public async Task TestStaticOperatorInInterface() { var source = @" internal interface I<T> where T : I<T> { abstract static int operator +(T x); } internal class C : I<C> { static int I<C>.operator +(C x) { throw new System.NotImplementedException(); } } "; var test = new VerifyCS.Test { TestCode = source, FixedCode = source, LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.Preview, ReferenceAssemblies = Testing.ReferenceAssemblies.Net.Net60 }; await test.RunAsync(); }
public async Task TopLevelStatement() { var source = @" int i = 0; [|switch|] (i) { case 1: return 4; default: return 7; }"; var fixedSource = @" int i = 0; return i switch { 1 => 4, _ => 7, }; "; var test = new VerifyCS.Test { TestCode = source, FixedCode = fixedSource, LanguageVersion = LanguageVersion.Preview, }; test.ExpectedDiagnostics.Add( // error CS8805: Program using top-level statements must be an executable. DiagnosticResult.CompilerError("CS8805")); await test.RunAsync(); }
public async Task TestPartial_WithExistingModifier() { var source = @" partial class [|C|] { } public partial class C { } "; var fixedSource = @" public partial class C { } public partial class C { } "; var test = new VerifyCS.Test { TestCode = source, FixedCode = fixedSource, LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.Preview, }; await test.RunAsync(); }
public async Task TestRecords() { var source = @" record [|Record|] { int [|field|]; } namespace System.Runtime.CompilerServices { public sealed class IsExternalInit { } }"; var fixedSource = @" internal record Record { private int field; } namespace System.Runtime.CompilerServices { public sealed class IsExternalInit { } }"; var test = new VerifyCS.Test { TestCode = source, FixedCode = fixedSource, LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.CSharp9, }; await test.RunAsync(); }
private static async Task TestAsync(string initialMarkup, string expectedMarkup) { var test = new VerifyCS.Test { TestCode = initialMarkup, FixedCode = expectedMarkup, CodeActionValidationMode = CodeActionValidationMode.Full, }; await test.RunAsync(); }
private static async Task TestMissingInRegularAndScriptAsync(string testCode, LanguageVersion?languageVersion = null) { var test = new VerifyCS.Test { TestCode = testCode, FixedCode = testCode, }; if (languageVersion != null) { test.LanguageVersion = languageVersion.Value; } await test.RunAsync(); }
public async Task TopLevelStatement_FollowedWithThrow() { // We should be rewriting the declaration for 'j' to get 'var j = i switch ...' var source = @" int i = 0; int j; [|switch|] (i) { case 1: j = 4; break; case 2: j = 5; break; } throw null; "; var fixedSource = @" int i = 0; int j; j = i switch { 1 => 4, 2 => 5, _ => throw null, }; "; var test = new VerifyCS.Test { TestCode = source, FixedCode = fixedSource, LanguageVersion = LanguageVersion.Preview, }; test.ExpectedDiagnostics.Add( // error CS8805: Program using top-level statements must be an executable. DiagnosticResult.CompilerError("CS8805")); await test.RunAsync(); }
private static async Task TestInRegularAndScript1Async( string[] initialMarkup, string[] expectedMarkup, int index = 0, TestParameters?parameters = null, List <DiagnosticResult> fixedExpectedDiagnostics = null) { var test = new VerifyCS.Test { CodeActionIndex = index, }; foreach (var source in initialMarkup) { test.TestState.Sources.Add(source); } foreach (var source in expectedMarkup) { test.FixedState.Sources.Add(source); } if (parameters?.parseOptions != null) { test.LanguageVersion = ((CSharpParseOptions)parameters.Value.parseOptions).LanguageVersion; } if (parameters?.options != null) { test.EditorConfig = CodeFixVerifierHelper.GetEditorConfigText(parameters.Value.options); } foreach (var diagnostic in fixedExpectedDiagnostics ?? new List <DiagnosticResult>()) { test.FixedState.ExpectedDiagnostics.Add(diagnostic); } await test.RunAsync(); }
public async Task TestRecordStructs() { var source = @" record struct [|Record|] { int [|field|]; } "; var fixedSource = @" internal record struct Record { private int field; } "; var test = new VerifyCS.Test { TestCode = source, FixedCode = fixedSource, LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.Preview, }; await test.RunAsync(); }