From 68b03049e09824094b8ff07280b8240ab438167d Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Mon, 14 Apr 2014 09:14:11 +0000 Subject: Format code around VCS conflict markers. Now correctly formats: { int a; void f() { callme(some(parameter1, <<<<<<< text by the vcs parameter2), ||||||| text by the vcs parameter2), parameter3, ======= text by the vcs parameter2, parameter3), >>>>>>> text by the vcs otherparameter); } } llvm-svn: 206157 --- clang/unittests/Format/FormatTest.cpp | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'clang/unittests/Format/FormatTest.cpp') diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 382276abb60..fb33bd685be 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8402,5 +8402,97 @@ TEST_F(FormatTest, HandleUnbalancedImplicitBracesAcrossPPBranches) { EXPECT_EQ(code, format(code)); } +TEST_F(FormatTest, HandleConflictMarkers) { + // Git/SVN conflict markers. + EXPECT_EQ("int a;\n" + "void f() {\n" + " callme(some(parameter1,\n" + "<<<<<<< text by the vcs\n" + " parameter2),\n" + "||||||| text by the vcs\n" + " parameter2),\n" + " parameter3,\n" + "======= text by the vcs\n" + " parameter2, parameter3),\n" + ">>>>>>> text by the vcs\n" + " otherparameter);\n", + format("int a;\n" + "void f() {\n" + " callme(some(parameter1,\n" + "<<<<<<< text by the vcs\n" + " parameter2),\n" + "||||||| text by the vcs\n" + " parameter2),\n" + " parameter3,\n" + "======= text by the vcs\n" + " parameter2,\n" + " parameter3),\n" + ">>>>>>> text by the vcs\n" + " otherparameter);\n")); + + // Perforce markers. + EXPECT_EQ("void f() {\n" + " function(\n" + ">>>> text by the vcs\n" + " parameter,\n" + "==== text by the vcs\n" + " parameter,\n" + "==== text by the vcs\n" + " parameter,\n" + "<<<< text by the vcs\n" + " parameter);\n", + format("void f() {\n" + " function(\n" + ">>>> text by the vcs\n" + " parameter,\n" + "==== text by the vcs\n" + " parameter,\n" + "==== text by the vcs\n" + " parameter,\n" + "<<<< text by the vcs\n" + " parameter);\n")); + + EXPECT_EQ("<<<<<<<\n" + "|||||||\n" + "=======\n" + ">>>>>>>", + format("<<<<<<<\n" + "|||||||\n" + "=======\n" + ">>>>>>>")); + + EXPECT_EQ("<<<<<<<\n" + "|||||||\n" + "int i;\n" + "=======\n" + ">>>>>>>", + format("<<<<<<<\n" + "|||||||\n" + "int i;\n" + "=======\n" + ">>>>>>>")); + + // FIXME: Handle parsing of macros around conflict markers correctly: + EXPECT_EQ("#define Macro \\\n" + "<<<<<<<\n" + "Something \\\n" + "|||||||\n" + "Else \\\n" + "=======\n" + "Other \\\n" + ">>>>>>>\n" + "End int i;\n", + format("#define Macro \\\n" + "<<<<<<<\n" + " Something \\\n" + "|||||||\n" + " Else \\\n" + "=======\n" + " Other \\\n" + ">>>>>>>\n" + " End\n" + "int i;\n")); +} + } // end namespace tooling } // end namespace clang -- cgit v1.2.3