Skip to content

Commit b28e879

Browse files
authored
[clang-format] Simplify ConfigParseTest for int/unsigned options (#124704)
Also add a number of missing tests for unsigned options.
1 parent 9ec4f47 commit b28e879

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ TEST(ConfigParseTest, GetsCorrectBasedOnStyle) {
144144
EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value()); \
145145
EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
146146

147+
#define CHECK_PARSE_INT(FIELD) CHECK_PARSE(#FIELD ": -1234", FIELD, -1234)
148+
149+
#define CHECK_PARSE_UNSIGNED(FIELD) CHECK_PARSE(#FIELD ": 1234", FIELD, 1234u)
150+
147151
#define CHECK_PARSE_LIST(FIELD) \
148152
CHECK_PARSE(#FIELD ": [foo]", FIELD, std::vector<std::string>{"foo"})
149153

@@ -254,35 +258,40 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
254258

255259
#undef CHECK_PARSE_BOOL
256260

261+
TEST(ConfigParseTest, ParsesConfigurationIntegers) {
262+
FormatStyle Style = {};
263+
Style.Language = FormatStyle::LK_Cpp;
264+
265+
CHECK_PARSE_INT(AccessModifierOffset);
266+
CHECK_PARSE_INT(PPIndentWidth);
267+
268+
CHECK_PARSE_UNSIGNED(BracedInitializerIndentWidth);
269+
CHECK_PARSE_UNSIGNED(ColumnLimit);
270+
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
271+
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
272+
CHECK_PARSE_UNSIGNED(IndentWidth);
273+
CHECK_PARSE_UNSIGNED(MaxEmptyLinesToKeep);
274+
CHECK_PARSE_UNSIGNED(ObjCBlockIndentWidth);
275+
CHECK_PARSE_UNSIGNED(PenaltyBreakAssignment);
276+
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeFirstCallParameter);
277+
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeMemberAccess);
278+
CHECK_PARSE_UNSIGNED(PenaltyBreakComment);
279+
CHECK_PARSE_UNSIGNED(PenaltyBreakFirstLessLess);
280+
CHECK_PARSE_UNSIGNED(PenaltyBreakOpenParenthesis);
281+
CHECK_PARSE_UNSIGNED(PenaltyBreakScopeResolution);
282+
CHECK_PARSE_UNSIGNED(PenaltyBreakString);
283+
CHECK_PARSE_UNSIGNED(PenaltyBreakTemplateDeclaration);
284+
CHECK_PARSE_UNSIGNED(PenaltyExcessCharacter);
285+
CHECK_PARSE_UNSIGNED(PenaltyIndentedWhitespace);
286+
CHECK_PARSE_UNSIGNED(PenaltyReturnTypeOnItsOwnLine);
287+
CHECK_PARSE_UNSIGNED(ShortNamespaceLines);
288+
CHECK_PARSE_UNSIGNED(SpacesBeforeTrailingComments);
289+
CHECK_PARSE_UNSIGNED(TabWidth);
290+
}
291+
257292
TEST(ConfigParseTest, ParsesConfiguration) {
258293
FormatStyle Style = {};
259294
Style.Language = FormatStyle::LK_Cpp;
260-
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);
261-
CHECK_PARSE("ConstructorInitializerIndentWidth: 1234",
262-
ConstructorInitializerIndentWidth, 1234u);
263-
CHECK_PARSE("ObjCBlockIndentWidth: 1234", ObjCBlockIndentWidth, 1234u);
264-
CHECK_PARSE("ColumnLimit: 1234", ColumnLimit, 1234u);
265-
CHECK_PARSE("MaxEmptyLinesToKeep: 1234", MaxEmptyLinesToKeep, 1234u);
266-
CHECK_PARSE("PenaltyBreakAssignment: 1234", PenaltyBreakAssignment, 1234u);
267-
CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
268-
PenaltyBreakBeforeFirstCallParameter, 1234u);
269-
CHECK_PARSE("PenaltyBreakBeforeMemberAccess: 1234",
270-
PenaltyBreakBeforeMemberAccess, 1234u);
271-
CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
272-
PenaltyBreakTemplateDeclaration, 1234u);
273-
CHECK_PARSE("PenaltyBreakOpenParenthesis: 1234", PenaltyBreakOpenParenthesis,
274-
1234u);
275-
CHECK_PARSE("PenaltyBreakScopeResolution: 1234", PenaltyBreakScopeResolution,
276-
1234u);
277-
CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
278-
CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
279-
PenaltyReturnTypeOnItsOwnLine, 1234u);
280-
CHECK_PARSE("SpacesBeforeTrailingComments: 1234",
281-
SpacesBeforeTrailingComments, 1234u);
282-
CHECK_PARSE("IndentWidth: 32", IndentWidth, 32u);
283-
CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
284-
CHECK_PARSE("BracedInitializerIndentWidth: 34", BracedInitializerIndentWidth,
285-
34);
286295
CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
287296

288297
Style.QualifierAlignment = FormatStyle::QAS_Right;

0 commit comments

Comments
 (0)