compositeprimes updated this revision to Diff 300402. Repository: rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89608/new/ https://reviews.llvm.org/D89608 Files: clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp +++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp @@ -133,7 +133,7 @@ utils::IncludeSorter::IS_Google_ObjC) {} std::vector<StringRef> headersToInclude() const override { - return {"clang_tidy/tests/insert_includes_test_header+foo.h"}; + return {"top_level_test_header+foo.h"}; } }; @@ -158,6 +158,10 @@ {"clang_tidy/tests/" "insert_includes_test_header.h", "\n"}, + // Top-level main file include + + // category. + {"top_level_test_header.h", "\n"}, + {"top_level_test_header+foo.h", "\n"}, // ObjC category. {"clang_tidy/tests/" "insert_includes_test_header+foo.h", @@ -708,14 +712,14 @@ TEST(IncludeInserterTest, InsertCategoryHeaderObjectiveC) { const char *PreCode = R"( -#import "clang_tidy/tests/insert_includes_test_header.h" +#import "top_level_test_header.h" void foo() { int a = 0; })"; const char *PostCode = R"( -#import "clang_tidy/tests/insert_includes_test_header.h" -#import "clang_tidy/tests/insert_includes_test_header+foo.h" +#import "top_level_test_header.h" +#import "top_level_test_header+foo.h" void foo() { int a = 0; @@ -724,7 +728,7 @@ EXPECT_EQ( PostCode, runCheckOnCode<ObjCCategoryHeaderInserterCheck>( - PreCode, "repo/clang_tidy/tests/insert_includes_test_header.mm")); + PreCode, "top_level_test_header.mm")); } TEST(IncludeInserterTest, InsertGeneratedHeaderObjectiveC) { Index: clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp @@ -45,8 +45,12 @@ // Objective-C categories have a `+suffix` format, but should be grouped // with the file they are a category of. + size_t start_index = Canonical.find_last_of('/'); + if (start_index == StringRef::npos) { + start_index = 0; + } return Canonical.substr( - 0, Canonical.find_first_of('+', Canonical.find_last_of('/'))); + 0, Canonical.find_first_of('+', start_index)); } return RemoveFirstSuffix( RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),
Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp +++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp @@ -133,7 +133,7 @@ utils::IncludeSorter::IS_Google_ObjC) {} std::vector<StringRef> headersToInclude() const override { - return {"clang_tidy/tests/insert_includes_test_header+foo.h"}; + return {"top_level_test_header+foo.h"}; } }; @@ -158,6 +158,10 @@ {"clang_tidy/tests/" "insert_includes_test_header.h", "\n"}, + // Top-level main file include + + // category. + {"top_level_test_header.h", "\n"}, + {"top_level_test_header+foo.h", "\n"}, // ObjC category. {"clang_tidy/tests/" "insert_includes_test_header+foo.h", @@ -708,14 +712,14 @@ TEST(IncludeInserterTest, InsertCategoryHeaderObjectiveC) { const char *PreCode = R"( -#import "clang_tidy/tests/insert_includes_test_header.h" +#import "top_level_test_header.h" void foo() { int a = 0; })"; const char *PostCode = R"( -#import "clang_tidy/tests/insert_includes_test_header.h" -#import "clang_tidy/tests/insert_includes_test_header+foo.h" +#import "top_level_test_header.h" +#import "top_level_test_header+foo.h" void foo() { int a = 0; @@ -724,7 +728,7 @@ EXPECT_EQ( PostCode, runCheckOnCode<ObjCCategoryHeaderInserterCheck>( - PreCode, "repo/clang_tidy/tests/insert_includes_test_header.mm")); + PreCode, "top_level_test_header.mm")); } TEST(IncludeInserterTest, InsertGeneratedHeaderObjectiveC) { Index: clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp @@ -45,8 +45,12 @@ // Objective-C categories have a `+suffix` format, but should be grouped // with the file they are a category of. + size_t start_index = Canonical.find_last_of('/'); + if (start_index == StringRef::npos) { + start_index = 0; + } return Canonical.substr( - 0, Canonical.find_first_of('+', Canonical.find_last_of('/'))); + 0, Canonical.find_first_of('+', start_index)); } return RemoveFirstSuffix( RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits