aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/buffer_updates_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua/buffer_updates_spec.lua')
-rw-r--r--test/functional/lua/buffer_updates_spec.lua90
1 files changed, 86 insertions, 4 deletions
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 7e4de7c39a..67dc5f5a16 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -25,14 +25,14 @@ local function attach_buffer(evname)
local evname = ...
local events = {}
- function test_register(bufnr, id, changedtick, utf_sizes)
+ function test_register(bufnr, id, changedtick, utf_sizes, preview)
local function callback(...)
table.insert(events, {id, ...})
if test_unreg == id then
return true
end
end
- local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes}
+ local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes, preview=preview}
if changedtick then
opts.on_changedtick = callback
end
@@ -288,9 +288,10 @@ 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, nil)
+ exec_lua("return test_register(...)", 0, "test1", false, false, true)
meths.buf_get_changedtick(0)
local verify_name = "test1"
@@ -493,6 +494,87 @@ describe('lua: nvim_buf_attach on_bytes', function()
}
end)
+
+ it('inccomand=nosplit and substitute', function()
+ if verify then pending("Verification can't be done when previewing") end
+
+ local check_events = setup_eventcheck(verify, {"abcde"})
+ meths.set_option('inccommand', 'nosplit')
+
+ feed ':%s/bcd/'
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 };
+ }
+
+ feed 'a'
+ check_events {
+ { "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()