diff options
| -rw-r--r-- | src/parse/mod.rs | 16 | ||||
| -rw-r--r-- | src/parse/test.rs | 18 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 8cc6a4f..47aff20 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -124,6 +124,22 @@ pub fn pipes<const N: usize>(cmds: [Command<PreExpansion>; N]) -> Ast<PreExpansi }) } +pub fn cond( + condition: Ast<PreExpansion>, + true_block: Block, + false_block: Block, +) -> Ast<PreExpansion> { + let Ast::Pipes(condition) = condition else { + panic!() + }; + Ast::If(If { + condition, + true_block, + false_block, + parse_progress: IfParseProgress::Done, + }) +} + pub fn estr(x: &[u8]) -> ExpString { ExpString { parts: vec![StringPart::Boring(x.to_vec())], diff --git a/src/parse/test.rs b/src/parse/test.rs index 01dea5d..f4ac92e 100644 --- a/src/parse/test.rs +++ b/src/parse/test.rs @@ -235,12 +235,26 @@ fn newline_does_not_separate_pipes() { #[test] fn simple_if() { - parse_test!(parse(b"if cond { x }"), todo!()); + parse_test!( + parse(b"if cond { x }"), + cond( + pipes([cmd([estr(b"cond")]),]), + block([pipes([cmd([estr(b"x")]),])]), + block([]) + ) + ); } #[test] fn if_else() { - parse_test!(parse(b"if cond { x } else { y }"), todo!()); + parse_test!( + parse(b"if cond { x } else { y }"), + cond( + pipes([cmd([estr(b"cond")]),]), + block([pipes([cmd([estr(b"x")]),])]), + block([pipes([cmd([estr(b"y")]),])]) + ) + ); } #[test] |
