summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-14 16:41:43 +0000
committerManuel Klimek <klimek@google.com>2013-01-14 16:41:43 +0000
commita54d1a99a2ea04e2746e154ab9f59dc8eaee60b0 (patch)
tree855ef6bf09967c5a988f90533e6953fc43a903e9 /clang/unittests/Format/FormatTest.cpp
parent51ce63cd9897a9be8160329f5c14d4394bd048a9 (diff)
downloadbcm5719-llvm-a54d1a99a2ea04e2746e154ab9f59dc8eaee60b0.tar.gz
bcm5719-llvm-a54d1a99a2ea04e2746e154ab9f59dc8eaee60b0.zip
Fixes formatting of nested brace initializers.
We now format this correctly: Status::Rep Status::global_reps[3] = { { kGlobalRef, OK_CODE, NULL, NULL, NULL }, { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL }, { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL } }; - fixed a bug where BreakBeforeClosingBrace would be set on the wrong state - added penalties for breaking between = and {, and between { and any other non-{ token llvm-svn: 172433
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1ab4a53c404..f8a81b59820 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -459,6 +459,32 @@ TEST_F(FormatTest, StaticInitializers) {
" looooooooooooooooooooooooooooooong };");
}
+TEST_F(FormatTest, NestedStaticInitializers) {
+ verifyFormat("static A x = { { {} } };\n");
+ verifyFormat(
+ "static A x = {\n"
+ " { { init1, init2, init3, init4 }, { init1, init2, init3, init4 } }\n"
+ "};\n");
+ 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"
+ "};");
+ verifyFormat(
+ "CGRect cg_rect = { { rect.fLeft, rect.fTop },\n"
+ " { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop"
+ " } };");
+
+ // FIXME: We might at some point want to handle this similar to parameters
+ // lists, where we have an option to put each on a single line.
+ verifyFormat("struct {\n"
+ " unsigned bit;\n"
+ " const char *const name;\n"
+ "} kBitsToOs[] = { { kOsMac, \"Mac\" }, { kOsWin, \"Windows\" },\n"
+ " { kOsLinux, \"Linux\" }, { kOsCrOS, \"Chrome OS\" } };");
+}
+
TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
verifyFormat("#define ALooooooooooooooooooooooooooooooooooooooongMacro("
" \\\n"
OpenPOWER on IntegriCloud