Author: Owen Pan Date: 2024-05-19T15:19:05-07:00 New Revision: 2d5e488c98225108aebfe4aa4acfe6ec1f234a37
URL: https://github.com/llvm/llvm-project/commit/2d5e488c98225108aebfe4aa4acfe6ec1f234a37 DIFF: https://github.com/llvm/llvm-project/commit/2d5e488c98225108aebfe4aa4acfe6ec1f234a37.diff LOG: [clang-format][NFC] Clean up SortIncludesTest.cpp Wherever applicable, replace EXPECT_EQ with verifyFormat and std::string with StringRef. Also, change a raw string literal to a regular one. Added: Modified: clang/unittests/Format/SortIncludesTest.cpp Removed: ################################################################################ diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 824fa0078cd03..52ba19627182b 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -53,35 +53,35 @@ class SortIncludesTest : public test::FormatTestBase { }; TEST_F(SortIncludesTest, BasicSorting) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"")); - - EXPECT_EQ("// comment\n" - "#include <a>\n" - "#include <b>", - sort("// comment\n" - "#include <b>\n" - "#include <a>", - {tooling::Range(25, 1)})); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"")); + + verifyFormat("// comment\n" + "#include <a>\n" + "#include <b>", + sort("// comment\n" + "#include <b>\n" + "#include <a>", + {tooling::Range(25, 1)})); } TEST_F(SortIncludesTest, TrailingComments) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\" /* long\n" - " * long\n" - " * comment*/\n" - "#include \"c.h\"\n" - "#include \"d.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\" /* long\n" - " * long\n" - " * comment*/\n" - "#include \"d.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\" /* long\n" + " * long\n" + " * comment*/\n" + "#include \"c.h\"\n" + "#include \"d.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\" /* long\n" + " * long\n" + " * comment*/\n" + "#include \"d.h\"")); } TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) { @@ -100,531 +100,531 @@ TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) { {"<path", 9, 11, false}, {"^<[^/].*\\.h>", 8, 10, false}, {"^\".*\\.h\"", 10, 12, false}}; - EXPECT_EQ("#include <sys/param.h>\n" - "#include <sys/types.h>\n" - "#include <sys/ioctl.h>\n" - "#include <sys/socket.h>\n" - "#include <sys/stat.h>\n" - "#include <sys/wait.h>\n" - "\n" - "#include <net/if.h>\n" - "#include <net/if_dl.h>\n" - "#include <net/route.h>\n" - "#include <netinet/in.h>\n" - "#include <protocols/rwhod.h>\n" - "\n" - "#include <assert.h>\n" - "#include <errno.h>\n" - "#include <inttypes.h>\n" - "#include <stdio.h>\n" - "#include <stdlib.h>\n" - "\n" - "#include <paths.h>\n" - "\n" - "#include \"pathnames.h\"", - sort("#include <sys/param.h>\n" - "#include <sys/types.h>\n" - "#include <sys/ioctl.h>\n" - "#include <net/if_dl.h>\n" - "#include <net/route.h>\n" - "#include <netinet/in.h>\n" - "#include <sys/socket.h>\n" - "#include <sys/stat.h>\n" - "#include <sys/wait.h>\n" - "#include <net/if.h>\n" - "#include <protocols/rwhod.h>\n" - "#include <assert.h>\n" - "#include <paths.h>\n" - "#include \"pathnames.h\"\n" - "#include <errno.h>\n" - "#include <inttypes.h>\n" - "#include <stdio.h>\n" - "#include <stdlib.h>")); + verifyFormat("#include <sys/param.h>\n" + "#include <sys/types.h>\n" + "#include <sys/ioctl.h>\n" + "#include <sys/socket.h>\n" + "#include <sys/stat.h>\n" + "#include <sys/wait.h>\n" + "\n" + "#include <net/if.h>\n" + "#include <net/if_dl.h>\n" + "#include <net/route.h>\n" + "#include <netinet/in.h>\n" + "#include <protocols/rwhod.h>\n" + "\n" + "#include <assert.h>\n" + "#include <errno.h>\n" + "#include <inttypes.h>\n" + "#include <stdio.h>\n" + "#include <stdlib.h>\n" + "\n" + "#include <paths.h>\n" + "\n" + "#include \"pathnames.h\"", + sort("#include <sys/param.h>\n" + "#include <sys/types.h>\n" + "#include <sys/ioctl.h>\n" + "#include <net/if_dl.h>\n" + "#include <net/route.h>\n" + "#include <netinet/in.h>\n" + "#include <sys/socket.h>\n" + "#include <sys/stat.h>\n" + "#include <sys/wait.h>\n" + "#include <net/if.h>\n" + "#include <protocols/rwhod.h>\n" + "#include <assert.h>\n" + "#include <paths.h>\n" + "#include \"pathnames.h\"\n" + "#include <errno.h>\n" + "#include <inttypes.h>\n" + "#include <stdio.h>\n" + "#include <stdlib.h>")); } TEST_F(SortIncludesTest, SortPriorityNotDefined) { FmtStyle = getLLVMStyle(); - EXPECT_EQ("#include \"FormatTestUtils.h\"\n" - "#include \"clang/Format/Format.h\"\n" - "#include \"llvm/ADT/None.h\"\n" - "#include \"llvm/Support/Debug.h\"\n" - "#include \"gtest/gtest.h\"", - sort("#include \"clang/Format/Format.h\"\n" - "#include \"llvm/ADT/None.h\"\n" - "#include \"FormatTestUtils.h\"\n" - "#include \"gtest/gtest.h\"\n" - "#include \"llvm/Support/Debug.h\"")); + verifyFormat("#include \"FormatTestUtils.h\"\n" + "#include \"clang/Format/Format.h\"\n" + "#include \"llvm/ADT/None.h\"\n" + "#include \"llvm/Support/Debug.h\"\n" + "#include \"gtest/gtest.h\"", + sort("#include \"clang/Format/Format.h\"\n" + "#include \"llvm/ADT/None.h\"\n" + "#include \"FormatTestUtils.h\"\n" + "#include \"gtest/gtest.h\"\n" + "#include \"llvm/Support/Debug.h\"")); } TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) { // Identical #includes have led to a failure with an unstable sort. - std::string Code = "#include <a>\n" - "#include <b>\n" - "#include <c>\n" - "#include <d>\n" - "#include <e>\n" - "#include <f>\n"; + StringRef Code = "#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "#include <d>\n" + "#include <e>\n" + "#include <f>\n"; EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cc").empty()); } TEST_F(SortIncludesTest, MainFileHeader) { - std::string Code = "#include <string>\n" - "\n" - "#include \"a/extra_action.proto.h\"\n"; + StringRef Code = "#include <string>\n" + "\n" + "#include \"a/extra_action.proto.h\"\n"; FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp); EXPECT_TRUE( sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a/extra_action.cc") .empty()); - EXPECT_EQ("#include \"foo.bar.h\"\n" - "\n" - "#include \"a.h\"", - sort("#include \"a.h\"\n" - "#include \"foo.bar.h\"", - "foo.bar.cc")); + verifyFormat("#include \"foo.bar.h\"\n" + "\n" + "#include \"a.h\"", + sort("#include \"a.h\"\n" + "#include \"foo.bar.h\"", + "foo.bar.cc")); } TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) { Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "\n" + "#include \"b.h\"")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "\n" + "#include \"b.h\"")); } TEST_F(SortIncludesTest, SupportClangFormatOff) { - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>\n" - "// clang-format off\n" - "#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "// clang-format on", - sort("#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "// clang-format off\n" - "#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "// clang-format on")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "// clang-format off\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "// clang-format on", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "// clang-format off\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "// clang-format on")); Style.IncludeBlocks = Style.IBS_Merge; - std::string Code = "// clang-format off\r\n" - "#include \"d.h\"\r\n" - "#include \"b.h\"\r\n" - "// clang-format on\r\n" - "\r\n" - "#include \"c.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"e.h\"\r\n"; - - std::string Expected = "// clang-format off\r\n" - "#include \"d.h\"\r\n" - "#include \"b.h\"\r\n" - "// clang-format on\r\n" - "\r\n" - "#include \"e.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"c.h\"\r\n"; - - EXPECT_EQ(Expected, sort(Code, "e.cpp", 1)); + StringRef Code = "// clang-format off\r\n" + "#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "// clang-format on\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + StringRef Expected = "// clang-format off\r\n" + "#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "// clang-format on\r\n" + "\r\n" + "#include \"e.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"c.h\"\r\n"; + + verifyFormat(Expected, sort(Code, "e.cpp", 1)); } TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) { - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>\n" - "/* clang-format off */\n" - "#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "/* clang-format on */", - sort("#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "/* clang-format off */\n" - "#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "/* clang-format on */")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */")); // Not really turning it off - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>\n" - "/* clang-format offically */\n" - "#include <a>\n" - "#include <b>\n" - "#include <c>\n" - "/* clang-format onwards */", - sort("#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "/* clang-format offically */\n" - "#include <b>\n" - "#include <a>\n" - "#include <c>\n" - "/* clang-format onwards */", - "input.h", 2)); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format onwards */", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format onwards */", + "input.h", 2)); } TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { FmtStyle.SortIncludes = FormatStyle::SI_Never; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "input.h", 0)); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "input.h", 0)); } TEST_F(SortIncludesTest, MixIncludeAndImport) { - EXPECT_EQ("#include \"a.h\"\n" - "#import \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#import \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#import \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#import \"b.h\"")); } TEST_F(SortIncludesTest, FixTrailingComments) { - EXPECT_EQ("#include \"a.h\" // comment\n" - "#include \"bb.h\" // comment\n" - "#include \"ccc.h\"", - sort("#include \"a.h\" // comment\n" - "#include \"ccc.h\"\n" - "#include \"bb.h\" // comment")); + verifyFormat("#include \"a.h\" // comment\n" + "#include \"bb.h\" // comment\n" + "#include \"ccc.h\"", + sort("#include \"a.h\" // comment\n" + "#include \"ccc.h\"\n" + "#include \"bb.h\" // comment")); } TEST_F(SortIncludesTest, LeadingWhitespace) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort(" #include \"a.h\"\n" - " #include \"c.h\"\n" - " #include \"b.h\"")); - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("# include \"a.h\"\n" - "# include \"c.h\"\n" - "# include \"b.h\"")); - EXPECT_EQ("#include \"a.h\"", sort("#include \"a.h\"\n" - " #include \"a.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort(" #include \"a.h\"\n" + " #include \"c.h\"\n" + " #include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("# include \"a.h\"\n" + "# include \"c.h\"\n" + "# include \"b.h\"")); + verifyFormat("#include \"a.h\"", sort("#include \"a.h\"\n" + " #include \"a.h\"")); } TEST_F(SortIncludesTest, TrailingWhitespace) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\" \n" - "#include \"c.h\" \n" - "#include \"b.h\" ")); - EXPECT_EQ("#include \"a.h\"", sort("#include \"a.h\"\n" - "#include \"a.h\" ")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\" \n" + "#include \"c.h\" \n" + "#include \"b.h\" ")); + verifyFormat("#include \"a.h\"", sort("#include \"a.h\"\n" + "#include \"a.h\" ")); } TEST_F(SortIncludesTest, GreaterInComment) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\" // >\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\" // >")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\" // >\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\" // >")); } TEST_F(SortIncludesTest, SortsLocallyInEachBlock) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "#include \"b.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "#include \"b.h\"", - "input.h", 0)); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "#include \"b.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "#include \"b.h\"", + "input.h", 0)); } TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) { Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "#include \"b.h\"")); } TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "// comment\n" - "#include \"b.h\"", - sort("#include \"c.h\"\n" - "#include \"a.h\"\n" - "// comment\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "// comment\n" + "#include \"b.h\"", + sort("#include \"c.h\"\n" + "#include \"a.h\"\n" + "// comment\n" + "#include \"b.h\"")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "// comment\n" - "#include \"b.h\"", - sort("#include \"c.h\"\n" - "#include \"a.h\"\n" - "// comment\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "// comment\n" + "#include \"b.h\"", + sort("#include \"c.h\"\n" + "#include \"a.h\"\n" + "// comment\n" + "#include \"b.h\"")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "// comment\n" - "#include \"b.h\"", - sort("#include \"c.h\"\n" - "#include \"a.h\"\n" - "// comment\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "// comment\n" + "#include \"b.h\"", + sort("#include \"c.h\"\n" + "#include \"a.h\"\n" + "// comment\n" + "#include \"b.h\"")); } TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include <array>\n" - "#include <b.h>\n" - "#include <d.h>\n" - "#include <vector>", - sort("#include <vector>\n" - "#include <d.h>\n" - "#include <array>\n" - "#include <b.h>\n" - "#include \"c.h\"\n" - "#include \"a.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include <array>\n" + "#include <b.h>\n" + "#include <d.h>\n" + "#include <vector>", + sort("#include <vector>\n" + "#include <d.h>\n" + "#include <array>\n" + "#include <b.h>\n" + "#include \"c.h\"\n" + "#include \"a.h\"")); FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp); - EXPECT_EQ("#include <b.h>\n" - "#include <d.h>\n" - "\n" - "#include <array>\n" - "#include <vector>\n" - "\n" - "#include \"a.h\"\n" - "#include \"c.h\"", - sort("#include <vector>\n" - "#include <d.h>\n" - "#include <array>\n" - "#include <b.h>\n" - "#include \"c.h\"\n" - "#include \"a.h\"")); + verifyFormat("#include <b.h>\n" + "#include <d.h>\n" + "\n" + "#include <array>\n" + "#include <vector>\n" + "\n" + "#include \"a.h\"\n" + "#include \"c.h\"", + sort("#include <vector>\n" + "#include <d.h>\n" + "#include <array>\n" + "#include <b.h>\n" + "#include \"c.h\"\n" + "#include \"a.h\"")); } TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) { Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include \"a.h\"\n" - "#include \"c.h\"\n" - "\n" - "#include <b.h>\n" - "#include <d.h>", - sort("#include <d.h>\n" - "#include <b.h>\n" - "#include \"c.h\"\n" - "#include \"a.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"c.h\"\n" + "\n" + "#include <b.h>\n" + "#include <d.h>", + sort("#include <d.h>\n" + "#include <b.h>\n" + "#include \"c.h\"\n" + "#include \"a.h\"")); } TEST_F(SortIncludesTest, HandlesMultilineIncludes) { - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"a.h\"\n" - "#include \\\n" - "\"c.h\"\n" - "#include \"b.h\"")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"a.h\"\n" + "#include \\\n" + "\"c.h\"\n" + "#include \"b.h\"")); } TEST_F(SortIncludesTest, HandlesTrailingCommentsWithAngleBrackets) { // Regression test from the discussion at https://reviews.llvm.org/D121370. - EXPECT_EQ("#include <cstdint>\n" - "\n" - "#include \"util/bar.h\"\n" - "#include \"util/foo/foo.h\" // foo<T>", - sort("#include <cstdint>\n" - "\n" - "#include \"util/bar.h\"\n" - "#include \"util/foo/foo.h\" // foo<T>", - /*FileName=*/"input.cc", - /*ExpectedNumRanges=*/0)); + verifyFormat("#include <cstdint>\n" + "\n" + "#include \"util/bar.h\"\n" + "#include \"util/foo/foo.h\" // foo<T>", + sort("#include <cstdint>\n" + "\n" + "#include \"util/bar.h\"\n" + "#include \"util/foo/foo.h\" // foo<T>", + /*FileName=*/"input.cc", + /*ExpectedNumRanges=*/0)); } TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a.cc")); - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a_test.cc")); - EXPECT_EQ("#include \"llvm/input.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/input.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "input.mm")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a.cc")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a_test.cc")); + verifyFormat("#include \"llvm/input.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/input.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "input.mm")); // Don't allow prefixes. - EXPECT_EQ("#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/not_a.h\"", - sort("#include \"llvm/not_a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a.cc")); + verifyFormat("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/not_a.h\"", + sort("#include \"llvm/not_a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a.cc")); // Don't do this for _main and other suffixes. - EXPECT_EQ("#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a_main.cc")); + verifyFormat("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a_main.cc")); // Don't do this in headers. - EXPECT_EQ("#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a.h")); + verifyFormat("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "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\"", - sort("#include <a>\n" - "\n" - "#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a.cc")); + verifyFormat("#include <a>\n" + "\n" + "#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include <a>\n" + "\n" + "#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a.cc")); // Only recognize the first #include with a matching basename as main include. - EXPECT_EQ("#include \"a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - sort("#include \"b.h\"\n" - "#include \"a.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - "a.cc")); + verifyFormat("#include \"a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include \"b.h\"\n" + "#include \"a.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + "a.cc")); } TEST_F(SortIncludesTest, LeavesMainHeaderFirstInAdditionalExtensions) { Style.IncludeIsMainRegex = "([-_](test|unittest))?|(Impl)?$"; - EXPECT_EQ("#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a_test.xxx")); - EXPECT_EQ("#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"llvm/a.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "aImpl.hpp")); + verifyFormat("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a_test.xxx")); + verifyFormat("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "aImpl.hpp")); // .cpp extension is considered "main" by default - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "aImpl.cpp")); - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a_test.cpp")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "aImpl.cpp")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a_test.cpp")); // Allow additional filenames / extensions Style.IncludeIsMainSourceRegex = "(Impl\\.hpp)|(\\.xxx)$"; - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "a_test.xxx")); - EXPECT_EQ("#include \"llvm/a.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"llvm/a.h\"\n" - "#include \"c.h\"\n" - "#include \"b.h\"", - "aImpl.hpp")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "a_test.xxx")); + verifyFormat("#include \"llvm/a.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"", + "aImpl.hpp")); } TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) { Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include \"c.h\"\n" - "#include \"a.h\"\n" - "#include \"b.h\"", - sort("#include \"b.h\"\n" - "\n" - "#include \"a.h\"\n" - "#include \"c.h\"", - "c.cc")); + verifyFormat("#include \"c.h\"\n" + "#include \"a.h\"\n" + "#include \"b.h\"", + sort("#include \"b.h\"\n" + "\n" + "#include \"a.h\"\n" + "#include \"c.h\"", + "c.cc")); } TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) { Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include \"a.h\"\n" - "\n" - "#include \"b.h\"\n" - "#include \"c.h\"", - sort("#include \"b.h\"\n" - "\n" - "#include \"a.h\"\n" - "#include \"c.h\"", - "a.cc")); + verifyFormat("#include \"a.h\"\n" + "\n" + "#include \"b.h\"\n" + "#include \"c.h\"", + sort("#include \"b.h\"\n" + "\n" + "#include \"a.h\"\n" + "#include \"c.h\"", + "a.cc")); } TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) { @@ -632,17 +632,17 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) { FmtStyle.SortIncludes = FormatStyle::SI_CaseInsensitive; - EXPECT_EQ("#include \"A/B.h\"\n" - "#include \"A/b.h\"\n" - "#include \"a/b.h\"\n" - "#include \"B/A.h\"\n" - "#include \"B/a.h\"", - sort("#include \"B/a.h\"\n" - "#include \"B/A.h\"\n" - "#include \"A/B.h\"\n" - "#include \"a/b.h\"\n" - "#include \"A/b.h\"", - "a.h")); + verifyFormat("#include \"A/B.h\"\n" + "#include \"A/b.h\"\n" + "#include \"a/b.h\"\n" + "#include \"B/A.h\"\n" + "#include \"B/a.h\"", + sort("#include \"B/a.h\"\n" + "#include \"B/A.h\"\n" + "#include \"A/B.h\"\n" + "#include \"a/b.h\"\n" + "#include \"A/b.h\"", + "a.h")); Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup; Style.IncludeCategories = { @@ -657,17 +657,17 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) { "#include \"Vlib.h\"\n" "#include \"AST.h\""; - EXPECT_EQ("#include \"AST.h\"\n" - "#include \"qt.h\"\n" - "#include \"Vlib.h\"\n" - "#include \"vlib.h\"\n" - "\n" - "#include <Qtwhatever.h>\n" - "#include <qtwhatever.h>\n" - "\n" - "#include <Algorithm>\n" - "#include <algorithm>", - sort(UnsortedCode)); + verifyFormat("#include \"AST.h\"\n" + "#include \"qt.h\"\n" + "#include \"Vlib.h\"\n" + "#include \"vlib.h\"\n" + "\n" + "#include <Qtwhatever.h>\n" + "#include <qtwhatever.h>\n" + "\n" + "#include <Algorithm>\n" + "#include <algorithm>", + sort(UnsortedCode)); } TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) { @@ -676,21 +676,21 @@ TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) { // Ensure both main header detection and grouping work in a case insensitive // manner. - EXPECT_EQ("#include \"llvm/A.h\"\n" - "#include \"b.h\"\n" - "#include \"c.h\"\n" - "#include \"LLVM/z.h\"\n" - "#include \"llvm/X.h\"\n" - "#include \"GTest/GTest.h\"\n" - "#include \"gmock/gmock.h\"", - sort("#include \"c.h\"\n" - "#include \"b.h\"\n" - "#include \"GTest/GTest.h\"\n" - "#include \"llvm/A.h\"\n" - "#include \"gmock/gmock.h\"\n" - "#include \"llvm/X.h\"\n" - "#include \"LLVM/z.h\"", - "a_TEST.cc")); + verifyFormat("#include \"llvm/A.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"LLVM/z.h\"\n" + "#include \"llvm/X.h\"\n" + "#include \"GTest/GTest.h\"\n" + "#include \"gmock/gmock.h\"", + sort("#include \"c.h\"\n" + "#include \"b.h\"\n" + "#include \"GTest/GTest.h\"\n" + "#include \"llvm/A.h\"\n" + "#include \"gmock/gmock.h\"\n" + "#include \"llvm/X.h\"\n" + "#include \"LLVM/z.h\"", + "a_TEST.cc")); } TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) { @@ -711,57 +711,57 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) { "#include <qtwhatever.h>\n" "#include <QtGlobal>"; - EXPECT_EQ("#include \"qa.h\"\n" - "#include \"qt.h\"\n" - "\n" - "#include <qtwhatever.h>\n" - "#include <windows.h>\n" - "\n" - "#include <QLabel>\n" - "#include <QWidget>\n" - "#include <QtGlobal>\n" - "#include <queue>\n" - "\n" - "#include <algorithm>", - sort(UnsortedCode)); + verifyFormat("#include \"qa.h\"\n" + "#include \"qt.h\"\n" + "\n" + "#include <qtwhatever.h>\n" + "#include <windows.h>\n" + "\n" + "#include <QLabel>\n" + "#include <QWidget>\n" + "#include <QtGlobal>\n" + "#include <queue>\n" + "\n" + "#include <algorithm>", + sort(UnsortedCode)); Style.IncludeCategories[2].RegexIsCaseSensitive = true; Style.IncludeCategories[3].RegexIsCaseSensitive = true; - EXPECT_EQ("#include \"qa.h\"\n" - "#include \"qt.h\"\n" - "\n" - "#include <qtwhatever.h>\n" - "#include <windows.h>\n" - "\n" - "#include <QLabel>\n" - "#include <QWidget>\n" - "\n" - "#include <QtGlobal>\n" - "\n" - "#include <algorithm>\n" - "#include <queue>", - sort(UnsortedCode)); + verifyFormat("#include \"qa.h\"\n" + "#include \"qt.h\"\n" + "\n" + "#include <qtwhatever.h>\n" + "#include <windows.h>\n" + "\n" + "#include <QLabel>\n" + "#include <QWidget>\n" + "\n" + "#include <QtGlobal>\n" + "\n" + "#include <algorithm>\n" + "#include <queue>", + sort(UnsortedCode)); } TEST_F(SortIncludesTest, NegativePriorities) { Style.IncludeCategories = {{".*important_os_header.*", -1, 0, false}, {".*", 1, 0, false}}; - EXPECT_EQ("#include \"important_os_header.h\"\n" - "#include \"c_main.h\"\n" - "#include \"a_other.h\"", - sort("#include \"c_main.h\"\n" - "#include \"a_other.h\"\n" - "#include \"important_os_header.h\"", - "c_main.cc")); + verifyFormat("#include \"important_os_header.h\"\n" + "#include \"c_main.h\"\n" + "#include \"a_other.h\"", + sort("#include \"c_main.h\"\n" + "#include \"a_other.h\"\n" + "#include \"important_os_header.h\"", + "c_main.cc")); // check stable when re-run - EXPECT_EQ("#include \"important_os_header.h\"\n" - "#include \"c_main.h\"\n" - "#include \"a_other.h\"", - sort("#include \"important_os_header.h\"\n" - "#include \"c_main.h\"\n" - "#include \"a_other.h\"", - "c_main.cc", 0)); + verifyFormat("#include \"important_os_header.h\"\n" + "#include \"c_main.h\"\n" + "#include \"a_other.h\"", + sort("#include \"important_os_header.h\"\n" + "#include \"c_main.h\"\n" + "#include \"a_other.h\"", + "c_main.cc", 0)); } TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) { @@ -769,34 +769,34 @@ TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) { {".*", 1, 0, false}}; Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include \"important_os_header.h\"\n" - "\n" - "#include \"c_main.h\"\n" - "\n" - "#include \"a_other.h\"", - sort("#include \"c_main.h\"\n" - "#include \"a_other.h\"\n" - "#include \"important_os_header.h\"", - "c_main.cc")); + verifyFormat("#include \"important_os_header.h\"\n" + "\n" + "#include \"c_main.h\"\n" + "\n" + "#include \"a_other.h\"", + sort("#include \"c_main.h\"\n" + "#include \"a_other.h\"\n" + "#include \"important_os_header.h\"", + "c_main.cc")); // check stable when re-run - EXPECT_EQ("#include \"important_os_header.h\"\n" - "\n" - "#include \"c_main.h\"\n" - "\n" - "#include \"a_other.h\"", - sort("#include \"important_os_header.h\"\n" - "\n" - "#include \"c_main.h\"\n" - "\n" - "#include \"a_other.h\"", - "c_main.cc", 0)); + verifyFormat("#include \"important_os_header.h\"\n" + "\n" + "#include \"c_main.h\"\n" + "\n" + "#include \"a_other.h\"", + sort("#include \"important_os_header.h\"\n" + "\n" + "#include \"c_main.h\"\n" + "\n" + "#include \"a_other.h\"", + "c_main.cc", 0)); } TEST_F(SortIncludesTest, CalculatesCorrectCursorPosition) { - std::string Code = "#include <ccc>\n" // Start of line: 0 - "#include <bbbbbb>\n" // Start of line: 15 - "#include <a>\n"; // Start of line: 33 + StringRef Code = "#include <ccc>\n" // Start of line: 0 + "#include <bbbbbb>\n" // Start of line: 15 + "#include <a>\n"; // Start of line: 33 EXPECT_EQ(31u, newCursor(Code, 0)); EXPECT_EQ(13u, newCursor(Code, 15)); EXPECT_EQ(0u, newCursor(Code, 33)); @@ -808,14 +808,14 @@ TEST_F(SortIncludesTest, CalculatesCorrectCursorPosition) { TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionWithRegrouping) { Style.IncludeBlocks = Style.IBS_Regroup; - std::string Code = "#include \"b\"\n" // Start of line: 0 - "\n" // Start of line: 13 - "#include \"aa\"\n" // Start of line: 14 - "int i;"; // Start of line: 28 - std::string Expected = "#include \"aa\"\n" // Start of line: 0 - "#include \"b\"\n" // Start of line: 14 - "int i;"; // Start of line: 27 - EXPECT_EQ(Expected, sort(Code)); + StringRef Code = "#include \"b\"\n" // Start of line: 0 + "\n" // Start of line: 13 + "#include \"aa\"\n" // Start of line: 14 + "int i;"; // Start of line: 28 + StringRef Expected = "#include \"aa\"\n" // Start of line: 0 + "#include \"b\"\n" // Start of line: 14 + "int i;"; // Start of line: 27 + verifyFormat(Expected, sort(Code)); EXPECT_EQ(12u, newCursor(Code, 26)); // Closing quote of "aa" EXPECT_EQ(26u, newCursor(Code, 27)); // Newline after "aa" EXPECT_EQ(27u, newCursor(Code, 28)); // Start of last line @@ -827,14 +827,14 @@ TEST_F(SortIncludesTest, FmtStyle.LineEnding = FormatStyle::LE_CRLF; Style.IncludeCategories = { {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}}; - std::string Code = "#include \"a\"\r\n" // Start of line: 0 - "\r\n" // Start of line: 14 - "#include \"b\"\r\n" // Start of line: 16 - "\r\n" // Start of line: 30 - "#include \"c\"\r\n" // Start of line: 32 - "\r\n" // Start of line: 46 - "int i;"; // Start of line: 48 - verifyNoChange(Code); + StringRef Code = "#include \"a\"\r\n" // Start of line: 0 + "\r\n" // Start of line: 14 + "#include \"b\"\r\n" // Start of line: 16 + "\r\n" // Start of line: 30 + "#include \"c\"\r\n" // Start of line: 32 + "\r\n" // Start of line: 46 + "int i;"; // Start of line: 48 + verifyFormat(Code); EXPECT_EQ(0u, newCursor(Code, 0)); EXPECT_EQ(14u, newCursor(Code, 14)); EXPECT_EQ(16u, newCursor(Code, 16)); @@ -850,19 +850,19 @@ TEST_F( Style.IncludeBlocks = Style.IBS_Regroup; FmtStyle.LineEnding = FormatStyle::LE_CRLF; Style.IncludeCategories = {{".*", 0, 0, false}}; - std::string Code = "#include \"a\"\r\n" // Start of line: 0 - "\r\n" // Start of line: 14 - "#include \"b\"\r\n" // Start of line: 16 - "\r\n" // Start of line: 30 - "#include \"c\"\r\n" // Start of line: 32 - "\r\n" // Start of line: 46 - "int i;"; // Start of line: 48 - std::string Expected = "#include \"a\"\r\n" // Start of line: 0 - "#include \"b\"\r\n" // Start of line: 14 - "#include \"c\"\r\n" // Start of line: 28 - "\r\n" // Start of line: 42 - "int i;"; // Start of line: 44 - EXPECT_EQ(Expected, sort(Code)); + StringRef Code = "#include \"a\"\r\n" // Start of line: 0 + "\r\n" // Start of line: 14 + "#include \"b\"\r\n" // Start of line: 16 + "\r\n" // Start of line: 30 + "#include \"c\"\r\n" // Start of line: 32 + "\r\n" // Start of line: 46 + "int i;"; // Start of line: 48 + StringRef Expected = "#include \"a\"\r\n" // Start of line: 0 + "#include \"b\"\r\n" // Start of line: 14 + "#include \"c\"\r\n" // Start of line: 28 + "\r\n" // Start of line: 42 + "int i;"; // Start of line: 44 + verifyFormat(Expected, sort(Code)); EXPECT_EQ(0u, newCursor(Code, 0)); EXPECT_EQ( 14u, @@ -885,19 +885,19 @@ TEST_F( FmtStyle.LineEnding = FormatStyle::LE_CRLF; Style.IncludeCategories = { {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}}; - std::string Code = "#include \"a\"\r\n" // Start of line: 0 - "#include \"b\"\r\n" // Start of line: 14 - "#include \"c\"\r\n" // Start of line: 28 - "\r\n" // Start of line: 42 - "int i;"; // Start of line: 44 - std::string Expected = "#include \"a\"\r\n" // Start of line: 0 - "\r\n" // Start of line: 14 - "#include \"b\"\r\n" // Start of line: 16 - "\r\n" // Start of line: 30 - "#include \"c\"\r\n" // Start of line: 32 - "\r\n" // Start of line: 46 - "int i;"; // Start of line: 48 - EXPECT_EQ(Expected, sort(Code)); + StringRef Code = "#include \"a\"\r\n" // Start of line: 0 + "#include \"b\"\r\n" // Start of line: 14 + "#include \"c\"\r\n" // Start of line: 28 + "\r\n" // Start of line: 42 + "int i;"; // Start of line: 44 + StringRef Expected = "#include \"a\"\r\n" // Start of line: 0 + "\r\n" // Start of line: 14 + "#include \"b\"\r\n" // Start of line: 16 + "\r\n" // Start of line: 30 + "#include \"c\"\r\n" // Start of line: 32 + "\r\n" // Start of line: 46 + "int i;"; // Start of line: 48 + verifyFormat(Expected, sort(Code)); EXPECT_EQ(0u, newCursor(Code, 0)); EXPECT_EQ(15u, newCursor(Code, 16)); EXPECT_EQ(30u, newCursor(Code, 32)); @@ -912,21 +912,21 @@ TEST_F( FmtStyle.LineEnding = FormatStyle::LE_CRLF; Style.IncludeCategories = { {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}}; - std::string Code = "#include \"a\"\r\n" // Start of line: 0 - "\r\n" // Start of line: 14 - "#include \"c\"\r\n" // Start of line: 16 - "\r\n" // Start of line: 30 - "#include \"b\"\r\n" // Start of line: 32 - "\r\n" // Start of line: 46 - "int i;"; // Start of line: 48 - std::string Expected = "#include \"a\"\r\n" // Start of line: 0 - "\r\n" // Start of line: 14 - "#include \"b\"\r\n" // Start of line: 16 - "\r\n" // Start of line: 30 - "#include \"c\"\r\n" // Start of line: 32 - "\r\n" // Start of line: 46 - "int i;"; // Start of line: 48 - EXPECT_EQ(Expected, sort(Code)); + StringRef Code = "#include \"a\"\r\n" // Start of line: 0 + "\r\n" // Start of line: 14 + "#include \"c\"\r\n" // Start of line: 16 + "\r\n" // Start of line: 30 + "#include \"b\"\r\n" // Start of line: 32 + "\r\n" // Start of line: 46 + "int i;"; // Start of line: 48 + StringRef Expected = "#include \"a\"\r\n" // Start of line: 0 + "\r\n" // Start of line: 14 + "#include \"b\"\r\n" // Start of line: 16 + "\r\n" // Start of line: 30 + "#include \"c\"\r\n" // Start of line: 32 + "\r\n" // Start of line: 46 + "int i;"; // Start of line: 48 + verifyFormat(Expected, sort(Code)); EXPECT_EQ(0u, newCursor(Code, 0)); EXPECT_EQ(14u, newCursor(Code, 14)); EXPECT_EQ(30u, newCursor(Code, 32)); @@ -938,88 +938,88 @@ TEST_F( #endif TEST_F(SortIncludesTest, DeduplicateIncludes) { - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <a>\n" - "#include <b>\n" - "#include <b>\n" - "#include <b>\n" - "#include <b>\n" - "#include <c>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <a>\n" + "#include <b>\n" + "#include <b>\n" + "#include <b>\n" + "#include <b>\n" + "#include <c>")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <a>\n" - "#include <b>\n" - "\n" - "#include <b>\n" - "\n" - "#include <b>\n" - "#include <c>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <a>\n" + "#include <b>\n" + "\n" + "#include <b>\n" + "\n" + "#include <b>\n" + "#include <c>")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <a>\n" - "#include <b>\n" - "\n" - "#include <b>\n" - "\n" - "#include <b>\n" - "#include <c>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <a>\n" + "#include <b>\n" + "\n" + "#include <b>\n" + "\n" + "#include <b>\n" + "#include <c>")); } TEST_F(SortIncludesTest, SortAndDeduplicateIncludes) { - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <b>\n" - "#include <a>\n" - "#include <b>\n" - "#include <b>\n" - "#include <c>\n" - "#include <b>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <b>\n" + "#include <a>\n" + "#include <b>\n" + "#include <b>\n" + "#include <c>\n" + "#include <b>")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge; - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <b>\n" - "#include <a>\n" - "\n" - "#include <b>\n" - "\n" - "#include <c>\n" - "#include <b>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <b>\n" + "#include <a>\n" + "\n" + "#include <b>\n" + "\n" + "#include <c>\n" + "#include <b>")); Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "#include <c>", - sort("#include <b>\n" - "#include <a>\n" - "\n" - "#include <b>\n" - "\n" - "#include <c>\n" - "#include <b>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "#include <c>", + sort("#include <b>\n" + "#include <a>\n" + "\n" + "#include <b>\n" + "\n" + "#include <c>\n" + "#include <b>")); } TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionAfterDeduplicate) { - std::string Code = "#include <b>\n" // Start of line: 0 - "#include <a>\n" // Start of line: 13 - "#include <b>\n" // Start of line: 26 - "#include <b>\n" // Start of line: 39 - "#include <c>\n" // Start of line: 52 - "#include <b>\n"; // Start of line: 65 - std::string Expected = "#include <a>\n" // Start of line: 0 - "#include <b>\n" // Start of line: 13 - "#include <c>\n"; // Start of line: 26 - EXPECT_EQ(Expected, sort(Code)); + StringRef Code = "#include <b>\n" // Start of line: 0 + "#include <a>\n" // Start of line: 13 + "#include <b>\n" // Start of line: 26 + "#include <b>\n" // Start of line: 39 + "#include <c>\n" // Start of line: 52 + "#include <b>\n"; // Start of line: 65 + StringRef Expected = "#include <a>\n" // Start of line: 0 + "#include <b>\n" // Start of line: 13 + "#include <c>\n"; // Start of line: 26 + verifyFormat(Expected, sort(Code)); // Cursor on 'i' in "#include <a>". EXPECT_EQ(1u, newCursor(Code, 14)); // Cursor on 'b' in "#include <b>". @@ -1033,26 +1033,26 @@ TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionAfterDeduplicate) { } TEST_F(SortIncludesTest, DeduplicateLocallyInEachBlock) { - EXPECT_EQ("#include <a>\n" - "#include <b>\n" - "\n" - "#include <b>\n" - "#include <c>", - sort("#include <a>\n" - "#include <b>\n" - "\n" - "#include <c>\n" - "#include <b>\n" - "#include <b>")); + verifyFormat("#include <a>\n" + "#include <b>\n" + "\n" + "#include <b>\n" + "#include <c>", + sort("#include <a>\n" + "#include <b>\n" + "\n" + "#include <c>\n" + "#include <b>\n" + "#include <b>")); } TEST_F(SortIncludesTest, ValidAffactedRangesAfterDeduplicatingIncludes) { - std::string Code = "#include <a>\n" - "#include <b>\n" - "#include <a>\n" - "#include <a>\n" - "\n" - " int x ;"; + StringRef Code = "#include <a>\n" + "#include <b>\n" + "#include <a>\n" + "#include <a>\n" + "\n" + " int x ;"; std::vector<tooling::Range> Ranges = {tooling::Range(0, 52)}; auto Replaces = sortIncludes(FmtStyle, Code, Ranges, "input.cpp"); Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges); @@ -1062,80 +1062,78 @@ TEST_F(SortIncludesTest, ValidAffactedRangesAfterDeduplicatingIncludes) { } TEST_F(SortIncludesTest, DoNotSortLikelyXml) { - EXPECT_EQ("<!--;\n" - "#include <b>\n" - "#include <a>\n" - "-->", - sort("<!--;\n" - "#include <b>\n" - "#include <a>\n" - "-->", - "input.h", 0)); + verifyFormat("<!--;\n" + "#include <b>\n" + "#include <a>\n" + "-->", + sort("<!--;\n" + "#include <b>\n" + "#include <a>\n" + "-->", + "input.h", 0)); } TEST_F(SortIncludesTest, DoNotOutputReplacementsForSortedBlocksWithRegrouping) { Style.IncludeBlocks = Style.IBS_Regroup; - std::string Code = R"( -#include "b.h" - -#include <a.h> -)"; - EXPECT_EQ(Code, sort(Code, "input.h", 0)); + StringRef Code = "#include \"b.h\"\n" + "\n" + "#include <a.h>"; + verifyFormat(Code, sort(Code, "input.h", 0)); } TEST_F(SortIncludesTest, DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) { Style.IncludeBlocks = Style.IBS_Regroup; - std::string Code = "#include \"b.h\"\r\n" - "\r\n" - "#include <a.h>\r\n"; - EXPECT_EQ(Code, sort(Code, "input.h", 0)); + StringRef Code = "#include \"b.h\"\r\n" + "\r\n" + "#include <a.h>\r\n"; + verifyFormat(Code, sort(Code, "input.h", 0)); } TEST_F(SortIncludesTest, MainIncludeChar) { - std::string Code = "#include <a>\n" - "#include \"quote/input.h\"\n" - "#include <angle-bracket/input.h>\n"; + StringRef Code = "#include <a>\n" + "#include \"quote/input.h\"\n" + "#include <angle-bracket/input.h>\n"; // Default behavior - EXPECT_EQ("#include \"quote/input.h\"\n" - "#include <a>\n" - "#include <angle-bracket/input.h>\n", - sort(Code, "input.cc", 1)); + verifyFormat("#include \"quote/input.h\"\n" + "#include <a>\n" + "#include <angle-bracket/input.h>\n", + sort(Code, "input.cc", 1)); Style.MainIncludeChar = tooling::IncludeStyle::MICD_Quote; - EXPECT_EQ("#include \"quote/input.h\"\n" - "#include <a>\n" - "#include <angle-bracket/input.h>\n", - sort(Code, "input.cc", 1)); + verifyFormat("#include \"quote/input.h\"\n" + "#include <a>\n" + "#include <angle-bracket/input.h>\n", + sort(Code, "input.cc", 1)); Style.MainIncludeChar = tooling::IncludeStyle::MICD_AngleBracket; - EXPECT_EQ("#include <angle-bracket/input.h>\n" - "#include \"quote/input.h\"\n" - "#include <a>\n", - sort(Code, "input.cc", 1)); + verifyFormat("#include <angle-bracket/input.h>\n" + "#include \"quote/input.h\"\n" + "#include <a>\n", + sort(Code, "input.cc", 1)); } TEST_F(SortIncludesTest, MainIncludeCharAnyPickQuote) { Style.MainIncludeChar = tooling::IncludeStyle::MICD_Any; - EXPECT_EQ("#include \"input.h\"\n" - "#include <a>\n" - "#include <b>\n", - sort("#include <a>\n" - "#include \"input.h\"\n" - "#include <b>\n", - "input.cc", 1)); + verifyFormat("#include \"input.h\"\n" + "#include <a>\n" + "#include <b>\n", + sort("#include <a>\n" + "#include \"input.h\"\n" + "#include <b>\n", + "input.cc", 1)); } TEST_F(SortIncludesTest, MainIncludeCharAnyPickAngleBracket) { Style.MainIncludeChar = tooling::IncludeStyle::MICD_Any; - EXPECT_EQ("#include <input.h>\n" - "#include <a>\n" - "#include <b>\n", - sort("#include <a>\n" - "#include <input.h>\n" - "#include <b>\n", - "input.cc", 1)); + verifyFormat("#include <input.h>\n" + "#include <a>\n" + "#include <b>\n", + sort("#include <a>\n" + "#include <input.h>\n" + "#include <b>\n", + "input.cc", 1)); } TEST_F(SortIncludesTest, MainIncludeCharQuoteAndRegroup) { @@ -1144,28 +1142,28 @@ TEST_F(SortIncludesTest, MainIncludeCharQuoteAndRegroup) { Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; Style.MainIncludeChar = tooling::IncludeStyle::MICD_Quote; - EXPECT_EQ("#include \"lib-b/input.h\"\n" - "\n" - "#include <lib-a/h-1.h>\n" - "#include <lib-a/h-3.h>\n" - "#include <lib-a/input.h>\n" - "\n" - "#include <lib-b/h-1.h>\n" - "#include <lib-b/h-3.h>\n" - "\n" - "#include <lib-c/h-1.h>\n" - "#include <lib-c/h-2.h>\n" - "#include <lib-c/h-3.h>\n", - sort("#include <lib-c/h-1.h>\n" - "#include <lib-c/h-2.h>\n" - "#include <lib-c/h-3.h>\n" - "#include <lib-b/h-1.h>\n" - "#include \"lib-b/input.h\"\n" - "#include <lib-b/h-3.h>\n" - "#include <lib-a/h-1.h>\n" - "#include <lib-a/input.h>\n" - "#include <lib-a/h-3.h>\n", - "input.cc")); + verifyFormat("#include \"lib-b/input.h\"\n" + "\n" + "#include <lib-a/h-1.h>\n" + "#include <lib-a/h-3.h>\n" + "#include <lib-a/input.h>\n" + "\n" + "#include <lib-b/h-1.h>\n" + "#include <lib-b/h-3.h>\n" + "\n" + "#include <lib-c/h-1.h>\n" + "#include <lib-c/h-2.h>\n" + "#include <lib-c/h-3.h>\n", + sort("#include <lib-c/h-1.h>\n" + "#include <lib-c/h-2.h>\n" + "#include <lib-c/h-3.h>\n" + "#include <lib-b/h-1.h>\n" + "#include \"lib-b/input.h\"\n" + "#include <lib-b/h-3.h>\n" + "#include <lib-a/h-1.h>\n" + "#include <lib-a/input.h>\n" + "#include <lib-a/h-3.h>\n", + "input.cc")); } TEST_F(SortIncludesTest, MainIncludeCharAngleBracketAndRegroup) { @@ -1174,60 +1172,60 @@ TEST_F(SortIncludesTest, MainIncludeCharAngleBracketAndRegroup) { Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; Style.MainIncludeChar = tooling::IncludeStyle::MICD_AngleBracket; - EXPECT_EQ("#include <lib-a/input.h>\n" - "\n" - "#include <lib-a/h-1.h>\n" - "#include <lib-a/h-3.h>\n" - "\n" - "#include \"lib-b/input.h\"\n" - "#include <lib-b/h-1.h>\n" - "#include <lib-b/h-3.h>\n" - "\n" - "#include <lib-c/h-1.h>\n" - "#include <lib-c/h-2.h>\n" - "#include <lib-c/h-3.h>\n", - sort("#include <lib-c/h-1.h>\n" - "#include <lib-c/h-2.h>\n" - "#include <lib-c/h-3.h>\n" - "#include <lib-b/h-1.h>\n" - "#include \"lib-b/input.h\"\n" - "#include <lib-b/h-3.h>\n" - "#include <lib-a/h-1.h>\n" - "#include <lib-a/input.h>\n" - "#include <lib-a/h-3.h>\n", - "input.cc")); + verifyFormat("#include <lib-a/input.h>\n" + "\n" + "#include <lib-a/h-1.h>\n" + "#include <lib-a/h-3.h>\n" + "\n" + "#include \"lib-b/input.h\"\n" + "#include <lib-b/h-1.h>\n" + "#include <lib-b/h-3.h>\n" + "\n" + "#include <lib-c/h-1.h>\n" + "#include <lib-c/h-2.h>\n" + "#include <lib-c/h-3.h>\n", + sort("#include <lib-c/h-1.h>\n" + "#include <lib-c/h-2.h>\n" + "#include <lib-c/h-3.h>\n" + "#include <lib-b/h-1.h>\n" + "#include \"lib-b/input.h\"\n" + "#include <lib-b/h-3.h>\n" + "#include <lib-a/h-1.h>\n" + "#include <lib-a/input.h>\n" + "#include <lib-a/h-3.h>\n", + "input.cc")); } TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) { FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC); - EXPECT_EQ("#include <a.h>\n" - "#include <b.h>\n" - "#include \"a.h\"", - sort("#include <b.h>\n" - "#include <a.h>\n" - "#include \"a.h\"")); + verifyFormat("#include <a.h>\n" + "#include <b.h>\n" + "#include \"a.h\"", + sort("#include <b.h>\n" + "#include <a.h>\n" + "#include \"a.h\"")); } TEST_F(SortIncludesTest, DoNotTreatPrecompiledHeadersAsFirstBlock) { Style.IncludeBlocks = Style.IBS_Merge; - std::string Code = "#include \"d.h\"\r\n" - "#include \"b.h\"\r\n" - "#pragma hdrstop\r\n" - "\r\n" - "#include \"c.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"e.h\"\r\n"; - - std::string Expected = "#include \"b.h\"\r\n" - "#include \"d.h\"\r\n" - "#pragma hdrstop\r\n" - "\r\n" - "#include \"e.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"c.h\"\r\n"; - - EXPECT_EQ(Expected, sort(Code, "e.cpp", 2)); + StringRef Code = "#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + StringRef Expected = "#include \"b.h\"\r\n" + "#include \"d.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"e.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"c.h\"\r\n"; + + verifyFormat(Expected, sort(Code, "e.cpp", 2)); Code = "#include \"d.h\"\n" "#include \"b.h\"\n" @@ -1245,59 +1243,59 @@ TEST_F(SortIncludesTest, DoNotTreatPrecompiledHeadersAsFirstBlock) { "#include \"a.h\"\n" "#include \"c.h\"\n"; - EXPECT_EQ(Expected, sort(Code, "e.cpp", 2)); + verifyFormat(Expected, sort(Code, "e.cpp", 2)); } TEST_F(SortIncludesTest, skipUTF8ByteOrderMarkMerge) { Style.IncludeBlocks = Style.IBS_Merge; - std::string Code = "\xEF\xBB\xBF#include \"d.h\"\r\n" - "#include \"b.h\"\r\n" - "\r\n" - "#include \"c.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"e.h\"\r\n"; - - std::string Expected = "\xEF\xBB\xBF#include \"e.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"b.h\"\r\n" - "#include \"c.h\"\r\n" - "#include \"d.h\"\r\n"; - - EXPECT_EQ(Expected, sort(Code, "e.cpp", 1)); + StringRef Code = "\xEF\xBB\xBF#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + StringRef Expected = "\xEF\xBB\xBF#include \"e.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"b.h\"\r\n" + "#include \"c.h\"\r\n" + "#include \"d.h\"\r\n"; + + verifyFormat(Expected, sort(Code, "e.cpp", 1)); } TEST_F(SortIncludesTest, skipUTF8ByteOrderMarkPreserve) { Style.IncludeBlocks = Style.IBS_Preserve; - std::string Code = "\xEF\xBB\xBF#include \"d.h\"\r\n" - "#include \"b.h\"\r\n" - "\r\n" - "#include \"c.h\"\r\n" - "#include \"a.h\"\r\n" - "#include \"e.h\"\r\n"; - - std::string Expected = "\xEF\xBB\xBF#include \"b.h\"\r\n" - "#include \"d.h\"\r\n" - "\r\n" - "#include \"a.h\"\r\n" - "#include \"c.h\"\r\n" - "#include \"e.h\"\r\n"; - - EXPECT_EQ(Expected, sort(Code, "e.cpp", 2)); + StringRef Code = "\xEF\xBB\xBF#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + StringRef Expected = "\xEF\xBB\xBF#include \"b.h\"\r\n" + "#include \"d.h\"\r\n" + "\r\n" + "#include \"a.h\"\r\n" + "#include \"c.h\"\r\n" + "#include \"e.h\"\r\n"; + + verifyFormat(Expected, sort(Code, "e.cpp", 2)); } TEST_F(SortIncludesTest, MergeLines) { Style.IncludeBlocks = Style.IBS_Merge; - std::string Code = "#include \"c.h\"\r\n" - "#include \"b\\\r\n" - ".h\"\r\n" - "#include \"a.h\"\r\n"; + StringRef Code = "#include \"c.h\"\r\n" + "#include \"b\\\r\n" + ".h\"\r\n" + "#include \"a.h\"\r\n"; - std::string Expected = "#include \"a.h\"\r\n" - "#include \"b\\\r\n" - ".h\"\r\n" - "#include \"c.h\"\r\n"; + StringRef Expected = "#include \"a.h\"\r\n" + "#include \"b\\\r\n" + ".h\"\r\n" + "#include \"c.h\"\r\n"; - EXPECT_EQ(Expected, sort(Code, "a.cpp", 1)); + verifyFormat(Expected, sort(Code, "a.cpp", 1)); } TEST_F(SortIncludesTest, DisableFormatDisablesIncludeSorting) { @@ -1305,154 +1303,154 @@ TEST_F(SortIncludesTest, DisableFormatDisablesIncludeSorting) { "#include <b.h>\n"; StringRef Unsorted = "#include <b.h>\n" "#include <a.h>\n"; - EXPECT_EQ(Sorted, sort(Unsorted)); + verifyFormat(Sorted, sort(Unsorted)); FmtStyle.DisableFormat = true; - EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0)); + verifyFormat(Unsorted, sort(Unsorted, "input.cpp", 0)); } TEST_F(SortIncludesTest, DisableRawStringLiteralSorting) { - EXPECT_EQ("const char *t = R\"(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")\";", - sort("const char *t = R\"(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")\";", - "test.cxx", 0)); - EXPECT_EQ("const char *t = R\"x(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")x\";", - sort("const char *t = R\"x(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")x\";", - "test.cxx", 0)); - EXPECT_EQ("const char *t = R\"xyz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")xyz\";", - sort("const char *t = R\"xyz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")xyz\";", - "test.cxx", 0)); - - EXPECT_EQ("#include <a.h>\n" - "#include <b.h>\n" - "const char *t = R\"(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")\";\n" - "#include <c.h>\n" - "#include <d.h>\n" - "const char *t = R\"x(\n" - "#include <f.h>\n" - "#include <e.h>\n" - ")x\";\n" - "#include <g.h>\n" - "#include <h.h>\n" - "const char *t = R\"xyz(\n" - "#include <j.h>\n" - "#include <i.h>\n" - ")xyz\";\n" - "#include <k.h>\n" - "#include <l.h>", - sort("#include <b.h>\n" - "#include <a.h>\n" - "const char *t = R\"(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")\";\n" - "#include <d.h>\n" - "#include <c.h>\n" - "const char *t = R\"x(\n" - "#include <f.h>\n" - "#include <e.h>\n" - ")x\";\n" - "#include <h.h>\n" - "#include <g.h>\n" - "const char *t = R\"xyz(\n" - "#include <j.h>\n" - "#include <i.h>\n" - ")xyz\";\n" - "#include <l.h>\n" - "#include <k.h>", - "test.cc", 4)); - - EXPECT_EQ("const char *t = R\"AMZ029amz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AMZ029amz\";", - sort("const char *t = R\"AMZ029amz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AMZ029amz\";", - "test.cxx", 0)); - - EXPECT_EQ("const char *t = R\"-AMZ029amz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")-AMZ029amz\";", - sort("const char *t = R\"-AMZ029amz(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")-AMZ029amz\";", - "test.cxx", 0)); - - EXPECT_EQ("const char *t = R\"AMZ029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AMZ029amz-\";", - sort("const char *t = R\"AMZ029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AMZ029amz-\";", - "test.cxx", 0)); - - EXPECT_EQ("const char *t = R\"AM|029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM|029amz-\";", - sort("const char *t = R\"AM|029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM|029amz-\";", - "test.cxx", 0)); - - EXPECT_EQ("const char *t = R\"AM[029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM[029amz-\";", - sort("const char *t = R\"AM[029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM[029amz-\";", - "test.cxx", 0)); - - EXPECT_EQ("const char *t = R\"AM]029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM]029amz-\";", - sort("const char *t = R\"AM]029amz-(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")AM]029amz-\";", - "test.cxx", 0)); + verifyFormat("const char *t = R\"(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")\";", + sort("const char *t = R\"(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")\";", + "test.cxx", 0)); + verifyFormat("const char *t = R\"x(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")x\";", + sort("const char *t = R\"x(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")x\";", + "test.cxx", 0)); + verifyFormat("const char *t = R\"xyz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")xyz\";", + sort("const char *t = R\"xyz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")xyz\";", + "test.cxx", 0)); + + verifyFormat("#include <a.h>\n" + "#include <b.h>\n" + "const char *t = R\"(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")\";\n" + "#include <c.h>\n" + "#include <d.h>\n" + "const char *t = R\"x(\n" + "#include <f.h>\n" + "#include <e.h>\n" + ")x\";\n" + "#include <g.h>\n" + "#include <h.h>\n" + "const char *t = R\"xyz(\n" + "#include <j.h>\n" + "#include <i.h>\n" + ")xyz\";\n" + "#include <k.h>\n" + "#include <l.h>", + sort("#include <b.h>\n" + "#include <a.h>\n" + "const char *t = R\"(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")\";\n" + "#include <d.h>\n" + "#include <c.h>\n" + "const char *t = R\"x(\n" + "#include <f.h>\n" + "#include <e.h>\n" + ")x\";\n" + "#include <h.h>\n" + "#include <g.h>\n" + "const char *t = R\"xyz(\n" + "#include <j.h>\n" + "#include <i.h>\n" + ")xyz\";\n" + "#include <l.h>\n" + "#include <k.h>", + "test.cc", 4)); + + verifyFormat("const char *t = R\"AMZ029amz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AMZ029amz\";", + sort("const char *t = R\"AMZ029amz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AMZ029amz\";", + "test.cxx", 0)); + + verifyFormat("const char *t = R\"-AMZ029amz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")-AMZ029amz\";", + sort("const char *t = R\"-AMZ029amz(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")-AMZ029amz\";", + "test.cxx", 0)); + + verifyFormat("const char *t = R\"AMZ029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AMZ029amz-\";", + sort("const char *t = R\"AMZ029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AMZ029amz-\";", + "test.cxx", 0)); + + verifyFormat("const char *t = R\"AM|029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM|029amz-\";", + sort("const char *t = R\"AM|029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM|029amz-\";", + "test.cxx", 0)); + + verifyFormat("const char *t = R\"AM[029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM[029amz-\";", + sort("const char *t = R\"AM[029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM[029amz-\";", + "test.cxx", 0)); + + verifyFormat("const char *t = R\"AM]029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM]029amz-\";", + sort("const char *t = R\"AM]029amz-(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")AM]029amz-\";", + "test.cxx", 0)); #define X "AMZ029amz{}+!%*=_:;',.<>|/?#~-$" - EXPECT_EQ("const char *t = R\"" X "(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")" X "\";", - sort("const char *t = R\"" X "(\n" - "#include <b.h>\n" - "#include <a.h>\n" - ")" X "\";", - "test.cxx", 0)); + verifyFormat("const char *t = R\"" X "(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")" X "\";", + sort("const char *t = R\"" X "(\n" + "#include <b.h>\n" + "#include <a.h>\n" + ")" X "\";", + "test.cxx", 0)); #undef X } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits