|
1 | 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | | -#nullable disable |
5 | | - |
6 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules |
7 | 5 | { |
8 | 6 | using System.Threading; |
@@ -65,5 +63,61 @@ public void TestMethod(object?[] arguments) |
65 | 63 |
|
66 | 64 | await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
67 | 65 | } |
| 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 | + } |
68 | 122 | } |
69 | 123 | } |
0 commit comments