From 8ffc42998b2cea3604e3824b36cf9e05d5cc0ce6 Mon Sep 17 00:00:00 2001 From: Nicholas Brekhus Date: Thu, 8 Feb 2024 12:23:48 -0800 Subject: [PATCH] FloatingEqMatcher supports conversion to const float types --- googlemock/include/gmock/gmock-matchers.h | 12 +++++++++--- googlemock/test/gmock-matchers-misc_test.cc | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index c4149f2e..61c6be24 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1761,9 +1761,15 @@ class FloatingEqMatcher { const FloatType max_abs_error_; }; - // The following 3 type conversion operators allow FloatEq(expected) and - // NanSensitiveFloatEq(expected) to be used as a Matcher, a - // Matcher, or a Matcher, but nothing else. + // The following 4 type conversion operators allow FloatEq(expected) and + // NanSensitiveFloatEq(expected) to be used as a Matcher, + // a Matcher, a Matcher, or a Matcher, + // but nothing else. + operator Matcher() const { + return MakeMatcher( + new Impl(expected_, nan_eq_nan_, max_abs_error_)); + } + operator Matcher() const { return MakeMatcher( new Impl(expected_, nan_eq_nan_, max_abs_error_)); diff --git a/googlemock/test/gmock-matchers-misc_test.cc b/googlemock/test/gmock-matchers-misc_test.cc index b8f64587..11e91ac8 100644 --- a/googlemock/test/gmock-matchers-misc_test.cc +++ b/googlemock/test/gmock-matchers-misc_test.cc @@ -696,6 +696,11 @@ TEST(OptionalTest, DescribesSelf) { EXPECT_EQ("value is equal to 1", Describe(m)); } +TEST(OptionalTest, WorksWithConstDouble) { + const SampleOptional opt(3.14159); + EXPECT_THAT(opt, Optional(DoubleEq(3.14159))); +} + TEST(OptionalTest, ExplainsSelf) { const Matcher> m = Optional(Eq(1)); EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptional(1)));