private void OneRefactorTest(string newName, string caretText, FileInput[] inputs, Version version, bool preview, string error, ExpectedPreviewItem[] expected = null) { Console.WriteLine("Replacing {0} with {1}", caretText, newName); version = version ?? new Version(2, 7); for (int loops = 0; loops < 2; loops++) { var views = new List<PythonEditor>(); try { var mainView = new PythonEditor(inputs[0].Input, version.ToLanguageVersion(), _vs, filename: inputs[0].Filename); var analyzer = mainView.Analyzer; views.Add(mainView); var bufferTable = new Dictionary<string, ITextBuffer> { { inputs[0].Filename, mainView.CurrentSnapshot.TextBuffer } }; foreach (var i in inputs.Skip(1)) { var editor = new PythonEditor(i.Input, version.ToLanguageVersion(), _vs, mainView.Factory, analyzer, i.Filename); views.Add(editor); bufferTable[i.Filename] = editor.CurrentSnapshot.TextBuffer; } // test runs twice, one w/ original buffer, once w/ re-analyzed buffers. if (loops == 1) { // do it again w/ a changed buffer mainView.Text = mainView.Text; } var caretPos = inputs[0].Input.IndexOf(caretText); mainView.View.MoveCaret(new SnapshotPoint(mainView.CurrentSnapshot, caretPos)); var extractInput = new RenameVariableTestInput(newName, bufferTable, preview); var previewChangesService = new TestPreviewChanges(expected); new VariableRenamer(views[0].View.View, _vs.ServiceProvider).RenameVariable(extractInput, previewChangesService); if (error != null) { Assert.AreEqual(error, extractInput.Failure); return; } Assert.IsNull(extractInput.Failure, "Unexpected error message: " + (extractInput.Failure ?? "")); Assert.AreEqual(preview, previewChangesService.Previewed, preview ? "Changes were not previewed" : "Changes were previewed"); AssertUtil.ArrayEquals(inputs.Select(i => i.Output).ToList(), views.Select(v => v.Text).ToList()); } finally { views.Reverse(); foreach (var v in views) { v.Dispose(); } } } }