michael@0: var code = '' + michael@0: ' wOrd1 (#%\n' + michael@0: ' word3] \n' + michael@0: 'aopop pop 0 1 2 3 4\n' + michael@0: ' (a) [b] {c} \n' + michael@0: 'int getchar(void) {\n' + michael@0: ' static char buf[BUFSIZ];\n' + michael@0: ' static char *bufp = buf;\n' + michael@0: ' if (n == 0) { /* buffer is empty */\n' + michael@0: ' n = read(0, buf, sizeof buf);\n' + michael@0: ' bufp = buf;\n' + michael@0: ' }\n' + michael@0: '\n' + michael@0: ' return (--n >= 0) ? (unsigned char) *bufp++ : EOF;\n' + michael@0: ' \n' + michael@0: '}\n'; michael@0: michael@0: var lines = (function() { michael@0: lineText = code.split('\n'); michael@0: var ret = []; michael@0: for (var i = 0; i < lineText.length; i++) { michael@0: ret[i] = { michael@0: line: i, michael@0: length: lineText[i].length, michael@0: lineText: lineText[i], michael@0: textStart: /^\s*/.exec(lineText[i])[0].length michael@0: }; michael@0: } michael@0: return ret; michael@0: })(); michael@0: var endOfDocument = makeCursor(lines.length - 1, michael@0: lines[lines.length - 1].length); michael@0: var wordLine = lines[0]; michael@0: var bigWordLine = lines[1]; michael@0: var charLine = lines[2]; michael@0: var bracesLine = lines[3]; michael@0: var seekBraceLine = lines[4]; michael@0: michael@0: var word1 = { michael@0: start: { line: wordLine.line, ch: 1 }, michael@0: end: { line: wordLine.line, ch: 5 } michael@0: }; michael@0: var word2 = { michael@0: start: { line: wordLine.line, ch: word1.end.ch + 2 }, michael@0: end: { line: wordLine.line, ch: word1.end.ch + 4 } michael@0: }; michael@0: var word3 = { michael@0: start: { line: bigWordLine.line, ch: 1 }, michael@0: end: { line: bigWordLine.line, ch: 5 } michael@0: }; michael@0: var bigWord1 = word1; michael@0: var bigWord2 = word2; michael@0: var bigWord3 = { michael@0: start: { line: bigWordLine.line, ch: 1 }, michael@0: end: { line: bigWordLine.line, ch: 7 } michael@0: }; michael@0: var bigWord4 = { michael@0: start: { line: bigWordLine.line, ch: bigWord1.end.ch + 3 }, michael@0: end: { line: bigWordLine.line, ch: bigWord1.end.ch + 7 } michael@0: }; michael@0: michael@0: var oChars = [ { line: charLine.line, ch: 1 }, michael@0: { line: charLine.line, ch: 3 }, michael@0: { line: charLine.line, ch: 7 } ]; michael@0: var pChars = [ { line: charLine.line, ch: 2 }, michael@0: { line: charLine.line, ch: 4 }, michael@0: { line: charLine.line, ch: 6 }, michael@0: { line: charLine.line, ch: 8 } ]; michael@0: var numChars = [ { line: charLine.line, ch: 10 }, michael@0: { line: charLine.line, ch: 12 }, michael@0: { line: charLine.line, ch: 14 }, michael@0: { line: charLine.line, ch: 16 }, michael@0: { line: charLine.line, ch: 18 }]; michael@0: var parens1 = { michael@0: start: { line: bracesLine.line, ch: 1 }, michael@0: end: { line: bracesLine.line, ch: 3 } michael@0: }; michael@0: var squares1 = { michael@0: start: { line: bracesLine.line, ch: 5 }, michael@0: end: { line: bracesLine.line, ch: 7 } michael@0: }; michael@0: var curlys1 = { michael@0: start: { line: bracesLine.line, ch: 9 }, michael@0: end: { line: bracesLine.line, ch: 11 } michael@0: }; michael@0: var seekOutside = { michael@0: start: { line: seekBraceLine.line, ch: 1 }, michael@0: end: { line: seekBraceLine.line, ch: 16 } michael@0: }; michael@0: var seekInside = { michael@0: start: { line: seekBraceLine.line, ch: 14 }, michael@0: end: { line: seekBraceLine.line, ch: 11 } michael@0: }; michael@0: michael@0: function copyCursor(cur) { michael@0: return { ch: cur.ch, line: cur.line }; michael@0: } michael@0: michael@0: function forEach(arr, func) { michael@0: for (var i = 0; i < arr.length; i++) { michael@0: func(arr[i]); michael@0: } michael@0: } michael@0: michael@0: function testVim(name, run, opts, expectedFail) { michael@0: var vimOpts = { michael@0: lineNumbers: true, michael@0: vimMode: true, michael@0: showCursorWhenSelecting: true, michael@0: value: code michael@0: }; michael@0: for (var prop in opts) { michael@0: if (opts.hasOwnProperty(prop)) { michael@0: vimOpts[prop] = opts[prop]; michael@0: } michael@0: } michael@0: return test('vim_' + name, function() { michael@0: var place = document.getElementById("testground"); michael@0: var cm = CodeMirror(place, vimOpts); michael@0: var vim = CodeMirror.Vim.maybeInitVimState_(cm); michael@0: michael@0: function doKeysFn(cm) { michael@0: return function(args) { michael@0: if (args instanceof Array) { michael@0: arguments = args; michael@0: } michael@0: for (var i = 0; i < arguments.length; i++) { michael@0: CodeMirror.Vim.handleKey(cm, arguments[i]); michael@0: } michael@0: } michael@0: } michael@0: function doInsertModeKeysFn(cm) { michael@0: return function(args) { michael@0: if (args instanceof Array) { arguments = args; } michael@0: function executeHandler(handler) { michael@0: if (typeof handler == 'string') { michael@0: CodeMirror.commands[handler](cm); michael@0: } else { michael@0: handler(cm); michael@0: } michael@0: return true; michael@0: } michael@0: for (var i = 0; i < arguments.length; i++) { michael@0: var key = arguments[i]; michael@0: // Find key in keymap and handle. michael@0: var handled = CodeMirror.lookupKey(key, ['vim-insert'], executeHandler); michael@0: // Record for insert mode. michael@0: if (handled === true && cm.state.vim.insertMode && arguments[i] != 'Esc') { michael@0: var lastChange = CodeMirror.Vim.getVimGlobalState_().macroModeState.lastInsertModeChanges; michael@0: if (lastChange) { michael@0: lastChange.changes.push(new CodeMirror.Vim.InsertModeKey(key)); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: function doExFn(cm) { michael@0: return function(command) { michael@0: cm.openDialog = helpers.fakeOpenDialog(command); michael@0: helpers.doKeys(':'); michael@0: } michael@0: } michael@0: function assertCursorAtFn(cm) { michael@0: return function(line, ch) { michael@0: var pos; michael@0: if (ch == null && typeof line.line == 'number') { michael@0: pos = line; michael@0: } else { michael@0: pos = makeCursor(line, ch); michael@0: } michael@0: eqPos(pos, cm.getCursor()); michael@0: } michael@0: } michael@0: function fakeOpenDialog(result) { michael@0: return function(text, callback) { michael@0: return callback(result); michael@0: } michael@0: } michael@0: function fakeOpenNotification(matcher) { michael@0: return function(text) { michael@0: matcher(text); michael@0: } michael@0: } michael@0: var helpers = { michael@0: doKeys: doKeysFn(cm), michael@0: // Warning: Only emulates keymap events, not character insertions. Use michael@0: // replaceRange to simulate character insertions. michael@0: // Keys are in CodeMirror format, NOT vim format. michael@0: doInsertModeKeys: doInsertModeKeysFn(cm), michael@0: doEx: doExFn(cm), michael@0: assertCursorAt: assertCursorAtFn(cm), michael@0: fakeOpenDialog: fakeOpenDialog, michael@0: fakeOpenNotification: fakeOpenNotification, michael@0: getRegisterController: function() { michael@0: return CodeMirror.Vim.getRegisterController(); michael@0: } michael@0: } michael@0: CodeMirror.Vim.resetVimGlobalState_(); michael@0: var successful = false; michael@0: var savedOpenNotification = cm.openNotification; michael@0: try { michael@0: run(cm, vim, helpers); michael@0: successful = true; michael@0: } finally { michael@0: cm.openNotification = savedOpenNotification; michael@0: if (!successful || verbose) { michael@0: place.style.visibility = "visible"; michael@0: } else { michael@0: place.removeChild(cm.getWrapperElement()); michael@0: } michael@0: } michael@0: }, expectedFail); michael@0: }; michael@0: testVim('qq@q', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'q', 'l', 'l', 'q'); michael@0: helpers.assertCursorAt(0,2); michael@0: helpers.doKeys('@', 'q'); michael@0: helpers.assertCursorAt(0,4); michael@0: }, { value: ' '}); michael@0: testVim('@@', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'q', 'l', 'l', 'q'); michael@0: helpers.assertCursorAt(0,2); michael@0: helpers.doKeys('@', 'q'); michael@0: helpers.assertCursorAt(0,4); michael@0: helpers.doKeys('@', '@'); michael@0: helpers.assertCursorAt(0,6); michael@0: }, { value: ' '}); michael@0: var jumplistScene = ''+ michael@0: 'word\n'+ michael@0: '(word)\n'+ michael@0: '{word\n'+ michael@0: 'word.\n'+ michael@0: '\n'+ michael@0: 'word search\n'+ michael@0: '}word\n'+ michael@0: 'word\n'+ michael@0: 'word\n'; michael@0: function testJumplist(name, keys, endPos, startPos, dialog) { michael@0: endPos = makeCursor(endPos[0], endPos[1]); michael@0: startPos = makeCursor(startPos[0], startPos[1]); michael@0: testVim(name, function(cm, vim, helpers) { michael@0: CodeMirror.Vim.resetVimGlobalState_(); michael@0: if(dialog)cm.openDialog = helpers.fakeOpenDialog('word'); michael@0: cm.setCursor(startPos); michael@0: helpers.doKeys.apply(null, keys); michael@0: helpers.assertCursorAt(endPos); michael@0: }, {value: jumplistScene}); michael@0: }; michael@0: testJumplist('jumplist_H', ['H', ''], [5,2], [5,2]); michael@0: testJumplist('jumplist_M', ['M', ''], [2,2], [2,2]); michael@0: testJumplist('jumplist_L', ['L', ''], [2,2], [2,2]); michael@0: testJumplist('jumplist_[[', ['[', '[', ''], [5,2], [5,2]); michael@0: testJumplist('jumplist_]]', [']', ']', ''], [2,2], [2,2]); michael@0: testJumplist('jumplist_G', ['G', ''], [5,2], [5,2]); michael@0: testJumplist('jumplist_gg', ['g', 'g', ''], [5,2], [5,2]); michael@0: testJumplist('jumplist_%', ['%', ''], [1,5], [1,5]); michael@0: testJumplist('jumplist_{', ['{', ''], [1,5], [1,5]); michael@0: testJumplist('jumplist_}', ['}', ''], [1,5], [1,5]); michael@0: testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', ''], [1,5], [1,5]); michael@0: testJumplist('jumplist_`', ['m', 'a', 'h', '`', 'a', 'h', ''], [1,5], [1,5]); michael@0: testJumplist('jumplist_*_cachedCursor', ['*', ''], [1,3], [1,3]); michael@0: testJumplist('jumplist_#_cachedCursor', ['#', ''], [1,3], [1,3]); michael@0: testJumplist('jumplist_n', ['#', 'n', ''], [1,1], [2,3]); michael@0: testJumplist('jumplist_N', ['#', 'N', ''], [1,1], [2,3]); michael@0: testJumplist('jumplist_repeat_', ['*', '*', '*', '3', ''], [2,3], [2,3]); michael@0: testJumplist('jumplist_repeat_', ['*', '*', '*', '3', '', '2', ''], [5,0], [2,3]); michael@0: testJumplist('jumplist_repeated_motion', ['3', '*', ''], [2,3], [2,3]); michael@0: testJumplist('jumplist_/', ['/', ''], [2,3], [2,3], 'dialog'); michael@0: testJumplist('jumplist_?', ['?', ''], [2,3], [2,3], 'dialog'); michael@0: testJumplist('jumplist_skip_delted_mark', michael@0: ['*', 'n', 'n', 'k', 'd', 'k', '', '', ''], michael@0: [0,2], [0,2]); michael@0: testJumplist('jumplist_skip_delted_mark', michael@0: ['*', 'n', 'n', 'k', 'd', 'k', '', '', ''], michael@0: [1,0], [0,2]); michael@0: michael@0: /** michael@0: * @param name Name of the test michael@0: * @param keys An array of keys or a string with a single key to simulate. michael@0: * @param endPos The expected end position of the cursor. michael@0: * @param startPos The position the cursor should start at, defaults to 0, 0. michael@0: */ michael@0: function testMotion(name, keys, endPos, startPos) { michael@0: testVim(name, function(cm, vim, helpers) { michael@0: if (!startPos) { michael@0: startPos = { line: 0, ch: 0 }; michael@0: } michael@0: cm.setCursor(startPos); michael@0: helpers.doKeys(keys); michael@0: helpers.assertCursorAt(endPos); michael@0: }); michael@0: }; michael@0: michael@0: function makeCursor(line, ch) { michael@0: return { line: line, ch: ch }; michael@0: }; michael@0: michael@0: function offsetCursor(cur, offsetLine, offsetCh) { michael@0: return { line: cur.line + offsetLine, ch: cur.ch + offsetCh }; michael@0: }; michael@0: michael@0: // Motion tests michael@0: testMotion('|', '|', makeCursor(0, 0), makeCursor(0,4)); michael@0: testMotion('|_repeat', ['3', '|'], makeCursor(0, 2), makeCursor(0,4)); michael@0: testMotion('h', 'h', makeCursor(0, 0), word1.start); michael@0: testMotion('h_repeat', ['3', 'h'], offsetCursor(word1.end, 0, -3), word1.end); michael@0: testMotion('l', 'l', makeCursor(0, 1)); michael@0: testMotion('l_repeat', ['2', 'l'], makeCursor(0, 2)); michael@0: testMotion('j', 'j', offsetCursor(word1.end, 1, 0), word1.end); michael@0: testMotion('j_repeat', ['2', 'j'], offsetCursor(word1.end, 2, 0), word1.end); michael@0: testMotion('j_repeat_clip', ['1000', 'j'], endOfDocument); michael@0: testMotion('k', 'k', offsetCursor(word3.end, -1, 0), word3.end); michael@0: testMotion('k_repeat', ['2', 'k'], makeCursor(0, 4), makeCursor(2, 4)); michael@0: testMotion('k_repeat_clip', ['1000', 'k'], makeCursor(0, 4), makeCursor(2, 4)); michael@0: testMotion('w', 'w', word1.start); michael@0: testMotion('w_multiple_newlines_no_space', 'w', makeCursor(12, 2), makeCursor(11, 2)); michael@0: testMotion('w_multiple_newlines_with_space', 'w', makeCursor(14, 0), makeCursor(12, 51)); michael@0: testMotion('w_repeat', ['2', 'w'], word2.start); michael@0: testMotion('w_wrap', ['w'], word3.start, word2.start); michael@0: testMotion('w_endOfDocument', 'w', endOfDocument, endOfDocument); michael@0: testMotion('w_start_to_end', ['1000', 'w'], endOfDocument, makeCursor(0, 0)); michael@0: testMotion('W', 'W', bigWord1.start); michael@0: testMotion('W_repeat', ['2', 'W'], bigWord3.start, bigWord1.start); michael@0: testMotion('e', 'e', word1.end); michael@0: testMotion('e_repeat', ['2', 'e'], word2.end); michael@0: testMotion('e_wrap', 'e', word3.end, word2.end); michael@0: testMotion('e_endOfDocument', 'e', endOfDocument, endOfDocument); michael@0: testMotion('e_start_to_end', ['1000', 'e'], endOfDocument, makeCursor(0, 0)); michael@0: testMotion('b', 'b', word3.start, word3.end); michael@0: testMotion('b_repeat', ['2', 'b'], word2.start, word3.end); michael@0: testMotion('b_wrap', 'b', word2.start, word3.start); michael@0: testMotion('b_startOfDocument', 'b', makeCursor(0, 0), makeCursor(0, 0)); michael@0: testMotion('b_end_to_start', ['1000', 'b'], makeCursor(0, 0), endOfDocument); michael@0: testMotion('ge', ['g', 'e'], word2.end, word3.end); michael@0: testMotion('ge_repeat', ['2', 'g', 'e'], word1.end, word3.start); michael@0: testMotion('ge_wrap', ['g', 'e'], word2.end, word3.start); michael@0: testMotion('ge_startOfDocument', ['g', 'e'], makeCursor(0, 0), michael@0: makeCursor(0, 0)); michael@0: testMotion('ge_end_to_start', ['1000', 'g', 'e'], makeCursor(0, 0), endOfDocument); michael@0: testMotion('gg', ['g', 'g'], makeCursor(lines[0].line, lines[0].textStart), michael@0: makeCursor(3, 1)); michael@0: testMotion('gg_repeat', ['3', 'g', 'g'], michael@0: makeCursor(lines[2].line, lines[2].textStart)); michael@0: testMotion('G', 'G', michael@0: makeCursor(lines[lines.length - 1].line, lines[lines.length - 1].textStart), michael@0: makeCursor(3, 1)); michael@0: testMotion('G_repeat', ['3', 'G'], makeCursor(lines[2].line, michael@0: lines[2].textStart)); michael@0: // TODO: Make the test code long enough to test Ctrl-F and Ctrl-B. michael@0: testMotion('0', '0', makeCursor(0, 0), makeCursor(0, 8)); michael@0: testMotion('^', '^', makeCursor(0, lines[0].textStart), makeCursor(0, 8)); michael@0: testMotion('+', '+', makeCursor(1, lines[1].textStart), makeCursor(0, 8)); michael@0: testMotion('-', '-', makeCursor(0, lines[0].textStart), makeCursor(1, 4)); michael@0: testMotion('_', ['6','_'], makeCursor(5, lines[5].textStart), makeCursor(0, 8)); michael@0: testMotion('$', '$', makeCursor(0, lines[0].length - 1), makeCursor(0, 1)); michael@0: testMotion('$_repeat', ['2', '$'], makeCursor(1, lines[1].length - 1), michael@0: makeCursor(0, 3)); michael@0: testMotion('f', ['f', 'p'], pChars[0], makeCursor(charLine.line, 0)); michael@0: testMotion('f_repeat', ['2', 'f', 'p'], pChars[2], pChars[0]); michael@0: testMotion('f_num', ['f', '2'], numChars[2], makeCursor(charLine.line, 0)); michael@0: testMotion('t', ['t','p'], offsetCursor(pChars[0], 0, -1), michael@0: makeCursor(charLine.line, 0)); michael@0: testMotion('t_repeat', ['2', 't', 'p'], offsetCursor(pChars[2], 0, -1), michael@0: pChars[0]); michael@0: testMotion('F', ['F', 'p'], pChars[0], pChars[1]); michael@0: testMotion('F_repeat', ['2', 'F', 'p'], pChars[0], pChars[2]); michael@0: testMotion('T', ['T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[1]); michael@0: testMotion('T_repeat', ['2', 'T', 'p'], offsetCursor(pChars[0], 0, 1), pChars[2]); michael@0: testMotion('%_parens', ['%'], parens1.end, parens1.start); michael@0: testMotion('%_squares', ['%'], squares1.end, squares1.start); michael@0: testMotion('%_braces', ['%'], curlys1.end, curlys1.start); michael@0: testMotion('%_seek_outside', ['%'], seekOutside.end, seekOutside.start); michael@0: testMotion('%_seek_inside', ['%'], seekInside.end, seekInside.start); michael@0: testVim('%_seek_skip', function(cm, vim, helpers) { michael@0: cm.setCursor(0,0); michael@0: helpers.doKeys(['%']); michael@0: helpers.assertCursorAt(0,9); michael@0: }, {value:'01234"("()'}); michael@0: testVim('%_skip_string', function(cm, vim, helpers) { michael@0: cm.setCursor(0,0); michael@0: helpers.doKeys(['%']); michael@0: helpers.assertCursorAt(0,4); michael@0: cm.setCursor(0,2); michael@0: helpers.doKeys(['%']); michael@0: helpers.assertCursorAt(0,0); michael@0: }, {value:'(")")'}); michael@0: (')') michael@0: testVim('%_skip_comment', function(cm, vim, helpers) { michael@0: cm.setCursor(0,0); michael@0: helpers.doKeys(['%']); michael@0: helpers.assertCursorAt(0,6); michael@0: cm.setCursor(0,3); michael@0: helpers.doKeys(['%']); michael@0: helpers.assertCursorAt(0,0); michael@0: }, {value:'(/*)*/)'}); michael@0: // Make sure that moving down after going to the end of a line always leaves you michael@0: // at the end of a line, but preserves the offset in other cases michael@0: testVim('Changing lines after Eol operation', function(cm, vim, helpers) { michael@0: cm.setCursor(0,0); michael@0: helpers.doKeys(['$']); michael@0: helpers.doKeys(['j']); michael@0: // After moving to Eol and then down, we should be at Eol of line 2 michael@0: helpers.assertCursorAt({ line: 1, ch: lines[1].length - 1 }); michael@0: helpers.doKeys(['j']); michael@0: // After moving down, we should be at Eol of line 3 michael@0: helpers.assertCursorAt({ line: 2, ch: lines[2].length - 1 }); michael@0: helpers.doKeys(['h']); michael@0: helpers.doKeys(['j']); michael@0: // After moving back one space and then down, since line 4 is shorter than line 2, we should michael@0: // be at Eol of line 2 - 1 michael@0: helpers.assertCursorAt({ line: 3, ch: lines[3].length - 1 }); michael@0: helpers.doKeys(['j']); michael@0: helpers.doKeys(['j']); michael@0: // After moving down again, since line 3 has enough characters, we should be back to the michael@0: // same place we were at on line 1 michael@0: helpers.assertCursorAt({ line: 5, ch: lines[2].length - 2 }); michael@0: }); michael@0: //making sure gj and gk recover from clipping michael@0: testVim('gj_gk_clipping', function(cm,vim,helpers){ michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('g','j','g','j'); michael@0: helpers.assertCursorAt(2, 1); michael@0: helpers.doKeys('g','k','g','k'); michael@0: helpers.assertCursorAt(0, 1); michael@0: },{value: 'line 1\n\nline 2'}); michael@0: //testing a mix of j/k and gj/gk michael@0: testVim('j_k_and_gj_gk', function(cm,vim,helpers){ michael@0: cm.setSize(120); michael@0: cm.setCursor(0, 0); michael@0: //go to the last character on the first line michael@0: helpers.doKeys('$'); michael@0: //move up/down on the column within the wrapped line michael@0: //side-effect: cursor is not locked to eol anymore michael@0: helpers.doKeys('g','k'); michael@0: var cur=cm.getCursor(); michael@0: eq(cur.line,0); michael@0: is((cur.ch<176),'gk didn\'t move cursor back (1)'); michael@0: helpers.doKeys('g','j'); michael@0: helpers.assertCursorAt(0, 176); michael@0: //should move to character 177 on line 2 (j/k preserve character index within line) michael@0: helpers.doKeys('j'); michael@0: //due to different line wrapping, the cursor can be on a different screen-x now michael@0: //gj and gk preserve screen-x on movement, much like moveV michael@0: helpers.doKeys('3','g','k'); michael@0: cur=cm.getCursor(); michael@0: eq(cur.line,1); michael@0: is((cur.ch<176),'gk didn\'t move cursor back (2)'); michael@0: helpers.doKeys('g','j','2','g','j'); michael@0: //should return to the same character-index michael@0: helpers.doKeys('k'); michael@0: helpers.assertCursorAt(0, 176); michael@0: },{ 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.'}); michael@0: testVim('gj_gk', function(cm, vim, helpers) { michael@0: if (phantom) return; michael@0: cm.setSize(120); michael@0: // Test top of document edge case. michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('g', 'j'); michael@0: helpers.doKeys('10', 'g', 'k'); michael@0: helpers.assertCursorAt(0, 4); michael@0: michael@0: // Test moving down preserves column position. michael@0: helpers.doKeys('g', 'j'); michael@0: var pos1 = cm.getCursor(); michael@0: var expectedPos2 = { line: 0, ch: (pos1.ch - 4) * 2 + 4}; michael@0: helpers.doKeys('g', 'j'); michael@0: helpers.assertCursorAt(expectedPos2); michael@0: michael@0: // Move to the last character michael@0: cm.setCursor(0, 0); michael@0: // Move left to reset HSPos michael@0: helpers.doKeys('h'); michael@0: // Test bottom of document edge case. michael@0: helpers.doKeys('100', 'g', 'j'); michael@0: var endingPos = cm.getCursor(); michael@0: is(endingPos != 0, 'gj should not be on wrapped line 0'); michael@0: var topLeftCharCoords = cm.charCoords(makeCursor(0, 0)); michael@0: var endingCharCoords = cm.charCoords(endingPos); michael@0: is(topLeftCharCoords.left == endingCharCoords.left, 'gj should end up on column 0'); michael@0: },{ lineNumbers: false, lineWrapping:true, value: 'Thislineisintentiallylongtotestmovementofgjandgkoverwrappedlines.' }); michael@0: testVim('}', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('}'); michael@0: helpers.assertCursorAt(1, 0); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', '}'); michael@0: helpers.assertCursorAt(4, 0); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('6', '}'); michael@0: helpers.assertCursorAt(5, 0); michael@0: }, { value: 'a\n\nb\nc\n\nd' }); michael@0: testVim('{', function(cm, vim, helpers) { michael@0: cm.setCursor(5, 0); michael@0: helpers.doKeys('{'); michael@0: helpers.assertCursorAt(4, 0); michael@0: cm.setCursor(5, 0); michael@0: helpers.doKeys('2', '{'); michael@0: helpers.assertCursorAt(1, 0); michael@0: cm.setCursor(5, 0); michael@0: helpers.doKeys('6', '{'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'a\n\nb\nc\n\nd' }); michael@0: michael@0: // Operator tests michael@0: testVim('dl', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 0); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'l'); michael@0: eq('word1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' ', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dl_eol', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 6); michael@0: helpers.doKeys('d', 'l'); michael@0: eq(' word1', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' ', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 5); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dl_repeat', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 0); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('2', 'd', 'l'); michael@0: eq('ord1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' w', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dh', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'h'); michael@0: eq(' wrd1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('o', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(offsetCursor(curStart, 0 , -1), cm.getCursor()); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dj', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'j'); michael@0: eq(' word3', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' word1\nword2\n', register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: ' word1\nword2\n word3' }); michael@0: testVim('dj_end_of_document', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'j'); michael@0: eq(' word1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dk', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(1, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'k'); michael@0: eq(' word3', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' word1\nword2\n', register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: ' word1\nword2\n word3' }); michael@0: testVim('dk_start_of_document', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'k'); michael@0: eq(' word1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dw_space', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 0); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('word1 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(' ', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dw_word', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 1); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'w'); michael@0: eq(' word2', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1 ', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1 word2' }); michael@0: testVim('dw_only_word', function(cm, vim, helpers) { michael@0: // Test that if there is only 1 word left, dw deletes till the end of the michael@0: // line. michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('d', 'w'); michael@0: eq(' ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1 ', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: ' word1 ' }); michael@0: testVim('dw_eol', function(cm, vim, helpers) { michael@0: // Assert that dw does not delete the newline if last word to delete is at end michael@0: // of line. michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('d', 'w'); michael@0: eq(' \nword2', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: ' word1\nword2' }); michael@0: testVim('dw_eol_with_multiple_newlines', function(cm, vim, helpers) { michael@0: // Assert that dw does not delete the newline if last word to delete is at end michael@0: // of line and it is followed by multiple newlines. michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('d', 'w'); michael@0: eq(' \n\nword2', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: ' word1\n\nword2' }); michael@0: testVim('dw_empty_line_followed_by_whitespace', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq(' \nword', cm.getValue()); michael@0: }, { value: '\n \nword' }); michael@0: testVim('dw_empty_line_followed_by_word', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('word', cm.getValue()); michael@0: }, { value: '\nword' }); michael@0: testVim('dw_empty_line_followed_by_empty_line', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('\n', cm.getValue()); michael@0: }, { value: '\n\n' }); michael@0: testVim('dw_whitespace_followed_by_whitespace', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('\n \n', cm.getValue()); michael@0: }, { value: ' \n \n' }); michael@0: testVim('dw_whitespace_followed_by_empty_line', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('\n\n', cm.getValue()); michael@0: }, { value: ' \n\n' }); michael@0: testVim('dw_word_whitespace_word', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('\n \nword2', cm.getValue()); michael@0: }, { value: 'word1\n \nword2'}) michael@0: testVim('dw_end_of_document', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('d', 'w'); michael@0: eq('\nab', cm.getValue()); michael@0: }, { value: '\nabc' }); michael@0: testVim('dw_repeat', function(cm, vim, helpers) { michael@0: // Assert that dw does delete newline if it should go to the next line, and michael@0: // that repeat works properly. michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('d', '2', 'w'); michael@0: eq(' ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1\nword2', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: ' word1\nword2' }); michael@0: testVim('de_word_start_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'e'); michael@0: eq('\n\n', cm.getValue()); michael@0: }, { value: 'word\n\n' }); michael@0: testVim('de_word_end_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('d', 'e'); michael@0: eq('wor', cm.getValue()); michael@0: }, { value: 'word\n\n\n' }); michael@0: testVim('de_whitespace_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'e'); michael@0: eq('', cm.getValue()); michael@0: }, { value: ' \n\n\n' }); michael@0: testVim('de_end_of_document', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('d', 'e'); michael@0: eq('\nab', cm.getValue()); michael@0: }, { value: '\nabc' }); michael@0: testVim('db_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('d', 'b'); michael@0: eq('\n\n', cm.getValue()); michael@0: }, { value: '\n\n\n' }); michael@0: testVim('db_word_start_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('d', 'b'); michael@0: eq('\nword', cm.getValue()); michael@0: }, { value: '\n\nword' }); michael@0: testVim('db_word_end_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 3); michael@0: helpers.doKeys('d', 'b'); michael@0: eq('\n\nd', cm.getValue()); michael@0: }, { value: '\n\nword' }); michael@0: testVim('db_whitespace_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('d', 'b'); michael@0: eq('', cm.getValue()); michael@0: }, { value: '\n \n' }); michael@0: testVim('db_start_of_document', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'b'); michael@0: eq('abc\n', cm.getValue()); michael@0: }, { value: 'abc\n' }); michael@0: testVim('dge_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: helpers.doKeys('d', 'g', 'e'); michael@0: // Note: In real VIM the result should be '', but it's not quite consistent, michael@0: // since 2 newlines are deleted. But in the similar case of word\n\n, only michael@0: // 1 newline is deleted. We'll diverge from VIM's behavior since it's much michael@0: // easier this way. michael@0: eq('\n', cm.getValue()); michael@0: }, { value: '\n\n' }); michael@0: testVim('dge_word_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: helpers.doKeys('d', 'g', 'e'); michael@0: eq('wor\n', cm.getValue()); michael@0: }, { value: 'word\n\n'}); michael@0: testVim('dge_whitespace_and_empty_lines', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('d', 'g', 'e'); michael@0: eq('', cm.getValue()); michael@0: }, { value: '\n \n' }); michael@0: testVim('dge_start_of_document', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', 'g', 'e'); michael@0: eq('bc\n', cm.getValue()); michael@0: }, { value: 'abc\n' }); michael@0: testVim('d_inclusive', function(cm, vim, helpers) { michael@0: // Assert that when inclusive is set, the character the cursor is on gets michael@0: // deleted too. michael@0: var curStart = makeCursor(0, 1); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('d', 'e'); michael@0: eq(' ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1 ' }); michael@0: testVim('d_reverse', function(cm, vim, helpers) { michael@0: // Test that deleting in reverse works. michael@0: cm.setCursor(1, 0); michael@0: helpers.doKeys('d', 'b'); michael@0: eq(' word2 ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1\n', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: ' word1\nword2 ' }); michael@0: testVim('dd', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 1, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount() - 1; michael@0: helpers.doKeys('d', 'd'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, lines[1].textStart); michael@0: }); michael@0: testVim('dd_prefix_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 2, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount() - 2; michael@0: helpers.doKeys('2', 'd', 'd'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, lines[2].textStart); michael@0: }); michael@0: testVim('dd_motion_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 2, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount() - 2; michael@0: helpers.doKeys('d', '2', 'd'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, lines[2].textStart); michael@0: }); michael@0: testVim('dd_multiply_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 6, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount() - 6; michael@0: helpers.doKeys('2', 'd', '3', 'd'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: helpers.assertCursorAt(0, lines[6].textStart); michael@0: }); michael@0: testVim('dd_lastline', function(cm, vim, helpers) { michael@0: cm.setCursor(cm.lineCount(), 0); michael@0: var expectedLineCount = cm.lineCount() - 1; michael@0: helpers.doKeys('d', 'd'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: helpers.assertCursorAt(cm.lineCount() - 1, 0); michael@0: }); michael@0: // Yank commands should behave the exact same as d commands, expect that nothing michael@0: // gets deleted. michael@0: testVim('yw_repeat', function(cm, vim, helpers) { michael@0: // Assert that yw does yank newline if it should go to the next line, and michael@0: // that repeat works properly. michael@0: var curStart = makeCursor(0, 1); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('y', '2', 'w'); michael@0: eq(' word1\nword2', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1\nword2', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1\nword2' }); michael@0: testVim('yy_multiply_repeat', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 6, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount(); michael@0: helpers.doKeys('2', 'y', '3', 'y'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }); michael@0: // Change commands behave like d commands except that it also enters insert michael@0: // mode. In addition, when the change is linewise, an additional newline is michael@0: // inserted so that insert mode starts on that line. michael@0: testVim('cw', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('c', '2', 'w'); michael@0: eq(' word3', cm.getValue()); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'word1 word2 word3'}); michael@0: testVim('cw_repeat', function(cm, vim, helpers) { michael@0: // Assert that cw does delete newline if it should go to the next line, and michael@0: // that repeat works properly. michael@0: var curStart = makeCursor(0, 1); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('c', '2', 'w'); michael@0: eq(' ', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('word1\nword2', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: ' word1\nword2' }); michael@0: testVim('cc_multiply_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedBuffer = cm.getRange({ line: 0, ch: 0 }, michael@0: { line: 6, ch: 0 }); michael@0: var expectedLineCount = cm.lineCount() - 5; michael@0: helpers.doKeys('2', 'c', '3', 'c'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq(expectedBuffer, register.toString()); michael@0: is(register.linewise); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('cc_append', function(cm, vim, helpers) { michael@0: var expectedLineCount = cm.lineCount(); michael@0: cm.setCursor(cm.lastLine(), 0); michael@0: helpers.doKeys('c', 'c'); michael@0: eq(expectedLineCount, cm.lineCount()); michael@0: }); michael@0: // Swapcase commands edit in place and do not modify registers. michael@0: testVim('g~w_repeat', function(cm, vim, helpers) { michael@0: // Assert that dw does delete newline if it should go to the next line, and michael@0: // that repeat works properly. michael@0: var curStart = makeCursor(0, 1); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('g', '~', '2', 'w'); michael@0: eq(' WORD1\nWORD2', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1\nword2' }); michael@0: testVim('g~g~', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: var expectedLineCount = cm.lineCount(); michael@0: var expectedValue = cm.getValue().toUpperCase(); michael@0: helpers.doKeys('2', 'g', '~', '3', 'g', '~'); michael@0: eq(expectedValue, cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: }, { value: ' word1\nword2\nword3\nword4\nword5\nword6' }); michael@0: testVim('>{motion}', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 3); michael@0: var expectedLineCount = cm.lineCount(); michael@0: var expectedValue = ' word1\n word2\nword3 '; michael@0: helpers.doKeys('>', 'k'); michael@0: eq(expectedValue, cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: ' word1\nword2\nword3 ', indentUnit: 2 }); michael@0: testVim('>>', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedLineCount = cm.lineCount(); michael@0: var expectedValue = ' word1\n word2\nword3 '; michael@0: helpers.doKeys('2', '>', '>'); michael@0: eq(expectedValue, cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: ' word1\nword2\nword3 ', indentUnit: 2 }); michael@0: testVim('<{motion}', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 3); michael@0: var expectedLineCount = cm.lineCount(); michael@0: var expectedValue = ' word1\nword2\nword3 '; michael@0: helpers.doKeys('<', 'k'); michael@0: eq(expectedValue, cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: ' word1\n word2\nword3 ', indentUnit: 2 }); michael@0: testVim('<<', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: var expectedLineCount = cm.lineCount(); michael@0: var expectedValue = ' word1\nword2\nword3 '; michael@0: helpers.doKeys('2', '<', '<'); michael@0: eq(expectedValue, cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: ' word1\n word2\nword3 ', indentUnit: 2 }); michael@0: michael@0: // Edit tests michael@0: function testEdit(name, before, pos, edit, after) { michael@0: return testVim(name, function(cm, vim, helpers) { michael@0: var ch = before.search(pos) michael@0: var line = before.substring(0, ch).split('\n').length - 1; michael@0: if (line) { michael@0: ch = before.substring(0, ch).split('\n').pop().length; michael@0: } michael@0: cm.setCursor(line, ch); michael@0: helpers.doKeys.apply(this, edit.split('')); michael@0: eq(after, cm.getValue()); michael@0: }, {value: before}); michael@0: } michael@0: michael@0: // These Delete tests effectively cover word-wise Change, Visual & Yank. michael@0: // Tabs are used as differentiated whitespace to catch edge cases. michael@0: // Normal word: michael@0: testEdit('diw_mid_spc', 'foo \tbAr\t baz', /A/, 'diw', 'foo \t\t baz'); michael@0: testEdit('daw_mid_spc', 'foo \tbAr\t baz', /A/, 'daw', 'foo \tbaz'); michael@0: testEdit('diw_mid_punct', 'foo \tbAr.\t baz', /A/, 'diw', 'foo \t.\t baz'); michael@0: testEdit('daw_mid_punct', 'foo \tbAr.\t baz', /A/, 'daw', 'foo.\t baz'); michael@0: testEdit('diw_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'diw', 'foo \t,.\t baz'); michael@0: testEdit('daw_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'daw', 'foo \t,.\t baz'); michael@0: testEdit('diw_start_spc', 'bAr \tbaz', /A/, 'diw', ' \tbaz'); michael@0: testEdit('daw_start_spc', 'bAr \tbaz', /A/, 'daw', 'baz'); michael@0: testEdit('diw_start_punct', 'bAr. \tbaz', /A/, 'diw', '. \tbaz'); michael@0: testEdit('daw_start_punct', 'bAr. \tbaz', /A/, 'daw', '. \tbaz'); michael@0: testEdit('diw_end_spc', 'foo \tbAr', /A/, 'diw', 'foo \t'); michael@0: testEdit('daw_end_spc', 'foo \tbAr', /A/, 'daw', 'foo'); michael@0: testEdit('diw_end_punct', 'foo \tbAr.', /A/, 'diw', 'foo \t.'); michael@0: testEdit('daw_end_punct', 'foo \tbAr.', /A/, 'daw', 'foo.'); michael@0: // Big word: michael@0: testEdit('diW_mid_spc', 'foo \tbAr\t baz', /A/, 'diW', 'foo \t\t baz'); michael@0: testEdit('daW_mid_spc', 'foo \tbAr\t baz', /A/, 'daW', 'foo \tbaz'); michael@0: testEdit('diW_mid_punct', 'foo \tbAr.\t baz', /A/, 'diW', 'foo \t\t baz'); michael@0: testEdit('daW_mid_punct', 'foo \tbAr.\t baz', /A/, 'daW', 'foo \tbaz'); michael@0: testEdit('diW_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'diW', 'foo \t\t baz'); michael@0: testEdit('daW_mid_punct2', 'foo \t,bAr.\t baz', /A/, 'daW', 'foo \tbaz'); michael@0: testEdit('diW_start_spc', 'bAr\t baz', /A/, 'diW', '\t baz'); michael@0: testEdit('daW_start_spc', 'bAr\t baz', /A/, 'daW', 'baz'); michael@0: testEdit('diW_start_punct', 'bAr.\t baz', /A/, 'diW', '\t baz'); michael@0: testEdit('daW_start_punct', 'bAr.\t baz', /A/, 'daW', 'baz'); michael@0: testEdit('diW_end_spc', 'foo \tbAr', /A/, 'diW', 'foo \t'); michael@0: testEdit('daW_end_spc', 'foo \tbAr', /A/, 'daW', 'foo'); michael@0: testEdit('diW_end_punct', 'foo \tbAr.', /A/, 'diW', 'foo \t'); michael@0: testEdit('daW_end_punct', 'foo \tbAr.', /A/, 'daW', 'foo'); michael@0: // Deleting text objects michael@0: // Open and close on same line michael@0: testEdit('di(_open_spc', 'foo (bAr) baz', /\(/, 'di(', 'foo () baz'); michael@0: testEdit('di)_open_spc', 'foo (bAr) baz', /\(/, 'di)', 'foo () baz'); michael@0: testEdit('da(_open_spc', 'foo (bAr) baz', /\(/, 'da(', 'foo baz'); michael@0: testEdit('da)_open_spc', 'foo (bAr) baz', /\(/, 'da)', 'foo baz'); michael@0: michael@0: testEdit('di(_middle_spc', 'foo (bAr) baz', /A/, 'di(', 'foo () baz'); michael@0: testEdit('di)_middle_spc', 'foo (bAr) baz', /A/, 'di)', 'foo () baz'); michael@0: testEdit('da(_middle_spc', 'foo (bAr) baz', /A/, 'da(', 'foo baz'); michael@0: testEdit('da)_middle_spc', 'foo (bAr) baz', /A/, 'da)', 'foo baz'); michael@0: michael@0: testEdit('di(_close_spc', 'foo (bAr) baz', /\)/, 'di(', 'foo () baz'); michael@0: testEdit('di)_close_spc', 'foo (bAr) baz', /\)/, 'di)', 'foo () baz'); michael@0: testEdit('da(_close_spc', 'foo (bAr) baz', /\)/, 'da(', 'foo baz'); michael@0: testEdit('da)_close_spc', 'foo (bAr) baz', /\)/, 'da)', 'foo baz'); michael@0: michael@0: // Open and close on different lines, equally indented michael@0: testEdit('di{_middle_spc', 'a{\n\tbar\n}b', /r/, 'di{', 'a{}b'); michael@0: testEdit('di}_middle_spc', 'a{\n\tbar\n}b', /r/, 'di}', 'a{}b'); michael@0: testEdit('da{_middle_spc', 'a{\n\tbar\n}b', /r/, 'da{', 'ab'); michael@0: testEdit('da}_middle_spc', 'a{\n\tbar\n}b', /r/, 'da}', 'ab'); michael@0: michael@0: // open and close on diff lines, open indented less than close michael@0: testEdit('di{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di{', 'a{}b'); michael@0: testEdit('di}_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di}', 'a{}b'); michael@0: testEdit('da{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'da{', 'ab'); michael@0: testEdit('da}_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'da}', 'ab'); michael@0: michael@0: // open and close on diff lines, open indented more than close michael@0: testEdit('di[_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'di[', 'a\t[]b'); michael@0: testEdit('di]_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'di]', 'a\t[]b'); michael@0: testEdit('da[_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'da[', 'a\tb'); michael@0: testEdit('da]_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'da]', 'a\tb'); michael@0: michael@0: // Operator-motion tests michael@0: testVim('D', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('D'); michael@0: eq(' wo\nword2\n word3', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('rd1', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 2); michael@0: }, { value: ' word1\nword2\n word3' }); michael@0: testVim('C', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('C'); michael@0: eq(' wo\nword2\n word3', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('rd1', register.toString()); michael@0: is(!register.linewise); michael@0: eqPos(curStart, cm.getCursor()); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: ' word1\nword2\n word3' }); michael@0: testVim('Y', function(cm, vim, helpers) { michael@0: var curStart = makeCursor(0, 3); michael@0: cm.setCursor(curStart); michael@0: helpers.doKeys('Y'); michael@0: eq(' word1\nword2\n word3', cm.getValue()); michael@0: var register = helpers.getRegisterController().getRegister(); michael@0: eq('rd1', register.toString()); michael@0: is(!register.linewise); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: ' word1\nword2\n word3' }); michael@0: testVim('~', function(cm, vim, helpers) { michael@0: helpers.doKeys('3', '~'); michael@0: eq('ABCdefg', cm.getValue()); michael@0: helpers.assertCursorAt(0, 3); michael@0: }, { value: 'abcdefg' }); michael@0: michael@0: // Action tests michael@0: testVim('ctrl-a', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(''); michael@0: eq('-9', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: helpers.doKeys('2',''); michael@0: eq('-7', cm.getValue()); michael@0: }, {value: '-10'}); michael@0: testVim('ctrl-x', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(''); michael@0: eq('-1', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: helpers.doKeys('2',''); michael@0: eq('-3', cm.getValue()); michael@0: }, {value: '0'}); michael@0: testVim('/ search forward', function(cm, vim, helpers) { michael@0: forEach(['', ''], function(key) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(key); michael@0: helpers.assertCursorAt(0, 5); michael@0: helpers.doKeys('l'); michael@0: helpers.doKeys(key); michael@0: helpers.assertCursorAt(0, 10); michael@0: cm.setCursor(0, 11); michael@0: helpers.doKeys(key); michael@0: helpers.assertCursorAt(0, 11); michael@0: }); michael@0: }, {value: '__jmp1 jmp2 jmp'}); michael@0: testVim('a', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('a'); michael@0: helpers.assertCursorAt(0, 2); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('a_eol', function(cm, vim, helpers) { michael@0: cm.setCursor(0, lines[0].length - 1); michael@0: helpers.doKeys('a'); michael@0: helpers.assertCursorAt(0, lines[0].length); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('i', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('i'); michael@0: helpers.assertCursorAt(0, 1); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('i_repeat', function(cm, vim, helpers) { michael@0: helpers.doKeys('3', 'i'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: eq('testtesttest', cm.getValue()); michael@0: helpers.assertCursorAt(0, 11); michael@0: }, { value: '' }); michael@0: testVim('i_repeat_delete', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('2', 'i'); michael@0: cm.replaceRange('z', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Backspace', 'Backspace', 'Esc'); michael@0: eq('abe', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: 'abcde' }); michael@0: testVim('A', function(cm, vim, helpers) { michael@0: helpers.doKeys('A'); michael@0: helpers.assertCursorAt(0, lines[0].length); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('I', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('I'); michael@0: helpers.assertCursorAt(0, lines[0].textStart); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }); michael@0: testVim('I_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('3', 'I'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: eq('testtesttestblah', cm.getValue()); michael@0: helpers.assertCursorAt(0, 11); michael@0: }, { value: 'blah' }); michael@0: testVim('o', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('o'); michael@0: eq('word1\n\nword2', cm.getValue()); michael@0: helpers.assertCursorAt(1, 0); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: 'word1\nword2' }); michael@0: testVim('o_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('3', 'o'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: eq('\ntest\ntest\ntest', cm.getValue()); michael@0: helpers.assertCursorAt(3, 3); michael@0: }, { value: '' }); michael@0: testVim('O', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('O'); michael@0: eq('\nword1\nword2', cm.getValue()); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: 'word1\nword2' }); michael@0: testVim('J', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('J'); michael@0: var expectedValue = 'word1 word2\nword3\n word4'; michael@0: eq(expectedValue, cm.getValue()); michael@0: helpers.assertCursorAt(0, expectedValue.indexOf('word2') - 1); michael@0: }, { value: 'word1 \n word2\nword3\n word4' }); michael@0: testVim('J_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('3', 'J'); michael@0: var expectedValue = 'word1 word2 word3\n word4'; michael@0: eq(expectedValue, cm.getValue()); michael@0: helpers.assertCursorAt(0, expectedValue.indexOf('word3') - 1); michael@0: }, { value: 'word1 \n word2\nword3\n word4' }); michael@0: testVim('p', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false); michael@0: helpers.doKeys('p'); michael@0: eq('__abc\ndef_', cm.getValue()); michael@0: helpers.assertCursorAt(1, 2); michael@0: }, { value: '___' }); michael@0: testVim('p_register', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().getRegister('a').setText('abc\ndef', false); michael@0: helpers.doKeys('"', 'a', 'p'); michael@0: eq('__abc\ndef_', cm.getValue()); michael@0: helpers.assertCursorAt(1, 2); michael@0: }, { value: '___' }); michael@0: testVim('p_wrong_register', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().getRegister('a').setText('abc\ndef', false); michael@0: helpers.doKeys('p'); michael@0: eq('___', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: '___' }); michael@0: testVim('p_line', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true); michael@0: helpers.doKeys('2', 'p'); michael@0: eq('___\n a\nd\n a\nd', cm.getValue()); michael@0: helpers.assertCursorAt(1, 2); michael@0: }, { value: '___' }); michael@0: testVim('p_lastline', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().pushText('"', 'yank', ' a\nd', true); michael@0: helpers.doKeys('2', 'p'); michael@0: eq('___\n a\nd\n a\nd', cm.getValue()); michael@0: helpers.assertCursorAt(1, 2); michael@0: }, { value: '___' }); michael@0: testVim('P', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false); michael@0: helpers.doKeys('P'); michael@0: eq('_abc\ndef__', cm.getValue()); michael@0: helpers.assertCursorAt(1, 3); michael@0: }, { value: '___' }); michael@0: testVim('P_line', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.getRegisterController().pushText('"', 'yank', ' a\nd\n', true); michael@0: helpers.doKeys('2', 'P'); michael@0: eq(' a\nd\n a\nd\n___', cm.getValue()); michael@0: helpers.assertCursorAt(0, 2); michael@0: }, { value: '___' }); michael@0: testVim('r', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('3', 'r', 'u'); michael@0: eq('wuuuet\nanother', cm.getValue(),'3r failed'); michael@0: helpers.assertCursorAt(0, 3); michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('v', 'j', 'h', 'r', ''); michael@0: eq('wuuu \n her', cm.getValue(),'Replacing selection by space-characters failed'); michael@0: }, { value: 'wordet\nanother' }); michael@0: testVim('R', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('R'); michael@0: helpers.assertCursorAt(0, 1); michael@0: eq('vim-replace', cm.getOption('keyMap')); michael@0: is(cm.state.overwrite, 'Setting overwrite state failed'); michael@0: }); michael@0: testVim('mark', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 't'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('\'', 't'); michael@0: helpers.assertCursorAt(2, 2); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 't'); michael@0: helpers.assertCursorAt(2, 2); michael@0: }); michael@0: testVim('jumpToMark_next', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 't'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(']', '`'); michael@0: helpers.assertCursorAt(2, 2); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(']', '\''); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_next_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', ']', '`'); michael@0: helpers.assertCursorAt(3, 2); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', ']', '\''); michael@0: helpers.assertCursorAt(3, 1); michael@0: }); michael@0: testVim('jumpToMark_next_sameline', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 4); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys(']', '`'); michael@0: helpers.assertCursorAt(2, 4); michael@0: }); michael@0: testVim('jumpToMark_next_onlyprev', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(4, 0); michael@0: helpers.doKeys(']', '`'); michael@0: helpers.assertCursorAt(4, 0); michael@0: }); michael@0: testVim('jumpToMark_next_nomark', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys(']', '`'); michael@0: helpers.assertCursorAt(2, 2); michael@0: helpers.doKeys(']', '\''); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_next_linewise_over', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(3, 4); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(2, 1); michael@0: helpers.doKeys(']', '\''); michael@0: helpers.assertCursorAt(3, 1); michael@0: }); michael@0: testVim('jumpToMark_next_action', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 't'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ']', '`'); michael@0: helpers.assertCursorAt(0, 0); michael@0: var actual = cm.getLine(0); michael@0: var expected = 'pop pop 0 1 2 3 4'; michael@0: eq(actual, expected, "Deleting while jumping to the next mark failed."); michael@0: }); michael@0: testVim('jumpToMark_next_line_action', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 't'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ']', '\''); michael@0: helpers.assertCursorAt(0, 1); michael@0: var actual = cm.getLine(0); michael@0: var expected = ' (a) [b] {c} ' michael@0: eq(actual, expected, "Deleting while jumping to the next mark line failed."); michael@0: }); michael@0: testVim('jumpToMark_prev', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 't'); michael@0: cm.setCursor(4, 0); michael@0: helpers.doKeys('[', '`'); michael@0: helpers.assertCursorAt(2, 2); michael@0: cm.setCursor(4, 0); michael@0: helpers.doKeys('[', '\''); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_prev_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(5, 0); michael@0: helpers.doKeys('2', '[', '`'); michael@0: helpers.assertCursorAt(3, 2); michael@0: cm.setCursor(5, 0); michael@0: helpers.doKeys('2', '[', '\''); michael@0: helpers.assertCursorAt(3, 1); michael@0: }); michael@0: testVim('jumpToMark_prev_sameline', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 4); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('[', '`'); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_prev_onlynext', function(cm, vim, helpers) { michael@0: cm.setCursor(4, 4); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 0); michael@0: helpers.doKeys('[', '`'); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_prev_nomark', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('[', '`'); michael@0: helpers.assertCursorAt(2, 2); michael@0: helpers.doKeys('[', '\''); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('jumpToMark_prev_linewise_over', function(cm, vim, helpers) { michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(3, 4); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(3, 6); michael@0: helpers.doKeys('[', '\''); michael@0: helpers.assertCursorAt(2, 0); michael@0: }); michael@0: testVim('delmark_single', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('m', 't'); michael@0: helpers.doEx('delmarks t'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 't'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }); michael@0: testVim('delmark_range', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'd'); michael@0: cm.setCursor(5, 2); michael@0: helpers.doKeys('m', 'e'); michael@0: helpers.doEx('delmarks b-d'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 'a'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'b'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'c'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'd'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'e'); michael@0: helpers.assertCursorAt(5, 2); michael@0: }); michael@0: testVim('delmark_multi', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'd'); michael@0: cm.setCursor(5, 2); michael@0: helpers.doKeys('m', 'e'); michael@0: helpers.doEx('delmarks bcd'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 'a'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'b'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'c'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'd'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'e'); michael@0: helpers.assertCursorAt(5, 2); michael@0: }); michael@0: testVim('delmark_multi_space', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'd'); michael@0: cm.setCursor(5, 2); michael@0: helpers.doKeys('m', 'e'); michael@0: helpers.doEx('delmarks b c d'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 'a'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'b'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'c'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'd'); michael@0: helpers.assertCursorAt(1, 2); michael@0: helpers.doKeys('`', 'e'); michael@0: helpers.assertCursorAt(5, 2); michael@0: }); michael@0: testVim('delmark_all', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('m', 'a'); michael@0: cm.setCursor(2, 2); michael@0: helpers.doKeys('m', 'b'); michael@0: cm.setCursor(3, 2); michael@0: helpers.doKeys('m', 'c'); michael@0: cm.setCursor(4, 2); michael@0: helpers.doKeys('m', 'd'); michael@0: cm.setCursor(5, 2); michael@0: helpers.doKeys('m', 'e'); michael@0: helpers.doEx('delmarks a b-de'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('`', 'a'); michael@0: helpers.assertCursorAt(0, 0); michael@0: helpers.doKeys('`', 'b'); michael@0: helpers.assertCursorAt(0, 0); michael@0: helpers.doKeys('`', 'c'); michael@0: helpers.assertCursorAt(0, 0); michael@0: helpers.doKeys('`', 'd'); michael@0: helpers.assertCursorAt(0, 0); michael@0: helpers.doKeys('`', 'e'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }); michael@0: testVim('visual', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'v', 'l', 'l'); michael@0: helpers.assertCursorAt(0, 3); michael@0: eqPos(makeCursor(0, 1), cm.getCursor('anchor')); michael@0: helpers.doKeys('d'); michael@0: eq('15', cm.getValue()); michael@0: }, { value: '12345' }); michael@0: testVim('visual_line', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'V', 'l', 'j', 'j', 'd'); michael@0: eq(' 4\n 5', cm.getValue()); michael@0: }, { value: ' 1\n 2\n 3\n 4\n 5' }); michael@0: testVim('visual_marks', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'v', 'l', 'l', 'v'); michael@0: // Test visual mode marks michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('\'', '<'); michael@0: helpers.assertCursorAt(0, 1); michael@0: helpers.doKeys('\'', '>'); michael@0: helpers.assertCursorAt(0, 3); michael@0: }); michael@0: testVim('visual_join', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'V', 'l', 'j', 'j', 'J'); michael@0: eq(' 1 2 3\n 4\n 5', cm.getValue()); michael@0: }, { value: ' 1\n 2\n 3\n 4\n 5' }); michael@0: testVim('visual_blank', function(cm, vim, helpers) { michael@0: helpers.doKeys('v', 'k'); michael@0: eq(vim.visualMode, true); michael@0: }, { value: '\n' }); michael@0: testVim('reselect_visual', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'v', 'l', 'l', 'y', 'g', 'v'); michael@0: helpers.assertCursorAt(0, 3); michael@0: eqPos(makeCursor(0, 1), cm.getCursor('anchor')); michael@0: helpers.doKeys('d'); michael@0: eq('15', cm.getValue()); michael@0: }, { value: '12345' }); michael@0: testVim('reselect_visual_line', function(cm, vim, helpers) { michael@0: helpers.doKeys('l', 'V', 'l', 'j', 'j', 'V', 'g', 'v', 'd'); michael@0: eq(' 4\n 5', cm.getValue()); michael@0: }, { value: ' 1\n 2\n 3\n 4\n 5' }); michael@0: testVim('s_normal', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('s'); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('ac', cm.getValue()); michael@0: }, { value: 'abc'}); michael@0: testVim('s_visual', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('v', 's'); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('ac', cm.getValue()); michael@0: }, { value: 'abc'}); michael@0: testVim('o_visual', function(cm,vim,helpers) { michael@0: cm.setCursor(0,0); michael@0: helpers.doKeys('v','l','l','l','o'); michael@0: helpers.assertCursorAt(0,0); michael@0: helpers.doKeys('v','v','j','j','j','o'); michael@0: helpers.assertCursorAt(0,0); michael@0: helpers.doKeys('o'); michael@0: helpers.doKeys('l','l') michael@0: helpers.assertCursorAt(3,2); michael@0: helpers.doKeys('d'); michael@0: eq('p',cm.getValue()); michael@0: }, { value: 'abcd\nefgh\nijkl\nmnop'}); michael@0: michael@0: testVim('S_normal', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('j', 'S'); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.assertCursorAt(1, 0); michael@0: eq('aa\n\ncc', cm.getValue()); michael@0: }, { value: 'aa\nbb\ncc'}); michael@0: testVim('S_visual', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 1); michael@0: helpers.doKeys('v', 'j', 'S'); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('\ncc', cm.getValue()); michael@0: }, { value: 'aa\nbb\ncc'}); michael@0: michael@0: testVim('/ and n/N', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('match'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(0, 11); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 6); michael@0: helpers.doKeys('N'); michael@0: helpers.assertCursorAt(0, 11); michael@0: michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', '/'); michael@0: helpers.assertCursorAt(1, 6); michael@0: }, { value: 'match nope match \n nope Match' }); michael@0: testVim('/_case', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('Match'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(1, 6); michael@0: }, { value: 'match nope match \n nope Match' }); michael@0: testVim('/_2_pcre', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.setOption('pcre', true); michael@0: cm.openDialog = helpers.fakeOpenDialog('(word){2}'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(1, 9); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(2, 1); michael@0: }, { value: 'word\n another wordword\n wordwordword\n' }); michael@0: testVim('/_2_nopcre', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.setOption('pcre', false); michael@0: cm.openDialog = helpers.fakeOpenDialog('\\(word\\)\\{2}'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(1, 9); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(2, 1); michael@0: }, { value: 'word\n another wordword\n wordwordword\n' }); michael@0: testVim('/_nongreedy', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('aa'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa \n a aa'}); michael@0: testVim('?_nongreedy', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('aa'); michael@0: helpers.doKeys('?'); michael@0: helpers.assertCursorAt(1, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa \n a aa'}); michael@0: testVim('/_greedy', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('a+'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 1); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa \n a aa'}); michael@0: testVim('?_greedy', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('a+'); michael@0: helpers.doKeys('?'); michael@0: helpers.assertCursorAt(1, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 1); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa \n a aa'}); michael@0: testVim('/_greedy_0_or_more', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('a*'); michael@0: helpers.doKeys('/'); michael@0: helpers.assertCursorAt(0, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 5); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 0); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 1); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa\n aa'}); michael@0: testVim('?_greedy_0_or_more', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('a*'); michael@0: helpers.doKeys('?'); michael@0: helpers.assertCursorAt(1, 1); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(1, 0); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 5); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 3); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: 'aaa aa\n aa'}); michael@0: testVim('? and n/N', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('match'); michael@0: helpers.doKeys('?'); michael@0: helpers.assertCursorAt(1, 6); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 11); michael@0: helpers.doKeys('N'); michael@0: helpers.assertCursorAt(1, 6); michael@0: michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', '?'); michael@0: helpers.assertCursorAt(0, 11); michael@0: }, { value: 'match nope match \n nope Match' }); michael@0: testVim('*', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('*'); michael@0: helpers.assertCursorAt(0, 22); michael@0: michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('2', '*'); michael@0: helpers.assertCursorAt(1, 8); michael@0: }, { value: 'nomatch match nomatch match \nnomatch Match' }); michael@0: testVim('*_no_word', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('*'); michael@0: helpers.assertCursorAt(0, 0); michael@0: }, { value: ' \n match \n' }); michael@0: testVim('*_symbol', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('*'); michael@0: helpers.assertCursorAt(1, 0); michael@0: }, { value: ' /}\n/} match \n' }); michael@0: testVim('#', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('#'); michael@0: helpers.assertCursorAt(1, 8); michael@0: michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('2', '#'); michael@0: helpers.assertCursorAt(0, 22); michael@0: }, { value: 'nomatch match nomatch match \nnomatch Match' }); michael@0: testVim('*_seek', function(cm, vim, helpers) { michael@0: // Should skip over space and symbols. michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('*'); michael@0: helpers.assertCursorAt(0, 22); michael@0: }, { value: ' := match nomatch match \nnomatch Match' }); michael@0: testVim('#', function(cm, vim, helpers) { michael@0: // Should skip over space and symbols. michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('#'); michael@0: helpers.assertCursorAt(1, 8); michael@0: }, { value: ' := match nomatch match \nnomatch Match' }); michael@0: testVim('macro_insert', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'a', '0', 'i'); michael@0: cm.replaceRange('foo', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q', '@', 'a'); michael@0: eq('foofoo', cm.getValue()); michael@0: }, { value: ''}); michael@0: testVim('macro_space', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('', ''); michael@0: helpers.assertCursorAt(0, 2); michael@0: helpers.doKeys('q', 'a', '', '', 'q'); michael@0: helpers.assertCursorAt(0, 4); michael@0: helpers.doKeys('@', 'a'); michael@0: helpers.assertCursorAt(0, 6); michael@0: helpers.doKeys('@', 'a'); michael@0: helpers.assertCursorAt(0, 8); michael@0: }, { value: 'one line of text.'}); michael@0: testVim('macro_parens', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'z', 'i'); michael@0: cm.replaceRange('(', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('e', 'a'); michael@0: cm.replaceRange(')', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q'); michael@0: helpers.doKeys('w', '@', 'z'); michael@0: helpers.doKeys('w', '@', 'z'); michael@0: eq('(see) (spot) (run)', cm.getValue()); michael@0: }, { value: 'see spot run'}); michael@0: testVim('macro_overwrite', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'z', '0', 'i'); michael@0: cm.replaceRange('I ', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q'); michael@0: helpers.doKeys('e'); michael@0: // Now replace the macro with something else. michael@0: helpers.doKeys('q', 'z', 'a'); michael@0: cm.replaceRange('.', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q'); michael@0: helpers.doKeys('e', '@', 'z'); michael@0: helpers.doKeys('e', '@', 'z'); michael@0: eq('I see. spot. run.', cm.getValue()); michael@0: }, { value: 'see spot run'}); michael@0: testVim('macro_search_f', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'a', 'f', ' '); michael@0: helpers.assertCursorAt(0,3); michael@0: helpers.doKeys('q', '0'); michael@0: helpers.assertCursorAt(0,0); michael@0: helpers.doKeys('@', 'a'); michael@0: helpers.assertCursorAt(0,3); michael@0: }, { value: 'The quick brown fox jumped over the lazy dog.'}); michael@0: testVim('macro_search_2f', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'a', '2', 'f', ' '); michael@0: helpers.assertCursorAt(0,9); michael@0: helpers.doKeys('q', '0'); michael@0: helpers.assertCursorAt(0,0); michael@0: helpers.doKeys('@', 'a'); michael@0: helpers.assertCursorAt(0,9); michael@0: }, { value: 'The quick brown fox jumped over the lazy dog.'}); michael@0: testVim('yank_register', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('"', 'a', 'y', 'y'); michael@0: helpers.doKeys('j', '"', 'b', 'y', 'y'); michael@0: cm.openDialog = helpers.fakeOpenDialog('registers'); michael@0: cm.openNotification = helpers.fakeOpenNotification(function(text) { michael@0: is(/a\s+foo/.test(text)); michael@0: is(/b\s+bar/.test(text)); michael@0: }); michael@0: helpers.doKeys(':'); michael@0: }, { value: 'foo\nbar'}); michael@0: testVim('macro_register', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('q', 'a', 'i'); michael@0: cm.replaceRange('gangnam', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q'); michael@0: helpers.doKeys('q', 'b', 'o'); michael@0: cm.replaceRange('style', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('q'); michael@0: cm.openDialog = helpers.fakeOpenDialog('registers'); michael@0: cm.openNotification = helpers.fakeOpenNotification(function(text) { michael@0: is(/a\s+i/.test(text)); michael@0: is(/b\s+o/.test(text)); michael@0: }); michael@0: helpers.doKeys(':'); michael@0: }, { value: ''}); michael@0: testVim('.', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', 'd', 'w'); michael@0: helpers.doKeys('.'); michael@0: eq('5 6', cm.getValue()); michael@0: }, { value: '1 2 3 4 5 6'}); michael@0: testVim('._repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('2', 'd', 'w'); michael@0: helpers.doKeys('3', '.'); michael@0: eq('6', cm.getValue()); michael@0: }, { value: '1 2 3 4 5 6'}); michael@0: testVim('._insert', function(cm, vim, helpers) { michael@0: helpers.doKeys('i'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('.'); michael@0: eq('testestt', cm.getValue()); michael@0: helpers.assertCursorAt(0, 6); michael@0: }, { value: ''}); michael@0: testVim('._insert_repeat', function(cm, vim, helpers) { michael@0: helpers.doKeys('i'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: cm.setCursor(0, 4); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('2', '.'); michael@0: eq('testesttestt', cm.getValue()); michael@0: helpers.assertCursorAt(0, 10); michael@0: }, { value: ''}); michael@0: testVim('._repeat_insert', function(cm, vim, helpers) { michael@0: helpers.doKeys('3', 'i'); michael@0: cm.replaceRange('te', cm.getCursor()); michael@0: cm.setCursor(0, 2); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('.'); michael@0: eq('tetettetetee', cm.getValue()); michael@0: helpers.assertCursorAt(0, 10); michael@0: }, { value: ''}); michael@0: testVim('._insert_o', function(cm, vim, helpers) { michael@0: helpers.doKeys('o'); michael@0: cm.replaceRange('z', cm.getCursor()); michael@0: cm.setCursor(1, 1); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: helpers.doKeys('.'); michael@0: eq('\nz\nz', cm.getValue()); michael@0: helpers.assertCursorAt(2, 0); michael@0: }, { value: ''}); michael@0: testVim('._insert_o_repeat', function(cm, vim, helpers) { michael@0: helpers.doKeys('o'); michael@0: cm.replaceRange('z', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: cm.setCursor(1, 0); michael@0: helpers.doKeys('2', '.'); michael@0: eq('\nz\nz\nz', cm.getValue()); michael@0: helpers.assertCursorAt(3, 0); michael@0: }, { value: ''}); michael@0: testVim('._insert_o_indent', function(cm, vim, helpers) { michael@0: helpers.doKeys('o'); michael@0: cm.replaceRange('z', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: cm.setCursor(1, 2); michael@0: helpers.doKeys('.'); michael@0: eq('{\n z\n z', cm.getValue()); michael@0: helpers.assertCursorAt(2, 2); michael@0: }, { value: '{'}); michael@0: testVim('._insert_cw', function(cm, vim, helpers) { michael@0: helpers.doKeys('c', 'w'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('2', 'l'); michael@0: helpers.doKeys('.'); michael@0: eq('test test word3', cm.getValue()); michael@0: helpers.assertCursorAt(0, 8); michael@0: }, { value: 'word1 word2 word3' }); michael@0: testVim('._insert_cw_repeat', function(cm, vim, helpers) { michael@0: // For some reason, repeat cw in desktop VIM will does not repeat insert mode michael@0: // changes. Will conform to that behavior. michael@0: helpers.doKeys('c', 'w'); michael@0: cm.replaceRange('test', cm.getCursor()); michael@0: helpers.doInsertModeKeys('Esc'); michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('l'); michael@0: helpers.doKeys('2', '.'); michael@0: eq('test test', cm.getValue()); michael@0: helpers.assertCursorAt(0, 8); michael@0: }, { value: 'word1 word2 word3' }); michael@0: testVim('._delete', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 5); michael@0: helpers.doKeys('i'); michael@0: helpers.doInsertModeKeys('Backspace', 'Esc'); michael@0: helpers.doKeys('.'); michael@0: eq('zace', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: 'zabcde'}); michael@0: testVim('._delete_repeat', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 6); michael@0: helpers.doKeys('i'); michael@0: helpers.doInsertModeKeys('Backspace', 'Esc'); michael@0: helpers.doKeys('2', '.'); michael@0: eq('zzce', cm.getValue()); michael@0: helpers.assertCursorAt(0, 1); michael@0: }, { value: 'zzabcde'}); michael@0: testVim('f;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('f', 'x'); michael@0: helpers.doKeys(';'); michael@0: helpers.doKeys('2', ';'); michael@0: eq(9, cm.getCursor().ch); michael@0: }, { value: '01x3xx678x'}); michael@0: testVim('F;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 8); michael@0: helpers.doKeys('F', 'x'); michael@0: helpers.doKeys(';'); michael@0: helpers.doKeys('2', ';'); michael@0: eq(2, cm.getCursor().ch); michael@0: }, { value: '01x3xx6x8x'}); michael@0: testVim('t;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('t', 'x'); michael@0: helpers.doKeys(';'); michael@0: helpers.doKeys('2', ';'); michael@0: eq(8, cm.getCursor().ch); michael@0: }, { value: '01x3xx678x'}); michael@0: testVim('T;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('T', 'x'); michael@0: helpers.doKeys(';'); michael@0: helpers.doKeys('2', ';'); michael@0: eq(2, cm.getCursor().ch); michael@0: }, { value: '0xx3xx678x'}); michael@0: testVim('f,', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 6); michael@0: helpers.doKeys('f', 'x'); michael@0: helpers.doKeys(','); michael@0: helpers.doKeys('2', ','); michael@0: eq(2, cm.getCursor().ch); michael@0: }, { value: '01x3xx678x'}); michael@0: testVim('F,', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 3); michael@0: helpers.doKeys('F', 'x'); michael@0: helpers.doKeys(','); michael@0: helpers.doKeys('2', ','); michael@0: eq(9, cm.getCursor().ch); michael@0: }, { value: '01x3xx678x'}); michael@0: testVim('t,', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 6); michael@0: helpers.doKeys('t', 'x'); michael@0: helpers.doKeys(','); michael@0: helpers.doKeys('2', ','); michael@0: eq(3, cm.getCursor().ch); michael@0: }, { value: '01x3xx678x'}); michael@0: testVim('T,', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 4); michael@0: helpers.doKeys('T', 'x'); michael@0: helpers.doKeys(','); michael@0: helpers.doKeys('2', ','); michael@0: eq(8, cm.getCursor().ch); michael@0: }, { value: '01x3xx67xx'}); michael@0: testVim('fd,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('f', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ';'); michael@0: eq('56789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('d', ','); michael@0: eq('01239', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Fd,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('F', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('d', ';'); michael@0: eq('01239', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ','); michael@0: eq('56789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('td,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('t', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ';'); michael@0: eq('456789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('d', ','); michael@0: eq('012349', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Td,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('T', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('d', ';'); michael@0: eq('012349', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('d', ','); michael@0: eq('456789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('fc,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('f', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('c', ';', 'Esc'); michael@0: eq('56789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('c', ','); michael@0: eq('01239', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Fc,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('F', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('c', ';', 'Esc'); michael@0: eq('01239', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('c', ','); michael@0: eq('56789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('tc,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('t', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('c', ';', 'Esc'); michael@0: eq('456789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('c', ','); michael@0: eq('012349', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Tc,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('T', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('c', ';', 'Esc'); michael@0: eq('012349', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('c', ','); michael@0: eq('456789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('fy,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('f', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('y', ';', 'P'); michael@0: eq('012340123456789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('y', ',', 'P'); michael@0: eq('012345678456789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Fy,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('F', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('y', ';', 'p'); michael@0: eq('012345678945678', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('y', ',', 'P'); michael@0: eq('012340123456789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('ty,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('t', '4'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('y', ';', 'P'); michael@0: eq('01230123456789', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('y', ',', 'p'); michael@0: eq('01234567895678', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('Ty,;', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('T', '4'); michael@0: cm.setCursor(0, 9); michael@0: helpers.doKeys('y', ';', 'p'); michael@0: eq('01234567895678', cm.getValue()); michael@0: helpers.doKeys('u'); michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys('y', ',', 'P'); michael@0: eq('01230123456789', cm.getValue()); michael@0: }, { value: '0123456789'}); michael@0: testVim('HML', function(cm, vim, helpers) { michael@0: var lines = 35; michael@0: var textHeight = cm.defaultTextHeight(); michael@0: cm.setSize(600, lines*textHeight); michael@0: cm.setCursor(120, 0); michael@0: helpers.doKeys('H'); michael@0: helpers.assertCursorAt(86, 2); michael@0: helpers.doKeys('L'); michael@0: helpers.assertCursorAt(120, 4); michael@0: helpers.doKeys('M'); michael@0: helpers.assertCursorAt(103,4); michael@0: }, { value: (function(){ michael@0: var lines = new Array(100); michael@0: var upper = ' xx\n'; michael@0: var lower = ' xx\n'; michael@0: upper = lines.join(upper); michael@0: lower = lines.join(lower); michael@0: return upper + lower; michael@0: })()}); michael@0: michael@0: var zVals = ['zb','zz','zt','z-','z.','z'].map(function(e, idx){ michael@0: var lineNum = 250; michael@0: var lines = 35; michael@0: testVim(e, function(cm, vim, helpers) { michael@0: var k1 = e[0]; michael@0: var k2 = e.substring(1); michael@0: var textHeight = cm.defaultTextHeight(); michael@0: cm.setSize(600, lines*textHeight); michael@0: cm.setCursor(lineNum, 0); michael@0: helpers.doKeys(k1, k2); michael@0: zVals[idx] = cm.getScrollInfo().top; michael@0: }, { value: (function(){ michael@0: return new Array(500).join('\n'); michael@0: })()}); michael@0: }); michael@0: testVim('zb', function(cm, vim, helpers){ michael@0: eq(zVals[2], zVals[5]); michael@0: }); michael@0: michael@0: var moveTillCharacterSandbox = michael@0: 'The quick brown fox \n' michael@0: 'jumped over the lazy dog.' michael@0: testVim('moveTillCharacter', function(cm, vim, helpers){ michael@0: cm.setCursor(0, 0); michael@0: // Search for the 'q'. michael@0: cm.openDialog = helpers.fakeOpenDialog('q'); michael@0: helpers.doKeys('/'); michael@0: eq(4, cm.getCursor().ch); michael@0: // Jump to just before the first o in the list. michael@0: helpers.doKeys('t'); michael@0: helpers.doKeys('o'); michael@0: eq('The quick brown fox \n', cm.getValue()); michael@0: // Delete that one character. michael@0: helpers.doKeys('d'); michael@0: helpers.doKeys('t'); michael@0: helpers.doKeys('o'); michael@0: eq('The quick bown fox \n', cm.getValue()); michael@0: // Delete everything until the next 'o'. michael@0: helpers.doKeys('.'); michael@0: eq('The quick box \n', cm.getValue()); michael@0: // An unmatched character should have no effect. michael@0: helpers.doKeys('d'); michael@0: helpers.doKeys('t'); michael@0: helpers.doKeys('q'); michael@0: eq('The quick box \n', cm.getValue()); michael@0: // Matches should only be possible on single lines. michael@0: helpers.doKeys('d'); michael@0: helpers.doKeys('t'); michael@0: helpers.doKeys('z'); michael@0: eq('The quick box \n', cm.getValue()); michael@0: // After all that, the search for 'q' should still be active, so the 'N' command michael@0: // can run it again in reverse. Use that to delete everything back to the 'q'. michael@0: helpers.doKeys('d'); michael@0: helpers.doKeys('N'); michael@0: eq('The ox \n', cm.getValue()); michael@0: eq(4, cm.getCursor().ch); michael@0: }, { value: moveTillCharacterSandbox}); michael@0: testVim('searchForPipe', function(cm, vim, helpers){ michael@0: CodeMirror.Vim.setOption('pcre', false); michael@0: cm.setCursor(0, 0); michael@0: // Search for the '|'. michael@0: cm.openDialog = helpers.fakeOpenDialog('|'); michael@0: helpers.doKeys('/'); michael@0: eq(4, cm.getCursor().ch); michael@0: }, { value: 'this|that'}); michael@0: michael@0: michael@0: var scrollMotionSandbox = michael@0: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' michael@0: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' michael@0: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' michael@0: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'; michael@0: testVim('scrollMotion', function(cm, vim, helpers){ michael@0: var prevCursor, prevScrollInfo; michael@0: cm.setCursor(0, 0); michael@0: // ctrl-y at the top of the file should have no effect. michael@0: helpers.doKeys(''); michael@0: eq(0, cm.getCursor().line); michael@0: prevScrollInfo = cm.getScrollInfo(); michael@0: helpers.doKeys(''); michael@0: eq(1, cm.getCursor().line); michael@0: is(prevScrollInfo.top < cm.getScrollInfo().top); michael@0: // Jump to the end of the sandbox. michael@0: cm.setCursor(1000, 0); michael@0: prevCursor = cm.getCursor(); michael@0: // ctrl-e at the bottom of the file should have no effect. michael@0: helpers.doKeys(''); michael@0: eq(prevCursor.line, cm.getCursor().line); michael@0: prevScrollInfo = cm.getScrollInfo(); michael@0: helpers.doKeys(''); michael@0: eq(prevCursor.line - 1, cm.getCursor().line); michael@0: is(prevScrollInfo.top > cm.getScrollInfo().top); michael@0: }, { value: scrollMotionSandbox}); michael@0: michael@0: var squareBracketMotionSandbox = ''+ michael@0: '({\n'+//0 michael@0: ' ({\n'+//11 michael@0: ' /*comment {\n'+//2 michael@0: ' */(\n'+//3 michael@0: '#else \n'+//4 michael@0: ' /* )\n'+//5 michael@0: '#if }\n'+//6 michael@0: ' )}*/\n'+//7 michael@0: ')}\n'+//8 michael@0: '{}\n'+//9 michael@0: '#else {{\n'+//10 michael@0: '{}\n'+//11 michael@0: '}\n'+//12 michael@0: '{\n'+//13 michael@0: '#endif\n'+//14 michael@0: '}\n'+//15 michael@0: '}\n'+//16 michael@0: '#else';//17 michael@0: testVim('[[, ]]', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(']', ']'); michael@0: helpers.assertCursorAt(9,0); michael@0: helpers.doKeys('2', ']', ']'); michael@0: helpers.assertCursorAt(13,0); michael@0: helpers.doKeys(']', ']'); michael@0: helpers.assertCursorAt(17,0); michael@0: helpers.doKeys('[', '['); michael@0: helpers.assertCursorAt(13,0); michael@0: helpers.doKeys('2', '[', '['); michael@0: helpers.assertCursorAt(9,0); michael@0: helpers.doKeys('[', '['); michael@0: helpers.assertCursorAt(0,0); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[], ][', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doKeys(']', '['); michael@0: helpers.assertCursorAt(12,0); michael@0: helpers.doKeys('2', ']', '['); michael@0: helpers.assertCursorAt(16,0); michael@0: helpers.doKeys(']', '['); michael@0: helpers.assertCursorAt(17,0); michael@0: helpers.doKeys('[', ']'); michael@0: helpers.assertCursorAt(16,0); michael@0: helpers.doKeys('2', '[', ']'); michael@0: helpers.assertCursorAt(12,0); michael@0: helpers.doKeys('[', ']'); michael@0: helpers.assertCursorAt(0,0); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[{, ]}', function(cm, vim, helpers) { michael@0: cm.setCursor(4, 10); michael@0: helpers.doKeys('[', '{'); michael@0: helpers.assertCursorAt(2,12); michael@0: helpers.doKeys('2', '[', '{'); michael@0: helpers.assertCursorAt(0,1); michael@0: cm.setCursor(4, 10); michael@0: helpers.doKeys(']', '}'); michael@0: helpers.assertCursorAt(6,11); michael@0: helpers.doKeys('2', ']', '}'); michael@0: helpers.assertCursorAt(8,1); michael@0: cm.setCursor(0,1); michael@0: helpers.doKeys(']', '}'); michael@0: helpers.assertCursorAt(8,1); michael@0: helpers.doKeys('[', '{'); michael@0: helpers.assertCursorAt(0,1); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[(, ])', function(cm, vim, helpers) { michael@0: cm.setCursor(4, 10); michael@0: helpers.doKeys('[', '('); michael@0: helpers.assertCursorAt(3,14); michael@0: helpers.doKeys('2', '[', '('); michael@0: helpers.assertCursorAt(0,0); michael@0: cm.setCursor(4, 10); michael@0: helpers.doKeys(']', ')'); michael@0: helpers.assertCursorAt(5,11); michael@0: helpers.doKeys('2', ']', ')'); michael@0: helpers.assertCursorAt(8,0); michael@0: helpers.doKeys('[', '('); michael@0: helpers.assertCursorAt(0,0); michael@0: helpers.doKeys(']', ')'); michael@0: helpers.assertCursorAt(8,0); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[*, ]*, [/, ]/', function(cm, vim, helpers) { michael@0: forEach(['*', '/'], function(key){ michael@0: cm.setCursor(7, 0); michael@0: helpers.doKeys('2', '[', key); michael@0: helpers.assertCursorAt(2,2); michael@0: helpers.doKeys('2', ']', key); michael@0: helpers.assertCursorAt(7,5); michael@0: }); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[#, ]#', function(cm, vim, helpers) { michael@0: cm.setCursor(10, 3); michael@0: helpers.doKeys('2', '[', '#'); michael@0: helpers.assertCursorAt(4,0); michael@0: helpers.doKeys('5', ']', '#'); michael@0: helpers.assertCursorAt(17,0); michael@0: cm.setCursor(10, 3); michael@0: helpers.doKeys(']', '#'); michael@0: helpers.assertCursorAt(14,0); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: testVim('[m, ]m, [M, ]M', function(cm, vim, helpers) { michael@0: cm.setCursor(11, 0); michael@0: helpers.doKeys('[', 'm'); michael@0: helpers.assertCursorAt(10,7); michael@0: helpers.doKeys('4', '[', 'm'); michael@0: helpers.assertCursorAt(1,3); michael@0: helpers.doKeys('5', ']', 'm'); michael@0: helpers.assertCursorAt(11,0); michael@0: helpers.doKeys('[', 'M'); michael@0: helpers.assertCursorAt(9,1); michael@0: helpers.doKeys('3', ']', 'M'); michael@0: helpers.assertCursorAt(15,0); michael@0: helpers.doKeys('5', '[', 'M'); michael@0: helpers.assertCursorAt(7,3); michael@0: }, { value: squareBracketMotionSandbox}); michael@0: michael@0: // Ex mode tests michael@0: testVim('ex_go_to_line', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 0); michael@0: helpers.doEx('4'); michael@0: helpers.assertCursorAt(3, 0); michael@0: }, { value: 'a\nb\nc\nd\ne\n'}); michael@0: testVim('ex_write', function(cm, vim, helpers) { michael@0: var tmp = CodeMirror.commands.save; michael@0: var written; michael@0: var actualCm; michael@0: CodeMirror.commands.save = function(cm) { michael@0: written = true; michael@0: actualCm = cm; michael@0: }; michael@0: // Test that w, wr, wri ... write all trigger :write. michael@0: var command = 'write'; michael@0: for (var i = 1; i < command.length; i++) { michael@0: written = false; michael@0: actualCm = null; michael@0: helpers.doEx(command.substring(0, i)); michael@0: eq(written, true); michael@0: eq(actualCm, cm); michael@0: } michael@0: CodeMirror.commands.save = tmp; michael@0: }); michael@0: testVim('ex_sort', function(cm, vim, helpers) { michael@0: helpers.doEx('sort'); michael@0: eq('Z\na\nb\nc\nd', cm.getValue()); michael@0: }, { value: 'b\nZ\nd\nc\na'}); michael@0: testVim('ex_sort_reverse', function(cm, vim, helpers) { michael@0: helpers.doEx('sort!'); michael@0: eq('d\nc\nb\na', cm.getValue()); michael@0: }, { value: 'b\nd\nc\na'}); michael@0: testVim('ex_sort_range', function(cm, vim, helpers) { michael@0: helpers.doEx('2,3sort'); michael@0: eq('b\nc\nd\na', cm.getValue()); michael@0: }, { value: 'b\nd\nc\na'}); michael@0: testVim('ex_sort_oneline', function(cm, vim, helpers) { michael@0: helpers.doEx('2sort'); michael@0: // Expect no change. michael@0: eq('b\nd\nc\na', cm.getValue()); michael@0: }, { value: 'b\nd\nc\na'}); michael@0: testVim('ex_sort_ignoreCase', function(cm, vim, helpers) { michael@0: helpers.doEx('sort i'); michael@0: eq('a\nb\nc\nd\nZ', cm.getValue()); michael@0: }, { value: 'b\nZ\nd\nc\na'}); michael@0: testVim('ex_sort_unique', function(cm, vim, helpers) { michael@0: helpers.doEx('sort u'); michael@0: eq('Z\na\nb\nc\nd', cm.getValue()); michael@0: }, { value: 'b\nZ\na\na\nd\na\nc\na'}); michael@0: testVim('ex_sort_decimal', function(cm, vim, helpers) { michael@0: helpers.doEx('sort d'); michael@0: eq('d3\n s5\n6\n.9', cm.getValue()); michael@0: }, { value: '6\nd3\n s5\n.9'}); michael@0: testVim('ex_sort_decimal_negative', function(cm, vim, helpers) { michael@0: helpers.doEx('sort d'); michael@0: eq('z-9\nd3\n s5\n6\n.9', cm.getValue()); michael@0: }, { value: '6\nd3\n s5\n.9\nz-9'}); michael@0: testVim('ex_sort_decimal_reverse', function(cm, vim, helpers) { michael@0: helpers.doEx('sort! d'); michael@0: eq('.9\n6\n s5\nd3', cm.getValue()); michael@0: }, { value: '6\nd3\n s5\n.9'}); michael@0: testVim('ex_sort_hex', function(cm, vim, helpers) { michael@0: helpers.doEx('sort x'); michael@0: eq(' s5\n6\n.9\n&0xB\nd3', cm.getValue()); michael@0: }, { value: '6\nd3\n s5\n&0xB\n.9'}); michael@0: testVim('ex_sort_octal', function(cm, vim, helpers) { michael@0: helpers.doEx('sort o'); michael@0: eq('.8\n.9\nd3\n s5\n6', cm.getValue()); michael@0: }, { value: '6\nd3\n s5\n.9\n.8'}); michael@0: testVim('ex_sort_decimal_mixed', function(cm, vim, helpers) { michael@0: helpers.doEx('sort d'); michael@0: eq('y\nz\nc1\nb2\na3', cm.getValue()); michael@0: }, { value: 'a3\nz\nc1\ny\nb2'}); michael@0: testVim('ex_sort_decimal_mixed_reverse', function(cm, vim, helpers) { michael@0: helpers.doEx('sort! d'); michael@0: eq('a3\nb2\nc1\nz\ny', cm.getValue()); michael@0: }, { value: 'a3\nz\nc1\ny\nb2'}); michael@0: michael@0: // Basic substitute tests. michael@0: testVim('ex_substitute_same_line', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: helpers.doEx('s/one/two'); michael@0: eq('one one\n two two', cm.getValue()); michael@0: }, { value: 'one one\n one one'}); michael@0: testVim('ex_substitute_global', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: helpers.doEx('%s/one/two'); michael@0: eq('two two\n two two', cm.getValue()); michael@0: }, { value: 'one one\n one one'}); michael@0: testVim('ex_substitute_input_range', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: helpers.doEx('1,3s/\\d/0'); michael@0: eq('0\n0\n0\n4', cm.getValue()); michael@0: }, { value: '1\n2\n3\n4' }); michael@0: testVim('ex_substitute_visual_range', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: // Set last visual mode selection marks '< and '> at lines 2 and 4 michael@0: helpers.doKeys('V', '2', 'j', 'v'); michael@0: helpers.doEx('\'<,\'>s/\\d/0'); michael@0: eq('1\n0\n0\n0\n5', cm.getValue()); michael@0: }, { value: '1\n2\n3\n4\n5' }); michael@0: testVim('ex_substitute_empty_query', function(cm, vim, helpers) { michael@0: // If the query is empty, use last query. michael@0: cm.setCursor(1, 0); michael@0: cm.openDialog = helpers.fakeOpenDialog('1'); michael@0: helpers.doKeys('/'); michael@0: helpers.doEx('s//b'); michael@0: eq('abb ab2 ab3', cm.getValue()); michael@0: }, { value: 'a11 a12 a13' }); michael@0: testVim('ex_substitute_javascript', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.setOption('pcre', false); michael@0: cm.setCursor(1, 0); michael@0: // Throw all the things that javascript likes to treat as special values michael@0: // into the replace part. All should be literal (this is VIM). michael@0: helpers.doEx('s/\\(\\d+\\)/$$ $\' $` $& \\1/') michael@0: eq('a $$ $\' $` $& 0 b', cm.getValue()); michael@0: }, { value: 'a 0 b' }); michael@0: michael@0: // More complex substitute tests that test both pcre and nopcre options. michael@0: function testSubstitute(name, options) { michael@0: testVim(name + '_pcre', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: CodeMirror.Vim.setOption('pcre', true); michael@0: helpers.doEx(options.expr); michael@0: eq(options.expectedValue, cm.getValue()); michael@0: }, options); michael@0: // If no noPcreExpr is defined, assume that it's the same as the expr. michael@0: var noPcreExpr = options.noPcreExpr ? options.noPcreExpr : options.expr; michael@0: testVim(name + '_nopcre', function(cm, vim, helpers) { michael@0: cm.setCursor(1, 0); michael@0: CodeMirror.Vim.setOption('pcre', false); michael@0: helpers.doEx(noPcreExpr); michael@0: eq(options.expectedValue, cm.getValue()); michael@0: }, options); michael@0: } michael@0: testSubstitute('ex_substitute_capture', { michael@0: value: 'a11 a12 a13', michael@0: expectedValue: 'a1111 a1212 a1313', michael@0: // $n is a backreference michael@0: expr: 's/(\\d+)/$1$1/', michael@0: // \n is a backreference. michael@0: noPcreExpr: 's/\\(\\d+\\)/\\1\\1/'}); michael@0: testSubstitute('ex_substitute_capture2', { michael@0: value: 'a 0 b', michael@0: expectedValue: 'a $00 b', michael@0: expr: 's/(\\d+)/$$$1$1/', michael@0: noPcreExpr: 's/\\(\\d+\\)/$\\1\\1/'}); michael@0: testSubstitute('ex_substitute_nocapture', { michael@0: value: 'a11 a12 a13', michael@0: expectedValue: 'a$1$1 a$1$1 a$1$1', michael@0: expr: 's/(\\d+)/$$1$$1', michael@0: noPcreExpr: 's/\\(\\d+\\)/$1$1/'}); michael@0: testSubstitute('ex_substitute_nocapture2', { michael@0: value: 'a 0 b', michael@0: expectedValue: 'a $10 b', michael@0: expr: 's/(\\d+)/$$1$1', michael@0: noPcreExpr: 's/\\(\\d+\\)/\\$1\\1/'}); michael@0: testSubstitute('ex_substitute_nocapture', { michael@0: value: 'a b c', michael@0: expectedValue: 'a $ c', michael@0: expr: 's/b/$$/', michael@0: noPcreExpr: 's/b/$/'}); michael@0: testSubstitute('ex_substitute_slash_regex', { michael@0: value: 'one/two \n three/four', michael@0: expectedValue: 'one|two \n three|four', michael@0: expr: '%s/\\//|'}); michael@0: testSubstitute('ex_substitute_pipe_regex', { michael@0: value: 'one|two \n three|four', michael@0: expectedValue: 'one,two \n three,four', michael@0: expr: '%s/\\|/,/', michael@0: noPcreExpr: '%s/|/,/'}); michael@0: testSubstitute('ex_substitute_or_regex', { michael@0: value: 'one|two \n three|four', michael@0: expectedValue: 'ana|twa \n thraa|faar', michael@0: expr: '%s/o|e|u/a', michael@0: noPcreExpr: '%s/o\\|e\\|u/a'}); michael@0: testSubstitute('ex_substitute_or_word_regex', { michael@0: value: 'one|two \n three|four', michael@0: expectedValue: 'five|five \n three|four', michael@0: expr: '%s/(one|two)/five/', michael@0: noPcreExpr: '%s/\\(one\\|two\\)/five'}); michael@0: testSubstitute('ex_substitute_backslashslash_regex', { michael@0: value: 'one\\two \n three\\four', michael@0: expectedValue: 'one,two \n three,four', michael@0: expr: '%s/\\\\/,'}); michael@0: testSubstitute('ex_substitute_slash_replacement', { michael@0: value: 'one,two \n three,four', michael@0: expectedValue: 'one/two \n three/four', michael@0: expr: '%s/,/\\/'}); michael@0: testSubstitute('ex_substitute_backslash_replacement', { michael@0: value: 'one,two \n three,four', michael@0: expectedValue: 'one\\two \n three\\four', michael@0: expr: '%s/,/\\\\/g'}); michael@0: testSubstitute('ex_substitute_multibackslash_replacement', { michael@0: value: 'one,two \n three,four', michael@0: expectedValue: 'one\\\\\\\\two \n three\\\\\\\\four', // 2*8 backslashes. michael@0: expr: '%s/,/\\\\\\\\\\\\\\\\/g'}); // 16 backslashes. michael@0: testSubstitute('ex_substitute_braces_word', { michael@0: value: 'ababab abb ab{2}', michael@0: expectedValue: 'ab abb ab{2}', michael@0: expr: '%s/(ab){2}//g', michael@0: noPcreExpr: '%s/\\(ab\\)\\{2\\}//g'}); michael@0: testSubstitute('ex_substitute_braces_range', { michael@0: value: 'a aa aaa aaaa', michael@0: expectedValue: 'a a', michael@0: expr: '%s/a{2,3}//g', michael@0: noPcreExpr: '%s/a\\{2,3\\}//g'}); michael@0: testSubstitute('ex_substitute_braces_literal', { michael@0: value: 'ababab abb ab{2}', michael@0: expectedValue: 'ababab abb ', michael@0: expr: '%s/ab\\{2\\}//g', michael@0: noPcreExpr: '%s/ab{2}//g'}); michael@0: testSubstitute('ex_substitute_braces_char', { michael@0: value: 'ababab abb ab{2}', michael@0: expectedValue: 'ababab ab{2}', michael@0: expr: '%s/ab{2}//g', michael@0: noPcreExpr: '%s/ab\\{2\\}//g'}); michael@0: testSubstitute('ex_substitute_braces_no_escape', { michael@0: value: 'ababab abb ab{2}', michael@0: expectedValue: 'ababab ab{2}', michael@0: expr: '%s/ab{2}//g', michael@0: noPcreExpr: '%s/ab\\{2}//g'}); michael@0: testSubstitute('ex_substitute_count', { michael@0: value: '1\n2\n3\n4', michael@0: expectedValue: '1\n0\n0\n4', michael@0: expr: 's/\\d/0/i 2'}); michael@0: testSubstitute('ex_substitute_count_with_range', { michael@0: value: '1\n2\n3\n4', michael@0: expectedValue: '1\n2\n0\n0', michael@0: expr: '1,3s/\\d/0/ 3'}); michael@0: function testSubstituteConfirm(name, command, initialValue, expectedValue, keys, finalPos) { michael@0: testVim(name, function(cm, vim, helpers) { michael@0: var savedOpenDialog = cm.openDialog; michael@0: var savedKeyName = CodeMirror.keyName; michael@0: var onKeyDown; michael@0: var recordedCallback; michael@0: var closed = true; // Start out closed, set false on second openDialog. michael@0: function close() { michael@0: closed = true; michael@0: } michael@0: // First openDialog should save callback. michael@0: cm.openDialog = function(template, callback, options) { michael@0: recordedCallback = callback; michael@0: } michael@0: // Do first openDialog. michael@0: helpers.doKeys(':'); michael@0: // Second openDialog should save keyDown handler. michael@0: cm.openDialog = function(template, callback, options) { michael@0: onKeyDown = options.onKeyDown; michael@0: closed = false; michael@0: }; michael@0: // Return the command to Vim and trigger second openDialog. michael@0: recordedCallback(command); michael@0: // The event should really use keyCode, but here just mock it out and use michael@0: // key and replace keyName to just return key. michael@0: CodeMirror.keyName = function (e) { return e.key; } michael@0: keys = keys.toUpperCase(); michael@0: for (var i = 0; i < keys.length; i++) { michael@0: is(!closed); michael@0: onKeyDown({ key: keys.charAt(i) }, '', close); michael@0: } michael@0: try { michael@0: eq(expectedValue, cm.getValue()); michael@0: helpers.assertCursorAt(finalPos); michael@0: is(closed); michael@0: } catch(e) { michael@0: throw e michael@0: } finally { michael@0: // Restore overriden functions. michael@0: CodeMirror.keyName = savedKeyName; michael@0: cm.openDialog = savedOpenDialog; michael@0: } michael@0: }, { value: initialValue }); michael@0: }; michael@0: testSubstituteConfirm('ex_substitute_confirm_emptydoc', michael@0: '%s/x/b/c', '', '', '', makeCursor(0, 0)); michael@0: testSubstituteConfirm('ex_substitute_confirm_nomatch', michael@0: '%s/x/b/c', 'ba a\nbab', 'ba a\nbab', '', makeCursor(0, 0)); michael@0: testSubstituteConfirm('ex_substitute_confirm_accept', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'yyy', makeCursor(1, 1)); michael@0: testSubstituteConfirm('ex_substitute_confirm_random_keys', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'ysdkywerty', makeCursor(1, 1)); michael@0: testSubstituteConfirm('ex_substitute_confirm_some', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb a\nbbb', 'yny', makeCursor(1, 1)); michael@0: testSubstituteConfirm('ex_substitute_confirm_all', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'a', makeCursor(1, 1)); michael@0: testSubstituteConfirm('ex_substitute_confirm_accept_then_all', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb b\nbbb', 'ya', makeCursor(1, 1)); michael@0: testSubstituteConfirm('ex_substitute_confirm_quit', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb a\nbab', 'yq', makeCursor(0, 3)); michael@0: testSubstituteConfirm('ex_substitute_confirm_last', michael@0: '%s/a/b/c', 'ba a\nbab', 'bb b\nbab', 'yl', makeCursor(0, 3)); michael@0: testSubstituteConfirm('ex_substitute_confirm_oneline', michael@0: '1s/a/b/c', 'ba a\nbab', 'bb b\nbab', 'yl', makeCursor(0, 3)); michael@0: testSubstituteConfirm('ex_substitute_confirm_range_accept', michael@0: '1,2s/a/b/c', 'aa\na \na\na', 'bb\nb \na\na', 'yyy', makeCursor(1, 0)); michael@0: testSubstituteConfirm('ex_substitute_confirm_range_some', michael@0: '1,3s/a/b/c', 'aa\na \na\na', 'ba\nb \nb\na', 'ynyy', makeCursor(2, 0)); michael@0: testSubstituteConfirm('ex_substitute_confirm_range_all', michael@0: '1,3s/a/b/c', 'aa\na \na\na', 'bb\nb \nb\na', 'a', makeCursor(2, 0)); michael@0: testSubstituteConfirm('ex_substitute_confirm_range_last', michael@0: '1,3s/a/b/c', 'aa\na \na\na', 'bb\nb \na\na', 'yyl', makeCursor(1, 0)); michael@0: //:noh should clear highlighting of search-results but allow to resume search through n michael@0: testVim('ex_noh_clearSearchHighlight', function(cm, vim, helpers) { michael@0: cm.openDialog = helpers.fakeOpenDialog('match'); michael@0: helpers.doKeys('?'); michael@0: helpers.doEx('noh'); michael@0: eq(vim.searchState_.getOverlay(),null,'match-highlighting wasn\'t cleared'); michael@0: helpers.doKeys('n'); michael@0: helpers.assertCursorAt(0, 11,'can\'t resume search after clearing highlighting'); michael@0: }, { value: 'match nope match \n nope Match' }); michael@0: testVim('set_boolean', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.defineOption('testoption', true, 'boolean'); michael@0: // Test default value is set. michael@0: is(CodeMirror.Vim.getOption('testoption')); michael@0: try { michael@0: // Test fail to set to non-boolean michael@0: CodeMirror.Vim.setOption('testoption', '5'); michael@0: fail(); michael@0: } catch (expected) {}; michael@0: // Test setOption michael@0: CodeMirror.Vim.setOption('testoption', false); michael@0: is(!CodeMirror.Vim.getOption('testoption')); michael@0: }); michael@0: testVim('ex_set_boolean', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.defineOption('testoption', true, 'boolean'); michael@0: // Test default value is set. michael@0: is(CodeMirror.Vim.getOption('testoption')); michael@0: try { michael@0: // Test fail to set to non-boolean michael@0: helpers.doEx('set testoption=22'); michael@0: fail(); michael@0: } catch (expected) {}; michael@0: // Test setOption michael@0: helpers.doEx('set notestoption'); michael@0: is(!CodeMirror.Vim.getOption('testoption')); michael@0: }); michael@0: testVim('set_string', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.defineOption('testoption', 'a', 'string'); michael@0: // Test default value is set. michael@0: eq('a', CodeMirror.Vim.getOption('testoption')); michael@0: try { michael@0: // Test fail to set non-string. michael@0: CodeMirror.Vim.setOption('testoption', true); michael@0: fail(); michael@0: } catch (expected) {}; michael@0: try { michael@0: // Test fail to set 'notestoption' michael@0: CodeMirror.Vim.setOption('notestoption', 'b'); michael@0: fail(); michael@0: } catch (expected) {}; michael@0: // Test setOption michael@0: CodeMirror.Vim.setOption('testoption', 'c'); michael@0: eq('c', CodeMirror.Vim.getOption('testoption')); michael@0: }); michael@0: testVim('ex_set_string', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.defineOption('testoption', 'a', 'string'); michael@0: // Test default value is set. michael@0: eq('a', CodeMirror.Vim.getOption('testoption')); michael@0: try { michael@0: // Test fail to set 'notestoption' michael@0: helpers.doEx('set notestoption=b'); michael@0: fail(); michael@0: } catch (expected) {}; michael@0: // Test setOption michael@0: helpers.doEx('set testoption=c') michael@0: eq('c', CodeMirror.Vim.getOption('testoption')); michael@0: }); michael@0: // TODO: Reset key maps after each test. michael@0: testVim('ex_map_key2key', function(cm, vim, helpers) { michael@0: helpers.doEx('map a x'); michael@0: helpers.doKeys('a'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('bc', cm.getValue()); michael@0: }, { value: 'abc' }); michael@0: testVim('ex_unmap_key2key', function(cm, vim, helpers) { michael@0: helpers.doEx('unmap a'); michael@0: helpers.doKeys('a'); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: 'abc' }); michael@0: testVim('ex_unmap_key2key_does_not_remove_default', function(cm, vim, helpers) { michael@0: try { michael@0: helpers.doEx('unmap a'); michael@0: fail(); michael@0: } catch (expected) {} michael@0: helpers.doKeys('a'); michael@0: eq('vim-insert', cm.getOption('keyMap')); michael@0: }, { value: 'abc' }); michael@0: testVim('ex_map_key2key_to_colon', function(cm, vim, helpers) { michael@0: helpers.doEx('map ; :'); michael@0: var dialogOpened = false; michael@0: cm.openDialog = function() { michael@0: dialogOpened = true; michael@0: } michael@0: helpers.doKeys(';'); michael@0: eq(dialogOpened, true); michael@0: }); michael@0: testVim('ex_map_ex2key:', function(cm, vim, helpers) { michael@0: helpers.doEx('map :del x'); michael@0: helpers.doEx('del'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('bc', cm.getValue()); michael@0: }, { value: 'abc' }); michael@0: testVim('ex_map_ex2ex', function(cm, vim, helpers) { michael@0: helpers.doEx('map :del :w'); michael@0: var tmp = CodeMirror.commands.save; michael@0: var written = false; michael@0: var actualCm; michael@0: CodeMirror.commands.save = function(cm) { michael@0: written = true; michael@0: actualCm = cm; michael@0: }; michael@0: helpers.doEx('del'); michael@0: CodeMirror.commands.save = tmp; michael@0: eq(written, true); michael@0: eq(actualCm, cm); michael@0: }); michael@0: testVim('ex_map_key2ex', function(cm, vim, helpers) { michael@0: helpers.doEx('map a :w'); michael@0: var tmp = CodeMirror.commands.save; michael@0: var written = false; michael@0: var actualCm; michael@0: CodeMirror.commands.save = function(cm) { michael@0: written = true; michael@0: actualCm = cm; michael@0: }; michael@0: helpers.doKeys('a'); michael@0: CodeMirror.commands.save = tmp; michael@0: eq(written, true); michael@0: eq(actualCm, cm); michael@0: }); michael@0: testVim('ex_map_key2key_visual_api', function(cm, vim, helpers) { michael@0: CodeMirror.Vim.map('b', ':w', 'visual'); michael@0: var tmp = CodeMirror.commands.save; michael@0: var written = false; michael@0: var actualCm; michael@0: CodeMirror.commands.save = function(cm) { michael@0: written = true; michael@0: actualCm = cm; michael@0: }; michael@0: // Mapping should not work in normal mode. michael@0: helpers.doKeys('b'); michael@0: eq(written, false); michael@0: // Mapping should work in visual mode. michael@0: helpers.doKeys('v', 'b'); michael@0: eq(written, true); michael@0: eq(actualCm, cm); michael@0: michael@0: CodeMirror.commands.save = tmp; michael@0: }); michael@0: michael@0: // Testing registration of functions as ex-commands and mapping to -keys michael@0: testVim('ex_api_test', function(cm, vim, helpers) { michael@0: var res=false; michael@0: var val='from'; michael@0: CodeMirror.Vim.defineEx('extest','ext',function(cm,params){ michael@0: if(params.args)val=params.args[0]; michael@0: else res=true; michael@0: }); michael@0: helpers.doEx(':ext to'); michael@0: eq(val,'to','Defining ex-command failed'); michael@0: CodeMirror.Vim.map('',':ext'); michael@0: helpers.doKeys('',''); michael@0: is(res,'Mapping to key failed'); michael@0: }); michael@0: // For now, this test needs to be last because it messes up : for future tests. michael@0: testVim('ex_map_key2key_from_colon', function(cm, vim, helpers) { michael@0: helpers.doEx('map : x'); michael@0: helpers.doKeys(':'); michael@0: helpers.assertCursorAt(0, 0); michael@0: eq('bc', cm.getValue()); michael@0: }, { value: 'abc' }); michael@0: michael@0: // Test event handlers michael@0: testVim('beforeSelectionChange', function(cm, vim, helpers) { michael@0: cm.setCursor(0, 100); michael@0: eqPos(cm.getCursor('head'), cm.getCursor('anchor')); michael@0: }, { value: 'abc' });