diff --git a/builtins_test.go b/builtins_test.go index 4389fb7..8d419fe 100644 --- a/builtins_test.go +++ b/builtins_test.go @@ -410,22 +410,16 @@ func TestBuiltinCompileErrors(t *testing.T) { for _, bad := range []string{ `"{digits(0)}"`, // count must be positive `"{upper(x)}"`, // count must be an integer - `"{lower()}"`, // wrong arity - `"{nope()}"`, // unknown function - `"{luhn(x)}"`, // function given args it takes none of - `"{int(1)}"`, // wrong arity `"{int(a,b)}"`, // non-integer args `"{int(5,1)}"`, // min > max `"{hex(0)}"`, // count must be positive `"{nanoid(-1)}"`, // negative count `"{base64(0)}"`, // count must be positive - `"{float(1,2)}"`, // wrong arity `"{float(1,2,-1)}"`, // negative decimals `"{float(NaN,NaN,2)}"`, // bounds must be finite `"{float(Inf,Inf,2)}"`, // same-sign infinities `"{float(1,NaN,2)}"`, // one NaN bound `"{float(-Inf,1,2)}"`, // one infinite bound - `"{digits(+5)}"`, // a count is a plain integer `"{digits(05)}"`, // no leading zero `"{int(+1,5)}"`, // a bound is a plain integer `"{int(5,5)}"`, // a constant is written as text @@ -438,3 +432,17 @@ func TestBuiltinCompileErrors(t *testing.T) { } } } + +func TestArgErrorsNameTheSpelling(t *testing.T) { + for src, want := range map[string]string{ + `"{float(1,2,02)}"`: "write 2", + `{"format":"{calc(a,02)}","a":"1"}`: "write 2", + `"{digits(+5)}"`: "write 5", + `"{hex(99999999999999999999)}"`: "exceeds the maximum", + `"{int(007,9)}"`: "write 7", + } { + if _, err := compile(parse(t, src)); err == nil || !strings.Contains(err.Error(), want) { + t.Errorf("compile(%s) = %v, want an error saying %q", src, err, want) + } + } +} diff --git a/format_test.go b/format_test.go index 0d466ef..8df1f38 100644 --- a/format_test.go +++ b/format_test.go @@ -120,6 +120,11 @@ func TestFormatCompileErrors(t *testing.T) { `"{}"`, // empty token name `{"format":"{a|}","a":"Q"}`, // empty alternation segment `"{luhn(}"`, // malformed function token + `"{lower()}"`, // wrong arity + `"{nope()}"`, // unknown function + `"{luhn(x)}"`, // function given args it takes none of + `"{int(1)}"`, // wrong arity + `"{float(1,2)}"`, // wrong arity } { if _, err := compile(parse(t, bad)); err == nil { t.Errorf("compile(%s) = nil error, want error", bad) @@ -127,20 +132,6 @@ func TestFormatCompileErrors(t *testing.T) { } } -func TestArgErrorsNameTheSpelling(t *testing.T) { - for src, want := range map[string]string{ - `"{float(1,2,02)}"`: "write 2", - `{"format":"{calc(a,02)}","a":"1"}`: "write 2", - `"{digits(+5)}"`: "write 5", - `"{hex(99999999999999999999)}"`: "exceeds the maximum", - `"{int(007,9)}"`: "write 7", - } { - if _, err := compile(parse(t, src)); err == nil || !strings.Contains(err.Error(), want) { - t.Errorf("compile(%s) = %v, want an error saying %q", src, err, want) - } - } -} - // TestSplitArgsQuotesOutsideSelectors pins the arg grammar: a comma splits outside a // selector and outside a quoted layout, and a quote inside a selector is a name's text. func TestSplitArgsQuotesOutsideSelectors(t *testing.T) {