Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equalto test as value-level analogue of reference-level sameas test. #283

Merged
merged 2 commits into from Dec 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions jinja2/tests.py
Expand Up @@ -102,6 +102,16 @@ def test_sequence(value):
return False
return True

def test_equalto(value, other):
"""Check if an object has the same value as another object:

.. sourcecode:: jinja

{% if foo.expression is equalto 42 %}
the foo attribute evaluates to the constant 42
{% endif %}
"""
return value == other

def test_sameas(value, other):
"""Check if an object points to the same memory address than another
Expand Down Expand Up @@ -146,5 +156,6 @@ def test_escaped(value):
'iterable': test_iterable,
'callable': test_callable,
'sameas': test_sameas,
'equalto': test_equalto,
'escaped': test_escaped
}
11 changes: 11 additions & 0 deletions jinja2/testsuite/tests.py
Expand Up @@ -72,6 +72,17 @@ def test_upper(self):
tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')
assert tmpl.render() == 'True|False'

def test_equalto(self):
tmpl = env.from_string('{{ foo is equalto 12 }}|'
'{{ foo is equalto 0 }}|'
'{{ foo is equalto (3 * 4) }}|'
'{{ bar is equalto "baz" }}|'
'{{ bar is equalto "zab" }}|'
'{{ bar is equalto ("ba" + "z") }}|'
'{{ bar is equalto bar }}|'
'{{ bar is equalto foo }}')
assert tmpl.render(foo=12, bar="baz") == 'True|False|True|True|False|True|True|False'

def test_sameas(self):
tmpl = env.from_string('{{ foo is sameas false }}|'
'{{ 0 is sameas false }}')
Expand Down