Add tests for if/else if/else/if
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
c9314a3d9b
commit
ef02e94591
3 changed files with 166 additions and 2 deletions
|
|
@ -675,11 +675,61 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_empty_output() {
|
fn check_empty_if_output() {
|
||||||
let input = "{{ if foo }}{{ end }}";
|
let input = "{{ if foo }}{{ end }}";
|
||||||
|
|
||||||
let parsed = crate::parser::parse(input.into()).unwrap();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
55
src/ast/snapshots/nomo__ast__tests__check_if_else.snap
Normal file
55
src/ast/snapshots/nomo__ast__tests__check_if_else.snap
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
---
|
||||||
|
source: src/ast/mod.rs
|
||||||
|
expression: ast
|
||||||
|
---
|
||||||
|
TemplateAst {
|
||||||
|
root: [
|
||||||
|
ConditionalChain {
|
||||||
|
chain: [
|
||||||
|
IfConditional {
|
||||||
|
if_block: Block {
|
||||||
|
prev_whitespace_content: None,
|
||||||
|
expression: VariableAccess(
|
||||||
|
[Ident]"foo" (6..9),
|
||||||
|
),
|
||||||
|
post_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (12..13),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ConditionalContent {
|
||||||
|
content: [
|
||||||
|
StaticContent(
|
||||||
|
[Content]"foo" (13..16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
Block {
|
||||||
|
prev_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (16..17),
|
||||||
|
),
|
||||||
|
expression: ElseConditional {
|
||||||
|
expression: None,
|
||||||
|
},
|
||||||
|
post_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (27..28),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
ConditionalContent {
|
||||||
|
content: [
|
||||||
|
StaticContent(
|
||||||
|
[Content]"bar" (28..31),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
Block {
|
||||||
|
prev_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (31..32),
|
||||||
|
),
|
||||||
|
expression: EndBlock,
|
||||||
|
post_whitespace_content: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
59
src/ast/snapshots/nomo__ast__tests__check_if_else_if.snap
Normal file
59
src/ast/snapshots/nomo__ast__tests__check_if_else_if.snap
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
---
|
||||||
|
source: src/ast/mod.rs
|
||||||
|
expression: ast
|
||||||
|
---
|
||||||
|
TemplateAst {
|
||||||
|
root: [
|
||||||
|
ConditionalChain {
|
||||||
|
chain: [
|
||||||
|
IfConditional {
|
||||||
|
if_block: Block {
|
||||||
|
prev_whitespace_content: None,
|
||||||
|
expression: VariableAccess(
|
||||||
|
[Ident]"foo" (6..9),
|
||||||
|
),
|
||||||
|
post_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (12..13),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ConditionalContent {
|
||||||
|
content: [
|
||||||
|
StaticContent(
|
||||||
|
[Content]"foo" (13..16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
Block {
|
||||||
|
prev_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (16..17),
|
||||||
|
),
|
||||||
|
expression: ElseConditional {
|
||||||
|
expression: Some(
|
||||||
|
VariableAccess(
|
||||||
|
[Ident]"bar" (28..31),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
post_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (34..35),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
ConditionalContent {
|
||||||
|
content: [
|
||||||
|
StaticContent(
|
||||||
|
[Content]"bar" (35..38),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
Block {
|
||||||
|
prev_whitespace_content: Some(
|
||||||
|
[Whitespace]" " (38..39),
|
||||||
|
),
|
||||||
|
expression: EndBlock,
|
||||||
|
post_whitespace_content: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue