mirror of
https://github.com/neovim/neovim.git
synced 2026-05-03 04:25:03 +00:00
refactor: format test/*
This commit is contained in:
@@ -17,50 +17,63 @@ describe('luaeval(vim.api.…)', function()
|
||||
describe('with channel_id and buffer handle', function()
|
||||
describe('nvim_buf_get_lines', function()
|
||||
it('works', function()
|
||||
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||
eq({'a\000b'},
|
||||
funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)'))
|
||||
funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' })
|
||||
eq({ 'a\000b' }, funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)'))
|
||||
end)
|
||||
end)
|
||||
describe('nvim_buf_set_lines', function()
|
||||
it('works', function()
|
||||
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||
funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' })
|
||||
eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})'))
|
||||
eq({'abc', 'b\000a', 'a\000b', 'ttt'},
|
||||
funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)'))
|
||||
eq(
|
||||
{ 'abc', 'b\000a', 'a\000b', 'ttt' },
|
||||
funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)')
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
describe('with errors', function()
|
||||
it('transforms API error from nvim_buf_set_lines into lua error', function()
|
||||
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||
eq({false, "'replacement string' item contains newlines"},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}'))
|
||||
funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' })
|
||||
eq(
|
||||
{ false, "'replacement string' item contains newlines" },
|
||||
funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}')
|
||||
)
|
||||
end)
|
||||
|
||||
it('transforms API error from nvim_win_set_cursor into lua error', function()
|
||||
eq({false, 'Argument "pos" must be a [row, col] array'},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}'))
|
||||
eq(
|
||||
{ false, 'Argument "pos" must be a [row, col] array' },
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}')
|
||||
)
|
||||
-- Used to produce a memory leak due to a bug in nvim_win_set_cursor
|
||||
eq({false, 'Invalid window id: -1'},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}'))
|
||||
eq(
|
||||
{ false, 'Invalid window id: -1' },
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}')
|
||||
)
|
||||
end)
|
||||
|
||||
it('transforms API error from nvim_win_set_cursor + same array as in first test into lua error',
|
||||
function()
|
||||
eq({false, 'Argument "pos" must be a [row, col] array'},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}'))
|
||||
end)
|
||||
it(
|
||||
'transforms API error from nvim_win_set_cursor + same array as in first test into lua error',
|
||||
function()
|
||||
eq(
|
||||
{ false, 'Argument "pos" must be a [row, col] array' },
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}')
|
||||
)
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
it('correctly evaluates API code which calls luaeval', function()
|
||||
local str = (([===[vim.api.nvim_eval([==[
|
||||
local str = (
|
||||
([===[vim.api.nvim_eval([==[
|
||||
luaeval('vim.api.nvim_eval([=[
|
||||
luaeval("vim.api.nvim_eval([[
|
||||
luaeval(1)
|
||||
]])")
|
||||
]=])')
|
||||
]==])]===]):gsub('\n', ' '))
|
||||
]==])]===]):gsub('\n', ' ')
|
||||
)
|
||||
eq(1, funcs.luaeval(str))
|
||||
end)
|
||||
|
||||
@@ -86,28 +99,32 @@ describe('luaeval(vim.api.…)', function()
|
||||
eq(6, eval([[type(luaeval('vim.api.nvim_eval("v:false")'))]]))
|
||||
eq(7, eval([[type(luaeval('vim.api.nvim_eval("v:null")'))]]))
|
||||
|
||||
eq({foo=42}, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]]))
|
||||
eq({42}, funcs.luaeval([[vim.api.nvim_eval('[42]')]]))
|
||||
eq({ foo = 42 }, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]]))
|
||||
eq({ 42 }, funcs.luaeval([[vim.api.nvim_eval('[42]')]]))
|
||||
|
||||
eq({foo={bar=42}, baz=50}, funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]]))
|
||||
eq({{42}, {}}, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=]))
|
||||
eq(
|
||||
{ foo = { bar = 42 }, baz = 50 },
|
||||
funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]])
|
||||
)
|
||||
eq({ { 42 }, {} }, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=]))
|
||||
end)
|
||||
|
||||
it('correctly converts to API objects', function()
|
||||
eq(1, funcs.luaeval('vim.api.nvim__id(1)'))
|
||||
eq('1', funcs.luaeval('vim.api.nvim__id("1")'))
|
||||
eq({1}, funcs.luaeval('vim.api.nvim__id({1})'))
|
||||
eq({foo=1}, funcs.luaeval('vim.api.nvim__id({foo=1})'))
|
||||
eq({ 1 }, funcs.luaeval('vim.api.nvim__id({1})'))
|
||||
eq({ foo = 1 }, funcs.luaeval('vim.api.nvim__id({foo=1})'))
|
||||
eq(1.5, funcs.luaeval('vim.api.nvim__id(1.5)'))
|
||||
eq(true, funcs.luaeval('vim.api.nvim__id(true)'))
|
||||
eq(false, funcs.luaeval('vim.api.nvim__id(false)'))
|
||||
eq(NIL, funcs.luaeval('vim.api.nvim__id(nil)'))
|
||||
|
||||
-- API strings from Blobs can work as NUL-terminated C strings
|
||||
eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
|
||||
exc_exec('call nvim_eval(v:_null_blob)'))
|
||||
eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
|
||||
exc_exec('call nvim_eval(0z)'))
|
||||
eq(
|
||||
'Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
|
||||
exc_exec('call nvim_eval(v:_null_blob)')
|
||||
)
|
||||
eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', exc_exec('call nvim_eval(0z)'))
|
||||
eq(1, eval('nvim_eval(0z31)'))
|
||||
|
||||
eq(0, eval([[type(luaeval('vim.api.nvim__id(1)'))]]))
|
||||
@@ -119,27 +136,56 @@ describe('luaeval(vim.api.…)', function()
|
||||
eq(6, eval([[type(luaeval('vim.api.nvim__id(false)'))]]))
|
||||
eq(7, eval([[type(luaeval('vim.api.nvim__id(nil)'))]]))
|
||||
|
||||
eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})'))
|
||||
eq(
|
||||
{ foo = 1, bar = { 42, { { baz = true }, 5 } } },
|
||||
funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})')
|
||||
)
|
||||
|
||||
eq(true, funcs.luaeval('vim.api.nvim__id(vim.api.nvim__id)(true)'))
|
||||
eq(42, exec_lua [[
|
||||
eq(
|
||||
42,
|
||||
exec_lua [[
|
||||
local f = vim.api.nvim__id({42, vim.api.nvim__id})
|
||||
return f[2](f[1])
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('correctly converts container objects with type_idx to API objects', function()
|
||||
eq(5, eval('type(luaeval("vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))'))
|
||||
eq(
|
||||
5,
|
||||
eval('type(luaeval("vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')
|
||||
)
|
||||
eq(4, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary})'))]]))
|
||||
eq(3, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))]]))
|
||||
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))
|
||||
|
||||
-- Presence of type_idx makes Vim ignore some keys
|
||||
eq({42}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'))
|
||||
eq({foo=2}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'))
|
||||
eq(10, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'))
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})'))
|
||||
eq(
|
||||
{ 42 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ foo = 2 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
10,
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{},
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})'
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('correctly converts arrays with type_idx to API objects', function()
|
||||
@@ -147,24 +193,67 @@ describe('luaeval(vim.api.…)', function()
|
||||
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))
|
||||
|
||||
eq({42}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'))
|
||||
eq({{foo=2}}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'))
|
||||
eq({10}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'))
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})'))
|
||||
eq(
|
||||
{ 42 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ { foo = 2 } },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ 10 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{},
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})'
|
||||
)
|
||||
)
|
||||
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id_array({})'))
|
||||
eq(3, eval([[type(luaeval('vim.api.nvim__id_array({})'))]]))
|
||||
end)
|
||||
|
||||
it('correctly converts dictionaries with type_idx to API objects', function()
|
||||
eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]]))
|
||||
eq(
|
||||
4,
|
||||
eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])
|
||||
)
|
||||
|
||||
eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))
|
||||
|
||||
eq({v={42}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'))
|
||||
eq({foo=2}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'))
|
||||
eq({v=10}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'))
|
||||
eq({v={}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})'))
|
||||
eq(
|
||||
{ v = { 42 } },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ foo = 2 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ v = 10 },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})'
|
||||
)
|
||||
)
|
||||
eq(
|
||||
{ v = {} },
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})'
|
||||
)
|
||||
)
|
||||
|
||||
-- If API requests dictionary, then empty table will be the one. This is not
|
||||
-- the case normally because empty table is an empty array.
|
||||
@@ -173,14 +262,26 @@ describe('luaeval(vim.api.…)', function()
|
||||
end)
|
||||
|
||||
it('converts booleans in positional args', function()
|
||||
eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, false) ]])
|
||||
eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, nil) ]])
|
||||
eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, true) ]]))
|
||||
eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 1) ]]))
|
||||
eq({ '' }, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, false) ]])
|
||||
eq({ '' }, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, nil) ]])
|
||||
eq(
|
||||
'Index out of bounds',
|
||||
pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, true) ]])
|
||||
)
|
||||
eq(
|
||||
'Index out of bounds',
|
||||
pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 1) ]])
|
||||
)
|
||||
|
||||
-- this follows lua conventions for bools (not api convention for Boolean)
|
||||
eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 0) ]]))
|
||||
eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, {}) ]]))
|
||||
eq(
|
||||
'Index out of bounds',
|
||||
pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 0) ]])
|
||||
)
|
||||
eq(
|
||||
'Index out of bounds',
|
||||
pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, {}) ]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('converts booleans in optional args', function()
|
||||
@@ -190,50 +291,92 @@ describe('luaeval(vim.api.…)', function()
|
||||
-- API conventions (not lua conventions): zero is falsy
|
||||
eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=0}) ]])
|
||||
|
||||
eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=true}) ]])
|
||||
eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=1}) ]])
|
||||
eq([[Invalid 'output': not a boolean]], pcall_err(exec_lua, [[ return vim.api.nvim_exec2("echo 'foobar'", {output={}}) ]]))
|
||||
eq(
|
||||
{ output = 'foobar' },
|
||||
exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=true}) ]]
|
||||
)
|
||||
eq({ output = 'foobar' }, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=1}) ]])
|
||||
eq(
|
||||
[[Invalid 'output': not a boolean]],
|
||||
pcall_err(exec_lua, [[ return vim.api.nvim_exec2("echo 'foobar'", {output={}}) ]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('errors out correctly when working with API', function()
|
||||
-- Conversion errors
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
|
||||
)
|
||||
-- Errors in number of arguments
|
||||
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]])))
|
||||
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]])))
|
||||
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 2 arguments',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]])))
|
||||
eq(
|
||||
'Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]]))
|
||||
)
|
||||
eq(
|
||||
'Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]]))
|
||||
)
|
||||
eq(
|
||||
'Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 2 arguments',
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
|
||||
)
|
||||
-- Error in argument types
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'name': Expected Lua string]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'name': Expected Lua string]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
|
||||
)
|
||||
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Number is not integral]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'window': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]]))
|
||||
)
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Number is not integral]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]]))
|
||||
)
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'window': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))
|
||||
)
|
||||
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]]))
|
||||
)
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]],
|
||||
remove_trace(
|
||||
exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])
|
||||
)
|
||||
)
|
||||
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]])))
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]]))
|
||||
)
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]],
|
||||
remove_trace(
|
||||
exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])
|
||||
)
|
||||
)
|
||||
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]])))
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]]))
|
||||
)
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]],
|
||||
remove_trace(
|
||||
exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]])
|
||||
)
|
||||
)
|
||||
|
||||
eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])))
|
||||
eq(
|
||||
[[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua table]],
|
||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))
|
||||
)
|
||||
|
||||
-- TODO: check for errors with Tabpage argument
|
||||
-- TODO: check for errors with Window argument
|
||||
@@ -243,7 +386,12 @@ describe('luaeval(vim.api.…)', function()
|
||||
it('accepts any value as API Boolean', function()
|
||||
eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)'))
|
||||
eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", 0, 1.5, "test")'))
|
||||
eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})'))
|
||||
eq(
|
||||
'',
|
||||
funcs.luaeval(
|
||||
'vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})'
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('serializes sparse arrays in Lua', function()
|
||||
|
||||
@@ -49,12 +49,15 @@ describe('vim.base64', function()
|
||||
end
|
||||
|
||||
-- Explicitly check encoded output
|
||||
eq('VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=', encode('The quick brown fox jumps over the lazy dog\n'))
|
||||
eq(
|
||||
'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=',
|
||||
encode('The quick brown fox jumps over the lazy dog\n')
|
||||
)
|
||||
|
||||
-- Test vectors from rfc4648
|
||||
local rfc4648 = {
|
||||
{ '', '' },
|
||||
{ 'f', 'Zg==', },
|
||||
{ 'f', 'Zg==' },
|
||||
{ 'fo', 'Zm8=' },
|
||||
{ 'foo', 'Zm9v' },
|
||||
{ 'foob', 'Zm9vYg==' },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,34 +5,33 @@ local eq = helpers.eq
|
||||
local exec_lua = helpers.exec_lua
|
||||
|
||||
local get_completions = function(input, env)
|
||||
return exec_lua("return {vim._expand_pat(...)}", input, env)
|
||||
return exec_lua('return {vim._expand_pat(...)}', input, env)
|
||||
end
|
||||
|
||||
local get_compl_parts = function(parts)
|
||||
return exec_lua("return {vim._expand_pat_get_parts(...)}", parts)
|
||||
return exec_lua('return {vim._expand_pat_get_parts(...)}', parts)
|
||||
end
|
||||
|
||||
before_each(clear)
|
||||
|
||||
describe('nlua_expand_pat', function()
|
||||
it('should complete exact matches', function()
|
||||
eq({{'exact'}, 0}, get_completions('exact', { exact = true }))
|
||||
eq({ { 'exact' }, 0 }, get_completions('exact', { exact = true }))
|
||||
end)
|
||||
|
||||
it('should return empty table when nothing matches', function()
|
||||
eq({{}, 0}, get_completions('foo', { bar = true }))
|
||||
eq({ {}, 0 }, get_completions('foo', { bar = true }))
|
||||
end)
|
||||
|
||||
it('should return nice completions with function call prefix', function()
|
||||
eq({{'FOO'}, 6}, get_completions('print(F', { FOO = true, bawr = true }))
|
||||
eq({ { 'FOO' }, 6 }, get_completions('print(F', { FOO = true, bawr = true }))
|
||||
end)
|
||||
|
||||
it('should return keys for nested dictionaries', function()
|
||||
eq(
|
||||
{{
|
||||
{ {
|
||||
'nvim_buf_set_lines',
|
||||
}, 8
|
||||
},
|
||||
}, 8 },
|
||||
get_completions('vim.api.nvim_buf_', {
|
||||
vim = {
|
||||
api = {
|
||||
@@ -40,34 +39,32 @@ describe('nlua_expand_pat', function()
|
||||
nvim_win_doesnt_match = true,
|
||||
},
|
||||
other_key = true,
|
||||
}
|
||||
},
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it('it should work with colons', function()
|
||||
eq(
|
||||
{{
|
||||
{ {
|
||||
'bawr',
|
||||
'baz',
|
||||
}, 8
|
||||
},
|
||||
}, 8 },
|
||||
get_completions('MyClass:b', {
|
||||
MyClass = {
|
||||
baz = true,
|
||||
bawr = true,
|
||||
foo = false,
|
||||
}
|
||||
},
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it('should return keys for string reffed dictionaries', function()
|
||||
eq(
|
||||
{{
|
||||
{ {
|
||||
'nvim_buf_set_lines',
|
||||
}, 11
|
||||
},
|
||||
}, 11 },
|
||||
get_completions('vim["api"].nvim_buf_', {
|
||||
vim = {
|
||||
api = {
|
||||
@@ -75,17 +72,16 @@ describe('nlua_expand_pat', function()
|
||||
nvim_win_doesnt_match = true,
|
||||
},
|
||||
other_key = true,
|
||||
}
|
||||
},
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it('should return keys for string reffed dictionaries', function()
|
||||
eq(
|
||||
{{
|
||||
{ {
|
||||
'nvim_buf_set_lines',
|
||||
}, 21
|
||||
},
|
||||
}, 21 },
|
||||
get_completions('vim["nested"]["api"].nvim_buf_', {
|
||||
vim = {
|
||||
nested = {
|
||||
@@ -95,80 +91,76 @@ describe('nlua_expand_pat', function()
|
||||
},
|
||||
},
|
||||
other_key = true,
|
||||
}
|
||||
},
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it('should work with lazy submodules of "vim" global', function()
|
||||
eq({{ 'inspect', 'inspect_pos' }, 4 },
|
||||
get_completions('vim.inspec'))
|
||||
eq({ { 'inspect', 'inspect_pos' }, 4 }, get_completions('vim.inspec'))
|
||||
|
||||
eq({{ 'treesitter' }, 4 },
|
||||
get_completions('vim.treesi'))
|
||||
eq({ { 'treesitter' }, 4 }, get_completions('vim.treesi'))
|
||||
|
||||
eq({{ 'set' }, 11 },
|
||||
get_completions('vim.keymap.se'))
|
||||
eq({ { 'set' }, 11 }, get_completions('vim.keymap.se'))
|
||||
end)
|
||||
|
||||
it('should be able to interpolate globals', function()
|
||||
eq(
|
||||
{{
|
||||
{ {
|
||||
'nvim_buf_set_lines',
|
||||
}, 12
|
||||
},
|
||||
}, 12 },
|
||||
get_completions('vim[MY_VAR].nvim_buf_', {
|
||||
MY_VAR = "api",
|
||||
MY_VAR = 'api',
|
||||
vim = {
|
||||
api = {
|
||||
nvim_buf_set_lines = true,
|
||||
nvim_win_doesnt_match = true,
|
||||
},
|
||||
other_key = true,
|
||||
}
|
||||
},
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it('should return everything if the input is of length 0', function()
|
||||
eq({{"other", "vim"}, 0}, get_completions('', { vim = true, other = true }))
|
||||
eq({ { 'other', 'vim' }, 0 }, get_completions('', { vim = true, other = true }))
|
||||
end)
|
||||
|
||||
describe('get_parts', function()
|
||||
it('should return an empty list for no separators', function()
|
||||
eq({{}, 1}, get_compl_parts("vim"))
|
||||
eq({ {}, 1 }, get_compl_parts('vim'))
|
||||
end)
|
||||
|
||||
it('just the first item before a period', function()
|
||||
eq({{"vim"}, 5}, get_compl_parts("vim.ap"))
|
||||
eq({ { 'vim' }, 5 }, get_compl_parts('vim.ap'))
|
||||
end)
|
||||
|
||||
it('should return multiple parts just for period', function()
|
||||
eq({{"vim", "api"}, 9}, get_compl_parts("vim.api.nvim_buf"))
|
||||
eq({ { 'vim', 'api' }, 9 }, get_compl_parts('vim.api.nvim_buf'))
|
||||
end)
|
||||
|
||||
it('should be OK with colons', function()
|
||||
eq({{"vim", "api"}, 9}, get_compl_parts("vim:api.nvim_buf"))
|
||||
eq({ { 'vim', 'api' }, 9 }, get_compl_parts('vim:api.nvim_buf'))
|
||||
end)
|
||||
|
||||
it('should work for just one string ref', function()
|
||||
eq({{"vim", "api"}, 12}, get_compl_parts("vim['api'].nvim_buf"))
|
||||
eq({ { 'vim', 'api' }, 12 }, get_compl_parts("vim['api'].nvim_buf"))
|
||||
end)
|
||||
|
||||
it('should work for just one string ref, with double quote', function()
|
||||
eq({{"vim", "api"}, 12}, get_compl_parts('vim["api"].nvim_buf'))
|
||||
eq({ { 'vim', 'api' }, 12 }, get_compl_parts('vim["api"].nvim_buf'))
|
||||
end)
|
||||
|
||||
it('should allows back-to-back string ref', function()
|
||||
eq({{"vim", "nested", "api"}, 22}, get_compl_parts('vim["nested"]["api"].nvim_buf'))
|
||||
eq({ { 'vim', 'nested', 'api' }, 22 }, get_compl_parts('vim["nested"]["api"].nvim_buf'))
|
||||
end)
|
||||
|
||||
it('should allows back-to-back string ref with spaces before and after', function()
|
||||
eq({{"vim", "nested", "api"}, 25}, get_compl_parts('vim[ "nested" ]["api"].nvim_buf'))
|
||||
eq({ { 'vim', 'nested', 'api' }, 25 }, get_compl_parts('vim[ "nested" ]["api"].nvim_buf'))
|
||||
end)
|
||||
|
||||
it('should allow VAR style loolup', function()
|
||||
eq({{"vim", {"NESTED"}, "api"}, 20}, get_compl_parts('vim[NESTED]["api"].nvim_buf'))
|
||||
eq({ { 'vim', { 'NESTED' }, 'api' }, 20 }, get_compl_parts('vim[NESTED]["api"].nvim_buf'))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -25,43 +25,53 @@ before_each(clear)
|
||||
|
||||
describe(':lua command', function()
|
||||
it('works', function()
|
||||
eq('', exec_capture(
|
||||
'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
|
||||
eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false))
|
||||
eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
|
||||
eq({ '', 'TEST' }, curbufmeths.get_lines(0, 100, false))
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
|
||||
EOF]])
|
||||
eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false))
|
||||
eq({ '', 'TSET' }, curbufmeths.get_lines(0, 100, false))
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
|
||||
eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false))
|
||||
eq({ '', 'SETT' }, curbufmeths.get_lines(0, 100, false))
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
|
||||
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
|
||||
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
|
||||
EOF]])
|
||||
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
|
||||
matches('.*Vim%(lua%):E15: Invalid expression: .*', pcall_err(source, [[
|
||||
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false))
|
||||
matches(
|
||||
'.*Vim%(lua%):E15: Invalid expression: .*',
|
||||
pcall_err(
|
||||
source,
|
||||
[[
|
||||
lua << eval EOF
|
||||
{}
|
||||
EOF
|
||||
]]))
|
||||
]]
|
||||
)
|
||||
)
|
||||
end)
|
||||
it('throws catchable errors', function()
|
||||
eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
|
||||
pcall_err(command, 'lua ()'))
|
||||
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]],
|
||||
remove_trace(exc_exec('lua error("TEST")')))
|
||||
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]],
|
||||
remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')))
|
||||
eq({''}, curbufmeths.get_lines(0, 100, false))
|
||||
eq(
|
||||
[[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
|
||||
pcall_err(command, 'lua ()')
|
||||
)
|
||||
eq(
|
||||
[[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]],
|
||||
remove_trace(exc_exec('lua error("TEST")'))
|
||||
)
|
||||
eq(
|
||||
[[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]],
|
||||
remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
|
||||
)
|
||||
eq({ '' }, curbufmeths.get_lines(0, 100, false))
|
||||
end)
|
||||
it('works with NULL errors', function()
|
||||
eq([=[Vim(lua):E5108: Error executing lua [NULL]]=],
|
||||
exc_exec('lua error(nil)'))
|
||||
eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)'))
|
||||
end)
|
||||
it('accepts embedded NLs without heredoc', function()
|
||||
-- Such code is usually used for `:execute 'lua' {generated_string}`:
|
||||
@@ -72,7 +82,7 @@ describe(':lua command', function()
|
||||
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
|
||||
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
|
||||
]])
|
||||
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
|
||||
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false))
|
||||
end)
|
||||
it('preserves global and not preserves local variables', function()
|
||||
eq('', exec_capture('lua gvar = 42'))
|
||||
@@ -83,26 +93,29 @@ describe(':lua command', function()
|
||||
it('works with long strings', function()
|
||||
local s = ('x'):rep(100500)
|
||||
|
||||
eq('Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'',
|
||||
pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)))
|
||||
eq({''}, curbufmeths.get_lines(0, -1, false))
|
||||
eq(
|
||||
'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'',
|
||||
pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s))
|
||||
)
|
||||
eq({ '' }, curbufmeths.get_lines(0, -1, false))
|
||||
|
||||
eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s)))
|
||||
eq({'', s}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ '', s }, curbufmeths.get_lines(0, -1, false))
|
||||
end)
|
||||
|
||||
it('can show multiline error messages', function()
|
||||
local screen = Screen.new(40,10)
|
||||
local screen = Screen.new(40, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
||||
[4] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
[3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
||||
[4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
||||
})
|
||||
|
||||
feed(':lua error("fail\\nmuch error\\nsuch details")<cr>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
{2: }|
|
||||
{3:E5108: Error executing lua [string ":lua}|
|
||||
{3:"]:1: fail} |
|
||||
@@ -113,22 +126,30 @@ describe(':lua command', function()
|
||||
{3: [string ":lua"]:1: in main chunk}|
|
||||
|
|
||||
{4:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('<cr>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*8
|
||||
|
|
||||
]]}
|
||||
eq('E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details', remove_trace(eval('v:errmsg')))
|
||||
]],
|
||||
}
|
||||
eq(
|
||||
'E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details',
|
||||
remove_trace(eval('v:errmsg'))
|
||||
)
|
||||
|
||||
local status, err = pcall(command,'lua error("some error\\nin a\\nAPI command")')
|
||||
local expected = 'Vim(lua):E5108: Error executing lua [string ":lua"]:1: some error\nin a\nAPI command'
|
||||
local status, err = pcall(command, 'lua error("some error\\nin a\\nAPI command")')
|
||||
local expected =
|
||||
'Vim(lua):E5108: Error executing lua [string ":lua"]:1: some error\nin a\nAPI command'
|
||||
eq(false, status)
|
||||
eq(expected, string.sub(remove_trace(err), -string.len(expected)))
|
||||
|
||||
feed(':messages<cr>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
{2: }|
|
||||
{3:E5108: Error executing lua [string ":lua}|
|
||||
{3:"]:1: fail} |
|
||||
@@ -139,17 +160,18 @@ describe(':lua command', function()
|
||||
{3: [string ":lua"]:1: in main chunk}|
|
||||
|
|
||||
{4:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
end)
|
||||
|
||||
it('prints result of =expr', function()
|
||||
exec_lua("x = 5")
|
||||
eq("5", exec_capture(':lua =x'))
|
||||
eq("5", exec_capture('=x'))
|
||||
exec_lua('x = 5')
|
||||
eq('5', exec_capture(':lua =x'))
|
||||
eq('5', exec_capture('=x'))
|
||||
exec_lua("function x() return 'hello' end")
|
||||
eq('hello', exec_capture(':lua = x()'))
|
||||
exec_lua("x = {a = 1, b = 2}")
|
||||
eq("{\n a = 1,\n b = 2\n}", exec_capture(':lua =x'))
|
||||
exec_lua('x = {a = 1, b = 2}')
|
||||
eq('{\n a = 1,\n b = 2\n}', exec_capture(':lua =x'))
|
||||
exec_lua([[function x(success)
|
||||
if success then
|
||||
return true, "Return value"
|
||||
@@ -157,69 +179,82 @@ describe(':lua command', function()
|
||||
return false, nil, "Error message"
|
||||
end
|
||||
end]])
|
||||
eq(dedent[[
|
||||
eq(
|
||||
dedent [[
|
||||
true
|
||||
Return value]],
|
||||
exec_capture(':lua =x(true)'))
|
||||
eq(dedent[[
|
||||
exec_capture(':lua =x(true)')
|
||||
)
|
||||
eq(
|
||||
dedent [[
|
||||
false
|
||||
nil
|
||||
Error message]],
|
||||
exec_capture('=x(false)'))
|
||||
exec_capture('=x(false)')
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe(':luado command', function()
|
||||
it('works', function()
|
||||
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
|
||||
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' })
|
||||
eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}'))
|
||||
eq({'ABC', 'def', 'gHi'}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({{1, 'ABC'}, {2, 'def'}, {3, 'gHi'}}, funcs.luaeval('lines'))
|
||||
eq({ 'ABC', 'def', 'gHi' }, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines'))
|
||||
|
||||
-- Automatic transformation of numbers
|
||||
eq('', exec_capture('luado return linenr'))
|
||||
eq({'1', '2', '3'}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ '1', '2', '3' }, curbufmeths.get_lines(0, -1, false))
|
||||
|
||||
eq('', exec_capture('luado return ("<%02x>"):format(line:byte())'))
|
||||
eq({'<31>', '<32>', '<33>'}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ '<31>', '<32>', '<33>' }, curbufmeths.get_lines(0, -1, false))
|
||||
end)
|
||||
it('stops processing lines when suddenly out of lines', function()
|
||||
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
|
||||
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' })
|
||||
eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")'))
|
||||
eq({''}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ '' }, curbufmeths.get_lines(0, -1, false))
|
||||
eq(1, funcs.luaeval('runs'))
|
||||
end)
|
||||
it('works correctly when changing lines out of range', function()
|
||||
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
|
||||
eq('Vim(luado):E322: Line number out of range: 1 past the end',
|
||||
pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr'))
|
||||
eq({''}, curbufmeths.get_lines(0, -1, false))
|
||||
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' })
|
||||
eq(
|
||||
'Vim(luado):E322: Line number out of range: 1 past the end',
|
||||
pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr')
|
||||
)
|
||||
eq({ '' }, curbufmeths.get_lines(0, -1, false))
|
||||
end)
|
||||
it('fails on errors', function()
|
||||
eq([[Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unexpected symbol near ')']],
|
||||
pcall_err(command, 'luado ()'))
|
||||
eq([[Vim(luado):E5111: Error calling lua: [string ":luado"]:0: attempt to perform arithmetic on global 'liness' (a nil value)]],
|
||||
pcall_err(command, 'luado return liness + 1'))
|
||||
eq(
|
||||
[[Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unexpected symbol near ')']],
|
||||
pcall_err(command, 'luado ()')
|
||||
)
|
||||
eq(
|
||||
[[Vim(luado):E5111: Error calling lua: [string ":luado"]:0: attempt to perform arithmetic on global 'liness' (a nil value)]],
|
||||
pcall_err(command, 'luado return liness + 1')
|
||||
)
|
||||
end)
|
||||
it('works with NULL errors', function()
|
||||
eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=],
|
||||
exc_exec('luado error(nil)'))
|
||||
eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)'))
|
||||
end)
|
||||
it('fails in sandbox when needed', function()
|
||||
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
|
||||
eq('Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1',
|
||||
pcall_err(command, 'sandbox luado runs = (runs or 0) + 1'))
|
||||
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' })
|
||||
eq(
|
||||
'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1',
|
||||
pcall_err(command, 'sandbox luado runs = (runs or 0) + 1')
|
||||
)
|
||||
eq(NIL, funcs.luaeval('runs'))
|
||||
end)
|
||||
it('works with long strings', function()
|
||||
local s = ('x'):rep(100500)
|
||||
|
||||
eq('Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'',
|
||||
pcall_err(command, ('luado return "%s'):format(s)))
|
||||
eq({''}, curbufmeths.get_lines(0, -1, false))
|
||||
eq(
|
||||
'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'',
|
||||
pcall_err(command, ('luado return "%s'):format(s))
|
||||
)
|
||||
eq({ '' }, curbufmeths.get_lines(0, -1, false))
|
||||
|
||||
eq('', exec_capture(('luado return "%s"'):format(s)))
|
||||
eq({s}, curbufmeths.get_lines(0, -1, false))
|
||||
eq({ s }, curbufmeths.get_lines(0, -1, false))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -231,26 +266,39 @@ describe(':luafile', function()
|
||||
end)
|
||||
|
||||
it('works', function()
|
||||
write_file(fname, [[
|
||||
write_file(
|
||||
fname,
|
||||
[[
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
|
||||
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
|
||||
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
|
||||
]])
|
||||
]]
|
||||
)
|
||||
eq('', exec_capture('luafile ' .. fname))
|
||||
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
|
||||
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false))
|
||||
end)
|
||||
|
||||
it('correctly errors out', function()
|
||||
write_file(fname, '()')
|
||||
eq(("Vim(luafile):E5112: Error while creating lua chunk: %s:1: unexpected symbol near ')'"):format(fname),
|
||||
exc_exec('luafile ' .. fname))
|
||||
eq(
|
||||
("Vim(luafile):E5112: Error while creating lua chunk: %s:1: unexpected symbol near ')'"):format(
|
||||
fname
|
||||
),
|
||||
exc_exec('luafile ' .. fname)
|
||||
)
|
||||
write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})')
|
||||
eq(("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(fname),
|
||||
remove_trace(exc_exec('luafile ' .. fname)))
|
||||
eq(
|
||||
("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(
|
||||
fname
|
||||
),
|
||||
remove_trace(exc_exec('luafile ' .. fname))
|
||||
)
|
||||
end)
|
||||
it('works with NULL errors', function()
|
||||
write_file(fname, 'error(nil)')
|
||||
eq([=[Vim(luafile):E5113: Error while calling lua chunk: [NULL]]=],
|
||||
exc_exec('luafile ' .. fname))
|
||||
eq(
|
||||
[=[Vim(luafile):E5113: Error while calling lua chunk: [NULL]]=],
|
||||
exc_exec('luafile ' .. fname)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,9 @@ describe('ffi.cdef', function()
|
||||
pending('missing LuaJIT FFI')
|
||||
end
|
||||
|
||||
eq(12, exec_lua[[
|
||||
eq(
|
||||
12,
|
||||
exec_lua [[
|
||||
local ffi = require('ffi')
|
||||
|
||||
ffi.cdef('int curwin_col_off(void);')
|
||||
@@ -19,9 +21,12 @@ describe('ffi.cdef', function()
|
||||
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
|
||||
|
||||
return ffi.C.curwin_col_off()
|
||||
]])
|
||||
]]
|
||||
)
|
||||
|
||||
eq(20, exec_lua[=[
|
||||
eq(
|
||||
20,
|
||||
exec_lua [=[
|
||||
local ffi = require('ffi')
|
||||
|
||||
ffi.cdef[[
|
||||
@@ -61,15 +66,19 @@ describe('ffi.cdef', function()
|
||||
nil,
|
||||
nil
|
||||
)
|
||||
]=])
|
||||
]=]
|
||||
)
|
||||
|
||||
-- Check that extern symbols are exported and accessible
|
||||
eq(true, exec_lua[[
|
||||
eq(
|
||||
true,
|
||||
exec_lua [[
|
||||
local ffi = require('ffi')
|
||||
|
||||
ffi.cdef('uint64_t display_tick;')
|
||||
|
||||
return ffi.C.display_tick >= 0
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -19,18 +19,23 @@ describe('vim.filetype', function()
|
||||
end)
|
||||
|
||||
it('works with extensions', function()
|
||||
eq('radicalscript', exec_lua [[
|
||||
eq(
|
||||
'radicalscript',
|
||||
exec_lua [[
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
rs = 'radicalscript',
|
||||
},
|
||||
})
|
||||
return vim.filetype.match({ filename = 'main.rs' })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('prioritizes filenames over extensions', function()
|
||||
eq('somethingelse', exec_lua [[
|
||||
eq(
|
||||
'somethingelse',
|
||||
exec_lua [[
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
rs = 'radicalscript',
|
||||
@@ -40,20 +45,27 @@ describe('vim.filetype', function()
|
||||
},
|
||||
})
|
||||
return vim.filetype.match({ filename = 'main.rs' })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with filenames', function()
|
||||
eq('nim', exec_lua [[
|
||||
eq(
|
||||
'nim',
|
||||
exec_lua [[
|
||||
vim.filetype.add({
|
||||
filename = {
|
||||
['s_O_m_e_F_i_l_e'] = 'nim',
|
||||
},
|
||||
})
|
||||
return vim.filetype.match({ filename = 's_O_m_e_F_i_l_e' })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
|
||||
eq('dosini', exec_lua([[
|
||||
eq(
|
||||
'dosini',
|
||||
exec_lua(
|
||||
[[
|
||||
local root = ...
|
||||
vim.filetype.add({
|
||||
filename = {
|
||||
@@ -62,11 +74,17 @@ describe('vim.filetype', function()
|
||||
},
|
||||
})
|
||||
return vim.filetype.match({ filename = root .. '/.config/fun/config' })
|
||||
]], root))
|
||||
]],
|
||||
root
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with patterns', function()
|
||||
eq('markdown', exec_lua([[
|
||||
eq(
|
||||
'markdown',
|
||||
exec_lua(
|
||||
[[
|
||||
local root = ...
|
||||
vim.env.HOME = '/a-funky+home%dir'
|
||||
vim.filetype.add({
|
||||
@@ -75,13 +93,18 @@ describe('vim.filetype', function()
|
||||
}
|
||||
})
|
||||
return vim.filetype.match({ filename = '~/blog/why_neovim_is_awesome.txt' })
|
||||
]], root))
|
||||
]],
|
||||
root
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with functions', function()
|
||||
command('new')
|
||||
command('file relevant_to_me')
|
||||
eq('foss', exec_lua [[
|
||||
eq(
|
||||
'foss',
|
||||
exec_lua [[
|
||||
vim.filetype.add({
|
||||
pattern = {
|
||||
["relevant_to_(%a+)"] = function(path, bufnr, capture)
|
||||
@@ -92,26 +115,33 @@ describe('vim.filetype', function()
|
||||
}
|
||||
})
|
||||
return vim.filetype.match({ buf = 0 })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with contents #22180', function()
|
||||
eq('sh', exec_lua [[
|
||||
eq(
|
||||
'sh',
|
||||
exec_lua [[
|
||||
-- Needs to be set so detect#sh doesn't fail
|
||||
vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
|
||||
return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('considers extension mappings when matching from hashbang', function()
|
||||
eq('fooscript', exec_lua [[
|
||||
eq(
|
||||
'fooscript',
|
||||
exec_lua [[
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
foo = 'fooscript',
|
||||
}
|
||||
})
|
||||
return vim.filetype.match({ contents = { '#!/usr/bin/env foo' } })
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('can get default option values for filetypes via vim.filetype.get_option()', function()
|
||||
@@ -120,20 +150,21 @@ describe('vim.filetype', function()
|
||||
for ft, opts in pairs {
|
||||
lua = { commentstring = '-- %s' },
|
||||
vim = { commentstring = '"%s' },
|
||||
man = { tagfunc = 'v:lua.require\'man\'.goto_tag' },
|
||||
xml = { formatexpr = 'xmlformat#Format()' }
|
||||
man = { tagfunc = "v:lua.require'man'.goto_tag" },
|
||||
xml = { formatexpr = 'xmlformat#Format()' },
|
||||
} do
|
||||
for option, value in pairs(opts) do
|
||||
eq(value, exec_lua([[ return vim.filetype.get_option(...) ]], ft, option))
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('filetype.lua', function()
|
||||
it('does not override user autocommands that set filetype #20333', function()
|
||||
clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}})
|
||||
clear({
|
||||
args = { '--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md' },
|
||||
})
|
||||
eq('notmarkdown', meths.get_option_value('filetype', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -56,13 +56,13 @@ describe('vim.fs', function()
|
||||
local test_dir = nvim_dir .. '/test'
|
||||
mkdir_p(test_dir)
|
||||
local dirs = {}
|
||||
for dir in vim.fs.parents(test_dir .. "/foo.txt") do
|
||||
for dir in vim.fs.parents(test_dir .. '/foo.txt') do
|
||||
dirs[#dirs + 1] = dir
|
||||
if dir == test_build_dir then
|
||||
break
|
||||
end
|
||||
end
|
||||
eq({test_dir, nvim_dir, test_build_dir}, dirs)
|
||||
eq({ test_dir, nvim_dir, test_build_dir }, dirs)
|
||||
rmdir(test_dir)
|
||||
end)
|
||||
end)
|
||||
@@ -74,11 +74,15 @@ describe('vim.fs', function()
|
||||
local function test_paths(paths)
|
||||
for _, path in ipairs(paths) do
|
||||
eq(
|
||||
exec_lua([[
|
||||
exec_lua(
|
||||
[[
|
||||
local path = ...
|
||||
return vim.fn.fnamemodify(path,':h'):gsub('\\', '/')
|
||||
]], path),
|
||||
vim.fs.dirname(path), path
|
||||
]],
|
||||
path
|
||||
),
|
||||
vim.fs.dirname(path),
|
||||
path
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -97,10 +101,15 @@ describe('vim.fs', function()
|
||||
local function test_paths(paths)
|
||||
for _, path in ipairs(paths) do
|
||||
eq(
|
||||
exec_lua([[
|
||||
exec_lua(
|
||||
[[
|
||||
local path = ...
|
||||
return vim.fn.fnamemodify(path,':t'):gsub('\\', '/')
|
||||
]], path), vim.fs.basename(path), path
|
||||
]],
|
||||
path
|
||||
),
|
||||
vim.fs.basename(path),
|
||||
path
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -125,7 +134,10 @@ describe('vim.fs', function()
|
||||
end)
|
||||
|
||||
it('works', function()
|
||||
eq(true, exec_lua([[
|
||||
eq(
|
||||
true,
|
||||
exec_lua(
|
||||
[[
|
||||
local dir, nvim = ...
|
||||
for name, type in vim.fs.dir(dir) do
|
||||
if name == nvim and type == 'file' then
|
||||
@@ -133,7 +145,11 @@ describe('vim.fs', function()
|
||||
end
|
||||
end
|
||||
return false
|
||||
]], nvim_dir, nvim_prog_basename))
|
||||
]],
|
||||
nvim_dir,
|
||||
nvim_prog_basename
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with opts.depth and opts.skip', function()
|
||||
@@ -151,7 +167,8 @@ describe('vim.fs', function()
|
||||
io.open('testd/a/b/c/c4', 'w'):close()
|
||||
|
||||
local function run(dir, depth, skip)
|
||||
local r = exec_lua([[
|
||||
local r = exec_lua(
|
||||
[[
|
||||
local dir, depth, skip = ...
|
||||
local r = {}
|
||||
local skip_f
|
||||
@@ -166,7 +183,11 @@ describe('vim.fs', function()
|
||||
r[name] = type_
|
||||
end
|
||||
return r
|
||||
]], dir, depth, skip)
|
||||
]],
|
||||
dir,
|
||||
depth,
|
||||
skip
|
||||
)
|
||||
return r
|
||||
end
|
||||
|
||||
@@ -192,7 +213,7 @@ describe('vim.fs', function()
|
||||
exp['a/b/c'] = 'directory'
|
||||
|
||||
eq(exp, run('testd', 3))
|
||||
eq(exp, run('testd', 999, {'a/b/c'}))
|
||||
eq(exp, run('testd', 999, { 'a/b/c' }))
|
||||
|
||||
exp['a/b/c/a4'] = 'file'
|
||||
exp['a/b/c/b4'] = 'file'
|
||||
@@ -204,27 +225,53 @@ describe('vim.fs', function()
|
||||
|
||||
describe('find()', function()
|
||||
it('works', function()
|
||||
eq({test_build_dir .. "/build"}, vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' }))
|
||||
eq({nvim_prog}, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' }))
|
||||
eq(
|
||||
{ test_build_dir .. '/build' },
|
||||
vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' })
|
||||
)
|
||||
eq({ nvim_prog }, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' }))
|
||||
|
||||
local parent, name = nvim_dir:match('^(.*/)([^/]+)$')
|
||||
eq({nvim_dir}, vim.fs.find(name, { path = parent, upward = true, type = 'directory' }))
|
||||
eq({ nvim_dir }, vim.fs.find(name, { path = parent, upward = true, type = 'directory' }))
|
||||
end)
|
||||
|
||||
it('accepts predicate as names', function()
|
||||
local opts = { path = nvim_dir, upward = true, type = 'directory' }
|
||||
eq({test_build_dir .. "/build"}, vim.fs.find(function(x) return x == 'build' end, opts))
|
||||
eq({nvim_prog}, vim.fs.find(function(x) return x == nvim_prog_basename end, { path = test_build_dir, type = 'file' }))
|
||||
eq({}, vim.fs.find(function(x) return x == 'no-match' end, opts))
|
||||
|
||||
opts = { path = test_source_path .. "/contrib", limit = math.huge }
|
||||
eq(
|
||||
exec_lua([[
|
||||
{ test_build_dir .. '/build' },
|
||||
vim.fs.find(function(x)
|
||||
return x == 'build'
|
||||
end, opts)
|
||||
)
|
||||
eq(
|
||||
{ nvim_prog },
|
||||
vim.fs.find(function(x)
|
||||
return x == nvim_prog_basename
|
||||
end, { path = test_build_dir, type = 'file' })
|
||||
)
|
||||
eq(
|
||||
{},
|
||||
vim.fs.find(function(x)
|
||||
return x == 'no-match'
|
||||
end, opts)
|
||||
)
|
||||
|
||||
opts = { path = test_source_path .. '/contrib', limit = math.huge }
|
||||
eq(
|
||||
exec_lua(
|
||||
[[
|
||||
local dir = ...
|
||||
return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true))
|
||||
]], test_source_path),
|
||||
vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts))
|
||||
]],
|
||||
test_source_path
|
||||
),
|
||||
vim.tbl_map(
|
||||
vim.fs.basename,
|
||||
vim.fs.find(function(_, d)
|
||||
return d:match('[\\/]contrib$')
|
||||
end, opts)
|
||||
)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -250,10 +297,16 @@ describe('vim.fs', function()
|
||||
end)
|
||||
it('works with environment variables', function()
|
||||
local xdg_config_home = test_build_dir .. '/.config'
|
||||
eq(xdg_config_home .. '/nvim', exec_lua([[
|
||||
eq(
|
||||
xdg_config_home .. '/nvim',
|
||||
exec_lua(
|
||||
[[
|
||||
vim.env.XDG_CONFIG_HOME = ...
|
||||
return vim.fs.normalize('$XDG_CONFIG_HOME/nvim')
|
||||
]], xdg_config_home))
|
||||
]],
|
||||
xdg_config_home
|
||||
)
|
||||
)
|
||||
end)
|
||||
if is_os('win') then
|
||||
it('Last slash is not truncated from root drive', function()
|
||||
|
||||
@@ -7,11 +7,14 @@ describe('glob', function()
|
||||
after_each(helpers.clear)
|
||||
|
||||
local match = function(...)
|
||||
return exec_lua([[
|
||||
return exec_lua(
|
||||
[[
|
||||
local pattern = select(1, ...)
|
||||
local str = select(2, ...)
|
||||
return require("vim.glob").to_lpeg(pattern):match(str) ~= nil
|
||||
]], ...)
|
||||
]],
|
||||
...
|
||||
)
|
||||
end
|
||||
|
||||
describe('glob matching', function()
|
||||
|
||||
@@ -8,7 +8,9 @@ local exec_lua = helpers.exec_lua
|
||||
local eq = helpers.eq
|
||||
local ok = helpers.ok
|
||||
|
||||
if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then return end
|
||||
if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then
|
||||
return
|
||||
end
|
||||
|
||||
describe(':help docs', function()
|
||||
before_each(clear)
|
||||
@@ -23,10 +25,14 @@ describe(':help docs', function()
|
||||
ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles)
|
||||
|
||||
eq({}, rv.parse_errors, 'no parse errors')
|
||||
eq(0, rv.err_count, 'no parse errors')
|
||||
eq(0, rv.err_count, 'no parse errors')
|
||||
eq({}, rv.invalid_links, 'invalid tags in :help docs')
|
||||
eq({}, rv.invalid_urls, 'invalid URLs in :help docs')
|
||||
eq({}, rv.invalid_spelling, 'invalid spelling in :help docs (see spell_dict in scripts/gen_help_html.lua)')
|
||||
eq(
|
||||
{},
|
||||
rv.invalid_spelling,
|
||||
'invalid spelling in :help docs (see spell_dict in scripts/gen_help_html.lua)'
|
||||
)
|
||||
end)
|
||||
|
||||
it('gen_help_html.lua generates HTML', function()
|
||||
@@ -36,7 +42,8 @@ describe(':help docs', function()
|
||||
|
||||
local tmpdir = exec_lua('return vim.fs.dirname(vim.fn.tempname())')
|
||||
-- Because gen() is slow (~30s), this test is limited to a few files.
|
||||
local rv = exec_lua([[
|
||||
local rv = exec_lua(
|
||||
[[
|
||||
local to_dir = ...
|
||||
return require('scripts.gen_help_html').gen(
|
||||
'./build/runtime/doc',
|
||||
|
||||
@@ -46,9 +46,9 @@ describe('vim.inspect_pos', function()
|
||||
hl_group_link = 'Normal',
|
||||
ns_id = 1,
|
||||
priority = 4096,
|
||||
right_gravity = true
|
||||
right_gravity = true,
|
||||
},
|
||||
row = 0
|
||||
row = 0,
|
||||
},
|
||||
{
|
||||
col = 10,
|
||||
@@ -63,10 +63,10 @@ describe('vim.inspect_pos', function()
|
||||
hl_group_link = 'Normal',
|
||||
ns_id = 2,
|
||||
priority = 4096,
|
||||
right_gravity = true
|
||||
right_gravity = true,
|
||||
},
|
||||
row = 0
|
||||
}
|
||||
row = 0,
|
||||
},
|
||||
},
|
||||
treesitter = {},
|
||||
semantic_tokens = {},
|
||||
|
||||
@@ -6,11 +6,11 @@ local pcall_err = helpers.pcall_err
|
||||
describe('vim.iter', function()
|
||||
it('new() on iterable class instance', function()
|
||||
local rb = vim.ringbuf(3)
|
||||
rb:push("a")
|
||||
rb:push("b")
|
||||
rb:push('a')
|
||||
rb:push('b')
|
||||
|
||||
local it = vim.iter(rb)
|
||||
eq({"a", "b"}, it:totable())
|
||||
eq({ 'a', 'b' }, it:totable())
|
||||
end)
|
||||
|
||||
it('filter()', function()
|
||||
@@ -20,18 +20,43 @@ describe('vim.iter', function()
|
||||
|
||||
local t = { 1, 2, 3, 4, 5 }
|
||||
eq({ 1, 3, 5 }, vim.iter(t):filter(odd):totable())
|
||||
eq({ 2, 4 }, vim.iter(t):filter(function(v) return not odd(v) end):totable())
|
||||
eq({}, vim.iter(t):filter(function(v) return v > 5 end):totable())
|
||||
eq(
|
||||
{ 2, 4 },
|
||||
vim
|
||||
.iter(t)
|
||||
:filter(function(v)
|
||||
return not odd(v)
|
||||
end)
|
||||
:totable()
|
||||
)
|
||||
eq(
|
||||
{},
|
||||
vim
|
||||
.iter(t)
|
||||
:filter(function(v)
|
||||
return v > 5
|
||||
end)
|
||||
:totable()
|
||||
)
|
||||
|
||||
do
|
||||
local it = vim.iter(ipairs(t))
|
||||
it:filter(function(i, v) return i > 1 and v < 5 end)
|
||||
it:map(function(_, v) return v * 2 end)
|
||||
it:filter(function(i, v)
|
||||
return i > 1 and v < 5
|
||||
end)
|
||||
it:map(function(_, v)
|
||||
return v * 2
|
||||
end)
|
||||
eq({ 4, 6, 8 }, it:totable())
|
||||
end
|
||||
|
||||
local it = vim.iter(string.gmatch('the quick brown fox', '%w+'))
|
||||
eq({'the', 'fox'}, it:filter(function(s) return #s <= 3 end):totable())
|
||||
eq(
|
||||
{ 'the', 'fox' },
|
||||
it:filter(function(s)
|
||||
return #s <= 3
|
||||
end):totable()
|
||||
)
|
||||
end)
|
||||
|
||||
it('map()', function()
|
||||
@@ -39,11 +64,11 @@ describe('vim.iter', function()
|
||||
eq(
|
||||
{ 2, 4, 6, 8, 10 },
|
||||
vim
|
||||
.iter(t)
|
||||
:map(function(v)
|
||||
return 2 * v
|
||||
end)
|
||||
:totable()
|
||||
.iter(t)
|
||||
:map(function(v)
|
||||
return 2 * v
|
||||
end)
|
||||
:totable()
|
||||
)
|
||||
|
||||
local it = vim.gsplit(
|
||||
@@ -59,21 +84,25 @@ describe('vim.iter', function()
|
||||
eq(
|
||||
{ 'Lion 2', 'Lion 4' },
|
||||
vim
|
||||
.iter(it)
|
||||
:map(function(s)
|
||||
local lnum = s:match('(%d+)')
|
||||
if lnum and tonumber(lnum) % 2 == 0 then
|
||||
return vim.trim(s:gsub('Line', 'Lion'))
|
||||
end
|
||||
end)
|
||||
:totable()
|
||||
.iter(it)
|
||||
:map(function(s)
|
||||
local lnum = s:match('(%d+)')
|
||||
if lnum and tonumber(lnum) % 2 == 0 then
|
||||
return vim.trim(s:gsub('Line', 'Lion'))
|
||||
end
|
||||
end)
|
||||
:totable()
|
||||
)
|
||||
end)
|
||||
|
||||
it('for loops', function()
|
||||
local t = {1, 2, 3, 4, 5}
|
||||
local t = { 1, 2, 3, 4, 5 }
|
||||
local acc = 0
|
||||
for v in vim.iter(t):map(function(v) return v * 3 end) do
|
||||
for v in
|
||||
vim.iter(t):map(function(v)
|
||||
return v * 3
|
||||
end)
|
||||
do
|
||||
acc = acc + v
|
||||
end
|
||||
eq(45, acc)
|
||||
@@ -81,23 +110,27 @@ describe('vim.iter', function()
|
||||
|
||||
it('totable()', function()
|
||||
do
|
||||
local it = vim.iter({1, 2, 3}):map(function(v) return v, v*v end)
|
||||
eq({{1, 1}, {2, 4}, {3, 9}}, it:totable())
|
||||
local it = vim.iter({ 1, 2, 3 }):map(function(v)
|
||||
return v, v * v
|
||||
end)
|
||||
eq({ { 1, 1 }, { 2, 4 }, { 3, 9 } }, it:totable())
|
||||
end
|
||||
|
||||
do
|
||||
local it = vim.iter(string.gmatch('1,4,lol,17,blah,2,9,3', '%d+')):map(tonumber)
|
||||
eq({1, 4, 17, 2, 9, 3}, it:totable())
|
||||
eq({ 1, 4, 17, 2, 9, 3 }, it:totable())
|
||||
end
|
||||
end)
|
||||
|
||||
it('join()', function()
|
||||
eq('1, 2, 3', vim.iter({1, 2, 3}):join(', '))
|
||||
eq('1, 2, 3', vim.iter({ 1, 2, 3 }):join(', '))
|
||||
eq('a|b|c|d', vim.iter(vim.gsplit('a|b|c|d', '|')):join('|'))
|
||||
end)
|
||||
|
||||
it('next()', function()
|
||||
local it = vim.iter({1, 2, 3}):map(function(v) return 2 * v end)
|
||||
local it = vim.iter({ 1, 2, 3 }):map(function(v)
|
||||
return 2 * v
|
||||
end)
|
||||
eq(2, it:next())
|
||||
eq(4, it:next())
|
||||
eq(6, it:next())
|
||||
@@ -105,19 +138,19 @@ describe('vim.iter', function()
|
||||
end)
|
||||
|
||||
it('rev()', function()
|
||||
eq({3, 2, 1}, vim.iter({1, 2, 3}):rev():totable())
|
||||
eq({ 3, 2, 1 }, vim.iter({ 1, 2, 3 }):rev():totable())
|
||||
|
||||
local it = vim.iter(string.gmatch("abc", "%w"))
|
||||
local it = vim.iter(string.gmatch('abc', '%w'))
|
||||
matches('rev%(%) requires a list%-like table', pcall_err(it.rev, it))
|
||||
end)
|
||||
|
||||
it('skip()', function()
|
||||
do
|
||||
local t = {4, 3, 2, 1}
|
||||
local t = { 4, 3, 2, 1 }
|
||||
eq(t, vim.iter(t):skip(0):totable())
|
||||
eq({3, 2, 1}, vim.iter(t):skip(1):totable())
|
||||
eq({2, 1}, vim.iter(t):skip(2):totable())
|
||||
eq({1}, vim.iter(t):skip(#t - 1):totable())
|
||||
eq({ 3, 2, 1 }, vim.iter(t):skip(1):totable())
|
||||
eq({ 2, 1 }, vim.iter(t):skip(2):totable())
|
||||
eq({ 1 }, vim.iter(t):skip(#t - 1):totable())
|
||||
eq({}, vim.iter(t):skip(#t):totable())
|
||||
eq({}, vim.iter(t):skip(#t + 1):totable())
|
||||
end
|
||||
@@ -126,10 +159,10 @@ describe('vim.iter', function()
|
||||
local function skip(n)
|
||||
return vim.iter(vim.gsplit('a|b|c|d', '|')):skip(n):totable()
|
||||
end
|
||||
eq({'a', 'b', 'c', 'd'}, skip(0))
|
||||
eq({'b', 'c', 'd'}, skip(1))
|
||||
eq({'c', 'd'}, skip(2))
|
||||
eq({'d'}, skip(3))
|
||||
eq({ 'a', 'b', 'c', 'd' }, skip(0))
|
||||
eq({ 'b', 'c', 'd' }, skip(1))
|
||||
eq({ 'c', 'd' }, skip(2))
|
||||
eq({ 'd' }, skip(3))
|
||||
eq({}, skip(4))
|
||||
eq({}, skip(5))
|
||||
end
|
||||
@@ -137,11 +170,11 @@ describe('vim.iter', function()
|
||||
|
||||
it('skipback()', function()
|
||||
do
|
||||
local t = {4, 3, 2, 1}
|
||||
local t = { 4, 3, 2, 1 }
|
||||
eq(t, vim.iter(t):skipback(0):totable())
|
||||
eq({4, 3, 2}, vim.iter(t):skipback(1):totable())
|
||||
eq({4, 3}, vim.iter(t):skipback(2):totable())
|
||||
eq({4}, vim.iter(t):skipback(#t - 1):totable())
|
||||
eq({ 4, 3, 2 }, vim.iter(t):skipback(1):totable())
|
||||
eq({ 4, 3 }, vim.iter(t):skipback(2):totable())
|
||||
eq({ 4 }, vim.iter(t):skipback(#t - 1):totable())
|
||||
eq({}, vim.iter(t):skipback(#t):totable())
|
||||
eq({}, vim.iter(t):skipback(#t + 1):totable())
|
||||
end
|
||||
@@ -151,14 +184,14 @@ describe('vim.iter', function()
|
||||
end)
|
||||
|
||||
it('slice()', function()
|
||||
local t = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
eq({3, 4, 5, 6, 7}, vim.iter(t):slice(3, 7):totable())
|
||||
local t = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
|
||||
eq({ 3, 4, 5, 6, 7 }, vim.iter(t):slice(3, 7):totable())
|
||||
eq({}, vim.iter(t):slice(6, 5):totable())
|
||||
eq({}, vim.iter(t):slice(0, 0):totable())
|
||||
eq({1}, vim.iter(t):slice(1, 1):totable())
|
||||
eq({1, 2}, vim.iter(t):slice(1, 2):totable())
|
||||
eq({10}, vim.iter(t):slice(10, 10):totable())
|
||||
eq({8, 9, 10}, vim.iter(t):slice(8, 11):totable())
|
||||
eq({ 1 }, vim.iter(t):slice(1, 1):totable())
|
||||
eq({ 1, 2 }, vim.iter(t):slice(1, 2):totable())
|
||||
eq({ 10 }, vim.iter(t):slice(10, 10):totable())
|
||||
eq({ 8, 9, 10 }, vim.iter(t):slice(8, 11):totable())
|
||||
|
||||
local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
|
||||
matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3))
|
||||
@@ -166,7 +199,7 @@ describe('vim.iter', function()
|
||||
|
||||
it('nth()', function()
|
||||
do
|
||||
local t = {4, 3, 2, 1}
|
||||
local t = { 4, 3, 2, 1 }
|
||||
eq(nil, vim.iter(t):nth(0))
|
||||
eq(4, vim.iter(t):nth(1))
|
||||
eq(3, vim.iter(t):nth(2))
|
||||
@@ -190,7 +223,7 @@ describe('vim.iter', function()
|
||||
|
||||
it('nthback()', function()
|
||||
do
|
||||
local t = {4, 3, 2, 1}
|
||||
local t = { 4, 3, 2, 1 }
|
||||
eq(nil, vim.iter(t):nthback(0))
|
||||
eq(1, vim.iter(t):nthback(1))
|
||||
eq(2, vim.iter(t):nthback(2))
|
||||
@@ -246,8 +279,18 @@ describe('vim.iter', function()
|
||||
end
|
||||
|
||||
do
|
||||
eq(true, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'd' end))
|
||||
eq(false, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'e' end))
|
||||
eq(
|
||||
true,
|
||||
vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s)
|
||||
return s == 'd'
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
false,
|
||||
vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s)
|
||||
return s == 'e'
|
||||
end)
|
||||
)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -267,8 +310,18 @@ describe('vim.iter', function()
|
||||
end
|
||||
|
||||
do
|
||||
eq(true, vim.iter(vim.gsplit('a|a|a|a', '|')):all(function(s) return s == 'a' end))
|
||||
eq(false, vim.iter(vim.gsplit('a|a|a|b', '|')):all(function(s) return s == 'a' end))
|
||||
eq(
|
||||
true,
|
||||
vim.iter(vim.gsplit('a|a|a|a', '|')):all(function(s)
|
||||
return s == 'a'
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
false,
|
||||
vim.iter(vim.gsplit('a|a|a|b', '|')):all(function(s)
|
||||
return s == 'a'
|
||||
end)
|
||||
)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -280,10 +333,10 @@ describe('vim.iter', function()
|
||||
|
||||
it('enumerate()', function()
|
||||
local it = vim.iter(vim.gsplit('abc', '')):enumerate()
|
||||
eq({1, 'a'}, {it:next()})
|
||||
eq({2, 'b'}, {it:next()})
|
||||
eq({3, 'c'}, {it:next()})
|
||||
eq({}, {it:next()})
|
||||
eq({ 1, 'a' }, { it:next() })
|
||||
eq({ 2, 'b' }, { it:next() })
|
||||
eq({ 3, 'c' }, { it:next() })
|
||||
eq({}, { it:next() })
|
||||
end)
|
||||
|
||||
it('peek()', function()
|
||||
@@ -301,14 +354,21 @@ describe('vim.iter', function()
|
||||
end)
|
||||
|
||||
it('find()', function()
|
||||
local t = {3, 6, 9, 12}
|
||||
local t = { 3, 6, 9, 12 }
|
||||
eq(12, vim.iter(t):find(12))
|
||||
eq(nil, vim.iter(t):find(15))
|
||||
eq(12, vim.iter(t):find(function(v) return v % 4 == 0 end))
|
||||
eq(
|
||||
12,
|
||||
vim.iter(t):find(function(v)
|
||||
return v % 4 == 0
|
||||
end)
|
||||
)
|
||||
|
||||
do
|
||||
local it = vim.iter(t)
|
||||
local pred = function(v) return v % 3 == 0 end
|
||||
local pred = function(v)
|
||||
return v % 3 == 0
|
||||
end
|
||||
eq(3, it:find(pred))
|
||||
eq(6, it:find(pred))
|
||||
eq(9, it:find(pred))
|
||||
@@ -318,7 +378,9 @@ describe('vim.iter', function()
|
||||
|
||||
do
|
||||
local it = vim.iter(vim.gsplit('AbCdE', ''))
|
||||
local pred = function(s) return s:match('[A-Z]') end
|
||||
local pred = function(s)
|
||||
return s:match('[A-Z]')
|
||||
end
|
||||
eq('A', it:find(pred))
|
||||
eq('C', it:find(pred))
|
||||
eq('E', it:find(pred))
|
||||
@@ -327,7 +389,7 @@ describe('vim.iter', function()
|
||||
end)
|
||||
|
||||
it('rfind()', function()
|
||||
local t = {1, 2, 3, 2, 1}
|
||||
local t = { 1, 2, 3, 2, 1 }
|
||||
do
|
||||
local it = vim.iter(t)
|
||||
eq(1, it:rfind(1))
|
||||
@@ -337,10 +399,12 @@ describe('vim.iter', function()
|
||||
|
||||
do
|
||||
local it = vim.iter(t):enumerate()
|
||||
local pred = function(i) return i % 2 ~= 0 end
|
||||
eq({5, 1}, {it:rfind(pred)})
|
||||
eq({3, 3}, {it:rfind(pred)})
|
||||
eq({1, 1}, {it:rfind(pred)})
|
||||
local pred = function(i)
|
||||
return i % 2 ~= 0
|
||||
end
|
||||
eq({ 5, 1 }, { it:rfind(pred) })
|
||||
eq({ 3, 3 }, { it:rfind(pred) })
|
||||
eq({ 1, 1 }, { it:rfind(pred) })
|
||||
eq(nil, it:rfind(pred))
|
||||
end
|
||||
|
||||
@@ -382,12 +446,20 @@ describe('vim.iter', function()
|
||||
end)
|
||||
|
||||
it('fold()', function()
|
||||
local t = {1, 2, 3, 4, 5}
|
||||
eq(115, vim.iter(t):fold(100, function(acc, v) return acc + v end))
|
||||
eq({5, 4, 3, 2, 1}, vim.iter(t):fold({}, function(acc, v)
|
||||
table.insert(acc, 1, v)
|
||||
return acc
|
||||
end))
|
||||
local t = { 1, 2, 3, 4, 5 }
|
||||
eq(
|
||||
115,
|
||||
vim.iter(t):fold(100, function(acc, v)
|
||||
return acc + v
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
{ 5, 4, 3, 2, 1 },
|
||||
vim.iter(t):fold({}, function(acc, v)
|
||||
table.insert(acc, 1, v)
|
||||
return acc
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('handles map-like tables', function()
|
||||
@@ -417,9 +489,12 @@ describe('vim.iter', function()
|
||||
},
|
||||
}
|
||||
|
||||
local output = vim.iter(map):map(function(key, value)
|
||||
return { [key] = value.file }
|
||||
end):totable()
|
||||
local output = vim
|
||||
.iter(map)
|
||||
:map(function(key, value)
|
||||
return { [key] = value.file }
|
||||
end)
|
||||
:totable()
|
||||
|
||||
table.sort(output, function(a, b)
|
||||
return next(a) < next(b)
|
||||
|
||||
@@ -16,40 +16,44 @@ describe('vim.json.decode()', function()
|
||||
end)
|
||||
|
||||
it('validation', function()
|
||||
eq('Expected object key string but found invalid token at character 2',
|
||||
pcall_err(exec_lua, [[return vim.json.decode('{a:"b"}')]]))
|
||||
eq(
|
||||
'Expected object key string but found invalid token at character 2',
|
||||
pcall_err(exec_lua, [[return vim.json.decode('{a:"b"}')]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('options', function()
|
||||
local jsonstr = '{"arr":[1,2,null],"bar":[3,7],"foo":{"a":"b"},"baz":null}'
|
||||
eq({
|
||||
arr = { 1, 2, vim.NIL },
|
||||
bar = { 3, 7 },
|
||||
baz = vim.NIL,
|
||||
foo = { a = 'b' },
|
||||
},
|
||||
exec_lua([[return vim.json.decode(..., {})]], jsonstr))
|
||||
arr = { 1, 2, vim.NIL },
|
||||
bar = { 3, 7 },
|
||||
baz = vim.NIL,
|
||||
foo = { a = 'b' },
|
||||
}, exec_lua([[return vim.json.decode(..., {})]], jsonstr))
|
||||
eq({
|
||||
arr = { 1, 2, vim.NIL },
|
||||
bar = { 3, 7 },
|
||||
-- baz = nil,
|
||||
foo = { a = 'b' },
|
||||
},
|
||||
exec_lua([[return vim.json.decode(..., { luanil = { object = true } })]], jsonstr))
|
||||
eq({
|
||||
arr = { 1, 2 },
|
||||
bar = { 3, 7 },
|
||||
baz = vim.NIL,
|
||||
foo = { a = 'b' },
|
||||
},
|
||||
exec_lua([[return vim.json.decode(..., { luanil = { array = true } })]], jsonstr))
|
||||
arr = { 1, 2, vim.NIL },
|
||||
bar = { 3, 7 },
|
||||
-- baz = nil,
|
||||
foo = { a = 'b' },
|
||||
}, exec_lua([[return vim.json.decode(..., { luanil = { object = true } })]], jsonstr))
|
||||
eq({
|
||||
arr = { 1, 2 },
|
||||
bar = { 3, 7 },
|
||||
baz = vim.NIL,
|
||||
foo = { a = 'b' },
|
||||
}, exec_lua([[return vim.json.decode(..., { luanil = { array = true } })]], jsonstr))
|
||||
eq(
|
||||
{
|
||||
arr = { 1, 2 },
|
||||
bar = { 3, 7 },
|
||||
-- baz = nil,
|
||||
foo = { a = 'b' },
|
||||
},
|
||||
exec_lua([[return vim.json.decode(..., { luanil = { array = true, object = true } })]], jsonstr))
|
||||
exec_lua(
|
||||
[[return vim.json.decode(..., { luanil = { array = true, object = true } })]],
|
||||
jsonstr
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('parses integer numbers', function()
|
||||
@@ -96,13 +100,15 @@ describe('vim.json.decode()', function()
|
||||
end)
|
||||
|
||||
it('parses containers', function()
|
||||
eq({1}, exec_lua([[return vim.json.decode('[1]')]]))
|
||||
eq({vim.NIL, 1}, exec_lua([[return vim.json.decode('[null, 1]')]]))
|
||||
eq({['1']=2}, exec_lua([[return vim.json.decode('{"1": 2}')]]))
|
||||
eq({['1']=2, ['3']={{['4']={['5']={{}, 1}}}}},
|
||||
exec_lua([[return vim.json.decode('{"1": 2, "3": [{"4": {"5": [ [], 1]}}]}')]]))
|
||||
eq({ 1 }, exec_lua([[return vim.json.decode('[1]')]]))
|
||||
eq({ vim.NIL, 1 }, exec_lua([[return vim.json.decode('[null, 1]')]]))
|
||||
eq({ ['1'] = 2 }, exec_lua([[return vim.json.decode('{"1": 2}')]]))
|
||||
eq(
|
||||
{ ['1'] = 2, ['3'] = { { ['4'] = { ['5'] = { {}, 1 } } } } },
|
||||
exec_lua([[return vim.json.decode('{"1": 2, "3": [{"4": {"5": [ [], 1]}}]}')]])
|
||||
)
|
||||
-- Empty string is a valid key. #20757
|
||||
eq({['']=42}, exec_lua([[return vim.json.decode('{"": 42}')]]))
|
||||
eq({ [''] = 42 }, exec_lua([[return vim.json.decode('{"": 42}')]]))
|
||||
end)
|
||||
|
||||
it('parses strings properly', function()
|
||||
@@ -111,8 +117,8 @@ describe('vim.json.decode()', function()
|
||||
eq('\\/"\t\b\n\r\f', exec_lua([=[return vim.json.decode([["\\\/\"\t\b\n\r\f"]])]=]))
|
||||
eq('/a', exec_lua([=[return vim.json.decode([["\/a"]])]=]))
|
||||
-- Unicode characters: 2-byte, 3-byte
|
||||
eq('«',exec_lua([=[return vim.json.decode([["«"]])]=]))
|
||||
eq('ફ',exec_lua([=[return vim.json.decode([["ફ"]])]=]))
|
||||
eq('«', exec_lua([=[return vim.json.decode([["«"]])]=]))
|
||||
eq('ફ', exec_lua([=[return vim.json.decode([["ફ"]])]=]))
|
||||
end)
|
||||
|
||||
it('parses surrogate pairs properly', function()
|
||||
@@ -120,11 +126,11 @@ describe('vim.json.decode()', function()
|
||||
end)
|
||||
|
||||
it('accepts all spaces in every position where space may be put', function()
|
||||
local s = ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t'
|
||||
local s =
|
||||
' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t'
|
||||
local str = ('%s{%s"key"%s:%s[%s"val"%s,%s"val2"%s]%s,%s"key2"%s:%s1%s}%s'):gsub('%%s', s)
|
||||
eq({key={'val', 'val2'}, key2=1}, exec_lua([[return vim.json.decode(...)]], str))
|
||||
eq({ key = { 'val', 'val2' }, key2 = 1 }, exec_lua([[return vim.json.decode(...)]], str))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('vim.json.encode()', function()
|
||||
@@ -170,5 +176,4 @@ describe('vim.json.encode()', function()
|
||||
it('dumps vim.NIL', function()
|
||||
eq('null', exec_lua([[return vim.json.encode(vim.NIL)]]))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -9,37 +9,49 @@ describe('vim.loader', function()
|
||||
before_each(helpers.clear)
|
||||
|
||||
it('handles changing files (#23027)', function()
|
||||
exec_lua[[
|
||||
exec_lua [[
|
||||
vim.loader.enable()
|
||||
]]
|
||||
|
||||
local tmp = helpers.tmpname()
|
||||
command('edit ' .. tmp)
|
||||
|
||||
eq(1, exec_lua([[
|
||||
eq(
|
||||
1,
|
||||
exec_lua(
|
||||
[[
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=1'})
|
||||
vim.cmd.write()
|
||||
loadfile(...)()
|
||||
return _G.TEST
|
||||
]], tmp))
|
||||
]],
|
||||
tmp
|
||||
)
|
||||
)
|
||||
|
||||
-- fs latency
|
||||
helpers.sleep(10)
|
||||
|
||||
eq(2, exec_lua([[
|
||||
eq(
|
||||
2,
|
||||
exec_lua(
|
||||
[[
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=2'})
|
||||
vim.cmd.write()
|
||||
loadfile(...)()
|
||||
return _G.TEST
|
||||
]], tmp))
|
||||
]],
|
||||
tmp
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('handles % signs in modpath (#24491)', function()
|
||||
exec_lua[[
|
||||
exec_lua [[
|
||||
vim.loader.enable()
|
||||
]]
|
||||
|
||||
local tmp1, tmp2 = (function (t)
|
||||
local tmp1, tmp2 = (function(t)
|
||||
assert(os.remove(t))
|
||||
assert(helpers.mkdir(t))
|
||||
assert(helpers.mkdir(t .. '/%'))
|
||||
|
||||
@@ -15,16 +15,15 @@ local retry = helpers.retry
|
||||
before_each(clear)
|
||||
|
||||
describe('vim.uv', function()
|
||||
|
||||
it('version', function()
|
||||
assert(funcs.luaeval('vim.uv.version()')>=72961, "libuv version too old")
|
||||
matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.uv.version_string()'))
|
||||
assert(funcs.luaeval('vim.uv.version()') >= 72961, 'libuv version too old')
|
||||
matches('(%d+)%.(%d+)%.(%d+)', funcs.luaeval('vim.uv.version_string()'))
|
||||
end)
|
||||
|
||||
it('timer', function()
|
||||
exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {})
|
||||
|
||||
local code=[[
|
||||
local code = [[
|
||||
local uv = vim.uv
|
||||
|
||||
local touch = 0
|
||||
@@ -61,14 +60,14 @@ describe('vim.uv', function()
|
||||
end)
|
||||
|
||||
it('is API safe', function()
|
||||
local screen = Screen.new(50,10)
|
||||
local screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
||||
[4] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
||||
[5] = {bold = true},
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
[3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
||||
[4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
||||
[5] = { bold = true },
|
||||
})
|
||||
|
||||
-- deferred API functions are disabled, as their safety can't be guaranteed
|
||||
@@ -96,7 +95,7 @@ describe('vim.uv', function()
|
||||
]])
|
||||
feed('<cr>')
|
||||
eq(false, eval("get(g:, 'valid', v:false)"))
|
||||
eq(true, exec_lua("return _G.is_fast"))
|
||||
eq(true, exec_lua('return _G.is_fast'))
|
||||
|
||||
-- callbacks can be scheduled to be executed in the main event loop
|
||||
-- where the entire API is available
|
||||
@@ -116,7 +115,7 @@ describe('vim.uv', function()
|
||||
howdy |
|
||||
]])
|
||||
eq(true, eval("get(g:, 'valid', v:false)"))
|
||||
eq(false, exec_lua("return _G.is_fast"))
|
||||
eq(false, exec_lua('return _G.is_fast'))
|
||||
|
||||
-- fast (not deferred) API functions are allowed to be called directly
|
||||
exec_lua([[
|
||||
@@ -133,7 +132,7 @@ describe('vim.uv', function()
|
||||
{1:~ }|*8
|
||||
{5:-- INSERT --} |
|
||||
]])
|
||||
eq({blocking=false, mode='n'}, exec_lua("return _G.mode"))
|
||||
eq({ blocking = false, mode = 'n' }, exec_lua('return _G.mode'))
|
||||
end)
|
||||
|
||||
it("is equal to require('luv')", function()
|
||||
|
||||
@@ -8,16 +8,22 @@ local exec_lua = helpers.exec_lua
|
||||
describe('lua vim.mpack', function()
|
||||
before_each(clear)
|
||||
it('encodes vim.NIL', function()
|
||||
eq({true, true, true, true}, exec_lua [[
|
||||
eq(
|
||||
{ true, true, true, true },
|
||||
exec_lua [[
|
||||
local var = vim.mpack.decode(vim.mpack.encode({33, vim.NIL, 77}))
|
||||
return {var[1]==33, var[2]==vim.NIL, var[3]==77, var[4]==nil}
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('encodes vim.empty_dict()', function()
|
||||
eq({{{}, "foo", {}}, true, false}, exec_lua [[
|
||||
eq(
|
||||
{ { {}, 'foo', {} }, true, false },
|
||||
exec_lua [[
|
||||
local var = vim.mpack.decode(vim.mpack.encode({{}, "foo", vim.empty_dict()}))
|
||||
return {var, vim.tbl_islist(var[1]), vim.tbl_islist(var[3])}
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -42,25 +42,36 @@ describe('print', function()
|
||||
eq('abc', exec_capture('luafile ' .. fname))
|
||||
end)
|
||||
it('handles errors in __tostring', function()
|
||||
write_file(fname, [[
|
||||
write_file(
|
||||
fname,
|
||||
[[
|
||||
local meta_nilerr = { __tostring = function() error(nil) end }
|
||||
local meta_abcerr = { __tostring = function() error("abc") end }
|
||||
local meta_tblout = { __tostring = function() return {"TEST"} end }
|
||||
v_nilerr = setmetatable({}, meta_nilerr)
|
||||
v_abcerr = setmetatable({}, meta_abcerr)
|
||||
v_tblout = setmetatable({}, meta_tblout)
|
||||
]])
|
||||
]]
|
||||
)
|
||||
eq('', exec_capture('luafile ' .. fname))
|
||||
-- TODO(bfredl): these look weird, print() should not use "E5114:" style errors..
|
||||
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]',
|
||||
pcall_err(command, 'lua print("foo", v_nilerr, "bar")'))
|
||||
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc',
|
||||
pcall_err(command, 'lua print("foo", v_abcerr, "bar")'))
|
||||
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',
|
||||
pcall_err(command, 'lua print("foo", v_tblout, "bar")'))
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]',
|
||||
pcall_err(command, 'lua print("foo", v_nilerr, "bar")')
|
||||
)
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc',
|
||||
pcall_err(command, 'lua print("foo", v_abcerr, "bar")')
|
||||
)
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',
|
||||
pcall_err(command, 'lua print("foo", v_tblout, "bar")')
|
||||
)
|
||||
end)
|
||||
it('coerces error values into strings', function()
|
||||
write_file(fname, [[
|
||||
write_file(
|
||||
fname,
|
||||
[[
|
||||
function string_error() error("my mistake") end
|
||||
function number_error() error(1234) end
|
||||
function nil_error() error(nil) end
|
||||
@@ -82,27 +93,35 @@ describe('print', function()
|
||||
})
|
||||
error(err)
|
||||
end
|
||||
]])
|
||||
]]
|
||||
)
|
||||
eq('', exec_capture('luafile ' .. fname))
|
||||
eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake',
|
||||
pcall_err(command, 'lua string_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234',
|
||||
pcall_err(command, 'lua number_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]',
|
||||
pcall_err(command, 'lua nil_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]',
|
||||
pcall_err(command, 'lua table_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake',
|
||||
pcall_err(command, 'lua custom_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]',
|
||||
pcall_err(command, 'lua bad_custom_error()'))
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake',
|
||||
pcall_err(command, 'lua string_error()')
|
||||
)
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234',
|
||||
pcall_err(command, 'lua number_error()')
|
||||
)
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua nil_error()'))
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua table_error()'))
|
||||
eq(
|
||||
'Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake',
|
||||
pcall_err(command, 'lua custom_error()')
|
||||
)
|
||||
eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()'))
|
||||
end)
|
||||
it('prints strings with NULs and NLs correctly', function()
|
||||
meths.set_option_value('more', true, {})
|
||||
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n',
|
||||
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]))
|
||||
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@',
|
||||
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]]))
|
||||
eq(
|
||||
'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n',
|
||||
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]])
|
||||
)
|
||||
eq(
|
||||
'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@',
|
||||
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]])
|
||||
)
|
||||
eq('T^@', exec_capture([[lua print("T\0")]]))
|
||||
eq('T\n', exec_capture([[lua print("T\n")]]))
|
||||
end)
|
||||
@@ -114,7 +133,8 @@ describe('print', function()
|
||||
eq('abc def', exec_capture('lua print("abc", "", "def")'))
|
||||
end)
|
||||
it('defers printing in luv event handlers', function()
|
||||
exec_lua([[
|
||||
exec_lua(
|
||||
[[
|
||||
local cmd = ...
|
||||
function test()
|
||||
local timer = vim.uv.new_timer()
|
||||
@@ -133,7 +153,9 @@ describe('print', function()
|
||||
print("very slow")
|
||||
vim.api.nvim_command("sleep 1m") -- force deferred event processing
|
||||
end
|
||||
]], (is_os('win') and "timeout 1") or "sleep 0.1")
|
||||
]],
|
||||
(is_os('win') and 'timeout 1') or 'sleep 0.1'
|
||||
)
|
||||
eq('very slow\nvery fast', exec_capture('lua test()'))
|
||||
end)
|
||||
|
||||
@@ -141,22 +163,25 @@ describe('print', function()
|
||||
local screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[0] = {bold = true, foreground=Screen.colors.Blue},
|
||||
[1] = {bold = true, foreground = Screen.colors.SeaGreen},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[0] = { bold = true, foreground = Screen.colors.Blue },
|
||||
[1] = { bold = true, foreground = Screen.colors.SeaGreen },
|
||||
[2] = { bold = true, reverse = true },
|
||||
})
|
||||
feed([[:lua print('\na')<CR>]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*3
|
||||
{2: }|
|
||||
|
|
||||
a |
|
||||
{1:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('<CR>')
|
||||
feed([[:lua print('b\n\nc')<CR>]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*2
|
||||
{2: }|
|
||||
@@ -164,7 +189,8 @@ describe('print', function()
|
||||
|
|
||||
c |
|
||||
{1:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -175,10 +201,10 @@ describe('debug.debug', function()
|
||||
screen = Screen.new()
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids {
|
||||
[0] = {bold=true, foreground=255};
|
||||
[1] = {bold = true, reverse = true};
|
||||
E = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
|
||||
cr = {bold = true, foreground = Screen.colors.SeaGreen4};
|
||||
[0] = { bold = true, foreground = 255 },
|
||||
[1] = { bold = true, reverse = true },
|
||||
E = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
||||
cr = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
||||
}
|
||||
end)
|
||||
|
||||
@@ -191,13 +217,15 @@ describe('debug.debug', function()
|
||||
end
|
||||
]])
|
||||
feed(':lua Test()\n')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*10
|
||||
{1: }|
|
||||
nil |
|
||||
lua_debug> ^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('print("TEST")\n')
|
||||
screen:expect([[
|
||||
|
|
||||
@@ -209,7 +237,8 @@ describe('debug.debug', function()
|
||||
lua_debug> ^ |
|
||||
]])
|
||||
feed('<C-c>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*2
|
||||
{1: }|
|
||||
@@ -223,7 +252,8 @@ describe('debug.debug', function()
|
||||
{E: [string ":lua"]:5: in function 'Test'} |
|
||||
{E: [string ":lua"]:1: in main chunk} |
|
||||
Interrupt: {cr:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('<C-l>:lua Test()\n')
|
||||
screen:expect([[
|
||||
|
|
||||
@@ -233,7 +263,8 @@ describe('debug.debug', function()
|
||||
lua_debug> ^ |
|
||||
]])
|
||||
feed('\n')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*4
|
||||
{1: }|
|
||||
@@ -245,20 +276,24 @@ describe('debug.debug', function()
|
||||
{E: [string ":lua"]:5: in function 'Test'} |
|
||||
{E: [string ":lua"]:1: in main chunk} |
|
||||
{cr:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
end)
|
||||
|
||||
it("can be safely exited with 'cont'", function()
|
||||
feed('<cr>')
|
||||
feed(':lua debug.debug() print("x")<cr>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*12
|
||||
lua_debug> ^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
feed("conttt<cr>") -- misspelled cont; invalid syntax
|
||||
screen:expect{grid=[[
|
||||
feed('conttt<cr>') -- misspelled cont; invalid syntax
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*8
|
||||
{1: }|
|
||||
@@ -266,10 +301,12 @@ describe('debug.debug', function()
|
||||
{E:E5115: Error while loading debug string: (debug comma}|
|
||||
{E:nd):1: '=' expected near '<eof>'} |
|
||||
lua_debug> ^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
feed("cont<cr>") -- exactly "cont", exit now
|
||||
screen:expect{grid=[[
|
||||
feed('cont<cr>') -- exactly "cont", exit now
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{0:~ }|*6
|
||||
{1: }|
|
||||
@@ -279,14 +316,17 @@ describe('debug.debug', function()
|
||||
lua_debug> cont |
|
||||
x |
|
||||
{cr:Press ENTER or type command to continue}^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
feed('<cr>')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
{0:~ }|*12
|
||||
|
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -296,12 +336,12 @@ describe('os.getenv', function()
|
||||
end)
|
||||
it('returns env var set by the parent process', function()
|
||||
local value = 'foo'
|
||||
clear({env = {['XTEST_1']=value}})
|
||||
clear({ env = { ['XTEST_1'] = value } })
|
||||
eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
|
||||
end)
|
||||
it('returns env var set by let', function()
|
||||
local value = 'foo'
|
||||
meths.command('let $XTEST_1 = "'..value..'"')
|
||||
meths.command('let $XTEST_1 = "' .. value .. '"')
|
||||
eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
|
||||
end)
|
||||
end)
|
||||
@@ -310,6 +350,6 @@ end)
|
||||
-- luajit or PUC lua 5.1.
|
||||
describe('bit module', function()
|
||||
it('works', function()
|
||||
eq (9, exec_lua [[ return require'bit'.band(11,13) ]])
|
||||
eq(9, exec_lua [[ return require'bit'.band(11,13) ]])
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -15,8 +15,8 @@ describe('runtime:', function()
|
||||
local init = 'dummy_init.lua'
|
||||
|
||||
setup(function()
|
||||
io.open(init, 'w'):close() -- touch init file
|
||||
clear{args = {'-u', init}}
|
||||
io.open(init, 'w'):close() -- touch init file
|
||||
clear { args = { '-u', init } }
|
||||
exec('set rtp+=' .. plug_dir)
|
||||
exec([[
|
||||
set shell=doesnotexist
|
||||
@@ -45,11 +45,11 @@ describe('runtime:', function()
|
||||
end)
|
||||
|
||||
it('lua colorschemes work and are included in cmdline completion', function()
|
||||
local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep)
|
||||
local colorscheme_file = table.concat({ colorscheme_folder, 'new_colorscheme.lua' }, sep)
|
||||
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
||||
|
||||
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
|
||||
eq({'colors/new_colorscheme.lua'}, funcs.getcompletion('colors/new_c', 'runtime'))
|
||||
eq({ 'new_colorscheme' }, funcs.getcompletion('new_c', 'color'))
|
||||
eq({ 'colors/new_colorscheme.lua' }, funcs.getcompletion('colors/new_c', 'runtime'))
|
||||
|
||||
exec('colorscheme new_colorscheme')
|
||||
|
||||
@@ -64,48 +64,60 @@ describe('runtime:', function()
|
||||
end)
|
||||
exec('set pp+=' .. pack_dir)
|
||||
|
||||
local pack_opt_dir = table.concat({pack_dir, 'pack', 'some_name', 'opt'}, sep)
|
||||
local colors_opt_dir = table.concat({pack_opt_dir, 'some_pack', 'colors'}, sep)
|
||||
local pack_opt_dir = table.concat({ pack_dir, 'pack', 'some_name', 'opt' }, sep)
|
||||
local colors_opt_dir = table.concat({ pack_opt_dir, 'some_pack', 'colors' }, sep)
|
||||
mkdir_p(colors_opt_dir)
|
||||
|
||||
local after_colorscheme_folder = table.concat({plug_dir, 'after', 'colors'}, sep)
|
||||
local after_colorscheme_folder = table.concat({ plug_dir, 'after', 'colors' }, sep)
|
||||
mkdir_p(after_colorscheme_folder)
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
|
||||
write_file(table.concat({colors_opt_dir, 'new_colorscheme.lua'}, sep),
|
||||
[[vim.g.colorscheme = 'lua_pp']])
|
||||
write_file(
|
||||
table.concat({ colors_opt_dir, 'new_colorscheme.lua' }, sep),
|
||||
[[vim.g.colorscheme = 'lua_pp']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('lua_pp', eval('g:colorscheme'))
|
||||
|
||||
write_file(table.concat({colors_opt_dir, 'new_colorscheme.vim'}, sep),
|
||||
[[let g:colorscheme = 'vim_pp']])
|
||||
write_file(
|
||||
table.concat({ colors_opt_dir, 'new_colorscheme.vim' }, sep),
|
||||
[[let g:colorscheme = 'vim_pp']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('vim_pp', eval('g:colorscheme'))
|
||||
|
||||
write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.lua'}, sep),
|
||||
[[vim.g.colorscheme = 'lua_rtp_after']])
|
||||
write_file(
|
||||
table.concat({ after_colorscheme_folder, 'new_colorscheme.lua' }, sep),
|
||||
[[vim.g.colorscheme = 'lua_rtp_after']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('lua_rtp_after', eval('g:colorscheme'))
|
||||
|
||||
write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.vim'}, sep),
|
||||
[[let g:colorscheme = 'vim_rtp_after']])
|
||||
write_file(
|
||||
table.concat({ after_colorscheme_folder, 'new_colorscheme.vim' }, sep),
|
||||
[[let g:colorscheme = 'vim_rtp_after']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('vim_rtp_after', eval('g:colorscheme'))
|
||||
|
||||
write_file(table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep),
|
||||
[[vim.g.colorscheme = 'lua_rtp']])
|
||||
write_file(
|
||||
table.concat({ colorscheme_folder, 'new_colorscheme.lua' }, sep),
|
||||
[[vim.g.colorscheme = 'lua_rtp']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('lua_rtp', eval('g:colorscheme'))
|
||||
|
||||
write_file(table.concat({colorscheme_folder, 'new_colorscheme.vim'}, sep),
|
||||
[[let g:colorscheme = 'vim_rtp']])
|
||||
write_file(
|
||||
table.concat({ colorscheme_folder, 'new_colorscheme.vim' }, sep),
|
||||
[[let g:colorscheme = 'vim_rtp']]
|
||||
)
|
||||
exec('colorscheme new_colorscheme')
|
||||
eq('vim_rtp', eval('g:colorscheme'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('compiler', function()
|
||||
local compiler_folder = table.concat({plug_dir, 'compiler'}, sep)
|
||||
local compiler_folder = table.concat({ plug_dir, 'compiler' }, sep)
|
||||
before_each(function()
|
||||
mkdir_p(compiler_folder)
|
||||
end)
|
||||
@@ -114,8 +126,8 @@ describe('runtime:', function()
|
||||
local compiler_file = compiler_folder .. sep .. 'new_compiler.lua'
|
||||
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
|
||||
|
||||
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
|
||||
eq({'compiler/new_compiler.lua'}, funcs.getcompletion('compiler/new_c', 'runtime'))
|
||||
eq({ 'new_compiler' }, funcs.getcompletion('new_c', 'compiler'))
|
||||
eq({ 'compiler/new_compiler.lua' }, funcs.getcompletion('compiler/new_c', 'runtime'))
|
||||
|
||||
exec('compiler new_compiler')
|
||||
|
||||
@@ -123,126 +135,189 @@ describe('runtime:', function()
|
||||
end)
|
||||
|
||||
it("'rtp' order is respected", function()
|
||||
local after_compiler_folder = table.concat({plug_dir, 'after', 'compiler'}, sep)
|
||||
mkdir_p(table.concat({compiler_folder, 'new_compiler'}, sep))
|
||||
mkdir_p(table.concat({after_compiler_folder, 'new_compiler'}, sep))
|
||||
local after_compiler_folder = table.concat({ plug_dir, 'after', 'compiler' }, sep)
|
||||
mkdir_p(table.concat({ compiler_folder, 'new_compiler' }, sep))
|
||||
mkdir_p(table.concat({ after_compiler_folder, 'new_compiler' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/compiler/ are loaded after all files in compiler/.
|
||||
write_file(table.concat({compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({after_compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({ compiler_folder, 'new_compiler.vim' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(
|
||||
table.concat({ compiler_folder, 'new_compiler.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'B']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_compiler_folder, 'new_compiler.vim' }, sep),
|
||||
[[let g:seq ..= 'a']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_compiler_folder, 'new_compiler.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
exec('compiler new_compiler')
|
||||
eq('ABab', eval('g:seq'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('ftplugin', function()
|
||||
local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep)
|
||||
local ftplugin_folder = table.concat({ plug_dir, 'ftplugin' }, sep)
|
||||
|
||||
it('lua ftplugins work and are included in cmdline completion', function()
|
||||
mkdir_p(ftplugin_folder)
|
||||
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
|
||||
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
|
||||
local ftplugin_file = table.concat({ ftplugin_folder, 'new-ft.lua' }, sep)
|
||||
write_file(ftplugin_file, [[vim.b.lua_ftplugin = 1]])
|
||||
|
||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||
eq({'ftplugin/new-ft.lua'}, funcs.getcompletion('ftplugin/new-f', 'runtime'))
|
||||
eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype'))
|
||||
eq({ 'ftplugin/new-ft.lua' }, funcs.getcompletion('ftplugin/new-f', 'runtime'))
|
||||
|
||||
exec [[set filetype=new-ft]]
|
||||
eq(1, eval('b:lua_ftplugin'))
|
||||
end)
|
||||
|
||||
it("'rtp' order is respected", function()
|
||||
local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
|
||||
mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
|
||||
mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
|
||||
local after_ftplugin_folder = table.concat({ plug_dir, 'after', 'ftplugin' }, sep)
|
||||
mkdir_p(table.concat({ ftplugin_folder, 'new-ft' }, sep))
|
||||
mkdir_p(table.concat({ after_ftplugin_folder, 'new-ft' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/ftplugin/ are loaded after all files in ftplugin/.
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'E']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'c']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'B']]
|
||||
)
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft_a.vim' }, sep), [[let g:seq ..= 'C']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft_a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'D']]
|
||||
)
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft', 'a.vim' }, sep), [[let g:seq ..= 'E']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft', 'a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'F']]
|
||||
)
|
||||
write_file(table.concat({ after_ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']])
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft_a.vim' }, sep),
|
||||
[[let g:seq ..= 'c']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft_a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'd']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft', 'a.vim' }, sep),
|
||||
[[let g:seq ..= 'e']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft', 'a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'f']]
|
||||
)
|
||||
exec('setfiletype new-ft')
|
||||
eq('ABCDEFabcdef', eval('g:seq'))
|
||||
end)
|
||||
|
||||
it("'rtp' order is respected with 'fileignorecase'", function()
|
||||
exec('set fileignorecase')
|
||||
local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
|
||||
mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
|
||||
mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
|
||||
local after_ftplugin_folder = table.concat({ plug_dir, 'after', 'ftplugin' }, sep)
|
||||
mkdir_p(table.concat({ ftplugin_folder, 'new-ft' }, sep))
|
||||
mkdir_p(table.concat({ after_ftplugin_folder, 'new-ft' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/ftplugin/ are loaded after all files in ftplugin/.
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft.VIM'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.VIM'}, sep), [[let g:seq ..= 'E']])
|
||||
write_file(table.concat({ftplugin_folder, 'new-ft', 'a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.VIM'}, sep), [[let g:seq ..= 'c']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft_a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
|
||||
write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft.VIM' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft.LUA' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'B']]
|
||||
)
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft_a.vim' }, sep), [[let g:seq ..= 'C']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft_a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'D']]
|
||||
)
|
||||
write_file(table.concat({ ftplugin_folder, 'new-ft', 'a.VIM' }, sep), [[let g:seq ..= 'E']])
|
||||
write_file(
|
||||
table.concat({ ftplugin_folder, 'new-ft', 'a.LUA' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'F']]
|
||||
)
|
||||
write_file(table.concat({ after_ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']])
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft_a.VIM' }, sep),
|
||||
[[let g:seq ..= 'c']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft_a.LUA' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'd']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft', 'a.vim' }, sep),
|
||||
[[let g:seq ..= 'e']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_ftplugin_folder, 'new-ft', 'a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'f']]
|
||||
)
|
||||
exec('setfiletype new-ft')
|
||||
eq('ABCDEFabcdef', eval('g:seq'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('indent', function()
|
||||
local indent_folder = table.concat({plug_dir, 'indent'}, sep)
|
||||
local indent_folder = table.concat({ plug_dir, 'indent' }, sep)
|
||||
|
||||
it('lua indents work and are included in cmdline completion', function()
|
||||
mkdir_p(indent_folder)
|
||||
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
|
||||
write_file(indent_file , [[vim.b.lua_indent = 1]])
|
||||
local indent_file = table.concat({ indent_folder, 'new-ft.lua' }, sep)
|
||||
write_file(indent_file, [[vim.b.lua_indent = 1]])
|
||||
|
||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||
eq({'indent/new-ft.lua'}, funcs.getcompletion('indent/new-f', 'runtime'))
|
||||
eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype'))
|
||||
eq({ 'indent/new-ft.lua' }, funcs.getcompletion('indent/new-f', 'runtime'))
|
||||
|
||||
exec [[set filetype=new-ft]]
|
||||
eq(1, eval('b:lua_indent'))
|
||||
end)
|
||||
|
||||
it("'rtp' order is respected", function()
|
||||
local after_indent_folder = table.concat({plug_dir, 'after', 'indent'}, sep)
|
||||
mkdir_p(table.concat({indent_folder, 'new-ft'}, sep))
|
||||
mkdir_p(table.concat({after_indent_folder, 'new-ft'}, sep))
|
||||
local after_indent_folder = table.concat({ plug_dir, 'after', 'indent' }, sep)
|
||||
mkdir_p(table.concat({ indent_folder, 'new-ft' }, sep))
|
||||
mkdir_p(table.concat({ after_indent_folder, 'new-ft' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/indent/ are loaded after all files in indent/.
|
||||
write_file(table.concat({indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({after_indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({ indent_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(
|
||||
table.concat({ indent_folder, 'new-ft.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'B']]
|
||||
)
|
||||
write_file(table.concat({ after_indent_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']])
|
||||
write_file(
|
||||
table.concat({ after_indent_folder, 'new-ft.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
exec('setfiletype new-ft')
|
||||
eq('ABab', eval('g:seq'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('syntax', function()
|
||||
local syntax_folder = table.concat({plug_dir, 'syntax'}, sep)
|
||||
local syntax_folder = table.concat({ plug_dir, 'syntax' }, sep)
|
||||
|
||||
before_each(function()
|
||||
mkdir_p(syntax_folder)
|
||||
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
||||
write_file(syntax_file , [[vim.b.current_syntax = 'my-lang']])
|
||||
local syntax_file = table.concat({ syntax_folder, 'my-lang.lua' }, sep)
|
||||
write_file(syntax_file, [[vim.b.current_syntax = 'my-lang']])
|
||||
exec([[let b:current_syntax = '']])
|
||||
end)
|
||||
|
||||
@@ -263,27 +338,42 @@ describe('runtime:', function()
|
||||
end)
|
||||
|
||||
it('lua syntaxes are included in cmdline completion', function()
|
||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
|
||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
|
||||
eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime'))
|
||||
eq({ 'my-lang' }, funcs.getcompletion('my-l', 'filetype'))
|
||||
eq({ 'my-lang' }, funcs.getcompletion('my-l', 'syntax'))
|
||||
eq({ 'syntax/my-lang.lua' }, funcs.getcompletion('syntax/my-l', 'runtime'))
|
||||
end)
|
||||
|
||||
it("'rtp' order is respected", function()
|
||||
local after_syntax_folder = table.concat({plug_dir, 'after', 'syntax'}, sep)
|
||||
mkdir_p(table.concat({syntax_folder, 'my-lang'}, sep))
|
||||
mkdir_p(table.concat({after_syntax_folder, 'my-lang'}, sep))
|
||||
local after_syntax_folder = table.concat({ plug_dir, 'after', 'syntax' }, sep)
|
||||
mkdir_p(table.concat({ syntax_folder, 'my-lang' }, sep))
|
||||
mkdir_p(table.concat({ after_syntax_folder, 'my-lang' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/syntax/ are loaded after all files in syntax/.
|
||||
write_file(table.concat({syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'C']])
|
||||
write_file(table.concat({syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
|
||||
write_file(table.concat({after_syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({after_syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'c']])
|
||||
write_file(table.concat({after_syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
|
||||
write_file(table.concat({ syntax_folder, 'my-lang.vim' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(
|
||||
table.concat({ syntax_folder, 'my-lang.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'B']]
|
||||
)
|
||||
write_file(table.concat({ syntax_folder, 'my-lang', 'a.vim' }, sep), [[let g:seq ..= 'C']])
|
||||
write_file(
|
||||
table.concat({ syntax_folder, 'my-lang', 'a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'D']]
|
||||
)
|
||||
write_file(table.concat({ after_syntax_folder, 'my-lang.vim' }, sep), [[let g:seq ..= 'a']])
|
||||
write_file(
|
||||
table.concat({ after_syntax_folder, 'my-lang.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_syntax_folder, 'my-lang', 'a.vim' }, sep),
|
||||
[[let g:seq ..= 'c']]
|
||||
)
|
||||
write_file(
|
||||
table.concat({ after_syntax_folder, 'my-lang', 'a.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'd']]
|
||||
)
|
||||
exec('setfiletype my-lang')
|
||||
eq('ABCDabcd', eval('g:seq'))
|
||||
end)
|
||||
@@ -291,21 +381,23 @@ describe('runtime:', function()
|
||||
|
||||
describe('spell', function()
|
||||
it("loads spell/LANG.{vim,lua} respecting 'rtp' order", function()
|
||||
local spell_folder = table.concat({plug_dir, 'spell'}, sep)
|
||||
local after_spell_folder = table.concat({plug_dir, 'after', 'spell'}, sep)
|
||||
mkdir_p(table.concat({spell_folder, 'Xtest'}, sep))
|
||||
mkdir_p(table.concat({after_spell_folder, 'Xtest'}, sep))
|
||||
local spell_folder = table.concat({ plug_dir, 'spell' }, sep)
|
||||
local after_spell_folder = table.concat({ plug_dir, 'after', 'spell' }, sep)
|
||||
mkdir_p(table.concat({ spell_folder, 'Xtest' }, sep))
|
||||
mkdir_p(table.concat({ after_spell_folder, 'Xtest' }, sep))
|
||||
exec('set rtp+=' .. plug_dir .. '/after')
|
||||
exec('let g:seq = ""')
|
||||
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
||||
-- All files in after/spell/ are loaded after all files in spell/.
|
||||
write_file(table.concat({spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({after_spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'a']])
|
||||
write_file(table.concat({after_spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
|
||||
write_file(table.concat({ spell_folder, 'Xtest.vim' }, sep), [[let g:seq ..= 'A']])
|
||||
write_file(table.concat({ spell_folder, 'Xtest.lua' }, sep), [[vim.g.seq = vim.g.seq .. 'B']])
|
||||
write_file(table.concat({ after_spell_folder, 'Xtest.vim' }, sep), [[let g:seq ..= 'a']])
|
||||
write_file(
|
||||
table.concat({ after_spell_folder, 'Xtest.lua' }, sep),
|
||||
[[vim.g.seq = vim.g.seq .. 'b']]
|
||||
)
|
||||
exec('set spelllang=Xtest')
|
||||
eq('ABab', eval('g:seq'))
|
||||
end)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -19,11 +19,14 @@ describe('vim.secure', function()
|
||||
local xstate = 'Xstate'
|
||||
|
||||
setup(function()
|
||||
clear{env={XDG_STATE_HOME=xstate}}
|
||||
clear { env = { XDG_STATE_HOME = xstate } }
|
||||
helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
|
||||
helpers.write_file('Xfile', [[
|
||||
helpers.write_file(
|
||||
'Xfile',
|
||||
[[
|
||||
let g:foobar = 42
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
@@ -35,10 +38,10 @@ describe('vim.secure', function()
|
||||
local screen = Screen.new(80, 8)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[3] = {bold = true, foreground = Screen.colors.SeaGreen},
|
||||
[4] = {reverse = true},
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
[3] = { bold = true, foreground = Screen.colors.SeaGreen },
|
||||
[4] = { reverse = true },
|
||||
})
|
||||
|
||||
--- XXX: screen:expect() may fail if this path is too long.
|
||||
@@ -46,20 +49,27 @@ describe('vim.secure', function()
|
||||
|
||||
-- Need to use feed_command instead of exec_lua because of the confirmation prompt
|
||||
feed_command([[lua vim.secure.read('Xfile')]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{1:~ }|*3
|
||||
{2: }|
|
||||
:lua vim.secure.read('Xfile') |
|
||||
{3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:]]
|
||||
.. cwd
|
||||
.. pathsep
|
||||
.. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('d')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*6
|
||||
|
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust))
|
||||
@@ -68,20 +78,27 @@ describe('vim.secure', function()
|
||||
os.remove(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
|
||||
feed_command([[lua vim.secure.read('Xfile')]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{1:~ }|*3
|
||||
{2: }|
|
||||
:lua vim.secure.read('Xfile') |
|
||||
{3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:]]
|
||||
.. cwd
|
||||
.. pathsep
|
||||
.. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('a')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*6
|
||||
|
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
local hash = funcs.sha256(helpers.read_file('Xfile'))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
@@ -91,44 +108,61 @@ describe('vim.secure', function()
|
||||
os.remove(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
|
||||
feed_command([[lua vim.secure.read('Xfile')]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{1:~ }|*3
|
||||
{2: }|
|
||||
:lua vim.secure.read('Xfile') |
|
||||
{3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:]]
|
||||
.. cwd
|
||||
.. pathsep
|
||||
.. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('i')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*6
|
||||
|
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
-- Trust database is not updated
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(nil, trust)
|
||||
|
||||
feed_command([[lua vim.secure.read('Xfile')]])
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|
|
||||
{1:~ }|*3
|
||||
{2: }|
|
||||
:lua vim.secure.read('Xfile') |
|
||||
{3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:]]
|
||||
.. cwd
|
||||
.. pathsep
|
||||
.. [[Xfile is not trusted.}{MATCH:%s+}|
|
||||
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
feed('v')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^let g:foobar = 42 |
|
||||
{1:~ }|*2
|
||||
{2:]] .. funcs.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}}|
|
||||
{2:]]
|
||||
.. funcs.fnamemodify(cwd, ':~')
|
||||
.. pathsep
|
||||
.. [[Xfile [RO]{MATCH:%s+}}|
|
||||
|
|
||||
{1:~ }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
-- Trust database is not updated
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
@@ -144,7 +178,7 @@ describe('vim.secure', function()
|
||||
local xstate = 'Xstate'
|
||||
|
||||
setup(function()
|
||||
clear{env={XDG_STATE_HOME=xstate}}
|
||||
clear { env = { XDG_STATE_HOME = xstate } }
|
||||
helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
|
||||
end)
|
||||
|
||||
@@ -161,13 +195,17 @@ describe('vim.secure', function()
|
||||
end)
|
||||
|
||||
it('returns error when passing both path and bufnr', function()
|
||||
matches('"path" and "bufnr" are mutually exclusive',
|
||||
pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]]))
|
||||
matches(
|
||||
'"path" and "bufnr" are mutually exclusive',
|
||||
pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('returns error when passing neither path or bufnr', function()
|
||||
matches('one of "path" or "bufnr" is required',
|
||||
pcall_err(exec_lua, [[vim.secure.trust({action='deny'})]]))
|
||||
matches(
|
||||
'one of "path" or "bufnr" is required',
|
||||
pcall_err(exec_lua, [[vim.secure.trust({action='deny'})]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('trust then deny then remove a file using bufnr', function()
|
||||
@@ -176,15 +214,15 @@ describe('vim.secure', function()
|
||||
local full_path = cwd .. pathsep .. 'test_file'
|
||||
|
||||
command('edit test_file')
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('%s %s', hash, full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]]))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('! %s', full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]]))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq('', vim.trim(trust))
|
||||
end)
|
||||
@@ -195,15 +233,15 @@ describe('vim.secure', function()
|
||||
local full_path = cwd .. pathsep .. 'test_file'
|
||||
|
||||
command('edit test_file')
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]]))
|
||||
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('! %s', full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('%s %s', hash, full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]]))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq('', vim.trim(trust))
|
||||
end)
|
||||
@@ -214,15 +252,21 @@ describe('vim.secure', function()
|
||||
local full_path = cwd .. pathsep .. 'test_file'
|
||||
|
||||
command('edit test_file')
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('%s %s', hash, full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]))
|
||||
eq(
|
||||
{ true, full_path },
|
||||
exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])
|
||||
)
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('! %s', full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]))
|
||||
eq(
|
||||
{ true, full_path },
|
||||
exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])
|
||||
)
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq('', vim.trim(trust))
|
||||
end)
|
||||
@@ -233,23 +277,31 @@ describe('vim.secure', function()
|
||||
local full_path = cwd .. pathsep .. 'test_file'
|
||||
|
||||
command('edit test_file')
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]))
|
||||
eq(
|
||||
{ true, full_path },
|
||||
exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])
|
||||
)
|
||||
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('! %s', full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq(string.format('%s %s', hash, full_path), vim.trim(trust))
|
||||
|
||||
eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]))
|
||||
eq(
|
||||
{ true, full_path },
|
||||
exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])
|
||||
)
|
||||
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
|
||||
eq('', vim.trim(trust))
|
||||
end)
|
||||
|
||||
it('trust returns error when buffer not associated to file', function()
|
||||
command('new')
|
||||
eq({false, 'buffer is not associated with a file'},
|
||||
exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]))
|
||||
eq(
|
||||
{ false, 'buffer is not associated with a file' },
|
||||
exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -154,7 +154,10 @@ describe('vim.snippet', function()
|
||||
end)
|
||||
|
||||
it('errors with multiple placeholders for the same index', function()
|
||||
test_expand_fail('class ${1:Foo} { void ${1:foo}() {} }', 'multiple placeholders for tabstop $1')
|
||||
test_expand_fail(
|
||||
'class ${1:Foo} { void ${1:foo}() {} }',
|
||||
'multiple placeholders for tabstop $1'
|
||||
)
|
||||
end)
|
||||
|
||||
it('errors with multiple $0 tabstops', function()
|
||||
@@ -162,26 +165,32 @@ describe('vim.snippet', function()
|
||||
end)
|
||||
|
||||
it('cancels session when deleting the snippet', function()
|
||||
test_expand_success({ 'local function $1()', ' $0', 'end' }, { 'local function ()', ' ', 'end' })
|
||||
test_expand_success(
|
||||
{ 'local function $1()', ' $0', 'end' },
|
||||
{ 'local function ()', ' ', 'end' }
|
||||
)
|
||||
feed('<esc>Vjjd')
|
||||
eq(false, exec_lua('return vim.snippet.active()'))
|
||||
end)
|
||||
|
||||
it('cancels session when inserting outside snippet region', function()
|
||||
feed('i<cr>')
|
||||
test_expand_success({ 'local function $1()', ' $0', 'end' }, { '', 'local function ()', ' ', 'end' })
|
||||
test_expand_success(
|
||||
{ 'local function $1()', ' $0', 'end' },
|
||||
{ '', 'local function ()', ' ', 'end' }
|
||||
)
|
||||
feed('<esc>O-- A comment')
|
||||
eq(false, exec_lua('return vim.snippet.active()'))
|
||||
end)
|
||||
|
||||
it('inserts choice', function ()
|
||||
it('inserts choice', function()
|
||||
test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
|
||||
sleep(100)
|
||||
feed('<Down><C-y>')
|
||||
eq({ 'console.log()' }, buf_lines(0))
|
||||
end)
|
||||
|
||||
it('closes the choice completion menu when jumping', function ()
|
||||
it('closes the choice completion menu when jumping', function()
|
||||
test_expand_success({ 'console.${1|assert,log,error|}($2)' }, { 'console.()' })
|
||||
sleep(100)
|
||||
exec_lua('vim.snippet.jump(1)')
|
||||
|
||||
@@ -11,43 +11,32 @@ describe('vim.spell', function()
|
||||
|
||||
describe('.check', function()
|
||||
local check = function(x, exp)
|
||||
return eq(exp, exec_lua("return vim.spell.check(...)", x))
|
||||
return eq(exp, exec_lua('return vim.spell.check(...)', x))
|
||||
end
|
||||
|
||||
it('can handle nil', function()
|
||||
eq([[bad argument #1 to 'check' (expected string)]],
|
||||
pcall_err(exec_lua, [[vim.spell.check(nil)]]))
|
||||
eq(
|
||||
[[bad argument #1 to 'check' (expected string)]],
|
||||
pcall_err(exec_lua, [[vim.spell.check(nil)]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('can check spellings', function()
|
||||
check('hello', {})
|
||||
|
||||
check(
|
||||
'helloi',
|
||||
{{"helloi", "bad", 1}}
|
||||
)
|
||||
check('helloi', { { 'helloi', 'bad', 1 } })
|
||||
|
||||
check(
|
||||
'hello therei',
|
||||
{{"therei", "bad", 7}}
|
||||
)
|
||||
check('hello therei', { { 'therei', 'bad', 7 } })
|
||||
|
||||
check(
|
||||
'hello. there',
|
||||
{{"there", "caps", 8}}
|
||||
)
|
||||
check('hello. there', { { 'there', 'caps', 8 } })
|
||||
|
||||
check(
|
||||
'neovim cna chkc spellins. okay?',
|
||||
{
|
||||
{"neovim" , "bad" , 1},
|
||||
{"cna" , "bad" , 8},
|
||||
{"chkc" , "bad" , 12},
|
||||
{"spellins", "bad" , 17},
|
||||
{"okay" , "caps", 27}
|
||||
}
|
||||
)
|
||||
check('neovim cna chkc spellins. okay?', {
|
||||
{ 'neovim', 'bad', 1 },
|
||||
{ 'cna', 'bad', 8 },
|
||||
{ 'chkc', 'bad', 12 },
|
||||
{ 'spellins', 'bad', 17 },
|
||||
{ 'okay', 'caps', 27 },
|
||||
})
|
||||
end)
|
||||
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -4,7 +4,8 @@ local exec_lua = helpers.exec_lua
|
||||
local eq = helpers.eq
|
||||
|
||||
local function system_sync(cmd, opts)
|
||||
return exec_lua([[
|
||||
return exec_lua(
|
||||
[[
|
||||
local cmd, opts = ...
|
||||
local obj = vim.system(...)
|
||||
|
||||
@@ -21,11 +22,15 @@ local function system_sync(cmd, opts)
|
||||
assert(not proc, 'process still exists')
|
||||
|
||||
return res
|
||||
]], cmd, opts)
|
||||
]],
|
||||
cmd,
|
||||
opts
|
||||
)
|
||||
end
|
||||
|
||||
local function system_async(cmd, opts)
|
||||
return exec_lua([[
|
||||
return exec_lua(
|
||||
[[
|
||||
local cmd, opts = ...
|
||||
_G.done = false
|
||||
local obj = vim.system(cmd, opts, function(obj)
|
||||
@@ -44,7 +49,10 @@ local function system_async(cmd, opts)
|
||||
assert(not proc, 'process still exists')
|
||||
|
||||
return _G.ret
|
||||
]], cmd, opts)
|
||||
]],
|
||||
cmd,
|
||||
opts
|
||||
)
|
||||
end
|
||||
|
||||
describe('vim.system', function()
|
||||
@@ -52,10 +60,10 @@ describe('vim.system', function()
|
||||
clear()
|
||||
end)
|
||||
|
||||
for name, system in pairs{ sync = system_sync, async = system_async, } do
|
||||
describe('('..name..')', function()
|
||||
for name, system in pairs { sync = system_sync, async = system_async } do
|
||||
describe('(' .. name .. ')', function()
|
||||
it('can run simple commands', function()
|
||||
eq('hello\n', system({'echo', 'hello' }, { text = true }).stdout)
|
||||
eq('hello\n', system({ 'echo', 'hello' }, { text = true }).stdout)
|
||||
end)
|
||||
|
||||
it('handle input', function()
|
||||
@@ -67,7 +75,7 @@ describe('vim.system', function()
|
||||
code = 124,
|
||||
signal = 15,
|
||||
stdout = '',
|
||||
stderr = ''
|
||||
stderr = '',
|
||||
}, system({ 'sleep', '10' }, { timeout = 1000 }))
|
||||
end)
|
||||
end)
|
||||
@@ -96,5 +104,4 @@ describe('vim.system', function()
|
||||
assert(signal == 2)
|
||||
]])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -20,4 +20,3 @@ describe('vim.text', function()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ describe('thread', function()
|
||||
screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
||||
[4] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
||||
[5] = {bold = true},
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
[3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
||||
[4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
||||
[5] = { bold = true },
|
||||
})
|
||||
end)
|
||||
|
||||
@@ -150,7 +150,7 @@ describe('thread', function()
|
||||
thread_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {true}}, next_msg())
|
||||
eq({ 'notification', 'result', { true } }, next_msg())
|
||||
end)
|
||||
|
||||
it('uv', function()
|
||||
@@ -182,7 +182,7 @@ describe('thread', function()
|
||||
thread_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg())
|
||||
eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg())
|
||||
end)
|
||||
|
||||
it('json', function()
|
||||
@@ -197,7 +197,7 @@ describe('thread', function()
|
||||
thread_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg())
|
||||
eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg())
|
||||
end)
|
||||
|
||||
it('diff', function()
|
||||
@@ -212,14 +212,18 @@ describe('thread', function()
|
||||
thread_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result',
|
||||
{table.concat({
|
||||
eq({
|
||||
'notification',
|
||||
'result',
|
||||
{
|
||||
table.concat({
|
||||
'@@ -1 +1 @@',
|
||||
'-Hello',
|
||||
'+Helli',
|
||||
''
|
||||
}, '\n')}},
|
||||
next_msg())
|
||||
'',
|
||||
}, '\n'),
|
||||
},
|
||||
}, next_msg())
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -241,28 +245,30 @@ describe('threadpool', function()
|
||||
work:queue()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {true}}, next_msg())
|
||||
eq({ 'notification', 'result', { true } }, next_msg())
|
||||
end)
|
||||
|
||||
it('with invalid argument', function()
|
||||
local status = pcall_err(exec_lua, [[
|
||||
local status = pcall_err(
|
||||
exec_lua,
|
||||
[[
|
||||
local work = vim.uv.new_thread(function() end, function() end)
|
||||
work:queue({})
|
||||
]])
|
||||
]]
|
||||
)
|
||||
|
||||
eq([[Error: thread arg not support type 'function' at 1]],
|
||||
status)
|
||||
eq([[Error: thread arg not support type 'function' at 1]], status)
|
||||
end)
|
||||
|
||||
it('with invalid return value', function()
|
||||
local screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||
[2] = {bold = true, reverse = true},
|
||||
[3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
||||
[4] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
||||
[5] = {bold = true},
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
[3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
||||
[4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
||||
[5] = { bold = true },
|
||||
})
|
||||
|
||||
exec_lua [[
|
||||
@@ -338,7 +344,7 @@ describe('threadpool', function()
|
||||
threadpool_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg())
|
||||
eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg())
|
||||
end)
|
||||
|
||||
it('json', function()
|
||||
@@ -354,7 +360,7 @@ describe('threadpool', function()
|
||||
threadpool_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg())
|
||||
eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg())
|
||||
end)
|
||||
|
||||
it('work', function()
|
||||
@@ -369,14 +375,18 @@ describe('threadpool', function()
|
||||
threadpool_test:do_test()
|
||||
]]
|
||||
|
||||
eq({'notification', 'result',
|
||||
{table.concat({
|
||||
eq({
|
||||
'notification',
|
||||
'result',
|
||||
{
|
||||
table.concat({
|
||||
'@@ -1 +1 @@',
|
||||
'-Hello',
|
||||
'+Helli',
|
||||
''
|
||||
}, '\n')}},
|
||||
next_msg())
|
||||
'',
|
||||
}, '\n'),
|
||||
},
|
||||
}, next_msg())
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -5,7 +5,7 @@ local exec_lua = helpers.exec_lua
|
||||
local clear = helpers.clear
|
||||
local feed = helpers.feed
|
||||
local funcs = helpers.funcs
|
||||
local inspect = require'vim.inspect'
|
||||
local inspect = require 'vim.inspect'
|
||||
|
||||
describe('vim.ui_attach', function()
|
||||
local screen
|
||||
@@ -26,54 +26,67 @@ describe('vim.ui_attach', function()
|
||||
end
|
||||
]]
|
||||
|
||||
screen = Screen.new(40,5)
|
||||
screen = Screen.new(40, 5)
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1};
|
||||
[2] = {bold = true};
|
||||
[3] = {background = Screen.colors.Grey};
|
||||
[4] = {background = Screen.colors.LightMagenta};
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true },
|
||||
[3] = { background = Screen.colors.Grey },
|
||||
[4] = { background = Screen.colors.LightMagenta },
|
||||
})
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
local function expect_events(expected)
|
||||
local evs = exec_lua "return get_events(...)"
|
||||
local evs = exec_lua 'return get_events(...)'
|
||||
eq(expected, evs, inspect(evs))
|
||||
end
|
||||
|
||||
it('can receive popupmenu events', function()
|
||||
exec_lua [[ vim.ui_attach(ns, {ext_popupmenu=true}, on_event) ]]
|
||||
feed('ifo')
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
fo^ |
|
||||
{1:~ }|*3
|
||||
{2:-- INSERT --} |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
|
||||
funcs.complete(1, {'food', 'foobar', 'foo'})
|
||||
screen:expect{grid=[[
|
||||
funcs.complete(1, { 'food', 'foobar', 'foo' })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
food^ |
|
||||
{1:~ }|*3
|
||||
{2:-- INSERT --} |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
expect_events {
|
||||
{ "popupmenu_show", { { "food", "", "", "" }, { "foobar", "", "", "" }, { "foo", "", "", "" } }, 0, 0, 0, 1 };
|
||||
{
|
||||
'popupmenu_show',
|
||||
{ { 'food', '', '', '' }, { 'foobar', '', '', '' }, { 'foo', '', '', '' } },
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
feed '<c-n>'
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
foobar^ |
|
||||
{1:~ }|*3
|
||||
{2:-- INSERT --} |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
expect_events {
|
||||
{ "popupmenu_select", 1 };
|
||||
{ 'popupmenu_select', 1 },
|
||||
}
|
||||
|
||||
feed '<c-y>'
|
||||
screen:expect_unchanged()
|
||||
expect_events {
|
||||
{ "popupmenu_hide" };
|
||||
{ 'popupmenu_hide' },
|
||||
}
|
||||
|
||||
-- vim.ui_detach() stops events, and reenables builtin pum immediately
|
||||
@@ -82,26 +95,31 @@ describe('vim.ui_attach', function()
|
||||
vim.fn.complete(1, {'food', 'foobar', 'foo'})
|
||||
]]
|
||||
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
food^ |
|
||||
{3:food }{1: }|
|
||||
{4:foobar }{1: }|
|
||||
{4:foo }{1: }|
|
||||
{2:-- INSERT --} |
|
||||
]]}
|
||||
expect_events {
|
||||
]],
|
||||
}
|
||||
|
||||
expect_events {}
|
||||
end)
|
||||
|
||||
it('does not crash on exit', function()
|
||||
funcs.system({
|
||||
helpers.nvim_prog,
|
||||
'-u', 'NONE',
|
||||
'-i', 'NONE',
|
||||
'--cmd', [[ lua ns = vim.api.nvim_create_namespace 'testspace' ]],
|
||||
'--cmd', [[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]],
|
||||
'--cmd', 'quitall!',
|
||||
'-u',
|
||||
'NONE',
|
||||
'-i',
|
||||
'NONE',
|
||||
'--cmd',
|
||||
[[ lua ns = vim.api.nvim_create_namespace 'testspace' ]],
|
||||
'--cmd',
|
||||
[[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]],
|
||||
'--cmd',
|
||||
'quitall!',
|
||||
})
|
||||
eq(0, helpers.eval('v:shell_error'))
|
||||
end)
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('vim.ui', function()
|
||||
|
||||
describe('select()', function()
|
||||
it('can select an item', function()
|
||||
local result = exec_lua[[
|
||||
local result = exec_lua [[
|
||||
local items = {
|
||||
{ name = 'Item 1' },
|
||||
{ name = 'Item 2' },
|
||||
@@ -51,7 +51,7 @@ describe('vim.ui', function()
|
||||
|
||||
describe('input()', function()
|
||||
it('can input text', function()
|
||||
local result = exec_lua[[
|
||||
local result = exec_lua [[
|
||||
local opts = {
|
||||
prompt = 'Input: ',
|
||||
}
|
||||
@@ -117,38 +117,44 @@ describe('vim.ui', function()
|
||||
it('can return nil when interrupted with Ctrl-C #18144', function()
|
||||
feed(':lua result = "on_confirm not called"<cr>')
|
||||
feed(':lua vim.ui.input({}, function(input) result = input end)<cr>')
|
||||
poke_eventloop() -- This is needed because Ctrl-C flushes input
|
||||
poke_eventloop() -- This is needed because Ctrl-C flushes input
|
||||
feed('Inputted Text<c-c>')
|
||||
eq(true, exec_lua('return (nil == result)'))
|
||||
end)
|
||||
|
||||
it('can return the identical object when an arbitrary opts.cancelreturn object is given', function()
|
||||
feed(':lua fn = function() return 42 end<CR>')
|
||||
eq(42, exec_lua('return fn()'))
|
||||
feed(':lua vim.ui.input({ cancelreturn = fn }, function(input) result = input end)<cr>')
|
||||
feed('cancel<esc>')
|
||||
eq(true, exec_lua('return (result == fn)'))
|
||||
eq(42, exec_lua('return result()'))
|
||||
end)
|
||||
|
||||
it(
|
||||
'can return the identical object when an arbitrary opts.cancelreturn object is given',
|
||||
function()
|
||||
feed(':lua fn = function() return 42 end<CR>')
|
||||
eq(42, exec_lua('return fn()'))
|
||||
feed(':lua vim.ui.input({ cancelreturn = fn }, function(input) result = input end)<cr>')
|
||||
feed('cancel<esc>')
|
||||
eq(true, exec_lua('return (result == fn)'))
|
||||
eq(42, exec_lua('return result()'))
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
describe('open()', function()
|
||||
it('validation', function()
|
||||
if is_os('win') or not is_ci('github') then
|
||||
exec_lua[[vim.system = function() return { wait=function() return { code=3} end } end]]
|
||||
exec_lua [[vim.system = function() return { wait=function() return { code=3} end } end]]
|
||||
end
|
||||
if not is_os('bsd') then
|
||||
matches('vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }',
|
||||
exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]])
|
||||
matches(
|
||||
'vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }',
|
||||
exec_lua [[local _, err = vim.ui.open('non-existent-file') ; return err]]
|
||||
)
|
||||
end
|
||||
|
||||
exec_lua[[
|
||||
exec_lua [[
|
||||
vim.fn.has = function() return 0 end
|
||||
vim.fn.executable = function() return 0 end
|
||||
]]
|
||||
eq('vim.ui.open: no handler found (tried: wslview, xdg-open)',
|
||||
exec_lua[[local _, err = vim.ui.open('foo') ; return err]])
|
||||
eq(
|
||||
'vim.ui.open: no handler found (tried: wslview, xdg-open)',
|
||||
exec_lua [[local _, err = vim.ui.open('foo') ; return err]]
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -16,20 +16,23 @@ describe('URI methods', function()
|
||||
it('file path includes only ascii characters', function()
|
||||
exec_lua("filepath = '/Foo/Bar/Baz.txt'")
|
||||
|
||||
eq('file:///Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq('file:///Foo/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)'))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua("filepath = '/Foo /Bar/Baz.txt'")
|
||||
|
||||
eq('file:///Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq('file:///Foo%20/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)'))
|
||||
end)
|
||||
|
||||
it('file path including Unicode characters', function()
|
||||
exec_lua("filepath = '/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt'")
|
||||
|
||||
-- The URI encoding should be case-insensitive
|
||||
eq('file:///xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq(
|
||||
'file:///xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt',
|
||||
exec_lua('return vim.uri_from_fname(filepath)')
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -37,19 +40,22 @@ describe('URI methods', function()
|
||||
it('file path includes only ascii characters', function()
|
||||
exec_lua([[filepath = 'C:\\Foo\\Bar\\Baz.txt']])
|
||||
|
||||
eq('file:///C:/Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq('file:///C:/Foo/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)'))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua([[filepath = 'C:\\Foo \\Bar\\Baz.txt']])
|
||||
|
||||
eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)'))
|
||||
end)
|
||||
|
||||
it('file path including Unicode characters', function()
|
||||
exec_lua([[filepath = 'C:\\xy\\åäö\\ɧ\\汉语\\↥\\🤦\\🦄\\å\\بِيَّ.txt']])
|
||||
|
||||
eq('file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
eq(
|
||||
'file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt',
|
||||
exec_lua('return vim.uri_from_fname(filepath)')
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -59,19 +65,19 @@ describe('URI methods', function()
|
||||
it('file path includes only ascii characters', function()
|
||||
exec_lua("uri = 'file:///Foo/Bar/Baz.txt'")
|
||||
|
||||
eq('/Foo/Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)"))
|
||||
eq('/Foo/Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)'))
|
||||
end)
|
||||
|
||||
it('local file path without hostname', function()
|
||||
exec_lua("uri = 'file:/Foo/Bar/Baz.txt'")
|
||||
|
||||
eq('/Foo/Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)"))
|
||||
eq('/Foo/Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)'))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua("uri = 'file:///Foo%20/Bar/Baz.txt'")
|
||||
|
||||
eq('/Foo /Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)"))
|
||||
eq('/Foo /Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)'))
|
||||
end)
|
||||
|
||||
it('file path including Unicode characters', function()
|
||||
@@ -133,73 +139,100 @@ describe('URI methods', function()
|
||||
|
||||
describe('decode non-file URI', function()
|
||||
it('uri_to_fname returns non-file URI unchanged', function()
|
||||
eq('jdt1.23+x-z://content/%5C/', exec_lua [[
|
||||
eq(
|
||||
'jdt1.23+x-z://content/%5C/',
|
||||
exec_lua [[
|
||||
return vim.uri_to_fname('jdt1.23+x-z://content/%5C/')
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('uri_to_fname returns non-file upper-case scheme URI unchanged', function()
|
||||
eq('JDT://content/%5C/', exec_lua [[
|
||||
eq(
|
||||
'JDT://content/%5C/',
|
||||
exec_lua [[
|
||||
return vim.uri_to_fname('JDT://content/%5C/')
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('uri_to_fname returns non-file scheme URI without authority unchanged', function()
|
||||
eq('zipfile:///path/to/archive.zip%3A%3Afilename.txt', exec_lua [[
|
||||
eq(
|
||||
'zipfile:///path/to/archive.zip%3A%3Afilename.txt',
|
||||
exec_lua [[
|
||||
return vim.uri_to_fname('zipfile:///path/to/archive.zip%3A%3Afilename.txt')
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('decode URI without scheme', function()
|
||||
it('fails because URI must have a scheme', function()
|
||||
eq(false, exec_lua [[
|
||||
eq(
|
||||
false,
|
||||
exec_lua [[
|
||||
return pcall(vim.uri_to_fname, 'not_an_uri.txt')
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('uri_to_fname should not treat comma as a scheme character', function()
|
||||
eq(false, exec_lua [[
|
||||
eq(
|
||||
false,
|
||||
exec_lua [[
|
||||
return pcall(vim.uri_to_fname, 'foo,://bar')
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('uri from bufnr', function()
|
||||
it('Windows paths should not be treated as uris', function()
|
||||
skip(not is_os('win'), "Not applicable on non-Windows")
|
||||
skip(not is_os('win'), 'Not applicable on non-Windows')
|
||||
|
||||
local file = helpers.tmpname()
|
||||
write_file(file, 'Test content')
|
||||
local test_case = string.format([[
|
||||
local test_case = string.format(
|
||||
[[
|
||||
local file = '%s'
|
||||
return vim.uri_from_bufnr(vim.fn.bufadd(file))
|
||||
]], file)
|
||||
local expected_uri = 'file:///' .. file:gsub("\\", "/")
|
||||
eq(expected_uri, exec_lua(test_case))
|
||||
os.remove(file)
|
||||
]],
|
||||
file
|
||||
)
|
||||
local expected_uri = 'file:///' .. file:gsub('\\', '/')
|
||||
eq(expected_uri, exec_lua(test_case))
|
||||
os.remove(file)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('uri to bufnr', function()
|
||||
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris', function()
|
||||
local uri = 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class'
|
||||
local test_case = string.format([[
|
||||
local uri =
|
||||
'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class'
|
||||
local test_case = string.format(
|
||||
[[
|
||||
local uri = '%s'
|
||||
return vim.uri_from_bufnr(vim.uri_to_bufnr(uri))
|
||||
]], uri)
|
||||
]],
|
||||
uri
|
||||
)
|
||||
eq(uri, exec_lua(test_case))
|
||||
end)
|
||||
|
||||
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', function()
|
||||
local uri = 'zipfile:///path/to/archive.zip%3A%3Afilename.txt'
|
||||
local test_case = string.format([[
|
||||
it(
|
||||
'uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority',
|
||||
function()
|
||||
local uri = 'zipfile:///path/to/archive.zip%3A%3Afilename.txt'
|
||||
local test_case = string.format(
|
||||
[[
|
||||
local uri = '%s'
|
||||
return vim.uri_from_bufnr(vim.uri_to_bufnr(uri))
|
||||
]], uri)
|
||||
eq(uri, exec_lua(test_case))
|
||||
end)
|
||||
]],
|
||||
uri
|
||||
)
|
||||
eq(uri, exec_lua(test_case))
|
||||
end
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -11,7 +11,6 @@ local function v(ver)
|
||||
end
|
||||
|
||||
describe('version', function()
|
||||
|
||||
it('package', function()
|
||||
clear()
|
||||
eq({ major = 42, minor = 3, patch = 99 }, exec_lua("return vim.version.parse('v42.3.99')"))
|
||||
@@ -35,7 +34,13 @@ describe('version', function()
|
||||
['v1.2'] = { major = 1, minor = 2, patch = 0 },
|
||||
['v1.2.3-prerelease'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease' },
|
||||
['v1.2-prerelease'] = { major = 1, minor = 2, patch = 0, prerelease = 'prerelease' },
|
||||
['v1.2.3-prerelease+build'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease', build = 'build' },
|
||||
['v1.2.3-prerelease+build'] = {
|
||||
major = 1,
|
||||
minor = 2,
|
||||
patch = 3,
|
||||
prerelease = 'prerelease',
|
||||
build = 'build',
|
||||
},
|
||||
['1.2.3+build'] = { major = 1, minor = 2, patch = 3, build = 'build' },
|
||||
}
|
||||
for input, output in pairs(tests) do
|
||||
@@ -108,86 +113,114 @@ describe('version', function()
|
||||
|
||||
describe('cmp()', function()
|
||||
local testcases = {
|
||||
{ v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1, },
|
||||
{ v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1, },
|
||||
{ v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1, },
|
||||
{ v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0, },
|
||||
{ v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1, },
|
||||
{ v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1, },
|
||||
{ v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1, },
|
||||
{ v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0, },
|
||||
{ v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1 },
|
||||
{ v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1 },
|
||||
{ v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1 },
|
||||
{ v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0 },
|
||||
{ v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1 },
|
||||
{ v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1 },
|
||||
{ v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1 },
|
||||
{ v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0 },
|
||||
|
||||
-- prerelease 💩 https://semver.org/#spec-item-11
|
||||
{ v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1, },
|
||||
{ v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1, },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1, },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-9', want = -1, },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-2.0', want = -1, },
|
||||
{ v1 = '1.0.0-2.0', v2 = '1.0.0-2', want = 1, },
|
||||
{ v1 = '1.0.0-2.0', v2 = '1.0.0-2.0', want = 0, },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha', want = 0, },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-beta', want = -1, },
|
||||
{ v1 = '1.0.0-beta', v2 = '1.0.0-alpha', want = 1, },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.1', want = -1, },
|
||||
{ v1 = '1.0.0-alpha.1', v2 = '1.0.0-alpha', want = 1, },
|
||||
{ v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1, },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1, },
|
||||
{ v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1, },
|
||||
{ v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1, },
|
||||
{ v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1, },
|
||||
{ v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1, },
|
||||
{ v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0, },
|
||||
{ v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1, },
|
||||
{ v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1 },
|
||||
{ v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1 },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1 },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-9', want = -1 },
|
||||
{ v1 = '1.0.0-2', v2 = '1.0.0-2.0', want = -1 },
|
||||
{ v1 = '1.0.0-2.0', v2 = '1.0.0-2', want = 1 },
|
||||
{ v1 = '1.0.0-2.0', v2 = '1.0.0-2.0', want = 0 },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha', want = 0 },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-beta', want = -1 },
|
||||
{ v1 = '1.0.0-beta', v2 = '1.0.0-alpha', want = 1 },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.1', want = -1 },
|
||||
{ v1 = '1.0.0-alpha.1', v2 = '1.0.0-alpha', want = 1 },
|
||||
{ v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1 },
|
||||
{ v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1 },
|
||||
{ v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1 },
|
||||
{ v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1 },
|
||||
{ v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1 },
|
||||
{ v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1 },
|
||||
{ v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0 },
|
||||
{ v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1 },
|
||||
}
|
||||
for _, tc in ipairs(testcases) do
|
||||
local msg = function(s) return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<')) end
|
||||
it(string.format('(v1 = %s, v2 = %s)', tc.v1, tc.v2),
|
||||
function()
|
||||
local rv = vim.version.cmp(tc.v1, tc.v2, { strict = true })
|
||||
ok(tc.want == rv, msg(tc.want), msg(rv))
|
||||
end
|
||||
)
|
||||
local msg = function(s)
|
||||
return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<'))
|
||||
end
|
||||
it(string.format('(v1 = %s, v2 = %s)', tc.v1, tc.v2), function()
|
||||
local rv = vim.version.cmp(tc.v1, tc.v2, { strict = true })
|
||||
ok(tc.want == rv, msg(tc.want), msg(rv))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe('parse()', function()
|
||||
describe('strict=true', function()
|
||||
local testcases = {
|
||||
{ desc = 'Nvim version', version = 'v0.9.0-dev-1233+g210120dde81e', want = { major = 0, minor = 9, patch = 0, prerelease = 'dev-1233', build = 'g210120dde81e', }, },
|
||||
{ desc = 'no v', version = '10.20.123', want = { major = 10, minor = 20, patch = 123, prerelease = nil, build = nil, }, },
|
||||
{ desc = 'with v', version = 'v1.2.3', want = { major = 1, minor = 2, patch = 3 }, },
|
||||
{ desc = 'prerelease', version = '1.2.3-alpha', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' }, },
|
||||
{ desc = 'prerelease.x', version = '1.2.3-alpha.1', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' }, },
|
||||
{ desc = 'build.x', version = '1.2.3+build.15', want = { major = 1, minor = 2, patch = 3, build = 'build.15' }, },
|
||||
{ desc = 'prerelease and build', version = '1.2.3-rc1+build.15', want = { major = 1, minor = 2, patch = 3, prerelease = 'rc1', build = 'build.15', }, },
|
||||
{
|
||||
desc = 'Nvim version',
|
||||
version = 'v0.9.0-dev-1233+g210120dde81e',
|
||||
want = {
|
||||
major = 0,
|
||||
minor = 9,
|
||||
patch = 0,
|
||||
prerelease = 'dev-1233',
|
||||
build = 'g210120dde81e',
|
||||
},
|
||||
},
|
||||
{
|
||||
desc = 'no v',
|
||||
version = '10.20.123',
|
||||
want = { major = 10, minor = 20, patch = 123, prerelease = nil, build = nil },
|
||||
},
|
||||
{
|
||||
desc = 'with v',
|
||||
version = 'v1.2.3',
|
||||
want = { major = 1, minor = 2, patch = 3 },
|
||||
},
|
||||
{
|
||||
desc = 'prerelease',
|
||||
version = '1.2.3-alpha',
|
||||
want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' },
|
||||
},
|
||||
{
|
||||
desc = 'prerelease.x',
|
||||
version = '1.2.3-alpha.1',
|
||||
want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' },
|
||||
},
|
||||
{
|
||||
desc = 'build.x',
|
||||
version = '1.2.3+build.15',
|
||||
want = { major = 1, minor = 2, patch = 3, build = 'build.15' },
|
||||
},
|
||||
{
|
||||
desc = 'prerelease and build',
|
||||
version = '1.2.3-rc1+build.15',
|
||||
want = { major = 1, minor = 2, patch = 3, prerelease = 'rc1', build = 'build.15' },
|
||||
},
|
||||
}
|
||||
for _, tc in ipairs(testcases) do
|
||||
it(
|
||||
string.format('%q: version = %q', tc.desc, tc.version),
|
||||
function()
|
||||
eq(tc.want, vim.version.parse(tc.version))
|
||||
end
|
||||
)
|
||||
it(string.format('%q: version = %q', tc.desc, tc.version), function()
|
||||
eq(tc.want, vim.version.parse(tc.version))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe('strict=false', function()
|
||||
local testcases = {
|
||||
{ version = '1.2', want = { major = 1, minor = 2, patch = 0 }, },
|
||||
{ version = '1', want = { major = 1, minor = 0, patch = 0 }, },
|
||||
{ version = '1.1-0', want = { major = 1, minor = 1, patch = 0, prerelease = '0' }, },
|
||||
{ version = '1-1.0', want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' }, },
|
||||
{ version = 'v1.2.3 ', want = { major = 1, minor = 2, patch = 3 }, },
|
||||
{ version = ' v1.2.3', want = { major = 1, minor = 2, patch = 3 }, },
|
||||
{ version = 'tmux 3.2a', want = { major = 3, minor = 2, patch = 0, }, },
|
||||
{ version = '1.2', want = { major = 1, minor = 2, patch = 0 } },
|
||||
{ version = '1', want = { major = 1, minor = 0, patch = 0 } },
|
||||
{ version = '1.1-0', want = { major = 1, minor = 1, patch = 0, prerelease = '0' } },
|
||||
{ version = '1-1.0', want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' } },
|
||||
{ version = 'v1.2.3 ', want = { major = 1, minor = 2, patch = 3 } },
|
||||
{ version = ' v1.2.3', want = { major = 1, minor = 2, patch = 3 } },
|
||||
{ version = 'tmux 3.2a', want = { major = 3, minor = 2, patch = 0 } },
|
||||
}
|
||||
for _, tc in ipairs(testcases) do
|
||||
it(
|
||||
string.format('version = %q', tc.version),
|
||||
function()
|
||||
eq(tc.want, vim.version.parse(tc.version, { strict = false }))
|
||||
end
|
||||
)
|
||||
it(string.format('version = %q', tc.version), function()
|
||||
eq(tc.want, vim.version.parse(tc.version, { strict = false }))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -205,8 +238,8 @@ describe('version', function()
|
||||
{ version = '1.2.3-%?' },
|
||||
{ version = '1.2.3+%?' },
|
||||
{ version = '1.2.3+build.0-rc1' },
|
||||
{ version = '3.2a', },
|
||||
{ version = 'tmux 3.2a', },
|
||||
{ version = '3.2a' },
|
||||
{ version = 'tmux 3.2a' },
|
||||
}
|
||||
|
||||
local function quote_empty(s)
|
||||
@@ -230,8 +263,10 @@ describe('version', function()
|
||||
}
|
||||
for _, tc in ipairs(testcases) do
|
||||
it(string.format('(%s): %s', tc.desc, tostring(tc.version)), function()
|
||||
local expected = string.format(type(tc.version) == 'string'
|
||||
and 'invalid version: "%s"' or 'invalid version: %s', tostring(tc.version))
|
||||
local expected = string.format(
|
||||
type(tc.version) == 'string' and 'invalid version: "%s"' or 'invalid version: %s',
|
||||
tostring(tc.version)
|
||||
)
|
||||
matches(expected, pcall_err(vim.version.parse, tc.version, { strict = true }))
|
||||
end)
|
||||
end
|
||||
@@ -255,19 +290,19 @@ describe('version', function()
|
||||
|
||||
it('lt()', function()
|
||||
eq(true, vim.version.lt('1', '2'))
|
||||
eq(false, vim.version.lt({3}, {0, 7, 4}))
|
||||
eq(false, vim.version.lt({major=3, minor=3, patch=0}, {3, 2, 0}))
|
||||
eq(false, vim.version.lt({ 3 }, { 0, 7, 4 }))
|
||||
eq(false, vim.version.lt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
|
||||
end)
|
||||
|
||||
it('gt()', function()
|
||||
eq(true, vim.version.gt('2', '1'))
|
||||
eq(true, vim.version.gt({3}, {0, 7, 4}))
|
||||
eq(true, vim.version.gt({major=3, minor=3, patch=0}, {3, 2, 0}))
|
||||
eq(true, vim.version.gt({ 3 }, { 0, 7, 4 }))
|
||||
eq(true, vim.version.gt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
|
||||
end)
|
||||
|
||||
it('eq()', function()
|
||||
eq(true, vim.version.eq('2', '2'))
|
||||
eq(true, vim.version.eq({3, 1, 0}, '3.1.0'))
|
||||
eq(true, vim.version.eq({major=3, minor=3, patch=0}, {3, 3, 0}))
|
||||
eq(true, vim.version.eq({ 3, 1, 0 }, '3.1.0'))
|
||||
eq(true, vim.version.eq({ major = 3, minor = 3, patch = 0 }, { 3, 3, 0 }))
|
||||
end)
|
||||
end)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ describe('vim._watch', function()
|
||||
|
||||
describe('watch', function()
|
||||
it('detects file changes', function()
|
||||
skip(is_os('bsd'), "Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38")
|
||||
skip(is_os('bsd'), 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38')
|
||||
local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
|
||||
|
||||
local result = exec_lua(
|
||||
@@ -99,7 +99,7 @@ describe('vim._watch', function()
|
||||
|
||||
describe('poll', function()
|
||||
it('detects file changes', function()
|
||||
skip(is_os('bsd'), "bsd only reports rename on folders if file inside change")
|
||||
skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change')
|
||||
local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
|
||||
|
||||
local result = exec_lua(
|
||||
@@ -165,12 +165,12 @@ describe('vim._watch', function()
|
||||
local expected = {
|
||||
{
|
||||
change_type = created,
|
||||
path = root_dir .. "/file",
|
||||
path = root_dir .. '/file',
|
||||
},
|
||||
{
|
||||
change_type = deleted,
|
||||
path = root_dir .. "/file",
|
||||
}
|
||||
path = root_dir .. '/file',
|
||||
},
|
||||
}
|
||||
eq(expected, result)
|
||||
end)
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('xdiff bindings', function()
|
||||
|
||||
describe('can diff text', function()
|
||||
before_each(function()
|
||||
exec_lua[[
|
||||
exec_lua [[
|
||||
a1 = 'Hello\n'
|
||||
b1 = 'Helli\n'
|
||||
|
||||
@@ -21,15 +21,14 @@ describe('xdiff bindings', function()
|
||||
end)
|
||||
|
||||
it('with no callback', function()
|
||||
|
||||
eq(
|
||||
table.concat({
|
||||
'@@ -1 +1 @@',
|
||||
'-Hello',
|
||||
'+Helli',
|
||||
''
|
||||
'',
|
||||
}, '\n'),
|
||||
exec_lua("return vim.diff(a1, b1)")
|
||||
exec_lua('return vim.diff(a1, b1)')
|
||||
)
|
||||
|
||||
eq(
|
||||
@@ -41,11 +40,10 @@ describe('xdiff bindings', function()
|
||||
'-foo',
|
||||
'+bar',
|
||||
'+baz',
|
||||
''
|
||||
'',
|
||||
}, '\n'),
|
||||
exec_lua("return vim.diff(a2, b2)")
|
||||
exec_lua('return vim.diff(a2, b2)')
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
it('with callback', function()
|
||||
@@ -53,43 +51,55 @@ describe('xdiff bindings', function()
|
||||
exp[#exp+1] = {sa, ca, sb, cb}
|
||||
end]])
|
||||
|
||||
eq({{1, 1, 1, 1}}, exec_lua[[
|
||||
eq(
|
||||
{ { 1, 1, 1, 1 } },
|
||||
exec_lua [[
|
||||
exp = {}
|
||||
assert(vim.diff(a1, b1, {on_hunk = on_hunk}) == nil)
|
||||
return exp
|
||||
]])
|
||||
]]
|
||||
)
|
||||
|
||||
eq({{1, 1, 1, 1}, {3, 1, 3, 2}}, exec_lua[[
|
||||
eq(
|
||||
{ { 1, 1, 1, 1 }, { 3, 1, 3, 2 } },
|
||||
exec_lua [[
|
||||
exp = {}
|
||||
assert(vim.diff(a2, b2, {on_hunk = on_hunk}) == nil)
|
||||
return exp
|
||||
]])
|
||||
]]
|
||||
)
|
||||
|
||||
-- gives higher precedence to on_hunk over result_type
|
||||
eq({{1, 1, 1, 1}, {3, 1, 3, 2}}, exec_lua[[
|
||||
eq(
|
||||
{ { 1, 1, 1, 1 }, { 3, 1, 3, 2 } },
|
||||
exec_lua [[
|
||||
exp = {}
|
||||
assert(vim.diff(a2, b2, {on_hunk = on_hunk, result_type='indices'}) == nil)
|
||||
return exp
|
||||
]])
|
||||
]]
|
||||
)
|
||||
end)
|
||||
|
||||
it('with error callback', function()
|
||||
exec_lua[[
|
||||
exec_lua [[
|
||||
on_hunk = function(sa, ca, sb, cb)
|
||||
error('ERROR1')
|
||||
end
|
||||
]]
|
||||
|
||||
eq([[error running function on_hunk: [string "<nvim>"]:0: ERROR1]],
|
||||
pcall_err(exec_lua, [[vim.diff(a1, b1, {on_hunk = on_hunk})]]))
|
||||
eq(
|
||||
[[error running function on_hunk: [string "<nvim>"]:0: ERROR1]],
|
||||
pcall_err(exec_lua, [[vim.diff(a1, b1, {on_hunk = on_hunk})]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('with hunk_lines', function()
|
||||
eq({{1, 1, 1, 1}},
|
||||
exec_lua([[return vim.diff(a1, b1, {result_type = 'indices'})]]))
|
||||
eq({ { 1, 1, 1, 1 } }, exec_lua([[return vim.diff(a1, b1, {result_type = 'indices'})]]))
|
||||
|
||||
eq({{1, 1, 1, 1}, {3, 1, 3, 2}},
|
||||
exec_lua([[return vim.diff(a2, b2, {result_type = 'indices'})]]))
|
||||
eq(
|
||||
{ { 1, 1, 1, 1 }, { 3, 1, 3, 2 } },
|
||||
exec_lua([[return vim.diff(a2, b2, {result_type = 'indices'})]])
|
||||
)
|
||||
end)
|
||||
|
||||
it('can run different algorithms', function()
|
||||
@@ -101,7 +111,8 @@ describe('xdiff bindings', function()
|
||||
'.bar {',
|
||||
' margin: 0;',
|
||||
'}',
|
||||
''}, '\n')
|
||||
'',
|
||||
}, '\n')
|
||||
|
||||
local b = table.concat({
|
||||
'.bar {',
|
||||
@@ -112,10 +123,12 @@ describe('xdiff bindings', function()
|
||||
' margin: 0;',
|
||||
' color: green;',
|
||||
'}',
|
||||
''}, '\n')
|
||||
'',
|
||||
}, '\n')
|
||||
|
||||
eq(
|
||||
table.concat({'@@ -1,4 +0,0 @@',
|
||||
table.concat({
|
||||
'@@ -1,4 +0,0 @@',
|
||||
'-.foo1 {',
|
||||
'- margin: 0;',
|
||||
'-}',
|
||||
@@ -126,31 +139,37 @@ describe('xdiff bindings', function()
|
||||
'+ margin: 0;',
|
||||
'+ color: green;',
|
||||
'+}',
|
||||
''}, '\n'),
|
||||
exec_lua([[
|
||||
'',
|
||||
}, '\n'),
|
||||
exec_lua(
|
||||
[[
|
||||
local args = {...}
|
||||
return vim.diff(args[1], args[2], {
|
||||
algorithm = 'patience'
|
||||
})
|
||||
]], a, b))
|
||||
]],
|
||||
a,
|
||||
b
|
||||
)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('can handle bad args', function()
|
||||
eq([[Expected at least 2 arguments]],
|
||||
pcall_err(exec_lua, [[vim.diff('a')]]))
|
||||
eq([[Expected at least 2 arguments]], pcall_err(exec_lua, [[vim.diff('a')]]))
|
||||
|
||||
eq([[bad argument #1 to 'diff' (expected string)]],
|
||||
pcall_err(exec_lua, [[vim.diff(1, 2)]]))
|
||||
eq([[bad argument #1 to 'diff' (expected string)]], pcall_err(exec_lua, [[vim.diff(1, 2)]]))
|
||||
|
||||
eq([[bad argument #3 to 'diff' (expected table)]],
|
||||
pcall_err(exec_lua, [[vim.diff('a', 'b', true)]]))
|
||||
eq(
|
||||
[[bad argument #3 to 'diff' (expected table)]],
|
||||
pcall_err(exec_lua, [[vim.diff('a', 'b', true)]])
|
||||
)
|
||||
|
||||
eq([[unexpected key: bad_key]],
|
||||
pcall_err(exec_lua, [[vim.diff('a', 'b', { bad_key = true })]]))
|
||||
|
||||
eq([[on_hunk is not a function]],
|
||||
pcall_err(exec_lua, [[vim.diff('a', 'b', { on_hunk = true })]]))
|
||||
eq([[unexpected key: bad_key]], pcall_err(exec_lua, [[vim.diff('a', 'b', { bad_key = true })]]))
|
||||
|
||||
eq(
|
||||
[[on_hunk is not a function]],
|
||||
pcall_err(exec_lua, [[vim.diff('a', 'b', { on_hunk = true })]])
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user