Skip to content

Commit

Permalink
Add tests for SA1024 in tuple expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 11, 2017
1 parent b812c06 commit 57a8b93
Showing 1 changed file with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,64 @@

namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
{
using Test.SpacingRules;
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using StyleCop.Analyzers.Test.SpacingRules;
using TestHelper;
using Xunit;

public class SA1024CSharp7UnitTests : SA1024UnitTests
{
/// <summary>
/// Verifies spacing around a <c>:</c> character in tuple expressions.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestSpacingAroundColonInTupleExpressionsAsync()
{
const string testCode = @"using System;
public class Foo
{
public void TestMethod()
{
var values = (x :3, y :4);
}
}";
const string fixedCode = @"using System;
public class Foo
{
public void TestMethod()
{
var values = (x: 3, y: 4);
}
}";

DiagnosticResult[] expected =
{
this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(" not", "preceded", string.Empty),
this.CSharpDiagnostic().WithLocation(7, 25).WithArguments(string.Empty, "followed", string.Empty),
this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(" not", "preceded", string.Empty),
this.CSharpDiagnostic().WithLocation(7, 31).WithArguments(string.Empty, "followed", string.Empty),
};

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
}

protected override Solution CreateSolution(ProjectId projectId, string language)
{
Solution solution = base.CreateSolution(projectId, language);
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
return solution
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
}
}
}

0 comments on commit 57a8b93

Please sign in to comment.