diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-07-15 18:23:11 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-08-06 17:01:47 +0200 |
commit | b0e26199ec02c9b392af6161522004c55db0441f (patch) | |
tree | c57e4cbd58018b8bf7e396239604b6e3e4943dfc /test/functional/lua/buffer_updates_spec.lua | |
parent | 067a39ba854cc02a750911ead968a744b2769aac (diff) | |
download | rneovim-b0e26199ec02c9b392af6161522004c55db0441f.tar.gz rneovim-b0e26199ec02c9b392af6161522004c55db0441f.tar.bz2 rneovim-b0e26199ec02c9b392af6161522004c55db0441f.zip |
lua: add {old_byte_size} to on_lines buffer change event
Diffstat (limited to 'test/functional/lua/buffer_updates_spec.lua')
-rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 90 |
1 files changed, 69 insertions, 21 deletions
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index c419d89be3..16c38bc20b 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -5,6 +5,8 @@ local command = helpers.command local meths = helpers.meths local clear = helpers.clear local eq = helpers.eq +local exec_lua = helpers.exec_lua +local feed = helpers.feed local origlines = {"original line 1", "original line 2", @@ -16,7 +18,7 @@ local origlines = {"original line 1", describe('lua: buffer event callbacks', function() before_each(function() clear() - meths.execute_lua([[ + exec_lua([[ local events = {} function test_register(bufnr, id, changedtick) @@ -38,55 +40,101 @@ describe('lua: buffer event callbacks', function() events = {} return ret_events end - ]], {}) + ]]) end) - it('works', function() + + -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot + -- assert the wrong thing), but masks errors with unflushed lines (as + -- nvim_buf_get_offset forces a flush of the memline). To be safe run the + -- test both ways. + local function check(verify) + local lastsize meths.buf_set_lines(0, 0, -1, true, origlines) - meths.execute_lua("return test_register(...)", {0, "test1"}) + if verify then + lastsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + end + exec_lua("return test_register(...)", 0, "test1") local tick = meths.buf_get_changedtick(0) + local verify_name = "test1" + local function check_events(expected) + local events = exec_lua("return get_events(...)" ) + eq(expected, events) + if verify then + for _, event in ipairs(events) do + if event[1] == verify_name and event[2] == "lines" then + local startline, endline = event[5], event[7] + local newrange = meths.buf_get_offset(0, endline) - meths.buf_get_offset(0, startline) + local newsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + local oldrange = newrange + lastsize - newsize + eq(oldrange, event[8]) + lastsize = newsize + end + end + end + end + command('normal! GyyggP') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 0, 0, 1 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 0, 0, 1, 0}}) meths.buf_set_lines(0, 3, 5, true, {"changed line"}) tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 3, 5, 4 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 3, 5, 4, 32 }}) - meths.execute_lua("return test_register(...)", {0, "test2", true}) + exec_lua("return test_register(...)", 0, "test2", true) tick = tick + 1 command('undo') -- plugins can opt in to receive changedtick events, or choose -- to only recieve actual changes. - eq({{ "test1", "lines", 1, tick, 3, 4, 5 }, - { "test2", "lines", 1, tick, 3, 4, 5 }, - { "test2", "changedtick", 1, tick+1 } }, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 3, 4, 5, 13 }, + { "test2", "lines", 1, tick, 3, 4, 5, 13 }, + { "test2", "changedtick", 1, tick+1 } }) tick = tick + 1 -- simulate next callback returning true - meths.execute_lua("test_unreg = 'test1'", {}) + exec_lua("test_unreg = 'test1'") meths.buf_set_lines(0, 6, 7, true, {"x1","x2","x3"}) tick = tick + 1 -- plugins can opt in to receive changedtick events, or choose -- to only recieve actual changes. - eq({{ "test1", "lines", 1, tick, 6, 7, 9 }, - { "test2", "lines", 1, tick, 6, 7, 9 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 6, 7, 9, 16 }, + { "test2", "lines", 1, tick, 6, 7, 9, 16 }}) + + verify_name = "test2" meths.buf_set_lines(0, 1, 1, true, {"added"}) tick = tick + 1 - eq({{ "test2", "lines", 1, tick, 1, 1, 2 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test2", "lines", 1, tick, 1, 1, 2, 0 }}) + + feed('wix') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 16 }}) + + -- check hot path for multiple insert + feed('yz') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 17 }}) + + feed('<bs>') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 19 }}) + + feed('<esc>') command('bwipe!') - eq({{ "test2", "detach", 1 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test2", "detach", 1 }}) + end + + it('works', function() + check(false) + end) + + it('works with verify', function() + check(true) end) end) |