From 0a445c7656203bbef11df086ec63e5d51ca8c266 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 17 Jan 2015 23:46:28 +0100 Subject: [PATCH] Test lexer returning invalid token --- test/PhpParser/ParserTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/PhpParser/ParserTest.php b/test/PhpParser/ParserTest.php index 2839f42..8537594 100644 --- a/test/PhpParser/ParserTest.php +++ b/test/PhpParser/ParserTest.php @@ -114,4 +114,21 @@ EOC; 'endTokenPos' => 18, ), $var->getAttributes()); } -} \ No newline at end of file + + /** + * @expectedException \RangeException + * @expectedExceptionMessage The lexer returned an invalid token (id=999, value=foobar) + */ + public function testInvalidToken() { + $lexer = new InvalidTokenLexer; + $parser = new Parser($lexer); + $parser->parse('dummy'); + } +} + +class InvalidTokenLexer extends Lexer { + public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) { + $value = 'foobar'; + return 999; + } +}