remove underscore from package names

This commit is contained in:
z7zmey
2018-02-19 13:12:09 +02:00
parent 014b0576d6
commit 4dda4fe7af
54 changed files with 500 additions and 500 deletions

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Assign node
type Assign struct {
Variable node.Node
Expression node.Node
}
// NewAssign node constuctor
func NewAssign(Variable node.Node, Expression node.Node) *Assign {
return &Assign{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Assign) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Assign) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// AssignRef node
type AssignRef struct {
Variable node.Node
Expression node.Node
}
// NewAssignRef node constuctor
func NewAssignRef(Variable node.Node, Expression node.Node) *AssignRef {
return &AssignRef{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *AssignRef) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *AssignRef) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// BitwiseAnd node
type BitwiseAnd struct {
Variable node.Node
Expression node.Node
}
// NewBitwiseAnd node constuctor
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *BitwiseAnd) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *BitwiseAnd) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// BitwiseOr node
type BitwiseOr struct {
Variable node.Node
Expression node.Node
}
// NewBitwiseOr node constuctor
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
return &BitwiseOr{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *BitwiseOr) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *BitwiseOr) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// BitwiseXor node
type BitwiseXor struct {
Variable node.Node
Expression node.Node
}
// NewBitwiseXor node constuctor
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
return &BitwiseXor{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *BitwiseXor) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *BitwiseXor) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Concat node
type Concat struct {
Variable node.Node
Expression node.Node
}
// NewConcat node constuctor
func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Concat) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Concat) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

45
node/expr/assign/n_div.go Normal file
View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Div node
type Div struct {
Variable node.Node
Expression node.Node
}
// NewDiv node constuctor
func NewDiv(Variable node.Node, Expression node.Node) *Div {
return &Div{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Div) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Div) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Minus node
type Minus struct {
Variable node.Node
Expression node.Node
}
// NewMinus node constuctor
func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Minus) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Minus) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

45
node/expr/assign/n_mod.go Normal file
View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Mod node
type Mod struct {
Variable node.Node
Expression node.Node
}
// NewMod node constuctor
func NewMod(Variable node.Node, Expression node.Node) *Mod {
return &Mod{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Mod) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Mod) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

45
node/expr/assign/n_mul.go Normal file
View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Mul node
type Mul struct {
Variable node.Node
Expression node.Node
}
// NewMul node constuctor
func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Mul) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Mul) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Plus node
type Plus struct {
Variable node.Node
Expression node.Node
}
// NewPlus node constuctor
func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Plus) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Plus) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

45
node/expr/assign/n_pow.go Normal file
View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Pow node
type Pow struct {
Variable node.Node
Expression node.Node
}
// NewPow node constuctor
func NewPow(Variable node.Node, Expression node.Node) *Pow {
return &Pow{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *Pow) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Pow) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// ShiftLeft node
type ShiftLeft struct {
Variable node.Node
Expression node.Node
}
// NewShiftLeft node constuctor
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *ShiftLeft) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *ShiftLeft) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,45 @@
package assign
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// ShiftRight node
type ShiftRight struct {
Variable node.Node
Expression node.Node
}
// NewShiftRight node constuctor
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
return &ShiftRight{
Variable,
Expression,
}
}
// Attributes returns node attributes as map
func (n *ShiftRight) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *ShiftRight) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable")
n.Variable.Walk(vv)
}
if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression")
n.Expression.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -0,0 +1,385 @@
package assign_test
import (
"bytes"
"reflect"
"testing"
"github.com/z7zmey/php-parser/node/expr/assign"
"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"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"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 TestAssignRef(t *testing.T) {
src := `<? $a =& $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAssignRefNew(t *testing.T) {
src := `<? $a =& new Foo;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAssignRefArgs(t *testing.T) {
src := `<? $a =& new Foo($b);`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.New{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Arguments: []node.Node{
&node.Argument{
Variadic: false,
IsReference: false,
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestAssign(t *testing.T) {
src := `<? $a = $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestBitwiseAnd(t *testing.T) {
src := `<? $a &= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseAnd{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestBitwiseOr(t *testing.T) {
src := `<? $a |= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseOr{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestBitwiseXor(t *testing.T) {
src := `<? $a ^= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseXor{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestConcat(t *testing.T) {
src := `<? $a .= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Concat{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestDiv(t *testing.T) {
src := `<? $a /= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Div{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestMinus(t *testing.T) {
src := `<? $a -= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Minus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestMod(t *testing.T) {
src := `<? $a %= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Mod{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestMul(t *testing.T) {
src := `<? $a *= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Mul{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestPlus(t *testing.T) {
src := `<? $a += $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Plus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestPow(t *testing.T) {
src := `<? $a **= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Pow{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestShiftLeft(t *testing.T) {
src := `<? $a <<= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.ShiftLeft{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestShiftRight(t *testing.T) {
src := `<? $a >>= $b;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.ShiftRight{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

View File

@@ -0,0 +1,189 @@
package assign_test
import (
"reflect"
"testing"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/kylelemons/godebug/pretty"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/walker"
)
var nodesToTest = []struct {
node node.Node // node
expectedVisitedKeys []string // visited keys
expectedAttributes map[string]interface{}
}{
{
&assign.AssignRef{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.BitwiseAnd{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.BitwiseOr{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.BitwiseXor{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Concat{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Div{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Minus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Mod{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Mul{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Plus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.Pow{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.ShiftLeft{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
{
&assign.ShiftRight{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
},
[]string{"Variable", "Expression"},
map[string]interface{}{},
},
}
type visitorMock struct {
visitChildren bool
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {
v := &visitorMock{false, nil}
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)
}
}
}
func TestVisitor(t *testing.T) {
for _, tt := range nodesToTest {
v := &visitorMock{true, nil}
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)
}
}
}
// test Attributes()
func TestNameAttributes(t *testing.T) {
for _, tt := range nodesToTest {
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)
}
}
}