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
|
package hm
import (
"fmt"
"testing"
)
func TestConstraints(t *testing.T) {
cs := Constraints{
{TypeVariable('a'), proton},
{TypeVariable('b'), proton},
}
correct := TypeVarSet{'a', 'b'}
ftv := cs.FreeTypeVar()
for _, v := range correct {
if !ftv.Contains(v) {
t.Errorf("Expected free type vars to contain %v", v)
break
}
}
sub := mSubs{
'a': neutron,
}
cs = cs.Apply(sub).(Constraints)
if cs[0].a != neutron {
t.Error("Expected neutron")
}
if cs[0].b != proton {
t.Error("Expected proton")
}
if cs[1].a != TypeVariable('b') {
t.Error("There was nothing to substitute b with")
}
if cs[1].b != proton {
t.Error("Expected proton")
}
if fmt.Sprintf("%v", cs) != "Constraints[{neutron = proton}, {b = proton}]" {
t.Errorf("Error in formatting cs")
}
}
func TestTypes_Contains(t *testing.T) {
ts := Types{TypeVariable('a'), proton}
if !ts.Contains(TypeVariable('a')) {
t.Error("Expected ts to contain 'a'")
}
if !ts.Contains(proton) {
t.Error("Expected ts to contain proton")
}
if ts.Contains(neutron) {
t.Error("ts shouldn't contain neutron")
}
}
|