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