Add tests for if/else if/else/if

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-09 11:40:12 +01:00
parent c9314a3d9b
commit ef02e94591
3 changed files with 166 additions and 2 deletions

View file

@ -675,11 +675,61 @@ mod tests {
}
#[test]
fn check_empty_output() {
fn check_empty_if_output() {
let input = "{{ if foo }}{{ end }}";
let parsed = crate::parser::parse(input.into()).unwrap();
panic_pretty(input, parse(parsed.tokens()));
let ast = panic_pretty(input, parse(parsed.tokens()));
insta::assert_debug_snapshot!(ast, @r#"
TemplateAst {
root: [
ConditionalChain {
chain: [
IfConditional {
if_block: Block {
prev_whitespace_content: None,
expression: VariableAccess(
[Ident]"foo" (6..9),
),
post_whitespace_content: None,
},
},
ConditionalContent {
content: [],
},
Block {
prev_whitespace_content: None,
expression: EndBlock,
post_whitespace_content: None,
},
],
},
],
}
"#);
}
#[test]
fn check_if_else() {
let input = "{{ if foo }} foo {{ else }} bar {{ end }}";
let parsed = crate::parser::parse(input.into()).unwrap();
let ast = panic_pretty(input, parse(parsed.tokens()));
insta::assert_debug_snapshot!(ast);
}
#[test]
fn check_if_else_if() {
let input = "{{ if foo }} foo {{ else if bar }} bar {{ end }}";
let parsed = crate::parser::parse(input.into()).unwrap();
let ast = panic_pretty(input, parse(parsed.tokens()));
insta::assert_debug_snapshot!(ast);
}
}