Skip to content

Commit 57a8b93

Browse files
committed
Add tests for SA1024 in tuple expressions
1 parent b812c06 commit 57a8b93

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,64 @@
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 SA1024CSharp7UnitTests : SA1024UnitTests
917
{
18+
/// <summary>
19+
/// Verifies spacing around a <c>:</c> character in tuple expressions.
20+
/// </summary>
21+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
22+
[Fact]
23+
public async Task TestSpacingAroundColonInTupleExpressionsAsync()
24+
{
25+
const string testCode = @"using System;
26+
27+
public class Foo
28+
{
29+
public void TestMethod()
30+
{
31+
var values = (x :3, y :4);
32+
}
33+
}";
34+
const string fixedCode = @"using System;
35+
36+
public class Foo
37+
{
38+
public void TestMethod()
39+
{
40+
var values = (x: 3, y: 4);
41+
}
42+
}";
43+
44+
DiagnosticResult[] expected =
45+
{
46+
this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(" not", "preceded", string.Empty),
47+
this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(string.Empty, "followed", string.Empty),
48+
this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(" not", "preceded", string.Empty),
49+
this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(string.Empty, "followed", string.Empty),
50+
};
51+
52+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
53+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
54+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
55+
}
56+
57+
protected override Solution CreateSolution(ProjectId projectId, string language)
58+
{
59+
Solution solution = base.CreateSolution(projectId, language);
60+
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
61+
return solution
62+
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
63+
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
64+
}
1065
}
1166
}

0 commit comments

Comments
 (0)