From c0f9fe973e6ff608f4f02f8a6cd39f2e9c50ea5c Mon Sep 17 00:00:00 2001 From: bott Date: Thu, 13 Sep 2018 23:40:17 +0200 Subject: Fix operator preference at loop.first --- testing/templates/precedence-for.html | 3 +++ testing/tests/loops.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 testing/templates/precedence-for.html (limited to 'testing') diff --git a/testing/templates/precedence-for.html b/testing/templates/precedence-for.html new file mode 100644 index 0000000..e5f7e8b --- /dev/null +++ b/testing/templates/precedence-for.html @@ -0,0 +1,3 @@ +{% for s in strings %} + {{- loop.index0 }}. {{ s }}{% if !loop.first %}{% else %} (first){% endif %} +{% endfor %} diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index ac19d43..6c2f35d 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -32,3 +32,17 @@ fn test_nested_for() { }; assert_eq!(s.render().unwrap(), "1\n 0a1b2c2\n 0one1two"); } + +#[derive(Template)] +#[template(path = "precedence-for.html")] +struct PrecedenceTemplate<'a> { + strings: Vec<&'a str>, +} + +#[test] +fn test_precedence_for() { + let s = PrecedenceTemplate { + strings: vec!["A", "alfa", "1"], + }; + assert_eq!(s.render().unwrap(), "0. A (first)\n1. alfa\n2. 1\n"); +} -- cgit