#[macro_export]
macro_rules! define_matcher {
(
$(#[$meta:meta])*
$vis:vis fn $name:ident for $target:ty {
expects: $expects:expr,
matches: | $actual:ident | $body:expr $(,)?
}
) => {
$crate::define_matcher! {
@build
$(#[$meta])*
$vis fn $name () for $target {
expects: $expects,
matches: | $actual | $body
}
}
};
(
$(#[$meta:meta])*
$vis:vis fn $name:ident ( $( $param:ident : $pty:ty ),* $(,)? ) for $target:ty {
expects: $expects:expr,
matches: | $actual:ident | $body:expr $(,)?
}
) => {
$crate::define_matcher! {
@build
$(#[$meta])*
$vis fn $name ( $( $param : $pty ),* ) for $target {
expects: $expects,
matches: | $actual | $body
}
}
};
(
@build
$(#[$meta:meta])*
$vis:vis fn $name:ident ( $( $param:ident : $pty:ty ),* ) for $target:ty {
expects: $expects:expr,
matches: | $actual:ident | $body:expr
}
) => {
$(#[$meta])*
$vis fn $name ( $( $param : $pty ),* ) -> impl $crate::Matcher<$target> {
struct __TbDefinedMatcher {
$( $param : $pty , )*
}
impl $crate::Matcher<$target> for __TbDefinedMatcher {
#[allow(unused_variables, clippy::clone_on_copy)]
fn check(&self, __tb_actual: &$target) -> $crate::MatchResult {
$( let $param = ::core::clone::Clone::clone(&self.$param); )*
let $actual = __tb_actual;
if $body {
$crate::MatchResult::pass()
} else {
$crate::MatchResult::fail($crate::Mismatch::new(
$crate::Matcher::description(self),
::std::format!("{:?}", __tb_actual),
))
}
}
#[allow(unused_variables, clippy::clone_on_copy)]
fn description(&self) -> $crate::Description {
$( let $param = ::core::clone::Clone::clone(&self.$param); )*
$crate::Description::text($expects)
}
}
__TbDefinedMatcher {
$( $param , )*
}
}
};
}