remove underscore from package names
This commit is contained in:
45
node/expr/binary/n_bitwise_and.go
Normal file
45
node/expr/binary/n_bitwise_and.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseAnd node
|
||||
type BitwiseAnd struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_bitwise_or.go
Normal file
45
node/expr/binary/n_bitwise_or.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseOr node
|
||||
type BitwiseOr struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_bitwise_xor.go
Normal file
45
node/expr/binary/n_bitwise_xor.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseXor node
|
||||
type BitwiseXor struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_boolean_and.go
Normal file
45
node/expr/binary/n_boolean_and.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BooleanAnd node
|
||||
type BooleanAnd struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBooleanAnd node constuctor
|
||||
func NewBooleanAnd(Variable node.Node, Expression node.Node) *BooleanAnd {
|
||||
return &BooleanAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *BooleanAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *BooleanAnd) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_boolean_or.go
Normal file
45
node/expr/binary/n_boolean_or.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BooleanOr node
|
||||
type BooleanOr struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBooleanOr node constuctor
|
||||
func NewBooleanOr(Variable node.Node, Expression node.Node) *BooleanOr {
|
||||
return &BooleanOr{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *BooleanOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *BooleanOr) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_coalesce.go
Normal file
45
node/expr/binary/n_coalesce.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Coalesce node
|
||||
type Coalesce struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewCoalesce node constuctor
|
||||
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
|
||||
return &Coalesce{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Coalesce) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Coalesce) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_concat.go
Normal file
45
node/expr/binary/n_concat.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Concat node
|
||||
type Concat struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_div.go
Normal file
45
node/expr/binary/n_div.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Div node
|
||||
type Div struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_equal.go
Normal file
45
node/expr/binary/n_equal.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Equal node
|
||||
type Equal struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewEqual node constuctor
|
||||
func NewEqual(Variable node.Node, Expression node.Node) *Equal {
|
||||
return &Equal{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Equal) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Equal) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_greater.go
Normal file
45
node/expr/binary/n_greater.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Greater node
|
||||
type Greater struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewGreater node constuctor
|
||||
func NewGreater(Variable node.Node, Expression node.Node) *Greater {
|
||||
return &Greater{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Greater) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Greater) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_greater_or_equal.go
Normal file
45
node/expr/binary/n_greater_or_equal.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// GreaterOrEqual node
|
||||
type GreaterOrEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewGreaterOrEqual node constuctor
|
||||
func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
|
||||
return &GreaterOrEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *GreaterOrEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *GreaterOrEqual) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_identical.go
Normal file
45
node/expr/binary/n_identical.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Identical node
|
||||
type Identical struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewIdentical node constuctor
|
||||
func NewIdentical(Variable node.Node, Expression node.Node) *Identical {
|
||||
return &Identical{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Identical) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Identical) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_logical_and.go
Normal file
45
node/expr/binary/n_logical_and.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalAnd node
|
||||
type LogicalAnd struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalAnd node constuctor
|
||||
func NewLogicalAnd(Variable node.Node, Expression node.Node) *LogicalAnd {
|
||||
return &LogicalAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *LogicalAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *LogicalAnd) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_logical_or.go
Normal file
45
node/expr/binary/n_logical_or.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalOr node
|
||||
type LogicalOr struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalOr node constuctor
|
||||
func NewLogicalOr(Variable node.Node, Expression node.Node) *LogicalOr {
|
||||
return &LogicalOr{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *LogicalOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *LogicalOr) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_logical_xor.go
Normal file
45
node/expr/binary/n_logical_xor.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalXor node
|
||||
type LogicalXor struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalXor node constuctor
|
||||
func NewLogicalXor(Variable node.Node, Expression node.Node) *LogicalXor {
|
||||
return &LogicalXor{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *LogicalXor) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *LogicalXor) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_minus.go
Normal file
45
node/expr/binary/n_minus.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Minus node
|
||||
type Minus struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_mod.go
Normal file
45
node/expr/binary/n_mod.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mod node
|
||||
type Mod struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_mul.go
Normal file
45
node/expr/binary/n_mul.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mul node
|
||||
type Mul struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_not_equal.go
Normal file
45
node/expr/binary/n_not_equal.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// NotEqual node
|
||||
type NotEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewNotEqual node constuctor
|
||||
func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
|
||||
return &NotEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *NotEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *NotEqual) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_not_identical.go
Normal file
45
node/expr/binary/n_not_identical.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// NotIdentical node
|
||||
type NotIdentical struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewNotIdentical node constuctor
|
||||
func NewNotIdentical(Variable node.Node, Expression node.Node) *NotIdentical {
|
||||
return &NotIdentical{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *NotIdentical) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *NotIdentical) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_plus.go
Normal file
45
node/expr/binary/n_plus.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Plus node
|
||||
type Plus struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_pow.go
Normal file
45
node/expr/binary/n_pow.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Pow node
|
||||
type Pow struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_shift_left.go
Normal file
45
node/expr/binary/n_shift_left.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftLeft node
|
||||
type ShiftLeft struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_shift_right.go
Normal file
45
node/expr/binary/n_shift_right.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftRight node
|
||||
type ShiftRight struct {
|
||||
Left node.Node
|
||||
Right 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.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_smaller.go
Normal file
45
node/expr/binary/n_smaller.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Smaller node
|
||||
type Smaller struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSmaller node constuctor
|
||||
func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
|
||||
return &Smaller{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Smaller) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Smaller) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_smaller_or_equal.go
Normal file
45
node/expr/binary/n_smaller_or_equal.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// SmallerOrEqual node
|
||||
type SmallerOrEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSmallerOrEqual node constuctor
|
||||
func NewSmallerOrEqual(Variable node.Node, Expression node.Node) *SmallerOrEqual {
|
||||
return &SmallerOrEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *SmallerOrEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *SmallerOrEqual) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
45
node/expr/binary/n_spaceship.go
Normal file
45
node/expr/binary/n_spaceship.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Spaceship node
|
||||
type Spaceship struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSpaceship node constuctor
|
||||
func NewSpaceship(Variable node.Node, Expression node.Node) *Spaceship {
|
||||
return &Spaceship{
|
||||
Variable,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Spaceship) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Spaceship) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
||||
589
node/expr/binary/t_binary_op_test.go
Normal file
589
node/expr/binary/t_binary_op_test.go
Normal file
@@ -0,0 +1,589 @@
|
||||
package binary_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/binary"
|
||||
"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 TestBitwiseAnd(t *testing.T) {
|
||||
src := `<? $a & $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.BitwiseAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.BitwiseOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.BitwiseXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestBooleanAnd(t *testing.T) {
|
||||
src := `<? $a && $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.BooleanAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestBooleanOr(t *testing.T) {
|
||||
src := `<? $a || $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.BooleanOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestCoalesce(t *testing.T) {
|
||||
src := `<? $a ?? $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Coalesce{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php7.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: &binary.Concat{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Div{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestEqual(t *testing.T) {
|
||||
src := `<? $a == $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Equal{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestGreaterOrEqual(t *testing.T) {
|
||||
src := `<? $a >= $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.GreaterOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestGreater(t *testing.T) {
|
||||
src := `<? $a > $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Greater{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestIdentical(t *testing.T) {
|
||||
src := `<? $a === $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Identical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestLogicalAnd(t *testing.T) {
|
||||
src := `<? $a and $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.LogicalAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestLogicalOr(t *testing.T) {
|
||||
src := `<? $a or $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.LogicalOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestLogicalXor(t *testing.T) {
|
||||
src := `<? $a xor $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.LogicalXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Minus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Mod{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Mul{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestNotEqual(t *testing.T) {
|
||||
src := `<? $a != $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.NotEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestNotIdentical(t *testing.T) {
|
||||
src := `<? $a !== $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.NotIdentical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Plus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.Pow{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.ShiftLeft{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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: &binary.ShiftRight{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestSmallerOrEqual(t *testing.T) {
|
||||
src := `<? $a <= $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.SmallerOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestSmaller(t *testing.T) {
|
||||
src := `<? $a < $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Smaller{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &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 TestSpaceship(t *testing.T) {
|
||||
src := `<? $a <=> $b;`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &binary.Spaceship{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
292
node/expr/binary/t_visitor_test.go
Normal file
292
node/expr/binary/t_visitor_test.go
Normal file
@@ -0,0 +1,292 @@
|
||||
package binary_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/binary"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
var nodesToTest = []struct {
|
||||
node node.Node // node
|
||||
expectedVisitedKeys []string // visited keys
|
||||
expectedAttributes map[string]interface{}
|
||||
}{
|
||||
{
|
||||
&binary.BitwiseAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.BitwiseOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.BitwiseXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.BooleanAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.BooleanOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Coalesce{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Concat{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Div{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Equal{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.GreaterOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Greater{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Identical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.LogicalAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.LogicalOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.LogicalXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Minus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Mod{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Mul{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.NotEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.NotIdentical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Plus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Pow{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.ShiftLeft{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.ShiftRight{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.SmallerOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Smaller{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&binary.Spaceship{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "$b"}},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user