2018-02-09 12:48:10 +00:00
|
|
|
package stmt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2018-02-19 11:00:58 +00:00
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 22,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
2018-02-09 12:48:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 27,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
2018-02-09 12:48:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 30,
|
|
|
|
},
|
|
|
|
},
|
2018-02-13 10:16:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 29,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Value: "one",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Modifier: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 38,
|
|
|
|
EndPos: 43,
|
|
|
|
},
|
|
|
|
Value: "public",
|
2018-04-29 19:34:24 +00:00
|
|
|
},
|
2018-02-13 10:16:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 29,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Value: "one",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Modifier: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 38,
|
|
|
|
EndPos: 43,
|
|
|
|
},
|
|
|
|
Value: "public",
|
|
|
|
},
|
|
|
|
Alias: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 45,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
Value: "two",
|
2018-04-29 19:34:24 +00:00
|
|
|
},
|
2018-02-13 10:16:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-13 10:16:53 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 4,
|
|
|
|
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,
|
|
|
|
StartPos: 10,
|
|
|
|
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,
|
|
|
|
StartPos: 16,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 20,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 25,
|
|
|
|
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,
|
|
|
|
StartPos: 29,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
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,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 36,
|
|
|
|
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,
|
|
|
|
StartPos: 50,
|
|
|
|
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,
|
|
|
|
StartPos: 50,
|
|
|
|
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,
|
|
|
|
StartPos: 55,
|
|
|
|
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,
|
|
|
|
StartPos: 55,
|
|
|
|
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,
|
|
|
|
StartPos: 61,
|
|
|
|
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,
|
|
|
|
StartPos: 61,
|
|
|
|
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,
|
|
|
|
StartPos: 61,
|
|
|
|
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,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
Value: "Baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 66,
|
|
|
|
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,
|
|
|
|
StartPos: 73,
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-09 12:48:10 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|