diff options
| -rw-r--r-- | CHANGELOG.md | 6 | ||||
| -rw-r--r-- | jsonmatch/interface.go | 16 |
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. // |
