test_parser.py
This file
Path
tests/test_parser.py
116 lines · 2.9 KiB · Python
Last changed by
Got rid of py.testisms.Armin Ronacherbefore adoption42979eb
History of this fileTake it
The walk stopped after 200 commits: lines older than 1de4c64 point at it.
documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 1–5why, one step back1# -*- coding: utf-8 -*-2"""3 unit test for the parser4 ~~~~~~~~~~~~~~~~~~~~~~~~5Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b
line 6why, one step back6 :copyright: (c) 2009 by the Jinja Team.documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 7–10why, one step back7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment10Got rid of py.testisms.Armin Ronacherbefore adoption42979eb
line 11why, one step back11env = Environment()documented recursive loopsArmin Ronacherbefore adoption1de4c64
line 12why, one step back12merged.Armin Ronacherbefore adoption1b43b58
line 13why, one step back13documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 14–32why, one step back14PHP_SYNTAX = '''\15<!-- I'm a comment, I'm not interesting -->\16<? for item in seq -?>17 <?= item ?>18<?- endfor ?>'''1920ERB_SYNTAX = '''\21<%# I'm a comment, I'm not interesting %>\22<% for item in seq -%>23 <%= item %>24<%- endfor %>'''2526COMMENT_SYNTAX = '''\27<!--# I'm a comment, I'm not interesting -->\28<!-- for item in seq --->29 ${item}30<!--- endfor -->'''3132MAKO_SYNTAX = '''\Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 33why, one step back33<%# regular comment %>documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 34–37why, one step back34% for item in seq:35 ${item}36% endfor'''37Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 38–43why, one step back38MAKO_SYNTAX_LINECOMMENTS = '''\39<%# regular comment %>40% for item in seq:41 ${item} ## the rest of the stuff42% endfor'''43documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 44–50why, one step back44BALANCING = '''{{{'foo':'bar'}.foo}}'''4546STARTCOMMENT = '''{# foo comment47and bar comment #}48{% macro blub() %}foo{% endmacro %}49{{ blub() }}'''50Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
line 51why, one step back51LINE_SYNTAX_PRIORITY1 = '''\Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 52–53why, one step back52/* ignore me.53 I'm a multiline comment */Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
lines 54–61why, one step back54## for item in seq:55* ${item} # this is just extra stuff56## endfor57'''5859LINE_SYNTAX_PRIORITY2 = '''\60/* ignore me.61 I'm a multiline comment */Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 62–63why, one step back62# for item in seq:63* ${item} ## this is just extra stuffAdded a testcase for the last change.Armin Ronacherbefore adoption3617a02
line 64why, one step back64 ## extra stuff i just want to ignoreAdded support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 65–66why, one step back65# endfor66'''documented recursive loopsArmin Ronacherbefore adoption1de4c64
line 67why, one step back67Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 68why, one step back68documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 69–86why, one step back69def test_php_syntax():70 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')71 tmpl = env.from_string(PHP_SYNTAX)72 assert tmpl.render(seq=range(5)) == '01234'737475def test_erb_syntax():76 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')77 tmpl = env.from_string(ERB_SYNTAX)78 assert tmpl.render(seq=range(5)) == '01234'798081def test_comment_syntax():82 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')83 tmpl = env.from_string(COMMENT_SYNTAX)84 assert tmpl.render(seq=range(5)) == '01234'8586Got rid of py.testisms.Armin Ronacherbefore adoption42979eb
line 87why, one step back87def test_balancing():documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 88–91why, one step back88 tmpl = env.from_string(BALANCING)89 assert tmpl.render() == 'bar'9091Got rid of py.testisms.Armin Ronacherbefore adoption42979eb
line 92why, one step back92def test_start_comment():documented recursive loopsArmin Ronacherbefore adoption1de4c64
lines 93–100why, one step back93 tmpl = env.from_string(STARTCOMMENT)94 assert tmpl.render().strip() == 'foo'959697def test_line_syntax():98 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')99 tmpl = env.from_string(MAKO_SYNTAX)100 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \merged.Armin Ronacherbefore adoption1b43b58
line 101why, one step back101 range(5)Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 102–109why, one step back102103 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')104 tmpl = env.from_string(MAKO_SYNTAX_LINECOMMENTS)105 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \106 range(5)107108109def test_line_syntax_priority():Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
lines 110–112why, one step back110 # XXX: why is the whitespace there in front of the newline?111 env = Environment('{%', '%}', '${', '}', '/*', '*/', '##', '#')112 tmpl = env.from_string(LINE_SYNTAX_PRIORITY1)Fixed another bug with line commentsArmin Ronacherbefore adoption1bb3ab7
line 113why, one step back113 assert tmpl.render(seq=[1, 2]).strip() == '* 1\n* 2'Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 114why, one step back114 env = Environment('{%', '%}', '${', '}', '/*', '*/', '#', '##')Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
line 115why, one step back115 tmpl = env.from_string(LINE_SYNTAX_PRIORITY2)Added a testcase for the last change.Armin Ronacherbefore adoption3617a02
line 116why, one step back116 assert tmpl.render(seq=[1, 2]).strip() == '* 1\n\n* 2'