Laravel version update
Laravel version update
This commit is contained in:
282
vendor/nikic/php-parser/test/PhpParser/LexerTest.php
vendored
282
vendor/nikic/php-parser/test/PhpParser/LexerTest.php
vendored
@@ -1,42 +1,51 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser;
|
||||
|
||||
use PhpParser\Parser\Tokens;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LexerTest extends \PHPUnit_Framework_TestCase
|
||||
class LexerTest extends TestCase
|
||||
{
|
||||
/* To allow overwriting in parent class */
|
||||
protected function getLexer(array $options = array()) {
|
||||
protected function getLexer(array $options = []) {
|
||||
return new Lexer($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestError
|
||||
*/
|
||||
public function testError($code, $message) {
|
||||
public function testError($code, $messages) {
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM does not throw warnings from token_get_all()');
|
||||
}
|
||||
|
||||
$lexer = $this->getLexer();
|
||||
try {
|
||||
$lexer->startLexing($code);
|
||||
} catch (Error $e) {
|
||||
$this->assertSame($message, $e->getMessage());
|
||||
$errorHandler = new ErrorHandler\Collecting();
|
||||
$lexer = $this->getLexer(['usedAttributes' => [
|
||||
'comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos'
|
||||
]]);
|
||||
$lexer->startLexing($code, $errorHandler);
|
||||
$errors = $errorHandler->getErrors();
|
||||
|
||||
return;
|
||||
$this->assertCount(count($messages), $errors);
|
||||
for ($i = 0; $i < count($messages); $i++) {
|
||||
$this->assertSame($messages[$i], $errors[$i]->getMessageWithColumnInfo($code));
|
||||
}
|
||||
|
||||
$this->fail('Expected PhpParser\Error');
|
||||
}
|
||||
|
||||
public function provideTestError() {
|
||||
return array(
|
||||
array('<?php /*', 'Unterminated comment on line 1'),
|
||||
array('<?php ' . "\1", 'Unexpected character "' . "\1" . '" (ASCII 1) on unknown line'),
|
||||
array('<?php ' . "\0", 'Unexpected null byte on unknown line'),
|
||||
);
|
||||
return [
|
||||
["<?php /*", ["Unterminated comment from 1:7 to 1:9"]],
|
||||
["<?php \1", ["Unexpected character \"\1\" (ASCII 1) from 1:7 to 1:7"]],
|
||||
["<?php \0", ["Unexpected null byte from 1:7 to 1:7"]],
|
||||
// Error with potentially emulated token
|
||||
["<?php ?? \0", ["Unexpected null byte from 1:10 to 1:10"]],
|
||||
["<?php\n\0\1 foo /* bar", [
|
||||
"Unexpected null byte from 2:1 to 2:1",
|
||||
"Unexpected character \"\1\" (ASCII 1) from 2:2 to 2:2",
|
||||
"Unterminated comment from 2:8 to 2:14"
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,144 +65,151 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
public function provideTestLex() {
|
||||
return array(
|
||||
return [
|
||||
// tests conversion of closing PHP tag and drop of whitespace and opening tags
|
||||
array(
|
||||
[
|
||||
'<?php tokens ?>plaintext',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
[],
|
||||
[
|
||||
[
|
||||
Tokens::T_STRING, 'tokens',
|
||||
array('startLine' => 1), array('endLine' => 1)
|
||||
),
|
||||
array(
|
||||
['startLine' => 1], ['endLine' => 1]
|
||||
],
|
||||
[
|
||||
ord(';'), '?>',
|
||||
array('startLine' => 1), array('endLine' => 1)
|
||||
),
|
||||
array(
|
||||
['startLine' => 1], ['endLine' => 1]
|
||||
],
|
||||
[
|
||||
Tokens::T_INLINE_HTML, 'plaintext',
|
||||
array('startLine' => 1), array('endLine' => 1)
|
||||
),
|
||||
)
|
||||
),
|
||||
['startLine' => 1, 'hasLeadingNewline' => false],
|
||||
['endLine' => 1]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests line numbers
|
||||
array(
|
||||
[
|
||||
'<?php' . "\n" . '$ token /** doc' . "\n" . 'comment */ $',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
[],
|
||||
[
|
||||
[
|
||||
ord('$'), '$',
|
||||
array('startLine' => 2), array('endLine' => 2)
|
||||
),
|
||||
array(
|
||||
['startLine' => 2], ['endLine' => 2]
|
||||
],
|
||||
[
|
||||
Tokens::T_STRING, 'token',
|
||||
array('startLine' => 2), array('endLine' => 2)
|
||||
),
|
||||
array(
|
||||
['startLine' => 2], ['endLine' => 2]
|
||||
],
|
||||
[
|
||||
ord('$'), '$',
|
||||
array(
|
||||
[
|
||||
'startLine' => 3,
|
||||
'comments' => array(
|
||||
new Comment\Doc('/** doc' . "\n" . 'comment */', 2, 14),
|
||||
)
|
||||
),
|
||||
array('endLine' => 3)
|
||||
),
|
||||
)
|
||||
),
|
||||
'comments' => [
|
||||
new Comment\Doc('/** doc' . "\n" . 'comment */', 2, 14, 5),
|
||||
]
|
||||
],
|
||||
['endLine' => 3]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests comment extraction
|
||||
array(
|
||||
[
|
||||
'<?php /* comment */ // comment' . "\n" . '/** docComment 1 *//** docComment 2 */ token',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
[],
|
||||
[
|
||||
[
|
||||
Tokens::T_STRING, 'token',
|
||||
array(
|
||||
[
|
||||
'startLine' => 2,
|
||||
'comments' => array(
|
||||
new Comment('/* comment */', 1, 6),
|
||||
new Comment('// comment' . "\n", 1, 20),
|
||||
new Comment\Doc('/** docComment 1 */', 2, 31),
|
||||
new Comment\Doc('/** docComment 2 */', 2, 50),
|
||||
),
|
||||
),
|
||||
array('endLine' => 2)
|
||||
),
|
||||
)
|
||||
),
|
||||
'comments' => [
|
||||
new Comment('/* comment */', 1, 6, 1),
|
||||
new Comment('// comment' . "\n", 1, 20, 3),
|
||||
new Comment\Doc('/** docComment 1 */', 2, 31, 4),
|
||||
new Comment\Doc('/** docComment 2 */', 2, 50, 5),
|
||||
],
|
||||
],
|
||||
['endLine' => 2]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests differing start and end line
|
||||
array(
|
||||
[
|
||||
'<?php "foo' . "\n" . 'bar"',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
[],
|
||||
[
|
||||
[
|
||||
Tokens::T_CONSTANT_ENCAPSED_STRING, '"foo' . "\n" . 'bar"',
|
||||
array('startLine' => 1), array('endLine' => 2)
|
||||
),
|
||||
)
|
||||
),
|
||||
['startLine' => 1], ['endLine' => 2]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests exact file offsets
|
||||
array(
|
||||
[
|
||||
'<?php "a";' . "\n" . '// foo' . "\n" . '"b";',
|
||||
array('usedAttributes' => array('startFilePos', 'endFilePos')),
|
||||
array(
|
||||
array(
|
||||
['usedAttributes' => ['startFilePos', 'endFilePos']],
|
||||
[
|
||||
[
|
||||
Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"',
|
||||
array('startFilePos' => 6), array('endFilePos' => 8)
|
||||
),
|
||||
array(
|
||||
['startFilePos' => 6], ['endFilePos' => 8]
|
||||
],
|
||||
[
|
||||
ord(';'), ';',
|
||||
array('startFilePos' => 9), array('endFilePos' => 9)
|
||||
),
|
||||
array(
|
||||
['startFilePos' => 9], ['endFilePos' => 9]
|
||||
],
|
||||
[
|
||||
Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"',
|
||||
array('startFilePos' => 18), array('endFilePos' => 20)
|
||||
),
|
||||
array(
|
||||
['startFilePos' => 18], ['endFilePos' => 20]
|
||||
],
|
||||
[
|
||||
ord(';'), ';',
|
||||
array('startFilePos' => 21), array('endFilePos' => 21)
|
||||
),
|
||||
)
|
||||
),
|
||||
['startFilePos' => 21], ['endFilePos' => 21]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests token offsets
|
||||
array(
|
||||
[
|
||||
'<?php "a";' . "\n" . '// foo' . "\n" . '"b";',
|
||||
array('usedAttributes' => array('startTokenPos', 'endTokenPos')),
|
||||
array(
|
||||
array(
|
||||
['usedAttributes' => ['startTokenPos', 'endTokenPos']],
|
||||
[
|
||||
[
|
||||
Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"',
|
||||
array('startTokenPos' => 1), array('endTokenPos' => 1)
|
||||
),
|
||||
array(
|
||||
['startTokenPos' => 1], ['endTokenPos' => 1]
|
||||
],
|
||||
[
|
||||
ord(';'), ';',
|
||||
array('startTokenPos' => 2), array('endTokenPos' => 2)
|
||||
),
|
||||
array(
|
||||
['startTokenPos' => 2], ['endTokenPos' => 2]
|
||||
],
|
||||
[
|
||||
Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"',
|
||||
array('startTokenPos' => 5), array('endTokenPos' => 5)
|
||||
),
|
||||
array(
|
||||
['startTokenPos' => 5], ['endTokenPos' => 5]
|
||||
],
|
||||
[
|
||||
ord(';'), ';',
|
||||
array('startTokenPos' => 6), array('endTokenPos' => 6)
|
||||
),
|
||||
)
|
||||
),
|
||||
['startTokenPos' => 6], ['endTokenPos' => 6]
|
||||
],
|
||||
]
|
||||
],
|
||||
// tests all attributes being disabled
|
||||
array(
|
||||
[
|
||||
'<?php /* foo */ $bar;',
|
||||
array('usedAttributes' => array()),
|
||||
array(
|
||||
array(
|
||||
['usedAttributes' => []],
|
||||
[
|
||||
[
|
||||
Tokens::T_VARIABLE, '$bar',
|
||||
array(), array()
|
||||
),
|
||||
array(
|
||||
[], []
|
||||
],
|
||||
[
|
||||
ord(';'), ';',
|
||||
array(), array()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
[], []
|
||||
]
|
||||
]
|
||||
],
|
||||
// tests no tokens
|
||||
[
|
||||
'',
|
||||
[],
|
||||
[]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,13 +226,13 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
public function provideTestHaltCompiler() {
|
||||
return array(
|
||||
array('<?php ... __halt_compiler();Remaining Text', 'Remaining Text'),
|
||||
array('<?php ... __halt_compiler ( ) ;Remaining Text', 'Remaining Text'),
|
||||
array('<?php ... __halt_compiler() ?>Remaining Text', 'Remaining Text'),
|
||||
return [
|
||||
['<?php ... __halt_compiler();Remaining Text', 'Remaining Text'],
|
||||
['<?php ... __halt_compiler ( ) ;Remaining Text', 'Remaining Text'],
|
||||
['<?php ... __halt_compiler() ?>Remaining Text', 'Remaining Text'],
|
||||
//array('<?php ... __halt_compiler();' . "\0", "\0"),
|
||||
//array('<?php ... __halt_compiler /* */ ( ) ;Remaining Text', 'Remaining Text'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,15 +249,15 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetTokens() {
|
||||
$code = '<?php "a";' . "\n" . '// foo' . "\n" . '"b";';
|
||||
$expectedTokens = array(
|
||||
array(T_OPEN_TAG, '<?php ', 1),
|
||||
array(T_CONSTANT_ENCAPSED_STRING, '"a"', 1),
|
||||
$expectedTokens = [
|
||||
[T_OPEN_TAG, '<?php ', 1],
|
||||
[T_CONSTANT_ENCAPSED_STRING, '"a"', 1],
|
||||
';',
|
||||
array(T_WHITESPACE, "\n", 1),
|
||||
array(T_COMMENT, '// foo' . "\n", 2),
|
||||
array(T_CONSTANT_ENCAPSED_STRING, '"b"', 3),
|
||||
[T_WHITESPACE, "\n", 1],
|
||||
[T_COMMENT, '// foo' . "\n", 2],
|
||||
[T_CONSTANT_ENCAPSED_STRING, '"b"', 3],
|
||||
';',
|
||||
);
|
||||
];
|
||||
|
||||
$lexer = $this->getLexer();
|
||||
$lexer->startLexing($code);
|
||||
|
Reference in New Issue
Block a user