TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.1 KiB
66 lines
2.1 KiB
<?php
|
|
|
|
use TypePhp\CompilerTest;
|
|
|
|
final class GeneratedCodeCommentTest extends BaseTest
|
|
{
|
|
private function compileProbe(bool $debug): string
|
|
{
|
|
global $translator;
|
|
|
|
$compiler = CompilerTest::create(ROOT_PATH);
|
|
$translator = $compiler;
|
|
if ($debug) {
|
|
$property = new ReflectionProperty($compiler, 'debug');
|
|
$property->setValue($compiler, true);
|
|
}
|
|
|
|
$source = ROOT_PATH . '/phpunit/code/generated-code-comments.php';
|
|
$compiler->addFiles([$source]);
|
|
$compiler->prepareFile($source);
|
|
$generated = $compiler->convertFile($source);
|
|
$code = file_get_contents($generated);
|
|
self::assertIsString($code);
|
|
return $code;
|
|
}
|
|
|
|
private function compileFile(string $file): string
|
|
{
|
|
global $translator;
|
|
|
|
$compiler = CompilerTest::create(ROOT_PATH);
|
|
$translator = $compiler;
|
|
$source = ROOT_PATH . '/phpunit/code/' . $file;
|
|
$compiler->addFiles([$source]);
|
|
$compiler->prepareFile($source);
|
|
$generated = $compiler->convertFile($source);
|
|
self::assertNotNull($generated);
|
|
$code = file_get_contents($generated);
|
|
self::assertIsString($code);
|
|
return $code;
|
|
}
|
|
|
|
public function testReleaseCodeOmitsCompilerExplanatoryComments(): void
|
|
{
|
|
$code = $this->compileProbe(false);
|
|
|
|
self::assertStringNotContainsString('// Stmt_', $code);
|
|
self::assertStringNotContainsString('// Nullsafe Operator:', $code);
|
|
self::assertStringNotContainsString('// Method Call:', $code);
|
|
}
|
|
|
|
public function testDebugCodeKeepsCompilerExplanatoryComments(): void
|
|
{
|
|
$code = $this->compileProbe(true);
|
|
|
|
self::assertStringContainsString('// Stmt_', $code);
|
|
self::assertStringContainsString('// Nullsafe Operator:', $code);
|
|
}
|
|
|
|
public function testCompileTimeUseDeclarationsDoNotEmitBlankLines(): void
|
|
{
|
|
$code = $this->compileFile('generated-code-use-spacing.php');
|
|
|
|
self::assertDoesNotMatchRegularExpression('/0,};(?:[ \t]*\R){3,}/', $code);
|
|
}
|
|
}
|
|
|