mode_cmdline_spec.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. -- Cmdline-mode tests.
  2. local t = require('test.testutil')
  3. local n = require('test.functional.testnvim')()
  4. local Screen = require('test.functional.ui.screen')
  5. local clear, insert, fn, eq, feed = n.clear, n.insert, n.fn, t.eq, n.feed
  6. local eval = n.eval
  7. local command = n.command
  8. local api = n.api
  9. describe('cmdline', function()
  10. before_each(clear)
  11. describe('Ctrl-R', function()
  12. it('pasting non-special register inserts <CR> *between* lines', function()
  13. insert([[
  14. line1abc
  15. line2somemoretext
  16. ]])
  17. -- Yank 2 lines linewise, then paste to cmdline.
  18. feed([[<C-\><C-N>gg0yj:<C-R>0]])
  19. -- <CR> inserted between lines, NOT after the final line.
  20. eq('line1abc\rline2somemoretext', fn.getcmdline())
  21. -- Yank 2 lines charwise, then paste to cmdline.
  22. feed([[<C-\><C-N>gg05lyvj:<C-R>0]])
  23. -- <CR> inserted between lines, NOT after the final line.
  24. eq('abc\rline2', fn.getcmdline())
  25. -- Yank 1 line linewise, then paste to cmdline.
  26. feed([[<C-\><C-N>ggyy:<C-R>0]])
  27. -- No <CR> inserted.
  28. eq('line1abc', fn.getcmdline())
  29. end)
  30. it('pasting special register inserts <CR>, <NL>', function()
  31. feed([[:<C-R>="foo\nbar\rbaz"<CR>]])
  32. eq('foo\nbar\rbaz', fn.getcmdline())
  33. end)
  34. it('pasting handles composing chars properly', function()
  35. local screen = Screen.new(60, 4)
  36. -- 'arabicshape' cheats and always redraws everything which trivially works,
  37. -- this test is for partial redraws in 'noarabicshape' mode.
  38. command('set noarabicshape')
  39. fn.setreg('a', '💻')
  40. feed(':test 🧑‍')
  41. screen:expect([[
  42. |
  43. {1:~ }|*2
  44. :test 🧑‍^ |
  45. ]])
  46. feed('<c-r><c-r>a')
  47. screen:expect([[
  48. |
  49. {1:~ }|*2
  50. :test 🧑‍💻^ |
  51. ]])
  52. end)
  53. end)
  54. it('Ctrl-Shift-V supports entering unsimplified key notations', function()
  55. feed(':"<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><CR>')
  56. eq('"<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>', eval('@:'))
  57. end)
  58. it('redraws statusline when toggling overstrike', function()
  59. local screen = Screen.new(60, 4)
  60. command('set laststatus=2 statusline=%!mode(1)')
  61. feed(':')
  62. screen:expect {
  63. grid = [[
  64. |
  65. {1:~ }|
  66. {3:c }|
  67. :^ |
  68. ]],
  69. }
  70. feed('<Insert>')
  71. screen:expect {
  72. grid = [[
  73. |
  74. {1:~ }|
  75. {3:cr }|
  76. :^ |
  77. ]],
  78. }
  79. end)
  80. describe('history', function()
  81. it('correctly clears start of the history', function()
  82. -- Regression test: check absence of the memory leak when clearing start of
  83. -- the history using cmdhist.c/clr_history().
  84. eq(1, fn.histadd(':', 'foo'))
  85. eq(1, fn.histdel(':'))
  86. eq('', fn.histget(':', -1))
  87. end)
  88. it('correctly clears end of the history', function()
  89. -- Regression test: check absence of the memory leak when clearing end of
  90. -- the history using cmdhist.c/clr_history().
  91. api.nvim_set_option_value('history', 1, {})
  92. eq(1, fn.histadd(':', 'foo'))
  93. eq(1, fn.histdel(':'))
  94. eq('', fn.histget(':', -1))
  95. end)
  96. it('correctly removes item from history', function()
  97. -- Regression test: check that cmdhist.c/del_history_idx() correctly clears
  98. -- history index after removing history entry. If it does not then deleting
  99. -- history will result in a double free.
  100. eq(1, fn.histadd(':', 'foo'))
  101. eq(1, fn.histadd(':', 'bar'))
  102. eq(1, fn.histadd(':', 'baz'))
  103. eq(1, fn.histdel(':', -2))
  104. eq(1, fn.histdel(':'))
  105. eq('', fn.histget(':', -1))
  106. end)
  107. end)
  108. end)