SupportHelpers.h supports both for now to ease migration.
template <typename InfoT>
class ErrorMatchesMono : public testing::MatcherInterface<const ErrorHolder &> {
public:
- explicit ErrorMatchesMono(Optional<testing::Matcher<InfoT &>> Matcher)
+ explicit ErrorMatchesMono(std::optional<testing::Matcher<InfoT &>> Matcher)
: Matcher(std::move(Matcher)) {}
bool MatchAndExplain(const ErrorHolder &Holder,
}
private:
- Optional<testing::Matcher<InfoT &>> Matcher;
+ std::optional<testing::Matcher<InfoT &>> Matcher;
};
class ErrorMessageMatches
: ValueMatcher(ValueMatcher) {}
template <class T>
- operator ::testing::Matcher<const llvm::Optional<T> &>() const {
+ operator ::testing::Matcher<const std::optional<T> &>() const {
return ::testing::MakeMatcher(
new Impl<T>(::testing::SafeMatcherCast<T>(ValueMatcher)));
}
template <class T>
- class Impl : public ::testing::MatcherInterface<const llvm::Optional<T> &> {
+ operator ::testing::Matcher<const Optional<T> &>() const {
+ return ::testing::MakeMatcher(
+ new Impl<T, Optional<T>>(::testing::SafeMatcherCast<T>(ValueMatcher)));
+ }
+
+ template <class T, class O = std::optional<T>>
+ class Impl : public ::testing::MatcherInterface<const O &> {
public:
explicit Impl(const ::testing::Matcher<T> &ValueMatcher)
: ValueMatcher(ValueMatcher) {}
- bool MatchAndExplain(const llvm::Optional<T> &Input,
+ bool MatchAndExplain(const O &Input,
testing::MatchResultListener *L) const override {
return Input && ValueMatcher.MatchAndExplain(*Input, L);
}
};
} // namespace detail
-/// Matches an llvm::Optional<T> with a value that conforms to an inner matcher.
+/// Matches an std::optional<T> with a value that conforms to an inner matcher.
/// To match std::nullopt you could use Eq(std::nullopt).
template <class InnerMatcher>
detail::ValueIsMatcher<InnerMatcher> ValueIs(const InnerMatcher &ValueMatcher) {
auto Require = [Text](bool Assertion, const char *Msg) {
require(Assertion, Msg, Text);
};
- llvm::Optional<llvm::StringRef> Name;
- llvm::Optional<llvm::StringRef> Payload;
+ std::optional<llvm::StringRef> Name;
+ std::optional<llvm::StringRef> Payload;
llvm::SmallVector<Annotation, 8> OpenRanges;
Code.reserve(Text.size());
namespace {
TEST(MatchersTest, Optional) {
- EXPECT_THAT(llvm::Optional<int>(std::nullopt), Not(llvm::ValueIs(_)));
- EXPECT_THAT(llvm::Optional<int>(10), llvm::ValueIs(10));
- EXPECT_THAT(llvm::Optional<int>(10), llvm::ValueIs(AllOf(Lt(11), Gt(9))));
+ EXPECT_THAT(std::optional<int>(std::nullopt), Not(llvm::ValueIs(_)));
+ EXPECT_THAT(std::optional<int>(10), llvm::ValueIs(10));
+ EXPECT_THAT(std::optional<int>(10), llvm::ValueIs(AllOf(Lt(11), Gt(9))));
}
} // namespace