예제 #1
0
        private void GetCompletions(string content, int lineNumber, int column, IList <CompletionSet> completionSets, ITextRange selectedRange = null)
        {
            TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var            line       = textBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber);

            GetCompletions(content, line.Start + column, completionSets, selectedRange);
        }
예제 #2
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);
        }
예제 #3
0
        private void GetPeekableItems(string content, int lineNumber, int column, IList <IPeekableItem> items, ITextRange selection = null)
        {
            var tb   = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var line = tb.CurrentSnapshot.GetLineFromLineNumber(lineNumber);

            GetPeekableItems(content, line.Start + column, items, selection);
        }
예제 #4
0
        private void ClassifyFile(MarkdownTestFilesFixture fixture, string fileName)
        {
            var testFile = fixture.GetDestinationPath(fileName);
            var content  = fixture.LoadDestinationFile(fileName);

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

            var crs  = _coreShell.GetService <IClassificationTypeRegistryService>();
            var ctrs = _coreShell.GetService <IContentTypeRegistryService>();
            var classifierProvider = new MdClassifierProvider(crs, ctrs, _coreShell);
            var cls = classifierProvider.GetClassifier(textBuffer);

            var spans        = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length)));
            var actual       = ClassificationWriter.WriteClassifications(spans);
            var baselineFile = testFile + ".colors";

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(fixture.SourcePath, @"Classification\", Path.GetFileName(testFile)) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
예제 #5
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)
            {
                baselineFile = Path.Combine(fixture.SourcePath, @"Classification\", Path.GetFileName(testFile)) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
예제 #6
0
        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, _services);
            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);
        }
예제 #7
0
            public async Task ParameterTest_ComputeCurrentParameter04()
            {
                await FunctionIndexUtility.GetFunctionInfoAsync("legend");

                REditorSettings.PartialArgumentNameMatch = true;

                ITextBuffer              textBuffer = new TextBufferMock("legend(an=1)", RContentTypeDefinition.ContentType);
                SignatureHelpSource      source     = new SignatureHelpSource(textBuffer);
                SignatureHelpSessionMock session    = new SignatureHelpSessionMock(textBuffer, 0);
                TextViewMock             textView   = session.TextView as TextViewMock;
                List <ISignature>        signatures = new List <ISignature>();

                EditorTree tree = new EditorTree(textBuffer);

                tree.Build();
                var document = new EditorDocumentMock(tree);

                session.TrackingPoint = new TrackingPointMock(textBuffer, 7, PointTrackingMode.Positive, TrackingFidelityMode.Forward);

                tree.TakeThreadOwnerShip();
                await source.AugmentSignatureHelpSessionAsync(session, signatures, tree.AstRoot);

                signatures.Should().ContainSingle();

                textView.Caret = new TextCaretMock(textView, 8);
                SignatureHelp sh    = signatures[0] as SignatureHelp;
                int           index = sh.ComputeCurrentParameter(tree.TextSnapshot, tree.AstRoot, 8);

                index.Should().Be(9);
            }
예제 #8
0
        public void Sections()
        {
            string content =
                @"# NAME1 -----
x <- 1


# NAME2 -----


";
            TextBufferMock textBuffer           = null;
            int            calls                = 0;
            OutlineRegionsChangedEventArgs args = null;

            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)) {
                        var rc1 = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc1);

                        rc1.Should().HaveCount(2);
                        rc1[0].DisplayText.Should().Be("# NAME1");
                        rc1[1].DisplayText.Should().Be("# NAME2");

                        rc1[0].Length.Should().Be(21);
                        rc1[1].Length.Should().Be(13);

                        ob.RegionsChanged += (s, e) => {
                            calls++;
                            args = e;
                        };

                        textBuffer.Insert(2, "A");
                        editorDocument.EditorTree.EnsureTreeReady();

                        // Wait for background/idle tasks to complete
                        var start = DateTime.Now;
                        while (calls == 0 && (DateTime.Now - start).TotalMilliseconds < 2000)
                        {
                            _editorShell.DoIdle();
                        }

                        calls.Should().Be(1);
                        args.Should().NotBeNull();
                        args.ChangedRange.Start.Should().Be(0);
                        args.ChangedRange.End.Should().Be(textBuffer.CurrentSnapshot.Length);
                        args.Regions.Should().HaveCount(2);

                        args.Regions[0].DisplayText.Should().Be("# ANAME1");
                        args.Regions[1].DisplayText.Should().Be("# NAME2");

                        args.Regions[0].Length.Should().Be(22);
                        args.Regions[1].Length.Should().Be(13);
                    }
                }
            }
        }
