Specialize assert_pred.

It has only two uses, and both use `matches_codepattern`. So just change
it to `assert_matches_codepattern`.
This commit is contained in:
Nicholas Nethercote 2024-06-04 13:20:43 +10:00
parent 95b4c07ef8
commit 13f2bc9a65

View File

@ -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);
}
}};
}
@ -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()
);
@ -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()
);