refactor cast package
This commit is contained in:
parent
6fdebcbcb3
commit
7ae4dbb081
@ -1,10 +0,0 @@
|
|||||||
package cast
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/z7zmey/php-parser/node"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cast node
|
|
||||||
type Cast struct {
|
|
||||||
Expr node.Node
|
|
||||||
}
|
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +34,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -56,12 +54,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -78,12 +74,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -100,12 +94,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -122,12 +114,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -144,12 +134,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -166,12 +154,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -188,12 +174,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -210,12 +194,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
@ -232,12 +214,10 @@ 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"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||||
|
@ -19,64 +19,50 @@ 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{}{},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user