2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2016-12-09 20:43:34 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local clear, feed, source = n.clear, n.feed, n.source
|
|
|
|
local command = n.command
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
2024-01-12 04:41:09 -07:00
|
|
|
local sleep = vim.uv.sleep
|
2016-12-09 20:43:34 -07:00
|
|
|
|
|
|
|
describe('CTRL-C (mapped)', function()
|
2022-04-29 22:11:35 -07:00
|
|
|
local screen
|
|
|
|
|
2016-12-09 20:43:34 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
2022-04-29 22:11:35 -07:00
|
|
|
screen = Screen.new(52, 6)
|
|
|
|
screen:attach()
|
2016-12-09 20:43:34 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('interrupts :global', function()
|
2017-01-19 06:19:59 -07:00
|
|
|
-- Crashes luajit.
|
2024-04-08 02:03:20 -07:00
|
|
|
if t.skip_fragile(pending) then
|
2017-01-03 20:10:38 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-12-09 20:43:34 -07:00
|
|
|
source([[
|
|
|
|
set nomore nohlsearch undolevels=-1
|
|
|
|
nnoremap <C-C> <NOP>
|
|
|
|
]])
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('silent edit! test/functional/fixtures/bigfile.txt')
|
2016-12-09 20:43:34 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
|
|
|
^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
|
|
|
|
0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; |
|
|
|
|
0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
|
|
|
|
0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
|
|
|
|
0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
local function test_ctrl_c(ms)
|
|
|
|
feed(':global/^/p<CR>')
|
2017-04-21 01:59:06 -07:00
|
|
|
screen:sleep(ms)
|
2016-12-09 20:43:34 -07:00
|
|
|
feed('<C-C>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect { any = 'Interrupt' }
|
2016-12-09 20:43:34 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- The test is time-sensitive. Try different sleep values.
|
2017-10-28 09:01:38 -07:00
|
|
|
local ms_values = { 100, 1000, 10000 }
|
2016-12-09 20:43:34 -07:00
|
|
|
for i, ms in ipairs(ms_values) do
|
|
|
|
if i < #ms_values then
|
|
|
|
local status, _ = pcall(test_ctrl_c, ms)
|
|
|
|
if status then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
else -- Call the last attempt directly.
|
|
|
|
test_ctrl_c(ms)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2022-04-29 22:11:35 -07:00
|
|
|
|
|
|
|
it('interrupts :sleep', function()
|
|
|
|
command('nnoremap <C-C> <Nop>')
|
|
|
|
feed(':sleep 100<CR>')
|
2022-08-16 00:21:46 -07:00
|
|
|
poke_eventloop() -- wait for :sleep to start
|
2022-04-29 22:11:35 -07:00
|
|
|
feed('foo<C-C>')
|
2022-08-16 00:21:46 -07:00
|
|
|
poke_eventloop() -- wait for input buffer to be flushed
|
2022-04-29 22:11:35 -07:00
|
|
|
feed('i')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*4
|
|
|
|
{5:-- INSERT --} |
|
2022-04-29 22:11:35 -07:00
|
|
|
]])
|
|
|
|
end)
|
2022-06-06 21:41:18 -07:00
|
|
|
|
|
|
|
it('interrupts recursive mapping', function()
|
|
|
|
command('nnoremap <C-C> <Nop>')
|
|
|
|
command('nmap <F2> <Ignore><F2>')
|
|
|
|
feed('<F2>')
|
2022-08-16 00:21:46 -07:00
|
|
|
sleep(10) -- wait for the key to enter typeahead
|
2022-06-06 21:41:18 -07:00
|
|
|
feed('foo<C-C>')
|
2022-08-16 00:21:46 -07:00
|
|
|
poke_eventloop() -- wait for input buffer to be flushed
|
2022-06-06 21:41:18 -07:00
|
|
|
feed('i')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*4
|
|
|
|
{5:-- INSERT --} |
|
2022-06-06 21:41:18 -07:00
|
|
|
]])
|
|
|
|
end)
|
2016-12-09 20:43:34 -07:00
|
|
|
end)
|