Skip to content

Commit 9727f83

Browse files
committed
Add tests for spacing around closing braces in tuple expressions
1 parent b25d183 commit 9727f83

3 files changed

Lines changed: 113 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
@@ -54,6 +54,41 @@ public class Foo
5454
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5555
}
5656

57+
/// <summary>
58+
/// Verifies spacing around a <c>}</c> character in tuple expressions.
59+
/// </summary>
60+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
61+
/// <seealso cref="SA1009CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
62+
/// <seealso cref="SA1013CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
63+
[Fact]
64+
public async Task TestSpacingAroundClosingBraceInTupleExpressionsAsync()
65+
{
66+
const string testCode = @"using System;
67+
68+
public class Foo
69+
{
70+
public void TestMethod()
71+
{
72+
var values = (new[] { 3} , new[] { 3} );
73+
}
74+
}";
75+
const string fixedCode = @"using System;
76+
77+
public class Foo
78+
{
79+
public void TestMethod()
80+
{
81+
var values = (new[] { 3}, new[] { 3} );
82+
}
83+
}";
84+
85+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 34).WithArguments(" not", "preceded");
86+
87+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
88+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
89+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
90+
}
91+
5792
/// <summary>
5893
/// Verifies spacing around a <c>&gt;</c> character in tuple types.
5994
/// </summary>

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

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

57+
/// <summary>
58+
/// Verifies spacing around a <c>}</c> character in tuple expressions.
59+
/// </summary>
60+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
61+
/// <seealso cref="SA1001CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
62+
/// <seealso cref="SA1013CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
63+
[Fact]
64+
public async Task TestSpacingAroundClosingBraceInTupleExpressionsAsync()
65+
{
66+
const string testCode = @"using System;
67+
68+
public class Foo
69+
{
70+
public void TestMethod()
71+
{
72+
var values = (new[] { 3} , new[] { 3} );
73+
}
74+
}";
75+
const string fixedCode = @"using System;
76+
77+
public class Foo
78+
{
79+
public void TestMethod()
80+
{
81+
var values = (new[] { 3} , new[] { 3});
82+
}
83+
}";
84+
85+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 47).WithArguments(" not", "preceded");
86+
87+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
88+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
89+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
90+
}
91+
5792
/// <summary>
5893
/// Verifies spacing around a <c>&gt;</c> character in tuple types.
5994
/// </summary>

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

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

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

812
public class SA1013CSharp7UnitTests : SA1013UnitTests
913
{
14+
/// <summary>
15+
/// Verifies spacing around a <c>}</c> character in tuple expressions.
16+
/// </summary>
17+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
18+
/// <seealso cref="SA1001CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
19+
/// <seealso cref="SA1009CSharp7UnitTests.TestSpacingAroundClosingBraceInTupleExpressionsAsync"/>
20+
[Fact]
21+
public async Task TestSpacingAroundClosingBraceInTupleExpressionsAsync()
22+
{
23+
const string testCode = @"using System;
24+
25+
public class Foo
26+
{
27+
public void TestMethod()
28+
{
29+
var values = (new[] { 3} , new[] { 3} );
30+
}
31+
}";
32+
const string fixedCode = @"using System;
33+
34+
public class Foo
35+
{
36+
public void TestMethod()
37+
{
38+
var values = (new[] { 3 } , new[] { 3 } );
39+
}
40+
}";
41+
42+
DiagnosticResult[] expected =
43+
{
44+
this.CSharpDiagnostic().WithLocation(7, 32).WithArguments(string.Empty, "preceded"),
45+
this.CSharpDiagnostic().WithLocation(7, 45).WithArguments(string.Empty, "preceded"),
46+
};
47+
48+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
49+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
50+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
51+
}
1052
}
1153
}

0 commit comments

Comments
 (0)