diff --git a/td/td_json.go b/td/td_json.go index 15b3d784..a67b20b7 100644 --- a/td/td_json.go +++ b/td/td_json.go @@ -22,6 +22,7 @@ import ( "github.com/maxatome/go-testdeep/internal/json" "github.com/maxatome/go-testdeep/internal/location" "github.com/maxatome/go-testdeep/internal/types" + "github.com/maxatome/go-testdeep/internal/util" ) // forbiddenOpsInJSON contains operators forbidden inside JSON, @@ -326,8 +327,7 @@ func (s *tdJSONSmuggler) Match(ctx ctxerr.Context, got reflect.Value) *ctxerr.Er } func (s *tdJSONSmuggler) String() string { - // Only called by MarshalJSON(), and so only when p.isTestDeeper - return s.expectedValue.Interface().(TestDeep).String() + return util.ToString(s.expectedValue.Interface()) } func (s *tdJSONSmuggler) HandleInvalid() bool { diff --git a/td/td_json_test.go b/td/td_json_test.go index 8e2e9370..abf9c15a 100644 --- a/td/td_json_test.go +++ b/td/td_json_test.go @@ -231,6 +231,25 @@ func TestJSON(t *testing.T) { Summary: mustContain("json: unsupported type"), }) + checkError(t, map[string]string{"zip": "pipo"}, + td.All(td.JSON(`SuperMapOf({"zip":$1})`, "bingo")), + expectedError{ + Path: mustBe(`DATA`), + Message: mustBe("compared (part 1 of 1)"), + Got: mustBe(`(map[string]string) (len=1) { + (string) (len=3) "zip": (string) (len=4) "pipo" +}`), + Expected: mustBe(`JSON(SuperMapOf(map[string]interface {}{ + "zip": "bingo", + }))`), + Origin: &expectedError{ + Path: mustBe(`DATA["zip"]`), + Message: mustBe(`values differ`), + Got: mustBe(`"pipo"`), + Expected: mustBe(`"bingo"`), + }, + }) + // // Fatal errors checkError(t, "never tested",