File tree Expand file tree Collapse file tree
StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -877,6 +877,45 @@ 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+ }
897+ " ;
898+ var fixedCode = @"class Program
899+ {
900+ static int Main(string[] args)
901+ {
902+ #if !NOT
903+ return 1;
904+ #endif
905+ }
906+ }
907+ " ;
908+
909+ DiagnosticResult [ ] expected =
910+ {
911+ this . CSharpDiagnostic ( DescriptorPrecededByWhitespace ) . WithLocation ( 5 , 4 ) . WithArguments ( "!" ) ,
912+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 5 , 4 ) . WithArguments ( "!" ) ,
913+ } ;
914+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
915+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
916+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
917+ }
918+
880919 /// <inheritdoc/>
881920 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
882921 {
You can’t perform that action at this time.
0 commit comments