summaryrefslogtreecommitdiff
path: root/unittests/Tooling/RefactoringTest.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-11-07 06:08:23 +0000
committerEric Liu <ioeric@google.com>2016-11-07 06:08:23 +0000
commitd06c3a1ca07b0b1b2c674314ca3dec3fd93d9abf (patch)
treec2330efad8bb32ca0f5046911feda5d576b0a921 /unittests/Tooling/RefactoringTest.cpp
parent320da71d26ff59f846bfbf998eb3373fccfd760b (diff)
downloadclang-d06c3a1ca07b0b1b2c674314ca3dec3fd93d9abf.tar.gz
Deduplicate replacements by FileEntry instead of file names.
Summary: The current version does not deduplicate equivalent file paths correctly. For example, a relative path and an absolute path are considered inequivalent. Comparing FileEnry addresses these issues. Reviewers: djasper Subscribers: alexshap, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D26288 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286096 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/RefactoringTest.cpp')
-rw-r--r--unittests/Tooling/RefactoringTest.cpp63
1 files changed, 44 insertions, 19 deletions
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp
index 81f0f1dc5b..31b14eac97 100644
--- a/unittests/Tooling/RefactoringTest.cpp
+++ b/unittests/Tooling/RefactoringTest.cpp
@@ -19,6 +19,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
@@ -972,40 +973,64 @@ TEST_F(MergeReplacementsTest, OverlappingRanges) {
toReplacements({{"", 0, 3, "cc"}, {"", 3, 3, "dd"}}));
}
-TEST(DeduplicateByFileTest, LeaveLeadingDotDot) {
+TEST(DeduplicateByFileTest, PathsWithDots) {
std::map<std::string, Replacements> FileToReplaces;
+ llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
+ new vfs::InMemoryFileSystem());
+ FileManager *FileMgr = new FileManager(FileSystemOptions(), VFS);
#if !defined(LLVM_ON_WIN32)
- FileToReplaces["../../a/b/.././c.h"] = Replacements();
- FileToReplaces["../../a/c.h"] = Replacements();
+ StringRef Path1 = "a/b/.././c.h";
+ StringRef Path2 = "a/c.h";
#else
- FileToReplaces["..\\..\\a\\b\\..\\.\\c.h"] = Replacements();
- FileToReplaces["..\\..\\a\\c.h"] = Replacements();
+ StringRef Path1 = "a\\b\\..\\.\\c.h";
+ StringRef Path2 = "a\\c.h";
#endif
- FileToReplaces = groupReplacementsByFile(FileToReplaces);
+ EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer("")));
+ EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer("")));
+ FileToReplaces[Path1] = Replacements();
+ FileToReplaces[Path2] = Replacements();
+ FileToReplaces = groupReplacementsByFile(*FileMgr, FileToReplaces);
EXPECT_EQ(1u, FileToReplaces.size());
-#if !defined(LLVM_ON_WIN32)
- EXPECT_EQ("../../a/c.h", FileToReplaces.begin()->first);
-#else
- EXPECT_EQ("..\\..\\a\\c.h", FileToReplaces.begin()->first);
-#endif
+ EXPECT_EQ(Path1, FileToReplaces.begin()->first);
}
-TEST(DeduplicateByFileTest, RemoveDotSlash) {
+TEST(DeduplicateByFileTest, PathWithDotSlash) {
std::map<std::string, Replacements> FileToReplaces;
+ llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
+ new vfs::InMemoryFileSystem());
+ FileManager *FileMgr = new FileManager(FileSystemOptions(), VFS);
#if !defined(LLVM_ON_WIN32)
- FileToReplaces["./a/b/.././c.h"] = Replacements();
- FileToReplaces["a/c.h"] = Replacements();
+ StringRef Path1 = "./a/b/c.h";
+ StringRef Path2 = "a/b/c.h";
#else
- FileToReplaces[".\\a\\b\\..\\.\\c.h"] = Replacements();
- FileToReplaces["a\\c.h"] = Replacements();
+ StringRef Path1 = ".\\a\\b\\c.h";
+ StringRef Path2 = "a\\b\\c.h";
#endif
- FileToReplaces = groupReplacementsByFile(FileToReplaces);
+ EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer("")));
+ EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer("")));
+ FileToReplaces[Path1] = Replacements();
+ FileToReplaces[Path2] = Replacements();
+ FileToReplaces = groupReplacementsByFile(*FileMgr, FileToReplaces);
EXPECT_EQ(1u, FileToReplaces.size());
+ EXPECT_EQ(Path1, FileToReplaces.begin()->first);
+}
+
+TEST(DeduplicateByFileTest, NonExistingFilePath) {
+ std::map<std::string, Replacements> FileToReplaces;
+ llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
+ new vfs::InMemoryFileSystem());
+ FileManager *FileMgr = new FileManager(FileSystemOptions(), VFS);
#if !defined(LLVM_ON_WIN32)
- EXPECT_EQ("a/c.h", FileToReplaces.begin()->first);
+ StringRef Path1 = "./a/b/c.h";
+ StringRef Path2 = "a/b/c.h";
#else
- EXPECT_EQ("a\\c.h", FileToReplaces.begin()->first);
+ StringRef Path1 = ".\\a\\b\\c.h";
+ StringRef Path2 = "a\\b\\c.h";
#endif
+ FileToReplaces[Path1] = Replacements();
+ FileToReplaces[Path2] = Replacements();
+ FileToReplaces = groupReplacementsByFile(*FileMgr, FileToReplaces);
+ EXPECT_TRUE(FileToReplaces.empty());
}
} // end namespace tooling