<div dir="ltr">This also changed the column limit for Obj-C files to 100 columns. Given that that wasn't mentioned in the CL description, was that intentional? <a href="https://google.github.io/styleguide/objcguide.xml#Line_Length">https://google.github.io/styleguide/objcguide.xml#Line_Length</a> says either is fine.<div><br></div><div>(Don't care which way it goes, but since the CL description didn't mention that I missed it, and it's wrong for Chromium style. And now we rolled in this revision and our roll failed due to this change.)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 12, 2016 at 4:42 AM, Daniel Jasper via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: djasper<br>
Date: Mon Dec 12 06:42:29 2016<br>
New Revision: 289428<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=289428&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=289428&view=rev</a><br>
Log:<br>
clang-format: Separate out a language kind for ObjC.<br>
<br>
While C(++) and ObjC are generally formatted the same way and can be<br>
mixed, people might want to choose different styles based on the<br>
language. This patch recognizes .m and .mm files as ObjC and also<br>
implements a very crude detection of whether or not a .h file contains<br>
ObjC code. This can be improved over time.<br>
<br>
Also move most of the ObjC tests into their own test file to keep file<br>
size maintainable.<br>
<br>
Added:<br>
cfe/trunk/unittests/Format/<wbr>FormatTestObjC.cpp<br>
Modified:<br>
cfe/trunk/include/clang/<wbr>Format/Format.h<br>
cfe/trunk/lib/Format/<wbr>ContinuationIndenter.cpp<br>
cfe/trunk/lib/Format/Format.<wbr>cpp<br>
cfe/trunk/lib/Format/<wbr>FormatTokenLexer.cpp<br>
cfe/trunk/lib/Format/<wbr>TokenAnnotator.cpp<br>
cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp<br>
cfe/trunk/unittests/Format/<wbr>CMakeLists.txt<br>
cfe/trunk/unittests/Format/<wbr>FormatTest.cpp<br>
cfe/trunk/unittests/Tooling/<wbr>ReplacementTest.h<br>
<br>
Modified: cfe/trunk/include/clang/<wbr>Format/Format.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Format/Format.h?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/<wbr>Format/Format.h (original)<br>
+++ cfe/trunk/include/clang/<wbr>Format/Format.h Mon Dec 12 06:42:29 2016<br>
@@ -465,6 +465,8 @@ struct FormatStyle {<br>
LK_Java,<br>
/// Should be used for JavaScript.<br>
LK_JavaScript,<br>
+ /// Should be used for ObjC code.<br>
+ LK_ObjC,<br>
/// Should be used for Protocol Buffers<br>
/// (<a href="https://developers.google.com/protocol-buffers/" rel="noreferrer" target="_blank">https://developers.google.<wbr>com/protocol-buffers/</a>).<br>
LK_Proto,<br>
@@ -852,13 +854,16 @@ extern const char *StyleOptionHelpDescri<br>
/// == "file".<br>
/// \param[in] FallbackStyle The name of a predefined style used to fallback to<br>
/// in case the style can't be determined from \p StyleName.<br>
+/// \param[in] Code The actual code to be formatted. Used to determine the<br>
+/// language if the filename isn't sufficient.<br>
/// \param[in] FS The underlying file system, in which the file resides. By<br>
/// default, the file system is the real file system.<br>
///<br>
/// \returns FormatStyle as specified by ``StyleName``. If no style could be<br>
/// determined, the default is LLVM Style (see ``getLLVMStyle()``).<br>
FormatStyle getStyle(StringRef StyleName, StringRef FileName,<br>
- StringRef FallbackStyle, vfs::FileSystem *FS = nullptr);<br>
+ StringRef FallbackStyle, StringRef Code = "",<br>
+ vfs::FileSystem *FS = nullptr);<br>
<br>
// \brief Returns a string representation of ``Language``.<br>
inline StringRef getLanguageName(FormatStyle::<wbr>LanguageKind Language) {<br>
<br>
Modified: cfe/trunk/lib/Format/<wbr>ContinuationIndenter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Format/<wbr>ContinuationIndenter.cpp?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Format/<wbr>ContinuationIndenter.cpp (original)<br>
+++ cfe/trunk/lib/Format/<wbr>ContinuationIndenter.cpp Mon Dec 12 06:42:29 2016<br>
@@ -560,6 +560,7 @@ unsigned ContinuationIndenter::<wbr>addTokenO<br>
// and we need to avoid bin packing there.<br>
bool NestedBlockSpecialCase =<br>
Style.Language != FormatStyle::LK_Cpp &&<br>
+ Style.Language != FormatStyle::LK_ObjC &&<br>
Current.is(tok::r_brace) && State.Stack.size() > 1 &&<br>
State.Stack[State.Stack.size() - 2].NestedBlockInlined;<br>
if (!NestedBlockSpecialCase)<br>
<br>
Modified: cfe/trunk/lib/Format/Format.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Format/<wbr>Format.cpp?rev=289428&r1=<wbr>289427&r2=289428&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Format/Format.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.<wbr>cpp Mon Dec 12 06:42:29 2016<br>
@@ -52,6 +52,7 @@ template <> struct ScalarEnumerationTrai<br>
IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);<br>
IO.enumCase(Value, "Java", FormatStyle::LK_Java);<br>
IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript);<br>
+ IO.enumCase(Value, "ObjC", FormatStyle::LK_ObjC);<br>
IO.enumCase(Value, "Proto", FormatStyle::LK_Proto);<br>
IO.enumCase(Value, "TableGen", FormatStyle::LK_TableGen);<br>
}<br>
@@ -623,6 +624,8 @@ FormatStyle getGoogleStyle(FormatStyle::<br>
} else if (Language == FormatStyle::LK_Proto) {<br>
GoogleStyle.<wbr>AllowShortFunctionsOnASingleLi<wbr>ne = FormatStyle::SFS_None;<br>
GoogleStyle.<wbr>SpacesInContainerLiterals = false;<br>
+ } else if (Language == FormatStyle::LK_ObjC) {<br>
+ GoogleStyle.ColumnLimit = 100;<br>
}<br>
<br>
return GoogleStyle;<br>
@@ -1861,6 +1864,8 @@ static FormatStyle::LanguageKind getLang<br>
return FormatStyle::LK_Java;<br>
if (FileName.endswith_lower(".js"<wbr>) || FileName.endswith_lower(".ts")<wbr>)<br>
return FormatStyle::LK_JavaScript; // JavaScript or TypeScript.<br>
+ if (FileName.endswith(".m") || FileName.endswith(".mm"))<br>
+ return FormatStyle::LK_ObjC;<br>
if (FileName.endswith_lower(".<wbr>proto") ||<br>
FileName.endswith_lower(".<wbr>protodevel"))<br>
return FormatStyle::LK_Proto;<br>
@@ -1870,12 +1875,21 @@ static FormatStyle::LanguageKind getLang<br>
}<br>
<br>
FormatStyle getStyle(StringRef StyleName, StringRef FileName,<br>
- StringRef FallbackStyle, vfs::FileSystem *FS) {<br>
+ StringRef FallbackStyle, StringRef Code,<br>
+ vfs::FileSystem *FS) {<br>
if (!FS) {<br>
FS = vfs::getRealFileSystem().get()<wbr>;<br>
}<br>
FormatStyle Style = getLLVMStyle();<br>
Style.Language = getLanguageByFileName(<wbr>FileName);<br>
+<br>
+ // This is a very crude detection of whether a header contains ObjC code that<br>
+ // should be improved over time and probably be done on tokens, not one the<br>
+ // bare content of the file.<br>
+ if (Style.Language == FormatStyle::LK_Cpp && FileName.endswith(".h") &&<br>
+ (Code.contains("\n- (") || Code.contains("\n+ (")))<br>
+ Style.Language = FormatStyle::LK_ObjC;<br>
+<br>
if (!getPredefinedStyle(<wbr>FallbackStyle, Style.Language, &Style)) {<br>
llvm::errs() << "Invalid fallback style \"" << FallbackStyle<br>
<< "\" using LLVM style\n";<br>
<br>
Modified: cfe/trunk/lib/Format/<wbr>FormatTokenLexer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Format/<wbr>FormatTokenLexer.cpp?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Format/<wbr>FormatTokenLexer.cpp (original)<br>
+++ cfe/trunk/lib/Format/<wbr>FormatTokenLexer.cpp Mon Dec 12 06:42:29 2016<br>
@@ -558,7 +558,8 @@ FormatToken *FormatTokenLexer::getNextTo<br>
Column = FormatTok-><wbr>LastLineColumnWidth;<br>
}<br>
<br>
- if (Style.Language == FormatStyle::LK_Cpp) {<br>
+ if (Style.Language == FormatStyle::LK_Cpp ||<br>
+ Style.Language == FormatStyle::LK_ObjC) {<br>
if (!(Tokens.size() > 0 && Tokens.back()->Tok.<wbr>getIdentifierInfo() &&<br>
Tokens.back()->Tok.<wbr>getIdentifierInfo()-><wbr>getPPKeywordID() ==<br>
tok::pp_define) &&<br>
<br>
Modified: cfe/trunk/lib/Format/<wbr>TokenAnnotator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Format/<wbr>TokenAnnotator.cpp?rev=289428&<wbr>r1=289427&r2=289428&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Format/<wbr>TokenAnnotator.cpp (original)<br>
+++ cfe/trunk/lib/Format/<wbr>TokenAnnotator.cpp Mon Dec 12 06:42:29 2016<br>
@@ -317,7 +317,8 @@ private:<br>
Contexts.back().<wbr>InTemplateArgument);<br>
<br>
bool StartsObjCMethodExpr =<br>
- !CppArrayTemplates && Style.Language == FormatStyle::LK_Cpp &&<br>
+ !CppArrayTemplates && (Style.Language == FormatStyle::LK_Cpp ||<br>
+ Style.Language == FormatStyle::LK_ObjC) &&<br>
Contexts.back().<wbr>CanBeExpression && Left->isNot(TT_LambdaLSquare) &&<br>
CurrentToken->isNot(tok::l_<wbr>brace) &&<br>
(!Parent ||<br>
@@ -433,7 +434,8 @@ private:<br>
FormatToken *Previous = CurrentToken-><wbr>getPreviousNonComment();<br>
if (((CurrentToken->is(tok::<wbr>colon) &&<br>
(!Contexts.back().<wbr>ColonIsDictLiteral ||<br>
- Style.Language != FormatStyle::LK_Cpp)) ||<br>
+ (Style.Language != FormatStyle::LK_Cpp &&<br>
+ Style.Language != FormatStyle::LK_ObjC))) ||<br>
Style.Language == FormatStyle::LK_Proto) &&<br>
(Previous->Tok.<wbr>getIdentifierInfo() ||<br>
Previous->is(tok::string_<wbr>literal)))<br>
@@ -1174,6 +1176,7 @@ private:<br>
bool rParenEndsCast(const FormatToken &Tok) {<br>
// C-style casts are only used in C++ and Java.<br>
if (Style.Language != FormatStyle::LK_Cpp &&<br>
+ Style.Language != FormatStyle::LK_ObjC &&<br>
Style.Language != FormatStyle::LK_Java)<br>
return false;<br>
<br>
<br>
Modified: cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/tools/clang-<wbr>format/ClangFormat.cpp?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp Mon Dec 12 06:42:29 2016<br>
@@ -249,7 +249,8 @@ static bool format(StringRef FileName) {<br>
if (fillRanges(Code.get(), Ranges))<br>
return true;<br>
StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;<br>
- FormatStyle FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle);<br>
+ FormatStyle FormatStyle =<br>
+ getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());<br>
if (SortIncludes.<wbr>getNumOccurrences() != 0)<br>
FormatStyle.SortIncludes = SortIncludes;<br>
unsigned CursorPosition = Cursor;<br>
<br>
Modified: cfe/trunk/unittests/Format/<wbr>CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CMakeLists.txt?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/unittests/<wbr>Format/CMakeLists.txt?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/unittests/Format/<wbr>CMakeLists.txt (original)<br>
+++ cfe/trunk/unittests/Format/<wbr>CMakeLists.txt Mon Dec 12 06:42:29 2016<br>
@@ -7,6 +7,7 @@ add_clang_unittest(FormatTests<br>
FormatTest.cpp<br>
FormatTestJava.cpp<br>
FormatTestJS.cpp<br>
+ FormatTestObjC.cpp<br>
FormatTestProto.cpp<br>
FormatTestSelective.cpp<br>
SortImportsTestJS.cpp<br>
<br>
Modified: cfe/trunk/unittests/Format/<wbr>FormatTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/unittests/<wbr>Format/FormatTest.cpp?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/unittests/Format/<wbr>FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/<wbr>FormatTest.cpp Mon Dec 12 06:42:29 2016<br>
@@ -2493,42 +2493,6 @@ TEST_F(FormatTest, FormatTryCatchBraceSt<br>
Style);<br>
}<br>
<br>
-TEST_F(FormatTest, FormatObjCTryCatch) {<br>
- verifyFormat("@try {\n"<br>
- " f();\n"<br>
- "} @catch (NSException e) {\n"<br>
- " @throw;\n"<br>
- "} @finally {\n"<br>
- " exit(42);\n"<br>
- "}");<br>
- verifyFormat("DEBUG({\n"<br>
- " @try {\n"<br>
- " } @finally {\n"<br>
- " }\n"<br>
- "});\n");<br>
-}<br>
-<br>
-TEST_F(FormatTest, FormatObjCAutoreleasepool) {<br>
- FormatStyle Style = getLLVMStyle();<br>
- verifyFormat("@autoreleasepool {\n"<br>
- " f();\n"<br>
- "}\n"<br>
- "@autoreleasepool {\n"<br>
- " f();\n"<br>
- "}\n",<br>
- Style);<br>
- Style.BreakBeforeBraces = FormatStyle::BS_Allman;<br>
- verifyFormat("@<wbr>autoreleasepool\n"<br>
- "{\n"<br>
- " f();\n"<br>
- "}\n"<br>
- "@autoreleasepool\n"<br>
- "{\n"<br>
- " f();\n"<br>
- "}\n",<br>
- Style);<br>
-}<br>
-<br>
TEST_F(FormatTest, StaticInitializers) {<br>
verifyFormat("static SomeClass SC = {1, 'a'};");<br>
<br>
@@ -7323,704 +7287,6 @@ TEST_F(FormatTest, FormatForObjectiveCMe<br>
verifyGoogleFormat("- foo:(int)foo;");<br>
}<br>
<br>
-TEST_F(FormatTest, FormatObjCInterface) {<br>
- verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n"<br>
- "@public\n"<br>
- " int field1;\n"<br>
- "@protected\n"<br>
- " int field2;\n"<br>
- "@private\n"<br>
- " int field3;\n"<br>
- "@package\n"<br>
- " int field4;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyGoogleFormat("@interface Foo : NSObject<NSSomeDelegate> {\n"<br>
- " @public\n"<br>
- " int field1;\n"<br>
- " @protected\n"<br>
- " int field2;\n"<br>
- " @private\n"<br>
- " int field3;\n"<br>
- " @package\n"<br>
- " int field4;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface /* wait for it */ Foo\n"<br>
- "+ (id)init;\n"<br>
- "// Look, a comment!\n"<br>
- "- (int)answerWith:(int)i;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo\n"<br>
- "@end\n"<br>
- "@interface Bar\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo : Bar\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo : /**/ Bar /**/ <Baz, /**/ Quux>\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyGoogleFormat("@interface Foo : Bar<Baz, Quux>\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo (HackStuff)\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo ()\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo (HackStuff) <MyProtocol>\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyGoogleFormat("@interface Foo (HackStuff)<MyProtocol>\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo : Bar {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo : Bar <Baz, Quux> {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo (HackStuff) {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo () {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@interface Foo (HackStuff) <MyProtocol> {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init;\n"<br>
- "@end");<br>
-<br>
- FormatStyle OnePerLine = getGoogleStyle();<br>
- OnePerLine.BinPackParameters = false;<br>
- verifyFormat("@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaa ()<\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaa> {\n"<br>
- "}",<br>
- OnePerLine);<br>
-}<br>
-<br>
-TEST_F(FormatTest, FormatObjCImplementation) {<br>
- verifyFormat("@implementation Foo : NSObject {\n"<br>
- "@public\n"<br>
- " int field1;\n"<br>
- "@protected\n"<br>
- " int field2;\n"<br>
- "@private\n"<br>
- " int field3;\n"<br>
- "@package\n"<br>
- " int field4;\n"<br>
- "}\n"<br>
- "+ (id)init {\n}\n"<br>
- "@end");<br>
-<br>
- verifyGoogleFormat("@<wbr>implementation Foo : NSObject {\n"<br>
- " @public\n"<br>
- " int field1;\n"<br>
- " @protected\n"<br>
- " int field2;\n"<br>
- " @private\n"<br>
- " int field3;\n"<br>
- " @package\n"<br>
- " int field4;\n"<br>
- "}\n"<br>
- "+ (id)init {\n}\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@implementation Foo\n"<br>
- "+ (id)init {\n"<br>
- " if (true)\n"<br>
- " return nil;\n"<br>
- "}\n"<br>
- "// Look, a comment!\n"<br>
- "- (int)answerWith:(int)i {\n"<br>
- " return i;\n"<br>
- "}\n"<br>
- "+ (int)answerWith:(int)i {\n"<br>
- " return i;\n"<br>
- "}\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@implementation Foo\n"<br>
- "@end\n"<br>
- "@implementation Bar\n"<br>
- "@end");<br>
-<br>
- EXPECT_EQ("@implementation Foo : Bar\n"<br>
- "+ (id)init {\n}\n"<br>
- "- (void)foo {\n}\n"<br>
- "@end",<br>
- format("@implementation Foo : Bar\n"<br>
- "+(id)init{}\n"<br>
- "-(void)foo{}\n"<br>
- "@end"));<br>
-<br>
- verifyFormat("@implementation Foo {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init {\n}\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@implementation Foo : Bar {\n"<br>
- " int _i;\n"<br>
- "}\n"<br>
- "+ (id)init {\n}\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@implementation Foo (HackStuff)\n"<br>
- "+ (id)init {\n}\n"<br>
- "@end");<br>
- verifyFormat("@implementation ObjcClass\n"<br>
- "- (void)method;\n"<br>
- "{}\n"<br>
- "@end");<br>
-}<br>
-<br>
-TEST_F(FormatTest, FormatObjCProtocol) {<br>
- verifyFormat("@protocol Foo\n"<br>
- "@property(weak) id delegate;\n"<br>
- "- (NSUInteger)numberOfThings;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@protocol MyProtocol <NSObject>\n"<br>
- "- (NSUInteger)numberOfThings;\n"<br>
- "@end");<br>
-<br>
- verifyGoogleFormat("@protocol MyProtocol<NSObject>\n"<br>
- "- (NSUInteger)numberOfThings;\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@protocol Foo;\n"<br>
- "@protocol Bar;\n");<br>
-<br>
- verifyFormat("@protocol Foo\n"<br>
- "@end\n"<br>
- "@protocol Bar\n"<br>
- "@end");<br>
-<br>
- verifyFormat("@protocol myProtocol\n"<br>
- "- (void)mandatoryWithInt:(int)i;<wbr>\n"<br>
- "@optional\n"<br>
- "- (void)optional;\n"<br>
- "@required\n"<br>
- "- (void)required;\n"<br>
- "@optional\n"<br>
- "@property(assign) int madProp;\n"<br>
- "@end\n");<br>
-<br>
- verifyFormat("@property(<wbr>nonatomic, assign, readonly)\n"<br>
- " int *<wbr>looooooooooooooooooooooooooooo<wbr>ngNumber;\n"<br>
- "@property(nonatomic, assign, readonly)\n"<br>
- " NSString *<wbr>looooooooooooooooooooooooooooo<wbr>ngName;");<br>
-<br>
- verifyFormat("@implementation PR18406\n"<br>
- "}\n"<br>
- "@end");<br>
-}<br>
-<br>
-TEST_F(FormatTest, FormatObjCMethodDeclarations) {<br>
- verifyFormat("- (void)doSomethingWith:(GTMFoo *)theFoo\n"<br>
- " rect:(NSRect)theRect\n"<br>
- " interval:(float)theInterval {\n"<br>
- "}");<br>
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
- " longKeyword:(NSRect)theRect\n"<br>
- " longerKeyword:(float)<wbr>theInterval\n"<br>
- " error:(NSError **)theError {\n"<br>
- "}");<br>
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
- " longKeyword:(NSRect)theRect\n"<br>
- " evenLongerKeyword:(float)<wbr>theInterval\n"<br>
- " error:(NSError **)theError {\n"<br>
- "}");<br>
- verifyFormat("- (instancetype)initXxxxxx:(id<<wbr>x>)x\n"<br>
- " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\<wbr>n"<br>
- " NS_DESIGNATED_INITIALIZER;",<br>
- getLLVMStyleWithColumns(60));<br>
-<br>
- // Continuation indent width should win over aligning colons if the function<br>
- // name is long.<br>
- FormatStyle continuationStyle = getGoogleStyle();<br>
- continuationStyle.ColumnLimit = 40;<br>
- continuationStyle.<wbr>IndentWrappedFunctionNames = true;<br>
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
- " dontAlignNamef:(NSRect)theRect {\n"<br>
- "}",<br>
- continuationStyle);<br>
-<br>
- // Make sure we don't break aligning for short parameter names.<br>
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
- " aShortf:(NSRect)theRect {\n"<br>
- "}",<br>
- continuationStyle);<br>
-<br>
- // Format pairs correctly.<br>
- verifyFormat("- (void)drawRectOn:(id)surface\<wbr>n"<br>
- " ofSize:(aaaaaaaa)height\n"<br>
- " :(size_t)width\n"<br>
- " atOrigin:(size_t)x\n"<br>
- " :(size_t)y\n"<br>
- " aaaaa:(a)yyy\n"<br>
- " bbb:(d)cccc;");<br>
- verifyFormat("- (void)drawRectOn:(id)surface ofSize:(aaa)height:(bbb)width;<wbr>");<br>
- verifyFormat("- (void)drawRectOn:(id)surface\<wbr>n"<br>
- " ofSize:(size_t)height\n"<br>
- " :(size_t)width;",<br>
- getLLVMStyleWithColumns(60));<br>
-}<br>
-<br>
-TEST_F(FormatTest, FormatObjCMethodExpr) {<br>
- verifyFormat("[foo bar:baz];");<br>
- verifyFormat("return [foo bar:baz];");<br>
- verifyFormat("return (a)[foo bar:baz];");<br>
- verifyFormat("f([foo bar:baz]);");<br>
- verifyFormat("f(2, [foo bar:baz]);");<br>
- verifyFormat("f(2, a ? b : c);");<br>
- verifyFormat("[[self initWithInt:4] bar:[baz quux:arrrr]];");<br>
-<br>
- // Unary operators.<br>
- verifyFormat("int a = +[foo bar:baz];");<br>
- verifyFormat("int a = -[foo bar:baz];");<br>
- verifyFormat("int a = ![foo bar:baz];");<br>
- verifyFormat("int a = ~[foo bar:baz];");<br>
- verifyFormat("int a = ++[foo bar:baz];");<br>
- verifyFormat("int a = --[foo bar:baz];");<br>
- verifyFormat("int a = sizeof [foo bar:baz];");<br>
- verifyFormat("int a = alignof [foo bar:baz];", getGoogleStyle());<br>
- verifyFormat("int a = &[foo bar:baz];");<br>
- verifyFormat("int a = *[foo bar:baz];");<br>
- // FIXME: Make casts work, without breaking f()[4].<br>
- // verifyFormat("int a = (int)[foo bar:baz];");<br>
- // verifyFormat("return (int)[foo bar:baz];");<br>
- // verifyFormat("(void)[foo bar:baz];");<br>
- verifyFormat("return (MyType *)[self.tableView cellForRowAtIndexPath:cell];")<wbr>;<br>
-<br>
- // Binary operators.<br>
- verifyFormat("[foo bar:baz], [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] = [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] *= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] /= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] %= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] += [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] -= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] <<= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] >>= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] &= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] ^= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] |= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] ? [foo bar:baz] : [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] || [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] && [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] | [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] ^ [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] & [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] == [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] != [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] >= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] <= [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] > [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] < [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] >> [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] << [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] - [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] + [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] * [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] / [foo bar:baz];");<br>
- verifyFormat("[foo bar:baz] % [foo bar:baz];");<br>
- // Whew!<br>
-<br>
- verifyFormat("return in[42];");<br>
- verifyFormat("for (auto v : in[1]) {\n}");<br>
- verifyFormat("for (int i = 0; i < in[a]; ++i) {\n}");<br>
- verifyFormat("for (int i = 0; in[a] < i; ++i) {\n}");<br>
- verifyFormat("for (int i = 0; i < n; ++i, ++in[a]) {\n}");<br>
- verifyFormat("for (int i = 0; i < n; ++i, in[a]++) {\n}");<br>
- verifyFormat("for (int i = 0; i < f(in[a]); ++i, in[a]++) {\n}");<br>
- verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"<br>
- "}");<br>
- verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");<br>
- verifyFormat("[self aaaaa:(1 + 2) bbbbb:3];");<br>
- verifyFormat("[self aaaaa:(Type)a bbbbb:3];");<br>
-<br>
- verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];");<br>
- verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");<br>
- verifyFormat("[self stuffWithInt:a ? [self foo:bar] : c];");<br>
- verifyFormat("[self stuffWithInt:a ? (e ? f : g) : c];");<br>
- verifyFormat("[cond ? obj1 : obj2 methodWithParam:param]");<br>
- verifyFormat("[button setAction:@selector(zoomOut:)]<wbr>;");<br>
- verifyFormat("[color getRed:&r green:&g blue:&b alpha:&a];");<br>
-<br>
- verifyFormat("arr[[self indexForFoo:a]];");<br>
- verifyFormat("throw [self errorFor:a];");<br>
- verifyFormat("@throw [self errorFor:a];");<br>
-<br>
- verifyFormat("[(id)foo bar:(id)baz quux:(id)snorf];");<br>
- verifyFormat("[(id)foo bar:(id) ? baz : quux];");<br>
- verifyFormat("4 > 4 ? (id)a : (id)baz;");<br>
-<br>
- // This tests that the formatter doesn't break after "backing" but before ":",<br>
- // which would be at 80 columns.<br>
- verifyFormat(<br>
- "void f() {\n"<br>
- " if ((self = [super initWithContentRect:<wbr>contentRect\n"<br>
- " styleMask:styleMask ?: otherMask\n"<br>
- " backing:<wbr>NSBackingStoreBuffered\n"<br>
- " defer:YES]))");<br>
-<br>
- verifyFormat(<br>
- "[foo checkThatBreakingAfterColonWor<wbr>ksOk:\n"<br>
- " [bar ifItDoes:<wbr>reduceOverallLineLengthLikeInT<wbr>hisCase]];");<br>
-<br>
- verifyFormat("[myObj short:arg1 // Force line break\n"<br>
- " longKeyword:arg2 != nil ? arg2 : @\"longKeyword\"\n"<br>
- " evenLongerKeyword:arg3 ?: @\"evenLongerKeyword\"\n"<br>
- " error:arg4];");<br>
- verifyFormat(<br>
- "void f() {\n"<br>
- " popup_window_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
- " initWithContentRect:<wbr>NSMakeRect(origin_global.x, origin_global.y,\n"<br>
- " pos.width(), pos.height())\n"<br>
- " styleMask:<wbr>NSBorderlessWindowMask\n"<br>
- " backing:<wbr>NSBackingStoreBuffered\n"<br>
- " defer:NO]);\n"<br>
- "}");<br>
- verifyFormat(<br>
- "void f() {\n"<br>
- " popup_wdow_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
- " iniithContentRect:NSMakRet(<wbr>origin_global.x, origin_global.y,\n"<br>
- " pos.width(), pos.height())\n"<br>
- " syeMask:<wbr>NSBorderlessWindowMask\n"<br>
- " bking:NSBackingStoreBuffered\<wbr>n"<br>
- " der:NO]);\n"<br>
- "}",<br>
- getLLVMStyleWithColumns(70));<br>
- verifyFormat(<br>
- "void f() {\n"<br>
- " popup_window_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
- " initWithContentRect:<wbr>NSMakeRect(origin_global.x, origin_global.y,\n"<br>
- " pos.width(), pos.height())\n"<br>
- " styleMask:<wbr>NSBorderlessWindowMask\n"<br>
- " backing:<wbr>NSBackingStoreBuffered\n"<br>
- " defer:NO]);\n"<br>
- "}",<br>
- getChromiumStyle(FormatStyle::<wbr>LK_Cpp));<br>
- verifyFormat("[<wbr>contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"<br>
- " with:contentsNativeView];");<br>
-<br>
- verifyFormat(<br>
- "[pboard addTypes:[NSArray arrayWithObject:<wbr>kBookmarkButtonDragType]\n"<br>
- " owner:nillllll];");<br>
-<br>
- verifyFormat(<br>
- "[pboard setData:[NSData dataWithBytes:&button length:sizeof(button)]\n"<br>
- " forType:<wbr>kBookmarkButtonDragType];");<br>
-<br>
- verifyFormat("[defaultCenter addObserver:self\n"<br>
- " selector:@selector(<wbr>willEnterFullscreen)\n"<br>
- " name:<wbr>kWillEnterFullscreenNotificati<wbr>on\n"<br>
- " object:nil];");<br>
- verifyFormat("[image_rep drawInRect:drawRect\n"<br>
- " fromRect:NSZeroRect\n"<br>
- " operation:NSCompositeCopy\n"<br>
- " fraction:1.0\n"<br>
- " respectFlipped:NO\n"<br>
- " hints:nil];");<br>
- verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaaaaaaa\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaa];");<br>
- verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaa(<wbr>aaaaaaaaaaaaaaaaaaaaa)\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaa];");<br>
- verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaaaaa.<wbr>aaaaaaaa[<wbr>aaaaaaaaaaaaaaaaaaaaa]\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaa];");<br>
- verifyFormat("[call aaaaaaaa.aaaaaa.aaaaaaaa.<wbr>aaaaaaaa.aaaaaaaa.aaaaaaaa\n"<br>
- " .aaaaaaaa];", // FIXME: Indentation seems off.<br>
- getLLVMStyleWithColumns(60));<br>
-<br>
- verifyFormat(<br>
- "scoped_nsobject<NSTextField> message(\n"<br>
- " // The frame will be fixed up when |-setMessageText:| is called.\n"<br>
- " [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]);");<br>
- verifyFormat("[self aaaaaa:bbbbbbbbbbbbb\n"<br>
- " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\<wbr>n"<br>
- " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n"<br>
- " aaaa:bbb];");<br>
- verifyFormat("[self param:function( //\n"<br>
- " parameter)]");<br>
- verifyFormat(<br>
- "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"<br>
- " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"<br>
- " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];");<br>
-<br>
- // FIXME: This violates the column limit.<br>
- verifyFormat(<br>
- "[aaaaaaaaaaaaaaaaaaaaaaaaa\n"<br>
- " aaaaaaaaaaaaaaaaa:aaaaaaaa\n"<br>
- " aaa:<wbr>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaaaaa];",<br>
- getLLVMStyleWithColumns(60));<br>
-<br>
- // Variadic parameters.<br>
- verifyFormat(<br>
- "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];");<br>
- verifyFormat(<br>
- "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"<br>
- " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"<br>
- " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];");<br>
- verifyFormat("[self // break\n"<br>
- " a:a\n"<br>
- " aaa:aaa];");<br>
- verifyFormat("bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||\n"<br>
- " [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);");<br>
-<br>
- // Formats pair-parameters.<br>
- verifyFormat("[I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd];");<br>
- verifyFormat("[I drawRectOn:surface //\n"<br>
- " ofSize:aa:bbb\n"<br>
- " atOrigin:cc:dd];");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCAt) {<br>
- verifyFormat("@<wbr>autoreleasepool");<br>
- verifyFormat("@catch");<br>
- verifyFormat("@class");<br>
- verifyFormat("@compatibility_<wbr>alias");<br>
- verifyFormat("@defs");<br>
- verifyFormat("@dynamic");<br>
- verifyFormat("@encode");<br>
- verifyFormat("@end");<br>
- verifyFormat("@finally");<br>
- verifyFormat("@implementation"<wbr>);<br>
- verifyFormat("@import");<br>
- verifyFormat("@interface");<br>
- verifyFormat("@optional");<br>
- verifyFormat("@package");<br>
- verifyFormat("@private");<br>
- verifyFormat("@property");<br>
- verifyFormat("@protected");<br>
- verifyFormat("@protocol");<br>
- verifyFormat("@public");<br>
- verifyFormat("@required");<br>
- verifyFormat("@selector");<br>
- verifyFormat("@synchronized");<br>
- verifyFormat("@synthesize");<br>
- verifyFormat("@throw");<br>
- verifyFormat("@try");<br>
-<br>
- EXPECT_EQ("@interface", format("@ interface"));<br>
-<br>
- // The precise formatting of this doesn't matter, nobody writes code like<br>
- // this.<br>
- verifyFormat("@ /*foo*/ interface");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCSnippets) {<br>
- verifyFormat("@autoreleasepool {\n"<br>
- " foo();\n"<br>
- "}");<br>
- verifyFormat("@class Foo, Bar;");<br>
- verifyFormat("@compatibility_<wbr>alias AliasName ExistingClass;");<br>
- verifyFormat("@dynamic textColor;");<br>
- verifyFormat("char *buf1 = @encode(int *);");<br>
- verifyFormat("char *buf1 = @encode(typeof(4 * 5));");<br>
- verifyFormat("char *buf1 = @encode(int **);");<br>
- verifyFormat("Protocol *proto = @protocol(p1);");<br>
- verifyFormat("SEL s = @selector(foo:);");<br>
- verifyFormat("@synchronized(<wbr>self) {\n"<br>
- " f();\n"<br>
- "}");<br>
-<br>
- verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");<br>
- verifyGoogleFormat("@<wbr>synthesize dropArrowPosition = dropArrowPosition_;");<br>
-<br>
- verifyFormat("@property(<wbr>assign, nonatomic) CGFloat hoverAlpha;");<br>
- verifyFormat("@property(<wbr>assign, getter=isEditable) BOOL editable;");<br>
- verifyGoogleFormat("@property(<wbr>assign, getter=isEditable) BOOL editable;");<br>
- verifyFormat("@property (assign, getter=isEditable) BOOL editable;",<br>
- getMozillaStyle());<br>
- verifyFormat("@property BOOL editable;", getMozillaStyle());<br>
- verifyFormat("@property (assign, getter=isEditable) BOOL editable;",<br>
- getWebKitStyle());<br>
- verifyFormat("@property BOOL editable;", getWebKitStyle());<br>
-<br>
- verifyFormat("@import foo.bar;\n"<br>
- "@import baz;");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCForIn) {<br>
- verifyFormat("- (void)test {\n"<br>
- " for (NSString *n in arrayOfStrings) {\n"<br>
- " foo(n);\n"<br>
- " }\n"<br>
- "}");<br>
- verifyFormat("- (void)test {\n"<br>
- " for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"<br>
- " foo(n);\n"<br>
- " }\n"<br>
- "}");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCLiterals) {<br>
- verifyFormat("@\"String\"");<br>
- verifyFormat("@1");<br>
- verifyFormat("@+4.8");<br>
- verifyFormat("@-4");<br>
- verifyFormat("@1LL");<br>
- verifyFormat("@.5");<br>
- verifyFormat("@'c'");<br>
- verifyFormat("@true");<br>
-<br>
- verifyFormat("NSNumber *smallestInt = @(-INT_MAX - 1);");<br>
- verifyFormat("NSNumber *piOverTwo = @(M_PI / 2);");<br>
- verifyFormat("NSNumber *favoriteColor = @(Green);");<br>
- verifyFormat("NSString *path = @(getenv(\"PATH\"));");<br>
-<br>
- verifyFormat("[dictionary setObject:@(1) forKey:@\"number\"];");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCDictLiterals) {<br>
- verifyFormat("@{");<br>
- verifyFormat("@{}");<br>
- verifyFormat("@{@\"one\" : @1}");<br>
- verifyFormat("return @{@\"one\" : @1;");<br>
- verifyFormat("@{@\"one\" : @1}");<br>
-<br>
- verifyFormat("@{@\"one\" : @{@2 : @1}}");<br>
- verifyFormat("@{\n"<br>
- " @\"one\" : @{@2 : @1},\n"<br>
- "}");<br>
-<br>
- verifyFormat("@{1 > 2 ? @\"one\" : @\"two\" : 1 > 2 ? @1 : @2}");<br>
- verifyIncompleteFormat("[self setDict:@{}");<br>
- verifyIncompleteFormat("[self setDict:@{@1 : @2}");<br>
- verifyFormat("NSLog(@\"%@\", @{@1 : @2, @2 : @3}[@1]);");<br>
- verifyFormat(<br>
- "NSDictionary *masses = @{@\"H\" : @1.0078, @\"He\" : @4.0026};");<br>
- verifyFormat(<br>
- "NSDictionary *settings = @{AVEncoderKey : @(AVAudioQualityMax)};");<br>
-<br>
- verifyFormat("NSDictionary *d = @{\n"<br>
- " @\"nam\" : NSUserNam(),\n"<br>
- " @\"dte\" : [NSDate date],\n"<br>
- " @\"processInfo\" : [NSProcessInfo processInfo]\n"<br>
- "};");<br>
- verifyFormat(<br>
- "@{\n"<br>
- " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e : "<br>
- "regularFont,\n"<br>
- "};");<br>
- verifyGoogleFormat(<br>
- "@{\n"<br>
- " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e : "<br>
- "regularFont,\n"<br>
- "};");<br>
- verifyFormat(<br>
- "@{\n"<br>
- " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e :\n"<br>
- " reeeeeeeeeeeeeeeeeeeeeeeegular<wbr>Font,\n"<br>
- "};");<br>
-<br>
- // We should try to be robust in case someone forgets the "@".<br>
- verifyFormat("NSDictionary *d = {\n"<br>
- " @\"nam\" : NSUserNam(),\n"<br>
- " @\"dte\" : [NSDate date],\n"<br>
- " @\"processInfo\" : [NSProcessInfo processInfo]\n"<br>
- "};");<br>
- verifyFormat("<wbr>NSMutableDictionary *dictionary =\n"<br>
- " [NSMutableDictionary dictionaryWithDictionary:@{\n"<br>
- " aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,\n"<br>
- " bbbbbbbbbbbbbbbbbb : bbbbb,\n"<br>
- " cccccccccccccccc : ccccccccccccccc\n"<br>
- " }];");<br>
-<br>
- // Ensure that casts before the key are kept on the same line as the key.<br>
- verifyFormat(<br>
- "NSDictionary *d = @{\n"<br>
- " (aaaaaaaa id)aaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaaaaaaaaaaaa,\<wbr>n"<br>
- " (aaaaaaaa id)aaaaaaaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaa,\n"<br>
- "};");<br>
-}<br>
-<br>
-TEST_F(FormatTest, ObjCArrayLiterals) {<br>
- verifyIncompleteFormat("@[");<br>
- verifyFormat("@[]");<br>
- verifyFormat(<br>
- "NSArray *array = @[ @\" Hey \", NSApp, [NSNumber numberWithInt:42] ];");<br>
- verifyFormat("return @[ @3, @[], @[ @4, @5 ] ];");<br>
- verifyFormat("NSArray *array = @[ [foo description] ];");<br>
-<br>
- verifyFormat(<br>
- "NSArray *some_variable = @[\n"<br>
- " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- "];");<br>
- verifyFormat(<br>
- "NSArray *some_variable = @[\n"<br>
- " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\"\n"<br>
- "];");<br>
- verifyFormat("NSArray *some_variable = @[\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- "];");<br>
- verifyFormat("NSArray *array = @[\n"<br>
- " @\"a\",\n"<br>
- " @\"a\",\n" // Trailing comma -> one per line.<br>
- "];");<br>
-<br>
- // We should try to be robust in case someone forgets the "@".<br>
- verifyFormat("NSArray *some_variable = [\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
- "];");<br>
- verifyFormat(<br>
- "- (NSAttributedString *)attributedStringForSegment:(<wbr>NSUInteger)segment\n"<br>
- " index:(NSUInteger)index\n"<br>
- " nonDigitAttributes:\n"<br>
- " (NSDictionary *)noDigitAttributes;");<br>
- verifyFormat("[someFunction someLooooooooooooongParameter:<wbr>@[\n"<br>
- " NSBundle.mainBundle.<wbr>infoDictionary[@\"a\"]\n"<br>
- "]];");<br>
-}<br>
<br>
TEST_F(FormatTest, BreaksStringLiterals) {<br>
EXPECT_EQ("\"some text \"\n"<br>
@@ -11630,13 +10896,13 @@ TEST(FormatStyle, GetStyleOfFile) {<br>
llvm::MemoryBuffer::<wbr>getMemBuffer("BasedOnStyle: LLVM")));<br>
ASSERT_TRUE(<br>
FS.addFile("/a/test.cpp", 0, llvm::MemoryBuffer::<wbr>getMemBuffer("int i;")));<br>
- auto Style1 = getStyle("file", "/a/.clang-format", "Google", &FS);<br>
+ auto Style1 = getStyle("file", "/a/.clang-format", "Google", "", &FS);<br>
ASSERT_EQ(Style1, getLLVMStyle());<br>
<br>
// Test 2: fallback to default.<br>
ASSERT_TRUE(<br>
FS.addFile("/b/test.cpp", 0, llvm::MemoryBuffer::<wbr>getMemBuffer("int i;")));<br>
- auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", &FS);<br>
+ auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", "", &FS);<br>
ASSERT_EQ(Style2, getMozillaStyle());<br>
<br>
// Test 3: format file in parent directory.<br>
@@ -11645,7 +10911,7 @@ TEST(FormatStyle, GetStyleOfFile) {<br>
llvm::MemoryBuffer::<wbr>getMemBuffer("BasedOnStyle: Google")));<br>
ASSERT_TRUE(FS.addFile("/c/<wbr>sub/sub/sub/test.cpp", 0,<br>
llvm::MemoryBuffer::<wbr>getMemBuffer("int i;")));<br>
- auto Style3 = getStyle("file", "/c/sub/sub/sub/test.cpp", "LLVM", &FS);<br>
+ auto Style3 = getStyle("file", "/c/sub/sub/sub/test.cpp", "LLVM", "", &FS);<br>
ASSERT_EQ(Style3, getGoogleStyle());<br>
}<br>
<br>
<br>
Added: cfe/trunk/unittests/Format/<wbr>FormatTestObjC.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=289428&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/unittests/<wbr>Format/FormatTestObjC.cpp?rev=<wbr>289428&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/unittests/Format/<wbr>FormatTestObjC.cpp (added)<br>
+++ cfe/trunk/unittests/Format/<wbr>FormatTestObjC.cpp Mon Dec 12 06:42:29 2016<br>
@@ -0,0 +1,822 @@<br>
+//===- unittest/Format/<wbr>FormatTestObjC.cpp - Formatting unit tests----------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "clang/Format/Format.h"<br>
+<br>
+#include "../Tooling/ReplacementTest.h"<br>
+#include "FormatTestUtils.h"<br>
+<br>
+#include "clang/Frontend/<wbr>TextDiagnosticPrinter.h"<br>
+#include "llvm/Support/Debug.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+#define DEBUG_TYPE "format-test"<br>
+<br>
+using clang::tooling::<wbr>ReplacementTest;<br>
+using clang::tooling::<wbr>toReplacements;<br>
+<br>
+namespace clang {<br>
+namespace format {<br>
+namespace {<br>
+<br>
+class FormatTestObjC : public ::testing::Test {<br>
+protected:<br>
+ FormatTestObjC() {<br>
+ Style = getLLVMStyle();<br>
+ Style.Language = FormatStyle::LK_ObjC;<br>
+ }<br>
+<br>
+ enum IncompleteCheck {<br>
+ IC_ExpectComplete,<br>
+ IC_ExpectIncomplete,<br>
+ IC_DoNotCheck<br>
+ };<br>
+<br>
+ std::string format(llvm::StringRef Code,<br>
+ IncompleteCheck CheckIncomplete = IC_ExpectComplete) {<br>
+ DEBUG(llvm::errs() << "---\n");<br>
+ DEBUG(llvm::errs() << Code << "\n\n");<br>
+ std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size()));<br>
+ bool IncompleteFormat = false;<br>
+ tooling::Replacements Replaces =<br>
+ reformat(Style, Code, Ranges, "<stdin>", &IncompleteFormat);<br>
+ if (CheckIncomplete != IC_DoNotCheck) {<br>
+ bool ExpectedIncompleteFormat = CheckIncomplete == IC_ExpectIncomplete;<br>
+ EXPECT_EQ(<wbr>ExpectedIncompleteFormat, IncompleteFormat) << Code << "\n\n";<br>
+ }<br>
+ auto Result = applyAllReplacements(Code, Replaces);<br>
+ EXPECT_TRUE(static_cast<bool>(<wbr>Result));<br>
+ DEBUG(llvm::errs() << "\n" << *Result << "\n\n");<br>
+ return *Result;<br>
+ }<br>
+<br>
+ void verifyFormat(StringRef Code) {<br>
+ EXPECT_EQ(Code.str(), format(test::messUp(Code)));<br>
+ }<br>
+<br>
+ void verifyIncompleteFormat(<wbr>StringRef Code) {<br>
+ EXPECT_EQ(Code.str(), format(test::messUp(Code), IC_ExpectIncomplete));<br>
+ }<br>
+<br>
+ FormatStyle Style;<br>
+};<br>
+<br>
+TEST_F(FormatTestObjC, DetectsObjCInHeaders) {<br>
+ Style = getStyle("LLVM", "a.h", "none", "@interface\n"<br>
+ "- (id)init;");<br>
+ EXPECT_EQ(FormatStyle::LK_<wbr>ObjC, Style.Language);<br>
+ Style = getStyle("LLVM", "a.h", "none", "@interface\n"<br>
+ "+ (id)init;");<br>
+ EXPECT_EQ(FormatStyle::LK_<wbr>ObjC, Style.Language);<br>
+<br>
+ // No recognizable ObjC.<br>
+ Style = getStyle("LLVM", "a.h", "none", "void f() {}");<br>
+ EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCTryCatch) {<br>
+ verifyFormat("@try {\n"<br>
+ " f();\n"<br>
+ "} @catch (NSException e) {\n"<br>
+ " @throw;\n"<br>
+ "} @finally {\n"<br>
+ " exit(42);\n"<br>
+ "}");<br>
+ verifyFormat("DEBUG({\n"<br>
+ " @try {\n"<br>
+ " } @finally {\n"<br>
+ " }\n"<br>
+ "});\n");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCAutoreleasepool) {<br>
+ verifyFormat("@autoreleasepool {\n"<br>
+ " f();\n"<br>
+ "}\n"<br>
+ "@autoreleasepool {\n"<br>
+ " f();\n"<br>
+ "}\n");<br>
+ Style.BreakBeforeBraces = FormatStyle::BS_Allman;<br>
+ verifyFormat("@<wbr>autoreleasepool\n"<br>
+ "{\n"<br>
+ " f();\n"<br>
+ "}\n"<br>
+ "@autoreleasepool\n"<br>
+ "{\n"<br>
+ " f();\n"<br>
+ "}\n");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCInterface) {<br>
+ verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n"<br>
+ "@public\n"<br>
+ " int field1;\n"<br>
+ "@protected\n"<br>
+ " int field2;\n"<br>
+ "@private\n"<br>
+ " int field3;\n"<br>
+ "@package\n"<br>
+ " int field4;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface /* wait for it */ Foo\n"<br>
+ "+ (id)init;\n"<br>
+ "// Look, a comment!\n"<br>
+ "- (int)answerWith:(int)i;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo\n"<br>
+ "@end\n"<br>
+ "@interface Bar\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo : Bar\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo : /**/ Bar /**/ <Baz, /**/ Quux>\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo (HackStuff)\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo ()\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo (HackStuff) <MyProtocol>\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo : Bar {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo : Bar <Baz, Quux> {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo (HackStuff) {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo () {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@interface Foo (HackStuff) <MyProtocol> {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ verifyFormat("@interface Foo : NSObject<NSSomeDelegate> {\n"<br>
+ " @public\n"<br>
+ " int field1;\n"<br>
+ " @protected\n"<br>
+ " int field2;\n"<br>
+ " @private\n"<br>
+ " int field3;\n"<br>
+ " @package\n"<br>
+ " int field4;\n"<br>
+ "}\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+ verifyFormat("@interface Foo : Bar<Baz, Quux>\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+ verifyFormat("@interface Foo (HackStuff)<MyProtocol>\n"<br>
+ "+ (id)init;\n"<br>
+ "@end");<br>
+ Style.BinPackParameters = false;<br>
+ Style.ColumnLimit = 80;<br>
+ verifyFormat("@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaa ()<\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaa,\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaa,\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaa,\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaa> {\n"<br>
+ "}");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCImplementation) {<br>
+ verifyFormat("@implementation Foo : NSObject {\n"<br>
+ "@public\n"<br>
+ " int field1;\n"<br>
+ "@protected\n"<br>
+ " int field2;\n"<br>
+ "@private\n"<br>
+ " int field3;\n"<br>
+ "@package\n"<br>
+ " int field4;\n"<br>
+ "}\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@implementation Foo\n"<br>
+ "+ (id)init {\n"<br>
+ " if (true)\n"<br>
+ " return nil;\n"<br>
+ "}\n"<br>
+ "// Look, a comment!\n"<br>
+ "- (int)answerWith:(int)i {\n"<br>
+ " return i;\n"<br>
+ "}\n"<br>
+ "+ (int)answerWith:(int)i {\n"<br>
+ " return i;\n"<br>
+ "}\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@implementation Foo\n"<br>
+ "@end\n"<br>
+ "@implementation Bar\n"<br>
+ "@end");<br>
+<br>
+ EXPECT_EQ("@implementation Foo : Bar\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "- (void)foo {\n}\n"<br>
+ "@end",<br>
+ format("@implementation Foo : Bar\n"<br>
+ "+(id)init{}\n"<br>
+ "-(void)foo{}\n"<br>
+ "@end"));<br>
+<br>
+ verifyFormat("@implementation Foo {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@implementation Foo : Bar {\n"<br>
+ " int _i;\n"<br>
+ "}\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@implementation Foo (HackStuff)\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "@end");<br>
+ verifyFormat("@implementation ObjcClass\n"<br>
+ "- (void)method;\n"<br>
+ "{}\n"<br>
+ "@end");<br>
+<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ verifyFormat("@implementation Foo : NSObject {\n"<br>
+ " @public\n"<br>
+ " int field1;\n"<br>
+ " @protected\n"<br>
+ " int field2;\n"<br>
+ " @private\n"<br>
+ " int field3;\n"<br>
+ " @package\n"<br>
+ " int field4;\n"<br>
+ "}\n"<br>
+ "+ (id)init {\n}\n"<br>
+ "@end");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCProtocol) {<br>
+ verifyFormat("@protocol Foo\n"<br>
+ "@property(weak) id delegate;\n"<br>
+ "- (NSUInteger)numberOfThings;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@protocol MyProtocol <NSObject>\n"<br>
+ "- (NSUInteger)numberOfThings;\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@protocol Foo;\n"<br>
+ "@protocol Bar;\n");<br>
+<br>
+ verifyFormat("@protocol Foo\n"<br>
+ "@end\n"<br>
+ "@protocol Bar\n"<br>
+ "@end");<br>
+<br>
+ verifyFormat("@protocol myProtocol\n"<br>
+ "- (void)mandatoryWithInt:(int)i;<wbr>\n"<br>
+ "@optional\n"<br>
+ "- (void)optional;\n"<br>
+ "@required\n"<br>
+ "- (void)required;\n"<br>
+ "@optional\n"<br>
+ "@property(assign) int madProp;\n"<br>
+ "@end\n");<br>
+<br>
+ verifyFormat("@property(<wbr>nonatomic, assign, readonly)\n"<br>
+ " int *<wbr>looooooooooooooooooooooooooooo<wbr>ngNumber;\n"<br>
+ "@property(nonatomic, assign, readonly)\n"<br>
+ " NSString *<wbr>looooooooooooooooooooooooooooo<wbr>ngName;");<br>
+<br>
+ verifyFormat("@implementation PR18406\n"<br>
+ "}\n"<br>
+ "@end");<br>
+<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ verifyFormat("@protocol MyProtocol<NSObject>\n"<br>
+ "- (NSUInteger)numberOfThings;\n"<br>
+ "@end");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) {<br>
+ verifyFormat("- (void)doSomethingWith:(GTMFoo *)theFoo\n"<br>
+ " rect:(NSRect)theRect\n"<br>
+ " interval:(float)theInterval {\n"<br>
+ "}");<br>
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
+ " longKeyword:(NSRect)theRect\n"<br>
+ " longerKeyword:(float)<wbr>theInterval\n"<br>
+ " error:(NSError **)theError {\n"<br>
+ "}");<br>
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
+ " longKeyword:(NSRect)theRect\n"<br>
+ " evenLongerKeyword:(float)<wbr>theInterval\n"<br>
+ " error:(NSError **)theError {\n"<br>
+ "}");<br>
+ Style.ColumnLimit = 60;<br>
+ verifyFormat("- (instancetype)initXxxxxx:(id<<wbr>x>)x\n"<br>
+ " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\<wbr>n"<br>
+ " NS_DESIGNATED_INITIALIZER;");<br>
+ verifyFormat("- (void)drawRectOn:(id)surface\<wbr>n"<br>
+ " ofSize:(size_t)height\n"<br>
+ " :(size_t)width;");<br>
+<br>
+ // Continuation indent width should win over aligning colons if the function<br>
+ // name is long.<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ Style.ColumnLimit = 40;<br>
+ Style.<wbr>IndentWrappedFunctionNames = true;<br>
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
+ " dontAlignNamef:(NSRect)theRect {\n"<br>
+ "}");<br>
+<br>
+ // Make sure we don't break aligning for short parameter names.<br>
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"<br>
+ " aShortf:(NSRect)theRect {\n"<br>
+ "}");<br>
+<br>
+ // Format pairs correctly.<br>
+ Style.ColumnLimit = 80;<br>
+ verifyFormat("- (void)drawRectOn:(id)surface\<wbr>n"<br>
+ " ofSize:(aaaaaaaa)height\n"<br>
+ " :(size_t)width\n"<br>
+ " atOrigin:(size_t)x\n"<br>
+ " :(size_t)y\n"<br>
+ " aaaaa:(a)yyy\n"<br>
+ " bbb:(d)cccc;");<br>
+ verifyFormat("- (void)drawRectOn:(id)surface ofSize:(aaa)height:(bbb)width;<wbr>");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, FormatObjCMethodExpr) {<br>
+ verifyFormat("[foo bar:baz];");<br>
+ verifyFormat("return [foo bar:baz];");<br>
+ verifyFormat("return (a)[foo bar:baz];");<br>
+ verifyFormat("f([foo bar:baz]);");<br>
+ verifyFormat("f(2, [foo bar:baz]);");<br>
+ verifyFormat("f(2, a ? b : c);");<br>
+ verifyFormat("[[self initWithInt:4] bar:[baz quux:arrrr]];");<br>
+<br>
+ // Unary operators.<br>
+ verifyFormat("int a = +[foo bar:baz];");<br>
+ verifyFormat("int a = -[foo bar:baz];");<br>
+ verifyFormat("int a = ![foo bar:baz];");<br>
+ verifyFormat("int a = ~[foo bar:baz];");<br>
+ verifyFormat("int a = ++[foo bar:baz];");<br>
+ verifyFormat("int a = --[foo bar:baz];");<br>
+ verifyFormat("int a = sizeof [foo bar:baz];");<br>
+ verifyFormat("int a = alignof [foo bar:baz];");<br>
+ verifyFormat("int a = &[foo bar:baz];");<br>
+ verifyFormat("int a = *[foo bar:baz];");<br>
+ // FIXME: Make casts work, without breaking f()[4].<br>
+ // verifyFormat("int a = (int)[foo bar:baz];");<br>
+ // verifyFormat("return (int)[foo bar:baz];");<br>
+ // verifyFormat("(void)[foo bar:baz];");<br>
+ verifyFormat("return (MyType *)[self.tableView cellForRowAtIndexPath:cell];")<wbr>;<br>
+<br>
+ // Binary operators.<br>
+ verifyFormat("[foo bar:baz], [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] = [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] *= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] /= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] %= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] += [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] -= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] <<= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] >>= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] &= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] ^= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] |= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] ? [foo bar:baz] : [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] || [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] && [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] | [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] ^ [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] & [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] == [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] != [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] >= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] <= [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] > [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] < [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] >> [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] << [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] - [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] + [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] * [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] / [foo bar:baz];");<br>
+ verifyFormat("[foo bar:baz] % [foo bar:baz];");<br>
+ // Whew!<br>
+<br>
+ verifyFormat("return in[42];");<br>
+ verifyFormat("for (auto v : in[1]) {\n}");<br>
+ verifyFormat("for (int i = 0; i < in[a]; ++i) {\n}");<br>
+ verifyFormat("for (int i = 0; in[a] < i; ++i) {\n}");<br>
+ verifyFormat("for (int i = 0; i < n; ++i, ++in[a]) {\n}");<br>
+ verifyFormat("for (int i = 0; i < n; ++i, in[a]++) {\n}");<br>
+ verifyFormat("for (int i = 0; i < f(in[a]); ++i, in[a]++) {\n}");<br>
+ verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"<br>
+ "}");<br>
+ verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");<br>
+ verifyFormat("[self aaaaa:(1 + 2) bbbbb:3];");<br>
+ verifyFormat("[self aaaaa:(Type)a bbbbb:3];");<br>
+<br>
+ verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];");<br>
+ verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");<br>
+ verifyFormat("[self stuffWithInt:a ? [self foo:bar] : c];");<br>
+ verifyFormat("[self stuffWithInt:a ? (e ? f : g) : c];");<br>
+ verifyFormat("[cond ? obj1 : obj2 methodWithParam:param]");<br>
+ verifyFormat("[button setAction:@selector(zoomOut:)]<wbr>;");<br>
+ verifyFormat("[color getRed:&r green:&g blue:&b alpha:&a];");<br>
+<br>
+ verifyFormat("arr[[self indexForFoo:a]];");<br>
+ verifyFormat("throw [self errorFor:a];");<br>
+ verifyFormat("@throw [self errorFor:a];");<br>
+<br>
+ verifyFormat("[(id)foo bar:(id)baz quux:(id)snorf];");<br>
+ verifyFormat("[(id)foo bar:(id) ? baz : quux];");<br>
+ verifyFormat("4 > 4 ? (id)a : (id)baz;");<br>
+<br>
+ // This tests that the formatter doesn't break after "backing" but before ":",<br>
+ // which would be at 80 columns.<br>
+ verifyFormat(<br>
+ "void f() {\n"<br>
+ " if ((self = [super initWithContentRect:<wbr>contentRect\n"<br>
+ " styleMask:styleMask ?: otherMask\n"<br>
+ " backing:<wbr>NSBackingStoreBuffered\n"<br>
+ " defer:YES]))");<br>
+<br>
+ verifyFormat(<br>
+ "[foo checkThatBreakingAfterColonWor<wbr>ksOk:\n"<br>
+ " [bar ifItDoes:<wbr>reduceOverallLineLengthLikeInT<wbr>hisCase]];");<br>
+<br>
+ verifyFormat("[myObj short:arg1 // Force line break\n"<br>
+ " longKeyword:arg2 != nil ? arg2 : @\"longKeyword\"\n"<br>
+ " evenLongerKeyword:arg3 ?: @\"evenLongerKeyword\"\n"<br>
+ " error:arg4];");<br>
+ verifyFormat(<br>
+ "void f() {\n"<br>
+ " popup_window_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
+ " initWithContentRect:<wbr>NSMakeRect(origin_global.x, origin_global.y,\n"<br>
+ " pos.width(), pos.height())\n"<br>
+ " styleMask:<wbr>NSBorderlessWindowMask\n"<br>
+ " backing:<wbr>NSBackingStoreBuffered\n"<br>
+ " defer:NO]);\n"<br>
+ "}");<br>
+ verifyFormat("[<wbr>contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"<br>
+ " with:contentsNativeView];");<br>
+<br>
+ verifyFormat(<br>
+ "[pboard addTypes:[NSArray arrayWithObject:<wbr>kBookmarkButtonDragType]\n"<br>
+ " owner:nillllll];");<br>
+<br>
+ verifyFormat(<br>
+ "[pboard setData:[NSData dataWithBytes:&button length:sizeof(button)]\n"<br>
+ " forType:<wbr>kBookmarkButtonDragType];");<br>
+<br>
+ verifyFormat("[defaultCenter addObserver:self\n"<br>
+ " selector:@selector(<wbr>willEnterFullscreen)\n"<br>
+ " name:<wbr>kWillEnterFullscreenNotificati<wbr>on\n"<br>
+ " object:nil];");<br>
+ verifyFormat("[image_rep drawInRect:drawRect\n"<br>
+ " fromRect:NSZeroRect\n"<br>
+ " operation:NSCompositeCopy\n"<br>
+ " fraction:1.0\n"<br>
+ " respectFlipped:NO\n"<br>
+ " hints:nil];");<br>
+ verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaaaaaaa\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaa];");<br>
+ verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaa(<wbr>aaaaaaaaaaaaaaaaaaaaa)\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaa];");<br>
+ verifyFormat("[<wbr>aaaaaaaaaaaaaaaaaaaaaaa.<wbr>aaaaaaaa[<wbr>aaaaaaaaaaaaaaaaaaaaa]\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaa];");<br>
+<br>
+ verifyFormat(<br>
+ "scoped_nsobject<NSTextField> message(\n"<br>
+ " // The frame will be fixed up when |-setMessageText:| is called.\n"<br>
+ " [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]);");<br>
+ verifyFormat("[self aaaaaa:bbbbbbbbbbbbb\n"<br>
+ " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\<wbr>n"<br>
+ " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n"<br>
+ " aaaa:bbb];");<br>
+ verifyFormat("[self param:function( //\n"<br>
+ " parameter)]");<br>
+ verifyFormat(<br>
+ "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"<br>
+ " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"<br>
+ " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];");<br>
+<br>
+ // Variadic parameters.<br>
+ verifyFormat(<br>
+ "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];");<br>
+ verifyFormat(<br>
+ "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"<br>
+ " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"<br>
+ " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];");<br>
+ verifyFormat("[self // break\n"<br>
+ " a:a\n"<br>
+ " aaa:aaa];");<br>
+ verifyFormat("bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||\n"<br>
+ " [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);");<br>
+<br>
+ // Formats pair-parameters.<br>
+ verifyFormat("[I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd];");<br>
+ verifyFormat("[I drawRectOn:surface //\n"<br>
+ " ofSize:aa:bbb\n"<br>
+ " atOrigin:cc:dd];");<br>
+<br>
+ Style.ColumnLimit = 70;<br>
+ verifyFormat(<br>
+ "void f() {\n"<br>
+ " popup_wdow_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
+ " iniithContentRect:NSMakRet(<wbr>origin_global.x, origin_global.y,\n"<br>
+ " pos.width(), pos.height())\n"<br>
+ " syeMask:<wbr>NSBorderlessWindowMask\n"<br>
+ " bking:NSBackingStoreBuffered\<wbr>n"<br>
+ " der:NO]);\n"<br>
+ "}");<br>
+<br>
+ Style.ColumnLimit = 60;<br>
+ verifyFormat("[call aaaaaaaa.aaaaaa.aaaaaaaa.<wbr>aaaaaaaa.aaaaaaaa.aaaaaaaa\n"<br>
+ " .aaaaaaaa];"); // FIXME: Indentation seems off.<br>
+ // FIXME: This violates the column limit.<br>
+ verifyFormat(<br>
+ "[aaaaaaaaaaaaaaaaaaaaaaaaa\n"<br>
+ " aaaaaaaaaaaaaaaaa:aaaaaaaa\n"<br>
+ " aaa:<wbr>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<wbr>aaaaaaaaaaa];");<br>
+<br>
+ Style = getChromiumStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ Style.ColumnLimit = 80;<br>
+ verifyFormat(<br>
+ "void f() {\n"<br>
+ " popup_window_.reset([[<wbr>RenderWidgetPopupWindow alloc]\n"<br>
+ " initWithContentRect:<wbr>NSMakeRect(origin_global.x, origin_global.y,\n"<br>
+ " pos.width(), pos.height())\n"<br>
+ " styleMask:<wbr>NSBorderlessWindowMask\n"<br>
+ " backing:<wbr>NSBackingStoreBuffered\n"<br>
+ " defer:NO]);\n"<br>
+ "}");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCAt) {<br>
+ verifyFormat("@<wbr>autoreleasepool");<br>
+ verifyFormat("@catch");<br>
+ verifyFormat("@class");<br>
+ verifyFormat("@compatibility_<wbr>alias");<br>
+ verifyFormat("@defs");<br>
+ verifyFormat("@dynamic");<br>
+ verifyFormat("@encode");<br>
+ verifyFormat("@end");<br>
+ verifyFormat("@finally");<br>
+ verifyFormat("@implementation"<wbr>);<br>
+ verifyFormat("@import");<br>
+ verifyFormat("@interface");<br>
+ verifyFormat("@optional");<br>
+ verifyFormat("@package");<br>
+ verifyFormat("@private");<br>
+ verifyFormat("@property");<br>
+ verifyFormat("@protected");<br>
+ verifyFormat("@protocol");<br>
+ verifyFormat("@public");<br>
+ verifyFormat("@required");<br>
+ verifyFormat("@selector");<br>
+ verifyFormat("@synchronized");<br>
+ verifyFormat("@synthesize");<br>
+ verifyFormat("@throw");<br>
+ verifyFormat("@try");<br>
+<br>
+ EXPECT_EQ("@interface", format("@ interface"));<br>
+<br>
+ // The precise formatting of this doesn't matter, nobody writes code like<br>
+ // this.<br>
+ verifyFormat("@ /*foo*/ interface");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCSnippets) {<br>
+ verifyFormat("@autoreleasepool {\n"<br>
+ " foo();\n"<br>
+ "}");<br>
+ verifyFormat("@class Foo, Bar;");<br>
+ verifyFormat("@compatibility_<wbr>alias AliasName ExistingClass;");<br>
+ verifyFormat("@dynamic textColor;");<br>
+ verifyFormat("char *buf1 = @encode(int *);");<br>
+ verifyFormat("char *buf1 = @encode(typeof(4 * 5));");<br>
+ verifyFormat("char *buf1 = @encode(int **);");<br>
+ verifyFormat("Protocol *proto = @protocol(p1);");<br>
+ verifyFormat("SEL s = @selector(foo:);");<br>
+ verifyFormat("@synchronized(<wbr>self) {\n"<br>
+ " f();\n"<br>
+ "}");<br>
+<br>
+ verifyFormat("@import foo.bar;\n"<br>
+ "@import baz;");<br>
+<br>
+ verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");<br>
+<br>
+ verifyFormat("@property(<wbr>assign, nonatomic) CGFloat hoverAlpha;");<br>
+ verifyFormat("@property(<wbr>assign, getter=isEditable) BOOL editable;");<br>
+<br>
+ Style = getMozillaStyle();<br>
+ verifyFormat("@property (assign, getter=isEditable) BOOL editable;");<br>
+ verifyFormat("@property BOOL editable;");<br>
+<br>
+ Style = getWebKitStyle();<br>
+ verifyFormat("@property (assign, getter=isEditable) BOOL editable;");<br>
+ verifyFormat("@property BOOL editable;");<br>
+<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");<br>
+ verifyFormat("@property(<wbr>assign, getter=isEditable) BOOL editable;");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCForIn) {<br>
+ verifyFormat("- (void)test {\n"<br>
+ " for (NSString *n in arrayOfStrings) {\n"<br>
+ " foo(n);\n"<br>
+ " }\n"<br>
+ "}");<br>
+ verifyFormat("- (void)test {\n"<br>
+ " for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"<br>
+ " foo(n);\n"<br>
+ " }\n"<br>
+ "}");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCLiterals) {<br>
+ verifyFormat("@\"String\"");<br>
+ verifyFormat("@1");<br>
+ verifyFormat("@+4.8");<br>
+ verifyFormat("@-4");<br>
+ verifyFormat("@1LL");<br>
+ verifyFormat("@.5");<br>
+ verifyFormat("@'c'");<br>
+ verifyFormat("@true");<br>
+<br>
+ verifyFormat("NSNumber *smallestInt = @(-INT_MAX - 1);");<br>
+ verifyFormat("NSNumber *piOverTwo = @(M_PI / 2);");<br>
+ verifyFormat("NSNumber *favoriteColor = @(Green);");<br>
+ verifyFormat("NSString *path = @(getenv(\"PATH\"));");<br>
+<br>
+ verifyFormat("[dictionary setObject:@(1) forKey:@\"number\"];");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCDictLiterals) {<br>
+ verifyFormat("@{");<br>
+ verifyFormat("@{}");<br>
+ verifyFormat("@{@\"one\" : @1}");<br>
+ verifyFormat("return @{@\"one\" : @1;");<br>
+ verifyFormat("@{@\"one\" : @1}");<br>
+<br>
+ verifyFormat("@{@\"one\" : @{@2 : @1}}");<br>
+ verifyFormat("@{\n"<br>
+ " @\"one\" : @{@2 : @1},\n"<br>
+ "}");<br>
+<br>
+ verifyFormat("@{1 > 2 ? @\"one\" : @\"two\" : 1 > 2 ? @1 : @2}");<br>
+ verifyIncompleteFormat("[self setDict:@{}");<br>
+ verifyIncompleteFormat("[self setDict:@{@1 : @2}");<br>
+ verifyFormat("NSLog(@\"%@\", @{@1 : @2, @2 : @3}[@1]);");<br>
+ verifyFormat(<br>
+ "NSDictionary *masses = @{@\"H\" : @1.0078, @\"He\" : @4.0026};");<br>
+ verifyFormat(<br>
+ "NSDictionary *settings = @{AVEncoderKey : @(AVAudioQualityMax)};");<br>
+<br>
+ verifyFormat("NSDictionary *d = @{\n"<br>
+ " @\"nam\" : NSUserNam(),\n"<br>
+ " @\"dte\" : [NSDate date],\n"<br>
+ " @\"processInfo\" : [NSProcessInfo processInfo]\n"<br>
+ "};");<br>
+ verifyFormat(<br>
+ "@{\n"<br>
+ " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e : "<br>
+ "regularFont,\n"<br>
+ "};");<br>
+ verifyFormat(<br>
+ "@{\n"<br>
+ " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e :\n"<br>
+ " reeeeeeeeeeeeeeeeeeeeeeeegular<wbr>Font,\n"<br>
+ "};");<br>
+<br>
+ // We should try to be robust in case someone forgets the "@".<br>
+ verifyFormat("NSDictionary *d = {\n"<br>
+ " @\"nam\" : NSUserNam(),\n"<br>
+ " @\"dte\" : [NSDate date],\n"<br>
+ " @\"processInfo\" : [NSProcessInfo processInfo]\n"<br>
+ "};");<br>
+ verifyFormat("<wbr>NSMutableDictionary *dictionary =\n"<br>
+ " [NSMutableDictionary dictionaryWithDictionary:@{\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,\n"<br>
+ " bbbbbbbbbbbbbbbbbb : bbbbb,\n"<br>
+ " cccccccccccccccc : ccccccccccccccc\n"<br>
+ " }];");<br>
+<br>
+ // Ensure that casts before the key are kept on the same line as the key.<br>
+ verifyFormat(<br>
+ "NSDictionary *d = @{\n"<br>
+ " (aaaaaaaa id)aaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaaaaaaaaaaaa,\<wbr>n"<br>
+ " (aaaaaaaa id)aaaaaaaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaa,\n"<br>
+ "};");<br>
+<br>
+ Style = getGoogleStyle(FormatStyle::<wbr>LK_ObjC);<br>
+ verifyFormat(<br>
+ "@{\n"<br>
+ " NSFontAttributeNameeeeeeeeeeee<wbr>eeeeeeeeeeeeeeeeeeeeeeeeeeeeee<wbr>e : "<br>
+ "regularFont,\n"<br>
+ "};");<br>
+}<br>
+<br>
+TEST_F(FormatTestObjC, ObjCArrayLiterals) {<br>
+ verifyIncompleteFormat("@[");<br>
+ verifyFormat("@[]");<br>
+ verifyFormat(<br>
+ "NSArray *array = @[ @\" Hey \", NSApp, [NSNumber numberWithInt:42] ];");<br>
+ verifyFormat("return @[ @3, @[], @[ @4, @5 ] ];");<br>
+ verifyFormat("NSArray *array = @[ [foo description] ];");<br>
+<br>
+ verifyFormat(<br>
+ "NSArray *some_variable = @[\n"<br>
+ " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ "];");<br>
+ verifyFormat(<br>
+ "NSArray *some_variable = @[\n"<br>
+ " aaaa == bbbbbbbbbbb ? @\"aaaaaaaaaaaa\" : @\"aaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\", @\"aaaaaaaaaaaaaaaa\"\n"<br>
+ "];");<br>
+ verifyFormat("NSArray *some_variable = @[\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ "];");<br>
+ verifyFormat("NSArray *array = @[\n"<br>
+ " @\"a\",\n"<br>
+ " @\"a\",\n" // Trailing comma -> one per line.<br>
+ "];");<br>
+<br>
+ // We should try to be robust in case someone forgets the "@".<br>
+ verifyFormat("NSArray *some_variable = [\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ " @\"aaaaaaaaaaaaaaaaa\",\n"<br>
+ "];");<br>
+ verifyFormat(<br>
+ "- (NSAttributedString *)attributedStringForSegment:(<wbr>NSUInteger)segment\n"<br>
+ " index:(NSUInteger)index\n"<br>
+ " nonDigitAttributes:\n"<br>
+ " (NSDictionary *)noDigitAttributes;");<br>
+ verifyFormat("[someFunction someLooooooooooooongParameter:<wbr>@[\n"<br>
+ " NSBundle.mainBundle.<wbr>infoDictionary[@\"a\"]\n"<br>
+ "]];");<br>
+}<br>
+} // end namespace<br>
+} // end namespace format<br>
+} // end namespace clang<br>
<br>
Modified: cfe/trunk/unittests/Tooling/<wbr>ReplacementTest.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ReplacementTest.h?rev=289428&r1=289427&r2=289428&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/unittests/<wbr>Tooling/ReplacementTest.h?rev=<wbr>289428&r1=289427&r2=289428&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/unittests/Tooling/<wbr>ReplacementTest.h (original)<br>
+++ cfe/trunk/unittests/Tooling/<wbr>ReplacementTest.h Mon Dec 12 06:42:29 2016<br>
@@ -24,7 +24,7 @@ namespace tooling {<br>
/// \brief Converts a set of replacements to Replacements class.<br>
/// \return A Replacements class containing \p Replaces on success; otherwise,<br>
/// an empty Replacements is returned.<br>
-static tooling::Replacements<br>
+inline tooling::Replacements<br>
toReplacements(const std::set<tooling::Replacement> &Replaces) {<br>
tooling::Replacements Result;<br>
for (const auto &R : Replaces) {<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>