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 ---------------- test/Twig/Tests/Fixtures/tests/iterable.test | 19 +++++++++++++++++++ test/Twig/Tests/Fixtures/tests/traversable.test | 19 ------------------- 8 files changed, 33 insertions(+), 60 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 create mode 100644 test/Twig/Tests/Fixtures/tests/iterable.test delete mode 100644 test/Twig/Tests/Fixtures/tests/traversable.test diff --git a/doc/tests/array.rst b/doc/tests/array.rst deleted file mode 100644 index 0bc46c4..0000000 --- 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 b16edc5..7b8c535 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 0000000..b7d2334 --- /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 1809755..0000000 --- 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 82f5706..a540c5a 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 1edb973..0000000 --- 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/iterable.test b/test/Twig/Tests/Fixtures/tests/iterable.test new file mode 100644 index 0000000..ec52550 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tests/iterable.test @@ -0,0 +1,19 @@ +--TEST-- +"iterable" test +--TEMPLATE-- +{{ 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(), + 'traversable' => new ArrayIterator(array()), + 'obj' => new stdClass(), + 'val' => 'test', +); +--EXPECT-- +ok +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/traversable.test deleted file mode 100644 index de406cd..0000000 --- a/test/Twig/Tests/Fixtures/tests/traversable.test +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -"traversable" test ---TEMPLATE-- -{{ foo is traversable ? 'ok' : 'ko' }} -{{ traversable is traversable ? 'ok' : 'ko' }} -{{ obj is traversable ? 'ok' : 'ko' }} -{{ val is traversable ? 'ok' : 'ko' }} ---DATA-- -return array( - 'foo' => array(), - 'traversable' => new ArrayIterator(array()), - 'obj' => new stdClass(), - 'val' => 'test', -); ---EXPECT-- -ok -ok -ko -ko \ No newline at end of file -- 1.7.2.5