php5 test coverage

This commit is contained in:
z7zmey 2018-02-12 15:08:08 +02:00
parent bf90803ef3
commit 98b1698db7
9 changed files with 8251 additions and 539 deletions

530
diff Normal file
View File

@ -0,0 +1,530 @@
1
2
3
-4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-20
-21
22
23
24
-25
-26
-27
28
29
30
-31
-32
-33
34
35
36
37
38
-39
-40
-41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-57
58
59
60
61
62
63
64
65
66
-67
-68
69
70
71
72
73
74
75
76
77
78
79
80
-81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-114
115
116
117
118
119
121
123
125
126
127
128
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
147
148
149
151
152
154
156
157
158
159
163
164
166
167
168
169
170
171
172
173
174
175
176
178
179
180
181
182
183
184
185
187
188
189
191
194
195
196
197
198
199
200
201
204
208
209
211
212
213
214
216
217
218
228
230
231
232
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
287
288
289
290
291
292
293
294
295
296
297
298
299
301
302
303
304
305
306
308
310
315
316
317
318
319
321
322
324
325
326
327
329
331
333
334
335
336
339
352
354
357
359
360
361
362
363
364
365
366
367
368
369
370
373
374
376
417
418
419
420
421
422
424
425
427
434
435
436
438
439
440
441
443
444
448
450
454
455
457
458
460
462
465
467
468
469
470
471
473
474
476
477
478
482
483
485
488
489
490
492
493
496
497
499
503
505
506
508
509
510
511
516
517
519
520
521
522
523
524
525
526
528
-120
-122
-124
-129
-145
-146
-150
-153
-155
-160
-161
-162
-165
-177
-186
-190
-192
-193
-202
-203
-205
-206
-207
-210
-215
-219
-220
-221
-222
-223
-224
-225
-226
-227
-229
-233
-283
-284
-285
-286
-300
-307
-309
-311
-312
-313
-314
-320
-323
-328
-330
-332
-337
-338
-340
-341
-342
-343
-344
-345
-346
-347
-348
-349
-350
-351
-353
-355
-356
-358
-371
-372
-375
-377
-378
-379
-380
-381
-382
-383
-384
-385
-386
-387
-388
-389
-390
-391
-392
-393
-394
-395
-396
-397
-398
-399
-400
-401
-402
-403
-404
-405
-406
-407
-408
-409
-410
-411
-412
-413
-414
-415
-416
-423
-426
-428
-429
-430
-431
-432
-433
-437
-442
-445
-446
-447
-449
-451
-452
-453
-456
-459
-461
-463
-464
-466
-472
-475
-479
-480
-481
-484
-486
-487
-491
-494
-495
-498
-500
-501
-502
-504
-507
-512
-513
-514
-515
-518
-527

6239
log Normal file

File diff suppressed because it is too large Load Diff

View File

