-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscheme_test.go
75 lines (60 loc) · 1.43 KB
/
scheme_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
package hm
import (
"fmt"
"testing"
)
func TestSchemeBasics(t *testing.T) {
s := new(Scheme)
s.tvs = TypeVarSet{'a', 'b'}
s.t = NewFnType(TypeVariable('c'), proton)
sub := mSubs{
'a': proton,
'b': neutron,
'c': electron,
}
s2 := s.Apply(nil).(*Scheme)
if s2 != s {
t.Errorf("Different pointers")
}
s2 = s.Apply(sub).(*Scheme)
if s2 != s {
t.Errorf("Different pointers")
}
if !s.tvs.Equals(TypeVarSet{'a', 'b'}) {
t.Error("TypeVarSet mutated")
}
if !s.t.Eq(NewFnType(electron, proton)) {
t.Error("Application failed")
}
s = new(Scheme)
s.tvs = TypeVarSet{'a', 'b'}
s.t = NewFnType(TypeVariable('c'), proton)
ftv := s.FreeTypeVar()
if !ftv.Equals(TypeVarSet{'c'}) {
t.Errorf("Expected ftv: {'c'}. Got %v instead", ftv)
}
// format
if fmt.Sprintf("%v", s) != "∀[a, b]: c → proton" {
t.Errorf("Scheme format is wrong.: Got %q", fmt.Sprintf("%v", s))
}
// Polytype scheme.Type
T, isMono := s.Type()
if isMono {
t.Errorf("%v is supposed to be a polytype. It shouldn't return true", s)
}
if !T.Eq(NewFnType(TypeVariable('c'), proton)) {
t.Error("Wrong type returned by scheme")
}
}
func TestSchemeNormalize(t *testing.T) {
s := new(Scheme)
s.tvs = TypeVarSet{'c', 'z', 'd'}
s.t = NewFnType(TypeVariable('a'), TypeVariable('c'))
err := s.Normalize()
if err != nil {
t.Error(err)
}
if !s.tvs.Equals(TypeVarSet{'a', 'b'}) {
t.Errorf("Expected: TypeVarSet{'a','b'}. Got: %v", s.tvs)
}
}