예제 #9
0
        public static EditorTree MakeTree(IServiceContainer services, string expression)
        {
            var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer();
            var tree       = new EditorTree(textBuffer, services);

            tree.Build();
            return(tree);
        }
예제 #10
0
        public static ITextView MakeTextView(string content, string contentType, ITextRange selectionRange) {
            TextBufferMock textBuffer = new TextBufferMock(content, contentType);
            TextViewMock textView = new TextViewMock(textBuffer);

            textView.Selection.Select(new SnapshotSpan(textBuffer.CurrentSnapshot,
                     new Span(selectionRange.Start, selectionRange.Length)), false);
            return textView;
        }
예제 #11
0
        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);
        }
예제 #12
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();
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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");
        }
예제 #16
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);
        }
        public IInteractiveWindowVisualComponent Create(int instanceId, IInteractiveEvaluator evaluator, IRSessionProvider sessionProvider)
        {
            var tb        = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            var container = new VisualComponentContainerStub <RInteractiveWindowVisualComponent>();
            var component = new RInteractiveWindowVisualComponent(new InteractiveWindowMock(new WpfTextViewMock(tb), evaluator), container, sessionProvider, _shell);

            container.Component = component;
            return(component);
        }
예제 #18
0
        public void S4Error(string content)
        {
            var tb = new TextBufferMock("##\r\n" + content, RContentTypeDefinition.ContentType);
            var eb = tb.ToEditorBuffer();

            var ast = RParser.Parse(tb.CurrentSnapshot.GetText());

            RoxygenBlock.TryInsertBlock(eb, ast, 4).Should().BeFalse();
        }
예제 #19
0
        public static EditorTree MakeTree(string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            return(tree);
        }
예제 #20
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);
        }
예제 #21
0
        public void ParameterTest03()
        {
            var content      = @"x <- foo(,,";
            var ast          = RParser.Parse(content);
            var editorBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType).ToEditorBuffer();

            var parametersInfo = ast.GetSignatureInfoFromBuffer(editorBuffer.CurrentSnapshot, 11);

            parametersInfo.Should().HaveParameterIndex(2);
        }
예제 #22
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);
        }
예제 #23
0
        public EditorDocumentMock(string content, string filePath = null)
        {
            var tb = new TextBufferMock(content, RContentTypeDefinition.ContentType);

            EditorTree = new EditorTreeMock(new EditorBuffer(tb), RParser.Parse(content));
            tb.AddService(this);
            if (!string.IsNullOrEmpty(filePath))
            {
                tb.Properties.AddProperty(typeof(ITextDocument), new TextDocumentMock(tb, filePath));
            }
        }
예제 #24
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]);
            }
        }
예제 #25
0
        public void TextProvider_Boundary2()
        {
            var text       = string.Empty;
            var textBuffer = new TextBufferMock(text, "text");

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

            textProvider.CompareTo(text.Length, 4, "laZy", true).Should().BeFalse();
            textProvider.CompareTo(0, 3, new string('c', 100), true).Should().BeFalse();
            textProvider.CompareTo(0, 0, "", true).Should().BeTrue();
            textProvider.CompareTo(0, 2, string.Empty, true).Should().BeFalse();
        }
예제 #26
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);
        }
예제 #27
0
        public async Task SourceRScriptTest(bool echo, string encoding)
        {
            await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RInteractiveWorkflowCommandTest));

            await _workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo(
                                                                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();
                }
            }
        }
예제 #28
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();
        }
예제 #29
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>();
        }
예제 #30
0
        public void TextProvider_Boundary1()
        {
            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, 4, "laZy", true).Should().BeFalse();
            textProvider.CompareTo(text.Length - 1, 4, "laZy", true).Should().BeFalse();
            textProvider.CompareTo(0, 3, new string('c', 100), true).Should().BeFalse();
            textProvider.CompareTo(0, 0, "", true).Should().BeTrue();
            textProvider.CompareTo(0, 2, string.Empty, true).Should().BeFalse();
            textProvider.CompareTo(text.Length - 2, 3, "dog", true).Should().BeFalse();
        }
예제 #31
0
        public async Task EvaluatorTest02()
        {
            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();

                    VsRHostScript.DoIdle(1000);
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("w <- dQuote('text')" + Environment.NewLine);

                    result.Should().Be(ExecutionResult.Success);
                    var text = tb.CurrentSnapshot.GetText();
                    text.Should().Be(string.Empty);
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("w" + Environment.NewLine);

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"“text”\"");
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("e <- dQuote('абвг')" + Environment.NewLine);

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.Should().Be(string.Empty);
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("e" + Environment.NewLine);

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"“абвг”\"");
                    tb.Clear();
                }
            }
        }