[cfe-commits] r172067 - in /cfe/trunk: lib/Format/Format.cpp lib/Format/UnwrappedLineParser.cpp test/Index/comment-c-decls.c test/Index/comment-cplus-decls.cpp test/Index/comment-cplus-template-decls.cpp test/Index/comment-to-html-xml-conversion.cpp test/Index/format-comment-cdecls.c unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Thu Jan 10 05:24:25 PST 2013
Author: klimek
Date: Thu Jan 10 07:24:24 2013
New Revision: 172067
URL: http://llvm.org/viewvc/llvm-project?rev=172067&view=rev
Log:
Do not add newline in empty blocks.
void f() {}
now gets formatted in one line.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/test/Index/comment-c-decls.c
cfe/trunk/test/Index/comment-cplus-decls.cpp
cfe/trunk/test/Index/comment-cplus-template-decls.cpp
cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp
cfe/trunk/test/Index/format-comment-cdecls.c
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 10 07:24:24 2013
@@ -1033,6 +1033,8 @@
if (Left.is(tok::at) &&
Right.FormatTok.Tok.getObjCKeywordID() != tok::objc_not_keyword)
return false;
+ if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
+ return false;
return true;
}
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jan 10 07:24:24 2013
@@ -167,15 +167,17 @@
assert(FormatTok.Tok.is(tok::l_brace) && "'{' expected");
nextToken();
- addUnwrappedLine();
+ if (!FormatTok.Tok.is(tok::r_brace)) {
+ addUnwrappedLine();
- Line->Level += AddLevels;
- parseLevel(/*HasOpeningBrace=*/true);
- Line->Level -= AddLevels;
+ Line->Level += AddLevels;
+ parseLevel(/*HasOpeningBrace=*/true);
+ Line->Level -= AddLevels;
- if (!FormatTok.Tok.is(tok::r_brace))
- return true;
+ if (!FormatTok.Tok.is(tok::r_brace))
+ return true;
+ }
nextToken(); // Munch the closing brace.
return false;
}
Modified: cfe/trunk/test/Index/comment-c-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-c-decls.c?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-c-decls.c (original)
+++ cfe/trunk/test/Index/comment-c-decls.c Thu Jan 10 07:24:24 2013
@@ -73,7 +73,7 @@
*/
double dS1;
};
-// CHECK: <Declaration>struct S {\n}</Declaration>
+// CHECK: <Declaration>struct S {}</Declaration>
// CHECK: <Declaration>int iS1</Declaration>
// CHECK: <Declaration>double dS1</Declaration>
@@ -101,4 +101,4 @@
*\brief block declaration
*/
int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; };
-// CHECK: <Declaration>int (^Block1)(int, int) = ^(int i, int j) {\n}</Declaration>
+// CHECK: <Declaration>int (^Block1)(int, int) = ^(int i, int j) {}</Declaration>
Modified: cfe/trunk/test/Index/comment-cplus-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-cplus-decls.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-cplus-decls.cpp (original)
+++ cfe/trunk/test/Index/comment-cplus-decls.cpp Thu Jan 10 07:24:24 2013
@@ -39,7 +39,7 @@
*/
data* reserved;
};
-// CHECK: <Declaration>class Test {\n}</Declaration>
+// CHECK: <Declaration>class Test {}</Declaration>
// CHECK: <Declaration>Test() : reserved(new Test::data())</Declaration>
// CHECK: <Declaration>unsigned int getID() const</Declaration>
// CHECK: <Declaration>void ~Test()</Declaration>
Modified: cfe/trunk/test/Index/comment-cplus-template-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-cplus-template-decls.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-cplus-template-decls.cpp (original)
+++ cfe/trunk/test/Index/comment-cplus-template-decls.cpp Thu Jan 10 07:24:24 2013
@@ -25,7 +25,7 @@
*/
void f() { }
};
-// CHECK: <Declaration>template <typename T> struct A {\n}</Declaration>
+// CHECK: <Declaration>template <typename T> struct A {}</Declaration>
// CHECK: <Declaration>A<T>()</Declaration>
// CHECK: <Declaration>void ~A<T>()</Declaration>
@@ -40,7 +40,7 @@
void f();
};
-// CHECK: <Declaration>template <typename T> struct D : A<T> {\n}</Declaration>
+// CHECK: <Declaration>template <typename T> struct D : A<T> {}</Declaration>
// CHECK: <Declaration>using A<T>::f</Declaration>
struct Base {
@@ -55,7 +55,7 @@
*/
using Base::foo;
};
-// CHECK: <Declaration>template <typename T> struct E : Base {\n}</Declaration>
+// CHECK: <Declaration>template <typename T> struct E : Base {}</Declaration>
// CHECK: <Declaration>using Base::foo</Declaration>
/// \tparam
@@ -66,4 +66,4 @@
template<template<template<typename CCC> class DDD, class BBB> class AAA>
void func_template_2();
-<Declaration>template <template <template <typename CCC> class DDD, class BBB> class AAA> void func_template_2()</Declaration>
+// FIXME: There is not Declaration field in the generated output.
Modified: cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp (original)
+++ cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp Thu Jan 10 07:24:24 2013
@@ -588,7 +588,7 @@
/// Aaa.
class comment_to_xml_conversion_01 {
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:7: ClassDecl=comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[<Class file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="7"><Name>comment_to_xml_conversion_01</Name><USR>c:@C at comment_to_xml_conversion_01</USR><Declaration>class comment_to_xml_conversion_01 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:7: ClassDecl=comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[<Class file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="7"><Name>comment_to_xml_conversion_01</Name><USR>c:@C at comment_to_xml_conversion_01</USR><Declaration>class comment_to_xml_conversion_01 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// \param aaa Blah blah.
comment_to_xml_conversion_01(int aaa);
@@ -645,7 +645,7 @@
template<typename T, typename U>
class comment_to_xml_conversion_08 { };
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:9: ClassTemplate=comment_to_xml_conversion_08:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="9"><Name>comment_to_xml_conversion_08</Name><USR>c:@C at comment_to_xml_conversion_01@CT>2#T#T at comment_to_xml_conversion_08</USR><Declaration>template <typename T, typename U> class comment_to_xml_conversion_08 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:9: ClassTemplate=comment_to_xml_conversion_08:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="9"><Name>comment_to_xml_conversion_08</Name><USR>c:@C at comment_to_xml_conversion_01@CT>2#T#T at comment_to_xml_conversion_08</USR><Declaration>template <typename T, typename U> class comment_to_xml_conversion_08 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// Aaa.
template<typename T>
@@ -670,19 +670,19 @@
template<typename T, typename U>
class comment_to_xml_conversion_11 { };
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplate=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CT>2#T#T at comment_to_xml_conversion_11</USR><Declaration>template <typename T, typename U> class comment_to_xml_conversion_11 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplate=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CT>2#T#T at comment_to_xml_conversion_11</USR><Declaration>template <typename T, typename U> class comment_to_xml_conversion_11 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// Aaa.
template<typename T>
class comment_to_xml_conversion_11<T, int> { };
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplatePartialSpecialization=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="partialSpecialization" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CP>1#T at comment_to_xml_conversion_11>#t0.0#I</USR><Declaration>class comment_to_xml_conversion_11 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplatePartialSpecialization=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="partialSpecialization" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CP>1#T at comment_to_xml_conversion_11>#t0.0#I</USR><Declaration>class comment_to_xml_conversion_11 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// Aaa.
template<>
class comment_to_xml_conversion_11<int, int> { };
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassDecl=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="specialization" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@C at comment_to_xml_conversion_11>#I#I</USR><Declaration>class comment_to_xml_conversion_11 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassDecl=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="specialization" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@C at comment_to_xml_conversion_11>#I#I</USR><Declaration>class comment_to_xml_conversion_11 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// Aaa.
int comment_to_xml_conversion_12;
@@ -691,11 +691,11 @@
/// Aaa.
namespace comment_to_xml_conversion_13 {
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:11: Namespace=comment_to_xml_conversion_13:{{.*}} FullCommentAsXML=[<Namespace file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="11"><Name>comment_to_xml_conversion_13</Name><USR>c:@N at comment_to_xml_conversion_13</USR><Declaration>namespace comment_to_xml_conversion_13 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Namespace>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:11: Namespace=comment_to_xml_conversion_13:{{.*}} FullCommentAsXML=[<Namespace file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="11"><Name>comment_to_xml_conversion_13</Name><USR>c:@N at comment_to_xml_conversion_13</USR><Declaration>namespace comment_to_xml_conversion_13 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Namespace>]
/// Aaa.
namespace comment_to_xml_conversion_14 {
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:13: Namespace=comment_to_xml_conversion_14:{{.*}} FullCommentAsXML=[<Namespace file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="13"><Name>comment_to_xml_conversion_14</Name><USR>c:@N at comment_to_xml_conversion_13@N at comment_to_xml_conversion_14</USR><Declaration>namespace comment_to_xml_conversion_14 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Namespace>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:13: Namespace=comment_to_xml_conversion_14:{{.*}} FullCommentAsXML=[<Namespace file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="13"><Name>comment_to_xml_conversion_14</Name><USR>c:@N at comment_to_xml_conversion_13@N at comment_to_xml_conversion_14</USR><Declaration>namespace comment_to_xml_conversion_14 {}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Namespace>]
}
}
Modified: cfe/trunk/test/Index/format-comment-cdecls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/format-comment-cdecls.c?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/test/Index/format-comment-cdecls.c (original)
+++ cfe/trunk/test/Index/format-comment-cdecls.c Thu Jan 10 07:24:24 2013
@@ -68,7 +68,7 @@
*/
double dS1;
};
-// CHECK: <Declaration>struct S {\n}</Declaration>
+// CHECK: <Declaration>struct S {}</Declaration>
// CHECK: <Declaration>int iS1</Declaration>
// CHECK: <Declaration>double dS1</Declaration>
@@ -96,4 +96,4 @@
*\brief block declaration
*/
int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; };
-// CHECK: <Declaration>int (^Block1)(int, int) = ^(int i, int j) {\n}</Declaration>
+// CHECK: <Declaration>int (^Block1)(int, int) = ^(int i, int j) {}</Declaration>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172067&r1=172066&r2=172067&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 10 07:24:24 2013
@@ -115,7 +115,7 @@
}
TEST_F(FormatTest, FormatsNestedBlockStatements) {
- EXPECT_EQ("{\n {\n {\n }\n }\n}", format("{{{}}}"));
+ EXPECT_EQ("{\n {\n {}\n }\n}", format("{{{}}}"));
}
TEST_F(FormatTest, FormatsNestedCall) {
@@ -163,9 +163,7 @@
}
TEST_F(FormatTest, ElseIf) {
- verifyFormat("if (a) {\n"
- "} else if (b) {\n"
- "}");
+ verifyFormat("if (a) {} else if (b) {}");
verifyFormat("if (a)\n"
" f();\n"
"else if (b)\n"
@@ -181,8 +179,7 @@
" ;");
verifyFormat("for (;;)\n"
" f();");
- verifyFormat("for (;;) {\n"
- "}");
+ verifyFormat("for (;;) {}");
verifyFormat("for (;;) {\n"
" f();\n"
"}");
@@ -190,19 +187,18 @@
verifyFormat(
"for (std::vector<UnwrappedLine>::iterator I = UnwrappedLines.begin(),\n"
" E = UnwrappedLines.end();\n"
- " I != E; ++I) {\n}");
+ " I != E; ++I) {}");
verifyFormat(
"for (MachineFun::iterator IIII = PrevIt, EEEE = F.end(); IIII != EEEE;\n"
- " ++IIIII) {\n}");
+ " ++IIIII) {}");
}
TEST_F(FormatTest, FormatsWhileLoop) {
- verifyFormat("while (true) {\n}");
+ verifyFormat("while (true) {}");
verifyFormat("while (true)\n"
" f();");
- verifyFormat("while () {\n"
- "}");
+ verifyFormat("while () {}");
verifyFormat("while () {\n"
" f();\n"
"}");
@@ -283,7 +279,7 @@
TEST_F(FormatTest, UnderstandsSingleLineComments) {
verifyFormat("// line 1\n"
"// line 2\n"
- "void f() {\n}\n");
+ "void f() {}\n");
verifyFormat("void f() {\n"
" // Doesn't do anything\n"
@@ -320,7 +316,7 @@
//===----------------------------------------------------------------------===//
TEST_F(FormatTest, DoesNotBreakSemiAfterClassDecl) {
- verifyFormat("class A {\n};");
+ verifyFormat("class A {};");
}
TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
@@ -328,30 +324,24 @@
"public:\n"
"protected:\n"
"private:\n"
- " void f() {\n"
- " }\n"
+ " void f() {}\n"
"};");
verifyGoogleFormat("class A {\n"
" public:\n"
" protected:\n"
" private:\n"
- " void f() {\n"
- " }\n"
+ " void f() {}\n"
"};");
}
TEST_F(FormatTest, FormatsDerivedClass) {
- verifyFormat("class A : public B {\n"
- "};");
- verifyFormat("class A : public ::B {\n"
- "};");
+ verifyFormat("class A : public B {};");
+ verifyFormat("class A : public ::B {};");
}
TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
- verifyFormat("class A {\n"
- "} a, b;");
- verifyFormat("struct A {\n"
- "} a, b;");
+ verifyFormat("class A {} a, b;");
+ verifyFormat("struct A {} a, b;");
}
TEST_F(FormatTest, FormatsEnum) {
@@ -371,29 +361,25 @@
TEST_F(FormatTest, FormatsNamespaces) {
verifyFormat("namespace some_namespace {\n"
- "class A {\n"
- "};\n"
+ "class A {};\n"
"void f() {\n"
" f();\n"
"}\n"
"}");
verifyFormat("namespace {\n"
- "class A {\n"
- "};\n"
+ "class A {};\n"
"void f() {\n"
" f();\n"
"}\n"
"}");
verifyFormat("inline namespace X {\n"
- "class A {\n"
- "};\n"
+ "class A {};\n"
"void f() {\n"
" f();\n"
"}\n"
"}");
verifyFormat("using namespace some_namespace;\n"
- "class A {\n"
- "};\n"
+ "class A {};\n"
"void f() {\n"
" f();\n"
"}");
@@ -419,8 +405,7 @@
"}");
verifyFormat("class A {\n"
" int a;\n"
- " A() try : a(0) {\n"
- " }\n"
+ " A() try : a(0) {}\n"
" catch (...) {\n"
" throw;\n"
" }\n"
@@ -519,7 +504,7 @@
}
TEST_F(FormatTest, LayoutRemainingTokens) {
- EXPECT_EQ("{\n}", format("{}"));
+ EXPECT_EQ("{}", format("{}"));
}
TEST_F(FormatTest, LayoutSingleUnwrappedLineInMacro) {
@@ -635,6 +620,10 @@
"}");
}
+TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
+ EXPECT_EQ("{}", format("{}"));
+}
+
//===----------------------------------------------------------------------===//
// Line break tests.
//===----------------------------------------------------------------------===//
@@ -642,8 +631,7 @@
TEST_F(FormatTest, FormatsFunctionDefinition) {
verifyFormat("void f(int a, int b, int c, int d, int e, int f, int g,"
" int h, int j, int f,\n"
- " int c, int ddddddddddddd) {\n"
- "}");
+ " int c, int ddddddddddddd) {}");
}
TEST_F(FormatTest, FormatsAwesomeMethodCall) {
@@ -654,33 +642,29 @@
}
TEST_F(FormatTest, ConstructorInitializers) {
- verifyFormat("Constructor() : Initializer(FitsOnTheLine) {\n}");
+ verifyFormat("Constructor() : Initializer(FitsOnTheLine) {}");
verifyFormat(
"SomeClass::Constructor()\n"
- " : aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {\n"
- "}");
+ " : aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}");
verifyFormat(
"SomeClass::Constructor()\n"
" : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
- " aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {\n"
- "}");
+ " aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}");
verifyFormat("Constructor()\n"
" : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
" aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
- " aaaaaaaaaaaaaaaaaaaaaaa() {\n"
- "}");
+ " aaaaaaaaaaaaaaaaaaaaaaa() {}");
// Here a line could be saved by splitting the second initializer onto two
// lines, but that is not desireable.
verifyFormat("Constructor()\n"
" : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaa),\n"
" aaaaaaaaaaa(aaaaaaaaaaa),\n"
- " aaaaaaaaaaaaaaaaaaaaat(aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
- "}");
+ " aaaaaaaaaaaaaaaaaaaaat(aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
verifyGoogleFormat("MyClass::MyClass(int var)\n"
" : some_var_(var), // 4 space indent\n"
@@ -698,11 +682,11 @@
TEST_F(FormatTest, BreaksDesireably) {
verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
" aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
- " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {\n}");
+ " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {}");
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
@@ -739,14 +723,14 @@
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
verifyFormat(
"if (aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
- " bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) {\n}");
+ " bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) {}");
verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
- " ccccccccccccccccccccccccc) {\n}");
+ " ccccccccccccccccccccccccc) {}");
verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
- " ccccccccccccccccccccccccc) {\n}");
+ " ccccccccccccccccccccccccc) {}");
verifyFormat(
"if ((aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb) &&\n"
- " ccccccccccccccccccccccccc) {\n}");
+ " ccccccccccccccccccccccccc) {}");
}
TEST_F(FormatTest, PrefersNotToBreakAfterAssignments) {
@@ -833,19 +817,17 @@
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
verifyFormat(
"if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
- "}");
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
verifyFormat(
"if (a) {\n"
+ " f();\n"
"} else if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
- "}");
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
verifyFormat(
// FIXME: Does an expression like this ever make sense? If yes, fix.
"if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 100000000 +\n"
- " 10000000) {\n"
- "}");
+ " 10000000) {}");
}
TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
@@ -873,8 +855,7 @@
// Here, it is not necessary to wrap at "." or "->".
verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaa) ||\n"
- " aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
- "}");
+ " aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}");
verifyFormat(
"aaaaaaaaaaa->aaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
@@ -924,7 +905,7 @@
verifyFormat("test << a >> b;");
verifyFormat("f<int>();");
- verifyFormat("template <typename T> void f() {\n}");
+ verifyFormat("template <typename T> void f() {}");
}
TEST_F(FormatTest, UnderstandsUnaryOperators) {
@@ -932,13 +913,13 @@
verifyFormat("f(-1, -2, -3);");
verifyFormat("a[-1] = 5;");
verifyFormat("int a = 5 + -2;");
- verifyFormat("if (i == -1) {\n}");
- verifyFormat("if (i != -1) {\n}");
- verifyFormat("if (i > -1) {\n}");
- verifyFormat("if (i < -1) {\n}");
+ verifyFormat("if (i == -1) {}");
+ verifyFormat("if (i != -1) {}");
+ verifyFormat("if (i > -1) {}");
+ verifyFormat("if (i < -1) {}");
verifyFormat("++(a->f());");
verifyFormat("--(a->f());");
- verifyFormat("if (!(a->f())) {\n}");
+ verifyFormat("if (!(a->f())) {}");
verifyFormat("a-- > b;");
verifyFormat("b ? -a : c;");
@@ -974,7 +955,7 @@
}
TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
- verifyFormat("int *f(int *a) {\n}");
+ verifyFormat("int *f(int *a) {}");
verifyFormat("f(a, *a);");
verifyFormat("f(*a);");
verifyFormat("int a = b * 10;");
@@ -987,7 +968,7 @@
verifyFormat("int a = *b;");
verifyFormat("int a = *b * c;");
verifyFormat("int a = b * *c;");
- verifyFormat("int main(int argc, char **argv) {\n}");
+ verifyFormat("int main(int argc, char **argv) {}");
verifyFormat("return 10 * b;");
verifyFormat("return *b * *c;");
verifyFormat("return a & ~b;");
@@ -1016,7 +997,7 @@
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
- verifyGoogleFormat("int main(int argc, char** argv) {\n}");
+ verifyGoogleFormat("int main(int argc, char** argv) {}");
verifyGoogleFormat("A<int*> a;");
verifyGoogleFormat("A<int**> a;");
verifyGoogleFormat("A<int*, int*> a;");
@@ -1036,11 +1017,11 @@
TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
verifyFormat("int *someFunction(int LoooooooooooooooongParam1,\n"
- " int LoooooooooooooooongParam2) {\n}");
+ " int LoooooooooooooooongParam2) {}");
verifyFormat(
"TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n"
" SourceLocation L, IdentifierIn *II,\n"
- " Type *T) {\n}");
+ " Type *T) {}");
}
TEST_F(FormatTest, LineStartsWithSpecialCharacter) {
@@ -1083,17 +1064,14 @@
verifyFormat("public:");
verifyFormat("class A {\n"
"public\n"
- " void f() {\n"
- " }\n"
+ " void f() {}\n"
"};");
verifyFormat("public\n"
"int qwerty;");
verifyFormat("public\n"
- "B {\n"
- "}");
+ "B {}");
verifyFormat("public\n"
- "{\n"
- "}");
+ "{}");
verifyFormat("public\n"
"B {\n"
" int x;\n"
@@ -1105,13 +1083,10 @@
}
TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
- verifyFormat("do {\n"
- "}");
- verifyFormat("do {\n"
- "}\n"
+ verifyFormat("do {}");
+ verifyFormat("do {}\n"
"f();");
- verifyFormat("do {\n"
- "}\n"
+ verifyFormat("do {}\n"
"wheeee(fun);");
verifyFormat("do {\n"
" f();\n"
@@ -1124,10 +1099,10 @@
}
TEST_F(FormatTest, IncorrectCodeErrorDetection) {
- EXPECT_EQ("{\n{\n}\n", format("{\n{\n}\n"));
- EXPECT_EQ("{\n {\n}\n", format("{\n {\n}\n"));
- EXPECT_EQ("{\n {\n }\n", format("{\n {\n }\n"));
- EXPECT_EQ("{\n {\n }\n }\n}\n", format("{\n {\n }\n }\n}\n"));
+ EXPECT_EQ("{\n{}\n", format("{\n{\n}\n"));
+ EXPECT_EQ("{\n {}\n", format("{\n {\n}\n"));
+ EXPECT_EQ("{\n {}\n", format("{\n {\n }\n"));
+ EXPECT_EQ("{\n {}\n }\n}\n", format("{\n {\n }\n }\n}\n"));
FormatStyle Style = getLLVMStyle();
Style.ColumnLimit = 10;
@@ -1296,8 +1271,7 @@
"@package\n"
" int field4;\n"
"}\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
verifyGoogleFormat("@implementation Foo : NSObject {\n"
@@ -1310,8 +1284,7 @@
" @package\n"
" int field4;\n"
"}\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
verifyFormat("@implementation Foo\n"
@@ -1331,28 +1304,24 @@
"@end");
verifyFormat("@implementation Foo : Bar\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
verifyFormat("@implementation Foo {\n"
" int _i;\n"
"}\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
verifyFormat("@implementation Foo : Bar {\n"
" int _i;\n"
"}\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
// FIXME: there should be a space before '(' for categories.
verifyFormat("@implementation Foo(HackStuff)\n"
- "+ (id)init {\n"
- "}\n"
+ "+ (id)init {}\n"
"@end");
}
More information about the cfe-commits
mailing list