blob: d592b39a482e9138b372ce3c18ae10296888609f [file] [log] [blame]
Daniel Jasper03a04fe2016-12-12 12:42:29 +00001//===- unittest/Format/FormatTestObjC.cpp - Formatting unit tests----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang/Format/Format.h"
11
12#include "../Tooling/ReplacementTest.h"
13#include "FormatTestUtils.h"
14
15#include "clang/Frontend/TextDiagnosticPrinter.h"
16#include "llvm/Support/Debug.h"
17#include "llvm/Support/MemoryBuffer.h"
18#include "gtest/gtest.h"
19
20#define DEBUG_TYPE "format-test"
21
22using clang::tooling::ReplacementTest;
Daniel Jasper03a04fe2016-12-12 12:42:29 +000023
24namespace clang {
25namespace format {
26namespace {
27
28class FormatTestObjC : public ::testing::Test {
29protected:
30 FormatTestObjC() {
31 Style = getLLVMStyle();
32 Style.Language = FormatStyle::LK_ObjC;
33 }
34
Krasimir Georgievbcda54b2017-04-21 14:35:20 +000035 enum StatusCheck {
36 SC_ExpectComplete,
37 SC_ExpectIncomplete,
38 SC_DoNotCheck
Daniel Jasper03a04fe2016-12-12 12:42:29 +000039 };
40
41 std::string format(llvm::StringRef Code,
Krasimir Georgievbcda54b2017-04-21 14:35:20 +000042 StatusCheck CheckComplete = SC_ExpectComplete) {
Daniel Jasper03a04fe2016-12-12 12:42:29 +000043 DEBUG(llvm::errs() << "---\n");
44 DEBUG(llvm::errs() << Code << "\n\n");
45 std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size()));
Krasimir Georgievbcda54b2017-04-21 14:35:20 +000046 FormattingAttemptStatus Status;
Daniel Jasper03a04fe2016-12-12 12:42:29 +000047 tooling::Replacements Replaces =
Krasimir Georgievbcda54b2017-04-21 14:35:20 +000048 reformat(Style, Code, Ranges, "<stdin>", &Status);
49 if (CheckComplete != SC_DoNotCheck) {
50 bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
51 EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
52 << Code << "\n\n";
Daniel Jasper03a04fe2016-12-12 12:42:29 +000053 }
54 auto Result = applyAllReplacements(Code, Replaces);
55 EXPECT_TRUE(static_cast<bool>(Result));
56 DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
57 return *Result;
58 }
59
60 void verifyFormat(StringRef Code) {
61 EXPECT_EQ(Code.str(), format(test::messUp(Code)));
62 }
63
64 void verifyIncompleteFormat(StringRef Code) {
Krasimir Georgievbcda54b2017-04-21 14:35:20 +000065 EXPECT_EQ(Code.str(), format(test::messUp(Code), SC_ExpectIncomplete));
Daniel Jasper03a04fe2016-12-12 12:42:29 +000066 }
67
68 FormatStyle Style;
69};
70
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000071TEST(FormatTestObjCStyle, DetectsObjCInHeaders) {
72 auto Style = getStyle("LLVM", "a.h", "none", "@interface\n"
73 "- (id)init;");
74 ASSERT_TRUE((bool)Style);
75 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
76
Daniel Jasper03a04fe2016-12-12 12:42:29 +000077 Style = getStyle("LLVM", "a.h", "none", "@interface\n"
78 "+ (id)init;");
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000079 ASSERT_TRUE((bool)Style);
80 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
Daniel Jasper03a04fe2016-12-12 12:42:29 +000081
Krasimir Georgiev11ef5312017-12-12 13:43:59 +000082 Style = getStyle("LLVM", "a.h", "none", "@interface\n"
83 "@end\n"
84 "//comment");
85 ASSERT_TRUE((bool)Style);
86 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
87
88 Style = getStyle("LLVM", "a.h", "none", "@interface\n"
89 "@end //comment");
90 ASSERT_TRUE((bool)Style);
91 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
92
Daniel Jasper03a04fe2016-12-12 12:42:29 +000093 // No recognizable ObjC.
94 Style = getStyle("LLVM", "a.h", "none", "void f() {}");
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000095 ASSERT_TRUE((bool)Style);
96 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Ben Hamiltone2e3e672018-01-17 17:33:08 +000097
98 Style = getStyle("{}", "a.h", "none", "@interface Foo\n@end\n");
99 ASSERT_TRUE((bool)Style);
100 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
101
102 Style = getStyle("{}", "a.h", "none",
103 "const int interface = 1;\nconst int end = 2;\n");
104 ASSERT_TRUE((bool)Style);
105 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
106
107 Style = getStyle("{}", "a.h", "none", "@protocol Foo\n@end\n");
108 ASSERT_TRUE((bool)Style);
109 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
110
111 Style = getStyle("{}", "a.h", "none",
112 "const int protocol = 1;\nconst int end = 2;\n");
113 ASSERT_TRUE((bool)Style);
114 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
115
Ben Hamiltone2e3e672018-01-17 17:33:08 +0000116 Style =
117 getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
118 ASSERT_TRUE((bool)Style);
119 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
120
121 Style = getStyle("{}", "a.h", "none", "enum Foo {};");
122 ASSERT_TRUE((bool)Style);
123 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
124
Ben Hamiltone2e3e672018-01-17 17:33:08 +0000125 Style =
126 getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n");
127 ASSERT_TRUE((bool)Style);
128 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
129
130 Style =
131 getStyle("{}", "a.h", "none", "inline void Foo() { Log(\"Foo\"); }\n");
132 ASSERT_TRUE((bool)Style);
133 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
134
135 Style =
136 getStyle("{}", "a.h", "none", "inline void Foo() { id = @[1, 2, 3]; }\n");
137 ASSERT_TRUE((bool)Style);
138 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
139
140 Style = getStyle("{}", "a.h", "none",
141 "inline void Foo() { id foo = @{1: 2, 3: 4, 5: 6}; }\n");
142 ASSERT_TRUE((bool)Style);
143 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
144
145 Style = getStyle("{}", "a.h", "none",
146 "inline void Foo() { int foo[] = {1, 2, 3}; }\n");
147 ASSERT_TRUE((bool)Style);
148 EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Jacek Olesiakce4f0af2018-02-15 08:47:56 +0000149
150 // ObjC characteristic types.
151 Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
152 ASSERT_TRUE((bool)Style);
153 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
154
155 Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
156 ASSERT_TRUE((bool)Style);
157 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
158
159 Style = getStyle("{}", "a.h", "none", "NSObject *Foo();\n");
160 ASSERT_TRUE((bool)Style);
161 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
162
163 Style = getStyle("{}", "a.h", "none", "NSSet *Foo();\n");
164 ASSERT_TRUE((bool)Style);
165 EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000166}
167
168TEST_F(FormatTestObjC, FormatObjCTryCatch) {
169 verifyFormat("@try {\n"
170 " f();\n"
171 "} @catch (NSException e) {\n"
172 " @throw;\n"
173 "} @finally {\n"
174 " exit(42);\n"
175 "}");
176 verifyFormat("DEBUG({\n"
177 " @try {\n"
178 " } @finally {\n"
179 " }\n"
180 "});\n");
181}
182
183TEST_F(FormatTestObjC, FormatObjCAutoreleasepool) {
184 verifyFormat("@autoreleasepool {\n"
185 " f();\n"
186 "}\n"
187 "@autoreleasepool {\n"
188 " f();\n"
189 "}\n");
190 Style.BreakBeforeBraces = FormatStyle::BS_Allman;
191 verifyFormat("@autoreleasepool\n"
192 "{\n"
193 " f();\n"
194 "}\n"
195 "@autoreleasepool\n"
196 "{\n"
197 " f();\n"
198 "}\n");
199}
200
Ben Hamilton56d1c012018-02-06 18:01:47 +0000201TEST_F(FormatTestObjC, FormatObjCGenerics) {
202 Style.ColumnLimit = 40;
203 verifyFormat("int aaaaaaaaaaaaaaaa(\n"
204 " NSArray<aaaaaaaaaaaaaaaaaa *>\n"
205 " aaaaaaaaaaaaaaaaa);\n");
206 verifyFormat("int aaaaaaaaaaaaaaaa(\n"
207 " NSArray<aaaaaaaaaaaaaaaaaaa<\n"
208 " aaaaaaaaaaaaaaaa *> *>\n"
209 " aaaaaaaaaaaaaaaaa);\n");
210}
211
Francois Ferrandba91c3d2018-02-27 13:48:21 +0000212TEST_F(FormatTestObjC, FormatObjCSynchronized) {
213 verifyFormat("@synchronized(self) {\n"
214 " f();\n"
215 "}\n"
216 "@synchronized(self) {\n"
217 " f();\n"
218 "}\n");
219 Style.BreakBeforeBraces = FormatStyle::BS_Allman;
220 verifyFormat("@synchronized(self)\n"
221 "{\n"
222 " f();\n"
223 "}\n"
224 "@synchronized(self)\n"
225 "{\n"
226 " f();\n"
227 "}\n");
228}
229
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000230TEST_F(FormatTestObjC, FormatObjCInterface) {
231 verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n"
232 "@public\n"
233 " int field1;\n"
234 "@protected\n"
235 " int field2;\n"
236 "@private\n"
237 " int field3;\n"
238 "@package\n"
239 " int field4;\n"
240 "}\n"
241 "+ (id)init;\n"
242 "@end");
243
244 verifyFormat("@interface /* wait for it */ Foo\n"
245 "+ (id)init;\n"
246 "// Look, a comment!\n"
247 "- (int)answerWith:(int)i;\n"
248 "@end");
249
250 verifyFormat("@interface Foo\n"
251 "@end\n"
252 "@interface Bar\n"
253 "@end");
254
255 verifyFormat("@interface Foo : Bar\n"
Nico Weberc068ff72018-01-23 17:10:25 +0000256 "@property(assign, readwrite) NSInteger bar;\n"
257 "+ (id)init;\n"
258 "@end");
259
260 verifyFormat("FOUNDATION_EXPORT NS_AVAILABLE_IOS(10.0) @interface Foo : Bar\n"
261 "@property(assign, readwrite) NSInteger bar;\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000262 "+ (id)init;\n"
263 "@end");
264
265 verifyFormat("@interface Foo : /**/ Bar /**/ <Baz, /**/ Quux>\n"
266 "+ (id)init;\n"
267 "@end");
268
269 verifyFormat("@interface Foo (HackStuff)\n"
270 "+ (id)init;\n"
271 "@end");
272
273 verifyFormat("@interface Foo ()\n"
274 "+ (id)init;\n"
275 "@end");
276
277 verifyFormat("@interface Foo (HackStuff) <MyProtocol>\n"
278 "+ (id)init;\n"
279 "@end");
280
281 verifyFormat("@interface Foo {\n"
282 " int _i;\n"
283 "}\n"
284 "+ (id)init;\n"
285 "@end");
286
287 verifyFormat("@interface Foo : Bar {\n"
288 " int _i;\n"
289 "}\n"
290 "+ (id)init;\n"
291 "@end");
292
293 verifyFormat("@interface Foo : Bar <Baz, Quux> {\n"
294 " int _i;\n"
295 "}\n"
296 "+ (id)init;\n"
297 "@end");
298
299 verifyFormat("@interface Foo (HackStuff) {\n"
300 " int _i;\n"
301 "}\n"
302 "+ (id)init;\n"
303 "@end");
304
305 verifyFormat("@interface Foo () {\n"
306 " int _i;\n"
307 "}\n"
308 "+ (id)init;\n"
309 "@end");
310
311 verifyFormat("@interface Foo (HackStuff) <MyProtocol> {\n"
312 " int _i;\n"
313 "}\n"
314 "+ (id)init;\n"
315 "@end");
316
Ben Hamilton5dd40182018-01-29 20:01:49 +0000317 Style.ColumnLimit = 40;
318 verifyFormat("@interface ccccccccccccc () <\n"
319 " ccccccccccccc, ccccccccccccc,\n"
320 " ccccccccccccc, ccccccccccccc> {\n"
321 "}");
Ben Hamilton4dc658c2018-02-02 20:15:14 +0000322 Style.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
Ben Hamilton5dd40182018-01-29 20:01:49 +0000323 verifyFormat("@interface ddddddddddddd () <\n"
324 " ddddddddddddd,\n"
325 " ddddddddddddd,\n"
326 " ddddddddddddd,\n"
327 " ddddddddddddd> {\n"
328 "}");
329
Ben Hamilton4dc658c2018-02-02 20:15:14 +0000330 Style.BinPackParameters = false;
331 Style.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
332 verifyFormat("@interface eeeeeeeeeeeee () <\n"
333 " eeeeeeeeeeeee,\n"
334 " eeeeeeeeeeeee,\n"
335 " eeeeeeeeeeeee,\n"
336 " eeeeeeeeeeeee> {\n"
337 "}");
338 Style.ObjCBinPackProtocolList = FormatStyle::BPS_Always;
339 verifyFormat("@interface fffffffffffff () <\n"
340 " fffffffffffff, fffffffffffff,\n"
341 " fffffffffffff, fffffffffffff> {\n"
342 "}");
343
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000344 Style = getGoogleStyle(FormatStyle::LK_ObjC);
Ben Hamiltonf84f1182018-01-18 18:37:16 +0000345 verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000346 " @public\n"
347 " int field1;\n"
348 " @protected\n"
349 " int field2;\n"
350 " @private\n"
351 " int field3;\n"
352 " @package\n"
353 " int field4;\n"
354 "}\n"
355 "+ (id)init;\n"
356 "@end");
Ben Hamiltonf84f1182018-01-18 18:37:16 +0000357 verifyFormat("@interface Foo : Bar <Baz, Quux>\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000358 "+ (id)init;\n"
359 "@end");
Ben Hamiltonf84f1182018-01-18 18:37:16 +0000360 verifyFormat("@interface Foo (HackStuff) <MyProtocol>\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000361 "+ (id)init;\n"
362 "@end");
Ben Hamilton3a47fdd2018-02-08 01:49:10 +0000363 Style.ColumnLimit = 40;
364 // BinPackParameters should be true by default.
365 verifyFormat("void eeeeeeee(int eeeee, int eeeee,\n"
366 " int eeeee, int eeeee);\n");
367 // ObjCBinPackProtocolList should be BPS_Never by default.
368 verifyFormat("@interface fffffffffffff () <\n"
369 " fffffffffffff,\n"
370 " fffffffffffff,\n"
371 " fffffffffffff,\n"
372 " fffffffffffff> {\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000373 "}");
374}
375
376TEST_F(FormatTestObjC, FormatObjCImplementation) {
377 verifyFormat("@implementation Foo : NSObject {\n"
378 "@public\n"
379 " int field1;\n"
380 "@protected\n"
381 " int field2;\n"
382 "@private\n"
383 " int field3;\n"
384 "@package\n"
385 " int field4;\n"
386 "}\n"
387 "+ (id)init {\n}\n"
388 "@end");
389
390 verifyFormat("@implementation Foo\n"
391 "+ (id)init {\n"
392 " if (true)\n"
393 " return nil;\n"
394 "}\n"
395 "// Look, a comment!\n"
396 "- (int)answerWith:(int)i {\n"
397 " return i;\n"
398 "}\n"
399 "+ (int)answerWith:(int)i {\n"
400 " return i;\n"
401 "}\n"
402 "@end");
403
404 verifyFormat("@implementation Foo\n"
405 "@end\n"
406 "@implementation Bar\n"
407 "@end");
408
409 EXPECT_EQ("@implementation Foo : Bar\n"
410 "+ (id)init {\n}\n"
411 "- (void)foo {\n}\n"
412 "@end",
413 format("@implementation Foo : Bar\n"
414 "+(id)init{}\n"
415 "-(void)foo{}\n"
416 "@end"));
417
418 verifyFormat("@implementation Foo {\n"
419 " int _i;\n"
420 "}\n"
421 "+ (id)init {\n}\n"
422 "@end");
423
424 verifyFormat("@implementation Foo : Bar {\n"
425 " int _i;\n"
426 "}\n"
427 "+ (id)init {\n}\n"
428 "@end");
429
430 verifyFormat("@implementation Foo (HackStuff)\n"
431 "+ (id)init {\n}\n"
432 "@end");
433 verifyFormat("@implementation ObjcClass\n"
434 "- (void)method;\n"
435 "{}\n"
436 "@end");
437
438 Style = getGoogleStyle(FormatStyle::LK_ObjC);
439 verifyFormat("@implementation Foo : NSObject {\n"
440 " @public\n"
441 " int field1;\n"
442 " @protected\n"
443 " int field2;\n"
444 " @private\n"
445 " int field3;\n"
446 " @package\n"
447 " int field4;\n"
448 "}\n"
449 "+ (id)init {\n}\n"
450 "@end");
451}
452
453TEST_F(FormatTestObjC, FormatObjCProtocol) {
454 verifyFormat("@protocol Foo\n"
455 "@property(weak) id delegate;\n"
456 "- (NSUInteger)numberOfThings;\n"
457 "@end");
458
459 verifyFormat("@protocol MyProtocol <NSObject>\n"
460 "- (NSUInteger)numberOfThings;\n"
461 "@end");
462
463 verifyFormat("@protocol Foo;\n"
464 "@protocol Bar;\n");
465
466 verifyFormat("@protocol Foo\n"
467 "@end\n"
468 "@protocol Bar\n"
469 "@end");
470
Nico Weberc068ff72018-01-23 17:10:25 +0000471 verifyFormat("FOUNDATION_EXPORT NS_AVAILABLE_IOS(10.0) @protocol Foo\n"
472 "@property(assign, readwrite) NSInteger bar;\n"
473 "@end");
474
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000475 verifyFormat("@protocol myProtocol\n"
476 "- (void)mandatoryWithInt:(int)i;\n"
477 "@optional\n"
478 "- (void)optional;\n"
479 "@required\n"
480 "- (void)required;\n"
481 "@optional\n"
482 "@property(assign) int madProp;\n"
483 "@end\n");
484
485 verifyFormat("@property(nonatomic, assign, readonly)\n"
486 " int *looooooooooooooooooooooooooooongNumber;\n"
487 "@property(nonatomic, assign, readonly)\n"
488 " NSString *looooooooooooooooooooooooooooongName;");
489
490 verifyFormat("@implementation PR18406\n"
491 "}\n"
492 "@end");
493
494 Style = getGoogleStyle(FormatStyle::LK_ObjC);
Ben Hamiltonf84f1182018-01-18 18:37:16 +0000495 verifyFormat("@protocol MyProtocol <NSObject>\n"
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000496 "- (NSUInteger)numberOfThings;\n"
497 "@end");
498}
499
500TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) {
501 verifyFormat("- (void)doSomethingWith:(GTMFoo *)theFoo\n"
502 " rect:(NSRect)theRect\n"
503 " interval:(float)theInterval {\n"
504 "}");
505 verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
506 " longKeyword:(NSRect)theRect\n"
507 " longerKeyword:(float)theInterval\n"
508 " error:(NSError **)theError {\n"
509 "}");
510 verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
511 " longKeyword:(NSRect)theRect\n"
512 " evenLongerKeyword:(float)theInterval\n"
513 " error:(NSError **)theError {\n"
514 "}");
515 Style.ColumnLimit = 60;
516 verifyFormat("- (instancetype)initXxxxxx:(id<x>)x\n"
517 " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n"
518 " NS_DESIGNATED_INITIALIZER;");
519 verifyFormat("- (void)drawRectOn:(id)surface\n"
520 " ofSize:(size_t)height\n"
521 " :(size_t)width;");
522
523 // Continuation indent width should win over aligning colons if the function
524 // name is long.
Ben Hamilton5b0c3ad2017-12-14 21:44:11 +0000525 Style = getGoogleStyle(FormatStyle::LK_ObjC);
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000526 Style.ColumnLimit = 40;
527 Style.IndentWrappedFunctionNames = true;
528 verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
529 " dontAlignNamef:(NSRect)theRect {\n"
530 "}");
531
532 // Make sure we don't break aligning for short parameter names.
533 verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
534 " aShortf:(NSRect)theRect {\n"
535 "}");
Ben Hamilton5b0c3ad2017-12-14 21:44:11 +0000536
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000537 // Format pairs correctly.
538 Style.ColumnLimit = 80;
539 verifyFormat("- (void)drawRectOn:(id)surface\n"
540 " ofSize:(aaaaaaaa)height\n"
541 " :(size_t)width\n"
542 " atOrigin:(size_t)x\n"
543 " :(size_t)y\n"
544 " aaaaa:(a)yyy\n"
545 " bbb:(d)cccc;");
546 verifyFormat("- (void)drawRectOn:(id)surface ofSize:(aaa)height:(bbb)width;");
547}
548
549TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
550 verifyFormat("[foo bar:baz];");
551 verifyFormat("return [foo bar:baz];");
552 verifyFormat("return (a)[foo bar:baz];");
553 verifyFormat("f([foo bar:baz]);");
554 verifyFormat("f(2, [foo bar:baz]);");
555 verifyFormat("f(2, a ? b : c);");
556 verifyFormat("[[self initWithInt:4] bar:[baz quux:arrrr]];");
557
558 // Unary operators.
559 verifyFormat("int a = +[foo bar:baz];");
560 verifyFormat("int a = -[foo bar:baz];");
561 verifyFormat("int a = ![foo bar:baz];");
562 verifyFormat("int a = ~[foo bar:baz];");
563 verifyFormat("int a = ++[foo bar:baz];");
564 verifyFormat("int a = --[foo bar:baz];");
565 verifyFormat("int a = sizeof [foo bar:baz];");
566 verifyFormat("int a = alignof [foo bar:baz];");
567 verifyFormat("int a = &[foo bar:baz];");
568 verifyFormat("int a = *[foo bar:baz];");
569 // FIXME: Make casts work, without breaking f()[4].
570 // verifyFormat("int a = (int)[foo bar:baz];");
571 // verifyFormat("return (int)[foo bar:baz];");
572 // verifyFormat("(void)[foo bar:baz];");
573 verifyFormat("return (MyType *)[self.tableView cellForRowAtIndexPath:cell];");
574
575 // Binary operators.
576 verifyFormat("[foo bar:baz], [foo bar:baz];");
577 verifyFormat("[foo bar:baz] = [foo bar:baz];");
578 verifyFormat("[foo bar:baz] *= [foo bar:baz];");
579 verifyFormat("[foo bar:baz] /= [foo bar:baz];");
580 verifyFormat("[foo bar:baz] %= [foo bar:baz];");
581 verifyFormat("[foo bar:baz] += [foo bar:baz];");
582 verifyFormat("[foo bar:baz] -= [foo bar:baz];");
583 verifyFormat("[foo bar:baz] <<= [foo bar:baz];");
584 verifyFormat("[foo bar:baz] >>= [foo bar:baz];");
585 verifyFormat("[foo bar:baz] &= [foo bar:baz];");
586 verifyFormat("[foo bar:baz] ^= [foo bar:baz];");
587 verifyFormat("[foo bar:baz] |= [foo bar:baz];");
588 verifyFormat("[foo bar:baz] ? [foo bar:baz] : [foo bar:baz];");
589 verifyFormat("[foo bar:baz] || [foo bar:baz];");
590 verifyFormat("[foo bar:baz] && [foo bar:baz];");
591 verifyFormat("[foo bar:baz] | [foo bar:baz];");
592 verifyFormat("[foo bar:baz] ^ [foo bar:baz];");
593 verifyFormat("[foo bar:baz] & [foo bar:baz];");
594 verifyFormat("[foo bar:baz] == [foo bar:baz];");
595 verifyFormat("[foo bar:baz] != [foo bar:baz];");
596 verifyFormat("[foo bar:baz] >= [foo bar:baz];");
597 verifyFormat("[foo bar:baz] <= [foo bar:baz];");
598 verifyFormat("[foo bar:baz] > [foo bar:baz];");
599 verifyFormat("[foo bar:baz] < [foo bar:baz];");
600 verifyFormat("[foo bar:baz] >> [foo bar:baz];");
601 verifyFormat("[foo bar:baz] << [foo bar:baz];");
602 verifyFormat("[foo bar:baz] - [foo bar:baz];");
603 verifyFormat("[foo bar:baz] + [foo bar:baz];");
604 verifyFormat("[foo bar:baz] * [foo bar:baz];");
605 verifyFormat("[foo bar:baz] / [foo bar:baz];");
606 verifyFormat("[foo bar:baz] % [foo bar:baz];");
607 // Whew!
608
609 verifyFormat("return in[42];");
610 verifyFormat("for (auto v : in[1]) {\n}");
611 verifyFormat("for (int i = 0; i < in[a]; ++i) {\n}");
612 verifyFormat("for (int i = 0; in[a] < i; ++i) {\n}");
613 verifyFormat("for (int i = 0; i < n; ++i, ++in[a]) {\n}");
614 verifyFormat("for (int i = 0; i < n; ++i, in[a]++) {\n}");
615 verifyFormat("for (int i = 0; i < f(in[a]); ++i, in[a]++) {\n}");
616 verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"
617 "}");
618 verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");
619 verifyFormat("[self aaaaa:(1 + 2) bbbbb:3];");
620 verifyFormat("[self aaaaa:(Type)a bbbbb:3];");
621
622 verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];");
623 verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");
624 verifyFormat("[self stuffWithInt:a ? [self foo:bar] : c];");
625 verifyFormat("[self stuffWithInt:a ? (e ? f : g) : c];");
626 verifyFormat("[cond ? obj1 : obj2 methodWithParam:param]");
627 verifyFormat("[button setAction:@selector(zoomOut:)];");
628 verifyFormat("[color getRed:&r green:&g blue:&b alpha:&a];");
629
630 verifyFormat("arr[[self indexForFoo:a]];");
631 verifyFormat("throw [self errorFor:a];");
632 verifyFormat("@throw [self errorFor:a];");
633
634 verifyFormat("[(id)foo bar:(id)baz quux:(id)snorf];");
635 verifyFormat("[(id)foo bar:(id) ? baz : quux];");
636 verifyFormat("4 > 4 ? (id)a : (id)baz;");
637
638 // This tests that the formatter doesn't break after "backing" but before ":",
639 // which would be at 80 columns.
640 verifyFormat(
641 "void f() {\n"
642 " if ((self = [super initWithContentRect:contentRect\n"
643 " styleMask:styleMask ?: otherMask\n"
644 " backing:NSBackingStoreBuffered\n"
645 " defer:YES]))");
646
647 verifyFormat(
648 "[foo checkThatBreakingAfterColonWorksOk:\n"
649 " [bar ifItDoes:reduceOverallLineLengthLikeInThisCase]];");
650
651 verifyFormat("[myObj short:arg1 // Force line break\n"
652 " longKeyword:arg2 != nil ? arg2 : @\"longKeyword\"\n"
653 " evenLongerKeyword:arg3 ?: @\"evenLongerKeyword\"\n"
654 " error:arg4];");
655 verifyFormat(
656 "void f() {\n"
657 " popup_window_.reset([[RenderWidgetPopupWindow alloc]\n"
658 " initWithContentRect:NSMakeRect(origin_global.x, origin_global.y,\n"
659 " pos.width(), pos.height())\n"
660 " styleMask:NSBorderlessWindowMask\n"
661 " backing:NSBackingStoreBuffered\n"
662 " defer:NO]);\n"
663 "}");
664 verifyFormat("[contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"
665 " with:contentsNativeView];");
666
667 verifyFormat(
668 "[pboard addTypes:[NSArray arrayWithObject:kBookmarkButtonDragType]\n"
669 " owner:nillllll];");
670
671 verifyFormat(
672 "[pboard setData:[NSData dataWithBytes:&button length:sizeof(button)]\n"
673 " forType:kBookmarkButtonDragType];");
674
675 verifyFormat("[defaultCenter addObserver:self\n"
676 " selector:@selector(willEnterFullscreen)\n"
677 " name:kWillEnterFullscreenNotification\n"
678 " object:nil];");
679 verifyFormat("[image_rep drawInRect:drawRect\n"
680 " fromRect:NSZeroRect\n"
681 " operation:NSCompositeCopy\n"
682 " fraction:1.0\n"
683 " respectFlipped:NO\n"
684 " hints:nil];");
685 verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
686 " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];");
687 verifyFormat("[aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n"
688 " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];");
689 verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa]\n"
690 " aaaaaaaaaaaaaaaaaaaaaa];");
691
692 verifyFormat(
693 "scoped_nsobject<NSTextField> message(\n"
694 " // The frame will be fixed up when |-setMessageText:| is called.\n"
695 " [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]);");
696 verifyFormat("[self aaaaaa:bbbbbbbbbbbbb\n"
697 " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n"
698 " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n"
699 " aaaa:bbb];");
700 verifyFormat("[self param:function( //\n"
701 " parameter)]");
702 verifyFormat(
703 "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"
704 " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"
705 " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];");
706
707 // Variadic parameters.
708 verifyFormat(
709 "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];");
710 verifyFormat(
711 "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"
712 " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"
713 " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];");
714 verifyFormat("[self // break\n"
715 " a:a\n"
716 " aaa:aaa];");
717 verifyFormat("bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||\n"
718 " [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);");
719
720 // Formats pair-parameters.
721 verifyFormat("[I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd];");
722 verifyFormat("[I drawRectOn:surface //\n"
Francois Ferrand38d80132018-02-09 15:41:56 +0000723 " ofSize:aa:bbb\n"
724 " atOrigin:cc:dd];");
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000725
Jacek Olesiakfb7f5c02018-02-07 10:35:08 +0000726 // Inline block as a first argument.
727 verifyFormat("[object justBlock:^{\n"
728 " a = 42;\n"
729 "}];");
730 verifyFormat("[object\n"
731 " justBlock:^{\n"
732 " a = 42;\n"
733 " }\n"
734 " notBlock:42\n"
735 " a:42];");
736 verifyFormat("[object\n"
737 " firstBlock:^{\n"
738 " a = 42;\n"
739 " }\n"
740 " blockWithLongerName:^{\n"
741 " a = 42;\n"
742 " }];");
743 verifyFormat("[object\n"
744 " blockWithLongerName:^{\n"
745 " a = 42;\n"
746 " }\n"
747 " secondBlock:^{\n"
748 " a = 42;\n"
749 " }];");
750 verifyFormat("[object\n"
751 " firstBlock:^{\n"
752 " a = 42;\n"
753 " }\n"
754 " notBlock:42\n"
755 " secondBlock:^{\n"
756 " a = 42;\n"
757 " }];");
758
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000759 Style.ColumnLimit = 70;
760 verifyFormat(
761 "void f() {\n"
762 " popup_wdow_.reset([[RenderWidgetPopupWindow alloc]\n"
763 " iniithContentRect:NSMakRet(origin_global.x, origin_global.y,\n"
764 " pos.width(), pos.height())\n"
765 " syeMask:NSBorderlessWindowMask\n"
766 " bking:NSBackingStoreBuffered\n"
767 " der:NO]);\n"
768 "}");
769
770 Style.ColumnLimit = 60;
771 verifyFormat("[call aaaaaaaa.aaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa\n"
772 " .aaaaaaaa];"); // FIXME: Indentation seems off.
773 // FIXME: This violates the column limit.
774 verifyFormat(
775 "[aaaaaaaaaaaaaaaaaaaaaaaaa\n"
776 " aaaaaaaaaaaaaaaaa:aaaaaaaa\n"
777 " aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];");
778
779 Style = getChromiumStyle(FormatStyle::LK_ObjC);
780 Style.ColumnLimit = 80;
781 verifyFormat(
782 "void f() {\n"
783 " popup_window_.reset([[RenderWidgetPopupWindow alloc]\n"
784 " initWithContentRect:NSMakeRect(origin_global.x, origin_global.y,\n"
785 " pos.width(), pos.height())\n"
786 " styleMask:NSBorderlessWindowMask\n"
787 " backing:NSBackingStoreBuffered\n"
788 " defer:NO]);\n"
789 "}");
Francois Ferrand38d80132018-02-09 15:41:56 +0000790
791 // Respect continuation indent and colon alignment (e.g. when object name is
792 // short, and first selector is the longest one)
793 Style = getLLVMStyle();
794 Style.Language = FormatStyle::LK_ObjC;
795 Style.ContinuationIndentWidth = 8;
796 verifyFormat("[self performSelectorOnMainThread:@selector(loadAccessories)\n"
797 " withObject:nil\n"
798 " waitUntilDone:false];");
799 verifyFormat("[self performSelector:@selector(loadAccessories)\n"
800 " withObjectOnMainThread:nil\n"
801 " waitUntilDone:false];");
802 verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaa\n"
803 " performSelectorOnMainThread:@selector(loadAccessories)\n"
804 " withObject:nil\n"
805 " waitUntilDone:false];");
806 verifyFormat("[self // force wrapping\n"
807 " performSelectorOnMainThread:@selector(loadAccessories)\n"
808 " withObject:nil\n"
809 " waitUntilDone:false];");
Daniel Jasper03a04fe2016-12-12 12:42:29 +0000810}
811
812TEST_F(FormatTestObjC, ObjCAt) {
813 verifyFormat("@autoreleasepool");
814 verifyFormat("@catch");
815 verifyFormat("@class");
816 verifyFormat("@compatibility_alias");
817 verifyFormat("@defs");
818 verifyFormat("@dynamic");
819 verifyFormat("@encode");
820 verifyFormat("@end");
821 verifyFormat("@finally");
822 verifyFormat("@implementation");
823 verifyFormat("@import");
824 verifyFormat("@interface");
825 verifyFormat("@optional");
826 verifyFormat("@package");
827 verifyFormat("@private");
828 verifyFormat("@property");
829 verifyFormat("@protected");
830 verifyFormat("@protocol");
831 verifyFormat("@public");
832 verifyFormat("@required");
833 verifyFormat("@selector");
834 verifyFormat("@synchronized");
835 verifyFormat("@synthesize");
836 verifyFormat("@throw");
837 verifyFormat("@try");
838
839 EXPECT_EQ("@interface", format("@ interface"));
840
841 // The precise formatting of this doesn't matter, nobody writes code like
842 // this.
843 verifyFormat("@ /*foo*/ interface");
844}
845
846TEST_F(FormatTestObjC, ObjCSnippets) {
847 verifyFormat("@autoreleasepool {\n"
848 " foo();\n"
849 "}");
850 verifyFormat("@class Foo, Bar;");
851 verifyFormat("@compatibility_alias AliasName ExistingClass;");
852 verifyFormat("@dynamic textColor;");
853 verifyFormat("char *buf1 = @encode(int *);");
854 verifyFormat("char *buf1 = @encode(typeof(4 * 5));");
855 verifyFormat("char *buf1 = @encode(int **);");
856 verifyFormat("Protocol *proto = @protocol(p1);");
857 verifyFormat("SEL s = @selector(foo:);");
858 verifyFormat("@synchronized(self) {\n"
859 " f();\n"
860 "}");
861
862 verifyFormat("@import foo.bar;\n"
863 "@import baz;");
864
865 verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
866
867 verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
868 verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
869
870 Style = getMozillaStyle();
871 verifyFormat("@property (assign, getter=isEditable) BOOL editable;");
872 verifyFormat("@property BOOL editable;");
873
874 Style = getWebKitStyle();
875 verifyFormat("@property (assign, getter=isEditable) BOOL editable;");
876 verifyFormat("@property BOOL editable;");
877
878 Style = getGoogleStyle(FormatStyle::LK_ObjC);
879 verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
880 verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
881}
882
883TEST_F(FormatTestObjC, ObjCForIn) {
884 verifyFormat("- (void)test {\n"
885 " for (NSString *n in arrayOfStrings) {\n"
886 " foo(n);\n"
887 " }\n"
888 "}");
889 verifyFormat("- (void)test {\n"
890 " for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
891 " foo(n);\n"
892 " }\n"
893 "}");
894}
895
896TEST_F(FormatTestObjC, ObjCLiterals) {
897 verifyFormat("@\"String\"");
898 verifyFormat("@1");
899 verifyFormat("@+4.8");
900 verifyFormat("@-4");
901 verifyFormat("@1LL");
902 verifyFormat("@.5");
903 verifyFormat("@'c'");
904 verifyFormat("@true");
905
906 verifyFormat("NSNumber *smallestInt = @(-INT_MAX - 1);");
907 verifyFormat("NSNumber *piOverTwo = @(M_PI / 2);");
908 verifyFormat("NSNumber *favoriteColor = @(Green);");
909 verifyFormat("NSString *path = @(getenv(\"PATH\"));");
910
911 verifyFormat("[dictionary setObject:@(1) forKey:@\"number\"];");
912}
913
914TEST_F(FormatTestObjC, ObjCDictLiterals) {
915 verifyFormat("@{");
916 verifyFormat("@{}");
917 verifyFormat("@{@\"one\" : @1}");
918 verifyFormat("return @{@\"one\" : @1;");
919 verifyFormat("@{@\"one\" : @1}");
920
921 verifyFormat("@{@\"one\" : @{@2 : @1}}");
922 verifyFormat("@{\n"
923 " @\"one\" : @{@2 : @1},\n"
924 "}");
925
926 verifyFormat("@{1 > 2 ? @\"one\" : @\"two\" : 1 > 2 ? @1 : @2}");
927 verifyIncompleteFormat("[self setDict:@{}");
928 verifyIncompleteFormat("[self setDict:@{@1 : @2}");
929 verifyFormat("NSLog(@\"%@\", @{@1 : @2, @2 : @3}[@1]);");
930 verifyFormat(
931 "NSDictionary *masses = @{@\"H\" : @1.0078, @\"He\" : @4.0026};");
932 verifyFormat(
933 "NSDictionary *settings = @{AVEncoderKey : @(AVAudioQualityMax)};");
934
935 verifyFormat("NSDictionary *d = @{\n"
936 " @\"nam\" : NSUserNam(),\n"
937 " @\"dte\" : [NSDate date],\n"
938 " @\"processInfo\" : [NSProcessInfo processInfo]\n"
939 "};");
940 verifyFormat(
941 "@{\n"
942 " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "
943 "regularFont,\n"
944 "};");
945 verifyFormat(
946 "@{\n"
947 " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :\n"
948 " reeeeeeeeeeeeeeeeeeeeeeeegularFont,\n"
949 "};");
950
951 // We should try to be robust in case someone forgets the "@".
952 verifyFormat("NSDictionary *d = {\n"
953 " @\"nam\" : NSUserNam(),\n"
954 " @\"dte\" : [NSDate date],\n"
955 " @\"processInfo\" : [NSProcessInfo processInfo]\n"
956 "};");
957 verifyFormat("NSMutableDictionary *dictionary =\n"
958 " [NSMutableDictionary dictionaryWithDictionary:@{\n"
959 " aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,\n"
960 " bbbbbbbbbbbbbbbbbb : bbbbb,\n"
961 " cccccccccccccccc : ccccccccccccccc\n"
962 " }];");
963
964 // Ensure that casts before the key are kept on the same line as the key.
965 verifyFormat(
966 "NSDictionary *d = @{\n"
967 " (aaaaaaaa id)aaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaaaaaaaaaaaa,\n"
968 " (aaaaaaaa id)aaaaaaaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaa,\n"
969 "};");
970
971 Style = getGoogleStyle(FormatStyle::LK_ObjC);
972 verifyFormat(
973 "@{\n"
974 " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "
975 "regularFont,\n"
976 "};");
977}
978
979TEST_F(FormatTestObjC, ObjCArrayLiterals) {
980 verifyIncompleteFormat("@[");
981 verifyFormat("@[]");
982 verifyFormat(
983 "NSArray *array = @[ @\" Hey \", NSApp, [NSNumber numberWithInt:42] ];");
984 verifyFormat("return @[ @3, @[], @[ @4, @5 ] ];");
985 verifyFormat("NSArray *array = @[ [foo description] ];");
986
987 verifyFormat(
988 "NSArray *some_variable = @[\n"
989 " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"
990 " @\"aaaaaaaaaaaaaaaaa\",\n"
991 " @\"aaaaaaaaaaaaaaaaa\",\n"
992 " @\"aaaaaaaaaaaaaaaaa\",\n"
993 "];");
994 verifyFormat(
995 "NSArray *some_variable = @[\n"
996 " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"
997 " @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\"\n"
998 "];");
999 verifyFormat("NSArray *some_variable = @[\n"
1000 " @\"aaaaaaaaaaaaaaaaa\",\n"
1001 " @\"aaaaaaaaaaaaaaaaa\",\n"
1002 " @\"aaaaaaaaaaaaaaaaa\",\n"
1003 " @\"aaaaaaaaaaaaaaaaa\",\n"
1004 "];");
1005 verifyFormat("NSArray *array = @[\n"
1006 " @\"a\",\n"
1007 " @\"a\",\n" // Trailing comma -> one per line.
1008 "];");
1009
1010 // We should try to be robust in case someone forgets the "@".
1011 verifyFormat("NSArray *some_variable = [\n"
1012 " @\"aaaaaaaaaaaaaaaaa\",\n"
1013 " @\"aaaaaaaaaaaaaaaaa\",\n"
1014 " @\"aaaaaaaaaaaaaaaaa\",\n"
1015 " @\"aaaaaaaaaaaaaaaaa\",\n"
1016 "];");
1017 verifyFormat(
1018 "- (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment\n"
1019 " index:(NSUInteger)index\n"
1020 " nonDigitAttributes:\n"
1021 " (NSDictionary *)noDigitAttributes;");
1022 verifyFormat("[someFunction someLooooooooooooongParameter:@[\n"
1023 " NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
1024 "]];");
Ben Hamilton09051f22018-02-08 16:07:25 +00001025 Style.ColumnLimit = 20;
1026 // We can't break string literals inside NSArray literals
1027 // (that raises -Wobjc-string-concatenation).
1028 verifyFormat("NSArray *foo = @[\n"
1029 " @\"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n"
1030 "];\n");
Daniel Jasper03a04fe2016-12-12 12:42:29 +00001031}
1032} // end namespace
1033} // end namespace format
1034} // end namespace clang