type self struct{}
+type Loop *Loop
+type Loopy interface{}
+
+var loop1, loop2 Loop
+var loopy1, loopy2 Loopy
+
+func init() {
+ loop1 = &loop2
+ loop2 = &loop1
+
+ loopy1 = &loopy2
+ loopy2 = &loopy1
+}
+
var deepEqualTests = []DeepEqualTest{
// Equalities
{nil, nil, true},
{&[3]interface{}{1, 2, 4}, &[3]interface{}{1, 2, "s"}, false},
{Basic{1, 0.5}, NotBasic{1, 0.5}, false},
{map[uint]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, false},
+
+ // Possible loops.
+ {&loop1, &loop1, true},
+ {&loop1, &loop2, true},
+ {&loopy1, &loopy1, true},
+ {&loopy1, &loopy2, true},
}
func TestDeepEqual(t *testing.T) {
}
// if depth > 10 { panic("deepValueEqual") } // for debugging
+
+ // We want to avoid putting more in the visited map than we need to.
+ // For any possible reference cycle that might be encountered,
+ // hard(t) needs to return true for at least one of the types in the cycle.
hard := func(k Kind) bool {
switch k {
- case Array, Map, Slice, Struct:
+ case Map, Slice, Ptr, Interface:
return true
}
return false