mirror of
https://github.com/github/awesome-copilot.git
synced 2026-08-26 18:45:12 +00:00
chore: publish from main
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CodeFixes;
|
||||
using Microsoft.CodeAnalysis.CSharp.Testing;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
|
||||
namespace Product.Analyzers.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience methods for testing a C# analyzer and its code fix together.
|
||||
/// </summary>
|
||||
/// <typeparam name="TAnalyzer">The analyzer under test.</typeparam>
|
||||
/// <typeparam name="TCodeFix">The code fix under test, or <see cref="EmptyCodeFixProvider"/>.</typeparam>
|
||||
public static class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
|
||||
where TAnalyzer : DiagnosticAnalyzer, new()
|
||||
where TCodeFix : CodeFixProvider, new()
|
||||
{
|
||||
public static DiagnosticResult Diagnostic()
|
||||
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();
|
||||
|
||||
public static DiagnosticResult Diagnostic(string diagnosticId)
|
||||
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);
|
||||
|
||||
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
|
||||
=> new(descriptor);
|
||||
|
||||
public static Task VerifyAnalyzerAsync(
|
||||
[StringSyntax("c#-test")] string source,
|
||||
params DiagnosticResult[] expected)
|
||||
{
|
||||
var test = new CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
|
||||
{
|
||||
TestCode = source,
|
||||
};
|
||||
|
||||
test.ExpectedDiagnostics.AddRange(expected);
|
||||
return test.RunAsync();
|
||||
}
|
||||
|
||||
public static Task VerifyCodeFixAsync(
|
||||
[StringSyntax("c#-test")] string source,
|
||||
[StringSyntax("c#-test")] string fixedSource)
|
||||
=> VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
|
||||
|
||||
public static Task VerifyCodeFixAsync(
|
||||
[StringSyntax("c#-test")] string source,
|
||||
DiagnosticResult expected,
|
||||
[StringSyntax("c#-test")] string fixedSource)
|
||||
=> VerifyCodeFixAsync(source, [expected], fixedSource);
|
||||
|
||||
public static Task VerifyCodeFixAsync(
|
||||
[StringSyntax("c#-test")] string source,
|
||||
DiagnosticResult[] expected,
|
||||
[StringSyntax("c#-test")] string fixedSource)
|
||||
{
|
||||
var test = new CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
|
||||
{
|
||||
TestCode = source,
|
||||
FixedCode = fixedSource,
|
||||
};
|
||||
|
||||
test.ExpectedDiagnostics.AddRange(expected);
|
||||
return test.RunAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user