Changeset View
Changeset View
Standalone View
Standalone View
clang/unittests/Format/FormatTestComments.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | protected: | ||||
} | } | ||||
void verifyFormat(llvm::StringRef Code, | void verifyFormat(llvm::StringRef Code, | ||||
const FormatStyle &Style = getLLVMStyle()) { | const FormatStyle &Style = getLLVMStyle()) { | ||||
EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; | EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; | ||||
EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); | EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); | ||||
} | } | ||||
void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code, | |||||
const FormatStyle &Style = getLLVMStyle()) { | |||||
EXPECT_EQ(Expected.str(), format(Expected, Style)) | |||||
<< "Expected code is not stable"; | |||||
EXPECT_EQ(Expected.str(), format(test::messUp(Code), Style)); | |||||
} | |||||
void verifyFormatWithoutMessUp(llvm::StringRef Expected, llvm::StringRef Code, | |||||
const FormatStyle &Style = getLLVMStyle()) { | |||||
EXPECT_EQ(Expected.str(), format(Expected, Style)) | |||||
<< "Expected code is not stable"; | |||||
EXPECT_EQ(Expected.str(), format(Code, Style)); | |||||
} | |||||
owenpan: Was this already done in D138402? | |||||
HazardyKnusperkeksAuthorUnsubmitted The first yes, the second no. I did just not update this diff, my commit is updated. HazardyKnusperkeks: The first yes, the second no. I did just not update this diff, my commit is updated. | |||||
void verifyGoogleFormat(llvm::StringRef Code) { | void verifyGoogleFormat(llvm::StringRef Code) { | ||||
verifyFormat(Code, getGoogleStyle()); | verifyFormat(Code, getGoogleStyle()); | ||||
} | } | ||||
/// \brief Verify that clang-format does not crash on the given input. | /// \brief Verify that clang-format does not crash on the given input. | ||||
void verifyNoCrash(llvm::StringRef Code, | void verifyNoCrash(llvm::StringRef Code, | ||||
const FormatStyle &Style = getLLVMStyle()) { | const FormatStyle &Style = getLLVMStyle()) { | ||||
format(Code, Style, SC_DoNotCheck); | format(Code, Style, SC_DoNotCheck); | ||||
▲ Show 20 Lines • Show All 2,992 Lines • ▼ Show 20 Lines | EXPECT_EQ("int foo = 12345; // comment\n" | ||||
" // comment which is\n" | " // comment which is\n" | ||||
" // wrapped arround.\n", | " // wrapped arround.\n", | ||||
format("int foo = 12345; // comment\n" | format("int foo = 12345; // comment\n" | ||||
"int bar = 1234; // This is a very long comment\n" | "int bar = 1234; // This is a very long comment\n" | ||||
" // which is wrapped arround.\n", | " // which is wrapped arround.\n", | ||||
Style)); | Style)); | ||||
} | } | ||||
TEST_F(FormatTestComments, DontAlignNamespaceComments) { | |||||
FormatStyle Style = getLLVMStyle(); | |||||
owenpanUnsubmitted Not Done ReplyInline ActionsShould we add tests for FixNamespaceComments: false? owenpan: Should we add tests for `FixNamespaceComments: false`? | |||||
HazardyKnusperkeksAuthorUnsubmitted Will do. HazardyKnusperkeks: Will do. | |||||
Style.NamespaceIndentation = FormatStyle::NI_All; | |||||
Style.NamespaceMacros.push_back("TESTSUITE"); | |||||
Style.ShortNamespaceLines = 0; | |||||
llvm::StringRef Input = "namespace A {\n" | |||||
" TESTSUITE(B) {\n" | |||||
" namespace C {\n" | |||||
" namespace D {} // namespace D\n" | |||||
" std::string Foo = Bar; // Comment\n" | |||||
" } // namespace C\n" | |||||
" }\n" | |||||
"} // NaMeSpAcE A"; | |||||
EXPECT_EQ(Style.AlignTrailingComments.Kind, FormatStyle::TCAS_Always); | |||||
verifyFormat("namespace A {\n" | |||||
" TESTSUITE(B) {\n" | |||||
" namespace C {\n" | |||||
" namespace D {} // namespace D\n" | |||||
" std::string Foo = Bar; // Comment\n" | |||||
" } // namespace C\n" | |||||
" } // TESTSUITE(B)\n" | |||||
"} // NaMeSpAcE A", | |||||
Input, Style); | |||||
Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Never; | |||||
verifyFormat("namespace A {\n" | |||||
" TESTSUITE(B) {\n" | |||||
" namespace C {\n" | |||||
" namespace D {} // namespace D\n" | |||||
" std::string Foo = Bar; // Comment\n" | |||||
" } // namespace C\n" | |||||
" } // TESTSUITE(B)\n" | |||||
"} // NaMeSpAcE A", | |||||
Input, Style); | |||||
Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Leave; | |||||
verifyFormatWithoutMessUp("namespace A {\n" | |||||
" TESTSUITE(B) {\n" | |||||
" namespace C {\n" | |||||
" namespace D {} // namespace D\n" | |||||
" std::string Foo = Bar; // Comment\n" | |||||
" } // namespace C\n" | |||||
" }// TESTSUITE(B)\n" | |||||
owenpanUnsubmitted Not Done ReplyInline ActionsWhy would TCAS_Leave result in no space before the trailing comment? owenpan: Why would `TCAS_Leave` result in no space before the trailing comment? | |||||
HazardyKnusperkeksAuthorUnsubmitted It just did, didn't investigate or decide. HazardyKnusperkeks: It just did, didn't investigate or decide.
Most likely clang-format just adds it there and the… | |||||
"} // NaMeSpAcE A", | |||||
Input, Style); | |||||
} | |||||
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) { | TEST_F(FormatTestComments, AlignsBlockCommentDecorations) { | ||||
EXPECT_EQ("/*\n" | EXPECT_EQ("/*\n" | ||||
" */", | " */", | ||||
format("/*\n" | format("/*\n" | ||||
"*/", | "*/", | ||||
getLLVMStyle())); | getLLVMStyle())); | ||||
EXPECT_EQ("/*\n" | EXPECT_EQ("/*\n" | ||||
" */", | " */", | ||||
▲ Show 20 Lines • Show All 1,240 Lines • Show Last 20 Lines |
Was this already done in D138402?