We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6e90edf commit bf23379Copy full SHA for bf23379
compare_test.go
@@ -285,6 +285,12 @@ func TestIsEqual(t *testing.T) {
285
assert.Equal(isEqual(slice1, slice4), false)
286
assert.Equal(isEqual(slice1, slice5), false)
287
288
+ assert.True(isEqual([][]any{{1}, {2, 3}}, [][]any{{1}, {2, 3}}))
289
+ assert.NotTrue(isEqual([][]any{{1}, {2, 3}}, [][]any{{1.0}, {2.0, 3.0}}))
290
+ assert.NotTrue(isEqual([][]any{{1}, {2, 3}}, [][]any{{"1"}, {"2", "3"}}))
291
+ assert.True(isEqual([][][]any{{{1}, {2}}, {{2, 3}}}, [][][]any{{{1}, {2}}, {{2, 3}}}))
292
+ assert.NotTrue(isEqual([][][]any{{{1}, {2}}, {{2, 3}}}, [][][]any{{{1}, {2}}, {{2, "3"}}}))
293
+
294
assert.Equal(isEqual(testStruct1{A: 0}, testStruct1{A: 0}), true)
295
assert.Equal(isEqual(testStruct1{A: 0}, testStruct1{A: 1}), false)
296
assert.Equal(isEqual(s1, s1), true)
slice.go
@@ -135,8 +135,17 @@ func isSliceEqual(v1, v2 reflect.Value) bool {
135
}
136
137
for i := 0; i < v1.Len(); i++ {
138
- if v1.Index(i).Interface() != v2.Index(i).Interface() {
139
- return false
+ v1v := v1.Index(i).Interface()
+ v2v := v2.Index(i).Interface()
140
141
+ if v1.Index(i).Comparable() && v2.Index(i).Comparable() && v1.Type().ConvertibleTo(v2.Type()) {
142
+ if v1v != v2v {
143
+ return false
144
+ }
145
+ } else {
146
+ if ok := isEqual(v1v, v2v); !ok {
147
148
149
150
151
0 commit comments