diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-05-09 10:32:47 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-05-09 10:32:47 +0200 |
| commit | edfc7e48c563a97399d18e3ef44fd595c0fd4e45 (patch) | |
| tree | 7e1318aee2fd1ae141514c447680129a0fda76bc | |
| parent | 8d02827c6dd3f14f0722c685938359fef4fb9d38 (diff) | |
| download | pish-edfc7e48c563a97399d18e3ef44fd595c0fd4e45.tar.gz | |
parse tests
| -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]], |
