test: support upvalues in exec_lua

This commit is contained in:
Lewis Russell
2024-08-11 09:27:48 +01:00
committed by Lewis Russell
parent a19e89022d
commit e5c174421d
34 changed files with 1740 additions and 1362 deletions

View File

@@ -25,30 +25,34 @@ describe('vim.uv', function()
it('timer', function()
exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {})
local code = [[
local code = function()
local touch = 0
local function wait(ms)
local this = coroutine.running()
assert(this)
local timer = vim.uv.new_timer()
timer:start(ms, 0, vim.schedule_wrap(function ()
timer:close()
touch = touch + 1
coroutine.resume(this)
touch = touch + 1
assert(touch==3)
vim.api.nvim_set_var("coroutine_cnt_1", touch)
end))
local timer = assert(vim.uv.new_timer())
timer:start(
ms,
0,
vim.schedule_wrap(function()
timer:close()
touch = touch + 1
coroutine.resume(this)
touch = touch + 1
assert(touch == 3)
vim.api.nvim_set_var('coroutine_cnt_1', touch)
end)
)
coroutine.yield()
touch = touch + 1
return touch
end
coroutine.wrap(function()
local touched = wait(10)
assert(touched==touch)
vim.api.nvim_set_var("coroutine_cnt", touched)
assert(touched == touch)
vim.api.nvim_set_var('coroutine_cnt', touched)
end)()
]]
end
eq(0, api.nvim_get_var('coroutine_cnt'))
exec_lua(code)
@@ -99,15 +103,19 @@ describe('vim.uv', function()
-- callbacks can be scheduled to be executed in the main event loop
-- where the entire API is available
exec_lua([[
local timer = vim.uv.new_timer()
timer:start(20, 0, vim.schedule_wrap(function ()
_G.is_fast = vim.in_fast_event()
timer:close()
vim.api.nvim_set_var("valid", true)
vim.api.nvim_command("echomsg 'howdy'")
end))
]])
exec_lua(function()
local timer = assert(vim.uv.new_timer())
timer:start(
20,
0,
vim.schedule_wrap(function()
_G.is_fast = vim.in_fast_event()
timer:close()
vim.api.nvim_set_var('valid', true)
vim.api.nvim_command("echomsg 'howdy'")
end)
)
end)
screen:expect([[
^ |
@@ -118,15 +126,15 @@ describe('vim.uv', function()
eq(false, exec_lua('return _G.is_fast'))
-- fast (not deferred) API functions are allowed to be called directly
exec_lua([[
local timer = vim.uv.new_timer()
timer:start(20, 0, function ()
exec_lua(function()
local timer = assert(vim.uv.new_timer())
timer:start(20, 0, function()
timer:close()
-- input is queued for processing after the callback returns
vim.api.nvim_input("isneaky")
vim.api.nvim_input('isneaky')
_G.mode = vim.api.nvim_get_mode()
end)
]])
end)
screen:expect([[
sneaky^ |
{1:~ }|*8
@@ -134,15 +142,15 @@ describe('vim.uv', function()
]])
eq({ blocking = false, mode = 'n' }, exec_lua('return _G.mode'))
exec_lua([[
local timer = vim.uv.new_timer()
timer:start(20, 0, function ()
exec_lua(function()
local timer = assert(vim.uv.new_timer())
timer:start(20, 0, function()
_G.is_fast = vim.in_fast_event()
timer:close()
_G.value = vim.fn.has("nvim-0.5")
_G.unvalue = vim.fn.has("python3")
_G.value = vim.fn.has('nvim-0.5')
_G.unvalue = vim.fn.has('python3')
end)
]])
end)
screen:expect({ any = [[{3:Vim:E5560: Vimscript function must not be called i}]] })
feed('<cr>')