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