9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
15#include "llvm/ADT/StringMap.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Testing/Annotations/Annotations.h"
18#include "gmock/gmock.h"
19#include "gtest/gtest.h"
61 TweakTest(
const char *TweakID) : TweakID(TweakID) {}
77 std::unique_ptr<const SymbolIndex>
Index =
nullptr;
92 std::string
apply(llvm::StringRef MarkedCode,
93 llvm::StringMap<std::string> *EditedFiles =
nullptr)
const;
100 static std::string
decorate(llvm::StringRef,
unsigned);
101 static std::string
decorate(llvm::StringRef, llvm::Annotations::Range);
105 return arg.first() == FileName && arg.second == Contents;
108#define TWEAK_TEST(TweakID) \
109 class TweakID##Test : public ::clang::clangd::TweakTest { \
111 TweakID##Test() : TweakTest(#TweakID) {} \
114#define EXPECT_AVAILABLE_(MarkedCode, Available) \
116 llvm::Annotations A{llvm::StringRef(MarkedCode)}; \
117 auto AST = build(A.code()); \
118 assert(!A.points().empty() || !A.ranges().empty()); \
119 for (const auto &P : A.points()) \
120 EXPECT_EQ(Available, isAvailable(AST, {P, P})) << decorate(A.code(), P); \
121 for (const auto &R : A.ranges()) \
122 EXPECT_EQ(Available, isAvailable(AST, R)) << decorate(A.code(), R); \
124#define EXPECT_AVAILABLE(MarkedCode) EXPECT_AVAILABLE_(MarkedCode, true)
125#define EXPECT_UNAVAILABLE(MarkedCode) EXPECT_AVAILABLE_(MarkedCode, false)
142template <
class EditedFilesMatcher>
143::testing::Matcher<TweakResult>
editedFiles(EditedFilesMatcher M) {
149inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &Stream,
151 Stream <<
"{ status: " << Result.
Status <<
", editedFiles: [";
153 Stream << F.first() <<
":\n";
156 return Stream <<
"] }";
182 llvm::Annotations::Range InvocationRange);
188#define TWEAK_WORKSPACE_TEST(TweakID) \
189 class TweakID##WorkspaceTest : public ::clang::clangd::TweakWorkspaceTest { \
191 TweakID##WorkspaceTest() : TweakWorkspaceTest(#TweakID) {} \
Stores and provides access to parsed AST.
std::vector< std::string > ExtraArgs
TweakTest(const char *TweakID)
llvm::StringMap< std::string > ExtraFiles
static std::string decorate(llvm::StringRef, unsigned)
WrappedAST build(llvm::StringRef) const
std::pair< ParsedAST, unsigned > WrappedAST
std::string apply(llvm::StringRef MarkedCode, llvm::StringMap< std::string > *EditedFiles=nullptr) const
bool isAvailable(WrappedAST &, llvm::Annotations::Range) const
std::unique_ptr< const SymbolIndex > Index
TweakWorkspaceTest(const char *TweakID)
TweakResult apply(StringRef InvocationFile, llvm::Annotations::Range InvocationRange)
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
MATCHER_P2(hasFlag, Flag, Path, "")
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
::testing::Matcher< TweakResult > editedFiles(EditedFilesMatcher M)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::StringMap< std::string > EditedFiles