diff options
| author | Daniel Jasper <djasper@google.com> | 2015-11-23 08:33:48 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2015-11-23 08:33:48 +0000 |
| commit | c7652b708852cfb7091791085b6836115ea8c69b (patch) | |
| tree | 54401692374dd1b519aa2df67bf4567790617c8e /unittests/Tooling/RefactoringTest.cpp | |
| parent | 55de488d205b13b9aba4757d28474022be14ab25 (diff) | |
| download | clang-c7652b708852cfb7091791085b6836115ea8c69b.tar.gz | |
Fix calculation of shifted cursor/code positions. Specifically support
the case where a specific range is replaced by new text. Previously,
the calculation would shift any position from within a replaced region
to the first character after the region. This is undersirable, e.g. for
clang-format's include sorting.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253859 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/RefactoringTest.cpp')
| -rw-r--r-- | unittests/Tooling/RefactoringTest.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index d9a87a5690..ff11aeae11 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -176,8 +176,8 @@ TEST(ShiftedCodePositionTest, FindsNewCodePosition) { EXPECT_EQ(1u, shiftedCodePosition(Replaces, 2)); // i|t i; EXPECT_EQ(2u, shiftedCodePosition(Replaces, 3)); // in| i; EXPECT_EQ(3u, shiftedCodePosition(Replaces, 4)); // int| i; - EXPECT_EQ(4u, shiftedCodePosition(Replaces, 5)); // int | i; - EXPECT_EQ(4u, shiftedCodePosition(Replaces, 6)); // int |i; + EXPECT_EQ(3u, shiftedCodePosition(Replaces, 5)); // int | i; + EXPECT_EQ(3u, shiftedCodePosition(Replaces, 6)); // int |i; EXPECT_EQ(4u, shiftedCodePosition(Replaces, 7)); // int |; EXPECT_EQ(5u, shiftedCodePosition(Replaces, 8)); // int i| } @@ -195,8 +195,8 @@ TEST(ShiftedCodePositionTest, VectorFindsNewCodePositionWithInserts) { EXPECT_EQ(1u, shiftedCodePosition(Replaces, 2)); // i|t i; EXPECT_EQ(2u, shiftedCodePosition(Replaces, 3)); // in| i; EXPECT_EQ(3u, shiftedCodePosition(Replaces, 4)); // int| i; - EXPECT_EQ(4u, shiftedCodePosition(Replaces, 5)); // int | i; - EXPECT_EQ(4u, shiftedCodePosition(Replaces, 6)); // int |i; + EXPECT_EQ(3u, shiftedCodePosition(Replaces, 5)); // int | i; + EXPECT_EQ(3u, shiftedCodePosition(Replaces, 6)); // int |i; EXPECT_EQ(4u, shiftedCodePosition(Replaces, 7)); // int |; EXPECT_EQ(5u, shiftedCodePosition(Replaces, 8)); // int i| } @@ -205,8 +205,17 @@ TEST(ShiftedCodePositionTest, FindsNewCodePositionWithInserts) { Replacements Replaces; Replaces.insert(Replacement("", 4, 0, "\"\n\"")); // Assume '"12345678"' is turned into '"1234"\n"5678"'. - EXPECT_EQ(4u, shiftedCodePosition(Replaces, 4)); // "123|5678" - EXPECT_EQ(8u, shiftedCodePosition(Replaces, 5)); // "1234|678" + EXPECT_EQ(3u, shiftedCodePosition(Replaces, 3)); // "123|5678" + EXPECT_EQ(7u, shiftedCodePosition(Replaces, 4)); // "1234|678" + EXPECT_EQ(8u, shiftedCodePosition(Replaces, 5)); // "12345|78" +} + +TEST(ShiftedCodePositionTest, FindsNewCodePositionInReplacedText) { + Replacements Replaces; + // Replace the first four characters with "abcd". + Replaces.insert(Replacement("", 0, 4, "abcd")); + for (unsigned i = 0; i < 3; ++i) + EXPECT_EQ(i, shiftedCodePosition(Replaces, i)); } class FlushRewrittenFilesTest : public ::testing::Test { |
