Describe the position argument without contrasting it, cover the past-the-end reset
This commit is contained in:
1 parent
f6e27044ad
commit
35639310c2
2 files changed
+19
-1
No files matched your search
@@ -114,7 +114,7 @@ abstract class AbstractLexer
|
||||
* Resets the lexer position on the input to the given position.
|
||||
*
|
||||
* @param int $position Character offset into the input, as found in
|
||||
* Token::$position; not an index in the token list.
|
||||
* Token::$position.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -119,6 +119,24 @@ class AbstractLexerTest extends TestCase
|
||||
$this->assertEquals($target, $this->concreteLexer->lookahead);
|
||||
}
|
||||
|
||||
public function testResetPositionPastTheLastToken(): void
|
||||
{
|
||||
$this->concreteLexer->setInput('price=10');
|
||||
|
||||
$tokenCount = 0;
|
||||
while ($this->concreteLexer->moveNext()) {
|
||||
$tokenCount++;
|
||||
}
|
||||
|
||||
$this->assertSame(3, $tokenCount);
|
||||
|
||||
// No token starts at or after this offset, so the lexer lands at the end.
|
||||
$this->concreteLexer->resetPosition(99);
|
||||
|
||||
$this->assertFalse($this->concreteLexer->moveNext());
|
||||
$this->assertNull($this->concreteLexer->lookahead);
|
||||
}
|
||||
|
||||
/** @phpstan-param list<Token<string, string|int>> $expectedTokens */
|
||||
#[DataProvider('dataProvider')]
|
||||
public function testMoveNext(string $input, array $expectedTokens): void
|
||||
|
||||
Reference in new issue
Block a user