test_parser.py
This file
Path
tests/test_parser.py
93 lines · 2.2 KiB · Python
Last changed by
added new testcaseArmin Ronacherbefore adoption9b0545a
History of this fileTake it
[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
lines 1–42why, 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"""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}'''42[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
line 43why, one step back43BALANCING = '''{{{'foo':'bar'}.foo}}'''[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
line 44why, one step back44added new testcaseArmin Ronacherbefore adoption9b0545a
lines 45–48why, one step back45STARTCOMMENT = '''{# foo comment46and bar comment #}47{% macro blub() %}foo{% endmacro %}48{{ blub() }}'''[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
line 49why, one step back49added new testcaseArmin Ronacherbefore adoption9b0545a
line 50why, one step back50[svn] added many new tests to jinjaArmin Ronacherbefore adoptionccf284b
lines 51–83why, one step back51def test_no_variable_block():52 env = Environment('{%', '%}', None, None)53 tmpl = env.from_string(NO_VARIABLE_BLOCK)54 assert tmpl.render(foo=42, seq=range(2)).splitlines() == [55 '42',56 '01',57 'foo is 42',58 '42 foos'59 ]606162def test_php_syntax():63 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')64 tmpl = env.from_string(PHP_SYNTAX)65 assert tmpl.render(seq=range(5)) == '01234'666768def test_erb_syntax():69 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')70 tmpl = env.from_string(ERB_SYNTAX)71 assert tmpl.render(seq=range(5)) == '01234'727374def test_comment_syntax():75 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')76 tmpl = env.from_string(COMMENT_SYNTAX)77 assert tmpl.render(seq=range(5)) == '01234'787980def test_smarty_syntax():81 env = Environment('{', '}', '{', '}', '{*', '*}')82 tmpl = env.from_string(SMARTY_SYNTAX)83 assert tmpl.render(seq=range(5)) == '01234'[svn] added some more jinja unittestsArmin Ronacherbefore adoptionecc051b
lines 84–88why, one step back848586def test_balancing(env):87 tmpl = env.from_string(BALANCING)88 assert tmpl.render() == 'bar'added new testcaseArmin Ronacherbefore adoption9b0545a
lines 89–93why, one step back899091def test_start_comment(env):92 tmpl = env.from_string(STARTCOMMENT)93 assert tmpl.render().strip() == 'foo'