StringTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class PHPParser_Tests_Node_Scalar_StringTest extends PHPUnit_Framework_TestCase
  3. {
  4. /**
  5. * @dataProvider provideTestParseEscapeSequences
  6. */
  7. public function testParseEscapeSequences($expected, $string, $quote) {
  8. $this->assertEquals(
  9. $expected,
  10. PHPParser_Node_Scalar_String::parseEscapeSequences($string, $quote)
  11. );
  12. }
  13. /**
  14. * @dataProvider provideTestParse
  15. */
  16. public function testCreate($expected, $string) {
  17. $this->assertEquals(
  18. $expected,
  19. PHPParser_Node_Scalar_String::parse($string)
  20. );
  21. }
  22. public function provideTestParseEscapeSequences() {
  23. return array(
  24. array('"', '\\"', '"'),
  25. array('\\"', '\\"', '`'),
  26. array('\\"\\`', '\\"\\`', null),
  27. array("\\\$\n\r\t\f\v", '\\\\\$\n\r\t\f\v', null),
  28. array("\x1B", '\e', null),
  29. array(chr(255), '\xFF', null),
  30. array(chr(255), '\377', null),
  31. array(chr(0), '\400', null),
  32. array("\0", '\0', null),
  33. array('\xFF', '\\\\xFF', null),
  34. );
  35. }
  36. public function provideTestParse() {
  37. $tests = array(
  38. array('A', '\'A\''),
  39. array('A', 'b\'A\''),
  40. array('A', '"A"'),
  41. array('A', 'b"A"'),
  42. array('\\', '\'\\\\\''),
  43. array('\'', '\'\\\'\''),
  44. );
  45. foreach ($this->provideTestParseEscapeSequences() as $i => $test) {
  46. // skip second and third tests, they aren't for double quotes
  47. if ($i != 1 && $i != 2) {
  48. $tests[] = array($test[0], '"' . $test[1] . '"');
  49. }
  50. }
  51. return $tests;
  52. }
  53. }