Best JavaScript code snippet using mountebank
vim_test.js
Source:vim_test.js
1var code = '' +2' wOrd1 (#%\n' +3' word3] \n' +4'aopop pop 0 1 2 3 4\n' +5' (a) [b] {c} \n' +6'int getchar(void) {\n' +7' static char buf[BUFSIZ];\n' +8' static char *bufp = buf;\n' +9' if (n == 0) { /* buffer is empty */\n' +10' n = read(0, buf, sizeof buf);\n' +11' bufp = buf;\n' +12' }\n' +13'\n' +14' return (--n >= 0) ? (unsigned char) *bufp++ : EOF;\n' +15' \n' +16'}\n';17var lines = (function() {18 lineText = code.split('\n');19 var ret = [];20 for (var i = 0; i < lineText.length; i++) {21 ret[i] = {22 line: i,23 length: lineText[i].length,24 lineText: lineText[i],25 textStart: /^\s*/.exec(lineText[i])[0].length26 };27 }28 return ret;29})();30var endOfDocument = makeCursor(lines.length - 1,31 lines[lines.length - 1].length);32var wordLine = lines[0];33var bigWordLine = lines[1];34var charLine = lines[2];35var bracesLine = lines[3];36var seekBraceLine = lines[4];37var word1 = {38 start: { line: wordLine.line, ch: 1 },39 end: { line: wordLine.line, ch: 5 }40};41var word2 = {42 start: { line: wordLine.line, ch: word1.end.ch + 2 },43 end: { line: wordLine.line, ch: word1.end.ch + 4 }44};45var word3 = {46 start: { line: bigWordLine.line, ch: 1 },47 end: { line: bigWordLine.line, ch: 5 }48};49var bigWord1 = word1;50var bigWord2 = word2;51var bigWord3 = {52 start: { line: bigWordLine.line, ch: 1 },53 end: { line: bigWordLine.line, ch: 7 }54};55var bigWord4 = {56 start: { line: bigWordLine.line, ch: bigWord1.end.ch + 3 },57 end: { line: bigWordLine.line, ch: bigWord1.end.ch + 7 }58};59var oChars = [ { line: charLine.line, ch: 1 },60 { line: charLine.line, ch: 3 },61 { line: charLine.line, ch: 7 } ];62var pChars = [ { line: charLine.line, ch: 2 },63 { line: charLine.line, ch: 4 },64 { line: charLine.line, ch: 6 },65 { line: charLine.line, ch: 8 } ];66var numChars = [ { line: charLine.line, ch: 10 },67 { line: charLine.line, ch: 12 },68 { line: charLine.line, ch: 14 },69 { line: charLine.line, ch: 16 },70 { line: charLine.line, ch: 18 }];71var parens1 = {72 start: { line: bracesLine.line, ch: 1 },73 end: { line: bracesLine.line, ch: 3 }74};75var squares1 = {76 start: { line: bracesLine.line, ch: 5 },77 end: { line: bracesLine.line, ch: 7 }78};79var curlys1 = {80 start: { line: bracesLine.line, ch: 9 },81 end: { line: bracesLine.line, ch: 11 }82};83var seekOutside = {84 start: { line: seekBraceLine.line, ch: 1 },85 end: { line: seekBraceLine.line, ch: 16 }86};87var seekInside = {88 start: { line: seekBraceLine.line, ch: 14 },89 end: { line: seekBraceLine.line, ch: 11 }90};91function copyCursor(cur) {92 return { ch: cur.ch, line: cur.line };93}94function testVim(name, run, opts, expectedFail) {95 var vimOpts = {96 lineNumbers: true,97 vimMode: true,98 showCursorWhenSelecting: true,99 value: code100 };101 for (var prop in opts) {102 if (opts.hasOwnProperty(prop)) {103 vimOpts[prop] = opts[prop];104 }105 }106 return test('vim_' + name, function() {107 var place = document.getElementById("testground");108 var cm = CodeMirror(place, vimOpts);109 var vim = CodeMirror.Vim.maybeInitVimState_(cm);110 function doKeysFn(cm) {111 return function(args) {112 if (args instanceof Array) {113 arguments = args;114 }115 for (var i = 0; i < arguments.length; i++) {116 CodeMirror.Vim.handleKey(cm, arguments[i]);117 }118 }119 }120 function doInsertModeKeysFn(cm) {121 return function(args) {122 if (args instanceof Array) { arguments = args; }123 function executeHandler(handler) {124 if (typeof handler == 'string') {125 CodeMirror.commands[handler](cm);126 } else {127 handler(cm);128 }129 return true;130 }131 for (var i = 0; i < arguments.length; i++) {132 var key = arguments[i];133 // Find key in keymap and handle.134 var handled = CodeMirror.lookupKey(key, ['vim-insert'], executeHandler);135 // Record for insert mode.136 if (handled === true && cm.state.vim.insertMode && arguments[i] != 'Esc') {137 var lastChange = CodeMirror.Vim.getVimGlobalState_().macroModeState.lastInsertModeChanges;138 if (lastChange) {139 lastChange.changes.push(new CodeMirror.Vim.InsertModeKey(key));140 }141 }142 }143 }144 }145 function doExFn(cm) {146 return function(command) {147 cm.openDialog = helpers.fakeOpenDialog(command);148 helpers.doKeys(':');149 }150 }151 function assertCursorAtFn(cm) {152 return function(line, ch) {153 var pos;154 if (ch == null && typeof line.line == 'number') {155 pos = line;156 } else {157 pos = makeCursor(line, ch);158 }159 eqPos(pos, cm.getCursor());160 }161 }162 function fakeOpenDialog(result) {163 return function(text, callback) {164 return callback(result);165 }166 }167 var helpers = {168 doKeys: doKeysFn(cm),169 // Warning: Only emulates keymap events, not character insertions. Use170 // replaceRange to simulate character insertions.171 // Keys are in CodeMirror format, NOT vim format.172 doInsertModeKeys: doInsertModeKeysFn(cm),173 doEx: doExFn(cm),174 assertCursorAt: assertCursorAtFn(cm),175 fakeOpenDialog: fakeOpenDialog,176 getRegisterController: function() {177 return CodeMirror.Vim.getRegisterController();178 }179 }180 CodeMirror.Vim.resetVimGlobalState_();181 var successful = false;182 try {183 run(cm, vim, helpers);184 successful = true;185 } finally {186 if ((debug && !successful) || verbose) {187 place.style.visibility = "visible";188 } else {189 place.removeChild(cm.getWrapperElement());190 }191 }192 }, expectedFail);193};194testVim('qq@q', function(cm, vim, helpers) {195 cm.setCursor(0, 0);196 helpers.doKeys('q', 'q', 'l', 'l', 'q');197 helpers.assertCursorAt(0,2);198 helpers.doKeys('@', 'q');199 helpers.assertCursorAt(0,4);200}, { value: ' '});201testVim('@@', function(cm, vim, helpers) {202 cm.setCursor(0, 0);203 helpers.doKeys('q', 'q', 'l', 'l', 'q');204 helpers.assertCursorAt(0,2);205 helpers.doKeys('@', 'q');206 helpers.assertCursorAt(0,4);207 helpers.doKeys('@', '@');208 helpers.assertCursorAt(0,6);209}, { value: ' '});210var jumplistScene = ''+211 'word\n'+212 '(word)\n'+213 '{word\n'+214 'word.\n'+215 '\n'+216 'word search\n'+217 '}word\n'+218 'word\n'+219 'word\n';220function testJumplist(name, keys, endPos, startPos, dialog) {221 endPos = makeCursor(endPos[0], endPos[1]);222 startPos = makeCursor(startPos[0], startPos[1]);223 testVim(name, function(cm, vim, helpers) {224 CodeMirror.Vim.resetVimGlobalState_();225 if(dialog)cm.openDialog = helpers.fakeOpenDialog('word');226 cm.setCursor(startPos);227 helpers.doKeys.apply(null, keys);228 helpers.assertCursorAt(endPos);229 }, {value: jumplistScene});230};231testJumplist('jumplist_H', ['H', '<C-o>'], [5,2], [5,2]);232testJumplist('jumplist_M', ['M', '<C-o>'], [2,2], [2,2]);233testJumplist('jumplist_L', ['L', '<C-o>'], [2,2], [2,2]);234testJumplist('jumplist_[[', ['[', '[', '<C-o>'], [5,2], [5,2]);235testJumplist('jumplist_]]', [']', ']', '<C-o>'], [2,2], [2,2]);236testJumplist('jumplist_G', ['G', '<C-o>'], [5,2], [5,2]);237testJumplist('jumplist_gg', ['g', 'g', '<C-o>'], [5,2], [5,2]);238testJumplist('jumplist_%', ['%', '<C-o>'], [1,5], [1,5]);239testJumplist('jumplist_{', ['{', '<C-o>'], [1,5], [1,5]);240testJumplist('jumplist_}', ['}', '<C-o>'], [1,5], [1,5]);241testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', '<C-i>'], [1,5], [1,5]);242testJumplist('jumplist_`', ['m', 'a', 'h', '`', 'a', 'h', '<C-i>'], [1,5], [1,5]);243testJumplist('jumplist_*_cachedCursor', ['*', '<C-o>'], [1,3], [1,3]);244testJumplist('jumplist_#_cachedCursor', ['#', '<C-o>'], [1,3], [1,3]);245testJumplist('jumplist_n', ['#', 'n', '<C-o>'], [1,1], [2,3]);246testJumplist('jumplist_N', ['#', 'N', '<C-o>'], [1,1], [2,3]);247testJumplist('jumplist_repeat_<c-o>', ['*', '*', '*', '3', '<C-o>'], [2,3], [2,3]);248testJumplist('jumplist_repeat_<c-i>', ['*', '*', '*', '3', '<C-o>', '2', '<C-i>'], [5,0], [2,3]);249testJumplist('jumplist_repeated_motion', ['3', '*', '<C-o>'], [2,3], [2,3]);250testJumplist('jumplist_/', ['/', '<C-o>'], [2,3], [2,3], 'dialog');251testJumplist('jumplist_?', ['?', '<C-o>'], [2,3], [2,3], 'dialog');252testJumplist('jumplist_skip_delted_mark<c-o>',253 ['*', 'n', 'n', 'k', 'd', 'k', '<C-o>', '<C-o>', '<C-o>'],254 [0,2], [0,2]);255testJumplist('jumplist_skip_delted_mark<c-i>',256 ['*', 'n', 'n', 'k', 'd', 'k', '<C-o>', '<C-i>', '<C-i>'],257 [1,0], [0,2]);258/**259 * @param name Name of the test260 * @param keys An array of keys or a string with a single key to simulate.261 * @param endPos The expected end position of the cursor.262 * @param startPos The position the cursor should start at, defaults to 0, 0.263 */264function testMotion(name, keys, endPos, startPos) {265 testVim(name, function(cm, vim, helpers) {266 if (!startPos) {267 startPos = { line: 0, ch: 0 };268 }269 cm.setCursor(startPos);270 helpers.doKeys(keys);271 helpers.assertCursorAt(endPos);272 });273};274function makeCursor(line, ch) {275 return { line: line, ch: ch };276};277function offsetCursor(cur, offsetLine, offsetCh) {278 return { line: cur.line + offsetLine, ch: cur.ch + offsetCh };279};280// Motion tests281testMotion('|', '|', makeCursor(0, 0), makeCursor(0,4));282testMotion('|_repeat', ['3', '|'], makeCursor(0, 2), makeCursor(0,4));283testMotion('h', 'h', makeCursor(0, 0), word1.start);284testMotion('h_repeat', ['3', 'h'], offsetCursor(word1.end, 0, -3), word1.end);285testMotion('l', 'l', makeCursor(0, 1));286testMotion('l_repeat', ['2', 'l'], makeCursor(0, 2));287testMotion('j', 'j', offsetCursor(word1.end, 1, 0), word1.end);288testMotion('j_repeat', ['2', 'j'], offsetCursor(word1.end, 2, 0), word1.end);289testMotion('j_repeat_clip', ['1000', 'j'], endOfDocument);290testMotion('k', 'k', offsetCursor(word3.end, -1, 0), word3.end);291testMotion('k_repeat', ['2', 'k'], makeCursor(0, 4), makeCursor(2, 4));292testMotion('k_repeat_clip', ['1000', 'k'], makeCursor(0, 4), makeCursor(2, 4));293testMotion('w', 'w', word1.start);294testMotion('w_multiple_newlines_no_space', 'w', makeCursor(12, 2), makeCursor(11, 2));295testMotion('w_multiple_newlines_with_space', 'w', makeCursor(14, 0), makeCursor(12, 51));296testMotion('w_repeat', ['2', 'w'], word2.start);297testMotion('w_wrap', ['w'], word3.start, word2.start);298testMotion('w_endOfDocument', 'w', endOfDocument, endOfDocument);299testMotion('w_start_to_end', ['1000', 'w'], endOfDocument, makeCursor(0, 0));300testMotion('W', 'W', bigWord1.start);301testMotion('W_repeat', ['2', 'W'], bigWord3.start, bigWord1.start);302testMotion('e', 'e', word1.end);303testMotion('e_repeat', ['2', 'e'], word2.end);304testMotion('e_wrap', 'e', word3.end, word2.end);305testMotion('e_endOfDocument', 'e', endOfDocument, endOfDocument);306testMotion('e_start_to_end', ['1000', 'e'], endOfDocument, makeCursor(0, 0));307testMotion('b', 'b', word3.start, word3.end);308testMotion('b_repeat', ['2', 'b'], word2.start, word3.end);309testMotion('b_wrap', 'b', word2.start, word3.start);310testMotion('b_startOfDocument', 'b', makeCursor(0, 0), makeCursor(0, 0));311testMotion('b_end_to_start', ['1000', 'b'], makeCursor(0, 0), endOfDocument);312testMotion('ge', ['g', 'e'], word2.end, word3.end);313testMotion('ge_repeat', ['2', 'g', 'e'], word1.end, word3.start);314testMotion('ge_wrap', ['g', 'e'], word2.end, word3.start);315testMotion('ge_startOfDocument', ['g', 'e'], makeCursor(0, 0),316 makeCursor(0, 0));317testMotion('ge_end_to_start', ['1000', 'g', 'e'], makeCursor(0, 0), endOfDocument);318testMotion('gg', ['g', 'g'], makeCursor(lines[0].line, lines[0].textStart),319 makeCursor(3, 1));320testMotion('gg_repeat', ['3', 'g', 'g'],321 makeCursor(lines[2].line, lines[2].textStart));322testMotion('G', 'G',323 makeCursor(lines[lines.length - 1].line, lines[lines.length - 1].textStart),324 makeCursor(3, 1));325testMotion('G_repeat', ['3', 'G'], makeCursor(lines[2].line,326 lines[2].textStart));327// TODO: Make the test code long enough to test Ctrl-F and Ctrl-B.328testMotion('0', '0', makeCursor(0, 0), makeCursor(0, 8));329testMotion('^', '^', makeCursor(0, lines[0].textStart), makeCursor(0, 8));330testMotion('+', '+', makeCursor(1, lines[1].textStart), makeCursor(0, 8));331testMotion('-', '-', makeCursor(0, lines[0].textStart), makeCursor(1, 4));332testMotion('_', ['6','_'], makeCursor(5, lines[5].textStart), makeCursor(0, 8));333testMotion('$', '$', makeCursor(0, lines[0].length - 1), makeCursor(0, 1));334testMotion('$_repeat', ['2', '$'], makeCursor(1, lines[1].length - 1),335 makeCursor(0, 3));336testMotion('f', ['f', 'p'], pChars[0], makeCursor(charLine.line, 0));337testMotion('f_repeat', ['2', 'f', 'p'], pChars[2], pChars[0]);338testMotion('f_num', ['f', '2'], numChars[2], makeCursor(charLine.line, 0));339testMotion('t', ['t','p'], offsetCursor(pChars[0], 0, -1),340 makeCursor(charLine.line, 0));341testMotion('t_repeat', ['2', 't', 'p'], offsetCursor(pChars[2], 0, -1),342 pChars[0]);343testMotion('F', ['F', 'p'], pChars[0], pChars[1]);344testMotion('F_repeat', ['2', 'F', 'p'], pChars[0], pChars[2]);345testMotion('T', ['T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[1]);346testMotion('T_repeat', ['2', 'T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[2]);347testMotion('%_parens', ['%'], parens1.end, parens1.start);348testMotion('%_squares', ['%'], squares1.end, squares1.start);349testMotion('%_braces', ['%'], curlys1.end, curlys1.start);350testMotion('%_seek_outside', ['%'], seekOutside.end, seekOutside.start);351testMotion('%_seek_inside', ['%'], seekInside.end, seekInside.start);352testVim('%_seek_skip', function(cm, vim, helpers) {353 cm.setCursor(0,0);354 helpers.doKeys(['%']);355 helpers.assertCursorAt(0,9);356}, {value:'01234"("()'});357testVim('%_skip_string', function(cm, vim, helpers) {358 cm.setCursor(0,0);359 helpers.doKeys(['%']);360 helpers.assertCursorAt(0,4);361 cm.setCursor(0,2);362 helpers.doKeys(['%']);363 helpers.assertCursorAt(0,0);364}, {value:'(")")'});365(')')366testVim('%_skip_comment', function(cm, vim, helpers) {367 cm.setCursor(0,0);368 helpers.doKeys(['%']);369 helpers.assertCursorAt(0,6);370 cm.setCursor(0,3);371 helpers.doKeys(['%']);372 helpers.assertCursorAt(0,0);373}, {value:'(/*)*/)'});374// Make sure that moving down after going to the end of a line always leaves you375// at the end of a line, but preserves the offset in other cases376testVim('Changing lines after Eol operation', function(cm, vim, helpers) {377 cm.setCursor(0,0);378 helpers.doKeys(['$']);379 helpers.doKeys(['j']);380 // After moving to Eol and then down, we should be at Eol of line 2381 helpers.assertCursorAt({ line: 1, ch: lines[1].length - 1 });382 helpers.doKeys(['j']);383 // After moving down, we should be at Eol of line 3384 helpers.assertCursorAt({ line: 2, ch: lines[2].length - 1 });385 helpers.doKeys(['h']);386 helpers.doKeys(['j']);387 // After moving back one space and then down, since line 4 is shorter than line 2, we should388 // be at Eol of line 2 - 1389 helpers.assertCursorAt({ line: 3, ch: lines[3].length - 1 });390 helpers.doKeys(['j']);391 helpers.doKeys(['j']);392 // After moving down again, since line 3 has enough characters, we should be back to the393 // same place we were at on line 1394 helpers.assertCursorAt({ line: 5, ch: lines[2].length - 2 });395});396//making sure gj and gk recover from clipping397testVim('gj_gk_clipping', function(cm,vim,helpers){398 cm.setCursor(0, 1);399 helpers.doKeys('g','j','g','j');400 helpers.assertCursorAt(2, 1);401 helpers.doKeys('g','k','g','k');402 helpers.assertCursorAt(0, 1);403},{value: 'line 1\n\nline 2'});404//testing a mix of j/k and gj/gk405testVim('j_k_and_gj_gk', function(cm,vim,helpers){406 cm.setSize(120);407 cm.setCursor(0, 0);408 //go to the last character on the first line409 helpers.doKeys('$');410 //move up/down on the column within the wrapped line411 //side-effect: cursor is not locked to eol anymore412 helpers.doKeys('g','k');413 var cur=cm.getCursor();414 eq(cur.line,0);415 is((cur.ch<176),'gk didn\'t move cursor back (1)');416 helpers.doKeys('g','j');417 helpers.assertCursorAt(0, 176);418 //should move to character 177 on line 2 (j/k preserve character index within line)419 helpers.doKeys('j');420 //due to different line wrapping, the cursor can be on a different screen-x now421 //gj and gk preserve screen-x on movement, much like moveV422 helpers.doKeys('3','g','k');423 cur=cm.getCursor();424 eq(cur.line,1);425 is((cur.ch<176),'gk didn\'t move cursor back (2)');426 helpers.doKeys('g','j','2','g','j');427 //should return to the same character-index428 helpers.doKeys('k');429 helpers.assertCursorAt(0, 176);430},{ lineWrapping:true, value: 'This line is intentially long to test movement of gj and gk over wrapped lines. I will start on the end of this line, then make a step up and back to set the origin for j and k.\nThis line is supposed to be even longer than the previous. I will jump here and make another wiggle with gj and gk, before I jump back to the line above. Both wiggles should not change my cursor\'s target character but both j/k and gj/gk change each other\'s reference position.'});431testVim('gj_gk', function(cm, vim, helpers) {432 if (phantom) return;433 cm.setSize(120);434 // Test top of document edge case.435 cm.setCursor(0, 4);436 helpers.doKeys('g', 'j');437 helpers.doKeys('10', 'g', 'k');438 helpers.assertCursorAt(0, 4);439 // Test moving down preserves column position.440 helpers.doKeys('g', 'j');441 var pos1 = cm.getCursor();442 var expectedPos2 = { line: 0, ch: (pos1.ch - 4) * 2 + 4};443 helpers.doKeys('g', 'j');444 helpers.assertCursorAt(expectedPos2);445 // Move to the last character446 cm.setCursor(0, 0);447 // Move left to reset HSPos448 helpers.doKeys('h');449 // Test bottom of document edge case.450 helpers.doKeys('100', 'g', 'j');451 var endingPos = cm.getCursor();452 is(endingPos != 0, 'gj should not be on wrapped line 0');453 var topLeftCharCoords = cm.charCoords(makeCursor(0, 0));454 var endingCharCoords = cm.charCoords(endingPos);455 is(topLeftCharCoords.left == endingCharCoords.left, 'gj should end up on column 0');456},{ lineNumbers: false, lineWrapping:true, value: 'Thislineisintentiallylongtotestmovementofgjandgkoverwrappedlines.' });457testVim('}', function(cm, vim, helpers) {458 cm.setCursor(0, 0);459 helpers.doKeys('}');460 helpers.assertCursorAt(1, 0);461 cm.setCursor(0, 0);462 helpers.doKeys('2', '}');463 helpers.assertCursorAt(4, 0);464 cm.setCursor(0, 0);465 helpers.doKeys('6', '}');466 helpers.assertCursorAt(5, 0);467}, { value: 'a\n\nb\nc\n\nd' });468testVim('{', function(cm, vim, helpers) {469 cm.setCursor(5, 0);470 helpers.doKeys('{');471 helpers.assertCursorAt(4, 0);472 cm.setCursor(5, 0);473 helpers.doKeys('2', '{');474 helpers.assertCursorAt(1, 0);475 cm.setCursor(5, 0);476 helpers.doKeys('6', '{');477 helpers.assertCursorAt(0, 0);478}, { value: 'a\n\nb\nc\n\nd' });479// Operator tests480testVim('dl', function(cm, vim, helpers) {481 var curStart = makeCursor(0, 0);482 cm.setCursor(curStart);483 helpers.doKeys('d', 'l');484 eq('word1 ', cm.getValue());485 var register = helpers.getRegisterController().getRegister();486 eq(' ', register.text);487 is(!register.linewise);488 eqPos(curStart, cm.getCursor());489}, { value: ' word1 ' });490testVim('dl_eol', function(cm, vim, helpers) {491 cm.setCursor(0, 6);492 helpers.doKeys('d', 'l');493 eq(' word1', cm.getValue());494 var register = helpers.getRegisterController().getRegister();495 eq(' ', register.text);496 is(!register.linewise);497 helpers.assertCursorAt(0, 5);498}, { value: ' word1 ' });499testVim('dl_repeat', function(cm, vim, helpers) {500 var curStart = makeCursor(0, 0);501 cm.setCursor(curStart);502 helpers.doKeys('2', 'd', 'l');503 eq('ord1 ', cm.getValue());504 var register = helpers.getRegisterController().getRegister();505 eq(' w', register.text);506 is(!register.linewise);507 eqPos(curStart, cm.getCursor());508}, { value: ' word1 ' });509testVim('dh', function(cm, vim, helpers) {510 var curStart = makeCursor(0, 3);511 cm.setCursor(curStart);512 helpers.doKeys('d', 'h');513 eq(' wrd1 ', cm.getValue());514 var register = helpers.getRegisterController().getRegister();515 eq('o', register.text);516 is(!register.linewise);517 eqPos(offsetCursor(curStart, 0 , -1), cm.getCursor());518}, { value: ' word1 ' });519testVim('dj', function(cm, vim, helpers) {520 var curStart = makeCursor(0, 3);521 cm.setCursor(curStart);522 helpers.doKeys('d', 'j');523 eq(' word3', cm.getValue());524 var register = helpers.getRegisterController().getRegister();525 eq(' word1\nword2\n', register.text);526 is(register.linewise);527 helpers.assertCursorAt(0, 1);528}, { value: ' word1\nword2\n word3' });529testVim('dj_end_of_document', function(cm, vim, helpers) {530 var curStart = makeCursor(0, 3);531 cm.setCursor(curStart);532 helpers.doKeys('d', 'j');533 eq(' word1 ', cm.getValue());534 var register = helpers.getRegisterController().getRegister();535 eq('', register.text);536 is(!register.linewise);537 helpers.assertCursorAt(0, 3);538}, { value: ' word1 ' });539testVim('dk', function(cm, vim, helpers) {540 var curStart = makeCursor(1, 3);541 cm.setCursor(curStart);542 helpers.doKeys('d', 'k');543 eq(' word3', cm.getValue());544 var register = helpers.getRegisterController().getRegister();545 eq(' word1\nword2\n', register.text);546 is(register.linewise);547 helpers.assertCursorAt(0, 1);548}, { value: ' word1\nword2\n word3' });549testVim('dk_start_of_document', function(cm, vim, helpers) {550 var curStart = makeCursor(0, 3);551 cm.setCursor(curStart);552 helpers.doKeys('d', 'k');553 eq(' word1 ', cm.getValue());554 var register = helpers.getRegisterController().getRegister();555 eq('', register.text);556 is(!register.linewise);557 helpers.assertCursorAt(0, 3);558}, { value: ' word1 ' });559testVim('dw_space', function(cm, vim, helpers) {560 var curStart = makeCursor(0, 0);561 cm.setCursor(curStart);562 helpers.doKeys('d', 'w');563 eq('word1 ', cm.getValue());564 var register = helpers.getRegisterController().getRegister();565 eq(' ', register.text);566 is(!register.linewise);567 eqPos(curStart, cm.getCursor());568}, { value: ' word1 ' });569testVim('dw_word', function(cm, vim, helpers) {570 var curStart = makeCursor(0, 1);571 cm.setCursor(curStart);572 helpers.doKeys('d', 'w');573 eq(' word2', cm.getValue());574 var register = helpers.getRegisterController().getRegister();575 eq('word1 ', register.text);576 is(!register.linewise);577 eqPos(curStart, cm.getCursor());578}, { value: ' word1 word2' });579testVim('dw_only_word', function(cm, vim, helpers) {580 // Test that if there is only 1 word left, dw deletes till the end of the581 // line.582 cm.setCursor(0, 1);583 helpers.doKeys('d', 'w');584 eq(' ', cm.getValue());585 var register = helpers.getRegisterController().getRegister();586 eq('word1 ', register.text);587 is(!register.linewise);588 helpers.assertCursorAt(0, 0);589}, { value: ' word1 ' });590testVim('dw_eol', function(cm, vim, helpers) {591 // Assert that dw does not delete the newline if last word to delete is at end592 // of line.593 cm.setCursor(0, 1);594 helpers.doKeys('d', 'w');595 eq(' \nword2', cm.getValue());596 var register = helpers.getRegisterController().getRegister();597 eq('word1', register.text);598 is(!register.linewise);599 helpers.assertCursorAt(0, 0);600}, { value: ' word1\nword2' });601testVim('dw_eol_with_multiple_newlines', function(cm, vim, helpers) {602 // Assert that dw does not delete the newline if last word to delete is at end603 // of line and it is followed by multiple newlines.604 cm.setCursor(0, 1);605 helpers.doKeys('d', 'w');606 eq(' \n\nword2', cm.getValue());607 var register = helpers.getRegisterController().getRegister();608 eq('word1', register.text);609 is(!register.linewise);610 helpers.assertCursorAt(0, 0);611}, { value: ' word1\n\nword2' });612testVim('dw_empty_line_followed_by_whitespace', function(cm, vim, helpers) {613 cm.setCursor(0, 0);614 helpers.doKeys('d', 'w');615 eq(' \nword', cm.getValue());616}, { value: '\n \nword' });617testVim('dw_empty_line_followed_by_word', function(cm, vim, helpers) {618 cm.setCursor(0, 0);619 helpers.doKeys('d', 'w');620 eq('word', cm.getValue());621}, { value: '\nword' });622testVim('dw_empty_line_followed_by_empty_line', function(cm, vim, helpers) {623 cm.setCursor(0, 0);624 helpers.doKeys('d', 'w');625 eq('\n', cm.getValue());626}, { value: '\n\n' });627testVim('dw_whitespace_followed_by_whitespace', function(cm, vim, helpers) {628 cm.setCursor(0, 0);629 helpers.doKeys('d', 'w');630 eq('\n \n', cm.getValue());631}, { value: ' \n \n' });632testVim('dw_whitespace_followed_by_empty_line', function(cm, vim, helpers) {633 cm.setCursor(0, 0);634 helpers.doKeys('d', 'w');635 eq('\n\n', cm.getValue());636}, { value: ' \n\n' });637testVim('dw_word_whitespace_word', function(cm, vim, helpers) {638 cm.setCursor(0, 0);639 helpers.doKeys('d', 'w');640 eq('\n \nword2', cm.getValue());641}, { value: 'word1\n \nword2'})642testVim('dw_end_of_document', function(cm, vim, helpers) {643 cm.setCursor(1, 2);644 helpers.doKeys('d', 'w');645 eq('\nab', cm.getValue());646}, { value: '\nabc' });647testVim('dw_repeat', function(cm, vim, helpers) {648 // Assert that dw does delete newline if it should go to the next line, and649 // that repeat works properly.650 cm.setCursor(0, 1);651 helpers.doKeys('d', '2', 'w');652 eq(' ', cm.getValue());653 var register = helpers.getRegisterController().getRegister();654 eq('word1\nword2', register.text);655 is(!register.linewise);656 helpers.assertCursorAt(0, 0);657}, { value: ' word1\nword2' });658testVim('de_word_start_and_empty_lines', function(cm, vim, helpers) {659 cm.setCursor(0, 0);660 helpers.doKeys('d', 'e');661 eq('\n\n', cm.getValue());662}, { value: 'word\n\n' });663testVim('de_word_end_and_empty_lines', function(cm, vim, helpers) {664 cm.setCursor(0, 3);665 helpers.doKeys('d', 'e');666 eq('wor', cm.getValue());667}, { value: 'word\n\n\n' });668testVim('de_whitespace_and_empty_lines', function(cm, vim, helpers) {669 cm.setCursor(0, 0);670 helpers.doKeys('d', 'e');671 eq('', cm.getValue());672}, { value: ' \n\n\n' });673testVim('de_end_of_document', function(cm, vim, helpers) {674 cm.setCursor(1, 2);675 helpers.doKeys('d', 'e');676 eq('\nab', cm.getValue());677}, { value: '\nabc' });678testVim('db_empty_lines', function(cm, vim, helpers) {679 cm.setCursor(2, 0);680 helpers.doKeys('d', 'b');681 eq('\n\n', cm.getValue());682}, { value: '\n\n\n' });683testVim('db_word_start_and_empty_lines', function(cm, vim, helpers) {684 cm.setCursor(2, 0);685 helpers.doKeys('d', 'b');686 eq('\nword', cm.getValue());687}, { value: '\n\nword' });688testVim('db_word_end_and_empty_lines', function(cm, vim, helpers) {689 cm.setCursor(2, 3);690 helpers.doKeys('d', 'b');691 eq('\n\nd', cm.getValue());692}, { value: '\n\nword' });693testVim('db_whitespace_and_empty_lines', function(cm, vim, helpers) {694 cm.setCursor(2, 0);695 helpers.doKeys('d', 'b');696 eq('', cm.getValue());697}, { value: '\n \n' });698testVim('db_start_of_document', function(cm, vim, helpers) {699 cm.setCursor(0, 0);700 helpers.doKeys('d', 'b');701 eq('abc\n', cm.getValue());702}, { value: 'abc\n' });703testVim('dge_empty_lines', function(cm, vim, helpers) {704 cm.setCursor(1, 0);705 helpers.doKeys('d', 'g', 'e');706 // Note: In real VIM the result should be '', but it's not quite consistent,707 // since 2 newlines are deleted. But in the similar case of word\n\n, only708 // 1 newline is deleted. We'll diverge from VIM's behavior since it's much709 // easier this way.710 eq('\n', cm.getValue());711}, { value: '\n\n' });712testVim('dge_word_and_empty_lines', function(cm, vim, helpers) {713 cm.setCursor(1, 0);714 helpers.doKeys('d', 'g', 'e');715 eq('wor\n', cm.getValue());716}, { value: 'word\n\n'});717testVim('dge_whitespace_and_empty_lines', function(cm, vim, helpers) {718 cm.setCursor(2, 0);719 helpers.doKeys('d', 'g', 'e');720 eq('', cm.getValue());721}, { value: '\n \n' });722testVim('dge_start_of_document', function(cm, vim, helpers) {723 cm.setCursor(0, 0);724 helpers.doKeys('d', 'g', 'e');725 eq('bc\n', cm.getValue());726}, { value: 'abc\n' });727testVim('d_inclusive', function(cm, vim, helpers) {728 // Assert that when inclusive is set, the character the cursor is on gets729 // deleted too.730 var curStart = makeCursor(0, 1);731 cm.setCursor(curStart);732 helpers.doKeys('d', 'e');733 eq(' ', cm.getValue());734 var register = helpers.getRegisterController().getRegister();735 eq('word1', register.text);736 is(!register.linewise);737 eqPos(curStart, cm.getCursor());738}, { value: ' word1 ' });739testVim('d_reverse', function(cm, vim, helpers) {740 // Test that deleting in reverse works.741 cm.setCursor(1, 0);742 helpers.doKeys('d', 'b');743 eq(' word2 ', cm.getValue());744 var register = helpers.getRegisterController().getRegister();745 eq('word1\n', register.text);746 is(!register.linewise);747 helpers.assertCursorAt(0, 1);748}, { value: ' word1\nword2 ' });749testVim('dd', function(cm, vim, helpers) {750 cm.setCursor(0, 3);751 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },752 { line: 1, ch: 0 });753 var expectedLineCount = cm.lineCount() - 1;754 helpers.doKeys('d', 'd');755 eq(expectedLineCount, cm.lineCount());756 var register = helpers.getRegisterController().getRegister();757 eq(expectedBuffer, register.text);758 is(register.linewise);759 helpers.assertCursorAt(0, lines[1].textStart);760});761testVim('dd_prefix_repeat', function(cm, vim, helpers) {762 cm.setCursor(0, 3);763 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },764 { line: 2, ch: 0 });765 var expectedLineCount = cm.lineCount() - 2;766 helpers.doKeys('2', 'd', 'd');767 eq(expectedLineCount, cm.lineCount());768 var register = helpers.getRegisterController().getRegister();769 eq(expectedBuffer, register.text);770 is(register.linewise);771 helpers.assertCursorAt(0, lines[2].textStart);772});773testVim('dd_motion_repeat', function(cm, vim, helpers) {774 cm.setCursor(0, 3);775 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },776 { line: 2, ch: 0 });777 var expectedLineCount = cm.lineCount() - 2;778 helpers.doKeys('d', '2', 'd');779 eq(expectedLineCount, cm.lineCount());780 var register = helpers.getRegisterController().getRegister();781 eq(expectedBuffer, register.text);782 is(register.linewise);783 helpers.assertCursorAt(0, lines[2].textStart);784});785testVim('dd_multiply_repeat', function(cm, vim, helpers) {786 cm.setCursor(0, 3);787 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },788 { line: 6, ch: 0 });789 var expectedLineCount = cm.lineCount() - 6;790 helpers.doKeys('2', 'd', '3', 'd');791 eq(expectedLineCount, cm.lineCount());792 var register = helpers.getRegisterController().getRegister();793 eq(expectedBuffer, register.text);794 is(register.linewise);795 helpers.assertCursorAt(0, lines[6].textStart);796});797testVim('dd_lastline', function(cm, vim, helpers) {798 cm.setCursor(cm.lineCount(), 0);799 var expectedLineCount = cm.lineCount() - 1;800 helpers.doKeys('d', 'd');801 eq(expectedLineCount, cm.lineCount());802 helpers.assertCursorAt(cm.lineCount() - 1, 0);803});804// Yank commands should behave the exact same as d commands, expect that nothing805// gets deleted.806testVim('yw_repeat', function(cm, vim, helpers) {807 // Assert that yw does yank newline if it should go to the next line, and808 // that repeat works properly.809 var curStart = makeCursor(0, 1);810 cm.setCursor(curStart);811 helpers.doKeys('y', '2', 'w');812 eq(' word1\nword2', cm.getValue());813 var register = helpers.getRegisterController().getRegister();814 eq('word1\nword2', register.text);815 is(!register.linewise);816 eqPos(curStart, cm.getCursor());817}, { value: ' word1\nword2' });818testVim('yy_multiply_repeat', function(cm, vim, helpers) {819 var curStart = makeCursor(0, 3);820 cm.setCursor(curStart);821 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },822 { line: 6, ch: 0 });823 var expectedLineCount = cm.lineCount();824 helpers.doKeys('2', 'y', '3', 'y');825 eq(expectedLineCount, cm.lineCount());826 var register = helpers.getRegisterController().getRegister();827 eq(expectedBuffer, register.text);828 is(register.linewise);829 eqPos(curStart, cm.getCursor());830});831// Change commands behave like d commands except that it also enters insert832// mode. In addition, when the change is linewise, an additional newline is833// inserted so that insert mode starts on that line.834testVim('cw', function(cm, vim, helpers) {835 cm.setCursor(0, 0);836 helpers.doKeys('c', '2', 'w');837 eq(' word3', cm.getValue());838 helpers.assertCursorAt(0, 0);839}, { value: 'word1 word2 word3'});840testVim('cw_repeat', function(cm, vim, helpers) {841 // Assert that cw does delete newline if it should go to the next line, and842 // that repeat works properly.843 var curStart = makeCursor(0, 1);844 cm.setCursor(curStart);845 helpers.doKeys('c', '2', 'w');846 eq(' ', cm.getValue());847 var register = helpers.getRegisterController().getRegister();848 eq('word1\nword2', register.text);849 is(!register.linewise);850 eqPos(curStart, cm.getCursor());851 eq('vim-insert', cm.getOption('keyMap'));852}, { value: ' word1\nword2' });853testVim('cc_multiply_repeat', function(cm, vim, helpers) {854 cm.setCursor(0, 3);855 var expectedBuffer = cm.getRange({ line: 0, ch: 0 },856 { line: 6, ch: 0 });857 var expectedLineCount = cm.lineCount() - 5;858 helpers.doKeys('2', 'c', '3', 'c');859 eq(expectedLineCount, cm.lineCount());860 var register = helpers.getRegisterController().getRegister();861 eq(expectedBuffer, register.text);862 is(register.linewise);863 eq('vim-insert', cm.getOption('keyMap'));864});865testVim('cc_append', function(cm, vim, helpers) {866 var expectedLineCount = cm.lineCount();867 cm.setCursor(cm.lastLine(), 0);868 helpers.doKeys('c', 'c');869 eq(expectedLineCount, cm.lineCount());870});871// Swapcase commands edit in place and do not modify registers.872testVim('g~w_repeat', function(cm, vim, helpers) {873 // Assert that dw does delete newline if it should go to the next line, and874 // that repeat works properly.875 var curStart = makeCursor(0, 1);876 cm.setCursor(curStart);877 helpers.doKeys('g', '~', '2', 'w');878 eq(' WORD1\nWORD2', cm.getValue());879 var register = helpers.getRegisterController().getRegister();880 eq('', register.text);881 is(!register.linewise);882 eqPos(curStart, cm.getCursor());883}, { value: ' word1\nword2' });884testVim('g~g~', function(cm, vim, helpers) {885 var curStart = makeCursor(0, 3);886 cm.setCursor(curStart);887 var expectedLineCount = cm.lineCount();888 var expectedValue = cm.getValue().toUpperCase();889 helpers.doKeys('2', 'g', '~', '3', 'g', '~');890 eq(expectedValue, cm.getValue());891 var register = helpers.getRegisterController().getRegister();892 eq('', register.text);893 is(!register.linewise);894 eqPos(curStart, cm.getCursor());895}, { value: ' word1\nword2\nword3\nword4\nword5\nword6' });896testVim('>{motion}', function(cm, vim, helpers) {897 cm.setCursor(1, 3);898 var expectedLineCount = cm.lineCount();899 var expectedValue = ' word1\n word2\nword3 ';900 helpers.doKeys('>', 'k');901 eq(expectedValue, cm.getValue());902 var register = helpers.getRegisterController().getRegister();903 eq('', register.text);904 is(!register.linewise);905 helpers.assertCursorAt(0, 3);906}, { value: ' word1\nword2\nword3 ', indentUnit: 2 });907testVim('>>', function(cm, vim, helpers) {908 cm.setCursor(0, 3);909 var expectedLineCount = cm.lineCount();910 var expectedValue = ' word1\n word2\nword3 ';911 helpers.doKeys('2', '>', '>');912 eq(expectedValue, cm.getValue());913 var register = helpers.getRegisterController().getRegister();914 eq('', register.text);915 is(!register.linewise);916 helpers.assertCursorAt(0, 3);917}, { value: ' word1\nword2\nword3 ', indentUnit: 2 });918testVim('<{motion}', function(cm, vim, helpers) {919 cm.setCursor(1, 3);920 var expectedLineCount = cm.lineCount();921 var expectedValue = ' word1\nword2\nword3 ';922 helpers.doKeys('<', 'k');923 eq(expectedValue, cm.getValue());924 var register = helpers.getRegisterController().getRegister();925 eq('', register.text);926 is(!register.linewise);927 helpers.assertCursorAt(0, 1);928}, { value: ' word1\n word2\nword3 ', indentUnit: 2 });929testVim('<<', function(cm, vim, helpers) {930 cm.setCursor(0, 3);931 var expectedLineCount = cm.lineCount();932 var expectedValue = ' word1\nword2\nword3 ';933 helpers.doKeys('2', '<', '<');934 eq(expectedValue, cm.getValue());935 var register = helpers.getRegisterController().getRegister();936 eq('', register.text);937 is(!register.linewise);938 helpers.assertCursorAt(0, 1);939}, { value: ' word1\n word2\nword3 ', indentUnit: 2 });940// Edit tests941function testEdit(name, before, pos, edit, after) {942 return testVim(name, function(cm, vim, helpers) {943 cm.setCursor(0, before.search(pos));944 helpers.doKeys.apply(this, edit.split(''));945 eq(after, cm.getValue());946 }, {value: before});947}948// These Delete tests effectively cover word-wise Change, Visual & Yank.949// Tabs are used as differentiated whitespace to catch edge cases.950// Normal word:951testEdit('diw_mid_spc', 'foo \tbAr\t baz', /A/, 'diw', 'foo \t\t baz');952testEdit('daw_mid_spc', 'foo \tbAr\t baz', /A/, 'daw', 'foo \tbaz');953testEdit('diw_mid_punct', 'foo \tbAr.\t baz', /A/, 'diw', 'foo \t.\t baz');954testEdit('daw_mid_punct', 'foo \tbAr.\t baz', /A/, 'daw', 'foo.\t baz');955testEdit('diw_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'diw', 'foo \t,.\t baz');956testEdit('daw_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'daw', 'foo \t,.\t baz');957testEdit('diw_start_spc', 'bAr \tbaz', /A/, 'diw', ' \tbaz');958testEdit('daw_start_spc', 'bAr \tbaz', /A/, 'daw', 'baz');959testEdit('diw_start_punct', 'bAr. \tbaz', /A/, 'diw', '. \tbaz');960testEdit('daw_start_punct', 'bAr. \tbaz', /A/, 'daw', '. \tbaz');961testEdit('diw_end_spc', 'foo \tbAr', /A/, 'diw', 'foo \t');962testEdit('daw_end_spc', 'foo \tbAr', /A/, 'daw', 'foo');963testEdit('diw_end_punct', 'foo \tbAr.', /A/, 'diw', 'foo \t.');964testEdit('daw_end_punct', 'foo \tbAr.', /A/, 'daw', 'foo.');965// Big word:966testEdit('diW_mid_spc', 'foo \tbAr\t baz', /A/, 'diW', 'foo \t\t baz');967testEdit('daW_mid_spc', 'foo \tbAr\t baz', /A/, 'daW', 'foo \tbaz');968testEdit('diW_mid_punct', 'foo \tbAr.\t baz', /A/, 'diW', 'foo \t\t baz');969testEdit('daW_mid_punct', 'foo \tbAr.\t baz', /A/, 'daW', 'foo \tbaz');970testEdit('diW_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'diW', 'foo \t\t baz');971testEdit('daW_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'daW', 'foo \tbaz');972testEdit('diW_start_spc', 'bAr\t baz', /A/, 'diW', '\t baz');973testEdit('daW_start_spc', 'bAr\t baz', /A/, 'daW', 'baz');974testEdit('diW_start_punct', 'bAr.\t baz', /A/, 'diW', '\t baz');975testEdit('daW_start_punct', 'bAr.\t baz', /A/, 'daW', 'baz');976testEdit('diW_end_spc', 'foo \tbAr', /A/, 'diW', 'foo \t');977testEdit('daW_end_spc', 'foo \tbAr', /A/, 'daW', 'foo');978testEdit('diW_end_punct', 'foo \tbAr.', /A/, 'diW', 'foo \t');979testEdit('daW_end_punct', 'foo \tbAr.', /A/, 'daW', 'foo');980// Operator-motion tests981testVim('D', function(cm, vim, helpers) {982 cm.setCursor(0, 3);983 helpers.doKeys('D');984 eq(' wo\nword2\n word3', cm.getValue());985 var register = helpers.getRegisterController().getRegister();986 eq('rd1', register.text);987 is(!register.linewise);988 helpers.assertCursorAt(0, 2);989}, { value: ' word1\nword2\n word3' });990testVim('C', function(cm, vim, helpers) {991 var curStart = makeCursor(0, 3);992 cm.setCursor(curStart);993 helpers.doKeys('C');994 eq(' wo\nword2\n word3', cm.getValue());995 var register = helpers.getRegisterController().getRegister();996 eq('rd1', register.text);997 is(!register.linewise);998 eqPos(curStart, cm.getCursor());999 eq('vim-insert', cm.getOption('keyMap'));1000}, { value: ' word1\nword2\n word3' });1001testVim('Y', function(cm, vim, helpers) {1002 var curStart = makeCursor(0, 3);1003 cm.setCursor(curStart);1004 helpers.doKeys('Y');1005 eq(' word1\nword2\n word3', cm.getValue());1006 var register = helpers.getRegisterController().getRegister();1007 eq('rd1', register.text);1008 is(!register.linewise);1009 helpers.assertCursorAt(0, 3);1010}, { value: ' word1\nword2\n word3' });1011testVim('~', function(cm, vim, helpers) {1012 helpers.doKeys('3', '~');1013 eq('ABCdefg', cm.getValue());1014 helpers.assertCursorAt(0, 3);1015}, { value: 'abcdefg' });1016// Action tests1017testVim('ctrl-a', function(cm, vim, helpers) {1018 cm.setCursor(0, 0);1019 helpers.doKeys('<C-a>');1020 eq('-9', cm.getValue());1021 helpers.assertCursorAt(0, 1);1022 helpers.doKeys('2','<C-a>');1023 eq('-7', cm.getValue());1024}, {value: '-10'});1025testVim('ctrl-x', function(cm, vim, helpers) {1026 cm.setCursor(0, 0);1027 helpers.doKeys('<C-x>');1028 eq('-1', cm.getValue());1029 helpers.assertCursorAt(0, 1);1030 helpers.doKeys('2','<C-x>');1031 eq('-3', cm.getValue());1032}, {value: '0'});1033testVim('<C-x>/<C-a> search forward', function(cm, vim, helpers) {1034 ['<C-x>', '<C-a>'].forEach(function(key) {1035 cm.setCursor(0, 0);1036 helpers.doKeys(key);1037 helpers.assertCursorAt(0, 5);1038 helpers.doKeys('l');1039 helpers.doKeys(key);1040 helpers.assertCursorAt(0, 10);1041 cm.setCursor(0, 11);1042 helpers.doKeys(key);1043 helpers.assertCursorAt(0, 11);1044 });1045}, {value: '__jmp1 jmp2 jmp'});1046testVim('a', function(cm, vim, helpers) {1047 cm.setCursor(0, 1);1048 helpers.doKeys('a');1049 helpers.assertCursorAt(0, 2);1050 eq('vim-insert', cm.getOption('keyMap'));1051});1052testVim('a_eol', function(cm, vim, helpers) {1053 cm.setCursor(0, lines[0].length - 1);1054 helpers.doKeys('a');1055 helpers.assertCursorAt(0, lines[0].length);1056 eq('vim-insert', cm.getOption('keyMap'));1057});1058testVim('i', function(cm, vim, helpers) {1059 cm.setCursor(0, 1);1060 helpers.doKeys('i');1061 helpers.assertCursorAt(0, 1);1062 eq('vim-insert', cm.getOption('keyMap'));1063});1064testVim('i_repeat', function(cm, vim, helpers) {1065 helpers.doKeys('3', 'i');1066 cm.replaceRange('test', cm.getCursor());1067 helpers.doInsertModeKeys('Esc');1068 eq('testtesttest', cm.getValue());1069 helpers.assertCursorAt(0, 11);1070}, { value: '' });1071testVim('i_repeat_delete', function(cm, vim, helpers) {1072 cm.setCursor(0, 4);1073 helpers.doKeys('2', 'i');1074 cm.replaceRange('z', cm.getCursor());1075 helpers.doInsertModeKeys('Backspace', 'Backspace', 'Esc');1076 eq('abe', cm.getValue());1077 helpers.assertCursorAt(0, 1);1078}, { value: 'abcde' });1079testVim('A', function(cm, vim, helpers) {1080 helpers.doKeys('A');1081 helpers.assertCursorAt(0, lines[0].length);1082 eq('vim-insert', cm.getOption('keyMap'));1083});1084testVim('I', function(cm, vim, helpers) {1085 cm.setCursor(0, 4);1086 helpers.doKeys('I');1087 helpers.assertCursorAt(0, lines[0].textStart);1088 eq('vim-insert', cm.getOption('keyMap'));1089});1090testVim('I_repeat', function(cm, vim, helpers) {1091 cm.setCursor(0, 1);1092 helpers.doKeys('3', 'I');1093 cm.replaceRange('test', cm.getCursor());1094 helpers.doInsertModeKeys('Esc');1095 eq('testtesttestblah', cm.getValue());1096 helpers.assertCursorAt(0, 11);1097}, { value: 'blah' });1098testVim('o', function(cm, vim, helpers) {1099 cm.setCursor(0, 4);1100 helpers.doKeys('o');1101 eq('word1\n\nword2', cm.getValue());1102 helpers.assertCursorAt(1, 0);1103 eq('vim-insert', cm.getOption('keyMap'));1104}, { value: 'word1\nword2' });1105testVim('o_repeat', function(cm, vim, helpers) {1106 cm.setCursor(0, 0);1107 helpers.doKeys('3', 'o');1108 cm.replaceRange('test', cm.getCursor());1109 helpers.doInsertModeKeys('Esc');1110 eq('\ntest\ntest\ntest', cm.getValue());1111 helpers.assertCursorAt(3, 3);1112}, { value: '' });1113testVim('O', function(cm, vim, helpers) {1114 cm.setCursor(0, 4);1115 helpers.doKeys('O');1116 eq('\nword1\nword2', cm.getValue());1117 helpers.assertCursorAt(0, 0);1118 eq('vim-insert', cm.getOption('keyMap'));1119}, { value: 'word1\nword2' });1120testVim('J', function(cm, vim, helpers) {1121 cm.setCursor(0, 4);1122 helpers.doKeys('J');1123 var expectedValue = 'word1 word2\nword3\n word4';1124 eq(expectedValue, cm.getValue());1125 helpers.assertCursorAt(0, expectedValue.indexOf('word2') - 1);1126}, { value: 'word1 \n word2\nword3\n word4' });1127testVim('J_repeat', function(cm, vim, helpers) {1128 cm.setCursor(0, 4);1129 helpers.doKeys('3', 'J');1130 var expectedValue = 'word1 word2 word3\n word4';1131 eq(expectedValue, cm.getValue());1132 helpers.assertCursorAt(0, expectedValue.indexOf('word3') - 1);1133}, { value: 'word1 \n word2\nword3\n word4' });1134testVim('p', function(cm, vim, helpers) {1135 cm.setCursor(0, 1);1136 helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);1137 helpers.doKeys('p');1138 eq('__abc\ndef_', cm.getValue());1139 helpers.assertCursorAt(1, 2);1140}, { value: '___' });1141testVim('p_register', function(cm, vim, helpers) {1142 cm.setCursor(0, 1);1143 helpers.getRegisterController().getRegister('a').set('abc\ndef', false);1144 helpers.doKeys('"', 'a', 'p');1145 eq('__abc\ndef_', cm.getValue());1146 helpers.assertCursorAt(1, 2);1147}, { value: '___' });1148testVim('p_wrong_register', function(cm, vim, helpers) {1149 cm.setCursor(0, 1);1150 helpers.getRegisterController().getRegister('a').set('abc\ndef', false);1151 helpers.doKeys('p');1152 eq('___', cm.getValue());1153 helpers.assertCursorAt(0, 1);1154}, { value: '___' });1155testVim('p_line', function(cm, vim, helpers) {1156 cm.setCursor(0, 1);1157 helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true);1158 helpers.doKeys('2', 'p');1159 eq('___\n a\nd\n a\nd', cm.getValue());1160 helpers.assertCursorAt(1, 2);1161}, { value: '___' });1162testVim('p_lastline', function(cm, vim, helpers) {1163 cm.setCursor(0, 1);1164 helpers.getRegisterController().pushText('"', 'yank', ' a\nd', true);1165 helpers.doKeys('2', 'p');1166 eq('___\n a\nd\n a\nd', cm.getValue());1167 helpers.assertCursorAt(1, 2);1168}, { value: '___' });1169testVim('P', function(cm, vim, helpers) {1170 cm.setCursor(0, 1);1171 helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);1172 helpers.doKeys('P');1173 eq('_abc\ndef__', cm.getValue());1174 helpers.assertCursorAt(1, 3);1175}, { value: '___' });1176testVim('P_line', function(cm, vim, helpers) {1177 cm.setCursor(0, 1);1178 helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true);1179 helpers.doKeys('2', 'P');1180 eq(' a\nd\n a\nd\n___', cm.getValue());1181 helpers.assertCursorAt(0, 2);1182}, { value: '___' });1183testVim('r', function(cm, vim, helpers) {1184 cm.setCursor(0, 1);1185 helpers.doKeys('3', 'r', 'u');1186 eq('wuuuet\nanother', cm.getValue(),'3r failed');1187 helpers.assertCursorAt(0, 3);1188 cm.setCursor(0, 4);1189 helpers.doKeys('v', 'j', 'h', 'r', '<Space>');1190 eq('wuuu \n her', cm.getValue(),'Replacing selection by space-characters failed');1191}, { value: 'wordet\nanother' });1192testVim('R', function(cm, vim, helpers) {1193 cm.setCursor(0, 1);1194 helpers.doKeys('R');1195 helpers.assertCursorAt(0, 1);1196 eq('vim-replace', cm.getOption('keyMap'));1197 is(cm.state.overwrite, 'Setting overwrite state failed');1198});1199testVim('mark', function(cm, vim, helpers) {1200 cm.setCursor(2, 2);1201 helpers.doKeys('m', 't');1202 cm.setCursor(0, 0);1203 helpers.doKeys('\'', 't');1204 helpers.assertCursorAt(2, 2);1205 cm.setCursor(0, 0);1206 helpers.doKeys('`', 't');1207 helpers.assertCursorAt(2, 2);1208});1209testVim('jumpToMark_next', function(cm, vim, helpers) {1210 cm.setCursor(2, 2);1211 helpers.doKeys('m', 't');1212 cm.setCursor(0, 0);1213 helpers.doKeys(']', '`');1214 helpers.assertCursorAt(2, 2);1215 cm.setCursor(0, 0);1216 helpers.doKeys(']', '\'');1217 helpers.assertCursorAt(2, 0);1218});1219testVim('jumpToMark_next_repeat', function(cm, vim, helpers) {1220 cm.setCursor(2, 2);1221 helpers.doKeys('m', 'a');1222 cm.setCursor(3, 2);1223 helpers.doKeys('m', 'b');1224 cm.setCursor(4, 2);1225 helpers.doKeys('m', 'c');1226 cm.setCursor(0, 0);1227 helpers.doKeys('2', ']', '`');1228 helpers.assertCursorAt(3, 2);1229 cm.setCursor(0, 0);1230 helpers.doKeys('2', ']', '\'');1231 helpers.assertCursorAt(3, 1);1232});1233testVim('jumpToMark_next_sameline', function(cm, vim, helpers) {1234 cm.setCursor(2, 0);1235 helpers.doKeys('m', 'a');1236 cm.setCursor(2, 4);1237 helpers.doKeys('m', 'b');1238 cm.setCursor(2, 2);1239 helpers.doKeys(']', '`');1240 helpers.assertCursorAt(2, 4);1241});1242testVim('jumpToMark_next_onlyprev', function(cm, vim, helpers) {1243 cm.setCursor(2, 0);1244 helpers.doKeys('m', 'a');1245 cm.setCursor(4, 0);1246 helpers.doKeys(']', '`');1247 helpers.assertCursorAt(4, 0);1248});1249testVim('jumpToMark_next_nomark', function(cm, vim, helpers) {1250 cm.setCursor(2, 2);1251 helpers.doKeys(']', '`');1252 helpers.assertCursorAt(2, 2);1253 helpers.doKeys(']', '\'');1254 helpers.assertCursorAt(2, 0);1255});1256testVim('jumpToMark_next_linewise_over', function(cm, vim, helpers) {1257 cm.setCursor(2, 2);1258 helpers.doKeys('m', 'a');1259 cm.setCursor(3, 4);1260 helpers.doKeys('m', 'b');1261 cm.setCursor(2, 1);1262 helpers.doKeys(']', '\'');1263 helpers.assertCursorAt(3, 1);1264});1265testVim('jumpToMark_next_action', function(cm, vim, helpers) {1266 cm.setCursor(2, 2);1267 helpers.doKeys('m', 't');1268 cm.setCursor(0, 0);1269 helpers.doKeys('d', ']', '`');1270 helpers.assertCursorAt(0, 0);1271 var actual = cm.getLine(0);1272 var expected = 'pop pop 0 1 2 3 4';1273 eq(actual, expected, "Deleting while jumping to the next mark failed.");1274});1275testVim('jumpToMark_next_line_action', function(cm, vim, helpers) {1276 cm.setCursor(2, 2);1277 helpers.doKeys('m', 't');1278 cm.setCursor(0, 0);1279 helpers.doKeys('d', ']', '\'');1280 helpers.assertCursorAt(0, 1);1281 var actual = cm.getLine(0);1282 var expected = ' (a) [b] {c} '1283 eq(actual, expected, "Deleting while jumping to the next mark line failed.");1284});1285testVim('jumpToMark_prev', function(cm, vim, helpers) {1286 cm.setCursor(2, 2);1287 helpers.doKeys('m', 't');1288 cm.setCursor(4, 0);1289 helpers.doKeys('[', '`');1290 helpers.assertCursorAt(2, 2);1291 cm.setCursor(4, 0);1292 helpers.doKeys('[', '\'');1293 helpers.assertCursorAt(2, 0);1294});1295testVim('jumpToMark_prev_repeat', function(cm, vim, helpers) {1296 cm.setCursor(2, 2);1297 helpers.doKeys('m', 'a');1298 cm.setCursor(3, 2);1299 helpers.doKeys('m', 'b');1300 cm.setCursor(4, 2);1301 helpers.doKeys('m', 'c');1302 cm.setCursor(5, 0);1303 helpers.doKeys('2', '[', '`');1304 helpers.assertCursorAt(3, 2);1305 cm.setCursor(5, 0);1306 helpers.doKeys('2', '[', '\'');1307 helpers.assertCursorAt(3, 1);1308});1309testVim('jumpToMark_prev_sameline', function(cm, vim, helpers) {1310 cm.setCursor(2, 0);1311 helpers.doKeys('m', 'a');1312 cm.setCursor(2, 4);1313 helpers.doKeys('m', 'b');1314 cm.setCursor(2, 2);1315 helpers.doKeys('[', '`');1316 helpers.assertCursorAt(2, 0);1317});1318testVim('jumpToMark_prev_onlynext', function(cm, vim, helpers) {1319 cm.setCursor(4, 4);1320 helpers.doKeys('m', 'a');1321 cm.setCursor(2, 0);1322 helpers.doKeys('[', '`');1323 helpers.assertCursorAt(2, 0);1324});1325testVim('jumpToMark_prev_nomark', function(cm, vim, helpers) {1326 cm.setCursor(2, 2);1327 helpers.doKeys('[', '`');1328 helpers.assertCursorAt(2, 2);1329 helpers.doKeys('[', '\'');1330 helpers.assertCursorAt(2, 0);1331});1332testVim('jumpToMark_prev_linewise_over', function(cm, vim, helpers) {1333 cm.setCursor(2, 2);1334 helpers.doKeys('m', 'a');1335 cm.setCursor(3, 4);1336 helpers.doKeys('m', 'b');1337 cm.setCursor(3, 6);1338 helpers.doKeys('[', '\'');1339 helpers.assertCursorAt(2, 0);1340});1341testVim('delmark_single', function(cm, vim, helpers) {1342 cm.setCursor(1, 2);1343 helpers.doKeys('m', 't');1344 helpers.doEx('delmarks t');1345 cm.setCursor(0, 0);1346 helpers.doKeys('`', 't');1347 helpers.assertCursorAt(0, 0);1348});1349testVim('delmark_range', function(cm, vim, helpers) {1350 cm.setCursor(1, 2);1351 helpers.doKeys('m', 'a');1352 cm.setCursor(2, 2);1353 helpers.doKeys('m', 'b');1354 cm.setCursor(3, 2);1355 helpers.doKeys('m', 'c');1356 cm.setCursor(4, 2);1357 helpers.doKeys('m', 'd');1358 cm.setCursor(5, 2);1359 helpers.doKeys('m', 'e');1360 helpers.doEx('delmarks b-d');1361 cm.setCursor(0, 0);1362 helpers.doKeys('`', 'a');1363 helpers.assertCursorAt(1, 2);1364 helpers.doKeys('`', 'b');1365 helpers.assertCursorAt(1, 2);1366 helpers.doKeys('`', 'c');1367 helpers.assertCursorAt(1, 2);1368 helpers.doKeys('`', 'd');1369 helpers.assertCursorAt(1, 2);1370 helpers.doKeys('`', 'e');1371 helpers.assertCursorAt(5, 2);1372});1373testVim('delmark_multi', function(cm, vim, helpers) {1374 cm.setCursor(1, 2);1375 helpers.doKeys('m', 'a');1376 cm.setCursor(2, 2);1377 helpers.doKeys('m', 'b');1378 cm.setCursor(3, 2);1379 helpers.doKeys('m', 'c');1380 cm.setCursor(4, 2);1381 helpers.doKeys('m', 'd');1382 cm.setCursor(5, 2);1383 helpers.doKeys('m', 'e');1384 helpers.doEx('delmarks bcd');1385 cm.setCursor(0, 0);1386 helpers.doKeys('`', 'a');1387 helpers.assertCursorAt(1, 2);1388 helpers.doKeys('`', 'b');1389 helpers.assertCursorAt(1, 2);1390 helpers.doKeys('`', 'c');1391 helpers.assertCursorAt(1, 2);1392 helpers.doKeys('`', 'd');1393 helpers.assertCursorAt(1, 2);1394 helpers.doKeys('`', 'e');1395 helpers.assertCursorAt(5, 2);1396});1397testVim('delmark_multi_space', function(cm, vim, helpers) {1398 cm.setCursor(1, 2);1399 helpers.doKeys('m', 'a');1400 cm.setCursor(2, 2);1401 helpers.doKeys('m', 'b');1402 cm.setCursor(3, 2);1403 helpers.doKeys('m', 'c');1404 cm.setCursor(4, 2);1405 helpers.doKeys('m', 'd');1406 cm.setCursor(5, 2);1407 helpers.doKeys('m', 'e');1408 helpers.doEx('delmarks b c d');1409 cm.setCursor(0, 0);1410 helpers.doKeys('`', 'a');1411 helpers.assertCursorAt(1, 2);1412 helpers.doKeys('`', 'b');1413 helpers.assertCursorAt(1, 2);1414 helpers.doKeys('`', 'c');1415 helpers.assertCursorAt(1, 2);1416 helpers.doKeys('`', 'd');1417 helpers.assertCursorAt(1, 2);1418 helpers.doKeys('`', 'e');1419 helpers.assertCursorAt(5, 2);1420});1421testVim('delmark_all', function(cm, vim, helpers) {1422 cm.setCursor(1, 2);1423 helpers.doKeys('m', 'a');1424 cm.setCursor(2, 2);1425 helpers.doKeys('m', 'b');1426 cm.setCursor(3, 2);1427 helpers.doKeys('m', 'c');1428 cm.setCursor(4, 2);1429 helpers.doKeys('m', 'd');1430 cm.setCursor(5, 2);1431 helpers.doKeys('m', 'e');1432 helpers.doEx('delmarks a b-de');1433 cm.setCursor(0, 0);1434 helpers.doKeys('`', 'a');1435 helpers.assertCursorAt(0, 0);1436 helpers.doKeys('`', 'b');1437 helpers.assertCursorAt(0, 0);1438 helpers.doKeys('`', 'c');1439 helpers.assertCursorAt(0, 0);1440 helpers.doKeys('`', 'd');1441 helpers.assertCursorAt(0, 0);1442 helpers.doKeys('`', 'e');1443 helpers.assertCursorAt(0, 0);1444});1445testVim('visual', function(cm, vim, helpers) {1446 helpers.doKeys('l', 'v', 'l', 'l');1447 helpers.assertCursorAt(0, 3);1448 eqPos(makeCursor(0, 1), cm.getCursor('anchor'));1449 helpers.doKeys('d');1450 eq('15', cm.getValue());1451}, { value: '12345' });1452testVim('visual_line', function(cm, vim, helpers) {1453 helpers.doKeys('l', 'V', 'l', 'j', 'j', 'd');1454 eq(' 4\n 5', cm.getValue());1455}, { value: ' 1\n 2\n 3\n 4\n 5' });1456testVim('visual_marks', function(cm, vim, helpers) {1457 helpers.doKeys('l', 'v', 'l', 'l', 'v');1458 // Test visual mode marks1459 cm.setCursor(0, 0);1460 helpers.doKeys('\'', '<');1461 helpers.assertCursorAt(0, 1);1462 helpers.doKeys('\'', '>');1463 helpers.assertCursorAt(0, 3);1464});1465testVim('visual_join', function(cm, vim, helpers) {1466 helpers.doKeys('l', 'V', 'l', 'j', 'j', 'J');1467 eq(' 1 2 3\n 4\n 5', cm.getValue());1468}, { value: ' 1\n 2\n 3\n 4\n 5' });1469testVim('visual_blank', function(cm, vim, helpers) {1470 helpers.doKeys('v', 'k');1471 eq(vim.visualMode, true);1472}, { value: '\n' });1473testVim('s_normal', function(cm, vim, helpers) {1474 cm.setCursor(0, 1);1475 helpers.doKeys('s');1476 helpers.doInsertModeKeys('Esc');1477 helpers.assertCursorAt(0, 0);1478 eq('ac', cm.getValue());1479}, { value: 'abc'});1480testVim('s_visual', function(cm, vim, helpers) {1481 cm.setCursor(0, 1);1482 helpers.doKeys('v', 's');1483 helpers.doInsertModeKeys('Esc');1484 helpers.assertCursorAt(0, 0);1485 eq('ac', cm.getValue());1486}, { value: 'abc'});1487testVim('S_normal', function(cm, vim, helpers) {1488 cm.setCursor(0, 1);1489 helpers.doKeys('j', 'S');1490 helpers.doInsertModeKeys('Esc');1491 helpers.assertCursorAt(1, 0);1492 eq('aa\n\ncc', cm.getValue());1493}, { value: 'aa\nbb\ncc'});1494testVim('S_visual', function(cm, vim, helpers) {1495 cm.setCursor(0, 1);1496 helpers.doKeys('v', 'j', 'S');1497 helpers.doInsertModeKeys('Esc');1498 helpers.assertCursorAt(0, 0);1499 eq('\ncc', cm.getValue());1500}, { value: 'aa\nbb\ncc'});1501testVim('/ and n/N', function(cm, vim, helpers) {1502 cm.openDialog = helpers.fakeOpenDialog('match');1503 helpers.doKeys('/');1504 helpers.assertCursorAt(0, 11);1505 helpers.doKeys('n');1506 helpers.assertCursorAt(1, 6);1507 helpers.doKeys('N');1508 helpers.assertCursorAt(0, 11);1509 cm.setCursor(0, 0);1510 helpers.doKeys('2', '/');1511 helpers.assertCursorAt(1, 6);1512}, { value: 'match nope match \n nope Match' });1513testVim('/_case', function(cm, vim, helpers) {1514 cm.openDialog = helpers.fakeOpenDialog('Match');1515 helpers.doKeys('/');1516 helpers.assertCursorAt(1, 6);1517}, { value: 'match nope match \n nope Match' });1518testVim('/_nongreedy', function(cm, vim, helpers) {1519 cm.openDialog = helpers.fakeOpenDialog('aa');1520 helpers.doKeys('/');1521 helpers.assertCursorAt(0, 4);1522 helpers.doKeys('n');1523 helpers.assertCursorAt(1, 3);1524 helpers.doKeys('n');1525 helpers.assertCursorAt(0, 0);1526}, { value: 'aaa aa \n a aa'});1527testVim('?_nongreedy', function(cm, vim, helpers) {1528 cm.openDialog = helpers.fakeOpenDialog('aa');1529 helpers.doKeys('?');1530 helpers.assertCursorAt(1, 3);1531 helpers.doKeys('n');1532 helpers.assertCursorAt(0, 4);1533 helpers.doKeys('n');1534 helpers.assertCursorAt(0, 0);1535}, { value: 'aaa aa \n a aa'});1536testVim('/_greedy', function(cm, vim, helpers) {1537 cm.openDialog = helpers.fakeOpenDialog('a+');1538 helpers.doKeys('/');1539 helpers.assertCursorAt(0, 4);1540 helpers.doKeys('n');1541 helpers.assertCursorAt(1, 1);1542 helpers.doKeys('n');1543 helpers.assertCursorAt(1, 3);1544 helpers.doKeys('n');1545 helpers.assertCursorAt(0, 0);1546}, { value: 'aaa aa \n a aa'});1547testVim('?_greedy', function(cm, vim, helpers) {1548 cm.openDialog = helpers.fakeOpenDialog('a+');1549 helpers.doKeys('?');1550 helpers.assertCursorAt(1, 3);1551 helpers.doKeys('n');1552 helpers.assertCursorAt(1, 1);1553 helpers.doKeys('n');1554 helpers.assertCursorAt(0, 4);1555 helpers.doKeys('n');1556 helpers.assertCursorAt(0, 0);1557}, { value: 'aaa aa \n a aa'});1558testVim('/_greedy_0_or_more', function(cm, vim, helpers) {1559 cm.openDialog = helpers.fakeOpenDialog('a*');1560 helpers.doKeys('/');1561 helpers.assertCursorAt(0, 3);1562 helpers.doKeys('n');1563 helpers.assertCursorAt(0, 4);1564 helpers.doKeys('n');1565 helpers.assertCursorAt(0, 5);1566 helpers.doKeys('n');1567 helpers.assertCursorAt(1, 0);1568 helpers.doKeys('n');1569 helpers.assertCursorAt(1, 1);1570 helpers.doKeys('n');1571 helpers.assertCursorAt(0, 0);1572}, { value: 'aaa aa\n aa'});1573testVim('?_greedy_0_or_more', function(cm, vim, helpers) {1574 cm.openDialog = helpers.fakeOpenDialog('a*');1575 helpers.doKeys('?');1576 helpers.assertCursorAt(1, 1);1577 helpers.doKeys('n');1578 helpers.assertCursorAt(1, 0);1579 helpers.doKeys('n');1580 helpers.assertCursorAt(0, 5);1581 helpers.doKeys('n');1582 helpers.assertCursorAt(0, 4);1583 helpers.doKeys('n');1584 helpers.assertCursorAt(0, 3);1585 helpers.doKeys('n');1586 helpers.assertCursorAt(0, 0);1587}, { value: 'aaa aa\n aa'});1588testVim('? and n/N', function(cm, vim, helpers) {1589 cm.openDialog = helpers.fakeOpenDialog('match');1590 helpers.doKeys('?');1591 helpers.assertCursorAt(1, 6);1592 helpers.doKeys('n');1593 helpers.assertCursorAt(0, 11);1594 helpers.doKeys('N');1595 helpers.assertCursorAt(1, 6);1596 cm.setCursor(0, 0);1597 helpers.doKeys('2', '?');1598 helpers.assertCursorAt(0, 11);1599}, { value: 'match nope match \n nope Match' });1600testVim('*', function(cm, vim, helpers) {1601 cm.setCursor(0, 9);1602 helpers.doKeys('*');1603 helpers.assertCursorAt(0, 22);1604 cm.setCursor(0, 9);1605 helpers.doKeys('2', '*');1606 helpers.assertCursorAt(1, 8);1607}, { value: 'nomatch match nomatch match \nnomatch Match' });1608testVim('*_no_word', function(cm, vim, helpers) {1609 cm.setCursor(0, 0);1610 helpers.doKeys('*');1611 helpers.assertCursorAt(0, 0);1612}, { value: ' \n match \n' });1613testVim('*_symbol', function(cm, vim, helpers) {1614 cm.setCursor(0, 0);1615 helpers.doKeys('*');1616 helpers.assertCursorAt(1, 0);1617}, { value: ' /}\n/} match \n' });1618testVim('#', function(cm, vim, helpers) {1619 cm.setCursor(0, 9);1620 helpers.doKeys('#');1621 helpers.assertCursorAt(1, 8);1622 cm.setCursor(0, 9);1623 helpers.doKeys('2', '#');1624 helpers.assertCursorAt(0, 22);1625}, { value: 'nomatch match nomatch match \nnomatch Match' });1626testVim('*_seek', function(cm, vim, helpers) {1627 // Should skip over space and symbols.1628 cm.setCursor(0, 3);1629 helpers.doKeys('*');1630 helpers.assertCursorAt(0, 22);1631}, { value: ' := match nomatch match \nnomatch Match' });1632testVim('#', function(cm, vim, helpers) {1633 // Should skip over space and symbols.1634 cm.setCursor(0, 3);1635 helpers.doKeys('#');1636 helpers.assertCursorAt(1, 8);1637}, { value: ' := match nomatch match \nnomatch Match' });1638testVim('.', function(cm, vim, helpers) {1639 cm.setCursor(0, 0);1640 helpers.doKeys('2', 'd', 'w');1641 helpers.doKeys('.');1642 eq('5 6', cm.getValue());1643}, { value: '1 2 3 4 5 6'});1644testVim('._repeat', function(cm, vim, helpers) {1645 cm.setCursor(0, 0);1646 helpers.doKeys('2', 'd', 'w');1647 helpers.doKeys('3', '.');1648 eq('6', cm.getValue());1649}, { value: '1 2 3 4 5 6'});1650testVim('._insert', function(cm, vim, helpers) {1651 helpers.doKeys('i');1652 cm.replaceRange('test', cm.getCursor());1653 helpers.doInsertModeKeys('Esc');1654 helpers.doKeys('.');1655 eq('testestt', cm.getValue());1656 helpers.assertCursorAt(0, 6);1657}, { value: ''});1658testVim('._insert_repeat', function(cm, vim, helpers) {1659 helpers.doKeys('i');1660 cm.replaceRange('test', cm.getCursor());1661 cm.setCursor(0, 4);1662 helpers.doInsertModeKeys('Esc');1663 helpers.doKeys('2', '.');1664 eq('testesttestt', cm.getValue());1665 helpers.assertCursorAt(0, 10);1666}, { value: ''});1667testVim('._repeat_insert', function(cm, vim, helpers) {1668 helpers.doKeys('3', 'i');1669 cm.replaceRange('te', cm.getCursor());1670 cm.setCursor(0, 2);1671 helpers.doInsertModeKeys('Esc');1672 helpers.doKeys('.');1673 eq('tetettetetee', cm.getValue());1674 helpers.assertCursorAt(0, 10);1675}, { value: ''});1676testVim('._insert_o', function(cm, vim, helpers) {1677 helpers.doKeys('o');1678 cm.replaceRange('z', cm.getCursor());1679 cm.setCursor(1, 1);1680 helpers.doInsertModeKeys('Esc');1681 helpers.doKeys('.');1682 eq('\nz\nz', cm.getValue());1683 helpers.assertCursorAt(2, 0);1684}, { value: ''});1685testVim('._insert_o_repeat', function(cm, vim, helpers) {1686 helpers.doKeys('o');1687 cm.replaceRange('z', cm.getCursor());1688 helpers.doInsertModeKeys('Esc');1689 cm.setCursor(1, 0);1690 helpers.doKeys('2', '.');1691 eq('\nz\nz\nz', cm.getValue());1692 helpers.assertCursorAt(3, 0);1693}, { value: ''});1694testVim('._insert_o_indent', function(cm, vim, helpers) {1695 helpers.doKeys('o');1696 cm.replaceRange('z', cm.getCursor());1697 helpers.doInsertModeKeys('Esc');1698 cm.setCursor(1, 2);1699 helpers.doKeys('.');1700 eq('{\n z\n z', cm.getValue());1701 helpers.assertCursorAt(2, 2);1702}, { value: '{'});1703testVim('._insert_cw', function(cm, vim, helpers) {1704 helpers.doKeys('c', 'w');1705 cm.replaceRange('test', cm.getCursor());1706 helpers.doInsertModeKeys('Esc');1707 cm.setCursor(0, 3);1708 helpers.doKeys('2', 'l');1709 helpers.doKeys('.');1710 eq('test test word3', cm.getValue());1711 helpers.assertCursorAt(0, 8);1712}, { value: 'word1 word2 word3' });1713testVim('._insert_cw_repeat', function(cm, vim, helpers) {1714 // For some reason, repeat cw in desktop VIM will does not repeat insert mode1715 // changes. Will conform to that behavior.1716 helpers.doKeys('c', 'w');1717 cm.replaceRange('test', cm.getCursor());1718 helpers.doInsertModeKeys('Esc');1719 cm.setCursor(0, 4);1720 helpers.doKeys('l');1721 helpers.doKeys('2', '.');1722 eq('test test', cm.getValue());1723 helpers.assertCursorAt(0, 8);1724}, { value: 'word1 word2 word3' });1725testVim('._delete', function(cm, vim, helpers) {1726 cm.setCursor(0, 5);1727 helpers.doKeys('i');1728 helpers.doInsertModeKeys('Backspace', 'Esc');1729 helpers.doKeys('.');1730 eq('zace', cm.getValue());1731 helpers.assertCursorAt(0, 1);1732}, { value: 'zabcde'});1733testVim('._delete_repeat', function(cm, vim, helpers) {1734 cm.setCursor(0, 6);1735 helpers.doKeys('i');1736 helpers.doInsertModeKeys('Backspace', 'Esc');1737 helpers.doKeys('2', '.');1738 eq('zzce', cm.getValue());1739 helpers.assertCursorAt(0, 1);1740}, { value: 'zzabcde'});1741testVim('f;', function(cm, vim, helpers) {1742 cm.setCursor(0, 0);1743 helpers.doKeys('f', 'x');1744 helpers.doKeys(';');1745 helpers.doKeys('2', ';');1746 eq(9, cm.getCursor().ch);1747}, { value: '01x3xx678x'});1748testVim('F;', function(cm, vim, helpers) {1749 cm.setCursor(0, 8);1750 helpers.doKeys('F', 'x');1751 helpers.doKeys(';');1752 helpers.doKeys('2', ';');1753 eq(2, cm.getCursor().ch);1754}, { value: '01x3xx6x8x'});1755testVim('t;', function(cm, vim, helpers) {1756 cm.setCursor(0, 0);1757 helpers.doKeys('t', 'x');1758 helpers.doKeys(';');1759 helpers.doKeys('2', ';');1760 eq(8, cm.getCursor().ch);1761}, { value: '01x3xx678x'});1762testVim('T;', function(cm, vim, helpers) {1763 cm.setCursor(0, 9);1764 helpers.doKeys('T', 'x');1765 helpers.doKeys(';');1766 helpers.doKeys('2', ';');1767 eq(2, cm.getCursor().ch);1768}, { value: '0xx3xx678x'});1769testVim('f,', function(cm, vim, helpers) {1770 cm.setCursor(0, 6);1771 helpers.doKeys('f', 'x');1772 helpers.doKeys(',');1773 helpers.doKeys('2', ',');1774 eq(2, cm.getCursor().ch);1775}, { value: '01x3xx678x'});1776testVim('F,', function(cm, vim, helpers) {1777 cm.setCursor(0, 3);1778 helpers.doKeys('F', 'x');1779 helpers.doKeys(',');1780 helpers.doKeys('2', ',');1781 eq(9, cm.getCursor().ch);1782}, { value: '01x3xx678x'});1783testVim('t,', function(cm, vim, helpers) {1784 cm.setCursor(0, 6);1785 helpers.doKeys('t', 'x');1786 helpers.doKeys(',');1787 helpers.doKeys('2', ',');1788 eq(3, cm.getCursor().ch);1789}, { value: '01x3xx678x'});1790testVim('T,', function(cm, vim, helpers) {1791 cm.setCursor(0, 4);1792 helpers.doKeys('T', 'x');1793 helpers.doKeys(',');1794 helpers.doKeys('2', ',');1795 eq(8, cm.getCursor().ch);1796}, { value: '01x3xx67xx'});1797testVim('fd,;', function(cm, vim, helpers) {1798 cm.setCursor(0, 0);1799 helpers.doKeys('f', '4');1800 cm.setCursor(0, 0);1801 helpers.doKeys('d', ';');1802 eq('56789', cm.getValue());1803 helpers.doKeys('u');1804 cm.setCursor(0, 9);1805 helpers.doKeys('d', ',');1806 eq('01239', cm.getValue());1807}, { value: '0123456789'});1808testVim('Fd,;', function(cm, vim, helpers) {1809 cm.setCursor(0, 9);1810 helpers.doKeys('F', '4');1811 cm.setCursor(0, 9);1812 helpers.doKeys('d', ';');1813 eq('01239', cm.getValue());1814 helpers.doKeys('u');1815 cm.setCursor(0, 0);1816 helpers.doKeys('d', ',');1817 eq('56789', cm.getValue());1818}, { value: '0123456789'});1819testVim('td,;', function(cm, vim, helpers) {1820 cm.setCursor(0, 0);1821 helpers.doKeys('t', '4');1822 cm.setCursor(0, 0);1823 helpers.doKeys('d', ';');1824 eq('456789', cm.getValue());1825 helpers.doKeys('u');1826 cm.setCursor(0, 9);1827 helpers.doKeys('d', ',');1828 eq('012349', cm.getValue());1829}, { value: '0123456789'});1830testVim('Td,;', function(cm, vim, helpers) {1831 cm.setCursor(0, 9);1832 helpers.doKeys('T', '4');1833 cm.setCursor(0, 9);1834 helpers.doKeys('d', ';');1835 eq('012349', cm.getValue());1836 helpers.doKeys('u');1837 cm.setCursor(0, 0);1838 helpers.doKeys('d', ',');1839 eq('456789', cm.getValue());1840}, { value: '0123456789'});1841testVim('fc,;', function(cm, vim, helpers) {1842 cm.setCursor(0, 0);1843 helpers.doKeys('f', '4');1844 cm.setCursor(0, 0);1845 helpers.doKeys('c', ';', 'Esc');1846 eq('56789', cm.getValue());1847 helpers.doKeys('u');1848 cm.setCursor(0, 9);1849 helpers.doKeys('c', ',');1850 eq('01239', cm.getValue());1851}, { value: '0123456789'});1852testVim('Fc,;', function(cm, vim, helpers) {1853 cm.setCursor(0, 9);1854 helpers.doKeys('F', '4');1855 cm.setCursor(0, 9);1856 helpers.doKeys('c', ';', 'Esc');1857 eq('01239', cm.getValue());1858 helpers.doKeys('u');1859 cm.setCursor(0, 0);1860 helpers.doKeys('c', ',');1861 eq('56789', cm.getValue());1862}, { value: '0123456789'});1863testVim('tc,;', function(cm, vim, helpers) {1864 cm.setCursor(0, 0);1865 helpers.doKeys('t', '4');1866 cm.setCursor(0, 0);1867 helpers.doKeys('c', ';', 'Esc');1868 eq('456789', cm.getValue());1869 helpers.doKeys('u');1870 cm.setCursor(0, 9);1871 helpers.doKeys('c', ',');1872 eq('012349', cm.getValue());1873}, { value: '0123456789'});1874testVim('Tc,;', function(cm, vim, helpers) {1875 cm.setCursor(0, 9);1876 helpers.doKeys('T', '4');1877 cm.setCursor(0, 9);1878 helpers.doKeys('c', ';', 'Esc');1879 eq('012349', cm.getValue());1880 helpers.doKeys('u');1881 cm.setCursor(0, 0);1882 helpers.doKeys('c', ',');1883 eq('456789', cm.getValue());1884}, { value: '0123456789'});1885testVim('fy,;', function(cm, vim, helpers) {1886 cm.setCursor(0, 0);1887 helpers.doKeys('f', '4');1888 cm.setCursor(0, 0);1889 helpers.doKeys('y', ';', 'P');1890 eq('012340123456789', cm.getValue());1891 helpers.doKeys('u');1892 cm.setCursor(0, 9);1893 helpers.doKeys('y', ',', 'P');1894 eq('012345678456789', cm.getValue());1895}, { value: '0123456789'});1896testVim('Fy,;', function(cm, vim, helpers) {1897 cm.setCursor(0, 9);1898 helpers.doKeys('F', '4');1899 cm.setCursor(0, 9);1900 helpers.doKeys('y', ';', 'p');1901 eq('012345678945678', cm.getValue());1902 helpers.doKeys('u');1903 cm.setCursor(0, 0);1904 helpers.doKeys('y', ',', 'P');1905 eq('012340123456789', cm.getValue());1906}, { value: '0123456789'});1907testVim('ty,;', function(cm, vim, helpers) {1908 cm.setCursor(0, 0);1909 helpers.doKeys('t', '4');1910 cm.setCursor(0, 0);1911 helpers.doKeys('y', ';', 'P');1912 eq('01230123456789', cm.getValue());1913 helpers.doKeys('u');1914 cm.setCursor(0, 9);1915 helpers.doKeys('y', ',', 'p');1916 eq('01234567895678', cm.getValue());1917}, { value: '0123456789'});1918testVim('Ty,;', function(cm, vim, helpers) {1919 cm.setCursor(0, 9);1920 helpers.doKeys('T', '4');1921 cm.setCursor(0, 9);1922 helpers.doKeys('y', ';', 'p');1923 eq('01234567895678', cm.getValue());1924 helpers.doKeys('u');1925 cm.setCursor(0, 0);1926 helpers.doKeys('y', ',', 'P');1927 eq('01230123456789', cm.getValue());1928}, { value: '0123456789'});1929testVim('HML', function(cm, vim, helpers) {1930 var lines = 35;1931 var textHeight = cm.defaultTextHeight();1932 cm.setSize(600, lines*textHeight);1933 cm.setCursor(120, 0);1934 helpers.doKeys('H');1935 helpers.assertCursorAt(86, 2);1936 helpers.doKeys('L');1937 helpers.assertCursorAt(120, 4);1938 helpers.doKeys('M');1939 helpers.assertCursorAt(103,4);1940}, { value: (function(){1941 var lines = new Array(100);1942 var upper = ' xx\n';1943 var lower = ' xx\n';1944 upper = lines.join(upper);1945 lower = lines.join(lower);1946 return upper + lower;1947})()});1948var zVals = ['zb','zz','zt','z-','z.','z<CR>'].map(function(e, idx){1949 var lineNum = 250;1950 var lines = 35;1951 testVim(e, function(cm, vim, helpers) {1952 var k1 = e[0];1953 var k2 = e.substring(1);1954 var textHeight = cm.defaultTextHeight();1955 cm.setSize(600, lines*textHeight);1956 cm.setCursor(lineNum, 0);1957 helpers.doKeys(k1, k2);1958 zVals[idx] = cm.getScrollInfo().top;1959 }, { value: (function(){1960 return new Array(500).join('\n');1961 })()});1962});1963testVim('zb<zz', function(cm, vim, helpers){1964 eq(zVals[0]<zVals[1], true);1965});1966testVim('zz<zt', function(cm, vim, helpers){1967 eq(zVals[1]<zVals[2], true);1968});1969testVim('zb==z-', function(cm, vim, helpers){1970 eq(zVals[0], zVals[3]);1971});1972testVim('zz==z.', function(cm, vim, helpers){1973 eq(zVals[1], zVals[4]);1974});1975testVim('zt==z<CR>', function(cm, vim, helpers){1976 eq(zVals[2], zVals[5]);1977});1978var squareBracketMotionSandbox = ''+1979 '({\n'+//01980 ' ({\n'+//111981 ' /*comment {\n'+//21982 ' */(\n'+//31983 '#else \n'+//41984 ' /* )\n'+//51985 '#if }\n'+//61986 ' )}*/\n'+//71987 ')}\n'+//81988 '{}\n'+//91989 '#else {{\n'+//101990 '{}\n'+//111991 '}\n'+//121992 '{\n'+//131993 '#endif\n'+//141994 '}\n'+//151995 '}\n'+//161996 '#else';//171997testVim('[[, ]]', function(cm, vim, helpers) {1998 cm.setCursor(0, 0);1999 helpers.doKeys(']', ']');2000 helpers.assertCursorAt(9,0);2001 helpers.doKeys('2', ']', ']');2002 helpers.assertCursorAt(13,0);2003 helpers.doKeys(']', ']');2004 helpers.assertCursorAt(17,0);2005 helpers.doKeys('[', '[');2006 helpers.assertCursorAt(13,0);2007 helpers.doKeys('2', '[', '[');2008 helpers.assertCursorAt(9,0);2009 helpers.doKeys('[', '[');2010 helpers.assertCursorAt(0,0);2011}, { value: squareBracketMotionSandbox});2012testVim('[], ][', function(cm, vim, helpers) {2013 cm.setCursor(0, 0);2014 helpers.doKeys(']', '[');2015 helpers.assertCursorAt(12,0);2016 helpers.doKeys('2', ']', '[');2017 helpers.assertCursorAt(16,0);2018 helpers.doKeys(']', '[');2019 helpers.assertCursorAt(17,0);2020 helpers.doKeys('[', ']');2021 helpers.assertCursorAt(16,0);2022 helpers.doKeys('2', '[', ']');2023 helpers.assertCursorAt(12,0);2024 helpers.doKeys('[', ']');2025 helpers.assertCursorAt(0,0);2026}, { value: squareBracketMotionSandbox});2027testVim('[{, ]}', function(cm, vim, helpers) {2028 cm.setCursor(4, 10);2029 helpers.doKeys('[', '{');2030 helpers.assertCursorAt(2,12);2031 helpers.doKeys('2', '[', '{');2032 helpers.assertCursorAt(0,1);2033 cm.setCursor(4, 10);2034 helpers.doKeys(']', '}');2035 helpers.assertCursorAt(6,11);2036 helpers.doKeys('2', ']', '}');2037 helpers.assertCursorAt(8,1);2038 cm.setCursor(0,1);2039 helpers.doKeys(']', '}');2040 helpers.assertCursorAt(8,1);2041 helpers.doKeys('[', '{');2042 helpers.assertCursorAt(0,1);2043}, { value: squareBracketMotionSandbox});2044testVim('[(, ])', function(cm, vim, helpers) {2045 cm.setCursor(4, 10);2046 helpers.doKeys('[', '(');2047 helpers.assertCursorAt(3,14);2048 helpers.doKeys('2', '[', '(');2049 helpers.assertCursorAt(0,0);2050 cm.setCursor(4, 10);2051 helpers.doKeys(']', ')');2052 helpers.assertCursorAt(5,11);2053 helpers.doKeys('2', ']', ')');2054 helpers.assertCursorAt(8,0);2055 helpers.doKeys('[', '(');2056 helpers.assertCursorAt(0,0);2057 helpers.doKeys(']', ')');2058 helpers.assertCursorAt(8,0);2059}, { value: squareBracketMotionSandbox});2060testVim('[*, ]*, [/, ]/', function(cm, vim, helpers) {2061 ['*', '/'].forEach(function(key){2062 cm.setCursor(7, 0);2063 helpers.doKeys('2', '[', key);2064 helpers.assertCursorAt(2,2);2065 helpers.doKeys('2', ']', key);2066 helpers.assertCursorAt(7,5);2067 });2068}, { value: squareBracketMotionSandbox});2069testVim('[#, ]#', function(cm, vim, helpers) {2070 cm.setCursor(10, 3);2071 helpers.doKeys('2', '[', '#');2072 helpers.assertCursorAt(4,0);2073 helpers.doKeys('5', ']', '#');2074 helpers.assertCursorAt(17,0);2075 cm.setCursor(10, 3);2076 helpers.doKeys(']', '#');2077 helpers.assertCursorAt(14,0);2078}, { value: squareBracketMotionSandbox});2079testVim('[m, ]m, [M, ]M', function(cm, vim, helpers) {2080 cm.setCursor(11, 0);2081 helpers.doKeys('[', 'm');2082 helpers.assertCursorAt(10,7);2083 helpers.doKeys('4', '[', 'm');2084 helpers.assertCursorAt(1,3);2085 helpers.doKeys('5', ']', 'm');2086 helpers.assertCursorAt(11,0);2087 helpers.doKeys('[', 'M');2088 helpers.assertCursorAt(9,1);2089 helpers.doKeys('3', ']', 'M');2090 helpers.assertCursorAt(15,0);2091 helpers.doKeys('5', '[', 'M');2092 helpers.assertCursorAt(7,3);2093}, { value: squareBracketMotionSandbox});2094// Ex mode tests2095testVim('ex_go_to_line', function(cm, vim, helpers) {2096 cm.setCursor(0, 0);2097 helpers.doEx('4');2098 helpers.assertCursorAt(3, 0);2099}, { value: 'a\nb\nc\nd\ne\n'});2100testVim('ex_write', function(cm, vim, helpers) {2101 var tmp = CodeMirror.commands.save;2102 var written;2103 var actualCm;2104 CodeMirror.commands.save = function(cm) {2105 written = true;2106 actualCm = cm;2107 };2108 // Test that w, wr, wri ... write all trigger :write.2109 var command = 'write';2110 for (var i = 1; i < command.length; i++) {2111 written = false;2112 actualCm = null;2113 helpers.doEx(command.substring(0, i));2114 eq(written, true);2115 eq(actualCm, cm);2116 }2117 CodeMirror.commands.save = tmp;2118});2119testVim('ex_sort', function(cm, vim, helpers) {2120 helpers.doEx('sort');2121 eq('Z\na\nb\nc\nd', cm.getValue());2122}, { value: 'b\nZ\nd\nc\na'});2123testVim('ex_sort_reverse', function(cm, vim, helpers) {2124 helpers.doEx('sort!');2125 eq('d\nc\nb\na', cm.getValue());2126}, { value: 'b\nd\nc\na'});2127testVim('ex_sort_range', function(cm, vim, helpers) {2128 helpers.doEx('2,3sort');2129 eq('b\nc\nd\na', cm.getValue());2130}, { value: 'b\nd\nc\na'});2131testVim('ex_sort_oneline', function(cm, vim, helpers) {2132 helpers.doEx('2sort');2133 // Expect no change.2134 eq('b\nd\nc\na', cm.getValue());2135}, { value: 'b\nd\nc\na'});2136testVim('ex_sort_ignoreCase', function(cm, vim, helpers) {2137 helpers.doEx('sort i');2138 eq('a\nb\nc\nd\nZ', cm.getValue());2139}, { value: 'b\nZ\nd\nc\na'});2140testVim('ex_sort_unique', function(cm, vim, helpers) {2141 helpers.doEx('sort u');2142 eq('Z\na\nb\nc\nd', cm.getValue());2143}, { value: 'b\nZ\na\na\nd\na\nc\na'});2144testVim('ex_sort_decimal', function(cm, vim, helpers) {2145 helpers.doEx('sort d');2146 eq('d3\n s5\n6\n.9', cm.getValue());2147}, { value: '6\nd3\n s5\n.9'});2148testVim('ex_sort_decimal_negative', function(cm, vim, helpers) {2149 helpers.doEx('sort d');2150 eq('z-9\nd3\n s5\n6\n.9', cm.getValue());2151}, { value: '6\nd3\n s5\n.9\nz-9'});2152testVim('ex_sort_decimal_reverse', function(cm, vim, helpers) {2153 helpers.doEx('sort! d');2154 eq('.9\n6\n s5\nd3', cm.getValue());2155}, { value: '6\nd3\n s5\n.9'});2156testVim('ex_sort_hex', function(cm, vim, helpers) {2157 helpers.doEx('sort x');2158 eq(' s5\n6\n.9\n&0xB\nd3', cm.getValue());2159}, { value: '6\nd3\n s5\n&0xB\n.9'});2160testVim('ex_sort_octal', function(cm, vim, helpers) {2161 helpers.doEx('sort o');2162 eq('.8\n.9\nd3\n s5\n6', cm.getValue());2163}, { value: '6\nd3\n s5\n.9\n.8'});2164testVim('ex_sort_decimal_mixed', function(cm, vim, helpers) {2165 helpers.doEx('sort d');2166 eq('y\nz\nc1\nb2\na3', cm.getValue());2167}, { value: 'a3\nz\nc1\ny\nb2'});2168testVim('ex_sort_decimal_mixed_reverse', function(cm, vim, helpers) {2169 helpers.doEx('sort! d');2170 eq('a3\nb2\nc1\nz\ny', cm.getValue());2171}, { value: 'a3\nz\nc1\ny\nb2'});2172testVim('ex_substitute_same_line', function(cm, vim, helpers) {2173 cm.setCursor(1, 0);2174 helpers.doEx('s/one/two');2175 eq('one one\n two two', cm.getValue());2176}, { value: 'one one\n one one'});2177testVim('ex_substitute_global', function(cm, vim, helpers) {2178 cm.setCursor(1, 0);2179 helpers.doEx('%s/one/two');2180 eq('two two\n two two', cm.getValue());2181}, { value: 'one one\n one one'});2182testVim('ex_substitute_input_range', function(cm, vim, helpers) {2183 cm.setCursor(1, 0);2184 helpers.doEx('1,3s/\\d/0');2185 eq('0\n0\n0\n4', cm.getValue());2186}, { value: '1\n2\n3\n4' });2187testVim('ex_substitute_visual_range', function(cm, vim, helpers) {2188 cm.setCursor(1, 0);2189 // Set last visual mode selection marks '< and '> at lines 2 and 42190 helpers.doKeys('V', '2', 'j', 'v');2191 helpers.doEx('\'<,\'>s/\\d/0');2192 eq('1\n0\n0\n0\n5', cm.getValue());2193}, { value: '1\n2\n3\n4\n5' });2194testVim('ex_substitute_capture', function(cm, vim, helpers) {2195 cm.setCursor(1, 0);2196 helpers.doEx('s/(\\d+)/$1$1/')2197 eq('a1111 a1212 a1313', cm.getValue());2198}, { value: 'a11 a12 a13' });2199testVim('ex_substitute_empty_query', function(cm, vim, helpers) {2200 // If the query is empty, use last query.2201 cm.setCursor(1, 0);2202 cm.openDialog = helpers.fakeOpenDialog('1');2203 helpers.doKeys('/');2204 helpers.doEx('s//b');2205 eq('abb ab2 ab3', cm.getValue());2206}, { value: 'a11 a12 a13' });2207testVim('ex_substitute_count', function(cm, vim, helpers) {2208 cm.setCursor(1, 0);2209 helpers.doEx('s/\\d/0/i 2');2210 eq('1\n0\n0\n4', cm.getValue());2211}, { value: '1\n2\n3\n4' });2212testVim('ex_substitute_count_with_range', function(cm, vim, helpers) {2213 cm.setCursor(1, 0);2214 helpers.doEx('1,3s/\\d/0/ 3');2215 eq('1\n2\n0\n0', cm.getValue());2216}, { value: '1\n2\n3\n4' });2217function testSubstituteConfirm(name, command, initialValue, expectedValue, keys, finalPos) {2218 testVim(name, function(cm, vim, helpers) {2219 var savedOpenDialog = cm.openDialog;2220 var savedKeyName = CodeMirror.keyName;2221 var onKeyDown;2222 var recordedCallback;2223 var closed = true; // Start out closed, set false on second openDialog.2224 function close() {2225 closed = true;2226 }2227 // First openDialog should save callback.2228 cm.openDialog = function(template, callback, options) {2229 recordedCallback = callback;2230 }2231 // Do first openDialog.2232 helpers.doKeys(':');2233 // Second openDialog should save keyDown handler.2234 cm.openDialog = function(template, callback, options) {2235 onKeyDown = options.onKeyDown;2236 closed = false;2237 };2238 // Return the command to Vim and trigger second openDialog.2239 recordedCallback(command);2240 // The event should really use keyCode, but here just mock it out and use2241 // key and replace keyName to just return key.2242 CodeMirror.keyName = function (e) { return e.key; }2243 keys = keys.toUpperCase();2244 for (var i = 0; i < keys.length; i++) {2245 is(!closed);2246 onKeyDown({ key: keys.charAt(i) }, '', close);2247 }2248 try {2249 eq(expectedValue, cm.getValue());2250 helpers.assertCursorAt(finalPos);2251 is(closed);2252 } catch(e) {2253 throw e2254 } finally {2255 // Restore overriden functions.2256 CodeMirror.keyName = savedKeyName;2257 cm.openDialog = savedOpenDialog;2258 }2259 }, { value: initialValue });2260};2261testSubstituteConfirm('ex_substitute_confirm_emptydoc',2262 '%s/x/b/c', '', '', '', makeCursor(0, 0));2263testSubstituteConfirm('ex_substitute_confirm_nomatch',2264 '%s/x/b/c', 'ba a\nbab', 'ba a\nbab', '', makeCursor(0, 0));2265testSubstituteConfirm('ex_substitute_confirm_accept',2266 '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'yyy', makeCursor(1, 1));2267testSubstituteConfirm('ex_substitute_confirm_random_keys',2268 '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'ysdkywerty', makeCursor(1, 1));2269testSubstituteConfirm('ex_substitute_confirm_some',2270 '%s/a/b/c', 'ba a\nbab', 'bb a\nbbb', 'yny', makeCursor(1, 1));2271testSubstituteConfirm('ex_substitute_confirm_all',2272 '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'a', makeCursor(1, 1));2273testSubstituteConfirm('ex_substitute_confirm_accept_then_all',2274 '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'ya', makeCursor(1, 1));2275testSubstituteConfirm('ex_substitute_confirm_quit',2276 '%s/a/b/c', 'ba a\nbab', 'bb a\nbab', 'yq', makeCursor(0, 3));2277testSubstituteConfirm('ex_substitute_confirm_last',2278 '%s/a/b/c', 'ba a\nbab', 'bb b\nbab', 'yl', makeCursor(0, 3));2279testSubstituteConfirm('ex_substitute_confirm_oneline',2280 '1s/a/b/c', 'ba a\nbab', 'bb b\nbab', 'yl', makeCursor(0, 3));2281testSubstituteConfirm('ex_substitute_confirm_range_accept',2282 '1,2s/a/b/c', 'aa\na \na\na', 'bb\nb \na\na', 'yyy', makeCursor(1, 0));2283testSubstituteConfirm('ex_substitute_confirm_range_some',2284 '1,3s/a/b/c', 'aa\na \na\na', 'ba\nb \nb\na', 'ynyy', makeCursor(2, 0));2285testSubstituteConfirm('ex_substitute_confirm_range_all',2286 '1,3s/a/b/c', 'aa\na \na\na', 'bb\nb \nb\na', 'a', makeCursor(2, 0));2287testSubstituteConfirm('ex_substitute_confirm_range_last',2288 '1,3s/a/b/c', 'aa\na \na\na', 'bb\nb \na\na', 'yyl', makeCursor(1, 0));2289//:noh should clear highlighting of search-results but allow to resume search through n2290testVim('ex_noh_clearSearchHighlight', function(cm, vim, helpers) {2291 cm.openDialog = helpers.fakeOpenDialog('match');2292 helpers.doKeys('?');2293 helpers.doEx('noh');2294 eq(vim.searchState_.getOverlay(),null,'match-highlighting wasn\'t cleared');2295 helpers.doKeys('n');2296 helpers.assertCursorAt(0, 11,'can\'t resume search after clearing highlighting');2297}, { value: 'match nope match \n nope Match' });2298// TODO: Reset key maps after each test.2299testVim('ex_map_key2key', function(cm, vim, helpers) {2300 helpers.doEx('map a x');2301 helpers.doKeys('a');2302 helpers.assertCursorAt(0, 0);2303 eq('bc', cm.getValue());2304}, { value: 'abc' });2305testVim('ex_map_key2key_to_colon', function(cm, vim, helpers) {2306 helpers.doEx('map ; :');2307 var dialogOpened = false;2308 cm.openDialog = function() {2309 dialogOpened = true;2310 }2311 helpers.doKeys(';');2312 eq(dialogOpened, true);2313});2314testVim('ex_map_ex2key:', function(cm, vim, helpers) {2315 helpers.doEx('map :del x');2316 helpers.doEx('del');2317 helpers.assertCursorAt(0, 0);2318 eq('bc', cm.getValue());2319}, { value: 'abc' });2320testVim('ex_map_ex2ex', function(cm, vim, helpers) {2321 helpers.doEx('map :del :w');2322 var tmp = CodeMirror.commands.save;2323 var written = false;2324 var actualCm;2325 CodeMirror.commands.save = function(cm) {2326 written = true;2327 actualCm = cm;2328 };2329 helpers.doEx('del');2330 CodeMirror.commands.save = tmp;2331 eq(written, true);2332 eq(actualCm, cm);2333});2334testVim('ex_map_key2ex', function(cm, vim, helpers) {2335 helpers.doEx('map a :w');2336 var tmp = CodeMirror.commands.save;2337 var written = false;2338 var actualCm;2339 CodeMirror.commands.save = function(cm) {2340 written = true;2341 actualCm = cm;2342 };2343 helpers.doKeys('a');2344 CodeMirror.commands.save = tmp;2345 eq(written, true);2346 eq(actualCm, cm);2347});2348// Testing registration of functions as ex-commands and mapping to <Key>-keys2349testVim('ex_api_test', function(cm, vim, helpers) {2350 var res=false;2351 var val='from';2352 CodeMirror.Vim.defineEx('extest','ext',function(cm,params){2353 if(params.args)val=params.args[0];2354 else res=true;2355 });2356 helpers.doEx(':ext to');2357 eq(val,'to','Defining ex-command failed');2358 CodeMirror.Vim.map('<C-CR><Space>',':ext');2359 helpers.doKeys('<C-CR>','<Space>');2360 is(res,'Mapping to key failed');2361});2362// For now, this test needs to be last because it messes up : for future tests.2363testVim('ex_map_key2key_from_colon', function(cm, vim, helpers) {2364 helpers.doEx('map : x');2365 helpers.doKeys(':');2366 helpers.assertCursorAt(0, 0);2367 eq('bc', cm.getValue());...
Using AI Code Generation
1var mb = require('mountebank');2var assert = require('assert');3var port = process.env.MB_PORT || 2525;4var host = process.env.MB_HOST || 'localhost';5var protocol = process.env.MB_PROTOCOL || 'http';6var api = mb.create(url);7api.get('/test', {statusCode: 200, body: 'test'});8api.post('/test', {statusCode: 200, body: 'test'});9api.put('/test', {statusCode: 200, body: 'test'});10api.delete('/test', {statusCode: 200, body: 'test'});11api.options('/test', {statusCode: 200, body: 'test'});12api.head('/test', {statu
Using AI Code Generation
1var mbHelper = require('mountebank-helper'),2 mb = mbHelper.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto', ipWhitelist: ['*'], allowInjection: true, debug: true, mbPath: 'mb.exe'});3mb.start()4 .then(function () {5 console.log('mb started');6 return mb.post('/imposters', {7 {8 {9 equals: {10 }11 }12 {13 is: {14 }15 }16 }17 });18 })19 .then(function () {20 console.log('imposter created');21 return mb.get('/imposters');22 })23 .then(function (response) {24 console.log('imposter retrieved');25 console.log(response.body);26 return mb.del('/imposters/2525');27 })28 .then(function () {29 console.log('imposter deleted');30 return mb.stop();31 })32 .then(function () {33 console.log('mb stopped');34 })35 .catch(function (error) {36 console.error(error);37 });38var exec = require('child_process').exec;39var mbPath = 'mb.exe';40var mbPort = 2525;41var mbPidFile = 'mb.pid';42var mbLogFile = 'mb.log';43var mbProtoFile = 'mb.proto';44var mbIpWhitelist = '*';45var mbAllowInjection = true;46var mbDebug = true;47var mbCommand = mbPath + ' start --port ' + mbPort + ' --pidfile ' + mbPidFile + ' --logfile ' + mbLogFile + ' --protofile ' + mbProtoFile + ' --ipWhitelist ' + mbIpWhitelist + ' --allowInjection ' + mbAllowInjection + ' --debug ' + mbDebug;48exec(mbCommand, function (error, stdout, stderr) {49 if (error) {50 console.error(error);51 }52 else {53 console.log('mb started');
Using AI Code Generation
1var assert = require('assert');2var mbHelper = require('mountebank-helper');3var mb = mbHelper.create({ port: 2525, allowInjection: true });4mb.start()5 .then(function () {6 return mb.post('/imposters', {7 {8 {9 is: {10 }11 }12 }13 });14 })15 .then(function () {16 return mb.get('/imposters');17 })18 .then(function (response) {19 assert.equal(response.statusCode, 200);20 assert.equal(response.body.imposters[0].port, 3000);21 })22 .then(function () {23 return mb.delete('/imposters');24 })25 .then(function () {26 return mb.stop();27 })28 .catch(function (error) {29 console.error(error);30 });
Using AI Code Generation
1var helpers = require('mountebank').helpers;2var mb = require('mountebank');3mb.create({4}, function () {5 helpers.mb.start();6});7mb.create({8}, function () {9 helpers.mb.start();10});11mb.create({12}, function () {13 helpers.mb.start();14});15mb.create({16}, function () {17 helpers.mb.start();18});19mb.create({20}, function () {21 helpers.mb.start();22});23mb.create({24}, function () {25 helpers.mb.start();26});27mb.create({
Using AI Code Generation
1var mbHelper = require('mountebank-helper');2var mb = new mbHelper('localhost', 2525);3mb.createStub({4 {5 equals: {6 }7 }8 {9 is: {10 }11 }12});13mb.verify({14}, function (error, result) {15 console.log('error = ' + error);16 console.log('result = ' + result);17});18mb.deleteStub({19});20mb.deleteAllStubs();21mb.createProxy({22 {23 equals: {24 }25 }26 {27 is: {28 }29 }30});31mb.deleteProxy({32});33mb.deleteAllProxies();34mb.createImposter({35 {36 {37 equals: {38 }39 }40 {41 is: {42 }43 }44 }45});46mb.deleteImposter({47});48mb.deleteAllImposters();49mb.createImposter({
Using AI Code Generation
1var mbHelper = require('mountebank-helper');2var mbPort = 2525;3var mbProtocol = 'http';4var mbHost = 'localhost';5var stub = {6 {7 is: {8 headers: {9 },10 body: {11 }12 }13 }14};15var predicate = {16 equals: {17 }18};19var imposter = {20 {21 {22 is: {23 headers: {24 },25 body: {26 }27 }28 }29 {30 equals: {31 }32 }33 }34};35var imposter = {36 {37 {38 is: {39 headers: {40 },41 body: {42 }43 }44 }45 {46 equals: {47 }48 }49 }50};51var mb = new mbHelper(mbHost, mbPort, mbProtocol);52mb.createImposter(imposter)53 .then(function (response) {54 console.log(response);55 mb.getImposter(3000)56 .then(function (response) {57 console.log(response);58 mb.deleteImposter(3000)59 .then(function (response) {60 console.log(response);
Using AI Code Generation
1const mb = require('mountebank');2const assert = require('assert');3const mbHelper = mb.create();4mbHelper.then(function (mb) {5});6const mb = require('mountebank');7const assert = require('assert');8const mbHelper = mb.create();9mbHelper.then(function (mb) {10});11const mb = require('mountebank');12const assert = require('assert');13const mbHelper = mb.create();14mbHelper.then(function (mb) {15});16const mb = require('mountebank');17const assert = require('assert');18const mbHelper = mb.create();19mbHelper.then(function (mb) {20});21const mb = require('mountebank');22const assert = require('assert');23const mbHelper = mb.create();24mbHelper.then(function (mb) {25});26const mb = require('mountebank');27const assert = require('assert');28const mbHelper = mb.create();29mbHelper.then(function (mb) {30});31const mb = require('mountebank');32const assert = require('assert');33const mbHelper = mb.create();34mbHelper.then(function (mb) {35});36const mb = require('mountebank');37const assert = require('assert');38const mbHelper = mb.create();39mbHelper.then(function (mb) {40});41const mb = require('mountebank');42const assert = require('assert');43const mbHelper = mb.create();44mbHelper.then(function (mb) {45});
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var host = 'localhost';4var mbHelper = mb.create(port, host);5mbHelper.post('/imposters', {6 "stubs": [{7 "responses": [{8 "is": {9 }10 }]11 }]12}, function (error, response) {13 if (error) {14 console.error('Failed to create imposter', error);15 } else {16 console.log('Created imposter', response.body);17 }18});19mbHelper.get('/imposters', function (error, response) {20 if (error) {21 console.error('Failed to get imposters', error);22 } else {23 console.log('Imposters', response.body);24 }25});26mbHelper.del('/imposters/3000', function (error, response) {27 if (error) {28 console.error('Failed to delete imposter', error);29 } else {30 console.log('Deleted imposter', response.body);31 }32});33mbHelper.del('/imposters', function (error, response) {34 if (error) {35 console.error('Failed to delete imposters', error);36 } else {37 console.log('Deleted imposters', response.body);38 }39});40mbHelper.get('/imposters', function (error, response) {41 if (error) {42 console.error('Failed to get imposters', error);43 } else {44 console.log('Imposters', response.body);45 }46});47mbHelper.stop(function (error) {48 if (error) {49 console.error('Failed to stop mountebank', error);50 } else {51 console.log('Stopped mountebank');52 }53});54mbHelper.get('/imposters', function (error, response) {55 if (error) {56 console.error('Failed to get imposters', error);57 } else {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!