diff options
author | Daniel Jasper <djasper@google.com> | 2013-03-01 17:13:29 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-03-01 17:13:29 +0000 |
commit | 8a5d7cd100ebfb8c6b353ee4ad5b14ab4105d32d (patch) | |
tree | 7533ffe23c41a82b1630321db78f7fe680e7f468 /unittests/Format/FormatTest.cpp | |
parent | 9b5b65957c6830af92dd1d62cbf8e341c95bc283 (diff) |
Correctly format arrays of pointers and function types.
Before:
void f(Type(*parameter)[10]) {}
int(*func)(void *);
After:
void f(Type (*parameter)[10]) {}
int (*func)(void *);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176356 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9b640cb907..64de86a926 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1812,7 +1812,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("int main(int argc, char **argv) {}"); verifyFormat("Test::Test(int b) : a(b * b) {}"); verifyIndependentOfContext("f(a, *a);"); - verifyIndependentOfContext("f(*a);"); + verifyFormat("void g() { f(*a); }"); verifyIndependentOfContext("int a = b * 10;"); verifyIndependentOfContext("int a = 10 * b;"); verifyIndependentOfContext("int a = b * c;"); @@ -1845,6 +1845,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("return sizeof(int **);"); verifyIndependentOfContext("return sizeof(int ******);"); verifyIndependentOfContext("return (int **&)a;"); + verifyFormat("void f(Type (*parameter)[10]) {}"); verifyGoogleFormat("return sizeof(int**);"); verifyIndependentOfContext("Type **A = static_cast<Type **>(P);"); verifyGoogleFormat("Type** A = static_cast<Type**>(P);"); @@ -1884,7 +1885,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("a = &(x + y);"); verifyIndependentOfContext("*(x + y).call();"); verifyIndependentOfContext("&(x + y)->call();"); - verifyIndependentOfContext("&(*I).first"); + verifyFormat("void f() { &(*I).first; }"); verifyIndependentOfContext("f(b * /* confusing comment */ ++c);"); verifyFormat( @@ -1909,7 +1910,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("A = new SomeType *[Length]();"); verifyGoogleFormat("A = new SomeType* [Length]();"); +} +TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) { EXPECT_EQ("int *a;\n" "int *a;\n" "int *a;", @@ -1977,12 +1980,13 @@ TEST_F(FormatTest, FormatsCasts) { } TEST_F(FormatTest, FormatsFunctionTypes) { - // FIXME: Determine the cases that need a space after the return type and fix. verifyFormat("A<bool()> a;"); verifyFormat("A<SomeType()> a;"); verifyFormat("A<void(*)(int, std::string)> a;"); - verifyFormat("int(*func)(void *);"); + // FIXME: Inconsistent. + verifyFormat("int (*func)(void *);"); + verifyFormat("void f() { int(*func)(void *); }"); } TEST_F(FormatTest, BreaksLongDeclarations) { |