Inheritance: ITextBuffer
 public IInteractiveWindowVisualComponent Create(int instanceId, IInteractiveEvaluator evaluator) {
     var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
     var container = new VisualComponentContainerStub<RInteractiveWindowVisualComponent>();
     var component = new RInteractiveWindowVisualComponent(new InteractiveWindowMock(new WpfTextViewMock(tb), evaluator), container);
     container.Component = component;
     return component;
 }
Exemplo n.º 2
0
        public void InsertRoxygen01() {
            var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            AstRoot ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            var result = RoxygenBlock.TryInsertBlock(tb, ast, 0);
            result.Should().BeFalse();

            tb = new TextBufferMock("x <- 1\r\ny <- 2", RContentTypeDefinition.ContentType);
            ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            RoxygenBlock.TryInsertBlock(tb, ast, 0).Should().BeFalse();
            RoxygenBlock.TryInsertBlock(tb, ast, 8).Should().BeFalse();

            tb = new TextBufferMock("##\r\nx <- function(a) { }", RContentTypeDefinition.ContentType);
            ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            RoxygenBlock.TryInsertBlock(tb, ast, 4).Should().BeTrue();
            string actual = tb.CurrentSnapshot.GetText();
            actual.Should().Be(
@"#' Title
#'
#' @param a
#'
#' @return
#' @export
#'
#' @examples
x <- function(a) { }");

            int funcStart = tb.CurrentSnapshot.GetText().IndexOf("x <-");
            tb.Insert(funcStart, "\r\n");
            RoxygenBlock.TryInsertBlock(tb, ast, funcStart - 2).Should().BeFalse();
        }
Exemplo n.º 3
0
        private static void ClassifyFile(MarkdownTestFilesFixture fixture, string fileName)
        {
            string testFile = fixture.GetDestinationPath(fileName);
            string content = fixture.LoadDestinationFile(fileName);

            TextBufferMock textBuffer = new TextBufferMock(content, MdContentTypeDefinition.ContentType);

            MdClassifierProvider classifierProvider = new MdClassifierProvider();
            EditorShell.Current.CompositionService.SatisfyImportsOnce(classifierProvider);

            IClassifier cls = classifierProvider.GetClassifier(textBuffer);

            IList<ClassificationSpan> spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length)));
            string actual = ClassificationWriter.WriteClassifications(spans);

            string baselineFile = testFile + ".colors";

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                string enlistmentPath = @"F:\RTVS\src\Markdown\Editor\Test\Files\Classification";
                baselineFile = Path.Combine(enlistmentPath, Path.GetFileName(testFile)) + ".colors";

                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Exemplo n.º 4
0
        private void ClassifyFile(MarkdownTestFilesFixture fixture, string fileName) {
            string testFile = fixture.GetDestinationPath(fileName);
            string content = fixture.LoadDestinationFile(fileName);

            TextBufferMock textBuffer = new TextBufferMock(content, MdContentTypeDefinition.ContentType);

            var crs = _exportProvider.GetExportedValue<IClassificationTypeRegistryService>();
            var ctrs = _exportProvider.GetExportedValue<IContentTypeRegistryService>();
            var cnp = _exportProvider.GetExports<IClassificationNameProvider, IComponentContentTypes>();

            MdClassifierProvider classifierProvider = new MdClassifierProvider(crs, ctrs, cnp, _exportProvider.GetExportedValue<ICoreShell>());
            _exportProvider.GetExportedValue<ICoreShell>().CompositionService.SatisfyImportsOnce(classifierProvider);

            IClassifier cls = classifierProvider.GetClassifier(textBuffer);

            IList<ClassificationSpan> spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length)));
            string actual = ClassificationWriter.WriteClassifications(spans);

            string baselineFile = testFile + ".colors";

            if (_regenerateBaselineFiles) {
                baselineFile = Path.Combine(fixture.SourcePath, @"Classification\", Path.GetFileName(testFile)) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            } else {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Exemplo n.º 5
0
       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();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        public void ParameterTest01() {
            string content = @"x <- foo(a,b,c,d)";
            AstRoot ast = RParser.Parse(content);

            ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 10);

            parametersInfo.Should().NotBeNull()
                .And.HaveFunctionCall()
                .And.HaveFunctionName("foo")
                .And.HaveParameterIndex(0)
                .And.HaveSignatureEnd(17);

            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 11);
            parametersInfo.Should().HaveParameterIndex(1);
            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 12);
            parametersInfo.Should().HaveParameterIndex(1);

            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 13);
            parametersInfo.Should().HaveParameterIndex(2);
            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 14);
            parametersInfo.Should().HaveParameterIndex(2);

            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 15);
            parametersInfo.Should().HaveParameterIndex(3);
            parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 16);
            parametersInfo.Should().HaveParameterIndex(3);
        }
Exemplo n.º 8
0
        public void IsSignatureHelpBufferTest() {
            var tb = new TextBufferMock(string.Empty, "R");
            tb.IsSignatureHelpBuffer().Should().BeFalse();

            tb = new TextBufferMock(string.Empty, "R Signature Help");
            tb.IsSignatureHelpBuffer().Should().BeTrue();
        }
        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);
        }
