diff options
author | Daniel Jasper <djasper@google.com> | 2015-11-23 08:36:35 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-11-23 08:36:35 +0000 |
commit | dd5d054c2c0b9f9b997dd98796d459c00a7285d1 (patch) | |
tree | b60ccc612c5cdfebe17d88de0338eeaa1327ea92 /unittests | |
parent | c7652b708852cfb7091791085b6836115ea8c69b (diff) | |
download | clang-dd5d054c2c0b9f9b997dd98796d459c00a7285d1.tar.gz |
clang-format: Make moving of the Cursor work properly when sorting #includes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/SortIncludesTest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/unittests/Format/SortIncludesTest.cpp b/unittests/Format/SortIncludesTest.cpp index a9f90e3f7b..70c7960df0 100644 --- a/unittests/Format/SortIncludesTest.cpp +++ b/unittests/Format/SortIncludesTest.cpp @@ -28,7 +28,14 @@ protected: reformat(Style, Sorted, Ranges, FileName)); } + unsigned newCursor(llvm::StringRef Code, unsigned Cursor) { + std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size())); + sortIncludes(Style, Code, Ranges, "input.cpp", &Cursor); + return Cursor; + } + FormatStyle Style = getLLVMStyle(); + }; TEST_F(SortIncludesTest, BasicSorting) { @@ -178,6 +185,19 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { "some_header.h")); } +TEST_F(SortIncludesTest, CalculatesCorrectCursorPosition) { + std::string Code = "#include <ccc>\n" // Start of line: 0 + "#include <bbbbbb>\n" // Start of line: 15 + "#include <a>\n"; // Start of line: 33 + EXPECT_EQ(31u, newCursor(Code, 0)); + EXPECT_EQ(13u, newCursor(Code, 15)); + EXPECT_EQ(0u, newCursor(Code, 33)); + + EXPECT_EQ(41u, newCursor(Code, 10)); + EXPECT_EQ(23u, newCursor(Code, 25)); + EXPECT_EQ(10u, newCursor(Code, 43)); +} + } // end namespace } // end namespace format } // end namespace clang |