From b203acd46278dc22d3c87f6643660044bf1acb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Wed, 3 Jul 2019 17:01:03 -0700 Subject: [PATCH] More RefactoringHelpers tests (mostly for extraction). --- .../RefactoringHelpersTests.cs | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs b/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs index 30f3f6ca4bc..7b74f0edd1a 100644 --- a/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs +++ b/src/EditorFeatures/CSharpTest/RefactoringHelpers/RefactoringHelpersTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using ICSharpCode.Decompiler.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.UnitTests.RefactoringHelpers; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; @@ -296,6 +297,60 @@ C LocalFunction(C c) await TestMissingAsync(testText); } + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestMissingSelectedLowerNode() + { + var testText = @" +class C +{ + void M() + { + [|C|] LocalFunction(C c) + { + return null; + } + } +}"; + await TestMissingAsync(testText); + } + + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestMissingSelectedWhitespace() + { + var testText = @" +class C +{ + void M() + { + C[| |]LocalFunction(C c) + { + return null; + } + } +}"; + await TestMissingAsync(testText); + } + + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestMissingSelectedWhitespace2() + { + var testText = @" +class C +{ + void M() + { + [| |]C LocalFunction(C c) + { + return null; + } + } +}"; + await TestMissingAsync(testText); + } + [Fact] [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] public async Task TestCompleteSelection() @@ -580,7 +635,116 @@ class Test2Attribute : Attribute { } #endregion + #region Extractions general + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestExtractionsClimbing() + { + var testText = @" +using System; +class C +{ + void M() + { + var a = {|result:new object()|};[||] + } +}"; + await TestAsync(testText); + } + + [Fact] + [WorkItem(35525, "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; } +}"; + await TestMissingAsync(testText); + } + #endregion + #region Extractions + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestExtractFromDeclaration() + { + var testText = @" +using System; +class C +{ + void M() + { + [|var a = {|result:new object()|};|] + } +}"; + await TestAsync(testText); + } + + [Fact] + [WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")] + public async Task TestExtractFromDeclaration2() + { + var testText = @" +using System; +class C +{ + void M() + { + var a = [|{|result:new object()|};|] + } +}"; + await TestAsync(testText); + } + + [Fact] + [WorkItem(35525, "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()|};|] + } +}"; + await TestAsync(testText); + } + + [Fact] + [WorkItem(35525, "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; }|} +}"; + await TestAsync(testText); + } + + [Fact] + [WorkItem(35525, "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; } +}"; + await TestMissingAsync(testText); + } + #endregion } } -- GitLab