]> granicus.if.org Git - php/commitdiff
new tests and fix the locales test where the pt local isnt available.
authorNuno Lopes <nlopess@php.net>
Mon, 3 Jul 2006 13:04:45 +0000 (13:04 +0000)
committerNuno Lopes <nlopess@php.net>
Mon, 3 Jul 2006 13:04:45 +0000 (13:04 +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]

index 531dd132ab9adaf11c8a05eee34f1eebf2606a03..6b600236cf34027bd39d26063609027026cb4eab 100644 (file)
@@ -2,6 +2,7 @@
 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
 
diff --git a/ext/pcre/tests/match_flags3.phpt b/ext/pcre/tests/match_flags3.phpt
new file mode 100644 (file)
index 0000000..8670f03
--- /dev/null
@@ -0,0 +1,37 @@
+--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_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(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 11
+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..146bb7d
--- /dev/null
@@ -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(): /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