-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpatchRegexpBuilderTest.php
executable file
·82 lines (61 loc) · 1.73 KB
/
patchRegexpBuilderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/php
<?php
namespace s9e\TextFormatter\Tests;
class Test {}
function _array(array $arr)
{
$i = -1;
$php = '[';
foreach ($arr as $k => $v)
{
if (++$i)
{
$php .= ', ';
}
if (!is_numeric($k))
{
$php .= var_export($k, true) . ' => ';
}
$php .= (is_array($v)) ? _array($v) : var_export($v, true);
}
$php .= ']';
return $php;
}
include __DIR__ . '/../tests/Configurator/Helpers/RegexpBuilderTest.php';
$test = new Configurator\Helpers\RegexpBuilderTest;
$php = '';
foreach ($test->getWordsLists() as $k => $case)
{
$regexp = var_export($case[0], true);
$wordlist = _array($case[1]);
$php .= "\n\t/**\n\t* @testdox fromList(" . $wordlist;
if (isset($case[2]))
{
$options = strtr(json_encode($case[2]), [
'{' => '[',
'}' => ']',
',' => ', ',
':' => ' => '
]);
$php .= ', ' . $options . '';
}
// Special case for handling the non-UTF test case
if ($regexp === "'\xC2[\xBC\xBD]'")
{
$regexp = '"\\xC2[\\xBC\\xBD]"';
}
$php .= ") returns " . $regexp . "\n\t*/\n\tpublic function test_" . strtoupper(dechex(crc32(serialize($case)))) . "()\n\t{\n\t\t\$this->fromListTestCase(" . $k . ");\n\t}\n";
}
$filepath = __DIR__ . '/../tests/Configurator/Helpers/RegexpBuilderTest.php';
$oldFile = file_get_contents($filepath);
$startComment = '// Start of content generated by ../../../scripts/patchRegexpBuilderTest.php';
$endComment = "\t// End of content generated by ../../../scripts/patchRegexpBuilderTest.php";
$newFile = substr($oldFile, 0, strpos($oldFile, $startComment) + strlen($startComment))
. $php
. substr($oldFile, strpos($oldFile, $endComment));
if ($newFile !== $oldFile)
{
echo "Patching $filepath\n";
file_put_contents($filepath, $newFile);
}
die("Done.\n");