Skip to content

Commit db6febe

Browse files
Improve coverage for SA1201 by adding tests with record structs.
1 parent 88cf7a1 commit db6febe

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/OrderingRules/SA1201CSharp10UnitTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,42 @@ public struct {|#1:FooStruct|} { }
5151

5252
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
5353
}
54+
55+
[Fact]
56+
public async Task TestOuterOrderWithRecordStructCorrectOrderAsync()
57+
{
58+
var testCode = @"namespace Foo { }
59+
public delegate void bar();
60+
public enum TestEnum { }
61+
public interface IFoo { }
62+
public record struct FooStruct { }
63+
public class FooClass { }
64+
";
65+
66+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
67+
await VerifyCSharpDiagnosticAsync("namespace OuterNamespace { " + testCode + " }", DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
68+
}
69+
70+
[Fact]
71+
public async Task TestOuterOrderWithRecordStructWrongOrderAsync()
72+
{
73+
var testCode = @"
74+
namespace Foo { }
75+
public enum TestEnum { }
76+
public delegate void {|#0:bar|}();
77+
public interface IFoo { }
78+
public class FooClass { }
79+
public record struct {|#1:FooStruct|} { }
80+
";
81+
82+
var expected = new[]
83+
{
84+
Diagnostic().WithLocation(0).WithArguments("delegate", "enum"),
85+
Diagnostic().WithLocation(1).WithArguments("record struct", "class"),
86+
};
87+
88+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
89+
await VerifyCSharpDiagnosticAsync("namespace OuterNamespace { " + testCode + " }", expected, CancellationToken.None).ConfigureAwait(false);
90+
}
5491
}
5592
}

0 commit comments

Comments
 (0)