private async Task TestWorkerAsync( string inputMarkup, string expectedOutputMarkup, Action callback) { using (var workspace = await TestWorkspace.CreateCSharpAsync(inputMarkup)) { var document = workspace.Documents.Single(); var view = document.GetTextView(); var snapshot = view.TextBuffer.CurrentSnapshot; view.SetSelection(document.SelectedSpans.Single().ToSnapshotSpan(snapshot)); var commandHandler = new SplitStringLiteralCommandHandler(); commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), callback); if (expectedOutputMarkup != null) { string expectedOutput; IList<TextSpan> expectedSpans; MarkupTestFile.GetSpans(expectedOutputMarkup, out expectedOutput, out expectedSpans); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedSpans.Single().Start, view.Caret.Position.BufferPosition.Position); } } }
private async Task TestWorkerAsync( string inputMarkup, string expectedOutputMarkup, Action callback) { using (var workspace = await TestWorkspace.CreateCSharpAsync(inputMarkup)) { var document = workspace.Documents.Single(); var view = document.GetTextView(); var cursorPosition = document.CursorPosition.Value; view.Caret.MoveTo(new SnapshotPoint(view.TextBuffer.CurrentSnapshot, cursorPosition)); var commandHandler = new SplitStringLiteralCommandHandler(); commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), callback); if (expectedOutputMarkup != null) { string expectedOutput; int expectedCursorPosition; MarkupTestFile.GetPosition(expectedOutputMarkup, out expectedOutput, out expectedCursorPosition); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedCursorPosition, view.Caret.Position.BufferPosition.Position); } } }
private async Task TestWorkerAsync( string inputMarkup, string expectedOutputMarkup, Action callback) { using (var workspace = await TestWorkspace.CreateCSharpAsync(inputMarkup)) { var document = workspace.Documents.Single(); var view = document.GetTextView(); var snapshot = view.TextBuffer.CurrentSnapshot; view.SetSelection(document.SelectedSpans.Single().ToSnapshotSpan(snapshot)); var commandHandler = new SplitStringLiteralCommandHandler(); commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), callback); if (expectedOutputMarkup != null) { string expectedOutput; IList <TextSpan> expectedSpans; MarkupTestFile.GetSpans(expectedOutputMarkup, out expectedOutput, out expectedSpans); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedSpans.Single().Start, view.Caret.Position.BufferPosition.Position); } } }
/// <summary> /// verifyUndo is needed because of https://github.com/dotnet/roslyn/issues/28033 /// Most tests will continue to verifyUndo, but select tests will skip it due to /// this known test infrastructure issure. This bug does not represent a product /// failure. /// </summary> private void TestWorker( string inputMarkup, string expectedOutputMarkup, Action callback, bool verifyUndo = true, IndentStyle indentStyle = IndentStyle.Smart) { using var workspace = TestWorkspace.CreateCSharp(inputMarkup); workspace.Options = workspace.Options.WithChangedOption(SmartIndent, LanguageNames.CSharp, indentStyle); var document = workspace.Documents.Single(); var view = document.GetTextView(); var originalSnapshot = view.TextBuffer.CurrentSnapshot; var originalSelections = document.SelectedSpans; var snapshotSpans = new List <SnapshotSpan>(); foreach (var selection in originalSelections) { snapshotSpans.Add(selection.ToSnapshotSpan(originalSnapshot)); } view.SetMultiSelection(snapshotSpans); var undoHistoryRegistry = workspace.GetService <ITextUndoHistoryRegistry>(); var commandHandler = new SplitStringLiteralCommandHandler( undoHistoryRegistry, workspace.GetService <IEditorOperationsFactoryService>()); if (!commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), TestCommandExecutionContext.Create())) { callback(); } if (expectedOutputMarkup != null) { MarkupTestFile.GetSpans(expectedOutputMarkup, out var expectedOutput, out ImmutableArray <TextSpan> expectedSpans); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedSpans.First().Start, view.Caret.Position.BufferPosition.Position); if (verifyUndo) { // Ensure that after undo we go back to where we were to begin with. var history = undoHistoryRegistry.GetHistory(document.GetTextBuffer()); history.Undo(count: originalSelections.Count); var currentSnapshot = document.GetTextBuffer().CurrentSnapshot; Assert.Equal(originalSnapshot.GetText(), currentSnapshot.GetText()); Assert.Equal(originalSelections.First().Start, view.Caret.Position.BufferPosition.Position); } } }
private void TestWorker( string inputMarkup, string expectedOutputMarkup, Action callback) { using (var workspace = TestWorkspace.CreateCSharp(inputMarkup)) { var document = workspace.Documents.Single(); var view = document.GetTextView(); var originalSnapshot = view.TextBuffer.CurrentSnapshot; var originalSelection = document.SelectedSpans.Single(); view.SetSelection(originalSelection.ToSnapshotSpan(originalSnapshot)); var undoHistoryRegistry = workspace.GetService <ITextUndoHistoryRegistry>(); var commandHandler = new SplitStringLiteralCommandHandler( undoHistoryRegistry, workspace.GetService <IEditorOperationsFactoryService>()); if (!commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(view, view.TextBuffer), TestCommandExecutionContext.Create())) { callback(); } if (expectedOutputMarkup != null) { MarkupTestFile.GetSpans(expectedOutputMarkup, out var expectedOutput, out ImmutableArray <TextSpan> expectedSpans); Assert.Equal(expectedOutput, view.TextBuffer.CurrentSnapshot.AsText().ToString()); Assert.Equal(expectedSpans.Single().Start, view.Caret.Position.BufferPosition.Position); // Ensure that after undo we go back to where we were to begin with. var history = undoHistoryRegistry.GetHistory(document.TextBuffer); history.Undo(count: 1); var currentSnapshot = document.TextBuffer.CurrentSnapshot; Assert.Equal(originalSnapshot.GetText(), currentSnapshot.GetText()); Assert.Equal(originalSelection.Start, view.Caret.Position.BufferPosition.Position); } } }