Skip to content

Commit

Permalink
Add range precedence tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 11, 2024
1 parent b15c623 commit 46bc5aa
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fn test_postfix_operator_after_cast() {
}

#[test]
fn test_ranges() {
fn test_range_kinds() {
syn::parse_str::<Expr>("..").unwrap();
syn::parse_str::<Expr>("..hi").unwrap();
syn::parse_str::<Expr>("lo..").unwrap();
Expand All @@ -348,6 +348,63 @@ fn test_ranges() {
syn::parse_str::<Expr>("lo...hi").unwrap_err();
}

#[test]
fn test_range_precedence() {
snapshot!(".. .." as Expr, @r###"
Expr::Range {
limits: RangeLimits::HalfOpen,
end: Some(Expr::Range {
limits: RangeLimits::HalfOpen,
}),
}
"###);

snapshot!(".. .. ()" as Expr, @r###"
Expr::Range {
limits: RangeLimits::HalfOpen,
end: Some(Expr::Range {
limits: RangeLimits::HalfOpen,
end: Some(Expr::Tuple),
}),
}
"###);

snapshot!("() .. .." as Expr, @r###"
Expr::Range {
start: Some(Expr::Tuple),
limits: RangeLimits::HalfOpen,
end: Some(Expr::Range {
limits: RangeLimits::HalfOpen,
}),
}
"###);

// FIXME: should fail to parse. A range with a lower bound cannot be the
// upper bound of another range.
snapshot!(".. () .." as Expr, @r###"
Expr::Range {
limits: RangeLimits::HalfOpen,
end: Some(Expr::Range {
start: Some(Expr::Tuple),
limits: RangeLimits::HalfOpen,
}),
}
"###);

// FIXME: should fail to parse. A range with an upper bound cannot be the
// lower bound of another range.
snapshot!("() .. () .." as Expr, @r###"
Expr::Range {
start: Some(Expr::Range {
start: Some(Expr::Tuple),
limits: RangeLimits::HalfOpen,
end: Some(Expr::Tuple),
}),
limits: RangeLimits::HalfOpen,
}
"###);
}

#[test]
fn test_ambiguous_label() {
for stmt in [
Expand Down

0 comments on commit 46bc5aa

Please sign in to comment.