mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
tests: lua buffer updates: reorg check_events()
This commit is contained in:
@@ -287,32 +287,36 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
|||||||
fail(msg)
|
fail(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
if verify then
|
if not verify then
|
||||||
for _, event in ipairs(events) do
|
return
|
||||||
for _, elem in ipairs(event) do
|
end
|
||||||
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
|
for _, event in ipairs(events) do
|
||||||
local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event)
|
for _, elem in ipairs(event) do
|
||||||
local before = string.sub(shadowbytes, 1, start_byte)
|
if type(elem) == "number" and elem < 0 then
|
||||||
-- no text in the tests will contain 0xff bytes (invalid UTF-8)
|
fail(string.format("Received event has negative values"))
|
||||||
-- 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
|
||||||
end
|
end
|
||||||
local text = meths.buf_get_lines(0, 0, -1, true)
|
|
||||||
local bytes = table.concat(text, '\n') .. '\n'
|
if event[1] == verify_name and event[2] == "bytes" then
|
||||||
eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong')
|
local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event)
|
||||||
for i = 1, string.len(shadowbytes) do
|
local before = string.sub(shadowbytes, 1, start_byte)
|
||||||
local shadowbyte = string.sub(shadowbytes, i, i)
|
-- no text in the tests will contain 0xff bytes (invalid UTF-8)
|
||||||
if shadowbyte ~= '\255' then
|
-- so we can use it as marker for unknown bytes
|
||||||
eq(string.sub(bytes, i, i), shadowbyte, i)
|
local unknown = string.rep('\255', new_byte)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user