11
11
using Microsoft . CodeAnalysis . CSharp ;
12
12
using CommunityToolkit . Mvvm . ComponentModel ;
13
13
using Microsoft . VisualStudio . TestTools . UnitTesting ;
14
- using System . Reflection . Emit ;
15
14
16
15
namespace CommunityToolkit . Mvvm . SourceGenerators . UnitTests ;
17
16
@@ -249,7 +248,6 @@ public partial class SampleViewModel
249
248
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
250
249
"MVVMTK0008" ) ;
251
250
252
- // Ensure that it succeeds with the minimum supported language version
253
251
VerifySuccessfulGeneration ( source ) ;
254
252
}
255
253
@@ -271,7 +269,6 @@ public partial class SampleViewModel
271
269
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
272
270
"MVVMTK0008" ) ;
273
271
274
- // Ensure that it succeeds with the minimum supported language version
275
272
VerifySuccessfulGeneration ( source ) ;
276
273
}
277
274
@@ -295,7 +292,6 @@ public partial class SampleViewModel
295
292
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
296
293
"MVVMTK0008" ) ;
297
294
298
- // Ensure that it succeeds with the minimum supported language version
299
295
VerifySuccessfulGeneration ( source ) ;
300
296
}
301
297
@@ -319,7 +315,6 @@ public partial class SampleViewModel : ObservableValidator
319
315
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
320
316
"MVVMTK0008" ) ;
321
317
322
- // Ensure that it succeeds with the minimum supported language version
323
318
VerifySuccessfulGeneration ( source ) ;
324
319
}
325
320
@@ -344,7 +339,6 @@ private void GreetUser(object value)
344
339
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
345
340
"MVVMTK0008" ) ;
346
341
347
- // Ensure that it succeeds with the minimum supported language version
348
342
VerifySuccessfulGeneration ( source ) ;
349
343
}
350
344
@@ -372,7 +366,6 @@ public void Receive(MyMessage message)
372
366
CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp7_3 ) ) ,
373
367
"MVVMTK0008" ) ;
374
368
375
- // Ensure that it succeeds with the minimum supported language version
376
369
VerifySuccessfulGeneration ( source ) ;
377
370
}
378
371
@@ -1454,22 +1447,9 @@ public partial class SampleViewModel
1454
1447
}
1455
1448
1456
1449
/// <summary>
1457
- /// Verifies the output of a source generator .
1450
+ /// Verifies that all available source generators can run successfully with the input source (including subsequent compilation) .
1458
1451
/// </summary>
1459
- /// <typeparam name="TGenerator">The generator type to use.</typeparam>
1460
1452
/// <param name="source">The input source to process.</param>
1461
- /// <param name="diagnosticsIds">The diagnostic ids to expect for the input source code.</param>
1462
- private static void VerifyGeneratedDiagnostics < TGenerator > ( string source , params string [ ] diagnosticsIds )
1463
- where TGenerator : class , IIncrementalGenerator , new ( )
1464
- {
1465
- IIncrementalGenerator generator = new TGenerator ( ) ;
1466
- VerifyGeneratedDiagnostics ( CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp8 ) ) , new [ ] { generator } , diagnosticsIds ) ;
1467
- }
1468
-
1469
- /// <summary>
1470
- /// Verifies the output of all source generators for input source (including subsequent compilation).
1471
- /// </summary>
1472
- /// <param name="source"></param>
1473
1453
private static void VerifySuccessfulGeneration ( string source )
1474
1454
{
1475
1455
IIncrementalGenerator [ ] generators =
@@ -1483,7 +1463,22 @@ private static void VerifySuccessfulGeneration(string source)
1483
1463
new ObservableValidatorValidateAllPropertiesGenerator ( ) ,
1484
1464
new RelayCommandGenerator ( )
1485
1465
} ;
1486
- VerifyGeneratedDiagnostics ( CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp8 ) ) , generators , new string [ ] { } ) ;
1466
+
1467
+ VerifyGeneratedDiagnostics ( CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp8 ) ) , generators , Array . Empty < string > ( ) ) ;
1468
+ }
1469
+
1470
+ /// <summary>
1471
+ /// Verifies the output of a source generator.
1472
+ /// </summary>
1473
+ /// <typeparam name="TGenerator">The generator type to use.</typeparam>
1474
+ /// <param name="source">The input source to process.</param>
1475
+ /// <param name="diagnosticsIds">The diagnostic ids to expect for the input source code.</param>
1476
+ private static void VerifyGeneratedDiagnostics < TGenerator > ( string source , params string [ ] diagnosticsIds )
1477
+ where TGenerator : class , IIncrementalGenerator , new ( )
1478
+ {
1479
+ IIncrementalGenerator generator = new TGenerator ( ) ;
1480
+
1481
+ VerifyGeneratedDiagnostics ( CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp8 ) ) , new [ ] { generator } , diagnosticsIds ) ;
1487
1482
}
1488
1483
1489
1484
/// <summary>
@@ -1496,6 +1491,7 @@ private static void VerifyGeneratedDiagnostics<TGenerator>(SyntaxTree syntaxTree
1496
1491
where TGenerator : class , IIncrementalGenerator , new ( )
1497
1492
{
1498
1493
IIncrementalGenerator generator = new TGenerator ( ) ;
1494
+
1499
1495
VerifyGeneratedDiagnostics ( syntaxTree , new [ ] { generator } , diagnosticsIds ) ;
1500
1496
}
1501
1497
0 commit comments