local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer
local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq
local curbufmeths, ok = helpers.curbufmeths, helpers.ok
local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe)
local meths = helpers.meths
local funcs = helpers.funcs
local request = helpers.request
local exc_exec = helpers.exc_exec
local exec_lua = helpers.exec_lua
local feed_command = helpers.feed_command
local insert = helpers.insert
local NIL = helpers.NIL
local command = helpers.command
local bufmeths = helpers.bufmeths
local feed = helpers.feed
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
describe('api/buf', function()
before_each(clear)
-- access deprecated functions
local function curbuf_depr(method, ...)
return request('buffer_'..method, 0, ...)
end
describe('nvim_buf_set_lines, nvim_buf_line_count', function()
it('deprecated forms', function()
eq(1, curbuf_depr('line_count'))
curbuf_depr('insert', -1, {'line'})
eq(2, curbuf_depr('line_count'))
curbuf_depr('insert', -1, {'line'})
eq(3, curbuf_depr('line_count'))
curbuf_depr('del_line', -1)
eq(2, curbuf_depr('line_count'))
curbuf_depr('del_line', -1)
curbuf_depr('del_line', -1)
-- There's always at least one line
eq(1, curbuf_depr('line_count'))
end)
it("doesn't crash just after set undolevels=1 #24894", function()
local buf = meths.create_buf(false, true)
meths.buf_set_option(buf, 'undolevels', -1)
meths.buf_set_lines(buf, 0, 1, false, { })
assert_alive()
end)
it('cursor position is maintained after lines are inserted #9961', function()
-- replace the buffer contents with these three lines.
request('nvim_buf_set_lines', 0, 0, -1, 1, {"line1", "line2", "line3", "line4"})
-- Set the current cursor to {3, 2}.
curwin('set_cursor', {3, 2})
-- add 2 lines and delete 1 line above the current cursor position.
request('nvim_buf_set_lines', 0, 1, 2, 1, {"line5", "line6"})
-- check the current set of lines in the buffer.
eq({"line1", "line5", "line6", "line3", "line4"}, buffer('get_lines', 0, 0, -1, 1))
-- cursor should be moved below by 1 line.
eq({4, 2}, curwin('get_cursor'))
-- add a line after the current cursor position.
request('nvim_buf_set_lines', 0, 5, 5, 1, {"line7"})
-- check the current set of lines in the buffer.
eq({"line1", "line5", "line6", "line3", "line4", "line7"}, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
eq({4, 2}, curwin('get_cursor'))
-- overwrite current cursor line.
request('nvim_buf_set_lines', 0, 3, 5, 1, {"line8", "line9"})
-- check the current set of lines in the buffer.
eq({"line1", "line5", "line6", "line8", "line9", "line7"}, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
eq({4, 2}, curwin('get_cursor'))
-- delete current cursor line.
request('nvim_buf_set_lines', 0, 3, 5, 1, {})
-- check the current set of lines in the buffer.
eq({"line1", "line5", "line6", "line7"}, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
eq({4, 2}, curwin('get_cursor'))
end)
it('cursor position is maintained in non-current window', function()
meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"})
meths.win_set_cursor(0, {3, 2})
local win = meths.get_current_win()
local buf = meths.get_current_buf()
command('new')
meths.buf_set_l
|