extern alias Core;
#if D2D1_TESTS
extern alias D2D1;
#else
extern alias D3D12;
#endif
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.Tests.SourceGenerators.Helpers;
///
/// A custom that uses a specific C# language version to parse code.
///
/// The type of the analyzer to test.
internal sealed class CSharpAnalyzerWithLanguageVersionTest : CSharpAnalyzerTest
where TAnalyzer : DiagnosticAnalyzer, new()
{
///
/// The C# language version to use to parse code.
///
private readonly LanguageVersion languageVersion;
///
/// Creates a new instance with the specified paramaters.
///
/// The C# language version to use to parse code.
private CSharpAnalyzerWithLanguageVersionTest(LanguageVersion languageVersion)
{
this.languageVersion = languageVersion;
}
///
protected override ParseOptions CreateParseOptions()
{
return new CSharpParseOptions(this.languageVersion, DocumentationMode.Diagnose);
}
///
/// The source code to analyze.
/// The language version to use to run the test.
public static Task VerifyAnalyzerAsync(string source, LanguageVersion languageVersion = LanguageVersion.CSharp12)
{
CSharpAnalyzerWithLanguageVersionTest test = new(languageVersion) { TestCode = source };
test.TestState.ReferenceAssemblies = ReferenceAssemblies.Net.Net80;
test.TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(Core::ComputeSharp.Hlsl).Assembly.Location));
#if D2D1_TESTS
test.TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly.Location));
#else
test.TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(D3D12::ComputeSharp.IComputeShader).Assembly.Location));
#endif
return test.RunAsync(CancellationToken.None);
}
}