diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-01-10 23:11:41 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-01-10 23:11:41 +0000 |
commit | cd52bdaaf076b0082c07c6b3d88937fb737054f1 (patch) | |
tree | fca5b9845970173d5ca3678e4ff7517407ff14b3 /unittests/Format/FormatTest.cpp | |
parent | 664566c37f81d70226df22c12aa05d1603b620f3 (diff) |
Formatter: Put spaces in ObjC method decls in the right place for Google style.
Objective-C method declarations look like this:
- (returntype)name:(type)argname anothername:(type)arg2name;
In google style, there's no space after the leading '-' but one after
"(returntype)" instead (but none after the argument types), see
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions
Not inserting the space after '-' is easy, but to insert the space after the
return type, the formatter needs to know that a closing parenthesis ends the
return type. To do this, I tweaked the code in parse() to check for this, which
in turn required moving detection of TT_ObjCMethodSpecifier from annotate() to
parse(), because parse() runs before annotate().
(To keep things interesting, the return type is optional, but it's almost
always there in practice.)
http://llvm-reviews.chandlerc.com/D280
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index deb668d984..1d6cff152d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1178,10 +1178,18 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) { "outRange8:(NSRange) out_range8 outRange9:(NSRange) out_range9;")); verifyFormat("- (int)sum:(vector<int>)numbers;"); - verifyGoogleFormat("- (void)setDelegate:(id<Protocol>)delegate;"); + verifyGoogleFormat("-(void) setDelegate:(id<Protocol>)delegate;"); // FIXME: In LLVM style, there should be a space in front of a '<' for ObjC // protocol lists (but not for template classes): //verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;"); + + verifyFormat("- (int(*)())foo:(int(*)())f;"); + verifyGoogleFormat("-(int(*)()) foo:(int(*)())foo;"); + + // If there's no return type (very rare in practice!), LLVM and Google style + // agree. + verifyFormat("- foo:(int)f;"); + verifyGoogleFormat("- foo:(int)foo;"); } TEST_F(FormatTest, FormatObjCBlocks) { @@ -1191,7 +1199,6 @@ TEST_F(FormatTest, FormatObjCBlocks) { TEST_F(FormatTest, FormatObjCInterface) { // FIXME: Handle comments like in "@interface /* wait for it */ Foo", PR14875 - // FIXME: In google style, it's "+(id) init", not "+ (id)init". verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n" "@public\n" " int field1;\n" @@ -1215,7 +1222,7 @@ TEST_F(FormatTest, FormatObjCInterface) { " @package\n" " int field4;\n" "}\n" - "+ (id)init;\n" + "+(id) init;\n" "@end"); verifyFormat("@interface Foo\n" @@ -1238,7 +1245,7 @@ TEST_F(FormatTest, FormatObjCInterface) { "@end"); verifyGoogleFormat("@interface Foo : Bar<Baz, Quux>\n" - "+ (id)init;\n" + "+(id) init;\n" "@end"); verifyFormat("@interface Foo (HackStuff)\n" @@ -1254,7 +1261,7 @@ TEST_F(FormatTest, FormatObjCInterface) { "@end"); verifyGoogleFormat("@interface Foo (HackStuff)<MyProtocol>\n" - "+ (id)init;\n" + "+(id) init;\n" "@end"); verifyFormat("@interface Foo {\n" @@ -1318,7 +1325,7 @@ TEST_F(FormatTest, FormatObjCImplementation) { " @package\n" " int field4;\n" "}\n" - "+ (id)init {}\n" + "+(id) init {}\n" "@end"); verifyFormat("@implementation Foo\n" @@ -1369,7 +1376,7 @@ TEST_F(FormatTest, FormatObjCProtocol) { "@end"); verifyGoogleFormat("@protocol MyProtocol<NSObject>\n" - "- (NSUInteger)numberOfThings;\n" + "-(NSUInteger) numberOfThings;\n" "@end"); verifyFormat("@protocol Foo;\n" |