diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/lua/loop_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/lua/overrides_spec.lua | 105 |
2 files changed, 107 insertions, 4 deletions
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index b96214738a..992d1666f6 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -75,6 +75,7 @@ describe('vim.loop', function() exec_lua([[ local timer = vim.loop.new_timer() timer:start(20, 0, function () + _G.is_fast = vim.in_fast_event() timer:close() vim.api.nvim_set_var("valid", true) vim.api.nvim_command("echomsg 'howdy'") @@ -89,18 +90,20 @@ describe('vim.loop', function() {1:~ }| {2: }| {3:Error executing luv callback:} | - {3:[string "<nvim>"]:4: E5560: nvim_set_var must not }| + {3:[string "<nvim>"]:5: E5560: nvim_set_var must not }| {3:be called in a lua loop callback} | {4:Press ENTER or type command to continue}^ | ]]) feed('<cr>') eq(false, eval("get(g:, 'valid', v:false)")) + eq(true, exec_lua("return _G.is_fast")) -- 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() 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'") @@ -120,6 +123,7 @@ describe('vim.loop', function() howdy | ]]) eq(true, eval("get(g:, 'valid', v:false)")) + eq(false, exec_lua("return _G.is_fast")) -- fast (not deferred) API functions are allowed to be called directly exec_lua([[ diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 8f318e3503..f6439001ac 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -14,6 +14,7 @@ local command = helpers.command local write_file = helpers.write_file local redir_exec = helpers.redir_exec local alter_slashes = helpers.alter_slashes +local exec_lua = helpers.exec_lua local screen @@ -53,11 +54,11 @@ describe('print', function() v_tblout = setmetatable({}, meta_tblout) ]]) eq('', redir_exec('luafile ' .. fname)) - eq('\nE5114: Error while converting print argument #2: [NULL]', + eq('\nE5105: Error while calling lua chunk: E5114: Error while converting print argument #2: [NULL]', redir_exec('lua print("foo", v_nilerr, "bar")')) - eq('\nE5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', + eq('\nE5105: Error while calling lua chunk: E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', redir_exec('lua print("foo", v_abcerr, "bar")')) - eq('\nE5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>', + eq('\nE5105: Error while calling lua chunk: E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>', redir_exec('lua print("foo", v_tblout, "bar")')) end) it('prints strings with NULs and NLs correctly', function() @@ -76,6 +77,29 @@ describe('print', function() eq('\nabc ', redir_exec('lua print("abc", "")')) eq('\nabc def', redir_exec('lua print("abc", "", "def")')) end) + it('defers printing in luv event handlers', function() + exec_lua([[ + local cmd = ... + function test() + local timer = vim.loop.new_timer() + local done = false + timer:start(10, 0, function() + print("very fast") + timer:close() + done = true + end) + -- be kind to slow travis OS X jobs: + -- 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() + end + print("very slow") + vim.api.nvim_command("sleep 1m") -- force deferred event processing + end + ]], (iswin() and "timeout 1") or "sleep 0.1") + eq('\nvery slow\nvery fast',redir_exec('lua test()')) + end) end) describe('debug.debug', function() @@ -183,6 +207,81 @@ describe('debug.debug', function() {cr:Press ENTER or type command to continue}^ | ]]) end) + + it("can be safely exited with 'cont'", function() + feed('<cr>') + feed(':lua debug.debug() print("x")<cr>') + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + lua_debug> ^ | + ]]} + + feed("conttt<cr>") -- misspelled cont; invalid syntax + screen:expect{grid=[[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + lua_debug> conttt | + {E:E5115: Error while loading debug string: (debug comma}| + {E:nd):1: '=' expected near '<eof>'} | + lua_debug> ^ | + ]]} + + feed("cont<cr>") -- exactly "cont", exit now + screen:expect{grid=[[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + lua_debug> conttt | + {E:E5115: Error while loading debug string: (debug comma}| + {E:nd):1: '=' expected near '<eof>'} | + lua_debug> cont | + x | + {cr:Press ENTER or type command to continue}^ | + ]]} + + feed('<cr>') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end) end) describe('package.path/package.cpath', function() |