From 79184809bb10b738c05c29a973d09bd65798b168 Mon Sep 17 00:00:00 2001 From: Peter Hodge Date: Fri, 26 Jan 2018 20:38:05 +0100 Subject: Tests for buffer updates Originally written by @phodge in https://github.com/neovim/neovim/pull/5269. --- test/functional/api/liveupdate_spec.lua | 734 ++++++++++++++++++++++++++++++++ 1 file changed, 734 insertions(+) create mode 100644 test/functional/api/liveupdate_spec.lua (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua new file mode 100644 index 0000000000..d6f1b2e384 --- /dev/null +++ b/test/functional/api/liveupdate_spec.lua @@ -0,0 +1,734 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq, ok = helpers.eq, helpers.ok +local buffer, command, eval, nvim, next_message = helpers.buffer, + helpers.command, helpers.eval, helpers.nvim, helpers.next_message + +local origlines = {"original line 1", + "original line 2", + "original line 3", + "original line 4", + "original line 5", + "original line 6"} + +function sendkeys(keys) + nvim('input', keys) + -- give neovim 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.01 + repeat until os.clock() > ntime +end + +function editoriginal(activate, lines) + if not lines then + lines = origlines + end + -- load up the file with the correct contents + helpers.clear() + return open(activate, lines) +end + +function open(activate, lines) + local filename = helpers.tmpname() + helpers.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 LiveUpdateStart messages + -- arrive as expectected + if activate then + ok(buffer('live_updates', b, true)) + expectn('LiveUpdateStart', {b, tick, lines, false}) + end + + return b, tick, filename +end + +function reopen(buf, expectedlines) + ok(buffer('live_updates', buf, false)) + expectn('LiveUpdateEnd', {buf}) + -- for some reason the :edit! increments tick by 2 + command('edit!') + local tick = eval('b:changedtick') + ok(buffer('live_updates', buf, true)) + expectn('LiveUpdateStart', {buf, tick, origlines, false}) + command('normal! gg') + return tick +end + +function expectn(name, args) + -- expect the next message to be the specified notification event + eq({'notification', name, args}, next_message()) +end + +function reopenwithfolds(b) + -- discard any changes to the buffer + local tick = reopen(b, origlines) + + -- use markers for folds, make all folds open by default + command('setlocal foldmethod=marker foldlevel=20') + + -- add a fold + command('2,4fold') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 3, {'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/'}}) + -- make a new fold that wraps lines 1-6 + command('1,6fold') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 6, {'original line 1/*{{{*/', + 'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/', + 'original line 5', + 'original line 6/*}}}*/'}}) + return tick +end + +describe('liveupdate', function() + it('knows when you add line to a buffer', function() + local b, tick = editoriginal(true) + + -- add a new line at the start of the buffer + command('normal! GyyggP') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 0, {'original line 6'}}) + + -- add multiple lines at the start of the file + command('normal! GkkyGggP') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 0, {'original line 4', + 'original line 5', + 'original line 6'}}) + + -- add one line to the middle of the file, several times + command('normal! ggYjjp') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 0, {'original line 4'}}) + command('normal! p') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 4, 0, {'original line 4'}}) + command('normal! p') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 5, 0, {'original line 4'}}) + + -- add multiple lines to the middle of the file + command('normal! gg4Yjjp') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 0, {'original line 4', + 'original line 5', + 'original line 6', + 'original line 4'}}) + + -- add one line to the end of the file + command('normal! ggYGp') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 17, 0, {'original line 4'}}) + + -- add one line to the end of the file, several times + command('normal! ggYGppp') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 18, 0, {'original line 4'}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 19, 0, {'original line 4'}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 20, 0, {'original line 4'}}) + + -- add several lines to the end of the file, several times + command('normal! gg4YGp') + command('normal! Gp') + command('normal! Gp') + firstfour = {'original line 4', + 'original line 5', + 'original line 6', + 'original line 4'} + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 21, 0, firstfour}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 25, 0, firstfour}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 29, 0, firstfour}) + + -- create a new empty buffer and wipe out the old one ... this will + -- turn off live updates + command('enew!') + expectn('LiveUpdateEnd', {b}) + + -- add a line at the start of an empty file + command('enew') + local tick = eval('b:changedtick') + b2 = nvim('get_current_buf') + ok(buffer('live_updates', b2, true)) + expectn('LiveUpdateStart', {b2, tick, {""}, false}) + eval('append(0, ["new line 1"])') + tick = tick + 1 + expectn('LiveUpdate', {b2, tick, 0, 0, {'new line 1'}}) + + -- turn off live updates manually + buffer('live_updates', b2, false) + expectn('LiveUpdateEnd', {b2}) + + -- add multiple lines to a blank file + command('enew!') + b3 = nvim('get_current_buf') + ok(buffer('live_updates', b3, true)) + tick = eval('b:changedtick') + expectn('LiveUpdateStart', {b3, tick, {""}, false}) + eval('append(0, ["new line 1", "new line 2", "new line 3"])') + tick = tick + 1 + expectn('LiveUpdate', {b3, tick, 0, 0, {'new line 1', + 'new line 2', + 'new line 3'}}) + + -- use the API itself to add a line to the start of the buffer + buffer('set_lines', b3, 0, 0, true, {'New First Line'}) + tick = tick + 1 + expectn('LiveUpdate', {b3, tick, 0, 0, {"New First Line"}}) + end) + + it('knows when you remove lines from a buffer', function() + local b, tick = editoriginal(true) + + -- remove one line from start of file + command('normal! dd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {}}) + + -- remove multiple lines from the start of the file + command('normal! 4dd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 4, {}}) + + -- remove multiple lines from middle of file + tick = reopen(b, origlines) + command('normal! jj3dd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 3, {}}) + + -- remove one line from the end of the file + tick = reopen(b, origlines) + command('normal! Gdd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 5, 1, {}}) + + -- remove multiple lines from the end of the file + tick = reopen(b, origlines) + command('normal! 4G3dd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 3, {}}) + + -- pretend to remove heaps lines from the end of the file but really + -- just remove two + tick = reopen(b, origlines) + command('normal! Gk5dd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 4, 2, {}}) + end) + + it('knows when you modify lines of text', function() + local b, tick = editoriginal(true) + local channel = nvim('get_api_info')[1] + + -- some normal text editing + command('normal! A555') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'original line 1555'}}) + command('normal! jj8X') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 1, {'origin3'}}) + + -- modify multiple lines at once using visual block mode + tick = reopen(b, origlines) + command('normal! jjw') + sendkeys('\x16jjllx') + tick = tick + 1 + expectn('LiveUpdate', + {b, tick, 2, 3, {'original e 3', 'original e 4', 'original e 5'}}) + + -- replace part of a line line using :s + tick = reopen(b, origlines) + command('3s/line 3/foo/') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 1, {'original foo'}}) + + -- replace parts of several lines line using :s + tick = reopen(b, origlines) + command('%s/line [35]/foo/') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 3, {'original foo', + 'original line 4', + 'original foo'}}) + + -- type text into the first line of a blank file, one character at a time + command('enew!') + tick = 2 + expectn('LiveUpdateEnd', {b}) + bnew = nvim('get_current_buf') + ok(buffer('live_updates', bnew, true)) + expectn('LiveUpdateStart', {bnew, tick, {''}, false}) + sendkeys('i') + sendkeys('h') + sendkeys('e') + sendkeys('l') + sendkeys('l') + sendkeys('o\nworld') + expectn('LiveUpdate', {bnew, tick + 1, 0, 1, {'h'}}) + expectn('LiveUpdate', {bnew, tick + 2, 0, 1, {'he'}}) + expectn('LiveUpdate', {bnew, tick + 3, 0, 1, {'hel'}}) + expectn('LiveUpdate', {bnew, tick + 4, 0, 1, {'hell'}}) + expectn('LiveUpdate', {bnew, tick + 5, 0, 1, {'hello'}}) + expectn('LiveUpdate', {bnew, tick + 6, 0, 1, {'hello', ''}}) + expectn('LiveUpdate', {bnew, tick + 7, 1, 1, {'world'}}) + end) + + it('knows when you replace lines', function() + local b, tick = editoriginal(true) + + -- blast away parts of some lines with visual mode + command('normal! jjwvjjllx') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 1, {'original '}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 1, {}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 1, {'e 5'}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 1, {'original e 5'}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 1, {}}) + + -- blast away a few lines using :g + tick = reopen(b, origlines) + command('global/line [35]/delete') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 2, 1, {}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 1, {}}) + end) + + it('knows when you filter lines', function() + -- Test filtering lines with !sort + local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) + + command('silent 2,5!sort') + -- the change comes through as two changes: + -- 1) addition of the new lines after the filtered lines + -- 2) removal of the original lines + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 5, 0, {"B", "C", "D", "E"}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 4, {}}) + end) + + it('sends a sensible event when you use "o"', function() + b, tick = editoriginal(true, {'AAA', 'BBB'}) + command('set noautoindent nosmartindent') + + -- use 'o' to start a new line from a line with no indent + command('normal! o') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 0, {""}}) + + -- undo the change, indent line 1 a bit, and try again + command('undo') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 1, {}}) + tick = tick + 1 + expectn('LiveUpdateTick', {b, tick}) + command('set autoindent') + command('normal! >>') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {"\tAAA"}}) + command('normal! ommm') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 0, {"\t"}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 1, {"\tmmm"}}) + + -- undo the change, and try again with 'O' + command('undo') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 1, {'\t'}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 1, {}}) + tick = tick + 1 + expectn('LiveUpdateTick', {b, tick}) + command('normal! ggOmmm') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 0, {"\t"}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {"\tmmm"}}) + end) + + it('deactivates when your buffer changes outside vim', function() + -- Test changing file from outside vim and reloading using :edit + local lines = {"Line 1", "Line 2"}; + local b, tick, filename = editoriginal(true, lines) + + command('normal! x') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'ine 1'}}) + command('undo') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'Line 1'}}) + tick = tick + 1 + expectn('LiveUpdateTick', {b, tick}) + + -- change the file directly + local f = io.open(filename, 'a') + f:write("another line\n") + f:flush() + f:close() + + -- reopen the file and watch live updates shut down + command('edit') + expectn('LiveUpdateEnd', {b}) + end) + + it('allows a channel to watch multiple 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 + b1, tick1, f1 = editoriginal(true, {'A1', 'A2'}) + b1nr = eval('bufnr("")') + command('split') + b2, tick2, f2 = open(true, {'B1', 'B2'}) + b2nr = eval('bufnr("")') + command('split') + b3, tick3, f3 = open(true, {'C1', 'C2'}) + b3nr = eval('bufnr("")') + + -- make a new window for moving between buffers + command('split') + + command('b'..b1nr) + command('normal! x') + tick1 = tick1 + 1 + expectn('LiveUpdate', {b1, tick1, 0, 1, {'1'}}) + command('undo') + tick1 = tick1 + 1 + expectn('LiveUpdate', {b1, tick1, 0, 1, {'A1'}}) + tick1 = tick1 + 1 + expectn('LiveUpdateTick', {b1, tick1}) + + command('b'..b2nr) + command('normal! x') + tick2 = tick2 + 1 + expectn('LiveUpdate', {b2, tick2, 0, 1, {'1'}}) + command('undo') + tick2 = tick2 + 1 + expectn('LiveUpdate', {b2, tick2, 0, 1, {'B1'}}) + tick2 = tick2 + 1 + expectn('LiveUpdateTick', {b2, tick2}) + + command('b'..b3nr) + command('normal! x') + tick3 = tick3 + 1 + expectn('LiveUpdate', {b3, tick3, 0, 1, {'1'}}) + command('undo') + tick3 = tick3 + 1 + expectn('LiveUpdate', {b3, tick3, 0, 1, {'C1'}}) + tick3 = tick3 + 1 + expectn('LiveUpdateTick', {b3, tick3}) + end) + + it('doesn\'t get confused when you turn watching on/off many times', + function() + local channel = nvim('get_api_info')[1] + local b, tick = editoriginal(false) + + -- turn on live updates many times + ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true)) + expectn('LiveUpdateStart', {b, tick, origlines, false}) + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + + -- turn live updates off many times + ok(buffer('live_updates', b, false)) + ok(buffer('live_updates', b, false)) + ok(buffer('live_updates', b, false)) + ok(buffer('live_updates', b, false)) + ok(buffer('live_updates', b, false)) + expectn('LiveUpdateEnd', {b}) + eval('rpcnotify('..channel..', "Hello Again")') + expectn('Hello Again', {}) + end) + + it('is able to notify several channels at once', function() + helpers.clear() + + local addsession = function(where) + eval('serverstart("'..where..'")') + local session = helpers.connect(where) + return session + end + + -- create several new sessions, in addition to our main API + sessions = {} + sessions[1] = addsession(helpers.tmpname()..'.1') + sessions[2] = addsession(helpers.tmpname()..'.2') + sessions[3] = addsession(helpers.tmpname()..'.3') + + function request(sessionnr, method, ...) + local status, rv = sessions[sessionnr]:request(method, ...) + if not status then + error(rv[2]) + end + return rv + end + + function wantn(sessionid, name, args) + local session = sessions[sessionid] + eq({'notification', name, args}, session:next_message()) + end + + -- edit a new file, but don't turn on live updates + local lines = {'AAA', 'BBB'} + local b, tick = open(false, lines) + + -- turn on live updates for sessions 1, 2 and 3 + ok(request(1, 'nvim_buf_live_updates', b, true)) + ok(request(2, 'nvim_buf_live_updates', b, true)) + ok(request(3, 'nvim_buf_live_updates', b, true)) + wantn(1, 'LiveUpdateStart', {b, tick, lines, false}) + wantn(2, 'LiveUpdateStart', {b, tick, lines, false}) + wantn(3, 'LiveUpdateStart', {b, tick, lines, false}) + + -- make a change to the buffer + command('normal! x') + tick = tick + 1 + wantn(1, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) + wantn(2, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) + wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) + + -- stop watching on channel 1 + ok(request(1, 'nvim_buf_live_updates', b, false)) + wantn(1, 'LiveUpdateEnd', {b}) + + -- undo the change to buffer 1 + command('undo') + tick = tick + 1 + wantn(2, 'LiveUpdate', {b, tick, 0, 1, {'AAA'}}) + wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + wantn(2, 'LiveUpdateTick', {b, tick}) + wantn(3, 'LiveUpdateTick', {b, tick}) + + -- make sure there are no other pending LiveUpdate messages going to + -- channel 1 + local channel1 = request(1, 'nvim_get_api_info')[1] + eval('rpcnotify('..channel1..', "Hello")') + wantn(1, 'Hello', {}) + + -- close the buffer and channels 2 and 3 should get a LiveUpdateEnd + -- notification + command('edit') + wantn(2, 'LiveUpdateEnd', {b}) + wantn(3, 'LiveUpdateEnd', {b}) + + -- make sure there are no other pending LiveUpdate messages going to + -- channel 1 + local channel1 = request(1, 'nvim_get_api_info')[1] + eval('rpcnotify('..channel1..', "Hello Again")') + wantn(1, 'Hello Again', {}) + end) + + it('works with :diffput and :diffget', function() + local b1, tick1 = editoriginal(true, {"AAA", "BBB"}) + local channel = nvim('get_api_info')[1] + command('diffthis') + command('rightbelow vsplit') + local b2, tick2 = open(true, {"BBB", "CCC"}) + command('diffthis') + -- go back to first buffer, and push the 'AAA' line to the second buffer + command('1wincmd w') + command('normal! gg') + command('diffput') + tick2 = tick2 + 1 + expectn('LiveUpdate', {b2, tick2, 0, 0, {"AAA"}}) + + -- use :diffget to grab the other change from buffer 2 + command('normal! G') + command('diffget') + tick1 = tick1 + 1 + expectn('LiveUpdate', {b1, tick1, 2, 0, {"CCC"}}) + + eval('rpcnotify('..channel..', "Goodbye")') + expectn('Goodbye', {}) + end) + + it('works with :sort', function() + -- test for :sort + local b, tick = editoriginal(true, {"B", "D", "C", "A", "E"}) + command('%sort') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}}) + end) + + it('works with :left', function() + local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) + local channel = nvim('get_api_info')[1] + command('2,4left') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 3, {"B", "B", "B"}}) + end) + + it('works with :right', function() + local b, tick = editoriginal(true, {" A", + "\t B", + "\t \tBB", + " \tB", + "\t\tC"}) + local channel = nvim('get_api_info')[1] + command('set ts=2 et') + command('2,4retab') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 3, {" B", " BB", " B"}}) + end) + + it('works with :move', function() + local b, tick = editoriginal(true, origlines) + local channel = nvim('get_api_info')[1] + -- move text down towards the end of the file + command('2,3move 4') + tick = tick + 2 + expectn('LiveUpdate', {b, tick, 4, 0, {"original line 2", + "original line 3"}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 2, {}}) + + -- move text up towards the start of the file + tick = reopen(b, origlines) + command('4,5move 2') + tick = tick + 2 + expectn('LiveUpdate', {b, tick, 2, 0, {"original line 4", + "original line 5"}}) + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 5, 2, {}}) + end) + + it('sends sensible events when you manually add/remove folds', function() + local b, tick = editoriginal(true) + local channel = nvim('get_api_info')[1] + tick = reopenwithfolds(b) + + -- delete the inner fold + command('normal! zR3Gzd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 1, 3, {'original line 2', + 'original line 3', + 'original line 4'}}) + -- delete the outer fold + command('normal! zd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 6, origlines}) + + -- discard changes and put the folds back + tick = reopenwithfolds(b) + + -- remove both folds at once + command('normal! ggzczD') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 6, origlines}) + + -- discard changes and put the folds back + tick = reopenwithfolds(b) + + -- now delete all folds at once + command('normal! zE') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 6, origlines}) + + -- create a fold from line 4 to the end of the file + command('normal! 4GA/*{{{*/') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 1, {'original line 4/*{{{*/'}}) + + -- delete the fold which only has one marker + command('normal! Gzd') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4', + 'original line 5', + 'original line 6'}}) + end) + + it('turns off updates when a buffer is closed', function() + local b, tick = editoriginal(true, {'AAA'}) + local channel = nvim('get_api_info')[1] + + -- test live updates are working + command('normal! x') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) + command('undo') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + expectn('LiveUpdateTick', {b, tick}) + + -- close our buffer by creating a new one + command('enew') + expectn('LiveUpdateEnd', {b}) + + -- reopen the original buffer, make sure there are no Live Updates sent + command('b1') + command('normal! x') + + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + end) + + -- test what happens when a buffer is hidden + it('keeps updates turned on if the buffer is hidden', function() + local b, tick = editoriginal(true, {'AAA'}) + local channel = nvim('get_api_info')[1] + + -- test live updates are working + command('normal! x') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) + command('undo') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + expectn('LiveUpdateTick', {b, tick}) + + -- close our buffer by creating a new one + command('set hidden') + command('enew') + + -- note that no LiveUpdateEnd is sent + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + + -- reopen the original buffer, make sure Live Updates are still active + command('b1') + command('normal! x') + tick = tick + 1 + expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) + end) + + it('turns off live updates when a buffer is unloaded, deleted, or wiped', + function() + -- start with a blank nvim + helpers.clear() + -- need to make a new window with a buffer because :bunload doesn't let you + -- unload the last buffer + for i, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do + command('new') + -- open a brand spanking new file + local b, filename = open(true, {'AAA'}) + + -- call :bunload or whatever the command is, and then check that we + -- receive a LiveUpdateEnd + command(cmd) + expectn('LiveUpdateEnd', {b}) + end + end) +end) -- cgit From bafae1c427cb1eeb52e4caa641ad134c1e062e8e Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 15:49:35 +0100 Subject: Add argument to not send a buffers content when updates are enabled Add a test. --- test/functional/api/liveupdate_spec.lua | 50 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua index d6f1b2e384..6f83a3e904 100644 --- a/test/functional/api/liveupdate_spec.lua +++ b/test/functional/api/liveupdate_spec.lua @@ -39,7 +39,7 @@ function open(activate, lines) -- turn on live updates, ensure that the LiveUpdateStart messages -- arrive as expectected if activate then - ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true, true)) expectn('LiveUpdateStart', {b, tick, lines, false}) end @@ -47,12 +47,12 @@ function open(activate, lines) end function reopen(buf, expectedlines) - ok(buffer('live_updates', buf, false)) + ok(buffer('live_updates', buf, false, true)) expectn('LiveUpdateEnd', {buf}) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') - ok(buffer('live_updates', buf, true)) + ok(buffer('live_updates', buf, true, true)) expectn('LiveUpdateStart', {buf, tick, origlines, false}) command('normal! gg') return tick @@ -161,20 +161,20 @@ describe('liveupdate', function() command('enew') local tick = eval('b:changedtick') b2 = nvim('get_current_buf') - ok(buffer('live_updates', b2, true)) + ok(buffer('live_updates', b2, true, true)) expectn('LiveUpdateStart', {b2, tick, {""}, false}) eval('append(0, ["new line 1"])') tick = tick + 1 expectn('LiveUpdate', {b2, tick, 0, 0, {'new line 1'}}) -- turn off live updates manually - buffer('live_updates', b2, false) + buffer('live_updates', b2, false, true) expectn('LiveUpdateEnd', {b2}) -- add multiple lines to a blank file command('enew!') b3 = nvim('get_current_buf') - ok(buffer('live_updates', b3, true)) + ok(buffer('live_updates', b3, true, true)) tick = eval('b:changedtick') expectn('LiveUpdateStart', {b3, tick, {""}, false}) eval('append(0, ["new line 1", "new line 2", "new line 3"])') @@ -267,7 +267,7 @@ describe('liveupdate', function() tick = 2 expectn('LiveUpdateEnd', {b}) bnew = nvim('get_current_buf') - ok(buffer('live_updates', bnew, true)) + ok(buffer('live_updates', bnew, true, true)) expectn('LiveUpdateStart', {bnew, tick, {''}, false}) sendkeys('i') sendkeys('h') @@ -440,21 +440,21 @@ describe('liveupdate', function() local b, tick = editoriginal(false) -- turn on live updates many times - ok(buffer('live_updates', b, true)) - ok(buffer('live_updates', b, true)) - ok(buffer('live_updates', b, true)) - ok(buffer('live_updates', b, true)) - ok(buffer('live_updates', b, true)) + ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates', b, true, true)) expectn('LiveUpdateStart', {b, tick, origlines, false}) eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) -- turn live updates off many times - ok(buffer('live_updates', b, false)) - ok(buffer('live_updates', b, false)) - ok(buffer('live_updates', b, false)) - ok(buffer('live_updates', b, false)) - ok(buffer('live_updates', b, false)) + ok(buffer('live_updates', b, false, true)) + ok(buffer('live_updates', b, false, true)) + ok(buffer('live_updates', b, false, true)) + ok(buffer('live_updates', b, false, true)) + ok(buffer('live_updates', b, false, true)) expectn('LiveUpdateEnd', {b}) eval('rpcnotify('..channel..', "Hello Again")') expectn('Hello Again', {}) @@ -493,9 +493,9 @@ describe('liveupdate', function() local b, tick = open(false, lines) -- turn on live updates for sessions 1, 2 and 3 - ok(request(1, 'nvim_buf_live_updates', b, true)) - ok(request(2, 'nvim_buf_live_updates', b, true)) - ok(request(3, 'nvim_buf_live_updates', b, true)) + ok(request(1, 'nvim_buf_live_updates', b, true, true)) + ok(request(2, 'nvim_buf_live_updates', b, true, true)) + ok(request(3, 'nvim_buf_live_updates', b, true, true)) wantn(1, 'LiveUpdateStart', {b, tick, lines, false}) wantn(2, 'LiveUpdateStart', {b, tick, lines, false}) wantn(3, 'LiveUpdateStart', {b, tick, lines, false}) @@ -508,7 +508,7 @@ describe('liveupdate', function() wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) -- stop watching on channel 1 - ok(request(1, 'nvim_buf_live_updates', b, false)) + ok(request(1, 'nvim_buf_live_updates', b, false, true)) wantn(1, 'LiveUpdateEnd', {b}) -- undo the change to buffer 1 @@ -731,4 +731,12 @@ describe('liveupdate', function() expectn('LiveUpdateEnd', {b}) end end) + + it('doesn\'t send the buffer\'s content when not requested', function() + helpers.clear() + local b, tick = editoriginal(false) + ok(buffer('live_updates', b, true, false)) + expectn('LiveUpdateStart', {b, tick, {}, false}) + end) + end) -- cgit From 8bcc01195968b84d1a74ecb82598bdf538004404 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 17:42:51 +0100 Subject: Make separate functions to start/stop live updates --- test/functional/api/liveupdate_spec.lua | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua index 6f83a3e904..9e071ccaa6 100644 --- a/test/functional/api/liveupdate_spec.lua +++ b/test/functional/api/liveupdate_spec.lua @@ -39,7 +39,7 @@ function open(activate, lines) -- turn on live updates, ensure that the LiveUpdateStart messages -- arrive as expectected if activate then - ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates_start', b, true)) expectn('LiveUpdateStart', {b, tick, lines, false}) end @@ -47,12 +47,12 @@ function open(activate, lines) end function reopen(buf, expectedlines) - ok(buffer('live_updates', buf, false, true)) + ok(buffer('live_updates_stop', buf)) expectn('LiveUpdateEnd', {buf}) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') - ok(buffer('live_updates', buf, true, true)) + ok(buffer('live_updates_start', buf, true)) expectn('LiveUpdateStart', {buf, tick, origlines, false}) command('normal! gg') return tick @@ -161,20 +161,20 @@ describe('liveupdate', function() command('enew') local tick = eval('b:changedtick') b2 = nvim('get_current_buf') - ok(buffer('live_updates', b2, true, true)) + ok(buffer('live_updates_start', b2, true)) expectn('LiveUpdateStart', {b2, tick, {""}, false}) eval('append(0, ["new line 1"])') tick = tick + 1 expectn('LiveUpdate', {b2, tick, 0, 0, {'new line 1'}}) -- turn off live updates manually - buffer('live_updates', b2, false, true) + buffer('live_updates_stop', b2) expectn('LiveUpdateEnd', {b2}) -- add multiple lines to a blank file command('enew!') b3 = nvim('get_current_buf') - ok(buffer('live_updates', b3, true, true)) + ok(buffer('live_updates_start', b3, true)) tick = eval('b:changedtick') expectn('LiveUpdateStart', {b3, tick, {""}, false}) eval('append(0, ["new line 1", "new line 2", "new line 3"])') @@ -267,7 +267,7 @@ describe('liveupdate', function() tick = 2 expectn('LiveUpdateEnd', {b}) bnew = nvim('get_current_buf') - ok(buffer('live_updates', bnew, true, true)) + ok(buffer('live_updates_start', bnew, true)) expectn('LiveUpdateStart', {bnew, tick, {''}, false}) sendkeys('i') sendkeys('h') @@ -440,21 +440,21 @@ describe('liveupdate', function() local b, tick = editoriginal(false) -- turn on live updates many times - ok(buffer('live_updates', b, true, true)) - ok(buffer('live_updates', b, true, true)) - ok(buffer('live_updates', b, true, true)) - ok(buffer('live_updates', b, true, true)) - ok(buffer('live_updates', b, true, true)) + ok(buffer('live_updates_start', b, true)) + ok(buffer('live_updates_start', b, true)) + ok(buffer('live_updates_start', b, true)) + ok(buffer('live_updates_start', b, true)) + ok(buffer('live_updates_start', b, true)) expectn('LiveUpdateStart', {b, tick, origlines, false}) eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) -- turn live updates off many times - ok(buffer('live_updates', b, false, true)) - ok(buffer('live_updates', b, false, true)) - ok(buffer('live_updates', b, false, true)) - ok(buffer('live_updates', b, false, true)) - ok(buffer('live_updates', b, false, true)) + ok(buffer('live_updates_stop', b)) + ok(buffer('live_updates_stop', b)) + ok(buffer('live_updates_stop', b)) + ok(buffer('live_updates_stop', b)) + ok(buffer('live_updates_stop', b)) expectn('LiveUpdateEnd', {b}) eval('rpcnotify('..channel..', "Hello Again")') expectn('Hello Again', {}) @@ -493,9 +493,9 @@ describe('liveupdate', function() local b, tick = open(false, lines) -- turn on live updates for sessions 1, 2 and 3 - ok(request(1, 'nvim_buf_live_updates', b, true, true)) - ok(request(2, 'nvim_buf_live_updates', b, true, true)) - ok(request(3, 'nvim_buf_live_updates', b, true, true)) + ok(request(1, 'nvim_buf_live_updates_start', b, true)) + ok(request(2, 'nvim_buf_live_updates_start', b, true)) + ok(request(3, 'nvim_buf_live_updates_start', b, true)) wantn(1, 'LiveUpdateStart', {b, tick, lines, false}) wantn(2, 'LiveUpdateStart', {b, tick, lines, false}) wantn(3, 'LiveUpdateStart', {b, tick, lines, false}) @@ -508,7 +508,7 @@ describe('liveupdate', function() wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) -- stop watching on channel 1 - ok(request(1, 'nvim_buf_live_updates', b, false, true)) + ok(request(1, 'nvim_buf_live_updates_stop', b)) wantn(1, 'LiveUpdateEnd', {b}) -- undo the change to buffer 1 @@ -735,7 +735,7 @@ describe('liveupdate', function() it('doesn\'t send the buffer\'s content when not requested', function() helpers.clear() local b, tick = editoriginal(false) - ok(buffer('live_updates', b, true, false)) + ok(buffer('live_updates_start', b, false)) expectn('LiveUpdateStart', {b, tick, {}, false}) end) -- cgit From 37b8e95fd69ba4991454f79802bfe1bccf7c827a Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 20:25:53 +0100 Subject: Lint --- test/functional/api/liveupdate_spec.lua | 85 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 45 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua index 9e071ccaa6..ba98aa60c8 100644 --- a/test/functional/api/liveupdate_spec.lua +++ b/test/functional/api/liveupdate_spec.lua @@ -10,7 +10,12 @@ local origlines = {"original line 1", "original line 5", "original line 6"} -function sendkeys(keys) +local function expectn(name, args) + -- expect the next message to be the specified notification event + eq({'notification', name, args}, next_message()) +end + +local function sendkeys(keys) nvim('input', keys) -- give neovim some time to process msgpack requests before possibly sending -- more key presses - otherwise they all pile up in the queue and get @@ -19,16 +24,7 @@ function sendkeys(keys) repeat until os.clock() > ntime end -function editoriginal(activate, lines) - if not lines then - lines = origlines - end - -- load up the file with the correct contents - helpers.clear() - return open(activate, lines) -end - -function open(activate, lines) +local function open(activate, lines) local filename = helpers.tmpname() helpers.write_file(filename, table.concat(lines, "\n").."\n", true) command('edit ' .. filename) @@ -46,24 +42,28 @@ function open(activate, lines) return b, tick, filename end -function reopen(buf, expectedlines) +local function editoriginal(activate, lines) + if not lines then + lines = origlines + end + -- load up the file with the correct contents + helpers.clear() + return open(activate, lines) +end + +local function reopen(buf, expectedlines) ok(buffer('live_updates_stop', buf)) expectn('LiveUpdateEnd', {buf}) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') ok(buffer('live_updates_start', buf, true)) - expectn('LiveUpdateStart', {buf, tick, origlines, false}) + expectn('LiveUpdateStart', {buf, tick, expectedlines, false}) command('normal! gg') return tick end -function expectn(name, args) - -- expect the next message to be the specified notification event - eq({'notification', name, args}, next_message()) -end - -function reopenwithfolds(b) +local function reopenwithfolds(b) -- discard any changes to the buffer local tick = reopen(b, origlines) @@ -141,7 +141,7 @@ describe('liveupdate', function() command('normal! gg4YGp') command('normal! Gp') command('normal! Gp') - firstfour = {'original line 4', + local firstfour = {'original line 4', 'original line 5', 'original line 6', 'original line 4'} @@ -159,8 +159,8 @@ describe('liveupdate', function() -- add a line at the start of an empty file command('enew') - local tick = eval('b:changedtick') - b2 = nvim('get_current_buf') + tick = eval('b:changedtick') + local b2 = nvim('get_current_buf') ok(buffer('live_updates_start', b2, true)) expectn('LiveUpdateStart', {b2, tick, {""}, false}) eval('append(0, ["new line 1"])') @@ -173,7 +173,7 @@ describe('liveupdate', function() -- add multiple lines to a blank file command('enew!') - b3 = nvim('get_current_buf') + local b3 = nvim('get_current_buf') ok(buffer('live_updates_start', b3, true)) tick = eval('b:changedtick') expectn('LiveUpdateStart', {b3, tick, {""}, false}) @@ -230,7 +230,6 @@ describe('liveupdate', function() it('knows when you modify lines of text', function() local b, tick = editoriginal(true) - local channel = nvim('get_api_info')[1] -- some normal text editing command('normal! A555') @@ -266,7 +265,7 @@ describe('liveupdate', function() command('enew!') tick = 2 expectn('LiveUpdateEnd', {b}) - bnew = nvim('get_current_buf') + local bnew = nvim('get_current_buf') ok(buffer('live_updates_start', bnew, true)) expectn('LiveUpdateStart', {bnew, tick, {''}, false}) sendkeys('i') @@ -324,7 +323,7 @@ describe('liveupdate', function() end) it('sends a sensible event when you use "o"', function() - b, tick = editoriginal(true, {'AAA', 'BBB'}) + local b, tick = editoriginal(true, {'AAA', 'BBB'}) command('set noautoindent nosmartindent') -- use 'o' to start a new line from a line with no indent @@ -391,14 +390,14 @@ describe('liveupdate', function() it('allows a channel to watch multiple 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 - b1, tick1, f1 = editoriginal(true, {'A1', 'A2'}) - b1nr = eval('bufnr("")') + local b1, tick1 = editoriginal(true, {'A1', 'A2'}) + local b1nr = eval('bufnr("")') command('split') - b2, tick2, f2 = open(true, {'B1', 'B2'}) - b2nr = eval('bufnr("")') + local b2, tick2 = open(true, {'B1', 'B2'}) + local b2nr = eval('bufnr("")') command('split') - b3, tick3, f3 = open(true, {'C1', 'C2'}) - b3nr = eval('bufnr("")') + local b3, tick3 = open(true, {'C1', 'C2'}) + local b3nr = eval('bufnr("")') -- make a new window for moving between buffers command('split') @@ -470,12 +469,12 @@ describe('liveupdate', function() end -- create several new sessions, in addition to our main API - sessions = {} + local sessions = {} sessions[1] = addsession(helpers.tmpname()..'.1') sessions[2] = addsession(helpers.tmpname()..'.2') sessions[3] = addsession(helpers.tmpname()..'.3') - function request(sessionnr, method, ...) + local function request(sessionnr, method, ...) local status, rv = sessions[sessionnr]:request(method, ...) if not status then error(rv[2]) @@ -483,7 +482,7 @@ describe('liveupdate', function() return rv end - function wantn(sessionid, name, args) + local function wantn(sessionid, name, args) local session = sessions[sessionid] eq({'notification', name, args}, session:next_message()) end @@ -534,7 +533,7 @@ describe('liveupdate', function() -- make sure there are no other pending LiveUpdate messages going to -- channel 1 - local channel1 = request(1, 'nvim_get_api_info')[1] + channel1 = request(1, 'nvim_get_api_info')[1] eval('rpcnotify('..channel1..', "Hello Again")') wantn(1, 'Hello Again', {}) end) @@ -573,7 +572,6 @@ describe('liveupdate', function() it('works with :left', function() local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) - local channel = nvim('get_api_info')[1] command('2,4left') tick = tick + 1 expectn('LiveUpdate', {b, tick, 1, 3, {"B", "B", "B"}}) @@ -585,7 +583,6 @@ describe('liveupdate', function() "\t \tBB", " \tB", "\t\tC"}) - local channel = nvim('get_api_info')[1] command('set ts=2 et') command('2,4retab') tick = tick + 1 @@ -594,7 +591,6 @@ describe('liveupdate', function() it('works with :move', function() local b, tick = editoriginal(true, origlines) - local channel = nvim('get_api_info')[1] -- move text down towards the end of the file command('2,3move 4') tick = tick + 2 @@ -614,9 +610,8 @@ describe('liveupdate', function() end) it('sends sensible events when you manually add/remove folds', function() - local b, tick = editoriginal(true) - local channel = nvim('get_api_info')[1] - tick = reopenwithfolds(b) + local b = editoriginal(true) + local tick = reopenwithfolds(b) -- delete the inner fold command('normal! zR3Gzd') @@ -683,7 +678,7 @@ describe('liveupdate', function() eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) end) - + -- test what happens when a buffer is hidden it('keeps updates turned on if the buffer is hidden', function() local b, tick = editoriginal(true, {'AAA'}) @@ -720,10 +715,10 @@ describe('liveupdate', function() helpers.clear() -- need to make a new window with a buffer because :bunload doesn't let you -- unload the last buffer - for i, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do + for _, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do command('new') -- open a brand spanking new file - local b, filename = open(true, {'AAA'}) + local b = open(true, {'AAA'}) -- call :bunload or whatever the command is, and then check that we -- receive a LiveUpdateEnd -- cgit From 0476e0aef3a82879961acd515b8587fc1b941597 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 27 Jan 2018 14:49:16 +0100 Subject: Make LiveUpdate return lastline instead of numreplaced In analogy to `nvim_buf_set_lines`. --- test/functional/api/liveupdate_spec.lua | 92 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua index ba98aa60c8..6e5221853d 100644 --- a/test/functional/api/liveupdate_spec.lua +++ b/test/functional/api/liveupdate_spec.lua @@ -73,7 +73,7 @@ local function reopenwithfolds(b) -- add a fold command('2,4fold') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 3, {'original line 2/*{{{*/', + expectn('LiveUpdate', {b, tick, 1, 4, {'original line 2/*{{{*/', 'original line 3', 'original line 4/*}}}*/'}}) -- make a new fold that wraps lines 1-6 @@ -107,18 +107,18 @@ describe('liveupdate', function() -- add one line to the middle of the file, several times command('normal! ggYjjp') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4'}}) command('normal! p') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 4, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 4, 4, {'original line 4'}}) command('normal! p') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 5, 5, {'original line 4'}}) -- add multiple lines to the middle of the file command('normal! gg4Yjjp') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 0, {'original line 4', + expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4', 'original line 5', 'original line 6', 'original line 4'}}) @@ -126,16 +126,16 @@ describe('liveupdate', function() -- add one line to the end of the file command('normal! ggYGp') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 17, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 17, 17, {'original line 4'}}) -- add one line to the end of the file, several times command('normal! ggYGppp') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 18, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 18, 18, {'original line 4'}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 19, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 19, 19, {'original line 4'}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 20, 0, {'original line 4'}}) + expectn('LiveUpdate', {b, tick, 20, 20, {'original line 4'}}) -- add several lines to the end of the file, several times command('normal! gg4YGp') @@ -146,11 +146,11 @@ describe('liveupdate', function() 'original line 6', 'original line 4'} tick = tick + 1 - expectn('LiveUpdate', {b, tick, 21, 0, firstfour}) + expectn('LiveUpdate', {b, tick, 21, 21, firstfour}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 25, 0, firstfour}) + expectn('LiveUpdate', {b, tick, 25, 25, firstfour}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 29, 0, firstfour}) + expectn('LiveUpdate', {b, tick, 29, 29, firstfour}) -- create a new empty buffer and wipe out the old one ... this will -- turn off live updates @@ -206,26 +206,26 @@ describe('liveupdate', function() tick = reopen(b, origlines) command('normal! jj3dd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {}}) + expectn('LiveUpdate', {b, tick, 2, 5, {}}) -- remove one line from the end of the file tick = reopen(b, origlines) command('normal! Gdd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 1, {}}) + expectn('LiveUpdate', {b, tick, 5, 6, {}}) -- remove multiple lines from the end of the file tick = reopen(b, origlines) command('normal! 4G3dd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 3, {}}) + expectn('LiveUpdate', {b, tick, 3, 6, {}}) -- pretend to remove heaps lines from the end of the file but really -- just remove two tick = reopen(b, origlines) command('normal! Gk5dd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 4, 2, {}}) + expectn('LiveUpdate', {b, tick, 4, 6, {}}) end) it('knows when you modify lines of text', function() @@ -237,7 +237,7 @@ describe('liveupdate', function() expectn('LiveUpdate', {b, tick, 0, 1, {'original line 1555'}}) command('normal! jj8X') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 1, {'origin3'}}) + expectn('LiveUpdate', {b, tick, 2, 3, {'origin3'}}) -- modify multiple lines at once using visual block mode tick = reopen(b, origlines) @@ -245,19 +245,19 @@ describe('liveupdate', function() sendkeys('\x16jjllx') tick = tick + 1 expectn('LiveUpdate', - {b, tick, 2, 3, {'original e 3', 'original e 4', 'original e 5'}}) + {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}}) -- replace part of a line line using :s tick = reopen(b, origlines) command('3s/line 3/foo/') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 1, {'original foo'}}) + expectn('LiveUpdate', {b, tick, 2, 3, {'original foo'}}) -- replace parts of several lines line using :s tick = reopen(b, origlines) command('%s/line [35]/foo/') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {'original foo', + expectn('LiveUpdate', {b, tick, 2, 5, {'original foo', 'original line 4', 'original foo'}}) @@ -280,7 +280,7 @@ describe('liveupdate', function() expectn('LiveUpdate', {bnew, tick + 4, 0, 1, {'hell'}}) expectn('LiveUpdate', {bnew, tick + 5, 0, 1, {'hello'}}) expectn('LiveUpdate', {bnew, tick + 6, 0, 1, {'hello', ''}}) - expectn('LiveUpdate', {bnew, tick + 7, 1, 1, {'world'}}) + expectn('LiveUpdate', {bnew, tick + 7, 1, 2, {'world'}}) end) it('knows when you replace lines', function() @@ -289,23 +289,23 @@ describe('liveupdate', function() -- blast away parts of some lines with visual mode command('normal! jjwvjjllx') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 1, {'original '}}) + expectn('LiveUpdate', {b, tick, 2, 3, {'original '}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 1, {}}) + expectn('LiveUpdate', {b, tick, 3, 4, {}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 1, {'e 5'}}) + expectn('LiveUpdate', {b, tick, 3, 4, {'e 5'}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 1, {'original e 5'}}) + expectn('LiveUpdate', {b, tick, 2, 3, {'original e 5'}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 1, {}}) + expectn('LiveUpdate', {b, tick, 3, 4, {}}) -- blast away a few lines using :g tick = reopen(b, origlines) command('global/line [35]/delete') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 1, {}}) + expectn('LiveUpdate', {b, tick, 2, 3, {}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 1, {}}) + expectn('LiveUpdate', {b, tick, 3, 4, {}}) end) it('knows when you filter lines', function() @@ -317,9 +317,9 @@ describe('liveupdate', function() -- 1) addition of the new lines after the filtered lines -- 2) removal of the original lines tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 0, {"B", "C", "D", "E"}}) + expectn('LiveUpdate', {b, tick, 5, 5, {"B", "C", "D", "E"}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 4, {}}) + expectn('LiveUpdate', {b, tick, 1, 5, {}}) end) it('sends a sensible event when you use "o"', function() @@ -329,12 +329,12 @@ describe('liveupdate', function() -- use 'o' to start a new line from a line with no indent command('normal! o') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 0, {""}}) + expectn('LiveUpdate', {b, tick, 1, 1, {""}}) -- undo the change, indent line 1 a bit, and try again command('undo') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {}}) + expectn('LiveUpdate', {b, tick, 1, 2, {}}) tick = tick + 1 expectn('LiveUpdateTick', {b, tick}) command('set autoindent') @@ -343,16 +343,16 @@ describe('liveupdate', function() expectn('LiveUpdate', {b, tick, 0, 1, {"\tAAA"}}) command('normal! ommm') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 0, {"\t"}}) + expectn('LiveUpdate', {b, tick, 1, 1, {"\t"}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {"\tmmm"}}) + expectn('LiveUpdate', {b, tick, 1, 2, {"\tmmm"}}) -- undo the change, and try again with 'O' command('undo') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {'\t'}}) + expectn('LiveUpdate', {b, tick, 1, 2, {'\t'}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {}}) + expectn('LiveUpdate', {b, tick, 1, 2, {}}) tick = tick + 1 expectn('LiveUpdateTick', {b, tick}) command('normal! ggOmmm') @@ -556,7 +556,7 @@ describe('liveupdate', function() command('normal! G') command('diffget') tick1 = tick1 + 1 - expectn('LiveUpdate', {b1, tick1, 2, 0, {"CCC"}}) + expectn('LiveUpdate', {b1, tick1, 2, 2, {"CCC"}}) eval('rpcnotify('..channel..', "Goodbye")') expectn('Goodbye', {}) @@ -574,7 +574,7 @@ describe('liveupdate', function() local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) command('2,4left') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 3, {"B", "B", "B"}}) + expectn('LiveUpdate', {b, tick, 1, 4, {"B", "B", "B"}}) end) it('works with :right', function() @@ -586,7 +586,7 @@ describe('liveupdate', function() command('set ts=2 et') command('2,4retab') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 3, {" B", " BB", " B"}}) + expectn('LiveUpdate', {b, tick, 1, 4, {" B", " BB", " B"}}) end) it('works with :move', function() @@ -594,19 +594,19 @@ describe('liveupdate', function() -- move text down towards the end of the file command('2,3move 4') tick = tick + 2 - expectn('LiveUpdate', {b, tick, 4, 0, {"original line 2", + expectn('LiveUpdate', {b, tick, 4, 4, {"original line 2", "original line 3"}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 2, {}}) + expectn('LiveUpdate', {b, tick, 1, 3, {}}) -- move text up towards the start of the file tick = reopen(b, origlines) command('4,5move 2') tick = tick + 2 - expectn('LiveUpdate', {b, tick, 2, 0, {"original line 4", + expectn('LiveUpdate', {b, tick, 2, 2, {"original line 4", "original line 5"}}) tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 2, {}}) + expectn('LiveUpdate', {b, tick, 5, 7, {}}) end) it('sends sensible events when you manually add/remove folds', function() @@ -616,7 +616,7 @@ describe('liveupdate', function() -- delete the inner fold command('normal! zR3Gzd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 3, {'original line 2', + expectn('LiveUpdate', {b, tick, 1, 4, {'original line 2', 'original line 3', 'original line 4'}}) -- delete the outer fold @@ -643,12 +643,12 @@ describe('liveupdate', function() -- create a fold from line 4 to the end of the file command('normal! 4GA/*{{{*/') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 1, {'original line 4/*{{{*/'}}) + expectn('LiveUpdate', {b, tick, 3, 4, {'original line 4/*{{{*/'}}) -- delete the fold which only has one marker command('normal! Gzd') tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4', + expectn('LiveUpdate', {b, tick, 3, 6, {'original line 4', 'original line 5', 'original line 6'}}) end) -- cgit From ec215a19621d06791d6ea3a5451e5c775620bc47 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sun, 28 Jan 2018 14:53:38 +0100 Subject: Fix tests on windows `cat` is distributed with neovim, so when can use it everywhere, as opposed to `sort`. The diffget test fails for unknown reasons on appveyor, mark it pending for now. --- test/functional/api/liveupdate_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua index 6e5221853d..e674913464 100644 --- a/test/functional/api/liveupdate_spec.lua +++ b/test/functional/api/liveupdate_spec.lua @@ -309,15 +309,15 @@ describe('liveupdate', function() end) it('knows when you filter lines', function() - -- Test filtering lines with !sort + -- Test filtering lines with !cat local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) - command('silent 2,5!sort') + command('silent 2,5!cat') -- the change comes through as two changes: -- 1) addition of the new lines after the filtered lines -- 2) removal of the original lines tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 5, {"B", "C", "D", "E"}}) + expectn('LiveUpdate', {b, tick, 5, 5, {"C", "E", "B", "D"}}) tick = tick + 1 expectn('LiveUpdate', {b, tick, 1, 5, {}}) end) @@ -462,17 +462,13 @@ describe('liveupdate', function() it('is able to notify several channels at once', function() helpers.clear() - local addsession = function(where) - eval('serverstart("'..where..'")') - local session = helpers.connect(where) - return session - end - -- create several new sessions, in addition to our main API local sessions = {} - sessions[1] = addsession(helpers.tmpname()..'.1') - sessions[2] = addsession(helpers.tmpname()..'.2') - sessions[3] = addsession(helpers.tmpname()..'.3') + local pipe = helpers.new_pipename() + eval("serverstart('"..pipe.."')") + sessions[1] = helpers.connect(pipe) + sessions[2] = helpers.connect(pipe) + sessions[3] = helpers.connect(pipe) local function request(sessionnr, method, ...) local status, rv = sessions[sessionnr]:request(method, ...) @@ -539,6 +535,10 @@ describe('liveupdate', function() end) it('works with :diffput and :diffget', function() + if os.getenv("APPVEYOR") then + pending("Fails on appveyor for some reason.", function() end) + end + local b1, tick1 = editoriginal(true, {"AAA", "BBB"}) local channel = nvim('get_api_info')[1] command('diffthis') -- cgit From 6bdcbef2f5acfd9815599c751bd8dcbe3204281f Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sun, 11 Feb 2018 22:51:29 +0100 Subject: The grand renaming --- test/functional/api/buffer_updates_spec.lua | 737 ++++++++++++++++++++++++++++ test/functional/api/liveupdate_spec.lua | 737 ---------------------------- 2 files changed, 737 insertions(+), 737 deletions(-) create mode 100644 test/functional/api/buffer_updates_spec.lua delete mode 100644 test/functional/api/liveupdate_spec.lua (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua new file mode 100644 index 0000000000..c3a1754cf3 --- /dev/null +++ b/test/functional/api/buffer_updates_spec.lua @@ -0,0 +1,737 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq, ok = helpers.eq, helpers.ok +local buffer, command, eval, nvim, next_message = helpers.buffer, + helpers.command, helpers.eval, helpers.nvim, helpers.next_msg + +local origlines = {"original line 1", + "original line 2", + "original line 3", + "original line 4", + "original line 5", + "original line 6"} + +local function expectn(name, args) + -- expect the next message to be the specified notification event + eq({'notification', name, args}, next_message()) +end + +local function sendkeys(keys) + nvim('input', keys) + -- give neovim 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.01 + repeat until os.clock() > ntime +end + +local function open(activate, lines) + local filename = helpers.tmpname() + helpers.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_updates_start messages + -- arrive as expectected + if activate then + ok(buffer('attach', b, true)) + expectn('nvim_buf_updates_start', {b, tick, lines, false}) + end + + return b, tick, filename +end + +local function editoriginal(activate, lines) + if not lines then + lines = origlines + end + -- load up the file with the correct contents + helpers.clear() + return open(activate, lines) +end + +local function reopen(buf, expectedlines) + ok(buffer('detach', buf)) + expectn('nvim_buf_updates_end', {buf}) + -- for some reason the :edit! increments tick by 2 + command('edit!') + local tick = eval('b:changedtick') + ok(buffer('attach', buf, true)) + expectn('nvim_buf_updates_start', {buf, tick, expectedlines, false}) + command('normal! gg') + return tick +end + +local function reopenwithfolds(b) + -- discard any changes to the buffer + local tick = reopen(b, origlines) + + -- use markers for folds, make all folds open by default + command('setlocal foldmethod=marker foldlevel=20') + + -- add a fold + command('2,4fold') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 4, {'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/'}}) + -- make a new fold that wraps lines 1-6 + command('1,6fold') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 6, {'original line 1/*{{{*/', + 'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/', + 'original line 5', + 'original line 6/*}}}*/'}}) + return tick +end + +describe('liveupdate', function() + it('knows when you add line to a buffer', function() + local b, tick = editoriginal(true) + + -- add a new line at the start of the buffer + command('normal! GyyggP') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 0, {'original line 6'}}) + + -- add multiple lines at the start of the file + command('normal! GkkyGggP') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 0, {'original line 4', + 'original line 5', + 'original line 6'}}) + + -- add one line to the middle of the file, several times + command('normal! ggYjjp') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 3, {'original line 4'}}) + command('normal! p') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 4, 4, {'original line 4'}}) + command('normal! p') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 5, 5, {'original line 4'}}) + + -- add multiple lines to the middle of the file + command('normal! gg4Yjjp') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 3, {'original line 4', + 'original line 5', + 'original line 6', + 'original line 4'}}) + + -- add one line to the end of the file + command('normal! ggYGp') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 17, 17, {'original line 4'}}) + + -- add one line to the end of the file, several times + command('normal! ggYGppp') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 18, 18, {'original line 4'}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 19, 19, {'original line 4'}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 20, 20, {'original line 4'}}) + + -- add several lines to the end of the file, several times + command('normal! gg4YGp') + command('normal! Gp') + command('normal! Gp') + local firstfour = {'original line 4', + 'original line 5', + 'original line 6', + 'original line 4'} + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 21, 21, firstfour}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 25, 25, firstfour}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 29, 29, firstfour}) + + -- create a new empty buffer and wipe out the old one ... this will + -- turn off live updates + command('enew!') + expectn('nvim_buf_updates_end', {b}) + + -- add a line at the start of an empty file + command('enew') + tick = eval('b:changedtick') + local b2 = nvim('get_current_buf') + ok(buffer('attach', b2, true)) + expectn('nvim_buf_updates_start', {b2, tick, {""}, false}) + eval('append(0, ["new line 1"])') + tick = tick + 1 + expectn('nvim_buf_update', {b2, tick, 0, 0, {'new line 1'}}) + + -- turn off live updates manually + buffer('detach', b2) + expectn('nvim_buf_updates_end', {b2}) + + -- add multiple lines to a blank file + command('enew!') + local b3 = nvim('get_current_buf') + ok(buffer('attach', b3, true)) + tick = eval('b:changedtick') + expectn('nvim_buf_updates_start', {b3, tick, {""}, false}) + eval('append(0, ["new line 1", "new line 2", "new line 3"])') + tick = tick + 1 + expectn('nvim_buf_update', {b3, tick, 0, 0, {'new line 1', + 'new line 2', + 'new line 3'}}) + + -- use the API itself to add a line to the start of the buffer + buffer('set_lines', b3, 0, 0, true, {'New First Line'}) + tick = tick + 1 + expectn('nvim_buf_update', {b3, tick, 0, 0, {"New First Line"}}) + end) + + it('knows when you remove lines from a buffer', function() + local b, tick = editoriginal(true) + + -- remove one line from start of file + command('normal! dd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {}}) + + -- remove multiple lines from the start of the file + command('normal! 4dd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 4, {}}) + + -- remove multiple lines from middle of file + tick = reopen(b, origlines) + command('normal! jj3dd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 5, {}}) + + -- remove one line from the end of the file + tick = reopen(b, origlines) + command('normal! Gdd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 5, 6, {}}) + + -- remove multiple lines from the end of the file + tick = reopen(b, origlines) + command('normal! 4G3dd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 6, {}}) + + -- pretend to remove heaps lines from the end of the file but really + -- just remove two + tick = reopen(b, origlines) + command('normal! Gk5dd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 4, 6, {}}) + end) + + it('knows when you modify lines of text', function() + local b, tick = editoriginal(true) + + -- some normal text editing + command('normal! A555') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'original line 1555'}}) + command('normal! jj8X') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 3, {'origin3'}}) + + -- modify multiple lines at once using visual block mode + tick = reopen(b, origlines) + command('normal! jjw') + sendkeys('\x16jjllx') + tick = tick + 1 + expectn('nvim_buf_update', + {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}}) + + -- replace part of a line line using :s + tick = reopen(b, origlines) + command('3s/line 3/foo/') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 3, {'original foo'}}) + + -- replace parts of several lines line using :s + tick = reopen(b, origlines) + command('%s/line [35]/foo/') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 5, {'original foo', + 'original line 4', + 'original foo'}}) + + -- type text into the first line of a blank file, one character at a time + command('enew!') + tick = 2 + expectn('nvim_buf_updates_end', {b}) + local bnew = nvim('get_current_buf') + ok(buffer('attach', bnew, true)) + expectn('nvim_buf_updates_start', {bnew, tick, {''}, false}) + sendkeys('i') + sendkeys('h') + sendkeys('e') + sendkeys('l') + sendkeys('l') + sendkeys('o\nworld') + expectn('nvim_buf_update', {bnew, tick + 1, 0, 1, {'h'}}) + expectn('nvim_buf_update', {bnew, tick + 2, 0, 1, {'he'}}) + expectn('nvim_buf_update', {bnew, tick + 3, 0, 1, {'hel'}}) + expectn('nvim_buf_update', {bnew, tick + 4, 0, 1, {'hell'}}) + expectn('nvim_buf_update', {bnew, tick + 5, 0, 1, {'hello'}}) + expectn('nvim_buf_update', {bnew, tick + 6, 0, 1, {'hello', ''}}) + expectn('nvim_buf_update', {bnew, tick + 7, 1, 2, {'world'}}) + end) + + it('knows when you replace lines', function() + local b, tick = editoriginal(true) + + -- blast away parts of some lines with visual mode + command('normal! jjwvjjllx') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 3, {'original '}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 4, {'e 5'}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 3, {'original e 5'}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + + -- blast away a few lines using :g + tick = reopen(b, origlines) + command('global/line [35]/delete') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 2, 3, {}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + end) + + it('knows when you filter lines', function() + -- Test filtering lines with !cat + local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) + + command('silent 2,5!cat') + -- the change comes through as two changes: + -- 1) addition of the new lines after the filtered lines + -- 2) removal of the original lines + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 5, 5, {"C", "E", "B", "D"}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 5, {}}) + end) + + it('sends a sensible event when you use "o"', function() + local b, tick = editoriginal(true, {'AAA', 'BBB'}) + command('set noautoindent nosmartindent') + + -- use 'o' to start a new line from a line with no indent + command('normal! o') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 1, {""}}) + + -- undo the change, indent line 1 a bit, and try again + command('undo') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 2, {}}) + tick = tick + 1 + expectn('nvim_buf_update_tick', {b, tick}) + command('set autoindent') + command('normal! >>') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {"\tAAA"}}) + command('normal! ommm') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 1, {"\t"}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 2, {"\tmmm"}}) + + -- undo the change, and try again with 'O' + command('undo') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 2, {'\t'}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 2, {}}) + tick = tick + 1 + expectn('nvim_buf_update_tick', {b, tick}) + command('normal! ggOmmm') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 0, {"\t"}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {"\tmmm"}}) + end) + + it('deactivates when your buffer changes outside vim', function() + -- Test changing file from outside vim and reloading using :edit + local lines = {"Line 1", "Line 2"}; + local b, tick, filename = editoriginal(true, lines) + + command('normal! x') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'ine 1'}}) + command('undo') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'Line 1'}}) + tick = tick + 1 + expectn('nvim_buf_update_tick', {b, tick}) + + -- change the file directly + local f = io.open(filename, 'a') + f:write("another line\n") + f:flush() + f:close() + + -- reopen the file and watch live updates shut down + command('edit') + expectn('nvim_buf_updates_end', {b}) + end) + + it('allows a channel to watch multiple 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'}) + local b1nr = eval('bufnr("")') + command('split') + local b2, tick2 = open(true, {'B1', 'B2'}) + local b2nr = eval('bufnr("")') + command('split') + local b3, tick3 = open(true, {'C1', 'C2'}) + local b3nr = eval('bufnr("")') + + -- make a new window for moving between buffers + command('split') + + command('b'..b1nr) + command('normal! x') + tick1 = tick1 + 1 + expectn('nvim_buf_update', {b1, tick1, 0, 1, {'1'}}) + command('undo') + tick1 = tick1 + 1 + expectn('nvim_buf_update', {b1, tick1, 0, 1, {'A1'}}) + tick1 = tick1 + 1 + expectn('nvim_buf_update_tick', {b1, tick1}) + + command('b'..b2nr) + command('normal! x') + tick2 = tick2 + 1 + expectn('nvim_buf_update', {b2, tick2, 0, 1, {'1'}}) + command('undo') + tick2 = tick2 + 1 + expectn('nvim_buf_update', {b2, tick2, 0, 1, {'B1'}}) + tick2 = tick2 + 1 + expectn('nvim_buf_update_tick', {b2, tick2}) + + command('b'..b3nr) + command('normal! x') + tick3 = tick3 + 1 + expectn('nvim_buf_update', {b3, tick3, 0, 1, {'1'}}) + command('undo') + tick3 = tick3 + 1 + expectn('nvim_buf_update', {b3, tick3, 0, 1, {'C1'}}) + tick3 = tick3 + 1 + expectn('nvim_buf_update_tick', {b3, tick3}) + end) + + it('doesn\'t get confused when you turn watching on/off many times', + function() + local channel = nvim('get_api_info')[1] + local b, tick = editoriginal(false) + + -- 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)) + expectn('nvim_buf_updates_start', {b, tick, origlines, false}) + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + + -- turn live updates off many times + ok(buffer('detach', b)) + ok(buffer('detach', b)) + ok(buffer('detach', b)) + ok(buffer('detach', b)) + ok(buffer('detach', b)) + expectn('nvim_buf_updates_end', {b}) + eval('rpcnotify('..channel..', "Hello Again")') + expectn('Hello Again', {}) + end) + + it('is able to notify several channels at once', function() + helpers.clear() + + -- create several new sessions, in addition to our main API + local sessions = {} + local pipe = helpers.new_pipename() + eval("serverstart('"..pipe.."')") + sessions[1] = helpers.connect(pipe) + sessions[2] = helpers.connect(pipe) + sessions[3] = helpers.connect(pipe) + + local function request(sessionnr, method, ...) + local status, rv = sessions[sessionnr]:request(method, ...) + if not status then + error(rv[2]) + end + return rv + end + + local function wantn(sessionid, name, args) + local session = sessions[sessionid] + eq({'notification', name, args}, session:next_message()) + end + + -- edit a new file, but don't turn on live updates + local lines = {'AAA', 'BBB'} + local b, tick = open(false, lines) + + -- turn on live updates 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)) + wantn(1, 'nvim_buf_updates_start', {b, tick, lines, false}) + wantn(2, 'nvim_buf_updates_start', {b, tick, lines, false}) + wantn(3, 'nvim_buf_updates_start', {b, tick, lines, false}) + + -- make a change to the buffer + command('normal! x') + tick = tick + 1 + wantn(1, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + wantn(2, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + wantn(3, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + + -- stop watching on channel 1 + ok(request(1, 'nvim_buf_detach', b)) + wantn(1, 'nvim_buf_updates_end', {b}) + + -- undo the change to buffer 1 + command('undo') + tick = tick + 1 + wantn(2, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + wantn(3, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + wantn(2, 'nvim_buf_update_tick', {b, tick}) + wantn(3, 'nvim_buf_update_tick', {b, tick}) + + -- make sure there are no other pending nvim_buf_update messages going to + -- channel 1 + local channel1 = request(1, 'nvim_get_api_info')[1] + eval('rpcnotify('..channel1..', "Hello")') + wantn(1, 'Hello', {}) + + -- close the buffer and channels 2 and 3 should get a nvim_buf_updates_end + -- notification + command('edit') + wantn(2, 'nvim_buf_updates_end', {b}) + wantn(3, 'nvim_buf_updates_end', {b}) + + -- make sure there are no other pending nvim_buf_update messages going to + -- channel 1 + channel1 = request(1, 'nvim_get_api_info')[1] + eval('rpcnotify('..channel1..', "Hello Again")') + wantn(1, 'Hello Again', {}) + end) + + it('works with :diffput and :diffget', function() + if os.getenv("APPVEYOR") then + pending("Fails on appveyor for some reason.", function() end) + end + + local b1, tick1 = editoriginal(true, {"AAA", "BBB"}) + local channel = nvim('get_api_info')[1] + command('diffthis') + command('rightbelow vsplit') + local b2, tick2 = open(true, {"BBB", "CCC"}) + command('diffthis') + -- go back to first buffer, and push the 'AAA' line to the second buffer + command('1wincmd w') + command('normal! gg') + command('diffput') + tick2 = tick2 + 1 + expectn('nvim_buf_update', {b2, tick2, 0, 0, {"AAA"}}) + + -- use :diffget to grab the other change from buffer 2 + command('normal! G') + command('diffget') + tick1 = tick1 + 1 + expectn('nvim_buf_update', {b1, tick1, 2, 2, {"CCC"}}) + + eval('rpcnotify('..channel..', "Goodbye")') + expectn('Goodbye', {}) + end) + + it('works with :sort', function() + -- test for :sort + local b, tick = editoriginal(true, {"B", "D", "C", "A", "E"}) + command('%sort') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}}) + end) + + it('works with :left', function() + local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) + command('2,4left') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 4, {"B", "B", "B"}}) + end) + + it('works with :right', function() + local b, tick = editoriginal(true, {" A", + "\t B", + "\t \tBB", + " \tB", + "\t\tC"}) + command('set ts=2 et') + command('2,4retab') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 4, {" B", " BB", " B"}}) + end) + + it('works with :move', function() + local b, tick = editoriginal(true, origlines) + -- move text down towards the end of the file + command('2,3move 4') + tick = tick + 2 + expectn('nvim_buf_update', {b, tick, 4, 4, {"original line 2", + "original line 3"}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 3, {}}) + + -- move text up towards the start of the file + tick = reopen(b, origlines) + command('4,5move 2') + tick = tick + 2 + expectn('nvim_buf_update', {b, tick, 2, 2, {"original line 4", + "original line 5"}}) + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 5, 7, {}}) + end) + + it('sends sensible events when you manually add/remove folds', function() + local b = editoriginal(true) + local tick = reopenwithfolds(b) + + -- delete the inner fold + command('normal! zR3Gzd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 1, 4, {'original line 2', + 'original line 3', + 'original line 4'}}) + -- delete the outer fold + command('normal! zd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + + -- discard changes and put the folds back + tick = reopenwithfolds(b) + + -- remove both folds at once + command('normal! ggzczD') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + + -- discard changes and put the folds back + tick = reopenwithfolds(b) + + -- now delete all folds at once + command('normal! zE') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + + -- create a fold from line 4 to the end of the file + command('normal! 4GA/*{{{*/') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 4, {'original line 4/*{{{*/'}}) + + -- delete the fold which only has one marker + command('normal! Gzd') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 3, 6, {'original line 4', + 'original line 5', + 'original line 6'}}) + end) + + it('turns off updates when a buffer is closed', function() + local b, tick = editoriginal(true, {'AAA'}) + local channel = nvim('get_api_info')[1] + + -- test live updates are working + command('normal! x') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + command('undo') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + expectn('nvim_buf_update_tick', {b, tick}) + + -- close our buffer by creating a new one + command('enew') + expectn('nvim_buf_updates_end', {b}) + + -- reopen the original buffer, make sure there are no Live Updates sent + command('b1') + command('normal! x') + + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + end) + + -- test what happens when a buffer is hidden + it('keeps updates turned on if the buffer is hidden', function() + local b, tick = editoriginal(true, {'AAA'}) + local channel = nvim('get_api_info')[1] + + -- test live updates are working + command('normal! x') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + command('undo') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + tick = tick + 1 + expectn('nvim_buf_update_tick', {b, tick}) + + -- close our buffer by creating a new one + command('set hidden') + command('enew') + + -- note that no nvim_buf_updates_end is sent + eval('rpcnotify('..channel..', "Hello There")') + expectn('Hello There', {}) + + -- reopen the original buffer, make sure Live Updates are still active + command('b1') + command('normal! x') + tick = tick + 1 + expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + end) + + it('turns off live updates when a buffer is unloaded, deleted, or wiped', + function() + -- start with a blank nvim + helpers.clear() + -- need to make a new window with a buffer because :bunload doesn't let you + -- unload the last buffer + for _, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do + command('new') + -- open a brand spanking new file + local b = open(true, {'AAA'}) + + -- call :bunload or whatever the command is, and then check that we + -- receive a nvim_buf_updates_end + command(cmd) + expectn('nvim_buf_updates_end', {b}) + end + end) + + it('doesn\'t send the buffer\'s content when not requested', function() + helpers.clear() + local b, tick = editoriginal(false) + ok(buffer('attach', b, false)) + expectn('nvim_buf_updates_start', {b, tick, {}, false}) + end) + +end) diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua deleted file mode 100644 index e674913464..0000000000 --- a/test/functional/api/liveupdate_spec.lua +++ /dev/null @@ -1,737 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, ok = helpers.eq, helpers.ok -local buffer, command, eval, nvim, next_message = helpers.buffer, - helpers.command, helpers.eval, helpers.nvim, helpers.next_message - -local origlines = {"original line 1", - "original line 2", - "original line 3", - "original line 4", - "original line 5", - "original line 6"} - -local function expectn(name, args) - -- expect the next message to be the specified notification event - eq({'notification', name, args}, next_message()) -end - -local function sendkeys(keys) - nvim('input', keys) - -- give neovim 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.01 - repeat until os.clock() > ntime -end - -local function open(activate, lines) - local filename = helpers.tmpname() - helpers.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 LiveUpdateStart messages - -- arrive as expectected - if activate then - ok(buffer('live_updates_start', b, true)) - expectn('LiveUpdateStart', {b, tick, lines, false}) - end - - return b, tick, filename -end - -local function editoriginal(activate, lines) - if not lines then - lines = origlines - end - -- load up the file with the correct contents - helpers.clear() - return open(activate, lines) -end - -local function reopen(buf, expectedlines) - ok(buffer('live_updates_stop', buf)) - expectn('LiveUpdateEnd', {buf}) - -- for some reason the :edit! increments tick by 2 - command('edit!') - local tick = eval('b:changedtick') - ok(buffer('live_updates_start', buf, true)) - expectn('LiveUpdateStart', {buf, tick, expectedlines, false}) - command('normal! gg') - return tick -end - -local function reopenwithfolds(b) - -- discard any changes to the buffer - local tick = reopen(b, origlines) - - -- use markers for folds, make all folds open by default - command('setlocal foldmethod=marker foldlevel=20') - - -- add a fold - command('2,4fold') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 4, {'original line 2/*{{{*/', - 'original line 3', - 'original line 4/*}}}*/'}}) - -- make a new fold that wraps lines 1-6 - command('1,6fold') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 6, {'original line 1/*{{{*/', - 'original line 2/*{{{*/', - 'original line 3', - 'original line 4/*}}}*/', - 'original line 5', - 'original line 6/*}}}*/'}}) - return tick -end - -describe('liveupdate', function() - it('knows when you add line to a buffer', function() - local b, tick = editoriginal(true) - - -- add a new line at the start of the buffer - command('normal! GyyggP') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 0, {'original line 6'}}) - - -- add multiple lines at the start of the file - command('normal! GkkyGggP') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 0, {'original line 4', - 'original line 5', - 'original line 6'}}) - - -- add one line to the middle of the file, several times - command('normal! ggYjjp') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4'}}) - command('normal! p') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 4, 4, {'original line 4'}}) - command('normal! p') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 5, {'original line 4'}}) - - -- add multiple lines to the middle of the file - command('normal! gg4Yjjp') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 3, {'original line 4', - 'original line 5', - 'original line 6', - 'original line 4'}}) - - -- add one line to the end of the file - command('normal! ggYGp') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 17, 17, {'original line 4'}}) - - -- add one line to the end of the file, several times - command('normal! ggYGppp') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 18, 18, {'original line 4'}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 19, 19, {'original line 4'}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 20, 20, {'original line 4'}}) - - -- add several lines to the end of the file, several times - command('normal! gg4YGp') - command('normal! Gp') - command('normal! Gp') - local firstfour = {'original line 4', - 'original line 5', - 'original line 6', - 'original line 4'} - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 21, 21, firstfour}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 25, 25, firstfour}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 29, 29, firstfour}) - - -- create a new empty buffer and wipe out the old one ... this will - -- turn off live updates - command('enew!') - expectn('LiveUpdateEnd', {b}) - - -- add a line at the start of an empty file - command('enew') - tick = eval('b:changedtick') - local b2 = nvim('get_current_buf') - ok(buffer('live_updates_start', b2, true)) - expectn('LiveUpdateStart', {b2, tick, {""}, false}) - eval('append(0, ["new line 1"])') - tick = tick + 1 - expectn('LiveUpdate', {b2, tick, 0, 0, {'new line 1'}}) - - -- turn off live updates manually - buffer('live_updates_stop', b2) - expectn('LiveUpdateEnd', {b2}) - - -- add multiple lines to a blank file - command('enew!') - local b3 = nvim('get_current_buf') - ok(buffer('live_updates_start', b3, true)) - tick = eval('b:changedtick') - expectn('LiveUpdateStart', {b3, tick, {""}, false}) - eval('append(0, ["new line 1", "new line 2", "new line 3"])') - tick = tick + 1 - expectn('LiveUpdate', {b3, tick, 0, 0, {'new line 1', - 'new line 2', - 'new line 3'}}) - - -- use the API itself to add a line to the start of the buffer - buffer('set_lines', b3, 0, 0, true, {'New First Line'}) - tick = tick + 1 - expectn('LiveUpdate', {b3, tick, 0, 0, {"New First Line"}}) - end) - - it('knows when you remove lines from a buffer', function() - local b, tick = editoriginal(true) - - -- remove one line from start of file - command('normal! dd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {}}) - - -- remove multiple lines from the start of the file - command('normal! 4dd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 4, {}}) - - -- remove multiple lines from middle of file - tick = reopen(b, origlines) - command('normal! jj3dd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 5, {}}) - - -- remove one line from the end of the file - tick = reopen(b, origlines) - command('normal! Gdd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 6, {}}) - - -- remove multiple lines from the end of the file - tick = reopen(b, origlines) - command('normal! 4G3dd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 6, {}}) - - -- pretend to remove heaps lines from the end of the file but really - -- just remove two - tick = reopen(b, origlines) - command('normal! Gk5dd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 4, 6, {}}) - end) - - it('knows when you modify lines of text', function() - local b, tick = editoriginal(true) - - -- some normal text editing - command('normal! A555') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'original line 1555'}}) - command('normal! jj8X') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {'origin3'}}) - - -- modify multiple lines at once using visual block mode - tick = reopen(b, origlines) - command('normal! jjw') - sendkeys('\x16jjllx') - tick = tick + 1 - expectn('LiveUpdate', - {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}}) - - -- replace part of a line line using :s - tick = reopen(b, origlines) - command('3s/line 3/foo/') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {'original foo'}}) - - -- replace parts of several lines line using :s - tick = reopen(b, origlines) - command('%s/line [35]/foo/') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 5, {'original foo', - 'original line 4', - 'original foo'}}) - - -- type text into the first line of a blank file, one character at a time - command('enew!') - tick = 2 - expectn('LiveUpdateEnd', {b}) - local bnew = nvim('get_current_buf') - ok(buffer('live_updates_start', bnew, true)) - expectn('LiveUpdateStart', {bnew, tick, {''}, false}) - sendkeys('i') - sendkeys('h') - sendkeys('e') - sendkeys('l') - sendkeys('l') - sendkeys('o\nworld') - expectn('LiveUpdate', {bnew, tick + 1, 0, 1, {'h'}}) - expectn('LiveUpdate', {bnew, tick + 2, 0, 1, {'he'}}) - expectn('LiveUpdate', {bnew, tick + 3, 0, 1, {'hel'}}) - expectn('LiveUpdate', {bnew, tick + 4, 0, 1, {'hell'}}) - expectn('LiveUpdate', {bnew, tick + 5, 0, 1, {'hello'}}) - expectn('LiveUpdate', {bnew, tick + 6, 0, 1, {'hello', ''}}) - expectn('LiveUpdate', {bnew, tick + 7, 1, 2, {'world'}}) - end) - - it('knows when you replace lines', function() - local b, tick = editoriginal(true) - - -- blast away parts of some lines with visual mode - command('normal! jjwvjjllx') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {'original '}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 4, {}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 4, {'e 5'}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {'original e 5'}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 4, {}}) - - -- blast away a few lines using :g - tick = reopen(b, origlines) - command('global/line [35]/delete') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 2, 3, {}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 4, {}}) - end) - - it('knows when you filter lines', function() - -- Test filtering lines with !cat - local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) - - command('silent 2,5!cat') - -- the change comes through as two changes: - -- 1) addition of the new lines after the filtered lines - -- 2) removal of the original lines - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 5, {"C", "E", "B", "D"}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 5, {}}) - end) - - it('sends a sensible event when you use "o"', function() - local b, tick = editoriginal(true, {'AAA', 'BBB'}) - command('set noautoindent nosmartindent') - - -- use 'o' to start a new line from a line with no indent - command('normal! o') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {""}}) - - -- undo the change, indent line 1 a bit, and try again - command('undo') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 2, {}}) - tick = tick + 1 - expectn('LiveUpdateTick', {b, tick}) - command('set autoindent') - command('normal! >>') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {"\tAAA"}}) - command('normal! ommm') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 1, {"\t"}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 2, {"\tmmm"}}) - - -- undo the change, and try again with 'O' - command('undo') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 2, {'\t'}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 2, {}}) - tick = tick + 1 - expectn('LiveUpdateTick', {b, tick}) - command('normal! ggOmmm') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 0, {"\t"}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {"\tmmm"}}) - end) - - it('deactivates when your buffer changes outside vim', function() - -- Test changing file from outside vim and reloading using :edit - local lines = {"Line 1", "Line 2"}; - local b, tick, filename = editoriginal(true, lines) - - command('normal! x') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'ine 1'}}) - command('undo') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'Line 1'}}) - tick = tick + 1 - expectn('LiveUpdateTick', {b, tick}) - - -- change the file directly - local f = io.open(filename, 'a') - f:write("another line\n") - f:flush() - f:close() - - -- reopen the file and watch live updates shut down - command('edit') - expectn('LiveUpdateEnd', {b}) - end) - - it('allows a channel to watch multiple 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'}) - local b1nr = eval('bufnr("")') - command('split') - local b2, tick2 = open(true, {'B1', 'B2'}) - local b2nr = eval('bufnr("")') - command('split') - local b3, tick3 = open(true, {'C1', 'C2'}) - local b3nr = eval('bufnr("")') - - -- make a new window for moving between buffers - command('split') - - command('b'..b1nr) - command('normal! x') - tick1 = tick1 + 1 - expectn('LiveUpdate', {b1, tick1, 0, 1, {'1'}}) - command('undo') - tick1 = tick1 + 1 - expectn('LiveUpdate', {b1, tick1, 0, 1, {'A1'}}) - tick1 = tick1 + 1 - expectn('LiveUpdateTick', {b1, tick1}) - - command('b'..b2nr) - command('normal! x') - tick2 = tick2 + 1 - expectn('LiveUpdate', {b2, tick2, 0, 1, {'1'}}) - command('undo') - tick2 = tick2 + 1 - expectn('LiveUpdate', {b2, tick2, 0, 1, {'B1'}}) - tick2 = tick2 + 1 - expectn('LiveUpdateTick', {b2, tick2}) - - command('b'..b3nr) - command('normal! x') - tick3 = tick3 + 1 - expectn('LiveUpdate', {b3, tick3, 0, 1, {'1'}}) - command('undo') - tick3 = tick3 + 1 - expectn('LiveUpdate', {b3, tick3, 0, 1, {'C1'}}) - tick3 = tick3 + 1 - expectn('LiveUpdateTick', {b3, tick3}) - end) - - it('doesn\'t get confused when you turn watching on/off many times', - function() - local channel = nvim('get_api_info')[1] - local b, tick = editoriginal(false) - - -- turn on live updates many times - ok(buffer('live_updates_start', b, true)) - ok(buffer('live_updates_start', b, true)) - ok(buffer('live_updates_start', b, true)) - ok(buffer('live_updates_start', b, true)) - ok(buffer('live_updates_start', b, true)) - expectn('LiveUpdateStart', {b, tick, origlines, false}) - eval('rpcnotify('..channel..', "Hello There")') - expectn('Hello There', {}) - - -- turn live updates off many times - ok(buffer('live_updates_stop', b)) - ok(buffer('live_updates_stop', b)) - ok(buffer('live_updates_stop', b)) - ok(buffer('live_updates_stop', b)) - ok(buffer('live_updates_stop', b)) - expectn('LiveUpdateEnd', {b}) - eval('rpcnotify('..channel..', "Hello Again")') - expectn('Hello Again', {}) - end) - - it('is able to notify several channels at once', function() - helpers.clear() - - -- create several new sessions, in addition to our main API - local sessions = {} - local pipe = helpers.new_pipename() - eval("serverstart('"..pipe.."')") - sessions[1] = helpers.connect(pipe) - sessions[2] = helpers.connect(pipe) - sessions[3] = helpers.connect(pipe) - - local function request(sessionnr, method, ...) - local status, rv = sessions[sessionnr]:request(method, ...) - if not status then - error(rv[2]) - end - return rv - end - - local function wantn(sessionid, name, args) - local session = sessions[sessionid] - eq({'notification', name, args}, session:next_message()) - end - - -- edit a new file, but don't turn on live updates - local lines = {'AAA', 'BBB'} - local b, tick = open(false, lines) - - -- turn on live updates for sessions 1, 2 and 3 - ok(request(1, 'nvim_buf_live_updates_start', b, true)) - ok(request(2, 'nvim_buf_live_updates_start', b, true)) - ok(request(3, 'nvim_buf_live_updates_start', b, true)) - wantn(1, 'LiveUpdateStart', {b, tick, lines, false}) - wantn(2, 'LiveUpdateStart', {b, tick, lines, false}) - wantn(3, 'LiveUpdateStart', {b, tick, lines, false}) - - -- make a change to the buffer - command('normal! x') - tick = tick + 1 - wantn(1, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) - wantn(2, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) - wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AA'}}) - - -- stop watching on channel 1 - ok(request(1, 'nvim_buf_live_updates_stop', b)) - wantn(1, 'LiveUpdateEnd', {b}) - - -- undo the change to buffer 1 - command('undo') - tick = tick + 1 - wantn(2, 'LiveUpdate', {b, tick, 0, 1, {'AAA'}}) - wantn(3, 'LiveUpdate', {b, tick, 0, 1, {'AAA'}}) - tick = tick + 1 - wantn(2, 'LiveUpdateTick', {b, tick}) - wantn(3, 'LiveUpdateTick', {b, tick}) - - -- make sure there are no other pending LiveUpdate messages going to - -- channel 1 - local channel1 = request(1, 'nvim_get_api_info')[1] - eval('rpcnotify('..channel1..', "Hello")') - wantn(1, 'Hello', {}) - - -- close the buffer and channels 2 and 3 should get a LiveUpdateEnd - -- notification - command('edit') - wantn(2, 'LiveUpdateEnd', {b}) - wantn(3, 'LiveUpdateEnd', {b}) - - -- make sure there are no other pending LiveUpdate messages going to - -- channel 1 - channel1 = request(1, 'nvim_get_api_info')[1] - eval('rpcnotify('..channel1..', "Hello Again")') - wantn(1, 'Hello Again', {}) - end) - - it('works with :diffput and :diffget', function() - if os.getenv("APPVEYOR") then - pending("Fails on appveyor for some reason.", function() end) - end - - local b1, tick1 = editoriginal(true, {"AAA", "BBB"}) - local channel = nvim('get_api_info')[1] - command('diffthis') - command('rightbelow vsplit') - local b2, tick2 = open(true, {"BBB", "CCC"}) - command('diffthis') - -- go back to first buffer, and push the 'AAA' line to the second buffer - command('1wincmd w') - command('normal! gg') - command('diffput') - tick2 = tick2 + 1 - expectn('LiveUpdate', {b2, tick2, 0, 0, {"AAA"}}) - - -- use :diffget to grab the other change from buffer 2 - command('normal! G') - command('diffget') - tick1 = tick1 + 1 - expectn('LiveUpdate', {b1, tick1, 2, 2, {"CCC"}}) - - eval('rpcnotify('..channel..', "Goodbye")') - expectn('Goodbye', {}) - end) - - it('works with :sort', function() - -- test for :sort - local b, tick = editoriginal(true, {"B", "D", "C", "A", "E"}) - command('%sort') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}}) - end) - - it('works with :left', function() - local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) - command('2,4left') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 4, {"B", "B", "B"}}) - end) - - it('works with :right', function() - local b, tick = editoriginal(true, {" A", - "\t B", - "\t \tBB", - " \tB", - "\t\tC"}) - command('set ts=2 et') - command('2,4retab') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 4, {" B", " BB", " B"}}) - end) - - it('works with :move', function() - local b, tick = editoriginal(true, origlines) - -- move text down towards the end of the file - command('2,3move 4') - tick = tick + 2 - expectn('LiveUpdate', {b, tick, 4, 4, {"original line 2", - "original line 3"}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 3, {}}) - - -- move text up towards the start of the file - tick = reopen(b, origlines) - command('4,5move 2') - tick = tick + 2 - expectn('LiveUpdate', {b, tick, 2, 2, {"original line 4", - "original line 5"}}) - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 5, 7, {}}) - end) - - it('sends sensible events when you manually add/remove folds', function() - local b = editoriginal(true) - local tick = reopenwithfolds(b) - - -- delete the inner fold - command('normal! zR3Gzd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 1, 4, {'original line 2', - 'original line 3', - 'original line 4'}}) - -- delete the outer fold - command('normal! zd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 6, origlines}) - - -- discard changes and put the folds back - tick = reopenwithfolds(b) - - -- remove both folds at once - command('normal! ggzczD') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 6, origlines}) - - -- discard changes and put the folds back - tick = reopenwithfolds(b) - - -- now delete all folds at once - command('normal! zE') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 6, origlines}) - - -- create a fold from line 4 to the end of the file - command('normal! 4GA/*{{{*/') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 4, {'original line 4/*{{{*/'}}) - - -- delete the fold which only has one marker - command('normal! Gzd') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 3, 6, {'original line 4', - 'original line 5', - 'original line 6'}}) - end) - - it('turns off updates when a buffer is closed', function() - local b, tick = editoriginal(true, {'AAA'}) - local channel = nvim('get_api_info')[1] - - -- test live updates are working - command('normal! x') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) - command('undo') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'AAA'}}) - tick = tick + 1 - expectn('LiveUpdateTick', {b, tick}) - - -- close our buffer by creating a new one - command('enew') - expectn('LiveUpdateEnd', {b}) - - -- reopen the original buffer, make sure there are no Live Updates sent - command('b1') - command('normal! x') - - eval('rpcnotify('..channel..', "Hello There")') - expectn('Hello There', {}) - end) - - -- test what happens when a buffer is hidden - it('keeps updates turned on if the buffer is hidden', function() - local b, tick = editoriginal(true, {'AAA'}) - local channel = nvim('get_api_info')[1] - - -- test live updates are working - command('normal! x') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) - command('undo') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'AAA'}}) - tick = tick + 1 - expectn('LiveUpdateTick', {b, tick}) - - -- close our buffer by creating a new one - command('set hidden') - command('enew') - - -- note that no LiveUpdateEnd is sent - eval('rpcnotify('..channel..', "Hello There")') - expectn('Hello There', {}) - - -- reopen the original buffer, make sure Live Updates are still active - command('b1') - command('normal! x') - tick = tick + 1 - expectn('LiveUpdate', {b, tick, 0, 1, {'AA'}}) - end) - - it('turns off live updates when a buffer is unloaded, deleted, or wiped', - function() - -- start with a blank nvim - helpers.clear() - -- need to make a new window with a buffer because :bunload doesn't let you - -- unload the last buffer - for _, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do - command('new') - -- open a brand spanking new file - local b = open(true, {'AAA'}) - - -- call :bunload or whatever the command is, and then check that we - -- receive a LiveUpdateEnd - command(cmd) - expectn('LiveUpdateEnd', {b}) - end - end) - - it('doesn\'t send the buffer\'s content when not requested', function() - helpers.clear() - local b, tick = editoriginal(false) - ok(buffer('live_updates_start', b, false)) - expectn('LiveUpdateStart', {b, tick, {}, false}) - end) - -end) -- cgit From 5aa8af7cdb5a2a8ed2cef02e6d7a0b9a2c714140 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 12 Feb 2018 21:41:21 +0100 Subject: Increase sendkeys timeout --- test/functional/api/buffer_updates_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index c3a1754cf3..cb20184a50 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -20,7 +20,7 @@ local function sendkeys(keys) -- give neovim 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.01 + local ntime = os.clock() + 0.1 repeat until os.clock() > ntime end -- cgit From de5d1e863c71c8da87422bdb94dc91749d4a8b61 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 12 Feb 2018 22:49:35 +0100 Subject: Try fixing that test on travis --- test/functional/api/buffer_updates_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index cb20184a50..b30d0805bd 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -242,7 +242,7 @@ describe('liveupdate', function() -- modify multiple lines at once using visual block mode tick = reopen(b, origlines) command('normal! jjw') - sendkeys('\x16jjllx') + sendkeys('jjllx') tick = tick + 1 expectn('nvim_buf_update', {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}}) -- cgit From e7451f8a91e0a9452fc3c3627ac60dc80288252c Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Tue, 24 Apr 2018 20:38:00 +0200 Subject: Some renamings and doc changes --- test/functional/api/buffer_updates_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index b30d0805bd..7659961e90 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -336,7 +336,7 @@ describe('liveupdate', function() tick = tick + 1 expectn('nvim_buf_update', {b, tick, 1, 2, {}}) tick = tick + 1 - expectn('nvim_buf_update_tick', {b, tick}) + expectn('nvim_buf_changedtick', {b, tick}) command('set autoindent') command('normal! >>') tick = tick + 1 @@ -354,7 +354,7 @@ describe('liveupdate', function() tick = tick + 1 expectn('nvim_buf_update', {b, tick, 1, 2, {}}) tick = tick + 1 - expectn('nvim_buf_update_tick', {b, tick}) + expectn('nvim_buf_changedtick', {b, tick}) command('normal! ggOmmm') tick = tick + 1 expectn('nvim_buf_update', {b, tick, 0, 0, {"\t"}}) @@ -374,7 +374,7 @@ describe('liveupdate', function() tick = tick + 1 expectn('nvim_buf_update', {b, tick, 0, 1, {'Line 1'}}) tick = tick + 1 - expectn('nvim_buf_update_tick', {b, tick}) + expectn('nvim_buf_changedtick', {b, tick}) -- change the file directly local f = io.open(filename, 'a') @@ -410,7 +410,7 @@ describe('liveupdate', function() tick1 = tick1 + 1 expectn('nvim_buf_update', {b1, tick1, 0, 1, {'A1'}}) tick1 = tick1 + 1 - expectn('nvim_buf_update_tick', {b1, tick1}) + expectn('nvim_buf_changedtick', {b1, tick1}) command('b'..b2nr) command('normal! x') @@ -420,7 +420,7 @@ describe('liveupdate', function() tick2 = tick2 + 1 expectn('nvim_buf_update', {b2, tick2, 0, 1, {'B1'}}) tick2 = tick2 + 1 - expectn('nvim_buf_update_tick', {b2, tick2}) + expectn('nvim_buf_changedtick', {b2, tick2}) command('b'..b3nr) command('normal! x') @@ -430,7 +430,7 @@ describe('liveupdate', function() tick3 = tick3 + 1 expectn('nvim_buf_update', {b3, tick3, 0, 1, {'C1'}}) tick3 = tick3 + 1 - expectn('nvim_buf_update_tick', {b3, tick3}) + expectn('nvim_buf_changedtick', {b3, tick3}) end) it('doesn\'t get confused when you turn watching on/off many times', @@ -512,8 +512,8 @@ describe('liveupdate', function() wantn(2, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) wantn(3, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) tick = tick + 1 - wantn(2, 'nvim_buf_update_tick', {b, tick}) - wantn(3, 'nvim_buf_update_tick', {b, tick}) + wantn(2, 'nvim_buf_changedtick', {b, tick}) + wantn(3, 'nvim_buf_changedtick', {b, tick}) -- make sure there are no other pending nvim_buf_update messages going to -- channel 1 @@ -665,7 +665,7 @@ describe('liveupdate', function() tick = tick + 1 expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) tick = tick + 1 - expectn('nvim_buf_update_tick', {b, tick}) + expectn('nvim_buf_changedtick', {b, tick}) -- close our buffer by creating a new one command('enew') @@ -692,7 +692,7 @@ describe('liveupdate', function() tick = tick + 1 expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) tick = tick + 1 - expectn('nvim_buf_update_tick', {b, tick}) + expectn('nvim_buf_changedtick', {b, tick}) -- close our buffer by creating a new one command('set hidden') -- cgit From 3866137eed6b6e649ac95e53ad246e977f9ac2ae Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Tue, 24 Apr 2018 21:41:59 +0200 Subject: Update test --- test/functional/api/buffer_updates_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 7659961e90..0eec59bd65 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local eq, ok = helpers.eq, helpers.ok -local buffer, command, eval, nvim, next_message = helpers.buffer, +local buffer, command, eval, nvim, next_msg = helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg local origlines = {"original line 1", @@ -12,7 +12,7 @@ local origlines = {"original line 1", local function expectn(name, args) -- expect the next message to be the specified notification event - eq({'notification', name, args}, next_message()) + eq({'notification', name, args}, next_msg()) end local function sendkeys(keys) @@ -88,8 +88,8 @@ local function reopenwithfolds(b) return tick end -describe('liveupdate', function() - it('knows when you add line to a buffer', function() +describe('buffer events', function() + it('when you add line to a buffer', function() local b, tick = editoriginal(true) -- add a new line at the start of the buffer -- cgit From ad151847f179e51d70cbde9440e765c2a451a7f6 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Thu, 10 May 2018 15:47:00 +0200 Subject: Unify updates_start and updates to lines_event Also rename changedtick -> changedtick_event --- test/functional/api/buffer_updates_spec.lua | 224 ++++++++++++++-------------- 1 file changed, 113 insertions(+), 111 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 0eec59bd65..3f15c8a8a5 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -32,11 +32,12 @@ local function open(activate, lines) -- what is the value of b:changedtick? local tick = eval('b:changedtick') - -- turn on live updates, ensure that the nvim_buf_updates_start messages + -- turn on live updates, ensure that the nvim_buf_lines_event messages -- arrive as expectected if activate then + local firstline = 0 ok(buffer('attach', b, true)) - expectn('nvim_buf_updates_start', {b, tick, lines, false}) + expectn('nvim_buf_lines_event', {b, tick, firstline, -1, lines, false}) end return b, tick, filename @@ -58,7 +59,8 @@ local function reopen(buf, expectedlines) command('edit!') local tick = eval('b:changedtick') ok(buffer('attach', buf, true)) - expectn('nvim_buf_updates_start', {buf, tick, expectedlines, false}) + local firstline = 0 + expectn('nvim_buf_lines_event', {buf, tick, firstline, -1, expectedlines, false}) command('normal! gg') return tick end @@ -73,18 +75,18 @@ local function reopenwithfolds(b) -- add a fold command('2,4fold') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 4, {'original line 2/*{{{*/', + expectn('nvim_buf_lines_event', {b, tick, 1, 4, {'original line 2/*{{{*/', 'original line 3', - 'original line 4/*}}}*/'}}) + 'original line 4/*}}}*/'}, false}) -- make a new fold that wraps lines 1-6 command('1,6fold') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 6, {'original line 1/*{{{*/', + expectn('nvim_buf_lines_event', {b, tick, 0, 6, {'original line 1/*{{{*/', 'original line 2/*{{{*/', 'original line 3', 'original line 4/*}}}*/', 'original line 5', - 'original line 6/*}}}*/'}}) + 'original line 6/*}}}*/'}, false}) return tick end @@ -95,47 +97,47 @@ describe('buffer events', function() -- add a new line at the start of the buffer command('normal! GyyggP') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 0, {'original line 6'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 0, {'original line 6'}, false}) -- add multiple lines at the start of the file command('normal! GkkyGggP') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 0, {'original line 4', + expectn('nvim_buf_lines_event', {b, tick, 0, 0, {'original line 4', 'original line 5', - 'original line 6'}}) + 'original line 6'}, false}) -- add one line to the middle of the file, several times command('normal! ggYjjp') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 3, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 3, {'original line 4'}, false}) command('normal! p') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 4, 4, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 4, 4, {'original line 4'}, false}) command('normal! p') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 5, 5, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 5, 5, {'original line 4'}, false}) -- add multiple lines to the middle of the file command('normal! gg4Yjjp') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 3, {'original line 4', + expectn('nvim_buf_lines_event', {b, tick, 3, 3, {'original line 4', 'original line 5', 'original line 6', - 'original line 4'}}) + 'original line 4'}, false}) -- add one line to the end of the file command('normal! ggYGp') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 17, 17, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 17, 17, {'original line 4'}, false}) -- add one line to the end of the file, several times command('normal! ggYGppp') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 18, 18, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 18, 18, {'original line 4'}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 19, 19, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 19, 19, {'original line 4'}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 20, 20, {'original line 4'}}) + expectn('nvim_buf_lines_event', {b, tick, 20, 20, {'original line 4'}, false}) -- add several lines to the end of the file, several times command('normal! gg4YGp') @@ -146,11 +148,11 @@ describe('buffer events', function() 'original line 6', 'original line 4'} tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 21, 21, firstfour}) + expectn('nvim_buf_lines_event', {b, tick, 21, 21, firstfour, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 25, 25, firstfour}) + expectn('nvim_buf_lines_event', {b, tick, 25, 25, firstfour, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 29, 29, firstfour}) + 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 @@ -162,10 +164,10 @@ describe('buffer events', function() tick = eval('b:changedtick') local b2 = nvim('get_current_buf') ok(buffer('attach', b2, true)) - expectn('nvim_buf_updates_start', {b2, tick, {""}, false}) + expectn('nvim_buf_lines_event', {b2, tick, 0, -1, {""}, false}) eval('append(0, ["new line 1"])') tick = tick + 1 - expectn('nvim_buf_update', {b2, tick, 0, 0, {'new line 1'}}) + expectn('nvim_buf_lines_event', {b2, tick, 0, 0, {'new line 1'}, false}) -- turn off live updates manually buffer('detach', b2) @@ -176,17 +178,17 @@ describe('buffer events', function() local b3 = nvim('get_current_buf') ok(buffer('attach', b3, true)) tick = eval('b:changedtick') - expectn('nvim_buf_updates_start', {b3, tick, {""}, false}) + expectn('nvim_buf_lines_event', {b3, tick, 0, -1, {""}, false}) eval('append(0, ["new line 1", "new line 2", "new line 3"])') tick = tick + 1 - expectn('nvim_buf_update', {b3, tick, 0, 0, {'new line 1', + expectn('nvim_buf_lines_event', {b3, tick, 0, 0, {'new line 1', 'new line 2', - 'new line 3'}}) + 'new line 3'}, false}) -- use the API itself to add a line to the start of the buffer buffer('set_lines', b3, 0, 0, true, {'New First Line'}) tick = tick + 1 - expectn('nvim_buf_update', {b3, tick, 0, 0, {"New First Line"}}) + expectn('nvim_buf_lines_event', {b3, tick, 0, 0, {"New First Line"}, false}) end) it('knows when you remove lines from a buffer', function() @@ -195,37 +197,37 @@ describe('buffer events', function() -- remove one line from start of file command('normal! dd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {}, false}) -- remove multiple lines from the start of the file command('normal! 4dd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 4, {}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 4, {}, false}) -- remove multiple lines from middle of file tick = reopen(b, origlines) command('normal! jj3dd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 5, {}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 5, {}, false}) -- remove one line from the end of the file tick = reopen(b, origlines) command('normal! Gdd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 5, 6, {}}) + expectn('nvim_buf_lines_event', {b, tick, 5, 6, {}, false}) -- remove multiple lines from the end of the file tick = reopen(b, origlines) command('normal! 4G3dd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 6, {}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 6, {}, false}) -- pretend to remove heaps lines from the end of the file but really -- just remove two tick = reopen(b, origlines) command('normal! Gk5dd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 4, 6, {}}) + expectn('nvim_buf_lines_event', {b, tick, 4, 6, {}, false}) end) it('knows when you modify lines of text', function() @@ -234,32 +236,32 @@ describe('buffer events', function() -- some normal text editing command('normal! A555') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'original line 1555'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'original line 1555'}, false}) command('normal! jj8X') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 3, {'origin3'}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'origin3'}, false}) -- modify multiple lines at once using visual block mode tick = reopen(b, origlines) command('normal! jjw') sendkeys('jjllx') tick = tick + 1 - expectn('nvim_buf_update', - {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}}) + expectn('nvim_buf_lines_event', + {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}, false}) -- replace part of a line line using :s tick = reopen(b, origlines) command('3s/line 3/foo/') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 3, {'original foo'}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original foo'}, false}) -- replace parts of several lines line using :s tick = reopen(b, origlines) command('%s/line [35]/foo/') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 5, {'original foo', + expectn('nvim_buf_lines_event', {b, tick, 2, 5, {'original foo', 'original line 4', - 'original foo'}}) + 'original foo'}, false}) -- type text into the first line of a blank file, one character at a time command('enew!') @@ -267,20 +269,20 @@ describe('buffer events', function() expectn('nvim_buf_updates_end', {b}) local bnew = nvim('get_current_buf') ok(buffer('attach', bnew, true)) - expectn('nvim_buf_updates_start', {bnew, tick, {''}, false}) + expectn('nvim_buf_lines_event', {bnew, tick, 0, -1, {''}, false}) sendkeys('i') sendkeys('h') sendkeys('e') sendkeys('l') sendkeys('l') sendkeys('o\nworld') - expectn('nvim_buf_update', {bnew, tick + 1, 0, 1, {'h'}}) - expectn('nvim_buf_update', {bnew, tick + 2, 0, 1, {'he'}}) - expectn('nvim_buf_update', {bnew, tick + 3, 0, 1, {'hel'}}) - expectn('nvim_buf_update', {bnew, tick + 4, 0, 1, {'hell'}}) - expectn('nvim_buf_update', {bnew, tick + 5, 0, 1, {'hello'}}) - expectn('nvim_buf_update', {bnew, tick + 6, 0, 1, {'hello', ''}}) - expectn('nvim_buf_update', {bnew, tick + 7, 1, 2, {'world'}}) + expectn('nvim_buf_lines_event', {bnew, tick + 1, 0, 1, {'h'}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 2, 0, 1, {'he'}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 3, 0, 1, {'hel'}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 4, 0, 1, {'hell'}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 5, 0, 1, {'hello'}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 6, 0, 1, {'hello', ''}, false}) + expectn('nvim_buf_lines_event', {bnew, tick + 7, 1, 2, {'world'}, false}) end) it('knows when you replace lines', function() @@ -289,23 +291,23 @@ describe('buffer events', function() -- blast away parts of some lines with visual mode command('normal! jjwvjjllx') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 3, {'original '}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original '}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 4, {'e 5'}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 4, {'e 5'}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 3, {'original e 5'}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original e 5'}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) -- blast away a few lines using :g tick = reopen(b, origlines) command('global/line [35]/delete') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 2, 3, {}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 3, {}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 4, {}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) end) it('knows when you filter lines', function() @@ -317,9 +319,9 @@ describe('buffer events', function() -- 1) addition of the new lines after the filtered lines -- 2) removal of the original lines tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 5, 5, {"C", "E", "B", "D"}}) + expectn('nvim_buf_lines_event', {b, tick, 5, 5, {"C", "E", "B", "D"}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 5, {}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 5, {}, false}) end) it('sends a sensible event when you use "o"', function() @@ -329,37 +331,37 @@ describe('buffer events', function() -- use 'o' to start a new line from a line with no indent command('normal! o') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 1, {""}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 1, {""}, false}) -- undo the change, indent line 1 a bit, and try again command('undo') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 2, {}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) tick = tick + 1 expectn('nvim_buf_changedtick', {b, tick}) command('set autoindent') command('normal! >>') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {"\tAAA"}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {"\tAAA"}, false}) command('normal! ommm') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 1, {"\t"}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 1, {"\t"}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 2, {"\tmmm"}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 2, {"\tmmm"}, false}) -- undo the change, and try again with 'O' command('undo') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 2, {'\t'}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 2, {'\t'}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 2, {}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) tick = tick + 1 expectn('nvim_buf_changedtick', {b, tick}) command('normal! ggOmmm') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 0, {"\t"}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 0, {"\t"}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {"\tmmm"}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {"\tmmm"}, false}) end) it('deactivates when your buffer changes outside vim', function() @@ -369,10 +371,10 @@ describe('buffer events', function() command('normal! x') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'ine 1'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'ine 1'}, false}) command('undo') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'Line 1'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'Line 1'}, false}) tick = tick + 1 expectn('nvim_buf_changedtick', {b, tick}) @@ -405,30 +407,30 @@ describe('buffer events', function() command('b'..b1nr) command('normal! x') tick1 = tick1 + 1 - expectn('nvim_buf_update', {b1, tick1, 0, 1, {'1'}}) + expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'1'}, false}) command('undo') tick1 = tick1 + 1 - expectn('nvim_buf_update', {b1, tick1, 0, 1, {'A1'}}) + expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'A1'}, false}) tick1 = tick1 + 1 expectn('nvim_buf_changedtick', {b1, tick1}) command('b'..b2nr) command('normal! x') tick2 = tick2 + 1 - expectn('nvim_buf_update', {b2, tick2, 0, 1, {'1'}}) + expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'1'}, false}) command('undo') tick2 = tick2 + 1 - expectn('nvim_buf_update', {b2, tick2, 0, 1, {'B1'}}) + expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'B1'}, false}) tick2 = tick2 + 1 expectn('nvim_buf_changedtick', {b2, tick2}) command('b'..b3nr) command('normal! x') tick3 = tick3 + 1 - expectn('nvim_buf_update', {b3, tick3, 0, 1, {'1'}}) + expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'1'}, false}) command('undo') tick3 = tick3 + 1 - expectn('nvim_buf_update', {b3, tick3, 0, 1, {'C1'}}) + expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'C1'}, false}) tick3 = tick3 + 1 expectn('nvim_buf_changedtick', {b3, tick3}) end) @@ -444,7 +446,7 @@ describe('buffer events', function() ok(buffer('attach', b, true)) ok(buffer('attach', b, true)) ok(buffer('attach', b, true)) - expectn('nvim_buf_updates_start', {b, tick, origlines, false}) + expectn('nvim_buf_lines_event', {b, tick, 0, -1, origlines, false}) eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) @@ -491,16 +493,16 @@ describe('buffer events', function() ok(request(1, 'nvim_buf_attach', b, true)) ok(request(2, 'nvim_buf_attach', b, true)) ok(request(3, 'nvim_buf_attach', b, true)) - wantn(1, 'nvim_buf_updates_start', {b, tick, lines, false}) - wantn(2, 'nvim_buf_updates_start', {b, tick, lines, false}) - wantn(3, 'nvim_buf_updates_start', {b, tick, 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(3, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) -- make a change to the buffer command('normal! x') tick = tick + 1 - wantn(1, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) - wantn(2, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) - wantn(3, 'nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + 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 ok(request(1, 'nvim_buf_detach', b)) @@ -509,13 +511,13 @@ describe('buffer events', function() -- undo the change to buffer 1 command('undo') tick = tick + 1 - wantn(2, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) - wantn(3, 'nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) + wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 wantn(2, 'nvim_buf_changedtick', {b, tick}) wantn(3, 'nvim_buf_changedtick', {b, tick}) - -- make sure there are no other pending nvim_buf_update messages going to + -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 local channel1 = request(1, 'nvim_get_api_info')[1] eval('rpcnotify('..channel1..', "Hello")') @@ -527,7 +529,7 @@ describe('buffer events', function() wantn(2, 'nvim_buf_updates_end', {b}) wantn(3, 'nvim_buf_updates_end', {b}) - -- make sure there are no other pending nvim_buf_update messages going to + -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 channel1 = request(1, 'nvim_get_api_info')[1] eval('rpcnotify('..channel1..', "Hello Again")') @@ -550,13 +552,13 @@ describe('buffer events', function() command('normal! gg') command('diffput') tick2 = tick2 + 1 - expectn('nvim_buf_update', {b2, tick2, 0, 0, {"AAA"}}) + expectn('nvim_buf_lines_event', {b2, tick2, 0, 0, {"AAA"}, false}) -- use :diffget to grab the other change from buffer 2 command('normal! G') command('diffget') tick1 = tick1 + 1 - expectn('nvim_buf_update', {b1, tick1, 2, 2, {"CCC"}}) + expectn('nvim_buf_lines_event', {b1, tick1, 2, 2, {"CCC"}, false}) eval('rpcnotify('..channel..', "Goodbye")') expectn('Goodbye', {}) @@ -567,14 +569,14 @@ describe('buffer events', function() local b, tick = editoriginal(true, {"B", "D", "C", "A", "E"}) command('%sort') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}, false}) end) it('works with :left', function() local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) command('2,4left') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 4, {"B", "B", "B"}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 4, {"B", "B", "B"}, false}) end) it('works with :right', function() @@ -586,7 +588,7 @@ describe('buffer events', function() command('set ts=2 et') command('2,4retab') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 4, {" B", " BB", " B"}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 4, {" B", " BB", " B"}, false}) end) it('works with :move', function() @@ -594,19 +596,19 @@ describe('buffer events', function() -- move text down towards the end of the file command('2,3move 4') tick = tick + 2 - expectn('nvim_buf_update', {b, tick, 4, 4, {"original line 2", - "original line 3"}}) + expectn('nvim_buf_lines_event', {b, tick, 4, 4, {"original line 2", + "original line 3"}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 3, {}}) + expectn('nvim_buf_lines_event', {b, tick, 1, 3, {}, false}) -- move text up towards the start of the file tick = reopen(b, origlines) command('4,5move 2') tick = tick + 2 - expectn('nvim_buf_update', {b, tick, 2, 2, {"original line 4", - "original line 5"}}) + expectn('nvim_buf_lines_event', {b, tick, 2, 2, {"original line 4", + "original line 5"}, false}) tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 5, 7, {}}) + expectn('nvim_buf_lines_event', {b, tick, 5, 7, {}, false}) end) it('sends sensible events when you manually add/remove folds', function() @@ -616,13 +618,13 @@ describe('buffer events', function() -- delete the inner fold command('normal! zR3Gzd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 1, 4, {'original line 2', + expectn('nvim_buf_lines_event', {b, tick, 1, 4, {'original line 2', 'original line 3', - 'original line 4'}}) + 'original line 4'}, false}) -- delete the outer fold command('normal! zd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) -- discard changes and put the folds back tick = reopenwithfolds(b) @@ -630,7 +632,7 @@ describe('buffer events', function() -- remove both folds at once command('normal! ggzczD') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) -- discard changes and put the folds back tick = reopenwithfolds(b) @@ -638,19 +640,19 @@ describe('buffer events', function() -- now delete all folds at once command('normal! zE') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 6, origlines}) + expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) -- create a fold from line 4 to the end of the file command('normal! 4GA/*{{{*/') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 4, {'original line 4/*{{{*/'}}) + expectn('nvim_buf_lines_event', {b, tick, 3, 4, {'original line 4/*{{{*/'}, false}) -- delete the fold which only has one marker command('normal! Gzd') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 3, 6, {'original line 4', + expectn('nvim_buf_lines_event', {b, tick, 3, 6, {'original line 4', 'original line 5', - 'original line 6'}}) + 'original line 6'}, false}) end) it('turns off updates when a buffer is closed', function() @@ -660,10 +662,10 @@ describe('buffer events', function() -- test live updates are working command('normal! x') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) command('undo') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 expectn('nvim_buf_changedtick', {b, tick}) @@ -687,10 +689,10 @@ describe('buffer events', function() -- test live updates are working command('normal! x') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) command('undo') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'AAA'}}) + expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 expectn('nvim_buf_changedtick', {b, tick}) @@ -706,7 +708,7 @@ describe('buffer events', function() command('b1') command('normal! x') tick = tick + 1 - expectn('nvim_buf_update', {b, tick, 0, 1, {'AA'}}) + 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', @@ -731,7 +733,7 @@ describe('buffer events', function() helpers.clear() local b, tick = editoriginal(false) ok(buffer('attach', b, false)) - expectn('nvim_buf_updates_start', {b, tick, {}, false}) + expectn('nvim_buf_lines_event', {b, tick, -1, -1, {}, false}) end) end) -- cgit From 0bee3925ab5186211f10c823d4f149d4d16eb7a5 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Thu, 10 May 2018 23:13:58 +0200 Subject: Send changedtick as first event if buffer contents weren't requested --- test/functional/api/buffer_updates_spec.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 3f15c8a8a5..1bbba91187 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -338,7 +338,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) tick = tick + 1 - expectn('nvim_buf_changedtick', {b, tick}) + expectn('nvim_buf_changedtick_event', {b, tick}) command('set autoindent') command('normal! >>') tick = tick + 1 @@ -356,7 +356,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) tick = tick + 1 - expectn('nvim_buf_changedtick', {b, tick}) + expectn('nvim_buf_changedtick_event', {b, tick}) command('normal! ggOmmm') tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 0, {"\t"}, false}) @@ -376,7 +376,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'Line 1'}, false}) tick = tick + 1 - expectn('nvim_buf_changedtick', {b, tick}) + expectn('nvim_buf_changedtick_event', {b, tick}) -- change the file directly local f = io.open(filename, 'a') @@ -412,7 +412,7 @@ describe('buffer events', function() tick1 = tick1 + 1 expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'A1'}, false}) tick1 = tick1 + 1 - expectn('nvim_buf_changedtick', {b1, tick1}) + expectn('nvim_buf_changedtick_event', {b1, tick1}) command('b'..b2nr) command('normal! x') @@ -422,7 +422,7 @@ describe('buffer events', function() tick2 = tick2 + 1 expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'B1'}, false}) tick2 = tick2 + 1 - expectn('nvim_buf_changedtick', {b2, tick2}) + expectn('nvim_buf_changedtick_event', {b2, tick2}) command('b'..b3nr) command('normal! x') @@ -432,7 +432,7 @@ describe('buffer events', function() tick3 = tick3 + 1 expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'C1'}, false}) tick3 = tick3 + 1 - expectn('nvim_buf_changedtick', {b3, tick3}) + expectn('nvim_buf_changedtick_event', {b3, tick3}) end) it('doesn\'t get confused when you turn watching on/off many times', @@ -514,8 +514,8 @@ describe('buffer events', function() wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 - wantn(2, 'nvim_buf_changedtick', {b, tick}) - wantn(3, 'nvim_buf_changedtick', {b, tick}) + wantn(2, 'nvim_buf_changedtick_event', {b, tick}) + wantn(3, 'nvim_buf_changedtick_event', {b, tick}) -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 @@ -667,7 +667,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 - expectn('nvim_buf_changedtick', {b, tick}) + expectn('nvim_buf_changedtick_event', {b, tick}) -- close our buffer by creating a new one command('enew') @@ -694,7 +694,7 @@ describe('buffer events', function() tick = tick + 1 expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) tick = tick + 1 - expectn('nvim_buf_changedtick', {b, tick}) + expectn('nvim_buf_changedtick_event', {b, tick}) -- close our buffer by creating a new one command('set hidden') @@ -733,7 +733,7 @@ describe('buffer events', function() helpers.clear() local b, tick = editoriginal(false) ok(buffer('attach', b, false)) - expectn('nvim_buf_lines_event', {b, tick, -1, -1, {}, false}) + expectn('nvim_buf_changedtick_event', {b, tick}) end) end) -- cgit From 65e7f6f0b97b02e323488e06bf0f5df93bbcbf93 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 18 May 2018 10:09:11 +0200 Subject: Rename some more, fixe borked renaming --- test/functional/api/buffer_updates_spec.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 1bbba91187..cb5de4e206 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -54,7 +54,7 @@ end local function reopen(buf, expectedlines) ok(buffer('detach', buf)) - expectn('nvim_buf_updates_end', {buf}) + expectn('nvim_buf_detach_event', {buf}) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') @@ -157,7 +157,7 @@ describe('buffer events', function() -- create a new empty buffer and wipe out the old one ... this will -- turn off live updates command('enew!') - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) -- add a line at the start of an empty file command('enew') @@ -171,7 +171,7 @@ describe('buffer events', function() -- turn off live updates manually buffer('detach', b2) - expectn('nvim_buf_updates_end', {b2}) + expectn('nvim_buf_detach_event', {b2}) -- add multiple lines to a blank file command('enew!') @@ -266,7 +266,7 @@ describe('buffer events', function() -- type text into the first line of a blank file, one character at a time command('enew!') tick = 2 - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) local bnew = nvim('get_current_buf') ok(buffer('attach', bnew, true)) expectn('nvim_buf_lines_event', {bnew, tick, 0, -1, {''}, false}) @@ -386,7 +386,7 @@ describe('buffer events', function() -- reopen the file and watch live updates shut down command('edit') - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) end) it('allows a channel to watch multiple buffers at once', function() @@ -456,7 +456,7 @@ describe('buffer events', function() ok(buffer('detach', b)) ok(buffer('detach', b)) ok(buffer('detach', b)) - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) eval('rpcnotify('..channel..', "Hello Again")') expectn('Hello Again', {}) end) @@ -506,7 +506,7 @@ describe('buffer events', function() -- stop watching on channel 1 ok(request(1, 'nvim_buf_detach', b)) - wantn(1, 'nvim_buf_updates_end', {b}) + wantn(1, 'nvim_buf_detach_event', {b}) -- undo the change to buffer 1 command('undo') @@ -523,11 +523,11 @@ describe('buffer events', function() eval('rpcnotify('..channel1..', "Hello")') wantn(1, 'Hello', {}) - -- close the buffer and channels 2 and 3 should get a nvim_buf_updates_end + -- close the buffer and channels 2 and 3 should get a nvim_buf_detach_event -- notification command('edit') - wantn(2, 'nvim_buf_updates_end', {b}) - wantn(3, 'nvim_buf_updates_end', {b}) + wantn(2, 'nvim_buf_detach_event', {b}) + wantn(3, 'nvim_buf_detach_event', {b}) -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 @@ -671,7 +671,7 @@ describe('buffer events', function() -- close our buffer by creating a new one command('enew') - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) -- reopen the original buffer, make sure there are no Live Updates sent command('b1') @@ -700,7 +700,7 @@ describe('buffer events', function() command('set hidden') command('enew') - -- note that no nvim_buf_updates_end is sent + -- note that no nvim_buf_detach_event is sent eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) @@ -723,9 +723,9 @@ describe('buffer events', function() local b = open(true, {'AAA'}) -- call :bunload or whatever the command is, and then check that we - -- receive a nvim_buf_updates_end + -- receive a nvim_buf_detach_event command(cmd) - expectn('nvim_buf_updates_end', {b}) + expectn('nvim_buf_detach_event', {b}) end end) -- cgit From 333679ad0ea6cb387debeae37645ecc0a830de25 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 21 May 2018 20:42:59 +0200 Subject: Add empty options dict to buf_attach --- test/functional/api/buffer_updates_spec.lua | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index cb5de4e206..00409c1528 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) 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 origlines = {"original line 1", "original line 2", @@ -36,7 +37,7 @@ local function open(activate, lines) -- arrive as expectected if activate then local firstline = 0 - ok(buffer('attach', b, true)) + ok(buffer('attach', b, true, {})) expectn('nvim_buf_lines_event', {b, tick, firstline, -1, lines, false}) end @@ -58,7 +59,7 @@ local function reopen(buf, expectedlines) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') - ok(buffer('attach', buf, true)) + ok(buffer('attach', buf, true, {})) local firstline = 0 expectn('nvim_buf_lines_event', {buf, tick, firstline, -1, expectedlines, false}) command('normal! gg') @@ -163,7 +164,7 @@ describe('buffer events', function() command('enew') tick = eval('b:changedtick') 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}) eval('append(0, ["new line 1"])') tick = tick + 1 @@ -176,7 +177,7 @@ describe('buffer events', function() -- add multiple lines to a blank file command('enew!') local b3 = nvim('get_current_buf') - ok(buffer('attach', b3, true)) + ok(buffer('attach', b3, true, {})) tick = eval('b:changedtick') expectn('nvim_buf_lines_event', {b3, tick, 0, -1, {""}, false}) eval('append(0, ["new line 1", "new line 2", "new line 3"])') @@ -268,7 +269,7 @@ describe('buffer events', function() tick = 2 expectn('nvim_buf_detach_event', {b}) 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}) sendkeys('i') sendkeys('h') @@ -441,11 +442,11 @@ describe('buffer events', function() local b, tick = editoriginal(false) -- 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}) eval('rpcnotify('..channel..', "Hello There")') expectn('Hello There', {}) @@ -490,9 +491,9 @@ describe('buffer events', function() local b, tick = open(false, lines) -- turn on live updates 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)) + ok(request(1, 'nvim_buf_attach', b, true, {})) + ok(request(2, '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(2, '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() helpers.clear() local b, tick = editoriginal(false) - ok(buffer('attach', b, false)) + ok(buffer('attach', b, false, {})) expectn('nvim_buf_changedtick_event', {b, tick}) 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) -- cgit