11// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- #nullable disable
5-
64namespace StyleCop . Analyzers . Test . OrderingRules
75{
6+ using System . Collections . Generic ;
7+ using System . Linq ;
88 using System . Threading ;
99 using System . Threading . Tasks ;
1010 using Microsoft . CodeAnalysis . Testing ;
11+ using StyleCop . Analyzers . Test . Helpers ;
1112 using Xunit ;
1213
1314 using static StyleCop . Analyzers . Test . Verifiers . StyleCopCodeFixVerifier <
@@ -16,6 +17,20 @@ namespace StyleCop.Analyzers.Test.OrderingRules
1617
1718 public class SA1201UnitTests
1819 {
20+ public static IEnumerable < object [ ] > ValueTypesAndReferenceTypes
21+ {
22+ get
23+ {
24+ foreach ( var valueTypeKeyword in CommonMemberData . ValueTypeDeclarationKeywords )
25+ {
26+ foreach ( var referenceTypeKeyword in CommonMemberData . ReferenceTypeDeclarationKeywords )
27+ {
28+ yield return new object [ ] { valueTypeKeyword . Single ( ) , referenceTypeKeyword . Single ( ) } ;
29+ }
30+ }
31+ }
32+ }
33+
1934 [ Fact ]
2035 public async Task TestOuterOrderCorrectOrderAsync ( )
2136 {
@@ -52,6 +67,35 @@ public struct FooStruct { }
5267 await VerifyCSharpDiagnosticAsync ( "namespace OuterNamespace { " + testCode + " }" , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
5368 }
5469
70+ [ Theory ]
71+ [ MemberData ( nameof ( ValueTypesAndReferenceTypes ) ) ]
72+ public async Task TestClassBeforeStructAsync (
73+ string structKeyword ,
74+ string classKeyword )
75+ {
76+ string testCode = $@ "
77+ public { classKeyword } FooClass {{ }}
78+ public { structKeyword } {{|#0:FooStruct|}} {{ }}
79+ " ;
80+ string fixedCode = $@ "public { structKeyword } FooStruct {{ }}
81+
82+ public { classKeyword } FooClass {{ }}
83+ " ;
84+
85+ var reportedClassKind = classKeyword switch
86+ {
87+ "record class" => "record" ,
88+ _ => classKeyword ,
89+ } ;
90+
91+ var expected = new [ ]
92+ {
93+ Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( structKeyword , reportedClassKind ) ,
94+ } ;
95+
96+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
97+ }
98+
5599 [ Fact ]
56100 public async Task TestTypeMemberOrderCorrectOrderClassAsync ( )
57101 {
0 commit comments