From: Xinchen Hui Date: Sat, 21 Mar 2015 13:11:14 +0000 (+0800) Subject: Improve test scripts X-Git-Tag: PRE_PHP7_NSAPI_REMOVAL~563 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=784c60ab6d6096fd8e88ba75f35b5b9ca2377fc3;p=php Improve test scripts --- 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-- '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-- - 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