googletest/matchers/
all_matcher.rs1#![doc(hidden)]
18
19#[macro_export]
63#[doc(hidden)]
64macro_rules! __all {
65 ($(,)?) => {{
66 $crate::matchers::anything()
67 }} ;
68 ($matcher:expr $(,)?) => {{
69 use $crate::matcher_support::__internal_unstable_do_not_depend_on_these::auto_eq;
70 auto_eq!($matcher)
71 }};
72 ($head:expr, $head2:expr $(,)?) => {{
73 use $crate::matcher_support::__internal_unstable_do_not_depend_on_these::auto_eq;
74 $crate::matchers::__internal_unstable_do_not_depend_on_these::ConjunctionMatcher::new(auto_eq!($head), auto_eq!($head2))
75 }};
76 ($head:expr, $head2:expr, $($tail:expr),+ $(,)?) => {{
77 use $crate::matcher_support::__internal_unstable_do_not_depend_on_these::auto_eq;
78 $crate::__all![
79 $crate::matchers::__internal_unstable_do_not_depend_on_these::ConjunctionMatcher::new(auto_eq!($head), auto_eq!($head2)),
80 $($tail),+
81 ]
82 }}
83}
84
85#[cfg(test)]
86mod tests {
87 use crate::matcher::MatcherResult;
88 use crate::prelude::*;
89 use crate::Result;
90 use indoc::indoc;
91
92 #[test]
93 fn description_shows_more_than_one_matcher() -> Result<()> {
94 let first_matcher = starts_with("A");
95 let second_matcher = ends_with("string");
96 let matcher = all!(first_matcher, second_matcher);
97
98 verify_that!(
99 Matcher::<&String>::describe(&matcher, MatcherResult::Match),
100 displays_as(eq(indoc!(
101 "
102 has all the following properties:
103 * starts with prefix \"A\"
104 * ends with suffix \"string\""
105 )))
106 )
107 }
108
109 #[test]
110 fn description_shows_one_matcher_directly() -> Result<()> {
111 let first_matcher = starts_with("A");
112 let matcher = all!(first_matcher);
113
114 verify_that!(
115 Matcher::<&String>::describe(&matcher, MatcherResult::Match),
116 displays_as(eq("starts with prefix \"A\""))
117 )
118 }
119
120 #[test]
121 fn mismatch_description_shows_which_matcher_failed_if_more_than_one_constituent() -> Result<()>
122 {
123 let first_matcher = starts_with("Another");
124 let second_matcher = ends_with("string");
125 let matcher = all!(first_matcher, second_matcher);
126
127 verify_that!(
128 matcher.explain_match("A string"),
129 displays_as(eq("which does not start with \"Another\""))
130 )
131 }
132
133 #[test]
134 fn mismatch_description_is_simple_when_only_one_consistuent() -> Result<()> {
135 let first_matcher = starts_with("Another");
136 let matcher = all!(first_matcher);
137
138 verify_that!(
139 matcher.explain_match("A string"),
140 displays_as(eq("which does not start with \"Another\""))
141 )
142 }
143
144 #[test]
145 fn all_with_auto_eq() -> Result<()> {
146 verify_that!(42, all![eq(42), 42, lt(100)])
147 }
148}