php5 test coverage
This commit is contained in:
@@ -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"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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{},
|
||||
|
||||
@@ -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"},
|
||||
|
||||
@@ -3,10 +3,11 @@ package stmt_test
|
||||
import (
|
||||
"bytes"
|
||||
"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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,11 +3,11 @@ package stmt_test
|
||||
import (
|
||||
"bytes"
|
||||
"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/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"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
`
|
||||
@@ -85,4 +154,4 @@ func TestSwitch(t *testing.T) {
|
||||
|
||||
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user