Skip to content
Myr

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 file

Take it

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 1–8why, one step back
1# -*- 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 back
9from jinja2 import Environment

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 10–29why, one step back
10
1112PHP_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 -->'''29

fixed more unittestsArmin Ronacherbefore adoption4f7d2d5

lines 30–33why, one step back
30MAKO_SYNTAX = '''\
31% for item in seq:32 ${item}33% endfor'''

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

line 34why, one step back
34

[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b

line 35why, one step back
35BALANCING = '''{{{'foo':'bar'}.foo}}'''

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

line 36why, one step back
36

added new testcaseArmin Ronacherbefore adoption9b0545a

lines 37–40why, one step back
37STARTCOMMENT = '''{# foo comment
38and bar comment #}39{% macro blub() %}foo{% endmacro %}40{{ blub() }}'''

[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b

line 41why, one step back
41

added new testcaseArmin Ronacherbefore adoption9b0545a

line 42why, one step back
42

[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b

lines 43–60why, one step back
43def 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 back
61def test_balancing(env):
62 tmpl = env.from_string(BALANCING)63 assert tmpl.render() == 'bar'

added new testcaseArmin Ronacherbefore adoption9b0545a

lines 64–68why, one step back
64
6566def 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 back
69
7071def 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)