Describe the position argument without contrasting it, cover the past-the-end reset

This commit is contained in:
dualfroz committed 2026-09-23 05:46:46 +02:00
1 parent f6e27044ad
commit 35639310c2
2 files changed
+19 -1

No files matched your search

+1 -1
View File
@@ -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
*/
+18
View File
@@ -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