aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-01-09 23:25:37 +0000
committerNico Weber <nicolasweber@gmx.de>2013-01-09 23:25:37 +0000
commit50767d8c8f2f667255bdb99692c0467ce992bc67 (patch)
treebcdb26efc63c5f9b5810aeebb34b66e545ca0ee3 /unittests/Format/FormatTest.cpp
parentd017e42af00c2e7c380d0f9b27c81734f4b2844e (diff)
Formatter: Add support for @implementation.
Just reuse the @interface code for this. It accepts slightly more than necessary (@implementation cannot have protocol lists), but that's ok. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172019 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 15fe9aa9d7..b536e012eb 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1251,6 +1251,77 @@ TEST_F(FormatTest, FormatObjCInterface) {
"@end");
}
+TEST_F(FormatTest, FormatObjCImplementation) {
+ verifyFormat("@implementation Foo : NSObject {\n"
+ "@public\n"
+ " int field1;\n"
+ "@protected\n"
+ " int field2;\n"
+ "@private\n"
+ " int field3;\n"
+ "@package\n"
+ " int field4;\n"
+ "}\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+
+ verifyGoogleFormat("@implementation Foo : NSObject {\n"
+ " @public\n"
+ " int field1;\n"
+ " @protected\n"
+ " int field2;\n"
+ " @private\n"
+ " int field3;\n"
+ " @package\n"
+ " int field4;\n"
+ "}\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+
+ verifyFormat("@implementation Foo\n"
+ "+ (id)init {\n"
+ " if (true)\n"
+ " return nil;\n"
+ "}\n"
+ "// Look, a comment!\n"
+ "- (int)answerWith:(int)i {\n"
+ " return i;\n"
+ "}\n"
+ "@end");
+
+ verifyFormat("@implementation Foo\n"
+ "@end\n"
+ "@implementation Bar\n"
+ "@end");
+
+ verifyFormat("@implementation Foo : Bar\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+
+ verifyFormat("@implementation Foo {\n"
+ " int _i;\n"
+ "}\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+
+ verifyFormat("@implementation Foo : Bar {\n"
+ " int _i;\n"
+ "}\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+
+ // FIXME: there should be a space before '(' for categories.
+ verifyFormat("@implementation Foo(HackStuff)\n"
+ "+ (id)init {\n"
+ "}\n"
+ "@end");
+}
+
TEST_F(FormatTest, FormatObjCProtocol) {
verifyFormat("@protocol Foo\n"
"@property(weak) id delegate;\n"