diff --git a/clang-tools-extra/clangd/unittests/Matchers.h b/clang-tools-extra/clangd/unittests/Matchers.h index 0fbd93b2e68825..17d18dd9b85b65 100644 --- a/clang-tools-extra/clangd/unittests/Matchers.h +++ b/clang-tools-extra/clangd/unittests/Matchers.h @@ -127,74 +127,6 @@ PolySubsequenceMatcher HasSubsequence(Args &&... M) { llvm::consumeError(ComputedValue.takeError()); \ } while (false) -// Implements the HasValue(m) matcher for matching an Optional whose -// value matches matcher m. -template class OptionalMatcher { -public: - explicit OptionalMatcher(const InnerMatcher &matcher) : matcher_(matcher) {} - OptionalMatcher(const OptionalMatcher&) = default; - OptionalMatcher &operator=(const OptionalMatcher&) = delete; - - // This type conversion operator template allows Optional(m) to be - // used as a matcher for any Optional type whose value type is - // compatible with the inner matcher. - // - // The reason we do this instead of relying on - // MakePolymorphicMatcher() is that the latter is not flexible - // enough for implementing the DescribeTo() method of Optional(). - template operator Matcher() const { - return MakeMatcher(new Impl(matcher_)); - } - -private: - // The monomorphic implementation that works for a particular optional type. - template - class Impl : public ::testing::MatcherInterface { - public: - using Value = typename std::remove_const< - typename std::remove_reference::type>::type::value_type; - - explicit Impl(const InnerMatcher &matcher) - : matcher_(::testing::MatcherCast(matcher)) {} - - Impl(const Impl&) = default; - Impl &operator=(const Impl&) = delete; - - virtual void DescribeTo(::std::ostream *os) const { - *os << "has a value that "; - matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream *os) const { - *os << "does not have a value that "; - matcher_.DescribeTo(os); - } - - virtual bool - MatchAndExplain(Optional optional, - ::testing::MatchResultListener *listener) const { - if (!optional) - return false; - - *listener << "which has a value "; - return MatchPrintAndExplain(*optional, matcher_, listener); - } - - private: - const Matcher matcher_; - }; - - const InnerMatcher matcher_; -}; - -// Creates a matcher that matches an Optional that has a value -// that matches inner_matcher. -template -inline OptionalMatcher -HasValue(const InnerMatcher &inner_matcher) { - return OptionalMatcher(inner_matcher); -} - } // namespace clangd } // namespace clang #endif diff --git a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp index 15158d8a45ca8b..406a842f5a0081 100644 --- a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp +++ b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp @@ -28,6 +28,7 @@ using ::testing::ElementsAre; using ::testing::Field; using ::testing::IsEmpty; using ::testing::Matcher; +using ::testing::Optional; using ::testing::SizeIs; using ::testing::UnorderedElementsAre; @@ -38,12 +39,12 @@ MATCHER_P(selectionRangeIs, R, "") { return arg.selectionRange == R; } template ::testing::Matcher parents(ParentMatchers... ParentsM) { return Field(&TypeHierarchyItem::parents, - HasValue(UnorderedElementsAre(ParentsM...))); + Optional(UnorderedElementsAre(ParentsM...))); } template ::testing::Matcher children(ChildMatchers... ChildrenM) { return Field(&TypeHierarchyItem::children, - HasValue(UnorderedElementsAre(ChildrenM...))); + Optional(UnorderedElementsAre(ChildrenM...))); } // Note: "not resolved" is different from "resolved but empty"! MATCHER(parentsNotResolved, "") { return !arg.parents; } @@ -790,7 +791,7 @@ struct Child : Parent1, Parent2 {}; Children, UnorderedElementsAre( AllOf(withName("Child"), - withResolveParents(HasValue(UnorderedElementsAre(withResolveID( + withResolveParents(Optional(UnorderedElementsAre(withResolveID( getSymbolID(&findDecl(AST, "Parent1")).str()))))))); } @@ -810,9 +811,9 @@ struct Chil^d : Parent {}; ASSERT_THAT(Result, SizeIs(1)); auto Parents = superTypes(Result.front(), Index.get()); - EXPECT_THAT(Parents, HasValue(UnorderedElementsAre( + EXPECT_THAT(Parents, Optional(UnorderedElementsAre( AllOf(withName("Parent"), - withResolveParents(HasValue(IsEmpty())))))); + withResolveParents(Optional(IsEmpty())))))); } } // namespace } // namespace clangd