findTest('replaceAll bla with \\t\\n', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'bla', replaceString: '<\\n\\t>', isRegex: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [11, 4, 11, 7], [11, 7, 11, 10], [11, 10, 11, 13] ] ); findModel.replaceAll(); assertFindState( editor, [1, 1, 1, 1], null, [] ); assert.equal(editor.getModel().getLineContent(11), '// <'); assert.equal(editor.getModel().getLineContent(12), '\t><'); assert.equal(editor.getModel().getLineContent(13), '\t><'); assert.equal(editor.getModel().getLineContent(14), '\t>ciao'); findModel.dispose(); findState.dispose(); });
findTest('issue #3516: "replace all" moves page/cursor/focus/scroll to the place of the last replacement', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'include', replaceString: 'bar' }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [2, 2, 2, 9], [3, 2, 3, 9] ] ); findModel.replaceAll(); assertFindState( editor, [1, 1, 1, 1], null, [] ); assert.equal(editor.getModel().getLineContent(2), '#bar "cool.h"'); assert.equal(editor.getModel().getLineContent(3), '#bar <iostream>'); findModel.dispose(); findState.dispose(); });
findTest('replaceAll bla', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'bla', replaceString: 'ciao' }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [11, 4, 11, 7], [11, 7, 11, 10], [11, 10, 11, 13] ] ); findModel.replaceAll(); assertFindState( editor, [1, 1, 1, 1], null, [] ); assert.equal(editor.getModel().getLineContent(11), '// ciaociaociaociao'); findModel.dispose(); findState.dispose(); });
findTest('issue #18711 replaceAll with empty string', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'hello', replaceString: '', wholeWord: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [6, 14, 6, 19], [6, 27, 6, 32], [7, 14, 7, 19], [8, 14, 8, 19] ] ); findModel.replaceAll(); assertFindState( editor, [1, 1, 1, 1], null, [] ); assert.equal(editor.getModel().getLineContent(6), ' cout << " world, !" << endl;'); assert.equal(editor.getModel().getLineContent(7), ' cout << " world again" << endl;'); assert.equal(editor.getModel().getLineContent(8), ' cout << " world again" << endl;'); findModel.dispose(); findState.dispose(); });
findTest('find .*', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: '.*', isRegex: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [1, 1, 1, 18], [2, 1, 2, 18], [3, 1, 3, 20], [4, 1, 4, 1], [5, 1, 5, 13], [6, 1, 6, 43], [7, 1, 7, 41], [8, 1, 8, 41], [9, 1, 9, 40], [10, 1, 10, 2], [11, 1, 11, 17], [12, 1, 12, 1], ] ); findModel.dispose(); findState.dispose(); });
findTest('find model next/prev with no matches', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'helloo', wholeWord: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.moveToNextMatch(); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.moveToPrevMatch(); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.dispose(); findState.dispose(); });
findTest('issue #19740 Find and replace capture group/backreference inserts `undefined` instead of empty string', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'hello(z)?', replaceString: 'hi$1', isRegex: true, matchCase: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [6, 14, 6, 19], [7, 14, 7, 19], [9, 14, 9, 19] ] ); findModel.replaceAll(); assertFindState( editor, [1, 1, 1, 1], null, [] ); assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;'); assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;'); assert.equal(editor.getModel().getLineContent(9), ' cout << "hiworld again" << endl;'); findModel.dispose(); findState.dispose(); });
findTest('find model updates state matchesCount', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'hello' }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assert.equal(findState.matchesCount, 5); assertFindState( editor, [1, 1, 1, 1], null, [ [6, 14, 6, 19], [6, 27, 6, 32], [7, 14, 7, 19], [8, 14, 8, 19], [9, 14, 9, 19] ] ); findState.change({ searchString: 'helloo' }, false); assert.equal(findState.matchesCount, 0); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.dispose(); findState.dispose(); });
findTest('replaceAll when search string is multiline and has look ahed regex and replace string has capturing groups', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'wo(rl)d(.*;\\n)(?=.*hello)', replaceString: 'gi$1$2', isRegex: true, matchCase: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [6, 20, 7, 1], [8, 20, 9, 1] ] ); findModel.replaceAll(); assert.equal(editor.getModel().getLineContent(6), ' cout << "hello girl, Hello!" << endl;'); assert.equal(editor.getModel().getLineContent(8), ' cout << "Hello girl again" << endl;'); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.dispose(); findState.dispose(); });
findTest('replaceAll when search string has look ahed regex', (editor, cursor) => { let findState = new FindReplaceState(); findState.change({ searchString: 'hello(?=\\sworld)', replaceString: 'hi', isRegex: true }, false); let findModel = new FindModelBoundToEditorModel(editor, findState); assertFindState( editor, [1, 1, 1, 1], null, [ [6, 14, 6, 19], [7, 14, 7, 19], [8, 14, 8, 19] ] ); findModel.replaceAll(); assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;'); assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;'); assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;'); assertFindState( editor, [1, 1, 1, 1], null, [] ); findModel.dispose(); findState.dispose(); });