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 services = PythonToolsTestUtilities.CreateMockServiceProvider().GetEditorServices(); using (var analyzer = new VsProjectAnalyzer(services, fact)) { var buffer = new MockTextBuffer(input, PythonCoreConstants.ContentType, "C:\\fob.py"); buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer); var view = new MockTextView(buffer); analyzer.MonitorTextBufferAsync(buffer).Wait(); var selectionSpan = new SnapshotSpan( buffer.CurrentSnapshot, ExtractMethodTests.GetSelectionSpan(input, selection) ); view.Selection.Select(selectionSpan, false); analyzer.FormatCodeAsync( selectionSpan, view, options, selectResult ).Wait(); Assert.AreEqual(expected, view.TextBuffer.CurrentSnapshot.GetText()); if (expectedSelection != null) { Assert.AreEqual( ExtractMethodTests.GetSelectionSpan(expected, expectedSelection), view.Selection.StreamSelectionSpan.SnapshotSpan.Span ); } } }
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 ); } } }
private static async Task CodeFormattingTest(string input, object selection, string expected, object expectedSelection, CodeFormattingOptions options, bool selectResult = true) { var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7)); var services = PythonToolsTestUtilities.CreateMockServiceProvider().GetEditorServices(); using (var analyzer = await VsProjectAnalyzer.CreateForTestsAsync(services, fact)) { var buffer = new MockTextBuffer(input, PythonCoreConstants.ContentType, Path.Combine(TestData.GetTempPath(), "fob.py")); buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer); var view = new MockTextView(buffer); 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); var selectionSpan = new SnapshotSpan( buffer.CurrentSnapshot, ExtractMethodTests.GetSelectionSpan(input, selection) ); view.Selection.Select(selectionSpan, false); await analyzer.FormatCodeAsync( selectionSpan, view, options, selectResult ); Assert.AreEqual(expected, view.TextBuffer.CurrentSnapshot.GetText()); if (expectedSelection != null) { Assert.AreEqual( ExtractMethodTests.GetSelectionSpan(expected, expectedSelection), view.Selection.StreamSelectionSpan.SnapshotSpan.Span ); } } }