diff options
author | Marek Kurdej <marek.kurdej+llvm.org@gmail.com> | 2022-03-07 18:28:32 +0100 |
---|---|---|
committer | Marek Kurdej <marek.kurdej+llvm.org@gmail.com> | 2022-03-08 13:33:36 +0100 |
commit | 7a54fceb256257e3f8c8bd16ffd55531d806c96e (patch) | |
tree | a889f6df421074630681e82814248a1e2c356f0a /clang/unittests/Format/FormatTestCSharp.cpp | |
parent | dfaadf6b12b8ca5e45855dc417e56dc31ff2b2ae (diff) | |
download | llvm-7a54fceb256257e3f8c8bd16ffd55531d806c96e.zip llvm-7a54fceb256257e3f8c8bd16ffd55531d806c96e.tar.gz llvm-7a54fceb256257e3f8c8bd16ffd55531d806c96e.tar.bz2 |
[clang-format] Handle C# 9 `init` accessor specifier.
Before, the code:
```
int Value { get; } = 0;
int Value { init; } = 0;
```
was formatted incoherently:
```
int Value { get; } = 0;
int Value { init; }
= 0;
```
because `init` was not recognised as an accessor specifier.
Reviewed By: MyDeveloperDay, HazardyKnusperkeks
Differential Revision: https://reviews.llvm.org/D121132
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 26c62c1..2a76420 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -960,9 +960,11 @@ TEST_F(FormatTestCSharp, CSharpPropertyAccessors) { verifyFormat("int Value { get; } = 0", Style); verifyFormat("int Value { set }", Style); verifyFormat("int Value { set; }", Style); + verifyFormat("int Value { init; }", Style); verifyFormat("int Value { internal set; }", Style); verifyFormat("int Value { set; } = 0", Style); verifyFormat("int Value { get; set }", Style); + verifyFormat("int Value { get; init; }", Style); verifyFormat("int Value { set; get }", Style); verifyFormat("int Value { get; private set; }", Style); verifyFormat("int Value { get; set; }", Style); @@ -976,6 +978,18 @@ public string Name { set => _name = value; })", Style); + verifyFormat(R"(// +public string Name { + init => _name = value; + get => _name; +})", + Style); + verifyFormat(R"(// +public string Name { + set => _name = value; + get => _name; +})", + Style); // Examples taken from // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties |