summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-06-07 16:02:52 +0000
committerAlexander Kornienko <alexfh@google.com>2013-06-07 16:02:52 +0000
commitdd7ece53a2958ab3910007f6521bbb078b33505c (patch)
tree8b16bfa4d9034dc88a102d1683c1ef6d1f937cba /clang/unittests/Format/FormatTest.cpp
parentcead69d4a3f80fa8684f5636a9469d043f4f7285 (diff)
downloadbcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.tar.gz
bcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.zip
Fixed calculation of penalty when breaking tokens.
Summary: Introduced two new style parameters: PenaltyBreakComment and PenaltyBreakString. Add penalty for each character of a breakable token beyond the column limit (this relates mainly to comments, as they are broken only on whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking inside most binary expressions. Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator in the presense of adjacent comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D933 llvm-svn: 183530
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp93
1 files changed, 62 insertions, 31 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f5204b45768..6a2edc0f99e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -675,7 +675,7 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
"};");
verifyGoogleFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " aaaaaaaaaaaaaaaaaaaaaa); // 81 cols with this comment");
+ " aaaaaaaaaaaaaaaaaaaaaa); // 81_cols_with_this_comment");
EXPECT_EQ("D(a, {\n"
" // test\n"
" int a;\n"
@@ -871,37 +871,36 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
format("// A comment before a macro definition\n"
"#define a b",
getLLVMStyleWithColumns(20)));
+}
- EXPECT_EQ("/* A comment before\n"
- " * a macro\n"
- " * definition */\n"
- "#define a b",
- format("/* A comment before a macro definition */\n"
- "#define a b",
- getLLVMStyleWithColumns(20)));
-
- EXPECT_EQ("/* some comment\n"
- " * a comment\n"
- "* that we break\n"
- " * another comment\n"
- "* we have to break\n"
- "* a left comment\n"
- " */",
- format(" /* some comment\n"
- " * a comment that we break\n"
- " * another comment we have to break\n"
- "* a left comment\n"
- " */",
- getLLVMStyleWithColumns(20)));
-
- EXPECT_EQ("/*\n"
- "\n"
- "\n"
- " */\n",
- format(" /* \n"
- " \n"
- " \n"
- " */\n"));
+TEST_F(FormatTest, PriorityOfCommentBreaking) {
+ EXPECT_EQ("if (xxx == yyy && // aaaaaaaaaaaa\n"
+ " // bbbbbbbbb\n"
+ " zzz)\n"
+ " q();",
+ format("if (xxx == yyy && // aaaaaaaaaaaa bbbbbbbbb\n"
+ " zzz) q();",
+ getLLVMStyleWithColumns(40)));
+ EXPECT_EQ("if (xxxxxxxxxx ==\n"
+ " yyy && // aaaaaa bbbbbbbb cccc\n"
+ " zzz)\n"
+ " q();",
+ format("if (xxxxxxxxxx == yyy && // aaaaaa bbbbbbbb cccc\n"
+ " zzz) q();",
+ getLLVMStyleWithColumns(40)));
+ EXPECT_EQ("if (xxxxxxxxxx &&\n"
+ " yyy || // aaaaaa bbbbbbbb cccc\n"
+ " zzz)\n"
+ " q();",
+ format("if (xxxxxxxxxx && yyy || // aaaaaa bbbbbbbb cccc\n"
+ " zzz) q();",
+ getLLVMStyleWithColumns(40)));
+ EXPECT_EQ("fffffffff(&xxx, // aaaaaaaaaaaa\n"
+ " // bbbbbbbbbbb\n"
+ " zzz);",
+ format("fffffffff(&xxx, // aaaaaaaaaaaa bbbbbbbbbbb\n"
+ " zzz);",
+ getLLVMStyleWithColumns(40)));
}
TEST_F(FormatTest, MultiLineCommentsInDefines) {
@@ -1059,6 +1058,37 @@ TEST_F(FormatTest, SplitsLongLinesInComments) {
" ;\n"
"}",
getLLVMStyleWithColumns(30)));
+
+ EXPECT_EQ("/* A comment before\n"
+ " * a macro\n"
+ " * definition */\n"
+ "#define a b",
+ format("/* A comment before a macro definition */\n"
+ "#define a b",
+ getLLVMStyleWithColumns(20)));
+
+ EXPECT_EQ("/* some comment\n"
+ " * a comment\n"
+ "* that we break\n"
+ " * another comment\n"
+ "* we have to break\n"
+ "* a left comment\n"
+ " */",
+ format(" /* some comment\n"
+ " * a comment that we break\n"
+ " * another comment we have to break\n"
+ "* a left comment\n"
+ " */",
+ getLLVMStyleWithColumns(20)));
+
+ EXPECT_EQ("/*\n"
+ "\n"
+ "\n"
+ " */\n",
+ format(" /* \n"
+ " \n"
+ " \n"
+ " */\n"));
}
TEST_F(FormatTest, SplitsLongLinesInCommentsInPreprocessor) {
@@ -3263,6 +3293,7 @@ TEST_F(FormatTest, FormatsCasts) {
// FIXME: Without type knowledge, this can still fall apart miserably.
verifyFormat("void f() { my_int a = (my_int) * b; }");
+ verifyFormat("void f() { return P ? (my_int) * P : (my_int)0; }");
verifyFormat("my_int a = (my_int) ~0;");
verifyFormat("my_int a = (my_int)++ a;");
verifyFormat("my_int a = (my_int) + 2;");
OpenPOWER on IntegriCloud