Skip to content
Myr

Add "is in" containment test (#658)

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

authored by Dirk D · committed by David Lord · parent 5c9de9c · Browse files · 2 files+20 added−1 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+20 added−1 removed

  • tests:+13 added−0 removed
  • other:+7 added−1 removed

2 files+20 added−1 removed

modified:jinja2/tests.py+7 added-1 removed
160 unmodified lines
161 """Check if value is less than other."""162 return value < other163164165def test_in(value, seq):166 """Check if value is in seq."""167 return value in seq168169170TESTS = {171 'odd': test_odd,172 'even': test_even,173 'divisibleby': test_divisibleby,
11 unmodified lines
185 'sameas': test_sameas,186 'equalto': test_equalto,187 'escaped': test_escaped,188 'greaterthan': test_greaterthan,184 'lessthan': test_lessthan189 'lessthan': test_lessthan,190 'in': test_in191}
modified:tests/test_tests.py+13 added
124 unmodified lines
125 "or 'stage' is matching '(dev|stage)' }}")126 assert tmpl.render() == 'False'127 assert items == [('us-west-1', '(us-east-1|ap-northeast-1)'),128 ('stage', '(dev|stage)')]129130 def test_in(self, env):131 tmpl = env.from_string('{{ "o" is in "foo" }}|'132 '{{ "foo" is in "foo" }}|'133 '{{ "b" is in "foo" }}|'134 '{{ 1 is in ((1, 2)) }}|'135 '{{ 3 is in ((1, 2)) }}|'136 '{{ 1 is in [1, 2] }}|'137 '{{ 3 is in [1, 2] }}|'138 '{{ "foo" is in {"foo": 1}}}|'139 '{{ "baz" is in {"bar": 1}}}')140 assert tmpl.render() \141 == 'True|True|False|True|False|True|False|True|False'