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