mirror of
https://github.com/neovim/neovim.git
synced 2026-04-19 14:00:49 +00:00
tests: load-adjust timer tests (functionaltest)
This commit is contained in:
@@ -4,6 +4,7 @@ local feed, eq, eval = helpers.feed, helpers.eq, helpers.eval
|
||||
local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
|
||||
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local load_adjust = helpers.load_adjust
|
||||
|
||||
describe('timers', function()
|
||||
before_each(function()
|
||||
@@ -19,14 +20,14 @@ describe('timers', function()
|
||||
it('works one-shot', function()
|
||||
command("call timer_start(50, 'MyHandler')")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 200)
|
||||
run(nil, nil, nil, load_adjust(200))
|
||||
eq(1,eval("g:val"))
|
||||
end)
|
||||
|
||||
it('works one-shot when repeat=0', function()
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': 0})")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 200)
|
||||
run(nil, nil, nil, load_adjust(200))
|
||||
eq(1,eval("g:val"))
|
||||
end)
|
||||
|
||||
@@ -34,7 +35,7 @@ describe('timers', function()
|
||||
it('works with repeat two', function()
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(2,eval("g:val"))
|
||||
end)
|
||||
|
||||
@@ -42,14 +43,14 @@ describe('timers', function()
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||
nvim_async("command", "sleep 10")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(2,eval("g:val"))
|
||||
end)
|
||||
|
||||
it('works with zero timeout', function()
|
||||
-- timer_start does still not invoke the callback immediately
|
||||
eq(0,eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]"))
|
||||
run(nil, nil, nil, 400)
|
||||
run(nil, nil, nil, load_adjust(400))
|
||||
eq(1000,eval("g:val"))
|
||||
end)
|
||||
|
||||
@@ -58,18 +59,18 @@ describe('timers', function()
|
||||
-- this also tests that remote requests works during sleep
|
||||
eval("timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(2,eval("g:val"))
|
||||
end)
|
||||
|
||||
it('are paused when event processing is disabled', function()
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||
run(nil, nil, nil, 100)
|
||||
run(nil, nil, nil, load_adjust(100))
|
||||
local count = eval("g:val")
|
||||
-- shows two line error message and thus invokes the return prompt.
|
||||
-- if we start to allow event processing here, we need to change this test.
|
||||
feed(':throw "fatal error"<CR>')
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
feed("<cr>")
|
||||
local diff = eval("g:val") - count
|
||||
assert(0 <= diff and diff <= 4,
|
||||
@@ -79,7 +80,7 @@ describe('timers', function()
|
||||
it('are triggered in blocking getchar() call', function()
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||
nvim_async("command", "let g:c = getchar()")
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
feed("c")
|
||||
local count = eval("g:val")
|
||||
assert(count >= 3, 'expected count >= 3, got: '..tostring(count))
|
||||
@@ -137,10 +138,10 @@ describe('timers', function()
|
||||
it('can be stopped', function()
|
||||
local t = eval("timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
funcs.timer_stop(t)
|
||||
local count = eval("g:val")
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
local count2 = eval("g:val")
|
||||
-- when count is eval:ed after timer_stop this should be non-racy
|
||||
eq(count, count2)
|
||||
@@ -161,7 +162,7 @@ describe('timers', function()
|
||||
]])
|
||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||
eq(0,eval("g:val"))
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(3,eval("g:val"))
|
||||
end)
|
||||
|
||||
@@ -174,7 +175,7 @@ describe('timers', function()
|
||||
]])
|
||||
command("call timer_start(20, 'MyHandler', {'repeat': 3})")
|
||||
command("call timer_start(40, 'MyHandler2', {'repeat': 2})")
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(3,eval("g:val"))
|
||||
eq(2,eval("g:val2"))
|
||||
end)
|
||||
@@ -189,7 +190,7 @@ describe('timers', function()
|
||||
endfunc
|
||||
]])
|
||||
command("call timer_start(5, 'MyHandler', {'repeat': 1})")
|
||||
run(nil, nil, nil, 300)
|
||||
run(nil, nil, nil, load_adjust(300))
|
||||
eq(1,eval("g:val"))
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user