From 179f0bca1890637f47e76c8acfd33040a6b7d515 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Fri, 18 Sep 2020 08:44:32 +0200 Subject: buf_updates: fix wrong updates on linewise change --- test/functional/lua/buffer_updates_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/functional/lua') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index ac5d25bdab..6b62768470 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -289,6 +289,12 @@ describe('lua: nvim_buf_attach on_bytes', function() if verify then for _, event in ipairs(events) do + for _, elem in ipairs(event) do + if type(elem) == "number" and elem < 0 then + fail(string.format("Received event has negative values")) + end + end + if event[1] == verify_name and event[2] == "bytes" then local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) local before = string.sub(shadowbytes, 1, start_byte) @@ -411,6 +417,24 @@ describe('lua: nvim_buf_attach on_bytes', function() { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; } end) + + it("changing lines", function() + local check_events = setup_eventcheck(verify, origlines) + + feed "cc" + check_events { + { "test1", "bytes", 1, 4, 1, 0, 1, 0, 15, 15, 0, 0, 0 }; + } + + feed "" + check_events {} + + feed "c3j" + check_events { + { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }; + { "test1", "bytes", 1, 5, 0, 0, 0, 4, 0, 0, 4, 0, 51 }; + } + end) end describe('(with verify) handles', function() -- cgit From 4cc2a7af4bb577d9f3c0573b7293f477046f08ae Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 19 Sep 2020 09:58:31 +0200 Subject: tests: lua buffer updates: reorg check_events() --- test/functional/lua/buffer_updates_spec.lua | 50 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'test/functional/lua') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 6b62768470..29bcca9035 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -287,32 +287,36 @@ describe('lua: nvim_buf_attach on_bytes', function() fail(msg) end - if verify then - for _, event in ipairs(events) do - for _, elem in ipairs(event) do - if type(elem) == "number" and elem < 0 then - fail(string.format("Received event has negative values")) - end - end + if not verify then + return + end - if event[1] == verify_name and event[2] == "bytes" then - local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) - local before = string.sub(shadowbytes, 1, start_byte) - -- no text in the tests will contain 0xff bytes (invalid UTF-8) - -- so we can use it as marker for unknown bytes - local unknown = string.rep('\255', new_byte) - local after = string.sub(shadowbytes, start_byte + old_byte + 1) - shadowbytes = before .. unknown .. after + for _, event in ipairs(events) do + for _, elem in ipairs(event) do + if type(elem) == "number" and elem < 0 then + fail(string.format("Received event has negative values")) end end - local text = meths.buf_get_lines(0, 0, -1, true) - local bytes = table.concat(text, '\n') .. '\n' - eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') - for i = 1, string.len(shadowbytes) do - local shadowbyte = string.sub(shadowbytes, i, i) - if shadowbyte ~= '\255' then - eq(string.sub(bytes, i, i), shadowbyte, i) - end + + if event[1] == verify_name and event[2] == "bytes" then + local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) + local before = string.sub(shadowbytes, 1, start_byte) + -- no text in the tests will contain 0xff bytes (invalid UTF-8) + -- so we can use it as marker for unknown bytes + local unknown = string.rep('\255', new_byte) + local after = string.sub(shadowbytes, start_byte + old_byte + 1) + shadowbytes = before .. unknown .. after + end + end + + local text = meths.buf_get_lines(0, 0, -1, true) + local bytes = table.concat(text, '\n') .. '\n' + + eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') + for i = 1, string.len(shadowbytes) do + local shadowbyte = string.sub(shadowbytes, i, i) + if shadowbyte ~= '\255' then + eq(string.sub(bytes, i, i), shadowbyte, i) end end end -- cgit From b7fc7ac6a115ce88df3cbbf6c0ad1a89791dc47c Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 19 Sep 2020 10:01:00 +0200 Subject: buffer updates: fix issues with "change" operator --- test/functional/lua/buffer_updates_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional/lua') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 29bcca9035..805e880663 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -427,7 +427,7 @@ describe('lua: nvim_buf_attach on_bytes', function() feed "cc" check_events { - { "test1", "bytes", 1, 4, 1, 0, 1, 0, 15, 15, 0, 0, 0 }; + { "test1", "bytes", 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 }; } feed "" @@ -436,7 +436,6 @@ describe('lua: nvim_buf_attach on_bytes', function() feed "c3j" check_events { { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 0, 0, 0, 4, 0, 0, 4, 0, 51 }; } end) end -- cgit