Tests: a reference path is one draw per render in both views, a repeat iteration draws anew, a group draws apart, and a bare reference beside a path is refused

This commit is contained in:
2026-09-15 22:45:13 +02:00
parent 72a6ef9071
commit 4b31482a53
5 changed files with 162 additions and 45 deletions
+30 -8
View File
@@ -31,25 +31,47 @@ func TestRepeatedChoiceItemIsRejected(t *testing.T) {
func TestInertObjectIsRejected(t *testing.T) {
for src, want := range map[string]string{
`{"format":"Malmö"}`: `write "Malmö"`,
`{"format":"{digits(3)}"}`: `write "{digits(3)}"`,
`[{"format":"a","weight":1},"b"]`: "weight 1",
`{"format":"{x}","x":"v","repeat":1}`: "repeat 1",
`{"format":"{x}","x":"v","separator":","}`: "separator",
`{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default",
`{"format":"","n":{"format":"1","datatype":"string"}}`: `datatype "string" is the default`,
`{"format":"Malmö"}`: `write "Malmö"`,
`{"format":"{digits(3)}"}`: `write "{digits(3)}"`,
`[{"format":"a","weight":1},"b"]`: "weight 1",
`{"format":"{x}","x":"v","repeat":1}`: "repeat 1",
`{"format":"{x}","x":"v","separator":","}`: "separator",
`{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default",
`{"format":"","n":{"format":"1","datatype":"string"}}`: `datatype "string" is the default`,
`{"format":"{x}","x":{"format":"{y}","y":"v","group":""}}`: `group "" is the default`,
`{"format":"{x}","x":{"format":"{y}","y":"v","group":1}}`: "group must be a string",
} {
if _, err := compile(parse(t, src)); err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("compile(%s) = %v, want an error mentioning %s", src, err, want)
}
}
for _, ok := range []string{`[{"format":"a","weight":2},"b"]`, `{"format":"ab","repeat":2}`, `{"format":"{x}","x":"v"}`, `"{digits(3)}"`} {
for _, ok := range []string{`[{"format":"a","weight":2},"b"]`, `{"format":"ab","repeat":2}`, `{"format":"{x}","x":"v"}`, `"{digits(3)}"`, `{"format":"{/cat.x}","group":"g"}`} {
if _, err := compile(parse(t, ok)); err != nil {
t.Errorf("compile(%s) = %v", ok, err)
}
}
}
func TestAGroupThatSplitsNothingIsRejected(t *testing.T) {
files := map[string]string{"mail": `"{/word.w}@example.com"`, "word": `{"format":"{w}","w":["a","b"]}`}
for src, want := range map[string]string{
`{"format":"{x}","x":{"format":"{y}","y":["a","b"],"group":"g"}}`: `group "g" splits nothing`,
`{"format":"{x}","x":{"format":"{/word}","group":"g"}}`: `group "g" splits nothing`,
`{"format":"{/word.w}","group":"g"}`: "",
`{"format":"{x}","x":{"format":"{/mail}","group":"g"}}`: "",
`{"format":"{x}","x":{"format":"{y}","y":"{/word.w}","repeat":2,"group":"g"}}`: "",
} {
files["cat"] = src
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, files)))
switch {
case want == "" && err != nil:
t.Errorf("New(%s) = %v, want a group over a reference path accepted, however deep", src, err)
case want != "" && (err == nil || !strings.Contains(err.Error(), want)):
t.Errorf("New(%s) = %v, want an error mentioning %s", src, err, want)
}
}
}
func TestInlineFolderSigilsAreRejected(t *testing.T) {
f := shipped(t)
for _, input := range []string{"{.sv_SE.person.last}", "{..sv_SE.person.last}"} {