Find a format's bound readers in one ordered scan

This commit is contained in:
M
2026-08-30 22:27:56 +02:00
committed by lilleman-tw
parent c1222eaf72
commit 5a69b02ee0
5 changed files with 76 additions and 28 deletions
+15
View File
@@ -82,3 +82,18 @@ func TestCalcReproducible(t *testing.T) {
t.Fatalf("calc not reproducible: %q != %q", a, b)
}
}
// TestCalcTokenOperandsReadsOnlyACalc pins what the helper answers for a body that
// is not a calc, and for one whose expression does not parse: nothing, either way.
// checkCalc is what reports a bad expression, so the callers that run after it
// never meet one — but they must not have to depend on that order to be safe.
func TestCalcTokenOperandsReadsOnlyACalc(t *testing.T) {
for _, body := range []string{"plain", "luhn()", "calc()", "calc(1 +)", "calc(()"} {
if got := calcTokenOperands(body); got != nil {
t.Errorf("calcTokenOperands(%q) = %v, want none", body, got)
}
}
if got := calcTokenOperands("calc(net * qty)"); len(got) != 2 {
t.Errorf("calcTokenOperands(calc(net * qty)) = %v, want both operands", got)
}
}