From 3b72d1d2b8fc141caf349125e3a4dd74a6982dfb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 20 Dec 2024 21:20:05 +0100 Subject: [PATCH] Add 'CSharpCodeFixTest<,>' helper type --- ...harpCodeFixerTest{TAnalyzer,TCodeFixer}.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Helpers/CSharpCodeFixerTest{TAnalyzer,TCodeFixer}.cs diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Helpers/CSharpCodeFixerTest{TAnalyzer,TCodeFixer}.cs b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Helpers/CSharpCodeFixerTest{TAnalyzer,TCodeFixer}.cs new file mode 100644 index 00000000..7a2dfd36 --- /dev/null +++ b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Helpers/CSharpCodeFixerTest{TAnalyzer,TCodeFixer}.cs @@ -0,0 +1,40 @@ +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp.Testing; + +#pragma warning disable IDE0290 + +namespace ComputeSharp.Tests.SourceGenerators.Helpers; + +/// +/// A custom that uses a specific C# language version to parse code. +/// +/// The type of the analyzer to produce diagnostics. +/// The type of code fix to test. +internal sealed class CSharpCodeFixTest : CSharpCodeFixTest + where TAnalyzer : DiagnosticAnalyzer, new() + where TCodeFixer : CodeFixProvider, new() +{ + /// + /// The C# language version to use to parse code. + /// + private readonly LanguageVersion languageVersion; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The C# language version to use to parse code. + public CSharpCodeFixTest(LanguageVersion languageVersion) + { + this.languageVersion = languageVersion; + } + + /// + protected override ParseOptions CreateParseOptions() + { + return new CSharpParseOptions(this.languageVersion, DocumentationMode.Diagnose); + } +}