Names interface

This commit is contained in:
z7zmey
2018-02-27 15:09:40 +02:00
parent 7976de4d11
commit 25798f6445
6 changed files with 102 additions and 76 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
View 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
}

View File

@@ -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())
}