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
type CastArray struct {
Cast
Expr node.Node
}
// NewCastArray node constuctor
func NewCastArray(Expr node.Node) *CastArray {
return &CastArray{
Cast{
Expr,
},
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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