aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/buffer_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-12-07 12:19:35 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:28 +0100
commit59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (patch)
treeac8f9b52013066f1145215dd46327d814b8cf02b /test/functional/api/buffer_spec.lua
parentb3eda5e73f65092d50ccd27a0373e8b9fad076b0 (diff)
downloadrneovim-59d117ec99b6037cb9fad5bbfb6d0b18f5012927.tar.gz
rneovim-59d117ec99b6037cb9fad5bbfb6d0b18f5012927.tar.bz2
rneovim-59d117ec99b6037cb9fad5bbfb6d0b18f5012927.zip
build: enable lintlua for test/ dir
Problem: Not all Lua code is checked by stylua. Automating code-style is an important mechanism for reducing time spent on accidental (non-essential) complexity. Solution: - Enable stylua for entire `test/` directory. - Exclude these high-churn files until this issue is resolved: https://github.com/JohnnyMorganz/StyLua/issues/829 ``` test/functional/ui/decorations_spec.lua | 3560 ++++++++++++++++++++++++++++++++++++---------------- test/functional/ui/float_spec.lua | 5826 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- test/functional/ui/multigrid_spec.lua | 1349 ++++++++++++++------ ``` - Make surgical changes to these files (or add `stylua: ignore` in some small scopes) to improve the result: ``` test/functional/vimscript/msgpack_functions_spec.lua | 1414 +++++++++++++++------ test/functional/api/buffer_spec.lua | 1389 +++++++++++---------- test/functional/api/vim_spec.lua | 2740 +++++++++++++++++++++++----------------- ``` - These "high churn" files are NOT excluded because the changes are largely an improvement: ``` test/functional/plugin/lsp_spec.lua | 2198 ++++++++++++++++++--------------- test/functional/plugin/shada_spec.lua | 4078 +++++++++++++++++++++++++++++++++++------------------------- test/functional/ui/cmdline_spec.lua | 1199 +++++++++++------- test/functional/ui/popupmenu_spec.lua | 1267 +++++++++++-------- test/functional/ui/messages_spec.lua | 1643 +++++++++++++++--------- ``` - TODO: how to check "all directories"? With `GLOB_DIRS *` and `/.deps/` (or `.deps/`) in `.styluaignore`, Lua code in `.deps/` is still checked...
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r--test/functional/api/buffer_spec.lua1200
1 files changed, 637 insertions, 563 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index b89101a5e7..e8fff7443d 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -23,16 +23,15 @@ describe('api/buf', function()
-- access deprecated functions
local function curbuf_depr(method, ...)
- return request('buffer_'..method, 0, ...)
+ 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'})
+ curbuf_depr('insert', -1, { 'line' })
eq(2, curbuf_depr('line_count'))
- curbuf_depr('insert', -1, {'line'})
+ curbuf_depr('insert', -1, { 'line' })
eq(3, curbuf_depr('line_count'))
curbuf_depr('del_line', -1)
eq(2, curbuf_depr('line_count'))
@@ -45,88 +44,88 @@ describe('api/buf', function()
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, { })
+ 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"})
+ 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})
+ 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"})
+ 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))
+ 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'))
+ eq({ 4, 2 }, curwin('get_cursor'))
-- add a line after the current cursor position.
- request('nvim_buf_set_lines', 0, 5, 5, 1, {"line7"})
+ 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))
+ eq({ 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
- eq({4, 2}, curwin('get_cursor'))
+ eq({ 4, 2 }, curwin('get_cursor'))
-- overwrite current cursor line.
- request('nvim_buf_set_lines', 0, 3, 5, 1, {"line8", "line9"})
+ 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))
+ eq({ 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' }, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
- eq({4, 2}, curwin('get_cursor'))
+ 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))
+ eq({ 'line1', 'line5', 'line6', 'line7' }, buffer('get_lines', 0, 0, -1, 1))
-- cursor position is unchanged.
- eq({4, 2}, curwin('get_cursor'))
+ 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})
+ 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_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))
+ 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))
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})
+ 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('split')
- meths.win_set_cursor(0, {4, 2})
+ meths.win_set_cursor(0, { 4, 2 })
local win2 = meths.get_current_win()
-- set current window to third one with another buffer
- command("new")
+ 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))
+ 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))
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"})
+ 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)
+ command('bunload! ' .. bufnr)
-- line count for an unloaded buffer should always be 0
eq(0, request('nvim_buf_line_count', bufnr))
end)
@@ -135,12 +134,12 @@ describe('api/buf', 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"})
+ 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))
+ eq({ 'line2', 'line3' }, buffer('get_lines', bufnr, 1, 3, 1))
-- force unload the buffer (this will discard changes)
command('new')
- command('bunload! '..bufnr)
+ 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
@@ -152,12 +151,12 @@ describe('api/buf', function()
before_each(function()
screen = Screen.new(20, 12)
screen:set_default_attr_ids {
- [1] = {bold = true, foreground = Screen.colors.Blue1};
- [2] = {reverse = true, bold = true};
- [3] = {reverse = true};
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { reverse = true, bold = true },
+ [3] = { reverse = true },
}
screen:attach()
- meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
+ meths.buf_set_lines(0, 0, -1, 1, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' })
meths.set_option_value('modified', false, {})
end)
@@ -166,9 +165,10 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('new | wincmd w')
- meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(win, { 8, 0 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -178,10 +178,12 @@ describe('api/buf', function()
^zzz |
{2:[No Name] }|
|
- ]]}
+ ]],
+ }
- meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -191,11 +193,13 @@ describe('api/buf', function()
^zzz |
{2:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -205,11 +209,13 @@ describe('api/buf', function()
^zzz |
{2:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- inserting just before topline does not scroll up if cursor would be moved
- meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -219,10 +225,13 @@ describe('api/buf', function()
^zzz |
{2:[No Name] [+] }|
|
- ]], unchanged=true}
+ ]],
+ unchanged = true,
+ }
- meths.win_set_cursor(0, {7, 0})
- screen:expect{grid=[[
+ meths.win_set_cursor(0, { 7, 0 })
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -232,10 +241,12 @@ describe('api/buf', function()
zzz |
{2:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
- meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' })
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -245,7 +256,8 @@ describe('api/buf', function()
^yyy |
{2:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
it('of non-current window', function()
@@ -253,9 +265,10 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('new')
- meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(win, { 8, 0 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -265,10 +278,12 @@ describe('api/buf', function()
zzz |
{3:[No Name] }|
|
- ]]}
+ ]],
+ }
- meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -278,11 +293,13 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -292,11 +309,13 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- inserting just before topline scrolls up
- meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -306,7 +325,8 @@ describe('api/buf', function()
yyy |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
it('of split windows with same buffer', function()
@@ -314,10 +334,11 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('split')
- meths.win_set_cursor(win, {8,0})
- meths.win_set_cursor(0, {1,0})
+ meths.win_set_cursor(win, { 8, 0 })
+ meths.win_set_cursor(0, { 1, 0 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^aaa |
bbb |
ccc |
@@ -330,10 +351,12 @@ describe('api/buf', function()
zzz |
{3:[No Name] }|
|
- ]]}
- meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
+ ]],
+ }
+ meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^aaabbb |
ccc |
ddd |
@@ -346,11 +369,13 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- replacing topline keeps it the topline
- meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
+ screen:expect {
+ grid = [[
^aaabbb |
ccc |
ddd |
@@ -363,11 +388,13 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
-- inserting just before topline scrolls up
- meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
- screen:expect{grid=[[
+ meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
+ screen:expect {
+ grid = [[
^aaabbb |
ccc |
ddd |
@@ -380,20 +407,21 @@ describe('api/buf', function()
yyy |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
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"})
- command("new")
+ local buf = meths.get_current_buf()
+ meths.buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' })
+ command('new')
- meths.buf_set_lines(0, 0, -1, true, {"xxx", "yyy", "zzz"})
+ meths.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))
+ 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))
end)
end)
@@ -431,8 +459,8 @@ describe('api/buf', function()
describe('deprecated: {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'})
- eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity
+ curbuf_depr('set_line_slice', 0, 0, true, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity
eq({}, curbuf_depr('get_line_slice', 2, 3, false, true))
eq({}, curbuf_depr('get_line_slice', 3, 9, true, true))
@@ -442,37 +470,36 @@ describe('api/buf', function()
end)
it('set_line_slice: out-of-bounds extends past end', function()
- curbuf_depr('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity
+ curbuf_depr('set_line_slice', 0, 0, true, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity
- eq({'c'}, curbuf_depr('get_line_slice', -1, 4, true, true))
- eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 5, true, true))
- curbuf_depr('set_line_slice', 4, 5, true, true, {'d'})
- eq({'a', 'b', 'c', 'd'}, curbuf_depr('get_line_slice', 0, 5, true, true))
- curbuf_depr('set_line_slice', -4, -5, true, true, {'e'})
- eq({'e', 'a', 'b', 'c', 'd'}, curbuf_depr('get_line_slice', 0, 5, true, true))
+ eq({ 'c' }, curbuf_depr('get_line_slice', -1, 4, true, true))
+ eq({ 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, 5, true, true))
+ curbuf_depr('set_line_slice', 4, 5, true, true, { 'd' })
+ eq({ 'a', 'b', 'c', 'd' }, curbuf_depr('get_line_slice', 0, 5, true, true))
+ curbuf_depr('set_line_slice', -4, -5, true, true, { 'e' })
+ eq({ 'e', 'a', 'b', 'c', 'd' }, curbuf_depr('get_line_slice', 0, 5, true, true))
end)
it('works', function()
- eq({''}, curbuf_depr('get_line_slice', 0, -1, true, true))
+ eq({ '' }, curbuf_depr('get_line_slice', 0, -1, true, true))
-- Replace buffer
- curbuf_depr('set_line_slice', 0, -1, true, true, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true))
- eq({'b', 'c'}, curbuf_depr('get_line_slice', 1, -1, true, true))
- eq({'b'}, curbuf_depr('get_line_slice', 1, 2, true, false))
+ curbuf_depr('set_line_slice', 0, -1, true, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, -1, true, true))
+ eq({ 'b', 'c' }, curbuf_depr('get_line_slice', 1, -1, true, true))
+ eq({ 'b' }, curbuf_depr('get_line_slice', 1, 2, true, false))
eq({}, curbuf_depr('get_line_slice', 1, 1, true, false))
- eq({'a', 'b'}, curbuf_depr('get_line_slice', 0, -1, true, false))
- eq({'b'}, curbuf_depr('get_line_slice', 1, -1, true, false))
- eq({'b', 'c'}, curbuf_depr('get_line_slice', -2, -1, true, true))
- curbuf_depr('set_line_slice', 1, 2, true, false, {'a', 'b', 'c'})
- eq({'a', 'a', 'b', 'c', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true))
- curbuf_depr('set_line_slice', -1, -1, true, true, {'a', 'b', 'c'})
- eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'},
- curbuf_depr('get_line_slice', 0, -1, true, true))
+ eq({ 'a', 'b' }, curbuf_depr('get_line_slice', 0, -1, true, false))
+ eq({ 'b' }, curbuf_depr('get_line_slice', 1, -1, true, false))
+ eq({ 'b', 'c' }, curbuf_depr('get_line_slice', -2, -1, true, true))
+ curbuf_depr('set_line_slice', 1, 2, true, false, { 'a', 'b', 'c' })
+ eq({ 'a', 'a', 'b', 'c', 'c' }, curbuf_depr('get_line_slice', 0, -1, true, true))
+ curbuf_depr('set_line_slice', -1, -1, true, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'a', 'b', 'c', 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, -1, true, true))
curbuf_depr('set_line_slice', 0, -3, true, false, {})
- eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true))
+ eq({ 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, -1, true, true))
curbuf_depr('set_line_slice', 0, -1, true, true, {})
- eq({''}, curbuf_depr('get_line_slice', 0, -1, true, true))
+ eq({ '' }, curbuf_depr('get_line_slice', 0, -1, true, true))
end)
end)
@@ -483,21 +510,25 @@ describe('api/buf', function()
it('fails correctly when input is not valid', function()
eq(1, api.curbufmeths.get_number())
- eq([['replacement string' item contains newlines]],
- pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'}))
+ eq(
+ [['replacement string' item contains newlines]],
+ pcall_err(bufmeths.set_lines, 1, 1, 2, false, { 'b\na' })
+ )
end)
it("fails if 'nomodifiable'", function()
command('set nomodifiable')
- eq([[Buffer is not 'modifiable']],
- pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, {'a','b'}))
+ eq(
+ [[Buffer is not 'modifiable']],
+ pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, { 'a', 'b' })
+ )
end)
it('has correct line_count when inserting and deleting', function()
eq(1, line_count())
- set_lines(-1, -1, true, {'line'})
+ set_lines(-1, -1, true, { 'line' })
eq(2, line_count())
- set_lines(-1, -1, true, {'line'})
+ set_lines(-1, -1, true, { 'line' })
eq(3, line_count())
set_lines(-2, -1, true, {})
eq(2, line_count())
@@ -508,81 +539,80 @@ describe('api/buf', function()
end)
it('can get, set and delete a single line', function()
- eq({''}, get_lines(0, 1, true))
- set_lines(0, 1, true, {'line1'})
- eq({'line1'}, get_lines(0, 1, true))
- set_lines(0, 1, true, {'line2'})
- eq({'line2'}, get_lines(0, 1, true))
+ eq({ '' }, get_lines(0, 1, true))
+ set_lines(0, 1, true, { 'line1' })
+ eq({ 'line1' }, get_lines(0, 1, true))
+ set_lines(0, 1, true, { 'line2' })
+ eq({ 'line2' }, get_lines(0, 1, true))
set_lines(0, 1, true, {})
- eq({''}, get_lines(0, 1, true))
+ eq({ '' }, get_lines(0, 1, true))
end)
it('can get a single line with strict indexing', function()
- set_lines(0, 1, true, {'line1.a'})
+ set_lines(0, 1, true, { 'line1.a' })
eq(1, line_count()) -- sanity
eq('Index out of bounds', pcall_err(get_lines, 1, 2, true))
eq('Index out of bounds', pcall_err(get_lines, -3, -2, true))
end)
it('can get a single line with non-strict indexing', function()
- set_lines(0, 1, true, {'line1.a'})
+ set_lines(0, 1, true, { 'line1.a' })
eq(1, line_count()) -- sanity
eq({}, get_lines(1, 2, false))
eq({}, get_lines(-3, -2, false))
end)
it('can set and delete a single line with strict indexing', function()
- set_lines(0, 1, true, {'line1.a'})
- eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {'line1.b'}))
- eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {'line1.c'}))
- eq({'line1.a'}, get_lines(0, -1, true))
+ set_lines(0, 1, true, { 'line1.a' })
+ eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, { 'line1.b' }))
+ eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, { 'line1.c' }))
+ eq({ 'line1.a' }, get_lines(0, -1, true))
eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {}))
eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {}))
- eq({'line1.a'}, get_lines(0, -1, true))
+ eq({ 'line1.a' }, get_lines(0, -1, true))
end)
it('can set and delete a single line with non-strict indexing', function()
- set_lines(0, 1, true, {'line1.a'})
- set_lines(1, 2, false, {'line1.b'})
- set_lines(-4, -3, false, {'line1.c'})
- eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true))
+ set_lines(0, 1, true, { 'line1.a' })
+ set_lines(1, 2, false, { 'line1.b' })
+ set_lines(-4, -3, false, { 'line1.c' })
+ eq({ 'line1.c', 'line1.a', 'line1.b' }, get_lines(0, -1, true))
set_lines(3, 4, false, {})
set_lines(-5, -4, false, {})
- eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true))
+ eq({ 'line1.c', 'line1.a', 'line1.b' }, get_lines(0, -1, true))
end)
it('can handle NULs', function()
- set_lines(0, 1, true, {'ab\0cd'})
- eq({'ab\0cd'}, get_lines(0, -1, true))
+ set_lines(0, 1, true, { 'ab\0cd' })
+ eq({ 'ab\0cd' }, get_lines(0, -1, true))
end)
it('works with multiple lines', function()
- eq({''}, get_lines(0, -1, true))
+ eq({ '' }, get_lines(0, -1, true))
-- Replace buffer
- for _, mode in pairs({false, true}) do
- set_lines(0, -1, mode, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, get_lines(0, -1, mode))
- eq({'b', 'c'}, get_lines(1, -1, mode))
- eq({'b'}, get_lines(1, 2, mode))
+ for _, mode in pairs({ false, true }) do
+ set_lines(0, -1, mode, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, get_lines(0, -1, mode))
+ eq({ 'b', 'c' }, get_lines(1, -1, mode))
+ eq({ 'b' }, get_lines(1, 2, mode))
eq({}, get_lines(1, 1, mode))
- eq({'a', 'b'}, get_lines(0, -2, mode))
- eq({'b'}, get_lines(1, -2, mode))
- eq({'b', 'c'}, get_lines(-3, -1, mode))
- set_lines(1, 2, mode, {'a', 'b', 'c'})
- eq({'a', 'a', 'b', 'c', 'c'}, get_lines(0, -1, mode))
- set_lines(-2, -1, mode, {'a', 'b', 'c'})
- eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'},
- get_lines(0, -1, mode))
+ eq({ 'a', 'b' }, get_lines(0, -2, mode))
+ eq({ 'b' }, get_lines(1, -2, mode))
+ eq({ 'b', 'c' }, get_lines(-3, -1, mode))
+ set_lines(1, 2, mode, { 'a', 'b', 'c' })
+ eq({ 'a', 'a', 'b', 'c', 'c' }, get_lines(0, -1, mode))
+ set_lines(-2, -1, mode, { 'a', 'b', 'c' })
+ eq({ 'a', 'a', 'b', 'c', 'a', 'b', 'c' }, get_lines(0, -1, mode))
set_lines(0, -4, mode, {})
- eq({'a', 'b', 'c'}, get_lines(0, -1, mode))
+ eq({ 'a', 'b', 'c' }, get_lines(0, -1, mode))
set_lines(0, -1, mode, {})
- eq({''}, get_lines(0, -1, mode))
+ eq({ '' }, get_lines(0, -1, mode))
end
end)
it('can get line ranges with non-strict indexing', function()
- set_lines(0, -1, true, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+ set_lines(0, -1, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, get_lines(0, -1, true)) --sanity
eq({}, get_lines(3, 4, false))
eq({}, get_lines(3, 10, false))
@@ -592,8 +622,8 @@ describe('api/buf', function()
end)
it('can get line ranges with strict indexing', function()
- set_lines(0, -1, true, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+ set_lines(0, -1, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, get_lines(0, -1, true)) --sanity
eq('Index out of bounds', pcall_err(get_lines, 3, 4, true))
eq('Index out of bounds', pcall_err(get_lines, 3, 10, true))
@@ -604,20 +634,20 @@ describe('api/buf', function()
end)
it('set_lines: out-of-bounds can extend past end', function()
- set_lines(0, -1, true, {'a', 'b', 'c'})
- eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+ set_lines(0, -1, true, { 'a', 'b', 'c' })
+ eq({ 'a', 'b', 'c' }, get_lines(0, -1, true)) --sanity
- eq({'c'}, get_lines(-2, 5, false))
- eq({'a', 'b', 'c'}, get_lines(0, 6, false))
- eq('Index out of bounds', pcall_err(set_lines, 4, 6, true, {'d'}))
- set_lines(4, 6, false, {'d'})
- eq({'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
- eq('Index out of bounds', pcall_err(set_lines, -6, -6, true, {'e'}))
- set_lines(-6, -6, false, {'e'})
- eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
+ eq({ 'c' }, get_lines(-2, 5, false))
+ eq({ 'a', 'b', 'c' }, get_lines(0, 6, false))
+ eq('Index out of bounds', pcall_err(set_lines, 4, 6, true, { 'd' }))
+ set_lines(4, 6, false, { 'd' })
+ eq({ 'a', 'b', 'c', 'd' }, get_lines(0, -1, true))
+ eq('Index out of bounds', pcall_err(set_lines, -6, -6, true, { 'e' }))
+ set_lines(-6, -6, false, { 'e' })
+ eq({ 'e', 'a', 'b', 'c', 'd' }, get_lines(0, -1, true))
end)
- it("set_lines on alternate buffer does not access invalid line (E315)", function()
+ it('set_lines on alternate buffer does not access invalid line (E315)', function()
feed_command('set hidden')
insert('Initial file')
command('enew')
@@ -637,8 +667,8 @@ describe('api/buf', function()
it("set_lines of invisible buffer doesn't move cursor in current window", function()
local screen = Screen.new(20, 5)
screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- [2] = {bold = true},
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { bold = true },
})
screen:attach()
@@ -646,7 +676,7 @@ describe('api/buf', function()
Who would win?
A real window
with proper text]])
- local buf = api.meths.create_buf(false,true)
+ local buf = api.meths.create_buf(false, true)
screen:expect([[
Who would win? |
A real window |
@@ -655,7 +685,7 @@ describe('api/buf', function()
|
]])
- api.meths.buf_set_lines(buf, 0, -1, true, {'or some', 'scratchy text'})
+ api.meths.buf_set_lines(buf, 0, -1, true, { 'or some', 'scratchy text' })
feed('i') -- provoke redraw
screen:expect([[
Who would win? |
@@ -671,32 +701,31 @@ describe('api/buf', function()
visible buffer line 1
line 2
]])
- local hiddenbuf = api.meths.create_buf(false,true)
+ local hiddenbuf = api.meths.create_buf(false, true)
command('vsplit')
command('vsplit')
feed('<c-w>l<c-w>l<c-w>l')
eq(3, funcs.winnr())
feed('<c-w>h')
eq(2, funcs.winnr())
- api.meths.buf_set_lines(hiddenbuf, 0, -1, true,
- {'hidden buffer line 1', 'line 2'})
+ api.meths.buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' })
feed('<c-w>p')
eq(3, funcs.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_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' })
meths.buf_set_name(bufnr, 'set_lines')
finally(function()
os.remove('set_lines')
end)
command('write!')
command('new')
- command('bunload! '..bufnr)
+ 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))
+ eq({ '' }, meths.buf_get_lines(new_bufnr, 0, -1, false))
end)
end)
@@ -709,70 +738,69 @@ describe('api/buf', function()
text
]])
- eq({'hello foo!'}, get_lines(0, 1, true))
-
+ eq({ 'hello foo!' }, get_lines(0, 1, true))
-- can replace a single word
- set_text(0, 6, 0, 9, {'world'})
- eq({'hello world!', 'text'}, get_lines(0, 2, true))
+ set_text(0, 6, 0, 9, { 'world' })
+ eq({ 'hello world!', 'text' }, get_lines(0, 2, true))
-- can insert text
- set_text(0, 0, 0, 0, {'well '})
- eq({'well hello world!', 'text'}, get_lines(0, 2, true))
+ set_text(0, 0, 0, 0, { 'well ' })
+ eq({ 'well hello world!', 'text' }, get_lines(0, 2, true))
-- can delete text
- set_text(0, 0, 0, 5, {''})
- eq({'hello world!', 'text'}, get_lines(0, 2, true))
+ set_text(0, 0, 0, 5, { '' })
+ eq({ 'hello world!', 'text' }, get_lines(0, 2, true))
-- can replace with multiple lines
- set_text(0, 6, 0, 11, {'foo', 'wo', 'more'})
- eq({'hello foo', 'wo', 'more!', 'text'}, get_lines(0, 4, true))
+ set_text(0, 6, 0, 11, { 'foo', 'wo', 'more' })
+ eq({ 'hello foo', 'wo', 'more!', 'text' }, get_lines(0, 4, true))
-- will join multiple lines if needed
- set_text(0, 6, 3, 4, {'bar'})
- eq({'hello bar'}, get_lines(0, 1, true))
+ set_text(0, 6, 3, 4, { 'bar' })
+ eq({ 'hello bar' }, get_lines(0, 1, true))
-- can use negative line numbers
- set_text(-2, 0, -2, 5, {'goodbye'})
- eq({'goodbye bar', ''}, get_lines(0, -1, true))
+ set_text(-2, 0, -2, 5, { 'goodbye' })
+ eq({ 'goodbye bar', '' }, get_lines(0, -1, true))
- set_text(-1, 0, -1, 0, {'text'})
- eq({'goodbye bar', 'text'}, get_lines(0, 2, true))
+ set_text(-1, 0, -1, 0, { 'text' })
+ eq({ 'goodbye bar', 'text' }, get_lines(0, 2, true))
-- can append to a line
- set_text(1, 4, -1, 4, {' and', 'more'})
- eq({'goodbye bar', 'text and', 'more'}, get_lines(0, 3, true))
+ set_text(1, 4, -1, 4, { ' and', 'more' })
+ eq({ 'goodbye bar', 'text and', 'more' }, get_lines(0, 3, true))
-- can use negative column numbers
- set_text(0, -5, 0, -1, {'!'})
- eq({'goodbye!'}, get_lines(0, 1, true))
+ set_text(0, -5, 0, -1, { '!' })
+ eq({ 'goodbye!' }, get_lines(0, 1, true))
end)
it('works with undo', function()
- insert([[
+ insert([[
hello world!
foo bar
]])
- -- setting text
- set_text(0, 0, 0, 0, {'well '})
- feed('u')
- eq({'hello world!'}, get_lines(0, 1, true))
+ -- setting text
+ set_text(0, 0, 0, 0, { 'well ' })
+ feed('u')
+ eq({ 'hello world!' }, get_lines(0, 1, true))
- -- deleting text
- set_text(0, 0, 0, 6, {''})
- feed('u')
- eq({'hello world!'}, get_lines(0, 1, true))
+ -- deleting text
+ set_text(0, 0, 0, 6, { '' })
+ feed('u')
+ eq({ 'hello world!' }, get_lines(0, 1, true))
- -- inserting newlines
- set_text(0, 0, 0, 0, {'hello', 'mr '})
- feed('u')
- eq({'hello world!'}, get_lines(0, 1, true))
+ -- inserting newlines
+ set_text(0, 0, 0, 0, { 'hello', 'mr ' })
+ feed('u')
+ eq({ 'hello world!' }, get_lines(0, 1, true))
- -- deleting newlines
- set_text(0, 0, 1, 4, {'hello'})
- feed('u')
- eq({'hello world!'}, get_lines(0, 1, true))
+ -- deleting newlines
+ set_text(0, 0, 1, 4, { 'hello' })
+ feed('u')
+ eq({ 'hello world!' }, get_lines(0, 1, true))
end)
it('updates the cursor position', function()
@@ -781,12 +809,12 @@ describe('api/buf', function()
]])
-- position the cursor on `!`
- curwin('set_cursor', {1, 11})
+ curwin('set_cursor', { 1, 11 })
-- replace 'world' with 'foo'
- set_text(0, 6, 0, 11, {'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 }, curwin('get_cursor'))
end)
it('updates the cursor position in non-current window', function()
@@ -794,18 +822,18 @@ describe('api/buf', function()
hello world!]])
-- position the cursor on `!`
- meths.win_set_cursor(0, {1, 11})
+ meths.win_set_cursor(0, { 1, 11 })
local win = meths.get_current_win()
local buf = meths.get_current_buf()
- command("new")
+ 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))
+ meths.buf_set_text(buf, 0, 6, 0, 11, { 'foo' })
+ eq({ 'hello foo!' }, meths.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 }, meths.win_get_cursor(win))
end)
it('updates the cursor position in TWO non-current windows', function()
@@ -813,24 +841,24 @@ describe('api/buf', function()
hello world!]])
-- position the cursor on `!`
- meths.win_set_cursor(0, {1, 11})
+ meths.win_set_cursor(0, { 1, 11 })
local win = meths.get_current_win()
local buf = meths.get_current_buf()
- command("split")
+ command('split')
local win2 = meths.get_current_win()
-- position the cursor on `w`
- meths.win_set_cursor(0, {1, 6})
+ meths.win_set_cursor(0, { 1, 6 })
- command("new")
+ 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))
+ meths.buf_set_text(buf, 0, 0, 0, 5, { 'foo' })
+ eq({ 'foo world!' }, meths.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 }, meths.win_get_cursor(win))
+ eq({ 1, 4 }, meths.win_get_cursor(win2))
end)
describe('when text is being added right at cursor position #22526', function()
@@ -839,12 +867,12 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'c'
- curwin('set_cursor', {1, 2})
+ curwin('set_cursor', { 1, 2 })
-- add 'xxx' before 'c'
- set_text(0, 2, 0, 2, {'xxx'})
- eq({'abxxxcd'}, get_lines(0, -1, true))
+ 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 }, curwin('get_cursor'))
end)
it('updates the cursor position only in non-current window when in INSERT mode', function()
@@ -852,23 +880,23 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'c'
- curwin('set_cursor', {1, 2})
+ curwin('set_cursor', { 1, 2 })
-- open vertical split
feed('<c-w>v')
-- get into INSERT mode to treat cursor
-- as being after 'b', not on 'c'
feed('i')
-- add 'xxx' between 'b' and 'c'
- set_text(0, 2, 0, 2, {'xxx'})
- eq({'abxxxcd'}, get_lines(0, -1, true))
+ 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 }, curwin('get_cursor'))
-- 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 }, curwin('get_cursor'))
end)
end)
@@ -878,20 +906,20 @@ describe('api/buf', function()
abcd]])
-- position the cursor on 'b'
- curwin('set_cursor', {1, 1})
+ curwin('set_cursor', { 1, 1 })
-- delete 'b'
set_text(0, 1, 0, 2, {})
- eq({'acd'}, get_lines(0, -1, true))
+ eq({ 'acd' }, get_lines(0, -1, true))
-- cursor is now on 'c'
- eq({1, 1}, curwin('get_cursor'))
+ eq({ 1, 1 }, curwin('get_cursor'))
end)
- it('leaves cursor at the same position in INSERT mode in current and non-current window', function()
+ it('maintains INSERT-mode cursor position current/non-current window', function()
insert([[
abcd]])
-- position the cursor on 'b'
- curwin('set_cursor', {1, 1})
+ curwin('set_cursor', { 1, 1 })
-- open vertical split
feed('<c-w>v')
-- get into INSERT mode to treat cursor
@@ -899,27 +927,27 @@ describe('api/buf', function()
feed('i')
-- delete 'b'
set_text(0, 1, 0, 2, {})
- eq({'acd'}, get_lines(0, -1, true))
+ 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 }, curwin('get_cursor'))
-- 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 }, curwin('get_cursor'))
end)
end)
describe('when cursor is inside replaced row range', function()
- it('keeps cursor at the same position if cursor is at start_row, but before start_col', function()
+ it('maintains cursor position if at start_row, but before start_col', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position the cursor on ' ' before 'first'
- curwin('set_cursor', {1, 14})
+ curwin('set_cursor', { 1, 14 })
set_text(0, 15, 2, 11, {
'the line we do not want',
@@ -931,17 +959,17 @@ 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 }, curwin('get_cursor'))
end)
- it('keeps cursor at the same position if cursor is at start_row and column is still valid', function()
+ it('maintains cursor position if at start_row and column is still valid', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position the cursor on 'f' in 'first'
- curwin('set_cursor', {1, 15})
+ curwin('set_cursor', { 1, 15 })
set_text(0, 15, 2, 11, {
'the line we do not want',
@@ -953,7 +981,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 }, curwin('get_cursor'))
end)
it('adjusts cursor column to keep it valid if start_row got smaller', function()
@@ -963,7 +991,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 't' in 'first'
- curwin('set_cursor', {1, 19})
+ curwin('set_cursor', { 1, 19 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'})
@@ -972,19 +1000,19 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 18}, cursor)
+ eq({ 1, 18 }, cursor)
end)
- it('adjusts cursor column to keep it valid if start_row got smaller in INSERT mode', function()
+ it('adjusts cursor column to keep it valid if start_row decreased in INSERT mode', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position the cursor on 't' in 'first'
- curwin('set_cursor', {1, 19})
+ curwin('set_cursor', { 1, 19 })
-- enter INSERT mode to treat cursor as being after 't'
feed('a')
@@ -995,19 +1023,19 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 19}, cursor)
+ eq({ 1, 19 }, cursor)
end)
- it('adjusts cursor column to keep it valid in a row after start_row if it got smaller', function()
+ it('adjusts cursor to valid column in row after start_row if it got smaller', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position the cursor on 'w' in 'want'
- curwin('set_cursor', {2, 31})
+ curwin('set_cursor', { 2, 31 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1024,23 +1052,25 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({2, 5}, cursor)
+ eq({ 2, 5 }, cursor)
end)
- it('adjusts cursor column to keep it valid in a row after start_row if it got smaller in INSERT mode', function()
- insert([[
+ it(
+ 'adjusts cursor to valid column in row after start_row if it got smaller in INSERT mode',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position the cursor on 'w' in 'want'
- curwin('set_cursor', {2, 31})
- -- enter INSERT mode
- feed('a')
+ -- position the cursor on 'w' in 'want'
+ curwin('set_cursor', { 2, 31 })
+ -- enter INSERT mode
+ feed('a')
- local cursor = exec_lua([[
+ local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
'1',
'then 2',
@@ -1049,16 +1079,17 @@ describe('api/buf', function()
return vim.api.nvim_win_get_cursor(0)
]])
- eq({
- 'This should be 1',
- 'then 2',
- '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'))
- -- immediate call to nvim_win_get_cursor should have returned the same position
- eq({2, 6}, cursor)
- end)
+ eq({
+ 'This should be 1',
+ 'then 2',
+ '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'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({ 2, 6 }, cursor)
+ end
+ )
it('adjusts cursor line and column to keep it inside replacement range', function()
insert([[
@@ -1067,7 +1098,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'n' in 'finally'
- curwin('set_cursor', {3, 6})
+ curwin('set_cursor', { 3, 6 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1083,9 +1114,9 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({2, 12}, cursor)
+ eq({ 2, 12 }, cursor)
end)
it('adjusts cursor line and column if replacement is empty', function()
@@ -1095,7 +1126,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'r' in 'there'
- curwin('set_cursor', {2, 8})
+ curwin('set_cursor', { 2, 8 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {})
@@ -1104,9 +1135,9 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 15}, cursor)
+ eq({ 1, 15 }, cursor)
end)
it('adjusts cursor line and column if replacement is empty and start_col == 0', function()
@@ -1116,7 +1147,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'r' in 'there'
- curwin('set_cursor', {2, 8})
+ curwin('set_cursor', { 2, 8 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {})
@@ -1125,9 +1156,9 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 0}, cursor)
+ eq({ 1, 0 }, cursor)
end)
it('adjusts cursor column if replacement ends at cursor row, after cursor column', function()
@@ -1137,7 +1168,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'y' in 'finally'
- curwin('set_cursor', {3, 10})
+ curwin('set_cursor', { 3, 10 })
set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' })
eq({
@@ -1146,29 +1177,32 @@ 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 }, curwin('get_cursor'))
end)
- it('adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode', function()
- insert([[
+ it(
+ 'adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position the cursor on 'y' at 'finally'
- curwin('set_cursor', {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' })
+ -- position the cursor on 'y' at 'finally'
+ curwin('set_cursor', { 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' })
- eq({
- 'This should be 1',
- 'this 2',
- 'and then the last one',
- }, get_lines(0, -1, true))
- -- cursor should end up after 'n' in 'then'
- eq({3, 8}, curwin('get_cursor'))
- end)
+ eq({
+ 'This should be 1',
+ 'this 2',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up after 'n' in 'then'
+ eq({ 3, 8 }, curwin('get_cursor'))
+ end
+ )
it('adjusts cursor column if replacement is inside of a single line', function()
insert([[
@@ -1177,7 +1211,7 @@ describe('api/buf', function()
and finally the last one]])
-- position the cursor on 'y' in 'finally'
- curwin('set_cursor', {3, 10})
+ curwin('set_cursor', { 3, 10 })
set_text(2, 4, 2, 11, { 'then' })
eq({
@@ -1186,7 +1220,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 }, curwin('get_cursor'))
end)
it('does not move cursor column after end of a line', function()
@@ -1195,7 +1229,7 @@ describe('api/buf', function()
!!!]])
-- position cursor on the last '1'
- curwin('set_cursor', {2, 2})
+ curwin('set_cursor', { 2, 2 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {})
@@ -1204,16 +1238,16 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 32}, cursor)
+ eq({ 1, 32 }, cursor)
end)
it('does not move cursor column before start of a line', function()
insert('\n!!!')
-- position cursor on the last '1'
- curwin('set_cursor', {2, 2})
+ curwin('set_cursor', { 2, 2 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {})
@@ -1222,20 +1256,20 @@ describe('api/buf', function()
eq({ '' }, get_lines(0, -1, true))
-- cursor should end up on '!'
- eq({1, 0}, curwin('get_cursor'))
+ eq({ 1, 0 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 0}, cursor)
+ eq({ 1, 0 }, cursor)
end)
describe('with virtualedit', function()
- it('adjusts cursor line and column to keep it inside replacement range if cursor is not after eol', function()
+ it('adjusts cursor line/col to keep inside replacement range if not after eol', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position cursor on 't' in 'want'
- curwin('set_cursor', {2, 34})
+ curwin('set_cursor', { 2, 34 })
-- turn on virtualedit
command('set virtualedit=all')
@@ -1253,23 +1287,26 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({2, 12}, cursor)
+ eq({ 2, 12 }, cursor)
-- coladd should be 0
- eq(0, exec_lua([[
+ eq(
+ 0,
+ exec_lua([[
return vim.fn.winsaveview().coladd
- ]]))
+ ]])
+ )
end)
- it('does not change cursor screen column when cursor is after eol and row got shorter', function()
+ it('does not change cursor screen column when cursor >EOL and row got shorter', function()
insert([[
This should be first
then there is a line we do not want
and finally the last one]])
-- position cursor on 't' in 'want'
- curwin('set_cursor', {2, 34})
+ curwin('set_cursor', { 2, 34 })
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol
@@ -1290,31 +1327,36 @@ 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 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({2, 26}, cursor)
+ eq({ 2, 26 }, cursor)
-- coladd should be increased so that cursor stays in the same screen column
- eq(13, exec_lua([[
+ eq(
+ 13,
+ exec_lua([[
return vim.fn.winsaveview().coladd
- ]]))
+ ]])
+ )
end)
- it('does not change cursor screen column when cursor is after eol and row got longer', function()
- insert([[
+ it(
+ 'does not change cursor screen column when cursor is after eol and row got longer',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position cursor on 't' in 'first'
- curwin('set_cursor', {1, 19})
- -- turn on virtualedit
- command('set virtualedit=all')
- -- move cursor after eol
- exec_lua([[
+ -- position cursor on 't' in 'first'
+ curwin('set_cursor', { 1, 19 })
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol
+ exec_lua([[
vim.fn.winrestview({ coladd = 21 })
]])
- local cursor = exec_lua([[
+ local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
'the line we do not want',
'but hopefully',
@@ -1322,36 +1364,42 @@ describe('api/buf', function()
return vim.api.nvim_win_get_cursor(0)
]])
- eq({
- 'This should be the line we do not want',
- 'but hopefully the last one',
- }, get_lines(0, -1, true))
- -- cursor should end up at eol of a new row
- eq({1, 38}, curwin('get_cursor'))
- -- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 38}, cursor)
- -- coladd should be increased so that cursor stays in the same screen column
- eq(2, exec_lua([[
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up at eol of a new row
+ eq({ 1, 38 }, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({ 1, 38 }, cursor)
+ -- coladd should be increased so that cursor stays in the same screen column
+ eq(
+ 2,
+ exec_lua([[
return vim.fn.winsaveview().coladd
- ]]))
- end)
-
- it('does not change cursor screen column when cursor is after eol and row extended past cursor column', function()
- insert([[
+ ]])
+ )
+ end
+ )
+
+ it(
+ 'does not change cursor screen column when cursor is after eol and row extended past cursor column',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position cursor on 't' in 'first'
- curwin('set_cursor', {1, 19})
- -- turn on virtualedit
- command('set virtualedit=all')
- -- move cursor after eol just a bit
- exec_lua([[
+ -- position cursor on 't' in 'first'
+ curwin('set_cursor', { 1, 19 })
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol just a bit
+ exec_lua([[
vim.fn.winrestview({ coladd = 3 })
]])
- local cursor = exec_lua([[
+ local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
'the line we do not want',
'but hopefully',
@@ -1359,37 +1407,43 @@ describe('api/buf', function()
return vim.api.nvim_win_get_cursor(0)
]])
- eq({
- 'This should be the line we do not want',
- 'but hopefully the last one',
- }, get_lines(0, -1, true))
- -- cursor should stay at the same screen column
- eq({1, 22}, curwin('get_cursor'))
- -- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 22}, cursor)
- -- coladd should become 0
- eq(0, exec_lua([[
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay at the same screen column
+ eq({ 1, 22 }, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({ 1, 22 }, cursor)
+ -- coladd should become 0
+ eq(
+ 0,
+ exec_lua([[
return vim.fn.winsaveview().coladd
- ]]))
- end)
-
- it('does not change cursor screen column when cursor is after eol and row range decreased', function()
- insert([[
+ ]])
+ )
+ end
+ )
+
+ it(
+ 'does not change cursor screen column when cursor is after eol and row range decreased',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and one more
and finally the last one]])
- -- position cursor on 'e' in 'more'
- curwin('set_cursor', {3, 11})
- -- turn on virtualedit
- command('set virtualedit=all')
- -- move cursor after eol
- exec_lua([[
+ -- position cursor on 'e' in 'more'
+ curwin('set_cursor', { 3, 11 })
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol
+ exec_lua([[
vim.fn.winrestview({ coladd = 28 })
]])
- local cursor = exec_lua([[
+ local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 3, 11, {
'the line we do not want',
'but hopefully',
@@ -1397,19 +1451,23 @@ describe('api/buf', function()
return vim.api.nvim_win_get_cursor(0)
]])
- eq({
- 'This should be the line we do not want',
- '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'))
- -- 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 column
- eq(13, exec_lua([[
+ eq({
+ 'This should be the line we do not want',
+ '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'))
+ -- 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 column
+ eq(
+ 13,
+ exec_lua([[
return vim.fn.winsaveview().coladd
- ]]))
- end)
+ ]])
+ )
+ end
+ )
end)
end)
@@ -1421,80 +1479,86 @@ describe('api/buf', function()
line]])
-- position the cursor on 'i'
- curwin('set_cursor', {3, 2})
+ curwin('set_cursor', { 3, 2 })
set_text(1, 6, 2, 0, {})
- eq({'first line', 'second line'}, get_lines(0, -1, true))
+ eq({ 'first line', 'second line' }, get_lines(0, -1, true))
-- cursor should stay on 'i'
- eq({2, 8}, curwin('get_cursor'))
+ eq({ 2, 8 }, curwin('get_cursor'))
-- add a newline back
- set_text(1, 6, 1, 6, {'', ''})
- eq({'first line', 'second', ' line'}, get_lines(0, -1, true))
+ set_text(1, 6, 1, 6, { '', '' })
+ eq({ 'first line', 'second', ' line' }, get_lines(0, -1, true))
-- cursor should return back to the original position
- eq({3, 2}, curwin('get_cursor'))
+ eq({ 3, 2 }, curwin('get_cursor'))
end)
- it('adjusts cursor column if the range is not bound to either start or end of a line', function()
- insert([[
+ it(
+ 'adjusts cursor column if the range is not bound to either start or end of a line',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position the cursor on 'h' in 'the'
- curwin('set_cursor', {3, 13})
- set_text(0, 14, 2, 11, {})
- eq({'This should be the last one'}, get_lines(0, -1, true))
- -- cursor should stay on 'h'
- eq({1, 16}, curwin('get_cursor'))
- -- add deleted lines back
- set_text(0, 14, 0, 14, {
- ' first',
- 'then there is a line we do not want',
- 'and finally',
- })
- eq({
- 'This should be first',
- 'then there is a line we do not want',
- 'and finally the last one',
- }, get_lines(0, -1, true))
- -- cursor should return back to the original position
- eq({3, 13}, curwin('get_cursor'))
- end)
-
- it('adjusts cursor column if replacing lines in range, not just deleting and adding', function()
- insert([[
+ -- position the cursor on 'h' in 'the'
+ curwin('set_cursor', { 3, 13 })
+ set_text(0, 14, 2, 11, {})
+ eq({ 'This should be the last one' }, get_lines(0, -1, true))
+ -- cursor should stay on 'h'
+ eq({ 1, 16 }, curwin('get_cursor'))
+ -- add deleted lines back
+ set_text(0, 14, 0, 14, {
+ ' first',
+ 'then there is a line we do not want',
+ 'and finally',
+ })
+ eq({
+ 'This should be first',
+ 'then there is a line we do not want',
+ 'and finally the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should return back to the original position
+ eq({ 3, 13 }, curwin('get_cursor'))
+ end
+ )
+
+ it(
+ 'adjusts cursor column if replacing lines in range, not just deleting and adding',
+ function()
+ insert([[
This should be first
then there is a line we do not want
and finally the last one]])
- -- position the cursor on 's' in 'last'
- curwin('set_cursor', {3, 18})
- set_text(0, 15, 2, 11, {
- 'the line we do not want',
- 'but hopefully',
- })
+ -- position the cursor on 's' in 'last'
+ curwin('set_cursor', { 3, 18 })
+ set_text(0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
- eq({
- 'This should be the line we do not want',
- 'but hopefully the last one',
- }, get_lines(0, -1, true))
- -- cursor should stay on 's'
- eq({2, 20}, curwin('get_cursor'))
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay on 's'
+ eq({ 2, 20 }, curwin('get_cursor'))
- set_text(0, 15, 1, 13, {
- 'first',
- 'then there is a line we do not want',
- 'and finally',
- })
+ set_text(0, 15, 1, 13, {
+ 'first',
+ 'then there is a line we do not want',
+ 'and finally',
+ })
- eq({
- 'This should be first',
- 'then there is a line we do not want',
- 'and finally the last one',
- }, get_lines(0, -1, true))
- -- cursor should return back to the original position
- eq({3, 18}, curwin('get_cursor'))
- end)
+ eq({
+ 'This should be first',
+ 'then there is a line we do not want',
+ 'and finally the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should return back to the original position
+ eq({ 3, 18 }, curwin('get_cursor'))
+ end
+ )
it('does not move cursor column after end of a line', function()
insert([[
@@ -1502,7 +1566,7 @@ describe('api/buf', function()
]])
-- position cursor at the empty line
- curwin('set_cursor', {2, 0})
+ curwin('set_cursor', { 2, 0 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 33, 1, 0, {'!'})
@@ -1511,9 +1575,9 @@ describe('api/buf', function()
eq({ 'This should be the only line here!' }, get_lines(0, -1, true))
-- cursor should end up on '!'
- eq({1, 33}, curwin('get_cursor'))
+ eq({ 1, 33 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 33}, cursor)
+ eq({ 1, 33 }, cursor)
end)
it('does not move cursor column before start of a line', function()
@@ -1522,7 +1586,7 @@ describe('api/buf', function()
eq({ '', '' }, get_lines(0, -1, true))
-- position cursor on the last '1'
- curwin('set_cursor', {2, 2})
+ curwin('set_cursor', { 2, 2 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 0, 1, 0, {''})
@@ -1531,19 +1595,19 @@ describe('api/buf', function()
eq({ '' }, get_lines(0, -1, true))
-- cursor should end up on '!'
- eq({1, 0}, curwin('get_cursor'))
+ eq({ 1, 0 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position
- eq({1, 0}, cursor)
+ eq({ 1, 0 }, cursor)
end)
end)
it('can handle NULs', function()
- set_text(0, 0, 0, 0, {'ab\0cd'})
+ set_text(0, 0, 0, 0, { 'ab\0cd' })
eq('ab\0cd', curbuf_depr('get_line', 0))
end)
it('adjusts extmarks', function()
- local ns = request('nvim_create_namespace', "my-fancy-plugin")
+ local ns = request('nvim_create_namespace', 'my-fancy-plugin')
insert([[
foo bar
baz
@@ -1551,41 +1615,41 @@ describe('api/buf', function()
local id1 = curbufmeths.set_extmark(ns, 0, 1, {})
local id2 = curbufmeths.set_extmark(ns, 0, 7, {})
local id3 = curbufmeths.set_extmark(ns, 1, 1, {})
- set_text(0, 4, 0, 7, {"q"})
+ set_text(0, 4, 0, 7, { 'q' })
- eq({'foo q', 'baz'}, get_lines(0, 2, true))
+ eq({ 'foo q', 'baz' }, get_lines(0, 2, true))
-- mark before replacement point is unaffected
- eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {}))
-- mark gets shifted back because the replacement was shorter
- eq({0, 5}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({ 0, 5 }, curbufmeths.get_extmark_by_id(ns, id2, {}))
-- mark on the next line is unaffected
- eq({1, 1}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ eq({ 1, 1 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
-- replacing the text spanning two lines will adjust the mark on the next line
- set_text(0, 3, 1, 3, {"qux"})
- eq({'fooqux', ''}, get_lines(0, 2, true))
- eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ set_text(0, 3, 1, 3, { 'qux' })
+ eq({ 'fooqux', '' }, get_lines(0, 2, true))
+ eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
-- but mark before replacement point is still unaffected
- eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {}))
-- and the mark in the middle was shifted to the end of the insertion
- eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {}))
-- marks should be put back into the same place after undoing
- set_text(0, 0, 0, 2, {''})
+ set_text(0, 0, 0, 2, { '' })
feed('u')
- eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
- eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
- eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
-- marks should be shifted over by the correct number of bytes for multibyte
-- chars
- set_text(0, 0, 0, 0, {'Ø'})
- eq({0, 3}, curbufmeths.get_extmark_by_id(ns, id1, {}))
- eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {}))
- eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ set_text(0, 0, 0, 0, { 'Ø' })
+ eq({ 0, 3 }, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
end)
- it("correctly marks changed region for redraw #13890", function()
+ it('correctly marks changed region for redraw #13890', function()
local screen = Screen.new(20, 5)
screen:attach()
@@ -1594,7 +1658,7 @@ describe('api/buf', function()
BBB
]])
- curbufmeths.set_text(0, 0, 1, 3, {'XXX', 'YYY'})
+ curbufmeths.set_text(0, 0, 1, 3, { 'XXX', 'YYY' })
screen:expect([[
XXX |
@@ -1627,14 +1691,14 @@ describe('api/buf', function()
end)
it('no heap-use-after-free when called consecutively #19643', function()
- set_text(0, 0, 0, 0, {'one', '', '', 'two'})
- eq({'one', '', '', 'two'}, get_lines(0, 4, true))
- meths.win_set_cursor(0, {1, 0})
+ set_text(0, 0, 0, 0, { 'one', '', '', 'two' })
+ eq({ 'one', '', '', 'two' }, get_lines(0, 4, true))
+ meths.win_set_cursor(0, { 1, 0 })
exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''})
vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''})
]])
- eq({'one', 'two'}, get_lines(0, 2, true))
+ eq({ 'one', 'two' }, get_lines(0, 2, true))
end)
describe('handles topline', function()
@@ -1642,12 +1706,12 @@ describe('api/buf', function()
before_each(function()
screen = Screen.new(20, 12)
screen:set_default_attr_ids {
- [1] = {bold = true, foreground = Screen.colors.Blue1};
- [2] = {reverse = true, bold = true};
- [3] = {reverse = true};
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { reverse = true, bold = true },
+ [3] = { reverse = true },
}
screen:attach()
- meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
+ meths.buf_set_lines(0, 0, -1, 1, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' })
meths.set_option_value('modified', false, {})
end)
@@ -1656,9 +1720,10 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('new | wincmd w')
- meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(win, { 8, 0 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -1668,10 +1733,12 @@ describe('api/buf', function()
^zzz |
{2:[No Name] }|
|
- ]]}
- meths.buf_set_text(buf, 0,3, 1,0, {"X"})
+ ]],
+ }
+ meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
|
{1:~ }|*4
{3:[No Name] }|
@@ -1681,7 +1748,8 @@ describe('api/buf', function()
^zzz |
{2:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
it('of non-current window', function()
@@ -1689,9 +1757,10 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('new')
- meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(win, { 8, 0 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -1701,10 +1770,12 @@ describe('api/buf', function()
zzz |
{3:[No Name] }|
|
- ]]}
+ ]],
+ }
- meths.buf_set_text(buf, 0,3, 1,0, {"X"})
- screen:expect{grid=[[
+ meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' })
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
@@ -1714,7 +1785,8 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
it('of split windows with same buffer', function()
@@ -1722,10 +1794,11 @@ describe('api/buf', function()
local buf = meths.get_current_buf()
command('split')
- meths.win_set_cursor(win, {8,0})
- meths.win_set_cursor(0, {1,1})
+ meths.win_set_cursor(win, { 8, 0 })
+ meths.win_set_cursor(0, { 1, 1 })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
a^aa |
bbb |
ccc |
@@ -1738,10 +1811,12 @@ describe('api/buf', function()
zzz |
{3:[No Name] }|
|
- ]]}
- meths.buf_set_text(buf, 0,3, 1,0, {"X"})
+ ]],
+ }
+ meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
a^aaXbbb |
ccc |
ddd |
@@ -1754,7 +1829,8 @@ describe('api/buf', function()
zzz |
{3:[No Name] [+] }|
|
- ]]}
+ ]],
+ }
end)
end)
end)
@@ -1769,14 +1845,14 @@ describe('api/buf', function()
end)
it('works', function()
- eq({'hello'}, get_text(0, 0, 0, 5, {}))
- eq({'hello foo!'}, get_text(0, 0, 0, 42, {}))
- eq({'foo!'}, get_text(0, 6, 0, 10, {}))
- eq({'foo!', 'tex'}, get_text(0, 6, 1, 3, {}))
- eq({'foo!', 'tex'}, get_text(-3, 6, -2, 3, {}))
- eq({''}, get_text(0, 18, 0, 20, {}))
- eq({'ext'}, get_text(-2, 1, -2, 4, {}))
- eq({'hello foo!', 'text', 'm'}, get_text(0, 0, 2, 1, {}))
+ eq({ 'hello' }, get_text(0, 0, 0, 5, {}))
+ eq({ 'hello foo!' }, get_text(0, 0, 0, 42, {}))
+ eq({ 'foo!' }, get_text(0, 6, 0, 10, {}))
+ eq({ 'foo!', 'tex' }, get_text(0, 6, 1, 3, {}))
+ eq({ 'foo!', 'tex' }, get_text(-3, 6, -2, 3, {}))
+ eq({ '' }, get_text(0, 18, 0, 20, {}))
+ eq({ 'ext' }, get_text(-2, 1, -2, 4, {}))
+ eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 2, 1, {}))
end)
it('errors on out-of-range', function()
@@ -1797,7 +1873,7 @@ describe('api/buf', function()
describe('nvim_buf_get_offset', function()
local get_offset = curbufmeths.get_offset
it('works', function()
- curbufmeths.set_lines(0,-1,true,{'Some\r','exa\000mple', '', 'buf\rfer', 'text'})
+ curbufmeths.set_lines(0, -1, true, { 'Some\r', 'exa\000mple', '', 'buf\rfer', 'text' })
eq(5, curbufmeths.line_count())
eq(0, get_offset(0))
eq(6, get_offset(1))
@@ -1823,12 +1899,12 @@ describe('api/buf', function()
meths.set_option_value('eol', true, {})
eq(29, get_offset(5))
- command("set hidden")
- command("enew")
- eq(6, bufmeths.get_offset(1,1))
- command("bunload! 1")
- eq(-1, bufmeths.get_offset(1,1))
- eq(-1, bufmeths.get_offset(1,0))
+ command('set hidden')
+ command('enew')
+ eq(6, bufmeths.get_offset(1, 1))
+ command('bunload! 1')
+ eq(-1, bufmeths.get_offset(1, 1))
+ eq(-1, bufmeths.get_offset(1, 0))
end)
it('works in empty buffer', function()
@@ -1846,43 +1922,41 @@ describe('api/buf', function()
describe('nvim_buf_get_var, nvim_buf_set_var, nvim_buf_del_var', function()
it('works', function()
- curbuf('set_var', 'lua', {1, 2, {['3'] = 1}})
- eq({1, 2, {['3'] = 1}}, curbuf('get_var', 'lua'))
- eq({1, 2, {['3'] = 1}}, nvim('eval', 'b:lua'))
+ curbuf('set_var', 'lua', { 1, 2, { ['3'] = 1 } })
+ eq({ 1, 2, { ['3'] = 1 } }, curbuf('get_var', 'lua'))
+ eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'b:lua'))
eq(1, funcs.exists('b:lua'))
curbufmeths.del_var('lua')
eq(0, funcs.exists('b:lua'))
- eq( 'Key not found: lua', pcall_err(curbufmeths.del_var, 'lua'))
+ eq('Key not found: lua', pcall_err(curbufmeths.del_var, 'lua'))
curbufmeths.set_var('lua', 1)
command('lockvar b:lua')
eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua'))
eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1))
- eq('Key is read-only: changedtick',
- pcall_err(curbufmeths.del_var, 'changedtick'))
- eq('Key is read-only: changedtick',
- pcall_err(curbufmeths.set_var, 'changedtick', 1))
+ eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick'))
+ eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', 1))
end)
end)
describe('nvim_buf_get_changedtick', function()
it('works', function()
eq(2, curbufmeths.get_changedtick())
- curbufmeths.set_lines(0, 1, false, {'abc\0', '\0def', 'ghi'})
+ curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' })
eq(3, curbufmeths.get_changedtick())
eq(3, curbufmeths.get_var('changedtick'))
end)
it('buffer_set_var returns the old value', function()
- local val1 = {1, 2, {['3'] = 1}}
- local val2 = {4, 7}
+ local val1 = { 1, 2, { ['3'] = 1 } }
+ local val2 = { 4, 7 }
eq(NIL, request('buffer_set_var', 0, 'lua', val1))
eq(val1, request('buffer_set_var', 0, 'lua', val2))
end)
it('buffer_del_var returns the old value', function()
- local val1 = {1, 2, {['3'] = 1}}
- local val2 = {4, 7}
- eq(NIL, request('buffer_set_var', 0, 'lua', val1))
+ local val1 = { 1, 2, { ['3'] = 1 } }
+ local val2 = { 4, 7 }
+ eq(NIL, request('buffer_set_var', 0, 'lua', val1))
eq(val1, request('buffer_set_var', 0, 'lua', val2))
eq(val2, request('buffer_del_var', 0, 'lua'))
end)
@@ -1894,17 +1968,17 @@ describe('api/buf', function()
nvim('set_option_value', 'shiftwidth', 4, {})
eq(4, nvim('get_option_value', 'shiftwidth', {}))
-- global-local option
- nvim('set_option_value', 'define', 'test', {buf = 0})
- eq('test', nvim('get_option_value', 'define', {buf = 0}))
+ nvim('set_option_value', 'define', 'test', { buf = 0 })
+ eq('test', nvim('get_option_value', 'define', { buf = 0 }))
-- Doesn't change the global value
- eq("", nvim('get_option_value', 'define', {scope='global'}))
+ eq('', nvim('get_option_value', 'define', { scope = 'global' }))
end)
it('returns values for unset local options', function()
-- 'undolevels' is only set to its "unset" value when a new buffer is
-- created
command('enew')
- eq(-123456, nvim('get_option_value', 'undolevels', {buf=0}))
+ eq(-123456, nvim('get_option_value', 'undolevels', { buf = 0 }))
end)
end)
@@ -1929,17 +2003,17 @@ describe('api/buf', function()
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'})
+ 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..')')
+ 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)
+ command('bunload! ' .. bufnr)
-- confirm the buffer is unloaded
- infolist = nvim('eval', 'getbufinfo('..bufnr..')')
+ 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))
@@ -1978,25 +2052,25 @@ describe('api/buf', function()
describe('nvim_buf_get_mark', function()
it('works', function()
- curbuf('set_lines', -1, -1, true, {'a', 'bit of', 'text'})
- curwin('set_cursor', {3, 4})
+ curbuf('set_lines', -1, -1, true, { 'a', 'bit of', 'text' })
+ curwin('set_cursor', { 3, 4 })
nvim('command', 'mark v')
- eq({3, 0}, curbuf('get_mark', 'v'))
+ eq({ 3, 0 }, curbuf('get_mark', 'v'))
end)
end)
describe('nvim_buf_set_mark', function()
it('works with buffer local marks', function()
- curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
+ curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' })
eq(true, curbufmeths.set_mark('z', 1, 1, {}))
- eq({1, 1}, curbufmeths.get_mark('z'))
- eq({0, 1, 2, 0}, funcs.getpos("'z"))
+ eq({ 1, 1 }, curbufmeths.get_mark('z'))
+ eq({ 0, 1, 2, 0 }, funcs.getpos("'z"))
end)
it('works with file/uppercase marks', function()
- curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
+ curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' })
eq(true, curbufmeths.set_mark('Z', 3, 2, {}))
- eq({3, 2}, curbufmeths.get_mark('Z'))
- eq({curbuf().id, 3, 3, 0}, funcs.getpos("'Z"))
+ eq({ 3, 2 }, curbufmeths.get_mark('Z'))
+ eq({ curbuf().id, 3, 3, 0 }, funcs.getpos("'Z"))
end)
it('fails when invalid marks names are used', function()
eq(false, pcall(curbufmeths.set_mark, '!', 1, 0, {}))
@@ -2009,29 +2083,29 @@ describe('api/buf', function()
describe('nvim_buf_del_mark', function()
it('works with buffer local marks', function()
- curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
+ curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' })
curbufmeths.set_mark('z', 3, 1, {})
eq(true, curbufmeths.del_mark('z'))
- eq({0, 0}, curbufmeths.get_mark('z'))
+ eq({ 0, 0 }, curbufmeths.get_mark('z'))
end)
it('works with file/uppercase marks', function()
- curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
+ curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' })
curbufmeths.set_mark('Z', 3, 3, {})
eq(true, curbufmeths.del_mark('Z'))
- eq({0, 0}, curbufmeths.get_mark('Z'))
+ eq({ 0, 0 }, curbufmeths.get_mark('Z'))
end)
it('returns false in marks not set in this buffer', function()
- local abuf = meths.create_buf(false,true)
- bufmeths.set_lines(abuf, -1, -1, true, {'a', 'bit of', 'text'})
+ local abuf = meths.create_buf(false, true)
+ bufmeths.set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' })
bufmeths.set_mark(abuf, 'A', 2, 2, {})
eq(false, curbufmeths.del_mark('A'))
- eq({2, 2}, bufmeths.get_mark(abuf, 'A'))
+ eq({ 2, 2 }, bufmeths.get_mark(abuf, 'A'))
end)
it('returns false if mark was not deleted', function()
- curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
+ curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' })
curbufmeths.set_mark('z', 3, 1, {})
eq(true, curbufmeths.del_mark('z'))
- eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted
+ eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted
end)
it('fails when invalid marks names are used', function()
eq(false, pcall(curbufmeths.del_mark, '!'))