php-parser/node/t_node_test.go

2756 lines
61 KiB
Go
Raw Normal View History

2018-01-13 01:40:08 +00:00
package node_test
import (
"testing"
"gotest.tools/assert"
2018-01-13 01:40:08 +00:00
"github.com/z7zmey/php-parser/node/name"
2018-06-24 07:19:44 +00:00
"github.com/z7zmey/php-parser/position"
2018-01-13 01:40:08 +00:00
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
2018-02-08 10:48:38 +00:00
"github.com/z7zmey/php-parser/php5"
2018-02-04 19:44:58 +00:00
"github.com/z7zmey/php-parser/php7"
2018-01-13 01:40:08 +00:00
)
func TestIdentifier(t *testing.T) {
src := `<? $foo;`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 3,
2018-06-24 07:19:44 +00:00
EndPos: 8,
},
2018-01-13 01:40:08 +00:00
Stmts: []node.Node{
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 3,
2018-06-24 07:19:44 +00:00
EndPos: 8,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.Variable{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 3,
2018-06-24 07:19:44 +00:00
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 3,
2018-06-24 07:19:44 +00:00
EndPos: 7,
},
Value: "foo",
},
2018-01-13 01:40:08 +00:00
},
},
},
}
2019-12-26 15:57:56 +00:00
php7parser := php7.NewParser([]byte(src), "7.4")
2018-04-10 12:23:13 +00:00
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-01-13 01:40:08 +00:00
2019-12-26 15:57:56 +00:00
php5parser := php5.NewParser([]byte(src), "5.6")
2018-04-10 12:23:13 +00:00
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-01-13 01:40:08 +00:00
}
2018-02-08 10:48:38 +00:00
func TestPhp7ArgumentNode(t *testing.T) {
2018-01-13 01:40:08 +00:00
src := `<?
foo($a, ...$b);
$foo($a, ...$b);
$foo->bar($a, ...$b);
foo::bar($a, ...$b);
$foo::bar($a, ...$b);
new foo($a, ...$b);
/** anonymous class */
new class ($a, ...$b) {};
`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 186,
},
2018-01-13 01:40:08 +00:00
Stmts: []node.Node{
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 21,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.FunctionCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 20,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 9,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 9,
},
Value: "foo",
},
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 20,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Variadic: false,
2018-06-25 12:38:31 +00:00
IsReference: false,
2018-06-24 07:19:44 +00:00
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 14,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 17,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 17,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 40,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.FunctionCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 39,
},
Function: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
Value: "foo",
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 39,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 33,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 36,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 36,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 64,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.MethodCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
Value: "foo",
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 49,
2018-06-24 07:19:44 +00:00
EndPos: 52,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 52,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
IsReference: false,
2018-06-25 12:38:31 +00:00
Variadic: false,
2018-06-24 07:19:44 +00:00
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 57,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 87,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.StaticCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 86,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 70,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 70,
},
Value: "foo",
},
},
},
Call: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 72,
2018-06-24 07:19:44 +00:00
EndPos: 75,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 75,
2018-06-24 07:19:44 +00:00
EndPos: 86,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 80,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
Variadic: true,
2018-06-25 12:38:31 +00:00
IsReference: false,
2018-06-24 07:19:44 +00:00
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 83,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 83,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 111,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.StaticCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 110,
},
Class: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
Value: "foo",
},
},
Call: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 96,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 99,
2018-06-24 07:19:44 +00:00
EndPos: 110,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Variadic: false,
2018-06-25 12:38:31 +00:00
IsReference: false,
2018-06-24 07:19:44 +00:00
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 104,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 114,
2018-06-24 07:19:44 +00:00
EndPos: 133,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.New{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 114,
2018-06-24 07:19:44 +00:00
EndPos: 132,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 118,
2018-06-24 07:19:44 +00:00
EndPos: 121,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 118,
2018-06-24 07:19:44 +00:00
EndPos: 121,
},
Value: "foo",
},
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 121,
2018-06-24 07:19:44 +00:00
EndPos: 132,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 126,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 129,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 129,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 161,
2018-06-24 07:19:44 +00:00
EndPos: 186,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.New{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 161,
2018-06-24 07:19:44 +00:00
EndPos: 185,
},
2018-01-13 01:40:08 +00:00
Class: &stmt.Class{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 165,
2018-06-24 07:19:44 +00:00
EndPos: 185,
},
2018-01-13 01:40:08 +00:00
PhpDocComment: "/** anonymous class */",
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 171,
2018-06-24 07:19:44 +00:00
EndPos: 182,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 172,
2018-06-24 07:19:44 +00:00
EndPos: 174,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 172,
2018-06-24 07:19:44 +00:00
EndPos: 174,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 172,
2018-06-24 07:19:44 +00:00
EndPos: 174,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 176,
2018-06-24 07:19:44 +00:00
EndPos: 181,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 179,
2018-06-24 07:19:44 +00:00
EndPos: 181,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 9,
EndLine: 9,
2019-03-10 21:37:01 +00:00
StartPos: 179,
2018-06-24 07:19:44 +00:00
EndPos: 181,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-01-13 01:40:08 +00:00
},
Stmts: []node.Node{},
},
},
},
},
}
2019-12-26 15:57:56 +00:00
php7parser := php7.NewParser([]byte(src), "7.4")
2018-04-10 12:23:13 +00:00
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-02-08 10:48:38 +00:00
}
func TestPhp5ArgumentNode(t *testing.T) {
src := `<?
foo($a, ...$b);
$foo($a, ...$b);
$foo->bar($a, ...$b);
foo::bar($a, ...$b);
$foo::bar($a, ...$b);
new foo($a, ...$b);
`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 133,
},
2018-02-08 10:48:38 +00:00
Stmts: []node.Node{
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 21,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.FunctionCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 20,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 9,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 9,
},
Value: "foo",
},
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 20,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 10,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 14,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 17,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 17,
2018-06-24 07:19:44 +00:00
EndPos: 19,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 40,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.FunctionCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 39,
},
Function: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
Value: "foo",
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 39,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 31,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 33,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 36,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 36,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 64,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.MethodCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
Value: "foo",
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 49,
2018-06-24 07:19:44 +00:00
EndPos: 52,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 52,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 55,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 57,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
IsReference: false,
Variadic: true,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 87,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.StaticCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 86,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 70,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 67,
2018-06-24 07:19:44 +00:00
EndPos: 70,
},
Value: "foo",
},
},
},
Call: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 72,
2018-06-24 07:19:44 +00:00
EndPos: 75,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 75,
2018-06-24 07:19:44 +00:00
EndPos: 86,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 76,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 80,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 83,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 83,
2018-06-24 07:19:44 +00:00
EndPos: 85,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 111,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.StaticCall{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 110,
},
Class: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
Value: "foo",
},
},
Call: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 96,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
Value: "bar",
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 99,
2018-06-24 07:19:44 +00:00
EndPos: 110,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 100,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 104,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 6,
EndLine: 6,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 109,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 114,
2018-06-24 07:19:44 +00:00
EndPos: 133,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.New{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 114,
2018-06-24 07:19:44 +00:00
EndPos: 132,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 118,
2018-06-24 07:19:44 +00:00
EndPos: 121,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 118,
2018-06-24 07:19:44 +00:00
EndPos: 121,
},
Value: "foo",
},
},
},
2018-04-29 16:58:49 +00:00
ArgumentList: &node.ArgumentList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 121,
2018-06-24 07:19:44 +00:00
EndPos: 132,
},
2018-04-29 16:58:49 +00:00
Arguments: []node.Node{
2018-06-24 07:19:44 +00:00
&node.Argument{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
Variadic: false,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 122,
2018-06-24 07:19:44 +00:00
EndPos: 124,
},
Value: "a",
},
},
},
&node.Argument{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 126,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Variadic: true,
IsReference: false,
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 129,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 7,
EndLine: 7,
2019-03-10 21:37:01 +00:00
StartPos: 129,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Value: "b",
},
},
},
2018-04-29 16:58:49 +00:00
},
2018-02-08 10:48:38 +00:00
},
},
},
},
}
2018-01-13 01:40:08 +00:00
2019-12-26 15:57:56 +00:00
php5parser := php5.NewParser([]byte(src), "5.6")
2018-04-10 12:23:13 +00:00
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-01-13 01:40:08 +00:00
}
2018-02-08 10:48:38 +00:00
func TestPhp7ParameterNode(t *testing.T) {
2018-01-13 01:40:08 +00:00
src := `<?
function foo(?bar $bar=null, baz &...$baz) {}
class foo {public function foo(?bar $bar=null, baz &...$baz) {}}
function(?bar $bar=null, baz &...$baz) {};
static function(?bar $bar=null, baz &...$baz) {};
`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 215,
},
2018-01-13 01:40:08 +00:00
Stmts: []node.Node{
&stmt.Function{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 51,
},
2018-01-13 01:40:08 +00:00
ReturnsRef: false,
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 15,
2018-06-24 07:19:44 +00:00
EndPos: 18,
},
Value: "foo",
},
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 19,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
ByRef: false,
Variadic: false,
VariableType: &node.Nullable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 19,
2018-06-24 07:19:44 +00:00
EndPos: 23,
},
Expr: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 20,
2018-06-24 07:19:44 +00:00
EndPos: 23,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 20,
2018-06-24 07:19:44 +00:00
EndPos: 23,
},
Value: "bar",
},
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 24,
2018-06-24 07:19:44 +00:00
EndPos: 28,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 29,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 35,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 35,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 35,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 43,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-01-13 01:40:08 +00:00
},
&stmt.Class{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 54,
2018-06-24 07:19:44 +00:00
EndPos: 118,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
Value: "foo",
},
2018-01-13 01:40:08 +00:00
Stmts: []node.Node{
&stmt.ClassMethod{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 65,
2018-06-24 07:19:44 +00:00
EndPos: 117,
},
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 81,
2018-06-24 07:19:44 +00:00
EndPos: 84,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 65,
2018-06-24 07:19:44 +00:00
EndPos: 71,
},
Value: "public",
},
},
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 85,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
ByRef: false,
Variadic: false,
VariableType: &node.Nullable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 85,
2018-06-24 07:19:44 +00:00
EndPos: 89,
},
Expr: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 86,
2018-06-24 07:19:44 +00:00
EndPos: 89,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 86,
2018-06-24 07:19:44 +00:00
EndPos: 89,
},
Value: "bar",
},
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 90,
2018-06-24 07:19:44 +00:00
EndPos: 94,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 95,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 95,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 95,
2018-06-24 07:19:44 +00:00
EndPos: 99,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 101,
2018-06-24 07:19:44 +00:00
EndPos: 113,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 101,
2018-06-24 07:19:44 +00:00
EndPos: 104,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 101,
2018-06-24 07:19:44 +00:00
EndPos: 104,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 109,
2018-06-24 07:19:44 +00:00
EndPos: 113,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 109,
2018-06-24 07:19:44 +00:00
EndPos: 113,
},
Value: "baz",
},
},
},
},
2018-06-03 06:35:44 +00:00
Stmt: &stmt.StmtList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 115,
2018-06-24 07:19:44 +00:00
EndPos: 117,
},
2018-06-03 06:35:44 +00:00
Stmts: []node.Node{},
},
2018-01-13 01:40:08 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 121,
2018-06-24 07:19:44 +00:00
EndPos: 163,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.Closure{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 121,
2018-06-24 07:19:44 +00:00
EndPos: 162,
},
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 130,
2018-06-24 07:19:44 +00:00
EndPos: 144,
},
ByRef: false,
Variadic: false,
VariableType: &node.Nullable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 130,
2018-06-24 07:19:44 +00:00
EndPos: 134,
},
Expr: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 131,
2018-06-24 07:19:44 +00:00
EndPos: 134,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 131,
2018-06-24 07:19:44 +00:00
EndPos: 134,
},
Value: "bar",
},
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 135,
2018-06-24 07:19:44 +00:00
EndPos: 139,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 135,
2018-06-24 07:19:44 +00:00
EndPos: 139,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 140,
2018-06-24 07:19:44 +00:00
EndPos: 144,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 140,
2018-06-24 07:19:44 +00:00
EndPos: 144,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 140,
2018-06-24 07:19:44 +00:00
EndPos: 144,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 146,
2018-06-24 07:19:44 +00:00
EndPos: 158,
},
Variadic: true,
ByRef: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 146,
2018-06-24 07:19:44 +00:00
EndPos: 149,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 146,
2018-06-24 07:19:44 +00:00
EndPos: 149,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 154,
2018-06-24 07:19:44 +00:00
EndPos: 158,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 154,
2018-06-24 07:19:44 +00:00
EndPos: 158,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-01-13 01:40:08 +00:00
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 166,
2018-06-24 07:19:44 +00:00
EndPos: 215,
},
2018-01-13 01:40:08 +00:00
Expr: &expr.Closure{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 166,
2018-06-24 07:19:44 +00:00
EndPos: 214,
},
Static: true,
PhpDocComment: "",
ReturnsRef: false,
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 182,
2018-06-24 07:19:44 +00:00
EndPos: 196,
},
ByRef: false,
Variadic: false,
VariableType: &node.Nullable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 182,
2018-06-24 07:19:44 +00:00
EndPos: 186,
},
Expr: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 183,
2018-06-24 07:19:44 +00:00
EndPos: 186,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 183,
2018-06-24 07:19:44 +00:00
EndPos: 186,
},
Value: "bar",
},
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 187,
2018-06-24 07:19:44 +00:00
EndPos: 191,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 187,
2018-06-24 07:19:44 +00:00
EndPos: 191,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 192,
2018-06-24 07:19:44 +00:00
EndPos: 196,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 192,
2018-06-24 07:19:44 +00:00
EndPos: 196,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 192,
2018-06-24 07:19:44 +00:00
EndPos: 196,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 198,
2018-06-24 07:19:44 +00:00
EndPos: 210,
},
Variadic: true,
ByRef: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 198,
2018-06-24 07:19:44 +00:00
EndPos: 201,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 198,
2018-06-24 07:19:44 +00:00
EndPos: 201,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 206,
2018-06-24 07:19:44 +00:00
EndPos: 210,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 206,
2018-06-24 07:19:44 +00:00
EndPos: 210,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-01-13 01:40:08 +00:00
},
},
},
}
2019-12-26 15:57:56 +00:00
php7parser := php7.NewParser([]byte(src), "7.4")
2018-04-10 12:23:13 +00:00
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-02-08 10:48:38 +00:00
}
func TestPhp5ParameterNode(t *testing.T) {
src := `<?
function foo(bar $bar=null, baz &...$baz) {}
class foo {public function foo(bar $bar=null, baz &...$baz) {}}
function(bar $bar=null, baz &...$baz) {};
static function(bar $bar=null, baz &...$baz) {};
`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 211,
},
2018-02-08 10:48:38 +00:00
Stmts: []node.Node{
&stmt.Function{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 6,
2018-06-24 07:19:44 +00:00
EndPos: 50,
},
2018-02-08 10:48:38 +00:00
ReturnsRef: false,
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 15,
2018-06-24 07:19:44 +00:00
EndPos: 18,
},
Value: "foo",
},
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 19,
2018-06-24 07:19:44 +00:00
EndPos: 32,
},
ByRef: false,
Variadic: false,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 19,
2018-06-24 07:19:44 +00:00
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 19,
2018-06-24 07:19:44 +00:00
EndPos: 22,
},
Value: "bar",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 23,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 23,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 32,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 32,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 32,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 34,
2018-06-24 07:19:44 +00:00
EndPos: 46,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 34,
2018-06-24 07:19:44 +00:00
EndPos: 37,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 34,
2018-06-24 07:19:44 +00:00
EndPos: 37,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 42,
2018-06-24 07:19:44 +00:00
EndPos: 46,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
2019-03-10 21:37:01 +00:00
StartPos: 42,
2018-06-24 07:19:44 +00:00
EndPos: 46,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-02-08 10:48:38 +00:00
},
&stmt.Class{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 53,
2018-06-24 07:19:44 +00:00
EndPos: 116,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 59,
2018-06-24 07:19:44 +00:00
EndPos: 62,
},
Value: "foo",
},
2018-02-08 10:48:38 +00:00
Stmts: []node.Node{
&stmt.ClassMethod{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 64,
2018-06-24 07:19:44 +00:00
EndPos: 115,
},
ReturnsRef: false,
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 80,
2018-06-24 07:19:44 +00:00
EndPos: 83,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 64,
2018-06-24 07:19:44 +00:00
EndPos: 70,
},
Value: "public",
},
},
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 84,
2018-06-24 07:19:44 +00:00
EndPos: 97,
},
ByRef: false,
Variadic: false,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 84,
2018-06-24 07:19:44 +00:00
EndPos: 87,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 84,
2018-06-24 07:19:44 +00:00
EndPos: 87,
},
Value: "bar",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 88,
2018-06-24 07:19:44 +00:00
EndPos: 92,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 88,
2018-06-24 07:19:44 +00:00
EndPos: 92,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 93,
2018-06-24 07:19:44 +00:00
EndPos: 97,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 93,
2018-06-24 07:19:44 +00:00
EndPos: 97,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 93,
2018-06-24 07:19:44 +00:00
EndPos: 97,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 99,
2018-06-24 07:19:44 +00:00
EndPos: 111,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 99,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 99,
2018-06-24 07:19:44 +00:00
EndPos: 102,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 111,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 107,
2018-06-24 07:19:44 +00:00
EndPos: 111,
},
Value: "baz",
},
},
},
},
2018-06-03 06:35:44 +00:00
Stmt: &stmt.StmtList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 3,
EndLine: 3,
2019-03-10 21:37:01 +00:00
StartPos: 113,
2018-06-24 07:19:44 +00:00
EndPos: 115,
},
2018-06-03 06:35:44 +00:00
Stmts: []node.Node{},
},
2018-02-08 10:48:38 +00:00
},
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 119,
2018-06-24 07:19:44 +00:00
EndPos: 160,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.Closure{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 119,
2018-06-24 07:19:44 +00:00
EndPos: 159,
},
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 128,
2018-06-24 07:19:44 +00:00
EndPos: 141,
},
Variadic: false,
ByRef: false,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 128,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 128,
2018-06-24 07:19:44 +00:00
EndPos: 131,
},
Value: "bar",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 132,
2018-06-24 07:19:44 +00:00
EndPos: 136,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 132,
2018-06-24 07:19:44 +00:00
EndPos: 136,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 137,
2018-06-24 07:19:44 +00:00
EndPos: 141,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 137,
2018-06-24 07:19:44 +00:00
EndPos: 141,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 137,
2018-06-24 07:19:44 +00:00
EndPos: 141,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 143,
2018-06-24 07:19:44 +00:00
EndPos: 155,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 143,
2018-06-24 07:19:44 +00:00
EndPos: 146,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 143,
2018-06-24 07:19:44 +00:00
EndPos: 146,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 151,
2018-06-24 07:19:44 +00:00
EndPos: 155,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
2019-03-10 21:37:01 +00:00
StartPos: 151,
2018-06-24 07:19:44 +00:00
EndPos: 155,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-02-08 10:48:38 +00:00
},
},
&stmt.Expression{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 163,
2018-06-24 07:19:44 +00:00
EndPos: 211,
},
2018-02-08 10:48:38 +00:00
Expr: &expr.Closure{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 163,
2018-06-24 07:19:44 +00:00
EndPos: 210,
},
PhpDocComment: "",
ReturnsRef: false,
Static: true,
Params: []node.Node{
&node.Parameter{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 179,
2018-06-24 07:19:44 +00:00
EndPos: 192,
},
ByRef: false,
Variadic: false,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 179,
2018-06-24 07:19:44 +00:00
EndPos: 182,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 179,
2018-06-24 07:19:44 +00:00
EndPos: 182,
},
Value: "bar",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 183,
2018-06-24 07:19:44 +00:00
EndPos: 187,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 183,
2018-06-24 07:19:44 +00:00
EndPos: 187,
},
Value: "bar",
},
},
DefaultValue: &expr.ConstFetch{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 188,
2018-06-24 07:19:44 +00:00
EndPos: 192,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 188,
2018-06-24 07:19:44 +00:00
EndPos: 192,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 188,
2018-06-24 07:19:44 +00:00
EndPos: 192,
},
Value: "null",
},
},
},
},
},
&node.Parameter{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 194,
2018-06-24 07:19:44 +00:00
EndPos: 206,
},
ByRef: true,
Variadic: true,
VariableType: &name.Name{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 194,
2018-06-24 07:19:44 +00:00
EndPos: 197,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 194,
2018-06-24 07:19:44 +00:00
EndPos: 197,
},
Value: "baz",
},
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 202,
2018-06-24 07:19:44 +00:00
EndPos: 206,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
2019-03-10 21:37:01 +00:00
StartPos: 202,
2018-06-24 07:19:44 +00:00
EndPos: 206,
},
Value: "baz",
},
},
},
},
Stmts: []node.Node{},
2018-02-08 10:48:38 +00:00
},
},
},
}
2019-12-26 15:57:56 +00:00
php5parser := php5.NewParser([]byte(src), "5.6")
2018-04-10 12:23:13 +00:00
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2018-01-13 01:40:08 +00:00
}
func TestCommentEndFile(t *testing.T) {
src := `<? //comment at the end)`
2018-05-02 09:14:24 +00:00
expected := &node.Root{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
}
2019-12-26 15:57:56 +00:00
php7parser := php7.NewParser([]byte(src), "7.4")
2018-04-10 12:23:13 +00:00
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
2019-12-26 15:57:56 +00:00
php5parser := php5.NewParser([]byte(src), "5.6")
2018-04-10 12:23:13 +00:00
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}