fix(bytetrack): send correct events when opening lines

a bit of test cleanup

ärrår

feeel

SPLIT

fix: sned correct updates on <CR>
This commit is contained in:
Thomas Vigouroux 2020-09-10 18:52:56 +02:00
parent 5581ac88c6
commit f0e258cf85
3 changed files with 88 additions and 14 deletions

View File

@ -1677,6 +1677,9 @@ int open_line(
truncate_spaces(saved_line); truncate_spaces(saved_line);
} }
ml_replace(curwin->w_cursor.lnum, saved_line, false); ml_replace(curwin->w_cursor.lnum, saved_line, false);
extmark_splice_cols(
curbuf, (int)curwin->w_cursor.lnum,
0, curwin->w_cursor.col, (int)STRLEN(saved_line), kExtmarkUndo);
saved_line = NULL; saved_line = NULL;
if (did_append) { if (did_append) {
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,

View File

@ -1,10 +1,13 @@
-- Test suite for testing interactions with API bindings -- Test suite for testing interactions with API bindings
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local inspect = require'vim.inspect'
local command = helpers.command local command = helpers.command
local meths = helpers.meths local meths = helpers.meths
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local fail = helpers.fail
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed = helpers.feed local feed = helpers.feed
local deepcopy = helpers.deepcopy local deepcopy = helpers.deepcopy
@ -243,21 +246,22 @@ describe('lua buffer event callbacks: on_lines', function()
end) end)
describe('lua buffer event callbacks: on_bytes', function() describe('lua: nvim_buf_attach on_bytes', function()
before_each(function() before_each(function()
clear() clear()
attach_buffer('on_bytes') attach_buffer('on_bytes')
end) end)
-- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot
-- assert the wrong thing), but masks errors with unflushed lines (as -- assert the wrong thing), but masks errors with unflushed lines (as
-- nvim_buf_get_offset forces a flush of the memline). To be safe run the -- nvim_buf_get_offset forces a flush of the memline). To be safe run the
-- test both ways. -- test both ways.
local function check(verify) local function setup_eventcheck(verify)
meths.buf_set_lines(0, 0, -1, true, origlines) meths.buf_set_lines(0, 0, -1, true, origlines)
local shadow = deepcopy(origlines) local shadow = deepcopy(origlines)
local shadowbytes = table.concat(shadow, '\n') .. '\n' local shadowbytes = table.concat(shadow, '\n') .. '\n'
-- TODO: while we are brewing the real strong coffe,
-- verify should check buf_get_offset after every check_events
if verify then if verify then
meths.buf_get_offset(0, meths.buf_line_count(0)) meths.buf_get_offset(0, meths.buf_line_count(0))
end end
@ -267,7 +271,21 @@ describe('lua buffer event callbacks: on_bytes', function()
local verify_name = "test1" local verify_name = "test1"
local function check_events(expected) local function check_events(expected)
local events = exec_lua("return get_events(...)" ) local events = exec_lua("return get_events(...)" )
eq(expected, events)
if not pcall(eq, expected, events) then
local msg = 'unexpected byte updates received.\n\nBABBLA MER \n\n'
msg = msg .. 'received events:\n'
for _, e in ipairs(events) do
msg = msg .. ' ' .. inspect(e) .. ';\n'
end
msg = msg .. '\nexpected events:\n'
for _, e in ipairs(expected) do
msg = msg .. ' ' .. inspect(e) .. ';\n'
end
fail(msg)
end
if verify then if verify then
for _, event in ipairs(events) do for _, event in ipairs(events) do
if event[1] == verify_name and event[2] == "bytes" then if event[1] == verify_name and event[2] == "bytes" then
@ -292,18 +310,60 @@ describe('lua buffer event callbacks: on_bytes', function()
end end
end end
feed('ggJ') return check_events
check_events({{'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1}})
feed('3J')
check_events({
{'test1', 'bytes', 1, 5, 0, 31, 31, 1, 0, 1, 0, 1, 1},
{'test1', 'bytes', 1, 5, 0, 47, 47, 1, 0, 1, 0, 1, 1},
})
end end
it('works with verify', function() -- Yes, we can do both
check(true) local function do_both(verify)
it('single and multiple join', function()
local check_events = setup_eventcheck(verify)
feed 'ggJ'
check_events {
{'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1};
}
feed '3J'
check_events {
{'test1', 'bytes', 1, 5, 0, 31, 31, 1, 0, 1, 0, 1, 1};
{'test1', 'bytes', 1, 5, 0, 47, 47, 1, 0, 1, 0, 1, 1};
}
end)
it('opening lines', function()
local check_events = setup_eventcheck(verify)
-- meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 1 };
}
feed '<cr>'
check_events {
{ "test1", "bytes", 1, 4, 8, 0, 115, 0, 0, 0, 0, 0, 0 };
{ "test1", "bytes", 1, 5, 7, 0, 114, 0, 0, 0, 1, 0, 1 };
}
end)
it('opening lines with autoindent', function()
local check_events = setup_eventcheck(verify)
meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 5 };
}
feed '<cr>'
check_events {
{ "test1", "bytes", 1, 4, 8, 0, 115, 0, 4, 4, 0, 0, 0 };
{ "test1", "bytes", 1, 5, 7, 4, 118, 0, 0, 0, 1, 4, 5 };
}
end)
end
describe('(with verify) handles', function()
do_both(true)
end)
describe('(without verify) handles', function()
do_both(false)
end) end)
end) end)

View File

@ -82,6 +82,17 @@ end
function module.ok(res, msg, logfile) function module.ok(res, msg, logfile)
return dumplog(logfile, assert.is_true, res, msg) return dumplog(logfile, assert.is_true, res, msg)
end end
-- TODO(bfredl): this should "failure" not "error" (issue with dumplog() )
local function epicfail(state, arguments, _)
state.failure_message = arguments[1]
return false
end
assert:register("assertion", "epicfail", epicfail)
function module.fail(msg, logfile)
return dumplog(logfile, assert.epicfail, msg)
end
function module.matches(pat, actual) function module.matches(pat, actual)
if nil ~= string.match(actual, pat) then if nil ~= string.match(actual, pat) then
return true return true