rename meta to freefloating; refactoring

This commit is contained in:
z7zmey
2019-02-13 22:18:07 +02:00
parent a7082117d9
commit b3800a2595
309 changed files with 9671 additions and 10115 deletions

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Assign node
type Assign struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewAssign node constructor
func NewAssign(Variable node.Node, Expression node.Node) *Assign {
return &Assign{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Assign) GetPosition() *position.Position {
return n.Position
}
func (n *Assign) GetMeta() *meta.Collection {
return &n.Meta
func (n *Assign) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Reference node
type Reference struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewReference node constructor
func NewReference(Variable node.Node, Expression node.Node) *Reference {
return &Reference{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Reference) GetPosition() *position.Position {
return n.Position
}
func (n *Reference) GetMeta() *meta.Collection {
return &n.Meta
func (n *Reference) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// BitwiseAnd node
type BitwiseAnd struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewBitwiseAnd node constructor
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *BitwiseAnd) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseAnd) GetMeta() *meta.Collection {
return &n.Meta
func (n *BitwiseAnd) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// BitwiseOr node
type BitwiseOr struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewBitwiseOr node constructor
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
return &BitwiseOr{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *BitwiseOr) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseOr) GetMeta() *meta.Collection {
return &n.Meta
func (n *BitwiseOr) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// BitwiseXor node
type BitwiseXor struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewBitwiseXor node constructor
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
return &BitwiseXor{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *BitwiseXor) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseXor) GetMeta() *meta.Collection {
return &n.Meta
func (n *BitwiseXor) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Concat node
type Concat struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewConcat node constructor
func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Concat) GetPosition() *position.Position {
return n.Position
}
func (n *Concat) GetMeta() *meta.Collection {
return &n.Meta
func (n *Concat) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Div node
type Div struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewDiv node constructor
func NewDiv(Variable node.Node, Expression node.Node) *Div {
return &Div{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Div) GetPosition() *position.Position {
return n.Position
}
func (n *Div) GetMeta() *meta.Collection {
return &n.Meta
func (n *Div) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Minus node
type Minus struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewMinus node constructor
func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Minus) GetPosition() *position.Position {
return n.Position
}
func (n *Minus) GetMeta() *meta.Collection {
return &n.Meta
func (n *Minus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Mod node
type Mod struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewMod node constructor
func NewMod(Variable node.Node, Expression node.Node) *Mod {
return &Mod{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Mod) GetPosition() *position.Position {
return n.Position
}
func (n *Mod) GetMeta() *meta.Collection {
return &n.Meta
func (n *Mod) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Mul node
type Mul struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewMul node constructor
func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Mul) GetPosition() *position.Position {
return n.Position
}
func (n *Mul) GetMeta() *meta.Collection {
return &n.Meta
func (n *Mul) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Plus node
type Plus struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewPlus node constructor
func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Plus) GetPosition() *position.Position {
return n.Position
}
func (n *Plus) GetMeta() *meta.Collection {
return &n.Meta
func (n *Plus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// Pow node
type Pow struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewPow node constructor
func NewPow(Variable node.Node, Expression node.Node) *Pow {
return &Pow{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *Pow) GetPosition() *position.Position {
return n.Position
}
func (n *Pow) GetMeta() *meta.Collection {
return &n.Meta
func (n *Pow) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// ShiftLeft node
type ShiftLeft struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewShiftLeft node constructor
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *ShiftLeft) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftLeft) GetMeta() *meta.Collection {
return &n.Meta
func (n *ShiftLeft) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -1,7 +1,7 @@
package assign
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,17 +9,18 @@ import (
// ShiftRight node
type ShiftRight struct {
Meta meta.Collection
Position *position.Position
Variable node.Node
Expression node.Node
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewShiftRight node constructor
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
return &ShiftRight{
Variable: Variable,
Expression: Expression,
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
@@ -33,8 +34,8 @@ func (n *ShiftRight) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftRight) GetMeta() *meta.Collection {
return &n.Meta
func (n *ShiftRight) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map

View File

@@ -2,14 +2,13 @@ package assign_test
import (
"bytes"
"reflect"
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/position"
"github.com/kylelemons/godebug/pretty"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
@@ -18,18 +17,6 @@ import (
"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 TestReference(t *testing.T) {
src := `<? $a =& $b;`
@@ -97,12 +84,12 @@ func TestReference(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 TestReferenceNew(t *testing.T) {
@@ -182,12 +169,12 @@ func TestReferenceNew(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 TestReferenceArgs(t *testing.T) {
@@ -304,12 +291,12 @@ func TestReferenceArgs(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 TestAssign(t *testing.T) {
@@ -379,12 +366,12 @@ func TestAssign(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 TestBitwiseAnd(t *testing.T) {
@@ -454,12 +441,12 @@ func TestBitwiseAnd(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 TestBitwiseOr(t *testing.T) {
@@ -529,12 +516,12 @@ func TestBitwiseOr(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 TestBitwiseXor(t *testing.T) {
@@ -604,12 +591,12 @@ func TestBitwiseXor(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 TestConcat(t *testing.T) {
@@ -679,12 +666,12 @@ func TestConcat(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 TestDiv(t *testing.T) {
@@ -754,12 +741,12 @@ func TestDiv(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 TestMinus(t *testing.T) {
@@ -829,12 +816,12 @@ func TestMinus(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 TestMod(t *testing.T) {
@@ -904,12 +891,12 @@ func TestMod(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 TestMul(t *testing.T) {
@@ -979,12 +966,12 @@ func TestMul(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 TestPlus(t *testing.T) {
@@ -1054,12 +1041,12 @@ func TestPlus(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 TestPow(t *testing.T) {
@@ -1129,12 +1116,12 @@ func TestPow(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 TestShiftLeft(t *testing.T) {
@@ -1204,12 +1191,12 @@ func TestShiftLeft(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 TestShiftRight(t *testing.T) {
@@ -1279,10 +1266,10 @@ func TestShiftRight(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)
}

View File

@@ -0,0 +1,81 @@
package assign_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr/assign"
)
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{
&assign.Reference{
FreeFloating: expected,
},
&assign.Assign{
FreeFloating: expected,
},
&assign.BitwiseAnd{
FreeFloating: expected,
},
&assign.BitwiseOr{
FreeFloating: expected,
},
&assign.BitwiseXor{
FreeFloating: expected,
},
&assign.Concat{
FreeFloating: expected,
},
&assign.Div{
FreeFloating: expected,
},
&assign.Minus{
FreeFloating: expected,
},
&assign.Mod{
FreeFloating: expected,
},
&assign.Mul{
FreeFloating: expected,
},
&assign.Plus{
FreeFloating: expected,
},
&assign.Pow{
FreeFloating: expected,
},
&assign.ShiftLeft{
FreeFloating: expected,
},
&assign.ShiftRight{
FreeFloating: expected,
},
&assign.ShiftRight{
FreeFloating: expected,
},
}
func TestMeta(t *testing.T) {
for _, n := range nodes {
actual := *n.GetFreeFloating()
assert.DeepEqual(t, expected, actual)
}
}

View File

@@ -1,49 +0,0 @@
package assign_test
import (
"testing"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&assign.Reference{},
&assign.Assign{},
&assign.BitwiseAnd{},
&assign.BitwiseOr{},
&assign.BitwiseXor{},
&assign.Concat{},
&assign.Div{},
&assign.Minus{},
&assign.Mod{},
&assign.Mul{},
&assign.Plus{},
&assign.Pow{},
&assign.ShiftLeft{},
&assign.ShiftRight{},
&assign.ShiftRight{},
}
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)
}
}

View File

@@ -3,6 +3,8 @@ package assign_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)
}
}

View File

@@ -1,15 +1,13 @@
package assign_test
import (
"reflect"
"testing"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/kylelemons/godebug/pretty"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/walker"
)
@@ -24,7 +22,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Assign{
@@ -32,7 +30,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.BitwiseAnd{
@@ -40,7 +38,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.BitwiseOr{
@@ -48,7 +46,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.BitwiseXor{
@@ -56,7 +54,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Concat{
@@ -64,7 +62,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Div{
@@ -72,7 +70,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Minus{
@@ -80,7 +78,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Mod{
@@ -88,7 +86,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Mul{
@@ -96,7 +94,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Plus{
@@ -104,7 +102,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.Pow{
@@ -112,7 +110,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.ShiftLeft{
@@ -120,7 +118,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
{
&assign.ShiftRight{
@@ -128,7 +126,7 @@ var nodesToTest = []struct {
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
nil,
},
}
@@ -150,31 +148,25 @@ func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {
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 TestVisitor(t *testing.T) {
for _, tt := range nodesToTest {
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)
}
}
@@ -185,9 +177,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)
}
}