diff options
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e6ba2230ac6d1..9b833a96f16ae 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -30,24 +30,25 @@ FormatStyle getGoogleStyle() { return getGoogleStyle(FormatStyle::LK_Cpp); } class FormatTest : public ::testing::Test { protected: - enum IncompleteCheck { - IC_ExpectComplete, - IC_ExpectIncomplete, - IC_DoNotCheck + enum StatusCheck { + SC_ExpectComplete, + SC_ExpectIncomplete, + SC_DoNotCheck }; std::string format(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle(), - IncompleteCheck CheckIncomplete = IC_ExpectComplete) { + StatusCheck CheckComplete = SC_ExpectComplete) { DEBUG(llvm::errs() << "---\n"); DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size())); - bool IncompleteFormat = false; + FormattingAttemptStatus Status; tooling::Replacements Replaces = - reformat(Style, Code, Ranges, "<stdin>", &IncompleteFormat); - if (CheckIncomplete != IC_DoNotCheck) { - bool ExpectedIncompleteFormat = CheckIncomplete == IC_ExpectIncomplete; - EXPECT_EQ(ExpectedIncompleteFormat, IncompleteFormat) << Code << "\n\n"; + reformat(Style, Code, Ranges, "<stdin>", &Status); + if (CheckComplete != SC_DoNotCheck) { + bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete; + EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete) + << Code << "\n\n"; } ReplacementCount = Replaces.size(); auto Result = applyAllReplacements(Code, Replaces); @@ -83,7 +84,7 @@ protected: void verifyIncompleteFormat(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) { EXPECT_EQ(Code.str(), - format(test::messUp(Code), Style, IC_ExpectIncomplete)); + format(test::messUp(Code), Style, SC_ExpectIncomplete)); } void verifyGoogleFormat(llvm::StringRef Code) { @@ -98,7 +99,7 @@ protected: /// \brief Verify that clang-format does not crash on the given input. void verifyNoCrash(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) { - format(Code, Style, IC_DoNotCheck); + format(Code, Style, SC_DoNotCheck); } int ReplacementCount; @@ -5220,6 +5221,12 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }"); verifyFormat("int x = f(&h)();"); verifyFormat("returnsFunction(¶m1, ¶m2)(param);"); + verifyFormat("std::function<\n" + " LooooooooooongTemplatedType<\n" + " SomeType>*(\n" + " LooooooooooooooooongType type)>\n" + " function;", + getGoogleStyleWithColumns(40)); } TEST_F(FormatTest, FormatsPointersToArrayTypes) { @@ -6189,7 +6196,7 @@ TEST_F(FormatTest, SkipsDeeplyNestedLines) { // Deeply nested part is untouched, rest is formatted. EXPECT_EQ(std::string("int i;\n") + Code + "int j;\n", format(std::string("int i;\n") + Code + "int j;\n", - getLLVMStyle(), IC_ExpectIncomplete)); + getLLVMStyle(), SC_ExpectIncomplete)); } //===----------------------------------------------------------------------===// |