Add empty options dict to buf_attach

This commit is contained in:
KillTheMule
2018-05-21 20:42:59 +02:00
parent 65e7f6f0b9
commit 333679ad0e
2 changed files with 29 additions and 15 deletions

View File

@@ -83,15 +83,22 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// the whole buffer. If so, the first notification will be a /// the whole buffer. If so, the first notification will be a
/// `nvim_buf_lines_event`. Otherwise, the first notification will be /// `nvim_buf_lines_event`. Otherwise, the first notification will be
/// a `nvim_buf_changedtick_event` /// a `nvim_buf_changedtick_event`
/// @param opts Optional parameters. Currently not used.
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
/// @return False when updates couldn't be enabled because the buffer isn't /// @return False when updates couldn't be enabled because the buffer isn't
/// loaded; otherwise True. /// loaded or `opts` contained an invalid key; otherwise True.
Boolean nvim_buf_attach(uint64_t channel_id, Boolean nvim_buf_attach(uint64_t channel_id,
Buffer buffer, Buffer buffer,
Boolean send_buffer, Boolean send_buffer,
Dictionary opts,
Error *err) Error *err)
FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY
{ {
if (opts.size > 0) {
api_set_error(err, kErrorTypeValidation, "dict isn't empty");
return false;
}
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) { if (!buf) {

View File

@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local eq, ok = helpers.eq, helpers.ok local eq, ok = helpers.eq, helpers.ok
local buffer, command, eval, nvim, next_msg = helpers.buffer, local buffer, command, eval, nvim, next_msg = helpers.buffer,
helpers.command, helpers.eval, helpers.nvim, helpers.next_msg helpers.command, helpers.eval, helpers.nvim, helpers.next_msg
local expect_err = helpers.expect_err
local origlines = {"original line 1", local origlines = {"original line 1",
"original line 2", "original line 2",
@@ -36,7 +37,7 @@ local function open(activate, lines)
-- arrive as expectected -- arrive as expectected
if activate then if activate then
local firstline = 0 local firstline = 0
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
expectn('nvim_buf_lines_event', {b, tick, firstline, -1, lines, false}) expectn('nvim_buf_lines_event', {b, tick, firstline, -1, lines, false})
end end
@@ -58,7 +59,7 @@ local function reopen(buf, expectedlines)
-- for some reason the :edit! increments tick by 2 -- for some reason the :edit! increments tick by 2
command('edit!') command('edit!')
local tick = eval('b:changedtick') local tick = eval('b:changedtick')
ok(buffer('attach', buf, true)) ok(buffer('attach', buf, true, {}))
local firstline = 0 local firstline = 0
expectn('nvim_buf_lines_event', {buf, tick, firstline, -1, expectedlines, false}) expectn('nvim_buf_lines_event', {buf, tick, firstline, -1, expectedlines, false})
command('normal! gg') command('normal! gg')
@@ -163,7 +164,7 @@ describe('buffer events', function()
command('enew') command('enew')
tick = eval('b:changedtick') tick = eval('b:changedtick')
local b2 = nvim('get_current_buf') local b2 = nvim('get_current_buf')
ok(buffer('attach', b2, true)) ok(buffer('attach', b2, true, {}))
expectn('nvim_buf_lines_event', {b2, tick, 0, -1, {""}, false}) expectn('nvim_buf_lines_event', {b2, tick, 0, -1, {""}, false})
eval('append(0, ["new line 1"])') eval('append(0, ["new line 1"])')
tick = tick + 1 tick = tick + 1
@@ -176,7 +177,7 @@ describe('buffer events', function()
-- add multiple lines to a blank file -- add multiple lines to a blank file
command('enew!') command('enew!')
local b3 = nvim('get_current_buf') local b3 = nvim('get_current_buf')
ok(buffer('attach', b3, true)) ok(buffer('attach', b3, true, {}))
tick = eval('b:changedtick') tick = eval('b:changedtick')
expectn('nvim_buf_lines_event', {b3, tick, 0, -1, {""}, false}) expectn('nvim_buf_lines_event', {b3, tick, 0, -1, {""}, false})
eval('append(0, ["new line 1", "new line 2", "new line 3"])') eval('append(0, ["new line 1", "new line 2", "new line 3"])')
@@ -268,7 +269,7 @@ describe('buffer events', function()
tick = 2 tick = 2
expectn('nvim_buf_detach_event', {b}) expectn('nvim_buf_detach_event', {b})
local bnew = nvim('get_current_buf') local bnew = nvim('get_current_buf')
ok(buffer('attach', bnew, true)) ok(buffer('attach', bnew, true, {}))
expectn('nvim_buf_lines_event', {bnew, tick, 0, -1, {''}, false}) expectn('nvim_buf_lines_event', {bnew, tick, 0, -1, {''}, false})
sendkeys('i') sendkeys('i')
sendkeys('h') sendkeys('h')
@@ -441,11 +442,11 @@ describe('buffer events', function()
local b, tick = editoriginal(false) local b, tick = editoriginal(false)
-- turn on live updates many times -- turn on live updates many times
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
ok(buffer('attach', b, true)) ok(buffer('attach', b, true, {}))
expectn('nvim_buf_lines_event', {b, tick, 0, -1, origlines, false}) expectn('nvim_buf_lines_event', {b, tick, 0, -1, origlines, false})
eval('rpcnotify('..channel..', "Hello There")') eval('rpcnotify('..channel..', "Hello There")')
expectn('Hello There', {}) expectn('Hello There', {})
@@ -490,9 +491,9 @@ describe('buffer events', function()
local b, tick = open(false, lines) local b, tick = open(false, lines)
-- turn on live updates for sessions 1, 2 and 3 -- turn on live updates for sessions 1, 2 and 3
ok(request(1, 'nvim_buf_attach', b, true)) ok(request(1, 'nvim_buf_attach', b, true, {}))
ok(request(2, 'nvim_buf_attach', b, true)) ok(request(2, 'nvim_buf_attach', b, true, {}))
ok(request(3, 'nvim_buf_attach', b, true)) ok(request(3, 'nvim_buf_attach', b, true, {}))
wantn(1, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) wantn(1, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false})
wantn(2, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) wantn(2, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false})
wantn(3, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) wantn(3, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false})
@@ -732,8 +733,14 @@ describe('buffer events', function()
it('doesn\'t send the buffer\'s content when not requested', function() it('doesn\'t send the buffer\'s content when not requested', function()
helpers.clear() helpers.clear()
local b, tick = editoriginal(false) local b, tick = editoriginal(false)
ok(buffer('attach', b, false)) ok(buffer('attach', b, false, {}))
expectn('nvim_buf_changedtick_event', {b, tick}) expectn('nvim_buf_changedtick_event', {b, tick})
end) end)
it('returns a proper error on nonempty options dict', function()
helpers.clear()
local b = editoriginal(false)
expect_err("dict isn't empty", buffer, 'attach', b, false, {builtin="asfd"})
end)
end) end)