aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests
diff options
context:
space:
mode:
authorLibravatar vallentin <mail@vallentin.dev>2020-12-15 18:18:05 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-12-16 09:08:12 +0100
commit6615d125bb88e7d5a30c8ba1c37869d2998c59ef (patch)
tree989e5e4379e17ecb17a1aa1ece89588ec76c7482 /testing/tests
parent230263711e7edb0110e1679f6d31353ba7cdc919 (diff)
downloadaskama-6615d125bb88e7d5a30c8ba1c37869d2998c59ef.tar.gz
askama-6615d125bb88e7d5a30c8ba1c37869d2998c59ef.tar.bz2
askama-6615d125bb88e7d5a30c8ba1c37869d2998c59ef.zip
Added more loop tests
Diffstat (limited to 'testing/tests')
-rw-r--r--testing/tests/loops.rs36
1 files changed, 36 insertions, 0 deletions
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");
+}