ctrl_c_spec.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, feed, source = n.clear, n.feed, n.source
  5. local command = n.command
  6. local poke_eventloop = n.poke_eventloop
  7. local sleep = vim.uv.sleep
  8. describe('CTRL-C (mapped)', function()
  9. local screen
  10. before_each(function()
  11. clear()
  12. screen = Screen.new(52, 6)
  13. end)
  14. it('interrupts :global', function()
  15. -- Crashes luajit.
  16. if t.skip_fragile(pending) then
  17. return
  18. end
  19. source([[
  20. set nomore nohlsearch undolevels=-1
  21. nnoremap <C-C> <NOP>
  22. ]])
  23. command('silent edit! test/functional/fixtures/bigfile.txt')
  24. screen:expect([[
  25. ^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
  26. 0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; |
  27. 0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
  28. 0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
  29. 0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;|
  30. |
  31. ]])
  32. local function test_ctrl_c(ms)
  33. feed(':global/^/p<CR>')
  34. screen:sleep(ms)
  35. feed('<C-C>')
  36. screen:expect { any = 'Interrupt' }
  37. end
  38. -- The test is time-sensitive. Try different sleep values.
  39. local ms_values = { 100, 1000, 10000 }
  40. for i, ms in ipairs(ms_values) do
  41. if i < #ms_values then
  42. local status, _ = pcall(test_ctrl_c, ms)
  43. if status then
  44. break
  45. end
  46. else -- Call the last attempt directly.
  47. test_ctrl_c(ms)
  48. end
  49. end
  50. end)
  51. it('interrupts :sleep', function()
  52. command('nnoremap <C-C> <Nop>')
  53. feed(':sleep 100<CR>')
  54. poke_eventloop() -- wait for :sleep to start
  55. feed('foo<C-C>')
  56. poke_eventloop() -- wait for input buffer to be flushed
  57. feed('i')
  58. screen:expect([[
  59. ^ |
  60. {1:~ }|*4
  61. {5:-- INSERT --} |
  62. ]])
  63. end)
  64. it('interrupts recursive mapping', function()
  65. command('nnoremap <C-C> <Nop>')
  66. command('nmap <F2> <Ignore><F2>')
  67. feed('<F2>')
  68. sleep(10) -- wait for the key to enter typeahead
  69. feed('foo<C-C>')
  70. poke_eventloop() -- wait for input buffer to be flushed
  71. feed('i')
  72. screen:expect([[
  73. ^ |
  74. {1:~ }|*4
  75. {5:-- INSERT --} |
  76. ]])
  77. end)
  78. end)