diff options
author | Daniel Jasper <djasper@google.com> | 2013-04-03 13:36:17 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-04-03 13:36:17 +0000 |
commit | 8ed9f2b25f082a1643ab5310f9eec33cf31a7577 (patch) | |
tree | fc06c676649ca39d533c768d5a73cc5a2459d6d3 /unittests | |
parent | 4128e19d6f3ae42e840bc6aaf6ce6d052a46f7e4 (diff) |
Improve formatting of for loops and multi-variable DeclStmts.
This combines several related changes:
a) Don't break before after the variable types in for loops with a
single variable.
b) Better indent DeclStmts defining multiple variables.
Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaa =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),
bbbbbbbbbbbbbbbbbbbbbbbbb =
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {
}
After:
bool aaaaaaaaaaaaaaaaaaaaaaaaa =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),
bbbbbbbbbbbbbbbbbbbbbbbbb =
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =
aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 92a2363bbd..2038ee167f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -311,8 +311,8 @@ TEST_F(FormatTest, FormatsForLoop) { verifyFormat( "for (MachineFun::iterator IIII = PrevIt, EEEE = F.end(); IIII != EEEE;\n" " ++IIIII) {\n}"); - verifyFormat("for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n" + verifyFormat("for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =\n" + " aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n" " aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {\n}"); verifyFormat("for (llvm::ArrayRef<NamedDecl *>::iterator\n" " I = FD->getDeclsInPrototypeScope().begin(),\n" @@ -329,6 +329,10 @@ TEST_F(FormatTest, FormatsForLoop) { verifyFormat("for (int aaaaaaaaaaa = 1; aaaaaaaaaaa <= bbbbbbbbbbbbbbb;\n" " aaaaaaaaaaa++, bbbbbbbbbbbbbbbbb++) {\n" "}"); + verifyFormat("for (some_namespace::SomeIterator iter( // force break\n" + " aaaaaaaaaa);\n" + " iter; ++iter) {\n" + "}"); FormatStyle NoBinPacking = getLLVMStyle(); NoBinPacking.BinPackParameters = false; @@ -1188,8 +1192,9 @@ TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) { } TEST_F(FormatTest, DoesNotBreakPureVirtualFunctionDefinition) { - verifyFormat("virtual void write(ELFWriter *writerrr,\n" - " OwningPtr<FileOutputBuffer> &buffer) = 0;"); + verifyFormat( + "virtual void\n" + "write(ELFWriter *writerrr, OwningPtr<FileOutputBuffer> &buffer) = 0;"); } TEST_F(FormatTest, LayoutUnknownPPDirective) { @@ -1378,7 +1383,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" @@ -1613,7 +1618,7 @@ TEST_F(FormatTest, BreaksDesireably) { } TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getGoogleStyle(); NoBinPacking.BinPackParameters = false; verifyFormat("f(aaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaa,\n" @@ -1851,14 +1856,13 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) { " aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa();"); verifyFormat("bool a = true, b = false;"); - // FIXME: Indentation looks weird. verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaa =\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),\n" " bbbbbbbbbbbbbbbbbbbbbbbbb =\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);"); verifyFormat( "bool aaaaaaaaaaaaaaaaaaaaa =\n" - " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n" " d = e && f;"); } @@ -2051,7 +2055,7 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); verifyFormat("template <typename T>\n" "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" - " int aaaaaaaaaaaaaaaaa);"); + " int aaaaaaaaaaaaaaaaaaaaaa);"); verifyFormat( "template <typename T1, typename T2 = char, typename T3 = char,\n" " typename T4 = char>\n" |