|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp7.SpacingRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly; |
| 12 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 13 | + StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly, |
| 14 | + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; |
7 | 15 |
|
8 | 16 | public partial class SA1010CSharp8UnitTests : SA1010CSharp7UnitTests |
9 | 17 | { |
| 18 | + [Fact] |
| 19 | + [WorkItem(3008, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008")] |
| 20 | + public async Task TestIndexAndRangeOpenBracketSpacingAsync() |
| 21 | + { |
| 22 | + var testCode = @" |
| 23 | +namespace TestNamespace |
| 24 | +{ |
| 25 | + using System; |
| 26 | +
|
| 27 | + public class TestClass |
| 28 | + { |
| 29 | + public void TestMethod(int[] values) |
| 30 | + { |
| 31 | + _ = values {|#0:[|}^1]; |
| 32 | + _ = values{|#1:[|} ^1]; |
| 33 | + _ = values {|#2:[|} ^1]; |
| 34 | + _ = values {|#3:[|}1..^2]; |
| 35 | + _ = values{|#4:[|} 1..^2]; |
| 36 | + _ = values[..]; |
| 37 | + _ = values{|#5:[|} ..]; |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | +"; |
| 42 | + var fixedCode = @" |
| 43 | +namespace TestNamespace |
| 44 | +{ |
| 45 | + using System; |
| 46 | +
|
| 47 | + public class TestClass |
| 48 | + { |
| 49 | + public void TestMethod(int[] values) |
| 50 | + { |
| 51 | + _ = values[^1]; |
| 52 | + _ = values[^1]; |
| 53 | + _ = values[^1]; |
| 54 | + _ = values[1..^2]; |
| 55 | + _ = values[1..^2]; |
| 56 | + _ = values[..]; |
| 57 | + _ = values[..]; |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +"; |
| 62 | + |
| 63 | + DiagnosticResult[] expected = |
| 64 | + { |
| 65 | + Diagnostic(DescriptorNotPreceded).WithLocation(0), |
| 66 | + Diagnostic(DescriptorNotFollowed).WithLocation(1), |
| 67 | + Diagnostic(DescriptorNotPreceded).WithLocation(2), |
| 68 | + Diagnostic(DescriptorNotFollowed).WithLocation(2), |
| 69 | + Diagnostic(DescriptorNotPreceded).WithLocation(3), |
| 70 | + Diagnostic(DescriptorNotFollowed).WithLocation(4), |
| 71 | + Diagnostic(DescriptorNotFollowed).WithLocation(5), |
| 72 | + }; |
| 73 | + |
| 74 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 75 | + } |
10 | 76 | } |
11 | 77 | } |
0 commit comments