菜谱项目

StringTest.php 1.8KB

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