diff options
| author | Daniel Jasper <djasper@google.com> | 2014-07-09 07:50:33 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-07-09 07:50:33 +0000 |
| commit | 4355e7f0effc788f1af2b48a531f650e1e40db39 (patch) | |
| tree | ac6f8ba9d24bf11533cbc84e7031767f34422d7f /clang/unittests/Format/FormatTest.cpp | |
| parent | 696b4a089cde5513973dc8e2cf17684d44e74aa5 (diff) | |
| download | bcm5719-llvm-4355e7f0effc788f1af2b48a531f650e1e40db39.tar.gz bcm5719-llvm-4355e7f0effc788f1af2b48a531f650e1e40db39.zip | |
clang-format: Revamp function declaration/definition indentation.
Key changes:
- Correctly (well ...) distinguish function declarations and variable
declarations with ()-initialization.
- Don't indent when breaking function declarations/definitions after the
return type.
- Indent variable declarations and typedefs when breaking after the
type.
This fixes llvm.org/PR17999.
llvm-svn: 212591
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 96274fc2031..7029b43f05b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1264,13 +1264,13 @@ TEST_F(FormatTest, DontSplitLineCommentsWithEscapedNewlines) { getLLVMStyleWithColumns(50))); // FIXME: One day we might want to implement adjustment of leading whitespace // of the consecutive lines in this kind of comment: - EXPECT_EQ("int\n" - "a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" - " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" - " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - format("int a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" - " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" - " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + EXPECT_EQ("double\n" + " a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" + " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" + " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + format("double a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" + " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n" + " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", getLLVMStyleWithColumns(49))); } @@ -2687,7 +2687,7 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { EXPECT_EQ("int\n" "#define A\n" " a;", - format("int\n#define A\na;", getGoogleStyle())); + format("int\n#define A\na;")); verifyFormat("functionCallTo(\n" " someOtherFunction(\n" " withSomeParameters, whichInSequence,\n" @@ -3359,7 +3359,7 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { // 2) break after return type. verifyFormat( "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);", + "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);", getGoogleStyle()); // 3) break after (. @@ -3371,8 +3371,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { // 4) break before after nested name specifiers. verifyFormat( "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " SomeClasssssssssssssssssssssssssssssssssssssss::\n" - " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc);", + "SomeClasssssssssssssssssssssssssssssssssssssss::\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc);", getGoogleStyle()); // However, there are exceptions, if a sufficient amount of lines can be @@ -3386,9 +3386,9 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { " Cccccccccccccc cccccccccc);"); verifyFormat( "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " bbbbbbbbbbb(Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n" - " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n" - " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);", + "bbbbbbbbbbb(Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n" + " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n" + " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);", getGoogleStyle()); verifyFormat( "Aaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc,\n" @@ -5054,22 +5054,28 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }"); } +TEST_F(FormatTest, BreaksLongVariableDeclarations) { + verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" + " LoooooooooooooooooooooooooooooooooooooooongVariable;"); + verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType const\n" + " LoooooooooooooooooooooooooooooooooooooooongVariable;"); + + // Different ways of ()-initializiation. + verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" + " LoooooooooooooooooooooooooooooooooooooooongVariable(1);"); + verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" + " LoooooooooooooooooooooooooooooooooooooooongVariable(a);"); + verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" + " LoooooooooooooooooooooooooooooooooooooooongVariable({});"); +} + TEST_F(FormatTest, BreaksLongDeclarations) { verifyFormat("typedef LoooooooooooooooooooooooooooooooooooooooongType\n" - " AnotherNameForTheLongType;", - getGoogleStyle()); + " AnotherNameForTheLongType;"); verifyFormat("typedef LongTemplateType<aaaaaaaaaaaaaaaaaaa()>\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;", - getGoogleStyle()); - verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" - " LoooooooooooooooooooooooooooooooooooooooongVariable;", - getGoogleStyle()); - verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType const\n" - " LoooooooooooooooooooooooooooooooooooooooongVariable;", - getGoogleStyle()); + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" - " LoooooooooooooooooooooooooooooooongFunctionDeclaration();", - getGoogleStyle()); + "LoooooooooooooooooooooooooooooooongFunctionDeclaration();"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType const\n" @@ -8101,7 +8107,6 @@ TEST_F(FormatTest, ParsesConfiguration) { CHECK_PARSE_BOOL(ObjCSpaceAfterProperty); CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList); CHECK_PARSE_BOOL(Cpp11BracedListStyle); - CHECK_PARSE_BOOL(IndentFunctionDeclarationAfterType); CHECK_PARSE_BOOL(SpacesInParentheses); CHECK_PARSE_BOOL(SpacesInAngles); CHECK_PARSE_BOOL(SpaceInEmptyParentheses); @@ -9044,7 +9049,7 @@ TEST_F(FormatTest, HandleConflictMarkers) { "=======\n" "Other \\\n" ">>>>>>>\n" - "End int i;\n", + " End int i;\n", format("#define Macro \\\n" "<<<<<<<\n" " Something \\\n" |

