]> granicus.if.org Git - php/commitdiff
MFB
authorNuno Lopes <nlopess@php.net>
Mon, 3 Jul 2006 14:55:49 +0000 (14:55 +0000)
committerNuno Lopes <nlopess@php.net>
Mon, 3 Jul 2006 14:55:49 +0000 (14:55 +0000)
ext/pcre/tests/locales.phpt
ext/pcre/tests/match_flags3.phpt [new file with mode: 0644]
ext/pcre/tests/preg_replace.phpt [new file with mode: 0644]
ext/pcre/tests/preg_replace_callback.phpt [new file with mode: 0644]
ext/pcre/tests/preg_replace_callback2.phpt [new file with mode: 0644]

index cb3028e2b5a2e8b7f5acd5601524646493d68d53..00dc91a0fd3f6a3147a0a89b370368cfac6ba388 100644 (file)
@@ -2,10 +2,11 @@
 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
 
-declare(encoding=latin1);
+declare(encoding='latin1');
 
 // this tests if the cache is working correctly, as the char tables
 // must be rebuilt after the locale change
diff --git a/ext/pcre/tests/match_flags3.phpt b/ext/pcre/tests/match_flags3.phpt
new file mode 100644 (file)
index 0000000..a0fa5a8
--- /dev/null
@@ -0,0 +1,45 @@
+--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: Wrong value for parameter 4 in call to preg_match() in %smatch_flags3.php on line 3
+NULL
+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/preg_replace.phpt b/ext/pcre/tests/preg_replace.phpt
new file mode 100644 (file)
index 0000000..2254e26
--- /dev/null
@@ -0,0 +1,35 @@
+--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(): /e modifier cannot be used with replacement callback in %spreg_replace.php on line 10
+NULL
+--EXPECTUF--
+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
+unicode(0) ""
+
+Warning: preg_replace_callback(): /e modifier cannot be used with replacement callback in %spreg_replace.php on line 10
+NULL
diff --git a/ext/pcre/tests/preg_replace_callback.phpt b/ext/pcre/tests/preg_replace_callback.phpt
new file mode 100644 (file)
index 0000000..0b0bc27
--- /dev/null
@@ -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 (file)
index 0000000..65f23ca
--- /dev/null
@@ -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 ins %preg_replace_callback2.php on line 8
+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"