diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
| commit | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (patch) | |
| tree | b38e2e5c6974b9a15f103e5cf884cba9fff90ef4 /ext/pcre/tests | |
| parent | a88a88d0986a4a32288c102cdbfebd78d7e91d99 (diff) | |
| download | php-d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76.tar.gz | |
Imported Upstream version 5.2.0upstream/5.2.0
Diffstat (limited to 'ext/pcre/tests')
26 files changed, 1270 insertions, 0 deletions
diff --git a/ext/pcre/tests/backtrack_limit.phpt b/ext/pcre/tests/backtrack_limit.phpt new file mode 100644 index 000000000..ebfd720c3 --- /dev/null +++ b/ext/pcre/tests/backtrack_limit.phpt @@ -0,0 +1,19 @@ +--TEST-- +Backtracking limit +--INI-- +pcre.backtrack_limit=2 +--FILE-- +<?php + +var_dump(preg_match_all('/.*\p{N}/', '0123456789', $dummy)); +var_dump(preg_last_error() === PREG_BACKTRACK_LIMIT_ERROR); + +var_dump(preg_match_all('/\p{Nd}/', '0123456789', $dummy)); +var_dump(preg_last_error() === PREG_NO_ERROR); + +?> +--EXPECT-- +int(0) +bool(true) +int(10) +bool(true) diff --git a/ext/pcre/tests/bug37800.phpt b/ext/pcre/tests/bug37800.phpt new file mode 100644 index 000000000..e8a0036eb --- /dev/null +++ b/ext/pcre/tests/bug37800.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #37800 (preg_replace() limit parameter odd behaviour) +--FILE-- +<?php +$s_string = '1111111111'; +$s_search = '/1/'; +$s_replace = 'One '; +$i_limit = 1; +$i_count = 0; + +$s_output = preg_replace($s_search, $s_replace, $s_string, $i_limit, +$i_count); +echo "Output = " . var_export($s_output, True) . "\n"; +echo "Count = $i_count\n"; +var_dump(preg_last_error() === PREG_NO_ERROR); + +$i_limit = strlen($s_string); +$s_output = preg_replace($s_search, $s_replace, $s_string, $i_limit, +$i_count); +echo "Output = " . var_export($s_output, True) . "\n"; +echo "Count = $i_count\n"; +var_dump(preg_last_error() === PREG_NO_ERROR); + +?> +--EXPECT-- +Output = 'One 111111111' +Count = 1 +bool(true) +Output = 'One One One One One One One One One One ' +Count = 10 +bool(true) diff --git a/ext/pcre/tests/cache_limit.phpt b/ext/pcre/tests/cache_limit.phpt new file mode 100644 index 000000000..bfe7f1b9a --- /dev/null +++ b/ext/pcre/tests/cache_limit.phpt @@ -0,0 +1,25 @@ +--TEST-- +Compiled regex cache limit +--FILE-- +<?php +define('PREG_CACHE_SIZE', 4096+1); + +$re = ''; +$str = str_repeat('x', PREG_CACHE_SIZE); + +for ($i=0; $i < PREG_CACHE_SIZE; ++$i) { + $re .= '.'; + if (!preg_match("/$re/", $str)) { + die('non match. error'); + } +} + +var_dump(preg_match('/./', $str)); // this one was already deleted from the cache +var_dump(preg_match("/$re/", $str)); // but not this one + +echo "done\n"; +?> +--EXPECT-- +int(1) +int(1) +done diff --git a/ext/pcre/tests/delimiters.phpt b/ext/pcre/tests/delimiters.phpt new file mode 100644 index 000000000..1826f8730 --- /dev/null +++ b/ext/pcre/tests/delimiters.phpt @@ -0,0 +1,37 @@ +--TEST-- +Delimiters crash test +--FILE-- +<?php + +var_dump(preg_match('', '')); +var_dump(preg_match(' ', '')); +var_dump(preg_match('@@', '')); +var_dump(preg_match('12', '')); +var_dump(preg_match('<>', '')); +var_dump(preg_match('~a', '')); +var_dump(preg_match('@\@\@@', '@@')); +var_dump(preg_match('//z', '@@')); +var_dump(preg_match('{', '')); + +?> +--EXPECTF-- +Warning: preg_match(): Empty regular expression in %sdelimiters.php on line 3 +bool(false) + +Warning: preg_match(): Empty regular expression in %sdelimiters.php on line 4 +bool(false) +int(1) + +Warning: preg_match(): Delimiter must not be alphanumeric or backslash in %sdelimiters.php on line 6 +bool(false) +int(1) + +Warning: preg_match(): No ending delimiter '~' found in %sdelimiters.php on line 8 +bool(false) +int(1) + +Warning: preg_match(): Unknown modifier 'z' in %sdelimiters.php on line 10 +bool(false) + +Warning: preg_match(): No ending matching delimiter '}' found in %sdelimiters.php on line 11 +bool(false) diff --git a/ext/pcre/tests/dollar_endonly.phpt b/ext/pcre/tests/dollar_endonly.phpt new file mode 100644 index 000000000..96a52441d --- /dev/null +++ b/ext/pcre/tests/dollar_endonly.phpt @@ -0,0 +1,39 @@ +--TEST-- +D (PCRE_DOLLAR_ENDONLY) modififer +--FILE-- +<?php + +var_dump(preg_match_all('/^\S+.+$/', "aeiou\n", $m)); +var_dump($m); + +var_dump(preg_match_all('/^\S+.+$/D', "aeiou\n", $m)); +var_dump($m); + +var_dump(preg_match_all('/^\S+\s$/D', "aeiou\n", $m)); +var_dump($m); + +?> +--EXPECT-- +int(1) +array(1) { + [0]=> + array(1) { + [0]=> + string(5) "aeiou" + } +} +int(0) +array(1) { + [0]=> + array(0) { + } +} +int(1) +array(1) { + [0]=> + array(1) { + [0]=> + string(6) "aeiou +" + } +} diff --git a/ext/pcre/tests/grep.phpt b/ext/pcre/tests/grep.phpt new file mode 100644 index 000000000..d3d9032e4 --- /dev/null +++ b/ext/pcre/tests/grep.phpt @@ -0,0 +1,23 @@ +--TEST-- +preg_grep() +--FILE-- +<?php +$array = array('a', '1', 'q6', 'h20'); + +var_dump(preg_grep('/^(\d|.\d)$/', $array)); +var_dump(preg_grep('/^(\d|.\d)$/', $array, PREG_GREP_INVERT)); + +?> +--EXPECT-- +array(2) { + [1]=> + string(1) "1" + [2]=> + string(2) "q6" +} +array(2) { + [0]=> + string(1) "a" + [3]=> + string(3) "h20" +} diff --git a/ext/pcre/tests/grep2.phpt b/ext/pcre/tests/grep2.phpt new file mode 100644 index 000000000..0cf8d4aeb --- /dev/null +++ b/ext/pcre/tests/grep2.phpt @@ -0,0 +1,45 @@ +--TEST-- +preg_grep() 2nd test +--FILE-- +<?php + +var_dump(preg_grep(1,array(),3,4)); +var_dump(preg_grep(1, 2)); +var_dump(preg_grep('/+/', array())); + +$array = array(5=>'a', 'x' => '1', 'xyz'=>'q6', 'h20'); + +var_dump(preg_grep('@^[a-z]+@', $array)); +var_dump(preg_grep('@^[a-z]+@', $array, PREG_GREP_INVERT)); + +ini_set('pcre.recursion_limit', 1); +var_dump(preg_last_error() == PREG_NO_ERROR); +var_dump(preg_grep('@^[a-z]+@', $array)); +var_dump(preg_last_error() == PREG_RECURSION_LIMIT_ERROR); + +?> +--EXPECTF-- +Warning: preg_grep() expects at most 3 parameters, 4 given in %sgrep2.php on line 3 +NULL + +Warning: preg_grep() expects parameter 2 to be array, integer given in %sgrep2.php on line 4 +NULL + +Warning: preg_grep(): Compilation failed: nothing to repeat at offset 0 in %sgrep2.php on line 5 +bool(false) +array(3) { + [5]=> + string(1) "a" + ["xyz"]=> + string(2) "q6" + [6]=> + string(3) "h20" +} +array(1) { + ["x"]=> + string(1) "1" +} +bool(true) +array(0) { +} +bool(true) diff --git a/ext/pcre/tests/invalid_utf8.phpt b/ext/pcre/tests/invalid_utf8.phpt new file mode 100644 index 000000000..df2de2da9 --- /dev/null +++ b/ext/pcre/tests/invalid_utf8.phpt @@ -0,0 +1,16 @@ +--TEST-- +preg_replace() and invalid UTF8 +--FILE-- +<?php + +$string = urldecode("search%e4"); +$result = preg_replace("#(&\#x*)([0-9A-F]+);*#iu","$1$2;",$string); +var_dump($result); +var_dump(preg_last_error()); + +echo "Done\n"; +?> +--EXPECT-- +NULL +int(4) +Done diff --git a/ext/pcre/tests/locales.phpt b/ext/pcre/tests/locales.phpt new file mode 100644 index 000000000..6b600236c --- /dev/null +++ b/ext/pcre/tests/locales.phpt @@ -0,0 +1,25 @@ +--TEST-- +Localized match +--SKIPIF-- +<?php if (!function_exists('setlocale')) die('skip: setlocale() not available'); ?> +<?php if (!@setlocale(LC_ALL, 'pt_PT', 'pt', 'pt_PT.ISO8859-1', 'portuguese')) die('skip pt locale not available'); +--FILE-- +<?php + +// this tests if the cache is working correctly, as the char tables +// must be rebuilt after the locale change + +setlocale(LC_ALL, 'C', 'POSIX'); +var_dump(preg_match('/^\w{6}$/', 'aאבחיט')); + +setlocale(LC_ALL, 'pt_PT', 'pt', 'pt_PT.ISO8859-1', 'portuguese'); +var_dump(preg_match('/^\w{6}$/', 'aאבחיט')); + +setlocale(LC_ALL, 'C', 'POSIX'); +var_dump(preg_match('/^\w{6}$/', 'aאבחיט')); + +?> +--EXPECT-- +int(0) +int(1) +int(0) diff --git a/ext/pcre/tests/match_flags.phpt b/ext/pcre/tests/match_flags.phpt new file mode 100644 index 000000000..ddd36bf9b --- /dev/null +++ b/ext/pcre/tests/match_flags.phpt @@ -0,0 +1,127 @@ +--TEST-- +preg_match_all() flags +--FILE-- +<?php + +var_dump(preg_match_all('/(.)x/', 'zxax', $match, PREG_PATTERN_ORDER)); +var_dump($match); + +var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_SET_ORDER)); +var_dump($match); + +var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_OFFSET_CAPTURE)); +var_dump($match); + +var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)); +var_dump($match); + +?> +--EXPECT-- +int(2) +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "zx" + [1]=> + string(2) "ax" + } + [1]=> + array(2) { + [0]=> + string(1) "z" + [1]=> + string(1) "a" + } +} +int(2) +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "zx" + [1]=> + string(1) "z" + } + [1]=> + array(2) { + [0]=> + string(2) "yx" + [1]=> + string(1) "y" + } +} +int(2) +array(2) { + [0]=> + array(2) { + [0]=> + array(2) { + [0]=> + string(2) "zx" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(2) "yx" + [1]=> + int(2) + } + } + [1]=> + array(2) { + [0]=> + array(2) { + [0]=> + string(1) "z" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(1) "y" + [1]=> + int(2) + } + } +} +int(2) +array(2) { + [0]=> + array(2) { + [0]=> + array(2) { + [0]=> + string(2) "zx" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(1) "z" + [1]=> + int(0) + } + } + [1]=> + array(2) { + [0]=> + array(2) { + [0]=> + string(2) "yx" + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + string(1) "y" + [1]=> + int(2) + } + } +} diff --git a/ext/pcre/tests/match_flags2.phpt b/ext/pcre/tests/match_flags2.phpt new file mode 100644 index 000000000..f70309173 --- /dev/null +++ b/ext/pcre/tests/match_flags2.phpt @@ -0,0 +1,95 @@ +--TEST-- +preg_match() flags +--FILE-- +<?php + +var_dump(preg_match('/x(.)/', 'fjszxax', $match, PREG_OFFSET_CAPTURE)); +var_dump($match); + +var_dump(preg_match('/(.)x/', 'fjszxax', $match, PREG_OFFSET_CAPTURE, 4)); +var_dump($match); + +var_dump(preg_match('/(?P<capt1>.)(x)(?P<letsmix>\S+)/', 'fjszxax', $match, PREG_OFFSET_CAPTURE)); +var_dump($match); + +?> +--EXPECT-- +int(1) +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "xa" + [1]=> + int(4) + } + [1]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(5) + } +} +int(1) +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "ax" + [1]=> + int(5) + } + [1]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(5) + } +} +int(1) +array(6) { + [0]=> + array(2) { + [0]=> + string(4) "zxax" + [1]=> + int(3) + } + ["capt1"]=> + array(2) { + [0]=> + string(1) "z" + [1]=> + int(3) + } + [1]=> + array(2) { + [0]=> + string(1) "z" + [1]=> + int(3) + } + [2]=> + array(2) { + [0]=> + string(1) "x" + [1]=> + int(4) + } + ["letsmix"]=> + array(2) { + [0]=> + string(2) "ax" + [1]=> + int(5) + } + [3]=> + array(2) { + [0]=> + string(2) "ax" + [1]=> + int(5) + } +} diff --git a/ext/pcre/tests/match_flags3.phpt b/ext/pcre/tests/match_flags3.phpt new file mode 100644 index 000000000..f22205e3d --- /dev/null +++ b/ext/pcre/tests/match_flags3.phpt @@ -0,0 +1,46 @@ +--TEST-- +preg_match() flags 3 +--FILE-- +<?php + +var_dump(preg_match('', '', $match, 0xfff)); + +var_dump(preg_match('/\d+/', '123 456 789 012', $match, 0, -8)); +var_dump($match); + +var_dump(preg_match('/\d+/', '123 456 789 012', $match, 0, -500)); +var_dump($match); + +var_dump(preg_match_all('/\d+/', '123 456 789 012', $match, 0, -8)); +var_dump($match); + +var_dump(preg_match('/(?P<3>)/', '')); + +?> +--EXPECTF-- + +Warning: preg_match(): Empty regular expression in %smatch_flags3.php on line 3 +bool(false) +int(1) +array(1) { + [0]=> + string(3) "789" +} +int(1) +array(1) { + [0]=> + string(3) "123" +} +int(2) +array(1) { + [0]=> + array(2) { + [0]=> + string(3) "789" + [1]=> + string(3) "012" + } +} + +Warning: preg_match(): Numeric named subpatterns are not allowed in %smatch_flags3.php on line 14 +bool(false) diff --git a/ext/pcre/tests/multiline.phpt b/ext/pcre/tests/multiline.phpt new file mode 100644 index 000000000..356800917 --- /dev/null +++ b/ext/pcre/tests/multiline.phpt @@ -0,0 +1,18 @@ +--TEST-- +Multi-line match +--FILE-- +<?php + +var_dump(preg_match_all('/^.{2,3}$/', "aei\nou", $dummy)); +var_dump(preg_match_all('/^.{2,3}$/', "aei\nou\n", $dummy)); +var_dump(preg_match_all('/^.{2,3}$/m', "aei\nou", $dummy)); +var_dump(preg_match_all('/^.{2,3}$/m', "aei\nou\n", $dummy)); + +echo "done\n"; +?> +--EXPECT-- +int(0) +int(0) +int(2) +int(2) +done diff --git a/ext/pcre/tests/pcre_anchored.phpt b/ext/pcre/tests/pcre_anchored.phpt new file mode 100644 index 000000000..caa96437e --- /dev/null +++ b/ext/pcre/tests/pcre_anchored.phpt @@ -0,0 +1,22 @@ +--TEST-- +A (PCRE_ANCHORED) modififer +--FILE-- +<?php + +var_dump(preg_match('/\PN+/', '123abc', $m)); +var_dump($m); + +var_dump(preg_match('/\P{N}+/A', '123abc')); +var_dump(preg_match('/^\P{N}+/', '123abc')); +var_dump(preg_match('/^\P{N}+/A', '123abc')); + +?> +--EXPECT-- +int(1) +array(1) { + [0]=> + string(3) "abc" +} +int(0) +int(0) +int(0) diff --git a/ext/pcre/tests/pcre_extended.phpt b/ext/pcre/tests/pcre_extended.phpt new file mode 100644 index 000000000..6c4b20e7f --- /dev/null +++ b/ext/pcre/tests/pcre_extended.phpt @@ -0,0 +1,29 @@ +--TEST-- +x (PCRE_EXTENDED) modififer +--FILE-- +<?php + +var_dump(preg_match('/a e i o u/', 'aeiou', $m)); +var_dump($m); + +var_dump(preg_match('/a e i o u/x', 'aeiou', $m)); +var_dump($m); + +var_dump(preg_match("/a e\ni\to\ru/x", 'aeiou', $m)); +var_dump($m); + +?> +--EXPECT-- +int(0) +array(0) { +} +int(1) +array(1) { + [0]=> + string(5) "aeiou" +} +int(1) +array(1) { + [0]=> + string(5) "aeiou" +} diff --git a/ext/pcre/tests/pcre_extra.phpt b/ext/pcre/tests/pcre_extra.phpt new file mode 100644 index 000000000..2bee408fb --- /dev/null +++ b/ext/pcre/tests/pcre_extra.phpt @@ -0,0 +1,14 @@ +--TEST-- +X (PCRE_EXTRA) modififer +--FILE-- +<?php + +var_dump(preg_match('/\y/', '\y')); +var_dump(preg_match('/\y/X', '\y')); + +?> +--EXPECTF-- +int(1) + +Warning: preg_match(): Compilation failed: unrecognized character follows \ at offset 1 in %spcre_extra.php on line 4 +bool(false) diff --git a/ext/pcre/tests/preg_replace.phpt b/ext/pcre/tests/preg_replace.phpt new file mode 100644 index 000000000..f7b5f7415 --- /dev/null +++ b/ext/pcre/tests/preg_replace.phpt @@ -0,0 +1,25 @@ +--TEST-- +preg_replace() +--FILE-- +<?php + +var_dump(preg_replace('{{\D+}}', 'x', '{abcd}')); +var_dump(preg_replace('{{\D+}}', 'ddd', 'abcd')); + +var_dump(preg_replace('/(ab)(c)(d)(e)(f)(g)(h)(i)(j)(k)/', 'a${1}2$103', 'zabcdefghijkl')); + +var_dump(preg_replace_callback('//e', '', '')); + +var_dump(preg_replace_callback('//e', 'strtolower', '')); + +?> +--EXPECTF-- +string(1) "x" +string(4) "abcd" +string(8) "zaab2k3l" + +Warning: preg_replace_callback(): Requires argument 2, '', to be a valid callback in %spreg_replace.php on line 8 +string(0) "" + +Warning: preg_replace_callback(): Modifier /e cannot be used with replacement callback in %spreg_replace.php on line 10 +NULL diff --git a/ext/pcre/tests/preg_replace2.phpt b/ext/pcre/tests/preg_replace2.phpt new file mode 100644 index 000000000..4e2f39f8c --- /dev/null +++ b/ext/pcre/tests/preg_replace2.phpt @@ -0,0 +1,42 @@ +--TEST-- +preg_replace() +--FILE-- +<?php + +var_dump(preg_replace('', array(), '')); + +var_dump(preg_replace(array('/\da(.)/ui', '@..@'), '$1', '12Abc')); +var_dump(preg_replace(array('/\da(.)/ui', '@(.)@'), '$1', array('x','a2aA', '1av2Ab'))); + + +var_dump(preg_replace(array('/[\w]+/'), array('$'), array('xyz', 'bdbd'))); +var_dump(preg_replace(array('/\s+/', '~[b-d]~'), array('$'), array('x y', 'bd bc'))); + +echo "==done==\n"; + +?> +--EXPECTF-- +Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace2.php on line 3 +bool(false) +string(1) "c" +array(3) { + [0]=> + string(1) "x" + [1]=> + string(2) "aA" + [2]=> + string(2) "vb" +} +array(2) { + [0]=> + string(1) "$" + [1]=> + string(1) "$" +} +array(2) { + [0]=> + string(3) "x$y" + [1]=> + string(1) "$" +} +==done== diff --git a/ext/pcre/tests/preg_replace_callback.phpt b/ext/pcre/tests/preg_replace_callback.phpt new file mode 100644 index 000000000..0b0bc2757 --- /dev/null +++ b/ext/pcre/tests/preg_replace_callback.phpt @@ -0,0 +1,25 @@ +--TEST-- +preg_replace_callback() +--FILE-- +<?php +$input = "plain [indent] deep [indent] [abcd]deeper[/abcd] [/indent] deep [/indent] plain"; + +function parseTagsRecursive($input) +{ + + $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#'; + + if (is_array($input)) { + $input = '<div style="margin-left: 10px">'.$input[1].'</div>'; + } + + return preg_replace_callback($regex, 'parseTagsRecursive', $input); +} + +$output = parseTagsRecursive($input); + +echo $output, "\n"; + +?> +--EXPECT-- +plain <div style="margin-left: 10px"> deep <div style="margin-left: 10px"> [abcd]deeper[/abcd] </div> deep </div> plain diff --git a/ext/pcre/tests/preg_replace_callback2.phpt b/ext/pcre/tests/preg_replace_callback2.phpt new file mode 100644 index 000000000..a7f5a362d --- /dev/null +++ b/ext/pcre/tests/preg_replace_callback2.phpt @@ -0,0 +1,40 @@ +--TEST-- +preg_replace_callback() 2 +--FILE-- +<?php + +function f() { + throw new Exception(); +} + +try { +var_dump(preg_replace_callback('/\w/', 'f', 'z')); +} catch(Exception $e) {} + +function g($x) { + return "'$x[0]'"; +} + +var_dump(preg_replace_callback('@\b\w{1,2}\b@', 'g', array('a b3 bcd', 'v' => 'aksfjk', 12 => 'aa bb'))); + +var_dump(preg_replace_callback('~\A.~', 'g', array(array('xyz')))); + +var_dump(preg_replace_callback('~\A.~', create_function('$m', 'return strtolower($m[0]);'), 'ABC')); +?> +--EXPECTF-- +Warning: preg_replace_callback(): Unable to call custom replacement function in %spreg_replace_callback2.php on line %d +array(3) { + [0]=> + string(12) "'a' 'b3' bcd" + ["v"]=> + string(6) "aksfjk" + [12]=> + string(9) "'aa' 'bb'" +} + +Notice: Array to string conversion in %spreg_replace_callback2.php on line 17 +array(1) { + [0]=> + string(7) "'A'rray" +} +string(3) "aBC" diff --git a/ext/pcre/tests/preg_replace_callback3.phpt b/ext/pcre/tests/preg_replace_callback3.phpt new file mode 100644 index 000000000..fafd966f4 --- /dev/null +++ b/ext/pcre/tests/preg_replace_callback3.phpt @@ -0,0 +1,45 @@ +--TEST-- +preg_replace_callback() 3 +--FILE-- +<?php + +var_dump(preg_replace_callback()); +var_dump(preg_replace_callback(1)); +var_dump(preg_replace_callback(1,2)); +var_dump(preg_replace_callback(1,2,3)); +var_dump(preg_replace_callback(1,2,3,4)); +$a = 5; +var_dump(preg_replace_callback(1,2,3,4,$a)); +$a = ""; +var_dump(preg_replace_callback("","","","",$a)); +$a = array(); +var_dump(preg_replace_callback($a,$a,$a,$a,$a)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: Wrong parameter count for preg_replace_callback() in %s on line %d +NULL + +Warning: Wrong parameter count for preg_replace_callback() in %s on line %d +NULL + +Warning: Wrong parameter count for preg_replace_callback() in %s on line %d +NULL + +Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d +int(3) + +Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d +int(3) + +Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d +int(3) + +Warning: preg_replace_callback(): Requires argument 2, '', to be a valid callback in %s on line 1%d +string(0) "" + +Warning: preg_replace_callback(): Requires argument 2, 'Array', to be a valid callback in %s on line %d +array(0) { +} +Done diff --git a/ext/pcre/tests/recursion_limit.phpt b/ext/pcre/tests/recursion_limit.phpt new file mode 100644 index 000000000..2a43aa27d --- /dev/null +++ b/ext/pcre/tests/recursion_limit.phpt @@ -0,0 +1,19 @@ +--TEST-- +PCRE Recursion limit +--INI-- +pcre.recursion_limit=2 +--FILE-- +<?php + +var_dump(preg_match_all('/\p{Ll}(\p{L}((\p{Ll}\p{Ll})))/', 'aeiou', $dummy)); +var_dump(preg_last_error() === PREG_RECURSION_LIMIT_ERROR); + +var_dump(preg_match_all('/\p{Ll}\p{L}\p{Ll}\p{Ll}/', 'aeiou', $dummy)); +var_dump(preg_last_error() === PREG_NO_ERROR); + +?> +--EXPECT-- +int(0) +bool(true) +int(1) +bool(true) diff --git a/ext/pcre/tests/split.phpt b/ext/pcre/tests/split.phpt new file mode 100644 index 000000000..8ec8e655c --- /dev/null +++ b/ext/pcre/tests/split.phpt @@ -0,0 +1,86 @@ +--TEST-- +preg_split() +--FILE-- +<?php + +var_dump(preg_split()); +var_dump(preg_split('/*/', 'x')); + +var_dump(preg_split('/[\s, ]+/', 'x yy,zzz')); +var_dump(preg_split('/[\s, ]+/', 'x yy,zzz', -1)); +var_dump(preg_split('/[\s, ]+/', 'x yy,zzz', 0)); +var_dump(preg_split('/[\s, ]+/', 'x yy,zzz', 1)); +var_dump(preg_split('/[\s, ]+/', 'x yy,zzz', 2)); + +var_dump(preg_split('/\d*/', 'ab2c3u')); +var_dump(preg_split('/\d*/', 'ab2c3u', -1, PREG_SPLIT_NO_EMPTY)); + +?> +--EXPECTF-- +Warning: preg_split() expects at least 2 parameters, 0 given in %ssplit.php on line 3 +bool(false) + +Warning: preg_split(): Compilation failed: nothing to repeat at offset 0 in %ssplit.php on line 4 +bool(false) +array(3) { + [0]=> + string(1) "x" + [1]=> + string(2) "yy" + [2]=> + string(3) "zzz" +} +array(3) { + [0]=> + string(1) "x" + [1]=> + string(2) "yy" + [2]=> + string(3) "zzz" +} +array(3) { + [0]=> + string(1) "x" + [1]=> + string(2) "yy" + [2]=> + string(3) "zzz" +} +array(1) { + [0]=> + string(8) "x yy,zzz" +} +array(2) { + [0]=> + string(1) "x" + [1]=> + string(6) "yy,zzz" +} +array(8) { + [0]=> + string(0) "" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(0) "" + [4]=> + string(1) "c" + [5]=> + string(0) "" + [6]=> + string(1) "u" + [7]=> + string(0) "" +} +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "u" +} diff --git a/ext/pcre/tests/split2.phpt b/ext/pcre/tests/split2.phpt new file mode 100644 index 000000000..391acb951 --- /dev/null +++ b/ext/pcre/tests/split2.phpt @@ -0,0 +1,315 @@ +--TEST-- +preg_split() 2nd test +--FILE-- +<?php + +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_DELIM_CAPTURE)); +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_OFFSET_CAPTURE)); +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)); +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE));; +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE)); +var_dump(preg_split('/(\d*)/', 'ab2c3u', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE)); + + +var_dump(preg_last_error(1)); +ini_set('pcre.recursion_limit', 1); +var_dump(preg_last_error() == PREG_NO_ERROR); +var_dump(preg_split('/(\d*)/', 'ab2c3u')); +var_dump(preg_last_error() == PREG_RECURSION_LIMIT_ERROR); + +?> +--EXPECTF-- +array(15) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(1) "a" + [3]=> + string(0) "" + [4]=> + string(1) "b" + [5]=> + string(1) "2" + [6]=> + string(0) "" + [7]=> + string(0) "" + [8]=> + string(1) "c" + [9]=> + string(1) "3" + [10]=> + string(0) "" + [11]=> + string(0) "" + [12]=> + string(1) "u" + [13]=> + string(0) "" + [14]=> + string(0) "" +} +array(8) { + [0]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(0) + } + [2]=> + array(2) { + [0]=> + string(1) "b" + [1]=> + int(1) + } + [3]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(3) + } + [4]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + int(3) + } + [5]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(5) + } + [6]=> + array(2) { + [0]=> + string(1) "u" + [1]=> + int(5) + } + [7]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(6) + } +} +array(6) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "2" + [3]=> + string(1) "c" + [4]=> + string(1) "3" + [5]=> + string(1) "u" +} +array(4) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(1) "b" + [1]=> + int(1) + } + [2]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + int(3) + } + [3]=> + array(2) { + [0]=> + string(1) "u" + [1]=> + int(5) + } +} +array(15) { + [0]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(0) + } + [2]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(0) + } + [3]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(1) + } + [4]=> + array(2) { + [0]=> + string(1) "b" + [1]=> + int(1) + } + [5]=> + array(2) { + [0]=> + string(1) "2" + [1]=> + int(2) + } + [6]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(3) + } + [7]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(3) + } + [8]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + int(3) + } + [9]=> + array(2) { + [0]=> + string(1) "3" + [1]=> + int(4) + } + [10]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(5) + } + [11]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(5) + } + [12]=> + array(2) { + [0]=> + string(1) "u" + [1]=> + int(5) + } + [13]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(6) + } + [14]=> + array(2) { + [0]=> + string(0) "" + [1]=> + int(6) + } +} +array(6) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + string(1) "b" + [1]=> + int(1) + } + [2]=> + array(2) { + [0]=> + string(1) "2" + [1]=> + int(2) + } + [3]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + int(3) + } + [4]=> + array(2) { + [0]=> + string(1) "3" + [1]=> + int(4) + } + [5]=> + array(2) { + [0]=> + string(1) "u" + [1]=> + int(5) + } +} + +Warning: preg_last_error() expects exactly 0 parameters, 1 given in %s on line %d +NULL +bool(true) +array(1) { + [0]=> + string(6) "ab2c3u" +} +bool(true) diff --git a/ext/pcre/tests/study.phpt b/ext/pcre/tests/study.phpt new file mode 100644 index 000000000..696a4c0ef --- /dev/null +++ b/ext/pcre/tests/study.phpt @@ -0,0 +1,31 @@ +--TEST-- +Study regex +--FILE-- +<?php + +var_dump(preg_match('/(?:(?:(?:(?:(?:(.))))))/ S', 'aeiou', $dump)); +var_dump($dump[1]); +var_dump(preg_match('/(?:(?:(?:(?:(?:(.))))))/', 'aeiou', $dump)); +var_dump($dump[1]); + +var_dump(preg_match('/(?>..)((?:(?>.)|.|.|.|u))/S', 'aeiou', $dump)); +var_dump($dump[1]); + +// try to trigger usual "match known text" optimization +var_dump(preg_match('/^aeiou$/S', 'aeiou', $dump)); +var_dump($dump[0]); +var_dump(preg_match('/aeiou/S', 'aeiou', $dump)); +var_dump($dump[0]); + +?> +--EXPECT-- +int(1) +string(1) "a" +int(1) +string(1) "a" +int(1) +string(1) "i" +int(1) +string(5) "aeiou" +int(1) +string(5) "aeiou" diff --git a/ext/pcre/tests/ungreedy.phpt b/ext/pcre/tests/ungreedy.phpt new file mode 100644 index 000000000..cf5e8adaf --- /dev/null +++ b/ext/pcre/tests/ungreedy.phpt @@ -0,0 +1,31 @@ +--TEST-- +U (PCRE_UNGREEDY) modififer +--FILE-- +<?php + +var_dump(preg_match('/<.*>/', '<aa> <bb> <cc>', $m)); +var_dump($m); + +var_dump(preg_match('/<.*>/U', '<aa> <bb> <cc>', $m)); +var_dump($m); + +var_dump(preg_match('/(?U)<.*>/', '<aa> <bb> <cc>', $m)); +var_dump($m); + +?> +--EXPECT-- +int(1) +array(1) { + [0]=> + string(14) "<aa> <bb> <cc>" +} +int(1) +array(1) { + [0]=> + string(4) "<aa>" +} +int(1) +array(1) { + [0]=> + string(4) "<aa>" +} |
