diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/eval/timer_spec.lua | 106 | ||||
-rw-r--r-- | test/functional/legacy/061_undo_tree_spec.lua | 13 |
2 files changed, 111 insertions, 8 deletions
diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua new file mode 100644 index 0000000000..df0a55e462 --- /dev/null +++ b/test/functional/eval/timer_spec.lua @@ -0,0 +1,106 @@ +local helpers = require('test.functional.helpers') +local ok, feed, eq, eval = helpers.ok, helpers.feed, helpers.eq, helpers.eval +local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run +local clear, execute, funcs = helpers.clear, helpers.execute, helpers.funcs + +describe('timers', function() + before_each(function() + clear() + source([[ + let g:val = 0 + func MyHandler(timer) + let g:val += 1 + endfunc + ]]) + end) + + it('works one-shot', function() + execute("call timer_start(50, 'MyHandler')") + eq(0,eval("g:val")) + run(nil, nil, nil, 200) + eq(1,eval("g:val")) + end) + + it('works with repeat two', function() + execute("call timer_start(50, 'MyHandler', {'repeat': 2})") + eq(0,eval("g:val")) + run(nil, nil, nil, 300) + eq(2,eval("g:val")) + end) + + it('are triggered during sleep', function() + execute("call timer_start(50, 'MyHandler', {'repeat': 2})") + nvim_async("command", "sleep 10") + eq(0,eval("g:val")) + run(nil, nil, nil, 300) + eq(2,eval("g:val")) + end) + + it('can be started during sleep', function() + nvim_async("command", "sleep 10") + -- 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) + eq(2,eval("g:val")) + end) + + it('are paused when event processing is disabled', function() + -- this is not the intended behavior, but at least there will + -- not be a burst of queued up callbacks + execute("call timer_start(50, 'MyHandler', {'repeat': 2})") + run(nil, nil, nil, 100) + local count = eval("g:val") + nvim_async("command", "let g:c = getchar()") + run(nil, nil, nil, 300) + feed("c") + local diff = eval("g:val") - count + ok(0 <= diff and diff <= 2) + eq(99, eval("g:c")) + end) + + it('can be stopped', function() + local t = eval("timer_start(50, 'MyHandler', {'repeat': -1})") + eq(0,eval("g:val")) + run(nil, nil, nil, 300) + funcs.timer_stop(t) + local count = eval("g:val") + run(nil, nil, nil, 300) + local count2 = eval("g:val") + ok(4 <= count and count <= 7) + -- when count is eval:ed after timer_stop this should be non-racy + eq(count, count2) + end) + + it('can be stopped from the handler', function() + source([[ + func! MyHandler(timer) + let g:val += 1 + if g:val == 3 + call timer_stop(a:timer) + " check double stop is ignored + call timer_stop(a:timer) + endif + endfunc + ]]) + execute("call timer_start(50, 'MyHandler', {'repeat': -1})") + eq(0,eval("g:val")) + run(nil, nil, nil, 300) + eq(3,eval("g:val")) + end) + + it('can have two timers', function() + source([[ + let g:val2 = 0 + func! MyHandler2(timer) + let g:val2 += 1 + endfunc + ]]) + execute("call timer_start(50, 'MyHandler', {'repeat': 3})") + execute("call timer_start(100, 'MyHandler2', {'repeat': 2})") + run(nil, nil, nil, 300) + eq(3,eval("g:val")) + eq(2,eval("g:val2")) + end) + +end) diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index 6db37bf1ff..350a77b2c5 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -1,10 +1,9 @@ -- Tests for undo tree and :earlier and :later. local helpers = require('test.functional.helpers') -local feed, source, eq, eval, clear, execute, expect, wait, write_file = - helpers.feed, helpers.source, helpers.eq, helpers.eval, - helpers.clear, helpers.execute, helpers.expect, helpers.wait, - helpers.write_file +local expect, feed, source = helpers.expect, helpers.feed, helpers.source +local eval, clear, execute = helpers.eval, helpers.clear, helpers.execute +local write_file, command, eq = helpers.write_file, helpers.command, helpers.eq local function expect_empty_buffer() -- The space will be removed by helpers.dedent but is needed because dedent @@ -57,8 +56,7 @@ describe('undo tree:', function() -- Delete three other characters and go back in time step by step. feed('$xxx') expect_line('123456') - execute('sleep 1') - wait() + command('sleep 1') feed('g-') expect_line('1234567') feed('g-') @@ -79,8 +77,7 @@ describe('undo tree:', function() expect_line('123456') -- Delay for two seconds and go some seconds forward and backward. - execute('sleep 2') - wait() + command('sleep 2') feed('Aa<esc>') feed('Ab<esc>') feed('Ac<esc>') |