Names interface
This commit is contained in:
@@ -40,3 +40,8 @@ func (n *FullyQualified) Walk(v walker.Visitor) {
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
|
||||
// GetParts returns the name parts
|
||||
func (n *FullyQualified) GetParts() []node.Node {
|
||||
return n.Parts
|
||||
}
|
||||
|
||||
@@ -40,3 +40,8 @@ func (n *Name) Walk(v walker.Visitor) {
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
|
||||
// GetParts returns the name parts
|
||||
func (n *Name) GetParts() []node.Node {
|
||||
return n.Parts
|
||||
}
|
||||
|
||||
@@ -40,3 +40,8 @@ func (n *Relative) Walk(v walker.Visitor) {
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
|
||||
// GetParts returns the name parts
|
||||
func (n *Relative) GetParts() []node.Node {
|
||||
return n.Parts
|
||||
}
|
||||
|
||||
11
node/name/names.go
Normal file
11
node/name/names.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
// Names is generalizing the Name types
|
||||
type Names interface {
|
||||
node.Node
|
||||
GetParts() []node.Node
|
||||
}
|
||||
@@ -96,3 +96,18 @@ func TestRelative(t *testing.T) {
|
||||
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestNamePartsGetter(t *testing.T) {
|
||||
expected := []node.Node{
|
||||
&name.NamePart{Value: "a"},
|
||||
&name.NamePart{Value: "b"},
|
||||
}
|
||||
|
||||
plainName := &name.Name{Parts: expected}
|
||||
relativeName := &name.Relative{Parts: expected}
|
||||
fullyQualifiedName := &name.FullyQualified{Parts: expected}
|
||||
|
||||
assertEqual(t, expected, plainName.GetParts())
|
||||
assertEqual(t, expected, relativeName.GetParts())
|
||||
assertEqual(t, expected, fullyQualifiedName.GetParts())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user