Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/unittests/Tooling/RefactoringTest.cpp
Show First 20 Lines • Show All 1,025 Lines • ▼ Show 20 Lines | mergeAndTestRewrite( | ||||
toReplacements({{"", 0, 1, ""}, {"", 2, 0, "bb"}, {"", 3, 0, "b"}}), | toReplacements({{"", 0, 1, ""}, {"", 2, 0, "bb"}, {"", 3, 0, "b"}}), | ||||
toReplacements({{"", 0, 2, "cc"}, {"", 2, 3, "dd"}})); | toReplacements({{"", 0, 2, "cc"}, {"", 2, 3, "dd"}})); | ||||
mergeAndTestRewrite( | mergeAndTestRewrite( | ||||
"aa", "babbab", "ccdd", | "aa", "babbab", "ccdd", | ||||
toReplacements({{"", 0, 0, "b"}, {"", 1, 0, "bb"}, {"", 2, 0, "b"}}), | toReplacements({{"", 0, 0, "b"}, {"", 1, 0, "bb"}, {"", 2, 0, "b"}}), | ||||
toReplacements({{"", 0, 3, "cc"}, {"", 3, 3, "dd"}})); | toReplacements({{"", 0, 3, "cc"}, {"", 3, 3, "dd"}})); | ||||
} | } | ||||
static constexpr bool usesWindowsPaths() { | |||||
return is_style_windows(llvm::sys::path::Style::native); | |||||
} | |||||
TEST(DeduplicateByFileTest, PathsWithDots) { | TEST(DeduplicateByFileTest, PathsWithDots) { | ||||
std::map<std::string, Replacements> FileToReplaces; | std::map<std::string, Replacements> FileToReplaces; | ||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | ||||
new llvm::vfs::InMemoryFileSystem()); | new llvm::vfs::InMemoryFileSystem()); | ||||
FileManager FileMgr(FileSystemOptions(), VFS); | FileManager FileMgr(FileSystemOptions(), VFS); | ||||
#if !defined(_WIN32) | StringRef Path1 = usesWindowsPaths() ? "a\\b\\..\\.\\c.h" : "a/b/.././c.h"; | ||||
StringRef Path1 = "a/b/.././c.h"; | StringRef Path2 = usesWindowsPaths() ? "a\\c.h" : "a/c.h"; | ||||
StringRef Path2 = "a/c.h"; | |||||
#else | |||||
StringRef Path1 = "a\\b\\..\\.\\c.h"; | |||||
StringRef Path2 = "a\\c.h"; | |||||
#endif | |||||
EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); | EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); | ||||
EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); | EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); | ||||
FileToReplaces[std::string(Path1)] = Replacements(); | FileToReplaces[std::string(Path1)] = Replacements(); | ||||
FileToReplaces[std::string(Path2)] = Replacements(); | FileToReplaces[std::string(Path2)] = Replacements(); | ||||
FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | ||||
EXPECT_EQ(1u, FileToReplaces.size()); | EXPECT_EQ(1u, FileToReplaces.size()); | ||||
EXPECT_EQ(Path1, FileToReplaces.begin()->first); | EXPECT_EQ(Path1, FileToReplaces.begin()->first); | ||||
} | } | ||||
TEST(DeduplicateByFileTest, PathWithDotSlash) { | TEST(DeduplicateByFileTest, PathWithDotSlash) { | ||||
std::map<std::string, Replacements> FileToReplaces; | std::map<std::string, Replacements> FileToReplaces; | ||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | ||||
new llvm::vfs::InMemoryFileSystem()); | new llvm::vfs::InMemoryFileSystem()); | ||||
FileManager FileMgr(FileSystemOptions(), VFS); | FileManager FileMgr(FileSystemOptions(), VFS); | ||||
#if !defined(_WIN32) | StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; | ||||
StringRef Path1 = "./a/b/c.h"; | StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; | ||||
StringRef Path2 = "a/b/c.h"; | |||||
#else | |||||
StringRef Path1 = ".\\a\\b\\c.h"; | |||||
StringRef Path2 = "a\\b\\c.h"; | |||||
#endif | |||||
EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); | EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); | ||||
EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); | EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); | ||||
FileToReplaces[std::string(Path1)] = Replacements(); | FileToReplaces[std::string(Path1)] = Replacements(); | ||||
FileToReplaces[std::string(Path2)] = Replacements(); | FileToReplaces[std::string(Path2)] = Replacements(); | ||||
FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | ||||
EXPECT_EQ(1u, FileToReplaces.size()); | EXPECT_EQ(1u, FileToReplaces.size()); | ||||
EXPECT_EQ(Path1, FileToReplaces.begin()->first); | EXPECT_EQ(Path1, FileToReplaces.begin()->first); | ||||
} | } | ||||
TEST(DeduplicateByFileTest, NonExistingFilePath) { | TEST(DeduplicateByFileTest, NonExistingFilePath) { | ||||
std::map<std::string, Replacements> FileToReplaces; | std::map<std::string, Replacements> FileToReplaces; | ||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS( | ||||
new llvm::vfs::InMemoryFileSystem()); | new llvm::vfs::InMemoryFileSystem()); | ||||
FileManager FileMgr(FileSystemOptions(), VFS); | FileManager FileMgr(FileSystemOptions(), VFS); | ||||
#if !defined(_WIN32) | StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; | ||||
StringRef Path1 = "./a/b/c.h"; | StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; | ||||
StringRef Path2 = "a/b/c.h"; | |||||
#else | |||||
StringRef Path1 = ".\\a\\b\\c.h"; | |||||
StringRef Path2 = "a\\b\\c.h"; | |||||
#endif | |||||
FileToReplaces[std::string(Path1)] = Replacements(); | FileToReplaces[std::string(Path1)] = Replacements(); | ||||
FileToReplaces[std::string(Path2)] = Replacements(); | FileToReplaces[std::string(Path2)] = Replacements(); | ||||
FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); | ||||
EXPECT_TRUE(FileToReplaces.empty()); | EXPECT_TRUE(FileToReplaces.empty()); | ||||
} | } | ||||
class AtomicChangeTest : public ::testing::Test { | class AtomicChangeTest : public ::testing::Test { | ||||
protected: | protected: | ||||
▲ Show 20 Lines • Show All 639 Lines • Show Last 20 Lines |