php5 test coverage
This commit is contained in:
@@ -83,6 +83,51 @@ func TestClosureUse(t *testing.T) {
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestClosureUse2(t *testing.T) {
|
||||
src := `<? function($a, $b) use (&$c, $d) {};`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Closure{
|
||||
ReturnsRef: false,
|
||||
Static: false,
|
||||
PhpDocComment: "",
|
||||
Params: []node.Node{
|
||||
&node.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
&node.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
},
|
||||
Uses: []node.Node{
|
||||
&expr.ClosureUse{
|
||||
ByRef: true,
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$c"}},
|
||||
},
|
||||
&expr.ClosureUse{
|
||||
ByRef: false,
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$d"}},
|
||||
},
|
||||
},
|
||||
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 TestClosureReturnType(t *testing.T) {
|
||||
src := `<? function(): void {};`
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"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"
|
||||
@@ -71,6 +72,47 @@ func TestYieldKeyVal(t *testing.T) {
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestYieldExpr(t *testing.T) {
|
||||
src := `<? yield 1;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Yield{
|
||||
Value: &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 TestYieldKeyExpr(t *testing.T) {
|
||||
src := `<? yield $a => 1;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Yield{
|
||||
Key: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Value: &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 TestYieldFrom(t *testing.T) {
|
||||
src := `<? yield from $a;`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user