[clang] ddbe6c4 - [clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 17 21:15:47 PDT 2024
Author: Owen Pan
Date: 2024-09-17T21:15:44-07:00
New Revision: ddbe6c412bab3fe7a3ffaf6f42c49849a518b4c6
URL: https://github.com/llvm/llvm-project/commit/ddbe6c412bab3fe7a3ffaf6f42c49849a518b4c6
DIFF: https://github.com/llvm/llvm-project/commit/ddbe6c412bab3fe7a3ffaf6f42c49849a518b4c6.diff
LOG: [clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334)
Added:
Modified:
clang/unittests/Format/FormatTestBase.h
clang/unittests/Format/FormatTestProto.cpp
clang/unittests/Format/FormatTestTextProto.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Format/FormatTestBase.h b/clang/unittests/Format/FormatTestBase.h
index 33110ca5d9edfd..9d9472964fd3b4 100644
--- a/clang/unittests/Format/FormatTestBase.h
+++ b/clang/unittests/Format/FormatTestBase.h
@@ -61,23 +61,23 @@ class FormatTestBase : public testing::Test {
return *Result;
}
- FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+ FormatStyle getStyleWithColumns(FormatStyle Style,
+ unsigned ColumnLimit) const {
Style.ColumnLimit = ColumnLimit;
return Style;
}
- FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+ FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) const {
return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
}
- FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) {
+ FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) const {
return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
}
- FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) {
- FormatStyle Style = getGoogleStyle(FormatStyle::FormatStyle::LK_TextProto);
- Style.ColumnLimit = ColumnLimit;
- return Style;
+ FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) const {
+ return getStyleWithColumns(getGoogleStyle(FormatStyle::LK_TextProto),
+ ColumnLimit);
}
bool _verifyFormat(const char *File, int Line, StringRef Expected,
diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp
index 5adb532ae4a412..30ce57c545ec76 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -516,8 +516,6 @@ TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
}
TEST_F(FormatTestProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60;
// The column limit allows for the keys submessage to be put on 1 line, but we
// break it since it contains a submessage an another entry.
verifyFormat("option (MyProto.options) = {\n"
diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp
index 23f46202a34637..fd65c9a58db5d8 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -18,9 +18,7 @@ namespace {
class FormatTestTextProto : public FormatTestBase {
protected:
virtual FormatStyle getDefaultStyle() const override {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60; // To make writing tests easier.
- return Style;
+ return getTextProtoStyleWithColumns(60);
}
};
@@ -126,7 +124,8 @@ TEST_F(FormatTestTextProto, ImplicitStringLiteralConcatenation) {
" 'bbbbb'");
verifyFormat("field_a: \"aaaaa\"\n"
" \"bbbbb\"");
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+
+ auto Style = getDefaultStyle();
Style.AlwaysBreakBeforeMultilineStrings = true;
verifyFormat("field_a:\n"
" 'aaaaa'\n"
@@ -359,46 +358,40 @@ TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
}
TEST_F(FormatTestTextProto, UnderstandsHashComments) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60; // To make writing tests easier.
- EXPECT_EQ("aaa: 100\n"
- "## this is a double-hash comment.\n"
- "bb: 100\n"
- "## another double-hash comment.\n"
- "### a triple-hash comment\n"
- "cc: 200\n"
- "### another triple-hash comment\n"
- "#### a quadriple-hash comment\n"
- "dd: 100\n"
- "#### another quadriple-hash comment",
- format("aaa: 100\n"
- "##this is a double-hash comment.\n"
- "bb: 100\n"
- "## another double-hash comment.\n"
- "###a triple-hash comment\n"
- "cc: 200\n"
- "### another triple-hash comment\n"
- "####a quadriple-hash comment\n"
- "dd: 100\n"
- "#### another quadriple-hash comment",
- Style));
+ auto Style = getDefaultStyle();
+
+ verifyFormat("aaa: 100\n"
+ "## this is a double-hash comment.\n"
+ "bb: 100\n"
+ "## another double-hash comment.\n"
+ "### a triple-hash comment\n"
+ "cc: 200\n"
+ "### another triple-hash comment\n"
+ "#### a quadriple-hash comment\n"
+ "dd: 100\n"
+ "#### another quadriple-hash comment",
+ "aaa: 100\n"
+ "##this is a double-hash comment.\n"
+ "bb: 100\n"
+ "## another double-hash comment.\n"
+ "###a triple-hash comment\n"
+ "cc: 200\n"
+ "### another triple-hash comment\n"
+ "####a quadriple-hash comment\n"
+ "dd: 100\n"
+ "#### another quadriple-hash comment",
+ Style);
// Ensure we support a common pattern for naming sections.
- EXPECT_EQ("##############\n"
- "# section name\n"
- "##############",
- format("##############\n"
- "# section name\n"
- "##############",
- Style));
-
- EXPECT_EQ("///////////////\n"
- "// section name\n"
- "///////////////",
- format("///////////////\n"
- "// section name\n"
- "///////////////",
- Style));
+ verifyFormat("##############\n"
+ "# section name\n"
+ "##############",
+ Style);
+
+ verifyFormat("///////////////\n"
+ "// section name\n"
+ "///////////////",
+ Style);
}
TEST_F(FormatTestTextProto, FormatsExtensions) {
@@ -519,8 +512,8 @@ TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
" ]\n"
"}\n"
"key: value");
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60; // To make writing tests easier.
+
+ auto Style = getDefaultStyle();
Style.Cpp11BracedListStyle = true;
verifyFormat("keys: [1]", Style);
}
@@ -544,7 +537,6 @@ TEST_F(FormatTestTextProto, BreaksConsecutiveStringLiterals) {
}
TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
verifyFormat("pppppppppp: {\n"
" ssssss: \"http://example.com/blahblahblah\"\n"
" ppppppp: \"sssss/MMMMMMMMMMMM\"\n"
@@ -556,12 +548,10 @@ TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) {
" key: value\n"
" }\n"
"}",
- Style);
+ getGoogleStyle(FormatStyle::LK_TextProto));
}
TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60;
verifyFormat("keys: [\n"
" data: { item: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }\n"
"]");
@@ -571,10 +561,6 @@ TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) {
}
TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
- FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
- Style.ColumnLimit = 60;
- // The column limit allows for the keys submessage to be put on 1 line, but we
- // break it since it contains a submessage an another entry.
verifyFormat("key: valueeeeeeee\n"
"keys: {\n"
" item: 'aaaaaaaaaaaaaaaa'\n"
More information about the cfe-commits
mailing list