summaryrefslogtreecommitdiff
path: root/ext/pcre/tests
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2015-03-21 21:11:14 +0800
committerXinchen Hui <laruence@php.net>2015-03-21 21:11:14 +0800
commit784c60ab6d6096fd8e88ba75f35b5b9ca2377fc3 (patch)
tree94b6d31abc9339a4538d0cf7244d98991a36a57d /ext/pcre/tests
parenta4529cc0e51d81432d8786448bea8b5f137d2cc3 (diff)
downloadphp-git-784c60ab6d6096fd8e88ba75f35b5b9ca2377fc3.tar.gz
Improve test scripts
Diffstat (limited to 'ext/pcre/tests')
-rw-r--r--ext/pcre/tests/preg_replace_callback_array.phpt73
-rw-r--r--ext/pcre/tests/preg_replace_callback_array2.phpt10
-rw-r--r--ext/pcre/tests/preg_replace_callback_array3.phpt35
3 files changed, 46 insertions, 72 deletions
diff --git a/ext/pcre/tests/preg_replace_callback_array.phpt b/ext/pcre/tests/preg_replace_callback_array.phpt
index 14a4656eb1..9e9e819134 100644
--- a/ext/pcre/tests/preg_replace_callback_array.phpt
+++ b/ext/pcre/tests/preg_replace_callback_array.phpt
@@ -3,48 +3,47 @@ preg_replace_callback_array() basic functions
--FILE--
<?php
-function f() {
- throw new Exception('f');
+class Rep {
+ public function __invoke() {
+ return "d";
+ }
}
-function a() {
- return __FUNCTION__;
+class Foo {
+ public static function rep($rep) {
+ return "ok";
+ }
}
-try {
- var_dump($c = preg_replace_callback_array(array('/\w*/' => 'f', '/\w/' => 'a'), 'z'));
-} catch(Exception $e) {
- var_dump($e->getMessage());
+function b() {
+ return "b";
}
-var_dump($c);
-function g($x) {
- return "'$x[0]'";
-}
-
-var_dump(preg_replace_callback_array(array('@\b\w{1,2}\b@' => 'g'), array('a b3 bcd', 'v' => 'aksfjk', 12 => 'aa bb')));
-
-var_dump(preg_replace_callback_array(array('~\A.~' => 'g'), array(array('xyz'))));
-
-var_dump(preg_replace_callback_array(array('~\A.~' => create_function('$m', 'return strtolower($m[0]);')), 'ABC'));
+var_dump(preg_replace_callback_array(
+ array(
+ "/a/" => 'b',
+ "/b/" => function () { return "c"; },
+ "/c/" => new Rep,
+ '/d/' => array("Foo", "rep")), 'a'));
+
+var_dump(preg_replace_callback_array(
+ array(
+ "/a/" => 'b',
+ "/c/" => new Rep,
+ "/b/" => function () { return "ok"; },
+ '/d/' => array("Foo", "rep")), 'a'));
+
+var_dump(preg_replace_callback_array(
+ array(
+ '/d/' => array("Foo", "rep"),
+ "/c/" => new Rep,
+ "/a/" => 'b',
+ "/b/" => create_function('$a', 'return "ok";')), 'a', -1, $count));
+
+var_dump($count);
?>
--EXPECTF--
-string(1) "f"
-
-Notice: Undefined variable: c in %spreg_replace_callback_array.php on line %d
-NULL
-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_callback_array.php on line %d
-array(1) {
- [0]=>
- string(7) "'A'rray"
-}
-string(3) "aBC"
+string(2) "ok"
+string(2) "ok"
+string(2) "ok"
+int(2)
diff --git a/ext/pcre/tests/preg_replace_callback_array2.phpt b/ext/pcre/tests/preg_replace_callback_array2.phpt
index fca71673c9..8e70bb06e8 100644
--- a/ext/pcre/tests/preg_replace_callback_array2.phpt
+++ b/ext/pcre/tests/preg_replace_callback_array2.phpt
@@ -19,9 +19,18 @@ $b = "";
var_dump(preg_replace_callback_array(array("xx" => "s"), $a, -1, $b));
var_dump($b);
function f() {
+ static $count = 1;
+ throw new Exception($count);
}
var_dump(preg_replace_callback_array(array('/\w' => 'f'), 'z'));
+
+try {
+ var_dump(preg_replace_callback_array(array('/\w/' => 'f', '/.*/' => 'f'), 'z'));
+} catch (Exception $e) {
+ var_dump($e->getMessage());
+}
+
echo "Done\n";
?>
--EXPECTF--
@@ -54,4 +63,5 @@ string(0) ""
Warning: preg_replace_callback_array(): No ending delimiter '/' found in %spreg_replace_callback_array2.php on line %d
NULL
+string(1) "1"
Done
diff --git a/ext/pcre/tests/preg_replace_callback_array3.phpt b/ext/pcre/tests/preg_replace_callback_array3.phpt
deleted file mode 100644
index ace1e88999..0000000000
--- a/ext/pcre/tests/preg_replace_callback_array3.phpt
+++ /dev/null
@@ -1,35 +0,0 @@
---TEST--
-preg_replace_callback_array() multiply callbacks
---FILE--
-<?php
-$code = "test-EXECUTE_DATA-xcvxcv-ZEND_VM_DISPATCH_TO_HELPER";
-
-$code = preg_replace_callback_array(
- array(
- "/EXECUTE_DATA/m" => function($matches) { return "execute_data";},
- "/ZEND_VM_DISPATCH_TO_HANDLER/m" => function($matches) { return "handler"; },
- "/ZEND_VM_DISPATCH_TO_HELPER/m" => function($matches) { return "helper"; },
- "/ZEND_VM_DISPATCH_TO_HELPER_EX/m" => function($matches) { return "helper_ex"; },
- ),
- $code);
-
-var_dump($code);
-$code = array("test-EXECUTE_DATA-ZEND_VM_DISPATCH_TO_HELPER_EX-test",
- "test-sdf-xcvxcv-ZEND_VM_DISPATCH_TO_HELPER_EX-test-EXECUTE_DATA-test");
-
-$code = preg_replace_callback_array(
- array(
- "/ZEND_VM_DISPATCH_TO_HANDLER/m" => function($matches) { return "handler"; },
- 23234 => function($matches) { return "execute_data";},
- "/ZEND_VM_DISPATCH_TO_HELPER/m" => function($matches) { return "helper"; },
- ),
- $code, -1, $count);
-
-var_dump($code, $count);
-?>
---EXPECTF--
-string(31) "test-execute_data-xcvxcv-helper"
-
-Warning: preg_replace_callback_array(): Delimiter must not be alphanumeric or backslash in %s on line %d
-NULL
-NULL