Add some parenthesization test cases with operators that are not left-associative

This commit is contained in:
David Tolnay 2024-12-20 19:47:49 -08:00
parent 13170cd787
commit d748d1d953
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -61,6 +61,9 @@ static EXPRS: &[&str] = &[
"(2 + 2) * 2",
"2 * (2 + 2)",
"2 + 2 + 2",
// Right-associative operator.
"2 += 2 += 2",
"(2 += 2) += 2",
// Return has lower precedence than a binary operator.
"(return 2) + 2",
"2 + (return 2)", // FIXME: no parenthesis needed.
@ -89,6 +92,11 @@ static EXPRS: &[&str] = &[
// allowed, except if the break is also labeled.
"break 'outer 'inner: loop {} + 2",
"break ('inner: loop {} + 2)",
// Grammar restriction: ranges cannot be the endpoint of another range.
"(2..2)..2",
"2..(2..2)",
"(2..2)..",
"..(2..2)",
// Grammar restriction: the value in let-else is not allowed to end in a
// curly brace.
"{ let _ = 1 + 1 else {}; }",