-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequal_test.go
42 lines (34 loc) · 1.21 KB
/
equal_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
package jsontools_test
import (
"testing"
"github.com/WqyJh/jsontools"
"github.com/stretchr/testify/require"
)
func TestEqual(t *testing.T) {
cases := []struct {
a, b string
want bool
}{
{`{"a":null}`, `{}`, true},
{`{"a":null,"b":"null"}`, `{"b":"null"}`, true},
{`{"a":1 , "b":null}`, `{"a":1}`, true},
{`{"a":null , "b":2}`, `{"b":2}`, true},
{`{"a":1,"b":2,"c":null}`, `{"a":1,"b":2}`, true},
{`{"a":1, "b":null,"c":3}`, `{"a":1,"c":3}`, true},
{`{ "a":null,"b":2,"c":3}`, `{"b":2,"c":3}`, true},
{`{"a":1,"b":null,"c":null}`, `{"a":1}`, true},
{`{"a":null,"b":2, "c":null}`, `{"b":2}`, true},
{`{"a":null,"b":null,"c":3}`, `{"c":3}`, true},
{`{"a":null,"b":null,"c":null}`, `{}`, true},
{`{"a":null,"b":null,"c":[1,2,3]}`, `{"c":[1,2,3]}`, true},
{`{"a":null,"b":[1,2,3],"c":null}`, `{"b":[1,2,3]}`, true},
{`{"a":[1,2,3] , "b" :null,"c":null }`, `{"a":[1,2,3]}`, true},
{`{"a":null,"b":null,"c":[1,2,{ "a":1.23,"b":null ,"c" :"null"}]}`, `{"c":[1,2,{"a":1.23,"c":"null"}]}`, true},
}
for i, c := range cases {
got, err := jsontools.JsonEqual([]byte(c.a), []byte(c.b))
require.NoError(t, err)
require.Equal(t, c.want, got)
jsontools.RequireJSONEq(t, c.a, c.b, "case %d", i)
}
}