From: Nico Weber Date: Mon, 19 Oct 2015 01:36:09 +0000 (+0000) Subject: clang-format: Extend main header include sorting heuristic to Objective-C files. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e930baa03c1829a050ce53a7ee7ddf851364e1bb;p=clang clang-format: Extend main header include sorting heuristic to Objective-C files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250675 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 674af7ac53..2595a66669 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1747,7 +1747,9 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, FileName.endswith(".cc") || FileName.endswith(".cpp")|| FileName.endswith(".c++")|| - FileName.endswith(".cxx"); + FileName.endswith(".cxx") || + FileName.endswith(".m")|| + FileName.endswith(".mm"); // Create pre-compiled regular expressions for the #include categories. SmallVector CategoryRegexs; diff --git a/unittests/Format/SortIncludesTest.cpp b/unittests/Format/SortIncludesTest.cpp index 8908eb92a5..36c8351810 100644 --- a/unittests/Format/SortIncludesTest.cpp +++ b/unittests/Format/SortIncludesTest.cpp @@ -122,6 +122,13 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { sort("#include \"llvm/a.h\"\n" "#include \"c.h\"\n" "#include \"b.h\"\n")); + EXPECT_EQ("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"\n", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"\n", + "input.mm")); // Don't do this in headers. EXPECT_EQ("#include \"b.h\"\n"