This commit is contained in:
nickbrekhus 2024-09-17 20:01:16 +02:00 committed by GitHub
commit 0558d639df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -1796,9 +1796,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<float>, a
// Matcher<const float&>, or a Matcher<float&>, but nothing else.
// The following 4 type conversion operators allow FloatEq(expected) and
// NanSensitiveFloatEq(expected) to be used as a Matcher<const float>,
// a Matcher<float>, a Matcher<const float&>, or a Matcher<float&>,
// but nothing else.
operator Matcher<const FloatType>() const {
return MakeMatcher(
new Impl<const FloatType>(expected_, nan_eq_nan_, max_abs_error_));
}
operator Matcher<FloatType>() const {
return MakeMatcher(
new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));

View File

@ -696,6 +696,11 @@ TEST(OptionalTest, DescribesSelf) {
EXPECT_EQ("value is equal to 1", Describe(m));
}
TEST(OptionalTest, WorksWithConstDouble) {
const SampleOptional<const double> opt(3.14159);
EXPECT_THAT(opt, Optional(DoubleEq(3.14159)));
}
TEST(OptionalTest, ExplainsSelf) {
const Matcher<SampleOptional<int>> m = Optional(Eq(1));
EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptional<int>(1)));