diff options
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index d37a533..75112a7 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -613,6 +613,64 @@ public string Name { set => _name = value; })", Style); + + // Examples taken from + // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties + verifyFormat(R"( +// Expression body definitions +public class SaleItem { + public decimal Price { + get => _cost; + set => _cost = value; + } +})", + Style); + + verifyFormat(R"( +// Properties with backing fields +class TimePeriod { + public double Hours { + get { return _seconds / 3600; } + set { + if (value < 0 || value > 24) + throw new ArgumentOutOfRangeException( + $"{nameof(value)} must be between 0 and 24."); + _seconds = value * 3600; + } + } +})", + Style); + + verifyFormat(R"( +// Auto-implemented properties +public class SaleItem { + public decimal Price { get; set; } +})", + Style); + + // Add column limit to wrap long lines. + Style.ColumnLimit = 100; + + // Examples with assignment to default value. + verifyFormat(R"( +// Long assignment to default value +class MyClass { + public override VeryLongNamedTypeIndeed VeryLongNamedValue { get; set } = + VeryLongNamedTypeIndeed.Create(DefaultFirstArgument, DefaultSecondArgument, + DefaultThirdArgument); +})", + Style); + + verifyFormat(R"( +// Long assignment to default value with expression body +class MyClass { + public override VeryLongNamedTypeIndeed VeryLongNamedValue { + get => veryLongNamedField; + set => veryLongNamedField = value; + } = VeryLongNamedTypeIndeed.Create(DefaultFirstArgument, DefaultSecondArgument, + DefaultThirdArgument); +})", + Style); } TEST_F(FormatTestCSharp, CSharpSpaces) { |