Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exhaustive test of FixupContext leading/trailing invariant #1801

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::classify;
use crate::expr::Expr;
use crate::precedence::Precedence;

#[cfg_attr(test, derive(PartialEq, Debug))]
pub(crate) struct FixupContext {
// Print expression such that it can be parsed back as a statement
// consisting of the original expression.
Expand Down Expand Up @@ -343,3 +344,33 @@ impl Clone for FixupContext {
*self
}
}

#[cfg(feature = "full")]
#[test]
fn test_leftmost_rightmost_invariant() {
const BITS: usize = 8;

for bits in 0u16..1 << BITS {
let mut i = 0;
let mut bit = || {
let mask = 1 << i;
i += 1;
(bits & mask) != 0
};
let fixup = FixupContext {
stmt: bit(),
leftmost_subexpression_in_stmt: bit(),
match_arm: bit(),
leftmost_subexpression_in_match_arm: bit(),
parenthesize_exterior_struct_lit: bit(),
next_operator_can_begin_expr: bit(),
next_operator_can_continue_expr: bit(),
next_operator_can_begin_generics: bit(),
};
assert_eq!(i, BITS);
assert_eq!(
fixup.leftmost_subexpression().rightmost_subexpression(),
fixup.rightmost_subexpression().leftmost_subexpression(),
);
}
}
Loading