mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
tinyexpr: report errors for extra args in parens correctly.
Usages like `math (1 1)` should report too many arguments, same as `math 1 1`. Check for these cases and add tests. Fixes #8511
This commit is contained in:
parent
abf119918f
commit
de0cbd2984
2 changed files with 21 additions and 1 deletions
|
@ -449,8 +449,11 @@ static te_expr *base(state *s) {
|
|||
case TOK_OPEN:
|
||||
next_token(s);
|
||||
ret = expr(s);
|
||||
if (s->type == TOK_CLOSE) {
|
||||
if (s->type == TOK_CLOSE)
|
||||
next_token(s);
|
||||
else if (s->type != TOK_ERROR && s->type != TOK_END && s->error == TE_ERROR_NONE) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_TOO_MANY_ARGS;
|
||||
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
|
||||
|
|
|
@ -129,6 +129,18 @@ not math '2 + 2 4'
|
|||
# CHECKERR: math: Error: Too many arguments
|
||||
# CHECKERR: '2 + 2 4'
|
||||
# CHECKERR: ^
|
||||
not math '(1 2)'
|
||||
# CHECKERR: math: Error: Too many arguments
|
||||
# CHECKERR: '(1 2)'
|
||||
# CHECKERR: ^
|
||||
not math '(1 pi)'
|
||||
# CHECKERR: math: Error: Too many arguments
|
||||
# CHECKERR: '(1 pi)'
|
||||
# CHECKERR: ^
|
||||
not math '(1 pow 1,2)'
|
||||
# CHECKERR: math: Error: Too many arguments
|
||||
# CHECKERR: '(1 pow 1,2)'
|
||||
# CHECKERR: ^
|
||||
not math
|
||||
# CHECKERR: math: expected >= 1 arguments; got 0
|
||||
not math -s 12
|
||||
|
@ -182,6 +194,11 @@ math 'log(16'
|
|||
# CHECKERR: 'log(16'
|
||||
# CHECKERR: ^
|
||||
|
||||
math '(2'
|
||||
# CHECKERR: math: Error: Missing closing parenthesis
|
||||
# CHECKERR: '(2'
|
||||
# CHECKERR: ^
|
||||
|
||||
math --base=16 255 / 15
|
||||
# CHECK: 0x11
|
||||
math -bhex 16 x 2
|
||||
|
|
Loading…
Reference in a new issue