aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2012-12-24 00:13:23 +0000
committerDaniel Jasper <djasper@google.com>2012-12-24 00:13:23 +0000
commite2c7acf58856fec94ed2b8089116e1ad80e3c30f (patch)
tree45f534b56938b8ebde8303f8609db342f4c8d348 /unittests/Format/FormatTest.cpp
parent029e70cef6355da737f69e3a88b3a7b06ac9a07f (diff)
Take operator precedence into account when splitting lines.
With this patch, splitting after binary operators has a panelty corresponding to the operator's precedence. We used to ignore this and eagerly format like: if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) { .. } With this patch, this becomes: if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) { .. } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171007 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index b316750a0b..0d7901525b 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -456,6 +456,21 @@ TEST_F(FormatTest, BreaksDesireably) {
" (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
}
+TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
+ verifyFormat(
+ "if (aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) {\n}");
+ verifyFormat(
+ "if (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
+ " ccccccccccccccccccccccccc) {\n}");
+ verifyFormat(
+ "if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
+ " ccccccccccccccccccccccccc) {\n}");
+ verifyFormat(
+ "if ((aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb) &&\n"
+ " ccccccccccccccccccccccccc) {\n}");
+}
+
TEST_F(FormatTest, AlignsStringLiterals) {
verifyFormat("loooooooooooooooooooooooooongFunction(\"short literal \"\n"
" \"short literal\");");