From edfc7e48c563a97399d18e3ef44fd595c0fd4e45 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Sat, 9 May 2026 10:32:47 +0200 Subject: parse tests --- src/parse/test.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ -257,9 +257,56 @@ 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> { struct CombinationGenerator<'a> { choices: &'a [&'a [u8]], -- cgit v1.2.3