Fix a warning

This commit is contained in:
Fabien Potencier
2024-04-24 08:00:09 +02:00
parent 12625c0c05
commit ccc20cbd1b
2 changed files with 24 additions and 1 deletions
+1 -1
View File
@@ -321,7 +321,7 @@ class Lexer
$this->moveCursor('...');
}
// arrow function
elseif ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) {
elseif ('=' === $this->code[$this->cursor] && ($this->cursor + 1 < $this->end) && '>' === $this->code[$this->cursor + 1]) {
$this->pushToken(Token::ARROW_TYPE, '=>');
$this->moveCursor('=>');
}
+23
View File
@@ -378,4 +378,27 @@ bar
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
/**
* @dataProvider getTemplateForErrorsAtTheEndOfTheStream
*/
public function testErrorsAtTheEndOfTheStream(string $template)
{
$lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class)));
set_error_handler(function () {
$this->fail('Lexer should not emit warnings.');
});
try {
$lexer->tokenize(new Source($template, 'index'));
$this->addToAssertionCount(1);
} finally {
restore_error_handler();
}
}
public function getTemplateForErrorsAtTheEndOfTheStream()
{
yield ['{{ ='];
yield ['{{ ..'];
}
}