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...
This commit is contained in:
Justin M. Keyes 2023-12-07 12:19:35 +01:00
parent b3eda5e73f
commit 59d117ec99
6 changed files with 2276 additions and 1808 deletions

View File

@ -1,9 +1,12 @@
/build /build/
/.deps/
/runtime/lua/coxpcall.lua /runtime/lua/coxpcall.lua
/runtime/lua/vim/_meta /runtime/lua/vim/_meta
/runtime/lua/vim/re.lua /runtime/lua/vim/re.lua
/test/functional test/functional/ui/decorations_spec.lua
test/functional/ui/float_spec.lua
test/functional/ui/multigrid_spec.lua
/test/functional/fixtures/lua/syntax_error.lua /test/functional/fixtures/lua/syntax_error.lua
/test/functional/legacy/030_fileformats_spec.lua /test/functional/legacy/030_fileformats_spec.lua
/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua /test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua

View File

@ -227,7 +227,7 @@ endif()
find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED}) find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED})
find_program(STYLUA_PRG stylua ${LINT_REQUIRED}) find_program(STYLUA_PRG stylua ${LINT_REQUIRED})
set(STYLUA_DIRS runtime scripts src test/unit) set(STYLUA_DIRS runtime scripts src test)
add_glob_target( add_glob_target(
TARGET lintlua-luacheck TARGET lintlua-luacheck
@ -235,7 +235,7 @@ add_glob_target(
FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q
GLOB_DIRS runtime scripts src test GLOB_DIRS runtime scripts src test
GLOB_PAT *.lua GLOB_PAT *.lua
TOUCH_STRATEGY SINGLE) TOUCH_STRATEGY PER_DIR)
add_dependencies(lintlua-luacheck lua-dev-deps) add_dependencies(lintlua-luacheck lua-dev-deps)
add_glob_target( add_glob_target(
@ -244,7 +244,7 @@ add_glob_target(
FLAGS --color=always --check --respect-ignores FLAGS --color=always --check --respect-ignores
GLOB_DIRS ${STYLUA_DIRS} GLOB_DIRS ${STYLUA_DIRS}
GLOB_PAT *.lua GLOB_PAT *.lua
TOUCH_STRATEGY SINGLE) TOUCH_STRATEGY PER_DIR)
add_custom_target(lintlua) add_custom_target(lintlua)
add_dependencies(lintlua lintlua-luacheck lintlua-stylua) add_dependencies(lintlua lintlua-luacheck lintlua-stylua)
@ -255,7 +255,7 @@ add_glob_target(
FLAGS -x -a FLAGS -x -a
GLOB_DIRS scripts GLOB_DIRS scripts
GLOB_PAT *.sh GLOB_PAT *.sh
TOUCH_STRATEGY SINGLE) TOUCH_STRATEGY PER_DIR)
add_custom_target(lintcommit add_custom_target(lintcommit
COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main) COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
@ -270,7 +270,8 @@ add_glob_target(
COMMAND ${STYLUA_PRG} COMMAND ${STYLUA_PRG}
FLAGS --respect-ignores FLAGS --respect-ignores
GLOB_DIRS ${STYLUA_DIRS} GLOB_DIRS ${STYLUA_DIRS}
GLOB_PAT *.lua) GLOB_PAT *.lua
TOUCH_STRATEGY PER_DIR)
add_custom_target(format) add_custom_target(format)
add_dependencies(format formatc formatlua) add_dependencies(format formatc formatlua)

View File

@ -26,7 +26,6 @@ describe('api/buf', function()
return request('buffer_' .. method, 0, ...) return request('buffer_' .. method, 0, ...)
end end
describe('nvim_buf_set_lines, nvim_buf_line_count', function() describe('nvim_buf_set_lines, nvim_buf_line_count', function()
it('deprecated forms', function() it('deprecated forms', function()
eq(1, curbuf_depr('line_count')) eq(1, curbuf_depr('line_count'))
@ -52,54 +51,54 @@ describe('api/buf', function()
it('cursor position is maintained after lines are inserted #9961', function() it('cursor position is maintained after lines are inserted #9961', function()
-- replace the buffer contents with these three lines. -- 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}. -- 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. -- 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. -- 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. -- 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. -- 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. -- 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. -- cursor position is unchanged.
eq({ 4, 2 }, curwin('get_cursor')) eq({ 4, 2 }, curwin('get_cursor'))
-- overwrite current cursor line. -- 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. -- 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. -- cursor position is unchanged.
eq({ 4, 2 }, curwin('get_cursor')) eq({ 4, 2 }, curwin('get_cursor'))
-- delete current cursor line. -- delete current cursor line.
request('nvim_buf_set_lines', 0, 3, 5, 1, {}) request('nvim_buf_set_lines', 0, 3, 5, 1, {})
-- check the current set of lines in the buffer. -- 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. -- cursor position is unchanged.
eq({ 4, 2 }, curwin('get_cursor')) eq({ 4, 2 }, curwin('get_cursor'))
end) end)
it('cursor position is maintained in non-current window', function() it('cursor position is maintained in non-current window', function()
meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"}) meths.buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' })
meths.win_set_cursor(0, { 3, 2 }) meths.win_set_cursor(0, { 3, 2 })
local win = meths.get_current_win() local win = meths.get_current_win()
local buf = meths.get_current_buf() local buf = meths.get_current_buf()
command('new') command('new')
meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"}) 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({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true))
eq({ 4, 2 }, meths.win_get_cursor(win)) eq({ 4, 2 }, meths.win_get_cursor(win))
end) end)
it('cursor position is maintained in TWO non-current windows', function() it('cursor position is maintained in TWO non-current windows', function()
meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"}) meths.buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' })
meths.win_set_cursor(0, { 3, 2 }) meths.win_set_cursor(0, { 3, 2 })
local win = meths.get_current_win() local win = meths.get_current_win()
local buf = meths.get_current_buf() local buf = meths.get_current_buf()
@ -109,10 +108,10 @@ describe('api/buf', function()
local win2 = meths.get_current_win() local win2 = meths.get_current_win()
-- set current window to third one with another buffer -- set current window to third one with another buffer
command("new") command('new')
meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"}) 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({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true))
eq({ 4, 2 }, meths.win_get_cursor(win)) eq({ 4, 2 }, meths.win_get_cursor(win))
eq({ 5, 2 }, meths.win_get_cursor(win2)) eq({ 5, 2 }, meths.win_get_cursor(win2))
end) end)
@ -121,7 +120,7 @@ describe('api/buf', function()
-- we'll need to know our bufnr for when it gets unloaded -- we'll need to know our bufnr for when it gets unloaded
local bufnr = curbuf('get_number') local bufnr = curbuf('get_number')
-- replace the buffer contents with these three lines -- 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 -- check the line count is correct
eq(4, request('nvim_buf_line_count', bufnr)) eq(4, request('nvim_buf_line_count', bufnr))
-- force unload the buffer (this will discard changes) -- force unload the buffer (this will discard changes)
@ -135,9 +134,9 @@ describe('api/buf', function()
-- we'll need to know our bufnr for when it gets unloaded -- we'll need to know our bufnr for when it gets unloaded
local bufnr = curbuf('get_number') local bufnr = curbuf('get_number')
-- replace the buffer contents with these three lines -- 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 -- 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) -- force unload the buffer (this will discard changes)
command('new') command('new')
command('bunload! ' .. bufnr) command('bunload! ' .. bufnr)
@ -152,12 +151,12 @@ describe('api/buf', function()
before_each(function() before_each(function()
screen = Screen.new(20, 12) screen = Screen.new(20, 12)
screen:set_default_attr_ids { screen:set_default_attr_ids {
[1] = {bold = true, foreground = Screen.colors.Blue1}; [1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = {reverse = true, bold = true}; [2] = { reverse = true, bold = true },
[3] = {reverse = true}; [3] = { reverse = true },
} }
screen:attach() 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, {}) meths.set_option_value('modified', false, {})
end) end)
@ -168,7 +167,8 @@ describe('api/buf', function()
command('new | wincmd w') 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 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -178,10 +178,12 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] }| {2:[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 = [[
| |
{1:~ }|*4 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -191,11 +193,13 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]]} ]],
}
-- replacing topline keeps it the topline -- replacing topline keeps it the topline
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect{grid=[[ screen:expect {
grid = [[
| |
{1:~ }|*4 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -205,11 +209,13 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]]} ]],
}
-- inserting just before topline does not scroll up if cursor would be moved -- inserting just before topline does not scroll up if cursor would be moved
meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect{grid=[[ screen:expect {
grid = [[
| |
{1:~ }|*4 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -219,10 +225,13 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]], unchanged=true} ]],
unchanged = true,
}
meths.win_set_cursor(0, { 7, 0 }) meths.win_set_cursor(0, { 7, 0 })
screen:expect{grid=[[ screen:expect {
grid = [[
| |
{1:~ }|*4 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -232,10 +241,12 @@ describe('api/buf', function()
zzz | zzz |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]]} ]],
}
meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"}) meths.buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' })
screen:expect{grid=[[ screen:expect {
grid = [[
| |
{1:~ }|*4 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -245,7 +256,8 @@ describe('api/buf', function()
^yyy | ^yyy |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]]} ]],
}
end) end)
it('of non-current window', function() it('of non-current window', function()
@ -255,7 +267,8 @@ describe('api/buf', function()
command('new') command('new')
meths.win_set_cursor(win, { 8, 0 }) meths.win_set_cursor(win, { 8, 0 })
screen:expect{grid=[[ screen:expect {
grid = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -265,10 +278,12 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] }| {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 = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -278,11 +293,13 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
-- replacing topline keeps it the topline -- replacing topline keeps it the topline
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect{grid=[[ screen:expect {
grid = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -292,11 +309,13 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
-- inserting just before topline scrolls up -- inserting just before topline scrolls up
meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect{grid=[[ screen:expect {
grid = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -306,7 +325,8 @@ describe('api/buf', function()
yyy | yyy |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
end) end)
it('of split windows with same buffer', function() it('of split windows with same buffer', function()
@ -317,7 +337,8 @@ describe('api/buf', function()
meths.win_set_cursor(win, { 8, 0 }) meths.win_set_cursor(win, { 8, 0 })
meths.win_set_cursor(0, { 1, 0 }) meths.win_set_cursor(0, { 1, 0 })
screen:expect{grid=[[ screen:expect {
grid = [[
^aaa | ^aaa |
bbb | bbb |
ccc | ccc |
@ -330,10 +351,12 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] }| {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 | ^aaabbb |
ccc | ccc |
ddd | ddd |
@ -346,11 +369,13 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
-- replacing topline keeps it the topline -- replacing topline keeps it the topline
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' })
screen:expect{grid=[[ screen:expect {
grid = [[
^aaabbb | ^aaabbb |
ccc | ccc |
ddd | ddd |
@ -363,11 +388,13 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
-- inserting just before topline scrolls up -- inserting just before topline scrolls up
meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) meths.buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect{grid=[[ screen:expect {
grid = [[
^aaabbb | ^aaabbb |
ccc | ccc |
ddd | ddd |
@ -380,19 +407,20 @@ describe('api/buf', function()
yyy | yyy |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
end) end)
end) end)
it('handles clearing out non-current buffer #24911', function() it('handles clearing out non-current buffer #24911', function()
local buf = meths.get_current_buf() local buf = meths.get_current_buf()
meths.buf_set_lines(buf, 0, -1, true, {"aaa", "bbb", "ccc"}) meths.buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' })
command("new") 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, {}) meths.buf_set_lines(buf, 0, -1, true, {})
eq({"xxx", "yyy", "zzz"}, meths.buf_get_lines(0, 0, -1, true)) eq({ 'xxx', 'yyy', 'zzz' }, meths.buf_get_lines(0, 0, -1, true))
eq({ '' }, meths.buf_get_lines(buf, 0, -1, true)) eq({ '' }, meths.buf_get_lines(buf, 0, -1, true))
end) end)
end) end)
@ -467,8 +495,7 @@ describe('api/buf', function()
curbuf_depr('set_line_slice', 1, 2, true, false, { 'a', 'b', 'c' }) 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)) 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' }) curbuf_depr('set_line_slice', -1, -1, true, true, { 'a', 'b', 'c' })
eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'}, eq({ 'a', 'a', 'b', 'c', 'a', 'b', 'c' }, curbuf_depr('get_line_slice', 0, -1, true, true))
curbuf_depr('get_line_slice', 0, -1, true, true))
curbuf_depr('set_line_slice', 0, -3, true, false, {}) 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, {}) curbuf_depr('set_line_slice', 0, -1, true, true, {})
@ -483,14 +510,18 @@ describe('api/buf', function()
it('fails correctly when input is not valid', function() it('fails correctly when input is not valid', function()
eq(1, api.curbufmeths.get_number()) eq(1, api.curbufmeths.get_number())
eq([['replacement string' item contains newlines]], eq(
pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'})) [['replacement string' item contains newlines]],
pcall_err(bufmeths.set_lines, 1, 1, 2, false, { 'b\na' })
)
end) end)
it("fails if 'nomodifiable'", function() it("fails if 'nomodifiable'", function()
command('set nomodifiable') command('set nomodifiable')
eq([[Buffer is not 'modifiable']], eq(
pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, {'a','b'})) [[Buffer is not 'modifiable']],
pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, { 'a', 'b' })
)
end) end)
it('has correct line_count when inserting and deleting', function() it('has correct line_count when inserting and deleting', function()
@ -571,8 +602,7 @@ describe('api/buf', function()
set_lines(1, 2, mode, { 'a', 'b', 'c' }) set_lines(1, 2, mode, { 'a', 'b', 'c' })
eq({ 'a', 'a', 'b', 'c', 'c' }, get_lines(0, -1, mode)) eq({ 'a', 'a', 'b', 'c', 'c' }, get_lines(0, -1, mode))
set_lines(-2, -1, mode, { 'a', 'b', 'c' }) set_lines(-2, -1, mode, { 'a', 'b', 'c' })
eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'}, eq({ 'a', 'a', 'b', 'c', 'a', 'b', 'c' }, get_lines(0, -1, mode))
get_lines(0, -1, mode))
set_lines(0, -4, 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, {}) set_lines(0, -1, mode, {})
@ -617,7 +647,7 @@ describe('api/buf', function()
eq({ 'e', 'a', 'b', 'c', 'd' }, get_lines(0, -1, true)) eq({ 'e', 'a', 'b', 'c', 'd' }, get_lines(0, -1, true))
end) 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') feed_command('set hidden')
insert('Initial file') insert('Initial file')
command('enew') command('enew')
@ -678,8 +708,7 @@ describe('api/buf', function()
eq(3, funcs.winnr()) eq(3, funcs.winnr())
feed('<c-w>h') feed('<c-w>h')
eq(2, funcs.winnr()) eq(2, funcs.winnr())
api.meths.buf_set_lines(hiddenbuf, 0, -1, true, api.meths.buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' })
{'hidden buffer line 1', 'line 2'})
feed('<c-w>p') feed('<c-w>p')
eq(3, funcs.winnr()) eq(3, funcs.winnr())
end) end)
@ -711,7 +740,6 @@ describe('api/buf', function()
eq({ 'hello foo!' }, get_lines(0, 1, true)) eq({ 'hello foo!' }, get_lines(0, 1, true))
-- can replace a single word -- can replace a single word
set_text(0, 6, 0, 9, { 'world' }) set_text(0, 6, 0, 9, { 'world' })
eq({ 'hello world!', 'text' }, get_lines(0, 2, true)) eq({ 'hello world!', 'text' }, get_lines(0, 2, true))
@ -799,7 +827,7 @@ describe('api/buf', function()
local win = meths.get_current_win() local win = meths.get_current_win()
local buf = meths.get_current_buf() local buf = meths.get_current_buf()
command("new") command('new')
-- replace 'world' with 'foo' -- replace 'world' with 'foo'
meths.buf_set_text(buf, 0, 6, 0, 11, { 'foo' }) meths.buf_set_text(buf, 0, 6, 0, 11, { 'foo' })
@ -817,12 +845,12 @@ describe('api/buf', function()
local win = meths.get_current_win() local win = meths.get_current_win()
local buf = meths.get_current_buf() local buf = meths.get_current_buf()
command("split") command('split')
local win2 = meths.get_current_win() local win2 = meths.get_current_win()
-- position the cursor on `w` -- 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' -- replace 'hello' with 'foo'
meths.buf_set_text(buf, 0, 0, 0, 5, { 'foo' }) meths.buf_set_text(buf, 0, 0, 0, 5, { 'foo' })
@ -886,7 +914,7 @@ describe('api/buf', function()
eq({ 1, 1 }, curwin('get_cursor')) eq({ 1, 1 }, curwin('get_cursor'))
end) 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([[ insert([[
abcd]]) abcd]])
@ -912,7 +940,7 @@ describe('api/buf', function()
end) end)
describe('when cursor is inside replaced row range', function() 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -934,7 +962,7 @@ describe('api/buf', function()
eq({ 1, 14 }, curwin('get_cursor')) eq({ 1, 14 }, curwin('get_cursor'))
end) 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -977,7 +1005,7 @@ describe('api/buf', function()
eq({ 1, 18 }, cursor) eq({ 1, 18 }, cursor)
end) 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1000,7 +1028,7 @@ describe('api/buf', function()
eq({ 1, 19 }, cursor) eq({ 1, 19 }, cursor)
end) 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1029,7 +1057,9 @@ describe('api/buf', function()
eq({ 2, 5 }, cursor) eq({ 2, 5 }, cursor)
end) end)
it('adjusts cursor column to keep it valid in a row after start_row if it got smaller in INSERT mode', function() it(
'adjusts cursor to valid column in row after start_row if it got smaller in INSERT mode',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1058,7 +1088,8 @@ describe('api/buf', function()
eq({ 2, 6 }, curwin('get_cursor')) eq({ 2, 6 }, curwin('get_cursor'))
-- immediate call to nvim_win_get_cursor should have returned the same position -- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 6 }, cursor) eq({ 2, 6 }, cursor)
end) end
)
it('adjusts cursor line and column to keep it inside replacement range', function() it('adjusts cursor line and column to keep it inside replacement range', function()
insert([[ insert([[
@ -1149,7 +1180,9 @@ describe('api/buf', function()
eq({ 3, 7 }, curwin('get_cursor')) eq({ 3, 7 }, curwin('get_cursor'))
end) end)
it('adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode', function() it(
'adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1168,7 +1201,8 @@ describe('api/buf', function()
}, get_lines(0, -1, true)) }, get_lines(0, -1, true))
-- cursor should end up after 'n' in 'then' -- cursor should end up after 'n' in 'then'
eq({ 3, 8 }, curwin('get_cursor')) eq({ 3, 8 }, curwin('get_cursor'))
end) end
)
it('adjusts cursor column if replacement is inside of a single line', function() it('adjusts cursor column if replacement is inside of a single line', function()
insert([[ insert([[
@ -1228,7 +1262,7 @@ describe('api/buf', function()
end) end)
describe('with virtualedit', function() 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1257,12 +1291,15 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position -- 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 -- coladd should be 0
eq(0, exec_lua([[ eq(
0,
exec_lua([[
return vim.fn.winsaveview().coladd return vim.fn.winsaveview().coladd
]])) ]])
)
end) 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([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1294,12 +1331,17 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position -- 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 -- 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 return vim.fn.winsaveview().coladd
]])) ]])
)
end) end)
it('does not change cursor screen column when cursor is after eol and row got longer', function() it(
'does not change cursor screen column when cursor is after eol and row got longer',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1331,12 +1373,18 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position -- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 38 }, cursor) eq({ 1, 38 }, cursor)
-- coladd should be increased so that cursor stays in the same screen column -- coladd should be increased so that cursor stays in the same screen column
eq(2, exec_lua([[ eq(
2,
exec_lua([[
return vim.fn.winsaveview().coladd return vim.fn.winsaveview().coladd
]])) ]])
end) )
end
)
it('does not change cursor screen column when cursor is after eol and row extended past cursor column', function() it(
'does not change cursor screen column when cursor is after eol and row extended past cursor column',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1368,12 +1416,18 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position -- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 22 }, cursor) eq({ 1, 22 }, cursor)
-- coladd should become 0 -- coladd should become 0
eq(0, exec_lua([[ eq(
0,
exec_lua([[
return vim.fn.winsaveview().coladd return vim.fn.winsaveview().coladd
]])) ]])
end) )
end
)
it('does not change cursor screen column when cursor is after eol and row range decreased', function() it(
'does not change cursor screen column when cursor is after eol and row range decreased',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1406,10 +1460,14 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position -- 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 -- 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 return vim.fn.winsaveview().coladd
]])) ]])
end) )
end
)
end) end)
end) end)
@ -1434,7 +1492,9 @@ describe('api/buf', function()
eq({ 3, 2 }, curwin('get_cursor')) eq({ 3, 2 }, curwin('get_cursor'))
end) end)
it('adjusts cursor column if the range is not bound to either start or end of a line', function() it(
'adjusts cursor column if the range is not bound to either start or end of a line',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1459,9 +1519,12 @@ describe('api/buf', function()
}, get_lines(0, -1, true)) }, get_lines(0, -1, true))
-- cursor should return back to the original position -- cursor should return back to the original position
eq({ 3, 13 }, curwin('get_cursor')) eq({ 3, 13 }, curwin('get_cursor'))
end) end
)
it('adjusts cursor column if replacing lines in range, not just deleting and adding', function() it(
'adjusts cursor column if replacing lines in range, not just deleting and adding',
function()
insert([[ insert([[
This should be first This should be first
then there is a line we do not want then there is a line we do not want
@ -1494,7 +1557,8 @@ describe('api/buf', function()
}, get_lines(0, -1, true)) }, get_lines(0, -1, true))
-- cursor should return back to the original position -- cursor should return back to the original position
eq({ 3, 18 }, curwin('get_cursor')) eq({ 3, 18 }, curwin('get_cursor'))
end) end
)
it('does not move cursor column after end of a line', function() it('does not move cursor column after end of a line', function()
insert([[ insert([[
@ -1543,7 +1607,7 @@ describe('api/buf', function()
end) end)
it('adjusts extmarks', function() it('adjusts extmarks', function()
local ns = request('nvim_create_namespace', "my-fancy-plugin") local ns = request('nvim_create_namespace', 'my-fancy-plugin')
insert([[ insert([[
foo bar foo bar
baz baz
@ -1551,7 +1615,7 @@ describe('api/buf', function()
local id1 = curbufmeths.set_extmark(ns, 0, 1, {}) local id1 = curbufmeths.set_extmark(ns, 0, 1, {})
local id2 = curbufmeths.set_extmark(ns, 0, 7, {}) local id2 = curbufmeths.set_extmark(ns, 0, 7, {})
local id3 = curbufmeths.set_extmark(ns, 1, 1, {}) 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 -- mark before replacement point is unaffected
@ -1562,7 +1626,7 @@ describe('api/buf', function()
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 -- replacing the text spanning two lines will adjust the mark on the next line
set_text(0, 3, 1, 3, {"qux"}) set_text(0, 3, 1, 3, { 'qux' })
eq({ 'fooqux', '' }, get_lines(0, 2, true)) eq({ 'fooqux', '' }, get_lines(0, 2, true))
eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {})) eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
-- but mark before replacement point is still unaffected -- but mark before replacement point is still unaffected
@ -1585,7 +1649,7 @@ describe('api/buf', function()
eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id3, {})) eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id3, {}))
end) 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) local screen = Screen.new(20, 5)
screen:attach() screen:attach()
@ -1642,12 +1706,12 @@ describe('api/buf', function()
before_each(function() before_each(function()
screen = Screen.new(20, 12) screen = Screen.new(20, 12)
screen:set_default_attr_ids { screen:set_default_attr_ids {
[1] = {bold = true, foreground = Screen.colors.Blue1}; [1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = {reverse = true, bold = true}; [2] = { reverse = true, bold = true },
[3] = {reverse = true}; [3] = { reverse = true },
} }
screen:attach() 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, {}) meths.set_option_value('modified', false, {})
end) end)
@ -1658,7 +1722,8 @@ describe('api/buf', function()
command('new | wincmd w') 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 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -1668,10 +1733,12 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] }| {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 {1:~ }|*4
{3:[No Name] }| {3:[No Name] }|
@ -1681,7 +1748,8 @@ describe('api/buf', function()
^zzz | ^zzz |
{2:[No Name] [+] }| {2:[No Name] [+] }|
| |
]]} ]],
}
end) end)
it('of non-current window', function() it('of non-current window', function()
@ -1691,7 +1759,8 @@ describe('api/buf', function()
command('new') command('new')
meths.win_set_cursor(win, { 8, 0 }) meths.win_set_cursor(win, { 8, 0 })
screen:expect{grid=[[ screen:expect {
grid = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -1701,10 +1770,12 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] }| {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 = [[
^ | ^ |
{1:~ }|*4 {1:~ }|*4
{2:[No Name] }| {2:[No Name] }|
@ -1714,7 +1785,8 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
end) end)
it('of split windows with same buffer', function() it('of split windows with same buffer', function()
@ -1725,7 +1797,8 @@ describe('api/buf', function()
meths.win_set_cursor(win, { 8, 0 }) meths.win_set_cursor(win, { 8, 0 })
meths.win_set_cursor(0, { 1, 1 }) meths.win_set_cursor(0, { 1, 1 })
screen:expect{grid=[[ screen:expect {
grid = [[
a^aa | a^aa |
bbb | bbb |
ccc | ccc |
@ -1738,10 +1811,12 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] }| {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 | a^aaXbbb |
ccc | ccc |
ddd | ddd |
@ -1754,7 +1829,8 @@ describe('api/buf', function()
zzz | zzz |
{3:[No Name] [+] }| {3:[No Name] [+] }|
| |
]]} ]],
}
end) end)
end) end)
end) end)
@ -1823,10 +1899,10 @@ describe('api/buf', function()
meths.set_option_value('eol', true, {}) meths.set_option_value('eol', true, {})
eq(29, get_offset(5)) eq(29, get_offset(5))
command("set hidden") command('set hidden')
command("enew") command('enew')
eq(6, bufmeths.get_offset(1, 1)) eq(6, bufmeths.get_offset(1, 1))
command("bunload! 1") command('bunload! 1')
eq(-1, bufmeths.get_offset(1, 1)) eq(-1, bufmeths.get_offset(1, 1))
eq(-1, bufmeths.get_offset(1, 0)) eq(-1, bufmeths.get_offset(1, 0))
end) end)
@ -1857,10 +1933,8 @@ describe('api/buf', function()
command('lockvar b:lua') command('lockvar b:lua')
eq('Key is locked: lua', pcall_err(curbufmeths.del_var, '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 locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1))
eq('Key is read-only: changedtick', eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, '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.set_var, 'changedtick', 1))
end) end)
end) end)
@ -1897,7 +1971,7 @@ describe('api/buf', function()
nvim('set_option_value', 'define', 'test', { buf = 0 }) nvim('set_option_value', 'define', 'test', { buf = 0 })
eq('test', nvim('get_option_value', 'define', { buf = 0 })) eq('test', nvim('get_option_value', 'define', { buf = 0 }))
-- Doesn't change the global value -- Doesn't change the global value
eq("", nvim('get_option_value', 'define', {scope='global'})) eq('', nvim('get_option_value', 'define', { scope = 'global' }))
end) end)
it('returns values for unset local options', function() it('returns values for unset local options', function()

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ describe('spellfile', function()
local spellheader = 'VIMspell\050' local spellheader = 'VIMspell\050'
it('errors out when prefcond section is truncated', function() it('errors out when prefcond section is truncated', function()
meths.set_option_value('runtimepath', testdir, {}) meths.set_option_value('runtimepath', testdir, {})
-- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -35,11 +36,11 @@ describe('spellfile', function()
-- │ │ ┌ Condition regex (missing!) -- │ │ ┌ Condition regex (missing!)
.. '\000\001\001') .. '\000\001\001')
meths.set_option_value('spelllang', 'en', {}) meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E758: Truncated spell file', eq('Vim(set):E758: Truncated spell file', exc_exec('set spell'))
exc_exec('set spell'))
end) end)
it('errors out when prefcond regexp contains NUL byte', function() it('errors out when prefcond regexp contains NUL byte', function()
meths.set_option_value('runtimepath', testdir, {}) meths.set_option_value('runtimepath', testdir, {})
-- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -55,11 +56,11 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option_value('spelllang', 'en', {}) meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
exc_exec('set spell'))
end) end)
it('errors out when region contains NUL byte', function() it('errors out when region contains NUL byte', function()
meths.set_option_value('runtimepath', testdir, {}) meths.set_option_value('runtimepath', testdir, {})
-- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_REGION) -- ┌ Section identifier (#SN_REGION)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -72,11 +73,11 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option_value('spelllang', 'en', {}) meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
exc_exec('set spell'))
end) end)
it('errors out when SAL section contains NUL byte', function() it('errors out when SAL section contains NUL byte', function()
meths.set_option_value('runtimepath', testdir, {}) meths.set_option_value('runtimepath', testdir, {})
-- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_SAL) -- ┌ Section identifier (#SN_SAL)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -96,15 +97,12 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option_value('spelllang', 'en', {}) meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
exc_exec('set spell'))
end) end)
it('errors out when spell header contains NUL bytes', function() it('errors out when spell header contains NUL bytes', function()
meths.set_option_value('runtimepath', testdir, {}) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000')
spellheader:sub(1, -3) .. '\000\000')
meths.set_option_value('spelllang', 'en', {}) meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E757: This does not look like a spell file', eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell'))
exc_exec('set spell'))
end) end)
end) end)

View File

@ -31,6 +31,7 @@ describe('msgpack*() functions', function()
-- Test that big objects (requirement: dump to something that is bigger then -- Test that big objects (requirement: dump to something that is bigger then
-- IOSIZE) are also fine. This particular object is obtained by concatenating -- IOSIZE) are also fine. This particular object is obtained by concatenating
-- 5 identical shada files. -- 5 identical shada files.
-- stylua: ignore
local big_obj = { local big_obj = {
1, 1436711454, 78, { 1, 1436711454, 78, {
encoding="utf-8", encoding="utf-8",
@ -336,8 +337,7 @@ describe('msgpack*() functions', function()
command('let dumped = ["\\xCF" . repeat("\\xFF", 8)]') command('let dumped = ["\\xCF" . repeat("\\xFF", 8)]')
command('let parsed = msgpackparse(dumped)') command('let parsed = msgpackparse(dumped)')
command('let dumped2 = msgpackdump(parsed)') command('let dumped2 = msgpackdump(parsed)')
eq(1, eval('type(parsed[0]) == type(0) ' .. eq(1, eval('type(parsed[0]) == type(0) ' .. '|| parsed[0]._TYPE is v:msgpack_types.integer'))
'|| parsed[0]._TYPE is v:msgpack_types.integer'))
if eval('type(parsed[0]) == type(0)') == 1 then if eval('type(parsed[0]) == type(0)') == 1 then
command('call assert_equal(0xFFFFFFFFFFFFFFFF, parsed[0])') command('call assert_equal(0xFFFFFFFFFFFFFFFF, parsed[0])')
eq({}, eval('v:errors')) eq({}, eval('v:errors'))
@ -351,8 +351,7 @@ describe('msgpack*() functions', function()
command('let dumped = ["\\xD3\\x80" . repeat("\\n", 7)]') command('let dumped = ["\\xD3\\x80" . repeat("\\n", 7)]')
command('let parsed = msgpackparse(dumped)') command('let parsed = msgpackparse(dumped)')
command('let dumped2 = msgpackdump(parsed)') command('let dumped2 = msgpackdump(parsed)')
eq(1, eval('type(parsed[0]) == type(0) ' .. eq(1, eval('type(parsed[0]) == type(0) ' .. '|| parsed[0]._TYPE is v:msgpack_types.integer'))
'|| parsed[0]._TYPE is v:msgpack_types.integer'))
if eval('type(parsed[0]) == type(0)') == 1 then if eval('type(parsed[0]) == type(0)') == 1 then
command('call assert_equal(-0x7fffffffffffffff - 1, parsed[0])') command('call assert_equal(-0x7fffffffffffffff - 1, parsed[0])')
eq({}, eval('v:errors')) eq({}, eval('v:errors'))
@ -383,7 +382,7 @@ describe('msgpack*() functions', function()
command('let dumped = ["\\xC4\\x01", ""]') command('let dumped = ["\\xC4\\x01", ""]')
command('let parsed = msgpackparse(dumped)') command('let parsed = msgpackparse(dumped)')
command('let dumped2 = msgpackdump(parsed)') command('let dumped2 = msgpackdump(parsed)')
eq({"\n"}, eval('parsed')) eq({ '\n' }, eval('parsed'))
eq(1, eval('dumped ==# dumped2')) eq(1, eval('dumped ==# dumped2'))
end) end)
@ -403,7 +402,8 @@ end
-- Test msgpackparse() with a readfile()-style list and a blob argument -- Test msgpackparse() with a readfile()-style list and a blob argument
local parse_eq = function(expect, list_arg) local parse_eq = function(expect, list_arg)
local blob_expr = '0z' .. blobstr(list_arg):gsub('(.)', function(c) local blob_expr = '0z'
.. blobstr(list_arg):gsub('(.)', function(c)
return ('%.2x'):format(c:byte()) return ('%.2x'):format(c:byte())
end) end)
eq(expect, funcs.msgpackparse(list_arg)) eq(expect, funcs.msgpackparse(list_arg))
@ -436,7 +436,7 @@ describe('msgpackparse() function', function()
end) end)
it('restores FIXEXT1 as special dictionary', function() it('restores FIXEXT1 as special dictionary', function()
parse_eq({{_TYPE={}, _VAL={0x10, {"", ""}}}}, {'\212\016', ''}) parse_eq({ { _TYPE = {}, _VAL = { 0x10, { '', '' } } } }, { '\212\016', '' })
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.ext')) eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.ext'))
end) end)
@ -449,8 +449,15 @@ describe('msgpackparse() function', function()
command('let dumped = ["\\x82\\xA1a\\xC4\\n\\xA1a\\xC4\\n"]') command('let dumped = ["\\x82\\xA1a\\xC4\\n\\xA1a\\xC4\\n"]')
-- FIXME Internal error bug, can't use parse_eq() here -- FIXME Internal error bug, can't use parse_eq() here
command('silent! let parsed = msgpackparse(dumped)') command('silent! let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={ {{_TYPE={}, _VAL={'a'}}, ''}, eq({
{{_TYPE={}, _VAL={'a'}}, ''}}} }, eval('parsed')) {
_TYPE = {},
_VAL = {
{ { _TYPE = {}, _VAL = { 'a' } }, '' },
{ { _TYPE = {}, _VAL = { 'a' } }, '' },
},
},
}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map')) eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
eq(1, eval('g:parsed[0]._VAL[0][0]._TYPE is v:msgpack_types.string')) eq(1, eval('g:parsed[0]._VAL[0][0]._TYPE is v:msgpack_types.string'))
eq(1, eval('g:parsed[0]._VAL[1][0]._TYPE is v:msgpack_types.string')) eq(1, eval('g:parsed[0]._VAL[1][0]._TYPE is v:msgpack_types.string'))
@ -462,8 +469,7 @@ describe('msgpackparse() function', function()
end) end)
it('msgpackparse(systemlist(...)) does not segfault. #3135', function() it('msgpackparse(systemlist(...)) does not segfault. #3135', function()
local cmd = "sort(keys(msgpackparse(systemlist('" local cmd = "sort(keys(msgpackparse(systemlist('" .. helpers.nvim_prog .. " --api-info'))[0]))"
..helpers.nvim_prog.." --api-info'))[0]))"
eval(cmd) eval(cmd)
eval(cmd) -- do it again (try to force segfault) eval(cmd) -- do it again (try to force segfault)
local api_info = eval(cmd) -- do it again local api_info = eval(cmd) -- do it again
@ -472,49 +478,64 @@ describe('msgpackparse() function', function()
pending('msgpackparse() has a bug on windows') pending('msgpackparse() has a bug on windows')
return return
end end
eq({'error_types', 'functions', 'types', eq({ 'error_types', 'functions', 'types', 'ui_events', 'ui_options', 'version' }, api_info)
'ui_events', 'ui_options', 'version'}, api_info)
end) end)
it('fails when called with no arguments', function() it('fails when called with no arguments', function()
eq('Vim(call):E119: Not enough arguments for function: msgpackparse', eq(
exc_exec('call msgpackparse()')) 'Vim(call):E119: Not enough arguments for function: msgpackparse',
exc_exec('call msgpackparse()')
)
end) end)
it('fails when called with two arguments', function() it('fails when called with two arguments', function()
eq('Vim(call):E118: Too many arguments for function: msgpackparse', eq(
exc_exec('call msgpackparse(["", ""], 1)')) 'Vim(call):E118: Too many arguments for function: msgpackparse',
exc_exec('call msgpackparse(["", ""], 1)')
)
end) end)
it('fails to parse a string', function() it('fails to parse a string', function()
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse("abcdefghijklmnopqrstuvwxyz")')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse("abcdefghijklmnopqrstuvwxyz")')
)
end) end)
it('fails to parse a number', function() it('fails to parse a number', function()
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse(127)')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(127)')
)
end) end)
it('fails to parse a dictionary', function() it('fails to parse a dictionary', function()
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse({})')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse({})')
)
end) end)
it('fails to parse a funcref', function() it('fails to parse a funcref', function()
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse(function("tr"))')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(function("tr"))')
)
end) end)
it('fails to parse a partial', function() it('fails to parse a partial', function()
command('function T() dict\nendfunction') command('function T() dict\nendfunction')
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse(function("T", [1, 2], {}))')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(function("T", [1, 2], {}))')
)
end) end)
it('fails to parse a float', function() it('fails to parse a float', function()
eq('Vim(call):E899: Argument of msgpackparse() must be a List or Blob', eq(
exc_exec('call msgpackparse(0.0)')) 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(0.0)')
)
end) end)
it('fails on incomplete msgpack string', function() it('fails on incomplete msgpack string', function()
@ -607,137 +628,173 @@ describe('msgpackdump() function', function()
it('fails to dump a function reference', function() it('fails to dump a function reference', function()
command('let Todump = function("tr")') command('let Todump = function("tr")')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference', eq(
exc_exec('call msgpackdump([Todump])')) 'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])')
)
end) end)
it('fails to dump a partial', function() it('fails to dump a partial', function()
command('function T() dict\nendfunction') command('function T() dict\nendfunction')
command('let Todump = function("T", [1, 2], {})') command('let Todump = function("T", [1, 2], {})')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference', eq(
exc_exec('call msgpackdump([Todump])')) 'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])')
)
end) end)
it('fails to dump a function reference in a list', function() it('fails to dump a function reference in a list', function()
command('let todump = [function("tr")]') command('let todump = [function("tr")]')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, index 0: attempt to dump function reference', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, index 0: attempt to dump function reference',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive list', function() it('fails to dump a recursive list', function()
command('let todump = [[[]]]') command('let todump = [[[]]]')
command('call add(todump[0][0], todump)') command('call add(todump[0][0], todump)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 0, index 0', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 0, index 0',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive dict', function() it('fails to dump a recursive dict', function()
command('let todump = {"d": {"d": {}}}') command('let todump = {"d": {"d": {}}}')
command('call extend(todump.d.d, {"d": todump})') command('call extend(todump.d.d, {"d": todump})')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key \'d\', key \'d\', key \'d\'', eq(
exc_exec('call msgpackdump([todump])')) "Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 'd', key 'd', key 'd'",
exc_exec('call msgpackdump([todump])')
)
end) end)
it('can dump dict with two same dicts inside', function() it('can dump dict with two same dicts inside', function()
command('let inter = {}') command('let inter = {}')
command('let todump = {"a": inter, "b": inter}') command('let todump = {"a": inter, "b": inter}')
dump_eq({"\130\161a\128\161b\128"}, '[todump]') dump_eq({ '\130\161a\128\161b\128' }, '[todump]')
end) end)
it('can dump list with two same lists inside', function() it('can dump list with two same lists inside', function()
command('let inter = []') command('let inter = []')
command('let todump = [inter, inter]') command('let todump = [inter, inter]')
dump_eq({"\146\144\144"}, '[todump]') dump_eq({ '\146\144\144' }, '[todump]')
end) end)
it('fails to dump a recursive list in a special dict', function() it('fails to dump a recursive list in a special dict', function()
command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
command('call add(todump._VAL, todump)') command('call add(todump._VAL, todump)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive (key) map in a special dict', function() it('fails to dump a recursive (key) map in a special dict', function()
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('call add(todump._VAL, [todump, 0])') command('call add(todump._VAL, [todump, 0])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive (val) map in a special dict', function() it('fails to dump a recursive (val) map in a special dict', function()
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('call add(todump._VAL, [0, todump])') command('call add(todump._VAL, [0, todump])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 0 at index 0 from special map', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 0 at index 0 from special map',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive (key) map in a special dict, _VAL reference', function() it('fails to dump a recursive (key) map in a special dict, _VAL reference', function()
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}') command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
command('call add(todump._VAL[0][0], todump._VAL)') command('call add(todump._VAL[0][0], todump._VAL)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive (val) map in a special dict, _VAL reference', function() it('fails to dump a recursive (val) map in a special dict, _VAL reference', function()
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}') command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
command('call add(todump._VAL[0][1], todump._VAL)') command('call add(todump._VAL[0][1], todump._VAL)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [] at index 0 from special map, index 0', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails to dump a recursive (val) special list in a special dict', it('fails to dump a recursive (val) special list in a special dict', function()
function()
command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
command('call add(todump._VAL, [0, todump._VAL])') command('call add(todump._VAL, [0, todump._VAL])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 1', eq(
exc_exec('call msgpackdump([todump])')) 'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 1',
exc_exec('call msgpackdump([todump])')
)
end) end)
it('fails when called with no arguments', function() it('fails when called with no arguments', function()
eq('Vim(call):E119: Not enough arguments for function: msgpackdump', eq(
exc_exec('call msgpackdump()')) 'Vim(call):E119: Not enough arguments for function: msgpackdump',
exc_exec('call msgpackdump()')
)
end) end)
it('fails when called with three arguments', function() it('fails when called with three arguments', function()
eq('Vim(call):E118: Too many arguments for function: msgpackdump', eq(
exc_exec('call msgpackdump(["", ""], 1, 2)')) 'Vim(call):E118: Too many arguments for function: msgpackdump',
exc_exec('call msgpackdump(["", ""], 1, 2)')
)
end) end)
it('fails to dump a string', function() it('fails to dump a string', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump("abcdefghijklmnopqrstuvwxyz")')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump("abcdefghijklmnopqrstuvwxyz")')
)
end) end)
it('fails to dump a number', function() it('fails to dump a number', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump(127)')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(127)')
)
end) end)
it('fails to dump a dictionary', function() it('fails to dump a dictionary', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq('Vim(call):E686: Argument of msgpackdump() must be a List', exc_exec('call msgpackdump({})'))
exc_exec('call msgpackdump({})'))
end) end)
it('fails to dump a funcref', function() it('fails to dump a funcref', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump(function("tr"))')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("tr"))')
)
end) end)
it('fails to dump a partial', function() it('fails to dump a partial', function()
command('function T() dict\nendfunction') command('function T() dict\nendfunction')
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump(function("T", [1, 2], {}))')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("T", [1, 2], {}))')
)
end) end)
it('fails to dump a float', function() it('fails to dump a float', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump(0.0)')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(0.0)')
)
end) end)
it('fails to dump special value', function() it('fails to dump special value', function()
for _, val in ipairs({ 'v:true', 'v:false', 'v:null' }) do for _, val in ipairs({ 'v:true', 'v:false', 'v:null' }) do
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq(
exc_exec('call msgpackdump(' .. val .. ')')) 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(' .. val .. ')')
)
end end
end) end)