...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pretty
19
20 import (
21 "testing"
22 )
23
24 func TestDiff(t *testing.T) {
25 for _, test := range []struct {
26 v1, v2 interface{}
27 ok bool
28 want string
29 }{
30 {5, 5, true, ""},
31 {"foo", "foo", true, ""},
32 {[]int{1, 2, 3}, []int{1, 0, 3}, false, `--- want
33 +++ got
34 @@ -1,5 +1,5 @@
35 []int{
36 1,
37 - 2,
38 + 0,
39 3,
40 }
41 `},
42 } {
43 got, ok, err := Diff(test.v1, test.v2)
44 if err != nil {
45 t.Errorf("%v vs. %v: %v", test.v1, test.v2, err)
46 continue
47 }
48 if ok != test.ok {
49 t.Errorf("%v vs. %v: got %t, want %t", test.v1, test.v2, ok, test.ok)
50 }
51 if got != test.want {
52 t.Errorf("%v vs. %v: got:\n%q\nwant:\n%q", test.v1, test.v2, got, test.want)
53 }
54 }
55 }
56
View as plain text