neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_input.vim (3363B)


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