Skip to content

Commit 7ffed65

Browse files
committed
Update SA1019 for indices and ranges
1 parent da443ba commit 7ffed65

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
75
{
86
using System.Threading;
@@ -65,5 +63,61 @@ public void TestMethod(object?[] arguments)
6563

6664
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
6765
}
66+
67+
[Fact]
68+
[WorkItem(3008, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008")]
69+
public async Task TestMemberAccessAfterIndexAndRangeExpressionsAsync()
70+
{
71+
var testCode = @"namespace TestNamespace
72+
{
73+
public class TestClass
74+
{
75+
public void TestMethod(string[] values)
76+
{
77+
var value1 = values[^1] {|#0:.|}ToString();
78+
var value2 = values[^1]{|#1:.|} ToString();
79+
var value3 = values[1..^1] {|#2:.|}ToString();
80+
var value4 = values[1..^1]{|#3:.|} ToString();
81+
var value5 = values[^1] {|#4:?|}.ToString();
82+
var value6 = values[^1]?{|#5:.|} ToString();
83+
var value7 = values[1..^1] {|#6:?|}.ToString();
84+
var value8 = values[1..^1]?{|#7:.|} ToString();
85+
}
86+
}
87+
}
88+
";
89+
var fixedCode = @"namespace TestNamespace
90+
{
91+
public class TestClass
92+
{
93+
public void TestMethod(string[] values)
94+
{
95+
var value1 = values[^1].ToString();
96+
var value2 = values[^1].ToString();
97+
var value3 = values[1..^1].ToString();
98+
var value4 = values[1..^1].ToString();
99+
var value5 = values[^1]?.ToString();
100+
var value6 = values[^1]?.ToString();
101+
var value7 = values[1..^1]?.ToString();
102+
var value8 = values[1..^1]?.ToString();
103+
}
104+
}
105+
}
106+
";
107+
108+
DiagnosticResult[] expected =
109+
{
110+
Diagnostic(DescriptorNotPreceded).WithArguments('.').WithLocation(0),
111+
Diagnostic(DescriptorNotFollowed).WithArguments('.').WithLocation(1),
112+
Diagnostic(DescriptorNotPreceded).WithArguments('.').WithLocation(2),
113+
Diagnostic(DescriptorNotFollowed).WithArguments('.').WithLocation(3),
114+
Diagnostic(DescriptorNotPreceded).WithArguments('?').WithLocation(4),
115+
Diagnostic(DescriptorNotFollowed).WithArguments('.').WithLocation(5),
116+
Diagnostic(DescriptorNotPreceded).WithArguments('?').WithLocation(6),
117+
Diagnostic(DescriptorNotFollowed).WithArguments('.').WithLocation(7),
118+
};
119+
120+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
121+
}
68122
}
69123
}

0 commit comments

Comments
 (0)