Chris@13: getLexer(); Chris@0: $lexer->startLexing('assertSame($expectedToken, $lexer->getNextToken()); Chris@0: $this->assertSame(0, $lexer->getNextToken()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider provideTestReplaceKeywords Chris@0: */ Chris@0: public function testNoReplaceKeywordsAfterObjectOperator($keyword) { Chris@0: $lexer = $this->getLexer(); Chris@0: $lexer->startLexing('' . $keyword); Chris@0: Chris@0: $this->assertSame(Tokens::T_OBJECT_OPERATOR, $lexer->getNextToken()); Chris@0: $this->assertSame(Tokens::T_STRING, $lexer->getNextToken()); Chris@0: $this->assertSame(0, $lexer->getNextToken()); Chris@0: } Chris@0: Chris@0: public function provideTestReplaceKeywords() { Chris@13: return [ Chris@0: // PHP 5.5 Chris@13: ['finally', Tokens::T_FINALLY], Chris@13: ['yield', Tokens::T_YIELD], Chris@0: Chris@0: // PHP 5.4 Chris@13: ['callable', Tokens::T_CALLABLE], Chris@13: ['insteadof', Tokens::T_INSTEADOF], Chris@13: ['trait', Tokens::T_TRAIT], Chris@13: ['__TRAIT__', Tokens::T_TRAIT_C], Chris@0: Chris@0: // PHP 5.3 Chris@13: ['__DIR__', Tokens::T_DIR], Chris@13: ['goto', Tokens::T_GOTO], Chris@13: ['namespace', Tokens::T_NAMESPACE], Chris@13: ['__NAMESPACE__', Tokens::T_NS_C], Chris@13: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider provideTestLexNewFeatures Chris@0: */ Chris@0: public function testLexNewFeatures($code, array $expectedTokens) { Chris@0: $lexer = $this->getLexer(); Chris@0: $lexer->startLexing('getNextToken($text)) { Chris@17: $tokens[] = [$token, $text]; Chris@0: } Chris@17: $this->assertSame($expectedTokens, $tokens); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider provideTestLexNewFeatures Chris@0: */ Chris@0: public function testLeaveStuffAloneInStrings($code) { Chris@0: $stringifiedToken = '"' . addcslashes($code, '"\\') . '"'; Chris@0: Chris@0: $lexer = $this->getLexer(); Chris@0: $lexer->startLexing('assertSame(Tokens::T_CONSTANT_ENCAPSED_STRING, $lexer->getNextToken($text)); Chris@0: $this->assertSame($stringifiedToken, $text); Chris@0: $this->assertSame(0, $lexer->getNextToken()); Chris@0: } Chris@0: Chris@17: /** Chris@17: * @dataProvider provideTestLexNewFeatures Chris@17: */ Chris@17: public function testErrorAfterEmulation($code) { Chris@17: $errorHandler = new ErrorHandler\Collecting; Chris@17: $lexer = $this->getLexer([]); Chris@17: $lexer->startLexing('getErrors(); Chris@17: $this->assertCount(1, $errors); Chris@17: Chris@17: $error = $errors[0]; Chris@17: $this->assertSame('Unexpected null byte', $error->getRawMessage()); Chris@17: Chris@17: $attrs = $error->getAttributes(); Chris@17: $expPos = strlen('assertSame($expPos, $attrs['startFilePos']); Chris@17: $this->assertSame($expPos, $attrs['endFilePos']); Chris@17: $this->assertSame($expLine, $attrs['startLine']); Chris@17: $this->assertSame($expLine, $attrs['endLine']); Chris@17: } Chris@17: Chris@0: public function provideTestLexNewFeatures() { Chris@13: return [ Chris@17: // PHP 7.4 Chris@17: ['??=', [ Chris@17: [Tokens::T_COALESCE_EQUAL, '??='], Chris@17: ]], Chris@13: ['yield from', [ Chris@13: [Tokens::T_YIELD_FROM, 'yield from'], Chris@13: ]], Chris@13: ["yield\r\nfrom", [ Chris@13: [Tokens::T_YIELD_FROM, "yield\r\nfrom"], Chris@13: ]], Chris@13: ['...', [ Chris@13: [Tokens::T_ELLIPSIS, '...'], Chris@13: ]], Chris@13: ['**', [ Chris@13: [Tokens::T_POW, '**'], Chris@13: ]], Chris@13: ['**=', [ Chris@13: [Tokens::T_POW_EQUAL, '**='], Chris@13: ]], Chris@13: ['??', [ Chris@13: [Tokens::T_COALESCE, '??'], Chris@13: ]], Chris@13: ['<=>', [ Chris@13: [Tokens::T_SPACESHIP, '<=>'], Chris@13: ]], Chris@13: ['0b1010110', [ Chris@13: [Tokens::T_LNUMBER, '0b1010110'], Chris@13: ]], Chris@13: ['0b1011010101001010110101010010101011010101010101101011001110111100', [ Chris@13: [Tokens::T_DNUMBER, '0b1011010101001010110101010010101011010101010101101011001110111100'], Chris@13: ]], Chris@13: ['\\', [ Chris@13: [Tokens::T_NS_SEPARATOR, '\\'], Chris@13: ]], Chris@13: ["<<<'NOWDOC'\nNOWDOC;\n", [ Chris@13: [Tokens::T_START_HEREDOC, "<<<'NOWDOC'\n"], Chris@13: [Tokens::T_END_HEREDOC, 'NOWDOC'], Chris@13: [ord(';'), ';'], Chris@13: ]], Chris@13: ["<<<'NOWDOC'\nFoobar\nNOWDOC;\n", [ Chris@13: [Tokens::T_START_HEREDOC, "<<<'NOWDOC'\n"], Chris@13: [Tokens::T_ENCAPSED_AND_WHITESPACE, "Foobar\n"], Chris@13: [Tokens::T_END_HEREDOC, 'NOWDOC'], Chris@13: [ord(';'), ';'], Chris@13: ]], Chris@17: Chris@17: // Flexible heredoc/nowdoc Chris@17: ["<<