Skip to content

Commit db7cf2d

Browse files
committed
Test inline @link in Lexer
This test demonstrates that the closing brace in an inline PhpDoc tag is not correctly tokenized and is bundled with the content of the previous token.
1 parent 7adaab7 commit db7cf2d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6988,6 +6988,23 @@ public function testNegatedAssertionToString(): void
69886988
$this->assertSame('@phpstan-assert !Type $param', $assertNode->__toString());
69896989
}
69906990

6991+
/**
6992+
* @dataProvider provideLexerData
6993+
*/
6994+
public function testClosingBraceInlineTag(
6995+
string $input,
6996+
array $expectedTokens,
6997+
): void {
6998+
$tokens = new TokenIterator($this->lexer->tokenize($input));
6999+
$this->assertEquals($expectedTokens, array_map(
7000+
fn ($token) => [
7001+
$token[Lexer::TYPE_OFFSET],
7002+
$token[Lexer::VALUE_OFFSET],
7003+
],
7004+
$tokens->getTokens(),
7005+
));
7006+
}
7007+
69917008
/**
69927009
* @return array<mixed>
69937010
*/
@@ -7664,6 +7681,32 @@ public function dataTextBetweenTagsBelongsToDescription(): iterable
76647681
];
76657682
}
76667683

7684+
public function provideLexerData(): Iterator
7685+
{
7686+
yield ['{@link https://example.com}', [
7687+
[Lexer::TOKEN_OPEN_CURLY_BRACKET, '{'],
7688+
[Lexer::TOKEN_PHPDOC_TAG, '@link'],
7689+
[Lexer::TOKEN_HORIZONTAL_WS, ' '],
7690+
[Lexer::TOKEN_IDENTIFIER, 'https'],
7691+
[Lexer::TOKEN_COLON, ':'],
7692+
[Lexer::TOKEN_OTHER, '//example.com'],
7693+
[Lexer::TOKEN_CLOSE_CURLY_BRACKET, '}'],
7694+
[Lexer::TOKEN_END, ''],
7695+
]];
7696+
7697+
yield ['{@link https://example.com }', [
7698+
[Lexer::TOKEN_OPEN_CURLY_BRACKET, '{'],
7699+
[Lexer::TOKEN_PHPDOC_TAG, '@link'],
7700+
[Lexer::TOKEN_HORIZONTAL_WS, ' '],
7701+
[Lexer::TOKEN_IDENTIFIER, 'https'],
7702+
[Lexer::TOKEN_COLON, ':'],
7703+
[Lexer::TOKEN_OTHER, '//example.com'],
7704+
[Lexer::TOKEN_HORIZONTAL_WS, ' '],
7705+
[Lexer::TOKEN_CLOSE_CURLY_BRACKET, '}'],
7706+
[Lexer::TOKEN_END, ''],
7707+
]];
7708+
}
7709+
76677710
/**
76687711
* @dataProvider dataTextBetweenTagsBelongsToDescription
76697712
*/

0 commit comments

Comments
 (0)