From 9e761076b8ed99ffa2b0da3e8522c3c625f56d4f Mon Sep 17 00:00:00 2001 From: Robert Nicholson Date: Fri, 26 Oct 2007 11:07:13 +0000 Subject: [PATCH] new testcases for array_splice --- .../tests/array/array_splice_basic.phpt | 118 +++ .../tests/array/array_splice_errors.phpt | 42 + .../tests/array/array_splice_variation1.phpt | 111 +++ .../tests/array/array_splice_variation2.phpt | 29 + .../tests/array/array_splice_variation3.phpt | 858 ++++++++++++++++++ .../tests/array/array_splice_variation4.phpt | 71 ++ 6 files changed, 1229 insertions(+) create mode 100644 ext/standard/tests/array/array_splice_basic.phpt create mode 100644 ext/standard/tests/array/array_splice_errors.phpt create mode 100644 ext/standard/tests/array/array_splice_variation1.phpt create mode 100644 ext/standard/tests/array/array_splice_variation2.phpt create mode 100644 ext/standard/tests/array/array_splice_variation3.phpt create mode 100644 ext/standard/tests/array/array_splice_variation4.phpt diff --git a/ext/standard/tests/array/array_splice_basic.phpt b/ext/standard/tests/array/array_splice_basic.phpt new file mode 100644 index 00000000000..efea53c8b12 --- /dev/null +++ b/ext/standard/tests/array/array_splice_basic.phpt @@ -0,0 +1,118 @@ +--TEST-- +Test array_splice(): basic functionality +--INI-- +--FILE-- + +--EXPECT-- +*** Testing array_splice() basic operations *** +test truncation +array(2) { + [0]=> + string(4) "blue" + [1]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" +} +test removing entries from the middle +array(2) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "yellow" +} +test substitution at end +array(3) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" + [2]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "orange" +} +array(1) { + [0]=> + string(6) "yellow" +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(5) "black" + [4]=> + string(6) "maroon" +} +test insertion +array(0) { +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(6) "purple" + [4]=> + string(6) "yellow" +} diff --git a/ext/standard/tests/array/array_splice_errors.phpt b/ext/standard/tests/array/array_splice_errors.phpt new file mode 100644 index 00000000000..04861cfbb86 --- /dev/null +++ b/ext/standard/tests/array/array_splice_errors.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_splice() function : error conditions +--INI-- +--FILE-- + +--EXPECTF-- + +*** Testing error conditions of array_splice() *** + +Warning: Wrong parameter count for array_splice() in %s on line %d +NULL + +Warning: Wrong parameter count for array_splice() in %s on line %d +NULL + +Warning: Wrong parameter count for array_splice() in %s on line %d +NULL + +Warning: array_splice(): The first argument should be an array in %s on line %d +NULL + +Warning: array_splice(): The first argument should be an array in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_splice_variation1.phpt b/ext/standard/tests/array/array_splice_variation1.phpt new file mode 100644 index 00000000000..99685feb281 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation1.phpt @@ -0,0 +1,111 @@ +--TEST-- +Test array_splice() function : usage variations - references + +--INI-- +--FILE-- +&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]); +var_dump (array_splice ($input_array,4,3)); +var_dump ($input_array); + +echo "Test behaviour of replacement array containing references \n"; + +$three=3; +$four=4; +$input_array=array (0,1,2); +$b=array(&$three,"fourkey"=>&$four); +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); + +echo "Test behaviour of replacement which is part of reference set \n"; + +$int=3; +$input_array=array (1,2); +$b=&$int; + +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); +echo "Done\n"; +?> +--EXPECT-- +test behaviour when input array is in a reference set +array(1) { + [0]=> + int(2) +} +array(2) { + [0]=> + &array(1) { + [0]=> + int(1) + } + [1]=> + &array(1) { + [0]=> + int(1) + } +} +Test behaviour of input arrays containing references +array(3) { + [0]=> + int(4) + [1]=> + &int(5) + ["six"]=> + &int(6) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(2) + ["three"]=> + &int(3) + [3]=> + int(7) + [4]=> + &int(8) + ["nine"]=> + &int(9) +} +Test behaviour of replacement array containing references +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(3) + [3]=> + &int(4) +} +Test behaviour of replacement which is part of reference set +array(2) { + [0]=> + int(1) + [1]=> + int(3) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_splice_variation2.phpt b/ext/standard/tests/array/array_splice_variation2.phpt new file mode 100644 index 00000000000..4a2685b0bd0 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation2.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_splice() function : usage variations - additional parameters + +--INI-- +--FILE-- + +--EXPECTF-- + +Warning: Wrong parameter count for array_splice() in %s on line %d +NULL +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_splice_variation3.phpt b/ext/standard/tests/array/array_splice_variation3.phpt new file mode 100644 index 00000000000..d2168665852 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation3.phpt @@ -0,0 +1,858 @@ +--TEST-- +Test array_splice() function : usage variations - lengths and offsets + +--INI-- +--FILE-- + + +--EXPECT-- +*** array_splice() function : usage variations - lengths and offsets +absolute offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +absolute offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(1) "A" + [4]=> + string(1) "B" + [5]=> + string(1) "C" + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - attempt to cut form before beginning + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +relative offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_splice_variation4.phpt b/ext/standard/tests/array/array_splice_variation4.phpt new file mode 100644 index 00000000000..abc1fe8efa1 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation4.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test array_splice() function : usage variations - non array replacement values + +--INI-- +--FILE-- + +--EXPECTF-- +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + float(2.1) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + bool(true) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + resource(%d) of type (stream) +} +Done \ No newline at end of file