13 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_MATCHERS_H 14 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_MATCHERS_H 16 #include "gmock/gmock.h" 20 using ::testing::Matcher;
24 #define EXPECT_IFF(condition, value, matcher) \ 27 EXPECT_THAT(value, matcher); \ 29 EXPECT_THAT(value, ::testing::Not(matcher)); \ 38 :
public ::testing::MatcherInterface<const std::vector<T> &> {
39 std::vector<Matcher<T>> Matchers;
45 *OS <<
"Contains the subsequence [";
47 for (
const auto &M : Matchers) {
56 ::testing::MatchResultListener *L)
const override {
57 std::vector<int> Matches(Matchers.size());
59 for (
size_t J = 0; I < Matchers.size() && J < V.size(); ++J)
60 if (Matchers[I].Matches(V[J]))
62 if (I == Matchers.size())
64 if (L->IsInterested()) {
66 for (
size_t K = 0; K < I; ++K) {
68 Matchers[K].DescribeTo(L->stream());
69 *L <<
" ==> " << ::testing::PrintToString(V[Matches[K]]);
72 Matchers[I].DescribeTo(L->stream());
73 *L <<
" ==> no subsequent match";
84 std::tuple<M...> Matchers;
88 : Matchers(std::make_tuple(std::forward<M>(Args)...)) {}
90 template <
typename T>
operator Matcher<const std::vector<T> &>()
const {
92 TypedMatchers<T>(std::index_sequence_for<M...>{})));
96 template <
typename T,
size_t... I>
97 std::vector<Matcher<T>> TypedMatchers(std::index_sequence<I...>)
const {
98 return {std::get<I>(Matchers)...};
105 template <
typename... Args>
113 #error "Refusing to redefine EXPECT_ERROR" 118 #define EXPECT_ERROR(expectedValue) \ 120 auto &&ComputedValue = (expectedValue); \ 121 if (ComputedValue) { \ 122 ADD_FAILURE() << "expected an error from " << #expectedValue \ 124 << ::testing::PrintToString(*ComputedValue); \ 127 llvm::consumeError(ComputedValue.takeError()); \ 143 template <
typename Optional>
operator Matcher<Optional>()
const {
144 return MakeMatcher(
new Impl<Optional>(matcher_));
149 template <
typename Optional>
150 class Impl :
public ::testing::MatcherInterface<Optional> {
152 using Value =
typename std::remove_const<
153 typename std::remove_reference<Optional>::type>::type::value_type;
155 explicit Impl(
const InnerMatcher &matcher)
156 : matcher_(::testing::MatcherCast<const Value &>(matcher)) {}
158 virtual void DescribeTo(::std::ostream *os)
const {
159 *os <<
"has a value that ";
160 matcher_.DescribeTo(os);
163 virtual void DescribeNegationTo(::std::ostream *os)
const {
164 *os <<
"does not have a value that ";
165 matcher_.DescribeTo(os);
170 ::testing::MatchResultListener *listener)
const {
171 if (!optional.hasValue())
174 *listener <<
"which has a value ";
175 return MatchPrintAndExplain(*optional, matcher_, listener);
179 const Matcher<const Value &> matcher_;
181 GTEST_DISALLOW_ASSIGN_(Impl);
184 const InnerMatcher matcher_;
191 template <
typename InnerMatcher>
void DescribeTo(std::ostream *OS) const override
OptionalMatcher< InnerMatcher > HasValue(const InnerMatcher &inner_matcher)
bool MatchAndExplain(const std::vector< T > &V, ::testing::MatchResultListener *L) const override
PolySubsequenceMatcher< Args... > HasSubsequence(Args &&... M)
SubsequenceMatcher(std::vector< Matcher< T >> M)
OptionalMatcher(const InnerMatcher &matcher)
PolySubsequenceMatcher(M &&... Args)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//