diff options
author | Daniel Jasper <djasper@google.com> | 2013-05-21 12:21:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-05-21 12:21:39 +0000 |
commit | 6bd3b93200c6ae141d0f7444ffb4cacd52b183ed (patch) | |
tree | 85ddc2eac780535408f50371bbde4f8a6a674729 /unittests/Tooling/RefactoringTest.cpp | |
parent | 800ff45b49e306a5706f249d3289281dc224dcb3 (diff) | |
download | clang-6bd3b93200c6ae141d0f7444ffb4cacd52b183ed.tar.gz clang-6bd3b93200c6ae141d0f7444ffb4cacd52b183ed.tar.bz2 clang-6bd3b93200c6ae141d0f7444ffb4cacd52b183ed.tar.xz |
Let clang-format move the cursor appropriately.
With this patch, clang-format will try to keep the cursor at the
original code position in editor integrations (implemented for emacs and
vim). This means, after formatting, clang-format will try to keep the
cursor on the same character of the same token.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182373 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/RefactoringTest.cpp')
-rw-r--r-- | unittests/Tooling/RefactoringTest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index 3e0d7280b1..cea6c417c6 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/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() { |