/// \brief The brace breaking style to use.
BraceBreakingStyle BreakBeforeBraces;
+ /// \brief If \c true, format { 1 }, otherwise {1}.
+ bool SpacesInBracedLists;
+
bool operator==(const FormatStyle &R) const {
return AccessModifierOffset == R.AccessModifierOffset &&
AlignEscapedNewlinesLeft == R.AlignEscapedNewlinesLeft &&
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
BinPackParameters == R.BinPackParameters &&
+ BreakBeforeBraces == R.BreakBeforeBraces &&
ColumnLimit == R.ColumnLimit &&
ConstructorInitializerAllOnOneLineOrOnePerLine ==
R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
DerivePointerBinding == R.DerivePointerBinding &&
IndentCaseLabels == R.IndentCaseLabels &&
+ IndentWidth == R.IndentWidth &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
PointerBindsToType == R.PointerBindsToType &&
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
+ SpacesInBracedLists == R.SpacesInBracedLists &&
Standard == R.Standard &&
- IndentWidth == R.IndentWidth &&
- UseTab == R.UseTab &&
- BreakBeforeBraces == R.BreakBeforeBraces;
+ UseTab == R.UseTab;
}
};
" // comment for bb....\n"
" bbbbbbbbbbb, ccccccccccc };");
verifyGoogleFormat(
- "static SomeType type = { aaaaaaaaaaa, // comment for aa...\n"
- " bbbbbbbbbbb, ccccccccccc };");
- verifyGoogleFormat("static SomeType type = { aaaaaaaaaaa,\n"
- " // comment for bb....\n"
- " bbbbbbbbbbb, ccccccccccc };");
+ "static SomeType type = {aaaaaaaaaaa, // comment for aa...\n"
+ " bbbbbbbbbbb, ccccccccccc};");
+ verifyGoogleFormat("static SomeType type = {aaaaaaaaaaa,\n"
+ " // comment for bb....\n"
+ " bbbbbbbbbbb, ccccccccccc};");
verifyFormat("S s = { { a, b, c }, // Group #1\n"
" { d, e, f }, // Group #2\n"
// Allow bin-packing in static initializers as this would often lead to
// terrible results, e.g.:
verifyGoogleFormat(
- "static SomeClass = { a, b, c, d, e, f, g, h, i, j,\n"
- " looooooooooooooooooooooooooooooooooongname,\n"
- " looooooooooooooooooooooooooooooong };");
+ "static SomeClass = {a, b, c, d, e, f, g, h, i, j,\n"
+ " looooooooooooooooooooooooooooooooooongname,\n"
+ " looooooooooooooooooooooooooooooong};");
// Here, everything other than the "}" would fit on a line.
verifyFormat("static int LooooooooooooooooooooooooongVariable[1] = {\n"
" 100000000000000000000000\n"
" { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
" { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
"};");
- verifyGoogleFormat("somes Status::global_reps[3] = {\n"
- " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
+ verifyGoogleFormat("SomeType Status::global_reps[3] = {\n"
+ " {kGlobalRef, OK_CODE, NULL, NULL, NULL},\n"
+ " {kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL},\n"
+ " {kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL}\n"
"};");
verifyFormat(
"CGRect cg_rect = { { rect.fLeft, rect.fTop },\n"
" 222222222222222222222222222222,\n"
" 333333333333333333333333333333 } },\n"
" { { 1, 2, 3 } }, { { 1, 2, 3 } } };");
+ verifyGoogleFormat(
+ "SomeArrayOfSomeType a = {{{1, 2, 3}}, {{1, 2, 3}},\n"
+ " {{111111111111111111111111111111,\n"
+ " 222222222222222222222222222222,\n"
+ " 333333333333333333333333333333}},\n"
+ " {{1, 2, 3}}, {{1, 2, 3}}};");
// FIXME: We might at some point want to handle this similar to parameter
// lists, where we have an option to put each on a single line.
}
TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
- verifyFormat("vector<int> x { 1, 2, 3, 4 };");
- verifyFormat("vector<T> x { {}, {}, {}, {} };");
+ verifyFormat("vector<int> x{ 1, 2, 3, 4 };");
+ verifyFormat("vector<T> x{ {}, {}, {}, {} };");
verifyFormat("f({ 1, 2 });");
- verifyFormat("auto v = Foo { 1 };");
+ verifyFormat("auto v = Foo{ 1 };");
verifyFormat("f({ 1, 2 }, { { 2, 3 }, { 4, 5 } }, c, { d });");
+
+ FormatStyle NoSpaces = getLLVMStyle();
+ NoSpaces.SpacesInBracedLists = false;
+ verifyFormat("vector<int> x{1, 2, 3, 4};", NoSpaces);
+ verifyFormat("vector<T> x{{}, {}, {}, {}};", NoSpaces);
+ verifyFormat("f({1, 2});", NoSpaces);
+ verifyFormat("auto v = Foo{1};", NoSpaces);
+ verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", NoSpaces);
}
TEST_F(FormatTest, LayoutTokensFollowingBlockInParentheses) {
CHECK_PARSE_BOOL(IndentCaseLabels);
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
CHECK_PARSE_BOOL(PointerBindsToType);
+ CHECK_PARSE_BOOL(SpacesInBracedLists);
CHECK_PARSE_BOOL(UseTab);
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);