//===-- Matchers.h ----------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // GMock matchers that aren't specific to particular tests. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_MATCHERS_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_MATCHERS_H #include "Protocol.h" #include "gmock/gmock.h" namespace clang { namespace clangd { Matcher; // EXPECT_IFF expects matcher if condition is true, and Not(matcher) if false. // This is hard to write as a function, because matchers may be polymorphic. #define EXPECT_IFF(condition, value, matcher) … // HasSubsequence(m1, m2, ...) matches a vector containing elements that match // m1, m2 ... in that order. // // SubsequenceMatcher implements this once the type of vector is known. template <typename T> class SubsequenceMatcher : public ::testing::MatcherInterface<const std::vector<T> &> { … }; // PolySubsequenceMatcher implements a "polymorphic" SubsequenceMatcher. // It captures the types of the element matchers, and can be converted to // Matcher<vector<T>> if each matcher can be converted to Matcher<T>. // This allows HasSubsequence() to accept polymorphic matchers like Not(). template <typename... M> class PolySubsequenceMatcher { … }; // HasSubsequence(m1, m2, ...) matches a vector containing elements that match // m1, m2 ... in that order. // The real implementation is in SubsequenceMatcher. template <typename... Args> PolySubsequenceMatcher<Args...> HasSubsequence(Args &&... M) { … } // EXPECT_ERROR seems like a pretty generic name, make sure it's not defined // already. #ifdef EXPECT_ERROR #error "Refusing to redefine EXPECT_ERROR" #endif // Consumes llvm::Expected<T>, checks it contains an error and marks it as // handled. #define EXPECT_ERROR(expectedValue) … // Implements the HasValue(m) matcher for matching an Optional whose // value matches matcher m. template <typename InnerMatcher> class OptionalMatcher { … }; // Creates a matcher that matches an Optional that has a value // that matches inner_matcher. template <typename InnerMatcher> inline OptionalMatcher<InnerMatcher> HasValue(const InnerMatcher &inner_matcher) { … } } // namespace clangd } // namespace clang #endif