php5 test coverage
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {}`
|
||||
|
||||
|
||||
@@ -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;}`
|
||||
|
||||
|
||||
@@ -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};`
|
||||
|
||||
Reference in New Issue
Block a user