Skip to content

Commit

Permalink
Change grouping behavior of tests. This fixes #401
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 7, 2017
1 parent 028f058 commit 147bd57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES
Expand Up @@ -30,6 +30,11 @@ Version 2.9
- Block sets are now marked `safe` by default.
- On Python 2 the asciification of ASCII strings can now be disabled with
the `compiler.ascii_str` policy.
- Tests now no longer accept an arbitrary expression as first argument but
a restricted one. This means that you can now properly use multiple

This comment has been minimized.

Copy link
@ThiefMaster

ThiefMaster Jan 7, 2017

Member

what kinds of expressions won't be accepted anymore?

This comment has been minimized.

Copy link
@mitsuhiko

mitsuhiko Jan 7, 2017

Author Contributor

You can't do foo is divisible by 1 + 1 any more. It needs to be foo is divisible by (1 + 1) now as a practical example. Really only primary expressions are allowed now if you need to use parentheses.

This comment has been minimized.

Copy link
@ThiefMaster

ThiefMaster Jan 7, 2017

Member

ok, so nothing likely to be used in the wild

tests in one expression without extra parentheses. In particular you can
now write ``foo is divisibleby 2 or foo is divisibleby 3``
as you would expect.

Version 2.8.2
-------------
Expand Down
2 changes: 1 addition & 1 deletion jinja2/parser.py
Expand Up @@ -806,7 +806,7 @@ def parse_test(self, node):
'name:and')):
if self.stream.current.test('name:is'):
self.fail('You cannot chain multiple tests with is')
args = [self.parse_expression()]
args = [self.parse_primary()]
else:
args = []
node = nodes.Test(node, name, args, kwargs, dyn_args,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tests.py
Expand Up @@ -112,3 +112,17 @@ def test_lessthan(self, env):
tmpl = env.from_string('{{ 0 is lessthan 1 }}|'
'{{ 1 is lessthan 0 }}')
assert tmpl.render() == 'True|False'

def test_multiple_tests(self):
items = []
def matching(x, y):
items.append((x, y))
return False
env = Environment()
env.tests['matching'] = matching
tmpl = env.from_string("{{ 'us-west-1' is matching "
"'(us-east-1|ap-northeast-1)' "
"or 'stage' is matching '(dev|stage)' }}")
assert tmpl.render() == 'False'
assert items == [('us-west-1', '(us-east-1|ap-northeast-1)'),
('stage', '(dev|stage)')]

0 comments on commit 147bd57

Please sign in to comment.