@@ -328,5 +328,90 @@ public void TestMethod()
328328
329329 await test . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
330330 }
331+
332+ [ Fact ]
333+ [ WorkItem ( 3003 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3003" ) ]
334+ public async Task TestReturnSwitchExpressionWithUnnecessaryParenthesisAsync ( )
335+ {
336+ const string testCode = @"
337+ public class TestClass
338+ {
339+ public object TestMethod(int n, object a, object b)
340+ {
341+ return {|#0:{|#1:(|}n switch { 1 => a, _ => b }{|#2:)|}|};
342+ }
343+ }
344+ " ;
345+
346+ const string fixedCode = @"
347+ public class TestClass
348+ {
349+ public object TestMethod(int n, object a, object b)
350+ {
351+ return n switch { 1 => a, _ => b };
352+ }
353+ }
354+ " ;
355+
356+ DiagnosticResult [ ] expected =
357+ {
358+ Diagnostic ( DiagnosticId ) . WithLocation ( 0 ) ,
359+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 1 ) ,
360+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 2 ) ,
361+ } ;
362+
363+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
364+ }
365+
366+ [ Fact ]
367+ [ WorkItem ( 3003 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3003" ) ]
368+ public async Task TestPropertyPatternWithUnnecessaryParenthesisAsync ( )
369+ {
370+ const string testCode = @"
371+ public class TestClass
372+ {
373+ public bool TestMethod(string value)
374+ {
375+ return {|#0:{|#1:(|}value is { Length: 1 }{|#2:)|}|};
376+ }
377+ }
378+ " ;
379+
380+ const string fixedCode = @"
381+ public class TestClass
382+ {
383+ public bool TestMethod(string value)
384+ {
385+ return value is { Length: 1 };
386+ }
387+ }
388+ " ;
389+
390+ DiagnosticResult [ ] expected =
391+ {
392+ Diagnostic ( DiagnosticId ) . WithLocation ( 0 ) ,
393+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 1 ) ,
394+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 2 ) ,
395+ } ;
396+
397+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
398+ }
399+
400+ [ Fact ]
401+ [ WorkItem ( 3003 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3003" ) ]
402+ public async Task TestNegatedPropertyPatternIsNotReportedAsync ( )
403+ {
404+ const string testCode = @"
405+ public class TestClass
406+ {
407+ public bool TestMethod(string value)
408+ {
409+ return !(value is { Length: 0 });
410+ }
411+ }
412+ " ;
413+
414+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
415+ }
331416 }
332417}
0 commit comments