From 7b5a0bc42b5f73ba289b31d75e90d06f08a138ab Mon Sep 17 00:00:00 2001 From: Josie Messa Date: Thu, 21 Feb 2008 14:36:15 +0000 Subject: [PATCH] - New tests for key() function --- ext/standard/tests/array/key_basic.phpt | 62 ++++ ext/standard/tests/array/key_error.phpt | 52 +++ ext/standard/tests/array/key_variation1.phpt | 348 +++++++++++++++++++ ext/standard/tests/array/key_variation2.phpt | 204 +++++++++++ ext/standard/tests/array/key_variation3.phpt | 53 +++ ext/standard/tests/array/key_variation4.phpt | 79 +++++ 6 files changed, 798 insertions(+) create mode 100644 ext/standard/tests/array/key_basic.phpt create mode 100644 ext/standard/tests/array/key_error.phpt create mode 100644 ext/standard/tests/array/key_variation1.phpt create mode 100644 ext/standard/tests/array/key_variation2.phpt create mode 100644 ext/standard/tests/array/key_variation3.phpt create mode 100644 ext/standard/tests/array/key_variation4.phpt diff --git a/ext/standard/tests/array/key_basic.phpt b/ext/standard/tests/array/key_basic.phpt new file mode 100644 index 0000000000..d596fe31ed --- /dev/null +++ b/ext/standard/tests/array/key_basic.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test key() function : basic functionality +--FILE-- + 'one', 'two', 'three' => 3); +echo "\n-- Initial Position: --\n"; +var_dump(key($array)); + +echo "\n-- Next Position: --\n"; +next($array); +var_dump(key($array)); + +echo "\n-- End Position: --\n"; +end($array); +var_dump(key($array)); + +echo "\n-- Past end of the array --\n"; +next($array); +var_dump(key($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : basic functionality *** + +-- Initial Position: -- +int(0) + +-- Next Position: -- +int(99) + +-- End Position: -- +string(5) "three" + +-- Past end of the array -- +NULL +===DONE=== +--UEXPECTF-- +*** Testing key() : basic functionality *** + +-- Initial Position: -- +int(0) + +-- Next Position: -- +int(99) + +-- End Position: -- +unicode(5) "three" + +-- Past end of the array -- +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_error.phpt b/ext/standard/tests/array/key_error.phpt new file mode 100644 index 0000000000..32dffb1b4a --- /dev/null +++ b/ext/standard/tests/array/key_error.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test key() function : error conditions - Pass incorrect number of args +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing key() : error conditions *** + +-- Testing key() function with Zero arguments -- + +Warning: key() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing key() function with more than expected no. of arguments -- + +Warning: key() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== +--UEXPECTF-- +*** Testing key() : error conditions *** + +-- Testing key() function with Zero arguments -- + +Warning: key() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing key() function with more than expected no. of arguments -- + +Warning: key() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_variation1.phpt b/ext/standard/tests/array/key_variation1.phpt new file mode 100644 index 0000000000..42c2aa016e --- /dev/null +++ b/ext/standard/tests/array/key_variation1.phpt @@ -0,0 +1,348 @@ +--TEST-- +Test key() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: key() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: key() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== +--UEXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: key() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: key() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- + +Warning: key() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: key() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: key() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: key() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: key() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_variation2.phpt b/ext/standard/tests/array/key_variation2.phpt new file mode 100644 index 0000000000..119a6dfdfc --- /dev/null +++ b/ext/standard/tests/array/key_variation2.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test key() function : usage variations +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + while (key($input) !== NULL) { + var_dump(key($input)); + next($input); + } + $iterator++; +}; +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 : int data -- +int(0) +int(1) +int(12345) +int(-2345) + +-- Iteration 2 : float data -- +int(10) +int(-10) +int(0) + +-- Iteration 3 : extreme floats data -- +int(12345678) +int(0) + +-- Iteration 4 : null uppercase data -- +string(0) "" + +-- Iteration 5 : null lowercase data -- +string(0) "" + +-- Iteration 6 : bool lowercase data -- +int(1) +int(0) + +-- Iteration 7 : bool uppercase data -- +int(1) +int(0) + +-- Iteration 8 : empty double quotes data -- +string(0) "" + +-- Iteration 9 : empty single quotes data -- +string(0) "" + +-- Iteration 10 : string data -- +string(7) "stringd" +string(7) "strings" +string(11) "hello world" + +-- Iteration 11 : undefined data -- +string(0) "" + +-- Iteration 12 : unset data -- +string(0) "" +===DONE=== +--UEXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 : int data -- +int(0) +int(1) +int(12345) +int(-2345) + +-- Iteration 2 : float data -- +int(10) +int(-10) +int(0) + +-- Iteration 3 : extreme floats data -- +int(12345678) +int(0) + +-- Iteration 4 : null uppercase data -- +unicode(0) "" + +-- Iteration 5 : null lowercase data -- +unicode(0) "" + +-- Iteration 6 : bool lowercase data -- +int(1) +int(0) + +-- Iteration 7 : bool uppercase data -- +int(1) +int(0) + +-- Iteration 8 : empty double quotes data -- +unicode(0) "" + +-- Iteration 9 : empty single quotes data -- +unicode(0) "" + +-- Iteration 10 : string data -- +unicode(7) "stringd" +unicode(7) "strings" +unicode(11) "hello world" + +-- Iteration 11 : undefined data -- +unicode(0) "" + +-- Iteration 12 : unset data -- +unicode(0) "" +===DONE=== diff --git a/ext/standard/tests/array/key_variation3.phpt b/ext/standard/tests/array/key_variation3.phpt new file mode 100644 index 0000000000..e4880aee56 --- /dev/null +++ b/ext/standard/tests/array/key_variation3.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test key() function : usage variations +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Initial position of internal pointer -- +int(0) + +-- Position after calling next() -- +$array1: int(1) +$array2: int(1) +===DONE=== +--UEXPECTF-- +*** Testing key() : usage variations *** + +-- Initial position of internal pointer -- +int(0) + +-- Position after calling next() -- +$array1: int(1) +$array2: int(1) +===DONE=== diff --git a/ext/standard/tests/array/key_variation4.phpt b/ext/standard/tests/array/key_variation4.phpt new file mode 100644 index 0000000000..1aad797f8e --- /dev/null +++ b/ext/standard/tests/array/key_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test key() function : usage variations +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: int(0) +Next Position: int(1) +End Position: int(2) + +-- Access an Array Within an Array -- +Initial Position: int(0) + +-- Recursive, Multidimensional Array -- +Current Position: int(2) +int(2) +int(0) +===DONE=== +--UEXPECTF-- +*** Testing key() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: int(0) +Next Position: int(1) +End Position: int(2) + +-- Access an Array Within an Array -- +Initial Position: int(0) + +-- Recursive, Multidimensional Array -- +Current Position: int(2) +int(2) +int(0) +===DONE=== -- 2.40.0