diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-09-19 09:58:31 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-09-19 09:58:31 +0200 |
commit | 4cc2a7af4bb577d9f3c0573b7293f477046f08ae (patch) | |
tree | 4147614f778bf4bd684f934656a34a6fef3293b8 | |
parent | 179f0bca1890637f47e76c8acfd33040a6b7d515 (diff) | |
download | rneovim-4cc2a7af4bb577d9f3c0573b7293f477046f08ae.tar.gz rneovim-4cc2a7af4bb577d9f3c0573b7293f477046f08ae.tar.bz2 rneovim-4cc2a7af4bb577d9f3c0573b7293f477046f08ae.zip |
tests: lua buffer updates: reorg check_events()
-rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 50 |
1 files changed, 27 insertions, 23 deletions
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 |