2022-06-04 12:48:12 +02:00
|
|
|
<?php declare(strict_types=1);
|
2017-01-19 22:23:19 +01:00
|
|
|
|
|
|
|
namespace PhpParser;
|
|
|
|
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
require __DIR__ . '/PhpParser/CodeTestParser.php';
|
|
|
|
require __DIR__ . '/PhpParser/CodeParsingTest.php';
|
|
|
|
|
|
|
|
$dir = __DIR__ . '/code/parser';
|
|
|
|
|
2022-08-29 21:52:53 +02:00
|
|
|
$testParser = new CodeTestParser();
|
|
|
|
$codeParsingTest = new CodeParsingTest();
|
2017-01-19 22:23:19 +01:00
|
|
|
foreach (filesInDir($dir, 'test') as $fileName => $code) {
|
|
|
|
if (false !== strpos($code, '@@{')) {
|
|
|
|
// Skip tests with evaluate segments
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
list($name, $tests) = $testParser->parseTest($code, 2);
|
|
|
|
$newTests = [];
|
|
|
|
foreach ($tests as list($modeLine, list($input, $expected))) {
|
2022-09-02 22:34:15 +02:00
|
|
|
$modes = $codeParsingTest->parseModeLine($modeLine);
|
|
|
|
$parser = $codeParsingTest->createParser($modes['version'] ?? null);
|
|
|
|
list(, $output) = $codeParsingTest->getParseOutput($parser, $input, $modes);
|
2017-01-19 22:23:19 +01:00
|
|
|
$newTests[] = [$modeLine, [$input, $output]];
|
|
|
|
}
|
|
|
|
|
|
|
|
$newCode = $testParser->reconstructTest($name, $newTests);
|
|
|
|
file_put_contents($fileName, $newCode);
|
2018-01-10 15:04:06 -02:00
|
|
|
}
|