diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-09-15 11:23:50 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-09-15 11:23:50 +0000 |
commit | 57065b2de4d945670107a164ea557cdfd94643b7 (patch) | |
tree | 61c7027c8cd6687150ab6f3d9fb996c4ff5e0add /unittests/Format | |
parent | 6d42a101dd0232c99d2358145f7d77e4de68596b (diff) |
[clang-format] New flag - BraceWrapping.AfterExternBlock
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **"extern C part"**
**Problem:**
Due to the lack of "brace wrapping extern" flag, clang format does parse the block after **extern** keyword moving the opening bracket to the header line always!
**Patch description:**
A new style added, new configuration flag - **BraceWrapping.AfterExternBlock** that allows us to decide whether we want a break before brace or not.
Reviewers: djasper, krasimir
Reviewed By: krasimir
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D37845
Contributed by @PriMee!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c7685c6cfc..e974550f22 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1704,7 +1704,42 @@ TEST_F(FormatTest, FormatsCompactNamespaces) { Style)); } -TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); } +TEST_F(FormatTest, FormatsExternC) { + verifyFormat("extern \"C\" {\nint a;"); + verifyFormat("extern \"C\" {}"); + verifyFormat("extern \"C\" {\n" + "int foo();\n" + "}"); + verifyFormat("extern \"C\" int foo() {}"); + verifyFormat("extern \"C\" int foo();"); + verifyFormat("extern \"C\" int foo() {\n" + " int i = 42;\n" + " return i;\n" + "}"); + + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + verifyFormat("extern \"C\" int foo() {}", Style); + verifyFormat("extern \"C\" int foo();", Style); + verifyFormat("extern \"C\" int foo()\n" + "{\n" + " int i = 42;\n" + " return i;\n" + "}", + Style); + + Style.BraceWrapping.AfterExternBlock = true; + Style.BraceWrapping.SplitEmptyRecord = false; + verifyFormat("extern \"C\"\n" + "{}", + Style); + verifyFormat("extern \"C\"\n" + "{\n" + " int foo();\n" + "}", + Style); +} TEST_F(FormatTest, FormatsInlineASM) { verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"); @@ -9979,6 +10014,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) { CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterObjCDeclaration); CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterStruct); CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterUnion); + CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock); CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch); CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse); CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces); |