diff --git a/src/AbstractLexer.php b/src/AbstractLexer.php index 20988d2..de7c62d 100644 --- a/src/AbstractLexer.php +++ b/src/AbstractLexer.php @@ -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 */ diff --git a/tests/AbstractLexerTest.php b/tests/AbstractLexerTest.php index 8b9d12e..d4a5003 100644 --- a/tests/AbstractLexerTest.php +++ b/tests/AbstractLexerTest.php @@ -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> $expectedTokens */ #[DataProvider('dataProvider')] public function testMoveNext(string $input, array $expectedTokens): void