@@ -170,5 +170,78 @@ public unsafe void TestMethod()
170170
171171 await VerifyCSharpDiagnosticAsync ( LanguageVersion . CSharp8 , testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
172172 }
173+
174+ [ Fact ]
175+ [ WorkItem ( 3370 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370" ) ]
176+ public async Task TestRangeFollowedByMemberCallAsync ( )
177+ {
178+ const string testCode = @"using System;
179+
180+ public class TestClass
181+ {
182+ public void TestMethod()
183+ {
184+ var array = (1..10).ToString();
185+ }
186+ }
187+ " ;
188+
189+ await new CSharpTest ( LanguageVersion . CSharp8 )
190+ {
191+ ReferenceAssemblies = ReferenceAssemblies . NetCore . NetCoreApp31 ,
192+ TestCode = testCode ,
193+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
194+ }
195+
196+ [ Fact ]
197+ [ WorkItem ( 3370 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370" ) ]
198+ public async Task TestRangeAsync ( )
199+ {
200+ const string testCode = @"using System;
201+
202+ public class TestClass
203+ {
204+ public void TestMethod()
205+ {
206+ var a = new int[0];
207+ var b = a[(..)];
208+ var range = (1..10);
209+ }
210+ }
211+ " ;
212+
213+ const string fixedCode = @"using System;
214+
215+ public class TestClass
216+ {
217+ public void TestMethod()
218+ {
219+ var a = new int[0];
220+ var b = a[..];
221+ var range = 1..10;
222+ }
223+ }
224+ " ;
225+
226+ DiagnosticResult [ ] expected =
227+ {
228+ Diagnostic ( DiagnosticId ) . WithSpan ( 8 , 19 , 8 , 23 ) ,
229+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 8 , 19 ) ,
230+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 8 , 22 ) ,
231+ Diagnostic ( DiagnosticId ) . WithSpan ( 9 , 21 , 9 , 28 ) ,
232+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 9 , 21 ) ,
233+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 9 , 27 ) ,
234+ } ;
235+
236+ var test = new CSharpTest ( LanguageVersion . CSharp8 )
237+ {
238+ ReferenceAssemblies = ReferenceAssemblies . NetCore . NetCoreApp31 ,
239+ TestCode = testCode ,
240+ FixedCode = fixedCode ,
241+ } ;
242+ test . ExpectedDiagnostics . AddRange ( expected ) ;
243+
244+ await test . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
245+ }
173246 }
174247}
0 commit comments