Skip to content
Myr

test_parser.py

This file

Path

tests/test_parser.py

116 lines · 2.9 KiB · Python

Last changed by

Got rid of py.testisms.Armin Ronacherbefore adoption42979eb

History of this file

Take it

The walk stopped after 200 commits: lines older than 1de4c64 point at it.

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 1–5why, one step back
1# -*- coding: utf-8 -*-
2"""3 unit test for the parser4 ~~~~~~~~~~~~~~~~~~~~~~~~5

Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b

line 6why, one step back
6 :copyright: (c) 2009 by the Jinja Team.

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 7–10why, one step back
7 :license: BSD, see LICENSE for more details.
8"""9from jinja2 import Environment10

Got rid of py.testisms.Armin Ronacherbefore adoption42979eb

line 11why, one step back
11env = Environment()

documented recursive loopsArmin Ronacherbefore adoption1de4c64

line 12why, one step back
12

merged.Armin Ronacherbefore adoption1b43b58

line 13why, one step back
13

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 14–32why, one step back
14PHP_SYNTAX = '''\
15<!-- I'm a comment, I'm not interesting -->\16<? for item in seq -?>17 <?= item ?>18<?- endfor ?>'''1920ERB_SYNTAX = '''\21<%# I'm a comment, I'm not interesting %>\22<% for item in seq -%>23 <%= item %>24<%- endfor %>'''2526COMMENT_SYNTAX = '''\27<!--# I'm a comment, I'm not interesting -->\28<!-- for item in seq --->29 ${item}30<!--- endfor -->'''3132MAKO_SYNTAX = '''\

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

line 33why, one step back
33<%# regular comment %>

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 34–37why, one step back
34% for item in seq:
35 ${item}36% endfor'''37

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

lines 38–43why, one step back
38MAKO_SYNTAX_LINECOMMENTS = '''\
39<%# regular comment %>40% for item in seq:41 ${item} ## the rest of the stuff42% endfor'''43

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 44–50why, one step back
44BALANCING = '''{{{'foo':'bar'}.foo}}'''
4546STARTCOMMENT = '''{# foo comment47and bar comment #}48{% macro blub() %}foo{% endmacro %}49{{ blub() }}'''50

Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d

line 51why, one step back
51LINE_SYNTAX_PRIORITY1 = '''\

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

lines 52–53why, one step back
52/* ignore me.
53 I'm a multiline comment */

Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d

lines 54–61why, one step back
54## for item in seq:
55* ${item} # this is just extra stuff56## endfor57'''5859LINE_SYNTAX_PRIORITY2 = '''\60/* ignore me.61 I'm a multiline comment */

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

lines 62–63why, one step back
62# for item in seq:
63* ${item} ## this is just extra stuff

Added a testcase for the last change.Armin Ronacherbefore adoption3617a02

line 64why, one step back
64 ## extra stuff i just want to ignore

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

lines 65–66why, one step back
65# endfor
66'''

documented recursive loopsArmin Ronacherbefore adoption1de4c64

line 67why, one step back
67

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

line 68why, one step back
68

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 69–86why, one step back
69def test_php_syntax():
70 env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')71 tmpl = env.from_string(PHP_SYNTAX)72 assert tmpl.render(seq=range(5)) == '01234'737475def test_erb_syntax():76 env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')77 tmpl = env.from_string(ERB_SYNTAX)78 assert tmpl.render(seq=range(5)) == '01234'798081def test_comment_syntax():82 env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')83 tmpl = env.from_string(COMMENT_SYNTAX)84 assert tmpl.render(seq=range(5)) == '01234'8586

Got rid of py.testisms.Armin Ronacherbefore adoption42979eb

line 87why, one step back
87def test_balancing():

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 88–91why, one step back
88 tmpl = env.from_string(BALANCING)
89 assert tmpl.render() == 'bar'9091

Got rid of py.testisms.Armin Ronacherbefore adoption42979eb

line 92why, one step back
92def test_start_comment():

documented recursive loopsArmin Ronacherbefore adoption1de4c64

lines 93–100why, one step back
93 tmpl = env.from_string(STARTCOMMENT)
94 assert tmpl.render().strip() == 'foo'959697def test_line_syntax():98 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')99 tmpl = env.from_string(MAKO_SYNTAX)100 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \

merged.Armin Ronacherbefore adoption1b43b58

line 101why, one step back
101 range(5)

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

lines 102–109why, one step back
102
103 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')104 tmpl = env.from_string(MAKO_SYNTAX_LINECOMMENTS)105 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \106 range(5)107108109def test_line_syntax_priority():

Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d

lines 110–112why, one step back
110 # XXX: why is the whitespace there in front of the newline?
111 env = Environment('{%', '%}', '${', '}', '/*', '*/', '##', '#')112 tmpl = env.from_string(LINE_SYNTAX_PRIORITY1)

Fixed another bug with line commentsArmin Ronacherbefore adoption1bb3ab7

line 113why, one step back
113 assert tmpl.render(seq=[1, 2]).strip() == '* 1\n* 2'

Added support for line-based comments.Armin Ronacherbefore adoption59b6bd5

line 114why, one step back
114 env = Environment('{%', '%}', '${', '}', '/*', '*/', '#', '##')

Fixed bug in line-based comments with priority.Armin Ronacherbefore adoptiondb7985d

line 115why, one step back
115 tmpl = env.from_string(LINE_SYNTAX_PRIORITY2)

Added a testcase for the last change.Armin Ronacherbefore adoption3617a02

line 116why, one step back
116 assert tmpl.render(seq=[1, 2]).strip() == '* 1\n\n* 2'