diff --git a/internal/php8/concat_precedence_test.go b/internal/php8/concat_precedence_test.go new file mode 100644 index 0000000..63c3aa9 --- /dev/null +++ b/internal/php8/concat_precedence_test.go @@ -0,0 +1,59 @@ +package php8_test + +import ( + "testing" + + "github.com/rectorphp/php-parser-in-go/pkg/ast" +) + +func concatAssignedValue(test *testing.T, source string) ast.Vertex { + test.Helper() + root, parserErrors := parsePHP85(source) + if len(parserErrors) != 0 { + test.Fatalf("unexpected parser errors: %v", parserErrors) + } + return root.(*ast.Root).Stmts[0].(*ast.StmtExpression).Expr.(*ast.ExprAssign).Expr +} + +// Since PHP 8.0 `+` and `-` bind tighter than `.`: "Sum: " . $a + $b is "Sum: " . ($a + $b). +func TestConcatBindsLooserThanPlus(test *testing.T) { + value := concatAssignedValue(test, `' T_IS_GREATER_OR_EQUAL %left T_PIPE +// Since PHP 8.0 concatenation binds looser than shifts and +/-: "a" . 1 + 2 is "a" . (1 + 2). +%left '.' %left T_SL T_SR -%left '+' '-' '.' +%left '+' '-' %left '*' '/' '%' %right '!' %nonassoc T_INSTANCEOF