Exemplo n.º 10
0
        public static EditorTree ApplyTextChange(string expression, int start, int oldLength, int newLength, string newText)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);
            tree.Build();

            TextChange tc = new TextChange();
            tc.OldRange = new TextRange(start, oldLength);
            tc.NewRange = new TextRange(start, newLength);
            tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot);

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new Span(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new Span(start, oldLength));
            }

            return tree;
        }
Exemplo n.º 11
0
        public void TextProvider_IndexOf2() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            textProvider.IndexOf("o", new TextRange(3, 7), true).Should().Be(8);
        }
Exemplo n.º 12
0
        public void TextProvider_IndexOf1() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            textProvider.IndexOf("fox", 0, true).Should().Be(12);
        }
Exemplo n.º 13
0
        public static EditorTree MakeTree(ICoreShell coreShell, string expression) {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            var tree = new EditorTree(textBuffer, coreShell);
            tree.Build();

            return tree;
        }
Exemplo n.º 14
0
 public EditorDocumentMock(string content, string filePath = null) {
     var tb = new TextBufferMock(content, RContentTypeDefinition.ContentType);
     EditorTree = new EditorTreeMock(tb, RParser.Parse(content));
     ServiceManager.AddService<IREditorDocument>(this, tb, null);
     if (!string.IsNullOrEmpty(filePath)) {
         tb.Properties.AddProperty(typeof(ITextDocument), new TextDocumentMock(tb, filePath));
     }
 }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        public void TextProvider_GetText() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            textProvider.GetText(9, 5).Should().Be("wn fo");
        }
Exemplo n.º 17
0
        public void ParameterTest03() {
            string content = @"x <- foo(,,";

            AstRoot ast = RParser.Parse(content);
            ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);

            var parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 11);
            parametersInfo.Should().HaveParameterIndex(2);
        }
Exemplo n.º 18
0
        public static EditorTree MakeTree(string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);
            tree.Build();

            return tree;
        }
Exemplo n.º 19
0
        public void TextProvider_GetCharAt() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            for (int i = 0; i < text.Length; i++) {
                textProvider[i].Should().Be(text[i]);
            }
        }
Exemplo n.º 20
0
        public void TextProvider_IndexOf_Range1() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            textProvider.IndexOf("uick", new TextRange(1, 4), true).Should().Be(1);
            textProvider.IndexOf("uick", new TextRange(1, 5), true).Should().Be(1);
            textProvider.IndexOf("uick", new TextRange(1, 3), false).Should().Be(-1);
            textProvider.IndexOf("uick", new TextRange(1, 0), false).Should().Be(-1);
        }
Exemplo n.º 21
0
        public void GetTextDocumentTest() {
            var tb = new TextBufferMock(string.Empty, "R");

            var s = Substitute.For<ITextDocument>();
            tb.Properties.AddProperty(typeof(ITextDocument), s);

            var td = tb.GetTextDocument();
            td.Should().NotBeNull();
            td.Should().Be(s);
            td.Should().BeAssignableTo<ITextDocument>();
        }
        public async Task EvaluatorTest01() {
            using (new VsRHostScript()) {
                var session = _sessionProvider.GetInteractiveWindowRSession();
                using (var eval = new RInteractiveEvaluator(session, RHistoryStubFactory.CreateDefault(), VsAppShell.Current, RToolsSettings.Current)) {
                    var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
                    var tv = new WpfTextViewMock(tb);

                    var iwm = new InteractiveWindowMock(tv);
                    eval.CurrentWindow = iwm;

                    var result = await eval.InitializeAsync();
                    result.Should().Be(ExecutionResult.Success);
                    session.IsHostRunning.Should().BeTrue();

                    eval.CanExecuteCode("x <-").Should().BeFalse();
                    eval.CanExecuteCode("(()").Should().BeFalse();
                    eval.CanExecuteCode("a *(b+c)").Should().BeTrue();

                    VsRHostScript.DoIdle(300);

                    result = await eval.ExecuteCodeAsync(new string(new char[10000])+"\r\n");
                    result.Should().Be(ExecutionResult.Failure);
                    string text = tb.CurrentSnapshot.GetText();
                    text.Should().Contain(string.Format(Microsoft.R.Components.Resources.InputIsTooLong, 4096));
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("z <- '電話帳 全米のお'\n");
                    result.Should().Be(ExecutionResult.Success);
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("z" + Environment.NewLine);
                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"電話帳 全米のお\"");
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("Encoding(z)\n");
                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"UTF-8\"");
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("x <- c(1:10)\n");
                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.Should().Be(string.Empty);
                    tb.Clear();

                    await eval.ResetAsync(initialize: false);
                    text = tb.CurrentSnapshot.GetText();
                    text.Should().StartWith(Microsoft.R.Components.Resources.MicrosoftRHostStopping);
                }
            }
        }
