From: Armin Ronacher Date: Sun, 8 Jan 2017 13:37:57 +0000 (+0100) Subject: Added test for the scope node X-Git-Tag: 2.9.3~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75bbd40730c9d3713cc1f090478c9cf588ba2118;p=thirdparty%2Fjinja.git Added test for the scope node --- diff --git a/tests/test_ext.py b/tests/test_ext.py index 9f8b9c3a..9ec5ac35 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -303,6 +303,39 @@ class TestInternationalization(object): ] +@pytest.mark.ext +class TestScope(object): + + def test_basic_scope_behavior(self): + # This is what the old with statement compiled down to + class ScopeExt(Extension): + tags = set(['scope']) + + def parse(self, parser): + node = nodes.Scope(lineno=next(parser.stream).lineno) + assignments = [] + while parser.stream.current.type != 'block_end': + lineno = parser.stream.current.lineno + if assignments: + parser.stream.expect('comma') + target = parser.parse_assign_target() + parser.stream.expect('assign') + expr = parser.parse_expression() + assignments.append(nodes.Assign(target, expr, lineno=lineno)) + node.body = assignments + \ + list(parser.parse_statements(('name:endscope',), + drop_needle=True)) + return node + + env = Environment(extensions=[ScopeExt]) + tmpl = env.from_string('''\ + {%- with a=1, b=2, c=b, d=e, e=5 -%} + {{ a }}|{{ b }}|{{ c }}|{{ d }}|{{ e }} + {%- endwith -%} + ''') + assert tmpl.render(b=3, e=4) == '1|2|2|4|5' + + @pytest.mark.ext class TestNewstyleInternationalization(object):