mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Merge pull request #5566 from Luv-Ray/fix-expr-issue5560
`expr`: check prefix operation
This commit is contained in:
commit
dbb29ec400
2 changed files with 26 additions and 2 deletions
|
@ -332,8 +332,12 @@ fn push_token_to_either_stack(
|
|||
}
|
||||
|
||||
Token::PrefixOp { .. } | Token::ParOpen => {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
Ok(())
|
||||
if out_stack.is_empty() {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from("syntax error (operation should be prefix)"))
|
||||
}
|
||||
}
|
||||
|
||||
Token::ParClose => move_till_match_paren(out_stack, op_stack),
|
||||
|
|
|
@ -100,6 +100,11 @@ fn test_parenthesis() {
|
|||
.args(&["(", "1", "+", "1", ")", "*", "2"])
|
||||
.succeeds()
|
||||
.stdout_only("4\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["1", "(", ")"])
|
||||
.fails()
|
||||
.stderr_only("expr: syntax error (operation should be prefix)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -221,6 +226,11 @@ fn test_index() {
|
|||
.args(&["index", "αbcdef_f", "f"])
|
||||
.succeeds()
|
||||
.stdout_only("6\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["αbcdef", "index", "α"])
|
||||
.fails()
|
||||
.stderr_only("expr: syntax error (operation should be prefix)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -234,6 +244,11 @@ fn test_length() {
|
|||
.args(&["length", "abcdef"])
|
||||
.succeeds()
|
||||
.stdout_only("6\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["abcdef", "length"])
|
||||
.fails()
|
||||
.stderr_only("expr: syntax error (operation should be prefix)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -271,6 +286,11 @@ fn test_substr() {
|
|||
.args(&["substr", "abc", "1", "1"])
|
||||
.succeeds()
|
||||
.stdout_only("a\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["abc", "substr", "1", "1"])
|
||||
.fails()
|
||||
.stderr_only("expr: syntax error (operation should be prefix)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue