api: set_text: fix some byte count issues

add byte count tests

update documentation
This commit is contained in:
Björn Linse
2020-12-30 11:31:17 +01:00
parent f7d01a65d5
commit 39d098f9f9
2 changed files with 88 additions and 32 deletions

View File

@@ -288,7 +288,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- TODO: while we are brewing the real strong coffe,
-- verify should check buf_get_offset after every check_events
if verify then
meths.buf_get_offset(0, meths.buf_line_count(0))
local len = meths.buf_get_offset(0, meths.buf_line_count(0))
eq(len == -1 and 1 or len, string.len(shadowbytes))
end
exec_lua("return test_register(...)", 0, "test1", false, false, true)
meths.buf_get_changedtick(0)
@@ -510,6 +511,70 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 };
}
end)
it('nvim_buf_set_text insert', function()
local check_events = setup_eventcheck(verify, {"bastext"})
meths.buf_set_text(0, 0, 3, 0, 3, {"fiol","kontra"})
check_events {
{ "test1", "bytes", 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 };
}
meths.buf_set_text(0, 1, 6, 1, 6, {"punkt","syntgitarr","övnings"})
check_events {
{ "test1", "bytes", 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 };
}
eq({ "basfiol", "kontrapunkt", "syntgitarr", "övningstext" },
meths.buf_get_lines(0, 0, -1, true))
end)
it('nvim_buf_set_text replace', function()
local check_events = setup_eventcheck(verify, origlines)
meths.buf_set_text(0, 2, 3, 2, 8, {"very text"})
check_events {
{ "test1", "bytes", 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 };
}
meths.buf_set_text(0, 3, 5, 3, 7, {" splitty","line "})
check_events {
{ "test1", "bytes", 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 };
}
meths.buf_set_text(0, 0, 8, 1, 2, {"JOINY"})
check_events {
{ "test1", "bytes", 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 };
}
meths.buf_set_text(0, 4, 0, 6, 0, {"was 5,6",""})
check_events {
{ "test1", "bytes", 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 };
}
eq({ "originalJOINYiginal line 2", "orivery text line 3", "origi splitty",
"line l line 4", "was 5,6", " indented line" },
meths.buf_get_lines(0, 0, -1, true))
end)
it('nvim_buf_set_text delete', function()
local check_events = setup_eventcheck(verify, origlines)
-- really {""} but accepts {} as a shorthand
meths.buf_set_text(0, 0, 0, 1, 0, {})
check_events {
{ "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 };
}
-- TODO(bfredl): this works but is not as convenient as set_lines
meths.buf_set_text(0, 4, 15, 5, 17, {""})
check_events {
{ "test1", "bytes", 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 };
}
eq({ "original line 2", "original line 3", "original line 4",
"original line 5", "original line 6" },
meths.buf_get_lines(0, 0, -1, true))
end)
end
describe('(with verify) handles', function()