diff options
Diffstat (limited to 'clang/unittests/Tooling/RefactoringTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/RefactoringTest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 3e0d7280b1d..cea6c417c63 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -151,6 +151,30 @@ TEST_F(ReplacementTest, ApplyAllFailsIfOneApplyFails) { EXPECT_EQ("z", Context.getRewrittenText(IDz)); } +TEST(ShiftedCodePositionTest, FindsNewCodePosition) { + Replacements Replaces; + Replaces.insert(Replacement("", 0, 1, "")); + Replaces.insert(Replacement("", 4, 3, " ")); + // Assume ' int i;' is turned into 'int i;' and cursor is located at '|'. + EXPECT_EQ(0u, shiftedCodePosition(Replaces, 0)); // |int i; + EXPECT_EQ(0u, shiftedCodePosition(Replaces, 1)); // |nt i; + 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(4u, shiftedCodePosition(Replaces, 7)); // int |; + EXPECT_EQ(5u, shiftedCodePosition(Replaces, 8)); // int i| +} + +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" +} + class FlushRewrittenFilesTest : public ::testing::Test { public: FlushRewrittenFilesTest() { |