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