Skip to content

Commit 354ebf3

Browse files
Merge pull request #258 from google:rename-matcher-result-variants
PiperOrigin-RevId: 548141383
2 parents 9e610d5 + 4e81bc2 commit 354ebf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+264
-280
lines changed

googletest/crate_docs.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {
178178
179179
fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
180180
if self.expected == *actual {
181-
MatcherResult::Matches
181+
MatcherResult::Match
182182
} else {
183-
MatcherResult::DoesNotMatch
183+
MatcherResult::NoMatch
184184
}
185185
}
186186
187187
fn describe(&self, matcher_result: MatcherResult) -> String {
188188
match matcher_result {
189-
MatcherResult::Matches => {
189+
MatcherResult::Match => {
190190
format!("is equal to {:?} the way I define it", self.expected)
191191
}
192-
MatcherResult::DoesNotMatch => {
192+
MatcherResult::NoMatch => {
193193
format!("isn't equal to {:?} the way I define it", self.expected)
194194
}
195195
}
@@ -212,18 +212,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {
212212
#
213213
# fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
214214
# if self.expected == *actual {
215-
# MatcherResult::Matches
215+
# MatcherResult::Match
216216
# } else {
217-
# MatcherResult::DoesNotMatch
217+
# MatcherResult::NoMatch
218218
# }
219219
# }
220220
#
221221
# fn describe(&self, matcher_result: MatcherResult) -> String {
222222
# match matcher_result {
223-
# MatcherResult::Matches => {
223+
# MatcherResult::Match => {
224224
# format!("is equal to {:?} the way I define it", self.expected)
225225
# }
226-
# MatcherResult::DoesNotMatch => {
226+
# MatcherResult::NoMatch => {
227227
# format!("isn't equal to {:?} the way I define it", self.expected)
228228
# }
229229
# }
@@ -251,18 +251,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {
251251
#
252252
# fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
253253
# if self.expected == *actual {
254-
# MatcherResult::Matches
254+
# MatcherResult::Match
255255
# } else {
256-
# MatcherResult::DoesNotMatch
256+
# MatcherResult::NoMatch
257257
# }
258258
# }
259259
#
260260
# fn describe(&self, matcher_result: MatcherResult) -> String {
261261
# match matcher_result {
262-
# MatcherResult::Matches => {
262+
# MatcherResult::Match => {
263263
# format!("is equal to {:?} the way I define it", self.expected)
264264
# }
265-
# MatcherResult::DoesNotMatch => {
265+
# MatcherResult::NoMatch => {
266266
# format!("isn't equal to {:?} the way I define it", self.expected)
267267
# }
268268
# }

googletest/src/assertions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ pub mod internal {
411411
source_location: SourceLocation,
412412
) -> Result<(), TestAssertionFailure> {
413413
match expected.matches(actual) {
414-
MatcherResult::Matches => Ok(()),
415-
MatcherResult::DoesNotMatch => {
414+
MatcherResult::Match => Ok(()),
415+
MatcherResult::NoMatch => {
416416
Err(create_assertion_failure(&expected, actual, actual_expr, source_location))
417417
}
418418
}

googletest/src/matcher.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Expected: {}
225225
Actual: {actual_formatted},
226226
{}
227227
{source_location}",
228-
matcher.describe(MatcherResult::Matches),
228+
matcher.describe(MatcherResult::Match),
229229
matcher.explain_match(actual),
230230
))
231231
}
@@ -234,28 +234,28 @@ Actual: {actual_formatted},
234234
#[derive(Debug, PartialEq, Clone, Copy)]
235235
pub enum MatcherResult {
236236
/// The actual value matches according to the [`Matcher`] definition.
237-
Matches,
237+
Match,
238238
/// The actual value does not match according to the [`Matcher`] definition.
239-
DoesNotMatch,
239+
NoMatch,
240240
}
241241

242242
impl From<bool> for MatcherResult {
243243
fn from(b: bool) -> Self {
244-
if b { MatcherResult::Matches } else { MatcherResult::DoesNotMatch }
244+
if b { MatcherResult::Match } else { MatcherResult::NoMatch }
245245
}
246246
}
247247

248248
impl From<MatcherResult> for bool {
249249
fn from(matcher_result: MatcherResult) -> Self {
250250
match matcher_result {
251-
MatcherResult::Matches => true,
252-
MatcherResult::DoesNotMatch => false,
251+
MatcherResult::Match => true,
252+
MatcherResult::NoMatch => false,
253253
}
254254
}
255255
}
256256

257257
impl MatcherResult {
258-
/// Returns `true` if `self` is [`MatcherResult::Matches`], otherwise
258+
/// Returns `true` if `self` is [`MatcherResult::Match`], otherwise
259259
/// `false`.
260260
///
261261
/// This delegates to `Into<bool>` but coerce the return type to `bool`

googletest/src/matchers/all_matcher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ pub mod internal {
9292
fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
9393
for component in &self.components {
9494
match component.matches(actual) {
95-
MatcherResult::DoesNotMatch => {
96-
return MatcherResult::DoesNotMatch;
95+
MatcherResult::NoMatch => {
96+
return MatcherResult::NoMatch;
9797
}
98-
MatcherResult::Matches => {}
98+
MatcherResult::Match => {}
9999
}
100100
}
101-
MatcherResult::Matches
101+
MatcherResult::Match
102102
}
103103

104104
fn explain_match(&self, actual: &Self::ActualT) -> String {
@@ -161,7 +161,7 @@ mod tests {
161161
let matcher: internal::AllMatcher<String, 2> = all!(first_matcher, second_matcher);
162162

163163
verify_that!(
164-
matcher.describe(MatcherResult::Matches),
164+
matcher.describe(MatcherResult::Match),
165165
eq(indoc!(
166166
"
167167
has all the following properties:
@@ -176,7 +176,7 @@ mod tests {
176176
let first_matcher = starts_with("A");
177177
let matcher: internal::AllMatcher<String, 1> = all!(first_matcher);
178178

179-
verify_that!(matcher.describe(MatcherResult::Matches), eq("starts with prefix \"A\""))
179+
verify_that!(matcher.describe(MatcherResult::Match), eq("starts with prefix \"A\""))
180180
}
181181

182182
#[test]

googletest/src/matchers/anything_matcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ impl<T: Debug + ?Sized> Matcher for Anything<T> {
3939
type ActualT = T;
4040

4141
fn matches(&self, _: &T) -> MatcherResult {
42-
MatcherResult::Matches
42+
MatcherResult::Match
4343
}
4444

4545
fn describe(&self, matcher_result: MatcherResult) -> String {
4646
match matcher_result {
47-
MatcherResult::Matches => "is anything".to_string(),
48-
MatcherResult::DoesNotMatch => "never matches".to_string(),
47+
MatcherResult::Match => "is anything".to_string(),
48+
MatcherResult::NoMatch => "never matches".to_string(),
4949
}
5050
}
5151
}

googletest/src/matchers/char_count_matcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ impl<T: Debug + ?Sized + AsRef<str>, E: Matcher<ActualT = usize>> Matcher for Ch
7373

7474
fn describe(&self, matcher_result: MatcherResult) -> String {
7575
match matcher_result {
76-
MatcherResult::Matches => {
76+
MatcherResult::Match => {
7777
format!(
7878
"has character count, which {}",
79-
self.expected.describe(MatcherResult::Matches)
79+
self.expected.describe(MatcherResult::Match)
8080
)
8181
}
82-
MatcherResult::DoesNotMatch => {
82+
MatcherResult::NoMatch => {
8383
format!(
8484
"has character count, which {}",
85-
self.expected.describe(MatcherResult::DoesNotMatch)
85+
self.expected.describe(MatcherResult::NoMatch)
8686
)
8787
}
8888
}

googletest/src/matchers/conjunction_matcher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ where
3838

3939
fn matches(&self, actual: &M1::ActualT) -> MatcherResult {
4040
match (self.m1.matches(actual), self.m2.matches(actual)) {
41-
(MatcherResult::Matches, MatcherResult::Matches) => MatcherResult::Matches,
42-
_ => MatcherResult::DoesNotMatch,
41+
(MatcherResult::Match, MatcherResult::Match) => MatcherResult::Match,
42+
_ => MatcherResult::NoMatch,
4343
}
4444
}
4545

4646
fn explain_match(&self, actual: &M1::ActualT) -> String {
4747
match (self.m1.matches(actual), self.m2.matches(actual)) {
48-
(MatcherResult::Matches, MatcherResult::Matches) => {
48+
(MatcherResult::Match, MatcherResult::Match) => {
4949
format!(
5050
"{} and\n {}",
5151
self.m1.explain_match(actual),
5252
self.m2.explain_match(actual)
5353
)
5454
}
55-
(MatcherResult::DoesNotMatch, MatcherResult::Matches) => self.m1.explain_match(actual),
56-
(MatcherResult::Matches, MatcherResult::DoesNotMatch) => self.m2.explain_match(actual),
57-
(MatcherResult::DoesNotMatch, MatcherResult::DoesNotMatch) => {
55+
(MatcherResult::NoMatch, MatcherResult::Match) => self.m1.explain_match(actual),
56+
(MatcherResult::Match, MatcherResult::NoMatch) => self.m2.explain_match(actual),
57+
(MatcherResult::NoMatch, MatcherResult::NoMatch) => {
5858
format!(
5959
"{} and\n {}",
6060
self.m1.explain_match(actual),

googletest/src/matchers/container_eq_matcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ where
120120

121121
fn describe(&self, matcher_result: MatcherResult) -> String {
122122
match matcher_result {
123-
MatcherResult::Matches => format!("is equal to {:?}", self.expected),
124-
MatcherResult::DoesNotMatch => format!("isn't equal to {:?}", self.expected),
123+
MatcherResult::Match => format!("is equal to {:?}", self.expected),
124+
MatcherResult::NoMatch => format!("isn't equal to {:?}", self.expected),
125125
}
126126
}
127127
}
@@ -279,7 +279,7 @@ mod tests {
279279

280280
let result = matcher.matches(&actual);
281281

282-
verify_that!(result, eq(MatcherResult::DoesNotMatch))
282+
verify_that!(result, eq(MatcherResult::NoMatch))
283283
}
284284

285285
#[test]

googletest/src/matchers/contains_matcher.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ where
9292
} else {
9393
for v in actual.into_iter() {
9494
if self.inner.matches(v).into() {
95-
return MatcherResult::Matches;
95+
return MatcherResult::Match;
9696
}
9797
}
98-
MatcherResult::DoesNotMatch
98+
MatcherResult::NoMatch
9999
}
100100
}
101101

@@ -110,22 +110,22 @@ where
110110

111111
fn describe(&self, matcher_result: MatcherResult) -> String {
112112
match (matcher_result, &self.count) {
113-
(MatcherResult::Matches, Some(count)) => format!(
113+
(MatcherResult::Match, Some(count)) => format!(
114114
"contains n elements which {}\n where n {}",
115-
self.inner.describe(MatcherResult::Matches),
116-
count.describe(MatcherResult::Matches)
115+
self.inner.describe(MatcherResult::Match),
116+
count.describe(MatcherResult::Match)
117117
),
118-
(MatcherResult::DoesNotMatch, Some(count)) => format!(
118+
(MatcherResult::NoMatch, Some(count)) => format!(
119119
"doesn't contain n elements which {}\n where n {}",
120-
self.inner.describe(MatcherResult::Matches),
121-
count.describe(MatcherResult::Matches)
120+
self.inner.describe(MatcherResult::Match),
121+
count.describe(MatcherResult::Match)
122122
),
123-
(MatcherResult::Matches, None) => format!(
123+
(MatcherResult::Match, None) => format!(
124124
"contains at least one element which {}",
125-
self.inner.describe(MatcherResult::Matches)
125+
self.inner.describe(MatcherResult::Match)
126126
),
127-
(MatcherResult::DoesNotMatch, None) => {
128-
format!("contains no element which {}", self.inner.describe(MatcherResult::Matches))
127+
(MatcherResult::NoMatch, None) => {
128+
format!("contains no element which {}", self.inner.describe(MatcherResult::Match))
129129
}
130130
}
131131
}
@@ -159,7 +159,7 @@ mod tests {
159159

160160
let result = matcher.matches(&vec![1]);
161161

162-
verify_that!(result, eq(MatcherResult::Matches))
162+
verify_that!(result, eq(MatcherResult::Match))
163163
}
164164

165165
#[test]
@@ -168,7 +168,7 @@ mod tests {
168168

169169
let result = matcher.matches(&vec![1]);
170170

171-
verify_that!(result, eq(MatcherResult::Matches))
171+
verify_that!(result, eq(MatcherResult::Match))
172172
}
173173

174174
#[test]
@@ -177,7 +177,7 @@ mod tests {
177177

178178
let result = matcher.matches(&[0, 1]);
179179

180-
verify_that!(result, eq(MatcherResult::Matches))
180+
verify_that!(result, eq(MatcherResult::Match))
181181
}
182182

183183
#[test]
@@ -186,7 +186,7 @@ mod tests {
186186

187187
let result = matcher.matches(&[0]);
188188

189-
verify_that!(result, eq(MatcherResult::DoesNotMatch))
189+
verify_that!(result, eq(MatcherResult::NoMatch))
190190
}
191191

192192
#[test]
@@ -195,7 +195,7 @@ mod tests {
195195

196196
let result = matcher.matches(&[]);
197197

198-
verify_that!(result, eq(MatcherResult::DoesNotMatch))
198+
verify_that!(result, eq(MatcherResult::NoMatch))
199199
}
200200

201201
#[test]
@@ -204,7 +204,7 @@ mod tests {
204204

205205
let result = matcher.matches(&[1, 1]);
206206

207-
verify_that!(result, eq(MatcherResult::Matches))
207+
verify_that!(result, eq(MatcherResult::Match))
208208
}
209209

210210
#[test]
@@ -213,7 +213,7 @@ mod tests {
213213

214214
let result = matcher.matches(&[0, 1]);
215215

216-
verify_that!(result, eq(MatcherResult::DoesNotMatch))
216+
verify_that!(result, eq(MatcherResult::NoMatch))
217217
}
218218

219219
#[test]
@@ -222,15 +222,15 @@ mod tests {
222222

223223
let result = matcher.matches(&[1, 1]);
224224

225-
verify_that!(result, eq(MatcherResult::DoesNotMatch))
225+
verify_that!(result, eq(MatcherResult::NoMatch))
226226
}
227227

228228
#[test]
229229
fn contains_formats_without_multiplicity_by_default() -> Result<()> {
230230
let matcher: ContainsMatcher<Vec<i32>, _> = contains(eq(1));
231231

232232
verify_that!(
233-
Matcher::describe(&matcher, MatcherResult::Matches),
233+
Matcher::describe(&matcher, MatcherResult::Match),
234234
eq("contains at least one element which is equal to 1")
235235
)
236236
}
@@ -240,7 +240,7 @@ mod tests {
240240
let matcher: ContainsMatcher<Vec<i32>, _> = contains(eq(1)).times(eq(2));
241241

242242
verify_that!(
243-
Matcher::describe(&matcher, MatcherResult::Matches),
243+
Matcher::describe(&matcher, MatcherResult::Match),
244244
eq("contains n elements which is equal to 1\n where n is equal to 2")
245245
)
246246
}

0 commit comments

Comments
 (0)