removed the array test and rename the traversable test to iterable

This commit is contained in:
Fabien Potencier
2012-04-20 20:12:07 +02:00
parent da9d2eb834
commit b20a74868b
7 changed files with 19 additions and 46 deletions
-11
View File
@@ -1,11 +0,0 @@
``array``
=========
``array`` checks if a variable is an array:
.. code-block:: jinja
{# evaluates to true if the foo variable is an array #}
{% if foo is array %}
...
{% endif %}
+1
View File
@@ -12,3 +12,4 @@ Tests
constant
defined
empty
iterable
+11
View File
@@ -0,0 +1,11 @@
``iterable``
============
``iterable`` checks if a variable is an array or a traversable object:
.. code-block:: jinja
{# evaluates to true if the foo variable is iterable #}
{% if foo is iterable %}
...
{% endif %}
-11
View File
@@ -1,11 +0,0 @@
``traversable``
=========
``traversable`` checks if a variable is an array or a traversable object:
.. code-block:: jinja
{# evaluates to true if the foo variable is traversable #}
{% if foo is traversable %}
...
{% endif %}
+2 -3
View File
@@ -202,8 +202,7 @@ class Twig_Extension_Core extends Twig_Extension
'divisibleby' => new Twig_Test_Node('Twig_Node_Expression_Test_Divisibleby'),
'constant' => new Twig_Test_Node('Twig_Node_Expression_Test_Constant'),
'empty' => new Twig_Test_Function('twig_test_empty'),
'array' => new Twig_Test_Function('is_array'),
'traversable' => new Twig_Test_Function('twig_test_traversable'),
'iterable' => new Twig_Test_Function('twig_test_iterable'),
);
}
@@ -1030,7 +1029,7 @@ function twig_test_empty($value)
*
* @return Boolean true if the value is traversable
*/
function twig_test_traversable($value)
function twig_test_iterable($value)
{
return $value instanceof Traversable || is_array($value);
}
@@ -1,16 +0,0 @@
--TEST--
"is_array" test
--TEMPLATE--
{{ foo is array ? 'ok' : 'ko' }}
{{ obj is array ? 'ok' : 'ko' }}
{{ val is array ? 'ok' : 'ko' }}
--DATA--
return array(
'foo' => array(),
'obj' => new stdClass(),
'val' => 'test',
);
--EXPECT--
ok
ko
ko
@@ -1,10 +1,10 @@
--TEST--
"traversable" test
"iterable" test
--TEMPLATE--
{{ foo is traversable ? 'ok' : 'ko' }}
{{ traversable is traversable ? 'ok' : 'ko' }}
{{ obj is traversable ? 'ok' : 'ko' }}
{{ val is traversable ? 'ok' : 'ko' }}
{{ foo is iterable ? 'ok' : 'ko' }}
{{ traversable is iterable ? 'ok' : 'ko' }}
{{ obj is iterable ? 'ok' : 'ko' }}
{{ val is iterable ? 'ok' : 'ko' }}
--DATA--
return array(
'foo' => array(),