Skip to content
Myr

Added a test for macro scoping in loops

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 6a754cb · Browse files · 1 file+17 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−0 removed

  • tests:+17 added−0 removed

1 file+17 added−0 removed

modified:tests/test_regression.py+17 added
333 unmodified lines
334 autoescape=lambda x: False, extensions=['jinja2.ext.autoescape'])335 template = "{% macro m() %}<html>{% endmacro %}"336 template += "{% autoescape true %}{{ m() }}{% endautoescape %}"337 assert env.from_string(template).render()338339 def test_macro_scoping(self, env):340 tmpl = env.from_string('''341 {% set n=[1,2,3,4,5] %}342 {% for n in [[1,2,3], [3,4,5], [5,6,7]] %}343344 {% macro x(l) %}345 {{ l.pop() }}346 {% if l %}{{ x(l) }}{% endif %}347 {% endmacro %}348349 {{ x(n) }}350351 {% endfor %}352 ''')353 assert list(map(int, tmpl.render().split())) == \354 [3, 2, 1, 5, 4, 3, 7, 6, 5]