php5 test coverage
This commit is contained in:
parent
a6fb7fc8a9
commit
0a34643856
8
diff
8
diff
@ -304,7 +304,9 @@
|
||||
304
|
||||
305
|
||||
306
|
||||
-307
|
||||
308
|
||||
-309
|
||||
310
|
||||
-311
|
||||
-312
|
||||
@ -315,8 +317,10 @@
|
||||
317
|
||||
318
|
||||
319
|
||||
-320
|
||||
321
|
||||
322
|
||||
-323
|
||||
324
|
||||
325
|
||||
326
|
||||
@ -414,10 +418,6 @@
|
||||
528
|
||||
|
||||
|
||||
-307
|
||||
-309
|
||||
-320
|
||||
-323
|
||||
-328
|
||||
-330
|
||||
-332
|
||||
|
@ -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;`
|
||||
|
||||
|
@ -224,6 +224,7 @@ CAD;
|
||||
clone $a;
|
||||
function(){};
|
||||
function($a, $b) use ($c, &$d) {};
|
||||
function($a, $b) use (&$c, $d) {};
|
||||
function() {};
|
||||
foo;
|
||||
namespace\foo;
|
||||
@ -287,6 +288,8 @@ CAD;
|
||||
yield;
|
||||
yield $a;
|
||||
yield $a => $b;
|
||||
yield 1;
|
||||
yield $a => 1;
|
||||
|
||||
(array)$a;
|
||||
(boolean)$a;
|
||||
@ -1858,6 +1861,36 @@ CAD;
|
||||
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{},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Closure{
|
||||
ReturnsRef: false,
|
||||
@ -2313,6 +2346,17 @@ CAD;
|
||||
Value: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Yield{
|
||||
Value: &scalar.Lnumber{Value: "1"},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Yield{
|
||||
Key: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Value: &scalar.Lnumber{Value: "1"},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &cast.CastArray{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
|
Loading…
Reference in New Issue
Block a user