diff options
author | Daniel Jasper <djasper@google.com> | 2012-12-24 16:43:00 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-12-24 16:43:00 +0000 |
commit | a4974cf6ae618f04d5dd7fc45bc18bff41ca86bf (patch) | |
tree | b2bfc7f1b1303209b265d480fc3154f881adc3ad /unittests/Format/FormatTest.cpp | |
parent | cf225b67e66d7a85773b7bf7907c0fef4374c31b (diff) |
Penalize tokens with a lower parenthesis level than the start of the line.
This prevents formattings like this (assuming "parameter" doesn't fit the line):
bool f = someFunction() && someFunctionWithParam(
parameter) && someOtherFunction();
Here, "parameter" - the start of line 2 - has a parenthesis level of 2, but
there are subsequent tokens ("&&" and "someOtherFunction") with a lower level.
This is bad for readability as "parameter" hides "someOtherFunction". With this
patch, this changes to:
bool f = someFunction() &&
someFunctionWithParam(parameter) &&
someOtherFunction();
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171038 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9a1cb90746..43003befb6 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -379,8 +379,9 @@ TEST_F(FormatTest, FormatsFunctionDefinition) { TEST_F(FormatTest, FormatsAwesomeMethodCall) { verifyFormat( - "SomeLongMethodName(SomeReallyLongMethod(CallOtherReallyLongMethod(\n" - " parameter, parameter, parameter)), SecondLongCall(parameter));"); + "SomeLongMethodName(SomeReallyLongMethod(\n" + " CallOtherReallyLongMethod(parameter, parameter, parameter)),\n" + " SecondLongCall(parameter));"); } TEST_F(FormatTest, ConstructorInitializers) { @@ -454,6 +455,13 @@ TEST_F(FormatTest, BreaksDesireably) { " aaaaaaaaaaa(aaaaaaaaa) || aaaaaaaaaaaaaaaaaaaaaaa ||\n" " aaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaa ||\n" " (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); + + verifyFormat( + "{\n {\n {\n" + " Annotation.SpaceRequiredBefore =\n" + " Line.Tokens[i - 1].Tok.isNot(tok::l_paren) &&\n" + " Line.Tokens[i - 1].Tok.isNot(tok::l_square);\n" + " }\n }\n}"); } TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) { |