package binary_test import ( "testing" "gotest.tools/assert" "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" "github.com/z7zmey/php-parser/position" ) func TestBitwiseAnd(t *testing.T) { src := `= $b;` expected := &node.Root{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 12, }, Stmts: []node.Node{ &stmt.Expression{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 12, }, Expr: &binary.GreaterOrEqual{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 11, }, Left: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, Value: "a", }, }, Right: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 9, EndPos: 11, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 9, EndPos: 11, }, Value: "b", }, }, }, }, }, } php7parser := php7.NewParser([]byte(src)) php7parser.Parse() actual := php7parser.GetRootNode() assert.DeepEqual(t, expected, actual) php5parser := php5.NewParser([]byte(src)) php5parser.Parse() actual = php5parser.GetRootNode() assert.DeepEqual(t, expected, actual) } func TestGreater(t *testing.T) { src := ` $b;` expected := &node.Root{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 11, }, Stmts: []node.Node{ &stmt.Expression{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 11, }, Expr: &binary.Greater{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 10, }, Left: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, Value: "a", }, }, Right: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 8, EndPos: 10, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 8, EndPos: 10, }, Value: "b", }, }, }, }, }, } php7parser := php7.NewParser([]byte(src)) php7parser.Parse() actual := php7parser.GetRootNode() assert.DeepEqual(t, expected, actual) php5parser := php5.NewParser([]byte(src)) php5parser.Parse() actual = php5parser.GetRootNode() assert.DeepEqual(t, expected, actual) } func TestIdentical(t *testing.T) { src := `> $b;` expected := &node.Root{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 12, }, Stmts: []node.Node{ &stmt.Expression{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 12, }, Expr: &binary.ShiftRight{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 11, }, Left: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, Value: "a", }, }, Right: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 9, EndPos: 11, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 9, EndPos: 11, }, Value: "b", }, }, }, }, }, } php7parser := php7.NewParser([]byte(src)) php7parser.Parse() actual := php7parser.GetRootNode() assert.DeepEqual(t, expected, actual) php5parser := php5.NewParser([]byte(src)) php5parser.Parse() actual = php5parser.GetRootNode() assert.DeepEqual(t, expected, actual) } func TestSmallerOrEqual(t *testing.T) { src := ` $b;` expected := &node.Root{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 13, }, Stmts: []node.Node{ &stmt.Expression{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 13, }, Expr: &binary.Spaceship{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 12, }, Left: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 3, EndPos: 5, }, Value: "a", }, }, Right: &expr.Variable{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 10, EndPos: 12, }, VarName: &node.Identifier{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 10, EndPos: 12, }, Value: "b", }, }, }, }, }, } php7parser := php7.NewParser([]byte(src)) php7parser.Parse() actual := php7parser.GetRootNode() assert.DeepEqual(t, expected, actual) }