forked from nsf/jsondiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsondiff_test.go
38 lines (35 loc) · 1.1 KB
/
jsondiff_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
package jsondiff
import (
"testing"
)
var cases = []struct {
a string
b string
result Difference
}{
{`{"a": 5}`, `["a"]`, NoMatch},
{`{"a": 5}`, `{"a": 6}`, NoMatch},
{`{"a": 5}`, `{"a": true}`, NoMatch},
{`{"a": 5}`, `{"a": 5}`, FullMatch},
{`{"a": 5}`, `{"a": 5, "b": 6}`, NoMatch},
{`{"a": 5, "b": 6}`, `{"a": 5}`, SupersetMatch},
{`{"a": 5, "b": 6}`, `{"b": 6}`, SupersetMatch},
{`{"a": null}`, `{"a": 1}`, NoMatch},
{`{"a": null}`, `{"a": null}`, FullMatch},
{`{"a": "null"}`, `{"a": null}`, NoMatch},
{`{"a": 3.1415}`, `{"a": 3.14156}`, NoMatch},
{`{"a": 3.1415}`, `{"a": 3.1415}`, FullMatch},
{`{"a": 4213123123}`, `{"a": "4213123123"}`, NoMatch},
{`{"a": 4213123123}`, `{"a": 4213123123}`, FullMatch},
{`{"a": 123, "b": 456, "c": ["baz", "foo"]}`, `{"a": 123, "c": ["foo", "baz"]}`, SupersetMatch},
}
func TestCompare(t *testing.T) {
opts := DefaultConsoleOptions()
opts.PrintTypes = false
for i, c := range cases {
result, _ := Compare([]byte(c.a), []byte(c.b), &opts)
if result != c.result {
t.Errorf("case %d failed, got: %s, expected: %s", i, result, c.result)
}
}
}