File tree Expand file tree Collapse file tree 1 file changed +69
-1
lines changed
test/ProgressOnderwijsUtils.Analyzers.Tests Expand file tree Collapse file tree 1 file changed +69
-1
lines changed Original file line number Diff line number Diff line change 11using System . Linq ;
22using System . Threading . Tasks ;
33using ExpressionToCodeLib ;
4+ using Microsoft . CodeAnalysis ;
45using Xunit ;
56
67namespace ProgressOnderwijsUtils . Analyzers . Tests ;
@@ -151,11 +152,78 @@ void M()
151152 }
152153 """ ,
153154 } ,
155+ new {
156+ Source = """
157+ class C
158+ {
159+ void M()
160+ {
161+ if (!false) { System.Console.WriteLine("A"); } else { System.Console.WriteLine("B"); }
162+ }
163+ }
164+ """ ,
165+ Expected = """
166+ class C
167+ {
168+ void M()
169+ {
170+ System.Console.WriteLine("A");
171+ }
172+ }
173+ """ ,
174+ } ,
175+ new {
176+ Source = """
177+ class C
178+ {
179+ void M()
180+ {
181+ if (!false) { System.Console.WriteLine("A"); } else { System.Console.WriteLine("B"); }
182+ }
183+ }
184+ """ ,
185+ Expected = """
186+ class C
187+ {
188+ void M()
189+ {
190+ System.Console.WriteLine("A");
191+ }
192+ }
193+ """ ,
194+ } ,
195+ new {
196+ Source = """
197+ class C
198+ {
199+ void M()
200+ {
201+ if (!false)
202+ {
203+ System.Console.WriteLine("A");
204+ }
205+ else
206+ {
207+ System.Console.WriteLine("B");
208+ }
209+ }
210+ }
211+ """ ,
212+ Expected = """
213+ class C
214+ {
215+ void M()
216+ {
217+ System.Console.WriteLine("A");
218+ }
219+ }
220+ """ ,
221+ } ,
154222 } ;
155223
156224 foreach ( var test in testCases ) {
157225 var workspace = DiagnosticHelper . CreateProjectWithTestFile ( test . Source ) ;
158- var diagnostic = DiagnosticHelper . GetDiagnostics ( new IfNotFalseAnalyzer ( ) , workspace ) . Single ( ) ;
226+ var diagnostic = DiagnosticHelper . GetDiagnostics ( new IfNotFalseAnalyzer ( ) , workspace ) . Single ( d => d . Id == IfNotFalseAnalyzer . Rule . Id ) ; // otherwise we could get diagnostic like CS0162 (unreachable code)
159227 var fixesMade = await DiagnosticHelper . ApplyAllCodeFixes ( workspace , diagnostic , new IfNotFalseCodeFix ( ) ) ;
160228 PAssert . That ( ( ) => fixesMade == 1 ) ;
161229
You can’t perform that action at this time.
0 commit comments