diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/parse/test.rs | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/parse/test.rs b/src/parse/test.rs index 768a5a2..cc3d4a3 100644 --- a/src/parse/test.rs +++ b/src/parse/test.rs @@ -258,8 +258,55 @@ fn if_else() { } #[test] +fn if_elif_else() { + parse_test!( + parse(b"if a { b } elif c { d } else { e }"), + cond( + pipes([cmd([estr(b"a")]),]), + block([pipes([cmd([estr(b"b")]),])]), + block([cond( + pipes([cmd([estr(b"c")]),]), + block([pipes([cmd([estr(b"d")]),])]), + block([pipes([cmd([estr(b"e")]),])]) + )]) + ) + ); +} + +#[test] +fn if_elif_else_newlines() { + parse_test!( + parse( + b" +if a { + b +} elif c { + d +} else { + e +}" + ), + cond( + pipes([cmd([estr(b"a")]),]), + block([pipes([cmd([estr(b"b")]),])]), + block([cond( + pipes([cmd([estr(b"c")]),]), + block([pipes([cmd([estr(b"d")]),])]), + block([pipes([cmd([estr(b"e")]),])]) + )]) + ) + ); +} + +#[test] fn simple_while() { - parse_test!(parse(b"while cond { x }"), whil(pipes([cmd([estr(b"cond")]),]), block([pipes([cmd([estr(b"x")]),])]))); + parse_test!( + parse(b"while cond { x }"), + whil( + pipes([cmd([estr(b"cond")]),]), + block([pipes([cmd([estr(b"x")]),])]) + ) + ); } #[test] @@ -357,6 +404,30 @@ fn backslash_joins_lines() { ) } +#[test] +fn pipe_on_newline_n() { + parse_test!( + parse(b"x\n| y"), + pipes([cmd([estr(b"x")]), cmd([estr(b"y")]),]) + ) +} + +#[test] +fn pipe_on_newline_r() { + parse_test!( + parse(b"x\r| y"), + pipes([cmd([estr(b"x")]), cmd([estr(b"y")]),]) + ) +} + +#[test] +fn pipe_on_newline_rn() { + parse_test!( + parse(b"x\r\n| y"), + pipes([cmd([estr(b"x")]), cmd([estr(b"y")]),]) + ) +} + fn combinations(choices: &[&[u8]], n: usize) -> impl Iterator<Item = Vec<u8>> { struct CombinationGenerator<'a> { choices: &'a [&'a [u8]], |
