aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-06 08:27:33 +0000
committerDaniel Jasper <djasper@google.com>2013-05-06 08:27:33 +0000
commit53e72cdcc0bc217cab33fa56858a0fe5b94ca453 (patch)
treeb3991f8bbdda8776b6421feae5fd14ba7bbb6e19 /unittests
parent10f6f065456a2cfb6c2ab5dfedefb930e5e52e9d (diff)
Change indentation when breaking after a type.
clang-format did not indent any declarations/definitions when breaking after the type. With this change, it indents for all declarations but does not indent for function definitions, i.e.: Before: const SomeLongTypeName& some_long_variable_name; typedef SomeLongTypeName SomeLongTypeAlias; const SomeLongReturnType* SomeLongFunctionName(); const SomeLongReturnType* SomeLongFunctionName() { ... } After: const SomeLongTypeName& some_long_variable_name; typedef SomeLongTypeName SomeLongTypeAlias; const SomeLongReturnType* SomeLongFunctionName(); const SomeLongReturnType* SomeLongFunctionName() { ... } While it might seem inconsistent to indent function declarations, but not definitions, there are two reasons for that: - Function declarations are very similar to declarations of function type variables, so there is another side to consistency to consider. - There can be many function declarations on subsequent lines and not indenting can make them harder to identify. Function definitions are already separated by their body and not indenting makes the function name slighly easier to find. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181187 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 2b74506fc0..98e6d47c4f 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1520,7 +1520,7 @@ TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {
EXPECT_EQ("int\n"
"#define A\n"
- "a;",
+ " a;",
format("int\n#define A\na;"));
verifyFormat("functionCallTo(\n"
" someOtherFunction(\n"
@@ -1713,7 +1713,7 @@ TEST_F(FormatTest, MemoizationTests) {
"CFRunLoopTimerCreate(CFAllocatorRef allocato, CFAbsoluteTime fireDate,\n"
" CFTimeInterval interval, CFOptionFlags flags,\n"
" CFIndex order, CFRunLoopTimerCallBack callout,\n"
- " CFRunLoopTimerContext *context);");
+ " CFRunLoopTimerContext *context) {}");
// Deep nesting somewhat works around our memoization.
verifyFormat(
@@ -1755,8 +1755,9 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
" Cccccccccccccc cccccccccccccc);");
// 2) break after return type.
- verifyFormat("Aaaaaaaaaaaaaaaaaaaaaaaa\n"
- "bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);");
+ verifyFormat(
+ "Aaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccccccccccccccc);");
// 3) break after (.
verifyFormat(
@@ -1766,8 +1767,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);");
// However, there are exceptions, if a sufficient amount of lines can be
// saved.
@@ -1780,9 +1781,9 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
" Cccccccccccccc cccccccccc);");
verifyFormat(
"Aaaaaaaaaaaaaaaaaa\n"
- "bbbbbbbbbbbbbb(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);");
verifyFormat(
"Aaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(Cccccccccccccc cccccccccc,\n"
" Cccccccccccccc cccccccccc,\n"
@@ -1954,12 +1955,9 @@ 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(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- "GUARDED_BY(aaaaaaaaaaaa);");
+ " GUARDED_BY(aaaaaaaaaaaa);");
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
@@ -2121,8 +2119,8 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
// FIXME: If multiple variables are defined, the "*" needs to move to the new
// line. Also fix indent for breaking after the type, this looks bad.
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
- " *b = bbbbbbbbbbbbbbbbbbb;");
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb;");
// Not ideal, but pointer-with-type does not allow much here.
verifyGoogleFormat(
@@ -2707,6 +2705,19 @@ TEST_F(FormatTest, FormatsFunctionTypes) {
}
TEST_F(FormatTest, BreaksLongDeclarations) {
+ verifyFormat("typedef LoooooooooooooooooooooooooooooooooooooooongType\n"
+ " AnotherNameForTheLongType;");
+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n"
+ " LoooooooooooooooooooooooooooooooooooooooongVariable;");
+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n"
+ " LoooooooooooooooooooooooooooooooongFunctionDeclaration();");
+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n"
+ "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}");
+
+ // FIXME: Without the comment, this breaks after "(".
+ verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType // break\n"
+ " (*LoooooooooooooooooooooooooooongFunctionTypeVarialbe)();");
+
verifyFormat("int *someFunction(int LoooooooooooooooooooongParam1,\n"
" int LoooooooooooooooooooongParam2) {}");
verifyFormat(
@@ -2722,7 +2733,7 @@ TEST_F(FormatTest, BreaksLongDeclarations) {
" AnotherLongParameterName) {}");
verifyFormat(
"aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"
- "aaaaaaaaaaaaaaaaaaaaaaa;");
+ " aaaaaaaaaaaaaaaaaaaaaaa;");
verifyGoogleFormat(
"TypeSpecDecl* TypeSpecDecl::Create(ASTContext& C, DeclContext* DC,\n"