aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/buffer_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-12 19:40:58 +0000
committerGitHub <noreply@github.com>2024-01-12 19:40:58 +0000
commit07a7c0ec999102f223a6aca17e93d33e18c02b94 (patch)
tree221ea513b45596f8e63035955494167fc20bf826 /test/functional/api/buffer_spec.lua
parent7f249936a989dbc21ad03e394197afc07cb9c0bf (diff)
parent795f896a5772d5e0795f86642bdf90c82efac45c (diff)
downloadrneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.gz
rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.bz2
rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.zip
Merge pull request #26994 from lewis6991/vimhelpers
test: big cleanup
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r--test/functional/api/buffer_spec.lua727
1 files changed, 379 insertions, 348 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index e8fff7443d..10be4c56a7 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -1,19 +1,18 @@
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 clear = helpers.clear
+local eq = helpers.eq
+local ok = helpers.ok
local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe)
-local meths = helpers.meths
-local funcs = helpers.funcs
+local api = helpers.api
+local fn = helpers.fn
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 NIL = vim.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
@@ -42,108 +41,114 @@ describe('api/buf', function()
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, {})
+ local buf = api.nvim_create_buf(false, true)
+ api.nvim_buf_set_option(buf, 'undolevels', -1)
+ api.nvim_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' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' })
-- Set the current cursor to {3, 2}.
- curwin('set_cursor', { 3, 2 })
+ api.nvim_win_set_cursor(0, { 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' })
+ api.nvim_buf_set_lines(0, 1, 2, true, { 'line5', 'line6' })
-- check the current set of lines in the buffer.
- eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, buffer('get_lines', 0, 0, -1, 1))
+ eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- cursor should be moved below by 1 line.
- eq({ 4, 2 }, curwin('get_cursor'))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(0))
-- add a line after the current cursor position.
- request('nvim_buf_set_lines', 0, 5, 5, 1, { 'line7' })
+ api.nvim_buf_set_lines(0, 5, 5, true, { 'line7' })
-- check the current set of lines in the buffer.
- eq({ 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, buffer('get_lines', 0, 0, -1, 1))
+ eq(
+ { 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' },
+ api.nvim_buf_get_lines(0, 0, -1, true)
+ )
-- cursor position is unchanged.
- eq({ 4, 2 }, curwin('get_cursor'))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(0))
-- overwrite current cursor line.
- request('nvim_buf_set_lines', 0, 3, 5, 1, { 'line8', 'line9' })
+ api.nvim_buf_set_lines(0, 3, 5, true, { '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))
+ eq(
+ { 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' },
+ api.nvim_buf_get_lines(0, 0, -1, true)
+ )
-- cursor position is unchanged.
- eq({ 4, 2 }, curwin('get_cursor'))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(0))
-- delete current cursor line.
- request('nvim_buf_set_lines', 0, 3, 5, 1, {})
+ api.nvim_buf_set_lines(0, 3, 5, true, {})
-- check the current set of lines in the buffer.
- eq({ 'line1', 'line5', 'line6', 'line7' }, buffer('get_lines', 0, 0, -1, 1))
+ eq({ 'line1', 'line5', 'line6', 'line7' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- cursor position is unchanged.
- eq({ 4, 2 }, curwin('get_cursor'))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(0))
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()
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' })
+ api.nvim_win_set_cursor(0, { 3, 2 })
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('new')
- meths.buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' })
- eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true))
- eq({ 4, 2 }, meths.win_get_cursor(win))
+ api.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' })
+ eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(buf, 0, -1, true))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(win))
end)
it('cursor position is maintained in TWO non-current windows', 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()
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' })
+ api.nvim_win_set_cursor(0, { 3, 2 })
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('split')
- meths.win_set_cursor(0, { 4, 2 })
- local win2 = meths.get_current_win()
+ api.nvim_win_set_cursor(0, { 4, 2 })
+ local win2 = api.nvim_get_current_win()
-- set current window to third one with another buffer
command('new')
- meths.buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' })
- eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true))
- eq({ 4, 2 }, meths.win_get_cursor(win))
- eq({ 5, 2 }, meths.win_get_cursor(win2))
+ api.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' })
+ eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(buf, 0, -1, true))
+ eq({ 4, 2 }, api.nvim_win_get_cursor(win))
+ eq({ 5, 2 }, api.nvim_win_get_cursor(win2))
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')
+ local bufnr = api.nvim_buf_get_number(0)
-- replace the buffer contents with these three lines
- request('nvim_buf_set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' })
+ api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' })
-- check the line count is correct
- eq(4, request('nvim_buf_line_count', bufnr))
+ eq(4, api.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))
+ eq(0, api.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')
+ local bufnr = api.nvim_buf_get_number(0)
-- replace the buffer contents with these three lines
- buffer('set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' })
+ api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' })
-- confirm that getting lines works
- eq({ 'line2', 'line3' }, buffer('get_lines', bufnr, 1, 3, 1))
+ eq({ 'line2', 'line3' }, api.nvim_buf_get_lines(bufnr, 1, 3, true))
-- 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))
+ eq({}, api.nvim_buf_get_lines(bufnr, 1, 3, true))
-- it's impossible to get out-of-bounds errors for an unloaded buffer
- eq({}, buffer('get_lines', bufnr, 8888, 9999, 1))
+ eq({}, api.nvim_buf_get_lines(bufnr, 8888, 9999, true))
end)
describe('handles topline', function()
@@ -156,16 +161,22 @@ describe('api/buf', function()
[3] = { reverse = true },
}
screen:attach()
- meths.buf_set_lines(0, 0, -1, 1, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' })
- meths.set_option_value('modified', false, {})
+ api.nvim_buf_set_lines(
+ 0,
+ 0,
+ -1,
+ true,
+ { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' }
+ )
+ api.nvim_set_option_value('modified', false, {})
end)
it('of current window', function()
- local win = meths.get_current_win()
- local buf = meths.get_current_buf()
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('new | wincmd w')
- meths.win_set_cursor(win, { 8, 0 })
+ api.nvim_win_set_cursor(win, { 8, 0 })
screen:expect {
grid = [[
@@ -181,7 +192,7 @@ describe('api/buf', function()
]],
}
- meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
+ api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
screen:expect {
grid = [[
|
@@ -197,7 +208,7 @@ describe('api/buf', function()
}
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect {
grid = [[
|
@@ -213,7 +224,7 @@ describe('api/buf', function()
}
-- inserting just before topline does not scroll up if cursor would be moved
- meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
|
@@ -229,7 +240,7 @@ describe('api/buf', function()
unchanged = true,
}
- meths.win_set_cursor(0, { 7, 0 })
+ api.nvim_win_set_cursor(0, { 7, 0 })
screen:expect {
grid = [[
|
@@ -244,7 +255,7 @@ describe('api/buf', function()
]],
}
- meths.buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' })
+ api.nvim_buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' })
screen:expect {
grid = [[
|
@@ -261,11 +272,11 @@ describe('api/buf', function()
end)
it('of non-current window', function()
- local win = meths.get_current_win()
- local buf = meths.get_current_buf()
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('new')
- meths.win_set_cursor(win, { 8, 0 })
+ api.nvim_win_set_cursor(win, { 8, 0 })
screen:expect {
grid = [[
@@ -281,7 +292,7 @@ describe('api/buf', function()
]],
}
- meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
+ api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
screen:expect {
grid = [[
^ |
@@ -297,7 +308,7 @@ describe('api/buf', function()
}
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect {
grid = [[
^ |
@@ -313,7 +324,7 @@ describe('api/buf', function()
}
-- inserting just before topline scrolls up
- meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^ |
@@ -330,12 +341,12 @@ describe('api/buf', function()
end)
it('of split windows with same buffer', function()
- local win = meths.get_current_win()
- local buf = meths.get_current_buf()
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('split')
- meths.win_set_cursor(win, { 8, 0 })
- meths.win_set_cursor(0, { 1, 0 })
+ api.nvim_win_set_cursor(win, { 8, 0 })
+ api.nvim_win_set_cursor(0, { 1, 0 })
screen:expect {
grid = [[
@@ -353,7 +364,7 @@ describe('api/buf', function()
|
]],
}
- meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
+ api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
screen:expect {
grid = [[
@@ -373,7 +384,7 @@ describe('api/buf', function()
}
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect {
grid = [[
^aaabbb |
@@ -392,7 +403,7 @@ describe('api/buf', function()
}
-- inserting just before topline scrolls up
- meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^aaabbb |
@@ -413,15 +424,15 @@ describe('api/buf', function()
end)
it('handles clearing out non-current buffer #24911', function()
- local buf = meths.get_current_buf()
- meths.buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' })
+ local buf = api.nvim_get_current_buf()
+ api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' })
command('new')
- meths.buf_set_lines(0, 0, -1, true, { 'xxx', 'yyy', 'zzz' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'xxx', 'yyy', 'zzz' })
- meths.buf_set_lines(buf, 0, -1, true, {})
- eq({ 'xxx', 'yyy', 'zzz' }, meths.buf_get_lines(0, 0, -1, true))
- eq({ '' }, meths.buf_get_lines(buf, 0, -1, true))
+ api.nvim_buf_set_lines(buf, 0, -1, true, {})
+ eq({ 'xxx', 'yyy', 'zzz' }, api.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ '' }, api.nvim_buf_get_lines(buf, 0, -1, true))
end)
end)
@@ -503,16 +514,24 @@ describe('api/buf', function()
end)
end)
- describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(api)
- local get_lines = api.curbufmeths.get_lines
- local set_lines = api.curbufmeths.set_lines
- local line_count = api.curbufmeths.line_count
+ describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(lua_or_rpc)
+ local function get_lines(...)
+ return lua_or_rpc.nvim_buf_get_lines(0, ...)
+ end
+
+ local function set_lines(...)
+ return lua_or_rpc.nvim_buf_set_lines(0, ...)
+ end
+
+ local function line_count()
+ return lua_or_rpc.nvim_buf_line_count(0)
+ end
it('fails correctly when input is not valid', function()
- eq(1, api.curbufmeths.get_number())
+ eq(1, lua_or_rpc.nvim_buf_get_number(0))
eq(
[['replacement string' item contains newlines]],
- pcall_err(bufmeths.set_lines, 1, 1, 2, false, { 'b\na' })
+ pcall_err(lua_or_rpc.nvim_buf_set_lines, 1, 1, 2, false, { 'b\na' })
)
end)
@@ -520,7 +539,7 @@ describe('api/buf', function()
command('set nomodifiable')
eq(
[[Buffer is not 'modifiable']],
- pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, { 'a', 'b' })
+ pcall_err(lua_or_rpc.nvim_buf_set_lines, 1, 1, 2, false, { 'a', 'b' })
)
end)
@@ -676,7 +695,7 @@ describe('api/buf', function()
Who would win?
A real window
with proper text]])
- local buf = api.meths.create_buf(false, true)
+ local buf = lua_or_rpc.nvim_create_buf(false, true)
screen:expect([[
Who would win? |
A real window |
@@ -685,7 +704,7 @@ describe('api/buf', function()
|
]])
- api.meths.buf_set_lines(buf, 0, -1, true, { 'or some', 'scratchy text' })
+ lua_or_rpc.nvim_buf_set_lines(buf, 0, -1, true, { 'or some', 'scratchy text' })
feed('i') -- provoke redraw
screen:expect([[
Who would win? |
@@ -701,36 +720,42 @@ describe('api/buf', function()
visible buffer line 1
line 2
]])
- local hiddenbuf = api.meths.create_buf(false, true)
+ local hiddenbuf = lua_or_rpc.nvim_create_buf(false, true)
command('vsplit')
command('vsplit')
feed('<c-w>l<c-w>l<c-w>l')
- eq(3, funcs.winnr())
+ eq(3, fn.winnr())
feed('<c-w>h')
- eq(2, funcs.winnr())
- api.meths.buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' })
+ eq(2, fn.winnr())
+ lua_or_rpc.nvim_buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' })
feed('<c-w>p')
- eq(3, funcs.winnr())
+ eq(3, fn.winnr())
end)
it('set_lines on unloaded buffer #8659 #22670', function()
- local bufnr = curbuf('get_number')
- meths.buf_set_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' })
- meths.buf_set_name(bufnr, 'set_lines')
+ local bufnr = api.nvim_get_current_buf().id
+ lua_or_rpc.nvim_buf_set_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' })
+ lua_or_rpc.nvim_buf_set_name(bufnr, 'set_lines')
finally(function()
os.remove('set_lines')
end)
command('write!')
command('new')
command('bunload! ' .. bufnr)
- local new_bufnr = funcs.bufnr('set_lines', true)
- meths.buf_set_lines(new_bufnr, 0, -1, false, {})
- eq({ '' }, meths.buf_get_lines(new_bufnr, 0, -1, false))
+ local new_bufnr = fn.bufnr('set_lines', true)
+ lua_or_rpc.nvim_buf_set_lines(new_bufnr, 0, -1, false, {})
+ eq({ '' }, lua_or_rpc.nvim_buf_get_lines(new_bufnr, 0, -1, false))
end)
end)
describe('nvim_buf_set_text', function()
- local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text
+ local function get_lines(...)
+ return api.nvim_buf_get_lines(0, ...)
+ end
+
+ local function set_text(...)
+ return api.nvim_buf_set_text(0, ...)
+ end
it('works', function()
insert([[
@@ -809,12 +834,12 @@ describe('api/buf', function()
]])
-- position the cursor on `!`
- curwin('set_cursor', { 1, 11 })
+ api.nvim_win_set_cursor(0, { 1, 11 })
-- replace 'world' with 'foo'
set_text(0, 6, 0, 11, { 'foo' })
eq('hello foo!', curbuf_depr('get_line', 0))
-- cursor should be moved left by two columns (replacement is shorter by 2 chars)
- eq({ 1, 9 }, curwin('get_cursor'))
+ eq({ 1, 9 }, api.nvim_win_get_cursor(0))
end)
it('updates the cursor position in non-current window', function()
@@ -822,18 +847,18 @@ describe('api/buf', function()
hello world!]])
-- position the cursor on `!`
- meths.win_set_cursor(0, { 1, 11 })
+ api.nvim_win_set_cursor(0, { 1, 11 })
- local win = meths.get_current_win()
- local buf = meths.get_current_buf()
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('new')
-- replace 'world' with 'foo'
- meths.buf_set_text(buf, 0, 6, 0, 11, { 'foo' })
- eq({ 'hello foo!' }, meths.buf_get_lines(buf, 0, -1, true))
+ api.nvim_buf_set_text(buf, 0, 6, 0, 11, { 'foo' })
+ eq({ 'hello foo!' }, api.nvim_buf_get_lines(buf, 0, -1, true))
-- cursor should be moved left by two columns (replacement is shorter by 2 chars)
- eq({ 1, 9 }, meths.win_get_cursor(win))
+ eq({ 1, 9 }, api.nvim_win_get_cursor(win))
end)
it('updates the cursor position in TWO non-current windows', function()
@@ -841,24 +866,24 @@ describe('api/buf', function()
hello world!]])
-- position the cursor on `!`
- meths.win_set_cursor(0, { 1, 11 })
- local win = meths.get_current_win()
- local buf = meths.get_current_buf()
+ api.nvim_win_set_cursor(0, { 1, 11 })
+ local win = api.nvim_get_current_win()
+ local buf = api.nvim_get_current_buf()
command('split')
- local win2 = meths.get_current_win()
+ local win2 = api.nvim_get_current_win()
-- position the cursor on `w`
- meths.win_set_cursor(0, { 1, 6 })
+ api.nvim_win_set_cursor(0, { 1, 6 })
command('new')
-- replace 'hello' with 'foo'
- meths.buf_set_text(buf, 0, 0, 0, 5, { 'foo' })
- eq({ 'foo world!' }, meths.buf_get_lines(buf, 0, -1, true))
+ api.nvim_buf_set_text(buf, 0, 0, 0, 5, { 'foo' })
+ eq({ 'foo world!' }, api.nvim_buf_get_lines(buf, 0, -1, true))
-- both cursors should be moved left by two columns (replacement is shorter by 2 chars)
- eq({ 1, 9 }, meths.win_get_cursor(win))
- eq({ 1, 4 }, meths.win_get_cursor(win2))
+ eq({ 1, 9 }, api.nvim_win_get_cursor(win))
+ eq({ 1, 4 }, api.nvim_win_get_cursor(win2))
end)
describe('when text is being added right at cursor position #22526', function()
@@ -867,12 +892,12 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'c'
- curwin('set_cursor', { 1, 2 })
+ api.nvim_win_set_cursor(0, { 1, 2 })
-- add 'xxx' before 'c'
set_text(0, 2, 0, 2, { 'xxx' })
eq({ 'abxxxcd' }, get_lines(0, -1, true))
-- cursor should be on 'c'
- eq({ 1, 5 }, curwin('get_cursor'))
+ eq({ 1, 5 }, api.nvim_win_get_cursor(0))
end)
it('updates the cursor position only in non-current window when in INSERT mode', function()
@@ -880,7 +905,7 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'c'
- curwin('set_cursor', { 1, 2 })
+ api.nvim_win_set_cursor(0, { 1, 2 })
-- open vertical split
feed('<c-w>v')
-- get into INSERT mode to treat cursor
@@ -890,13 +915,13 @@ describe('api/buf', function()
set_text(0, 2, 0, 2, { 'xxx' })
eq({ 'abxxxcd' }, get_lines(0, -1, true))
-- in the current window cursor should stay after 'b'
- eq({ 1, 2 }, curwin('get_cursor'))
+ eq({ 1, 2 }, api.nvim_win_get_cursor(0))
-- quit INSERT mode
feed('<esc>')
-- close current window
feed('<c-w>c')
-- in another window cursor should be on 'c'
- eq({ 1, 5 }, curwin('get_cursor'))
+ eq({ 1, 5 }, api.nvim_win_get_cursor(0))
end)
end)
@@ -906,12 +931,12 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'b'
- curwin('set_cursor', { 1, 1 })
+ api.nvim_win_set_cursor(0, { 1, 1 })
-- delete 'b'
set_text(0, 1, 0, 2, {})
eq({ 'acd' }, get_lines(0, -1, true))
-- cursor is now on 'c'
- eq({ 1, 1 }, curwin('get_cursor'))
+ eq({ 1, 1 }, api.nvim_win_get_cursor(0))
end)
it('maintains INSERT-mode cursor position current/non-current window', function()
@@ -919,7 +944,7 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'b'
- curwin('set_cursor', { 1, 1 })
+ api.nvim_win_set_cursor(0, { 1, 1 })
-- open vertical split
feed('<c-w>v')
-- get into INSERT mode to treat cursor
@@ -929,13 +954,13 @@ describe('api/buf', function()
set_text(0, 1, 0, 2, {})
eq({ 'acd' }, get_lines(0, -1, true))
-- cursor in the current window should stay after 'a'
- eq({ 1, 1 }, curwin('get_cursor'))
+ eq({ 1, 1 }, api.nvim_win_get_cursor(0))
-- quit INSERT mode
feed('<esc>')
-- close current window
feed('<c-w>c')
-- cursor in non-current window should stay on 'c'
- eq({ 1, 1 }, curwin('get_cursor'))
+ eq({ 1, 1 }, api.nvim_win_get_cursor(0))
end)
end)
@@ -947,7 +972,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on ' ' before 'first'
- curwin('set_cursor', { 1, 14 })
+ api.nvim_win_set_cursor(0, { 1, 14 })
set_text(0, 15, 2, 11, {
'the line we do not want',
@@ -959,7 +984,7 @@ describe('api/buf', function()
'but hopefully the last one',
}, get_lines(0, -1, true))
-- cursor should stay at the same position
- eq({ 1, 14 }, curwin('get_cursor'))
+ eq({ 1, 14 }, api.nvim_win_get_cursor(0))
end)
it('maintains cursor position if at start_row and column is still valid', function()
@@ -969,7 +994,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'f' in 'first'
- curwin('set_cursor', { 1, 15 })
+ api.nvim_win_set_cursor(0, { 1, 15 })
set_text(0, 15, 2, 11, {
'the line we do not want',
@@ -981,7 +1006,7 @@ describe('api/buf', function()
'but hopefully the last one',
}, get_lines(0, -1, true))
-- cursor should stay at the same position
- eq({ 1, 15 }, curwin('get_cursor'))
+ eq({ 1, 15 }, api.nvim_win_get_cursor(0))
end)
it('adjusts cursor column to keep it valid if start_row got smaller', function()
@@ -991,7 +1016,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 't' in 'first'
- curwin('set_cursor', { 1, 19 })
+ api.nvim_win_set_cursor(0, { 1, 19 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'})
@@ -1000,7 +1025,7 @@ describe('api/buf', function()
eq({ 'This should be last' }, get_lines(0, -1, true))
-- cursor should end up on 't' in 'last'
- eq({ 1, 18 }, curwin('get_cursor'))
+ eq({ 1, 18 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 18 }, cursor)
end)
@@ -1012,7 +1037,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 't' in 'first'
- curwin('set_cursor', { 1, 19 })
+ api.nvim_win_set_cursor(0, { 1, 19 })
-- enter INSERT mode to treat cursor as being after 't'
feed('a')
@@ -1023,7 +1048,7 @@ describe('api/buf', function()
eq({ 'This should be last' }, get_lines(0, -1, true))
-- cursor should end up after 't' in 'last'
- eq({ 1, 19 }, curwin('get_cursor'))
+ eq({ 1, 19 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 19 }, cursor)
end)
@@ -1035,7 +1060,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'w' in 'want'
- curwin('set_cursor', { 2, 31 })
+ api.nvim_win_set_cursor(0, { 2, 31 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1052,7 +1077,7 @@ describe('api/buf', function()
'and then the last one',
}, get_lines(0, -1, true))
-- cursor column should end up at the end of a row
- eq({ 2, 5 }, curwin('get_cursor'))
+ eq({ 2, 5 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 5 }, cursor)
end)
@@ -1066,7 +1091,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'w' in 'want'
- curwin('set_cursor', { 2, 31 })
+ api.nvim_win_set_cursor(0, { 2, 31 })
-- enter INSERT mode
feed('a')
@@ -1085,7 +1110,7 @@ describe('api/buf', function()
'and then the last one',
}, get_lines(0, -1, true))
-- cursor column should end up at the end of a row
- eq({ 2, 6 }, curwin('get_cursor'))
+ eq({ 2, 6 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 6 }, cursor)
end
@@ -1098,7 +1123,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'n' in 'finally'
- curwin('set_cursor', { 3, 6 })
+ api.nvim_win_set_cursor(0, { 3, 6 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1114,7 +1139,7 @@ describe('api/buf', function()
}, get_lines(0, -1, true))
-- cursor should end up on 'y' in 'hopefully'
-- to stay in the range, because it got smaller
- eq({ 2, 12 }, curwin('get_cursor'))
+ eq({ 2, 12 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 12 }, cursor)
end)
@@ -1126,7 +1151,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'r' in 'there'
- curwin('set_cursor', { 2, 8 })
+ api.nvim_win_set_cursor(0, { 2, 8 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {})
@@ -1135,7 +1160,7 @@ describe('api/buf', function()
eq({ 'This should be the last one' }, get_lines(0, -1, true))
-- cursor should end up on the next column after deleted range
- eq({ 1, 15 }, curwin('get_cursor'))
+ eq({ 1, 15 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 15 }, cursor)
end)
@@ -1147,7 +1172,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'r' in 'there'
- curwin('set_cursor', { 2, 8 })
+ api.nvim_win_set_cursor(0, { 2, 8 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {})
@@ -1156,7 +1181,7 @@ describe('api/buf', function()
eq({ 'finally the last one' }, get_lines(0, -1, true))
-- cursor should end up in column 0
- eq({ 1, 0 }, curwin('get_cursor'))
+ eq({ 1, 0 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 0 }, cursor)
end)
@@ -1168,7 +1193,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'y' in 'finally'
- curwin('set_cursor', { 3, 10 })
+ api.nvim_win_set_cursor(0, { 3, 10 })
set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' })
eq({
@@ -1177,7 +1202,7 @@ describe('api/buf', function()
'and then the last one',
}, get_lines(0, -1, true))
-- cursor should end up on 'n' in 'then'
- eq({ 3, 7 }, curwin('get_cursor'))
+ eq({ 3, 7 }, api.nvim_win_get_cursor(0))
end)
it(
@@ -1189,7 +1214,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'y' at 'finally'
- curwin('set_cursor', { 3, 10 })
+ api.nvim_win_set_cursor(0, { 3, 10 })
-- enter INSERT mode to treat cursor as being between 'l' and 'y'
feed('i')
set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' })
@@ -1200,7 +1225,7 @@ describe('api/buf', function()
'and then the last one',
}, get_lines(0, -1, true))
-- cursor should end up after 'n' in 'then'
- eq({ 3, 8 }, curwin('get_cursor'))
+ eq({ 3, 8 }, api.nvim_win_get_cursor(0))
end
)
@@ -1211,7 +1236,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'y' in 'finally'
- curwin('set_cursor', { 3, 10 })
+ api.nvim_win_set_cursor(0, { 3, 10 })
set_text(2, 4, 2, 11, { 'then' })
eq({
@@ -1220,7 +1245,7 @@ describe('api/buf', function()
'and then the last one',
}, get_lines(0, -1, true))
-- cursor should end up on 'n' in 'then'
- eq({ 3, 7 }, curwin('get_cursor'))
+ eq({ 3, 7 }, api.nvim_win_get_cursor(0))
end)
it('does not move cursor column after end of a line', function()
@@ -1229,7 +1254,7 @@ describe('api/buf', function()
!!!]])
-- position cursor on the last '1'
- curwin('set_cursor', { 2, 2 })
+ api.nvim_win_set_cursor(0, { 2, 2 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {})
@@ -1238,7 +1263,7 @@ describe('api/buf', function()
eq({ 'This should be the only line here' }, get_lines(0, -1, true))
-- cursor should end up on '!'
- eq({ 1, 32 }, curwin('get_cursor'))
+ eq({ 1, 32 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 32 }, cursor)
end)
@@ -1247,7 +1272,7 @@ describe('api/buf', function()
insert('\n!!!')
-- position cursor on the last '1'
- curwin('set_cursor', { 2, 2 })
+ api.nvim_win_set_cursor(0, { 2, 2 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {})
@@ -1256,7 +1281,7 @@ describe('api/buf', function()
eq({ '' }, get_lines(0, -1, true))
-- cursor should end up on '!'
- eq({ 1, 0 }, curwin('get_cursor'))
+ eq({ 1, 0 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 0 }, cursor)
end)
@@ -1269,7 +1294,7 @@ describe('api/buf', function()
and finally the last one]])
-- position cursor on 't' in 'want'
- curwin('set_cursor', { 2, 34 })
+ api.nvim_win_set_cursor(0, { 2, 34 })
-- turn on virtualedit
command('set virtualedit=all')
@@ -1287,7 +1312,7 @@ describe('api/buf', function()
}, get_lines(0, -1, true))
-- cursor should end up on 'y' in 'hopefully'
-- to stay in the range
- eq({ 2, 12 }, curwin('get_cursor'))
+ eq({ 2, 12 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 12 }, cursor)
-- coladd should be 0
@@ -1306,7 +1331,7 @@ describe('api/buf', function()
and finally the last one]])
-- position cursor on 't' in 'want'
- curwin('set_cursor', { 2, 34 })
+ api.nvim_win_set_cursor(0, { 2, 34 })
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol
@@ -1327,7 +1352,7 @@ describe('api/buf', function()
'but hopefully the last one',
}, get_lines(0, -1, true))
-- cursor should end up at eol of a new row
- eq({ 2, 26 }, curwin('get_cursor'))
+ eq({ 2, 26 }, api.nvim_win_get_cursor(0))
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 26 }, cursor)
-- coladd should be increased so that cursor stays in the same screen colum