Skip to content
Myr

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

1 file+39 added−32 removed

modified:jinja2/testsuite/lexnparse.py+39 added-32 removed
381 unmodified lines
382class LstripBlocksTestCase(JinjaTestCase):383384 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"388389 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() == ""393394 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 "398399 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"403404 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 '408409 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 '413414 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 lines
425 assert tmpl.render() == '\nhello\n'426427 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 hello430431 {% 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 #}435hello
2 unmodified lines
438439 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 '444445 def test_lstrip_angle_bracket_comment(self):446 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',447 lstrip_blocks=True, trim_blocks=True)
9 unmodified lines
457 <% 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 lines
500 <?=item?>501 <?endfor?>''')502 assert tmpl.render(seq=range(5)) == ' ' + ''.join(' %s\n' % x for x in range(5))503507 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'516504 def test_erb_syntax(self):505 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',506 lstrip_blocks=True, trim_blocks=True)507 #env.from_string('')
8 unmodified lines
516 <% endfor %>517''')518 assert tmpl.render(seq=range(5)) == ''.join(' %s\n' % x for x in range(5))519520 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'529530 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'539540 def test_comment_syntax(self):541 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->',542 lstrip_blocks=True, trim_blocks=True)543 tmpl = env.from_string('''\
13 unmodified lines