Skip to content

Commit 6cb3089

Browse files
committed
chore: cosmetic changes before the release
Signed-off-by: Maxime Soulé <[email protected]>
1 parent ebf2b7d commit 6cb3089

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

helpers/tdhttp/request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, Maxime Soulé
1+
// Copyright (c) 2019-2023, Maxime Soulé
22
// All rights reserved.
33
//
44
// This source code is licensed under the BSD-style license found in the
@@ -256,7 +256,7 @@ func TestNewRequest(tt *testing.T) {
256256
),
257257
}))
258258

259-
// PostForm - td.Q
259+
// PostForm - tdhttp.Q
260260
t.Cmp(
261261
tdhttp.PostForm("/path",
262262
tdhttp.Q{

td/t_anchor_119.go renamed to td/t_anchor_118.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
//go:build go1.19
8-
// +build go1.19
7+
//go:build go1.18
8+
// +build go1.18
99

1010
package td
1111

td/t_anchor_119_test.go renamed to td/t_anchor_118_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
//go:build go1.19
8-
// +build go1.19
7+
//go:build go1.18
8+
// +build go1.18
99

1010
package td_test
1111

td/td_json.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)