Skip to content

Commit ddbe6c4

Browse files
authored
[clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334)
1 parent 22a2d74 commit ddbe6c4

File tree

3 files changed

+45
-61
lines changed

3 files changed

+45
-61
lines changed

clang/unittests/Format/FormatTestBase.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ class FormatTestBase : public testing::Test {
6161
return *Result;
6262
}
6363

64-
FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
64+
FormatStyle getStyleWithColumns(FormatStyle Style,
65+
unsigned ColumnLimit) const {
6566
Style.ColumnLimit = ColumnLimit;
6667
return Style;
6768
}
6869

69-
FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
70+
FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) const {
7071
return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
7172
}
7273

73-
FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) {
74+
FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) const {
7475
return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
7576
}
7677

77-
FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) {
78-
FormatStyle Style = getGoogleStyle(FormatStyle::FormatStyle::LK_TextProto);
79-
Style.ColumnLimit = ColumnLimit;
80-
return Style;
78+
FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) const {
79+
return getStyleWithColumns(getGoogleStyle(FormatStyle::LK_TextProto),
80+
ColumnLimit);
8181
}
8282

8383
bool _verifyFormat(const char *File, int Line, StringRef Expected,

clang/unittests/Format/FormatTestProto.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
516516
}
517517

518518
TEST_F(FormatTestProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
519-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
520-
Style.ColumnLimit = 60;
521519
// The column limit allows for the keys submessage to be put on 1 line, but we
522520
// break it since it contains a submessage an another entry.
523521
verifyFormat("option (MyProto.options) = {\n"

clang/unittests/Format/FormatTestTextProto.cpp

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ namespace {
1818
class FormatTestTextProto : public FormatTestBase {
1919
protected:
2020
virtual FormatStyle getDefaultStyle() const override {
21-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
22-
Style.ColumnLimit = 60; // To make writing tests easier.
23-
return Style;
21+
return getTextProtoStyleWithColumns(60);
2422
}
2523
};
2624

@@ -126,7 +124,8 @@ TEST_F(FormatTestTextProto, ImplicitStringLiteralConcatenation) {
126124
" 'bbbbb'");
127125
verifyFormat("field_a: \"aaaaa\"\n"
128126
" \"bbbbb\"");
129-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
127+
128+
auto Style = getDefaultStyle();
130129
Style.AlwaysBreakBeforeMultilineStrings = true;
131130
verifyFormat("field_a:\n"
132131
" 'aaaaa'\n"
@@ -359,46 +358,40 @@ TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
359358
}
360359

361360
TEST_F(FormatTestTextProto, UnderstandsHashComments) {
362-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
363-
Style.ColumnLimit = 60; // To make writing tests easier.
364-
EXPECT_EQ("aaa: 100\n"
365-
"## this is a double-hash comment.\n"
366-
"bb: 100\n"
367-
"## another double-hash comment.\n"
368-
"### a triple-hash comment\n"
369-
"cc: 200\n"
370-
"### another triple-hash comment\n"
371-
"#### a quadriple-hash comment\n"
372-
"dd: 100\n"
373-
"#### another quadriple-hash comment",
374-
format("aaa: 100\n"
375-
"##this is a double-hash comment.\n"
376-
"bb: 100\n"
377-
"## another double-hash comment.\n"
378-
"###a triple-hash comment\n"
379-
"cc: 200\n"
380-
"### another triple-hash comment\n"
381-
"####a quadriple-hash comment\n"
382-
"dd: 100\n"
383-
"#### another quadriple-hash comment",
384-
Style));
361+
auto Style = getDefaultStyle();
362+
363+
verifyFormat("aaa: 100\n"
364+
"## this is a double-hash comment.\n"
365+
"bb: 100\n"
366+
"## another double-hash comment.\n"
367+
"### a triple-hash comment\n"
368+
"cc: 200\n"
369+
"### another triple-hash comment\n"
370+
"#### a quadriple-hash comment\n"
371+
"dd: 100\n"
372+
"#### another quadriple-hash comment",
373+
"aaa: 100\n"
374+
"##this is a double-hash comment.\n"
375+
"bb: 100\n"
376+
"## another double-hash comment.\n"
377+
"###a triple-hash comment\n"
378+
"cc: 200\n"
379+
"### another triple-hash comment\n"
380+
"####a quadriple-hash comment\n"
381+
"dd: 100\n"
382+
"#### another quadriple-hash comment",
383+
Style);
385384

386385
// Ensure we support a common pattern for naming sections.
387-
EXPECT_EQ("##############\n"
388-
"# section name\n"
389-
"##############",
390-
format("##############\n"
391-
"# section name\n"
392-
"##############",
393-
Style));
394-
395-
EXPECT_EQ("///////////////\n"
396-
"// section name\n"
397-
"///////////////",
398-
format("///////////////\n"
399-
"// section name\n"
400-
"///////////////",
401-
Style));
386+
verifyFormat("##############\n"
387+
"# section name\n"
388+
"##############",
389+
Style);
390+
391+
verifyFormat("///////////////\n"
392+
"// section name\n"
393+
"///////////////",
394+
Style);
402395
}
403396

404397
TEST_F(FormatTestTextProto, FormatsExtensions) {
@@ -519,8 +512,8 @@ TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
519512
" ]\n"
520513
"}\n"
521514
"key: value");
522-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
523-
Style.ColumnLimit = 60; // To make writing tests easier.
515+
516+
auto Style = getDefaultStyle();
524517
Style.Cpp11BracedListStyle = true;
525518
verifyFormat("keys: [1]", Style);
526519
}
@@ -544,7 +537,6 @@ TEST_F(FormatTestTextProto, BreaksConsecutiveStringLiterals) {
544537
}
545538

546539
TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) {
547-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
548540
verifyFormat("pppppppppp: {\n"
549541
" ssssss: \"http://example.com/blahblahblah\"\n"
550542
" ppppppp: \"sssss/MMMMMMMMMMMM\"\n"
@@ -556,12 +548,10 @@ TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) {
556548
" key: value\n"
557549
" }\n"
558550
"}",
559-
Style);
551+
getGoogleStyle(FormatStyle::LK_TextProto));
560552
}
561553

562554
TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) {
563-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
564-
Style.ColumnLimit = 60;
565555
verifyFormat("keys: [\n"
566556
" data: { item: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }\n"
567557
"]");
@@ -571,10 +561,6 @@ TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) {
571561
}
572562

573563
TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
574-
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
575-
Style.ColumnLimit = 60;
576-
// The column limit allows for the keys submessage to be put on 1 line, but we
577-
// break it since it contains a submessage an another entry.
578564
verifyFormat("key: valueeeeeeee\n"
579565
"keys: {\n"
580566
" item: 'aaaaaaaaaaaaaaaa'\n"

0 commit comments

Comments
 (0)