robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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