mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
api/buffer: introduce buffer_[gs]et_lines with new indexing convention.
-1 is index past the end, and -2 is the index of the last element. This eliminates the need for include_start/include_end. Allow the handling of out-of-bounds to be configurable.
This commit is contained in:
@@ -35,10 +35,11 @@ describe('buffer_* functions', function()
|
||||
eq('', curbuf('get_line', 0))
|
||||
end)
|
||||
|
||||
it('get_line: out-of-bounds returns empty string', function()
|
||||
it('get_line: out-of-bounds is an error', function()
|
||||
curbuf('set_line', 0, 'line1.a')
|
||||
eq('', curbuf('get_line', 1))
|
||||
eq('', curbuf('get_line', -2))
|
||||
eq(1, curbuf('line_count')) -- sanity
|
||||
eq(false, pcall(curbuf, 'get_line', 1))
|
||||
eq(false, pcall(curbuf, 'get_line', -2))
|
||||
end)
|
||||
|
||||
it('set_line, del_line: out-of-bounds is an error', function()
|
||||
@@ -68,14 +69,16 @@ describe('buffer_* functions', function()
|
||||
eq({}, curbuf('get_line_slice', -4, -5, true, true))
|
||||
end)
|
||||
|
||||
it('set_line_slice: out-of-bounds is an error', function()
|
||||
it('set_line_slice: out-of-bounds extends past end', function()
|
||||
curbuf('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'})
|
||||
eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 2, true, true)) --sanity
|
||||
|
||||
eq({'c'}, curbuf('get_line_slice', -1, 4, true, true))
|
||||
eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 5, true, true))
|
||||
eq(false, pcall(curbuf, 'set_line_slice', 4, 5, true, true, {'d'}))
|
||||
eq(false, pcall(curbuf, 'set_line_slice', -4, -5, true, true, {'d'}))
|
||||
curbuf('set_line_slice', 4, 5, true, true, {'d'})
|
||||
eq({'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true))
|
||||
curbuf('set_line_slice', -4, -5, true, true, {'e'})
|
||||
eq({'e', 'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true))
|
||||
end)
|
||||
|
||||
it('works', function()
|
||||
|
||||
Reference in New Issue
Block a user