mirror of
https://github.com/php/php-src.git
synced 2025-01-24 12:43:38 +08:00
New testcases for chunk_split() function
This commit is contained in:
parent
fedf2eddfd
commit
482eabc6b6
53
ext/standard/tests/strings/chunk_split_basic.phpt
Normal file
53
ext/standard/tests/strings/chunk_split_basic.phpt
Normal file
@ -0,0 +1,53 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing chunk_split() for basic functionality by passing all possible
|
||||
* arguments as well as with default arguments chunklen and ending
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : basic functionality ***\n";
|
||||
|
||||
|
||||
// Initialise all required variables
|
||||
$str = 'Testing';
|
||||
$chunklen = 2;
|
||||
$ending = '##';
|
||||
|
||||
// Calling chunk_split() with all possible arguments
|
||||
echo "-- Testing chunk_split() with all possible arguments --\n";
|
||||
var_dump( chunk_split($str, $chunklen, $ending) );
|
||||
|
||||
|
||||
// Calling chunk_split() with default ending string
|
||||
echo "-- Testing chunk_split() with default ending string --\n";
|
||||
var_dump( chunk_split($str, $chunklen) );
|
||||
|
||||
|
||||
//Calling chunk_split() with default chunklen and ending string
|
||||
echo "-- Testing chunk_split() with default chunklen and ending string --\n";
|
||||
var_dump( chunk_split($str) );
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : basic functionality ***
|
||||
-- Testing chunk_split() with all possible arguments --
|
||||
string(15) "Te##st##in##g##"
|
||||
-- Testing chunk_split() with default ending string --
|
||||
string(15) "Te
|
||||
st
|
||||
in
|
||||
g
|
||||
"
|
||||
-- Testing chunk_split() with default chunklen and ending string --
|
||||
string(9) "Testing
|
||||
"
|
||||
Done
|
40
ext/standard/tests/strings/chunk_split_error.phpt
Normal file
40
ext/standard/tests/strings/chunk_split_error.phpt
Normal file
@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing error conditions of chunk_split() with zero arguments
|
||||
* and for more than expected number of argments
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : error conditions ***\n";
|
||||
|
||||
// Zero arguments
|
||||
echo "-- Testing chunk_split() function with Zero arguments --";
|
||||
var_dump( chunk_split() );
|
||||
|
||||
// With one more than the expected number of arguments
|
||||
$str = 'Testing chunk_split';
|
||||
$chunklen = 5;
|
||||
$ending = '***';
|
||||
$extra_arg = 10;
|
||||
echo "-- Testing chunk_split() function with more than expected no. of arguments --";
|
||||
var_dump( chunk_split($str, $chunklen, $ending, $extra_arg) );
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : error conditions ***
|
||||
-- Testing chunk_split() function with Zero arguments --
|
||||
Warning: Wrong parameter count for chunk_split() in %s on line %d
|
||||
NULL
|
||||
-- Testing chunk_split() function with more than expected no. of arguments --
|
||||
Warning: Wrong parameter count for chunk_split() in %s on line %d
|
||||
NULL
|
||||
Done
|
167
ext/standard/tests/strings/chunk_split_variation1.phpt
Normal file
167
ext/standard/tests/strings/chunk_split_variation1.phpt
Normal file
@ -0,0 +1,167 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - with unexpected values for 'str' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line %d%d
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : with unexpected values for 'str' argument ***\n";
|
||||
|
||||
// Initialising variables
|
||||
$chunklen = 2;
|
||||
$ending = ' ';
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//class for object variable
|
||||
class MyClass
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__, 'r');
|
||||
|
||||
//different values for 'str'
|
||||
$values = array(
|
||||
|
||||
// int data
|
||||
0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
10.5,
|
||||
-10.5,
|
||||
10.5e10,
|
||||
10.6E-10,
|
||||
.5,
|
||||
|
||||
// array data
|
||||
array(),
|
||||
array(0),
|
||||
array(1),
|
||||
array(1, 2),
|
||||
array('color' => 'red', 'item' => 'pen'),
|
||||
|
||||
// null data
|
||||
NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
"",
|
||||
'',
|
||||
|
||||
// string data
|
||||
"string",
|
||||
'string',
|
||||
|
||||
// object data
|
||||
new MyClass(),
|
||||
|
||||
// undefined data
|
||||
@$undefined_var,
|
||||
|
||||
// unset data
|
||||
@$unset_var,
|
||||
|
||||
// resource data
|
||||
$fp
|
||||
);
|
||||
|
||||
// loop through each element of the array for 'str'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration ".($count+1)." --\n";
|
||||
var_dump( chunk_split($values[$count], $chunklen, $ending) );
|
||||
};
|
||||
|
||||
echo "Done";
|
||||
|
||||
// close the resource
|
||||
fclose($fp);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : with unexpected values for 'str' argument ***
|
||||
-- Iteration 1 --
|
||||
string(2) "0 "
|
||||
-- Iteration 2 --
|
||||
string(2) "1 "
|
||||
-- Iteration 3 --
|
||||
string(8) "12 34 5 "
|
||||
-- Iteration 4 --
|
||||
string(8) "-2 34 5 "
|
||||
-- Iteration 5 --
|
||||
string(6) "10 .5 "
|
||||
-- Iteration 6 --
|
||||
string(8) "-1 0. 5 "
|
||||
-- Iteration 7 --
|
||||
string(18) "10 50 00 00 00 00 "
|
||||
-- Iteration 8 --
|
||||
string(11) "1. 06 E- 9 "
|
||||
-- Iteration 9 --
|
||||
string(5) "0. 5 "
|
||||
-- Iteration 10 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(8) "Ar ra y "
|
||||
-- Iteration 11 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(8) "Ar ra y "
|
||||
-- Iteration 12 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(8) "Ar ra y "
|
||||
-- Iteration 13 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(8) "Ar ra y "
|
||||
-- Iteration 14 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(8) "Ar ra y "
|
||||
-- Iteration 15 --
|
||||
string(1) " "
|
||||
-- Iteration 16 --
|
||||
string(1) " "
|
||||
-- Iteration 17 --
|
||||
string(2) "1 "
|
||||
-- Iteration 18 --
|
||||
string(1) " "
|
||||
-- Iteration 19 --
|
||||
string(2) "1 "
|
||||
-- Iteration 20 --
|
||||
string(1) " "
|
||||
-- Iteration 21 --
|
||||
string(1) " "
|
||||
-- Iteration 22 --
|
||||
string(1) " "
|
||||
-- Iteration 23 --
|
||||
string(9) "st ri ng "
|
||||
-- Iteration 24 --
|
||||
string(9) "st ri ng "
|
||||
-- Iteration 25 --
|
||||
string(9) "ob je ct "
|
||||
-- Iteration 26 --
|
||||
string(1) " "
|
||||
-- Iteration 27 --
|
||||
string(1) " "
|
||||
-- Iteration 28 --
|
||||
string(21) "Re so ur ce i d #5 "
|
||||
Done
|
86
ext/standard/tests/strings/chunk_split_variation10.phpt
Normal file
86
ext/standard/tests/strings/chunk_split_variation10.phpt
Normal file
@ -0,0 +1,86 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - different single quoted strings for 'ending' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing different single quoted strings for 'ending' arguments to chunk_split()
|
||||
* 'chunklen' is set to 9.2 for this testcase
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : different single quoted strings as 'ending' ***\n";
|
||||
|
||||
|
||||
//Initializing variables
|
||||
$str = "This is to test chunk_split() with various 'single quoted' ending string.";
|
||||
$chunklen = 9.2;
|
||||
|
||||
//different values for 'ending' argument
|
||||
$values = array (
|
||||
'', //empty
|
||||
' ', //space
|
||||
'a', //Single char
|
||||
'ENDING', //String
|
||||
'@#$%^', //Special chars
|
||||
|
||||
|
||||
'\t',
|
||||
'\n',
|
||||
'\r',
|
||||
'\r\n',
|
||||
|
||||
'\0', //Null char
|
||||
'123', //Numeric
|
||||
'(MSG)', //With ( and )
|
||||
') ending string (', //sentence as ending string
|
||||
') numbers 1234 (', //string with numbers
|
||||
') speci@! ch@r$ (' //string with special chars
|
||||
);
|
||||
|
||||
|
||||
//loop through each element of values for 'ending'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump( chunk_split($str, $chunklen, $values[$count]) );
|
||||
}
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : different single quoted strings as 'ending' ***
|
||||
-- Iteration 0 --
|
||||
string(73) "This is to test chunk_split() with various 'single quoted' ending string."
|
||||
-- Iteration 1 --
|
||||
string(82) "This is t o test ch unk_split () with v arious 's ingle quo ted' endi ng string . "
|
||||
-- Iteration 2 --
|
||||
string(82) "This is tao test chaunk_splita() with vaarious 'saingle quoated' endiang stringa.a"
|
||||
-- Iteration 3 --
|
||||
string(127) "This is tENDINGo test chENDINGunk_splitENDING() with vENDINGarious 'sENDINGingle quoENDINGted' endiENDINGng stringENDING.ENDING"
|
||||
-- Iteration 4 --
|
||||
string(118) "This is t@#$%^o test ch@#$%^unk_split@#$%^() with v@#$%^arious 's@#$%^ingle quo@#$%^ted' endi@#$%^ng string@#$%^.@#$%^"
|
||||
-- Iteration 5 --
|
||||
string(91) "This is t\to test ch\tunk_split\t() with v\tarious 's\tingle quo\tted' endi\tng string\t.\t"
|
||||
-- Iteration 6 --
|
||||
string(91) "This is t\no test ch\nunk_split\n() with v\narious 's\ningle quo\nted' endi\nng string\n.\n"
|
||||
-- Iteration 7 --
|
||||
string(91) "This is t\ro test ch\runk_split\r() with v\rarious 's\ringle quo\rted' endi\rng string\r.\r"
|
||||
-- Iteration 8 --
|
||||
string(109) "This is t\r\no test ch\r\nunk_split\r\n() with v\r\narious 's\r\ningle quo\r\nted' endi\r\nng string\r\n.\r\n"
|
||||
-- Iteration 9 --
|
||||
string(91) "This is t\0o test ch\0unk_split\0() with v\0arious 's\0ingle quo\0ted' endi\0ng string\0.\0"
|
||||
-- Iteration 10 --
|
||||
string(100) "This is t123o test ch123unk_split123() with v123arious 's123ingle quo123ted' endi123ng string123.123"
|
||||
-- Iteration 11 --
|
||||
string(118) "This is t(MSG)o test ch(MSG)unk_split(MSG)() with v(MSG)arious 's(MSG)ingle quo(MSG)ted' endi(MSG)ng string(MSG).(MSG)"
|
||||
-- Iteration 12 --
|
||||
string(226) "This is t) ending string (o test ch) ending string (unk_split) ending string (() with v) ending string (arious 's) ending string (ingle quo) ending string (ted' endi) ending string (ng string) ending string (.) ending string ("
|
||||
-- Iteration 13 --
|
||||
string(217) "This is t) numbers 1234 (o test ch) numbers 1234 (unk_split) numbers 1234 (() with v) numbers 1234 (arious 's) numbers 1234 (ingle quo) numbers 1234 (ted' endi) numbers 1234 (ng string) numbers 1234 (.) numbers 1234 ("
|
||||
-- Iteration 14 --
|
||||
string(226) "This is t) speci@! ch@r$ (o test ch) speci@! ch@r$ (unk_split) speci@! ch@r$ (() with v) speci@! ch@r$ (arious 's) speci@! ch@r$ (ingle quo) speci@! ch@r$ (ted' endi) speci@! ch@r$ (ng string) speci@! ch@r$ (.) speci@! ch@r$ ("
|
||||
Done
|
95
ext/standard/tests/strings/chunk_split_variation11.phpt
Normal file
95
ext/standard/tests/strings/chunk_split_variation11.phpt
Normal file
@ -0,0 +1,95 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - different strings for 'ending' with heredoc 'str'
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing different strings for 'ending' and heredoc string as 'str' to chunk_split()
|
||||
* 'chunklen' is set to 6E0 for this testcase
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : different values for 'ending' with heredoc 'str'***\n";
|
||||
|
||||
// Initializing required variables
|
||||
// heredoc string for 'str' argument
|
||||
$heredoc_str = <<<EOT
|
||||
This is heredoc string with \t and \n.It also contains
|
||||
sPeci@! ch@r$ :) & numbers 222.This is \k wrong escape char.
|
||||
EOT;
|
||||
|
||||
$chunklen = 6E+0;
|
||||
|
||||
//different values for 'ending'
|
||||
$values = array (
|
||||
"", //empty
|
||||
" ", //space
|
||||
"a", //single char
|
||||
"ENDING", //regular string
|
||||
"\r\n", //White space char
|
||||
"123", //Numeric
|
||||
")speci@! ch@r$(", //String with special chars
|
||||
);
|
||||
|
||||
//loop through each values for 'ending'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration ".($count+1). " --\n";
|
||||
var_dump( chunk_split($heredoc_str, $chunklen, $values[$count]) );
|
||||
}
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : different values for 'ending' with heredoc 'str'***
|
||||
-- Iteration 1 --
|
||||
string(113) "This is heredoc string with and
|
||||
.It also contains
|
||||
sPeci@! ch@r$ :) & numbers 222.This is \k wrong escape char."
|
||||
-- Iteration 2 --
|
||||
string(132) "This i s here doc st ring w ith and
|
||||
. It als o cont ains
|
||||
s Peci@! ch@r$ :) & number s 222. This i s \k w rong e scape char. "
|
||||
-- Iteration 3 --
|
||||
string(132) "This ias hereadoc staring waith aand
|
||||
.aIt alsao contaains
|
||||
saPeci@!a ch@r$a :) & anumberas 222.aThis ias \k warong eascape achar.a"
|
||||
-- Iteration 4 --
|
||||
string(227) "This iENDINGs hereENDINGdoc stENDINGring wENDINGith ENDINGand
|
||||
.ENDINGIt alsENDINGo contENDINGains
|
||||
sENDINGPeci@!ENDING ch@r$ENDING :) & ENDINGnumberENDINGs 222.ENDINGThis iENDINGs \k wENDINGrong eENDINGscape ENDINGchar.ENDING"
|
||||
-- Iteration 5 --
|
||||
string(151) "This i
|
||||
s here
|
||||
doc st
|
||||
ring w
|
||||
ith
|
||||
and
|
||||
.
|
||||
It als
|
||||
o cont
|
||||
ains
|
||||
s
|
||||
Peci@!
|
||||
ch@r$
|
||||
:) &
|
||||
number
|
||||
s 222.
|
||||
This i
|
||||
s \k w
|
||||
rong e
|
||||
scape
|
||||
char.
|
||||
"
|
||||
-- Iteration 6 --
|
||||
string(170) "This i123s here123doc st123ring w123ith 123and
|
||||
.123It als123o cont123ains
|
||||
s123Peci@!123 ch@r$123 :) & 123number123s 222.123This i123s \k w123rong e123scape 123char.123"
|
||||
-- Iteration 7 --
|
||||
string(398) "This i)speci@! ch@r$(s here)speci@! ch@r$(doc st)speci@! ch@r$(ring w)speci@! ch@r$(ith )speci@! ch@r$(and
|
||||
.)speci@! ch@r$(It als)speci@! ch@r$(o cont)speci@! ch@r$(ains
|
||||
s)speci@! ch@r$(Peci@!)speci@! ch@r$( ch@r$)speci@! ch@r$( :) & )speci@! ch@r$(number)speci@! ch@r$(s 222.)speci@! ch@r$(This i)speci@! ch@r$(s \k w)speci@! ch@r$(rong e)speci@! ch@r$(scape )speci@! ch@r$(char.)speci@! ch@r$("
|
||||
Done
|
145
ext/standard/tests/strings/chunk_split_variation12.phpt
Normal file
145
ext/standard/tests/strings/chunk_split_variation12.phpt
Normal file
@ -0,0 +1,145 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - different heredoc strings for 'ending' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing different heredoc strings as 'ending' argument to chunk_split()
|
||||
* 'chunklen' argument is set to 10
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : different heredoc strings for 'ending' argument ***\n";
|
||||
|
||||
// Initializing required variables
|
||||
$chunklen = 10;
|
||||
$str = "This is str to check with heredoc ending.This\tcontains,\nspeci@! ch@r$ __with wrong \k escape char 222.";
|
||||
|
||||
// Null heredoc string
|
||||
$heredoc_null = <<<EOT1
|
||||
EOT1;
|
||||
|
||||
// heredoc string with single character
|
||||
$heredoc_char = <<<EOT2
|
||||
a
|
||||
EOT2;
|
||||
|
||||
// simple heredoc string
|
||||
$heredoc_str = <<<EOT3
|
||||
This is simple heredoc string
|
||||
EOT3;
|
||||
|
||||
// heredoc with special characters
|
||||
$heredoc_spchar = <<<EOT4
|
||||
This checks with $, %, &, chars
|
||||
EOT4;
|
||||
|
||||
// blank heredoc string
|
||||
$heredoc_blank = <<<EOT5
|
||||
|
||||
EOT5;
|
||||
|
||||
// heredoc with different white space characters
|
||||
$heredoc_escchar = <<<EOT6
|
||||
This checks\t and \nwhite space chars
|
||||
EOT6;
|
||||
|
||||
// heredoc with multiline
|
||||
$heredoc_multiline= <<<EOT7
|
||||
This is to check chunk_split
|
||||
function with multiline
|
||||
heredoc
|
||||
EOT7;
|
||||
|
||||
// heredoc with quotes and slashes
|
||||
$heredoc_quote_slash = <<<EOT8
|
||||
"To check " in heredoc".I'm sure it'll \work!
|
||||
EOT8;
|
||||
|
||||
// different heredoc strings for 'ending'
|
||||
$heredoc_arr = array(
|
||||
$heredoc_null,
|
||||
$heredoc_blank,
|
||||
$heredoc_char,
|
||||
$heredoc_str,
|
||||
$heredoc_multiline,
|
||||
$heredoc_spchar,
|
||||
$heredoc_escchar,
|
||||
$heredoc_quote_slash
|
||||
);
|
||||
|
||||
|
||||
// loop through each element of the heredoc_arr for str
|
||||
$count = 0;
|
||||
foreach($heredoc_arr as $value) {
|
||||
echo "-- Iteration ".($count+1). " --\n";
|
||||
var_dump( chunk_split( $str, $chunklen, $value) );
|
||||
$count++;
|
||||
};
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : different heredoc strings for 'ending' argument ***
|
||||
-- Iteration 1 --
|
||||
string(102) "This is str to check with heredoc ending.This contains,
|
||||
speci@! ch@r$ __with wrong \k escape char 222."
|
||||
-- Iteration 2 --
|
||||
string(102) "This is str to check with heredoc ending.This contains,
|
||||
speci@! ch@r$ __with wrong \k escape char 222."
|
||||
-- Iteration 3 --
|
||||
string(113) "This is star to checka with hereadoc endinga.This contaains,
|
||||
specai@! ch@r$ a__with wroang \k escaape char 22a2.a"
|
||||
-- Iteration 4 --
|
||||
string(421) "This is stThis is simple heredoc stringr to checkThis is simple heredoc string with hereThis is simple heredoc stringdoc endingThis is simple heredoc string.This contThis is simple heredoc stringains,
|
||||
specThis is simple heredoc stringi@! ch@r$ This is simple heredoc string__with wroThis is simple heredoc stringng \k escaThis is simple heredoc stringpe char 22This is simple heredoc string2.This is simple heredoc string"
|
||||
-- Iteration 5 --
|
||||
string(762) "This is stThis is to check chunk_split
|
||||
function with multiline
|
||||
heredocr to checkThis is to check chunk_split
|
||||
function with multiline
|
||||
heredoc with hereThis is to check chunk_split
|
||||
function with multiline
|
||||
heredocdoc endingThis is to check chunk_split
|
||||
function with multiline
|
||||
heredoc.This contThis is to check chunk_split
|
||||
function with multiline
|
||||
heredocains,
|
||||
specThis is to check chunk_split
|
||||
function with multiline
|
||||
heredoci@! ch@r$ This is to check chunk_split
|
||||
function with multiline
|
||||
heredoc__with wroThis is to check chunk_split
|
||||
function with multiline
|
||||
heredocng \k escaThis is to check chunk_split
|
||||
function with multiline
|
||||
heredocpe char 22This is to check chunk_split
|
||||
function with multiline
|
||||
heredoc2.This is to check chunk_split
|
||||
function with multiline
|
||||
heredoc"
|
||||
-- Iteration 6 --
|
||||
string(443) "This is stThis checks with $, %, &, charsr to checkThis checks with $, %, &, chars with hereThis checks with $, %, &, charsdoc endingThis checks with $, %, &, chars.This contThis checks with $, %, &, charsains,
|
||||
specThis checks with $, %, &, charsi@! ch@r$ This checks with $, %, &, chars__with wroThis checks with $, %, &, charsng \k escaThis checks with $, %, &, charspe char 22This checks with $, %, &, chars2.This checks with $, %, &, chars"
|
||||
-- Iteration 7 --
|
||||
string(487) "This is stThis checks and
|
||||
white space charsr to checkThis checks and
|
||||
white space chars with hereThis checks and
|
||||
white space charsdoc endingThis checks and
|
||||
white space chars.This contThis checks and
|
||||
white space charsains,
|
||||
specThis checks and
|
||||
white space charsi@! ch@r$ This checks and
|
||||
white space chars__with wroThis checks and
|
||||
white space charsng \k escaThis checks and
|
||||
white space charspe char 22This checks and
|
||||
white space chars2.This checks and
|
||||
white space chars"
|
||||
-- Iteration 8 --
|
||||
string(597) "This is st"To check " in heredoc".I'm sure it'll \work!r to check"To check " in heredoc".I'm sure it'll \work! with here"To check " in heredoc".I'm sure it'll \work!doc ending"To check " in heredoc".I'm sure it'll \work!.This cont"To check " in heredoc".I'm sure it'll \work!ains,
|
||||
spec"To check " in heredoc".I'm sure it'll \work!i@! ch@r$ "To check " in heredoc".I'm sure it'll \work!__with wro"To check " in heredoc".I'm sure it'll \work!ng \k esca"To check " in heredoc".I'm sure it'll \work!pe char 22"To check " in heredoc".I'm sure it'll \work!2."To check " in heredoc".I'm sure it'll \work!"
|
||||
Done
|
42
ext/standard/tests/strings/chunk_split_variation13.phpt
Normal file
42
ext/standard/tests/strings/chunk_split_variation13.phpt
Normal file
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - default 'chunklen' with long string as 'str'argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing long string as 'str' and testing default value of chunklen which is 76
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : default 'chunklen' with long string 'str' ***\n";
|
||||
|
||||
//Initializing variables
|
||||
$values = array (
|
||||
"123456789012345678901234567890123456789012345678901234567890123456789012345678901",
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
|
||||
);
|
||||
|
||||
//loop through each element of values for 'str' and default value of 'chunklen'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump( chunk_split($values[$count]) );
|
||||
}
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : default 'chunklen' with long string 'str' ***
|
||||
-- Iteration 0 --
|
||||
string(85) "1234567890123456789012345678901234567890123456789012345678901234567890123456
|
||||
78901
|
||||
"
|
||||
-- Iteration 1 --
|
||||
string(217) "1234567890123456789012345678901234567890123456789012345678901234567890123456
|
||||
7890123456789012345678901234567890123456789012345678901234567890123456789012
|
||||
34567890123456789012345678901234567890123456789012345678901
|
||||
"
|
||||
Done
|
172
ext/standard/tests/strings/chunk_split_variation2.phpt
Normal file
172
ext/standard/tests/strings/chunk_split_variation2.phpt
Normal file
@ -0,0 +1,172 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - unexpected values for 'chunklen' argument(Bug#42796)
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***\n";
|
||||
|
||||
// Initialise function arguments
|
||||
$str = 'This is chuklen variation';
|
||||
$ending = '*';
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//get resource variable
|
||||
$fp = fopen(__FILE__, 'r');
|
||||
|
||||
//Class to get object variable
|
||||
class MyClass
|
||||
{
|
||||
public function __toString() {
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
//array of values to iterate over
|
||||
$values = array(
|
||||
|
||||
// float data
|
||||
10.5,
|
||||
-10.5,
|
||||
10.5e10,
|
||||
10.6E-10,
|
||||
.5,
|
||||
|
||||
// array data
|
||||
array(),
|
||||
array(0),
|
||||
array(1),
|
||||
array(1, 2),
|
||||
array('color' => 'red', 'item' => 'pen'),
|
||||
|
||||
// null data
|
||||
NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
"",
|
||||
'',
|
||||
|
||||
// string data
|
||||
"string",
|
||||
'string',
|
||||
|
||||
// object data
|
||||
new MyClass(),
|
||||
|
||||
// undefined data
|
||||
@$undefined_var,
|
||||
|
||||
// unset data
|
||||
@$unset_var,
|
||||
|
||||
// resource variable
|
||||
$fp
|
||||
);
|
||||
|
||||
// loop through each element of the values for 'chunklen'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration ".($count+1)." --\n";
|
||||
var_dump( chunk_split($str, $values[$count], $ending) );
|
||||
}
|
||||
|
||||
echo "Done";
|
||||
|
||||
//closing resource
|
||||
fclose($fp);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***
|
||||
-- Iteration 1 --
|
||||
string(28) "This is ch*uklen vari*ation*"
|
||||
-- Iteration 2 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 3 --
|
||||
string(26) "This is chuklen variation*"
|
||||
-- Iteration 4 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 5 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 6 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 7 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 8 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 9 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 10 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 11 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 12 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 13 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 14 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 15 --
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 16 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 17 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 18 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 19 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 20 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 21 --
|
||||
|
||||
Notice: Object of class MyClass could not be converted to int in %s on line %d
|
||||
string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
|
||||
-- Iteration 22 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 23 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 24 --
|
||||
string(30) "This *is ch*uklen* vari*ation*"
|
||||
Done
|
158
ext/standard/tests/strings/chunk_split_variation3.phpt
Normal file
158
ext/standard/tests/strings/chunk_split_variation3.phpt
Normal file
@ -0,0 +1,158 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - unexpected values for 'ending' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : unexpected values for 'ending' ***\n";
|
||||
|
||||
// Initializing variables
|
||||
$str = 'This is simple string.';
|
||||
$chunklen = 4.9;
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__,'r');
|
||||
|
||||
//Class to get object variable
|
||||
class MyClass
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
//different values for 'ending'
|
||||
$values = array(
|
||||
|
||||
// int data
|
||||
0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
10.5,
|
||||
-10.5,
|
||||
10.5e10,
|
||||
10.6E-10,
|
||||
.5,
|
||||
|
||||
// array data
|
||||
array(),
|
||||
array(0),
|
||||
array(1),
|
||||
array(1, 2),
|
||||
array('color' => 'red', 'item' => 'pen'),
|
||||
|
||||
// null data
|
||||
NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
"",
|
||||
'',
|
||||
|
||||
// object data
|
||||
new MyClass(),
|
||||
|
||||
// undefined data
|
||||
@$undefined_var,
|
||||
|
||||
// unset data
|
||||
@$unset_var,
|
||||
|
||||
// resource data
|
||||
$fp
|
||||
);
|
||||
|
||||
// loop through each element of values for 'ending'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration ".($count+1)." --\n";
|
||||
var_dump( chunk_split($str, $chunklen, $values[$count]) );
|
||||
}
|
||||
|
||||
echo "Done";
|
||||
|
||||
//closing resource
|
||||
fclose($fp);
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : unexpected values for 'ending' ***
|
||||
-- Iteration 1 --
|
||||
string(28) "This0 is 0simp0le s0trin0g.0"
|
||||
-- Iteration 2 --
|
||||
string(28) "This1 is 1simp1le s1trin1g.1"
|
||||
-- Iteration 3 --
|
||||
string(52) "This12345 is 12345simp12345le s12345trin12345g.12345"
|
||||
-- Iteration 4 --
|
||||
string(52) "This-2345 is -2345simp-2345le s-2345trin-2345g.-2345"
|
||||
-- Iteration 5 --
|
||||
string(46) "This10.5 is 10.5simp10.5le s10.5trin10.5g.10.5"
|
||||
-- Iteration 6 --
|
||||
string(52) "This-10.5 is -10.5simp-10.5le s-10.5trin-10.5g.-10.5"
|
||||
-- Iteration 7 --
|
||||
string(94) "This105000000000 is 105000000000simp105000000000le s105000000000trin105000000000g.105000000000"
|
||||
-- Iteration 8 --
|
||||
string(64) "This1.06E-9 is 1.06E-9simp1.06E-9le s1.06E-9trin1.06E-9g.1.06E-9"
|
||||
-- Iteration 9 --
|
||||
string(40) "This0.5 is 0.5simp0.5le s0.5trin0.5g.0.5"
|
||||
-- Iteration 10 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
|
||||
-- Iteration 11 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
|
||||
-- Iteration 12 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
|
||||
-- Iteration 13 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
|
||||
-- Iteration 14 --
|
||||
|
||||
Notice: Array to string conversion in %s on line %d
|
||||
string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
|
||||
-- Iteration 15 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 16 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 17 --
|
||||
string(28) "This1 is 1simp1le s1trin1g.1"
|
||||
-- Iteration 18 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 19 --
|
||||
string(28) "This1 is 1simp1le s1trin1g.1"
|
||||
-- Iteration 20 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 21 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 22 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 23 --
|
||||
string(58) "Thisobject is objectsimpobjectle sobjecttrinobjectg.object"
|
||||
-- Iteration 24 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 25 --
|
||||
string(22) "This is simple string."
|
||||
-- Iteration 26 --
|
||||
string(106) "ThisResource id #5 is Resource id #5simpResource id #5le sResource id #5trinResource id #5g.Resource id #5"
|
||||
Done
|
177
ext/standard/tests/strings/chunk_split_variation4.phpt
Normal file
177
ext/standard/tests/strings/chunk_split_variation4.phpt
Normal file
@ -0,0 +1,177 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - different heredoc strings as 'str' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing different heredoc strings as 'str' argument to the chunk_split()
|
||||
* with 'chunklen' 4 and default value of 'ending' that is "\r\n"
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : heredoc strings as 'str' argument ***\n";
|
||||
|
||||
// Initializing required variables
|
||||
$chunklen = 4;
|
||||
|
||||
// Null heredoc string
|
||||
$heredoc_null = <<<EOT1
|
||||
EOT1;
|
||||
|
||||
// heredoc string with single character
|
||||
$heredoc_char = <<<EOT2
|
||||
a
|
||||
EOT2;
|
||||
|
||||
// simple heredoc string
|
||||
$heredoc_str = <<<EOT3
|
||||
This is simple heredoc string
|
||||
EOT3;
|
||||
|
||||
// heredoc with special characters
|
||||
$heredoc_spchar = <<<EOT4
|
||||
This checks heredoc with $, %, &, chars
|
||||
EOT4;
|
||||
|
||||
// blank heredoc string
|
||||
$heredoc_blank = <<<EOT5
|
||||
|
||||
EOT5;
|
||||
|
||||
// heredoc with different white space characters
|
||||
$heredoc_escchar = <<<EOT6
|
||||
This checks\t chunk_split()\nEscape\rchars
|
||||
EOT6;
|
||||
|
||||
// heredoc with multiline
|
||||
$heredoc_multiline= <<<EOT7
|
||||
This is to check chunk_split
|
||||
function with multiline
|
||||
heredoc
|
||||
EOT7;
|
||||
|
||||
// heredoc with quotes and slashes
|
||||
$heredoc_quote_slash = <<<EOT8
|
||||
"To check " in heredoc"
|
||||
I'm sure it'll work also with \
|
||||
which is single slash
|
||||
EOT8;
|
||||
|
||||
//different heredoc strings for 'str'
|
||||
$heredoc_arr = array(
|
||||
$heredoc_null,
|
||||
$heredoc_blank,
|
||||
$heredoc_char,
|
||||
$heredoc_str,
|
||||
$heredoc_multiline,
|
||||
$heredoc_spchar,
|
||||
$heredoc_escchar,
|
||||
$heredoc_quote_slash
|
||||
);
|
||||
|
||||
|
||||
// loop through each element of the heredoc_arr for 'str'
|
||||
$count = 0;
|
||||
foreach($heredoc_arr as $str) {
|
||||
echo "-- Iteration ".($count+1). " --\n";
|
||||
var_dump( chunk_split( $str, $chunklen) );
|
||||
$count++;
|
||||
};
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : heredoc strings as 'str' argument ***
|
||||
-- Iteration 1 --
|
||||
string(2) "
|
||||
"
|
||||
-- Iteration 2 --
|
||||
string(2) "
|
||||
"
|
||||
-- Iteration 3 --
|
||||
string(3) "a
|
||||
"
|
||||
-- Iteration 4 --
|
||||
string(45) "This
|
||||
is
|
||||
simp
|
||||
le h
|
||||
ered
|
||||
oc s
|
||||
trin
|
||||
g
|
||||
"
|
||||
-- Iteration 5 --
|
||||
string(90) "This
|
||||
is
|
||||
to c
|
||||
heck
|
||||
chu
|
||||
nk_s
|
||||
plit
|
||||
|
||||
fun
|
||||
ctio
|
||||
n wi
|
||||
th m
|
||||
ulti
|
||||
line
|
||||
|
||||
her
|
||||
edoc
|
||||
"
|
||||
-- Iteration 6 --
|
||||
string(59) "This
|
||||
che
|
||||
cks
|
||||
here
|
||||
doc
|
||||
with
|
||||
$,
|
||||
%, &
|
||||
, ch
|
||||
ars
|
||||
"
|
||||
-- Iteration 7 --
|
||||
string(59) "This
|
||||
che
|
||||
cks
|
||||
chu
|
||||
nk_s
|
||||
plit
|
||||
()
|
||||
E
|
||||
scap
|
||||
e
|
||||
ch
|
||||
ars
|
||||
"
|
||||
-- Iteration 8 --
|
||||
string(117) ""To
|
||||
chec
|
||||
k "
|
||||
in h
|
||||
ered
|
||||
oc"
|
||||
|
||||
I'm
|
||||
sure
|
||||
it'
|
||||
ll w
|
||||
ork
|
||||
also
|
||||
wit
|
||||
h \
|
||||
|
||||
whic
|
||||
h is
|
||||
sin
|
||||
gle
|
||||
slas
|
||||
h
|
||||
"
|
||||
Done
|
BIN
ext/standard/tests/strings/chunk_split_variation5.phpt
Normal file
BIN
ext/standard/tests/strings/chunk_split_variation5.phpt
Normal file
Binary file not shown.
76
ext/standard/tests/strings/chunk_split_variation6.phpt
Normal file
76
ext/standard/tests/strings/chunk_split_variation6.phpt
Normal file
@ -0,0 +1,76 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - single quoted strings for 'str' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions: none
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing different single quoted strings as 'str' argument to the function
|
||||
* 'chunklen' is set to 7 and 'ending' is '):('
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : with different single quoted 'str' ***\n";
|
||||
|
||||
//Initializing variables
|
||||
$chunklen = 7;
|
||||
$ending = "):(";
|
||||
|
||||
//different single quoted string for 'str'
|
||||
$values = array(
|
||||
'', //empty
|
||||
' ', //space
|
||||
'This is simple string', //regular string
|
||||
'It\'s string with quotes',
|
||||
'This contains @ # $ % ^ & chars', //special characters
|
||||
'This string\tcontains\rwhite space\nchars', //with white space chars
|
||||
'This is string with 1234 numbers',
|
||||
'This is string with \0 and ".chr(0)."null chars', //for binary safe
|
||||
'This is string with multiple space char',
|
||||
'This is to check string with ()',
|
||||
' Testing with multiple spaces ',
|
||||
'Testing invalid \k and \m escape char',
|
||||
'This is to check with \\n and \\t'
|
||||
);
|
||||
|
||||
|
||||
//Loop through each element of values for 'str'
|
||||
for($count = 0;$count < count($values);$count++) {
|
||||
echo "-- Iteration $count --\n";
|
||||
var_dump( chunk_split($values[$count], $chunklen, $ending) );
|
||||
}
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : with different single quoted 'str' ***
|
||||
-- Iteration 0 --
|
||||
string(3) "):("
|
||||
-- Iteration 1 --
|
||||
string(4) " ):("
|
||||
-- Iteration 2 --
|
||||
string(30) "This is):( simple):( string):("
|
||||
-- Iteration 3 --
|
||||
string(35) "It's st):(ring wi):(th quot):(es):("
|
||||
-- Iteration 4 --
|
||||
string(46) "This co):(ntains ):(@ # $ %):( ^ & ch):(ars):("
|
||||
-- Iteration 5 --
|
||||
string(59) "This st):(ring\tc):(ontains):(\rwhite):( space\):(nchars):("
|
||||
-- Iteration 6 --
|
||||
string(47) "This is):( string):( with 1):(234 num):(bers):("
|
||||
-- Iteration 7 --
|
||||
string(68) "This is):( string):( with \):(0 and "):(.chr(0)):(."null ):(chars):("
|
||||
-- Iteration 8 --
|
||||
string(74) "This is):( string):( with ):( multi):(ple ):( sp):(ace cha):(r):("
|
||||
-- Iteration 9 --
|
||||
string(46) "This is):( to che):(ck stri):(ng with):( ()):("
|
||||
-- Iteration 10 --
|
||||
string(59) " Te):(sting w):(ith ):(multipl):(e space):(s ):("
|
||||
-- Iteration 11 --
|
||||
string(55) "Testing):( invali):(d \k an):(d \m es):(cape ch):(ar):("
|
||||
-- Iteration 12 --
|
||||
string(46) "This is):( to che):(ck with):( \n and):( \t):("
|
||||
Done
|
BIN
ext/standard/tests/strings/chunk_split_variation7.phpt
Normal file
BIN
ext/standard/tests/strings/chunk_split_variation7.phpt
Normal file
Binary file not shown.
88
ext/standard/tests/strings/chunk_split_variation8.phpt
Normal file
88
ext/standard/tests/strings/chunk_split_variation8.phpt
Normal file
@ -0,0 +1,88 @@
|
||||
--TEST--
|
||||
Test chunk_split() function : usage variations - different integer values for 'chunklen' with heredoc string as 'str'(Bug#42796)
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
|
||||
* Description: Returns split line
|
||||
* Source code: ext/standard/string.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
/*
|
||||
* passing different integer values for 'chunklen' and heredoc string for 'str' to chunk_split()
|
||||
*/
|
||||
|
||||
echo "*** Testing chunk_split() : different 'chunklen' with heredoc 'str' ***\n";
|
||||
|
||||
|
||||
// Initializing required variables
|
||||
//heredoc string as str
|
||||
$heredoc_str = <<<EOT
|
||||
This's heredoc string with \t and \n white space char.
|
||||
It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
|
||||
chunk_split()
|
||||
EOT;
|
||||
|
||||
$ending = ':::';
|
||||
|
||||
// different values for 'chunklen'
|
||||
$values = array (
|
||||
0,
|
||||
1,
|
||||
-123, //negative integer
|
||||
0234, //octal number
|
||||
0x1A, //hexadecimal number
|
||||
2147483647, //max positive integer number
|
||||
2147483648, //max positive integer+1
|
||||
-2147483648, //min negative integer
|
||||
|
||||
);
|
||||
|
||||
|
||||
// loop through each element of values for 'chunklen'
|
||||
for($count = 0; $count < count($values); $count++) {
|
||||
echo "-- Iteration ".($count+1). " --\n";
|
||||
var_dump( chunk_split($heredoc_str, $values[$count], $ending) );
|
||||
}
|
||||
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing chunk_split() : different 'chunklen' with heredoc 'str' ***
|
||||
-- Iteration 1 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 2 --
|
||||
string(504) "T:::h:::i:::s:::':::s::: :::h:::e:::r:::e:::d:::o:::c::: :::s:::t:::r:::i:::n:::g::: :::w:::i:::t:::h::: ::: ::: :::a:::n:::d::: :::
|
||||
::: :::w:::h:::i:::t:::e::: :::s:::p:::a:::c:::e::: :::c:::h:::a:::r:::.:::
|
||||
:::I:::t::: :::h:::a:::s::: :::_:::s:::p:::e:::c:::i:::@:::l::: :::c:::h:::@:::r:::$::: :::2:::2:::2:::2::: :::!:::!:::!:::N:::o:::w::: :::\:::k::: :::a:::s::: :::e:::s:::c:::a:::p:::e::: :::c:::h:::a:::r::: :::t:::o::: :::t:::e:::s:::t:::
|
||||
:::c:::h:::u:::n:::k:::_:::s:::p:::l:::i:::t:::(:::):::"
|
||||
-- Iteration 3 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 4 --
|
||||
string(129) "This's heredoc string with and
|
||||
white space char.
|
||||
It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
|
||||
chunk_split():::"
|
||||
-- Iteration 5 --
|
||||
string(141) "This's heredoc string with::: and
|
||||
white space char.:::
|
||||
It has _speci@l ch@r$ 222:::2 !!!Now \k as escape char::: to test
|
||||
chunk_split():::"
|
||||
-- Iteration 6 --
|
||||
string(129) "This's heredoc string with and
|
||||
white space char.
|
||||
It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
|
||||
chunk_split():::"
|
||||
-- Iteration 7 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
-- Iteration 8 --
|
||||
|
||||
Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
Done
|
BIN
ext/standard/tests/strings/chunk_split_variation9.phpt
Normal file
BIN
ext/standard/tests/strings/chunk_split_variation9.phpt
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user