aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar yossyJ <28825627+yossyJ@users.noreply.github.com>2019-01-05 20:18:59 +0900
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-01-08 15:59:45 +0100
commitdf07f7f5e3345ced96decb0cb4c4f1bdfcdb1b12 (patch)
treee6619644eec17048143e1bca34ee37dc0701dae8 /testing
parentc5c37f56a1232ff924a6bfda6c1c05e64a6241b1 (diff)
downloadaskama-df07f7f5e3345ced96decb0cb4c4f1bdfcdb1b12.tar.gz
askama-df07f7f5e3345ced96decb0cb4c4f1bdfcdb1b12.tar.bz2
askama-df07f7f5e3345ced96decb0cb4c4f1bdfcdb1b12.zip
Add support for loop.last
Diffstat (limited to '')
-rw-r--r--testing/templates/for-range.html2
-rw-r--r--testing/templates/precedence-for.html2
-rw-r--r--testing/tests/loops.rs10
3 files changed, 10 insertions, 4 deletions
diff --git a/testing/templates/for-range.html b/testing/templates/for-range.html
index 9b109bb..3688478 100644
--- a/testing/templates/for-range.html
+++ b/testing/templates/for-range.html
@@ -1,5 +1,5 @@
{% for s in 0..2 -%}
- foo
+ foo{% if loop.first %} (first){% endif %}{% if loop.last %} (last){% endif %}
{% endfor -%}
{% for s in init..1 -%}
diff --git a/testing/templates/precedence-for.html b/testing/templates/precedence-for.html
index c8d2cdd..57c900b 100644
--- a/testing/templates/precedence-for.html
+++ b/testing/templates/precedence-for.html
@@ -1,3 +1,3 @@
{% for s in strings %}
- {{- loop.index0 }}. {{ s }}{{ 2 * loop.index }}{% if !loop.first %}{% else %} (first){% endif %}
+ {{- loop.index0 }}. {{ s }}{{ 2 * loop.index }}{% if !loop.first %}{% else %} (first){% endif %}{% if loop.last %} (last){% endif %}
{% endfor %}
diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs
index b5fac7c..3ce6185 100644
--- a/testing/tests/loops.rs
+++ b/testing/tests/loops.rs
@@ -46,7 +46,10 @@ fn test_precedence_for() {
let s = PrecedenceTemplate {
strings: vec!["A", "alfa", "1"],
};
- assert_eq!(s.render().unwrap(), "0. A2 (first)\n1. alfa4\n2. 16\n");
+ assert_eq!(
+ s.render().unwrap(),
+ "0. A2 (first)\n1. alfa4\n2. 16 (last)\n"
+ );
}
#[derive(Template)]
@@ -59,5 +62,8 @@ struct ForRangeTemplate {
#[test]
fn test_for_range() {
let s = ForRangeTemplate { init: -1, end: 1 };
- assert_eq!(s.render().unwrap(), "foo\nfoo\nbar\nbar\nfoo\nbar\nbar\n");
+ assert_eq!(
+ s.render().unwrap(),
+ "foo (first)\nfoo (last)\nbar\nbar\nfoo\nbar\nbar\n"
+ );
}