mirror of
https://github.com/php/php-src.git
synced 2025-01-22 03:34:19 +08:00
New pcre extension tests. Tested on Windows, Linux and Linux 64-bit
This commit is contained in:
parent
8ef259994f
commit
1f56f22fa3
35
ext/pcre/tests/pcre.constants.phpt
Normal file
35
ext/pcre/tests/pcre.constants.phpt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
--TEST--
|
||||||
|
Test for pre-defined pcre constants
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo "PCRE constants test\n";
|
||||||
|
|
||||||
|
echo "PREG_PATTERN_ORDER= ", PREG_PATTERN_ORDER, "\n";
|
||||||
|
echo "PREG_OFFSET_CAPTURE= ", PREG_OFFSET_CAPTURE, "\n";
|
||||||
|
echo "PREG_SPLIT_NO_EMPTY= ", PREG_SPLIT_NO_EMPTY, "\n";
|
||||||
|
echo "PREG_SPLIT_DELIM_CAPTURE= ", PREG_SPLIT_DELIM_CAPTURE, "\n";
|
||||||
|
echo "PREG_SPLIT_OFFSET_CAPTURE= ", PREG_SPLIT_OFFSET_CAPTURE, "\n";
|
||||||
|
echo "PREG_GREP_INVERT= ", PREG_GREP_INVERT, "\n";
|
||||||
|
echo "PREG_NO_ERROR= ", PREG_NO_ERROR, "\n";
|
||||||
|
echo "PREG_INTERNAL_ERROR= ", PREG_INTERNAL_ERROR, "\n";
|
||||||
|
echo "PREG_BACKTRACK_LIMIT_ERROR= ", PREG_BACKTRACK_LIMIT_ERROR, "\n";
|
||||||
|
echo "PREG_RECURSION_LIMIT_ERROR= ", PREG_RECURSION_LIMIT_ERROR, "\n";
|
||||||
|
echo "PREG_BAD_UTF8_ERROR= ", PREG_BAD_UTF8_ERROR, "\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
===Done===
|
||||||
|
--EXPECT--
|
||||||
|
PCRE constants test
|
||||||
|
PREG_PATTERN_ORDER= 1
|
||||||
|
PREG_OFFSET_CAPTURE= 256
|
||||||
|
PREG_SPLIT_NO_EMPTY= 1
|
||||||
|
PREG_SPLIT_DELIM_CAPTURE= 2
|
||||||
|
PREG_SPLIT_OFFSET_CAPTURE= 4
|
||||||
|
PREG_GREP_INVERT= 1
|
||||||
|
PREG_NO_ERROR= 0
|
||||||
|
PREG_INTERNAL_ERROR= 1
|
||||||
|
PREG_BACKTRACK_LIMIT_ERROR= 2
|
||||||
|
PREG_RECURSION_LIMIT_ERROR= 3
|
||||||
|
PREG_BAD_UTF8_ERROR= 4
|
||||||
|
===Done===
|
30
ext/pcre/tests/preg_last_error_error.phpt
Normal file
30
ext/pcre/tests/preg_last_error_error.phpt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
--TEST--
|
||||||
|
Test preg_grep() function : error conditions - wrong numbers of parameters
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* Prototype : int preg_last_error ( void )
|
||||||
|
* Description: Returns the error code of the last PCRE regex execution
|
||||||
|
* Source code: ext/pcre/php_pcre.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pass an incorrect number of arguments to preg_last_error() to test behaviour
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing preg_last_error() : error conditions ***\n";
|
||||||
|
|
||||||
|
// Test preg_last_error with one more than the expected number of arguments
|
||||||
|
echo "\n-- Testing preg_last_error() function with more than expected no. of arguments --\n";
|
||||||
|
$extra_arg = 10;
|
||||||
|
var_dump( preg_last_error($extra_arg) );
|
||||||
|
?>
|
||||||
|
===Done===
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing preg_last_error() : error conditions ***
|
||||||
|
|
||||||
|
-- Testing preg_last_error() function with more than expected no. of arguments --
|
||||||
|
|
||||||
|
Warning: preg_last_error() expects exactly 0 parameters, 1 given in %s on line %d
|
||||||
|
NULL
|
||||||
|
===Done===
|
23
ext/pcre/tests/preg_match_basic_002.phpt
Normal file
23
ext/pcre/tests/preg_match_basic_002.phpt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
--TEST--
|
||||||
|
preg_match() single line match with multi-line input
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
|
||||||
|
* Description: Perform a regular expression match
|
||||||
|
* Source code: ext/pcre/php_pcre.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
$string = "My\nName\nIs\nStrange";
|
||||||
|
preg_match("/M(.*)/", $string, $matches);
|
||||||
|
|
||||||
|
var_dump($matches);
|
||||||
|
?>
|
||||||
|
===Done===
|
||||||
|
--EXPECTF--
|
||||||
|
array(2) {
|
||||||
|
[0]=>
|
||||||
|
string(2) "My"
|
||||||
|
[1]=>
|
||||||
|
string(1) "y"
|
||||||
|
}
|
||||||
|
===Done===
|
22
ext/pcre/tests/preg_match_variation1.phpt
Normal file
22
ext/pcre/tests/preg_match_variation1.phpt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
--TEST--
|
||||||
|
Test preg_match() function : variation
|
||||||
|
--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
|
||||||
|
*/
|
||||||
|
|
||||||
|
//test passing in the same variable where 1 is by value, the other is a different
|
||||||
|
//type and by reference so should be updated to the new type.
|
||||||
|
$string = "-1";
|
||||||
|
preg_match('/[\-\+]?[0-9\.]*/', $string, $string);
|
||||||
|
var_dump($string);
|
||||||
|
?>
|
||||||
|
===Done===
|
||||||
|
--EXPECT--
|
||||||
|
array(1) {
|
||||||
|
[0]=>
|
||||||
|
string(2) "-1"
|
||||||
|
}
|
||||||
|
===Done===
|
59
ext/pcre/tests/preg_replace_callback_error1.phpt
Normal file
59
ext/pcre/tests/preg_replace_callback_error1.phpt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
--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
|
||||||
|
*/
|
||||||
|
error_reporting(E_ALL&~E_NOTICE);
|
||||||
|
/*
|
||||||
|
* Testing how preg_replace_callback reacts to being passed the wrong type of regex argument
|
||||||
|
*/
|
||||||
|
echo "*** Testing preg_replace_callback() : error conditions ***\n";
|
||||||
|
$regex_array = array('abcdef', //Regex without delimiters
|
||||||
|
'/[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
|
||||||
|
$replacement = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
|
||||||
|
function integer_word($matches) {
|
||||||
|
global $replacement;
|
||||||
|
return $replacement[$matches[0]];
|
||||||
|
}
|
||||||
|
$subject = 'number 1.';
|
||||||
|
foreach($regex_array as $regex_value) {
|
||||||
|
print "\nArg value is $regex_value\n";
|
||||||
|
var_dump(preg_replace_callback($regex_value, 'integer_word', $subject));
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
===Done===
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing preg_replace_callback() : error conditions ***
|
||||||
|
|
||||||
|
Arg value is abcdef
|
||||||
|
|
||||||
|
Warning: preg_replace_callback(): Delimiter must not be alphanumeric or backslash in %s on line %d
|
||||||
|
NULL
|
||||||
|
|
||||||
|
Arg value is /[a-zA-Z]
|
||||||
|
|
||||||
|
Warning: preg_replace_callback(): No ending delimiter '/' found in %s on line %d
|
||||||
|
NULL
|
||||||
|
|
||||||
|
Arg value is [a-zA-Z]/
|
||||||
|
|
||||||
|
Warning: preg_replace_callback(): Unknown modifier '/' in %s on line %d
|
||||||
|
NULL
|
||||||
|
|
||||||
|
Arg value is /[a-zA-Z]/F
|
||||||
|
|
||||||
|
Warning: preg_replace_callback(): Unknown modifier 'F' in %s on line %d
|
||||||
|
NULL
|
||||||
|
|
||||||
|
Arg value is Array
|
||||||
|
string(9) "number 1."
|
||||||
|
|
||||||
|
Arg value is /[a-zA-Z]/
|
||||||
|
string(3) " 1."
|
||||||
|
===Done===
|
Loading…
Reference in New Issue
Block a user