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