Fix lstrip_blocks tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kristi Tsukida · committed by Kristi Tsukida · parent fdf8201 · Browse files · 1 file·+39 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+39 added−32 removed
- other:+39 added−32 removed
Provenance
- Commit
01d8986- Tree
2319650- Author
Kristi Tsukida <kristi.dev@gmail.com>- Committer
Kristi Tsukida <kristi.dev@gmail.com>- Parent
fdf8201
1 file changed+39 added−32 removed
modified:jinja2/testsuite/lexnparse.py+39 added-32 removed
381 unmodified lines382 class LstripBlocksTestCase(JinjaTestCase):383 384 def test_lstrip(self):385 env = Environment(lstrip_blocks=True, trim_blocks=False)386- tmpl = env.from_string(''' {% if True %}387- {% endif %}''')386+ tmpl = env.from_string(''' {% if True %}\n {% endif %}''')387 assert tmpl.render() == "\n"388 389 def test_lstrip_trim(self):390 env = Environment(lstrip_blocks=True, trim_blocks=True)392- tmpl = env.from_string(''' {% if True %}393- {% endif %}''')391+ tmpl = env.from_string(''' {% if True %}\n {% endif %}''')392 assert tmpl.render() == ""393 394+ def test_no_lstrip(self):395+ env = Environment(lstrip_blocks=True, trim_blocks=False)396+ tmpl = env.from_string(''' {%+ if True %}\n {%+ endif %}''')397+ assert tmpl.render() == " \n "398+399 def test_lstrip_endline(self):397- env = Environment(lstrip_blocks=True, trim_blocks=True)398- tmpl = env.from_string(''' {% if True %} \n {% endif %} ''')399- assert tmpl.render() == " \n "400+ env = Environment(lstrip_blocks=True, trim_blocks=False)401+ tmpl = env.from_string(''' hello{% if True %}\n goodbye{% endif %}''')402+ assert tmpl.render() == " hello\n goodbye"403 404 def test_lstrip_inline(self):405 env = Environment(lstrip_blocks=True, trim_blocks=False)403- tmpl = env.from_string(''' {% if True %}hello{% endif %}''')404- assert tmpl.render() == ' hello'406+ tmpl = env.from_string(''' {% if True %}hello {% endif %}''')407+ assert tmpl.render() == 'hello '408 409 def test_lstrip_nested(self):410 env = Environment(lstrip_blocks=True, trim_blocks=False)408- tmpl = env.from_string(''' {% if True %}{% if True %}hello{% endif %}{% endif %}''')409- assert tmpl.render() == ' hello'411+ tmpl = env.from_string(''' {% if True %}a {% if True %}b {% endif %}c {% endif %}''')412+ assert tmpl.render() == 'a b c '413 414 def test_lstrip_left_chars(self):415 env = Environment(lstrip_blocks=True, trim_blocks=False)416 tmpl = env.from_string(''' abc {% if True %}8 unmodified lines425 assert tmpl.render() == '\nhello\n'426 427 def test_lstrip_preserve_leading_newlines(self):428 env = Environment(lstrip_blocks=True, trim_blocks=False)426- tmpl = env.from_string('''\429+ tmpl = env.from_string('''\n\n\n{% set hello = 1 %}''')430+ assert tmpl.render() == '\n\n\n'431 428- {% if True %}429- hello430-431- {% endif %}''')432- assert tmpl.render() == ' \n\n hello\n\n'433- 432 def test_lstrip_comment(self):433 env = Environment(lstrip_blocks=True, trim_blocks=False)434 tmpl = env.from_string(''' {# if True #}435 hello2 unmodified lines438 439 def test_lstrip_angle_bracket_simple(self):440 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',441 lstrip_blocks=True, trim_blocks=True)444- tmpl = env.from_string('''\445- <% if True %>hello<% endif %>''')446- assert tmpl.render() == ' hello'442+ tmpl = env.from_string(''' <% if True %>hello <% endif %>''')443+ assert tmpl.render() == 'hello '444 445 def test_lstrip_angle_bracket_comment(self):446 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',447 lstrip_blocks=True, trim_blocks=True)9 unmodified lines457 <% for item in seq %>458 ${item} ## the rest of the stuff459 <% endfor %>''')460 assert tmpl.render(seq=range(5)) == \464- ' ' + ''.join(str(x) + '\n' for x in range(5))461+ ' ' + ''.join('%s\n' % x for x in range(5))462 463 def test_lstrip_angle_bracket_compact(self):464 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',465 lstrip_blocks=True, trim_blocks=True)34 unmodified lines500 <?=item?>501 <?endfor?>''')502 assert tmpl.render(seq=range(5)) == ' ' + ''.join(' %s\n' % x for x in range(5))503 507- def test_erb_syntax_with_manual(self):508- env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',509- lstrip_blocks=True, trim_blocks=True)510- tmpl = env.from_string('''\511-<%# I'm a comment, I'm not interesting %>512- <% for item in seq -%>513- <%= item %>514- <%- endfor %>''')515- assert tmpl.render(seq=range(5)) == '01234'516-504 def test_erb_syntax(self):505 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',506 lstrip_blocks=True, trim_blocks=True)507 #env.from_string('')8 unmodified lines516 <% endfor %>517 ''')518 assert tmpl.render(seq=range(5)) == ''.join(' %s\n' % x for x in range(5))519 520+ def test_erb_syntax_with_manual(self):521+ env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',522+ lstrip_blocks=True, trim_blocks=True)523+ tmpl = env.from_string('''\524+<%# I'm a comment, I'm not interesting %>525+ <% for item in seq -%>526+ <%= item %>527+ <%- endfor %>''')528+ assert tmpl.render(seq=range(5)) == '01234'529+530+ def test_erb_syntax_no_lstrip(self):531+ env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',532+ lstrip_blocks=True, trim_blocks=True)533+ tmpl = env.from_string('''\534+<%# I'm a comment, I'm not interesting %>535+ <%+ for item in seq -%>536+ <%= item %>537+ <%- endfor %>''')538+ assert tmpl.render(seq=range(5)) == ' 01234'539+540 def test_comment_syntax(self):541 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->',542 lstrip_blocks=True, trim_blocks=True)543 tmpl = env.from_string('''\13 unmodified lines