mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
expr: fix substr parsing
This commit is contained in:
parent
83424751c1
commit
6049bc091a
2 changed files with 16 additions and 3 deletions
|
@ -685,9 +685,9 @@ impl<'a, S: AsRef<str>> Parser<'a, S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"substr" => {
|
"substr" => {
|
||||||
let string = self.parse_expression()?;
|
let string = self.parse_simple_expression()?;
|
||||||
let pos = self.parse_expression()?;
|
let pos = self.parse_simple_expression()?;
|
||||||
let length = self.parse_expression()?;
|
let length = self.parse_simple_expression()?;
|
||||||
AstNodeInner::Substr {
|
AstNodeInner::Substr {
|
||||||
string: Box::new(string),
|
string: Box::new(string),
|
||||||
pos: Box::new(pos),
|
pos: Box::new(pos),
|
||||||
|
|
|
@ -507,6 +507,19 @@ fn test_substr() {
|
||||||
.stderr_only("expr: syntax error: unexpected argument 'substr'\n");
|
.stderr_only("expr: syntax error: unexpected argument 'substr'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_substr_precedence() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["substr", "ab cd", "3", "1", "!=", " "])
|
||||||
|
.fails_with_code(1)
|
||||||
|
.stdout_only("0\n");
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["substr", "ab cd", "2", "1", "!=", " "])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("1\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_substr() {
|
fn test_invalid_substr() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue