diff options
author | Jonathan Coe <jbcoe@google.com> | 2020-05-15 13:55:48 +0100 |
---|---|---|
committer | Jonathan Coe <jbcoe@google.com> | 2020-05-15 14:08:40 +0100 |
commit | 8fa743ab82027da443bac050e86b70bcdb78cbee (patch) | |
tree | 48eb9081731b23572f3af91f168d19c3ccf36180 /clang/unittests/Format/FormatTestCSharp.cpp | |
parent | 0ef62fc25d3f2017551c24f4c65d001e003e88ab (diff) | |
download | llvm-8fa743ab82027da443bac050e86b70bcdb78cbee.zip llvm-8fa743ab82027da443bac050e86b70bcdb78cbee.tar.gz llvm-8fa743ab82027da443bac050e86b70bcdb78cbee.tar.bz2 |
[clang-format] C# property formatting can be controlled by config options
Summary:
Allow brace wrapping in C# property accessors to be controlled by configuration options.
Add new tests and revert old test results for Microsoft style to their previous state (as intended).
`FormatStyle.BraceWrapping.AfterFunction = true;` will change automatic property formatting from
```
Type MyType { get; set }
```
to
```
Type MyType
{ get; set }
```
Reviewers: krasimir, MyDeveloperDay
Reviewed By: krasimir, MyDeveloperDay
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D79000
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 6f0b196..5567e19 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -245,11 +245,13 @@ TEST_F(FormatTestCSharp, Attributes) { "}"); verifyFormat("[TestMethod]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server " "listening on provided host\")]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat( "[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n" @@ -677,6 +679,32 @@ class MyClass { DefaultThirdArgument); })", Style); + + // Brace wrapping and single-lining of accessor can be controlled by config. + Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + + verifyFormat(R"(// +public class SaleItem { + public decimal Price + { get; set; } +})", + Style); + + verifyFormat(R"(// +class TimePeriod { + public double Hours + { + get { + return _seconds / 3600; + } + set { + _seconds = value * 3600; + } + } +})", + Style); } TEST_F(FormatTestCSharp, CSharpSpaces) { |