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