@@ -349,6 +349,124 @@ public void TestMethod()
349349 await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
350350 }
351351
352+ [ Fact ]
353+ [ WorkItem ( 3816 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3816" ) ]
354+ public async Task TestCommaFollowingPreprocessorDirectiveAsync ( )
355+ {
356+ var testCode = @"
357+ interface IFormattable {}
358+ interface ISpanFormattable {}
359+
360+ partial struct Money : IFormattable
361+ #if true
362+ , ISpanFormattable
363+ #endif
364+ {
365+ }
366+ " ;
367+
368+ var expected = DiagnosticResult . EmptyDiagnosticResults ;
369+
370+ await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
371+ }
372+
373+ [ Fact ]
374+ [ WorkItem ( 3816 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3816" ) ]
375+ public async Task TestCommaFollowingElifDirectiveAsync ( )
376+ {
377+ var testCode = @"
378+ interface IFormattable {}
379+ interface ISpanFormattable {}
380+
381+ partial struct Money : IFormattable
382+ #if false
383+ #elif true
384+ , ISpanFormattable
385+ #endif
386+ {
387+ }
388+ " ;
389+
390+ var expected = DiagnosticResult . EmptyDiagnosticResults ;
391+
392+ await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
393+ }
394+
395+ [ Fact ]
396+ [ WorkItem ( 3816 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3816" ) ]
397+ public async Task TestCommaFollowingElseDirectiveAsync ( )
398+ {
399+ var testCode = @"
400+ interface IFormattable {}
401+ interface ISpanFormattable {}
402+
403+ partial struct Money : IFormattable
404+ #if false
405+ #else
406+ , ISpanFormattable
407+ #endif
408+ {
409+ }
410+ " ;
411+
412+ var expected = DiagnosticResult . EmptyDiagnosticResults ;
413+
414+ await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
415+ }
416+
417+ [ Fact ]
418+ [ WorkItem ( 3816 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3816" ) ]
419+ public async Task TestCommaFollowingEndIfDirectiveAsync ( )
420+ {
421+ var testCode = @"
422+ interface IFormattable {}
423+ interface ISpanFormattable {}
424+
425+ partial struct Money : IFormattable
426+ #if false
427+ #endif
428+ , ISpanFormattable
429+ {
430+ }
431+ " ;
432+
433+ var expected = DiagnosticResult . EmptyDiagnosticResults ;
434+
435+ await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
436+ }
437+
438+ [ Fact ]
439+ [ WorkItem ( 3816 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3816" ) ]
440+ public async Task TestCommaNotFollowingDirectiveAsync ( )
441+ {
442+ var testCode = @"
443+ interface IFormattable {}
444+ interface ISpanFormattable {}
445+
446+ partial struct Money : IFormattable
447+ {|#0:,|} ISpanFormattable
448+ {
449+ }
450+ " ;
451+
452+ var fixedCode = @"
453+ interface IFormattable {}
454+ interface ISpanFormattable {}
455+
456+ partial struct Money : IFormattable,
457+ ISpanFormattable
458+ {
459+ }
460+ " ;
461+
462+ var expected = new [ ]
463+ {
464+ Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( " not" , "preceded" ) ,
465+ } ;
466+
467+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
468+ }
469+
352470 private Task TestCommaInStatementOrDeclAsync ( string originalStatement , DiagnosticResult expected , string fixedStatement )
353471 {
354472 return this . TestCommaInStatementOrDeclAsync ( originalStatement , new [ ] { expected } , fixedStatement ) ;
0 commit comments