-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypeVariable_test.go
87 lines (69 loc) · 1.58 KB
/
typeVariable_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package hm
import (
"fmt"
"testing"
)
func TestTypeVariableBasics(t *testing.T) {
tv := TypeVariable('a')
if name := tv.Name(); name != "a" {
t.Errorf("Expected name to be \"a\". Got %q instead", name)
}
if str := tv.String(); str != "a" {
t.Errorf("Expected String() of 'a'. Got %q instead", str)
}
if tv.Types() != nil {
t.Errorf("Expected Types() of TypeVariable to be nil")
}
ftv := tv.FreeTypeVar()
if len(ftv) != 1 {
t.Errorf("Expected a type variable to be free when FreeTypeVar() is called")
}
if ftv[0] != tv {
t.Errorf("Expected ...")
}
sub := mSubs{
'a': proton,
}
if tv.Apply(sub) != proton {
t.Error("Expected proton")
}
sub = mSubs{
'b': proton,
}
if tv.Apply(sub) != tv {
t.Error("Expected unchanged")
}
}
func TestTypeVariableNormalize(t *testing.T) {
original := TypeVarSet{'c', 'a', 'd'}
normalized := TypeVarSet{'a', 'b', 'c'}
tv := TypeVariable('a')
norm, err := tv.Normalize(original, normalized)
if err != nil {
t.Error(err)
}
if norm != TypeVariable('b') {
t.Errorf("Expected 'b'. Got %v", norm)
}
tv = TypeVariable('e')
if _, err = tv.Normalize(original, normalized); err == nil {
t.Error("Expected an error")
}
}
func TestTypeConst(t *testing.T) {
T := proton
if T.Name() != "proton" {
t.Error("Expected name to be proton")
}
if fmt.Sprintf("%v", T) != "proton" {
t.Error("Expected name to be proton")
}
if T.String() != "proton" {
t.Error("Expected name to be proton")
}
if T2, err := T.Normalize(nil, nil); err != nil {
t.Error(err)
} else if T2 != T {
t.Error("Const types should return itself")
}
}