Skip to content

Commit 3761711

Browse files
committed
Add SA1008 tests for ref expressions
1 parent 9727f83 commit 3761711

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,62 @@
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;
11+
12+
using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly;
713

814
public class SA1008CSharp7UnitTests : SA1008UnitTests
915
{
16+
/// <summary>
17+
/// Verifies that spacing for <c>ref</c> expressions is handled properly.
18+
/// </summary>
19+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
20+
[Fact]
21+
public async Task TestRefExpressionAsync()
22+
{
23+
var testCode = @"namespace TestNamespace
24+
{
25+
using System.Threading.Tasks;
26+
27+
public class TestClass
28+
{
29+
public void TestMethod()
30+
{
31+
int test = 1;
32+
ref int t = ref( test);
33+
}
34+
}
35+
}
36+
";
37+
38+
var fixedCode = @"namespace TestNamespace
39+
{
40+
using System.Threading.Tasks;
41+
42+
public class TestClass
43+
{
44+
public void TestMethod()
45+
{
46+
int test = 1;
47+
ref int t = ref (test);
48+
}
49+
}
50+
}
51+
";
52+
53+
DiagnosticResult[] expectedDiagnostics =
54+
{
55+
this.CSharpDiagnostic(DescriptorPreceded).WithLocation(10, 28),
56+
this.CSharpDiagnostic(DescriptorNotFollowed).WithLocation(10, 28),
57+
};
58+
59+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
60+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
61+
await this.VerifyCSharpFixAsync(testCode, fixedCode, numberOfFixAllIterations: 2).ConfigureAwait(false);
62+
}
1063
}
1164
}

0 commit comments

Comments
 (0)