]> granicus.if.org Git - php/commitdiff
Improve test scripts
authorXinchen Hui <laruence@php.net>
Sat, 21 Mar 2015 13:11:14 +0000 (21:11 +0800)
committerXinchen Hui <laruence@php.net>
Sat, 21 Mar 2015 13:11:14 +0000 (21:11 +0800)
ext/pcre/tests/preg_replace_callback_array.phpt
ext/pcre/tests/preg_replace_callback_array2.phpt
ext/pcre/tests/preg_replace_callback_array3.phpt [deleted file]

index 14a4656eb18b39328796329458f41a602700699f..9e9e81913499a2cabb0ce165118e1a16a418e45d 100644 (file)
@@ -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)
index fca71673c99274783a81d36249cef8c15841cfad..8e70bb06e8c1119f89297012151a585a0f1012bc 100644 (file)
@@ -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 (file)
index ace1e88..0000000
+++ /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