From e3290ea9f3c2579a819c9c4016beb50f20a41cad Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 12 Jun 2008 10:30:01 +0200 Subject: [PATCH] Fixed a broken unittest and fixed a bug that required multiple tests to be put into parentheses for chaning. --HG-- branch : trunk --- jinja2/parser.py | 6 +++++- tests/test_syntax.py | 5 +++++ tests/test_various.py | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/jinja2/parser.py b/jinja2/parser.py index e73d820..810e381 100644 --- a/jinja2/parser.py +++ b/jinja2/parser.py @@ -703,7 +703,11 @@ class Parser(object): args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None) elif self.stream.current.type in ('name', 'string', 'integer', 'float', 'lparen', 'lbracket', - 'lbrace'): + 'lbrace') and not \ + self.stream.current.test_any('name:else', 'name:or', + 'name:and'): + if self.stream.current.test('name:is'): + self.fail('You cannot chain multiple tests with is') args = [self.parse_expression()] else: args = [] diff --git a/tests/test_syntax.py b/tests/test_syntax.py index a126b5f..986125c 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -171,3 +171,8 @@ def test_contant_casing(env): str(const), str(const).lower(), str(const).upper() )) assert tmpl.render() == '%s|%s|' % (const, const) + + +def test_test_chaining(env): + raises(TemplateSyntaxError, env.from_string, '{{ foo is string is sequence }}') + env.from_string('{{ 42 is string or 42 is number }}').render() == 'True' diff --git a/tests/test_various.py b/tests/test_various.py index 535b97c..36f039a 100644 --- a/tests/test_various.py +++ b/tests/test_various.py @@ -67,7 +67,7 @@ def test_item_and_attribute(): for env in Environment(), SandboxedEnvironment(): tmpl = env.from_string('{{ foo.items() }}') assert tmpl.render(foo={'items': 42}) == "[('items', 42)]" - tmpl = env.from_string('{{ foo|attr("items") }}') + tmpl = env.from_string('{{ foo|attr("items")() }}') assert tmpl.render(foo={'items': 42}) == "[('items', 42)]" tmpl = env.from_string('{{ foo["items"] }}') assert tmpl.render(foo={'items': 42}) == '42' -- 2.26.2