Exemplo 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 });
        }