mirror of
https://github.com/google/googletest.git
synced 2026-04-30 19:09:20 +08:00
Point from the "Defining Matchers" section in the reference doc to the cookbook, which is much more detailed.
PiperOrigin-RevId: 852639172 Change-Id: Ia39a01702c7c64404950a1be19b1ebdfdff8f010
This commit is contained in:
parent
9156d4caac
commit
76cd89bcf1
@ -3566,7 +3566,7 @@ general leads to better compiler error messages that pay off in the long run.
|
|||||||
They also allow overloading matchers based on parameter types (as opposed to
|
They also allow overloading matchers based on parameter types (as opposed to
|
||||||
just based on the number of parameters).
|
just based on the number of parameters).
|
||||||
|
|
||||||
### Writing New Monomorphic Matchers
|
### Writing New Monomorphic Matchers {#MonomorphicMatchers}
|
||||||
|
|
||||||
A matcher of type `testing::Matcher<T>` implements the matcher interface for `T`
|
A matcher of type `testing::Matcher<T>` implements the matcher interface for `T`
|
||||||
and does two things: it tests whether a value of type `T` matches the matcher,
|
and does two things: it tests whether a value of type `T` matches the matcher,
|
||||||
@ -3666,11 +3666,11 @@ Expected: is divisible by 7
|
|||||||
Tip: for convenience, `MatchAndExplain()` can take a `MatchResultListener*`
|
Tip: for convenience, `MatchAndExplain()` can take a `MatchResultListener*`
|
||||||
instead of `std::ostream*`.
|
instead of `std::ostream*`.
|
||||||
|
|
||||||
### Writing New Polymorphic Matchers
|
### Writing New Polymorphic Matchers {#PolymorphicMatchers}
|
||||||
|
|
||||||
Unlike a monomorphic matcher, which can only be used to match a value of a
|
Unlike a monomorphic matcher, which can only be used to match a value of a
|
||||||
particular type, a *polymorphic* matcher is one that can be used to match values
|
particular type, a *polymorphic* matcher is one that can be used to match values
|
||||||
of multiple types. For example, `Eq(5)` is a polymorhpic matcher as it can be
|
of multiple types. For example, `Eq(5)` is a polymorphic matcher as it can be
|
||||||
used to match an `int`, a `double`, a `float`, and so on. You should think of a
|
used to match an `int`, a `double`, a `float`, and so on. You should think of a
|
||||||
polymorphic matcher as a *matcher factory* as opposed to a
|
polymorphic matcher as a *matcher factory* as opposed to a
|
||||||
`testing::Matcher<SomeType>` - itself is not an actual matcher, but can be
|
`testing::Matcher<SomeType>` - itself is not an actual matcher, but can be
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
# Matchers Reference
|
# Matchers Reference
|
||||||
|
|
||||||
|
<!-- disableFinding(LINK_RELATIVE_G3DOC) -->
|
||||||
|
|
||||||
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
|
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
|
||||||
`EXPECT_CALL()`, or use it to validate a value directly using two macros:
|
`EXPECT_CALL()`, or use it to validate a value directly using two macros:
|
||||||
|
|
||||||
@ -297,6 +299,13 @@ which must be a permanent callback.
|
|||||||
|
|
||||||
## Defining Matchers
|
## Defining Matchers
|
||||||
|
|
||||||
|
{: .callout .note}
|
||||||
|
Note: full details about defining new matchers are in the
|
||||||
|
[cookbook](../gmock_cook_book.md#NewMatchers). In particular, if `MATCHER`
|
||||||
|
macros are not sufficient, you can directly implement
|
||||||
|
[monomorphic](../gmock_cook_book.md#MonomorphicMatchers) or
|
||||||
|
[polymorphic](../gmock_cook_book.md#PolymorphicMatchers) matchers.
|
||||||
|
|
||||||
| Macro | Description |
|
| Macro | Description |
|
||||||
| :----------------------------------- | :------------------------------------ |
|
| :----------------------------------- | :------------------------------------ |
|
||||||
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |
|
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user