test_parser.py
This file
Path
tests/test_parser.py
75 lines · 1.7 KiB · Python
Last changed by
fixed more unittestsArmin Ronacherbefore adoption4f7d2d5
History of this fileTake it
[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
lines 1–8why, one step back1# -*- coding: utf-8 -*-2"""3 unit test for the parser4 ~~~~~~~~~~~~~~~~~~~~~~~~56 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""converted unit tests, started rewriting filtersChristoph Hackbefore adoptione9e43bb
line 9why, one step back9from jinja2 import Environment[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
lines 10–29why, one step back101112PHP_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 -->'''29fixed more unittestsArmin Ronacherbefore adoption4f7d2d5
lines 30–33why, one step back30MAKO_SYNTAX = '''\31% for item in seq:32 ${item}33% endfor'''[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
line 34why, one step back34[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
line 35why, one step back35BALANCING = '''{{{'foo':'bar'}.foo}}'''[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
line 36why, one step back36added new testcaseArmin Ronacherbefore adoption9b0545a
lines 37–40why, one step back37STARTCOMMENT = '''{# foo comment38and bar comment #}39{% macro blub() %}foo{% endmacro %}40{{ blub() }}'''[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
line 41why, one step back41added new testcaseArmin Ronacherbefore adoption9b0545a
line 42why, one step back42[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
lines 43–60why, one step back43def test_php_syntax():44 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')45 tmpl = env.from_string(PHP_SYNTAX)46 assert tmpl.render(seq=range(5)) == '01234'474849def test_erb_syntax():50 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')51 tmpl = env.from_string(ERB_SYNTAX)52 assert tmpl.render(seq=range(5)) == '01234'535455def test_comment_syntax():56 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')57 tmpl = env.from_string(COMMENT_SYNTAX)58 assert tmpl.render(seq=range(5)) == '01234'5960[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
lines 61–63why, one step back61def test_balancing(env):62 tmpl = env.from_string(BALANCING)63 assert tmpl.render() == 'bar'added new testcaseArmin Ronacherbefore adoption9b0545a
lines 64–68why, one step back646566def test_start_comment(env):67 tmpl = env.from_string(STARTCOMMENT)68 assert tmpl.render().strip() == 'foo'fixed more unittestsArmin Ronacherbefore adoption4f7d2d5
lines 69–75why, one step back697071def test_line_syntax():72 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')73 tmpl = env.from_string(MAKO_SYNTAX)74 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \75 range(5)