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