Skip to content

Commit

Permalink
feat: add test for if let containing a for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute authored and djc committed Oct 9, 2024
1 parent 3c7389f commit a7e108c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/templates/if-let-with-for.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- if let Some(thing) = thing -%}
{%- for item in thing.items -%}
{{ item }}
{%- endfor -%}
{%- endif -%}

{%- if let Some(thing) = thing -%}
{%- for item in thing.items -%}
{{ item }}
{%- endfor -%}
{%- endif -%}
23 changes: 23 additions & 0 deletions testing/tests/if_let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,26 @@ fn test_elif() {
assert_eq!(Elif { s: None }.render().unwrap(), "empty");
assert_eq!(Elif { s: Some("tada") }.render().unwrap(), "tada");
}

#[derive(Template)]
#[template(path = "if-let-with-for.html")]
struct IfLetWithForTemplate {
thing: Option<IfLetWithForTemplateThing>,
}

struct IfLetWithForTemplateThing {
items: Vec<usize>,
}

#[test]
fn test_if_let_with_for() {
let s = IfLetWithForTemplate {
thing: Some(IfLetWithForTemplateThing {
items: vec![1, 2, 3],
}),
};
assert_eq!(s.render().unwrap(), "123123");

let t = IfLetWithForTemplate { thing: None };
assert_eq!(t.render().unwrap(), "");
}

0 comments on commit a7e108c

Please sign in to comment.