Tests for weight 0, a never-numeric calc operand, the repeat product along a path, and ErrNoData
Tests / vet + fmt + tests (pull_request) Failing after 15s

This commit is contained in:
2026-09-02 18:22:23 +02:00
parent c5c06375d8
commit d72d326de5
5 changed files with 54 additions and 8 deletions
+23
View File
@@ -218,3 +218,26 @@ func TestCalcHoldIsPerTemplate(t *testing.T) {
t.Fatal("the nested template never differed from its parent, want its own draw")
}
}
func TestCalcOverANeverNumericOperandIsRejected(t *testing.T) {
for src, want := range map[string]string{
`{"format":"{calc(x * 2)}","x":"abc"}`: `"abc"`,
`{"format":"{calc(x * 2)}","x":["a","b"]}`: `"x"`,
`{"format":"{calc(x + y)}","x":"1","y":"{{2}}"}`: `"{2}"`,
} {
_, err := compile(parse(t, src))
if err == nil || !strings.Contains(err.Error(), want) || !strings.Contains(err.Error(), "never a number") {
t.Errorf("compile(%s) = %v, want the operand rejected naming %s", src, err, want)
}
}
for _, ok := range []string{
`{"format":"{calc(x * 2)}","x":"3"}`,
`{"format":"{calc(x * 2)}","x":" 2.5 "}`,
`{"format":"{calc(x * 2)}","x":["1","abc"]}`,
`{"format":"{calc(x * 2)}","x":"{digits(2)}"}`,
} {
if _, err := compile(parse(t, ok)); err != nil {
t.Errorf("compile(%s) = %v, want it accepted", ok, err)
}
}
}