}
}
-func checkSameType(t *testing.T, x, y interface{}) {
- if TypeOf(x) != TypeOf(y) {
+func checkSameType(t *testing.T, x Type, y interface{}) {
+ if x != TypeOf(y) || TypeOf(Zero(x).Interface()) != TypeOf(y) {
t.Errorf("did not find preexisting type for %s (vs %s)", TypeOf(x), TypeOf(y))
}
}
// check that type already in binary is found
type T int
- checkSameType(t, Zero(ArrayOf(5, TypeOf(T(1)))).Interface(), [5]T{})
+ checkSameType(t, ArrayOf(5, TypeOf(T(1))), [5]T{})
}
func TestArrayOfGC(t *testing.T) {
// check that type already in binary is found
type T1 int
- checkSameType(t, Zero(SliceOf(TypeOf(T1(1)))).Interface(), []T1{})
+ checkSameType(t, SliceOf(TypeOf(T1(1))), []T1{})
}
func TestSliceOverflow(t *testing.T) {
})
})
// check that type already in binary is found
- checkSameType(t, Zero(StructOf(fields[2:3])).Interface(), struct{ Y uint64 }{})
+ checkSameType(t, StructOf(fields[2:3]), struct{ Y uint64 }{})
}
func TestStructOfExportRules(t *testing.T) {
// check that type already in binary is found
type T1 int
- checkSameType(t, Zero(ChanOf(BothDir, TypeOf(T1(1)))).Interface(), (chan T1)(nil))
+ checkSameType(t, ChanOf(BothDir, TypeOf(T1(1))), (chan T1)(nil))
}
func TestChanOfDir(t *testing.T) {
// check that type already in binary is found
type T1 int
- checkSameType(t, Zero(ChanOf(RecvDir, TypeOf(T1(1)))).Interface(), (<-chan T1)(nil))
- checkSameType(t, Zero(ChanOf(SendDir, TypeOf(T1(1)))).Interface(), (chan<- T1)(nil))
+ checkSameType(t, ChanOf(RecvDir, TypeOf(T1(1))), (<-chan T1)(nil))
+ checkSameType(t, ChanOf(SendDir, TypeOf(T1(1))), (chan<- T1)(nil))
// check String form of ChanDir
if crt.ChanDir().String() != "<-chan" {
}
// check that type already in binary is found
- checkSameType(t, Zero(MapOf(TypeOf(V(0)), TypeOf(K("")))).Interface(), map[V]K(nil))
+ checkSameType(t, MapOf(TypeOf(V(0)), TypeOf(K(""))), map[V]K(nil))
// check that invalid key type panics
shouldPanic(func() { MapOf(TypeOf((func())(nil)), TypeOf(false)) })
{in: []Type{TypeOf(int(0))}, out: []Type{TypeOf(false), TypeOf("")}, want: (func(int) (bool, string))(nil)},
}
for _, tt := range testCases {
- checkSameType(t, Zero(FuncOf(tt.in, tt.out, tt.variadic)).Interface(), tt.want)
+ checkSameType(t, FuncOf(tt.in, tt.out, tt.variadic), tt.want)
}
// check that variadic requires last element be a slice.