mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Add some more pcre tests
This commit is contained in:
parent
caa15f0291
commit
6cfced8eff
30 changed files with 1459 additions and 0 deletions
62
ext/pcre/tests/preg_grep_basic.phpt
Normal file
62
ext/pcre/tests/preg_grep_basic.phpt
Normal file
|
@ -0,0 +1,62 @@
|
|||
--TEST--
|
||||
Test preg_grep() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_grep(string regex, array input [, int flags])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$array = array('HTTP://WWW.EXAMPLE.COM', '/index.html', '/info/stat/', 'http://test.uk.com/index/html', '/display/dept.php');
|
||||
var_dump($array);
|
||||
var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array)); //finds a string starting with http (regardless of case) (matches two)
|
||||
var_dump(preg_grep('@(/\w+\.*/*)+@', $array)); //finds / followed by one or more of a-z, A-Z and 0-9, followed by zero or more . followed by zero or more / all more than once. (matches all)
|
||||
var_dump(preg_grep('@^http://[^w]{3}.*$@i', $array)); //finds http:// (at the beginning of a string) not followed by 3 characters that aren't w's then anything to the end of the sttring (matches one)
|
||||
var_dump(preg_grep('@.*?\.co\.uk$@i', $array)); //finds any address ending in .co.uk (matches none)
|
||||
var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array, PREG_GREP_INVERT)); //same as first example but the array created contains everything that is NOT matched but the regex (matches three)
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(22) "HTTP://WWW.EXAMPLE.COM"
|
||||
[1]=>
|
||||
string(11) "/index.html"
|
||||
[2]=>
|
||||
string(11) "/info/stat/"
|
||||
[3]=>
|
||||
string(29) "http://test.uk.com/index/html"
|
||||
[4]=>
|
||||
string(17) "/display/dept.php"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(22) "HTTP://WWW.EXAMPLE.COM"
|
||||
[3]=>
|
||||
string(29) "http://test.uk.com/index/html"
|
||||
}
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(22) "HTTP://WWW.EXAMPLE.COM"
|
||||
[1]=>
|
||||
string(11) "/index.html"
|
||||
[2]=>
|
||||
string(11) "/info/stat/"
|
||||
[3]=>
|
||||
string(29) "http://test.uk.com/index/html"
|
||||
[4]=>
|
||||
string(17) "/display/dept.php"
|
||||
}
|
||||
array(1) {
|
||||
[3]=>
|
||||
string(29) "http://test.uk.com/index/html"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(3) {
|
||||
[1]=>
|
||||
string(11) "/index.html"
|
||||
[2]=>
|
||||
string(11) "/info/stat/"
|
||||
[4]=>
|
||||
string(17) "/display/dept.php"
|
||||
}
|
43
ext/pcre/tests/preg_grep_error.phpt
Normal file
43
ext/pcre/tests/preg_grep_error.phpt
Normal file
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Test preg_grep() function : error conditions - wrong numbers of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_grep(string regex, array input [, int flags])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_grep() : error conditions ***\n";
|
||||
// Zero arguments
|
||||
echo "\n-- Testing preg_grep() function with Zero arguments --\n";
|
||||
var_dump(preg_grep());
|
||||
//Test preg_grep with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_grep() function with more than expected no. of arguments --\n";
|
||||
$regex = '/\d/';
|
||||
$input = array(1, 2);
|
||||
$flags = 0;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_grep($regex, $input, $flags, $extra_arg));
|
||||
// Testing preg_grep withone less than the expected number of arguments
|
||||
echo "\n-- Testing preg_grep() function with less than expected no. of arguments --\n";
|
||||
$regex = 'string_val';
|
||||
var_dump(preg_grep($regex));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_grep() : error conditions ***
|
||||
|
||||
-- Testing preg_grep() function with Zero arguments --
|
||||
|
||||
Warning: preg_grep() expects at least 2 parameters, 0 given in %spreg_grep_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_grep() function with more than expected no. of arguments --
|
||||
|
||||
Warning: preg_grep() expects at most 3 parameters, 4 given in %spreg_grep_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_grep() function with less than expected no. of arguments --
|
||||
|
||||
Warning: preg_grep() expects at least 2 parameters, 1 given in %spreg_grep_error.php on line %d
|
||||
NULL
|
||||
Done
|
68
ext/pcre/tests/preg_grep_error1.phpt
Normal file
68
ext/pcre/tests/preg_grep_error1.phpt
Normal file
|
@ -0,0 +1,68 @@
|
|||
--TEST--
|
||||
Test preg_grep() function : error conditions - bad regular expressions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_grep(string regex, array input [, int flags])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_grep reacts to being passed bad regexes
|
||||
*/
|
||||
echo "*** Testing preg_grep() : error conditions ***\n";
|
||||
$values = array('abcdef', //Regex without delimeter
|
||||
'/[a-zA-Z]', //Regex without closing delimeter
|
||||
'[a-zA-Z]/', //Regex without opening delimeter
|
||||
'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
|
||||
'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
|
||||
);
|
||||
$array = array(123, 'abc', 'test');
|
||||
foreach($values as $value) {
|
||||
print "\nArg value is $value\n";
|
||||
var_dump(preg_grep($value, $array));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_grep($value, $array));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
*** Testing preg_grep() : error conditions ***
|
||||
|
||||
Arg value is abcdef
|
||||
|
||||
Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]
|
||||
|
||||
Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is [a-zA-Z]/
|
||||
|
||||
Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]/F
|
||||
|
||||
Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is Array
|
||||
|
||||
Warning: preg_grep() expects parameter 1 to be string, array given in %spreg_grep_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]/
|
||||
array(2) {
|
||||
[1]=>
|
||||
string(3) "abc"
|
||||
[2]=>
|
||||
string(4) "test"
|
||||
}
|
||||
|
||||
Warning: preg_grep() expects parameter 1 to be string, object given in %spreg_grep_error1.php on line %d
|
||||
NULL
|
||||
Done
|
42
ext/pcre/tests/preg_grep_error2.phpt
Normal file
42
ext/pcre/tests/preg_grep_error2.phpt
Normal file
|
@ -0,0 +1,42 @@
|
|||
--TEST--
|
||||
Test preg_grep() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_grep(string regex, array input [, int flags])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_grep reacts to being passed the wrong type of input argument
|
||||
*/
|
||||
echo "*** Testing preg_grep() : error conditions ***\n";
|
||||
$regex = '/[a-zA-Z]/';
|
||||
$input = array('this is a string', array('this is', 'a subarray'),);
|
||||
foreach($input as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_grep($regex, $value));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_grep($regex, $value));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_grep() : error conditions ***
|
||||
|
||||
Arg value is: this is a string
|
||||
|
||||
Warning: preg_grep() expects parameter 2 to be array, string given in %spreg_grep_error2.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is: Array
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(7) "this is"
|
||||
[1]=>
|
||||
string(10) "a subarray"
|
||||
}
|
||||
|
||||
Warning: preg_grep() expects parameter 2 to be array, object given in %spreg_grep_error2.php on line %d
|
||||
NULL
|
||||
Done
|
82
ext/pcre/tests/preg_match_all_basic.phpt
Normal file
82
ext/pcre/tests/preg_match_all_basic.phpt
Normal file
|
@ -0,0 +1,82 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
|
||||
var_dump(preg_match_all('/[0-35-9]/', $string, $match1, PREG_OFFSET_CAPTURE|PREG_PATTERN_ORDER, -10)); //finds any digit that's not 4 10 digits from the end(1 match)
|
||||
var_dump($match1);
|
||||
var_dump(preg_match_all('/[tT]his is a(.*?)\./', $string, $match2, PREG_SET_ORDER)); //finds "This is a test." and "This is another test." (non-greedy) (2 matches)
|
||||
var_dump($match2);
|
||||
var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
|
||||
var_dump($match3);
|
||||
var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches)
|
||||
var_dump($match4);
|
||||
var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
|
||||
var_dump($match5);
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "3"
|
||||
[1]=>
|
||||
int(61)
|
||||
}
|
||||
}
|
||||
}
|
||||
int(2)
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(15) "This is a test."
|
||||
[1]=>
|
||||
string(5) " test"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(21) "This is another test."
|
||||
[1]=>
|
||||
string(11) "nother test"
|
||||
}
|
||||
}
|
||||
int(1)
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(21) ". \[4]. 34534 string."
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(17) "[4]. 34534 string"
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(3) {
|
||||
[0]=>
|
||||
array(0) {
|
||||
}
|
||||
[1]=>
|
||||
array(0) {
|
||||
}
|
||||
[2]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
89
ext/pcre/tests/preg_match_all_edit_basic.phpt
Normal file
89
ext/pcre/tests/preg_match_all_edit_basic.phpt
Normal file
|
@ -0,0 +1,89 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Description: Perform a Perl-style global regular expression match
|
||||
* Source code: ext/pcre/php_pcre.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
|
||||
|
||||
var_dump(preg_match_all('/[0-35-9]/', $string, $match1, PREG_OFFSET_CAPTURE|PREG_PATTERN_ORDER, -10)); //finds any digit that's not 4 10 digits from the end(1 match)
|
||||
var_dump($match1);
|
||||
|
||||
var_dump(preg_match_all('/[tT]his is a(.*?)\./', $string, $match2, PREG_SET_ORDER)); //finds "This is a test." and "This is another test." (non-greedy) (2 matches)
|
||||
var_dump($match2);
|
||||
|
||||
var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
|
||||
var_dump($match3);
|
||||
|
||||
var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches)
|
||||
var_dump($match4);
|
||||
|
||||
var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
|
||||
var_dump($match5);
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "3"
|
||||
[1]=>
|
||||
int(61)
|
||||
}
|
||||
}
|
||||
}
|
||||
int(2)
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(15) "This is a test."
|
||||
[1]=>
|
||||
string(5) " test"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(21) "This is another test."
|
||||
[1]=>
|
||||
string(11) "nother test"
|
||||
}
|
||||
}
|
||||
int(1)
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(21) ". \[4]. 34534 string."
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(17) "[4]. 34534 string"
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(3) {
|
||||
[0]=>
|
||||
array(0) {
|
||||
}
|
||||
[1]=>
|
||||
array(0) {
|
||||
}
|
||||
[2]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
45
ext/pcre/tests/preg_match_all_error.phpt
Normal file
45
ext/pcre/tests/preg_match_all_error.phpt
Normal file
|
@ -0,0 +1,45 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : error conditions - incorrect number of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_match_all() : error conditions ***\n";
|
||||
// Zero arguments
|
||||
echo "\n-- Testing preg_match_all() function with Zero arguments --\n";
|
||||
var_dump(preg_match_all());
|
||||
//Test preg_match_all with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_match_all() function with more than expected no. of arguments --\n";
|
||||
$pattern = '/\w/';
|
||||
$subject = 'string_val';
|
||||
$flags = PREG_OFFSET_CAPTURE;
|
||||
$offset = 10;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_match_all($pattern, $subject, $matches, $flags, $offset, $extra_arg));
|
||||
// Testing preg_match_all withone less than the expected number of arguments
|
||||
echo "\n-- Testing preg_match_all() function with less than expected no. of arguments --\n";
|
||||
$pattern = '/\w/';
|
||||
$subject = 'string_val';
|
||||
var_dump(preg_match_all($pattern, $subject));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_match_all() : error conditions ***
|
||||
|
||||
-- Testing preg_match_all() function with Zero arguments --
|
||||
|
||||
Warning: preg_match_all() expects at least 3 parameters, 0 given in %spreg_match_all_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_match_all() function with more than expected no. of arguments --
|
||||
|
||||
Warning: preg_match_all() expects at most 5 parameters, 6 given in %spreg_match_all_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_match_all() function with less than expected no. of arguments --
|
||||
|
||||
Warning: preg_match_all() expects at least 3 parameters, 2 given in %spreg_match_all_error.php on line %d
|
||||
bool(false)
|
||||
Done
|
81
ext/pcre/tests/preg_match_all_error1.phpt
Normal file
81
ext/pcre/tests/preg_match_all_error1.phpt
Normal file
|
@ -0,0 +1,81 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : error conditions - bad regular expressions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_match_all reacts to being passed the wrong type of regex argument
|
||||
*/
|
||||
echo "*** Testing preg_match_all() : error conditions ***\n";
|
||||
$regex_array = array('abcdef', //Regex without delimeter
|
||||
'/[a-zA-Z]', //Regex without closing delimeter
|
||||
'[a-zA-Z]/', //Regex without opening delimeter
|
||||
'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
|
||||
'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
|
||||
);
|
||||
$subject = 'test';
|
||||
foreach($regex_array as $regex_value) {
|
||||
print "\nArg value is $regex_value\n";
|
||||
var_dump(preg_match_all($regex_value, $subject, $matches1));
|
||||
var_dump($matches1);
|
||||
}
|
||||
$regex_value = new stdclass(); //Object
|
||||
var_dump(preg_match_all($regex_value, $subject, $matches));
|
||||
var_dump($matches);
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_match_all() : error conditions ***
|
||||
|
||||
Arg value is abcdef
|
||||
|
||||
Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]
|
||||
|
||||
Warning: preg_match_all(): No ending delimiter '/' found in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is [a-zA-Z]/
|
||||
|
||||
Warning: preg_match_all(): Unknown modifier '/' in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]/F
|
||||
|
||||
Warning: preg_match_all(): Unknown modifier 'F' in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is Array
|
||||
|
||||
Warning: preg_match_all() expects parameter 1 to be string, array given in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]/
|
||||
int(4)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(1) "t"
|
||||
[1]=>
|
||||
string(1) "e"
|
||||
[2]=>
|
||||
string(1) "s"
|
||||
[3]=>
|
||||
string(1) "t"
|
||||
}
|
||||
}
|
||||
|
||||
Warning: preg_match_all() expects parameter 1 to be string, object given in %spreg_match_all_error1.php on line %d
|
||||
bool(false)
|
||||
NULL
|
54
ext/pcre/tests/preg_match_all_error2.phpt
Normal file
54
ext/pcre/tests/preg_match_all_error2.phpt
Normal file
|
@ -0,0 +1,54 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_match_all reacts to being passed the wrong type of input argument
|
||||
*/
|
||||
echo "*** Testing preg_match_all() : error conditions ***\n";
|
||||
$regex = '/[a-zA-Z]/';
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_match_all($regex, $value, $matches));
|
||||
var_dump($matches);
|
||||
$input = array(array('this is', 'a subarray'), 'test',);
|
||||
foreach($input as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_match_all($regex, $value, $matches));
|
||||
var_dump($matches);
|
||||
}
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_match_all() : error conditions ***
|
||||
|
||||
Warning: preg_match_all() expects parameter 2 to be string, object given in %spreg_match_all_error2.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is: Array
|
||||
|
||||
Warning: preg_match_all() expects parameter 2 to be string, array given in %spreg_match_all_error2.php on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
Arg value is: test
|
||||
int(4)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(1) "t"
|
||||
[1]=>
|
||||
string(1) "e"
|
||||
[2]=>
|
||||
string(1) "s"
|
||||
[3]=>
|
||||
string(1) "t"
|
||||
}
|
||||
}
|
||||
Done
|
20
ext/pcre/tests/preg_match_all_error3.phpt
Normal file
20
ext/pcre/tests/preg_match_all_error3.phpt
Normal file
|
@ -0,0 +1,20 @@
|
|||
--TEST--
|
||||
Test preg_match_all() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
/*
|
||||
* Testing how preg_match_all reacts to being passed the wrong type of subpatterns array argument
|
||||
*/
|
||||
echo "*** Testing preg_match_all() : error conditions ***\n";
|
||||
$regex = '/[a-z]/';
|
||||
$subject = 'string';
|
||||
var_dump(preg_match_all($regex, $subject, test));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Fatal error: Only variables can be passed by reference in %spreg_match_all_error3.php on line %d
|
52
ext/pcre/tests/preg_match_basic.phpt
Normal file
52
ext/pcre/tests/preg_match_basic.phpt
Normal file
|
@ -0,0 +1,52 @@
|
|||
--TEST--
|
||||
Test preg_match() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$string = 'Hello, world. [*], this is \ a string';
|
||||
var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, "
|
||||
var_dump($match1);
|
||||
var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string
|
||||
var_dump($match2);
|
||||
var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string";
|
||||
var_dump($match3);
|
||||
var_dump(preg_match('@\w{4}\s\w{2}\s\\\(?:\s.*)@', $string, $match4, PREG_OFFSET_CAPTURE, 14)); //finds "this is \ a string" (with non-capturing parentheses)
|
||||
var_dump($match4);
|
||||
var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world)
|
||||
var_dump($match5);
|
||||
?>
|
||||
|
||||
--EXPECTF--
|
||||
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "Hello, "
|
||||
}
|
||||
int(0)
|
||||
array(0) {
|
||||
}
|
||||
int(1)
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(23) "[*], this is \ a string"
|
||||
[1]=>
|
||||
string(18) "this is \ a string"
|
||||
}
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(18) "this is \ a string"
|
||||
[1]=>
|
||||
int(19)
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(0) {
|
||||
}
|
||||
|
60
ext/pcre/tests/preg_match_basic_edit.phpt
Normal file
60
ext/pcre/tests/preg_match_basic_edit.phpt
Normal file
|
@ -0,0 +1,60 @@
|
|||
--TEST--
|
||||
Test preg_match() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
|
||||
* Description: Perform a Perl-style regular expression match
|
||||
* Source code: ext/pcre/php_pcre.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
|
||||
$string = 'Hello, world. [*], this is \ a string';
|
||||
|
||||
var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, "
|
||||
var_dump($match1);
|
||||
|
||||
var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string
|
||||
var_dump($match2);
|
||||
|
||||
var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string";
|
||||
var_dump($match3);
|
||||
|
||||
var_dump(preg_match('@\w{4}\s\w{2}\s\\\(?:\s.*)@', $string, $match4, PREG_OFFSET_CAPTURE, 14)); //finds "this is \ a string" (with non-capturing parentheses)
|
||||
var_dump($match4);
|
||||
|
||||
var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world)
|
||||
var_dump($match5);
|
||||
?>
|
||||
|
||||
--EXPECTF--
|
||||
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "Hello, "
|
||||
}
|
||||
int(0)
|
||||
array(0) {
|
||||
}
|
||||
int(1)
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(23) "[*], this is \ a string"
|
||||
[1]=>
|
||||
string(18) "this is \ a string"
|
||||
}
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(18) "this is \ a string"
|
||||
[1]=>
|
||||
int(19)
|
||||
}
|
||||
}
|
||||
int(0)
|
||||
array(0) {
|
||||
}
|
||||
|
44
ext/pcre/tests/preg_match_error.phpt
Normal file
44
ext/pcre/tests/preg_match_error.phpt
Normal file
|
@ -0,0 +1,44 @@
|
|||
--TEST--
|
||||
Test preg_match() function : error conditions - wrong numbers of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_match() : error conditions ***\n";
|
||||
// Zero arguments
|
||||
echo "\n-- Testing preg_match() function with Zero arguments --\n";
|
||||
var_dump(preg_match());
|
||||
//Test preg_match with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_match() function with more than expected no. of arguments --\n";
|
||||
$pattern = '/\w/';
|
||||
$subject = 'string_val';
|
||||
$flags = PREG_OFFSET_CAPTURE;
|
||||
$offset = 10;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_match($pattern, $subject, $matches, $flags, $offset, $extra_arg));
|
||||
// Testing preg_match withone less than the expected number of arguments
|
||||
echo "\n-- Testing preg_match() function with less than expected no. of arguments --\n";
|
||||
$pattern = '/\w/';
|
||||
var_dump(preg_match($pattern));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_match() : error conditions ***
|
||||
|
||||
-- Testing preg_match() function with Zero arguments --
|
||||
|
||||
Warning: preg_match() expects at least 2 parameters, 0 given in %spreg_match_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_match() function with more than expected no. of arguments --
|
||||
|
||||
Warning: preg_match() expects at most 5 parameters, 6 given in %spreg_match_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_match() function with less than expected no. of arguments --
|
||||
|
||||
Warning: preg_match() expects at least 2 parameters, 1 given in %spreg_match_error.php on line %d
|
||||
bool(false)
|
||||
Done
|
61
ext/pcre/tests/preg_match_error1.phpt
Normal file
61
ext/pcre/tests/preg_match_error1.phpt
Normal file
|
@ -0,0 +1,61 @@
|
|||
--TEST--
|
||||
Test preg_match() function : error conditions - bad regular expressions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_match reacts to being passed the wrong type of regex argument
|
||||
*/
|
||||
echo "*** Testing preg_match() : error conditions ***\n";
|
||||
$regex_array = array('abcdef', //Regex without delimeter
|
||||
'/[a-zA-Z]', //Regex without closing delimeter
|
||||
'[a-zA-Z]/', //Regex without opening delimeter
|
||||
'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
|
||||
'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
|
||||
);
|
||||
$subject = 'this is a test';
|
||||
foreach($regex_array as $regex_value) {
|
||||
print "\nArg value is $regex_value\n";
|
||||
var_dump(preg_match($regex_value, $subject));
|
||||
}
|
||||
$regex_value = new stdclass(); //Object
|
||||
var_dump(preg_match($regex_value, $subject));
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
*** Testing preg_match() : error conditions ***
|
||||
|
||||
Arg value is abcdef
|
||||
|
||||
Warning: preg_match(): Delimiter must not be alphanumeric or backslash in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]
|
||||
|
||||
Warning: preg_match(): No ending delimiter '/' found in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is [a-zA-Z]/
|
||||
|
||||
Warning: preg_match(): Unknown modifier '/' in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]/F
|
||||
|
||||
Warning: preg_match(): Unknown modifier 'F' in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is Array
|
||||
|
||||
Warning: preg_match() expects parameter 1 to be string, array given in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]/
|
||||
int(1)
|
||||
|
||||
Warning: preg_match() expects parameter 1 to be string, object given in %spreg_match_error1.php on line %d
|
||||
bool(false)
|
38
ext/pcre/tests/preg_match_error2.phpt
Normal file
38
ext/pcre/tests/preg_match_error2.phpt
Normal file
|
@ -0,0 +1,38 @@
|
|||
--TEST--
|
||||
Test preg_match() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_match reacts to being passed the wrong type of subject argument
|
||||
*/
|
||||
echo "*** Testing preg_match() : error conditions ***\n";
|
||||
$regex = '/[a-zA-Z]/';
|
||||
$input = array('this is a string', array('this is', 'a subarray'),);
|
||||
foreach($input as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_match($regex, $value));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_match($regex, $value));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
*** Testing preg_match() : error conditions ***
|
||||
|
||||
Arg value is: this is a string
|
||||
int(1)
|
||||
|
||||
Arg value is: Array
|
||||
|
||||
Warning: preg_match() expects parameter 2 to be string, array given in %spreg_match_error2.php on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: preg_match() expects parameter 2 to be string, object given in %spreg_match_error2.php on line %d
|
||||
bool(false)
|
||||
Done
|
25
ext/pcre/tests/preg_quote_basic.phpt
Normal file
25
ext/pcre/tests/preg_quote_basic.phpt
Normal file
|
@ -0,0 +1,25 @@
|
|||
--TEST--
|
||||
Test preg_quote() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_quote(string str [, string delim_char])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$string_before = '/this *-has \ metacharacters^ in $';
|
||||
print "\$string_before looks like: $string_before\n"; //$string_before is printed as is written
|
||||
$string_after = preg_quote($string_before, '/');
|
||||
print "\$string_after looks like: $string_after, with metacharacters and / (set as delimiter) escaped\n"; //$string_after is printed with metacharacters escaped.
|
||||
$string1 = 'testing - /this *-has \ metacharacters^ in $ should work';
|
||||
var_dump(preg_match('/^[tT]\w{6} - ' . preg_quote($string_before, '/') . ' [a-z]*\s*work$/', $string1, $matches1));
|
||||
var_dump($matches1);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
$string_before looks like: /this *-has \ metacharacters^ in $
|
||||
$string_after looks like: \/this \*-has \\ metacharacters\^ in \$, with metacharacters and / (set as delimiter) escaped
|
||||
int(1)
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(58) "testing - /this *-has \ metacharacters^ in $ should work"
|
||||
}
|
33
ext/pcre/tests/preg_quote_error.phpt
Normal file
33
ext/pcre/tests/preg_quote_error.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
Test preg_quote() function : error conditions - wrong numbers of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_quote(string str [, string delim_char])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_quote() : error conditions ***\n";
|
||||
// Zero arguments
|
||||
echo "\n-- Testing preg_quote() function with Zero arguments --\n";
|
||||
var_dump(preg_quote());
|
||||
//Test preg_quote with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_quote() function with more than expected no. of arguments --\n";
|
||||
$str = 'string_val';
|
||||
$delim_char = '/';
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_quote($str, $delim_char, $extra_arg));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_quote() : error conditions ***
|
||||
|
||||
-- Testing preg_quote() function with Zero arguments --
|
||||
|
||||
Warning: preg_quote() expects at least 1 parameter, 0 given in %spreg_quote_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_quote() function with more than expected no. of arguments --
|
||||
|
||||
Warning: preg_quote() expects at most 2 parameters, 3 given in %spreg_quote_error.php on line %d
|
||||
NULL
|
||||
Done
|
36
ext/pcre/tests/preg_quote_error1.phpt
Normal file
36
ext/pcre/tests/preg_quote_error1.phpt
Normal file
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
Test preg_quote() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_quote(string str [, string delim_char])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_quote reacts to being passed the wrong type of input argument
|
||||
*/
|
||||
echo "*** Testing preg_quote() : error conditions ***\n";
|
||||
$input = array('this is a string', array('this is', 'a subarray'),);
|
||||
foreach($input as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_quote($value));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_quote($value));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_quote() : error conditions ***
|
||||
|
||||
Arg value is: this is a string
|
||||
string(16) "this is a string"
|
||||
|
||||
Arg value is: Array
|
||||
|
||||
Warning: preg_quote() expects parameter 1 to be string, array given in %spreg_quote_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Warning: preg_quote() expects parameter 1 to be string, object given in %spreg_quote_error1.php on line %d
|
||||
NULL
|
||||
Done
|
25
ext/pcre/tests/preg_replace_basic.phpt
Normal file
25
ext/pcre/tests/preg_replace_basic.phpt
Normal file
|
@ -0,0 +1,25 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$string = '123456789 - Hello, world - This is a string.';
|
||||
var_dump($string);
|
||||
var_dump(preg_replace('<- This is a string$>', 'This shouldn\'t work', $string)); //tries to find '- This is a string' at the end of a string but can't so replaces nothing and prints the unchanged $string.
|
||||
var_dump(preg_replace('<[0-35-9]>', '4', $string)); //finds any number that's not 4 and replaces it with a 4 ('444444444')
|
||||
var_dump(preg_replace('<\b[hH]\w{2,4}>', 'Bonjour', $string)); //finds h or H at the beginning of a word followed by 2-4 characters and replaces it with Bonjour (i.e. Hello -> Bonjour) (was finding the 'his' in This and replacing it)
|
||||
var_dump(preg_replace('<(\w)\s*-\s*(\w)>', '\\1. \\2', $string)); //finds dashes with an indefinate amount of whitespace around them and replaces them with a full stop precedeby no spaces and followed by one space
|
||||
var_dump(preg_replace('<(^[a-z]\w+)@(\w+)\.(\w+)\.([a-z]{2,}$)>', '\\1 at \\2 dot \\3 dot \\4', 'josmessa@uk.ibm.com')); //finds the e-mail address and replaces the @ and . with "at" and "dot" (uses backreferences) ('josmessa at uk dot ibm dot com')
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
string(54) "123456789 - Hello, world - This is a string."
|
||||
string(54) "123456789 - Hello, world - This is a string."
|
||||
string(54) "444444444 - Hello, world - This is a string."
|
||||
string(56) "123456789 - Bonjour, world - This is a string."
|
||||
string(42) "123456789. Hello, world. This is a string."
|
||||
string(30) "josmessa at uk dot ibm dot com"
|
33
ext/pcre/tests/preg_replace_callback_basic.phpt
Normal file
33
ext/pcre/tests/preg_replace_callback_basic.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
Test preg_replace_callback() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
/*
|
||||
* Basic test for preg_replace_callback
|
||||
*/
|
||||
$replacement = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); //array will have the default key values (0-9) and each value is the corresponding key written in words.
|
||||
function integer_word($matches) {
|
||||
global $replacement;
|
||||
return $replacement[$matches[0]]; //all examples will be looking for an integer value, if one is found it will be stored in $matches[0] which corresponds to a key in the $replacements array
|
||||
|
||||
}
|
||||
$subject1 = 'there are 7 words in this sentence.';
|
||||
$new_subject1 = preg_replace_callback('/\d/', "integer_word", $subject1);
|
||||
print "$new_subject1 \n";
|
||||
$subject2 = '1 2 3 4 is now written in words';
|
||||
$new_subject2 = preg_replace_callback('/\d/', "integer_word", $subject2, 3); //limits to three replacements
|
||||
print "$new_subject2 \n";
|
||||
$subject3 = 'there are no numbers in this string';
|
||||
$new_subject3 = preg_replace_callback('/\d/', "integer_word", $subject3, 5, $count); //limites to five replacements and counts the number of replacements made ands stores in $count variable
|
||||
print "$new_subject3 \n";
|
||||
print $count;
|
||||
?>
|
||||
--EXPECTF--
|
||||
there are seven words in this sentence.
|
||||
one two three 4 is now written in words
|
||||
there are no numbers in this string
|
||||
0
|
48
ext/pcre/tests/preg_replace_callback_error.phpt
Normal file
48
ext/pcre/tests/preg_replace_callback_error.phpt
Normal file
|
@ -0,0 +1,48 @@
|
|||
--TEST--
|
||||
Test preg_replace_callback() function : error
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "***Testing preg_replace_callback() : error conditions***\n";
|
||||
//Zero arguments
|
||||
echo "\n-- Testing preg_replace_callback() function with Zero arguments --\n";
|
||||
var_dump(preg_replace_callback());
|
||||
//Test preg_replace_callback() with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_replace_callback() function with more than expected no. of arguments --\n";
|
||||
$replacement = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
|
||||
function integer_word($matches) {
|
||||
global $replacement;
|
||||
return $replacement[$matches[0]];
|
||||
}
|
||||
$regex = '/\d/';
|
||||
$subject = 'there are 7 words in this sentence.';
|
||||
$limit = 10;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_replace_callback($regex, 'integer_word', $subject, $limit, $count, $extra_arg));
|
||||
//Testing preg_replace_callback() with one less than the expected number of arguments
|
||||
echo "\n-- Testing preg_replace_callback() function with less than expected no. of arguments --\n";
|
||||
$regex = '/\d/';
|
||||
var_dump(preg_replace_callback($regex, 'integer word'));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
***Testing preg_replace_callback() : error conditions***
|
||||
|
||||
-- Testing preg_replace_callback() function with Zero arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace_callback() in %spreg_replace_callback_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_replace_callback() function with more than expected no. of arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace_callback() in %spreg_replace_callback_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_replace_callback() function with less than expected no. of arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace_callback() in %spreg_replace_callback_error.php on line %d
|
||||
NULL
|
||||
Done
|
39
ext/pcre/tests/preg_replace_edit_basic.phpt
Normal file
39
ext/pcre/tests/preg_replace_edit_basic.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : basic
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Description: Perform Perl-style regular expression replacement.
|
||||
* Source code: ext/pcre/php_pcre.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$string = '123456789 - Hello, world - This is a string.';
|
||||
var_dump($string);
|
||||
|
||||
var_dump(preg_replace('<- This is a string$>',
|
||||
'This shouldn\'t work', $string)); //tries to find '- This is a string' at the end of a string but can't so replaces nothing and prints the unchanged $string.
|
||||
|
||||
var_dump(preg_replace('<[0-35-9]>',
|
||||
'4', $string, //finds any number that's not 4 and replaces it with a 4
|
||||
'5', $count)); //limits to 5 replacements returns 444444789
|
||||
var_dump($count); //counts the number of replacements made (5)
|
||||
|
||||
|
||||
var_dump(preg_replace('<\b[hH]\w{2,4}>',
|
||||
'Bonjour', $string)); //finds h or H at the beginning of a word followed by 2-4 characters and replaces it with Bonjour (i.e. Hello -> Bonjour) (was finding the 'his' in This and replacing it)
|
||||
|
||||
var_dump(preg_replace('<(\w)\s*-\s*(\w)>',
|
||||
'\\1. \\2', $string)); //finds dashes with an indefinate amount of whitespace around them and replaces them with a full stop precedeby no spaces and followed by one space
|
||||
|
||||
var_dump(preg_replace('<(^[a-z]\w+)@(\w+)\.(\w+)\.([a-z]{2,}$)>',
|
||||
'\\1 at \\2 dot \\3 dot \\4', 'josmessa@uk.ibm.com')); //finds the e-mail address and replaces the @ and . with "at" and "dot" (uses backreferences) ('josmessa at uk dot ibm dot com')
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(54) "123456789 - Hello, world - This is a string."
|
||||
string(54) "123456789 - Hello, world - This is a string."
|
||||
string(54) "444444789 - Hello, world - This is a string."
|
||||
int(5)
|
||||
string(56) "123456789 - Bonjour, world - This is a string."
|
||||
string(42) "123456789. Hello, world. This is a string."
|
||||
string(30) "josmessa at uk dot ibm dot com"
|
45
ext/pcre/tests/preg_replace_error.phpt
Normal file
45
ext/pcre/tests/preg_replace_error.phpt
Normal file
|
@ -0,0 +1,45 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : error - incorrect number of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_replace() : error conditions ***\n";
|
||||
//Zero arguments
|
||||
echo "\n-- Testing preg_replace() function with zero arguments --\n";
|
||||
var_dump(preg_replace());
|
||||
//Test preg_replace() with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_replace() function with more than expected no. of arguments --\n";
|
||||
$regex = '/\w/';
|
||||
$replace = '1';
|
||||
$subject = 'string_val';
|
||||
$limit = 10;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_replace($regex, $replace, $subject, $limit, $count, $extra_arg));
|
||||
//Testing preg_replace() with one less than the expected number of arguments
|
||||
echo "\n-- Testing preg_replace() function with less than expected no. of arguments --\n";
|
||||
$regex = '/\w/';
|
||||
$replace = '1';
|
||||
var_dump(preg_replace($regex, $replace));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_replace() : error conditions ***
|
||||
|
||||
-- Testing preg_replace() function with zero arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace() in %spreg_replace_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_replace() function with more than expected no. of arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace() in %spreg_replace_error.php on line %d
|
||||
NULL
|
||||
|
||||
-- Testing preg_replace() function with less than expected no. of arguments --
|
||||
|
||||
Warning: Wrong parameter count for preg_replace() in %spreg_replace_error.php on line %d
|
||||
NULL
|
||||
Done
|
59
ext/pcre/tests/preg_replace_error1.phpt
Normal file
59
ext/pcre/tests/preg_replace_error1.phpt
Normal file
|
@ -0,0 +1,59 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : error - bad regular expressions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_replace reacts to being passed the wrong type of regex argument
|
||||
*/
|
||||
echo "*** Testing preg_replace() : error conditions***\n";
|
||||
$regex_array = array('abcdef', //Regex without delimeter
|
||||
'/[a-zA-Z]', //Regex without closing delimeter
|
||||
'[a-zA-Z]/', //Regex without opening delimeter
|
||||
'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
|
||||
'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
|
||||
);
|
||||
$replace = 1;
|
||||
$subject = 'a';
|
||||
foreach($regex_array as $regex_value) {
|
||||
print "\nArg value is $regex_value\n";
|
||||
var_dump(preg_replace($regex_value, $replace, $subject));
|
||||
}
|
||||
$regex_value = new stdclass(); //Object
|
||||
var_dump(preg_replace($regex_value, $replace, $subject));
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_replace() : error conditions***
|
||||
|
||||
Arg value is abcdef
|
||||
|
||||
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]
|
||||
|
||||
Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is [a-zA-Z]/
|
||||
|
||||
Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is /[a-zA-Z]/F
|
||||
|
||||
Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d
|
||||
NULL
|
||||
|
||||
Arg value is Array
|
||||
string(1) "a"
|
||||
|
||||
Arg value is /[a-zA-Z]/
|
||||
string(1) "1"
|
||||
|
||||
Catchable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error1.php on line %d
|
||||
|
37
ext/pcre/tests/preg_replace_error2.phpt
Normal file
37
ext/pcre/tests/preg_replace_error2.phpt
Normal file
|
@ -0,0 +1,37 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_replace reacts to being passed the wrong type of replacement argument
|
||||
*/
|
||||
echo "*** Testing preg_replace() : error conditions ***\n";
|
||||
$regex = '/[a-zA-Z]/';
|
||||
$replace = array('this is a string', array('this is', 'a subarray'),);
|
||||
$subject = 'test';
|
||||
foreach($replace as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_replace($regex, $value, $subject));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_replace($regex, $value, $subject));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_replace() : error conditions ***
|
||||
|
||||
Arg value is: this is a string
|
||||
string(64) "this is a stringthis is a stringthis is a stringthis is a string"
|
||||
|
||||
Arg value is: Array
|
||||
|
||||
Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace_error2.php on line %d
|
||||
bool(false)
|
||||
|
||||
Catchable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error2.php on line %d
|
||||
|
17
ext/pcre/tests/preg_replace_variation1.phpt
Normal file
17
ext/pcre/tests/preg_replace_variation1.phpt
Normal file
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
Test preg_replace() function : variation both arguments are arrays
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
/*
|
||||
* Testing preg_replace when the regex and the replacement are both arrays.
|
||||
*/
|
||||
$string = 'This is a string. It contains numbers (0-9) as well as parentheses and some other things!';
|
||||
$new_string = preg_replace(array('/\b\w{1}s/', '/(\d{1})-(\d{1})/', '/[\(!\)]/'), array('test', '$1 to $2', '*'), $string);
|
||||
print $new_string;
|
||||
?>
|
||||
--EXPECTF--
|
||||
This test a string. It contains numbers *0 to 9* test well test parentheses and some other things*
|
76
ext/pcre/tests/preg_split_basic.phpt
Normal file
76
ext/pcre/tests/preg_split_basic.phpt
Normal file
|
@ -0,0 +1,76 @@
|
|||
--TEST--
|
||||
Test preg_split() function : basic functionality
|
||||
--INI--
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_split(string pattern, string subject [, int limit [, int flags]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
$string = 'this is a_list: value1, Test__, string; Hello, world!_(parentheses)';
|
||||
var_dump(preg_split('/[:,;\(\)]/', $string, -1, PREG_SPLIT_NO_EMPTY)); //parts of $string seperated by : , ; ( or ) are put into an array.
|
||||
var_dump(preg_split('/:\s*(\w*,*\s*)+;/', $string)); //all text between : and ; is removed
|
||||
var_dump(preg_split('/(\(|\))/', $string, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY)); //all text before (parentheses) is put into first element, ( into second, "parentheses" into third and ) into fourth.
|
||||
var_dump(preg_split('/NAME/i', $string)); //tries to find NAME regardless of case in $string (can't split it so just returns how string as first element)
|
||||
var_dump(preg_split('/\w/', $string, -1, PREG_SPLIT_NO_EMPTY)); //every character (including whitespace) is put into an array element
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(7) {
|
||||
[0]=>
|
||||
string(14) "this is a_list"
|
||||
[1]=>
|
||||
string(7) " value1"
|
||||
[2]=>
|
||||
string(7) " Test__"
|
||||
[3]=>
|
||||
string(7) " string"
|
||||
[4]=>
|
||||
string(6) " Hello"
|
||||
[5]=>
|
||||
string(8) " world!_"
|
||||
[6]=>
|
||||
string(11) "parentheses"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(14) "this is a_list"
|
||||
[1]=>
|
||||
string(28) " Hello, world!_(parentheses)"
|
||||
}
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(54) "this is a_list: value1, Test__, string; Hello, world!_"
|
||||
[1]=>
|
||||
string(1) "("
|
||||
[2]=>
|
||||
string(11) "parentheses"
|
||||
[3]=>
|
||||
string(1) ")"
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(67) "this is a_list: value1, Test__, string; Hello, world!_(parentheses)"
|
||||
}
|
||||
array(10) {
|
||||
[0]=>
|
||||
string(1) " "
|
||||
[1]=>
|
||||
string(1) " "
|
||||
[2]=>
|
||||
string(2) ": "
|
||||
[3]=>
|
||||
string(2) ", "
|
||||
[4]=>
|
||||
string(2) ", "
|
||||
[5]=>
|
||||
string(2) "; "
|
||||
[6]=>
|
||||
string(2) ", "
|
||||
[7]=>
|
||||
string(1) "!"
|
||||
[8]=>
|
||||
string(1) "("
|
||||
[9]=>
|
||||
string(1) ")"
|
||||
}
|
44
ext/pcre/tests/preg_split_error.phpt
Normal file
44
ext/pcre/tests/preg_split_error.phpt
Normal file
|
@ -0,0 +1,44 @@
|
|||
--TEST--
|
||||
Test preg_split() function : error conditions - incorrect number of parameters
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_split(string pattern, string subject [, int limit [, int flags]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
echo "*** Testing preg_split() : error conditions ***\n";
|
||||
// Zero arguments
|
||||
echo "\n-- Testing preg_split() function with Zero arguments --\n";
|
||||
var_dump(preg_split());
|
||||
//Test preg_split with one more than the expected number of arguments
|
||||
echo "\n-- Testing preg_split() function with more than expected no. of arguments --\n";
|
||||
$pattern = '/_/';
|
||||
$subject = 'string_val';
|
||||
$limit = 10;
|
||||
$flags = PREG_SPLIT_NO_EMPTY;
|
||||
$extra_arg = 10;
|
||||
var_dump(preg_split($pattern, $subject, $limit, $flags, $extra_arg));
|
||||
// Testing preg_split withone less than the expected number of arguments
|
||||
echo "\n-- Testing preg_split() function with less than expected no. of arguments --\n";
|
||||
$pattern = '/\./';
|
||||
var_dump(preg_split($pattern));
|
||||
echo "Done"
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_split() : error conditions ***
|
||||
|
||||
-- Testing preg_split() function with Zero arguments --
|
||||
|
||||
Warning: preg_split() expects at least 2 parameters, 0 given in %spreg_split_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_split() function with more than expected no. of arguments --
|
||||
|
||||
Warning: preg_split() expects at most 4 parameters, 5 given in %spreg_split_error.php on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing preg_split() function with less than expected no. of arguments --
|
||||
|
||||
Warning: preg_split() expects at least 2 parameters, 1 given in %spreg_split_error.php on line %d
|
||||
bool(false)
|
||||
Done
|
67
ext/pcre/tests/preg_split_error1.phpt
Normal file
67
ext/pcre/tests/preg_split_error1.phpt
Normal file
|
@ -0,0 +1,67 @@
|
|||
--TEST--
|
||||
Test preg_split() function : error conditions - bad regular expressions
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_split(string pattern, string subject [, int limit [, int flags]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_split reacts to being passed the wrong type of regex argument
|
||||
*/
|
||||
echo "*** Testing preg_split() : error conditions ***\n";
|
||||
$regex_array = array('abcdef', //Regex without delimiter
|
||||
'/[a-zA-Z]', //Regex without closing delimiter
|
||||
'[a-zA-Z]/', //Regex without opening delimiter
|
||||
'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
|
||||
'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
|
||||
);
|
||||
$subject = '1 2 a 3 4 b 5 6';
|
||||
foreach($regex_array as $regex_value) {
|
||||
print "\nArg value is $regex_value\n";
|
||||
var_dump(preg_split($regex_value, $subject));
|
||||
}
|
||||
$regex_value = new stdclass(); //Object
|
||||
var_dump(preg_split($regex_value, $subject));
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_split() : error conditions ***
|
||||
|
||||
Arg value is abcdef
|
||||
|
||||
Warning: preg_split(): Delimiter must not be alphanumeric or backslash in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]
|
||||
|
||||
Warning: preg_split(): No ending delimiter '/' found in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is [a-zA-Z]/
|
||||
|
||||
Warning: preg_split(): Unknown modifier '/' in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]/F
|
||||
|
||||
Warning: preg_split(): Unknown modifier 'F' in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is Array
|
||||
|
||||
Warning: preg_split() expects parameter 1 to be string, array given in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
||||
|
||||
Arg value is /[a-zA-Z]/
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(4) "1 2 "
|
||||
[1]=>
|
||||
string(5) " 3 4 "
|
||||
[2]=>
|
||||
string(4) " 5 6"
|
||||
}
|
||||
|
||||
Warning: preg_split() expects parameter 1 to be string, object given in %spreg_split_error1.php on line %d
|
||||
bool(false)
|
34
ext/pcre/tests/preg_split_error2.phpt
Normal file
34
ext/pcre/tests/preg_split_error2.phpt
Normal file
|
@ -0,0 +1,34 @@
|
|||
--TEST--
|
||||
Test preg_split() function : error conditions - wrong arg types
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
* proto array preg_split(string pattern, string subject [, int limit [, int flags]])
|
||||
* Function is implemented in ext/pcre/php_pcre.c
|
||||
*/
|
||||
error_reporting(E_ALL&~E_NOTICE);
|
||||
/*
|
||||
* Testing how preg_split reacts to being passed the wrong type of input argument
|
||||
*/
|
||||
echo "*** Testing preg_split() : error conditions ***\n";
|
||||
$regex = '/[a-zA-Z]/';
|
||||
$input = array(array('this is', 'a subarray'),);
|
||||
foreach($input as $value) {
|
||||
print "\nArg value is: $value\n";
|
||||
var_dump(preg_split($regex, $value));
|
||||
}
|
||||
$value = new stdclass(); //Object
|
||||
var_dump(preg_split($regex, $value));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing preg_split() : error conditions ***
|
||||
|
||||
Arg value is: Array
|
||||
|
||||
Warning: preg_split() expects parameter 2 to be string, array given in %spreg_split_error2.php on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: preg_split() expects parameter 2 to be string, object given in %spreg_split_error2.php on line %d
|
||||
bool(false)
|
||||
Done
|
Loading…
Add table
Add a link
Reference in a new issue