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
|
|
|
|
2024-01-02 18:09:18 -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)
|
2016-12-09 20:43:34 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
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>
|
|
|
|
]])
|
|
|
|
|
2024-01-02 18:09:18 -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)
|
2024-01-02 18:09:18 -07:00
|
|
|
feed(':global/^/p<CR>')
|
2017-04-21 01:59:06 -07:00
|
|
|
screen:sleep(ms)
|
2024-01-02 18:09:18 -07:00
|
|
|
feed('<C-C>')
|
|
|
|
screen:expect { any = 'Interrupt' }
|
2016-12-09 20:43:34 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- The test is time-sensitive. Try different sleep values.
|
2024-01-02 18:09:18 -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)
|
2024-01-02 18:09:18 -07:00
|
|
|
if status then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
else -- Call the last attempt directly.
|
2016-12-09 20:43:34 -07:00
|
|
|
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>')
|
2024-01-02 18:09:18 -07:00
|
|
|
poke_eventloop() -- wait for :sleep to start
|
2022-04-29 22:11:35 -07:00
|
|
|
feed('foo<C-C>')
|
2024-01-02 18:09:18 -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>')
|
2024-01-02 18:09:18 -07:00
|
|
|
sleep(10) -- wait for the key to enter typeahead
|
2022-06-06 21:41:18 -07:00
|
|
|
feed('foo<C-C>')
|
2024-01-02 18:09:18 -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)
|