|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules |
5 | 5 | { |
6 | | - using Test.SpacingRules; |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using StyleCop.Analyzers.Test.SpacingRules; |
| 9 | + using TestHelper; |
| 10 | + using Xunit; |
| 11 | + |
| 12 | + using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly; |
7 | 13 |
|
8 | 14 | public class SA1008CSharp7UnitTests : SA1008UnitTests |
9 | 15 | { |
| 16 | + /// <summary> |
| 17 | + /// Verifies that spacing for <c>ref</c> expressions is handled properly. |
| 18 | + /// </summary> |
| 19 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 20 | + [Fact] |
| 21 | + public async Task TestRefExpressionAsync() |
| 22 | + { |
| 23 | + var testCode = @"namespace TestNamespace |
| 24 | +{ |
| 25 | + using System.Threading.Tasks; |
| 26 | +
|
| 27 | + public class TestClass |
| 28 | + { |
| 29 | + public void TestMethod() |
| 30 | + { |
| 31 | + int test = 1; |
| 32 | + ref int t = ref( test); |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | +"; |
| 37 | + |
| 38 | + var fixedCode = @"namespace TestNamespace |
| 39 | +{ |
| 40 | + using System.Threading.Tasks; |
| 41 | +
|
| 42 | + public class TestClass |
| 43 | + { |
| 44 | + public void TestMethod() |
| 45 | + { |
| 46 | + int test = 1; |
| 47 | + ref int t = ref (test); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +"; |
| 52 | + |
| 53 | + DiagnosticResult[] expectedDiagnostics = |
| 54 | + { |
| 55 | + this.CSharpDiagnostic(DescriptorPreceded).WithLocation(10, 28), |
| 56 | + this.CSharpDiagnostic(DescriptorNotFollowed).WithLocation(10, 28), |
| 57 | + }; |
| 58 | + |
| 59 | + await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false); |
| 60 | + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 61 | + await this.VerifyCSharpFixAsync(testCode, fixedCode, numberOfFixAllIterations: 2).ConfigureAwait(false); |
| 62 | + } |
10 | 63 | } |
11 | 64 | } |
0 commit comments