diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-10 13:08:12 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-10 13:08:12 +0000 |
commit | 46ef852618b18bc79e403b37a12c9b692e76126b (patch) | |
tree | 0f056c2efc19968c4dca28215efbcbda6892fd2a /unittests/Format/FormatTest.cpp | |
parent | e1d792f0ee02b5beb4b8e94506b3a0c353df43dd (diff) |
Improvements to function type and ObjC block formatting.
Before: int (^myBlock) (int) = ^(int num) {}
A<void ()>;
int (*b)(int);
After: int (^myBlock)(int) = ^(int num) {}
A<void()>;
int(*b)(int);
For function types and function pointer types, this patch only makes
the behavior consistent (for types that are keywords and other types).
For the latter function pointer type declarations, we'll probably
want to add a space after "int".
Also added LangOpts.Bool = 1, so we handle "A<bool()>" appropriately
Moved the LangOpts-settings to a public place for use by tests
and clang-format binary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172065 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 860661b432..39d8bb8f77 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -26,12 +26,8 @@ protected: std::vector<CharSourceRange> Ranges( 1, CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length))); - LangOptions LangOpts; - LangOpts.CPlusPlus = 1; - LangOpts.CPlusPlus11 = 1; - LangOpts.ObjC1 = 1; - LangOpts.ObjC2 = 1; - Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, LangOpts); + Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, + getFormattingLangOpts()); tooling::Replacements Replace = reformat(Style, Lex, Context.Sources, Ranges); EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite)); @@ -1029,6 +1025,15 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyGoogleFormat("int a = b ? *c : *d;"); } +TEST_F(FormatTest, FormatsFunctionTypes) { + // FIXME: Determine the cases that need a space after the return type and fix. + verifyFormat("A<bool()> a;"); + verifyFormat("A<SomeType()> a;"); + verifyFormat("A<void(*)(int, std::string)> a;"); + + verifyFormat("int(*func)(void *);"); +} + TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) { verifyFormat("int *someFunction(int LoooooooooooooooongParam1,\n" " int LoooooooooooooooongParam2) {\n}"); @@ -1177,8 +1182,8 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) { } TEST_F(FormatTest, FormatObjCBlocks) { - verifyFormat("int (^Block) (int, int);"); - verifyFormat("int (^Block1) (int, int) = ^(int i, int j)"); + verifyFormat("int (^Block)(int, int);"); + verifyFormat("int (^Block1)(int, int) = ^(int i, int j)"); } TEST_F(FormatTest, FormatObjCInterface) { |