Tests
4 minute read
Tests can be used to test a variable against a common expression.
To test a variable or expression, you add the is-operator or is not-operator plus the name of the test after the variable.
{{ 21 is divisibleby(3) }}
=> true
boolean
Test returns true if the object is a boolean value.
{{ true is boolean }}
=> true
defined
Test returns true if the variable is defined.
{{ foo is defined }}
Refer to the default filter.
See also: undefined.
divisibleby
Test returns true if the variable is divisible by a number.
{# divisibleby(num) #}
{{ 21 is divisibleby 3 }}
=> true
Refer to the divide operator.
eq
Test returns true if the variable equals the second variable.
{{ 1 is eq 2 }}
=> false
Refer to the equality comparison.
escaped
Test returns true if the variable is escaped.
{{ foo is escaped }}
Refer to the escape filter.
even
Test returns true if the variable is even.
{{ 2 is even }}
=> true
See also: float, integer, number, odd.
false
Test returns true if the variable is false.
{{ true is false }}
=> false
float
Test returns true if the object is a float.
{{ foo is not float }}
Refer to the float filter.
See also: even, integer, number, odd.
ge
Test returns true if the variable is greater than or equal to the second variable.
{{ 3 is ge(3) }}
=> true
Refer to the greater than or equal to comparison.
gt
Test returns true if the variable is greater than the second variable.
{{ 1 is gt(3) }}
=> false
Refer to the greater than comparison.
in
Test returns true if the variable is in the sequence.
{{ 1 is in [1, 2, 3] }}
=> true
Refer to the in operator.
integer
Test returns true if the variable is an integer.
{{ "1" is integer }}
=> false
Refer to the int filter.
See also: even, float, number, odd.
iterable
Test returns true if it is possible to iterate over an object.
{{ [1, 2, 3] is iterable }}
=> true
See also: sequence.
le
Test returns true if the variable is less than or equal to the second variable.
{{ 3 is le(3) }}
=> true
Refer to the less than or equal to comparison.
lower
Test returns true if the variable is lowercased.
{{ "hello" is lower }}
=> true
Refer to the lower filter.
See also: upper.
lt
Test returns true if the variable is less than the second variable.
{{ 1 is lt(3) }}
=> true
Refer to the less than comparison.
mapping
Test returns true if the object is a mapping.
{{ dict is mapping }}
Refer to the dict literal.
ne
Test returns true if the variable is not equal to the second variable.
{{ foo is ne bar }}
Refer to the inequality comparison.
none
Test returns true if the variable is none.
{{ foo is none }}
Refer to the default filter.
number
Test returns true if the variable is a number.
{{ 1 is number }}
=> true
See also: even, float, integer, odd.
odd
Test returns true if the variable is odd.
{{ 1 is odd }}
=> true
See also: even, float, integer, number.
sameas
Test returns true if an object points to the same memory address as another object.
{{ foo.bar is sameas 1 }}
sequence
Test returns true if the variable is a sequence.
{{ [1,2,3] is sequence }}
=> true
Refer to the sequence literal.
See also: iterable.
string
Test returns true if the variable is a string.
{{ "hello" is string }}
=> true
Refer to the string filter.
true
Test returns true if the object is true.
{{ true is true }}
=> true
undefined
Test returns true if the variable is undefined.
{{ foo is undefined }}
Refer to the default filter.
See also: defined.
upper
Test returns true if the variable is uppercased.
{{ "HELLO" is upper }}
=> true
Refer to the upper filter.
See also: lower.