diff options
author | Peter Hodge <peter.hodge84@gmail.com> | 2018-06-29 11:32:05 +1000 |
---|---|---|
committer | Peter Hodge <peter.hodge84@gmail.com> | 2018-07-25 15:07:13 +1000 |
commit | b53b621ef61ec2ac694437fdcb8385f3d9ee0cbc (patch) | |
tree | 5e184db4239471af6761f4914e1d7cddfca1b345 /test/functional/api/buffer_spec.lua | |
parent | 10bb11e8d1a0762bdfe8bd6de7453bd66ed5fc92 (diff) | |
download | rneovim-b53b621ef61ec2ac694437fdcb8385f3d9ee0cbc.tar.gz rneovim-b53b621ef61ec2ac694437fdcb8385f3d9ee0cbc.tar.bz2 rneovim-b53b621ef61ec2ac694437fdcb8385f3d9ee0cbc.zip |
functests: tests related to operations on unloaded buffers #7688
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 823c134ebd..958e2f68fc 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -35,8 +35,37 @@ describe('api/buf', function() -- There's always at least one line eq(1, curbuf_depr('line_count')) end) - end) + it('line_count has defined behaviour for unloaded buffers', function() + -- we'll need to know our bufnr for when it gets unloaded + local bufnr = curbuf('get_number') + -- replace the buffer contents with these three lines + request('nvim_buf_set_lines', bufnr, 0, -1, 1, {"line1", "line2", "line3", "line4"}) + -- check the line count is correct + eq(4, request('nvim_buf_line_count', bufnr)) + -- force unload the buffer (this will discard changes) + command('new') + command('bunload! '..bufnr) + -- line count for an unloaded buffer should always be 0 + eq(0, request('nvim_buf_line_count', bufnr)) + end) + + it('get_lines has defined behaviour for unloaded buffers', function() + -- we'll need to know our bufnr for when it gets unloaded + local bufnr = curbuf('get_number') + -- replace the buffer contents with these three lines + buffer('set_lines', bufnr, 0, -1, 1, {"line1", "line2", "line3", "line4"}) + -- confirm that getting lines works + eq({"line2", "line3"}, buffer('get_lines', bufnr, 1, 3, 1)) + -- force unload the buffer (this will discard changes) + command('new') + command('bunload! '..bufnr) + -- attempting to get lines now always gives empty list + eq({}, buffer('get_lines', bufnr, 1, 3, 1)) + -- it's impossible to get out-of-bounds errors for an unloaded buffer + eq({}, buffer('get_lines', bufnr, 8888, 9999, 1)) + end) + end) describe('{get,set,del}_line', function() it('works', function() @@ -70,7 +99,6 @@ describe('api/buf', function() end) end) - describe('{get,set}_line_slice', function() it('get_line_slice: out-of-bounds returns empty array', function() curbuf_depr('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) @@ -345,6 +373,31 @@ describe('api/buf', function() end) end) + describe('is_loaded', function() + it('works', function() + -- record our buffer number for when we unload it + local bufnr = curbuf('get_number') + -- api should report that the buffer is loaded + ok(buffer('is_loaded', bufnr)) + -- hide the current buffer by switching to a new empty buffer + -- Careful! we need to modify the buffer first or vim will just reuse it + buffer('set_lines', bufnr, 0, -1, 1, {'line1'}) + command('hide enew') + -- confirm the buffer is hidden, but still loaded + local infolist = nvim('eval', 'getbufinfo('..bufnr..')') + eq(1, #infolist) + eq(1, infolist[1].hidden) + eq(1, infolist[1].loaded) + -- now force unload the buffer + command('bunload! '..bufnr) + -- confirm the buffer is unloaded + infolist = nvim('eval', 'getbufinfo('..bufnr..')') + eq(0, infolist[1].loaded) + -- nvim_buf_is_loaded() should also report the buffer as unloaded + eq(false, buffer('is_loaded', bufnr)) + end) + end) + describe('is_valid', function() it('works', function() nvim('command', 'new') |