mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
Support !!positions parser test mode
And use it for the group use prefix position test that was previously implemented as a separate test.
This commit is contained in:
parent
b02f8ac07d
commit
098294beec
@ -11,20 +11,28 @@ class CodeParsingTest extends CodeTestAbstract
|
||||
/**
|
||||
* @dataProvider provideTestParse
|
||||
*/
|
||||
public function testParse($name, $code, $expected, $mode) {
|
||||
public function testParse($name, $code, $expected, $modeLine) {
|
||||
if (null !== $modeLine) {
|
||||
$modes = array_fill_keys(explode(',', $modeLine), true);
|
||||
} else {
|
||||
$modes = [];
|
||||
}
|
||||
|
||||
|
||||
$lexer = new Lexer\Emulative(array('usedAttributes' => array(
|
||||
'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments'
|
||||
)));
|
||||
$parser5 = new Parser\Php5($lexer);
|
||||
$parser7 = new Parser\Php7($lexer);
|
||||
|
||||
$output5 = $this->getParseOutput($parser5, $code);
|
||||
$output7 = $this->getParseOutput($parser7, $code);
|
||||
$dumpPositions = isset($modes['positions']);
|
||||
$output5 = $this->getParseOutput($parser5, $code, $dumpPositions);
|
||||
$output7 = $this->getParseOutput($parser7, $code, $dumpPositions);
|
||||
|
||||
if ($mode === 'php5') {
|
||||
if (isset($modes['php5'])) {
|
||||
$this->assertSame($expected, $output5, $name);
|
||||
$this->assertNotSame($expected, $output7, $name);
|
||||
} else if ($mode === 'php7') {
|
||||
} else if (isset($modes['php7'])) {
|
||||
$this->assertNotSame($expected, $output5, $name);
|
||||
$this->assertSame($expected, $output7, $name);
|
||||
} else {
|
||||
@ -33,7 +41,7 @@ class CodeParsingTest extends CodeTestAbstract
|
||||
}
|
||||
}
|
||||
|
||||
private function getParseOutput(Parser $parser, $code) {
|
||||
private function getParseOutput(Parser $parser, $code, $dumpPositions) {
|
||||
$errors = new ErrorHandler\Collecting;
|
||||
$stmts = $parser->parse($code, $errors);
|
||||
|
||||
@ -43,8 +51,8 @@ class CodeParsingTest extends CodeTestAbstract
|
||||
}
|
||||
|
||||
if (null !== $stmts) {
|
||||
$dumper = new NodeDumper(['dumpComments' => true]);
|
||||
$output .= $dumper->dump($stmts);
|
||||
$dumper = new NodeDumper(['dumpComments' => true, 'dumpPositions' => $dumpPositions]);
|
||||
$output .= $dumper->dump($stmts, $code);
|
||||
}
|
||||
|
||||
return canonicalize($output);
|
||||
|
@ -171,17 +171,6 @@ EOC;
|
||||
array("?>\nFoo", ['hasLeadingNewline' => true]),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGroupUsePrefixFileOffsets() {
|
||||
$parser = $this->getParser(new Lexer(
|
||||
['usedAttributes' => ['startFilePos', 'endFilePos']]
|
||||
));
|
||||
$stmts = $parser->parse('<?php use Foo\Bar\{Baz};');
|
||||
/** @var Node\Stmt\GroupUse $groupUse */
|
||||
$groupUse = $stmts[0];
|
||||
$this->assertSame(10, $groupUse->prefix->getAttribute('startFilePos'));
|
||||
$this->assertSame(16, $groupUse->prefix->getAttribute('endFilePos'));
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidTokenLexer extends Lexer {
|
||||
|
28
test/code/parser/stmt/namespace/groupUsePositions.test
Normal file
28
test/code/parser/stmt/namespace/groupUsePositions.test
Normal file
@ -0,0 +1,28 @@
|
||||
Ensure correct file position attributes for group use prefix
|
||||
-----
|
||||
<?php
|
||||
use Foo\Bar\{Baz};
|
||||
-----
|
||||
!!positions
|
||||
array(
|
||||
0: Stmt_GroupUse[2:1 - 2:17](
|
||||
type: TYPE_UNKNOWN (0)
|
||||
prefix: Name[2:5 - 2:11](
|
||||
parts: array(
|
||||
0: Foo
|
||||
1: Bar
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
0: Stmt_UseUse[2:14 - 2:16](
|
||||
type: TYPE_NORMAL (1)
|
||||
name: Name[2:14 - 2:16](
|
||||
parts: array(
|
||||
0: Baz
|
||||
)
|
||||
)
|
||||
alias: Baz
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user