test_parser.py
This file
Path
tests/test_parser.py
113 lines · 2.8 KiB · Python
Last changed by
Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
History of this fileTake it
The walk stopped after 200 commits: lines older than b217886 point at it.
added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
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.added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
lines 7–30why, one step back7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment101112PHP_SYNTAX = '''\13<!-- I'm a comment, I'm not interesting -->\14<? for item in seq -?>15 <?= item ?>16<?- endfor ?>'''1718ERB_SYNTAX = '''\19<%# I'm a comment, I'm not interesting %>\20<% for item in seq -%>21 <%= item %>22<%- endfor %>'''2324COMMENT_SYNTAX = '''\25<!--# I'm a comment, I'm not interesting -->\26<!-- for item in seq --->27 ${item}28<!--- endfor -->'''2930MAKO_SYNTAX = '''\Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 31why, one step back31<%# regular comment %>added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
lines 32–35why, one step back32% for item in seq:33 ${item}34% endfor'''35Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 36–41why, one step back36MAKO_SYNTAX_LINECOMMENTS = '''\37<%# regular comment %>38% for item in seq:39 ${item} ## the rest of the stuff40% endfor'''41added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
lines 42–48why, one step back42BALANCING = '''{{{'foo':'bar'}.foo}}'''4344STARTCOMMENT = '''{# foo comment45and bar comment #}46{% macro blub() %}foo{% endmacro %}47{{ blub() }}'''48Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
line 49why, one step back49LINE_SYNTAX_PRIORITY1 = '''\Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 50–51why, one step back50/* ignore me.51 I'm a multiline comment */Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
lines 52–59why, one step back52## for item in seq:53* ${item} # this is just extra stuff54## endfor55'''5657LINE_SYNTAX_PRIORITY2 = '''\58/* ignore me.59 I'm a multiline comment */Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 60–63why, one step back60# for item in seq:61* ${item} ## this is just extra stuff62# endfor63'''added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
line 64why, one step back64Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 65why, one step back65added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886
lines 66–97why, one step back66def test_php_syntax():67 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')68 tmpl = env.from_string(PHP_SYNTAX)69 assert tmpl.render(seq=range(5)) == '01234'707172def test_erb_syntax():73 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')74 tmpl = env.from_string(ERB_SYNTAX)75 assert tmpl.render(seq=range(5)) == '01234'767778def test_comment_syntax():79 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')80 tmpl = env.from_string(COMMENT_SYNTAX)81 assert tmpl.render(seq=range(5)) == '01234'828384def test_balancing(env):85 tmpl = env.from_string(BALANCING)86 assert tmpl.render() == 'bar'878889def test_start_comment(env):90 tmpl = env.from_string(STARTCOMMENT)91 assert tmpl.render().strip() == 'foo'929394def test_line_syntax():95 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')96 tmpl = env.from_string(MAKO_SYNTAX)97 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
lines 98–106why, one step back98 range(5)99100 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')101 tmpl = env.from_string(MAKO_SYNTAX_LINECOMMENTS)102 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \103 range(5)104105106def test_line_syntax_priority():Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
lines 107–110why, one step back107 # XXX: why is the whitespace there in front of the newline?108 env = Environment('{%', '%}', '${', '}', '/*', '*/', '##', '#')109 tmpl = env.from_string(LINE_SYNTAX_PRIORITY1)110 assert tmpl.render(seq=[1, 2]).strip() == '* 1 \n* 2'Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5
line 111why, one step back111 env = Environment('{%', '%}', '${', '}', '/*', '*/', '#', '##')Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d
lines 112–113why, one step back112 tmpl = env.from_string(LINE_SYNTAX_PRIORITY2)113 assert tmpl.render(seq=[1, 2]).strip() == '* 1 \n* 2'