mirror of
https://github.com/google/googletest.git
synced 2025-12-02 00:57:37 -05:00
Modernize example of combining matchers.
As of C++14 an ordinary function can have an `auto` return type. PiperOrigin-RevId: 826617761 Change-Id: I2ceecc8430643c0ac7843fb216b5a117cfe10ab3
This commit is contained in:
committed by
Copybara-Service
parent
17d335d7c7
commit
6ec14dfd8c
@@ -900,15 +900,16 @@ using ::testing::Not;
|
|||||||
|
|
||||||
Matchers are function objects, and parametrized matchers can be composed just
|
Matchers are function objects, and parametrized matchers can be composed just
|
||||||
like any other function. However because their types can be long and rarely
|
like any other function. However because their types can be long and rarely
|
||||||
provide meaningful information, it can be easier to express them with C++14
|
provide meaningful information, it can be easier to express them with template
|
||||||
generic lambdas to avoid specifying types. For example,
|
parameters and `auto`. For example,
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
using ::testing::Contains;
|
using ::testing::Contains;
|
||||||
using ::testing::Property;
|
using ::testing::Property;
|
||||||
|
|
||||||
inline constexpr auto HasFoo = [](const auto& f) {
|
template <typename SubMatcher>
|
||||||
return Property("foo", &MyClass::foo, Contains(f));
|
inline constexpr auto HasFoo(const SubMatcher& sub_matcher) {
|
||||||
|
return Property("foo", &MyClass::foo, Contains(sub_matcher));
|
||||||
};
|
};
|
||||||
...
|
...
|
||||||
EXPECT_THAT(x, HasFoo("blah"));
|
EXPECT_THAT(x, HasFoo("blah"));
|
||||||
|
|||||||
Reference in New Issue
Block a user