ParserTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace JmesPath\Tests;
  3. use JmesPath\Lexer;
  4. use JmesPath\Parser;
  5. use PHPUnit\Framework\TestCase;
  6. /**
  7. * @covers JmesPath\Parser
  8. */
  9. class ParserTest extends TestCase
  10. {
  11. /**
  12. * @expectedException \JmesPath\SyntaxErrorException
  13. * @expectedExceptionMessage Syntax error at character 0
  14. */
  15. public function testMatchesFirstTokens()
  16. {
  17. $p = new Parser(new Lexer());
  18. $p->parse('.bar');
  19. }
  20. /**
  21. * @expectedException \JmesPath\SyntaxErrorException
  22. * @expectedExceptionMessage Syntax error at character 1
  23. */
  24. public function testThrowsSyntaxErrorForInvalidSequence()
  25. {
  26. $p = new Parser(new Lexer());
  27. $p->parse('a,');
  28. }
  29. /**
  30. * @expectedException \JmesPath\SyntaxErrorException
  31. * @expectedExceptionMessage Syntax error at character 2
  32. */
  33. public function testMatchesAfterFirstToken()
  34. {
  35. $p = new Parser(new Lexer());
  36. $p->parse('a.,');
  37. }
  38. /**
  39. * @expectedException \JmesPath\SyntaxErrorException
  40. * @expectedExceptionMessage Unexpected "eof" token
  41. */
  42. public function testHandlesEmptyExpressions()
  43. {
  44. (new Parser(new Lexer()))->parse('');
  45. }
  46. }