#[macro_export]
macro_rules! assert_matches {
($expression:expr, $pattern:pat $(if $condition:expr)? $(,)?) => {
match $expression {
$pattern $(if $condition)? => (),
ref expression => panic!(
"assertion `left matches right` failed\n left: {:?}\n right: {}",
expression,
stringify!($pattern $(if $condition)?),
)
}
};
($expression:expr, $pattern:pat $(if $condition:expr)? => $code:expr $(,)?) => {
match $expression {
$pattern $(if $condition)? => $code,
ref expression => panic!(
"assertion `left matches right` failed\n left: {:?}\n right: {}",
expression,
stringify!($pattern $(if $condition)?),
)
}
};
($expression:expr, $pattern:pat $(if $condition:expr)?, $($arg:tt)+) => {
match $expression {
$pattern $(if $condition)? => (),
ref expression => panic!(
"assertion `left matches right` failed: {}\n left: {:?}\n right: {}",
format_args!($($arg)+),
expression,
stringify!($pattern $(if $condition)?),
)
}
};
($expression:expr, $pattern:pat $(if $condition:expr)? => $code:expr, $($arg:tt)+) => {
match $expression {
$pattern $(if $condition)? => $code,
ref expression => panic!(
"assertion `left matches right` failed: {}\n left: {:?}\n right: {}",
format_args!($($arg)+),
expression,
stringify!($pattern $(if $condition)?),
)
}
};
}