fix(JSON): mixing numeric and named placeholders didn't work correctly · maxatome/go-testdeep@83bafbc
@@ -105,6 +105,16 @@ func TestJSON(t *testing.T) {
105105td.Tag("age", td.Between(40, 45)),
106106td.Tag("gender", td.NotEmpty())))
107107108+// Tag placeholders + numeric placeholders
109+checkOK(t, []MyStruct{got, got},
110+td.JSON(`[
111+ {"name":"$1","age":$age,"gender":"$3"},
112+ {"name":"$1","age":$2,"gender":"$3"}
113+ ]`,
114+td.Re(`^Bo`), // $1
115+td.Tag("age", td.Between(40, 45)), // $2
116+"male")) // $3
117+108118// Tag placeholders + operators are not JSON marshallable
109119checkOK(t, got,
110120td.JSON(`$all`, td.Tag("all", map[string]any{
@@ -113,6 +123,15 @@ func TestJSON(t *testing.T) {
113123"gender": td.NotEmpty(),
114124 })))
115125126+checkError(t, got,
127+td.JSON(`{"name":$1, "age":$1, "gender":$1}`,
128+td.Tag("!!", td.Ignore())),
129+expectedError{
130+Message: mustBe("bad usage of Tag operator"),
131+Summary: mustBe("Invalid tag, should match (Letter|_)(Letter|_|Number)*"),
132+Under: mustContain("under operator Tag"),
133+ })
134+116135// Tag placeholders + nil
117136checkOK(t, nil, td.JSON(`$all`, td.Tag("all", nil)))
118137