summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings
diff options
context:
space:
mode:
authorandy wharmby <wharmby@php.net>2009-01-18 14:35:00 +0000
committerandy wharmby <wharmby@php.net>2009-01-18 14:35:00 +0000
commitcdef2ee23b9cf66946eba62f9353af2f249bf448 (patch)
tree154d47109d1177acf0f84b97d48d155bd87f7731 /ext/standard/tests/strings
parent18a6f9e55d9aa6586a42199b3f28c312db38a1a7 (diff)
downloadphp-git-cdef2ee23b9cf66946eba62f9353af2f249bf448.tar.gz
New explode() tests. Tested on Windows. Linux and Linux 64 bit
Diffstat (limited to 'ext/standard/tests/strings')
-rw-r--r--ext/standard/tests/strings/explode_error.phpt37
-rw-r--r--ext/standard/tests/strings/explode_variation1.phpt203
-rw-r--r--ext/standard/tests/strings/explode_variation2.phpt209
-rw-r--r--ext/standard/tests/strings/explode_variation3.phpt238
-rw-r--r--ext/standard/tests/strings/explode_variation4.phpt36
-rw-r--r--ext/standard/tests/strings/explode_variation5.phpt48
-rw-r--r--ext/standard/tests/strings/explode_variation6.phpt70
7 files changed, 841 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/explode_error.phpt b/ext/standard/tests/strings/explode_error.phpt
new file mode 100644
index 0000000000..f7342e7ad3
--- /dev/null
+++ b/ext/standard/tests/strings/explode_error.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test explode() function : error conditions
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() : error conditions ***\n";
+
+echo "\n-- Testing explode() function with no arguments --\n";
+var_dump( explode() );
+
+echo "\n-- Testing explode() function with more than expected no. of arguments --\n";
+$delimeter = " ";
+$string = "piece1 piece2 piece3 piece4 piece5 piece6";
+$limit = 5;
+$extra_arg = 10;
+var_dump( explode($delimeter, $string, $limit, $extra_arg) );
+
+?>
+===Done===
+--EXPECTF--
+*** Testing explode() : error conditions ***
+
+-- Testing explode() function with no arguments --
+
+Warning: explode() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing explode() function with more than expected no. of arguments --
+
+Warning: explode() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+===Done=== \ No newline at end of file
diff --git a/ext/standard/tests/strings/explode_variation1.phpt b/ext/standard/tests/strings/explode_variation1.phpt
new file mode 100644
index 0000000000..abb3c32236
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation1.phpt
@@ -0,0 +1,203 @@
+--TEST--
+Test explode() function : usage variations - test values for $delimiter argument
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: with unexpected inputs for 'delimiter' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return "sample object";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $delimeter
+$delimeters = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ 255,
+ 256,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*7*/ 10.5,
+ -20.5,
+ 10.1234567e10,
+
+ // array values
+/*10*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*13*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null values
+/*17*/ NULL,
+ null,
+
+ // objects
+/*19*/ new sample(),
+
+ // resource
+/*20*/ $file_handle,
+
+ // undefined variable
+/*21*/ @$undefined_var,
+
+ // unset variable
+/*22*/ @$unset_var
+);
+
+// loop through with each element of the $delimeters array to test explode() function
+$count = 1;
+$string = "piece1 piece2 piece3 piece4 piece5 piece6";
+$limit = 5;
+foreach($delimeters as $delimeter) {
+ echo "-- Iteration $count --\n";
+ var_dump( explode($delimeter, $string, $limit) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing explode() function: with unexpected inputs for 'delimiter' argument ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 2 --
+array(2) {
+ [0]=>
+ string(5) "piece"
+ [1]=>
+ string(35) " piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 3 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 4 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 5 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 6 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 7 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 8 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 9 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 13 --
+array(2) {
+ [0]=>
+ string(5) "piece"
+ [1]=>
+ string(35) " piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 14 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+-- Iteration 15 --
+array(2) {
+ [0]=>
+ string(5) "piece"
+ [1]=>
+ string(35) " piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 16 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+-- Iteration 19 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 20 --
+array(1) {
+ [0]=>
+ string(%d) "%s"
+}
+-- Iteration 21 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+-- Iteration 22 --
+
+Warning: explode(): Empty delimiter in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/standard/tests/strings/explode_variation2.phpt b/ext/standard/tests/strings/explode_variation2.phpt
new file mode 100644
index 0000000000..f2c0057fe7
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation2.phpt
@@ -0,0 +1,209 @@
+--TEST--
+Test explode() function : usage variations - test values for $string argument
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: with unexpected inputs for 'string' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return "sample object";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $string
+$strings = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ 255,
+ 256,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*7*/ 10.5,
+ -20.5,
+ 10.1234567e10,
+
+ // array values
+/*10*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*13*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null values
+/*17*/ NULL,
+ null,
+
+ // objects
+/*19*/ new sample(),
+
+ // resource
+/*20*/ $file_handle,
+
+ // undefined variable
+/*21*/ @$undefined_var,
+
+ // unset variable
+/*22*/ @$unset_var
+);
+
+// loop through with each element of the $strings array to test explode() function
+$count = 1;
+$delimeter = " ";
+$limit = 5;
+foreach($strings as $string) {
+ echo "-- Iteration $count --\n";
+ var_dump( explode($delimeter, $string, $limit) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing explode() function: with unexpected inputs for 'string' argument ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(1) "0"
+}
+-- Iteration 2 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 3 --
+array(1) {
+ [0]=>
+ string(3) "255"
+}
+-- Iteration 4 --
+array(1) {
+ [0]=>
+ string(3) "256"
+}
+-- Iteration 5 --
+array(1) {
+ [0]=>
+ string(10) "2147483647"
+}
+-- Iteration 6 --
+array(1) {
+ [0]=>
+ string(11) "-2147483648"
+}
+-- Iteration 7 --
+array(1) {
+ [0]=>
+ string(4) "10.5"
+}
+-- Iteration 8 --
+array(1) {
+ [0]=>
+ string(5) "-20.5"
+}
+-- Iteration 9 --
+array(1) {
+ [0]=>
+ string(12) "101234567000"
+}
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(5) "Array"
+}
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(5) "Array"
+}
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+array(1) {
+ [0]=>
+ string(5) "Array"
+}
+-- Iteration 13 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 14 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 15 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 16 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 17 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 18 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 19 --
+array(2) {
+ [0]=>
+ string(6) "sample"
+ [1]=>
+ string(6) "object"
+}
+-- Iteration 20 --
+array(3) {
+ [0]=>
+ string(8) "Resource"
+ [1]=>
+ string(2) "id"
+ [2]=>
+ string(%d) "#%d"
+}
+-- Iteration 21 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 22 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+===DONE===
diff --git a/ext/standard/tests/strings/explode_variation3.phpt b/ext/standard/tests/strings/explode_variation3.phpt
new file mode 100644
index 0000000000..54d5222caa
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation3.phpt
@@ -0,0 +1,238 @@
+--TEST--
+Test explode() function : usage variations - test values for $limit argument
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: with unexpected inputs for 'limit' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return "sample object";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $delimeter
+$limits = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ 255,
+ 256,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*7*/ 10.5,
+ -20.5,
+ 10.1234567e5,
+
+ // array values
+/*10*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*13*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null values
+/*17*/ NULL,
+ null,
+
+ // objects
+/*19*/ new sample(),
+
+ // resource
+/*20*/ $file_handle,
+
+ // undefined variable
+/*21*/ @$undefined_var,
+
+ // unset variable
+/*22*/ @$unset_var
+);
+
+// loop through with each element of the $limits array to test explode() function
+$count = 1;
+$delimeter = " ";
+$string = "piece1 piece2 piece3 piece4 piece5 piece6";
+foreach($limits as $limit) {
+ echo "-- Iteration $count --\n";
+ var_dump( explode($delimeter, $string, $limit) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===Done===
+--EXPECTF--
+*** Testing explode() function: with unexpected inputs for 'limit' argument ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 2 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 3 --
+array(6) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(6) "piece2"
+ [2]=>
+ string(6) "piece3"
+ [3]=>
+ string(6) "piece4"
+ [4]=>
+ string(6) "piece5"
+ [5]=>
+ string(6) "piece6"
+}
+-- Iteration 4 --
+array(6) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(6) "piece2"
+ [2]=>
+ string(6) "piece3"
+ [3]=>
+ string(6) "piece4"
+ [4]=>
+ string(6) "piece5"
+ [5]=>
+ string(6) "piece6"
+}
+-- Iteration 5 --
+array(6) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(6) "piece2"
+ [2]=>
+ string(6) "piece3"
+ [3]=>
+ string(6) "piece4"
+ [4]=>
+ string(6) "piece5"
+ [5]=>
+ string(6) "piece6"
+}
+-- Iteration 6 --
+array(0) {
+}
+-- Iteration 7 --
+array(6) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(6) "piece2"
+ [2]=>
+ string(6) "piece3"
+ [3]=>
+ string(6) "piece4"
+ [4]=>
+ string(6) "piece5"
+ [5]=>
+ string(6) "piece6"
+}
+-- Iteration 8 --
+array(0) {
+}
+-- Iteration 9 --
+array(6) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(6) "piece2"
+ [2]=>
+ string(6) "piece3"
+ [3]=>
+ string(6) "piece4"
+ [4]=>
+ string(6) "piece5"
+ [5]=>
+ string(6) "piece6"
+}
+-- Iteration 10 --
+
+Warning: explode() expects parameter 3 to be long, array given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: explode() expects parameter 3 to be long, array given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: explode() expects parameter 3 to be long, array given in %s on line %d
+NULL
+-- Iteration 13 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 14 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 15 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 16 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 17 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 18 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 19 --
+
+Warning: explode() expects parameter 3 to be long, object given in %s on line %d
+NULL
+-- Iteration 20 --
+
+Warning: explode() expects parameter 3 to be long, resource given in %s on line %d
+NULL
+-- Iteration 21 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+-- Iteration 22 --
+array(1) {
+ [0]=>
+ string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
+}
+===Done=== \ No newline at end of file
diff --git a/ext/standard/tests/strings/explode_variation4.phpt b/ext/standard/tests/strings/explode_variation4.phpt
new file mode 100644
index 0000000000..080531c6ec
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation4.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test explode() function : usage variations - match longer string
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: match longer string ***\n";
+
+$pizza = "piece1 piece2 piece3 piece4 piece5 piece6 p";
+$pieces = explode(" p", $pizza);
+var_dump($pieces);
+?>
+===DONE===
+--EXPECT--
+*** Testing explode() function: match longer string ***
+array(7) {
+ [0]=>
+ string(6) "piece1"
+ [1]=>
+ string(5) "iece2"
+ [2]=>
+ string(5) "iece3"
+ [3]=>
+ string(5) "iece4"
+ [4]=>
+ string(5) "iece5"
+ [5]=>
+ string(5) "iece6"
+ [6]=>
+ string(0) ""
+}
+===DONE===
diff --git a/ext/standard/tests/strings/explode_variation5.phpt b/ext/standard/tests/strings/explode_variation5.phpt
new file mode 100644
index 0000000000..754e55222a
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation5.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test explode() function : usage variations - positive and negative limits
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: positive and negative limits ***\n";
+$str = 'one||two||three||four';
+
+echo "\n-- positive limit --\n";
+var_dump(explode('||', $str, 2));
+
+echo "\n-- negative limit (since PHP 5.1) --\n";
+var_dump(explode('||', $str, -1));
+
+echo "\n-- negative limit (since PHP 5.1) with null string -- \n";
+var_dump(explode('||', "", -1));
+?>
+===DONE===
+--EXPECT--
+*** Testing explode() function: positive and negative limits ***
+
+-- positive limit --
+array(2) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(16) "two||three||four"
+}
+
+-- negative limit (since PHP 5.1) --
+array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+}
+
+-- negative limit (since PHP 5.1) with null string --
+array(0) {
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/standard/tests/strings/explode_variation6.phpt b/ext/standard/tests/strings/explode_variation6.phpt
new file mode 100644
index 0000000000..d1b34e3ef8
--- /dev/null
+++ b/ext/standard/tests/strings/explode_variation6.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Test explode() function : usage variations - misc tests
+--FILE--
+<?php
+
+/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
+ * Description: Split a string by string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing explode() function: misc tests ***\n";
+
+$str = "one\x00two\x00three\x00four";
+
+echo "\n-- positive limit with null separator --\n";
+$e = test_explode("\x00", $str, 2);
+
+echo "\n-- negative limit (since PHP 5.1) with null separator --\n";
+$e = test_explode("\x00", $str, -2);
+
+echo "\n-- unknown string --\n";
+$e = test_explode("fred", $str,1);
+
+echo "\n-- limit = 0 --\n";
+$e = test_explode("\x00", $str, 0);
+
+echo "\n-- limit = -1 --\n";
+$e = test_explode("\x00", $str, -1);
+
+echo "\n-- large limit = -100 --\n";
+$e = test_explode("\x00", $str, 100);
+
+function test_explode($delim, $string, $limit)
+{
+ $e = explode($delim, $string, $limit);
+ foreach ( $e as $v)
+ {
+ var_dump(bin2hex($v));
+ }
+}
+?>
+===DONE===
+--EXPECT--
+*** Testing explode() function: misc tests ***
+
+-- positive limit with null separator --
+string(6) "6f6e65"
+string(28) "74776f00746872656500666f7572"
+
+-- negative limit (since PHP 5.1) with null separator --
+string(6) "6f6e65"
+string(6) "74776f"
+
+-- unknown string --
+string(36) "6f6e650074776f00746872656500666f7572"
+
+-- limit = 0 --
+string(36) "6f6e650074776f00746872656500666f7572"
+
+-- limit = -1 --
+string(6) "6f6e65"
+string(6) "74776f"
+string(10) "7468726565"
+
+-- large limit = -100 --
+string(6) "6f6e65"
+string(6) "74776f"
+string(10) "7468726565"
+string(8) "666f7572"
+===DONE=== \ No newline at end of file