diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-04-01 14:29:30 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-04-01 14:29:32 +0200 |
| commit | ca7ccbadbc19c2cb28f1b7edfcc845b9d7888adc (patch) | |
| tree | 78722261410ff806736b3f249cb81bc5732b15d4 /jsonmatch/diff_test.go | |
| parent | e21e702017a5da3224c93caedf0d51b062627311 (diff) | |
| download | go-gg-ca7ccbadbc19c2cb28f1b7edfcc845b9d7888adc.tar.gz | |
jsonmatch: fix destructuring of Array
Diffstat (limited to 'jsonmatch/diff_test.go')
| -rw-r--r-- | jsonmatch/diff_test.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/jsonmatch/diff_test.go b/jsonmatch/diff_test.go index f0f4fdd..a59d304 100644 --- a/jsonmatch/diff_test.go +++ b/jsonmatch/diff_test.go @@ -56,7 +56,7 @@ func TestCanonicalizesActualPayload(t *testing.T) { "data": jsonmatch.Object{ "foo": 42, "bar": "hello world", - "qux": []any{5, nil, 15}, + "qux": jsonmatch.Array{5, nil, 15}, }, } AssertEqual(t, match.DiffAgainst(message), nil) @@ -390,3 +390,20 @@ type unmarshalableObject struct{} func (unmarshalableObject) MarshalJSON() ([]byte, error) { return nil, errors.New("this object is unmarshalable") } + +func TestArrayOnArrayAction(t *testing.T) { + message := []byte(`[[1,3]]`) // but we assert against [[1,2]] + expected := []jsonmatch.Diff{{ + Kind: "value mismatch", + Pointer: "/0/1", + ExpectedJSON: "2", + ActualJSON: "3", + }} + + match := jsonmatch.Array{[]any{1, 2}} + AssertEqual(t, match.DiffAgainst(message), expected) + + // this used to fail before the fix in the commit that added this test + match = jsonmatch.Array{jsonmatch.Array{1, 2}} + AssertEqual(t, match.DiffAgainst(message), expected) +} |
