Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ TEST(ConfigParseTest, GetsCorrectBasedOnStyle) {
EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value()); \
EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"

#define CHECK_PARSE_INT(FIELD) CHECK_PARSE(#FIELD ": -1234", FIELD, -1234)

#define CHECK_PARSE_UNSIGNED(FIELD) CHECK_PARSE(#FIELD ": 1234", FIELD, 1234u)

#define CHECK_PARSE_LIST(FIELD) \
CHECK_PARSE(#FIELD ": [foo]", FIELD, std::vector<std::string>{"foo"})

Expand Down Expand Up @@ -254,35 +258,40 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {

#undef CHECK_PARSE_BOOL

TEST(ConfigParseTest, ParsesConfigurationIntegers) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;

CHECK_PARSE_INT(AccessModifierOffset);
CHECK_PARSE_INT(PPIndentWidth);

CHECK_PARSE_UNSIGNED(BracedInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ColumnLimit);
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
CHECK_PARSE_UNSIGNED(IndentWidth);
CHECK_PARSE_UNSIGNED(MaxEmptyLinesToKeep);
CHECK_PARSE_UNSIGNED(ObjCBlockIndentWidth);
CHECK_PARSE_UNSIGNED(PenaltyBreakAssignment);
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeFirstCallParameter);
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeMemberAccess);
CHECK_PARSE_UNSIGNED(PenaltyBreakComment);
CHECK_PARSE_UNSIGNED(PenaltyBreakFirstLessLess);
CHECK_PARSE_UNSIGNED(PenaltyBreakOpenParenthesis);
CHECK_PARSE_UNSIGNED(PenaltyBreakScopeResolution);
CHECK_PARSE_UNSIGNED(PenaltyBreakString);
CHECK_PARSE_UNSIGNED(PenaltyBreakTemplateDeclaration);
CHECK_PARSE_UNSIGNED(PenaltyExcessCharacter);
CHECK_PARSE_UNSIGNED(PenaltyIndentedWhitespace);
CHECK_PARSE_UNSIGNED(PenaltyReturnTypeOnItsOwnLine);
CHECK_PARSE_UNSIGNED(ShortNamespaceLines);
CHECK_PARSE_UNSIGNED(SpacesBeforeTrailingComments);
CHECK_PARSE_UNSIGNED(TabWidth);
}

TEST(ConfigParseTest, ParsesConfiguration) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);
CHECK_PARSE("ConstructorInitializerIndentWidth: 1234",
ConstructorInitializerIndentWidth, 1234u);
CHECK_PARSE("ObjCBlockIndentWidth: 1234", ObjCBlockIndentWidth, 1234u);
CHECK_PARSE("ColumnLimit: 1234", ColumnLimit, 1234u);
CHECK_PARSE("MaxEmptyLinesToKeep: 1234", MaxEmptyLinesToKeep, 1234u);
CHECK_PARSE("PenaltyBreakAssignment: 1234", PenaltyBreakAssignment, 1234u);
CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
PenaltyBreakBeforeFirstCallParameter, 1234u);
CHECK_PARSE("PenaltyBreakBeforeMemberAccess: 1234",
PenaltyBreakBeforeMemberAccess, 1234u);
CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
PenaltyBreakTemplateDeclaration, 1234u);
CHECK_PARSE("PenaltyBreakOpenParenthesis: 1234", PenaltyBreakOpenParenthesis,
1234u);
CHECK_PARSE("PenaltyBreakScopeResolution: 1234", PenaltyBreakScopeResolution,
1234u);
CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
PenaltyReturnTypeOnItsOwnLine, 1234u);
CHECK_PARSE("SpacesBeforeTrailingComments: 1234",
SpacesBeforeTrailingComments, 1234u);
CHECK_PARSE("IndentWidth: 32", IndentWidth, 32u);
CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
CHECK_PARSE("BracedInitializerIndentWidth: 34", BracedInitializerIndentWidth,
34);
CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");

Style.QualifierAlignment = FormatStyle::QAS_Right;
Expand Down
Loading