com php-src: Improve test scripts: ext/pcre/tests/preg_replac e_callback_array.phpt ext/pcre/tests/preg_replace_c allback_array2.phpt
ext/pcre/tests/preg_replace_cal lback_array3.phpt

From: Date: Sat, 21 Mar 2015 13:11:14 +0000
Subject: com php-src: Improve test scripts: ext/pcre/tests/preg_replac e_callback_array.phpt ext/pcre/tests/preg_replace_c allback_array2.phpt
ext/pcre/tests/preg_replace_cal lback_array3.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85747@lists.php.net to get a copy of this message
Commit: 784c60ab6d6096fd8e88ba75f35b5b9ca2377fc3 Author: Xinchen Hui <laruence@php.net> Sat, 21 Mar 2015 21:11:14 +0800 Parents: a4529cc0e51d81432d8786448bea8b5f137d2cc3 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=784c60ab6d6096fd8e88ba75f35b5b9ca2377fc3 Log: Improve test scripts Changed paths: M ext/pcre/tests/preg_replace_callback_array.phpt M ext/pcre/tests/preg_replace_callback_array2.phpt D ext/pcre/tests/preg_replace_callback_array3.phpt Diff: diff --git a/ext/pcre/tests/preg_replace_callback_array.phpt b/ext/pcre/tests/preg_replace_callback_array.phpt index 14a4656..9e9e819 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 fca7167..8e70bb0 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 ace1e88..0000000 --- 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

« previous php.cvs (#85747) next »