robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.6 KiB89 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local clear = n.clear
6local eq = t.eq
7local exec = n.exec
8local exec_lua = n.exec_lua
9local feed = n.feed
10local api = n.api
11local poke_eventloop = n.poke_eventloop
12
13before_each(clear)
14
15describe('state() function', function()
16  -- oldtest: Test_state()
17  it('works', function()
18    api.nvim_ui_attach(80, 24, {}) -- Allow hit-enter-prompt
19
20    exec_lua([[
21      function _G.Get_state_mode()
22        _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) }
23      end
24      function _G.Run_timer()
25        local timer = vim.uv.new_timer()
26        timer:start(0, 0, function()
27          _G.Get_state_mode()
28          timer:close()
29        end)
30      end
31    ]])
32    exec([[
33      call setline(1, ['one', 'two', 'three'])
34      map ;; gg
35      set complete=.
36      func RunTimer()
37        call timer_start(0, {id -> v:lua.Get_state_mode()})
38      endfunc
39      au Filetype foobar call v:lua.Get_state_mode()
40    ]])
41
42    -- Using a ":" command Vim is busy, thus "S" is returned
43    feed([[:call v:lua.Get_state_mode()<CR>]])
44    eq({ 'S', 'n' }, exec_lua('return _G.res'))
45
46    -- Using a timer callback
47    feed([[:call RunTimer()<CR>]])
48    poke_eventloop() -- Process pending input
49    poke_eventloop() -- Process time_event
50    eq({ 'c', 'n' }, exec_lua('return _G.res'))
51
52    -- Halfway a mapping
53    feed([[:call v:lua.Run_timer()<CR>;]])
54    api.nvim_get_mode() -- Process pending input and luv timer callback
55    feed(';')
56    eq({ 'mS', 'n' }, exec_lua('return _G.res'))
57
58    -- An operator is pending
59    feed([[:call RunTimer()<CR>y]])
60    poke_eventloop() -- Process pending input
61    poke_eventloop() -- Process time_event
62    feed('y')
63    eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
64
65    -- A register was specified
66    feed([[:call RunTimer()<CR>"r]])
67    poke_eventloop() -- Process pending input
68    poke_eventloop() -- Process time_event
69    feed('yy')
70    eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
71
72    -- Insert mode completion
73    feed([[:call RunTimer()<CR>Got<C-N>]])
74    poke_eventloop() -- Process pending input
75    poke_eventloop() -- Process time_event
76    feed('<Esc>')
77    eq({ 'aSc', 'i' }, exec_lua('return _G.res'))
78
79    -- Autocommand executing
80    feed([[:set filetype=foobar<CR>]])
81    eq({ 'xS', 'n' }, exec_lua('return _G.res'))
82
83    -- messages scrolled
84    feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"<CR>]])
85    api.nvim_get_mode() -- Process pending input and luv timer callback
86    feed('<CR>')
87    eq({ 'Ss', 'r' }, exec_lua('return _G.res'))
88  end)
89end)