mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
New explode() tests. Tested on Windows. Linux and Linux 64 bit
This commit is contained in:
parent
18a6f9e55d
commit
cdef2ee23b
37
ext/standard/tests/strings/explode_error.phpt
Normal file
37
ext/standard/tests/strings/explode_error.phpt
Normal file
@ -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===
|
203
ext/standard/tests/strings/explode_variation1.phpt
Normal file
203
ext/standard/tests/strings/explode_variation1.phpt
Normal file
@ -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===
|
209
ext/standard/tests/strings/explode_variation2.phpt
Normal file
209
ext/standard/tests/strings/explode_variation2.phpt
Normal file
@ -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===
|
238
ext/standard/tests/strings/explode_variation3.phpt
Normal file
238
ext/standard/tests/strings/explode_variation3.phpt
Normal file
@ -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===
|
36
ext/standard/tests/strings/explode_variation4.phpt
Normal file
36
ext/standard/tests/strings/explode_variation4.phpt
Normal file
@ -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===
|
48
ext/standard/tests/strings/explode_variation5.phpt
Normal file
48
ext/standard/tests/strings/explode_variation5.phpt
Normal file
@ -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===
|
70
ext/standard/tests/strings/explode_variation6.phpt
Normal file
70
ext/standard/tests/strings/explode_variation6.phpt
Normal file
@ -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===
|
Loading…
Reference in New Issue
Block a user