From 786746cb07c9830d0b690b231678c5f01c362ba6 Mon Sep 17 00:00:00 2001 From: Josie Messa Date: Thu, 14 Feb 2008 11:17:36 +0000 Subject: [PATCH] - New tests for array_slice() function --- .../tests/array/array_slice_basic.phpt | 51 +++ .../tests/array/array_slice_error.phpt | 43 +++ .../tests/array/array_slice_variation10.phpt | 44 +++ .../tests/array/array_slice_variation11.phpt | 227 ++++++++++++ .../tests/array/array_slice_variation2.phpt | 301 ++++++++++++++++ .../tests/array/array_slice_variation3.phpt | 211 +++++++++++ .../tests/array/array_slice_variation4.phpt | 327 ++++++++++++++++++ .../tests/array/array_slice_variation5.phpt | 191 ++++++++++ .../tests/array/array_slice_variation6.phpt | 150 ++++++++ .../tests/array/array_slice_variation7.phpt | 300 ++++++++++++++++ .../tests/array/array_slice_variation8.phpt | 56 +++ .../tests/array/array_slice_variation9.phpt | 73 ++++ 12 files changed, 1974 insertions(+) create mode 100644 ext/standard/tests/array/array_slice_basic.phpt create mode 100644 ext/standard/tests/array/array_slice_error.phpt create mode 100644 ext/standard/tests/array/array_slice_variation10.phpt create mode 100644 ext/standard/tests/array/array_slice_variation11.phpt create mode 100644 ext/standard/tests/array/array_slice_variation2.phpt create mode 100644 ext/standard/tests/array/array_slice_variation3.phpt create mode 100644 ext/standard/tests/array/array_slice_variation4.phpt create mode 100644 ext/standard/tests/array/array_slice_variation5.phpt create mode 100644 ext/standard/tests/array/array_slice_variation6.phpt create mode 100644 ext/standard/tests/array/array_slice_variation7.phpt create mode 100644 ext/standard/tests/array/array_slice_variation8.phpt create mode 100644 ext/standard/tests/array/array_slice_variation9.phpt diff --git a/ext/standard/tests/array/array_slice_basic.phpt b/ext/standard/tests/array/array_slice_basic.phpt new file mode 100644 index 0000000000..a4cbe46751 --- /dev/null +++ b/ext/standard/tests/array/array_slice_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_slice() function : basic functionality +--FILE-- + 1, 'two' => 2, 3, 23 => 4); +$offset = 2; +$length = 2; +$preserve_keys = true; + +// Calling array_slice() with all possible arguments +echo "\n-- All arguments --\n"; +var_dump( array_slice($input, $offset, $length, $preserve_keys) ); + +// Calling array_slice() with mandatory arguments +echo "\n-- Mandatory arguments --\n"; +var_dump( array_slice($input, $offset) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : basic functionality *** + +-- All arguments -- +array(2) { + [0]=> + int(3) + [23]=> + int(4) +} + +-- Mandatory arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_error.phpt b/ext/standard/tests/array/array_slice_error.phpt new file mode 100644 index 0000000000..0e8f1c7571 --- /dev/null +++ b/ext/standard/tests/array/array_slice_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_slice() function : error conditions - Pass incorrect number of args +--FILE-- + +--EXPECTF-- +*** Testing array_slice() : error conditions *** + +-- Testing array_slice() function with more than expected no. of arguments -- + +Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d +NULL + +-- Testing array_slice() function with less than expected no. of arguments -- + +Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation10.phpt b/ext/standard/tests/array/array_slice_variation10.phpt new file mode 100644 index 0000000000..85c521d6d3 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation10.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_slice() function : usage variations - position of internal array pointer +--FILE-- + 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero'); + +echo "\n-- Call array_slice() --\n"; +var_dump($result = array_slice($input, 2)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Call array_slice() -- +array(2) { + [0]=> + string(12) "twenty-three" + [1]=> + string(4) "zero" +} +-- Position of Internal Pointer in Result: -- +0 => twenty-three + +-- Position of Internal Pointer in Original Array: -- +one => un +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation11.phpt b/ext/standard/tests/array/array_slice_variation11.phpt new file mode 100644 index 0000000000..4c7a148c88 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation11.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $input arg +--FILE-- + + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_slice() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation2.phpt b/ext/standard/tests/array/array_slice_variation2.phpt new file mode 100644 index 0000000000..15da00216f --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation2.phpt @@ -0,0 +1,301 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $offset arg +--FILE-- + 1, 2, 'three' => 3, 4); + +//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 = << + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 2 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 3 -- +array(0) { +} + +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 5 -- +array(0) { +} + +-- Iteration 6 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 7 -- +array(0) { +} + +-- Iteration 8 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 9 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 10 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 11 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 12 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 13 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 14 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 15 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 22 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 23 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation3.phpt b/ext/standard/tests/array/array_slice_variation3.phpt new file mode 100644 index 0000000000..10e5cacdce --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation3.phpt @@ -0,0 +1,211 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $length arg +--FILE-- + 1, 2, 'three' => 3, 4); +$offset = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = << + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(0) { +} + +-- Iteration 2 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 3 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 4 -- +array(0) { +} + +-- Iteration 5 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 6 -- +array(0) { +} + +-- Iteration 7 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 8 -- +array(0) { +} + +-- Iteration 9 -- +array(0) { +} + +-- Iteration 10 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 11 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 12 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 13 -- +array(0) { +} + +-- Iteration 14 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 15 -- +array(0) { +} + +-- Iteration 16 -- +array(0) { +} + +-- Iteration 17 -- +array(0) { +} + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- +array(0) { +} + +-- Iteration 20 -- +array(0) { +} + +-- Iteration 21 -- +array(0) { +} + +-- Iteration 22 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 23 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation4.phpt b/ext/standard/tests/array/array_slice_variation4.phpt new file mode 100644 index 0000000000..f093d2db89 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation4.phpt @@ -0,0 +1,327 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $preserve_keys arg +--FILE-- + 1, 2, 99 => 3, 4); +$offset = 0; +$length = 3; + +//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 = << + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 2 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 3 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 4 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 5 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 6 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 7 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 8 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 15 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 16 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 17 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 4 to be boolean, array given in %s on line %d +NULL + +-- Iteration 19 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 20 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 21 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 4 to be boolean, object given in %s on line %d +NULL + +-- Iteration 23 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 24 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation5.phpt b/ext/standard/tests/array/array_slice_variation5.phpt new file mode 100644 index 0000000000..ed5c82f18f --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation5.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different integers as $offset argument +--FILE-- + 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); + +for ($i = -7; $i <= 7; $i++) { + echo "\n-- \$offset is $i --\n"; + var_dump(array_slice($input, $i)); +} +echo "\n-- \$offset is maximum integer value --\n"; +var_dump(array_slice($input, PHP_INT_MAX)); + +echo "\n-- \$offset is minimum integer value --\n"; +var_dump(array_slice($input, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $offset is -7 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -6 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -5 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -3 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -2 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -1 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 0 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 1 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 2 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 3 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 4 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 5 -- +array(0) { +} + +-- $offset is 6 -- +array(0) { +} + +-- $offset is 7 -- +array(0) { +} + +-- $offset is maximum integer value -- +array(0) { +} + +-- $offset is minimum integer value -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation6.phpt b/ext/standard/tests/array/array_slice_variation6.phpt new file mode 100644 index 0000000000..e210b4dd2b --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation6.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test array_slice() function : usage variations - pass different int values as $length arg +--FILE-- + 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); +$offset = 1; + +for ($i = -6; $i <= 6; $i++) { + echo "\n-- \$length is $i --\n"; + var_dump(array_slice($input, $offset, $i)); +} +echo "\n-- \$length is maximum integer value --\n"; +var_dump(array_slice($input, $offset, PHP_INT_MAX)); + +echo "\n-- \$length is minimum integer value --\n"; +var_dump(array_slice($input, $offset, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $length is -6 -- +array(0) { +} + +-- $length is -5 -- +array(0) { +} + +-- $length is -4 -- +array(0) { +} + +-- $length is -3 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is -2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is -1 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 0 -- +array(0) { +} + +-- $length is 1 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is 2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is 3 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 5 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 6 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is maximum integer value -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is minimum integer value -- +array(0) { +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation7.phpt b/ext/standard/tests/array/array_slice_variation7.phpt new file mode 100644 index 0000000000..abf517d1f2 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation7.phpt @@ -0,0 +1,300 @@ +--TEST-- +Test array_slice() function : usage variations - different data types as keys in an array +--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 array_slice() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator : key type is $type --\n"; + echo "\$preserve_keys = TRUE\n"; + var_dump( array_slice($input, $offset, $length, true) ); + echo "\$preserve_keys = FALSE\n"; + var_dump( array_slice($input, $offset, $length, false) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 : key type is int -- +$preserve_keys = TRUE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} +$preserve_keys = FALSE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2 : key type is float -- +$preserve_keys = TRUE +array(3) { + [10]=> + string(8) "positive" + [-10]=> + string(8) "negative" + [0]=> + string(4) "half" +} +$preserve_keys = FALSE +array(3) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3 : key type is extreme floats -- +$preserve_keys = TRUE +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4 : key type is null uppercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 1" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 : key type is null lowercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 2" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 : key type is bool lowercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7 : key type is bool uppercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8 : key type is empty double quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptyd" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 : key type is empty single quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptys" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 : key type is string -- +$preserve_keys = TRUE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} +$preserve_keys = FALSE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11 : key type is undefined -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(9) "undefined" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 : key type is unset -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(5) "unset" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(5) "unset" +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation8.phpt b/ext/standard/tests/array/array_slice_variation8.phpt new file mode 100644 index 0000000000..aece410c02 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation8.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_slice() function : usage variations - multidimensional arrays +--FILE-- + 'nine'); + +echo "\n-- Slice a two-dimensional array --\n"; +var_dump(array_slice($input, 1, 3)); + +echo "\n-- \$input is a sub-array --\n"; +var_dump(array_slice($input[2], 1, 2)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Slice a two-dimensional array -- +array(3) { + [0]=> + string(3) "one" + [1]=> + array(3) { + [0]=> + string(4) "zero" + [1]=> + string(2) "un" + [2]=> + string(4) "deux" + } + [2]=> + string(4) "nine" +} + +-- $input is a sub-array -- +array(2) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation9.phpt b/ext/standard/tests/array/array_slice_variation9.phpt new file mode 100644 index 0000000000..1961a4046c --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation9.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_slice() function : usage variations - referenced variables +--FILE-- + &$val1, 2 => &$val2, 1 => &$val3); +var_dump(array_slice($input, 1, 2)); + +echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; +$val2 = 'hello, world'; +var_dump(array_slice($input, 1, 2, true)); + +echo "\n-- Pass array by reference --\n"; +$new_input = array (1, 2, 3); +var_dump(array_slice(&$new_input, 1)); +echo "-- Check passed array: --\n"; +var_dump($new_input); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Array of referenced variables ($preserve_keys = default) -- +array(2) { + [0]=> + &string(3) "two" + [1]=> + &string(5) "three" +} +-- Change $val2 ($preserve_keys = TRUE) -- +array(2) { + [2]=> + &string(12) "hello, world" + [1]=> + &string(5) "three" +} + +-- Pass array by reference -- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +-- Check passed array: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done \ No newline at end of file -- 2.40.0