diff options
author | Daniel Jasper <djasper@google.com> | 2016-08-30 21:33:41 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-08-30 21:33:41 +0000 |
commit | d6a007803925164fdb40fd4efd647e9d32b2d67b (patch) | |
tree | 68134461bcf6f2c1145b1dabd67de2287da87362 /clang/unittests/Format/SortIncludesTest.cpp | |
parent | befba52f89a70f8cf1b11f57063c7a52fe886188 (diff) | |
download | bcm5719-llvm-d6a007803925164fdb40fd4efd647e9d32b2d67b.tar.gz bcm5719-llvm-d6a007803925164fdb40fd4efd647e9d32b2d67b.zip |
clang-format: Correctly calculate affected ranges when sorting #includes.
affectedRanges takes a start and an end offset, not offset and length.
llvm-svn: 280165
Diffstat (limited to 'clang/unittests/Format/SortIncludesTest.cpp')
-rw-r--r-- | clang/unittests/Format/SortIncludesTest.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index b6ee2ddf669..c3c56a81304 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -24,8 +24,8 @@ protected: return std::vector<tooling::Range>(1, tooling::Range(0, Code.size())); } - std::string sort(StringRef Code, StringRef FileName = "input.cpp") { - auto Ranges = GetCodeRange(Code); + std::string sort(StringRef Code, std::vector<tooling::Range> Ranges, + StringRef FileName = "input.cc") { auto Replaces = sortIncludes(Style, Code, Ranges, FileName); Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges); auto Sorted = applyAllReplacements(Code, Replaces); @@ -36,6 +36,10 @@ protected: return *Result; } + std::string sort(StringRef Code, StringRef FileName = "input.cpp") { + return sort(Code, GetCodeRange(Code), FileName); + } + unsigned newCursor(llvm::StringRef Code, unsigned Cursor) { sortIncludes(Style, Code, GetCodeRange(Code), "input.cpp", &Cursor); return Cursor; @@ -52,6 +56,14 @@ TEST_F(SortIncludesTest, BasicSorting) { sort("#include \"a.h\"\n" "#include \"c.h\"\n" "#include \"b.h\"\n")); + + EXPECT_EQ("// comment\n" + "#include <a>\n" + "#include <b>\n", + sort("// comment\n" + "#include <b>\n" + "#include <a>\n", + {tooling::Range(25, 1)})); } TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) { |