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)

File diff suppressed because it is too large Load Diff

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

@ -20,17 +20,18 @@ describe('msgpack*() functions', function()
-- Regression test: msgpack_list_write was failing to write buffer with zero -- Regression test: msgpack_list_write was failing to write buffer with zero
-- length. -- length.
obj_test('are able to dump and restore {"file": ""}', {{file=''}}) obj_test('are able to dump and restore {"file": ""}', { { file = '' } })
-- Regression test: msgpack_list_write was failing to write buffer with NL at -- Regression test: msgpack_list_write was failing to write buffer with NL at
-- the end. -- the end.
obj_test('are able to dump and restore {0, "echo mpack"}', {{0, 'echo mpack'}}) obj_test('are able to dump and restore {0, "echo mpack"}', { { 0, 'echo mpack' } })
obj_test('are able to dump and restore "Test\\n"', {'Test\n'}) obj_test('are able to dump and restore "Test\\n"', { 'Test\n' })
-- Regression test: msgpack_list_write was failing to write buffer with NL -- Regression test: msgpack_list_write was failing to write buffer with NL
-- inside. -- inside.
obj_test('are able to dump and restore "Test\\nTest 2"', {'Test\nTest 2'}) obj_test('are able to dump and restore "Test\\nTest 2"', { 'Test\nTest 2' })
-- 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",
@ -330,19 +331,18 @@ describe('msgpack*() functions', function()
} }
obj_test('are able to dump and restore rather big object', big_obj) obj_test('are able to dump and restore rather big object', big_obj)
obj_test('are able to dump and restore floating-point value', {0.125}) obj_test('are able to dump and restore floating-point value', { 0.125 })
it('can restore and dump UINT64_MAX', function() it('can restore and dump UINT64_MAX', 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'))
else else
eq({_TYPE={}, _VAL={1, 3, 0x7FFFFFFF, 0x7FFFFFFF}}, eval('parsed[0]')) eq({ _TYPE = {}, _VAL = { 1, 3, 0x7FFFFFFF, 0x7FFFFFFF } }, eval('parsed[0]'))
end end
eq(1, eval('dumped ==# dumped2')) eq(1, eval('dumped ==# dumped2'))
end) end)
@ -351,13 +351,12 @@ 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'))
else else
eq({_TYPE={}, _VAL={-1, 2, 0, 0}}, eval('parsed[0]')) eq({ _TYPE = {}, _VAL = { -1, 2, 0, 0 } }, eval('parsed[0]'))
end end
eq(1, eval('dumped ==# dumped2')) eq(1, eval('dumped ==# dumped2'))
end) end)
@ -366,7 +365,7 @@ describe('msgpack*() functions', function()
command('let dumped = ["\\xC4\\x01\\n"]') command('let dumped = ["\\xC4\\x01\\n"]')
command('let parsed = msgpackparse(dumped)') command('let parsed = msgpackparse(dumped)')
command('let dumped2 = msgpackdump(parsed)') command('let dumped2 = msgpackdump(parsed)')
eq({'\000'}, eval('parsed')) eq({ '\000' }, eval('parsed'))
eq(1, eval('dumped ==# dumped2')) eq(1, eval('dumped ==# dumped2'))
end) end)
@ -374,7 +373,7 @@ describe('msgpack*() functions', function()
command('let dumped = ["\\xA1\\n"]') command('let dumped = ["\\xA1\\n"]')
command('let parsed = msgpackparse(dumped)') command('let parsed = msgpackparse(dumped)')
command('let dumped2 = msgpackdump(parsed)') command('let dumped2 = msgpackdump(parsed)')
eq({{_TYPE={}, _VAL={'\n'}}}, eval('parsed')) eq({ { _TYPE = {}, _VAL = { '\n' } } }, eval('parsed'))
eq(1, eval('parsed[0]._TYPE is v:msgpack_types.string')) eq(1, eval('parsed[0]._TYPE is v:msgpack_types.string'))
eq(1, eval('dumped ==# dumped2')) eq(1, eval('dumped ==# dumped2'))
end) end)
@ -383,19 +382,19 @@ 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)
it('dump and restore special mapping with floating-point value', function() it('dump and restore special mapping with floating-point value', function()
command('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') command('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}')
eq({0.125}, eval('msgpackparse(msgpackdump([todump]))')) eq({ 0.125 }, eval('msgpackparse(msgpackdump([todump]))'))
end) end)
end) end)
local blobstr = function(list) local blobstr = function(list)
local l = {} local l = {}
for i,v in ipairs(list) do for i, v in ipairs(list) do
l[i] = v:gsub('\n', '\000') l[i] = v:gsub('\n', '\000')
end end
return table.concat(l, '\n') return table.concat(l, '\n')
@ -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))
@ -415,33 +415,33 @@ describe('msgpackparse() function', function()
before_each(clear) before_each(clear)
it('restores nil as v:null', function() it('restores nil as v:null', function()
parse_eq(eval('[v:null]'), {'\192'}) parse_eq(eval('[v:null]'), { '\192' })
end) end)
it('restores boolean false as v:false', function() it('restores boolean false as v:false', function()
parse_eq({false}, {'\194'}) parse_eq({ false }, { '\194' })
end) end)
it('restores boolean true as v:true', function() it('restores boolean true as v:true', function()
parse_eq({true}, {'\195'}) parse_eq({ true }, { '\195' })
end) end)
it('restores FIXSTR as special dict', function() it('restores FIXSTR as special dict', function()
parse_eq({{_TYPE={}, _VAL={'ab'}}}, {'\162ab'}) parse_eq({ { _TYPE = {}, _VAL = { 'ab' } } }, { '\162ab' })
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.string')) eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.string'))
end) end)
it('restores BIN 8 as string', function() it('restores BIN 8 as string', function()
parse_eq({'ab'}, {'\196\002ab'}) parse_eq({ 'ab' }, { '\196\002ab' })
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)
it('restores MAP with BIN key as special dictionary', function() it('restores MAP with BIN key as special dictionary', function()
parse_eq({{_TYPE={}, _VAL={{'a', ''}}}}, {'\129\196\001a\196\n'}) parse_eq({ { _TYPE = {}, _VAL = { { 'a', '' } } } }, { '\129\196\001a\196\n' })
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map')) eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
end) end)
@ -449,21 +449,27 @@ 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'))
end) end)
it('restores MAP with MAP key as special dictionary', function() it('restores MAP with MAP key as special dictionary', function()
parse_eq({{_TYPE={}, _VAL={{{}, ''}}}}, {'\129\128\196\n'}) parse_eq({ { _TYPE = {}, _VAL = { { {}, '' } } } }, { '\129\128\196\n' })
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map')) eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
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()
@ -541,11 +562,11 @@ describe('msgpackdump() function', function()
end end
it('dumps string as BIN 8', function() it('dumps string as BIN 8', function()
dump_eq({'\196\004Test'}, '["Test"]') dump_eq({ '\196\004Test' }, '["Test"]')
end) end)
it('dumps blob as BIN 8', function() it('dumps blob as BIN 8', function()
dump_eq({'\196\005Bl\nb!'}, '[0z426c006221]') dump_eq({ '\196\005Bl\nb!' }, '[0z426c006221]')
end) end)
it('can dump generic mapping with generic mapping keys and values', function() it('can dump generic mapping with generic mapping keys and values', function()
@ -553,209 +574,245 @@ describe('msgpackdump() function', function()
command('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('call add(todump._VAL, [todumpv1, todumpv2])') command('call add(todump._VAL, [todumpv1, todumpv2])')
dump_eq({'\129\128\128'}, '[todump]') dump_eq({ '\129\128\128' }, '[todump]')
end) end)
it('can dump v:true', function() it('can dump v:true', function()
dump_eq({'\195'}, '[v:true]') dump_eq({ '\195' }, '[v:true]')
end) end)
it('can dump v:false', function() it('can dump v:false', function()
dump_eq({'\194'}, '[v:false]') dump_eq({ '\194' }, '[v:false]')
end) end)
it('can dump v:null', function() it('can dump v:null', function()
dump_eq({'\192'}, '[v:null]') dump_eq({ '\192' }, '[v:null]')
end) end)
it('can dump special bool mapping (true)', function() it('can dump special bool mapping (true)', function()
command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}') command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}')
dump_eq({'\195'}, '[todump]') dump_eq({ '\195' }, '[todump]')
end) end)
it('can dump special bool mapping (false)', function() it('can dump special bool mapping (false)', function()
command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}') command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}')
dump_eq({'\194'}, '[todump]') dump_eq({ '\194' }, '[todump]')
end) end)
it('can dump special nil mapping', function() it('can dump special nil mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}') command('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}')
dump_eq({'\192'}, '[todump]') dump_eq({ '\192' }, '[todump]')
end) end)
it('can dump special ext mapping', function() it('can dump special ext mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
dump_eq({'\212\005', ''}, '[todump]') dump_eq({ '\212\005', '' }, '[todump]')
end) end)
it('can dump special array mapping', function() it('can dump special array mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}')
dump_eq({'\146\005\145\196\n'}, '[todump]') dump_eq({ '\146\005\145\196\n' }, '[todump]')
end) end)
it('can dump special UINT64_MAX mapping', function() it('can dump special UINT64_MAX mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.integer}') command('let todump = {"_TYPE": v:msgpack_types.integer}')
command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]')
dump_eq({'\207\255\255\255\255\255\255\255\255'}, '[todump]') dump_eq({ '\207\255\255\255\255\255\255\255\255' }, '[todump]')
end) end)
it('can dump special INT64_MIN mapping', function() it('can dump special INT64_MIN mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.integer}') command('let todump = {"_TYPE": v:msgpack_types.integer}')
command('let todump._VAL = [-1, 2, 0, 0]') command('let todump._VAL = [-1, 2, 0, 0]')
dump_eq({'\211\128\n\n\n\n\n\n\n'}, '[todump]') dump_eq({ '\211\128\n\n\n\n\n\n\n' }, '[todump]')
end) end)
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)
it('can dump NULL string', function() it('can dump NULL string', function()
dump_eq({'\196\n'}, '[$XXX_UNEXISTENT_VAR_XXX]') dump_eq({ '\196\n' }, '[$XXX_UNEXISTENT_VAR_XXX]')
dump_eq({'\196\n'}, '[{"_TYPE": v:msgpack_types.binary, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}]') dump_eq({ '\196\n' }, '[{"_TYPE": v:msgpack_types.binary, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}]')
dump_eq({'\160'}, '[{"_TYPE": v:msgpack_types.string, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}]') dump_eq({ '\160' }, '[{"_TYPE": v:msgpack_types.string, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}]')
end) end)
it('can dump NULL blob', function() it('can dump NULL blob', function()
eq({'\196\n'}, eval('msgpackdump([v:_null_blob])')) eq({ '\196\n' }, eval('msgpackdump([v:_null_blob])'))
end) end)
it('can dump NULL list', function() it('can dump NULL list', function()
eq({'\144'}, eval('msgpackdump([v:_null_list])')) eq({ '\144' }, eval('msgpackdump([v:_null_list])'))
end) end)
it('can dump NULL dictionary', function() it('can dump NULL dictionary', function()
eq({'\128'}, eval('msgpackdump([v:_null_dict])')) eq({ '\128' }, eval('msgpackdump([v:_null_dict])'))
end) end)
end) end)