ParserTest.php 1.2 KB

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