コード例 #1
0
        public void TestCommentCurrentLine()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"print 'hello'
print 'goodbye'
");


            editorTestToolset.UIThread.Invoke(() => {
                view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(0).Start);
                view.CommentOrUncommentBlock(true);
            });

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

            editorTestToolset.UIThread.Invoke(() => {
                view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);
                view.CommentOrUncommentBlock(true);
            });

            Assert.AreEqual(@"#print 'hello'
#print 'goodbye'
",
                            view.GetText());
        }
コード例 #2
0
        private static async Task CodeFormattingTest(string input, object selection, string expected, object expectedSelection, CodeFormattingOptions options, bool formatSelected = true)
        {
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7));
            var editorTestToolset = new EditorTestToolset().WithPythonToolsService();

            var services = editorTestToolset.GetPythonEditorServices();

            editorTestToolset.GetService <IPythonToolsOptionsService>().ImportFrom(options);

            using (var analyzer = await VsProjectAnalyzer.CreateForTestsAsync(services, fact))
            {
                var   analysisStartedTask = EventTaskSources.VsProjectAnalyzer.AnalysisStarted.Create(analyzer);
                var   buffer = editorTestToolset.CreatePythonTextBuffer(input, analyzer);
                var   view   = editorTestToolset.CreateTextView(buffer);
                await analysisStartedTask;

                var bi    = services.GetBufferInfo(buffer);
                var entry = await analyzer.AnalyzeFileAsync(bi.Filename);

                Assert.AreEqual(entry, bi.TrySetAnalysisEntry(entry, null), "Failed to set analysis entry");
                entry.GetOrCreateBufferParser(services).AddBuffer(buffer);

                if (formatSelected)
                {
                    var selectionSpan = new SnapshotSpan(
                        buffer.CurrentSnapshot,
                        ExtractMethodTests.GetSelectionSpan(input, selection)
                        );

                    await editorTestToolset.UIThread.InvokeTask(async() =>
                    {
                        view.Selection.Select(selectionSpan, false);
                        await EditFilter.GetOrCreate(services, view).FormatSelectionAsync();
                    });
                }
                else
                {
                    await editorTestToolset.UIThread.InvokeTask(async() =>
                    {
                        await EditFilter.GetOrCreate(services, view).FormatDocumentAsync();
                    });
                }

                Assert.AreEqual(expected, view.TextBuffer.CurrentSnapshot.GetText());
                if (expectedSelection != null)
                {
                    Assert.AreEqual(
                        ExtractMethodTests.GetSelectionSpan(expected, expectedSelection),
                        view.Selection.StreamSelectionSpan.SnapshotSpan.Span
                        );
                }
            }
        }
コード例 #3
0
        public void TestUnComment()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"#print 'hello'
#print 'goodbye'");

            editorTestToolset.UIThread.Invoke(() => {
                view.SelectAll();
                view.CommentOrUncommentBlock(false);
            });

            var expected = @"print 'hello'
print 'goodbye'";

            Assert.AreEqual(expected, view.GetText());
        }
コード例 #4
0
        public void TestCommentAfterCodeIsNotUncommented()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"print 'hello' #comment that should stay a comment
#print 'still here' # another comment that should stay a comment
print 'goodbye'");

            editorTestToolset.UIThread.Invoke(() => {
                view.Select(0, view.GetText().IndexOf("print 'goodbye'"));
                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.GetText());
        }
コード例 #5
0
ファイル: CommentBlockTests.cs プロジェクト: bschnurr/PTVS
        public void TestComment()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"print 'hello'
print 'goodbye'
");

            editorTestToolset.UIThread.Invoke(() => {
                view.SelectAll();
                CommentHelper.CommentOrUncommentBlock(view, true);
            });

            Assert.AreEqual(@"#print 'hello'
#print 'goodbye'
",
                            view.GetText());
        }
コード例 #6
0
ファイル: CommentBlockTests.cs プロジェクト: bschnurr/PTVS
        public void TestCommentBlankLine()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"print('hi')

print('bye')");

            editorTestToolset.UIThread.Invoke(() => {
                view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);
                CommentHelper.CommentOrUncommentBlock(view, true);
            });

            Assert.AreEqual(@"print('hi')

print('bye')",
                            view.GetText());
        }
コード例 #7
0
ファイル: ExtractMethodTests.cs プロジェクト: PeezoSlug/PTVS
        private async Task 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 editorTestToolset = new EditorTestToolset().WithPythonToolsService();
            var services          = editorTestToolset.GetPythonEditorServices();

            using (var analyzer = await VsProjectAnalyzer.CreateForTestsAsync(services, fact))
            {
                var   analysisStartedTask = EventTaskSources.VsProjectAnalyzer.AnalysisStarted.Create(analyzer);
                var   buffer = editorTestToolset.CreatePythonTextBuffer(input, Path.Combine(TestData.GetTempPath(), "fob.py"), analyzer);
                var   view   = editorTestToolset.CreateTextView(buffer);
                await analysisStartedTask;

                var bi = services.GetBufferInfo(buffer);
                bi.ParseImmediately = true;
                var entry = await analyzer.AnalyzeFileAsync(bi.DocumentUri, bi.Filename);

                Assert.AreEqual(entry, bi.TrySetAnalysisEntry(entry, null));
                var bp = entry.GetOrCreateBufferParser(services);
                bp.AddBuffer(buffer);
                await bp.EnsureCodeSyncedAsync(bi.Buffer, true);

                ExtractMethodTestInput extractInput = new ExtractMethodTestInput(true, scopeName, targetName, parameters ?? new string[0]);
                await editorTestToolset.UIThread.InvokeTask(() =>
                {
                    view.Selection.Select(new SnapshotSpan(view.TextBuffer.CurrentSnapshot, extract()), false);
                    return(new Microsoft.PythonTools.Refactoring.MethodExtractor(services, view).ExtractMethod(extractInput));
                });

                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());
                }
            }
        }
コード例 #8
0
        public void TestUnCommentIndented()
        {
            var editorTestToolset = new EditorTestToolset();
            var view = editorTestToolset.CreatePythonTextView(@"def f():
    #print 'hello'
    #print 'still here'
    print 'goodbye'");

            editorTestToolset.UIThread.Invoke(() => {
                view.Select(@"    #print 'hello'
    #print 'still here'");
                view.CommentOrUncommentBlock(false);
            });

            Assert.AreEqual(@"def f():
    print 'hello'
    print 'still here'
    print 'goodbye'",
                            view.GetText());
        }