13 #include "clang/Tooling/Core/Replacement.h" 14 #include "gmock/gmock.h" 15 #include "gtest/gtest.h" 21 MATCHER_P2(RenameRange, Code,
Range,
"") {
25 TEST(RenameTest, SingleFile) {
78 for (
const Test &T : Tests) {
79 Annotations Code(T.Before);
81 auto AST = TU.build();
84 ASSERT_TRUE(
bool(RenameResult)) << RenameResult.takeError();
86 tooling::applyAllReplacements(Code.code(), *RenameResult);
87 ASSERT_TRUE(
bool(ApplyResult)) << ApplyResult.takeError();
89 EXPECT_EQ(T.After, *ApplyResult) << T.Before;
93 TEST(RenameTest, Renameable) {
96 const char* ErrorMessage;
99 const bool HeaderFile =
true;
101 {R
"cpp(// allow -- function-local 102 void f(int [[Lo^cal]]) { 106 nullptr, HeaderFile},
108 {R
"cpp(// allow -- symbol is indexable and has no refs in index. 109 void [[On^lyInThisFile]](); 111 nullptr, HeaderFile},
113 {R
"cpp(// disallow -- symbol is indexable and has other refs in index. 118 "used outside main file", HeaderFile},
120 {R
"cpp(// disallow -- symbol is not indexable. 122 class Unin^dexable {}; 125 "not eligible for indexing", HeaderFile},
127 {R
"cpp(// disallow -- namespace symbol isn't supported 130 "not a supported kind", HeaderFile},
137 "not a supported kind", HeaderFile},
139 {R
"cpp(// foo is declared outside the file. 141 )cpp", "used outside main file", !HeaderFile},
143 const char *CommonHeader = R
"cpp( 148 OtherFile.HeaderCode = CommonHeader;
149 OtherFile.Filename =
"other.cc";
151 auto OtherFileIndex = OtherFile.index();
153 for (
const auto& Case : Cases) {
154 Annotations T(Case.Code);
157 if (Case.IsHeaderFile) {
159 TU.Filename =
"test.h";
161 TU.ExtraArgs.push_back(
"-xobjective-c++-header");
163 auto AST = TU.build();
166 "dummyNewName", OtherFileIndex.get());
167 bool WantRename =
true;
168 if (T.ranges().empty())
171 assert(Case.ErrorMessage &&
"Error message must be set!");
172 EXPECT_FALSE(
Results) <<
"expected renameWithinFile returned an error: " 175 EXPECT_THAT(ActualMessage, testing::HasSubstr(Case.ErrorMessage));
177 EXPECT_TRUE(
bool(
Results)) <<
"renameWithinFile returned an error: " 179 std::vector<testing::Matcher<tooling::Replacement>>
Expected;
180 for (
const auto &R : T.ranges())
181 Expected.push_back(RenameRange(TU.Code, R));
182 EXPECT_THAT(*
Results, UnorderedElementsAreArray(Expected));
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
std::vector< CodeCompletionResult > Results
llvm::Expected< tooling::Replacements > renameWithinFile(ParsedAST &AST, llvm::StringRef File, Position Pos, llvm::StringRef NewName, const SymbolIndex *Index)
Renames all occurrences of the symbol at Pos to NewName.
TEST(BackgroundQueueTest, Priority)
std::string testPath(PathRef File)
Range range
The range of the text document to be manipulated.
static TestTU withCode(llvm::StringRef Code)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
TextEdit replacementToEdit(llvm::StringRef Code, const tooling::Replacement &R)
CharSourceRange Range
SourceRange for the file name.
std::vector< const char * > Expected