diff options
Diffstat (limited to 'clang/unittests/Format')
-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) { |