Skip to content
Myr

[svn] added tests for "capture" and "format" filters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent f0f4deb · Browse files · 2 files+17 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−0 removed

  • tests:+13 added−0 removed
  • other:+4 added−0 removed

2 files+17 added−0 removed

modified:jinja/filters.py+4 added
575 unmodified lines
576 ....577 {% endfilter %}578 {{ foo }}579 """580 def wrapped(env, context, value):581 context[name] = value582 return value583 return wrapped584585586FILTERS = {587 'replace': do_replace,
36 unmodified lines
modified:tests/test_filters.py+13 added
13 unmodified lines
14 :license: BSD, see LICENSE for more details.15"""1617CAPITALIZE = '''{{ "foo bar"|capitalize }}'''18CAPTURE = '''{{ "foo"|capture('bar') }}|{{ bar }}'''19CENTER = '''{{ "foo"|center(9) }}'''20DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\21{{ false|default('no', true) }}|{{ given|default("no") }}'''22DICTSORT = '''{{ foo|dictsort }}|\
6 unmodified lines
29{{ 1000000000|filesizeformat }}|\30{{ 1000000000000|filesizeformat }}'31FIRST = '''{{ foo|first }}'''32FLOAT = '''{{ "42"|float }}|{{ "ajsghasjgd"|float }}|{{ "32.32"|float }}'''33FORMAT = '''{{ "%s|%s"|format("a", "b") }}'''34INDENT = '''{{ foo|indent(2) }}|{{ foo|indent(2, true) }}'''35INT = '''{{ "42"|int }}|{{ "ajsghasjgd"|int }}|{{ "32.32"|int }}'''36JOIN = '''{{ [1, 2, 3]|join("|") }}'''37LAST = '''{{ foo|last }}'''
19 unmodified lines
57 tmpl = env.from_string(CAPITALIZE)58 assert tmpl.render() == 'Foo bar'596061def test_capture(env):62 tmpl = env.from_string(CAPTURE)63 assert tmpl.render() == 'foo|foo'646566def test_center(env):67 tmpl = env.from_string(CENTER)68 assert tmpl.render() == ' foo '69
34 unmodified lines
104 out = tmpl.render()105 assert out == '42.0|0.0|32.32'106107108def test_format(env):109 tmpl = env.from_string(FORMAT)110 out = tmpl.render()111 assert out == 'a|b'112113114def test_indent(env):115 tmpl = env.from_string(INDENT)116 text = '\n'.join([' '.join(['foo', 'bar'] * 2)] * 2)117 out = tmpl.render(foo=text)
99 unmodified lines