FileName.endswith(".cxx") || FileName.endswith(".m") ||
FileName.endswith(".mm");
StringRef FileStem = llvm::sys::path::stem(FileName);
+ bool FirstIncludeBlock = true;
// Create pre-compiled regular expressions for the #include categories.
SmallVector<llvm::Regex, 4> CategoryRegexs;
break;
}
}
- if (IsSource && Category > 0 && IncludeName.startswith("\"")) {
+ if (IsSource && Category > 0 && FirstIncludeBlock &&
+ IncludeName.startswith("\"")) {
StringRef HeaderStem =
llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1));
if (FileStem.startswith(HeaderStem))
sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces,
Cursor);
IncludesInBlock.clear();
+ FirstIncludeBlock = false;
}
Prev = Pos + 1;
}
"#include \"c.h\"\n"
"#include \"b.h\"\n",
"a.h"));
+
+ // Only do this in the first #include block.
+ EXPECT_EQ("#include <a>\n"
+ "\n"
+ "#include \"b.h\"\n"
+ "#include \"c.h\"\n"
+ "#include \"llvm/a.h\"\n",
+ sort("#include <a>\n"
+ "\n"
+ "#include \"llvm/a.h\"\n"
+ "#include \"c.h\"\n"
+ "#include \"b.h\"\n",
+ "a.cc"));
}
TEST_F(SortIncludesTest, NegativePriorities) {