aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-31 14:59:26 +0000
committerDaniel Jasper <djasper@google.com>2013-01-31 14:59:26 +0000
commitf343cabb68d495041706b8e2f1ed48fbac3cba06 (patch)
tree2dd9f5abf3507b0cd7a34f8a04dc0c09d1da6297 /unittests/Format/FormatTest.cpp
parent335078b0ffa844a963fdebab58b80f645ba32088 (diff)
Several improvements to the formatting of static initializers.
1. Never avoid bin packing in static initializers as this can lead to terrible results. 2. If an element has to be broken over multiple lines, break after the following comma. This should be a step forward, but there are still many cases especially with nested static initializers that we handle badly. More patches will follow. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 97358982cf..5ffd351889 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -506,13 +506,20 @@ TEST_F(FormatTest, CommentsInStaticInitializers) {
" bbbbbbbbbbb, ccccccccccc };");
verifyGoogleFormat(
"static SomeType type = { aaaaaaaaaaa, // comment for aa...\n"
- " bbbbbbbbbbb,\n"
- " ccccccccccc };");
+ " bbbbbbbbbbb, ccccccccccc };");
verifyGoogleFormat("static SomeType type = { aaaaaaaaaaa,\n"
" // comment for bb....\n"
- " bbbbbbbbbbb,\n"
- " ccccccccccc };");
+ " bbbbbbbbbbb, ccccccccccc };");
+ verifyFormat("S s = { { a, b, c }, // Group #1\n"
+ " { d, e, f }, // Group #2\n"
+ " { g, h, i } }; // Group #3");
+ verifyFormat("S s = { { // Group #1\n"
+ " a, b, c },\n"
+ " { // Group #2\n"
+ " d, e, f },\n"
+ " { // Group #3\n"
+ " g, h, i } };");
}
//===----------------------------------------------------------------------===//
@@ -649,6 +656,12 @@ TEST_F(FormatTest, StaticInitializers) {
"static SomeClass = { a, b, c, d, e, f, g, h, i, j,\n"
" looooooooooooooooooooooooooooooooooongname,\n"
" looooooooooooooooooooooooooooooong };");
+ // 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 };");
}
TEST_F(FormatTest, NestedStaticInitializers) {
@@ -657,7 +670,12 @@ TEST_F(FormatTest, NestedStaticInitializers) {
"static A x = { { { init1, init2, init3, init4 },\n"
" { init1, init2, init3, init4 } } };");
- // FIXME: Fix this in general and verify that it works in LLVM style again.
+ verifyFormat(
+ "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(
"somes Status::global_reps[3] = {\n"
" { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
@@ -669,6 +687,13 @@ TEST_F(FormatTest, NestedStaticInitializers) {
" { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop"
" } };");
+ verifyFormat(
+ "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.
verifyFormat("struct {\n"