From 9d92c027e89e877409ec0e65f700d3bbb14d139b Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 14 May 2018 19:51:33 +0000 Subject: [clang-format] Move #include related style to libToolingCore Summary: This will be shared by include insertion/deletion library. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgorny, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46758 llvm-svn: 332284 --- clang/unittests/Format/SortIncludesTest.cpp | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'clang/unittests/Format/SortIncludesTest.cpp') diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 09fc0703d42..dde88003784 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -26,12 +26,12 @@ protected: std::string sort(StringRef Code, std::vector Ranges, StringRef FileName = "input.cc") { - auto Replaces = sortIncludes(Style, Code, Ranges, FileName); + auto Replaces = sortIncludes(FmtStyle, Code, Ranges, FileName); Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges); auto Sorted = applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast(Sorted)); auto Result = applyAllReplacements( - *Sorted, reformat(Style, *Sorted, Ranges, FileName)); + *Sorted, reformat(FmtStyle, *Sorted, Ranges, FileName)); EXPECT_TRUE(static_cast(Result)); return *Result; } @@ -41,12 +41,12 @@ protected: } unsigned newCursor(llvm::StringRef Code, unsigned Cursor) { - sortIncludes(Style, Code, GetCodeRange(Code), "input.cpp", &Cursor); + sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.cpp", &Cursor); return Cursor; } - FormatStyle Style = getLLVMStyle(); - + FormatStyle FmtStyle = getLLVMStyle(); + tooling::IncludeStyle &Style = FmtStyle.IncludeStyle; }; TEST_F(SortIncludesTest, BasicSorting) { @@ -74,11 +74,11 @@ TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) { "#include \n" "#include \n" "#include \n"; - EXPECT_TRUE(sortIncludes(Style, Code, GetCodeRange(Code), "a.cc").empty()); + EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cc").empty()); } TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) { - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \"a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n", @@ -88,7 +88,7 @@ TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) { "\n" "#include \"b.h\"\n")); - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \"a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n", @@ -119,7 +119,7 @@ TEST_F(SortIncludesTest, SupportClangFormatOff) { } TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { - Style.SortIncludes = false; + FmtStyle.SortIncludes = false; EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" "#include \"b.h\"\n", @@ -182,7 +182,7 @@ TEST_F(SortIncludesTest, SortsLocallyInEachBlock) { } TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) { - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \"a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n", @@ -202,7 +202,7 @@ TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) { "// comment\n" "#include \"b.h\"\n")); - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" "// comment\n" @@ -212,7 +212,7 @@ TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) { "// comment\n" "#include \"b.h\"\n")); - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" "// comment\n" @@ -233,7 +233,7 @@ TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { "#include \"c.h\"\n" "#include \"a.h\"\n")); - Style = getGoogleStyle(FormatStyle::LK_Cpp); + FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp); EXPECT_EQ("#include \n" "#include \n" "#include \"a.h\"\n" @@ -245,7 +245,7 @@ TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { } TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) { - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" "\n" @@ -345,7 +345,7 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) { Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \"c.h\"\n" "#include \"a.h\"\n" @@ -359,7 +359,7 @@ TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) { TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) { Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \"a.h\"\n" "\n" @@ -417,7 +417,7 @@ TEST_F(SortIncludesTest, NegativePriorities) { TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) { Style.IncludeCategories = {{".*important_os_header.*", -1}, {".*", 1}}; - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \"important_os_header.h\"\n" "\n" @@ -467,7 +467,7 @@ TEST_F(SortIncludesTest, DeduplicateIncludes) { "#include \n" "#include \n")); - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \n" "#include \n" "#include \n", @@ -479,7 +479,7 @@ TEST_F(SortIncludesTest, DeduplicateIncludes) { "#include \n" "#include \n")); - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \n" "#include \n" "#include \n", @@ -503,7 +503,7 @@ TEST_F(SortIncludesTest, SortAndDeduplicateIncludes) { "#include \n" "#include \n")); - Style.IncludeBlocks = FormatStyle::IBS_Merge; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; EXPECT_EQ("#include \n" "#include \n" "#include \n", @@ -515,7 +515,7 @@ TEST_F(SortIncludesTest, SortAndDeduplicateIncludes) { "#include \n" "#include \n")); - Style.IncludeBlocks = FormatStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; EXPECT_EQ("#include \n" "#include \n" "#include \n", @@ -573,7 +573,7 @@ TEST_F(SortIncludesTest, ValidAffactedRangesAfterDeduplicatingIncludes) { "\n" " int x ;"; std::vector Ranges = {tooling::Range(0, 52)}; - auto Replaces = sortIncludes(Style, Code, Ranges, "input.cpp"); + auto Replaces = sortIncludes(FmtStyle, Code, Ranges, "input.cpp"); Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges); EXPECT_EQ(1u, Ranges.size()); EXPECT_EQ(0u, Ranges[0].getOffset()); -- cgit v1.2.3