示例#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 });
        }
示例#2
0
        public void TestComment() {
            var view = new MockTextView(
                new MockTextBuffer(@"console.log('Hello');
console.log('Goodbye');"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.Length)),
                false
            );

            view.CommentOrUncommentBlock(true);

            Assert.AreEqual(@"//console.log('Hello');
//console.log('Goodbye');",
                 view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#3
0
        public void TestComment() {
            var view = new MockTextView(
                MockTextBuffer(@"print 'hello'
print 'goodbye'
"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.Length)),
                false
            );

            view.CommentOrUncommentBlock(true);

            Assert.AreEqual(@"#print 'hello'
#print 'goodbye'
",
                 view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#4
0
        public void TestUnCommentCurrentLine() {
            var view = new MockTextView(
                new MockTextBuffer(@"//console.log('Hello');
//console.log('Goodbye');"));

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(0).Start);

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"console.log('Hello');
//console.log('Goodbye');",
                 view.TextBuffer.CurrentSnapshot.GetText());

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"console.log('Hello');
console.log('Goodbye');",
                view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#5
0
        public void TestUnCommentCurrentLine() {
            var view = new MockTextView(
                MockTextBuffer(@"#print 'hello'
#print 'goodbye'"));

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(0).Start);

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"print 'hello'
#print 'goodbye'", 
                 view.TextBuffer.CurrentSnapshot.GetText());

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"print 'hello'
print 'goodbye'",
                view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#6
0
 public MockTextCaret(MockTextView view) {
     _view = view;
 }
示例#7
0
        public void TestCommentAfterCodeIsNotUncommented() {
            var view = new MockTextView(
                new MockTextBuffer(@"console.log('Hello');//comment that should stay a comment;
//console.log('Still here');//another comment that should stay a comment;
console.log('Goodbye');"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.GetText().IndexOf("console.log('Goodbye');"))),
                false
            );

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"console.log('Hello');//comment that should stay a comment;
console.log('Still here');//another comment that should stay a comment;
console.log('Goodbye');",
                view.TextBuffer.CurrentSnapshot.GetText());
        }
 public MockIncrementalSearch(MockTextView textView) {
     _view = textView;
 }
示例#9
0
 public MockBufferGraph(MockTextView view) {
     _view = view;
     _buffers.Add(view.TextBuffer);
 }
示例#10
0
        public void TestUnCommentIndented() {
            var view = new MockTextView(
                MockTextBuffer(@"def f():
    #print 'hello'
    #print 'still here'
    print 'goodbye'"));

            view.Selection.Select(
                new SnapshotSpan(
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start,
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(2).End
                ),
                false
            );

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"def f():
    print 'hello'
    print 'still here'
    print 'goodbye'",
                    view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#11
0
        public void TestCommentAfterCodeIsNotUncommented()
        {
            var view = new MockTextView(
                MockTextBuffer(@"print 'hello' #comment that should stay a comment
#print 'still here' # another comment that should stay a comment
print 'goodbye'"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.GetText().IndexOf("print 'goodbye'"))),
                false
            );

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"print 'hello' #comment that should stay a comment
print 'still here' # another comment that should stay a comment
print 'goodbye'",
                view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#12
0
 public MockTextCaret(MockTextView view)
 {
     _view     = view;
     _position = new MockTrackingPoint((MockTextSnapshot)_view.TextBuffer.CurrentSnapshot, 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(content: startingText, contentType: NodejsConstants.Nodejs, filename: "C:\\app.js"));
            var insertionPoint = new SnapshotPoint(view.TextSnapshot, insertionPosition);

            // Setup mock registry service and classification provider for the IsMultilineComment method.
            var classifierProvider = new NodejsClassifierProvider(new MockContentTypeRegistryService(NodejsConstants.Nodejs));
            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());
        }
示例#14
0
 public MockTextCaret(MockTextView view) {
     _view = view;
     _position = new MockTrackingPoint((MockTextSnapshot)_view.TextBuffer.CurrentSnapshot, 0);
 }
示例#15
0
 public MockReplWindow(IReplEvaluator eval, string contentType = "Python") {            
     _eval = eval;
     _contentType = contentType;
     _view = new MockTextView(new MockTextBuffer(String.Empty, "text"));
     _eval.Initialize(this);
 }
示例#16
0
        private static void CodeFormattingTest(string input, object selection, string expected, object expectedSelection, CodeFormattingOptions options, bool selectResult = true) {
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7));
            var serviceProvider = PythonToolsTestUtilities.CreateMockServiceProvider();
            using (var analyzer = new VsProjectAnalyzer(serviceProvider, fact, new[] { fact })) {
                var buffer = new MockTextBuffer(input, PythonCoreConstants.ContentType, "C:\\fob.py");
                buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer);
                var view = new MockTextView(buffer);
                var selectionSpan = new SnapshotSpan(
                    buffer.CurrentSnapshot,
                    ExtractMethodTests.GetSelectionSpan(input, selection)
                );
                view.Selection.Select(selectionSpan, false);

                new CodeFormatter(serviceProvider, view, options).FormatCode(
                    selectionSpan,
                    selectResult
                );

                Assert.AreEqual(expected, view.TextBuffer.CurrentSnapshot.GetText());
                if (expectedSelection != null) {
                    Assert.AreEqual(
                        ExtractMethodTests.GetSelectionSpan(expected, expectedSelection),
                        view.Selection.StreamSelectionSpan.SnapshotSpan.Span
                    );
                }
            }
        }
示例#17
0
        private void ExtractMethodTest(string input, Func<Span> extract, TestResult expected, string scopeName = null, string targetName = "g", Version version = null, params string[] parameters) {
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version ?? new Version(2, 7));
            var serviceProvider = PythonToolsTestUtilities.CreateMockServiceProvider();
            using (var analyzer = new VsProjectAnalyzer(serviceProvider, fact)) {
                var buffer = new MockTextBuffer(input, "Python", "C:\\fob.py");
                var view = new MockTextView(buffer);
                buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer);
                analyzer.MonitorTextBufferAsync(buffer).Wait();
                var extractInput = new ExtractMethodTestInput(true, scopeName, targetName, parameters ?? new string[0]);

                view.Selection.Select(
                    new SnapshotSpan(view.TextBuffer.CurrentSnapshot, extract()),
                    false
                );

                new MethodExtractor(serviceProvider, view).ExtractMethod(extractInput).Wait();

                if (expected.IsError) {
                    Assert.AreEqual(expected.Text, extractInput.FailureReason);
                    Assert.AreEqual(input, view.TextBuffer.CurrentSnapshot.GetText());
                } else {
                    Assert.AreEqual(null, extractInput.FailureReason);
                    Assert.AreEqual(expected.Text, view.TextBuffer.CurrentSnapshot.GetText());
                }
            }
        }
示例#18
0
        public void TestCommentBlankLine() {
            var view = new MockTextView(
                new MockTextBuffer(@"console.log('hi');

console.log('bye');"));

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);

            view.CommentOrUncommentBlock(true);

            Assert.AreEqual(@"console.log('hi');

console.log('bye');",
             view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#19
0
 public MockTextCaret(MockTextView view)
 {
     _view = view;
 }
示例#20
0
        public void TestUnCommentIndented() {
            var view = new MockTextView(
                new MockTextBuffer(@"function f(){
    //console.log('Hello');
    //console.log('Still here');
    console.log('Goodbye');
}"));

            view.Selection.Select(
                new SnapshotSpan(
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start,
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(2).End
                ),
                false
            );

            view.CommentOrUncommentBlock(false);

            Assert.AreEqual(@"function f(){
    console.log('Hello');
    console.log('Still here');
    console.log('Goodbye');
}",
                    view.TextBuffer.CurrentSnapshot.GetText());
        }
示例#21
0
 public MockBufferGraph(MockTextView view)
 {
     _view = view;
     _buffers.Add(view.TextBuffer);
 }
示例#22
0
 public MockEditorOperations(MockTextView textView) {
     _view = textView;
 }