aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestComments.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2023-03-01 12:33:19 +0000
committerManuel Klimek <klimek@google.com>2023-03-01 12:36:07 +0000
commitf8d10d5ac9ab4b45b388c74357fc82fb96562e66 (patch)
treeefe0af1da0093ce6ced6f26bc80fdae7b0d77425 /clang/unittests/Format/FormatTestComments.cpp
parentb06e5ad8a659c00448c2e295595bed9c8e2d0853 (diff)
downloadllvm-f8d10d5ac9ab4b45b388c74357fc82fb96562e66.zip
llvm-f8d10d5ac9ab4b45b388c74357fc82fb96562e66.tar.gz
llvm-f8d10d5ac9ab4b45b388c74357fc82fb96562e66.tar.bz2
[clang-format][NFC] Refactor formatting unit tests.
Pull out common base class for formatting unit tests, removing duplicate code that accumulated over the years. Pull out macro expansion test into its own test file.
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp70
1 files changed, 5 insertions, 65 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 3336ee4..03d093b 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -6,79 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Format/Format.h"
+#include "FormatTestBase.h"
-#include "../Tooling/ReplacementTest.h"
-#include "FormatTestUtils.h"
-
-#include "llvm/Support/Debug.h"
-#include "gtest/gtest.h"
-
-#define DEBUG_TYPE "format-test"
-
-using clang::tooling::ReplacementTest;
+#define DEBUG_TYPE "format-test-comments"
namespace clang {
namespace format {
+namespace test {
namespace {
FormatStyle getGoogleStyle() { return getGoogleStyle(FormatStyle::LK_Cpp); }
-class FormatTestComments : public ::testing::Test {
-protected:
- enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
-
- std::string format(llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle(),
- StatusCheck CheckComplete = SC_ExpectComplete) {
- LLVM_DEBUG(llvm::errs() << "---\n");
- LLVM_DEBUG(llvm::errs() << Code << "\n\n");
- std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size()));
- FormattingAttemptStatus Status;
- tooling::Replacements Replaces =
- 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);
- EXPECT_TRUE(static_cast<bool>(Result));
- LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
- return *Result;
- }
-
- FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
- FormatStyle Style = getLLVMStyle();
- Style.ColumnLimit = ColumnLimit;
- return Style;
- }
-
- FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) {
- FormatStyle Style = getGoogleStyle(FormatStyle::FormatStyle::LK_TextProto);
- Style.ColumnLimit = ColumnLimit;
- return Style;
- }
-
- void verifyFormat(llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle()) {
- EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
- EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
- }
-
- void verifyGoogleFormat(llvm::StringRef Code) {
- verifyFormat(Code, getGoogleStyle());
- }
-
- /// \brief Verify that clang-format does not crash on the given input.
- void verifyNoCrash(llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle()) {
- format(Code, Style, SC_DoNotCheck);
- }
-
- int ReplacementCount;
-};
+class FormatTestComments : public FormatTestBase {};
//===----------------------------------------------------------------------===//
// Tests for comments.
@@ -4376,5 +4315,6 @@ TEST_F(FormatTestComments, SplitCommentIntroducers) {
}
} // end namespace
+} // namespace test
} // end namespace format
} // end namespace clang