Skip to content

Commit

Permalink
Specialize assert_pred.
Browse files Browse the repository at this point in the history
It has only two uses, and both use `matches_codepattern`. So just change
it to `assert_matches_codepattern`.
  • Loading branch information
nnethercote committed Jun 5, 2024
1 parent 95b4c07 commit 13f2bc9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions compiler/rustc_parse/src/parser/mut_visit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ impl MutVisitor for ToZzIdentMutVisitor {
}
}

// Maybe add to `expand.rs`.
macro_rules! assert_pred {
($pred:expr, $predname:expr, $a:expr , $b:expr) => {{
let pred_val = $pred;
macro_rules! assert_matches_codepattern {
($a:expr , $b:expr) => {{
let a_val = $a;
let b_val = $b;
if !(pred_val(&a_val, &b_val)) {
panic!("expected args satisfying {}, got {} and {}", $predname, a_val, b_val);
if !matches_codepattern(&a_val, &b_val) {
panic!("expected args satisfying `matches_codepattern`, got {} and {}", a_val, b_val);
}
}};
}
Expand All @@ -41,9 +39,7 @@ fn ident_transformation() {
let mut krate =
string_to_crate("#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
zz_visitor.visit_crate(&mut krate);
assert_pred!(
matches_codepattern,
"matches_codepattern",
assert_matches_codepattern!(
print_crate_items(&krate),
"#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string()
);
Expand All @@ -61,9 +57,7 @@ fn ident_transformation_in_defs() {
.to_string(),
);
zz_visitor.visit_crate(&mut krate);
assert_pred!(
matches_codepattern,
"matches_codepattern",
assert_matches_codepattern!(
print_crate_items(&krate),
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string()
);
Expand Down

0 comments on commit 13f2bc9

Please sign in to comment.