php5 test coverage

This commit is contained in:
z7zmey 2018-02-14 21:02:57 +02:00
parent 75f952ad03
commit 30b6533864
6 changed files with 3463 additions and 2234 deletions

74
diff
View File

@ -434,51 +434,88 @@
434
435
436
-437
438
439
440
441
-442
443
444
-445
-446
-447
448
-449
450
-451
-452
-453
454
455
-456
457
458
-459
460
-461
-463
-464
462
465
-466
467
468
469
470
471
-472
473
474
-475
476
477
478
-479
-480
-481
482
483
-484
485
-486
-487
488
489
490
-491
492
493
-494
-495
496
497
-498
499
-500
-501
503
-502
505
-504
506
-507
508
509
510
511
-512
-513
-514
-515
516
517
-518
519
520
521
@ -490,41 +527,4 @@
528
-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

5292
log

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,29 @@ import (
"github.com/z7zmey/php-parser/php7"
)
func TestEmptyList(t *testing.T) {
src := `<? list() = $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign_op.Assign{
Variable: &expr.List{
Items: []node.Node{},
},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
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 TestList(t *testing.T) {
src := `<? list($a) = $b;`

File diff suppressed because it is too large Load Diff

View File

@ -3432,7 +3432,13 @@ assignment_list:
assignment_list ',' assignment_list_element
{ fmt.Println("487"); $$ = append($1, $3) }
| assignment_list_element
{ fmt.Println("488"); $$ = []node.Node{$1} }
{
if $1 == nil {
$$ = []node.Node{}
} else {
fmt.Println("488"); $$ = []node.Node{$1}
}
}
;

View File

@ -86,6 +86,11 @@ CAD;
__TRAIT__;
"test $var";
"test $var[1]";
"test $var[1234567890123456789012345678901234567890]";
"test $var[bar]";
"test $var[$bar]";
"$foo $bar";
"test $foo->bar()";
"test ${foo}";
"test ${foo[0]}";
@ -221,6 +226,8 @@ CAD;
array();
array(1);
array(1=>1, &$b,);
array(3 =>&$b);
array(&$b, 1=>1, 1, 3 =>&$b);
~$a;
!$a;
@ -236,6 +243,7 @@ CAD;
\foo;
empty($a);
empty(Foo);
@$a;
eval($a);
exit;
@ -262,7 +270,9 @@ CAD;
$a instanceof \Foo;
isset($a, $b);
list($a) = $b;
isset(Foo);
list() = $b;
list($a, $b) = $b;
list($a[]) = $b;
list(list($a)) = $b;
@ -272,6 +282,9 @@ CAD;
new \Foo();
print($a);
$a->foo;
$a->foo[1];
$a->foo->bar->baz()->quux[0];
$a->foo()[1][1];
` + "`cmd $a`;" + `
` + "`cmd`;" + `
` + "``;" + `
@ -294,6 +307,7 @@ CAD;
-$a;
+$a;
$$a;
$$$a;
yield;
yield $a;
yield $a => $b;
@ -366,6 +380,7 @@ CAD;
static::foo;
new $foo;
new $foo::$bar;
new $a->b[0];
new $a->b{$b ?: null}->$c->d[0];static $a = [1][0];
@ -410,6 +425,16 @@ CAD;
static $a = array();
static $a = array(1 => 1, 2);
static $a = [1, 2 => 2][0];
if (yield 1) {}
Foo::$$bar;
$foo();
$foo()[0][0];
$a{$b};
${$a};
$foo::{$bar}();
$foo::bar;
`
expectedParams := []node.Node{
@ -611,6 +636,59 @@ CAD;
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "test "},
&expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$var"}},
Dim: &scalar.Lnumber{Value: "1"},
},
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "test "},
&expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$var"}},
Dim: &scalar.String{Value: "1234567890123456789012345678901234567890"},
},
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "test "},
&expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$var"}},
Dim: &scalar.String{Value: "bar"},
},
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "test "},
&expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$var"}},
Dim: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
},
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
&scalar.EncapsedStringPart{Value: " "},
&expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
},
},
},
&stmt.Expression{
Expr: &scalar.Encapsed{
Parts: []node.Node{
@ -1860,6 +1938,41 @@ CAD;
},
},
},
&stmt.Expression{
Expr: &expr.Array{
Items: []node.Node{
&expr.ArrayItem{
ByRef: true,
Key: &scalar.Lnumber{Value: "3"},
Val: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
},
&stmt.Expression{
Expr: &expr.Array{
Items: []node.Node{
&expr.ArrayItem{
ByRef: true,
Val: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
&expr.ArrayItem{
ByRef: false,
Key: &scalar.Lnumber{Value: "1"},
Val: &scalar.Lnumber{Value: "1"},
},
&expr.ArrayItem{
ByRef: false,
Val: &scalar.Lnumber{Value: "1"},
},
&expr.ArrayItem{
ByRef: true,
Key: &scalar.Lnumber{Value: "3"},
Val: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
},
&stmt.Expression{
Expr: &expr.BitwiseNot{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
@ -1988,6 +2101,13 @@ CAD;
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
&stmt.Expression{
Expr: &expr.Empty{
Expr: &expr.ConstFetch{
Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
},
},
},
&stmt.Expression{
Expr: &expr.ErrorSuppress{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
@ -2156,6 +2276,23 @@ CAD;
},
},
},
&stmt.Expression{
Expr: &expr.Isset{
Variables: []node.Node{
&expr.ConstFetch{
Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
},
},
},
},
&stmt.Expression{
Expr: &assign_op.Assign{
Variable: &expr.List{
Items: []node.Node{},
},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
&stmt.Expression{
Expr: &assign_op.Assign{
Variable: &expr.List{
@ -2164,6 +2301,10 @@ CAD;
ByRef: false,
Val: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
&expr.ArrayItem{
ByRef: false,
Val: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
@ -2251,6 +2392,47 @@ CAD;
Property: &node.Identifier{Value: "foo"},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.PropertyFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Property: &node.Identifier{Value: "foo"},
},
Dim: &scalar.Lnumber{Value: "1"},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.PropertyFetch{
Variable: &expr.MethodCall{
Variable: &expr.PropertyFetch{
Variable: &expr.PropertyFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Property: &node.Identifier{Value: "foo"},
},
Property: &node.Identifier{Value: "bar"},
},
Method: &node.Identifier{Value: "baz"},
Arguments: []node.Node{},
},
Property: &node.Identifier{Value: "quux"},
},
Dim: &scalar.Lnumber{Value: "0"},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.ArrayDimFetch{
Variable: &expr.MethodCall{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Method: &node.Identifier{Value: "foo"},
Arguments: []node.Node{},
},
Dim: &scalar.Lnumber{Value: "1"},
},
Dim: &scalar.Lnumber{Value: "1"},
},
},
&stmt.Expression{
Expr: &expr.ShellExec{
Parts: []node.Node{
@ -2430,6 +2612,9 @@ CAD;
&stmt.Expression{
Expr: &expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$a"}}},
},
&stmt.Expression{
Expr: &expr.Variable{VarName: &expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$a"}}}},
},
&stmt.Expression{
Expr: &expr.Yield{},
},
@ -2896,6 +3081,14 @@ CAD;
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
},
},
&stmt.Expression{
Expr: &expr.New{
Class: &expr.StaticPropertyFetch{
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Property: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
},
},
},
&stmt.Expression{
Expr: &expr.New{
Class: &expr.ArrayDimFetch{
@ -3408,7 +3601,6 @@ CAD;
},
},
},
&stmt.Static{
Vars: []node.Node{
&stmt.StaticVar{
@ -3432,6 +3624,60 @@ CAD;
},
},
},
&stmt.If{
Cond: &expr.Yield{
Value: &scalar.Lnumber{Value: "1"},
},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
&stmt.Expression{
Expr: &expr.StaticPropertyFetch{
Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
Property: &expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}}},
},
},
&stmt.Expression{
Expr: &expr.FunctionCall{
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.ArrayDimFetch{
Variable: &expr.FunctionCall{
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{},
},
Dim: &scalar.Lnumber{Value: "0"},
},
Dim: &scalar.Lnumber{Value: "0"},
},
},
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Dim: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
&stmt.Expression{
Expr: &expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$a"}}},
},
&stmt.Expression{
Expr: &expr.StaticCall{
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Call: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
Arguments: []node.Node{},
},
},
&stmt.Expression{
Expr: &expr.ClassConstFetch{
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
ConstantName: &node.Identifier{Value: "bar"},
},
},
},
}