diff options
author | Daniel Jasper <djasper@google.com> | 2013-02-23 21:01:55 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-02-23 21:01:55 +0000 |
commit | 237d4c1c785be13656bff6c09e5b7ccd066ff5ba (patch) | |
tree | 9e223d4193e9c674d0b15715b83516b1e2401624 /unittests/Format/FormatTest.cpp | |
parent | 04ea68c12578955c125f7df3b58432fcdb28484e (diff) |
Better formatting of conditional expressions.
In conditional expressions, if the condition is split over multiple
lines, also break before both operands.
This prevents formattings like:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c;
Which are bad, because they suggestion incorrect operator precedence:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c);
This lead to the discovery that the expression parser incorrectly
handled conditional operators and that it could also handle semicolons
(which in turn reduced the amount of special casing for for-loops). As a
side-effect, we can now apply the bin-packing configuration to the
sections of for-loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175973 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index daaeca3fa0..2f8097c612 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -306,6 +306,11 @@ TEST_F(FormatTest, FormatsForLoop) { " aaaaaaaaaaaaaaaa);\n" " aaaaaaaaaaa++, bbbbbbbbbbbbbbbbb++) {\n" "}"); + verifyGoogleFormat( + "for (std::vector<UnwrappedLine>::iterator I = UnwrappedLines.begin(),\n" + " E = UnwrappedLines.end();\n" + " I != E;\n" + " ++I) {\n}"); } TEST_F(FormatTest, RangeBasedForLoops) { @@ -1397,9 +1402,14 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " ? aaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " : aaaaaaaaaaaaaaaaaaaaaaaaaaa;"); - - // FIXME: The trailing third parameter here is kind of hidden. Prefer putting - // it on the next line. + verifyFormat( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " ? aaaaaaaaaaaaaaa\n" + " : aaaaaaaaaaaaaaa;"); + verifyFormat("f(aaaaaaaaaaaaaaaa == // force break\n" + " aaaaaaaaa\n" + " ? b\n" + " : c);"); verifyFormat( "unsigned Indent =\n" " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n" @@ -1408,6 +1418,14 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { " TheLine.InPPDirective, PreviousEndOfLineColumn);", getLLVMStyleWithColumns(70)); + verifyGoogleFormat( + "void f() {\n" + " g(aaa,\n" + " aaaaaaaaaa == aaaaaaaaaa ? aaaa : aaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " ? aaaaaaaaaaaaaaa\n" + " : aaaaaaaaaaaaaaa);\n" + "}"); } TEST_F(FormatTest, DeclarationsOfMultipleVariables) { |