aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonmatch/diff_test.go19
-rw-r--r--jsonmatch/machinery.go2
2 files changed, 20 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)
+}
diff --git a/jsonmatch/machinery.go b/jsonmatch/machinery.go
index 172c82a..7f91f67 100644
--- a/jsonmatch/machinery.go
+++ b/jsonmatch/machinery.go
@@ -130,6 +130,8 @@ func getDiffsForValue(path []pathElement, expected, actual any) []Diff {
return getDiffsForObject(path, expected, actual)
case []any:
return getDiffsForArray(path, expected, actual)
+ case Array:
+ return getDiffsForArray(path, expected, actual)
case []map[string]any:
downcasted := make([]any, len(expected))
for idx, val := range expected {