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
|
package hm
import "testing"
func TestConstraint(t *testing.T) {
c := Constraint{
a: TypeVariable('a'),
b: NewFnType(TypeVariable('b'), TypeVariable('c')),
}
ftv := c.FreeTypeVar()
if !ftv.Equals(TypeVarSet{TypeVariable('a'), TypeVariable('b'), TypeVariable('c')}) {
t.Error("the free type variables of a Constraint is not as expected")
}
subs := mSubs{
'a': NewFnType(proton, proton),
'b': proton,
'c': neutron,
}
c = c.Apply(subs).(Constraint)
if !c.a.Eq(NewFnType(proton, proton)) {
t.Errorf("c.a: %v", c)
}
if !c.b.Eq(NewFnType(proton, neutron)) {
t.Errorf("c.b: %v", c)
}
}
|