php5 test coverage

This commit is contained in:
z7zmey 2018-02-12 23:10:53 +02:00
parent 98b1698db7
commit b5e6d263f3
12 changed files with 2215 additions and 1797 deletions

22
diff
View File

@ -117,12 +117,16 @@
117
118
119
-120
121
-122
123
-124
125
126
127
128
-129
130
131
132
@ -138,16 +142,23 @@
142
143
144
-145
-146
147
148
149
-150
151
152
-153
154
-155
156
157
158
159
-160
-161
163
164
166
@ -369,17 +380,6 @@
528
-120
-122
-124
-129
-145
-146
-150
-153
-155
-160
-161
-162
-165
-177

2686
log

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@ func TestFunctionCallRelative(t *testing.T) {
}
func TestFunctionFullyQualified(t *testing.T) {
src := `<? \foo();`
src := `<? \foo([]);`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -76,7 +76,15 @@ func TestFunctionFullyQualified(t *testing.T) {
&name.NamePart{Value: "foo"},
},
},
Arguments: []node.Node{},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.ShortArray{
Items: []node.Node{},
},
},
},
},
},
},
@ -90,14 +98,22 @@ func TestFunctionFullyQualified(t *testing.T) {
}
func TestFunctionCallVar(t *testing.T) {
src := `<? $foo();`
src := `<? $foo(yield $a);`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{},
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.Yield{
Value: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
},
},
},
},

View File

@ -38,7 +38,7 @@ func TestDeclare(t *testing.T) {
}
func TestDeclareStmts(t *testing.T) {
src := `<? declare(ticks=1) {}`
src := `<? declare(ticks=1, strict_types=1) {}`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -49,6 +49,11 @@ func TestDeclareStmts(t *testing.T) {
ConstantName: &node.Identifier{Value: "ticks"},
Expr: &scalar.Lnumber{Value: "1"},
},
&stmt.Constant{
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "strict_types"},
Expr: &scalar.Lnumber{Value: "1"},
},
},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},

View File

@ -1,11 +1,12 @@
package stmt_test
import (
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/node/name"
"bytes"
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/stmt"
@ -19,10 +20,10 @@ func TestSimpleFunction(t *testing.T) {
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{},
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{},
},
},
}
@ -40,9 +41,9 @@ func TestFunctionReturn(t *testing.T) {
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
&stmt.Return{},
},
@ -58,14 +59,28 @@ func TestFunctionReturn(t *testing.T) {
}
func TestFunctionReturnVar(t *testing.T) {
src := `<? function foo() {return $a;}`
src := `<? function foo(array $a, callable $b) {return $a;}`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{Value: "foo"},
Params: []node.Node{
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "array"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "callable"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
Stmts: []node.Node{
&stmt.Return{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
@ -88,9 +103,9 @@ func TestRefFunction(t *testing.T) {
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: true,
ReturnsRef: true,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
&stmt.Return{
Expr: &scalar.Lnumber{Value: "1"},
@ -113,9 +128,9 @@ func TestReturnTypeFunction(t *testing.T) {
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: true,
ReturnsRef: true,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{Value: "foo"},
ReturnType: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "void"},

View File

@ -5,8 +5,9 @@ import (
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
"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"
)
@ -32,7 +33,7 @@ func TestGlobal(t *testing.T) {
}
func TestGlobalVars(t *testing.T) {
src := `<? global $a, $b;`
src := `<? global $a, $b, $$c, ${foo()};`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -40,6 +41,17 @@ func TestGlobalVars(t *testing.T) {
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "$a"}},
&expr.Variable{VarName: &node.Identifier{Value: "$b"}},
&expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$c"}}},
&expr.Variable{
VarName: &expr.FunctionCall{
Function: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "foo"},
},
},
Arguments: []node.Node{},
},
},
},
},
},

View File

