@@ -11,6 +11,7 @@ import {initialize, closeActiveWindows} from './initialize';
1111import { execPythonFile } from '../client/common/utils' ;
1212import { extractVariable , extractMethod } from '../client/providers/simpleRefactorProvider' ;
1313import { RefactorProxy } from '../client/refactor/proxy' ;
14+ import { getTextEditsFromPatch } from '../client/common/editor' ;
1415
1516let EXTENSION_DIR = path . join ( __dirname , '..' , '..' ) ;
1617let pythonSettings = settings . PythonSettings . getInstance ( ) ;
@@ -119,8 +120,6 @@ suite('Method Extraction', () => {
119120
120121 function testingMethodExtraction ( shouldError : boolean , pythonSettings : settings . IPythonSettings , startPos : Position , endPos : Position ) {
121122 let ch = new MockOutputChannel ( 'Python' ) ;
122- let textDocument : vscode . TextDocument ;
123- let textEditor : vscode . TextEditor ;
124123 let rangeOfTextToExtract = new vscode . Range ( startPos , endPos ) ;
125124 let proxy = new RefactorProxy ( EXTENSION_DIR , pythonSettings , path . dirname ( refactorTargetFile ) ) ;
126125 let mockTextDoc = new MockTextDocument ( refactorTargetFile , [
@@ -129,11 +128,17 @@ suite('Method Extraction', () => {
129128 ] ) ;
130129
131130 const DIFF = `--- a/refactor.py\n+++ b/refactor.py\n@@ -237,9 +237,12 @@\n try:\n self._process_request(self._input.readline())\n except Exception as ex:\n- message = ex.message + ' \\n' + traceback.format_exc()\n- sys.stderr.write(str(len(message)) + ':' + message)\n- sys.stderr.flush()\n+ self.myNewMethod(ex)\n+\n+ def myNewMethod(self, ex):\n+ message = ex.message + ' \\n' + traceback.format_exc()\n+ sys.stderr.write(str(len(message)) + ':' + message)\n+ sys.stderr.flush()\n \n if __name__ == '__main__':\n RopeRefactoring().watch()\n` ;
131+ let expectedTextEdits = getTextEditsFromPatch ( mockTextDoc . getText ( ) , DIFF ) ;
132132
133133 return proxy . extractMethod < RenameResponse > ( mockTextDoc , 'myNewMethod' , refactorTargetFile , rangeOfTextToExtract )
134134 . then ( response => {
135+ let textEdits = getTextEditsFromPatch ( mockTextDoc . getText ( ) , DIFF ) ;
135136 assert . equal ( response . results . length , 1 , 'Invalid number of items in response' ) ;
136- assert . equal ( response . results [ 0 ] . diff , DIFF , 'Invalid DIFF' ) ;
137+ assert . equal ( textEdits . length , expectedTextEdits . length , 'Invalid number of Text Edits' ) ;
138+ textEdits . forEach ( edit => {
139+ let foundEdit = expectedTextEdits . filter ( item => item . newText === edit . newText && item . range . isEqual ( edit . range ) ) ;
140+ assert . equal ( foundEdit . length , 1 , 'Edit not found' ) ;
141+ } ) ;
137142 } ) . catch ( error => {
138143 if ( shouldError ) {
139144 // Wait a minute this shouldn't work, what's going on
0 commit comments