diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index 22ad0214..b53cbd59 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -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 just based on the number of parameters). -### Writing New Monomorphic Matchers +### Writing New Monomorphic Matchers {#MonomorphicMatchers} A matcher of type `testing::Matcher` implements the matcher interface for `T` 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*` 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 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 polymorphic matcher as a *matcher factory* as opposed to a `testing::Matcher` - itself is not an actual matcher, but can be diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md index 4c234e17..665feee9 100644 --- a/docs/reference/matchers.md +++ b/docs/reference/matchers.md @@ -1,5 +1,7 @@ # Matchers Reference + + 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: @@ -297,6 +299,13 @@ which must be a permanent callback. ## 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 | | :----------------------------------- | :------------------------------------ | | `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |