test_input.vim 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. " Tests for character input and feedkeys() function.
  2. func Test_feedkeys_x_with_empty_string()
  3. new
  4. call feedkeys("ifoo\<Esc>")
  5. call assert_equal('', getline('.'))
  6. call feedkeys('', 'x')
  7. call assert_equal('foo', getline('.'))
  8. " check it goes back to normal mode immediately.
  9. call feedkeys('i', 'x')
  10. call assert_equal('foo', getline('.'))
  11. quit!
  12. endfunc
  13. func Test_feedkeys_with_abbreviation()
  14. new
  15. inoreabbrev trigger value
  16. call feedkeys("atrigger ", 'x')
  17. call feedkeys("atrigger ", 'x')
  18. call assert_equal('value value ', getline(1))
  19. bwipe!
  20. iunabbrev trigger
  21. endfunc
  22. func Test_feedkeys_escape_special()
  23. nnoremap … <Cmd>let g:got_ellipsis += 1<CR>
  24. call feedkeys('…', 't')
  25. call assert_equal('…', getcharstr())
  26. let g:got_ellipsis = 0
  27. call feedkeys('…', 'xt')
  28. call assert_equal(1, g:got_ellipsis)
  29. unlet g:got_ellipsis
  30. nunmap …
  31. endfunc
  32. func Test_input_simplify_ctrl_at()
  33. new
  34. " feeding unsimplified CTRL-@ should still trigger i_CTRL-@
  35. call feedkeys("ifoo\<Esc>A\<*C-@>x", 'xt')
  36. call assert_equal('foofo', getline(1))
  37. bw!
  38. endfunc
  39. func Test_input_simplify_noremap()
  40. call feedkeys("i\<*C-M>", 'nx')
  41. call assert_equal('', getline(1))
  42. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  43. bw!
  44. endfunc
  45. func Test_input_simplify_timedout()
  46. inoremap <C-M>a b
  47. call feedkeys("i\<*C-M>", 'xt')
  48. call assert_equal('', getline(1))
  49. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  50. iunmap <C-M>a
  51. bw!
  52. endfunc
  53. " vim: shiftwidth=2 sts=2 expandtab