@@ -328,5 +328,82 @@ public void TestMethod()
328328
329329 await test . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
330330 }
331+
332+ [ Fact ]
333+ [ WorkItem ( 3008 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008" ) ]
334+ public async Task TestParenthesizedRangeExpressionsAreAcceptedAsync ( )
335+ {
336+ const string testCode = @"using System;
337+
338+ public class TestClass
339+ {
340+ public Range TestMethod(int length)
341+ {
342+ Range local = {|#0:{|#1:(|}1..^3{|#2:)|}|};
343+ return {|#3:{|#4:(|}1..^length{|#5:)|}|};
344+ }
345+ }
346+ " ;
347+ const string fixedCode = @"using System;
348+
349+ public class TestClass
350+ {
351+ public Range TestMethod(int length)
352+ {
353+ Range local = 1..^3;
354+ return 1..^length;
355+ }
356+ }
357+ " ;
358+
359+ DiagnosticResult [ ] expected =
360+ {
361+ Diagnostic ( DiagnosticId ) . WithLocation ( 0 ) ,
362+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 1 ) ,
363+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 2 ) ,
364+ Diagnostic ( DiagnosticId ) . WithLocation ( 3 ) ,
365+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 4 ) ,
366+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 5 ) ,
367+ } ;
368+
369+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
370+ }
371+
372+ [ Fact ]
373+ [ WorkItem ( 3008 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008" ) ]
374+ public async Task TestParenthesizedIndexExpressionsAreAcceptedAsync ( )
375+ {
376+ const string testCode = @"using System;
377+
378+ public class TestClass
379+ {
380+ public int TestMethod(int length)
381+ {
382+ Index index = {|#0:{|#1:(|}^5{|#2:)|}|};
383+ return (^2).GetOffset(length);
384+ }
385+ }
386+ " ;
387+ const string fixedCode = @"using System;
388+
389+ public class TestClass
390+ {
391+ public int TestMethod(int length)
392+ {
393+ Index index = ^5;
394+ return (^2).GetOffset(length);
395+ }
396+ }
397+ " ;
398+
399+ DiagnosticResult [ ] expected =
400+ {
401+ Diagnostic ( DiagnosticId ) . WithLocation ( 0 ) ,
402+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 1 ) ,
403+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 2 ) ,
404+ } ;
405+
406+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
407+ }
331408 }
332409}
0 commit comments