-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccca1bd
commit 522c7e2
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\PhpDocParser\Parser; | ||
|
||
use PHPStan\PhpDocParser\Lexer\Lexer; | ||
use PHPUnit\Framework\TestCase; | ||
use const PHP_EOL; | ||
|
||
class TokenIteratorTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @return iterable<array{string, ?string}> | ||
*/ | ||
public function dataGetDetectedNewline(): iterable | ||
{ | ||
yield [ | ||
'/** @param Foo $a */', | ||
null, | ||
]; | ||
|
||
yield [ | ||
'/**' . "\n" . | ||
' * @param Foo $a' . "\n" . | ||
' */', | ||
"\n", | ||
]; | ||
|
||
yield [ | ||
'/**' . "\r\n" . | ||
' * @param Foo $a' . "\r\n" . | ||
' */', | ||
"\r\n", | ||
]; | ||
|
||
yield [ | ||
'/**' . PHP_EOL . | ||
' * @param Foo $a' . PHP_EOL . | ||
' */', | ||
PHP_EOL, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataGetDetectedNewline | ||
*/ | ||
public function testGetDetectedNewline(string $phpDoc, ?string $expectedNewline): void | ||
{ | ||
$lexer = new Lexer(true); | ||
$tokens = new TokenIterator($lexer->tokenize($phpDoc)); | ||
$constExprParser = new ConstExprParser(); | ||
$typeParser = new TypeParser($constExprParser); | ||
$phpDocParser = new PhpDocParser($typeParser, $constExprParser); | ||
$phpDocParser->parse($tokens); | ||
$this->assertSame($expectedNewline, $tokens->getDetectedNewline()); | ||
} | ||
|
||
} |