refactor cast package

This commit is contained in:
z7zmey 2018-02-09 19:50:20 +02:00
parent 6fdebcbcb3
commit 7ae4dbb081
10 changed files with 31 additions and 89 deletions

View File

@ -1,10 +0,0 @@
package cast
import (
"github.com/z7zmey/php-parser/node"
)
// Cast node
type Cast struct {
Expr node.Node
}

View File

@ -7,15 +7,13 @@ import (
// CastArray node // CastArray node
type CastArray struct { type CastArray struct {
Cast Expr node.Node
} }
// NewCastArray node constuctor // NewCastArray node constuctor
func NewCastArray(Expr node.Node) *CastArray { func NewCastArray(Expr node.Node) *CastArray {
return &CastArray{ return &CastArray{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastBool node // CastBool node
type CastBool struct { type CastBool struct {
Cast Expr node.Node
} }
// NewCastBool node constuctor // NewCastBool node constuctor
func NewCastBool(Expr node.Node) *CastBool { func NewCastBool(Expr node.Node) *CastBool {
return &CastBool{ return &CastBool{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastDouble node // CastDouble node
type CastDouble struct { type CastDouble struct {
Cast Expr node.Node
} }
// NewCastDouble node constuctor // NewCastDouble node constuctor
func NewCastDouble(Expr node.Node) *CastDouble { func NewCastDouble(Expr node.Node) *CastDouble {
return &CastDouble{ return &CastDouble{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastInt node // CastInt node
type CastInt struct { type CastInt struct {
Cast Expr node.Node
} }
// NewCastInt node constuctor // NewCastInt node constuctor
func NewCastInt(Expr node.Node) *CastInt { func NewCastInt(Expr node.Node) *CastInt {
return &CastInt{ return &CastInt{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastObject node // CastObject node
type CastObject struct { type CastObject struct {
Cast Expr node.Node
} }
// NewCastObject node constuctor // NewCastObject node constuctor
func NewCastObject(Expr node.Node) *CastObject { func NewCastObject(Expr node.Node) *CastObject {
return &CastObject{ return &CastObject{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastString node // CastString node
type CastString struct { type CastString struct {
Cast Expr node.Node
} }
// NewCastString node constuctor // NewCastString node constuctor
func NewCastString(Expr node.Node) *CastString { func NewCastString(Expr node.Node) *CastString {
return &CastString{ return &CastString{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -7,15 +7,13 @@ import (
// CastUnset node // CastUnset node
type CastUnset struct { type CastUnset struct {
Cast Expr node.Node
} }
// NewCastUnset node constuctor // NewCastUnset node constuctor
func NewCastUnset(Expr node.Node) *CastUnset { func NewCastUnset(Expr node.Node) *CastUnset {
return &CastUnset{ return &CastUnset{
Cast{ Expr,
Expr,
},
} }
} }

View File

@ -34,9 +34,7 @@ func TestCastArray(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastArray{ Expr: &cast.CastArray{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -56,9 +54,7 @@ func TestCastBool(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastBool{ Expr: &cast.CastBool{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -78,9 +74,7 @@ func TestCastBoolShort(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastBool{ Expr: &cast.CastBool{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -100,9 +94,7 @@ func TestCastDouble(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastDouble{ Expr: &cast.CastDouble{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -122,9 +114,7 @@ func TestCastFloat(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastDouble{ Expr: &cast.CastDouble{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -144,9 +134,7 @@ func TestCastInt(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastInt{ Expr: &cast.CastInt{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -166,9 +154,7 @@ func TestCastIntShort(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastInt{ Expr: &cast.CastInt{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -188,9 +174,7 @@ func TestCastObject(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastObject{ Expr: &cast.CastObject{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -210,9 +194,7 @@ func TestCastString(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastString{ Expr: &cast.CastString{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },
@ -232,9 +214,7 @@ func TestCastUnset(t *testing.T) {
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &cast.CastUnset{ Expr: &cast.CastUnset{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
}, },
}, },

View File

@ -19,63 +19,49 @@ var nodesToTest = []struct {
}{ }{
{ {
&cast.CastArray{ &cast.CastArray{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastBool{ &cast.CastBool{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastDouble{ &cast.CastDouble{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastInt{ &cast.CastInt{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastObject{ &cast.CastObject{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastString{ &cast.CastString{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.CastUnset{ &cast.CastUnset{
Cast: cast.Cast{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},