diff options
author | Adrian Moennich <adrian@planetcoding.net> | 2017-08-22 22:59:57 +0200 |
---|---|---|
committer | Adrian Moennich <adrian@planetcoding.net> | 2017-08-22 23:12:09 +0200 |
commit | cde2a54b87876bd02b283db2f52aca3d9272a92c (patch) | |
tree | 2cce6a0e6958fdb7d6c34cb9012f5216c2ab7d21 /tests | |
parent | d117425f5ed3f542100f20d3bf700ae7bc54039f (diff) | |
download | jinja2-2.9-maintenance.tar.gz |
Compile `elif` tag to `elif` instead of `else: if`2.9-maintenance
This avoids deep nesting in case of many `{% elif .. %}` blocks (which
would fail during execution) and also deep recursion (which may fail
during compilation)
fixes #759
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_core_tags.py | 9 | ||||
-rw-r--r-- | tests/test_idtracking.py | 8 |
2 files changed, 13 insertions, 4 deletions
diff --git a/tests/test_core_tags.py b/tests/test_core_tags.py index f48d8b4..19b849e 100644 --- a/tests/test_core_tags.py +++ b/tests/test_core_tags.py @@ -222,6 +222,15 @@ class TestIfCondition(object): %}...{% else %}XXX{% endif %}''') assert tmpl.render() == '...' + def test_elif_deep(self, env): + elifs = '\n'.join('{{% elif a == {0} %}}{0}'.format(i) + for i in range(1, 1000)) + tmpl = env.from_string('{{% if a == 0 %}}0{0}{{% else %}}x{{% endif %}}' + .format(elifs)) + for x in (0, 10, 999): + assert tmpl.render(a=x).strip() == str(x) + assert tmpl.render(a=1000).strip() == 'x' + def test_else(self, env): tmpl = env.from_string('{% if false %}XXX{% else %}...{% endif %}') assert tmpl.render() == '...' diff --git a/tests/test_idtracking.py b/tests/test_idtracking.py index ea01b17..29312d3 100644 --- a/tests/test_idtracking.py +++ b/tests/test_idtracking.py @@ -61,7 +61,7 @@ def test_complex(): nodes.Output([ nodes.Name('title_upper', 'load'), nodes.Call(nodes.Name('render_title', 'load'), [ - nodes.Const('Aha')], [], None, None)])], [])])]) + nodes.Const('Aha')], [], None, None)])], [], [])])]) for_loop = nodes.For( nodes.Name('item', 'store'), @@ -155,7 +155,7 @@ def test_if_branching_stores(): tmpl = nodes.Template([ nodes.If(nodes.Name('expression', 'load'), [ nodes.Assign(nodes.Name('variable', 'store'), - nodes.Const(42))], [])]) + nodes.Const(42))], [], [])]) sym = symbols_for_node(tmpl) assert sym.refs == { @@ -177,7 +177,7 @@ def test_if_branching_stores_undefined(): nodes.Assign(nodes.Name('variable', 'store'), nodes.Const(23)), nodes.If(nodes.Name('expression', 'load'), [ nodes.Assign(nodes.Name('variable', 'store'), - nodes.Const(42))], [])]) + nodes.Const(42))], [], [])]) sym = symbols_for_node(tmpl) assert sym.refs == { @@ -197,7 +197,7 @@ def test_if_branching_stores_undefined(): def test_if_branching_multi_scope(): for_loop = nodes.For(nodes.Name('item', 'store'), nodes.Name('seq', 'load'), [ nodes.If(nodes.Name('expression', 'load'), [ - nodes.Assign(nodes.Name('x', 'store'), nodes.Const(42))], []), + nodes.Assign(nodes.Name('x', 'store'), nodes.Const(42))], [], []), nodes.Include(nodes.Const('helper.html'), True, False) ], [], None, False) |