From 351776860adfea82643180bc35a25cf03b0866ed Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 20 Apr 2020 14:55:54 -0700 Subject: [PATCH] Add tests for pattern brace completion --- .../AutomaticBraceCompletionTests.cs | 94 +++++++++++++++++++ .../AbstractAutomaticBraceCompletionTests.cs | 3 +- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs index 0e2dbe32437c3..ccd84b21d7022 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs @@ -363,6 +363,100 @@ void M() CheckReturn(session.Session, 12, expectedAfterReturn); } + [WpfFact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)] + public void RecursivePattern_Nested() + { + var code = @" +class C +{ + void M() + { + _ = this is { Name: $$ } + } +}"; + + var expectedBeforeReturn = @" +class C +{ + void M() + { + _ = this is { Name: { } } + } +}"; + + var expectedAfterReturn = @" +class C +{ + void M() + { + _ = this is { Name: + { + + } } + } +}"; + using var session = CreateSession(code); + Assert.NotNull(session); + + CheckStart(session.Session); + CheckText(session.Session, expectedBeforeReturn); + CheckReturn(session.Session, 16, expectedAfterReturn); + } + + [WpfFact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)] + public void RecursivePattern_Parentheses1() + { + var code = @" +class C +{ + void M() + { + _ = this is { Name: $$ } + } +}"; + var expected = @" +class C +{ + void M() + { + _ = this is { Name: () } + } +}"; + + using var session = CreateSession(TestWorkspace.CreateCSharp(code), '(', ')'); + Assert.NotNull(session); + + CheckStart(session.Session); + CheckText(session.Session, expected); + } + + [WpfFact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)] + public void RecursivePattern_Parentheses2() + { + var code = @" +class C +{ + void M() + { + _ = this is { Name: { Length: (> 3) and $$ } } + } +}"; + var expected = @" +class C +{ + void M() + { + _ = this is { Name: { Length: (> 3) and () } } + } +}"; + + using var session = CreateSession(TestWorkspace.CreateCSharp(code), '(', ')'); + Assert.NotNull(session); + + CheckStart(session.Session); + CheckText(session.Session, expected); + } + [WpfFact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)] public void RecursivePattern_FollowedByInvocation() { diff --git a/src/EditorFeatures/TestUtilities/AutomaticCompletion/AbstractAutomaticBraceCompletionTests.cs b/src/EditorFeatures/TestUtilities/AutomaticCompletion/AbstractAutomaticBraceCompletionTests.cs index 655b8f565f18c..f55dcdabf47e6 100644 --- a/src/EditorFeatures/TestUtilities/AutomaticCompletion/AbstractAutomaticBraceCompletionTests.cs +++ b/src/EditorFeatures/TestUtilities/AutomaticCompletion/AbstractAutomaticBraceCompletionTests.cs @@ -14,6 +14,7 @@ using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.BraceCompletion; using Microsoft.VisualStudio.Text.Operations; +using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.UnitTests.AutomaticCompletion @@ -87,7 +88,7 @@ internal void CheckReturn(IBraceCompletionSession session, int indentation, stri if (result != null) { - Assert.Equal(result, session.SubjectBuffer.CurrentSnapshot.GetText()); + AssertEx.EqualOrDiff(result, session.SubjectBuffer.CurrentSnapshot.GetText()); } }