|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.LayoutRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp7.LayoutRules; |
| 10 | + using StyleCop.Analyzers.Test.Helpers; |
| 11 | + using Xunit; |
| 12 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 13 | + StyleCop.Analyzers.LayoutRules.SA1500BracesForMultiLineStatementsMustNotShareLine, |
| 14 | + StyleCop.Analyzers.LayoutRules.SA1500CodeFixProvider>; |
7 | 15 |
|
8 | 16 | public partial class SA1500CSharp8UnitTests : SA1500CSharp7UnitTests |
9 | 17 | { |
| 18 | + [Fact] |
| 19 | + [WorkItem(3003, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3003")] |
| 20 | + public async Task TestSwitchExpressionBracesMustOwnLineAsync() |
| 21 | + { |
| 22 | + var testCode = @" |
| 23 | +public class TestClass |
| 24 | +{ |
| 25 | + public int Test(Item value) |
| 26 | + { |
| 27 | + return value switch {|#0:{|} |
| 28 | + { Prop: 1 } => 1, |
| 29 | + _ => 0 {|#1:}|}; |
| 30 | + } |
| 31 | +} |
| 32 | +
|
| 33 | +public class Item |
| 34 | +{ |
| 35 | + public int Prop { get; set; } |
| 36 | +} |
| 37 | +"; |
| 38 | + |
| 39 | + var fixedCode = @" |
| 40 | +public class TestClass |
| 41 | +{ |
| 42 | + public int Test(Item value) |
| 43 | + { |
| 44 | + return value switch |
| 45 | + { |
| 46 | + { Prop: 1 } => 1, |
| 47 | + _ => 0 |
| 48 | + }; |
| 49 | + } |
| 50 | +} |
| 51 | +
|
| 52 | +public class Item |
| 53 | +{ |
| 54 | + public int Prop { get; set; } |
| 55 | +} |
| 56 | +"; |
| 57 | + |
| 58 | + DiagnosticResult[] expectedDiagnostics = |
| 59 | + { |
| 60 | + Diagnostic().WithLocation(0), |
| 61 | + Diagnostic().WithLocation(1), |
| 62 | + }; |
| 63 | + |
| 64 | + await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + [WorkItem(3003, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3003")] |
| 69 | + public async Task TestPropertyPatternBracesMustOwnLineAsync() |
| 70 | + { |
| 71 | + var testCode = @" |
| 72 | +public class TestClass |
| 73 | +{ |
| 74 | + public bool Test(object value) |
| 75 | + { |
| 76 | + return value is TestType {|#0:{|} A: 1, |
| 77 | + B: 2 {|#1:}|}; |
| 78 | + } |
| 79 | +} |
| 80 | +
|
| 81 | +public class TestType |
| 82 | +{ |
| 83 | + public int A { get; set; } |
| 84 | +
|
| 85 | + public int B { get; set; } |
| 86 | +} |
| 87 | +"; |
| 88 | + |
| 89 | + var fixedCode = @" |
| 90 | +public class TestClass |
| 91 | +{ |
| 92 | + public bool Test(object value) |
| 93 | + { |
| 94 | + return value is TestType |
| 95 | + { |
| 96 | + A: 1, |
| 97 | + B: 2 |
| 98 | + }; |
| 99 | + } |
| 100 | +} |
| 101 | +
|
| 102 | +public class TestType |
| 103 | +{ |
| 104 | + public int A { get; set; } |
| 105 | +
|
| 106 | + public int B { get; set; } |
| 107 | +} |
| 108 | +"; |
| 109 | + |
| 110 | + DiagnosticResult[] expectedDiagnostics = |
| 111 | + { |
| 112 | + Diagnostic().WithLocation(0), |
| 113 | + Diagnostic().WithLocation(1), |
| 114 | + }; |
| 115 | + |
| 116 | + await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 117 | + } |
10 | 118 | } |
11 | 119 | } |
0 commit comments