Skip to content

Commit 7611192

Browse files
committed
Add tests for spacing around closing generic brackets in tuple types
1 parent d7d623a commit 7611192

3 files changed

Lines changed: 127 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1001CSharp7UnitTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ public class Foo
5858
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5959
}
6060

61+
/// <summary>
62+
/// Verifies spacing around a <c>&gt;</c> character in tuple types.
63+
/// </summary>
64+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
65+
/// <seealso cref="SA1009CSharp7UnitTests.TestClosingGenericBracketsInTupleTypesNotFollowedBySpaceAsync"/>
66+
/// <seealso cref="SA1015CSharp7UnitTests.TestClosingGenericBracketsInTupleTypesNotPrecededBySpaceAsync"/>
67+
[Fact]
68+
public async Task TestClosingGenericBracketsInTupleTypesNotFollowedBySpaceAsync()
69+
{
70+
const string testCode = @"using System;
71+
72+
public class Foo
73+
{
74+
public void TestMethod()
75+
{
76+
(Func<int > , Func<int > ) value = (null, null);
77+
}
78+
}";
79+
const string fixedCode = @"using System;
80+
81+
public class Foo
82+
{
83+
public void TestMethod()
84+
{
85+
(Func<int >, Func<int > ) value = (null, null);
86+
}
87+
}";
88+
89+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 21).WithArguments(" not", "preceded");
90+
91+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
92+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
93+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
94+
}
95+
6196
protected override Solution CreateSolution(ProjectId projectId, string language)
6297
{
6398
Solution solution = base.CreateSolution(projectId, language);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1009CSharp7UnitTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ public class Foo
5858
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5959
}
6060

61+
/// <summary>
62+
/// Verifies spacing around a <c>&gt;</c> character in tuple types.
63+
/// </summary>
64+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
65+
/// <seealso cref="SA1001CSharp7UnitTests.TestClosingGenericBracketsInTupleTypesNotFollowedBySpaceAsync"/>
66+
/// <seealso cref="SA1015CSharp7UnitTests.TestClosingGenericBracketsInTupleTypesNotPrecededBySpaceAsync"/>
67+
[Fact]
68+
public async Task TestClosingGenericBracketsInTupleTypesNotFollowedBySpaceAsync()
69+
{
70+
const string testCode = @"using System;
71+
72+
public class Foo
73+
{
74+
public void TestMethod()
75+
{
76+
(Func<int > , Func<int > ) value = (null, null);
77+
}
78+
}";
79+
const string fixedCode = @"using System;
80+
81+
public class Foo
82+
{
83+
public void TestMethod()
84+
{
85+
(Func<int > , Func<int >) value = (null, null);
86+
}
87+
}";
88+
89+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 34).WithArguments(" not", "preceded");
90+
91+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
92+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
93+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
94+
}
95+
6196
protected override Solution CreateSolution(ProjectId projectId, string language)
6297
{
6398
Solution solution = base.CreateSolution(projectId, language);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1015CSharp7UnitTests.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,65 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
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;
715

816
public class SA1015CSharp7UnitTests : SA1015UnitTests
917
{
18+
/// <summary>
19+
/// Verifies spacing around a <c>&gt;</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+
}
1066
}
1167
}

0 commit comments

Comments
 (0)