3 // Copyright 2020 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Check to make sure that we compare fields in order. See issue 8606.
15 type A2 [6]interface{}
16 type S struct{ x, y interface{} }
17 type S2 struct{ x, y, z, a, b, c interface{} }
42 s1 := S3{func() {}, 0}
43 s2 := S3{func() {}, 1}
45 for _, test := range []struct {
49 {false, A{1, b}, A{2, b}},
50 {true, A{b, 1}, A{b, 2}},
51 {false, A{1, b}, A{"2", b}},
52 {true, A{b, 1}, A{b, "2"}},
54 {false, A2{1, b}, A2{2, b}},
55 {true, A2{b, 1}, A2{b, 2}},
56 {false, A2{1, b}, A2{"2", b}},
57 {true, A2{b, 1}, A2{b, "2"}},
59 {false, S{1, b}, S{2, b}},
60 {true, S{b, 1}, S{b, 2}},
61 {false, S{1, b}, S{"2", b}},
62 {true, S{b, 1}, S{b, "2"}},
64 {false, S2{x: 1, y: b}, S2{x: 2, y: b}},
65 {true, S2{x: b, y: 1}, S2{x: b, y: 2}},
66 {false, S2{x: 1, y: b}, S2{x: "2", y: b}},
67 {true, S2{x: b, y: 1}, S2{x: b, y: "2"}},
69 {true, T1{i: b, a: 1}, T1{i: b, a: 2}},
70 {false, T1{a: 1, j: b}, T1{a: 2, j: b}},
71 {true, T2{i: b, a: 1}, T2{i: b, a: 2}},
72 {false, T2{a: 1, j: b}, T2{a: 2, j: b}},
73 {true, T3{i: b, s: "foo"}, T3{i: b, s: "bar"}},
74 {false, T3{s: "foo", j: b}, T3{s: "bar", j: b}},
75 {true, T3{i: b, s: "fooz"}, T3{i: b, s: "bar"}},
76 {false, T3{s: "fooz", j: b}, T3{s: "bar", j: b}},
77 {true, A{s1, s2}, A{s2, s1}},
79 {false, S4{[1000]byte{0}, func() {}}, S4{[1000]byte{1}, func() {}}},
84 panic(fmt.Sprintf("comparing %#v and %#v panicked", test.a, test.b))
88 panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b))
92 shouldPanic(fmt.Sprintf("comparing %#v and %#v did not panic", test.a, test.b), f)
94 f() // should not panic
99 func shouldPanic(name string, f func()) {
101 if recover() == nil {