@ -6,8 +6,8 @@ import (
"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/node/scalar"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
)
@ -46,7 +46,33 @@ func TestStaticVars(t *testing.T) {
},
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
Expr: &scalar.Lnumber{Value: "1"},
Expr: &scalar.Lnumber{Value: "1"},
},
},
},
},
}
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 TestStaticVars2(t *testing.T) {
src := `<? static $a = 1, $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Static{
Vars: []node.Node{
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &scalar.Lnumber{Value: "1"},
},
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},

View File

@ -27,14 +27,14 @@ func TestAltSwitch(t *testing.T) {
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Cond: &scalar.Lnumber{Value: "1"},
Stmts: []node.Node{},
},
&stmt.Default{
Stmts: []node.Node{},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Cond: &scalar.Lnumber{Value: "2"},
Stmts: []node.Node{},
},
},
@ -45,6 +45,38 @@ func TestAltSwitch(t *testing.T) {
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 TestAltSwitchSemicolon(t *testing.T) {
src := `<?
switch (1) :;
case 1;
case 2;
endswitch;
`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Stmts: []node.Node{},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
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)
@ -54,6 +86,43 @@ func TestSwitch(t *testing.T) {
src := `<?
switch (1) {
case 1: break;
case 2: break;
}
`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Stmts: []node.Node{
&stmt.Break{},
},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Stmts: []node.Node{
&stmt.Break{},
},
},
},
},
},
}
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 TestSwitchSemicolon(t *testing.T) {
src := `<?
switch (1) {;
case 1; break;
case 2; break;
}
`

View File

@ -31,7 +31,6 @@ func TestBreakEmpty(t *testing.T) {
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
@ -57,13 +56,12 @@ func TestBreakLight(t *testing.T) {
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 TestBreak(t *testing.T) {
src := `<? while (1) { break(3); }`
src := `<? while (1) : break(3); endwhile;`
expected := &stmt.StmtList{
Stmts: []node.Node{
@ -83,7 +81,6 @@ func TestBreak(t *testing.T) {
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

File diff suppressed because it is too large Load Diff

View File

@ -668,7 +668,11 @@ unticked_statement:
comments.AddComments($$, $1.Comments())
}
| yield_expr ';'
{ fmt.Println("58"); $$ = $1 }
{
fmt.Println("58"); $$ = stmt.NewExpression($1)
positions.AddPosition($$, positionBuilder.NewNodeTokenPosition($1, $2))
comments.AddComments($$, comments[$1])
}
| T_GLOBAL global_var_list ';'
{
fmt.Println("59"); $$ = stmt.NewGlobal($2)
@ -2276,41 +2280,25 @@ expr_without_variable:
yield_expr:
T_YIELD expr_without_variable
{
yield := expr.NewYield(nil, $2)
positions.AddPosition(yield, positionBuilder.NewTokenNodePosition($1, $2))
comments.AddComments(yield, $1.Comments())
fmt.Println("307"); $$ = stmt.NewExpression(yield)
fmt.Println("307"); $$ = expr.NewYield(nil, $2)
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $2))
comments.AddComments($$, $1.Comments())
}
| T_YIELD variable
{
yield := expr.NewYield(nil, $2)
positions.AddPosition(yield, positionBuilder.NewTokenNodePosition($1, $2))
comments.AddComments(yield, $1.Comments())
fmt.Println("308"); $$ = stmt.NewExpression(yield)
fmt.Println("308"); $$ = expr.NewYield(nil, $2)
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $2))
comments.AddComments($$, $1.Comments())
}
| T_YIELD expr T_DOUBLE_ARROW expr_without_variable
{
yield := expr.NewYield($2, $4)
positions.AddPosition(yield, positionBuilder.NewTokenNodePosition($1, $4))
comments.AddComments(yield, $1.Comments())
fmt.Println("309"); $$ = stmt.NewExpression(yield)
fmt.Println("309"); $$ = expr.NewYield($2, $4)
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $4))
comments.AddComments($$, $1.Comments())
}
| T_YIELD expr T_DOUBLE_ARROW variable
{
yield := expr.NewYield($2, $4)
positions.AddPosition(yield, positionBuilder.NewTokenNodePosition($1, $4))
comments.AddComments(yield, $1.Comments())
fmt.Println("310"); $$ = stmt.NewExpression(yield)
fmt.Println("310"); $$ = expr.NewYield($2, $4)
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $4))
comments.AddComments($$, $1.Comments())
}

View File

@ -102,7 +102,7 @@ CAD;
while (1) { break; }
while (1) { break 2; }
while (1) { break(3); }
while (1) : break(3); endwhile;
class foo{ const FOO = 1, BAR = 2; }
class foo{ function bar() {} }
class foo{ public static function &bar() {} }
@ -117,7 +117,7 @@ CAD;
while (1) { continue 2; }
while (1) { continue(3); }
declare(ticks=1);
declare(ticks=1) {}
declare(ticks=1, strict_types=1) {}
declare(ticks=1): enddeclare;
do {} while(1);
echo $a, 1;
@ -140,10 +140,10 @@ CAD;
return $a;
}
function foo() {return;}
function foo(array $a, callable $b) {return;}
function &foo() {return 1;}
function &foo() {}
global $a, $b;
global $a, $b, $$c, ${foo()};
a:
goto a;
__halt_compiler();
@ -162,15 +162,26 @@ CAD;
class foo {var $a;}
class foo {public static $a, $b = 1;}
static $a, $b = 1;
static $a = 1, $b;
switch (1) :
case 1:
default:
case 2:
endswitch;
switch (1) :;
case 1;
case 2;
endswitch;
switch (1) {
case 1: break;
case 2: break;
}
switch (1) {;
case 1; break;
case 2; break;
}
throw $e;
@ -223,9 +234,9 @@ CAD;
die;
die($a);
foo();
namespace\foo();
\foo();
$foo();
namespace\foo(&$a);
\foo([]);
$foo(yield $a);
$a--;
$a++;
@ -794,6 +805,11 @@ CAD;
ConstantName: &node.Identifier{Value: "ticks"},
Expr: &scalar.Lnumber{Value: "1"},
},
&stmt.Constant{
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "strict_types"},
Expr: &scalar.Lnumber{Value: "1"},
},
},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
@ -936,7 +952,7 @@ CAD;
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{
Stmts: []node.Node{
&stmt.HaltCompiler{},
&stmt.Function{
ReturnsRef: false,
@ -946,8 +962,8 @@ CAD;
},
&stmt.Class{
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Baz"},
Stmts: []node.Node{},
ClassName: &node.Identifier{Value: "Baz"},
Stmts: []node.Node{},
},
&stmt.Return{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
@ -958,6 +974,20 @@ CAD;
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Params: []node.Node{
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "array"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "callable"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
Stmts: []node.Node{
&stmt.Return{},
},
@ -982,6 +1012,17 @@ CAD;
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "$a"}},
&expr.Variable{VarName: &node.Identifier{Value: "$b"}},
&expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "$c"}}},
&expr.Variable{
VarName: &expr.FunctionCall{
Function: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "foo"},
},
},
Arguments: []node.Node{},
},
},
},
},
&stmt.Label{
@ -1152,6 +1193,17 @@ CAD;
},
},
},
&stmt.Static{
Vars: []node.Node{
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &scalar.Lnumber{Value: "1"},
},
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
@ -1168,6 +1220,36 @@ CAD;
},
},
},
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Stmts: []node.Node{},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Stmts: []node.Node{},
},
},
},
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Stmts: []node.Node{
&stmt.Break{},
},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Stmts: []node.Node{
&stmt.Break{},
},
},
},
},
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Cases: []node.Node{
@ -1750,7 +1832,13 @@ CAD;
&name.NamePart{Value: "foo"},
},
},
Arguments: []node.Node{},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: true,
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
},
},
&stmt.Expression{
@ -1760,13 +1848,29 @@ CAD;
&name.NamePart{Value: "foo"},
},
},
Arguments: []node.Node{},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.ShortArray{
Items: []node.Node{},
},
},
},
},
},
&stmt.Expression{
Expr: &expr.FunctionCall{
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{},
Function: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.Yield{
Value: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
},
},
},
},
&stmt.Expression{