@@ -7,7 +7,9 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
77 using System . Threading . Tasks ;
88 using Microsoft . CodeAnalysis . CSharp ;
99 using Microsoft . CodeAnalysis . Testing ;
10+ using StyleCop . Analyzers . SpacingRules ;
1011 using StyleCop . Analyzers . Test . CSharp7 . SpacingRules ;
12+ using StyleCop . Analyzers . Test . Verifiers ;
1113 using Xunit ;
1214 using static StyleCop . Analyzers . Test . Verifiers . StyleCopCodeFixVerifier <
1315 StyleCop . Analyzers . SpacingRules . SA1009ClosingParenthesisMustBeSpacedCorrectly ,
@@ -96,5 +98,52 @@ public IDisposable Service()
9698
9799 await VerifyCSharpFixAsync ( LanguageVersion . CSharp8 , testCode , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
98100 }
101+
102+ /// <summary>
103+ /// Verifies that spacing before a range expression double dots isn't required.
104+ /// </summary>
105+ /// <remarks>
106+ /// <para>Double dots of range expressions already provide enough spacing for readability so there is no
107+ /// need to suffix the closing parenthesis with a space.</para>
108+ /// </remarks>
109+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
110+ [ Fact ]
111+ [ WorkItem ( 3064 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3064" ) ]
112+ public async Task TestBeforeRangeExpressionAsync ( )
113+ {
114+ var testCode = SpecialTypeDefinitions . IndexAndRange + @"
115+ namespace TestNamespace
116+ {
117+ using System;
118+ public class TestClass
119+ {
120+ public string TestMethod()
121+ {
122+ string str = ""test"";
123+ int startLen = 4;
124+ return str[(startLen - 1) ..];
125+ }
126+ }
127+ }
128+ " ;
129+
130+ var fixedCode = SpecialTypeDefinitions . IndexAndRange + @"
131+ namespace TestNamespace
132+ {
133+ using System;
134+ public class TestClass
135+ {
136+ public string TestMethod()
137+ {
138+ string str = ""test"";
139+ int startLen = 4;
140+ return str[(startLen - 1)..];
141+ }
142+ }
143+ }
144+ " ;
145+ DiagnosticResult expected = Diagnostic ( ) . WithSpan ( 28 , 37 , 28 , 38 ) . WithArguments ( " not" , "followed" ) ;
146+ await VerifyCSharpFixAsync ( LanguageVersion . CSharp8 , testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
147+ }
99148 }
100149}
0 commit comments