php5 test coverage

This commit is contained in:
z7zmey 2018-02-13 13:38:57 +02:00
parent 0c3b75de8d
commit 5faf9769cf
7 changed files with 607 additions and 459 deletions

4
diff
View File

@ -226,9 +226,11 @@
-226
-227
228
-229
230
231
232
-233
234
235
236
@ -403,8 +405,6 @@
528
-229
-233
-283
-284
-285

957
log

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@ import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
@ -49,6 +50,67 @@ func TestAssignRef(t *testing.T) {
assertEqual(t, expected, actual)
}
func TestAssignRefNew(t *testing.T) {
src := `<? $a =& new Foo;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign_op.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &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 TestAssignRefArgs(t *testing.T) {
src := `<? $a =& new Foo($b);`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign_op.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &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 TestAssign(t *testing.T) {
src := `<? $a = $b;`

View File

@ -15,7 +15,7 @@ import (
)
func TestNew(t *testing.T) {
src := `<? new Foo();`
src := `<? new Foo;`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -26,7 +26,6 @@ func TestNew(t *testing.T) {
&name.NamePart{Value: "Foo"},
},
},
Arguments: []node.Node{},
},
},
},

View File

@ -4476,7 +4476,7 @@ yydefault:
positions.AddPosition(_new, positionBuilder.NewTokenNodePosition(yyDollar[4].token, yyDollar[5].node))
if yyDollar[6].nodesWithEndToken != nil {
_new := expr.NewNew(yyDollar[5].node, yyDollar[6].nodesWithEndToken.nodes)
_new = expr.NewNew(yyDollar[5].node, yyDollar[6].nodesWithEndToken.nodes)
positions.AddPosition(_new, positionBuilder.NewTokensPosition(yyDollar[4].token, yyDollar[6].nodesWithEndToken.endToken))
}
comments.AddComments(_new, comments[yyDollar[1].node])

View File

@ -1848,7 +1848,7 @@ expr_without_variable:
positions.AddPosition(_new, positionBuilder.NewTokenNodePosition($4, $5))
if $6 != nil {
_new := expr.NewNew($5, $6.nodes)
_new = expr.NewNew($5, $6.nodes)
positions.AddPosition(_new, positionBuilder.NewTokensPosition($4, $6.endToken))
}
comments.AddComments(_new, comments[$1])

View File

@ -261,7 +261,7 @@ CAD;
list(list($a)) = $b;
$a->foo();
new Foo();
new Foo;
new namespace\Foo();
new \Foo();
print($a);
@ -326,6 +326,8 @@ CAD;
$a < $b;
$a =& $b;
$a =& new Foo;
$a =& new Foo($b);
$a = $b;
$a &= $b;
$a |= $b;
@ -2111,7 +2113,6 @@ CAD;
&name.NamePart{Value: "Foo"},
},
},
Arguments: []node.Node{},
},
},
&stmt.Expression{
@ -2514,6 +2515,37 @@ CAD;
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
&stmt.Expression{
Expr: &assign_op.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
},
},
&stmt.Expression{
Expr: &assign_op.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
},
},
&stmt.Expression{
Expr: &assign_op.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},