#![doc(hidden)]
#[macro_export]
macro_rules! __auto_eq {
($e:expr) => {{
#[allow(unused_imports)]
use $crate::matcher_support::__internal_unstable_do_not_depend_on_these::ExpectedKind as _;
match $e {
expected => {
$crate::matcher_support::__internal_unstable_do_not_depend_on_these::Wrapper(
&expected,
)
.kind()
.matcher(expected)
}
}
}};
}
pub mod internal {
use crate::{
matcher::MatcherBase,
matchers::{eq, EqMatcher},
};
pub struct Wrapper<T>(pub T);
impl<T: MatcherBase> Wrapper<&'_ T> {
#[inline]
pub fn kind(&self) -> MatcherTag {
MatcherTag
}
}
pub trait ExpectedKind {
#[inline]
fn kind(&self) -> ExpectedTag {
ExpectedTag
}
}
impl<T> ExpectedKind for Wrapper<T> {}
pub struct MatcherTag;
impl MatcherTag {
#[inline]
pub fn matcher<M>(self, matcher: M) -> M {
matcher
}
}
pub struct ExpectedTag;
impl ExpectedTag {
#[inline]
pub fn matcher<T>(self, expected: T) -> EqMatcher<T> {
eq(expected)
}
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
use crate::Result;
#[test]
fn auto_ref_matcher() -> Result<()> {
verify_that!(123, __auto_eq!(ge(9)))
}
#[test]
fn auto_ref_expected() -> Result<()> {
verify_that!(123, __auto_eq!(123))
}
#[test]
fn auto_ref_on_ref_matcher() -> Result<()> {
let matcher = eq(123);
verify_that!(123, __auto_eq!(&matcher))
}
}