@@ -24,7 +24,7 @@ public class SA1516CSharp9UnitTests : SA1516CSharp8UnitTests
2424 /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
2525 [ Fact ]
2626 [ WorkItem ( 3242 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3242" ) ]
27- public async Task TestStatementSpacingInTopLevelProgramAsync ( )
27+ public async Task TestUsingAndGlobalStatementSpacingInTopLevelProgramAsync ( )
2828 {
2929 var testCode = @"using System;
3030using System.Threading;
@@ -55,5 +55,64 @@ public async Task TestStatementSpacingInTopLevelProgramAsync()
5555 FixedCode = fixedCode ,
5656 } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
5757 }
58+
59+ /// <summary>
60+ /// Verifies that SA1516 is not reported between global statement in top-level programs.
61+ /// </summary>
62+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
63+ [ Fact ]
64+ [ WorkItem ( 3351 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3351" ) ]
65+ public async Task TestGlobalStatementSpacingInTopLevelProgramAsync ( )
66+ {
67+ var testCode = @"int i = 0;
68+ return i;
69+ " ;
70+
71+ await new CSharpTest ( LanguageVersion . CSharp9 )
72+ {
73+ ReferenceAssemblies = ReferenceAssemblies . Net . Net50 ,
74+ TestState =
75+ {
76+ OutputKind = OutputKind . ConsoleApplication ,
77+ Sources = { testCode } ,
78+ } ,
79+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
80+ }
81+
82+ /// <summary>
83+ /// Verifies that SA1516 is reported between global statement and record declaration in top-level programs.
84+ /// </summary>
85+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
86+ [ Fact ]
87+ public async Task TestGlobalStatementAndRecordSpacingInTopLevelProgramAsync ( )
88+ {
89+ var testCode = @"return 0;
90+ {|#0:record|} A();
91+ " ;
92+
93+ var fixedCode = @"return 0;
94+
95+ record A();
96+ " ;
97+
98+ await new CSharpTest ( LanguageVersion . CSharp9 )
99+ {
100+ ReferenceAssemblies = ReferenceAssemblies . Net . Net50 ,
101+ TestState =
102+ {
103+ OutputKind = OutputKind . ConsoleApplication ,
104+ Sources = { testCode } ,
105+ ExpectedDiagnostics =
106+ {
107+ // /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
108+ Diagnostic ( ) . WithLocation ( 0 ) ,
109+
110+ // /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
111+ Diagnostic ( ) . WithLocation ( 0 ) ,
112+ } ,
113+ } ,
114+ FixedCode = fixedCode ,
115+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
116+ }
58117 }
59118}
0 commit comments