Skip to content

Commit

Permalink
Add assertion in test_permutations that parsed expr is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 29, 2024
1 parent a83b158 commit ee76c9e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod macros;

mod common;

use crate::common::visit::FlattenParens;
use crate::common::visit::{AsIfPrinted, FlattenParens};
use proc_macro2::{Delimiter, Group, Span};
use quote::{quote, ToTokens as _};
use std::process::ExitCode;
Expand Down Expand Up @@ -1172,11 +1172,16 @@ fn test_permutations() -> ExitCode {
return;
}};
}
let mut assert = |expr: Expr| {
let mut assert = |mut original: Expr| {
count += 1;
let tokens = expr.to_token_stream();
if syn::parse2::<Expr>(tokens.clone()).is_err() {
let tokens = original.to_token_stream();
let Ok(mut parsed) = syn::parse2::<Expr>(tokens.clone()) else {
fail!("failed to parse: {}", tokens);
};
AsIfPrinted.visit_expr_mut(&mut original);
FlattenParens.visit_expr_mut(&mut parsed);
if original != parsed {
fail!("before: {}\nafter: {}", tokens, parsed.to_token_stream());
}
};

Expand Down

0 comments on commit ee76c9e

Please sign in to comment.