1289 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			1289 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package assign_test
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	"reflect"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/z7zmey/php-parser/node/expr/assign"
 | |
| 	"github.com/z7zmey/php-parser/position"
 | |
| 
 | |
| 	"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 TestReference(t *testing.T) {
 | |
| 	src := `<? $a =& $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Reference{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestReferenceNew(t *testing.T) {
 | |
| 	src := `<? $a =& new Foo;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    17,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    17,
 | |
| 				},
 | |
| 				Expr: &assign.Reference{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    16,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.New{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    16,
 | |
| 						},
 | |
| 						Class: &name.Name{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  14,
 | |
| 								EndPos:    16,
 | |
| 							},
 | |
| 							Parts: []node.Node{
 | |
| 								&name.NamePart{
 | |
| 									Position: &position.Position{
 | |
| 										StartLine: 1,
 | |
| 										EndLine:   1,
 | |
| 										StartPos:  14,
 | |
| 										EndPos:    16,
 | |
| 									},
 | |
| 									Value: "Foo",
 | |
| 								},
 | |
| 							},
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestReferenceArgs(t *testing.T) {
 | |
| 	src := `<? $a =& new Foo($b);`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    21,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    21,
 | |
| 				},
 | |
| 				Expr: &assign.Reference{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    20,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.New{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    20,
 | |
| 						},
 | |
| 						Class: &name.Name{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  14,
 | |
| 								EndPos:    16,
 | |
| 							},
 | |
| 							Parts: []node.Node{
 | |
| 								&name.NamePart{
 | |
| 									Position: &position.Position{
 | |
| 										StartLine: 1,
 | |
| 										EndLine:   1,
 | |
| 										StartPos:  14,
 | |
| 										EndPos:    16,
 | |
| 									},
 | |
| 									Value: "Foo",
 | |
| 								},
 | |
| 							},
 | |
| 						},
 | |
| 						ArgumentList: &node.ArgumentList{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  17,
 | |
| 								EndPos:    20,
 | |
| 							},
 | |
| 							Arguments: []node.Node{
 | |
| 								&node.Argument{
 | |
| 									Position: &position.Position{
 | |
| 										StartLine: 1,
 | |
| 										EndLine:   1,
 | |
| 										StartPos:  18,
 | |
| 										EndPos:    19,
 | |
| 									},
 | |
| 									Variadic:    false,
 | |
| 									IsReference: false,
 | |
| 									Expr: &expr.Variable{
 | |
| 										Position: &position.Position{
 | |
| 											StartLine: 1,
 | |
| 											EndLine:   1,
 | |
| 											StartPos:  18,
 | |
| 											EndPos:    19,
 | |
| 										},
 | |
| 										VarName: &node.Identifier{
 | |
| 											Position: &position.Position{
 | |
| 												StartLine: 1,
 | |
| 												EndLine:   1,
 | |
| 												StartPos:  18,
 | |
| 												EndPos:    19,
 | |
| 											},
 | |
| 											Value: "b",
 | |
| 										},
 | |
| 									},
 | |
| 								},
 | |
| 							},
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestAssign(t *testing.T) {
 | |
| 	src := `<? $a = $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    11,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    11,
 | |
| 				},
 | |
| 				Expr: &assign.Assign{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    10,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  9,
 | |
| 							EndPos:    10,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  9,
 | |
| 								EndPos:    10,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestBitwiseAnd(t *testing.T) {
 | |
| 	src := `<? $a &= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.BitwiseAnd{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestBitwiseOr(t *testing.T) {
 | |
| 	src := `<? $a |= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.BitwiseOr{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestBitwiseXor(t *testing.T) {
 | |
| 	src := `<? $a ^= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.BitwiseXor{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestConcat(t *testing.T) {
 | |
| 	src := `<? $a .= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Concat{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestDiv(t *testing.T) {
 | |
| 	src := `<? $a /= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Div{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestMinus(t *testing.T) {
 | |
| 	src := `<? $a -= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Minus{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestMod(t *testing.T) {
 | |
| 	src := `<? $a %= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Mod{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestMul(t *testing.T) {
 | |
| 	src := `<? $a *= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Mul{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestPlus(t *testing.T) {
 | |
| 	src := `<? $a += $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    12,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    12,
 | |
| 				},
 | |
| 				Expr: &assign.Plus{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    11,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  10,
 | |
| 							EndPos:    11,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  10,
 | |
| 								EndPos:    11,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestPow(t *testing.T) {
 | |
| 	src := `<? $a **= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    13,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    13,
 | |
| 				},
 | |
| 				Expr: &assign.Pow{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    12,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  11,
 | |
| 							EndPos:    12,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  11,
 | |
| 								EndPos:    12,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestShiftLeft(t *testing.T) {
 | |
| 	src := `<? $a <<= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    13,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    13,
 | |
| 				},
 | |
| 				Expr: &assign.ShiftLeft{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    12,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  11,
 | |
| 							EndPos:    12,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  11,
 | |
| 								EndPos:    12,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 | |
| 
 | |
| func TestShiftRight(t *testing.T) {
 | |
| 	src := `<? $a >>= $b;`
 | |
| 
 | |
| 	expected := &node.Root{
 | |
| 		Position: &position.Position{
 | |
| 			StartLine: 1,
 | |
| 			EndLine:   1,
 | |
| 			StartPos:  4,
 | |
| 			EndPos:    13,
 | |
| 		},
 | |
| 		Stmts: []node.Node{
 | |
| 			&stmt.Expression{
 | |
| 				Position: &position.Position{
 | |
| 					StartLine: 1,
 | |
| 					EndLine:   1,
 | |
| 					StartPos:  4,
 | |
| 					EndPos:    13,
 | |
| 				},
 | |
| 				Expr: &assign.ShiftRight{
 | |
| 					Position: &position.Position{
 | |
| 						StartLine: 1,
 | |
| 						EndLine:   1,
 | |
| 						StartPos:  4,
 | |
| 						EndPos:    12,
 | |
| 					},
 | |
| 					Variable: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  4,
 | |
| 							EndPos:    5,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  4,
 | |
| 								EndPos:    5,
 | |
| 							},
 | |
| 							Value: "a",
 | |
| 						},
 | |
| 					},
 | |
| 					Expression: &expr.Variable{
 | |
| 						Position: &position.Position{
 | |
| 							StartLine: 1,
 | |
| 							EndLine:   1,
 | |
| 							StartPos:  11,
 | |
| 							EndPos:    12,
 | |
| 						},
 | |
| 						VarName: &node.Identifier{
 | |
| 							Position: &position.Position{
 | |
| 								StartLine: 1,
 | |
| 								EndLine:   1,
 | |
| 								StartPos:  11,
 | |
| 								EndPos:    12,
 | |
| 							},
 | |
| 							Value: "b",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php7parser.Parse()
 | |
| 	actual := php7parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| 
 | |
| 	php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
 | |
| 	php5parser.Parse()
 | |
| 	actual = php5parser.GetRootNode()
 | |
| 	assertEqual(t, expected, actual)
 | |
| }
 |