Skip to content

Commit

Permalink
Merge pull request #6 from sharwell/multi-position
Browse files Browse the repository at this point in the history
Support multiple positions in AutomaticLineEnderTests
  • Loading branch information
Cosifne authored Jan 21, 2021
2 parents 6b7fa6c + 4c9ef96 commit c076e5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void EventField()
$$
}", @"class C
{
event System.EventHandler e = null$$
e$$vent System.Even$$tHandler e$$ = null$$
}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
Expand All @@ -26,12 +27,27 @@ public abstract class AbstractAutomaticLineEnderTests

internal abstract IChainedCommandHandler<AutomaticLineEnderCommandArgs> GetCommandHandler(TestWorkspace workspace);

protected void Test(string expected, string markupCode, bool completionActive = false, bool assertNextHandlerInvoked = false)
{
TestFileMarkupParser.GetPositionsAndSpans(markupCode, out var code, out var positions, out _);
Assert.NotEmpty(positions);

foreach (var position in positions)
{
// Run the test once for each input position. All marked positions in the input for a test are expected
// to have the same result.
Test(expected, code, position, completionActive, assertNextHandlerInvoked);
}
}

#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/45892
protected void Test(string expected, string code, bool completionActive = false, bool assertNextHandlerInvoked = false)
private void Test(string expected, string code, int position, bool completionActive = false, bool assertNextHandlerInvoked = false)
#pragma warning restore IDE0060 // Remove unused parameter
{
var markupCode = code[0..position] + "$$" + code[position..];

// WPF is required for some reason: https://github.com/dotnet/roslyn/issues/46286
using var workspace = TestWorkspace.Create(Language, compilationOptions: null, parseOptions: null, new[] { code }, composition: EditorTestCompositions.EditorFeaturesWpf);
using var workspace = TestWorkspace.Create(Language, compilationOptions: null, parseOptions: null, new[] { markupCode }, composition: EditorTestCompositions.EditorFeaturesWpf);

var view = workspace.Documents.Single().GetTextView();
var buffer = workspace.Documents.Single().GetTextBuffer();
Expand Down

0 comments on commit c076e5d

Please sign in to comment.