mirror of
https://github.com/php/php-src.git
synced 2026-03-27 17:52:16 +01:00
split test
This commit is contained in:
45
ext/standard/tests/strings/substr_count_basic.phpt
Normal file
45
ext/standard/tests/strings/substr_count_basic.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
Test substr_count() function (basic)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "***Testing basic operations ***\n";
|
||||
var_dump(@substr_count("", ""));
|
||||
var_dump(@substr_count("a", ""));
|
||||
var_dump(@substr_count("", "a"));
|
||||
var_dump(@substr_count("", "a"));
|
||||
var_dump(@substr_count("", chr(0)));
|
||||
$a = str_repeat("abcacba", 100);
|
||||
var_dump(@substr_count($a, "bca"));
|
||||
$a = str_repeat("abcacbabca", 100);
|
||||
var_dump(@substr_count($a, "bca"));
|
||||
var_dump(substr_count($a, "bca", 200));
|
||||
var_dump(substr_count($a, "bca", 200, 50));
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
***Testing basic operations ***
|
||||
bool(false)
|
||||
bool(false)
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
int(100)
|
||||
int(200)
|
||||
int(160)
|
||||
int(10)
|
||||
Done
|
||||
--UEXPECTF--
|
||||
***Testing basic operations ***
|
||||
bool(false)
|
||||
bool(false)
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
int(100)
|
||||
int(200)
|
||||
int(160)
|
||||
int(10)
|
||||
Done
|
||||
63
ext/standard/tests/strings/substr_count_error.phpt
Normal file
63
ext/standard/tests/strings/substr_count_error.phpt
Normal file
@@ -0,0 +1,63 @@
|
||||
--TEST--
|
||||
Test substr_count() function (error conditions)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing error conditions ***\n";
|
||||
/* Zero argument */
|
||||
var_dump( substr_count() );
|
||||
|
||||
/* more than expected no. of args */
|
||||
var_dump( substr_count($str, "t", 0, 15, 30) );
|
||||
|
||||
/* offset as negative value */
|
||||
var_dump(substr_count($str, "t", -5));
|
||||
|
||||
/* offset > size of the string */
|
||||
var_dump(substr_count($str, "t", 25));
|
||||
|
||||
/* Using offset and length to go beyond the size of the string:
|
||||
Warning message expected, as length+offset > length of string */
|
||||
var_dump( substr_count($str, "i", 5, 15) );
|
||||
|
||||
/* length as Null */
|
||||
var_dump( substr_count($str, "t", "", "") );
|
||||
var_dump( substr_count($str, "i", NULL, NULL) );
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing error conditions ***
|
||||
|
||||
Warning: substr_count() expects at least 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
|
||||
Warning: substr_count() expects at most 4 parameters, 5 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
|
||||
Warning: substr_count(): Offset should be greater than or equal to 0 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
|
||||
Warning: substr_count(): Offset value 25 exceeds string length in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
|
||||
Warning: substr_count(): Offset value 5 exceeds string length in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
|
||||
Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
|
||||
NULL
|
||||
|
||||
Notice: Undefined variable: str in %s on line %d
|
||||
int(0)
|
||||
Done
|
||||
@@ -1,25 +1,7 @@
|
||||
--TEST--
|
||||
Test substr_count() function
|
||||
Test substr_count() function (variation - 1)
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype: int substr_count ( string $haystack, string $needle [, int $offset [, int $length]] );
|
||||
* Description: substr_count() returns the number of times the needle substring occurs in the
|
||||
* haystack string. Please note that needle is case sensitive
|
||||
*/
|
||||
|
||||
/* Count the number of substring occurrences */
|
||||
echo "***Testing basic operations ***\n";
|
||||
var_dump(@substr_count("", ""));
|
||||
var_dump(@substr_count("a", ""));
|
||||
var_dump(@substr_count("", "a"));
|
||||
var_dump(@substr_count("", "a"));
|
||||
var_dump(@substr_count("", chr(0)));
|
||||
$a = str_repeat("abcacba", 100);
|
||||
var_dump(@substr_count($a, "bca"));
|
||||
$a = str_repeat("abcacbabca", 100);
|
||||
var_dump(@substr_count($a, "bca"));
|
||||
var_dump(substr_count($a, "bca", 200));
|
||||
var_dump(substr_count($a, "bca", 200, 50));
|
||||
|
||||
echo "\n*** Testing possible variations ***\n";
|
||||
echo "-- 3rd or 4th arg as string --\n";
|
||||
@@ -67,43 +49,10 @@ var_dump(substr_count($str, "\0"));
|
||||
var_dump(substr_count($str, "\x000"));
|
||||
var_dump(substr_count($str, "0"));
|
||||
|
||||
|
||||
echo "\n*** Testing error conditions ***\n";
|
||||
/* Zero argument */
|
||||
var_dump( substr_count() );
|
||||
|
||||
/* more than expected no. of args */
|
||||
var_dump( substr_count($str, "t", 0, 15, 30) );
|
||||
|
||||
/* offset as negative value */
|
||||
var_dump(substr_count($str, "t", -5));
|
||||
|
||||
/* offset > size of the string */
|
||||
var_dump(substr_count($str, "t", 25));
|
||||
|
||||
/* Using offset and length to go beyond the size of the string:
|
||||
Warning message expected, as length+offset > length of string */
|
||||
var_dump( substr_count($str, "i", 5, 15) );
|
||||
|
||||
/* length as Null */
|
||||
var_dump( substr_count($str, "t", "", "") );
|
||||
var_dump( substr_count($str, "i", NULL, NULL) );
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
***Testing basic operations ***
|
||||
bool(false)
|
||||
bool(false)
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
int(100)
|
||||
int(200)
|
||||
int(160)
|
||||
int(10)
|
||||
|
||||
*** Testing possible variations ***
|
||||
-- 3rd or 4th arg as string --
|
||||
int(1)
|
||||
@@ -147,25 +96,49 @@ int(16)
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
Done
|
||||
--UEXPECTF--
|
||||
*** Testing possible variations ***
|
||||
-- 3rd or 4th arg as string --
|
||||
int(1)
|
||||
int(1)
|
||||
|
||||
*** Testing error conditions ***
|
||||
Notice: A non well formed numeric value encountered in %s on line %d
|
||||
int(2)
|
||||
|
||||
Warning: substr_count() expects at least 2 parameters, 0 given in %s on line %d
|
||||
Notice: A non well formed numeric value encountered in %s on line %d
|
||||
|
||||
Notice: A non well formed numeric value encountered in %s on line %d
|
||||
int(2)
|
||||
|
||||
-- 3rd or 4th arg as NULL --
|
||||
|
||||
Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: substr_count() expects at most 4 parameters, 5 given in %s on line %d
|
||||
Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: substr_count(): Offset should be greater than or equal to 0 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: substr_count(): Offset value 25 exceeds string length in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: substr_count(): Offset value 5 exceeds string length in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
|
||||
NULL
|
||||
int(0)
|
||||
int(2)
|
||||
|
||||
-- overlapped substrings --
|
||||
int(2)
|
||||
int(2)
|
||||
|
||||
-- complex strings containing other than 7-bit chars --
|
||||
int(2)
|
||||
int(2)
|
||||
int(1)
|
||||
|
||||
-- heredoc string --
|
||||
int(14)
|
||||
int(16)
|
||||
|
||||
-- heredoc null string --
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
Done
|
||||
70
ext/standard/tests/strings/substr_count_variation_002.phpt
Normal file
70
ext/standard/tests/strings/substr_count_variation_002.phpt
Normal file
@@ -0,0 +1,70 @@
|
||||
--TEST--
|
||||
Test substr_count() function (variation - 2)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing possible variations ***\n";
|
||||
echo "\n-- complex strings containing other than 7-bit chars --\n";
|
||||
$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
|
||||
var_dump(substr_count($str, chr(128)));
|
||||
var_dump(substr_count($str, chr(255)));
|
||||
var_dump(substr_count($str, chr(256)));
|
||||
|
||||
echo "\n-- heredoc string --\n";
|
||||
$string = <<<EOD
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
|
||||
EOD;
|
||||
var_dump(substr_count($string, "abcd"));
|
||||
var_dump(substr_count($string, "1234"));
|
||||
|
||||
echo "\n-- heredoc null string --\n";
|
||||
$str = <<<EOD
|
||||
EOD;
|
||||
var_dump(substr_count($str, "\0"));
|
||||
var_dump(substr_count($str, "\x000"));
|
||||
var_dump(substr_count($str, "0"));
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing possible variations ***
|
||||
|
||||
-- complex strings containing other than 7-bit chars --
|
||||
int(2)
|
||||
int(2)
|
||||
int(1)
|
||||
|
||||
-- heredoc string --
|
||||
int(14)
|
||||
int(16)
|
||||
|
||||
-- heredoc null string --
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
Done
|
||||
--UEXPECTF--
|
||||
*** Testing possible variations ***
|
||||
|
||||
-- complex strings containing other than 7-bit chars --
|
||||
int(2)
|
||||
int(2)
|
||||
int(1)
|
||||
|
||||
-- heredoc string --
|
||||
int(14)
|
||||
int(16)
|
||||
|
||||
-- heredoc null string --
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
Done
|
||||
Reference in New Issue
Block a user