From a7e108cd76a2a89dfdf0dfb87b1286ec3a523f08 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 8 Oct 2024 17:54:09 -0400 Subject: [PATCH] feat: add test for if let containing a for loop --- testing/templates/if-let-with-for.html | 11 +++++++++++ testing/tests/if_let.rs | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 testing/templates/if-let-with-for.html diff --git a/testing/templates/if-let-with-for.html b/testing/templates/if-let-with-for.html new file mode 100644 index 00000000..b0de7f98 --- /dev/null +++ b/testing/templates/if-let-with-for.html @@ -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 -%} diff --git a/testing/tests/if_let.rs b/testing/tests/if_let.rs index d3834181..da5428bf 100644 --- a/testing/tests/if_let.rs +++ b/testing/tests/if_let.rs @@ -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, +} + +struct IfLetWithForTemplateThing { + items: Vec, +} + +#[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(), ""); +}