@ -54,3 +54,41 @@ func TestFor(t *testing.T) {
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAltFor(t *testing.T) {
src := `<? for($i = 0; $i < 10; $i++, $i++) : endfor;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.For{
Init: []node.Node{
&assign_op.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
Expression: &scalar.Lnumber{Value: "0"},
},
},
Cond: []node.Node{
&binary_op.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
Right: &scalar.Lnumber{Value: "10"},
},
},
Loop: []node.Node{
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
},
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
},
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

View File

@ -32,6 +32,26 @@ func TestForeach(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestForeachExpr(t *testing.T) {
src := `<? foreach ([] as $v) {}`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAltForeach(t *testing.T) {
src := `<? foreach ($a as $v) : endforeach;`
@ -73,6 +93,27 @@ func TestForeachWithKey(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestForeachExprWithKey(t *testing.T) {
src := `<? foreach ([] as $k => $v) {}`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "$k"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestForeachWithRef(t *testing.T) {
src := `<? foreach ($a as $k => &$v) {}`

View File

@ -7,6 +7,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
@ -56,6 +57,31 @@ func TestFunctionReturn(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestFunctionReturnVar(t *testing.T) {
src := `<? function foo() {return $a;}`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
&stmt.Return{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestRefFunction(t *testing.T) {
src := `<? function &foo() {return 1;}`

View File

@ -37,6 +37,59 @@ func TestSimpleUse(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestUseFullyQualified(t *testing.T) {
src := `<? use \Foo;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestUseFullyQualifiedAlias(t *testing.T) {
src := `<? use \Foo as Bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "Bar"},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestUseList(t *testing.T) {
src := `<? use Foo, Bar;`
@ -105,7 +158,7 @@ func TestUseListAlias(t *testing.T) {
}
func TestUseListFunctionType(t *testing.T) {
src := `<? use function Foo, Bar;`
src := `<? use function Foo, \Bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -138,8 +191,44 @@ func TestUseListFunctionType(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestUseListFunctionTypeAliases(t *testing.T) {
src := `<? use function Foo as foo, \Bar as bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "function"},
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "foo"},
},
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
Alias: &node.Identifier{Value: "bar"},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestUseListConstType(t *testing.T) {
src := `<? use const Foo, Bar;`
src := `<? use const Foo, \Bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -172,6 +261,42 @@ func TestUseListConstType(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestUseListConstTypeAliases(t *testing.T) {
src := `<? use const Foo as foo, \Bar as bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "const"},
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "foo"},
},
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
Alias: &node.Identifier{Value: "bar"},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestGroupUse(t *testing.T) {
src := `<? use Foo\{Bar, Baz};`

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -123,12 +123,23 @@ CAD;
echo $a, 1;
echo($a);
for($i = 0; $i < 10; $i++, $i++) {}
for($i = 0; $i < 10; $i++, $i++) : endfor;
foreach ($a as $v) {}
foreach ([] as $v) {}
foreach ($a as $v) : endforeach;
foreach ($a as $k => $v) {}
foreach ([] as $k => $v) {}
foreach ($a as $k => &$v) {}
foreach ($a as $k => list($v)) {}
function foo() {}
function foo() {
__halt_compiler();
function bar() {}
class Baz {}
return $a;
}
function foo() {return;}
function &foo() {return 1;}
function &foo() {}
@ -146,7 +157,7 @@ CAD;
interface Foo extends Bar {}
interface Foo extends Bar, Baz {}
namespace Foo;
namespace Foo {}
namespace Foo\Bar {}
namespace {}
class foo {var $a;}
class foo {public static $a, $b = 1;}
@ -171,15 +182,20 @@ CAD;
try {}
try {} catch (Exception $e) {}
try {} catch (Exception $e) {} catch (RuntimeException $e) {}
try {} catch (Exception $e) {} catch (RuntimeException $e) {} catch (AdditionException $e) {}
try {} catch (Exception $e) {} finally {}
unset($a, $b);
use Foo;
use \Foo;
use \Foo as Bar;
use Foo, Bar;
use Foo, Bar as Baz;
use function Foo, Bar;
use const Foo, Bar;
use function Foo, \Bar;
use function Foo as foo, \Bar as bar;
use const Foo, \Bar;
use const Foo as foo, \Bar as bar;
$a[1];
$a[1][2];
@ -839,11 +855,39 @@ CAD;
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.For{
Init: []node.Node{
&assign_op.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
Expression: &scalar.Lnumber{Value: "0"},
},
},
Cond: []node.Node{
&binary_op.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
Right: &scalar.Lnumber{Value: "10"},
},
},
Loop: []node.Node{
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
},
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
},
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
@ -855,6 +899,12 @@ CAD;
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "$k"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
},
&stmt.Foreach{
ByRef: true,
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
@ -882,6 +932,28 @@ CAD;
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{},
},
&stmt.Function{
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
&stmt.HaltCompiler{},
&stmt.Function{
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "bar"},
Stmts: []node.Node{},
},
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Baz"},
Stmts: []node.Node{},
},
&stmt.Return{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
},
&stmt.Function{
ReturnsRef: false,
PhpDocComment: "",
@ -1023,6 +1095,7 @@ CAD;
NamespaceName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
&name.NamePart{Value: "Bar"},
},
},
Stmts: []node.Node{},
@ -1263,6 +1336,50 @@ CAD;
},
},
},
&stmt.Try{
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Types: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Types: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Types: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "AdditionException"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
},
},
&stmt.Try{
Stmts: []node.Node{},
Catches: []node.Node{
@ -1301,6 +1418,29 @@ CAD;
},
},
},
&stmt.UseList{
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
},
},
&stmt.UseList{
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "Bar"},
},
},
},
&stmt.UseList{
Uses: []node.Node{
&stmt.Use{
@ -1357,6 +1497,27 @@ CAD;
},
},
},
&stmt.UseList{
UseType: &node.Identifier{Value: "function"},
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "foo"},
},
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
Alias: &node.Identifier{Value: "bar"},
},
},
},
&stmt.UseList{
UseType: &node.Identifier{Value: "const"},
Uses: []node.Node{
@ -1376,6 +1537,27 @@ CAD;
},
},
},
&stmt.UseList{
UseType: &node.Identifier{Value: "const"},
Uses: []node.Node{
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Alias: &node.Identifier{Value: "foo"},
},
&stmt.Use{
Use: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
Alias: &node.Identifier{Value: "bar"},
},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},