Exemplo n.º 23
0
 public void GetWordSpan(string content, int position, int start, int length) {
     var tb = new TextBufferMock(content, RContentTypeDefinition.ContentType);
     Span? span = RTextStructure.GetWordSpan(tb.CurrentSnapshot, position);
     if (span.HasValue) {
         span.Value.Start.Should().Be(start);
         span.Value.Length.Should().Be(length);
     } else {
         length.Should().Be(0);
         start.Should().Be(0);
     }
 }
Exemplo n.º 24
0
        public void TextProvider_CompareTo() {
            var text = "Quick brown fox jumps over the lazy dog";
            var textBuffer = new TextBufferMock(text, "text");

            var textProvider = new TextProvider(textBuffer.CurrentSnapshot, 10);

            textProvider.CompareTo(text.Length - 8, 4, "laZy", true).Should().BeTrue();
            textProvider.CompareTo(text.Length - 8, 3, "laZy", true).Should().BeFalse();
            textProvider.CompareTo(text.Length - 9, 4, "laZy", true).Should().BeFalse();
            textProvider.CompareTo(text.Length - 3, 3, "dog", false).Should().BeTrue();
            textProvider.CompareTo(text.Length - 3, 3, "dOg", false).Should().BeFalse();
            textProvider.CompareTo(text.Length - 2, 3, "dog", true).Should().BeFalse();
        }
Exemplo n.º 25
0
        public void GetPositionFromLineColumnTest() {
            var tb = new TextBufferMock("a\r\nb", "R");

            int? position;
            position = tb.GetPositionFromLineColumn(0, 0);
            position.Should().Be(0);

            position = tb.GetPositionFromLineColumn(1, 0);
            position.Should().Be(3);

            position = tb.GetPositionFromLineColumn(100, 100);
            position.Should().NotHaveValue();
        }
Exemplo n.º 26
0
 public static OutlineRegionCollection BuildOutlineRegions(IEditorShell editorShell, string content) {
     TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
     using (var tree = new EditorTree(textBuffer, editorShell)) {
         tree.Build();
         using (var editorDocument = new EditorDocumentMock(tree)) {
             using (var ob = new ROutlineRegionBuilder(editorDocument, editorShell)) {
                 OutlineRegionCollection rc = new OutlineRegionCollection(0);
                 ob.BuildRegions(rc);
                 return rc;
             }
         }
     }
 }
Exemplo n.º 27
0
        public void InsertRoxygen02() {
            var tb = new TextBufferMock("##\r\nx <- function() { }", RContentTypeDefinition.ContentType);
            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());
            RoxygenBlock.TryInsertBlock(tb, ast, 4).Should().BeTrue();
            string actual = tb.CurrentSnapshot.GetText();
            actual.Should().Be(
@"#' Title
#'
#' @return
#' @export
#'
#' @examples
x <- function() { }");
        }
Exemplo n.º 28
0
        public static OutlineRegionCollection BuildOutlineRegions(string content)
        {
            TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            using (EditorTree tree = new EditorTree(textBuffer)) {
                tree.Build();

                EditorDocumentMock editorDocument = new EditorDocumentMock(tree);
                ROutlineRegionBuilder ob = new ROutlineRegionBuilder(editorDocument);
                OutlineRegionCollection rc = new OutlineRegionCollection(0);
                ob.BuildRegions(rc);

                return rc;
            }
        }
        public async Task SourceRScriptTest(bool echo, string encoding) {
            await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RInteractiveWorkflowCommandTest));
            await _workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo {
                Name = _testMethod.Name,
                RHostCommandLineArguments = _settings.LastActiveConnection.RCommandLineArguments,
                CranMirrorName = _settings.CranMirror,
                CodePage = _settings.RCodePage
            }, null, 50000);

            var session = _workflow.RSession;
            await session.ExecuteAsync("sourced <- FALSE");

            var tracker = Substitute.For<IActiveWpfTextViewTracker>();
            tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns((IWpfTextView)null);

            var command = new SourceRScriptCommand(_workflow, tracker, echo);
            command.Should().BeSupported()
                .And.BeInvisibleAndDisabled();

            using (await _workflow.GetOrCreateVisualComponentAsync()) {
                const string code = "sourced <- TRUE";
                var textBuffer = new TextBufferMock(code, RContentTypeDefinition.ContentType);
                var textView = new WpfTextViewMock(textBuffer);

                tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns(textView);
                tracker.LastActiveTextView.Returns(textView);

                command.Should().BeSupported()
                    .And.BeVisibleAndDisabled();

                using (var sf = new SourceFile(code)) {
                    var document = new TextDocumentMock(textBuffer, sf.FilePath) {
                        Encoding = Encoding.GetEncoding(encoding)
                    };

                    textBuffer.Properties[typeof(ITextDocument)] = document;

                    command.Should().BeSupported()
                        .And.BeVisibleAndEnabled();

                    var mutatedTask = EventTaskSources.IRSession.Mutated.Create(session);

                    await command.InvokeAsync().Should().BeCompletedAsync();

                    await mutatedTask.Should().BeCompletedAsync();
                    (await session.EvaluateAsync<bool>("sourced", REvaluationKind.Normal)).Should().BeTrue();
                }
            }
        }
Exemplo n.º 30
0
        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);
        }