aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-04-11 14:29:13 +0000
committerDaniel Jasper <djasper@google.com>2013-04-11 14:29:13 +0000
commit1407bee187d7b964d5293ac8bf4f7a490c78cec6 (patch)
tree98953a2e6b0057cfa12cb6c8851a66041c57051d /unittests
parenta8262981683c4768f43e8b8bc507ab77fff0b216 (diff)
Change clang-format's affinity for breaking after return types.
Function declarations are now broken with the following preferences: 1) break amongst arguments. 2) break after return type. 3) break after (. 4) break before after nested name specifiers. Options #2 or #3 are preferred over #1 only if a substantial number of lines can be saved by that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179287 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp62
1 files changed, 56 insertions, 6 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 09fbce830e..91b8f81080 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1199,8 +1199,8 @@ TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
TEST_F(FormatTest, DoesNotBreakPureVirtualFunctionDefinition) {
verifyFormat(
- "virtual void\n"
- "write(ELFWriter *writerrr, OwningPtr<FileOutputBuffer> &buffer) = 0;");
+ "virtual void write(ELFWriter *writerrr,\n"
+ " OwningPtr<FileOutputBuffer> &buffer) = 0;");
}
TEST_F(FormatTest, LayoutUnknownPPDirective) {
@@ -1700,6 +1700,56 @@ TEST_F(FormatTest, BreaksAsHighAsPossible) {
" Intervals[i - 1].getRange().getLast()) {\n}");
}
+TEST_F(FormatTest, BreaksFunctionDeclarations) {
+ // Principially, we break function declarations in a certain order:
+ // 1) break amongst arguments.
+ verifyFormat("Aaaaaaaaaaaaaa bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccc,\n"
+ " Cccccccccccccc cccccccccccccc);");
+
+ // 2) break after return type.
+ verifyFormat("Aaaaaaaaaaaaaaaaaaaaaaaa\n"
+ "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);");
+
+ // 3) break after (.
+ verifyFormat(
+ "Aaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb(\n"
+ " Cccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccc);");
+
+ // 4) break before after nested name specifiers.
+ verifyFormat(
+ "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ "SomeClasssssssssssssssssssssssssssssssssssssss::\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc);");
+
+ // However, there are exceptions, if a sufficient amount of lines can be
+ // saved.
+ // FIXME: The precise cut-offs wrt. the number of saved lines might need some
+ // more adjusting.
+ verifyFormat("Aaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbb(Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc);");
+ verifyFormat(
+ "Aaaaaaaaaaaaaaaaaa\n"
+ "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);");
+ verifyFormat(
+ "Aaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc);");
+ verifyFormat("Aaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc,\n"
+ " Cccccccccccccc cccccccccc, Cccccccccccccc cccccccccc);");
+}
+
TEST_F(FormatTest, BreaksDesireably) {
verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
" aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
@@ -1850,7 +1900,7 @@ TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
" aaaaaaaaaaaaaaaaaaaaaaaaa));");
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" __attribute__((unused));");
-
+
// FIXME: This is bad indentation, but generally hard to distinguish from a
// function declaration.
verifyFormat(
@@ -2600,9 +2650,9 @@ TEST_F(FormatTest, BreaksLongDeclarations) {
verifyFormat("int *someFunction(int LoooooooooooooooooooongParam1,\n"
" int LoooooooooooooooooooongParam2) {}");
verifyFormat(
- "TypeSpecDecl *\n"
- "TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,\n"
- " IdentifierIn *II, Type *T) {}");
+ "TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n"
+ " SourceLocation L, IdentifierIn *II,\n"
+ " Type *T) {}");
verifyFormat("ReallyLongReturnType<TemplateParam1, TemplateParam2>\n"
"ReallyReallyLongFunctionName(\n"
" const std::string &SomeParameter,\n"