diff --git a/src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs b/src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs index 38eb4c2c153f9..9829f22f6f62e 100644 --- a/src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs @@ -63,31 +63,31 @@ private Task TestInRegularAndScriptAsync( [WpfFact] public async Task AddMissingImports_AddImport_PasteContainsSingleMissingImport() { - var code = @" -class C -{ - public [|D|] Foo { get; } -} + var code = """ + class C + { + public [|D|] Foo { get; } + } -namespace A -{ - public class D { } -} -"; + namespace A + { + public class D { } + } + """; - var expected = @" -using A; + var expected = """ + using A; -class C -{ - public D Foo { get; } -} + class C + { + public D Foo { get; } + } -namespace A -{ - public class D { } -} -"; + namespace A + { + public class D { } + } + """; await TestInRegularAndScriptAsync(code, expected); } @@ -95,47 +95,47 @@ public class D { } [WpfFact] public async Task AddMissingImports_AddImportsBelowSystem_PlaceSystemFirstPasteContainsMultipleMissingImports() { - var code = @" -using System; + var code = """ + using System; -class C -{ - [|public D Foo { get; } - public E Bar { get; }|] -} + class C + { + [|public D Foo { get; } + public E Bar { get; }|] + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; - var expected = @" -using System; -using A; -using B; + var expected = """ + using System; + using A; + using B; -class C -{ - public D Foo { get; } - public E Bar { get; } -} + class C + { + public D Foo { get; } + public E Bar { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; await TestInRegularAndScriptAsync(code, expected, placeSystemNamespaceFirst: true, separateImportDirectiveGroups: false); } @@ -143,47 +143,47 @@ public class E { } [WpfFact] public async Task AddMissingImports_AddImportsAboveSystem_DoNotPlaceSystemFirstPasteContainsMultipleMissingImports() { - var code = @" -using System; + var code = """ + using System; -class C -{ - [|public D Foo { get; } - public E Bar { get; }|] -} + class C + { + [|public D Foo { get; } + public E Bar { get; }|] + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; - var expected = @" -using A; -using B; -using System; + var expected = """ + using A; + using B; + using System; -class C -{ - public D Foo { get; } - public E Bar { get; } -} + class C + { + public D Foo { get; } + public E Bar { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; await TestInRegularAndScriptAsync(code, expected, placeSystemNamespaceFirst: false, separateImportDirectiveGroups: false); } @@ -191,48 +191,48 @@ public class E { } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/pull/42221")] public async Task AddMissingImports_AddImportsUngrouped_SeparateImportGroupsPasteContainsMultipleMissingImports() { - var code = @" -using System; + var code = """ + using System; -class C -{ - [|public D Foo { get; } - public E Bar { get; }|] -} + class C + { + [|public D Foo { get; } + public E Bar { get; }|] + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; - var expected = @" -using A; -using B; + var expected = """ + using A; + using B; -using System; + using System; -class C -{ - public D Foo { get; } - public E Bar { get; } -} + class C + { + public D Foo { get; } + public E Bar { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; await TestInRegularAndScriptAsync(code, expected, placeSystemNamespaceFirst: false, separateImportDirectiveGroups: true); } @@ -240,45 +240,45 @@ public class E { } [WpfFact] public async Task AddMissingImports_PartialFix_PasteContainsFixableAndAmbiguousMissingImports() { - var code = @" -class C -{ - [|public D Foo { get; } - public E Bar { get; }|] -} + var code = """ + class C + { + [|public D Foo { get; } + public E Bar { get; }|] + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class D { } - public class E { } -} -"; + namespace B + { + public class D { } + public class E { } + } + """; - var expected = @" -using B; + var expected = """ + using B; -class C -{ - public D Foo { get; } - public E Bar { get; } -} + class C + { + public D Foo { get; } + public E Bar { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class D { } - public class E { } -} -"; + namespace B + { + public class D { } + public class E { } + } + """; await TestInRegularAndScriptAsync(code, expected); } @@ -286,17 +286,17 @@ public class E { } [WpfFact] public async Task AddMissingImports_NoAction_NoPastedSpan() { - var code = @" -class C -{ - public D[||] Foo { get; } -} + var code = """ + class C + { + public D[||] Foo { get; } + } -namespace A -{ - public class D { } -} -"; + namespace A + { + public class D { } + } + """; await TestMissingInRegularAndScriptAsync(code); } @@ -304,17 +304,17 @@ public class D { } [WpfFact] public async Task AddMissingImports_NoAction_PasteIsNotMissingImports() { - var code = @" -class [|C|] -{ - public D Foo { get; } -} + var code = """ + class [|C|] + { + public D Foo { get; } + } -namespace A -{ - public class D { } -} -"; + namespace A + { + public class D { } + } + """; await TestMissingInRegularAndScriptAsync(code); } @@ -322,22 +322,22 @@ public class D { } [WpfFact] public async Task AddMissingImports_NoAction_PasteContainsAmibiguousMissingImport() { - var code = @" -class C -{ - public [|D|] Foo { get; } -} + var code = """ + class C + { + public [|D|] Foo { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class D { } -} -"; + namespace B + { + public class D { } + } + """; await TestMissingInRegularAndScriptAsync(code); } @@ -346,44 +346,44 @@ public class D { } [WpfFact] public async Task AddMissingImports_AddMultipleImports_NoPreviousImports() { - var code = @" -class C -{ - [|public D Foo { get; } - public E Bar { get; }|] -} + var code = """ + class C + { + [|public D Foo { get; } + public E Bar { get; }|] + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; - var expected = @" -using A; -using B; + var expected = """ + using A; + using B; -class C -{ - public D Foo { get; } - public E Bar { get; } -} + class C + { + public D Foo { get; } + public E Bar { get; } + } -namespace A -{ - public class D { } -} + namespace A + { + public class D { } + } -namespace B -{ - public class E { } -} -"; + namespace B + { + public class E { } + } + """; await TestInRegularAndScriptAsync(code, expected, placeSystemNamespaceFirst: false, separateImportDirectiveGroups: false); } diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBracketCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBracketCompletionTests.cs index 372324fa830cf..81c518f916762 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBracketCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBracketCompletionTests.cs @@ -45,10 +45,12 @@ public void Attribute_TopLevel2() [WpfFact] public void InvalidLocation_String() { - var code = @"class C -{ - string s = ""$$ -}"; + var code = """ + class C + { + string s = "$$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -56,11 +58,13 @@ public void InvalidLocation_String() [WpfFact] public void InvalidLocation_String2() { - var code = @"class C -{ - string s = @"" -$$ -}"; + var code = """ + class C + { + string s = @" + $$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -68,10 +72,12 @@ public void InvalidLocation_String2() [WpfFact] public void InvalidLocation_Comment() { - var code = @"class C -{ - //$$ -}"; + var code = """ + class C + { + //$$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -79,10 +85,12 @@ public void InvalidLocation_Comment() [WpfFact] public void InvalidLocation_Comment2() { - var code = @"class C -{ - /* $$ -}"; + var code = """ + class C + { + /* $$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -90,10 +98,12 @@ public void InvalidLocation_Comment2() [WpfFact] public void InvalidLocation_Comment3() { - var code = @"class C -{ - /// $$ -}"; + var code = """ + class C + { + /// $$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -101,10 +111,12 @@ public void InvalidLocation_Comment3() [WpfFact] public void InvalidLocation_Comment4() { - var code = @"class C -{ - /** $$ -}"; + var code = """ + class C + { + /** $$ + } + """; using var session = CreateSession(code); Assert.Null(session); } @@ -112,13 +124,15 @@ public void InvalidLocation_Comment4() [WpfFact] public void MultiLine_Comment() { - var code = @"class C -{ - void Method() - { - /* */$$ - } -}"; + var code = """ + class C + { + void Method() + { + /* */$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -128,13 +142,15 @@ void Method() [WpfFact] public void MultiLine_DocComment() { - var code = @"class C -{ - void Method() - { - /** */$$ - } -}"; + var code = """ + class C + { + void Method() + { + /** */$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -144,13 +160,15 @@ void Method() [WpfFact] public void String1() { - var code = @"class C -{ - void Method() - { - var s = """"$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = ""$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -160,13 +178,15 @@ void Method() [WpfFact] public void String2() { - var code = @"class C -{ - void Method() - { - var s = @""""$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @""$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -176,8 +196,10 @@ void Method() [WpfFact] public void Attribute_OpenBracket() { - var code = @"$$ -class C { }"; + var code = """ + $$ + class C { } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -188,8 +210,10 @@ class C { }"; [WpfFact] public void Attribute_OpenBracket_Delete() { - var code = @"$$ -class C { }"; + var code = """ + $$ + class C { } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -201,8 +225,10 @@ class C { }"; [WpfFact] public void Attribute_OpenBracket_Tab() { - var code = @"$$ -class C { }"; + var code = """ + $$ + class C { } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -214,8 +240,10 @@ class C { }"; [WpfFact] public void Attribute_OpenBracket_CloseBracket() { - var code = @"$$ -class C { }"; + var code = """ + $$ + class C { } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -227,10 +255,12 @@ class C { }"; [WpfFact] public void Array_Multiple_Invalid() { - var code = @"class C -{ - int [$$] -}"; + var code = """ + class C + { + int [$$] + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -241,10 +271,12 @@ int [$$] [WpfFact] public void Array_Nested() { - var code = @"class C -{ - int [] i = new int [arr$$] -}"; + var code = """ + class C + { + int [] i = new int [arr$$] + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -254,36 +286,36 @@ public void Array_Nested() [WpfFact] public void ListPattern() { - var code = @" -class C -{ - void M(object o) - { - _ = o is$$ - } -} -"; - var expectedBeforeReturn = @" -class C -{ - void M(object o) - { - _ = o is [] - } -} -"; - var expected = @" -class C -{ - void M(object o) - { - _ = o is - [ - - ] - } -} -"; + var code = """ + class C + { + void M(object o) + { + _ = o is$$ + } + } + """; + var expectedBeforeReturn = """ + class C + { + void M(object o) + { + _ = o is [] + } + } + """; + var expected = """ + class C + { + void M(object o) + { + _ = o is + [ + + ] + } + } + """; using var session = CreateSession(code); CheckStart(session.Session); CheckText(session.Session, expectedBeforeReturn); diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLessAndGreaterThanCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLessAndGreaterThanCompletionTests.cs index 90278f958f549..bf3c19bdb047d 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLessAndGreaterThanCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLessAndGreaterThanCompletionTests.cs @@ -52,10 +52,12 @@ public void Class_TypeParameter() [WpfFact] public void Method_TypeParameter() { - var code = @"class C -{ - void Method$$ -}"; + var code = """ + class C + { + void Method$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -108,10 +110,12 @@ public void Multiple_Invalid() [WpfFact] public void Multiple_Nested() { - var code = @"class C -{ - C -}"; + var code = """ + class C + { + C + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -121,14 +125,16 @@ public void Multiple_Nested() [WpfFact] public void TypeArgument_Invalid() { - var code = @"class C -{ - void Method() - { - var i = 1; - var b = i $$ - } -}"; + var code = """ + class C + { + void Method() + { + var i = 1; + var b = i $$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -137,13 +143,15 @@ void Method() [WpfFact] public void TypeArgument1() { - var code = @"class C -{ - void Method() - { - var a = new List$$ - } -}"; + var code = """ + class C + { + void Method() + { + var a = new List$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -152,13 +160,15 @@ void Method() [WpfFact] public void TypeArgument2() { - var code = @"class C -{ - void Method() - { - var a = typeof(List$$ - } -}"; + var code = """ + class C + { + void Method() + { + var a = typeof(List$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -168,10 +178,12 @@ void Method() [WpfFact] public void TypeParameterReturnType() { - var code = @"class C -{ - List$$ -}"; + var code = """ + class C + { + List$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -183,10 +195,12 @@ public void TypeParameterReturnType() [WpfFact] public void TypeParameterInDecl() { - var code = @"class C -{ - void List$$ -}"; + var code = """ + class C + { + void List$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -198,10 +212,12 @@ void List$$ [WpfFact] public void TypeParameterInDeclWith() { - var code = @"class C -{ - async Task$$ -}"; + var code = """ + class C + { + async Task$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -213,15 +229,17 @@ async Task$$ [WpfFact] public void TypeArgumentWithUsing() { - var code = @"using System.Collections.Generic; - -class C -{ - void Test() - { - List$$ - } -}"; + var code = """ + using System.Collections.Generic; + + class C + { + void Test() + { + List$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -233,13 +251,15 @@ void Test() [WpfFact] public void TypeArgumentNoUsing() { - var code = @"class C -{ - void Test() - { - List$$ - } -}"; + var code = """ + class C + { + void Test() + { + List$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -249,14 +269,16 @@ void Test() [WpfFact] public void NotInLessThanComparisonOperation() { - var code = @"using System.Linq; -class C -{ - void Test(int[] args) - { - var a = args[0]$$ - } -}"; + var code = """ + using System.Linq; + class C + { + void Test(int[] args) + { + var a = args[0]$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -266,14 +288,16 @@ void Test(int[] args) [WpfFact] public void NotInLessThanComparisonOperationAfterConditionalAccessExpression() { - var code = @"using System.Linq; -class C -{ - void Test(object[] args, object[] other) - { - var a = args?.First()$$ - } -}"; + var code = """ + using System.Linq; + class C + { + void Test(object[] args, object[] other) + { + var a = args?.First()$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -283,14 +307,16 @@ void Test(object[] args, object[] other) [WpfFact] public void TypeArgumentInConditionalAccessExpressionSimple() { - var code = @"using System.Linq; -class C -{ - void Test(object[] args) - { - args?.OfType$$ - } -}"; + var code = """ + using System.Linq; + class C + { + void Test(object[] args) + { + args?.OfType$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -300,25 +326,27 @@ void Test(object[] args) [WpfFact] public void TypeArgumentInConditionalAccessExpressionNested() { - var code = @"class C -{ - void Test() - { - Outer t = new Outer(); - t?.GetInner()?.Method$$ - } -} -class Outer -{ - public Inner GetInner() - { - return new Inner(); - } -} -class Inner -{ - public void Method() { } -}"; + var code = """ + class C + { + void Test() + { + Outer t = new Outer(); + t?.GetInner()?.Method$$ + } + } + class Outer + { + public Inner GetInner() + { + return new Inner(); + } + } + class Inner + { + public void Method() { } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -330,33 +358,35 @@ public void Method() { } [WpfFact] public void TypeArgumentInConditionalAccessExpressionDeeplyNested() { - var code = @"class C -{ - void Test() - { - new Outer1()?.GetInner()?.GetInner().DoSomething$$ - } -} -internal class Outer1 -{ - public Outer2 GetInner() - { - return new Outer2(); - } -} -internal class Outer2 -{ - public Outer2() { } - public Inner GetInner() - { - return new Inner(); - } -} -internal class Inner -{ - public Inner() { } - public void DoSomething() { } -}"; + var code = """ + class C + { + void Test() + { + new Outer1()?.GetInner()?.GetInner().DoSomething$$ + } + } + internal class Outer1 + { + public Outer2 GetInner() + { + return new Outer2(); + } + } + internal class Outer2 + { + public Outer2() { } + public Inner GetInner() + { + return new Inner(); + } + } + internal class Inner + { + public Inner() { } + public void DoSomething() { } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -366,31 +396,33 @@ public void DoSomething() { } [WpfFact] public void TypeArgumentInConditionalAccessExpressionWithLambdas() { - var code = @"using System; -using System.Collections.Generic; -using System.Linq; - -class Program -{ - void Goo(object[] args) - { - var a = new Outer(); - a?.M(x => x?.ToString())?.Method$$ - } -} - -public class Outer -{ - internal Inner M(Func p) - { - throw new NotImplementedException(); - } -} - -public class Inner -{ - public void Method() { } -}"; + var code = """ + using System; + using System.Collections.Generic; + using System.Linq; + + class Program + { + void Goo(object[] args) + { + var a = new Outer(); + a?.M(x => x?.ToString())?.Method$$ + } + } + + public class Outer + { + internal Inner M(Func p) + { + throw new NotImplementedException(); + } + } + + public class Inner + { + public void Method() { } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -399,10 +431,11 @@ public void Method() { } [WpfFact] public void FunctionPointerStartSession() { - var code = @" -class C -{ - delegate*$$"; + var code = """ + class C + { + delegate*$$ + """; using var session = CreateSession(code); Assert.NotNull(session); diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLiteralCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLiteralCompletionTests.cs index e22ef9a569a3c..e72052289dd4c 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLiteralCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticLiteralCompletionTests.cs @@ -65,13 +65,15 @@ public void VerbatimString_TopLevel2() [WpfFact] public void String_String() { - var code = @"class C -{ - void Method() - { - var s = """"$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = ""$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -80,13 +82,15 @@ void Method() [WpfFact] public void String_VerbatimString() { - var code = @"class C -{ - void Method() - { - var s = """"@$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = ""@$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -95,13 +99,15 @@ void Method() [WpfFact] public void String_Char() { - var code = @"class C -{ - void Method() - { - var s = @""""$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @""$$ + } + } + """; using var session = CreateSessionSingleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -110,13 +116,15 @@ void Method() [WpfFact] public void Method_String() { - var code = @"class C -{ - void Method() - { - var s = $$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -125,13 +133,15 @@ void Method() [WpfFact] public void Method_String_Delete() { - var code = @"class C -{ - void Method() - { - var s = $$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -141,13 +151,15 @@ void Method() [WpfFact] public void Method_String_Tab() { - var code = @"class C -{ - void Method() - { - var s = $$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -157,13 +169,15 @@ void Method() [WpfFact] public void Method_String_Quotation() { - var code = @"class C -{ - void Method() - { - var s = $$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -173,13 +187,15 @@ void Method() [WpfFact] public void VerbatimMethod_String() { - var code = @"class C -{ - void Method() - { - var s = @$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -188,13 +204,15 @@ void Method() [WpfFact] public void VerbatimMethod_String_Delete() { - var code = @"class C -{ - void Method() - { - var s = @$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -204,13 +222,15 @@ void Method() [WpfFact] public void VerbatimMethod_String_Tab() { - var code = @"class C -{ - void Method() - { - var s = @$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -220,13 +240,15 @@ void Method() [WpfFact] public void VerbatimMethod_String_Quotation() { - var code = @"class C -{ - void Method() - { - var s = @$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -236,13 +258,15 @@ void Method() [WpfFact] public void Method_InterpolatedString() { - var code = @"class C -{ - void Method() - { - var s = $[||]$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $[||]$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -251,13 +275,15 @@ void Method() [WpfFact] public void Method_InterpolatedString_Delete() { - var code = @"class C -{ - void Method() - { - var s = $[||]$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $[||]$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -267,13 +293,15 @@ void Method() [WpfFact] public void Method_InterpolatedString_Tab() { - var code = @"class C -{ - void Method() - { - var s = $[||]$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $[||]$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -283,13 +311,15 @@ void Method() [WpfFact] public void Method_InterpolatedString_Quotation() { - var code = @"class C -{ - void Method() - { - var s = $[||]$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $[||]$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -299,13 +329,15 @@ void Method() [WpfFact] public void VerbatimMethod_InterpolatedString() { - var code = @"class C -{ - void Method() - { - var s = $@$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $@$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -314,13 +346,15 @@ void Method() [WpfFact] public void VerbatimMethod_InterpolatedString_Delete() { - var code = @"class C -{ - void Method() - { - var s = $@$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $@$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -330,13 +364,15 @@ void Method() [WpfFact] public void VerbatimMethod_InterpolatedString_Tab() { - var code = @"class C -{ - void Method() - { - var s = $@$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $@$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -346,13 +382,15 @@ void Method() [WpfFact] public void VerbatimMethod_InterpolatedString_Quotation() { - var code = @"class C -{ - void Method() - { - var s = $@$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = $@$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -362,13 +400,15 @@ void Method() [WpfFact] public void Preprocessor1() { - var code = @"class C -{ - void Method() - { -#line $$ - } -}"; + var code = """ + class C + { + void Method() + { + #line $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -378,13 +418,15 @@ void Method() [WpfFact] public void Preprocessor2() { - var code = @"class C -{ - void Method() - { -#line $$ - } -}"; + var code = """ + class C + { + void Method() + { + #line $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -394,13 +436,15 @@ void Method() [WpfFact] public void Preprocessor3() { - var code = @"class C -{ - void Method() - { -#line $$ - } -}"; + var code = """ + class C + { + void Method() + { + #line $$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -411,13 +455,15 @@ void Method() [WpfFact] public void VerbatimStringDoubleQuote() { - var code = @"class C -{ - void Method() - { - var s = @""""$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @""$$ + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -426,13 +472,15 @@ void Method() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59178")] public void String_CompleteLiteral() { - var code = @"class C -{ - void Method() - { - var s = ""this"" + $$that""; - } -}"; + var code = """ + class C + { + void Method() + { + var s = "this" + $$that"; + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); @@ -441,13 +489,15 @@ void Method() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59178")] public void String_BeforeOtherString1() { - var code = @"class C -{ - void Method() - { - var s = $$ + "" + bar""; - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + " + bar"; + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -456,13 +506,15 @@ void Method() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59178")] public void String_BeforeOtherString2() { - var code = @"class C -{ - void Method() - { - var s = $$ + ""; } ""; - } -}"; + var code = """ + class C + { + void Method() + { + var s = $$ + "; } "; + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -471,14 +523,16 @@ void Method() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59178")] public void String_DoNotCompleteVerbatim() { - var code = @"class C -{ - void Method() - { - var s = ""this"" + @$$that - and this""; - } -}"; + var code = """ + class C + { + void Method() + { + var s = "this" + @$$that + and this"; + } + } + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session); @@ -487,11 +541,13 @@ void Method() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59178")] public void String_CompleteLiteral_EndOfFile() { - var code = @"class C -{ - void Method() - { - var s = ""this"" + $$that"""; + var code = """ + class C + { + void Method() + { + var s = "this" + $$that" + """; using var session = CreateSessionDoubleQuote(code); Assert.NotNull(session); CheckStart(session.Session, expectValidSession: false); diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticParenthesisCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticParenthesisCompletionTests.cs index ae8d551ef2c14..ce67d48cdd059 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticParenthesisCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticParenthesisCompletionTests.cs @@ -27,13 +27,15 @@ public void Creation() [WpfFact] public void String1() { - var code = @"class C -{ - void Method() - { - var s = """"$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = ""$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -42,13 +44,15 @@ void Method() [WpfFact] public void String2() { - var code = @"class C -{ - void Method() - { - var s = @""""$$ - } -}"; + var code = """ + class C + { + void Method() + { + var s = @""$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -57,10 +61,12 @@ void Method() [WpfFact] public void ParameterList_OpenParenthesis() { - var code = @"class C -{ - void Method$$ -}"; + var code = """ + class C + { + void Method$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -70,10 +76,12 @@ void Method$$ [WpfFact] public void ParameterList_OpenParenthesis_Delete() { - var code = @"class C -{ - void Method$$ -}"; + var code = """ + class C + { + void Method$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -84,10 +92,12 @@ void Method$$ [WpfFact] public void ParameterList_OpenParenthesis_Tab() { - var code = @"class C -{ - void Method$$ -}"; + var code = """ + class C + { + void Method$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -98,10 +108,12 @@ void Method$$ [WpfFact] public void ParameterList_OpenParenthesis_CloseParenthesis() { - var code = @"class C -{ - void Method$$ -}"; + var code = """ + class C + { + void Method$$ + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -112,13 +124,15 @@ void Method$$ [WpfFact] public void Argument() { - var code = @"class C -{ - void Method() - { - Method$$ - } -}"; + var code = """ + class C + { + void Method() + { + Method$$ + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -128,13 +142,15 @@ void Method() [WpfFact] public void Argument_Invalid() { - var code = @"class C -{ - void Method() - { - Method($$) - } -}"; + var code = """ + class C + { + void Method() + { + Method($$) + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); @@ -144,13 +160,15 @@ void Method() [WpfFact] public void Array_Nested() { - var code = @"class C -{ - int Method(int i) - { - Method(Method$$) - } -}"; + var code = """ + class C + { + int Method(int i) + { + Method(Method$$) + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); CheckStart(session.Session); @@ -160,17 +178,18 @@ int Method(int i) [WpfFact] public void OpenParenthesisWithExistingCloseParen() { - var code = @"class A -{ - public A(int a, int b) { } - - public static A Create() - { - return new A$$ - 0, 0); - } -} -"; + var code = """ + class A + { + public A(int a, int b) { } + + public static A Create() + { + return new A$$ + 0, 0); + } + } + """; using var session = CreateSession(code); Assert.NotNull(session); diff --git a/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs b/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs index 1d83013f42519..7b856631b6820 100644 --- a/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs +++ b/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs @@ -25,182 +25,182 @@ public sealed class CloseBlockCommentTests : AbstractTypingCommandHandlerTest* $$ -"; - var expected = @" - /* - * -*/$$ -"; + var code = """ + /* + * + * $$ + """; + var expected = """ + /* + * + */$$ + """; VerifyTabs(code, expected); } [WpfFact] public void NotClosedAfterAsteriskSpaceWithOptionOff() { - var code = @" - /* - * - * $$ -"; - var expected = @" - /* - * - * /$$ -"; + var code = """ + /* + * + * $$ + """; + var expected = """ + /* + * + * /$$ + """; Verify(code, expected, workspace => { var globalOptions = workspace.GetService(); @@ -292,50 +292,52 @@ public void NotClosedAfterAsteriskSpaceWithOptionOff() [WpfFact] public void NotClosedAfterAsteriskSpaceOutsideComment() { - var code = @" - / * - * - * $$ -"; - var expected = @" - / * - * - * /$$ -"; + var code = """ + / * + * + * $$ + """; + var expected = """ + / * + * + * /$$ + """; Verify(code, expected); } [WpfFact] public void NotClosedAfterAsteriskSpaceInsideString() { - var code = @" -class C -{ - string s = @"" - /* - * - * $$ -"; - var expected = @" -class C -{ - string s = @"" - /* - * - * /$$ -"; + var code = """ + class C + { + string s = @" + /* + * + * $$ + """; + var expected = """ + class C + { + string s = @" + /* + * + * /$$ + """; Verify(code, expected); } [WpfFact] public void ClosedAfterAsteriskSpaceEndOfFile() { - var code = @" - /* - * $$"; - var expected = @" - /* - */$$"; + var code = """ + /* + * $$ + """; + var expected = """ + /* + */$$ + """; Verify(code, expected); } diff --git a/src/EditorFeatures/CSharpTest/BraceMatching/CSharpBraceMatcherTests.cs b/src/EditorFeatures/CSharpTest/BraceMatching/CSharpBraceMatcherTests.cs index ee8dd9977911f..eec2fc6f10469 100644 --- a/src/EditorFeatures/CSharpTest/BraceMatching/CSharpBraceMatcherTests.cs +++ b/src/EditorFeatures/CSharpTest/BraceMatching/CSharpBraceMatcherTests.cs @@ -625,18 +625,20 @@ public async Task TestVerbatimUtf8String7() [WpfFact] public async Task TestConditionalDirectiveWithSingleMatchingDirective() { - var code = @" -public class C -{ -#if$$ CHK -#endif -}"; - var expected = @" -public class C -{ -#if$$ CHK -[|#endif|] -}"; + var code = """ + public class C + { + #if$$ CHK + #endif + } + """; + var expected = """ + public class C + { + #if$$ CHK + [|#endif|] + } + """; await TestAsync(code, expected); } @@ -645,20 +647,22 @@ public class C [WpfFact] public async Task TestConditionalDirectiveWithTwoMatchingDirectives() { - var code = @" -public class C -{ -#if$$ CHK -#else -#endif -}"; - var expected = @" -public class C -{ -#if$$ CHK -[|#else|] -#endif -}"; + var code = """ + public class C + { + #if$$ CHK + #else + #endif + } + """; + var expected = """ + public class C + { + #if$$ CHK + [|#else|] + #endif + } + """; await TestAsync(code, expected); } @@ -667,22 +671,24 @@ public class C [WpfFact] public async Task TestConditionalDirectiveWithAllMatchingDirectives() { - var code = @" -public class C -{ -#if CHK -#elif RET -#else -#endif$$ -}"; - var expected = @" -public class C -{ -[|#if|] CHK -#elif RET -#else -#endif -}"; + var code = """ + public class C + { + #if CHK + #elif RET + #else + #endif$$ + } + """; + var expected = """ + public class C + { + [|#if|] CHK + #elif RET + #else + #endif + } + """; await TestAsync(code, expected); } @@ -691,18 +697,20 @@ public class C [WpfFact] public async Task TestRegionDirective() { - var code = @" -public class C -{ -$$#region test -#endregion -}"; - var expected = @" -public class C -{ -#region test -[|#endregion|] -}"; + var code = """ + public class C + { + $$#region test + #endregion + } + """; + var expected = """ + public class C + { + #region test + [|#endregion|] + } + """; await TestAsync(code, expected); } @@ -711,36 +719,38 @@ public class C [WpfFact] public async Task TestInterleavedDirectivesInner() { - var code = @" -#define CHK -public class C -{ - void Test() - { -#if CHK -$$#region test - var x = 5; -#endregion -#else - var y = 6; -#endif - } -}"; - var expected = @" -#define CHK -public class C -{ - void Test() - { -#if CHK -#region test - var x = 5; -[|#endregion|] -#else - var y = 6; -#endif - } -}"; + var code = """ + #define CHK + public class C + { + void Test() + { + #if CHK + $$#region test + var x = 5; + #endregion + #else + var y = 6; + #endif + } + } + """; + var expected = """ + #define CHK + public class C + { + void Test() + { + #if CHK + #region test + var x = 5; + [|#endregion|] + #else + var y = 6; + #endif + } + } + """; await TestAsync(code, expected); } @@ -749,36 +759,38 @@ void Test() [WpfFact] public async Task TestInterleavedDirectivesOuter() { - var code = @" -#define CHK -public class C -{ - void Test() - { -#if$$ CHK -#region test - var x = 5; -#endregion -#else - var y = 6; -#endif - } -}"; - var expected = @" -#define CHK -public class C -{ - void Test() - { -#if CHK -#region test - var x = 5; -#endregion -[|#else|] - var y = 6; -#endif - } -}"; + var code = """ + #define CHK + public class C + { + void Test() + { + #if$$ CHK + #region test + var x = 5; + #endregion + #else + var y = 6; + #endif + } + } + """; + var expected = """ + #define CHK + public class C + { + void Test() + { + #if CHK + #region test + var x = 5; + #endregion + [|#else|] + var y = 6; + #endif + } + } + """; await TestAsync(code, expected); } @@ -787,16 +799,18 @@ void Test() [WpfFact] public async Task TestUnmatchedDirective1() { - var code = @" -public class C -{ -$$#region test -}"; - var expected = @" -public class C -{ -#region test -}"; + var code = """ + public class C + { + $$#region test + } + """; + var expected = """ + public class C + { + #region test + } + """; await TestAsync(code, expected); } @@ -805,16 +819,18 @@ public class C [WpfFact] public async Task TestUnmatchedDirective2() { - var code = @" -#d$$efine CHK -public class C -{ -}"; - var expected = @" -#define CHK -public class C -{ -}"; + var code = """ + #d$$efine CHK + public class C + { + } + """; + var expected = """ + #define CHK + public class C + { + } + """; await TestAsync(code, expected); } @@ -823,22 +839,24 @@ public class C [WpfFact] public async Task TestUnmatchedConditionalDirective() { - var code = @" -class Program -{ - static void Main(string[] args) - {#if$$ + var code = """ + class Program + { + static void Main(string[] args) + {#if$$ - } -}"; - var expected = @" -class Program -{ - static void Main(string[] args) - {#if + } + } + """; + var expected = """ + class Program + { + static void Main(string[] args) + {#if - } -}"; + } + } + """; await TestAsync(code, expected); } @@ -847,22 +865,24 @@ static void Main(string[] args) [WpfFact] public async Task TestUnmatchedConditionalDirective2() { - var code = @" -class Program -{ - static void Main(string[] args) - {#else$$ - - } -}"; - var expected = @" -class Program -{ - static void Main(string[] args) - {#else - - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + {#else$$ + + } + } + """; + var expected = """ + class Program + { + static void Main(string[] args) + {#else + + } + } + """; await TestAsync(code, expected); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.AddImports.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.AddImports.cs index db291e17526f3..a762076eefa27 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.AddImports.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.AddImports.cs @@ -20,11 +20,12 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task AddParameterAddsAllImports() { - var markup = @" -class C -{ - void $$M() { } -}"; + var markup = """ + class C + { + void $$M() { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex( @@ -35,16 +36,17 @@ class C CallSiteKind.Todo), "System.Collections.Generic.Dictionary>")}; - var updatedCode = @" -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Threading.Tasks; + var updatedCode = """ + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; -class C -{ - void M(Dictionary> test) { } -}"; + class C + { + void M(Dictionary> test) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -52,13 +54,14 @@ void M(Dictionary> test) { } [Fact] public async Task AddParameterAddsOnlyMissingImports() { - var markup = @" -using System.ComponentModel; + var markup = """ + using System.ComponentModel; -class C -{ - void $$M() { } -}"; + class C + { + void $$M() { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex( @@ -69,16 +72,17 @@ class C CallSiteKind.Todo), "System.Collections.Generic.Dictionary>")}; - var updatedCode = @" -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Threading.Tasks; + var updatedCode = """ + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; -class C -{ - void M(Dictionary> test) { } -}"; + class C + { + void M(Dictionary> test) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -86,29 +90,30 @@ void M(Dictionary> test) { } [Fact] public async Task AddParameterAddsImportsOnCascading() { - var markup = @" -using NS1; - -namespace NS1 -{ - class B - { - public virtual void M() { } - } -} - -namespace NS2 -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Threading.Tasks; - - class D : B - { - public override void $$M() { } - } -}"; + var markup = """ + using NS1; + + namespace NS1 + { + class B + { + public virtual void M() { } + } + } + + namespace NS2 + { + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; + + class D : B + { + public override void $$M() { } + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex( @@ -119,33 +124,34 @@ class D : B CallSiteKind.Todo), "System.Collections.Generic.Dictionary>")}; - var updatedCode = @" -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Threading.Tasks; -using NS1; - -namespace NS1 -{ - class B - { - public virtual void M(Dictionary> test) { } - } -} - -namespace NS2 -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Threading.Tasks; - - class D : B - { - public override void M(Dictionary> test) { } - } -}"; + var updatedCode = """ + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; + using NS1; + + namespace NS1 + { + class B + { + public virtual void M(Dictionary> test) { } + } + } + + namespace NS2 + { + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; + + class D : B + { + public override void M(Dictionary> test) { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Cascading.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Cascading.cs index af83a90911389..f3f7e32f335a1 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Cascading.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Cascading.cs @@ -19,33 +19,35 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task AddParameter_Cascade_ToImplementedMethod() { - var markup = @" -interface I -{ - void M(int x, string y); -} - -class C : I -{ - $$public void M(int x, string y) - { } -}"; + var markup = """ + interface I + { + void M(int x, string y); + } + + class C : I + { + $$public void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -interface I -{ - void M(string y, int newIntegerParameter, int x); -} - -class C : I -{ - public void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + interface I + { + void M(string y, int newIntegerParameter, int x); + } + + class C : I + { + public void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -53,33 +55,35 @@ public void M(string y, int newIntegerParameter, int x) [Fact] public async Task AddParameter_Cascade_ToImplementedMethod_WithTuples() { - var markup = @" -interface I -{ - void M((int, int) x, (string a, string b) y); -} - -class C : I -{ - $$public void M((int, int) x, (string a, string b) y) - { } -}"; + var markup = """ + interface I + { + void M((int, int) x, (string a, string b) y); + } + + class C : I + { + $$public void M((int, int) x, (string a, string b) y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -interface I -{ - void M((string a, string b) y, int newIntegerParameter, (int, int) x); -} - -class C : I -{ - public void M((string a, string b) y, int newIntegerParameter, (int, int) x) - { } -}"; + var updatedCode = """ + interface I + { + void M((string a, string b) y, int newIntegerParameter, (int, int) x); + } + + class C : I + { + public void M((string a, string b) y, int newIntegerParameter, (int, int) x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -87,33 +91,35 @@ public void M((string a, string b) y, int newIntegerParameter, (int, int) x) [Fact] public async Task AddParameter_Cascade_ToImplementingMethod() { - var markup = @" -interface I -{ - $$void M(int x, string y); -} - -class C : I -{ - public void M(int x, string y) - { } -}"; + var markup = """ + interface I + { + $$void M(int x, string y); + } + + class C : I + { + public void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -interface I -{ - void M(string y, int newIntegerParameter, int x); -} - -class C : I -{ - public void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + interface I + { + void M(string y, int newIntegerParameter, int x); + } + + class C : I + { + public void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -121,35 +127,37 @@ public void M(string y, int newIntegerParameter, int x) [Fact] public async Task AddParameter_Cascade_ToOverriddenMethod() { - var markup = @" -class B -{ - public virtual void M(int x, string y) - { } -} - -class D : B -{ - $$public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + public virtual void M(int x, string y) + { } + } + + class D : B + { + $$public override void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int newIntegerParameter, int x) - { } -} - -class D : B -{ - public override void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int newIntegerParameter, int x) + { } + } + + class D : B + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -157,35 +165,37 @@ public override void M(string y, int newIntegerParameter, int x) [Fact] public async Task AddParameter_Cascade_ToOverridingMethod() { - var markup = @" -class B -{ - $$public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + $$public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int newIntegerParameter, int x) - { } -} - -class D : B -{ - public override void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int newIntegerParameter, int x) + { } + } + + class D : B + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -193,47 +203,49 @@ public override void M(string y, int newIntegerParameter, int x) [Fact] public async Task AddParameter_Cascade_ToOverriddenMethod_Transitive() { - var markup = @" -class B -{ - public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -} - -class D2 : D -{ - $$public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + + class D2 : D + { + $$public override void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int newIntegerParameter, int x) - { } -} - -class D : B -{ - public override void M(string y, int newIntegerParameter, int x) - { } -} - -class D2 : D -{ - public override void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int newIntegerParameter, int x) + { } + } + + class D : B + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + + class D2 : D + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -241,47 +253,49 @@ public override void M(string y, int newIntegerParameter, int x) [Fact] public async Task AddParameter_Cascade_ToOverridingMethod_Transitive() { - var markup = @" -class B -{ - $$public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -} - -class D2 : D -{ - public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + $$public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + + class D2 : D + { + public override void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int newIntegerParameter, int x) - { } -} - -class D : B -{ - public override void M(string y, int newIntegerParameter, int x) - { } -} - -class D2 : D -{ - public override void M(string y, int newIntegerParameter, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int newIntegerParameter, int x) + { } + } + + class D : B + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + + class D2 : D + { + public override void M(string y, int newIntegerParameter, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -295,30 +309,32 @@ public async Task AddParameter_Cascade_ToMethods_Complex() //// / \ \ //// $$D2 D3 C - var markup = @" -class B { public virtual void M(int x, string y) { } } -class D : B, I { public override void M(int x, string y) { } } -class D2 : D { public override void $$M(int x, string y) { } } -class D3 : D { public override void M(int x, string y) { } } -interface I { void M(int x, string y); } -interface I2 { void M(int x, string y); } -interface I3 : I, I2 { } -class C : I3 { public void M(int x, string y) { } }"; + var markup = """ + class B { public virtual void M(int x, string y) { } } + class D : B, I { public override void M(int x, string y) { } } + class D2 : D { public override void $$M(int x, string y) { } } + class D3 : D { public override void M(int x, string y) { } } + interface I { void M(int x, string y); } + interface I2 { void M(int x, string y); } + interface I3 : I, I2 { } + class C : I3 { public void M(int x, string y) { } } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class B { public virtual void M(string y, int newIntegerParameter, int x) { } } -class D : B, I { public override void M(string y, int newIntegerParameter, int x) { } } -class D2 : D { public override void M(string y, int newIntegerParameter, int x) { } } -class D3 : D { public override void M(string y, int newIntegerParameter, int x) { } } -interface I { void M(string y, int newIntegerParameter, int x); } -interface I2 { void M(string y, int newIntegerParameter, int x); } -interface I3 : I, I2 { } -class C : I3 { public void M(string y, int newIntegerParameter, int x) { } }"; + var updatedCode = """ + class B { public virtual void M(string y, int newIntegerParameter, int x) { } } + class D : B, I { public override void M(string y, int newIntegerParameter, int x) { } } + class D2 : D { public override void M(string y, int newIntegerParameter, int x) { } } + class D3 : D { public override void M(string y, int newIntegerParameter, int x) { } } + interface I { void M(string y, int newIntegerParameter, int x); } + interface I2 { void M(string y, int newIntegerParameter, int x); } + interface I3 : I, I2 { } + class C : I3 { public void M(string y, int newIntegerParameter, int x) { } } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -326,110 +342,114 @@ class C : I3 { public void M(string y, int newIntegerParameter, int x) { } }"; [Fact] public async Task AddParameter_Cascade_ToMethods_WithDifferentParameterNames() { - var markup = @" -public class B -{ - /// - /// - public virtual int M(int x, string y) - { - return 1; - } -} - -public class D : B -{ - /// - /// - public override int M(int a, string b) - { - return 1; - } -} - -public class D2 : D -{ - /// - /// - public override int $$M(int y, string x) - { - M(1, ""Two""); - ((D)this).M(1, ""Two""); - ((B)this).M(1, ""Two""); - - M(1, x: ""Two""); - ((D)this).M(1, b: ""Two""); - ((B)this).M(1, y: ""Two""); - - return 1; - } -}"; + var markup = """ + public class B + { + /// + /// + public virtual int M(int x, string y) + { + return 1; + } + } + + public class D : B + { + /// + /// + public override int M(int a, string b) + { + return 1; + } + } + + public class D2 : D + { + /// + /// + public override int $$M(int y, string x) + { + M(1, "Two"); + ((D)this).M(1, "Two"); + ((B)this).M(1, "Two"); + + M(1, x: "Two"); + ((D)this).M(1, b: "Two"); + ((B)this).M(1, y: "Two"); + + return 1; + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -public class B -{ - /// - /// - /// - public virtual int M(string y, int newIntegerParameter, int x) - { - return 1; - } -} - -public class D : B -{ - /// - /// - /// - public override int M(string b, int newIntegerParameter, int a) - { - return 1; - } -} - -public class D2 : D -{ - /// - /// - /// - public override int M(string x, int newIntegerParameter, int y) - { - M(""Two"", 12345, 1); - ((D)this).M(""Two"", 12345, 1); - ((B)this).M(""Two"", 12345, 1); - - M(x: ""Two"", newIntegerParameter: 12345, y: 1); - ((D)this).M(b: ""Two"", newIntegerParameter: 12345, a: 1); - ((B)this).M(y: ""Two"", newIntegerParameter: 12345, x: 1); - - return 1; - } -}"; + var updatedCode = """ + public class B + { + /// + /// + /// + public virtual int M(string y, int newIntegerParameter, int x) + { + return 1; + } + } + + public class D : B + { + /// + /// + /// + public override int M(string b, int newIntegerParameter, int a) + { + return 1; + } + } + + public class D2 : D + { + /// + /// + /// + public override int M(string x, int newIntegerParameter, int y) + { + M("Two", 12345, 1); + ((D)this).M("Two", 12345, 1); + ((B)this).M("Two", 12345, 1); + + M(x: "Two", newIntegerParameter: 12345, y: 1); + ((D)this).M(b: "Two", newIntegerParameter: 12345, a: 1); + ((B)this).M(y: "Two", newIntegerParameter: 12345, x: 1); + + return 1; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact(Skip = "https://github.com/dotnet/roslyn/issues/53091")] public async Task AddParameter_Cascade_Record() { - var markup = @" -record $$BaseR(int A, int B); + var markup = """ + record $$BaseR(int A, int B); -record DerivedR() : BaseR(0, 1);"; + record DerivedR() : BaseR(0, 1); + """; var permutation = new AddedParameterOrExistingIndex[] { new(1), new(new AddedParameter(null, "int", "C", CallSiteKind.Value, "3"), "int"), new(0) }; - var updatedCode = @" -record BaseR(int B, int C, int A); + var updatedCode = """ + record BaseR(int B, int C, int A); -record DerivedR() : BaseR(1, 3, 0);"; + record DerivedR() : BaseR(1, 3, 0); + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -437,20 +457,22 @@ record DerivedR() : BaseR(1, 3, 0);"; [Fact(Skip = "https://github.com/dotnet/roslyn/issues/53091")] public async Task AddParameter_Cascade_PrimaryConstructor() { - var markup = @" -class $$BaseR(int A, int B); + var markup = """ + class $$BaseR(int A, int B); -class DerivedR() : BaseR(0, 1);"; + class DerivedR() : BaseR(0, 1); + """; var permutation = new AddedParameterOrExistingIndex[] { new(1), new(new AddedParameter(null, "int", "C", CallSiteKind.Value, "3"), "int"), new(0) }; - var updatedCode = @" -class BaseR(int B, int C, int A); + var updatedCode = """ + class BaseR(int B, int C, int A); -class DerivedR() : BaseR(1, 3, 0);"; + class DerivedR() : BaseR(1, 3, 0); + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Delegates.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Delegates.cs index 47ca927fcbdaf..12f3e1a8542e9 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Delegates.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.Delegates.cs @@ -20,33 +20,35 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task AddParameter_Delegates_ImplicitInvokeCalls() { - var markup = @" -delegate void MyDelegate($$int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1(1, ""Two"", true); - } -}"; + var markup = """ + delegate void MyDelegate($$int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1(1, "Two", true); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1(true, 12345, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1(true, 12345, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 0); } @@ -54,33 +56,35 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddParameter_Delegates_ExplicitInvokeCalls() { - var markup = @" -delegate void MyDelegate(int x, string $$y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.Invoke(1, ""Two"", true); - } -}"; + var markup = """ + delegate void MyDelegate(int x, string $$y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.Invoke(1, "Two", true); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.Invoke(true, 12345, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.Invoke(true, 12345, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 1); } @@ -88,33 +92,35 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddParameter_Delegates_BeginInvokeCalls() { - var markup = @" -delegate void MyDelegate(int x, string y, bool z$$); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.BeginInvoke(1, ""Two"", true, null, null); - } -}"; + var markup = """ + delegate void MyDelegate(int x, string y, bool z$$); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.BeginInvoke(1, "Two", true, null, null); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.BeginInvoke(true, 12345, ""Two"", null, null); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.BeginInvoke(true, 12345, "Two", null, null); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 2); } @@ -122,691 +128,727 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddParameter_Delegates_AnonymousMethods() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = delegate (int e, string f, bool g) { var x = f.Length + (g ? 0 : 1); }; - d1 = delegate { }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = delegate (int e, string f, bool g) { var x = f.Length + (g ? 0 : 1); }; + d1 = delegate { }; + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = delegate (bool g, int newIntegerParameter, string f) { var x = f.Length + (g ? 0 : 1); }; - d1 = delegate { }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = delegate (bool g, int newIntegerParameter, string f) { var x = f.Length + (g ? 0 : 1); }; + d1 = delegate { }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Lambdas() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (r, s, t) => { var x = s.Length + (t ? 0 : 1); }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (r, s, t) => { var x = s.Length + (t ? 0 : 1); }; + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (t, newIntegerParameter, s) => { var x = s.Length + (t ? 0 : 1); }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (t, newIntegerParameter, s) => { var x = s.Length + (t ? 0 : 1); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Lambdas_RemovingOnlyParameterIntroducesParentheses() { - var markup = @" -delegate void $$MyDelegate(int x); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (r) => { System.Console.WriteLine(""Test""); }; - d1 = r => { System.Console.WriteLine(""Test""); }; - d1 = r => { System.Console.WriteLine(""Test""); }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (r) => { System.Console.WriteLine("Test"); }; + d1 = r => { System.Console.WriteLine("Test"); }; + d1 = r => { System.Console.WriteLine("Test"); }; + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), }; - var expectedUpdatedCode = @" -delegate void MyDelegate(int newIntegerParameter); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (newIntegerParameter) => { System.Console.WriteLine(""Test""); }; - d1 = (int newIntegerParameter) => { System.Console.WriteLine(""Test""); }; - d1 = (int newIntegerParameter) => { System.Console.WriteLine(""Test""); }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(int newIntegerParameter); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (newIntegerParameter) => { System.Console.WriteLine("Test"); }; + d1 = (int newIntegerParameter) => { System.Console.WriteLine("Test"); }; + d1 = (int newIntegerParameter) => { System.Console.WriteLine("Test"); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughMethodGroups_AssignedToVariable() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = Goo; - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = Goo; + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = Goo; - Goo(true, 12345, ""Two""); - Goo(1, false, false); - } - - void Goo(bool c, int newIntegerParameter, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = Goo; + Goo(true, 12345, "Two"); + Goo(1, false, false); + } + + void Goo(bool c, int newIntegerParameter, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughMethodGroups_DelegateConstructor() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = new MyDelegate(Goo); - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = new MyDelegate(Goo); + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = new MyDelegate(Goo); - Goo(true, 12345, ""Two""); - Goo(1, false, false); - } - - void Goo(bool c, int newIntegerParameter, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = new MyDelegate(Goo); + Goo(true, 12345, "Two"); + Goo(1, false, false); + } + + void Goo(bool c, int newIntegerParameter, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughMethodGroups_PassedAsArgument() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - Target(Goo); - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Target(MyDelegate d) { } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + Target(Goo); + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Target(MyDelegate d) { } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - Target(Goo); - Goo(true, 12345, ""Two""); - Goo(1, false, false); - } - - void Target(MyDelegate d) { } - - void Goo(bool c, int newIntegerParameter, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + Target(Goo); + Goo(true, 12345, "Two"); + Goo(1, false, false); + } + + void Target(MyDelegate d) { } + + void Goo(bool c, int newIntegerParameter, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughMethodGroups_ReturnValue() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = Result(); - Goo(1, ""Two"", true); - } - - private MyDelegate Result() - { - return Goo; - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = Result(); + Goo(1, "Two", true); + } + + private MyDelegate Result() + { + return Goo; + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = Result(); - Goo(true, 12345, ""Two""); - } - - private MyDelegate Result() - { - return Goo; - } - - void Goo(bool c, int newIntegerParameter, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = Result(); + Goo(true, 12345, "Two"); + } + + private MyDelegate Result() + { + return Goo; + } + + void Goo(bool c, int newIntegerParameter, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughMethodGroups_YieldReturnValue() { - var markup = @" -using System.Collections.Generic; - -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - Goo(1, ""Two"", true); - } - - private IEnumerable Result() - { - yield return Goo; - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + using System.Collections.Generic; + + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + Goo(1, "Two", true); + } + + private IEnumerable Result() + { + yield return Goo; + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -using System.Collections.Generic; - -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - Goo(true, 12345, ""Two""); - } - - private IEnumerable Result() - { - yield return Goo; - } - - void Goo(bool c, int newIntegerParameter, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + using System.Collections.Generic; + + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + Goo(true, 12345, "Two"); + } + + private IEnumerable Result() + { + yield return Goo; + } + + void Goo(bool c, int newIntegerParameter, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_ReferencingLambdas_MethodArgument() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M6() - { - Target((m, n, o) => { var x = n.Length + (o ? 0 : 1); }); - } - - void Target(MyDelegate d) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M6() + { + Target((m, n, o) => { var x = n.Length + (o ? 0 : 1); }); + } + + void Target(MyDelegate d) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M6() - { - Target((o, newIntegerParameter, n) => { var x = n.Length + (o ? 0 : 1); }); - } - - void Target(MyDelegate d) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M6() + { + Target((o, newIntegerParameter, n) => { var x = n.Length + (o ? 0 : 1); }); + } + + void Target(MyDelegate d) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_ReferencingLambdas_YieldReturn() { - var markup = @" -using System.Collections.Generic; - -delegate void $$MyDelegate(int x, string y, bool z); -class C -{ - private IEnumerable Result3() - { - yield return (g, h, i) => { var x = h.Length + (i ? 0 : 1); }; - } -}"; + var markup = """ + using System.Collections.Generic; + + delegate void $$MyDelegate(int x, string y, bool z); + class C + { + private IEnumerable Result3() + { + yield return (g, h, i) => { var x = h.Length + (i ? 0 : 1); }; + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -using System.Collections.Generic; - -delegate void MyDelegate(bool z, int newIntegerParameter, string y); -class C -{ - private IEnumerable Result3() - { - yield return (i, newIntegerParameter, h) => { var x = h.Length + (i ? 0 : 1); }; - } -}"; + var expectedUpdatedCode = """ + using System.Collections.Generic; + + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + class C + { + private IEnumerable Result3() + { + yield return (i, newIntegerParameter, h) => { var x = h.Length + (i ? 0 : 1); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Recursive() { - var markup = @" -delegate RecursiveDelegate $$RecursiveDelegate(int x, string y, bool z); - -class C -{ - void M() - { - RecursiveDelegate rd = null; - rd(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true); - } -}"; + var markup = """ + delegate RecursiveDelegate $$RecursiveDelegate(int x, string y, bool z); + + class C + { + void M() + { + RecursiveDelegate rd = null; + rd(1, "Two", true)(1, "Two", true)(1, "Two", true)(1, "Two", true)(1, "Two", true); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate RecursiveDelegate RecursiveDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - RecursiveDelegate rd = null; - rd(true, 12345, ""Two"")(true, 12345, ""Two"")(true, 12345, ""Two"")(true, 12345, ""Two"")(true, 12345, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate RecursiveDelegate RecursiveDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + RecursiveDelegate rd = null; + rd(true, 12345, "Two")(true, 12345, "Two")(true, 12345, "Two")(true, 12345, "Two")(true, 12345, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_DocComments() { - var markup = @" -/// -/// This is , which has these methods: -/// -/// -/// -/// -/// -/// x! -/// y! -/// z! -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = Goo; - Goo(1, ""Two"", true); - } - - /// - /// - /// - void Goo(int a, string b, bool c) { } -}"; + var markup = """ + /// + /// This is , which has these methods: + /// + /// + /// + /// + /// + /// x! + /// y! + /// z! + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = Goo; + Goo(1, "Two", true); + } + + /// + /// + /// + void Goo(int a, string b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -/// -/// This is , which has these methods: -/// -/// -/// -/// -/// -/// z! -/// -/// y! -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class C -{ - void M() - { - MyDelegate d1 = Goo; - Goo(true, 12345, ""Two""); - } - - /// - /// - /// - void Goo(bool c, int newIntegerParameter, string b) { } -}"; + var expectedUpdatedCode = """ + /// + /// This is , which has these methods: + /// + /// + /// + /// + /// + /// z! + /// + /// y! + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class C + { + void M() + { + MyDelegate d1 = Goo; + Goo(true, 12345, "Two"); + } + + /// + /// + /// + void Goo(bool c, int newIntegerParameter, string b) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_CascadeThroughEventAdd() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class Program -{ - void M() - { - MyEvent += Program_MyEvent; - } - - event MyDelegate MyEvent; - void Program_MyEvent(int a, string b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class Program + { + void M() + { + MyEvent += Program_MyEvent; + } + + event MyDelegate MyEvent; + void Program_MyEvent(int a, string b, bool c) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, int newIntegerParameter, string y); - -class Program -{ - void M() - { - MyEvent += Program_MyEvent; - } - - event MyDelegate MyEvent; - void Program_MyEvent(bool c, int newIntegerParameter, string b) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, int newIntegerParameter, string y); + + class Program + { + void M() + { + MyEvent += Program_MyEvent; + } + + event MyDelegate MyEvent; + void Program_MyEvent(bool c, int newIntegerParameter, string b) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Generics1() { - var markup = @" -public class DP16a -{ - public delegate void D($$T t); - public event D E1; - public event D E2; - - public void M1(int i) { } - public void M2(int i) { } - public void M3(int i) { } - - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + var markup = """ + public class DP16a + { + public delegate void D($$T t); + public event D E1; + public event D E2; + + public void M1(int i) { } + public void M2(int i) { } + public void M3(int i) { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), }; - var expectedUpdatedCode = @" -public class DP16a -{ - public delegate void D(int newIntegerParameter); - public event D E1; - public event D E2; - - public void M1(int newIntegerParameter) { } - public void M2(int newIntegerParameter) { } - public void M3(int newIntegerParameter) { } - - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + var expectedUpdatedCode = """ + public class DP16a + { + public delegate void D(int newIntegerParameter); + public event D E1; + public event D E2; + + public void M1(int newIntegerParameter) { } + public void M2(int newIntegerParameter) { } + public void M3(int newIntegerParameter) { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Generics2() { - var markup = @" -public class D17 -{ - public delegate void $$D(T t); -} -public class D17Test -{ - void Test() { var x = new D17.D(M17); } - internal void M17(string s) { } -}"; + var markup = """ + public class D17 + { + public delegate void $$D(T t); + } + public class D17Test + { + void Test() { var x = new D17.D(M17); } + internal void M17(string s) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), }; - var expectedUpdatedCode = @" -public class D17 -{ - public delegate void D(int newIntegerParameter); -} -public class D17Test -{ - void Test() { var x = new D17.D(M17); } - internal void M17(int newIntegerParameter) { } -}"; + var expectedUpdatedCode = """ + public class D17 + { + public delegate void D(int newIntegerParameter); + } + public class D17Test + { + void Test() { var x = new D17.D(M17); } + internal void M17(int newIntegerParameter) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_GenericParams() { - var markup = @" -class DA -{ - void M(params int[] i) { } - void B() - { - DP20.D d = new DP20.D(M); - d(); - d(0); - d(0, 1); - } -} -public class DP20 -{ - public delegate void $$D(params T[] t); - public void M1(params T[] t) { } - - void B() - { - D d = new D(M1); - } -}"; + var markup = """ + class DA + { + void M(params int[] i) { } + void B() + { + DP20.D d = new DP20.D(M); + d(); + d(0); + d(0, 1); + } + } + public class DP20 + { + public delegate void $$D(params T[] t); + public void M1(params T[] t) { } + + void B() + { + D d = new D(M1); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), }; - var expectedUpdatedCode = @" -class DA -{ - void M(int newIntegerParameter) { } - void B() - { - DP20.D d = new DP20.D(M); - d(12345); - d(12345); - d(12345); - } -} -public class DP20 -{ - public delegate void D(int newIntegerParameter); - public void M1(int newIntegerParameter) { } - - void B() - { - D d = new D(M1); - } -}"; + var expectedUpdatedCode = """ + class DA + { + void M(int newIntegerParameter) { } + void B() + { + DP20.D d = new DP20.D(M); + d(12345); + d(12345); + d(12345); + } + } + public class DP20 + { + public delegate void D(int newIntegerParameter); + public void M1(int newIntegerParameter) { } + + void B() + { + D d = new D(M1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task AddParameter_Delegates_Generic_RemoveArgumentAtReference() { - var markup = @"public class CD -{ - public delegate void D(T t); -} -class Test -{ - public void M() - { - var dele = new CD.$$D((int x) => { }); - } -}"; + var markup = """ + public class CD + { + public delegate void D(T t); + } + class Test + { + public void M() + { + var dele = new CD.$$D((int x) => { }); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int") }; - var expectedUpdatedCode = @"public class CD -{ - public delegate void D(int newIntegerParameter); -} -class Test -{ - public void M() - { - var dele = new CD.D((int newIntegerParameter) => { }); - } -}"; + var expectedUpdatedCode = """ + public class CD + { + public delegate void D(int newIntegerParameter); + } + class Test + { + public void M() + { + var dele = new CD.D((int newIntegerParameter) => { }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 0); } @@ -814,90 +856,94 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddParameter_Delegate_Generics_RemoveStaticArgument() { - var markup = @" -public class C2 -{ - public delegate void D(T t); -} - -public class D2 -{ - public static D2 Instance = null; - void M(D2 m) { } - - void B() - { - C2.D d = new C2.D(M); - $$d(D2.Instance); - } -}"; + var markup = """ + public class C2 + { + public delegate void D(T t); + } + + public class D2 + { + public static D2 Instance = null; + void M(D2 m) { } + + void B() + { + C2.D d = new C2.D(M); + $$d(D2.Instance); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int") }; - var expectedUpdatedCode = @" -public class C2 -{ - public delegate void D(int newIntegerParameter); -} - -public class D2 -{ - public static D2 Instance = null; - void M(int newIntegerParameter) { } - - void B() - { - C2.D d = new C2.D(M); - d(12345); - } -}"; + var expectedUpdatedCode = """ + public class C2 + { + public delegate void D(int newIntegerParameter); + } + + public class D2 + { + public static D2 Instance = null; + void M(int newIntegerParameter) { } + + void B() + { + C2.D d = new C2.D(M); + d(12345); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task TestAddParameter_Delegates_Relaxation_ParameterlessFunctionToFunction() { - var markup = @" -class C0 -{ - delegate int $$MyFunc(int x, string y, bool z); - - class C - { - public void M() - { - MyFunc f = Test(); - } - - private MyFunc Test() - { - return null; - } - } -}"; + var markup = """ + class C0 + { + delegate int $$MyFunc(int x, string y, bool z); + + class C + { + public void M() + { + MyFunc f = Test(); + } + + private MyFunc Test() + { + return null; + } + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "int"), new AddedParameterOrExistingIndex(1) }; - var expectedUpdatedCode = @" -class C0 -{ - delegate int MyFunc(bool z, int newIntegerParameter, string y); - - class C - { - public void M() - { - MyFunc f = Test(); - } - - private MyFunc Test() - { - return null; - } - } -}"; + var expectedUpdatedCode = """ + class C0 + { + delegate int MyFunc(bool z, int newIntegerParameter, string y); + + class C + { + public void M() + { + MyFunc f = Test(); + } + + private MyFunc Test() + { + return null; + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Infer.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Infer.cs index 02f718bb10cd9..e99d7548855bf 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Infer.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Infer.cs @@ -20,24 +20,26 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task AddOptionalParameter_CallsiteInferred_NoOptions() { - var markup = @" -class C -{ - void M$$() - { - M(); - } -}"; + var markup = """ + class C + { + void M$$() + { + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - void M(int a) - { - M(TODO); - } -}"; + var updatedCode = """ + class C + { + void M(int a) + { + M(TODO); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -45,26 +47,28 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_SingleLocal() { - var markup = @" -class C -{ - void M$$() - { - int x = 7; - M(); - } -}"; + var markup = """ + class C + { + void M$$() + { + int x = 7; + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - void M(int a) - { - int x = 7; - M(x); - } -}"; + var updatedCode = """ + class C + { + void M(int a) + { + int x = 7; + M(x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -72,26 +76,28 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_NotOnInaccessibleLocal() { - var markup = @" -class C -{ - void M$$() - { - M(); - int x = 7; - } -}"; + var markup = """ + class C + { + void M$$() + { + M(); + int x = 7; + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - void M(int a) - { - M(TODO); - int x = 7; - } -}"; + var updatedCode = """ + class C + { + void M(int a) + { + M(TODO); + int x = 7; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -99,28 +105,30 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_MultipleLocals() { - var markup = @" -class C -{ - void M$$() - { - int x = 7; - int y = 8; - M(); - } -}"; + var markup = """ + class C + { + void M$$() + { + int x = 7; + int y = 8; + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - void M(int a) - { - int x = 7; - int y = 8; - M(y); - } -}"; + var updatedCode = """ + class C + { + void M(int a) + { + int x = 7; + int y = 8; + M(y); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -128,25 +136,27 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_SingleParameter() { - var markup = @" -class C -{ - void M$$(int x) - { - M(1); - } -}"; + var markup = """ + class C + { + void M$$(int x) + { + M(1); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - void M(int x, int a) - { - M(1, x); - } -}"; + var updatedCode = """ + class C + { + void M(int x, int a) + { + M(1, x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -154,28 +164,30 @@ void M(int x, int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_SingleField() { - var markup = @" -class C -{ - int x = 8; + var markup = """ + class C + { + int x = 8; - void M$$() - { - M(); - } -}"; + void M$$() + { + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - int x = 8; + var updatedCode = """ + class C + { + int x = 8; - void M(int a) - { - M(x); - } -}"; + void M(int a) + { + M(x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -183,28 +195,30 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_SingleProperty() { - var markup = @" -class C -{ - int X { get; set; } + var markup = """ + class C + { + int X { get; set; } - void M$$() - { - M(); - } -}"; + void M$$() + { + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Inferred) }; - var updatedCode = @" -class C -{ - int X { get; set; } + var updatedCode = """ + class C + { + int X { get; set; } - void M(int a) - { - M(X); - } -}"; + void M(int a) + { + M(X); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -212,32 +226,34 @@ void M(int a) [Fact] public async Task AddOptionalParameter_CallsiteInferred_ImplicitlyConvertable() { - var markup = @" -class B { } -class D : B { } + var markup = """ + class B { } + class D : B { } -class C -{ - void M$$() - { - D d = null; - M(); - } -}"; + class C + { + void M$$() + { + D d = null; + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("B", "b", CallSiteKind.Inferred) }; - var updatedCode = @" -class B { } -class D : B { } + var updatedCode = """ + class B { } + class D : B { } -class C -{ - void M(B b) - { - D d = null; - M(d); - } -}"; + class C + { + void M(B b) + { + D d = null; + M(d); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Omit.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Omit.cs index 25c59ec92cfed..3b4207da9baea 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Omit.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.Omit.cs @@ -20,24 +20,26 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [WpfFact] public async Task AddOptionalParameter_ToEmptySignature_CallsiteOmitted() { - var markup = @" -class C -{ - void M$$() - { - M(); - } -}"; + var markup = """ + class C + { + void M$$() + { + M(); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Omitted, isRequired: false, defaultValue: "1") }; - var updatedCode = @" -class C -{ - void M(int a = 1) - { - M(); - } -}"; + var updatedCode = """ + class C + { + void M(int a = 1) + { + M(); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -45,25 +47,27 @@ void M(int a = 1) [WpfFact] public async Task AddOptionalParameter_AfterRequiredParameter_CallsiteOmitted() { - var markup = @" -class C -{ - void M$$(int x) - { - M(1); - } -}"; + var markup = """ + class C + { + void M$$(int x) + { + M(1); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Omitted, isRequired: false, defaultValue: "1") }; - var updatedCode = @" -class C -{ - void M(int x, int a = 1) - { - M(1); - } -}"; + var updatedCode = """ + class C + { + void M(int x, int a = 1) + { + M(1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -71,29 +75,31 @@ void M(int x, int a = 1) [WpfFact] public async Task AddOptionalParameter_BeforeOptionalParameter_CallsiteOmitted() { - var markup = @" -class C -{ - void M$$(int x = 2) - { - M() - M(2); - M(x: 2); - } -}"; + var markup = """ + class C + { + void M$$(int x = 2) + { + M() + M(2); + M(x: 2); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Omitted, isRequired: false, defaultValue: "1"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class C -{ - void M(int a = 1, int x = 2) - { - M() - M(x: 2); - M(x: 2); - } -}"; + var updatedCode = """ + class C + { + void M(int a = 1, int x = 2) + { + M() + M(x: 2); + M(x: 2); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -101,31 +107,33 @@ void M(int a = 1, int x = 2) [WpfFact] public async Task AddOptionalParameter_BeforeExpandedParamsArray_CallsiteOmitted() { - var markup = @" -class C -{ - void M$$(params int[] p) - { - M(); - M(1); - M(1, 2); - M(1, 2, 3); - } -}"; + var markup = """ + class C + { + void M$$(params int[] p) + { + M(); + M(1); + M(1, 2); + M(1, 2, 3); + } + } + """; var updatedSignature = new[] { AddedParameterOrExistingIndex.CreateAdded("System.Int32", "a", CallSiteKind.Omitted, isRequired: false, defaultValue: "1"), new AddedParameterOrExistingIndex(0) }; - var updatedCode = @" -class C -{ - void M(int a = 1, params int[] p) - { - M(); - M(p: new int[] { 1 }); - M(p: new int[] { 1, 2 }); - M(p: new int[] { 1, 2, 3 }); - } -}"; + var updatedCode = """ + class C + { + void M(int a = 1, params int[] p) + { + M(); + M(p: new int[] { 1 }); + M(p: new int[] { 1, 2 }); + M(p: new int[] { 1, 2, 3 }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -133,27 +141,29 @@ void M(int a = 1, params int[] p) [WpfFact] public async Task AddOptionalParameterWithOmittedCallsiteToAttributeConstructor() { - var markup = @" -[Some(1, 2, 4)] -class SomeAttribute : System.Attribute -{ - public SomeAttribute$$(int a, int b, int y = 4) - { - } -}"; + var markup = """ + [Some(1, 2, 4)] + class SomeAttribute : System.Attribute + { + public SomeAttribute$$(int a, int b, int y = 4) + { + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(1), AddedParameterOrExistingIndex.CreateAdded("int", "x", CallSiteKind.Omitted, isRequired: false, defaultValue: "3"), new AddedParameterOrExistingIndex(2)}; - var updatedCode = @" -[Some(1, 2, y: 4)] -class SomeAttribute : System.Attribute -{ - public SomeAttribute(int a, int b, int x = 3, int y = 4) - { - } -}"; + var updatedCode = """ + [Some(1, 2, y: 4)] + class SomeAttribute : System.Attribute + { + public SomeAttribute(int a, int b, int x = 3, int y = 4) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.SymbolKinds.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.SymbolKinds.cs index 464f8669e4ced..f431ba64cd03e 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.SymbolKinds.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.OptionalParameter.SymbolKinds.cs @@ -20,39 +20,41 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [WpfFact] public async Task AddOptionalParameter_ToConstructor() { - var markup = @" -class B -{ - public B() : this(1) { } - public B$$(int a) - { - var q = new B(1); - } -} - -class D : B -{ - public D() : base(1) { } -}"; + var markup = """ + class B + { + public B() : this(1) { } + public B$$(int a) + { + var q = new B(1); + } + } + + class D : B + { + public D() : base(1) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "x", CallSiteKind.Value, callSiteValue: "100", isRequired: false, defaultValue: "10"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "y", CallSiteKind.Omitted, isRequired: false, defaultValue: "11"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "z", CallSiteKind.Value, callSiteValue: "102", isRequired: false, defaultValue: "12")}; - var updatedCode = @" -class B -{ - public B() : this(1, 100, z: 102) { } - public B(int a, int x = 10, int y = 11, int z = 12) - { - var q = new B(1, 100, z: 102); - } -} - -class D : B -{ - public D() : base(1, 100, z: 102) { } -}"; + var updatedCode = """ + class B + { + public B() : this(1, 100, z: 102) { } + public B(int a, int x = 10, int y = 11, int z = 12) + { + var q = new B(1, 100, z: 102); + } + } + + class D : B + { + public D() : base(1, 100, z: 102) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -61,39 +63,41 @@ public D() : base(1, 100, z: 102) { } [WpfFact] public async Task AddOptionalParameter_ToConstructor_ImplicitObjectCreation() { - var markup = @" -class B -{ - public B() : this(1) { } - public B$$(int a) - { - B q = new(1); - } -} - -class D : B -{ - public D() : base(1) { } -}"; + var markup = """ + class B + { + public B() : this(1) { } + public B$$(int a) + { + B q = new(1); + } + } + + class D : B + { + public D() : base(1) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "x", CallSiteKind.Value, callSiteValue: "100", isRequired: false, defaultValue: "10"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "y", CallSiteKind.Omitted, isRequired: false, defaultValue: "11"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "z", CallSiteKind.Value, callSiteValue: "102", isRequired: false, defaultValue: "12")}; - var updatedCode = @" -class B -{ - public B() : this(1, 100, z: 102) { } - public B(int a, int x = 10, int y = 11, int z = 12) - { - B q = new(1, 100, z: 102); - } -} - -class D : B -{ - public D() : base(1, 100, z: 102) { } -}"; + var updatedCode = """ + class B + { + public B() : this(1, 100, z: 102) { } + public B(int a, int x = 10, int y = 11, int z = 12) + { + B q = new(1, 100, z: 102); + } + } + + class D : B + { + public D() : base(1, 100, z: 102) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -101,31 +105,33 @@ public D() : base(1, 100, z: 102) { } [WpfFact] public async Task AddOptionalParameter_ToIndexer() { - var markup = @" -class B -{ - public int this$$[int a] { get { return 5; } } - - public void M() - { - var d = this[1]; - } -}"; + var markup = """ + class B + { + public int this$$[int a] { get { return 5; } } + + public void M() + { + var d = this[1]; + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "x", CallSiteKind.Value, callSiteValue: "100", isRequired: false, defaultValue: "10"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "y", CallSiteKind.Omitted, isRequired: false, defaultValue: "11"), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "z", CallSiteKind.Value, callSiteValue: "102", isRequired: false, defaultValue: "12")}; - var updatedCode = @" -class B -{ - public int this[int a, int x = 10, int y = 11, int z = 12] { get { return 5; } } - - public void M() - { - var d = this[1, 100, z: 102]; - } -}"; + var updatedCode = """ + class B + { + public int this[int a, int x = 10, int y = 11, int z = 12] { get { return 5; } } + + public void M() + { + var d = this[1, 100, z: 102]; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -133,12 +139,13 @@ public void M() [WpfFact] public async Task AddOptionalParameter_ToAttribute() { - var markup = @" -[My(1)] -class MyAttribute : System.Attribute -{ - public MyAttribute($$int a) { } -}"; + var markup = """ + [My(1)] + class MyAttribute : System.Attribute + { + public MyAttribute($$int a) { } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("System.Int32", "x", CallSiteKind.Value, callSiteValue: "100", isRequired: false, defaultValue: "10"), @@ -147,12 +154,13 @@ public MyAttribute($$int a) { } // TODO: The = in the attribute is a bug. You cannot specify that the attribute should use : instead in the SyntaxGenerator // https://github.com/dotnet/roslyn/issues/43354 - var updatedCode = @" -[My(1, 100, z = 102)] -class MyAttribute : System.Attribute -{ - public MyAttribute(int a, int x = 10, int y = 11, int z = 12) { } -}"; + var updatedCode = """ + [My(1, 100, z = 102)] + class MyAttribute : System.Attribute + { + public MyAttribute(int a, int x = 10, int y = 11, int z = 12) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.cs index acdaf1dc2ad42..26cacb7863980 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.cs @@ -20,94 +20,96 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task AddParameters() { - var markup = @" -static class Ext -{ - /// - /// This is a summary of - /// - /// - /// - /// - /// - /// - /// - /// - static void $$M(this object o, int a, string b, bool c, int x = 0, string y = ""Zero"", params int[] p) - { - object t = new object(); - - M(t, 1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - M(t, 1, ""two"", true, 3, ""four"", 5, 6); - t.M(1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - t.M(1, ""two"", true, 3, ""four"", 5, 6); - - M(t, 1, ""two"", true, 3, ""four""); - M(t, 1, ""two"", true, 3); - M(t, 1, ""two"", true); - - M(t, 1, ""two"", c: true); - M(t, 1, ""two"", true, 3, y: ""four""); - - M(t, 1, ""two"", true, 3, p: new[] { 5 }); - M(t, 1, ""two"", true, p: new[] { 5 }); - M(t, 1, ""two"", true, y: ""four""); - M(t, 1, ""two"", true, x: 3); - - M(t, 1, ""two"", true, y: ""four"", x: 3); - M(t, 1, y: ""four"", x: 3, b: ""two"", c: true); - M(t, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(t, p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1, o: t); - } -}"; + var markup = """ + static class Ext + { + /// + /// This is a summary of + /// + /// + /// + /// + /// + /// + /// + /// + static void $$M(this object o, int a, string b, bool c, int x = 0, string y = "Zero", params int[] p) + { + object t = new object(); + + M(t, 1, "two", true, 3, "four", new[] { 5, 6 }); + M(t, 1, "two", true, 3, "four", 5, 6); + t.M(1, "two", true, 3, "four", new[] { 5, 6 }); + t.M(1, "two", true, 3, "four", 5, 6); + + M(t, 1, "two", true, 3, "four"); + M(t, 1, "two", true, 3); + M(t, 1, "two", true); + + M(t, 1, "two", c: true); + M(t, 1, "two", true, 3, y: "four"); + + M(t, 1, "two", true, 3, p: new[] { 5 }); + M(t, 1, "two", true, p: new[] { 5 }); + M(t, 1, "two", true, y: "four"); + M(t, 1, "two", true, x: 3); + + M(t, 1, "two", true, y: "four", x: 3); + M(t, 1, y: "four", x: 3, b: "two", c: true); + M(t, y: "four", x: 3, c: true, b: "two", a: 1); + M(t, p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1); + M(p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1, o: t); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "System.Int32"), new AddedParameterOrExistingIndex(new AddedParameter(null, "string", "newString", CallSiteKind.Value, ""), "System.String"), new AddedParameterOrExistingIndex(5)}; - var updatedCode = @" -static class Ext -{ - /// - /// This is a summary of - /// - /// - /// - /// - /// - /// - /// - /// - static void M(this object o, string b, int newIntegerParameter, string newString, string y = ""Zero"") - { - object t = new object(); - - M(t, ""two"", 12345, , ""four""); - M(t, ""two"", 12345, , ""four""); - t.M(""two"", 12345, , ""four""); - t.M(""two"", 12345, , ""four""); - - M(t, ""two"", 12345, , ""four""); - M(t, ""two"", 12345, ); - M(t, ""two"", 12345, ); - - M(t, ""two"", 12345, ); - M(t, ""two"", 12345, , y: ""four""); - - M(t, ""two"", 12345, ); - M(t, ""two"", 12345, ); - M(t, ""two"", 12345, , y: ""four""); - M(t, ""two"", 12345, ); - - M(t, ""two"", 12345, , y: ""four""); - M(t, y: ""four"", newIntegerParameter: 12345, newString:, b: ""two""); - M(t, y: ""four"", newIntegerParameter: 12345, newString:, b: ""two""); - M(t, y: ""four"", newIntegerParameter: 12345, newString:, b: ""two""); - M(y: ""four"", b: ""two"", newIntegerParameter: 12345, newString:, o: t); - } -}"; + var updatedCode = """ + static class Ext + { + /// + /// This is a summary of + /// + /// + /// + /// + /// + /// + /// + /// + static void M(this object o, string b, int newIntegerParameter, string newString, string y = "Zero") + { + object t = new object(); + + M(t, "two", 12345, , "four"); + M(t, "two", 12345, , "four"); + t.M("two", 12345, , "four"); + t.M("two", 12345, , "four"); + + M(t, "two", 12345, , "four"); + M(t, "two", 12345, ); + M(t, "two", 12345, ); + + M(t, "two", 12345, ); + M(t, "two", 12345, , y: "four"); + + M(t, "two", 12345, ); + M(t, "two", 12345, ); + M(t, "two", 12345, , y: "four"); + M(t, "two", 12345, ); + + M(t, "two", 12345, , y: "four"); + M(t, y: "four", newIntegerParameter: 12345, newString:, b: "two"); + M(t, y: "four", newIntegerParameter: 12345, newString:, b: "two"); + M(t, y: "four", newIntegerParameter: 12345, newString:, b: "two"); + M(y: "four", b: "two", newIntegerParameter: 12345, newString:, o: t); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -115,24 +117,26 @@ static void M(this object o, string b, int newIntegerParameter, string newString [Fact] public async Task AddParameterToParameterlessMethod() { - var markup = @" -static class Ext -{ - static void $$M() - { - M(); - } -}"; + var markup = """ + static class Ext + { + static void $$M() + { + M(); + } + } + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(new AddedParameter(null, "int", "newIntegerParameter", CallSiteKind.Value, "12345"), "System.Int32")}; - var updatedCode = @" -static class Ext -{ - static void M(int newIntegerParameter) - { - M(12345); - } -}"; + var updatedCode = """ + static class Ext + { + static void M(int newIntegerParameter) + { + M(12345); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -140,34 +144,36 @@ static void M(int newIntegerParameter) [Fact] public async Task AddAndReorderLocalFunctionParametersAndArguments_OnDeclaration() { - var markup = @" -using System; -class MyClass -{ - public void M() - { - Goo(1, 2); - void $$Goo(int x, string y) - { - } - } -}"; + var markup = """ + using System; + class MyClass + { + public void M() + { + Goo(1, 2); + void $$Goo(int x, string y) + { + } + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class MyClass -{ - public void M() - { - Goo(2, 34, 1); - void Goo(string y, byte b, int x) - { - } - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void M() + { + Goo(2, 34, 1); + void Goo(string y, byte b, int x) + { + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -175,34 +181,36 @@ void Goo(string y, byte b, int x) [Fact] public async Task AddAndReorderLocalFunctionParametersAndArguments_OnInvocation() { - var markup = @" -using System; -class MyClass -{ - public void M() - { - $$Goo(1, null); - void Goo(int x, string y) - { - } - } -}"; + var markup = """ + using System; + class MyClass + { + public void M() + { + $$Goo(1, null); + void Goo(int x, string y) + { + } + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class MyClass -{ - public void M() - { - Goo(null, 34, 1); - void Goo(string y, byte b, int x) - { - } - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void M() + { + Goo(null, 34, 1); + void Goo(string y, byte b, int x) + { + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -210,26 +218,28 @@ void Goo(string y, byte b, int x) [Fact] public async Task AddAndReorderMethodParameters() { - var markup = @" -using System; -class MyClass -{ - public void $$Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void $$Goo(int x, string y) + { + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, byte b, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, byte b, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -237,28 +247,30 @@ public void Goo(string y, byte b, int x) [Fact] public async Task AddAndReorderMethodParametersAndArguments() { - var markup = @" -using System; -class MyClass -{ - public void $$Goo(int x, string y) - { - Goo(3, ""hello""); - } -}"; + var markup = """ + using System; + class MyClass + { + public void $$Goo(int x, string y) + { + Goo(3, "hello"); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, byte b, int x) - { - Goo(""hello"", 34, 3); - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, byte b, int x) + { + Goo("hello", 34, 3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -266,28 +278,30 @@ public void Goo(string y, byte b, int x) [Fact] public async Task AddAndReorderMethodParametersAndArgumentsOfNestedCalls() { - var markup = @" -using System; -class MyClass -{ - public int $$Goo(int x, string y) - { - return Goo(Goo(4, ""inner""), ""outer""); - } -}"; + var markup = """ + using System; + class MyClass + { + public int $$Goo(int x, string y) + { + return Goo(Goo(4, "inner"), "outer"); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class MyClass -{ - public int Goo(string y, byte b, int x) - { - return Goo(""outer"", 34, Goo(""inner"", 34, 4)); - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public int Goo(string y, byte b, int x) + { + return Goo("outer", 34, Goo("inner", 34, 4)); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -295,52 +309,54 @@ public int Goo(string y, byte b, int x) [Fact] public async Task AddAndReorderConstructorParametersAndArguments() { - var markup = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(5, ""test2"") - { - } -} - -class MyClass -{ - public MyClass() : this(2, ""test"") - { - } - - public $$MyClass(int x, string y) - { - var t = new MyClass(x, y); - } -}"; + var markup = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base(5, "test2") + { + } + } + + class MyClass + { + public MyClass() : this(2, "test") + { + } + + public $$MyClass(int x, string y) + { + var t = new MyClass(x, y); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), AddedParameterOrExistingIndex.CreateAdded("byte", "b", CallSiteKind.Value, "34"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(""test2"", 34, 5) - { - } -} - -class MyClass -{ - public MyClass() : this(""test"", 34, 2) - { - } - - public MyClass(string y, byte b, int x) - { - var t = new MyClass(y, 34, x); - } -}"; + var updatedCode = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base("test2", 34, 5) + { + } + } + + class MyClass + { + public MyClass() : this("test", 34, 2) + { + } + + public MyClass(string y, byte b, int x) + { + var t = new MyClass(y, 34, x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -348,34 +364,36 @@ public MyClass(string y, byte b, int x) [Fact] public async Task AddAndReorderAttributeConstructorParametersAndArguments() { - var markup = @" -[My(""test"", 8)] -class MyClass -{ -} - -class MyAttribute : System.Attribute -{ - public MyAttribute(string x, int y)$$ - { - } -}"; + var markup = """ + [My("test", 8)] + class MyClass + { + } + + class MyAttribute : System.Attribute + { + public MyAttribute(string x, int y)$$ + { + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -[My(8, 34, ""test"")] -class MyClass -{ -} - -class MyAttribute : System.Attribute -{ - public MyAttribute(int y, byte b, string x) - { - } -}"; + var updatedCode = """ + [My(8, 34, "test")] + class MyClass + { + } + + class MyAttribute : System.Attribute + { + public MyAttribute(int y, byte b, string x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -383,20 +401,21 @@ public MyAttribute(int y, byte b, string x) [Fact] public async Task AddAndReorderExtensionMethodParametersAndArguments_StaticCall() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five""); - } -} - -public static class CExt -{ - public static void M(this $$C goo, int x, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"") - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 1, 2, "three", "four", "five"); + } + } + + public static class CExt + { + public static void M(this $$C goo, int x, int y, string a = "test_a", string b = "test_b", string c = "test_c") + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(2), @@ -406,20 +425,21 @@ public static void M(this $$C goo, int x, int y, string a = ""test_a"", string b new AddedParameterOrExistingIndex(4), new AddedParameterOrExistingIndex(3)}; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 2, 1, 34, ""five"", ""four"", ""three""); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, byte b, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"") - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 2, 1, 34, "five", "four", "three"); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, byte b, string c = "test_c", string b = "test_b", string a = "test_a") + { } + } + """; // Although the `ParameterConfig` has 0 for the `SelectedIndex`, the UI dialog will make an adjustment // and select parameter `y` instead because the `this` parameter cannot be moved or removed. @@ -430,20 +450,21 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddAndReorderExtensionMethodParametersAndArguments_ExtensionCall() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - new C().M(1, 2, ""three"", ""four"", ""five""); - } -} - -public static class CExt -{ - public static void M(this C goo, int x$$, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"") - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + new C().M(1, 2, "three", "four", "five"); + } + } + + public static class CExt + { + public static void M(this C goo, int x$$, int y, string a = "test_a", string b = "test_b", string c = "test_c") + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(2), @@ -452,20 +473,21 @@ public static void M(this C goo, int x$$, int y, string a = ""test_a"", string b new AddedParameterOrExistingIndex(5), new AddedParameterOrExistingIndex(4), new AddedParameterOrExistingIndex(3)}; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - new C().M(2, 1, 34, ""five"", ""four"", ""three""); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, byte b, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"") - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + new C().M(2, 1, 34, "five", "four", "three"); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, byte b, string c = "test_c", string b = "test_b", string a = "test_a") + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 1); @@ -474,27 +496,29 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddParameterWithOmittedArgument_ParamsAsArray() { - var markup = @" -public class C -{ - void $$M(int x, int y, params int[] p) - { - M(x, y, p: p); - } -}"; + var markup = """ + public class C + { + void $$M(int x, int y, params int[] p) + { + M(x, y, p: p); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(1), AddedParameterOrExistingIndex.CreateAdded("int", "z", CallSiteKind.Omitted, isRequired: false, defaultValue: "3"), new AddedParameterOrExistingIndex(2)}; - var updatedCode = @" -public class C -{ - void M(int x, int y, int z = 3, params int[] p) - { - M(x, y, p: p); - } -}"; + var updatedCode = """ + public class C + { + void M(int x, int y, int z = 3, params int[] p) + { + M(x, y, p: p); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -502,27 +526,29 @@ void M(int x, int y, int z = 3, params int[] p) [Fact] public async Task AddAndReorderParamsMethodParametersAndArguments_ParamsAsArray() { - var markup = @" -public class C -{ - void $$M(int x, int y, params int[] p) - { - M(x, y, new[] { 1, 2, 3 }); - } -}"; + var markup = """ + public class C + { + void $$M(int x, int y, params int[] p) + { + M(x, y, new[] { 1, 2, 3 }); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(2)}; - var updatedCode = @" -public class C -{ - void M(int y, int x, byte b, params int[] p) - { - M(y, x, 34, new[] { 1, 2, 3 }); - } -}"; + var updatedCode = """ + public class C + { + void M(int y, int x, byte b, params int[] p) + { + M(y, x, 34, new[] { 1, 2, 3 }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -530,28 +556,30 @@ void M(int y, int x, byte b, params int[] p) [Fact] public async Task AddAndReorderParamsMethodParametersAndArguments_ParamsExpanded() { - var markup = @" -public class C -{ - void $$M(int x, int y, params int[] p) - { - M(x, y, 1, 2, 3); - } -}"; + var markup = """ + public class C + { + void $$M(int x, int y, params int[] p) + { + M(x, y, 1, 2, 3); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(2)}; - var updatedCode = @" -public class C -{ - void M(int y, int x, byte b, params int[] p) - { - M(y, x, 34, 1, 2, 3); - } -}"; + var updatedCode = """ + public class C + { + void M(int y, int x, byte b, params int[] p) + { + M(y, x, 34, 1, 2, 3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -559,23 +587,24 @@ void M(int y, int x, byte b, params int[] p) [Fact] public async Task AddAndReorderExtensionAndParamsMethodParametersAndArguments_VariedCallsites() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five"", new[] { 6, 7, 8 }); - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five"", 6, 7, 8); - new C().M(1, 2, ""three"", ""four"", ""five"", new[] { 6, 7, 8 }); - new C().M(1, 2, ""three"", ""four"", ""five"", 6, 7, 8); - } -} - -public static class CExt -{ - public static void $$M(this C goo, int x, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"", params int[] p) - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 1, 2, "three", "four", "five", new[] { 6, 7, 8 }); + CExt.M(new C(), 1, 2, "three", "four", "five", 6, 7, 8); + new C().M(1, 2, "three", "four", "five", new[] { 6, 7, 8 }); + new C().M(1, 2, "three", "four", "five", 6, 7, 8); + } + } + + public static class CExt + { + public static void $$M(this C goo, int x, int y, string a = "test_a", string b = "test_b", string c = "test_c", params int[] p) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), new AddedParameterOrExistingIndex(2), @@ -585,23 +614,24 @@ public static class CExt new AddedParameterOrExistingIndex(4), new AddedParameterOrExistingIndex(3), new AddedParameterOrExistingIndex(6)}; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 2, 1, 34, ""five"", ""four"", ""three"", new[] { 6, 7, 8 }); - CExt.M(new C(), 2, 1, 34, ""five"", ""four"", ""three"", 6, 7, 8); - new C().M(2, 1, 34, ""five"", ""four"", ""three"", new[] { 6, 7, 8 }); - new C().M(2, 1, 34, ""five"", ""four"", ""three"", 6, 7, 8); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, byte b, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"", params int[] p) - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 2, 1, 34, "five", "four", "three", new[] { 6, 7, 8 }); + CExt.M(new C(), 2, 1, 34, "five", "four", "three", 6, 7, 8); + new C().M(2, 1, 34, "five", "four", "three", new[] { 6, 7, 8 }); + new C().M(2, 1, 34, "five", "four", "three", 6, 7, 8); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, byte b, string c = "test_c", string b = "test_b", string a = "test_a", params int[] p) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -610,40 +640,42 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task AddAndReorderIndexerParametersAndArguments() { - var markup = @" -class Program -{ - void M() - { - var x = new Program()[1, 2]; - new Program()[1, 2] = x; - } - - public int this[int x, int y]$$ - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + var x = new Program()[1, 2]; + new Program()[1, 2] = x; + } + + public int this[int x, int y]$$ + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -class Program -{ - void M() - { - var x = new Program()[2, 34, 1]; - new Program()[2, 34, 1] = x; - } - - public int this[int y, byte b, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + void M() + { + var x = new Program()[2, 34, 1]; + new Program()[2, 34, 1] = x; + } + + public int this[int y, byte b, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -651,34 +683,36 @@ void M() [Fact] public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_OnIndividualLines() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - /// - void Goo(int c, int b, byte bb, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + /// + void Goo(int c, int b, byte bb, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -686,30 +720,32 @@ void Goo(int c, int b, byte bb, int a) [Fact] public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_OnSameLine() { - var markup = @" -public class C -{ - /// a is funb is func is fun - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// a is funb is func is fun + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// c is funb is fun - /// a is fun - void Goo(int c, int b, byte bb, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// c is funb is fun + /// a is fun + void Goo(int c, int b, byte bb, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -717,20 +753,21 @@ void Goo(int c, int b, byte bb, int a) [Fact] public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_MixedLineDistribution() { - var markup = @" -public class C -{ - /// - /// - /// - /// Comments spread - /// over several - /// lines - void $$Goo(int a, int b, int c, int d, int e, int f) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + /// Comments spread + /// over several + /// lines + void $$Goo(int a, int b, int c, int d, int e, int f) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(5), new AddedParameterOrExistingIndex(4), @@ -739,21 +776,22 @@ public class C new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// Comments spread - /// over several - /// lines - /// - /// - /// - /// - void Goo(int f, int e, int d, int c, byte bb, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// Comments spread + /// over several + /// lines + /// + /// + /// + /// + void Goo(int f, int e, int d, int c, byte bb, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -761,17 +799,18 @@ void Goo(int f, int e, int d, int c, byte bb, int b, int a) [Fact] public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_MixedWithRegularComments() { - var markup = @" -public class C -{ - /// - // Why is there a regular comment here? - /// - void $$Goo(int a, int b, int c, int d, int e) - { - - } -}"; + var markup = """ + public class C + { + /// + // Why is there a regular comment here? + /// + void $$Goo(int a, int b, int c, int d, int e) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(4), new AddedParameterOrExistingIndex(3), @@ -779,18 +818,19 @@ public class C new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - // Why is there a regular comment here? - /// - /// - void Goo(int e, int d, int c, byte b, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + // Why is there a regular comment here? + /// + /// + void Goo(int e, int d, int c, byte b, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -798,36 +838,38 @@ void Goo(int e, int d, int c, byte b, int b, int a) [Fact] public async Task AddAndReorderParamTagsInDocComments_MultiLineDocComments_OnSeparateLines1() { - var markup = @" -class Program -{ - /** - * x! - * y! - * z! - */ - static void $$M(int x, int y, int z) - { - } -}"; + var markup = """ + class Program + { + /** + * x! + * y! + * z! + */ + static void $$M(int x, int y, int z) + { + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -class Program -{ - /** - * z! - * - * y! - */ - /// x! - static void M(int z, byte b, int y, int x) - { - } -}"; + var updatedCode = """ + class Program + { + /** + * z! + * + * y! + */ + /// x! + static void M(int z, byte b, int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -835,28 +877,30 @@ static void M(int z, byte b, int y, int x) [Fact] public async Task AddAndReorderParamTagsInDocComments_MultiLineDocComments_OnSingleLine() { - var markup = @" -class Program -{ - /** x!y!z! */ - static void $$M(int x, int y, int z) - { - } -}"; + var markup = """ + class Program + { + /** x!y!z! */ + static void $$M(int x, int y, int z) + { + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -class Program -{ - /** z!y! */ - /// x! - static void M(int z, byte b, int y, int x) - { - } -}"; + var updatedCode = """ + class Program + { + /** z!y! */ + /// x! + static void M(int z, byte b, int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -864,230 +908,244 @@ static void M(int z, byte b, int y, int x) [Fact] public async Task AddAndReorderParamTagsInDocComments_IncorrectOrder_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - void Goo(int c, byte bb, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + void Goo(int c, byte bb, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParamTagsInDocComments_WrongNames_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - void Goo(int c, byte b, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + void Goo(int c, byte b, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParamTagsInDocComments_InsufficientTags_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - void Goo(int c, byte b, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + void Goo(int c, byte b, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParamTagsInDocComments_ExcessiveTags_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - /// - void Goo(int c, byte bb, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + /// + void Goo(int c, byte bb, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParamTagsInDocComments_OnConstructors() { - var markup = @" -public class C -{ - /// - /// - /// - public $$C(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + public $$C(int a, int b, int c) + { + + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - /// - public C(int c, byte bb, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + /// + public C(int c, byte bb, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParamTagsInDocComments_OnIndexers() { - var markup = @" -public class C -{ - /// - /// - /// - public int $$this[int a, int b, int c] - { - get { return 5; } - set { } - } -}"; + var markup = """ + public class C + { + /// + /// + /// + public int $$this[int a, int b, int c] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(2), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "bb", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -public class C -{ - /// - /// - /// - /// - public int this[int c, byte bb, int b, int a] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + /// + public int this[int c, byte bb, int b, int a] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task AddAndReorderParametersInCrefs() { - var markup = @" -class C -{ - /// - /// See and - /// - $$void M(int x, string y) - { } -}"; + var markup = """ + class C + { + /// + /// See and + /// + $$void M(int x, string y) + { } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -class C -{ - /// - /// See and - /// - void M(string y, byte b, int x) - { } -}"; + var updatedCode = """ + class C + { + /// + /// See and + /// + void M(string y, byte b, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1095,42 +1153,44 @@ void M(string y, byte b, int x) [Fact] public async Task AddAndReorderParametersInMethodThatImplementsInterfaceMethodOnlyThroughADerivedType1() { - var markup = @" -interface I -{ - $$void M(int x, string y); -} - -class C -{ - public void M(int x, string y) - { - } -} - -class D : C, I -{ -}"; + var markup = """ + interface I + { + $$void M(int x, string y); + } + + class C + { + public void M(int x, string y) + { + } + } + + class D : C, I + { + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -interface I -{ - void M(string y, byte b, int x); -} - -class C -{ - public void M(string y, byte b, int x) - { - } -} - -class D : C, I -{ -}"; + var updatedCode = """ + interface I + { + void M(string y, byte b, int x); + } + + class C + { + public void M(string y, byte b, int x) + { + } + } + + class D : C, I + { + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1138,42 +1198,44 @@ class D : C, I [Fact] public async Task AddAndReorderParametersInMethodThatImplementsInterfaceMethodOnlyThroughADerivedType2() { - var markup = @" -interface I -{ - void M(int x, string y); -} - -class C -{ - $$public void M(int x, string y) - { - } -} - -class D : C, I -{ -}"; + var markup = """ + interface I + { + void M(int x, string y); + } + + class C + { + $$public void M(int x, string y) + { + } + } + + class D : C, I + { + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -interface I -{ - void M(string y, byte b, int x); -} - -class C -{ - public void M(string y, byte b, int x) - { - } -} - -class D : C, I -{ -}"; + var updatedCode = """ + interface I + { + void M(string y, byte b, int x); + } + + class C + { + public void M(string y, byte b, int x) + { + } + } + + class D : C, I + { + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1181,46 +1243,48 @@ class D : C, I [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/43664")] public async Task AddParameterOnUnparenthesizedLambda() { - var markup = @" -using System.Linq; - -namespace ConsoleApp426 -{ - class Program - { - static void M(string[] args) - { - if (args.All(b$$ => Test())) - { - - } - } - - static bool Test() { return true; } - } -}"; + var markup = """ + using System.Linq; + + namespace ConsoleApp426 + { + class Program + { + static void M(string[] args) + { + if (args.All(b$$ => Test())) + { + + } + } + + static bool Test() { return true; } + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(0), AddedParameterOrExistingIndex.CreateAdded("byte", "bb", CallSiteKind.Value, callSiteValue: "34") }; - var updatedCode = @" -using System.Linq; + var updatedCode = """ + using System.Linq; -namespace ConsoleApp426 -{ - class Program - { - static void M(string[] args) - { - if (args.All((b, byte bb) => Test())) - { + namespace ConsoleApp426 + { + class Program + { + static void M(string[] args) + { + if (args.All((b, byte bb) => Test())) + { - } - } + } + } - static bool Test() { return true; } - } -}"; + static bool Test() { return true; } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1228,51 +1292,53 @@ static void M(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44126")] public async Task AddAndReorderImplicitObjectCreationParameter() { - var markup = @" -using System; -class C -{ - $$C(int x, string y) - { - } - - public void M() - { - C _ = new(1, ""y""); - } -}"; + var markup = """ + using System; + class C + { + $$C(int x, string y) + { + } + + public void M() + { + C _ = new(1, "y"); + } + } + """; var permutation = new[] { new AddedParameterOrExistingIndex(1), new AddedParameterOrExistingIndex(new AddedParameter(null, "byte", "b", CallSiteKind.Value, callSiteValue: "34"), "byte"), new AddedParameterOrExistingIndex(0)}; - var updatedCode = @" -using System; -class C -{ - C(string y, byte b, int x) - { - } - - public void M() - { - C _ = new(""y"", 34, 1); - } -}"; + var updatedCode = """ + using System; + class C + { + C(string y, byte b, int x) + { + } + + public void M() + { + C _ = new("y", 34, 1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44558")] public async Task AddParameters_Record() { - var markup = @" -/// -/// -/// -record $$R(int First, int Second, int Third) -{ - static R M() => new R(1, 2, 3); -} -"; + var markup = """ + /// + /// + /// + record $$R(int First, int Second, int Third) + { + static R M() => new R(1, 2, 3); + } + """; var updatedSignature = new AddedParameterOrExistingIndex[] { new(0), @@ -1280,16 +1346,16 @@ record $$R(int First, int Second, int Third) new(1), new(new AddedParameter(null, "int", "Forth", CallSiteKind.Value, "12345"), "System.Int32") }; - var updatedCode = @" -/// -/// -/// -/// -record R(int First, int Third, int Second, int Forth) -{ - static R M() => new R(1, 3, 2, 12345); -} -"; + var updatedCode = """ + /// + /// + /// + /// + record R(int First, int Third, int Second, int Forth) + { + static R M() => new R(1, 3, 2, 12345); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1297,15 +1363,15 @@ record R(int First, int Third, int Second, int Forth) [Fact] public async Task AddParameters_PrimaryConstructor_Class() { - var markup = @" -/// -/// -/// -class $$R(int First, int Second, int Third) -{ - static R M() => new R(1, 2, 3); -} -"; + var markup = """ + /// + /// + /// + class $$R(int First, int Second, int Third) + { + static R M() => new R(1, 2, 3); + } + """; var updatedSignature = new AddedParameterOrExistingIndex[] { new(0), @@ -1313,16 +1379,16 @@ class $$R(int First, int Second, int Third) new(1), new(new AddedParameter(null, "int", "Forth", CallSiteKind.Value, "12345"), "System.Int32") }; - var updatedCode = @" -/// -/// -/// -/// -class R(int First, int Third, int Second, int Forth) -{ - static R M() => new R(1, 3, 2, 12345); -} -"; + var updatedCode = """ + /// + /// + /// + /// + class R(int First, int Third, int Second, int Forth) + { + static R M() => new R(1, 3, 2, 12345); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1330,15 +1396,15 @@ class R(int First, int Third, int Second, int Forth) [Fact] public async Task AddParameters_PrimaryConstructor_Struct() { - var markup = @" -/// -/// -/// -struct $$R(int First, int Second, int Third) -{ - static R M() => new R(1, 2, 3); -} -"; + var markup = """ + /// + /// + /// + struct $$R(int First, int Second, int Third) + { + static R M() => new R(1, 2, 3); + } + """; var updatedSignature = new AddedParameterOrExistingIndex[] { new(0), @@ -1346,16 +1412,16 @@ struct $$R(int First, int Second, int Third) new(1), new(new AddedParameter(null, "int", "Forth", CallSiteKind.Value, "12345"), "System.Int32") }; - var updatedCode = @" -/// -/// -/// -/// -struct R(int First, int Third, int Second, int Forth) -{ - static R M() => new R(1, 3, 2, 12345); -} -"; + var updatedCode = """ + /// + /// + /// + /// + struct R(int First, int Third, int Second, int Forth) + { + static R M() => new R(1, 3, 2, 12345); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignatureTests.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignatureTests.cs index 0aa708e7d3a0a..bb92dc075eb2f 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignatureTests.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignatureTests.cs @@ -18,11 +18,12 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8333")] public async Task TestNotInExpressionBody() { - var markup = @" -class Ext -{ - void Goo(int a, int b) => [||]0; -}"; + var markup = """ + class Ext + { + void Goo(int a, int b) => [||]0; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -30,32 +31,34 @@ class Ext [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/1905")] public async Task TestAfterSemicolonForInvocationInExpressionStatement_ViaCommand() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - M1(1, 2);$$ - M2(1, 2, 3); - } - - static void M1(int x, int y) { } - - static void M2(int x, int y, int z) { } -}"; - var expectedCode = @" -class Program -{ - static void Main(string[] args) - { - M1(2, 1); - M2(1, 2, 3); - } - - static void M1(int y, int x) { } - - static void M2(int x, int y, int z) { } -}"; + var markup = """ + class Program + { + static void Main(string[] args) + { + M1(1, 2);$$ + M2(1, 2, 3); + } + + static void M1(int x, int y) { } + + static void M2(int x, int y, int z) { } + } + """; + var expectedCode = """ + class Program + { + static void Main(string[] args) + { + M1(2, 1); + M2(1, 2, 3); + } + + static void M1(int y, int x) { } + + static void M2(int x, int y, int z) { } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, @@ -67,22 +70,24 @@ await TestChangeSignatureViaCommandAsync( [Fact] public async Task TestOnLambdaWithTwoDiscardParameters_ViaCommand() { - var markup = @" -class Program -{ - static void M() - { - System.Func f = $$(int _, string _) => 1; - } -}"; - var expectedCode = @" -class Program -{ - static void M() - { - System.Func f = (string _, int _) => 1; - } -}"; + var markup = """ + class Program + { + static void M() + { + System.Func f = $$(int _, string _) => 1; + } + } + """; + var expectedCode = """ + class Program + { + static void M() + { + System.Func f = (string _, int _) => 1; + } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, @@ -94,47 +99,50 @@ await TestChangeSignatureViaCommandAsync( [Fact] public async Task TestOnAnonymousMethodWithTwoParameters_ViaCommand() { - var markup = @" -class Program -{ - static void M() - { - System.Func f = [||]delegate(int x, string y) { return 1; }; - } -}"; + var markup = """ + class Program + { + static void M() + { + System.Func f = [||]delegate(int x, string y) { return 1; }; + } + } + """; await TestMissingAsync(markup); } [Fact] public async Task TestOnAnonymousMethodWithTwoDiscardParameters_ViaCommand() { - var markup = @" -class Program -{ - static void M() - { - System.Func f = [||]delegate(int _, string _) { return 1; }; - } -}"; + var markup = """ + class Program + { + static void M() + { + System.Func f = [||]delegate(int _, string _) { return 1; }; + } + } + """; await TestMissingAsync(markup); } [Fact] public async Task TestAfterSemicolonForInvocationInExpressionStatement_ViaCodeAction() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - M1(1, 2);[||] - M2(1, 2, 3); - } + var markup = """ + class Program + { + static void Main(string[] args) + { + M1(1, 2);[||] + M2(1, 2, 3); + } - static void M1(int x, int y) { } + static void M1(int x, int y) { } - static void M2(int x, int y, int z) { } -}"; + static void M2(int x, int y, int z) { } + } + """; await TestMissingAsync(markup); } @@ -142,14 +150,15 @@ static void M2(int x, int y, int z) { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingWhitespace() { - var markup = @" -class Ext -{ - [||] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [||] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -157,14 +166,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingTrivia() { - var markup = @" -class Ext -{ - // [||] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + // [||] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -172,14 +182,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingTrivia2() { - var markup = @" -class Ext -{ - [||]// - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [||]// + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -187,14 +198,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingDocComment() { - var markup = @" -class Ext -{ - /// [||] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + /// [||] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -202,14 +214,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingDocComment2() { - var markup = @" -class Ext -{ - [||]/// - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [||]/// + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -217,14 +230,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingAttributes1() { - var markup = @" -class Ext -{ - [||][X] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [||][X] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -232,14 +246,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingAttributes2() { - var markup = @" -class Ext -{ - [[||]X] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [[||]X] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -247,14 +262,15 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInLeadingAttributes3() { - var markup = @" -class Ext -{ - [X][||] - void Goo(int a, int b) - { - }; -}"; + var markup = """ + class Ext + { + [X][||] + void Goo(int a, int b) + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } @@ -262,13 +278,14 @@ void Goo(int a, int b) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17309")] public async Task TestNotInConstraints() { - var markup = @" -class Ext -{ - void Goo(int a, int b) where [||]T : class - { - }; -}"; + var markup = """ + class Ext + { + void Goo(int a, int b) where [||]T : class + { + }; + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_CheckAllSignatureChanges.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_CheckAllSignatureChanges.cs index ca5e498c94d63..863abae8fd43d 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_CheckAllSignatureChanges.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_CheckAllSignatureChanges.cs @@ -24,47 +24,48 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests #pragma warning restore xUnit1019 public async Task TestAllSignatureChanges_1This_3Regular_2Default_1Params(int totalParameters, int[] signature) { - var markup = @" -static class Ext -{ - /// - /// This is a summary of - /// - /// - /// - /// - /// - /// - /// - /// - static void $$M(this object o, int a, string b, bool c, int x = 0, string y = ""Zero"", params int[] p) - { - object t = new object(); - - M(t, 1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - M(t, 1, ""two"", true, 3, ""four"", 5, 6); - t.M(1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - t.M(1, ""two"", true, 3, ""four"", 5, 6); - - M(t, 1, ""two"", true, 3, ""four""); - M(t, 1, ""two"", true, 3); - M(t, 1, ""two"", true); - - M(t, 1, ""two"", c: true); - M(t, 1, ""two"", true, 3, y: ""four""); - - M(t, 1, ""two"", true, 3, p: new[] { 5 }); - M(t, 1, ""two"", true, p: new[] { 5 }); - M(t, 1, ""two"", true, y: ""four""); - M(t, 1, ""two"", true, x: 3); - - M(t, 1, ""two"", true, y: ""four"", x: 3); - M(t, 1, y: ""four"", x: 3, b: ""two"", c: true); - M(t, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(t, p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1, o: t); - } -}"; + var markup = """ + static class Ext + { + /// + /// This is a summary of + /// + /// + /// + /// + /// + /// + /// + /// + static void $$M(this object o, int a, string b, bool c, int x = 0, string y = "Zero", params int[] p) + { + object t = new object(); + + M(t, 1, "two", true, 3, "four", new[] { 5, 6 }); + M(t, 1, "two", true, 3, "four", 5, 6); + t.M(1, "two", true, 3, "four", new[] { 5, 6 }); + t.M(1, "two", true, 3, "four", 5, 6); + + M(t, 1, "two", true, 3, "four"); + M(t, 1, "two", true, 3); + M(t, 1, "two", true); + + M(t, 1, "two", c: true); + M(t, 1, "two", true, 3, y: "four"); + + M(t, 1, "two", true, 3, p: new[] { 5 }); + M(t, 1, "two", true, p: new[] { 5 }); + M(t, 1, "two", true, y: "four"); + M(t, 1, "two", true, x: 3); + + M(t, 1, "two", true, y: "four", x: 3); + M(t, 1, y: "four", x: 3, b: "two", c: true); + M(t, y: "four", x: 3, c: true, b: "two", a: 1); + M(t, p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1); + M(p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1, o: t); + } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, @@ -83,93 +84,94 @@ await TestChangeSignatureViaCommandAsync( #pragma warning restore xUnit1019 public async Task TestAllSignatureChanges_OnDelegate_3Regular(int totalParameters, int[] signature) { - var markup = @" -using System; -using System.Collections.Generic; -using System.Linq; - -/// -/// This is , which has these methods: -/// -/// -/// -/// -/// -/// x! -/// y! -/// z! -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - - // Inline updates - d1(1, ""Two"", true); - d1.Invoke(1, ""Two"", true); - // d1.BeginInvoke(1, ""Two"", null, null); - d1.EndInvoke(null); - d1 = delegate (int e, string f, bool g) { var x = e + (g ? f.Length : 0); }; - d1 = delegate { }; - d1 = (r, s, t) => { var x = r + (t ? s.Length : 0); }; - - // Cascade through method groups - d1 = Goo1; - d1 = new MyDelegate(Goo2); - Target(Goo3); - Target((m, n, o) => { var x = m + (o ? n.Length : 0); }); - d1 = Result(); - d1 = Result2().First(); - d1 = Result3().First(); - - // And references to those methods - Goo1(1, ""Two"", true); - Goo2(1, ""Two"", true); - Goo2(1, false, false); // shouldn't change - Goo3(1, ""Two"", true); - Goo4(1, ""Two"", true); - Goo5(1, ""Two"", true); - } - - private MyDelegate Result() { return Goo4; } - private IEnumerable Result2() { yield return Goo5; } - private IEnumerable Result3() { yield return (g, h, i) => { var x = g + (i ? h.Length : 0); }; } - - void Target(MyDelegate d) { } - void TargetTakesAction(Action a) { } - - /// - /// - /// - void Goo1(int a, string b, bool c) { } - - /// - /// - /// - void Goo2(int a, string b, bool c) { } - - /// - /// - /// - void Goo2(int a, object b, bool c) { } - - /// - /// - /// - void Goo3(int a, string b, bool c) { } - - /// - /// - /// - void Goo4(int a, string b, bool c) { } - - /// - /// - /// - void Goo5(int a, string b, bool c) { } -}"; + var markup = """ + using System; + using System.Collections.Generic; + using System.Linq; + + /// + /// This is , which has these methods: + /// + /// + /// + /// + /// + /// x! + /// y! + /// z! + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + + // Inline updates + d1(1, "Two", true); + d1.Invoke(1, "Two", true); + // d1.BeginInvoke(1, "Two", null, null); + d1.EndInvoke(null); + d1 = delegate (int e, string f, bool g) { var x = e + (g ? f.Length : 0); }; + d1 = delegate { }; + d1 = (r, s, t) => { var x = r + (t ? s.Length : 0); }; + + // Cascade through method groups + d1 = Goo1; + d1 = new MyDelegate(Goo2); + Target(Goo3); + Target((m, n, o) => { var x = m + (o ? n.Length : 0); }); + d1 = Result(); + d1 = Result2().First(); + d1 = Result3().First(); + + // And references to those methods + Goo1(1, "Two", true); + Goo2(1, "Two", true); + Goo2(1, false, false); // shouldn't change + Goo3(1, "Two", true); + Goo4(1, "Two", true); + Goo5(1, "Two", true); + } + + private MyDelegate Result() { return Goo4; } + private IEnumerable Result2() { yield return Goo5; } + private IEnumerable Result3() { yield return (g, h, i) => { var x = g + (i ? h.Length : 0); }; } + + void Target(MyDelegate d) { } + void TargetTakesAction(Action a) { } + + /// + /// + /// + void Goo1(int a, string b, bool c) { } + + /// + /// + /// + void Goo2(int a, string b, bool c) { } + + /// + /// + /// + void Goo2(int a, object b, bool c) { } + + /// + /// + /// + void Goo3(int a, string b, bool c) { } + + /// + /// + /// + void Goo4(int a, string b, bool c) { } + + /// + /// + /// + void Goo5(int a, string b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs index eacb523cd690a..49f9d3e5cc1ca 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs @@ -27,29 +27,31 @@ protected internal override string GetLanguage() [Fact] public async Task ChangeSignature_Delegates_ImplicitInvokeCalls() { - var markup = @" -delegate void MyDelegate($$int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1(1, ""Two"", true); - } -}"; + var markup = """ + delegate void MyDelegate($$int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1(1, "Two", true); + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1(true, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1(true, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 0); } @@ -57,29 +59,31 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ChangeSignature_Delegates_ExplicitInvokeCalls() { - var markup = @" -delegate void MyDelegate(int x, string $$y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.Invoke(1, ""Two"", true); - } -}"; + var markup = """ + delegate void MyDelegate(int x, string $$y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.Invoke(1, "Two", true); + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.Invoke(true, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.Invoke(true, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 1); } @@ -87,29 +91,31 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ChangeSignature_Delegates_BeginInvokeCalls() { - var markup = @" -delegate void MyDelegate(int x, string y, bool z$$); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.BeginInvoke(1, ""Two"", true, null, null); - } -}"; + var markup = """ + delegate void MyDelegate(int x, string y, bool z$$); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.BeginInvoke(1, "Two", true, null, null); + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1.BeginInvoke(true, ""Two"", null, null); - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1.BeginInvoke(true, "Two", null, null); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 2); } @@ -117,633 +123,669 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ChangeSignature_Delegates_AnonymousMethods() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = delegate (int e, string f, bool g) { var x = f.Length + (g ? 0 : 1); }; - d1 = delegate { }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = delegate (int e, string f, bool g) { var x = f.Length + (g ? 0 : 1); }; + d1 = delegate { }; + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = delegate (bool g, string f) { var x = f.Length + (g ? 0 : 1); }; - d1 = delegate { }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = delegate (bool g, string f) { var x = f.Length + (g ? 0 : 1); }; + d1 = delegate { }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Lambdas() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (r, s, t) => { var x = s.Length + (t ? 0 : 1); }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (r, s, t) => { var x = s.Length + (t ? 0 : 1); }; + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (t, s) => { var x = s.Length + (t ? 0 : 1); }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (t, s) => { var x = s.Length + (t ? 0 : 1); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Lambdas_RemovingOnlyParameterIntroducesParentheses() { - var markup = @" -delegate void $$MyDelegate(int x); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = (r) => { System.Console.WriteLine(""Test""); }; - d1 = r => { System.Console.WriteLine(""Test""); }; - d1 = r => { System.Console.WriteLine(""Test""); }; - } -}"; + var markup = """ + delegate void $$MyDelegate(int x); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = (r) => { System.Console.WriteLine("Test"); }; + d1 = r => { System.Console.WriteLine("Test"); }; + d1 = r => { System.Console.WriteLine("Test"); }; + } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @" -delegate void MyDelegate(); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = () => { System.Console.WriteLine(""Test""); }; - d1 = () => { System.Console.WriteLine(""Test""); }; - d1 = () => { System.Console.WriteLine(""Test""); }; - } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = () => { System.Console.WriteLine("Test"); }; + d1 = () => { System.Console.WriteLine("Test"); }; + d1 = () => { System.Console.WriteLine("Test"); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughMethodGroups_AssignedToVariable() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = Goo; - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = Goo; + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = null; - d1 = Goo; - Goo(true, ""Two""); - Goo(1, false, false); - } - - void Goo(bool c, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = null; + d1 = Goo; + Goo(true, "Two"); + Goo(1, false, false); + } + + void Goo(bool c, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughMethodGroups_DelegateConstructor() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = new MyDelegate(Goo); - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = new MyDelegate(Goo); + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = new MyDelegate(Goo); - Goo(true, ""Two""); - Goo(1, false, false); - } - - void Goo(bool c, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = new MyDelegate(Goo); + Goo(true, "Two"); + Goo(1, false, false); + } + + void Goo(bool c, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughMethodGroups_PassedAsArgument() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - Target(Goo); - Goo(1, ""Two"", true); - Goo(1, false, false); - } - - void Target(MyDelegate d) { } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + Target(Goo); + Goo(1, "Two", true); + Goo(1, false, false); + } + + void Target(MyDelegate d) { } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - Target(Goo); - Goo(true, ""Two""); - Goo(1, false, false); - } - - void Target(MyDelegate d) { } - - void Goo(bool c, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + Target(Goo); + Goo(true, "Two"); + Goo(1, false, false); + } + + void Target(MyDelegate d) { } + + void Goo(bool c, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughMethodGroups_ReturnValue() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = Result(); - Goo(1, ""Two"", true); - } - - private MyDelegate Result() - { - return Goo; - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = Result(); + Goo(1, "Two", true); + } + + private MyDelegate Result() + { + return Goo; + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = Result(); - Goo(true, ""Two""); - } - - private MyDelegate Result() - { - return Goo; - } - - void Goo(bool c, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = Result(); + Goo(true, "Two"); + } + + private MyDelegate Result() + { + return Goo; + } + + void Goo(bool c, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughMethodGroups_YieldReturnValue() { - var markup = @" -using System.Collections.Generic; - -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - Goo(1, ""Two"", true); - } - - private IEnumerable Result() - { - yield return Goo; - } - - void Goo(int a, string b, bool c) { } - void Goo(int a, object b, bool c) { } -}"; + var markup = """ + using System.Collections.Generic; + + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + Goo(1, "Two", true); + } + + private IEnumerable Result() + { + yield return Goo; + } + + void Goo(int a, string b, bool c) { } + void Goo(int a, object b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -using System.Collections.Generic; - -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - Goo(true, ""Two""); - } - - private IEnumerable Result() - { - yield return Goo; - } - - void Goo(bool c, string b) { } - void Goo(int a, object b, bool c) { } -}"; + var expectedUpdatedCode = """ + using System.Collections.Generic; + + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + Goo(true, "Two"); + } + + private IEnumerable Result() + { + yield return Goo; + } + + void Goo(bool c, string b) { } + void Goo(int a, object b, bool c) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_ReferencingLambdas_MethodArgument() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M6() - { - Target((m, n, o) => { var x = n.Length + (o ? 0 : 1); }); - } - - void Target(MyDelegate d) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M6() + { + Target((m, n, o) => { var x = n.Length + (o ? 0 : 1); }); + } + + void Target(MyDelegate d) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class C -{ - void M6() - { - Target((o, n) => { var x = n.Length + (o ? 0 : 1); }); - } - - void Target(MyDelegate d) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class C + { + void M6() + { + Target((o, n) => { var x = n.Length + (o ? 0 : 1); }); + } + + void Target(MyDelegate d) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_ReferencingLambdas_YieldReturn() { - var markup = @" -using System.Collections.Generic; - -delegate void $$MyDelegate(int x, string y, bool z); -class C -{ - private IEnumerable Result3() - { - yield return (g, h, i) => { var x = h.Length + (i ? 0 : 1); }; - } -}"; + var markup = """ + using System.Collections.Generic; + + delegate void $$MyDelegate(int x, string y, bool z); + class C + { + private IEnumerable Result3() + { + yield return (g, h, i) => { var x = h.Length + (i ? 0 : 1); }; + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -using System.Collections.Generic; - -delegate void MyDelegate(bool z, string y); -class C -{ - private IEnumerable Result3() - { - yield return (i, h) => { var x = h.Length + (i ? 0 : 1); }; - } -}"; + var expectedUpdatedCode = """ + using System.Collections.Generic; + + delegate void MyDelegate(bool z, string y); + class C + { + private IEnumerable Result3() + { + yield return (i, h) => { var x = h.Length + (i ? 0 : 1); }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Recursive() { - var markup = @" -delegate RecursiveDelegate $$RecursiveDelegate(int x, string y, bool z); - -class C -{ - void M() - { - RecursiveDelegate rd = null; - rd(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true)(1, ""Two"", true); - } -}"; + var markup = """ + delegate RecursiveDelegate $$RecursiveDelegate(int x, string y, bool z); + + class C + { + void M() + { + RecursiveDelegate rd = null; + rd(1, "Two", true)(1, "Two", true)(1, "Two", true)(1, "Two", true)(1, "Two", true); + } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate RecursiveDelegate RecursiveDelegate(bool z, string y); - -class C -{ - void M() - { - RecursiveDelegate rd = null; - rd(true, ""Two"")(true, ""Two"")(true, ""Two"")(true, ""Two"")(true, ""Two""); - } -}"; + var expectedUpdatedCode = """ + delegate RecursiveDelegate RecursiveDelegate(bool z, string y); + + class C + { + void M() + { + RecursiveDelegate rd = null; + rd(true, "Two")(true, "Two")(true, "Two")(true, "Two")(true, "Two"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_DocComments() { - var markup = @" -/// -/// This is , which has these methods: -/// -/// -/// -/// -/// -/// x! -/// y! -/// z! -delegate void $$MyDelegate(int x, string y, bool z); - -class C -{ - void M() - { - MyDelegate d1 = Goo; - Goo(1, ""Two"", true); - } - - /// - /// - /// - void Goo(int a, string b, bool c) { } -}"; + var markup = """ + /// + /// This is , which has these methods: + /// + /// + /// + /// + /// + /// x! + /// y! + /// z! + delegate void $$MyDelegate(int x, string y, bool z); + + class C + { + void M() + { + MyDelegate d1 = Goo; + Goo(1, "Two", true); + } + + /// + /// + /// + void Goo(int a, string b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -/// -/// This is , which has these methods: -/// -/// -/// -/// -/// -/// z! -/// y! -/// -delegate void MyDelegate(bool z, string y); - -class C -{ - void M() - { - MyDelegate d1 = Goo; - Goo(true, ""Two""); - } - - /// - /// - /// - void Goo(bool c, string b) { } -}"; + var expectedUpdatedCode = """ + /// + /// This is , which has these methods: + /// + /// + /// + /// + /// + /// z! + /// y! + /// + delegate void MyDelegate(bool z, string y); + + class C + { + void M() + { + MyDelegate d1 = Goo; + Goo(true, "Two"); + } + + /// + /// + /// + void Goo(bool c, string b) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_CascadeThroughEventAdd() { - var markup = @" -delegate void $$MyDelegate(int x, string y, bool z); - -class Program -{ - void M() - { - MyEvent += Program_MyEvent; - } - - event MyDelegate MyEvent; - void Program_MyEvent(int a, string b, bool c) { } -}"; + var markup = """ + delegate void $$MyDelegate(int x, string y, bool z); + + class Program + { + void M() + { + MyEvent += Program_MyEvent; + } + + event MyDelegate MyEvent; + void Program_MyEvent(int a, string b, bool c) { } + } + """; var updatedSignature = new[] { 2, 1 }; - var expectedUpdatedCode = @" -delegate void MyDelegate(bool z, string y); - -class Program -{ - void M() - { - MyEvent += Program_MyEvent; - } - - event MyDelegate MyEvent; - void Program_MyEvent(bool c, string b) { } -}"; + var expectedUpdatedCode = """ + delegate void MyDelegate(bool z, string y); + + class Program + { + void M() + { + MyEvent += Program_MyEvent; + } + + event MyDelegate MyEvent; + void Program_MyEvent(bool c, string b) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Generics1() { - var markup = @" -public class DP16a -{ - public delegate void D($$T t); - public event D E1; - public event D E2; - - public void M1(int i) { } - public void M2(int i) { } - public void M3(int i) { } - - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + var markup = """ + public class DP16a + { + public delegate void D($$T t); + public event D E1; + public event D E2; + + public void M1(int i) { } + public void M2(int i) { } + public void M3(int i) { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @" -public class DP16a -{ - public delegate void D(); - public event D E1; - public event D E2; - - public void M1() { } - public void M2() { } - public void M3() { } - - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + var expectedUpdatedCode = """ + public class DP16a + { + public delegate void D(); + public event D E1; + public event D E2; + + public void M1() { } + public void M2() { } + public void M3() { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Generics2() { - var markup = @" -public class D17 -{ - public delegate void $$D(T t); -} -public class D17Test -{ - void Test() { var x = new D17.D(M17); } - internal void M17(string s) { } -}"; + var markup = """ + public class D17 + { + public delegate void $$D(T t); + } + public class D17Test + { + void Test() { var x = new D17.D(M17); } + internal void M17(string s) { } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @" -public class D17 -{ - public delegate void D(); -} -public class D17Test -{ - void Test() { var x = new D17.D(M17); } - internal void M17() { } -}"; + var expectedUpdatedCode = """ + public class D17 + { + public delegate void D(); + } + public class D17Test + { + void Test() { var x = new D17.D(M17); } + internal void M17() { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_GenericParams() { - var markup = @" -class DA -{ - void M(params int[] i) { } - void B() - { - DP20.D d = new DP20.D(M); - d(); - d(0); - d(0, 1); - } -} -public class DP20 -{ - public delegate void $$D(params T[] t); - public void M1(params T[] t) { } - - void B() - { - D d = new D(M1); - } -}"; + var markup = """ + class DA + { + void M(params int[] i) { } + void B() + { + DP20.D d = new DP20.D(M); + d(); + d(0); + d(0, 1); + } + } + public class DP20 + { + public delegate void $$D(params T[] t); + public void M1(params T[] t) { } + + void B() + { + D d = new D(M1); + } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @" -class DA -{ - void M() { } - void B() - { - DP20.D d = new DP20.D(M); - d(); - d(); - d(); - } -} -public class DP20 -{ - public delegate void D(); - public void M1() { } - - void B() - { - D d = new D(M1); - } -}"; + var expectedUpdatedCode = """ + class DA + { + void M() { } + void B() + { + DP20.D d = new DP20.D(M); + d(); + d(); + d(); + } + } + public class DP20 + { + public delegate void D(); + public void M1() { } + + void B() + { + D d = new D(M1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Delegates_Generic_RemoveArgumentAtReference() { - var markup = @"public class CD -{ - public delegate void D(T t); -} -class Test -{ - public void M() - { - var dele = new CD.$$D((int x) => { }); - } -}"; + var markup = """ + public class CD + { + public delegate void D(T t); + } + class Test + { + public void M() + { + var dele = new CD.$$D((int x) => { }); + } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @"public class CD -{ - public delegate void D(); -} -class Test -{ - public void M() - { - var dele = new CD.D(() => { }); - } -}"; + var expectedUpdatedCode = """ + public class CD + { + public delegate void D(); + } + class Test + { + public void M() + { + var dele = new CD.D(() => { }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode, expectedSelectedIndex: 0); } @@ -751,41 +793,43 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ChangeSignature_Delegate_Generics_RemoveStaticArgument() { - var markup = @" -public class C2 -{ - public delegate void D(T t); -} - -public class D2 -{ - public static D2 Instance = null; - void M(D2 m) { } - - void B() - { - C2.D d = new C2.D(M); - $$d(D2.Instance); - } -}"; + var markup = """ + public class C2 + { + public delegate void D(T t); + } + + public class D2 + { + public static D2 Instance = null; + void M(D2 m) { } + + void B() + { + C2.D d = new C2.D(M); + $$d(D2.Instance); + } + } + """; var updatedSignature = Array.Empty(); - var expectedUpdatedCode = @" -public class C2 -{ - public delegate void D(); -} - -public class D2 -{ - public static D2 Instance = null; - void M() { } - - void B() - { - C2.D d = new C2.D(M); - d(); - } -}"; + var expectedUpdatedCode = """ + public class C2 + { + public delegate void D(); + } + + public class D2 + { + public static D2 Instance = null; + void M() { } + + void B() + { + C2.D d = new C2.D(M); + d(); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs index afa05baf8c179..3f4a7e820eb97 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs @@ -18,416 +18,448 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task ChangeSignature_Formatting_KeepCountsPerLine() { - var markup = @" -class C -{ - void $$Method(int a, int b, int c, - int d, int e, - int f) - { - Method(1, - 2, 3, - 4, 5, 6); - } -}"; + var markup = """ + class C + { + void $$Method(int a, int b, int c, + int d, int e, + int f) + { + Method(1, + 2, 3, + 4, 5, 6); + } + } + """; var updatedSignature = new[] { 5, 4, 3, 2, 1, 0 }; - var expectedUpdatedCode = @" -class C -{ - void Method(int f, int e, int d, - int c, int b, - int a) - { - Method(6, - 5, 4, - 3, 2, 1); - } -}"; + var expectedUpdatedCode = """ + class C + { + void Method(int f, int e, int d, + int c, int b, + int a) + { + Method(6, + 5, 4, + 3, 2, 1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_KeepTrivia() { - var markup = @" -class C -{ - void $$Method( - int a, int b, int c, - int d, int e, - int f) - { - Method( - 1, 2, 3, - 4, 5, 6); - } -}"; + var markup = """ + class C + { + void $$Method( + int a, int b, int c, + int d, int e, + int f) + { + Method( + 1, 2, 3, + 4, 5, 6); + } + } + """; var updatedSignature = new[] { 1, 2, 3, 4, 5 }; - var expectedUpdatedCode = @" -class C -{ - void Method( - int b, int c, int d, - int e, int f) - { - Method( - 2, 3, 4, - 5, 6); - } -}"; + var expectedUpdatedCode = """ + class C + { + void Method( + int b, int c, int d, + int e, int f) + { + Method( + 2, 3, 4, + 5, 6); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_KeepTrivia_WithArgumentNames() { - var markup = @" -class C -{ - void $$Method( - int a, int b, int c, - int d, int e, - int f) - { - Method( - a: 1, b: 2, c: 3, - d: 4, e: 5, f: 6); - } -}"; + var markup = """ + class C + { + void $$Method( + int a, int b, int c, + int d, int e, + int f) + { + Method( + a: 1, b: 2, c: 3, + d: 4, e: 5, f: 6); + } + } + """; var updatedSignature = new[] { 1, 2, 3, 4, 5 }; - var expectedUpdatedCode = @" -class C -{ - void Method( - int b, int c, int d, - int e, int f) - { - Method( - b: 2, c: 3, d: 4, - e: 5, f: 6); - } -}"; + var expectedUpdatedCode = """ + class C + { + void Method( + int b, int c, int d, + int e, int f) + { + Method( + b: 2, c: 3, d: 4, + e: 5, f: 6); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_Method() { - var markup = @" -class C -{ - void $$Method(int a, - int b) - { - Method(1, - 2); - } -}"; + var markup = """ + class C + { + void $$Method(int a, + int b) + { + Method(1, + 2); + } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class C -{ - void Method(int b, - int a) - { - Method(2, - 1); - } -}"; + var expectedUpdatedCode = """ + class C + { + void Method(int b, + int a) + { + Method(2, + 1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_Constructor() { - var markup = @" -class SomeClass -{ - $$SomeClass(int a, - int b) - { - new SomeClass(1, - 2); - } -}"; + var markup = """ + class SomeClass + { + $$SomeClass(int a, + int b) + { + new SomeClass(1, + 2); + } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class SomeClass -{ - SomeClass(int b, - int a) - { - new SomeClass(2, - 1); - } -}"; + var expectedUpdatedCode = """ + class SomeClass + { + SomeClass(int b, + int a) + { + new SomeClass(2, + 1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_Indexer() { - var markup = @" -class SomeClass -{ - public int $$this[int a, - int b] - { - get - { - return new SomeClass()[1, - 2]; - } - } -}"; + var markup = """ + class SomeClass + { + public int $$this[int a, + int b] + { + get + { + return new SomeClass()[1, + 2]; + } + } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class SomeClass -{ - public int this[int b, - int a] - { - get - { - return new SomeClass()[2, - 1]; - } - } -}"; + var expectedUpdatedCode = """ + class SomeClass + { + public int this[int b, + int a] + { + get + { + return new SomeClass()[2, + 1]; + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_Delegate() { - var markup = @" -class SomeClass -{ - delegate void $$MyDelegate(int a, - int b); + var markup = """ + class SomeClass + { + delegate void $$MyDelegate(int a, + int b); - void M(int a, - int b) - { - var myDel = new MyDelegate(M); - myDel(1, - 2); - } -}"; + void M(int a, + int b) + { + var myDel = new MyDelegate(M); + myDel(1, + 2); + } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class SomeClass -{ - delegate void MyDelegate(int b, - int a); + var expectedUpdatedCode = """ + class SomeClass + { + delegate void MyDelegate(int b, + int a); - void M(int b, - int a) - { - var myDel = new MyDelegate(M); - myDel(2, - 1); - } -}"; + void M(int b, + int a) + { + var myDel = new MyDelegate(M); + myDel(2, + 1); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_AnonymousMethod() { - var markup = @" -class SomeClass -{ - delegate void $$MyDelegate(int a, - int b); + var markup = """ + class SomeClass + { + delegate void $$MyDelegate(int a, + int b); - void M() - { - MyDelegate myDel = delegate (int x, - int y) - { - // Nothing - }; - } -}"; + void M() + { + MyDelegate myDel = delegate (int x, + int y) + { + // Nothing + }; + } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class SomeClass -{ - delegate void MyDelegate(int b, - int a); + var expectedUpdatedCode = """ + class SomeClass + { + delegate void MyDelegate(int b, + int a); - void M() - { - MyDelegate myDel = delegate (int y, - int x) - { - // Nothing - }; - } -}"; + void M() + { + MyDelegate myDel = delegate (int y, + int x) + { + // Nothing + }; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_ConstructorInitializers() { - var markup = @" -class B -{ - public $$B(int x, int y) { } - public B() : this(1, - 2) - { } -} + var markup = """ + class B + { + public $$B(int x, int y) { } + public B() : this(1, + 2) + { } + } -class D : B -{ - public D() : base(1, - 2) - { } -}"; + class D : B + { + public D() : base(1, + 2) + { } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -class B -{ - public B(int y, int x) { } - public B() : this(2, - 1) - { } -} + var expectedUpdatedCode = """ + class B + { + public B(int y, int x) { } + public B() : this(2, + 1) + { } + } -class D : B -{ - public D() : base(2, - 1) - { } -}"; + class D : B + { + public D() : base(2, + 1) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact] public async Task ChangeSignature_Formatting_Attribute() { - var markup = @" -[Custom(1, - 2)] -class CustomAttribute : System.Attribute -{ - public $$CustomAttribute(int x, int y) { } -}"; + var markup = """ + [Custom(1, + 2)] + class CustomAttribute : System.Attribute + { + public $$CustomAttribute(int x, int y) { } + } + """; var updatedSignature = new[] { 1, 0 }; - var expectedUpdatedCode = @" -[Custom(2, - 1)] -class CustomAttribute : System.Attribute -{ - public CustomAttribute(int y, int x) { } -}"; + var expectedUpdatedCode = """ + [Custom(2, + 1)] + class CustomAttribute : System.Attribute + { + public CustomAttribute(int y, int x) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_Attribute_KeepTrivia() { - var markup = @" -[Custom( - 1, 2)] -class CustomAttribute : System.Attribute -{ - public $$CustomAttribute(int x, int y) { } -}"; + var markup = """ + [Custom( + 1, 2)] + class CustomAttribute : System.Attribute + { + public $$CustomAttribute(int x, int y) { } + } + """; var updatedSignature = new[] { 1 }; - var expectedUpdatedCode = @" -[Custom( - 2)] -class CustomAttribute : System.Attribute -{ - public CustomAttribute(int y) { } -}"; + var expectedUpdatedCode = """ + [Custom( + 2)] + class CustomAttribute : System.Attribute + { + public CustomAttribute(int y) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_Attribute_KeepTrivia_RemovingSecond() { - var markup = @" -[Custom( - 1, 2)] -class CustomAttribute : System.Attribute -{ - public $$CustomAttribute(int x, int y) { } -}"; + var markup = """ + [Custom( + 1, 2)] + class CustomAttribute : System.Attribute + { + public $$CustomAttribute(int x, int y) { } + } + """; var updatedSignature = new[] { 0 }; - var expectedUpdatedCode = @" -[Custom( - 1)] -class CustomAttribute : System.Attribute -{ - public CustomAttribute(int x) { } -}"; + var expectedUpdatedCode = """ + [Custom( + 1)] + class CustomAttribute : System.Attribute + { + public CustomAttribute(int x) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_Attribute_KeepTrivia_RemovingBoth() { - var markup = @" -[Custom( - 1, 2)] -class CustomAttribute : System.Attribute -{ - public $$CustomAttribute(int x, int y) { } -}"; + var markup = """ + [Custom( + 1, 2)] + class CustomAttribute : System.Attribute + { + public $$CustomAttribute(int x, int y) { } + } + """; var updatedSignature = new int[] { }; - var expectedUpdatedCode = @" -[Custom( -)] -class CustomAttribute : System.Attribute -{ - public CustomAttribute() { } -}"; + var expectedUpdatedCode = """ + [Custom( + )] + class CustomAttribute : System.Attribute + { + public CustomAttribute() { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28156")] public async Task ChangeSignature_Formatting_Attribute_KeepTrivia_RemovingBeforeNewlineComma() { - var markup = @" -[Custom(1 - , 2, 3)] -class CustomAttribute : System.Attribute -{ - public $$CustomAttribute(int x, int y, int z) { } -}"; + var markup = """ + [Custom(1 + , 2, 3)] + class CustomAttribute : System.Attribute + { + public $$CustomAttribute(int x, int y, int z) { } + } + """; var updatedSignature = new[] { 1, 2 }; - var expectedUpdatedCode = @" -[Custom(2, 3)] -class CustomAttribute : System.Attribute -{ - public CustomAttribute(int y, int z) { } -}"; + var expectedUpdatedCode = """ + [Custom(2, 3)] + class CustomAttribute : System.Attribute + { + public CustomAttribute(int y, int z) { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/946220")] public async Task ChangeSignature_Formatting_LambdaAsArgument() { - var markup = @"class C -{ - void M(System.Action f, int z$$) - { - M((x, y) => System.Console.WriteLine(x + y), 5); - } -}"; + var markup = """ + class C + { + void M(System.Action f, int z$$) + { + M((x, y) => System.Console.WriteLine(x + y), 5); + } + } + """; var updatedSignature = new[] { 0 }; - var expectedUpdatedCode = @"class C -{ - void M(System.Action f) - { - M((x, y) => System.Console.WriteLine(x + y)); - } -}"; + var expectedUpdatedCode = """ + class C + { + void M(System.Action f) + { + M((x, y) => System.Console.WriteLine(x + y)); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); } } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/RemoveParametersTests.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/RemoveParametersTests.cs index d34b9e380fe94..b975cd9071df6 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/RemoveParametersTests.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/RemoveParametersTests.cs @@ -28,89 +28,91 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)] public async Task RemoveParameters1() { - var markup = @" -static class Ext -{ - /// - /// This is a summary of - /// - /// - /// - /// - /// - /// - /// - /// - static void $$M(this object o, int a, string b, bool c, int x = 0, string y = ""Zero"", params int[] p) - { - object t = new object(); - - M(t, 1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - M(t, 1, ""two"", true, 3, ""four"", 5, 6); - t.M(1, ""two"", true, 3, ""four"", new[] { 5, 6 }); - t.M(1, ""two"", true, 3, ""four"", 5, 6); - - M(t, 1, ""two"", true, 3, ""four""); - M(t, 1, ""two"", true, 3); - M(t, 1, ""two"", true); - - M(t, 1, ""two"", c: true); - M(t, 1, ""two"", true, 3, y: ""four""); - - M(t, 1, ""two"", true, 3, p: new[] { 5 }); - M(t, 1, ""two"", true, p: new[] { 5 }); - M(t, 1, ""two"", true, y: ""four""); - M(t, 1, ""two"", true, x: 3); - - M(t, 1, ""two"", true, y: ""four"", x: 3); - M(t, 1, y: ""four"", x: 3, b: ""two"", c: true); - M(t, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(t, p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1); - M(p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1, o: t); - } -}"; + var markup = """ + static class Ext + { + /// + /// This is a summary of + /// + /// + /// + /// + /// + /// + /// + /// + static void $$M(this object o, int a, string b, bool c, int x = 0, string y = "Zero", params int[] p) + { + object t = new object(); + + M(t, 1, "two", true, 3, "four", new[] { 5, 6 }); + M(t, 1, "two", true, 3, "four", 5, 6); + t.M(1, "two", true, 3, "four", new[] { 5, 6 }); + t.M(1, "two", true, 3, "four", 5, 6); + + M(t, 1, "two", true, 3, "four"); + M(t, 1, "two", true, 3); + M(t, 1, "two", true); + + M(t, 1, "two", c: true); + M(t, 1, "two", true, 3, y: "four"); + + M(t, 1, "two", true, 3, p: new[] { 5 }); + M(t, 1, "two", true, p: new[] { 5 }); + M(t, 1, "two", true, y: "four"); + M(t, 1, "two", true, x: 3); + + M(t, 1, "two", true, y: "four", x: 3); + M(t, 1, y: "four", x: 3, b: "two", c: true); + M(t, y: "four", x: 3, c: true, b: "two", a: 1); + M(t, p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1); + M(p: new[] { 5 }, y: "four", x: 3, c: true, b: "two", a: 1, o: t); + } + } + """; var updatedSignature = new[] { 0, 2, 5 }; - var updatedCode = @" -static class Ext -{ - /// - /// This is a summary of - /// - /// - /// - /// - /// - /// - /// - /// - static void M(this object o, string b, string y = ""Zero"") - { - object t = new object(); - - M(t, ""two"", ""four""); - M(t, ""two"", ""four""); - t.M(""two"", ""four""); - t.M(""two"", ""four""); - - M(t, ""two"", ""four""); - M(t, ""two""); - M(t, ""two""); - - M(t, ""two""); - M(t, ""two"", y: ""four""); - - M(t, ""two""); - M(t, ""two""); - M(t, ""two"", y: ""four""); - M(t, ""two""); - - M(t, ""two"", y: ""four""); - M(t, y: ""four"", b: ""two""); - M(t, y: ""four"", b: ""two""); - M(t, y: ""four"", b: ""two""); - M(y: ""four"", b: ""two"", o: t); - } -}"; + var updatedCode = """ + static class Ext + { + /// + /// This is a summary of + /// + /// + /// + /// + /// + /// + /// + /// + static void M(this object o, string b, string y = "Zero") + { + object t = new object(); + + M(t, "two", "four"); + M(t, "two", "four"); + t.M("two", "four"); + t.M("two", "four"); + + M(t, "two", "four"); + M(t, "two"); + M(t, "two"); + + M(t, "two"); + M(t, "two", y: "four"); + + M(t, "two"); + M(t, "two"); + M(t, "two", y: "four"); + M(t, "two"); + + M(t, "two", y: "four"); + M(t, y: "four", b: "two"); + M(t, y: "four", b: "two"); + M(t, y: "four", b: "two"); + M(y: "four", b: "two", o: t); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -118,69 +120,71 @@ static void M(this object o, string b, string y = ""Zero"") [Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)] public async Task RemoveParameters_GenericParameterType() { - var markup = @" -class DA -{ - void M(params int[] i) { } - - void B() - { - DP20.D d = new DP20.D(M); - - /*DA19*/$$d(0); - d(); - d(0, 1); - } -} -public class DP20 -{ - public delegate void /*DP20*/D(params T[] t); - public event D E1; - public event D E2; + var markup = """ + class DA + { + void M(params int[] i) { } - public void M1(params T[] t) { } - public void M2(params T[] t) { } - public void M3(params T[] t) { } + void B() + { + DP20.D d = new DP20.D(M); - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + /*DA19*/$$d(0); + d(); + d(0, 1); + } + } + public class DP20 + { + public delegate void /*DP20*/D(params T[] t); + public event D E1; + public event D E2; + + public void M1(params T[] t) { } + public void M2(params T[] t) { } + public void M3(params T[] t) { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; var updatedSignature = Array.Empty(); - var updatedCode = @" -class DA -{ - void M() { } - - void B() - { - DP20.D d = new DP20.D(M); - - /*DA19*/d(); - d(); - d(); - } -} -public class DP20 -{ - public delegate void /*DP20*/D(); - public event D E1; - public event D E2; + var updatedCode = """ + class DA + { + void M() { } - public void M1() { } - public void M2() { } - public void M3() { } + void B() + { + DP20.D d = new DP20.D(M); - void B() - { - D d = new D(M1); - E1 += new D(M2); - E2 -= new D(M3); - } -}"; + /*DA19*/d(); + d(); + d(); + } + } + public class DP20 + { + public delegate void /*DP20*/D(); + public event D E1; + public event D E2; + + public void M1() { } + public void M2() { } + public void M3() { } + + void B() + { + D d = new D(M1); + E1 += new D(M2); + E2 -= new D(M3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -190,9 +194,10 @@ void B() [WorkItem("https://github.com/dotnet/roslyn/issues/784")] public async Task RemoveParameters_ExtensionMethodInAnotherFile() { - var workspaceXml = @" - - "; + var workspaceXml = """ + + + """; for (var i = 0; i <= 4; i++) { @@ -209,19 +214,20 @@ void M() "; } - workspaceXml += @" - -public class C5 -{ -} + workspaceXml += """ + + public class C5 + { + } -public static class C5Ext -{ - public void $$Ext(this C5 c, int i, string s) - { - } -} -"; + public static class C5Ext + { + public void $$Ext(this C5 c, int i, string s) + { + } + } + + """; for (var i = 6; i <= 9; i++) { @@ -238,9 +244,10 @@ void M() "; } - workspaceXml += @" - -"; + workspaceXml += """ + + + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), @@ -271,9 +278,10 @@ void M() [WorkItem("https://github.com/dotnet/roslyn/issues/784")] public async Task AddRemoveParameters_ExtensionMethodInAnotherFile() { - var workspaceXml = @" - - "; + var workspaceXml = """ + + + """; for (var i = 0; i <= 4; i++) { @@ -290,19 +298,20 @@ void M() "; } - workspaceXml += @" - -public class C5 -{ -} + workspaceXml += """ + + public class C5 + { + } -public static class C5Ext -{ - public void $$Ext(this C5 c, int i, string s) - { - } -} -"; + public static class C5Ext + { + public void $$Ext(this C5 c, int i, string s) + { + } + } + + """; for (var i = 6; i <= 9; i++) { @@ -319,9 +328,10 @@ void M() "; } - workspaceXml += @" - -"; + workspaceXml += """ + + + """; var updatedSignature = new[] { new AddedParameterOrExistingIndex(0), @@ -353,9 +363,9 @@ void M() [Trait(Traits.Feature, Traits.Features.Interactive)] public void ChangeSignatureCommandDisabledInSubmission() { - using var workspace = TestWorkspace.Create(XElement.Parse(@" + using var workspace = TestWorkspace.Create(XElement.Parse(""" - + class C { void M$$(int x) @@ -363,7 +373,8 @@ class C } } - "), + + """), workspaceKind: WorkspaceKind.Interactive, composition: EditorTestCompositions.EditorFeaturesWpf); // Force initialization. @@ -384,27 +395,29 @@ class C [WorkItem("https://github.com/dotnet/roslyn/issues/44126")] public async Task RemoveParameters_ImplicitObjectCreation() { - var markup = @" -public class C -{ - public $$C(int a, string b) { } + var markup = """ + public class C + { + public $$C(int a, string b) { } - void M() - { - C c = new(1, ""b""); - } -}"; + void M() + { + C c = new(1, "b"); + } + } + """; var updatedSignature = new[] { 1 }; - var updatedCode = @" -public class C -{ - public C(string b) { } + var updatedCode = """ + public class C + { + public C(string b) { } - void M() - { - C c = new(""b""); - } -}"; + void M() + { + C c = new("b"); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -413,20 +426,22 @@ void M() [WorkItem("https://github.com/dotnet/roslyn/issues/66547")] public async Task RemoveParameters_SpecialSymbolNamedParameter() { - var markup = @" -void $$m(object? param, bool @new = true) -{ -} + var markup = """ + void $$m(object? param, bool @new = true) + { + } -m(null, @new: false);"; + m(null, @new: false); + """; var updatedSignature = new[] { 1 }; - var updatedCode = @" -void m(bool @new = true) -{ -} + var updatedCode = """ + void m(bool @new = true) + { + } -m(@new: false);"; + m(@new: false); + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.Cascading.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.Cascading.cs index 7f41394a4506e..66c240851c7e9 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.Cascading.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.Cascading.cs @@ -18,29 +18,31 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task ReorderParameters_Cascade_ToImplementedMethod() { - var markup = @" -interface I -{ - void M(int x, string y); -} - -class C : I -{ - $$public void M(int x, string y) - { } -}"; + var markup = """ + interface I + { + void M(int x, string y); + } + + class C : I + { + $$public void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -interface I -{ - void M(string y, int x); -} - -class C : I -{ - public void M(string y, int x) - { } -}"; + var updatedCode = """ + interface I + { + void M(string y, int x); + } + + class C : I + { + public void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -48,29 +50,31 @@ public void M(string y, int x) [Fact] public async Task ReorderParameters_Cascade_ToImplementedMethod_WithTuples() { - var markup = @" -interface I -{ - void M((int, int) x, (string a, string b) y); -} - -class C : I -{ - $$public void M((int, int) x, (string a, string b) y) - { } -}"; + var markup = """ + interface I + { + void M((int, int) x, (string a, string b) y); + } + + class C : I + { + $$public void M((int, int) x, (string a, string b) y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -interface I -{ - void M((string a, string b) y, (int, int) x); -} - -class C : I -{ - public void M((string a, string b) y, (int, int) x) - { } -}"; + var updatedCode = """ + interface I + { + void M((string a, string b) y, (int, int) x); + } + + class C : I + { + public void M((string a, string b) y, (int, int) x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -78,29 +82,31 @@ public void M((string a, string b) y, (int, int) x) [Fact] public async Task ReorderParameters_Cascade_ToImplementingMethod() { - var markup = @" -interface I -{ - $$void M(int x, string y); -} - -class C : I -{ - public void M(int x, string y) - { } -}"; + var markup = """ + interface I + { + $$void M(int x, string y); + } + + class C : I + { + public void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -interface I -{ - void M(string y, int x); -} - -class C : I -{ - public void M(string y, int x) - { } -}"; + var updatedCode = """ + interface I + { + void M(string y, int x); + } + + class C : I + { + public void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -108,31 +114,33 @@ public void M(string y, int x) [Fact] public async Task ReorderParameters_Cascade_ToOverriddenMethod() { - var markup = @" -class B -{ - public virtual void M(int x, string y) - { } -} - -class D : B -{ - $$public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + public virtual void M(int x, string y) + { } + } + + class D : B + { + $$public override void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int x) - { } -} - -class D : B -{ - public override void M(string y, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int x) + { } + } + + class D : B + { + public override void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -140,31 +148,33 @@ public override void M(string y, int x) [Fact] public async Task ReorderParameters_Cascade_ToOverridingMethod() { - var markup = @" -class B -{ - $$public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + $$public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int x) - { } -} - -class D : B -{ - public override void M(string y, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int x) + { } + } + + class D : B + { + public override void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -172,43 +182,45 @@ public override void M(string y, int x) [Fact] public async Task ReorderParameters_Cascade_ToOverriddenMethod_Transitive() { - var markup = @" -class B -{ - public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -} - -class D2 : D -{ - $$public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + + class D2 : D + { + $$public override void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int x) - { } -} - -class D : B -{ - public override void M(string y, int x) - { } -} - -class D2 : D -{ - public override void M(string y, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int x) + { } + } + + class D : B + { + public override void M(string y, int x) + { } + } + + class D2 : D + { + public override void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -216,43 +228,45 @@ public override void M(string y, int x) [Fact] public async Task ReorderParameters_Cascade_ToOverridingMethod_Transitive() { - var markup = @" -class B -{ - $$public virtual void M(int x, string y) - { } -} - -class D : B -{ - public override void M(int x, string y) - { } -} - -class D2 : D -{ - public override void M(int x, string y) - { } -}"; + var markup = """ + class B + { + $$public virtual void M(int x, string y) + { } + } + + class D : B + { + public override void M(int x, string y) + { } + } + + class D2 : D + { + public override void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B -{ - public virtual void M(string y, int x) - { } -} - -class D : B -{ - public override void M(string y, int x) - { } -} - -class D2 : D -{ - public override void M(string y, int x) - { } -}"; + var updatedCode = """ + class B + { + public virtual void M(string y, int x) + { } + } + + class D : B + { + public override void M(string y, int x) + { } + } + + class D2 : D + { + public override void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -266,26 +280,28 @@ public async Task ReorderParameters_Cascade_ToMethods_Complex() //// / \ \ //// $$D2 D3 C - var markup = @" -class B { public virtual void M(int x, string y) { } } -class D : B, I { public override void M(int x, string y) { } } -class D2 : D { public override void $$M(int x, string y) { } } -class D3 : D { public override void M(int x, string y) { } } -interface I { void M(int x, string y); } -interface I2 { void M(int x, string y); } -interface I3 : I, I2 { } -class C : I3 { public void M(int x, string y) { } }"; + var markup = """ + class B { public virtual void M(int x, string y) { } } + class D : B, I { public override void M(int x, string y) { } } + class D2 : D { public override void $$M(int x, string y) { } } + class D3 : D { public override void M(int x, string y) { } } + interface I { void M(int x, string y); } + interface I2 { void M(int x, string y); } + interface I3 : I, I2 { } + class C : I3 { public void M(int x, string y) { } } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B { public virtual void M(string y, int x) { } } -class D : B, I { public override void M(string y, int x) { } } -class D2 : D { public override void M(string y, int x) { } } -class D3 : D { public override void M(string y, int x) { } } -interface I { void M(string y, int x); } -interface I2 { void M(string y, int x); } -interface I3 : I, I2 { } -class C : I3 { public void M(string y, int x) { } }"; + var updatedCode = """ + class B { public virtual void M(string y, int x) { } } + class D : B, I { public override void M(string y, int x) { } } + class D2 : D { public override void M(string y, int x) { } } + class D3 : D { public override void M(string y, int x) { } } + interface I { void M(string y, int x); } + interface I2 { void M(string y, int x); } + interface I3 : I, I2 { } + class C : I3 { public void M(string y, int x) { } } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -293,83 +309,85 @@ class C : I3 { public void M(string y, int x) { } }"; [Fact] public async Task ReorderParameters_Cascade_ToMethods_WithDifferentParameterNames() { - var markup = @" -public class B -{ - /// - /// - public virtual int M(int x, string y) - { - return 1; - } -} - -public class D : B -{ - /// - /// - public override int M(int a, string b) - { - return 1; - } -} - -public class D2 : D -{ - /// - /// - public override int $$M(int y, string x) - { - M(1, ""Two""); - ((D)this).M(1, ""Two""); - ((B)this).M(1, ""Two""); - - M(1, x: ""Two""); - ((D)this).M(1, b: ""Two""); - ((B)this).M(1, y: ""Two""); - - return 1; - } -}"; + var markup = """ + public class B + { + /// + /// + public virtual int M(int x, string y) + { + return 1; + } + } + + public class D : B + { + /// + /// + public override int M(int a, string b) + { + return 1; + } + } + + public class D2 : D + { + /// + /// + public override int $$M(int y, string x) + { + M(1, "Two"); + ((D)this).M(1, "Two"); + ((B)this).M(1, "Two"); + + M(1, x: "Two"); + ((D)this).M(1, b: "Two"); + ((B)this).M(1, y: "Two"); + + return 1; + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -public class B -{ - /// - /// - public virtual int M(string y, int x) - { - return 1; - } -} - -public class D : B -{ - /// - /// - public override int M(string b, int a) - { - return 1; - } -} - -public class D2 : D -{ - /// - /// - public override int M(string x, int y) - { - M(""Two"", 1); - ((D)this).M(""Two"", 1); - ((B)this).M(""Two"", 1); - - M(x: ""Two"", y: 1); - ((D)this).M(b: ""Two"", a: 1); - ((B)this).M(y: ""Two"", x: 1); - - return 1; - } -}"; + var updatedCode = """ + public class B + { + /// + /// + public virtual int M(string y, int x) + { + return 1; + } + } + + public class D : B + { + /// + /// + public override int M(string b, int a) + { + return 1; + } + } + + public class D2 : D + { + /// + /// + public override int M(string x, int y) + { + M("Two", 1); + ((D)this).M("Two", 1); + ((B)this).M("Two", 1); + + M(x: "Two", y: 1); + ((D)this).M(b: "Two", a: 1); + ((B)this).M(y: "Two", x: 1); + + return 1; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationErrors.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationErrors.cs index 0d34506490eeb..e77c9faef8170 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationErrors.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationErrors.cs @@ -19,14 +19,15 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task ReorderMethodParameters_InvokeOnClassName_ShouldFail() { - var markup = @" -using System; -class MyClass$$ -{ - public void Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass$$ + { + public void Goo(int x, string y) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.IncorrectKind); } @@ -34,16 +35,17 @@ public void Goo(int x, string y) [Fact] public async Task ReorderMethodParameters_InvokeOnField_ShouldFail() { - var markup = @" -using System; -class MyClass -{ - int t$$ = 2; + var markup = """ + using System; + class MyClass + { + int t$$ = 2; - public void Goo(int x, string y) - { - } -}"; + public void Goo(int x, string y) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.IncorrectKind); } @@ -58,14 +60,15 @@ public async Task ReorderMethodParameters_CanBeStartedEvenWithNoParameters() [Fact] public async Task ReorderMethodParameters_InvokeOnOverloadedOperator_ShouldFail() { - var markup = @" -class C -{ - public static C $$operator +(C a, C b) - { - return null; - } -}"; + var markup = """ + class C + { + public static C $$operator +(C a, C b) + { + return null; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.IncorrectKind); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationLocation.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationLocation.cs index 6d0ba4f85714f..0da679565e7e6 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationLocation.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.InvocationLocation.cs @@ -21,23 +21,25 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task ReorderMethodParameters_InvokeBeforeMethodName() { - var markup = @" -using System; -class MyClass -{ - public void $$Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void $$Goo(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -46,23 +48,25 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderMethodParameters_InvokeInParameterList() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, $$string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, $$string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 1); @@ -71,23 +75,25 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderMethodParameters_InvokeAfterParameterList() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y)$$ - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y)$$ + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -95,23 +101,25 @@ public void Goo(string y, int x) [Fact] public async Task ReorderMethodParameters_InvokeBeforeMethodDeclaration() { - var markup = @" -using System; -class MyClass -{ - $$public void Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + $$public void Goo(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -119,14 +127,15 @@ public void Goo(string y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnMetadataReference_InIdentifier_ShouldFail() { - var markup = @" -class C -{ - static void Main(string[] args) - { - ((System.IFormattable)null).ToSt$$ring(""test"", null); - } -}"; + var markup = """ + class C + { + static void Main(string[] args) + { + ((System.IFormattable)null).ToSt$$ring("test", null); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.DefinedInMetadata); } @@ -134,14 +143,15 @@ static void Main(string[] args) [Fact] public async Task ReorderMethodParameters_InvokeOnMetadataReference_AtBeginningOfInvocation_ShouldFail() { - var markup = @" -class C -{ - static void Main(string[] args) - { - $$((System.IFormattable)null).ToString(""test"", null); - } -}"; + var markup = """ + class C + { + static void Main(string[] args) + { + $$((System.IFormattable)null).ToString("test", null); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.DefinedInMetadata); } @@ -149,14 +159,15 @@ static void Main(string[] args) [Fact] public async Task ReorderMethodParameters_InvokeOnMetadataReference_InArgumentsOfInvocation_ShouldFail() { - var markup = @" -class C -{ - static void Main(string[] args) - { - ((System.IFormattable)null).ToString(""test"",$$ null); - } -}"; + var markup = """ + class C + { + static void Main(string[] args) + { + ((System.IFormattable)null).ToString("test",$$ null); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.DefinedInMetadata); } @@ -164,11 +175,12 @@ static void Main(string[] args) [Fact] public async Task ReorderMethodParameters_InvokeOnMetadataReference_AfterInvocation_ShouldFail() { - var markup = @" -class C -{ - string s = ((System.IFormattable)null).ToString(""test"", null)$$; -}"; + var markup = """ + class C + { + string s = ((System.IFormattable)null).ToString("test", null)$$; + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedFailureReason: ChangeSignatureFailureKind.IncorrectKind); } @@ -176,15 +188,16 @@ class C [Fact] public async Task ReorderMethodParameters_InvokeInMethodBody_ViaCommand() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - $$ - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + $$ + } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, markup, expectedSuccess: false); @@ -193,15 +206,16 @@ await TestChangeSignatureViaCommandAsync( [Fact] public async Task ReorderMethodParameters_InvokeInMethodBody_ViaSmartTag() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - [||] - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + [||] + } + } + """; await TestMissingAsync(markup); } @@ -209,33 +223,35 @@ public void Goo(int x, string y) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_BeginningOfIdentifier() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - $$Bar(x, y); - } - - public void Bar(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + $$Bar(x, y); + } + + public void Bar(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(y, x); - } - - public void Bar(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(y, x); + } + + public void Bar(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -243,33 +259,35 @@ public void Bar(string y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_ArgumentList() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - $$Bar(x, y); - } - - public void Bar(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + $$Bar(x, y); + } + + public void Bar(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(y, x); - } - - public void Bar(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(y, x); + } + + public void Bar(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -277,43 +295,45 @@ public void Bar(string y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_NestedCalls1() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar($$Baz(x, y), y); - } - - public void Bar(int x, string y) - { - } - - public int Baz(int x, string y) - { - return 1; - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar($$Baz(x, y), y); + } + + public void Bar(int x, string y) + { + } + + public int Baz(int x, string y) + { + return 1; + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(Baz(y, x), y); - } - - public void Bar(int x, string y) - { - } - - public int Baz(string y, int x) - { - return 1; - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(Baz(y, x), y); + } + + public void Bar(int x, string y) + { + } + + public int Baz(string y, int x) + { + return 1; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -321,43 +341,45 @@ public int Baz(string y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_NestedCalls2() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar$$(Baz(x, y), y); - } - - public void Bar(int x, string y) - { - } - - public int Baz(int x, string y) - { - return 1; - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar$$(Baz(x, y), y); + } + + public void Bar(int x, string y) + { + } + + public int Baz(int x, string y) + { + return 1; + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(y, Baz(x, y)); - } - - public void Bar(string y, int x) - { - } - - public int Baz(int x, string y) - { - return 1; - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(y, Baz(x, y)); + } + + public void Bar(string y, int x) + { + } + + public int Baz(int x, string y) + { + return 1; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -365,43 +387,45 @@ public int Baz(int x, string y) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_NestedCalls3() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(Baz(x, y), $$y); - } - - public void Bar(int x, string y) - { - } - - public int Baz(int x, string y) - { - return 1; - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(Baz(x, y), $$y); + } + + public void Bar(int x, string y) + { + } + + public int Baz(int x, string y) + { + return 1; + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - Bar(y, Baz(x, y)); - } - - public void Bar(string y, int x) - { - } - - public int Baz(int x, string y) - { - return 1; - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + Bar(y, Baz(x, y)); + } + + public void Bar(string y, int x) + { + } + + public int Baz(int x, string y) + { + return 1; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -409,27 +433,29 @@ public int Baz(int x, string y) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_Attribute() { - var markup = @" -using System; - -[$$My(1, 2)] -class MyAttribute : Attribute -{ - public MyAttribute(int x, int y) - { - } -}"; + var markup = """ + using System; + + [$$My(1, 2)] + class MyAttribute : Attribute + { + public MyAttribute(int x, int y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; - -[My(2, 1)] -class MyAttribute : Attribute -{ - public MyAttribute(int y, int x) - { - } -}"; + var updatedCode = """ + using System; + + [My(2, 1)] + class MyAttribute : Attribute + { + public MyAttribute(int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -437,21 +463,23 @@ public MyAttribute(int y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_OnlyHasCandidateSymbols() { - var markup = @" -class Test -{ - void M(int x, string y) { } - void M(int x, double y) { } - void M2() { $$M(""s"", 1); } -}"; + var markup = """ + class Test + { + void M(int x, string y) { } + void M(int x, double y) { } + void M2() { $$M("s", 1); } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Test -{ - void M(string y, int x) { } - void M(int x, double y) { } - void M2() { M(1, ""s""); } -}"; + var updatedCode = """ + class Test + { + void M(string y, int x) { } + void M(int x, double y) { } + void M2() { M(1, "s"); } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -459,29 +487,31 @@ void M(int x, double y) { } [Fact] public async Task ReorderMethodParameters_InvokeOnReference_CallToOtherConstructor() { - var markup = @" -class Program -{ - public Program(int x, int y) : this(1, 2, 3)$$ - { - } - - public Program(int x, int y, int z) - { - } -}"; + var markup = """ + class Program + { + public Program(int x, int y) : this(1, 2, 3)$$ + { + } + + public Program(int x, int y, int z) + { + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -class Program -{ - public Program(int x, int y) : this(3, 2, 1) - { - } - - public Program(int z, int y, int x) - { - } -}"; + var updatedCode = """ + class Program + { + public Program(int x, int y) : this(3, 2, 1) + { + } + + public Program(int z, int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -489,35 +519,37 @@ public Program(int z, int y, int x) [Fact] public async Task ReorderMethodParameters_InvokeOnReference_CallToBaseConstructor() { - var markup = @" -class B -{ - public B(int a, int b) - { - } -} - -class D : B -{ - public D(int x, int y) : base(1, 2)$$ - { - } -}"; + var markup = """ + class B + { + public B(int a, int b) + { + } + } + + class D : B + { + public D(int x, int y) : base(1, 2)$$ + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class B -{ - public B(int b, int a) - { - } -} - -class D : B -{ - public D(int x, int y) : base(2, 1) - { - } -}"; + var updatedCode = """ + class B + { + public B(int b, int a) + { + } + } + + class D : B + { + public D(int x, int y) : base(2, 1) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -529,25 +561,27 @@ public D(int x, int y) : base(2, 1) [Fact] public async Task ReorderIndexerParameters_InvokeAtBeginningOfDeclaration() { - var markup = @" -class Program -{ - $$int this[int x, string y] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + $$int this[int x, string y] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -556,25 +590,27 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderIndexerParameters_InParameters() { - var markup = @" -class Program -{ - int this[int x, $$string y] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + int this[int x, $$string y] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 1); @@ -583,25 +619,27 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderIndexerParameters_InvokeAtEndOfDeclaration() { - var markup = @" -class Program -{ - int this[int x, string y]$$ - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + int this[int x, string y]$$ + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -610,25 +648,27 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderIndexerParameters_InvokeInAccessor() { - var markup = @" -class Program -{ - int this[int x, string y] - { - get { return $$5; } - set { } - } -}"; + var markup = """ + class Program + { + int this[int x, string y] + { + get { return $$5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -636,35 +676,37 @@ class Program [Fact] public async Task ReorderIndexerParameters_InvokeOnReference_BeforeTarget() { - var markup = @" -class Program -{ - void M(Program p) - { - var t = $$p[5, ""test""]; - } - - int this[int x, string y] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M(Program p) + { + var t = $$p[5, "test"]; + } + + int this[int x, string y] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - void M(Program p) - { - var t = p[""test"", 5]; - } - - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + void M(Program p) + { + var t = p["test", 5]; + } + + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -672,35 +714,37 @@ void M(Program p) [Fact] public async Task ReorderIndexerParameters_InvokeOnReference_InArgumentList() { - var markup = @" -class Program -{ - void M(Program p) - { - var t = p[5, ""test""$$]; - } - - int this[int x, string y] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M(Program p) + { + var t = p[5, "test"$$]; + } + + int this[int x, string y] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - void M(Program p) - { - var t = p[""test"", 5]; - } - - int this[string y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + void M(Program p) + { + var t = p["test", 5]; + } + + int this[string y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -713,27 +757,29 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderDelegateParameters_ObjectCreation1() { - var markup = @" -public class C -{ - void T() - { - var d = new $$D((x, y) => { }); - } - - public delegate void D(int x, int y); -}"; + var markup = """ + public class C + { + void T() + { + var d = new $$D((x, y) => { }); + } + + public delegate void D(int x, int y); + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -public class C -{ - void T() - { - var d = new D((y, x) => { }); - } - - public delegate void D(int y, int x); -}"; + var updatedCode = """ + public class C + { + void T() + { + var d = new D((y, x) => { }); + } + + public delegate void D(int y, int x); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -742,31 +788,33 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderDelegateParameters_ObjectCreation2() { - var markup = @" -public class CD -{ - public delegate void D(T t, T u); -} -class Test -{ - public void M() - { - var dele = new CD.$$D((int x, int y) => { }); - } -}"; + var markup = """ + public class CD + { + public delegate void D(T t, T u); + } + class Test + { + public void M() + { + var dele = new CD.$$D((int x, int y) => { }); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -public class CD -{ - public delegate void D(T u, T t); -} -class Test -{ - public void M() - { - var dele = new CD.D((int y, int x) => { }); - } -}"; + var updatedCode = """ + public class CD + { + public delegate void D(T u, T t); + } + class Test + { + public void M() + { + var dele = new CD.D((int y, int x) => { }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -777,98 +825,106 @@ public void M() [Fact] public async Task ReorderMethodParameters_CodeRefactoring_InvokeBeforeMethodName() { - var markup = @" -using System; -class MyClass -{ - public void [||]Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void [||]Goo(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: true, updatedSignature: permutation, expectedCode: updatedCode); } [Fact] public async Task ReorderMethodParameters_CodeRefactoring_NotInMethodBody() { - var markup = @" -using System; -class MyClass -{ - public void Goo(int x, string y) - { - [||] - } -}"; + var markup = """ + using System; + class MyClass + { + public void Goo(int x, string y) + { + [||] + } + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } [Fact] public async Task ReorderMethodParameters_CodeRefactoring_InLambda() { - var markup = @" -class Program -{ - void M(int x) - { - System.Func f = (a, b)[||] => { return a; }; - } -}"; + var markup = """ + class Program + { + void M(int x) + { + System.Func f = (a, b)[||] => { return a; }; + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - void M(int x) - { - System.Func f = (b, a) => { return a; }; - } -}"; + var updatedCode = """ + class Program + { + void M(int x) + { + System.Func f = (b, a) => { return a; }; + } + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: true, updatedSignature: permutation, expectedCode: updatedCode); } [Fact] public async Task ReorderMethodParameters_CodeRefactoring_NotInLambdaBody() { - var markup = @" -class Program -{ - void M(int x) - { - System.Func f = (a, b) => { [||]return a; }; - } -}"; + var markup = """ + class Program + { + void M(int x) + { + System.Func f = (a, b) => { [||]return a; }; + } + } + """; await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction: false); } [Fact] public async Task ReorderMethodParameters_CodeRefactoring_AtCallSite_ViaCommand() { - var markup = @" -class Program -{ - void M(int x, int y) - { - M($$5, 6); - } -}"; + var markup = """ + class Program + { + void M(int x, int y) + { + M($$5, 6); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - void M(int y, int x) - { - M(6, 5); - } -}"; + var updatedCode = """ + class Program + { + void M(int y, int x) + { + M(6, 5); + } + } + """; await TestChangeSignatureViaCommandAsync( LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); @@ -877,14 +933,15 @@ await TestChangeSignatureViaCommandAsync( [Fact] public async Task ReorderMethodParameters_CodeRefactoring_AtCallSite_ViaCodeAction() { - var markup = @" -class Program -{ - void M(int x, int y) - { - M([||]5, 6); - } -}"; + var markup = """ + class Program + { + void M(int x, int y) + { + M([||]5, 6); + } + } + """; await TestMissingAsync(markup); } diff --git a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs index 24d17965507f5..522a17bc28c57 100644 --- a/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs +++ b/src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs @@ -18,31 +18,33 @@ public partial class ChangeSignatureTests : AbstractChangeSignatureTests [Fact] public async Task ReorderLocalFunctionParametersAndArguments_OnDeclaration() { - var markup = @" -using System; -class MyClass -{ - public void M() - { - Goo(1, 2); - void $$Goo(int x, string y) - { - } - } -}"; + var markup = """ + using System; + class MyClass + { + public void M() + { + Goo(1, 2); + void $$Goo(int x, string y) + { + } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void M() - { - Goo(2, 1); - void Goo(string y, int x) - { - } - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void M() + { + Goo(2, 1); + void Goo(string y, int x) + { + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -50,31 +52,33 @@ void Goo(string y, int x) [Fact] public async Task ReorderLocalFunctionParametersAndArguments_OnInvocation() { - var markup = @" -using System; -class MyClass -{ - public void M() - { - $$Goo(1, null); - void Goo(int x, string y) - { - } - } -}"; + var markup = """ + using System; + class MyClass + { + public void M() + { + $$Goo(1, null); + void Goo(int x, string y) + { + } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void M() - { - Goo(null, 1); - void Goo(string y, int x) - { - } - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void M() + { + Goo(null, 1); + void Goo(string y, int x) + { + } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -82,23 +86,25 @@ void Goo(string y, int x) [Fact] public async Task ReorderMethodParameters() { - var markup = @" -using System; -class MyClass -{ - public void $$Goo(int x, string y) - { - } -}"; + var markup = """ + using System; + class MyClass + { + public void $$Goo(int x, string y) + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -106,25 +112,27 @@ public void Goo(string y, int x) [Fact] public async Task ReorderMethodParametersAndArguments() { - var markup = @" -using System; -class MyClass -{ - public void $$Goo(int x, string y) - { - Goo(3, ""hello""); - } -}"; + var markup = """ + using System; + class MyClass + { + public void $$Goo(int x, string y) + { + Goo(3, "hello"); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public void Goo(string y, int x) - { - Goo(""hello"", 3); - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public void Goo(string y, int x) + { + Goo("hello", 3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -132,25 +140,27 @@ public void Goo(string y, int x) [Fact] public async Task ReorderMethodParametersAndArgumentsOfNestedCalls() { - var markup = @" -using System; -class MyClass -{ - public int $$Goo(int x, string y) - { - return Goo(Goo(4, ""inner""), ""outer""); - } -}"; + var markup = """ + using System; + class MyClass + { + public int $$Goo(int x, string y) + { + return Goo(Goo(4, "inner"), "outer"); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; -class MyClass -{ - public int Goo(string y, int x) - { - return Goo(""outer"", Goo(""inner"", 4)); - } -}"; + var updatedCode = """ + using System; + class MyClass + { + public int Goo(string y, int x) + { + return Goo("outer", Goo("inner", 4)); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -158,49 +168,51 @@ public int Goo(string y, int x) [Fact] public async Task ReorderConstructorParametersAndArguments() { - var markup = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(5, ""test2"") - { - } -} - -class MyClass -{ - public MyClass() : this(2, ""test"") - { - } - - public $$MyClass(int x, string y) - { - var t = new MyClass(x, y); - } -}"; + var markup = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base(5, "test2") + { + } + } + + class MyClass + { + public MyClass() : this(2, "test") + { + } + + public $$MyClass(int x, string y) + { + var t = new MyClass(x, y); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(""test2"", 5) - { - } -} - -class MyClass -{ - public MyClass() : this(""test"", 2) - { - } - - public MyClass(string y, int x) - { - var t = new MyClass(y, x); - } -}"; + var updatedCode = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base("test2", 5) + { + } + } + + class MyClass + { + public MyClass() : this("test", 2) + { + } + + public MyClass(string y, int x) + { + var t = new MyClass(y, x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -208,49 +220,51 @@ public MyClass(string y, int x) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44126")] public async Task ReorderConstructorParametersAndArguments_ImplicitObjectCreation() { - var markup = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(5, ""test2"") - { - } -} - -class MyClass -{ - public MyClass() : this(2, ""test"") - { - } - - public MyClass(int x, string y) - { - MyClass t = new$$(x, y); - } -}"; + var markup = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base(5, "test2") + { + } + } + + class MyClass + { + public MyClass() : this(2, "test") + { + } + + public MyClass(int x, string y) + { + MyClass t = new$$(x, y); + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -using System; - -class MyClass2 : MyClass -{ - public MyClass2() : base(""test2"", 5) - { - } -} - -class MyClass -{ - public MyClass() : this(""test"", 2) - { - } - - public MyClass(string y, int x) - { - MyClass t = new(y, x); - } -}"; + var updatedCode = """ + using System; + + class MyClass2 : MyClass + { + public MyClass2() : base("test2", 5) + { + } + } + + class MyClass + { + public MyClass() : this("test", 2) + { + } + + public MyClass(string y, int x) + { + MyClass t = new(y, x); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -258,31 +272,33 @@ public MyClass(string y, int x) [Fact] public async Task ReorderAttributeConstructorParametersAndArguments() { - var markup = @" -[My(""test"", 8)] -class MyClass -{ -} - -class MyAttribute : System.Attribute -{ - public MyAttribute(string x, int y)$$ - { - } -}"; + var markup = """ + [My("test", 8)] + class MyClass + { + } + + class MyAttribute : System.Attribute + { + public MyAttribute(string x, int y)$$ + { + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -[My(8, ""test"")] -class MyClass -{ -} - -class MyAttribute : System.Attribute -{ - public MyAttribute(int y, string x) - { - } -}"; + var updatedCode = """ + [My(8, "test")] + class MyClass + { + } + + class MyAttribute : System.Attribute + { + public MyAttribute(int y, string x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -290,35 +306,37 @@ public MyAttribute(int y, string x) [Fact] public async Task ReorderExtensionMethodParametersAndArguments_StaticCall() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five""); - } -} - -public static class CExt -{ - public static void M(this $$C goo, int x, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"") - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 1, 2, "three", "four", "five"); + } + } + + public static class CExt + { + public static void M(this $$C goo, int x, int y, string a = "test_a", string b = "test_b", string c = "test_c") + { } + } + """; var permutation = new[] { 0, 2, 1, 5, 4, 3 }; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 2, 1, ""five"", ""four"", ""three""); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"") - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 2, 1, "five", "four", "three"); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, string c = "test_c", string b = "test_b", string a = "test_a") + { } + } + """; // Although the `ParameterConfig` has 0 for the `SelectedIndex`, the UI dialog will make an adjustment // and select parameter `y` instead because the `this` parameter cannot be moved or removed. @@ -329,35 +347,37 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderExtensionMethodParametersAndArguments_ExtensionCall() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - new C().M(1, 2, ""three"", ""four"", ""five""); - } -} - -public static class CExt -{ - public static void M(this C goo, int x$$, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"") - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + new C().M(1, 2, "three", "four", "five"); + } + } + + public static class CExt + { + public static void M(this C goo, int x$$, int y, string a = "test_a", string b = "test_b", string c = "test_c") + { } + } + """; var permutation = new[] { 0, 2, 1, 5, 4, 3 }; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - new C().M(2, 1, ""five"", ""four"", ""three""); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"") - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + new C().M(2, 1, "five", "four", "three"); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, string c = "test_c", string b = "test_b", string a = "test_a") + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 1); @@ -366,23 +386,25 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderParamsMethodParametersAndArguments_ParamsAsArray() { - var markup = @" -public class C -{ - void $$M(int x, int y, params int[] p) - { - M(x, y, new[] { 1, 2, 3 }); - } -}"; + var markup = """ + public class C + { + void $$M(int x, int y, params int[] p) + { + M(x, y, new[] { 1, 2, 3 }); + } + } + """; var permutation = new[] { 1, 0, 2 }; - var updatedCode = @" -public class C -{ - void M(int y, int x, params int[] p) - { - M(y, x, new[] { 1, 2, 3 }); - } -}"; + var updatedCode = """ + public class C + { + void M(int y, int x, params int[] p) + { + M(y, x, new[] { 1, 2, 3 }); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -390,23 +412,25 @@ void M(int y, int x, params int[] p) [Fact] public async Task ReorderParamsMethodParametersAndArguments_ParamsExpanded() { - var markup = @" -public class C -{ - void $$M(int x, int y, params int[] p) - { - M(x, y, 1, 2, 3); - } -}"; + var markup = """ + public class C + { + void $$M(int x, int y, params int[] p) + { + M(x, y, 1, 2, 3); + } + } + """; var permutation = new[] { 1, 0, 2 }; - var updatedCode = @" -public class C -{ - void M(int y, int x, params int[] p) - { - M(y, x, 1, 2, 3); - } -}"; + var updatedCode = """ + public class C + { + void M(int y, int x, params int[] p) + { + M(y, x, 1, 2, 3); + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -414,41 +438,43 @@ void M(int y, int x, params int[] p) [Fact] public async Task ReorderExtensionAndParamsMethodParametersAndArguments_VariedCallsites() { - var markup = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five"", new[] { 6, 7, 8 }); - CExt.M(new C(), 1, 2, ""three"", ""four"", ""five"", 6, 7, 8); - new C().M(1, 2, ""three"", ""four"", ""five"", new[] { 6, 7, 8 }); - new C().M(1, 2, ""three"", ""four"", ""five"", 6, 7, 8); - } -} - -public static class CExt -{ - public static void $$M(this C goo, int x, int y, string a = ""test_a"", string b = ""test_b"", string c = ""test_c"", params int[] p) - { } -}"; + var markup = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 1, 2, "three", "four", "five", new[] { 6, 7, 8 }); + CExt.M(new C(), 1, 2, "three", "four", "five", 6, 7, 8); + new C().M(1, 2, "three", "four", "five", new[] { 6, 7, 8 }); + new C().M(1, 2, "three", "four", "five", 6, 7, 8); + } + } + + public static class CExt + { + public static void $$M(this C goo, int x, int y, string a = "test_a", string b = "test_b", string c = "test_c", params int[] p) + { } + } + """; var permutation = new[] { 0, 2, 1, 5, 4, 3, 6 }; - var updatedCode = @" -public class C -{ - static void Main(string[] args) - { - CExt.M(new C(), 2, 1, ""five"", ""four"", ""three"", new[] { 6, 7, 8 }); - CExt.M(new C(), 2, 1, ""five"", ""four"", ""three"", 6, 7, 8); - new C().M(2, 1, ""five"", ""four"", ""three"", new[] { 6, 7, 8 }); - new C().M(2, 1, ""five"", ""four"", ""three"", 6, 7, 8); - } -} - -public static class CExt -{ - public static void M(this C goo, int y, int x, string c = ""test_c"", string b = ""test_b"", string a = ""test_a"", params int[] p) - { } -}"; + var updatedCode = """ + public class C + { + static void Main(string[] args) + { + CExt.M(new C(), 2, 1, "five", "four", "three", new[] { 6, 7, 8 }); + CExt.M(new C(), 2, 1, "five", "four", "three", 6, 7, 8); + new C().M(2, 1, "five", "four", "three", new[] { 6, 7, 8 }); + new C().M(2, 1, "five", "four", "three", 6, 7, 8); + } + } + + public static class CExt + { + public static void M(this C goo, int y, int x, string c = "test_c", string b = "test_b", string a = "test_a", params int[] p) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode, expectedSelectedIndex: 0); @@ -457,37 +483,39 @@ await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSi [Fact] public async Task ReorderIndexerParametersAndArguments() { - var markup = @" -class Program -{ - void M() - { - var x = new Program()[1, 2]; - new Program()[1, 2] = x; - } - - public int this[int x, int y]$$ - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + var x = new Program()[1, 2]; + new Program()[1, 2] = x; + } + + public int this[int x, int y]$$ + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class Program -{ - void M() - { - var x = new Program()[2, 1]; - new Program()[2, 1] = x; - } - - public int this[int y, int x] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + class Program + { + void M() + { + var x = new Program()[2, 1]; + new Program()[2, 1] = x; + } + + public int this[int y, int x] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -495,29 +523,31 @@ void M() [Fact] public async Task ReorderParamTagsInDocComments_SingleLineDocComments_OnIndividualLines() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - void Goo(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + void Goo(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -525,25 +555,27 @@ void Goo(int c, int b, int a) [Fact] public async Task ReorderParamTagsInDocComments_SingleLineDocComments_OnSameLine() { - var markup = @" -public class C -{ - /// a is funb is func is fun - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// a is funb is func is fun + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// c is funb is funa is fun - void Goo(int c, int b, int a) - { + var updatedCode = """ + public class C + { + /// c is funb is funa is fun + void Goo(int c, int b, int a) + { - } -}"; + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -551,35 +583,37 @@ void Goo(int c, int b, int a) [Fact] public async Task ReorderParamTagsInDocComments_SingleLineDocComments_MixedLineDistribution() { - var markup = @" -public class C -{ - /// - /// - /// - /// Comments spread - /// over several - /// lines - void $$Goo(int a, int b, int c, int d, int e, int f) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + /// Comments spread + /// over several + /// lines + void $$Goo(int a, int b, int c, int d, int e, int f) + { + + } + } + """; var permutation = new[] { 5, 4, 3, 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// Comments spread - /// over several - /// lines - /// - /// - /// - void Goo(int f, int e, int d, int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// Comments spread + /// over several + /// lines + /// + /// + /// + void Goo(int f, int e, int d, int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -587,29 +621,31 @@ void Goo(int f, int e, int d, int c, int b, int a) [Fact] public async Task ReorderParamTagsInDocComments_SingleLineDocComments_MixedWithRegularComments() { - var markup = @" -public class C -{ - /// - // Why is there a regular comment here? - /// - void $$Goo(int a, int b, int c, int d, int e) - { - - } -}"; + var markup = """ + public class C + { + /// + // Why is there a regular comment here? + /// + void $$Goo(int a, int b, int c, int d, int e) + { + + } + } + """; var permutation = new[] { 4, 3, 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - // Why is there a regular comment here? - /// - void Goo(int e, int d, int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + // Why is there a regular comment here? + /// + void Goo(int e, int d, int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -617,31 +653,33 @@ void Goo(int e, int d, int c, int b, int a) [Fact] public async Task ReorderParamTagsInDocComments_MultiLineDocComments_OnSeparateLines1() { - var markup = @" -class Program -{ - /** - * x! - * y! - * z! - */ - static void $$M(int x, int y, int z) - { - } -}"; + var markup = """ + class Program + { + /** + * x! + * y! + * z! + */ + static void $$M(int x, int y, int z) + { + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -class Program -{ - /** - * z! - * y! - * x! - */ - static void M(int z, int y, int x) - { - } -}"; + var updatedCode = """ + class Program + { + /** + * z! + * y! + * x! + */ + static void M(int z, int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -649,23 +687,25 @@ static void M(int z, int y, int x) [Fact] public async Task ReorderParamTagsInDocComments_MultiLineDocComments_OnSingleLine() { - var markup = @" -class Program -{ - /** x!y!z! */ - static void $$M(int x, int y, int z) - { - } -}"; + var markup = """ + class Program + { + /** x!y!z! */ + static void $$M(int x, int y, int z) + { + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -class Program -{ - /** z!y!x! */ - static void M(int z, int y, int x) - { - } -}"; + var updatedCode = """ + class Program + { + /** z!y!x! */ + static void M(int z, int y, int x) + { + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -673,201 +713,215 @@ static void M(int z, int y, int x) [Fact] public async Task ReorderParamTagsInDocComments_IncorrectOrder_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - void Goo(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + void Goo(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParamTagsInDocComments_WrongNames_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - void Goo(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + void Goo(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParamTagsInDocComments_InsufficientTags_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - void Goo(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + void Goo(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParamTagsInDocComments_ExcessiveTags_MaintainsOrder() { - var markup = @" -public class C -{ - /// - /// - /// - /// - void $$Goo(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + /// + void $$Goo(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - /// - void Goo(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + /// + void Goo(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParamTagsInDocComments_OnConstructors() { - var markup = @" -public class C -{ - /// - /// - /// - public $$C(int a, int b, int c) - { - - } -}"; + var markup = """ + public class C + { + /// + /// + /// + public $$C(int a, int b, int c) + { + + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - public C(int c, int b, int a) - { - - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + public C(int c, int b, int a) + { + + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParamTagsInDocComments_OnIndexers() { - var markup = @" -public class C -{ - /// - /// - /// - public int $$this[int a, int b, int c] - { - get { return 5; } - set { } - } -}"; + var markup = """ + public class C + { + /// + /// + /// + public int $$this[int a, int b, int c] + { + get { return 5; } + set { } + } + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -public class C -{ - /// - /// - /// - public int this[int c, int b, int a] - { - get { return 5; } - set { } - } -}"; + var updatedCode = """ + public class C + { + /// + /// + /// + public int this[int c, int b, int a] + { + get { return 5; } + set { } + } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } [Fact] public async Task ReorderParametersInCrefs() { - var markup = @" -class C -{ - /// - /// See and - /// - $$void M(int x, string y) - { } -}"; + var markup = """ + class C + { + /// + /// See and + /// + $$void M(int x, string y) + { } + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -class C -{ - /// - /// See and - /// - void M(string y, int x) - { } -}"; + var updatedCode = """ + class C + { + /// + /// See and + /// + void M(string y, int x) + { } + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -875,39 +929,41 @@ void M(string y, int x) [Fact] public async Task ReorderParametersInMethodThatImplementsInterfaceMethodOnlyThroughADerivedType1() { - var markup = @" -interface I -{ - $$void M(int x, string y); -} - -class C -{ - public void M(int x, string y) - { - } -} - -class D : C, I -{ -}"; + var markup = """ + interface I + { + $$void M(int x, string y); + } + + class C + { + public void M(int x, string y) + { + } + } + + class D : C, I + { + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -interface I -{ - void M(string y, int x); -} - -class C -{ - public void M(string y, int x) - { - } -} - -class D : C, I -{ -}"; + var updatedCode = """ + interface I + { + void M(string y, int x); + } + + class C + { + public void M(string y, int x) + { + } + } + + class D : C, I + { + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -915,39 +971,41 @@ class D : C, I [Fact] public async Task ReorderParametersInMethodThatImplementsInterfaceMethodOnlyThroughADerivedType2() { - var markup = @" -interface I -{ - void M(int x, string y); -} - -class C -{ - $$public void M(int x, string y) - { - } -} - -class D : C, I -{ -}"; + var markup = """ + interface I + { + void M(int x, string y); + } + + class C + { + $$public void M(int x, string y) + { + } + } + + class D : C, I + { + } + """; var permutation = new[] { 1, 0 }; - var updatedCode = @" -interface I -{ - void M(string y, int x); -} - -class C -{ - public void M(string y, int x) - { - } -} - -class D : C, I -{ -}"; + var updatedCode = """ + interface I + { + void M(string y, int x); + } + + class C + { + public void M(string y, int x) + { + } + } + + class D : C, I + { + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -955,23 +1013,25 @@ class D : C, I [Fact] public async Task ReorderParamTagsInDocComments_Record() { - var markup = @" -/// -/// -/// -record $$R(int A, int B, int C) -{ - public static R Instance = new(0, 1, 2); -}"; + var markup = """ + /// + /// + /// + record $$R(int A, int B, int C) + { + public static R Instance = new(0, 1, 2); + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -/// -/// -/// -record R(int C, int B, int A) -{ - public static R Instance = new(2, 1, 0); -}"; + var updatedCode = """ + /// + /// + /// + record R(int C, int B, int A) + { + public static R Instance = new(2, 1, 0); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -979,23 +1039,25 @@ record R(int C, int B, int A) [Fact] public async Task ReorderParamTagsInDocComments_PrimaryConstructor_Class() { - var markup = @" -/// -/// -/// -class $$R(int A, int B, int C) -{ - public static R Instance = new(0, 1, 2); -}"; + var markup = """ + /// + /// + /// + class $$R(int A, int B, int C) + { + public static R Instance = new(0, 1, 2); + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -/// -/// -/// -class R(int C, int B, int A) -{ - public static R Instance = new(2, 1, 0); -}"; + var updatedCode = """ + /// + /// + /// + class R(int C, int B, int A) + { + public static R Instance = new(2, 1, 0); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } @@ -1003,23 +1065,25 @@ class R(int C, int B, int A) [Fact] public async Task ReorderParamTagsInDocComments_PrimaryConstructor_Struct() { - var markup = @" -/// -/// -/// -struct $$R(int A, int B, int C) -{ - public static R Instance = new(0, 1, 2); -}"; + var markup = """ + /// + /// + /// + struct $$R(int A, int B, int C) + { + public static R Instance = new(0, 1, 2); + } + """; var permutation = new[] { 2, 1, 0 }; - var updatedCode = @" -/// -/// -/// -struct R(int C, int B, int A) -{ - public static R Instance = new(2, 1, 0); -}"; + var updatedCode = """ + /// + /// + /// + struct R(int C, int B, int A) + { + public static R Instance = new(2, 1, 0); + } + """; await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); } diff --git a/src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests_Preprocessor.cs b/src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests_Preprocessor.cs index 38f081c7e5024..d5c9413138983 100644 --- a/src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests_Preprocessor.cs +++ b/src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests_Preprocessor.cs @@ -19,8 +19,10 @@ public partial class SyntacticClassifierTests public async Task PP_IfTrue(TestHost testHost) { var code = -@"#if true -#endif"; + """ + #if true + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -34,8 +36,10 @@ await TestInMethodAsync(code, public async Task PP_IfTrueWithComment(TestHost testHost) { var code = -@"#if true //Goo -#endif"; + """ + #if true //Goo + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -50,8 +54,10 @@ await TestInMethodAsync(code, public async Task PP_IfFalse(TestHost testHost) { var code = -@"#if false -#endif"; + """ + #if false + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -65,8 +71,10 @@ await TestInMethodAsync(code, public async Task PP_IfGOO(TestHost testHost) { var code = -@"#if GOO -#endif"; + """ + #if GOO + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -80,8 +88,10 @@ await TestInMethodAsync(code, public async Task PP_IfNotTrue(TestHost testHost) { var code = -@"#if !true -#endif"; + """ + #if !true + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -96,8 +106,10 @@ await TestInMethodAsync(code, public async Task PP_IfNotFalse(TestHost testHost) { var code = -@"#if !false -#endif"; + """ + #if !false + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -112,8 +124,10 @@ await TestInMethodAsync(code, public async Task PP_IfNotGOO(TestHost testHost) { var code = -@"#if !GOO -#endif"; + """ + #if !GOO + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -128,8 +142,10 @@ await TestInMethodAsync(code, public async Task PP_IfTrueWithParens(TestHost testHost) { var code = -@"#if (true) -#endif"; + """ + #if (true) + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -145,8 +161,10 @@ await TestInMethodAsync(code, public async Task PP_IfFalseWithParens(TestHost testHost) { var code = -@"#if (false) -#endif"; + """ + #if (false) + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -162,8 +180,10 @@ await TestInMethodAsync(code, public async Task PP_IfGOOWithParens(TestHost testHost) { var code = -@"#if (GOO) -#endif"; + """ + #if (GOO) + #endif + """; await TestInMethodAsync(code, testHost, PPKeyword("#"), @@ -179,8 +199,10 @@ await TestInMethodAsync(code, public async Task PP_IfOrExpression(TestHost testHost) { var code = -@"#if GOO || BAR -#endif"; + """ + #if GOO || BAR + #endif + """; await TestInMethodAsync(code, testHost, @@ -197,8 +219,10 @@ await TestInMethodAsync(code, public async Task PP_IfAndExpression(TestHost testHost) { var code = -@"#if GOO && BAR -#endif"; + """ + #if GOO && BAR + #endif + """; await TestInMethodAsync(code, testHost, @@ -215,8 +239,10 @@ await TestInMethodAsync(code, public async Task PP_IfOrAndExpression(TestHost testHost) { var code = -@"#if GOO || BAR && BAZ -#endif"; + """ + #if GOO || BAR && BAZ + #endif + """; await TestInMethodAsync(code, testHost, @@ -235,8 +261,10 @@ await TestInMethodAsync(code, public async Task PP_IfOrExpressionWithParens(TestHost testHost) { var code = -@"#if (GOO || BAR) -#endif"; + """ + #if (GOO || BAR) + #endif + """; await TestInMethodAsync(code, testHost, @@ -255,8 +283,10 @@ await TestInMethodAsync(code, public async Task PP_IfAndExpressionWithParens(TestHost testHost) { var code = -@"#if (GOO && BAR) -#endif"; + """ + #if (GOO && BAR) + #endif + """; await TestInMethodAsync(code, testHost, @@ -275,8 +305,10 @@ await TestInMethodAsync(code, public async Task PP_IfOrAndExpressionWithParens(TestHost testHost) { var code = -@"#if GOO || (BAR && BAZ) -#endif"; + """ + #if GOO || (BAR && BAZ) + #endif + """; await TestInMethodAsync(code, testHost, @@ -317,8 +349,10 @@ await TestAsync(" #if goo", public async Task PP_If3(TestHost testHost) { var code = -@"#if goo -#endif"; + """ + #if goo + #endif + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -332,8 +366,10 @@ await TestAsync(code, public async Task PP_If4(TestHost testHost) { var code = -@"#if -#endif"; + """ + #if + #endif + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -346,17 +382,21 @@ await TestAsync(code, public async Task PP_If5(TestHost testHost) { var code = -@"#if -aoeu -aoeu -#endif"; + """ + #if + aoeu + aoeu + #endif + """; await TestAsync(code, testHost, PPKeyword("#"), PPKeyword("if"), - Inactive(@"aoeu -aoeu -"), + Inactive(""" + aoeu + aoeu + + """), PPKeyword("#"), PPKeyword("endif")); } @@ -365,9 +405,11 @@ await TestAsync(code, public async Task PP_If6(TestHost testHost) { var code = -@"#if -#else -aeu"; + """ + #if + #else + aeu + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -381,10 +423,12 @@ await TestAsync(code, public async Task PP_If7(TestHost testHost) { var code = -@"#if -#else -#endif -aeu"; + """ + #if + #else + #endif + aeu + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -401,13 +445,15 @@ await TestAsync(code, public async Task PP_If8(bool script, TestHost testHost) { var code = -@"#if -#else -aoeu -aoeu -aou -#endif -aeu"; + """ + #if + #else + aoeu + aoeu + aou + #endif + aeu + """; var parseOptions = script ? Options.Script : null; @@ -433,13 +479,15 @@ await TestAsync( public async Task PP_If9(bool script, TestHost testHost) { var code = -@"#if //Goo1 -#else //Goo2 -aoeu -aoeu -aou -#endif //Goo3 -aeu"; + """ + #if //Goo1 + #else //Goo2 + aoeu + aoeu + aou + #endif //Goo3 + aeu + """; var parseOptions = script ? Options.Script : null; @@ -525,8 +573,10 @@ await TestAsync(" #endregion adsf", public async Task PP_RegionEndRegion1(TestHost testHost) { await TestAsync( -@"#region -#endregion", + """ + #region + #endregion + """, testHost, PPKeyword("#"), PPKeyword("region"), @@ -538,8 +588,10 @@ await TestAsync( public async Task PP_CommentAfterRegion1(TestHost testHost) { await TestAsync( -@"#region adsf //comment -#endregion", + """ + #region adsf //comment + #endregion + """, testHost, PPKeyword("#"), PPKeyword("region"), @@ -552,8 +604,10 @@ await TestAsync( public async Task PP_CommentAfterRegion2(TestHost testHost) { await TestAsync( -@"#region //comment -#endregion", + """ + #region //comment + #endregion + """, testHost, PPKeyword("#"), PPKeyword("region"), @@ -566,8 +620,10 @@ await TestAsync( public async Task PP_CommentAfterEndRegion1(TestHost testHost) { await TestAsync( -@"#region -#endregion adsf //comment", + """ + #region + #endregion adsf //comment + """, testHost, PPKeyword("#"), PPKeyword("region"), @@ -580,8 +636,10 @@ await TestAsync( public async Task PP_CommentAfterEndRegion2(TestHost testHost) { await TestAsync( -@"#region -#endregion //comment", + """ + #region + #endregion //comment + """, testHost, PPKeyword("#"), PPKeyword("region"), @@ -594,8 +652,10 @@ await TestAsync( public async Task PP_DeclarationDirectives(TestHost testHost) { await TestAsync( -@"#define A -#undef B", + """ + #define A + #undef B + """, testHost, PPKeyword("#"), PPKeyword("define"), @@ -609,10 +669,12 @@ await TestAsync( public async Task PP_IfElseEndIfDirectives(TestHost testHost) { var code = -@"#if true -#elif DEBUG -#else -#endif"; + """ + #if true + #elif DEBUG + #else + #endif + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -822,14 +884,18 @@ await TestAsync(code, [Theory, CombinatorialData] public async Task PP_LineNumberWithFilename(TestHost testHost) { - var code = @"#line 100 ""C:\Goo"""; + var code = """ + #line 100 "C:\Goo" + """; await TestAsync(code, testHost, PPKeyword("#"), PPKeyword("line"), Number("100"), - String("\"C:\\Goo\"")); + String(""" + "C:\Goo" + """)); } [Theory, CombinatorialData] @@ -842,14 +908,18 @@ await TestAsync(code, PPKeyword("#"), PPKeyword("line"), Number("100"), - String("\"C:\\Goo\""), + String(""" + "C:\Goo" + """), Comment("//Goo")); } [Theory, CombinatorialData] public async Task PP_LineSpanWithCharacterOffset(TestHost testHost) { - var code = @"#line (1, 2) - (3, 4) 5 ""file.txt"""; + var code = """ + #line (1, 2) - (3, 4) 5 "file.txt" + """; await TestAsync(code, testHost, @@ -867,7 +937,9 @@ await TestAsync(code, Number("4"), Punctuation.CloseParen, Number("5"), - String("\"file.txt\"")); + String(""" + "file.txt" + """)); } [Theory, CombinatorialData] @@ -890,7 +962,9 @@ await TestAsync(code, Punctuation.Comma, Number("4"), Punctuation.CloseParen, - String("\"\""), + String(""" + "" + """), Comment("//comment")); } @@ -1014,14 +1088,22 @@ await TestAsync( public async Task PP_PragmaChecksum2(TestHost testHost) { await TestAsync( -@"#pragma checksum ""file.txt"" ""{00000000-0000-0000-0000-000000000000}"" ""2453""", + """ + #pragma checksum "file.txt" "{00000000-0000-0000-0000-000000000000}" "2453" + """, testHost, PPKeyword("#"), PPKeyword("pragma"), PPKeyword("checksum"), - String("\"file.txt\""), - String("\"{00000000-0000-0000-0000-000000000000}\""), - String("\"2453\"")); + String(""" + "file.txt" + """), + String(""" + "{00000000-0000-0000-0000-000000000000}" + """), + String(""" + "2453" + """)); } [Theory, CombinatorialData] @@ -1033,9 +1115,15 @@ await TestAsync( PPKeyword("#"), PPKeyword("pragma"), PPKeyword("checksum"), - String("\"file.txt\""), - String("\"{00000000-0000-0000-0000-000000000000}\""), - String("\"2453\""), + String(""" + "file.txt" + """), + String(""" + "{00000000-0000-0000-0000-000000000000}" + """), + String(""" + "2453" + """), Comment("// Goo")); } diff --git a/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs b/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs index 87ed0949bb6a1..6232c7e025f2b 100644 --- a/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs @@ -31,11 +31,13 @@ public class SyntacticTaggerTests public async Task TestTagsChangedForPortionThatChanged() { var code = -@"class Program2 -{ - string x = @""/// $$ -/// ""; -}"; + """ + class Program2 + { + string x = @"/// $$ + /// "; + } + """; using var workspace = TestWorkspace.CreateCSharp(code); var document = workspace.Documents.First(); var subjectBuffer = document.GetTextBuffer(); @@ -74,7 +76,9 @@ public async Task TestTagsChangedForPortionThatChanged() checkpoint = new Checkpoint(); // Now apply an edit that require us to reclassify more that just the current line - var snapshot = subjectBuffer.Insert(document.CursorPosition.Value, "\""); + var snapshot = subjectBuffer.Insert(document.CursorPosition.Value, """ + " + """); expectedLength = snapshot.Length; // NOTE: TagsChanged is raised on the UI thread, so there is no race between diff --git a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs index 31f1c6748c84f..4a5c135d647f2 100644 --- a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs @@ -46,11 +46,13 @@ await TestAsync( public async Task Bug17819(TestHost testHost) { await TestAsync( -@"_ _() -{ -} -/// where where : partial -{ - static dynamic dynamic() - { - return dynamic(); - } -} -"; + var code = """ + partial class partial where where : partial + { + static dynamic dynamic() + { + return dynamic(); + } + } + """; await TestAsync(code, testHost, Keyword("partial"), @@ -303,16 +312,18 @@ await TestInMethodAsync(@"foreach (var v in args) { }", public async Task ValueInSetterAndAnonymousTypePropertyName(TestHost testHost) { await TestAsync( -@"class C -{ - int P - { - set - { - var t = new { value = value }; - } - } -}", + """ + class C + { + int P + { + set + { + var t = new { value = value }; + } + } + } + """, testHost, Keyword("class"), Class("C"), @@ -341,18 +352,20 @@ int P public async Task TestValueInEvent(TestHost testHost) { await TestInClassAsync( -@"event int Bar -{ - add - { - this.value = value; - } + """ + event int Bar + { + add + { + this.value = value; + } - remove - { - this.value = value; - } -}", + remove + { + this.value = value; + } + } + """, testHost, Keyword("event"), Keyword("int"), @@ -384,18 +397,20 @@ await TestInClassAsync( public async Task TestValueInProperty(TestHost testHost) { await TestInClassAsync( -@"int Goo -{ - get - { - this.value = value; - } + """ + int Goo + { + get + { + this.value = value; + } - set - { - this.value = value; - } -}", + set + { + this.value = value; + } + } + """, testHost, Keyword("int"), Property("Goo"), @@ -426,13 +441,15 @@ await TestInClassAsync( public async Task ValueFieldInSetterAccessedThroughThis(TestHost testHost) { await TestInClassAsync( -@"int P -{ - set - { - this.value = value; - } -}", + """ + int P + { + set + { + this.value = value; + } + } + """, testHost, Keyword("int"), Property("P"), @@ -472,13 +489,15 @@ await TestInMethodAsync( public async Task TestVarConstructor(TestHost testHost) { await TestAsync( -@"class var -{ - void Main() - { - new var(); - } -}", + """ + class var + { + void Main() + { + new var(); + } + } + """, testHost, Keyword("class"), Class("var"), @@ -502,13 +521,15 @@ void Main() public async Task TestVarTypeParameter(TestHost testHost) { await TestAsync( -@"class X -{ - void Goo() - { - var x; - } -}", + """ + class X + { + void Goo() + { + var x; + } + } + """, testHost, Keyword("class"), Class("X"), @@ -533,12 +554,14 @@ void Goo() public async Task TestVarAttribute1(TestHost testHost) { await TestAsync( -@"using System; + """ + using System; -[var] -class var : Attribute -{ -}", + [var] + class var : Attribute + { + } + """, testHost, Keyword("using"), Namespace("System"), @@ -559,12 +582,14 @@ class var : Attribute public async Task TestVarAttribute2(TestHost testHost) { await TestAsync( -@"using System; + """ + using System; -[var] -class varAttribute : Attribute -{ -}", + [var] + class varAttribute : Attribute + { + } + """, testHost, Keyword("using"), Namespace("System"), @@ -585,15 +610,17 @@ class varAttribute : Attribute public async Task TestStandaloneTypeName(TestHost testHost) { await TestAsync( -@"using System; + """ + using System; -class C -{ - static void Main() - { - var tree = Console - } -}", + class C + { + static void Main() + { + var tree = Console + } + } + """, testHost, Keyword("using"), Namespace("System"), @@ -622,13 +649,15 @@ static void Main() public async Task TestNamespaceClassAmbiguities(TestHost testHost) { await TestAsync( -@"class C -{ -} + """ + class C + { + } -namespace C -{ -}", + namespace C + { + } + """, testHost, Keyword("class"), Class("C"), @@ -644,13 +673,15 @@ namespace C public async Task NameAttributeValue(TestHost testHost) { await TestAsync( -@"class Program -{ - /// - void Goo(int x) - { - } -}", + """ + class Program + { + /// + void Goo(int x) + { + } + } + """, testHost, Keyword("class"), Class("Program"), @@ -664,9 +695,13 @@ void Goo(int x) XmlDoc.Name("param"), XmlDoc.AttributeName("name"), XmlDoc.Delimiter("="), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), Parameter("x"), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), XmlDoc.Delimiter("/>"), Keyword("void"), Method("Goo"), @@ -683,13 +718,15 @@ void Goo(int x) public async Task Cref1(TestHost testHost) { await TestAsync( -@"/// -class Program -{ - void Goo() - { - } -}", + """ + /// + class Program + { + void Goo() + { + } + } + """, testHost, XmlDoc.Delimiter("///"), XmlDoc.Text(" "), @@ -697,12 +734,16 @@ void Goo() XmlDoc.Name("see"), XmlDoc.AttributeName("cref"), XmlDoc.Delimiter("="), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), Class("Program"), Punctuation.OpenCurly, TypeParameter("T"), Punctuation.CloseCurly, - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), XmlDoc.Delimiter("/>"), Keyword("class"), Class("Program"), @@ -723,13 +764,15 @@ void Goo() public async Task CrefNamespaceIsNotClass(TestHost testHost) { await TestAsync( -@"/// -namespace N -{ - class Program - { - } -}", + """ + /// + namespace N + { + class Program + { + } + } + """, testHost, XmlDoc.Delimiter("///"), XmlDoc.Text(" "), @@ -737,9 +780,13 @@ class Program XmlDoc.Name("see"), XmlDoc.AttributeName("cref"), XmlDoc.Delimiter("="), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), Namespace("N"), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), XmlDoc.Delimiter("/>"), Keyword("namespace"), Namespace("N"), @@ -755,12 +802,14 @@ class Program public async Task InterfacePropertyWithSameNameShouldBePreferredToType(TestHost testHost) { await TestAsync( -@"interface IGoo -{ - int IGoo { get; set; } + """ + interface IGoo + { + int IGoo { get; set; } - void Bar(int x = IGoo); -}", + void Bar(int x = IGoo); + } + """, testHost, Keyword("interface"), Interface("IGoo"), @@ -790,15 +839,17 @@ await TestAsync( public async Task XmlDocCref(TestHost testHost) { await TestAsync( -@"/// -/// -/// -class MyClass -{ - public MyClass(int x) - { - } -}", + """ + /// + /// + /// + class MyClass + { + public MyClass(int x) + { + } + } + """, testHost, XmlDoc.Delimiter("///"), XmlDoc.Text(" "), @@ -811,14 +862,18 @@ public MyClass(int x) XmlDoc.Name("see"), XmlDoc.AttributeName("cref"), XmlDoc.Delimiter("="), - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), Class("MyClass"), Operators.Dot, Class("MyClass"), Punctuation.OpenParen, Keyword("int"), Punctuation.CloseParen, - XmlDoc.AttributeQuotes("\""), + XmlDoc.AttributeQuotes(""" + " + """), XmlDoc.Delimiter("/>"), XmlDoc.Delimiter("///"), XmlDoc.Text(" "), @@ -843,12 +898,13 @@ public MyClass(int x) public async Task TestGenericTypeWithNoArity(TestHost testHost) { await TestAsync( -@" -using System.Collections.Generic; + """ + using System.Collections.Generic; -class Program : IReadOnlyCollection -{ -}", + class Program : IReadOnlyCollection + { + } + """, testHost, Keyword("using"), Namespace("System"), @@ -869,12 +925,13 @@ class Program : IReadOnlyCollection public async Task TestGenericTypeWithWrongArity(TestHost testHost) { await TestAsync( -@" -using System.Collections.Generic; + """ + using System.Collections.Generic; -class Program : IReadOnlyCollection -{ -}", + class Program : IReadOnlyCollection + { + } + """, testHost, Keyword("using"), Namespace("System"), @@ -900,13 +957,14 @@ class Program : IReadOnlyCollection public async Task TestExtensionMethodDeclaration(TestHost testHost) { await TestAsync( -@"static class ExtMethod -{ - public static void TestMethod(this C c) - { - } -} -", + """ + static class ExtMethod + { + public static void TestMethod(this C c) + { + } + } + """, testHost, Keyword("static"), Keyword("class"), @@ -932,22 +990,23 @@ public static void TestMethod(this C c) public async Task TestExtensionMethodUsage(TestHost testHost) { await TestAsync( -@"static class ExtMethod -{ - public static void TestMethod(this C c) - { - } -} + """ + static class ExtMethod + { + public static void TestMethod(this C c) + { + } + } -class C -{ - void Test() - { - ExtMethod.TestMethod(new C()); - new C().TestMethod(); - } -} -", + class C + { + void Test() + { + ExtMethod.TestMethod(new C()); + new C().TestMethod(); + } + } + """, testHost, ParseOptions(Options.Regular), Keyword("static"), @@ -1005,8 +1064,10 @@ void Test() public async Task TestConstLocals(TestHost testHost) { await TestInMethodAsync( -@"const int Number = 42; -var x = Number;", + """ + const int Number = 42; + var x = Number; + """, testHost, Keyword("const"), Keyword("int"), @@ -1025,9 +1086,10 @@ await TestInMethodAsync( [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_InsideMethod(TestHost testHost) { - await TestInMethodAsync(@" -var unmanaged = 0; -unmanaged++;", + await TestInMethodAsync(""" + var unmanaged = 0; + unmanaged++; + """, testHost, Keyword("var"), Local("unmanaged"), @@ -1061,9 +1123,10 @@ await TestAsync( [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Type_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface unmanaged {} -class X where T : unmanaged { }", + await TestAsync(""" + interface unmanaged {} + class X where T : unmanaged { } + """, testHost, Keyword("interface"), Interface("unmanaged"), @@ -1085,12 +1148,13 @@ class X where T : unmanaged { }", [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Type_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface unmanaged {} -} -class X where T : unmanaged { }", + await TestAsync(""" + namespace OtherScope + { + interface unmanaged {} + } + class X where T : unmanaged { } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1116,11 +1180,12 @@ class X where T : unmanaged { }", [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Method_Keyword(TestHost testHost) { - await TestAsync(@" -class X -{ - void M() where T : unmanaged { } -}", + await TestAsync(""" + class X + { + void M() where T : unmanaged { } + } + """, testHost, Keyword("class"), Class("X"), @@ -1144,12 +1209,13 @@ void M() where T : unmanaged { } [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Method_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface unmanaged {} -class X -{ - void M() where T : unmanaged { } -}", + await TestAsync(""" + interface unmanaged {} + class X + { + void M() where T : unmanaged { } + } + """, testHost, Keyword("interface"), Interface("unmanaged"), @@ -1177,15 +1243,16 @@ void M() where T : unmanaged { } [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Method_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface unmanaged {} -} -class X -{ - void M() where T : unmanaged { } -}", + await TestAsync(""" + namespace OtherScope + { + interface unmanaged {} + } + class X + { + void M() where T : unmanaged { } + } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1238,9 +1305,10 @@ await TestAsync( [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Delegate_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface unmanaged {} -delegate void D() where T : unmanaged;", + await TestAsync(""" + interface unmanaged {} + delegate void D() where T : unmanaged; + """, testHost, Keyword("interface"), Interface("unmanaged"), @@ -1264,14 +1332,15 @@ interface unmanaged {} [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_Delegate_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface unmanaged {} -} -delegate void D() where T : unmanaged;", - testHost, - Keyword("namespace"), + await TestAsync(""" + namespace OtherScope + { + interface unmanaged {} + } + delegate void D() where T : unmanaged; + """, + testHost, + Keyword("namespace"), Namespace("OtherScope"), Punctuation.OpenCurly, Keyword("interface"), @@ -1297,14 +1366,15 @@ interface unmanaged {} [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_LocalFunction_Keyword(TestHost testHost) { - await TestAsync(@" -class X -{ - void N() - { - void M() where T : unmanaged { } - } -}", + await TestAsync(""" + class X + { + void N() + { + void M() where T : unmanaged { } + } + } + """, testHost, Keyword("class"), Class("X"), @@ -1334,15 +1404,16 @@ void M() where T : unmanaged { } [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_LocalFunction_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface unmanaged {} -class X -{ - void N() - { - void M() where T : unmanaged { } - } -}", + await TestAsync(""" + interface unmanaged {} + class X + { + void N() + { + void M() where T : unmanaged { } + } + } + """, testHost, Keyword("interface"), Interface("unmanaged"), @@ -1376,18 +1447,19 @@ void M() where T : unmanaged { } [Theory, CombinatorialData] public async Task TestUnmanagedConstraint_LocalFunction_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface unmanaged {} -} -class X -{ - void N() - { - void M() where T : unmanaged { } - } -}", + await TestAsync(""" + namespace OtherScope + { + interface unmanaged {} + } + class X + { + void N() + { + void M() where T : unmanaged { } + } + } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1426,22 +1498,23 @@ void M() where T : unmanaged { } [CombinatorialData] public async Task TestOperatorOverloading(TestHost testHost) { - await TestAsync(@" -class C -{ - void M() - { - var a = 1 + 1; - var b = new True() + new True(); - } -} -class True -{ - public static True operator +(True a, True b) - { - return new True(); - } -}", + await TestAsync(""" + class C + { + void M() + { + var a = 1 + 1; + var b = new True() + new True(); + } + } + class True + { + public static True operator +(True a, True b) + { + return new True(); + } + } + """, testHost, Keyword("class"), Class("C"), @@ -1502,9 +1575,10 @@ class True [Theory, CombinatorialData] public async Task TestNotNullConstraint_InsideMethod(TestHost testHost) { - await TestInMethodAsync(@" -var notnull = 0; -notnull++;", + await TestInMethodAsync(""" + var notnull = 0; + notnull++; + """, testHost, Keyword("var"), Local("notnull"), @@ -1538,9 +1612,10 @@ await TestAsync( [Theory, CombinatorialData] public async Task TestNotNullConstraint_Type_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface notnull {} -class X where T : notnull { }", + await TestAsync(""" + interface notnull {} + class X where T : notnull { } + """, testHost, Keyword("interface"), Interface("notnull"), @@ -1562,12 +1637,13 @@ class X where T : notnull { }", [Theory, CombinatorialData] public async Task TestNotNullConstraint_Type_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface notnull {} -} -class X where T : notnull { }", + await TestAsync(""" + namespace OtherScope + { + interface notnull {} + } + class X where T : notnull { } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1593,11 +1669,12 @@ class X where T : notnull { }", [Theory, CombinatorialData] public async Task TestNotNullConstraint_Method_Keyword(TestHost testHost) { - await TestAsync(@" -class X -{ - void M() where T : notnull { } -}", + await TestAsync(""" + class X + { + void M() where T : notnull { } + } + """, testHost, Keyword("class"), Class("X"), @@ -1621,12 +1698,13 @@ void M() where T : notnull { } [Theory, CombinatorialData] public async Task TestNotNullConstraint_Method_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface notnull {} -class X -{ - void M() where T : notnull { } -}", + await TestAsync(""" + interface notnull {} + class X + { + void M() where T : notnull { } + } + """, testHost, Keyword("interface"), Interface("notnull"), @@ -1654,15 +1732,16 @@ void M() where T : notnull { } [Theory, CombinatorialData] public async Task TestNotNullConstraint_Method_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface notnull {} -} -class X -{ - void M() where T : notnull { } -}", + await TestAsync(""" + namespace OtherScope + { + interface notnull {} + } + class X + { + void M() where T : notnull { } + } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1715,9 +1794,10 @@ await TestAsync( [Theory, CombinatorialData] public async Task TestNotNullConstraint_Delegate_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface notnull {} -delegate void D() where T : notnull;", + await TestAsync(""" + interface notnull {} + delegate void D() where T : notnull; + """, testHost, Keyword("interface"), Interface("notnull"), @@ -1741,12 +1821,13 @@ interface notnull {} [Theory, CombinatorialData] public async Task TestNotNullConstraint_Delegate_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface notnull {} -} -delegate void D() where T : notnull;", + await TestAsync(""" + namespace OtherScope + { + interface notnull {} + } + delegate void D() where T : notnull; + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1774,14 +1855,15 @@ interface notnull {} [Theory, CombinatorialData] public async Task TestNotNullConstraint_LocalFunction_Keyword(TestHost testHost) { - await TestAsync(@" -class X -{ - void N() - { - void M() where T : notnull { } - } -}", + await TestAsync(""" + class X + { + void N() + { + void M() where T : notnull { } + } + } + """, testHost, Keyword("class"), Class("X"), @@ -1811,15 +1893,16 @@ void M() where T : notnull { } [Theory, CombinatorialData] public async Task TestNotNullConstraint_LocalFunction_ExistingInterface(TestHost testHost) { - await TestAsync(@" -interface notnull {} -class X -{ - void N() - { - void M() where T : notnull { } - } -}", + await TestAsync(""" + interface notnull {} + class X + { + void N() + { + void M() where T : notnull { } + } + } + """, testHost, Keyword("interface"), Interface("notnull"), @@ -1853,18 +1936,19 @@ void M() where T : notnull { } [Theory, CombinatorialData] public async Task TestNotNullConstraint_LocalFunction_ExistingInterfaceButOutOfScope(TestHost testHost) { - await TestAsync(@" -namespace OtherScope -{ - interface notnull {} -} -class X -{ - void N() - { - void M() where T : notnull { } - } -}", + await TestAsync(""" + namespace OtherScope + { + interface notnull {} + } + class X + { + void N() + { + void M() where T : notnull { } + } + } + """, testHost, Keyword("namespace"), Namespace("OtherScope"), @@ -1904,21 +1988,22 @@ void M() where T : notnull { } public async Task VarInPropertyPattern(TestHost testHost) { await TestAsync( -@" -using System; + """ + using System; -class Person { public string Name; } + class Person { public string Name; } -class Program -{ - void Goo(object o) - { - if (o is Person { Name: var n }) - { - Console.WriteLine(n); - } - } -}", + class Program + { + void Goo(object o) + { + if (o is Person { Name: var n }) + { + Console.WriteLine(n); + } + } + } + """, testHost, Keyword("using"), Namespace("System"), @@ -1973,16 +2058,17 @@ void Goo(object o) public async Task NotPattern(TestHost testHost) { await TestAsync( -@" -class Person -{ - void Goo(object o) - { - if (o is not Person p) - { - } - } -}", + """ + class Person + { + void Goo(object o) + { + if (o is not Person p) + { + } + } + } + """, testHost, Keyword("class"), Class("Person"), @@ -2013,16 +2099,17 @@ void Goo(object o) public async Task OrPattern(TestHost testHost) { await TestAsync( -@" -class Person -{ - void Goo(object o) - { - if (o is Person or int) - { - } - } -}", + """ + class Person + { + void Goo(object o) + { + if (o is Person or int) + { + } + } + } + """, testHost, Keyword("class"), Class("Person"), @@ -2053,11 +2140,11 @@ void Goo(object o) public async Task TestPatternVariables(TestHost testHost) { await TestAsync( - @" -void M(object o) { - _ = o is [var (x, y), {} z] list; -} -", + """ + void M(object o) { + _ = o is [var (x, y), {} z] list; + } + """, testHost, Keyword("void"), Method("M"), @@ -2092,16 +2179,17 @@ void M(object o) { public async Task RelationalPattern(TestHost testHost) { await TestAsync( -@" -class Person -{ - void Goo(object o) - { - if (o is >= 0) - { - } - } -}", + """ + class Person + { + void Goo(object o) + { + if (o is >= 0) + { + } + } + } + """, testHost, Keyword("class"), Class("Person"), @@ -2130,9 +2218,11 @@ void Goo(object o) public async Task BasicFileScopedNamespaceClassification(TestHost testHost) { await TestAsync( -@"namespace NS; + """ + namespace NS; -class C { }", + class C { } + """, testHost, Keyword("namespace"), Namespace("NS"), @@ -2151,7 +2241,9 @@ public async Task TestStringEscape(TestHost testHost) Keyword("var"), Local("goo"), Operators.Equals, - Verbatim("$@\""), + Verbatim(""" + $@" + """), Escape("{{"), Punctuation.OpenCurly, Number("12"), @@ -2159,7 +2251,9 @@ public async Task TestStringEscape(TestHost testHost) String("X"), Punctuation.CloseCurly, Escape("}}"), - Verbatim("\""), + Verbatim(""" + " + """), Punctuation.Semicolon); } @@ -2168,11 +2262,12 @@ public async Task TestStringEscape(TestHost testHost) public async Task TestStaticConstructorClass(TestHost testHost) { await TestAsync( -@" -class C -{ - static C() { } -}", + """ + class C + { + static C() { } + } + """, testHost, Keyword("class"), Class("C"), @@ -2192,11 +2287,12 @@ static C() { } public async Task TestStaticConstructorInterface(TestHost testHost) { await TestAsync( -@" -interface C -{ - static C() { } -}", + """ + interface C + { + static C() { } + } + """, testHost, Keyword("interface"), Interface("C"), @@ -2216,10 +2312,11 @@ static C() { } public async Task TestArgsInTopLevel(TestHost testHost) { await TestAsync( -@" -[|foreach (var arg in args) -{ -}|]", + """ + [|foreach (var arg in args) + { + }|] + """, testHost, parseOptions: null, ControlKeyword("foreach"), @@ -2238,16 +2335,17 @@ await TestAsync( public async Task TestArgsInNormalProgram(TestHost testHost) { await TestAsync( -@" -class Program -{ - static void Main(string[] args) - { - [|foreach (var arg in args) - { - }|] - } -}", + """ + class Program + { + static void Main(string[] args) + { + [|foreach (var arg in args) + { + }|] + } + } + """, testHost, parseOptions: null, ControlKeyword("foreach"), @@ -2266,10 +2364,12 @@ static void Main(string[] args) public async Task TestAsyncInIncompleteMember(TestHost testHost) { await TestAsync( -@"class Test -{ - public async -}", + """ + class Test + { + public async + } + """, testHost, parseOptions: null, Keyword("class"), @@ -2285,14 +2385,16 @@ public async public async Task TestAsyncInIncompleteMemberWhenAsyncTypeIsDefined(TestHost testHost) { await TestAsync( -@"[|class Test -{ - public async -}|] + """ + [|class Test + { + public async + }|] -class async -{ -}", + class async + { + } + """, testHost, parseOptions: null, Keyword("class"), @@ -2308,10 +2410,12 @@ class async public async Task TestAsyncInPotentialLocalFunctionDeclaration(TestHost testHost) { await TestAsync( -@"void M() -{ - async -}", + """ + void M() + { + async + } + """, testHost, parseOptions: null, Keyword("void"), @@ -2328,14 +2432,16 @@ await TestAsync( public async Task TestAsyncInPotentialLocalFunctionDeclarationWhenAsyncTypeIsDefined(TestHost testHost) { await TestAsync( -@"[|void M() -{ - async -}|] + """ + [|void M() + { + async + }|] -class async -{ -}", + class async + { + } + """, testHost, parseOptions: null, Keyword("void"), @@ -2352,13 +2458,15 @@ class async public async Task TestAsyncAsLocalMemberType_NoAsyncInScope(TestHost testHost) { await TestAsync( -@"class Test -{ - void M() - { - [|async a;|] - } -}", + """ + class Test + { + void M() + { + [|async a;|] + } + } + """, testHost, parseOptions: null, Keyword("async"), @@ -2371,16 +2479,17 @@ void M() public async Task TestAsyncAsLocalMemberType_AsyncInScope(TestHost testHost) { await TestAsync( -@" -class async { } + """ + class async { } -class Test -{ - void M() - { - [|async a;|] - } -}", + class Test + { + void M() + { + [|async a;|] + } + } + """, testHost, parseOptions: null, Class("async"), @@ -2393,10 +2502,12 @@ void M() public async Task TestAsyncAsPropertyType_NoAsyncInScope(TestHost testHost) { await TestAsync( -@"class Test -{ - [|public async Prop { get; set; }|] -}", + """ + class Test + { + [|public async Prop { get; set; }|] + } + """, testHost, parseOptions: null, Keyword("public"), @@ -2415,13 +2526,14 @@ await TestAsync( public async Task TestAsyncAsPropertyType_AsyncInScope(TestHost testHost) { await TestAsync( -@" -class async { } + """ + class async { } -class Test -{ - [|public async Prop { get; set; }|] -}", + class Test + { + [|public async Prop { get; set; }|] + } + """, testHost, parseOptions: null, Keyword("public"), @@ -2440,10 +2552,12 @@ class Test public async Task TestAsyncAsMethodReturnType_NoAsyncInScope(TestHost testHost) { await TestAsync( -@"class Test -{ - [|public async M()|] {} -}", + """ + class Test + { + [|public async M()|] {} + } + """, testHost, parseOptions: null, Keyword("public"), @@ -2458,13 +2572,14 @@ await TestAsync( public async Task TestAsyncAsMethodReturnType_AsyncInScope(TestHost testHost) { await TestAsync( -@" -class async { } + """ + class async { } -class Test -{ - [|public async M()|] {} -}", + class Test + { + [|public async M()|] {} + } + """, testHost, parseOptions: null, Keyword("public"), @@ -2479,18 +2594,20 @@ class Test public async Task TestAsyncAsAccessingName(TestHost testHost) { await TestAsync( -@"class Test -{ - void M() - { - var a = [|C.async;|] - } -} + """ + class Test + { + void M() + { + var a = [|C.async;|] + } + } -class C -{ - public static int async; -}", + class C + { + public static int async; + } + """, testHost, parseOptions: null, Class("C"), @@ -2505,14 +2622,16 @@ class C public async Task TestAsyncInIncompleteDelegateOrLambda(TestHost testHost) { await TestAsync( -@"using System; -class Test -{ - void M() - { - [|Action a = async |] - } -}", + """ + using System; + class Test + { + void M() + { + [|Action a = async |] + } + } + """, testHost, parseOptions: null, Delegate("Action"), diff --git a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests_Dynamic.cs b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests_Dynamic.cs index f6d83ba30890a..2db25fc29802e 100644 --- a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests_Dynamic.cs +++ b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests_Dynamic.cs @@ -150,12 +150,14 @@ await TestAsync( public async Task DynamicAsExternAlias(TestHost testHost) { await TestAsync( -@"extern alias dynamic; - -class C -{ - dynamic::Goo a; -}", + """ + extern alias dynamic; + + class C + { + dynamic::Goo a; + } + """, testHost, Keyword("extern"), Keyword("alias"), @@ -202,11 +204,13 @@ await TestAsync(@"delegate dynamic MyDelegate (dynamic d)", public async Task DynamicAsDelegateLocalVariable(TestHost testHost) { await TestInMethodAsync( -@"Func f = delegate -{ - int dynamic = 10; - return dynamic.ToString(); -};", + """ + Func f = delegate + { + int dynamic = 10; + return dynamic.ToString(); + }; + """, testHost, Identifier("Func"), Punctuation.OpenAngle, @@ -236,14 +240,16 @@ await TestInMethodAsync( public async Task DynamicAsGenericTypeName(TestHost testHost) { await TestAsync( -@"partial class dynamic -{ -} - -class C -{ - dynamic d; -}", + """ + partial class dynamic + { + } + + class C + { + dynamic d; + } + """, testHost, Keyword("partial"), Keyword("class"), @@ -269,10 +275,12 @@ class C public async Task DynamicAsGenericField(TestHost testHost) { await TestAsync( -@"class A -{ - T dynamic; -}", + """ + class A + { + T dynamic; + } + """, testHost, Keyword("class"), Class("A"), @@ -372,8 +380,10 @@ await TestInMethodAsync(@"var v = from dynamic in names", public async Task DynamicAsAnonymousTypePropertyName(TestHost testHost) { await TestInMethodAsync( -@"var v = from dynamic in names - select new { dynamic = dynamic };", + """ + var v = from dynamic in names + select new { dynamic = dynamic }; + """, testHost, Keyword("var"), Local("v"), @@ -418,11 +428,13 @@ await TestInMethodAsync( public async Task DynamicAsAnonymousMethodLocalVariable(TestHost testHost) { await TestInMethodAsync( -@"D f = delegate -{ - string dynamic = ""a""; - return dynamic.Length; -};", + """ + D f = delegate + { + string dynamic = "a"; + return dynamic.Length; + }; + """, testHost, Identifier("D"), Local("f"), @@ -432,7 +444,9 @@ await TestInMethodAsync( Keyword("string"), Local("dynamic"), Operators.Equals, - String(@"""a"""), + String(""" + "a" + """), Punctuation.Semicolon, ControlKeyword("return"), Local("dynamic"), @@ -447,9 +461,11 @@ await TestInMethodAsync( public async Task DynamicAsMethodName(TestHost testHost) { await TestInClassAsync( -@"dynamic dynamic() -{ -}", + """ + dynamic dynamic() + { + } + """, testHost, Keyword("dynamic"), Method("dynamic"), @@ -463,9 +479,11 @@ await TestInClassAsync( public async Task DynamicAsStaticMethodTypeAndParams(TestHost testHost) { await TestInClassAsync( -@"static dynamic dynamic(params dynamic[] dynamic) -{ -}", + """ + static dynamic dynamic(params dynamic[] dynamic) + { + } + """, testHost, Keyword("static"), Keyword("dynamic"), @@ -486,9 +504,11 @@ await TestInClassAsync( public async Task DynamicArraysInMethodSignature(TestHost testHost) { await TestInClassAsync( -@"dynamic[] M(dynamic[] p, params dynamic[] pa) -{ -}", + """ + dynamic[] M(dynamic[] p, params dynamic[] pa) + { + } + """, testHost, Keyword("dynamic"), Punctuation.OpenBracket, @@ -514,11 +534,13 @@ await TestInClassAsync( public async Task DynamicInPartialMethods(TestHost testHost) { await TestInClassAsync( -@"partial void F(dynamic d); + """ + partial void F(dynamic d); -partial void F(dynamic d) -{ -}", + partial void F(dynamic d) + { + } + """, testHost, Keyword("partial"), Keyword("void"), @@ -543,9 +565,11 @@ partial void F(dynamic d) public async Task DynamicRefAndOutParameters(TestHost testHost) { await TestInClassAsync( -@"void F(ref dynamic r, out dynamic o) -{ -}", + """ + void F(ref dynamic r, out dynamic o) + { + } + """, testHost, Keyword("void"), Method("F"), @@ -566,9 +590,11 @@ await TestInClassAsync( public async Task DynamicInExtensionMethod(TestHost testHost) { await TestInClassAsync( -@"dynamic F(this dynamic self, dynamic p) -{ -}", + """ + dynamic F(this dynamic self, dynamic p) + { + } + """, testHost, Keyword("dynamic"), ExtensionMethod("F"), @@ -588,9 +614,11 @@ await TestInClassAsync( public async Task DynamicAsBaseClass(TestHost testHost) { await TestAsync( -@"class C : dynamic -{ -}", + """ + class C : dynamic + { + } + """, testHost, Keyword("class"), Class("C"), @@ -604,9 +632,11 @@ await TestAsync( public async Task DynamicAsGenericConstraint(TestHost testHost) { await TestAsync( -@"class C where T : dynamic -{ -}", + """ + class C where T : dynamic + { + } + """, testHost, Keyword("class"), Class("C"), @@ -625,10 +655,12 @@ await TestAsync( public async Task DynamicSizeOf(TestHost testHost) { await TestInClassAsync( -@"unsafe int M() -{ - return sizeof(dynamic); -}", + """ + unsafe int M() + { + return sizeof(dynamic); + } + """, testHost, Keyword("unsafe"), Keyword("int"), @@ -661,9 +693,11 @@ await TestInMethodAsync(@"typeof(dynamic)", public async Task DynamicAsArrayName(bool script, TestHost testHost) { var code = -@"int[] dynamic = { - 1 -};"; + """ + int[] dynamic = { + 1 + }; + """; var parseOptions = script ? Options.Script : null; @@ -722,9 +756,11 @@ await TestInMethodAsync( public async Task DynamicAsNamespaceName(TestHost testHost) { await TestAsync( -@"namespace dynamic -{ -}", + """ + namespace dynamic + { + } + """, testHost, Keyword("namespace"), Namespace("dynamic"), @@ -736,9 +772,11 @@ await TestAsync( public async Task DynamicAsClassName(TestHost testHost) { await TestAsync( -@"class dynamic -{ -}", + """ + class dynamic + { + } + """, testHost, Keyword("class"), Class("dynamic"), @@ -750,12 +788,14 @@ await TestAsync( public async Task DynamicAsConstructorDeclarationName(TestHost testHost) { await TestAsync( -@"class dynamic -{ - dynamic() - { - } -}", + """ + class dynamic + { + dynamic() + { + } + } + """, testHost, Keyword("class"), Class("dynamic"), @@ -785,8 +825,10 @@ await TestInMethodAsync( public async Task DynamicAsGotoLabel(TestHost testHost) { await TestInMethodAsync( -@"dynamic: int i = 0; - goto dynamic;", + """ + dynamic: int i = 0; + goto dynamic; + """, testHost, Label("dynamic"), Punctuation.Colon, @@ -819,10 +861,12 @@ await TestInMethodAsync( public async Task DynamicAsEnumFieldDefinition(TestHost testHost) { await TestAsync( -@"enum A -{ - dynamic -}", + """ + enum A + { + dynamic + } + """, testHost, Keyword("enum"), Enum("A"), @@ -835,9 +879,11 @@ await TestAsync( public async Task DynamicAsEnumType(TestHost testHost) { await TestAsync( -@"enum dynamic -{ -}", + """ + enum dynamic + { + } + """, testHost, Keyword("enum"), Enum("dynamic"), @@ -849,10 +895,12 @@ await TestAsync( public async Task DynamicAsGenericTypeParameter(TestHost testHost) { await TestAsync( -@"class C where dynamic : T -{ - dynamic d; -}", + """ + class C where dynamic : T + { + dynamic d; + } + """, testHost, Keyword("class"), Class("C"), @@ -1037,8 +1085,10 @@ await TestInMethodAsync( public async Task DynamicAsRegionLabel(TestHost testHost) { var code = -@"#region dynamic -#endregion"; + """ + #region dynamic + #endregion + """; await TestAsync(code, testHost, PPKeyword("#"), @@ -1052,9 +1102,11 @@ await TestAsync(code, public async Task DynamicAsInterfaceType(TestHost testHost) { await TestAsync( -@"interface dynamic -{ -}", + """ + interface dynamic + { + } + """, testHost, Keyword("interface"), Interface("dynamic"), @@ -1066,9 +1118,11 @@ await TestAsync( public async Task DynamicAsStructType(TestHost testHost) { await TestAsync( -@"struct dynamic -{ -}", + """ + struct dynamic + { + } + """, testHost, Keyword("struct"), Struct("dynamic"), diff --git a/src/EditorFeatures/CSharpTest/CodeLens/CSharpCodeLensTests.cs b/src/EditorFeatures/CSharpTest/CodeLens/CSharpCodeLensTests.cs index 09de42bba2244..a4aebcb13dbcb 100644 --- a/src/EditorFeatures/CSharpTest/CodeLens/CSharpCodeLensTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeLens/CSharpCodeLensTests.cs @@ -18,60 +18,64 @@ public sealed class CSharpCodeLensTests : AbstractCodeLensTest [Fact] public async Task TestCount() { - const string input = @" - - + + - - -"; + {|1: public void D() + { + C(); + }|} + } + ]]> + + + + """; await RunCountTest(input); } [Fact] public async Task TestCapping() { - const string input = @" - - + + - - -"; + {|1: public void D() + { + C(); + }|} + } + ]]> + + + + """; await RunCountTest(input, 1); } @@ -79,45 +83,47 @@ public class A [Fact] public async Task TestLinkedFiles() { - const string input = @" - - + + - - - - - - - -"; + {|3: public void D() + { + C(); + }|} + } + ]]> + + + + + + + + + """; await RunReferenceTest(input); } @@ -125,30 +131,32 @@ void F() [Fact] public async Task TestDisplay() { - const string input = @" - - + + - - -"; + {|1: public void D() + { + C(); + }|} + } + ]]> + + + + """; await RunReferenceTest(input); } @@ -156,63 +164,67 @@ public class A [Fact] public async Task TestMethodReferences() { - const string input = @" - - + + - - -"; + {|1: public void D() + { + C(); + }|} + } + ]]> + + + + """; await RunMethodReferenceTest(input); } [Fact] public async Task TestMethodReferencesWithDocstrings() { - const string input = @" - - - /// - /// - {|0: public void B() - { - C(); - }|} + const string input = """ + + + + /// + /// + {|0: public void B() + { + C(); + }|} - {|2: public void C() - { - D(); - }|} + {|2: public void C() + { + D(); + }|} - {|1: public void D() - { - C(); - }|} -} -]]> - - -"; + {|1: public void D() + { + C(); + }|} + } + ]]> + + + + """; await RunMethodReferenceTest(input); } @@ -258,126 +270,136 @@ public async Task TestFullyQualifiedName(string typeKind) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49636")] public async Task TestExplicitParameterlessConstructor() { - const string input = @" - - - - -"; + const string input = """ + + + + + + + """; await RunReferenceTest(input); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49636")] public async Task TestExplicitParameterlessConstructor_TwoCalls() { - const string input = @" - - - - -"; + const string input = """ + + + + + + + """; await RunReferenceTest(input); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49636")] public async Task TestImplicitParameterlessConstructor() { - const string input = @" - - - - -"; + const string input = """ + + + + + + + """; await RunReferenceTest(input); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49636")] public async Task TestImplicitParameterlessConstructor_TwoCalls() { - const string input = @" - - - - -"; + const string input = """ + + + + + + + """; await RunReferenceTest(input); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51633")] public async Task TestMethodRefSourceGeneratedDocument() { - const string input = @" - - - - new Program(); - } -}]]> - - -"; + const string input = """ + + + + + new Program(); + } + }]]> + + + + """; await RunMethodReferenceTest(input); } } diff --git a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs index e601ea1669ecd..41c6193f605d8 100644 --- a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs +++ b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs @@ -27,67 +27,77 @@ public class CSharpCommentSelectionTests [WpfFact] public void UncommentAndFormat1() { - var code = @"class A -{ - [| // void Method ( ) - // { - // - // }|] -}"; - var expected = @"class A -{ - void Method() - { - - } -}"; + var code = """ + class A + { + [| // void Method ( ) + // { + // + // }|] + } + """; + var expected = """ + class A + { + void Method() + { + + } + } + """; UncommentSelection(code, expected); } [WpfFact] public void UncommentAndFormat2() { - var code = @"class A -{ - [| /* void Method ( ) - { - - } */|] -}"; - var expected = @"class A -{ - void Method() - { - - } -}"; + var code = """ + class A + { + [| /* void Method ( ) + { + + } */|] + } + """; + var expected = """ + class A + { + void Method() + { + + } + } + """; UncommentSelection(code, expected); } [WpfFact] public void UncommentSingleLineCommentInPseudoBlockComment() { - var code = @" -class C -{ - /// - protected void RtlTranslateAlignment2() - { - //[|int x = 0;|] - } - /* Hello world */ -}"; - - var expected = @" -class C -{ - /// - protected void RtlTranslateAlignment2() - { - int x = 0; - } - /* Hello world */ -}"; + var code = """ + class C + { + /// + protected void RtlTranslateAlignment2() + { + //[|int x = 0;|] + } + /* Hello world */ + } + """; + + var expected = """ + class C + { + /// + protected void RtlTranslateAlignment2() + { + int x = 0; + } + /* Hello world */ + } + """; UncommentSelection(code, expected); } @@ -95,20 +105,24 @@ protected void RtlTranslateAlignment2() [WpfFact] public void UncommentAndFormat3() { - var code = @"class A -{ - [| // void Method ( ) |] - [| // { |] - [| // |] - [| // } |] -}"; - var expected = @"class A -{ - void Method() - { - - } -}"; + var code = """ + class A + { + [| // void Method ( ) |] + [| // { |] + [| // |] + [| // } |] + } + """; + var expected = """ + class A + { + void Method() + { + + } + } + """; UncommentSelection(code, expected); } diff --git a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleBlockCommentCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleBlockCommentCommandHandlerTests.cs index e45b31f51a9f8..43cbdff7f755a 100644 --- a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleBlockCommentCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleBlockCommentCommandHandlerTests.cs @@ -26,27 +26,29 @@ public class CSharpToggleBlockCommentCommandHandlerTests : AbstractToggleComment public void AddComment_CommentMarkerStringBeforeSelection() { var markup = -@" -class C -{ - void M() - { - string s = '/*'; - [|var j = 2; - var k = 3;|] - } -}"; + """ + class C + { + void M() + { + string s = '/*'; + [|var j = 2; + var k = 3;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - string s = '/*'; - [|/*var j = 2; - var k = 3;*/|] - } -}"; + """ + class C + { + void M() + { + string s = '/*'; + [|/*var j = 2; + var k = 3;*/|] + } + } + """; ToggleComment(markup, expected); } @@ -55,31 +57,33 @@ void M() public void AddComment_DirectiveWithCommentInsideSelection() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; -#if false - /*var j = 2;*/ -#endif - var k = 3;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + #if false + /*var j = 2;*/ + #endif + var k = 3;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|/*var i = 1; -#if false - /*var j = 2;*/ -#endif - var k = 3;*/|] - } -}"; + """ + class C + { + void M() + { + [|/*var i = 1; + #if false + /*var j = 2;*/ + #endif + var k = 3;*/|] + } + } + """; ToggleComment(markup, expected); } @@ -88,27 +92,29 @@ void M() public void AddComment_MarkerInsideSelection() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; - string s = '/*'; - var k = 3;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + string s = '/*'; + var k = 3;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|/*var i = 1; - string s = '/*'; - var k = 3;*/|] - } -}"; + """ + class C + { + void M() + { + [|/*var i = 1; + string s = '/*'; + var k = 3;*/|] + } + } + """; ToggleComment(markup, expected); } @@ -117,27 +123,29 @@ void M() public void AddComment_CloseCommentMarkerStringInSelection() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; - string s = '*/'; - var k = 3;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + string s = '*/'; + var k = 3;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|/*var i = 1; - string s = '*/'; - var k = 3;*/|] - } -}"; + """ + class C + { + void M() + { + [|/*var i = 1; + string s = '*/'; + var k = 3;*/|] + } + } + """; ToggleComment(markup, expected); } @@ -146,27 +154,29 @@ void M() public void AddComment_CommentMarkerStringAfterSelection() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; - var j = 2;|] - string s = '*/'; - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + var j = 2;|] + string s = '*/'; + } + } + """; var expected = -@" -class C -{ - void M() - { - [|/*var i = 1; - var j = 2;*/|] - string s = '*/'; - } -}"; + """ + class C + { + void M() + { + [|/*var i = 1; + var j = 2;*/|] + string s = '*/'; + } + } + """; ToggleComment(markup, expected); } @@ -175,29 +185,31 @@ void M() public void RemoveComment_CommentMarkerStringNearSelection() { var markup = -@" -class C -{ - void M() - { - string s = '/*'; - [|/*var i = 1; - var j = 2; - var k = 3;*/|] - } -}"; + """ + class C + { + void M() + { + string s = '/*'; + [|/*var i = 1; + var j = 2; + var k = 3;*/|] + } + } + """; var expected = -@" -class C -{ - void M() - { - string s = '/*'; - [|var i = 1; - var j = 2; - var k = 3;|] - } -}"; + """ + class C + { + void M() + { + string s = '/*'; + [|var i = 1; + var j = 2; + var k = 3;|] + } + } + """; ToggleComment(markup, expected); } @@ -206,23 +218,25 @@ void M() public void RemoveComment_CommentMarkerStringInSelection() { var markup = -@" -class C -{ - void M() - { - [|/*string s = '/*';*/|] - } -}"; + """ + class C + { + void M() + { + [|/*string s = '/*';*/|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|string s = '/*';|] - } -}"; + """ + class C + { + void M() + { + [|string s = '/*';|] + } + } + """; ToggleComment(markup, expected); } diff --git a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleLineCommentCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleLineCommentCommandHandlerTests.cs index 6135d1e1415d1..1e464f72aab28 100644 --- a/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleLineCommentCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/CommentSelection/CSharpToggleLineCommentCommandHandlerTests.cs @@ -43,23 +43,25 @@ public void AddComment_EmptySelection() public void AddComment_CaretInUncommentedLine() { var markup = -@" -class C -{ - void M() - { - var$$ i = 1; - } -}"; + """ + class C + { + void M() + { + var$$ i = 1; + } + } + """; var expected = -@" -class C -{ - void M() - { - //var[||] i = 1; - } -}"; + """ + class C + { + void M() + { + //var[||] i = 1; + } + } + """; ToggleComment(markup, expected); } @@ -68,23 +70,25 @@ void M() public void AddComment_CaretBeforeUncommentedLine() { var markup = -@" -class C -{ - void M() - { -$$ var i = 1; - } -}"; + """ + class C + { + void M() + { + $$ var i = 1; + } + } + """; var expected = -@" -class C -{ - void M() - { -[||] //var i = 1; - } -}"; + """ + class C + { + void M() + { + [||] //var i = 1; + } + } + """; ToggleComment(markup, expected); } @@ -93,23 +97,25 @@ void M() public void AddComment_SingleLineSelected() { var markup = -@" -class C -{ - void M() - { - [|var i = 1;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//var i = 1;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1;|] + } + } + """; ToggleComment(markup, expected); } @@ -118,23 +124,25 @@ void M() public void AddComment_PartialSingleLineSelected() { var markup = -@" -class C -{ - void M() - { - var [|i = 1;|] - } -}"; + """ + class C + { + void M() + { + var [|i = 1;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - //var [|i = 1;|] - } -}"; + """ + class C + { + void M() + { + //var [|i = 1;|] + } + } + """; ToggleComment(markup, expected); } @@ -143,27 +151,29 @@ void M() public void AddComment_SingleLineWithWhitespaceSelected() { var markup = -@" -class C -{ - void M() - { -[| - var i = 1; - |] - } -}"; + """ + class C + { + void M() + { + [| + var i = 1; + |] + } + } + """; var expected = -@" -class C -{ - void M() - { -[| - //var i = 1; - |] - } -}"; + """ + class C + { + void M() + { + [| + //var i = 1; + |] + } + } + """; ToggleComment(markup, expected); } @@ -172,23 +182,25 @@ void M() public void AddComment_SelectionInsideCommentAtEndOfLine() { var markup = -@" -class C -{ - void M() - { - var i = 1; // A [|comment|]. - } -}"; + """ + class C + { + void M() + { + var i = 1; // A [|comment|]. + } + } + """; var expected = -@" -class C -{ - void M() - { - //var i = 1; // A [|comment|]. - } -}"; + """ + class C + { + void M() + { + //var i = 1; // A [|comment|]. + } + } + """; ToggleComment(markup, expected); } @@ -197,23 +209,25 @@ void M() public void AddComment_SelectionAroundCommentAtEndOfLine() { var markup = -@" -class C -{ - void M() - { - var i = 1; [|// A comment.|] - } -}"; + """ + class C + { + void M() + { + var i = 1; [|// A comment.|] + } + } + """; var expected = -@" -class C -{ - void M() - { - //var i = 1; [|// A comment.|] - } -}"; + """ + class C + { + void M() + { + //var i = 1; [|// A comment.|] + } + } + """; ToggleComment(markup, expected); } @@ -222,23 +236,25 @@ void M() public void AddComment_SelectionOutsideCommentAtEndOfLine() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; // A comment.|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; // A comment.|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//var i = 1; // A comment.|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; // A comment.|] + } + } + """; ToggleComment(markup, expected); } @@ -247,23 +263,25 @@ void M() public void AddComment_CaretOutsideCommentAtEndOfLine() { var markup = -@" -class C -{ - void M() - { - var $$i = 1; // A comment. - } -}"; + """ + class C + { + void M() + { + var $$i = 1; // A comment. + } + } + """; var expected = -@" -class C -{ - void M() - { - //var [||]i = 1; // A comment. - } -}"; + """ + class C + { + void M() + { + //var [||]i = 1; // A comment. + } + } + """; ToggleComment(markup, expected); } @@ -272,23 +290,25 @@ void M() public void AddComment_CaretInsideCommentAtEndOfLine() { var markup = -@" -class C -{ - void M() - { - var i = 1; // A $$comment. - } -}"; + """ + class C + { + void M() + { + var i = 1; // A $$comment. + } + } + """; var expected = -@" -class C -{ - void M() - { - //var i = 1; // A [||]comment. - } -}"; + """ + class C + { + void M() + { + //var i = 1; // A [||]comment. + } + } + """; ToggleComment(markup, expected); } @@ -297,23 +317,25 @@ void M() public void AddComment_CommentMarkerInString() { var markup = -@" -class C -{ - void M() - { - [|string s = '\\';|] - } -}"; + """ + class C + { + void M() + { + [|string s = '\\';|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//string s = '\\';|] - } -}"; + """ + class C + { + void M() + { + [|//string s = '\\';|] + } + } + """; ToggleComment(markup, expected); } @@ -322,25 +344,27 @@ void M() public void AddComment_MultipleLinesSelected() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//var i = 1; - //var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; + //var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -349,31 +373,33 @@ void M() public void AddComment_MultipleLinesWithWhitespaceSelected() { var markup = -@" -class C -{ - void M() - { -[| - var i = 1; - - var j = 2; - |] - } -}"; + """ + class C + { + void M() + { + [| + var i = 1; + + var j = 2; + |] + } + } + """; var expected = -@" -class C -{ - void M() - { -[| - //var i = 1; - - //var j = 2; - |] - } -}"; + """ + class C + { + void M() + { + [| + //var i = 1; + + //var j = 2; + |] + } + } + """; ToggleComment(markup, expected); } @@ -382,25 +408,27 @@ void M() public void AddComment_MultipleLinesPartiallyCommentedSelected() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1; - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; + var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|////var i = 1; - //var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|////var i = 1; + //var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -409,25 +437,27 @@ void M() public void AddComment_MultipleLinesWithCommentsInLineSelected() { var markup = -@" -class C -{ - void M() - { - [|var i = 1; // A comment. - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; // A comment. + var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//var i = 1; // A comment. - //var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; // A comment. + //var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -436,27 +466,29 @@ void M() public void AddComment_MultipleLinesWithDifferentIndentationsSelected() { var markup = -@" -class C -{ -[| void M() - { - var i = 1; - - var j = 2; - }|] -}"; + """ + class C + { + [| void M() + { + var i = 1; + + var j = 2; + }|] + } + """; var expected = -@" -class C -{ -[| //void M() - //{ - // var i = 1; - - // var j = 2; - //}|] -}"; + """ + class C + { + [| //void M() + //{ + // var i = 1; + + // var j = 2; + //}|] + } + """; ToggleComment(markup, expected); } @@ -465,25 +497,27 @@ class C public void AddComment_MultiCaret() { var markup = -@" -class C -{ - void M() - { - var [||]i = 1; - var [||]j = 2; - } -}"; + """ + class C + { + void M() + { + var [||]i = 1; + var [||]j = 2; + } + } + """; var expected = -@" -class C -{ - void M() - { - //var [||]i = 1; - //var [||]j = 2; - } -}"; + """ + class C + { + void M() + { + //var [||]i = 1; + //var [||]j = 2; + } + } + """; ToggleComment(markup, expected); } @@ -492,25 +526,27 @@ void M() public void AddComment_MultiSeletion() { var markup = -@" -class C -{ - void M() - { - [|var i = 1;|] - [|var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1;|] + [|var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|//var i = 1;|] - [|//var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1;|] + [|//var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -519,25 +555,27 @@ void M() public void AddComment_MultiSeletionPartiallyCommented() { var markup = -@" -class C -{ - void M() - { - [|//var i = |]1; - [|var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = |]1; + [|var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|////var i = |]1; - [|//var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|////var i = |]1; + [|//var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -547,22 +585,25 @@ public void AddComment_WithProjectionBuffer() { var surfaceMarkup = @"< html >@{|S1:|}"; var csharpMarkup = -@" -{|S1:class C -{ - void M() - { - [|var i = 1;|] - } -}|}"; + """ + {|S1:class C + { + void M() + { + [|var i = 1;|] + } + }|} + """; var expected = -@"< html >@class C -{ - void M() - { - [|//var i = 1;|] - } -}"; + """ + < html >@class C + { + void M() + { + [|//var i = 1;|] + } + } + """; ToggleCommentWithProjectionBuffer(surfaceMarkup, csharpMarkup, expected); } @@ -571,23 +612,25 @@ void M() public void RemoveComment_CaretInCommentedLine() { var markup = -@" -class C -{ - void M() - { - //var$$ i = 1; - } -}"; + """ + class C + { + void M() + { + //var$$ i = 1; + } + } + """; var expected = -@" -class C -{ - void M() - { - var[||] i = 1; - } -}"; + """ + class C + { + void M() + { + var[||] i = 1; + } + } + """; ToggleComment(markup, expected); } @@ -596,23 +639,25 @@ void M() public void RemoveComment_CaretBeforeCommentedLine() { var markup = -@" -class C -{ - void M() - { - $$ //var i = 1; - } -}"; + """ + class C + { + void M() + { + $$ //var i = 1; + } + } + """; var expected = -@" -class C -{ - void M() - { - [||] var i = 1; - } -}"; + """ + class C + { + void M() + { + [||] var i = 1; + } + } + """; ToggleComment(markup, expected); } @@ -621,23 +666,25 @@ void M() public void RemoveComment_CaretInCommentedLineWithEndComment() { var markup = -@" -class C -{ - void M() - { - //var i = 1; // A $$comment. - } -}"; + """ + class C + { + void M() + { + //var i = 1; // A $$comment. + } + } + """; var expected = -@" -class C -{ - void M() - { - var i = 1; // A [||]comment. - } -}"; + """ + class C + { + void M() + { + var i = 1; // A [||]comment. + } + } + """; ToggleComment(markup, expected); } @@ -646,23 +693,25 @@ void M() public void RemoveComment_CaretInDoubleCommentedLine() { var markup = -@" -class C -{ - void M() - { - ////var$$ i = 1; - } -}"; + """ + class C + { + void M() + { + ////var$$ i = 1; + } + } + """; var expected = -@" -class C -{ - void M() - { - //var[||] i = 1; - } -}"; + """ + class C + { + void M() + { + //var[||] i = 1; + } + } + """; ToggleComment(markup, expected); } @@ -671,23 +720,25 @@ void M() public void RemoveComment_CommentedLineSelected() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|var i = 1;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1;|] + } + } + """; ToggleComment(markup, expected); } @@ -696,23 +747,25 @@ void M() public void RemoveComment_InsideCommentSelected() { var markup = -@" -class C -{ - void M() - { - //var [|i = 1;|] - } -}"; + """ + class C + { + void M() + { + //var [|i = 1;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - var [|i = 1;|] - } -}"; + """ + class C + { + void M() + { + var [|i = 1;|] + } + } + """; ToggleComment(markup, expected); } @@ -721,27 +774,29 @@ void M() public void RemoveComment_CommentedLineWithWhitespaceSelected() { var markup = -@" -class C -{ - void M() - { -[| - //var i = 1; - |] - } -}"; + """ + class C + { + void M() + { + [| + //var i = 1; + |] + } + } + """; var expected = -@" -class C -{ - void M() - { -[| - var i = 1; -|] - } -}"; + """ + class C + { + void M() + { + [| + var i = 1; + |] + } + } + """; ToggleComment(markup, expected); } @@ -750,23 +805,25 @@ void M() public void RemoveComment_CommentMarkerInString() { var markup = -@" -class C -{ - void M() - { - [|//string s = '\\';|] - } -}"; + """ + class C + { + void M() + { + [|//string s = '\\';|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|string s = '\\';|] - } -}"; + """ + class C + { + void M() + { + [|string s = '\\';|] + } + } + """; ToggleComment(markup, expected); } @@ -775,25 +832,27 @@ void M() public void RemoveComment_MultipleCommentedLinesSelected() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1; - //var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; + //var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|var i = 1; - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; + var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -802,31 +861,33 @@ void M() public void RemoveComment_MultipleCommentedLinesAndWhitespaceSelected() { var markup = -@" -class C -{ - void M() - { -[| - //var i = 1; - - //var j = 2; - |] - } -}"; + """ + class C + { + void M() + { + [| + //var i = 1; + + //var j = 2; + |] + } + } + """; var expected = -@" -class C -{ - void M() - { -[| - var i = 1; - - var j = 2; -|] - } -}"; + """ + class C + { + void M() + { + [| + var i = 1; + + var j = 2; + |] + } + } + """; ToggleComment(markup, expected); } @@ -835,25 +896,27 @@ void M() public void RemoveComment_MultipleCommentedLinesWithEndCommentSelected() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1; // A comment. - //var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; // A comment. + //var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|var i = 1; // A comment. - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1; // A comment. + var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -862,27 +925,29 @@ void M() public void RemoveComment_MultipleLinesWithDifferentIndentationsSelected() { var markup = -@" -class C -{ -[| //void M() - //{ - // var i = 1; - - // var j = 2; - //}|] -}"; + """ + class C + { + [| //void M() + //{ + // var i = 1; + + // var j = 2; + //}|] + } + """; var expected = -@" -class C -{ -[| void M() - { - var i = 1; - - var j = 2; - }|] -}"; + """ + class C + { + [| void M() + { + var i = 1; + + var j = 2; + }|] + } + """; ToggleComment(markup, expected); } @@ -891,27 +956,29 @@ class C public void RemoveComment_MultiCaret() { var markup = -@" -class C -{ - void M() - { - //var [||]i = 1; - [||] - //var [||]j = 2; - } -}"; + """ + class C + { + void M() + { + //var [||]i = 1; + [||] + //var [||]j = 2; + } + } + """; var expected = -@" -class C -{ - void M() - { - var [||]i = 1; -[||] - var [||]j = 2; - } -}"; + """ + class C + { + void M() + { + var [||]i = 1; + [||] + var [||]j = 2; + } + } + """; ToggleComment(markup, expected); } @@ -920,27 +987,29 @@ void M() public void RemoveComment_MultiSeletion() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1;|] - [| |] - [|//var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1;|] + [| |] + [|//var j = 2;|] + } + } + """; var expected = -@" -class C -{ - void M() - { - [|var i = 1;|] -[||] - [|var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|var i = 1;|] + [||] + [|var j = 2;|] + } + } + """; ToggleComment(markup, expected); } @@ -950,22 +1019,25 @@ public void RemoveComment_WithProjectionBuffer() { var surfaceMarkup = @"< html >@{|S1:|}"; var csharpMarkup = -@" -{|S1:class C -{ - void M() - { - [|//var i = 1;|] - } -}|}"; + """ + {|S1:class C + { + void M() + { + [|//var i = 1;|] + } + }|} + """; var expected = -@"< html >@class C -{ - void M() - { - [|var i = 1;|] - } -}"; + """ + < html >@class C + { + void M() + { + [|var i = 1;|] + } + } + """; ToggleCommentWithProjectionBuffer(surfaceMarkup, csharpMarkup, expected); } @@ -974,38 +1046,41 @@ void M() public void ToggleComment_MultipleLinesSelected() { var markup = -@" -class C -{ - void M() - { - [|//var i = 1; - - var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = 1; + + var j = 2;|] + } + } + """; var expected = new string[] { -@" -class C -{ - void M() - { - [|////var i = 1; - - //var j = 2;|] - } -}", -@" -class C -{ - void M() - { - [|//var i = 1; - - var j = 2;|] - } -}" + """ + class C + { + void M() + { + [|////var i = 1; + + //var j = 2;|] + } + } + """, + """ + class C + { + void M() + { + [|//var i = 1; + + var j = 2;|] + } + } + """ }; ToggleCommentMultiple(markup, expected); @@ -1015,38 +1090,41 @@ void M() public void ToggleComment_MultipleSelection() { var markup = -@" -class C -{ - void M() - { - [|//var i = |]1; -[||] - [|var j = 2;|] - } -}"; + """ + class C + { + void M() + { + [|//var i = |]1; + [||] + [|var j = 2;|] + } + } + """; var expected = new string[] { -@" -class C -{ - void M() - { - [|////var i = |]1; -[||] - [|//var j = 2;|] - } -}", -@" -class C -{ - void M() - { - [|//var i = |]1; -[||] - [|var j = 2;|] - } -}" + """ + class C + { + void M() + { + [|////var i = |]1; + [||] + [|//var j = 2;|] + } + } + """, + """ + class C + { + void M() + { + [|//var i = |]1; + [||] + [|var j = 2;|] + } + } + """ }; ToggleCommentMultiple(markup, expected); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs index 6e59bef8ac1f1..7f5753da6ae96 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs @@ -139,23 +139,25 @@ await VerifyInFrontOfCommentAsync( protected static string AddInsideMethod(string text) { return -@"class C -{ - void F() - { - " + text + -@" } -}"; + """ + class C + { + void F() + { + """ + text + + """ + } + } + """; } protected static string AddUsingDirectives(string usingDirectives, string text) { return usingDirectives + -@" - +""" -" + +""" + text; } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AttributeNamedParameterCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AttributeNamedParameterCompletionProviderTests.cs index a01333ebd1ccc..f011c53704c83 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AttributeNamedParameterCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AttributeNamedParameterCompletionProviderTests.cs @@ -24,20 +24,21 @@ internal override Type GetCompletionProviderType() [Fact] public async Task SendEnterThroughToEditorTest() { - const string markup = @" -using System; -class class1 -{ - [Test($$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } -}"; + const string markup = """ + using System; + class class1 + { + [Test($$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + } + """; await VerifySendEnterThroughToEnterAsync(markup, "Color =", sendThroughEnterOption: EnterKeyRule.Never, expected: false); await VerifySendEnterThroughToEnterAsync(markup, "Color =", sendThroughEnterOption: EnterKeyRule.AfterFullyTypedWord, expected: true); @@ -47,20 +48,21 @@ public class TestAttribute : Attribute [Fact] public async Task CommitCharacterTest() { - const string markup = @" -using System; -class class1 -{ - [Test($$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } -}"; + const string markup = """ + using System; + class class1 + { + [Test($$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + } + """; await VerifyCommonCommitCharactersAsync(markup, textTypedSoFar: ""); } @@ -68,20 +70,21 @@ public class TestAttribute : Attribute [Fact] public async Task SimpleAttributeUsage() { - var markup = @" -using System; -class class1 -{ - [Test($$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } -}"; + var markup = """ + using System; + class class1 + { + [Test($$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + } + """; await VerifyItemExistsAsync(markup, "Color", displayTextSuffix: " ="); } @@ -89,21 +92,22 @@ public class TestAttribute : Attribute [Fact] public async Task AfterComma() { - var markup = @" -using System; -class class1 -{ - [Test(Color = ConsoleColor.Black, $$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } - public string Text { get; set; } -}"; + var markup = """ + using System; + class class1 + { + [Test(Color = ConsoleColor.Black, $$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + public string Text { get; set; } + } + """; await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " ="); } @@ -111,21 +115,22 @@ public class TestAttribute : Attribute [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544345")] public async Task ExistingItemsAreFiltered() { - var markup = @" -using System; -class class1 -{ - [Test(Color = ConsoleColor.Black, $$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } - public string Text { get; set; } -}"; + var markup = """ + using System; + class class1 + { + [Test(Color = ConsoleColor.Black, $$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + public string Text { get; set; } + } + """; await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " ="); await VerifyItemIsAbsentAsync(markup, "Color", displayTextSuffix: " ="); @@ -134,18 +139,18 @@ public class TestAttribute : Attribute [Fact] public async Task AttributeConstructor() { - var markup = @" -using System; -class TestAttribute : Attribute -{ - public TestAttribute(int a = 42) - { } -} - -[Test($$ -class Goo -{ } -"; + var markup = """ + using System; + class TestAttribute : Attribute + { + public TestAttribute(int a = 42) + { } + } + + [Test($$ + class Goo + { } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -153,18 +158,18 @@ class Goo [Fact] public async Task AttributeConstructorAfterComma() { - var markup = @" -using System; -class TestAttribute : Attribute -{ - public TestAttribute(int a = 42, string s = """") - { } -} - -[Test(s:"""", $$ -class Goo -{ } -"; + var markup = """ + using System; + class TestAttribute : Attribute + { + public TestAttribute(int a = 42, string s = "") + { } + } + + [Test(s:"", $$ + class Goo + { } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -172,21 +177,22 @@ class Goo [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545426")] public async Task TestPropertiesInScript() { - var markup = @" -using System; - -class TestAttribute : Attribute -{ - public string Text { get; set; } - public TestAttribute(int number = 42) - { - } -} - -[Test($$ -class Goo -{ -}"; + var markup = """ + using System; + + class TestAttribute : Attribute + { + public string Text { get; set; } + public TestAttribute(int number = 42) + { + } + } + + [Test($$ + class Goo + { + } + """; await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " ="); } @@ -194,20 +200,21 @@ class Goo [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1075278")] public async Task NotInComment() { - var markup = @" -using System; -class class1 -{ - [Test( //$$ - public void Goo() - { - } -} - -public class TestAttribute : Attribute -{ - public ConsoleColor Color { get; set; } -}"; + var markup = """ + using System; + class class1 + { + [Test( //$$ + public void Goo() + { + } + } + + public class TestAttribute : Attribute + { + public ConsoleColor Color { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs index 0724a99f4b546..c7e71393b0762 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs @@ -63,35 +63,38 @@ static string GetDescription(string keyword, string tooltip) [Fact] public async Task TestNotInTypeContext() { - await VerifyAbsenceAsync(@" -class Program -{ - $$ -}"); + await VerifyAbsenceAsync(""" + class Program + { + $$ + } + """); } [Fact] public async Task TestStatementInMethod() { - await VerifyKeywordAsync(@" -class C -{ - void F() - { - $$ } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + void F() + { + $$ } + } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestStatementInMethod_Async() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - $$ } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + $$ } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -103,27 +106,27 @@ public async Task TestStatementInMethod_TopLevel() [Fact] public async Task TestExpressionInAsyncMethod() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - var z = $$ } -} -", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + var z = $$ } + } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestExpressionInNonAsyncMethodWithTaskReturn() { - await VerifyKeywordAsync(@" -class C -{ - Task F() - { - var z = $$ } -} -", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + Task F() + { + var z = $$ } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -135,13 +138,14 @@ public async Task TestExpressionInAsyncMethod_TopLevel() [Fact] public async Task TestUsingStatement() { - await VerifyAbsenceAsync(@" -class C -{ - async Task F() - { - using $$ } -}", LanguageVersion.CSharp9); + await VerifyAbsenceAsync(""" + class C + { + async Task F() + { + using $$ } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -161,13 +165,14 @@ public async Task TestGlobalUsingDirective() [Fact] public async Task TestForeachStatement() { - await VerifyAbsenceAsync(@" -class C -{ - async Task F() - { - foreach $$ } -}", LanguageVersion.CSharp9); + await VerifyAbsenceAsync(""" + class C + { + async Task F() + { + foreach $$ } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -179,77 +184,86 @@ public async Task TestForeachStatement_TopLevel() [Fact] public async Task TestNotInQuery() { - await VerifyAbsenceAsync(@" -class C -{ - async Task F() - { - var z = from a in ""char"" - select $$ } - } -", LanguageVersion.CSharp9); + await VerifyAbsenceAsync(""" + class C + { + async Task F() + { + var z = from a in "char" + select $$ } + } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestNotInQuery_TopLevel() { await VerifyAbsenceAsync( -@"var z = from a in ""char"" - select $$", LanguageVersion.CSharp9); + """ + var z = from a in "char" + select $$ + """, LanguageVersion.CSharp9); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/907052")] public async Task TestInFinally() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - try { } -finally { $$ } } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + try { } + finally { $$ } } + } + """, LanguageVersion.CSharp9); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/907052")] public async Task TestInFinally_TopLevel() { await VerifyKeywordAsync( -@"try { } -finally { $$ }", LanguageVersion.CSharp9); + """ + try { } + finally { $$ } + """, LanguageVersion.CSharp9); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/907052")] public async Task TestInCatch() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - try { } -catch { $$ } } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + try { } + catch { $$ } } + } + """, LanguageVersion.CSharp9); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/907052")] public async Task TestInCatch_TopLevel() { await VerifyKeywordAsync( -@"try { } -catch { $$ }", LanguageVersion.CSharp9); + """ + try { } + catch { $$ } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestNotInLock() { - await VerifyAbsenceAsync(@" -class C -{ - async Task F() - { - lock(this) { $$ } } -}", LanguageVersion.CSharp9); + await VerifyAbsenceAsync(""" + class C + { + async Task F() + { + lock(this) { $$ } } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -261,34 +275,38 @@ public async Task TestNotInLock_TopLevel() [Fact] public async Task TestInAsyncLambdaInCatch() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - try { } -catch { var z = async () => $$ } } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + try { } + catch { var z = async () => $$ } } + } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestInAsyncLambdaInCatch_TopLevel() { await VerifyKeywordAsync( -@"try { } -catch { var z = async () => $$ }", LanguageVersion.CSharp9); + """ + try { } + catch { var z = async () => $$ } + """, LanguageVersion.CSharp9); } [Fact] public async Task TestAwaitInLock() { - await VerifyKeywordAsync(@" -class C -{ - async Task F() - { - lock($$ } -}", LanguageVersion.CSharp9); + await VerifyKeywordAsync(""" + class C + { + async Task F() + { + lock($$ } + } + """, LanguageVersion.CSharp9); } [Fact] @@ -300,33 +318,33 @@ public async Task TestAwaitInLock_TopLevel() [Fact] public async Task TestDotAwaitSuggestAfterDotOnTask() { - await VerifyKeywordAsync(@" -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Threading.Tasks; -class C -{ - async Task F(Task someTask) - { - someTask.$$ - } -} -", dotAwait: true, dotAwaitf: true); + class C + { + async Task F(Task someTask) + { + someTask.$$ + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] public async Task TestDotAwaitSuggestAfterDotOnTaskOfT() { - await VerifyKeywordAsync(@" -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Threading.Tasks; -class C -{ - async Task F(Task someTask) - { - someTask.$$ - } -} -", dotAwait: true, dotAwaitf: true); + class C + { + async Task F(Task someTask) + { + someTask.$$ + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] @@ -358,111 +376,116 @@ async Task F(ValueTask someTask) [Fact] public async Task TestDotAwaitSuggestAfterDotOnCustomAwaitable() { - await VerifyKeywordAsync(@" -using System; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System; + using System.Runtime.CompilerServices; + using System.Threading.Tasks; -public class DummyAwaiter: INotifyCompletion { - public bool IsCompleted => true; - public void OnCompleted(Action continuation) => continuation(); - public void GetResult() {} -} + public class DummyAwaiter: INotifyCompletion { + public bool IsCompleted => true; + public void OnCompleted(Action continuation) => continuation(); + public void GetResult() {} + } -public class CustomAwaitable -{ - public DummyAwaiter GetAwaiter() => new DummyAwaiter(); -} + public class CustomAwaitable + { + public DummyAwaiter GetAwaiter() => new DummyAwaiter(); + } -static class Program -{ - static async Task Main() - { - var awaitable = new CustomAwaitable(); - awaitable.$$; - } -}", dotAwait: true); + static class Program + { + static async Task Main() + { + var awaitable = new CustomAwaitable(); + awaitable.$$; + } + } + """, dotAwait: true); } [Fact] public async Task TestDotAwaitSuggestAfterDotOnCustomAwaitableButNotConfigureAwaitEvenIfPresent() { - await VerifyKeywordAsync(@" -using System; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System; + using System.Runtime.CompilerServices; + using System.Threading.Tasks; -public class DummyAwaiter: INotifyCompletion { - public bool IsCompleted => true; - public void OnCompleted(Action continuation) => continuation(); - public void GetResult() {} -} + public class DummyAwaiter: INotifyCompletion { + public bool IsCompleted => true; + public void OnCompleted(Action continuation) => continuation(); + public void GetResult() {} + } -public class CustomAwaitable -{ - public DummyAwaiter GetAwaiter() => new DummyAwaiter(); - public ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; -} + public class CustomAwaitable + { + public DummyAwaiter GetAwaiter() => new DummyAwaiter(); + public ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; + } -static class Program -{ - static async Task Main() - { - var awaitable = new CustomAwaitable(); - awaitable.$$; - } -}", dotAwait: true, dotAwaitf: false); + static class Program + { + static async Task Main() + { + var awaitable = new CustomAwaitable(); + awaitable.$$; + } + } + """, dotAwait: true, dotAwaitf: false); } [Fact] public async Task TestDotAwaitSuggestAfterDotDot() { - await VerifyKeywordAsync(@" -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Threading.Tasks; -static class Program -{ - static async Task Main(Task someTask) - { - someTask.$$.; - } -}", dotAwait: true, dotAwaitf: true); + static class Program + { + static async Task Main(Task someTask) + { + someTask.$$.; + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] public async Task TestDotAwaitSuggestAfterDotBeforeType() { - await VerifyKeywordAsync(@" -using System; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System; + using System.Threading.Tasks; -static class Program -{ - static async Task Main(Task someTask) - { - someTask.$$ - Int32 i = 0; - } -}", dotAwait: true, dotAwaitf: true); + static class Program + { + static async Task Main(Task someTask) + { + someTask.$$ + Int32 i = 0; + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] public async Task TestDotAwaitSuggestAfterDotBeforeAnotherAwait() { - await VerifyKeywordAsync(@" -using System; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System; + using System.Threading.Tasks; -static class Program -{ - static async Task Main(Task someTask) - { - someTask.$$ - await Test(); - } + static class Program + { + static async Task Main(Task someTask) + { + someTask.$$ + await Test(); + } - async Task Test() { } -}", dotAwait: true, dotAwaitf: true); + async Task Test() { } + } + """, dotAwait: true, dotAwaitf: true); } [Theory] @@ -567,19 +590,20 @@ public async Task TestDotAwaitSuggestBeforeLocalFunction() // * only for locals (e.g. IParameterSymbols are fine) which // * are declared with var // * The return type of the local function is used as first name in a MemberAccess in the declarator - await VerifyKeywordAsync(@" -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Threading.Tasks; -static class Program -{ - static async Task Main() - { - var local = Task.CompletedTask; - local.a$$ + static class Program + { + static async Task Main() + { + var local = Task.CompletedTask; + local.a$$ - Task LocalFunction() => Task.CompletedTask; - } -}"); + Task LocalFunction() => Task.CompletedTask; + } + } + """); } [Theory] @@ -610,181 +634,181 @@ static async Task Main() [Fact] public async Task TestDotAwaitNotAfterDotOnTaskIfAlreadyAwaited() { - await VerifyAbsenceAsync(@" -using System.Threading.Tasks; + await VerifyAbsenceAsync(""" + using System.Threading.Tasks; -class C -{ - async Task F(Task someTask) - { - await someTask.$$ - } -} -"); + class C + { + async Task F(Task someTask) + { + await someTask.$$ + } + } + """); } [Fact] public async Task TestDotAwaitNotAfterTaskType() { - await VerifyAbsenceAsync(@" -using System.Threading.Tasks; + await VerifyAbsenceAsync(""" + using System.Threading.Tasks; -class C -{ - async Task F() - { - Task.$$ - } -} -"); + class C + { + async Task F() + { + Task.$$ + } + } + """); } [Fact] public async Task TestDotAwaitNotInLock() { - await VerifyAbsenceAsync(@" -using System.Threading.Tasks; + await VerifyAbsenceAsync(""" + using System.Threading.Tasks; -class C -{ - async Task F(Task someTask) - { - lock(this) { someTask.$$ } - } -} -"); + class C + { + async Task F(Task someTask) + { + lock(this) { someTask.$$ } + } + } + """); } [Fact] public async Task TestDotAwaitNotInLock_TopLevel() { - await VerifyAbsenceAsync(@" -using System.Threading.Tasks; + await VerifyAbsenceAsync(""" + using System.Threading.Tasks; -lock(this) { Task.CompletedTask.$$ } -"); + lock(this) { Task.CompletedTask.$$ } + """); } [Fact] public async Task TestDotAwaitQueryNotInSelect() { - await VerifyAbsenceAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyAbsenceAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var z = from t in new[] { Task.CompletedTask } - select t.$$ - } -} -"); + class C + { + async Task F() + { + var z = from t in new[] { Task.CompletedTask } + select t.$$ + } + } + """); } [Fact] public async Task TestDotAwaitQueryInFirstFromClause() { - await VerifyKeywordAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var arrayTask2 = Task.FromResult(new int[0]); - var z = from t in arrayTask2.$$ - select t; - } -} -", dotAwait: true, dotAwaitf: true); + class C + { + async Task F() + { + var arrayTask2 = Task.FromResult(new int[0]); + var z = from t in arrayTask2.$$ + select t; + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] public async Task TestDotAwaitQueryNotInSecondFromClause() { - await VerifyNoItemsExistAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyNoItemsExistAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var array1 = new int[0]; - var arrayTask2 = Task.FromResult(new int[0]); - var z = from i1 in array1 - from i2 in arrayTask2.$$ - select i2; - } -} -"); + class C + { + async Task F() + { + var array1 = new int[0]; + var arrayTask2 = Task.FromResult(new int[0]); + var z = from i1 in array1 + from i2 in arrayTask2.$$ + select i2; + } + } + """); } [Fact] public async Task TestDotAwaitQueryNotInContinuation() { - await VerifyNoItemsExistAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyNoItemsExistAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var array1 = new int[0]; - var arrayTask2 = Task.FromResult(new int[0]); - var z = from i1 in array1 - select i1 into c - from i2 in arrayTask2.$$ - select i2; - } -} -"); + class C + { + async Task F() + { + var array1 = new int[0]; + var arrayTask2 = Task.FromResult(new int[0]); + var z = from i1 in array1 + select i1 into c + from i2 in arrayTask2.$$ + select i2; + } + } + """); } [Fact] public async Task TestDotAwaitQueryInJoinClause() { - await VerifyKeywordAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var array1 = new int[0]; - var arrayTask2 = Task.FromResult(new int[0]); - var z = from i1 in array1 - join i2 in arrayTask2.$$ on i1 equals i2 - select i1; - } -} -", dotAwait: true, dotAwaitf: true); + class C + { + async Task F() + { + var array1 = new int[0]; + var arrayTask2 = Task.FromResult(new int[0]); + var z = from i1 in array1 + join i2 in arrayTask2.$$ on i1 equals i2 + select i1; + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] public async Task TestDotAwaitQueryInJoinIntoClause() { - await VerifyKeywordAsync(@" -using System.Linq; -using System.Threading.Tasks; + await VerifyKeywordAsync(""" + using System.Linq; + using System.Threading.Tasks; -class C -{ - async Task F() - { - var array1 = new int[0]; - var arrayTask2 = Task.FromResult(new int[0]); - var z = from i1 in array1 - join i2 in arrayTask2.$$ on i1 equals i2 into g - select g; - } -} -", dotAwait: true, dotAwaitf: true); + class C + { + async Task F() + { + var array1 = new int[0]; + var arrayTask2 = Task.FromResult(new int[0]); + var z = from i1 in array1 + join i2 in arrayTask2.$$ on i1 equals i2 into g + select g; + } + } + """, dotAwait: true, dotAwaitf: true); } [Fact] @@ -798,17 +822,17 @@ public async Task TestDotAwaitNotAfterConditionalAccessOfTaskMembers() // Completion should not offer await, because the patterns above would change to much code. // This decision should be revised after https://github.com/dotnet/csharplang/issues/35 // is implemented. - await VerifyAbsenceAsync(@" -using System.Threading.Tasks; - -class C -{ - async Task F(Task someTask) - { - someTask?.$$ - } -} -"); + await VerifyAbsenceAsync(""" + using System.Threading.Tasks; + + class C + { + async Task F(Task someTask) + { + someTask?.$$ + } + } + """); } [Theory] diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs index f80093130a19f..e8ea064b58748 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs @@ -28,21 +28,21 @@ private static string FormatExplicitConversionDescription(string fromType, strin [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorIndexerCompletionItemsShouldBePlacedLastInCompletionList() { - var castCompletionItem = (await GetCompletionItemsAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; -} + var castCompletionItem = (await GetCompletionItemsAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", SourceCodeKind.Regular)).Single(); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, SourceCodeKind.Regular)).Single(); var completionList = new[] { CompletionItem.Create("SomeText0"), @@ -74,61 +74,61 @@ public static void Main() public async Task ExplicitUserDefinedConversionIsNotOfferedAfterNumberLiteral() { // User may want to type a floating point literal. - await VerifyNoItemsExistAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - 1.$$ - } -} -", SourceCodeKind.Regular); + public class Program + { + public static void Main() + { + 1.$$ + } + } + """, SourceCodeKind.Regular); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIsSuggestedAfterDot() { - await VerifyItemExistsAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; -} + await VerifyItemExistsAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIsSuggestedIfMemberNameIsPartiallyWritten() { - await VerifyItemExistsAsync(@" -public class C -{ - public void fly() { } - public static explicit operator float(C c) => 0; -} + await VerifyItemExistsAsync(""" + public class C + { + public void fly() { } + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.fl$$ - } -} -", "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + public class Program + { + public static void Main() + { + var c = new C(); + c.fl$$ + } + } + """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -138,7 +138,9 @@ public static void Main() [InlineData("c.fl $$", false)] [InlineData("c.($$", false)] [InlineData("c$$", false)] - [InlineData(@"""c.$$", false)] + [InlineData(""" + "c.$$ + """, false)] [InlineData("c?.$$", true)] [InlineData("((C)c).$$", true)] [InlineData("(true ? c : c).$$", true)] @@ -169,40 +171,40 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIsNotSuggestedOnStaticAccess() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - C.$$ - } -} -"); + public class Program + { + public static void Main() + { + C.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIsNotSuggestedInNameofContext() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + } -public class Program -{ - public static void Main() - { - var c = new C(); - var name = nameof(c.$$ - } -} -"); + public class Program + { + public static void Main() + { + var c = new C(); + var name = nameof(c.$$ + } + } + """); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -255,26 +257,26 @@ public void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIsSuggestedForAllExplicitConversionsToOtherTypesAndNotForImplicitConversions() { - var items = await GetCompletionItemsAsync(@" -public class C -{ - public static explicit operator float(C c) => 0; - public static explicit operator int(C c) => 0; - - public static explicit operator C(float f) => new C(); - public static implicit operator C(string s) => new C(); - public static implicit operator string(C c) => ""; -} + var items = await GetCompletionItemsAsync(""" + public class C + { + public static explicit operator float(C c) => 0; + public static explicit operator int(C c) => 0; -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", SourceCodeKind.Regular); + public static explicit operator C(float f) => new C(); + public static implicit operator C(string s) => new C(); + public static implicit operator string(C c) => "; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, SourceCodeKind.Regular); Assert.Collection(items, i => Assert.Equal("float", i.DisplayText), i => Assert.Equal("int", i.DisplayText)); @@ -283,141 +285,145 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIgnoresConversionLikeMethods() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static bool op_Explicit(C c) => false; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static bool op_Explicit(C c) => false; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -"); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionIgnoreMalformedOperators() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static explicit operator int() => 0; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static explicit operator int() => 0; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -"); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionFromOtherTypeToTargetIsNotSuggested() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static explicit operator C(D d) => null; -} -public class D -{ -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static explicit operator C(D d) => null; + } + public class D + { + } -public class Program -{ - public static void Main() - { - var d = new D(); - d.$$ - } -} -"); + public class Program + { + public static void Main() + { + var d = new D(); + d.$$ + } + } + """); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitConversionOfNullableStructToNullableStructIsOffered() { // Lifted conversion https://docs.microsoft.com/hu-hu/dotnet/csharp/language-reference/language-specification/conversions#lifted-conversion-operators - await VerifyItemExistsAsync(@" -public struct S { - public static explicit operator int(S _) => 0; -} -public class Program -{ - public static void Main() - { - S? s = null; - s.$$ - } -} -", "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + await VerifyItemExistsAsync(""" + public struct S { + public static explicit operator int(S _) => 0; + } + public class Program + { + public static void Main() + { + S? s = null; + s.$$ + } + } + """, "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitConversionDescriptionIsIsGiven() { - const string Markup = @" -public struct S { - /// - /// Explicit conversion of to . - /// - /// The to convert - public static explicit operator int(S value) => 0; -} + const string Markup = """ + public struct S { + /// + /// Explicit conversion of to . + /// + /// The to convert + public static explicit operator int(S value) => 0; + } -public class Program -{ - public static void Main() - { - var s = new S(); - s.$$ - } -} -"; + public class Program + { + public static void Main() + { + var s = new S(); + s.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, expectedDescriptionOrNull: -@"S.explicit operator int(S value) -Explicit conversion of S to int."); + """ + S.explicit operator int(S value) + Explicit conversion of S to int. + """); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitConversionDescriptionIsIsGivenLifted() { - const string Markup = @" -public struct S { - /// - /// Explicit conversion of to . - /// - /// The to convert - public static explicit operator int(S value) => 0; -} + const string Markup = """ + public struct S { + /// + /// Explicit conversion of to . + /// + /// The to convert + public static explicit operator int(S value) => 0; + } -public class Program -{ - public static void Main() - { - S? s = new S(); - s.$$ - } -} -"; + public class Program + { + public static void Main() + { + S? s = new S(); + s.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, expectedDescriptionOrNull: -@"S.explicit operator int?(S? value) -Explicit conversion of S to int."); + """ + S.explicit operator int?(S? value) + Explicit conversion of S to int. + """); } [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -453,16 +459,16 @@ public static void Main() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitBuiltInNumericConversionDescriptionIsLikeAConversionOperatorDescription() { - const string Markup = @" -public class Program -{ - public static void Main() - { - int i = 0; - i.$$ - } -} -"; + const string Markup = """ + public class Program + { + public static void Main() + { + int i = 0; + i.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "byte", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, @@ -474,16 +480,16 @@ await VerifyItemExistsAsync(Markup, "byte", displayTextPrefix: "(", displayTextS [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitBuiltInNumericConversionDescriptionIsLikeAConversionOperatorDescriptionLifted() { - const string Markup = @" -public class Program -{ - public static void Main() - { - int? i = 0; - i.$$ - } -} -"; + const string Markup = """ + public class Program + { + public static void Main() + { + int? i = 0; + i.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "byte?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, @@ -497,17 +503,17 @@ public async Task ExplicitBuiltInEnumConversionsAreSortedAndComplete() { // built-in enum conversions: // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#explicit-enumeration-conversions - var items = await GetCompletionItemsAsync(@" -public enum E { One } -public class Program -{ - public static void Main() - { - var e = E.One; - e.$$ - } -} -", SourceCodeKind.Regular); + var items = await GetCompletionItemsAsync(""" + public enum E { One } + public class Program + { + public static void Main() + { + var e = E.One; + e.$$ + } + } + """, SourceCodeKind.Regular); var expected = new[] { "byte", "char", "decimal", "double", "float", "int", "long", "sbyte", "short", "uint", "ulong", "ushort" }; AssertEx.SetEqual(items.Select(i => i.DisplayText), expected); } @@ -515,17 +521,17 @@ public static void Main() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitBuiltInEnumConversionDescriptionIsLikeAConversionOperatorDescription() { - const string Markup = @" -public enum E { One } -public class Program -{ - public static void Main() - { - var e = E.One; - e.$$ - } -} -"; + const string Markup = """ + public enum E { One } + public class Program + { + public static void Main() + { + var e = E.One; + e.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, @@ -537,17 +543,17 @@ await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSu [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitBuiltInEnumConversionDescriptionIsLikeAConversionOperatorDescriptionLifted() { - const string Markup = @" -public enum E { One } -public class Program -{ - public static void Main() - { - E? e = E.One; - e.$$ - } -} -"; + const string Markup = """ + public enum E { One } + public class Program + { + public static void Main() + { + E? e = E.One; + e.$$ + } + } + """; await VerifyItemExistsAsync(Markup, "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, @@ -559,23 +565,23 @@ await VerifyItemExistsAsync(Markup, "int?", displayTextPrefix: "(", displayTextS [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitBuiltInEnumConversionDescriptionIsLikeAConversionOperatorDescriptionUnimportedNamespaceMinimalName() { - const string Markup = @" -namespace A.B -{ - public enum E { One } -} -namespace A.C -{ - public class Program - { - public static void Main() - { - var e = B.E.One; - e.$$ - } - } -} -"; + const string Markup = """ + namespace A.B + { + public enum E { One } + } + namespace A.C + { + public class Program + { + public static void Main() + { + var e = B.E.One; + e.$$ + } + } + } + """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }, @@ -612,22 +618,22 @@ public static void Main() public async Task ExplicitUserDefinedConversionInheritedConversions() { // Base class lookup rule: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#processing-of-user-defined-explicit-conversions - await VerifyItemExistsAsync(@" -public class Base { - public static explicit operator int(Base b) => 0; -} -public class Derived: Base -{ -} -public class Program -{ - public static void Main() - { - var d = new Derived(); - var i = d.$$ - } -} -", "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + await VerifyItemExistsAsync(""" + public class Base { + public static explicit operator int(Base b) => 0; + } + public class Derived: Base + { + } + public class Program + { + public static void Main() + { + var d = new Derived(); + var i = d.$$ + } + } + """, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -651,31 +657,31 @@ public static void Main() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnConversionIsRespected_EditorBrowsableStateNever() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Never)] - public static explicit operator int(C _) => 0; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Never)] + public static explicit operator int(C _) => 0; + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -690,33 +696,33 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnConversionIsRespected_EditorBrowsableStateNever_InheritedConversion_1() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var d = new Derived(); - d.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class Base { - [EditorBrowsable(EditorBrowsableState.Never)] - public static explicit operator int(Base b) => 0; - } - public class Derived: Base - { - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class Base { + [EditorBrowsable(EditorBrowsableState.Never)] + public static explicit operator int(Base b) => 0; + } + public class Derived: Base + { + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -731,33 +737,33 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnConversionIsRespected_EditorBrowsableStateNever_InheritedConversion_2() { - var markup = @" -namespace N -{ - public class Derived: Base - { - } - public class Program - { - public static void Main() - { - var d = new Derived(); - d.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class Base { - [EditorBrowsable(EditorBrowsableState.Never)] - public static explicit operator int(Base b) => 0; - } -} -"; + var markup = """ + namespace N + { + public class Derived: Base + { + } + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class Base { + [EditorBrowsable(EditorBrowsableState.Never)] + public static explicit operator int(Base b) => 0; + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -772,31 +778,31 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnConversionIsRespected_EditorBrowsableStateAdvanced() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Advanced)] - public static explicit operator int(C _) => 0; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Advanced)] + public static explicit operator int(C _) => 0; + } + } + """; HideAdvancedMembers = false; @@ -824,22 +830,22 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task ExplicitUserDefinedConversionOfDerefenrencedPointerIsNotOffered() { - await VerifyNoItemsExistAsync(@" -public struct S { - public static explicit operator int(S s) => 0; -} -public class Program -{ - public static void Main() - { - unsafe{ - var s = new S(); - S* p = &s; - var i = p->$$; - } - } -} -"); + await VerifyNoItemsExistAsync(""" + public struct S { + public static explicit operator int(S s) => 0; + } + public class Program + { + public static void Main() + { + unsafe{ + var s = new S(); + S* p = &s; + var i = p->$$; + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs index 80124190c4512..159537aefe18c 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs @@ -64,46 +64,52 @@ await VerifyAtEndOfFile_ItemPartiallyWrittenAsync( [Fact] public async Task NameCref() { - var text = @"using System; -namespace Goo -{ - /// - class Program - { - } -}"; + var text = """ + using System; + namespace Goo + { + /// + class Program + { + } + } + """; await VerifyItemExistsAsync(text, "AccessViolationException"); } [Fact] public async Task QualifiedCref() { - var text = @"using System; -namespace Goo -{ + var text = """ + using System; + namespace Goo + { - class Program - { - /// - void goo() { } - } -}"; + class Program + { + /// + void goo() { } + } + } + """; await VerifyItemExistsAsync(text, "goo"); } [Fact] public async Task CrefArgumentList() { - var text = @"using System; -namespace Goo -{ + var text = """ + using System; + namespace Goo + { - class Program - { - /// - void goo(int i) { } - } -}"; + class Program + { + /// + void goo(int i) { } + } + } + """; await VerifyItemIsAbsentAsync(text, "goo(int)"); await VerifyItemExistsAsync(text, "int"); } @@ -111,60 +117,67 @@ void goo(int i) { } [Fact] public async Task CrefTypeParameterInArgumentList() { - var text = @"using System; -namespace Goo -{ + var text = """ + using System; + namespace Goo + { - class Program - { - /// - void goo(T i) { } - } -}"; + class Program + { + /// + void goo(T i) { } + } + } + """; await VerifyItemExistsAsync(text, "Q"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530887")] public async Task PrivateMember() { - var text = @"using System; -namespace Goo -{ - /// - class Program - { - } - - class C - { - private int Private; - public int Public; - } -}"; + var text = """ + using System; + namespace Goo + { + /// + class Program + { + } + + class C + { + private int Private; + public int Public; + } + } + """; await VerifyItemExistsAsync(text, "Private"); } [Fact] public async Task AfterSingleQuote() { - var text = @"using System; -namespace Goo -{ - /// - class Program - { - } -}"; + var text = """ + using System; + namespace Goo + { + /// + class Program + { + } + } + """; await VerifyItemExistsAsync(text, "Exception"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531315")] public async Task EscapePredefinedTypeName() { - var text = @"using System; -/// -class @void { } -"; + var text = """ + using System; + /// + class @void { } + """; await VerifyItemExistsAsync(text, "@void"); } @@ -172,15 +185,15 @@ class @void { } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531345")] public async Task ShowParameterNames() { - var text = @"/// -class C -{ - void M(int x) { } - void M(ref long x) { } - void M(T x) { } -} - -"; + var text = """ + /// + class C + { + void M(int x) { } + void M(ref long x) { } + void M(T x) { } + } + """; await VerifyItemExistsAsync(text, "M(int)"); await VerifyItemExistsAsync(text, "M(ref long)"); await VerifyItemExistsAsync(text, "M{T}(T)"); @@ -189,34 +202,34 @@ void M(T x) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531345")] public async Task ShowTypeParameterNames() { - var text = @"/// -class C -{ - void M(int x) { } - void M(long x) { } - void M(string x) { } -} - -"; + var text = """ + /// + class C + { + void M(int x) { } + void M(long x) { } + void M(string x) { } + } + """; await VerifyItemExistsAsync(text, "C{TGoo}"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531156")] public async Task ShowConstructors() { - var text = @"using System; - -/// -class C -{ - public C(int x) { } + var text = """ + using System; - public C() { } + /// + class C + { + public C(int x) { } - public C(T x) { } -} + public C() { } -"; + public C(T x) { } + } + """; await VerifyItemExistsAsync(text, "C()"); await VerifyItemExistsAsync(text, "C(T)"); await VerifyItemExistsAsync(text, "C(int)"); @@ -225,73 +238,72 @@ public C(T x) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/598679")] public async Task NoParamsModifier() { - var text = @"/// -/// -/// -class C - { - void M(int x) { } - void M(params long[] x) { } - } - - -"; + var text = """ + /// + /// + /// + class C + { + void M(int x) { } + void M(params long[] x) { } + } + """; await VerifyItemExistsAsync(text, "M(long[])"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/607773")] public async Task UnqualifiedTypes() { - var text = @" -using System.Collections.Generic; -/// -class C { } -"; + var text = """ + using System.Collections.Generic; + /// + class C { } + """; await VerifyItemExistsAsync(text, "Enumerator"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/607773")] public async Task CommitUnqualifiedTypes() { - var text = @" -using System.Collections.Generic; -/// -class C { } -"; + var text = """ + using System.Collections.Generic; + /// + class C { } + """; - var expected = @" -using System.Collections.Generic; -/// -class C { } -"; + var expected = """ + using System.Collections.Generic; + /// + class C { } + """; await VerifyProviderCommitAsync(text, "Enumerator", expected, ' '); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/642285")] public async Task SuggestOperators() { - var text = @" -class Test -{ - /// - public static Test operator !(Test t) - { - return new Test(); - } - public static int operator +(Test t1, Test t2) // Invoke FAR here on operator - { - return 1; - } - public static bool operator true(Test t) - { - return true; - } - public static bool operator false(Test t) - { - return false; - } -} -"; + var text = """ + class Test + { + /// + public static Test operator !(Test t) + { + return new Test(); + } + public static int operator +(Test t1, Test t2) // Invoke FAR here on operator + { + return 1; + } + public static bool operator true(Test t) + { + return true; + } + public static bool operator false(Test t) + { + return false; + } + } + """; await VerifyItemExistsAsync(text, "operator !(Test)"); await VerifyItemExistsAsync(text, "operator +(Test, Test)"); await VerifyItemExistsAsync(text, "operator true(Test)"); @@ -301,49 +313,51 @@ public static bool operator false(Test t) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/641096")] public async Task SuggestIndexers() { - var text = @" -/// -class Program -{ - int[] arr; + var text = """ + /// + class Program + { + int[] arr; - public int this[int i] - { - get { return arr[i]; } - } -} -"; + public int this[int i] + { + get { return arr[i]; } + } + } + """; await VerifyItemExistsAsync(text, "this[int]"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531315")] public async Task CommitEscapedPredefinedTypeName() { - var text = @"using System; -/// -class @void { } -"; + var text = """ + using System; + /// + class @void { } + """; - var expected = @"using System; -/// -class @void { } -"; + var expected = """ + using System; + /// + class @void { } + """; await VerifyProviderCommitAsync(text, "@void", expected, ' '); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/598159")] public async Task RefOutModifiers() { - var text = @"/// -/// -/// -class C -{ - void M(ref int x) { } - void M(out long x) { } -} - -"; + var text = """ + /// + /// + /// + class C + { + void M(ref int x) { } + void M(out long x) { } + } + """; await VerifyItemExistsAsync(text, "M(ref int)"); await VerifyItemExistsAsync(text, "M(out long)"); } @@ -351,28 +365,30 @@ void M(out long x) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/673587")] public async Task NestedNamespaces() { - var text = @"namespace N -{ - class C - { - void sub() { } - } - namespace N - { - class C - { } - } -} -class Program -{ - /// - /// // type N. here - /// - static void Main(string[] args) - { + var text = """ + namespace N + { + class C + { + void sub() { } + } + namespace N + { + class C + { } + } + } + class Program + { + /// + /// // type N. here + /// + static void Main(string[] args) + { - } -}"; + } + } + """; await VerifyItemExistsAsync(text, "N"); await VerifyItemExistsAsync(text, "C"); } @@ -380,51 +396,52 @@ static void Main(string[] args) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/730338")] public async Task PermitTypingTypeParameters() { - var text = @" -using System.Collections.Generic; -/// -class C { } -"; + var text = """ + using System.Collections.Generic; + /// + class C { } + """; - var expected = @" -using System.Collections.Generic; -/// -class C { } -"; + var expected = """ + using System.Collections.Generic; + /// + class C { } + """; await VerifyProviderCommitAsync(text, "List{T}", expected, '{'); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/730338")] public async Task PermitTypingParameterTypes() { - var text = @" -using System.Collections.Generic; -/// -class C -{ - public void goo(int x) { } -} -"; + var text = """ + using System.Collections.Generic; + /// + class C + { + public void goo(int x) { } + } + """; - var expected = @" -using System.Collections.Generic; -/// -class C -{ - public void goo(int x) { } -} -"; + var expected = """ + using System.Collections.Generic; + /// + class C + { + public void goo(int x) { } + } + """; await VerifyProviderCommitAsync(text, "goo(int)", expected, '('); } [Fact] public async Task CrefCompletionSpeculatesOutsideTrivia() { - var text = @" -/// -class C -{ - public void goo(int x) { } -} -"; + var text = """ + using System; + /// + class C + { + public void goo(int x) { } + } + """; await VerifyItemExistsAsync(text, "uint"); await VerifyItemExistsAsync(text, "UInt32"); @@ -467,14 +484,14 @@ public void goo(int x) { } [Fact] public async Task NoSuggestionAfterEmptyCref() { - var text = @" -using System; -/// - { - private readonly T[] arr; - public ref T this[int i] => ref arr[i]; - public override int GetHashCode() => 1; - public int Length { get; } - unsafe public Span(void* pointer, int length) - { - this.arr = Helpers.ToArray(pointer, length); - this.Length = length; - } - public Span(T[] arr) - { - this.arr = arr; - this.Length = arr.Length; - } - public void CopyTo(Span other) { } - /// Gets an enumerator for this span. - public Enumerator GetEnumerator() => new Enumerator(this); - /// Enumerates the elements of a . - public ref struct Enumerator - { - /// The span being enumerated. - private readonly Span _span; - /// The next index to yield. - private int _index; - /// Initialize the enumerator. - /// The span to enumerate. - internal Enumerator(Span span) - { - _span = span; - _index = -1; - } - /// Advances the enumerator to the next element of the span. - public bool MoveNext() + private const string Span = """ + namespace System { - int index = _index + 1; - if (index < _span.Length) + public readonly ref struct Span { - _index = index; - return true; + private readonly T[] arr; + public ref T this[int i] => ref arr[i]; + public override int GetHashCode() => 1; + public int Length { get; } + unsafe public Span(void* pointer, int length) + { + this.arr = Helpers.ToArray(pointer, length); + this.Length = length; + } + public Span(T[] arr) + { + this.arr = arr; + this.Length = arr.Length; + } + public void CopyTo(Span other) { } + /// Gets an enumerator for this span. + public Enumerator GetEnumerator() => new Enumerator(this); + /// Enumerates the elements of a . + public ref struct Enumerator + { + /// The span being enumerated. + private readonly Span _span; + /// The next index to yield. + private int _index; + /// Initialize the enumerator. + /// The span to enumerate. + internal Enumerator(Span span) + { + _span = span; + _index = -1; + } + /// Advances the enumerator to the next element of the span. + public bool MoveNext() + { + int index = _index + 1; + if (index < _span.Length) + { + _index = index; + return true; + } + return false; + } + /// Gets the element at the current position of the enumerator. + public ref T Current + { + get => ref _span[_index]; + } + } + public static implicit operator Span(T[] array) => new Span(array); + public Span Slice(int offset, int length) + { + var copy = new T[length]; + Array.Copy(arr, offset, copy, 0, length); + return new Span(copy); + } } - return false; - } - /// Gets the element at the current position of the enumerator. - public ref T Current - { - get => ref _span[_index]; - } - } - public static implicit operator Span(T[] array) => new Span(array); - public Span Slice(int offset, int length) - { - var copy = new T[length]; - Array.Copy(arr, offset, copy, 0, length); - return new Span(copy); - } - } - public readonly ref struct ReadOnlySpan - { - private readonly T[] arr; - public ref readonly T this[int i] => ref arr[i]; - public override int GetHashCode() => 2; - public int Length { get; } - unsafe public ReadOnlySpan(void* pointer, int length) - { - this.arr = Helpers.ToArray(pointer, length); - this.Length = length; - } - public ReadOnlySpan(T[] arr) - { - this.arr = arr; - this.Length = arr.Length; - } - public void CopyTo(Span other) { } - /// Gets an enumerator for this span. - public Enumerator GetEnumerator() => new Enumerator(this); - /// Enumerates the elements of a . - public ref struct Enumerator - { - /// The span being enumerated. - private readonly ReadOnlySpan _span; - /// The next index to yield. - private int _index; - /// Initialize the enumerator. - /// The span to enumerate. - internal Enumerator(ReadOnlySpan span) - { - _span = span; - _index = -1; - } - /// Advances the enumerator to the next element of the span. - public bool MoveNext() - { - int index = _index + 1; - if (index < _span.Length) + public readonly ref struct ReadOnlySpan { - _index = index; - return true; + private readonly T[] arr; + public ref readonly T this[int i] => ref arr[i]; + public override int GetHashCode() => 2; + public int Length { get; } + unsafe public ReadOnlySpan(void* pointer, int length) + { + this.arr = Helpers.ToArray(pointer, length); + this.Length = length; + } + public ReadOnlySpan(T[] arr) + { + this.arr = arr; + this.Length = arr.Length; + } + public void CopyTo(Span other) { } + /// Gets an enumerator for this span. + public Enumerator GetEnumerator() => new Enumerator(this); + /// Enumerates the elements of a . + public ref struct Enumerator + { + /// The span being enumerated. + private readonly ReadOnlySpan _span; + /// The next index to yield. + private int _index; + /// Initialize the enumerator. + /// The span to enumerate. + internal Enumerator(ReadOnlySpan span) + { + _span = span; + _index = -1; + } + /// Advances the enumerator to the next element of the span. + public bool MoveNext() + { + int index = _index + 1; + if (index < _span.Length) + { + _index = index; + return true; + } + return false; + } + /// Gets the element at the current position of the enumerator. + public ref readonly T Current + { + get => ref _span[_index]; + } + } + public static implicit operator ReadOnlySpan(T[] array) => array == null ? default : new ReadOnlySpan(array); + public static implicit operator ReadOnlySpan(string stringValue) => string.IsNullOrEmpty(stringValue) ? default : new ReadOnlySpan((T[])(object)stringValue.ToCharArray()); + public ReadOnlySpan Slice(int offset, int length) + { + var copy = new T[length]; + Array.Copy(arr, offset, copy, 0, length); + return new ReadOnlySpan(copy); + } } - return false; - } - /// Gets the element at the current position of the enumerator. - public ref readonly T Current - { - get => ref _span[_index]; - } - } - public static implicit operator ReadOnlySpan(T[] array) => array == null ? default : new ReadOnlySpan(array); - public static implicit operator ReadOnlySpan(string stringValue) => string.IsNullOrEmpty(stringValue) ? default : new ReadOnlySpan((T[])(object)stringValue.ToCharArray()); - public ReadOnlySpan Slice(int offset, int length) - { - var copy = new T[length]; - Array.Copy(arr, offset, copy, 0, length); - return new ReadOnlySpan(copy); - } - } - public readonly ref struct SpanLike - { - public readonly Span field; - } - public enum Color: sbyte - { - Red, - Green, - Blue - } - public static unsafe class Helpers - { - public static T[] ToArray(void* ptr, int count) - { - if (ptr == null) - { - return null; - } - if (typeof(T) == typeof(int)) - { - var arr = new int[count]; - for(int i = 0; i < count; i++) + public readonly ref struct SpanLike { - arr[i] = ((int*)ptr)[i]; + public readonly Span field; } - return (T[])(object)arr; - } - if (typeof(T) == typeof(byte)) - { - var arr = new byte[count]; - for(int i = 0; i < count; i++) + public enum Color: sbyte { - arr[i] = ((byte*)ptr)[i]; + Red, + Green, + Blue } - return (T[])(object)arr; - } - if (typeof(T) == typeof(char)) - { - var arr = new char[count]; - for(int i = 0; i < count; i++) + public static unsafe class Helpers { - arr[i] = ((char*)ptr)[i]; + public static T[] ToArray(void* ptr, int count) + { + if (ptr == null) + { + return null; + } + if (typeof(T) == typeof(int)) + { + var arr = new int[count]; + for(int i = 0; i < count; i++) + { + arr[i] = ((int*)ptr)[i]; + } + return (T[])(object)arr; + } + if (typeof(T) == typeof(byte)) + { + var arr = new byte[count]; + for(int i = 0; i < count; i++) + { + arr[i] = ((byte*)ptr)[i]; + } + return (T[])(object)arr; + } + if (typeof(T) == typeof(char)) + { + var arr = new char[count]; + for(int i = 0; i < count; i++) + { + arr[i] = ((char*)ptr)[i]; + } + return (T[])(object)arr; + } + if (typeof(T) == typeof(Color)) + { + var arr = new Color[count]; + for(int i = 0; i < count; i++) + { + arr[i] = ((Color*)ptr)[i]; + } + return (T[])(object)arr; + } + throw new Exception("add a case for: " + typeof(T)); + } } - return (T[])(object)arr; } - if (typeof(T) == typeof(Color)) + """; + + private const string IAsyncEnumerable = """ + namespace System { - var arr = new Color[count]; - for(int i = 0; i < count; i++) + public interface IAsyncDisposable { - arr[i] = ((Color*)ptr)[i]; + System.Threading.Tasks.ValueTask DisposeAsync(); } - return (T[])(object)arr; } - throw new Exception(""add a case for: "" + typeof(T)); - } - } -}"; - - private const string IAsyncEnumerable = @" -namespace System -{ - public interface IAsyncDisposable - { - System.Threading.Tasks.ValueTask DisposeAsync(); - } -} -namespace System.Runtime.CompilerServices -{ - using System.Threading.Tasks; + namespace System.Runtime.CompilerServices + { + using System.Threading.Tasks; - public sealed class AsyncMethodBuilderAttribute : Attribute - { - public AsyncMethodBuilderAttribute(Type builderType) { } - public Type BuilderType { get; } - } + public sealed class AsyncMethodBuilderAttribute : Attribute + { + public AsyncMethodBuilderAttribute(Type builderType) { } + public Type BuilderType { get; } + } - public struct AsyncValueTaskMethodBuilder - { - public ValueTask Task => default; - - public static AsyncValueTaskMethodBuilder Create() => default; - public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : INotifyCompletion - where TStateMachine : IAsyncStateMachine {} - - public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : ICriticalNotifyCompletion - where TStateMachine : IAsyncStateMachine {} - public void SetException(Exception exception) {} - public void SetResult() {} - public void SetStateMachine(IAsyncStateMachine stateMachine) {} - public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {} - } + public struct AsyncValueTaskMethodBuilder + { + public ValueTask Task => default; + + public static AsyncValueTaskMethodBuilder Create() => default; + public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : INotifyCompletion + where TStateMachine : IAsyncStateMachine {} + + public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : ICriticalNotifyCompletion + where TStateMachine : IAsyncStateMachine {} + public void SetException(Exception exception) {} + public void SetResult() {} + public void SetStateMachine(IAsyncStateMachine stateMachine) {} + public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {} + } - public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion - { - public bool IsCompleted => default; + public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion + { + public bool IsCompleted => default; - public void GetResult() { } - public void OnCompleted(Action continuation) { } - public void UnsafeOnCompleted(Action continuation) { } - } + public void GetResult() { } + public void OnCompleted(Action continuation) { } + public void UnsafeOnCompleted(Action continuation) { } + } - public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion - { - public bool IsCompleted => default; - public TResult GetResult() => default; - public void OnCompleted(Action continuation) { } - public void UnsafeOnCompleted(Action continuation) { } - } -} + public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion + { + public bool IsCompleted => default; + public TResult GetResult() => default; + public void OnCompleted(Action continuation) { } + public void UnsafeOnCompleted(Action continuation) { } + } + } -namespace System.Threading.Tasks -{ - using System.Runtime.CompilerServices; + namespace System.Threading.Tasks + { + using System.Runtime.CompilerServices; - [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))] - public readonly struct ValueTask : IEquatable - { - public ValueTask(Task task) {} - public ValueTask(IValueTaskSource source, short token) {} - - public bool IsCompleted => default; - public bool IsCompletedSuccessfully => default; - public bool IsFaulted => default; - public bool IsCanceled => default; - - public Task AsTask() => default; - public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; - public override bool Equals(object obj) => default; - public bool Equals(ValueTask other) => default; - public ValueTaskAwaiter GetAwaiter() => default; - public override int GetHashCode() => default; - public ValueTask Preserve() => default; - - public static bool operator ==(ValueTask left, ValueTask right) => default; - public static bool operator !=(ValueTask left, ValueTask right) => default; - } + [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))] + public readonly struct ValueTask : IEquatable + { + public ValueTask(Task task) {} + public ValueTask(IValueTaskSource source, short token) {} + + public bool IsCompleted => default; + public bool IsCompletedSuccessfully => default; + public bool IsFaulted => default; + public bool IsCanceled => default; + + public Task AsTask() => default; + public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; + public override bool Equals(object obj) => default; + public bool Equals(ValueTask other) => default; + public ValueTaskAwaiter GetAwaiter() => default; + public override int GetHashCode() => default; + public ValueTask Preserve() => default; + + public static bool operator ==(ValueTask left, ValueTask right) => default; + public static bool operator !=(ValueTask left, ValueTask right) => default; + } - [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))] - public readonly struct ValueTask : IEquatable> - { - public ValueTask(TResult result) {} - public ValueTask(Task task) {} - public ValueTask(IValueTaskSource source, short token) {} - - public bool IsFaulted => default; - public bool IsCompletedSuccessfully => default; - public bool IsCompleted => default; - public bool IsCanceled => default; - public TResult Result => default; - - public Task AsTask() => default; - public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; - - public bool Equals(ValueTask other) => default; - public override bool Equals(object obj) => default; - public ValueTaskAwaiter GetAwaiter() => default; - public override int GetHashCode() => default; - public ValueTask Preserve() => default; - public override string ToString() => default; - public static bool operator ==(ValueTask left, ValueTask right) => default; - public static bool operator !=(ValueTask left, ValueTask right) => default; - } -} + [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))] + public readonly struct ValueTask : IEquatable> + { + public ValueTask(TResult result) {} + public ValueTask(Task task) {} + public ValueTask(IValueTaskSource source, short token) {} + + public bool IsFaulted => default; + public bool IsCompletedSuccessfully => default; + public bool IsCompleted => default; + public bool IsCanceled => default; + public TResult Result => default; + + public Task AsTask() => default; + public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; + + public bool Equals(ValueTask other) => default; + public override bool Equals(object obj) => default; + public ValueTaskAwaiter GetAwaiter() => default; + public override int GetHashCode() => default; + public ValueTask Preserve() => default; + public override string ToString() => default; + public static bool operator ==(ValueTask left, ValueTask right) => default; + public static bool operator !=(ValueTask left, ValueTask right) => default; + } + } -namespace System.Collections.Generic -{ - public interface IAsyncEnumerable - { - IAsyncEnumerator GetAsyncEnumerator(); - } + namespace System.Collections.Generic + { + public interface IAsyncEnumerable + { + IAsyncEnumerator GetAsyncEnumerator(); + } - public interface IAsyncEnumerator : IAsyncDisposable - { - System.Threading.Tasks.ValueTask MoveNextAsync(); - T Current { get; } - } -}"; + public interface IAsyncEnumerator : IAsyncDisposable + { + System.Threading.Tasks.ValueTask MoveNextAsync(); + T Current { get; } + } + } + """; internal override Type GetCompletionProviderType() => typeof(DeclarationNameCompletionProvider); @@ -362,12 +364,12 @@ public class MyClass [Fact] public async Task NameWithOnlyType1() { - var markup = @" -public class MyClass -{ - MyClass $$ -} -"; + var markup = """ + public class MyClass + { + MyClass $$ + } + """; await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic); await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic); await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic); @@ -376,37 +378,37 @@ public class MyClass [Fact] public async Task AsyncTaskOfT() { - var markup = @" -using System.Threading.Tasks; -public class C -{ - async Task $$ -} -"; + var markup = """ + using System.Threading.Tasks; + public class C + { + async Task $$ + } + """; await VerifyItemExistsAsync(markup, "GetCAsync"); } [Fact(Skip = "not yet implemented")] public async Task NonAsyncTaskOfT() { - var markup = @" -public class C -{ - Task $$ -} -"; + var markup = """ + public class C + { + Task $$ + } + """; await VerifyItemExistsAsync(markup, "GetCAsync"); } [Fact] public async Task MethodDeclaration1() { - var markup = @" -public class C -{ - virtual C $$ -} -"; + var markup = """ + public class C + { + virtual C $$ + } + """; await VerifyItemExistsAsync(markup, "GetC"); await VerifyItemIsAbsentAsync(markup, "C"); await VerifyItemIsAbsentAsync(markup, "c"); @@ -415,13 +417,13 @@ virtual C $$ [Fact] public async Task WordBreaking1() { - var markup = @" -using System.Threading; -public class C -{ - CancellationToken $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + CancellationToken $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "cancellation"); await VerifyItemExistsAsync(markup, "token"); @@ -430,52 +432,52 @@ public class C [Fact] public async Task WordBreaking2() { - var markup = @" -interface I {} -public class C -{ - I $$ -} -"; + var markup = """ + interface I {} + public class C + { + I $$ + } + """; await VerifyItemExistsAsync(markup, "GetI"); } [Fact] public async Task WordBreaking3() { - var markup = @" -interface II {} -public class C -{ - II $$ -} -"; + var markup = """ + interface II {} + public class C + { + II $$ + } + """; await VerifyItemExistsAsync(markup, "GetI"); } [Fact] public async Task WordBreaking4() { - var markup = @" -interface IGoo {} -public class C -{ - IGoo $$ -} -"; + var markup = """ + interface IGoo {} + public class C + { + IGoo $$ + } + """; await VerifyItemExistsAsync(markup, "Goo"); } [Fact] public async Task WordBreaking5() { - var markup = @" -class SomeWonderfullyLongClassName {} -public class C -{ - SomeWonderfullyLongClassName $$ -} -"; + var markup = """ + class SomeWonderfullyLongClassName {} + public class C + { + SomeWonderfullyLongClassName $$ + } + """; await VerifyItemExistsAsync(markup, "Some"); await VerifyItemExistsAsync(markup, "SomeWonderfully"); await VerifyItemExistsAsync(markup, "SomeWonderfullyLong"); @@ -490,117 +492,117 @@ public class C [Fact] public async Task Parameter1() { - var markup = @" -using System.Threading; -public class C -{ - void Goo(CancellationToken $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + void Goo(CancellationToken $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact] public async Task Parameter2() { - var markup = @" -using System.Threading; -public class C -{ - void Goo(int x, CancellationToken c$$ -} -"; + var markup = """ + using System.Threading; + public class C + { + void Goo(int x, CancellationToken c$$ + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact] public async Task Parameter3() { - var markup = @" -using System.Threading; -public class C -{ - void Goo(CancellationToken c$$) {} -} -"; + var markup = """ + using System.Threading; + public class C + { + void Goo(CancellationToken c$$) {} + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter4() { - var markup = @" -using System.Threading; -public class C -{ - void Other(CancellationToken cancellationToken) {} - void Goo(CancellationToken c$$) {} -} -"; + var markup = """ + using System.Threading; + public class C + { + void Other(CancellationToken cancellationToken) {} + void Goo(CancellationToken c$$) {} + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact] public async Task Parameter5() { - var markup = @" -using System.Threading; -public class C -{ - void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} -} -"; + var markup = """ + using System.Threading; + public class C + { + void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} + } + """; await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter6() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -void Other(CancellationToken cancellationToken) {} -void Goo(CancellationToken c$$) {} -"; + void Other(CancellationToken cancellationToken) {} + void Goo(CancellationToken c$$) {} + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact] public async Task Parameter7() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} -"; + void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} + """; await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter8() { - var markup = @" -using System.Threading; -public class C -{ - int this[CancellationToken cancellationToken] => throw null; - int this[CancellationToken c$$] => throw null; -} -"; + var markup = """ + using System.Threading; + public class C + { + int this[CancellationToken cancellationToken] => throw null; + int this[CancellationToken c$$] => throw null; + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter9() { - var markup = @" -using System.Threading; -public class C -{ - int this[CancellationToken cancellationToken] => throw null; - int this[CancellationToken cancellationToken, CancellationToken c$$] => throw null; -} -"; + var markup = """ + using System.Threading; + public class C + { + int this[CancellationToken cancellationToken] => throw null; + int this[CancellationToken cancellationToken, CancellationToken c$$] => throw null; + } + """; await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); } @@ -611,15 +613,15 @@ public class C [WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter10(LanguageVersion languageVersion) { - var source = @" -public class DbContext { } -public class C -{ - void Goo(DbContext context) { - void InnerGoo(DbContext $$) { } - } -} -"; + var source = """ + public class DbContext { } + public class C + { + void Goo(DbContext context) { + void InnerGoo(DbContext $$) { } + } + } + """; var markup = GetMarkup(source, languageVersion); await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); @@ -641,16 +643,16 @@ void InnerGoo(DbContext $$) { } [WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter11(LanguageVersion languageVersion) { - var source = @" -public class DbContext { } -public class C -{ - void Goo() { - DbContext context; - void InnerGoo(DbContext $$) { } - } -} -"; + var source = """ + public class DbContext { } + public class C + { + void Goo() { + DbContext context; + void InnerGoo(DbContext $$) { } + } + } + """; var markup = GetMarkup(source, languageVersion); await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); @@ -672,16 +674,16 @@ void InnerGoo(DbContext $$) { } [WorkItem("https://github.com/dotnet/roslyn/issues/45492")] public async Task Parameter12(LanguageVersion languageVersion) { - var source = @" -public class DbContext { } -public class C -{ - DbContext dbContext; - void Goo(DbContext context) { - void InnerGoo(DbContext $$) { } - } -} -"; + var source = """ + public class DbContext { } + public class C + { + DbContext dbContext; + void Goo(DbContext context) { + void InnerGoo(DbContext $$) { } + } + } + """; var markup = GetMarkup(source, languageVersion); await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); @@ -708,13 +710,13 @@ public async Task Parameter13() NamingStyleFallbackOptions = ParameterCamelCaseWithPascalCaseFallback() }; - var markup = @" -using System.Threading; -public class C -{ - void Goo(CancellationToken $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + void Goo(CancellationToken $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter, options: options); await VerifyItemIsAbsentAsync(markup, "CancellationToken", options: options); } @@ -722,15 +724,15 @@ void Goo(CancellationToken $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task SuggestParameterNamesFromExistingOverloads() { - var markup = @" -using System.Threading; -public class C -{ - void M(CancellationToken myTok) { } + var markup = """ + using System.Threading; + public class C + { + void M(CancellationToken myTok) { } - void M(CancellationToken $$ -} -"; + void M(CancellationToken $$ + } + """; await VerifyItemExistsAsync(markup, "myTok", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } @@ -738,15 +740,15 @@ void M(CancellationToken $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task SuggestParameterNamesFromExistingOverloads_Constructor() { - var markup = @" -using System.Threading; -public class C -{ - public C(string firstName, string middleName, string lastName) { } + var markup = """ + using System.Threading; + public class C + { + public C(string firstName, string middleName, string lastName) { } - public C(string firstName, string $$) -} -"; + public C(string firstName, string $$) + } + """; await VerifyItemExistsAsync(markup, "middleName", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "lastName", glyph: (int)Glyph.Parameter); await VerifyItemIsAbsentAsync(markup, "firstName"); @@ -755,27 +757,27 @@ public C(string firstName, string $$) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task DoNotSuggestParameterNamesFromTheSameOverload() { - var markup = @" -public class C -{ - void M(string name, string $$) { } -} -"; + var markup = """ + public class C + { + void M(string name, string $$) { } + } + """; await VerifyItemIsAbsentAsync(markup, "name"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task DoNotSuggestParameterNamesFromNonOverloads() { - var markup = @" -using System.Threading; -public class C -{ - void M1(CancellationToken myTok) { } + var markup = """ + using System.Threading; + public class C + { + void M1(CancellationToken myTok) { } - void M2(CancellationToken $$ -} -"; + void M2(CancellationToken $$ + } + """; await VerifyItemIsAbsentAsync(markup, "myTok"); await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); } @@ -783,44 +785,44 @@ void M2(CancellationToken $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task DoNotSuggestInGenericType() { - var markup = @" -using System.Collections.Generic; -public class C -{ - void M(IEnumerable numbers) { } + var markup = """ + using System.Collections.Generic; + public class C + { + void M(IEnumerable numbers) { } - void M(List<$$>) { } -} -"; + void M(List<$$>) { } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] public async Task DoNotSuggestInOptionalParameterDefaultValue() { - var markup = @" -using System.Collections.Generic; -public class C -{ - private const int ZERO = 0; - void M(int num = ZERO) { } + var markup = """ + using System.Collections.Generic; + public class C + { + private const int ZERO = 0; + void M(int num = ZERO) { } - void M(int x, int num = $$) { } -} -"; + void M(int x, int num = $$) { } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] public async Task EscapeKeywords1() { - var markup = @" -using System.Text; -public class C -{ - void Goo(StringBuilder $$) {} -} -"; + var markup = """ + using System.Text; + public class C + { + void Goo(StringBuilder $$) {} + } + """; await VerifyItemExistsAsync(markup, "stringBuilder", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "@string", glyph: (int)Glyph.Parameter); await VerifyItemExistsAsync(markup, "builder", glyph: (int)Glyph.Parameter); @@ -829,45 +831,45 @@ void Goo(StringBuilder $$) {} [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] public async Task EscapeKeywords2() { - var markup = @" -class For { } -public class C -{ - void Goo(For $$) {} -} -"; + var markup = """ + class For { } + public class C + { + void Goo(For $$) {} + } + """; await VerifyItemExistsAsync(markup, "@for", glyph: (int)Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] public async Task EscapeKeywords3() { - var markup = @" -class For { } -public class C -{ - void goo() - { - For $$ - } -} -"; + var markup = """ + class For { } + public class C + { + void goo() + { + For $$ + } + } + """; await VerifyItemExistsAsync(markup, "@for"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] public async Task EscapeKeywords4() { - var markup = @" -using System.Text; -public class C -{ - void goo() - { - StringBuilder $$ - } -} -"; + var markup = """ + using System.Text; + public class C + { + void goo() + { + StringBuilder $$ + } + } + """; await VerifyItemExistsAsync(markup, "stringBuilder"); await VerifyItemExistsAsync(markup, "@string"); await VerifyItemExistsAsync(markup, "builder"); @@ -876,17 +878,17 @@ void goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25214")] public async Task TypeImplementsLazyOfType1() { - var markup = @" -using System; -using System.Collections.Generic; + var markup = """ + using System; + using System.Collections.Generic; -internal class Example -{ - public Lazy $$ -} + internal class Example + { + public Lazy $$ + } -public class Item { } -"; + public class Item { } + """; await VerifyItemExistsAsync(markup, "item"); await VerifyItemExistsAsync(markup, "Item"); await VerifyItemExistsAsync(markup, "GetItem"); @@ -895,17 +897,17 @@ public class Item { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25214")] public async Task TypeImplementsLazyOfType2() { - var markup = @" -using System; -using System.Collections.Generic; + var markup = """ + using System; + using System.Collections.Generic; -internal class Example -{ - public List> $$ -} + internal class Example + { + public List> $$ + } -public class Item { } -"; + public class Item { } + """; await VerifyItemExistsAsync(markup, "items"); await VerifyItemExistsAsync(markup, "Items"); await VerifyItemExistsAsync(markup, "GetItems"); @@ -914,180 +916,180 @@ public class Item { } [Fact] public async Task NoSuggestionsForInt() { - var markup = @" -using System.Threading; -public class C -{ - int $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + int $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForLong() { - var markup = @" -using System.Threading; -public class C -{ - long $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + long $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForDouble() { - var markup = @" -using System.Threading; -public class C -{ - double $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + double $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForFloat() { - var markup = @" -using System.Threading; -public class C -{ - float $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + float $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForSbyte() { - var markup = @" -using System.Threading; -public class C -{ - sbyte $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + sbyte $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForShort() { - var markup = @" -using System.Threading; -public class C -{ - short $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + short $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForUint() { - var markup = @" -using System.Threading; -public class C -{ - uint $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + uint $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForUlong() { - var markup = @" -using System.Threading; -public class C -{ - ulong $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + ulong $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task SuggestionsForUShort() { - var markup = @" -using System.Threading; -public class C -{ - ushort $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + ushort $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForBool() { - var markup = @" -using System.Threading; -public class C -{ - bool $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + bool $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForByte() { - var markup = @" -using System.Threading; -public class C -{ - byte $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + byte $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForChar() { - var markup = @" -using System.Threading; -public class C -{ - char $$ -} -"; + var markup = """ + using System.Threading; + public class C + { + char $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSuggestionsForString() { - var markup = @" -public class C -{ - string $$ -} -"; + var markup = """ + public class C + { + string $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NoSingleLetterClassNameSuggested() { - var markup = @" -public class C -{ - C $$ -} -"; + var markup = """ + public class C + { + C $$ + } + """; await VerifyItemIsAbsentAsync(markup, "C"); await VerifyItemIsAbsentAsync(markup, "c"); } @@ -1095,13 +1097,13 @@ public class C [Fact] public async Task ArrayElementTypeSuggested() { - var markup = @" -using System.Threading; -public class MyClass -{ - MyClass[] $$ -} -"; + var markup = """ + using System.Threading; + public class MyClass + { + MyClass[] $$ + } + """; await VerifyItemExistsAsync(markup, "MyClasses"); await VerifyItemIsAbsentAsync(markup, "Array"); } @@ -1109,63 +1111,63 @@ public class MyClass [Fact] public async Task NotTriggeredByVar() { - var markup = @" -public class C -{ - var $$ -} -"; + var markup = """ + public class C + { + var $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task NotAfterVoid() { - var markup = @" -public class C -{ - void $$ -} -"; + var markup = """ + public class C + { + void $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task AfterGeneric() { - var markup = @" -public class C -{ - System.Collections.Generic.IEnumerable $$ -} -"; + var markup = """ + public class C + { + System.Collections.Generic.IEnumerable $$ + } + """; await VerifyItemExistsAsync(markup, "GetCs"); } [Fact] public async Task NothingAfterVar() { - var markup = @" -public class C -{ - void goo() - { - var $$ - } -} -"; + var markup = """ + public class C + { + void goo() + { + var $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task TestCorrectOrder() { - var markup = @" -public class MyClass -{ - MyClass $$ -} -"; + var markup = """ + public class MyClass + { + MyClass $$ + } + """; var items = await GetCompletionItemsAsync(markup, SourceCodeKind.Regular); Assert.Equal( new[] { "myClass", "my", "@class", "MyClass", "My", "Class", "GetMyClass", "GetMy", "GetClass" }, @@ -1175,12 +1177,12 @@ public class MyClass [Fact] public async Task TestDescriptionInsideClass() { - var markup = @" -public class MyClass -{ - MyClass $$ -} -"; + var markup = """ + public class MyClass + { + MyClass $$ + } + """; await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); @@ -1189,15 +1191,15 @@ public class MyClass [Fact] public async Task TestDescriptionInsideMethod() { - var markup = @" -public class MyClass -{ - void M() - { - MyClass $$ - } -} -"; + var markup = """ + public class MyClass + { + void M() + { + MyClass $$ + } + } + """; await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemIsAbsentAsync(markup, "MyClass"); await VerifyItemIsAbsentAsync(markup, "GetMyClass"); @@ -1206,13 +1208,13 @@ void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20273")] public async Task Alias1() { - var markup = @" -using MyType = System.String; -public class C -{ - MyType $$ -} -"; + var markup = """ + using MyType = System.String; + public class C + { + MyType $$ + } + """; await VerifyItemExistsAsync(markup, "my"); await VerifyItemExistsAsync(markup, "type"); await VerifyItemExistsAsync(markup, "myType"); @@ -1220,13 +1222,13 @@ public class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20273")] public async Task AliasWithInterfacePattern() { - var markup = @" -using IMyType = System.String; -public class C -{ - MyType $$ -} -"; + var markup = """ + using IMyType = System.String; + public class C + { + MyType $$ + } + """; await VerifyItemExistsAsync(markup, "my"); await VerifyItemExistsAsync(markup, "type"); await VerifyItemExistsAsync(markup, "myType"); @@ -1235,233 +1237,233 @@ public class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20016")] public async Task NotAfterExistingName1() { - var markup = @" -using IMyType = System.String; -public class C -{ - MyType myType $$ -} -"; + var markup = """ + using IMyType = System.String; + public class C + { + MyType myType $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20016")] public async Task NotAfterExistingName2() { - var markup = @" -using IMyType = System.String; -public class C -{ - MyType myType, MyType $$ -} -"; + var markup = """ + using IMyType = System.String; + public class C + { + MyType myType, MyType $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19409")] public async Task OutVarArgument() { - var markup = @" -class Test -{ - void Do(out Test goo) - { - Do(out var $$ - } -} -"; + var markup = """ + class Test + { + void Do(out Test goo) + { + Do(out var $$ + } + } + """; await VerifyItemExistsAsync(markup, "test"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19409")] public async Task OutArgument() { - var markup = @" -class Test -{ - void Do(out Test goo) - { - Do(out Test $$ - } -} -"; + var markup = """ + class Test + { + void Do(out Test goo) + { + Do(out Test $$ + } + } + """; await VerifyItemExistsAsync(markup, "test"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19409")] public async Task OutGenericArgument() { - var markup = @" -class Test -{ - void Do(out T goo) - { - Do(out Test $$ - } -} -"; + var markup = """ + class Test + { + void Do(out T goo) + { + Do(out Test $$ + } + } + """; await VerifyItemExistsAsync(markup, "test"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleExpressionDeclaration1() { - var markup = @" -class Test -{ - void Do() - { - (System.Array array, System.Action $$ - } -} -"; + var markup = """ + class Test + { + void Do() + { + (System.Array array, System.Action $$ + } + } + """; await VerifyItemExistsAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleExpressionDeclaration2() { - var markup = @" -class Test -{ - void Do() - { - (array, action $$ - } -} -"; + var markup = """ + class Test + { + void Do() + { + (array, action $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleExpressionDeclaration_NestedTuples() { - var markup = @" -class Test -{ - void Do() - { - ((int i1, int i2), (System.Array array, System.Action $$ - } -} -"; + var markup = """ + class Test + { + void Do() + { + ((int i1, int i2), (System.Array array, System.Action $$ + } + } + """; await VerifyItemExistsAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleExpressionDeclaration_NestedTuples_CompletionInTheMiddle() { - var markup = @" -class Test -{ - void Do() - { - ((System.Array array, System.Action $$), (int i1, int i2)) - } -} -"; + var markup = """ + class Test + { + void Do() + { + ((System.Array array, System.Action $$), (int i1, int i2)) + } + } + """; await VerifyItemExistsAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition1() { - var markup = @" -class Test -{ - void Do() - { - (System.Array $$ - } -} -"; + var markup = """ + class Test + { + void Do() + { + (System.Array $$ + } + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition2() { - var markup = @" -class Test -{ - (System.Array $$) Test() => default; -} -"; + var markup = """ + class Test + { + (System.Array $$) Test() => default; + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition3() { - var markup = @" -class Test -{ - (System.Array array, System.Action $$) Test() => default; -} -"; + var markup = """ + class Test + { + (System.Array array, System.Action $$) Test() => default; + } + """; await VerifyItemExistsAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition4() { - var markup = @" -class Test -{ - (System.Array $$ -} -"; + var markup = """ + class Test + { + (System.Array $$ + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition5() { - var markup = @" -class Test -{ - void M((System.Array $$ -} -"; + var markup = """ + class Test + { + void M((System.Array $$ + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition_NestedTuples() { - var markup = @" -class Test -{ - void M(((int, int), (int, System.Array $$ -} -"; + var markup = """ + class Test + { + void M(((int, int), (int, System.Array $$ + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementDefinition_InMiddleOfTuple() { - var markup = @" -class Test -{ - void M((int, System.Array $$),int) -} -"; + var markup = """ + class Test + { + void M((int, System.Array $$),int) + } + """; await VerifyItemExistsAsync(markup, "array"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementTypeInference() { - var markup = @" -class Test -{ - void Do() - { - (var accessViolationException, var $$) = (new AccessViolationException(), new Action(() => { })); - } -} -"; + var markup = """ + class Test + { + void Do() + { + (var accessViolationException, var $$) = (new AccessViolationException(), new Action(() => { })); + } + } + """; // Currently not supported: await VerifyItemIsAbsentAsync(markup, "action"); // see https://github.com/dotnet/roslyn/issues/27138 @@ -1473,71 +1475,71 @@ void Do() [WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementInGenericTypeArgument() { - var markup = @" -class Test -{ - void Do() - { - System.Func<(System.Action $$ - } -} -"; + var markup = """ + class Test + { + void Do() + { + System.Func<(System.Action $$ + } + } + """; await VerifyItemExistsAsync(markup, "action"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22342")] public async Task TupleElementInvocationInsideTuple() { - var markup = @" -class Test -{ - void Do() - { - int M(int i1, int i2) => i1; - var t=(e1: 1, e2: M(1, $$)); - } -} -"; + var markup = """ + class Test + { + void Do() + { + int M(int i1, int i2) => i1; + var t=(e1: 1, e2: M(1, $$)); + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17987")] public async Task Pluralize1() { - var markup = @" -using System.Collections.Generic; -class Index -{ - IEnumerable $$ -} -"; + var markup = """ + using System.Collections.Generic; + class Index + { + IEnumerable $$ + } + """; await VerifyItemExistsAsync(markup, "Indices"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17987")] public async Task Pluralize2() { - var markup = @" -using System.Collections.Generic; -class Test -{ - IEnumerable> $$ -} -"; + var markup = """ + using System.Collections.Generic; + class Test + { + IEnumerable> $$ + } + """; await VerifyItemExistsAsync(markup, "tests"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17987")] public async Task Pluralize3() { - var markup = @" -using System.Collections.Generic; -using System.Threading; -class Test -{ - IEnumerable $$ -} -"; + var markup = """ + using System.Collections.Generic; + using System.Threading; + class Test + { + IEnumerable $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationTokens"); await VerifyItemExistsAsync(markup, "cancellations"); await VerifyItemExistsAsync(markup, "tokens"); @@ -1546,14 +1548,14 @@ class Test [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17987")] public async Task PluralizeList() { - var markup = @" -using System.Collections.Generic; -using System.Threading; -class Test -{ - List $$ -} -"; + var markup = """ + using System.Collections.Generic; + using System.Threading; + class Test + { + List $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationTokens"); await VerifyItemExistsAsync(markup, "cancellations"); await VerifyItemExistsAsync(markup, "tokens"); @@ -1562,14 +1564,14 @@ class Test [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17987")] public async Task PluralizeArray() { - var markup = @" -using System.Collections.Generic; -using System.Threading; -class Test -{ - CancellationToken[] $$ -} -"; + var markup = """ + using System.Collections.Generic; + using System.Threading; + class Test + { + CancellationToken[] $$ + } + """; await VerifyItemExistsAsync(markup, "cancellationTokens"); await VerifyItemExistsAsync(markup, "cancellations"); await VerifyItemExistsAsync(markup, "tokens"); @@ -1578,128 +1580,128 @@ class Test [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37366")] public async Task PluralizeSpan() { - var markup = @" -using System; + var markup = """ + using System; -class Test -{ - void M(Span $$) { } -} -" + Span; + class Test + { + void M(Span $$) { } + } + """ + Span; await VerifyItemExistsAsync(markup, "tests"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37366")] public async Task PluralizeValidGetEnumerator() { - var markup = @" -class MyClass -{ - public void M(MyOwnCollection $$) { } -} + var markup = """ + class MyClass + { + public void M(MyOwnCollection $$) { } + } -class MyOwnCollection -{ - public MyEnumerator GetEnumerator() - { - return new MyEnumerator(); - } + class MyOwnCollection + { + public MyEnumerator GetEnumerator() + { + return new MyEnumerator(); + } - public class MyEnumerator - { - public T Current { get; } - - public bool MoveNext() { return false; } - } -} -"; + public class MyEnumerator + { + public T Current { get; } + + public bool MoveNext() { return false; } + } + } + """; await VerifyItemExistsAsync(markup, "myClasses"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37366")] public async Task PluralizeValidGetAsyncEnumerator() { - var markup = @" -using System.Threading.Tasks; + var markup = """ + using System.Threading.Tasks; -class MyClass -{ - public void M(MyOwnCollection $$) { } -} + class MyClass + { + public void M(MyOwnCollection $$) { } + } -class MyOwnCollection -{ - public MyEnumerator GetAsyncEnumerator() - { - return new MyEnumerator(); - } + class MyOwnCollection + { + public MyEnumerator GetAsyncEnumerator() + { + return new MyEnumerator(); + } - public class MyEnumerator - { - public T Current { get; } - - public Task MoveNextAsync() { return Task.FromResult(false); } - } -} -"; + public class MyEnumerator + { + public T Current { get; } + + public Task MoveNextAsync() { return Task.FromResult(false); } + } + } + """; await VerifyItemExistsAsync(markup, "myClasses"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37366")] public async Task PluralizeForUnimplementedIEnumerable() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -class MyClass -{ - public void M(MyOwnCollection $$) { } -} + class MyClass + { + public void M(MyOwnCollection $$) { } + } -class MyOwnCollection : IEnumerable -{ -} -"; + class MyOwnCollection : IEnumerable + { + } + """; await VerifyItemExistsAsync(markup, "myClasses"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37366")] public async Task PluralizeForUnimplementedIAsyncEnumerable() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -class MyClass -{ - public void M(MyOwnCollection $$) { } -} + class MyClass + { + public void M(MyOwnCollection $$) { } + } -class MyOwnCollection : IAsyncEnumerable -{ -} -" + IAsyncEnumerable; + class MyOwnCollection : IAsyncEnumerable + { + } + """ + IAsyncEnumerable; await VerifyItemExistsAsync(markup, "myClasses"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching1() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static void Main() - { - object obj = null; - if (obj is CancellationToken $$) { } - } -} -"; + public class C + { + public static void Main() + { + object obj = null; + if (obj is CancellationToken $$) { } + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "cancellation"); await VerifyItemExistsAsync(markup, "token"); @@ -1708,18 +1710,18 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching2() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static bool Foo() - { - object obj = null; - return obj is CancellationToken $$ - } -} -"; + public class C + { + public static bool Foo() + { + object obj = null; + return obj is CancellationToken $$ + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "cancellation"); await VerifyItemExistsAsync(markup, "token"); @@ -1728,21 +1730,21 @@ public static bool Foo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching3() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static void Main() - { - object obj = null; - switch(obj) - { - case CancellationToken $$ - } - } -} -"; + public class C + { + public static void Main() + { + object obj = null; + switch(obj) + { + case CancellationToken $$ + } + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "cancellation"); await VerifyItemExistsAsync(markup, "token"); @@ -1751,18 +1753,18 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching4() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static void Main() - { - object obj = null; - if (obj is CancellationToken ca$$) { } - } -} -"; + public class C + { + public static void Main() + { + object obj = null; + if (obj is CancellationToken ca$$) { } + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "cancellation"); } @@ -1770,18 +1772,18 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching5() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static bool Foo() - { - object obj = null; - return obj is CancellationToken to$$ - } -} -"; + public class C + { + public static bool Foo() + { + object obj = null; + return obj is CancellationToken to$$ + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "token"); } @@ -1789,21 +1791,21 @@ public static bool Foo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23497")] public async Task InPatternMatching6() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -public class C -{ - public static void Main() - { - object obj = null; - switch(obj) - { - case CancellationToken to$$ - } - } -} -"; + public class C + { + public static void Main() + { + object obj = null; + switch(obj) + { + case CancellationToken to$$ + } + } + } + """; await VerifyItemExistsAsync(markup, "cancellationToken"); await VerifyItemExistsAsync(markup, "token"); } @@ -1811,136 +1813,136 @@ public static void Main() [Fact] public async Task InUsingStatement1() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - using (StreamReader s$$ - } -} -"; + class C + { + void M() + { + using (StreamReader s$$ + } + } + """; await VerifyItemExistsAsync(markup, "streamReader"); } [Fact] public async Task InUsingStatement2() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - using (StreamReader s1, $$ - } -} -"; + class C + { + void M() + { + using (StreamReader s1, $$ + } + } + """; await VerifyItemExistsAsync(markup, "streamReader"); } [Fact] public async Task InUsingStatement_Var() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - using (var m$$ = new MemoryStream()) - } -} -"; + class C + { + void M() + { + using (var m$$ = new MemoryStream()) + } + } + """; await VerifyItemExistsAsync(markup, "memoryStream"); } [Fact] public async Task InForStatement1() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - for (StreamReader s$$ - } -} -"; + class C + { + void M() + { + for (StreamReader s$$ + } + } + """; await VerifyItemExistsAsync(markup, "streamReader"); } [Fact] public async Task InForStatement2() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - for (StreamReader s1, $$ - } -} -"; + class C + { + void M() + { + for (StreamReader s1, $$ + } + } + """; await VerifyItemExistsAsync(markup, "streamReader"); } [Fact] public async Task InForStatement_Var() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - for (var m$$ = new MemoryStream(); - } -} -"; + class C + { + void M() + { + for (var m$$ = new MemoryStream(); + } + } + """; await VerifyItemExistsAsync(markup, "memoryStream"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26021")] public async Task InForEachStatement() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - foreach (StreamReader $$ - } -} -"; + class C + { + void M() + { + foreach (StreamReader $$ + } + } + """; await VerifyItemExistsAsync(markup, "streamReader"); } [Fact] public async Task InForEachStatement_Var() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - void M() - { - foreach (var m$$ in new[] { new MemoryStream() }) - } -} -"; + class C + { + void M() + { + foreach (var m$$ in new[] { new MemoryStream() }) + } + } + """; await VerifyItemExistsAsync(markup, "memoryStream"); } @@ -1949,173 +1951,173 @@ public async Task DisabledByOption() { ShowNameSuggestions = false; - var markup = @" -class Test -{ - Test $$ -} -"; + var markup = """ + class Test + { + Test $$ + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsIEnumerableOfType() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method() - { - Container $$ - } -} + public class Class1 + { + public void Method() + { + Container $$ + } + } -public class Container : ContainerBase { } -public class ContainerBase : IEnumerable { } -"; + public class Container : ContainerBase { } + public class ContainerBase : IEnumerable { } + """; await VerifyItemExistsAsync(markup, "container"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsIEnumerableOfType2() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method() - { - Container $$ - } -} + public class Class1 + { + public void Method() + { + Container $$ + } + } -public class ContainerBase : IEnumerable { } -public class Container : ContainerBase { } -"; + public class ContainerBase : IEnumerable { } + public class Container : ContainerBase { } + """; await VerifyItemExistsAsync(markup, "container"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsIEnumerableOfType3() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method() - { - Container $$ - } -} + public class Class1 + { + public void Method() + { + Container $$ + } + } -public class Container : IEnumerable { } -"; + public class Container : IEnumerable { } + """; await VerifyItemExistsAsync(markup, "container"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsIEnumerableOfType4() { - var markup = @" -using System.Collections.Generic; -using System.Threading.Tasks; + var markup = """ + using System.Collections.Generic; + using System.Threading.Tasks; -public class Class1 -{ - public void Method() - { - TaskType $$ - } -} + public class Class1 + { + public void Method() + { + TaskType $$ + } + } -public class ContainerBase : IEnumerable { } -public class Container : ContainerBase { } -public class TaskType : Task { } -"; + public class ContainerBase : IEnumerable { } + public class Container : ContainerBase { } + public class TaskType : Task { } + """; await VerifyItemExistsAsync(markup, "taskType"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsTaskOfType() { - var markup = @" -using System.Threading.Tasks; + var markup = """ + using System.Threading.Tasks; -public class Class1 -{ - public void Method() - { - Container $$ - } -} + public class Class1 + { + public void Method() + { + Container $$ + } + } -public class Container : ContainerBase { } -public class ContainerBase : Task { } -"; + public class Container : ContainerBase { } + public class ContainerBase : Task { } + """; await VerifyItemExistsAsync(markup, "container"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsTaskOfType2() { - var markup = @" -using System.Threading.Tasks; + var markup = """ + using System.Threading.Tasks; -public class Class1 -{ - public void Method() - { - Container $$ - } -} + public class Class1 + { + public void Method() + { + Container $$ + } + } -public class Container : Task { } -public class ContainerBase : Container { } -"; + public class Container : Task { } + public class ContainerBase : Container { } + """; await VerifyItemExistsAsync(markup, "container"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeImplementsTaskOfType3() { - var markup = @" -using System.Collections.Generic; -using System.Threading.Tasks; + var markup = """ + using System.Collections.Generic; + using System.Threading.Tasks; -public class Class1 -{ - public void Method() - { - EnumerableType $$ - } -} + public class Class1 + { + public void Method() + { + EnumerableType $$ + } + } -public class TaskType : TaskTypeBase { } -public class TaskTypeBase : Task { } -public class EnumerableType : IEnumerable { } -"; + public class TaskType : TaskTypeBase { } + public class TaskTypeBase : Task { } + public class EnumerableType : IEnumerable { } + """; await VerifyItemExistsAsync(markup, "taskTypes"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23590")] public async Task TypeIsNullableOfNullable() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method() - { - // This code isn't legal, but we want to ensure we don't crash in this broken code scenario - IEnumerable> $$ - } -} -"; + public class Class1 + { + public void Method() + { + // This code isn't legal, but we want to ensure we don't crash in this broken code scenario + IEnumerable> $$ + } + } + """; await VerifyItemExistsAsync(markup, "nullables"); } @@ -2123,19 +2125,19 @@ public void Method() [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableStructInLocalWithNullableTypeName() { - var markup = @" -using System; + var markup = """ + using System; -public struct ImmutableArray : System.Collections.Generic.IEnumerable { } + public struct ImmutableArray : System.Collections.Generic.IEnumerable { } -public class Class1 -{ - public void Method() - { - Nullable> $$ - } -} -"; + public class Class1 + { + public void Method() + { + Nullable> $$ + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } @@ -2143,19 +2145,19 @@ public void Method() [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableStructInLocalWithQuestionMark() { - var markup = @" -using System.Collections.Immutable; + var markup = """ + using System.Collections.Immutable; -public struct ImmutableArray : System.Collections.Generic.IEnumerable { } + public struct ImmutableArray : System.Collections.Generic.IEnumerable { } -public class Class1 -{ - public void Method() - { - ImmutableArray? $$ - } -} -"; + public class Class1 + { + public void Method() + { + ImmutableArray? $$ + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } @@ -2163,19 +2165,19 @@ public void Method() [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableReferenceInLocal() { - var markup = @" -#nullable enable + var markup = """ + #nullable enable -using System.Collections.Generic; + using System.Collections.Generic; -public class Class1 -{ - public void Method() - { - IEnumerable? $$ - } -} -"; + public class Class1 + { + public void Method() + { + IEnumerable? $$ + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } @@ -2183,18 +2185,18 @@ public void Method() [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableStructInParameterWithNullableTypeName() { - var markup = @" -using System; + var markup = """ + using System; -public struct ImmutableArray : System.Collections.Generic.IEnumerable { } + public struct ImmutableArray : System.Collections.Generic.IEnumerable { } -public class Class1 -{ - public void Method(Nullable> $$) - { - } -} -"; + public class Class1 + { + public void Method(Nullable> $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } @@ -2202,16 +2204,16 @@ public void Method(Nullable> $$) [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableStructInParameterWithQuestionMark() { - var markup = @" -public struct ImmutableArray : System.Collections.Generic.IEnumerable { } - -public class Class1 -{ - public void Method(ImmutableArray? $$) - { - } -} -"; + var markup = """ + public struct ImmutableArray : System.Collections.Generic.IEnumerable { } + + public class Class1 + { + public void Method(ImmutableArray? $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } @@ -2219,130 +2221,130 @@ public void Method(ImmutableArray? $$) [WorkItem("https://developercommunity2.visualstudio.com/t/Regression-from-1675-Suggested-varia/1220195")] public async Task TypeIsNullableReferenceInParameter() { - var markup = @" -#nullable enable + var markup = """ + #nullable enable -using System.Collections.Generic; + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable? $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable? $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableParameterOfUnmanagedType() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "ints"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableParameterOfObject() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "objects"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableParameterOfString() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "strings"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableGenericTParameter() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "values"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableGenericTNameParameter() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "results"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableGenericUnexpectedlyNamedParameter() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "args"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36364")] public async Task EnumerableGenericUnexpectedlyNamedParameterBeginsWithT() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -public class Class1 -{ - public void Method(IEnumerable $$) - { - } -} -"; + public class Class1 + { + public void Method(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "types"); } @@ -2358,12 +2360,12 @@ public async Task CustomNamingStyleInsideClass() NamingStyleFallbackOptions = NamesEndWithSuffixPreferences() }; - var markup = @" -class Configuration -{ - Configuration $$ -} -"; + var markup = """ + class Configuration + { + Configuration $$ + } + """; await VerifyItemExistsAsync(markup, "ConfigurationField", glyph: (int)Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name, options: options); await VerifyItemExistsAsync(markup, "ConfigurationProperty", glyph: (int)Glyph.PropertyPublic, @@ -2386,15 +2388,15 @@ public async Task CustomNamingStyleInsideMethod() NamingStyleFallbackOptions = NamesEndWithSuffixPreferences() }; - var markup = @" -class Configuration -{ - void M() - { - Configuration $$ - } -} -"; + var markup = """ + class Configuration + { + void M() + { + Configuration $$ + } + } + """; await VerifyItemExistsAsync(markup, "ConfigurationLocal", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name, options: options); await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: (int)Glyph.MethodPublic, @@ -2407,22 +2409,22 @@ await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: (int)Gl [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionDoesNotUseForeachVariableName() { - var markup = @" -class ClassA -{ - class ClassB {} + var markup = """ + class ClassA + { + class ClassB {} - readonly List classBList; + readonly List classBList; - void M() - { - foreach (var classB in classBList) - { - ClassB $$ - } - } -} -"; + void M() + { + foreach (var classB in classBList) + { + ClassB $$ + } + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); @@ -2431,17 +2433,17 @@ await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionDoesNotUseParameterName() { - var markup = @" -class ClassA -{ - class ClassB { } + var markup = """ + class ClassA + { + class ClassB { } - void M(ClassB classB) - { - ClassB $$ - } -} -"; + void M(ClassB classB) + { + ClassB $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); @@ -2450,19 +2452,19 @@ await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionCanUsePropertyName() { - var markup = @" -class ClassA -{ - class ClassB { } + var markup = """ + class ClassA + { + class ClassB { } - ClassB classB { get; set; } + ClassB classB { get; set; } - void M() - { - ClassB $$ - } -} -"; + void M() + { + ClassB $$ + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2470,19 +2472,19 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionCanUseFieldName() { - var markup = @" -class ClassA -{ - class ClassB { } + var markup = """ + class ClassA + { + class ClassB { } - ClassB classB; + ClassB classB; - void M() - { - ClassB $$ - } -} -"; + void M() + { + ClassB $$ + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2490,18 +2492,18 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionDoesNotUseLocalName() { - var markup = @" -class ClassA -{ - class ClassB { } + var markup = """ + class ClassA + { + class ClassB { } - void M() - { - ClassB classB = new ClassB(); - ClassB $$ - } -} -"; + void M() + { + ClassB classB = new ClassB(); + ClassB $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); @@ -2510,19 +2512,19 @@ await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionDoesNotUseLocalNameMultiple() { - var markup = @" -class ClassA -{ - class ClassB { } - - void M() - { - ClassB classB = new ClassB(); - ClassB classB1 = new ClassB(); - ClassB $$ - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + + void M() + { + ClassB classB = new ClassB(); + ClassB classB1 = new ClassB(); + ClassB $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemIsAbsentAsync(markup, "classB1"); await VerifyItemExistsAsync(markup, "classB2", glyph: (int)Glyph.Local, @@ -2532,21 +2534,21 @@ await VerifyItemExistsAsync(markup, "classB2", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionDoesNotUseLocalInsideIf() { - var markup = @" -class ClassA -{ - class ClassB { } - - void M(bool flag) - { - ClassB $$ - if (flag) - { - ClassB classB = new ClassB(); - } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + + void M(bool flag) + { + ClassB $$ + if (flag) + { + ClassB classB = new ClassB(); + } + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); @@ -2555,15 +2557,15 @@ await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionCanUseClassName() { - var markup = @" -class classA -{ - void M() - { - classA $$ - } -} -"; + var markup = """ + class classA + { + void M() + { + classA $$ + } + } + """; await VerifyItemExistsAsync(markup, "classA", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2571,22 +2573,22 @@ await VerifyItemExistsAsync(markup, "classA", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31304")] public async Task TestCompletionCanUseLocalInDifferentScope() { - var markup = @" -class ClassA -{ - class ClassB { } + var markup = """ + class ClassA + { + class ClassB { } - void M() - { - ClassB classB = new ClassB(); - } + void M() + { + ClassB classB = new ClassB(); + } - void M2() - { - ClassB $$ - } -} -"; + void M2() + { + ClassB $$ + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2598,17 +2600,17 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, [WorkItem("https://github.com/dotnet/roslyn/issues/42049")] public async Task TestUseLocalAsLocalFunctionParameter(LanguageVersion languageVersion) { - var source = @" -class ClassA -{ - class ClassB { } - void M() - { - ClassB classB = new ClassB(); - void LocalM1(ClassB $$) { } - } -} -"; + var source = """ + class ClassA + { + class ClassB { } + void M() + { + ClassB classB = new ClassB(); + void LocalM1(ClassB $$) { } + } + } + """; var markup = GetMarkup(source, languageVersion); if (languageVersion.MapSpecifiedToEffectiveVersion() >= LanguageVersion.CSharp8) @@ -2629,20 +2631,20 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, [WorkItem("https://github.com/dotnet/roslyn/issues/42049")] public async Task TestCompletionDoesNotUseLocalAsLocalFunctionVariable(LanguageVersion languageVersion) { - var source = @" -class ClassA -{ - class ClassB { } - void M() - { - ClassB classB = new ClassB(); - void LocalM1() - { - ClassB $$ - } - } -} -"; + var source = """ + class ClassA + { + class ClassB { } + void M() + { + ClassB classB = new ClassB(); + void LocalM1() + { + ClassB $$ + } + } + } + """; var markup = GetMarkup(source, languageVersion); await VerifyItemIsAbsentAsync(markup, "classB"); } @@ -2650,62 +2652,62 @@ void LocalM1() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionDoesNotUseLocalInNestedLocalFunction() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - ClassB classB = new ClassB(); - void LocalM1() - { - void LocalM2() - { - ClassB $$ - } - } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + ClassB classB = new ClassB(); + void LocalM1() + { + void LocalM2() + { + ClassB $$ + } + } + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionDoesNotUseLocalFunctionParameterInNestedLocalFunction() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - void LocalM1(ClassB classB) - { - void LocalM2() - { - ClassB $$ - } - } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + void LocalM1(ClassB classB) + { + void LocalM2() + { + ClassB $$ + } + } + } + } + """; await VerifyItemIsAbsentAsync(markup, "classB"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionCanUseLocalFunctionParameterAsParameter() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - void LocalM1(ClassB classB) { } - void LocalM2(ClassB $$) { } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + void LocalM1(ClassB classB) { } + void LocalM2(ClassB $$) { } + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2713,20 +2715,20 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionCanUseLocalFunctionVariableAsParameter() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - void LocalM1() - { - ClassB classB - } - void LocalM2(ClassB $$) { } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + void LocalM1() + { + ClassB classB + } + void LocalM2(ClassB $$) { } + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2734,20 +2736,20 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionCanUseLocalFunctionParameterAsVariable() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - void LocalM1(ClassB classB) { } - void LocalM2() - { - ClassB $$ - } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + void LocalM1(ClassB classB) { } + void LocalM2() + { + ClassB $$ + } + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2755,23 +2757,23 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35891")] public async Task TestCompletionCanUseLocalFunctionVariableAsVariable() { - var markup = @" -class ClassA -{ - class ClassB { } - void M() - { - void LocalM1() - { - ClassB classB - } - void LocalM2() - { - ClassB $$ - } - } -} -"; + var markup = """ + class ClassA + { + class ClassB { } + void M() + { + void LocalM1() + { + ClassB classB + } + void LocalM2() + { + ClassB $$ + } + } + } + """; await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2779,12 +2781,12 @@ await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, [Fact] public async Task TestNotForUnboundAsync() { - var markup = @" -class C -{ - async $$ -} -"; + var markup = """ + class C + { + async $$ + } + """; await VerifyItemIsAbsentAsync(markup, "async"); await VerifyItemIsAbsentAsync(markup, "Async"); await VerifyItemIsAbsentAsync(markup, "GetAsync"); @@ -2802,51 +2804,51 @@ public async Task ConflictingLocalVariable() NamingStyleFallbackOptions = MultipleCamelCaseLocalRules() }; - var markup = @" -public class MyClass -{ - void M() - { - MyClass myClass; - MyClass $$ - } -} -"; + var markup = """ + public class MyClass + { + void M() + { + MyClass myClass; + MyClass $$ + } + } + """; await VerifyItemExistsAsync(markup, "myClass1", glyph: (int)Glyph.Local, options: options); } [Fact] public async Task TestNotForNonTypeSymbol() { - var markup = @" -using System; -class C -{ - Console.BackgroundColor $$ -} -"; + var markup = """ + using System; + class C + { + Console.BackgroundColor $$ + } + """; await VerifyItemIsAbsentAsync(markup, "consoleColor"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29487")] public async Task TestForOutParam1() { - var markup = @" -using System.Threading; + var markup = """ + using System.Threading; -class C -{ - void Main() - { - Goo(out var $$) - } + class C + { + void Main() + { + Goo(out var $$) + } - void Goo(out CancellationToken interestingName) - { + void Goo(out CancellationToken interestingName) + { - } -} -"; + } + } + """; await VerifyItemExistsAsync(markup, "interestingName"); await VerifyItemExistsAsync(markup, "cancellationToken"); } @@ -2854,63 +2856,63 @@ void Goo(out CancellationToken interestingName) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/43602")] public async Task TestForOutParam2() { - var markup = @" -class C -{ - void Main() - { - int.TryParse("""", out var $$) - } -} -"; + var markup = """ + class C + { + void Main() + { + int.TryParse("", out var $$) + } + } + """; await VerifyItemExistsAsync(markup, "result"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49791")] public async Task TestForErrorType1() { - var markup = @" -class C -{ - void Main(string _rootPath) - { - _rootPath $$ - _rootPath = null; - } -} -"; + var markup = """ + class C + { + void Main(string _rootPath) + { + _rootPath $$ + _rootPath = null; + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49791")] public async Task TestForErrorType2() { - var markup = @" -class C -{ - void Main() - { - Goo $$ - Goo = null; - } -} -"; + var markup = """ + class C + { + void Main() + { + Goo $$ + Goo = null; + } + } + """; await VerifyItemExistsAsync(markup, "goo"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36352")] public async Task InferCollectionInErrorCase1() { - var markup = @" -class Customer { } + var markup = """ + class Customer { } -class V -{ - void M(IEnumerable $$) - { - } -} -"; + class V + { + void M(IEnumerable $$) + { + } + } + """; await VerifyItemExistsAsync(markup, "customers"); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs index f34a0f12648c6..ac0f2dd5803a3 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs @@ -27,12 +27,12 @@ public class DeclarationNameCompletion_ContextTests [Fact] public async Task AfterTypeInClass1() { - var markup = @" -class C -{ - int $$ -} -"; + var markup = """ + class C + { + int $$ + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Field), new SymbolKindOrTypeKind(SymbolKind.Property), @@ -45,12 +45,12 @@ await VerifySymbolKinds(markup, [Fact] public async Task AfterTypeInClassWithAccessibility() { - var markup = @" -class C -{ - public int $$ -} -"; + var markup = """ + class C + { + public int $$ + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Field), new SymbolKindOrTypeKind(SymbolKind.Property), @@ -63,12 +63,12 @@ await VerifySymbolKinds(markup, [Fact] public async Task AfterTypeInClassVirtual() { - var markup = @" -class C -{ - public virtual int $$ -} -"; + var markup = """ + class C + { + public virtual int $$ + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Property), new SymbolKindOrTypeKind(MethodKind.Ordinary)); @@ -80,12 +80,12 @@ await VerifySymbolKinds(markup, [Fact] public async Task AfterTypeInClassStatic() { - var markup = @" -class C -{ - private static int $$ -} -"; + var markup = """ + class C + { + private static int $$ + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Field), new SymbolKindOrTypeKind(SymbolKind.Property), @@ -98,12 +98,12 @@ await VerifySymbolKinds(markup, [Fact] public async Task AfterTypeInClassConst() { - var markup = @" -class C -{ - private const int $$ -} -"; + var markup = """ + class C + { + private const int $$ + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Field)); await VerifyModifiers(markup, new DeclarationModifiers(isConst: true)); @@ -114,15 +114,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task VariableDeclaration1() { - var markup = @" -class C -{ - void goo() - { - int $$ - } -} -"; + var markup = """ + class C + { + void goo() + { + int $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); @@ -134,15 +134,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task VariableDeclaration2() { - var markup = @" -class C -{ - void goo() - { - int c1, $$ - } -} -"; + var markup = """ + class C + { + void goo() + { + int c1, $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -153,15 +153,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task ReadonlyVariableDeclaration1() { - var markup = @" -class C -{ - void goo() - { - readonly int $$ - } -} -"; + var markup = """ + class C + { + void goo() + { + readonly int $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); @@ -173,15 +173,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task ReadonlyVariableDeclaration2() { - var markup = @" -class C -{ - void goo() - { - readonly int c1, $$ - } -} -"; + var markup = """ + class C + { + void goo() + { + readonly int c1, $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers(isReadOnly: true)); @@ -192,15 +192,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task UsingVariableDeclaration1() { - var markup = @" -class C -{ - void M() - { - using (int i$$ - } -} -"; + var markup = """ + class C + { + void M() + { + using (int i$$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -211,15 +211,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task UsingVariableDeclaration2() { - var markup = @" -class C -{ - void M() - { - using (int i1, $$ - } -} -"; + var markup = """ + class C + { + void M() + { + using (int i1, $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -230,15 +230,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task ForVariableDeclaration1() { - var markup = @" -class C -{ - void M() - { - for (int i$$ - } -} -"; + var markup = """ + class C + { + void M() + { + for (int i$$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -249,15 +249,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task ForVariableDeclaration2() { - var markup = @" -class C -{ - void M() - { - for (int i1, $$ - } -} -"; + var markup = """ + class C + { + void M() + { + for (int i1, $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -268,15 +268,15 @@ await VerifySymbolKinds(markup, [Fact] public async Task ForEachVariableDeclaration() { - var markup = @" -class C -{ - void M() - { - foreach (int $$ - } -} -"; + var markup = """ + class C + { + void M() + { + foreach (int $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -287,13 +287,13 @@ await VerifySymbolKinds(markup, [Fact] public async Task Parameter1() { - var markup = @" -class C -{ - void goo(C $$ - } -} -"; + var markup = """ + class C + { + void goo(C $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -304,13 +304,13 @@ await VerifySymbolKinds(markup, [Fact] public async Task Parameter2() { - var markup = @" -class C -{ - void goo(C c1, C $$ - } -} -"; + var markup = """ + class C + { + void goo(C c1, C $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -321,13 +321,13 @@ await VerifySymbolKinds(markup, [Fact] public async Task ParameterAfterPredefinedType1() { - var markup = @" -class C -{ - void goo(string $$ - } -} -"; + var markup = """ + class C + { + void goo(string $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -338,13 +338,13 @@ await VerifySymbolKinds(markup, [Fact] public async Task ParameterAfterPredefinedType2() { - var markup = @" -class C -{ - void goo(C c1, string $$ - } -} -"; + var markup = """ + class C + { + void goo(C c1, string $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -355,14 +355,14 @@ await VerifySymbolKinds(markup, [Fact] public async Task ParameterAfterGeneric() { - var markup = @" -using System.Collections.Generic; -class C -{ - void goo(C c1, List $$ - } -} -"; + var markup = """ + using System.Collections.Generic; + class C + { + void goo(C c1, List $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); @@ -373,11 +373,11 @@ await VerifySymbolKinds(markup, [Fact] public async Task ClassTypeParameter1() { - var markup = @" -class C<$$ -{ -} -"; + var markup = """ + class C<$$ + { + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.TypeParameter)); } @@ -385,11 +385,11 @@ await VerifySymbolKinds(markup, [Fact] public async Task ClassTypeParameter2() { - var markup = @" -class C { } - class Program - { - static void Main(string[] args) - { - ReallyLongClassName $$ - } - } -"; + var markup = """ + namespace ConsoleApp1 + { + class ReallyLongClassName { } + class Program + { + static void Main(string[] args) + { + ReallyLongClassName $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); @@ -737,18 +737,18 @@ await VerifySymbolKinds(markup, [Fact] public async Task LocalInsideMethodAfterPredefinedTypeKeyword() { - var markup = @" -namespace ConsoleApp1 -{ - class ReallyLongClassName { } - class Program - { - static void Main(string[] args) - { - string $$ - } - } -"; + var markup = """ + namespace ConsoleApp1 + { + class ReallyLongClassName { } + class Program + { + static void Main(string[] args) + { + string $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); @@ -757,17 +757,17 @@ await VerifySymbolKinds(markup, [Fact] public async Task LocalInsideMethodAfterArray() { - var markup = @" -namespace ConsoleApp1 -{ - class Program - { - static void Main(string[] args) - { - string[] $$ - } - } -"; + var markup = """ + namespace ConsoleApp1 + { + class Program + { + static void Main(string[] args) + { + string[] $$ + } + } + """; await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs index 9a9211cf09887..496a6493e631c 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs @@ -20,31 +20,32 @@ internal override Type GetCompletionProviderType() [Fact] public async Task NullableEnum() { - var markup = @"class Program -{ - static void Main(string[] args) - { - Colors? d = $$ - Colors c = Colors.Blue; - } -} -"; - var colors = @" -enum Colors -{ - Red, - Blue, - Green, -} -"; - var colorsLike = @" -readonly struct Colors -{ - public static readonly Colors Red; - public static readonly Colors Blue; - public static readonly Colors Green; -} -"; + var markup = """ + class Program + { + static void Main(string[] args) + { + Colors? d = $$ + Colors c = Colors.Blue; + } + } + """; + var colors = """ + enum Colors + { + Red, + Blue, + Green, + } + """; + var colorsLike = """ + readonly struct Colors + { + public static readonly Colors Red; + public static readonly Colors Blue; + public static readonly Colors Green; + } + """; await VerifyItemExistsAsync(markup + colors, "Colors"); await VerifyItemIsAbsentAsync(markup + colorsLike, "Colors"); @@ -53,21 +54,22 @@ readonly struct Colors [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_EnumMemberAlways() { - var markup = @" -class Program -{ - public void M() - { - Goo d = $$ - } -} -"; - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] -public enum Goo -{ - Member -}"; + var markup = """ + class Program + { + public void M() + { + Goo d = $$ + } + } + """; + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public enum Goo + { + Member + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, referencedCode: referencedCode, @@ -81,21 +83,22 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_EnumMemberNever() { - var markup = @" -class Program -{ - public void M() - { - Goo d = $$ - } -} -"; - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] -public enum Goo -{ - Member -}"; + var markup = """ + class Program + { + public void M() + { + Goo d = $$ + } + } + """; + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public enum Goo + { + Member + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, referencedCode: referencedCode, @@ -109,21 +112,22 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_EnumMemberAdvanced() { - var markup = @" -class Program -{ - public void M() - { - Goo d = $$ - } -} -"; - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] -public enum Goo -{ - Member -}"; + var markup = """ + class Program + { + public void M() + { + Goo d = $$ + } + } + """; + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public enum Goo + { + Member + } + """; HideAdvancedMembers = true; await VerifyItemInEditorBrowsableContextsAsync( @@ -150,29 +154,30 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/854099")] public async Task NotInComment() { - var markup = @"class Program -{ - static void Main(string[] args) - { - Colors c = // $$ - } -"; - var colors = @" -enum Colors -{ - Red, - Blue, - Green, -} -"; - var colorsLike = @" -readonly struct Colors -{ - public static readonly Colors Red; - public static readonly Colors Blue; - public static readonly Colors Green; -} -"; + var markup = """ + class Program + { + static void Main(string[] args) + { + Colors c = // $$ + } + """; + var colors = """ + enum Colors + { + Red, + Blue, + Green, + } + """; + var colorsLike = """ + readonly struct Colors + { + public static readonly Colors Red; + public static readonly Colors Blue; + public static readonly Colors Green; + } + """; await VerifyNoItemsExistAsync(markup + colors); await VerifyNoItemsExistAsync(markup + colorsLike); @@ -471,21 +476,23 @@ class Program public async Task NoCompletionListTag() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class C -{ - -} + class C + { -class Program -{ - void Goo() - { - C c = $$ - } -}"; + } + + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -493,22 +500,24 @@ void Goo() public async Task CompletionList() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -/// -class C -{ - -} + /// + class C + { -class Program -{ - void Goo() - { - C c = $$ - } -}"; + } + + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyItemExistsAsync(markup, "C"); } @@ -516,22 +525,24 @@ void Goo() public async Task CompletionListCrefToString() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -/// -class C -{ - -} + /// + class C + { -class Program -{ - void Goo() - { - C c = $$ - } -}"; + } + + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyItemExistsAsync(markup, "string", glyph: (int)Glyph.ClassPublic); } @@ -539,22 +550,24 @@ void Goo() public async Task CompletionListEmptyCref() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -/// -class C -{ - -} + /// + class C + { -class Program -{ - void Goo() - { - C c = $$ - } -}"; + } + + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -562,24 +575,26 @@ void Goo() public async Task CompletionListInaccessibleType() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -/// -class C -{ - private class Inner - { - } -} + /// + class C + { + private class Inner + { + } + } -class Program -{ - void Goo() - { - C c = $$ - } -}"; + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -587,24 +602,26 @@ void Goo() public async Task CompletionListNotAType() { var markup = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -/// -class C -{ - public void Z() - { - } -} + /// + class C + { + public void Z() + { + } + } -class Program -{ - void Goo() - { - C c = $$ - } -}"; + class Program + { + void Goo() + { + C c = $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -612,24 +629,25 @@ void Goo() public async Task CompletionListContainingMembers() { var markup = -@" -/// - public class SomeType - { } - - public static class TypeContainer - { - public static SomeType Foo1 = new SomeType(); - public static Program Foo2 = new Program(); - } - - class Program - { - void Goo() - { - SomeType c = $$ - } - }"; + """ + /// + public class SomeType + { } + + public static class TypeContainer + { + public static SomeType Foo1 = new SomeType(); + public static Program Foo2 = new Program(); + } + + class Program + { + void Goo() + { + SomeType c = $$ + } + } + """; await VerifyItemExistsAsync(markup, "TypeContainer"); await VerifyItemExistsAsync(markup, "TypeContainer.Foo1"); await VerifyItemExistsAsync(markup, "TypeContainer.Foo2"); @@ -715,27 +733,27 @@ static void Main(string[] args) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/828196")] public async Task NotInParameterNameContext() { - var enumE = @" -enum E -{ - a -} -"; - var enumLikeE = @" -readonly struct E -{ - public static readonly E a; -} -"; - var markup = @" -class C -{ - void goo(E first, E second) - { - goo(first: E.a, $$ - } -} -"; + var enumE = """ + enum E + { + a + } + """; + var enumLikeE = """ + readonly struct E + { + public static readonly E a; + } + """; + var markup = """ + class C + { + void goo(E first, E second) + { + goo(first: E.a, $$ + } + } + """; await VerifyItemIsAbsentAsync(enumE + markup, "E"); @@ -746,57 +764,59 @@ void goo(E first, E second) public async Task InExpressionBodiedProperty() { var markup = -@"class C -{ - Colors Colors => $$ -} -"; - var colors = @" -enum Colors -{ - Red, - Blue, - Green, -} -"; - var colorsLike = @" -readonly struct Colors -{ - public static readonly Colors Red; - public static readonly Colors Blue; - public static readonly Colors Green; -} -"; - - await VerifyItemExistsAsync(markup + colors, "Colors"); - await VerifyItemIsAbsentAsync(markup + colorsLike, "Colors"); - } + """ + class C + { + Colors Colors => $$ + } + """; + var colors = """ + enum Colors + { + Red, + Blue, + Green, + } + """; + var colorsLike = """ + readonly struct Colors + { + public static readonly Colors Red; + public static readonly Colors Blue; + public static readonly Colors Green; + } + """; + + await VerifyItemExistsAsync(markup + colors, "Colors"); + await VerifyItemIsAbsentAsync(markup + colorsLike, "Colors"); + } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4310")] public async Task InExpressionBodiedMethod() { var markup = -@"class C -{ - Colors GetColors() => $$ -} -"; - var colors = @" -enum Colors -{ - Red, - Blue, - Green, -} -"; - var colorsLike = @" -readonly struct Colors -{ - public static readonly Colors Red; - public static readonly Colors Blue; - public static readonly Colors Green; -} -"; + """ + class C + { + Colors GetColors() => $$ + } + """; + var colors = """ + enum Colors + { + Red, + Blue, + Green, + } + """; + var colorsLike = """ + readonly struct Colors + { + public static readonly Colors Red; + public static readonly Colors Blue; + public static readonly Colors Green; + } + """; await VerifyItemExistsAsync(markup + colors, "Colors"); await VerifyItemIsAbsentAsync(markup + colorsLike, "Colors"); @@ -805,11 +825,12 @@ readonly struct Colors [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60341")] public async Task NotAfterAsync1() { - var markup = @" -class Test -{ - public async $$ -}"; + var markup = """ + class Test + { + public async $$ + } + """; await VerifyNoItemsExistAsync(markup); } @@ -817,12 +838,13 @@ public async $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60341")] public async Task NotAfterAsync2() { - var markup = @" -class Test -{ - public async $$ - public void M() {} -}"; + var markup = """ + class Test + { + public async $$ + public void M() {} + } + """; await VerifyNoItemsExistAsync(markup); } @@ -831,33 +853,34 @@ public void M() {} public async Task NotAfterDot() { var markup = -@"namespace ConsoleApplication253 -{ - class Program - { - static void Main(string[] args) - { - M(E.$$) - } + """ + namespace ConsoleApplication253 + { + class Program + { + static void Main(string[] args) + { + M(E.$$) + } - static void M(E e) { } - } -} -"; - var enumE = @" -enum E -{ - A, - B, -} -"; - var enumLikeE = @" -readonly struct E -{ - public static readonly E A; - public static readonly E B; -} -"; + static void M(E e) { } + } + } + """; + var enumE = """ + enum E + { + A, + B, + } + """; + var enumLikeE = """ + readonly struct E + { + public static readonly E A; + public static readonly E B; + } + """; await VerifyNoItemsExistAsync(markup + enumE); await VerifyNoItemsExistAsync(markup + enumLikeE); @@ -867,33 +890,34 @@ readonly struct E public async Task NotAfterDotWithTextTyped() { var markup = -@"namespace ConsoleApplication253 -{ - class Program - { - static void Main(string[] args) - { - M(E.a$$) - } + """ + namespace ConsoleApplication253 + { + class Program + { + static void Main(string[] args) + { + M(E.a$$) + } - static void M(E e) { } - } -} -"; - var enumE = @" -enum E -{ - A, - B, -} -"; - var enumLikeE = @" -readonly struct E -{ - public static readonly E A; - public static readonly E B; -} -"; + static void M(E e) { } + } + } + """; + var enumE = """ + enum E + { + A, + B, + } + """; + var enumLikeE = """ + readonly struct E + { + public static readonly E A; + public static readonly E B; + } + """; await VerifyNoItemsExistAsync(markup + enumE); await VerifyNoItemsExistAsync(markup + enumLikeE); @@ -903,18 +927,20 @@ readonly struct E public async Task TestInEnumInitializer1() { var markup = -@"using System; + """ + using System; -[Flags] -internal enum ProjectTreeWriterOptions -{ - None, - Tags, - FilePath, - Capabilities, - Visibility, - AllProperties = FilePath | Visibility | $$ -}"; + [Flags] + internal enum ProjectTreeWriterOptions + { + None, + Tags, + FilePath, + Capabilities, + Visibility, + AllProperties = FilePath | Visibility | $$ + } + """; await VerifyItemExistsAsync(markup, "ProjectTreeWriterOptions"); } @@ -922,18 +948,20 @@ internal enum ProjectTreeWriterOptions public async Task TestInEnumInitializer2() { var markup = -@"using System; + """ + using System; -[Flags] -internal enum ProjectTreeWriterOptions -{ - None, - Tags, - FilePath, - Capabilities, - Visibility, - AllProperties = FilePath | $$ Visibility -}"; + [Flags] + internal enum ProjectTreeWriterOptions + { + None, + Tags, + FilePath, + Capabilities, + Visibility, + AllProperties = FilePath | $$ Visibility + } + """; await VerifyItemExistsAsync(markup, "ProjectTreeWriterOptions"); } @@ -941,18 +969,20 @@ internal enum ProjectTreeWriterOptions public async Task TestInEnumInitializer3() { var markup = -@"using System; + """ + using System; -[Flags] -internal enum ProjectTreeWriterOptions -{ - None, - Tags, - FilePath, - Capabilities, - Visibility, - AllProperties = FilePath | $$ | Visibility -}"; + [Flags] + internal enum ProjectTreeWriterOptions + { + None, + Tags, + FilePath, + Capabilities, + Visibility, + AllProperties = FilePath | $$ | Visibility + } + """; await VerifyItemExistsAsync(markup, "ProjectTreeWriterOptions"); } @@ -960,18 +990,20 @@ internal enum ProjectTreeWriterOptions public async Task TestInEnumInitializer4() { var markup = -@"using System; + """ + using System; -[Flags] -internal enum ProjectTreeWriterOptions -{ - None, - Tags, - FilePath, - Capabilities, - Visibility, - AllProperties = FilePath ^ $$ -}"; + [Flags] + internal enum ProjectTreeWriterOptions + { + None, + Tags, + FilePath, + Capabilities, + Visibility, + AllProperties = FilePath ^ $$ + } + """; await VerifyItemExistsAsync(markup, "ProjectTreeWriterOptions"); } @@ -979,18 +1011,20 @@ internal enum ProjectTreeWriterOptions public async Task TestInEnumInitializer5() { var markup = -@"using System; + """ + using System; -[Flags] -internal enum ProjectTreeWriterOptions -{ - None, - Tags, - FilePath, - Capabilities, - Visibility, - AllProperties = FilePath & $$ -}"; + [Flags] + internal enum ProjectTreeWriterOptions + { + None, + Tags, + FilePath, + Capabilities, + Visibility, + AllProperties = FilePath & $$ + } + """; await VerifyItemExistsAsync(markup, "ProjectTreeWriterOptions"); } @@ -998,16 +1032,18 @@ internal enum ProjectTreeWriterOptions public async Task TestInEnumHasFlag() { var markup = -@"using System.IO; + """ + using System.IO; -class C -{ - void M() - { - FileInfo f; - f.Attributes.HasFlag($$ - } -}"; + class C + { + void M() + { + FileInfo f; + f.Attributes.HasFlag($$ + } + } + """; await VerifyItemExistsAsync(markup, "FileAttributes"); } @@ -1155,26 +1191,29 @@ Sample A() [Fact] public async Task TestEditorBrowsable_EnumTypeDotMemberAlways() { - var markup = @" -class P -{ - public void S() - { - MyEnum d = $$; - } -}"; - var referencedCode = @" -public enum MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - Member -}"; - var referencedCode_EnumLike = @" -public readonly struct MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public static readonly MyEnum Member; -}"; + var markup = """ + class P + { + public void S() + { + MyEnum d = $$; + } + } + """; + var referencedCode = """ + public enum MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + Member + } + """; + var referencedCode_EnumLike = """ + public readonly struct MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public static readonly MyEnum Member; + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -1198,26 +1237,29 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact] public async Task TestEditorBrowsable_EnumTypeDotMemberNever() { - var markup = @" -class P -{ - public void S() - { - MyEnum d = $$; - } -}"; - var referencedCode = @" -public enum MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - Member -}"; - var referencedCode_EnumLike = @" -public readonly struct MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public static readonly MyEnum Member; -}"; + var markup = """ + class P + { + public void S() + { + MyEnum d = $$; + } + } + """; + var referencedCode = """ + public enum MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + Member + } + """; + var referencedCode_EnumLike = """ + public readonly struct MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static readonly MyEnum Member; + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -1241,26 +1283,29 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact] public async Task TestEditorBrowsable_EnumTypeDotMemberAdvanced() { - var markup = @" -class P -{ - public void S() - { - MyEnum d = $$; - } -}"; - var referencedCode = @" -public enum MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - Member -}"; - var referencedCode_EnumLike = @" -public readonly struct MyEnum -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - public static readonly MyEnum Member; -}"; + var markup = """ + class P + { + public void S() + { + MyEnum d = $$; + } + } + """; + var referencedCode = """ + public enum MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + Member + } + """; + var referencedCode_EnumLike = """ + public readonly struct MyEnum + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public static readonly MyEnum Member; + } + """; HideAdvancedMembers = true; @@ -1310,36 +1355,36 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact] public async Task TestTriggeredOnOpenParen() { - var markup = @" -static class Program -{ - public static void Main(string[] args) - { - // type after this line - Bar($$ - } + var markup = """ + static class Program + { + public static void Main(string[] args) + { + // type after this line + Bar($$ + } - public static void Bar(Goo f) - { - } -} -"; - var goo = @" -enum Goo -{ - AMember, - BMember, - CMember -} -"; - var gooLike = @" -readonly struct Goo -{ - public static readonly Goo AMember; - public static readonly Goo BMember; - public static readonly Goo CMember; -} -"; + public static void Bar(Goo f) + { + } + } + """; + var goo = """ + enum Goo + { + AMember, + BMember, + CMember + } + """; + var gooLike = """ + readonly struct Goo + { + public static readonly Goo AMember; + public static readonly Goo BMember; + public static readonly Goo CMember; + } + """; await VerifyItemExistsAsync(markup + goo, "Goo.AMember", usePreviousCharAsTrigger: true); await VerifyItemExistsAsync(markup + goo, "Goo.AMember", usePreviousCharAsTrigger: false); @@ -1350,32 +1395,32 @@ readonly struct Goo [Fact] public async Task TestRightSideOfAssignment() { - var markup = @" -static class Program -{ - public static void Main(string[] args) - { - Goo x; - x = $$; - } -} -"; - var goo = @" -enum Goo -{ - AMember, - BMember, - CMember -} -"; - var gooLike = @" -readonly struct Goo -{ - public static readonly Goo AMember; - public static readonly Goo BMember; - public static readonly Goo CMember; -} -"; + var markup = """ + static class Program + { + public static void Main(string[] args) + { + Goo x; + x = $$; + } + } + """; + var goo = """ + enum Goo + { + AMember, + BMember, + CMember + } + """; + var gooLike = """ + readonly struct Goo + { + public static readonly Goo AMember; + public static readonly Goo BMember; + public static readonly Goo CMember; + } + """; await VerifyItemExistsAsync(markup + goo, "Goo.AMember", usePreviousCharAsTrigger: true); await VerifyItemExistsAsync(markup + goo, "Goo.AMember", usePreviousCharAsTrigger: false); @@ -1386,36 +1431,36 @@ readonly struct Goo [Fact] public async Task TestCaseStatement() { - var markup = @" -static class Module1 -{ - public static void Main(string[] args) - { - var value = E.A; + var markup = """ + static class Module1 + { + public static void Main(string[] args) + { + var value = E.A; - switch (value) - { - case $$ - } - } -} -"; - var e = @" -enum E -{ - A, - B, - C -} -"; - var eLike = @" -readonly struct E -{ - public static readonly E A; - public static readonly E B; - public static readonly E C; -} -"; + switch (value) + { + case $$ + } + } + } + """; + var e = """ + enum E + { + A, + B, + C + } + """; + var eLike = """ + readonly struct E + { + public static readonly E A; + public static readonly E B; + public static readonly E C; + } + """; await VerifyItemExistsAsync(e + markup, "E.A", usePreviousCharAsTrigger: true); await VerifyItemExistsAsync(e + markup, "E.A", usePreviousCharAsTrigger: false); @@ -1594,27 +1639,27 @@ struct DateTime [Fact] public async Task TestCaseStatementWithInt32InferredType() { - var markup = @" -class C -{ - public void M(DayOfWeek day) - { - switch (day) - { - case DayOfWeek.A: - break; + var markup = """ + class C + { + public void M(DayOfWeek day) + { + switch (day) + { + case DayOfWeek.A: + break; - case $$ - } - } + case $$ + } + } - enum DayOfWeek - { - A, - B - } -} -"; + enum DayOfWeek + { + A, + B + } + } + """; await VerifyItemExistsAsync(markup, "DayOfWeek.A"); await VerifyItemExistsAsync(markup, "DayOfWeek.B"); @@ -1623,20 +1668,20 @@ enum DayOfWeek [Fact] public async Task TestLocalNoAs() { - var markup = @" -enum E -{ - A -} + var markup = """ + enum E + { + A + } -class C -{ - public void M() - { - const E e = e$$; - } -} -"; + class C + { + public void M() + { + const E e = e$$; + } + } + """; await VerifyItemExistsAsync(markup, "E.A"); await VerifyItemIsAbsentAsync(markup, "e as E"); @@ -1645,20 +1690,20 @@ public void M() [Fact] public async Task TestIncludeEnumAfterTyping() { - var markup = @" -enum E -{ - A -} + var markup = """ + enum E + { + A + } -class C -{ - public void M() - { - const E e = e$$; - } -} -"; + class C + { + public void M() + { + const E e = e$$; + } + } + """; await VerifyItemExistsAsync(markup, "E.A"); } @@ -1666,62 +1711,62 @@ public void M() [Fact] public async Task TestNotInTrivia() { - var markup = @" -class C -{ - public void M(DayOfWeek day) - { - switch (day) - { - case DayOfWeek.A: - case DayOfWeek.B// $$ - : - break; - } - } + var markup = """ + class C + { + public void M(DayOfWeek day) + { + switch (day) + { + case DayOfWeek.A: + case DayOfWeek.B// $$ + : + break; + } + } - enum DayOfWeek - { - A, - B - } -} -"; + enum DayOfWeek + { + A, + B + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task TestCommitOnComma() { - var markup = @" -enum E -{ - A -} + var markup = """ + enum E + { + A + } -class C -{ - public void M() - { - const E e = $$ - } -} -"; + class C + { + public void M() + { + const E e = $$ + } + } + """; - var expected = @" -enum E -{ - A -} + var expected = """ + enum E + { + A + } -class C -{ - public void M() - { - const E e = E.A; - } -} -"; + class C + { + public void M() + { + const E e = E.A; + } + } + """; await VerifyProviderCommitAsync(markup, "E.A", expected, ';'); } @@ -1798,18 +1843,18 @@ public void Main() [Fact] public async Task EnumMember_TestInEnumHasFlag() { - var markup = @" -using System.IO; + var markup = """ + using System.IO; -class C -{ - public void Main() - { - FileInfo f; - f.Attributes.HasFlag($$ - } -} -"; + class C + { + public void Main() + { + FileInfo f; + f.Attributes.HasFlag($$ + } + } + """; await VerifyItemExistsAsync(markup, "FileAttributes.Hidden"); } @@ -1817,44 +1862,44 @@ public void Main() [Fact] public async Task TestMultipleEnumsCausedByOverloads() { - var markup = @" -class C -{ - public enum Color - { - Red, - Green, - } + var markup = """ + class C + { + public enum Color + { + Red, + Green, + } - public enum Palette - { - AccentColor1, - AccentColor2, - } + public enum Palette + { + AccentColor1, + AccentColor2, + } - public readonly struct ColorLike - { - public static readonly ColorLike Red; - public static readonly ColorLike Green; - } + public readonly struct ColorLike + { + public static readonly ColorLike Red; + public static readonly ColorLike Green; + } - public readonly struct PaletteLike - { - public static readonly PaletteLike AccentColor1; - public static readonly PaletteLike AccentColor2; - } + public readonly struct PaletteLike + { + public static readonly PaletteLike AccentColor1; + public static readonly PaletteLike AccentColor2; + } - public void SetColor(Color color) { } - public void SetColor(Palette palette) { } - public void SetColor(ColorLike color) { } - public void SetColor(PaletteLike palette) { } + public void SetColor(Color color) { } + public void SetColor(Palette palette) { } + public void SetColor(ColorLike color) { } + public void SetColor(PaletteLike palette) { } - public void Main() - { - SetColor($$ - } -} -"; + public void Main() + { + SetColor($$ + } + } + """; await VerifyItemExistsAsync(markup, "Color.Red"); await VerifyItemExistsAsync(markup, "Palette.AccentColor1"); @@ -2002,71 +2047,71 @@ public void M() [Fact] public async Task TestPatterns_SwitchStatement_PropertyPattern() { - var markup = @" -public enum Color -{ - Red, - Green, -} + var markup = """ + public enum Color + { + Red, + Green, + } -class C -{ - public Color Color { get; } + class C + { + public Color Color { get; } - public void M() - { - switch (this) - { - case { Color: $$ - } -} -"; + public void M() + { + switch (this) + { + case { Color: $$ + } + } + """; await VerifyItemExistsAsync(markup, "Color.Red"); } [Fact] public async Task TestPatterns_SwitchExpression_PropertyPattern() { - var markup = @" -public enum Color -{ - Red, - Green, -} + var markup = """ + public enum Color + { + Red, + Green, + } -class C -{ - public Color Color { get; } + class C + { + public Color Color { get; } - public void M() - { - var isRed = this switch - { - { Color: $$ - } -} -"; + public void M() + { + var isRed = this switch + { + { Color: $$ + } + } + """; await VerifyItemExistsAsync(markup, "Color.Red"); } [Fact] public async Task TestStaticAndInstanceMembers() { - var markup = @" -public readonly struct Color -{ - public static readonly Color Red; - public readonly Color Green; -} + var markup = """ + public readonly struct Color + { + public static readonly Color Red; + public readonly Color Green; + } -class C -{ - public void M(Color color) - { - M($$ - } -} -"; + class C + { + public void M(Color color) + { + M($$ + } + } + """; await VerifyItemExistsAsync(markup, "Color.Red"); await VerifyItemIsAbsentAsync(markup, "Color.Green"); @@ -2075,21 +2120,21 @@ public void M(Color color) [Fact] public async Task TestProperties() { - var markup = @" -public readonly struct Color -{ - public static Color Red { get; } - public Color Green { get; } -} + var markup = """ + public readonly struct Color + { + public static Color Red { get; } + public Color Green { get; } + } -class C -{ - public void M(Color color) - { - M($$ - } -} -"; + class C + { + public void M(Color color) + { + M($$ + } + } + """; await VerifyItemExistsAsync(markup, "Color.Red"); await VerifyItemIsAbsentAsync(markup, "Color.Green"); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceMemberCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceMemberCompletionProviderTests.cs index 8151107a59298..80bd8adfa92b3 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceMemberCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceMemberCompletionProviderTests.cs @@ -20,21 +20,22 @@ internal override Type GetCompletionProviderType() [Fact] public async Task ExplicitInterfaceMember_01() { - var markup = @" -interface IGoo -{ - void Goo(); - void Goo(int x); - int Prop { get; } - int Generic(K key, V value); - string this[int i] { get; } - void With_Underscore(); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; + var markup = """ + interface IGoo + { + void Goo(); + void Goo(int x); + int Prop { get; } + int Generic(K key, V value); + string this[int i] { get; } + void With_Underscore(); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "()"); await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "(int x)"); @@ -47,18 +48,19 @@ void IGoo.$$ [Fact] public async Task ExplicitInterfaceMember_02() { - var markup = @" -interface IGoo -{ - void Goo(); - void Goo(int x); - int Prop { get; } -} + var markup = """ + interface IGoo + { + void Goo(); + void Goo(int x); + int Prop { get; } + } -interface IBar : IGoo -{ - void IGoo.$$ -}"; + interface IBar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "()"); await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "(int x)"); @@ -68,18 +70,19 @@ void IGoo.$$ [Fact] public async Task ExplicitInterfaceMember_03() { - var markup = @" -interface IGoo -{ - virtual void Goo() {} - virtual void Goo(int x) {} - virtual int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + virtual void Goo() {} + virtual void Goo(int x) {} + virtual int Prop { get => 0; } + } -class Bar : IGoo -{ - void IGoo.$$ -}"; + class Bar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "()"); await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "(int x)"); @@ -89,18 +92,19 @@ void IGoo.$$ [Fact] public async Task ExplicitInterfaceMember_04() { - var markup = @" -interface IGoo -{ - virtual void Goo() {} - virtual void Goo(int x) {} - virtual int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + virtual void Goo() {} + virtual void Goo(int x) {} + virtual int Prop { get => 0; } + } -interface IBar : IGoo -{ - void IGoo.$$ -}"; + interface IBar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "()"); await VerifyItemExistsAsync(markup, "Goo", displayTextSuffix: "(int x)"); @@ -110,27 +114,29 @@ void IGoo.$$ [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/709988")] public async Task CommitOnNotParen() { - var markup = @" -interface IGoo -{ - void Goo(); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - void Goo(); -} - -class Bar : IGoo -{ - void IGoo.Goo() -}"; + var markup = """ + interface IGoo + { + void Goo(); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + void Goo(); + } + + class Bar : IGoo + { + void IGoo.Goo() + } + """; await VerifyProviderCommitAsync(markup, "Goo()", expected, null); } @@ -138,27 +144,29 @@ void IGoo.Goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/709988")] public async Task CommitOnParen() { - var markup = @" -interface IGoo -{ - void Goo(); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - void Goo(); -} - -class Bar : IGoo -{ - void IGoo.Goo( -}"; + var markup = """ + interface IGoo + { + void Goo(); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + void Goo(); + } + + class Bar : IGoo + { + void IGoo.Goo( + } + """; await VerifyProviderCommitAsync(markup, "Goo()", expected, '('); } @@ -166,22 +174,23 @@ void IGoo.Goo( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19947")] public async Task ExplicitInterfaceMemberCompletionContainsOnlyValidValues() { - var markup = @" -interface I1 -{ - void Goo(); -} + var markup = """ + interface I1 + { + void Goo(); + } -interface I2 : I1 -{ - void Goo2(); - int Prop { get; } -} + interface I2 : I1 + { + void Goo2(); + int Prop { get; } + } -class Bar : I2 -{ - void I2.$$ -}"; + class Bar : I2 + { + void I2.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Equals(object obj)"); await VerifyItemIsAbsentAsync(markup, "Goo()"); @@ -196,19 +205,19 @@ void I2.$$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26595")] public async Task ExplicitInterfaceMemberCompletionDoesNotContainAccessors() { - var markup = @" + var markup = """ + interface I1 + { + void Foo(); + int Prop { get; } + event EventHandler TestEvent; + } -interface I1 -{ - void Foo(); - int Prop { get; } - event EventHandler TestEvent; -} - -class Bar : I1 -{ - void I1.$$ -}"; + class Bar : I1 + { + void I1.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Prop.get"); await VerifyItemIsAbsentAsync(markup, "TestEvent.add"); @@ -222,17 +231,18 @@ void I1.$$ [Fact] public async Task NotStaticMember_01() { - var markup = @" -interface IGoo -{ - static void Goo() {} - static int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + static void Goo() {} + static int Prop { get => 0; } + } -class Bar : IGoo -{ - void IGoo.$$ -}"; + class Bar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo()"); await VerifyItemIsAbsentAsync(markup, "Prop"); @@ -241,17 +251,18 @@ void IGoo.$$ [Fact] public async Task NotStaticMember_02() { - var markup = @" -interface IGoo -{ - static void Goo() {} - static int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + static void Goo() {} + static int Prop { get => 0; } + } -interface IBar : IGoo -{ - void IGoo.$$ -}"; + interface IBar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo()"); await VerifyItemIsAbsentAsync(markup, "Prop"); @@ -260,17 +271,18 @@ void IGoo.$$ [Fact] public async Task NotSealedMember_01() { - var markup = @" -interface IGoo -{ - sealed void Goo() {} - sealed int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + sealed void Goo() {} + sealed int Prop { get => 0; } + } -class Bar : IGoo -{ - void IGoo.$$ -}"; + class Bar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo()"); await VerifyItemIsAbsentAsync(markup, "Prop"); @@ -279,17 +291,18 @@ void IGoo.$$ [Fact] public async Task NotSealedMember_02() { - var markup = @" -interface IGoo -{ - sealed void Goo() {} - sealed int Prop { get => 0; } -} + var markup = """ + interface IGoo + { + sealed void Goo() {} + sealed int Prop { get => 0; } + } -interface IBar : IGoo -{ - void IGoo.$$ -}"; + interface IBar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo()"); await VerifyItemIsAbsentAsync(markup, "Prop"); @@ -298,18 +311,19 @@ void IGoo.$$ [Fact] public async Task NotNestedType_01() { - var markup = @" -interface IGoo -{ - public abstract class Goo - { - } -} + var markup = """ + interface IGoo + { + public abstract class Goo + { + } + } -class Bar : IGoo -{ - void IGoo.$$ -}"; + class Bar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo"); } @@ -317,18 +331,19 @@ void IGoo.$$ [Fact] public async Task NotNestedType_02() { - var markup = @" -interface IGoo -{ - public abstract class Goo - { - } -} + var markup = """ + interface IGoo + { + public abstract class Goo + { + } + } -interface IBar : IGoo -{ - void IGoo.$$ -}"; + interface IBar : IGoo + { + void IGoo.$$ + } + """; await VerifyItemIsAbsentAsync(markup, "Goo"); } @@ -337,30 +352,32 @@ void IGoo.$$ public async Task NotInaccessibleMember_01() { var markup = -@" - - Assembly2 - - - - - - -public interface IGoo -{ - internal void Goo1() {} - internal int Prop1 { get => 0; } - protected void Goo2() {} - protected int Prop2 { get => 0; } -} - - -"; + """ + + + Assembly2 + + + + + + + public interface IGoo + { + internal void Goo1() {} + internal int Prop1 { get => 0; } + protected void Goo2() {} + protected int Prop2 { get => 0; } + } + + + + """; await VerifyItemIsAbsentAsync(markup, "Goo1", displayTextSuffix: "()"); await VerifyItemIsAbsentAsync(markup, "Prop1"); @@ -372,30 +389,32 @@ protected void Goo2() {} public async Task NotInaccessibleMember_02() { var markup = -@" - - Assembly2 - - - - - - -public interface IGoo -{ - internal void Goo1() {} - internal int Prop1 { get => 0; } - protected void Goo2() {} - protected int Prop2 { get => 0; } -} - - -"; + """ + + + Assembly2 + + + + + + + public interface IGoo + { + internal void Goo1() {} + internal int Prop1 { get => 0; } + protected void Goo2() {} + protected int Prop2 { get => 0; } + } + + + + """; await VerifyItemIsAbsentAsync(markup, "Goo1", displayTextSuffix: "()"); await VerifyItemIsAbsentAsync(markup, "Prop1"); @@ -406,27 +425,29 @@ protected void Goo2() {} [Fact] public async Task VerifySignatureCommit_Generic_Tab() { - var markup = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.Generic(K key, V value) -}"; + var markup = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.Generic(K key, V value) + } + """; await VerifyProviderCommitAsync(markup, "Generic(K key, V value)", expected, '\t'); } @@ -434,27 +455,29 @@ void IGoo.Generic(K key, V value) [Fact] public async Task VerifySignatureCommit_Generic_OpenBrace() { - var markup = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.Generic< -}"; + var markup = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.Generic< + } + """; await VerifyProviderCommitAsync(markup, "Generic(K key, V value)", expected, '<'); } @@ -462,27 +485,29 @@ void IGoo.Generic< [Fact] public async Task VerifySignatureCommit_Method_Tab() { - var markup = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.Generic(K key, V value) -}"; + var markup = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.Generic(K key, V value) + } + """; await VerifyProviderCommitAsync(markup, "Generic(K key, V value)", expected, '\t'); } @@ -490,27 +515,29 @@ void IGoo.Generic(K key, V value) [Fact] public async Task VerifySignatureCommit_Method_OpenBrace() { - var markup = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int Generic(K key, V value); -} - -class Bar : IGoo -{ - void IGoo.Generic( -}"; + var markup = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int Generic(K key, V value); + } + + class Bar : IGoo + { + void IGoo.Generic( + } + """; await VerifyProviderCommitAsync(markup, "Generic(K key, V value)", expected, '('); } @@ -518,27 +545,29 @@ void IGoo.Generic( [Fact] public async Task VerifySignatureCommit_Indexer_Tab() { - var markup = @" -interface IGoo -{ - int this[K key, V value] { get; } -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int this[K key, V value] { get; } -} - -class Bar : IGoo -{ - void IGoo.this[K key, V value] -}"; + var markup = """ + interface IGoo + { + int this[K key, V value] { get; } + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int this[K key, V value] { get; } + } + + class Bar : IGoo + { + void IGoo.this[K key, V value] + } + """; await VerifyProviderCommitAsync(markup, "this[K key, V value]", expected, '\t'); } @@ -546,27 +575,29 @@ class Bar : IGoo [Fact] public async Task VerifySignatureCommit_Indexer_OpenBrace() { - var markup = @" -interface IGoo -{ - int this[K key, V value] { get; } -} - -class Bar : IGoo -{ - void IGoo.$$ -}"; - - var expected = @" -interface IGoo -{ - int this[K key, V value] { get; } -} - -class Bar : IGoo -{ - void IGoo.this[ -}"; + var markup = """ + interface IGoo + { + int this[K key, V value] { get; } + } + + class Bar : IGoo + { + void IGoo.$$ + } + """; + + var expected = """ + interface IGoo + { + int this[K key, V value] { get; } + } + + class Bar : IGoo + { + void IGoo.this[ + } + """; await VerifyProviderCommitAsync(markup, "this[K key, V value]", expected, '['); } @@ -607,29 +638,29 @@ void I.M({refKind} string s) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53924")] public async Task TestStaticAbstractInterfaceMember() { - var markup = @" -interface I2 where T : I2 -{ - abstract static implicit operator int(T x); -} - -class Test2 : I2 -{ - static implicit I2.$$ -} -"; - - var expected = @" -interface I2 where T : I2 -{ - abstract static implicit operator int(T x); -} - -class Test2 : I2 -{ - static implicit I2.operator int(Test2 x) -} -"; + var markup = """ + interface I2 where T : I2 + { + abstract static implicit operator int(T x); + } + + class Test2 : I2 + { + static implicit I2.$$ + } + """; + + var expected = """ + interface I2 where T : I2 + { + abstract static implicit operator int(T x); + } + + class Test2 : I2 + { + static implicit I2.operator int(Test2 x) + } + """; await VerifyProviderCommitAsync(markup, "operator int(Test2 x)", expected, '\t'); } @@ -637,31 +668,31 @@ static implicit I2.operator int(Test2 x) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53924")] public async Task TestStaticAbstractInterfaceMember_TrueOperator() { - var markup = @" -interface I where T : I -{ - abstract static bool operator true(T x); - abstract static bool operator false(T x); -} - -class C : I -{ - static bool I.$$ -} -"; - - var expected = @" -interface I where T : I -{ - abstract static bool operator true(T x); - abstract static bool operator false(T x); -} - -class C : I -{ - static bool I.operator true(C x) -} -"; + var markup = """ + interface I where T : I + { + abstract static bool operator true(T x); + abstract static bool operator false(T x); + } + + class C : I + { + static bool I.$$ + } + """; + + var expected = """ + interface I where T : I + { + abstract static bool operator true(T x); + abstract static bool operator false(T x); + } + + class C : I + { + static bool I.operator true(C x) + } + """; await VerifyProviderCommitAsync(markup, "operator true(C x)", expected, '\t'); } @@ -669,29 +700,29 @@ static bool I.operator true(C x) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53924")] public async Task TestStaticAbstractInterfaceMember_UnaryPlusOperator() { - var markup = @" -interface I where T : I -{ - abstract static T operator +(T x); -} - -class C : I -{ - static C I.$$ -} -"; - - var expected = @" -interface I where T : I -{ - abstract static T operator +(T x); -} - -class C : I -{ - static C I.operator +(C x) -} -"; + var markup = """ + interface I where T : I + { + abstract static T operator +(T x); + } + + class C : I + { + static C I.$$ + } + """; + + var expected = """ + interface I where T : I + { + abstract static T operator +(T x); + } + + class C : I + { + static C I.operator +(C x) + } + """; await VerifyProviderCommitAsync(markup, "operator +(C x)", expected, '\t'); } @@ -699,29 +730,29 @@ class C : I [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53924")] public async Task TestStaticAbstractInterfaceMember_BinaryPlusOperator() { - var markup = @" -interface I where T : I -{ - abstract static T operator +(T x, T y); -} - -class C : I -{ - static C I.$$ -} -"; - - var expected = @" -interface I where T : I -{ - abstract static T operator +(T x, T y); -} - -class C : I -{ - static C I.operator +(C x, C y) -} -"; + var markup = """ + interface I where T : I + { + abstract static T operator +(T x, T y); + } + + class C : I + { + static C I.$$ + } + """; + + var expected = """ + interface I where T : I + { + abstract static T operator +(T x, T y); + } + + class C : I + { + static C I.operator +(C x, C y) + } + """; await VerifyProviderCommitAsync(markup, "operator +(C x, C y)", expected, '\t'); } @@ -729,29 +760,29 @@ class C : I [Fact] public async Task TestWithParamsParameter() { - var markup = @" -interface I -{ - void M(params string[] args); -} - -class C : I -{ - void I.$$ -} -"; - - var expected = @" -interface I -{ - void M(params string[] args); -} - -class C : I -{ - void I.M(params string[] args) -} -"; + var markup = """ + interface I + { + void M(params string[] args); + } + + class C : I + { + void I.$$ + } + """; + + var expected = """ + interface I + { + void M(params string[] args); + } + + class C : I + { + void I.M(params string[] args) + } + """; await VerifyProviderCommitAsync(markup, "M(params string[] args)", expected, '\t'); } @@ -759,33 +790,33 @@ void I.M(params string[] args) [Fact] public async Task TestWithNullable() { - var markup = @" -#nullable enable + var markup = """ + #nullable enable -interface I -{ - void M(T? x); -} + interface I + { + void M(T? x); + } -class C : I -{ - void I.$$ -} -"; + class C : I + { + void I.$$ + } + """; - var expected = @" -#nullable enable + var expected = """ + #nullable enable -interface I -{ - void M(T? x); -} + interface I + { + void M(T? x); + } -class C : I -{ - void I.M(T? x) -} -"; + class C : I + { + void I.M(T? x) + } + """; await VerifyProviderCommitAsync(markup, "M(T? x)", expected, '\t'); } @@ -793,29 +824,29 @@ void I.M(T? x) [Fact] public async Task TestEscapeIdentifier() { - var markup = @" -interface I -{ - void M(string @class); -} - -class C : I -{ - void I.$$ -} -"; - - var expected = @" -interface I -{ - void M(string @class); -} - -class C : I -{ - void I.M(string @class) -} -"; + var markup = """ + interface I + { + void M(string @class); + } + + class C : I + { + void I.$$ + } + """; + + var expected = """ + interface I + { + void M(string @class); + } + + class C : I + { + void I.M(string @class) + } + """; await VerifyProviderCommitAsync(markup, "M(string @class)", expected, '\t'); } @@ -823,29 +854,29 @@ void I.M(string @class) [Fact] public async Task TestEscapeIdentifier2() { - var markup = @" -interface I -{ - void M<@class>(); -} - -class C : I -{ - void I.$$ -} -"; - - var expected = @" -interface I -{ - void M<@class>(); -} - -class C : I -{ - void I.M<@class>() -} -"; + var markup = """ + interface I + { + void M<@class>(); + } + + class C : I + { + void I.$$ + } + """; + + var expected = """ + interface I + { + void M<@class>(); + } + + class C : I + { + void I.M<@class>() + } + """; await VerifyProviderCommitAsync(markup, "M<@class>()", expected, '\t'); } @@ -853,29 +884,29 @@ void I.M<@class>() [Fact] public async Task TestParameterWithDefaultValue() { - var markup = @" -interface I -{ - void M(int x = 10); -} - -class C : I -{ - void I.$$ -} -"; - - var expected = @" -interface I -{ - void M(int x = 10); -} - -class C : I -{ - void I.M(int x) -} -"; + var markup = """ + interface I + { + void M(int x = 10); + } + + class C : I + { + void I.$$ + } + """; + + var expected = """ + interface I + { + void M(int x = 10); + } + + class C : I + { + void I.M(int x) + } + """; // TODO: Consider adding the default value too. await VerifyProviderCommitAsync(markup, "M(int x)", expected, '\t'); } @@ -883,33 +914,33 @@ void I.M(int x) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60215")] public async Task TestStaticAbstractCheckedUnaryOperator() { - var markup = @" -interface I1 where T : I1 -{ - abstract static T operator checked -(T x); + var markup = """ + interface I1 where T : I1 + { + abstract static T operator checked -(T x); - abstract static T operator -(T x); -} + abstract static T operator -(T x); + } -class C : I1 -{ - static C I1.$$ -} -"; + class C : I1 + { + static C I1.$$ + } + """; - var expected = @" -interface I1 where T : I1 -{ - abstract static T operator checked -(T x); + var expected = """ + interface I1 where T : I1 + { + abstract static T operator checked -(T x); - abstract static T operator -(T x); -} + abstract static T operator -(T x); + } -class C : I1 -{ - static C I1.operator checked -(C x) -} -"; + class C : I1 + { + static C I1.operator checked -(C x) + } + """; await VerifyProviderCommitAsync(markup, "operator checked -(C x)", expected, '\t'); } @@ -917,33 +948,33 @@ class C : I1 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60215")] public async Task TestStaticAbstractCheckedBinaryOperator() { - var markup = @" -interface I1 where T : I1 -{ - abstract static T operator checked +(T x, T y); + var markup = """ + interface I1 where T : I1 + { + abstract static T operator checked +(T x, T y); - abstract static T operator +(T x, T y); -} + abstract static T operator +(T x, T y); + } -class C : I1 -{ - static C I1.$$ -} -"; + class C : I1 + { + static C I1.$$ + } + """; - var expected = @" -interface I1 where T : I1 -{ - abstract static T operator checked +(T x, T y); + var expected = """ + interface I1 where T : I1 + { + abstract static T operator checked +(T x, T y); - abstract static T operator +(T x, T y); -} + abstract static T operator +(T x, T y); + } -class C : I1 -{ - static C I1.operator checked +(C x, C y) -} -"; + class C : I1 + { + static C I1.operator checked +(C x, C y) + } + """; await VerifyProviderCommitAsync(markup, "operator checked +(C x, C y)", expected, '\t'); } @@ -951,33 +982,33 @@ class C : I1 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60215")] public async Task TestStaticAbstractCheckedCastOperator() { - var markup = @" -interface I1 where T : I1 -{ - abstract static explicit operator checked string(T x); - abstract static explicit operator string(T x); -} - - -class C3 : I1 -{ - static C3 I1.$$ -} -"; - - var expected = @" -interface I1 where T : I1 -{ - abstract static explicit operator checked string(T x); - abstract static explicit operator string(T x); -} - - -class C3 : I1 -{ - static C3 I1.operator checked string(C3 x) -} -"; + var markup = """ + interface I1 where T : I1 + { + abstract static explicit operator checked string(T x); + abstract static explicit operator string(T x); + } + + + class C3 : I1 + { + static C3 I1.$$ + } + """; + + var expected = """ + interface I1 where T : I1 + { + abstract static explicit operator checked string(T x); + abstract static explicit operator string(T x); + } + + + class C3 : I1 + { + static C3 I1.operator checked string(C3 x) + } + """; await VerifyProviderCommitAsync(markup, "operator checked string(C3 x)", expected, '\t'); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceTypeCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceTypeCompletionProviderTests.cs index 3a87ccd24488d..df17a7b37fd42 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceTypeCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExplicitInterfaceTypeCompletionProviderTests.cs @@ -22,14 +22,14 @@ internal override Type GetCompletionProviderType() [Fact] public async Task TestAtStartOfClass() { - var markup = @" -using System.Collections; - -class C : IList -{ - int $$ -} -"; + var markup = """ + using System.Collections; + + class C : IList + { + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); await VerifyItemExistsAsync(markup, "ICollection"); @@ -65,26 +65,26 @@ public async Task TestAtStartOfRecord(string record) [Fact, WorkItem("https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=459044")] public async Task TestInMisplacedUsing() { - var markup = @" -class C -{ - using ($$) -} -"; + var markup = """ + class C + { + using ($$) + } + """; await VerifyNoItemsExistAsync(markup); // no crash } [Fact] public async Task TestAtStartOfStruct() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -struct C : IList -{ - int $$ -} -"; + struct C : IList + { + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -95,15 +95,15 @@ struct C : IList [Fact] public async Task TestAfterField() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int i; - int $$ -} -"; + class C : IList + { + int i; + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -114,15 +114,15 @@ class C : IList [Fact] public async Task TestAfterMethod_01() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - void Goo() { } - int $$ -} -"; + class C : IList + { + void Goo() { } + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -133,15 +133,15 @@ void Goo() { } [Fact] public async Task TestAfterMethod_02() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -interface C : IList -{ - void Goo() { } - int $$ -} -"; + interface C : IList + { + void Goo() { } + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -152,15 +152,15 @@ void Goo() { } [Fact] public async Task TestAfterExpressionBody() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int Goo() => 0; - int $$ -} -"; + class C : IList + { + int Goo() => 0; + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -171,18 +171,18 @@ class C : IList [Fact] public async Task TestWithAttributeFollowing() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int Goo() => 0; - int $$ + class C : IList + { + int Goo() => 0; + int $$ - [Attr] - int Bar(); -} -"; + [Attr] + int Bar(); + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -193,17 +193,17 @@ class C : IList [Fact] public async Task TestWithModifierFollowing() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int Goo() => 0; - int $$ + class C : IList + { + int Goo() => 0; + int $$ - public int Bar(); -} -"; + public int Bar(); + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -214,17 +214,17 @@ class C : IList [Fact] public async Task TestWithTypeFollowing() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int Goo() => 0; - int $$ + class C : IList + { + int Goo() => 0; + int $$ - int Bar(); -} -"; + int Bar(); + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -235,17 +235,17 @@ class C : IList [Fact] public async Task TestWithTypeFollowing2() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - int Goo() => 0; - int $$ + class C : IList + { + int Goo() => 0; + int $$ - X Bar(); -} -"; + X Bar(); + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -256,17 +256,17 @@ class C : IList [Fact] public async Task NotInMember() { - var markup = @" -using System.Collections; - -class C : IList -{ - void Goo() - { - int $$ - } -} -"; + var markup = """ + using System.Collections; + + class C : IList + { + void Goo() + { + int $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -274,14 +274,14 @@ void Goo() [Fact] public async Task NotWithAccessibility() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -class C : IList -{ - public int $$ -} -"; + class C : IList + { + public int $$ + } + """; await VerifyNoItemsExistAsync(markup); } @@ -289,14 +289,14 @@ public int $$ [Fact] public async Task TestInInterface() { - var markup = @" -using System.Collections; + var markup = """ + using System.Collections; -interface I : IList -{ - int $$ -} -"; + interface I : IList + { + int $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IEnumerable"); @@ -307,16 +307,17 @@ interface I : IList [Fact] public async Task TestImplementedAsAsync() { - var markup = @" -interface IGoo -{ - Task Goo(); -} - -class MyGoo : IGoo -{ - async Task $$ -}"; + var markup = """ + interface IGoo + { + Task Goo(); + } + + class MyGoo : IGoo + { + async Task $$ + } + """; await VerifyAnyItemExistsAsync(markup, hasSuggestionModeItem: true); await VerifyItemExistsAsync(markup, "IGoo"); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs index ae8e8785b65a0..e3f50248b213b 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs @@ -133,31 +133,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration(ReferenceType refType) { - var file1 = @" -using System; -using MyInt = System.Int32; + var file1 = """ + using System; + using MyInt = System.Int32; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this MyInt x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this MyInt x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -171,31 +173,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration_PrimitiveType(ReferenceType refType) { - var file1 = @" -using System; -using MyInt = System.Int32; + var file1 = """ + using System; + using MyInt = System.Int32; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this MyInt x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this MyInt x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -209,31 +213,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration_RegularType(ReferenceType refType) { - var file1 = @" -using System; -using MyAlias = System.Exception; + var file1 = """ + using System; + using MyAlias = System.Exception; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this MyAlias x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this MyAlias x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(Exception x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(Exception x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -247,31 +253,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration_GenericType(ReferenceType refType) { - var file1 = @" -using System; -using MyAlias = System.Collections.Generic.List; + var file1 = """ + using System; + using MyAlias = System.Collections.Generic.List; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this MyAlias x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this MyAlias x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(System.Collections.Generic.List x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(System.Collections.Generic.List x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -285,30 +293,32 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration_RegularTypeWithSameSimpleName(ReferenceType refType) { - var file1 = @" -using DataTime = System.Exception; + var file1 = """ + using DataTime = System.Exception; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this System.DateTime x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this System.DateTime x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(DateTime x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(DateTime x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -322,31 +332,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInDeclaration_Namespace(ReferenceType refType) { - var file1 = @" -using System; -using GenericCollection = System.Collections.Generic; + var file1 = """ + using System; + using GenericCollection = System.Collections.Generic; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this GenericCollection.List x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this GenericCollection.List x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(System.Collections.Generic.List x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(System.Collections.Generic.List x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -361,31 +373,33 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UsingAliasInUsage(ReferenceType refType) { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this int x) - => true; - } -}"; - var file2 = @" -using System; -using MyInt = System.Int32; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this int x) + => true; + } + } + """; + var file2 = """ + using System; + using MyInt = System.Int32; -namespace Baz -{ - public class Bat - { - public void M(MyInt x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(MyInt x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -412,19 +426,20 @@ public static bool ExtentionMethod(this MyType t) => true; }} }}"; - var file2 = @" -using System; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(MyType x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(MyType x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( markup, @@ -450,19 +465,20 @@ public static bool ExtentionMethod(this object t) => true; }} }}"; - var file2 = @" -using System; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(MyType x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(MyType x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( markup, @@ -537,19 +553,20 @@ public static bool ExtentionMethod(this MyBase t) => true; }} }}"; - var file2 = @" -using System; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(MyType x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(MyType x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( markup, @@ -570,18 +587,19 @@ await VerifyImportItemExistsAsync( [Theory] public async Task BoundedGenericType(string type, ReferenceType refType) { - var file1 = @" -using System; -using System.Collections.Generic; + var file1 = """ + using System; + using System.Collections.Generic; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this IEnumerable t) - => true; - } -}"; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this IEnumerable t) + => true; + } + } + """; var file2 = $@" using System; using System.Collections.Generic; @@ -616,17 +634,18 @@ await VerifyImportItemExistsAsync( [Theory] public async Task MatchingTypeParameter(string type, ReferenceType refType) { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this T t) - => true; - } -}"; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this T t) + => true; + } + } + """; var file2 = $@" using System; using System.Collections.Generic; @@ -657,30 +676,32 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestInternalExtensionMethods_NoIVT_InReference(ReferenceType refType) { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - internal static class ExtensionClass - { - public static bool ExtentionMethod(this int x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + internal static class ExtensionClass + { + public static bool ExtentionMethod(this int x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemIsAbsentAsync( @@ -692,30 +713,32 @@ await VerifyImportItemIsAbsentAsync( [Fact] public async Task TestInternalExtensionMethods_NoIVT_InSameProject() { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - internal static class ExtensionClass - { - internal static bool ExtentionMethod(this int x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + internal static class ExtensionClass + { + internal static bool ExtentionMethod(this int x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, ReferenceType.None); await VerifyImportItemExistsAsync( @@ -731,28 +754,30 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestInternalExtensionMethods_WithIVT(ReferenceType refType) { - var file1 = @" -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""Project1"")] + var file1 = """ + [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Project1")] -namespace Foo -{ - internal static class ExtensionClass - { - internal static bool ExtentionMethod(this int x) - => true; - } -}"; - var file2 = @" -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Foo + { + internal static class ExtensionClass + { + internal static bool ExtentionMethod(this int x) + => true; + } + } + """; + var file2 = """ + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -766,34 +791,36 @@ await VerifyImportItemExistsAsync( [Theory] public async Task UserDefinedGenericType(ReferenceType refType) { - var file1 = @" -using System; + var file1 = """ + using System; -public class MyGeneric -{ -} + public class MyGeneric + { + } -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this MyGeneric x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this MyGeneric x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(MyGeneric x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(MyGeneric x) + { + x.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, refType); await VerifyImportItemExistsAsync( @@ -808,17 +835,18 @@ await VerifyImportItemExistsAsync( [Theory] public async Task MethodSymbolReceiver(string expression) { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtentionMethod(this int x) - => true; - } -}"; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtentionMethod(this int x) + => true; + } + } + """; var file2 = $@" using System; @@ -911,29 +939,31 @@ await VerifyImportItemExistsAsync( [Fact] public async Task ExtensionMethodDelcaredInRootNamespaceVBSource() { - var file1 = @" -Imports System -Imports System.Runtime.CompilerServices - -Public Module Foo - - public Function ExtentionMethod(x As Integer) As Boolean - Return True - End Function -End Module"; - var file2 = @" -using System; - -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + var file1 = """ + Imports System + Imports System.Runtime.CompilerServices + + Public Module Foo + + public Function ExtentionMethod(x As Integer) As Boolean + Return True + End Function + End Module + """; + var file2 = """ + using System; + + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = CreateMarkupForProjecWithVBProjectReference(file2, file1, sourceLanguage: LanguageNames.CSharp, rootNamespace: "Root"); await VerifyImportItemExistsAsync( @@ -946,29 +976,31 @@ await VerifyImportItemExistsAsync( [Fact] public async Task ExtensionMethodDelcaredInGlobalNamespaceVBSource() { - var file1 = @" -Imports System -Imports System.Runtime.CompilerServices - -Public Module Foo - - public Function ExtentionMethod(x As Integer) As Boolean - Return True - End Function -End Module"; - var file2 = @" -using System; - -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + var file1 = """ + Imports System + Imports System.Runtime.CompilerServices + + Public Module Foo + + public Function ExtentionMethod(x As Integer) As Boolean + Return True + End Function + End Module + """; + var file2 = """ + using System; + + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = CreateMarkupForProjecWithVBProjectReference(file2, file1, sourceLanguage: LanguageNames.CSharp); await VerifyImportItemIsAbsentAsync( @@ -980,31 +1012,33 @@ await VerifyImportItemIsAbsentAsync( [Fact] public async Task TestTriggerLocation() { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - internal static class ExtensionClass - { - internal static bool ExtentionMethod(this int x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + internal static class ExtensionClass + { + internal static bool ExtentionMethod(this int x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - var z = 10; - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + var z = 10; + } + } + } + """; var markup = GetMarkup(file2, file1, ReferenceType.None); await VerifyImportItemExistsAsync( @@ -1019,29 +1053,29 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestIdenticalAliases(string type, string expectedMethodname, string expectedNamespace) { - var file1 = @" -using X = System.String; + var file1 = """ + using X = System.String; -namespace Foo -{ - using X = System.Int32; + namespace Foo + { + using X = System.Int32; - internal static class ExtensionClass - { - internal static bool Int32Method(this X x) - => true; - } -} + internal static class ExtensionClass + { + internal static bool Int32Method(this X x) + => true; + } + } -namespace Bar -{ - internal static class ExtensionClass - { - internal static bool StringMethod(this X x) - => true; - } -} -"; + namespace Bar + { + internal static class ExtensionClass + { + internal static bool StringMethod(this X x) + => true; + } + } + """; var file2 = $@" using System; @@ -1069,21 +1103,21 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestIdenticalMethodName(string type) { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtMethod(this int x) - => true; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtMethod(this int x) + => true; - public static bool ExtMethod(this Exception x) - => true; - } -} -"; + public static bool ExtMethod(this Exception x) + => true; + } + } + """; var file2 = $@" using System; @@ -1109,30 +1143,32 @@ await VerifyImportItemExistsAsync( [Fact] public async Task DoNotTriggerOnType() { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static class ExtensionClass - { - public static bool ExtMethod(this string x) - => true; - } -}"; - var file2 = @" -using System; + namespace Foo + { + public static class ExtensionClass + { + public static bool ExtMethod(this string x) + => true; + } + } + """; + var file2 = """ + using System; -namespace Baz -{ - public class Bat - { - public void M() - { - string.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M() + { + string.$$ + } + } + } + """; var markup = GetMarkup(file2, file1, ReferenceType.None); await VerifyImportItemIsAbsentAsync( markup, @@ -1143,39 +1179,41 @@ await VerifyImportItemIsAbsentAsync( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42325")] public async Task TestExtensionMethodInPartialClass() { - var file1 = @" -using System; + var file1 = """ + using System; -namespace Foo -{ - public static partial class ExtensionClass - { - public static bool ExtentionMethod1(this string x) - => true; - } -}"; - var currentFile = @" -using System; + namespace Foo + { + public static partial class ExtensionClass + { + public static bool ExtentionMethod1(this string x) + => true; + } + } + """; + var currentFile = """ + using System; -namespace Foo -{ - public static partial class ExtensionClass - { - public static bool ExtentionMethod2(this string x) - => true; - } -} + namespace Foo + { + public static partial class ExtensionClass + { + public static bool ExtentionMethod2(this string x) + => true; + } + } -namespace Baz -{ - public class Bat - { - public void M(string x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(string x) + { + x.$$ + } + } + } + """; var markup = CreateMarkupForSingleProject(currentFile, file1, LanguageNames.CSharp); @@ -1209,28 +1247,29 @@ public static bool ExtentionMethod1(this int x) => true; }} }}"; - var srcDoc = @" -using System; + var srcDoc = """ + using System; -namespace Foo -{ - internal static class ExtensionClass - { - public static bool ExtentionMethod2(this int x) - => true; - } -} + namespace Foo + { + internal static class ExtensionClass + { + public static bool ExtentionMethod2(this int x) + => true; + } + } -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = refType switch { @@ -1255,41 +1294,44 @@ await VerifyImportItemExistsAsync( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42325")] public async Task TestExtensionMethodsInConflictingTypesFromReferencedProjects() { - var refDoc1 = @" -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""Project1"")] + var refDoc1 = """ + [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Project1")] -namespace Foo -{ - internal static class ExtensionClass - { - public static bool ExtentionMethod1(this int x) - => true; - } -}"; - var refDoc2 = @" -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""Project1"")] + namespace Foo + { + internal static class ExtensionClass + { + public static bool ExtentionMethod1(this int x) + => true; + } + } + """; + var refDoc2 = """ + [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Project1")] -namespace Foo -{ - internal static class ExtensionClass - { - public static bool ExtentionMethod2(this int x) - => true; - } -}"; - var srcDoc = @" -using System; + namespace Foo + { + internal static class ExtensionClass + { + public static bool ExtentionMethod2(this int x) + => true; + } + } + """; + var srcDoc = """ + using System; -namespace Baz -{ - public class Bat - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace Baz + { + public class Bat + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = CreateMarkupForProjectWithMultupleProjectReferences(srcDoc, LanguageNames.CSharp, LanguageNames.CSharp, new[] { refDoc1, refDoc2 }); @@ -1484,32 +1526,34 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestGenericReceiverTypeWithConstraint(ReferenceType refType) { - var refDoc = @" -using System; + var refDoc = """ + using System; -namespace NS1 -{ - public class C1 {} -} + namespace NS1 + { + public class C1 {} + } -namespace NS2 -{ - public static class Extensions - { - public static bool ExtentionMethod(this NS1.C1 c) => false; - } -}"; - var srcDoc = @" -namespace NS1 -{ - public class C2 - { - public void M(T x) where T : C1 - { - x.$$ - } - } -}"; + namespace NS2 + { + public static class Extensions + { + public static bool ExtentionMethod(this NS1.C1 c) => false; + } + } + """; + var srcDoc = """ + namespace NS1 + { + public class C2 + { + public void M(T x) where T : C1 + { + x.$$ + } + } + } + """; var markup = refType switch { @@ -1616,27 +1660,29 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestDescriptionOfGenericReceiverType(ReferenceType refType) { - var refDoc = @" -using System; + var refDoc = """ + using System; -namespace NS2 -{ - public static class Extensions - { - public static bool ExtentionMethod(this T t) => false; - } -}"; - var srcDoc = @" -namespace NS1 -{ - public class C - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace NS2 + { + public static class Extensions + { + public static bool ExtentionMethod(this T t) => false; + } + } + """; + var srcDoc = """ + namespace NS1 + { + public class C + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = refType switch { @@ -1659,32 +1705,34 @@ await VerifyImportItemExistsAsync( [Theory] public async Task TestDescriptionOfOverloads(ReferenceType refType) { - var refDoc = @" -using System; + var refDoc = """ + using System; -namespace NS2 -{ - public static class Extensions - { - public static bool ExtentionMethod(this int t) => false; - public static bool ExtentionMethod(this int t, int a) => false; - public static bool ExtentionMethod(this int t, int a, int b) => false; - public static bool ExtentionMethod(this int t, T a) => false; - public static bool ExtentionMethod(this int t, T a, T b) => false; - public static bool ExtentionMethod(this int t, T1 a, T2 b) => false; - } -}"; - var srcDoc = @" -namespace NS1 -{ - public class C - { - public void M(int x) - { - x.$$ - } - } -}"; + namespace NS2 + { + public static class Extensions + { + public static bool ExtentionMethod(this int t) => false; + public static bool ExtentionMethod(this int t, int a) => false; + public static bool ExtentionMethod(this int t, int a, int b) => false; + public static bool ExtentionMethod(this int t, T a) => false; + public static bool ExtentionMethod(this int t, T a, T b) => false; + public static bool ExtentionMethod(this int t, T1 a, T2 b) => false; + } + } + """; + var srcDoc = """ + namespace NS1 + { + public class C + { + public void M(int x) + { + x.$$ + } + } + } + """; var markup = refType switch { @@ -1714,30 +1762,32 @@ await VerifyImportItemExistsAsync( [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47551")] public async Task TestBrowsableAlways(ReferenceType refType) { - var srcDoc = @" -class Program -{ - void M() - { - new Goo().$$ - } -}"; + var srcDoc = """ + class Program + { + void M() + { + new Goo().$$ + } + } + """; - var refDoc = @" -public class Goo -{ -} + var refDoc = """ + public class Goo + { + } -namespace Foo -{ - public static class GooExtensions - { - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] - public static void Bar(this Goo goo, int x) - { - } - } -}"; + namespace Foo + { + public static class GooExtensions + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] + public static void Bar(this Goo goo, int x) + { + } + } + } + """; var markup = refType switch { @@ -1758,30 +1808,32 @@ await VerifyImportItemExistsAsync( [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47551")] public async Task TestBrowsableNever(ReferenceType refType) { - var srcDoc = @" -class Program -{ - void M() - { - new Goo().$$ - } -}"; + var srcDoc = """ + class Program + { + void M() + { + new Goo().$$ + } + } + """; - var refDoc = @" -public class Goo -{ -} + var refDoc = """ + public class Goo + { + } -namespace Foo -{ - public static class GooExtensions - { - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public static void Bar(this Goo goo, int x) - { - } - } -}"; + namespace Foo + { + public static class GooExtensions + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public static void Bar(this Goo goo, int x) + { + } + } + } + """; var (markup, shouldContainItem) = refType switch { @@ -1816,30 +1868,32 @@ public async Task TestBrowsableAdvanced(ReferenceType refType, bool hideAdvanced { HideAdvancedMembers = hideAdvanced; - var srcDoc = @" -class Program -{ - void M() - { - new Goo().$$ - } -}"; + var srcDoc = """ + class Program + { + void M() + { + new Goo().$$ + } + } + """; - var refDoc = @" -public class Goo -{ -} + var refDoc = """ + public class Goo + { + } -namespace Foo -{ - public static class GooExtensions - { - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - public static void Bar(this Goo goo, int x) - { - } - } -}"; + namespace Foo + { + public static class GooExtensions + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static void Bar(this Goo goo, int x) + { + } + } + } + """; var (markup, shouldContainItem) = (refType, hideAdvanced) switch { @@ -1871,57 +1925,59 @@ await VerifyImportItemIsAbsentAsync( [InlineData(';')] public async Task TestCommitWithCustomizedCharForMethod(char commitChar) { - var markup = @" -public class C -{ -} -namespace AA -{ - public static class Ext - { - public static int ToInt(this C c) - => 1; - } -} + var markup = """ + public class C + { + } + namespace AA + { + public static class Ext + { + public static int ToInt(this C c) + => 1; + } + } -namespace BB -{ - public class B - { - public void M() - { - var c = new C(); - c.$$ - } - } -}"; + namespace BB + { + public class B + { + public void M() + { + var c = new C(); + c.$$ + } + } + } + """; - var expected = $@" -using AA; + var expected = $$""" + using AA; -public class C -{{ -}} -namespace AA -{{ - public static class Ext - {{ - public static int ToInt(this C c) - => 1; - }} -}} + public class C + { + } + namespace AA + { + public static class Ext + { + public static int ToInt(this C c) + => 1; + } + } -namespace BB -{{ - public class B - {{ - public void M() - {{ - var c = new C(); - c.ToInt(){commitChar} - }} - }} -}}"; + namespace BB + { + public class B + { + public void M() + { + var c = new C(); + c.ToInt(){{commitChar}} + } + } + } + """; await VerifyProviderCommitAsync(markup, "ToInt", expected, commitChar: commitChar, sourceCodeKind: SourceCodeKind.Regular); } @@ -1931,18 +1987,19 @@ public void M() [Theory] public async Task TestTargetTypedCompletion(string targetType, bool matchTargetType, string expectedParameterList) { - var refDoc = @" -using System; + var refDoc = """ + using System; -namespace NS2 -{ - public static class Extensions - { - public static int ExtentionMethod(this int t, int a) => 0; - public static int[] ExtentionMethod(this int t, int a, int b) => null; - public static string ExtentionMethod(this int t, int a, int b, int c) => false; - } -}"; + namespace NS2 + { + public static class Extensions + { + public static int ExtentionMethod(this int t, int a) => 0; + public static int[] ExtentionMethod(this int t, int a, int b) => null; + public static string ExtentionMethod(this int t, int a, int b, int c) => false; + } + } + """; var srcDoc = $@" namespace NS1 {{ diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExternAliasCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExternAliasCompletionProviderTests.cs index 34be841188ecd..60cab4230ab8b 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExternAliasCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExternAliasCompletionProviderTests.cs @@ -22,51 +22,57 @@ internal override Type GetCompletionProviderType() [Fact] public async Task NoAliases() { - await VerifyNoItemsExistAsync(@" -extern alias $$ -class C -{ -}"); + await VerifyNoItemsExistAsync(""" + extern alias $$ + class C + { + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] public async Task ExternAlias() { - var markup = @" -extern alias $$ "; + var markup = """ + extern alias $$ + """; await VerifyItemWithAliasedMetadataReferencesAsync(markup, "goo", "goo", 1, "C#", "C#"); } [Fact] public async Task NotAfterExternAlias() { - var markup = @" -extern alias goo $$ "; + var markup = """ + extern alias goo $$ + """; await VerifyItemWithAliasedMetadataReferencesAsync(markup, "goo", "goo", 0, "C#", "C#"); } [Fact] public async Task NotGlobal() { - var markup = @" -extern alias $$ "; + var markup = """ + extern alias $$ + """; await VerifyItemWithAliasedMetadataReferencesAsync(markup, "goo", "global", 0, "C#", "C#"); } [Fact] public async Task NotIfAlreadyUsed() { - var markup = @" -extern alias goo; -extern alias $$"; + var markup = """ + extern alias goo; + extern alias $$ + """; await VerifyItemWithAliasedMetadataReferencesAsync(markup, "goo", "goo", 0, "C#", "C#"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1075278")] public async Task NotInComment() { - var markup = @" -extern alias // $$ "; + var markup = """ + extern alias // $$ + """; await VerifyNoItemsExistAsync(markup); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs index 899f35ff449b6..bb8448ffa15f6 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs @@ -20,32 +20,34 @@ public class FunctionPointerUnmanagedCallingConventionCompletionProviderTests : [Fact] public async Task TypeFound() { - var markup = @" -namespace System.Runtime.CompilerServices -{ - public class CallConvUnitTest { } -} + var markup = """ + namespace System.Runtime.CompilerServices + { + public class CallConvUnitTest { } + } -class C -{ - delegate* unmanaged[$$] f; -}"; + class C + { + delegate* unmanaged[$$] f; + } + """; await VerifyItemExistsAsync(markup, "UnitTest"); } [Fact] public async Task TypeFoundSecondCallingConvention() { - var markup = @" -namespace System.Runtime.CompilerServices -{ - public class CallConvUnitTest { } -} + var markup = """ + namespace System.Runtime.CompilerServices + { + public class CallConvUnitTest { } + } -class C -{ - delegate* unmanaged[Thiscall, $$] f; -}"; + class C + { + delegate* unmanaged[Thiscall, $$] f; + } + """; await VerifyItemExistsAsync(markup, "UnitTest"); } @@ -58,17 +60,18 @@ public async Task PredefinedCallingConventionFound(string callingConvention) { // We explicitly create a project with no references (not even common references) to ensure we // get the defaults - var markup = @" - - - - class C - { - delegate* unmanaged[$$] <int, string> f; - } - - -"; + var markup = """ + + + + class C + { + delegate* unmanaged[$$] <int, string> f; + } + + + + """; await VerifyItemExistsAsync(markup, callingConvention, glyph: (int)Glyph.Keyword); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/IndexerCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/IndexerCompletionProviderTests.cs index fa3e2ca9d86e8..3b04c90a596ea 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/IndexerCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/IndexerCompletionProviderTests.cs @@ -23,142 +23,142 @@ internal override Type GetCompletionProviderType() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerIsSuggestedAfterDot() { - await VerifyItemExistsAsync(@" -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", "this", displayTextSuffix: "[]", matchingFilters: new List { FilterSet.PropertyFilter }); + await VerifyItemExistsAsync(""" + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, "this", displayTextSuffix: "[]", matchingFilters: new List { FilterSet.PropertyFilter }); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerIsSuggestedAfterDotForString() { - await VerifyItemExistsAsync(@" -public class Program -{ - public static void Main(string s) - { - s.$$ - } -} -", "this", displayTextSuffix: "[]", matchingFilters: new List { FilterSet.PropertyFilter }); + await VerifyItemExistsAsync(""" + public class Program + { + public static void Main(string s) + { + s.$$ + } + } + """, "this", displayTextSuffix: "[]", matchingFilters: new List { FilterSet.PropertyFilter }); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerIsNotSuggestedOnStaticAccess() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - C.$$ - } -} -"); + await VerifyNoItemsExistAsync(""" + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + C.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerIsNotSuggestedInNameOfContext() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - var name = nameof(c.$$ - } -} -"); + await VerifyNoItemsExistAsync(""" + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + var name = nameof(c.$$ + } + } + """); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerSuggestionCommitsOpenAndClosingBraces() { - await VerifyCustomCommitProviderAsync(@" -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", "this", @" -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c[$$] - } -} -"); + await VerifyCustomCommitProviderAsync(""" + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, "this", """ + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c[$$] + } + } + """); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerWithTwoParametersSuggestionCommitsOpenAndClosingBraces() { - await VerifyCustomCommitProviderAsync(@" -public class C -{ - public int this[int x, int y] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", "this", @" -public class C -{ - public int this[int x, int y] => i; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c[$$] - } -} -"); + await VerifyCustomCommitProviderAsync(""" + public class C + { + public int this[int x, int y] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, "this", """ + public class C + { + public int this[int x, int y] => i; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c[$$] + } + } + """); } [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -262,125 +262,125 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerDescriptionIncludesDocCommentsAndOverloadsHint() { - await VerifyItemExistsAsync(@" -public class C -{ - /// - /// Returns the index - /// - /// The index - /// Returns the index - public int this[int i] => i; - - /// - /// Returns 1 - /// - /// The index - /// Returns 1 - public int this[string s] => 1; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -", "this", displayTextSuffix: "[]", expectedDescriptionOrNull: @$"int C.this[int i] {{ get; }} (+ 1 {FeaturesResources.overload}) + await VerifyItemExistsAsync(""" + public class C + { + /// + /// Returns the index + /// + /// The index + /// Returns the index + public int this[int i] => i; + + /// + /// Returns 1 + /// + /// The index + /// Returns 1 + public int this[string s] => 1; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """, "this", displayTextSuffix: "[]", expectedDescriptionOrNull: @$"int C.this[int i] {{ get; }} (+ 1 {FeaturesResources.overload}) Returns the index i"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerOfBaseTypeIsSuggestedAfterDot() { - await VerifyItemExistsAsync(@" -public class Base -{ - public int this[int i] => i; -} -public class Derived : Base -{ -} - -public class Program -{ - public static void Main() - { - var d = new Derived(); - d.$$ - } -} -", "this", displayTextSuffix: "[]"); + await VerifyItemExistsAsync(""" + public class Base + { + public int this[int i] => i; + } + public class Derived : Base + { + } + + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + """, "this", displayTextSuffix: "[]"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerOfBaseTypeIsNotSuggestedIfNotAccessible() { - await VerifyNoItemsExistAsync(@" -public class Base -{ - protected int this[int i] => i; -} -public class Derived : Base -{ -} - -public class Program -{ - public static void Main() - { - var d = new Derived(); - d.$$ - } -} -"); + await VerifyNoItemsExistAsync(""" + public class Base + { + protected int this[int i] => i; + } + public class Derived : Base + { + } + + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerIsSuggestedOnString() { - await VerifyItemExistsAsync(@" -public class Program -{ - public static void Main() - { - var s = ""Test""; - s.$$ - } -} -", "this", displayTextSuffix: "[]"); + await VerifyItemExistsAsync(""" + public class Program + { + public static void Main() + { + var s = "Test"; + s.$$ + } + } + """, "this", displayTextSuffix: "[]"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnIndexerIsRespected_EditorBrowsableStateNever() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Never)] - public int this[int i] => i; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Never)] + public int this[int i] => i; + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -395,31 +395,31 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnIndexerIsRespected_EditorBrowsableStateAdvanced() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Advanced)] - public int this[int i] => i; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Advanced)] + public int this[int i] => i; + } + } + """; HideAdvancedMembers = true; await VerifyItemInEditorBrowsableContextsAsync( @@ -446,35 +446,35 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnIndexerIsRespected_EditorBrowsableStateNever_InheritedMember() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var d = new Derived(); - d.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class Base - { - [EditorBrowsable(EditorBrowsableState.Never)] - public int this[int i] => i; - } - - public class Derived: Base - { - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class Base + { + [EditorBrowsable(EditorBrowsableState.Never)] + public int this[int i] => i; + } + + public class Derived: Base + { + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -489,39 +489,39 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task IndexerNullForgivingOperatorHandling() { - await VerifyCustomCommitProviderAsync(@" -#nullable enable - -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - C? c = null; - var i = c!.$$ - } -} -", "this", @" -#nullable enable - -public class C -{ - public int this[int i] => i; -} - -public class Program -{ - public static void Main() - { - C? c = null; - var i = c![$$] - } -} -"); + await VerifyCustomCommitProviderAsync(""" + #nullable enable + + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + C? c = null; + var i = c!.$$ + } + } + """, "this", """ + #nullable enable + + public class C + { + public int this[int i] => i; + } + + public class Program + { + public static void Main() + { + C? c = null; + var i = c![$$] + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/KeywordCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/KeywordCompletionProviderTests.cs index 56463771e638e..e819aa650de13 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/KeywordCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/KeywordCompletionProviderTests.cs @@ -46,25 +46,27 @@ public async Task InEmptyFile() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInInactiveCode() { - var markup = @"class C -{ - void M() - { -#if false -$$ -"; + var markup = """ + class C + { + void M() + { + #if false + $$ + """; await VerifyNoItemsExistAsync(markup); } [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInCharLiteral() { - var markup = @"class C -{ - void M() - { - var c = '$$'; -"; + var markup = """ + class C + { + void M() + { + var c = '$$'; + """; await VerifyNoItemsExistAsync(markup); } @@ -72,11 +74,13 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedCharLiteral() { - var markup = @"class C -{ - void M() - { - var c = '$$ "; + var markup = """ + class C + { + void M() + { + var c = '$$ + """; await VerifyNoItemsExistAsync(markup); } @@ -84,11 +88,13 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedCharLiteralAtEndOfFile() { - var markup = @"class C -{ - void M() - { - var c = '$$"; + var markup = """ + class C + { + void M() + { + var c = '$$ + """; await VerifyNoItemsExistAsync(markup); } @@ -96,12 +102,13 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInString() { - var markup = @"class C -{ - void M() - { - var s = ""$$""; -"; + var markup = """ + class C + { + void M() + { + var s = "$$"; + """; await VerifyNoItemsExistAsync(markup); } @@ -109,7 +116,9 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInStringInDirective() { - var markup = "#r \"$$\""; + var markup = """ + #r "$$" + """; await VerifyNoItemsExistAsync(markup, SourceCodeKind.Script); } @@ -117,11 +126,13 @@ public async Task NotInStringInDirective() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedString() { - var markup = @"class C -{ - void M() - { - var s = ""$$ "; + var markup = """ + class C + { + void M() + { + var s = "$$ + """; await VerifyNoItemsExistAsync(markup); } @@ -129,7 +140,9 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedStringInDirective() { - var markup = "#r \"$$\""; + var markup = """ + #r "$$" + """; await VerifyNoItemsExistAsync(markup, SourceCodeKind.Script); } @@ -137,11 +150,13 @@ public async Task NotInUnterminatedStringInDirective() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedStringAtEndOfFile() { - var markup = @"class C -{ - void M() - { - var s = ""$$"; + var markup = """ + class C + { + void M() + { + var s = "$$ + """; await VerifyNoItemsExistAsync(markup); } @@ -149,14 +164,15 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInVerbatimString() { - var markup = @"class C -{ - void M() - { - var s = @"" -$$ -""; -"; + var markup = """ + class C + { + void M() + { + var s = @" + $$ + "; + """; await VerifyNoItemsExistAsync(markup); } @@ -164,13 +180,14 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedVerbatimString() { - var markup = @"class C -{ - void M() - { - var s = @"" -$$ -"; + var markup = """ + class C + { + void M() + { + var s = @" + $$ + """; await VerifyNoItemsExistAsync(markup); } @@ -178,11 +195,13 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInUnterminatedVerbatimStringAtEndOfFile() { - var markup = @"class C -{ - void M() - { - var s = @""$$"; + var markup = """ + class C + { + void M() + { + var s = @"$$ + """; await VerifyNoItemsExistAsync(markup); } @@ -190,12 +209,13 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInSingleLineComment() { - var markup = @"class C -{ - void M() - { - // $$ -"; + var markup = """ + class C + { + void M() + { + // $$ + """; await VerifyNoItemsExistAsync(markup); } @@ -203,9 +223,11 @@ void M() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInSingleLineCommentAtEndOfFile() { - var markup = @"namespace A -{ -}// $$"; + var markup = """ + namespace A + { + }// $$ + """; await VerifyNoItemsExistAsync(markup); } @@ -213,14 +235,15 @@ public async Task NotInSingleLineCommentAtEndOfFile() [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task NotInMutliLineComment() { - var markup = @"class C -{ - void M() - { -/* - $$ -*/ -"; + var markup = """ + class C + { + void M() + { + /* + $$ + */ + """; await VerifyNoItemsExistAsync(markup); } @@ -229,28 +252,30 @@ void M() [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/968256")] public async Task UnionOfItemsFromBothContexts() { - var markup = @" - - + + - - - - - -"; + #if GOO + } + #endif + } + ]]> + + + + + + + """; await VerifyItemInLinkedFilesAsync(markup, "public", null); await VerifyItemInLinkedFilesAsync(markup, "for", null); } @@ -260,17 +285,21 @@ void goo() { [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task FormattingAfterCompletionCommit_AfterGetAccessorInSingleLineIncompleteProperty() { - var markupBeforeCommit = @"class Program -{ - int P {g$$ - void Main() { } -}"; + var markupBeforeCommit = """ + class Program + { + int P {g$$ + void Main() { } + } + """; - var expectedCodeAfterCommit = @"class Program -{ - int P {get; - void Main() { } -}"; + var expectedCodeAfterCommit = """ + class Program + { + int P {get; + void Main() { } + } + """; await VerifyProviderCommitAsync(markupBeforeCommit, "get", expectedCodeAfterCommit, commitChar: ';'); } @@ -279,17 +308,21 @@ void Main() { } [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task FormattingAfterCompletionCommit_AfterBothAccessorsInSingleLineIncompleteProperty() { - var markupBeforeCommit = @"class Program -{ - int P {get;set$$ - void Main() { } -}"; + var markupBeforeCommit = """ + class Program + { + int P {get;set$$ + void Main() { } + } + """; - var expectedCodeAfterCommit = @"class Program -{ - int P {get;set; - void Main() { } -}"; + var expectedCodeAfterCommit = """ + class Program + { + int P {get;set; + void Main() { } + } + """; await VerifyProviderCommitAsync(markupBeforeCommit, "set", expectedCodeAfterCommit, commitChar: ';'); } @@ -298,17 +331,21 @@ void Main() { } [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task FormattingAfterCompletionCommit_InSingleLineMethod() { - var markupBeforeCommit = @"class Program -{ - public static void Test() { return$$ - void Main() { } -}"; + var markupBeforeCommit = """ + class Program + { + public static void Test() { return$$ + void Main() { } + } + """; - var expectedCodeAfterCommit = @"class Program -{ - public static void Test() { return; - void Main() { } -}"; + var expectedCodeAfterCommit = """ + class Program + { + public static void Test() { return; + void Main() { } + } + """; await VerifyProviderCommitAsync(markupBeforeCommit, "return", expectedCodeAfterCommit, commitChar: ';'); } @@ -316,18 +353,19 @@ void Main() { } [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task PredefinedTypeKeywordsShouldBeRecommendedAfterCaseInASwitch() { - var text = @" -class Program -{ - public static void Test() - { - object o = null; - switch (o) - { - case $$ - } - } -}"; + var text = """ + class Program + { + public static void Test() + { + object o = null; + switch (o) + { + case $$ + } + } + } + """; await VerifyItemExistsAsync(text, "int"); await VerifyItemExistsAsync(text, "string"); @@ -338,11 +376,12 @@ public static void Test() [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task PrivateOrProtectedModifiers() { - var text = @" -class C -{ -$$ -}"; + var text = """ + class C + { + $$ + } + """; await VerifyItemExistsAsync(text, "private"); await VerifyItemExistsAsync(text, "protected"); @@ -351,11 +390,12 @@ class C [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task PrivateProtectedModifier() { - var text = @" -class C -{ - private $$ -}"; + var text = """ + class C + { + private $$ + } + """; await VerifyItemExistsAsync(text, "protected"); } @@ -363,11 +403,12 @@ class C [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task ProtectedPrivateModifier() { - var text = @" -class C -{ - protected $$ -}"; + var text = """ + class C + { + protected $$ + } + """; await VerifyItemExistsAsync(text, "private"); } @@ -377,10 +418,11 @@ class C public async Task DoNotSuggestEventAfterReadonlyInClass() { var markup = -@"class C { - readonly $$ -} -"; + """ + class C { + readonly $$ + } + """; await VerifyItemIsAbsentAsync(markup, "event"); } @@ -389,10 +431,11 @@ public async Task DoNotSuggestEventAfterReadonlyInClass() public async Task DoNotSuggestEventAfterReadonlyInInterface() { var markup = -@"interface C { - readonly $$ -} -"; + """ + interface C { + readonly $$ + } + """; await VerifyItemIsAbsentAsync(markup, "event"); } @@ -401,10 +444,11 @@ public async Task DoNotSuggestEventAfterReadonlyInInterface() public async Task SuggestEventAfterReadonlyInStruct() { var markup = -@"struct C { - readonly $$ -} -"; + """ + struct C { + readonly $$ + } + """; await VerifyItemExistsAsync(markup, "event"); } @@ -516,12 +560,13 @@ event System.Action E {{ public async Task SuggestAccessorAfterReadonlyInStruct() { var markup = -@"struct C { - int X { - readonly $$ - } -} -"; + """ + struct C { + int X { + readonly $$ + } + } + """; await VerifyItemExistsAsync(markup, "get"); await VerifyItemExistsAsync(markup, "set"); await VerifyItemIsAbsentAsync(markup, "void"); @@ -533,10 +578,11 @@ public async Task SuggestReadonlyMethodInStruct() { var markup = -@"struct C { - public $$ void M() {} -} -"; + """ + struct C { + public $$ void M() {} + } + """; await VerifyItemExistsAsync(markup, "readonly"); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs index 36ca14e0a5b58..8537d6a9138a2 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs @@ -68,10 +68,16 @@ public void IsTextualTriggerCharacterTest(string markup) [InlineData("#loa\"$$", false)] [InlineData("#load\"$$", true)] [InlineData(" # load \"$$", true)] - [InlineData(" # load \"$$\"", true)] + [InlineData(""" + # load "$$" + """, true)] [InlineData(" # load \"\"$$", true)] - [InlineData("$$ # load \"\"", false)] - [InlineData(" # load $$\"\"", false)] + [InlineData(""" + $$ # load "" + """, false)] + [InlineData(""" + # load $$"" + """, false)] public void ShouldTriggerCompletion(string textWithPositionMarker, bool expectedResult) { var position = textWithPositionMarker.IndexOf("$$"); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/NamedParameterCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/NamedParameterCompletionProviderTests.cs index 46d3a7fc0bc29..c5fc983cd0d24 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/NamedParameterCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/NamedParameterCompletionProviderTests.cs @@ -22,17 +22,18 @@ internal override Type GetCompletionProviderType() [Fact] public async Task SendEnterThroughToEditorTest() { - const string markup = @" -class Goo -{ - public Goo(int a = 42) - { } - - void Bar() - { - var b = new Goo($$ - } -}"; + const string markup = """ + class Goo + { + public Goo(int a = 42) + { } + + void Bar() + { + var b = new Goo($$ + } + } + """; await VerifySendEnterThroughToEnterAsync(markup, "a:", sendThroughEnterOption: EnterKeyRule.Never, expected: false); await VerifySendEnterThroughToEnterAsync(markup, "a:", sendThroughEnterOption: EnterKeyRule.AfterFullyTypedWord, expected: true); @@ -42,17 +43,18 @@ void Bar() [Fact] public async Task CommitCharacterTest() { - const string markup = @" -class Goo -{ - public Goo(int a = 42) - { } - - void Bar() - { - var b = new Goo($$ - } -}"; + const string markup = """ + class Goo + { + public Goo(int a = 42) + { } + + void Bar() + { + var b = new Goo($$ + } + } + """; await VerifyCommonCommitCharactersAsync(markup, textTypedSoFar: ""); } @@ -60,17 +62,18 @@ void Bar() [Fact] public async Task InObjectCreation() { - var markup = @" -class Goo -{ - public Goo(int a = 42) - { } - - void Bar() - { - var b = new Goo($$ - } -}"; + var markup = """ + class Goo + { + public Goo(int a = 42) + { } + + void Bar() + { + var b = new Goo($$ + } + } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -78,18 +81,18 @@ void Bar() [Fact] public async Task InBaseConstructor() { - var markup = @" -class Goo -{ - public Goo(int a = 42) - { } -} - -class DogBed : Goo -{ - public DogBed(int b) : base($$ -} -"; + var markup = """ + class Goo + { + public Goo(int a = 42) + { } + } + + class DogBed : Goo + { + public DogBed(int b) : base($$ + } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -97,15 +100,15 @@ public DogBed(int b) : base($$ [Fact] public async Task InvocationExpression() { - var markup = @" -class Goo -{ - void Bar(int a) - { - Bar($$ - } -} -"; + var markup = """ + class Goo + { + void Bar(int a) + { + Bar($$ + } + } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -113,15 +116,15 @@ void Bar(int a) [Fact] public async Task InvocationExpressionAfterComma() { - var markup = @" -class Goo -{ - void Bar(int a, string b) - { - Bar(b:"""", $$ - } -} -"; + var markup = """ + class Goo + { + void Bar(int a, string b) + { + Bar(b:"", $$ + } + } + """; await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":"); } @@ -129,32 +132,32 @@ void Bar(int a, string b) [Fact] public async Task ElementAccessExpression() { - var markup = @" -class SampleCollection -{ - private T[] arr = new T[100]; - public T this[int i] - { - get - { - return arr[i]; - } - set - { - arr[i] = value; - } - } -} - -class Program -{ - static void Main(string[] args) - { - SampleCollection stringCollection = new SampleCollection(); - stringCollection[$$ - } -} -"; + var markup = """ + class SampleCollection + { + private T[] arr = new T[100]; + public T this[int i] + { + get + { + return arr[i]; + } + set + { + arr[i] = value; + } + } + } + + class Program + { + static void Main(string[] args) + { + SampleCollection stringCollection = new SampleCollection(); + stringCollection[$$ + } + } + """; await VerifyItemExistsAsync(markup, "i", displayTextSuffix: ":"); } @@ -162,19 +165,19 @@ static void Main(string[] args) [Fact] public async Task PartialMethods() { - var markup = @" -partial class PartialClass -{ - static partial void Goo(int declaring); - static partial void Goo(int implementing) - { - } - static void Caller() - { - Goo($$ - } -} -"; + var markup = """ + partial class PartialClass + { + static partial void Goo(int declaring); + static partial void Goo(int implementing) + { + } + static void Caller() + { + Goo($$ + } + } + """; await VerifyItemExistsAsync(markup, "declaring", displayTextSuffix: ":"); await VerifyItemIsAbsentAsync(markup, "implementing", displayTextSuffix: ":"); @@ -183,19 +186,19 @@ static void Caller() [Fact] public async Task ExtendedPartialMethods() { - var markup = @" -partial class PartialClass -{ - public static partial void Goo(int declaring); - public static partial void Goo(int implementing) - { - } - static void Caller() - { - Goo($$ - } -} -"; + var markup = """ + partial class PartialClass + { + public static partial void Goo(int declaring); + public static partial void Goo(int implementing) + { + } + static void Caller() + { + Goo($$ + } + } + """; await VerifyItemExistsAsync(markup, "declaring", displayTextSuffix: ":"); await VerifyItemIsAbsentAsync(markup, "implementing", displayTextSuffix: ":"); @@ -204,15 +207,15 @@ static void Caller() [Fact] public async Task NotAfterColon() { - var markup = @" -class Goo -{ - void Bar(int a, string b) - { - Bar(a:$$ - } -} -"; + var markup = """ + class Goo + { + void Bar(int a, string b) + { + Bar(a:$$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -220,16 +223,16 @@ void Bar(int a, string b) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544292")] public async Task NotInCollectionInitializers() { - var markup = @" -using System.Collections.Generic; -class Goo -{ - void Bar(List integers) - { - Bar(integers: new List { 10, 11,$$ 12 }); - } -} -"; + var markup = """ + using System.Collections.Generic; + class Goo + { + void Bar(List integers) + { + Bar(integers: new List { 10, 11,$$ 12 }); + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -237,21 +240,21 @@ void Bar(List integers) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544191")] public async Task FilteringOverloadsByCallSite() { - var markup = @" -class Class1 -{ - void Test() - { - Goo(boolean:true, $$) - } - - void Goo(string str = ""hello"", char character = 'a') - { } - - void Goo(string str = ""hello"", bool boolean = false) - { } -} -"; + var markup = """ + class Class1 + { + void Test() + { + Goo(boolean:true, $$) + } + + void Goo(string str = "hello", char character = 'a') + { } + + void Goo(string str = "hello", bool boolean = false) + { } + } + """; await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":"); await VerifyItemIsAbsentAsync(markup, "character", displayTextSuffix: ":"); @@ -260,21 +263,21 @@ void Goo(string str = ""hello"", bool boolean = false) [Fact] public async Task DoNotFilterYet() { - var markup = @" -class Class1 -{ - void Test() - { - Goo(str:"""", $$) - } - - void Goo(string str = ""hello"", char character = 'a') - { } - - void Goo(string str = ""hello"", bool boolean = false) - { } -} -"; + var markup = """ + class Class1 + { + void Test() + { + Goo(str:"", $$) + } + + void Goo(string str = "hello", char character = 'a') + { } + + void Goo(string str = "hello", bool boolean = false) + { } + } + """; await VerifyItemExistsAsync(markup, "boolean", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "character", displayTextSuffix: ":"); @@ -283,30 +286,30 @@ void Goo(string str = ""hello"", bool boolean = false) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544191")] public async Task FilteringOverloadsByCallSiteComplex() { - var markup = @" -class Goo -{ - void Test() - { - Bar m = new Bar(); - Method(obj:m, $$ - } - - void Method(Bar obj, int num = 23, string str = """") - { - } - void Method(double dbl = double.MinValue, string str = """") - { - } - void Method(int num = 1, bool b = false, string str = """") - { - } - void Method(Bar obj, bool b = false, string str = """") - { - } -} -class Bar { } -"; + var markup = """ + class Goo + { + void Test() + { + Bar m = new Bar(); + Method(obj:m, $$ + } + + void Method(Bar obj, int num = 23, string str = "") + { + } + void Method(double dbl = double.MinValue, string str = "") + { + } + void Method(int num = 1, bool b = false, string str = "") + { + } + void Method(Bar obj, bool b = false, string str = "") + { + } + } + class Bar { } + """; await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":"); @@ -316,26 +319,26 @@ class Bar { } [Fact] public async Task MethodOverloads() { - var markup = @" -class Goo -{ - void Test() - { - object m = null; - Method(m, $$ - } - - void Method(object obj, int num = 23, string str = """") - { - } - void Method(int num = 1, bool b = false, string str = """") - { - } - void Method(object obj, bool b = false, string str = """") - { - } -} -"; + var markup = """ + class Goo + { + void Test() + { + object m = null; + Method(m, $$ + } + + void Method(object obj, int num = 23, string str = "") + { + } + void Method(int num = 1, bool b = false, string str = "") + { + } + void Method(object obj, bool b = false, string str = "") + { + } + } + """; await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":"); @@ -344,29 +347,29 @@ void Method(object obj, bool b = false, string str = """") [Fact] public async Task ExistingNamedParamsAreFilteredOut() { - var markup = @" -class Goo -{ - void Test() - { - object m = null; - Method(obj: m, str: """", $$); - } - - void Method(object obj, int num = 23, string str = """") - { - } - void Method(double dbl = double.MinValue, string str = """") - { - } - void Method(int num = 1, bool b = false, string str = """") - { - } - void Method(object obj, bool b = false, string str = """") - { - } -} -"; + var markup = """ + class Goo + { + void Test() + { + object m = null; + Method(obj: m, str: "", $$); + } + + void Method(object obj, int num = 23, string str = "") + { + } + void Method(double dbl = double.MinValue, string str = "") + { + } + void Method(int num = 1, bool b = false, string str = "") + { + } + void Method(object obj, bool b = false, string str = "") + { + } + } + """; await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":"); await VerifyItemIsAbsentAsync(markup, "obj", displayTextSuffix: ":"); @@ -376,36 +379,36 @@ void Method(object obj, bool b = false, string str = """") [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529369")] public async Task VerbatimIdentifierNotAKeyword() { - var markup = @" -class Program -{ - void Goo(int @integer) - { - Goo(@i$$ - } -} -"; + var markup = """ + class Program + { + void Goo(int @integer) + { + Goo(@i$$ + } + } + """; await VerifyItemExistsAsync(markup, "integer", displayTextSuffix: ":"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544209")] public async Task DescriptionStringInMethodOverloads() { - var markup = @" -class Class1 -{ - void Test() - { - Goo(boolean: true, $$) - } - - void Goo(string obj = ""hello"") - { } - - void Goo(bool boolean = false, Class1 obj = default(Class1)) - { } -} -"; + var markup = """ + class Class1 + { + void Test() + { + Goo(boolean: true, $$) + } + + void Goo(string obj = "hello") + { } + + void Goo(bool boolean = false, Class1 obj = default(Class1)) + { } + } + """; await VerifyItemExistsAsync(markup, "obj", displayTextSuffix: ":", expectedDescriptionOrNull: $"({FeaturesResources.parameter}) Class1 obj = default(Class1)"); } @@ -413,111 +416,113 @@ await VerifyItemExistsAsync(markup, "obj", displayTextSuffix: ":", [Fact] public async Task InDelegates() { - var markup = @" -public delegate void Del(string message); - -class Program -{ - public static void DelegateMethod(string message) - { - System.Console.WriteLine(message); - } - - static void Main(string[] args) - { - Del handler = DelegateMethod; - handler($$ - } -}"; + var markup = """ + public delegate void Del(string message); + + class Program + { + public static void DelegateMethod(string message) + { + System.Console.WriteLine(message); + } + + static void Main(string[] args) + { + Del handler = DelegateMethod; + handler($$ + } + } + """; await VerifyItemExistsAsync(markup, "message", displayTextSuffix: ":"); } [Fact] public async Task InDelegateInvokeSyntax() { - var markup = @" -public delegate void Del(string message); - -class Program -{ - public static void DelegateMethod(string message) - { - System.Console.WriteLine(message); - } - - static void Main(string[] args) - { - Del handler = DelegateMethod; - handler.Invoke($$ - } -}"; + var markup = """ + public delegate void Del(string message); + + class Program + { + public static void DelegateMethod(string message) + { + System.Console.WriteLine(message); + } + + static void Main(string[] args) + { + Del handler = DelegateMethod; + handler.Invoke($$ + } + } + """; await VerifyItemExistsAsync(markup, "message", displayTextSuffix: ":"); } [Fact] public async Task NotInComment() { - var markup = @" -public class Test -{ -static void Main() -{ -M(x: 0, //Hit ctrl-space at the end of this comment $$ -y: 1); -} -static void M(int x, int y) { } -} -"; + var markup = """ + public class Test + { + static void Main() + { + M(x: 0, //Hit ctrl-space at the end of this comment $$ + y: 1); + } + static void M(int x, int y) { } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task CommitWithColonWordFullyTyped() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - Main(args$$) - } -} -"; - - var expected = @" -class Program -{ - static void Main(string[] args) - { - Main(args:) - } -} -"; + var markup = """ + class Program + { + static void Main(string[] args) + { + Main(args$$) + } + } + """; + + var expected = """ + class Program + { + static void Main(string[] args) + { + Main(args:) + } + } + """; await VerifyProviderCommitAsync(markup, "args:", expected, ':'); } [Fact] public async Task CommitWithColonWordPartiallyTyped() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - Main(arg$$) - } -} -"; - - var expected = @" -class Program -{ - static void Main(string[] args) - { - Main(args:) - } -} -"; + var markup = """ + class Program + { + static void Main(string[] args) + { + Main(arg$$) + } + } + """; + + var expected = """ + class Program + { + static void Main(string[] args) + { + Main(args:) + } + } + """; await VerifyProviderCommitAsync(markup, "args:", expected, ':'); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.cs index f5d1c65dfad1d..16e149cddd331 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.cs @@ -26,16 +26,17 @@ internal override Type GetCompletionProviderType() [Fact] public async Task NothingToInitialize() { - var markup = @" -class C { } - -class D -{ - void goo() - { - C goo = new C { $$ - } -}"; + var markup = """ + class C { } + + class D + { + void goo() + { + C goo = new C { $$ + } + } + """; await VerifyNoItemsExistAsync(markup); await VerifyExclusiveAsync(markup, true); @@ -44,16 +45,17 @@ void goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/46397")] public async Task ImplicitObjectCreation_NothingToInitialize() { - var markup = @" -class C { } - -class D -{ - void goo() - { - C goo = new() { $$ - } -}"; + var markup = """ + class C { } + + class D + { + void goo() + { + C goo = new() { $$ + } + } + """; await VerifyNoItemsExistAsync(markup); await VerifyExclusiveAsync(markup, true); @@ -62,16 +64,17 @@ void goo() [Fact] public async Task OneItem1() { - var markup = @" -class C { public int value {set; get; }} - -class D -{ - void goo() - { - C goo = new C { v$$ - } -}"; + var markup = """ + class C { public int value {set; get; }} + + class D + { + void goo() + { + C goo = new C { v$$ + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemIsAbsentAsync(markup, "k__BackingField"); @@ -81,16 +84,17 @@ void goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/46397")] public async Task ImplicitObjectCreation_OneItem1() { - var markup = @" -class C { public int value {set; get; }} - -class D -{ - void goo() - { - C goo = new() { v$$ - } -}"; + var markup = """ + class C { public int value {set; get; }} + + class D + { + void goo() + { + C goo = new() { v$$ + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemIsAbsentAsync(markup, "k__BackingField"); @@ -100,16 +104,17 @@ void goo() [Fact] public async Task ImplicitObjectCreation_NullableStruct_OneItem1() { - var markup = @" -struct S { public int value {set; get; }} - -class D -{ - void goo() - { - S? goo = new() { v$$ - } -}"; + var markup = """ + struct S { public int value {set; get; }} + + class D + { + void goo() + { + S? goo = new() { v$$ + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemIsAbsentAsync(markup, "k__BackingField"); @@ -119,16 +124,17 @@ void goo() [Fact] public async Task ShowWithEqualsSign() { - var markup = @" -class C { public int value {set; get; }} - -class D -{ - void goo() - { - C goo = new C { v$$= - } -}"; + var markup = """ + class C { public int value {set; get; }} + + class D + { + void goo() + { + C goo = new C { v$$= + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemIsAbsentAsync(markup, "k__BackingField"); @@ -138,16 +144,17 @@ void goo() [Fact] public async Task OneItem2() { - var markup = @" -class C -{ - public int value {set; get; } - - void goo() - { - C goo = new C { v$$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + + void goo() + { + C goo = new C { v$$ + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemIsAbsentAsync(markup, "k__BackingField"); @@ -157,20 +164,21 @@ void goo() [Fact] public async Task FieldAndProperty() { - var markup = @" -class C -{ - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C goo = new C { v$$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C goo = new C { v$$ + } + } + """; await VerifyItemExistsAsync(markup, "value"); await VerifyItemExistsAsync(markup, "otherValue"); @@ -180,20 +188,21 @@ void goo() [Fact] public async Task HidePreviouslyTyped() { - var markup = @" -class C -{ - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C goo = new C { value = 3, o$$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C goo = new C { value = 3, o$$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "value"); await VerifyExclusiveAsync(markup, true); @@ -203,20 +212,21 @@ void goo() [Fact] public async Task NotInEqualsValue() { - var markup = @" -class C -{ - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C goo = new C { value = v$$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C goo = new C { value = v$$ + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -224,20 +234,21 @@ void goo() [Fact] public async Task NothingLeftToShow() { - var markup = @" -class C -{ - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C goo = new C { value = 3, otherValue = 4, $$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C goo = new C { value = 3, otherValue = 4, $$ + } + } + """; await VerifyNoItemsExistAsync(markup); await VerifyExclusiveAsync(markup, true); @@ -246,25 +257,26 @@ void goo() [Fact] public async Task NestedObjectInitializers() { - var markup = @" -class C -{ - public int value {set; get; } - public int otherValue; -} - -class D -{ - public C myValue {set; get;} -} - -class E -{ - void goo() - { - D bar = new D { myValue = new C { $$ - } -}"; + var markup = """ + class C + { + public int value {set; get; } + public int otherValue; + } + + class D + { + public C myValue {set; get;} + } + + class E + { + void goo() + { + D bar = new D { myValue = new C { $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "myValue"); await VerifyItemExistsAsync(markup, "value"); await VerifyItemExistsAsync(markup, "otherValue"); @@ -274,104 +286,111 @@ void goo() [Fact] public async Task NotExclusive1() { - var markup = @"using System.Collections.Generic; -class C : IEnumerable -{ - public void Add(int a) { } - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C bar = new C { v$$ - } -}"; + var markup = """ + using System.Collections.Generic; + class C : IEnumerable + { + public void Add(int a) { } + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C bar = new C { v$$ + } + } + """; await VerifyExclusiveAsync(markup, false); } [Fact] public async Task NotExclusive2() { - var markup = @"using System.Collections; -class C : IEnumerable -{ - public void Add(object a) { } - public int value {set; get; } - public int otherValue; -} - -class D -{ - void goo() - { - C bar = new C { v$$ - } -}"; + var markup = """ + using System.Collections; + class C : IEnumerable + { + public void Add(object a) { } + public int value {set; get; } + public int otherValue; + } + + class D + { + void goo() + { + C bar = new C { v$$ + } + } + """; await VerifyExclusiveAsync(markup, false); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544242")] public async Task NotInArgumentList() { - var markup = @"class C -{ - void M(int i, int j) - { - M(i, j$$ - } -} -"; + var markup = """ + class C + { + void M(int i, int j) + { + M(i, j$$ + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530075")] public async Task NotInArgumentList2() { - var markup = @"class C -{ - public int A; - void M(int i, int j) - { - new C(1, $$ - } -} -"; + var markup = """ + class C + { + public int A; + void M(int i, int j) + { + new C(1, $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544289")] public async Task DerivedMembers() { - var markup = @"using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -namespace ConsoleApplication1 -{ - class Base - { - public int GooBase; - private int BasePrivate { get; set; } - public int BasePublic{ get; set; } - } - - class Derived : Base - { - public int GooDerived; - } - - class Program - { - static void Main(string[] args) - { - var x = new Derived { F$$ - } - } -} -"; + var markup = """ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + namespace ConsoleApplication1 + { + class Base + { + public int GooBase; + private int BasePrivate { get; set; } + public int BasePublic{ get; set; } + } + + class Derived : Base + { + public int GooDerived; + } + + class Program + { + static void Main(string[] args) + { + var x = new Derived { F$$ + } + } + } + """; await VerifyItemExistsAsync(markup, "GooBase"); await VerifyItemExistsAsync(markup, "GooDerived"); await VerifyItemExistsAsync(markup, "BasePublic"); @@ -381,52 +400,55 @@ static void Main(string[] args) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544242")] public async Task NotInCollectionInitializer() { - var markup = @"using System.Collections.Generic; -class C -{ - void goo() - { - var a = new List {0, $$ - } -} -"; + var markup = """ + using System.Collections.Generic; + class C + { + void goo() + { + var a = new List {0, $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task InitializeDerivedType() { - var markup = @"using System.Collections.Generic; - -class B {} -class D : B -{ - public int goo; -} - -class C -{ - void stuff() - { - B a = new D { $$ - } -} -"; + var markup = """ + using System.Collections.Generic; + + class B {} + class D : B + { + public int goo; + } + + class C + { + void stuff() + { + B a = new D { $$ + } + } + """; await VerifyItemExistsAsync(markup, "goo"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544550")] public async Task ReadOnlyPropertiesShouldNotBePresent() { - var markup = @"using System.Collections.Generic; -class C -{ - void goo() - { - var a = new List {$$ - } -} -"; + var markup = """ + using System.Collections.Generic; + class C + { + void goo() + { + var a = new List {$$ + } + } + """; await VerifyItemExistsAsync(markup, "Capacity"); await VerifyItemIsAbsentAsync(markup, "Count"); @@ -435,15 +457,16 @@ void goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544550")] public async Task IndexersShouldNotBePresent() { - var markup = @"using System.Collections.Generic; -class C -{ - void goo() - { - var a = new List {$$ - } -} -"; + var markup = """ + using System.Collections.Generic; + class C + { + void goo() + { + var a = new List {$$ + } + } + """; await VerifyItemExistsAsync(markup, "Capacity"); await VerifyItemIsAbsentAsync(markup, "this[]"); @@ -452,18 +475,19 @@ void goo() [Fact] public async Task ReadOnlyPropertiesThatFollowTheCollectionPatternShouldBePresent() { - var markup = @"using System.Collections.Generic; -class C -{ - public readonly int goo; - public readonly List bar; - - void M() - { - new C() { $$ - } -} -"; + var markup = """ + using System.Collections.Generic; + class C + { + public readonly int goo; + public readonly List bar; + + void M() + { + new C() { $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "goo"); await VerifyItemExistsAsync(markup, "bar"); @@ -472,19 +496,20 @@ void M() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544607")] public async Task DoNotIncludeStaticMember() { - var markup = @" -class Goo -{ - public static int Gibberish { get; set; } -} - -class Bar -{ - void goo() - { - var c = new Goo { $$ - } -}"; + var markup = """ + class Goo + { + public static int Gibberish { get; set; } + } + + class Bar + { + void goo() + { + var c = new Goo { $$ + } + } + """; await VerifyItemIsAbsentAsync(markup, "Gibberish"); } @@ -492,20 +517,22 @@ void goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_PropertyInObjectCreationAlways() { - var markup = @" -public class C -{ - public void M() - { - var x = new Goo { $$ - } -}"; - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public string Prop { get; set; } -}"; + var markup = """ + public class C + { + public void M() + { + var x = new Goo { $$ + } + } + """; + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public string Prop { get; set; } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -520,20 +547,22 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_PropertyInObjectCreationNever() { - var markup = @" -public class C -{ - public void M() - { - var x = new Goo { $$ - } -}"; - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public string Prop { get; set; } -}"; + var markup = """ + public class C + { + public void M() + { + var x = new Goo { $$ + } + } + """; + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public string Prop { get; set; } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, referencedCode: referencedCode, @@ -547,20 +576,22 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545678")] public async Task EditorBrowsable_PropertyInObjectCreationAdvanced() { - var markup = @" -public class C -{ - public void M() - { - var x = new Goo { $$ - } -}"; - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - public string Prop { get; set; } -}"; + var markup = """ + public class C + { + public void M() + { + var x = new Goo { $$ + } + } + """; + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public string Prop { get; set; } + } + """; HideAdvancedMembers = true; await VerifyItemInEditorBrowsableContextsAsync( @@ -587,16 +618,17 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact] public async Task TestCommitCharacter() { - const string markup = @" -class C { public int value {set; get; }} - -class D -{ - void goo() - { - C goo = new C { v$$ - } -}"; + const string markup = """ + class C { public int value {set; get; }} + + class D + { + void goo() + { + C goo = new C { v$$ + } + } + """; await VerifyCommonCommitCharactersAsync(markup, textTypedSoFar: "v"); } @@ -604,16 +636,17 @@ void goo() [Fact] public async Task TestEnter() { - const string markup = @" -class C { public int value {set; get; }} - -class D -{ - void goo() - { - C goo = new C { v$$ - } -}"; + const string markup = """ + class C { public int value {set; get; }} + + class D + { + void goo() + { + C goo = new C { v$$ + } + } + """; using var workspace = TestWorkspace.CreateCSharp(markup, composition: GetComposition()); var hostDocument = workspace.Documents.Single(); @@ -636,15 +669,17 @@ public void TestTrigger() public async Task DoNotIncludeIndexedPropertyWithNonOptionalParameter() { var markup = @"C c01 = new C() {$$ }"; - var referencedCode = @"Public Class C - Public Property IndexProp(ByVal p1 As Integer) As String - Get - Return Nothing - End Get - Set(ByVal value As String) - End Set - End Property -End Class"; + var referencedCode = """ + Public Class C + Public Property IndexProp(ByVal p1 As Integer) As String + Get + Return Nothing + End Get + Set(ByVal value As String) + End Set + End Property + End Class + """; HideAdvancedMembers = false; @@ -661,40 +696,41 @@ await VerifyItemInEditorBrowsableContextsAsync( [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4754")] public async Task CollectionInitializerPatternFromBaseType() { - var markup = @" -using System; -using System.Collections; - -public class SupportsAdd : IEnumerable -{ - public void Add(int x) { } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } -} - -class SupportsAddDerived : SupportsAdd { } - -class Container -{ - public SupportsAdd S { get; } - public SupportsAddDerived D { get; } -} - -class Program -{ - static void Main(string[] args) - { - var y = new Container { $$ }; - } -}"; + var markup = """ + using System; + using System.Collections; + + public class SupportsAdd : IEnumerable + { + public void Add(int x) { } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + class SupportsAddDerived : SupportsAdd { } + + class Container + { + public SupportsAdd S { get; } + public SupportsAddDerived D { get; } + } + + class Program + { + static void Main(string[] args) + { + var y = new Container { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "S"); await VerifyItemExistsAsync(markup, "D"); @@ -703,40 +739,41 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4754")] public async Task CollectionInitializerPatternFromBaseTypeInaccessible() { - var markup = @" -using System; -using System.Collections; - -public class SupportsAdd : IEnumerable -{ - protected void Add(int x) { } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } -} - -class SupportsAddDerived : SupportsAdd { } - -class Container -{ - public SupportsAdd S { get; } - public SupportsAddDerived D { get; } -} - -class Program -{ - static void Main(string[] args) - { - var y = new Container { $$ }; - } -}"; + var markup = """ + using System; + using System.Collections; + + public class SupportsAdd : IEnumerable + { + protected void Add(int x) { } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + class SupportsAddDerived : SupportsAdd { } + + class Container + { + public SupportsAdd S { get; } + public SupportsAddDerived D { get; } + } + + class Program + { + static void Main(string[] args) + { + var y = new Container { $$ }; + } + } + """; // Can't use S={3}, but the object initializer syntax S={} is still valid await VerifyItemExistsAsync(markup, "S"); @@ -746,22 +783,23 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/13158")] public async Task CollectionInitializerForInterfaceType1() { - var markup = @" -using System.Collections.Generic; - -public class Goo -{ - public IList Items { get; } = new List(); - public int Bar; -} - -class Program -{ - static void Main(string[] args) - { - var y = new Goo { $$ }; - } -}"; + var markup = """ + using System.Collections.Generic; + + public class Goo + { + public IList Items { get; } = new List(); + public int Bar; + } + + class Program + { + static void Main(string[] args) + { + var y = new Goo { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "Items"); await VerifyItemExistsAsync(markup, "Bar"); @@ -770,24 +808,25 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/13158")] public async Task CollectionInitializerForInterfaceType2() { - var markup = @" -using System.Collections.Generic; - -public interface ICustomCollection : ICollection { } - -public class Goo -{ - public ICustomCollection Items { get; } = new List(); - public int Bar; -} - -class Program -{ - static void Main(string[] args) - { - var y = new Goo { $$ }; - } -}"; + var markup = """ + using System.Collections.Generic; + + public interface ICustomCollection : ICollection { } + + public class Goo + { + public ICustomCollection Items { get; } = new List(); + public int Bar; + } + + class Program + { + static void Main(string[] args) + { + var y = new Goo { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "Items"); await VerifyItemExistsAsync(markup, "Bar"); @@ -796,37 +835,38 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4754")] public async Task CollectionInitializerPatternFromBaseTypeAccessible() { - var markup = @" -using System; -using System.Collections; - -public class SupportsAdd : IEnumerable -{ - protected void Add(int x) { } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } -} - -class SupportsAddDerived : SupportsAdd -{ -class Container -{ - public SupportsAdd S { get; } - public SupportsAddDerived D { get; } -} - static void Main(string[] args) - { - var y = new Container { $$ }; - } -}"; + var markup = """ + using System; + using System.Collections; + + public class SupportsAdd : IEnumerable + { + protected void Add(int x) { } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + class SupportsAddDerived : SupportsAdd + { + class Container + { + public SupportsAdd S { get; } + public SupportsAddDerived D { get; } + } + static void Main(string[] args) + { + var y = new Container { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "S"); await VerifyItemExistsAsync(markup, "D"); @@ -835,24 +875,25 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4754")] public async Task ObjectInitializerOfGenericTypeConstructedWithInaccessibleType() { - var markup = @" -class Generic -{ - public string Value { get; set; } -} - -class Program -{ - private class InaccessibleToGeneric - { - - } - - static void Main(string[] args) - { - var g = new Generic { $$ } - } -}"; + var markup = """ + class Generic + { + public string Value { get; set; } + } + + class Program + { + private class InaccessibleToGeneric + { + + } + + static void Main(string[] args) + { + var g = new Generic { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "Value"); } @@ -860,24 +901,25 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24612")] public async Task ObjectInitializerOfGenericTypeСonstraint1() { - var markup = @" -internal interface IExample -{ - string A { get; set; } - string B { get; set; } -} - -internal class Example -{ - public static T Create() - where T : IExample, new() - { - return new T - { - $$ - }; - } -}"; + var markup = """ + internal interface IExample + { + string A { get; set; } + string B { get; set; } + } + + internal class Example + { + public static T Create() + where T : IExample, new() + { + return new T + { + $$ + }; + } + } + """; await VerifyItemExistsAsync(markup, "A"); await VerifyItemExistsAsync(markup, "B"); @@ -886,18 +928,19 @@ public static T Create() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24612")] public async Task ObjectInitializerOfGenericTypeСonstraint2() { - var markup = @" -internal class Example -{ - public static T Create() - where T : new() - { - return new T - { - $$ - }; - } -}"; + var markup = """ + internal class Example + { + public static T Create() + where T : new() + { + return new T + { + $$ + }; + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -905,18 +948,19 @@ public static T Create() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24612")] public async Task ObjectInitializerOfGenericTypeСonstraint3() { - var markup = @" -internal class Example -{ - public static T Create() - where T : System.Delegate, new() - { - return new T - { - $$ - }; - } -}"; + var markup = """ + internal class Example + { + public static T Create() + where T : System.Delegate, new() + { + return new T + { + $$ + }; + } + } + """; await VerifyItemExistsAsync(markup, "Target"); await VerifyItemExistsAsync(markup, "Method"); @@ -925,18 +969,19 @@ public static T Create() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24612")] public async Task ObjectInitializerOfGenericTypeСonstraint4() { - var markup = @" -internal class Example -{ - public static T Create() - where T : unmanaged - { - return new T - { - $$ - }; - } -}"; + var markup = """ + internal class Example + { + public static T Create() + where T : unmanaged + { + return new T + { + $$ + }; + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -944,23 +989,24 @@ public static T Create() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26560")] public async Task ObjectInitializerEscapeKeywords() { - var markup = @" -class C -{ - public int @new { get; set; } + var markup = """ + class C + { + public int @new { get; set; } - public int @this { get; set; } + public int @this { get; set; } - public int now { get; set; } -} + public int now { get; set; } + } -class D -{ - static void Main(string[] args) - { - var t = new C() { $$ }; - } -}"; + class D + { + static void Main(string[] args) + { + var t = new C() { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "@new"); await VerifyItemExistsAsync(markup, "@this"); @@ -973,20 +1019,21 @@ static void Main(string[] args) [Fact] public async Task RequiredMembersLabeledAndSelected() { - var markup = @" -class C -{ - public required int RequiredField; - public required int RequiredProperty { get; set; } -} - -class D -{ - static void Main(string[] args) - { - var t = new C() { $$ }; - } -}"; + var markup = """ + class C + { + public required int RequiredField; + public required int RequiredProperty { get; set; } + } + + class D + { + static void Main(string[] args) + { + var t = new C() { $$ }; + } + } + """; await VerifyItemExistsAsync(markup, "RequiredField", inlineDescription: FeaturesResources.Required, matchPriority: MatchPriority.Preselect); await VerifyItemExistsAsync(markup, "RequiredProperty", inlineDescription: FeaturesResources.Required); @@ -995,25 +1042,26 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15205")] public async Task NestedPropertyInitializers1() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public int Prop { get; set; } -} - - -class Program -{ - static void Main(string[] args) - { - var a = new A { $$ } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public int Prop { get; set; } + } + + + class Program + { + static void Main(string[] args) + { + var a = new A { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "PropB"); } @@ -1021,30 +1069,31 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15205")] public async Task NestedPropertyInitializers2() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public C PropC { get; } -} - -class C -{ - public int P { get; set; } -} - - -class Program -{ - static void Main(string[] args) - { - var a = new A { $$ } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public C PropC { get; } + } + + class C + { + public int P { get; set; } + } + + + class Program + { + static void Main(string[] args) + { + var a = new A { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "PropB"); } @@ -1052,44 +1101,45 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15205")] public async Task NestedPropertyInitializers3() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public C PropC { get; } -} - -class C -{ - public SupportsAdd P { get; set; } -} - -public class SupportsAdd : IEnumerable -{ - public void Add(int x) { } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } -} - -class Program -{ - static void Main(string[] args) - { - var a = new A { $$ } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public C PropC { get; } + } + + class C + { + public SupportsAdd P { get; set; } + } + + public class SupportsAdd : IEnumerable + { + public void Add(int x) { } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + class Program + { + static void Main(string[] args) + { + var a = new A { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "PropB"); } @@ -1097,30 +1147,31 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15205")] public async Task NestedPropertyInitializers4() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public C PropC { get; } -} - -class C -{ - public int P; -} - - -class Program -{ - static void Main(string[] args) - { - var a = new A { $$ } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public C PropC { get; } + } + + class C + { + public int P; + } + + + class Program + { + static void Main(string[] args) + { + var a = new A { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "PropB"); } @@ -1128,29 +1179,30 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15205")] public async Task NestedPropertyInitializers5() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public C PropC { get; } -} - -class C -{ - public int P { get; } -} - -class Program -{ - static void Main(string[] args) - { - var a = new A { $$ } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public C PropC { get; } + } + + class C + { + public int P { get; } + } + + class Program + { + static void Main(string[] args) + { + var a = new A { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "PropB"); } @@ -1158,29 +1210,30 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36702")] public async Task NestedPropertyInitializers6() { - var markup = @" -class A -{ - public B PropB { get; } -} - -class B -{ - public C PropC { get; } -} - -class C -{ - public int P { get; } -} - -class Program -{ - static void Main(string[] args) - { - var a = new A { PropB = { $$ } } - } -}"; + var markup = """ + class A + { + public B PropB { get; } + } + + class B + { + public C PropC { get; } + } + + class C + { + public int P { get; } + } + + class Program + { + static void Main(string[] args) + { + var a = new A { PropB = { $$ } } + } + } + """; await VerifyItemExistsAsync(markup, "PropC"); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs index 709e98d5da5c7..ad8d7d2164cab 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs @@ -73,40 +73,40 @@ public static IEnumerable UnaryOperators() public async Task OperatorIsNotOfferedAfterNumberLiteral() { // User may want to type a floating point literal. - await VerifyNoItemsExistAsync(@" -public class C -{ - public static C operator +(C a, C b) => default; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static C operator +(C a, C b) => default; + } -public class Program -{ - public static void Main() - { - 1.$$ - } -} -", SourceCodeKind.Regular); + public class Program + { + public static void Main() + { + 1.$$ + } + } + """, SourceCodeKind.Regular); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorIsSuggestedAfterDot() { - await VerifyItemExistsAsync(@" -public class C -{ - public static C operator +(C a, C b) => default; -} + await VerifyItemExistsAsync(""" + public class C + { + public static C operator +(C a, C b) => default; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$; - } -} -", "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$; + } + } + """, "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -145,84 +145,84 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorIsNotSuggestedOnStaticAccess() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static C operator +(C a, C b) => default; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static C operator +(C a, C b) => default; + } -public class Program -{ - public static void Main() - { - C.$$ - } -} -"); + public class Program + { + public static void Main() + { + C.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorIsNotSuggestedInNameoOfContext() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static C operator +(C a, C b) => default; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static C operator +(C a, C b) => default; + } -public class Program -{ - public static void Main() - { - var c = new C(); - var name = nameof(c.$$ - } -} -"); + public class Program + { + public static void Main() + { + var c = new C(); + var name = nameof(c.$$ + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorsAreSortedByImporttanceAndGroupedByTopic() { - var items = await GetCompletionItemsAsync(@" -public class C -{ - public static C operator +(C a, C b) => null; - public static C operator -(C a, C b) => null; - public static C operator *(C a, C b) => null; - public static C operator /(C a, C b) => null; - public static C operator %(C a, C b) => null; - public static bool operator ==(C a, C b) => true; - public static bool operator !=(C a, C b) => false; - public static bool operator <(C a, C b) => true; - public static bool operator >(C a, C b) => false; - public static bool operator <=(C a, C b) => true; - public static bool operator >=(C a, C b) => false; - public static C operator +(C a) => null; - public static C operator -(C a) => null; - public static C operator ++(C a) => null; - public static C operator --(C a) => null; - public static bool operator true(C w) => true; - public static bool operator false(C w) => false; - public static bool operator &(C a, C b) => true; - public static bool operator |(C a, C b) => true; - public static C operator !(C a) => null; - public static C operator ^(C a, C b) => null; - public static C operator <<(C a, int b) => null; - public static C operator >>(C a, int b) => null; - public static C operator >>>(C a, int b) => null; - public static C operator ~(C a) => null; -} - -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$; - } -} -", SourceCodeKind.Regular); + var items = await GetCompletionItemsAsync(""" + public class C + { + public static C operator +(C a, C b) => null; + public static C operator -(C a, C b) => null; + public static C operator *(C a, C b) => null; + public static C operator /(C a, C b) => null; + public static C operator %(C a, C b) => null; + public static bool operator ==(C a, C b) => true; + public static bool operator !=(C a, C b) => false; + public static bool operator <(C a, C b) => true; + public static bool operator >(C a, C b) => false; + public static bool operator <=(C a, C b) => true; + public static bool operator >=(C a, C b) => false; + public static C operator +(C a) => null; + public static C operator -(C a) => null; + public static C operator ++(C a) => null; + public static C operator --(C a) => null; + public static bool operator true(C w) => true; + public static bool operator false(C w) => false; + public static bool operator &(C a, C b) => true; + public static bool operator |(C a, C b) => true; + public static C operator !(C a) => null; + public static C operator ^(C a, C b) => null; + public static C operator <<(C a, int b) => null; + public static C operator >>(C a, int b) => null; + public static C operator >>>(C a, int b) => null; + public static C operator ~(C a) => null; + } + + public class Program + { + public static void Main() + { + var c = new C(); + c.$$; + } + } + """, SourceCodeKind.Regular); // true and false operators are not listed Assert.Collection(items, i => Assert.Equal("==", i.DisplayText), @@ -308,22 +308,22 @@ public static void Main() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorNoSuggestionForTrueAndFalse() { - await VerifyNoItemsExistAsync(@" -public class C -{ - public static bool operator true(C _) => true; - public static bool operator false(C _) => true; -} + await VerifyNoItemsExistAsync(""" + public class C + { + public static bool operator true(C _) => true; + public static bool operator false(C _) => true; + } -public class Program -{ - public static void Main() - { - var c = new C(); - c.$$ - } -} -"); + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + """); } [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -583,20 +583,21 @@ public static void Main() [MemberData(nameof(UnaryOperators))] public async Task OperatorLiftingUnary(string operatorSign) { - const string template = @" -public struct S -{{ - {0} => default; -}} - -public class Program -{{ - public static void Main() - {{ - S? s = null; - s.$$ - }} -}}"; + const string template = """ + public struct S + {{ + {0} => default; + }} + + public class Program + {{ + public static void Main() + {{ + S? s = null; + s.$$ + }} + }} + """; var inlineDescription = operatorSign.Length == 1 ? $"{operatorSign}x" : $"x{operatorSign}"; @@ -610,20 +611,21 @@ public static void Main() [MemberData(nameof(BinaryArithmeticAndLogicalOperators))] public async Task OperatorLiftingBinary(string operatorSign) { - const string template = @" -public struct S -{{ - {0} => default; -}} - -public class Program -{{ - public static void Main() - {{ - S? s = null; - s.$$ - }} -}}"; + const string template = """ + public struct S + {{ + {0} => default; + }} + + public class Program + {{ + public static void Main() + {{ + S? s = null; + s.$$ + }} + }} + """; var inlineDescription = $"x {operatorSign} y"; await VerifyItemExistsAsync(string.Format(template, $"public static S operator {operatorSign}(S a, S b)"), operatorSign, inlineDescription: inlineDescription); await VerifyItemExistsAsync(string.Format(template, $"public static int operator {operatorSign}(S a, S b)"), operatorSign, inlineDescription: inlineDescription); @@ -636,20 +638,21 @@ public static void Main() [MemberData(nameof(BinaryEqualityAndRelationalOperators))] public async Task OperatorLiftingEqualityRelational(string operatorSign) { - const string template = @" -public struct S -{{ - {0} => default; -}} - -public class Program -{{ - public static void Main() - {{ - S? s = null; - s.$$ - }} -}}"; + const string template = """ + public struct S + {{ + {0} => default; + }} + + public class Program + {{ + public static void Main() + {{ + S? s = null; + s.$$ + }} + }} + """; await VerifyItemExistsAsync(string.Format(template, $"public static bool operator {operatorSign}(S a, S b)"), operatorSign, inlineDescription: $"x {operatorSign} y"); await VerifyNoItemsExistAsync(string.Format(template, $"public static int operator {operatorSign}(S a, S b)")); await VerifyNoItemsExistAsync(string.Format(template, $"public static bool operator {operatorSign}(S a, S b, S c)")); @@ -659,101 +662,105 @@ public static void Main() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorLiftingIsApplied() { - await VerifyCustomCommitProviderAsync(@" -public struct S -{ - public static bool operator ==(S a, S b) => default; -} + await VerifyCustomCommitProviderAsync(""" + public struct S + { + public static bool operator ==(S a, S b) => default; + } -public class Program -{ - public static void Main() - { - S? s = null; - s.$$ - } -}", "==", @" -public struct S -{ - public static bool operator ==(S a, S b) => default; -} + public class Program + { + public static void Main() + { + S? s = null; + s.$$ + } + } + """, "==", """ + public struct S + { + public static bool operator ==(S a, S b) => default; + } -public class Program -{ - public static void Main() - { - S? s = null; - s == $$ - } -}"); + public class Program + { + public static void Main() + { + S? s = null; + s == $$ + } + } + """); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorOfBaseTypeIsSuggested() { - await VerifyItemExistsAsync(@" -public class Base { - public static int operator +(Base b, int a)=>0; -} -public class Derived: Base -{ -} + await VerifyItemExistsAsync(""" + public class Base { + public static int operator +(Base b, int a)=>0; + } + public class Derived: Base + { + } -public class Program -{ - public static void Main() - { - var d = new Derived(); - d.$$ - } -}", "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + public class Program + { + public static void Main() + { + var d = new Derived(); + d.$$ + } + } + """, "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorForRecordsAreSuggested() { - await VerifyItemExistsAsync(@" -public record R { -} + await VerifyItemExistsAsync(""" + public record R { + } -public class Program -{ - public static void Main() - { - var r = new R(); - r.$$ - } -}", "==", inlineDescription: "x == y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); + public class Program + { + public static void Main() + { + var r = new R(); + r.$$ + } + } + """, "==", inlineDescription: "x == y", glyph: (int)Glyph.Operator, matchingFilters: new List { FilterSet.OperatorFilter }); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnOperatorIsRespected_EditorBrowsableStateNever() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Never)] - public static C operator -(C a, C b) => default; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Never)] + public static C operator -(C a, C b) => default; + } + } + """; await VerifyItemInEditorBrowsableContextsAsync( markup: markup, @@ -768,31 +775,31 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task TestEditorBrowsableOnOperatorIsRespected_EditorBrowsableStateAdvanced() { - var markup = @" -namespace N -{ - public class Program - { - public static void Main() - { - var c = new C(); - c.$$ - } - } -} -"; - var referencedCode = @" -using System.ComponentModel; - -namespace N -{ - public class C - { - [EditorBrowsable(EditorBrowsableState.Advanced)] - public static C operator -(C a, C b) => default; - } -} -"; + var markup = """ + namespace N + { + public class Program + { + public static void Main() + { + var c = new C(); + c.$$ + } + } + } + """; + var referencedCode = """ + using System.ComponentModel; + + namespace N + { + public class C + { + [EditorBrowsable(EditorBrowsableState.Advanced)] + public static C operator -(C a, C b) => default; + } + } + """; HideAdvancedMembers = false; @@ -820,39 +827,39 @@ await VerifyItemInEditorBrowsableContextsAsync( [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] public async Task OperatorBinaryNullForgivingHandling() { - await VerifyCustomCommitProviderAsync(@" -#nullable enable - -public class C -{ - public static C operator +(C a, C b) => default; -} + await VerifyCustomCommitProviderAsync(""" + #nullable enable -public class Program -{ - public static void Main() - { - C? c = null; - var _ = c!.$$ - } -} -", "+", @" -#nullable enable + public class C + { + public static C operator +(C a, C b) => default; + } -public class C -{ - public static C operator +(C a, C b) => default; -} + public class Program + { + public static void Main() + { + C? c = null; + var _ = c!.$$ + } + } + """, "+", """ + #nullable enable + + public class C + { + public static C operator +(C a, C b) => default; + } -public class Program -{ - public static void Main() - { - C? c = null; - var _ = c! + $$ - } -} -"); + public class Program + { + public static void Main() + { + C? c = null; + var _ = c! + $$ + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OverrideCompletionProviderTests_ExpressionBody.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OverrideCompletionProviderTests_ExpressionBody.cs index 416d0a52cf12e..8b0b73170a93f 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OverrideCompletionProviderTests_ExpressionBody.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OverrideCompletionProviderTests_ExpressionBody.cs @@ -36,23 +36,27 @@ internal override OptionsCollection NonCompletionOptions [WpfFact] public async Task CommitProducesExpressionBodyProperties() { - var markupBeforeCommit = @"class B -{ - public virtual int A { get; set; } - class C : B - { - override A$$ - } -}"; + var markupBeforeCommit = """ + class B + { + public virtual int A { get; set; } + class C : B + { + override A$$ + } + } + """; - var expectedCodeAfterCommit = @"class B -{ - public virtual int A { get; set; } - class C : B - { - public override int A { get => base.A$$; set => base.A = value; } - } -}"; + var expectedCodeAfterCommit = """ + class B + { + public virtual int A { get; set; } + class C : B + { + public override int A { get => base.A$$; set => base.A = value; } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "A", expectedCodeAfterCommit); } @@ -61,23 +65,27 @@ class C : B [WpfFact] public async Task CommitProducesExpressionBodyGetterOnlyProperty() { - var markupBeforeCommit = @"class B -{ - public virtual int A { get; } - class C : B - { - override A$$ - } -}"; + var markupBeforeCommit = """ + class B + { + public virtual int A { get; } + class C : B + { + override A$$ + } + } + """; - var expectedCodeAfterCommit = @"class B -{ - public virtual int A { get; } - class C : B - { - public override int A => base.A;$$ - } -}"; + var expectedCodeAfterCommit = """ + class B + { + public virtual int A { get; } + class C : B + { + public override int A => base.A;$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "A", expectedCodeAfterCommit); } @@ -86,23 +94,27 @@ class C : B [WpfFact] public async Task CommitProducesExpressionBodyMethod() { - var markupBeforeCommit = @"class B -{ - public virtual int A() => 2; - class C : B - { - override A$$ - } -}"; + var markupBeforeCommit = """ + class B + { + public virtual int A() => 2; + class C : B + { + override A$$ + } + } + """; - var expectedCodeAfterCommit = @"class B -{ - public virtual int A() => 2; - class C : B - { - public override int A() => base.A();$$ - } -}"; + var expectedCodeAfterCommit = """ + class B + { + public virtual int A() => 2; + class C : B + { + public override int A() => base.A();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "A()", expectedCodeAfterCommit); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialMethodCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialMethodCompletionProviderTests.cs index ef46eb1930078..43b9d639c8d20 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialMethodCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialMethodCompletionProviderTests.cs @@ -25,344 +25,402 @@ internal override Type GetCompletionProviderType() [Fact] public async Task NoPartialMethods1() { - var text = @"class c -{ - $$ -}"; + var text = """ + class c + { + $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task NoPartialMethods2() { - var text = @"class c -{ - private void goo() { }; + var text = """ + class c + { + private void goo() { }; - partial void $$ -}"; + partial void $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task NoExtendedPartialMethods2() { - var text = @"class c -{ - public void goo() { }; + var text = """ + class c + { + public void goo() { }; - public void $$ -}"; + public void $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task PartialMethodInPartialClass() { - var text = @"partial class c -{ - partial void goo(); + var text = """ + partial class c + { + partial void goo(); - partial void $$ -}"; + partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task ExtendedPartialMethodInPartialClass() { - var text = @"partial class c -{ - public partial void goo(); + var text = """ + partial class c + { + public partial void goo(); - public partial void $$ -}"; + public partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task PartialMethodInPartialGenericClass() { - var text = @"partial class c -{ - partial void goo(T bar); + var text = """ + partial class c + { + partial void goo(T bar); - partial void $$ -}"; + partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo(T bar)"); } [Fact] public async Task ExtendedPartialMethodInPartialGenericClass() { - var text = @"partial class c -{ - public partial void goo(T bar); + var text = """ + partial class c + { + public partial void goo(T bar); - public partial void $$ -}"; + public partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo(T bar)"); } [Fact] public async Task PartialMethodInPartialStruct() { - var text = @"partial struct c -{ - partial void goo(); + var text = """ + partial struct c + { + partial void goo(); - partial void $$ -}"; + partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task ExtendedPartialMethodInPartialStruct() { - var text = @"partial struct c -{ - public partial void goo(); + var text = """ + partial struct c + { + public partial void goo(); - public partial void $$ -}"; + public partial void $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task CompletionOnPartial1() { - var text = @"partial class c -{ - partial void goo(); + var text = """ + partial class c + { + partial void goo(); - partial $$ -}"; + partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task CompletionOnExtendedPartial1() { - var text = @"partial class c -{ - public partial void goo(); + var text = """ + partial class c + { + public partial void goo(); - partial $$ -}"; + partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task CompletionOnPartial2() { - var text = @"partial class c -{ - partial void goo(); + var text = """ + partial class c + { + partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task CompletionOnExtendedPartial2() { - var text = @"partial class c -{ - public partial void goo(); + var text = """ + partial class c + { + public partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task StaticUnsafePartial() { - var text = @"partial class c -{ - partial static unsafe void goo(); + var text = """ + partial class c + { + partial static unsafe void goo(); - void static unsafe partial $$ -}"; + void static unsafe partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task StaticUnsafeExtendedPartial() { - var text = @"partial class c -{ - public partial static unsafe void goo(); + var text = """ + partial class c + { + public partial static unsafe void goo(); - void static unsafe partial $$ -}"; + void static unsafe partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task PartialCompletionWithPrivate() { - var text = @"partial class c -{ - partial static unsafe void goo(); + var text = """ + partial class c + { + partial static unsafe void goo(); - private partial $$ -}"; + private partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task PartialCompletionWithPublic() { - var text = @"partial class c -{ - public partial static unsafe void goo(); + var text = """ + partial class c + { + public partial static unsafe void goo(); - public partial $$ -}"; + public partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task NotCompletionDespiteValidModifier() { - var text = @"partial class c -{ - partial void goo(); + var text = """ + partial class c + { + partial void goo(); - void partial unsafe $$ -}"; + void partial unsafe $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task NoExtendedCompletionDespiteValidModifier() { - var text = @"partial class c -{ - public partial void goo(); + var text = """ + partial class c + { + public partial void goo(); - void partial unsafe $$ -}"; + void partial unsafe $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task YesIfPublic() { - var text = @"partial class c -{ - public partial void goo(); + var text = """ + partial class c + { + public partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfInternal() { - var text = @"partial class c -{ - internal partial void goo(); + var text = """ + partial class c + { + internal partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfProtected() { - var text = @"partial class c -{ - protected partial void goo(); + var text = """ + partial class c + { + protected partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfProtectedInternal() { - var text = @"partial class c -{ - protected internal partial void goo(); + var text = """ + partial class c + { + protected internal partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfExtern() { - var text = @"partial class c -{ - partial void goo(); + var text = """ + partial class c + { + partial void goo(); - extern void partial $$ -}"; + extern void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfVirtual() { - var text = @"partial class c -{ - virtual partial void goo(); + var text = """ + partial class c + { + virtual partial void goo(); - void partial $$ -}"; + void partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task YesIfNonVoidReturnType() { - var text = @"partial class c -{ - partial int goo(); + var text = """ + partial class c + { + partial int goo(); - partial $$ -}"; + partial $$ + } + """; await VerifyItemExistsAsync(text, "goo()"); } [Fact] public async Task NotInsideInterface() { - var text = @"partial interface i -{ - partial void goo(); + var text = """ + partial interface i + { + partial void goo(); - partial $$ -}"; + partial $$ + } + """; await VerifyNoItemsExistAsync(text); } [WpfFact] public async Task CommitInPartialClass() { - var markupBeforeCommit = @"partial class c -{ - partial void goo(); + var markupBeforeCommit = """ + partial class c + { + partial void goo(); - partial $$ -}"; + partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - partial void goo(); + var expectedCodeAfterCommit = """ + partial class c + { + partial void goo(); - partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -370,22 +428,26 @@ partial void goo() [WpfFact] public async Task CommitInExtendedPartialClass() { - var markupBeforeCommit = @"partial class c -{ - public partial void goo(); + var markupBeforeCommit = """ + partial class c + { + public partial void goo(); - partial $$ -}"; + partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - public partial void goo(); + var expectedCodeAfterCommit = """ + partial class c + { + public partial void goo(); - public partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + public partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -393,22 +455,26 @@ public partial void goo() [WpfFact] public async Task CommitGenericPartialMethod() { - var markupBeforeCommit = @"partial class c -{ - partial void goo(T bar); + var markupBeforeCommit = """ + partial class c + { + partial void goo(T bar); - partial $$ -}"; + partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - partial void goo(T bar); + var expectedCodeAfterCommit = """ + partial class c + { + partial void goo(T bar); - partial void goo(T bar) - { - throw new System.NotImplementedException();$$ - } -}"; + partial void goo(T bar) + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo(T bar)", expectedCodeAfterCommit); } @@ -416,22 +482,26 @@ partial void goo(T bar) [WpfFact] public async Task CommitGenericExtendedPartialMethod() { - var markupBeforeCommit = @"partial class c -{ - public partial void goo(T bar); + var markupBeforeCommit = """ + partial class c + { + public partial void goo(T bar); - partial $$ -}"; + partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - public partial void goo(T bar); + var expectedCodeAfterCommit = """ + partial class c + { + public partial void goo(T bar); - public partial void goo(T bar) - { - throw new System.NotImplementedException();$$ - } -}"; + public partial void goo(T bar) + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo(T bar)", expectedCodeAfterCommit); } @@ -439,22 +509,26 @@ public partial void goo(T bar) [WpfFact] public async Task CommitMethodErasesPrivate() { - var markupBeforeCommit = @"partial class c -{ - partial void goo(); + var markupBeforeCommit = """ + partial class c + { + partial void goo(); - private partial $$ -}"; + private partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - partial void goo(); + var expectedCodeAfterCommit = """ + partial class c + { + partial void goo(); - partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -462,22 +536,26 @@ partial void goo() [WpfFact] public async Task CommitMethodKeepsExtendedPrivate() { - var markupBeforeCommit = @"partial class c -{ - private partial void goo(); + var markupBeforeCommit = """ + partial class c + { + private partial void goo(); - private partial $$ -}"; + private partial $$ + } + """; - var expectedCodeAfterCommit = @"partial class c -{ - private partial void goo(); + var expectedCodeAfterCommit = """ + partial class c + { + private partial void goo(); - private partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + private partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -485,28 +563,32 @@ private partial void goo() [WpfFact] public async Task CommitInPartialClassPart() { - var markupBeforeCommit = @"partial class c -{ - partial void goo(); -} - -partial class c -{ - partial $$ -}"; - - var expectedCodeAfterCommit = @"partial class c -{ - partial void goo(); -} - -partial class c -{ - partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + var markupBeforeCommit = """ + partial class c + { + partial void goo(); + } + + partial class c + { + partial $$ + } + """; + + var expectedCodeAfterCommit = """ + partial class c + { + partial void goo(); + } + + partial class c + { + partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -514,28 +596,32 @@ partial void goo() [WpfFact] public async Task CommitInExtendedPartialClassPart() { - var markupBeforeCommit = @"partial class c -{ - public partial void goo(); -} - -partial class c -{ - partial $$ -}"; - - var expectedCodeAfterCommit = @"partial class c -{ - public partial void goo(); -} - -partial class c -{ - public partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + var markupBeforeCommit = """ + partial class c + { + public partial void goo(); + } + + partial class c + { + partial $$ + } + """; + + var expectedCodeAfterCommit = """ + partial class c + { + public partial void goo(); + } + + partial class c + { + public partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -543,22 +629,26 @@ public partial void goo() [WpfFact] public async Task CommitInPartialStruct() { - var markupBeforeCommit = @"partial struct c -{ - partial void goo(); + var markupBeforeCommit = """ + partial struct c + { + partial void goo(); - partial $$ -}"; + partial $$ + } + """; - var expectedCodeAfterCommit = @"partial struct c -{ - partial void goo(); + var expectedCodeAfterCommit = """ + partial struct c + { + partial void goo(); - partial void goo() - { - throw new System.NotImplementedException();$$ - } -}"; + partial void goo() + { + throw new System.NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "goo()", expectedCodeAfterCommit); } @@ -566,64 +656,68 @@ partial void goo() [Fact] public async Task NotIfNoPartialKeyword() { - var text = @"partial class C - { - partial void Goo(); - } - - partial class C - { - void $$ - } -"; + var text = """ + partial class C + { + partial void Goo(); + } + + partial class C + { + void $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact] public async Task NotIfNoExtendedPartialKeyword() { - var text = @"partial class C - { - public partial void Goo(); - } - - partial class C - { - void $$ - } -"; + var text = """ + partial class C + { + public partial void Goo(); + } + + partial class C + { + void $$ + } + """; await VerifyNoItemsExistAsync(text); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/578757")] public async Task DoNotConsiderFollowingDeclarationPartial() { - var text = @"class Program -{ - partial $$ - - void Goo() - { - - } -} -"; + var text = """ + class Program + { + partial $$ + + void Goo() + { + + } + } + """; await VerifyNoItemsExistAsync(text); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/578757")] public async Task DoNotConsiderFollowingDeclarationExtendedPartial() { - var text = @"class Program -{ - public partial $$ - - void Goo() - { - - } -} -"; + var text = """ + class Program + { + public partial $$ + + void Goo() + { + + } + } + """; await VerifyNoItemsExistAsync(text); } @@ -631,26 +725,30 @@ void Goo() [WpfFact] public async Task CommitAsync() { - var markupBeforeCommit = @"using System; + var markupBeforeCommit = """ + using System; -partial class Bar -{ - partial void Goo(); + partial class Bar + { + partial void Goo(); - async partial $$ -}"; + async partial $$ + } + """; - var expectedCodeAfterCommit = @"using System; + var expectedCodeAfterCommit = """ + using System; -partial class Bar -{ - partial void Goo(); + partial class Bar + { + partial void Goo(); - async partial void Goo() - { - throw new NotImplementedException();$$ - } -}"; + async partial void Goo() + { + throw new NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Goo()", expectedCodeAfterCommit); } @@ -659,26 +757,30 @@ async partial void Goo() [WpfFact] public async Task CommitAsyncExtended() { - var markupBeforeCommit = @"using System; + var markupBeforeCommit = """ + using System; -partial class Bar -{ - public partial void Goo(); + partial class Bar + { + public partial void Goo(); - async partial $$ -}"; + async partial $$ + } + """; - var expectedCodeAfterCommit = @"using System; + var expectedCodeAfterCommit = """ + using System; -partial class Bar -{ - public partial void Goo(); + partial class Bar + { + public partial void Goo(); - public async partial void Goo() - { - throw new NotImplementedException();$$ - } -}"; + public async partial void Goo() + { + throw new NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Goo()", expectedCodeAfterCommit); } @@ -687,26 +789,30 @@ public async partial void Goo() [WpfFact] public async Task AmbiguityCommittingWithParen() { - var markupBeforeCommit = @"using System; + var markupBeforeCommit = """ + using System; -partial class Bar -{ - partial void Goo(); + partial class Bar + { + partial void Goo(); - partial Goo$$ -}"; + partial Goo$$ + } + """; - var expectedCodeAfterCommit = @"using System; + var expectedCodeAfterCommit = """ + using System; -partial class Bar -{ - partial void Goo(); + partial class Bar + { + partial void Goo(); - partial void Goo() - { - throw new NotImplementedException();$$ - } -}"; + partial void Goo() + { + throw new NotImplementedException();$$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Goo()", expectedCodeAfterCommit, commitChar: '('); } @@ -715,30 +821,32 @@ partial void Goo() [WpfFact] public async Task NoDefaultParameterValues() { - var text = @"namespace PartialClass -{ - partial class PClass - { - partial void PMethod(int i = 0); - - partial $$ - } -} -"; - - var expected = @"namespace PartialClass -{ - partial class PClass - { - partial void PMethod(int i = 0); - - partial void PMethod(int i) - { - throw new System.NotImplementedException();$$ - } - } -} -"; + var text = """ + namespace PartialClass + { + partial class PClass + { + partial void PMethod(int i = 0); + + partial $$ + } + } + """; + + var expected = """ + namespace PartialClass + { + partial class PClass + { + partial void PMethod(int i = 0); + + partial void PMethod(int i) + { + throw new System.NotImplementedException();$$ + } + } + } + """; await VerifyCustomCommitProviderAsync(text, "PMethod(int i)", expected); } @@ -746,30 +854,32 @@ partial void PMethod(int i) [WpfFact] public async Task NoDefaultParameterValuesExtended() { - var text = @"namespace PartialClass -{ - partial class PClass - { - public partial void PMethod(int i = 0); - - partial $$ - } -} -"; - - var expected = @"namespace PartialClass -{ - partial class PClass - { - public partial void PMethod(int i = 0); - - public partial void PMethod(int i) - { - throw new System.NotImplementedException();$$ - } - } -} -"; + var text = """ + namespace PartialClass + { + partial class PClass + { + public partial void PMethod(int i = 0); + + partial $$ + } + } + """; + + var expected = """ + namespace PartialClass + { + partial class PClass + { + public partial void PMethod(int i = 0); + + public partial void PMethod(int i) + { + throw new System.NotImplementedException();$$ + } + } + } + """; await VerifyCustomCommitProviderAsync(text, "PMethod(int i)", expected); } @@ -784,22 +894,24 @@ public async Task ExpressionBodyMethod() CSharpCodeStyleOptions.PreferExpressionBodiedMethods, new CodeStyleOption2(ExpressionBodyPreference.WhenPossible, NotificationOption2.Silent)); - var text = @"using System; -partial class Bar -{ - partial void Foo(); - partial $$ -} -" + var text = """ + using System; + partial class Bar + { + partial void Foo(); + partial $$ + } + """ ; - var expected = @"using System; -partial class Bar -{ - partial void Foo(); - partial void Foo() => throw new NotImplementedException();$$ -} -" + var expected = """ + using System; + partial class Bar + { + partial void Foo(); + partial void Foo() => throw new NotImplementedException();$$ + } + """ ; await VerifyCustomCommitProviderAsync(text, "Foo()", expected); @@ -815,22 +927,24 @@ public async Task ExpressionBodyMethodExtended() CSharpCodeStyleOptions.PreferExpressionBodiedMethods, new CodeStyleOption2(ExpressionBodyPreference.WhenPossible, NotificationOption2.Silent)); - var text = @"using System; -partial class Bar -{ - public partial void Foo(); - partial $$ -} -" + var text = """ + using System; + partial class Bar + { + public partial void Foo(); + partial $$ + } + """ ; - var expected = @"using System; -partial class Bar -{ - public partial void Foo(); - public partial void Foo() => throw new NotImplementedException();$$ -} -" + var expected = """ + using System; + partial class Bar + { + public partial void Foo(); + public partial void Foo() => throw new NotImplementedException();$$ + } + """ ; await VerifyCustomCommitProviderAsync(text, "Foo()", expected); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialTypeCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialTypeCompletionProviderTests.cs index d53b6d57b3b2f..3ca1c15869953 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialTypeCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PartialTypeCompletionProviderTests.cs @@ -21,10 +21,11 @@ internal override Type GetCompletionProviderType() [Fact] public async Task TestRecommendTypesWithoutPartial() { - var text = @" -class C { } + var text = """ + class C { } -partial class $$"; + partial class $$ + """; await VerifyItemIsAbsentAsync(text, "C"); } @@ -32,10 +33,11 @@ partial class $$"; [Fact] public async Task TestPartialClass1() { - var text = @" -partial class C { } + var text = """ + partial class C { } -partial class $$"; + partial class $$ + """; await VerifyItemExistsAsync(text, "C"); } @@ -43,12 +45,13 @@ partial class $$"; [Fact] public async Task TestPartialGenericClass1() { - var text = @" -class Bar { } + var text = """ + class Bar { } -partial class C { } + partial class C { } -partial class $$"; + partial class $$ + """; await VerifyItemExistsAsync(text, "C"); } @@ -56,19 +59,21 @@ partial class $$"; [Fact] public async Task TestPartialGenericClassCommitOnParen() { - var text = @" -class Bar { } + var text = """ + class Bar { } -partial class C { } + partial class C { } -partial class $$"; + partial class $$ + """; - var expected = @" -class Bar { } + var expected = """ + class Bar { } -partial class C { } + partial class C { } -partial class C<"; + partial class C< + """; await VerifyProviderCommitAsync(text, "C", expected, '<'); } @@ -76,19 +81,21 @@ partial class C<"; [Fact] public async Task TestPartialGenericClassCommitOnTab() { - var text = @" -class Bar { } + var text = """ + class Bar { } -partial class C { } + partial class C { } -partial class $$"; + partial class $$ + """; - var expected = @" -class Bar { } + var expected = """ + class Bar { } -partial class C { } + partial class C { } -partial class C"; + partial class C + """; await VerifyProviderCommitAsync(text, "C", expected, null); } @@ -96,15 +103,17 @@ partial class C"; [Fact] public async Task TestPartialGenericClassCommitOnSpace() { - var text = @" -partial class C { } + var text = """ + partial class C { } -partial class $$"; + partial class $$ + """; - var expected = @" -partial class C { } + var expected = """ + partial class C { } -partial class C "; + partial class C + """; await VerifyProviderCommitAsync(text, "C", expected, ' '); } @@ -112,10 +121,11 @@ partial class C "; [Fact] public async Task TestPartialClassWithModifiers() { - var text = @" -partial class C { } + var text = """ + partial class C { } -internal partial class $$"; + internal partial class $$ + """; await VerifyItemExistsAsync(text, "C"); } @@ -123,10 +133,11 @@ internal partial class $$"; [Fact] public async Task TestPartialStruct() { - var text = @" -partial struct S { } + var text = """ + partial struct S { } -partial struct $$"; + partial struct $$ + """; await VerifyItemExistsAsync(text, "S"); } @@ -134,10 +145,11 @@ partial struct $$"; [Fact] public async Task TestPartialInterface() { - var text = @" -partial interface I { } + var text = """ + partial interface I { } -partial interface $$"; + partial interface $$ + """; await VerifyItemExistsAsync(text, "I"); } @@ -145,10 +157,11 @@ partial interface $$"; [Fact] public async Task TestTypeKindMatches1() { - var text = @" -partial struct S { } + var text = """ + partial struct S { } -partial class $$"; + partial class $$ + """; await VerifyNoItemsExistAsync(text); } @@ -156,10 +169,11 @@ partial class $$"; [Fact] public async Task TestTypeKindMatches2() { - var text = @" -partial class C { } + var text = """ + partial class C { } -partial struct $$"; + partial struct $$ + """; await VerifyNoItemsExistAsync(text); } @@ -167,16 +181,17 @@ partial struct $$"; [Fact] public async Task TestPartialClassesInSameNamespace() { - var text = @" -namespace N -{ - partial class Goo { } -} - -namespace N -{ - partial class $$ -}"; + var text = """ + namespace N + { + partial class Goo { } + } + + namespace N + { + partial class $$ + } + """; await VerifyItemExistsAsync(text, "Goo"); } @@ -184,13 +199,14 @@ partial class $$ [Fact] public async Task TestNotPartialClassesAcrossDifferentNamespaces() { - var text = @" -namespace N -{ - partial class Goo { } -} + var text = """ + namespace N + { + partial class Goo { } + } -partial class $$"; + partial class $$ + """; await VerifyNoItemsExistAsync(text); } @@ -198,14 +214,14 @@ partial class $$"; [Fact] public async Task TestNotPartialClassesInOuterNamespaces() { - var text = @" -partial class C { } + var text = """ + partial class C { } -namespace N -{ - partial class $$ -} -"; + namespace N + { + partial class $$ + } + """; await VerifyNoItemsExistAsync(text); } @@ -213,12 +229,12 @@ partial class $$ [Fact] public async Task TestNotPartialClassesInOuterClass() { - var text = @" -partial class C -{ - partial class $$ -} -"; + var text = """ + partial class C + { + partial class $$ + } + """; await VerifyNoItemsExistAsync(text); } @@ -226,15 +242,17 @@ partial class $$ [Fact] public async Task TestClassWithConstraint() { - var text = @" -partial class C1 where T : System.Exception { } + var text = """ + partial class C1 where T : System.Exception { } -partial class $$"; + partial class $$ + """; - var expected = @" -partial class C1 where T : System.Exception { } + var expected = """ + partial class C1 where T : System.Exception { } -partial class C1"; + partial class C1 + """; await VerifyProviderCommitAsync(text, "C1", expected, null); } @@ -250,10 +268,11 @@ public async Task TestDoNotSuggestCurrentMember() [Fact] public async Task TestNotInTrivia() { - var text = @" -partial class C1 { } + var text = """ + partial class C1 { } -partial class //$$"; + partial class //$$ + """; await VerifyNoItemsExistAsync(text); } @@ -261,15 +280,17 @@ partial class //$$"; [Fact] public async Task TestPartialClassWithReservedName() { - var text = @" -partial class @class { } + var text = """ + partial class @class { } -partial class $$"; + partial class $$ + """; - var expected = @" -partial class @class { } + var expected = """ + partial class @class { } -partial class @class"; + partial class @class + """; await VerifyProviderCommitAsync(text, "@class", expected, null); } @@ -277,15 +298,17 @@ partial class @class"; [Fact] public async Task TestPartialGenericClassWithReservedName() { - var text = @" -partial class @class { } + var text = """ + partial class @class { } -partial class $$"; + partial class $$ + """; - var expected = @" -partial class @class { } + var expected = """ + partial class @class { } -partial class @class"; + partial class @class + """; await VerifyProviderCommitAsync(text, "@class", expected, null); } @@ -293,15 +316,17 @@ partial class @class"; [Fact] public async Task TestPartialGenericInterfaceWithVariance() { - var text = @" -partial interface I { } + var text = """ + partial interface I { } -partial interface $$"; + partial interface $$ + """; - var expected = @" -partial interface I { } + var expected = """ + partial interface I { } -partial interface I"; + partial interface I + """; await VerifyProviderCommitAsync(text, "I", expected, null); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PropertySubPatternCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PropertySubPatternCompletionProviderTests.cs index c59114d4ea099..f24dd826f4c90 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PropertySubPatternCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/PropertySubPatternCompletionProviderTests.cs @@ -23,18 +23,18 @@ internal override Type GetCompletionProviderType() public async Task PropertiesInRecursivePattern() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } - - void M() - { - _ = this is Program { $$ } - } -} -"; + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } + + void M() + { + _ = this is Program { $$ } + } + } + """; // VerifyItemExistsAsync also tests with the item typed. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); @@ -44,19 +44,19 @@ void M() public async Task PropertiesInRecursivePattern_WithPositional() { var markup = -@" -public class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + public class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is Program (1, 2) { $$ } - } - public void Deconstruct(out int x, out int y) => throw null; -} -"; + void M() + { + _ = this is Program (1, 2) { $$ } + } + public void Deconstruct(out int x, out int y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); } @@ -65,19 +65,19 @@ void M() public async Task PropertiesInRecursivePattern_WithPositional_UsingStaticType() { var markup = -@" -public class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + public class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is (1, 2) { $$ } - } - public void Deconstruct(out int x, out int y) => throw null; -} -"; + void M() + { + _ = this is (1, 2) { $$ } + } + public void Deconstruct(out int x, out int y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); } @@ -86,18 +86,18 @@ void M() public async Task PropertiesInRecursivePattern_WithEscapedKeyword() { var markup = -@" -class Program -{ - public int @new { get; set; } - public int @struct { get; set; } + """ + class Program + { + public int @new { get; set; } + public int @struct { get; set; } - void M() - { - _ = this is Program { $$ } - } -} -"; + void M() + { + _ = this is Program { $$ } + } + } + """; await VerifyItemExistsAsync(markup, "@new", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "@struct", displayTextSuffix: ""); } @@ -106,17 +106,17 @@ void M() public async Task PropertiesInRecursivePattern_WriteOnlyProperties() { var markup = -@" -class Program -{ - public int P1 { set => throw null; } + """ + class Program + { + public int P1 { set => throw null; } - void M() - { - _ = this is Program { $$ } - } -} -"; + void M() + { + _ = this is Program { $$ } + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -124,20 +124,20 @@ void M() public async Task PropertiesInRecursivePattern_WithDerivedType() { var markup = -@" -class Program -{ - void M() - { - _ = this is Derived { $$ } - } -} -class Derived -{ - public int P1 { get; set; } - public int P2 { get; set; } -} -"; + """ + class Program + { + void M() + { + _ = this is Derived { $$ } + } + } + class Derived + { + public int P1 { get; set; } + public int P2 { get; set; } + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); } @@ -146,20 +146,20 @@ class Derived public async Task PropertiesInRecursivePattern_WithOtherType() { var markup = -@" -class Program -{ - void M(Other other) - { - _ = other is Other { $$ } - } -} -class Other -{ - public int P1 { get; set; } - public int F2; -} -"; + """ + class Program + { + void M(Other other) + { + _ = other is Other { $$ } + } + } + class Other + { + public int P1 { get; set; } + public int F2; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "F2", displayTextSuffix: ""); } @@ -168,20 +168,20 @@ class Other public async Task PropertiesInRecursivePattern_WithDerivedType_WithInaccessibleMembers() { var markup = -@" -class Program -{ - void M() - { - _ = this is Derived { $$ } - } -} -class Derived : Program -{ - private int P1 { get; set; } - private int P2 { get; set; } -} -"; + """ + class Program + { + void M() + { + _ = this is Derived { $$ } + } + } + class Derived : Program + { + private int P1 { get; set; } + private int P2 { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -189,20 +189,20 @@ class Derived : Program public async Task PropertiesInRecursivePattern_WithDerivedType_WithPrivateMember() { var markup = -@" -class Program -{ - private int P1 { get; set; } - void M() - { - _ = this is Derived { $$ } - } -} -class Derived : Program -{ - private int P2 { get; set; } -} -"; + """ + class Program + { + private int P1 { get; set; } + void M() + { + _ = this is Derived { $$ } + } + } + class Derived : Program + { + private int P2 { get; set; } + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); } @@ -210,18 +210,18 @@ class Derived : Program public async Task PropertiesInRecursivePattern_UseStaticTypeFromIs() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is { $$ } - } -} -"; + void M() + { + _ = this is { $$ } + } + } + """; // VerifyItemExistsAsync also tests with the item typed. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); @@ -231,21 +231,21 @@ void M() public async Task PropertiesInRecursivePattern_InSwitchStatement() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } - - void M() - { - switch (this) - { - case Program { $$ } - } - } -} -"; + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } + + void M() + { + switch (this) + { + case Program { $$ } + } + } + } + """; // VerifyItemExistsAsync also tests with the item typed. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); @@ -255,21 +255,21 @@ void M() public async Task PropertiesInRecursivePattern_UseStaticTypeFromSwitchStatement() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } - - void M() - { - switch (this) - { - case { $$ } - } - } -} -"; + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } + + void M() + { + switch (this) + { + case { $$ } + } + } + } + """; // VerifyItemExistsAsync also tests with the item typed. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); @@ -279,18 +279,18 @@ void M() public async Task PropertiesInRecursivePattern_InSwitchExpression() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this switch { { $$ } } - } -} -"; + void M() + { + _ = this switch { { $$ } } + } + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); } @@ -299,23 +299,23 @@ void M() public async Task PropertiesInRecursivePattern_NestedInProperty() { var markup = -@" -public class Nested -{ - public int P3 { get; set; } - public int P4 { get; set; } -} -class Program -{ - public int P1 { get; set; } - public Nested P2 { get; set; } - - void M() - { - _ = this is Program { P2: { $$ } } - } -} -"; + """ + public class Nested + { + public int P3 { get; set; } + public int P4 { get; set; } + } + class Program + { + public int P1 { get; set; } + public Nested P2 { get; set; } + + void M() + { + _ = this is Program { P2: { $$ } } + } + } + """; await VerifyItemIsAbsentAsync(markup, "P1"); await VerifyItemIsAbsentAsync(markup, "P2"); await VerifyItemExistsAsync(markup, "P3", displayTextSuffix: ""); @@ -326,23 +326,23 @@ void M() public async Task PropertiesInRecursivePattern_NestedInField() { var markup = -@" -public class Nested -{ - public int P3 { get; set; } - public int P4 { get; set; } -} -class Program -{ - public int P1 { get; set; } - public Nested F2; - - void M() - { - _ = this is Program { F2: { $$ } } - } -} -"; + """ + public class Nested + { + public int P3 { get; set; } + public int P4 { get; set; } + } + class Program + { + public int P1 { get; set; } + public Nested F2; + + void M() + { + _ = this is Program { F2: { $$ } } + } + } + """; await VerifyItemIsAbsentAsync(markup, "P1"); await VerifyItemIsAbsentAsync(markup, "F2"); await VerifyItemExistsAsync(markup, "P3", displayTextSuffix: ""); @@ -353,23 +353,23 @@ void M() public async Task PropertiesInRecursivePattern_Nested_WithFields() { var markup = -@" -public class Nested -{ - public int F3; - public int F4; -} -class Program -{ - public int P1 { get; set; } - public Nested P2 { get; set; } - - void M() - { - _ = this is Program { P2: { $$ } } - } -} -"; + """ + public class Nested + { + public int F3; + public int F4; + } + class Program + { + public int P1 { get; set; } + public Nested P2 { get; set; } + + void M() + { + _ = this is Program { P2: { $$ } } + } + } + """; await VerifyItemIsAbsentAsync(markup, "P1"); await VerifyItemIsAbsentAsync(markup, "P2"); await VerifyItemExistsAsync(markup, "F3", displayTextSuffix: ""); @@ -380,23 +380,23 @@ void M() public async Task PropertiesInRecursivePattern_Nested_WithMissingProperty() { var markup = -@" -public class Nested -{ - public int P3 { get; set; } - public int P4 { get; set; } -} -class Program -{ - public int P1 { get; set; } - public Nested P2 { get; set; } - - void M() - { - _ = this is Program { : { $$ } } - } -} -"; + """ + public class Nested + { + public int P3 { get; set; } + public int P4 { get; set; } + } + class Program + { + public int P1 { get; set; } + public Nested P2 { get; set; } + + void M() + { + _ = this is Program { : { $$ } } + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -404,18 +404,18 @@ void M() public async Task PropertiesInRecursivePattern_NoType() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = missing is { $$ } - } -} -"; + void M() + { + _ = missing is { $$ } + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -423,18 +423,18 @@ void M() public async Task PropertiesInRecursivePattern_MissingAfterColon() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is { P1: $$ } - } -} -"; + void M() + { + _ = this is { P1: $$ } + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -442,18 +442,18 @@ void M() public async Task PropertiesInRecursivePattern_SecondProperty() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is Program { P2: 1, $$ } - } -} -"; + void M() + { + _ = this is Program { P2: 1, $$ } + } + } + """; // VerifyItemExistsAsync also tests with the item typed. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemIsAbsentAsync(markup, "P2"); @@ -463,21 +463,21 @@ void M() public async Task PropertiesInRecursivePattern_PositionalInFirstProperty() { var markup = -@" -class Program -{ - public D P1 { get; set; } - - void M() - { - _ = this is Program { P1: ($$ } - } -} -class D -{ - public int P2 { get; set; } -} -"; + """ + class Program + { + public D P1 { get; set; } + + void M() + { + _ = this is Program { P1: ($$ } + } + } + class D + { + public int P2 { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -485,21 +485,21 @@ class D public async Task PropertiesInRecursivePattern_PositionalInFirstProperty_AfterComma() { var markup = -@" -class Program -{ - public D P1 { get; set; } - - void M() - { - _ = this is Program { P1: (1, $$ } - } -} -class D -{ - public int P2 { get; set; } -} -"; + """ + class Program + { + public D P1 { get; set; } + + void M() + { + _ = this is Program { P1: (1, $$ } + } + } + class D + { + public int P2 { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -507,21 +507,21 @@ class D public async Task PropertiesInRecursivePattern_PositionalInFirstProperty_AfterCommaAndBeforeParen() { var markup = -@" -class Program -{ - public D P1 { get; set; } - - void M() - { - _ = this is Program { P1: (1, $$) } - } -} -class D -{ - public int P2 { get; set; } -} -"; + """ + class Program + { + public D P1 { get; set; } + + void M() + { + _ = this is Program { P1: (1, $$) } + } + } + class D + { + public int P2 { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -529,19 +529,19 @@ class D public async Task PropertiesInRecursivePattern_InPositional_Incomplete() { var markup = -@" -public class Program -{ - public int P1 { get; set; } + """ + public class Program + { + public int P1 { get; set; } - void M() - { - _ = this is ({ $$ }) // Can deconstruct into a parenthesized property pattern - } + void M() + { + _ = this is ({ $$ }) // Can deconstruct into a parenthesized property pattern + } - public void Deconstruct(out Program x, out Program y) => throw null; -} -"; + public void Deconstruct(out Program x, out Program y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); } @@ -549,19 +549,19 @@ void M() public async Task PropertiesInRecursivePattern_InPositional_Incomplete_WithoutClosingBrace() { var markup = -@" -public class Program -{ - public int P1 { get; set; } + """ + public class Program + { + public int P1 { get; set; } - void M() - { - _ = this is ({ $$ // Can deconstruct into a parenthesized property pattern - } + void M() + { + _ = this is ({ $$ // Can deconstruct into a parenthesized property pattern + } - public void Deconstruct(out Program x, out Program y) => throw null; -} -"; + public void Deconstruct(out Program x, out Program y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); } @@ -569,21 +569,21 @@ void M() public async Task PropertiesInRecursivePattern_InPositional_Incomplete_WithTwoTypes() { var markup = -@" -public class Program -{ - void M() - { - _ = this is ({ $$ }) // no deconstruction into 1 element - } - - public void Deconstruct(out D x, out Program y) => throw null; -} -public class D -{ - public int P2 { get; set; } -} -"; + """ + public class Program + { + void M() + { + _ = this is ({ $$ }) // no deconstruction into 1 element + } + + public void Deconstruct(out D x, out Program y) => throw null; + } + public class D + { + public int P2 { get; set; } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -591,19 +591,19 @@ public class D public async Task PropertiesInRecursivePattern_InPositional_Complete_BeforeComma() { var markup = -@" -public class Program -{ - public int P1 { get; set; } + """ + public class Program + { + public int P1 { get; set; } - void M() - { - _ = this is ({ $$ }, ) - } + void M() + { + _ = this is ({ $$ }, ) + } - public void Deconstruct(out Program x, out Program y) => throw null; -} -"; + public void Deconstruct(out Program x, out Program y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); } @@ -611,19 +611,19 @@ void M() public async Task PropertiesInRecursivePattern_InPositional_Complete_AfterComma() { var markup = -@" -public class Program -{ - public int P1 { get; set; } + """ + public class Program + { + public int P1 { get; set; } - void M() - { - _ = this is ( , { $$ }) - } + void M() + { + _ = this is ( , { $$ }) + } - public void Deconstruct(out Program x, out Program y) => throw null; -} -"; + public void Deconstruct(out Program x, out Program y) => throw null; + } + """; await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); } @@ -631,18 +631,18 @@ void M() public async Task PropertiesInRecursivePattern_NoPropertyLeft() { var markup = -@" -class Program -{ - public int P1 { get; set; } - public int P2 { get; set; } + """ + class Program + { + public int P1 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is Program { P2: 1, P1: 2, $$ } - } -} -"; + void M() + { + _ = this is Program { P2: 1, P1: 2, $$ } + } + } + """; await VerifyNoItemsExistAsync(markup); } @@ -650,20 +650,20 @@ void M() public async Task PropertiesInRecursivePattern_NotForEditorUnbrowsable() { var markup = -@" -class Program -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public int P1 { get; set; } + """ + class Program + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public int P1 { get; set; } - public int P2 { get; set; } + public int P2 { get; set; } - void M() - { - _ = this is Program { $$ } - } -} -"; + void M() + { + _ = this is Program { $$ } + } + } + """; // Ignore browsability limiting attributes if the symbol is declared in source. await VerifyItemExistsAsync(markup, "P1", displayTextSuffix: ""); await VerifyItemExistsAsync(markup, "P2", displayTextSuffix: ""); @@ -673,15 +673,15 @@ void M() public async Task StaticProperties_NotSuggested() { var markup = -@" -class Program -{ - void M() - { - _ = """" is { $$ } - } -} -"; + """ + class Program + { + void M() + { + _ = "" is { $$ } + } + } + """; await VerifyItemIsAbsentAsync(markup, "Empty"); } @@ -689,17 +689,17 @@ void M() public async Task StaticFields_NotSuggested() { var markup = -@" -class Program -{ - static int x = 42; + """ + class Program + { + static int x = 42; - void M() - { - _ = this is { $$ } - } -} -"; + void M() + { + _ = this is { $$ } + } + } + """; await VerifyItemIsAbsentAsync(markup, "x"); } @@ -707,15 +707,15 @@ void M() public async Task ConstFields_NotSuggested() { var markup = -@" -class Program -{ - void M() - { - _ = 5 is { $$ } - } -} -"; + """ + class Program + { + void M() + { + _ = 5 is { $$ } + } + } + """; await VerifyItemIsAbsentAsync(markup, "MaxValue"); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs index 29293e5b106d5..73f87b31c4b21 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs @@ -94,7 +94,9 @@ public async Task FileSystemReference() var normalizedWindowsPath = Directory.GetDirectories(windowsRoot, windowsDir.Name).Single(); var windowsFolderName = Path.GetFileName(normalizedWindowsPath); - var code = "#r \"" + windowsRoot + "$$"; + var code = """ + #r " + """ + windowsRoot + "$$"; await VerifyItemExistsAsync(code, windowsFolderName, expectedDescriptionOrNull: null, sourceCodeKind: SourceCodeKind.Script); } @@ -104,11 +106,19 @@ public async Task FileSystemReference() [InlineData("#r$$", false)] [InlineData("#r\"$$", true)] [InlineData(" # r \"$$", true)] - [InlineData(" # r \"$$\"", true)] + [InlineData(""" + # r "$$" + """, true)] [InlineData(" # r \"\"$$", true)] - [InlineData("$$ # r \"\"", false)] - [InlineData(" # $$r \"\"", false)] - [InlineData(" # r $$\"\"", false)] + [InlineData(""" + $$ # r "" + """, false)] + [InlineData(""" + # $$r "" + """, false)] + [InlineData(""" + # r $$"" + """, false)] public void ShouldTriggerCompletion(string textWithPositionMarker, bool expectedResult) { var position = textWithPositionMarker.IndexOf("$$"); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SnippetCompletionProviderTests.cs index 63cd73a85bf1e..12ee1993beb15 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SnippetCompletionProviderTests.cs @@ -87,22 +87,24 @@ public async Task SnippetsInLineSpanDirective() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/968256")] public async Task ShowSnippetsFromOtherContext() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; await VerifyItemInLinkedFilesAsync(markup, MockSnippetInfoService.SnippetShortcut, null); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs index 7c4b9473098fe..04ba1dd426bcb 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs @@ -18,19 +18,23 @@ public class CSharpClassSnippetCompletionProviderTests : AbstractCSharpSnippetCo public async Task InsertClassSnippetInNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace -{ - $$ -}"; + """ + namespace Namespace + { + $$ + } + """; var expectedCodeAfterCommit = -@"namespace Namespace -{ - class MyClass - { - $$ - } -}"; + """ + namespace Namespace + { + class MyClass + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -38,17 +42,21 @@ class MyClass public async Task InsertClassSnippetInFileScopedNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace; + """ + namespace Namespace; -$$"; + $$ + """; var expectedCodeAfterCommit = -@"namespace Namespace; + """ + namespace Namespace; -class MyClass -{ - $$ -}"; + class MyClass + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -59,10 +67,12 @@ public async Task InsertClassSnippetTest() @"$$"; var expectedCodeAfterCommit = -@"class MyClass -{ - $$ -}"; + """ + class MyClass + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -70,15 +80,19 @@ public async Task InsertClassSnippetTest() public async Task InsertClassTopLevelSnippetTest() { var markupBeforeCommit = -@"System.Console.WriteLine(); -$$"; + """ + System.Console.WriteLine(); + $$ + """; var expectedCodeAfterCommit = -@"System.Console.WriteLine(); -class MyClass -{ - $$ -}"; + """ + System.Console.WriteLine(); + class MyClass + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -86,19 +100,23 @@ class MyClass public async Task InsertClassSnippetInClassTest() { var markupBeforeCommit = -@"class MyClass -{ - $$ -}"; + """ + class MyClass + { + $$ + } + """; var expectedCodeAfterCommit = -@"class MyClass -{ - class MyClass1 - { - $$ - } -}"; + """ + class MyClass + { + class MyClass1 + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -106,19 +124,23 @@ class MyClass1 public async Task InsertClassSnippetInRecordTest() { var markupBeforeCommit = -@"record MyRecord -{ - $$ -}"; + """ + record MyRecord + { + $$ + } + """; var expectedCodeAfterCommit = -@"record MyRecord -{ - class MyClass - { - $$ - } -}"; + """ + record MyRecord + { + class MyClass + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -126,19 +148,23 @@ class MyClass public async Task InsertClassSnippetInStructTest() { var markupBeforeCommit = -@"struct MyStruct -{ - $$ -}"; + """ + struct MyStruct + { + $$ + } + """; var expectedCodeAfterCommit = -@"struct MyStruct -{ - class MyClass - { - $$ - } -}"; + """ + struct MyStruct + { + class MyClass + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -146,19 +172,23 @@ class MyClass public async Task InsertClassSnippetInInterfaceTest() { var markupBeforeCommit = -@"interface MyInterface -{ - $$ -}"; + """ + interface MyInterface + { + $$ + } + """; var expectedCodeAfterCommit = -@"interface MyInterface -{ - class MyClass - { - $$ - } -}"; + """ + interface MyInterface + { + class MyClass + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -195,10 +225,12 @@ public class MyClass public async Task NoClassSnippetInEnumTest() { var markupBeforeCommit = -@"enum MyEnum -{ - $$ -}"; + """ + enum MyEnum + { + $$ + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -207,13 +239,15 @@ public async Task NoClassSnippetInEnumTest() public async Task NoClassSnippetInMethodTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - $$ - } -}"; + """ + class Program + { + public void Method() + { + $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -221,13 +255,15 @@ public void Method() public async Task NoClassSnippetInConstructorTest() { var markupBeforeCommit = -@"class Program -{ - public Program() - { - $$ - } -}"; + """ + class Program + { + public Program() + { + $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs index 7a4ffcec2b852..5812fdb407223 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs @@ -20,24 +20,28 @@ public class CSharpConsoleSnippetCompletionProviderTests : AbstractCSharpSnippet public async Task InsertConsoleSnippetInMethodTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - Wr$$ - } -}"; + """ + class Program + { + public void Method() + { + Wr$$ + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public void Method() - { - Console.WriteLine($$); - } -}"; + """ + using System; + + class Program + { + public void Method() + { + Console.WriteLine($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -45,24 +49,28 @@ public void Method() public async Task InsertAsyncConsoleSnippetTest() { var markupBeforeCommit = -@"class Program -{ - public async Task MethodAsync() - { - Wr$$ - } -}"; + """ + class Program + { + public async Task MethodAsync() + { + Wr$$ + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public async Task MethodAsync() - { - await Console.Out.WriteLineAsync($$); - } -}"; + """ + using System; + + class Program + { + public async Task MethodAsync() + { + await Console.Out.WriteLineAsync($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -70,24 +78,28 @@ public async Task MethodAsync() public async Task InsertConsoleSnippetGlobalTest() { var markupBeforeCommit = -@"$$ -class Program -{ - public async Task MethodAsync() - { - } -}"; + """ + $$ + class Program + { + public async Task MethodAsync() + { + } + } + """; var expectedCodeAfterCommit = -@"using System; - -Console.WriteLine($$); -class Program -{ - public async Task MethodAsync() - { - } -}"; + """ + using System; + + Console.WriteLine($$); + class Program + { + public async Task MethodAsync() + { + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -95,17 +107,18 @@ public async Task MethodAsync() public async Task NoConsoleSnippetInBlockNamespaceTest() { var markupBeforeCommit = -@" -namespace Namespace -{ - $$ - class Program - { - public async Task MethodAsync() - { - } - } -}"; + """ + namespace Namespace + { + $$ + class Program + { + public async Task MethodAsync() + { + } + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -113,16 +126,16 @@ public async Task MethodAsync() public async Task NoConsoleSnippetInFileScopedNamespaceTest() { var markupBeforeCommit = -@" -namespace Namespace; -$$ -class Program -{ - public async Task MethodAsync() - { - } -} -"; + """ + namespace Namespace; + $$ + class Program + { + public async Task MethodAsync() + { + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -130,26 +143,30 @@ public async Task MethodAsync() public async Task InsertConsoleSnippetInConstructorTest() { var markupBeforeCommit = -@"class Program -{ - public Program() - { - var x = 5; - $$ - } -}"; + """ + class Program + { + public Program() + { + var x = 5; + $$ + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public Program() - { - var x = 5; - Console.WriteLine($$); - } -}"; + """ + using System; + + class Program + { + public Program() + { + var x = 5; + Console.WriteLine($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -157,32 +174,36 @@ public Program() public async Task InsertConsoleSnippetInLocalFunctionTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + $$ + } + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - Console.WriteLine($$); - } - } -}"; + """ + using System; + + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + Console.WriteLine($$); + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -190,28 +211,32 @@ void LocalMethod() public async Task InsertConsoleSnippetInAnonymousFunctionTest() { var markupBeforeCommit = -@"public delegate void Print(int value); + """ + public delegate void Print(int value); -static void Main(string[] args) -{ - Print print = delegate(int val) { - $$ - }; + static void Main(string[] args) + { + Print print = delegate(int val) { + $$ + }; -}"; + } + """; var expectedCodeAfterCommit = -@"using System; + """ + using System; -public delegate void Print(int value); + public delegate void Print(int value); -static void Main(string[] args) -{ - Print print = delegate(int val) { - Console.WriteLine($$); - }; + static void Main(string[] args) + { + Print print = delegate(int val) { + Console.WriteLine($$); + }; -}"; + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -219,22 +244,24 @@ static void Main(string[] args) public async Task InsertConsoleSnippetInParenthesizedLambdaExpressionTest() { var markupBeforeCommit = -@" -Func testForEquality = (x, y) => -{ - $$ - return x == y; -};"; + """ + Func testForEquality = (x, y) => + { + $$ + return x == y; + }; + """; var expectedCodeAfterCommit = -@" -using System; - -Func testForEquality = (x, y) => -{ - Console.WriteLine($$); - return x == y; -};"; + """ + using System; + + Func testForEquality = (x, y) => + { + Console.WriteLine($$); + return x == y; + }; + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -242,22 +269,24 @@ public async Task InsertConsoleSnippetInParenthesizedLambdaExpressionTest() public async Task NoConsoleSnippetInSwitchExpression() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var operation = 2; - - var result = operation switch - { - $$ - 1 => ""Case 1"", - 2 => ""Case 2"", - 3 => ""Case 3"", - 4 => ""Case 4"", - }; - } -}"; + """ + class Program + { + public void Method() + { + var operation = 2; + + var result = operation switch + { + $$ + 1 => "Case 1", + 2 => "Case 2", + 3 => "Case 3", + 4 => "Case 4", + }; + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -265,13 +294,15 @@ public void Method() public async Task NoConsoleSnippetInSingleLambdaExpression() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - Func f = x => $$; - } -}"; + """ + class Program + { + public void Method() + { + Func f = x => $$; + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -279,13 +310,15 @@ public void Method() public async Task NoConsoleSnippetInStringTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var str = ""$$""; - } -}"; + """ + class Program + { + public void Method() + { + var str = "$$"; + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -294,23 +327,25 @@ public void Method() public async Task NoConsoleSnippetInObjectInitializerTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var str = new Test($$); - } -} - -class Test -{ - private string val; - - public Test(string val) - { - this.val = val; - } -}"; + """ + class Program + { + public void Method() + { + var str = new Test($$); + } + } + + class Test + { + private string val; + + public Test(string val) + { + this.val = val; + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -319,12 +354,14 @@ public Test(string val) public async Task NoConsoleSnippetInParameterListTest() { var markupBeforeCommit = -@"class Program -{ - public void Method(int x, $$) - { - } -}"; + """ + class Program + { + public void Method(int x, $$) + { + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -333,12 +370,14 @@ public void Method(int x, $$) public async Task NoConsoleSnippetInRecordDeclarationTest() { var markupBeforeCommit = -@"public record Person -{ - $$ - public string FirstName { get; init; } = default!; - public string LastName { get; init; } = default!; -};"; + """ + public record Person + { + $$ + public string FirstName { get; init; } = default!; + public string LastName { get; init; } = default!; + }; + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -347,13 +386,15 @@ public async Task NoConsoleSnippetInRecordDeclarationTest() public async Task NoConsoleSnippetInVariableDeclarationTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var x = $$ - } -}"; + """ + class Program + { + public void Method() + { + var x = $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -362,24 +403,28 @@ public void Method() public async Task InsertConsoleSnippetWithInvocationBeforeAndAfterCursorTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - Wr$$Blah - } -}"; + """ + class Program + { + public void Method() + { + Wr$$Blah + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public void Method() - { - Console.WriteLine($$); - } -}"; + """ + using System; + + class Program + { + public void Method() + { + Console.WriteLine($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -387,24 +432,28 @@ public void Method() public async Task InsertConsoleSnippetWithInvocationUnderscoreBeforeAndAfterCursorTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - _Wr$$Blah_ - } -}"; + """ + class Program + { + public void Method() + { + _Wr$$Blah_ + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public void Method() - { - Console.WriteLine($$); - } -}"; + """ + using System; + + class Program + { + public void Method() + { + Console.WriteLine($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -416,28 +465,32 @@ public void Method() public async Task InsertConsoleSnippetWithPropertyNamedConsoleTest() { var markupBeforeCommit = -@"class Program -{ - public int Console { get; set; } - - public void Method() - { - $$ - } -}"; + """ + class Program + { + public int Console { get; set; } + + public void Method() + { + $$ + } + } + """; var expectedCodeAfterCommit = -@"using System; - -class Program -{ - public int Console { get; set; } - - public void Method() - { - Console.WriteLine($$); - } -}"; + """ + using System; + + class Program + { + public int Console { get; set; } + + public void Method() + { + Console.WriteLine($$); + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConstructorSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConstructorSnippetCompletionProviderTests.cs index bc396aef78a07..ac94c251a460a 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConstructorSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConstructorSnippetCompletionProviderTests.cs @@ -22,10 +22,12 @@ public class CSharpConstructorSnippetCompletionProviderTests : AbstractCSharpSni public async Task ConstructorSnippetMissingInNamespace() { var markupBeforeCommit = -@"namespace Namespace -{ - $$ -}"; + """ + namespace Namespace + { + $$ + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -34,9 +36,11 @@ public async Task ConstructorSnippetMissingInNamespace() public async Task ConstructorSnippetMissingInFilescopedNamespace() { var markupBeforeCommit = -@"namespace Namespace; + """ + namespace Namespace; -$$"; + $$ + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -45,8 +49,10 @@ public async Task ConstructorSnippetMissingInFilescopedNamespace() public async Task ConstructorSnippetMissingInTopLevelContext() { var markupBeforeCommit = -@"System.Console.WriteLine(); -$$"; + """ + System.Console.WriteLine(); + $$ + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -55,19 +61,23 @@ public async Task ConstructorSnippetMissingInTopLevelContext() public async Task InsertConstructorSnippetInClassTest() { var markupBeforeCommit = -@"class MyClass -{ - $$ -}"; + """ + class MyClass + { + $$ + } + """; var expectedCodeAfterCommit = -@"class MyClass -{ - public MyClass() - { - $$ - } -}"; + """ + class MyClass + { + public MyClass() + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -75,19 +85,23 @@ public MyClass() public async Task InsertConstructorSnippetInAbstractClassTest() { var markupBeforeCommit = -@"abstract class MyClass -{ - $$ -}"; + """ + abstract class MyClass + { + $$ + } + """; var expectedCodeAfterCommit = -@"abstract class MyClass -{ - public MyClass() - { - $$ - } -}"; + """ + abstract class MyClass + { + public MyClass() + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -95,19 +109,23 @@ public MyClass() public async Task InsertConstructorSnippetInStructTest() { var markupBeforeCommit = -@"struct MyStruct -{ - $$ -}"; + """ + struct MyStruct + { + $$ + } + """; var expectedCodeAfterCommit = -@"struct MyStruct -{ - public MyStruct() - { - $$ - } -}"; + """ + struct MyStruct + { + public MyStruct() + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -115,19 +133,23 @@ public MyStruct() public async Task InsertConstructorSnippetInRecordTest() { var markupBeforeCommit = -@"record MyRecord -{ - $$ -}"; + """ + record MyRecord + { + $$ + } + """; var expectedCodeAfterCommit = -@"record MyRecord -{ - public MyRecord() - { - $$ - } -}"; + """ + record MyRecord + { + public MyRecord() + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -135,10 +157,12 @@ public MyRecord() public async Task ConstructorSnippetMissingInInterface() { var markupBeforeCommit = -@"interface MyInterface -{ - $$ -}"; + """ + interface MyInterface + { + $$ + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -147,25 +171,29 @@ public async Task ConstructorSnippetMissingInInterface() public async Task InsertConstructorSnippetInNestedClassTest() { var markupBeforeCommit = -@"class MyClass -{ - class MyClass1 - { - $$ - } -}"; + """ + class MyClass + { + class MyClass1 + { + $$ + } + } + """; var expectedCodeAfterCommit = -@"class MyClass -{ - class MyClass1 - { - public MyClass1() - { - $$ - } - } -}"; + """ + class MyClass + { + class MyClass1 + { + public MyClass1() + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpElseSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpElseSnippetCompletionProviderTests.cs index 9ccd5a0edac62..bb6f32f9ecb10 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpElseSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpElseSnippetCompletionProviderTests.cs @@ -22,31 +22,35 @@ public class CSharpElseSnippetCompletionProviderTests : AbstractCSharpSnippetCom public async Task InsertElseSnippetInMethodTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - if (true) - { - } - $$ - } -}"; + """ + class Program + { + public void Method() + { + if (true) + { + } + $$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - if (true) - { - } - else - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + if (true) + { + } + else + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -54,13 +58,15 @@ public void Method() public async Task NoElseSnippetInMethodWithoutIfStatementTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - $$ - } -}"; + """ + class Program + { + public void Method() + { + $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -68,31 +74,35 @@ public void Method() public async Task InsertElseSnippetGlobalTest() { var markupBeforeCommit = -@"if (true) -{ -} -$$ -class Program -{ - public async Task MethodAsync() - { - } -}"; + """ + if (true) + { + } + $$ + class Program + { + public async Task MethodAsync() + { + } + } + """; var expectedCodeAfterCommit = -@"if (true) -{ -} -else -{ - $$ -} -class Program -{ - public async Task MethodAsync() - { - } -}"; + """ + if (true) + { + } + else + { + $$ + } + class Program + { + public async Task MethodAsync() + { + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -100,20 +110,21 @@ public async Task MethodAsync() public async Task NoElseSnippetInBlockNamespaceTest() { var markupBeforeCommit = -@" -namespace Namespace -{ - if (true) - { - } - $$ - class Program - { - public async Task MethodAsync() - { - } - } -}"; + """ + namespace Namespace + { + if (true) + { + } + $$ + class Program + { + public async Task MethodAsync() + { + } + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -121,19 +132,19 @@ public async Task MethodAsync() public async Task NoElseSnippetInFileScopedNamespaceTest() { var markupBeforeCommit = -@" -namespace Namespace; -if (true) -{ -} -$$ -class Program -{ - public async Task MethodAsync() - { - } -} -"; + """ + namespace Namespace; + if (true) + { + } + $$ + class Program + { + public async Task MethodAsync() + { + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -141,31 +152,35 @@ public async Task MethodAsync() public async Task InsertElseSnippetInConstructorTest() { var markupBeforeCommit = -@"class Program -{ - public Program() - { - if (true) - { - } - $$ - } -}"; + """ + class Program + { + public Program() + { + if (true) + { + } + $$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public Program() - { - if (true) - { - } - else - { - $$ - } - } -}"; + """ + class Program + { + public Program() + { + if (true) + { + } + else + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -173,41 +188,45 @@ public Program() public async Task InsertElseSnippetInLocalFunctionTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - if (true) - { - - } - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + if (true) + { + + } + $$ + } + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - if (true) - { - - } - else - { - $$ - } - } - } -}"; + """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + if (true) + { + + } + else + { + $$ + } + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -215,27 +234,31 @@ void LocalMethod() public async Task InsertElseSnippetSingleLineIfWithBlockTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - if (true) {} - $$ - } -}"; + """ + class Program + { + public void Method() + { + if (true) {} + $$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - if (true) {} - else - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + if (true) {} + else + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -243,29 +266,33 @@ public void Method() public async Task InsertElseSnippetSingleLineIfTest() { var markupBeforeCommit = -@"using System; -class Program -{ - public void Method() - { - if (true) Console.WriteLine(5); - $$ - } -}"; + """ + using System; + class Program + { + public void Method() + { + if (true) Console.WriteLine(5); + $$ + } + } + """; var expectedCodeAfterCommit = -@"using System; -class Program -{ - public void Method() - { - if (true) Console.WriteLine(5); - else - { - $$ - } - } -}"; + """ + using System; + class Program + { + public void Method() + { + if (true) Console.WriteLine(5); + else + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -273,37 +300,41 @@ public void Method() public async Task InsertElseSnippetNestedIfTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - if (true) - { - if (true) - { - } - } - $$ - } -}"; + """ + class Program + { + public void Method() + { + if (true) + { + if (true) + { + } + } + $$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - if (true) - { - if (true) - { - } - } - else - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + if (true) + { + if (true) + { + } + } + else + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForEachSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForEachSnippetCompletionProviderTests.cs index 21d3795d46c40..566d1c921db95 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForEachSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForEachSnippetCompletionProviderTests.cs @@ -18,25 +18,29 @@ public class CSharpForEachSnippetCompletionProviderTests : AbstractCSharpSnippet public async Task InsertForEachSnippetInMethodTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - Ins$$ - } -}"; + """ + class Program + { + public void Method() + { + Ins$$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - foreach (var item in collection) - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + foreach (var item in collection) + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -44,27 +48,31 @@ public void Method() public async Task InsertForEachSnippetInMethodItemUsedTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var item = 5; - Ins$$ - } -}"; + """ + class Program + { + public void Method() + { + var item = 5; + Ins$$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - var item = 5; - foreach (var item1 in collection) - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + var item = 5; + foreach (var item1 in collection) + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -72,15 +80,17 @@ public void Method() public async Task InsertForEachSnippetInGlobalContextTest() { var markupBeforeCommit = -@"Ins$$ -"; + """ + Ins$$ + """; var expectedCodeAfterCommit = -@"foreach (var item in collection) -{ - $$ -} -"; + """ + foreach (var item in collection) + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -88,25 +98,29 @@ public async Task InsertForEachSnippetInGlobalContextTest() public async Task InsertForEachSnippetInConstructorTest() { var markupBeforeCommit = -@"class Program -{ - public Program() - { - $$ - } -}"; + """ + class Program + { + public Program() + { + $$ + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public Program() - { - foreach (var item in collection) - { - $$ - } - } -}"; + """ + class Program + { + public Program() + { + foreach (var item in collection) + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -114,33 +128,37 @@ public Program() public async Task InsertForEachSnippetWithCollectionTest() { var markupBeforeCommit = -@"using System; -using System.Collections.Generic; + """ + using System; + using System.Collections.Generic; -class Program -{ - public Program() - { - var list = new List { 1, 2, 3 }; - $$ - } -}"; + class Program + { + public Program() + { + var list = new List { 1, 2, 3 }; + $$ + } + } + """; var expectedCodeAfterCommit = -@"using System; -using System.Collections.Generic; + """ + using System; + using System.Collections.Generic; -class Program -{ - public Program() - { - var list = new List { 1, 2, 3 }; - foreach (var item in list) - { - $$ - } - } -}"; + class Program + { + public Program() + { + var list = new List { 1, 2, 3 }; + foreach (var item in list) + { + $$ + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -148,33 +166,37 @@ public Program() public async Task InsertForEachSnippetInLocalFunctionTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - $$ - } - } -}"; + """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + $$ + } + } + } + """; var expectedCodeAfterCommit = -@"class Program -{ - public void Method() - { - var x = 5; - void LocalMethod() - { - foreach (var item in collection) - { - $$ - } - } - } -}"; + """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + foreach (var item in collection) + { + $$ + } + } + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -182,25 +204,29 @@ void LocalMethod() public async Task InsertForEachSnippetInAnonymousFunctionTest() { var markupBeforeCommit = -@"public delegate void Print(int value); -static void Main(string[] args) -{ - Print print = delegate(int val) { - $$ - }; -}"; + """ + public delegate void Print(int value); + static void Main(string[] args) + { + Print print = delegate(int val) { + $$ + }; + } + """; var expectedCodeAfterCommit = -@"public delegate void Print(int value); -static void Main(string[] args) -{ - Print print = delegate(int val) { - foreach (var item in args) - { - $$ - } - }; -}"; + """ + public delegate void Print(int value); + static void Main(string[] args) + { + Print print = delegate(int val) { + foreach (var item in args) + { + $$ + } + }; + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -208,21 +234,25 @@ static void Main(string[] args) public async Task InsertForEachSnippetInParenthesizedLambdaExpressionRegularTest() { var markupBeforeCommit = -@"Func testForEquality = (x, y) => -{ - $$ - return x == y; -};"; + """ + Func testForEquality = (x, y) => + { + $$ + return x == y; + }; + """; var expectedCodeAfterCommit = -@"Func testForEquality = (x, y) => -{ - foreach (var item in args) - { - $$ - } - return x == y; -};"; + """ + Func testForEquality = (x, y) => + { + foreach (var item in args) + { + $$ + } + return x == y; + }; + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit, sourceCodeKind: SourceCodeKind.Regular); } @@ -230,21 +260,25 @@ public async Task InsertForEachSnippetInParenthesizedLambdaExpressionRegularTest public async Task InsertForEachSnippetInParenthesizedLambdaExpressionScriptTest() { var markupBeforeCommit = -@"Func testForEquality = (x, y) => -{ - $$ - return x == y; -};"; + """ + Func testForEquality = (x, y) => + { + $$ + return x == y; + }; + """; var expectedCodeAfterCommit = -@"Func testForEquality = (x, y) => -{ - foreach (var item in collection) - { - $$ - } - return x == y; -};"; + """ + Func testForEquality = (x, y) => + { + foreach (var item in collection) + { + $$ + } + return x == y; + }; + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit, sourceCodeKind: SourceCodeKind.Script); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpInterfaceSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpInterfaceSnippetCompletionProviderTests.cs index 8d0cba468dfed..1d363788bef50 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpInterfaceSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpInterfaceSnippetCompletionProviderTests.cs @@ -18,19 +18,23 @@ public class CSharpInterfaceSnippetCompletionProviderTests : AbstractCSharpSnipp public async Task InsertInterfaceSnippetInNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace -{ - $$ -}"; + """ + namespace Namespace + { + $$ + } + """; var expectedCodeAfterCommit = -@"namespace Namespace -{ - interface MyInterface - { - $$ - } -}"; + """ + namespace Namespace + { + interface MyInterface + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -38,17 +42,21 @@ interface MyInterface public async Task InsertInterfaceSnippetInFileScopedNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace; + """ + namespace Namespace; -$$"; + $$ + """; var expectedCodeAfterCommit = -@"namespace Namespace; + """ + namespace Namespace; -interface MyInterface -{ - $$ -}"; + interface MyInterface + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -59,10 +67,12 @@ public async Task InsertInterfaceSnippetTest() @"$$"; var expectedCodeAfterCommit = -@"interface MyInterface -{ - $$ -}"; + """ + interface MyInterface + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -70,15 +80,19 @@ public async Task InsertInterfaceSnippetTest() public async Task InsertInterfaceTopLevelSnippetTest() { var markupBeforeCommit = -@"System.Console.WriteLine(); -$$"; + """ + System.Console.WriteLine(); + $$ + """; var expectedCodeAfterCommit = -@"System.Console.WriteLine(); -interface MyInterface -{ - $$ -}"; + """ + System.Console.WriteLine(); + interface MyInterface + { + $$ + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -86,19 +100,23 @@ interface MyInterface public async Task InsertInterfaceSnippetInClassTest() { var markupBeforeCommit = -@"class MyClass -{ - $$ -}"; + """ + class MyClass + { + $$ + } + """; var expectedCodeAfterCommit = -@"class MyClass -{ - interface MyInterface - { - $$ - } -}"; + """ + class MyClass + { + interface MyInterface + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -106,19 +124,23 @@ interface MyInterface public async Task InsertInterfaceSnippetInRecordTest() { var markupBeforeCommit = -@"record MyRecord -{ - $$ -}"; + """ + record MyRecord + { + $$ + } + """; var expectedCodeAfterCommit = -@"record MyRecord -{ - interface MyInterface - { - $$ - } -}"; + """ + record MyRecord + { + interface MyInterface + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -126,19 +148,23 @@ interface MyInterface public async Task InsertInterfaceSnippetInStructTest() { var markupBeforeCommit = -@"struct MyStruct -{ - $$ -}"; + """ + struct MyStruct + { + $$ + } + """; var expectedCodeAfterCommit = -@"struct MyStruct -{ - interface MyInterface - { - $$ - } -}"; + """ + struct MyStruct + { + interface MyInterface + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -146,19 +172,23 @@ interface MyInterface public async Task InsertInterfaceSnippetInInterfaceTest() { var markupBeforeCommit = -@"interface MyInterface -{ - $$ -}"; + """ + interface MyInterface + { + $$ + } + """; var expectedCodeAfterCommit = -@"interface MyInterface -{ - interface MyInterface1 - { - $$ - } -}"; + """ + interface MyInterface + { + interface MyInterface1 + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -195,10 +225,12 @@ public interface MyInterface public async Task NoInterfaceSnippetInEnumTest() { var markupBeforeCommit = -@"enum MyEnum -{ - $$ -}"; + """ + enum MyEnum + { + $$ + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -207,13 +239,15 @@ public async Task NoInterfaceSnippetInEnumTest() public async Task NoInteraceSnippetInMethodTest() { var markupBeforeCommit = -@"class Program -{ - public void Method() - { - $$ - } -}"; + """ + class Program + { + public void Method() + { + $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -221,13 +255,15 @@ public void Method() public async Task NoInterfaceSnippetInConstructorTest() { var markupBeforeCommit = -@"class Program -{ - public Program() - { - $$ - } -}"; + """ + class Program + { + public Program() + { + $$ + } + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpStructSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpStructSnippetCompletionProviderTests.cs index 93a2f5eeb8e4a..a859ccaf6a487 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpStructSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpStructSnippetCompletionProviderTests.cs @@ -18,19 +18,23 @@ public class CSharpStructSnippetCompletionProviderTests : AbstractCSharpSnippetC public async Task InsertStructSnippetInNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace -{ - $$ -}"; + """ + namespace Namespace + { + $$ + } + """; var expectedCodeAfterCommit = -@"namespace Namespace -{ - struct MyStruct - { - $$ - } -}"; + """ + namespace Namespace + { + struct MyStruct + { + $$ + } + } + """; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -38,17 +42,21 @@ struct MyStruct public async Task InsertStructSnippetInFileScopedNamespaceTest() { var markupBeforeCommit = -@"namespace Namespace; + """ + namespace Namespace; -$$"; + $$ + """; var expectedCodeAfterCommit = -@"namespace Namespace; + """ + namespace Namespace; -struct MyStruct -{ - $$ -}" + struct MyStruct + { + $$ + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -60,10 +68,12 @@ public async Task InsertStructSnippetTest() @"$$"; var expectedCodeAfterCommit = -@"struct MyStruct -{ - $$ -}" + """ + struct MyStruct + { + $$ + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -72,15 +82,19 @@ public async Task InsertStructSnippetTest() public async Task InsertStructTopLevelSnippetTest() { var markupBeforeCommit = -@"System.Console.WriteLine(); -$$"; + """ + System.Console.WriteLine(); + $$ + """; var expectedCodeAfterCommit = -@"System.Console.WriteLine(); -struct MyStruct -{ - $$ -}" + """ + System.Console.WriteLine(); + struct MyStruct + { + $$ + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -89,20 +103,24 @@ struct MyStruct public async Task InsertStructSnippetInClassTest() { var markupBeforeCommit = -@"struct MyClass -{ - $$ -}" + """ + struct MyClass + { + $$ + } + """ ; var expectedCodeAfterCommit = -@"struct MyClass -{ - struct MyStruct - { - $$ - } -}" + """ + struct MyClass + { + struct MyStruct + { + $$ + } + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -111,19 +129,23 @@ struct MyStruct public async Task InsertStructSnippetInRecordTest() { var markupBeforeCommit = -@"record MyRecord -{ - $$ -}"; + """ + record MyRecord + { + $$ + } + """; var expectedCodeAfterCommit = -@"record MyRecord -{ - struct MyStruct - { - $$ - } -}" + """ + record MyRecord + { + struct MyStruct + { + $$ + } + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -132,19 +154,23 @@ struct MyStruct public async Task InsertStructSnippetInStructTest() { var markupBeforeCommit = -@"struct MyStruct -{ - $$ -}"; + """ + struct MyStruct + { + $$ + } + """; var expectedCodeAfterCommit = -@"struct MyStruct -{ - struct MyStruct1 - { - $$ - } -}" + """ + struct MyStruct + { + struct MyStruct1 + { + $$ + } + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -153,19 +179,23 @@ struct MyStruct1 public async Task InsertStructSnippetInInterfaceTest() { var markupBeforeCommit = -@"interface MyInterface -{ - $$ -}"; + """ + interface MyInterface + { + $$ + } + """; var expectedCodeAfterCommit = -@"interface MyInterface -{ - struct MyStruct - { - $$ - } -}" + """ + interface MyInterface + { + struct MyStruct + { + $$ + } + } + """ ; await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); } @@ -204,10 +234,12 @@ public struct MyStruct public async Task NoStructSnippetInEnumTest() { var markupBeforeCommit = -@"enum MyEnum -{ - $$ -}"; + """ + enum MyEnum + { + $$ + } + """; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -216,13 +248,15 @@ public async Task NoStructSnippetInEnumTest() public async Task NoStructSnippetInMethodTest() { var markupBeforeCommit = -@"struct Program -{ - public void Method() - { - $$ - } -}" + """ + struct Program + { + public void Method() + { + $$ + } + } + """ ; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } @@ -231,13 +265,15 @@ public void Method() public async Task NoStructSnippetInConstructorTest() { var markupBeforeCommit = -@"struct Program -{ - public Program() - { - $$ - } -}" + """ + struct Program + { + public Program() + { + $$ + } + } + """ ; await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SpeculativeTCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SpeculativeTCompletionProviderTests.cs index 15346aaa67a8b..42fe1c0e06ed3 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SpeculativeTCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SpeculativeTCompletionProviderTests.cs @@ -23,11 +23,12 @@ internal override Type GetCompletionProviderType() [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task IsCommitCharacterTest() { - const string markup = @" -class C -{ - $$ -}"; + const string markup = """ + class C + { + $$ + } + """; await VerifyCommonCommitCharactersAsync(markup, textTypedSoFar: ""); } @@ -39,11 +40,12 @@ public void IsTextualTriggerCharacterTest() [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task SendEnterThroughToEditorTest() { - const string markup = @" -class C -{ - $$ -}"; + const string markup = """ + class C + { + $$ + } + """; await VerifySendEnterThroughToEnterAsync(markup, "T", sendThroughEnterOption: EnterKeyRule.Never, expected: false); await VerifySendEnterThroughToEnterAsync(markup, "T", sendThroughEnterOption: EnterKeyRule.AfterFullyTypedWord, expected: true); @@ -53,11 +55,12 @@ class C [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task InClass() { - var markup = @" -class C -{ - $$ -}"; + var markup = """ + class C + { + $$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -65,11 +68,12 @@ class C [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task InInterface() { - var markup = @" -interface I -{ - $$ -}"; + var markup = """ + interface I + { + $$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -77,11 +81,12 @@ interface I [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task InStruct() { - var markup = @" -struct S -{ - $$ -}"; + var markup = """ + struct S + { + $$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -89,11 +94,12 @@ struct S [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task NotInNamespace() { - var markup = @" -namespace N -{ - $$ -}"; + var markup = """ + namespace N + { + $$ + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -101,11 +107,12 @@ namespace N [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task NotInEnum() { - var markup = @" -enum E -{ - $$ -}"; + var markup = """ + enum E + { + $$ + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -113,11 +120,12 @@ enum E [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task AfterDelegate() { - var markup = @" -class C -{ - delegate $$ -}"; + var markup = """ + class C + { + delegate $$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -125,11 +133,12 @@ class C [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task NotAfterVoid() { - var markup = @" -class C -{ - void $$ -}"; + var markup = """ + class C + { + void $$ + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -137,11 +146,12 @@ class C [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task NotAfterInt() { - var markup = @" -class C -{ - int $$ -}"; + var markup = """ + class C + { + int $$ + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -149,12 +159,13 @@ class C [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task InGeneric() { - var markup = @" -using System; -class C -{ - Func<$$ -}"; + var markup = """ + using System; + class C + { + Func<$$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -163,12 +174,13 @@ class C [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRef0() { - var markup = @" -using System; -class C -{ - ref $$ -}"; + var markup = """ + using System; + class C + { + ref $$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -177,12 +189,13 @@ class C [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRef1() { - var markup = @" -using System; -class C -{ - ref T$$ -}"; + var markup = """ + using System; + class C + { + ref T$$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -191,12 +204,13 @@ ref T$$ [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRefGeneric0() { - var markup = @" -using System; -class C -{ - ref Func<$$ -}"; + var markup = """ + using System; + class C + { + ref Func<$$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -205,12 +219,13 @@ ref Func<$$ [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRefGeneric1() { - var markup = @" -using System; -class C -{ - ref Func<$$> -}"; + var markup = """ + using System; + class C + { + ref Func<$$> + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -219,12 +234,13 @@ ref Func<$$> [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRefGeneric2() { - var markup = @" -using System; -class C -{ - ref Func -}"; + var markup = """ + using System; + class C + { + ref Func + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -233,12 +249,13 @@ ref Func [WorkItem("https://github.com/dotnet/roslyn/issues/37224")] public async Task InRefGeneric3() { - var markup = @" -using System; -class C -{ - ref Func - /// $$ - /// - void Goo() { } -}"; + var markup = """ + class C + { + /// + /// $$ + /// + void Goo() { } + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -854,12 +909,13 @@ void Goo() { } [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task AfterAsyncTask() { - var markup = @" -using System.Threading.Tasks; -class Program -{ - async Task<$$ -}"; + var markup = """ + using System.Threading.Tasks; + class Program + { + async Task<$$ + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -867,12 +923,13 @@ async Task<$$ [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task NotOkAfterAsync() { - var markup = @" -using System.Threading.Tasks; -class Program -{ - async $$ -}"; + var markup = """ + using System.Threading.Tasks; + class Program + { + async $$ + } + """; await VerifyItemIsAbsentAsync(markup, "T"); } @@ -881,28 +938,30 @@ class Program [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/968256")] public async Task UnionOfItemsFromBothContexts() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; await VerifyItemInLinkedFilesAsync(markup, "T", null); } @@ -910,12 +969,13 @@ void goo() { [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1020654")] public async Task AfterAsyncTaskWithBraceCompletion() { - var markup = @" -using System.Threading.Tasks; -class Program -{ - async Task<$$> -}"; + var markup = """ + using System.Threading.Tasks; + class Program + { + async Task<$$> + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -924,14 +984,15 @@ async Task<$$> [CompilerTrait(CompilerFeature.LocalFunctions)] public async Task LocalFunctionReturnType() { - var markup = @" -class C -{ - public void M() - { - $$ - } -}"; + var markup = """ + class C + { + public void M() + { + $$ + } + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -939,14 +1000,15 @@ public void M() [CompilerTrait(CompilerFeature.LocalFunctions)] public async Task LocalFunctionAfterAyncTask() { - var markup = @" -class C -{ - public void M() - { - async Task<$$> - } -}"; + var markup = """ + class C + { + public void M() + { + async Task<$$> + } + } + """; await VerifyItemExistsAsync(markup, "T"); } @@ -954,14 +1016,15 @@ async Task<$$> [CompilerTrait(CompilerFeature.LocalFunctions)] public async Task LocalFunctionAfterAsync() { - var markup = @" -class C -{ - public void M() - { - async $$ - } -}"; + var markup = """ + class C + { + public void M() + { + async $$ + } + } + """; await VerifyItemExistsAsync(markup, "T"); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs index 5331f2eb9f0c0..953fb54360dc9 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs @@ -39,16 +39,17 @@ public async Task AfterFirstImplicitArgument() [Fact] public async Task AfterFirstImplicitArgumentInMethodCall() { - var markup = @"class c -{ - private void bar(Func f) { } - - private void goo() - { - bar((x, i $$ - } -} -"; + var markup = """ + class c + { + private void bar(Func f) { } + + private void goo() + { + bar((x, i $$ + } + } + """; // The right-hand-side parses like a possible deconstruction or tuple type await VerifyBuilderAsync(markup); } @@ -56,16 +57,17 @@ private void goo() [Fact] public async Task AfterFirstExplicitArgumentInMethodCall() { - var markup = @"class c -{ - private void bar(Func f) { } - - private void goo() - { - bar((int x, i $$ - } -} -"; + var markup = """ + class c + { + private void bar(Func f) { } + + private void goo() + { + bar((int x, i $$ + } + } + """; // Could be a deconstruction expression await VerifyBuilderAsync(markup); } @@ -73,18 +75,19 @@ private void goo() [Fact] public async Task DelegateTypeExpected1() { - var markup = @"using System; + var markup = """ + using System; -class c -{ - private void bar(Func f) { } - - private void goo() - { - bar($$ - } -} -"; + class c + { + private void bar(Func f) { } + + private void goo() + { + bar($$ + } + } + """; await VerifyBuilderAsync(markup); } @@ -95,586 +98,659 @@ public async Task DelegateTypeExpected2() [Fact] public async Task ObjectInitializerDelegateType() { - var markup = @"using System; -using System.Collections.Generic; -using System.Linq; + var markup = """ + using System; + using System.Collections.Generic; + using System.Linq; -class Program -{ - public Func myfunc { get; set; } -} + class Program + { + public Func myfunc { get; set; } + } -class a -{ - void goo() - { - var b = new Program() { myfunc = $$ - } -}"; + class a + { + void goo() + { + var b = new Program() { myfunc = $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/817145")] public async Task ExplicitArrayInitializer() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - Func[] myfunc = new Func[] { $$; - } -}"; + class a + { + void goo() + { + Func[] myfunc = new Func[] { $$; + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task ImplicitArrayInitializerUnknownType() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - var a = new [] { $$; - } -}"; + class a + { + void goo() + { + var a = new [] { $$; + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task ImplicitArrayInitializerKnownDelegateType() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - var a = new [] { x => 2 * x, $$ - } -}"; + class a + { + void goo() + { + var a = new [] { x => 2 * x, $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task TernaryOperatorUnknownType() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - var a = true ? $$ - } -}"; + class a + { + void goo() + { + var a = true ? $$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task TernaryOperatorKnownDelegateType1() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - var a = true ? x => x * 2 : $$ - } -}"; + class a + { + void goo() + { + var a = true ? x => x * 2 : $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task TernaryOperatorKnownDelegateType2() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - Func a = true ? $$ - } -}"; + class a + { + void goo() + { + Func a = true ? $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task OverloadTakesADelegate1() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo(int a) { } - void goo(Func a) { } + class a + { + void goo(int a) { } + void goo(Func a) { } - void bar() - { - this.goo($$ - } -}"; + void bar() + { + this.goo($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task OverloadTakesDelegate2() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo(int i, int a) { } - void goo(int i, Func a) { } + class a + { + void goo(int i, int a) { } + void goo(int i, Func a) { } - void bar() - { - this.goo(1, $$ - } -}"; + void bar() + { + this.goo(1, $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task ExplicitCastToDelegate() { - var markup = @"using System; + var markup = """ + using System; -class a -{ + class a + { - void bar() - { - (Func) ($$ - } -}"; + void bar() + { + (Func) ($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/860580")] public async Task ReturnStatement() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - Func bar() - { - return $$ - } -}"; + class a + { + Func bar() + { + return $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task BuilderInAnonymousType1() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - int bar() - { - var q = new {$$ - } -}"; + class a + { + int bar() + { + var q = new {$$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task BuilderInAnonymousType2() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - int bar() - { - var q = new {$$ 1, 2 }; - } -}"; + class a + { + int bar() + { + var q = new {$$ 1, 2 }; + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task BuilderInAnonymousType3() { - var markup = @"using System; -class a -{ - int bar() - { - var q = new {Name = 1, $$ }; - } -}"; + var markup = """ + using System; + class a + { + int bar() + { + var q = new {Name = 1, $$ }; + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task BuilderInFromClause() { - var markup = @"using System; -using System.Linq; + var markup = """ + using System; + using System.Linq; -class a -{ - int bar() - { - var q = from $$ - } -}"; + class a + { + int bar() + { + var q = from $$ + } + } + """; await VerifyBuilderAsync(markup.ToString()); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/823968")] public async Task BuilderInJoinClause() { - var markup = @"using System; -using System.Linq; -using System.Collections.Generic; + var markup = """ + using System; + using System.Linq; + using System.Collections.Generic; -class a -{ - int bar() - { - var list = new List(); - var q = from a in list - join $$ - } -}"; + class a + { + int bar() + { + var list = new List(); + var q = from a in list + join $$ + } + } + """; await VerifyBuilderAsync(markup.ToString()); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544290")] public async Task ParenthesizedLambdaArgument() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - Console.CancelKeyPress += new ConsoleCancelEventHandler((a$$, e) => { }); - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + Console.CancelKeyPress += new ConsoleCancelEventHandler((a$$, e) => { }); + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544379")] public async Task IncompleteParenthesizedLambdaArgument() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - Console.CancelKeyPress += new ConsoleCancelEventHandler((a$$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + Console.CancelKeyPress += new ConsoleCancelEventHandler((a$$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544379")] public async Task IncompleteNestedParenthesizedLambdaArgument() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - Console.CancelKeyPress += new ConsoleCancelEventHandler(((a$$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + Console.CancelKeyPress += new ConsoleCancelEventHandler(((a$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task ParenthesizedExpressionInVarDeclaration() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - var x = (a$$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + var x = (a$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24432")] public async Task TestInObjectCreation() { - var markup = @"using System; -class Program -{ - static void Main() - { - Program x = new P$$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main() + { + Program x = new P$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24432")] public async Task TestInArrayCreation() { - var markup = @"using System; -class Program -{ - static void Main() - { - Program[] x = new $$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main() + { + Program[] x = new $$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24432")] public async Task TestInArrayCreation2() { - var markup = @"using System; -class Program -{ - static void Main() - { - Program[] x = new Pr$$ - } -}"; + var markup = """ + using System; + class Program + { + static void Main() + { + Program[] x = new Pr$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task TupleExpressionInVarDeclaration() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - var x = (a$$, b) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + var x = (a$$, b) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task TupleExpressionInVarDeclaration2() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - var x = (a, b$$) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + var x = (a, b$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task IncompleteLambdaInActionDeclaration() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - System.Action x = (a$$, b) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + System.Action x = (a$$, b) + } + } + """; await VerifyBuilderAsync(markup); } [Fact] public async Task TupleWithNamesInActionDeclaration() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - System.Action x = (a$$, b: b) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + System.Action x = (a$$, b: b) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task TupleWithNamesInActionDeclaration2() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - System.Action x = (a: a, b$$) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + System.Action x = (a: a, b$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact] public async Task TupleWithNamesInVarDeclaration() { - var markup = @"using System; -class Program -{ - static void Main(string[] args) - { - var x = (a: a, b$$) - } -}"; + var markup = """ + using System; + class Program + { + static void Main(string[] args) + { + var x = (a: a, b$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546363")] public async Task BuilderForLinqExpression() { - var markup = @"using System; -using System.Linq.Expressions; - -public class Class -{ - public void Goo(Expression> arg) - { - Goo($$ - } -}"; + var markup = """ + using System; + using System.Linq.Expressions; + + public class Class + { + public void Goo(Expression> arg) + { + Goo($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546363")] public async Task NotInTypeParameter() { - var markup = @"using System; -using System.Linq.Expressions; - -public class Class -{ - public void Goo(Expression> arg) - { - Enumerable.Empty<$$ - } -}"; + var markup = """ + using System; + using System.Linq.Expressions; + + public class Class + { + public void Goo(Expression> arg) + { + Enumerable.Empty<$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/611477")] public async Task ExtensionMethodFaultTolerance() { - var markup = @"using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace Outer -{ - public struct ImmutableArray : IEnumerable - { - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public static class ReadOnlyArrayExtensions - { - public static ImmutableArray Select(this ImmutableArray array, Func selector) - { - throw new NotImplementedException(); - } - } - - namespace Inner - { - class Program - { - static void Main(string[] args) - { - args.Select($$ - } - } - } -} -"; + var markup = """ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + + namespace Outer + { + public struct ImmutableArray : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public static class ReadOnlyArrayExtensions + { + public static ImmutableArray Select(this ImmutableArray array, Func selector) + { + throw new NotImplementedException(); + } + } + + namespace Inner + { + class Program + { + static void Main(string[] args) + { + args.Select($$ + } + } + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/834609")] public async Task LambdaWithAutomaticBraceCompletion() { - var markup = @"using System; -using System; - -public class Class -{ - public void Goo() - { - EventHandler h = (s$$) - } -}"; + var markup = """ + using System; + using System; + + public class Class + { + public void Goo() + { + EventHandler h = (s$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")] public async Task ThisConstructorInitializer() { - var markup = @"using System; -class X -{ - X(Func x) : this($$) { } -}"; + var markup = """ + using System; + class X + { + X(Func x) : this($$) { } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")] public async Task BaseConstructorInitializer() { - var markup = @"using System; -class B -{ - public B(Func x) {} -} + var markup = """ + using System; + class B + { + public B(Func x) {} + } -class D : B -{ - D() : base($$) { } -}"; + class D : B + { + D() : base($$) { } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/887842")] public async Task PreprocessorExpression() { - var markup = @"class C -{ -#if $$ -}"; + var markup = """ + class C + { + #if $$ + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/967254")] public async Task ImplicitArrayInitializerAfterNew() { - var markup = @"using System; + var markup = """ + using System; -class a -{ - void goo() - { - int[] a = new $$; - } -}"; + class a + { + void goo() + { + int[] a = new $$; + } + } + """; await VerifyNotBuilderAsync(markup); } @@ -730,95 +806,102 @@ public async Task PartialInterfaceName() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12818")] public async Task UnwrapParamsArray() { - var markup = @" -using System; -class C { - C(params Action[] a) { - new C($$ - } -}"; + var markup = """ + using System; + class C { + C(params Action[] a) { + new C($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12818")] public async Task DoNotUnwrapRegularArray() { - var markup = @" -using System; -class C { - C(Action[] a) { - new C($$ - } -}"; + var markup = """ + using System; + class C { + C(Action[] a) { + new C($$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47662")] public async Task LambdaExpressionInImplicitObjectCreation() { - var markup = @" -using System; -class C { - C(Action a) { - C c = new($$ - } -}"; + var markup = """ + using System; + class C { + C(Action a) { + C c = new($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15443")] public async Task NotBuilderWhenDelegateInferredRightOfDotInInvocation() { - var markup = @" -class C { - Action a = Task.$$ -}"; + var markup = """ + class C { + Action a = Task.$$ + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/15443")] public async Task NotBuilderInTypeArgument() { - var markup = @" -namespace ConsoleApplication1 -{ - class Program - { - class N { } - static void Main(string[] args) - { - Program.N n = Load() => default(T); - } -}"; + static T Load() => default(T); + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/16176")] public async Task NotBuilderForLambdaAfterNew() { - var markup = @" -class C { - Action a = new $$ -}"; + var markup = """ + class C { + Action a = new $$ + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20937")] public async Task AsyncLambda() { - var markup = @" -using System; -using System.Threading.Tasks; -class Program -{ - public void B(Func> f) { } + var markup = """ + using System; + using System.Threading.Tasks; + class Program + { + public void B(Func> f) { } - void A() - { - B(async($$"; + void A() + { + B(async($$ + """; await VerifyBuilderAsync(markup); } @@ -826,16 +909,17 @@ void A() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20937")] public async Task AsyncLambdaAfterComma() { - var markup = @" -using System; -using System.Threading.Tasks; -class Program -{ - public void B(Func> f) { } + var markup = """ + using System; + using System.Threading.Tasks; + class Program + { + public void B(Func> f) { } - void A() - { - B(async(p1, $$"; + void A() + { + B(async(p1, $$ + """; await VerifyBuilderAsync(markup); } @@ -843,468 +927,482 @@ void A() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod1() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(a$$ - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(a$$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod2() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(a$$) - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(a$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod3() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(($$ - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(($$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod4() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(($$) - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(($$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod5() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(($$)) - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(($$)) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod6() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar((a, $$ - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar((a, $$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithExtensionAndInstanceMethod7() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, Action action) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, Action action) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(async (a$$ - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(async (a$$ + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28586")] public async Task WithNonDelegateExtensionAndInstanceMethod1() { - var markup = @" -using System; + var markup = """ + using System; -public sealed class Goo -{ - public void Bar() - { - } -} + public sealed class Goo + { + public void Bar() + { + } + } -public static class GooExtensions -{ - public static void Bar(this Goo goo, int val) - { - } -} + public static class GooExtensions + { + public static void Bar(this Goo goo, int val) + { + } + } -public static class Repro -{ - public static void ReproMethod(Goo goo) - { - goo.Bar(a$$ - } -} -"; + public static class Repro + { + public static void ReproMethod(Goo goo) + { + goo.Bar(a$$ + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInDeclarationPattern() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is int o$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is int o$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInDeclarationPattern2() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is System.Collections.Generic.List an$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is System.Collections.Generic.List an$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInRecursivePattern() { - var markup = @" -class C -{ - int P { get; } + var markup = """ + class C + { + int P { get; } - void M(C test) - { - if (test is { P: 1 } o$$) - } -}"; + void M(C test) + { + if (test is { P: 1 } o$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInPropertyPattern() { - var markup = @" -class C -{ - int P { get; } + var markup = """ + class C + { + int P { get; } - void M(C test) - { - if (test is { P: int o$$ }) - } -}"; + void M(C test) + { + if (test is { P: int o$$ }) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInAndPattern() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is 1 and int a$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is 1 and int a$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInAndOrPattern() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is (int or 1) and int a$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is (int or 1) and int a$$) + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInSwitchStatement() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - switch (e) - { - case int o$$ - } - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + switch (e) + { + case int o$$ + } + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestInSwitchExpression() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - var result = e switch - { - int o$$ - } - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + var result = e switch + { + int o$$ + } + } + } + """; await VerifyBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInNotPattern_Declaration() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is not int o$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is not int o$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInNotPattern_Declaration2() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is not (1 and int o$$)) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is not (1 and int o$$)) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInNotPattern_Recursive() { - var markup = @" -class C -{ - int P { get; } + var markup = """ + class C + { + int P { get; } - void M(C test) - { - if (test is not { P: 1 } o$$) - } -}"; + void M(C test) + { + if (test is not { P: 1 } o$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInOrPattern() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is 1 or int o$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is 1 or int o$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInAndOrPattern() { - var markup = @" -class C -{ - void M() - { - var e = new object(); - if (e is 1 or int and int o$$) - } -}"; + var markup = """ + class C + { + void M() + { + var e = new object(); + if (e is 1 or int and int o$$) + } + } + """; await VerifyNotBuilderAsync(markup); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42368")] public async Task TestMissingInRecursiveOrPattern() { - var markup = @" -class C -{ - int P { get; } + var markup = """ + class C + { + int P { get; } - void M(C test) - { - if (test is null or { P: 1 } o$$) - } -}"; + void M(C test) + { + if (test is null or { P: 1 } o$$) + } + } + """; await VerifyNotBuilderAsync(markup); } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs index a9f9e60e19873..cde5ede628968 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs @@ -73,8 +73,10 @@ public async Task GlobalStatement1() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] public async Task GlobalStatement2() { - await VerifyItemExistsAsync(@"using System; -Console.$$", @"Beep"); + await VerifyItemExistsAsync(""" + using System; + Console.$$ + """, @"Beep"); } [Fact] @@ -84,70 +86,84 @@ public async Task InvalidLocation3() [Fact] public async Task InvalidLocation4() { - await VerifyItemIsAbsentAsync(@"class C { -#if false -System.Console.$$ -#endif", @"Beep"); + await VerifyItemIsAbsentAsync(""" + class C { + #if false + System.Console.$$ + #endif + """, @"Beep"); } [Fact] public async Task InvalidLocation5() { - await VerifyItemIsAbsentAsync(@"class C { -#if true -System.Console.$$ -#endif", @"Beep"); + await VerifyItemIsAbsentAsync(""" + class C { + #if true + System.Console.$$ + #endif + """, @"Beep"); } [Fact] public async Task InvalidLocation6() { - await VerifyItemIsAbsentAsync(@"using System; + await VerifyItemIsAbsentAsync(""" + using System; -class C { -// Console.$$", @"Beep"); + class C { + // Console.$$ + """, @"Beep"); } [Fact] public async Task InvalidLocation7() { - await VerifyItemIsAbsentAsync(@"using System; + await VerifyItemIsAbsentAsync(""" + using System; -class C { -/* Console.$$ */", @"Beep"); + class C { + /* Console.$$ */ + """, @"Beep"); } [Fact] public async Task InvalidLocation8() { - await VerifyItemIsAbsentAsync(@"using System; + await VerifyItemIsAbsentAsync(""" + using System; -class C { -/// Console.$$", @"Beep"); + class C { + /// Console.$$ + """, @"Beep"); } [Fact] public async Task InvalidLocation9() { - await VerifyItemIsAbsentAsync(@"using System; - -class C { - void Method() - { - /// Console.$$ - } -}", @"Beep"); + await VerifyItemIsAbsentAsync(""" + using System; + + class C { + void Method() + { + /// Console.$$ + } + } + """, @"Beep"); } [Fact] public async Task InvalidLocation10() { - await VerifyItemIsAbsentAsync(@"using System; - -class C { - void Method() - { - /** Console.$$ */", @"Beep"); + await VerifyItemIsAbsentAsync(""" + using System; + + class C { + void Method() + { + /** Console.$$ */ + """, @"Beep"); } [Fact] @@ -161,8 +177,10 @@ public async Task InvalidLocation12() [Fact] public async Task InvalidLocation13() { - var content = @"[Console.$$] -class CL {}"; + var content = """ + [Console.$$] + class CL {} + """; await VerifyItemIsAbsentAsync(AddUsingDirectives("using System;", content), @"Beep"); } @@ -174,10 +192,12 @@ public async Task InvalidLocation14() [Fact] public async Task InvalidLocation15() { - var content = @"class CL { - [Console.$$] - void Method() {} -}"; + var content = """ + class CL { + [Console.$$] + void Method() {} + } + """; await VerifyItemIsAbsentAsync(AddUsingDirectives("using System;", content), @"Beep"); } @@ -188,52 +208,60 @@ public async Task InvalidLocation16() [Fact] public async Task InvalidLocation17() { - await VerifyItemIsAbsentAsync(@"using System; - -class Program { - static void Main(string[] args) - { - string a = ""a$$ - } -}", @"Main"); + await VerifyItemIsAbsentAsync(""" + using System; + + class Program { + static void Main(string[] args) + { + string a = "a$$ + } + } + """, @"Main"); } [Fact] public async Task InvalidLocation18() { - await VerifyItemIsAbsentAsync(@"using System; - -class Program { - static void Main(string[] args) - { - #region - #endregion // a$$ - } -}", @"Main"); + await VerifyItemIsAbsentAsync(""" + using System; + + class Program { + static void Main(string[] args) + { + #region + #endregion // a$$ + } + } + """, @"Main"); } [Fact] public async Task InvalidLocation19() { - await VerifyItemIsAbsentAsync(@"using System; - -class Program { - static void Main(string[] args) - { - //s$$ - } -}", @"SByte"); + await VerifyItemIsAbsentAsync(""" + using System; + + class Program { + static void Main(string[] args) + { + //s$$ + } + } + """, @"SByte"); } [Fact] public async Task InsideMethodBody() { - await VerifyItemExistsAsync(@"using System; - -class C { - void Method() - { - Console.$$", @"Beep"); + await VerifyItemExistsAsync(""" + using System; + + class C { + void Method() + { + Console.$$ + """, @"Beep"); } [Fact] @@ -243,62 +271,72 @@ public async Task UsingDirectiveGlobal() [Fact] public async Task InsideAccessor() { - await VerifyItemExistsAsync(@"using System; - -class C { - string Property - { - get - { - Console.$$", @"Beep"); + await VerifyItemExistsAsync(""" + using System; + + class C { + string Property + { + get + { + Console.$$ + """, @"Beep"); } [Fact] public async Task FieldInitializer() { - await VerifyItemExistsAsync(@"using System; + await VerifyItemExistsAsync(""" + using System; -class C { - int i = Console.$$", @"Beep"); + class C { + int i = Console.$$ + """, @"Beep"); } [Fact] public async Task FieldInitializer2() { - await VerifyItemExistsAsync(@" -class C { - object i = $$", @"System"); + await VerifyItemExistsAsync(""" + class C { + object i = $$ + """, @"System"); } [Fact] public async Task ImportedProperty() { - await VerifyItemExistsAsync(@"using System.Collections.Generic; - -class C { - void Method() - { - new List().$$", @"Capacity"); + await VerifyItemExistsAsync(""" + using System.Collections.Generic; + + class C { + void Method() + { + new List().$$ + """, @"Capacity"); } [Fact] public async Task FieldInitializerWithProperty() { - await VerifyItemExistsAsync(@"using System.Collections.Generic; -class C { - int i = new List().$$", @"Count"); + await VerifyItemExistsAsync(""" + using System.Collections.Generic; + class C { + int i = new List().$$ + """, @"Count"); } [Fact] public async Task StaticMethods() { - await VerifyItemExistsAsync(@"using System; + await VerifyItemExistsAsync(""" + using System; -class C { - private static int Method() {} + class C { + private static int Method() {} - int i = $$ -", @"Method"); + int i = $$ + """, @"Method"); } [Fact] @@ -308,10 +346,11 @@ public async Task EndOfFile() [Fact] public async Task InheritedStaticFields() { - var code = @"class A { public static int X; } -class B : A { public static int Y; } -class C { void M() { B.$$ } } -"; + var code = """ + class A { public static int X; } + class B : A { public static int Y; } + class C { void M() { B.$$ } } + """; await VerifyItemExistsAsync(code, "X"); await VerifyItemExistsAsync(code, "Y"); } @@ -319,15 +358,17 @@ class C { void M() { B.$$ } } [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems?id=209299")] public async Task TestDescriptionWhenDocumentLengthChanges() { - var code = @"using System; - -class C -{ - string Property - { - get - { - Console.$$";//, @"Beep" + var code = """ + using System; + + class C + { + string Property + { + get + { + Console.$$ + """;//, @"Beep" using var workspace = TestWorkspace.CreateCSharp(code); var testDocument = workspace.Documents.Single(); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TupleNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TupleNameCompletionProviderTests.cs index d371bc22c44cf..0489892b38994 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TupleNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TupleNameCompletionProviderTests.cs @@ -21,105 +21,113 @@ public class TupleNameCompletionProviderTests : AbstractCSharpCompletionProvider [Fact] public async Task AfterOpenParen() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = ($$ - } -}", "word", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = ($$ + } + } + """, "word", displayTextSuffix: ":"); } [Fact] public async Task AfterOpenParenWithBraceCompletion() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = ($$) - } -}", "word", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = ($$) + } + } + """, "word", displayTextSuffix: ":"); } [Fact] public async Task AfterOpenParenInTupleExpression() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = ($$, zword: 2 - } -}", "word", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = ($$, zword: 2 + } + } + """, "word", displayTextSuffix: ":"); } [Fact] public async Task AfterOpenParenInTupleExpressionWithBraceCompletion() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = ($$, zword: 2 - } -}", "word", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = ($$, zword: 2 + } + } + """, "word", displayTextSuffix: ":"); } [Fact] public async Task AfterComma() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = (1, $$ - } -}", "zword", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = (1, $$ + } + } + """, "zword", displayTextSuffix: ":"); } [Fact] public async Task AfterCommaWithBraceCompletion() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = (1, $$) - } -}", "zword", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = (1, $$) + } + } + """, "zword", displayTextSuffix: ":"); } [Fact] public async Task InTupleAsArgument() { - await VerifyItemExistsAsync(@" -class Program -{ - static void Main((int word, int zword) args) - { - Main(($$)) - } -}", "word", displayTextSuffix: ":"); + await VerifyItemExistsAsync(""" + class Program + { + static void Main((int word, int zword) args) + { + Main(($$)) + } + } + """, "word", displayTextSuffix: ":"); } [Fact] public async Task MultiplePossibleTuples() { - var markup = @" -class Program -{ - static void Main((int number, int znumber) args) { } - static void Main((string word, int zword) args) { - Main(($$ - } -}"; + var markup = """ + class Program + { + static void Main((int number, int znumber) args) { } + static void Main((string word, int zword) args) { + Main(($$ + } + } + """; await VerifyItemExistsAsync(markup, "word", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "number", displayTextSuffix: ":"); } @@ -127,14 +135,15 @@ static void Main((string word, int zword) args) { [Fact] public async Task MultiplePossibleTuplesAfterComma() { - var markup = @" -class Program -{ - static void Main((int number, int znumber) args) { } - static void Main((string word, int zword) args) { - Main((1, $$ - } -}"; + var markup = """ + class Program + { + static void Main((int number, int znumber) args) { } + static void Main((string word, int zword) args) { + Main((1, $$ + } + } + """; await VerifyItemExistsAsync(markup, "zword", displayTextSuffix: ":"); await VerifyItemExistsAsync(markup, "znumber", displayTextSuffix: ":"); } @@ -142,28 +151,30 @@ static void Main((string word, int zword) args) { [Fact] public async Task AtIndexGreaterThanNumberOfTupleElements() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - (int word, int zword) t = (1, 2, 3, 4, $$ - } -}"; + var markup = """ + class Program + { + static void Main(string[] args) + { + (int word, int zword) t = (1, 2, 3, 4, $$ + } + } + """; await VerifyNoItemsExistAsync(markup); } [Fact] public async Task ConvertCastToTupleExpression() { - var markup = @" -class C -{ - void goo() - { - (int goat, int moat) x = (g$$)1; - } -}"; + var markup = """ + class C + { + void goo() + { + (int goat, int moat) x = (g$$)1; + } + } + """; await VerifyItemExistsAsync(markup, "goat", displayTextSuffix: ":"); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs index ff26c013cd7ae..ab5c51ac79204 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs @@ -76,348 +76,396 @@ await VerifyAtEndOfFile_ItemPartiallyWrittenAsync( [Fact] public async Task AlwaysVisibleAtAnyLevelItems1() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "inheritdoc", "see", "seealso", "![CDATA[", "!--"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "inheritdoc", "see", "seealso", "![CDATA[", "!--"); } [Fact] public async Task AlwaysVisibleAtAnyLevelItems2() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "inheritdoc", "see", "seealso", "![CDATA[", "!--"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "inheritdoc", "see", "seealso", "![CDATA[", "!--"); } [Fact] public async Task AlwaysVisibleNotTopLevelItems1() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "c", "code", "list", "para"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "c", "code", "list", "para"); } [Fact] public async Task AlwaysVisibleNotTopLevelItems2() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "c", "code", "list", "para", "paramref", "typeparamref"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "c", "code", "list", "para", "paramref", "typeparamref"); } [Fact] public async Task AlwaysVisibleTopLevelOnlyItems1() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "exception", "include", "permission"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "exception", "include", "permission"); } [Fact] public async Task AlwaysVisibleTopLevelOnlyItems2() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "exception", "include", "permission"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "exception", "include", "permission"); } [Fact] public async Task TopLevelSingleUseItems1() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "example", "remarks", "summary"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "example", "remarks", "summary"); } [Fact] public async Task TopLevelSingleUseItems2() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - public void bar() { } -}", "example", "remarks", "summary"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + public void bar() { } + } + """, "example", "remarks", "summary"); } [Fact] public async Task TopLevelSingleUseItems3() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - /// - /// - - public void bar() { } -}", "example", "remarks", "summary"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + /// + /// + + public void bar() { } + } + """, "example", "remarks", "summary"); } [Fact] public async Task OnlyInListItems() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - /// - /// - - public void bar() { } -}", "listheader", "item", "term", "description"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + /// + /// + + public void bar() { } + } + """, "listheader", "item", "term", "description"); } [Fact] public async Task OnlyInListItems2() { - await VerifyItemsAbsentAsync(@" -public class goo -{ - /// $$ - - public void bar() { } -}", "listheader", "item", "term", "description"); + await VerifyItemsAbsentAsync(""" + public class goo + { + /// $$ + + public void bar() { } + } + """, "listheader", "item", "term", "description"); } [Fact] public async Task OnlyInListItems3() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// $$ - - public void bar() { } -}", "listheader", "item", "term", "description"); + await VerifyItemsExistAsync(""" + public class goo + { + /// $$ + + public void bar() { } + } + """, "listheader", "item", "term", "description"); } [Fact] public async Task OnlyInListItems4() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// <$$ - - public void bar() { } -}", "listheader", "item", "term", "description"); + await VerifyItemsExistAsync(""" + public class goo + { + /// <$$ + + public void bar() { } + } + """, "listheader", "item", "term", "description"); } [Fact] public async Task ListHeaderItems() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// - /// $$ - /// - /// - /// - - public void bar() { } -}", "term", "description"); + await VerifyItemsExistAsync(""" + public class goo + { + /// + /// $$ + /// + /// + /// + + public void bar() { } + } + """, "term", "description"); } [Fact] public async Task VoidMethodDeclarationItems() { - await VerifyItemIsAbsentAsync(@" -public class goo -{ - - /// $$ - public void bar() { } -}", "returns"); + await VerifyItemIsAbsentAsync(""" + public class goo + { + + /// $$ + public void bar() { } + } + """, "returns"); } [Fact] public async Task MethodReturns() { - await VerifyItemExistsAsync(@" -public class goo -{ - - /// $$ - public int bar() { } -}", "returns"); + await VerifyItemExistsAsync(""" + public class goo + { + + /// $$ + public int bar() { } + } + """, "returns"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task ReadWritePropertyNoReturns() { - await VerifyItemIsAbsentAsync(@" -public class goo -{ - - /// $$ - public int bar { get; set; } -}", "returns"); + await VerifyItemIsAbsentAsync(""" + public class goo + { + + /// $$ + public int bar { get; set; } + } + """, "returns"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task ReadWritePropertyValue() { - await VerifyItemExistsAsync(@" -public class goo -{ - - /// $$ - public int bar { get; set; } -}", "value"); + await VerifyItemExistsAsync(""" + public class goo + { + + /// $$ + public int bar { get; set; } + } + """, "value"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task ReadOnlyPropertyNoReturns() { - await VerifyItemIsAbsentAsync(@" -public class goo -{ - - /// $$ - public int bar { get; } -}", "returns"); + await VerifyItemIsAbsentAsync(""" + public class goo + { + + /// $$ + public int bar { get; } + } + """, "returns"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task ReadOnlyPropertyValue() { - await VerifyItemExistsAsync(@" -public class goo -{ - - /// $$ - public int bar { get; } -}", "value"); + await VerifyItemExistsAsync(""" + public class goo + { + + /// $$ + public int bar { get; } + } + """, "value"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task WriteOnlyPropertyNoReturns() { - await VerifyItemIsAbsentAsync(@" -public class goo -{ - - /// $$ - public int bar { set; } -}", "returns"); + await VerifyItemIsAbsentAsync(""" + public class goo + { + + /// $$ + public int bar { set; } + } + """, "returns"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8627")] public async Task WriteOnlyPropertyValue() { - await VerifyItemExistsAsync(@" -public class goo -{ - - /// $$ - public int bar { set; } -}", "value"); + await VerifyItemExistsAsync(""" + public class goo + { + + /// $$ + public int bar { set; } + } + """, "value"); } [Fact] public async Task MethodParamTypeParam() { - var text = @" -public class goo -{ - - /// $$ - public int bar(TBar green) { } -}"; + var text = """ + public class goo + { + + /// $$ + public int bar(TBar green) { } + } + """; - await VerifyItemsExistAsync(text, "typeparam name=\"TBar\"", "param name=\"green\""); - await VerifyItemsAbsentAsync(text, "typeparam name=\"TGoo\""); + await VerifyItemsExistAsync(text, """ + typeparam name="TBar" + """, """ + param name="green" + """); + await VerifyItemsAbsentAsync(text, """ + typeparam name="TGoo" + """); } [Fact] public async Task IndexerParamTypeParam() { - await VerifyItemsExistAsync(@" -public class goo -{ + await VerifyItemsExistAsync(""" + public class goo + { - /// $$ - public int this[T green] { get { } set { } } -}", "param name=\"green\""); + /// $$ + public int this[T green] { get { } set { } } + } + """, """ + param name="green" + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17872")] public async Task MethodParamRefName() { - var text = @" -public class Outer -{ - public class Inner - { - /// - /// $$ - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + /// $$ + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync( text, - "typeparamref name=\"TOuter\"", - "typeparamref name=\"TInner\"", - "typeparamref name=\"TMethod\"", - "paramref name=\"green\""); + """ + typeparamref name="TOuter" + """, + """ + typeparamref name="TInner" + """, + """ + typeparamref name="TMethod" + """, + """ + paramref name="green" + """); } [Fact] public async Task ClassTypeParamRefName() { - await VerifyItemsExistAsync(@" -/// -/// $$ -/// -public class goo -{ - public int bar(T green) { } -}", "typeparamref name=\"T\""); + await VerifyItemsExistAsync(""" + /// + /// $$ + /// + public class goo + { + public int bar(T green) { } + } + """, """ + typeparamref name="T" + """); } [Fact] public async Task ClassTypeParam() { - await VerifyItemsExistAsync(@" -/// $$ -public class goo -{ - public int bar(T green) { } -}", "typeparam name=\"T\""); + await VerifyItemsExistAsync(""" + /// $$ + public class goo + { + public int bar(T green) { } + } + """, """ + typeparam name="T" + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/638802")] public async Task TagsAfterSameLineClosedTag() { - var text = @"/// -/// $$ -/// -/// -"; + var text = """ + /// + /// $$ + /// + /// + """; await VerifyItemsExistAsync(text, "!--", "![CDATA[", "c", "code", "inheritdoc", "list", "para", "seealso", "see"); } @@ -425,15 +473,16 @@ public async Task TagsAfterSameLineClosedTag() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/734825")] public async Task EnumMember() { - var text = @"public enum z -{ - /// - /// - /// - /// <$$ - a -} -"; + var text = """ + public enum z + { + /// + /// + /// + /// <$$ + a + } + """; await VerifyItemsExistAsync(text); } @@ -441,11 +490,12 @@ public async Task EnumMember() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/954679")] public async Task CompletionList() { - await VerifyItemExistsAsync(@" -/// $$ -public class goo -{ -}", "completionlist"); + await VerifyItemExistsAsync(""" + /// $$ + public class goo + { + } + """, "completionlist"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] @@ -453,76 +503,79 @@ public class goo public async Task ParamRefNames() { // Local functions do not support documentation comments - await VerifyItemIsAbsentAsync(@" -/// -/// -/// -static void Main(string[] args) -{ -} -", "args", sourceCodeKind: SourceCodeKind.Regular); + await VerifyItemIsAbsentAsync(""" + /// + /// + /// + static void Main(string[] args) + { + } + """, "args", sourceCodeKind: SourceCodeKind.Regular); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/775091")] public async Task ParamRefNames_Interactive() { - await VerifyItemExistsAsync(@" -/// -/// -/// -static void Main(string[] args) -{ -} -", "args", sourceCodeKind: SourceCodeKind.Script); + await VerifyItemExistsAsync(""" + /// + /// + /// + static void Main(string[] args) + { + } + """, "args", sourceCodeKind: SourceCodeKind.Script); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] public async Task ParamNamesInEmptyAttribute() { // Local functions do not support documentation comments - await VerifyItemIsAbsentAsync(@" -/// -static void Goo(string str) -{ -} -", "str", sourceCodeKind: SourceCodeKind.Regular); + await VerifyItemIsAbsentAsync(""" + /// + static void Goo(string str) + { + } + """, "str", sourceCodeKind: SourceCodeKind.Regular); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44423")] public async Task ParamNamesInEmptyAttribute_Interactive() { - await VerifyItemExistsAsync(@" -/// -static void Goo(string str) -{ -} -", "str", sourceCodeKind: SourceCodeKind.Script); + await VerifyItemExistsAsync(""" + /// + static void Goo(string str) + { + } + """, "str", sourceCodeKind: SourceCodeKind.Script); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26713")] public async Task DelegateParams() { - await VerifyItemExistsAsync(@" -/// $$ -delegate void D(object o); -", "param name=\"o\""); + await VerifyItemExistsAsync(""" + /// $$ + delegate void D(object o); + """, """ + param name="o" + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17872")] public async Task TypeParamRefNamesInEmptyAttribute() { - var text = @" -public class Outer -{ - public class Inner - { - /// - /// - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + /// + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync(text, "TOuter", "TInner", "TMethod"); } @@ -530,17 +583,18 @@ public int Method(T green) { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17872")] public async Task TypeParamRefNamesPartiallyTyped() { - var text = @" -public class Outer -{ - public class Inner - { - /// - /// - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + /// + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync(text, "TOuter", "TInner", "TMethod"); } @@ -548,15 +602,16 @@ public int Method(T green) { } [Fact] public async Task TypeParamNamesInEmptyAttribute() { - var text = @" -public class Outer -{ - public class Inner - { - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync(text, "TMethod"); await VerifyItemsAbsentAsync(text, "TOuter", "TInner"); @@ -565,17 +620,18 @@ public int Method(T green) { } [Fact] public async Task TypeParamNamesInWrongScope() { - var text = @" -public class Outer -{ - public class Inner - { - /// - /// - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + /// + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync(text, "TMethod"); await VerifyItemsAbsentAsync(text, "TOuter", "TInner"); @@ -584,15 +640,16 @@ public int Method(T green) { } [Fact] public async Task TypeParamNamesPartiallyTyped() { - var text = @" -public class Outer -{ - public class Inner - { - /// - public int Method(T green) { } - } -}"; + var text = """ + public class Outer + { + public class Inner + { + /// + public int Method(T green) { } + } + } + """; await VerifyItemsExistAsync(text, "TMethod"); await VerifyItemsAbsentAsync(text, "TOuter", "TInner"); @@ -601,376 +658,398 @@ public int Method(T green) { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8322")] public async Task PartialTagCompletion() { - await VerifyItemsExistAsync(@" -public class goo -{ - /// - /// - public void bar() { } -}", "!--", "![CDATA[", "c", "code", "inheritdoc", "list", "para", "see", "seealso"); + await VerifyItemsExistAsync(""" + public class goo + { + /// + /// + public void bar() { } + } + """, "!--", "![CDATA[", "c", "code", "inheritdoc", "list", "para", "see", "seealso"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11487")] public async Task TypeParamAtTopLevelOnly() { - await VerifyItemsAbsentAsync(@" -/// -/// $$ -/// -public class Goo -{ -}", "typeparam name=\"T\""); + await VerifyItemsAbsentAsync(""" + /// + /// $$ + /// + public class Goo + { + } + """, """ + typeparam name="T" + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11487")] public async Task ParamAtTopLevelOnly() { - await VerifyItemsAbsentAsync(@" -/// -/// $$ -/// -static void Goo(string str) -{ -}", "param name=\"str\""); + await VerifyItemsAbsentAsync(""" + /// + /// $$ + /// + static void Goo(string str) + { + } + """, """ + param name="str" + """); } [Fact] public async Task ListAttributeNames() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "type"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "type"); } [Fact] public async Task ListTypeAttributeValue() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "bullet", "number", "table"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "bullet", "number", "table"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37504")] [WorkItem(11489, "https://github.com/dotnet/roslyn/issues/11490")] public async Task SeeAttributeNames() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "cref", "langword", "href"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "cref", "langword", "href"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37504")] public async Task SeeAlsoAttributeNames() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "cref", "href"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "cref", "href"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22789")] public async Task LangwordCompletionInPlainText() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// Some text $$ - /// - static void Goo() - { - } -}", "null", "sealed", "true", "false", "await"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// Some text $$ + /// + static void Goo() + { + } + } + """, "null", "sealed", "true", "false", "await"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22789")] public async Task LangwordCompletionAfterAngleBracket1() { - await VerifyItemsAbsentAsync(@" -class C -{ - /// - /// Some text <$$ - /// - static void Goo() - { - } -}", "null", "sealed", "true", "false", "await"); + await VerifyItemsAbsentAsync(""" + class C + { + /// + /// Some text <$$ + /// + static void Goo() + { + } + } + """, "null", "sealed", "true", "false", "await"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22789")] public async Task LangwordCompletionAfterAngleBracket2() { - await VerifyItemsAbsentAsync(@" -class C -{ - /// - /// Some text - static void Goo() - { - } -}", "null", "sealed", "true", "false", "await"); + await VerifyItemsAbsentAsync(""" + class C + { + /// + /// Some text + static void Goo() + { + } + } + """, "null", "sealed", "true", "false", "await"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22789")] public async Task LangwordCompletionAfterAngleBracket3() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// Some text < $$ - /// - static void Goo() - { - } -}", "null", "sealed", "true", "false", "await"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// Some text < $$ + /// + static void Goo() + { + } + } + """, "null", "sealed", "true", "false", "await"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11490")] public async Task SeeLangwordAttributeValue() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "null", "true", "false", "await"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "null", "true", "false", "await"); } [Fact] public async Task InheritdocAttributes1() { - await VerifyItemsExistAsync(@" -class C -{ - /// - /// - /// - static void Goo() - { - } -}", "cref", "path"); + await VerifyItemsExistAsync(""" + class C + { + /// + /// + /// + static void Goo() + { + } + } + """, "cref", "path"); } [Fact] public async Task InheritdocAttributes2() { - await VerifyItemsExistAsync(@" -class C -{ - /// - static void Goo() - { - } -}", "cref", "path"); + await VerifyItemsExistAsync(""" + class C + { + /// + static void Goo() + { + } + } + """, "cref", "path"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameAfterTagNameInIncompleteTag() { - var text = @" -class C -{ - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "cref"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameAfterTagNameInEmptyElement() { - var text = @" -class C -{ - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "cref"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameAfterTagNamePartiallyTyped() { - var text = @" -class C -{ - /// - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "type"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameAfterSpecialNameAttribute() { - var text = @" -class C -{ - /// - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "type"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameAfterTextAttribute() { - var text = @" -class C -{ - /// - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "type"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameInWrongTagTypeEmptyElement() { - var text = @" -class C -{ - /// - /// - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + /// + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "type"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeNameInWrongTagTypeElementStartTag() { - var text = @" -class C -{ - /// - /// - /// - void Goo() { } -} -"; + var text = """ + class C + { + /// + /// + /// + void Goo() { } + } + """; await VerifyItemExistsAsync(text, "langword"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")] public async Task AttributeValueOnQuote() { - var text = @" -class C -{ - /// - /// - static void Goo() - { - } -}"; + var text = """ + class C + { + /// + /// - /// - /// - /// $$ - /// - /// - /// - static void Goo() - { - } -}"; + var text = """ + class C + { + /// + /// + /// + /// $$ + /// + /// + /// + static void Goo() + { + } + } + """; await VerifyItemExistsAsync(text, "term"); await VerifyItemExistsAsync(text, "description"); } @@ -978,73 +1057,101 @@ static void Goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52738")] public async Task RecordParam() { - await VerifyItemsExistAsync(@" -/// $$ -public record Goo(string MyParameter); -", "param name=\"MyParameter\"", "typeparam name=\"T\""); + await VerifyItemsExistAsync(""" + /// $$ + public record Goo(string MyParameter); + """, """ + param name="MyParameter" + """, """ + typeparam name="T" + """); } [Fact] public async Task PrimaryConstructor_Class_Param() { - await VerifyItemsExistAsync(@" -/// $$ -public class Goo(string MyParameter); -", "param name=\"MyParameter\"", "typeparam name=\"T\""); + await VerifyItemsExistAsync(""" + /// $$ + public class Goo(string MyParameter); + """, """ + param name="MyParameter" + """, """ + typeparam name="T" + """); } [Fact] public async Task PrimaryConstructor_Struct_Param() { - await VerifyItemsExistAsync(@" -/// $$ -public struct Goo(string MyParameter); -", "param name=\"MyParameter\"", "typeparam name=\"T\""); + await VerifyItemsExistAsync(""" + /// $$ + public struct Goo(string MyParameter); + """, """ + param name="MyParameter" + """, """ + typeparam name="T" + """); } [Fact] [WorkItem("https://github.com/dotnet/roslyn/issues/69293")] public async Task DelegateParamRef() { - await VerifyItemsExistAsync(@" -/// -/// $$ -/// -public delegate void Goo(string myParameter); -", "paramref name=\"myParameter\"", "typeparamref name=\"T\""); + await VerifyItemsExistAsync(""" + /// + /// $$ + /// + public delegate void Goo(string myParameter); + """, """ + paramref name="myParameter" + """, """ + typeparamref name="T" + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52738")] public async Task RecordParamRef() { - await VerifyItemsExistAsync(@" -/// -/// $$ -/// -public record Goo(string MyParameter); -", "paramref name=\"MyParameter\"", "typeparamref name=\"T\""); + await VerifyItemsExistAsync(""" + /// + /// $$ + /// + public record Goo(string MyParameter); + """, """ + paramref name="MyParameter" + """, """ + typeparamref name="T" + """); } [Fact] public async Task PrimaryConstructor_Class_ParamRef() { - await VerifyItemsExistAsync(@" -/// -/// $$ -/// -public class Goo(string MyParameter); -", "paramref name=\"MyParameter\"", "typeparamref name=\"T\""); + await VerifyItemsExistAsync(""" + /// + /// $$ + /// + public class Goo(string MyParameter); + """, """ + paramref name="MyParameter" + """, """ + typeparamref name="T" + """); } [Fact] public async Task PrimaryConstructor_Struct_ParamRef() { - await VerifyItemsExistAsync(@" -/// -/// $$ -/// -public struct Goo(string MyParameter); -", "paramref name=\"MyParameter\"", "typeparamref name=\"T\""); + await VerifyItemsExistAsync(""" + /// + /// $$ + /// + public struct Goo(string MyParameter); + """, """ + paramref name="MyParameter" + """, """ + typeparamref name="T" + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionServiceTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionServiceTests.cs index cf3b94c5d7761..cf2904e0d943f 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionServiceTests.cs @@ -150,16 +150,17 @@ public async Task PassThroughOptions2() [Theory, CombinatorialData] public async Task GettingCompletionListShoudNotRunSourceGenerator(bool forkBeforeFreeze) { - var sourceMarkup = @" -using System; - -namespace N -{ - public class C1 - { - $$ - } -}"; + var sourceMarkup = """ + using System; + + namespace N + { + public class C1 + { + $$ + } + } + """; MarkupTestFile.GetPosition(sourceMarkup.NormalizeLineEndings(), out var source, out int? position); var generatorRanCount = 0; diff --git a/src/EditorFeatures/CSharpTest/ConvertNamespace/ConvertNamespaceCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/ConvertNamespace/ConvertNamespaceCommandHandlerTests.cs index e6bf4475fa0e0..85be3fae92d39 100644 --- a/src/EditorFeatures/CSharpTest/ConvertNamespace/ConvertNamespaceCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/ConvertNamespace/ConvertNamespaceCommandHandlerTests.cs @@ -36,12 +36,13 @@ public static ConvertNamespaceTestState CreateTestState(string markup) => new(GetWorkspaceXml(markup)); public static XElement GetWorkspaceXml(string markup) - => XElement.Parse(string.Format(@" - - - {0} - -", markup)); + => XElement.Parse(string.Format(""" + + + {0} + + + """, markup)); internal void AssertCodeIs(string expectedCode) { @@ -58,299 +59,347 @@ public void SendTypeChar(char ch) public void TestSingleName() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace N$$ -{ - class C - { - } -}"); + """ + namespace N$$ + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace N;$$ + """ + namespace N;$$ -class C -{ -}"); + class C + { + } + """); } [WpfFact] public void TestOptionOff() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace N$$ -{ - class C - { - } -}"); + """ + namespace N$$ + { + class C + { + } + } + """); testState.Workspace.GlobalOptions.SetGlobalOption(CompleteStatementOptionsStorage.AutomaticallyCompleteStatementOnSemicolon, false); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace N;$$ -{ - class C - { - } -}"); + """ + namespace N;$$ + { + class C + { + } + } + """); } [WpfFact] public void TestDottedName1() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace A.B$$ -{ - class C - { - } -}"); + """ + namespace A.B$$ + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace A.B;$$ + """ + namespace A.B;$$ -class C -{ -}"); + class C + { + } + """); } [WpfFact] public void TestDottedName2() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace A.$$B -{ - class C - { - } -}"); + """ + namespace A.$$B + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace A.;$$B -{ - class C - { - } -}"); + """ + namespace A.;$$B + { + class C + { + } + } + """); } [WpfFact] public void TestDottedName3() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace A$$.B -{ - class C - { - } -}"); + """ + namespace A$$.B + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace A;$$.B -{ - class C - { - } -}"); + """ + namespace A;$$.B + { + class C + { + } + } + """); } [WpfFact] public void TestDottedName4() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace $$A.B -{ - class C - { - } -}"); + """ + namespace $$A.B + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace ;$$A.B -{ - class C - { - } -}"); + """ + namespace ;$$A.B + { + class C + { + } + } + """); } [WpfFact] public void TestAfterWhitespace() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace A.B $$ -{ - class C - { - } -}"); + """ + namespace A.B $$ + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace A.B;$$ + """ + namespace A.B;$$ -class C -{ -}"); + class C + { + } + """); } [WpfFact] public void TestBeforeName() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace $$N -{ - class C - { - } -}"); + """ + namespace $$N + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace ;$$N -{ - class C - { - } -}"); + """ + namespace ;$$N + { + class C + { + } + } + """); } [WpfFact] public void TestNestedNamespace() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace N$$ -{ - namespace N2 - { - class C - { - } - } -}"); + """ + namespace N$$ + { + namespace N2 + { + class C + { + } + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace N;$$ -{ - namespace N2 - { - class C - { - } - } -}"); + """ + namespace N;$$ + { + namespace N2 + { + class C + { + } + } + } + """); } [WpfFact] public void TestSiblingNamespace() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace N$$ -{ -} - -namespace N2 -{ - class C - { - } -}"); + """ + namespace N$$ + { + } + + namespace N2 + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace N;$$ -{ -} - -namespace N2 -{ - class C - { - } -}"); + """ + namespace N;$$ + { + } + + namespace N2 + { + class C + { + } + } + """); } [WpfFact] public void TestOuterUsings() { using var testState = ConvertNamespaceTestState.CreateTestState( -@" -using A; -using B; - -namespace N$$ -{ - class C - { - } -}"); + """ + using A; + using B; + + namespace N$$ + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@" -using A; -using B; + """ + using A; + using B; -namespace N;$$ + namespace N;$$ -class C -{ -}"); + class C + { + } + """); } [WpfFact] public void TestInnerUsings() { using var testState = ConvertNamespaceTestState.CreateTestState( -@" -namespace N$$ -{ - using A; - using B; - - class C - { - } -}"); + """ + namespace N$$ + { + using A; + using B; + + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@" -namespace N;$$ + """ + namespace N;$$ -using A; -using B; + using A; + using B; -class C -{ -}"); + class C + { + } + """); } [WpfFact] public void TestCommentAfterName() { using var testState = ConvertNamespaceTestState.CreateTestState( -@"namespace N$$ // Goo -{ - class C - { - } -}"); + """ + namespace N$$ // Goo + { + class C + { + } + } + """); testState.SendTypeChar(';'); testState.AssertCodeIs( -@"namespace N;$$ // Goo + """ + namespace N;$$ // Goo -class C -{ -}"); + class C + { + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Debugging/DataTipInfoGetterTests.cs b/src/EditorFeatures/CSharpTest/Debugging/DataTipInfoGetterTests.cs index 8725edc93e586..a812ec2ebc5be 100644 --- a/src/EditorFeatures/CSharpTest/Debugging/DataTipInfoGetterTests.cs +++ b/src/EditorFeatures/CSharpTest/Debugging/DataTipInfoGetterTests.cs @@ -72,229 +72,265 @@ public async Task TestCSharpLanguageDebugInfoGetDataTipSpanAndText() public async Task Test1() { await TestAsync( -@"class C -{ - void Goo() - { - [|Sys$$tem|].Console.WriteLine(args); - } -}"); + """ + class C + { + void Goo() + { + [|Sys$$tem|].Console.WriteLine(args); + } + } + """); } [Fact] public async Task Test2() { await TestAsync( -@"class C -{ - void Goo() - { - [|System$$.Console|].WriteLine(args); - } -}"); + """ + class C + { + void Goo() + { + [|System$$.Console|].WriteLine(args); + } + } + """); } [Fact] public async Task Test3() { await TestAsync( -@"class C -{ - void Goo() - { - [|System.$$Console|].WriteLine(args); - } -}"); + """ + class C + { + void Goo() + { + [|System.$$Console|].WriteLine(args); + } + } + """); } [Fact] public async Task Test4() { await TestAsync( -@"class C -{ - void Goo() - { - [|System.Con$$sole|].WriteLine(args); - } -}"); + """ + class C + { + void Goo() + { + [|System.Con$$sole|].WriteLine(args); + } + } + """); } [Fact] public async Task Test5() { await TestAsync( -@"class C -{ - void Goo() - { - [|System.Console.Wri$$teLine|](args); - } -}"); + """ + class C + { + void Goo() + { + [|System.Console.Wri$$teLine|](args); + } + } + """); } [Fact] public async Task Test6() { await TestNoDataTipAsync( -@"class C -{ - void Goo() - { - [|System.Console.WriteLine|]$$(args); - } -}"); + """ + class C + { + void Goo() + { + [|System.Console.WriteLine|]$$(args); + } + } + """); } [Fact] public async Task Test7() { await TestAsync( -@"class C -{ - void Goo() - { - System.Console.WriteLine($$[|args|]); - } -}"); + """ + class C + { + void Goo() + { + System.Console.WriteLine($$[|args|]); + } + } + """); } [Fact] public async Task Test8() { await TestNoDataTipAsync( -@"class C -{ - void Goo() - { - [|System.Console.WriteLine|](args$$); - } -}"); + """ + class C + { + void Goo() + { + [|System.Console.WriteLine|](args$$); + } + } + """); } [Fact] public async Task TestVar() { await TestAsync( -@"class C -{ - void Goo() - { - [|va$$r|] v = 0; - } -}", "int"); + """ + class C + { + void Goo() + { + [|va$$r|] v = 0; + } + } + """, "int"); } [Fact] public async Task TestVariableType() { await TestAsync( -@"class C -{ - void Goo() - { - [|in$$t|] i = 0; - } -}"); + """ + class C + { + void Goo() + { + [|in$$t|] i = 0; + } + } + """); } [Fact] public async Task TestVariableIdentifier() { await TestAsync( -@"class C -{ - void Goo() - { - int [|$$i|] = 0; - } -}"); + """ + class C + { + void Goo() + { + int [|$$i|] = 0; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539910")] public async Task TestLiterals() { await TestAsync( -@"class C -{ - void Goo() - { - int i = [|4$$2|]; - } -}", "int"); + """ + class C + { + void Goo() + { + int i = [|4$$2|]; + } + } + """, "int"); } [Fact] public async Task TestNonExpressions() { await TestNoDataTipAsync( -@"class C -{ - void Goo() - { - int i = 42; - }$$ -}"); + """ + class C + { + void Goo() + { + int i = 42; + }$$ + } + """); } [Fact] public async Task TestParameterIdentifier() { await TestAsync( -@"class C -{ - void Goo(int [|$$i|]) - { - } -}"); + """ + class C + { + void Goo(int [|$$i|]) + { + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/942699")] public async Task TestCatchIdentifier() { await TestAsync( -@"class C -{ - void Goo() - { - try - { - } - catch (System.Exception [|$$e|]) - { - } - } -}"); + """ + class C + { + void Goo() + { + try + { + } + catch (System.Exception [|$$e|]) + { + } + } + } + """); } [Fact] public async Task TestEvent() { await TestAsync( -@"class C -{ - event System.Action [|$$E|]; -}"); + """ + class C + { + event System.Action [|$$E|]; + } + """); await TestAsync( -@"class C -{ - event System.Action [|$$E|] - { - add { } - remove { } - } -}"); + """ + class C + { + event System.Action [|$$E|] + { + add { } + remove { } + } + } + """); } [Fact] public async Task TestMethod() { await TestAsync( -@"class C -{ - int [|$$M|]() { } -}"); + """ + class C + { + int [|$$M|]() { } + } + """); } [Fact] @@ -302,140 +338,157 @@ public async Task TestTypeParameter() { await TestAsync("class C { }"); await TestAsync( -@"class C -{ - void M() { } -}"); + """ + class C + { + void M() { } + } + """); } [Fact] public async Task UsingAlias() { await TestAsync( -@"using [|$$S|] = Static; + """ + using [|$$S|] = Static; -static class Static -{ -}"); + static class Static + { + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540921")] public async Task TestForEachIdentifier() { await TestAsync( -@"class C -{ - void Goo(string[] args) - { - foreach (string [|$$s|] in args) - { - } - } -}"); + """ + class C + { + void Goo(string[] args) + { + foreach (string [|$$s|] in args) + { + } + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546328")] public async Task TestProperty() { await TestAsync( -@"namespace ConsoleApplication16 -{ - class C - { - public int [|$$goo|] { get; private set; } // hover over me - public C() - { - this.goo = 1; - } - public int Goo() - { - return 2; // breakpoint here - } - } - class Program - { - static void Main(string[] args) - { - new C().Goo(); - } - } -} -"); + """ + namespace ConsoleApplication16 + { + class C + { + public int [|$$goo|] { get; private set; } // hover over me + public C() + { + this.goo = 1; + } + public int Goo() + { + return 2; // breakpoint here + } + } + class Program + { + static void Main(string[] args) + { + new C().Goo(); + } + } + } + """); } [Fact] public async Task TestQueryIdentifier() { await TestAsync( // From -@"class C -{ - object Goo(string[] args) - { - return from [|$$a|] in args select a; - } -}"); + """ + class C + { + object Goo(string[] args) + { + return from [|$$a|] in args select a; + } + } + """); await TestAsync( // Let -@"class C -{ - object Goo(string[] args) - { - return from a in args let [|$$b|] = ""END"" select a + b; - } -}"); + """ + class C + { + object Goo(string[] args) + { + return from a in args let [|$$b|] = "END" select a + b; + } + } + """); await TestAsync( // Join -@"class C -{ - object Goo(string[] args) - { - return from a in args join [|$$b|] in args on a equals b; - } -}"); + """ + class C + { + object Goo(string[] args) + { + return from a in args join [|$$b|] in args on a equals b; + } + } + """); await TestAsync( // Join Into -@"class C -{ - object Goo(string[] args) - { - return from a in args join b in args on a equals b into [|$$c|]; - } -}"); + """ + class C + { + object Goo(string[] args) + { + return from a in args join b in args on a equals b into [|$$c|]; + } + } + """); await TestAsync( // Continuation -@"class C -{ - object Goo(string[] args) - { - return from a in args select a into [|$$b|] from c in b select c; - } -}"); + """ + class C + { + object Goo(string[] args) + { + return from a in args select a into [|$$b|] from c in b select c; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077843")] public async Task TestConditionalAccessExpression() { - var sourceTemplate = @" -class A -{{ - B B; - - object M() - {{ - return {0}; - }} -}} - -class B -{{ - C C; -}} - -class C -{{ - D D; -}} - -class D -{{ -}} -"; + var sourceTemplate = """ + class A + {{ + B B; + + object M() + {{ + return {0}; + }} + }} + + class B + {{ + C C; + }} + + class C + {{ + D D; + }} + + class D + {{ + }} + """; // One level. await TestAsync(string.Format(sourceTemplate, "[|Me?.$$B|]")); @@ -483,26 +536,26 @@ class D [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077843")] public async Task TestConditionalAccessExpression_Trivia() { - var sourceTemplate = @" -class A -{{ - B B; - - object M() - {{ - return {0}; - }} -}} - -class B -{{ - C C; -}} - -class C -{{ -}} -"; + var sourceTemplate = """ + class A + {{ + B B; + + object M() + {{ + return {0}; + }} + }} + + class B + {{ + C C; + }} + + class C + {{ + }} + """; await TestAsync(string.Format(sourceTemplate, "/*1*/[|$$Me|]/*2*/?./*3*/B/*4*/?./*5*/C/*6*/")); await TestAsync(string.Format(sourceTemplate, "/*1*/[|Me/*2*/?./*3*/$$B|]/*4*/?./*5*/C/*6*/")); diff --git a/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs b/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs index e7c7bbac5f4d6..57d3af9f36c74 100644 --- a/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs +++ b/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs @@ -43,28 +43,31 @@ public async Task TestClass() public async Task TestMethod() { await TestAsync( -@"class Class -{ - public static void Meth$$od() - { - } -} -", "Class.Method()", 0); + """ + class Class + { + public static void Meth$$od() + { + } + } + """, "Class.Method()", 0); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/527668")] public async Task TestNamespace() { await TestAsync( -@"namespace Namespace -{ - class Class - { - void Method() - { - }$$ - } -}", "Namespace.Class.Method()", 2); + """ + namespace Namespace + { + class Class + { + void Method() + { + }$$ + } + } + """, "Namespace.Class.Method()", 2); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49000")] @@ -73,435 +76,478 @@ public async Task TestFileScopedNamespace() // This test behavior is incorrect. This should be Namespace.Class.Method. // See the associated WorkItem for details. await TestAsync( -@"namespace Namespace; + """ + namespace Namespace; -class Class -{ - void Method() - { - }$$ -} -", "Namespace.Class.Method()", 2); + class Class + { + void Method() + { + }$$ + } + """, "Namespace.Class.Method()", 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/527668")] public async Task TestDottedNamespace() { await TestAsync( -@"namespace Namespace.Another -{ - class Class - { - void Method() - { - }$$ - } -}", "Namespace.Another.Class.Method()", 2); + """ + namespace Namespace.Another + { + class Class + { + void Method() + { + }$$ + } + } + """, "Namespace.Another.Class.Method()", 2); } [Fact] public async Task TestNestedNamespace() { await TestAsync( -@"namespace Namespace -{ - namespace Another - { - class Class - { - void Method() - { - }$$ - } - } -}", "Namespace.Another.Class.Method()", 2); + """ + namespace Namespace + { + namespace Another + { + class Class + { + void Method() + { + }$$ + } + } + } + """, "Namespace.Another.Class.Method()", 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/527668")] public async Task TestNestedType() { await TestAsync( -@"class Outer -{ - class Inner - { - void Quux() - {$$ - } - } -}", "Outer.Inner.Quux()", 1); + """ + class Outer + { + class Inner + { + void Quux() + {$$ + } + } + } + """, "Outer.Inner.Quux()", 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/527668")] public async Task TestPropertyGetter() { await TestAsync( -@"class Class -{ - string Property - { - get - { - return null;$$ - } - } -}", "Class.Property", 4); + """ + class Class + { + string Property + { + get + { + return null;$$ + } + } + } + """, "Class.Property", 4); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/527668")] public async Task TestPropertySetter() { await TestAsync( -@"class Class -{ - string Property - { - get - { - return null; - } + """ + class Class + { + string Property + { + get + { + return null; + } - set - { - string s = $$value; - } - } -}", "Class.Property", 9); + set + { + string s = $$value; + } + } + } + """, "Class.Property", 9); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538415")] public async Task TestField() { await TestAsync( -@"class Class -{ - int fi$$eld; -}", "Class.field", 0); + """ + class Class + { + int fi$$eld; + } + """, "Class.field", 0); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543494")] public async Task TestLambdaInFieldInitializer() { await TestAsync( -@"class Class -{ - Action a = b => { in$$t c; }; -}", "Class.a", 0); + """ + class Class + { + Action a = b => { in$$t c; }; + } + """, "Class.a", 0); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543494")] public async Task TestMultipleFields() { await TestAsync( -@"class Class -{ - int a1, a$$2; -}", "Class.a2", 0); + """ + class Class + { + int a1, a$$2; + } + """, "Class.a2", 0); } [Fact] public async Task TestConstructor() { await TestAsync( -@"class C1 -{ - C1() - { + """ + class C1 + { + C1() + { - $$} -} -", "C1.C1()", 3); + $$} + } + """, "C1.C1()", 3); } [Fact] public async Task TestDestructor() { await TestAsync( -@"class C1 -{ - ~C1() - { - $$} -} -", "C1.~C1()", 2); + """ + class C1 + { + ~C1() + { + $$} + } + """, "C1.~C1()", 2); } [Fact] public async Task TestOperator() { await TestAsync( -@"namespace N1 -{ - class C1 - { - public static int operator +(C1 x, C1 y) - { - $$return 42; - } - } -} -", "N1.C1.+(C1 x, C1 y)", 2); // Old implementation reports "operator +" (rather than "+")... + """ + namespace N1 + { + class C1 + { + public static int operator +(C1 x, C1 y) + { + $$return 42; + } + } + } + """, "N1.C1.+(C1 x, C1 y)", 2); // Old implementation reports "operator +" (rather than "+")... } [Fact] public async Task TestConversionOperator() { await TestAsync( -@"namespace N1 -{ - class C1 - { - public static explicit operator N1.C2(N1.C1 x) - { - $$return null; - } - } - class C2 - { - } -} -", "N1.C1.N1.C2(N1.C1 x)", 2); // Old implementation reports "explicit operator N1.C2" (rather than "N1.C2")... + """ + namespace N1 + { + class C1 + { + public static explicit operator N1.C2(N1.C1 x) + { + $$return null; + } + } + class C2 + { + } + } + """, "N1.C1.N1.C2(N1.C1 x)", 2); // Old implementation reports "explicit operator N1.C2" (rather than "N1.C2")... } [Fact] public async Task TestEvent() { await TestAsync( -@"class C1 -{ - delegate void D1(); - event D1 e1$$; -} -", "C1.e1", 0); + """ + class C1 + { + delegate void D1(); + event D1 e1$$; + } + """, "C1.e1", 0); } [Fact] public async Task TextExplicitInterfaceImplementation() { await TestAsync( -@"interface I1 -{ - void M1(); -} -class C1 -{ - void I1.M1() - { - $$} -} -", "C1.M1()", 2); + """ + interface I1 + { + void M1(); + } + class C1 + { + void I1.M1() + { + $$} + } + """, "C1.M1()", 2); } [Fact] public async Task TextIndexer() { await TestAsync( -@"class C1 -{ - C1 this[int x] - { - get - { - $$return null; - } - } -} -", "C1.this[int x]", 4); + """ + class C1 + { + C1 this[int x] + { + get + { + $$return null; + } + } + } + """, "C1.this[int x]", 4); } [Fact] public async Task TestParamsParameter() { await TestAsync( -@"class C1 -{ - void M1(params int[] x) { $$ } -} -", "C1.M1(params int[] x)", 0); + """ + class C1 + { + void M1(params int[] x) { $$ } + } + """, "C1.M1(params int[] x)", 0); } [Fact] public async Task TestArglistParameter() { await TestAsync( -@"class C1 -{ - void M1(__arglist) { $$ } -} -", "C1.M1(__arglist)", 0); // Old implementation does not show "__arglist"... + """ + class C1 + { + void M1(__arglist) { $$ } + } + """, "C1.M1(__arglist)", 0); // Old implementation does not show "__arglist"... } [Fact] public async Task TestRefAndOutParameters() { await TestAsync( -@"class C1 -{ - void M1( ref int x, out int y ) - { - $$y = x; - } -} -", "C1.M1( ref int x, out int y )", 2); // Old implementation did not show extra spaces around the parameters... + """ + class C1 + { + void M1( ref int x, out int y ) + { + $$y = x; + } + } + """, "C1.M1( ref int x, out int y )", 2); // Old implementation did not show extra spaces around the parameters... } [Fact] public async Task TestOptionalParameters() { await TestAsync( -@"class C1 -{ - void M1(int x =1) - { - $$y = x; - } -} -", "C1.M1(int x =1)", 2); + """ + class C1 + { + void M1(int x =1) + { + $$y = x; + } + } + """, "C1.M1(int x =1)", 2); } [Fact] public async Task TestExtensionMethod() { await TestAsync( -@"static class C1 -{ - static void M1(this int x) - { - }$$ -} -", "C1.M1(this int x)", 2); + """ + static class C1 + { + static void M1(this int x) + { + }$$ + } + """, "C1.M1(this int x)", 2); } [Fact] public async Task TestGenericType() { await TestAsync( -@"class C1 -{ - static void M1() { $$ } -} -", "C1.M1()", 0); + """ + class C1 + { + static void M1() { $$ } + } + """, "C1.M1()", 0); } [Fact] public async Task TestGenericMethod() { await TestAsync( -@"class C1 -{ - static void M1() { $$ } -} -", "C1.M1()", 0); + """ + class C1 + { + static void M1() { $$ } + } + """, "C1.M1()", 0); } [Fact] public async Task TestGenericParameters() { await TestAsync( -@"class C1 -{ - static void M1(C1 x, V y) { $$ } -} -", "C1.M1(C1 x, V y)", 0); + """ + class C1 + { + static void M1(C1 x, V y) { $$ } + } + """, "C1.M1(C1 x, V y)", 0); } [Fact] public async Task TestMissingNamespace() { await TestAsync( -@"{ - class Class - { - int a1, a$$2; - } -}", "Class.a2", 0); + """ + { + class Class + { + int a1, a$$2; + } + } + """, "Class.a2", 0); } [Fact] public async Task TestMissingNamespaceName() { await TestAsync( -@"namespace -{ - class C1 - { - int M1() - $${ - } - } -}", "?.C1.M1()", 1); + """ + namespace + { + class C1 + { + int M1() + $${ + } + } + } + """, "?.C1.M1()", 1); } [Fact] public async Task TestMissingClassName() { await TestAsync( -@"namespace N1 - class - { - int M1() - $${ - } - } -}", "N1.M1()", 1); // Old implementation displayed "N1.?.M1", but we don't see a class declaration in the syntax tree... + """ + namespace N1 + class + { + int M1() + $${ + } + } + } + """, "N1.M1()", 1); // Old implementation displayed "N1.?.M1", but we don't see a class declaration in the syntax tree... } [Fact] public async Task TestMissingMethodName() { await TestAsync( -@"namespace N1 -{ - class C1 - { - static void (ref int x) - { - $$} - } -}", "N1.C1", 4); + """ + namespace N1 + { + class C1 + { + static void (ref int x) + { + $$} + } + } + """, "N1.C1", 4); } [Fact] public async Task TestMissingParameterList() { await TestAsync( -@"namespace N1 -{ - class C1 - { - static void M1 - { - $$} - } -}", "N1.C1.M1", 2); + """ + namespace N1 + { + class C1 + { + static void M1 + { + $$} + } + } + """, "N1.C1.M1", 2); } [Fact] public async Task TopLevelField() { await TestAsync( -@"$$int f1; -", "f1", 0, new CSharpParseOptions(kind: SourceCodeKind.Script)); + """ + $$int f1; + """, "f1", 0, new CSharpParseOptions(kind: SourceCodeKind.Script)); } [Fact] public async Task TopLevelMethod() { await TestAsync( -@"int M1(int x) -{ -$$} -", "M1(int x)", 2, new CSharpParseOptions(kind: SourceCodeKind.Script)); + """ + int M1(int x) + { + $$} + """, "M1(int x)", 2, new CSharpParseOptions(kind: SourceCodeKind.Script)); } [Fact] public async Task TopLevelStatement() { await TestAsync( -@" - -$$System.Console.WriteLine(""Hello"") -", null, 0, new CSharpParseOptions(kind: SourceCodeKind.Script)); + """ + $$System.Console.WriteLine("Hello") + """, null, 0, new CSharpParseOptions(kind: SourceCodeKind.Script)); } } } diff --git a/src/EditorFeatures/CSharpTest/Debugging/NameResolverTests.cs b/src/EditorFeatures/CSharpTest/Debugging/NameResolverTests.cs index f4e8404ab627c..f2a17597662d5 100644 --- a/src/EditorFeatures/CSharpTest/Debugging/NameResolverTests.cs +++ b/src/EditorFeatures/CSharpTest/Debugging/NameResolverTests.cs @@ -42,12 +42,14 @@ public async Task TestCSharpLanguageDebugInfoCreateNameResolver() public async Task TestSimpleNameInClass() { var text = -@"class C -{ - void Goo() - { - } -}"; + """ + class C + { + void Goo() + { + } + } + """; await TestAsync(text, "Goo", "C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "C.Goo()"); @@ -63,16 +65,17 @@ void Goo() public async Task TestSimpleNameInNamespace() { var text = -@" -namespace N -{ - class C - { - void Goo() - { - } - } -}"; + """ + namespace N + { + class C + { + void Goo() + { + } + } + } + """; await TestAsync(text, "Goo", "N.C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "N.C.Goo()"); @@ -91,16 +94,17 @@ void Goo() public async Task TestSimpleNameInGenericClassNamespace() { var text = -@" -namespace N -{ - class C - { - void Goo() - { - } - } -}"; + """ + namespace N + { + class C + { + void Goo() + { + } + } + } + """; await TestAsync(text, "Goo", "N.C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "N.C.Goo()"); @@ -120,16 +124,17 @@ void Goo() public async Task TestGenericNameInClassNamespace() { var text = -@" -namespace N -{ - class C - { - void Goo() - { - } - } -}"; + """ + namespace N + { + class C + { + void Goo() + { + } + } + } + """; await TestAsync(text, "Goo", "N.C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "N.C.Goo()"); @@ -154,16 +159,18 @@ void Goo() public async Task TestOverloadsInSingleClass() { var text = -@"class C -{ - void Goo() - { - } - - void Goo(int i) - { - } -}"; + """ + class C + { + void Goo() + { + } + + void Goo(int i) + { + } + } + """; await TestAsync(text, "Goo", "C.Goo()", "C.Goo(int)"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "C.Goo()", "C.Goo(int)"); @@ -180,25 +187,27 @@ void Goo(int i) public async Task TestMethodsInMultipleClasses() { var text = -@"namespace N -{ - class C - { - void Goo() - { - } - } -} - -namespace N1 -{ - class C - { - void Goo(int i) - { - } - } -}"; + """ + namespace N + { + class C + { + void Goo() + { + } + } + } + + namespace N1 + { + class C + { + void Goo(int i) + { + } + } + } + """; await TestAsync(text, "Goo", "N1.C.Goo(int)", "N.C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "N1.C.Goo(int)", "N.C.Goo()"); @@ -216,25 +225,27 @@ void Goo(int i) public async Task TestMethodsWithDifferentArityInMultipleClasses() { var text = -@"namespace N -{ - class C - { - void Goo() - { - } - } -} - -namespace N1 -{ - class C - { - void Goo(int i) - { - } - } -}"; + """ + namespace N + { + class C + { + void Goo() + { + } + } + } + + namespace N1 + { + class C + { + void Goo(int i) + { + } + } + } + """; await TestAsync(text, "Goo", "N1.C.Goo(int)", "N.C.Goo()"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "N1.C.Goo(int)", "N.C.Goo()"); @@ -256,20 +267,22 @@ void Goo(int i) public async Task TestOverloadsWithMultipleParametersInSingleClass() { var text = -@"class C -{ - void Goo(int a) - { - } - - void Goo(int a, string b = ""bb"") - { - } - - void Goo(__arglist) - { - } -}"; + """ + class C + { + void Goo(int a) + { + } + + void Goo(int a, string b = "bb") + { + } + + void Goo(__arglist) + { + } + } + """; await TestAsync(text, "Goo", "C.Goo(int)", "C.Goo(int, [string])", "C.Goo(__arglist)"); await TestAsync(text, "goo"); await TestAsync(text, "C.Goo", "C.Goo(int)", "C.Goo(int, [string])", "C.Goo(__arglist)"); @@ -298,12 +311,14 @@ void Goo(__arglist) public async Task AccessorTests() { var text = -@"class C -{ - int Property1 { get { return 42; } } - int Property2 { set { } } - int Property3 { get; set;} -}"; + """ + class C + { + int Property1 { get { return 42; } } + int Property2 { set { } } + int Property3 { get; set;} + } + """; await TestAsync(text, "Property1", "C.Property1"); await TestAsync(text, "Property2", "C.Property2"); await TestAsync(text, "Property3", "C.Property3"); @@ -313,19 +328,21 @@ int Property2 { set { } } public async Task NegativeTests() { var text = -@"using System.Runtime.CompilerServices; -abstract class C -{ - public abstract void AbstractMethod(int a); - int Field; - delegate void Delegate(); - event Delegate Event; - [IndexerName(""ABCD"")] - int this[int i] { get { return i; } } - void Goo() { } - void Goo(int x = 1, int y = 2) { } - ~C() { } -}"; + """ + using System.Runtime.CompilerServices; + abstract class C + { + public abstract void AbstractMethod(int a); + int Field; + delegate void Delegate(); + event Delegate Event; + [IndexerName("ABCD")] + int this[int i] { get { return i; } } + void Goo() { } + void Goo(int x = 1, int y = 2) { } + ~C() { } + } + """; await TestAsync(text, "AbstractMethod"); await TestAsync(text, "Field"); await TestAsync(text, "Delegate"); @@ -363,16 +380,18 @@ void Goo(int x = 1, int y = 2) { } public async Task TestInstanceConstructors() { var text = -@"class C -{ - public C() { } -} - -class G -{ - public G() { } - ~G() { } -}"; + """ + class C + { + public C() { } + } + + class G + { + public G() { } + ~G() { } + } + """; await TestAsync(text, "C", "C.C()"); await TestAsync(text, "C.C", "C.C()"); await TestAsync(text, "C.C()", "C.C()"); @@ -404,12 +423,14 @@ public G() { } public async Task TestStaticConstructors() { var text = -@"class C -{ - static C() - { - } -}"; + """ + class C + { + static C() + { + } + } + """; await TestAsync(text, "C", "C.C()"); await TestAsync(text, "C.C", "C.C()"); await TestAsync(text, "C.C()", "C.C()"); @@ -427,16 +448,18 @@ static C() public async Task TestAllConstructors() { var text = -@"class C -{ - static C() - { - } - - public C(int i) - { - } -}"; + """ + class C + { + static C() + { + } + + public C(int i) + { + } + } + """; await TestAsync(text, "C", "C.C(int)", "C.C()"); await TestAsync(text, "C.C", "C.C(int)", "C.C()"); await TestAsync(text, "C.C()", "C.C()"); @@ -452,20 +475,22 @@ public C(int i) public async Task TestPartialMethods() { var text = -@"partial class C -{ - partial int M1(); + """ + partial class C + { + partial int M1(); - partial void M2() { } + partial void M2() { } - partial void M2(); + partial void M2(); - partial int M3(); + partial int M3(); - partial int M3(int x) { return 0; } + partial int M3(int x) { return 0; } - partial void M4() { } -}"; + partial void M4() { } + } + """; await TestAsync(text, "M1"); await TestAsync(text, "C.M1"); await TestAsync(text, "M2", "C.M2()"); @@ -479,10 +504,12 @@ partial void M4() { } public async Task TestLeadingAndTrailingText() { var text = -@"class C -{ - void Goo() { }; -}"; + """ + class C + { + void Goo() { }; + } + """; await TestAsync(text, "Goo;", "C.Goo()"); await TestAsync(text, @"Goo();", "C.Goo()"); @@ -496,20 +523,24 @@ await TestAsync(text, await TestAsync(text, @"Goo(); // comment", "C.Goo()"); await TestAsync(text, -@"/*comment*/ - Goo(/* params */); /* comment", "C.Goo()"); + """ + /*comment*/ + Goo(/* params */); /* comment + """, "C.Goo()"); } [Fact] public async Task TestEscapedKeywords() { var text = -@"struct @true { } -class @foreach -{ - void where(@true @this) { } - void @false() { } -}"; + """ + struct @true { } + class @foreach + { + void where(@true @this) { } + void @false() { } + } + """; await TestAsync(text, "where", "@foreach.where(@true)"); await TestAsync(text, "@where", "@foreach.where(@true)"); await TestAsync(text, "@foreach.where", "@foreach.where(@true)"); @@ -523,11 +554,13 @@ void @false() { } public async Task TestAliasQualifiedNames() { var text = -@"extern alias A -class C -{ - void Goo(D d) { } -}"; + """ + extern alias A + class C + { + void Goo(D d) { } + } + """; await TestAsync(text, "A::Goo"); await TestAsync(text, "A::Goo(A::B)"); await TestAsync(text, "A::Goo(A::B)"); @@ -539,39 +572,41 @@ void Goo(D d) { } public async Task TestNestedTypesAndNamespaces() { var text = -@"namespace N1 -{ - class C - { - void Goo() { } - } - namespace N2 - { - class C { } - } - namespace N3 - { - class D { } - } - namespace N4 - { - class C - { - void Goo(double x) { } - - class D - { - void Goo() { } - - class E - { - void Goo() { } - } - } - } - } - namespace N5 { } -}"; + """ + namespace N1 + { + class C + { + void Goo() { } + } + namespace N2 + { + class C { } + } + namespace N3 + { + class D { } + } + namespace N4 + { + class C + { + void Goo(double x) { } + + class D + { + void Goo() { } + + class E + { + void Goo() { } + } + } + } + } + namespace N5 { } + } + """; await TestAsync(text, "Goo", "N1.N4.C.Goo(double)", "N1.N4.C.D.Goo()", "N1.N4.C.D.E.Goo()", "N1.C.Goo()"); await TestAsync(text, "C.Goo", "N1.N4.C.Goo(double)", "N1.C.Goo()"); @@ -586,14 +621,16 @@ namespace N5 { } public async Task TestInterfaces() { var text = -@"interface I1 -{ - void Goo(); -} -class C1 : I1 -{ - void I1.Goo() { } -}"; + """ + interface I1 + { + void Goo(); + } + class C1 : I1 + { + void I1.Goo() { } + } + """; await TestAsync(text, "Goo", "C1.Goo()"); await TestAsync(text, "I1.Goo"); diff --git a/src/EditorFeatures/CSharpTest/DecompiledSource/DecompiledSourceFormattingTests.cs b/src/EditorFeatures/CSharpTest/DecompiledSource/DecompiledSourceFormattingTests.cs index 94dfb974a118d..76ce54129458e 100644 --- a/src/EditorFeatures/CSharpTest/DecompiledSource/DecompiledSourceFormattingTests.cs +++ b/src/EditorFeatures/CSharpTest/DecompiledSource/DecompiledSourceFormattingTests.cs @@ -24,203 +24,231 @@ public class DecompiledSourceFormattingTests public async Task TestIfFormatting1() { await TestAsync( -@"class C { - void M() { - if (true) { - } - } -}", -@"class C -{ - void M() - { - if (true) - { - } - } -}"); + """ + class C { + void M() { + if (true) { + } + } + } + """, + """ + class C + { + void M() + { + if (true) + { + } + } + } + """); } [Fact] public async Task TestIfFormatting2() { await TestAsync( -@"class C { - void M() { - if (true) { - } - return; - } -}", -@"class C -{ - void M() - { - if (true) - { - } + """ + class C { + void M() { + if (true) { + } + return; + } + } + """, + """ + class C + { + void M() + { + if (true) + { + } - return; - } -}"); + return; + } + } + """); } [Fact] public async Task TestIfFormatting3() { await TestAsync( -@"class C { - void M() { - if (true) { - } else { - return; -} - } -}", -@"class C -{ - void M() - { - if (true) - { - } - else - { - return; - } - } -}"); + """ + class C { + void M() { + if (true) { + } else { + return; + } + } + } + """, + """ + class C + { + void M() + { + if (true) + { + } + else + { + return; + } + } + } + """); } [Fact] public async Task TestTryCatchFinally() { await TestAsync( -@"class C { - void M() { - try { - } catch { - } finally { - } - } -}", -@"class C -{ - void M() - { - try - { - } - catch - { - } - finally - { - } - } -}"); + """ + class C { + void M() { + try { + } catch { + } finally { + } + } + } + """, + """ + class C + { + void M() + { + try + { + } + catch + { + } + finally + { + } + } + } + """); } [Fact] public async Task TestDoWhile() { await TestAsync( -@"class C { - void M() { - do { - } while(true); - } -}", -@"class C -{ - void M() - { - do - { - } while (true); - } -}"); + """ + class C { + void M() { + do { + } while(true); + } + } + """, + """ + class C + { + void M() + { + do + { + } while (true); + } + } + """); } [Fact] public async Task TestNestedIf() { await TestAsync( -@"class C { - void M() { - if (true) { - if (true) { - } - } - } -}", -@"class C -{ - void M() - { - if (true) - { - if (true) - { - } - } - } -}"); + """ + class C { + void M() { + if (true) { + if (true) { + } + } + } + } + """, + """ + class C + { + void M() + { + if (true) + { + if (true) + { + } + } + } + } + """); } [Fact] public async Task TestBraces() { await TestAsync( -@"class C { - void M() { - if (true) { - } - while (true) { - } - switch (true) { - } - try { - } finally { - } - using (null) { - } - foreach (var x in y) { - } - } -}", -@"class C -{ - void M() - { - if (true) - { - } + """ + class C { + void M() { + if (true) { + } + while (true) { + } + switch (true) { + } + try { + } finally { + } + using (null) { + } + foreach (var x in y) { + } + } + } + """, + """ + class C + { + void M() + { + if (true) + { + } - while (true) - { - } + while (true) + { + } - switch (true) - { - } + switch (true) + { + } - try - { - } - finally - { - } + try + { + } + finally + { + } - using (null) - { - } + using (null) + { + } - foreach (var x in y) - { - } - } -}"); + foreach (var x in y) + { + } + } + } + """); } private static async Task TestAsync(string input, string expected) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest.cs b/src/EditorFeatures/CSharpTest/Diagnostics/AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest.cs index c1fec49b3cfa8..0c6e242d2d0e4 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest.cs @@ -24,128 +24,129 @@ protected AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest(ITestOutputHel protected internal override string GetLanguage() => LanguageNames.CSharp; - protected const string IAsyncEnumerable = @" -namespace System -{ - public interface IAsyncDisposable - { - System.Threading.Tasks.ValueTask DisposeAsync(); - } -} - -namespace System.Runtime.CompilerServices -{ - using System.Threading.Tasks; - - public sealed class AsyncMethodBuilderAttribute : Attribute - { - public AsyncMethodBuilderAttribute(Type builderType) { } - public Type BuilderType { get; } - } - - public struct AsyncValueTaskMethodBuilder - { - public ValueTask Task => default; - - public static AsyncValueTaskMethodBuilder Create() => default; - public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : INotifyCompletion - where TStateMachine : IAsyncStateMachine {} - - public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) - where TAwaiter : ICriticalNotifyCompletion - where TStateMachine : IAsyncStateMachine {} - public void SetException(Exception exception) {} - public void SetResult() {} - public void SetStateMachine(IAsyncStateMachine stateMachine) {} - public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {} - } - - public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion - { - public bool IsCompleted => default; - - public void GetResult() { } - public void OnCompleted(Action continuation) { } - public void UnsafeOnCompleted(Action continuation) { } - } - - public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion - { - public bool IsCompleted => default; - public TResult GetResult() => default; - public void OnCompleted(Action continuation) { } - public void UnsafeOnCompleted(Action continuation) { } - } -} - -namespace System.Threading.Tasks -{ - using System.Runtime.CompilerServices; - - [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))] - public readonly struct ValueTask : IEquatable - { - public ValueTask(Task task) {} - public ValueTask(IValueTaskSource source, short token) {} - - public bool IsCompleted => default; - public bool IsCompletedSuccessfully => default; - public bool IsFaulted => default; - public bool IsCanceled => default; - - public Task AsTask() => default; - public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; - public override bool Equals(object obj) => default; - public bool Equals(ValueTask other) => default; - public ValueTaskAwaiter GetAwaiter() => default; - public override int GetHashCode() => default; - public ValueTask Preserve() => default; - - public static bool operator ==(ValueTask left, ValueTask right) => default; - public static bool operator !=(ValueTask left, ValueTask right) => default; - } - - [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))] - public readonly struct ValueTask : IEquatable> - { - public ValueTask(TResult result) {} - public ValueTask(Task task) {} - public ValueTask(IValueTaskSource source, short token) {} - - public bool IsFaulted => default; - public bool IsCompletedSuccessfully => default; - public bool IsCompleted => default; - public bool IsCanceled => default; - public TResult Result => default; - - public Task AsTask() => default; - public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; - - public bool Equals(ValueTask other) => default; - public override bool Equals(object obj) => default; - public ValueTaskAwaiter GetAwaiter() => default; - public override int GetHashCode() => default; - public ValueTask Preserve() => default; - public override string ToString() => default; - public static bool operator ==(ValueTask left, ValueTask right) => default; - public static bool operator !=(ValueTask left, ValueTask right) => default; - } -} - -namespace System.Collections.Generic -{ - public interface IAsyncEnumerable - { - IAsyncEnumerator GetAsyncEnumerator(); - } - - public interface IAsyncEnumerator : IAsyncDisposable - { - System.Threading.Tasks.ValueTask MoveNextAsync(); - T Current { get; } - } -}"; + protected const string IAsyncEnumerable = """ + namespace System + { + public interface IAsyncDisposable + { + System.Threading.Tasks.ValueTask DisposeAsync(); + } + } + + namespace System.Runtime.CompilerServices + { + using System.Threading.Tasks; + + public sealed class AsyncMethodBuilderAttribute : Attribute + { + public AsyncMethodBuilderAttribute(Type builderType) { } + public Type BuilderType { get; } + } + + public struct AsyncValueTaskMethodBuilder + { + public ValueTask Task => default; + + public static AsyncValueTaskMethodBuilder Create() => default; + public void AwaitOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : INotifyCompletion + where TStateMachine : IAsyncStateMachine {} + + public void AwaitUnsafeOnCompleted(ref TAwaiter awaiter, ref TStateMachine stateMachine) + where TAwaiter : ICriticalNotifyCompletion + where TStateMachine : IAsyncStateMachine {} + public void SetException(Exception exception) {} + public void SetResult() {} + public void SetStateMachine(IAsyncStateMachine stateMachine) {} + public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {} + } + + public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion + { + public bool IsCompleted => default; + + public void GetResult() { } + public void OnCompleted(Action continuation) { } + public void UnsafeOnCompleted(Action continuation) { } + } + + public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion + { + public bool IsCompleted => default; + public TResult GetResult() => default; + public void OnCompleted(Action continuation) { } + public void UnsafeOnCompleted(Action continuation) { } + } + } + + namespace System.Threading.Tasks + { + using System.Runtime.CompilerServices; + + [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))] + public readonly struct ValueTask : IEquatable + { + public ValueTask(Task task) {} + public ValueTask(IValueTaskSource source, short token) {} + + public bool IsCompleted => default; + public bool IsCompletedSuccessfully => default; + public bool IsFaulted => default; + public bool IsCanceled => default; + + public Task AsTask() => default; + public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; + public override bool Equals(object obj) => default; + public bool Equals(ValueTask other) => default; + public ValueTaskAwaiter GetAwaiter() => default; + public override int GetHashCode() => default; + public ValueTask Preserve() => default; + + public static bool operator ==(ValueTask left, ValueTask right) => default; + public static bool operator !=(ValueTask left, ValueTask right) => default; + } + + [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))] + public readonly struct ValueTask : IEquatable> + { + public ValueTask(TResult result) {} + public ValueTask(Task task) {} + public ValueTask(IValueTaskSource source, short token) {} + + public bool IsFaulted => default; + public bool IsCompletedSuccessfully => default; + public bool IsCompleted => default; + public bool IsCanceled => default; + public TResult Result => default; + + public Task AsTask() => default; + public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => default; + + public bool Equals(ValueTask other) => default; + public override bool Equals(object obj) => default; + public ValueTaskAwaiter GetAwaiter() => default; + public override int GetHashCode() => default; + public ValueTask Preserve() => default; + public override string ToString() => default; + public static bool operator ==(ValueTask left, ValueTask right) => default; + public static bool operator !=(ValueTask left, ValueTask right) => default; + } + } + + namespace System.Collections.Generic + { + public interface IAsyncEnumerable + { + IAsyncEnumerator GetAsyncEnumerator(); + } + + public interface IAsyncEnumerator : IAsyncDisposable + { + System.Threading.Tasks.ValueTask MoveNextAsync(); + T Current { get; } + } + } + """; internal OptionsCollection RequireArithmeticBinaryParenthesesForClarity => ParenthesesOptionsProvider.RequireArithmeticBinaryParenthesesForClarity; internal OptionsCollection RequireRelationalBinaryParenthesesForClarity => ParenthesesOptionsProvider.RequireRelationalBinaryParenthesesForClarity; diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/BooleanCodeStyleOptionConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/BooleanCodeStyleOptionConfigurationTests.cs index cdd3ddfd7ac36..4a862994ecdc6 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/BooleanCodeStyleOptionConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/BooleanCodeStyleOptionConfigurationTests.cs @@ -38,71 +38,73 @@ public class TrueConfigurationTests : BooleanCodeStyleOptionConfigurationTests [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -110,71 +112,73 @@ public Customer() [Fact(Skip = "https://github.com/dotnet/roslyn/issues/39466")] public async Task ConfigureEditorconfig_RuleExists_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] # Comment1 -dotnet_style_object_initializer = false:suggestion ; Comment2 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] # Comment1 -dotnet_style_object_initializer = true:suggestion ; Comment2 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] # Comment1 + dotnet_style_object_initializer = false:suggestion ; Comment2 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] # Comment1 + dotnet_style_object_initializer = true:suggestion ; Comment2 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -182,76 +186,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_style_object_initializer = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_style_object_initializer = false:suggestion - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_style_object_initializer = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_style_object_initializer = false:suggestion + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -259,71 +265,73 @@ public Customer() [Fact(Skip = "https://github.com/dotnet/roslyn/issues/39466")] public async Task ConfigureEditorconfig_MaintainSeverity_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = true:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = true:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -331,76 +339,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = false:suggestion -dotnet_style_object_initializerr = false - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = false:suggestion -dotnet_style_object_initializerr = false - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = false:suggestion + dotnet_style_object_initializerr = false + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = false:suggestion + dotnet_style_object_initializerr = false + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -414,71 +424,73 @@ public class FalseConfigurationTests : BooleanCodeStyleOptionConfigurationTests [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -486,71 +498,73 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = false:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = false:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -558,71 +572,73 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_False_NoSeveritySuffix() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -630,74 +646,76 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RuleExists_DotnetDiagnosticEntry() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = warning - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = warning + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -705,73 +723,75 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_ConflitingDotnetDiagnosticEntry() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = error -dotnet_style_object_initializer = true:warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = error -dotnet_style_object_initializer = false:warning - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = error + dotnet_style_object_initializer = true:warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = error + dotnet_style_object_initializer = false:warning + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -779,76 +799,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_style_object_initializer = true:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_style_object_initializer = true:suggestion - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_style_object_initializer = true:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_style_object_initializer = true:suggestion + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -856,71 +878,73 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_MaintainSeverity_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = true:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = false:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = true:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = false:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -928,74 +952,76 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = false:suggestion - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = false:suggestion + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/EnumCodeStyleOptionConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/EnumCodeStyleOptionConfigurationTests.cs index c27aa92281903..fcb96080aa4e8 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/EnumCodeStyleOptionConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/EnumCodeStyleOptionConfigurationTests.cs @@ -51,47 +51,49 @@ public class UnusedLocalVariableConfigurationTests : EnumCodeStyleOptionConfigur [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_UnusedLocalVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = unused_local_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = unused_local_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -99,47 +101,49 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_UnusedLocalVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -csharp_style_unused_value_assignment_preference = discard_variable:suggestion ; Comment2 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion ; Comment2 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + csharp_style_unused_value_assignment_preference = discard_variable:suggestion ; Comment2 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion ; Comment2 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -147,50 +151,52 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RuleExists_DotnetDiagnosticEntry() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -dotnet_diagnostic.IDE0059.severity = warning ; Comment2 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -dotnet_diagnostic.IDE0059.severity = warning ; Comment2 - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = unused_local_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + dotnet_diagnostic.IDE0059.severity = warning ; Comment2 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + dotnet_diagnostic.IDE0059.severity = warning ; Comment2 + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = unused_local_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -198,49 +204,51 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RuleExists_ConflictingDotnetDiagnosticEntry() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -dotnet_diagnostic.IDE0059.severity = error ; Comment2 -csharp_style_unused_value_assignment_preference = discard_variable:suggestion ; Comment3 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] # Comment1 -dotnet_diagnostic.IDE0059.severity = error ; Comment2 -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion ; Comment3 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + dotnet_diagnostic.IDE0059.severity = error ; Comment2 + csharp_style_unused_value_assignment_preference = discard_variable:suggestion ; Comment3 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] # Comment1 + dotnet_diagnostic.IDE0059.severity = error ; Comment2 + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion ; Comment3 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -248,52 +256,54 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_UnusedLocalVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.vb] -csharp_style_unused_value_assignment_preference = discard_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.vb] -csharp_style_unused_value_assignment_preference = discard_variable:suggestion - -[*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = unused_local_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.vb] + csharp_style_unused_value_assignment_preference = discard_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.vb] + csharp_style_unused_value_assignment_preference = discard_variable:suggestion + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = unused_local_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -301,47 +311,49 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_MaintainSeverity_UnusedLocalVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.{vb,cs}] -csharp_style_unused_value_assignment_preference = discard_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.{vb,cs}] -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.{vb,cs}] + csharp_style_unused_value_assignment_preference = discard_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.{vb,cs}] + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -349,50 +361,52 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_UnusedLocalVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preferencer = discard_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preferencer = discard_variable:suggestion - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = unused_local_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preferencer = discard_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preferencer = discard_variable:suggestion + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = unused_local_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -406,47 +420,49 @@ public class DiscardVariableConfigurationTests : EnumCodeStyleOptionConfiguratio [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_DiscardVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -454,47 +470,49 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_DiscardVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference = discard_variable:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference = discard_variable:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -502,47 +520,49 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_DiscardVariable_WithoutSeveritySuffix() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference = unused_local_variable - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference = discard_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference = unused_local_variable + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference = discard_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -550,52 +570,54 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_DiscardVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.vb] -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.vb] -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion - -[*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.vb] + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.vb] + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -603,47 +625,49 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_MaintainSeverity_DiscardVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.{vb,cs}] -csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.{vb,cs}] -csharp_style_unused_value_assignment_preference = discard_variable:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.{vb,cs}] + csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.{vb,cs}] + csharp_style_unused_value_assignment_preference = discard_variable:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -651,50 +675,52 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_DiscardVariable() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - [|var obj = new Program1();|] - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference_error = discard_variable:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } - var obj = new Program1(); - obj = null; - var obj2 = obj; - } -} - - [*.cs] -csharp_style_unused_value_assignment_preference_error = discard_variable:suggestion - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + [|var obj = new Program1();|] + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference_error = discard_variable:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable } + var obj = new Program1(); + obj = null; + var obj2 = obj; + } + } + + [*.cs] + csharp_style_unused_value_assignment_preference_error = discard_variable:suggestion + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/MultipleCodeStyleOptionConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/MultipleCodeStyleOptionConfigurationTests.cs index e791d5118e320..ba197eb169117 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/MultipleCodeStyleOptionConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureCodeStyle/MultipleCodeStyleOptionConfigurationTests.cs @@ -56,43 +56,45 @@ public class VarElsewhere_TrueConfigurationTests : MultipleCodeStyleOptionConfig [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] - -# IDE0008: Use explicit type -csharp_style_var_elsewhere = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + + # IDE0008: Use explicit type + csharp_style_var_elsewhere = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -100,45 +102,47 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] # Comment1 -csharp_style_var_elsewhere = false:suggestion ; Comment2 -csharp_style_var_for_built_in_types = true:suggestion ; Comment3 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] # Comment1 -csharp_style_var_elsewhere = true:suggestion ; Comment2 -csharp_style_var_for_built_in_types = true:suggestion ; Comment3 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] # Comment1 + csharp_style_var_elsewhere = false:suggestion ; Comment2 + csharp_style_var_for_built_in_types = true:suggestion ; Comment3 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] # Comment1 + csharp_style_var_elsewhere = true:suggestion ; Comment2 + csharp_style_var_for_built_in_types = true:suggestion ; Comment3 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -146,45 +150,47 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_True_WithoutSeveritySuffix() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] # Comment1 -csharp_style_var_elsewhere = false ; Comment2 -csharp_style_var_for_built_in_types = true ; Comment3 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] # Comment1 -csharp_style_var_elsewhere = true ; Comment2 -csharp_style_var_for_built_in_types = true ; Comment3 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] # Comment1 + csharp_style_var_elsewhere = false ; Comment2 + csharp_style_var_for_built_in_types = true ; Comment3 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] # Comment1 + csharp_style_var_elsewhere = true ; Comment2 + csharp_style_var_for_built_in_types = true ; Comment3 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -192,48 +198,50 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.vb] -csharp_style_var_elsewhere = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.vb] -csharp_style_var_elsewhere = false:suggestion - -[*.cs] - -# IDE0008: Use explicit type -csharp_style_var_elsewhere = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.vb] + csharp_style_var_elsewhere = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.vb] + csharp_style_var_elsewhere = false:suggestion + + [*.cs] + + # IDE0008: Use explicit type + csharp_style_var_elsewhere = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -241,43 +249,45 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_MaintainSeverity_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.{vb,cs}] -csharp_style_var_elsewhere = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.{vb,cs}] -csharp_style_var_elsewhere = true:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.{vb,cs}] + csharp_style_var_elsewhere = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.{vb,cs}] + csharp_style_var_elsewhere = true:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -285,46 +295,48 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_True() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] -csharp_style_var_when_type_is_apparent_error = false:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] -csharp_style_var_when_type_is_apparent_error = false:suggestion - -# IDE0008: Use explicit type -csharp_style_var_elsewhere = true - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] + csharp_style_var_when_type_is_apparent_error = false:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + csharp_style_var_when_type_is_apparent_error = false:suggestion + + # IDE0008: Use explicit type + csharp_style_var_elsewhere = true + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -340,43 +352,45 @@ public class VarForBuiltInTypes_FalseConfigurationTests : MultipleCodeStyleOptio [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] - -# IDE0008: Use explicit type -csharp_style_var_for_built_in_types = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + + # IDE0008: Use explicit type + csharp_style_var_for_built_in_types = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -384,43 +398,45 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] -csharp_style_var_for_built_in_types = true:silent - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] -csharp_style_var_for_built_in_types = false:silent - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] + csharp_style_var_for_built_in_types = true:silent + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + csharp_style_var_for_built_in_types = false:silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -428,43 +444,45 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_RuleExists_False_WithoutSeveritySuffix() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] -csharp_style_var_for_built_in_types = true - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] -csharp_style_var_for_built_in_types = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] + csharp_style_var_for_built_in_types = true + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + csharp_style_var_for_built_in_types = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -472,48 +490,50 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.vb] -csharp_style_var_for_built_in_types = true:silent - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.vb] -csharp_style_var_for_built_in_types = true:silent - -[*.cs] - -# IDE0008: Use explicit type -csharp_style_var_for_built_in_types = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.vb] + csharp_style_var_for_built_in_types = true:silent + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.vb] + csharp_style_var_for_built_in_types = true:silent + + [*.cs] + + # IDE0008: Use explicit type + csharp_style_var_for_built_in_types = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -521,43 +541,45 @@ static void Main() [Fact] public async Task ConfigureEditorconfig_MaintainSeverity_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.{vb,cs}] -csharp_style_var_for_built_in_types = true:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.{vb,cs}] -csharp_style_var_for_built_in_types = false:suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.{vb,cs}] + csharp_style_var_for_built_in_types = true:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.{vb,cs}] + csharp_style_var_for_built_in_types = false:suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -565,46 +587,48 @@ static void Main() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_False() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - [|var obj = new Program1();|] - } -} - - [*.cs] -csharp_style_var_for_built_in_types_error = false:silent - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } - var obj = new Program1(); - } -} - - [*.cs] -csharp_style_var_for_built_in_types_error = false:silent - -# IDE0008: Use explicit type -csharp_style_var_for_built_in_types = false - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + [|var obj = new Program1();|] + } + } + + [*.cs] + csharp_style_var_for_built_in_types_error = false:silent + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // { csharp_style_var_when_type_is_apparent, csharp_style_var_for_built_in_types, csharp_style_var_elsewhere } + var obj = new Program1(); + } + } + + [*.cs] + csharp_style_var_for_built_in_types_error = false:silent + + # IDE0008: Use explicit type + csharp_style_var_for_built_in_types = false + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/AllAnalyzersSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/AllAnalyzersSeverityConfigurationTests.cs index 06ea38d95c237..4566de9c51b54 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/AllAnalyzersSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/AllAnalyzersSeverityConfigurationTests.cs @@ -65,29 +65,31 @@ public sealed class SilentConfigurationTests : AllAnalyzersSeverityConfiguration [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty() { - var input = @" - - - -[|class Program1 { }|] - - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -95,29 +97,31 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_RuleExists() { - var input = @" - - - -[|class Program1 { }|] - - [*.cs] -dotnet_analyzer_diagnostic.severity = suggestion # Comment - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] -dotnet_analyzer_diagnostic.severity = silent # Comment - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.cs] + dotnet_analyzer_diagnostic.severity = suggestion # Comment + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + dotnet_analyzer_diagnostic.severity = silent # Comment + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -125,34 +129,36 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_RuleIdEntryExists() { - var input = @" - - - -[|class Program1 { }|] - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment1 -dotnet_diagnostic.category-CustomCategory.severity = warning # Comment2 - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment1 -dotnet_diagnostic.category-CustomCategory.severity = warning # Comment2 - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment1 + dotnet_diagnostic.category-CustomCategory.severity = warning # Comment2 + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment1 + dotnet_diagnostic.category-CustomCategory.severity = warning # Comment2 + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -160,34 +166,36 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader() { - var input = @" - - - -[|class Program1 { }|] - - [*.vb] -dotnet_analyzer_diagnostic.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 { } - - [*.vb] -dotnet_analyzer_diagnostic.severity = suggestion - -[*.cs] - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.vb] + dotnet_analyzer_diagnostic.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.vb] + dotnet_analyzer_diagnostic.severity = suggestion + + [*.cs] + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -195,17 +203,18 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_MaintainExistingEntry() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, input, CodeActionIndex); } @@ -213,17 +222,18 @@ public async Task ConfigureEditorconfig_MaintainExistingEntry() [Fact] public async Task ConfigureEditorconfig_DiagnosticsSuppressed() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.severity = none + + + + """; await TestMissingInRegularAndScriptAsync(input); } @@ -231,32 +241,34 @@ public async Task ConfigureEditorconfig_DiagnosticsSuppressed() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.XYZ1111.severity = suggestion - - -"; - - var expected = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.XYZ1111.severity = suggestion - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.XYZ1111.severity = suggestion + + + + """; + + var expected = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.XYZ1111.severity = suggestion + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -266,36 +278,38 @@ public async Task ConfigureEditorconfig_RegexHeaderMatch() { // NOTE: Even though we have a regex match, bulk configuration code fix is always applied to all files // within the editorconfig cone, so it generates a new entry. - var input = @" - - - -[|class Program1 { }|] - - [*am/fi*e.cs] -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fi*e.cs] -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = warning - -[*.cs] - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fi*e.cs] + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fi*e.cs] + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = warning + + [*.cs] + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -303,36 +317,38 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RegexHeaderNonMatch() { - var input = @" - - - -[|class Program1 { }|] - - [*am/fii*e.cs] -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fii*e.cs] -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = warning - -[*.cs] - -# Default severity for all analyzer diagnostics -dotnet_analyzer_diagnostic.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fii*e.cs] + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fii*e.cs] + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = warning + + [*.cs] + + # Default severity for all analyzer diagnostics + dotnet_analyzer_diagnostic.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CSharpCodeStyleOptionBasedSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CSharpCodeStyleOptionBasedSeverityConfigurationTests.cs index 506540aaeb7ec..59bcee32a22c8 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CSharpCodeStyleOptionBasedSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CSharpCodeStyleOptionBasedSeverityConfigurationTests.cs @@ -37,48 +37,50 @@ public class ErrorConfigurationTests : CSharpCodeStyleOptionBasedSeverityConfigu [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_Error() { - var input = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - - - -"; - - var expected = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.cs] - -# IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = error - - -"; + var input = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + + + + + """; + + var expected = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + dotnet_diagnostic.IDE0059.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -86,53 +88,55 @@ public int Test() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ExistingRule_Error() { - var input = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable:warning -dotnet_diagnostic.IDE0059.severity = suggestion - - -"; - - var expected = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.cs] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable:error -dotnet_diagnostic.IDE0059.severity = error - - -"; + var input = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable:warning + dotnet_diagnostic.IDE0059.severity = suggestion + + + + """; + + var expected = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.cs] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable:error + dotnet_diagnostic.IDE0059.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -140,53 +144,55 @@ public int Test() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ExistingRuleDotNetHeader_Error() { - var input = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.{vb,cs}] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable:warning -dotnet_diagnostic.IDE0059.severity = suggestion - - -"; - - var expected = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.{vb,cs}] - -# IDE0059: Unnecessary assignment of a value -csharp_style_unused_value_assignment_preference = discard_variable:error -dotnet_diagnostic.IDE0059.severity = error - - -"; + var input = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.{vb,cs}] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable:warning + dotnet_diagnostic.IDE0059.severity = suggestion + + + + """; + + var expected = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.{vb,cs}] + + # IDE0059: Unnecessary assignment of a value + csharp_style_unused_value_assignment_preference = discard_variable:error + dotnet_diagnostic.IDE0059.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -194,56 +200,58 @@ public int Test() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ChooseBestHeader_Error() { - var input = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.cs] -csharp_style_expression_bodied_methods = false:silent - -[*.{vb,cs}] -dotnet_style_qualification_for_field = false:silent - - -"; - - var expected = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.cs] -csharp_style_expression_bodied_methods = false:silent - -# IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = error - -[*.{vb,cs}] -dotnet_style_qualification_for_field = false:silent - - -"; + var input = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + [*.{vb,cs}] + dotnet_style_qualification_for_field = false:silent + + + + """; + + var expected = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + # IDE0059: Unnecessary assignment of a value + dotnet_diagnostic.IDE0059.severity = error + + [*.{vb,cs}] + dotnet_style_qualification_for_field = false:silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -251,56 +259,58 @@ public int Test() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ChooseBestHeaderReversed_Error() { - var input = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.{vb,cs}] -dotnet_style_qualification_for_field = false:silent - -[*.cs] -csharp_style_expression_bodied_methods = false:silent - - -"; - - var expected = @" - - - -public class Class1 -{ - public int Test() - { - var o = 1; - // csharp_style_unused_value_assignment_preference = discard_variable - var [|unused|] = o; - return 1; - } -} - - [*.{vb,cs}] -dotnet_style_qualification_for_field = false:silent - -[*.cs] -csharp_style_expression_bodied_methods = false:silent - -# IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = error - - -"; + var input = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.{vb,cs}] + dotnet_style_qualification_for_field = false:silent + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + + + """; + + var expected = """ + + + + public class Class1 + { + public int Test() + { + var o = 1; + // csharp_style_unused_value_assignment_preference = discard_variable + var [|unused|] = o; + return 1; + } + } + + [*.{vb,cs}] + dotnet_style_qualification_for_field = false:silent + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + # IDE0059: Unnecessary assignment of a value + dotnet_diagnostic.IDE0059.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CategoryBasedSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CategoryBasedSeverityConfigurationTests.cs index e2dc58a6de683..aec1441474d4c 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CategoryBasedSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CategoryBasedSeverityConfigurationTests.cs @@ -65,29 +65,31 @@ public sealed class SilentConfigurationTests : CategoryBasedSeverityConfiguratio [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty() { - var input = @" - - - -[|class Program1 { }|] - - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -95,29 +97,31 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_RuleExists() { - var input = @" - - - -[|class Program1 { }|] - - [*.cs] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion # Comment - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent # Comment - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.cs] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion # Comment + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent # Comment + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -125,32 +129,34 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_RuleIdEntryExists() { - var input = @" - - - -[|class Program1 { }|] - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -158,34 +164,36 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader() { - var input = @" - - - -[|class Program1 { }|] - - [*.vb] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 { } - - [*.vb] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion - -[*.cs] - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.vb] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.vb] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = suggestion + + [*.cs] + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -193,17 +201,18 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_MaintainExistingEntry() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, input, CodeActionIndex); } @@ -211,17 +220,18 @@ public async Task ConfigureEditorconfig_MaintainExistingEntry() [Fact] public async Task ConfigureEditorconfig_DiagnosticsSuppressed() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.category-CustomCategory.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.category-CustomCategory.severity = none + + + + """; await TestMissingInRegularAndScriptAsync(input); } @@ -229,32 +239,34 @@ public async Task ConfigureEditorconfig_DiagnosticsSuppressed() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.category-XYZ1111Category.severity = suggestion - - -"; - - var expected = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_analyzer_diagnostic.category-XYZ1111Category.severity = suggestion - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.category-XYZ1111Category.severity = suggestion + + + + """; + + var expected = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_analyzer_diagnostic.category-XYZ1111Category.severity = suggestion + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -264,36 +276,38 @@ public async Task ConfigureEditorconfig_RegexHeaderMatch() { // NOTE: Even though we have a regex match, bulk configuration code fix is always applied to all files // within the editorconfig cone, so it generates a new entry. - var input = @" - - - -[|class Program1 { }|] - - [*am/fi*e.cs] -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fi*e.cs] -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning - -[*.cs] - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fi*e.cs] + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fi*e.cs] + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning + + [*.cs] + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -301,36 +315,38 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RegexHeaderNonMatch() { - var input = @" - - - -[|class Program1 { }|] - - [*am/fii*e.cs] -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fii*e.cs] -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning - -[*.cs] - -# Default severity for analyzer diagnostics with category 'CustomCategory' -dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fii*e.cs] + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fii*e.cs] + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = warning + + [*.cs] + + # Default severity for analyzer diagnostics with category 'CustomCategory' + dotnet_analyzer_diagnostic.category-CustomCategory.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CodeStyleOptionBasedSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CodeStyleOptionBasedSeverityConfigurationTests.cs index 976decdb7a9e3..00dbb723103d6 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CodeStyleOptionBasedSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/CodeStyleOptionBasedSeverityConfigurationTests.cs @@ -37,71 +37,73 @@ public class NoneConfigurationTests : CodeStyleOptionBasedSeverityConfigurationT [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_None() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = none - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -109,73 +111,75 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_None() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] # Comment1 -dotnet_style_object_initializer = true:suggestion ; Comment2 -dotnet_diagnostic.IDE0017.severity = suggestion ;; Comment3 - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] # Comment1 -dotnet_style_object_initializer = true:none ; Comment2 -dotnet_diagnostic.IDE0017.severity = none ;; Comment3 - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] # Comment1 + dotnet_style_object_initializer = true:suggestion ; Comment2 + dotnet_diagnostic.IDE0017.severity = suggestion ;; Comment3 + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] # Comment1 + dotnet_style_object_initializer = true:none ; Comment2 + dotnet_diagnostic.IDE0017.severity = none ;; Comment3 + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -183,76 +187,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_None() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_diagnostic.IDE0017.severity = suggestion - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = none - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_diagnostic.IDE0017.severity = suggestion + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -260,73 +266,75 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_MaintainOption_None() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = true:suggestion -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{vb,cs}] -dotnet_style_object_initializer = true:none -dotnet_diagnostic.IDE0017.severity = none - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = true:suggestion + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{vb,cs}] + dotnet_style_object_initializer = true:none + dotnet_diagnostic.IDE0017.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -334,76 +342,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_None() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = true:suggestion -dotnet_diagnostic.IDE0017.severityyy = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = true:suggestion -dotnet_diagnostic.IDE0017.severityyy = suggestion - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = none - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = true:suggestion + dotnet_diagnostic.IDE0017.severityyy = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = true:suggestion + dotnet_diagnostic.IDE0017.severityyy = suggestion + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -417,71 +427,73 @@ public class SilentConfigurationTests : CodeStyleOptionBasedSeverityConfiguratio [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_Silent() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = silent - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -489,71 +501,73 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_Silent() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = silent - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -567,71 +581,73 @@ public class SuggestionConfigurationTests : CodeStyleOptionBasedSeverityConfigur [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_Suggestion() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -639,73 +655,75 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_Suggestion() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:suggestion -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:suggestion + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -719,221 +737,227 @@ public class WarningConfigurationTests : CodeStyleOptionBasedSeverityConfigurati [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_Warning() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = warning + + + + """; - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - public Customer() - { + [Fact] + public async Task ConfigureEditorconfig_RuleExists_Warning() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - public Customer() + [Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)] + public class ErrorConfigurationTests : CodeStyleOptionBasedSeverityConfigurationTests { + protected override int CodeActionIndex => 4; - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [Fact] - public async Task ConfigureEditorconfig_RuleExists_Warning() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - } - - [Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)] - public class ErrorConfigurationTests : CodeStyleOptionBasedSeverityConfigurationTests - { - protected override int CodeActionIndex => 4; - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_Empty_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_Empty_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -941,74 +965,76 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RuleExists_CodeStyleBased_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:error - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:error + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -1016,827 +1042,849 @@ public Customer() [Fact] public async Task ConfigureEditorconfig_RuleExists_SeverityBased_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [Fact] - public async Task ConfigureEditorconfig_RuleExists_CodeStyleAndSeverityBased_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:suggestion -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = new Customer(); - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_InvalidHeader_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.vb] -dotnet_diagnostic.IDE0017.severity = suggestion - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_InvalidRule_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = true:warning -dotnet_diagnostic.IDE0017.severityyy = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializerr = true:warning -dotnet_diagnostic.IDE0017.severityyy = suggestion - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_ConcreteHeader_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_NestedDirectory_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_NestedDirectoryNestedHeader_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [ParentFolder/File.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [ParentFolder/File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_NestedDirectoryIncorrectHeader_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [ParentFolderr/File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [ParentFolderr/File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = warning - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; - - await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); - } - - [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_IncorrectExtension_Error() - { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.vb] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.vb] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - -[*.{cs,vb}] + } -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + [Fact] + public async Task ConfigureEditorconfig_RuleExists_CodeStyleAndSeverityBased_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:suggestion + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = new Customer(); + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_HeaderRegex_Error() + public async Task ConfigureEditorconfig_InvalidHeader_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.vb] + dotnet_diagnostic.IDE0017.severity = suggestion + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - } - } -} - - [Parent*r/Fil*.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_InvalidRule_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = true:warning + dotnet_diagnostic.IDE0017.severityyy = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializerr = true:warning + dotnet_diagnostic.IDE0017.severityyy = suggestion + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - internal class Customer - { - public int _age; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_ConcreteHeader_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; - public Customer() - { + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - } - } -} - - [Parent*r/Fil*.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_NestedDirectory_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } [ConditionalFact(typeof(IsEnglishLocal))] - public async Task ConfigureEditorconfig_HeaderAllFiles_Error() + public async Task ConfigureEditorconfig_NestedDirectoryNestedHeader_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [ParentFolder/File.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [ParentFolder/File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - internal class Customer - { - public int _age; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_NestedDirectoryIncorrectHeader_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [ParentFolderr/File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [ParentFolderr/File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = warning + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; - public Customer() - { + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - } - } -} - - [*] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_IncorrectExtension_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.vb] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.vb] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - internal class Customer - { - public int _age; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_HeaderRegex_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [Parent*r/Fil*.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [Parent*r/Fil*.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; - public Customer() - { + await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); + } - } - } -} - - [*] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; + [ConditionalFact(typeof(IsEnglishLocal))] + public async Task ConfigureEditorconfig_HeaderAllFiles_Error() + { + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -1844,103 +1892,105 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_MultipleHeaders_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.vb] -dotnet_diagnostic.IDE0017.severity = warning - -[File.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - -[cs.vb] -dotnet_diagnostic.IDE0017.severity = warning - -[test.test] -dotnet_diagnostic.IDE0017.severity = warning - -[WrongName.cs] -dotnet_diagnostic.IDE0017.severity = warning - -[WrongName2.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [File.vb] -dotnet_diagnostic.IDE0017.severity = warning - -[File.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - -[cs.vb] -dotnet_diagnostic.IDE0017.severity = warning - -[test.test] -dotnet_diagnostic.IDE0017.severity = warning - -[WrongName.cs] -dotnet_diagnostic.IDE0017.severity = warning - -[WrongName2.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.vb] + dotnet_diagnostic.IDE0017.severity = warning + + [File.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + [cs.vb] + dotnet_diagnostic.IDE0017.severity = warning + + [test.test] + dotnet_diagnostic.IDE0017.severity = warning + + [WrongName.cs] + dotnet_diagnostic.IDE0017.severity = warning + + [WrongName2.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [File.vb] + dotnet_diagnostic.IDE0017.severity = warning + + [File.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + [cs.vb] + dotnet_diagnostic.IDE0017.severity = warning + + [test.test] + dotnet_diagnostic.IDE0017.severity = warning + + [WrongName.cs] + dotnet_diagnostic.IDE0017.severity = warning + + [WrongName2.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -1948,76 +1998,78 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RegexPartialMatch_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [gram.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [gram.cs] -dotnet_diagnostic.IDE0017.severity = warning - -[*.{cs,vb}] - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [gram.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [gram.cs] + dotnet_diagnostic.IDE0017.severity = warning + + [*.{cs,vb}] + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -2025,71 +2077,73 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_VerifyCaseInsensitive_Warning() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [PROgram.cs] -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [PROgram.cs] -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [PROgram.cs] + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [PROgram.cs] + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -2097,81 +2151,83 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_DuplicateRule_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - -[Program.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - -[Program.cs] -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + [Program.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + [Program.cs] + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -2179,80 +2235,82 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ChooseBestHeader_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] -dotnet_style_qualification_for_field = false:silent - -[*.cs] -csharp_style_expression_bodied_methods = false:silent - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.{cs,vb}] -dotnet_style_qualification_for_field = false:silent - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - -[*.cs] -csharp_style_expression_bodied_methods = false:silent - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + dotnet_style_qualification_for_field = false:silent + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.{cs,vb}] + dotnet_style_qualification_for_field = false:silent + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -2260,80 +2318,82 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_ChooseBestHeaderReversed_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -csharp_style_expression_bodied_methods = false:silent - -[*.{cs,vb}] -dotnet_style_qualification_for_field = false:silent - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [*.cs] -csharp_style_expression_bodied_methods = false:silent - -[*.{cs,vb}] -dotnet_style_qualification_for_field = false:silent - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + [*.{cs,vb}] + dotnet_style_qualification_for_field = false:silent + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [*.cs] + csharp_style_expression_bodied_methods = false:silent + + [*.{cs,vb}] + dotnet_style_qualification_for_field = false:silent + + # IDE0017: Simplify object initialization + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -2341,77 +2401,79 @@ public Customer() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_DotFileName_Error() { - var input = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [Test.file.cs] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = true:warning -dotnet_diagnostic.IDE0017.severity = warning - - -"; - - var expected = @" - - - -class Program1 -{ - static void Main() - { - // dotnet_style_object_initializer = true - var obj = new Customer() { _age = 21 }; - - // dotnet_style_object_initializer = false - Customer obj2 = [|new Customer()|]; - obj2._age = 21; - } - - internal class Customer - { - public int _age; - - public Customer() - { - - } - } -} - - [Test.file.cs] - -# IDE0017: Simplify object initialization -dotnet_style_object_initializer = true:error -dotnet_diagnostic.IDE0017.severity = error - - -"; + var input = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [Test.file.cs] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = true:warning + dotnet_diagnostic.IDE0017.severity = warning + + + + """; + + var expected = """ + + + + class Program1 + { + static void Main() + { + // dotnet_style_object_initializer = true + var obj = new Customer() { _age = 21 }; + + // dotnet_style_object_initializer = false + Customer obj2 = [|new Customer()|]; + obj2._age = 21; + } + + internal class Customer + { + public int _age; + + public Customer() + { + + } + } + } + + [Test.file.cs] + + # IDE0017: Simplify object initialization + dotnet_style_object_initializer = true:error + dotnet_diagnostic.IDE0017.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/DotNetDiagnosticSeverityBasedSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/DotNetDiagnosticSeverityBasedSeverityConfigurationTests.cs index 9c7566315984e..2020941ec19ca 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/DotNetDiagnosticSeverityBasedSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/DotNetDiagnosticSeverityBasedSeverityConfigurationTests.cs @@ -59,29 +59,31 @@ public class NoneConfigurationTests : DotNetDiagnosticSeverityBasedSeverityConfi [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_None() { - var input = @" - - - -[|class Program1 { }|] - - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -89,29 +91,31 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_RuleExists_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment - - -"; - - var expected = @" - - - -class Program1 { } - - [*.cs] -dotnet_diagnostic.XYZ0001.severity = none # Comment - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.cs] + dotnet_diagnostic.XYZ0001.severity = none # Comment + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -119,34 +123,36 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidHeader_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.vb] -dotnet_diagnostic.XYZ0001.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 { } - - [*.vb] -dotnet_diagnostic.XYZ0001.severity = suggestion - -[*.cs] - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.vb] + dotnet_diagnostic.XYZ0001.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.vb] + dotnet_diagnostic.XYZ0001.severity = suggestion + + [*.cs] + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -154,17 +160,18 @@ class Program1 { } [Fact] public async Task ConfigureEditorconfig_MaintainExistingEntry_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestMissingInRegularAndScriptAsync(input); } @@ -172,32 +179,34 @@ public async Task ConfigureEditorconfig_MaintainExistingEntry_None() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_InvalidRule_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_diagnostic.XYZ1111.severity = none - - -"; - - var expected = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_diagnostic.XYZ1111.severity = none - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_diagnostic.XYZ1111.severity = none + + + + """; + + var expected = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_diagnostic.XYZ1111.severity = none + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -206,32 +215,34 @@ public async Task ConfigureEditorconfig_InvalidRule_None() [WorkItem("https://github.com/dotnet/roslyn/issues/45446")] public async Task ConfigureEditorconfig_MissingRule_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_diagnostic.severity = none - - -"; - - var expected = @" - - - -[|class Program1 { }|] - - [*.{vb,cs}] -dotnet_diagnostic.severity = none - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_diagnostic.severity = none + + + + """; + + var expected = """ + + + + [|class Program1 { }|] + + [*.{vb,cs}] + dotnet_diagnostic.severity = none + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -239,31 +250,33 @@ public async Task ConfigureEditorconfig_MissingRule_None() [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RegexHeaderMatch_None() { - var input = @" - - - -[|class Program1 { }|] - - [*am/fi*e.cs] -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fi*e.cs] -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fi*e.cs] + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fi*e.cs] + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -271,36 +284,38 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_RegexHeaderNonMatch_None() { - var input = @" - - - -[|class Program1 { }|] - - [*am/fii*e.cs] -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = warning - - -"; - - var expected = @" - - - -class Program1 { } - - [*am/fii*e.cs] -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = warning - -[*.cs] - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*am/fii*e.cs] + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = warning + + + + """; + + var expected = """ + + + + class Program1 { } + + [*am/fii*e.cs] + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = warning + + [*.cs] + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -308,29 +323,31 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureGlobalconfig_Empty_None() { - var input = @" - - - -[|class Program1 { }|] - - is_global = true - -"; - - var expected = @" - - - -class Program1 { } - - is_global = true - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + is_global = true + + + """; + + var expected = """ + + + + class Program1 { } + + is_global = true + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -338,29 +355,31 @@ class Program1 { } [Fact] public async Task ConfigureGlobalconfig_RuleExists_None() { - var input = @" - - - -[|class Program1 { }|] - - is_global = true # Comment -dotnet_diagnostic.XYZ0001.severity = suggestion # Comment - - -"; - - var expected = @" - - - -class Program1 { } - - is_global = true # Comment -dotnet_diagnostic.XYZ0001.severity = none # Comment - - -"; + var input = """ + + + + [|class Program1 { }|] + + is_global = true # Comment + dotnet_diagnostic.XYZ0001.severity = suggestion # Comment + + + + """; + + var expected = """ + + + + class Program1 { } + + is_global = true # Comment + dotnet_diagnostic.XYZ0001.severity = none # Comment + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -368,34 +387,36 @@ class Program1 { } [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureGlobalconfig_InvalidHeader_None() { - var input = @" - - - -[|class Program1 { }|] - - [*.vb] -dotnet_diagnostic.XYZ0001.severity = suggestion - - -"; - - var expected = @" - - - -class Program1 { } - - [*.vb] -dotnet_diagnostic.XYZ0001.severity = suggestion - -[*.cs] - -# XYZ0001: Title -dotnet_diagnostic.XYZ0001.severity = none - - -"; + var input = """ + + + + [|class Program1 { }|] + + [*.vb] + dotnet_diagnostic.XYZ0001.severity = suggestion + + + + """; + + var expected = """ + + + + class Program1 { } + + [*.vb] + dotnet_diagnostic.XYZ0001.severity = suggestion + + [*.cs] + + # XYZ0001: Title + dotnet_diagnostic.XYZ0001.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/MultipleCodeStyleOptionBasedSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/MultipleCodeStyleOptionBasedSeverityConfigurationTests.cs index de6a5e366ce19..afd257fe10017 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/MultipleCodeStyleOptionBasedSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/MultipleCodeStyleOptionBasedSeverityConfigurationTests.cs @@ -39,69 +39,71 @@ public class ErrorConfigurationTests : MultipleCodeStyleOptionBasedSeverityConfi [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_Empty_Error() { - var input = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { [|RuleName|] = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - - -"; - - var expected = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { RuleName = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = error - - -"; + var input = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { [|RuleName|] = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + + + + """; + + var expected = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { RuleName = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_diagnostic.IDE0037.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -110,82 +112,84 @@ static void Main(string[] args) [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_BothRulesExist_Error() { - var input = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { [|RuleName|] = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_tuple_names = true:suggestion - - -"; - - var expected = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { RuleName = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:error - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_tuple_names = true:error - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = error - - -"; + var input = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { [|RuleName|] = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_tuple_names = true:suggestion + + + + """; + + var expected = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { RuleName = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:error + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_tuple_names = true:error + + # IDE0037: Use inferred member name + dotnet_diagnostic.IDE0037.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -194,76 +198,78 @@ static void Main(string[] args) [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_OneRuleExists_Error() { - var input = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { [|RuleName|] = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning - - -"; - - var expected = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { RuleName = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:error - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = error - - -"; + var input = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { [|RuleName|] = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning + + + + """; + + var expected = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { RuleName = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:error + + # IDE0037: Use inferred member name + dotnet_diagnostic.IDE0037.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } @@ -272,85 +278,87 @@ static void Main(string[] args) [ConditionalFact(typeof(IsEnglishLocal))] public async Task ConfigureEditorconfig_AllPossibleEntriesExist_Error() { - var input = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { [|RuleName|] = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_tuple_names = true:suggestion - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = silent - - -"; - - var expected = @" - - - -using System; - -namespace ConsoleApp5 -{ - class Foo - { - public string RuleName = ""test""; - } - - class Bar - { - static void Main(string[] args) - { - var foo = new Foo(); - - var bar = new { RuleName = foo.RuleName }; - - Console.WriteLine(bar.RuleName); - } - } -} - - [*.{cs,vb}] - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_anonymous_type_member_names = true:error - -# IDE0037: Use inferred member name -dotnet_style_prefer_inferred_tuple_names = true:error - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = error - - -"; + var input = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { [|RuleName|] = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_tuple_names = true:suggestion + + # IDE0037: Use inferred member name + dotnet_diagnostic.IDE0037.severity = silent + + + + """; + + var expected = """ + + + + using System; + + namespace ConsoleApp5 + { + class Foo + { + public string RuleName = "test"; + } + + class Bar + { + static void Main(string[] args) + { + var foo = new Foo(); + + var bar = new { RuleName = foo.RuleName }; + + Console.WriteLine(bar.RuleName); + } + } + } + + [*.{cs,vb}] + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_anonymous_type_member_names = true:error + + # IDE0037: Use inferred member name + dotnet_style_prefer_inferred_tuple_names = true:error + + # IDE0037: Use inferred member name + dotnet_diagnostic.IDE0037.severity = error + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/VarForBuiltInTypesSeverityConfigurationTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/VarForBuiltInTypesSeverityConfigurationTests.cs index 6912aba4e8f08..fe1c2c9d52191 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/VarForBuiltInTypesSeverityConfigurationTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Configuration/ConfigureSeverity/VarForBuiltInTypesSeverityConfigurationTests.cs @@ -36,33 +36,35 @@ public async Task MaintainValue() Assert.False(CSharpCodeStyleOptions.VarForBuiltInTypes.DefaultValue.Value); Assert.Equal(NotificationOption2.Silent, CSharpCodeStyleOptions.VarForBuiltInTypes.DefaultValue.Notification); - var input = @" - - - -[|int|] x = 1; - - -[*.cs] -csharp_style_var_for_built_in_types = true:suggestion -dotnet_diagnostic.IDE0007.severity = suggestion - - -"; + var input = """ + + + + [|int|] x = 1; + + + [*.cs] + csharp_style_var_for_built_in_types = true:suggestion + dotnet_diagnostic.IDE0007.severity = suggestion + + + + """; - var expected = @" - - - -int x = 1; - - -[*.cs] -csharp_style_var_for_built_in_types = true:none -dotnet_diagnostic.IDE0007.severity = none - - -"; + var expected = """ + + + + int x = 1; + + + [*.cs] + csharp_style_var_for_built_in_types = true:none + dotnet_diagnostic.IDE0007.severity = none + + + + """; await TestInRegularAndScriptAsync(input, expected, CodeActionIndex); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs index b6ef1762a8f4b..d95932e494656 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs @@ -75,15 +75,15 @@ public async Task DiagnosticAnalyzerDriverAllInOne() public async Task DiagnosticAnalyzerDriverVsAnalyzerDriverOnCodeBlock() { var methodNames = new string[] { "Initialize", "AnalyzeCodeBlock" }; - var source = @" -[System.Obsolete] -class C -{ - int P { get; set; } - delegate void A(); - delegate string F(); -} -"; + var source = """ + [System.Obsolete] + class C + { + int P { get; set; } + delegate void A(); + delegate string F(); + } + """; var ideEngineAnalyzer = new CSharpTrackingDiagnosticAnalyzer(); using (var ideEngineWorkspace = TestWorkspace.CreateCSharp(source, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService)) @@ -244,16 +244,16 @@ public static void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context) [Fact] public async Task CodeBlockAnalyzersOnlyAnalyzeExecutableCode() { - var source = @" -using System; -class C -{ - void F(int x = 0) - { - Console.WriteLine(0); - } -} -"; + var source = """ + using System; + class C + { + void F(int x = 0) + { + Console.WriteLine(0); + } + } + """; var analyzer = new CodeBlockAnalyzerFactory(); using (var ideEngineWorkspace = TestWorkspace.CreateCSharp(source, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService)) @@ -267,16 +267,16 @@ void F(int x = 0) Assert.Equal(2, diagnosticsFromAnalyzer.Count()); } - source = @" -using System; -class C -{ - void F(int x = 0, int y = 1, int z = 2) - { - Console.WriteLine(0); - } -} -"; + source = """ + using System; + class C + { + void F(int x = 0, int y = 1, int z = 2) + { + Console.WriteLine(0); + } + } + """; using (var compilerEngineWorkspace = TestWorkspace.CreateCSharp(source, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService)) { diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs index 7e1547e70afd6..2a466108f6ec8 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/FixAllProvider/BatchFixerTests.cs @@ -102,57 +102,59 @@ public override FixAllProvider GetFixAllProvider() [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInDocument_QualifyWithThis() { - var input = @" - - - -class C -{ - int Sign; - void F() - { - string x = @""namespace Namespace - { - class Type - { - void Goo() - { - int x = 1 "" + {|FixAllInDocument:Sign|} + @"" "" + Sign + @""3; - } - } - } -""; - } -} - - -"; - - var expected = @" - - - -class C -{ - int Sign; - void F() - { - string x = @""namespace Namespace - { - class Type - { - void Goo() - { - int x = 1 "" + this.Sign + @"" "" + this.Sign + @""3; - } - } - } -""; - } -} - - -"; + var input = """ + + + + class C + { + int Sign; + void F() + { + string x = @"namespace Namespace + { + class Type + { + void Goo() + { + int x = 1 " + {|FixAllInDocument:Sign|} + @" " + Sign + @"3; + } + } + } + "; + } + } + + + + """; + + var expected = """ + + + + class C + { + int Sign; + void F() + { + string x = @"namespace Namespace + { + class Type + { + void Goo() + { + int x = 1 " + this.Sign + @" " + this.Sign + @"3; + } + } + } + "; + } + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixAllTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixAllTests.cs index e82dce423ae68..a3aaead8ceeda 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixAllTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixAllTests.cs @@ -26,95 +26,97 @@ public partial class UserInfoDiagnosticSuppressionTests : CSharpPragmaWarningDis [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInDocument() { - var input = @" - - - -using System; - -{|FixAllInDocument:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} -class Class3 { } - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; - - var expected = @" - - - -using System; - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method() - { - int x = 0; - } -} - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class2 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class3 { } -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInDocument:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + class Class3 { } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; + + var expected = """ + + + + using System; + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method() + { + int x = 0; + } + } + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class2 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class3 { } + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } @@ -123,93 +125,95 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInProject() { - var input = @" - - - -using System; - -{|FixAllInProject:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; - - var expected = @" - - - -using System; - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method() - { - int x = 0; - } -} - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class2 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} - - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class3 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInProject:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; + + var expected = """ + + + + using System; + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method() + { + int x = 0; + } + } + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class2 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class3 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } @@ -218,97 +222,99 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInSolution() { - var input = @" - - - -using System; - -{|FixAllInSolution:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; - - var expected = @" - - - -using System; - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method() - { - int x = 0; - } -} - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class2 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} - - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class3 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} - - - - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method() - { - int x = 0; - } -} - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -class Class2 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInSolution:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; + + var expected = """ + + + + using System; + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method() + { + int x = 0; + } + } + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class2 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class3 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + + + + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method() + { + int x = 0; + } + } + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + class Class2 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } @@ -317,27 +323,28 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInContainingMember() { - var input = @" - - - -using System; - -{|FixAllInContainingMember:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} -class Class3 { } - - -"; + var input = """ + + + + using System; + + {|FixAllInContainingMember:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + class Class3 { } + + + + """; await TestMissingInRegularAndScriptAsync(input); } @@ -346,93 +353,95 @@ class Class3 { } [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInContainingType() { - var input = @" - - - -using System; - -{|FixAllInContainingType:partial class Class1|} -{ - int Method1() - { - int x = 0; - } -} - -class Class2 -{ - int Method2() - { - int x = 0; - } -} - - -partial class Class1 -{ - int Method3() - { - int x = 0; - } -} - -class Class4 -{ - int Method4() - { - int x = 0; - } -} - - -"; - - var expected = @" - - - -using System; - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -partial class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method1() - { - int x = 0; - } -} - -class Class2 -{ - int Method2() - { - int x = 0; - } -} - - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -partial class Class1 -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method3() - { - int x = 0; - } -} - -class Class4 -{ - int Method4() - { - int x = 0; - } -} - - -"; + var input = """ + + + + using System; + + {|FixAllInContainingType:partial class Class1|} + { + int Method1() + { + int x = 0; + } + } + + class Class2 + { + int Method2() + { + int x = 0; + } + } + + + partial class Class1 + { + int Method3() + { + int x = 0; + } + } + + class Class4 + { + int Method4() + { + int x = 0; + } + } + + + + """; + + var expected = """ + + + + using System; + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + partial class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method1() + { + int x = 0; + } + } + + class Class2 + { + int Method2() + { + int x = 0; + } + } + + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + partial class Class1 + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method3() + { + int x = 0; + } + } + + class Class4 + { + int Method4() + { + int x = 0; + } + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } @@ -451,46 +460,47 @@ public partial class UserInfoDiagnosticSuppressionTests : CSharpGlobalSuppressMe [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInDocument() { - var input = @" - - - -using System; - -{|FixAllInDocument:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInDocument:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; var addedGlobalSuppressions = $@"// This file is used by Code Analysis to maintain SuppressMessage @@ -506,48 +516,51 @@ class Class2 " .Replace("<", "<").Replace(">", ">"); - var expected = @" - - - -using System; - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} + var expected = """ + + + + using System; + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + """ + addedGlobalSuppressions + + """ - -class Class3 -{ -} - - " + addedGlobalSuppressions + - @" - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} + + + + class Class1 + { + int Method() + { + int x = 0; + } + } -class Class2 -{ -} - - -"; + class Class2 + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected, index: 1); } @@ -556,46 +569,47 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInProject() { - var input = @" - - - -using System; - -{|FixAllInProject:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInProject:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; var addedGlobalSuppressions = $@"// This file is used by Code Analysis to maintain SuppressMessage @@ -612,48 +626,51 @@ class Class2 " .Replace("<", "<").Replace(">", ">"); - var expected = @" - - - -using System; - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} + var expected = """ + + + + using System; + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + """ + addedGlobalSuppressions + + """ - " + addedGlobalSuppressions + - @" - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} + + + + class Class1 + { + int Method() + { + int x = 0; + } + } -class Class2 -{ -} - - -"; + class Class2 + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected, index: 1); } @@ -662,46 +679,47 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInSolution() { - var input = @" - - - -using System; - -{|FixAllInSolution:class Class1|} -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInSolution:class Class1|} + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; var addedGlobalSuppressionsProject1 = $@"// This file is used by Code Analysis to maintain SuppressMessage @@ -732,50 +750,55 @@ class Class2 ".Replace("<", "<").Replace(">", ">"); - var expected = @" - - - -using System; - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} + var expected = """ + + + + using System; + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + """ + addedGlobalSuppressionsProject1 + + """ - -class Class3 -{ -} - - " + addedGlobalSuppressionsProject1 + - @" - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} + + + + class Class1 + { + int Method() + { + int x = 0; + } + } -class Class2 -{ -} + class Class2 + { + } + + + """ + addedGlobalSuppressionsProject2 + + """ - " + addedGlobalSuppressionsProject2 + - @" - -"; + + + """; await TestInRegularAndScriptAsync(input, expected); } @@ -784,26 +807,27 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInContainingMember() { - var input = @" - - - -using System; - -{|FixAllInContainingMember:class Class1|} -{ - int Method1() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInContainingMember:class Class1|} + { + int Method1() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; await TestMissingInRegularAndScriptAsync(input); } @@ -812,39 +836,40 @@ class Class2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInContainingType() { - var input = @" - - - -using System; - -{|FixAllInContainingType:partial class Class1|} -{ - int Method1() - { - int x = 0; - } -} - -class Class2 -{ -} - - -partial class Class1 -{ - int Method2() - { - int x = 0; - } -} - -class Class3 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInContainingType:partial class Class1|} + { + int Method1() + { + int x = 0; + } + } + + class Class2 + { + } + + + partial class Class1 + { + int Method2() + { + int x = 0; + } + } + + class Class3 + { + } + + + + """; var addedGlobalSuppressions = $@"// This file is used by Code Analysis to maintain SuppressMessage @@ -860,41 +885,44 @@ class Class3 " .Replace("<", "<").Replace(">", ">"); - var expected = @" - - - -using System; - -partial class Class1 -{ - int Method1() - { - int x = 0; - } -} - -class Class2 -{ -} - - -partial class Class1 -{ - int Method2() - { - int x = 0; - } -} - -class Class3 -{ -} + var expected = """ + + + + using System; + + partial class Class1 + { + int Method1() + { + int x = 0; + } + } + + class Class2 + { + } + + + partial class Class1 + { + int Method2() + { + int x = 0; + } + } + + class Class3 + { + } + + + """ + addedGlobalSuppressions + + """ - " + addedGlobalSuppressions + - @" - -"; + + + """; await TestInRegularAndScriptAsync(input, expected, index: 1); } @@ -908,46 +936,47 @@ public partial class CSharpDiagnosticWithoutLocationSuppressionTests : CSharpSup [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInProject() { - var input = @" - - - {|FixAllInProject:|} -using System; - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + {|FixAllInProject:|} + using System; + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; var addedGlobalSuppressions = $@"// This file is used by Code Analysis to maintain SuppressMessage @@ -961,48 +990,51 @@ class Class2 " .Replace("<", "<").Replace(">", ">"); - var expected = @" - - - -using System; - -class Class1 -{ - int Method() + var expected = """ + + + + using System; + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + class Class3 + { + } + + + """ + addedGlobalSuppressions + + """ + + + + + class Class1 { - int x = 0; + int Method() + { + int x = 0; + } } -} -class Class2 -{ -} - - -class Class3 -{ -} - - " + addedGlobalSuppressions + - @" - - - -class Class1 -{ - int Method() + class Class2 { - int x = 0; } -} - -class Class2 -{ -} - - -"; + + + + """; await TestInRegularAndScriptAsync(input, expected); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixMultipleTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixMultipleTests.cs index 591056312f3b3..e025f43c3254a 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixMultipleTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTest_FixMultipleTests.cs @@ -64,97 +64,99 @@ public class CSharpFixMultiplePragmaWarningSuppressionTests : CSharpFixMultipleS [WorkItem("https://github.com/dotnet/roslyn/issues/6455")] public async Task TestFixMultipleInDocument() { - var input = @" - - - -using System; - -{|FixAllInSelection:class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -}|} -class Class3 { } - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; - - var expected = @" - - - -using System; - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -#pragma warning disable InfoDiagnostic2 // InfoDiagnostic2 Title -class Class1 -#pragma warning restore InfoDiagnostic2 // InfoDiagnostic2 Title -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ - int Method() - { - int x = 0; - } -} - -#pragma warning disable InfoDiagnostic // InfoDiagnostic Title -#pragma warning disable InfoDiagnostic2 // InfoDiagnostic2 Title -class Class2 -#pragma warning restore InfoDiagnostic2 // InfoDiagnostic2 Title -#pragma warning restore InfoDiagnostic // InfoDiagnostic Title -{ -} -class Class3 { } - - -class Class3 -{ -} - - - - -class Class1 -{ - int Method() - { - int x = 0; - } -} - -class Class2 -{ -} - - -"; + var input = """ + + + + using System; + + {|FixAllInSelection:class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + }|} + class Class3 { } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; + + var expected = """ + + + + using System; + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + #pragma warning disable InfoDiagnostic2 // InfoDiagnostic2 Title + class Class1 + #pragma warning restore InfoDiagnostic2 // InfoDiagnostic2 Title + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + int Method() + { + int x = 0; + } + } + + #pragma warning disable InfoDiagnostic // InfoDiagnostic Title + #pragma warning disable InfoDiagnostic2 // InfoDiagnostic2 Title + class Class2 + #pragma warning restore InfoDiagnostic2 // InfoDiagnostic2 Title + #pragma warning restore InfoDiagnostic // InfoDiagnostic Title + { + } + class Class3 { } + + + class Class3 + { + } + + + + + class Class1 + { + int Method() + { + int x = 0; + } + } + + class Class2 + { + } + + + + """; await TestInRegularAndScriptAsync(input, expected); } diff --git a/src/EditorFeatures/CSharpTest/DocumentationComments/XmlTagCompletionTests.cs b/src/EditorFeatures/CSharpTest/DocumentationComments/XmlTagCompletionTests.cs index a43a8d883e71a..f939048b42e1c 100644 --- a/src/EditorFeatures/CSharpTest/DocumentationComments/XmlTagCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/DocumentationComments/XmlTagCompletionTests.cs @@ -26,13 +26,15 @@ private protected override TestWorkspace CreateTestWorkspace(string initialMarku [WpfFact] public void SimpleTagCompletion() { - var text = @" -/// $$ -class c { }"; + var expected = """ + /// $$ + class c { } + """; Verify(text, expected, '>'); } @@ -40,17 +42,19 @@ class c { }"; [WpfFact] public void NestedTagCompletion() { - var text = @" -/// -/// -class c { }"; - - var expected = @" -/// -/// $$ -/// -class c { }"; + var text = """ + /// + /// + class c { } + """; + + var expected = """ + /// + /// $$ + /// + class c { } + """; Verify(text, expected, '>'); } @@ -58,15 +62,17 @@ class c { }"; [WpfFact] public void CompleteBeforeIncompleteTag() { - var text = @" -/// -class c { }"; - - var expected = @" -/// $$ -/// -class c { }"; + var text = """ + /// + class c { } + """; + + var expected = """ + /// $$ + /// + class c { } + """; Verify(text, expected, '>'); } @@ -74,13 +80,15 @@ class c { }"; [WpfFact] public void NotEmptyElement() { - var text = @" -/// <$$ -class c { }"; + var text = """ + /// <$$ + class c { } + """; - var expected = @" -/// <>$$ -class c { }"; + var expected = """ + /// <>$$ + class c { } + """; Verify(text, expected, '>'); } @@ -88,13 +96,15 @@ class c { }"; [WpfFact] public void NotAlreadyCompleteTag() { - var text = @" -/// -class c { }"; + var text = """ + /// + class c { } + """; - var expected = @" -/// $$ -class c { }"; + var expected = """ + /// $$ + class c { } + """; Verify(text, expected, '>'); } @@ -102,17 +112,19 @@ class c { }"; [WpfFact] public void NotAlreadyCompleteTag2() { - var text = @" -/// -class c { }"; - - var expected = @" -/// $$ -/// -/// -class c { }"; + var text = """ + /// + class c { } + """; + + var expected = """ + /// $$ + /// + /// + class c { } + """; Verify(text, expected, '>'); } @@ -120,13 +132,15 @@ class c { }"; [WpfFact] public void SimpleSlashCompletion() { - var text = @" -/// <$$ -class c { }"; + var text = """ + /// <$$ + class c { } + """; - var expected = @" -/// $$ -class c { }"; + var expected = """ + /// $$ + class c { } + """; Verify(text, expected, '/'); } @@ -134,17 +148,19 @@ class c { }"; [WpfFact] public void NestedSlashTagCompletion() { - var text = @" -/// -/// <$$ -/// -class c { }"; - - var expected = @" -/// -/// $$ -/// -class c { }"; + var text = """ + /// + /// <$$ + /// + class c { } + """; + + var expected = """ + /// + /// $$ + /// + class c { } + """; Verify(text, expected, '/'); } @@ -152,15 +168,17 @@ class c { }"; [WpfFact] public void SlashCompleteBeforeIncompleteTag() { - var text = @" -/// <$$ -/// -class c { }"; - - var expected = @" -/// $$ -/// -class c { }"; + var text = """ + /// <$$ + /// + class c { } + """; + + var expected = """ + /// $$ + /// + class c { } + """; Verify(text, expected, '/'); } @@ -168,13 +186,15 @@ class c { }"; [WpfFact] public void SlashNotEmptyElement() { - var text = @" -/// <><$$ -class c { }"; + var text = """ + /// <><$$ + class c { } + """; - var expected = @" -/// <><$$goo> -class c { }"; + var text = """ + /// <$$goo> + class c { } + """; - var expected = @" -/// -class c { }"; + var expected = """ + /// + class c { } + """; Verify(text, expected, '/'); } @@ -196,17 +218,19 @@ class c { }"; [WpfFact] public void SlashNotAlreadyCompleteTag2() { - var text = @" -/// -/// -/// <$$goo> -class c { }"; - - var expected = @" -/// -/// -/// -class c { }"; + var text = """ + /// + /// + /// <$$goo> + class c { } + """; + + var expected = """ + /// + /// + /// + class c { } + """; Verify(text, expected, '/'); } @@ -214,13 +238,15 @@ class c { }"; [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/638800")] public void NestedIdenticalTags() { - var text = @" -/// -class c { }"; + var text = """ + /// + class c { } + """; - var expected = @" -/// $$ -class c { }"; + var expected = """ + /// $$ + class c { } + """; Verify(text, expected, '>'); } @@ -228,13 +254,15 @@ class c { }"; [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/638800")] public void MultipleNestedIdenticalTags() { - var text = @" -/// -class c { }"; + var text = """ + /// + class c { } + """; - var expected = @" -/// $$ -class c { }"; + var expected = """ + /// $$ + class c { } + """; Verify(text, expected, '>'); } @@ -242,17 +270,19 @@ class c { }"; [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/638235")] public void SlashNotIfCloseTagFollows() { - var text = @" -/// -/// <$$ -/// -class c { }"; - - var expected = @" -/// -/// -class c { }"; + var text = """ + /// + /// <$$ + /// + class c { } + """; + + var expected = """ + /// + /// + class c { } + """; Verify(text, expected, '/'); } @@ -260,13 +290,15 @@ class c { }"; [WpfFact] public void TestSimpleTagCompletion() { - var text = @" -/// $$ -class C {}"; + var expected = """ + /// $$ + class C {} + """; Verify(text, expected, '>'); } @@ -274,17 +306,19 @@ class C {}"; [WpfFact] public void TestNestedTagCompletion() { - var text = @" -/// -/// -class C {}"; - - var expected = @" -/// -/// $$ -/// -class C {}"; + var text = """ + /// + /// + class C {} + """; + + var expected = """ + /// + /// $$ + /// + class C {} + """; Verify(text, expected, '>'); } @@ -292,15 +326,17 @@ class C {}"; [WpfFact] public void TestCompleteBeforeIncompleteTag() { - var text = @" -/// -class C {}"; - - var expected = @" -/// $$ -/// -class C {}"; + var text = """ + /// + class C {} + """; + + var expected = """ + /// $$ + /// + class C {} + """; Verify(text, expected, '>'); } @@ -308,13 +344,15 @@ class C {}"; [WpfFact] public void TestNotEmptyElement() { - var text = @" -/// <$$ -class C {}"; + var text = """ + /// <$$ + class C {} + """; - var expected = @" -/// <>$$ -class C {}"; + var expected = """ + /// <>$$ + class C {} + """; Verify(text, expected, '>'); } @@ -322,13 +360,15 @@ class C {}"; [WpfFact] public void TestNotAlreadyCompleteTag() { - var text = @" -/// -class C {}"; + var text = """ + /// + class C {} + """; - var expected = @" -/// $$ -class C {}"; + var expected = """ + /// $$ + class C {} + """; Verify(text, expected, '>'); } @@ -336,17 +376,19 @@ class C {}"; [WpfFact] public void TestNotAlreadyCompleteTag2() { - var text = @" -/// -class C {}"; - - var expected = @" -/// $$ -/// -/// -class C {}"; + var text = """ + /// + class C {} + """; + + var expected = """ + /// $$ + /// + /// + class C {} + """; Verify(text, expected, '>'); } @@ -354,17 +396,19 @@ class C {}"; [WpfFact] public void TestNotOutsideDocComment() { - var text = @" -class C -{ - private int z = $$ -}"; + var text = """ + class C + { + private int z = $$ + } + """; Verify(text, expected, '>'); } @@ -372,17 +416,19 @@ class C [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/638235")] public void TestNotCloseClosedTag() { - var text = @" -/// -/// <$$ -/// -class C {}"; - - var expected = @" -/// -/// -class C {}"; + var text = """ + /// + /// <$$ + /// + class C {} + """; + + var expected = """ + /// + /// + class C {} + """; Verify(text, expected, '/'); } diff --git a/src/EditorFeatures/CSharpTest/EncapsulateField/EncapsulateFieldCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/EncapsulateField/EncapsulateFieldCommandHandlerTests.cs index 07f2c043e31a3..c8cfe9b76ad51 100644 --- a/src/EditorFeatures/CSharpTest/EncapsulateField/EncapsulateFieldCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/EncapsulateField/EncapsulateFieldCommandHandlerTests.cs @@ -24,39 +24,41 @@ public class EncapsulateFieldCommandHandlerTests [WpfFact, Trait(Traits.Feature, Traits.Features.EncapsulateField)] public async Task EncapsulatePrivateField() { - var text = @" -class C -{ - private int f$$ield; - - private void goo() - { - field = 3; - } -}"; - var expected = @" -class C -{ - private int field; - - public int Field - { - get - { - return field; - } + var text = """ + class C + { + private int f$$ield; + + private void goo() + { + field = 3; + } + } + """; + var expected = """ + class C + { + private int field; + + public int Field + { + get + { + return field; + } - set - { - field = value; - } - } + set + { + field = value; + } + } - private void goo() - { - Field = 3; - } -}"; + private void goo() + { + Field = 3; + } + } + """; using var state = EncapsulateFieldTestState.Create(text); await state.AssertEncapsulateAsAsync(expected); @@ -65,39 +67,41 @@ private void goo() [WpfFact, Trait(Traits.Feature, Traits.Features.EncapsulateField)] public async Task EncapsulateNonPrivateField() { - var text = @" -class C -{ - protected int fi$$eld; - - private void goo() - { - field = 3; - } -}"; - var expected = @" -class C -{ - private int field; + var text = """ + class C + { + protected int fi$$eld; + + private void goo() + { + field = 3; + } + } + """; + var expected = """ + class C + { + private int field; + + protected int Field + { + get + { + return field; + } - protected int Field - { - get - { - return field; - } + set + { + field = value; + } + } - set - { - field = value; - } - } - - private void goo() - { - Field = 3; - } -}"; + private void goo() + { + Field = 3; + } + } + """; using var state = EncapsulateFieldTestState.Create(text); await state.AssertEncapsulateAsAsync(expected); @@ -106,16 +110,17 @@ private void goo() [WpfFact, Trait(Traits.Feature, Traits.Features.EncapsulateField)] public async Task DialogShownIfNotFieldsFound() { - var text = @" -class$$ C -{ - private int field; - - private void goo() - { - field = 3; - } -}"; + var text = """ + class$$ C + { + private int field; + + private void goo() + { + field = 3; + } + } + """; using var state = EncapsulateFieldTestState.Create(text); await state.AssertErrorAsync(); @@ -125,58 +130,58 @@ private void goo() [WpfFact, Trait(Traits.Feature, Traits.Features.EncapsulateField)] public async Task EncapsulateTwoFields() { - var text = @" -class Program -{ - [|static int A = 1; - static int B = A;|] - - static void Main(string[] args) - { - System.Console.WriteLine(A); - System.Console.WriteLine(B); - } -} -"; - var expected = @" -class Program -{ - static int A = 1; - static int B = A1; - - public static int A1 - { - get - { - return A; - } + var text = """ + class Program + { + [|static int A = 1; + static int B = A;|] + + static void Main(string[] args) + { + System.Console.WriteLine(A); + System.Console.WriteLine(B); + } + } + """; + var expected = """ + class Program + { + static int A = 1; + static int B = A1; + + public static int A1 + { + get + { + return A; + } - set - { - A = value; - } - } + set + { + A = value; + } + } - public static int B1 - { - get - { - return B; - } + public static int B1 + { + get + { + return B; + } - set - { - B = value; - } - } + set + { + B = value; + } + } - static void Main(string[] args) - { - System.Console.WriteLine(A1); - System.Console.WriteLine(B1); - } -} -"; + static void Main(string[] args) + { + System.Console.WriteLine(A1); + System.Console.WriteLine(B1); + } + } + """; using var state = EncapsulateFieldTestState.Create(text); await state.AssertEncapsulateAsAsync(expected); @@ -187,15 +192,16 @@ static void Main(string[] args) [Trait(Traits.Feature, Traits.Features.Interactive)] public void EncapsulateFieldCommandDisabledInSubmission() { - using var workspace = TestWorkspace.Create(XElement.Parse(@" + using var workspace = TestWorkspace.Create(XElement.Parse(""" - + class C { object $$goo; } - "), + + """), workspaceKind: WorkspaceKind.Interactive, composition: EditorTestCompositions.EditorFeaturesWpf); // Force initialization. diff --git a/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs b/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs index 795994e817064..4b8c338a718f0 100644 --- a/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs +++ b/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs @@ -48,12 +48,13 @@ public static EventHookupTestState CreateTestState(string markup, OptionsCollect => new EventHookupTestState(GetWorkspaceXml(markup), options); public static XElement GetWorkspaceXml(string markup) - => XElement.Parse(string.Format(@" - - - {0} - -", markup)); + => XElement.Parse(string.Format(""" + + + {0} + + + """, markup)); internal void AssertShowing(string expectedText) { diff --git a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/AbstractContextTests.cs b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/AbstractContextTests.cs index dc596f6defaae..45274536615dc 100644 --- a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/AbstractContextTests.cs +++ b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/AbstractContextTests.cs @@ -119,21 +119,25 @@ protected void VerifyFalse(string text) protected static string AddInsideMethod(string text) { return -@"class C -{ - void F() - { - " + text + -@" } -}"; + """ + class C + { + void F() + { + """ + text + + """ + } + } + """; } protected static string AddInsideClass(string text) { return -@"class C -{ - " + text + + """ + class C + { + """ + text + @"}"; } } diff --git a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/NamespaceContextTests.cs b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/NamespaceContextTests.cs index 9aaf3a5574b65..4c2a2c4524432 100644 --- a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/NamespaceContextTests.cs +++ b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/NamespaceContextTests.cs @@ -28,9 +28,11 @@ public void UsingDirective() [Fact] public void InactiveRegion() { - VerifyFalse(@"#if false -$$ -#endif"); + VerifyFalse(""" + #if false + $$ + #endif + """); } [Fact] @@ -40,9 +42,11 @@ public void SingleLineComment1() [Fact] public void SingleLineComment2() { - VerifyTrue(@"class C { -// -$$"); + VerifyTrue(""" + class C { + // + $$ + """); } [Fact] @@ -76,8 +80,10 @@ public void AssemblyAttribute() [Fact] public void TypeAttribute() { - VerifyTrue(@"[$$] -class CL {}"); + VerifyTrue(""" + [$$] + class CL {} + """); } [Fact] @@ -87,26 +93,32 @@ public void TypeParamAttribute() [Fact] public void MethodAttribute() { - VerifyTrue(@"class CL { - [$$] - void Method() {} -}"); + VerifyTrue(""" + class CL { + [$$] + void Method() {} + } + """); } [Fact] public void MethodTypeParamAttribute() { - VerifyTrue(@"class CL{ - void Method<[A$$]T> () {} -}"); + VerifyTrue(""" + class CL{ + void Method<[A$$]T> () {} + } + """); } [Fact] public void MethodParamAttribute() { - VerifyTrue(@"class CL{ - void Method ([$$]int i) {} -}"); + VerifyTrue(""" + class CL{ + void Method ([$$]int i) {} + } + """); } [Fact] @@ -120,9 +132,11 @@ public void UnderNamespace() [Fact] public void OutsideOfType() { - VerifyFalse(@"namespace NS { -class CL {} -$$"); + VerifyFalse(""" + namespace NS { + class CL {} + $$ + """); } [Fact] @@ -140,17 +154,19 @@ public void UsingAlias2() [Fact] public void IncompleteMember() { - VerifyTrue(@"class CL { - $$ -"); + VerifyTrue(""" + class CL { + $$ + """); } [Fact] public void IncompleteMemberAccessibility() { - VerifyTrue(@"class CL { - public $$ -"); + VerifyTrue(""" + class CL { + public $$ + """); } [Fact] @@ -212,99 +228,127 @@ public void CatchDeclaration() [Fact] public void FieldDeclaration() { - VerifyTrue(@"class CL { - $$ i"); + VerifyTrue(""" + class CL { + $$ i + """); } [Fact] public void EventFieldDeclaration() { - VerifyTrue(@"class CL { - event $$"); + VerifyTrue(""" + class CL { + event $$ + """); } [Fact] public void ConversionOperatorDeclaration() { - VerifyTrue(@"class CL { - explicit operator $$"); + VerifyTrue(""" + class CL { + explicit operator $$ + """); } [Fact] public void ConversionOperatorDeclarationNoToken() { - VerifyFalse(@"class CL { - explicit $$"); + VerifyFalse(""" + class CL { + explicit $$ + """); } [Fact] public void PropertyDeclaration() { - VerifyTrue(@"class CL { - $$ Prop {"); + VerifyTrue(""" + class CL { + $$ Prop { + """); } [Fact] public void EventDeclaration() { - VerifyTrue(@"class CL { - event $$ Event {"); + VerifyTrue(""" + class CL { + event $$ Event { + """); } [Fact] public void IndexerDeclaration() { - VerifyTrue(@"class CL { - $$ this"); + VerifyTrue(""" + class CL { + $$ this + """); } [Fact] public void Parameter() { - VerifyTrue(@"class CL { - void Method($$"); + VerifyTrue(""" + class CL { + void Method($$ + """); } [Fact] public void ArrayType() { - VerifyTrue(@"class CL { - $$ ["); + VerifyTrue(""" + class CL { + $$ [ + """); } [Fact] public void PointerType() { - VerifyTrue(@"class CL { - $$ *"); + VerifyTrue(""" + class CL { + $$ * + """); } [Fact] public void NullableType() { - VerifyTrue(@"class CL { - $$ ?"); + VerifyTrue(""" + class CL { + $$ ? + """); } [Fact] public void DelegateDeclaration() { - VerifyTrue(@"class CL { - delegate $$"); + VerifyTrue(""" + class CL { + delegate $$ + """); } [Fact] public void MethodDeclaration() { - VerifyTrue(@"class CL { - $$ M("); + VerifyTrue(""" + class CL { + $$ M( + """); } [Fact] public void OperatorDeclaration() { - VerifyTrue(@"class CL { - $$ operator"); + VerifyTrue(""" + class CL { + $$ operator + """); } [Fact] @@ -470,9 +514,11 @@ public void SwitchStatement() [Fact] public void SwitchLabelCase() { - VerifyTrue(AddInsideMethod(@"switch(i) - { - case $$")); + VerifyTrue(AddInsideMethod(""" + switch(i) + { + case $$ + """)); } [Fact] diff --git a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/TypeContextTests.cs b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/TypeContextTests.cs index 9cf0a4ca70f77..88b510b40d988 100644 --- a/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/TypeContextTests.cs +++ b/src/EditorFeatures/CSharpTest/Extensions/ContextQuery/TypeContextTests.cs @@ -28,9 +28,11 @@ public void UsingDirective() [Fact] public void InactiveRegion() { - VerifyFalse(@"#if false -$$ -#endif"); + VerifyFalse(""" + #if false + $$ + #endif + """); } [Fact] @@ -40,9 +42,11 @@ public void SingleLineComment1() [Fact] public void SingleLineComment2() { - VerifyTrue(@"class C { -// -$$"); + VerifyTrue(""" + class C { + // + $$ + """); } [Fact] @@ -76,8 +80,10 @@ public void AssemblyAttribute() [Fact] public void TypeAttribute() { - VerifyTrue(@"[$$] -class CL {}"); + VerifyTrue(""" + [$$] + class CL {} + """); } [Fact] @@ -87,26 +93,32 @@ public void TypeParamAttribute() [Fact] public void MethodAttribute() { - VerifyTrue(@"class CL { - [$$] - void Method() {} -}"); + VerifyTrue(""" + class CL { + [$$] + void Method() {} + } + """); } [Fact] public void MethodTypeParamAttribute() { - VerifyTrue(@"class CL{ - void Method<[A$$]T> () {} -}"); + VerifyTrue(""" + class CL{ + void Method<[A$$]T> () {} + } + """); } [Fact] public void MethodParamAttribute() { - VerifyTrue(@"class CL{ - void Method ([$$]int i) {} -}"); + VerifyTrue(""" + class CL{ + void Method ([$$]int i) {} + } + """); } [Fact] @@ -120,9 +132,11 @@ public void UnderNamespace() [Fact] public void OutsideOfType() { - VerifyFalse(@"namespace NS { -class CL {} -$$"); + VerifyFalse(""" + namespace NS { + class CL {} + $$ + """); } [Fact] @@ -136,17 +150,19 @@ public void UsingAlias() [Fact] public void IncompleteMember() { - VerifyTrue(@"class CL { - $$ -"); + VerifyTrue(""" + class CL { + $$ + """); } [Fact] public void IncompleteMemberAccessibility() { - VerifyTrue(@"class CL { - public $$ -"); + VerifyTrue(""" + class CL { + public $$ + """); } [Fact] @@ -208,99 +224,127 @@ public void CatchDeclaration() [Fact] public void FieldDeclaration() { - VerifyTrue(@"class CL { - $$ i"); + VerifyTrue(""" + class CL { + $$ i + """); } [Fact] public void EventFieldDeclaration() { - VerifyTrue(@"class CL { - event $$"); + VerifyTrue(""" + class CL { + event $$ + """); } [Fact] public void ConversionOperatorDeclaration() { - VerifyTrue(@"class CL { - explicit operator $$"); + VerifyTrue(""" + class CL { + explicit operator $$ + """); } [Fact] public void ConversionOperatorDeclarationNoToken() { - VerifyFalse(@"class CL { - explicit $$"); + VerifyFalse(""" + class CL { + explicit $$ + """); } [Fact] public void PropertyDeclaration() { - VerifyTrue(@"class CL { - $$ Prop {"); + VerifyTrue(""" + class CL { + $$ Prop { + """); } [Fact] public void EventDeclaration() { - VerifyTrue(@"class CL { - event $$ Event {"); + VerifyTrue(""" + class CL { + event $$ Event { + """); } [Fact] public void IndexerDeclaration() { - VerifyTrue(@"class CL { - $$ this"); + VerifyTrue(""" + class CL { + $$ this + """); } [Fact] public void Parameter() { - VerifyTrue(@"class CL { - void Method($$"); + VerifyTrue(""" + class CL { + void Method($$ + """); } [Fact] public void ArrayType() { - VerifyTrue(@"class CL { - $$ ["); + VerifyTrue(""" + class CL { + $$ [ + """); } [Fact] public void PointerType() { - VerifyTrue(@"class CL { - $$ *"); + VerifyTrue(""" + class CL { + $$ * + """); } [Fact] public void NullableType() { - VerifyTrue(@"class CL { - $$ ?"); + VerifyTrue(""" + class CL { + $$ ? + """); } [Fact] public void DelegateDeclaration() { - VerifyTrue(@"class CL { - delegate $$"); + VerifyTrue(""" + class CL { + delegate $$ + """); } [Fact] public void MethodDeclaration() { - VerifyTrue(@"class CL { - $$ M("); + VerifyTrue(""" + class CL { + $$ M( + """); } [Fact] public void OperatorDeclaration() { - VerifyTrue(@"class CL { - $$ operator"); + VerifyTrue(""" + class CL { + $$ operator + """); } [Fact] @@ -466,9 +510,11 @@ public void SwitchStatement() [Fact] public void SwitchLabelCase() { - VerifyTrue(AddInsideMethod(@"switch(i) - { - case $$")); + VerifyTrue(AddInsideMethod(""" + switch(i) + { + case $$ + """)); } [Fact] diff --git a/src/EditorFeatures/CSharpTest/Extensions/SyntaxTreeExtensionsTests.cs b/src/EditorFeatures/CSharpTest/Extensions/SyntaxTreeExtensionsTests.cs index 0868735ab3a71..c8cadaa3b8ce5 100644 --- a/src/EditorFeatures/CSharpTest/Extensions/SyntaxTreeExtensionsTests.cs +++ b/src/EditorFeatures/CSharpTest/Extensions/SyntaxTreeExtensionsTests.cs @@ -34,12 +34,13 @@ private static void VerifyWholeLineIsInactive(SyntaxTree tree, int lineNumber) [Fact] public void SimpleInactive() { - var code = @"#if false -This is inactive -#else -// This is active -#endif -"; + var code = """ + #if false + This is inactive + #else + // This is active + #endif + """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); VerifyWholeLineIsInactive(tree, 1); @@ -51,9 +52,10 @@ This is inactive [Fact] public void InactiveEof() { - var code = @"#if false -This is inactive -"; + var code = """ + #if false + This is inactive + """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); VerifyWholeLineIsInactive(tree, 1); @@ -62,11 +64,12 @@ This is inactive [Fact] public void InactiveEof2() { - var code = @"#if false -This is inactive -#endif -// This is active -"; + var code = """ + #if false + This is inactive + #endif + // This is active + """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); diff --git a/src/EditorFeatures/CSharpTest/Formatting/CSharpNewDocumentFormattingServiceTests.cs b/src/EditorFeatures/CSharpTest/Formatting/CSharpNewDocumentFormattingServiceTests.cs index 0903587e6fce7..08650b137bf05 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/CSharpNewDocumentFormattingServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/CSharpNewDocumentFormattingServiceTests.cs @@ -24,7 +24,9 @@ public static IEnumerable EndOfDocumentSequences get { yield return new object[] { "" }; - yield return new object[] { "\r\n" }; + yield return new object[] { """ + + """ }; } } @@ -35,19 +37,21 @@ protected override TestWorkspace CreateTestWorkspace(string testCode, ParseOptio [Fact] public async Task TestFileScopedNamespaces() { - await TestAsync(testCode: @" -namespace Goo -{ - internal class C - { - } -}", - expected: @" -namespace Goo; - -internal class C -{ -}", + await TestAsync(testCode: """ + namespace Goo + { + internal class C + { + } + } + """, + expected: """ + namespace Goo; + + internal class C + { + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.NamespaceDeclarations, new CodeStyleOption2(NamespaceDeclarationPreference.FileScoped, NotificationOption2.Error) } @@ -58,14 +62,15 @@ internal class C [Fact] public async Task TestFileScopedNamespaces_Invalid_MultipleNamespaces() { - var testCode = @" -namespace Goo -{ -} + var testCode = """ + namespace Goo + { + } -namespace Bar -{ -}"; + namespace Bar + { + } + """; await TestAsync( testCode: testCode, @@ -80,13 +85,14 @@ await TestAsync( [Fact] public async Task TestFileScopedNamespaces_Invalid_WrongLanguageVersion() { - var testCode = @" -namespace Goo -{ - internal class C - { - } -}"; + var testCode = """ + namespace Goo + { + internal class C + { + } + } + """; await TestAsync( testCode: testCode, @@ -124,9 +130,11 @@ internal class C [Fact] public async Task TestOrganizeUsingsWithNoUsings() { - var testCode = @"namespace Goo -{ -}"; + var testCode = """ + namespace Goo + { + } + """; await TestAsync( testCode: testCode, expected: testCode, @@ -139,18 +147,22 @@ await TestAsync( [Fact] public async Task TestFileBanners() { - await TestAsync(testCode: @"using System; + await TestAsync(testCode: """ + using System; -namespace Goo -{ -}", - expected: @"// This is a banner. + namespace Goo + { + } + """, + expected: """ + // This is a banner. -using System; + using System; -namespace Goo -{ -}", + namespace Goo + { + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CodeStyleOptions2.FileHeaderTemplate, "This is a banner." } @@ -160,22 +172,26 @@ namespace Goo [Fact] public async Task TestAccessibilityModifiers() { - await TestAsync(testCode: @"using System; - -namespace Goo -{ - class C - { - } -}", - expected: @"using System; + await TestAsync(testCode: """ + using System; -namespace Goo -{ - internal class C - { - } -}", + namespace Goo + { + class C + { + } + } + """, + expected: """ + using System; + + namespace Goo + { + internal class C + { + } + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CodeStyleOptions2.AccessibilityModifiersRequired, new CodeStyleOption2(AccessibilityModifiersRequired.Always, NotificationOption2.Error) } @@ -185,20 +201,24 @@ internal class C [Fact] public async Task TestAccessibilityModifiers_FileScopedNamespace() { - await TestAsync(testCode: @"using System; + await TestAsync(testCode: """ + using System; -namespace Goo -{ - class C - { - } -}", - expected: @"using System; - -namespace Goo; -internal class C -{ -}", + namespace Goo + { + class C + { + } + } + """, + expected: """ + using System; + + namespace Goo; + internal class C + { + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.NamespaceDeclarations, new CodeStyleOption2(NamespaceDeclarationPreference.FileScoped, NotificationOption2.Error) }, @@ -210,38 +230,42 @@ internal class C public async Task TestAccessibilityModifiers_IgnoresPartial() { await TestAsync( - testCode: @"using System; - -namespace Goo -{ - class E - { - } - - partial class C - { - } - - class D - { - } -}", - expected: @"using System; - -namespace Goo -{ - internal class E - { - } - - partial class C - { - } + testCode: """ + using System; - internal class D - { - } -}", + namespace Goo + { + class E + { + } + + partial class C + { + } + + class D + { + } + } + """, + expected: """ + using System; + + namespace Goo + { + internal class E + { + } + + partial class C + { + } + + internal class D + { + } + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CodeStyleOptions2.AccessibilityModifiersRequired, new CodeStyleOption2(AccessibilityModifiersRequired.Always, NotificationOption2.Error) } @@ -251,15 +275,19 @@ internal class D [Fact] public async Task TestUsingDirectivePlacement() { - await TestAsync(testCode: @"using System; + await TestAsync(testCode: """ + using System; -namespace Goo -{ -}", - expected: @"namespace Goo -{ - using System; -}", + namespace Goo + { + } + """, + expected: """ + namespace Goo + { + using System; + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferredUsingDirectivePlacement, new CodeStyleOption2(AddImportPlacement.InsideNamespace, NotificationOption2.Error) } @@ -269,14 +297,18 @@ namespace Goo [Fact] public async Task TestPreferTopLevelStatements() { - await TestAsync(testCode: @"using System; - -// See https://aka.ms/new-console-template for more information -Console.WriteLine(""Hello, World!"");", - expected: @"using System; - -// See https://aka.ms/new-console-template for more information -Console.WriteLine(""Hello, World!"");", + await TestAsync(testCode: """ + using System; + + // See https://aka.ms/new-console-template for more information + Console.WriteLine("Hello, World!"); + """, + expected: """ + using System; + + // See https://aka.ms/new-console-template for more information + Console.WriteLine("Hello, World!"); + """, options: new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferTopLevelStatements, new CodeStyleOption2(value: true, notification: NotificationOption2.Suggestion) } @@ -286,19 +318,23 @@ public async Task TestPreferTopLevelStatements() [Fact] public async Task TestPreferProgramMain() { - await TestAsync(testCode: @"using System; + await TestAsync(testCode: """ + using System; -// See https://aka.ms/new-console-template for more information -Console.WriteLine(""Hello, World!"");", - expected: @"using System; + // See https://aka.ms/new-console-template for more information + Console.WriteLine("Hello, World!"); + """, + expected: """ + using System; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(""Hello, World!""); - } -}", + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } + """, options: new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferTopLevelStatements, new CodeStyleOption2(value: false, notification: NotificationOption2.Suggestion) } diff --git a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs index 4712ff5621d08..5e0c52e5c0967 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs @@ -45,290 +45,308 @@ public partial class CodeCleanupTests [Fact] public Task RemoveUsings() { - var code = @"using System; -using System.Collections.Generic; -class Program -{ - static void Main(string[] args) - { - Console.WriteLine(); - } -} -"; + var code = """ + using System; + using System.Collections.Generic; + class Program + { + static void Main(string[] args) + { + Console.WriteLine(); + } + } + """; - var expected = @"using System; + var expected = """ + using System; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(); - } -} -"; + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine(); + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact] public Task SortUsings() { - var code = @"using System.Collections.Generic; -using System; -class Program -{ - static void Main(string[] args) - { - var list = new List(); - Console.WriteLine(list.Count); - } -} -"; + var code = """ + using System.Collections.Generic; + using System; + class Program + { + static void Main(string[] args) + { + var list = new List(); + Console.WriteLine(list.Count); + } + } + """; - var expected = @"using System; -using System.Collections.Generic; + var expected = """ + using System; + using System.Collections.Generic; -internal class Program -{ - private static void Main(string[] args) - { - List list = new(); - Console.WriteLine(list.Count); - } -} -"; + internal class Program + { + private static void Main(string[] args) + { + List list = new(); + Console.WriteLine(list.Count); + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact] public Task SortGlobalUsings() { - var code = @"using System.Threading.Tasks; -using System.Threading; -global using System.Collections.Generic; -global using System; -class Program -{ - static Task Main(string[] args) - { - Barrier b = new Barrier(0); - var list = new List(); - Console.WriteLine(list.Count); - b.Dispose(); - } -} -"; + var code = """ + using System.Threading.Tasks; + using System.Threading; + global using System.Collections.Generic; + global using System; + class Program + { + static Task Main(string[] args) + { + Barrier b = new Barrier(0); + var list = new List(); + Console.WriteLine(list.Count); + b.Dispose(); + } + } + """; - var expected = @"global using System; -global using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; + var expected = """ + global using System; + global using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; -internal class Program -{ - private static Task Main(string[] args) - { - Barrier b = new(0); - List list = new(); - Console.WriteLine(list.Count); - b.Dispose(); - } -} -"; + internal class Program + { + private static Task Main(string[] args) + { + Barrier b = new(0); + List list = new(); + Console.WriteLine(list.Count); + b.Dispose(); + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36984")] public Task GroupUsings() { - var code = @"using M; -using System; + var code = """ + using M; + using System; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(""Hello World!""); + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); - new Goo(); - } -} + new Goo(); + } + } -namespace M -{ - public class Goo { } -} -"; + namespace M + { + public class Goo { } + } + """; - var expected = @"using M; + var expected = """ + using M; -using System; + using System; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(""Hello World!""); + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); - _ = new Goo(); - } -} + _ = new Goo(); + } + } -namespace M -{ - public class Goo { } -} -"; + namespace M + { + public class Goo { } + } + """; return AssertCodeCleanupResult(expected, code, systemUsingsFirst: false, separateUsingGroups: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36984")] public Task SortAndGroupUsings() { - var code = @"using M; -using System; + var code = """ + using M; + using System; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(""Hello World!""); + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); - new Goo(); - } -} + new Goo(); + } + } -namespace M -{ - public class Goo { } -} -"; + namespace M + { + public class Goo { } + } + """; - var expected = @"using System; + var expected = """ + using System; -using M; + using M; -internal class Program -{ - private static void Main(string[] args) - { - Console.WriteLine(""Hello World!""); + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); - _ = new Goo(); - } -} + _ = new Goo(); + } + } -namespace M -{ - public class Goo { } -} -"; + namespace M + { + public class Goo { } + } + """; return AssertCodeCleanupResult(expected, code, systemUsingsFirst: true, separateUsingGroups: true); } [Fact] public Task FixAddRemoveBraces() { - var code = @"class Program -{ - int Method() - { - int a = 0; - if (a > 0) - a ++; - - return a; - } -} -"; - var expected = @"internal class Program -{ - private int Method() - { - int a = 0; - if (a > 0) - { - a++; - } - - return a; - } -} -"; + var code = """ + class Program + { + int Method() + { + int a = 0; + if (a > 0) + a ++; + + return a; + } + } + """; + var expected = """ + internal class Program + { + private int Method() + { + int a = 0; + if (a > 0) + { + a++; + } + + return a; + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact] public Task RemoveUnusedVariable() { - var code = @"class Program -{ - void Method() - { - int a; - } -} -"; - var expected = @"internal class Program -{ - private void Method() - { - } -} -"; + var code = """ + class Program + { + void Method() + { + int a; + } + } + """; + var expected = """ + internal class Program + { + private void Method() + { + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact] public Task FixAccessibilityModifiers() { - var code = @"class Program -{ - void Method() - { - int a; - } -} -"; - var expected = @"internal class Program -{ - private void Method() - { - } -} -"; + var code = """ + class Program + { + void Method() + { + int a; + } + } + """; + var expected = """ + internal class Program + { + private void Method() + { + } + } + """; return AssertCodeCleanupResult(expected, code); } [Fact] public Task FixUsingPlacementPreferOutside() { - var code = @"namespace A -{ - using System; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + var code = """ + namespace A + { + using System; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; - var expected = @"using System; + var expected = """ + using System; -namespace A -{ - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + namespace A + { + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; return AssertCodeCleanupResult(expected, code); } @@ -336,33 +354,35 @@ private void Method() [Fact] public Task FixUsingPlacementPreferInside() { - var code = @"using System; - -namespace A -{ - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + var code = """ + using System; - var expected = @"namespace A -{ - using System; + namespace A + { + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + var expected = """ + namespace A + { + using System; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; return AssertCodeCleanupResult(expected, code, InsideNamespaceOption); } @@ -370,19 +390,20 @@ private void Method() [Fact] public Task FixUsingPlacementPreferInsidePreserve() { - var code = @"using System; + var code = """ + using System; -namespace A -{ - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + namespace A + { + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; var expected = code; @@ -392,19 +413,20 @@ private void Method() [Fact] public Task FixUsingPlacementPreferOutsidePreserve() { - var code = @"namespace A -{ - using System; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - } - } -} -"; + var code = """ + namespace A + { + using System; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + } + } + } + """; var expected = code; @@ -414,40 +436,42 @@ private void Method() [Fact] public Task FixUsingPlacementMixedPreferOutside() { - var code = @"using System; + var code = """ + using System; -namespace A -{ - using System.Collections.Generic; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = new List(); - Console.WriteLine(list.Length); - } - } -} -"; + namespace A + { + using System.Collections.Generic; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = new List(); + Console.WriteLine(list.Length); + } + } + } + """; - var expected = @"using System; -using System.Collections.Generic; + var expected = """ + using System; + using System.Collections.Generic; -namespace A -{ - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = []; - Console.WriteLine(list.Length); - } - } -} -"; + namespace A + { + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = []; + Console.WriteLine(list.Length); + } + } + } + """; return AssertCodeCleanupResult(expected, code, OutsideNamespaceOption); } @@ -455,41 +479,42 @@ private void Method() [Fact] public Task FixUsingPlacementMixedPreferInside() { - var code = @"using System; - -namespace A -{ - using System.Collections.Generic; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = new(); - Console.WriteLine(list.Length); - } - } -} -"; - - var expected = @"namespace A -{ - using System; - using System.Collections.Generic; + var code = """ + using System; + namespace A + { + using System.Collections.Generic; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = new(); + Console.WriteLine(list.Length); + } + } + } + """; - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = []; - Console.WriteLine(list.Length); - } - } -} -"; + var expected = """ + namespace A + { + using System; + using System.Collections.Generic; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = []; + Console.WriteLine(list.Length); + } + } + } + """; return AssertCodeCleanupResult(expected, code, InsideNamespaceOption); } @@ -497,23 +522,24 @@ private void Method() [Fact] public Task FixUsingPlacementMixedPreferInsidePreserve() { - var code = @"using System; + var code = """ + using System; -namespace A -{ - using System.Collections.Generic; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = []; - Console.WriteLine(list.Length); - } - } -} -"; + namespace A + { + using System.Collections.Generic; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = []; + Console.WriteLine(list.Length); + } + } + } + """; var expected = code; @@ -523,23 +549,24 @@ private void Method() [Fact] public Task FixUsingPlacementMixedPreferOutsidePreserve() { - var code = @"using System; + var code = """ + using System; -namespace A -{ - using System.Collections.Generic; - - internal class Program - { - private void Method() - { - Console.WriteLine(); - List list = []; - Console.WriteLine(list.Length); - } - } -} -"; + namespace A + { + using System.Collections.Generic; + + internal class Program + { + private void Method() + { + Console.WriteLine(); + List list = []; + Console.WriteLine(list.Length); + } + } + } + """; var expected = code; @@ -571,96 +598,96 @@ public void VerifyAllCodeStyleFixersAreSupportedByCodeCleanup(string language) Assert.Equal(expectedNumberOfUnsupportedDiagnosticIds, unsupportedDiagnosticIds.Length); } - private const string _code = @" -class C -{ - public void M1(int x, int y) - { - switch (x) - { - case 1: - case 10: - break; - default: - break; - } - - switch (y) - { - case 1: - break; - case 1000: - default: - break; - } - - switch (x) - { - case 1: - break; - case 1000: - break; - } - - switch (y) - { - default: - break; - } - - switch (y) { } - - switch (x) - { - case : - case 1000: - break; - } - } -} -"; - - private const string _fixed = @" -class C -{ - public void M1(int x, int y) - { - switch (x) - { - case 1: - case 10: - break; - } - - switch (y) - { - case 1: - break; - } - - switch (x) - { - case 1: - break; - case 1000: - break; - } - - switch (y) - { - } - - switch (y) { } + private const string _code = """ + class C + { + public void M1(int x, int y) + { + switch (x) + { + case 1: + case 10: + break; + default: + break; + } + + switch (y) + { + case 1: + break; + case 1000: + default: + break; + } + + switch (x) + { + case 1: + break; + case 1000: + break; + } + + switch (y) + { + default: + break; + } + + switch (y) { } + + switch (x) + { + case : + case 1000: + break; + } + } + } + """; - switch (x) - { - case : - case 1000: - break; - } - } -} -"; + private const string _fixed = """ + class C + { + public void M1(int x, int y) + { + switch (x) + { + case 1: + case 10: + break; + } + + switch (y) + { + case 1: + break; + } + + switch (x) + { + case 1: + break; + case 1000: + break; + } + + switch (y) + { + } + + switch (y) { } + + switch (x) + { + case : + case 1000: + break; + } + } + } + """; [Fact] public async Task RunThirdPartyFixer() diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests_Venus.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests_Venus.cs index 9479b9d21c69d..2d95f042ad492 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests_Venus.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests_Venus.cs @@ -19,27 +19,31 @@ public FormattingEngineTests_Venus(ITestOutputHelper output) : base(output) { } [WpfFact, Trait(Traits.Feature, Traits.Features.Formatting), Trait(Traits.Feature, Traits.Features.Venus)] public async Task SimpleOneLineNugget() { - var code = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1[| -int x=1 ; -|]#line hidden -#line default - } -}"; - - var expected = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1 - int x = 1; -#line hidden -#line default -} -}"; + var code = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1[| + int x=1 ; + |]#line hidden + #line default + } + } + """; + + var expected = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1 + int x = 1; + #line hidden + #line default + } + } + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 7); } @@ -47,32 +51,36 @@ void PreRender() [WpfFact, Trait(Traits.Feature, Traits.Features.Formatting), Trait(Traits.Feature, Traits.Features.Venus)] public async Task SimpleMultiLineNugget() { - var code = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1[| -if(true) -{ -Console.WriteLine(5);} -|]#line hidden -#line default - } -}"; - - var expected = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1 - if (true) - { - Console.WriteLine(5); - } -#line hidden -#line default -} -}"; + var code = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1[| + if(true) + { + Console.WriteLine(5);} + |]#line hidden + #line default + } + } + """; + + var expected = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1 + if (true) + { + Console.WriteLine(5); + } + #line hidden + #line default + } + } + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 3); } @@ -80,33 +88,37 @@ void PreRender() [WpfFact, Trait(Traits.Feature, Traits.Features.Formatting), Trait(Traits.Feature, Traits.Features.Venus)] public async Task SimpleQueryWithinNugget() { - var code = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1[| -int[] numbers = { 5, 4, 1 }; -var even = from n in numbers - where n % 2 == 0 - select n; -|]#line hidden -#line default - } -}"; - - var expected = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1 - int[] numbers = { 5, 4, 1 }; - var even = from n in numbers - where n % 2 == 0 - select n; -#line hidden -#line default -} -}"; + var code = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1[| + int[] numbers = { 5, 4, 1 }; + var even = from n in numbers + where n % 2 == 0 + select n; + |]#line hidden + #line default + } + } + """; + + var expected = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1 + int[] numbers = { 5, 4, 1 }; + var even = from n in numbers + where n % 2 == 0 + select n; + #line hidden + #line default + } + } + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 7); } @@ -114,33 +126,37 @@ void PreRender() [WpfFact, Trait(Traits.Feature, Traits.Features.Formatting), Trait(Traits.Feature, Traits.Features.Venus)] public async Task LambdaExpressionInNugget() { - var code = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1[| -int[] source = new [] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8} ; - -foreach(int i in source.Where(x => x > 5)) - Console.WriteLine(i); -|]#line hidden -#line default - } -}"; - - var expected = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1 - int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; - - foreach (int i in source.Where(x => x > 5)) - Console.WriteLine(i); -#line hidden -#line default -} -}"; + var code = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1[| + int[] source = new [] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8} ; + + foreach(int i in source.Where(x => x > 5)) + Console.WriteLine(i); + |]#line hidden + #line default + } + } + """; + + var expected = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1 + int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; + + foreach (int i in source.Where(x => x > 5)) + Console.WriteLine(i); + #line hidden + #line default + } + } + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 3); } @@ -149,51 +165,55 @@ void PreRender() [WpfFact, Trait(Traits.Feature, Traits.Features.Formatting), Trait(Traits.Feature, Traits.Features.Venus)] public async Task StatementLambdaInNugget() { - var code = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1[| - int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; - - foreach (int i in source.Where( - x => - { - if (x <= 3) - return true; - else if (x >= 7) - return true; - return false; - } - )) - Console.WriteLine(i); -|]#line hidden -#line default - } -}"; - - var expected = @"public class Default -{ - void PreRender() - { -#line ""Goo.aspx"", 1 - int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; - - foreach (int i in source.Where( - x => - { - if (x <= 3) - return true; - else if (x >= 7) - return true; - return false; - } - )) - Console.WriteLine(i); -#line hidden -#line default -} -}"; + var code = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1[| + int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; + + foreach (int i in source.Where( + x => + { + if (x <= 3) + return true; + else if (x >= 7) + return true; + return false; + } + )) + Console.WriteLine(i); + |]#line hidden + #line default + } + } + """; + + var expected = """ + public class Default + { + void PreRender() + { + #line "Goo.aspx", 1 + int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; + + foreach (int i in source.Where( + x => + { + if (x <= 3) + return true; + else if (x >= 7) + return true; + return false; + } + )) + Console.WriteLine(i); + #line hidden + #line default + } + } + """; // It is somewhat odd that the 'x' and the ')' maintain their // position relative to 'foreach', but the block doesn't, but that isn't diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs index 3bc93fe9871ec..8f9c5f507195f 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs @@ -39,11 +39,13 @@ public class CSharpFormatterTestsBase : CSharpFormattingEngineTestBase public CSharpFormatterTestsBase(ITestOutputHelper output) : base(output) { } - protected const string HtmlMarkup = @" - - <%{|S1:|}%> - -"; + protected const string HtmlMarkup = """ + + + <%{|S1:|}%> + + + """; protected const int BaseIndentationOfNugget = 8; protected static async Task GetSmartTokenFormatterIndentationWorkerAsync( diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests_Performance.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests_Performance.cs index aabe30eee6c76..4878602a10378 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests_Performance.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests_Performance.cs @@ -19,2196 +19,2196 @@ public void RegionPerformance() { var code = #region very long sample code - @"using System; -using System.Collections.Generic; + """ + using System; + using System.Collections.Generic; -class Class1 -{ -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + class Class1 + { + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - } - #endregion - }; -#endif + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + } + #endregion + }; + #endif -#if (false && Var1) - Dictionary> x = new Dictionary>() { - #region Region 1 - { - 1, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 2 - { - 2, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 3 - { - 3, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 4 - { - 4, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 5 - { - 5, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 6 - { - 6, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 7 - { - 7, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 8 - { - 8, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 9 - { - 9, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }, - #endregion - #region Region 10 - { - 10, - new List() - { - ""a"", - ""b"", - ""c"", - ""d"", - ""e"", - ""f"" - } - }$$ - - #endregion - }; -#endif -} + #if (false && Var1) + Dictionary> x = new Dictionary>() { + #region Region 1 + { + 1, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 2 + { + 2, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 3 + { + 3, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 4 + { + 4, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 5 + { + 5, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 6 + { + 6, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 7 + { + 7, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 8 + { + 8, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 9 + { + 9, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }, + #endregion + #region Region 10 + { + 10, + new List() + { + "a", + "b", + "c", + "d", + "e", + "f" + } + }$$ -class Program -{ - static void Main() - { - } -} + #endregion + }; + #endif + } -"; + class Program + { + static void Main() + { + } + } + """; #endregion AssertSmartIndent( diff --git a/src/EditorFeatures/CSharpTest/GoToAdjacentMember/CSharpGoToAdjacentMemberTests.cs b/src/EditorFeatures/CSharpTest/GoToAdjacentMember/CSharpGoToAdjacentMemberTests.cs index fc971d9568623..4211a0395e80d 100644 --- a/src/EditorFeatures/CSharpTest/GoToAdjacentMember/CSharpGoToAdjacentMemberTests.cs +++ b/src/EditorFeatures/CSharpTest/GoToAdjacentMember/CSharpGoToAdjacentMemberTests.cs @@ -29,21 +29,25 @@ public async Task EmptyFile() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task ClassWithNoMembers() { - var code = @"class C -{ -$$ -}"; + var code = """ + class C + { + $$ + } + """; Assert.Null(await GetTargetPositionAsync(code, next: true)); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task BeforeClassWithMember() { - var code = @"$$ -class C -{ - [||]void M() { } -}"; + var code = """ + $$ + class C + { + [||]void M() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -51,13 +55,14 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task AfterClassWithMember() { - var code = @" -class C -{ - [||]void M() { } -} + var code = """ + class C + { + [||]void M() { } + } -$$"; + $$ + """; await AssertNavigatedAsync(code, next: true); } @@ -65,18 +70,19 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task BetweenClasses() { - var code = @" -class C1 -{ - void M() { } -} + var code = """ + class C1 + { + void M() { } + } -$$ + $$ -class C2 -{ - [||]void M() { } -} "; + class C2 + { + [||]void M() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -84,18 +90,19 @@ class C2 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task BetweenClassesPrevious() { - var code = @" -class C1 -{ - [||]void M() { } -} + var code = """ + class C1 + { + [||]void M() { } + } -$$ + $$ -class C2 -{ - void M() { } -} "; + class C2 + { + void M() { } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -103,12 +110,13 @@ void M() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task FromFirstMemberToSecond() { - var code = @" -class C -{ - $$void M1() { } - [||]void M2() { } -}"; + var code = """ + class C + { + $$void M1() { } + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -116,12 +124,13 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task FromSecondToFirst() { - var code = @" -class C -{ - [||]void M1() { } - $$void M2() { } -}"; + var code = """ + class C + { + [||]void M1() { } + $$void M2() { } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -129,12 +138,13 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task NextWraps() { - var code = @" -class C -{ - [||]void M1() { } - $$void M2() { } -}"; + var code = """ + class C + { + [||]void M1() { } + $$void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -142,12 +152,13 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task PreviousWraps() { - var code = @" -class C -{ - $$void M1() { } - [||]void M2() { } -}"; + var code = """ + class C + { + $$void M1() { } + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -155,16 +166,17 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task DescendsIntoNestedType() { - var code = @" -class C -{ - $$void M1() { } + var code = """ + class C + { + $$void M1() { } - class N - { - [||]void M2() { } - } -}"; + class N + { + [||]void M2() { } + } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -172,88 +184,95 @@ class N [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtConstructor() { - var code = @" -class C -{ - $$void M1() { } - [||]public C() { } -}"; + var code = """ + class C + { + $$void M1() { } + [||]public C() { } + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtDestructor() { - var code = @" -class C -{ - $$void M1() { } - [||]~C() { } -}"; + var code = """ + class C + { + $$void M1() { } + [||]~C() { } + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtOperator() { - var code = @" -class C -{ - $$void M1() { } - [||]static C operator+(C left, C right) { throw new System.NotImplementedException(); } -}"; + var code = """ + class C + { + $$void M1() { } + [||]static C operator+(C left, C right) { throw new System.NotImplementedException(); } + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtField() { - var code = @" -class C -{ - $$void M1() { } - [||]int F; -}"; + var code = """ + class C + { + $$void M1() { } + [||]int F; + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtFieldlikeEvent() { - var code = @" -class C -{ - $$void M1() { } - [||]event System.EventHandler E; -}"; + var code = """ + class C + { + $$void M1() { } + [||]event System.EventHandler E; + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtAutoProperty() { - var code = @" -class C -{ - $$void M1() { } - [||]int P { get; set ; } -}"; + var code = """ + class C + { + $$void M1() { } + [||]int P { get; set ; } + } + """; await AssertNavigatedAsync(code, next: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtPropertyWithAccessors() { - var code = @" -class C -{ - $$void M1() { } + var code = """ + class C + { + $$void M1() { } - [||]int P - { - get { return 42; } - set { } - } -}"; + [||]int P + { + get { return 42; } + set { } + } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -261,19 +280,20 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task SkipsPropertyAccessors() { - var code = @" -class C -{ - void M1() { } + var code = """ + class C + { + void M1() { } - $$int P - { - get { return 42; } - set { } - } + $$int P + { + get { return 42; } + set { } + } - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -281,19 +301,20 @@ void M1() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task FromInsideAccessor() { - var code = @" -class C -{ - void M1() { } + var code = """ + class C + { + void M1() { } - int P - { - get { return $$42; } - set { } - } + int P + { + get { return $$42; } + set { } + } - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -301,17 +322,18 @@ int P [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtIndexerWithAccessors() { - var code = @" -class C -{ - $$void M1() { } + var code = """ + class C + { + $$void M1() { } - [||]int this[int i] - { - get { return 42; } - set { } - } -}"; + [||]int this[int i] + { + get { return 42; } + set { } + } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -319,19 +341,20 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task SkipsIndexerAccessors() { - var code = @" -class C -{ - void M1() { } + var code = """ + class C + { + void M1() { } - $$int this[int i] - { - get { return 42; } - set { } - } + $$int this[int i] + { + get { return 42; } + set { } + } - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -339,17 +362,18 @@ void M1() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtEventWithAddRemove() { - var code = @" -class C -{ - $$void M1() { } + var code = """ + class C + { + $$void M1() { } - [||]event EventHandler E - { - add { } - remove { } - } -}"; + [||]event EventHandler E + { + add { } + remove { } + } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -357,19 +381,20 @@ class C [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task SkipsEventAddRemove() { - var code = @" -class C -{ - void M1() { } + var code = """ + class C + { + void M1() { } - $$event EventHandler E - { - add { } - remove { } - } + $$event EventHandler E + { + add { } + remove { } + } - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -377,16 +402,17 @@ void M1() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task FromInsideMethod() { - var code = @" -class C -{ - void M1() - { - $$System.Console.WriteLine(); - } + var code = """ + class C + { + void M1() + { + $$System.Console.WriteLine(); + } - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -394,15 +420,16 @@ void M1() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task NextFromBetweenMethods() { - var code = @" -class C -{ - void M1() { } + var code = """ + class C + { + void M1() { } - $$ + $$ - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -410,15 +437,16 @@ void M1() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task PreviousFromBetweenMethods() { - var code = @" -class C -{ - [||]void M1() { } + var code = """ + class C + { + [||]void M1() { } - $$ + $$ - void M2() { } -}"; + void M2() { } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -426,15 +454,16 @@ void M2() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task NextFromBetweenMethodsInTrailingTrivia() { - var code = @" -class C -{ - void M1() - { - } $$ + var code = """ + class C + { + void M1() + { + } $$ - [||]void M2() { } -}"; + [||]void M2() { } + } + """; await AssertNavigatedAsync(code, next: true); } @@ -442,15 +471,16 @@ void M1() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task PreviousFromBetweenMethodsInTrailingTrivia() { - var code = @" -class C -{ - [||]void M1() - { - } $$ + var code = """ + class C + { + [||]void M1() + { + } $$ - void M2() { } -}"; + void M2() { } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -458,13 +488,14 @@ void M2() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task StopsAtExpressionBodiedMember() { - var code = @" -class C -{ - int M1() => $$42; + var code = """ + class C + { + int M1() => $$42; - [||]int M2() => 42; -}"; + [||]int M2() => 42; + } + """; await AssertNavigatedAsync(code, next: true); } @@ -473,18 +504,19 @@ class C [WorkItem("https://github.com/dotnet/roslyn/issues/10588")] public async Task PreviousFromInsideCurrent() { - var code = @" -class C -{ - [||]void M1() - { - Console.WriteLine($$); - } + var code = """ + class C + { + [||]void M1() + { + Console.WriteLine($$); + } - void M2() - { - } -}"; + void M2() + { + } + } + """; await AssertNavigatedAsync(code, next: false); } @@ -492,10 +524,11 @@ void M2() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task NextInScript() { - var code = @" -$$void M1() { } + var code = """ + $$void M1() { } -[||]void M2() { }"; + [||]void M2() { } + """; await AssertNavigatedAsync(code, next: true, sourceCodeKind: SourceCodeKind.Script); } @@ -503,10 +536,11 @@ public async Task NextInScript() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4311")] public async Task PrevInScript() { - var code = @" -[||]void M1() { } + var code = """ + [||]void M1() { } -$$void M2() { }"; + $$void M2() { } + """; await AssertNavigatedAsync(code, next: false, sourceCodeKind: SourceCodeKind.Script); } diff --git a/src/EditorFeatures/CSharpTest/Intents/AddConstructorParameterIntentTests.cs b/src/EditorFeatures/CSharpTest/Intents/AddConstructorParameterIntentTests.cs index 59b17307f2ba9..336721c5355af 100644 --- a/src/EditorFeatures/CSharpTest/Intents/AddConstructorParameterIntentTests.cs +++ b/src/EditorFeatures/CSharpTest/Intents/AddConstructorParameterIntentTests.cs @@ -29,34 +29,40 @@ public class AddConstructorParameterIntentTests : IntentTestsBase public async Task AddConstructorParameterWithField() { var initialText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} + """ + class C + { + private readonly int _someInt;{|priorSelection:|} - public C() - { - } -}"; + public C() + { + } + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int som) - { - } -}"; + public C(int som) + { + } + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int someInt) - { - _someInt = someInt; - } -}"; + public C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -65,33 +71,39 @@ public C(int someInt) public async Task AddConstructorParameterWithProperty() { var initialText = -@"class C -{ - public int SomeInt { get; }{|priorSelection:|} + """ + class C + { + public int SomeInt { get; }{|priorSelection:|} - public C() - { - } -}"; + public C() + { + } + } + """; var currentText = -@"class C -{ - public int SomeInt { get; } + """ + class C + { + public int SomeInt { get; } - public C(int som) - { - } -}"; + public C(int som) + { + } + } + """; var expectedText = -@"class C -{ - public int SomeInt { get; } + """ + class C + { + public int SomeInt { get; } - public C(int someInt) - { - SomeInt = someInt; - } -}"; + public C(int someInt) + { + SomeInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -100,37 +112,43 @@ public C(int someInt) public async Task AddMultipleConstructorParameters() { var initialText = -@"class C -{ - {|priorSelection:private readonly int _someInt; - private readonly string _someString;|} + """ + class C + { + {|priorSelection:private readonly int _someInt; + private readonly string _someString;|} - public C() - { - } -}"; + public C() + { + } + } + """; var currentText = -@"class C -{ - {|priorSelection:private readonly int _someInt; - private readonly string _someString;|} + """ + class C + { + {|priorSelection:private readonly int _someInt; + private readonly string _someString;|} - public C(int som) - { - } -}"; + public C(int som) + { + } + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; - private readonly string _someString; + """ + class C + { + private readonly int _someInt; + private readonly string _someString; - public C(int someInt, string someString) - { - _someInt = someInt; - _someString = someString; - } -}"; + public C(int someInt, string someString) + { + _someInt = someInt; + _someString = someString; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -139,36 +157,42 @@ public C(int someInt, string someString) public async Task AddConstructorParameterOnlyAddsSelected() { var initialText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} - private readonly string _someString; + """ + class C + { + private readonly int _someInt;{|priorSelection:|} + private readonly string _someString; - public C() - { - } -}"; + public C() + { + } + } + """; var currentText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} - private readonly string _someString; + """ + class C + { + private readonly int _someInt;{|priorSelection:|} + private readonly string _someString; - public C(int som) - { - } -}"; + public C(int som) + { + } + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; - private readonly string _someString; + """ + class C + { + private readonly int _someInt; + private readonly string _someString; - public C(int someInt) - { - _someInt = someInt; - } -}"; + public C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -177,33 +201,39 @@ public C(int someInt) public async Task AddConstructorParameterUsesCodeStyleOption() { var initialText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} + """ + class C + { + private readonly int _someInt;{|priorSelection:|} - public C() - { - } -}"; + public C() + { + } + } + """; var currentText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} + """ + class C + { + private readonly int _someInt;{|priorSelection:|} - public C(int som) - { - } -}"; + public C(int som) + { + } + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int someInt) - { - this._someInt = someInt; - } -}"; + public C(int someInt) + { + this._someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText, options: new OptionsCollection(LanguageNames.CSharp) { @@ -215,33 +245,39 @@ await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialT public async Task AddConstructorParameterUsesExistingAccessibility() { var initialText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} + """ + class C + { + private readonly int _someInt;{|priorSelection:|} - protected C() - { - } -}"; + protected C() + { + } + } + """; var currentText = -@"class C -{ - private readonly int _someInt;{|priorSelection:|} + """ + class C + { + private readonly int _someInt;{|priorSelection:|} - protected C(int som) - { - } -}"; + protected C(int som) + { + } + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - protected C(int someInt) - { - _someInt = someInt; - } -}"; + protected C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.AddConstructorParameter, initialText, currentText, expectedText).ConfigureAwait(false); } diff --git a/src/EditorFeatures/CSharpTest/Intents/DeleteParameterIntentTests.cs b/src/EditorFeatures/CSharpTest/Intents/DeleteParameterIntentTests.cs index 645a23be7c83e..a03f654dd728d 100644 --- a/src/EditorFeatures/CSharpTest/Intents/DeleteParameterIntentTests.cs +++ b/src/EditorFeatures/CSharpTest/Intents/DeleteParameterIntentTests.cs @@ -18,41 +18,47 @@ public class DeleteParameterIntentTests : IntentTestsBase public async Task TestDeleteParameterIntentAsync() { var initialText = -@"class C -{ - void M() - { - Method({|priorSelection:1|}); - } - - void Method(int value) - { - } -}"; + """ + class C + { + void M() + { + Method({|priorSelection:1|}); + } + + void Method(int value) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(); - } - - void Method(int value) - { - } -}"; + """ + class C + { + void M() + { + Method(); + } + + void Method(int value) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(); - } - - void Method() - { - } -}"; + """ + class C + { + void M() + { + Method(); + } + + void Method() + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -61,41 +67,47 @@ void Method() public async Task TestDeleteParameterOnDefinitionIntentAsync() { var initialText = -@"class C -{ - void M() - { - Method(1); - } - - void Method(int {|priorSelection:value|}) - { - } -}"; + """ + class C + { + void M() + { + Method(1); + } + + void Method(int {|priorSelection:value|}) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(); - } - - void Method(int value) - { - } -}"; + """ + class C + { + void M() + { + Method(); + } + + void Method(int value) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(); - } - - void Method() - { - } -}"; + """ + class C + { + void M() + { + Method(); + } + + void Method() + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -103,41 +115,47 @@ void Method() [Fact] public async Task TestDeleteSecondParameterIntentAsync() { - var initialText = @"class C -{ - void M() - { - Method(1, {|priorSelection:2|}, 3); - } - - void Method(int value1, int value2, int value3) - { - } -}"; + var initialText = """ + class C + { + void M() + { + Method(1, {|priorSelection:2|}, 3); + } + + void Method(int value1, int value2, int value3) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(1, 3); - } - - void Method(int value1, int value2, int value3) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 3); + } + + void Method(int value1, int value2, int value3) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(1, 3); - } - - void Method(int value1, int value3) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 3); + } + + void Method(int value1, int value3) + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -145,41 +163,47 @@ void Method(int value1, int value3) [Fact] public async Task TestDeleteLastParameterAsync() { - var initialText = @"class C -{ - void M() - { - Method(1, 2, {|priorSelection:3|}); - } - - void Method(int value1, int value2, int value3) - { - } -}"; + var initialText = """ + class C + { + void M() + { + Method(1, 2, {|priorSelection:3|}); + } + + void Method(int value1, int value2, int value3) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(1, 2); - } - - void Method(int value1, int value2, int value3) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 2); + } + + void Method(int value1, int value2, int value3) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(1, 2); - } - - void Method(int value1, int value2) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 2); + } + + void Method(int value1, int value2) + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -187,39 +211,43 @@ void Method(int value1, int value2) [Fact] public async Task TestDeleteThisParameterAsync() { - var initialText = @"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this {|priorSelection:Foo|} foo) - { - - } -}"; + var initialText = """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(); + } + } + + public static class FooExtensions + { + public static void DoFoo(this {|priorSelection:Foo|} foo) + { + + } + } + """; var currentText = -@"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(); - } -} - -public static class FooExtensions -{ - public static void DoFoo() - { - - } -}"; + """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(); + } + } + + public static class FooExtensions + { + public static void DoFoo() + { + + } + } + """; await VerifyIntentMissingAsync(WellKnownIntents.DeleteParameter, initialText, currentText).ConfigureAwait(false); } @@ -227,56 +255,62 @@ public static void DoFoo() [Fact] public async Task TestDeleteParameterInExtensionMethodAsync() { - var initialText = @"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo({|priorSelection:1|}, 2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int value1, int value2) - { - - } -}"; + var initialText = """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo({|priorSelection:1|}, 2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int value1, int value2) + { + + } + } + """; var currentText = -@"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int value1, int value2) - { - - } -}"; + """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int value1, int value2) + { + + } + } + """; var expectedText = -@"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int value2) - { - - } -}"; + """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int value2) + { + + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -284,56 +318,62 @@ public static void DoFoo(this Foo foo, int value2) [Fact] public async Task TestDeleteParameterOnDefinitionAsync() { - var initialText = @"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(1, 2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int {|priorSelection:value1|}, int value2) - { - - } -}"; + var initialText = """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(1, 2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int {|priorSelection:value1|}, int value2) + { + + } + } + """; var currentText = -@"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int value1, int value2) - { - - } -}"; + """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int value1, int value2) + { + + } + } + """; var expectedText = -@"public class Foo -{ - static void Bar() - { - var f = new Foo(); - f.DoFoo(2); - } -} - -public static class FooExtensions -{ - public static void DoFoo(this Foo foo, int value2) - { - - } -}"; + """ + public class Foo + { + static void Bar() + { + var f = new Foo(); + f.DoFoo(2); + } + } + + public static class FooExtensions + { + public static void DoFoo(this Foo foo, int value2) + { + + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -342,41 +382,47 @@ public static void DoFoo(this Foo foo, int value2) public async Task TestDeleteParamsParameterAsync() { var initialText = -@"class C -{ - void M() - { - Method(new C(), {|priorSelection:1|}, 2, 3); - } - - void Method(C c, params int[] values) - { - } -}"; + """ + class C + { + void M() + { + Method(new C(), {|priorSelection:1|}, 2, 3); + } + + void Method(C c, params int[] values) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(new C(), 2, 3); - } - - void Method(C c, params int[] values) - { - } -}"; + """ + class C + { + void M() + { + Method(new C(), 2, 3); + } + + void Method(C c, params int[] values) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(new C()); - } - - void Method(C c) - { - } -}"; + """ + class C + { + void M() + { + Method(new C()); + } + + void Method(C c) + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -385,41 +431,47 @@ void Method(C c) public async Task TestDeleteParameterBeforeParamsAsync() { var initialText = -@"class C -{ - void M() - { - Method(1.0f, 1, 2, 3); - } - - void Method(float {|priorSelection:f|}, params int[] values) - { - } -}"; + """ + class C + { + void M() + { + Method(1.0f, 1, 2, 3); + } + + void Method(float {|priorSelection:f|}, params int[] values) + { + } + } + """; var currentText = -@"class C -{ - void M() - { - Method(1, 2, 3); - } - - void Method(float f, params int[] values) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 2, 3); + } + + void Method(float f, params int[] values) + { + } + } + """; var expectedText = -@"class C -{ - void M() - { - Method(1, 2, 3); - } - - void Method(params int[] values) - { - } -}"; + """ + class C + { + void M() + { + Method(1, 2, 3); + } + + void Method(params int[] values) + { + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -428,53 +480,59 @@ void Method(params int[] values) public async Task TestDeleteParameterOnStaticExtensionInvocationAsync() { var initialText = -@"public static class AExtension -{ - public static void Method(this A c, int i) - { - - } -} - -public class A -{ - void M() - { - AExtension.Method(new A(), {|priorSelection:1|}); - } -}"; + """ + public static class AExtension + { + public static void Method(this A c, int i) + { + + } + } + + public class A + { + void M() + { + AExtension.Method(new A(), {|priorSelection:1|}); + } + } + """; var currentText = -@"public static class AExtension -{ - public static void Method(this A c, int i) - { - - } -} - -public class A -{ - void M() - { - AExtension.Method(new A()); - } -}"; + """ + public static class AExtension + { + public static void Method(this A c, int i) + { + + } + } + + public class A + { + void M() + { + AExtension.Method(new A()); + } + } + """; var expectedText = -@"public static class AExtension -{ - public static void Method(this A c) - { - - } -} - -public class A -{ - void M() - { - AExtension.Method(new A()); - } -}"; + """ + public static class AExtension + { + public static void Method(this A c) + { + + } + } + + public class A + { + void M() + { + AExtension.Method(new A()); + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -483,44 +541,50 @@ void M() public async Task TestDeleteParameterOnConstructorInvocationAsync() { var initialText = -@"public class A -{ - public A(int i, string s) - { - - } - - static A M() - { - return new A(1, {|priorSelection:""hello""|}); - } -}"; + """ + public class A + { + public A(int i, string s) + { + + } + + static A M() + { + return new A(1, {|priorSelection:"hello"|}); + } + } + """; var currentText = -@"public class A -{ - public A(int i, string s) - { - - } - - static A M() - { - return new A(1); - } -}"; + """ + public class A + { + public A(int i, string s) + { + + } + + static A M() + { + return new A(1); + } + } + """; var expectedText = -@"public class A -{ - public A(int i) - { - - } - - static A M() - { - return new A(1); - } -}"; + """ + public class A + { + public A(int i) + { + + } + + static A M() + { + return new A(1); + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.DeleteParameter, initialText, currentText, expectedText).ConfigureAwait(false); } diff --git a/src/EditorFeatures/CSharpTest/Intents/GenerateConstructorIntentTests.cs b/src/EditorFeatures/CSharpTest/Intents/GenerateConstructorIntentTests.cs index 5aed528476674..824935ab70ee1 100644 --- a/src/EditorFeatures/CSharpTest/Intents/GenerateConstructorIntentTests.cs +++ b/src/EditorFeatures/CSharpTest/Intents/GenerateConstructorIntentTests.cs @@ -18,29 +18,35 @@ public class GenerateConstructorIntentTests : IntentTestsBase public async Task GenerateConstructorSimpleResult() { var initialText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C -}"; + public C + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int someInt) - { - _someInt = someInt; - } -}"; + public C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.GenerateConstructor, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -49,29 +55,35 @@ public C(int someInt) public async Task GenerateConstructorTypedPrivateWithoutIntentData() { var initialText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - private C -}"; + private C + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int someInt) - { - _someInt = someInt; - } -}"; + public C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.GenerateConstructor, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -80,29 +92,35 @@ public C(int someInt) public async Task GenerateConstructorTypedPrivateWithIntentData() { var initialText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - private C -}"; + private C + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - private C(int someInt) - { - _someInt = someInt; - } -}"; + private C(int someInt) + { + _someInt = someInt; + } + } + """; // lang=json var intentData = @"{ ""accessibility"": ""Private""}"; @@ -114,29 +132,35 @@ private C(int someInt) public async Task GenerateConstructorTypedPrivateProtectedWithIntentData() { var initialText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - private protected C -}"; + private protected C + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - private protected C(int someInt) - { - _someInt = someInt; - } -}"; + private protected C(int someInt) + { + _someInt = someInt; + } + } + """; // lang=json var intentData = @"{ ""accessibility"": ""ProtectedAndInternal""}"; @@ -148,30 +172,38 @@ private protected C(int someInt) public async Task GenerateConstructorWithFieldsInPartial() { var initialText = -@"partial class C -{ - {|priorSelection:|} -}"; + """ + partial class C + { + {|priorSelection:|} + } + """; var currentText = -@"partial class C -{ - public C -}"; + """ + partial class C + { + public C + } + """; var additionalDocuments = new string[] { -@"partial class C -{ - private readonly int _someInt; -}" + """ + partial class C + { + private readonly int _someInt; + } + """ }; var expectedText = -@"partial class C -{ - public C(int someInt) - { - _someInt = someInt; - } -}"; + """ + partial class C + { + public C(int someInt) + { + _someInt = someInt; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.GenerateConstructor, initialText, currentText, additionalDocuments, new[] { expectedText }).ConfigureAwait(false); } @@ -180,29 +212,35 @@ public C(int someInt) public async Task GenerateConstructorWithReferenceType() { var initialText = -@"class C -{ - private readonly object _someObject; + """ + class C + { + private readonly object _someObject; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly object _someObject; + """ + class C + { + private readonly object _someObject; - public C -}"; + public C + } + """; var expectedText = -@"class C -{ - private readonly object _someObject; + """ + class C + { + private readonly object _someObject; - public C(object someObject) - { - _someObject = someObject; - } -}"; + public C(object someObject) + { + _someObject = someObject; + } + } + """; await VerifyExpectedTextAsync(WellKnownIntents.GenerateConstructor, initialText, currentText, expectedText).ConfigureAwait(false); } @@ -211,26 +249,32 @@ public C(object someObject) public async Task GenerateConstructorWithExpressionBodyOption() { var initialText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - {|priorSelection:|} -}"; + {|priorSelection:|} + } + """; var currentText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C -}"; + public C + } + """; var expectedText = -@"class C -{ - private readonly int _someInt; + """ + class C + { + private readonly int _someInt; - public C(int someInt) => _someInt = someInt; -}"; + public C(int someInt) => _someInt = someInt; + } + """; await VerifyExpectedTextAsync(WellKnownIntents.GenerateConstructor, initialText, currentText, expectedText, options: new OptionsCollection(LanguageNames.CSharp) diff --git a/src/EditorFeatures/CSharpTest/Intents/RenameIntentTests.cs b/src/EditorFeatures/CSharpTest/Intents/RenameIntentTests.cs index 7031814ae04fe..a736b1985ee48 100644 --- a/src/EditorFeatures/CSharpTest/Intents/RenameIntentTests.cs +++ b/src/EditorFeatures/CSharpTest/Intents/RenameIntentTests.cs @@ -18,32 +18,38 @@ public class RenameIntentTests : IntentTestsBase public async Task TestRenameIntentAsync() { var initialText = -@"class C -{ - void M() - { - var thing = 1; - {|priorSelection:thing|}.ToString(); - } -}"; + """ + class C + { + void M() + { + var thing = 1; + {|priorSelection:thing|}.ToString(); + } + } + """; var currentText = -@"class C -{ - void M() - { - var thing = 1; - something.ToString(); - } -}"; + """ + class C + { + void M() + { + var thing = 1; + something.ToString(); + } + } + """; var expectedText = -@"class C -{ - void M() - { - var something = 1; - something.ToString(); - } -}"; + """ + class C + { + void M() + { + var something = 1; + something.ToString(); + } + } + """; await VerifyExpectedRenameAsync(initialText, currentText, expectedText, "something").ConfigureAwait(false); } @@ -52,32 +58,38 @@ void M() public async Task TestRenameIntentAsync_Insert() { var initialText = -@"class C -{ - void M() - { - var thing = 1; - {|priorSelection:|}thing.ToString(); - } -}"; + """ + class C + { + void M() + { + var thing = 1; + {|priorSelection:|}thing.ToString(); + } + } + """; var currentText = -@"class C -{ - void M() - { - var thing = 1; - something.ToString(); - } -}"; + """ + class C + { + void M() + { + var thing = 1; + something.ToString(); + } + } + """; var expectedText = -@"class C -{ - void M() - { - var something = 1; - something.ToString(); - } -}"; + """ + class C + { + void M() + { + var something = 1; + something.ToString(); + } + } + """; await VerifyExpectedRenameAsync(initialText, currentText, expectedText, "something").ConfigureAwait(false); } @@ -86,32 +98,38 @@ void M() public async Task TestRenameIntentAsync_Delete() { var initialText = -@"class C -{ - void M() - { - var something = 1; - {|priorSelection:some|}thing.ToString(); - } -}"; + """ + class C + { + void M() + { + var something = 1; + {|priorSelection:some|}thing.ToString(); + } + } + """; var currentText = -@"class C -{ - void M() - { - var something = 1; - thing.ToString(); - } -}"; + """ + class C + { + void M() + { + var something = 1; + thing.ToString(); + } + } + """; var expectedText = -@"class C -{ - void M() - { - var thing = 1; - thing.ToString(); - } -}"; + """ + class C + { + void M() + { + var thing = 1; + thing.ToString(); + } + } + """; await VerifyExpectedRenameAsync(initialText, currentText, expectedText, "thing").ConfigureAwait(false); } @@ -120,69 +138,79 @@ void M() public async Task TestRenameIntentAsync_MultipleFiles() { var initialText = -@"namespace M -{ - public class C - { - public static string {|priorSelection:SomeString|} = string.Empty; - - void M() - { - var m = SomeString; - } - } -}"; + """ + namespace M + { + public class C + { + public static string {|priorSelection:SomeString|} = string.Empty; + + void M() + { + var m = SomeString; + } + } + } + """; var currentText = -@"namespace M -{ - public class C - { - public static string BetterString = string.Empty; - - void M() - { - var m = SomeString; - } - } -}"; + """ + namespace M + { + public class C + { + public static string BetterString = string.Empty; + + void M() + { + var m = SomeString; + } + } + } + """; var additionalDocuments = new string[] { -@"namespace M -{ - public class D - { - void M() - { - var m = C.SomeString; - } - } -}" + """ + namespace M + { + public class D + { + void M() + { + var m = C.SomeString; + } + } + } + """ }; var expectedTexts = new string[] { -@"namespace M -{ - public class C - { - public static string BetterString = string.Empty; - - void M() - { - var m = BetterString; - } - } -}", -@"namespace M -{ - public class D - { - void M() - { - var m = C.BetterString; - } - } -}" + """ + namespace M + { + public class C + { + public static string BetterString = string.Empty; + + void M() + { + var m = BetterString; + } + } + } + """, + """ + namespace M + { + public class D + { + void M() + { + var m = C.BetterString; + } + } + } + """ }; await VerifyExpectedRenameAsync(initialText, currentText, additionalDocuments, expectedTexts, "BetterString").ConfigureAwait(false); diff --git a/src/EditorFeatures/CSharpTest/Interactive/NavigateTo/InteractiveNavigateToTests.cs b/src/EditorFeatures/CSharpTest/Interactive/NavigateTo/InteractiveNavigateToTests.cs index 4846af4d2ed69..b6744f7ff090e 100644 --- a/src/EditorFeatures/CSharpTest/Interactive/NavigateTo/InteractiveNavigateToTests.cs +++ b/src/EditorFeatures/CSharpTest/Interactive/NavigateTo/InteractiveNavigateToTests.cs @@ -42,9 +42,11 @@ await TestAsync(testHost, composition, "", async w => public async Task FindClass(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, -@"class Goo -{ -}", async w => + """ + class Goo + { + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassPrivate); @@ -56,15 +58,17 @@ await TestAsync(testHost, composition, public async Task FindNestedClass(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - class Bar - { - internal class DogBed - { - } - } -}", async w => + """ + class Goo + { + class Bar + { + internal class DogBed + { + } + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("DogBed")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "DogBed", "[|DogBed|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -76,18 +80,20 @@ internal class DogBed public async Task FindMemberInANestedClass(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - class Bar - { - class DogBed - { - public void Method() - { - } - } - } -}", async w => + """ + class Goo + { + class Bar + { + class DogBed + { + public void Method() + { + } + } + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Method")).Single(); VerifyNavigateToResultItem(item, "Method", "[|Method|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo.Bar.DogBed", "Test")); @@ -99,11 +105,13 @@ public void Method() public async Task FindGenericClassWithConstraints(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"using System.Collections; + """ + using System.Collections; -class Goo where T : IEnumerable -{ -}", async w => + class Goo where T : IEnumerable + { + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassPrivate); @@ -115,14 +123,16 @@ class Goo where T : IEnumerable public async Task FindGenericMethodWithConstraints(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"using System; + """ + using System; -class Goo -{ - public void Bar(T item) where T : IComparable - { - } -}", async w => + class Goo + { + public void Bar(T item) where T : IComparable + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|](T)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -134,15 +144,17 @@ public void Bar(T item) where T : IComparable public async Task FindPartialClass(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"public partial class Goo -{ - int a; -} - -partial class Goo -{ - int b; -}", async w => + """ + public partial class Goo + { + int a; + } + + partial class Goo + { + int b; + } + """, async w => { var expecteditem1 = new NavigateToItem("Goo", NavigateToItemKind.Class, "csharp", null, null, s_emptyExactPatternMatch, null); var expecteditems = new List { expecteditem1, expecteditem1 }; @@ -158,9 +170,11 @@ partial class Goo public async Task FindTypesInMetadata(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"using System; + """ + using System; -Class Program { FileStyleUriParser f; }", async w => + Class Program { FileStyleUriParser f; } + """, async w => { var items = await _aggregator.GetItemsAsync("FileStyleUriParser"); Assert.Equal(0, items.Count()); @@ -172,12 +186,14 @@ await TestAsync(testHost, composition, public async Task FindClassInNamespace(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"namespace Bar -{ - class Goo - { - } -}", async w => + """ + namespace Bar + { + class Goo + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -189,9 +205,11 @@ class Goo public async Task FindStruct(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"struct Bar -{ -}", async w => + """ + struct Bar + { + } + """, async w => { var item = (await _aggregator.GetItemsAsync("B")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Structure, Glyph.StructurePrivate); @@ -203,12 +221,14 @@ await TestAsync(testHost, composition, public async Task FindEnum(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"enum Colors -{ - Red, - Green, - Blue -}", async w => + """ + enum Colors + { + Red, + Green, + Blue + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Colors")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Colors", "[|Colors|]", PatternMatchKind.Exact, NavigateToItemKind.Enum, Glyph.EnumPrivate); @@ -220,12 +240,14 @@ await TestAsync(testHost, composition, public async Task FindEnumMember(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"enum Colors -{ - Red, - Green, - Blue -}", async w => + """ + enum Colors + { + Red, + Green, + Blue + } + """, async w => { var item = (await _aggregator.GetItemsAsync("R")).Single(); VerifyNavigateToResultItem(item, "Red", "[|R|]ed", PatternMatchKind.Prefix, NavigateToItemKind.EnumItem, Glyph.EnumMemberPublic); @@ -237,10 +259,12 @@ await TestAsync(testHost, composition, public async Task FindConstField(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - const int bar = 7; -}", async w => + """ + class Goo + { + const int bar = 7; + } + """, async w => { var item = (await _aggregator.GetItemsAsync("ba")).Single(); VerifyNavigateToResultItem(item, "bar", "[|ba|]r", PatternMatchKind.Prefix, NavigateToItemKind.Constant, Glyph.ConstantPrivate); @@ -252,10 +276,12 @@ await TestAsync(testHost, composition, public async Task FindVerbatimIdentifier(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - string @string; -}", async w => + """ + class Goo + { + string @string; + } + """, async w => { var item = (await _aggregator.GetItemsAsync("string")).Single(); VerifyNavigateToResultItem(item, "string", "[|string|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -291,10 +317,12 @@ await TestAsync(testHost, composition, program, async w => public async Task FindAutoProperty(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - int Bar { get; set; } -}", async w => + """ + class Goo + { + int Bar { get; set; } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("B")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Property, Glyph.PropertyPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -306,10 +334,12 @@ await TestAsync(testHost, composition, public async Task FindMethod(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - void DoSomething(); -}", async w => + """ + class Goo + { + void DoSomething(); + } + """, async w => { var item = (await _aggregator.GetItemsAsync("DS")).Single(); VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething()", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -321,12 +351,14 @@ await TestAsync(testHost, composition, public async Task FindParameterizedMethod(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - void DoSomething(int a, string b) - { - } -}", async w => + """ + class Goo + { + void DoSomething(int a, string b) + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("DS")).Single(); VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething(int, string)", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -338,12 +370,14 @@ void DoSomething(int a, string b) public async Task FindConstructor(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - public Goo() - { - } -}", async w => + """ + class Goo + { + public Goo() + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -355,12 +389,14 @@ public Goo() public async Task FindParameterizedConstructor(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - public Goo(int i) - { - } -}", async w => + """ + class Goo + { + public Goo(int i) + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method); VerifyNavigateToResultItem(item, "Goo", "[|Goo|](int)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -372,12 +408,14 @@ public Goo(int i) public async Task FindStaticConstructor(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class Goo -{ - static Goo() - { - } -}", async w => + """ + class Goo + { + static Goo() + { + } + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method && t.Name != ".ctor"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|].static Goo()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -404,10 +442,12 @@ public async Task FindPartialMethods(TestHost testHost, Composition composition) public async Task FindPartialMethodDefinitionOnly(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"partial class Goo -{ - partial void Bar(); -}", async w => + """ + partial class Goo + { + partial void Bar(); + } + """, async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_1_2, "Goo", "test1.cs", "Test")); @@ -449,9 +489,11 @@ await TestAsync(testHost, composition, program, async w => public async Task FindInterface(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"public interface IGoo -{ -}", async w => + """ + public interface IGoo + { + } + """, async w => { var item = (await _aggregator.GetItemsAsync("IG")).Single(); VerifyNavigateToResultItem(item, "IGoo", "[|IG|]oo", PatternMatchKind.Prefix, NavigateToItemKind.Interface, Glyph.InterfacePublic); @@ -463,10 +505,12 @@ await TestAsync(testHost, composition, public async Task FindDelegateInNamespace(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"namespace Goo -{ - delegate void DoStuff(); -}", async w => + """ + namespace Goo + { + delegate void DoStuff(); + } + """, async w => { var item = (await _aggregator.GetItemsAsync("DoStuff")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "DoStuff", "[|DoStuff|]", PatternMatchKind.Exact, NavigateToItemKind.Delegate, Glyph.DelegateInternal); @@ -478,12 +522,14 @@ await TestAsync(testHost, composition, public async Task FindLambdaExpression(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"using System; + """ + using System; -class Goo -{ - Func sqr = x => x * x; -}", async w => + class Goo + { + Func sqr = x => x * x; + } + """, async w => { var item = (await _aggregator.GetItemsAsync("sqr")).Single(); VerifyNavigateToResultItem(item, "sqr", "[|sqr|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -495,23 +541,25 @@ class Goo public async Task OrderingOfConstructorsAndTypes(TestHost testHost, Composition composition) { await TestAsync(testHost, composition, - @"class C1 -{ - C1(int i) - { - } -} - -class C2 -{ - C2(float f) - { - } - - static C2() - { - } -}", async w => + """ + class C1 + { + C1(int i) + { + } + } + + class C2 + { + C2(float f) + { + } + + static C2() + { + } + } + """, async w => { var expecteditems = new List { @@ -533,9 +581,11 @@ public async Task StartStopSanity(TestHost testHost, Composition composition) { // Verify that multiple calls to start/stop and dispose don't blow up await TestAsync(testHost, composition, - @"public class Goo -{ -}", async w => + """ + public class Goo + { + } + """, async w => { // Do one set of queries Assert.Single((await _aggregator.GetItemsAsync("Goo")).Where(x => x.Kind != "Method")); @@ -554,7 +604,12 @@ await TestAsync(testHost, composition, [CombinatorialData] public async Task DescriptionItems(TestHost testHost, Composition composition) { - var code = "public\r\nclass\r\nGoo\r\n{ }"; + var code = """ + public + class + Goo + { } + """; await TestAsync(testHost, composition, code, async w => { var item = (await _aggregator.GetItemsAsync("G")).Single(x => x.Kind != "Method"); diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncLocalFunctionHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncLocalFunctionHighlighterTests.cs index b59b2827b66f7..2e4f2f21f83f9 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncLocalFunctionHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncLocalFunctionHighlighterTests.cs @@ -21,29 +21,31 @@ internal override Type GetHighlighterType() public async Task TestLocalFunction() { await TestAsync( -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } - async Task UseAsync() - { - {|Cursor:[|async|]|} Task function() - { - return [|await|] AsyncMethod(); - } - int result = await AsyncMethod(); - Task resultTask = AsyncMethod(); - result = await resultTask; - result = await function(); - } -}"); + async Task UseAsync() + { + {|Cursor:[|async|]|} Task function() + { + return [|await|] AsyncMethod(); + } + int result = await AsyncMethod(); + Task resultTask = AsyncMethod(); + result = await resultTask; + result = await function(); + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncMethodHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncMethodHighlighterTests.cs index 7afb9ba4e8160..1c1a47dc5ebb1 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncMethodHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AsyncMethodHighlighterTests.cs @@ -22,58 +22,62 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class AsyncExample -{ - {|Cursor:[|async|]|} Task AsyncMethod() - { - int hours = 24; - return hours; - } + class AsyncExample + { + {|Cursor:[|async|]|} Task AsyncMethod() + { + int hours = 24; + return hours; + } - async Task UseAsync() - { - Func> lambda = async () => - { - return await AsyncMethod(); - }; - int result = await AsyncMethod(); - Task resultTask = AsyncMethod(); - result = await resultTask; - result = await lambda(); - } -}"); + async Task UseAsync() + { + Func> lambda = async () => + { + return await AsyncMethod(); + }; + int result = await AsyncMethod(); + Task resultTask = AsyncMethod(); + result = await resultTask; + result = await lambda(); + } + } + """); } [Fact] public async Task TestExample2_1() { await TestAsync( -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } - {|Cursor:[|async|]|} Task UseAsync() - { - Func> lambda = async () => - { - return await AsyncMethod(); - }; - int result = [|await|] AsyncMethod(); - Task resultTask = AsyncMethod(); - result = [|await|] resultTask; - result = [|await|] lambda(); - } -}"); + {|Cursor:[|async|]|} Task UseAsync() + { + Func> lambda = async () => + { + return await AsyncMethod(); + }; + int result = [|await|] AsyncMethod(); + Task resultTask = AsyncMethod(); + result = [|await|] resultTask; + result = [|await|] lambda(); + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AwaitHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AwaitHighlighterTests.cs index 25e67ee900ec5..06da72b09d816 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/AwaitHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/AwaitHighlighterTests.cs @@ -23,312 +23,342 @@ internal override Type GetHighlighterType() public async Task TestExample2_2() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } - - [|async|] Task UseAsync() - { - Func> lambda = async () => - { - return await AsyncMethod(); - }; - int result = {|Cursor:[|await|]|} AsyncMethod(); - Task resultTask = AsyncMethod(); - result = [|await|] resultTask; - result = [|await|] lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } + + [|async|] Task UseAsync() + { + Func> lambda = async () => + { + return await AsyncMethod(); + }; + int result = {|Cursor:[|await|]|} AsyncMethod(); + Task resultTask = AsyncMethod(); + result = [|await|] resultTask; + result = [|await|] lambda(); + } + } + """); } [Fact] public async Task TestExample2_3() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } - - [|async|] Task UseAsync() - { - Func> lambda = async () => - { - return await AsyncMethod(); - }; - int result = [|await|] AsyncMethod(); - Task resultTask = AsyncMethod(); - result = {|Cursor:[|await|]|} resultTask; - result = [|await|] lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } + + [|async|] Task UseAsync() + { + Func> lambda = async () => + { + return await AsyncMethod(); + }; + int result = [|await|] AsyncMethod(); + Task resultTask = AsyncMethod(); + result = {|Cursor:[|await|]|} resultTask; + result = [|await|] lambda(); + } + } + """); } [Fact] public async Task TestExample2_4() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } - - [|async|] Task UseAsync() - { - Func> lambda = async () => - { - return await AsyncMethod(); - }; - int result = [|await|] AsyncMethod(); - Task resultTask = AsyncMethod(); - result = [|await|] resultTask; - result = {|Cursor:[|await|]|} lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } + + [|async|] Task UseAsync() + { + Func> lambda = async () => + { + return await AsyncMethod(); + }; + int result = [|await|] AsyncMethod(); + Task resultTask = AsyncMethod(); + result = [|await|] resultTask; + result = {|Cursor:[|await|]|} lambda(); + } + } + """); } [Fact] public async Task TestExample3_2() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task AsyncMethod() - { - int hours = 24; - return hours; - } - - async Task UseAsync() - { - Func> lambda = [|async|] () => - { - return {|Cursor:[|await|]|} AsyncMethod(); - }; - int result = await AsyncMethod(); - Task resultTask = AsyncMethod(); - result = await resultTask; - result = await lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task AsyncMethod() + { + int hours = 24; + return hours; + } + + async Task UseAsync() + { + Func> lambda = [|async|] () => + { + return {|Cursor:[|await|]|} AsyncMethod(); + }; + int result = await AsyncMethod(); + Task resultTask = AsyncMethod(); + result = await resultTask; + result = await lambda(); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/573625")] public async Task TestNestedAwaits1() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task> AsyncMethod() - { - return NewMethod(); - } - - private static Task NewMethod() - { - int hours = 24; - return hours; - } - - async Task UseAsync() - { - Func> lambda = [|async|] () => - { - return {|Cursor:[|await await|]|} AsyncMethod(); - }; - int result = await await AsyncMethod(); - Task> resultTask = AsyncMethod(); - result = await await resultTask; - result = await lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task> AsyncMethod() + { + return NewMethod(); + } + + private static Task NewMethod() + { + int hours = 24; + return hours; + } + + async Task UseAsync() + { + Func> lambda = [|async|] () => + { + return {|Cursor:[|await await|]|} AsyncMethod(); + }; + int result = await await AsyncMethod(); + Task> resultTask = AsyncMethod(); + result = await await resultTask; + result = await lambda(); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/573625")] public async Task TestNestedAwaits2() { await TestAsync( -@"using System; -using System.Threading.Tasks; - -class AsyncExample -{ - async Task> AsyncMethod() - { - return NewMethod(); - } - - private static Task NewMethod() - { - int hours = 24; - return hours; - } - - [|async|] Task UseAsync() - { - Func> lambda = async () => - { - return await await AsyncMethod(); - }; - int result = {|Cursor:[|await await|]|} AsyncMethod(); - Task> resultTask = AsyncMethod(); - result = [|await await|] resultTask; - result = [|await|] lambda(); - } -}"); + """ + using System; + using System.Threading.Tasks; + + class AsyncExample + { + async Task> AsyncMethod() + { + return NewMethod(); + } + + private static Task NewMethod() + { + int hours = 24; + return hours; + } + + [|async|] Task UseAsync() + { + Func> lambda = async () => + { + return await await AsyncMethod(); + }; + int result = {|Cursor:[|await await|]|} AsyncMethod(); + Task> resultTask = AsyncMethod(); + result = [|await await|] resultTask; + result = [|await|] lambda(); + } + } + """); } [Fact] public async Task TestAwaitUsing_OnAsync() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - {|Cursor:[|async|]|} Task M() - { - [|await|] using (var x = new object()); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + {|Cursor:[|async|]|} Task M() + { + [|await|] using (var x = new object()); + } + } + """); } [Fact] public async Task TestAwaitUsing_OnAwait() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - [|async|] Task M() - { - {|Cursor:[|await|]|} using (var x = new object()); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + [|async|] Task M() + { + {|Cursor:[|await|]|} using (var x = new object()); + } + } + """); } [Fact] public async Task TestAwaitUsingDeclaration_OnAsync() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - {|Cursor:[|async|]|} Task M() - { - [|await|] using var x = new object(); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + {|Cursor:[|async|]|} Task M() + { + [|await|] using var x = new object(); + } + } + """); } [Fact] public async Task TestAwaitUsingDeclaration_OnAwait() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - [|async|] Task M() - { - {|Cursor:[|await|]|} using var x = new object(); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + [|async|] Task M() + { + {|Cursor:[|await|]|} using var x = new object(); + } + } + """); } [Fact] public async Task TestAwaitForEach_OnAsync() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - {|Cursor:[|async|]|} Task M() - { - foreach [|await|] (var n in new int[] { }); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + {|Cursor:[|async|]|} Task M() + { + foreach [|await|] (var n in new int[] { }); + } + } + """); } [Fact] public async Task TestAwaitForEach_OnAwait() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - [|async|] Task M() - { - foreach {|Cursor:[|await|]|} (var n in new int[] { }); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + [|async|] Task M() + { + foreach {|Cursor:[|await|]|} (var n in new int[] { }); + } + } + """); } [Fact] public async Task TestForEachVariableAwait_OnAsync() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - {|Cursor:[|async|]|} Task M() - { - foreach [|await|] (var (a, b) in new (int, int)[] { }); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + {|Cursor:[|async|]|} Task M() + { + foreach [|await|] (var (a, b) in new (int, int)[] { }); + } + } + """); } [Fact] public async Task TestForEachVariableAwait_OnAwait() { await TestAsync( -@"using System.Threading.Tasks; - -class C -{ - [|async|] Task M() - { - foreach {|Cursor:[|await|]|} (var (a, b) in new (int, int)[] { }); - } -}"); + """ + using System.Threading.Tasks; + + class C + { + [|async|] Task M() + { + foreach {|Cursor:[|await|]|} (var (a, b) in new (int, int)[] { }); + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60400")] public async Task TestTopLevelStatements() { await TestAsync( -@"[|await|] Task.Delay(1000); -{|Cursor:[|await|]|} Task.Run(() => { })"); + """ + [|await|] Task.Delay(1000); + {|Cursor:[|await|]|} Task.Run(() => { }) + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedExpressionHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedExpressionHighlighterTests.cs index e3e106a05da1f..18fa05058ec71 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedExpressionHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedExpressionHighlighterTests.cs @@ -22,41 +22,45 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - short x = short.MaxValue; - short y = short.MaxValue; - int z; - try - { - z = {|Cursor:[|checked|]|}((short)(x + y)); - } - catch (OverflowException e) - { - z = -1; - } + """ + class C + { + void M() + { + short x = short.MaxValue; + short y = short.MaxValue; + int z; + try + { + z = {|Cursor:[|checked|]|}((short)(x + y)); + } + catch (OverflowException e) + { + z = -1; + } - return z; - } -}"); + return z; + } + } + """); } [Fact] public async Task TestExample2_1() { await TestAsync( -@"class C -{ - void M() - { - short x = short.MaxValue; - short y = short.MaxValue; - int z = {|Cursor:[|unchecked|]|}((short)(x + y)); - return z; - } -}"); + """ + class C + { + void M() + { + short x = short.MaxValue; + short y = short.MaxValue; + int z = {|Cursor:[|unchecked|]|}((short)(x + y)); + return z; + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedStatementHighlighterTests.cs index 3dc1741cf4a89..0b119d7020616 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/CheckedStatementHighlighterTests.cs @@ -22,52 +22,56 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - short x = 0; - short y = 100; - while (true) - { - {|Cursor:[|checked|]|} - { - x++; - } + """ + class C + { + void M() + { + short x = 0; + short y = 100; + while (true) + { + {|Cursor:[|checked|]|} + { + x++; + } - unchecked - { - y++; - } - } - } -}"); + unchecked + { + y++; + } + } + } + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - void M() - { - short x = 0; - short y = 100; - while (true) - { - checked - { - x++; - } + """ + class C + { + void M() + { + short x = 0; + short y = 100; + while (true) + { + checked + { + x++; + } - {|Cursor:[|unchecked|]|} - { - y++; - } - } - } -}"); + {|Cursor:[|unchecked|]|} + { + y++; + } + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/ConditionalPreprocessorHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/ConditionalPreprocessorHighlighterTests.cs index a08b904799a6a..a3cc17b2a0657 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/ConditionalPreprocessorHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/ConditionalPreprocessorHighlighterTests.cs @@ -22,243 +22,261 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - - - #define Debug -#undef Trace - class PurchaseTransaction - { - void Commit() - { -{|Cursor:[|#if|]|} Debug - CheckConsistency(); -#if Trace - WriteToLog(this.ToString()); -#else - Exit(); -#endif -[|#endif|] - CommitHelper(); - } - } -} -}"); + """ + class C + { + void M() + { + + + #define Debug + #undef Trace + class PurchaseTransaction + { + void Commit() + { + {|Cursor:[|#if|]|} Debug + CheckConsistency(); + #if Trace + WriteToLog(this.ToString()); + #else + Exit(); + #endif + [|#endif|] + CommitHelper(); + } + } + } + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - void M() - { - - - #define Debug -#undef Trace - class PurchaseTransaction - { - void Commit() - { -[|#if|] Debug - CheckConsistency(); -#if Trace - WriteToLog(this.ToString()); -#else - Exit(); -#endif -{|Cursor:[|#endif|]|} - CommitHelper(); - } - } -} -}"); + """ + class C + { + void M() + { + + + #define Debug + #undef Trace + class PurchaseTransaction + { + void Commit() + { + [|#if|] Debug + CheckConsistency(); + #if Trace + WriteToLog(this.ToString()); + #else + Exit(); + #endif + {|Cursor:[|#endif|]|} + CommitHelper(); + } + } + } + } + """); } [Fact] public async Task TestExample2_1() { await TestAsync( -@"class C -{ - void M() - { - - - #define Debug -#undef Trace - class PurchaseTransaction - { - void Commit() - { -#if Debug - CheckConsistency(); -{|Cursor:[|#if|]|} Trace - WriteToLog(this.ToString()); -[|#else|] - Exit(); -[|#endif|] -#endif - CommitHelper(); - } - } -} -}"); + """ + class C + { + void M() + { + + + #define Debug + #undef Trace + class PurchaseTransaction + { + void Commit() + { + #if Debug + CheckConsistency(); + {|Cursor:[|#if|]|} Trace + WriteToLog(this.ToString()); + [|#else|] + Exit(); + [|#endif|] + #endif + CommitHelper(); + } + } + } + } + """); } [Fact] public async Task TestExample2_2() { await TestAsync( -@"class C -{ - void M() - { - - - #define Debug -#undef Trace - class PurchaseTransaction - { - void Commit() - { -#if Debug - CheckConsistency(); -[|#if|] Trace - WriteToLog(this.ToString()); -{|Cursor:[|#else|]|} - Exit(); -[|#endif|] -#endif - CommitHelper(); - } - } -} -}"); + """ + class C + { + void M() + { + + + #define Debug + #undef Trace + class PurchaseTransaction + { + void Commit() + { + #if Debug + CheckConsistency(); + [|#if|] Trace + WriteToLog(this.ToString()); + {|Cursor:[|#else|]|} + Exit(); + [|#endif|] + #endif + CommitHelper(); + } + } + } + } + """); } [Fact] public async Task TestExample2_3() { await TestAsync( -@"class C -{ - void M() - { - - - #define Debug -#undef Trace - class PurchaseTransaction - { - void Commit() - { -#if Debug - CheckConsistency(); -[|#if|] Trace - WriteToLog(this.ToString()); -[|#else|] - Exit(); -{|Cursor:[|#endif|]|} -#endif - CommitHelper(); - } - } -} -}"); + """ + class C + { + void M() + { + + + #define Debug + #undef Trace + class PurchaseTransaction + { + void Commit() + { + #if Debug + CheckConsistency(); + [|#if|] Trace + WriteToLog(this.ToString()); + [|#else|] + Exit(); + {|Cursor:[|#endif|]|} + #endif + CommitHelper(); + } + } + } + } + """); } [Fact] public async Task TestExample4_1() { await TestAsync( -@"class C -{ - void M() - { -#define Goo1 -#define Goo2 + """ + class C + { + void M() + { + #define Goo1 + #define Goo2 -{|Cursor:[|#if|]|} Goo1 + {|Cursor:[|#if|]|} Goo1 -[|#elif|] Goo2 + [|#elif|] Goo2 -[|#else|] + [|#else|] -[|#endif|] - } -}"); + [|#endif|] + } + } + """); } [Fact] public async Task TestExample4_2() { await TestAsync( -@"class C -{ - void M() - { -#define Goo1 -#define Goo2 + """ + class C + { + void M() + { + #define Goo1 + #define Goo2 -[|#if|] Goo1 + [|#if|] Goo1 -{|Cursor:[|#elif|]|} Goo2 + {|Cursor:[|#elif|]|} Goo2 -[|#else|] + [|#else|] -[|#endif|] - } -}"); + [|#endif|] + } + } + """); } [Fact] public async Task TestExample4_3() { await TestAsync( -@"class C -{ - void M() - { -#define Goo1 -#define Goo2 + """ + class C + { + void M() + { + #define Goo1 + #define Goo2 -[|#if|] Goo1 + [|#if|] Goo1 -[|#elif|] Goo2 + [|#elif|] Goo2 -{|Cursor:[|#else|]|} + {|Cursor:[|#else|]|} -[|#endif|] - } -}"); + [|#endif|] + } + } + """); } [Fact] public async Task TestExample4_4() { await TestAsync( -@"class C -{ - void M() - { -#define Goo1 -#define Goo2 + """ + class C + { + void M() + { + #define Goo1 + #define Goo2 -[|#if|] Goo1 + [|#if|] Goo1 -[|#elif|] Goo2 + [|#elif|] Goo2 -[|#else|] + [|#else|] -{|Cursor:[|#endif|]|} - } -}"); + {|Cursor:[|#endif|]|} + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/IfStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/IfStatementHighlighterTests.cs index ba44ae385d50b..9e1117c4c6759 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/IfStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/IfStatementHighlighterTests.cs @@ -22,666 +22,718 @@ internal override Type GetHighlighterType() public async Task TestIfStatementWithIfAndSingleElse1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|} (a < 5) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|} (a < 5) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndSingleElse2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElse1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|} (a < 5) - { - // blah - } - [|else if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|} (a < 5) + { + // blah + } + [|else if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElse2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - {|Cursor:[|else if|]|} (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + {|Cursor:[|else if|]|} (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElse3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else if|] (a == 10) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else if|] (a == 10) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithElseIfOnDifferentLines1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|} (a < 5) - { - // blah - } - [|else|] - [|if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|} (a < 5) + { + // blah + } + [|else|] + [|if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithElseIfOnDifferentLines2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - {|Cursor:[|else|]|} - [|if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + {|Cursor:[|else|]|} + [|if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithElseIfOnDifferentLines3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else|] - {|Cursor:[|if|]|} (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else|] + {|Cursor:[|if|]|} (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithElseIfOnDifferentLines4() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else|] - [|if|] (a == 10) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else|] + [|if|] (a == 10) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElseTouching1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|}(a < 5) - { - // blah - } - [|else if|](a == 10) - { - // blah - } - [|else|]{ - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|}(a < 5) + { + // blah + } + [|else if|](a == 10) + { + // blah + } + [|else|]{ + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElseTouching2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|](a < 5) - { - // blah - } - {|Cursor:[|else if|]|}(a == 10) - { - // blah - } - [|else|]{ - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|](a < 5) + { + // blah + } + {|Cursor:[|else if|]|}(a == 10) + { + // blah + } + [|else|]{ + // blah + } + } + } + """); } [Fact] public async Task TestIfStatementWithIfAndElseIfAndElseTouching3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|](a < 5) - { - // blah - } - [|else if|](a == 10) - { - // blah - } - {|Cursor:[|else|]|}{ - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|](a < 5) + { + // blah + } + [|else if|](a == 10) + { + // blah + } + {|Cursor:[|else|]|}{ + // blah + } + } + } + """); } [Fact] public async Task TestExtraSpacesBetweenElseAndIf1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|} (a < 5) - { - // blah - } - [|else if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|} (a < 5) + { + // blah + } + [|else if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestExtraSpacesBetweenElseAndIf2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - {|Cursor:[|else if|]|} (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + {|Cursor:[|else if|]|} (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestExtraSpacesBetweenElseAndIf3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else if|] (a == 10) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else if|] (a == 10) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestCommentBetweenElseIf1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - {|Cursor:[|if|]|} (a < 5) - { - // blah - } - [|else|] /* test */ [|if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + {|Cursor:[|if|]|} (a < 5) + { + // blah + } + [|else|] /* test */ [|if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestCommentBetweenElseIf2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - {|Cursor:[|else|]|} /* test */ [|if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + {|Cursor:[|else|]|} /* test */ [|if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestCommentBetweenElseIf3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else|] /* test */ {|Cursor:[|if|]|} (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else|] /* test */ {|Cursor:[|if|]|} (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestCommentBetweenElseIf4() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - [|if|] (a < 5) - { - // blah - } - [|else|] /* test */ [|if|] (a == 10) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + [|if|] (a < 5) + { + // blah + } + [|else|] /* test */ [|if|] (a == 10) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestNestedIfDoesNotHighlight1() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - int b = 15; - {|Cursor:[|if|]|} (a < 5) - { - // blah - if (b < 15) - b = 15; - else - b = 14; - } - [|else if|] (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + int b = 15; + {|Cursor:[|if|]|} (a < 5) + { + // blah + if (b < 15) + b = 15; + else + b = 14; + } + [|else if|] (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestNestedIfDoesNotHighlight2() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - int b = 15; - [|if|] (a < 5) - { - // blah - if (b < 15) - b = 15; - else - b = 14; - } - {|Cursor:[|else if|]|} (a == 10) - { - // blah - } - [|else|] - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + int b = 15; + [|if|] (a < 5) + { + // blah + if (b < 15) + b = 15; + else + b = 14; + } + {|Cursor:[|else if|]|} (a == 10) + { + // blah + } + [|else|] + { + // blah + } + } + } + """); } [Fact] public async Task TestNestedIfDoesNotHighlight3() { await TestAsync( -@"public class C -{ - public void Goo() - { - int a = 10; - int b = 15; - [|if|] (a < 5) - { - // blah - if (b < 15) - b = 15; - else - b = 14; - } - [|else if|] (a == 10) - { - // blah - } - {|Cursor:[|else|]|} - { - // blah - } - } -}"); + """ + public class C + { + public void Goo() + { + int a = 10; + int b = 15; + [|if|] (a < 5) + { + // blah + if (b < 15) + b = 15; + else + b = 14; + } + [|else if|] (a == 10) + { + // blah + } + {|Cursor:[|else|]|} + { + // blah + } + } + } + """); } [Fact] public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|if|]|} (x) - { - if (y) - { - F(); - } - else if (z) - { - G(); - } - else - { - H(); - } - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|if|]|} (x) + { + if (y) + { + F(); + } + else if (z) + { + G(); + } + else + { + H(); + } + } + } + } + """); } [Fact] public async Task TestExample2_1() { await TestAsync( -@"class C -{ - void M() - { - if (x) - { - {|Cursor:[|if|]|} (y) - { - F(); - } - [|else if|] (z) - { - G(); - } - [|else|] - { - H(); - } - } - } -}"); + """ + class C + { + void M() + { + if (x) + { + {|Cursor:[|if|]|} (y) + { + F(); + } + [|else if|] (z) + { + G(); + } + [|else|] + { + H(); + } + } + } + } + """); } [Fact] public async Task TestExample2_2() { await TestAsync( -@"class C -{ - void M() - { - if (x) - { - [|if|] (y) - { - F(); - } - {|Cursor:[|else if|]|} (z) - { - G(); - } - [|else|] - { - H(); - } - } - } -}"); + """ + class C + { + void M() + { + if (x) + { + [|if|] (y) + { + F(); + } + {|Cursor:[|else if|]|} (z) + { + G(); + } + [|else|] + { + H(); + } + } + } + } + """); } [Fact] public async Task TestExample2_3() { await TestAsync( -@"class C -{ - void M() - { - if (x) - { - [|if|] (y) - { - F(); - } - [|else if|] (z) - { - G(); - } - {|Cursor:[|else|]|} - { - H(); - } - } - } -}"); + """ + class C + { + void M() + { + if (x) + { + [|if|] (y) + { + F(); + } + [|else if|] (z) + { + G(); + } + {|Cursor:[|else|]|} + { + H(); + } + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/LockStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/LockStatementHighlighterTests.cs index ef8642a61f3c0..962334c89d256 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/LockStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/LockStatementHighlighterTests.cs @@ -21,27 +21,29 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class Account -{ - object lockObj = new object(); - int balance; + """ + class Account + { + object lockObj = new object(); + int balance; - int Withdraw(int amount) - { - {|Cursor:[|lock|]|} (lockObj) - { - if (balance >= amount) - { - balance = balance – amount; - return amount; - } - else - { - return -1; - } - } - } -}"); + int Withdraw(int amount) + { + {|Cursor:[|lock|]|} (lockObj) + { + if (balance >= amount) + { + balance = balance – amount; + return amount; + } + else + { + return -1; + } + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/LoopHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/LoopHighlighterTests.cs index 88d79d188c2ed..04bf3058ca4d6 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/LoopHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/LoopHighlighterTests.cs @@ -22,687 +22,733 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|while|]|} (true) - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|while|]|} (true) + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - void M() - { - [|while|] (true) - { - if (x) - { - {|Cursor:[|break|]|}; - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + [|while|] (true) + { + if (x) + { + {|Cursor:[|break|]|}; + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample1_3() { await TestAsync( -@"class C -{ - void M() - { - [|while|] (true) - { - if (x) - { - [|break|]; - } - else - { - {|Cursor:[|continue|]|}; - } - } - } -}"); + """ + class C + { + void M() + { + [|while|] (true) + { + if (x) + { + [|break|]; + } + else + { + {|Cursor:[|continue|]|}; + } + } + } + } + """); } [Fact] public async Task TestExample2_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|do|]|} - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - [|while|] (true); - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|do|]|} + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + [|while|] (true); + } + } + """); } [Fact] public async Task TestExample2_2() { await TestAsync( -@"class C -{ - void M() - { - [|do|] - { - if (x) - { - {|Cursor:[|break|]|}; - } - else - { - [|continue|]; - } - } - [|while|] (true); - } -}"); + """ + class C + { + void M() + { + [|do|] + { + if (x) + { + {|Cursor:[|break|]|}; + } + else + { + [|continue|]; + } + } + [|while|] (true); + } + } + """); } [Fact] public async Task TestExample2_3() { await TestAsync( -@"class C -{ - void M() - { - [|do|] - { - if (x) - { - [|break|]; - } - else - { - {|Cursor:[|continue|]|}; - } - } - [|while|] (true); - } -}"); + """ + class C + { + void M() + { + [|do|] + { + if (x) + { + [|break|]; + } + else + { + {|Cursor:[|continue|]|}; + } + } + [|while|] (true); + } + } + """); } [Fact] public async Task TestExample2_4() { await TestAsync( -@"class C -{ - void M() - { - [|do|] - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - {|Cursor:[|while|]|} (true); - } -}"); + """ + class C + { + void M() + { + [|do|] + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + {|Cursor:[|while|]|} (true); + } + } + """); } [Fact] public async Task TestExample2_5() { await TestAsync( -@"class C -{ - void M() - { - do - { - if (x) - { - break; - } - else - { - continue; - } - } - while {|Cursor:(true)|}; - } -}"); + """ + class C + { + void M() + { + do + { + if (x) + { + break; + } + else + { + continue; + } + } + while {|Cursor:(true)|}; + } + } + """); } [Fact] public async Task TestExample2_6() { await TestAsync( -@"class C -{ - void M() - { - [|do|] - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - [|while|] (true);{|Cursor:|} - } -}"); + """ + class C + { + void M() + { + [|do|] + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + [|while|] (true);{|Cursor:|} + } + } + """); } [Fact] public async Task TestExample3_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|for|]|} (int i = 0; i < 10; i++) - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|for|]|} (int i = 0; i < 10; i++) + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample3_2() { await TestAsync( -@"class C -{ - void M() - { - [|for|] (int i = 0; i < 10; i++) - { - if (x) - { - {|Cursor:[|break|];|} - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + [|for|] (int i = 0; i < 10; i++) + { + if (x) + { + {|Cursor:[|break|];|} + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample3_3() { await TestAsync( -@"class C -{ - void M() - { - [|for|] (int i = 0; i < 10; i++) - { - if (x) - { - [|break|]; - } - else - { - {|Cursor:[|continue|];|} - } - } - } -}"); + """ + class C + { + void M() + { + [|for|] (int i = 0; i < 10; i++) + { + if (x) + { + [|break|]; + } + else + { + {|Cursor:[|continue|];|} + } + } + } + } + """); } [Fact] public async Task TestExample4_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|foreach|]|} (var a in x) - { - if (x) - { - [|break|]; - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|foreach|]|} (var a in x) + { + if (x) + { + [|break|]; + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample4_2() { await TestAsync( -@"class C -{ - void M() - { - [|foreach|] (var a in x) - { - if (x) - { - {|Cursor:[|break|];|} - } - else - { - [|continue|]; - } - } - } -}"); + """ + class C + { + void M() + { + [|foreach|] (var a in x) + { + if (x) + { + {|Cursor:[|break|];|} + } + else + { + [|continue|]; + } + } + } + } + """); } [Fact] public async Task TestExample4_3() { await TestAsync( -@"class C -{ - void M() - { - [|foreach|] (var a in x) - { - if (x) - { - [|break|]; - } - else - { - {|Cursor:[|continue|];|} - } - } - } -}"); + """ + class C + { + void M() + { + [|foreach|] (var a in x) + { + if (x) + { + [|break|]; + } + else + { + {|Cursor:[|continue|];|} + } + } + } + } + """); } [Fact] public async Task TestNestedExample1_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|foreach|]|} (var a in x) - { - if (a) - { - [|break|]; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + {|Cursor:[|foreach|]|} (var a in x) { - do + if (a) + { + [|break|]; + } + else + { + switch (b) + { + case 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + break; + } + } + + for (int i = 0; i < 10; i++) { break; } - while (false); - break; } - - break; + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_2() { await TestAsync( -@"class C -{ - void M() - { - [|foreach|] (var a in x) - { - if (a) - { - {|Cursor:[|break|];|} - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + [|foreach|] (var a in x) { - do + if (a) + { + {|Cursor:[|break|];|} + } + else + { + switch (b) + { + case 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + break; + } + } + + for (int i = 0; i < 10; i++) { break; } - while (false); - break; } - - break; + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_3() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - {|Cursor:[|do|]|} + if (a) { - [|break|]; + break; + } + else + { + switch (b) + { + case 0: + while (true) + { + {|Cursor:[|do|]|} + { + [|break|]; + } + [|while|] (false); + break; + } + + break; + } } - [|while|] (false); - break; - } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_4() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - [|do|] + if (a) { - {|Cursor:[|break|];|} + break; + } + else + { + switch (b) + { + case 0: + while (true) + { + [|do|] + { + {|Cursor:[|break|];|} + } + [|while|] (false); + break; + } + + break; + } } - [|while|] (false); - break; - } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_5() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - [|do|] + if (a) + { + break; + } + else { - [|break|]; + switch (b) + { + case 0: + while (true) + { + [|do|] + { + [|break|]; + } + {|Cursor:[|while|]|} (false); + break; + } + + break; + } } - {|Cursor:[|while|]|} (false); - break; - } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_6() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - [|do|] + if (a) { - [|break|]; + break; + } + else + { + switch (b) + { + case 0: + while (true) + { + [|do|] + { + [|break|]; + } + [|while|] (false);{|Cursor:|} + break; + } + + break; + } } - [|while|] (false);{|Cursor:|} - break; - } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_7() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - {|Cursor:[|while|]|} (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - [|break|]; - } + else + { + switch (b) + { + case 0: + {|Cursor:[|while|]|} (true) + { + do + { + break; + } + while (false); + [|break|]; + } + + break; + } + } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_8() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - [|while|] (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - {|Cursor:[|break|];|} - } + else + { + switch (b) + { + case 0: + [|while|] (true) + { + do + { + break; + } + while (false); + {|Cursor:[|break|];|} + } + + break; + } + } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } // TestNestedExample1 9-13 are in SwitchStatementHighlighterTests.cs @@ -711,480 +757,506 @@ void M() public async Task TestNestedExample1_14() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + switch (b) + { + case 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + break; + } + } - break; + {|Cursor:[|for|]|} (int i = 0; i < 10; i++) + { + [|break|]; + } + } + } } - } - - {|Cursor:[|for|]|} (int i = 0; i < 10; i++) - { - [|break|]; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_15() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case 0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + switch (b) + { + case 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + break; + } + } - break; + [|for|] (int i = 0; i < 10; i++) + { + {|Cursor:[|break|];|} + } + } + } } - } - - [|for|] (int i = 0; i < 10; i++) - { - {|Cursor:[|break|];|} - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|foreach|]|} (var a in x) - { - if (a) - { - [|continue|]; - } - else - { - while (true) + """ + class C { - do + void M() { - continue; + {|Cursor:[|foreach|]|} (var a in x) + { + if (a) + { + [|continue|]; + } + else + { + while (true) + { + do + { + continue; + } + while (false); + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - while (false); - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_2() { await TestAsync( -@"class C -{ - void M() - { - [|foreach|] (var a in x) - { - if (a) - { - {|Cursor:[|continue|];|} - } - else - { - while (true) + """ + class C { - do + void M() { - continue; + [|foreach|] (var a in x) + { + if (a) + { + {|Cursor:[|continue|];|} + } + else + { + while (true) + { + do + { + continue; + } + while (false); + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - while (false); - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_3() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - {|Cursor:[|do|]|} + void M() { - [|continue|]; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + {|Cursor:[|do|]|} + { + [|continue|]; + } + [|while|] (false); + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - [|while|] (false); - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_4() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - [|do|] + void M() { - {|Cursor:[|continue|];|} + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + [|do|] + { + {|Cursor:[|continue|];|} + } + [|while|] (false); + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - [|while|] (false); - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_5() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - [|do|] + void M() { - [|continue|]; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + [|do|] + { + [|continue|]; + } + {|Cursor:[|while|]|} (false); + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - {|Cursor:[|while|]|} (false); - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_6() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - do + void M() { - continue; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + do + { + continue; + } + while {|Cursor:(false)|}; + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - while {|Cursor:(false)|}; - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_7() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - [|do|] + void M() { - [|continue|]; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + [|do|] + { + [|continue|]; + } + [|while|] (false);{|Cursor:|} + continue; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - [|while|] (false);{|Cursor:|} - continue; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_8() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - {|Cursor:[|while|]|} (true) + """ + class C { - do + void M() { - continue; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + {|Cursor:[|while|]|} (true) + { + do + { + continue; + } + while (false); + [|continue|]; + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - while (false); - [|continue|]; } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_9() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - [|while|] (true) + """ + class C { - do + void M() { - continue; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + [|while|] (true) + { + do + { + continue; + } + while (false); + {|Cursor:[|continue|];|} + } + } + + for (int i = 0; i < 10; i++) + { + continue; + } + } } - while (false); - {|Cursor:[|continue|];|} } - } - - for (int i = 0; i < 10; i++) - { - continue; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_10() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - do + void M() { - continue; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + do + { + continue; + } + while (false); + continue; + } + } + + {|Cursor:[|for|]|} (int i = 0; i < 10; i++) + { + [|continue|]; + } + } } - while (false); - continue; } - } - - {|Cursor:[|for|]|} (int i = 0; i < 10; i++) - { - [|continue|]; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample2_11() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - continue; - } - else - { - while (true) + """ + class C { - do + void M() { - continue; + foreach (var a in x) + { + if (a) + { + continue; + } + else + { + while (true) + { + do + { + continue; + } + while (false); + continue; + } + } + + [|for|] (int i = 0; i < 10; i++) + { + {|Cursor:[|continue|];|} + } + } } - while (false); - continue; } - } - - [|for|] (int i = 0; i < 10; i++) - { - {|Cursor:[|continue|];|} - } - } - } -}"); + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/RegionHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/RegionHighlighterTests.cs index 13255702bfb61..e821b6dbe4acb 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/RegionHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/RegionHighlighterTests.cs @@ -22,92 +22,104 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - {|Cursor:[|#region|]|} Main - static void Main() - { - } - [|#endregion|] -}"); + """ + class C + { + {|Cursor:[|#region|]|} Main + static void Main() + { + } + [|#endregion|] + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - [|#region|] Main - static void Main() - { - } - {|Cursor:[|#endregion|]|} -}"); + """ + class C + { + [|#region|] Main + static void Main() + { + } + {|Cursor:[|#endregion|]|} + } + """); } [Fact] public async Task TestNestedExample1_1() { await TestAsync( -@"class C -{ - {|Cursor:[|#region|]|} Main - static void Main() - { - #region body - #endregion - } - [|#endregion|] -}"); + """ + class C + { + {|Cursor:[|#region|]|} Main + static void Main() + { + #region body + #endregion + } + [|#endregion|] + } + """); } [Fact] public async Task TestNestedExample1_2() { await TestAsync( -@"class C -{ - #region Main - static void Main() - { - {|Cursor:[|#region|]|} body - [|#endregion|] - } - #endregion -}"); + """ + class C + { + #region Main + static void Main() + { + {|Cursor:[|#region|]|} body + [|#endregion|] + } + #endregion + } + """); } [Fact] public async Task TestNestedExample1_3() { await TestAsync( -@"class C -{ - #region Main - static void Main() - { - [|#region|] body - {|Cursor:[|#endregion|]|} - } - #endregion -}"); + """ + class C + { + #region Main + static void Main() + { + [|#region|] body + {|Cursor:[|#endregion|]|} + } + #endregion + } + """); } [Fact] public async Task TestNestedExample1_4() { await TestAsync( -@"class C -{ - [|#region|] Main - static void Main() - { - #region body - #endregion - } - {|Cursor:[|#endregion|]|} -}"); + """ + class C + { + [|#region|] Main + static void Main() + { + #region body + #endregion + } + {|Cursor:[|#endregion|]|} + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/ReturnStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/ReturnStatementHighlighterTests.cs index defa71d3c38ec..7bfeb9914243a 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/ReturnStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/ReturnStatementHighlighterTests.cs @@ -22,454 +22,500 @@ internal override Type GetHighlighterType() public async Task TestInLambda() { await TestAsync( -@"static double CalculateArea(double radius) -{ - Func f = r => { - if (Double.IsNan(r)) - { - {|Cursor:[|return|]|} Double.NaN; - } - else - { - [|return|] r * r * Math.PI; - } - }; - return calcArea(radius); -}"); + """ + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + {|Cursor:[|return|]|} Double.NaN; + } + else + { + [|return|] r * r * Math.PI; + } + }; + return calcArea(radius); + } + """); } [Fact] public async Task TestInLambda_NotOnReturnValue() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - return {|Cursor:Double.NaN|}; - } - else - { - return r * r * Math.PI; - } - }; - return calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + return {|Cursor:Double.NaN|}; + } + else + { + return r * r * Math.PI; + } + }; + return calcArea(radius); + } + } + """); } [Fact] public async Task TestInLambda_OnSemicolon() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - [|return|] Double.NaN;{|Cursor:|} - } - else - { - [|return|] r * r * Math.PI; - } - }; - return calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + [|return|] Double.NaN;{|Cursor:|} + } + else + { + [|return|] r * r * Math.PI; + } + }; + return calcArea(radius); + } + } + """); } [Fact] public async Task TestInLambda_SecondOccurence() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - [|return|] Double.NaN; - } - else - { - {|Cursor:[|return|]|} r * r * Math.PI; - } - }; - return calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + [|return|] Double.NaN; + } + else + { + {|Cursor:[|return|]|} r * r * Math.PI; + } + }; + return calcArea(radius); + } + } + """); } [Fact] public async Task TestInLambda_SecondOccurence_NotOnReturnValue() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - return Double.NaN; - } - else - { - return {|Cursor:r * r * Math.PI|}; - } - }; - return calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + return Double.NaN; + } + else + { + return {|Cursor:r * r * Math.PI|}; + } + }; + return calcArea(radius); + } + } + """); } [Fact] public async Task TestInLambda_SecondOccurence_OnSemicolon() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - [|return|] Double.NaN; - } - else - { - [|return|] r * r * Math.PI;{|Cursor:|} - } - }; - return calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + [|return|] Double.NaN; + } + else + { + [|return|] r * r * Math.PI;{|Cursor:|} + } + }; + return calcArea(radius); + } + } + """); } [Fact] public async Task TestInMethodWithLambda() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - return Double.NaN; - } - else - { - return r * r * Math.PI; - } - }; - {|Cursor:[|return|]|} calcArea(radius); - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + return Double.NaN; + } + else + { + return r * r * Math.PI; + } + }; + {|Cursor:[|return|]|} calcArea(radius); + } + } + """); } [Fact] public async Task TestInMethodWithLambda_NotOnReturnValue() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - return Double.NaN; - } - else - { - return r * r * Math.PI; - } - }; - return {|Cursor:calcArea(radius)|}; - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + return Double.NaN; + } + else + { + return r * r * Math.PI; + } + }; + return {|Cursor:calcArea(radius)|}; + } + } + """); } [Fact] public async Task TestInMethodWithLambda_OnSemicolon() { await TestAsync( -@"class C -{ - static double CalculateArea(double radius) - { - Func f = r => { - if (Double.IsNan(r)) - { - return Double.NaN; - } - else - { - return r * r * Math.PI; - } - }; - [|return|] calcArea(radius);{|Cursor:|} - } -}"); + """ + class C + { + static double CalculateArea(double radius) + { + Func f = r => { + if (Double.IsNan(r)) + { + return Double.NaN; + } + else + { + return r * r * Math.PI; + } + }; + [|return|] calcArea(radius);{|Cursor:|} + } + } + """); } [Fact] public async Task TestInConstructor() { await TestAsync( -@"class C -{ - C() - { - {|Cursor:[|return|]|}; - [|return|]; - } -}"); + """ + class C + { + C() + { + {|Cursor:[|return|]|}; + [|return|]; + } + } + """); } [Fact] public async Task TestInDestructor() { await TestAsync( -@"class C -{ - ~C() - { - {|Cursor:[|return|]|}; - [|return|]; - } -}"); + """ + class C + { + ~C() + { + {|Cursor:[|return|]|}; + [|return|]; + } + } + """); } [Fact] public async Task TestInOperator() { await TestAsync( -@"class C -{ - public static string operator +(C a) - { - {|Cursor:[|return|]|} null; - [|return|] null; - } -}"); + """ + class C + { + public static string operator +(C a) + { + {|Cursor:[|return|]|} null; + [|return|] null; + } + } + """); } [Fact] public async Task TestInConversionOperator() { await TestAsync( -@"class C -{ - public static explicit operator string(C a) - { - {|Cursor:[|return|]|} null; - [|return|] null; - } -}"); + """ + class C + { + public static explicit operator string(C a) + { + {|Cursor:[|return|]|} null; + [|return|] null; + } + } + """); } [Fact] public async Task TestInGetter() { await TestAsync( -@"class C -{ - int P - { - get - { - {|Cursor:[|return|]|} 0; - [|return|] 0; - } - set - { - return; - return; - } - } -}"); + """ + class C + { + int P + { + get + { + {|Cursor:[|return|]|} 0; + [|return|] 0; + } + set + { + return; + return; + } + } + } + """); } [Fact] public async Task TestInSetter() { await TestAsync( -@"class C -{ - int P - { - get - { - return 0; - return 0; - } - set - { - {|Cursor:[|return|]|}; - [|return|]; - } - } -}"); + """ + class C + { + int P + { + get + { + return 0; + return 0; + } + set + { + {|Cursor:[|return|]|}; + [|return|]; + } + } + } + """); } [Fact] public async Task TestInInit() { await TestAsync( -@"class C -{ - int P - { - get - { - return 0; - return 0; - } - init - { - {|Cursor:[|return|]|}; - [|return|]; - } - } -}"); + """ + class C + { + int P + { + get + { + return 0; + return 0; + } + init + { + {|Cursor:[|return|]|}; + [|return|]; + } + } + } + """); } [Fact] public async Task TestInAdder() { await TestAsync( -@"class C -{ - event EventHandler E - { - add - { - {|Cursor:[|return|]|}; - [|return|]; - } - remove - { - return; - return; - } - } -}"); + """ + class C + { + event EventHandler E + { + add + { + {|Cursor:[|return|]|}; + [|return|]; + } + remove + { + return; + return; + } + } + } + """); } [Fact] public async Task TestInRemover() { await TestAsync( -@"class C -{ - event EventHandler E - { - add - { - return; - return; - } - remove - { - {|Cursor:[|return|]|}; - [|return|]; - } - } -}"); + """ + class C + { + event EventHandler E + { + add + { + return; + return; + } + remove + { + {|Cursor:[|return|]|}; + [|return|]; + } + } + } + """); } [Fact] public async Task TestInLocalFunction() { await TestAsync( -@"class C -{ - void M() - { - void F() - { - {|Cursor:[|return|]|}; - [|return|]; - } + """ + class C + { + void M() + { + void F() + { + {|Cursor:[|return|]|}; + [|return|]; + } - return; - } -}"); + return; + } + } + """); } [Fact] public async Task TestInSimpleLambda() { await TestAsync( -@"class C -{ - void M() - { - Action f = s => - { - {|Cursor:[|return|]|}; - [|return|]; - }; + """ + class C + { + void M() + { + Action f = s => + { + {|Cursor:[|return|]|}; + [|return|]; + }; - return; - } -}"); + return; + } + } + """); } [Fact] public async Task TestInParenthesizedLambda() { await TestAsync( -@"class C -{ - void M() - { - Action f = (s) => - { - {|Cursor:[|return|]|}; - [|return|]; - }; + """ + class C + { + void M() + { + Action f = (s) => + { + {|Cursor:[|return|]|}; + [|return|]; + }; - return; - } -}"); + return; + } + } + """); } [Fact] public async Task TestInAnonymousMethod() { await TestAsync( -@"class C -{ - void M() - { - Action f = delegate - { - {|Cursor:[|return|]|}; - [|return|]; - }; + """ + class C + { + void M() + { + Action f = delegate + { + {|Cursor:[|return|]|}; + [|return|]; + }; - return; - } -}"); + return; + } + } + """); } [Fact] public async Task TestInTopLevelStatements() { await TestAsync( -@"if (args.Length > 0) [|return|] 0; -{|Cursor:[|return|]|} 1;"); + """ + if (args.Length > 0) [|return|] 0; + {|Cursor:[|return|]|} 1; + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/SwitchStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/SwitchStatementHighlighterTests.cs index 6ad6dd151996d..3e72c921adbce 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/SwitchStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/SwitchStatementHighlighterTests.cs @@ -23,800 +23,860 @@ internal override Type GetHighlighterType() public async Task TestExample1_OnSwitchKeyword() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|switch|]|} (i) - { - [|case|] 0: - CaseZero(); - [|break|]; - [|case|] 1: - CaseOne(); - [|break|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|switch|]|} (i) + { + [|case|] 0: + CaseZero(); + [|break|]; + [|case|] 1: + CaseOne(); + [|break|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample1_OnCaseKeyword() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - {|Cursor:[|case|]|} 0: - CaseZero(); - [|break|]; - [|case|] 1: - CaseOne(); - [|break|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + {|Cursor:[|case|]|} 0: + CaseZero(); + [|break|]; + [|case|] 1: + CaseOne(); + [|break|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample1_AfterCaseColon() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0:{|Cursor:|} - CaseZero(); - [|break|]; - [|case|] 1: - CaseOne(); - [|break|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0:{|Cursor:|} + CaseZero(); + [|break|]; + [|case|] 1: + CaseOne(); + [|break|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample1_NotOnCaseValue() { await TestAsync( -@"class C -{ - void M() - { - switch (i) - { - case {|Cursor:0|}: - CaseZero(); - break; - case 1: - CaseOne(); - break; - default: - CaseOthers(); - break; - } - } -}"); + """ + class C + { + void M() + { + switch (i) + { + case {|Cursor:0|}: + CaseZero(); + break; + case 1: + CaseOne(); + break; + default: + CaseOthers(); + break; + } + } + } + """); } [Fact] public async Task TestExample1_OnBreakStatement() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - {|Cursor:[|break|];|} - [|case|] 1: - CaseOne(); - [|break|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + {|Cursor:[|break|];|} + [|case|] 1: + CaseOne(); + [|break|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample1_OnDefaultLabel() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - [|break|]; - [|case|] 1: - CaseOne(); - [|break|]; - {|Cursor:[|default|]:|} - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + [|break|]; + [|case|] 1: + CaseOne(); + [|break|]; + {|Cursor:[|default|]:|} + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample2_OnGotoCaseKeywords() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - {|Cursor:[|goto case|]|} 1; - [|case|] 1: - CaseOne(); - [|goto default|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + {|Cursor:[|goto case|]|} 1; + [|case|] 1: + CaseOne(); + [|goto default|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample2_AfterGotoCaseSemicolon() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - [|goto case|] 1;{|Cursor:|} - [|case|] 1: - CaseOne(); - [|goto default|]; - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + [|goto case|] 1;{|Cursor:|} + [|case|] 1: + CaseOne(); + [|goto default|]; + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestExample2_NotOnGotoCaseValue() { await TestAsync( -@"class C -{ - void M() - { - switch (i) - { - case 0: - CaseZero(); - goto case {|Cursor:1|}; - case 1: - CaseOne(); - goto default; - default: - CaseOthers(); - break; - } - } -}"); + """ + class C + { + void M() + { + switch (i) + { + case 0: + CaseZero(); + goto case {|Cursor:1|}; + case 1: + CaseOne(); + goto default; + default: + CaseOthers(); + break; + } + } + } + """); } [Fact] public async Task TestExample2_OnGotoDefaultStatement() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - [|goto case|] 1; - [|case|] 1: - CaseOne(); - {|Cursor:[|goto default|];|} - [|default|]: - CaseOthers(); - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + [|goto case|] 1; + [|case|] 1: + CaseOne(); + {|Cursor:[|goto default|];|} + [|default|]: + CaseOthers(); + [|break|]; + } + } + } + """); } [Fact] public async Task TestNestedExample1_OnSwitchKeyword() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - {|Cursor:[|switch|]|} (b) + """ + class C { - [|case|] 0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + {|Cursor:[|switch|]|} (b) + { + [|case|] 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + [|break|]; + } + } - [|break|]; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_OnCaseKeyword() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - [|switch|] (b) + """ + class C { - {|Cursor:[|case|]|} 0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + [|switch|] (b) + { + {|Cursor:[|case|]|} 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + [|break|]; + } + } - [|break|]; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_NotBeforeCaseValue() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - switch (b) + """ + class C { - case {|Cursor:|}0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + switch (b) + { + case {|Cursor:|}0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + break; + } + } - break; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_AfterCaseColon() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - [|switch|] (b) + """ + class C { - [|case|] 0:{|Cursor:|} - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + [|switch|] (b) + { + [|case|] 0:{|Cursor:|} + while (true) + { + do + { + break; + } + while (false); + break; + } + + [|break|]; + } + } - [|break|]; + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task TestNestedExample1_OnBreakStatement() { await TestAsync( -@"class C -{ - void M() - { - foreach (var a in x) - { - if (a) - { - break; - } - else - { - [|switch|] (b) + """ + class C { - [|case|] 0: - while (true) + void M() + { + foreach (var a in x) { - do + if (a) { break; } - while (false); - break; - } + else + { + [|switch|] (b) + { + [|case|] 0: + while (true) + { + do + { + break; + } + while (false); + break; + } + + {|Cursor:[|break|];|} + } + } - {|Cursor:[|break|];|} + for (int i = 0; i < 10; i++) + { + break; + } + } + } } - } - - for (int i = 0; i < 10; i++) - { - break; - } - } - } -}"); + """); } [Fact] public async Task Bug3483() { await TestAsync( -@"class C -{ - static void M() - { - [|switch|] (2) - { - [|case|] 1: - {|Cursor:[|goto|]|} - } - } -}"); + """ + class C + { + static void M() + { + [|switch|] (2) + { + [|case|] 1: + {|Cursor:[|goto|]|} + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithUnrelatedGotoStatement_OnGotoCaseGotoKeyword() { await TestAsync( -@"class C -{ - void M() - { - label: - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - [|{|Cursor:goto|} case|] 1; - [|case|] 1: - CaseOne(); - [|goto default|]; - [|default|]: - CaseOthers(); - goto label; - } - } -}"); + """ + class C + { + void M() + { + label: + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + [|{|Cursor:goto|} case|] 1; + [|case|] 1: + CaseOne(); + [|goto default|]; + [|default|]: + CaseOthers(); + goto label; + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithUnrelatedGotoStatement_OnGotoDefaultGotoKeyword() { await TestAsync( -@"class C -{ - void M() - { - label: - [|switch|] (i) - { - [|case|] 0: - CaseZero(); - [|goto case|] 1; - [|case|] 1: - CaseOne(); - [|{|Cursor:goto|} default|]; - [|default|]: - CaseOthers(); - goto label; - } - } -}"); + """ + class C + { + void M() + { + label: + [|switch|] (i) + { + [|case|] 0: + CaseZero(); + [|goto case|] 1; + [|case|] 1: + CaseOne(); + [|{|Cursor:goto|} default|]; + [|default|]: + CaseOthers(); + goto label; + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithUnrelatedGotoStatement_NotOnGotoLabelGotoKeyword() { await TestAsync( -@"class C -{ - void M() - { - label: - switch (i) - { - case 0: - CaseZero(); - goto case 1; - case 1: - CaseOne(); - goto default; - default: - CaseOthers(); - {|Cursor:goto|} label; - } - } -}"); + """ + class C + { + void M() + { + label: + switch (i) + { + case 0: + CaseZero(); + goto case 1; + case 1: + CaseOne(); + goto default; + default: + CaseOthers(); + {|Cursor:goto|} label; + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithNestedStatements_OnSwitchKeyword() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|switch|]|} (i) - { - [|case|] 0: - { - CaseZero(); - [|goto case|] 1; - } - [|case|] 1: - { - CaseOne(); - [|goto default|]; - } - [|default|]: - { - CaseOthers(); - [|break|]; - } - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|switch|]|} (i) + { + [|case|] 0: + { + CaseZero(); + [|goto case|] 1; + } + [|case|] 1: + { + CaseOne(); + [|goto default|]; + } + [|default|]: + { + CaseOthers(); + [|break|]; + } + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithNestedStatements_OnBreakKeyword() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (i) - { - [|case|] 0: - { - CaseZero(); - [|goto case|] 1; - } - [|case|] 1: - { - CaseOne(); - [|goto default|]; - } - [|default|]: - { - CaseOthers(); - {|Cursor:[|break|]|}; - } - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (i) + { + [|case|] 0: + { + CaseZero(); + [|goto case|] 1; + } + [|case|] 1: + { + CaseOne(); + [|goto default|]; + } + [|default|]: + { + CaseOthers(); + {|Cursor:[|break|]|}; + } + } + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithGotoCaseAndBreakInsideLoop_OnSwitchKeyword() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|switch|]|} (true) - { - [|case|] true: - while (true) + """ + class C { - [|goto case|] true; - break; - - switch (true) + void M() { - case true: - goto case true; - break; + {|Cursor:[|switch|]|} (true) + { + [|case|] true: + while (true) + { + [|goto case|] true; + break; + + switch (true) + { + case true: + goto case true; + break; + } + } + } } } - } - } -}"); + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithGotoCaseAndBreakInsideLoop_OnGotoCaseGotoKeyword() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (true) - { - [|case|] true: - while (true) + """ + class C { - [|{|Cursor:goto|} case|] true; - break; - - switch (true) + void M() { - case true: - goto case true; - break; + [|switch|] (true) + { + [|case|] true: + while (true) + { + [|{|Cursor:goto|} case|] true; + break; + + switch (true) + { + case true: + goto case true; + break; + } + } + } } } - } - } -}"); + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25039")] public async Task TestWithGotoCaseAndBreakInsideLoop_NotOnLoopBreakKeyword() { await TestAsync( -@"class C -{ - void M() - { - switch (true) - { - case true: - while (true) + """ + class C { - goto case true; - {|Cursor:break|}; - - switch (true) + void M() { - case true: - goto case true; - break; + switch (true) + { + case true: + while (true) + { + goto case true; + {|Cursor:break|}; + + switch (true) + { + case true: + goto case true; + break; + } + } + } } } - } - } -}"); + """); } [Fact] public async Task TestWithWhenClauseAndPattern_OnSwitchKeyword() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|switch|]|} (true) - { - [|case|] true when true: - [|break|]; - [|case|] bool b: - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|switch|]|} (true) + { + [|case|] true when true: + [|break|]; + [|case|] bool b: + [|break|]; + } + } + } + """); } [Fact] public async Task TestWithWhenClauseAndPattern_NotOnWhenKeyword() { await TestAsync( -@"class C -{ - void M() - { - switch (true) - { - case true {|Cursor:when|} true: - break; - case bool b: - break; - } - } -}"); + """ + class C + { + void M() + { + switch (true) + { + case true {|Cursor:when|} true: + break; + case bool b: + break; + } + } + } + """); } [Fact] public async Task TestWithWhenClauseAndPattern_AfterWhenCaseColon() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (true) - { - [|case|] true when true:{|Cursor:|} - [|break|]; - [|case|] bool b: - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (true) + { + [|case|] true when true:{|Cursor:|} + [|break|]; + [|case|] bool b: + [|break|]; + } + } + } + """); } [Fact] public async Task TestWithWhenClauseAndPattern_AfterPatternCaseColon() { await TestAsync( -@"class C -{ - void M() - { - [|switch|] (true) - { - [|case|] true when true: - [|break|]; - [|case|] bool b:{|Cursor:|} - [|break|]; - } - } -}"); + """ + class C + { + void M() + { + [|switch|] (true) + { + [|case|] true when true: + [|break|]; + [|case|] bool b:{|Cursor:|} + [|break|]; + } + } + } + """); } [Fact] public async Task TestWithWhenClauseAndPattern_NotOnWhenValue() { await TestAsync( -@"class C -{ - void M() - { - switch (true) - { - case true when {|Cursor:true|}: - break; - case bool b: - break; - } - } -}"); + """ + class C + { + void M() + { + switch (true) + { + case true when {|Cursor:true|}: + break; + case bool b: + break; + } + } + } + """); } [Fact] public async Task TestWithWhenClauseAndPattern_NotOnPattern() { await TestAsync( -@"class C -{ - void M() - { - switch (true) - { - case true when true: - break; - case {|Cursor:bool b|}: - break; - } - } -}"); + """ + class C + { + void M() + { + switch (true) + { + case true when true: + break; + case {|Cursor:bool b|}: + break; + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/TryStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/TryStatementHighlighterTests.cs index b2d6861bcd9a2..684f7ea88ecbd 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/TryStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/TryStatementHighlighterTests.cs @@ -22,168 +22,182 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|try|]|} - { - try - { - } - catch (Exception e) - { - } - } - [|finally|] - { - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|try|]|} + { + try + { + } + catch (Exception e) + { + } + } + [|finally|] + { + } + } + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - void M() - { - try - { - {|Cursor:[|try|]|} - { - } - [|catch|] (Exception e) - { - } - } - finally - { - } - } -}"); + """ + class C + { + void M() + { + try + { + {|Cursor:[|try|]|} + { + } + [|catch|] (Exception e) + { + } + } + finally + { + } + } + } + """); } [Fact] public async Task TestExample1_3() { await TestAsync( -@"class C -{ - void M() - { - try - { - [|try|] - { - } - {|Cursor:[|catch|]|} (Exception e) - { - } - } - finally - { - } - } -}"); + """ + class C + { + void M() + { + try + { + [|try|] + { + } + {|Cursor:[|catch|]|} (Exception e) + { + } + } + finally + { + } + } + } + """); } [Fact] public async Task TestExample1_4() { await TestAsync( -@"class C -{ - void M() - { - [|try|] - { - try - { - } - catch (Exception e) - { - } - } - {|Cursor:[|finally|]|} - { - } - } -}"); + """ + class C + { + void M() + { + [|try|] + { + try + { + } + catch (Exception e) + { + } + } + {|Cursor:[|finally|]|} + { + } + } + } + """); } [Fact] public async Task TestExceptionFilter1() { await TestAsync( -@"class C -{ - void M() - { - try - { - {|Cursor:[|try|]|} - { - } - [|catch|] (Exception e) [|when|] (e != null) - { - } - } - finally - { - } - } -}"); + """ + class C + { + void M() + { + try + { + {|Cursor:[|try|]|} + { + } + [|catch|] (Exception e) [|when|] (e != null) + { + } + } + finally + { + } + } + } + """); } [Fact] public async Task TestExceptionFilter2() { await TestAsync( -@"class C -{ - void M() - { - try - { - [|try|] - { - } - {|Cursor:[|catch|]|} (Exception e) [|when|] (e != null) - { - } - } - finally - { - } - } -}"); + """ + class C + { + void M() + { + try + { + [|try|] + { + } + {|Cursor:[|catch|]|} (Exception e) [|when|] (e != null) + { + } + } + finally + { + } + } + } + """); } [Fact] public async Task TestExceptionFilter3() { await TestAsync( -@"class C -{ - void M() - { - try - { - [|try|] - { - } - [|catch|] (Exception e) {|Cursor:[|when|]|} (e != null) - { - } - } - finally - { - } - } -}"); + """ + class C + { + void M() + { + try + { + [|try|] + { + } + [|catch|] (Exception e) {|Cursor:[|when|]|} (e != null) + { + } + } + finally + { + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/UnsafeStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/UnsafeStatementHighlighterTests.cs index 77df94e89c128..fbff553c660cd 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/UnsafeStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/UnsafeStatementHighlighterTests.cs @@ -21,20 +21,22 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - int var1 = 5; - {|Cursor:[|unsafe|]|} - { - int* ptr1, ptr2; - ptr1 = &var1; - ptr2 = ptr1; - *ptr2 = 20; - } - } -}"); + """ + class C + { + void M() + { + int var1 = 5; + {|Cursor:[|unsafe|]|} + { + int* ptr1, ptr2; + ptr1 = &var1; + ptr2 = ptr1; + *ptr2 = 20; + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/UsingStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/UsingStatementHighlighterTests.cs index 74ba97260300b..d65e8d19c554f 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/UsingStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/UsingStatementHighlighterTests.cs @@ -21,16 +21,18 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - void M() - { - {|Cursor:[|using|]|} (Font f = new Font(“Arial”, 10.0f)) - { - // use f... - } - } -}"); + """ + class C + { + void M() + { + {|Cursor:[|using|]|} (Font f = new Font(“Arial”, 10.0f)) + { + // use f... + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/KeywordHighlighting/YieldStatementHighlighterTests.cs b/src/EditorFeatures/CSharpTest/KeywordHighlighting/YieldStatementHighlighterTests.cs index 34870d661b6d8..666e8c0b63dd4 100644 --- a/src/EditorFeatures/CSharpTest/KeywordHighlighting/YieldStatementHighlighterTests.cs +++ b/src/EditorFeatures/CSharpTest/KeywordHighlighting/YieldStatementHighlighterTests.cs @@ -22,84 +22,92 @@ internal override Type GetHighlighterType() public async Task TestExample1_1() { await TestAsync( -@"class C -{ - IEnumerable Range(int min, int max) - { - while (true) - { - if (min >= max) - { - {|Cursor:[|yield break|];|} - } + """ + class C + { + IEnumerable Range(int min, int max) + { + while (true) + { + if (min >= max) + { + {|Cursor:[|yield break|];|} + } - [|yield return|] min++; - } - } -}"); + [|yield return|] min++; + } + } + } + """); } [Fact] public async Task TestExample1_2() { await TestAsync( -@"class C -{ - IEnumerable Range(int min, int max) - { - while (true) - { - if (min >= max) - { - [|yield break|]; - } + """ + class C + { + IEnumerable Range(int min, int max) + { + while (true) + { + if (min >= max) + { + [|yield break|]; + } - {|Cursor:[|yield return|]|} min++; - } - } -}"); + {|Cursor:[|yield return|]|} min++; + } + } + } + """); } [Fact] public async Task TestExample1_3() { await TestAsync( -@"class C -{ - IEnumerable Range(int min, int max) - { - while (true) - { - if (min >= max) - { - yield break; - } + """ + class C + { + IEnumerable Range(int min, int max) + { + while (true) + { + if (min >= max) + { + yield break; + } - yield return {|Cursor:min++|}; - } - } -}"); + yield return {|Cursor:min++|}; + } + } + } + """); } [Fact] public async Task TestExample1_4() { await TestAsync( -@"class C -{ - IEnumerable Range(int min, int max) - { - while (true) - { - if (min >= max) - { - [|yield break|]; - } + """ + class C + { + IEnumerable Range(int min, int max) + { + while (true) + { + if (min >= max) + { + [|yield break|]; + } - [|yield return|] min++;{|Cursor:|} - } - } -}"); + [|yield return|] min++;{|Cursor:|} + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs b/src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs index ba0ea1f02b8d7..4635307735516 100644 --- a/src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs +++ b/src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs @@ -28,433 +28,492 @@ public async Task TestEmptyFile() [Fact] public async Task TestEmptyClass() { - var file = @"class C -{ -}"; + var file = """ + class C + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0); } [Fact] public async Task TestClassWithOneMethod() { - var file = @"class C -{ - void M() - { - } -}"; + var file = """ + class C + { + void M() + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 1); } [Fact] public async Task TestClassWithTwoMethods() { - var file = @"class C -{ - void M() - { - } - - void N() - { - } -}"; + var file = """ + class C + { + void M() + { + } + + void N() + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task TestClassWithTwoNonEmptyMethods() { - var file = @"class C -{ - void M() - { - N(); - } - - void N() - { - M(); - } -}"; + var file = """ + class C + { + void M() + { + N(); + } + + void N() + { + M(); + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 1, 4); } [Fact] public async Task TestClassWithMethodAndField() { - var file = @"class C -{ - void M() - { - } + var file = """ + class C + { + void M() + { + } - int field; -}"; + int field; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task TestEmptyNamespace() { - var file = @"namespace N -{ -}"; + var file = """ + namespace N + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0); } [Fact] public async Task TestNamespaceAndClass() { - var file = @"namespace N -{ - class C - { - } -}"; + var file = """ + namespace N + { + class C + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 1); } [Fact] public async Task TestNamespaceAndTwoClasses() { - var file = @"namespace N -{ - class C - { - } - - class D - { - } -}"; + var file = """ + namespace N + { + class C + { + } + + class D + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task TestNamespaceAndTwoClassesAndDelegate() { - var file = @"namespace N -{ - class C - { - } + var file = """ + namespace N + { + class C + { + } - class D - { - } + class D + { + } - delegate void Del(); -}"; + delegate void Del(); + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 1, 3); } [Fact] public async Task TestNestedClass() { - var file = @"class C -{ - class N - { - } -}"; + var file = """ + class C + { + class N + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 1); } [Fact] public async Task TestTwoNestedClasses() { - var file = @"class C -{ - class N - { - } - - class N2 - { - } -}"; + var file = """ + class C + { + class N + { + } + + class N2 + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task TestStruct() { - var file = @"struct S -{ -}"; + var file = """ + struct S + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0); } [Fact] public async Task TestInterface() { - var file = @"interface I -{ -}"; + var file = """ + interface I + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0); } [Fact] public async Task TestEnum() { - var file = @"enum E -{ -}"; + var file = """ + enum E + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0); } [Fact] public async Task TestProperty() { - var file = @"class C -{ - int Prop - { - get - { - return 0; - } - set - { - } - } -}"; + var file = """ + class C + { + int Prop + { + get + { + return 0; + } + set + { + } + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 4); } [Fact] public async Task TestPropertyAndField() { - var file = @"class C -{ - int Prop - { - get - { - return 0; - } - set - { - } - } - - int field; -}"; + var file = """ + class C + { + int Prop + { + get + { + return 0; + } + set + { + } + } + + int field; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 3, 5); } [Fact] public async Task TestClassWithFieldAndMethod() { - var file = @"class C -{ - int field; + var file = """ + class C + { + int field; - void M() - { - } -}"; + void M() + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task UsingDirective() { - var file = @"using System; + var file = """ + using System; -class C -{ -}"; + class C + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 1); } [Fact] public async Task UsingDirectiveInNamespace() { - var file = @"namespace N -{ - using System; + var file = """ + namespace N + { + using System; - class C - { - } -}"; + class C + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task UsingDirectiveInFileScopedNamespace() { - var file = @"namespace N; + var file = """ + namespace N; -using System; + using System; -class C -{ -} -"; + class C + { + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 1); } [Fact] public async Task PropertyStyleEventDeclaration() { - var file = @"class C -{ - event EventHandler E - { - add { } - remove { } - } - - int i; -}"; + var file = """ + class C + { + event EventHandler E + { + add { } + remove { } + } + + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 2, 4); } [Fact] public async Task IndexerDeclaration() { - var file = @"class C -{ - int this[int i] - { - get { return i; } - set { } - } - - int i; -}"; + var file = """ + class C + { + int this[int i] + { + get { return i; } + set { } + } + + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 3, 5); } [Fact] public async Task Constructor() { - var file = @"class C -{ - C() - { - } + var file = """ + class C + { + C() + { + } - int i; -}"; + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task Destructor() { - var file = @"class C -{ - ~C() - { - } + var file = """ + class C + { + ~C() + { + } - int i; -}"; + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task Operator() { - var file = @"class C -{ - static C operator +(C lhs, C rhs) - { - } + var file = """ + class C + { + static C operator +(C lhs, C rhs) + { + } - int i; -}"; + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task ConversionOperator() { - var file = @"class C -{ - static implicit operator C(int i) - { - } + var file = """ + class C + { + static implicit operator C(int i) + { + } - int i; -}"; + int i; + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 0, 2); } [Fact] public async Task Bug930292() { - var file = @"class Program -{ -void A() { } -void B() { } -void C() { } -void D() { } -} -"; + var file = """ + class Program + { + void A() { } + void B() { } + void C() { } + void D() { } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 4); } [Fact] public async Task Bug930289() { - var file = @"namespace Roslyn.Compilers.CSharp -{ -internal struct ArrayElement -{ -internal T Value; -internal ArrayElement(T value) { this.Value = value; } -public static implicit operator ArrayElement(T value) { return new ArrayElement(value); } -} -} -"; + var file = """ + namespace Roslyn.Compilers.CSharp + { + internal struct ArrayElement + { + internal T Value; + internal ArrayElement(T value) { this.Value = value; } + public static implicit operator ArrayElement(T value) { return new ArrayElement(value); } + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 6); } [Fact] public async Task TestConsoleApp() { - var file = @"using System; -using System.Collections.Generic; -using System.Linq; - -class Program -{ - static void Main(string[] args) - { - } -}"; + var file = """ + using System; + using System.Collections.Generic; + using System.Linq; + + class Program + { + static void Main(string[] args) + { + } + } + """; await AssertTagsOnBracesOrSemicolonsAsync(file, 2, 4); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/1297")] public async Task ExpressionBodiedProperty() { - await AssertTagsOnBracesOrSemicolonsAsync(@"class C -{ - int Prop => 3; + await AssertTagsOnBracesOrSemicolonsAsync(""" + class C + { + int Prop => 3; - void M() - { - } -}", 0, 2); + void M() + { + } + } + """, 0, 2); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/1297")] public async Task ExpressionBodiedIndexer() { - await AssertTagsOnBracesOrSemicolonsAsync(@"class C -{ - int this[int i] => 3; + await AssertTagsOnBracesOrSemicolonsAsync(""" + class C + { + int this[int i] => 3; - void M() - { - } -}", 0, 2); + void M() + { + } + } + """, 0, 2); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/1297")] @@ -462,14 +521,16 @@ public async Task ExpressionBodiedEvent() { // This is not valid code, and parses all wrong, but just in case a user writes it. Note // the 3 is because there is a skipped } in the event declaration. - await AssertTagsOnBracesOrSemicolonsAsync(@"class C -{ - event EventHandler MyEvent => 3; - - void M() - { - } -}", 3); + await AssertTagsOnBracesOrSemicolonsAsync(""" + class C + { + event EventHandler MyEvent => 3; + + void M() + { + } + } + """, 3); } #region Negative (incomplete) tests diff --git a/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs b/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs index f690ca03f9247..e9eae057e927b 100644 --- a/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs +++ b/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs @@ -52,57 +52,66 @@ public class MoveToNamespaceTests : AbstractMoveToNamespaceTests [Fact] public Task MoveToNamespace_MoveItems_CaretAboveNamespace() => TestMoveToNamespaceAsync( -@"using System; -[||] -namespace A -{ - class MyClass - { - } -}", + """ + using System; + [||] + namespace A + { + class MyClass + { + } + } + """, expectedSuccess: false); [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/59716")] public Task MoveToNamespace_MoveItems_CaretAboveNamespace_FileScopedNamespace() => TestMoveToNamespaceAsync( -@"using System; -[||] -namespace A; - -class MyClass -{ -} -", + """ + using System; + [||] + namespace A; + + class MyClass + { + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveItems_CaretAboveNamespace2() => TestMoveToNamespaceAsync( -@"using System;[||] - -namespace A -{ - class MyClass - { - } -}", + """ + using System;[||] + + namespace A + { + class MyClass + { + } + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveItems_WeirdNamespace() => TestMoveToNamespaceAsync( -@"namespace A [||]. B . C -{ - class MyClass - { - } -}", -expectedMarkup: @"namespace {|Warning:A|} -{ - class MyClass - { - } -}", + """ + namespace A [||]. B . C + { + class MyClass + { + } + } + """, +expectedMarkup: """ + namespace {|Warning:A|} + { + class MyClass + { + } + } + """, targetNamespace: "A", expectedSymbolChanges: new Dictionary() { @@ -112,20 +121,24 @@ class MyClass [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceName() => TestMoveToNamespaceAsync( -@"namespace A[||] -{ - class MyClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - class MyClass - { - void Method() { } - } -}", + """ + namespace A[||] + { + class MyClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + class MyClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -135,20 +148,24 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceName2() => TestMoveToNamespaceAsync( -@"namespace A[||].B.C -{ - class MyClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - class MyClass - { - void Method() { } - } -}", + """ + namespace A[||].B.C + { + class MyClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + class MyClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -158,20 +175,24 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceKeyword() => TestMoveToNamespaceAsync( -@"namespace[||] A -{ - class MyClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - class MyClass - { - void Method() { } - } -}", + """ + namespace[||] A + { + class MyClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + class MyClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -182,20 +203,24 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceKeyword2() => TestMoveToNamespaceAsync( -@"[||]namespace A -{ - class MyClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - class MyClass - { - void Method() { } - } -}", + """ + [||]namespace A + { + class MyClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + class MyClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -205,66 +230,75 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceBrace() => TestMoveToNamespaceAsync( -@"namespace A -[||]{ - class MyClass - { - void Method() { } - } -}", + """ + namespace A + [||]{ + class MyClass + { + void Method() { } + } + } + """, expectedSuccess: false); [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/59716")] public Task MoveToNamespace_MoveItems_CaretAfterFileScopedNamespaceSemicolon() => TestMoveToNamespaceAsync( -@"namespace A; [||] + """ + namespace A; [||] -class MyClass -{ - void Method() { } -} -", + class MyClass + { + void Method() { } + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveItems_CaretOnNamespaceBrace2() => TestMoveToNamespaceAsync( -@"namespace A -{[||] - class MyClass - { - void Method() { } - } -}", + """ + namespace A + {[||] + class MyClass + { + void Method() { } + } + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveItems_MultipleDeclarations() => TestMoveToNamespaceAsync( -@"namespace A[||] -{ - class MyClass - { - void Method() { } - } - - class MyOtherClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - class MyClass - { - void Method() { } - } - - class MyOtherClass - { - void Method() { } - } -}", + """ + namespace A[||] + { + class MyClass + { + void Method() { } + } + + class MyOtherClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + class MyClass + { + void Method() { } + } + + class MyOtherClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -275,60 +309,64 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_WithVariousSymbols() => TestMoveToNamespaceAsync( -@"namespace A[||] -{ - public delegate void MyDelegate(); - - public enum MyEnum - { - One, - Two, - Three - } - - public struct MyStruct - { } - - public interface MyInterface - { } - - class MyClass - { - void Method() { } - } - - class MyOtherClass - { - void Method() { } - } -}", -expectedMarkup: @"namespace {|Warning:B|} -{ - public delegate void MyDelegate(); - - public enum MyEnum - { - One, - Two, - Three - } - - public struct MyStruct - { } - - public interface MyInterface - { } - - class MyClass - { - void Method() { } - } - - class MyOtherClass - { - void Method() { } - } -}", + """ + namespace A[||] + { + public delegate void MyDelegate(); + + public enum MyEnum + { + One, + Two, + Three + } + + public struct MyStruct + { } + + public interface MyInterface + { } + + class MyClass + { + void Method() { } + } + + class MyOtherClass + { + void Method() { } + } + } + """, +expectedMarkup: """ + namespace {|Warning:B|} + { + public delegate void MyDelegate(); + + public enum MyEnum + { + One, + Two, + Three + } + + public struct MyStruct + { } + + public interface MyInterface + { } + + class MyClass + { + void Method() { } + } + + class MyOtherClass + { + void Method() { } + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -343,31 +381,35 @@ void Method() { } [Fact] public Task MoveToNamespace_MoveItems_NestedNamespace() => TestMoveToNamespaceAsync( -@"namespace A[||] -{ - namespace C - { - class MyClass - { - void Method() { } - } - } -}", + """ + namespace A[||] + { + namespace C + { + class MyClass + { + void Method() { } + } + } + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveItems_NestedNamespace2() => TestMoveToNamespaceAsync( -@"namespace A -{ - namespace C[||] - { - class MyClass - { - void Method() { } - } - } -}", + """ + namespace A + { + namespace C[||] + { + class MyClass + { + void Method() { } + } + } + } + """, expectedSuccess: false); [Theory] @@ -465,31 +507,35 @@ namespace A [Fact] public Task MoveToNamespace_MoveType_TopWithReference() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass[||] : IMyClass - { - } + """ + namespace A + { + class MyClass[||] : IMyClass + { + } - interface IMyClass - { - } -}", -expectedMarkup: @"using A; + interface IMyClass + { + } + } + """, +expectedMarkup: """ + using A; -namespace {|Warning:B|} -{ - class MyClass : IMyClass - { - } -} + namespace {|Warning:B|} + { + class MyClass : IMyClass + { + } + } -namespace A -{ - interface IMyClass - { - } -}", + namespace A + { + interface IMyClass + { + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -532,31 +578,35 @@ namespace {{|Warning:B|}} [Fact] public Task MoveToNamespace_MoveType_BottomReference() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass : IMyClass - { - } + """ + namespace A + { + class MyClass : IMyClass + { + } - interface IMyClass[||] - { - } -}", -expectedMarkup: @"using B; + interface IMyClass[||] + { + } + } + """, +expectedMarkup: """ + using B; -namespace A -{ - class MyClass : IMyClass - { - } -} + namespace A + { + class MyClass : IMyClass + { + } + } -namespace {|Warning:B|} -{ - interface IMyClass - { - } -}", + namespace {|Warning:B|} + { + interface IMyClass + { + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -742,58 +792,64 @@ namespace A [Fact] public Task MoveToNamespace_MoveType_CaretInMethod() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass - { - public string [||]MyMethod - { - return ""; - } - } + """ + namespace A + { + class MyClass + { + public string [||]MyMethod + { + return "; + } + } -}", + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveType_MiddleReference() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass : IMyClass - { - } + """ + namespace A + { + class MyClass : IMyClass + { + } - interface IMyClass[||] - { - } + interface IMyClass[||] + { + } - class MyClass3 : IMyClass - { - } -}", -expectedMarkup: @"using B; + class MyClass3 : IMyClass + { + } + } + """, +expectedMarkup: """ + using B; -namespace A -{ - class MyClass : IMyClass - { - } -} + namespace A + { + class MyClass : IMyClass + { + } + } -namespace {|Warning:B|} -{ - interface IMyClass - { - } -} + namespace {|Warning:B|} + { + interface IMyClass + { + } + } -namespace A -{ - class MyClass3 : IMyClass - { - } -}", + namespace A + { + class MyClass3 : IMyClass + { + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -803,50 +859,54 @@ class MyClass3 : IMyClass [Fact] public Task MoveToNamespace_MoveType_MiddleReference2() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass : IMyClass - { - } + """ + namespace A + { + class MyClass : IMyClass + { + } - interface IMyClass - { - } + interface IMyClass + { + } - class [||]MyClass3 : IMyClass - { - } + class [||]MyClass3 : IMyClass + { + } - class MyClass4 - { - } -}", -expectedMarkup: @"using A; + class MyClass4 + { + } + } + """, +expectedMarkup: """ + using A; -namespace A -{ - class MyClass : IMyClass - { - } + namespace A + { + class MyClass : IMyClass + { + } - interface IMyClass - { - } -} + interface IMyClass + { + } + } -namespace {|Warning:B|} -{ - class MyClass3 : IMyClass - { - } -} + namespace {|Warning:B|} + { + class MyClass3 : IMyClass + { + } + } -namespace A -{ - class MyClass4 - { - } -}", + namespace A + { + class MyClass4 + { + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -856,108 +916,118 @@ class MyClass4 [Fact] public Task MoveToNamespace_MoveType_NestedInNamespace() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass - { - } - - namespace B - { - interface [||]IMyClass - { - } - } - - class MyClass2 : B.IMyClass - { - } -}", + """ + namespace A + { + class MyClass + { + } + + namespace B + { + interface [||]IMyClass + { + } + } + + class MyClass2 : B.IMyClass + { + } + } + """, expectedSuccess: false); [Fact] public Task MoveToNamespace_MoveType_Cancelled() => TestCancelledOption( -@"namespace A -{ - class MyClass - { - } - - interface [||]IMyClass - { - } - - class MyClass2 : B.IMyClass - { - } -}"); + """ + namespace A + { + class MyClass + { + } + + interface [||]IMyClass + { + } + + class MyClass2 : B.IMyClass + { + } + } + """); [Fact] public Task MoveToNamespace_MoveItems_Cancelled() => TestCancelledOption( -@"namespace A[||] -{ - class MyClass - { - } - - interface IMyClass - { - } - - class MyClass2 : B.IMyClass - { - } -}"); + """ + namespace A[||] + { + class MyClass + { + } + + interface IMyClass + { + } + + class MyClass2 : B.IMyClass + { + } + } + """); [Fact] public Task MoveToNamespace_MoveType_MiddleReference_ComplexName() => TestMoveToNamespaceAsync( -@"namespace A.B.C -{ - class MyClass : IMyClass - { - } + """ + namespace A.B.C + { + class MyClass : IMyClass + { + } - interface IMyClass - { - } + interface IMyClass + { + } - class [||]MyClass3 : IMyClass - { - } + class [||]MyClass3 : IMyClass + { + } - class MyClass4 - { - } -}", -expectedMarkup: @"using A.B.C; + class MyClass4 + { + } + } + """, +expectedMarkup: """ + using A.B.C; -namespace A.B.C -{ - class MyClass : IMyClass - { - } + namespace A.B.C + { + class MyClass : IMyClass + { + } - interface IMyClass - { - } -} + interface IMyClass + { + } + } -namespace {|Warning:My.New.Namespace|} -{ - class MyClass3 : IMyClass - { - } -} + namespace {|Warning:My.New.Namespace|} + { + class MyClass3 : IMyClass + { + } + } -namespace A.B.C -{ - class MyClass4 - { - } -}", + namespace A.B.C + { + class MyClass4 + { + } + } + """, targetNamespace: "My.New.Namespace", expectedSymbolChanges: new Dictionary() { @@ -967,50 +1037,54 @@ class MyClass4 [Fact] public Task MoveToNamespace_MoveType_MiddleReference_ComplexName2() => TestMoveToNamespaceAsync( -@"namespace A -{ - class MyClass : IMyClass - { - } - - interface IMyClass - { - } - - class [||]MyClass3 : IMyClass - { - } - - class MyClass4 - { - } -}", -expectedMarkup: @"using A; - -namespace A -{ - class MyClass : IMyClass - { - } - - interface IMyClass - { - } -} - -namespace {|Warning:My.New.Namespace|} -{ - class MyClass3 : IMyClass - { - } -} - -namespace A -{ - class MyClass4 - { - } -}", + """ + namespace A + { + class MyClass : IMyClass + { + } + + interface IMyClass + { + } + + class [||]MyClass3 : IMyClass + { + } + + class MyClass4 + { + } + } + """, +expectedMarkup: """ + using A; + + namespace A + { + class MyClass : IMyClass + { + } + + interface IMyClass + { + } + } + + namespace {|Warning:My.New.Namespace|} + { + class MyClass3 : IMyClass + { + } + } + + namespace A + { + class MyClass4 + { + } + } + """, targetNamespace: "My.New.Namespace", expectedSymbolChanges: new Dictionary() { @@ -1020,50 +1094,54 @@ class MyClass4 [Fact] public Task MoveToNamespace_MoveType_MiddleReference_ComplexName3() => TestMoveToNamespaceAsync( -@"namespace A.B.C -{ - class MyClass : IMyClass - { - } - - interface IMyClass - { - } - - class [||]MyClass3 : IMyClass - { - } - - class MyClass4 - { - } -}", -expectedMarkup: @"using A.B.C; - -namespace A.B.C -{ - class MyClass : IMyClass - { - } - - interface IMyClass - { - } -} - -namespace {|Warning:B|} -{ - class MyClass3 : IMyClass - { - } -} - -namespace A.B.C -{ - class MyClass4 - { - } -}", + """ + namespace A.B.C + { + class MyClass : IMyClass + { + } + + interface IMyClass + { + } + + class [||]MyClass3 : IMyClass + { + } + + class MyClass4 + { + } + } + """, +expectedMarkup: """ + using A.B.C; + + namespace A.B.C + { + class MyClass : IMyClass + { + } + + interface IMyClass + { + } + } + + namespace {|Warning:B|} + { + class MyClass3 : IMyClass + { + } + } + + namespace A.B.C + { + class MyClass4 + { + } + } + """, targetNamespace: "B", expectedSymbolChanges: new Dictionary() { @@ -1073,82 +1151,94 @@ class MyClass4 [Fact] public Task MoveToNamespace_Analysis_MoveItems_ComplexNamespace() => TestMoveToNamespaceAnalysisAsync( -@"namespace [||]A.Complex.Namespace -{ - class MyClass - { - } -}", + """ + namespace [||]A.Complex.Namespace + { + class MyClass + { + } + } + """, expectedNamespaceName: "A.Complex.Namespace"); [Fact] public Task MoveToNamespace_Analysis_MoveType_ComplexNamespace() => TestMoveToNamespaceAnalysisAsync( -@"namespace A.Complex.Namespace -{ - class [||]MyClass - { - } -}", + """ + namespace A.Complex.Namespace + { + class [||]MyClass + { + } + } + """, expectedNamespaceName: "A.Complex.Namespace"); [Fact] public Task MoveToNamespace_Analysis_MoveItems_WeirdNamespace() => TestMoveToNamespaceAnalysisAsync( -@"namespace A [||]. B . C -{ - class MyClass - { - } -}", + """ + namespace A [||]. B . C + { + class MyClass + { + } + } + """, expectedNamespaceName: "A . B . C"); [Fact] public Task MoveToNamespace_Analysis_MoveType_WeirdNamespace() => TestMoveToNamespaceAnalysisAsync( -@"namespace A . B . C -{ - class MyClass[||] - { - } -}", + """ + namespace A . B . C + { + class MyClass[||] + { + } + } + """, expectedNamespaceName: "A . B . C"); [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34736")] public Task MoveToNamespace_MoveType_Usings() => TestMoveToNamespaceAsync( -@"namespace One -{ - using Two; - class C1 - { - private C2 c2; - } -} - -namespace [||]Two -{ - class C2 - { - - } -}", -expectedMarkup: @"namespace One -{ - using Three; - class C1 - { - private C2 c2; - } -} - -namespace {|Warning:Three|} -{ - class C2 - { - - } -}", + """ + namespace One + { + using Two; + class C1 + { + private C2 c2; + } + } + + namespace [||]Two + { + class C2 + { + + } + } + """, +expectedMarkup: """ + namespace One + { + using Three; + class C1 + { + private C2 c2; + } + } + + namespace {|Warning:Three|} + { + class C2 + { + + } + } + """, targetNamespace: "Three", expectedSymbolChanges: new Dictionary() { @@ -1158,13 +1248,15 @@ class C2 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35577")] public async Task MoveToNamespace_WithoutOptionsService() { - var code = @"namespace A[||] -{ -class MyClass -{ - void Method() { } -} -}"; + var code = """ + namespace A[||] + { + class MyClass + { + void Method() { } + } + } + """; using var workspace = TestWorkspace.CreateCSharp(code, composition: s_compositionWithoutOptions); using var testState = new TestState(workspace); @@ -1236,82 +1328,92 @@ public Task MoveToNamespace_MoveOneTypeInGlobalNamespace(string typeKeyword) [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758")] public Task MoveToNamespace_PartialTypesInNamesapce_SelectType() => TestMoveToNamespaceAsync( -@"namespace NS -{ - partial class MyClass[||] - { - } - - partial class MyClass - { - } -}", + """ + namespace NS + { + partial class MyClass[||] + { + } + + partial class MyClass + { + } + } + """, expectedSuccess: false); [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758")] public Task MoveToNamespace_PartialTypesInNamesapce_SelectNamespace() => TestMoveToNamespaceAsync( -@"namespace NS[||] -{ - partial class MyClass - { - } - - partial class MyClass - { - } -}", + """ + namespace NS[||] + { + partial class MyClass + { + } + + partial class MyClass + { + } + } + """, expectedSuccess: false); [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758")] public Task MoveToNamespace_PartialTypesInGlobalNamesapce() => TestMoveToNamespaceAsync( -@"partial class MyClass[||] -{ -} -partial class MyClass -{ -}", + """ + partial class MyClass[||] + { + } + partial class MyClass + { + } + """, expectedSuccess: false); [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/39234")] public async Task TestMultiTargetingProject() { // Create two projects with same project file path and single linked document to simulate a multi-targeting project. - var input = @" - - -namespace A -{ - public class Class1 - { - } - - public class Class2[||] - { - } -} - - - - - -"; + var input = """ + + + + namespace A + { + public class Class1 + { + } + + public class Class2[||] + { + } + } + + + + + + + """; var expected = -@"namespace A -{ - public class Class1 - { - } -} - -namespace B -{ - public class Class2 - { - } -}"; + """ + namespace A + { + public class Class1 + { + } + } + + namespace B + { + public class Class2 + { + } + } + """; using var workspace = TestWorkspace.Create(System.Xml.Linq.XElement.Parse(input), composition: s_composition, openDocuments: false); // Set the target namespace to "B" @@ -1338,20 +1440,24 @@ public class Class2 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35507")] public Task MoveToNamespace_MoveTypeFromSystemNamespace() => TestMoveToNamespaceAsync( -@"namespace System -{ - [||]class A - { - - } -}", -expectedMarkup: @"namespace {|Warning:Test|} -{ - [||]class A - { - - } -}", + """ + namespace System + { + [||]class A + { + + } + } + """, +expectedMarkup: """ + namespace {|Warning:Test|} + { + [||]class A + { + + } + } + """, targetNamespace: "Test", expectedSymbolChanges: new Dictionary() { diff --git a/src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs b/src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs index 28c93b64e2df1..5ae7c2be30fe9 100644 --- a/src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs +++ b/src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs @@ -46,9 +46,11 @@ await TestAsync(testHost, composition, "", async w => public async Task FindClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -60,9 +62,11 @@ await TestAsync( public async Task FindRecord(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"record Goo +testHost, composition, """ +record Goo { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -74,9 +78,11 @@ await TestAsync( public async Task FindRecordClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"record class Goo +testHost, composition, """ +record class Goo { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -87,17 +93,17 @@ await TestAsync( [CombinatorialData] public async Task FindRecordStruct(TestHost testHost, Composition composition) { - var content = XElement.Parse(@" - - - -record struct Goo -{ -} - - - -"); + var content = XElement.Parse(""" + + + + record struct Goo + { + } + + + + """); await TestAsync(testHost, composition, content, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); @@ -109,16 +115,16 @@ await TestAsync(testHost, composition, content, async w => [CombinatorialData] public async Task FindClassInFileScopedNamespace(TestHost testHost, Composition composition) { - var content = XElement.Parse(@" - - - -namespace FileScopedNS; -class Goo { } - - - -"); + var content = XElement.Parse(""" + + + + namespace FileScopedNS; + class Goo { } + + + + """); await TestAsync(testHost, composition, content, async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); @@ -131,9 +137,11 @@ await TestAsync(testHost, composition, content, async w => public async Task FindVerbatimClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class @static +testHost, composition, """ +class @static { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("static")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "static", "[|static|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -149,7 +157,8 @@ await TestAsync( public async Task FindNestedClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { class Bar { @@ -157,7 +166,8 @@ internal class DogBed { } } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("DogBed")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "DogBed", "[|DogBed|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -169,7 +179,8 @@ internal class DogBed public async Task FindMemberInANestedClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { class Bar { @@ -180,7 +191,8 @@ public void Method() } } } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Method")).Single(); VerifyNavigateToResultItem(item, "Method", "[|Method|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo.Bar.DogBed", "Test")); @@ -192,11 +204,13 @@ public void Method() public async Task FindGenericClassWithConstraints(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"using System.Collections; +testHost, composition, """ +using System.Collections; class Goo where T : IEnumerable { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -208,14 +222,16 @@ class Goo where T : IEnumerable public async Task FindGenericMethodWithConstraints(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"using System; +testHost, composition, """ +using System; class Goo { public void Bar(T item) where T : IComparable { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|](T)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -227,7 +243,8 @@ public void Bar(T item) where T : IComparable public async Task FindPartialClass(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"public partial class Goo +testHost, composition, """ +public partial class Goo { int a; } @@ -235,7 +252,8 @@ await TestAsync( partial class Goo { int b; -}", async w => +} +""", async w => { var expecteditem1 = new NavigateToItem("Goo", NavigateToItemKind.Class, "csharp", null, null, s_emptyExactPatternMatch, null); var expecteditems = new List { expecteditem1, expecteditem1 }; @@ -251,9 +269,11 @@ partial class Goo public async Task FindTypesInMetadata(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"using System; +testHost, composition, """ +using System; -Class Program { FileStyleUriParser f; }", async w => +Class Program { FileStyleUriParser f; } +""", async w => { var items = await _aggregator.GetItemsAsync("FileStyleUriParser"); Assert.Equal(0, items.Count()); @@ -265,12 +285,14 @@ await TestAsync( public async Task FindClassInNamespace(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"namespace Bar +testHost, composition, """ +namespace Bar { class Goo { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal); @@ -282,9 +304,11 @@ class Goo public async Task FindStruct(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"struct Bar +testHost, composition, """ +struct Bar { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("B")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Structure, Glyph.StructureInternal); @@ -296,12 +320,14 @@ await TestAsync( public async Task FindEnum(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"enum Colors +testHost, composition, """ +enum Colors { Red, Green, Blue -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Colors")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "Colors", "[|Colors|]", PatternMatchKind.Exact, NavigateToItemKind.Enum, Glyph.EnumInternal); @@ -313,12 +339,14 @@ await TestAsync( public async Task FindEnumMember(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"enum Colors +testHost, composition, """ +enum Colors { Red, Green, Blue -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("R")).Single(); VerifyNavigateToResultItem(item, "Red", "[|R|]ed", PatternMatchKind.Prefix, NavigateToItemKind.EnumItem, Glyph.EnumMemberPublic); @@ -330,10 +358,12 @@ await TestAsync( public async Task FindField1(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int bar; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("b")).Single(); VerifyNavigateToResultItem(item, "bar", "[|b|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -345,10 +375,12 @@ await TestAsync( public async Task FindField2(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int bar; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("ba")).Single(); VerifyNavigateToResultItem(item, "bar", "[|ba|]r", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -360,10 +392,12 @@ await TestAsync( public async Task FindField3(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int bar; -}", async w => +} +""", async w => { Assert.Empty(await _aggregator.GetItemsAsync("ar")); }); @@ -374,10 +408,12 @@ await TestAsync( public async Task FindVerbatimField(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int @string; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("string")).Single(); VerifyNavigateToResultItem(item, "string", "[|string|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -393,10 +429,12 @@ await TestAsync( public async Task FindPtrField1(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int* bar; -}", async w => +} +""", async w => { Assert.Empty(await _aggregator.GetItemsAsync("ar")); }); @@ -407,10 +445,12 @@ await TestAsync( public async Task FindPtrField2(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int* bar; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("b")).Single(); VerifyNavigateToResultItem(item, "bar", "[|b|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate); @@ -422,10 +462,12 @@ await TestAsync( public async Task FindConstField(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { const int bar = 7; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("ba")).Single(); VerifyNavigateToResultItem(item, "bar", "[|ba|]r", PatternMatchKind.Prefix, NavigateToItemKind.Constant, Glyph.ConstantPrivate); @@ -461,10 +503,12 @@ await TestAsync(testHost, composition, program, async w => public async Task FindAutoProperty(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { int Bar { get; set; } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("B")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Property, Glyph.PropertyPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -476,10 +520,12 @@ await TestAsync( public async Task FindMethod(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { void DoSomething(); -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("DS")).Single(); VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething()", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -491,10 +537,12 @@ await TestAsync( public async Task FindVerbatimMethod(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { void @static(); -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("static")).Single(); VerifyNavigateToResultItem(item, "static", "[|static|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -510,12 +558,14 @@ await TestAsync( public async Task FindParameterizedMethod(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { void DoSomething(int a, string b) { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("DS")).Single(); VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething(int, string)", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -527,12 +577,14 @@ void DoSomething(int a, string b) public async Task FindConstructor(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { public Goo() { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -544,12 +596,14 @@ public Goo() public async Task FindParameterizedConstructor(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { public Goo(int i) { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method); VerifyNavigateToResultItem(item, "Goo", "[|Goo|](int)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -561,12 +615,14 @@ public Goo(int i) public async Task FindStaticConstructor(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { static Goo() { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method && t.Name != ".ctor"); VerifyNavigateToResultItem(item, "Goo", "[|Goo|].static Goo()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -593,10 +649,12 @@ public async Task FindPartialMethods(TestHost testHost, Composition composition) public async Task FindPartialMethodDefinitionOnly(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"partial class Goo +testHost, composition, """ +partial class Goo { partial void Bar(); -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_1_2, "Goo", "test1.cs", "Test")); @@ -608,12 +666,14 @@ await TestAsync( public async Task FindPartialMethodImplementationOnly(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"partial class Goo +testHost, composition, """ +partial class Goo { partial void Bar() { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_1_2, "Goo", "test1.cs", "Test")); @@ -655,9 +715,11 @@ await TestAsync(testHost, composition, program, async w => public async Task FindInterface(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"public interface IGoo +testHost, composition, """ +public interface IGoo { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("IG")).Single(); VerifyNavigateToResultItem(item, "IGoo", "[|IG|]oo", PatternMatchKind.Prefix, NavigateToItemKind.Interface, Glyph.InterfacePublic); @@ -669,9 +731,11 @@ await TestAsync( public async Task FindTopLevelLocalFunction(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"void Goo() +testHost, composition, """ +void Goo() { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -683,9 +747,11 @@ await TestAsync( public async Task FindTopLevelLocalFunction_WithParameters(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"void Goo(int i) +testHost, composition, """ +void Goo(int i) { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(); VerifyNavigateToResultItem(item, "Goo", "[|Goo|](int)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -697,9 +763,11 @@ await TestAsync( public async Task FindTopLevelLocalFunction_WithTypeArgumentsAndParameters(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"void Goo(int i) +testHost, composition, """ +void Goo(int i) { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(); VerifyNavigateToResultItem(item, "Goo", "[|Goo|](int)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -711,12 +779,14 @@ await TestAsync( public async Task FindNestedLocalFunctionTopLevelStatements(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"void Goo() +testHost, composition, """ +void Goo() { void Bar() { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -728,7 +798,7 @@ void Bar() public async Task FindLocalFunctionInMethod(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @" +testHost, composition, """ class C { void M() @@ -740,7 +810,8 @@ void Bar() } } } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Goo")).Single(); VerifyNavigateToResultItem(item, "Goo", "[|Goo|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -752,7 +823,7 @@ void Bar() public async Task FindNestedLocalFunctionInMethod(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @" +testHost, composition, """ class C { void M() @@ -764,7 +835,8 @@ void Bar() } } } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Bar")).Single(); VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -776,10 +848,12 @@ void Bar() public async Task FindDelegateInNamespace(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"namespace Goo +testHost, composition, """ +namespace Goo { delegate void DoStuff(); -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("DoStuff")).Single(x => x.Kind != "Method"); VerifyNavigateToResultItem(item, "DoStuff", "[|DoStuff|]", PatternMatchKind.Exact, NavigateToItemKind.Delegate, Glyph.DelegateInternal); @@ -791,12 +865,14 @@ await TestAsync( public async Task FindLambdaExpression(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"using System; +testHost, composition, """ +using System; class Goo { Func sqr = x => x * x; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("sqr")).Single(); VerifyNavigateToResultItem(item, "sqr", "[|sqr|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -808,10 +884,12 @@ class Goo public async Task FindArray(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { object[] itemArray; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("itemArray")).Single(); VerifyNavigateToResultItem(item, "itemArray", "[|itemArray|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -823,7 +901,8 @@ await TestAsync( public async Task FindClassAndMethodWithSameName(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { } @@ -832,7 +911,8 @@ class Test void Goo() { } -}", async w => +} +""", async w => { var expectedItems = new List { @@ -849,7 +929,8 @@ void Goo() public async Task FindMethodNestedInGenericTypes(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class A +testHost, composition, """ +class A { class B { @@ -860,7 +941,8 @@ void M() } } } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("M")).Single(); VerifyNavigateToResultItem(item, "M", "[|M|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "A.B.C", "Test")); @@ -872,7 +954,8 @@ void M() public async Task OrderingOfConstructorsAndTypes(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class C1 +testHost, composition, """ +class C1 { C1(int i) { @@ -888,7 +971,8 @@ class C2 static C2() { } -}", async w => +} +""", async w => { var expecteditems = new List { @@ -909,12 +993,14 @@ static C2() public async Task NavigateToMethodWithNullableParameter(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class C +testHost, composition, """ +class C { void M(object? o) { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("M")).Single(); VerifyNavigateToResultItem(item, "M", "[|M|](object?)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate); @@ -927,9 +1013,11 @@ public async Task StartStopSanity(TestHost testHost, Composition composition) { // Verify that multiple calls to start/stop and dispose don't blow up await TestAsync( -testHost, composition, @"public class Goo +testHost, composition, """ +public class Goo { -}", async w => +} +""", async w => { // Do one set of queries Assert.Single((await _aggregator.GetItemsAsync("Goo")).Where(x => x.Kind != "Method")); @@ -948,7 +1036,12 @@ await TestAsync( [CombinatorialData] public async Task DescriptionItems(TestHost testHost, Composition composition) { - await TestAsync(testHost, composition, "public\r\nclass\r\nGoo\r\n{ }", async w => + await TestAsync(testHost, composition, """ + public + class + Goo + { } + """, async w => { var item = (await _aggregator.GetItemsAsync("G")).Single(x => x.Kind != "Method"); var itemDisplay = item.DisplayFactory.CreateItemDisplay(item); @@ -1083,19 +1176,21 @@ await TestAsync(testHost, composition, source, async w => public async Task TestIndexer1(TestHost testHost, Composition composition) { var source = -@"class C -{ - public int this[int y] { get { } } -} + """ + class C + { + public int this[int y] { get { } } + } -class D -{ - void Goo() - { - var q = new C(); - var b = q[4]; - } -}"; + class D + { + void Goo() + { + var q = new C(); + var b = q[4]; + } + } + """; await TestAsync(testHost, composition, source, async w => { var expecteditems = new List @@ -1257,30 +1352,30 @@ await TestAsync(testHost, composition, source, async w => [WorkItem("https://github.com/dotnet/roslyn/issues/8009")] public async Task NavigateToGeneratedFiles() { - using var workspace = TestWorkspace.Create(@" - - - - namespace N - { - public partial class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public partial class C - { - public void VisibleMethod_Generated() { } - } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + namespace N + { + public partial class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public partial class C + { + public void VisibleMethod_Generated() { } + } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1302,12 +1397,14 @@ public void VisibleMethod_Generated() { } public async Task FindFuzzy1(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class C +testHost, composition, """ +class C { public void ToError() { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("ToEror")).Single(); VerifyNavigateToResultItem(item, "ToError", "ToError()", PatternMatchKind.Fuzzy, NavigateToItemKind.Method, Glyph.MethodPublic); @@ -1319,12 +1416,14 @@ public void ToError() public async Task Test__arglist(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class C +testHost, composition, """ +class C { public void ToError(__arglist) { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("ToError")).Single(); VerifyNavigateToResultItem(item, "ToError", "[|ToError|](__arglist)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic); @@ -1334,24 +1433,24 @@ public void ToError(__arglist) [Fact] public async Task DoNotIncludeTrivialPartialContainer() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - public void VisibleMethod() { } - } - - - public partial class Outer - { - public partial class Inner { } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + public void VisibleMethod() { } + } + + + public partial class Outer + { + public partial class Inner { } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1367,25 +1466,25 @@ public partial class Inner { } [Fact] public async Task DoNotIncludeTrivialPartialContainerWithMultipleNestedTypes() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - public void VisibleMethod() { } - } - - - public partial class Outer - { - public partial class Inner1 { } - public partial class Inner2 { } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + public void VisibleMethod() { } + } + + + public partial class Outer + { + public partial class Inner1 { } + public partial class Inner2 { } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1401,24 +1500,24 @@ public partial class Inner2 { } [Fact] public async Task DoNotIncludeWhenAllAreTrivialPartialContainer() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - public partial class Inner1 { } - } - - - public partial class Outer - { - public partial class Inner2 { } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + public partial class Inner1 { } + } + + + public partial class Outer + { + public partial class Inner2 { } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1431,24 +1530,24 @@ public partial class Inner2 { } [Fact] public async Task DoIncludeNonTrivialPartialContainer() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - public void VisibleMethod() { } - } - - - public partial class Outer - { - public void VisibleMethod2() { } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + public void VisibleMethod() { } + } + + + public partial class Outer + { + public void VisibleMethod2() { } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1465,25 +1564,25 @@ public void VisibleMethod2() { } [Fact] public async Task DoIncludeNonTrivialPartialContainerWithNestedType() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - public void VisibleMethod() { } - } - - - public partial class Outer - { - public void VisibleMethod2() { } - public class Inner { } - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + public void VisibleMethod() { } + } + + + public partial class Outer + { + public void VisibleMethod2() { } + public class Inner { } + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1500,17 +1599,17 @@ public class Inner { } [Fact] public async Task DoIncludePartialWithNoContents() { - using var workspace = TestWorkspace.Create(@" - - - - public partial class Outer - { - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public partial class Outer + { + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1526,18 +1625,18 @@ public partial class Outer [Fact] public async Task DoIncludeNonPartialOnlyContainingNestedTypes() { - using var workspace = TestWorkspace.Create(@" - - - - public class Outer - { - public class Inner {} - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public class Outer + { + public class Inner {} + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1553,17 +1652,17 @@ public class Inner {} [Fact] public async Task DoIncludeSymbolsFromSourceGeneratedFiles() { - using var workspace = TestWorkspace.Create(@" - - - - public class C - { - } - - - -", composition: EditorTestCompositions.EditorFeatures); + using var workspace = TestWorkspace.Create(""" + + + + public class C + { + } + + + + """, composition: EditorTestCompositions.EditorFeatures); _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1583,14 +1682,16 @@ public async Task DoIncludeSymbolsFromMultipleSourceGeneratedFiles() files: Array.Empty(), sourceGeneratedFiles: new[] { - @" -public partial class C -{ -}", - @" -public partial class C -{ -}", + """ + public partial class C + { + } + """, + """ + public partial class C + { + } + """, }, composition: EditorTestCompositions.EditorFeatures); @@ -1611,14 +1712,16 @@ public partial class C public async Task FindMethodWithTuple(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"class Goo +testHost, composition, """ +class Goo { public void Method( (int x, Dictionary y) t1, (bool b, global::System.Int32 c) t2) { } -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Method")).Single(); VerifyNavigateToResultItem(item, "Method", "[|Method|]((int x, Dictionary y), (bool b, global::System.Int32 c))", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test")); @@ -1631,9 +1734,11 @@ public void Method( public async Task FindRecordMember1(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"record Goo(int Member) +testHost, composition, """ +record Goo(int Member) { -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Member")).Single(x => x.Kind == NavigateToItemKind.Property); VerifyNavigateToResultItem(item, "Member", "[|Member|]", PatternMatchKind.Exact, NavigateToItemKind.Property, Glyph.PropertyPublic); @@ -1646,10 +1751,12 @@ await TestAsync( public async Task FindRecordMember2(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"record Goo(int Member) +testHost, composition, """ +record Goo(int Member) { public int Member { get; } = Member; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Member")).Single(x => x.Kind == NavigateToItemKind.Property); VerifyNavigateToResultItem(item, "Member", "[|Member|]", PatternMatchKind.Exact, NavigateToItemKind.Property, Glyph.PropertyPublic); @@ -1662,10 +1769,12 @@ await TestAsync( public async Task FindRecordMember3(TestHost testHost, Composition composition) { await TestAsync( -testHost, composition, @"record Goo(int Member) +testHost, composition, """ +record Goo(int Member) { public int Member = Member; -}", async w => +} +""", async w => { var item = (await _aggregator.GetItemsAsync("Member")).Single(x => x.Kind == NavigateToItemKind.Field); VerifyNavigateToResultItem(item, "Member", "[|Member|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPublic); @@ -1681,30 +1790,30 @@ private static bool IsFromFile(NavigateToItem item, string fileName) [CombinatorialData] public async Task NavigateToPrioritizeResultInCurrentDocument1(TestHost testHost) { - await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(@" - - - - namespace N - { - public class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public class D - { - public void VisibleMethod() { } - } - } - - - -"), async workspace => + await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(""" + + + + namespace N + { + public class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public class D + { + public void VisibleMethod() { } + } + } + + + + """), async workspace => { _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1727,30 +1836,30 @@ public void VisibleMethod() { } [CombinatorialData] public async Task NavigateToPrioritizeResultInCurrentDocument2(TestHost testHost) { - await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(@" - - - - namespace N - { - public class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public class D - { - public void VisibleMethod() { } - } - } - - - -"), async workspace => + await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(""" + + + + namespace N + { + public class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public class D + { + public void VisibleMethod() { } + } + } + + + + """), async workspace => { _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1773,30 +1882,30 @@ public void VisibleMethod() { } [CombinatorialData] public async Task NavigateToPrioritizeResultInCurrentDocument3(TestHost testHost) { - await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(@" - - - - namespace N - { - public class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public class D - { - public void VisibleMethod() { } - } - } - - - -"), async workspace => + await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(""" + + + + namespace N + { + public class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public class D + { + public void VisibleMethod() { } + } + } + + + + """), async workspace => { _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1819,30 +1928,30 @@ public void VisibleMethod() { } [CombinatorialData] public async Task NavigateToPrioritizeResultInCurrentDocument4(TestHost testHost) { - await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(@" - - - - namespace N - { - public class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public class D - { - public void VisibleMethod() { } - } - } - - - -"), async workspace => + await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(""" + + + + namespace N + { + public class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public class D + { + public void VisibleMethod() { } + } + } + + + + """), async workspace => { _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); @@ -1865,30 +1974,30 @@ public void VisibleMethod() { } [CombinatorialData] public async Task NavigateToPrioritizeResultInCurrentDocument5(TestHost testHost) { - await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(@" - - - - namespace N - { - public class C - { - public void VisibleMethod() { } - } - } - - - namespace N - { - public class D - { - public void VisibleMethod() { } - } - } - - - -"), async workspace => + await TestAsync(testHost, Composition.FirstActiveAndVisible, XElement.Parse(""" + + + + namespace N + { + public class C + { + public void VisibleMethod() { } + } + } + + + namespace N + { + public class D + { + public void VisibleMethod() { } + } + } + + + + """), async workspace => { _provider = CreateProvider(workspace); _aggregator = new NavigateToTestAggregator(_provider); diff --git a/src/EditorFeatures/CSharpTest/PdbSourceDocument/ImplementationAssemblyLookupServiceTests.cs b/src/EditorFeatures/CSharpTest/PdbSourceDocument/ImplementationAssemblyLookupServiceTests.cs index 52e8f4a35a791..3853bc437017c 100644 --- a/src/EditorFeatures/CSharpTest/PdbSourceDocument/ImplementationAssemblyLookupServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/PdbSourceDocument/ImplementationAssemblyLookupServiceTests.cs @@ -24,12 +24,13 @@ public class ImplementationAssemblyLookupServiceTests : AbstractPdbSourceDocumen [Fact] public async Task Net6SdkLayout_InvalidXml() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -61,12 +62,13 @@ await RunTestAsync(async path => [Fact] public async Task Net6SdkLayout() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -100,12 +102,13 @@ await RunTestAsync(async path => [Fact] public async Task Net6SdkLayout_PacksInPath() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -141,15 +144,16 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + """; await RunTestAsync(async path => { @@ -191,24 +195,25 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_Namespace() { - var source = @" -namespace A -{ - namespace B - { - public class C - { - public class D - { - // A change - public event System.EventHandler [|E|] { add { } remove { } } - } - } - } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(A.B.C))] -"; + var source = """ + namespace A + { + namespace B + { + public class C + { + public class D + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + } + } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(A.B.C))] + """; await RunTestAsync(async path => { @@ -251,24 +256,25 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_Generics() { - var source = @" -namespace A -{ - namespace B - { - public class C - { - public class D - { - // A change - public event System.EventHandler [|E|] { add { } remove { } } - } - } - } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(A.B.C<>))] -"; + var source = """ + namespace A + { + namespace B + { + public class C + { + public class D + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + } + } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(A.B.C<>))] + """; await RunTestAsync(async path => { @@ -311,18 +317,19 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_NestedType() { - var source = @" -public class C -{ - public class D - { - // A change - public event System.EventHandler [|E|] { add { } remove { } } - } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -"; + var source = """ + public class C + { + public class D + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + """; await RunTestAsync(async path => { @@ -364,15 +371,16 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_Cache() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + """; await RunTestAsync(async path => { @@ -421,22 +429,23 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_MultipleTypes_Cache() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -} - -public class D { } -public class E { } -public class F { }"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(D))] -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(E))] -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(F))] -"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + + public class D { } + public class E { } + public class F { } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(D))] + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(E))] + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(F))] + """; await RunTestAsync(async path => { @@ -485,15 +494,16 @@ await RunTestAsync(async path => [Fact] public async Task FollowTypeForwards_MultipleHops_Cache() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + """; await RunTestAsync(async path => { diff --git a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbFileLocatorServiceTests.cs b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbFileLocatorServiceTests.cs index 149cf3ddba1e4..a80681c87a0bf 100644 --- a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbFileLocatorServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbFileLocatorServiceTests.cs @@ -18,11 +18,12 @@ public class PdbFileLocatorServiceTests : AbstractPdbSourceDocumentTests [Fact] public async Task ReturnsPdbPathFromDebugger() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -46,11 +47,12 @@ await RunTestAsync(async path => [Fact] public async Task DoesntReadNonPortablePdbs() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -76,11 +78,12 @@ await RunTestAsync(async path => [Fact] public async Task NoPdbFoundReturnsNull() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { diff --git a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentLoaderServiceTests.cs b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentLoaderServiceTests.cs index 2f8e57c0a597b..ce681fd57d842 100644 --- a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentLoaderServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentLoaderServiceTests.cs @@ -22,11 +22,12 @@ public class PdbSourceDocumentLoaderServiceTests : AbstractPdbSourceDocumentTest [Fact] public async Task ReturnsSourceFileFromSourceLink() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -56,11 +57,12 @@ await RunTestAsync(async path => [Fact] public async Task NoUrlFoundReturnsNull() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { diff --git a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentTests.cs b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentTests.cs index ea5ac5d35666d..3995e2ce1b3c5 100644 --- a/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentTests.cs +++ b/src/EditorFeatures/CSharpTest/PdbSourceDocument/PdbSourceDocumentTests.cs @@ -24,19 +24,20 @@ public partial class PdbSourceDocumentTests : AbstractPdbSourceDocumentTests [CombinatorialData] public async Task PreprocessorSymbols1(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ -#if SOME_DEFINED_CONSTANT - public void [|M|]() - { - } -#else - public void M() - { - } -#endif -}"; + var source = """ + public class C + { + #if SOME_DEFINED_CONSTANT + public void [|M|]() + { + } + #else + public void M() + { + } + #endif + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.M"), preprocessorSymbols: new[] { "SOME_DEFINED_CONSTANT" }); } @@ -44,19 +45,20 @@ public void M() [CombinatorialData] public async Task PreprocessorSymbols2(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ -#if SOME_DEFINED_CONSTANT - public void M() - { - } -#else - public void [|M|]() - { - } -#endif -}"; + var source = """ + public class C + { + #if SOME_DEFINED_CONSTANT + public void M() + { + } + #else + public void [|M|]() + { + } + #endif + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.M")); } @@ -64,14 +66,15 @@ public void M() [CombinatorialData] public async Task Method(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public void [|M|]() - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class C + { + public void [|M|]() + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.M")); } @@ -79,14 +82,15 @@ public class C [CombinatorialData] public async Task Constructor(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public [|C|]() - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class C + { + public [|C|]() + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C..ctor")); } @@ -94,14 +98,15 @@ public class C [CombinatorialData] public async Task Parameter(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public void M(int [|a|]) - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class C + { + public void M(int [|a|]) + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.M").Parameters.First()); } @@ -109,11 +114,12 @@ public void M(int [|a|]) [CombinatorialData] public async Task Class_FromTypeDefinitionDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|C|] -{ - // this is a comment that wouldn't appear in decompiled source -}"; + var source = """ + public class [|C|] + { + // this is a comment that wouldn't appear in decompiled source + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C")); } @@ -122,11 +128,12 @@ public class [|C|] [CombinatorialData] public async Task Constructor_FromTypeDefinitionDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|C|] -{ - // this is a comment that wouldn't appear in decompiled source -}"; + var source = """ + public class [|C|] + { + // this is a comment that wouldn't appear in decompiled source + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C..ctor")); } @@ -134,14 +141,15 @@ public class [|C|] [CombinatorialData] public async Task NestedClass_FromTypeDefinitionDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class Outer -{ - public class [|C|] - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class Outer + { + public class [|C|] + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer.C")); } @@ -149,14 +157,15 @@ public class [|C|] [CombinatorialData] public async Task NestedClassConstructor_FromTypeDefinitionDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class Outer -{ - public class [|C|] - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class Outer + { + public class [|C|] + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer.C..ctor")); } @@ -164,14 +173,15 @@ public class [|C|] [CombinatorialData] public async Task Class_FromTypeDefinitionDocumentOfNestedClass(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|Outer|] -{ - public class C - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class [|Outer|] + { + public class C + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer")); } @@ -179,14 +189,15 @@ public class C [CombinatorialData] public async Task Constructor_FromTypeDefinitionDocumentOfNestedClass(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|Outer|] -{ - public class C - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class [|Outer|] + { + public class C + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer..ctor")); } @@ -195,17 +206,18 @@ public class C [CombinatorialData] public async Task NestedClass_FromMethodDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class Outer -{ - public class [|C|] - { - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } - } -}"; + var source = """ + public class Outer + { + public class [|C|] + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer.C")); } @@ -213,17 +225,18 @@ public void M() [CombinatorialData] public async Task NestedClassConstructor_FromMethodDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class Outer -{ - public class [|C|] - { - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } - } -}"; + var source = """ + public class Outer + { + public class [|C|] + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer.C..ctor")); } @@ -232,17 +245,18 @@ public void M() [CombinatorialData] public async Task Class_FromMethodDocumentOfNestedClass(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|Outer|] -{ - public class C - { - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } - } -}"; + var source = """ + public class [|Outer|] + { + public class C + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer")); } @@ -251,17 +265,18 @@ public void M() [CombinatorialData] public async Task Constructor_FromMethodDocumentOfNestedClass(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|Outer|] -{ - public class C - { - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } - } -}"; + var source = """ + public class [|Outer|] + { + public class C + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("Outer..ctor")); } @@ -270,14 +285,15 @@ public void M() [CombinatorialData] public async Task Class_FromMethodDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|C|] -{ - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class [|C|] + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C")); } @@ -285,14 +301,15 @@ public void M() [CombinatorialData] public async Task Constructor_FromMethodDocument(Location pdbLocation, Location sourceLocation) { - var source = @" -public class [|C|] -{ - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + var source = """ + public class [|C|] + { + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C..ctor")); } @@ -300,11 +317,12 @@ public void M() [CombinatorialData] public async Task Field(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public int [|f|]; -}"; + var source = """ + public class C + { + public int [|f|]; + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.f")); } @@ -312,11 +330,12 @@ public class C [CombinatorialData] public async Task Property(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public int [|P|] { get; set; } -}"; + var source = """ + public class C + { + public int [|P|] { get; set; } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.P")); } @@ -324,11 +343,12 @@ public class C [CombinatorialData] public async Task Property_WithBody(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public int [|P|] { get { return 1; } } -}"; + var source = """ + public class C + { + public int [|P|] { get { return 1; } } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.P")); } @@ -336,11 +356,12 @@ public class C [CombinatorialData] public async Task EventField(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public event System.EventHandler [|E|]; -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|]; + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.E")); } @@ -348,16 +369,17 @@ public class C [CombinatorialData] public async Task EventField_WithMethod(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public event System.EventHandler [|E|]; + var source = """ + public class C + { + public event System.EventHandler [|E|]; - public void M() - { - // this is a comment that wouldn't appear in decompiled source - } -}"; + public void M() + { + // this is a comment that wouldn't appear in decompiled source + } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.E")); } @@ -365,22 +387,24 @@ public void M() [CombinatorialData] public async Task Event(Location pdbLocation, Location sourceLocation) { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await TestAsync(pdbLocation, sourceLocation, source, c => c.GetMember("C.E")); } [Fact] public async Task ReferenceAssembly_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; // A pdb won't be emitted when building a reference assembly so the first two parameters don't actually matter await TestAsync(Location.OnDisk, Location.OnDisk, source, c => c.GetMember("C.E"), buildReferenceAssembly: true, expectNullResult: true); } @@ -388,12 +412,13 @@ public event System.EventHandler [|E|] { add { } remove { } } [Fact] public async Task NugetPackageLayout() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -417,12 +442,13 @@ await RunTestAsync(async path => [Fact] public async Task Net6SdkLayout() { - var source = @" -public class C -{ - // A change - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + // A change + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -452,14 +478,14 @@ await RunTestAsync(async path => [Fact] public async Task Net6SdkLayout_WithOtherReferences() { - var source = @" -public class C -{ - public void [|M|](string d) - { - } -} -"; + var source = """ + public class C + { + public void [|M|](string d) + { + } + } + """; await RunTestAsync(async path => { @@ -496,17 +522,17 @@ await RunTestAsync(async path => [Fact] public async Task Net6SdkLayout_TypeForward() { - var source = @" -public class [|C|] -{ - public void M(string d) - { - } -} -"; - var typeForwardSource = @" -[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] -"; + var source = """ + public class [|C|] + { + public void M(string d) + { + } + } + """; + var typeForwardSource = """ + [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(C))] + """; await RunTestAsync(async path => { @@ -558,11 +584,12 @@ await RunTestAsync(async path => [Fact] public async Task NoPdb_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -580,11 +607,12 @@ await RunTestAsync(async path => [Fact] public async Task NoDll_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -602,11 +630,12 @@ await RunTestAsync(async path => [Fact] public async Task NoSource_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan); @@ -623,11 +652,12 @@ await RunTestAsync(async path => [Fact] public async Task WindowsPdb_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan); @@ -642,11 +672,12 @@ await RunTestAsync(async path => [Fact] public async Task EmptyPdb_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -664,11 +695,12 @@ await RunTestAsync(async path => [Fact] public async Task CorruptPdb_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -688,17 +720,19 @@ await RunTestAsync(async path => [Fact] public async Task OldPdb_NullResult() { - var source1 = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; - var source2 = @" -public class C -{ - // A change - public event System.EventHandler E { add { } remove { } } -}"; + var source1 = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; + var source2 = """ + public class C + { + // A change + public event System.EventHandler E { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -725,17 +759,19 @@ await RunTestAsync(async path => [CombinatorialData] public async Task SourceFileChecksumIncorrect_NullResult(Location pdbLocation) { - var source1 = @" -public class C -{ - public event System.EventHandler [|E|] { add { } remove { } } -}"; - var source2 = @" -public class C -{ - // A change - public event System.EventHandler E { add { } remove { } } -}"; + var source1 = """ + public class C + { + public event System.EventHandler [|E|] { add { } remove { } } + } + """; + var source2 = """ + public class C + { + // A change + public event System.EventHandler E { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -766,11 +802,12 @@ await RunTestAsync(async path => [InlineData(Location.OnDisk, "utf-8")] public async Task EncodedEmbeddedSource(Location pdbLocation, string encodingWebName) { - var source = @" -public class C -{ - public event System.EventHandler E { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler E { add { } remove { } } + } + """; var encoding = Encoding.GetEncoding(encodingWebName); @@ -794,12 +831,13 @@ await RunTestAsync(async path => [CombinatorialData] public async Task EncodedEmbeddedSource_SJIS(Location pdbLocation) { - var source = @" -public class C -{ - // ワ - public event System.EventHandler E { add { } remove { } } -}"; + var source = """ + public class C + { + // ワ + public event System.EventHandler E { add { } remove { } } + } + """; var encoding = Encoding.GetEncoding("SJIS"); @@ -823,12 +861,13 @@ await RunTestAsync(async path => [CombinatorialData] public async Task EncodedEmbeddedSource_SJIS_FallbackEncoding(Location pdbLocation) { - var source = @" -public class C -{ - // ワ - public event System.EventHandler E { add { } remove { } } -}"; + var source = """ + public class C + { + // ワ + public event System.EventHandler E { add { } remove { } } + } + """; var encoding = Encoding.GetEncoding("SJIS"); @@ -851,11 +890,12 @@ await RunTestAsync(async path => [Fact] public async Task OptionTurnedOff_NullResult() { - var source = @" -public class C -{ - public event System.EventHandler E { add { } remove { } } -}"; + var source = """ + public class C + { + public event System.EventHandler E { add { } remove { } } + } + """; await RunTestAsync(async path => { @@ -886,26 +926,26 @@ await RunTestAsync(async path => [Fact] public async Task MethodInPartialType_NavigateToCorrectFile() { - var source1 = @" -public partial class C -{ - public void M1() - { - } -} -"; - var source2 = @" -using System.Threading.Tasks; + var source1 = """ + public partial class C + { + public void M1() + { + } + } + """; + var source2 = """ + using System.Threading.Tasks; -public partial class C -{ - public static async Task [|M2|]() => await M3(); + public partial class C + { + public static async Task [|M2|]() => await M3(); - private static async Task M3() - { - } -} -"; + private static async Task M3() + { + } + } + """; await RunTestAsync(async path => { diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs index 14450779523bd..53a3b5dfd857a 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs @@ -34,11 +34,11 @@ public class DiagnosticAnalyzerQuickInfoSourceTests public async Task ErrorTitleIsShownOnDisablePragma() { await TestInMethodAsync( -@" -#pragma warning disable CS0219$$ - var i = 0; -#pragma warning restore CS0219 -", GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); + """ + #pragma warning disable CS0219$$ + var i = 0; + #pragma warning restore CS0219 + """, GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); } [WorkItem("https://github.com/dotnet/roslyn/issues/46604")] @@ -46,11 +46,11 @@ await TestInMethodAsync( public async Task ErrorTitleIsShownOnRestorePragma() { await TestInMethodAsync( -@" -#pragma warning disable CS0219 - var i = 0; -#pragma warning restore CS0219$$ -", GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); + """ + #pragma warning disable CS0219 + var i = 0; + #pragma warning restore CS0219$$ + """, GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); } [WorkItem("https://github.com/dotnet/roslyn/issues/46604")] @@ -58,9 +58,9 @@ await TestInMethodAsync( public async Task DisabledWarningNotExistingInCodeIsDisplayedByTitleWithoutCodeDetails() { await TestInMethodAsync( -@" -#pragma warning disable CS0219$$ -", GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); + """ + #pragma warning disable CS0219$$ + """, GetFormattedErrorTitle(ErrorCode.WRN_UnreferencedVarAssg)); } [WorkItem("https://github.com/dotnet/roslyn/issues/49102")] @@ -123,17 +123,17 @@ await TestInMethodAsync( public async Task ErrorTitleIsShwonInSupressMessageAttribute() { await TestAsync( -@" -using System.Diagnostics.CodeAnalysis; -namespace T -{ - [SuppressMessage(""CodeQuality"", ""IDE0051$$"")] - public class C - { - private int _i; - } -} -", GetFormattedIDEAnalyzerTitle(51, nameof(AnalyzersResources.Remove_unused_private_members)), ImmutableArray.Empty); + """ + using System.Diagnostics.CodeAnalysis; + namespace T + { + [SuppressMessage("CodeQuality", "IDE0051$$")] + public class C + { + private int _i; + } + } + """, GetFormattedIDEAnalyzerTitle(51, nameof(AnalyzersResources.Remove_unused_private_members)), ImmutableArray.Empty); } [WorkItem("https://github.com/dotnet/roslyn/issues/46604")] @@ -153,7 +153,9 @@ public class C [InlineData(@"[SuppressMessage(""CodeQuality"", """" + (DiagnosticIds.IDE0051 +$$ "": Remove unused private member""))]", true)] [InlineData(@"[SuppressMessage(category: ""CodeQuality"", checkId$$: DiagnosticIds.IDE0051 + "": Remove unused private member"")]", true)] // False negative: Aliased attribute is not supported - [InlineData(@"[SM(""CodeQuality"", ""IDE0051$$""", false)] + [InlineData(""" + [SM("CodeQuality", "IDE0051$$" + """, false)] public async Task QuickInfoSuppressMessageAttributeUseCases(string suppressMessageAttribute, bool shouldShowQuickInfo) { var description = shouldShowQuickInfo @@ -243,12 +245,16 @@ private static string GetFormattedIDEAnalyzerTitle(int ideDiagnosticId, string n protected static Task TestInClassAsync(string code, string expectedDescription, params TextSpan[] relatedSpans) => TestAsync( -@"class C -{" + code + "}", expectedDescription, relatedSpans.ToImmutableArray()); + """ + class C + { + """ + code + "}", expectedDescription, relatedSpans.ToImmutableArray()); protected static Task TestInMethodAsync(string code, string expectedDescription, params TextSpan[] relatedSpans) => TestInClassAsync( -@"void M() -{" + code + "}", expectedDescription, relatedSpans); + """ + void M() + { + """ + code + "}", expectedDescription, relatedSpans); } } diff --git a/src/EditorFeatures/CSharpTest/RawStringLiteral/RawStringLiteralCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/RawStringLiteral/RawStringLiteralCommandHandlerTests.cs index 76f7edc4f690e..a024b59b1ff53 100644 --- a/src/EditorFeatures/CSharpTest/RawStringLiteral/RawStringLiteralCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/RawStringLiteral/RawStringLiteralCommandHandlerTests.cs @@ -88,13 +88,17 @@ public void SendReturn(bool handled) public void TestReturnInSixQuotes() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$"""""""); + """" + var v = """$$""" + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = """""" -$${|VirtualSpaces-4:|} - """""""); + """" + var v = """ + $${|VirtualSpaces-4:|} + """ + """"); } [WpfFact] @@ -105,61 +109,79 @@ public void TestReturnInSixQuotesWithSemicolonAfter() testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = """""" -$${|VirtualSpaces-4:|} - """""";"); + """" + var v = """ + $${|VirtualSpaces-4:|} + """; + """"); } [WpfFact] public void TestReturnInSixQuotesNotAtMiddle() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""""$$"""""); + """"" + var v = """"$$"" + """""); testState.SendReturn(handled: false); testState.AssertCodeIs( -@"var v = """"""""$$"""""); + """"" + var v = """"$$"" + """""); } [WpfFact] public void TestReturnInSixQuotes_Interpolated() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = $""""""$$"""""""); + """" + var v = $"""$$""" + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = $"""""" -$${|VirtualSpaces-4:|} - """""""); + """" + var v = $""" + $${|VirtualSpaces-4:|} + """ + """"); } [WpfFact] public void TestReturnInSixQuotesMoreQuotesLaterOn() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$""""""; -Console.WriteLine(""Goo"");"); + """" + var v = """$$"""; + Console.WriteLine("Goo"); + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = """""" -$${|VirtualSpaces-4:|} - """"""; -Console.WriteLine(""Goo"");"); + """" + var v = """ + $${|VirtualSpaces-4:|} + """; + Console.WriteLine("Goo"); + """"); } [WpfFact] public void TestReturnInSixQuotesAsArgument1() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = WriteLine(""""""$$"""""""); + """" + var v = WriteLine("""$$""" + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine("""""" -$${|VirtualSpaces-4:|} - """""""); + """" + var v = WriteLine(""" + $${|VirtualSpaces-4:|} + """ + """"); } [WpfFact] @@ -170,9 +192,11 @@ public void TestReturnInSixQuotesAsArgument2() testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine("""""" -$${|VirtualSpaces-4:|} - """""")"); + """" + var v = WriteLine(""" + $${|VirtualSpaces-4:|} + """) + """"); } [WpfFact] @@ -183,54 +207,68 @@ public void TestReturnInSixQuotesAsArgument3() testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine("""""" -$${|VirtualSpaces-4:|} - """""");"); + """" + var v = WriteLine(""" + $${|VirtualSpaces-4:|} + """); + """"); } [WpfFact] public void TestReturnInSixQuotesAsArgument4() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = WriteLine( - """"""$$"""""""); + """" + var v = WriteLine( + """$$""" + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine( - """""" -$${|VirtualSpaces-4:|} - """""""); + """" + var v = WriteLine( + """ + $${|VirtualSpaces-4:|} + """ + """"); } [WpfFact] public void TestReturnInSixQuotesAsArgument5() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = WriteLine( - """"""$$"""""")"); + """" + var v = WriteLine( + """$$""") + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine( - """""" -$${|VirtualSpaces-4:|} - """""")"); + """" + var v = WriteLine( + """ + $${|VirtualSpaces-4:|} + """) + """"); } [WpfFact] public void TestReturnInSixQuotesAsArgument6() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = WriteLine( - """"""$$"""""");"); + """" + var v = WriteLine( + """$$"""); + """"); testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = WriteLine( - """""" -$${|VirtualSpaces-4:|} - """""");"); + """" + var v = WriteLine( + """ + $${|VirtualSpaces-4:|} + """); + """"); } [WpfFact] @@ -241,20 +279,26 @@ public void TestReturnInSixQuotesWithSemicolonAfter_Interpolated() testState.SendReturn(handled: true); testState.AssertCodeIs( -@"var v = $"""""" -$${|VirtualSpaces-4:|} - """""";"); + """" + var v = $""" + $${|VirtualSpaces-4:|} + """; + """"); } [WpfFact] public void TestReturnInSixQuotesNotAtMiddle_Interpolated() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = $""""""""$$"""""); + """"" + var v = $""""$$"" + """""); testState.SendReturn(handled: false); testState.AssertCodeIs( -@"var v = $""""""""$$"""""); + """"" + var v = $""""$$"" + """""); } [WpfFact] @@ -287,7 +331,9 @@ public void TestGenerateAtEndOfFile() testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""$$"""""""); + """" + var v = """$$""" + """"); } [WpfFact] @@ -309,7 +355,9 @@ public void TestGenerateWithInterpolatedString() testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = $""""""$$"""""""); + """" + var v = $"""$$""" + """"); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/66538")] @@ -390,55 +438,75 @@ public void TestNoGenerateWithVerbatimInterpolatedString2() public void TestDoNotGrowEmptyInsideSimpleString() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = ""$$"""); + """ + var v = "$$" + """); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"$$"""); + """ + var v = ""$$" + """); } [WpfFact] public void TestDoNotGrowEmptyInsideFourQuotes() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"$$"""""); + """ + var v = ""$$"" + """); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""$$"""""); + """" + var v = """$$"" + """"); } [WpfFact] public void TestDoGrowEmptyInsideSixQuotesInMiddle() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$"""""""); + """" + var v = """$$""" + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""""$$"""""""""); + """"" + var v = """"$$"""" + """""); } [WpfFact] public void TestDoGrowEmptyInsideSixQuotesInInterpolatedRaw() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = $""""""$$"""""""); + """" + var v = $"""$$""" + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = $""""""""$$"""""""""); + """"" + var v = $""""$$"""" + """""); } [WpfFact] public void TestDoNotGrowEmptyInsideSixQuotesWhenNotInMiddle1() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = $""""$$"""""""""); + """"" + var v = $""$$"""" + """""); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = $""""""$$"""""""""); + """"" + var v = $"""$$"""" + """""); } #endregion @@ -449,41 +517,53 @@ public void TestDoNotGrowEmptyInsideSixQuotesWhenNotInMiddle1() public void TestGrowDelimetersWhenEndExists_SingleLine() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$ """""""); + """" + var v = """$$ """ + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""""$$ """""""""); + """"" + var v = """"$$ """" + """""); } [WpfFact] public void TestGrowDelimetersWhenEndExists_MultiLine() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$ + """" + var v = """$$ - """""""); + """ + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""""$$ + """"" + var v = """"$$ - """""""""); + """" + """""); } [WpfFact] public void TestGrowDelimetersWhenEndExists_Interpolated() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = $""""""$$ + """" + var v = $"""$$ - """""""); + """ + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = $""""""""$$ + """"" + var v = $""""$$ - """""""""); + """" + """""); } [WpfFact] @@ -501,15 +581,19 @@ public void TestDoNotGrowDelimetersWhenEndNotThere() public void TestDoNotGrowDelimetersWhenEndTooShort() { using var testState = RawStringLiteralTestState.CreateTestState( -@"var v = """"""$$ + """" + var v = """$$ - """""); + "" + """"); testState.SendTypeChar('"'); testState.AssertCodeIs( -@"var v = """"""""$$ + """"" + var v = """"$$ - """""); + "" + """""); } #endregion @@ -522,7 +606,9 @@ public void TestTypeQuoteEmptyFile() testState.SendTypeChar('"'); testState.AssertCodeIs( -@"""$$"); + """ + "$$ + """); } } } diff --git a/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs b/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs index 2e66af57d3627..043d47eedf811 100644 --- a/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs +++ b/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs @@ -17,361 +17,381 @@ public partial class RefactoringHelpersTests : RefactoringHelpersTestBase(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestBeforeTokenDirectlyUnderNode() { - var testText = @" -class C -{ - void M() - { - {|result:C [||]LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:C [||]LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestAfterTokenDirectlyUnderNode() { - var testText = @" -class C -{ - void M() - { - {|result:C [||]LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:C [||]LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInTokenUnderDifferentNode() { - var testText = @" -class C -{ - void M() - { - C LocalFunction(C c) - { - [||]return null; - } - - } -}"; + var testText = """ + class C + { + void M() + { + C LocalFunction(C c) + { + [||]return null; + } + + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbRightEdge() { - var testText = @" -class C -{ - void M() - { - {|result:C LocalFunction(C c) - { - return null; - }[||]|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:C LocalFunction(C c) + { + return null; + }[||]|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdge() { - var testText = @" -class C -{ - void M() - { - {|result:[||]C LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:[||]C LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdgeComments() { - var testText = @" -class C -{ - void M() - { - /// - /// Comment1 - /// - {|result:[||]C LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + /// + /// Comment1 + /// + {|result:[||]C LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInAnotherChildNode() { - var testText = @" -class C -{ - void M() - { - C LocalFunction(C c) - { - [||]return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + C LocalFunction(C c) + { + [||]return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInTooFarBeforeInWhitespace() { - var testText = @" -class C -{ - void M() - { - [||] - - C LocalFunction(C c) - { - return null; - } - - } -}"; + var testText = """ + class C + { + void M() + { + [||] + + C LocalFunction(C c) + { + return null; + } + + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInWhiteSpaceOnLineWithDifferentStatement() { - var testText = @" -class C -{ - void M() - { - - var a = null; [||] - C LocalFunction(C c) - { - return null; - } - - } -}"; + var testText = """ + class C + { + void M() + { + + var a = null; [||] + C LocalFunction(C c) + { + return null; + } + + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestNotBeforePrecedingComment() { - var testText = @" -class C -{ - void M() - { - [||]//Test comment - C LocalFunction(C c) - { - return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + [||]//Test comment + C LocalFunction(C c) + { + return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestBeforeInWhitespace1_OnSameLine() { - var testText = @" -class C -{ - void M() - { -[||] {|result:C LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + [||] {|result:C LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestBeforeInWhitespace1_OnPreviousLine() { - var testText = @" -class C -{ - void M() - { - [||] - {|result:C LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + [||] + {|result:C LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestBeforeInWhitespace1_NotOnMultipleLinesPrior() { - var testText = @" -class C -{ - void M() - { - [||] - - C LocalFunction(C c) - { - return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + [||] + + C LocalFunction(C c) + { + return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestBeforeInWhitespace2() { - var testText = @" -class C -{ - void M() - { - var a = null; -[||] {|result:C LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + var a = null; + [||] {|result:C LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInNextTokensLeadingTrivia() { - var testText = @" -class C -{ - void M() - { - - C LocalFunction(C c) - { - return null; - } - [||] - } -}"; + var testText = """ + class C + { + void M() + { + + C LocalFunction(C c) + { + return null; + } + [||] + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestInEmptySyntaxNode_AllowEmptyNodesTrue1() { - var testText = @" -class C -{ - void M() - { - N(0, [||]{|result:|}); - } - - int N(int a, int b, int c) - { - } -}"; + var testText = """ + class C + { + void M() + { + N(0, [||]{|result:|}); + } + + int N(int a, int b, int c) + { + } + } + """; await TestAsync(testText, allowEmptyNodes: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestInEmptySyntaxNode_AllowEmptyNodesTrue2() { - var testText = @" -class C -{ - void M() - { - N(0, N(0, [||]{|result:|}, 0)); - } - - int N(int a, int b, int c) - { - } -}"; + var testText = """ + class C + { + void M() + { + N(0, N(0, [||]{|result:|}, 0)); + } + + int N(int a, int b, int c) + { + } + } + """; await TestAsync(testText, allowEmptyNodes: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestInEmptySyntaxNode_AllowEmptyNodesFalse1() { - var testText = @" -class C -{ - void M() - { - N(0, [||], 0)); - } - - int N(int a, int b, int c) - { - } -}"; + var testText = """ + class C + { + void M() + { + N(0, [||], 0)); + } + + int N(int a, int b, int c) + { + } + } + """; await TestMissingAsync(testText, allowEmptyNodes: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestInEmptySyntaxNode_AllowEmptyNodesFalse2() { - var testText = @" -class C -{ - void M() - { - N(0, {|result:N(0, [||], 0)|}); - } - - int N(int a, int b, int c) - { - } -}"; + var testText = """ + class C + { + void M() + { + N(0, {|result:N(0, [||], 0)|}); + } + + int N(int a, int b, int c) + { + } + } + """; await TestAsync(testText, allowEmptyNodes: false); } @@ -381,214 +401,226 @@ int N(int a, int b, int c) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestSelectedTokenDirectlyUnderNode() { - var testText = @" -class C -{ - void M() - { - {|result:C [|LocalFunction|](C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:C [|LocalFunction|](C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestPartiallySelectedTokenDirectlyUnderNode() { - var testText = @" -class C -{ - void M() - { - {|result:C Lo[|calFunct|]ion(C c) - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:C Lo[|calFunct|]ion(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestSelectedMultipleTokensUnderNode() { - var testText = @" -class C -{ - void M() - { - {|result:[|C LocalFunction(C c)|] - { - return null; - }|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:[|C LocalFunction(C c)|] + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedMultipleTokensWithLowerCommonAncestor() { - var testText = @" -class C -{ - void M() - { - C LocalFunction(C c) - [|{ - return null; - }|] - } -}"; + var testText = """ + class C + { + void M() + { + C LocalFunction(C c) + [|{ + return null; + }|] + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedLowerNode() { - var testText = @" -class C -{ - void M() - { - [|C|] LocalFunction(C c) - { - return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + [|C|] LocalFunction(C c) + { + return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedWhitespace() { - var testText = @" -class C -{ - void M() - { - C[| |]LocalFunction(C c) - { - return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + C[| |]LocalFunction(C c) + { + return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedWhitespace2() { - var testText = @" -class C -{ - void M() - { - [| |]C LocalFunction(C c) - { - return null; - } - } -}"; + var testText = """ + class C + { + void M() + { + [| |]C LocalFunction(C c) + { + return null; + } + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestCompleteSelection() { - var testText = @" -class C -{ - void M() - { - {|result:[|C LocalFunction(C c) - { - return null; - }|]|} - } -}"; + var testText = """ + class C + { + void M() + { + {|result:[|C LocalFunction(C c) + { + return null; + }|]|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestOverSelection() { - var testText = @" -class C -{ - void M() - { - [| - - {|result:C LocalFunction(C c) - { - return null; - }|} - - |]var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + [| + + {|result:C LocalFunction(C c) + { + return null; + }|} + + |]var a = new object(); + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestOverSelectionComments() { - var testText = @" -class C -{ - void M() - { - - // Co[|mment1 - {|result:C LocalFunction(C c) - { - return null; - }|}|] - } -}"; + var testText = """ + class C + { + void M() + { + + // Co[|mment1 + {|result:C LocalFunction(C c) + { + return null; + }|}|] + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingOverSelection() { - var testText = @" -class C -{ - void M() - { - [| - C LocalFunction(C c) - { - return null; - } - v|]ar a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + [| + C LocalFunction(C c) + { + return null; + } + v|]ar a = new object(); + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectionBefore() { - var testText = @" -class C -{ - void M() - { - - [| |]C LocalFunction(C c) - { - return null; - } - var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + + [| |]C LocalFunction(C c) + { + return null; + } + var a = new object(); + } + } + """; await TestMissingAsync(testText); } @@ -598,67 +630,72 @@ void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38708")] public async Task TestUnderselectionOnSemicolon() { - var testText = @" -class Program -{ - static void Main() - { - {|result:Main()|}[|;|] - } -}"; + var testText = """ + class Program + { + static void Main() + { + {|result:Main()|}[|;|] + } + } + """; await TestNotUnderselectedAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38708")] public async Task TestUnderselectionBug1() { - var testText = @" -class Program -{ - public static void Method() - { - //[|> - var str = {|result:"" <|] aaa""|}; - } -}"; + var testText = """ + class Program + { + public static void Method() + { + //[|> + var str = {|result:" <|] aaa"|}; + } + } + """; await TestNotUnderselectedAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38708")] public async Task TestUnderselectionBug2() { - var testText = @" -class C { - public void M() - { - Console.WriteLine(""Hello world"");[| - {|result:Console.WriteLine(new |]C())|}; - } - }"; + var testText = """ + class C { + public void M() + { + Console.WriteLine("Hello world");[| + {|result:Console.WriteLine(new |]C())|}; + } + } + """; await TestNotUnderselectedAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38708")] public async Task TestUnderselection() { - var testText = @" -class C { - public void M() - { - bool a = {|result:[|true || false || true|]|}; - }"; + var testText = """ + class C { + public void M() + { + bool a = {|result:[|true || false || true|]|}; + } + """; await TestNotUnderselectedAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38708")] public async Task TestUnderselection2() { - var testText = @" -class C { - public void M() - { - bool a = true || [|false || true|] || true; - }"; + var testText = """ + class C { + public void M() + { + bool a = true || [|false || true|] || true; + } + """; await TestUnderselectedAsync(testText); } #endregion @@ -667,267 +704,283 @@ public void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37584")] public async Task TestMissingEmptyMember() { - var testText = @" -using System; -public class Class1 -{ - [][||] -}"; + var testText = """ + using System; + public class Class1 + { + [][||] + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38502")] public async Task TestIncompleteAttribute() { - var testText = @" -using System; -public class Class1 -{ - {|result:void foo([[||]bar) {}|} -}"; + var testText = """ + using System; + public class Class1 + { + {|result:void foo([[||]bar) {}|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38502")] public async Task TestIncompleteAttribute2() { - var testText = @" -using System; -public class Class1 -{ - {|result:void foo([[||]Class1 arg1) {}|} -}"; + var testText = """ + using System; + public class Class1 + { + {|result:void foo([[||]Class1 arg1) {}|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37837")] public async Task TestEmptyParameter() { - var testText = @" -using System; -public class TestAttribute : Attribute { } -public class Class1 -{ - static void foo({|result:[Test][||] -|} { - - } -}"; + var testText = """ + using System; + public class TestAttribute : Attribute { } + public class Class1 + { + static void foo({|result:[Test][||] + |} { + + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37584")] public async Task TestMissingEmptyMember2() { - var testText = @" -using System; -public class Class1 -{ - [||]// Comment - [] -}"; + var testText = """ + using System; + public class Class1 + { + [||]// Comment + [] + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37584")] public async Task TestEmptyAttributeList() { - var testText = @" -using System; -public class Class1 -{ - {|result:[] - [||]void a() {}|} -}"; + var testText = """ + using System; + public class Class1 + { + {|result:[] + [||]void a() {}|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdgeBeforeAttribute() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - - // Comment1 - [||]{|result:[Test] - void M() - { - }|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + + // Comment1 + [||]{|result:[Test] + void M() + { + }|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdgeAfterAttribute() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - - {|result:[Test] - [||]void M() - { - }|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + + {|result:[Test] + [||]void M() + { + }|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdgeAfterAttributeComments() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - - // Comment1 - {|result:[Test] - // Comment2 - [||]void M() - { - }|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + + // Comment1 + {|result:[Test] + // Comment2 + [||]void M() + { + }|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestClimbLeftEdgeAfterAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - class Test2Attribute : Attribute { } - - // Comment1 - {|result:[Test] - [Test2] - // Comment2 - [||]void M() - { - }|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + class Test2Attribute : Attribute { } + + // Comment1 + {|result:[Test] + [Test2] + // Comment2 + [||]void M() + { + }|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingBetweenAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - class Test2Attribute : Attribute { } - - [Test] - [||][Test2] - void M() - { - } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + class Test2Attribute : Attribute { } + + [Test] + [||][Test2] + void M() + { + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingBetweenInAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - - [[||]Test] - void M() - { - } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + + [[||]Test] + void M() + { + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - class Test2Attribute : Attribute { } - - [|[Test] - [Test2]|] - void M() - { - } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + class Test2Attribute : Attribute { } + + [|[Test] + [Test2]|] + void M() + { + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingSelectedAttribute() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - - [|[Test]|] - void M() - { - } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + + [|[Test]|] + void M() + { + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestSelectedWholeNodeAndAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - class Test2Attribute : Attribute { } - - // Comment1 - [|{|result:[Test] - [Test2] - // Comment2 - void M() - { - }|}|] -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + class Test2Attribute : Attribute { } + + // Comment1 + [|{|result:[Test] + [Test2] + // Comment2 + void M() + { + }|}|] + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestSelectedWholeNodeWithoutAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - class Test2Attribute : Attribute { } - - // Comment1 - {|result:[Test] - [Test2] - // Comment2 - [|void M() - { - }|]|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + class Test2Attribute : Attribute { } + + // Comment1 + {|result:[Test] + [Test2] + // Comment2 + [|void M() + { + }|]|} + } + """; await TestAsync(testText); } #endregion @@ -936,28 +989,30 @@ class Test2Attribute : Attribute { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractionsClimbing() { - var testText = @" -using System; -class C -{ - void M() - { - var a = {|result:new object()|};[||] - } -}"; + var testText = """ + using System; + class C + { + void M() + { + var a = {|result:new object()|};[||] + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingExtractHeaderForSelection() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - [Test] public [|int|] a { get; set; } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + [Test] public [|int|] a { get; set; } + } + """; await TestMissingAsync(testText); } @@ -972,18 +1027,20 @@ public async Task TestMultipleExtractions() static string GetTestText(string data) { - return @" -class C -{ - void M() - { - C LocalFunction(C c) - { - " + data + @"return null; - } - var a = new object(); - } -}"; + return """ + class C + { + void M() + { + C LocalFunction(C c) + { + """ + data + """ + return null; + } + var a = new object(); + } + } + """; } } @@ -993,102 +1050,109 @@ C LocalFunction(C c) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractFromDeclaration() { - var testText = @" -using System; -class C -{ - void M() - { - [|var a = {|result:new object()|};|] - } -}"; + var testText = """ + using System; + class C + { + void M() + { + [|var a = {|result:new object()|};|] + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractFromDeclaration2() { - var testText = @" -using System; -class C -{ - void M() - { - var a = [|{|result:new object()|};|] - } -}"; + var testText = """ + using System; + class C + { + void M() + { + var a = [|{|result:new object()|};|] + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractFromAssignment() { - var testText = @" -using System; -class C -{ - void M() - { - object a; - a = [|{|result:new object()|};|] - } -}"; + var testText = """ + using System; + class C + { + void M() + { + object a; + a = [|{|result:new object()|};|] + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractFromDeclarator() { - var testText = @" -using System; -class C -{ - void M() - { - var [|a = {|result:new object()|}|]; - } -}"; + var testText = """ + using System; + class C + { + void M() + { + var [|a = {|result:new object()|}|]; + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractFromDeclarator2() { - var testText = @" -using System; -class C -{ - void M() - { - {|result:var [|a = new object()|];|} - } -}"; + var testText = """ + using System; + class C + { + void M() + { + {|result:var [|a = new object()|];|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestExtractInHeaderOfProperty() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - {|result:[Test] public i[||]nt a { get; set; }|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + {|result:[Test] public i[||]nt a { get; set; }|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingExtractNotInHeaderOfProperty() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - [Test] public int a { [||]get; set; } -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + [Test] public int a { [||]get; set; } + } + """; await TestMissingAsync(testText); } @@ -1102,18 +1166,20 @@ class TestAttribute : Attribute { } [WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingInHeaderHole(string data) { - var testText = @" -class C -{ - void M() - { - C LocalFunction(C c) - { - " + data + @"return null; - } - var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + C LocalFunction(C c) + { + """ + data + """ + return null; + } + var a = new object(); + } + } + """; await TestMissingAsync(testText); } @@ -1128,18 +1194,20 @@ C LocalFunction(C c) [WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestInHeader(string data) { - var testText = @" -class C -{ - void M() - { - C LocalFunction(C c) - { - " + data + @"return null; - } - var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + C LocalFunction(C c) + { + """ + data + """ + return null; + } + var a = new object(); + } + } + """; await TestAsync(testText); } #endregion @@ -1148,65 +1216,68 @@ C LocalFunction(C c) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestNextToHidden() { - var testText = @" -#line default -class C -{ - void M() - { -#line hidden - var a = b; -#line default - {|result:C [||]LocalFunction(C c) - { - return null; - }|} - } -}"; + var testText = """ + #line default + class C + { + void M() + { + #line hidden + var a = b; + #line default + {|result:C [||]LocalFunction(C c) + { + return null; + }|} + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestNextToHidden2() { - var testText = @" -#line default -class C -{ - void M() - { -#line hidden - var a = b; -#line default - {|result:C [||]LocalFunction(C c) - { - return null; - }|} -#line hidden - var a = b; -#line default - } -}"; + var testText = """ + #line default + class C + { + void M() + { + #line hidden + var a = b; + #line default + {|result:C [||]LocalFunction(C c) + { + return null; + }|} + #line hidden + var a = b; + #line default + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingHidden() { - var testText = @" -#line default -class C -{ - void M() - { -#line hidden - C LocalFunction(C c) -#line default - { - return null; - }[||] - } -}"; + var testText = """ + #line default + class C + { + void M() + { + #line hidden + C LocalFunction(C c) + #line default + { + return null; + }[||] + } + } + """; await TestMissingAsync(testText); } #endregion @@ -1215,50 +1286,53 @@ C LocalFunction(C c) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingPredicate() { - var testText = @" -class C -{ - void M() - { - N([||]2+3); - } - - void N(int a) - { - } -}"; + var testText = """ + class C + { + void M() + { + N([||]2+3); + } + + void N(int a) + { + } + } + """; await TestMissingAsync(testText, n => n.Parent is TupleExpressionSyntax); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgument() { - var testText = @" -class C -{ - void M() - { - N({|result:[||]2+3|}); - } - - void N(int a) - { - } -}"; + var testText = """ + class C + { + void M() + { + N({|result:[||]2+3|}); + } + + void N(int a) + { + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestPredicate() { - var testText = @" -class C -{ - void M() - { - var a = ({|result:[||]2 + 3|}, 2 + 3); - } -}"; + var testText = """ + class C + { + void M() + { + var a = ({|result:[||]2 + 3|}, 2 + 3); + } + } + """; await TestAsync(testText, n => n.Parent is TupleExpressionSyntax); } #endregion @@ -1267,169 +1341,182 @@ void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsInInitializer() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C({|result:[Test]int a = [||]42|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C({|result:[Test]int a = [||]42|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingArgumentsExtractionsSelectInitializer() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([Test]int a = [|42|], int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([Test]int a = [|42|], int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingArgumentsExtractionsSelectComma() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([Test]int a = 42[|,|] int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([Test]int a = 42[|,|] int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingArgumentsExtractionsInAttributes() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([[||]Test]int a = 42, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([[||]Test]int a = 42, int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingArgumentsExtractionsSelectType1() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([Test][|int|] a = 42, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([Test][|int|] a = 42, int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingArgumentsExtractionsSelectType2() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([Test][|C|] a = null, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([Test][|C|] a = null, int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsAtTheEnd() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C({|result:[Test]int a = 42[||]|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C({|result:[Test]int a = 42[||]|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsBefore() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([||]{|result:[Test]int a = 42|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([||]{|result:[Test]int a = 42|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsSelectParamName() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C({|result:[Test]int [|a|] = 42|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C({|result:[Test]int [|a|] = 42|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsSelectParam1() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C({|result:[Test][|int a|] = 42|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C({|result:[Test][|int a|] = 42|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsSelectParam2() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C([|{|result:[Test]int a = 42|}|], int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C([|{|result:[Test]int a = 42|}|], int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsSelectParam3() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public C({|result:[Test][|int a = 42|]|}, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public C({|result:[Test][|int a = 42|]|}, int b = 41) {} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestArgumentsExtractionsInHeader() { - var testText = @" -using System; -class CC -{ - class TestAttribute : Attribute { } - public CC({|result:[Test]C[||]C a = 42|}, int b = 41) {} -}"; + var testText = """ + using System; + class CC + { + class TestAttribute : Attribute { } + public CC({|result:[Test]C[||]C a = 42|}, int b = 41) {} + } + """; await TestAsync(testText); } @@ -1439,52 +1526,56 @@ public CC({|result:[Test]C[||]C a = 42|}, int b = 41) {} [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingMethodExplicitInterfaceSelection() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - public void [|I|].A([Test]int a = 42, int b = 41) {} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + public void [|I|].A([Test]int a = 42, int b = 41) {} + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMethodCaretBeforeInterfaceSelection() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - {|result:public void [||]I.A([Test]int a = 42, int b = 41) {}|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + {|result:public void [||]I.A([Test]int a = 42, int b = 41) {}|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMethodNameAndExplicitInterfaceSelection() { - var testText = @" -using System; -class C -{ - class TestAttribute : Attribute { } - {|result:public void [|I.A|]([Test]int a = 42, int b = 41) {}|} -}"; + var testText = """ + using System; + class C + { + class TestAttribute : Attribute { } + {|result:public void [|I.A|]([Test]int a = 42, int b = 41) {}|} + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMethodInHeader() { - var testText = @" -using System; -class CC -{ - class TestAttribute : Attribute { } - {|result:public C[||]C I.A([Test]int a = 42, int b = 41) { return null; }|} -}"; + var testText = """ + using System; + class CC + { + class TestAttribute : Attribute { } + {|result:public C[||]C I.A([Test]int a = 42, int b = 41) { return null; }|} + } + """; await TestAsync(testText); } @@ -1508,19 +1599,21 @@ class TestAttribute : Attribute { } [WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestLocalDeclarationInHeader(string data) { - var testText = @" -class C -{ - void M() - { - - C LocalFunction(C c) - { - " + data + @"return null; - } - var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + + C LocalFunction(C c) + { + """ + data + """ + return null; + } + var a = new object(); + } + } + """; await TestAsync(testText); } @@ -1531,19 +1624,21 @@ C LocalFunction(C c) [WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingLocalDeclarationCaretInHeader(string data) { - var testText = @" -class C -{ - void M() - { - - C LocalFunction(C c) - { - " + data + @"return null; - } - var a = new object(); - } -}"; + var testText = """ + class C + { + void M() + { + + C LocalFunction(C c) + { + """ + data + """ + return null; + } + var a = new object(); + } + } + """; await TestMissingAsync(testText); } #endregion @@ -1553,72 +1648,78 @@ C LocalFunction(C c) public async Task TestMultiline_IfElseIfElseSelection1() { await TestAsync( -@"class A -{ - void Goo() - { - {|result:[|if (a) - { - a(); - }|] - else if (b) - { - b(); - } - else - { - c(); - }|} - } -}"); + """ + class A + { + void Goo() + { + {|result:[|if (a) + { + a(); + }|] + else if (b) + { + b(); + } + else + { + c(); + }|} + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMultiline_IfElseIfElseSelection2() { await TestAsync( -@"class A -{ - void Goo() - { - {|result:[|if (a) - { - a(); - } - else if (b) - { - b(); - } - else - { - c(); - }|]|} - } -}"); + """ + class A + { + void Goo() + { + {|result:[|if (a) + { + a(); + } + else if (b) + { + b(); + } + else + { + c(); + }|]|} + } + } + """); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingMultiline_IfElseIfElseSelection() { await TestMissingAsync( -@"class A -{ - void Goo() - { - if (a) - { - a(); - } - [|else if (b) - { - b(); - } - else - { - c(); - }|] - } -}"); + """ + class A + { + void Goo() + { + if (a) + { + a(); + } + [|else if (b) + { + b(); + } + else + { + c(); + }|] + } + } + """); } #endregion @@ -1627,56 +1728,59 @@ void Goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestDeepIn() { - var testText = @" -class C -{ - void M() - { - N({|result:2+[||]3+4|}); - } - - void N(int a) - { - } -}"; + var testText = """ + class C + { + void M() + { + N({|result:2+[||]3+4|}); + } + + void N(int a) + { + } + } + """; await TestAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestMissingDeepInSecondRow() { - var testText = @" -class C -{ - void M() - { - N(2 - +[||]3+4); - } - - void N(int a) - { - } -}"; + var testText = """ + class C + { + void M() + { + N(2 + +[||]3+4); + } + + void N(int a) + { + } + } + """; await TestMissingAsync(testText); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/35525")] public async Task TestDeepInExpression() { - var testText = @" -class C -{ - void M() - { - var b = ({|result:N(2[||])|}, 0); - } - - int N(int a) - { - return a; - } -}"; + var testText = """ + class C + { + void M() + { + var b = ({|result:N(2[||])|}, 0); + } + + int N(int a) + { + return a; + } + } + """; await TestAsync(testText, predicate: n => n.Parent is TupleExpressionSyntax); } #endregion diff --git a/src/EditorFeatures/CSharpTest/Rename/CSharpRenamerTests.cs b/src/EditorFeatures/CSharpTest/Rename/CSharpRenamerTests.cs index be1848f028a41..6f3750c8babd5 100644 --- a/src/EditorFeatures/CSharpTest/Rename/CSharpRenamerTests.cs +++ b/src/EditorFeatures/CSharpTest/Rename/CSharpRenamerTests.cs @@ -73,28 +73,30 @@ public Task CSharp_RenameDocument_RenamePartialClass() { new DocumentWithInfo() { - Text = @" -namespace Test -{ - partial class C - { - } -}", + Text = """ + namespace Test + { + partial class C + { + } + } + """, DocumentFilePath = @"Test\Folder\Path\C.cs", DocumentName = "C.cs" }, new DocumentWithInfo() { - Text = @" -namespace Test -{ - partial class C - { - class Other - { - } - } -}", + Text = """ + namespace Test + { + partial class C + { + class Other + { + } + } + } + """, DocumentFilePath = @"Test\Folder\Path\C.Other.cs", DocumentName = "C.Other.cs" } @@ -104,28 +106,30 @@ class Other { new DocumentWithInfo() { - Text = @" -namespace Test -{ - partial class C2 - { - } -}", + Text = """ + namespace Test + { + partial class C2 + { + } + } + """, DocumentFilePath = @"Test\Folder\Path\C2.cs", DocumentName = "C2.cs" }, new DocumentWithInfo() { - Text = @" -namespace Test -{ - partial class C2 - { - class Other - { - } - } -}", + Text = """ + namespace Test + { + partial class C2 + { + class Other + { + } + } + } + """, DocumentFilePath = @"Test\Folder\Path\C.Other.cs", DocumentName = "C.Other.cs" } @@ -137,30 +141,36 @@ class Other [Fact] public Task CSharp_RenameDocument_NoRenameNamespace() => TestEmptyActionSet( -@"namespace Test.Path -{ - class C - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs"); [Fact] public Task CSharp_RenameDocument_RenameNamespace() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -}", -@"namespace Test.Path.After.Test -{ - class C - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + """, + """ + namespace Test.Path.After.Test + { + class C + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Path\After\Test\Document.cs"); @@ -168,32 +178,36 @@ class C [Fact] public Task CSharp_RenameDocument_RenameMultipleNamespaces() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -} - -namespace Test.Path -{ - class C2 - { - } -}", -@"namespace Test.Path.After.Test -{ - class C - { - } -} - -namespace Test.Path.After.Test -{ - class C2 - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + + namespace Test.Path + { + class C2 + { + } + } + """, + """ + namespace Test.Path.After.Test + { + class C + { + } + } + + namespace Test.Path.After.Test + { + class C2 + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Path\After\Test\Document.cs"); @@ -201,46 +215,50 @@ class C2 [Fact] public Task CSharp_RenameDocument_RenameMultipleNamespaces2() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -} - -namespace Test.Path -{ - class C2 - { - } -} - -namespace Other.Namespace -{ - class C3 - { - } -}", -@"namespace Test.Path.After.Test -{ - class C - { - } -} - -namespace Test.Path.After.Test -{ - class C2 - { - } -} - -namespace Other.Namespace -{ - class C3 - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + + namespace Test.Path + { + class C2 + { + } + } + + namespace Other.Namespace + { + class C3 + { + } + } + """, + """ + namespace Test.Path.After.Test + { + class C + { + } + } + + namespace Test.Path.After.Test + { + class C2 + { + } + } + + namespace Other.Namespace + { + class C3 + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Path\After\Test\Document.cs"); @@ -248,46 +266,50 @@ class C3 [Fact] public Task CSharp_RenameDocument_RenameMultipleNamespaces3() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -} - -namespace Other.Namespace -{ - class C2 - { - } -} - -namespace Test.Path -{ - class C3 - { - } -}", -@"namespace Test.Path.After.Test -{ - class C - { - } -} - -namespace Other.Namespace -{ - class C2 - { - } -} - -namespace Test.Path.After.Test -{ - class C3 - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + + namespace Other.Namespace + { + class C2 + { + } + } + + namespace Test.Path + { + class C3 + { + } + } + """, + """ + namespace Test.Path.After.Test + { + class C + { + } + } + + namespace Other.Namespace + { + class C2 + { + } + } + + namespace Test.Path.After.Test + { + class C3 + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Path\After\Test\Document.cs"); @@ -295,38 +317,42 @@ class C3 [Fact] public Task CSharp_RenameDocument_RenameMultipleNamespaces_Nested() => TestRenameDocument( -@"namespace Test.Path -{ - class C + """ + namespace Test.Path { + class C + { + } } -} -namespace Test -{ - namespace Path + namespace Test { - class C2 + namespace Path { + class C2 + { + } } } -}", -@"namespace Test.Path.After.Test -{ - class C + """, + """ + namespace Test.Path.After.Test { + class C + { + } } -} -namespace Test -{ - namespace Path + namespace Test { - class C2 + namespace Path { + class C2 + { + } } } -}", + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Path\After\Test\Document.cs"); @@ -334,18 +360,22 @@ class C2 [Fact] public Task CSharp_RenameDocument_RenameNamespace2() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -}", -@"namespace Test -{ - class C - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + """, + """ + namespace Test + { + class C + { + } + } + """, documentPath: @"Test\Path\Document.cs", documentName: @"Document.cs", newDocumentPath: @"Test\Document.cs"); @@ -353,18 +383,22 @@ class C [Fact] public Task CSharp_RenameDocument_RenameNamespaceAndClass() => TestRenameDocument( -@"namespace Test.Path -{ - class C - { - } -}", -@"namespace Test -{ - class C2 - { - } -}", + """ + namespace Test.Path + { + class C + { + } + } + """, + """ + namespace Test + { + class C2 + { + } + } + """, documentPath: @"Test\Path\C2.cs", documentName: @"C.cs", newDocumentName: @"C2", @@ -375,8 +409,10 @@ public Task CSharp_RenameDocument_MappedDocumentHasNoResults() { var documentName = "Component1.razor"; var documentText = -@"

Component1

-@code {}"; + """ +

Component1

+ @code {} + """; return TestRenameMappedFile(documentText, documentName, newDocumentName: "MyComponent.razor"); } diff --git a/src/EditorFeatures/CSharpTest/Semantics/SpeculationAnalyzerTests.cs b/src/EditorFeatures/CSharpTest/Semantics/SpeculationAnalyzerTests.cs index 2caf61f34a7f8..da86e338d915b 100644 --- a/src/EditorFeatures/CSharpTest/Semantics/SpeculationAnalyzerTests.cs +++ b/src/EditorFeatures/CSharpTest/Semantics/SpeculationAnalyzerTests.cs @@ -24,16 +24,17 @@ public class SpeculationAnalyzerTests : SpeculationAnalyzerTestsBase [Fact] public void SpeculationAnalyzerDifferentOverloads() { - Test(@" -class Program -{ - void Vain(int arg = 3) { } - void Vain(string arg) { } - void Main() - { - [|Vain(5)|]; - } -} ", "Vain(string.Empty)", true); + Test(""" + class Program + { + void Vain(int arg = 3) { } + void Vain(string arg) { } + void Main() + { + [|Vain(5)|]; + } + } + """, "Vain(string.Empty)", true); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/672396")] @@ -43,247 +44,263 @@ public void SpeculationAnalyzerExtensionMethodExplicitInvocation() // practice this is fine as the only thing that makes this change is complexification, and we don't test for // semantics changed after that as the purpose of complexification is to put us in a safe place to make // changes that won't break semantics. - Test(@" -static class Program -{ - public static void Vain(this int arg) { } - static void Main() - { - [|5.Vain()|]; - } -} ", "Vain(5)", semanticChanges: true); + Test(""" + static class Program + { + public static void Vain(this int arg) { } + static void Main() + { + [|5.Vain()|]; + } + } + """, "Vain(5)", semanticChanges: true); } [Fact] public void SpeculationAnalyzerImplicitBaseClassConversion() { - Test(@" -using System; -class Program -{ - void Main() - { - Exception ex = [|(Exception)new InvalidOperationException()|]; - } -} ", "new InvalidOperationException()", false); + Test(""" + using System; + class Program + { + void Main() + { + Exception ex = [|(Exception)new InvalidOperationException()|]; + } + } + """, "new InvalidOperationException()", false); } [Fact] public void SpeculationAnalyzerImplicitNumericConversion() { - Test(@" -class Program -{ - void Main() - { - long i = [|(long)5|]; - } -} ", "5", false); + Test(""" + class Program + { + void Main() + { + long i = [|(long)5|]; + } + } + """, "5", false); } [Fact] public void SpeculationAnalyzerImplicitUserConversion() { - Test(@" -class From -{ - public static implicit operator To(From from) { return new To(); } -} -class To { } -class Program -{ - void Main() - { - To to = [|(To)new From()|]; - } -} ", "new From()", true); + Test(""" + class From + { + public static implicit operator To(From from) { return new To(); } + } + class To { } + class Program + { + void Main() + { + To to = [|(To)new From()|]; + } + } + """, "new From()", true); } [Fact] public void SpeculationAnalyzerExplicitConversion() { - Test(@" -using System; -class Program -{ - void Main() - { - Exception ex1 = new InvalidOperationException(); - var ex2 = [|(InvalidOperationException)ex1|]; - } -} ", "ex1", true); + Test(""" + using System; + class Program + { + void Main() + { + Exception ex1 = new InvalidOperationException(); + var ex2 = [|(InvalidOperationException)ex1|]; + } + } + """, "ex1", true); } [Fact] public void SpeculationAnalyzerArrayImplementingNonGenericInterface() { - Test(@" -using System.Collections; -class Program -{ - void Main() - { - var a = new[] { 1, 2, 3 }; - [|((IEnumerable)a).GetEnumerator()|]; - } -} ", "a.GetEnumerator()", false); + Test(""" + using System.Collections; + class Program + { + void Main() + { + var a = new[] { 1, 2, 3 }; + [|((IEnumerable)a).GetEnumerator()|]; + } + } + """, "a.GetEnumerator()", false); } [Fact] public void SpeculationAnalyzerVirtualMethodWithBaseConversion() { - Test(@" -using System; -using System.IO; -class Program -{ - void Main() - { - var s = new MemoryStream(); - [|((Stream)s).Flush()|]; - } -} ", "s.Flush()", false); + Test(""" + using System; + using System.IO; + class Program + { + void Main() + { + var s = new MemoryStream(); + [|((Stream)s).Flush()|]; + } + } + """, "s.Flush()", false); } [Fact] public void SpeculationAnalyzerNonVirtualMethodImplementingInterface() { - Test(@" -using System; -class Class : IComparable -{ - public int CompareTo(object other) { return 1; } -} -class Program -{ - static void Main() - { - var c = new Class(); - var d = new Class(); - [|((IComparable)c).CompareTo(d)|]; - } -} ", "c.CompareTo(d)", true); + Test(""" + using System; + class Class : IComparable + { + public int CompareTo(object other) { return 1; } + } + class Program + { + static void Main() + { + var c = new Class(); + var d = new Class(); + [|((IComparable)c).CompareTo(d)|]; + } + } + """, "c.CompareTo(d)", true); } [Fact] public void SpeculationAnalyzerSealedClassImplementingInterface() { - Test(@" -using System; -sealed class Class : IComparable -{ - public int CompareTo(object other) { return 1; } -} -class Program -{ - static void Main() - { - var c = new Class(); - var d = new Class(); - [|((IComparable)c).CompareTo(d)|]; - } -} ", "((IComparable)c).CompareTo(d)", semanticChanges: false); + Test(""" + using System; + sealed class Class : IComparable + { + public int CompareTo(object other) { return 1; } + } + class Program + { + static void Main() + { + var c = new Class(); + var d = new Class(); + [|((IComparable)c).CompareTo(d)|]; + } + } + """, "((IComparable)c).CompareTo(d)", semanticChanges: false); } [Fact] public void SpeculationAnalyzerValueTypeImplementingInterface() { - Test(@" -using System; -class Program -{ - void Main() - { - decimal d = 5; - [|((IComparable)d).CompareTo(6)|]; - } -} ", "d.CompareTo(6)", false); + Test(""" + using System; + class Program + { + void Main() + { + decimal d = 5; + [|((IComparable)d).CompareTo(6)|]; + } + } + """, "d.CompareTo(6)", false); } [Fact] public void SpeculationAnalyzerBinaryExpressionIntVsLong() { - Test(@" -class Program -{ - void Main() - { - var r = [|1+1L|]; - } -} ", "1+1", true); + Test(""" + class Program + { + void Main() + { + var r = [|1+1L|]; + } + } + """, "1+1", true); } [Fact] public void SpeculationAnalyzerQueryExpressionSelectType() { - Test(@" -using System.Linq; -class Program -{ - static void Main(string[] args) - { - var items = [|from i in Enumerable.Range(0, 3) select (long)i|]; - } -} ", "from i in Enumerable.Range(0, 3) select i", true); + Test(""" + using System.Linq; + class Program + { + static void Main(string[] args) + { + var items = [|from i in Enumerable.Range(0, 3) select (long)i|]; + } + } + """, "from i in Enumerable.Range(0, 3) select i", true); } [Fact] public void SpeculationAnalyzerQueryExpressionFromType() { - Test(@" -using System.Linq; -class Program -{ - static void Main(string[] args) - { - var items = [|from i in new long[0] select i|]; - } -} ", "from i in new int[0] select i", true); + Test(""" + using System.Linq; + class Program + { + static void Main(string[] args) + { + var items = [|from i in new long[0] select i|]; + } + } + """, "from i in new int[0] select i", true); } [Fact] public void SpeculationAnalyzerQueryExpressionGroupByType() { - Test(@" -using System.Linq; -class Program -{ - static void Main(string[] args) - { - var items = [|from i in Enumerable.Range(0, 3) group (long)i by i|]; - } -} ", "from i in Enumerable.Range(0, 3) group i by i", true); + Test(""" + using System.Linq; + class Program + { + static void Main(string[] args) + { + var items = [|from i in Enumerable.Range(0, 3) group (long)i by i|]; + } + } + """, "from i in Enumerable.Range(0, 3) group i by i", true); } [Fact] public void SpeculationAnalyzerQueryExpressionOrderByType() { - Test(@" -using System.Linq; -class Program -{ - static void Main(string[] args) - { - var items = from i in Enumerable.Range(0, 3) orderby [|(long)i|] select i; - } -} ", "i", true); + Test(""" + using System.Linq; + class Program + { + static void Main(string[] args) + { + var items = from i in Enumerable.Range(0, 3) orderby [|(long)i|] select i; + } + } + """, "i", true); } [Fact] public void SpeculationAnalyzerDifferentAttributeConstructors() { - Test(@" -using System; -class AnAttribute : Attribute -{ - public AnAttribute(string a, long b) { } - public AnAttribute(int a, int b) { } -} -class Program -{ - [An([|""5""|], 6)] - static void Main() { } -} ", "5", false, "6"); + Test(""" + using System; + class AnAttribute : Attribute + { + public AnAttribute(string a, long b) { } + public AnAttribute(int a, int b) { } + } + class Program + { + [An([|"5"|], 6)] + static void Main() { } + } + """, "5", false, "6"); // Note: the answer should have been that the replacement does change semantics (true), // however to have enough context one must analyze AttributeSyntax instead of separate ExpressionSyntaxes it contains, @@ -293,209 +310,213 @@ static void Main() { } [Fact] public void SpeculationAnalyzerCollectionInitializers() { - Test(@" -using System.Collections; -class Collection : IEnumerable -{ - public IEnumerator GetEnumerator() { throw new System.NotImplementedException(); } - public void Add(string s) { } - public void Add(int i) { } - void Main() - { - var c = new Collection { [|""5""|] }; - } -} ", "5", true); + Test(""" + using System.Collections; + class Collection : IEnumerable + { + public IEnumerator GetEnumerator() { throw new System.NotImplementedException(); } + public void Add(string s) { } + public void Add(int i) { } + void Main() + { + var c = new Collection { [|"5"|] }; + } + } + """, "5", true); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1088815")] public void SpeculationAnalyzerBrokenCode() { - Test(@" -public interface IRogueAction -{ - public string Name { get; private set; } - - protected IRogueAction(string name) - { - [|this.Name|] = name; - } -} ", "Name", semanticChanges: false, isBrokenCode: true); + Test(""" + public interface IRogueAction + { + public string Name { get; private set; } + + protected IRogueAction(string name) + { + [|this.Name|] = name; + } + } + """, "Name", semanticChanges: false, isBrokenCode: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] public void SpeculationAnalyzerAnonymousObjectMemberDeclaredWithNeededCast() { - Test(@" -class Program -{ - static void Main(string[] args) - { - object thing = new { shouldBeAnInt = [|(int)Directions.South|] }; - } - public enum Directions { North, East, South, West } -} ", "Directions.South", semanticChanges: true); + Test(""" + class Program + { + static void Main(string[] args) + { + object thing = new { shouldBeAnInt = [|(int)Directions.South|] }; + } + public enum Directions { North, East, South, West } + } + """, "Directions.South", semanticChanges: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] public void SpeculationAnalyzerAnonymousObjectMemberDeclaredWithUnneededCast() { - Test(@" -class Program -{ - static void Main(string[] args) - { - object thing = new { shouldBeAnInt = [|(Directions)Directions.South|] }; - } - public enum Directions { North, East, South, West } -} ", "Directions.South", semanticChanges: false); + Test(""" + class Program + { + static void Main(string[] args) + { + object thing = new { shouldBeAnInt = [|(Directions)Directions.South|] }; + } + public enum Directions { North, East, South, West } + } + """, "Directions.South", semanticChanges: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19987")] public void SpeculationAnalyzerSwitchCaseWithRedundantCast() { - Test(@" -class Program -{ - static void Main(string[] arts) - { - var x = 1f; - switch (x) - { - case [|(float) 1|]: - System.Console.WriteLine(""one""); - break; - - default: - System.Console.WriteLine(""not one""); - break; - } - } -} - ", "1", semanticChanges: false); + Test(""" + class Program + { + static void Main(string[] arts) + { + var x = 1f; + switch (x) + { + case [|(float) 1|]: + System.Console.WriteLine("one"); + break; + + default: + System.Console.WriteLine("not one"); + break; + } + } + } + """, "1", semanticChanges: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19987")] public void SpeculationAnalyzerSwitchCaseWithRequiredCast() { - Test(@" -class Program -{ - static void Main(string[] arts) - { - object x = 1f; - switch (x) - { - case [|(float) 1|]: // without the case, object x does not match int 1 - System.Console.WriteLine(""one""); - break; - - default: - System.Console.WriteLine(""not one""); - break; - } - } -} - ", "1", semanticChanges: true); + Test(""" + class Program + { + static void Main(string[] arts) + { + object x = 1f; + switch (x) + { + case [|(float) 1|]: // without the case, object x does not match int 1 + System.Console.WriteLine("one"); + break; + + default: + System.Console.WriteLine("not one"); + break; + } + } + } + """, "1", semanticChanges: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] public void SpeculationAnalyzerIndexerPropertyWithRedundantCast() { - Test(code: @" -class Indexer -{ - public int this[int x] { get { return x; } } -} -class A -{ - public Indexer Foo { get; } = new Indexer(); -} -class B : A -{ -} -class Program -{ - static void Main(string[] args) - { - var b = new B(); - var y = ([|(A)b|]).Foo[1]; - } -} -", replacementExpression: "b", semanticChanges: false); + Test(code: """ + class Indexer + { + public int this[int x] { get { return x; } } + } + class A + { + public Indexer Foo { get; } = new Indexer(); + } + class B : A + { + } + class Program + { + static void Main(string[] args) + { + var b = new B(); + var y = ([|(A)b|]).Foo[1]; + } + } + """, replacementExpression: "b", semanticChanges: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] public void SpeculationAnalyzerIndexerPropertyWithRequiredCast() { - Test(code: @" -class Indexer -{ - public int this[int x] { get { return x; } } -} -class A -{ - public Indexer Foo { get; } = new Indexer(); -} -class B : A -{ - public new Indexer Foo { get; } = new Indexer(); -} -class Program -{ - static void Main(string[] args) - { - var b = new B(); - var y = ([|(A)b|]).Foo[1]; - } -} -", replacementExpression: "b", semanticChanges: true); + Test(code: """ + class Indexer + { + public int this[int x] { get { return x; } } + } + class A + { + public Indexer Foo { get; } = new Indexer(); + } + class B : A + { + public new Indexer Foo { get; } = new Indexer(); + } + class Program + { + static void Main(string[] args) + { + var b = new B(); + var y = ([|(A)b|]).Foo[1]; + } + } + """, replacementExpression: "b", semanticChanges: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] public void SpeculationAnalyzerDelegatePropertyWithRedundantCast() { - Test(code: @" -public delegate void MyDelegate(); -class A -{ - public MyDelegate Foo { get; } -} -class B : A -{ -} -class Program -{ - static void Main(string[] args) - { - var b = new B(); - ([|(A)b|]).Foo(); - } -} -", replacementExpression: "b", semanticChanges: false); + Test(code: """ + public delegate void MyDelegate(); + class A + { + public MyDelegate Foo { get; } + } + class B : A + { + } + class Program + { + static void Main(string[] args) + { + var b = new B(); + ([|(A)b|]).Foo(); + } + } + """, replacementExpression: "b", semanticChanges: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] public void SpeculationAnalyzerDelegatePropertyWithRequiredCast() { - Test(code: @" -public delegate void MyDelegate(); -class A -{ - public MyDelegate Foo { get; } -} -class B : A -{ - public new MyDelegate Foo { get; } -} -class Program -{ - static void Main(string[] args) - { - var b = new B(); - ([|(A)b|]).Foo(); - } -} -", replacementExpression: "b", semanticChanges: true); + Test(code: """ + public delegate void MyDelegate(); + class A + { + public MyDelegate Foo { get; } + } + class B : A + { + public new MyDelegate Foo { get; } + } + class Program + { + static void Main(string[] args) + { + var b = new B(); + ([|(A)b|]).Foo(); + } + } + """, replacementExpression: "b", semanticChanges: true); } protected override SyntaxTree Parse(string text) diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs index d00d76e57bde0..77912de108902 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs @@ -27,15 +27,16 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithoutParameters() { - var markup = @" -class SomethingAttribute : System.Attribute -{ -} + var markup = """ + class SomethingAttribute : System.Attribute + { + } -[[|Something($$|]] -class D -{ -}"; + [[|Something($$|]] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -46,17 +47,18 @@ class D [Fact] public async Task TestInvocationWithoutParametersMethodXmlComments() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// Summary For Attribute - public SomethingAttribute() { } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + /// Summary For Attribute + public SomethingAttribute() { } + } -[[|Something($$|]] -class D -{ -}"; + [[|Something($$|]] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", "Summary For Attribute", null, currentParameterIndex: 0)); @@ -67,16 +69,16 @@ class D [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickInt() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public SomethingAttribute(string i) => throw null; - public SomethingAttribute(int i) => throw null; - public SomethingAttribute(byte filtered) => throw null; -} -[[|Something(i: 1$$|])] -class D { } -"; + var markup = """ + class SomethingAttribute : System.Attribute + { + public SomethingAttribute(string i) => throw null; + public SomethingAttribute(int i) => throw null; + public SomethingAttribute(byte filtered) => throw null; + } + [[|Something(i: 1$$|])] + class D { } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("SomethingAttribute(int i)", currentParameterIndex: 0, isSelected: true), @@ -89,16 +91,16 @@ class D { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickString() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public SomethingAttribute(string i) => throw null; - public SomethingAttribute(int i) => throw null; - public SomethingAttribute(byte filtered) => throw null; -} -[[|Something(i: null$$|])] -class D { } -"; + var markup = """ + class SomethingAttribute : System.Attribute + { + public SomethingAttribute(string i) => throw null; + public SomethingAttribute(int i) => throw null; + public SomethingAttribute(byte filtered) => throw null; + } + [[|Something(i: null$$|])] + class D { } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("SomethingAttribute(int i)", currentParameterIndex: 0), @@ -111,16 +113,17 @@ class D { } [Fact] public async Task TestInvocationWithParametersOn1() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public SomethingAttribute(int someInteger, string someString) { } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public SomethingAttribute(int someInteger, string someString) { } + } -[[|Something($$|]] -class D -{ -}"; + [[|Something($$|]] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -131,21 +134,22 @@ class D [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// - /// Summary For Attribute - /// - /// Param someInteger - /// Param someString - public SomethingAttribute(int someInteger, string someString) { } -} - -[[|Something($$ -|]class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + /// + /// Summary For Attribute + /// + /// Param someInteger + /// Param someString + public SomethingAttribute(int someInteger, string someString) { } + } + + [[|Something($$ + |]class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someInteger", currentParameterIndex: 0)); @@ -156,16 +160,17 @@ public SomethingAttribute(int someInteger, string someString) { } [Fact] public async Task TestInvocationWithParametersOn2() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public SomethingAttribute(int someInteger, string someString) { } -} - -[[|Something(22, $$|]] -class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + public SomethingAttribute(int someInteger, string someString) { } + } + + [[|Something(22, $$|]] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -175,21 +180,22 @@ class D [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// - /// Summary For Attribute - /// - /// Param someInteger - /// Param someString - public SomethingAttribute(int someInteger, string someString) { } -} - -[[|Something(22, $$ -|]class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + /// + /// Summary For Attribute + /// + /// Param someInteger + /// Param someString + public SomethingAttribute(int someInteger, string someString) { } + } + + [[|Something(22, $$ + |]class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someString", currentParameterIndex: 1)); @@ -200,14 +206,15 @@ public SomethingAttribute(int someInteger, string someString) { } [Fact] public async Task TestInvocationWithClosingParen() { - var markup = @" -class SomethingAttribute : System.Attribute -{ } + var markup = """ + class SomethingAttribute : System.Attribute + { } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -219,47 +226,53 @@ class D public async Task TestInvocationSpan1() { await TestAsync( -@"using System; + """ + using System; -class C -{ - [[|Obsolete($$|])] - void Goo() - { - } -}"); + class C + { + [[|Obsolete($$|])] + void Goo() + { + } + } + """); } [Fact] public async Task TestInvocationSpan2() { await TestAsync( -@"using System; + """ + using System; -class C -{ - [[|Obsolete($$|])] - void Goo() - { - } -}"); + class C + { + [[|Obsolete($$|])] + void Goo() + { + } + } + """); } [Fact] public async Task TestInvocationSpan3() { await TestAsync( -@"using System; + """ + using System; -class C -{ - [[|Obsolete( + class C + { + [[|Obsolete( -$$|]] - void Goo() - { - } -}"); + $$|]] + void Goo() + { + } + } + """); } #endregion @@ -269,18 +282,19 @@ void Goo() [Fact] public async Task TestCurrentParameterName() { - var markup = @" -using System; + var markup = """ + using System; -class SomethingAttribute : Attribute -{ - public SomethingAttribute(int someParameter, bool somethingElse) { } -} + class SomethingAttribute : Attribute + { + public SomethingAttribute(int someParameter, bool somethingElse) { } + } -[[|Something(somethingElse: false, someParameter: $$22|])] -class C -{ -}"; + [[|Something(somethingElse: false, someParameter: $$22|])] + class C + { + } + """; await VerifyCurrentParameterNameAsync(markup, "someParameter"); } @@ -293,16 +307,17 @@ class C [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithValidField() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo; -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo; + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute({CSharpFeaturesResources.Properties}: [goo = int])", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -313,16 +328,17 @@ class D [Fact] public async Task TestAttributeWithInvalidFieldReadonly() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public readonly int goo; -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public readonly int goo; + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -333,16 +349,17 @@ class D [Fact] public async Task TestAttributeWithInvalidFieldStatic() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public static int goo; -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public static int goo; + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -353,16 +370,17 @@ class D [Fact] public async Task TestAttributeWithInvalidFieldConst() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public const int goo = 42; -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public const int goo = 42; + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -378,16 +396,17 @@ class D [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithValidProperty() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo { get; set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo { get; set; } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute({CSharpFeaturesResources.Properties}: [goo = int])", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -399,16 +418,17 @@ class D [Fact] public async Task TestAttributeWithInvalidPropertyStatic() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public static int goo { get; set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public static int goo { get; set; } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -419,16 +439,17 @@ class D [Fact] public async Task TestAttributeWithInvalidPropertyNoSetter() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo { get { return 0; } } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo { get { return 0; } } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -439,16 +460,17 @@ class D [Fact] public async Task TestAttributeWithInvalidPropertyNoGetter() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo { set { } } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo { set { } } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -459,16 +481,17 @@ class D [Fact] public async Task TestAttributeWithInvalidPropertyPrivateGetter() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo { private get; set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo { private get; set; } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -479,16 +502,17 @@ class D [Fact] public async Task TestAttributeWithInvalidPropertyPrivateSetter() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - public int goo { get; private set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + public int goo { get; private set; } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)); @@ -500,24 +524,25 @@ class D [WorkItem("https://github.com/dotnet/roslyn/issues/12544")] public async Task TestAttributeWithOverriddenProperty() { - var markup = @" -cusing System; + var markup = """ + cusing System; -class BaseAttribute : Attribute -{ - public virtual string Name { get; set; } -} + class BaseAttribute : Attribute + { + public virtual string Name { get; set; } + } -class DerivedAttribute : BaseAttribute -{ - public override string Name { get; set; } -} + class DerivedAttribute : BaseAttribute + { + public override string Name { get; set; } + } -[[|Derived($$|])] -class C -{ + [[|Derived($$|])] + class C + { -}"; + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"DerivedAttribute({CSharpFeaturesResources.Properties}: [Name = string])", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -533,20 +558,21 @@ class C [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithArgumentsAndNamedParameters1() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// GooParameter - /// BarParameter - public SomethingAttribute(int goo = 0, string bar = null) { } - public int fieldfoo { get; set; } - public string fieldbar { get; set; } -} - -[[|Something($$|])] -class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + /// GooParameter + /// BarParameter + public SomethingAttribute(int goo = 0, string bar = null) { } + public int fieldfoo { get; set; } + public string fieldbar { get; set; } + } + + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute([int goo = 0], [string bar = null], {CSharpFeaturesResources.Properties}: [fieldbar = string], [fieldfoo = int])", string.Empty, "GooParameter", currentParameterIndex: 0)); @@ -559,20 +585,21 @@ class D [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithArgumentsAndNamedParameters2() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// GooParameter - /// BarParameter - public SomethingAttribute(int goo = 0, string bar = null) { } - public int fieldfoo { get; set; } - public string fieldbar { get; set; } -} - -[[|Something(22, $$|])] -class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + /// GooParameter + /// BarParameter + public SomethingAttribute(int goo = 0, string bar = null) { } + public int fieldfoo { get; set; } + public string fieldbar { get; set; } + } + + [[|Something(22, $$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute([int goo = 0], [string bar = null], {CSharpFeaturesResources.Properties}: [fieldbar = string], [fieldfoo = int])", string.Empty, "BarParameter", currentParameterIndex: 1)); @@ -585,20 +612,21 @@ class D [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithArgumentsAndNamedParameters3() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// GooParameter - /// BarParameter - public SomethingAttribute(int goo = 0, string bar = null) { } - public int fieldfoo { get; set; } - public string fieldbar { get; set; } -} - -[[|Something(22, null, $$|])] -class D -{ -}"; + var markup = """ + class SomethingAttribute : System.Attribute + { + /// GooParameter + /// BarParameter + public SomethingAttribute(int goo = 0, string bar = null) { } + public int fieldfoo { get; set; } + public string fieldbar { get; set; } + } + + [[|Something(22, null, $$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute([int goo = 0], [string bar = null], {CSharpFeaturesResources.Properties}: [fieldbar = string], [fieldfoo = int])", string.Empty, string.Empty, currentParameterIndex: 2)); @@ -611,18 +639,19 @@ class D [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithOptionalArgumentAndNamedParameterWithSameName1() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// GooParameter - public SomethingAttribute(int goo = 0) { } - public int goo { get; set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + /// GooParameter + public SomethingAttribute(int goo = 0) { } + public int goo { get; set; } + } -[[|Something($$|])] -class D -{ -}"; + [[|Something($$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute([int goo = 0], {CSharpFeaturesResources.Properties}: [goo = int])", string.Empty, "GooParameter", currentParameterIndex: 0)); @@ -635,18 +664,19 @@ class D [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545425")] public async Task TestAttributeWithOptionalArgumentAndNamedParameterWithSameName2() { - var markup = @" -class SomethingAttribute : System.Attribute -{ - /// GooParameter - public SomethingAttribute(int goo = 0) { } - public int goo { get; set; } -} + var markup = """ + class SomethingAttribute : System.Attribute + { + /// GooParameter + public SomethingAttribute(int goo = 0) { } + public int goo { get; set; } + } -[[|Something(22, $$|])] -class D -{ -}"; + [[|Something(22, $$|])] + class D + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"SomethingAttribute([int goo = 0], {CSharpFeaturesResources.Properties}: [goo = int])", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -662,18 +692,19 @@ class D [Fact] public async Task TestInvocationOnTriggerParens() { - var markup = @" -using System; + var markup = """ + using System; -class SomethingAttribute : Attribute -{ - public SomethingAttribute(int someParameter, bool somethingElse) { } -} + class SomethingAttribute : Attribute + { + public SomethingAttribute(int someParameter, bool somethingElse) { } + } -[[|Something($$|])] -class C -{ -}"; + [[|Something($$|])] + class C + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someParameter, bool somethingElse)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -684,18 +715,19 @@ class C [Fact] public async Task TestInvocationOnTriggerComma() { - var markup = @" -using System; + var markup = """ + using System; -class SomethingAttribute : Attribute -{ - public SomethingAttribute(int someParameter, bool somethingElse) { } -} + class SomethingAttribute : Attribute + { + public SomethingAttribute(int someParameter, bool somethingElse) { } + } -[[|Something(22,$$|])] -class C -{ -}"; + [[|Something(22,$$|])] + class C + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("SomethingAttribute(int someParameter, bool somethingElse)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -706,18 +738,19 @@ class C [Fact] public async Task TestNoInvocationOnSpace() { - var markup = @" -using System; + var markup = """ + using System; -class SomethingAttribute : Attribute -{ - public SomethingAttribute(int someParameter, bool somethingElse) { } -} + class SomethingAttribute : Attribute + { + public SomethingAttribute(int someParameter, bool somethingElse) { } + } -[[|Something(22, $$|])] -class C -{ -}"; + [[|Something(22, $$|])] + class C + { + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems, usePreviousCharAsTrigger: true); @@ -738,21 +771,22 @@ public void TestTriggerCharacters() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Attribute_BrowsableAlways() { - var markup = @" -[MyAttribute($$ -class Program -{ -}"; - - var referencedCode = @" - -public class MyAttribute -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public MyAttribute(int x) - { - } -}"; + var markup = """ + [MyAttribute($$ + class Program + { + } + """; + + var referencedCode = """ + public class MyAttribute + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public MyAttribute(int x) + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("MyAttribute(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -768,21 +802,22 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Attribute_BrowsableNever() { - var markup = @" -[MyAttribute($$ -class Program -{ -}"; - - var referencedCode = @" - -public class MyAttribute -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public MyAttribute(int x) - { - } -}"; + var markup = """ + [MyAttribute($$ + class Program + { + } + """; + + var referencedCode = """ + public class MyAttribute + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyAttribute(int x) + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("MyAttribute(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -798,21 +833,22 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Attribute_BrowsableAdvanced() { - var markup = @" -[MyAttribute($$ -class Program -{ -}"; - - var referencedCode = @" - -public class MyAttribute -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - public MyAttribute(int x) - { - } -}"; + var markup = """ + [MyAttribute($$ + class Program + { + } + """; + + var referencedCode = """ + public class MyAttribute + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public MyAttribute(int x) + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("MyAttribute(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -837,26 +873,27 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Attribute_BrowsableMixed() { - var markup = @" -[MyAttribute($$ -class Program -{ -}"; - - var referencedCode = @" - -public class MyAttribute -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public MyAttribute(int x) - { - } - - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public MyAttribute(int x, int y) - { - } -}"; + var markup = """ + [MyAttribute($$ + class Program + { + } + """; + + var referencedCode = """ + public class MyAttribute + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public MyAttribute(int x) + { + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyAttribute(int x, int y) + { + } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("MyAttribute(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -878,28 +915,30 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact] public async Task FieldUnavailableInOneLinkedFile() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"Secret()\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj2", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } @@ -907,34 +946,36 @@ void Goo() [Fact] public async Task ExcludeFilesWithInactiveRegions() { - var markup = @" - - - - - - - - - - -"; + var markup = """ + + + + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"Secret()\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj3", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); @@ -943,8 +984,9 @@ void Goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1067933")] public async Task InvokedWithNoToken() { - var markup = @" -// [goo($$"; + var markup = """ + // [goo($$ + """; await TestAsync(markup); } @@ -952,15 +994,16 @@ public async Task InvokedWithNoToken() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1081535")] public async Task TestInvocationWithBadParameterList() { - var markup = @" -class SomethingAttribute : System.Attribute -{ -} + var markup = """ + class SomethingAttribute : System.Attribute + { + } -[Something{$$] -class D -{ -}"; + [Something{$$] + class D + { + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems); diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs index db352e79656eb..6271938dc965d 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs @@ -26,17 +26,18 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithoutParameters() { - var markup = @" -class BaseClass -{ - public BaseClass() { } -} - -class Derived : BaseClass -{ - public Derived() [|: base($$|]) - { } -}"; + var markup = """ + class BaseClass + { + public BaseClass() { } + } + + class Derived : BaseClass + { + public Derived() [|: base($$|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass()", string.Empty, null, currentParameterIndex: 0)); @@ -47,18 +48,19 @@ public Derived() [|: base($$|]) [Fact] public async Task TestInvocationWithoutParametersMethodXmlComments() { - var markup = @" -class BaseClass -{ - /// Summary for BaseClass - public BaseClass() { } -} + var markup = """ + class BaseClass + { + /// Summary for BaseClass + public BaseClass() { } + } -class Derived : BaseClass -{ - public Derived() [|: base($$|]) - { } -}"; + class Derived : BaseClass + { + public Derived() [|: base($$|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass()", "Summary for BaseClass", null, currentParameterIndex: 0)); @@ -69,17 +71,18 @@ public Derived() [|: base($$|]) [Fact] public async Task TestInvocationWithParametersOn1() { - var markup = @" -class BaseClass -{ - public BaseClass(int a, int b) { } -} + var markup = """ + class BaseClass + { + public BaseClass(int a, int b) { } + } -class Derived : BaseClass -{ - public Derived() [|: base($$2, 3|]) - { } -}"; + class Derived : BaseClass + { + public Derived() [|: base($$2, 3|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -90,20 +93,21 @@ public Derived() [|: base($$2, 3|]) [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var markup = @" -class BaseClass -{ - /// Summary for BaseClass - /// Param a - /// Param b - public BaseClass(int a, int b) { } -} - -class Derived : BaseClass -{ - public Derived() [|: base($$2, 3|]) - { } -}"; + var markup = """ + class BaseClass + { + /// Summary for BaseClass + /// Param a + /// Param b + public BaseClass(int a, int b) { } + } + + class Derived : BaseClass + { + public Derived() [|: base($$2, 3|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int a, int b)", "Summary for BaseClass", "Param a", currentParameterIndex: 0)); @@ -114,21 +118,22 @@ public Derived() [|: base($$2, 3|]) [Fact] public async Task TestInvocationWithParametersOn2() { - var markup = @" -class BaseClass -{ - /// Summary for BaseClass - /// Param a - /// Param b - public BaseClass(int a, int b) { } -} - - -class Derived : BaseClass -{ - public Derived() [|: base(2, $$3|]) - { } -}"; + var markup = """ + class BaseClass + { + /// Summary for BaseClass + /// Param a + /// Param b + public BaseClass(int a, int b) { } + } + + + class Derived : BaseClass + { + public Derived() [|: base(2, $$3|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1)); @@ -138,20 +143,21 @@ public Derived() [|: base(2, $$3|]) [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var markup = @" -class BaseClass -{ - /// Summary for BaseClass - /// Param a - /// Param b - public BaseClass(int a, int b) { } -} - -class Derived : BaseClass -{ - public Derived() [|: base(2, $$3|]) - { } -}"; + var markup = """ + class BaseClass + { + /// Summary for BaseClass + /// Param a + /// Param b + public BaseClass(int a, int b) { } + } + + class Derived : BaseClass + { + public Derived() [|: base(2, $$3|]) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1)); @@ -162,12 +168,13 @@ public Derived() [|: base(2, $$3|]) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocation() { - var markup = @" -class Goo -{ - public Goo(int a, int b) { } - public Goo() [|: this(2, $$3|]) { } -}"; + var markup = """ + class Goo + { + public Goo(int a, int b) { } + public Goo() [|: this(2, $$3|]) { } + } + """; var expectedOrderedItems = new List { @@ -180,12 +187,13 @@ public Goo() [|: this(2, $$3|]) { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocationWithNonEmptyArgumentList() { - var markup = @" -class Foo -{ - public Foo(int a, int b) [|: this($$|]) { } - public Foo() { } -}"; + var markup = """ + class Foo + { + public Foo(int a, int b) [|: this($$|]) { } + public Foo() { } + } + """; var expectedOrderedItems = new List { @@ -198,12 +206,13 @@ public Foo() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationWithoutClosingParen() { - var markup = @" -class Goo -{ - public Goo(int a, int b) { } - public Goo() [|: this(2, $$ -|]}"; + var markup = """ + class Goo + { + public Goo(int a, int b) { } + public Goo() [|: this(2, $$ + |]} + """; var expectedOrderedItems = new List { @@ -216,12 +225,13 @@ public Goo() [|: this(2, $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocationWithoutClosingParenWithNonEmptyArgumentList() { - var markup = @" -class Foo -{ - public Foo() { } - public Foo(int a, int b) [|: this($$ -|]}"; + var markup = """ + class Foo + { + public Foo() { } + public Foo(int a, int b) [|: this($$ + |]} + """; var expectedOrderedItems = new List { @@ -234,15 +244,16 @@ public Foo(int a, int b) [|: this($$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickInt() { - var markup = @" -class D -{ - D() [|: this(i: 1$$|]) { } + var markup = """ + class D + { + D() [|: this(i: 1$$|]) { } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0, isSelected: true), @@ -255,15 +266,16 @@ class D [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickString() { - var markup = @" -class D -{ - D() [|: this(i: null$$|]) { } + var markup = """ + class D + { + D() [|: this(i: null$$|]) { } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0), @@ -280,12 +292,13 @@ class D [Fact] public async Task TestCurrentParameterName() { - var markup = @" -class Goo -{ - public Goo(int a, int b) { } - public Goo() : this(b: 2, a: $$ -}"; + var markup = """ + class Goo + { + public Goo(int a, int b) { } + public Goo() : this(b: 2, a: $$ + } + """; await VerifyCurrentParameterNameAsync(markup, "a"); } @@ -297,12 +310,13 @@ public Goo() : this(b: 2, a: $$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationOnTriggerParens() { - var markup = @" -class Goo -{ - public Goo(int a) { } - public Goo() : this($$ -}"; + var markup = """ + class Goo + { + public Goo(int a) { } + public Goo() : this($$ + } + """; var expectedOrderedItems = new List { @@ -315,12 +329,13 @@ public Goo() : this($$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationOnTriggerParensWithNonEmptyArgumentList() { - var markup = @" -class Foo -{ - public Foo(int a) : this($$ - public Foo() { } -}"; + var markup = """ + class Foo + { + public Foo(int a) : this($$ + public Foo() { } + } + """; var expectedOrderedItems = new List { @@ -333,12 +348,13 @@ public Foo() { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationOnTriggerComma() { - var markup = @" -class Goo -{ - public Goo(int a, int b) { } - public Goo() : this(2,$$ -}"; + var markup = """ + class Goo + { + public Goo(int a, int b) { } + public Goo() : this(2,$$ + } + """; var expectedOrderedItems = new List { @@ -351,12 +367,13 @@ public Goo() : this(2,$$ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationOnTriggerCommaWithNonEmptyArgumentList() { - var markup = @" -class Foo -{ - public Foo(int a, int b) : this($$ - public Foo() { } -}"; + var markup = """ + class Foo + { + public Foo(int a, int b) : this($$ + public Foo() { } + } + """; var expectedOrderedItems = new List { @@ -369,12 +386,13 @@ public Foo() { } [Fact] public async Task TestNoInvocationOnSpace() { - var markup = @" -class Goo -{ - public Goo(int a, int b) { } - public Goo() : this(2, $$ -}"; + var markup = """ + class Goo + { + public Goo(int a, int b) { } + public Goo() : this(2, $$ + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems, usePreviousCharAsTrigger: true); @@ -395,19 +413,21 @@ public void TestTriggerCharacters() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_ConstructorInitializer_BrowsableStateAlways() { - var markup = @" -class DerivedClass : BaseClass -{ - public DerivedClass() : base($$ -}"; - - var referencedCode = @" -public class BaseClass -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public BaseClass(int x) - { } -}"; + var markup = """ + class DerivedClass : BaseClass + { + public DerivedClass() : base($$ + } + """; + + var referencedCode = """ + public class BaseClass + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public BaseClass(int x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -422,19 +442,21 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_ConstructorInitializer_BrowsableStateNever() { - var markup = @" -class DerivedClass : BaseClass -{ - public DerivedClass() : base($$ -}"; - - var referencedCode = @" -public class BaseClass -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public BaseClass(int x) - { } -}"; + var markup = """ + class DerivedClass : BaseClass + { + public DerivedClass() : base($$ + } + """; + + var referencedCode = """ + public class BaseClass + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public BaseClass(int x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -449,19 +471,21 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_ConstructorInitializer_BrowsableStateAdvanced() { - var markup = @" -class DerivedClass : BaseClass -{ - public DerivedClass() : base($$ -}"; - - var referencedCode = @" -public class BaseClass -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - public BaseClass(int x) - { } -}"; + var markup = """ + class DerivedClass : BaseClass + { + public DerivedClass() : base($$ + } + """; + + var referencedCode = """ + public class BaseClass + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public BaseClass(int x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("BaseClass(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -485,23 +509,25 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_ConstructorInitializer_BrowsableStateMixed() { - var markup = @" -class DerivedClass : BaseClass -{ - public DerivedClass() : base($$ -}"; - - var referencedCode = @" -public class BaseClass -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public BaseClass(int x) - { } - - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public BaseClass(int x, int y) - { } -}"; + var markup = """ + class DerivedClass : BaseClass + { + public DerivedClass() : base($$ + } + """; + + var referencedCode = """ + public class BaseClass + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public BaseClass(int x) + { } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public BaseClass(int x, int y) + { } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("BaseClass(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -522,31 +548,33 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact] public async Task FieldUnavailableInOneLinkedFile() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"Secret(int secret)\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj2", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } @@ -554,37 +582,39 @@ public SuperSecret(int secret) : base($$ [Fact] public async Task ExcludeFilesWithInactiveRegions() { - var markup = @" - - - - - - - - - - -"; + var markup = """ + + + + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"Secret(int secret)\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj3", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); @@ -593,8 +623,9 @@ public SuperSecret(int secret) : base($$ [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1067933")] public async Task InvokedWithNoToken() { - var markup = @" -// goo($$"; + var markup = """ + // goo($$ + """; await TestAsync(markup); } @@ -602,17 +633,18 @@ public async Task InvokedWithNoToken() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1082601")] public async Task TestInvocationWithBadParameterList() { - var markup = @" -class BaseClass -{ - public BaseClass() { } -} + var markup = """ + class BaseClass + { + public BaseClass() { } + } -class Derived : BaseClass -{ - public Derived() [|: base{$$|]) - { } -}"; + class Derived : BaseClass + { + public Derived() [|: base{$$|]) + { } + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems); @@ -621,13 +653,14 @@ public Derived() [|: base{$$|]) [Fact] public async Task TypingTupleDoesNotDismiss1() { - var markup = @" -class D { public D(object o) {} } -class C : D -{ - public C() [|: base(($$) - |]{} -}"; + var markup = """ + class D { public D(object o) {} } + class C : D + { + public C() [|: base(($$) + |]{} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("D(object o)", currentParameterIndex: 0)); @@ -638,12 +671,13 @@ public C() [|: base(($$) [Fact] public async Task TypingTupleDoesNotDismiss2() { - var markup = @" -class D { public D(object o) {} } -class C : D -{ - public C() [|: base((1,$$) |]{} -}"; + var markup = """ + class D { public D(object o) {} } + class C : D + { + public C() [|: base((1,$$) |]{} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("D(object o)", currentParameterIndex: 0)); @@ -654,13 +688,14 @@ public C() [|: base((1,$$) |]{} [Fact] public async Task TypingTupleDoesNotDismiss3() { - var markup = @" -class D { public D(object o) {} } -class C : D -{ - public C() [|: base((1, ($$) - |]{} -}"; + var markup = """ + class D { public D(object o) {} } + class C : D + { + public C() [|: base((1, ($$) + |]{} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("D(object o)", currentParameterIndex: 0)); @@ -671,12 +706,13 @@ public C() [|: base((1, ($$) [Fact] public async Task TypingTupleDoesNotDismiss4() { - var markup = @" -class D { public D(object o) {} } -class C : D -{ - public C() [|: base((1, (2,$$) |]{} -}"; + var markup = """ + class D { public D(object o) {} } + class C : D + { + public C() [|: base((1, (2,$$) |]{} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("D(object o)", currentParameterIndex: 0)); diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/ElementAccessExpressionSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/ElementAccessExpressionSignatureHelpProviderTests.cs index e3a713b7fd0b6..d1edf8d7b1281 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/ElementAccessExpressionSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/ElementAccessExpressionSignatureHelpProviderTests.cs @@ -26,24 +26,25 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithParametersOn1() { - var markup = @" -class C -{ - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[$$|]]; - } -}"; + var markup = """ + class C + { + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[$$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -54,18 +55,19 @@ void Goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24311")] public async Task TestInvocationWithParametersOn1_WithRefReturn() { - var markup = @" -class C -{ - public ref int this[int a] - { - get { throw null; } - } - void Goo(C c) - { - [|c[$$]|] - } -}"; + var markup = """ + class C + { + public ref int this[int a] + { + get { throw null; } + } + void Goo(C c) + { + [|c[$$]|] + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("ref int C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -76,18 +78,19 @@ void Goo(C c) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24311")] public async Task TestInvocationWithParametersOn1_WithRefReadonlyReturn() { - var markup = @" -class C -{ - public ref readonly int this[int a] - { - get { throw null; } - } - void Goo(C c) - { - [|c[$$]|] - } -}"; + var markup = """ + class C + { + public ref readonly int this[int a] + { + get { throw null; } + } + void Goo(C c) + { + [|c[$$]|] + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("ref readonly int C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -98,24 +101,25 @@ void Goo(C c) [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/636117")] public async Task TestInvocationOnExpression() { - var markup = @" -class C -{ - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - C[] c = new C[1]; - c[0][$$ - } -}"; + var markup = """ + class C + { + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + C[] c = new C[1]; + c[0][$$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -126,28 +130,29 @@ void Goo() [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var markup = @" -class C -{ - /// - /// Summary for this. - /// - /// Param a - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[$$|]]; - } -}"; + var markup = """ + class C + { + /// + /// Summary for this. + /// + /// Param a + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[$$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", "Summary for this.", "Param a", currentParameterIndex: 0)); @@ -158,24 +163,25 @@ void Goo() [Fact] public async Task TestInvocationWithParametersOn2() { - var markup = @" -class C -{ - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[22, $$|]]; - } -}"; + var markup = """ + class C + { + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[22, $$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a, bool b]", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -185,29 +191,30 @@ void Goo() [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var markup = @" -class C -{ - /// - /// Summary for this. - /// - /// Param a - /// Param b - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[22, $$|]]; - } -}"; + var markup = """ + class C + { + /// + /// Summary for this. + /// + /// Param a + /// Param b + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[22, $$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a, bool b]", "Summary for this.", "Param b", currentParameterIndex: 1)); @@ -219,23 +226,25 @@ void Goo() public async Task TestInvocationWithoutClosingBracketWithParameters() { var markup = -@"class C -{ - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[$$ - |]} -}"; + """ + class C + { + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[$$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -246,24 +255,25 @@ void Goo() [Fact] public async Task TestInvocationWithoutClosingBracketWithParametersOn2() { - var markup = @" -class C -{ - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[22, $$ - |]} -}"; + var markup = """ + class C + { + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[22, $$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a, bool b]", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -278,24 +288,25 @@ void Goo() [Fact] public async Task TestCurrentParameterName() { - var markup = @" -class C -{ - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[b: false, a: $$42|]]; - } -}"; + var markup = """ + class C + { + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[b: false, a: $$42|]]; + } + } + """; await VerifyCurrentParameterNameAsync(markup, "a"); } @@ -307,24 +318,25 @@ void Goo() [Fact] public async Task TestInvocationOnTriggerBracket() { - var markup = @" -class C -{ - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[$$|]]; - } -}"; + var markup = """ + class C + { + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[$$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -335,24 +347,25 @@ void Goo() [Fact] public async Task TestInvocationOnTriggerComma() { - var markup = @" -class C -{ - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[42,$$|]]; - } -}"; + var markup = """ + class C + { + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[42,$$|]]; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a, bool b]", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -363,24 +376,25 @@ void Goo() [Fact] public async Task TestNoInvocationOnSpace() { - var markup = @" -class C -{ - public string this[int a, bool b] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - var x = [|c[42, $$|]]; - } -}"; + var markup = """ + class C + { + public string this[int a, bool b] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + var x = [|c[42, $$|]]; + } + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems, usePreviousCharAsTrigger: true); @@ -402,25 +416,27 @@ public void TestTriggerCharacters() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_PropertyAlways() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] - public int this[int x] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] + public int this[int x] + { + get { return 5; } + set { } + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -435,25 +451,27 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_PropertyNever() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public int this[int x] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public int this[int x] + { + get { return 5; } + set { } + } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -468,25 +486,27 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_PropertyAdvanced() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - public int this[int x] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public int this[int x] + { + get { return 5; } + set { } + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -510,31 +530,33 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_PropertyNeverOnOneOfTwoOverloads() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public int this[int x] - { - get { return 5; } - set { } - } - - public int this[double d] - { - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public int this[int x] + { + get { return 5; } + set { } + } + + public int this[double d] + { + get { return 5; } + set { } + } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("int Goo[double d]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -556,25 +578,27 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_GetBrowsableNeverIgnored() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - public int this[int x] - { - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - get { return 5; } - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + public int this[int x] + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + get { return 5; } + set { } + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -589,25 +613,27 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_SetBrowsableNeverIgnored() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - public int this[int x] - { - get { return 5; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + public int this[int x] + { + get { return 5; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + set { } + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -622,26 +648,28 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Indexer_GetSetBrowsableNeverIgnored() { - var markup = @" -class Program -{ - void M() - { - new Goo()[$$ - } -}"; - - var referencedCode = @" -public class Goo -{ - public int this[int x] - { - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - get { return 5; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - set { } - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo()[$$ + } + } + """; + + var referencedCode = """ + public class Goo + { + public int this[int x] + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + get { return 5; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + set { } + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int Goo[int x]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -660,42 +688,46 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530811")] public async Task IndexedProperty() { - var markup = @"class Program -{ - void M() - { - CCC c = new CCC(); - c.IndexProp[$$ - } -}"; + var markup = """ + class Program + { + void M() + { + CCC c = new CCC(); + c.IndexProp[$$ + } + } + """; // Note that is required by compiler. Bug 17013 tracks enabling indexed property for non-COM types. - var referencedCode = @"Imports System.Runtime.InteropServices - - - -Public Class CCC - -#Region ""COM GUIDs"" - Public Const ClassId As String = ""9d965fd2-1514-44f6-accd-257ce77c46b0"" - Public Const InterfaceId As String = ""a9415060-fdf0-47e3-bc80-9c18f7f39cf6"" - Public Const EventsId As String = ""c6a866a5-5f97-4b53-a5df-3739dc8ff1bb"" -# End Region - - ''' - ''' An index property from VB - ''' - ''' p1 is an integer index - ''' A string - Public Property IndexProp(ByVal p1 As Integer) As String - Get - Return Nothing - End Get - Set(ByVal value As String) - - End Set - End Property -End Class"; + var referencedCode = """ + Imports System.Runtime.InteropServices + + + + Public Class CCC + + #Region "COM GUIDs" + Public Const ClassId As String = "9d965fd2-1514-44f6-accd-257ce77c46b0" + Public Const InterfaceId As String = "a9415060-fdf0-47e3-bc80-9c18f7f39cf6" + Public Const EventsId As String = "c6a866a5-5f97-4b53-a5df-3739dc8ff1bb" + # End Region + + ''' + ''' An index property from VB + ''' + ''' p1 is an integer index + ''' A string + Public Property IndexProp(ByVal p1 As Integer) As String + Get + Return Nothing + End Get + Set(ByVal value As String) + + End Set + End Property + End Class + """; var metadataItems = new List(); metadataItems.Add(new SignatureHelpTestItem("string CCC.IndexProp[int p1]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -716,32 +748,34 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact] public async Task FieldUnavailableInOneLinkedFile() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"int C[int z]\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj2", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } @@ -749,38 +783,40 @@ void goo() [Fact] public async Task ExcludeFilesWithInactiveRegions() { - var markup = @" - - - - - - - - - - -"; + var markup = """ + + + + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"int C[int z]\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj3", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); @@ -795,24 +831,25 @@ internal override Type GetSignatureHelpProviderType() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/636117")] public async Task TestInvocation() { - var markup = @" -class C -{ - public string this[int a] - { - get { return null; } - set { } - } -} - -class D -{ - void Goo() - { - var c = new C(); - c[$$] - } -}"; + var markup = """ + class C + { + public string this[int a] + { + get { return null; } + set { } + } + } + + class D + { + void Goo() + { + var c = new C(); + c[$$] + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("string C[int a]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -823,24 +860,24 @@ void Goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/939417")] public async Task ConditionalIndexer() { - var markup = @" -public class P -{ - public int this[int z] - { - get - { - return 0; - } - } - - public void goo() - { - P p = null; - p?[$$] - } -} -"; + var markup = """ + public class P + { + public int this[int z] + { + get + { + return 0; + } + } + + public void goo() + { + P p = null; + p?[$$] + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("int P[int z]", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -853,49 +890,60 @@ public async Task NonIdentifierConditionalIndexer() { var expected = new[] { new SignatureHelpTestItem("char string[int index]") }; await TestAsync( -@"class C -{ - void M() - { - """"?[$$ } -}", expected); // inline with a string literal + """ + class C + { + void M() + { + ""?[$$ } + } + """, expected); // inline with a string literal await TestAsync( -@"class C -{ - void M() - { - """"?[/**/$$ } -}", expected); // inline with a string literal and multiline comment + """ + class C + { + void M() + { + ""?[/**/$$ } + } + """, expected); // inline with a string literal and multiline comment await TestAsync( -@"class C -{ - void M() - { - ("""")?[$$ } -}", expected); // parenthesized expression + """ + class C + { + void M() + { + ("")?[$$ } + } + """, expected); // parenthesized expression await TestAsync( -@"class C -{ - void M() - { - new System.String(' ', 1)?[$$ } -}", expected); // new object expression + """ + class C + { + void M() + { + new System.String(' ', 1)?[$$ } + } + """, expected); // new object expression // more complicated parenthesized expression await TestAsync( -@"class C -{ - void M() - { - (null as System.Collections.Generic.List)?[$$ } -}", new[] { new SignatureHelpTestItem("int System.Collections.Generic.List[int index]") }); + """ + class C + { + void M() + { + (null as System.Collections.Generic.List)?[$$ } + } + """, new[] { new SignatureHelpTestItem("int System.Collections.Generic.List[int index]") }); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1067933")] public async Task InvokedWithNoToken() { - var markup = @" -// goo[$$"; + var markup = """ + // goo[$$ + """; await TestAsync(markup); } @@ -903,63 +951,63 @@ public async Task InvokedWithNoToken() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2482")] public async Task WhereExpressionLooksLikeArrayTypeSyntaxOfQualifiedName() { - var markup = @" -class WithIndexer -{ - public int this[int index] { get { return 0; } } -} - -class TestClass -{ - public WithIndexer Item { get; set; } - - public void Method(TestClass tc) - { - // `tc.Item[]` parses as ArrayTypeSyntax with an ElementType of QualifiedNameSyntax - tc.Item[$$] - } -} -"; + var markup = """ + class WithIndexer + { + public int this[int index] { get { return 0; } } + } + + class TestClass + { + public WithIndexer Item { get; set; } + + public void Method(TestClass tc) + { + // `tc.Item[]` parses as ArrayTypeSyntax with an ElementType of QualifiedNameSyntax + tc.Item[$$] + } + } + """; await TestAsync(markup, new[] { new SignatureHelpTestItem("int WithIndexer[int index]") }, usePreviousCharAsTrigger: true); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20507")] public async Task InConditionalIndexingFollowedByMemberAccess() { - var markup = @" -class Indexable -{ - public Indexable this[int x] { get => null; } - - Indexable Count; - - static void Main(string[] args) - { - Indexable x; - x?[$$].Count; - } -} -"; + var markup = """ + class Indexable + { + public Indexable this[int x] { get => null; } + + Indexable Count; + + static void Main(string[] args) + { + Indexable x; + x?[$$].Count; + } + } + """; await TestAsync(markup, new[] { new SignatureHelpTestItem("Indexable Indexable[int x]") }, usePreviousCharAsTrigger: false); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20507")] public async Task InConditionalIndexingFollowedByConditionalAccess() { - var markup = @" -class Indexable -{ - public Indexable this[int x] { get => null; } - - Indexable Count; - - static void Main(string[] args) - { - Indexable x; - x?[$$].Count?.Count; - } -} -"; + var markup = """ + class Indexable + { + public Indexable this[int x] { get => null; } + + Indexable Count; + + static void Main(string[] args) + { + Indexable x; + x?[$$].Count?.Count; + } + } + """; await TestAsync(markup, new[] { new SignatureHelpTestItem("Indexable Indexable[int x]") }, usePreviousCharAsTrigger: false); } } diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNamePartiallyWrittenSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNamePartiallyWrittenSignatureHelpProviderTests.cs index 06f39f4ebb17e..3db4101d8cd4a 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNamePartiallyWrittenSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNamePartiallyWrittenSignatureHelpProviderTests.cs @@ -25,16 +25,17 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task NestedGenericUnterminated() { - var markup = @" -class G { }; - -class C -{ - void Goo() - { - G$$ - } -}"; + var markup = """ + class G { }; + + class C + { + void Goo() + { + G$$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -45,18 +46,19 @@ void Goo() [Fact] public async Task NestedGenericUnterminatedWithAmbiguousShift() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - var x = G>$$> + class C + { + void Goo() + { + var x = G>$$> - x = x; - } -}"; + x = x; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -67,18 +69,19 @@ void Goo() [Fact] public async Task NestedGenericUnterminatedWithAmbiguousUnsignedShift() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - var x = G>>$$> + class C + { + void Goo() + { + var x = G>>$$> - x = x; - } -}"; + x = x; + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -89,16 +92,17 @@ void Goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544088")] public async Task DeclaringGenericTypeWith1ParameterUnterminated() { - var markup = @" -class G { }; - -class C -{ - void Goo() - { - [|G<$$ - |]} -}"; + var markup = """ + class G { }; + + class C + { + void Goo() + { + [|G<$$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -109,20 +113,20 @@ void Goo() [Fact] public async Task CallingGenericAsyncMethod() { - var markup = @" -using System.Threading.Tasks; -class Program -{ - void Main(string[] args) - { - Goo<$$ - } - Task Goo() - { - return Goo(); - } -} -"; + var markup = """ + using System.Threading.Tasks; + class Program + { + void Main(string[] args) + { + Goo<$$ + } + Task Goo() + { + return Goo(); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"({CSharpFeaturesResources.awaitable}) Task Program.Goo()", methodDocumentation: string.Empty, string.Empty, currentParameterIndex: 0)); @@ -134,23 +138,24 @@ Task Goo() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericMethod_BrowsableAlways() { - var markup = @" -class Program -{ - void M() - { - new C().Goo<$$ - } -} -"; - - var referencedCode = @" -public class C -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public void Goo(T x) - { } -}"; + var markup = """ + class Program + { + void M() + { + new C().Goo<$$ + } + } + """; + + var referencedCode = """ + public class C + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public void Goo(T x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(T x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -166,23 +171,24 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericMethod_BrowsableNever() { - var markup = @" -class Program -{ - void M() - { - new C().Goo<$$ - } -} -"; - - var referencedCode = @" -public class C -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public void Goo(T x) - { } -}"; + var markup = """ + class Program + { + void M() + { + new C().Goo<$$ + } + } + """; + + var referencedCode = """ + public class C + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public void Goo(T x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(T x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -198,23 +204,24 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericMethod_BrowsableAdvanced() { - var markup = @" -class Program -{ - void M() - { - new C().Goo<$$ - } -} -"; - - var referencedCode = @" -public class C -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] - public void Goo(T x) - { } -}"; + var markup = """ + class Program + { + void M() + { + new C().Goo<$$ + } + } + """; + + var referencedCode = """ + public class C + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public void Goo(T x) + { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(T x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -239,27 +246,28 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericMethod_BrowsableMixed() { - var markup = @" -class Program -{ - void M() - { - new C().Goo<$$ - } -} -"; - - var referencedCode = @" -public class C -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] - public void Goo(T x) - { } - - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public void Goo(T x, U y) - { } -}"; + var markup = """ + class Program + { + void M() + { + new C().Goo<$$ + } + } + """; + + var referencedCode = """ + public class C + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public void Goo(T x) + { } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public void Goo(T x, U y) + { } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("void C.Goo(T x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -278,25 +286,26 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact] public async Task GenericExtensionMethod() { - var markup = @" -interface IGoo -{ - void Bar(); -} - -static class GooExtensions -{ - public static void Bar(this IGoo goo) { } -} - -class Program -{ - static void Main() - { - IGoo f = null; - f.[|Bar<$$ - |]} -}"; + var markup = """ + interface IGoo + { + void Bar(); + } + + static class GooExtensions + { + public static void Bar(this IGoo goo) { } + } + + class Program + { + static void Main() + { + IGoo f = null; + f.[|Bar<$$ + |]} + } + """; var expectedOrderedItems = new List { @@ -311,20 +320,21 @@ static void Main() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544088")] public async Task InvokingGenericMethodWith1ParameterUnterminated() { - var markup = @" -class C -{ - /// - /// Method Goo - /// - /// Method type parameter - void Goo() { } - - void Bar() - { - [|Goo<$$ - |]} -}"; + var markup = """ + class C + { + /// + /// Method Goo + /// + /// Method type parameter + void Goo() { } + + void Bar() + { + [|Goo<$$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo()", @@ -336,16 +346,17 @@ void Bar() [Fact] public async Task TestInvocationOnTriggerBracket() { - var markup = @" -class G { }; - -class C -{ - void Goo() - { - [|G<$$ - |]} -}"; + var markup = """ + class G { }; + + class C + { + void Goo() + { + [|G<$$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -356,16 +367,17 @@ void Goo() [Fact] public async Task TestInvocationOnTriggerComma() { - var markup = @" -class G { }; - -class C -{ - void Goo() - { - [|G { }; + + class C + { + void Goo() + { + [|G(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -376,8 +388,9 @@ void Goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1067933")] public async Task InvokedWithNoToken() { - var markup = @" -// goo<$$"; + var markup = """ + // goo<$$ + """; await TestAsync(markup); } diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameSignatureHelpProviderTests.cs index 7162dce6df4bc..b51b0340e6299 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameSignatureHelpProviderTests.cs @@ -29,16 +29,17 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task NestedGenericTerminated() { - var markup = @" -class G { }; - -class C -{ - void Goo() - { - G$$> - } -}"; + var markup = """ + class G { }; + + class C + { + void Goo() + { + G$$> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -49,16 +50,17 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWith1ParameterTerminated() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -69,16 +71,17 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWith2ParametersOn1() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -89,16 +92,17 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWith2ParametersOn2() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - [|G - } -}"; + class C + { + void Goo() + { + [|G + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -109,21 +113,22 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWith2ParametersOn1XmlDoc() { - var markup = @" -/// -/// Summary for G -/// -/// TypeParamS. Also see -/// TypeParamT -class G { }; - -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + var markup = """ + /// + /// Summary for G + /// + /// TypeParamS. Also see + /// TypeParamT + class G { }; + + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", @@ -137,21 +142,22 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWith2ParametersOn2XmlDoc() { - var markup = @" -/// -/// Summary for G -/// -/// TypeParamS -/// TypeParamT. Also see -class G { }; - -class C -{ - void Goo() - { - [|G - } -}"; + var markup = """ + /// + /// Summary for G + /// + /// TypeParamS + /// TypeParamT. Also see + class G { }; + + class C + { + void Goo() + { + [|G + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G", "Summary for G", "TypeParamT. Also see S", currentParameterIndex: 1)); @@ -166,17 +172,18 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsStruct() { - var markup = @" -class G where S : struct -{ }; + var markup = """ + class G where S : struct + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : struct", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -187,17 +194,18 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsClass() { - var markup = @" -class G where S : class -{ }; + var markup = """ + class G where S : class + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : class", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -208,17 +216,18 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsNew() { - var markup = @" -class G where S : new() -{ }; + var markup = """ + class G where S : new() + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : new()", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -229,19 +238,20 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsBase() { - var markup = @" -class Base { } + var markup = """ + class Base { } -class G where S : Base -{ }; + class G where S : Base + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -252,19 +262,20 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericWithGeneric() { - var markup = @" -class Base { } + var markup = """ + class Base { } -class G where S : Base -{ }; + class G where S : Base + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -275,19 +286,20 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericWithNonGeneric() { - var markup = @" -class Base { } + var markup = """ + class Base { } -class G where S : Base -{ }; + class G where S : Base + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -298,19 +310,20 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericNested() { - var markup = @" -class Base { } + var markup = """ + class Base { } -class G where S : Base> -{ }; + class G where S : Base> + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : Base>", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -321,17 +334,18 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsDeriveFromAnotherGenericParameter() { - var markup = @" -class G where S : T -{ }; + var markup = """ + class G where S : T + { }; -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : T", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -342,28 +356,29 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsMixed1() { - var markup = @" -/// -/// Summary1 -/// -/// SummaryS -/// SummaryT -class G - where S : Base, new() - where T : class, S, IGoo, new() -{ }; - -internal interface IGoo { } - -internal class Base { } - -class C -{ - void Goo() - { - [|G<$$|]> - } -}"; + var markup = """ + /// + /// Summary1 + /// + /// SummaryS + /// SummaryT + class G + where S : Base, new() + where T : class, S, IGoo, new() + { }; + + internal interface IGoo { } + + internal class Base { } + + class C + { + void Goo() + { + [|G<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where S : Base, new()", "Summary1", "SummaryS", currentParameterIndex: 0)); @@ -374,28 +389,29 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsMixed2() { - var markup = @" -/// -/// Summary1 -/// -/// SummaryS -/// SummaryT -class G - where S : Base, new() - where T : class, S, IGoo, new() -{ }; - -internal interface IGoo { } - -internal class Base { } - -class C -{ - void Goo() - { - [|G - } -}"; + var markup = """ + /// + /// Summary1 + /// + /// SummaryS + /// SummaryT + class G + where S : Base, new() + where T : class, S, IGoo, new() + { }; + + internal interface IGoo { } + + internal class Base { } + + class C + { + void Goo() + { + [|G + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("G where T : class, S, IGoo, new()", "Summary1", "SummaryT", currentParameterIndex: 1)); @@ -410,16 +426,17 @@ void Goo() [Fact] public async Task InvokingGenericMethodWith1ParameterTerminated() { - var markup = @" -class C -{ - void Goo() { } + var markup = """ + class C + { + void Goo() { } - void Bar() - { - [|Goo<$$|]> - } -}"; + void Bar() + { + [|Goo<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo()", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -430,23 +447,24 @@ void Bar() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn1() { - var markup = @" -class C -{ - /// - /// Method summary - /// - /// type param S. see - /// type param T. - /// parameter s - /// parameter t - void Goo(S s, T t) { } - - void Bar() - { - [|Goo<$$|]> - } -}"; + var markup = """ + class C + { + /// + /// Method summary + /// + /// type param S. see + /// type param T. + /// parameter s + /// parameter t + void Goo(S s, T t) { } + + void Bar() + { + [|Goo<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(S s, T t)", @@ -458,16 +476,17 @@ void Bar() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn2() { - var markup = @" -class C -{ - void Goo(S s, T t) { } + var markup = """ + class C + { + void Goo(S s, T t) { } - void Bar() - { - [|Goo - } -}"; + void Bar() + { + [|Goo + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(S s, T t)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -478,21 +497,22 @@ void Bar() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn1XmlDoc() { - var markup = @" -class C -{ - /// - /// SummaryForGoo - /// - /// SummaryForS - /// SummaryForT - void Goo(S s, T t) { } - - void Bar() - { - [|Goo<$$|]> - } -}"; + var markup = """ + class C + { + /// + /// SummaryForGoo + /// + /// SummaryForS + /// SummaryForT + void Goo(S s, T t) { } + + void Bar() + { + [|Goo<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForS", currentParameterIndex: 0)); @@ -503,21 +523,22 @@ void Bar() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn2XmlDoc() { - var markup = @" -class C -{ - /// - /// SummaryForGoo - /// - /// SummaryForS - /// SummaryForT - void Goo(S s, T t) { } - - void Bar() - { - [|Goo - } -}"; + var markup = """ + class C + { + /// + /// SummaryForGoo + /// + /// SummaryForS + /// SummaryForT + void Goo(S s, T t) { } + + void Bar() + { + [|Goo + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForT", currentParameterIndex: 1)); @@ -528,23 +549,24 @@ void Bar() [Fact] public async Task CallingGenericExtensionMethod() { - var markup = @" -class G -{ }; - -class C -{ - void Bar() - { - G g = null; - g.[|Goo<$$|]> - } -} - -static class GooClass -{ - public static void Goo(this G g) { } -}"; + var markup = """ + class G + { }; + + class C + { + void Bar() + { + G g = null; + g.[|Goo<$$|]> + } + } + + static class GooClass + { + public static void Goo(this G g) { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"({CSharpFeaturesResources.extension}) void G.Goo()", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -560,27 +582,28 @@ public static void Goo(this G g) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWithConstraintsMixed1() { - var markup = @" -class Base { } -interface IGoo { } - -class C -{ - /// - /// GooSummary - /// - /// ParamS - /// ParamT - S Goo(S s, T t) - where S : Base, new() - where T : class, S, IGoo, new() - { return null; } - - void Bar() - { - [|Goo<$$|]> - } -}"; + var markup = """ + class Base { } + interface IGoo { } + + class C + { + /// + /// GooSummary + /// + /// ParamS + /// ParamT + S Goo(S s, T t) + where S : Base, new() + where T : class, S, IGoo, new() + { return null; } + + void Bar() + { + [|Goo<$$|]> + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("S C.Goo(S s, T t) where S : Base, new()", "GooSummary", "ParamS", currentParameterIndex: 0)); @@ -591,27 +614,28 @@ void Bar() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWithConstraintsMixed2() { - var markup = @" -class Base { } -interface IGoo { } - -class C -{ - /// - /// GooSummary - /// - /// ParamS - /// ParamT - S Goo(S s, T t) - where S : Base, new() - where T : class, S, IGoo, new() - { return null; } - - void Bar() - { - [|Goo - } -}"; + var markup = """ + class Base { } + interface IGoo { } + + class C + { + /// + /// GooSummary + /// + /// ParamS + /// ParamT + S Goo(S s, T t) + where S : Base, new() + where T : class, S, IGoo, new() + { return null; } + + void Bar() + { + [|Goo + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("S C.Goo(S s, T t) where T : class, S, IGoo, new()", "GooSummary", "ParamT", currentParameterIndex: 1)); @@ -622,23 +646,23 @@ void Bar() [Fact] public async Task TestUnmanagedConstraint() { - var markup = @" - -class C -{ - /// - /// summary headline - /// - /// T documentation - void M(T arg) where T : unmanaged - { - } - - void Bar() - { - [|M<$$|]> - } -}"; + var markup = """ + class C + { + /// + /// summary headline + /// + /// T documentation + void M(T arg) where T : unmanaged + { + } + + void Bar() + { + [|M<$$|]> + } + } + """; await TestAsync(markup, new List { @@ -662,28 +686,30 @@ public void TestTriggerCharacters() [Fact] public async Task FieldUnavailableInOneLinkedFile() { - var markup = @" - - - { - } -#endif - void goo() - { - var x = new D<$$ - } -} -]]> - - - - - -"; + var markup = """ + + + + { + } + #endif + void goo() + { + var x = new D<$$ + } + } + ]]> + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"D\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj2", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } @@ -691,34 +717,36 @@ void goo() [Fact] public async Task ExcludeFilesWithInactiveRegions() { - var markup = @" - - - { - } -#endif - -#if BAR - void goo() - { - var x = new D<$$ - } -#endif -} -]]> - - - - - - - - -"; + var markup = """ + + + + { + } + #endif + + #if BAR + void goo() + { + var x = new D<$$ + } + #endif + } + ]]> + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"D\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj3", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); @@ -731,20 +759,22 @@ void goo() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericType_BrowsableAlways() { - var markup = @" -class Program -{ - void M() - { - var c = new C<$$ - } -}"; - - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] -public class C -{ -}"; + var markup = """ + class Program + { + void M() + { + var c = new C<$$ + } + } + """; + + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] + public class C + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -760,20 +790,22 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericType_BrowsableNever() { - var markup = @" -class Program -{ - void M() - { - var c = new C<$$ - } -}"; - - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] -public class C -{ -}"; + var markup = """ + class Program + { + void M() + { + var c = new C<$$ + } + } + """; + + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public class C + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -789,20 +821,22 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_GenericType_BrowsableAdvanced() { - var markup = @" -class Program -{ - void M() - { - var c = new C<$$ - } -}"; - - var referencedCode = @" -[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] -public class C -{ -}"; + var markup = """ + class Program + { + void M() + { + var c = new C<$$ + } + } + """; + + var referencedCode = """ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + public class C + { + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -828,16 +862,17 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1083601")] public async Task DeclaringGenericTypeWithBadTypeArgumentList() { - var markup = @" -class G { }; + var markup = """ + class G { }; -class C -{ - void Goo() - { - G{$$> - } -}"; + class C + { + void Goo() + { + G{$$> + } + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems); @@ -846,29 +881,34 @@ void Goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50114")] public async Task DeclaringGenericTypeWithDocCommentList() { - var markup = @" -/// -/// List: -/// -/// -/// -/// Item 1. -/// -/// -/// -/// -class G { }; - -class C -{ - void Goo() - { - [|G - } -}"; + var markup = """ + /// + /// List: + /// + /// + /// + /// Item 1. + /// + /// + /// + /// + class G { }; + + class C + { + void Goo() + { + [|G + } + } + """; var expectedOrderedItems = new List(); - expectedOrderedItems.Add(new SignatureHelpTestItem("G", "List:\r\n\r\nItem 1.", + expectedOrderedItems.Add(new SignatureHelpTestItem("G", """ + List: + + Item 1. + """, classificationTypeNames: ImmutableArray.Create( ClassificationTypeNames.Text, ClassificationTypeNames.WhiteSpace, diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/InitializerExpressionSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/InitializerExpressionSignatureHelpProviderTests.cs index 52fe7f2e9b8cd..9537035cf899f 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/InitializerExpressionSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/InitializerExpressionSignatureHelpProviderTests.cs @@ -24,16 +24,17 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task WithSingleParamAddMethods() { - var markup = @" -using System.Collections.Generic; - -class C -{ - void Goo() - { - new List { { $$ - } -}"; + var markup = """ + using System.Collections.Generic; + + class C + { + void Goo() + { + new List { { $$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void List.Add(int item)", currentParameterIndex: 0)); @@ -44,16 +45,17 @@ void Goo() [Fact] public async Task ForMultiParamAddMethods() { - var markup = @" -using System.Collections.Generic; - -class C -{ - void Goo() - { - new Dictionary { { $$ - } -}"; + var markup = """ + using System.Collections.Generic; + + class C + { + void Goo() + { + new Dictionary { { $$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void Dictionary.Add(int key, string value)", currentParameterIndex: 0)); @@ -64,16 +66,17 @@ void Goo() [Fact] public async Task ForSecondParam() { - var markup = @" -using System.Collections.Generic; - -class C -{ - void Goo() - { - new Dictionary { { 0, $$ - } -}"; + var markup = """ + using System.Collections.Generic; + + class C + { + void Goo() + { + new Dictionary { { 0, $$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void Dictionary.Add(int key, string value)", currentParameterIndex: 1)); @@ -84,21 +87,22 @@ void Goo() [Fact] public async Task ForNestedCollectionInitializer() { - var markup = @" -using System.Collections.Generic; - -class Bar -{ - public Dictionary D; -} - -class C -{ - void Goo() - { - new Bar { D = { { $$ - } -}"; + var markup = """ + using System.Collections.Generic; + + class Bar + { + public Dictionary D; + } + + class C + { + void Goo() + { + new Bar { D = { { $$ + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void Dictionary.Add(int key, string value)", currentParameterIndex: 0)); @@ -109,20 +113,20 @@ void Goo() [Fact] public async Task WithoutClosingBraces() { - var markup = @" -using System.Collections.Generic; + var markup = """ + using System.Collections.Generic; -class Bar -{ - public Dictionary D; -} + class Bar + { + public Dictionary D; + } -class C -{ - void Goo() - { - new Bar { D = { { $$ -"; + class C + { + void Goo() + { + new Bar { D = { { $$ + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void Dictionary.Add(int key, string value)", currentParameterIndex: 0)); @@ -133,22 +137,22 @@ void Goo() [Fact] public async Task WithMultipleAddMethods() { - var markup = @" -using System.Collections; - -class Bar : IEnumerable -{ - public void Add(int i) { } - public void Add(int i, string s) { } - public void Add(int i, string s, bool b) { } -} - -class C -{ - void Goo() - { - new Bar { { $$ -"; + var markup = """ + using System.Collections; + + class Bar : IEnumerable + { + public void Add(int i) { } + public void Add(int i, string s) { } + public void Add(int i, string s, bool b) { } + } + + class C + { + void Goo() + { + new Bar { { $$ + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("void Bar.Add(int i)", currentParameterIndex: 0)); @@ -161,22 +165,22 @@ void Goo() [Fact] public async Task DoesNotImplementIEnumerable() { - var markup = @" -using System.Collections; - -class Bar -{ - public void Add(int i) { } - public void Add(int i, string s) { } - public void Add(int i, string s, bool b) { } -} - -class C -{ - void Goo() - { - new Bar { { $$ -"; + var markup = """ + using System.Collections; + + class Bar + { + public void Add(int i) { } + public void Add(int i, string s) { } + public void Add(int i, string s, bool b) { } + } + + class C + { + void Goo() + { + new Bar { { $$ + """; var expectedOrderedItems = new List(); @@ -186,26 +190,26 @@ void Goo() [Fact] public async Task WithExtensionAddMethods() { - var markup = @" -using System.Collections; - -class Bar : IEnumerable -{ -} - -static class Extensions -{ - public static void Add(this Bar b, int i) { } - public static void Add(this Bar b, int i, string s) { } - public static void Add(this Bar b, int i, string s, bool b) { } -} - -class C -{ - void Goo() - { - new Bar { { $$ -"; + var markup = """ + using System.Collections; + + class Bar : IEnumerable + { + } + + static class Extensions + { + public static void Add(this Bar b, int i) { } + public static void Add(this Bar b, int i, string s) { } + public static void Add(this Bar b, int i, string s, bool b) { } + } + + class C + { + void Goo() + { + new Bar { { $$ + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem($"({CSharpFeaturesResources.extension}) void Bar.Add(int i)", currentParameterIndex: 0)); diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/ObjectCreationExpressionSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/ObjectCreationExpressionSignatureHelpProviderTests.cs index f36c9afba060f..01c9db5945ba2 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/ObjectCreationExpressionSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/ObjectCreationExpressionSignatureHelpProviderTests.cs @@ -26,14 +26,15 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithoutParameters() { - var markup = @" -class C -{ - void goo() - { - var c = [|new C($$|]); - } -}"; + var markup = """ + class C + { + void goo() + { + var c = [|new C($$|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C()", string.Empty, null, currentParameterIndex: 0)); @@ -44,20 +45,21 @@ void goo() [Fact] public async Task TestImplicitInvocationWithoutParameters() { - var markup = @" - - - - -"; + var markup = """ + + + + + + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C()", string.Empty, null, currentParameterIndex: 0)); @@ -68,19 +70,20 @@ void M() [Fact] public async Task TestInvocationWithoutParametersMethodXmlComments() { - var markup = @" -class C -{ - /// - /// Summary for C - /// - C() { } - - void Goo() - { - C c = [|new C($$|]); - } -}"; + var markup = """ + class C + { + /// + /// Summary for C + /// + C() { } + + void Goo() + { + C c = [|new C($$|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C()", "Summary for C", null, currentParameterIndex: 0)); @@ -90,16 +93,17 @@ void Goo() [Fact] public async Task TestInvocationWithParametersOn1() { - var markup = @" -class C -{ - C(int a, int b) { } + var markup = """ + class C + { + C(int a, int b) { } - void Goo() - { - C c = [|new C($$2, 3|]); - } -}"; + void Goo() + { + C c = [|new C($$2, 3|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -110,16 +114,17 @@ void Goo() [Fact] public async Task TestImplicitInvocationWithParametersOn1() { - var markup = @" -class C -{ - C(int a, int b) { } + var markup = """ + class C + { + C(int a, int b) { } - void M() - { - C c = [|new($$2, 3|]); - } -}"; + void M() + { + C c = [|new($$2, 3|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -130,21 +135,22 @@ void M() [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var markup = @" -class C -{ - /// - /// Summary for C - /// - /// Param a - /// Param b - C(int a, int b) { } - - void Goo() - { - C c = [|new C($$2, 3|]); - } -}"; + var markup = """ + class C + { + /// + /// Summary for C + /// + /// Param a + /// Param b + C(int a, int b) { } + + void Goo() + { + C c = [|new C($$2, 3|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", "Summary for C", "Param a", currentParameterIndex: 0)); @@ -155,16 +161,17 @@ void Goo() [Fact] public async Task TestInvocationWithParametersOn2() { - var markup = @" -class C -{ - C(int a, int b) { } - - void Goo() - { - C c = [|new C(2, $$3|]); - } -}"; + var markup = """ + class C + { + C(int a, int b) { } + + void Goo() + { + C c = [|new C(2, $$3|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -174,21 +181,22 @@ void Goo() [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var markup = @" -class C -{ - /// - /// Summary for C - /// - /// Param a - /// Param b - C(int a, int b) { } - - void Goo() - { - C c = [|new C(2, $$3|]); - } -}"; + var markup = """ + class C + { + /// + /// Summary for C + /// + /// Param a + /// Param b + C(int a, int b) { } + + void Goo() + { + C c = [|new C(2, $$3|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", "Summary for C", "Param b", currentParameterIndex: 1)); @@ -198,17 +206,18 @@ void Goo() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickFirst() { - var markup = @" -class D -{ - void M() - { - [|new D(i: 1$$|]); - } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + var markup = """ + class D + { + void M() + { + [|new D(i: 1$$|]); + } + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0, isSelected: true), @@ -221,17 +230,18 @@ void M() [Fact] public async Task PickCorrectOverload_PickFirst_ImplicitObjectCreation() { - var markup = @" -class D -{ - void M() - { - D d = [|new(i: 1$$|]); - } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + var markup = """ + class D + { + void M() + { + D d = [|new(i: 1$$|]); + } + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0, isSelected: true), @@ -244,17 +254,18 @@ void M() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickSecond() { - var markup = @" -class D -{ - void M() - { - [|new D(i: null$$|]); - } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + var markup = """ + class D + { + void M() + { + [|new D(i: null$$|]); + } + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0), @@ -267,17 +278,18 @@ void M() [Fact] public async Task PickCorrectOverload_PickSecond_ImplicitObjectCreation() { - var markup = @" -class D -{ - void M() - { - D d = [|new(i: null$$|]); - } - D(D filtered) => throw null; - D(string i) => throw null; - D(int i) => throw null; -}"; + var markup = """ + class D + { + void M() + { + D d = [|new(i: null$$|]); + } + D(D filtered) => throw null; + D(string i) => throw null; + D(int i) => throw null; + } + """; var expectedOrderedItems = new List { new SignatureHelpTestItem("D(int i)", currentParameterIndex: 0), @@ -290,14 +302,15 @@ void M() [Fact] public async Task TestInvocationWithoutClosingParen() { - var markup = @" -class C -{ - void goo() - { - var c = [|new C($$ - |]} -}"; + var markup = """ + class C + { + void goo() + { + var c = [|new C($$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C()", string.Empty, null, currentParameterIndex: 0)); @@ -308,16 +321,17 @@ void goo() [Fact] public async Task TestInvocationWithoutClosingParenWithParameters() { - var markup = @" -class C -{ - C(int a, int b) { } + var markup = """ + class C + { + C(int a, int b) { } - void Goo() - { - C c = [|new C($$2, 3 - |]} -}"; + void Goo() + { + C c = [|new C($$2, 3 + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -328,16 +342,17 @@ void Goo() [Fact] public async Task TestInvocationWithoutClosingParenWithParametersOn2() { - var markup = @" -class C -{ - C(int a, int b) { } + var markup = """ + class C + { + C(int a, int b) { } - void Goo() - { - C c = [|new C(2, $$3 - |]} -}"; + void Goo() + { + C c = [|new C(2, $$3 + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -348,16 +363,17 @@ void Goo() [Fact] public async Task TestInvocationOnLambda() { - var markup = @" -using System; + var markup = """ + using System; -class C -{ - void goo() - { - var bar = [|new Action($$ - |]} -}"; + class C + { + void goo() + { + var bar = [|new Action($$ + |]} + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Action(void (int, int) target)", string.Empty, string.Empty, currentParameterIndex: 0, isSelected: true)); @@ -372,18 +388,19 @@ void goo() [Fact] public async Task TestCurrentParameterName() { - var markup = @" -class C -{ - C(int a, string b) - { - } + var markup = """ + class C + { + C(int a, string b) + { + } - void goo() - { - var c = [|new C(b: string.Empty, $$a: 2|]); - } -}"; + void goo() + { + var c = [|new C(b: string.Empty, $$a: 2|]); + } + } + """; await VerifyCurrentParameterNameAsync(markup, "a"); } @@ -395,14 +412,15 @@ void goo() [Fact] public async Task TestInvocationOnTriggerParens() { - var markup = @" -class C -{ - void goo() - { - var c = [|new C($$|]); - } -}"; + var markup = """ + class C + { + void goo() + { + var c = [|new C($$|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C()", string.Empty, null, currentParameterIndex: 0)); @@ -413,18 +431,19 @@ void goo() [Fact] public async Task TestInvocationOnTriggerComma() { - var markup = @" -class C -{ - C(int a, string b) - { - } + var markup = """ + class C + { + C(int a, string b) + { + } - void goo() - { - var c = [|new C(2,$$string.Empty|]); - } -}"; + void goo() + { + var c = [|new C(2,$$string.Empty|]); + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(int a, string b)", string.Empty, string.Empty, currentParameterIndex: 1)); @@ -435,18 +454,19 @@ void goo() [Fact] public async Task TestNoInvocationOnSpace() { - var markup = @" -class C -{ - C(int a, string b) - { - } + var markup = """ + class C + { + C(int a, string b) + { + } - void goo() - { - var c = [|new C(2, $$string.Empty|]); - } -}"; + void goo() + { + var c = [|new C(2, $$string.Empty|]); + } + } + """; var expectedOrderedItems = new List(); await TestAsync(markup, expectedOrderedItems, usePreviousCharAsTrigger: true); @@ -467,23 +487,25 @@ public void TestTriggerCharacters() [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Constructor_BrowsableAlways() { - var markup = @" -class Program -{ - void M() - { - new Goo($$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] - public Goo(int x) - { - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo($$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] + public Goo(int x) + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Goo(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -499,23 +521,25 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Constructor_BrowsableNever() { - var markup = @" -class Program -{ - void M() - { - new Goo($$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Goo(int x) - { - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo($$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public Goo(int x) + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Goo(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -531,23 +555,25 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Constructor_BrowsableAdvanced() { - var markup = @" -class Program -{ - void M() - { - new Goo($$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - public Goo() - { - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo($$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public Goo() + { + } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Goo()", string.Empty, null, currentParameterIndex: 0)); @@ -571,27 +597,29 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem(7336, "DevDiv_Projects/Roslyn")] public async Task EditorBrowsable_Constructor_BrowsableMixed() { - var markup = @" -class Program -{ - void M() - { - new Goo($$ - } -}"; - - var referencedCode = @" -public class Goo -{ - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] - public Goo(int x) - { - } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Goo(long y) - { - } -}"; + var markup = """ + class Program + { + void M() + { + new Goo($$ + } + } + """; + + var referencedCode = """ + public class Goo + { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)] + public Goo(int x) + { + } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public Goo(long y) + { + } + } + """; var expectedOrderedItemsMetadataReference = new List(); expectedOrderedItemsMetadataReference.Add(new SignatureHelpTestItem("Goo(int x)", string.Empty, string.Empty, currentParameterIndex: 0)); @@ -612,28 +640,30 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact] public async Task FieldUnavailableInOneLinkedFile() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"D()\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj2", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } @@ -641,34 +671,36 @@ void goo() [Fact] public async Task ExcludeFilesWithInactiveRegions() { - var markup = @" - - - - - - - - - - -"; + var markup = """ + + + + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"D()\r\n\r\n{string.Format(FeaturesResources._0_1, "Proj1", FeaturesResources.Available)}\r\n{string.Format(FeaturesResources._0_1, "Proj3", FeaturesResources.Not_Available)}\r\n\r\n{FeaturesResources.You_can_use_the_navigation_bar_to_switch_contexts}", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); @@ -677,8 +709,9 @@ void goo() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1067933")] public async Task InvokedWithNoToken() { - var markup = @" -// new goo($$"; + var markup = """ + // new goo($$ + """; await TestAsync(markup); } @@ -686,14 +719,15 @@ public async Task InvokedWithNoToken() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1078993")] public async Task TestSigHelpInIncorrectObjectCreationExpression() { - var markup = @" -class C -{ - void goo(C c) - { - goo([|new C{$$|] - } -}"; + var markup = """ + class C + { + void goo(C c) + { + goo([|new C{$$|] + } + } + """; await TestAsync(markup); } @@ -701,16 +735,17 @@ void goo(C c) [Fact] public async Task TypingTupleDoesNotDismiss1() { - var markup = @" -class C -{ - public C(object o) { } - public C M() - { - return [|new C(($$) - |]} + var markup = """ + class C + { + public C(object o) { } + public C M() + { + return [|new C(($$) + |]} -}"; + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(object o)", currentParameterIndex: 0)); @@ -721,16 +756,17 @@ public C M() [Fact] public async Task TypingTupleDoesNotDismiss2() { - var markup = @" -class C -{ - public C(object o) { } - public C M() - { - return [|new C((1,$$) - |]} + var markup = """ + class C + { + public C(object o) { } + public C M() + { + return [|new C((1,$$) + |]} -}"; + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(object o)", currentParameterIndex: 0)); @@ -741,16 +777,17 @@ public C M() [Fact] public async Task TypingTupleDoesNotDismiss3() { - var markup = @" -class C -{ - public C(object o) { } - public C M() - { - return [|new C((1, ($$) - |]} + var markup = """ + class C + { + public C(object o) { } + public C M() + { + return [|new C((1, ($$) + |]} -}"; + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(object o)", currentParameterIndex: 0)); @@ -761,16 +798,17 @@ public C M() [Fact] public async Task TypingTupleDoesNotDismiss4() { - var markup = @" -class C -{ - public C(object o) { } - public C M() - { - return [|new C((1, (2,$$) - |]} + var markup = """ + class C + { + public C(object o) { } + public C M() + { + return [|new C((1, (2,$$) + |]} -}"; + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("C(object o)", currentParameterIndex: 0)); @@ -795,16 +833,17 @@ public C M() [WorkItem("https://github.com/dotnet/roslyn/issues/6713")] public async Task PickCorrectOverload_Incomplete(string arguments, int expectedParameterIndex, int expecteSelectedIndex) { - var markup = @" -class Program -{ - static void M() - { - [|new Program(ARGUMENTS|]); - } - Program(int i, string s) { } - Program(string s, string s2) { } -}"; + var markup = """ + class Program + { + static void M() + { + [|new Program(ARGUMENTS|]); + } + Program(int i, string s) { } + Program(string s, string s2) { } + } + """; var index = 0; var expectedOrderedItems = new List @@ -824,16 +863,17 @@ static void M() [WorkItem("https://github.com/dotnet/roslyn/issues/6713")] public async Task PickCorrectOverload_Incomplete_WithNames(string arguments, int expectedParameterIndex) { - var markup = @" -class Program -{ - void M() - { - [|new Program(ARGUMENTS|]); - } - Program(int i, string s) { } - Program(string s, string s2) { } -}"; + var markup = """ + class Program + { + void M() + { + [|new Program(ARGUMENTS|]); + } + Program(int i, string s) { } + Program(string s, string s2) { } + } + """; var expectedOrderedItems = new List { diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProviderTests.cs index b2eba9003a31f..a3a55e73d1290 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProviderTests.cs @@ -23,13 +23,13 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task PrimaryConstructorBaseType_FirstParameter() { - var markup = @" -record Base(int Identifier) -{ - private Base(string ignored) : this(1, 2) { } -} -record Derived(int Other) : [|Base($$1|]); -"; + var markup = """ + record Base(int Identifier) + { + private Base(string ignored) : this(1, 2) { } + } + record Derived(int Other) : [|Base($$1|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(Base original)", string.Empty, null, currentParameterIndex: 0)); @@ -41,13 +41,13 @@ record Derived(int Other) : [|Base($$1|]); [Fact] public async Task PrimaryConstructorClassBaseType_FirstParameter() { - var markup = @" -class Base(int Identifier) -{ - private Base(string ignored) : this(1, 2) { } -} -class Derived(int Other) : [|Base($$1|]); -"; + var markup = """ + class Base(int Identifier) + { + private Base(string ignored) : this(1, 2) { } + } + class Derived(int Other) : [|Base($$1|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(int Identifier)", string.Empty, null, currentParameterIndex: 0, isSelected: true)); @@ -58,13 +58,13 @@ class Derived(int Other) : [|Base($$1|]); [Fact] public async Task PrimaryConstructorBaseType_SecondParameter() { - var markup = @" -record Base(int Identifier1, int Identifier2) -{ - protected Base(string name) : this(1, 2) { } -} -record Derived(int Other) : [|Base(1, $$2|]); -"; + var markup = """ + record Base(int Identifier1, int Identifier2) + { + protected Base(string name) : this(1, 2) { } + } + record Derived(int Other) : [|Base(1, $$2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(Base original)", string.Empty, null, currentParameterIndex: 1)); @@ -77,13 +77,13 @@ record Derived(int Other) : [|Base(1, $$2|]); [Fact] public async Task PrimaryConstructorClassBaseType_SecondParameter() { - var markup = @" -class Base(int Identifier1, int Identifier2) -{ - protected Base(string name) : this(1, 2) { } -} -class Derived(int Other) : [|Base(1, $$2|]); -"; + var markup = """ + class Base(int Identifier1, int Identifier2) + { + protected Base(string name) : this(1, 2) { } + } + class Derived(int Other) : [|Base(1, $$2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(string name)", string.Empty, null, currentParameterIndex: 1)); @@ -95,14 +95,14 @@ class Derived(int Other) : [|Base(1, $$2|]); [Fact] public async Task CommentOnBaseConstructor() { - var markup = @" -record Base(int Identifier1, int Identifier2) -{ - /// Summary for constructor - protected Base(string name) : this(1, 2) { } -} -record Derived(int Other) : [|Base(1, $$2|]); -"; + var markup = """ + record Base(int Identifier1, int Identifier2) + { + /// Summary for constructor + protected Base(string name) : this(1, 2) { } + } + record Derived(int Other) : [|Base(1, $$2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(Base original)", string.Empty, null, currentParameterIndex: 1)); @@ -115,14 +115,14 @@ record Derived(int Other) : [|Base(1, $$2|]); [Fact] public async Task CommentOnClassBaseConstructor() { - var markup = @" -class Base(int Identifier1, int Identifier2) -{ - /// Summary for constructor - protected Base(string name) : this(1, 2) { } -} -class Derived(int Other) : [|Base(1, $$2|]); -"; + var markup = """ + class Base(int Identifier1, int Identifier2) + { + /// Summary for constructor + protected Base(string name) : this(1, 2) { } + } + class Derived(int Other) : [|Base(1, $$2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(string name)", "Summary for constructor", null, currentParameterIndex: 1)); @@ -134,15 +134,15 @@ class Derived(int Other) : [|Base(1, $$2|]); [Fact] public async Task CommentOnBaseConstructorAndParameters() { - var markup = @" -record Base(int Identifier1, int Identifier2) -{ - /// Summary for constructor - /// Param name - protected Base(string name) : this(1, 2) { } -} -record Derived(int Other) : [|Base($$1, 2|]); -"; + var markup = """ + record Base(int Identifier1, int Identifier2) + { + /// Summary for constructor + /// Param name + protected Base(string name) : this(1, 2) { } + } + record Derived(int Other) : [|Base($$1, 2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(Base original)", string.Empty, null, currentParameterIndex: 0)); @@ -155,15 +155,15 @@ record Derived(int Other) : [|Base($$1, 2|]); [Fact] public async Task CommentOnClassBaseConstructorAndParameters() { - var markup = @" -class Base(int Identifier1, int Identifier2) -{ - /// Summary for constructor - /// Param name - protected Base(string name) : this(1, 2) { } -} -class Derived(int Other) : [|Base($$1, 2|]); -"; + var markup = """ + class Base(int Identifier1, int Identifier2) + { + /// Summary for constructor + /// Param name + protected Base(string name) : this(1, 2) { } + } + class Derived(int Other) : [|Base($$1, 2|]); + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("Base(string name)", "Summary for constructor", "Param name", currentParameterIndex: 0)); diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/TupleConstructionSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/TupleConstructionSignatureHelpProviderTests.cs index 6e3ba0cdd6c21..283aef8565874 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/TupleConstructionSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/TupleConstructionSignatureHelpProviderTests.cs @@ -24,11 +24,12 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task InvocationAfterOpenParen() { - var markup = @" -class C -{ - (int, int) y = [|($$ -|]}"; + var markup = """ + class C + { + (int, int) y = [|($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, int)", currentParameterIndex: 0, parameterDocumentation: "")); @@ -39,11 +40,12 @@ class C [Fact] public async Task InvocationWithNullableReferenceTypes() { - var markup = @" -class C -{ - (string?, string) y = [|($$ -|]}"; + var markup = """ + class C + { + (string?, string) y = [|($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(string?, string)", currentParameterIndex: 0)); @@ -54,14 +56,15 @@ class C [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/655607")] public async Task TestMissingTupleElement() { - var markup = @" -class C -{ - void M() - { - (a, ) = [|($$ -|] } -}"; + var markup = """ + class C + { + void M() + { + (a, ) = [|($$ + |] } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(object a, object)", currentParameterIndex: 0)); @@ -72,11 +75,12 @@ void M() [Fact] public async Task InvocationAfterOpenParen2() { - var markup = @" -class C -{ - (int, int) y = [|($$)|] -}"; + var markup = """ + class C + { + (int, int) y = [|($$)|] + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, int)", currentParameterIndex: 0)); @@ -87,11 +91,12 @@ class C [Fact] public async Task InvocationAfterComma1() { - var markup = @" -class C -{ - (int, int) y = [|(1,$$ -|]}"; + var markup = """ + class C + { + (int, int) y = [|(1,$$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, int)", currentParameterIndex: 1, parameterDocumentation: "")); @@ -102,11 +107,12 @@ class C [Fact] public async Task InvocationAfterComma2() { - var markup = @" -class C -{ - (int, int) y = [|(1,$$)|] -}"; + var markup = """ + class C + { + (int, int) y = [|(1,$$)|] + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, int)", currentParameterIndex: 1)); @@ -117,11 +123,12 @@ class C [Fact] public async Task ParameterIndexWithNameTyped() { - var markup = @" -class C -{ - (int a, int b) y = [|(b: $$ -|]}"; + var markup = """ + class C + { + (int a, int b) y = [|(b: $$ + |]} + """; var expectedOrderedItems = new List(); @@ -136,11 +143,12 @@ class C [Fact(Skip = "https://github.com/dotnet/roslyn/issues/14277")] public async Task NestedTuple() { - var markup = @" -class C -{ - (int a, (int b, int c)) y = [|(1, ($$ -|]}"; + var markup = """ + class C + { + (int a, (int b, int c)) y = [|(1, ($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int b, int c)", currentParameterIndex: 0)); @@ -151,11 +159,12 @@ class C [Fact] public async Task NestedTupleWhenNotInferred() { - var markup = @" -class C -{ - (int, object) y = [|(1, ($$ -|]}"; + var markup = """ + class C + { + (int, object) y = [|(1, ($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, object)", currentParameterIndex: 1)); @@ -166,11 +175,12 @@ class C [Fact] public async Task NestedTupleWhenNotInferred2() { - var markup = @" -class C -{ - (int, object) y = [|(1, (2,$$ -|]}"; + var markup = """ + class C + { + (int, object) y = [|(1, (2,$$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, object)", currentParameterIndex: 1)); @@ -181,11 +191,12 @@ class C [Fact] public async Task NestedTupleWhenNotInferred3() { - var markup = @" -class C -{ - (int, object) y = [|(1, ($$ -|]}"; + var markup = """ + class C + { + (int, object) y = [|(1, ($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, object)", currentParameterIndex: 1)); @@ -196,11 +207,12 @@ class C [Fact] public async Task NestedTupleWhenNotInferred4() { - var markup = @" -class C -{ - (object, object) y = [|(($$ -|]}"; + var markup = """ + class C + { + (object, object) y = [|(($$ + |]} + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(object, object)", currentParameterIndex: 0)); @@ -211,17 +223,18 @@ class C [Fact] public async Task MultipleOverloads() { - var markup = @" -class Program -{ - static void Main(string[] args) - { - Do1([|($$)|]) - } - - static void Do1((int, int) i) { } - static void Do1((string, string) s) { } -}"; + var markup = """ + class Program + { + static void Main(string[] args) + { + Do1([|($$)|]) + } + + static void Do1((int, int) i) { } + static void Do1((string, string) s) { } + } + """; var expectedOrderedItems = new List(); expectedOrderedItems.Add(new SignatureHelpTestItem("(int, int)", currentParameterIndex: 0)); @@ -233,28 +246,30 @@ static void Do1((string, string) s) { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14793")] public async Task DoNotCrashInLinkedFile() { - var markup = @" - - - - - - - -"; + var markup = """ + + + + + + + + + + """; var expectedDescription = new SignatureHelpTestItem($"(int, string)", currentParameterIndex: 0); await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false); } diff --git a/src/EditorFeatures/CSharpTest/SpellCheck/SpellCheckSpanTests.cs b/src/EditorFeatures/CSharpTest/SpellCheck/SpellCheckSpanTests.cs index c86874d66878b..fc303283ff6b3 100644 --- a/src/EditorFeatures/CSharpTest/SpellCheck/SpellCheckSpanTests.cs +++ b/src/EditorFeatures/CSharpTest/SpellCheck/SpellCheckSpanTests.cs @@ -25,8 +25,9 @@ public async Task TestSingleLineComment1() [Fact] public async Task TestSingleLineComment2() { - await TestAsync(@" -{|Comment:// Goo|}"); + await TestAsync(""" + {|Comment:// Goo|} + """); } [Fact] @@ -38,64 +39,71 @@ public async Task TestMultiLineComment1() [Fact] public async Task TestMultiLineComment2() { - await TestAsync(@" -{|Comment:/* - Goo - */|}"); + await TestAsync(""" + {|Comment:/* + Goo + */|} + """); } [Fact] public async Task TestMultiLineComment3() { - await TestAsync(@" -{|Comment:/* - Goo - |}"); + await TestAsync(""" + {|Comment:/* + Goo + |} + """); } [Fact] public async Task TestMultiLineComment4() { - await TestAsync(@" -{|Comment:/**/|}"); + await TestAsync(""" + {|Comment:/**/|} + """); } [Fact] public async Task TestMultiLineComment5() { - await TestAsync(@" -{|Comment:/*/|}"); + await TestAsync(""" + {|Comment:/*/|} + """); } [Fact] public async Task TestDocComment1() { - await TestAsync(@" -///{|Comment:goo bar baz|} -class {|Identifier:C|} -{ -}"); + await TestAsync(""" + ///{|Comment:goo bar baz|} + class {|Identifier:C|} + { + } + """); } [Fact] public async Task TestDocComment2() { - await TestAsync(@" -///{|Comment:goo bar baz|} -///{|Comment:goo bar baz|} -class {|Identifier:C|} -{ -}"); + await TestAsync(""" + ///{|Comment:goo bar baz|} + ///{|Comment:goo bar baz|} + class {|Identifier:C|} + { + } + """); } [Fact] public async Task TestDocComment3() { - await TestAsync(@" -///{|Comment: |}{|Comment: goo bar baz |} -class {|Identifier:C|} -{ -}"); + await TestAsync(""" + ///{|Comment: |}{|Comment: goo bar baz |} + class {|Identifier:C|} + { + } + """); } [Fact] @@ -107,35 +115,41 @@ public async Task TestString1() [Fact] public async Task TestString2() { - await TestAsync(@""" goo "); + await TestAsync(""" + " goo + """); } [Fact] public async Task TestString3() { - await TestAsync(@" -{|String:"" goo ""|}"); + await TestAsync(""" + {|String:" goo "|} + """); } [Fact] public async Task TestString4() { - await TestAsync(@" -"" goo "); + await TestAsync(""" + " goo + """); } [Fact] public async Task TestString5() { - await TestAsync(@" -{|String:@"" goo ""|}"); + await TestAsync(""" + {|String:@" goo "|} + """); } [Fact] public async Task TestString6() { - await TestAsync(@" -@"" goo "); + await TestAsync(""" + @" goo + """); } [Fact] @@ -147,79 +161,96 @@ public async Task TestString7() [Fact] public async Task TestString8() { - await TestAsync(@""""""" goo """""); + await TestAsync("""" + """ goo "" + """"); } [Fact] public async Task TestString9() { - await TestAsync(@""""""" goo """); + await TestAsync("""" + """ goo " + """"); } [Fact] public async Task TestString10() { - await TestAsync(@""""""" goo "); + await TestAsync("""" + """ goo + """"); } [Fact] public async Task TestString11() { - await TestAsync(@"{|String:"""""" - goo - """"""|}"); + await TestAsync("""" + {|String:""" + goo + """|} + """"); } [Fact] public async Task TestString12() { - await TestAsync(@""""""" - goo - """""); + await TestAsync("""" + """ + goo + "" + """"); } [Fact] public async Task TestString13() { - await TestAsync(@""""""" - goo - """); + await TestAsync("""" + """ + goo + " + """"); } [Fact] public async Task TestString14() { - await TestAsync(@""""""" - goo - "); + await TestAsync("""" + """ + goo + """"); } [Fact] public async Task TestString15() { - await TestAsync(@" -$""{|String: goo |}"""); + await TestAsync(""" + $"{|String: goo |}" + """); } [Fact] public async Task TestString16() { - await TestAsync(@" -$""{|String: goo |}{0}{|String: bar |}"""); + await TestAsync(""" + $"{|String: goo |}{0}{|String: bar |}" + """); } [Fact] public async Task TestString17() { - await TestAsync(@" -$""""""{|String: goo |}{0}{|String: bar |}"""""""); + await TestAsync("""" + $"""{|String: goo |}{0}{|String: bar |}""" + """"); } [Fact] public async Task TestString18() { - await TestAsync(@" -$""""""{|String: goo |}{0:abcd}{|String: bar |}"""""""); + await TestAsync("""" + $"""{|String: goo |}{0:abcd}{|String: bar |}""" + """"); } [Fact] @@ -285,332 +316,366 @@ public async Task TestEscapedString10() [Fact] public async Task TestIdentifier1() { - await TestAsync(@" -class {|Identifier:C|} -{ -}"); + await TestAsync(""" + class {|Identifier:C|} + { + } + """); } [Fact] public async Task TestIdentifier2() { - await TestAsync(@" -record {|Identifier:C|} -{ -}"); + await TestAsync(""" + record {|Identifier:C|} + { + } + """); } [Fact] public async Task TestIdentifier3() { - await TestAsync(@" -record class {|Identifier:C|} -{ -}"); + await TestAsync(""" + record class {|Identifier:C|} + { + } + """); } [Fact] public async Task TestIdentifier4() { - await TestAsync(@" -delegate void {|Identifier:C|}();"); + await TestAsync(""" + delegate void {|Identifier:C|}(); + """); } [Fact] public async Task TestIdentifier5() { - await TestAsync(@" -enum {|Identifier:C|} { }"); + await TestAsync(""" + enum {|Identifier:C|} { } + """); } [Fact] public async Task TestIdentifier6() { - await TestAsync(@" -enum {|Identifier:C|} -{ - {|Identifier:D|} -}"); + await TestAsync(""" + enum {|Identifier:C|} + { + {|Identifier:D|} + } + """); } [Fact] public async Task TestIdentifier7() { - await TestAsync(@" -enum {|Identifier:C|} -{ - {|Identifier:D|}, {|Identifier:E|} -}"); + await TestAsync(""" + enum {|Identifier:C|} + { + {|Identifier:D|}, {|Identifier:E|} + } + """); } [Fact] public async Task TestIdentifier8() { - await TestAsync(@" -interface {|Identifier:C|} { }"); + await TestAsync(""" + interface {|Identifier:C|} { } + """); } [Fact] public async Task TestIdentifier9() { - await TestAsync(@" -struct {|Identifier:C|} { }"); + await TestAsync(""" + struct {|Identifier:C|} { } + """); } [Fact] public async Task TestIdentifier10() { - await TestAsync(@" -record struct {|Identifier:C|}() { }"); + await TestAsync(""" + record struct {|Identifier:C|}() { } + """); } [Fact] public async Task TestIdentifier11() { - await TestAsync(@" -class {|Identifier:C|}<{|Identifier:T|}> { }"); + await TestAsync(""" + class {|Identifier:C|}<{|Identifier:T|}> { } + """); } [Fact] public async Task TestIdentifier12() { - await TestAsync(@" -class {|Identifier:C|} -{ - private int {|Identifier:X|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private int {|Identifier:X|}; + } + """); } [Fact] public async Task TestIdentifier13() { - await TestAsync(@" -class {|Identifier:C|} -{ - private int {|Identifier:X|}, {|Identifier:Y|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private int {|Identifier:X|}, {|Identifier:Y|}; + } + """); } [Fact] public async Task TestIdentifier14() { - await TestAsync(@" -class {|Identifier:C|} -{ - private const int {|Identifier:X|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private const int {|Identifier:X|}; + } + """); } [Fact] public async Task TestIdentifier15() { - await TestAsync(@" -class {|Identifier:C|} -{ - private const int {|Identifier:X|}, {|Identifier:Y|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private const int {|Identifier:X|}, {|Identifier:Y|}; + } + """); } [Fact] public async Task TestIdentifier16() { - await TestAsync(@" -class {|Identifier:C|} -{ - private int {|Identifier:X|} => 0; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private int {|Identifier:X|} => 0; + } + """); } [Fact] public async Task TestIdentifier17() { - await TestAsync(@" -class {|Identifier:C|} -{ - private event Action {|Identifier:X|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private event Action {|Identifier:X|}; + } + """); } [Fact] public async Task TestIdentifier18() { - await TestAsync(@" -class {|Identifier:C|} -{ - private event Action {|Identifier:X|}, {|Identifier:Y|}; -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private event Action {|Identifier:X|}, {|Identifier:Y|}; + } + """); } [Fact] public async Task TestIdentifier19() { - await TestAsync(@" -class {|Identifier:C|} -{ - private event Action {|Identifier:X|} { add { } remove { } } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + private event Action {|Identifier:X|} { add { } remove { } } + } + """); } [Fact] public async Task TestIdentifier20() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}() - { - int {|Identifier:E|}; - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}() + { + int {|Identifier:E|}; + } + } + """); } [Fact] public async Task TestIdentifier21() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}() - { - int {|Identifier:E|}, {|Identifier:F|}; - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}() + { + int {|Identifier:E|}, {|Identifier:F|}; + } + } + """); } [Fact] public async Task TestIdentifier22() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}() - { -{|Identifier:E|}: - return; - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}() + { + {|Identifier:E|}: + return; + } + } + """); } [Fact] public async Task TestIdentifier23() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}(int {|Identifier:E|}) - { - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}(int {|Identifier:E|}) + { + } + } + """); } [Fact] public async Task TestIdentifier24() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}(int {|Identifier:E|}) - { - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}(int {|Identifier:E|}) + { + } + } + """); } [Fact] public async Task TestIdentifier25() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}(int {|Identifier:E|}, int {|Identifier:F|}) - { - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}(int {|Identifier:E|}, int {|Identifier:F|}) + { + } + } + """); } [Fact] public async Task TestIdentifier26() { - await TestAsync(@" -static class {|Identifier:C|} -{ - static void {|Identifier:D|}(this int {|Identifier:E|}) - { - } -}"); + await TestAsync(""" + static class {|Identifier:C|} + { + static void {|Identifier:D|}(this int {|Identifier:E|}) + { + } + } + """); } [Fact] public async Task TestIdentifier27() { - await TestAsync(@" -namespace {|Identifier:C|} -{ -}"); + await TestAsync(""" + namespace {|Identifier:C|} + { + } + """); } [Fact] public async Task TestIdentifier28() { - await TestAsync(@" -namespace {|Identifier:C|}.{|Identifier:D|} -{ -}"); + await TestAsync(""" + namespace {|Identifier:C|}.{|Identifier:D|} + { + } + """); } [Fact] public async Task TestIdentifier29() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}() - { - for (int {|Identifier:E|} = 0; E < 10; E++) - { - } - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}() + { + for (int {|Identifier:E|} = 0; E < 10; E++) + { + } + } + } + """); } [Fact] public async Task TestIdentifier30() { - await TestAsync(@" -class {|Identifier:C|} -{ - void {|Identifier:D|}() - { - Goo(out var {|Identifier:E|}); - } -}"); + await TestAsync(""" + class {|Identifier:C|} + { + void {|Identifier:D|}() + { + Goo(out var {|Identifier:E|}); + } + } + """); } [Fact] public async Task TestIdentifier31() { - await TestAsync(@" -class {|Identifier:C|}() { }"); + await TestAsync(""" + class {|Identifier:C|}() { } + """); } [Fact] public async Task TestIdentifier32() { - await TestAsync(@" -struct {|Identifier:C|}() { }"); + await TestAsync(""" + struct {|Identifier:C|}() { } + """); } [Fact] public async Task TestIdentifier33() { - await TestAsync(@" -class {|Identifier:C|};"); + await TestAsync(""" + class {|Identifier:C|}; + """); } [Fact] public async Task TestIdentifier34() { - await TestAsync(@" -struct {|Identifier:C|};"); + await TestAsync(""" + struct {|Identifier:C|}; + """); } } } diff --git a/src/EditorFeatures/CSharpTest/SplitComment/SplitCommentCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/SplitComment/SplitCommentCommandHandlerTests.cs index 10213ce0404a6..f7d70dede086c 100644 --- a/src/EditorFeatures/CSharpTest/SplitComment/SplitCommentCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/SplitComment/SplitCommentCommandHandlerTests.cs @@ -22,21 +22,25 @@ protected override TestWorkspace CreateWorkspace(string markup) public void TestWithSelection() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //[|Test|] Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // - //Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + //[|Test|] Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // + //Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -44,21 +48,25 @@ public static void Main(string[] args) public void TestWithAllWhitespaceSelection() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // [| |] Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // - // Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // [| |] Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // + // Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -66,13 +74,15 @@ public static void Main(string[] args) public void TestMissingInSlashes() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - /[||]/Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + /[||]/Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -80,11 +90,13 @@ public static void Main(string[] args) public void TestMissingAtEndOfFile() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //Test Comment[||]"); + """ + public class Program + { + public static void Main(string[] args) + { + //Test Comment[||] + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -92,13 +104,15 @@ public static void Main(string[] args) public void TestMissingBeforeSlashes() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - [||]//Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + [||]//Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -106,13 +120,15 @@ public static void Main(string[] args) public void TestMissingWithMultiSelection() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //[||]Test[||] Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + //[||]Test[||] Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -120,21 +136,25 @@ public static void Main(string[] args) public void TestSplitStartOfComment() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //[||]Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // - //Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + //[||]Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // + //Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -142,21 +162,25 @@ public static void Main(string[] args) public void TestSplitStartOfQuadComment() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - ////[||]Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - //// - ////Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + ////[||]Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + //// + ////Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -165,13 +189,15 @@ public static void Main(string[] args) public void TestSplitMiddleOfQuadComment() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //[||]//Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + //[||]//Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/48547")] @@ -179,13 +205,15 @@ public static void Main(string[] args) public void TestSplitWithCommentAfterwards1() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // goo[||] //Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // goo[||] //Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/48547")] @@ -193,13 +221,15 @@ public static void Main(string[] args) public void TestSplitWithCommentAfterwards2() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // goo [||] //Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // goo [||] //Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/48547")] @@ -207,13 +237,15 @@ public static void Main(string[] args) public void TestSplitWithCommentAfterwards3() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // goo [||]//Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // goo [||]//Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/48547")] @@ -221,13 +253,15 @@ public static void Main(string[] args) public void TestSplitWithCommentAfterwards4() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // [|goo|] //Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // [|goo|] //Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -235,21 +269,25 @@ public static void Main(string[] args) public void TestSplitStartOfCommentWithLeadingSpace1() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // [||]Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // - // Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // [||]Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // + // Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -257,21 +295,25 @@ public static void Main(string[] args) public void TestSplitStartOfCommentWithLeadingSpace2() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - //[||] Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // - //Test Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + //[||] Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // + //Test Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -290,14 +332,16 @@ public static void Main(string[] args) // {commentValue} }} }}", -@"public class Program +""" +public class Program { public static void Main(string[] args) { // X // Test Comment } -}"); +} +"""); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -317,14 +361,16 @@ public static void Main(string[] args) //// {commentValue} }} }}", -@"public class Program +""" +public class Program { public static void Main(string[] args) { //// X //// Test Comment } -}"); +} +"""); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -332,21 +378,25 @@ public static void Main(string[] args) public void TestSplitMiddleOfComment() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // Test [||]Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // Test - // Comment - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // Test [||]Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // Test + // Comment + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -354,13 +404,15 @@ public static void Main(string[] args) public void TestSplitEndOfComment() { TestNotHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // Test Comment[||] - } -}"); + """ + public class Program + { + public static void Main(string[] args) + { + // Test Comment[||] + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -368,19 +420,23 @@ public static void Main(string[] args) public void TestSplitCommentEndOfLine1() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) // Test [||]Comment - { - } -}", -@"public class Program -{ - public static void Main(string[] args) // Test - // Comment - { - } -}"); + """ + public class Program + { + public static void Main(string[] args) // Test [||]Comment + { + } + } + """, + """ + public class Program + { + public static void Main(string[] args) // Test + // Comment + { + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -388,19 +444,23 @@ public static void Main(string[] args) // Test public void TestSplitCommentEndOfLine2() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) // Test[||] Comment - { - } -}", -@"public class Program -{ - public static void Main(string[] args) // Test - // Comment - { - } -}"); + """ + public class Program + { + public static void Main(string[] args) // Test[||] Comment + { + } + } + """, + """ + public class Program + { + public static void Main(string[] args) // Test + // Comment + { + } + } + """); } [WorkItem("https://github.com/dotnet/roslyn/issues/38516")] @@ -408,37 +468,43 @@ public static void Main(string[] args) // Test public void TestUseTabs() { TestHandled( -@"public class Program -{ - public static void Main(string[] args) - { - // X[||]Test Comment - } -}", -@"public class Program -{ - public static void Main(string[] args) - { - // X - // Test Comment - } -}", useTabs: true); + """ + public class Program + { + public static void Main(string[] args) + { + // X[||]Test Comment + } + } + """, + """ + public class Program + { + public static void Main(string[] args) + { + // X + // Test Comment + } + } + """, useTabs: true); } [WpfFact] public void TestDoesNotHandleDocComments() { TestNotHandled( -@"namespace TestNamespace -{ - public class Program - { - /// Test [||]Comment - public static void Main(string[] args) - { - } - } -}"); + """ + namespace TestNamespace + { + public class Program + { + /// Test [||]Comment + public static void Main(string[] args) + { + } + } + } + """); } } } diff --git a/src/EditorFeatures/CSharpTest/Squiggles/ErrorSquiggleProducerTests.cs b/src/EditorFeatures/CSharpTest/Squiggles/ErrorSquiggleProducerTests.cs index 9951a29ffeff8..67dc4c038c77e 100644 --- a/src/EditorFeatures/CSharpTest/Squiggles/ErrorSquiggleProducerTests.cs +++ b/src/EditorFeatures/CSharpTest/Squiggles/ErrorSquiggleProducerTests.cs @@ -65,20 +65,22 @@ public async Task ErrorTagGeneratedForWarning() public async Task ErrorTagGeneratedForWarningAsError() { var workspaceXml = -@" - - - - class Program - { - void Test() - { - int a = 5; - } - } - - -"; + """ + + + + + class Program + { + void Test() + { + int a = 5; + } + } + + + + """; using var workspace = TestWorkspace.Create(workspaceXml); @@ -92,26 +94,28 @@ void Test() public async Task CustomizableTagsForUnnecessaryCode() { var workspaceXml = -@" - - -// System is used - rest are unused. -using System.Collections; -using System; -using System.Diagnostics; -using System.Collections.Generic; + """ + + + + // System is used - rest are unused. + using System.Collections; + using System; + using System.Diagnostics; + using System.Collections.Generic; -class Program -{ - void Test() - { - Int32 x = 2; // Int32 can be simplified. - x += 1; - } -} - - -"; + class Program + { + void Test() + { + Int32 x = 2; // Int32 can be simplified. + x += 1; + } + } + + + + """; using var workspace = TestWorkspace.Create(workspaceXml, composition: SquiggleUtilities.CompositionWithSolutionCrawler); var language = workspace.Projects.Single().Language; @@ -298,15 +302,17 @@ public async Task TestNoErrorsAfterProjectRemoved() public async Task BuildErrorZeroLengthSpan() { var workspaceXml = -@" - - - class Test -{ -} - - -"; + """ + + + + class Test + { + } + + + + """; using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition); @@ -332,15 +338,17 @@ class Test public async Task LiveErrorZeroLengthSpan() { var workspaceXml = -@" - - - class Test -{ -} - - -"; + """ + + + + class Test + { + } + + + + """; using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition); diff --git a/src/EditorFeatures/CSharpTest/StringIndentation/StringIndentationTests.cs b/src/EditorFeatures/CSharpTest/StringIndentation/StringIndentationTests.cs index 1d20ca0623ad5..736b99c0ad4a9 100644 --- a/src/EditorFeatures/CSharpTest/StringIndentation/StringIndentationTests.cs +++ b/src/EditorFeatures/CSharpTest/StringIndentation/StringIndentationTests.cs @@ -322,372 +322,412 @@ void M() [Fact] public async Task TestCase10() { - await TestAsync(@"class C -{ - void M() - { - var v = - $$"""""""" - |goo - """"""""; - } -}"); + await TestAsync(""""" + class C + { + void M() + { + var v = + $$"""" + |goo + """"; + } + } + """""); } [Fact] public async Task TestCase11() { - await TestAsync(@"class C -{ - void M() - { - var v = - $$"""""""" - |goo - """"""""; - } -}"); + await TestAsync(""""" + class C + { + void M() + { + var v = + $$"""" + |goo + """"; + } + } + """""); } [Fact] public async Task TestCase12() { - await TestAsync(@"class C -{ - void M() - { - var v = - $$"""""""" - |goo - """"""""; - } -}"); + await TestAsync(""""" + class C + { + void M() + { + var v = + $$"""" + |goo + """"; + } + } + """""); } [Fact] public async Task TestWithHoles1() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo - | { 1 + 1 } - | baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo + | { 1 + 1 } + | baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles2() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo{ - | 1 + 1 - | }baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo{ + | 1 + 1 + | }baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles3() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo{ - |1 + 1 - | }baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo{ + |1 + 1 + | }baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles4() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo{ - 1 + 1 - }baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo{ + 1 + 1 + }baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles5() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo{ - |1 + 1 - | }baz - | quux - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo{ + |1 + 1 + | }baz + | quux + """; + } + } + """"); } [Fact] public async Task TestWithHoles6() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | goo{ - 1 + 1 - }baz - | quux - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | goo{ + 1 + 1 + }baz + | quux + """; + } + } + """"); } [Fact] public async Task TestWithHoles7() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - |goo{ - 1 + 1 - }baz - |quux - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + |goo{ + 1 + 1 + }baz + |quux + """; + } + } + """"); } [Fact] public async Task TestWithHoles8() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | { 1 + 1 } - | baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | { 1 + 1 } + | baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles9() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | { - | 1 + 1 - | } - | baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | { + | 1 + 1 + | } + | baz + """; + } + } + """"); } [Fact] public async Task TestWithHoles10() { - await TestAsync(@"class C -{ - void M() - { - var v = $"""""" - | { - 1 + 1 + await TestAsync("""" + class C + { + void M() + { + var v = $""" + | { + 1 + 1 + } + | baz + """; + } } - | baz - """"""; - } -}"); + """"); } [Fact] public async Task TestWithNestedHoles1() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - | $"""""" - | |bar - | """""" - |} - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + | $""" + | |bar + | """ + |} + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles2() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - | $"""""" - | |bar - | |{ - | | 1 + 1 - | |} - | """""" - |} - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + | $""" + | |bar + | |{ + | | 1 + 1 + | |} + | """ + |} + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles3() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - | $"""""" - | |bar - | |{ - | 1 + 1 - | } - | """""" - |} - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + | $""" + | |bar + | |{ + | 1 + 1 + | } + | """ + |} + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles4() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - $"""""" - |bar - |{ - 1 + 1 - } - """""" - } - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + $""" + |bar + |{ + 1 + 1 + } + """ + } + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles5() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - $"""""" - |bar - """""" - } - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + $""" + |bar + """ + } + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles6() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - $"""""" - |bar - |{ - | 1 + 1 - |} - """""" - } - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + $""" + |bar + |{ + | 1 + 1 + |} + """ + } + |baz + """; + } + } + """"); } [Fact] public async Task TestWithNestedHoles7() { - await TestAsync(@"class C -{ - void M() - { - var x = - $"""""" - |goo - |{ - $"""""" - |bar - |{ - 1 + 1 - } - """""" - } - |baz - """"""; - } -}"); + await TestAsync("""" + class C + { + void M() + { + var x = + $""" + |goo + |{ + $""" + |bar + |{ + 1 + 1 + } + """ + } + |baz + """; + } + } + """"); } [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1542623")] diff --git a/src/EditorFeatures/CSharpTest/SuggestionTags/SuggestionTagProducerTests.cs b/src/EditorFeatures/CSharpTest/SuggestionTags/SuggestionTagProducerTests.cs index 1cbdcad9eda7e..7bc8e01eff50e 100644 --- a/src/EditorFeatures/CSharpTest/SuggestionTags/SuggestionTagProducerTests.cs +++ b/src/EditorFeatures/CSharpTest/SuggestionTags/SuggestionTagProducerTests.cs @@ -31,12 +31,14 @@ public async Task SuggestionTagTest1(bool isSuppressed) var pragmaText = isSuppressed ? $@"#pragma warning disable {IDEDiagnosticIds.UseObjectInitializerDiagnosticId} " : string.Empty; var (spans, selection) = await GetTagSpansAndSelectionAsync( -pragmaText + @"class C { +pragmaText + """ +class C { void M() { var v = [|ne|]w X(); v.Y = 1; } -}"); +} +"""); if (isSuppressed) { Assert.Empty(spans); diff --git a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyCompilationsTests.cs b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyCompilationsTests.cs index ee1c9ce775378..3ae7f39f8085e 100644 --- a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyCompilationsTests.cs +++ b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyCompilationsTests.cs @@ -21,53 +21,55 @@ public partial class SymbolKeyTest : SymbolKeyTestBase [Fact] public void C2CTypeSymbolUnchanged01() { - var src1 = @"using System; - -public delegate void DGoo(int p1, string p2); - -namespace N1.N2 -{ - public interface IGoo { } - namespace N3 - { - public class CGoo - { - public struct SGoo - { - public enum EGoo { Zero, One } - } - } - } -} -"; - - var src2 = @"using System; - -public delegate void DGoo(int p1, string p2); - -namespace N1.N2 -{ - public interface IGoo - { - // Add member - N3.CGoo GetClass(); - } - - namespace N3 - { - public class CGoo - { - public struct SGoo - { - // Update member - public enum EGoo { Zero, One, Two } - } - // Add member - public void M(int n) { Console.WriteLine(n); } - } - } -} -"; + var src1 = """ + using System; + + public delegate void DGoo(int p1, string p2); + + namespace N1.N2 + { + public interface IGoo { } + namespace N3 + { + public class CGoo + { + public struct SGoo + { + public enum EGoo { Zero, One } + } + } + } + } + """; + + var src2 = """ + using System; + + public delegate void DGoo(int p1, string p2); + + namespace N1.N2 + { + public interface IGoo + { + // Add member + N3.CGoo GetClass(); + } + + namespace N3 + { + public class CGoo + { + public struct SGoo + { + // Update member + public enum EGoo { Zero, One, Two } + } + // Add member + public void M(int n) { Console.WriteLine(n); } + } + } + } + """; var comp1 = CreateCompilation(src1, assemblyName: "Test"); var comp2 = CreateCompilation(src2, assemblyName: "Test"); @@ -83,12 +85,12 @@ public void C2CErrorSymbolUnchanged01() { var src1 = @"public void Method() { }"; - var src2 = @" -public void Method() -{ - System.Console.WriteLine(12345); -} -"; + var src2 = """ + public void Method() + { + System.Console.WriteLine(12345); + } + """; var comp1 = CreateCompilation(src1, assemblyName: "C2CErrorSymbolUnchanged01"); var comp2 = CreateCompilation(src2, assemblyName: "C2CErrorSymbolUnchanged01"); @@ -111,16 +113,17 @@ public void Method() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/820263")] public void PartialDefinitionAndImplementationResolveCorrectly() { - var src = @"using System; -namespace NS -{ - public partial class C1 - { - partial void M() { } - partial void M(); - } -} -"; + var src = """ + using System; + namespace NS + { + public partial class C1 + { + partial void M() { } + partial void M(); + } + } + """; var comp = (Compilation)CreateCompilation(src, assemblyName: "Test"); @@ -137,16 +140,17 @@ partial void M() { } [Fact] public void ExtendedPartialDefinitionAndImplementationResolveCorrectly() { - var src = @"using System; -namespace NS -{ - public partial class C1 - { - public partial void M() { } - public partial void M(); - } -} -"; + var src = """ + using System; + namespace NS + { + public partial class C1 + { + public partial void M() { } + public partial void M(); + } + } + """; var comp = (Compilation)CreateCompilation(src, assemblyName: "Test"); @@ -163,34 +167,33 @@ public partial void M() { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/916341")] public void ExplicitIndexerImplementationResolvesCorrectly() { - var src = @" -interface I -{ - object this[int index] { get; } -} -interface I -{ - T this[int index] { get; } -} -class C : I, I -{ - object I.this[int index] - { - get - { - throw new System.NotImplementedException(); - } - } - T I.this[int index] - { - get - { - throw new System.NotImplementedException(); - } - } -} - -"; + var src = """ + interface I + { + object this[int index] { get; } + } + interface I + { + T this[int index] { get; } + } + class C : I, I + { + object I.this[int index] + { + get + { + throw new System.NotImplementedException(); + } + } + T I.this[int index] + { + get + { + throw new System.NotImplementedException(); + } + } + } + """; var compilation = (Compilation)CreateCompilation(src, assemblyName: "Test"); @@ -208,15 +211,17 @@ T I.this[int index] public void RecursiveReferenceToConstructedGeneric() { var src1 = -@"using System.Collections.Generic; - -class C -{ - public void M(List list) - { - var v = list.Add(default(Z)); - } -}"; + """ + using System.Collections.Generic; + + class C + { + public void M(List list) + { + var v = list.Add(default(Z)); + } + } + """; var comp1 = CreateCompilation(src1); var comp2 = CreateCompilation(src1); @@ -240,13 +245,14 @@ public void M(List list) [Fact] public void FileType1() { - var src1 = @"using System; - -namespace N1.N2 -{ - file class C { } -} -"; + var src1 = """ + using System; + + namespace N1.N2 + { + file class C { } + } + """; var originalComp = CreateCompilation(src1, assemblyName: "Test"); var newComp = CreateCompilation(src1, assemblyName: "Test"); @@ -260,13 +266,14 @@ file class C { } [Fact] public void FileType2() { - var src1 = @"using System; - -namespace N1.N2 -{ - file class C { } -} -"; + var src1 = """ + using System; + + namespace N1.N2 + { + file class C { } + } + """; var originalComp = CreateCompilation(src1, assemblyName: "Test"); var newComp = CreateCompilation(src1, assemblyName: "Test"); @@ -280,13 +287,14 @@ file class C { } [Fact] public void FileType3() { - var src1 = @"using System; - -namespace N1.N2 -{ - file class C { } -} -"; + var src1 = """ + using System; + + namespace N1.N2 + { + file class C { } + } + """; // this should result in two entirely separate file symbols. // note that the IDE can only distinguish file-local type symbols with the same name when they have distinct file paths. // We are OK with this as we will require file types with identical names to have distinct file paths later in the preview. @@ -305,20 +313,21 @@ file class C { } public void FileType4() { // we should be able to distinguish a file-local type and non-file-local type when they have the same source name. - var src1 = SyntaxFactory.ParseSyntaxTree(@"using System; - -namespace N1.N2 -{ - file class C { } -} -", path: "File1.cs"); - - var src2 = SyntaxFactory.ParseSyntaxTree(@" -namespace N1.N2 -{ - class C { } -} -", path: "File2.cs"); + var src1 = SyntaxFactory.ParseSyntaxTree(""" + using System; + + namespace N1.N2 + { + file class C { } + } + """, path: "File1.cs"); + + var src2 = SyntaxFactory.ParseSyntaxTree(""" + namespace N1.N2 + { + class C { } + } + """, path: "File2.cs"); var originalComp = CreateCompilation(new[] { src1, src2 }, assemblyName: "Test"); var newComp = CreateCompilation(new[] { src1, src2 }, assemblyName: "Test"); @@ -336,50 +345,52 @@ class C { } [Fact] public void C2CTypeSymbolChanged01() { - var src1 = @"using System; - -public delegate void DGoo(int p1); - -namespace N1.N2 -{ - public interface IBase { } - public interface IGoo { } - namespace N3 - { - public class CGoo - { - public struct SGoo - { - public enum EGoo { Zero, One } - } - } - } -} -"; - - var src2 = @"using System; - -public delegate void DGoo(int p1, string p2); // add 1 more parameter - -namespace N1.N2 -{ - public interface IBase { } - public interface IGoo : IBase // add base interface - { - } - - namespace N3 - { - public class CGoo : IGoo // impl interface - { - private struct SGoo // change modifier - { - internal enum EGoo : long { Zero, One } // change base class, and modifier - } - } - } -} -"; + var src1 = """ + using System; + + public delegate void DGoo(int p1); + + namespace N1.N2 + { + public interface IBase { } + public interface IGoo { } + namespace N3 + { + public class CGoo + { + public struct SGoo + { + public enum EGoo { Zero, One } + } + } + } + } + """; + + var src2 = """ + using System; + + public delegate void DGoo(int p1, string p2); // add 1 more parameter + + namespace N1.N2 + { + public interface IBase { } + public interface IGoo : IBase // add base interface + { + } + + namespace N3 + { + public class CGoo : IGoo // impl interface + { + private struct SGoo // change modifier + { + internal enum EGoo : long { Zero, One } // change base class, and modifier + } + } + } + } + """; var comp1 = CreateCompilation(src1, assemblyName: "Test"); var comp2 = CreateCompilation(src2, assemblyName: "Test"); @@ -393,30 +404,31 @@ internal enum EGoo : long { Zero, One } // change base class, and modifier [Fact] public void C2CTypeSymbolChanged02() { - var src1 = @"using System; -namespace NS -{ - public class C1 - { - public void M() {} - } -} -"; - - var src2 = @" -namespace NS -{ - internal class C1 // add new C1 - { - public string P { get; set; } - } - - public class C2 // rename C1 to C2 - { - public void M() {} - } -} -"; + var src1 = """ + using System; + namespace NS + { + public class C1 + { + public void M() {} + } + } + """; + + var src2 = """ + namespace NS + { + internal class C1 // add new C1 + { + public string P { get; set; } + } + + public class C2 // rename C1 to C2 + { + public void M() {} + } + } + """; var comp1 = (Compilation)CreateCompilation(src1, assemblyName: "Test"); var comp2 = (Compilation)CreateCompilation(src2, assemblyName: "Test"); @@ -439,31 +451,33 @@ public void M() {} [Fact] public void C2CMemberSymbolChanged01() { - var src1 = @"using System; -using System.Collections.Generic; - -public class Test -{ - private byte field = 123; - internal string P { get; set; } - public void M(ref int n) { } - event Action myEvent; -} -"; - - var src2 = @"using System; -public class Test -{ - internal protected byte field = 255; // change modifier and init-value - internal string P { get { return null; } } // remove 'set' - public int M(ref int n) { return 0; } // change ret type - event Action myEvent // add add/remove - { - add { } - remove { } - } -} -"; + var src1 = """ + using System; + using System.Collections.Generic; + + public class Test + { + private byte field = 123; + internal string P { get; set; } + public void M(ref int n) { } + event Action myEvent; + } + """; + + var src2 = """ + using System; + public class Test + { + internal protected byte field = 255; // change modifier and init-value + internal string P { get { return null; } } // remove 'set' + public int M(ref int n) { return 0; } // change ret type + event Action myEvent // add add/remove + { + add { } + remove { } + } + } + """; var comp1 = CreateCompilation(src1, assemblyName: "Test"); var comp2 = CreateCompilation(src2, assemblyName: "Test"); @@ -479,23 +493,25 @@ event Action myEvent // add add/remove [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542700")] public void C2CIndexerSymbolChanged01() { - var src1 = @"using System; -using System.Collections.Generic; - -public class Test -{ - public string this[string p1] { set { } } - protected long this[long p1] { set { } } -} -"; - - var src2 = @"using System; -public class Test -{ - internal string this[string p1] { set { } } // change modifier - protected long this[long p1] { get { return 0; } set { } } // add 'get' -} -"; + var src1 = """ + using System; + using System.Collections.Generic; + + public class Test + { + public string this[string p1] { set { } } + protected long this[long p1] { set { } } + } + """; + + var src2 = """ + using System; + public class Test + { + internal string this[string p1] { set { } } // change modifier + protected long this[long p1] { get { return 0; } set { } } // add 'get' + } + """; var comp1 = (Compilation)CreateCompilation(src1, assemblyName: "Test"); var comp2 = (Compilation)CreateCompilation(src2, assemblyName: "Test"); @@ -512,15 +528,15 @@ internal string this[string p1] { set { } } // change modifier [Fact] public void C2CAssemblyChanged01() { - var src = @" -namespace NS -{ - public class C1 - { - public void M() {} - } -} -"; + var src = """ + namespace NS + { + public class C1 + { + public void M() {} + } + } + """; var comp1 = (Compilation)CreateCompilation(src, assemblyName: "Assembly1"); var comp2 = (Compilation)CreateCompilation(src, assemblyName: "Assembly2"); @@ -603,17 +619,17 @@ public void C2CAssemblyChanged03() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546254")] public void C2CAssemblyChanged04() { - var src = @" -[assembly: System.Reflection.AssemblyVersion(""1.2.3.4"")] -[assembly: System.Reflection.AssemblyTitle(""One Hundred Years of Solitude"")] -public class C {} -"; - - var src2 = @" -[assembly: System.Reflection.AssemblyVersion(""1.2.3.42"")] -[assembly: System.Reflection.AssemblyTitle(""One Hundred Years of Solitude"")] -public class C {} -"; + var src = """ + [assembly: System.Reflection.AssemblyVersion("1.2.3.4")] + [assembly: System.Reflection.AssemblyTitle("One Hundred Years of Solitude")] + public class C {} + """; + + var src2 = """ + [assembly: System.Reflection.AssemblyVersion("1.2.3.42")] + [assembly: System.Reflection.AssemblyTitle("One Hundred Years of Solitude")] + public class C {} + """; // different versions var comp1 = (Compilation)CreateCompilation(src, assemblyName: "Assembly"); diff --git a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyMetadataVsSourceTests.cs b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyMetadataVsSourceTests.cs index 8968a7af94e39..6e9388006912d 100644 --- a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyMetadataVsSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyMetadataVsSourceTests.cs @@ -24,38 +24,40 @@ public partial class SymbolKeyTest : SymbolKeyTestBase [Fact] public void M2SNamedTypeSymbols01() { - var src1 = @"using System; + var src1 = """ + using System; -public delegate void D(int p1, string p2); + public delegate void D(int p1, string p2); -namespace N1.N2 -{ - public interface I { } - namespace N3 - { - public class C - { - public struct S - { - public enum E { Zero, One, Two } - public void M(int n) { Console.WriteLine(n); } - } - } - } -} -"; + namespace N1.N2 + { + public interface I { } + namespace N3 + { + public class C + { + public struct S + { + public enum E { Zero, One, Two } + public void M(int n) { Console.WriteLine(n); } + } + } + } + } + """; - var src2 = @"using System; -using N1.N2.N3; + var src2 = """ + using System; + using N1.N2.N3; -public class App : C -{ - private event D myEvent; - internal N1.N2.I Prop { get; set; } - protected C.S.E this[int x] { set { } } - public void M(C.S s) { s.M(123); } -} -"; + public class App : C + { + private event D myEvent; + internal N1.N2.I Prop { get; set; } + protected C.S.E this[int x] { set { } } + public void M(C.S s) { s.M(123); } + } + """; var comp1 = CreateCompilation(src1); @@ -94,50 +96,52 @@ protected C.S.E this[int x] { set { } } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542700")] public void M2SNonTypeMemberSymbols01() { - var src1 = @"using System; + var src1 = """ + using System; -namespace N1 -{ - public interface IGoo - { - void M(int p1, int p2); - void M(params short[] ary); + namespace N1 + { + public interface IGoo + { + void M(int p1, int p2); + void M(params short[] ary); - void M(string p1); - void M(ref string p1); - } + void M(string p1); + void M(ref string p1); + } - public struct S - { - public event Action PublicEvent { add { } remove { } } - public IGoo PublicField; - public string PublicProp { get; set; } - public short this[sbyte p] { get { return p; } } - } -} -"; + public struct S + { + public event Action PublicEvent { add { } remove { } } + public IGoo PublicField; + public string PublicProp { get; set; } + public short this[sbyte p] { get { return p; } } + } + } + """; - var src2 = @"using System; -using AN = N1; + var src2 = """ + using System; + using AN = N1; -public class App -{ - static void Main() - { - var obj = new AN.S(); + public class App + { + static void Main() + { + var obj = new AN.S(); - /**/obj.PublicEvent/**/ += EH; + /**/obj.PublicEvent/**/ += EH; - var igoo = /**/obj.PublicField/**/; + var igoo = /**/obj.PublicField/**/; - /**/igoo.M(/**/obj.PublicProp/**/)/**/; + /**/igoo.M(/**/obj.PublicProp/**/)/**/; - /**/igoo.M(obj[12], /**/obj[123]/**/)/**/; - } + /**/igoo.M(obj[12], /**/obj[123]/**/)/**/; + } - static void EH(AN.S s) { } -} -"; + static void EH(AN.S s) { } + } + """; var comp1 = CreateCompilation(src1); @@ -183,49 +187,51 @@ static void EH(AN.S s) { } [Fact] public void M2MMultiTargetingMsCorLib01() { - var src1 = @"using System; -using System.IO; + var src1 = """ + using System; + using System.IO; -public class A -{ - public FileInfo GetFileInfo(string path) - { - if (File.Exists(path)) - { - return new FileInfo(path); - } + public class A + { + public FileInfo GetFileInfo(string path) + { + if (File.Exists(path)) + { + return new FileInfo(path); + } - return null; - } + return null; + } - public void PrintInfo(Array ary, ref DateTime time) - { - if (ary != null) - Console.WriteLine(ary); - else - Console.WriteLine(""null""); + public void PrintInfo(Array ary, ref DateTime time) + { + if (ary != null) + Console.WriteLine(ary); + else + Console.WriteLine("null"); - time = DateTime.Now; - } -} -"; + time = DateTime.Now; + } + } + """; - var src2 = @"using System; + var src2 = """ + using System; -class Test -{ - static void Main() - { - var a = new A(); - var fi = a.GetFileInfo(null); - Console.WriteLine(fi); + class Test + { + static void Main() + { + var a = new A(); + var fi = a.GetFileInfo(null); + Console.WriteLine(fi); - var dt = DateTime.Now; - var ary = Array.CreateInstance(typeof(string), 2); - a.PrintInfo(ary, ref dt); - } -} -"; + var dt = DateTime.Now; + var ary = Array.CreateInstance(typeof(string), 2); + a.PrintInfo(ary, ref dt); + } + } + """; var comp20 = (Compilation)CreateEmptyCompilation(src1, new[] { Net40.mscorlib }); // "Compilation 2 Assembly" @@ -277,53 +283,55 @@ static void Main() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546255")] public void M2MMultiTargetingMsCorLib02() { - var src1 = @"using System; -namespace Mscorlib20 -{ - public interface IGoo - { - // interface - IDisposable Prop { get; set; } - // class - Exception this[ArgumentException t] { get; } - } + var src1 = """ + using System; + namespace Mscorlib20 + { + public interface IGoo + { + // interface + IDisposable Prop { get; set; } + // class + Exception this[ArgumentException t] { get; } + } - public class CGoo : IGoo - { - // enum - public DayOfWeek PublicField; - // delegate - public event System.Threading.ParameterizedThreadStart PublicEventField; + public class CGoo : IGoo + { + // enum + public DayOfWeek PublicField; + // delegate + public event System.Threading.ParameterizedThreadStart PublicEventField; - public IDisposable Prop { get; set; } - public Exception this[ArgumentException t] { get { return t; } } - } -} -"; + public IDisposable Prop { get; set; } + public Exception this[ArgumentException t] { get { return t; } } + } + } + """; - var src2 = @"using System; -using N20 = Mscorlib20; + var src2 = """ + using System; + using N20 = Mscorlib20; -class Test -{ - public IDisposable M() - { - var obj = new N20::CGoo(); - N20.IGoo igoo = obj; + class Test + { + public IDisposable M() + { + var obj = new N20::CGoo(); + N20.IGoo igoo = obj; - /**/obj.PublicEventField/**/ += /**/MyEveHandler/**/; - var local = /**/igoo[null]/**/; + /**/obj.PublicEventField/**/ += /**/MyEveHandler/**/; + var local = /**/igoo[null]/**/; - if (/**/obj.PublicField /**/== DayOfWeek.Friday) - { - return /**/(obj as N20.IGoo).Prop/**/; - } - return null; - } + if (/**/obj.PublicField /**/== DayOfWeek.Friday) + { + return /**/(obj as N20.IGoo).Prop/**/; + } + return null; + } - public void MyEveHandler(object o) { } -} -"; + public void MyEveHandler(object o) { } + } + """; var comp20 = CreateEmptyCompilation(src1, new[] { Net40.mscorlib }); // "Compilation ref Compilation" @@ -372,40 +380,42 @@ public void MyEveHandler(object o) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546255")] public void M2MMultiTargetingMsCorLib03() { - var src1 = @"using System; -namespace Mscorlib20 -{ - public interface IGoo - { - // interface - IDisposable Prop { get; set; } - // class - Exception this[ArgumentException t] { get; } - } + var src1 = """ + using System; + namespace Mscorlib20 + { + public interface IGoo + { + // interface + IDisposable Prop { get; set; } + // class + Exception this[ArgumentException t] { get; } + } - public class CGoo : IGoo - { - // explicit - IDisposable IGoo.Prop { get; set; } - Exception IGoo.this[ArgumentException t] { get { return t; } } - } -} -"; + public class CGoo : IGoo + { + // explicit + IDisposable IGoo.Prop { get; set; } + Exception IGoo.this[ArgumentException t] { get { return t; } } + } + } + """; - var src2 = @"using System; -using N20 = Mscorlib20; + var src2 = """ + using System; + using N20 = Mscorlib20; -class Test -{ - public IDisposable M() - { - N20.IGoo igoo = new N20::CGoo(); + class Test + { + public IDisposable M() + { + N20.IGoo igoo = new N20::CGoo(); - var local = /**/igoo[new ArgumentException()]/**/; - return /**/igoo.Prop/**/; - } -} -"; + var local = /**/igoo[new ArgumentException()]/**/; + return /**/igoo.Prop/**/; + } + } + """; var comp20 = CreateEmptyCompilation(src1, new[] { Net40.mscorlib }); // "Compilation ref Compilation" diff --git a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyTests.cs b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyTests.cs index 3a6730bbad3b5..ed2b4194807c2 100644 --- a/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyTests.cs +++ b/src/EditorFeatures/CSharpTest/SymbolKey/SymbolKeyTests.cs @@ -22,12 +22,12 @@ public class SymbolKeyTests [Fact] public async Task FileType_01() { - var typeSource = @" -file class C1 -{ - public static void M() { } -} -"; + var typeSource = """ + file class C1 + { + public static void M() { } + } + """; var workspaceXml = @$" @@ -130,23 +130,24 @@ public class Inner { } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45437")] public async Task TestGenericsAndNullability() { - var typeSource = @" -#nullable enable - - public sealed class ConditionalWeakTableTest /*: IEnumerable>, IEnumerable*/ - where TKey : class - where TValue : class - { - public ConditionalWeakTable() { } - public void Add(TKey key, TValue value) { } - public void AddOrUpdate(TKey key, TValue value) { } - public void Clear() { } - public TValue GetOrCreateValue(TKey key) => default; - public TValue GetValue(TKey key, ConditionalWeakTableTest.CreateValueCallback createValueCallback) => default; - public bool Remove(TKey key) => false; - - public delegate TValue CreateValueCallback(TKey key); - }".Replace("<", "<").Replace(">", ">"); + var typeSource = """ + #nullable enable + + public sealed class ConditionalWeakTableTest /*: IEnumerable>, IEnumerable*/ + where TKey : class + where TValue : class + { + public ConditionalWeakTable() { } + public void Add(TKey key, TValue value) { } + public void AddOrUpdate(TKey key, TValue value) { } + public void Clear() { } + public TValue GetOrCreateValue(TKey key) => default; + public TValue GetValue(TKey key, ConditionalWeakTableTest.CreateValueCallback createValueCallback) => default; + public bool Remove(TKey key) => false; + + public delegate TValue CreateValueCallback(TKey key); + } + """.Replace("<", "<").Replace(">", ">"); var workspaceXml = @$" @@ -209,24 +210,26 @@ public async Task ResolveBodySymbolsInMultiProjectReferencesToOriginalProjectAsy TestWorkspace GetWorkspace() { - var bodyProject = @" - - -class Program -{ - void M() - { - int local; - } -} - - "; - var referenceProject = @" - - BodyProject - - - "; + var bodyProject = """ + + + class Program + { + void M() + { + int local; + } + } + + + """; + var referenceProject = """ + + BodyProject + + + + """; // Randomize the order of the projects in the workspace. if (random.Next() % 2 == 0) diff --git a/src/EditorFeatures/CSharpTest/TaskList/CSharpTaskListTests.cs b/src/EditorFeatures/CSharpTest/TaskList/CSharpTaskListTests.cs index a6853a5d788b4..9e7583b335240 100644 --- a/src/EditorFeatures/CSharpTest/TaskList/CSharpTaskListTests.cs +++ b/src/EditorFeatures/CSharpTest/TaskList/CSharpTaskListTests.cs @@ -52,7 +52,9 @@ public async Task SingleLineTodoComment_Number(TestHost host) [Theory, CombinatorialData] public async Task SingleLineTodoComment_Quote(TestHost host) { - var code = @"// ""TODO test"""; + var code = """ + // "TODO test" + """; await TestAsync(code, host); } @@ -132,12 +134,13 @@ public async Task MultilineTodoComment_Singleline_Document(TestHost host) [Theory, CombinatorialData] public async Task MultilineTodoComment_Multiline(TestHost host) { - var code = @" -/* [|TODO: hello |] - [|TODO: hello |] -[|TODO: hello |] - * [|TODO: hello |] - [|TODO: hello |]*/"; + var code = """ + /* [|TODO: hello |] + [|TODO: hello |] + [|TODO: hello |] + * [|TODO: hello |] + [|TODO: hello |]*/ + """; await TestAsync(code, host); } @@ -145,12 +148,13 @@ public async Task MultilineTodoComment_Multiline(TestHost host) [Theory, CombinatorialData] public async Task MultilineTodoComment_Multiline_DocComment(TestHost host) { - var code = @" -/** [|TODO: hello |] - [|TODO: hello |] -[|TODO: hello |] - * [|TODO: hello |] - [|TODO: hello |]*/"; + var code = """ + /** [|TODO: hello |] + [|TODO: hello |] + [|TODO: hello |] + * [|TODO: hello |] + [|TODO: hello |]*/ + """; await TestAsync(code, host); } @@ -158,11 +162,12 @@ public async Task MultilineTodoComment_Multiline_DocComment(TestHost host) [Theory, CombinatorialData] public async Task SinglelineDocumentComment_Multiline(TestHost host) { - var code = @" - /// - /// [|TODO : test |] - /// - /// [|UNDONE: test2 |]"; + var code = """ + /// + /// [|TODO : test |] + /// + /// [|UNDONE: test2 |] + """; await TestAsync(code, host); } diff --git a/src/EditorFeatures/CSharpTest/TextStructureNavigation/TextStructureNavigatorTests.cs b/src/EditorFeatures/CSharpTest/TextStructureNavigation/TextStructureNavigatorTests.cs index 7d040a8479799..0a17d01dd5034 100644 --- a/src/EditorFeatures/CSharpTest/TextStructureNavigation/TextStructureNavigatorTests.cs +++ b/src/EditorFeatures/CSharpTest/TextStructureNavigation/TextStructureNavigatorTests.cs @@ -55,9 +55,17 @@ public void EndOfFile() public void NewLine() { AssertExtent( - "class Class1 {$${|Insignificant:\r\n|}\r\n}"); - AssertExtent( - "class Class1 {\r\n$${|Insignificant:\r\n|}}"); + """ + class Class1 {$${|Insignificant: + |} + } + """); + AssertExtent( + """ + class Class1 { + $${|Insignificant: + |}} + """); } [WpfFact] @@ -310,135 +318,169 @@ public void InterpolatedString1() public void TestRawStringContent() { AssertExtent( - @"string s = """""" - Hello - {|Significant:$$World|}! - :) - """""";"); - - AssertExtent( - @"string s = """""" - Hello - {|Significant:W$$orld|}! - :) - """""";"); - - AssertExtent( - @"string s = """""" - Hello - {|Significant:Wo$$rld|}! - :) - """""";"); - - AssertExtent( - @"string s = """""" - Hello - {|Significant:Wor$$ld|}! - :) - """""";"); - - AssertExtent( - @"string s = """""" - Hello - {|Significant:Worl$$d|}! - :) - """""";"); - - AssertExtent( - @"string s = """""" - Hello - World{|Significant:$$!|} - :) - """""";"); + """" + string s = """ + Hello + {|Significant:$$World|}! + :) + """; + """"); + + AssertExtent( + """" + string s = """ + Hello + {|Significant:W$$orld|}! + :) + """; + """"); + + AssertExtent( + """" + string s = """ + Hello + {|Significant:Wo$$rld|}! + :) + """; + """"); + + AssertExtent( + """" + string s = """ + Hello + {|Significant:Wor$$ld|}! + :) + """; + """"); + + AssertExtent( + """" + string s = """ + Hello + {|Significant:Worl$$d|}! + :) + """; + """"); + + AssertExtent( + """" + string s = """ + Hello + World{|Significant:$$!|} + :) + """; + """"); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59581")] public void TestRawStringDelimeter1() { AssertExtent( - @"string s = {|Significant:$$""""""|} - Hello - World! - :) - """""";"); - - AssertExtent( - @"string s = {|Significant:""$$""""|} - Hello - World! - :) - """""";"); - - AssertExtent( - @"string s = {|Significant:""""$$""|} - Hello - World! - :) - """""";"); + """" + string s = {|Significant:$$"""|} + Hello + World! + :) + """; + """"); + + AssertExtent( + """" + string s = {|Significant:"$$""|} + Hello + World! + :) + """; + """"); + + AssertExtent( + """" + string s = {|Significant:""$$"|} + Hello + World! + :) + """; + """"); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59581")] public void TestRawStringDelimeter2() { AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:$$""""""|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""$$""""|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""""$$""|};"); + """" + string s = """ + Hello + World! + :) + {|Significant:$$"""|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:"$$""|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:""$$"|}; + """"); } [WpfFact] public void TestUtf8RawStringDelimeter() { AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:$$""""""u8|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""$$""""u8|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""""$$""u8|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""""""$$u8|};"); - - AssertExtent( - @"string s = """""" - Hello - World! - :) - {|Significant:""""""u$$8|};"); + """" + string s = """ + Hello + World! + :) + {|Significant:$$"""u8|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:"$$""u8|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:""$$"u8|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:"""$$u8|}; + """"); + + AssertExtent( + """" + string s = """ + Hello + World! + :) + {|Significant:"""u$$8|}; + """"); } private static void TestNavigator( @@ -496,15 +538,19 @@ public void GetSpanOfFirstChildTest() { // Go from 'class Class1 { }' to 'class' TestNavigator( -@"class Class1 -{ -}", (n, s) => n.GetSpanOfFirstChild(s), 0, 16, 0, 5); + """ + class Class1 + { + } + """, (n, s) => n.GetSpanOfFirstChild(s), 0, 16, 0, 5); // Next operation should do nothing as we're at the bottom TestNavigator( -@"class Class1 -{ -}", (n, s) => n.GetSpanOfFirstChild(s), 0, 5, 0, 5); + """ + class Class1 + { + } + """, (n, s) => n.GetSpanOfFirstChild(s), 0, 5, 0, 5); } [WpfFact] @@ -512,9 +558,11 @@ public void GetSpanOfNextSiblingTest() { // Go from 'class' to 'Class1' TestNavigator( -@"class Class1 -{ -}", (n, s) => n.GetSpanOfNextSibling(s), 0, 5, 6, 6); + """ + class Class1 + { + } + """, (n, s) => n.GetSpanOfNextSibling(s), 0, 5, 6, 6); } [WpfFact] diff --git a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs index 2475fa900b7d2..d32d1c7c8392c 100644 --- a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs +++ b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.Delegate.cs @@ -39,14 +39,16 @@ private async Task TestDelegateAsync(string text, string expectedType) public async Task TestDeclaration1() { var text = -@"using System; -class C -{ - void M() - { - Func q = [|here|]; - } -}"; + """ + using System; + class C + { + void M() + { + Func q = [|here|]; + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -55,15 +57,17 @@ void M() public async Task TestAssignment1() { var text = -@"using System; -class C -{ - void M() - { - Func f; - f = [|here|] - } -}"; + """ + using System; + class C + { + void M() + { + Func f; + f = [|here|] + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -72,16 +76,18 @@ void M() public async Task TestArgument1() { var text = -@"using System; -class C -{ - void M() - { - Bar([|here|]); - } - - void Bar(Func f); -}"; + """ + using System; + class C + { + void M() + { + Bar([|here|]); + } + + void Bar(Func f); + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -90,16 +96,18 @@ void M() public async Task TestConstructor1() { var text = -@"using System; -class C -{ - void M() - { - new C([|here|]); - } - - public C(Func f); -}"; + """ + using System; + class C + { + void M() + { + new C([|here|]); + } + + public C(Func f); + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -108,14 +116,16 @@ void M() public async Task TestDelegateConstructor1() { var text = -@"using System; -class C -{ - void M() - { - new Func([|here|]); - } -}"; + """ + using System; + class C + { + void M() + { + new Func([|here|]); + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -124,14 +134,16 @@ void M() public async Task TestCastExpression1() { var text = -@"using System; -class C -{ - void M() - { - (Func)[|here|] - } -}"; + """ + using System; + class C + { + void M() + { + (Func)[|here|] + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -140,14 +152,16 @@ void M() public async Task TestCastExpression2() { var text = -@"using System; -class C -{ - void M() - { - (Func)([|here|] - } -}"; + """ + using System; + class C + { + void M() + { + (Func)([|here|] + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -156,14 +170,16 @@ void M() public async Task TestReturnFromMethod() { var text = -@"using System; -class C -{ - Func M() - { - return [|here|] - } -}"; + """ + using System; + class C + { + Func M() + { + return [|here|] + } + } + """; await TestDelegateAsync(text, "System.Func"); } @@ -172,14 +188,16 @@ Func M() public async Task TestInsideLambda1() { var text = -@"using System; -class C -{ - void M() - { - Func> f = i => [|here|] - } -}"; + """ + using System; + class C + { + void M() + { + Func> f = i => [|here|] + } + } + """; await TestDelegateAsync(text, "System.Func"); } diff --git a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs index 84a16d48f210e..79996aeefe54a 100644 --- a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs +++ b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs @@ -46,22 +46,26 @@ protected override async Task TestWorkerAsync(Document document, TextSpan textSp private async Task TestInClassAsync(string text, string expectedType, TestMode mode) { - text = @"class C -{ - $ -}".Replace("$", text); + text = """ + class C + { + $ + } + """.Replace("$", text); await TestAsync(text, expectedType, mode); } private async Task TestInMethodAsync(string text, string expectedType, TestMode mode) { - text = @"class C -{ - void M() - { - $ - } -}".Replace("$", text); + text = """ + class C + { + void M() + { + $ + } + } + """.Replace("$", text); await TestAsync(text, expectedType, mode); } @@ -124,8 +128,10 @@ await TestInMethodAsync( public async Task TestVariableDeclaratorNullableReferenceType(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -string? q = [|Goo()|];", "global::System.String?", mode); + """ + #nullable enable + string? q = [|Goo()|]; + """, "global::System.String?", mode); } [Fact] @@ -139,16 +145,20 @@ await TestInMethodAsync( public async Task TestCoalesce2(TestMode mode) { await TestInMethodAsync( -@"bool? b; -var q = b ?? [|Goo()|];", "global::System.Boolean", mode); + """ + bool? b; + var q = b ?? [|Goo()|]; + """, "global::System.Boolean", mode); } [Theory, CombinatorialData] public async Task TestCoalesce3(TestMode mode) { await TestInMethodAsync( -@"string s; -var q = s ?? [|Goo()|];", "global::System.String", mode); + """ + string s; + var q = s ?? [|Goo()|]; + """, "global::System.String", mode); } [Fact] @@ -165,24 +175,30 @@ public async Task TestCoalesceWithErrorType() // a struct (where the question mark is legal) or a class (where it isn't). We'll thus avoid sticking question marks in this case. // https://github.com/dotnet/roslyn/issues/37852 tracks fixing this is a much fancier way. await TestInMethodAsync( -@"ErrorType s; -var q = [|Goo()|] ?? s;", "ErrorType", TestMode.Node); + """ + ErrorType s; + var q = [|Goo()|] ?? s; + """, "ErrorType", TestMode.Node); } [Theory, CombinatorialData] public async Task TestBinaryExpression1(TestMode mode) { await TestInMethodAsync( -@"string s; -var q = s + [|Goo()|];", "global::System.String", mode); + """ + string s; + var q = s + [|Goo()|]; + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestBinaryExpression2(TestMode mode) { await TestInMethodAsync( -@"var s; -var q = s || [|Goo()|];", "global::System.Boolean", mode); + """ + var s; + var q = s || [|Goo()|]; + """, "global::System.Boolean", mode); } [Theory, CombinatorialData] @@ -225,44 +241,48 @@ await TestInMethodAsync( public async Task TestOverloadedConditionalLogicalOperatorsInferBool(TestMode mode) { await TestAsync( -@"using System; - -class C -{ - public static C operator &(C c, C d) - { - return null; - } - - public static bool operator true(C c) - { - return true; - } + """ + using System; - public static bool operator false(C c) - { - return false; - } - - static void Main(string[] args) - { - var c = new C() && [|Goo()|]; - } -}", "global::System.Boolean", mode); + class C + { + public static C operator &(C c, C d) + { + return null; + } + + public static bool operator true(C c) + { + return true; + } + + public static bool operator false(C c) + { + return false; + } + + static void Main(string[] args) + { + var c = new C() && [|Goo()|]; + } + } + """, "global::System.Boolean", mode); } [Theory, CombinatorialData] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestConditionalLogicalOrOperatorAlwaysInfersBool(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = a || [|7|]; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = a || [|7|]; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -270,42 +290,48 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestConditionalLogicalAndOperatorAlwaysInfersBool(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = a && [|7|]; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = a && [|7|]; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference1() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] | true; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] | true; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference2() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] | b | c || d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] | b | c || d; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } @@ -313,32 +339,36 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference3(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = a | b | [|c|] || d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = a | b | [|c|] || d; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference4() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] | b); - } - static object Goo(Program p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] | b); + } + static object Goo(Program p) + { + return p; + } + } + """; await TestAsync(text, "Program", TestMode.Node); } @@ -346,32 +376,36 @@ static object Goo(Program p) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference5(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] | b); - } - static object Goo(bool p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] | b); + } + static object Goo(bool p) + { + return p; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference6() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if (([|x|] | y) != 0) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if (([|x|] | y) != 0) {} + } + } + """; await TestAsync(text, "global::System.Int32", TestMode.Node); } @@ -379,42 +413,48 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrOperatorInference7(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] | y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] | y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference1() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] & true; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] & true; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference2() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] & b & c && d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] & b & c && d; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } @@ -422,32 +462,36 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference3(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = a & b & [|c|] && d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = a & b & [|c|] && d; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference4() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] & b); - } - static object Goo(Program p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] & b); + } + static object Goo(Program p) + { + return p; + } + } + """; await TestAsync(text, "Program", TestMode.Node); } @@ -455,32 +499,36 @@ static object Goo(Program p) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference5(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] & b); - } - static object Goo(bool p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] & b); + } + static object Goo(bool p) + { + return p; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference6() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if (([|x|] & y) != 0) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if (([|x|] & y) != 0) {} + } + } + """; await TestAsync(text, "global::System.Int32", TestMode.Node); } @@ -488,42 +536,48 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndOperatorInference7(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] & y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] & y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference1() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] ^ true; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] ^ true; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference2() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = [|a|] ^ b ^ c && d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = [|a|] ^ b ^ c && d; + } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } @@ -531,32 +585,36 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference3(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = a ^ b ^ [|c|] && d; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = a ^ b ^ [|c|] && d; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference4() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] ^ b); - } - static object Goo(Program p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] ^ b); + } + static object Goo(Program p) + { + return p; + } + } + """; await TestAsync(text, "Program", TestMode.Node); } @@ -564,32 +622,36 @@ static object Goo(Program p) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference5(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - var x = Goo([|a|] ^ b); - } - static object Goo(bool p) - { - return p; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + var x = Goo([|a|] ^ b); + } + static object Goo(bool p) + { + return p; + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference6() { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if (([|x|] ^ y) != 0) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if (([|x|] ^ y) != 0) {} + } + } + """; await TestAsync(text, "global::System.Int32", TestMode.Node); } @@ -597,14 +659,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorOperatorInference7(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] ^ y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] ^ y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -612,14 +676,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrEqualsOperatorInference1(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] |= y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] |= y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -627,14 +693,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalOrEqualsOperatorInference2(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - int z = [|x|] |= y; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + int z = [|x|] |= y; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -642,14 +710,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndEqualsOperatorInference1(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] &= y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] &= y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -657,14 +727,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalAndEqualsOperatorInference2(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - int z = [|x|] &= y; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + int z = [|x|] &= y; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -672,14 +744,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorEqualsOperatorInference1(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - if ([|x|] ^= y) {} - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + if ([|x|] ^= y) {} + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -687,14 +761,16 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/617633")] public async Task TestLogicalXorEqualsOperatorInference2(TestMode mode) { - var text = @"using System; -class C -{ - static void Main(string[] args) - { - int z = [|x|] ^= y; - } -}"; + var text = """ + using System; + class C + { + static void Main(string[] args) + { + int z = [|x|] ^= y; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -702,285 +778,333 @@ static void Main(string[] args) public async Task TestReturnInConstructor(TestMode mode) { await TestInClassAsync( -@"C() -{ - return [|Goo()|]; -}", "void", mode); + """ + C() + { + return [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInDestructor(TestMode mode) { await TestInClassAsync( -@"~C() -{ - return [|Goo()|]; -}", "void", mode); + """ + ~C() + { + return [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInMethod(TestMode mode) { await TestInClassAsync( -@"int M() -{ - return [|Goo()|]; -}", "global::System.Int32", mode); + """ + int M() + { + return [|Goo()|]; + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInMethodNullableReference(TestMode mode) { await TestInClassAsync( -@"#nullable enable -string? M() -{ - return [|Goo()|]; -}", "global::System.String?", mode); + """ + #nullable enable + string? M() + { + return [|Goo()|]; + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInVoidMethod(TestMode mode) { await TestInClassAsync( -@"void M() -{ - return [|Goo()|]; -}", "void", mode); + """ + void M() + { + return [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskOfTMethod(TestMode mode) { await TestInClassAsync( -@"async System.Threading.Tasks.Task M() -{ - return [|Goo()|]; -}", "global::System.Int32", mode); + """ + async System.Threading.Tasks.Task M() + { + return [|Goo()|]; + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskOfTMethodNestedNullability(TestMode mode) { await TestInClassAsync( -@"async System.Threading.Tasks.Task M() -{ - return [|Goo()|]; -}", "global::System.String?", mode); + """ + async System.Threading.Tasks.Task M() + { + return [|Goo()|]; + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskMethod(TestMode mode) { await TestInClassAsync( -@"async System.Threading.Tasks.Task M() -{ - return [|Goo()|]; -}", "void", mode); + """ + async System.Threading.Tasks.Task M() + { + return [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncVoidMethod(TestMode mode) { await TestInClassAsync( -@"async void M() -{ - return [|Goo()|]; -}", "void", mode); + """ + async void M() + { + return [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInOperator(TestMode mode) { await TestInClassAsync( -@"public static C operator ++(C c) -{ - return [|Goo()|]; -}", "global::C", mode); + """ + public static C operator ++(C c) + { + return [|Goo()|]; + } + """, "global::C", mode); } [Theory, CombinatorialData] public async Task TestReturnInConversionOperator(TestMode mode) { await TestInClassAsync( -@"public static implicit operator int(C c) -{ - return [|Goo()|]; -}", "global::System.Int32", mode); + """ + public static implicit operator int(C c) + { + return [|Goo()|]; + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInPropertyGetter(TestMode mode) { await TestInClassAsync( -@"int P -{ - get - { - return [|Goo()|]; - } -}", "global::System.Int32", mode); + """ + int P + { + get + { + return [|Goo()|]; + } + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInPropertyGetterNullableReference(TestMode mode) { await TestInClassAsync( -@"#nullable enable -string? P -{ - get - { - return [|Goo()|]; - } -}", "global::System.String?", mode); + """ + #nullable enable + string? P + { + get + { + return [|Goo()|]; + } + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInPropertySetter(TestMode mode) { await TestInClassAsync( -@"int P -{ - set - { - return [|Goo()|]; - } -}", "void", mode); + """ + int P + { + set + { + return [|Goo()|]; + } + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInIndexerGetter(TestMode mode) { await TestInClassAsync( -@"int this[int i] -{ - get - { - return [|Goo()|]; - } -}", "global::System.Int32", mode); + """ + int this[int i] + { + get + { + return [|Goo()|]; + } + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInIndexerGetterNullableReference(TestMode mode) { await TestInClassAsync( -@"#nullable enable -string? this[int i] -{ - get - { - return [|Goo()|]; - } -}", "global::System.String?", mode); + """ + #nullable enable + string? this[int i] + { + get + { + return [|Goo()|]; + } + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInIndexerSetter(TestMode mode) { await TestInClassAsync( -@"int this[int i] -{ - set - { - return [|Goo()|]; - } -}", "void", mode); + """ + int this[int i] + { + set + { + return [|Goo()|]; + } + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInEventAdder(TestMode mode) { await TestInClassAsync( -@"event System.EventHandler E -{ - add - { - return [|Goo()|]; - } - remove { } -}", "void", mode); + """ + event System.EventHandler E + { + add + { + return [|Goo()|]; + } + remove { } + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInEventRemover(TestMode mode) { await TestInClassAsync( -@"event System.EventHandler E -{ - add { } - remove - { - return [|Goo()|]; - } -}", "void", mode); + """ + event System.EventHandler E + { + add { } + remove + { + return [|Goo()|]; + } + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - int F() - { - return [|Goo()|]; - } -}", "global::System.Int32", mode); + """ + void M() + { + int F() + { + return [|Goo()|]; + } + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInLocalFunctionNullableReference(TestMode mode) { await TestInClassAsync( -@"#nullable enable -void M() -{ - string? F() - { - return [|Goo()|]; - } -}", "global::System.String?", mode); + """ + #nullable enable + void M() + { + string? F() + { + return [|Goo()|]; + } + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskOfTLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async System.Threading.Tasks.Task F() - { - return [|Goo()|]; - } -}", "global::System.Int32", mode); + """ + void M() + { + async System.Threading.Tasks.Task F() + { + return [|Goo()|]; + } + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async System.Threading.Tasks.Task F() - { - return [|Goo()|]; - } -}", "void", mode); + """ + void M() + { + async System.Threading.Tasks.Task F() + { + return [|Goo()|]; + } + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncVoidLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async void F() - { - return [|Goo()|]; - } -}", "void", mode); + """ + void M() + { + async void F() + { + return [|Goo()|]; + } + } + """, "void", mode); } [Theory, CombinatorialData] @@ -1022,8 +1146,10 @@ await TestInClassAsync( public async Task TestExpressionBodiedAsyncTaskOfTMethodNullableReference(TestMode mode) { await TestInClassAsync( -@"#nullable enable -async System.Threading.Tasks.Task M() => [|Goo()|];", "global::System.String?", mode); + """ + #nullable enable + async System.Threading.Tasks.Task M() => [|Goo()|]; + """, "global::System.String?", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/27647"), CombinatorialData] @@ -1114,40 +1240,48 @@ await TestInClassAsync( public async Task TestExpressionBodiedLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - int F() => [|Goo()|]; -}", "global::System.Int32", mode); + """ + void M() + { + int F() => [|Goo()|]; + } + """, "global::System.Int32", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/27647"), CombinatorialData] public async Task TestExpressionBodiedAsyncTaskOfTLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async System.Threading.Tasks.Task F() => [|Goo()|]; -}", "global::System.Int32", mode); + """ + void M() + { + async System.Threading.Tasks.Task F() => [|Goo()|]; + } + """, "global::System.Int32", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/27647"), CombinatorialData] public async Task TestExpressionBodiedAsyncTaskLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async System.Threading.Tasks.Task F() => [|Goo()|]; -}", "void", mode); + """ + void M() + { + async System.Threading.Tasks.Task F() => [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] public async Task TestExpressionBodiedAsyncVoidLocalFunction(TestMode mode) { await TestInClassAsync( -@"void M() -{ - async void F() => [|Goo()|]; -}", "void", mode); + """ + void M() + { + async void F() => [|Goo()|]; + } + """, "void", mode); } [Theory, CombinatorialData] @@ -1221,18 +1355,20 @@ public async Task TestYieldReturnInvalidTypeInMethod([CombinatorialValues("int[] public async Task TestYieldReturnInLocalFunction(TestMode mode) { var markup = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - IEnumerable F() - { - yield return [|abc|] - } - } -}"; + class C + { + void M() + { + IEnumerable F() + { + yield return [|abc|] + } + } + } + """; await TestAsync(markup, "global::System.Int32", mode); } @@ -1240,18 +1376,20 @@ IEnumerable F() public async Task TestYieldReturnInPropertyGetter(TestMode mode) { var markup = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - IEnumerable P - { - get - { - yield return [|abc|] - } - } -}"; + class C + { + IEnumerable P + { + get + { + yield return [|abc|] + } + } + } + """; await TestAsync(markup, "global::System.Int32", mode); } @@ -1259,18 +1397,20 @@ IEnumerable P public async Task TestYieldReturnInPropertySetter(TestMode mode) { var markup = -@"using System.Collections.Generic; - -class C -{ - IEnumerable P - { - set - { - yield return [|abc|] - } - } -}"; + """ + using System.Collections.Generic; + + class C + { + IEnumerable P + { + set + { + yield return [|abc|] + } + } + } + """; await TestAsync(markup, "global::System.Object", mode); } @@ -1285,153 +1425,183 @@ await TestAsync( public async Task TestReturnInSimpleLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func f = s => -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func f = s => + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInParenthesizedLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func f = () => -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func f = () => + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInLambdaWithNullableReturn(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -System.Func f = s => -{ - return [|Goo()|]; -};", "global::System.String?", mode); + """ + #nullable enable + System.Func f = s => + { + return [|Goo()|]; + }; + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInAnonymousMethod(TestMode mode) { await TestInMethodAsync( -@"System.Func f = delegate () -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func f = delegate () + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInAnonymousMethodWithNullableReturn(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -System.Func f = delegate () -{ - return [|Goo()|]; -};", "global::System.String?", mode); + """ + #nullable enable + System.Func f = delegate () + { + return [|Goo()|]; + }; + """, "global::System.String?", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/4486"), CombinatorialData] public async Task TestReturnInAsyncTaskOfTSimpleLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func> f = async s => -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func> f = async s => + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/4486"), CombinatorialData] public async Task TestReturnInAsyncTaskOfTParenthesizedLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func> f = async () => -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func> f = async () => + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/4486"), CombinatorialData] public async Task TestReturnInAsyncTaskOfTAnonymousMethod(TestMode mode) { await TestInMethodAsync( -@"System.Func> f = async delegate () -{ - return [|Goo()|]; -};", "global::System.Int32", mode); + """ + System.Func> f = async delegate () + { + return [|Goo()|]; + }; + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskOfTAnonymousMethodWithNullableReference(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -System.Func> f = async delegate () -{ - return [|Goo()|]; -};", "global::System.String?", mode); + """ + #nullable enable + System.Func> f = async delegate () + { + return [|Goo()|]; + }; + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskSimpleLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func f = async s => -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Func f = async s => + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskParenthesizedLambda(TestMode mode) { await TestInMethodAsync( -@"System.Func f = async () => -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Func f = async () => + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncTaskAnonymousMethod(TestMode mode) { await TestInMethodAsync( -@"System.Func f = async delegate () -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Func f = async delegate () + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncVoidSimpleLambda(TestMode mode) { await TestInMethodAsync( -@"System.Action f = async s => -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Action f = async s => + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncVoidParenthesizedLambda(TestMode mode) { await TestInMethodAsync( -@"System.Action f = async () => -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Action f = async () => + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] public async Task TestReturnInAsyncVoidAnonymousMethod(TestMode mode) { await TestInMethodAsync( -@"System.Action f = async delegate () -{ - return [|Goo()|]; -};", "void", mode); + """ + System.Action f = async delegate () + { + return [|Goo()|]; + }; + """, "void", mode); } [Theory, CombinatorialData] @@ -1467,8 +1637,10 @@ await TestInMethodAsync( public async Task TestAsyncTaskOfTSimpleLambdaWithNullableReturn(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -System.Func> f = async s => [|Goo()|];", "global::System.String?", mode); + """ + #nullable enable + System.Func> f = async s => [|Goo()|]; + """, "global::System.String?", mode); } [Theory, CombinatorialData] @@ -1549,9 +1721,11 @@ public async Task TestDo(TestMode mode) public async Task TestFor1(TestMode mode) { await TestInMethodAsync( -@"for (int i = 0; [|Goo()|]; + """ + for (int i = 0; [|Goo()|]; -i++) { }", "global::System.Boolean", mode); + i++) { } + """, "global::System.Boolean", mode); } [Theory, CombinatorialData] @@ -1566,8 +1740,10 @@ public async Task TestFor3(TestMode mode) public async Task TestForNullableReference(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -for (string? s = [|Goo()|]; ; ) { }", "global::System.String?", mode); + """ + #nullable enable + for (string? s = [|Goo()|]; ; ) { } + """, "global::System.String?", mode); } [Theory, CombinatorialData] @@ -1590,8 +1766,10 @@ public async Task TestForEach(TestMode mode) public async Task TestForEachNullableElements(TestMode mode) { await TestInMethodAsync( -@"#nullable enable -foreach (string? v in [|Goo()|]) { }", "global::System.Collections.Generic.IEnumerable", mode); + """ + #nullable enable + foreach (string? v in [|Goo()|]) { } + """, "global::System.Collections.Generic.IEnumerable", mode); } [Theory, CombinatorialData] @@ -1659,60 +1837,70 @@ await TestInMethodAsync( public async Task TestMethodCall2(TestMode mode) { await TestInClassAsync( -@"void M() -{ - Bar([|Goo()|]); -} + """ + void M() + { + Bar([|Goo()|]); + } -void Bar(int i);", "global::System.Int32", mode); + void Bar(int i); + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestMethodCall3(TestMode mode) { await TestInClassAsync( -@"void M() -{ - Bar([|Goo()|]); -} + """ + void M() + { + Bar([|Goo()|]); + } -void Bar();", "global::System.Object", mode); + void Bar(); + """, "global::System.Object", mode); } [Theory, CombinatorialData] public async Task TestMethodCall4(TestMode mode) { await TestInClassAsync( -@"void M() -{ - Bar([|Goo()|]); -} + """ + void M() + { + Bar([|Goo()|]); + } -void Bar(int i, string s);", "global::System.Int32", mode); + void Bar(int i, string s); + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestMethodCall5(TestMode mode) { await TestInClassAsync( -@"void M() -{ - Bar(s: [|Goo()|]); -} + """ + void M() + { + Bar(s: [|Goo()|]); + } -void Bar(int i, string s);", "global::System.String", mode); + void Bar(int i, string s); + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestMethodCallNullableReference(TestMode mode) { await TestInClassAsync( -@"void M() -{ - Bar([|Goo()|]); -} + """ + void M() + { + Bar([|Goo()|]); + } -void Bar(string? s);", "global::System.String?", mode); + void Bar(string? s); + """, "global::System.String?", mode); } [Theory, CombinatorialData] @@ -1726,159 +1914,181 @@ await TestInMethodAsync( public async Task TestConstructorCall2(TestMode mode) { await TestInClassAsync( -@"void M() -{ - new C([|Goo()|]); -} + """ + void M() + { + new C([|Goo()|]); + } -C(int i) -{ -}", "global::System.Int32", mode); + C(int i) + { + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestConstructorCall3(TestMode mode) { await TestInClassAsync( -@"void M() -{ - new C([|Goo()|]); -} + """ + void M() + { + new C([|Goo()|]); + } -C() -{ -}", "global::System.Object", mode); + C() + { + } + """, "global::System.Object", mode); } [Theory, CombinatorialData] public async Task TestConstructorCall4(TestMode mode) { await TestInClassAsync( -@"void M() -{ - new C([|Goo()|]); -} + """ + void M() + { + new C([|Goo()|]); + } -C(int i, string s) -{ -}", "global::System.Int32", mode); + C(int i, string s) + { + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestConstructorCall5(TestMode mode) { await TestInClassAsync( -@"void M() -{ - new C(s: [|Goo()|]); -} + """ + void M() + { + new C(s: [|Goo()|]); + } -C(int i, string s) -{ -}", "global::System.String", mode); + C(int i, string s) + { + } + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestConstructorCallNullableParameter(TestMode mode) { await TestInClassAsync( -@"#nullable enable + """ + #nullable enable -void M() -{ - new C([|Goo()|]); -} + void M() + { + new C([|Goo()|]); + } -C(string? s) -{ -}", "global::System.String?", mode); + C(string? s) + { + } + """, "global::System.String?", mode); } [Theory, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112"), CombinatorialData] public async Task TestThisConstructorInitializer1(TestMode mode) { await TestAsync( -@"class MyClass -{ - public MyClass(int x) : this([|test|]) - { - } -}", "global::System.Int32", mode); + """ + class MyClass + { + public MyClass(int x) : this([|test|]) + { + } + } + """, "global::System.Int32", mode); } [Theory, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112"), CombinatorialData] public async Task TestThisConstructorInitializer2(TestMode mode) { await TestAsync( -@"class MyClass -{ - public MyClass(int x, string y) : this(5, [|test|]) - { - } -}", "global::System.String", mode); + """ + class MyClass + { + public MyClass(int x, string y) : this(5, [|test|]) + { + } + } + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestThisConstructorInitializerNullableParameter(TestMode mode) { await TestAsync( -@"#nullable enable + """ + #nullable enable -class MyClass -{ - public MyClass(string? y) : this([|test|]) - { - } -}", "global::System.String?", mode); + class MyClass + { + public MyClass(string? y) : this([|test|]) + { + } + } + """, "global::System.String?", mode); } [Theory, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112"), CombinatorialData] public async Task TestBaseConstructorInitializer(TestMode mode) { await TestAsync( -@"class B -{ - public B(int x) - { - } -} + """ + class B + { + public B(int x) + { + } + } -class D : B -{ - public D() : base([|test|]) - { - } -}", "global::System.Int32", mode); + class D : B + { + public D() : base([|test|]) + { + } + } + """, "global::System.Int32", mode); } [Theory, CombinatorialData] public async Task TestBaseConstructorInitializerNullableParameter(TestMode mode) { await TestAsync( -@"#nullable enable + """ + #nullable enable -class B -{ - public B(string? x) - { - } -} + class B + { + public B(string? x) + { + } + } -class D : B -{ - public D() : base([|test|]) - { - } -}", "global::System.String?", mode); + class D : B + { + public D() : base([|test|]) + { + } + } + """, "global::System.String?", mode); } [Theory, CombinatorialData] public async Task TestIndexAccess1(TestMode mode) { await TestInMethodAsync( -@"string[] i; + """ + string[] i; -i[[|Goo()|]];", "global::System.Int32", mode); + i[[|Goo()|]]; + """, "global::System.Int32", mode); } [Theory, CombinatorialData] @@ -1889,51 +2099,59 @@ public async Task TestIndexerCall1(TestMode mode) public async Task TestIndexerCall2(TestMode mode) { await TestInClassAsync( -@"void M() -{ - this[[|Goo()|]]; -} + """ + void M() + { + this[[|Goo()|]]; + } -int this[long i] { get; }", "global::System.Int64", mode); + int this[long i] { get; } + """, "global::System.Int64", mode); } [Theory, CombinatorialData] public async Task TestIndexerCall3(TestMode mode) { await TestInClassAsync( -@"void M() -{ - this[42, [|Goo()|]]; -} + """ + void M() + { + this[42, [|Goo()|]]; + } -int this[int i, string s] { get; }", "global::System.String", mode); + int this[int i, string s] { get; } + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestIndexerCall5(TestMode mode) { await TestInClassAsync( -@"void M() -{ - this[s: [|Goo()|]]; -} + """ + void M() + { + this[s: [|Goo()|]]; + } -int this[int i, string s] { get; }", "global::System.String", mode); + int this[int i, string s] { get; } + """, "global::System.String", mode); } [Theory, CombinatorialData] public async Task TestArrayInitializerInImplicitArrayCreationSimple(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - var a = new[] { 1, [|2|] }; - } -}"; + class C + { + void M() + { + var a = new[] { 1, [|2|] }; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -1942,18 +2160,20 @@ void M() public async Task TestArrayInitializerInImplicitArrayCreation1(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - var a = new[] { Bar(), [|Goo()|] }; - } + class C + { + void M() + { + var a = new[] { Bar(), [|Goo()|] }; + } - int Bar() { return 1; } - int Goo() { return 2; } -}"; + int Bar() { return 1; } + int Goo() { return 2; } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -1962,17 +2182,19 @@ void M() public async Task TestArrayInitializerInImplicitArrayCreation2(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - var a = new[] { Bar(), [|Goo()|] }; - } + class C + { + void M() + { + var a = new[] { Bar(), [|Goo()|] }; + } - int Bar() { return 1; } -}"; + int Bar() { return 1; } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -1981,15 +2203,17 @@ void M() public async Task TestArrayInitializerInImplicitArrayCreation3(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - var a = new[] { Bar(), [|Goo()|] }; - } -}"; + class C + { + void M() + { + var a = new[] { Bar(), [|Goo()|] }; + } + } + """; await TestAsync(text, "global::System.Object", mode); } @@ -1998,19 +2222,21 @@ void M() public async Task TestArrayInitializerInImplicitArrayCreationInferredAsNullable(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -using System.Collections.Generic; + using System.Collections.Generic; -class C -{ - void M() - { - var a = new[] { Bar(), [|Goo()|] }; - } + class C + { + void M() + { + var a = new[] { Bar(), [|Goo()|] }; + } - object? Bar() { return null; } -}"; + object? Bar() { return null; } + } + """; await TestAsync(text, "global::System.Object?", mode); } @@ -2019,15 +2245,17 @@ void M() public async Task TestArrayInitializerInEqualsValueClauseSimple(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - int[] a = { 1, [|2|] }; - } -}"; + class C + { + void M() + { + int[] a = { 1, [|2|] }; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2036,17 +2264,19 @@ void M() public async Task TestArrayInitializerInEqualsValueClause(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - int[] a = { Bar(), [|Goo()|] }; - } + class C + { + void M() + { + int[] a = { Bar(), [|Goo()|] }; + } - int Bar() { return 1; } -}"; + int Bar() { return 1; } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2055,17 +2285,19 @@ void M() public async Task TestArrayInitializerInEqualsValueClauseNullableElement(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -using System.Collections.Generic; + using System.Collections.Generic; -class C -{ - void M() - { - string?[] a = { [|Goo()|] }; - } -}"; + class C + { + void M() + { + string?[] a = { [|Goo()|] }; + } + } + """; await TestAsync(text, "global::System.String?", mode); } @@ -2075,15 +2307,17 @@ void M() public async Task TestCollectionInitializer1(TestMode mode) { var text = -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - new List() { [|Goo()|] }; - } -}"; + class C + { + void M() + { + new List() { [|Goo()|] }; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2092,17 +2326,19 @@ void M() public async Task TestCollectionInitializerNullableElement(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -using System.Collections.Generic; + using System.Collections.Generic; -class C -{ - void M() - { - new List() { [|Goo()|] }; - } -}"; + class C + { + void M() + { + new List() { [|Goo()|] }; + } + } + """; await TestAsync(text, "global::System.String?", mode); } @@ -2112,16 +2348,17 @@ void M() public async Task TestCollectionInitializer2(TestMode mode) { var text = -@" -using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - new Dictionary() { { [|Goo()|], """" } }; - } -}"; + class C + { + void M() + { + new Dictionary() { { [|Goo()|], "" } }; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2131,16 +2368,17 @@ void M() public async Task TestCollectionInitializer3(TestMode mode) { var text = -@" -using System.Collections.Generic; + """ + using System.Collections.Generic; -class C -{ - void M() - { - new Dictionary() { { 0, [|Goo()|] } }; - } -}"; + class C + { + void M() + { + new Dictionary() { { 0, [|Goo()|] } }; + } + } + """; await TestAsync(text, "global::System.String", mode); } @@ -2149,21 +2387,23 @@ void M() public async Task TestCustomCollectionInitializerAddMethod1() { var text = -@"class C : System.Collections.IEnumerable -{ - void M() - { - var x = new C() { [|a|] }; - } - - void Add(int i) { } - void Add(string s, bool b) { } - - public System.Collections.IEnumerator GetEnumerator() - { - throw new System.NotImplementedException(); - } -}"; + """ + class C : System.Collections.IEnumerable + { + void M() + { + var x = new C() { [|a|] }; + } + + void Add(int i) { } + void Add(string s, bool b) { } + + public System.Collections.IEnumerator GetEnumerator() + { + throw new System.NotImplementedException(); + } + } + """; await TestAsync(text, "global::System.Int32", TestMode.Node); } @@ -2173,21 +2413,23 @@ public System.Collections.IEnumerator GetEnumerator() public async Task TestCustomCollectionInitializerAddMethod2(TestMode mode) { var text = -@"class C : System.Collections.IEnumerable -{ - void M() - { - var x = new C() { { ""test"", [|b|] } }; - } - - void Add(int i) { } - void Add(string s, bool b) { } - - public System.Collections.IEnumerator GetEnumerator() - { - throw new System.NotImplementedException(); - } -}"; + """ + class C : System.Collections.IEnumerable + { + void M() + { + var x = new C() { { "test", [|b|] } }; + } + + void Add(int i) { } + void Add(string s, bool b) { } + + public System.Collections.IEnumerator GetEnumerator() + { + throw new System.NotImplementedException(); + } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -2197,21 +2439,23 @@ public System.Collections.IEnumerator GetEnumerator() public async Task TestCustomCollectionInitializerAddMethod3(TestMode mode) { var text = -@"class C : System.Collections.IEnumerable -{ - void M() - { - var x = new C() { { [|s|], true } }; - } - - void Add(int i) { } - void Add(string s, bool b) { } - - public System.Collections.IEnumerator GetEnumerator() - { - throw new System.NotImplementedException(); - } -}"; + """ + class C : System.Collections.IEnumerable + { + void M() + { + var x = new C() { { [|s|], true } }; + } + + void Add(int i) { } + void Add(string s, bool b) { } + + public System.Collections.IEnumerator GetEnumerator() + { + throw new System.NotImplementedException(); + } + } + """; await TestAsync(text, "global::System.String", mode); } @@ -2220,21 +2464,23 @@ public System.Collections.IEnumerator GetEnumerator() public async Task TestCustomCollectionInitializerAddMethodWithNullableParameter(TestMode mode) { var text = -@"class C : System.Collections.IEnumerable -{ - void M() - { - var x = new C() { { ""test"", [|s|] } }; - } - - void Add(int i) { } - void Add(string s, string? s2) { } - - public System.Collections.IEnumerator GetEnumerator() - { - throw new System.NotImplementedException(); - } -}"; + """ + class C : System.Collections.IEnumerable + { + void M() + { + var x = new C() { { "test", [|s|] } }; + } + + void Add(int i) { } + void Add(string s, string? s2) { } + + public System.Collections.IEnumerator GetEnumerator() + { + throw new System.NotImplementedException(); + } + } + """; await TestAsync(text, "global::System.String?", mode); } @@ -2243,14 +2489,15 @@ public System.Collections.IEnumerator GetEnumerator() public async Task TestArrayInference1() { var text = -@" -class A -{ - void Goo() - { - A[] x = new [|C|][] { }; - } -}"; + """ + class A + { + void Goo() + { + A[] x = new [|C|][] { }; + } + } + """; await TestAsync(text, "global::A", TestMode.Node); } @@ -2259,14 +2506,15 @@ void Goo() public async Task TestArrayInference1_Position() { var text = -@" -class A -{ - void Goo() - { - A[] x = new [|C|][] { }; - } -}"; + """ + class A + { + void Goo() + { + A[] x = new [|C|][] { }; + } + } + """; await TestAsync(text, "global::A[]", TestMode.Position); } @@ -2275,14 +2523,15 @@ void Goo() public async Task TestArrayInference2() { var text = -@" -class A -{ - void Goo() - { - A[][] x = new [|C|][][] { }; - } -}"; + """ + class A + { + void Goo() + { + A[][] x = new [|C|][][] { }; + } + } + """; await TestAsync(text, "global::A", TestMode.Node); } @@ -2291,14 +2540,15 @@ void Goo() public async Task TestArrayInference2_Position() { var text = -@" -class A -{ - void Goo() - { - A[][] x = new [|C|][][] { }; - } -}"; + """ + class A + { + void Goo() + { + A[][] x = new [|C|][][] { }; + } + } + """; await TestAsync(text, "global::A[][]", TestMode.Position); } @@ -2307,30 +2557,32 @@ void Goo() public async Task TestArrayInference3() { var text = -@" -class A -{ - void Goo() - { - A[][] x = new [|C|][] { }; - } -}"; + """ + class A + { + void Goo() + { + A[][] x = new [|C|][] { }; + } + } + """; await TestAsync(text, "global::A[]", TestMode.Node); } [Fact] public async Task TestArrayInference3_Position() - { - var text = -@" -class A -{ - void Goo() - { - A[][] x = new [|C|][] { }; - } -}"; + { + var text = + """ + class A + { + void Goo() + { + A[][] x = new [|C|][] { }; + } + } + """; await TestAsync(text, "global::A[][]", TestMode.Position); } @@ -2339,15 +2591,16 @@ void Goo() public async Task TestArrayInference4(TestMode mode) { var text = -@" -using System; -class A -{ - void Goo() - { - Func[] x = new Func[] { [|Bar()|] }; - } -}"; + """ + using System; + class A + { + void Goo() + { + Func[] x = new Func[] { [|Bar()|] }; + } + } + """; await TestAsync(text, "global::System.Func", mode); } @@ -2357,14 +2610,16 @@ void Goo() public async Task TestInsideLambda2(TestMode mode) { var text = -@"using System; -class C -{ - void M() - { - Func f = i => [|here|] - } -}"; + """ + using System; + class C + { + void M() + { + Func f = i => [|here|] + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2373,16 +2628,18 @@ void M() public async Task TestInsideLambdaNullableReturn(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -using System; -class C -{ - void M() - { - Func f = i => [|here|] - } -}"; + using System; + class C + { + void M() + { + Func f = i => [|here|] + } + } + """; await TestAsync(text, "global::System.String?", mode); } @@ -2392,13 +2649,15 @@ void M() public async Task TestPointer1(TestMode mode) { var text = -@"class C -{ - void M(int* i) - { - var q = i[[|Goo()|]]; - } -}"; + """ + class C + { + void M(int* i) + { + var q = i[[|Goo()|]]; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2408,13 +2667,15 @@ void M(int* i) public async Task TestDynamic1(TestMode mode) { var text = -@"class C -{ - void M(dynamic i) - { - var q = i[[|Goo()|]]; - } -}"; + """ + class C + { + void M(dynamic i) + { + var q = i[[|Goo()|]]; + } + } + """; await TestAsync(text, "global::System.Int32", mode); } @@ -2423,13 +2684,15 @@ void M(dynamic i) public async Task TestChecked1(TestMode mode) { var text = -@"class C -{ - void M() - { - string q = checked([|Goo()|]); - } -}"; + """ + class C + { + void M() + { + string q = checked([|Goo()|]); + } + } + """; await TestAsync(text, "global::System.String", mode); } @@ -2439,14 +2702,16 @@ void M() public async Task TestAwaitTaskOfT(TestMode mode) { var text = -@"using System.Threading.Tasks; -class C -{ - void M() - { - int x = await [|Goo()|]; - } -}"; + """ + using System.Threading.Tasks; + class C + { + void M() + { + int x = await [|Goo()|]; + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", mode); } @@ -2455,16 +2720,18 @@ void M() public async Task TestAwaitTaskOfTNullableValue(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -using System.Threading.Tasks; -class C -{ - void M() - { - string? x = await [|Goo()|]; - } -}"; + using System.Threading.Tasks; + class C + { + void M() + { + string? x = await [|Goo()|]; + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", mode); } @@ -2474,14 +2741,16 @@ void M() public async Task TestAwaitTaskOfTaskOfT(TestMode mode) { var text = -@"using System.Threading.Tasks; -class C -{ - void M() - { - Task x = await [|Goo()|]; - } -}"; + """ + using System.Threading.Tasks; + class C + { + void M() + { + Task x = await [|Goo()|]; + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task>", mode); } @@ -2491,14 +2760,16 @@ void M() public async Task TestAwaitTask(TestMode mode) { var text = -@"using System.Threading.Tasks; -class C -{ - void M() - { - await [|Goo()|]; - } -}"; + """ + using System.Threading.Tasks; + class C + { + void M() + { + await [|Goo()|]; + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", mode); } @@ -2508,15 +2779,17 @@ void M() public async Task TestLockStatement(TestMode mode) { var text = -@"class C -{ - void M() - { - lock([|Goo()|]) - { - } - } -}"; + """ + class C + { + void M() + { + lock([|Goo()|]) + { + } + } + } + """; await TestAsync(text, "global::System.Object", mode); } @@ -2526,15 +2799,17 @@ void M() public async Task TestAwaitExpressionInLockStatement(TestMode mode) { var text = -@"class C -{ - async void M() - { - lock(await [|Goo()|]) - { - } - } -}"; + """ + class C + { + async void M() + { + lock(await [|Goo()|]) + { + } + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", mode); } @@ -2544,15 +2819,17 @@ async void M() public async Task TestReturnFromAsyncTaskOfT(TestMode mode) { var markup = -@"using System.Threading.Tasks; -class Program -{ - async Task M() - { - await Task.Delay(1); - return [|ab|] - } -}"; + """ + using System.Threading.Tasks; + class Program + { + async Task M() + { + await Task.Delay(1); + return [|ab|] + } + } + """; await TestAsync(markup, "global::System.Int32", mode); } @@ -2561,17 +2838,19 @@ async Task M() public async Task TestAttributeArguments1(TestMode mode) { var markup = -@"[A([|dd|], ee, Y = ff)] -class AAttribute : System.Attribute -{ - public int X; - public string Y; + """ + [A([|dd|], ee, Y = ff)] + class AAttribute : System.Attribute + { + public int X; + public string Y; - public AAttribute(System.DayOfWeek a, double b) - { + public AAttribute(System.DayOfWeek a, double b) + { - } -}"; + } + } + """; await TestAsync(markup, "global::System.DayOfWeek", mode); } @@ -2580,17 +2859,19 @@ public AAttribute(System.DayOfWeek a, double b) public async Task TestAttributeArguments2(TestMode mode) { var markup = -@"[A(dd, [|ee|], Y = ff)] -class AAttribute : System.Attribute -{ - public int X; - public string Y; + """ + [A(dd, [|ee|], Y = ff)] + class AAttribute : System.Attribute + { + public int X; + public string Y; - public AAttribute(System.DayOfWeek a, double b) - { + public AAttribute(System.DayOfWeek a, double b) + { - } -}"; + } + } + """; await TestAsync(markup, "global::System.Double", mode); } @@ -2599,17 +2880,19 @@ public AAttribute(System.DayOfWeek a, double b) public async Task TestAttributeArguments3(TestMode mode) { var markup = -@"[A(dd, ee, Y = [|ff|])] -class AAttribute : System.Attribute -{ - public int X; - public string Y; + """ + [A(dd, ee, Y = [|ff|])] + class AAttribute : System.Attribute + { + public int X; + public string Y; - public AAttribute(System.DayOfWeek a, double b) - { + public AAttribute(System.DayOfWeek a, double b) + { - } -}"; + } + } + """; await TestAsync(markup, "global::System.String", mode); } @@ -2618,21 +2901,23 @@ public AAttribute(System.DayOfWeek a, double b) public async Task TestReturnStatementWithinDelegateWithinAMethodCall(TestMode mode) { var text = -@"using System; + """ + using System; -class Program -{ - delegate string A(int i); + class Program + { + delegate string A(int i); - static void Main(string[] args) - { - B(delegate(int i) { return [|M()|]; }); - } + static void Main(string[] args) + { + B(delegate(int i) { return [|M()|]; }); + } - private static void B(A a) - { - } -}"; + private static void B(A a) + { + } + } + """; await TestAsync(text, "global::System.String", mode); } @@ -2642,11 +2927,12 @@ private static void B(A a) public async Task TestCatchFilterClause(TestMode mode) { var text = -@" -try -{ } -catch (Exception) if ([|M()|]) -}"; + """ + try + { } + catch (Exception) if ([|M()|]) + } + """; await TestInMethodAsync(text, "global::System.Boolean", mode); } @@ -2655,11 +2941,12 @@ public async Task TestCatchFilterClause(TestMode mode) public async Task TestCatchFilterClause1(TestMode mode) { var text = -@" -try -{ } -catch (Exception) if ([|M|]) -}"; + """ + try + { } + catch (Exception) if ([|M|]) + } + """; await TestInMethodAsync(text, "global::System.Boolean", mode); } @@ -2667,11 +2954,12 @@ public async Task TestCatchFilterClause1(TestMode mode) public async Task TestCatchFilterClause2() { var text = -@" -try -{ } -catch (Exception) if ([|M|].N) -}"; + """ + try + { } + catch (Exception) if ([|M|].N) + } + """; await TestInMethodAsync(text, "global::System.Object", TestMode.Node); } @@ -2679,16 +2967,18 @@ public async Task TestCatchFilterClause2() public async Task TestAwaitExpressionWithChainingMethod() { var text = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class C -{ - static async void T() - { - bool x = await [|M()|].ConfigureAwait(false); - } -}"; + class C + { + static async void T() + { + bool x = await [|M()|].ConfigureAwait(false); + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", TestMode.Node); } @@ -2696,16 +2986,18 @@ static async void T() public async Task TestAwaitExpressionWithChainingMethod2() { var text = -@"using System; -using System.Threading.Tasks; + """ + using System; + using System.Threading.Tasks; -class C -{ - static async void T() - { - bool x = await [|M|].ContinueWith(a => { return true; }).ContinueWith(a => { return false; }); - } -}"; + class C + { + static async void T() + { + bool x = await [|M|].ContinueWith(a => { return true; }).ContinueWith(a => { return false; }); + } + } + """; await TestAsync(text, "global::System.Threading.Tasks.Task", TestMode.Node); } @@ -2713,17 +3005,19 @@ static async void T() public async Task TestAwaitExpressionWithGenericMethod1() { var text = -@"using System.Threading.Tasks; + """ + using System.Threading.Tasks; -public class C -{ - private async void M() - { - bool merged = await X([|Test()|]); - } + public class C + { + private async void M() + { + bool merged = await X([|Test()|]); + } - private async Task X(T t) { return t; } -}"; + private async Task X(T t) { return t; } + } + """; await TestAsync(text, "global::System.Boolean", TestMode.Node); } @@ -2732,17 +3026,19 @@ private async void M() public async Task TestAwaitExpressionWithGenericMethod2(TestMode mode) { var text = -@"using System.Threading.Tasks; + """ + using System.Threading.Tasks; -public class C -{ - private async void M() - { - bool merged = await Task.Run(() => [|Test()|]);; - } + public class C + { + private async void M() + { + bool merged = await Task.Run(() => [|Test()|]);; + } - private async Task X(T t) { return t; } -}"; + private async Task X(T t) { return t; } + } + """; await TestAsync(text, "global::System.Boolean", mode); } @@ -2751,13 +3047,15 @@ private async void M() public async Task TestNullCoalescingOperator1(TestMode mode) { var text = - @"class C -{ - void M() + """ + class C { - object z = [|a|] ?? null; + void M() + { + object z = [|a|] ?? null; + } } -}"; + """; // In position mode, we are inferring that the thing to the right is an object, because it's being assigned to a local of type object. // In node mode, we are inferring the node is an object? because it's to the left of the ??. await TestAsync(text, mode == TestMode.Node ? "global::System.Object?" : "global::System.Object", mode); @@ -2768,13 +3066,15 @@ void M() public async Task TestNullCoalescingOperator2(TestMode mode) { var text = - @"class C -{ - void M() + """ + class C { - object z = [|a|] ?? b ?? c; + void M() + { + object z = [|a|] ?? b ?? c; + } } -}"; + """; // In position mode, we are inferring that the thing to the right is an object, because it's being assigned to a local of type object. // In node mode, we are inferring the node is an object? because it's to the left of the ??. await TestAsync(text, mode == TestMode.Node ? "global::System.Object?" : "global::System.Object", mode); @@ -2785,13 +3085,15 @@ void M() public async Task TestNullCoalescingOperator3(TestMode mode) { var text = - @"class C -{ - void M() + """ + class C { - object z = a ?? [|b|] ?? c; + void M() + { + object z = a ?? [|b|] ?? c; + } } -}"; + """; // In position mode, we are inferring that the thing to the right is an object, because it's to the right of the first ?? // and thus must be the same type as the object being assigned to. // In node mode, we are inferring the node is an object? because it's to the left of the ??. @@ -2802,16 +3104,18 @@ void M() public async Task TestSelectLambda() { var text = - @"using System.Collections.Generic; -using System.Linq; + """ + using System.Collections.Generic; + using System.Linq; -class C -{ - void M(IEnumerable args) + class C { - args = args.Select(a =>[||]) + void M(IEnumerable args) + { + args = args.Select(a =>[||]) + } } -}"; + """; await TestAsync(text, "global::System.Object", TestMode.Node); } @@ -2819,16 +3123,18 @@ void M(IEnumerable args) public async Task TestSelectLambda2() { var text = - @"using System.Collections.Generic; -using System.Linq; + """ + using System.Collections.Generic; + using System.Linq; -class C -{ - void M(IEnumerable args) + class C { - args = args.Select(a =>[|b|]) + void M(IEnumerable args) + { + args = args.Select(a =>[|b|]) + } } -}"; + """; await TestAsync(text, "global::System.String", TestMode.Node); } @@ -2837,18 +3143,20 @@ void M(IEnumerable args) public async Task TestSelectLambda3(TestMode mode) { var text = -@"using System.Collections.Generic; -using System.Linq; + """ + using System.Collections.Generic; + using System.Linq; -class A { } -class B { } -class C -{ - IEnumerable GetB(IEnumerable a) - { - return a.Select(i => [|Goo(i)|]); - } -}"; + class A { } + class B { } + class C + { + IEnumerable GetB(IEnumerable a) + { + return a.Select(i => [|Goo(i)|]); + } + } + """; await TestAsync(text, "global::B", mode); } @@ -2856,13 +3164,15 @@ IEnumerable GetB(IEnumerable a) public async Task TestDefaultStatement1() { var text = - @"class C -{ - static void Main(string[] args) + """ + class C { - System.ConsoleModifiers c = default([||]) + static void Main(string[] args) + { + System.ConsoleModifiers c = default([||]) + } } -}"; + """; await TestAsync(text, "global::System.ConsoleModifiers", TestMode.Position); } @@ -2870,13 +3180,15 @@ static void Main(string[] args) public async Task TestDefaultStatement2() { var text = - @"class C -{ - static void Goo(System.ConsoleModifiers arg) + """ + class C { - Goo(default([||]) + static void Goo(System.ConsoleModifiers arg) + { + Goo(default([||]) + } } -}"; + """; await TestAsync(text, "global::System.ConsoleModifiers", TestMode.Position); } @@ -2884,15 +3196,16 @@ static void Goo(System.ConsoleModifiers arg) public async Task TestWhereCall() { var text = - @" -using System.Collections.Generic; -class C -{ - void Goo() + """ + using System.Collections.Generic; + class C { - [|ints|].Where(i => i > 10); + void Goo() + { + [|ints|].Where(i => i > 10); + } } -}"; + """; await TestAsync(text, "global::System.Collections.Generic.IEnumerable", TestMode.Node); } @@ -2900,15 +3213,16 @@ void Goo() public async Task TestWhereCall2() { var text = - @" -using System.Collections.Generic; -class C -{ - void Goo() + """ + using System.Collections.Generic; + class C { - [|ints|].Where(i => null); + void Goo() + { + [|ints|].Where(i => null); + } } -}"; + """; await TestAsync(text, "global::System.Collections.Generic.IEnumerable", TestMode.Node); } @@ -2916,16 +3230,18 @@ void Goo() public async Task TestObjectCreationBeforeArrayIndexing() { var text = -@"using System; -class C -{ - void M() - { - int[] array; - C p = new [||] - array[4] = 4; - } -}"; + """ + using System; + class C + { + void M() + { + int[] array; + C p = new [||] + array[4] = 4; + } + } + """; await TestAsync(text, "global::C", TestMode.Position); } @@ -2957,14 +3273,16 @@ await TestInMethodAsync( public async Task TestObjectCreationBeforeBlock() { var text = -@"class Program -{ - static void Main(string[] args) - { - Program p = new [||] - { } - } -}"; + """ + class Program + { + static void Main(string[] args) + { + Program p = new [||] + { } + } + } + """; await TestAsync(text, "global::Program", TestMode.Position); } @@ -2973,17 +3291,19 @@ static void Main(string[] args) public async Task TestInferringThroughGenericFunctionWithNullableReturn(TestMode mode) { var text = -@"#nullable enable + """ + #nullable enable -class Program -{ - static void Main(string[] args) - { - string? s = Identity([|input|]); - } + class Program + { + static void Main(string[] args) + { + string? s = Identity([|input|]); + } - static T Identity(T value) { return value; } -}"; + static T Identity(T value) { return value; } + } + """; await TestAsync(text, "global::System.String?", mode); } @@ -2992,15 +3312,17 @@ static void Main(string[] args) public async Task TestInferringThroughGenericFunctionMissingArgument() { var text = -@"class Program -{ - static void Main(string[] args) - { - string s = Identity([||]); - } + """ + class Program + { + static void Main(string[] args) + { + string s = Identity([||]); + } - static T Identity(T value) { return value; } -}"; + static T Identity(T value) { return value; } + } + """; await TestAsync(text, "global::System.String", TestMode.Position); } @@ -3009,15 +3331,17 @@ static void Main(string[] args) public async Task TestInferringThroughGenericFunctionTooManyArguments(TestMode mode) { var text = -@"class Program -{ - static void Main(string[] args) - { - string s = Identity(""test"", [||]); - } + """ + class Program + { + static void Main(string[] args) + { + string s = Identity("test", [||]); + } - static T Identity(T value) { return value; } -}"; + static T Identity(T value) { return value; } + } + """; await TestAsync(text, "global::System.Object", mode); } @@ -3047,16 +3371,18 @@ await TestInMethodAsync( public async Task TestInferringInEnumHasFlags(TestMode mode) { var text = -@"using System.IO; + """ + using System.IO; -class Program -{ - static void Main(string[] args) - { - FileInfo f; - f.Attributes.HasFlag([|flag|]); - } -}"; + class Program + { + static void Main(string[] args) + { + FileInfo f; + f.Attributes.HasFlag([|flag|]); + } + } + """; await TestAsync(text, "global::System.IO.FileAttributes", mode); } @@ -3131,102 +3457,102 @@ public void M() [Fact] public async Task TestEnumInPatterns_SwitchStatement_PropertyPattern() { - var markup = @" -public enum Color -{ - Red, - Green, -} - -class C -{ - public Color Color { get; } + var markup = """ + public enum Color + { + Red, + Green, + } - public void M() - { - switch (this) - { - case { Color: [||] - } -} -"; + class C + { + public Color Color { get; } + + public void M() + { + switch (this) + { + case { Color: [||] + } + } + """; await TestAsync(markup, "global::Color", TestMode.Position); } [Fact] public async Task TestEnumInPatterns_SwitchExpression_PropertyPattern() { - var markup = @" -public enum Color -{ - Red, - Green, -} - -class C -{ - public Color Color { get; } + var markup = """ + public enum Color + { + Red, + Green, + } - public void M() - { - var isRed = this switch - { - { Color: [||] - } -} -"; + class C + { + public Color Color { get; } + + public void M() + { + var isRed = this switch + { + { Color: [||] + } + } + """; await TestAsync(markup, "global::Color", TestMode.Position); } [Fact] public async Task TestEnumInPatterns_SwitchStatement_ExtendedPropertyPattern() { - var markup = @" -public enum Color -{ - Red, - Green, -} - -class C -{ - public C AnotherC { get; } - public Color Color { get; } + var markup = """ + public enum Color + { + Red, + Green, + } - public void M() - { - switch (this) - { - case { AnotherC.Color: [||] - } -} -"; + class C + { + public C AnotherC { get; } + public Color Color { get; } + + public void M() + { + switch (this) + { + case { AnotherC.Color: [||] + } + } + """; await TestAsync(markup, "global::Color", TestMode.Position); } [Fact] public async Task TestEnumInPatterns_SwitchStatement_ExtendedPropertyPattern_Field() { - var markup = @" -public enum Color -{ - Red, - Green, -} - -class C -{ - public C AnotherC { get; } - public Color Color; + var markup = """ + public enum Color + { + Red, + Green, + } - public void M() - { - switch (this) - { - case { AnotherC.Color: [||] - } -} -"; + class C + { + public C AnotherC { get; } + public Color Color; + + public void M() + { + switch (this) + { + case { AnotherC.Color: [||] + } + } + """; await TestAsync(markup, "global::Color", TestMode.Position); } } diff --git a/src/EditorFeatures/CSharpTest/Workspaces/WorkspaceTests_EditorFeatures.cs b/src/EditorFeatures/CSharpTest/Workspaces/WorkspaceTests_EditorFeatures.cs index 68cc8f692a267..676bde4fbdea4 100644 --- a/src/EditorFeatures/CSharpTest/Workspaces/WorkspaceTests_EditorFeatures.cs +++ b/src/EditorFeatures/CSharpTest/Workspaces/WorkspaceTests_EditorFeatures.cs @@ -158,11 +158,13 @@ public async Task TestChangeOptions1() var solution = workspace.CurrentSolution; var document = new TestHostDocument( -@"#if GOO -class C { } -#else -class D { } -#endif"); + """ + #if GOO + class C { } + #else + class D { } + #endif + """); var project1 = new TestHostProject(workspace, document, name: "project1"); @@ -183,11 +185,13 @@ public async Task TestChangeOptions2() var solution = workspace.CurrentSolution; var document = new TestHostDocument( -@"#if GOO -class C { } -#else -class D { } -#endif"); + """ + #if GOO + class C { } + #else + class D { } + #endif + """); var project1 = new TestHostProject(workspace, document, name: "project1"); @@ -445,7 +449,11 @@ public async Task TestGetCompilationOnCrossLanguageDependentProject() var document1 = new TestHostDocument(@"public class C { }"); var project1 = new TestHostProject(workspace, document1, name: "project1"); - var document2 = new TestHostDocument("Public Class D \r\n Inherits C\r\nEnd Class"); + var document2 = new TestHostDocument(""" + Public Class D + Inherits C + End Class + """); var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 }); workspace.AddTestProject(project1); @@ -469,7 +477,11 @@ public async Task TestGetCompilationOnCrossLanguageDependentProjectChanged() var document1 = new TestHostDocument(@"public class C { }"); var project1 = new TestHostProject(workspace, document1, name: "project1"); - var document2 = new TestHostDocument("Public Class D \r\n Inherits C\r\nEnd Class"); + var document2 = new TestHostDocument(""" + Public Class D + Inherits C + End Class + """); var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 }); workspace.AddTestProject(project1); @@ -514,7 +526,11 @@ public async Task TestDependentSemanticVersionChangesWhenNotOriginallyAccessed() var document1 = new TestHostDocument(@"public class C { }"); var project1 = new TestHostProject(workspace, document1, name: "project1"); - var document2 = new TestHostDocument("Public Class D \r\n Inherits C\r\nEnd Class"); + var document2 = new TestHostDocument(""" + Public Class D + Inherits C + End Class + """); var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 }); workspace.AddTestProject(project1); @@ -571,7 +587,11 @@ public async Task TestGetCompilationOnCrossLanguageDependentProjectChangedInProg var document1 = new TestHostDocument(@"public class C { }"); var project1 = new TestHostProject(workspace, document1, name: "project1"); - var document2 = new TestHostDocument("Public Class D \r\n Inherits C\r\nEnd Class"); + var document2 = new TestHostDocument(""" + Public Class D + Inherits C + End Class + """); var project2 = new TestHostProject(workspace, document2, language: LanguageNames.VisualBasic, name: "project2", projectReferences: new[] { project1 }); workspace.AddTestProject(project1); @@ -1052,8 +1072,12 @@ public async Task TestAnalyzerConfigFile_Properties() public async Task TestAdditionalFile_DocumentChanged() { using var workspace = CreateWorkspace(); - var startText = @" ToString(formatProvider); - public static string Invariant(FormattableString formattable) => formattable.ToString(Globalization.CultureInfo.InvariantCulture); - public override string ToString() => ToString(Globalization.CultureInfo.CurrentCulture); - } -} + string IFormattable.ToString(string ignored, IFormatProvider formatProvider) => ToString(formatProvider); + public static string Invariant(FormattableString formattable) => formattable.ToString(Globalization.CultureInfo.InvariantCulture); + public override string ToString() => ToString(Globalization.CultureInfo.CurrentCulture); + } + } -namespace System.Runtime.CompilerServices -{ - public static class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] arguments) => new ConcreteFormattableString(format, arguments); + namespace System.Runtime.CompilerServices + { + public static class FormattableStringFactory + { + public static FormattableString Create(string format, params object[] arguments) => new ConcreteFormattableString(format, arguments); - private sealed class ConcreteFormattableString : FormattableString - { - private readonly string _format; - private readonly object[] _arguments; + private sealed class ConcreteFormattableString : FormattableString + { + private readonly string _format; + private readonly object[] _arguments; - internal ConcreteFormattableString(string format, object[] arguments) - { - _format = format; - _arguments = arguments; - } + internal ConcreteFormattableString(string format, object[] arguments) + { + _format = format; + _arguments = arguments; + } - public override string Format => _format; - public override object[] GetArguments() => _arguments; - public override int ArgumentCount => _arguments.Length; - public override object GetArgument(int index) => _arguments[index]; - public override string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _format, _arguments); - } - } -} -"; + public override string Format => _format; + public override object[] GetArguments() => _arguments; + public override int ArgumentCount => _arguments.Length; + public override object GetArgument(int index) => _arguments[index]; + public override string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _format, _arguments); + } + } + } + """; } }