rename meta to freefloating; refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
@@ -9,15 +9,16 @@ import (
|
||||
|
||||
// FullyQualified node
|
||||
type FullyQualified struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
}
|
||||
|
||||
// NewFullyQualified node constructor
|
||||
func NewFullyQualified(Parts []node.Node) *FullyQualified {
|
||||
return &FullyQualified{
|
||||
Parts: Parts,
|
||||
FreeFloating: nil,
|
||||
Parts: Parts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *FullyQualified) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *FullyQualified) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *FullyQualified) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
@@ -9,15 +9,16 @@ import (
|
||||
|
||||
// Name node
|
||||
type Name struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
}
|
||||
|
||||
// NewName node constructor
|
||||
func NewName(Parts []node.Node) *Name {
|
||||
return &Name{
|
||||
Parts: Parts,
|
||||
FreeFloating: nil,
|
||||
Parts: Parts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Name) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Name) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Name) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// NamePart node
|
||||
type NamePart struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewNamePart node constructor
|
||||
func NewNamePart(Value string) *NamePart {
|
||||
return &NamePart{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *NamePart) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *NamePart) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *NamePart) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
@@ -9,15 +9,16 @@ import (
|
||||
|
||||
// Relative node
|
||||
type Relative struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
}
|
||||
|
||||
// NewRelative node constructor
|
||||
func NewRelative(Parts []node.Node) *Relative {
|
||||
return &Relative{
|
||||
Parts: Parts,
|
||||
FreeFloating: nil,
|
||||
Parts: Parts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Relative) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Relative) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Relative) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
48
node/name/t_freefloating_test.go
Normal file
48
node/name/t_freefloating_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package name_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
)
|
||||
|
||||
var expected freefloating.Collection = freefloating.Collection{
|
||||
freefloating.Start: []freefloating.String{
|
||||
{
|
||||
StringType: freefloating.WhiteSpaceType,
|
||||
Value: " ",
|
||||
Position: nil,
|
||||
},
|
||||
{
|
||||
StringType: freefloating.CommentType,
|
||||
Value: "//comment\n",
|
||||
Position: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var nodes = []node.Node{
|
||||
&name.FullyQualified{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&name.NamePart{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&name.Name{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&name.Relative{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
}
|
||||
|
||||
func TestMeta(t *testing.T) {
|
||||
for _, n := range nodes {
|
||||
actual := *n.GetFreeFloating()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package name_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
var nodes = []node.Node{
|
||||
&name.FullyQualified{},
|
||||
&name.NamePart{},
|
||||
&name.Name{},
|
||||
&name.Relative{},
|
||||
}
|
||||
|
||||
func TestMeta(t *testing.T) {
|
||||
expected := &meta.Collection{
|
||||
&meta.Data{
|
||||
Value: "//comment\n",
|
||||
Type: meta.CommentType,
|
||||
Position: nil,
|
||||
},
|
||||
&meta.Data{
|
||||
Value: " ",
|
||||
Type: meta.WhiteSpaceType,
|
||||
Position: nil,
|
||||
},
|
||||
}
|
||||
for _, n := range nodes {
|
||||
n.GetMeta().Push(*expected...)
|
||||
actual := n.GetMeta()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,20 @@ package name_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"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 assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
diff := pretty.Compare(expected, actual)
|
||||
|
||||
if diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
} else {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
src := `<? foo();`
|
||||
|
||||
@@ -89,12 +76,12 @@ func TestName(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFullyQualified(t *testing.T) {
|
||||
@@ -157,12 +144,12 @@ func TestFullyQualified(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestRelative(t *testing.T) {
|
||||
@@ -225,12 +212,12 @@ func TestRelative(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestNamePartsGetter(t *testing.T) {
|
||||
@@ -243,7 +230,7 @@ func TestNamePartsGetter(t *testing.T) {
|
||||
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())
|
||||
assert.DeepEqual(t, expected, plainName.GetParts())
|
||||
assert.DeepEqual(t, expected, relativeName.GetParts())
|
||||
assert.DeepEqual(t, expected, fullyQualifiedName.GetParts())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package name_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
@@ -11,6 +13,6 @@ func TestPosition(t *testing.T) {
|
||||
for _, n := range nodes {
|
||||
n.SetPosition(expected)
|
||||
actual := n.GetPosition()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package name_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
var nameNodesTests = []struct {
|
||||
@@ -56,31 +55,25 @@ func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
|
||||
|
||||
func TestNameVisitorDisableChildren(t *testing.T) {
|
||||
for _, tt := range nameNodesTests {
|
||||
v := &visitorMock{false, nil}
|
||||
v := &visitorMock{false, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := []string{}
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNameVisitor(t *testing.T) {
|
||||
for _, tt := range nameNodesTests {
|
||||
v := &visitorMock{true, nil}
|
||||
v := &visitorMock{true, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := tt.expectedVisitedKeys
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +84,6 @@ func TestNameAttributes(t *testing.T) {
|
||||
expected := tt.expectedAttributes
|
||||
actual := tt.node.Attributes()
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user