Commits

Jason Pellerin committed b475e16

Added regression test for nested loops & context

  • Participants
  • Parent commits c859c8e

Comments (0)

Files changed (1)

File tests/test_forloop.py

     {%- for item in foo %}{{ 'hello'|itemtimes }}{% endfor -%}
     ''')
     assert t.render(foo=(2,)) == 'hellohellohello'
+
+
+def test_scoping_context_func_nested_loop():
+    tmpl = ('''
+    {%- for item in foo %}{% for thing in stuff %}{{ callme() }}:{% endfor -%}
+    /{% endfor -%}''')
+    print env.compile(tmpl, raw=True)
+    t = env.from_string(tmpl)
+    @contextfunction
+    def callme(context):
+        assert 'item' in context
+        assert 'loop' in context
+        assert 'thing' in context
+        return "%s.%s.%s" % (
+            context['item'], context['thing'], context['loop'].index)
+    expect = '1.1.1:1.2.2:/2.1.1:2.2.2:/3.1.1:3.2.2:/'
+    result = t.render(foo=(1,2,3), stuff=(1,2,), callme=callme)
+    assert result == expect
+