generateCorpus.php 931 B

123456789101112131415161718192021222324252627282930
  1. <?php declare(strict_types=1);
  2. $testDir = __DIR__ . '/../../test';
  3. require $testDir . '/bootstrap.php';
  4. require $testDir . '/PhpParser/CodeTestParser.php';
  5. require $testDir . '/PhpParser/CodeParsingTest.php';
  6. $inputDirs = [$testDir . '/code/parser', $testDir . '/code/prettyPrinter'];
  7. if ($argc < 2) {
  8. echo "Usage: php generateCorpus.php dir/";
  9. exit(1);
  10. }
  11. $corpusDir = $argv[1];
  12. if (!is_dir($corpusDir)) {
  13. mkdir($corpusDir, 0777, true);
  14. }
  15. $testParser = new PhpParser\CodeTestParser();
  16. $codeParsingTest = new PhpParser\CodeParsingTest();
  17. foreach ($inputDirs as $inputDir) {
  18. foreach (PhpParser\filesInDir($inputDir, 'test') as $fileName => $code) {
  19. list($_name, $tests) = $testParser->parseTest($code, 2);
  20. foreach ($tests as list($_modeLine, list($input, $_expected))) {
  21. $path = $corpusDir . '/' . md5($input) . '.txt';
  22. file_put_contents($path, $input);
  23. }
  24. }
  25. }