diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2017-01-08 14:37:57 +0100 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2017-01-08 14:38:00 +0100 |
commit | 75bbd40730c9d3713cc1f090478c9cf588ba2118 (patch) | |
tree | 726d6bf5cac1a8571193513f0800178bd3db9959 /tests | |
parent | 16e4daebc46377df496bccaa9747a72869b88548 (diff) | |
download | jinja2-75bbd40730c9d3713cc1f090478c9cf588ba2118.tar.gz |
Added test for the scope node
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ext.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_ext.py b/tests/test_ext.py index 9f8b9c3..9ec5ac3 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -304,6 +304,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): def test_trans(self): |