[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
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ddaa5ca..c76475c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10665,16 +10665,17 @@
CHECK_PARSE("ForEachMacros: [BOOST_FOREACH, Q_FOREACH]", ForEachMacros,
BoostAndQForeach);
- Style.IncludeCategories.clear();
- std::vector<FormatStyle::IncludeCategory> ExpectedCategories = {{"abc/.*", 2},
- {".*", 1}};
+ Style.IncludeStyle.IncludeCategories.clear();
+ std::vector<tooling::IncludeStyle::IncludeCategory> ExpectedCategories = {
+ {"abc/.*", 2}, {".*", 1}};
CHECK_PARSE("IncludeCategories:\n"
" - Regex: abc/.*\n"
" Priority: 2\n"
" - Regex: .*\n"
" Priority: 1",
- IncludeCategories, ExpectedCategories);
- CHECK_PARSE("IncludeIsMainRegex: 'abc$'", IncludeIsMainRegex, "abc$");
+ IncludeStyle.IncludeCategories, ExpectedCategories);
+ CHECK_PARSE("IncludeIsMainRegex: 'abc$'", IncludeStyle.IncludeIsMainRegex,
+ "abc$");
Style.RawStringFormats.clear();
std::vector<FormatStyle::RawStringFormat> ExpectedRawStringFormats = {
diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp
index 09fc070..dde8800 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -26,12 +26,12 @@
std::string sort(StringRef Code, std::vector<tooling::Range> 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<bool>(Sorted));
auto Result = applyAllReplacements(
- *Sorted, reformat(Style, *Sorted, Ranges, FileName));
+ *Sorted, reformat(FmtStyle, *Sorted, Ranges, FileName));
EXPECT_TRUE(static_cast<bool>(Result));
return *Result;
}
@@ -41,12 +41,12 @@
}
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 @@
"#include <d>\n"
"#include <e>\n"
"#include <f>\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 @@
"\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, 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, 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 @@
"// 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 @@
"// 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 @@
"#include \"c.h\"\n"
"#include \"a.h\"\n"));
- Style = getGoogleStyle(FormatStyle::LK_Cpp);
+ FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp);
EXPECT_EQ("#include <b.h>\n"
"#include <d.h>\n"
"#include \"a.h\"\n"
@@ -245,7 +245,7 @@
}
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, 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, 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, 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 @@
"#include <b>\n"
"#include <c>\n"));
- Style.IncludeBlocks = FormatStyle::IBS_Merge;
+ Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
"#include <c>\n",
@@ -479,7 +479,7 @@
"#include <b>\n"
"#include <c>\n"));
- Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+ Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
"#include <c>\n",
@@ -503,7 +503,7 @@
"#include <c>\n"
"#include <b>\n"));
- Style.IncludeBlocks = FormatStyle::IBS_Merge;
+ Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
"#include <c>\n",
@@ -515,7 +515,7 @@
"#include <c>\n"
"#include <b>\n"));
- Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+ Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
EXPECT_EQ("#include <a>\n"
"#include <b>\n"
"#include <c>\n",
@@ -573,7 +573,7 @@
"\n"
" int x ;";
std::vector<tooling::Range> 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());