summaryrefslogtreecommitdiffstats
path: root/googlemock/include
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-08-23 19:30:05 (GMT)
committerXiaoyi Zhang <zhangxy@google.com>2019-08-23 20:39:21 (GMT)
commited2eef654373c17b96bf5a007bb481a6e96ba629 (patch)
treee5c3c53af7c0c8f153a36aeab0daa617cc145140 /googlemock/include
parentdb1b739943e9ea996105239573e3c38a50bf38cc (diff)
downloadgoogletest-ed2eef654373c17b96bf5a007bb481a6e96ba629.zip
googletest-ed2eef654373c17b96bf5a007bb481a6e96ba629.tar.gz
googletest-ed2eef654373c17b96bf5a007bb481a6e96ba629.tar.bz2
Googletest export
Add tuple version of Optional() matches. This allows Optional() to be used in Pointwise matchers. PiperOrigin-RevId: 265110864
Diffstat (limited to 'googlemock/include')
-rw-r--r--googlemock/include/gmock/gmock-matchers.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index b1c0dc0..40e0452 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -3239,10 +3239,16 @@ class OptionalMatcher {
: value_matcher_(value_matcher) {}
template <typename Optional>
- operator Matcher<Optional>() const {
+ operator Matcher<Optional>() const { // NOLINT
return Matcher<Optional>(new Impl<const Optional&>(value_matcher_));
}
+ template <typename Optional1, typename ValueType2>
+ operator Matcher<std::tuple<Optional1, ValueType2>>() const { // NOLINT
+ return MakeMatcher(
+ new PairImpl<Optional1, ValueType2>(value_matcher_));
+ }
+
template <typename Optional>
class Impl : public MatcherInterface<Optional> {
public:
@@ -3281,6 +3287,49 @@ class OptionalMatcher {
GTEST_DISALLOW_ASSIGN_(Impl);
};
+ template <typename Optional1, typename ValueType2>
+ class PairImpl : public MatcherInterface<std::tuple<Optional1, ValueType2>> {
+ public:
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional1) Optional1View;
+ typedef typename Optional1View::value_type ValueType1;
+ typedef std::tuple<Optional1, ValueType2> OptionalTuple;
+ typedef std::tuple<ValueType1, ValueType2> ValuePair;
+
+ explicit PairImpl(const ValueMatcher& value_matcher)
+ : value_matcher_(MatcherCast<ValuePair>(value_matcher)) {}
+
+ void DescribeTo(::std::ostream* os) const override {
+ *os << "are optionals where the values ";
+ value_matcher_.DescribeTo(os);
+ }
+
+ void DescribeNegationTo(::std::ostream* os) const override {
+ *os << "are optionals where the values ";
+ value_matcher_.DescribeNegationTo(os);
+ }
+
+ bool MatchAndExplain(OptionalTuple optional_tuple,
+ MatchResultListener* listener) const override {
+ const auto& optional1 = std::get<0>(optional_tuple);
+ const auto& value2 = std::get<1>(optional_tuple);
+ if (!optional1) {
+ *listener << "left is nullopt";
+ return false;
+ }
+ const ValueType1& value1 = *optional1;
+ StringMatchResultListener value_listener;
+ const bool match = value_matcher_.MatchAndExplain(
+ std::make_tuple(value1, value2), &value_listener);
+ *listener << (match ? "which match" : "whose values don't match");
+ PrintIfNotEmpty(value_listener.str(), listener->stream());
+ return match;
+ }
+
+ private:
+ const Matcher<ValuePair> value_matcher_;
+ GTEST_DISALLOW_ASSIGN_(PairImpl);
+ };
+
private:
const ValueMatcher value_matcher_;
GTEST_DISALLOW_ASSIGN_(OptionalMatcher);