Add tests for lstrip whitespace behavior fix
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Also did peformance tests for the previous fix and saw no measurable impact.
authored by Peter Dolak · committed by Peter Dolak · parent dbbd082 · Browse files · 2 files·+94 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
2 files+94 added−0 removed
- tests:+92 added−0 removed
- other:+2 added−0 removed
Provenance
- Commit
7163513- Tree
d01904e- Author
Peter Dolak <peter.dolak@exponea.com>- Committer
Peter Dolak <peter.dolak@exponea.com>- Parent
dbbd082
2 files changed+94 added−0 removed
modified:tests/test_lexnparse.py+92 added
727 unmodified lines728 <%endfor%>"""729 )730 assert tmpl.render(seq=range(5)) == "".join("%s\n" % x for x in range(5))731 732+ def test_lstrip_blocks_outside_with_new_line(self):733+ env = Environment(lstrip_blocks=True, trim_blocks=False)734+ tmpl = env.from_string(735+ " {% if kvs %}(\n"736+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}\n"737+ " ){% endif %}"738+ )739+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])740+ assert out == "(\na=1 b=2 \n )"741+742+ def test_lstrip_trim_blocks_outside_with_new_line(self):743+ env = Environment(lstrip_blocks=True, trim_blocks=True)744+ tmpl = env.from_string(745+ " {% if kvs %}(\n"746+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}\n"747+ " ){% endif %}"748+ )749+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])750+ assert out == "(\na=1 b=2 )"751+752+ def test_lstrip_blocks_inside_with_new_line(self):753+ env = Environment(lstrip_blocks=True, trim_blocks=False)754+ tmpl = env.from_string(755+ " ({% if kvs %}\n"756+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}\n"757+ " {% endif %})"758+ )759+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])760+ assert out == " (\na=1 b=2 \n)"761+762+ def test_lstrip_trim_blocks_inside_with_new_line(self):763+ env = Environment(lstrip_blocks=True, trim_blocks=True)764+ tmpl = env.from_string(765+ " ({% if kvs %}\n"766+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}\n"767+ " {% endif %})"768+ )769+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])770+ assert out == " (a=1 b=2 )"771+772+ def test_lstrip_blocks_without_new_line(self):773+ env = Environment(lstrip_blocks=True, trim_blocks=False)774+ tmpl = env.from_string(775+ " {% if kvs %}"776+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}"777+ " {% endif %}"778+ )779+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])780+ assert out == " a=1 b=2 "781+782+ def test_lstrip_trim_blocks_without_new_line(self):783+ env = Environment(lstrip_blocks=True, trim_blocks=True)784+ tmpl = env.from_string(785+ " {% if kvs %}"786+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor %}"787+ " {% endif %}"788+ )789+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])790+ assert out == " a=1 b=2 "791+792+ def test_lstrip_blocks_consume_after_without_new_line(self):793+ env = Environment(lstrip_blocks=True, trim_blocks=False)794+ tmpl = env.from_string(795+ " {% if kvs -%}"796+ " {% for k, v in kvs %}{{ k }}={{ v }} {% endfor -%}"797+ " {% endif -%}"798+ )799+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])800+ assert out == "a=1 b=2 "801+802+ def test_lstrip_trim_blocks_consume_before_without_new_line(self):803+ env = Environment(lstrip_blocks=False, trim_blocks=False)804+ tmpl = env.from_string(805+ " {%- if kvs %}"806+ " {%- for k, v in kvs %}{{ k }}={{ v }} {% endfor -%}"807+ " {%- endif %}"808+ )809+ out = tmpl.render(kvs=[("a", 1), ("b", 2)])810+ assert out == "a=1 b=2 "811+812+ def test_lstrip_trim_blocks_comment(self):813+ env = Environment(lstrip_blocks=True, trim_blocks=True)814+ tmpl = env.from_string(" {# 1 space #}\n {# 2 spaces #} {# 4 spaces #}")815+ out = tmpl.render()816+ assert out == " " * 4817+818+ def test_lstrip_trim_blocks_raw(self):819+ env = Environment(lstrip_blocks=True, trim_blocks=True)820+ tmpl = env.from_string("{{x}}\n{%- raw %} {% endraw -%}\n{{ y }}")821+ out = tmpl.render(x=1, y=2)822+ assert out == "1 2"823+824 def test_php_syntax_with_manual(self, env):825 env = Environment(826 "<?", "?>", "<?=", "?>", "<!--", "-->", lstrip_blocks=True, trim_blocks=True827 )103 unmodified linesmodified:CHANGES.rst+2 added
23 unmodified lines24 - Fix line numbers in error messages when newlines are stripped.25 :pr:`1178`26 - The special ``namespace()`` assignment object in templates works in27 async environments. :issue:`1180`28+- Fix whitespace being removed before tags in the middle of lines when29+ ``lstrip_blocks`` is enabled. :issue:`1138`30 31 32 Version 2.11.133 --------------737 unmodified lines