#define LLVM_CLANG_FORMAT_FORMAT_H
#include "clang/Basic/LangOptions.h"
+#include "clang/Tooling/Core/IncludeStyle.h"
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/ArrayRef.h"
#include <system_error>
/// For example: BOOST_FOREACH.
std::vector<std::string> ForEachMacros;
- /// Styles for sorting multiple ``#include`` blocks.
- enum IncludeBlocksStyle {
- /// Sort each ``#include`` block separately.
- /// \code
- /// #include "b.h" into #include "b.h"
- ///
- /// #include <lib/main.h> #include "a.h"
- /// #include "a.h" #include <lib/main.h>
- /// \endcode
- IBS_Preserve,
- /// Merge multiple ``#include`` blocks together and sort as one.
- /// \code
- /// #include "b.h" into #include "a.h"
- /// #include "b.h"
- /// #include <lib/main.h> #include <lib/main.h>
- /// #include "a.h"
- /// \endcode
- IBS_Merge,
- /// Merge multiple ``#include`` blocks together and sort as one.
- /// Then split into groups based on category priority. See
- /// ``IncludeCategories``.
- /// \code
- /// #include "b.h" into #include "a.h"
- /// #include "b.h"
- /// #include <lib/main.h>
- /// #include "a.h" #include <lib/main.h>
- /// \endcode
- IBS_Regroup,
- };
-
- /// Dependent on the value, multiple ``#include`` blocks can be sorted
- /// as one and divided based on category.
- IncludeBlocksStyle IncludeBlocks;
-
- /// See documentation of ``IncludeCategories``.
- struct IncludeCategory {
- /// The regular expression that this category matches.
- std::string Regex;
- /// The priority to assign to this category.
- int Priority;
- bool operator==(const IncludeCategory &Other) const {
- return Regex == Other.Regex && Priority == Other.Priority;
- }
- };
-
- /// Regular expressions denoting the different ``#include`` categories
- /// used for ordering ``#includes``.
- ///
- /// These regular expressions are matched against the filename of an include
- /// (including the <> or "") in order. The value belonging to the first
- /// matching regular expression is assigned and ``#includes`` are sorted first
- /// according to increasing category number and then alphabetically within
- /// each category.
- ///
- /// If none of the regular expressions match, INT_MAX is assigned as
- /// category. The main header for a source file automatically gets category 0.
- /// so that it is generally kept at the beginning of the ``#includes``
- /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
- /// can also assign negative priorities if you have certain headers that
- /// always need to be first.
- ///
- /// To configure this in the .clang-format file, use:
- /// \code{.yaml}
- /// IncludeCategories:
- /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
- /// Priority: 2
- /// - Regex: '^(<|"(gtest|gmock|isl|json)/)'
- /// Priority: 3
- /// - Regex: '.*'
- /// Priority: 1
- /// \endcode
- std::vector<IncludeCategory> IncludeCategories;
-
- /// Specify a regular expression of suffixes that are allowed in the
- /// file-to-main-include mapping.
- ///
- /// When guessing whether a #include is the "main" include (to assign
- /// category 0, see above), use this regex of allowed suffixes to the header
- /// stem. A partial match is done, so that:
- /// - "" means "arbitrary suffix"
- /// - "$" means "no suffix"
- ///
- /// For example, if configured to "(_test)?$", then a header a.h would be seen
- /// as the "main" include in both a.cc and a_test.cc.
- std::string IncludeIsMainRegex;
+ tooling::IncludeStyle IncludeStyle;
/// Indent case labels one level from the switch statement.
///
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
- IncludeBlocks == R.IncludeBlocks &&
- IncludeCategories == R.IncludeCategories &&
+ IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
+ IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
IndentCaseLabels == R.IndentCaseLabels &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentWidth == R.IndentWidth && Language == R.Language &&
ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
- PenaltyBreakAssignment ==
- R.PenaltyBreakAssignment &&
+ PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
PenaltyBreakBeforeFirstCallParameter ==
R.PenaltyBreakBeforeFirstCallParameter &&
PenaltyBreakComment == R.PenaltyBreakComment &&
--- /dev/null
+//===--- IncludeStyle.h - Style of C++ #include directives -------*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H
+#define LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H
+
+#include "llvm/Support/YAMLTraits.h"
+#include <string>
+#include <vector>
+
+namespace clang {
+namespace tooling {
+
+/// Style for sorting and grouping C++ #include directives.
+struct IncludeStyle {
+ /// Styles for sorting multiple ``#include`` blocks.
+ enum IncludeBlocksStyle {
+ /// Sort each ``#include`` block separately.
+ /// \code
+ /// #include "b.h" into #include "b.h"
+ ///
+ /// #include <lib/main.h> #include "a.h"
+ /// #include "a.h" #include <lib/main.h>
+ /// \endcode
+ IBS_Preserve,
+ /// Merge multiple ``#include`` blocks together and sort as one.
+ /// \code
+ /// #include "b.h" into #include "a.h"
+ /// #include "b.h"
+ /// #include <lib/main.h> #include <lib/main.h>
+ /// #include "a.h"
+ /// \endcode
+ IBS_Merge,
+ /// Merge multiple ``#include`` blocks together and sort as one.
+ /// Then split into groups based on category priority. See
+ /// ``IncludeCategories``.
+ /// \code
+ /// #include "b.h" into #include "a.h"
+ /// #include "b.h"
+ /// #include <lib/main.h>
+ /// #include "a.h" #include <lib/main.h>
+ /// \endcode
+ IBS_Regroup,
+ };
+
+ /// Dependent on the value, multiple ``#include`` blocks can be sorted
+ /// as one and divided based on category.
+ IncludeBlocksStyle IncludeBlocks;
+
+ /// See documentation of ``IncludeCategories``.
+ struct IncludeCategory {
+ /// The regular expression that this category matches.
+ std::string Regex;
+ /// The priority to assign to this category.
+ int Priority;
+ bool operator==(const IncludeCategory &Other) const {
+ return Regex == Other.Regex && Priority == Other.Priority;
+ }
+ };
+
+ /// Regular expressions denoting the different ``#include`` categories
+ /// used for ordering ``#includes``.
+ ///
+ /// These regular expressions are matched against the filename of an include
+ /// (including the <> or "") in order. The value belonging to the first
+ /// matching regular expression is assigned and ``#includes`` are sorted first
+ /// according to increasing category number and then alphabetically within
+ /// each category.
+ ///
+ /// If none of the regular expressions match, INT_MAX is assigned as
+ /// category. The main header for a source file automatically gets category 0.
+ /// so that it is generally kept at the beginning of the ``#includes``
+ /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
+ /// can also assign negative priorities if you have certain headers that
+ /// always need to be first.
+ ///
+ /// To configure this in the .clang-format file, use:
+ /// \code{.yaml}
+ /// IncludeCategories:
+ /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ /// Priority: 2
+ /// - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ /// Priority: 3
+ /// - Regex: '.*'
+ /// Priority: 1
+ /// \endcode
+ std::vector<IncludeCategory> IncludeCategories;
+
+ /// Specify a regular expression of suffixes that are allowed in the
+ /// file-to-main-include mapping.
+ ///
+ /// When guessing whether a #include is the "main" include (to assign
+ /// category 0, see above), use this regex of allowed suffixes to the header
+ /// stem. A partial match is done, so that:
+ /// - "" means "arbitrary suffix"
+ /// - "$" means "no suffix"
+ ///
+ /// For example, if configured to "(_test)?$", then a header a.h would be seen
+ /// as the "main" include in both a.cc and a_test.cc.
+ std::string IncludeIsMainRegex;
+};
+
+} // namespace tooling
+} // namespace clang
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::IncludeStyle::IncludeCategory)
+
+namespace llvm {
+namespace yaml {
+
+template <>
+struct MappingTraits<clang::tooling::IncludeStyle::IncludeCategory> {
+ static void mapping(IO &IO,
+ clang::tooling::IncludeStyle::IncludeCategory &Category);
+};
+
+template <>
+struct ScalarEnumerationTraits<
+ clang::tooling::IncludeStyle::IncludeBlocksStyle> {
+ static void
+ enumeration(IO &IO, clang::tooling::IncludeStyle::IncludeBlocksStyle &Value);
+};
+
+} // namespace yaml
+} // namespace llvm
+
+#endif // LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H
using clang::format::FormatStyle;
-LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
namespace llvm {
Style.ExperimentalAutoDetectBinPacking);
IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
IO.mapOptional("ForEachMacros", Style.ForEachMacros);
- IO.mapOptional("IncludeBlocks", Style.IncludeBlocks);
- IO.mapOptional("IncludeCategories", Style.IncludeCategories);
- IO.mapOptional("IncludeIsMainRegex", Style.IncludeIsMainRegex);
+ IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
+ IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
+ IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
IO.mapOptional("IndentWidth", Style.IndentWidth);
}
};
-template <> struct MappingTraits<FormatStyle::IncludeCategory> {
- static void mapping(IO &IO, FormatStyle::IncludeCategory &Category) {
- IO.mapOptional("Regex", Category.Regex);
- IO.mapOptional("Priority", Category.Priority);
- }
-};
-
-template <> struct ScalarEnumerationTraits<FormatStyle::IncludeBlocksStyle> {
- static void enumeration(IO &IO, FormatStyle::IncludeBlocksStyle &Value) {
- IO.enumCase(Value, "Preserve", FormatStyle::IBS_Preserve);
- IO.enumCase(Value, "Merge", FormatStyle::IBS_Merge);
- IO.enumCase(Value, "Regroup", FormatStyle::IBS_Regroup);
- }
-};
-
template <> struct MappingTraits<FormatStyle::RawStringFormat> {
static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
IO.mapOptional("Language", Format.Language);
LLVMStyle.ForEachMacros.push_back("foreach");
LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
- LLVMStyle.IncludeCategories = {{"^\"(llvm|llvm-c|clang|clang-c)/", 2},
- {"^(<|\"(gtest|gmock|isl|json)/)", 3},
- {".*", 1}};
- LLVMStyle.IncludeIsMainRegex = "(Test)?$";
- LLVMStyle.IncludeBlocks = FormatStyle::IBS_Preserve;
+ LLVMStyle.IncludeStyle.IncludeCategories = {
+ {"^\"(llvm|llvm-c|clang|clang-c)/", 2},
+ {"^(<|\"(gtest|gmock|isl|json)/)", 3},
+ {".*", 1}};
+ LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
+ LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
LLVMStyle.IndentWrappedFunctionNames = false;
GoogleStyle.AlwaysBreakTemplateDeclarations = true;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.DerivePointerAlignment = true;
- GoogleStyle.IncludeCategories = {
+ GoogleStyle.IncludeStyle.IncludeCategories = {
{"^<ext/.*\\.h>", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
- GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
+ GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
// the entire block. Otherwise, no replacement is generated.
if (Indices.size() == Includes.size() &&
std::is_sorted(Indices.begin(), Indices.end()) &&
- Style.IncludeBlocks == FormatStyle::IBS_Preserve)
+ Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve)
return;
std::string result;
for (unsigned Index : Indices) {
if (!result.empty()) {
result += "\n";
- if (Style.IncludeBlocks == FormatStyle::IBS_Regroup &&
+ if (Style.IncludeStyle.IncludeBlocks ==
+ tooling::IncludeStyle::IBS_Regroup &&
CurrentCategory != Includes[Index].Category)
result += "\n";
}
IncludeCategoryManager(const FormatStyle &Style, StringRef FileName)
: Style(Style), FileName(FileName) {
FileStem = llvm::sys::path::stem(FileName);
- for (const auto &Category : Style.IncludeCategories)
+ for (const auto &Category : Style.IncludeStyle.IncludeCategories)
CategoryRegexs.emplace_back(Category.Regex, llvm::Regex::IgnoreCase);
IsMainFile = FileName.endswith(".c") || FileName.endswith(".cc") ||
FileName.endswith(".cpp") || FileName.endswith(".c++") ||
int Ret = INT_MAX;
for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
if (CategoryRegexs[i].match(IncludeName)) {
- Ret = Style.IncludeCategories[i].Priority;
+ Ret = Style.IncludeStyle.IncludeCategories[i].Priority;
break;
}
if (CheckMainHeader && IsMainFile && Ret > 0 && isMainHeader(IncludeName))
if (FileStem.startswith(HeaderStem) ||
FileStem.startswith_lower(HeaderStem)) {
llvm::Regex MainIncludeRegex(
- (HeaderStem + Style.IncludeIsMainRegex).str(),
+ (HeaderStem + Style.IncludeStyle.IncludeIsMainRegex).str(),
llvm::Regex::IgnoreCase);
if (MainIncludeRegex.match(FileStem))
return true;
FormattingOff = false;
const bool EmptyLineSkipped =
- Trimmed.empty() && (Style.IncludeBlocks == FormatStyle::IBS_Merge ||
- Style.IncludeBlocks == FormatStyle::IBS_Regroup);
+ Trimmed.empty() &&
+ (Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Merge ||
+ Style.IncludeStyle.IncludeBlocks ==
+ tooling::IncludeStyle::IBS_Regroup);
if (!FormattingOff && !Line.endswith("\\")) {
if (IncludeRegex.match(Line, &Matches)) {
// Add 0 for main header and INT_MAX for headers that are not in any
// category.
Priorities = {0, INT_MAX};
- for (const auto &Category : Style.IncludeCategories)
+ for (const auto &Category : Style.IncludeStyle.IncludeCategories)
Priorities.insert(Category.Priority);
SmallVector<StringRef, 32> Lines;
Code.drop_front(MinInsertOffset).split(Lines, "\n");
set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangToolingCore
+ IncludeStyle.cpp
Lookup.cpp
Replacement.cpp
Diagnostic.cpp
--- /dev/null
+//===--- IncludeStyle.cpp - Style of C++ #include directives -----*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Tooling/Core/IncludeStyle.h"
+
+
+using clang::tooling::IncludeStyle;
+
+namespace llvm {
+namespace yaml {
+
+void MappingTraits<IncludeStyle::IncludeCategory>::mapping(
+ IO &IO, IncludeStyle::IncludeCategory &Category) {
+ IO.mapOptional("Regex", Category.Regex);
+ IO.mapOptional("Priority", Category.Priority);
+}
+
+void ScalarEnumerationTraits<IncludeStyle::IncludeBlocksStyle>::enumeration(
+ IO &IO, IncludeStyle::IncludeBlocksStyle &Value) {
+ IO.enumCase(Value, "Preserve", IncludeStyle::IBS_Preserve);
+ IO.enumCase(Value, "Merge", IncludeStyle::IBS_Merge);
+ IO.enumCase(Value, "Regroup", IncludeStyle::IBS_Regroup);
+}
+
+} // namespace yaml
+} // namespace llvm
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 = {
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;
}
}
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) {
"#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",
"\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",
}
TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
- Style.SortIncludes = false;
+ FmtStyle.SortIncludes = false;
EXPECT_EQ("#include \"a.h\"\n"
"#include \"c.h\"\n"
"#include \"b.h\"\n",
}
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",
"// 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"
"// 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"
"#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"
}
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"
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"
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"
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"
"#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",
"#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",
"#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",
"#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",
"\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());