diff options
author | Ben Hamilton <benhamilton@google.com> | 2019-07-22 18:20:01 +0000 |
---|---|---|
committer | Ben Hamilton <benhamilton@google.com> | 2019-07-22 18:20:01 +0000 |
commit | 83a361438a1bc830995e8816110904247eb0e20d (patch) | |
tree | 214686bd6db4709455f72580eaa1b89d848949f9 /unittests | |
parent | dffd3559afa4be1df1991d27d897a079e1724c36 (diff) | |
download | clang-83a361438a1bc830995e8816110904247eb0e20d.tar.gz |
Adds support for formatting NS_CLOSED_ENUM and CF_CLOSED_ENUM alongside NS_ENUM and CF_ENUM.
Summary:
Addresses the formatting of NS_CLOSED_ENUM and CF_CLOSED_ENUM, introduced in Swift 5.
Before:
```
typedef NS_CLOSED_ENUM(NSInteger, Foo){FooValueOne = 1, FooValueTwo,
FooValueThree};
```
After:
```
typedef NS_CLOSED_ENUM(NSInteger, Foo) {
FooValueOne = 1,
FooValueTwo,
FooValueThree
};
```
Contributed by heijink.
Reviewers: benhamilton, krasimir
Reviewed By: benhamilton
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65012
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366719 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 15 | ||||
-rw-r--r-- | unittests/Format/FormatTestObjC.cpp | 7 |
2 files changed, 21 insertions, 1 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c1cec11013..463b9213a0 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1716,6 +1716,8 @@ TEST_F(FormatTest, FormatsTypedefEnum) { TEST_F(FormatTest, FormatsNSEnums) { verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }"); + verifyGoogleFormat( + "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }"); verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n" " // Information about someDecentlyLongValue.\n" " someDecentlyLongValue,\n" @@ -1724,6 +1726,14 @@ TEST_F(FormatTest, FormatsNSEnums) { " // Information about aThirdDecentlyLongValue.\n" " aThirdDecentlyLongValue\n" "};"); + verifyGoogleFormat("typedef NS_CLOSED_ENUM(NSInteger, MyType) {\n" + " // Information about someDecentlyLongValue.\n" + " someDecentlyLongValue,\n" + " // Information about anotherDecentlyLongValue.\n" + " anotherDecentlyLongValue,\n" + " // Information about aThirdDecentlyLongValue.\n" + " aThirdDecentlyLongValue\n" + "};"); verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n" " a = 1,\n" " b = 2,\n" @@ -1734,6 +1744,11 @@ TEST_F(FormatTest, FormatsNSEnums) { " b = 2,\n" " c = 3,\n" "};"); + verifyGoogleFormat("typedef CF_CLOSED_ENUM(NSInteger, MyType) {\n" + " a = 1,\n" + " b = 2,\n" + " c = 3,\n" + "};"); verifyGoogleFormat("typedef CF_OPTIONS(NSInteger, MyType) {\n" " a = 1,\n" " b = 2,\n" diff --git a/unittests/Format/FormatTestObjC.cpp b/unittests/Format/FormatTestObjC.cpp index b1e289d89b..8fb9319588 100644 --- a/unittests/Format/FormatTestObjC.cpp +++ b/unittests/Format/FormatTestObjC.cpp @@ -114,7 +114,12 @@ TEST(FormatTestObjCStyle, DetectsObjCInHeaders) { EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); Style = - getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n"); + getStyle("{}", "a.h", "none", "typedef NS_ENUM(int, Foo) {};\n"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + + Style = getStyle("{}", "a.h", "none", + "typedef NS_CLOSED_ENUM(int, Foo) {};\n"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); |