-
Notifications
You must be signed in to change notification settings - Fork 2
/
diff_test.go
111 lines (103 loc) · 1.65 KB
/
diff_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package testingutils
import (
"fmt"
"testing"
)
func ExamplePrettyJsonDiff() {
type Company struct {
Name string
}
type People struct {
Name string
Age int
Company Company
}
p1 := People{
Name: "Felix",
Age: 20,
Company: Company{
Name: "The Plant",
},
}
p2 := People{
Name: "Tom",
Age: 21,
Company: Company{
Name: "Microsoft",
},
}
fmt.Println(PrettyJsonDiff(p1, p2))
//Output:
// --- Expected
// +++ Actual
// @@ -1,7 +1,7 @@
// {
// - "Name": "Felix",
// - "Age": 20,
// + "Name": "Tom",
// + "Age": 21,
// "Company": {
// - "Name": "The Plant"
// + "Name": "Microsoft"
// }
// }
}
func ExamplePrettyJsonDiff_JSONRawMessage(t *testing.T) {
str1 := `{
"Active": true,
"Addresses": [], "Age": 0,
"Avatar": "",
"Company": "",
"CreditCard": {
"Number": "411111111111",
"Issuer": "VISA"
},
"ID": 1,
"Languages": null,
"Name": "jinzhu",
"Profile": {
"ID": 0,
"Name": "jinzhu",
"Phone": {
"ID": 0,
"Num": "110"
},
"Sex": "male"
},
"RegisteredAt": "2017-01-01 00:00",
"Role": ""
}`
str2 := `{
"Active": true,
"Addresses": [],
"Age": 0,
"Avatar": "",
"Company": "",
"ID": 1,
"Languages": null,
"Name": "jinzhu",
"Profile": {
"ID": 0,
"Name": "jinzhu",
"Phone": {
"ID": 0,
"Num": "110"
},
"Sex": "male"
},
"RegisteredAt": "2017-01-01 00:00",
"Role": ""
}`
fmt.Println(PrettyJsonDiff(str1, str2))
// Output
// "Age": 0,
// "Avatar": "",
// "Company": "",
// - "CreditCard": {
// - "Number": "411111111111",
// - "Issuer": "VISA"
// - },
// "ID": 1,
// "Languages": null,
// "Name": "jinzhu",
}