diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-16 14:59:02 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-16 14:59:02 +0000 |
commit | 0df6acdf4f6faf7579775a739e1c09448c076c0f (patch) | |
tree | f91f004a8f568b32b857f5a0d23a54626901d42b /unittests/Format/FormatTest.cpp | |
parent | ca547dbbb1e10c801158f2eecaf3d49e1071b0e3 (diff) |
Add option to avoid "bin-packing" of parameters.
"Bin-packing" here means allowing multiple parameters on one line, if a
function call/declaration is spread over multiple lines.
This is required by the Chromium style guide and probably desired for
the Google style guide. Not making changes to LLVM style as I don't have
enough data.
With this enabled, we format stuff like:
aaaaaaaaaaaaaaa(aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172617 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index efea545d32..066e8881eb 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -484,10 +484,11 @@ TEST_F(FormatTest, StaticInitializers) { 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( + "static A x = { { { init1, init2, init3, init4 },\n" + " { init1, init2, init3, init4 } } };"); + + // FIXME: Fix this in general an verify that it works in LLVM style again. + verifyGoogleFormat( "somes Status::global_reps[3] = {\n" " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n" " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n" @@ -670,8 +671,7 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { "#define A B\n" " withMoreParamters,\n" " whichStronglyInfluenceTheLayout),\n" - " andMoreParameters),\n" - " trailing);", getLLVMStyleWithColumns(69)); + " andMoreParameters), trailing);", getLLVMStyleWithColumns(69)); } TEST_F(FormatTest, LayoutBlockInsideParens) { @@ -763,22 +763,13 @@ TEST_F(FormatTest, ConstructorInitializers) { "}"); // This test takes VERY long when memoization is broken. - verifyGoogleFormat( - "Constructor()\n" - " : aaaa(a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a)\n" - " aaaa(a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a," - " a, a, a,\n" - " a, a, a, a, a, a, a, a, a, a, a) {}\n"); + std::string input = "Constructor()\n" + " : aaaa(a,\n"; + for (unsigned i = 0, e = 80; i != e; ++i) { + input += " a,\n"; + } + input += " a) {}"; + verifyGoogleFormat(input); } TEST_F(FormatTest, BreaksAsHighAsPossible) { @@ -829,6 +820,31 @@ TEST_F(FormatTest, BreaksDesireably) { " }\n }\n}"); } +TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { + verifyGoogleFormat( + "aaaaaaaa(aaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)),\n" + " aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));"); + verifyGoogleFormat( + "aaaaaaaaaaaaaaa(aaaaaaaaa,\n" + " aaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();"); + verifyGoogleFormat( + "somefunction(someotherFunction(ddddddddddddddddddddddddddddddddddd,\n" + " ddddddddddddddddddddddddddddd),\n" + " test);"); + + verifyGoogleFormat( + "std::vector<aaaaaaaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaa;"); + verifyGoogleFormat("a(\"a\"\n" + " \"a\",\n" + " a);"); +} + TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) { verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " GUARDED_BY(aaaaaaaaaaaaa);"); |