@@ -506,7 +506,8 @@ func jsonify(ctx ctxerr.Context, got reflect.Value) (any, *ctxerr.Error) {
506
506
// as is, in its freshly unmarshaled JSON form (so as bool, float64,
507
507
// string, []any, map[string]any or simply nil).
508
508
//
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]:
510
511
//
511
512
// td.Cmp(t, gotValue, td.JSON("file.json", td.Between(12, 34)))
512
513
// 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) {
660
661
// As for placeholders, there is no differences between $^NotZero and
661
662
// "$^NotZero".
662
663
//
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
+ //
663
677
// TypeBehind method returns the [reflect.Type] of the expectedJSON
664
678
// once JSON unmarshaled. So it can be bool, string, float64, []any,
665
679
// map[string]any or any in case expectedJSON is "null".
@@ -818,7 +832,8 @@ var _ TestDeep = &tdMapJSON{}
818
832
// as is, in its freshly unmarshaled JSON form (so as bool, float64,
819
833
// string, []any, map[string]any or simply nil).
820
834
//
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]:
822
837
//
823
838
// td.Cmp(t, gotValue, td.SubJSONOf("file.json", td.Between(12, 34)))
824
839
// td.Cmp(t, gotValue, td.SubJSONOf([]byte(`[1, $1, 3]`), td.Between(12, 34)))
@@ -973,6 +988,19 @@ var _ TestDeep = &tdMapJSON{}
973
988
// As for placeholders, there is no differences between $^NotZero and
974
989
// "$^NotZero".
975
990
//
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
+ //
976
1004
// TypeBehind method returns the map[string]any type.
977
1005
//
978
1006
// See also [JSON], [JSONPointer] and [SuperJSONOf].
@@ -1085,7 +1113,8 @@ func SubJSONOf(expectedJSON any, params ...any) TestDeep {
1085
1113
// as is, in its freshly unmarshaled JSON form (so as bool, float64,
1086
1114
// string, []any, map[string]any or simply nil).
1087
1115
//
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]:
1089
1118
//
1090
1119
// td.Cmp(t, gotValue, td.SuperJSONOf("file.json", td.Between(12, 34)))
1091
1120
// 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 {
1239
1268
// As for placeholders, there is no differences between $^NotZero and
1240
1269
// "$^NotZero".
1241
1270
//
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
+ //
1242
1284
// TypeBehind method returns the map[string]any type.
1243
1285
//
1244
1286
// See also [JSON], [JSONPointer] and [SubJSONOf].
0 commit comments