Expand Up
@@ -504,7 +504,7 @@ testVim('{', function(cm, vim, helpers) {
helpers . doKeys ( '6' , '{' ) ;
helpers . assertCursorAt ( 0 , 0 ) ;
} , { value : 'a\n\nb\nc\n\nd' } ) ;
testVim ( 'paragraph motions ' , function ( cm , vim , helpers ) {
testVim ( 'paragraph_motions ' , function ( cm , vim , helpers ) {
cm . setCursor ( 10 , 0 ) ;
helpers . doKeys ( '{' ) ;
helpers . assertCursorAt ( 4 , 0 ) ;
Expand Down
Expand Up
@@ -984,6 +984,17 @@ testVim('cc_multiply_repeat', function(cm, vim, helpers) {
is ( register . linewise ) ;
eq ( 'vim-insert' , cm . getOption ( 'keyMap' ) ) ;
} ) ;
testVim ( 'ct' , function ( cm , vim , helpers ) {
cm . setCursor ( 0 , 9 ) ;
helpers . doKeys ( 'c' , 't' , 'w' ) ;
eq ( ' word1 word3' , cm . getValue ( ) ) ;
helpers . doKeys ( '<Esc>' , 'c' , '|' ) ;
eq ( ' word3' , cm . getValue ( ) ) ;
helpers . assertCursorAt ( 0 , 0 ) ;
helpers . doKeys ( '<Esc>' , '2' , 'u' , 'w' , 'h' ) ;
helpers . doKeys ( 'c' , '2' , 'g' , 'e' ) ;
eq ( ' wordword3' , cm . getValue ( ) ) ;
} , { value : ' word1 word2 word3' } ) ;
testVim ( 'cc_should_not_append_to_document' , function ( cm , vim , helpers ) {
var expectedLineCount = cm . lineCount ( ) ;
cm . setCursor ( cm . lastLine ( ) , 0 ) ;
Expand Down
Expand Up
@@ -1884,7 +1895,11 @@ testVim('visual_block_move_to_eol', function(cm, vim, helpers) {
cm . setCursor ( 0 , 0 ) ;
helpers . doKeys ( '<C-v>' , 'G' , '$' ) ;
var selections = cm . getSelections ( ) . join ( ) ;
eq ( "123,45,6" , selections ) ;
eq ( '123,45,6' , selections ) ;
// Checks that with cursor at Infinity, finding words backwards still works.
helpers . doKeys ( '2' , 'k' , 'b' ) ;
selections = cm . getSelections ( ) . join ( ) ;
eq ( '1' , selections ) ;
} , { value : '123\n45\n6' } ) ;
testVim ( 'visual_block_different_line_lengths' , function ( cm , vim , helpers ) {
// test the block selection with lines of different length
Expand Down
Expand Up
@@ -2712,6 +2727,44 @@ testVim('exCommand_history', function(cm, vim, helpers) {
onKeyDown ( { keyCode : keyCodes . Up } , input , close ) ;
eq ( input , 'sort' ) ;
} , { value : '' } ) ;
testVim ( 'search_clear' , function ( cm , vim , helpers ) {
var onKeyDown ;
var input = '' ;
var keyCodes = {
Ctrl : 17 ,
u : 85
} ;
cm . openDialog = function ( template , callback , options ) {
onKeyDown = options . onKeyDown ;
} ;
var close = function ( newVal ) {
if ( typeof newVal == 'string' ) input = newVal ;
}
helpers . doKeys ( '/' ) ;
input = 'foo' ;
onKeyDown ( { keyCode : keyCodes . Ctrl } , input , close ) ;
onKeyDown ( { keyCode : keyCodes . u , ctrlKey : true } , input , close ) ;
eq ( input , '' ) ;
} ) ;
testVim ( 'exCommand_clear' , function ( cm , vim , helpers ) {
var onKeyDown ;
var input = '' ;
var keyCodes = {
Ctrl : 17 ,
u : 85
} ;
cm . openDialog = function ( template , callback , options ) {
onKeyDown = options . onKeyDown ;
} ;
var close = function ( newVal ) {
if ( typeof newVal == 'string' ) input = newVal ;
}
helpers . doKeys ( ':' ) ;
input = 'foo' ;
onKeyDown ( { keyCode : keyCodes . Ctrl } , input , close ) ;
onKeyDown ( { keyCode : keyCodes . u , ctrlKey : true } , input , close ) ;
eq ( input , '' ) ;
} ) ;
testVim ( '.' , function ( cm , vim , helpers ) {
cm . setCursor ( 0 , 0 ) ;
helpers . doKeys ( '2' , 'd' , 'w' ) ;
Expand Down
Expand Up
@@ -3659,17 +3712,111 @@ testVim('set_string', function(cm, vim, helpers) {
eq ( 'c' , CodeMirror . Vim . getOption ( 'testoption' ) ) ;
} ) ;
testVim ( 'ex_set_string' , function ( cm , vim , helpers ) {
CodeMirror . Vim . defineOption ( 'testoption ' , 'a' , 'string' ) ;
CodeMirror . Vim . defineOption ( 'testopt ' , 'a' , 'string' ) ;
// Test default value is set.
eq ( 'a' , CodeMirror . Vim . getOption ( 'testoption ' ) ) ;
eq ( 'a' , CodeMirror . Vim . getOption ( 'testopt ' ) ) ;
try {
// Test fail to set 'notestoption '
helpers . doEx ( 'set notestoption =b' ) ;
// Test fail to set 'notestopt '
helpers . doEx ( 'set notestopt =b' ) ;
fail ( ) ;
} catch ( expected ) { } ;
// Test setOption
helpers . doEx ( 'set testoption=c' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testoption' ) ) ;
helpers . doEx ( 'set testopt=c' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
helpers . doEx ( 'set testopt=c' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ; //local || global
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ; // local
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ; // global
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' ) ) ; // global
// Test setOption global
helpers . doEx ( 'setg testopt=d' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ;
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
// Test setOption local
helpers . doEx ( 'setl testopt=e' )
eq ( 'e' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ;
eq ( 'e' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
} ) ;
testVim ( 'ex_set_callback' , function ( cm , vim , helpers ) {
var global ;
function cb ( val , cm , cfg ) {
if ( val === undefined ) {
// Getter
if ( cm ) {
return cm . _local ;
} else {
return global ;
}
} else {
// Setter
if ( cm ) {
cm . _local = val ;
} else {
global = val ;
}
}
}
CodeMirror . Vim . defineOption ( 'testopt' , 'a' , 'string' , cb ) ;
// Test default value is set.
eq ( 'a' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
try {
// Test fail to set 'notestopt'
helpers . doEx ( 'set notestopt=b' ) ;
fail ( ) ;
} catch ( expected ) { } ;
// Test setOption (Identical to the string tests, but via callback instead)
helpers . doEx ( 'set testopt=c' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ; //local || global
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ; // local
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ; // global
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' ) ) ; // global
// Test setOption global
helpers . doEx ( 'setg testopt=d' )
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ;
eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
// Test setOption local
helpers . doEx ( 'setl testopt=e' )
eq ( 'e' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ;
eq ( 'e' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'local' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' , cm , { scope : 'global' } ) ) ;
eq ( 'd' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
} )
testVim ( 'ex_set_filetype' , function ( cm , vim , helpers ) {
CodeMirror . defineMode ( 'test_mode' , function ( ) {
return { token : function ( stream ) {
stream . match ( / ^ \s + | ^ \S + / ) ;
} } ;
} ) ;
CodeMirror . defineMode ( 'test_mode_2' , function ( ) {
return { token : function ( stream ) {
stream . match ( / ^ \s + | ^ \S + / ) ;
} } ;
} ) ;
// Test mode is set.
helpers . doEx ( 'set filetype=test_mode' ) ;
eq ( 'test_mode' , cm . getMode ( ) . name ) ;
// Test 'ft' alias also sets mode.
helpers . doEx ( 'set ft=test_mode_2' ) ;
eq ( 'test_mode_2' , cm . getMode ( ) . name ) ;
} ) ;
testVim ( 'ex_set_filetype_null' , function ( cm , vim , helpers ) {
CodeMirror . defineMode ( 'test_mode' , function ( ) {
return { token : function ( stream ) {
stream . match ( / ^ \s + | ^ \S + / ) ;
} } ;
} ) ;
cm . setOption ( 'mode' , 'test_mode' ) ;
// Test mode is set to null.
helpers . doEx ( 'set filetype=' ) ;
eq ( 'null' , cm . getMode ( ) . name ) ;
} ) ;
// TODO: Reset key maps after each test.
testVim ( 'ex_map_key2key' , function ( cm , vim , helpers ) {
Expand Down