diff options
| author | Nuno Lopes <nlopess@php.net> | 2006-06-13 21:55:38 +0000 |
|---|---|---|
| committer | Nuno Lopes <nlopess@php.net> | 2006-06-13 21:55:38 +0000 |
| commit | c93dc5d873981377b99c33019bda5b2319604e5e (patch) | |
| tree | 5c9dbf72e057a7e6613a22314d2c98b1dd2e4691 /ext/pcre/tests | |
| parent | 9660548a22c998b5110867cef20c7aa2a9d25f3b (diff) | |
| download | php-git-c93dc5d873981377b99c33019bda5b2319604e5e.tar.gz | |
add new tests, increasing coverage by about 10%
Diffstat (limited to 'ext/pcre/tests')
| -rw-r--r-- | ext/pcre/tests/backtrack_limit.phpt | 19 | ||||
| -rw-r--r-- | ext/pcre/tests/cache_limit.phpt | 25 | ||||
| -rw-r--r-- | ext/pcre/tests/delimiters.phpt | 33 | ||||
| -rw-r--r-- | ext/pcre/tests/grep.phpt | 23 | ||||
| -rw-r--r-- | ext/pcre/tests/locales.phpt | 24 | ||||
| -rw-r--r-- | ext/pcre/tests/multiline.phpt | 18 | ||||
| -rw-r--r-- | ext/pcre/tests/recursion_limit.phpt | 19 | ||||
| -rw-r--r-- | ext/pcre/tests/study.phpt | 31 |
8 files changed, 192 insertions, 0 deletions
diff --git a/ext/pcre/tests/backtrack_limit.phpt b/ext/pcre/tests/backtrack_limit.phpt new file mode 100644 index 0000000000..ebfd720c3c --- /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/cache_limit.phpt b/ext/pcre/tests/cache_limit.phpt new file mode 100644 index 0000000000..bfe7f1b9a9 --- /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 0000000000..0cc235ecaa --- /dev/null +++ b/ext/pcre/tests/delimiters.phpt @@ -0,0 +1,33 @@ +--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', '@@')); + +?> +--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) diff --git a/ext/pcre/tests/grep.phpt b/ext/pcre/tests/grep.phpt new file mode 100644 index 0000000000..d3d9032e49 --- /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/locales.phpt b/ext/pcre/tests/locales.phpt new file mode 100644 index 0000000000..0f55df0aad --- /dev/null +++ b/ext/pcre/tests/locales.phpt @@ -0,0 +1,24 @@ +--TEST-- +Localized match +--SKIPIF-- +<?php if (!function_exists('setlocale')) die('setlocale() 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', '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/multiline.phpt b/ext/pcre/tests/multiline.phpt new file mode 100644 index 0000000000..356800917b --- /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/recursion_limit.phpt b/ext/pcre/tests/recursion_limit.phpt new file mode 100644 index 0000000000..2a43aa27d6 --- /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/study.phpt b/ext/pcre/tests/study.phpt new file mode 100644 index 0000000000..696a4c0ef0 --- /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" |
