blob: e81dfc0173533d5e38319aada375630666f7c6a9 [file] [log] [blame]
Armin Ronacher93e14c22007-03-20 16:17:48 +01001# -*- coding: utf-8 -*-
2"""
3 unit test for various things
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 :copyright: 2007 by Armin Ronacher.
7 :license: BSD, see LICENSE for more details.
8"""
Christoph Hacke9e43bb2008-04-13 23:35:48 +02009from jinja2.exceptions import TemplateSyntaxError
Armin Ronacher93e14c22007-03-20 16:17:48 +010010
Armin Ronacher4f7d2d52008-04-22 10:40:26 +020011
Armin Ronacher93e14c22007-03-20 16:17:48 +010012UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''
Armin Ronacher93e14c22007-03-20 16:17:48 +010013RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''
Armin Ronacher4f7d2d52008-04-22 10:40:26 +020014CONST = '''{{ true }}|{{ false }}|{{ none }}|\
15{{ none is defined }}|{{ missing is defined }}'''
Armin Ronacher0a2ac692008-05-13 01:03:08 +020016LOCALSET = '''{% set foo = 0 %}\
17{% for item in [1, 2] %}{% set foo = 1 %}{% endfor %}\
Armin Ronacher1cc232c2007-09-07 17:52:41 +020018{{ foo }}'''
Armin Ronacher0a2ac692008-05-13 01:03:08 +020019CONSTASS1 = '''{% set true = 42 %}'''
Armin Ronacher4f7d2d52008-04-22 10:40:26 +020020CONSTASS2 = '''{% for none in seq %}{% endfor %}'''
Armin Ronacher93e14c22007-03-20 16:17:48 +010021
22
23def test_unpacking(env):
24 tmpl = env.from_string(UNPACKING)
25 assert tmpl.render() == '1|2|3'
26
27
28def test_raw(env):
29 tmpl = env.from_string(RAW)
30 assert tmpl.render() == '{{ FOO }} and {% BAR %}'
31
32
Armin Ronacherecc051b2007-06-01 18:25:28 +020033def test_const(env):
34 tmpl = env.from_string(CONST)
Armin Ronacher4f7d2d52008-04-22 10:40:26 +020035 assert tmpl.render() == 'True|False|None|True|False'
Armin Ronacherecc051b2007-06-01 18:25:28 +020036
37
38def test_const_assign(env):
39 for tmpl in CONSTASS1, CONSTASS2:
40 try:
41 env.from_string(tmpl)
42 except TemplateSyntaxError:
43 pass
44 else:
45 raise AssertionError('expected syntax error')
Armin Ronacher1cc232c2007-09-07 17:52:41 +020046
47
48def test_localset(env):
49 tmpl = env.from_string(LOCALSET)
50 assert tmpl.render() == '0'