Replace /e modifier with callback + eval()

As this also fixes the overescaping issue, some stuff in the tests can be written more nicely now.
This commit is contained in:
nikic 2012-03-02 00:28:46 +01:00
parent 48f089a111
commit 0c0515c7de
2 changed files with 10 additions and 2 deletions

View File

@ -51,7 +51,11 @@ class PHPParser_Tests_codeTest extends PHPUnit_Framework_TestCase
$fileContents = file_get_contents($file);
// evaluate @@{expr}@@ expressions
$fileContents = preg_replace('/@@\{(.*?)\}@@/e', '$1', $fileContents);
$fileContents = preg_replace_callback(
'/@@\{(.*?)\}@@/',
array($this, 'evalCallback'),
$fileContents
);
// parse sections
$parts = array_map('trim', explode('-----', $fileContents));
@ -78,4 +82,8 @@ class PHPParser_Tests_codeTest extends PHPUnit_Framework_TestCase
// trim right side of all lines
return implode("\n", array_map('rtrim', explode("\n", $str)));
}
protected function evalCallback($matches) {
return eval('return ' . $matches[1] . ';');
}
}

View File

@ -45,7 +45,7 @@ array(
9: Scalar_String(
value: !"!\!$!
!
!@@{ chr(9) }@@!@@{ chr(12) }@@!@@{ chr(11) }@@!@@{ chr(27) }@@!\a
!@@{ "\t" }@@!@@{ "\f" }@@!@@{ "\v" }@@!@@{ chr(27) /* "\e" */ }@@!\a
)
10: Scalar_String(
value: !@@{ chr(255) }@@!@@{ chr(255) }@@!@@{ chr(0) }@@!@@{ chr(0) }@@!