Skip to content

Commit

Permalink
Test and fix lexing of redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Mar 21, 2024
1 parent 6ada4f8 commit 5cff29e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/line/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(&[
r"'(?<singlequoted>[^']*)'",
r#""(?<doublequoted>[^"]*)""#,
r#"(?<strayquotes>['"]+)"#,
r#"(?<unquoted>[^'"\s]+)"#,
r#"(?<unquoted>[^'">\s]+)"#,
].join("|")).unwrap());

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -73,4 +73,15 @@ mod tests {
// TODO: Should we parse adjacent stuff as one arg?
assert_eq!(lex(r#"echo '"Hello 'world 1234"#), vec![arg("echo"), arg("\"Hello "), arg("world"), arg("1234")]);
}

#[test]
fn redirects() {
assert_eq!(lex(">"), vec![redirect()]);
assert_eq!(lex(">>"), vec![redirect(), redirect()]);
assert_eq!(lex(">a"), vec![redirect(), arg("a")]);
assert_eq!(lex(">1"), vec![redirect(), arg("1")]);
assert_eq!(lex(" >0> 1"), vec![redirect(), arg("0"), redirect(), arg("1")]);
assert_eq!(lex("echo Test > a"), vec![arg("echo"), arg("Test"), redirect(), arg("a")]);
assert_eq!(lex(r#"echo '{"x": 23,"y":3}' > /dev/null"#), vec![arg("echo"), arg(r#"{"x": 23,"y":3}"#), redirect(), arg("/dev/null")])
}
}

0 comments on commit 5cff29e

Please sign in to comment.