aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2025-11-18 16:43:18 +0100
committerStefan Majewsky <majewsky@gmx.net>2025-11-18 16:43:52 +0100
commit2a0845b89e9c2e3dea49682f9acb5d21e7258b75 (patch)
tree86a4a7e5134f7dde7ba8ecd406b55c8fc111eb7b
parentba9324523f685fadbb65bcf70b22cdc7c15d92fb (diff)
downloadgo-gg-2a0845b89e9c2e3dea49682f9acb5d21e7258b75.tar.gz
jsonmatch: add Diff.String()
-rw-r--r--CHANGELOG.md6
-rw-r--r--jsonmatch/interface.go16
2 files changed, 17 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69d2d4f..b70e003 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,12 @@ SPDX-FileCopyrightText: 2025 Stefan Majewsky <majewsky@gmx.net>
SPDX-License-Identifier: Apache-2.0
-->
+# v1.4.0 (TBD)
+
+Changes:
+
+- Add `jsonmatch.Diff.String()`.
+
# v1.3.0 (2025-08-15)
Changes:
diff --git a/jsonmatch/interface.go b/jsonmatch/interface.go
index 3c10cc3..99bbb9f 100644
--- a/jsonmatch/interface.go
+++ b/jsonmatch/interface.go
@@ -36,11 +36,7 @@
// },
// }
// for _, diff := range expected.DiffAgainst(resp.Body.Bytes()) {
-// if diff.Pointer == "" {
-// t.Errorf("%s: expected %s, but got %s", diff.Kind, diff.ExpectedJSON, diff.ActualJSON)
-// } else {
-// t.Errorf("%s at %s: expected %s, but got %s", diff.Kind, diff.Pointer, diff.ExpectedJSON, diff.ActualJSON)
-// }
+// t.Error(diff.String())
// }
// }
//
@@ -137,6 +133,7 @@ package jsonmatch
import (
"encoding/json"
"errors"
+ "fmt"
)
// Diffable is the common interface of types Object, Array, Scalar and Null from this package.
@@ -239,6 +236,15 @@ type Diff struct {
ActualJSON string
}
+// String returns a simple and complete string representation of the contents of this Diff.
+func (d Diff) String() string {
+ if d.Pointer == "" {
+ return fmt.Sprintf("%s: expected %s, but got %s", d.Kind, d.ExpectedJSON, d.ActualJSON)
+ } else {
+ return fmt.Sprintf("%s at %s: expected %s, but got %s", d.Kind, d.Pointer, d.ExpectedJSON, d.ActualJSON)
+ }
+}
+
// Pointer is a JSON pointer (RFC 6901) that references a particular JSON value relative to the root of the encoded JSON payload that was given to DiffAgainst().
// It appears in type Diff.
//