mirror of
https://github.com/php/php-src.git
synced 2024-09-24 03:17:26 +00:00
new testcases for array_splice
This commit is contained in:
parent
656d0e468b
commit
9e761076b8
118
ext/standard/tests/array/array_splice_basic.phpt
Normal file
118
ext/standard/tests/array/array_splice_basic.phpt
Normal file
@ -0,0 +1,118 @@
|
||||
--TEST--
|
||||
Test array_splice(): basic functionality
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_splice() basic operations ***\n";
|
||||
echo "test truncation \n";
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
var_dump (array_splice($input, 2));
|
||||
var_dump ($input);
|
||||
// $input is now array("red", "green")
|
||||
|
||||
echo "test removing entries from the middle \n";
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
var_dump (array_splice($input, 1, -1));
|
||||
var_dump ($input);
|
||||
// $input is now array("red", "yellow")
|
||||
|
||||
echo "test substitution at end \n";
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
var_dump (array_splice($input, 1, count($input), "orange"));
|
||||
var_dump ($input);
|
||||
// $input is now array("red", "orange")
|
||||
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
var_dump (array_splice($input, -1, 1, array("black", "maroon")));
|
||||
var_dump ($input);
|
||||
// $input is now array("red", "green",
|
||||
// "blue", "black", "maroon")
|
||||
|
||||
echo "test insertion \n";
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
var_dump (array_splice($input, 3, 0, "purple"));
|
||||
var_dump ($input);
|
||||
// $input is now array("red", "green",
|
||||
// "blue", "purple", "yellow");
|
||||
|
||||
|
||||
?>
|
||||
--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"
|
||||
}
|
42
ext/standard/tests/array/array_splice_errors.phpt
Normal file
42
ext/standard/tests/array/array_splice_errors.phpt
Normal file
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
Test array_splice() function : error conditions
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "\n*** Testing error conditions of array_splice() ***\n";
|
||||
|
||||
$int=1;
|
||||
$array=array(1,2);
|
||||
var_dump (array_splice());
|
||||
var_dump (array_splice($int));
|
||||
var_dump (array_splice($array));
|
||||
var_dump (array_splice($int,$int));
|
||||
$obj= new stdclass;
|
||||
var_dump (array_splice($obj,0,1));
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--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
|
111
ext/standard/tests/array/array_splice_variation1.phpt
Normal file
111
ext/standard/tests/array/array_splice_variation1.phpt
Normal file
@ -0,0 +1,111 @@
|
||||
--TEST--
|
||||
Test array_splice() function : usage variations - references
|
||||
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
|
||||
echo "test behaviour when input array is in a reference set\n";
|
||||
|
||||
$input_array=array (array(1,2));
|
||||
$input_array[]=&$input_array[0];
|
||||
var_dump (array_splice ($input_array[0],1,1));
|
||||
var_dump ($input_array);
|
||||
|
||||
echo "Test behaviour of input arrays containing references \n";
|
||||
/*
|
||||
* There are three regions to test:, before cut, the cut and after the cut.
|
||||
* For reach we check a plain value, a reference value with integer key and a
|
||||
* reference value with a string key.
|
||||
*/
|
||||
$numbers=array(0,1,2,3,4,5,6,7,8,9,10,11,12);
|
||||
$input_array=array(0,1,&$numbers[2],"three"=>&$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
|
29
ext/standard/tests/array/array_splice_variation2.phpt
Normal file
29
ext/standard/tests/array/array_splice_variation2.phpt
Normal file
@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
Test array_splice() function : usage variations - additional parameters
|
||||
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
$array=array(0,1,2);
|
||||
var_dump (array_splice($array,1,1,3,4,5,6,7,8,9));
|
||||
var_dump ($array);
|
||||
echo "Done\n";
|
||||
?>
|
||||
--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
|
858
ext/standard/tests/array/array_splice_variation3.phpt
Normal file
858
ext/standard/tests/array/array_splice_variation3.phpt
Normal file
@ -0,0 +1,858 @@
|
||||
--TEST--
|
||||
Test array_splice() function : usage variations - lengths and offsets
|
||||
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** array_splice() function : usage variations - lengths and offsets\n";
|
||||
|
||||
|
||||
function test_splice ($offset, $length)
|
||||
{
|
||||
echo " - No replacement\n";
|
||||
$input_array=array(0,1,2,3,4,5);
|
||||
var_dump (array_splice ($input_array,$offset,$length));
|
||||
var_dump ($input_array);
|
||||
echo " - With replacement\n";
|
||||
$input_array=array(0,1,2,3,4,5);
|
||||
var_dump (array_splice ($input_array,$offset,$length,array ("A","B","C")));
|
||||
var_dump ($input_array);
|
||||
}
|
||||
|
||||
echo "absolute offset - absolute length - cut from beginning\n";
|
||||
test_splice (0,2);
|
||||
echo "absolute offset - absolute length - cut from middle\n";
|
||||
test_splice (2,2);
|
||||
echo "absolute offset - absolute length - cut from end\n";
|
||||
test_splice (4,2);
|
||||
echo "absolute offset - absolute length - attempt to cut past end\n";
|
||||
test_splice (4,4);
|
||||
echo "absolute offset - absolute length - cut everything\n";
|
||||
test_splice (0,7);
|
||||
echo "absolute offset - absolute length - cut nothing\n";
|
||||
test_splice (3,0);
|
||||
|
||||
echo "absolute offset - relative length - cut from beginning\n";
|
||||
test_splice (0,-4);
|
||||
|
||||
echo "absolute offset - relative length - cut from middle\n";
|
||||
test_splice (2,-2);
|
||||
|
||||
echo "absolute offset - relative length - attempt to cut form before beginning \n";
|
||||
test_splice (0,-7);
|
||||
|
||||
echo "absolute offset - relative length - cut nothing\n";
|
||||
test_splice (2,-7);
|
||||
|
||||
echo "relative offset - absolute length - cut from beginning\n";
|
||||
test_splice (-6,2);
|
||||
|
||||
echo "relative offset - absolute length - cut from middle\n";
|
||||
test_splice (-4,2);
|
||||
echo "relative offset - absolute length - cut from end\n";
|
||||
test_splice (-2,2);
|
||||
echo "relative offset - absolute length - attempt to cut past end\n";
|
||||
test_splice (-2,4);
|
||||
echo "relative offset - absolute length - cut everything\n";
|
||||
test_splice (-6,6);
|
||||
echo "relative offset - absolute length - cut nothing\n";
|
||||
test_splice (-6,0);
|
||||
|
||||
echo "relative offset - relative length - cut from beginning\n";
|
||||
test_splice (-6,-4);
|
||||
|
||||
echo "relative offset - relative length - cut from middle\n";
|
||||
test_splice (-4,-2);
|
||||
|
||||
echo "relative offset - relative length - cut nothing\n";
|
||||
test_splice (-4,-7);
|
||||
echo "Done\n";
|
||||
?>
|
||||
|
||||
--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
|
71
ext/standard/tests/array/array_splice_variation4.phpt
Normal file
71
ext/standard/tests/array/array_splice_variation4.phpt
Normal file
@ -0,0 +1,71 @@
|
||||
--TEST--
|
||||
Test array_splice() function : usage variations - non array replacement values
|
||||
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array array_splice(array input, int offset [, int length [, array replacement]])
|
||||
* Function is implemented in ext/standard/array.c
|
||||
*/
|
||||
|
||||
function test_splice ($replacement)
|
||||
{
|
||||
$input_array=array(0,1);
|
||||
var_dump (array_splice ($input_array,2,0,$replacement));
|
||||
var_dump ($input_array);
|
||||
}
|
||||
|
||||
test_splice (2);
|
||||
|
||||
test_splice (2.1);
|
||||
|
||||
test_splice (true);
|
||||
//file type resource
|
||||
$file_handle = fopen(__FILE__, "r");
|
||||
|
||||
test_splice ($file_handle);
|
||||
echo "Done\n";
|
||||
?>
|
||||
--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
|
Loading…
Reference in New Issue
Block a user