aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/buffer_updates_spec.lua
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-09-19 11:02:32 +0200
committerGitHub <noreply@github.com>2020-09-19 11:02:32 +0200
commitcea2417f30bf728cd818311b1988e0ce223011d8 (patch)
tree39b327ea24c97778ff57371d3c11fe4d056eb4da /test/functional/lua/buffer_updates_spec.lua
parent569e75799d7015b15631c80cee1feec561f29df7 (diff)
parent2f2c73265fd63af2f60799767417043ed15bd42c (diff)
downloadrneovim-cea2417f30bf728cd818311b1988e0ce223011d8.tar.gz
rneovim-cea2417f30bf728cd818311b1988e0ce223011d8.tar.bz2
rneovim-cea2417f30bf728cd818311b1988e0ce223011d8.zip
Merge pull request #12935 from vigoux/byte-change-lines
buf_updates: fix wrong updates on linewise change
Diffstat (limited to 'test/functional/lua/buffer_updates_spec.lua')
-rw-r--r--test/functional/lua/buffer_updates_spec.lua63
1 files changed, 45 insertions, 18 deletions
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index ac5d25bdab..805e880663 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -287,26 +287,36 @@ describe('lua: nvim_buf_attach on_bytes', function()
fail(msg)
end
- if verify then
- for _, event in ipairs(events) do
- 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
+ if not verify then
+ return
+ end
+
+ 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
@@ -411,6 +421,23 @@ 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, 0, 0, 0, 0, 15, 15, 0, 0, 0 };
+ }
+
+ feed "<ESC>"
+ check_events {}
+
+ feed "c3j"
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 };
+ }
+ end)
end
describe('(with verify) handles', function()