Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / nikic / php-parser / test / code / formatPreservation / listInsertion.test
1 Insertion into list nodes
2 -----
3 <?php
4 $foo;
5
6 $bar;
7 -----
8 $stmts[] = new Stmt\Expression(new Expr\Variable('baz'));
9 -----
10 <?php
11 $foo;
12
13 $bar;
14 $baz;
15 -----
16 <?php
17
18 function test() {
19     $foo;
20
21     $bar;
22 }
23 -----
24 $stmts[0]->stmts[] = new Stmt\Expression(new Expr\Variable('baz'));
25 -----
26 <?php
27
28 function test() {
29     $foo;
30
31     $bar;
32     $baz;
33 }
34 -----
35 <?php
36
37 function test(Foo     $param1) {}
38 -----
39 $stmts[0]->params[] = new Node\Param(new Expr\Variable('param2'));
40 -----
41 <?php
42
43 function test(Foo     $param1, $param2) {}
44 -----
45 <?php
46
47 try {
48     /* stuff */
49 } catch
50 (Foo $x) {}
51 -----
52 $stmts[0]->catches[0]->types[] = new Node\Name('Bar');
53 -----
54 <?php
55
56 try {
57     /* stuff */
58 } catch
59 (Foo|Bar $x) {}
60 -----
61 <?php
62
63 function test(Foo     $param1) {}
64 -----
65 array_unshift($stmts[0]->params, new Node\Param(new Expr\Variable('param0')));
66 -----
67 <?php
68
69 function test($param0, Foo     $param1) {}
70 -----
71 <?php
72
73 function test() {}
74 -----
75 $stmts[0]->params[] = new Node\Param(new Expr\Variable('param0'));
76 /* Insertion into empty list not handled yet */
77 -----
78 <?php
79
80 function test($param0)
81 {
82 }
83 -----
84 <?php
85
86 if ($cond) {
87 } elseif ($cond2) {
88 }
89 -----
90 $stmts[0]->elseifs[] = new Stmt\ElseIf_(new Expr\Variable('cond3'), []);
91 -----
92 <?php
93
94 if ($cond) {
95 } elseif ($cond2) {
96 } elseif ($cond3) {
97 }
98 -----
99 <?php
100
101 try {
102 } catch (Foo $foo) {
103 }
104 -----
105 $stmts[0]->catches[] = new Stmt\Catch_([new Node\Name('Bar')], new Expr\Variable('bar'), []);
106 -----
107 <?php
108
109 try {
110 } catch (Foo $foo) {
111 } catch (Bar $bar) {
112 }
113 -----
114 <?php
115 $foo; $bar;
116 -----
117 $node = new Stmt\Expression(new Expr\Variable('baz'));
118 $node->setAttribute('comments', [new Comment('// Test')]);
119 $stmts[] = $node;
120 -----
121 <?php
122 $foo; $bar;
123 // Test
124 $baz;
125 -----
126 <?php
127 function test() {
128     $foo; $bar;
129 }
130 -----
131 $node = new Stmt\Expression(new Expr\Variable('baz'));
132 $node->setAttribute('comments', [new Comment('// Test'), new Comment('// Test 2')]);
133 $stmts[0]->stmts[] = $node;
134 -----
135 <?php
136 function test() {
137     $foo; $bar;
138     // Test
139     // Test 2
140     $baz;
141 }
142 -----
143 <?php
144 namespace
145 Foo;
146 -----
147 $stmts[0]->name->parts[0] = 'Xyz';
148 -----
149 <?php
150 namespace
151 Xyz;
152 -----
153 <?php
154 function test() {
155     $foo; $bar;
156 }
157 -----
158 $node = new Stmt\Expression(new Expr\Variable('baz'));
159 array_unshift($stmts[0]->stmts, $node);
160 -----
161 <?php
162 function test() {
163     $baz;
164     $foo; $bar;
165 }
166 -----
167 <?php
168 function test() {
169     $foo; $bar;
170 }
171 -----
172 $node = new Stmt\Expression(new Expr\Variable('baz'));
173 $node->setAttribute('comments', [new Comment('// Test')]);
174 array_unshift($stmts[0]->stmts, $node);
175 -----
176 <?php
177 function test() {
178     // Test
179     $baz;
180     $foo; $bar;
181 }
182 -----
183 <?php
184 function test() {
185
186     // Foo bar
187     $foo; $bar;
188 }
189 -----
190 $node = new Stmt\Expression(new Expr\Variable('baz'));
191 $node->setAttribute('comments', [new Comment('// Test')]);
192 array_unshift($stmts[0]->stmts, $node);
193 -----
194 <?php
195 function test() {
196
197     // Test
198     $baz;
199     // Foo bar
200     $foo; $bar;
201 }
202 -----
203 <?php
204 function test() {
205
206     // Foo bar
207     $foo; $bar;
208 }
209 -----
210 $node = new Stmt\Expression(new Expr\Variable('baz'));
211 $node->setAttribute('comments', [new Comment('// Test')]);
212 array_unshift($stmts[0]->stmts, $node);
213 $stmts[0]->stmts[1]->setAttribute('comments', [new Comment('// Bar foo')]);
214 -----
215 <?php
216 function test() {
217
218     // Test
219     $baz;
220     // Bar foo
221     $foo; $bar;
222 }
223 -----
224 <?php
225 function test() {
226
227     // Foo bar
228     $foo; $bar;
229 }
230 -----
231 $node = new Stmt\Expression(new Expr\Variable('baz'));
232 $node->setAttribute('comments', [new Comment('// Test')]);
233 array_unshift($stmts[0]->stmts, $node);
234 $stmts[0]->stmts[1]->setAttribute('comments', []);
235 -----
236 <?php
237 function test() {
238
239     // Test
240     $baz;
241     $foo; $bar;
242 }
243 -----
244 <?php
245 function test() {
246
247     // Foo bar
248     $foo; $bar;
249 }
250 -----
251 array_unshift(
252     $stmts[0]->stmts,
253     new Stmt\Expression(new Expr\Variable('a')),
254     new Stmt\Expression(new Expr\Variable('b')));
255 -----
256 <?php
257 function test() {
258
259     $a;
260     $b;
261     // Foo bar
262     $foo; $bar;
263 }
264 -----
265 <?php
266 function test() {}
267 -----
268 /* Insertion into empty list not handled yet */
269 $stmts[0]->stmts = [
270     new Stmt\Expression(new Expr\Variable('a')),
271     new Stmt\Expression(new Expr\Variable('b')),
272 ];
273 -----
274 <?php
275 function test()
276 {
277     $a;
278     $b;
279 }
280 -----
281 <?php
282 $array = [
283     1,
284     2,
285     3,
286 ];
287 -----
288 array_unshift($stmts[0]->expr->expr->items, new Expr\ArrayItem(new Scalar\LNumber(42)));
289 $stmts[0]->expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24));
290 -----
291 <?php
292 $array = [
293     42,
294     1,
295     2,
296     3,
297     24,
298 ];
299 -----
300 <?php
301 $array = [
302     1, 2,
303     3,
304 ];
305 -----
306 $stmts[0]->expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24));
307 -----
308 <?php
309 $array = [
310     1, 2,
311     3, 24,
312 ];