public void GotoBrace() { string content = "if(x<1) {x<-2}"; ITextBuffer textBuffer = new TextBufferMock(content, "R"); ITextView textView = new TextViewMock(textBuffer); var command = new GotoBraceCommand(textView, textBuffer); object o = new object(); var status = command.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE); status.Should().Be(CommandStatus.SupportedAndEnabled); status = command.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE_EXT); status.Should().Be(CommandStatus.SupportedAndEnabled); textView.Caret.MoveTo(new SnapshotPoint(textBuffer.CurrentSnapshot, 2)); command.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE, null, ref o); textView.Caret.Position.BufferPosition.Position.Should().Be(7); command.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE, null, ref o); textView.Caret.Position.BufferPosition.Position.Should().Be(2); textView.Caret.MoveTo(new SnapshotPoint(textBuffer.CurrentSnapshot, 8)); command.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE, null, ref o); textView.Caret.Position.BufferPosition.Position.Should().Be(14); command.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.GOTOBRACE, null, ref o); textView.Caret.Position.BufferPosition.Position.Should().Be(8); }
public void ExpansionControllerTest() { var textBuffer = new TextBufferMock("if", RContentTypeDefinition.ContentType); var textView = new TextViewMock(textBuffer); var o = new object(); var controller = new ExpansionsController(textView, textBuffer, _expansionManager, _cache); controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled); controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled); controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.RETURN, null, ref o).Should().Be(CommandResult.NotSupported); controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.NotSupported); controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.CANCEL, null, ref o).Should().Be(CommandResult.NotSupported); textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, 2)); bool inserted; var client = controller.ExpansionClient as ExpansionClient; client.StartSnippetInsertion(out inserted); controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled); controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled); client.Session.Should().NotBeNull(); var session = client.Session; var mock = session as VsExpansionSessionMock; controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.TAB, null, ref o).Should().Be(CommandResult.Executed); mock.ExpansionFieldIndex.Should().Be(1); controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.Executed); mock.ExpansionFieldIndex.Should().Be(0); client.EndExpansion(); }
public void ExpansionClientTest() { var textBuffer = new TextBufferMock("if", RContentTypeDefinition.ContentType); var textView = new TextViewMock(textBuffer); var client = new ExpansionClient(textView, textBuffer, _expansionManager, _cache); client.IsEditingExpansion().Should().BeFalse(); client.IsCaretInsideSnippetFields().Should().BeFalse(); _expansionManager.InvokeInsertionUI(null, null, Guid.Empty, new string[0], 0, 0, new string[0], 0, 0, string.Empty, string.Empty) .ReturnsForAnyArgs(VSConstants.S_OK); client.InvokeInsertionUI((int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(VSConstants.S_OK); textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, 2)); bool inserted; client.StartSnippetInsertion(out inserted); inserted.Should().BeTrue(); client.IsEditingExpansion().Should().BeTrue(); client.EndExpansion(); client.IsEditingExpansion().Should().BeFalse(); client.OnItemChosen("if", "path"); client.IsEditingExpansion().Should().BeTrue(); client.EndExpansion(); client.IsEditingExpansion().Should().BeFalse(); client.IsCaretInsideSnippetFields().Should().BeFalse(); }
public static ITextView MakeTextView(string content, ITextRange selectionRange) { TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); TextViewMock textView = new TextViewMock(textBuffer); textView.Selection.Select(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(selectionRange.Start, selectionRange.Length)), false); return textView; }
public void FormatDocument(string original, string expected) { ITextBuffer textBuffer = new TextBufferMock(original, RContentTypeDefinition.ContentType); ITextView textView = new TextViewMock(textBuffer); using (var command = new FormatDocumentCommand(textView, textBuffer, _editorShell)) { var status = command.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.FORMATDOCUMENT); status.Should().Be(CommandStatus.SupportedAndEnabled); object o = new object(); command.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.FORMATDOCUMENT, null, ref o); } string actual = textBuffer.CurrentSnapshot.GetText(); actual.Should().Be(expected); }
public void FormatOnPasteStatus() { ITextBuffer textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); ITextView textView = new TextViewMock(textBuffer); var clipboard = new ClipboardDataProvider(); using (var command = new FormatOnPasteCommand(textView, textBuffer, _editorShell)) { command.ClipboardDataProvider = clipboard; var status = command.Status(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste); status.Should().Be(CommandStatus.NotSupported); clipboard.Format = DataFormats.UnicodeText; clipboard.Data = "data"; status = command.Status(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste); status.Should().Be(CommandStatus.SupportedAndEnabled); } }
public void Test01() { var tv = new TextViewMock(new TextBufferMock(string.Empty, "text")); var proxy = CommandTargetProxy.GetProxyTarget(tv, null); object o = new object(); proxy.Should().NotBeNull(); ServiceManager.GetService<CommandTargetProxy>(tv).Should().Be(proxy); proxy.Status(Guid.Empty, 0).Should().Be(CommandStatus.NotSupported); proxy.Invoke(Guid.Empty, 0, null, ref o).Should().Be(CommandResult.NotSupported); var ct = Substitute.For<ICommandTarget>(); ct.Status(Guid.Empty, 0).Returns(CommandStatus.Supported); CommandTargetProxy.SetCommandTarget(tv, ct); ServiceManager.GetService<CommandTargetProxy>(tv).Should().BeNull(); proxy.Status(Guid.Empty, 0).Should().Be(CommandStatus.Supported); }
public async Task SendToReplTest() { string content = "x <- 1\r\ny <- 2\r\n"; var editorBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); var tv = new TextViewMock(editorBuffer); var commandFactory = new VsRCommandFactory(_workflowProvider, _componentContainerFactory); var commands = UIThreadHelper.Instance.Invoke(() => commandFactory.GetCommands(tv, editorBuffer)); await _workflow.RSession.HostStarted; _workflow.ActiveWindow.Should().NotBeNull(); var command = commands.OfType<SendToReplCommand>() .Should().ContainSingle().Which; var replBuffer = _workflow.ActiveWindow.InteractiveWindow.CurrentLanguageBuffer; var containerStub = (VisualComponentContainerStub<RInteractiveWindowVisualComponent>)_workflow.ActiveWindow.Container; containerStub.IsOnScreen.Should().BeFalse(); Guid group = VSConstants.VsStd11; int id = (int)VSConstants.VSStd11CmdID.ExecuteLineInInteractive; object o = new object(); command.Status(group, id).Should().Be(CommandStatus.SupportedAndEnabled); containerStub.IsOnScreen = false; command.Invoke(group, id, null, ref o); replBuffer.CurrentSnapshot.GetText().Trim().Should().Be("x <- 1"); int caretPos = tv.Caret.Position.BufferPosition.Position; int lineNum = editorBuffer.CurrentSnapshot.GetLineNumberFromPosition(caretPos); lineNum.Should().Be(1); tv.Selection.Select(new SnapshotSpan(editorBuffer.CurrentSnapshot, new Span(0, 1)), false); command.Invoke(group, id, null, ref o); ITextSnapshotLine line = replBuffer.CurrentSnapshot.GetLineFromLineNumber(1); line.GetText().Trim().Should().Be("x"); _workflow.ActiveWindow.Dispose(); }
private void GetCompletions(string content, int position, IList<CompletionSet> completionSets, ITextRange selectedRange = null) { AstRoot ast = RParser.Parse(content); TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); TextViewMock textView = new TextViewMock(textBuffer, position); if (selectedRange != null) { textView.Selection.Select(new SnapshotSpan(textBuffer.CurrentSnapshot, selectedRange.Start, selectedRange.Length), false); } CompletionSessionMock completionSession = new CompletionSessionMock(textView, completionSets, position); RCompletionSource completionSource = new RCompletionSource(textBuffer); completionSource.PopulateCompletionList(position, completionSession, completionSets, ast); }
public SignatureHelpSessionMock(IServiceContainer services, ITextBuffer textBuffer, int caretPosition) { TextView = new TextViewMock(textBuffer, caretPosition); }
private string FormatFromClipboard(string content) { ITextBuffer textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); ITextView textView = new TextViewMock(textBuffer); var clipboard = new ClipboardDataProvider(); using (var command = new FormatOnPasteCommand(textView, textBuffer, _editorShell)) { command.ClipboardDataProvider = clipboard; clipboard.Format = DataFormats.UnicodeText; clipboard.Data = content; var ast = RParser.Parse(textBuffer.CurrentSnapshot.GetText()); using (var document = new EditorDocumentMock(new EditorTreeMock(textBuffer, ast))) { object o = new object(); command.Invoke(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste, null, ref o); } } return textBuffer.CurrentSnapshot.GetText(); }
private ITextView MakeTextView(string content, int caretPosition) { var tb = new TextBufferMock(content, RContentTypeDefinition.ContentType); var tv = new TextViewMock(tb); tv.Caret.MoveTo(new SnapshotPoint(tb.CurrentSnapshot, caretPosition)); return tv; }
private TextViewMock SetupTextView(string content, int startLineNumber, int startColumn) { var document = new EditorDocumentMock(content); var tv = new TextViewMock(document.TextBuffer); var line = document.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(startLineNumber); tv.Caret.MoveTo(new SnapshotPoint(tv.TextBuffer.CurrentSnapshot, line.Start + startColumn)); return tv; }
private void GetPeekableItems(string content, int position, IList<IPeekableItem> items, ITextRange selection = null) { var document = new EditorDocumentMock(content, @"C:\file.r"); TextViewMock textView = new TextViewMock(document.TextBuffer, position); if (selection != null) { textView.Selection.Select(new SnapshotSpan(document.TextBuffer.CurrentSnapshot, new Span(selection.Start, selection.Length)), isReversed: false); textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, selection.End)); } else { textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, position)); } var peekSession = PeekSessionMock.Create(textView, position); var factory = PeekResultFactoryMock.Create(); var peekSource = new PeekableItemSource(textView.TextBuffer, factory, _exportProvider.GetExportedValue<ICoreShell>()); peekSource.AugmentPeekSession(peekSession, items); }