From b20a74868bbf3e56b9c416920837363887e7d4d7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 20 Apr 2012 20:12:07 +0200 Subject: [PATCH] removed the array test and rename the traversable test to iterable --- doc/tests/array.rst | 11 ----------- doc/tests/index.rst | 1 + doc/tests/iterable.rst | 11 +++++++++++ doc/tests/traversable.rst | 11 ----------- lib/Twig/Extension/Core.php | 5 ++--- test/Twig/Tests/Fixtures/tests/is_array.test | 16 ---------------- .../tests/{traversable.test => iterable.test} | 10 +++++----- 7 files changed, 19 insertions(+), 46 deletions(-) delete mode 100644 doc/tests/array.rst create mode 100644 doc/tests/iterable.rst delete mode 100644 doc/tests/traversable.rst delete mode 100644 test/Twig/Tests/Fixtures/tests/is_array.test rename test/Twig/Tests/Fixtures/tests/{traversable.test => iterable.test} (51%) diff --git a/doc/tests/array.rst b/doc/tests/array.rst deleted file mode 100644 index 0bc46c474..000000000 --- a/doc/tests/array.rst +++ /dev/null @@ -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 %} diff --git a/doc/tests/index.rst b/doc/tests/index.rst index b16edc53a..7b8c53565 100644 --- a/doc/tests/index.rst +++ b/doc/tests/index.rst @@ -12,3 +12,4 @@ Tests constant defined empty + iterable diff --git a/doc/tests/iterable.rst b/doc/tests/iterable.rst new file mode 100644 index 000000000..b7d2334ad --- /dev/null +++ b/doc/tests/iterable.rst @@ -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 %} diff --git a/doc/tests/traversable.rst b/doc/tests/traversable.rst deleted file mode 100644 index 1809755b2..000000000 --- a/doc/tests/traversable.rst +++ /dev/null @@ -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 %} diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 82f5706f1..a540c5a6a 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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); } diff --git a/test/Twig/Tests/Fixtures/tests/is_array.test b/test/Twig/Tests/Fixtures/tests/is_array.test deleted file mode 100644 index 1edb973b2..000000000 --- a/test/Twig/Tests/Fixtures/tests/is_array.test +++ /dev/null @@ -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 \ No newline at end of file diff --git a/test/Twig/Tests/Fixtures/tests/traversable.test b/test/Twig/Tests/Fixtures/tests/iterable.test similarity index 51% rename from test/Twig/Tests/Fixtures/tests/traversable.test rename to test/Twig/Tests/Fixtures/tests/iterable.test index de406cd8a..ec5255013 100644 --- a/test/Twig/Tests/Fixtures/tests/traversable.test +++ b/test/Twig/Tests/Fixtures/tests/iterable.test @@ -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(),