Skip to content

Commit da509d5

Browse files
committed
Add test of assignment and range precedence
1 parent b1a12f4 commit da509d5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_expr.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,34 @@ fn test_tuple_comma() {
576576
}
577577
"###);
578578
}
579+
580+
#[test]
581+
fn test_assign_range_precedence() {
582+
// Range has higher precedence as the right-hand of an assignment, but
583+
// ambiguous precedence as the left-hand of an assignment.
584+
snapshot!("() = () .. ()" as Expr, @r###"
585+
Expr::Assign {
586+
left: Expr::Tuple,
587+
right: Expr::Range {
588+
start: Some(Expr::Tuple),
589+
limits: RangeLimits::HalfOpen,
590+
end: Some(Expr::Tuple),
591+
},
592+
}
593+
"###);
594+
595+
snapshot!("() += () .. ()" as Expr, @r###"
596+
Expr::Binary {
597+
left: Expr::Tuple,
598+
op: BinOp::AddAssign,
599+
right: Expr::Range {
600+
start: Some(Expr::Tuple),
601+
limits: RangeLimits::HalfOpen,
602+
end: Some(Expr::Tuple),
603+
},
604+
}
605+
"###);
606+
607+
syn::parse_str::<Expr>("() .. () = ()").unwrap_err();
608+
syn::parse_str::<Expr>("() .. () += ()").unwrap_err();
609+
}

0 commit comments

Comments
 (0)