]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Added a test for macro scoping in loops
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jan 2017 20:48:53 +0000 (21:48 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jan 2017 20:48:53 +0000 (21:48 +0100)
tests/test_regression.py

index adc651e9b9fe8dd56914a274affdfb44eaa1a38f..4deaebe90a5f3ecf27ac9659a2a902027b9034e4 100644 (file)
@@ -335,3 +335,20 @@ class TestBug(object):
         template = "{% macro m() %}<html>{% endmacro %}"
         template += "{% autoescape true %}{{ m() }}{% endautoescape %}"
         assert env.from_string(template).render()
+
+    def test_macro_scoping(self, env):
+        tmpl = env.from_string('''
+        {% set n=[1,2,3,4,5] %}
+        {% for n in [[1,2,3], [3,4,5], [5,6,7]] %}
+
+        {% macro x(l) %}
+          {{ l.pop() }}
+          {% if l %}{{ x(l) }}{% endif %}
+        {% endmacro %}
+
+        {{ x(n) }}
+
+        {% endfor %}
+        ''')
+        assert list(map(int, tmpl.render().split())) == \
+            [3, 2, 1, 5, 4, 3, 7, 6, 5]