From ca7ccbadbc19c2cb28f1b7edfcc845b9d7888adc Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Wed, 1 Apr 2026 14:29:30 +0200 Subject: jsonmatch: fix destructuring of Array --- jsonmatch/diff_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'jsonmatch/diff_test.go') 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) +} -- cgit v1.2.3