append_spec.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local eq = t.eq
  5. local dedent = t.dedent
  6. local exec = n.exec
  7. local feed = n.feed
  8. local clear = n.clear
  9. local fn = n.fn
  10. local command = n.command
  11. local api = n.api
  12. local cmdtest = function(cmd, prep, ret1)
  13. describe(':' .. cmd, function()
  14. before_each(function()
  15. clear()
  16. api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' })
  17. end)
  18. local buffer_contents = function()
  19. return api.nvim_buf_get_lines(0, 0, -1, false)
  20. end
  21. it(cmd .. 's' .. prep .. ' the current line by default', function()
  22. command(cmd .. '\nabc\ndef')
  23. eq(ret1, buffer_contents())
  24. end)
  25. -- Used to crash because this invokes history processing which uses
  26. -- hist_char2type which after fdb68e35e4c729c7ed097d8ade1da29e5b3f4b31
  27. -- crashed.
  28. it(cmd .. 's' .. prep .. ' the current line by default when feeding', function()
  29. feed(':' .. cmd .. '\nabc\ndef\n.\n')
  30. eq(ret1, buffer_contents())
  31. end)
  32. -- This used to crash since that commit as well.
  33. it('opens empty cmdline window', function()
  34. local hisline = '" Some comment to be stored in history'
  35. feed(':' .. hisline .. '<CR>')
  36. feed(':' .. cmd .. '<CR>abc<CR>def<C-f>')
  37. eq({ 'def' }, buffer_contents())
  38. eq(hisline, fn.histget(':', -2))
  39. eq(cmd, fn.histget(':'))
  40. -- Test that command-line window was launched
  41. eq('nofile', api.nvim_get_option_value('buftype', {}))
  42. eq('n', fn.mode(1))
  43. feed('<CR>')
  44. eq('c', fn.mode(1))
  45. feed('.<CR>')
  46. eq('n', fn.mode(1))
  47. eq(ret1, buffer_contents())
  48. end)
  49. end)
  50. end
  51. cmdtest('insert', ' before', { 'abc', 'def', 'foo', 'bar', 'baz' })
  52. cmdtest('append', ' after', { 'foo', 'abc', 'def', 'bar', 'baz' })
  53. cmdtest('change', '', { 'abc', 'def', 'bar', 'baz' })
  54. describe('the first line is redrawn correctly after inserting text in an empty buffer', function()
  55. local screen
  56. before_each(function()
  57. clear()
  58. screen = Screen.new(20, 8)
  59. screen:set_default_attr_ids({
  60. [1] = { bold = true, foreground = Screen.colors.Blue },
  61. [2] = { bold = true, reverse = true },
  62. })
  63. end)
  64. it('using :append', function()
  65. exec(dedent([[
  66. append
  67. aaaaa
  68. bbbbb
  69. .]]))
  70. screen:expect([[
  71. aaaaa |
  72. ^bbbbb |
  73. {1:~ }|*5
  74. |
  75. ]])
  76. end)
  77. it('using :insert', function()
  78. exec(dedent([[
  79. insert
  80. aaaaa
  81. bbbbb
  82. .]]))
  83. screen:expect([[
  84. aaaaa |
  85. ^bbbbb |
  86. {1:~ }|*5
  87. |
  88. ]])
  89. end)
  90. end)