summaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock-matchers_test.cc
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/test/gmock-matchers_test.cc
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/test/gmock-matchers_test.cc')
-rw-r--r--googlemock/test/gmock-matchers_test.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index a61d040..f5e25e0 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -6387,7 +6387,7 @@ class SampleOptional {
explicit SampleOptional(T value)
: value_(std::move(value)), has_value_(true) {}
SampleOptional() : value_(), has_value_(false) {}
- operator bool() const { return has_value_; }
+ explicit operator bool() const { return has_value_; }
const T& operator*() const { return value_; }
private:
@@ -6427,6 +6427,39 @@ TEST(OptionalTest, WorksWithMoveOnly) {
EXPECT_TRUE(m.Matches(SampleOptional<std::unique_ptr<int>>(nullptr)));
}
+TEST(OptionalTest, TupleDescribesSelf) {
+ const Matcher<std::tuple<SampleOptional<int>, int>> m = Optional(Eq());
+ EXPECT_EQ("are optionals where the values are an equal pair", Describe(m));
+}
+
+TEST(OptionalTest, TupleExplainsSelf) {
+ const Matcher<std::tuple<SampleOptional<int>, int>> m = Optional(Eq());
+ EXPECT_EQ("which match",
+ Explain(m, std::make_tuple(SampleOptional<int>(1), 1)));
+ EXPECT_EQ("whose values don't match",
+ Explain(m, std::make_tuple(SampleOptional<int>(1), 2)));
+}
+
+TEST(OptionalTest, TupleMatchesNonEmpty) {
+ const Matcher<std::tuple<SampleOptional<int>, int>> m1 = Optional(Eq());
+ const Matcher<std::tuple<SampleOptional<int>, int>> m2 = Optional(Lt());
+ EXPECT_TRUE(m1.Matches(std::make_tuple(SampleOptional<int>(1), 1)));
+ EXPECT_FALSE(m1.Matches(std::make_tuple(SampleOptional<int>(1), 2)));
+ EXPECT_FALSE(m2.Matches(std::make_tuple(SampleOptional<int>(1), 1)));
+ EXPECT_TRUE(m2.Matches(std::make_tuple(SampleOptional<int>(1), 2)));
+}
+
+TEST(OptionalTest, TupleDoesNotMatchNullopt) {
+ const Matcher<std::tuple<SampleOptional<int>, int>> m1 = Optional(Eq());
+ EXPECT_FALSE(m1.Matches(std::make_tuple(SampleOptional<int>(), 1)));
+}
+
+TEST(OptionalTest, TupleWorksInPointwise) {
+ std::vector<SampleOptional<int>> v = {
+ SampleOptional<int>(1), SampleOptional<int>(2), SampleOptional<int>(3)};
+ EXPECT_THAT(v, Pointwise(Optional(Eq()), {1, 2, 3}));
+}
+
class SampleVariantIntString {
public:
SampleVariantIntString(int i) : i_(i), has_int_(true) {}