Skip to content

Commit 04ab8ae

Browse files
committed
Update SA1010 for indices and ranges
1 parent 47250af commit 04ab8ae

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1010CSharp8UnitTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,75 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
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>;
715

816
public partial class SA1010CSharp8UnitTests : SA1010CSharp7UnitTests
917
{
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+
}
1076
}
1177
}

0 commit comments

Comments
 (0)