1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Make keyword emulation check case-insensitive

This commit is contained in:
Nikita Popov 2020-09-23 20:19:40 +02:00
parent 88be6127fa
commit b5351f883a
2 changed files with 15 additions and 1 deletions

View File

@ -9,7 +9,7 @@ abstract class KeywordEmulator extends TokenEmulator
public function isEmulationNeeded(string $code): bool
{
return strpos($code, $this->getKeywordString()) !== false;
return strpos(strtolower($code), $this->getKeywordString()) !== false;
}
public function emulate(string $code, array $tokens): array

View File

@ -24,6 +24,17 @@ class EmulativeTest extends LexerTest
$this->assertSame(0, $lexer->getNextToken());
}
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testReplaceKeywordsUppercase($keyword, $expectedToken) {
$lexer = $this->getLexer();
$lexer->startLexing('<?php ' . strtoupper($keyword));
$this->assertSame($expectedToken, $lexer->getNextToken());
$this->assertSame(0, $lexer->getNextToken());
}
/**
* @dataProvider provideTestReplaceKeywords
*/
@ -318,8 +329,11 @@ class EmulativeTest extends LexerTest
return [
['8.0', 'match', [[Tokens::T_MATCH, 'match']]],
['7.4', 'match', [[Tokens::T_STRING, 'match']]],
// Keywords are not case-sensitive.
['7.4', 'fn', [[Tokens::T_FN, 'fn']]],
['7.4', 'FN', [[Tokens::T_FN, 'FN']]],
['7.3', 'fn', [[Tokens::T_STRING, 'fn']]],
['7.3', 'FN', [[Tokens::T_STRING, 'FN']]],
// Tested here to skip testLeaveStuffAloneInStrings.
['8.0', '"$foo?->bar"', [
[ord('"'), '"'],