diff options
author | KillTheMule <KillTheMule@users.noreply.github.com> | 2018-07-01 14:40:51 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-07-01 14:42:56 +0200 |
commit | 40911e435e8aa4d568b5b9892272505509058063 (patch) | |
tree | 12aadd9a5621932269cdee6f617a01932a8219a9 /test/functional/api/buffer_updates_spec.lua | |
parent | 70626e6a1eb9c82a5eb4e3b55abfd474908ef501 (diff) | |
download | rneovim-40911e435e8aa4d568b5b9892272505509058063.tar.gz rneovim-40911e435e8aa4d568b5b9892272505509058063.tar.bz2 rneovim-40911e435e8aa4d568b5b9892272505509058063.zip |
API: emit nvim_buf_lines_event from :terminal #8616
closes #8575
Diffstat (limited to 'test/functional/api/buffer_updates_spec.lua')
-rw-r--r-- | test/functional/api/buffer_updates_spec.lua | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 6da790b871..1d5e31fee4 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -3,6 +3,7 @@ local eq, ok = helpers.eq, helpers.ok local buffer, command, eval, nvim, next_msg = helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg local expect_err = helpers.expect_err +local nvim_prog = helpers.nvim_prog local write_file = helpers.write_file local origlines = {"original line 1", @@ -741,3 +742,88 @@ describe('API: buffer events:', function() end) end) + +describe('API: buffer events:', function() + before_each(function() + helpers.clear() + end) + + local function lines_subset(first, second) + for i = 1,#first do + if first[i] ~= second[i] then + return false + end + end + return true + end + + local function lines_equal(f, s) + return lines_subset(f, s) and lines_subset(s, f) + end + + local function assert_match_somewhere(expected_lines, buffer_lines) + local msg = next_msg() + + while(msg ~= nil) do + local event = msg[2] + if event == 'nvim_buf_lines_event' then + local args = msg[3] + local starts = args[3] + local newlines = args[5] + + -- Size of the contained nvim instance is 23 lines, this might change + -- with the test setup. Note updates are continguous. + assert(#newlines <= 23) + + for i = 1,#newlines do + buffer_lines[starts + i] = newlines[i] + end + -- we don't compare the msg area of the embedded nvim, it's too flakey + buffer_lines[23] = nil + + if lines_equal(buffer_lines, expected_lines) then + -- OK + return + end + end + msg = next_msg() + end + assert(false, 'did not match/receive expected nvim_buf_lines_event lines') + end + + it('when :terminal lines change', function() + local buffer_lines = {} + local expected_lines = {} + command('terminal "'..nvim_prog..'" -u NONE -i NONE -n -c "set shortmess+=A"') + local b = nvim('get_current_buf') + ok(buffer('attach', b, true, {})) + + for _ = 1,22 do + table.insert(expected_lines,'~') + end + expected_lines[1] = '' + expected_lines[22] = ('tmp_terminal_nvim'..(' '):rep(45) + ..'0,0-1 All') + + sendkeys('i:e tmp_terminal_nvim<Enter>') + assert_match_somewhere(expected_lines, buffer_lines) + + expected_lines[1] = 'Blarg' + expected_lines[22] = ('tmp_terminal_nvim [+]'..(' '):rep(41) + ..'1,6 All') + + sendkeys('iBlarg') + assert_match_somewhere(expected_lines, buffer_lines) + + for i = 1,21 do + expected_lines[i] = 'xyz' + end + expected_lines[22] = ('tmp_terminal_nvim [+]'..(' '):rep(41) + ..'31,4 Bot') + + local s = string.rep('\nxyz', 30) + sendkeys(s) + assert_match_somewhere(expected_lines, buffer_lines) + end) + +end) |