summaryrefslogtreecommitdiffstats
path: root/clang/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
commit8a8ce2406a2283b428bd62a4820a2657e8aa902f (patch)
tree0a903f70a2813bea2da2aee9bfe0eca2fc80c55a /clang/unittests/Format/FormatTest.cpp
parent8660623576340189baddc65ffaeac2df8c29ea03 (diff)
downloadbcm5719-llvm-8a8ce2406a2283b428bd62a4820a2657e8aa902f.tar.gz
bcm5719-llvm-8a8ce2406a2283b428bd62a4820a2657e8aa902f.zip
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. llvm-svn: 174061
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 97358982cf6..5ffd3518891 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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"
OpenPOWER on IntegriCloud