summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_splice_basic.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/array/array_splice_basic.phpt
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/array/array_splice_basic.phpt')
-rw-r--r--ext/standard/tests/array/array_splice_basic.phpt117
1 files changed, 117 insertions, 0 deletions
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 0000000..e96303d
--- /dev/null
+++ b/ext/standard/tests/array/array_splice_basic.phpt
@@ -0,0 +1,117 @@
+--TEST--
+Test array_splice(): basic functionality
+--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"
+}