From 1395a762ee6d300e4d8583d8c86e3205d48d5334 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Tue, 31 Jan 2017 11:53:03 -0800 Subject: [PATCH] Adding some refactoring tests with tuples (#16663) --- .../GenerateType/GenerateTypeTests.cs | 50 +++++++++++++++++++ .../ImplementAbstractClassTests.cs | 29 +++++++++++ .../ImplementInterfaceTests.cs | 28 +++++++++++ .../GenerateType/GenerateTypeTests.vb | 40 +++++++++++++++ .../ImplementAbstractClassTests.vb | 21 ++++++++ .../ImplementInterfaceTests.vb | 22 ++++++++ 6 files changed, 190 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs index 9aa5c0e86e5..731042e21eb 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs @@ -267,6 +267,56 @@ public Foo() index: 2); } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)] + public async Task TestGenerateClassWithCtorFromObjectCreationWithTuple() + { + await TestAsync( +@"class Class +{ + var f = new [|Generated|]((1, 2)); +}", +@"class Class +{ + var f = new Generated((1, 2)); + + private class Generated + { + private (int, int) p; + + public Generated((int, int) p) + { + this.p = p; + } + } +}", +index: 2); + } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)] + public async Task TestGenerateClassWithCtorFromObjectCreationWithTupleWithNames() + { + await TestAsync( +@"class Class +{ + var f = new [|Generated|]((a: 1, b: 2, 3)); +}", +@"class Class +{ + var f = new Generated((a: 1, b: 2, 3)); + + private class Generated + { + private (int a, int b, int) p; + + public Generated((int a, int b, int) p) + { + this.p = p; + } + } +}", +index: 2); + } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)] public async Task TestGenerateClassFromBaseList() { diff --git a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs index f43d08fc8bf..fd65ae3ca7d 100644 --- a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs @@ -105,6 +105,35 @@ protected override string FooMethod() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementAbstractClass)] + [WorkItem(16434, "https://github.com/dotnet/roslyn/issues/16434")] + public async Task TestMethodWithTupleNames() + { + await TestAllOptionsOffAsync( +@"abstract class Base +{ + protected abstract (int a, int b) Method((string, string d) x); +} + +class [|Program|] : Base +{ +}", +@"using System; + +abstract class Base +{ + protected abstract (int a, int b) Method((string, string d) x); +} + +class Program : Base +{ + protected override (int a, int b) Method((string, string d) x) + { + throw new NotImplementedException(); + } +}"); + } + [WorkItem(543234, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543234")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementAbstractClass)] public async Task TestNotAvailableForStruct() diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index 27389625274..b710d390741 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -113,6 +113,34 @@ public void Method1() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] + public async Task TestMethodWithTuple() + { + await TestWithAllCodeStyleOptionsOffAsync( +@"interface IInterface +{ + (int, int) Method((string, string) x); +} + +class Class : [|IInterface|] +{ +}", +@"using System; + +interface IInterface +{ + (int, int) Method((string, string) x); +} + +class Class : IInterface +{ + public (int, int) Method((string, string) x) + { + throw new NotImplementedException(); + } +}"); + } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestExpressionBodiedMethod1() { diff --git a/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb b/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb index 70b71fbdb51..6cd7172afd6 100644 --- a/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb @@ -124,6 +124,46 @@ End Class", index:=2) End Function + + Public Async Function TestGenerateClassWithCtorFromObjectCreationWithTuple() As Task + Await TestAsync( +"Class C + Dim f = New [|Generated|]((1, 2)) +End Class", +"Class C + Dim f = New Generated((1, 2)) + + Private Class Generated + Private p As (Integer, Integer) + + Public Sub New(p As (Integer, Integer)) + Me.p = p + End Sub + End Class +End Class", +index:=2) + End Function + + + Public Async Function TestGenerateClassWithCtorFromObjectCreationWithTupleWithNames() As Task + Await TestAsync( +"Class C + Dim f = New [|Generated|]((a:=1, b:=2, 3)) +End Class", +"Class C + Dim f = New Generated((a:=1, b:=2, 3)) + + Private Class Generated + Private p As (a As Integer, b As Integer, Integer) + + Public Sub New(p As (a As Integer, b As Integer, Integer)) + Me.p = p + End Sub + End Class +End Class", +index:=2) + End Function + Public Async Function TestCreateException() As Task Await TestAsync( diff --git a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb index 4ed3f721fd2..a755538919d 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb @@ -39,6 +39,27 @@ Public Class Bar End Class") End Function + + Public Async Function TestMethodWithTupleNames() As Task + Await TestAsync( +"Public MustInherit Class Base + Protected MustOverride Function Bar(x As (a As Integer, Integer)) As (c As Integer, Integer) +End Class +Public Class [|Derived|] + Inherits Base +End Class", +"Imports System +Public MustInherit Class Base + Protected MustOverride Function Bar(x As (a As Integer, Integer)) As (c As Integer, Integer) +End Class +Public Class Derived + Inherits Base + Protected Overrides Function Bar(x As (a As Integer, Integer)) As (c As Integer, Integer) + Throw New NotImplementedException() + End Function +End Class") + End Function + Public Async Function TestOptionalIntParameter() As Task Await TestAsync( diff --git a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb index 8bcbf4e9a71..08045d898c4 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb @@ -35,6 +35,28 @@ Class C End Class") End Function + + Public Async Function TestInterfaceWithTuple() As Task + Await TestAsync( +"Imports System +Class Foo + Implements [|IFoo|] +End Class +Interface IFoo + Function Method(x As (Alice As Integer, Bob As Integer)) As (String, String) +End Interface", +"Imports System +Class Foo + Implements IFoo + Public Function Method(x As (Alice As Integer, Bob As Integer)) As (String, String) Implements IFoo.Method + Throw New NotImplementedException() + End Function +End Class +Interface IFoo + Function Method(x As (Alice As Integer, Bob As Integer)) As (String, String) +End Interface") + End Function + Public Async Function TestMethodConflict1() As Task Await TestAsync( -- GitLab