diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2021-11-10 19:00:41 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-11-11 15:35:45 +0100 |
commit | f6b79cd82adae8fa598c5d4db6cf41c2781eb214 (patch) | |
tree | 194eb3149a52a1b10ddbb948011fcba0f25385e8 /testing | |
parent | 393a0ebc368cdf6b2be1de2097092dd1959bda36 (diff) | |
download | askama-f6b79cd82adae8fa598c5d4db6cf41c2781eb214.tar.gz askama-f6b79cd82adae8fa598c5d4db6cf41c2781eb214.tar.bz2 askama-f6b79cd82adae8fa598c5d4db6cf41c2781eb214.zip |
Implement `for … in … if …`
Diffstat (limited to 'testing')
-rw-r--r-- | testing/tests/loops.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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(), ":("); +} |