|
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 SA1009CSharp7UnitTests : SA1009UnitTests |
9 | 17 | { |
| 18 | + /// <summary> |
| 19 | + /// Verifies spacing around a <c>]</c> character in tuple types and expressions. |
| 20 | + /// </summary> |
| 21 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 22 | + /// <seealso cref="SA1001CSharp7UnitTests.TestBracketsInTupleTypesNotFollowedBySpaceAsync"/> |
| 23 | + /// <seealso cref="SA1011CSharp7UnitTests.TestBracketsInTupleTypesNotFollowedBySpaceAsync"/> |
| 24 | + [Fact] |
| 25 | + public async Task TestBracketsInTupleTypesNotFollowedBySpaceAsync() |
| 26 | + { |
| 27 | + const string testCode = @"using System; |
| 28 | +
|
| 29 | +public class Foo |
| 30 | +{ |
| 31 | + public (int[] , int[] ) TestMethod((int[] , int[] ) a) |
| 32 | + { |
| 33 | + (int[] , int[] ) ints = (new int[][] { new[] { 3 } }[0] , new int[][] { new[] { 3 } }[0] ); |
| 34 | + return ints; |
| 35 | + } |
| 36 | +}"; |
| 37 | + const string fixedCode = @"using System; |
| 38 | +
|
| 39 | +public class Foo |
| 40 | +{ |
| 41 | + public (int[] , int[]) TestMethod((int[] , int[]) a) |
| 42 | + { |
| 43 | + (int[] , int[]) ints = (new int[][] { new[] { 3 } }[0] , new int[][] { new[] { 3 } }[0]); |
| 44 | + return ints; |
| 45 | + } |
| 46 | +}"; |
| 47 | + |
| 48 | + DiagnosticResult[] expected = |
| 49 | + { |
| 50 | + this.CSharpDiagnostic().WithLocation(5, 27).WithArguments(" not", "preceded"), |
| 51 | + this.CSharpDiagnostic().WithLocation(5, 55).WithArguments(" not", "preceded"), |
| 52 | + this.CSharpDiagnostic().WithLocation(7, 24).WithArguments(" not", "preceded"), |
| 53 | + this.CSharpDiagnostic().WithLocation(7, 98).WithArguments(" not", "preceded"), |
| 54 | + }; |
| 55 | + |
| 56 | + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); |
| 57 | + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 58 | + await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); |
| 59 | + } |
| 60 | + |
| 61 | + protected override Solution CreateSolution(ProjectId projectId, string language) |
| 62 | + { |
| 63 | + Solution solution = base.CreateSolution(projectId, language); |
| 64 | + Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime"); |
| 65 | + return solution |
| 66 | + .AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location)) |
| 67 | + .AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location)); |
| 68 | + } |
10 | 69 | } |
11 | 70 | } |
0 commit comments