mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 23:08:16 +00:00
fixup! eval: add wait() test
This commit is contained in:
@@ -10895,15 +10895,11 @@ static void f_getwininfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// Dummy timer callback. Used by f_wait().
|
// Dummy timer callback. Used by f_wait().
|
||||||
static void dummy_timer_due_cb(TimeWatcher *tw, void *data)
|
static void dummy_timer_due_cb(TimeWatcher *tw, void *data)
|
||||||
{
|
{
|
||||||
if (!uv_timer_get_repeat(&tw->uv)) {
|
|
||||||
time_watcher_start(tw, dummy_timer_due_cb, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy timer close callback. Used by f_wait().
|
// Dummy timer close callback. Used by f_wait().
|
||||||
static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
|
static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
|
||||||
{
|
{
|
||||||
multiqueue_free(tw->events);
|
|
||||||
xfree(tw);
|
xfree(tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10914,7 +10910,7 @@ static void f_wait(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
|
|
||||||
if (argvars[0].v_type != VAR_NUMBER) {
|
if (argvars[0].v_type != VAR_NUMBER) {
|
||||||
EMSG2(_(e_invarg2), "First argument of wait() must be a number");
|
EMSG2(_(e_invargval), "1");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10928,20 +10924,18 @@ static void f_wait(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
if (tv_interval->v_type == VAR_NUMBER) {
|
if (tv_interval->v_type == VAR_NUMBER) {
|
||||||
interval = tv_interval->vval.v_number;
|
interval = tv_interval->vval.v_number;
|
||||||
if (interval < 0) {
|
if (interval <= 0) {
|
||||||
EMSG2(_(e_invarg2),
|
EMSG2(_(e_invargval), "3");
|
||||||
"Third argument of wait() must be a non-negative number");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Start dummy timer
|
// Start dummy timer
|
||||||
tw = xmalloc(sizeof(TimeWatcher));
|
tw = xmalloc(sizeof(TimeWatcher));
|
||||||
time_watcher_init(&main_loop, tw, NULL);
|
time_watcher_init(&main_loop, tw, NULL);
|
||||||
tw->events = multiqueue_new_child(main_loop.events);
|
tw->events = main_loop.events;
|
||||||
tw->blockable = true;
|
tw->blockable = true;
|
||||||
time_watcher_start(tw, dummy_timer_due_cb, interval, interval);
|
time_watcher_start(tw, dummy_timer_due_cb, interval, interval);
|
||||||
} else if (tv_interval->v_type != VAR_UNKNOWN) {
|
} else if (tv_interval->v_type != VAR_UNKNOWN) {
|
||||||
EMSG2(_(e_invarg2),
|
EMSG2(_(e_invargval), "3");
|
||||||
"Third argument of wait() must be a non-negative number");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,18 +64,15 @@ describe('wait()', function()
|
|||||||
nvim('set_var', 'counter', 0)
|
nvim('set_var', 'counter', 0)
|
||||||
eq(0, call('wait', 1000, 'Count() >= 5', 5))
|
eq(0, call('wait', 1000, 'Count() >= 5', 5))
|
||||||
eq(5, nvim('get_var', 'counter'))
|
eq(5, nvim('get_var', 'counter'))
|
||||||
|
|
||||||
nvim('set_var', 'counter', 0)
|
|
||||||
eq(0, call('wait', 1000, 'Count() >= 5', 0))
|
|
||||||
eq(5, nvim('get_var', 'counter'))
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('errors out on invalid timeout value', function()
|
it('errors out on invalid timeout value', function()
|
||||||
expect_err('E475: Invalid argument', call, 'wait', '', 1)
|
expect_err('Invalid value for argument', call, 'wait', '', 1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('errors out on invalid interval', function()
|
it('errors out on invalid interval', function()
|
||||||
expect_err('E475: Invalid argument', call, 'wait', 0, 1, -1)
|
expect_err('Invalid value for argument', call, 'wait', 0, 1, -1)
|
||||||
expect_err('E475: Invalid argument', call, 'wait', 0, 1, '')
|
expect_err('Invalid value for argument', call, 'wait', 0, 1, 0)
|
||||||
|
expect_err('Invalid value for argument', call, 'wait', 0, 1, '')
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user