lstrojny Thu Sep 11 18:21:37 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/array prev_basic.phpt prev_error1.phpt prev_error2.phpt prev_error3.phpt prev_variation1.phpt prev_variation2.phpt Log: MFH: prev()-tests by Iain Lewis <[EMAIL PROTECTED]>
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_basic.phpt +++ php-src/ext/standard/tests/array/prev_basic.phpt --TEST-- Test prev() function : basic functionality --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */
/* * Test basic functionality of prev() */ echo "*** Testing prev() : basic functionality ***\n"; $array = array('zero', 'one', 'two'); end($array); echo key($array) . " => " . current($array) . "\n"; var_dump(prev($array)); echo key($array) . " => " . current($array) . "\n"; var_dump(prev($array)); echo key($array) . " => " . current($array) . "\n"; var_dump(prev($array)); echo "\n*** Testing an array with differing values/keys ***\n"; $array2 = array('one', 2 => "help", 3, false, 'stringkey2' => 'val2', 'stringkey1' => 'val1'); end($array2); $length = count($array2); for ($i = $length; $i > 0; $i--) { var_dump(prev($array2)); } ?> ===DONE=== --EXPECTF-- *** Testing prev() : basic functionality *** 2 => two unicode(3) "one" 1 => one unicode(4) "zero" 0 => zero bool(false) *** Testing an array with differing values/keys *** unicode(4) "val2" bool(false) int(3) unicode(4) "help" unicode(3) "one" bool(false) ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_error1.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_error1.phpt +++ php-src/ext/standard/tests/array/prev_error1.phpt --TEST-- Test prev() function : error conditions - Pass incorrect number of arguments --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */ /* * Pass incorrect number of arguments to prev() to test behaviour */ echo "*** Testing prev() : error conditions ***\n"; // Zero arguments echo "\n-- Testing prev() function with Zero arguments --\n"; var_dump( prev() ); //Test prev with one more than the expected number of arguments echo "\n-- Testing prev() function with more than expected no. of arguments --\n"; $array_arg = array(1, 2); $extra_arg = 10; var_dump( prev($array_arg, $extra_arg) ); ?> ===DONE=== --EXPECTF-- *** Testing prev() : error conditions *** -- Testing prev() function with Zero arguments -- Warning: prev() expects exactly 1 parameter, 0 given in %s on line %d NULL -- Testing prev() function with more than expected no. of arguments -- Warning: prev() expects exactly 1 parameter, 2 given in %s on line %d NULL ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_error2.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_error2.phpt +++ php-src/ext/standard/tests/array/prev_error2.phpt --TEST-- prev - ensure warning is received when passing an indirect temporary. --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */ /* * Pass temporary variables to prev() to test behaviour */ function f() { $array = array(1,2); end($array); return $array; } echo "\n-- Passing an indirect temporary variable --\n"; var_dump(prev(f())); ?> --EXPECTF-- -- Passing an indirect temporary variable -- Strict Standards: Only variables should be passed by reference in %s on line %d int(1) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_error3.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_error3.phpt +++ php-src/ext/standard/tests/array/prev_error3.phpt --TEST-- prev - ensure we cannot pass a temporary --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */ /* * Pass temporary variables to prev() to test behaviour */ var_dump(prev(array(1, 2))); ?> --EXPECTF-- Fatal error: Only variables can be passed by reference in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_variation1.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_variation1.phpt +++ php-src/ext/standard/tests/array/prev_variation1.phpt --TEST-- Test prev() function : usage variation - Pass different data types as $array_arg --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */ /* * Pass different data types as $array_arg argument to prev() to test behaviour */ echo "*** Testing prev() : variation ***\n"; //get an unset variable $unset_var = 10; unset ($unset_var); // get a class class classA { public function __toString() { return "Class A object"; } } // heredoc string $heredoc = <<<EOT hello world EOT; // get a resource variable $fp = fopen(__FILE__, "r"); // unexpected values to be passed to $array_arg argument $inputs = array( // int data /*1*/ 0, 1, 12345, -2345, // float data /*5*/ 10.5, -10.5, 12.3456789000e10, 12.3456789000E-10, .5, // null data /*10*/ NULL, null, // boolean data /*12*/ true, false, TRUE, FALSE, // empty data /*16*/ "", '', array(), // string data /*19*/ "string", 'string', $heredoc, // object data /*22*/ new classA(), // undefined data /*23*/ @$undefined_var, // unset data /*24*/ @$unset_var, // resource variable /*25*/ $fp ); // loop through each element of $inputs to check the behavior of prev() $iterator = 1; foreach($inputs as $input) { echo "\n-- Iteration $iterator --\n"; var_dump( prev($input) ); $iterator++; }; fclose($fp); ?> ===DONE=== --EXPECTF-- *** Testing prev() : variation *** -- Iteration 1 -- Warning: prev() expects parameter 1 to be array, integer given in %s on line %d NULL -- Iteration 2 -- Warning: prev() expects parameter 1 to be array, integer given in %s on line %d NULL -- Iteration 3 -- Warning: prev() expects parameter 1 to be array, integer given in %s on line %d NULL -- Iteration 4 -- Warning: prev() expects parameter 1 to be array, integer given in %s on line %d NULL -- Iteration 5 -- Warning: prev() expects parameter 1 to be array, double given in %s on line %d NULL -- Iteration 6 -- Warning: prev() expects parameter 1 to be array, double given in %s on line %d NULL -- Iteration 7 -- Warning: prev() expects parameter 1 to be array, double given in %s on line %d NULL -- Iteration 8 -- Warning: prev() expects parameter 1 to be array, double given in %s on line %d NULL -- Iteration 9 -- Warning: prev() expects parameter 1 to be array, double given in %s on line %d NULL -- Iteration 10 -- Warning: prev() expects parameter 1 to be array, null given in %s on line %d NULL -- Iteration 11 -- Warning: prev() expects parameter 1 to be array, null given in %s on line %d NULL -- Iteration 12 -- Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d NULL -- Iteration 13 -- Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d NULL -- Iteration 14 -- Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d NULL -- Iteration 15 -- Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d NULL -- Iteration 16 -- Warning: prev() expects parameter 1 to be array, Unicode string given in %s on line %d NULL -- Iteration 17 -- Warning: prev() expects parameter 1 to be array, Unicode string given in %s on line %d NULL -- Iteration 18 -- bool(false) -- Iteration 19 -- Warning: prev() expects parameter 1 to be array, Unicode string given in %s on line %d NULL -- Iteration 20 -- Warning: prev() expects parameter 1 to be array, Unicode string given in %s on line %d NULL -- Iteration 21 -- Warning: prev() expects parameter 1 to be array, Unicode string given in %s on line %d NULL -- Iteration 22 -- Warning: prev() expects parameter 1 to be array, object given in %s on line %d NULL -- Iteration 23 -- Warning: prev() expects parameter 1 to be array, null given in %s on line %d NULL -- Iteration 24 -- Warning: prev() expects parameter 1 to be array, null given in %s on line %d NULL -- Iteration 25 -- Warning: prev() expects parameter 1 to be array, resource given in %s on line %d NULL ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/prev_variation2.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/prev_variation2.phpt +++ php-src/ext/standard/tests/array/prev_variation2.phpt --TEST-- Test prev() function : usage variation - Multi-dimensional arrays --FILE-- <?php /* Prototype : mixed prev(array $array_arg) * Description: Move array argument's internal pointer to the previous element and return it * Source code: ext/standard/array.c */ /* * Test prev() when passed: * 1. a two-dimensional array * 2. a sub-array * as $array_arg argument. */ echo "*** Testing prev() : usage variations ***\n"; $subarray = array(9,8,7); end($subarray); $array_arg = array ($subarray, 'a' => 'z'); end($array_arg); echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; var_dump(prev($array_arg)); var_dump(prev($array_arg)); echo "\n-- Pass a sub-array as \$array_arg --\n"; var_dump(prev($array_arg[0])); ?> ===DONE=== --EXPECTF-- *** Testing prev() : usage variations *** -- Pass a two-dimensional array as $array_arg -- array(3) { [0]=> int(9) [1]=> int(8) [2]=> int(7) } bool(false) -- Pass a sub-array as $array_arg -- int(8) ===DONE===
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php