Removed optional speedups extension hack.
[jinja2.git] / tests / test_ifcondition.py
1 # -*- coding: utf-8 -*-
2 """
3     unit test for if conditions
4     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6     :copyright: 2007 by Armin Ronacher.
7     :license: BSD, see LICENSE for more details.
8 """
9
10 SIMPLE = '''{% if true %}...{% endif %}'''
11 ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''
12 ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''
13 EMPTY = '''[{% if true %}{% else %}{% endif %}]'''
14
15
16 def test_simple(env):
17     tmpl = env.from_string(SIMPLE)
18     assert tmpl.render() == '...'
19
20
21 def test_elif(env):
22     tmpl = env.from_string(ELIF)
23     assert tmpl.render() == '...'
24
25
26 def test_else(env):
27     tmpl = env.from_string(ELSE)
28     assert tmpl.render() == '...'
29
30
31 def test_empty(env):
32     tmpl = env.from_string(EMPTY)
33     assert tmpl.render() == '[]'
34
35
36 def test_complete(env):
37     tmpl = env.from_string('{% if a %}A{% elif b %}B{% elif c == d %}'
38                            'C{% else %}D{% endif %}')
39     assert tmpl.render(a=0, b=False, c=42, d=42.0) == 'C'
40
41
42 def test_no_scope(env):
43     tmpl = env.from_string('{% if a %}{% set foo = 1 %}{% endif %}{{ foo }}')
44     assert tmpl.render(a=True) == '1'
45     tmpl = env.from_string('{% if true %}{% set foo = 1 %}{% endif %}{{ foo }}')
46     assert tmpl.render() == '1'