wharmby Sun Jan 18 14:34:52 2009 UTC Added files: (Branch: PHP_5_2) /php-src/ext/standard/tests/strings explode_variation6.phpt explode_variation1.phpt explode_variation2.phpt explode_variation4.phpt explode_variation3.phpt explode_variation5.phpt explode_error.phpt Log: New explode() tests. Tested on Windows. Linux and Linux 64 bit
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation6.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation6.phpt +++ php-src/ext/standard/tests/strings/explode_variation6.phpt --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 = b"one\x00two\x00three\x00four"; echo "\n-- positive limit with null separator --\n"; $e = test_explode(b"\x00", $str, 2); echo "\n-- negative limit (since PHP 5.1) with null separator --\n"; $e = test_explode(b"\x00", $str, -2); echo "\n-- unknown string --\n"; $e = test_explode(b"fred", $str,1); echo "\n-- limit = 0 --\n"; $e = test_explode(b"\x00", $str, 0); echo "\n-- limit = -1 --\n"; $e = test_explode(b"\x00", $str, -1); echo "\n-- large limit = -100 --\n"; $e = test_explode(b"\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 -- unicode(6) "6f6e65" unicode(28) "74776f00746872656500666f7572" -- negative limit (since PHP 5.1) with null separator -- unicode(6) "6f6e65" unicode(6) "74776f" -- unknown string -- unicode(36) "6f6e650074776f00746872656500666f7572" -- limit = 0 -- unicode(36) "6f6e650074776f00746872656500666f7572" -- limit = -1 -- unicode(6) "6f6e65" unicode(6) "74776f" unicode(10) "7468726565" -- large limit = -100 -- unicode(6) "6f6e65" unicode(6) "74776f" unicode(10) "7468726565" unicode(8) "666f7572" ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation1.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation1.phpt +++ php-src/ext/standard/tests/strings/explode_variation1.phpt --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]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 2 -- array(2) { [0]=> unicode(5) "piece" [1]=> unicode(35) " piece2 piece3 piece4 piece5 piece6" } -- Iteration 3 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 4 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 5 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 6 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 7 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 8 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 9 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 10 -- Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 11 -- Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 12 -- Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 13 -- array(2) { [0]=> unicode(5) "piece" [1]=> unicode(35) " piece2 piece3 piece4 piece5 piece6" } -- Iteration 14 -- Warning: explode(): Empty delimiter in %s on line %d bool(false) -- Iteration 15 -- array(2) { [0]=> unicode(5) "piece" [1]=> unicode(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]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 20 -- Warning: explode() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d NULL -- 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=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation2.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation2.phpt +++ php-src/ext/standard/tests/strings/explode_variation2.phpt --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.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 $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]=> unicode(1) "0" } -- Iteration 2 -- array(1) { [0]=> unicode(1) "1" } -- Iteration 3 -- array(1) { [0]=> unicode(3) "255" } -- Iteration 4 -- array(1) { [0]=> unicode(3) "256" } -- Iteration 5 -- array(1) { [0]=> unicode(10) "2147483647" } -- Iteration 6 -- array(1) { [0]=> unicode(11) "-2147483648" } -- Iteration 7 -- array(1) { [0]=> unicode(4) "10.5" } -- Iteration 8 -- array(1) { [0]=> unicode(5) "-20.5" } -- Iteration 9 -- array(1) { [0]=> unicode(10) "1012345.67" } -- Iteration 10 -- Warning: explode() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 11 -- Warning: explode() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 12 -- Warning: explode() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d NULL -- Iteration 13 -- array(1) { [0]=> unicode(1) "1" } -- Iteration 14 -- array(1) { [0]=> unicode(0) "" } -- Iteration 15 -- array(1) { [0]=> unicode(1) "1" } -- Iteration 16 -- array(1) { [0]=> unicode(0) "" } -- Iteration 17 -- array(1) { [0]=> unicode(0) "" } -- Iteration 18 -- array(1) { [0]=> unicode(0) "" } -- Iteration 19 -- array(2) { [0]=> unicode(6) "sample" [1]=> unicode(6) "object" } -- Iteration 20 -- Warning: explode() expects parameter 2 to be string (Unicode or binary), resource given in %s on line %d NULL -- Iteration 21 -- array(1) { [0]=> unicode(0) "" } -- Iteration 22 -- array(1) { [0]=> unicode(0) "" } ===Done=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation4.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation4.phpt +++ php-src/ext/standard/tests/strings/explode_variation4.phpt --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]=> unicode(6) "piece1" [1]=> unicode(5) "iece2" [2]=> unicode(5) "iece3" [3]=> unicode(5) "iece4" [4]=> unicode(5) "iece5" [5]=> unicode(5) "iece6" [6]=> unicode(0) "" } ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation3.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation3.phpt +++ php-src/ext/standard/tests/strings/explode_variation3.phpt --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]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 2 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 3 -- array(6) { [0]=> unicode(6) "piece1" [1]=> unicode(6) "piece2" [2]=> unicode(6) "piece3" [3]=> unicode(6) "piece4" [4]=> unicode(6) "piece5" [5]=> unicode(6) "piece6" } -- Iteration 4 -- array(6) { [0]=> unicode(6) "piece1" [1]=> unicode(6) "piece2" [2]=> unicode(6) "piece3" [3]=> unicode(6) "piece4" [4]=> unicode(6) "piece5" [5]=> unicode(6) "piece6" } -- Iteration 5 -- array(6) { [0]=> unicode(6) "piece1" [1]=> unicode(6) "piece2" [2]=> unicode(6) "piece3" [3]=> unicode(6) "piece4" [4]=> unicode(6) "piece5" [5]=> unicode(6) "piece6" } -- Iteration 6 -- array(0) { } -- Iteration 7 -- array(6) { [0]=> unicode(6) "piece1" [1]=> unicode(6) "piece2" [2]=> unicode(6) "piece3" [3]=> unicode(6) "piece4" [4]=> unicode(6) "piece5" [5]=> unicode(6) "piece6" } -- Iteration 8 -- array(0) { } -- Iteration 9 -- array(6) { [0]=> unicode(6) "piece1" [1]=> unicode(6) "piece2" [2]=> unicode(6) "piece3" [3]=> unicode(6) "piece4" [4]=> unicode(6) "piece5" [5]=> unicode(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]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 14 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 15 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 16 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 17 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 18 -- array(1) { [0]=> unicode(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]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } -- Iteration 22 -- array(1) { [0]=> unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6" } ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_variation5.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_variation5.phpt +++ php-src/ext/standard/tests/strings/explode_variation5.phpt --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]=> unicode(3) "one" [1]=> unicode(16) "two||three||four" } -- negative limit (since PHP 5.1) -- array(3) { [0]=> unicode(3) "one" [1]=> unicode(3) "two" [2]=> unicode(5) "three" } -- negative limit (since PHP 5.1) with null string -- array(0) { } ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/explode_error.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/explode_error.phpt +++ php-src/ext/standard/tests/strings/explode_error.phpt --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===
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php