Hold only the {token} grammar's tests in format_test.go, the rest in files named for what they test, and drop the done item

This commit is contained in:
2026-09-25 18:18:57 +02:00
committed by Lillem4n
parent 44a824ccf5
commit 5e84b26a5f
8 changed files with 301 additions and 264 deletions
+19
View File
@@ -270,3 +270,22 @@ func TestCalcConstantZeroDivisorIsRejected(t *testing.T) {
}
t.Fatal("a sometimes-zero divisor never printed +Inf in 50 draws")
}
func TestCalcCompileErrors(t *testing.T) {
for _, bad := range []string{
`"{calc(1/0)}"`, // a constant zero divisor
`{"format":"{calc(x/y)}","x":"1","y":"0"}`, // a fixed zero divisor
`"{calc()}"`, // calc needs an expression
`"{calc(1 +)}"`, // dangling operator
`"{calc((1 + 2)}"`, // unbalanced parenthesis
`"{calc(1 2)}"`, // two operands, no operator
`"{calc(price)}"`, // operand names no field
`"{calc(1, 2, 3)}"`, // too many args
`"{calc(1, x)}"`, // decimals arg not an integer
`"{calc(1, -1)}"`, // decimals negative
} {
if _, err := compile(parse(t, bad)); err == nil {
t.Errorf("compile(%s) = nil error, want error", bad)
}
}
}