Skip to content

Commit

Permalink
Add 'CSharpCodeFixTest<,>' helper type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 20, 2024
1 parent 3340fe7 commit 7b31a16
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// A custom <see cref="CSharpCodeFixTest{TAnalyzer, TCodeFix, TVerifier}"/> that uses a specific C# language version to parse code.
/// </summary>
/// <typeparam name="TAnalyzer">The type of the analyzer to produce diagnostics.</typeparam>
/// <typeparam name="TCodeFixer">The type of code fix to test.</typeparam>
internal sealed class CSharpCodeFixTest<TAnalyzer, TCodeFixer> : CSharpCodeFixTest<TAnalyzer, TCodeFixer, DefaultVerifier>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFixer : CodeFixProvider, new()
{
/// <summary>
/// The C# language version to use to parse code.
/// </summary>
private readonly LanguageVersion languageVersion;

/// <summary>
/// Creates a new <see cref="CSharpCodeFixTest{TAnalyzer, TCodeFix}"/> instance with the specified parameters.
/// </summary>
/// <param name="languageVersion">The C# language version to use to parse code.</param>
public CSharpCodeFixTest(LanguageVersion languageVersion)
{
this.languageVersion = languageVersion;
}

/// <inheritdoc/>
protected override ParseOptions CreateParseOptions()
{
return new CSharpParseOptions(this.languageVersion, DocumentationMode.Diagnose);
}
}

0 comments on commit 7b31a16

Please sign in to comment.