rename meta to freefloating; refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Array node
|
||||
type Array struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewArray node constructor
|
||||
func NewArray(Expr node.Node) *Array {
|
||||
return &Array{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Array) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Array) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Array) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Bool node
|
||||
type Bool struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewBool node constructor
|
||||
func NewBool(Expr node.Node) *Bool {
|
||||
return &Bool{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Bool) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Bool) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Bool) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Double node
|
||||
type Double struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewDouble node constructor
|
||||
func NewDouble(Expr node.Node) *Double {
|
||||
return &Double{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Double) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Double) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Double) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Int node
|
||||
type Int struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewInt node constructor
|
||||
func NewInt(Expr node.Node) *Int {
|
||||
return &Int{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Int) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Int) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Int) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Object node
|
||||
type Object struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewObject node constructor
|
||||
func NewObject(Expr node.Node) *Object {
|
||||
return &Object{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Object) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Object) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Object) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// String node
|
||||
type String struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewString node constructor
|
||||
func NewString(Expr node.Node) *String {
|
||||
return &String{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *String) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *String) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *String) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cast
|
||||
|
||||
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 (
|
||||
|
||||
// Unset node
|
||||
type Unset struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewUnset node constructor
|
||||
func NewUnset(Expr node.Node) *Unset {
|
||||
return &Unset{
|
||||
Expr: Expr,
|
||||
FreeFloating: nil,
|
||||
Expr: Expr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Unset) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Unset) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Unset) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -2,10 +2,9 @@ package cast_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
@@ -16,18 +15,6 @@ import (
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
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 TestArray(t *testing.T) {
|
||||
src := `<? (array)$a;`
|
||||
|
||||
@@ -78,12 +65,12 @@ func TestArray(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 TestBool(t *testing.T) {
|
||||
@@ -136,12 +123,12 @@ func TestBool(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 TestBoolShort(t *testing.T) {
|
||||
@@ -194,12 +181,12 @@ func TestBoolShort(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 TestDouble(t *testing.T) {
|
||||
@@ -252,12 +239,12 @@ func TestDouble(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 TestCastFloat(t *testing.T) {
|
||||
@@ -310,12 +297,12 @@ func TestCastFloat(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 TestInt(t *testing.T) {
|
||||
@@ -368,12 +355,12 @@ func TestInt(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 TestIntShort(t *testing.T) {
|
||||
@@ -426,12 +413,12 @@ func TestIntShort(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 TestObject(t *testing.T) {
|
||||
@@ -484,12 +471,12 @@ func TestObject(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 TestString(t *testing.T) {
|
||||
@@ -542,12 +529,12 @@ func TestString(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 TestBinaryString(t *testing.T) {
|
||||
@@ -600,12 +587,12 @@ func TestBinaryString(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 TestUnset(t *testing.T) {
|
||||
@@ -658,10 +645,10 @@ func TestUnset(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)
|
||||
}
|
||||
|
||||
57
node/expr/cast/t_freefloating_test.go
Normal file
57
node/expr/cast/t_freefloating_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package cast_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/cast"
|
||||
)
|
||||
|
||||
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{
|
||||
&cast.Array{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.Bool{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.Double{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.Int{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.Object{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.String{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&cast.Unset{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
}
|
||||
|
||||
func TestMeta(t *testing.T) {
|
||||
for _, n := range nodes {
|
||||
actual := *n.GetFreeFloating()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cast_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr/cast"
|
||||
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
var nodes = []node.Node{
|
||||
&cast.Array{},
|
||||
&cast.Bool{},
|
||||
&cast.Double{},
|
||||
&cast.Int{},
|
||||
&cast.Object{},
|
||||
&cast.String{},
|
||||
&cast.Unset{},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package cast_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,10 +1,9 @@
|
||||
package cast_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
@@ -22,49 +21,49 @@ var nodesToTest = []struct {
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Bool{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Double{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Int{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Object{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.String{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Unset{
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -86,31 +85,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +114,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