php-parser/node/stmt/t_trait_use_test.go

823 lines
18 KiB
Go
Raw Normal View History

2018-02-09 12:48:10 +00:00
package stmt_test
import (
"testing"
"gotest.tools/assert"
2018-04-29 19:34:24 +00:00
"github.com/z7zmey/php-parser/node/name"
2018-06-24 07:19:44 +00:00
"github.com/z7zmey/php-parser/position"
2018-04-29 19:34:24 +00:00
2018-02-09 12:48:10 +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 TestTraitUse(t *testing.T) {
src := `<? class Foo { use 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: 25,
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.Class{
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: 25,
},
2018-02-09 12:48:10 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 23,
},
2018-02-09 12:48:10 +00:00
Traits: []node.Node{
&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-09 12:48:10 +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-09 12:48:10 +00:00
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 22,
EndPos: 23,
},
},
2018-02-09 12:48:10 +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-09 12:48:10 +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-02-09 12:48:10 +00:00
}
func TestTraitsUse(t *testing.T) {
src := `<? class Foo { use 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: 30,
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.Class{
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 12:48:10 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 28,
},
2018-02-09 12:48:10 +00:00
Traits: []node.Node{
&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-09 12:48:10 +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-09 12:48:10 +00:00
},
},
&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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
2018-02-09 12:48:10 +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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "Baz",
},
2018-02-09 12:48:10 +00:00
},
},
},
TraitAdaptationList: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 27,
EndPos: 28,
},
},
2018-02-09 12:48:10 +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-09 12:48:10 +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-02-09 12:48:10 +00:00
}
2018-02-13 10:16:53 +00:00
func TestTraitsUseEmptyAdaptations(t *testing.T) {
src := `<? class Foo { use 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: 32,
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.Class{
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: 32,
},
2018-02-13 10:16:53 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 30,
},
2018-02-13 10:16:53 +00:00
Traits: []node.Node{
&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-13 10:16:53 +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-13 10:16:53 +00:00
},
},
&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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
2018-02-13 10:16:53 +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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "Baz",
},
2018-02-13 10:16:53 +00:00
},
},
},
2018-06-24 07:19:44 +00:00
TraitAdaptationList: &stmt.TraitAdaptationList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 30,
},
},
2018-02-13 10:16:53 +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-13 10:16:53 +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-02-13 10:16:53 +00:00
}
func TestTraitsUseModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public; } }`
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: 48,
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.Class{
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: 48,
},
2018-02-13 10:16:53 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 46,
},
2018-02-13 10:16:53 +00:00
Traits: []node.Node{
&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-13 10:16:53 +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-13 10:16:53 +00:00
},
},
&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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
2018-02-13 10:16:53 +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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "Baz",
},
2018-02-13 10:16:53 +00:00
},
},
},
2018-04-29 19:34:24 +00:00
TraitAdaptationList: &stmt.TraitAdaptationList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 46,
},
2018-04-29 19:34:24 +00:00
Adaptations: []node.Node{
&stmt.TraitUseAlias{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 43,
},
2018-04-29 19:34:24 +00:00
Ref: &stmt.TraitMethodRef{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Value: "one",
},
},
Modifier: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 37,
2018-06-24 07:19:44 +00:00
EndPos: 43,
},
Value: "public",
2018-04-29 19:34:24 +00:00
},
2018-02-13 10:16:53 +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-13 10:16:53 +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-02-13 10:16:53 +00:00
}
func TestTraitsUseAliasModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public two; } }`
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: 52,
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.Class{
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: 52,
},
2018-02-13 10:16:53 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-13 10:16:53 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 50,
},
2018-02-13 10:16:53 +00:00
Traits: []node.Node{
&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-13 10:16:53 +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-13 10:16:53 +00:00
},
},
&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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
2018-02-13 10:16:53 +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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "Baz",
},
2018-02-13 10:16:53 +00:00
},
},
},
2018-04-29 19:34:24 +00:00
TraitAdaptationList: &stmt.TraitAdaptationList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 50,
},
2018-04-29 19:34:24 +00:00
Adaptations: []node.Node{
&stmt.TraitUseAlias{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
2018-04-29 19:34:24 +00:00
Ref: &stmt.TraitMethodRef{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Value: "one",
},
},
Modifier: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 37,
2018-06-24 07:19:44 +00:00
EndPos: 43,
},
Value: "public",
},
Alias: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 44,
2018-06-24 07:19:44 +00:00
EndPos: 47,
},
Value: "two",
2018-04-29 19:34:24 +00:00
},
2018-02-13 10:16:53 +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-13 10:16:53 +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-02-13 10:16:53 +00:00
}
2018-02-09 12:48:10 +00:00
func TestTraitsUseAdaptions(t *testing.T) {
src := `<? class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }`
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: 80,
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.Class{
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: 80,
},
2018-02-09 12:48:10 +00:00
PhpDocComment: "",
2018-06-24 07:19:44 +00:00
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 9,
2018-06-24 07:19:44 +00:00
EndPos: 12,
},
Value: "Foo",
},
2018-02-09 12:48:10 +00:00
Stmts: []node.Node{
&stmt.TraitUse{
2018-06-24 07:19:44 +00:00
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: 78,
},
2018-02-09 12:48:10 +00:00
Traits: []node.Node{
&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-09 12:48:10 +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-09 12:48:10 +00:00
},
},
&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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
2018-02-09 12:48:10 +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: 24,
2018-06-24 07:19:44 +00:00
EndPos: 27,
},
Value: "Baz",
},
2018-02-09 12:48:10 +00:00
},
},
},
2018-04-29 19:34:24 +00:00
TraitAdaptationList: &stmt.TraitAdaptationList{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 28,
2018-06-24 07:19:44 +00:00
EndPos: 78,
},
2018-04-29 19:34:24 +00:00
Adaptations: []node.Node{
&stmt.TraitUsePrecedence{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 58,
},
2018-04-29 19:34:24 +00:00
Ref: &stmt.TraitMethodRef{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 30,
2018-06-24 07:19:44 +00:00
EndPos: 38,
},
2018-04-29 19:34:24 +00:00
Trait: &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: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
2018-04-29 19:34:24 +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: 30,
2018-06-24 07:19:44 +00:00
EndPos: 33,
},
Value: "Bar",
},
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 35,
2018-06-24 07:19:44 +00:00
EndPos: 38,
2018-04-29 19:34:24 +00:00
},
2018-06-24 07:19:44 +00:00
Value: "one",
2018-02-09 12:48:10 +00:00
},
},
2018-04-29 19:34:24 +00:00
Insteadof: []node.Node{
&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: 49,
2018-06-24 07:19:44 +00:00
EndPos: 52,
},
2018-04-29 19:34:24 +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: 49,
2018-06-24 07:19:44 +00:00
EndPos: 52,
},
Value: "Baz",
},
2018-04-29 19:34:24 +00:00
},
2018-02-09 12:48:10 +00:00
},
2018-04-29 19:34:24 +00:00
&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: 54,
2018-06-24 07:19:44 +00:00
EndPos: 58,
},
2018-04-29 19:34:24 +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: 54,
2018-06-24 07:19:44 +00:00
EndPos: 58,
},
Value: "Quux",
},
2018-04-29 19:34:24 +00:00
},
2018-02-09 12:48:10 +00:00
},
},
},
2018-04-29 19:34:24 +00:00
&stmt.TraitUseAlias{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 75,
},
2018-04-29 19:34:24 +00:00
Ref: &stmt.TraitMethodRef{
2018-06-24 07:19:44 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 60,
2018-06-24 07:19:44 +00:00
EndPos: 68,
},
2018-04-29 19:34:24 +00:00
Trait: &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: 60,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
2018-04-29 19:34:24 +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: 60,
2018-06-24 07:19:44 +00:00
EndPos: 63,
},
Value: "Baz",
},
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 65,
2018-06-24 07:19:44 +00:00
EndPos: 68,
2018-04-29 19:34:24 +00:00
},
2018-06-24 07:19:44 +00:00
Value: "one",
},
},
Alias: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
2019-03-10 21:37:01 +00:00
StartPos: 72,
2018-06-24 07:19:44 +00:00
EndPos: 75,
2018-02-09 12:48:10 +00:00
},
2018-06-24 07:19:44 +00:00
Value: "two",
2018-02-09 12:48:10 +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-09 12:48:10 +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-02-09 12:48:10 +00:00
}