test_parser.py
This file
Path
tests/test_parser.py
83 lines · 2.0 KiB · Python
Last changed by
[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
History of this fileTake it
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"""910from jinja import Environment1112NO_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 %}'''1819PHP_SYNTAX = '''\20<!-- I'm a comment, I'm not interesting -->\21<? for item in seq -?>22 <?= item ?>23<?- endfor ?>'''2425ERB_SYNTAX = '''\26<%# I'm a comment, I'm not interesting %>\27<% for item in seq -%>28 <%= item %>29<%- endfor %>'''3031COMMENT_SYNTAX = '''\32<!--# I'm a comment, I'm not interesting -->\33<!-- for item in seq --->34 ${item}35<!--- endfor -->'''3637SMARTY_SYNTAX = '''\38{* I'm a comment, I'm not interesting *}\39{for item in seq-}40 {item}41{-endfor}'''4243BALANCING = '''{{{'foo':'bar'}.foo}}'''444546def 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() == [50 '42',51 '01',52 'foo is 42',53 '42 foos'54 ]555657def test_php_syntax():58 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')59 tmpl = env.from_string(PHP_SYNTAX)60 assert tmpl.render(seq=range(5)) == '01234'616263def test_erb_syntax():64 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')65 tmpl = env.from_string(ERB_SYNTAX)66 assert tmpl.render(seq=range(5)) == '01234'676869def test_comment_syntax():70 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')71 tmpl = env.from_string(COMMENT_SYNTAX)72 assert tmpl.render(seq=range(5)) == '01234'737475def test_smarty_syntax():76 env = Environment('{', '}', '{', '}', '{*', '*}')77 tmpl = env.from_string(SMARTY_SYNTAX)78 assert tmpl.render(seq=range(5)) == '01234'798081def test_balancing(env):82 tmpl = env.from_string(BALANCING)83 assert tmpl.render() == 'bar'