Skip to content

Commit 9fd3ef0

Browse files
committed
Update tests for SA1206 for the new modifiers for structs
1 parent b1a3a50 commit 9fd3ef0

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/OrderingRules/SA1206CSharp7UnitTests.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,66 @@ namespace StyleCop.Analyzers.Test.CSharp7.OrderingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.CSharp;
810
using StyleCop.Analyzers.Test.OrderingRules;
911
using TestHelper;
1012
using Xunit;
1113

1214
public class SA1206CSharp7UnitTests : SA1206UnitTests
1315
{
14-
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
16+
[Fact]
1517
public async Task TestRefKeywordInStructDeclarationAsync()
1618
{
17-
var testCode = @"private ref struct BitHelper
19+
var testCode = @"class OuterClass
1820
{
21+
private ref struct BitHelper
22+
{
23+
}
24+
}
25+
";
26+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
27+
}
28+
29+
[Fact]
30+
public async Task TestReadonlyKeywordInStructDeclarationAsync()
31+
{
32+
var testCode = @"class OuterClass
33+
{
34+
private readonly struct BitHelper
35+
{
36+
}
1937
}
2038
";
2139
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
2240
}
2341

24-
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
25-
public async Task TestRefKeywordInStructDeclarationWrongOrderAsync()
42+
[Fact]
43+
public async Task TestReadonlyKeywordInStructDeclarationWrongOrderAsync()
2644
{
27-
var testCode = @"ref private struct BitHelper
45+
// Note that we don't need a test for ref with the wrong order, because this would be a compile time error
46+
var testCode = @"class OuterClass
2847
{
48+
readonly private struct BitHelper
49+
{
50+
}
2951
}
3052
";
3153

3254
DiagnosticResult[] expected = new[]
3355
{
34-
this.CSharpDiagnostic().WithLocation(1, 13).WithArguments("ref", "private"),
56+
this.CSharpDiagnostic().WithLocation(3, 14).WithArguments("private", "readonly"),
3557
};
3658
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
3759
}
60+
61+
protected override Project ApplyCompilationOptions(Project project)
62+
{
63+
var newProject = base.ApplyCompilationOptions(project);
64+
65+
var parseOptions = (CSharpParseOptions)newProject.ParseOptions;
66+
67+
return newProject.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.Latest));
68+
}
3869
}
3970
}

0 commit comments

Comments
 (0)