blob: 5a487cf6b09295deec6dfd805a74ac616f3251d9 [file] [log] [blame]
Armin Ronacher3da90312008-05-23 16:37:28 +02001# -*- coding: utf-8 -*-
2"""
3 unit test for some extensions
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 :copyright: 2008 by Armin Ronacher.
7 :license: BSD, see LICENSE for more details.
8"""
9from jinja2 import Environment
10
11
12def test_loop_controls():
13 env = Environment(extensions=['jinja2.ext.loopcontrols'])
14
15 tmpl = env.from_string('''
16 {%- for item in [1, 2, 3, 4] %}
17 {%- if item % 2 == 0 %}{% continue %}{% endif -%}
18 {{ item }}
19 {%- endfor %}''')
20 assert tmpl.render() == '13'
21
22 tmpl = env.from_string('''
23 {%- for item in [1, 2, 3, 4] %}
24 {%- if item > 2 %}{% break %}{% endif -%}
25 {{ item }}
26 {%- endfor %}''')
27 assert tmpl.render() == '12'
28
29
30def test_do():
31 env = Environment(extensions=['jinja2.ext.do'])
32 tmpl = env.from_string('''
33 {%- set items = [] %}
34 {%- for char in "foo" %}
35 {%- do items.append(loop.index0 ~ char) %}
36 {%- endfor %}{{ items|join(', ') }}''')
37 assert tmpl.render() == '0f, 1o, 2o'