diff options
author | vallentin <mail@vallentin.dev> | 2021-06-23 18:23:35 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-06-23 21:34:17 +0200 |
commit | 017b5901fb27f12c0a51738ec5f0a992e0316d8c (patch) | |
tree | 95e830aba152388b5dbe6d0046d17f7297e85ab1 /testing/tests | |
parent | e70e8f7c1d4a5266a998a57b0bb9746ce9396769 (diff) | |
download | askama-017b5901fb27f12c0a51738ec5f0a992e0316d8c.tar.gz askama-017b5901fb27f12c0a51738ec5f0a992e0316d8c.tar.bz2 askama-017b5901fb27f12c0a51738ec5f0a992e0316d8c.zip |
Added loop tests
Diffstat (limited to 'testing/tests')
-rw-r--r-- | testing/tests/loops.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index b324ae3..3bba428 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -1,3 +1,5 @@ +use std::ops::Range; + use askama::Template; #[derive(Template)] @@ -131,3 +133,84 @@ fn test_for_zip_ranges() { "0 10 30 1 11 31 2 12 32 3 13 33 4 14 34 5 15 35 6 16 36 7 17 37 8 18 38 9 19 39 " ); } + +struct ForVecAttrVec { + iterable: Vec<i32>, +} + +#[derive(Template)] +#[template( + source = "{% for x in v %}{% for y in x.iterable %}{{ y }} {% endfor %}{% endfor %}", + ext = "txt" +)] +struct ForVecAttrVecTemplate { + v: Vec<ForVecAttrVec>, +} + +#[test] +fn test_for_vec_attr_vec() { + let t = ForVecAttrVecTemplate { + v: vec![ + ForVecAttrVec { + iterable: vec![1, 2], + }, + ForVecAttrVec { + iterable: vec![3, 4], + }, + ForVecAttrVec { + iterable: vec![5, 6], + }, + ], + }; + assert_eq!(t.render().unwrap(), "1 2 3 4 5 6 "); +} + +struct ForVecAttrSlice { + iterable: &'static [i32], +} + +#[derive(Template)] +#[template( + source = "{% for x in v %}{% for y in x.iterable %}{{ y }} {% endfor %}{% endfor %}", + ext = "txt" +)] +struct ForVecAttrSliceTemplate { + v: Vec<ForVecAttrSlice>, +} + +#[test] +fn test_for_vec_attr_slice() { + let t = ForVecAttrSliceTemplate { + v: vec![ + ForVecAttrSlice { iterable: &[1, 2] }, + ForVecAttrSlice { iterable: &[3, 4] }, + ForVecAttrSlice { iterable: &[5, 6] }, + ], + }; + assert_eq!(t.render().unwrap(), "1 2 3 4 5 6 "); +} + +struct ForVecAttrRange { + iterable: Range<usize>, +} + +#[derive(Template)] +#[template( + source = "{% for x in v %}{% for y in x.iterable.clone() %}{{ y }} {% endfor %}{% endfor %}", + ext = "txt" +)] +struct ForVecAttrRangeTemplate { + v: Vec<ForVecAttrRange>, +} + +#[test] +fn test_for_vec_attr_range() { + let t = ForVecAttrRangeTemplate { + v: vec![ + ForVecAttrRange { iterable: 1..3 }, + ForVecAttrRange { iterable: 3..5 }, + ForVecAttrRange { iterable: 5..7 }, + ], + }; + assert_eq!(t.render().unwrap(), "1 2 3 4 5 6 "); +} |