|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
|
5 | 5 | {
|
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.CSharp; |
| 9 | + using Microsoft.CodeAnalysis.Testing; |
6 | 10 | using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
|
| 11 | + using Xunit; |
| 12 | + using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly; |
| 13 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 14 | + StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly, |
| 15 | + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; |
7 | 16 |
|
8 | 17 | public class SA1008CSharp9UnitTests : SA1008CSharp8UnitTests
|
9 | 18 | {
|
| 19 | + [Fact] |
| 20 | + [WorkItem(3230, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3230")] |
| 21 | + public async Task TestParenthesizedPatternAsync() |
| 22 | + { |
| 23 | + const string testCode = @" |
| 24 | +class C |
| 25 | +{ |
| 26 | + void Method(int b) |
| 27 | + { |
| 28 | + _ = b is{|#0:(|} >= 0 and <= 31) or 127; |
| 29 | + _ = b is{|#1:(|}>= 0 and <= 31) or 127; |
| 30 | + _ = b is {|#2:(|} >= 0 and <= 31) or 127; |
| 31 | + } |
| 32 | +}"; |
| 33 | + const string fixedCode = @" |
| 34 | +class C |
| 35 | +{ |
| 36 | + void Method(int b) |
| 37 | + { |
| 38 | + _ = b is (>= 0 and <= 31) or 127; |
| 39 | + _ = b is (>= 0 and <= 31) or 127; |
| 40 | + _ = b is (>= 0 and <= 31) or 127; |
| 41 | + } |
| 42 | +}"; |
| 43 | + |
| 44 | + await new CSharpTest(LanguageVersion.CSharp9) |
| 45 | + { |
| 46 | + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, |
| 47 | + ExpectedDiagnostics = |
| 48 | + { |
| 49 | + // /0/Test0.cs(6,17): warning SA1008: Opening parenthesis should be preceded by a space. |
| 50 | + Diagnostic(DescriptorPreceded).WithLocation(0), |
| 51 | + |
| 52 | + // /0/Test0.cs(6,17): warning SA1008: Opening parenthesis should not be followed by a space. |
| 53 | + Diagnostic(DescriptorNotFollowed).WithLocation(0), |
| 54 | + |
| 55 | + // /0/Test0.cs(7,17): warning SA1008: Opening parenthesis should be preceded by a space. |
| 56 | + Diagnostic(DescriptorPreceded).WithLocation(1), |
| 57 | + |
| 58 | + // /0/Test0.cs(8,18): warning SA1008: Opening parenthesis should not be followed by a space. |
| 59 | + Diagnostic(DescriptorNotFollowed).WithLocation(2), |
| 60 | + }, |
| 61 | + TestCode = testCode, |
| 62 | + FixedCode = fixedCode, |
| 63 | + }.RunAsync(CancellationToken.None).ConfigureAwait(false); |
| 64 | + } |
10 | 65 | }
|
11 | 66 | }
|
0 commit comments