Skip to content

Commit 1b1ff97

Browse files
committed
Add regression test for #1831
1 parent 573b29f commit 1b1ff97

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1003UnitTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)