From d6a007803925164fdb40fd4efd647e9d32b2d67b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 30 Aug 2016 21:33:41 +0000 Subject: clang-format: Correctly calculate affected ranges when sorting #includes. affectedRanges takes a start and an end offset, not offset and length. llvm-svn: 280165 --- clang/unittests/Format/SortIncludesTest.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'clang/unittests/Format/SortIncludesTest.cpp') 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(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 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 \n" + "#include \n", + sort("// comment\n" + "#include \n" + "#include \n", + {tooling::Range(25, 1)})); } TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) { -- cgit v1.2.3