@@ -877,6 +877,62 @@ public void TestMethod()
877877 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
878878 }
879879
880+ /// <summary>
881+ /// Verifies that spacing errors in conditional directives are fixed correctly. This is a regression test for
882+ /// DotNetAnalyzers/StyleCopAnalyzers#1831.
883+ /// </summary>
884+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
885+ [ Fact ]
886+ public async Task TestConditionalDirectivesCorrectlyFixedAsync ( )
887+ {
888+ var testCode = @"class Program
889+ {
890+ static int Main(string[] args)
891+ {
892+ #if! NOT
893+ return 1;
894+ #endif
895+
896+ #if! NOT&&! Y
897+ return 1;
898+ #endif
899+ }
900+ }
901+ " ;
902+ var fixedCode = @"class Program
903+ {
904+ static int Main(string[] args)
905+ {
906+ #if !NOT
907+ return 1;
908+ #endif
909+
910+ #if !NOT && !Y
911+ return 1;
912+ #endif
913+ }
914+ }
915+ " ;
916+
917+ DiagnosticResult [ ] expected =
918+ {
919+ this . CSharpDiagnostic ( DescriptorPrecededByWhitespace ) . WithLocation ( 5 , 4 ) . WithArguments ( "!" ) ,
920+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 5 , 4 ) . WithArguments ( "!" ) ,
921+
922+ this . CSharpDiagnostic ( DescriptorPrecededByWhitespace ) . WithLocation ( 9 , 4 ) . WithArguments ( "!" ) ,
923+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 9 , 4 ) . WithArguments ( "!" ) ,
924+
925+ this . CSharpDiagnostic ( DescriptorPrecededByWhitespace ) . WithLocation ( 9 , 9 ) . WithArguments ( "&&" ) ,
926+ this . CSharpDiagnostic ( DescriptorFollowedByWhitespace ) . WithLocation ( 9 , 9 ) . WithArguments ( "&&" ) ,
927+
928+ this . CSharpDiagnostic ( DescriptorPrecededByWhitespace ) . WithLocation ( 9 , 11 ) . WithArguments ( "!" ) ,
929+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 9 , 11 ) . WithArguments ( "!" ) ,
930+ } ;
931+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
932+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
933+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
934+ }
935+
880936 /// <inheritdoc/>
881937 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
882938 {
0 commit comments