diff options
Diffstat (limited to 'src/matchers/property_matcher.rs')
-rw-r--r-- | src/matchers/property_matcher.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/matchers/property_matcher.rs b/src/matchers/property_matcher.rs index d69ba1d..19b4862 100644 --- a/src/matchers/property_matcher.rs +++ b/src/matchers/property_matcher.rs @@ -13,7 +13,7 @@ // limitations under the License. // There are no visible documentation elements in this module; the declarative -// macro is documented at the top level. +// macro is documented in the matcher module. #![doc(hidden)] /// Matches an object which, upon calling the given method on it with the given @@ -44,8 +44,7 @@ /// failure, it will be invoked a second time, with the assertion failure output /// reflecting the *second* invocation. /// -/// If the method returns a *reference*, then it must be preceded by the keyword -/// `ref`: +/// If the method returns a *reference*, then it must be preceded by a `*`: /// /// ``` /// # use googletest::prelude::*; @@ -58,7 +57,7 @@ /// } /// /// # let value = vec![MyStruct { a_field: 100 }]; -/// verify_that!(value, contains(property!(ref MyStruct.get_a_field(), eq(100)))) +/// verify_that!(value, contains(property!(*MyStruct.get_a_field(), eq(100)))) /// # .unwrap(); /// ``` /// @@ -93,17 +92,18 @@ /// } /// /// let value = MyStruct { a_string: "A string".into() }; -/// verify_that!(value, property!(ref MyStruct.get_a_string(), eq("A string"))) // Does not compile +/// verify_that!(value, property!(*MyStruct.get_a_string(), eq("A string"))) // Does not compile /// # .unwrap(); /// ``` /// -/// This macro is analogous to [`field`][crate::field], except that it extracts -/// the datum to be matched from the given object by invoking a method rather -/// than accessing a field. +/// This macro is analogous to [`field`][crate::matchers::field], except that it +/// extracts the datum to be matched from the given object by invoking a method +/// rather than accessing a field. /// /// The list of arguments may optionally have a trailing comma. #[macro_export] -macro_rules! property { +#[doc(hidden)] +macro_rules! __property { ($($t:tt)*) => { $crate::property_internal!($($t)*) } } @@ -113,15 +113,15 @@ macro_rules! property { #[macro_export] macro_rules! property_internal { ($($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{ - use $crate::matchers::property_matcher::internal::property_matcher; + use $crate::matchers::__internal_unstable_do_not_depend_on_these::property_matcher; property_matcher( |o: &$($t)::+| o.$method($($argument),*), &stringify!($method($($argument),*)), $m) }}; - (ref $($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{ - use $crate::matchers::property_matcher::internal::property_ref_matcher; + (* $($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{ + use $crate::matchers::__internal_unstable_do_not_depend_on_these::property_ref_matcher; property_ref_matcher( |o: &$($t)::+| o.$method($($argument),*), &stringify!($method($($argument),*)), @@ -134,7 +134,10 @@ macro_rules! property_internal { /// **For internal use only. API stablility is not guaranteed!** #[doc(hidden)] pub mod internal { - use crate::matcher::{Matcher, MatcherResult}; + use crate::{ + description::Description, + matcher::{Matcher, MatcherResult}, + }; use std::{fmt::Debug, marker::PhantomData}; /// **For internal use only. API stablility is not guaranteed!** @@ -167,15 +170,16 @@ pub mod internal { self.inner.matches(&(self.extractor)(actual)) } - fn describe(&self, matcher_result: MatcherResult) -> String { + fn describe(&self, matcher_result: MatcherResult) -> Description { format!( "has property `{}`, which {}", self.property_desc, self.inner.describe(matcher_result) ) + .into() } - fn explain_match(&self, actual: &OuterT) -> String { + fn explain_match(&self, actual: &OuterT) -> Description { let actual_inner = (self.extractor)(actual); format!( "whose property `{}` is `{:#?}`, {}", @@ -183,6 +187,7 @@ pub mod internal { actual_inner, self.inner.explain_match(&actual_inner) ) + .into() } } @@ -216,15 +221,16 @@ pub mod internal { self.inner.matches((self.extractor)(actual)) } - fn describe(&self, matcher_result: MatcherResult) -> String { + fn describe(&self, matcher_result: MatcherResult) -> Description { format!( "has property `{}`, which {}", self.property_desc, self.inner.describe(matcher_result) ) + .into() } - fn explain_match(&self, actual: &OuterT) -> String { + fn explain_match(&self, actual: &OuterT) -> Description { let actual_inner = (self.extractor)(actual); format!( "whose property `{}` is `{:#?}`, {}", @@ -232,6 +238,7 @@ pub mod internal { actual_inner, self.inner.explain_match(actual_inner) ) + .into() } } } |