1package jsondiff
2
3import (
4	"testing"
5)
6
7var cases = []struct {
8	a      string
9	b      string
10	result Difference
11}{
12	{`{"a": 5}`, `["a"]`, NoMatch},
13	{`{"a": 5}`, `{"a": 6}`, NoMatch},
14	{`{"a": 5}`, `{"a": true}`, NoMatch},
15	{`{"a": 5}`, `{"a": 5}`, FullMatch},
16	{`{"a": 5}`, `{"a": 5, "b": 6}`, NoMatch},
17	{`{"a": 5, "b": 6}`, `{"a": 5}`, SupersetMatch},
18	{`{"a": 5, "b": 6}`, `{"b": 6}`, SupersetMatch},
19	{`{"a": null}`, `{"a": 1}`, NoMatch},
20	{`{"a": null}`, `{"a": null}`, FullMatch},
21	{`{"a": "null"}`, `{"a": null}`, NoMatch},
22	{`{"a": 3.1415}`, `{"a": 3.14156}`, NoMatch},
23	{`{"a": 3.1415}`, `{"a": 3.1415}`, FullMatch},
24	{`{"a": 4213123123}`, `{"a": "4213123123"}`, NoMatch},
25	{`{"a": 4213123123}`, `{"a": 4213123123}`, FullMatch},
26}
27
28func TestCompare(t *testing.T) {
29	opts := DefaultConsoleOptions()
30	opts.PrintTypes = false
31	for i, c := range cases {
32		result, _ := Compare([]byte(c.a), []byte(c.b), &opts)
33		if result != c.result {
34			t.Errorf("case %d failed, got: %s, expected: %s", i, result, c.result)
35		}
36	}
37}
38