robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e0b724de09
master
1" Tests for character input and feedkeys() function. 2 3func Test_feedkeys_x_with_empty_string () 4new 5call feedkeys ( "ifoo\<Esc>" ) 6call assert_equal ( '' , getline ( '.' )) 7call feedkeys ( '' , 'x' ) 8call assert_equal ( 'foo' , getline ( '.' )) 9 10" check it goes back to normal mode immediately. 11call feedkeys ( 'i' , 'x' ) 12call assert_equal ( 'foo' , getline ( '.' )) 13quit ! 14endfunc 15 16func Test_feedkeys_with_abbreviation () 17new 18inoreabbrev trigger value 19call feedkeys ( "atrigger " , 'x' ) 20call feedkeys ( "atrigger " , 'x' ) 21call assert_equal ( 'value value ' , getline ( 1 )) 22bwipe ! 23iunabbrev trigger 24endfunc 25 26func Test_feedkeys_escape_special () 27nnoremap …<Cmd> let g: got_ellipsis += 1 <CR> 28call feedkeys ( '…' , 't' ) 29call assert_equal ( '…' , getcharstr ()) 30let g: got_ellipsis = 0 31call feedkeys ( '…' , 'xt' ) 32call assert_equal ( 1 , g: got_ellipsis ) 33unlet g: got_ellipsis 34nunmap … 35endfunc 36 37func Test_input_simplify_ctrl_at () 38new 39" feeding unsimplified CTRL-@ should still trigger i_CTRL-@ 40call feedkeys ( "ifoo\<Esc>A\<*C-@>x" , 'xt' ) 41call assert_equal ( 'foofo' , getline ( 1 )) 42bw ! 43endfunc 44 45func Test_input_simplify_noremap () 46call feedkeys ( "i\<*C-M>" , 'nx' ) 47call assert_equal ( '' , getline ( 1 )) 48call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos ()) 49bw ! 50endfunc 51 52func Test_input_simplify_timedout () 53inoremap < C-M > a b 54call feedkeys ( "i\<*C-M>" , 'xt' ) 55call assert_equal ( '' , getline ( 1 )) 56call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos ()) 57iunmap <C-M>a 58bw ! 59endfunc 60 61" Check that <Ignore> and <MouseMove> are no-op in the middle of various 62" commands as they are ignored by plain_vgetc(). 63func Test_input_noop_keys () 64for key in [ "\<Ignore>" , "\<MouseMove>" ] 6520 new 66setlocal scrolloff = 0 67 68let lines = range ( 1 , 100 ) ->mapnew ({ _ , n ->$ 'line {n}'}) 69call setline ( 1 , lines ) 70let InsertNoopKeys = { s ->key .. split ( s , '\zs' ) ->join ( key ) .. key } 71 72call feedkeys ( InsertNoopKeys ( "60z\<CR>\<C-\>\<C-N>" ), 'tnix' ) 73call assert_equal ( 60 , line ( 'w0' )) 74call assert_equal ( 'line 60' , getline ( '.' )) 75 76call feedkeys ( InsertNoopKeys ( "gg20ddi\<C-V>x5F\<Esc>" ), 'tnix' ) 77call assert_equal ( 80 , line ( '$' )) 78call assert_equal ( '_line 21' , getline ( '.' )) 79 80call feedkeys ( InsertNoopKeys ( "fea\<C-K>,.\<C-\>\<C-N>" ), 'tnix' ) 81call assert_equal ( '_line… 21' , getline ( '.' )) 82 83call feedkeys ( InsertNoopKeys ( "Iabcde\<C-G>ufghij\<Esc>u" ), 'tnix' ) 84call assert_equal ( 'abcde_line… 21' , getline ( '.' )) 85call feedkeys ( "\<C-R>$2Feg~tj" , 'tnix' ) 86call assert_equal ( 'abcdEFGHIj_line… 21' , getline ( '.' )) 87 88let @g= 'FOO' 89call feedkeys ( InsertNoopKeys ( "A\<C-R>g\<C-R>\<C-O>g\<Esc>" ), 'tnix' ) 90call assert_equal ( 'abcdEFGHIj_line… 21FOOFOO' , getline ( '.' )) 91 92call feedkeys ( InsertNoopKeys ( "0v10l\<C-G>\<C-R>g?!!\<Esc>" ), 'tnix' ) 93call assert_equal ( 'abcdEFGHIj_' , @g) 94call assert_equal ( '?!!line… 21FOOFOO' , getline ( '.' )) 95 96let @g= 'BAR' 97call feedkeys ( InsertNoopKeys ( "$:\"abc\<C-R>\<C-R>\<C-W>\<CR>" ), 'tnix' ) 98call assert_equal ( '"abc21FOOFOO' , @:) 99call feedkeys ( InsertNoopKeys ( ":\<C-\>e'\"foo'\<CR>\<C-R>g\<CR>" ), 'tnix' ) 100call assert_equal ( '"fooBAR' , @:) 101 102call feedkeys ( InsertNoopKeys ( "z10\<CR>" ), 'tnix' ) 103call assert_equal ( 10 , winheight ( 0 )) 104call feedkeys ( InsertNoopKeys ( "\<C-W>10+" ), 'tnix' ) 105call assert_equal ( 20 , winheight ( 0 )) 106 107bwipe ! 108endfor 109endfunc 110 111" vim: shiftwidth=2 sts=2 expandtab