-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeepdiff_test.go
64 lines (58 loc) · 1.38 KB
/
deepdiff_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package evendeep
import (
"testing"
"github.com/hedzr/evendeep/diff"
"github.com/hedzr/evendeep/typ"
)
func TestDeepDiff(t *testing.T) {
testData := []testCase{
{
[]int{3, 0, 9},
[]int{9, 3, 0},
"",
true,
diff.WithSliceOrderedComparison(true),
},
{
[]int{3, 0},
[]int{9, 3, 0},
"added: [0] = 9\n",
false,
diff.WithSliceOrderedComparison(true),
},
{
[]int{3, 0},
[]int{9, 3, 0},
"added: [2] = <zero>\nmodified: [0] = 9 (int) (Old: 3)\nmodified: [1] = 3 (int) (Old: <zero>)\n",
false,
diff.WithSliceOrderedComparison(false),
},
}
checkTestCases(t, testData)
}
func TestDeepEqual(t *testing.T) { //nolint:revive
equal := DeepEqual([]int{3, 0, 9}, []int{9, 3, 0}, diff.WithSliceOrderedComparison(true))
if !equal {
t.Errorf("expecting equal = true but got false")
}
}
type testCase struct {
a, b typ.Any
diff string
equal bool
opt diff.Opt
}
func checkTestCases(t *testing.T, testData []testCase) {
for i, td := range testData {
delta, equal := DeepDiff(td.a, td.b, td.opt)
if delta.PrettyPrint() != td.diff {
t.Errorf("%d. PrettyDiff(%#v, %#v) diff = %#v; not %#v", i, td.a, td.b, delta.String(), td.diff)
continue
}
if equal != td.equal {
t.Errorf("%d. PrettyDiff(%#v, %#v) equal = %#v; not %#v", i, td.a, td.b, equal, td.equal)
continue
}
t.Logf("%d passed. PrettyDiff(%#v, %#v)\n%v", i, td.a, td.b, delta)
}
}