diff options
| author | Jonathan Stròˆbele <mail@jonathanstroebele.de> | 2025-02-13 16:23:29 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-02-24 16:25:53 +0100 |
| commit | 240421c7c4c81fe5df26274b807266bd4ca73d7f (patch) | |
| tree | e9f57be777f592e51687b8f731f2dc80fac373b2 /tests/template_tests | |
| parent | 582ba18d56167587e290545f113d3956e73a5801 (diff) | |
Fixed #36186 -- Added forloop.length variable within a template for loop.
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_for.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_for.py b/tests/template_tests/syntax_tests/test_for.py index a47a99ac65..8b8b1c4d27 100644 --- a/tests/template_tests/syntax_tests/test_for.py +++ b/tests/template_tests/syntax_tests/test_for.py @@ -356,6 +356,25 @@ class ForTagTests(SimpleTestCase): with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string("invalid_for_loop", {"items": (1, 2)}) + @setup( + { + "forloop-length": "{% for val in values %}{{ forloop.length }}{% endfor %}", + "forloop-length-reversed": "{% for val in values reversed %}" + "{{ forloop.length }}{% endfor %}", + } + ) + def test_forloop_length(self): + cases = [ + ([1, 2, 3], "333"), + ([1, 2, 3, 4, 5, 6], "666666"), + ([], ""), + ] + for values, expected_output in cases: + for template in ["forloop-length", "forloop-length-reversed"]: + with self.subTest(expected_output=expected_output, template=template): + output = self.engine.render_to_string(template, {"values": values}) + self.assertEqual(output, expected_output) + class ForNodeTests(SimpleTestCase): def test_repr(self): |
