forked from OSchip/llvm-project
[clang-format] De-duplicate includes with leading or trailing whitespace.
This fixes PR46555 (https://bugs.llvm.org/show_bug.cgi?id=46555). Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D88296
This commit is contained in:
parent
6627a3c287
commit
fe21c86ee7
|
@ -2179,7 +2179,8 @@ static void sortCppIncludes(const FormatStyle &Style,
|
|||
// Deduplicate #includes.
|
||||
Indices.erase(std::unique(Indices.begin(), Indices.end(),
|
||||
[&](unsigned LHSI, unsigned RHSI) {
|
||||
return Includes[LHSI].Text == Includes[RHSI].Text;
|
||||
return Includes[LHSI].Text.trim() ==
|
||||
Includes[RHSI].Text.trim();
|
||||
}),
|
||||
Indices.end());
|
||||
|
||||
|
|
|
@ -289,6 +289,19 @@ TEST_F(SortIncludesTest, LeadingWhitespace) {
|
|||
sort("# include \"a.h\"\n"
|
||||
"# include \"c.h\"\n"
|
||||
"# include \"b.h\"\n"));
|
||||
EXPECT_EQ("#include \"a.h\"\n", sort("#include \"a.h\"\n"
|
||||
" #include \"a.h\"\n"));
|
||||
}
|
||||
|
||||
TEST_F(SortIncludesTest, TrailingWhitespace) {
|
||||
EXPECT_EQ("#include \"a.h\"\n"
|
||||
"#include \"b.h\"\n"
|
||||
"#include \"c.h\"\n",
|
||||
sort("#include \"a.h\" \n"
|
||||
"#include \"c.h\" \n"
|
||||
"#include \"b.h\" \n"));
|
||||
EXPECT_EQ("#include \"a.h\"\n", sort("#include \"a.h\"\n"
|
||||
"#include \"a.h\" \n"));
|
||||
}
|
||||
|
||||
TEST_F(SortIncludesTest, GreaterInComment) {
|
||||
|
|
Loading…
Reference in New Issue