mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
test: fixing unary operators that are getting parsed as argument instead of string literal (#9951)
* Check for three-string comparison in test * Add regression tests for unary operator in three-arg form
This commit is contained in:
@@ -188,7 +188,16 @@ impl Parser {
|
||||
match symbol {
|
||||
Symbol::LParen => self.lparen()?,
|
||||
Symbol::Bang => self.bang()?,
|
||||
Symbol::UnaryOp(_) => self.uop(symbol),
|
||||
Symbol::UnaryOp(_) => {
|
||||
// Three-argument string comparison: `-f = a` means "-f" = "a", not file test
|
||||
let is_string_cmp = matches!(self.peek(), Symbol::Op(Operator::String(_)))
|
||||
&& !matches!(Symbol::new(self.tokens.clone().nth(1)), Symbol::None);
|
||||
if is_string_cmp {
|
||||
self.literal(symbol.into_literal())?;
|
||||
} else {
|
||||
self.uop(symbol);
|
||||
}
|
||||
}
|
||||
Symbol::None => self.stack.push(symbol),
|
||||
literal => self.literal(literal)?,
|
||||
}
|
||||
|
||||
@@ -1027,3 +1027,10 @@ fn test_string_lt_gt_operator() {
|
||||
.fails_with_code(1)
|
||||
.no_output();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unary_op_as_literal_in_three_arg_form() {
|
||||
// `-f = a` is string comparison "-f" = "a", not file test
|
||||
new_ucmd!().args(&["-f", "=", "a"]).fails_with_code(1);
|
||||
new_ucmd!().args(&["-f", "=", "a", "-o", "b"]).succeeds();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user