[clang-tools-extra] r360118 - [clangd] Add test that r360116 accidentally fixed a duplicate-edits bug in rename. NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue May 7 00:45:41 PDT 2019
Author: sammccall
Date: Tue May 7 00:45:41 2019
New Revision: 360118
URL: http://llvm.org/viewvc/llvm-project?rev=360118&view=rev
Log:
[clangd] Add test that r360116 accidentally fixed a duplicate-edits bug in rename. NFC
Modified:
clang-tools-extra/trunk/clangd/refactor/Rename.cpp
clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp
Modified: clang-tools-extra/trunk/clangd/refactor/Rename.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/Rename.cpp?rev=360118&r1=360117&r2=360118&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/refactor/Rename.cpp (original)
+++ clang-tools-extra/trunk/clangd/refactor/Rename.cpp Tue May 7 00:45:41 2019
@@ -66,6 +66,8 @@ renameWithinFile(ParsedAST &AST, llvm::S
// Right now we only support renaming the main file, so we
// drop replacements not for the main file. In the future, we might
// also support rename with wider scope.
+ // Rename sometimes returns duplicate edits (which is a bug). A side-effect of
+ // adding them to a single Replacements object is these are deduplicated.
for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) {
for (const auto &Rep : Change.getReplacements()) {
if (Rep.getFilePath() == File)
Modified: clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp?rev=360118&r1=360117&r2=360118&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp Tue May 7 00:45:41 2019
@@ -19,27 +19,72 @@ namespace clangd {
namespace {
TEST(RenameTest, SingleFile) {
- Annotations Code(R"cpp(
- void foo() {
- fo^o();
- }
- )cpp");
- auto TU = TestTU::withCode(Code.code());
- TU.HeaderCode = "void foo();"; // outside main file, will not be touched.
+ struct Test {
+ const char* Before;
+ const char* After;
+ } Tests[] = {
+ // Rename function.
+ {
+ R"cpp(
+ void foo() {
+ fo^o();
+ }
+ )cpp",
+ R"cpp(
+ void abcde() {
+ abcde();
+ }
+ )cpp",
+ },
+ // Rename type.
+ {
+ R"cpp(
+ struct foo{};
+ foo test() {
+ f^oo x;
+ return x;
+ }
+ )cpp",
+ R"cpp(
+ struct abcde{};
+ abcde test() {
+ abcde x;
+ return x;
+ }
+ )cpp",
+ },
+ // Rename variable.
+ {
+ R"cpp(
+ void bar() {
+ if (auto ^foo = 5) {
+ foo = 3;
+ }
+ }
+ )cpp",
+ R"cpp(
+ void bar() {
+ if (auto abcde = 5) {
+ abcde = 3;
+ }
+ }
+ )cpp",
+ },
+ };
+ for (const Test &T : Tests) {
+ Annotations Code(T.Before);
+ auto TU = TestTU::withCode(Code.code());
+ TU.HeaderCode = "void foo();"; // outside main file, will not be touched.
+ auto AST = TU.build();
+ auto RenameResult =
+ renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+ ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
+ auto ApplyResult =
+ tooling::applyAllReplacements(Code.code(), *RenameResult);
+ ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
- auto AST = TU.build();
- auto RenameResult =
- renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
- ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
- auto ApplyResult = tooling::applyAllReplacements(Code.code(), *RenameResult);
- ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
-
- const char *Want = R"cpp(
- void abcde() {
- abcde();
- }
- )cpp";
- EXPECT_EQ(Want, *ApplyResult);
+ EXPECT_EQ(T.After, *ApplyResult) << T.Before;
+ }
}
} // namespace
More information about the cfe-commits
mailing list