1 # -*- coding: utf-8 -*-
3 unit test for the parser
4 ~~~~~~~~~~~~~~~~~~~~~~~~
6 :copyright: 2007 by Armin Ronacher.
7 :license: BSD, see LICENSE for more details.
10 from jinja import Environment
12 NO_VARIABLE_BLOCK = '''\
13 {# i'm a freaking comment #}\
14 {% if foo %}{% foo %}{% endif %}
15 {% for item in seq %}{% item %}{% endfor %}
16 {% trans foo %}foo is {% foo %}{% endtrans %}
17 {% trans foo %}one foo{% pluralize %}{% foo %} foos{% endtrans %}'''
20 <!-- I'm a comment, I'm not interesting -->\
21 <? for item in seq -?>
26 <%# I'm a comment, I'm not interesting %>\
27 <% for item in seq -%>
32 <!--# I'm a comment, I'm not interesting -->\
33 <!-- for item in seq --->
38 {* I'm a comment, I'm not interesting *}\
43 BALANCING = '''{{{'foo':'bar'}.foo}}'''
46 def test_no_variable_block():
47 env = Environment('{%', '%}', None, None)
48 tmpl = env.from_string(NO_VARIABLE_BLOCK)
49 assert tmpl.render(foo=42, seq=range(2)).splitlines() == [
57 def test_php_syntax():
58 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')
59 tmpl = env.from_string(PHP_SYNTAX)
60 assert tmpl.render(seq=range(5)) == '01234'
63 def test_erb_syntax():
64 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')
65 tmpl = env.from_string(ERB_SYNTAX)
66 assert tmpl.render(seq=range(5)) == '01234'
69 def test_comment_syntax():
70 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')
71 tmpl = env.from_string(COMMENT_SYNTAX)
72 assert tmpl.render(seq=range(5)) == '01234'
75 def test_smarty_syntax():
76 env = Environment('{', '}', '{', '}', '{*', '*}')
77 tmpl = env.from_string(SMARTY_SYNTAX)
78 assert tmpl.render(seq=range(5)) == '01234'
81 def test_balancing(env):
82 tmpl = env.from_string(BALANCING)
83 assert tmpl.render() == 'bar'