summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_splice_basic.phpt
diff options
context:
space:
mode:
authorRobert Nicholson <nicholsr@php.net>2007-10-26 11:07:13 +0000
committerRobert Nicholson <nicholsr@php.net>2007-10-26 11:07:13 +0000
commit9e761076b8ed99ffa2b0da3e8522c3c625f56d4f (patch)
treef02e9fc1fb3645cd68fbd186e46116924e4c64d0 /ext/standard/tests/array/array_splice_basic.phpt
parent656d0e468bbd462c660d1e12cb9151e66d1bac54 (diff)
downloadphp-git-9e761076b8ed99ffa2b0da3e8522c3c625f56d4f.tar.gz
new testcases for array_splice
Diffstat (limited to 'ext/standard/tests/array/array_splice_basic.phpt')
-rw-r--r--ext/standard/tests/array/array_splice_basic.phpt118
1 files changed, 118 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 0000000000..efea53c8b1
--- /dev/null
+++ b/ext/standard/tests/array/array_splice_basic.phpt
@@ -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"
+}