@@ -506,7 +506,8 @@ func jsonify(ctx ctxerr.Context, got reflect.Value) (any, *ctxerr.Error) {
506506// as is, in its freshly unmarshaled JSON form (so as bool, float64,
507507// string, []any, map[string]any or simply nil).
508508//
509- // Note expectedJSON can be a []byte, a JSON filename or a [io.Reader]:
509+ // Note expectedJSON can be a []byte, an [encoding/json.RawMessage], a
510+ // JSON filename or a [io.Reader]:
510511//
511512// td.Cmp(t, gotValue, td.JSON("file.json", td.Between(12, 34)))
512513// td.Cmp(t, gotValue, td.JSON([]byte(`[1, $1, 3]`), td.Between(12, 34)))
@@ -660,6 +661,19 @@ func jsonify(ctx ctxerr.Context, got reflect.Value) (any, *ctxerr.Error) {
660661// As for placeholders, there is no differences between $^NotZero and
661662// "$^NotZero".
662663//
664+ // Tip: when an [io.Reader] is expected to contain JSON data, it
665+ // cannot be tested directly, but using the [Smuggle] operator simply
666+ // solves the problem:
667+ //
668+ // var body io.Reader
669+ // // …
670+ // td.Cmp(t, body, td.Smuggle(json.RawMessage{}, td.JSON(`{"foo":1}`)))
671+ // // or equally
672+ // td.Cmp(t, body, td.Smuggle(json.RawMessage(nil), td.JSON(`{"foo":1}`)))
673+ //
674+ // [Smuggle] reads from body into an [encoding/json.RawMessage] then
675+ // this buffer is unmarshaled by JSON operator before the comparison.
676+ //
663677// TypeBehind method returns the [reflect.Type] of the expectedJSON
664678// once JSON unmarshaled. So it can be bool, string, float64, []any,
665679// map[string]any or any in case expectedJSON is "null".
@@ -818,7 +832,8 @@ var _ TestDeep = &tdMapJSON{}
818832// as is, in its freshly unmarshaled JSON form (so as bool, float64,
819833// string, []any, map[string]any or simply nil).
820834//
821- // Note expectedJSON can be a []byte, JSON filename or [io.Reader]:
835+ // Note expectedJSON can be a []byte, an [encoding/json.RawMessage], a
836+ // JSON filename or a [io.Reader]:
822837//
823838// td.Cmp(t, gotValue, td.SubJSONOf("file.json", td.Between(12, 34)))
824839// td.Cmp(t, gotValue, td.SubJSONOf([]byte(`[1, $1, 3]`), td.Between(12, 34)))
@@ -973,6 +988,19 @@ var _ TestDeep = &tdMapJSON{}
973988// As for placeholders, there is no differences between $^NotZero and
974989// "$^NotZero".
975990//
991+ // Tip: when an [io.Reader] is expected to contain JSON data, it
992+ // cannot be tested directly, but using the [Smuggle] operator simply
993+ // solves the problem:
994+ //
995+ // var body io.Reader
996+ // // …
997+ // td.Cmp(t, body, td.Smuggle(json.RawMessage{}, td.SubJSONOf(`{"foo":1,"bar":2}`)))
998+ // // or equally
999+ // td.Cmp(t, body, td.Smuggle(json.RawMessage(nil), td.SubJSONOf(`{"foo":1,"bar":2}`)))
1000+ //
1001+ // [Smuggle] reads from body into an [encoding/json.RawMessage] then
1002+ // this buffer is unmarshaled by SubJSONOf operator before the comparison.
1003+ //
9761004// TypeBehind method returns the map[string]any type.
9771005//
9781006// See also [JSON], [JSONPointer] and [SuperJSONOf].
@@ -1085,7 +1113,8 @@ func SubJSONOf(expectedJSON any, params ...any) TestDeep {
10851113// as is, in its freshly unmarshaled JSON form (so as bool, float64,
10861114// string, []any, map[string]any or simply nil).
10871115//
1088- // Note expectedJSON can be a []byte, JSON filename or [io.Reader]:
1116+ // Note expectedJSON can be a []byte, an [encoding/json.RawMessage], a
1117+ // JSON filename or a [io.Reader]:
10891118//
10901119// td.Cmp(t, gotValue, td.SuperJSONOf("file.json", td.Between(12, 34)))
10911120// td.Cmp(t, gotValue, td.SuperJSONOf([]byte(`[1, $1, 3]`), td.Between(12, 34)))
@@ -1239,6 +1268,19 @@ func SubJSONOf(expectedJSON any, params ...any) TestDeep {
12391268// As for placeholders, there is no differences between $^NotZero and
12401269// "$^NotZero".
12411270//
1271+ // Tip: when an [io.Reader] is expected to contain JSON data, it
1272+ // cannot be tested directly, but using the [Smuggle] operator simply
1273+ // solves the problem:
1274+ //
1275+ // var body io.Reader
1276+ // // …
1277+ // td.Cmp(t, body, td.Smuggle(json.RawMessage{}, td.SuperJSONOf(`{"foo":1}`)))
1278+ // // or equally
1279+ // td.Cmp(t, body, td.Smuggle(json.RawMessage(nil), td.SuperJSONOf(`{"foo":1}`)))
1280+ //
1281+ // [Smuggle] reads from body into an [encoding/json.RawMessage] then
1282+ // this buffer is unmarshaled by SuperJSONOf operator before the comparison.
1283+ //
12421284// TypeBehind method returns the map[string]any type.
12431285//
12441286// See also [JSON], [JSONPointer] and [SubJSONOf].
0 commit comments