File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -61,10 +61,11 @@ const (
61
61
// pass it to Equal; if you do, it does nothing.
62
62
FLAG_NONE byte = iota
63
63
64
- // FLAG_IGNORE_SLICE_ORDER causes Equal to ignore slice order and, instead,
65
- // compare value counts. For example, []{1, 2} and []{2, 1} are equal
66
- // because each value has the same count. But []{1, 2, 2} and []{1, 2}
67
- // are not equal because the first slice has two occurrences of value 2.
64
+ // FLAG_IGNORE_SLICE_ORDER causes Equal to ignore slice order so that
65
+ // []int{1, 2} and []int{2, 1} are equal. Only slices of primitive scalars
66
+ // like numbers and strings are supported. Slices of complex types,
67
+ // like []T where T is a struct, are undefined because Equal does not
68
+ // recurse into the slice value when this flag is enabled.
68
69
FLAG_IGNORE_SLICE_ORDER
69
70
)
70
71
Original file line number Diff line number Diff line change @@ -1561,3 +1561,23 @@ func TestSliceOrderString(t *testing.T) {
1561
1561
t .Errorf ("got %s, expected '(unordered) slice[]=x: value count: 0 != 1'" , diff [2 ])
1562
1562
}
1563
1563
}
1564
+
1565
+ func TestSliceOrderStruct (t * testing.T ) {
1566
+ // https://github.com/go-test/deep/issues/28
1567
+ // This is NOT supported but Go is so wonderful that it just happens to work.
1568
+ // But again: not supported. So if this test starts to fail or be a problem,
1569
+ // it can and should be removed becuase the docs say it's not supported.
1570
+ type T struct { i int }
1571
+ a := []T {
1572
+ {i : 1 },
1573
+ {i : 2 },
1574
+ }
1575
+ b := []T {
1576
+ {i : 2 },
1577
+ {i : 1 },
1578
+ }
1579
+ diff := deep .Equal (a , b , deep .FLAG_IGNORE_SLICE_ORDER )
1580
+ if len (diff ) != 0 {
1581
+ t .Fatalf ("expected 0 diff, got %d: %s" , len (diff ), diff )
1582
+ }
1583
+ }
You can’t perform that action at this time.
0 commit comments