From 6615d125bb88e7d5a30c8ba1c37869d2998c59ef Mon Sep 17 00:00:00 2001 From: vallentin Date: Tue, 15 Dec 2020 18:18:05 +0100 Subject: Added more loop tests --- testing/tests/loops.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'testing/tests/loops.rs') diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index 3ce6185..4345b4f 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -67,3 +67,39 @@ fn test_for_range() { "foo (first)\nfoo (last)\nbar\nbar\nfoo\nbar\nbar\n" ); } + +#[derive(Template)] +#[template(source = "{% for i in [1, 2, 3] %}{{ i }}{% endfor %}", ext = "txt")] +struct ForArrayTemplate {} + +#[test] +fn test_for_array() { + let t = ForArrayTemplate {}; + assert_eq!(t.render().unwrap(), "123"); +} + +#[derive(Template)] +#[template( + source = "{% for i in [1, 2, 3].iter() %}{{ i }}{% endfor %}", + ext = "txt" +)] +struct ForMethodCallTemplate {} + +#[test] +fn test_for_method_call() { + let t = ForMethodCallTemplate {}; + assert_eq!(t.render().unwrap(), "123"); +} + +#[derive(Template)] +#[template( + source = "{% for i in [1, 2, 3, 4, 5][3..] %}{{ i }}{% endfor %}", + ext = "txt" +)] +struct ForIndexTemplate {} + +#[test] +fn test_for_index() { + let t = ForIndexTemplate {}; + assert_eq!(t.render().unwrap(), "45"); +} -- cgit