diff options
Diffstat (limited to 'test/functional/api/buffer_updates_spec.lua')
-rw-r--r-- | test/functional/api/buffer_updates_spec.lua | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 00409c1528..6da790b871 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -3,6 +3,7 @@ local eq, ok = helpers.eq, helpers.ok local buffer, command, eval, nvim, next_msg = helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg local expect_err = helpers.expect_err +local write_file = helpers.write_file local origlines = {"original line 1", "original line 2", @@ -18,7 +19,7 @@ end local function sendkeys(keys) nvim('input', keys) - -- give neovim some time to process msgpack requests before possibly sending + -- give nvim some time to process msgpack requests before possibly sending -- more key presses - otherwise they all pile up in the queue and get -- processed at once local ntime = os.clock() + 0.1 @@ -27,14 +28,14 @@ end local function open(activate, lines) local filename = helpers.tmpname() - helpers.write_file(filename, table.concat(lines, "\n").."\n", true) + write_file(filename, table.concat(lines, "\n").."\n", true) command('edit ' .. filename) local b = nvim('get_current_buf') -- what is the value of b:changedtick? local tick = eval('b:changedtick') - -- turn on live updates, ensure that the nvim_buf_lines_event messages - -- arrive as expectected + -- Enable buffer events, ensure that the nvim_buf_lines_event messages + -- arrive as expected if activate then local firstline = 0 ok(buffer('attach', b, true, {})) @@ -91,8 +92,8 @@ local function reopenwithfolds(b) return tick end -describe('buffer events', function() - it('when you add line to a buffer', function() +describe('API: buffer events:', function() + it('when lines are added', function() local b, tick = editoriginal(true) -- add a new line at the start of the buffer @@ -156,7 +157,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 29, 29, firstfour, false}) -- create a new empty buffer and wipe out the old one ... this will - -- turn off live updates + -- turn off buffer events command('enew!') expectn('nvim_buf_detach_event', {b}) @@ -170,7 +171,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b2, tick, 0, 0, {'new line 1'}, false}) - -- turn off live updates manually + -- turn off buffer events manually buffer('detach', b2) expectn('nvim_buf_detach_event', {b2}) @@ -192,7 +193,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b3, tick, 0, 0, {"New First Line"}, false}) end) - it('knows when you remove lines from a buffer', function() + it('when lines are removed', function() local b, tick = editoriginal(true) -- remove one line from start of file @@ -231,7 +232,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 4, 6, {}, false}) end) - it('knows when you modify lines of text', function() + it('when text is changed', function() local b, tick = editoriginal(true) -- some normal text editing @@ -286,7 +287,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {bnew, tick + 7, 1, 2, {'world'}, false}) end) - it('knows when you replace lines', function() + it('when lines are replaced', function() local b, tick = editoriginal(true) -- blast away parts of some lines with visual mode @@ -311,7 +312,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) end) - it('knows when you filter lines', function() + it('when lines are filtered', function() -- Test filtering lines with !cat local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) @@ -325,7 +326,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 1, 5, {}, false}) end) - it('sends a sensible event when you use "o"', function() + it('when you use "o"', function() local b, tick = editoriginal(true, {'AAA', 'BBB'}) command('set noautoindent nosmartindent') @@ -365,7 +366,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 0, 1, {"\tmmm"}, false}) end) - it('deactivates when your buffer changes outside vim', function() + it('deactivates if the buffer is changed externally', function() -- Test changing file from outside vim and reloading using :edit local lines = {"Line 1", "Line 2"}; local b, tick, filename = editoriginal(true, lines) @@ -380,17 +381,14 @@ describe('buffer events', function() expectn('nvim_buf_changedtick_event', {b, tick}) -- change the file directly - local f = io.open(filename, 'a') - f:write("another line\n") - f:flush() - f:close() + write_file(filename, "another line\n", true, true) - -- reopen the file and watch live updates shut down + -- reopen the file and watch buffer events shut down command('edit') expectn('nvim_buf_detach_event', {b}) end) - it('allows a channel to watch multiple buffers at once', function() + it('channel can watch many buffers at once', function() -- edit 3 buffers, make sure they all have windows visible so that when we -- move between buffers, none of them are unloaded local b1, tick1 = editoriginal(true, {'A1', 'A2'}) @@ -436,12 +434,12 @@ describe('buffer events', function() expectn('nvim_buf_changedtick_event', {b3, tick3}) end) - it('doesn\'t get confused when you turn watching on/off many times', + it('does not get confused if enabled/disabled many times', function() local channel = nvim('get_api_info')[1] local b, tick = editoriginal(false) - -- turn on live updates many times + -- Enable buffer events many times. ok(buffer('attach', b, true, {})) ok(buffer('attach', b, true, {})) ok(buffer('attach', b, true, {})) @@ -451,7 +449,7 @@ describe('buffer events', function() eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) - -- turn live updates off many times + -- Disable buffer events many times. ok(buffer('detach', b)) ok(buffer('detach', b)) ok(buffer('detach', b)) @@ -462,7 +460,7 @@ describe('buffer events', function() expectn('Hello Again', {}) end) - it('is able to notify several channels at once', function() + it('can notify several channels at once', function() helpers.clear() -- create several new sessions, in addition to our main API @@ -486,11 +484,11 @@ describe('buffer events', function() eq({'notification', name, args}, session:next_message()) end - -- edit a new file, but don't turn on live updates + -- Edit a new file, but don't enable buffer events. local lines = {'AAA', 'BBB'} local b, tick = open(false, lines) - -- turn on live updates for sessions 1, 2 and 3 + -- Enable buffer events for sessions 1, 2 and 3. ok(request(1, 'nvim_buf_attach', b, true, {})) ok(request(2, 'nvim_buf_attach', b, true, {})) ok(request(3, 'nvim_buf_attach', b, true, {})) @@ -498,18 +496,18 @@ describe('buffer events', function() wantn(2, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) wantn(3, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) - -- make a change to the buffer + -- Change the buffer. command('normal! x') tick = tick + 1 wantn(1, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) - -- stop watching on channel 1 + -- Stop watching on channel 1. ok(request(1, 'nvim_buf_detach', b)) wantn(1, 'nvim_buf_detach_event', {b}) - -- undo the change to buffer 1 + -- Undo the change to buffer 1. command('undo') tick = tick + 1 wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) @@ -612,7 +610,7 @@ describe('buffer events', function() expectn('nvim_buf_lines_event', {b, tick, 5, 7, {}, false}) end) - it('sends sensible events when you manually add/remove folds', function() + it('when you manually add/remove folds', function() local b = editoriginal(true) local tick = reopenwithfolds(b) @@ -656,11 +654,11 @@ describe('buffer events', function() 'original line 6'}, false}) end) - it('turns off updates when a buffer is closed', function() + it('detaches if the buffer is closed', function() local b, tick = editoriginal(true, {'AAA'}) local channel = nvim('get_api_info')[1] - -- test live updates are working + -- Test that buffer events are working. command('normal! x') tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) @@ -674,7 +672,7 @@ describe('buffer events', function() command('enew') expectn('nvim_buf_detach_event', {b}) - -- reopen the original buffer, make sure there are no Live Updates sent + -- Reopen the original buffer, make sure there are no buffer events sent. command('b1') command('normal! x') @@ -682,12 +680,11 @@ describe('buffer events', function() expectn('Hello There', {}) end) - -- test what happens when a buffer is hidden - it('keeps updates turned on if the buffer is hidden', function() + it('stays attached if the buffer is hidden', function() local b, tick = editoriginal(true, {'AAA'}) local channel = nvim('get_api_info')[1] - -- test live updates are working + -- Test that buffer events are working. command('normal! x') tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) @@ -697,22 +694,22 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_changedtick_event', {b, tick}) - -- close our buffer by creating a new one + -- Close our buffer by creating a new one. command('set hidden') command('enew') - -- note that no nvim_buf_detach_event is sent + -- Assert that no nvim_buf_detach_event is sent. eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) - -- reopen the original buffer, make sure Live Updates are still active + -- Reopen the original buffer, assert that buffer events are still active. command('b1') command('normal! x') tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) end) - it('turns off live updates when a buffer is unloaded, deleted, or wiped', + it('detaches if the buffer is unloaded/deleted/wiped', function() -- start with a blank nvim helpers.clear() @@ -730,7 +727,7 @@ describe('buffer events', function() end end) - it('doesn\'t send the buffer\'s content when not requested', function() + it('does not send the buffer content if not requested', function() helpers.clear() local b, tick = editoriginal(false) ok(buffer('attach', b, false, {})) |