aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/terminal.c4
-rw-r--r--test/functional/api/buffer_updates_spec.lua86
-rw-r--r--test/functional/fixtures/tty-test.c7
3 files changed, 93 insertions, 4 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index c2370de0f8..6907529726 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1239,9 +1239,7 @@ static void refresh_screen(Terminal *term, buf_T *buf)
int change_start = row_to_linenr(term, term->invalid_start);
int change_end = change_start + changed;
- changed_lines(change_start, 0, change_end, added,
- // Don't send nvim_buf_lines_event for :terminal buffer.
- false);
+ changed_lines(change_start, 0, change_end, added, true);
term->invalid_start = INT_MAX;
term->invalid_end = -1;
}
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)
diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c
index 4f0858acdb..5f1f5cb91c 100644
--- a/test/functional/fixtures/tty-test.c
+++ b/test/functional/fixtures/tty-test.c
@@ -150,7 +150,12 @@ int main(int argc, char **argv)
}
if (argc > 1) {
- int count = atoi(argv[1]);
+ errno = 0;
+ int count = (int)strtol(argv[1], NULL, 10);
+ if (errno != 0) {
+ abort();
+ }
+ count = (count < 0 || count > 99999) ? 0 : count;
for (int i = 0; i < count; i++) {
printf("line%d\n", i);
}