aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/ui_event_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/lua/ui_event_spec.lua
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-rahm.tar.gz
rneovim-rahm.tar.bz2
rneovim-rahm.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'test/functional/lua/ui_event_spec.lua')
-rw-r--r--test/functional/lua/ui_event_spec.lua177
1 files changed, 111 insertions, 66 deletions
diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua
index c8616e3e11..ddb10127e4 100644
--- a/test/functional/lua/ui_event_spec.lua
+++ b/test/functional/lua/ui_event_spec.lua
@@ -106,20 +106,15 @@ describe('vim.ui_attach', function()
end)
it('does not crash on exit', function()
- fn.system({
- n.nvim_prog,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ local p = n.spawn_wait(
'--cmd',
[[ lua ns = vim.api.nvim_create_namespace 'testspace' ]],
'--cmd',
[[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]],
'--cmd',
- 'quitall!',
- })
- eq(0, n.eval('v:shell_error'))
+ 'quitall!'
+ )
+ eq(0, p.status)
end)
it('can receive accurate message kinds even if they are history', function()
@@ -173,18 +168,67 @@ describe('vim.ui_attach', function()
vim.ui_attach(ns, { ext_messages = true }, function(ev)
if ev == 'msg_show' then
vim.schedule(function() vim.cmd.redraw() end)
- else
- vim.cmd.redraw()
+ elseif ev:find('cmdline') then
+ _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0)
+ vim.api.nvim_buf_set_lines(0, 0, -1, false, { tostring(_G.cmdline) })
+ vim.cmd('redraw')
end
- _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0)
end
)]])
+ screen:expect([[
+ ^ |
+ {1:~ }|*4
+ ]])
feed(':')
- n.assert_alive()
- eq(2, exec_lua('return _G.cmdline'))
- n.assert_alive()
+ screen:expect({
+ grid = [[
+ ^1 |
+ {1:~ }|*4
+ ]],
+ cmdline = { {
+ content = { { '' } },
+ firstc = ':',
+ pos = 0,
+ } },
+ })
feed('version<CR><CR>v<Esc>')
- n.assert_alive()
+ screen:expect({
+ grid = [[
+ ^2 |
+ {1:~ }|*4
+ ]],
+ cmdline = { { abort = false } },
+ })
+ feed([[:call confirm("Save changes?", "&Yes\n&No\n&Cancel")<CR>]])
+ screen:expect({
+ grid = [[
+ ^4 |
+ {1:~ }|*4
+ ]],
+ cmdline = {
+ {
+ content = { { '' } },
+ hl_id = 10,
+ pos = 0,
+ prompt = '[Y]es, (N)o, (C)ancel: ',
+ },
+ },
+ messages = {
+ {
+ content = { { '\nSave changes?\n', 6, 10 } },
+ history = false,
+ kind = 'confirm',
+ },
+ },
+ })
+ feed('n')
+ screen:expect({
+ grid = [[
+ ^4 |
+ {1:~ }|*4
+ ]],
+ cmdline = { { abort = false } },
+ })
end)
it("preserved 'incsearch/command' screen state after :redraw from ext_cmdline", function()
@@ -261,30 +305,15 @@ describe('vim.ui_attach', function()
lled in a fast event context |
{1:~ }|
]],
+ cmdline = { { abort = false } },
messages = {
{
- content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 7 } },
+ content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 6 } },
+ history = true,
kind = 'emsg',
},
},
})
- -- No fast context for prompt message kinds
- feed(':%s/Function/Replacement/c<cr>')
- screen:expect({
- grid = [[
- ^E122: {10:Function} Foo already exists, add !|
- to replace it |
- replace with Replacement (y/n/a/q/l/^E/^|
- Y)? |
- {1:~ }|
- ]],
- messages = {
- {
- content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 19 } },
- kind = 'confirm_sub',
- },
- },
- })
end)
end)
@@ -316,30 +345,36 @@ describe('vim.ui_attach', function()
vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] })
end)
]])
+ local s1 = [[
+ ^ |
+ {1:~ }|*4
+ ]]
+ screen:expect(s1)
+ feed('QQQQQQ<CR>')
screen:expect({
grid = [[
- ^ |
- {1:~ }|*4
- ]],
- })
- feed('ifoo')
- screen:expect({
- grid = [[
- foo^ |
- {1:~ }|*4
- ]],
- showmode = { { '-- INSERT --', 5, 12 } },
- })
- feed('<esc>:1mes clear<cr>:mes<cr>')
- screen:expect({
- grid = [[
- foo |
- {3: }|
- {9:Excessive errors in vim.ui_attach() call}|
- {9:back from ns: 1.} |
+ {9:obal 'err' (a nil value)} |
+ {9:stack traceback:} |
+ {9: [string "<nvim>"]:2: in function}|
+ {9: <[string "<nvim>"]:1>} |
{100:Press ENTER or type command to continue}^ |
]],
+ messages = {
+ {
+ content = { { 'Press ENTER or type command to continue', 100, 18 } },
+ history = true,
+ kind = 'return_prompt',
+ },
+ },
})
+ feed(':1mes clear<CR>:mes<CR>')
+ screen:expect([[
+ |
+ {3: }|
+ {9:Excessive errors in vim.ui_attach() call}|
+ {9:back from ns: 1.} |
+ {100:Press ENTER or type command to continue}^ |
+ ]])
feed('<cr>')
-- Also when scheduled
exec_lua([[
@@ -348,16 +383,17 @@ describe('vim.ui_attach', function()
end)
]])
screen:expect({
- any = 'fo^o',
+ grid = s1,
messages = {
{
content = {
{
'Error executing vim.schedule lua callback: [string "<nvim>"]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string "<nvim>"]:2: in function <[string "<nvim>"]:2>',
9,
- 7,
+ 6,
},
},
+ history = true,
kind = 'lua_error',
},
{
@@ -365,26 +401,35 @@ describe('vim.ui_attach', function()
{
'Error executing vim.schedule lua callback: [string "<nvim>"]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string "<nvim>"]:2: in function <[string "<nvim>"]:2>',
9,
- 7,
+ 6,
},
},
+ history = true,
kind = 'lua_error',
},
{
- content = { { 'Press ENTER or type command to continue', 100, 19 } },
+ content = { { 'Press ENTER or type command to continue', 100, 18 } },
+ history = false,
kind = 'return_prompt',
},
},
})
feed('<esc>:1mes clear<cr>:mes<cr>')
- screen:expect({
- grid = [[
- foo |
- {3: }|
- {9:Excessive errors in vim.ui_attach() call}|
- {9:back from ns: 2.} |
- {100:Press ENTER or type command to continue}^ |
- ]],
- })
+ screen:expect([[
+ |
+ {3: }|
+ {9:Excessive errors in vim.ui_attach() call}|
+ {9:back from ns: 2.} |
+ {100:Press ENTER or type command to continue}^ |
+ ]])
+ end)
+
+ it('sourcing invalid file does not crash #32166', function()
+ exec_lua([[
+ local ns = vim.api.nvim_create_namespace("")
+ vim.ui_attach(ns, { ext_messages = true }, function() end)
+ ]])
+ feed((':luafile %s<CR>'):format(testlog))
+ n.assert_alive()
end)
end)