summaryrefslogtreecommitdiff
path: root/unittests/Format
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2018-03-22 03:23:53 +0000
committerBen Hamilton <benhamilton@google.com>2018-03-22 03:23:53 +0000
commit23ecb164a296cf283a63fd69c179e0d4b4068565 (patch)
treee5b6a5edc8d3a20f9f0f5dd21fb2286cbf8cc0ab /unittests/Format
parentac4ba722eda7d90a9414575c9bd80e1416056f5f (diff)
downloadclang-23ecb164a296cf283a63fd69c179e0d4b4068565.tar.gz
[clang-format] Don't insert space between r_paren and 'new' in ObjC decl
Summary: Previously, clang-format would insert a space between the closing parenthesis and 'new' in the following valid Objective-C declaration: + (instancetype)new; This was because 'new' is treated as a keyword, not an identifier. TokenAnnotator::spaceRequiredBefore() already handled the case where r_paren came before an identifier, so this diff extends it to handle r_paren before 'new'. Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak, stephanemoore Reviewed By: djasper, jolesiak, stephanemoore Subscribers: stephanemoore, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44692 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328174 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format')
-rw-r--r--unittests/Format/FormatTestObjC.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/unittests/Format/FormatTestObjC.cpp b/unittests/Format/FormatTestObjC.cpp
index 35c4d88638..51443c0f39 100644
--- a/unittests/Format/FormatTestObjC.cpp
+++ b/unittests/Format/FormatTestObjC.cpp
@@ -514,6 +514,7 @@ TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) {
" evenLongerKeyword:(float)theInterval\n"
" error:(NSError **)theError {\n"
"}");
+ verifyFormat("+ (instancetype)new;\n");
Style.ColumnLimit = 60;
verifyFormat("- (instancetype)initXxxxxx:(id<x>)x\n"
" y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n"
@@ -914,6 +915,17 @@ TEST_F(FormatTestObjC, ObjCForIn) {
" }]) {\n}");
}
+TEST_F(FormatTestObjC, ObjCNew) {
+ verifyFormat("+ (instancetype)new {\n"
+ " return nil;\n"
+ "}\n");
+ verifyFormat("+ (instancetype)myNew {\n"
+ " return [self new];\n"
+ "}\n");
+ verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
+ verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+}
+
TEST_F(FormatTestObjC, ObjCLiterals) {
verifyFormat("@\"String\"");
verifyFormat("@1");