|
1 | 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. |
3 | 3 |
|
| 4 | +using Xunit; |
4 | 5 | namespace StyleCop.Analyzers.Test.ReadabilityRules |
5 | 6 | { |
6 | 7 | using System.Collections.Generic; |
@@ -421,6 +422,51 @@ public enum ImplicitUseKindFlags { Assign } |
421 | 422 | await this.VerifyCSharpFixAllFixAsync(testCode, fixedTestCode, maxNumberOfIterations: 1).ConfigureAwait(false); |
422 | 423 | } |
423 | 424 |
|
| 425 | + /// <summary> |
| 426 | + /// Regression test for issue 1883 (whitespace is preserved incorrectly): https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1883 |
| 427 | + /// </summary> |
| 428 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 429 | + [Fact] |
| 430 | + public async Task TestWhitespaceIsHandledCorrectlyAsync() |
| 431 | + { |
| 432 | + var testCode = @" |
| 433 | +namespace SA1133CodeFix |
| 434 | +{ |
| 435 | + using System.ComponentModel; |
| 436 | + using System.Diagnostics.CodeAnalysis; |
| 437 | +
|
| 438 | + [DefaultValue(true), |
| 439 | + SuppressMessage(null, null)] |
| 440 | + internal class Foo |
| 441 | + { |
| 442 | + } |
| 443 | +} |
| 444 | +"; |
| 445 | + |
| 446 | + var fixedTestCode = @" |
| 447 | +namespace SA1133CodeFix |
| 448 | +{ |
| 449 | + using System.ComponentModel; |
| 450 | + using System.Diagnostics.CodeAnalysis; |
| 451 | +
|
| 452 | + [DefaultValue(true)] |
| 453 | + [SuppressMessage(null, null)] |
| 454 | + internal class Foo |
| 455 | + { |
| 456 | + } |
| 457 | +} |
| 458 | +"; |
| 459 | + |
| 460 | + DiagnosticResult[] expected = |
| 461 | + { |
| 462 | + this.CSharpDiagnostic().WithLocation(8, 5) |
| 463 | + }; |
| 464 | + |
| 465 | + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); |
| 466 | + await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 467 | + await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false); |
| 468 | + } |
| 469 | + |
424 | 470 | /// <inheritdoc/> |
425 | 471 | protected override CodeFixProvider GetCSharpCodeFixProvider() |
426 | 472 | { |
|
0 commit comments