diff options
-rw-r--r-- | testing/templates/nested-for.html | 6 | ||||
-rw-r--r-- | testing/tests/loops.rs | 17 |
2 files changed, 23 insertions, 0 deletions
diff --git a/testing/templates/nested-for.html b/testing/templates/nested-for.html new file mode 100644 index 0000000..6e0cd72 --- /dev/null +++ b/testing/templates/nested-for.html @@ -0,0 +1,6 @@ +{% for seq in seqs -%} + {{ loop.index }} + {% for v in seq -%} + {{ loop.index0 }}{{ v }} + {%- endfor -%} +{% endfor %} diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index 4776729..bb245a4 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -16,3 +16,20 @@ fn test_for() { }; assert_eq!(s.render(), "0. A\n1. alfa\n2. 1\n"); } + + +#[derive(Template)] +#[template(path = "nested-for.html", print = "code")] +struct NestedForTemplate<'a> { + seqs: Vec<&'a [&'a str]>, +} + +#[test] +fn test_nested_for() { + let alpha = vec!["a", "b", "c"]; + let numbers = vec!["one", "two"]; + let s = NestedForTemplate { + seqs: vec![&alpha, &numbers], + }; + assert_eq!(s.render(), "1\n 0a1b2c2\n 0one1two"); +} |