From f6b79cd82adae8fa598c5d4db6cf41c2781eb214 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Wed, 10 Nov 2021 19:00:41 +0100 Subject: Implement `for … in … if …` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testing/tests/loops.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'testing/tests') diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index f014068..4a02153 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -417,3 +417,21 @@ fn test_for_cycle_empty() { }; assert!(t.render().is_err()) } + +#[derive(Template)] +#[template( + source = "{% for i in 0..limit if i % 2 == 1 %}{{i}}.{% else %}:({% endfor %}", + ext = "txt" +)] +struct ForInIf { + limit: usize, +} + +#[test] +fn test_for_in_if() { + let t = ForInIf { limit: 10 }; + assert_eq!(t.render().unwrap(), "1.3.5.7.9."); + + let t = ForInIf { limit: 1 }; + assert_eq!(t.render().unwrap(), ":("); +} -- cgit