Skip to content

Commit

Permalink
Add test of assignment and range precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 11, 2024
1 parent b1a12f4 commit da509d5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_expr.rs
Expand Up @@ -576,3 +576,34 @@ fn test_tuple_comma() {
}
"###);
}

#[test]
fn test_assign_range_precedence() {
// Range has higher precedence as the right-hand of an assignment, but
// ambiguous precedence as the left-hand of an assignment.
snapshot!("() = () .. ()" as Expr, @r###"
Expr::Assign {
left: Expr::Tuple,
right: Expr::Range {
start: Some(Expr::Tuple),
limits: RangeLimits::HalfOpen,
end: Some(Expr::Tuple),
},
}
"###);

snapshot!("() += () .. ()" as Expr, @r###"
Expr::Binary {
left: Expr::Tuple,
op: BinOp::AddAssign,
right: Expr::Range {
start: Some(Expr::Tuple),
limits: RangeLimits::HalfOpen,
end: Some(Expr::Tuple),
},
}
"###);

syn::parse_str::<Expr>("() .. () = ()").unwrap_err();
syn::parse_str::<Expr>("() .. () += ()").unwrap_err();
}

0 comments on commit da509d5

Please sign in to comment.