|
1 | | -const parser = require('../main'); |
| 1 | +const parser = require("../main"); |
2 | 2 |
|
3 | 3 | describe("Test variables", function() { |
4 | 4 | it("fix 253 - can't be parsed `global` with multiple `$`", function() { |
5 | | - expect(parser.parseEval(` |
| 5 | + expect( |
| 6 | + parser.parseEval(` |
6 | 7 | global $$foo; |
7 | | - ` |
8 | | - )).toMatchSnapshot(); |
| 8 | + `) |
| 9 | + ).toMatchSnapshot(); |
9 | 10 | }); |
10 | 11 |
|
11 | 12 | it("fix 248 - broken ast for `$$$$$`", function() { |
12 | | - expect(parser.parseEval(` |
| 13 | + expect( |
| 14 | + parser.parseEval(` |
13 | 15 | $foo::$$property; |
14 | 16 | $foo::\${$property}; |
15 | 17 | $bar->$$property; |
16 | 18 | $bar->\${$property}; |
17 | | - ` |
18 | | - )).toMatchSnapshot(); |
| 19 | + `) |
| 20 | + ).toMatchSnapshot(); |
19 | 21 | }); |
20 | | - |
| 22 | + |
21 | 23 | it("fix 248 - test curly", function() { |
22 | | - expect(parser.parseEval(` |
| 24 | + expect( |
| 25 | + parser.parseEval(` |
23 | 26 | $bar->{$property->foo}; |
24 | 27 | $bar->\${$property}; |
25 | 28 | $bar->foo_{$property}; |
26 | | - ` |
27 | | - )).toMatchSnapshot(); |
| 29 | + `) |
| 30 | + ).toMatchSnapshot(); |
28 | 31 | }); |
29 | 32 |
|
30 | | - |
31 | 33 | it("array destructuring", function() { |
32 | 34 | expect(parser.parseEval("[$id1, $name1] = $data[0];")).toMatchSnapshot(); |
33 | 35 | }); |
34 | 36 |
|
35 | 37 | it("default variables", function() { |
36 | | - expect(parser.parseEval(` |
| 38 | + expect( |
| 39 | + parser.parseEval(` |
37 | 40 | $a = "foo"; |
38 | 41 | $b = &$c; |
39 | | - $a->b = true;` |
40 | | - )).toMatchSnapshot(); |
| 42 | + $a->b = true;`) |
| 43 | + ).toMatchSnapshot(); |
41 | 44 | }); |
42 | 45 |
|
43 | 46 | it("Variable chains", function() { |
44 | 47 | expect(parser.parseEval("foo::$a[1][2];")).toMatchSnapshot(); |
45 | 48 | }); |
46 | 49 |
|
47 | 50 | it("fix #167", function() { |
48 | | - expect(parser.parseEval("$var = Foo::{$bar['baz']}();Foo::$bar['baz']();")).toMatchSnapshot(); |
| 51 | + expect( |
| 52 | + parser.parseEval("$var = Foo::{$bar['baz']}();Foo::$bar['baz']();") |
| 53 | + ).toMatchSnapshot(); |
49 | 54 | }); |
50 | 55 |
|
51 | 56 | it("valid offset lookup", function() { |
52 | | - expect(parser.parseEval("get_class($var)::$$$$$property;")).toMatchSnapshot(); |
| 57 | + expect( |
| 58 | + parser.parseEval("get_class($var)::$$$$$property;") |
| 59 | + ).toMatchSnapshot(); |
53 | 60 | }); |
54 | 61 |
|
55 | | - it('fix #185', function() { |
56 | | - expect(parser.parseEval(` |
| 62 | + it("fix #185", function() { |
| 63 | + expect( |
| 64 | + parser.parseEval(` |
57 | 65 | $var = ($var[0])::foo; |
58 | 66 | $var = ($var[0][1])::foo; |
59 | 67 | $var = ($var[0])[1]::foo; |
60 | 68 | $var = (($var[0])[1])::foo; |
61 | 69 | $var = (new Foo())::bar; |
62 | 70 | get_class($this->resource)::$wrap; |
63 | | - `)).toMatchSnapshot(); |
64 | | - |
| 71 | + `) |
| 72 | + ).toMatchSnapshot(); |
65 | 73 | }); |
66 | 74 |
|
67 | | - |
68 | 75 | it("Class constants", function() { |
69 | | - expect(parser.parseEval(` |
| 76 | + expect( |
| 77 | + parser.parseEval(` |
70 | 78 | static::foo(); |
71 | 79 | self::foo(); |
72 | 80 | parent::foo(); |
73 | 81 | foo::class; |
74 | 82 | $this->foo(); |
75 | 83 | foo::$bar; |
76 | | - $this->foo::bar["baz"]::qux();` |
77 | | - )).toMatchSnapshot(); |
| 84 | + $this->foo::bar["baz"]::qux();`) |
| 85 | + ).toMatchSnapshot(); |
78 | 86 | }); |
79 | 87 |
|
80 | 88 | it("Encaps var offset", function() { |
81 | | - expect(parser.parseEval(` |
| 89 | + expect( |
| 90 | + parser.parseEval(` |
82 | 91 | $a = "{$a[1]}"; |
83 | 92 | $a = "{$a["a"]}"; |
84 | | - $a = "{$a[$b]}";` |
85 | | - )).toMatchSnapshot(); |
| 93 | + $a = "{$a[$b]}";`) |
| 94 | + ).toMatchSnapshot(); |
86 | 95 | }); |
87 | 96 |
|
88 | 97 | it("Chained encapsed vars", function() { |
89 | | - expect(parser.parseEval( |
90 | | - ` |
| 98 | + expect( |
| 99 | + parser.parseEval( |
| 100 | + ` |
91 | 101 | $a = "{$a->foo()[$bar[$foo]]}"; |
92 | 102 | ` |
93 | | - )).toMatchSnapshot(); |
| 103 | + ) |
| 104 | + ).toMatchSnapshot(); |
94 | 105 | }); |
95 | 106 |
|
96 | 107 | it("Dynamic variables", function() { |
97 | | - expect(parser.parseEval(` |
| 108 | + expect( |
| 109 | + parser.parseEval(` |
98 | 110 | $$a = "bar"; |
99 | 111 | $$$a = "bar"; |
100 | 112 | \${$a."bar"} = "bar"; |
101 | 113 | $foo{$a."bar"} = "bar"; |
102 | | - `)).toMatchSnapshot(); |
| 114 | + `) |
| 115 | + ).toMatchSnapshot(); |
103 | 116 | }); |
104 | 117 |
|
105 | 118 | describe("Check errors", function() { |
106 | 119 | it("should be ?", function() { |
107 | | - expect(parser.parseEval("$? = true;", { |
108 | | - parser: { |
109 | | - suppressErrors: true |
110 | | - } |
111 | | - })).toMatchSnapshot(); |
| 120 | + expect( |
| 121 | + parser.parseEval("$? = true;", { |
| 122 | + parser: { |
| 123 | + suppressErrors: true |
| 124 | + } |
| 125 | + }) |
| 126 | + ).toMatchSnapshot(); |
112 | 127 | }); |
113 | 128 |
|
114 | 129 | it("should fail on double static lookup", function() { |
115 | | - expect(parser.parseEval(["this->foo::bar::baz;"].join("\n"), { |
116 | | - parser: { |
117 | | - suppressErrors: true |
118 | | - } |
119 | | - })).toMatchSnapshot(); |
| 130 | + expect( |
| 131 | + parser.parseEval(["this->foo::bar::baz;"].join("\n"), { |
| 132 | + parser: { |
| 133 | + suppressErrors: true |
| 134 | + } |
| 135 | + }) |
| 136 | + ).toMatchSnapshot(); |
120 | 137 | }); |
121 | 138 |
|
122 | 139 | it("should fail on property lookup on static lookup", function() { |
123 | | - expect(parser.parseEval(["$this->foo::bar->baz;"].join("\n"), { |
124 | | - parser: { |
125 | | - suppressErrors: true |
126 | | - } |
127 | | - })).toMatchSnapshot(); |
| 140 | + expect( |
| 141 | + parser.parseEval(["$this->foo::bar->baz;"].join("\n"), { |
| 142 | + parser: { |
| 143 | + suppressErrors: true |
| 144 | + } |
| 145 | + }) |
| 146 | + ).toMatchSnapshot(); |
128 | 147 | }); |
129 | 148 |
|
130 | 149 | it("should fail $foo->bar::!", function() { |
131 | | - expect(parser.parseEval("$foo->bar::!", { |
132 | | - parser: { |
133 | | - suppressErrors: true |
134 | | - } |
135 | | - })).toMatchSnapshot(); |
| 150 | + expect( |
| 151 | + parser.parseEval("$foo->bar::!", { |
| 152 | + parser: { |
| 153 | + suppressErrors: true |
| 154 | + } |
| 155 | + }) |
| 156 | + ).toMatchSnapshot(); |
136 | 157 | }); |
137 | 158 |
|
138 | 159 | it("should fail foo::bar::baz", function() { |
139 | | - expect(parser.parseEval("foo::bar::baz", { |
140 | | - parser: { |
141 | | - suppressErrors: true |
142 | | - } |
143 | | - })).toMatchSnapshot(); |
| 160 | + expect( |
| 161 | + parser.parseEval("foo::bar::baz", { |
| 162 | + parser: { |
| 163 | + suppressErrors: true |
| 164 | + } |
| 165 | + }) |
| 166 | + ).toMatchSnapshot(); |
144 | 167 | }); |
145 | 168 | }); |
| 169 | + |
| 170 | + it("simple variable", function() { |
| 171 | + expect(parser.parseEval("$var = $var;")).toMatchSnapshot(); |
| 172 | + }); |
| 173 | + it("simple variable #2", function() { |
| 174 | + expect(parser.parseEval("$var = ${$var};")).toMatchSnapshot(); |
| 175 | + }); |
| 176 | + it("simple variable #3", function() { |
| 177 | + expect(parser.parseEval("$var = ${$var + 'foo'};")).toMatchSnapshot(); |
| 178 | + }); |
| 179 | + it("simple variable #4", function() { |
| 180 | + expect(parser.parseEval("$var = $$$var;")).toMatchSnapshot(); |
| 181 | + }); |
146 | 182 | }); |
0 commit comments