Permalink
Browse files

Refs #26479 -- Documented is/is not if tag operator behavior for none…

…xistent variables.
  • Loading branch information...
alasdairnicol authored and timgraham committed Apr 28, 2016
1 parent 246020e commit dac075e9103ba961af4f70b4011616daa72985d4
Showing with 35 additions and 6 deletions.
  1. +15 −6 docs/ref/templates/builtins.txt
  2. +20 −0 tests/template_tests/syntax_tests/test_if.py
@@ -523,20 +523,29 @@ Not contained within. This is the negation of the ``in`` operator.
Object identity. Tests if two values are the same object. Example::
- {% if value is None %}
- This will output if and only if value is None.
+ {% if somevar is True %}
+ This appears if and only if somevar is True.
+ {% endif %}
+
+ {% if somevar is None %}
+ This appears if somevar is None, or if somevar is not found in the context.
{% endif %}
``is not`` operator
^^^^^^^^^^^^^^^^^^^
.. versionadded:: 1.10
-Tests if two values are not the same object. This is the negation of
-the ``is`` operator. Example::
+Negated object identity. Tests if two values are not the same object. This is
+the negation of the ``is`` operator. Example::
+
+ {% if somevar is not True %}
+ This appears if somevar is not True, or if somevar is not found in the
+ context.
+ {% endif %}
- {% if value is not None %}
- This will output if and only if value is not None.
+ {% if somevar is not None %}
+ This appears if and only if somevar is not None.
{% endif %}
Filters
@@ -564,6 +564,16 @@ def test_if_is_no_match(self):
output = self.engine.render_to_string('template', {'foo': 1})
self.assertEqual(output, 'no')
+ @setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
+ def test_if_is_variable_missing(self):
+ output = self.engine.render_to_string('template', {'foo': 1})
+ self.assertEqual(output, 'no')
+
+ @setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
+ def test_if_is_both_variables_missing(self):
+ output = self.engine.render_to_string('template', {})
+ self.assertEqual(output, 'yes')
+
@setup({'template': '{% if foo is not None %}yes{% else %}no{% endif %}'})
def test_if_is_not_match(self):
# For this to act as a regression test, it's important not to use
@@ -575,3 +585,13 @@ def test_if_is_not_match(self):
def test_if_is_not_no_match(self):
output = self.engine.render_to_string('template', {'foo': None})
self.assertEqual(output, 'no')
+
+ @setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
+ def test_if_is_not_variable_missing(self):
+ output = self.engine.render_to_string('template', {'foo': False})
+ self.assertEqual(output, 'yes')
+
+ @setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
+ def test_if_is_not_both_variables_missing(self):
+ output = self.engine.render_to_string('template', {})
+ self.assertEqual(output, 'no')

1 comment on commit dac075e

@yilmazalican

This comment has been minimized.

Show comment Hide comment
@yilmazalican

yilmazalican Apr 29, 2016

ya kardeş napıyon amk

ya kardeş napıyon amk

Please sign in to comment.