comparison vendor/nikic/php-parser/test/PhpParser/Node/Scalar/StringTest.php @ 0:4c8ae668cc8c

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