From 0b666579b6d927bdfaa4ff9aec28f73d831ba1c2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 18 Mar 2007 23:15:23 +0100 Subject: [PATCH] [svn] added tests for "capture" and "format" filters --HG-- branch : trunk --- jinja/filters.py | 4 ++++ tests/test_filters.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/jinja/filters.py b/jinja/filters.py index 01cab4f..7de2176 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -577,6 +577,10 @@ def do_capture(name='captured'): {% endfilter %} {{ foo }} """ + def wrapped(env, context, value): + context[name] = value + return value + return wrapped FILTERS = { diff --git a/tests/test_filters.py b/tests/test_filters.py index eab73d5..53b142a 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -15,6 +15,7 @@ """ CAPITALIZE = '''{{ "foo bar"|capitalize }}''' +CAPTURE = '''{{ "foo"|capture('bar') }}|{{ bar }}''' CENTER = '''{{ "foo"|center(9) }}''' DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\ {{ false|default('no', true) }}|{{ given|default("no") }}''' @@ -29,6 +30,7 @@ FILESIZEFORMAT = '{{ 100|filesizeformat }}|\ {{ 1000000000000|filesizeformat }}' FIRST = '''{{ foo|first }}''' FLOAT = '''{{ "42"|float }}|{{ "ajsghasjgd"|float }}|{{ "32.32"|float }}''' +FORMAT = '''{{ "%s|%s"|format("a", "b") }}''' INDENT = '''{{ foo|indent(2) }}|{{ foo|indent(2, true) }}''' INT = '''{{ "42"|int }}|{{ "ajsghasjgd"|int }}|{{ "32.32"|int }}''' JOIN = '''{{ [1, 2, 3]|join("|") }}''' @@ -56,6 +58,11 @@ def test_capitalize(env): assert tmpl.render() == 'Foo bar' +def test_capture(env): + tmpl = env.from_string(CAPTURE) + assert tmpl.render() == 'foo|foo' + + def test_center(env): tmpl = env.from_string(CENTER) assert tmpl.render() == ' foo ' @@ -98,6 +105,12 @@ def test_float(env): assert out == '42.0|0.0|32.32' +def test_format(env): + tmpl = env.from_string(FORMAT) + out = tmpl.render() + assert out == 'a|b' + + def test_indent(env): tmpl = env.from_string(INDENT) text = '\n'.join([' '.join(['foo', 'bar'] * 2)] * 2) -- 2.26.2