aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/loop_spec.lua
diff options
context:
space:
mode:
authorGeorge Zhao <zhaozg@gmail.com>2019-06-10 20:13:18 +0800
committerJustin M. Keyes <justinkz@gmail.com>2019-06-10 14:13:18 +0200
commitc83926cd0aa5720e88e84fa3fae3c0e689cca3ef (patch)
treeb0511481bce7d76b4dfe91b1bdc6d626eeeb5f40 /test/functional/lua/loop_spec.lua
parent3e58e60568c2acc765f3ee72295e2f15baa3cf52 (diff)
downloadrneovim-c83926cd0aa5720e88e84fa3fae3c0e689cca3ef.tar.gz
rneovim-c83926cd0aa5720e88e84fa3fae3c0e689cca3ef.tar.bz2
rneovim-c83926cd0aa5720e88e84fa3fae3c0e689cca3ef.zip
lua: introduce vim.loop (expose libuv event-loop) #10123
Co-authored-by: Andrey Popp <8mayday@gmail.com> closes #9546 closes #10084
Diffstat (limited to 'test/functional/lua/loop_spec.lua')
-rw-r--r--test/functional/lua/loop_spec.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua
new file mode 100644
index 0000000000..8cc54e8c13
--- /dev/null
+++ b/test/functional/lua/loop_spec.lua
@@ -0,0 +1,55 @@
+-- Test suite for testing interactions with API bindings
+local helpers = require('test.functional.helpers')(after_each)
+local funcs = helpers.funcs
+local meths = helpers.meths
+local clear = helpers.clear
+local sleep = helpers.sleep
+local eq = helpers.eq
+local matches = helpers.matches
+
+before_each(clear)
+
+describe('vim.loop', 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()'))
+ end)
+
+ it('timer', function()
+ meths.execute_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {})
+
+ local code=[[
+ local loop = vim.loop
+
+ local touch = 0
+ local function wait(ms)
+ local this = coroutine.running()
+ assert(this)
+ local timer = loop.new_timer()
+ timer:start(ms, 0, 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)
+ end)()
+ ]]
+
+ eq(0, meths.get_var('coroutine_cnt'))
+ meths.execute_lua(code, {})
+ sleep(20)
+ eq(2, meths.get_var('coroutine_cnt'))
+ eq(3, meths.get_var('coroutine_cnt_1'))
+ end)
+end)