2018-02-09 10:36:31 +00:00
|
|
|
package stmt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-02-13 20:18:07 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
|
2018-06-24 07:19:44 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/name"
|
|
|
|
"github.com/z7zmey/php-parser/position"
|
|
|
|
|
2018-02-09 10:36:31 +00:00
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
|
|
|
"github.com/z7zmey/php-parser/php5"
|
|
|
|
"github.com/z7zmey/php-parser/php7"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleUse(t *testing.T) {
|
|
|
|
src := `<? use 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: 11,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 11,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 13:08:08 +00:00
|
|
|
func TestUseFullyQualified(t *testing.T) {
|
|
|
|
src := `<? use \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: 12,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 12,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 11,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 11,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 11,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseFullyQualifiedAlias(t *testing.T) {
|
|
|
|
src := `<? use \Foo as Bar;`
|
|
|
|
|
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: 19,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 19,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 18,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 11,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 8,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 11,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 15,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 18,
|
2018-02-12 13:08:08 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "Bar",
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 10:36:31 +00:00
|
|
|
func TestUseList(t *testing.T) {
|
|
|
|
src := `<? use Foo, Bar;`
|
|
|
|
|
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: 16,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 16,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseListAlias(t *testing.T) {
|
|
|
|
src := `<? use Foo, Bar as Baz;`
|
|
|
|
|
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: 23,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 23,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 22,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 19,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 22,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "Baz",
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseListFunctionType(t *testing.T) {
|
2018-02-12 13:08:08 +00:00
|
|
|
src := `<? use function Foo, \Bar;`
|
|
|
|
|
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: 26,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 26,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "function",
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 22,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 25,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 22,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 25,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 22,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 25,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseListFunctionTypeAliases(t *testing.T) {
|
|
|
|
src := `<? use function Foo as foo, \Bar as bar;`
|
2018-02-09 10:36:31 +00:00
|
|
|
|
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: 40,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 40,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "function",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 26,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 23,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 26,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "foo",
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 29,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 39,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 29,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 32,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 29,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 36,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 39,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "bar",
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseListConstType(t *testing.T) {
|
2018-02-12 13:08:08 +00:00
|
|
|
src := `<? use const Foo, \Bar;`
|
|
|
|
|
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: 23,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 23,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Value: "const",
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 19,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 22,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 19,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 22,
|
|
|
|
},
|
2018-02-12 13:08:08 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 19,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 22,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08: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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-12 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseListConstTypeAliases(t *testing.T) {
|
|
|
|
src := `<? use const Foo as foo, \Bar as bar;`
|
2018-02-09 10:36:31 +00:00
|
|
|
|
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: 37,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.UseList{
|
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: 37,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Value: "const",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 23,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 20,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 23,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "foo",
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 33,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 36,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "bar",
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGroupUse(t *testing.T) {
|
|
|
|
src := `<? use Foo\{Bar, Baz};`
|
|
|
|
|
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: 22,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.GroupUse{
|
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: 22,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Prefix: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 20,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 20,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 20,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGroupUseAlias(t *testing.T) {
|
|
|
|
src := `<? use Foo\{Bar, Baz as quux};`
|
|
|
|
|
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: 30,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.GroupUse{
|
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: 30,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Prefix: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 28,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 20,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 17,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 20,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 24,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 28,
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: "quux",
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFunctionGroupUse(t *testing.T) {
|
|
|
|
src := `<? use function Foo\{Bar, Baz};`
|
|
|
|
|
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: 31,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.GroupUse{
|
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: 31,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 15,
|
|
|
|
},
|
|
|
|
Value: "function",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Prefix: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 16,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 21,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 24,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 21,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 24,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 21,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 24,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 26,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConstGroupUse(t *testing.T) {
|
|
|
|
src := `<? use const Foo\{Bar, Baz};`
|
|
|
|
|
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: 28,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.GroupUse{
|
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: 28,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Value: "const",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Prefix: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 13,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 16,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 23,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 26,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 23,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 26,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 23,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 26,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-09 10:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMixedGroupUse(t *testing.T) {
|
|
|
|
src := `<? use Foo\{const Bar, function Baz};`
|
|
|
|
|
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: 37,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.GroupUse{
|
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: 37,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Prefix: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 7,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 10,
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 12,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 17,
|
|
|
|
},
|
|
|
|
Value: "const",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 18,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 21,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 32,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 35,
|
|
|
|
},
|
|
|
|
UseType: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 23,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
Value: "function",
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Use: &name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 32,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 35,
|
|
|
|
},
|
2018-02-09 10:36:31 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
2019-03-10 21:37:01 +00:00
|
|
|
StartPos: 32,
|
2018-06-24 07:19:44 +00:00
|
|
|
EndPos: 35,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
2018-02-09 10:36:31 +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()
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-19 11:00:58 +00:00
|
|
|
}
|