Ejemplo n.º 1
0
        private void DataTipTest(string input, string selectionRegex, string expectedDataTip)
        {
            var buffer = new MockTextBuffer(input, @"C:\fob.js", "Node.js");
            var view   = new MockTextView(buffer);

            var classifierProvider = new NodejsClassifierProvider(new MockContentTypeRegistryService(NodejsConstants.Nodejs));

            classifierProvider._classificationRegistry = new MockClassificationTypeRegistryService();
            classifierProvider.GetClassifier(buffer);

            var analyzer = new VsProjectAnalyzer();

            buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer);
            analyzer.AddBuffer(buffer);
            analyzer.WaitForCompleteAnalysis();

            var m = Regex.Match(input, selectionRegex);

            Assert.IsTrue(m.Success);

            var startPos      = m.Index;
            var startLine     = buffer.CurrentSnapshot.GetLineFromPosition(startPos);
            var endPos        = m.Index + m.Length;
            var endLine       = buffer.CurrentSnapshot.GetLineFromPosition(endPos);
            var selectionSpan = new TextSpan {
                iStartLine  = startLine.LineNumber,
                iStartIndex = startPos - startLine.Start.Position,
                iEndLine    = endLine.LineNumber,
                iEndIndex   = endPos - endLine.Start.Position
            };

            var dataTipSpan = DataTipTextViewFilter.GetDataTipSpan(view, selectionSpan);

            if (expectedDataTip == null)
            {
                Assert.IsNull(dataTipSpan);
                return;
            }

            Assert.IsNotNull(dataTipSpan);
            var actualSpan = dataTipSpan.Value;

            startPos = input.IndexOf(expectedDataTip);
            Assert.AreNotEqual(-1, startPos);
            startLine = buffer.CurrentSnapshot.GetLineFromPosition(startPos);
            endPos    = startPos + expectedDataTip.Length;
            endLine   = buffer.CurrentSnapshot.GetLineFromPosition(endPos);
            var expectedSpan = new TextSpan {
                iStartLine  = startLine.LineNumber,
                iStartIndex = startPos - startLine.Start.Position,
                iEndLine    = endLine.LineNumber,
                iEndIndex   = endPos - endLine.Start.Position
            };

            // TextSpan doesn't override ToString, so test output is unusable in case of failure when comparing
            // two spans directly - use an anonymous type instead to produce pretty output.
            Assert.AreEqual(
                new { expectedSpan.iStartLine, expectedSpan.iStartIndex, expectedSpan.iEndLine, expectedSpan.iEndIndex },
                new { actualSpan.iStartLine, actualSpan.iStartIndex, actualSpan.iEndLine, actualSpan.iEndIndex });
        }
Ejemplo n.º 2
0
        private void TestMultilineCommenting(string startingText, string expectedEndingText, bool containsMultilineComment = true)
        {
            const string insertionPointString = "<enter>";

            // Find insertion point and fake enter key by putting \r\n before the insertion point.
            startingText = startingText.Replace(insertionPointString, string.Format("\r\n{0}", insertionPointString));

            // Take input text and find index of the enter.
            int insertionPosition = startingText.IndexOf(insertionPointString);

            startingText = startingText.Remove(insertionPosition, insertionPointString.Length);

            // create the view and request a multiline comment format
            var view = new MockTextView(
                new MockTextBuffer(startingText, "C:\\app.js", NodejsConstants.Nodejs));
            var insertionPoint = new SnapshotPoint(view.TextSnapshot, insertionPosition);

            // Setup mock registry service and classification provider for the IsMultilineComment method.
            var classifierProvider = new NodejsClassifierProvider(new MockContentTypeRegistryService());

            classifierProvider._classificationRegistry = new MockClassificationTypeRegistryService();
            var classifier = classifierProvider.GetClassifier(view.TextBuffer);

            SnapshotSpan commentSpan;

            if (insertionPoint.IsMultilineComment(out commentSpan))
            {
                view.FormatMultilineComment(commentSpan.Start, insertionPoint);
            }
            else if (containsMultilineComment)
            {
                Assert.Fail("This was not seen as a comment.  Something went wrong");
            }

            Assert.AreEqual(expectedEndingText, view.TextBuffer.CurrentSnapshot.GetText());
        }