@@ -152,5 +152,68 @@ public object TestMethod(Foo n, int a)
152152 TestCode = testCode ,
153153 } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
154154 }
155+
156+ [ Fact ]
157+ [ WorkItem ( 3968 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3968" ) ]
158+ public async Task TestOuterParenthesesAroundParenthesizedPatternAreRemovedAsync ( )
159+ {
160+ const string testCode = @"
161+ class C
162+ {
163+ void M(int value)
164+ {
165+ if ({|#0:{|#1:(|}(value is (> 0 and < 5)){|#2:)|}|})
166+ {
167+ }
168+ }
169+ }" ;
170+
171+ const string fixedCode = @"
172+ class C
173+ {
174+ void M(int value)
175+ {
176+ if (value is (> 0 and < 5))
177+ {
178+ }
179+ }
180+ }" ;
181+
182+ await new CSharpTest ( )
183+ {
184+ NumberOfIncrementalIterations = 2 ,
185+ NumberOfFixAllIterations = 2 ,
186+ TestCode = testCode ,
187+ ExpectedDiagnostics =
188+ {
189+ Diagnostic ( DiagnosticId ) . WithLocation ( 0 ) ,
190+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 1 ) ,
191+ Diagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 2 ) ,
192+ } ,
193+ FixedCode = fixedCode ,
194+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
195+ }
196+
197+ /// <summary>
198+ /// Verifies that parentheses required to clarify precedence within patterns are not removed.
199+ /// </summary>
200+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
201+ [ Fact ]
202+ [ WorkItem ( 3968 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3968" ) ]
203+ public async Task TestClarifyingPatternParenthesesAreNotRemovedAsync ( )
204+ {
205+ const string testCode = @"
206+ class C
207+ {
208+ void M(int value)
209+ {
210+ if (value is (> 0 and < 5) or 10)
211+ {
212+ }
213+ }
214+ }" ;
215+
216+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
217+ }
155218 }
156219}
0 commit comments