summaryrefslogtreecommitdiff
path: root/ext/pcre
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2006-06-14 17:37:53 +0000
committerNuno Lopes <nlopess@php.net>2006-06-14 17:37:53 +0000
commita7bc286638ff4ed9ac8ced1969dc945caf815024 (patch)
treefe158021edac763003d337606b091a3409b75bea /ext/pcre
parent7406f3771a150b9345f32e4278fc99e2be98d3bf (diff)
downloadphp-git-a7bc286638ff4ed9ac8ced1969dc945caf815024.tar.gz
more tests (and fix 2 from yesterday)
Diffstat (limited to 'ext/pcre')
-rw-r--r--ext/pcre/tests/delimiters.phpt4
-rw-r--r--ext/pcre/tests/dollar_endonly.phpt39
-rw-r--r--ext/pcre/tests/locales.phpt2
-rw-r--r--ext/pcre/tests/match_flags.phpt127
-rw-r--r--ext/pcre/tests/match_flags2.phpt95
-rw-r--r--ext/pcre/tests/pcre_anchored.phpt22
-rw-r--r--ext/pcre/tests/pcre_extended.phpt29
-rw-r--r--ext/pcre/tests/pcre_extra.phpt14
-rw-r--r--ext/pcre/tests/ungreedy.phpt31
9 files changed, 362 insertions, 1 deletions
diff --git a/ext/pcre/tests/delimiters.phpt b/ext/pcre/tests/delimiters.phpt
index 0cc235ecaa..1826f8730a 100644
--- a/ext/pcre/tests/delimiters.phpt
+++ b/ext/pcre/tests/delimiters.phpt
@@ -11,6 +11,7 @@ var_dump(preg_match('<>', ''));
var_dump(preg_match('~a', ''));
var_dump(preg_match('@\@\@@', '@@'));
var_dump(preg_match('//z', '@@'));
+var_dump(preg_match('{', ''));
?>
--EXPECTF--
@@ -31,3 +32,6 @@ 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 0000000000..96a52441df
--- /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/locales.phpt b/ext/pcre/tests/locales.phpt
index 0f55df0aad..2e90c3d32a 100644
--- a/ext/pcre/tests/locales.phpt
+++ b/ext/pcre/tests/locales.phpt
@@ -1,7 +1,7 @@
--TEST--
Localized match
--SKIPIF--
-<?php if (!function_exists('setlocale')) die('setlocale() not available'); ?>
+<?php if (!function_exists('setlocale')) die('skip: setlocale() not available'); ?>
--FILE--
<?php
diff --git a/ext/pcre/tests/match_flags.phpt b/ext/pcre/tests/match_flags.phpt
new file mode 100644
index 0000000000..ddd36bf9ba
--- /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 0000000000..f703091735
--- /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/pcre_anchored.phpt b/ext/pcre/tests/pcre_anchored.phpt
new file mode 100644
index 0000000000..caa96437e1
--- /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 0000000000..6c4b20e7f0
--- /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 0000000000..2bee408fbf
--- /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/ungreedy.phpt b/ext/pcre/tests/ungreedy.phpt
new file mode 100644
index 0000000000..cf5e8adafd
--- /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>"
+}