|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules |
5 | 5 | { |
6 | | - using Test.SpacingRules; |
| 6 | + using System; |
| 7 | + using System.Linq; |
| 8 | + using System.Reflection; |
| 9 | + using System.Threading; |
| 10 | + using System.Threading.Tasks; |
| 11 | + using Microsoft.CodeAnalysis; |
| 12 | + using StyleCop.Analyzers.Test.SpacingRules; |
| 13 | + using TestHelper; |
| 14 | + using Xunit; |
7 | 15 |
|
8 | 16 | public class SA1024CSharp7UnitTests : SA1024UnitTests |
9 | 17 | { |
| 18 | + /// <summary> |
| 19 | + /// Verifies spacing around a <c>:</c> character in tuple expressions. |
| 20 | + /// </summary> |
| 21 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 22 | + [Fact] |
| 23 | + public async Task TestSpacingAroundColonInTupleExpressionsAsync() |
| 24 | + { |
| 25 | + const string testCode = @"using System; |
| 26 | +
|
| 27 | +public class Foo |
| 28 | +{ |
| 29 | + public void TestMethod() |
| 30 | + { |
| 31 | + var values = (x :3, y :4); |
| 32 | + } |
| 33 | +}"; |
| 34 | + const string fixedCode = @"using System; |
| 35 | +
|
| 36 | +public class Foo |
| 37 | +{ |
| 38 | + public void TestMethod() |
| 39 | + { |
| 40 | + var values = (x: 3, y: 4); |
| 41 | + } |
| 42 | +}"; |
| 43 | + |
| 44 | + DiagnosticResult[] expected = |
| 45 | + { |
| 46 | + this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(" not", "preceded", string.Empty), |
| 47 | + this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(string.Empty, "followed", string.Empty), |
| 48 | + this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(" not", "preceded", string.Empty), |
| 49 | + this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(string.Empty, "followed", string.Empty), |
| 50 | + }; |
| 51 | + |
| 52 | + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); |
| 53 | + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 54 | + await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); |
| 55 | + } |
| 56 | + |
| 57 | + protected override Solution CreateSolution(ProjectId projectId, string language) |
| 58 | + { |
| 59 | + Solution solution = base.CreateSolution(projectId, language); |
| 60 | + Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime"); |
| 61 | + return solution |
| 62 | + .AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location)) |
| 63 | + .AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location)); |
| 64 | + } |
10 | 65 | } |
11 | 66 | } |
0 commit comments