Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for pattern brace completion #43522

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 () } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does (< throw anything off due to < being a mismatched brace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't because it's a normal binary operator. I need to figure out how to test it though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to make quick sense of this, so I filed #43560 as a follow-up.

}
}";

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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

Expand Down