aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/RefactoringTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2016-03-01 12:37:30 +0000
committerManuel Klimek <klimek@google.com>2016-03-01 12:37:30 +0000
commitb12e5a5ccd8e5ca71a3722a4b5103a794ca5515f (patch)
tree2be713f424b906e73a5320edca75855f6b37226e /clang/unittests/Tooling/RefactoringTest.cpp
parent109702ccb16f33a5b0305a1d1287413c9a88adca (diff)
downloadllvm-b12e5a5ccd8e5ca71a3722a4b5103a794ca5515f.zip
llvm-b12e5a5ccd8e5ca71a3722a4b5103a794ca5515f.tar.gz
llvm-b12e5a5ccd8e5ca71a3722a4b5103a794ca5515f.tar.bz2
Add functions to apply replacements and reformat them.
This is a commonly useful feature to have, and we have implemented it multiple times with different kinds of bugs. This implementation centralizes the idea in a set of functions that we can then use from the various tools. Reverts r262234, which is a revert of r262232, and puts the functions into FOrmat.h, as they are closely coupled to clang-format, and we otherwise introduce a cyclic dependency between libFormat and libTooling. Patch by Eric Liu. llvm-svn: 262323
Diffstat (limited to 'clang/unittests/Tooling/RefactoringTest.cpp')
-rw-r--r--clang/unittests/Tooling/RefactoringTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp
index ff11aea..73da5a8 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -418,6 +418,25 @@ TEST(Range, contains) {
EXPECT_FALSE(Range(0, 10).contains(Range(0, 11)));
}
+TEST(Range, CalculateRangesOfReplacements) {
+ // Before: aaaabbbbbbz
+ // After : bbbbbbzzzzzzoooooooooooooooo
+ Replacements Replaces;
+ Replaces.insert(Replacement("foo", 0, 4, ""));
+ Replaces.insert(Replacement("foo", 10, 1, "zzzzzz"));
+ Replaces.insert(Replacement("foo", 11, 0, "oooooooooooooooo"));
+
+ std::vector<Range> Ranges = calculateChangedRangesInFile(Replaces);
+
+ EXPECT_EQ(3ul, Ranges.size());
+ EXPECT_TRUE(Ranges[0].getOffset() == 0);
+ EXPECT_TRUE(Ranges[0].getLength() == 0);
+ EXPECT_TRUE(Ranges[1].getOffset() == 6);
+ EXPECT_TRUE(Ranges[1].getLength() == 6);
+ EXPECT_TRUE(Ranges[2].getOffset() == 12);
+ EXPECT_TRUE(Ranges[2].getLength() == 16);
+}
+
TEST(DeduplicateTest, removesDuplicates) {
std::vector<Replacement> Input;
Input.push_back(Replacement("fileA", 50, 0, " foo "));