mirror of
https://github.com/neovim/neovim.git
synced 2026-04-22 07:15:34 +00:00
feat(lua): rename vim.loop -> vim.uv (#22846)
This commit is contained in:
@@ -24,7 +24,7 @@ describe('vim.highlight.on_yank', function()
|
||||
it('does not close timer twice', function()
|
||||
exec_lua([[
|
||||
vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y"}})
|
||||
vim.loop.sleep(10)
|
||||
vim.uv.sleep(10)
|
||||
vim.schedule(function()
|
||||
vim.highlight.on_yank({timeout = 0, on_macro = true, event = {operator = "y"}})
|
||||
end)
|
||||
|
||||
@@ -14,24 +14,24 @@ local retry = helpers.retry
|
||||
|
||||
before_each(clear)
|
||||
|
||||
describe('vim.loop', function()
|
||||
describe('vim.uv', function()
|
||||
|
||||
it('version', function()
|
||||
assert(funcs.luaeval('vim.loop.version()')>=72961, "libuv version too old")
|
||||
matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.loop.version_string()'))
|
||||
assert(funcs.luaeval('vim.uv.version()')>=72961, "libuv version too old")
|
||||
matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.uv.version_string()'))
|
||||
end)
|
||||
|
||||
it('timer', function()
|
||||
exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {})
|
||||
|
||||
local code=[[
|
||||
local loop = vim.loop
|
||||
local uv = vim.uv
|
||||
|
||||
local touch = 0
|
||||
local function wait(ms)
|
||||
local this = coroutine.running()
|
||||
assert(this)
|
||||
local timer = loop.new_timer()
|
||||
local timer = uv.new_timer()
|
||||
timer:start(ms, 0, vim.schedule_wrap(function ()
|
||||
timer:close()
|
||||
touch = touch + 1
|
||||
@@ -73,7 +73,7 @@ describe('vim.loop', function()
|
||||
|
||||
-- deferred API functions are disabled, as their safety can't be guaranteed
|
||||
exec_lua([[
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
timer:start(20, 0, function ()
|
||||
_G.is_fast = vim.in_fast_event()
|
||||
timer:close()
|
||||
@@ -101,7 +101,7 @@ describe('vim.loop', function()
|
||||
-- callbacks can be scheduled to be executed in the main event loop
|
||||
-- where the entire API is available
|
||||
exec_lua([[
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
timer:start(20, 0, vim.schedule_wrap(function ()
|
||||
_G.is_fast = vim.in_fast_event()
|
||||
timer:close()
|
||||
@@ -127,7 +127,7 @@ describe('vim.loop', function()
|
||||
|
||||
-- fast (not deferred) API functions are allowed to be called directly
|
||||
exec_lua([[
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
timer:start(20, 0, function ()
|
||||
timer:close()
|
||||
-- input is queued for processing after the callback returns
|
||||
@@ -151,6 +151,6 @@ describe('vim.loop', function()
|
||||
end)
|
||||
|
||||
it("is equal to require('luv')", function()
|
||||
eq(true, exec_lua("return vim.loop == require('luv')"))
|
||||
eq(true, exec_lua("return vim.uv == require('luv')"))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -119,7 +119,7 @@ describe('print', function()
|
||||
exec_lua([[
|
||||
local cmd = ...
|
||||
function test()
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
local done = false
|
||||
timer:start(10, 0, function()
|
||||
print("very fast")
|
||||
@@ -130,7 +130,7 @@ describe('print', function()
|
||||
-- loop until we know for sure the callback has been executed
|
||||
while not done do
|
||||
os.execute(cmd)
|
||||
vim.loop.run("nowait") -- fake os_breakcheck()
|
||||
vim.uv.run("nowait") -- fake os_breakcheck()
|
||||
end
|
||||
print("very slow")
|
||||
vim.api.nvim_command("sleep 1m") -- force deferred event processing
|
||||
|
||||
@@ -27,10 +27,10 @@ describe('thread', function()
|
||||
|
||||
it('entry func is executed in protected mode', function()
|
||||
exec_lua [[
|
||||
local thread = vim.loop.new_thread(function()
|
||||
local thread = vim.uv.new_thread(function()
|
||||
error('Error in thread entry func')
|
||||
end)
|
||||
vim.loop.thread_join(thread)
|
||||
vim.uv.thread_join(thread)
|
||||
]]
|
||||
|
||||
screen:expect([[
|
||||
@@ -51,17 +51,17 @@ describe('thread', function()
|
||||
|
||||
it('callback is executed in protected mode', function()
|
||||
exec_lua [[
|
||||
local thread = vim.loop.new_thread(function()
|
||||
local timer = vim.loop.new_timer()
|
||||
local thread = vim.uv.new_thread(function()
|
||||
local timer = vim.uv.new_timer()
|
||||
local function ontimeout()
|
||||
timer:stop()
|
||||
timer:close()
|
||||
error('Error in thread callback')
|
||||
end
|
||||
timer:start(10, 0, ontimeout)
|
||||
vim.loop.run()
|
||||
vim.uv.run()
|
||||
end)
|
||||
vim.loop.thread_join(thread)
|
||||
vim.uv.thread_join(thread)
|
||||
]]
|
||||
|
||||
screen:expect([[
|
||||
@@ -83,10 +83,10 @@ describe('thread', function()
|
||||
describe('print', function()
|
||||
it('works', function()
|
||||
exec_lua [[
|
||||
local thread = vim.loop.new_thread(function()
|
||||
local thread = vim.uv.new_thread(function()
|
||||
print('print in thread')
|
||||
end)
|
||||
vim.loop.thread_join(thread)
|
||||
vim.uv.thread_join(thread)
|
||||
]]
|
||||
|
||||
screen:expect([[
|
||||
@@ -105,10 +105,10 @@ describe('thread', function()
|
||||
|
||||
it('vim.inspect', function()
|
||||
exec_lua [[
|
||||
local thread = vim.loop.new_thread(function()
|
||||
local thread = vim.uv.new_thread(function()
|
||||
print(vim.inspect({1,2}))
|
||||
end)
|
||||
vim.loop.thread_join(thread)
|
||||
vim.uv.thread_join(thread)
|
||||
]]
|
||||
|
||||
screen:expect([[
|
||||
@@ -140,13 +140,13 @@ describe('thread', function()
|
||||
function Thread_Test:do_test()
|
||||
local async
|
||||
local on_async = self.on_async
|
||||
async = vim.loop.new_async(function(ret)
|
||||
async = vim.uv.new_async(function(ret)
|
||||
on_async(ret)
|
||||
async:close()
|
||||
end)
|
||||
local thread =
|
||||
vim.loop.new_thread(self.entry_func, async, self.entry_str, self.args)
|
||||
vim.loop.thread_join(thread)
|
||||
vim.uv.new_thread(self.entry_func, async, self.entry_str, self.args)
|
||||
vim.uv.thread_join(thread)
|
||||
end
|
||||
|
||||
Thread_Test.new = function(entry, on_async, ...)
|
||||
@@ -175,10 +175,10 @@ describe('thread', function()
|
||||
eq({'notification', 'result', {true}}, next_msg())
|
||||
end)
|
||||
|
||||
it('loop', function()
|
||||
it('uv', function()
|
||||
exec_lua [[
|
||||
local entry = function(async)
|
||||
async:send(vim.loop.version())
|
||||
async:send(vim.uv.version())
|
||||
end
|
||||
local on_async = function(ret)
|
||||
vim.rpcnotify(1, ret)
|
||||
@@ -259,7 +259,7 @@ describe('threadpool', function()
|
||||
local after_work_fn = function(ret)
|
||||
vim.rpcnotify(1, 'result', ret)
|
||||
end
|
||||
local work = vim.loop.new_work(work_fn, after_work_fn)
|
||||
local work = vim.uv.new_work(work_fn, after_work_fn)
|
||||
work:queue()
|
||||
]]
|
||||
|
||||
@@ -268,7 +268,7 @@ describe('threadpool', function()
|
||||
|
||||
it('with invalid argument', function()
|
||||
local status = pcall_err(exec_lua, [[
|
||||
local work = vim.loop.new_thread(function() end, function() end)
|
||||
local work = vim.uv.new_thread(function() end, function() end)
|
||||
work:queue({})
|
||||
]])
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('threadpool', function()
|
||||
})
|
||||
|
||||
exec_lua [[
|
||||
local work = vim.loop.new_work(function() return {} end, function() end)
|
||||
local work = vim.uv.new_work(function() return {} end, function() end)
|
||||
work:queue()
|
||||
]]
|
||||
|
||||
@@ -319,7 +319,7 @@ describe('threadpool', function()
|
||||
|
||||
function Threadpool_Test:do_test()
|
||||
local work =
|
||||
vim.loop.new_work(self.work_fn, self.after_work)
|
||||
vim.uv.new_work(self.work_fn, self.after_work)
|
||||
work:queue(self.work_fn_str, self.args)
|
||||
end
|
||||
|
||||
@@ -334,10 +334,10 @@ describe('threadpool', function()
|
||||
]]
|
||||
end)
|
||||
|
||||
it('loop', function()
|
||||
it('uv', function()
|
||||
exec_lua [[
|
||||
local work_fn = function()
|
||||
return vim.loop.version()
|
||||
return vim.uv.version()
|
||||
end
|
||||
local after_work_fn = function(ret)
|
||||
vim.rpcnotify(1, ret)
|
||||
|
||||
@@ -882,7 +882,7 @@ describe('lua stdlib', function()
|
||||
|
||||
it('vim.fn is allowed in "fast" context by some functions #18306', function()
|
||||
exec_lua([[
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
timer:start(0, 0, function()
|
||||
timer:close()
|
||||
assert(vim.in_fast_event())
|
||||
@@ -948,7 +948,7 @@ describe('lua stdlib', function()
|
||||
})
|
||||
screen:attach()
|
||||
exec_lua([[
|
||||
timer = vim.loop.new_timer()
|
||||
timer = vim.uv.new_timer()
|
||||
timer:start(20, 0, function ()
|
||||
-- notify ok (executed later when safe)
|
||||
vim.rpcnotify(chan, 'nvim_set_var', 'yy', {3, vim.NIL})
|
||||
@@ -2481,7 +2481,7 @@ describe('lua stdlib', function()
|
||||
start_time = get_time()
|
||||
|
||||
vim.g.timer_result = false
|
||||
timer = vim.loop.new_timer()
|
||||
timer = vim.uv.new_timer()
|
||||
timer:start(100, 0, vim.schedule_wrap(function()
|
||||
vim.g.timer_result = true
|
||||
end))
|
||||
@@ -2503,7 +2503,7 @@ describe('lua stdlib', function()
|
||||
start_time = get_time()
|
||||
|
||||
vim.g.timer_result = false
|
||||
timer = vim.loop.new_timer()
|
||||
timer = vim.uv.new_timer()
|
||||
timer:start(100, 0, vim.schedule_wrap(function()
|
||||
vim.g.timer_result = true
|
||||
end))
|
||||
@@ -2546,17 +2546,17 @@ describe('lua stdlib', function()
|
||||
|
||||
it('should allow waiting with no callback, explicit', function()
|
||||
eq(true, exec_lua [[
|
||||
local start_time = vim.loop.hrtime()
|
||||
local start_time = vim.uv.hrtime()
|
||||
vim.wait(50, nil)
|
||||
return vim.loop.hrtime() - start_time > 25000
|
||||
return vim.uv.hrtime() - start_time > 25000
|
||||
]])
|
||||
end)
|
||||
|
||||
it('should allow waiting with no callback, implicit', function()
|
||||
eq(true, exec_lua [[
|
||||
local start_time = vim.loop.hrtime()
|
||||
local start_time = vim.uv.hrtime()
|
||||
vim.wait(50)
|
||||
return vim.loop.hrtime() - start_time > 25000
|
||||
return vim.uv.hrtime() - start_time > 25000
|
||||
]])
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user