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.
 
 

49 lines
1.7 KiB

<?php
use TypePhp\CompilerTest;
class GeneratedCodeIndentationTest extends \PHPUnit\Framework\TestCase
{
public function testNestedStatementsAndZendWrappersAreConsistentlyIndented(): void
{
global $translator;
$compiler = CompilerTest::create(ROOT_PATH);
$translator = $compiler;
$source = ROOT_PATH . '/phpunit/code/generated-code-indentation.php';
$compiler->addFiles([$source]);
$compiler->prepareFile($source);
$cppFile = $compiler->convertFile($source);
$this->assertNotNull($cppFile);
$code = file_get_contents($cppFile);
$this->assertIsString($code);
$this->assertStringContainsString(
"\t\twhile (tmp_var_0.next()) {\n\t\t\titem = tmp_var_0.value();",
$code,
);
$this->assertStringContainsString(
"\t\t\ttry {\n\t\t\t\tif (",
$code,
);
$this->assertStringContainsString(
"\t\t\t\t} else {\n\t\t\t\t\tif (",
$code,
);
$this->assertStringContainsString(
"\ttry {\n\t\tphp::checkCallArgCount(1, 1, false);",
$code,
);
$this->assertStringNotContainsString("\ntry {", $code);
$this->assertStringNotContainsString("\ncatch (zend_object", $code);
$this->assertDoesNotMatchRegularExpression('/}[ \\t]+}/', $code);
$this->assertStringContainsString(
"php::Var php_generated_empty_function() {\n\treturn php::null;\n}",
$code,
);
$this->assertStringContainsString(
"\tphp::Var value = 1L;\n\n\treturn php::null;\n}",
$code,
);
$this->assertStringNotContainsString('return php::null;}', $code);
}
}