|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis; |
| 9 | + using Microsoft.CodeAnalysis.CSharp; |
| 10 | + using Microsoft.CodeAnalysis.Testing; |
6 | 11 | using StyleCop.Analyzers.Test.CSharp8.LayoutRules; |
| 12 | + using Xunit; |
| 13 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 14 | + StyleCop.Analyzers.LayoutRules.SA1516ElementsMustBeSeparatedByBlankLine, |
| 15 | + StyleCop.Analyzers.LayoutRules.SA1516CodeFixProvider>; |
7 | 16 |
|
8 | 17 | public class SA1516CSharp9UnitTests : SA1516CSharp8UnitTests |
9 | 18 | { |
| 19 | + /// <summary> |
| 20 | + /// Verifies that SA1516 is reported at the correct location in top-level programs. |
| 21 | + /// </summary> |
| 22 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 23 | + [Fact] |
| 24 | + [WorkItem(3242, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3242")] |
| 25 | + public async Task TestStatementSpacingInTopLevelProgramAsync() |
| 26 | + { |
| 27 | + var testCode = @"using System; |
| 28 | +using System.Threading; |
| 29 | +{|#0:return|} 0; |
| 30 | +"; |
| 31 | + var fixedCode = @"using System; |
| 32 | +using System.Threading; |
| 33 | +
|
| 34 | +return 0; |
| 35 | +"; |
| 36 | + |
| 37 | + await new CSharpTest(LanguageVersion.CSharp9) |
| 38 | + { |
| 39 | + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, |
| 40 | + TestCode = testCode, |
| 41 | + ExpectedDiagnostics = |
| 42 | + { |
| 43 | + // /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line |
| 44 | + Diagnostic().WithLocation(0), |
| 45 | + |
| 46 | + // /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line |
| 47 | + Diagnostic().WithLocation(0), |
| 48 | + }, |
| 49 | + FixedCode = fixedCode, |
| 50 | + SolutionTransforms = |
| 51 | + { |
| 52 | + (solution, projectId) => |
| 53 | + { |
| 54 | + var project = solution.GetProject(projectId); |
| 55 | + var options = project.CompilationOptions; |
| 56 | + return solution.WithProjectCompilationOptions(projectId, options.WithOutputKind(OutputKind.ConsoleApplication)); |
| 57 | + }, |
| 58 | + }, |
| 59 | + }.RunAsync(CancellationToken.None).ConfigureAwait(false); |
| 60 | + } |
10 | 61 | } |
11 | 62 | } |
0 commit comments