Improve test scripts

This commit is contained in:
Xinchen Hui 2015-03-21 21:11:14 +08:00
parent a4529cc0e5
commit 784c60ab6d
3 changed files with 44 additions and 70 deletions

View 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());
}
var_dump($c);
function g($x) {
return "'$x[0]'";
function b() {
return "b";
}
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/" => 'b',
"/b/" => function () { return "c"; },
"/c/" => new Rep,
'/d/' => array("Foo", "rep")), 'a'));
var_dump(preg_replace_callback_array(array('~\A.~' => 'g'), array(array('xyz'))));
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('~\A.~' => create_function('$m', 'return strtolower($m[0]);')), 'ABC'));
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)

View 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

View File

@ -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