aboutsummaryrefslogtreecommitdiff
path: root/test/functional/editor
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-06-07 12:41:18 +0800
committerGitHub <noreply@github.com>2022-06-07 12:41:18 +0800
commit9e442c17eeffca934c1de3674b910458e04c989b (patch)
treeeb5ee68d6e118f1b927a9f3fd6203e4fa673091a /test/functional/editor
parentab1f96e1d5ba6d6664eb472c2eaade4f91982734 (diff)
downloadrneovim-9e442c17eeffca934c1de3674b910458e04c989b.tar.gz
rneovim-9e442c17eeffca934c1de3674b910458e04c989b.tar.bz2
rneovim-9e442c17eeffca934c1de3674b910458e04c989b.zip
fix(input): allow Ctrl-C to interrupt a recursive mapping even if mapped (#18885)
Diffstat (limited to 'test/functional/editor')
-rw-r--r--test/functional/editor/ctrl_c_spec.lua94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua
new file mode 100644
index 0000000000..60131bf2a4
--- /dev/null
+++ b/test/functional/editor/ctrl_c_spec.lua
@@ -0,0 +1,94 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear, feed, source = helpers.clear, helpers.feed, helpers.source
+local command = helpers.command
+local sleep = helpers.sleep
+
+describe("CTRL-C (mapped)", function()
+ local screen
+
+ before_each(function()
+ clear()
+ screen = Screen.new(52, 6)
+ screen:attach()
+ end)
+
+ it("interrupts :global", function()
+ -- Crashes luajit.
+ if helpers.skip_fragile(pending) then
+ return
+ end
+
+ source([[
+ set nomore nohlsearch undolevels=-1
+ nnoremap <C-C> <NOP>
+ ]])
+
+ command("silent edit! test/functional/fixtures/bigfile.txt")
+
+ 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>")
+ screen:sleep(ms)
+ feed("<C-C>")
+ screen:expect{any="Interrupt"}
+ end
+
+ -- The test is time-sensitive. Try different sleep values.
+ local ms_values = {100, 1000, 10000}
+ 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)
+
+ it('interrupts :sleep', function()
+ command('nnoremap <C-C> <Nop>')
+ feed(':sleep 100<CR>')
+ -- wait for :sleep to start
+ sleep(10)
+ feed('foo<C-C>')
+ -- wait for input buffer to be flushed
+ sleep(10)
+ feed('i')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ end)
+
+ it('interrupts recursive mapping', function()
+ command('nnoremap <C-C> <Nop>')
+ command('nmap <F2> <Ignore><F2>')
+ feed('<F2>')
+ sleep(10)
+ feed('foo<C-C>')
+ -- wait for input buffer to be flushed
+ sleep(10)
+ feed('i')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ end)
+end)