aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-12 17:59:57 +0000
committerLewis Russell <lewis6991@gmail.com>2024-01-12 18:59:14 +0000
commit795f896a5772d5e0795f86642bdf90c82efac45c (patch)
tree308f04fbee18d2ec3f00c12a8bec96b84d8907f0 /test/functional/lua
parent4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e (diff)
downloadrneovim-795f896a5772d5e0795f86642bdf90c82efac45c.tar.gz
rneovim-795f896a5772d5e0795f86642bdf90c82efac45c.tar.bz2
rneovim-795f896a5772d5e0795f86642bdf90c82efac45c.zip
test: rename (meths, funcs) -> (api, fn)
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/api_spec.lua114
-rw-r--r--test/functional/lua/buffer_updates_spec.lua134
-rw-r--r--test/functional/lua/commands_spec.lua54
-rw-r--r--test/functional/lua/diagnostic_spec.lua60
-rw-r--r--test/functional/lua/filetype_spec.lua4
-rw-r--r--test/functional/lua/loop_spec.lua14
-rw-r--r--test/functional/lua/luaeval_spec.lua110
-rw-r--r--test/functional/lua/overrides_spec.lua24
-rw-r--r--test/functional/lua/runtime_spec.lua24
-rw-r--r--test/functional/lua/secure_spec.lua64
-rw-r--r--test/functional/lua/ui_event_spec.lua6
-rw-r--r--test/functional/lua/vim_spec.lua514
12 files changed, 559 insertions, 563 deletions
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index d10802440f..acd56a0ddb 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local exc_exec = helpers.exc_exec
local remove_trace = helpers.remove_trace
-local funcs = helpers.funcs
+local fn = helpers.fn
local clear = helpers.clear
local eval = helpers.eval
local NIL = vim.NIL
@@ -17,39 +17,39 @@ 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)'))
+ fn.setline(1, { 'abc', 'def', 'a\nb', 'ttt' })
+ eq({ 'a\000b' }, fn.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' })
- eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})'))
+ fn.setline(1, { 'abc', 'def', 'a\nb', 'ttt' })
+ eq(NIL, fn.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)')
+ fn.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' })
+ fn.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"})}')
+ fn.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})}')
+ fn.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})}')
+ fn.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}')
)
end)
@@ -58,7 +58,7 @@ describe('luaeval(vim.api.…)', function()
function()
eq(
{ false, 'Argument "pos" must be a [row, col] array' },
- funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}')
+ fn.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}')
)
end
)
@@ -74,20 +74,20 @@ describe('luaeval(vim.api.…)', function()
]=])')
]==])]===]):gsub('\n', ' ')
)
- eq(1, funcs.luaeval(str))
+ eq(1, fn.luaeval(str))
end)
it('correctly converts from API objects', function()
- eq(1, funcs.luaeval('vim.api.nvim_eval("1")'))
- eq('1', funcs.luaeval([[vim.api.nvim_eval('"1"')]]))
- eq('Blobby', funcs.luaeval('vim.api.nvim_eval("0z426c6f626279")'))
- eq({}, funcs.luaeval('vim.api.nvim_eval("[]")'))
- eq({}, funcs.luaeval('vim.api.nvim_eval("{}")'))
- eq(1, funcs.luaeval('vim.api.nvim_eval("1.0")'))
- eq('\000', funcs.luaeval('vim.api.nvim_eval("0z00")'))
- eq(true, funcs.luaeval('vim.api.nvim_eval("v:true")'))
- eq(false, funcs.luaeval('vim.api.nvim_eval("v:false")'))
- eq(NIL, funcs.luaeval('vim.api.nvim_eval("v:null")'))
+ eq(1, fn.luaeval('vim.api.nvim_eval("1")'))
+ eq('1', fn.luaeval([[vim.api.nvim_eval('"1"')]]))
+ eq('Blobby', fn.luaeval('vim.api.nvim_eval("0z426c6f626279")'))
+ eq({}, fn.luaeval('vim.api.nvim_eval("[]")'))
+ eq({}, fn.luaeval('vim.api.nvim_eval("{}")'))
+ eq(1, fn.luaeval('vim.api.nvim_eval("1.0")'))
+ eq('\000', fn.luaeval('vim.api.nvim_eval("0z00")'))
+ eq(true, fn.luaeval('vim.api.nvim_eval("v:true")'))
+ eq(false, fn.luaeval('vim.api.nvim_eval("v:false")'))
+ eq(NIL, fn.luaeval('vim.api.nvim_eval("v:null")'))
eq(0, eval([[type(luaeval('vim.api.nvim_eval("1")'))]]))
eq(1, eval([[type(luaeval('vim.api.nvim_eval("''1''")'))]]))
@@ -99,25 +99,25 @@ 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 }, fn.luaeval([[vim.api.nvim_eval('{"foo": 42}')]]))
+ eq({ 42 }, fn.luaeval([[vim.api.nvim_eval('[42]')]]))
eq(
{ foo = { bar = 42 }, baz = 50 },
- funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]])
+ fn.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]])
)
- eq({ { 42 }, {} }, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=]))
+ eq({ { 42 }, {} }, fn.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.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)'))
+ eq(1, fn.luaeval('vim.api.nvim__id(1)'))
+ eq('1', fn.luaeval('vim.api.nvim__id("1")'))
+ eq({ 1 }, fn.luaeval('vim.api.nvim__id({1})'))
+ eq({ foo = 1 }, fn.luaeval('vim.api.nvim__id({foo=1})'))
+ eq(1.5, fn.luaeval('vim.api.nvim__id(1.5)'))
+ eq(true, fn.luaeval('vim.api.nvim__id(true)'))
+ eq(false, fn.luaeval('vim.api.nvim__id(false)'))
+ eq(NIL, fn.luaeval('vim.api.nvim__id(nil)'))
-- API strings from Blobs can work as NUL-terminated C strings
eq(
@@ -138,10 +138,10 @@ describe('luaeval(vim.api.…)', function()
eq(
{ foo = 1, bar = { 42, { { baz = true }, 5 } } },
- funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})')
+ fn.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(true, fn.luaeval('vim.api.nvim__id(vim.api.nvim__id)(true)'))
eq(
42,
exec_lua [[
@@ -159,30 +159,30 @@ describe('luaeval(vim.api.…)', function()
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})'))
+ eq({}, fn.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))
-- Presence of type_idx makes Vim ignore some keys
eq(
{ 42 },
- funcs.luaeval(
+ fn.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(
+ fn.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(
+ fn.luaeval(
'vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})'
)
)
eq(
{},
- funcs.luaeval(
+ fn.luaeval(
'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})'
)
)
@@ -191,34 +191,34 @@ describe('luaeval(vim.api.…)', function()
it('correctly converts arrays with type_idx to API objects', function()
eq(3, eval([[type(luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))]]))
- eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))
+ eq({}, fn.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))
eq(
{ 42 },
- funcs.luaeval(
+ fn.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(
+ fn.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(
+ fn.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(
+ fn.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({}, fn.luaeval('vim.api.nvim__id_array({})'))
eq(3, eval([[type(luaeval('vim.api.nvim__id_array({})'))]]))
end)
@@ -228,36 +228,36 @@ describe('luaeval(vim.api.…)', function()
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({}, fn.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))
eq(
{ v = { 42 } },
- funcs.luaeval(
+ fn.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(
+ fn.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(
+ fn.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(
+ fn.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.
- eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({})'))
+ eq({}, fn.luaeval('vim.api.nvim__id_dictionary({})'))
eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]]))
end)
@@ -384,13 +384,11 @@ describe('luaeval(vim.api.…)', function()
end)
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('', fn.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)'))
+ eq('', fn.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})'
- )
+ fn.luaeval('vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})')
)
end)
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 5e11349b67..ba298acc7e 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -2,8 +2,8 @@
local helpers = require('test.functional.helpers')(after_each)
local command = helpers.command
-local meths = helpers.meths
-local funcs = helpers.funcs
+local api = helpers.api
+local fn = helpers.fn
local clear = helpers.clear
local eq = helpers.eq
local fail = helpers.fail
@@ -54,9 +54,9 @@ end)
describe('lua buffer event callbacks: on_lines', function()
local function setup_eventcheck(verify, utf_sizes, lines)
local lastsize
- meths.nvim_buf_set_lines(0, 0, -1, true, lines)
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
if verify then
- lastsize = meths.nvim_buf_get_offset(0, meths.nvim_buf_line_count(0))
+ lastsize = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0))
end
exec_lua('return test_register(...)', 0, 'on_lines', 'test1', false, utf_sizes)
local verify_name = 'test1'
@@ -76,9 +76,9 @@ describe('lua buffer event callbacks: on_lines', function()
for _, event in ipairs(events) do
if event[1] == verify_name and event[2] == 'lines' then
local startline, endline = event[5], event[7]
- local newrange = meths.nvim_buf_get_offset(0, endline)
- - meths.nvim_buf_get_offset(0, startline)
- local newsize = meths.nvim_buf_get_offset(0, meths.nvim_buf_line_count(0))
+ local newrange = api.nvim_buf_get_offset(0, endline)
+ - api.nvim_buf_get_offset(0, startline)
+ local newsize = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0))
local oldrange = newrange + lastsize - newsize
eq(oldrange, event[8])
lastsize = newsize
@@ -98,13 +98,13 @@ describe('lua buffer event callbacks: on_lines', function()
local function check(verify, utf_sizes)
local check_events, verify_name = setup_eventcheck(verify, utf_sizes, origlines)
- local tick = meths.nvim_buf_get_changedtick(0)
+ local tick = api.nvim_buf_get_changedtick(0)
command('set autoindent')
command('normal! GyyggP')
tick = tick + 1
check_events { { 'test1', 'lines', 1, tick, 0, 0, 1, 0 } }
- meths.nvim_buf_set_lines(0, 3, 5, true, { 'changed line' })
+ api.nvim_buf_set_lines(0, 3, 5, true, { 'changed line' })
tick = tick + 1
check_events { { 'test1', 'lines', 1, tick, 3, 5, 4, 32 } }
@@ -142,7 +142,7 @@ describe('lua buffer event callbacks: on_lines', function()
-- simulate next callback returning true
exec_lua("test_unreg = 'test1'")
- meths.nvim_buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' })
+ api.nvim_buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' })
tick = tick + 1
-- plugins can opt in to receive changedtick events, or choose
@@ -154,7 +154,7 @@ describe('lua buffer event callbacks: on_lines', function()
verify_name 'test2'
- meths.nvim_buf_set_lines(0, 1, 1, true, { 'added' })
+ api.nvim_buf_set_lines(0, 1, 1, true, { 'added' })
tick = tick + 1
check_events { { 'test2', 'lines', 1, tick, 1, 1, 2, 0 } }
@@ -206,7 +206,7 @@ describe('lua buffer event callbacks: on_lines', function()
}
local check_events, verify_name = setup_eventcheck(verify, true, unicode_text)
- local tick = meths.nvim_buf_get_changedtick(0)
+ local tick = api.nvim_buf_get_changedtick(0)
feed('ggdd')
tick = tick + 1
@@ -254,7 +254,7 @@ describe('lua buffer event callbacks: on_lines', function()
end)
it('has valid cursor position while shifting', function()
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'line1' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line1' })
exec_lua([[
vim.api.nvim_buf_attach(0, false, {
on_lines = function()
@@ -263,15 +263,15 @@ describe('lua buffer event callbacks: on_lines', function()
})
]])
feed('>>')
- eq(1, meths.nvim_get_var('listener_cursor_line'))
+ eq(1, api.nvim_get_var('listener_cursor_line'))
end)
it('has valid cursor position while deleting lines', function()
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' })
- meths.nvim_win_set_cursor(0, { 2, 0 })
- eq(2, meths.nvim_win_get_cursor(0)[1])
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' })
- eq(2, meths.nvim_win_get_cursor(0)[1])
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' })
+ api.nvim_win_set_cursor(0, { 2, 0 })
+ eq(2, api.nvim_win_get_cursor(0)[1])
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' })
+ eq(2, api.nvim_win_get_cursor(0)[1])
end)
it('does not SEGFAULT when accessing window buffer info in on_detach #14998', function()
@@ -299,7 +299,7 @@ describe('lua buffer event callbacks: on_lines', function()
end)
it('#12718 lnume', function()
- meths.nvim_buf_set_lines(0, 0, -1, true, { '1', '2', '3' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { '1', '2', '3' })
exec_lua([[
vim.api.nvim_buf_attach(0, false, {
on_lines = function(...)
@@ -312,15 +312,15 @@ describe('lua buffer event callbacks: on_lines', function()
feed('G0')
feed('p')
-- Is the last arg old_byte_size correct? Doesn't matter for this PR
- eq(meths.nvim_get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 })
+ eq(api.nvim_get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 })
feed('2G0')
feed('p')
- eq(meths.nvim_get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 })
+ eq(api.nvim_get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 })
feed('1G0')
feed('P')
- eq(meths.nvim_get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 })
+ eq(api.nvim_get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 })
end)
it(
@@ -334,7 +334,7 @@ describe('lua buffer event callbacks: on_lines', function()
})
]])
feed('itest123<Esc><C-A>')
- eq('test124', meths.nvim_get_current_line())
+ eq('test124', api.nvim_get_current_line())
end
)
end)
@@ -346,19 +346,19 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- test both ways.
local function setup_eventcheck(verify, start_txt)
if start_txt then
- meths.nvim_buf_set_lines(0, 0, -1, true, start_txt)
+ api.nvim_buf_set_lines(0, 0, -1, true, start_txt)
else
- start_txt = meths.nvim_buf_get_lines(0, 0, -1, true)
+ start_txt = api.nvim_buf_get_lines(0, 0, -1, true)
end
local shadowbytes = table.concat(start_txt, '\n') .. '\n'
-- TODO: while we are brewing the real strong coffee,
-- verify should check buf_get_offset after every check_events
if verify then
- local len = meths.nvim_buf_get_offset(0, meths.nvim_buf_line_count(0))
+ local len = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0))
eq(len == -1 and 1 or len, string.len(shadowbytes))
end
exec_lua('return test_register(...)', 0, 'on_bytes', 'test1', false, false, true)
- meths.nvim_buf_get_changedtick(0)
+ api.nvim_buf_get_changedtick(0)
local verify_name = 'test1'
local function check_events(expected)
@@ -385,11 +385,11 @@ describe('lua: nvim_buf_attach on_bytes', function()
local after = string.sub(shadowbytes, start_byte + old_byte + 1)
shadowbytes = before .. unknown .. after
elseif event[1] == verify_name and event[2] == 'reload' then
- shadowbytes = table.concat(meths.nvim_buf_get_lines(0, 0, -1, true), '\n') .. '\n'
+ shadowbytes = table.concat(api.nvim_buf_get_lines(0, 0, -1, true), '\n') .. '\n'
end
end
- local text = meths.nvim_buf_get_lines(0, 0, -1, true)
+ local text = api.nvim_buf_get_lines(0, 0, -1, true)
local bytes = table.concat(text, '\n') .. '\n'
eq(
@@ -426,7 +426,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines', function()
local check_events = setup_eventcheck(verify, origlines)
- -- meths.nvim_set_option_value('autoindent', true, {})
+ -- api.nvim_set_option_value('autoindent', true, {})
feed 'Go'
check_events {
{ 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 1 },
@@ -439,7 +439,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines with autoindent', function()
local check_events = setup_eventcheck(verify, origlines)
- meths.nvim_set_option_value('autoindent', true, {})
+ api.nvim_set_option_value('autoindent', true, {})
feed 'Go'
check_events {
{ 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 5 },
@@ -453,19 +453,19 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('setline(num, line)', function()
local check_events = setup_eventcheck(verify, origlines)
- funcs.setline(2, 'babla')
+ fn.setline(2, 'babla')
check_events {
{ 'test1', 'bytes', 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 },
}
- funcs.setline(2, { 'foo', 'bar' })
+ fn.setline(2, { 'foo', 'bar' })
check_events {
{ 'test1', 'bytes', 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 },
{ 'test1', 'bytes', 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 },
}
- local buf_len = meths.nvim_buf_line_count(0)
- funcs.setline(buf_len + 1, 'baz')
+ local buf_len = api.nvim_buf_line_count(0)
+ fn.setline(buf_len + 1, 'baz')
check_events {
{ 'test1', 'bytes', 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 },
}
@@ -473,8 +473,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('continuing comments with fo=or', function()
local check_events = setup_eventcheck(verify, { '// Comment' })
- meths.nvim_set_option_value('formatoptions', 'ro', {})
- meths.nvim_set_option_value('filetype', 'c', {})
+ api.nvim_set_option_value('formatoptions', 'ro', {})
+ api.nvim_set_option_value('filetype', 'c', {})
feed 'A<CR>'
check_events {
{ 'test1', 'bytes', 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 },
@@ -555,7 +555,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('visual charwise paste', function()
local check_events = setup_eventcheck(verify, { '1234567890' })
- funcs.setreg('a', '___')
+ fn.setreg('a', '___')
feed '1G1|vll'
check_events {}
@@ -612,7 +612,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('inccomand=nosplit and substitute', function()
local check_events = setup_eventcheck(verify, { 'abcde', '12345' })
- meths.nvim_set_option_value('inccommand', 'nosplit', {})
+ api.nvim_set_option_value('inccommand', 'nosplit', {})
-- linewise substitute
feed(':%s/bcd/')
@@ -697,41 +697,41 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('nvim_buf_set_text insert', function()
local check_events = setup_eventcheck(verify, { 'bastext' })
- meths.nvim_buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' })
+ api.nvim_buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' })
check_events {
{ 'test1', 'bytes', 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 },
}
- meths.nvim_buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' })
+ api.nvim_buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' })
check_events {
{ 'test1', 'bytes', 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 },
}
eq(
{ 'basfiol', 'kontrapunkt', 'syntgitarr', 'övningstext' },
- meths.nvim_buf_get_lines(0, 0, -1, true)
+ api.nvim_buf_get_lines(0, 0, -1, true)
)
end)
it('nvim_buf_set_text replace', function()
local check_events = setup_eventcheck(verify, origlines)
- meths.nvim_buf_set_text(0, 2, 3, 2, 8, { 'very text' })
+ api.nvim_buf_set_text(0, 2, 3, 2, 8, { 'very text' })
check_events {
{ 'test1', 'bytes', 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 },
}
- meths.nvim_buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' })
+ api.nvim_buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' })
check_events {
{ 'test1', 'bytes', 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 },
}
- meths.nvim_buf_set_text(0, 0, 8, 1, 2, { 'JOINY' })
+ api.nvim_buf_set_text(0, 0, 8, 1, 2, { 'JOINY' })
check_events {
{ 'test1', 'bytes', 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 },
}
- meths.nvim_buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' })
+ api.nvim_buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' })
check_events {
{ 'test1', 'bytes', 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 },
}
@@ -743,20 +743,20 @@ describe('lua: nvim_buf_attach on_bytes', function()
'line l line 4',
'was 5,6',
' indented line',
- }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ }, api.nvim_buf_get_lines(0, 0, -1, true))
end)
it('nvim_buf_set_text delete', function()
local check_events = setup_eventcheck(verify, origlines)
-- really {""} but accepts {} as a shorthand
- meths.nvim_buf_set_text(0, 0, 0, 1, 0, {})
+ api.nvim_buf_set_text(0, 0, 0, 1, 0, {})
check_events {
{ 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 },
}
-- TODO(bfredl): this works but is not as convenient as set_lines
- meths.nvim_buf_set_text(0, 4, 15, 5, 17, { '' })
+ api.nvim_buf_set_text(0, 4, 15, 5, 17, { '' })
check_events {
{ 'test1', 'bytes', 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 },
}
@@ -766,7 +766,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
'original line 4',
'original line 5',
'original line 6',
- }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ }, api.nvim_buf_get_lines(0, 0, -1, true))
end)
it('checktime autoread', function()
@@ -801,7 +801,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ 'test1', 'bytes', 1, 5, 0, 10, 10, 1, 0, 1, 0, 1, 1 },
}
- eq({ 'new line 1 new line 2', 'new line 3' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ 'new line 1 new line 2', 'new line 3' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- check we can undo and redo a reload event.
feed 'u'
@@ -925,19 +925,19 @@ describe('lua: nvim_buf_attach on_bytes', function()
command('set undodir=. | set undofile')
local ns = helpers.request('nvim_create_namespace', 'ns1')
- meths.nvim_buf_set_extmark(0, ns, 0, 0, {})
+ api.nvim_buf_set_extmark(0, ns, 0, 0, {})
- eq({ '12345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- splice
feed('gg0d2l')
- eq({ '345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ '345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- move
command('.m+1')
- eq({ 'hello world', '345' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ 'hello world', '345' }, api.nvim_buf_get_lines(0, 0, -1, true))
-- reload undofile and undo changes
command('w')
@@ -950,7 +950,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
local check_events = setup_eventcheck(verify, nil)
feed('u')
- eq({ '345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ '345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true))
check_events {
{ 'test1', 'bytes', 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 },
@@ -958,7 +958,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
}
feed('u')
- eq({ '12345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
+ eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true))
check_events {
{ 'test1', 'bytes', 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 },
@@ -969,7 +969,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('blockwise paste with uneven line lengths', function()
local check_events = setup_eventcheck(verify, { 'aaaa', 'aaa', 'aaa' })
- -- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true))
+ -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true))
feed('gg0<c-v>jj$d')
check_events {
@@ -1023,7 +1023,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('virtual edit', function()
local check_events = setup_eventcheck(verify, { '', ' ' })
- meths.nvim_set_option_value('virtualedit', 'all', {})
+ api.nvim_set_option_value('virtualedit', 'all', {})
feed [[<Right><Right>iab<ESC>]]
@@ -1042,7 +1042,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('block visual paste', function()
local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF' })
- funcs.setreg('a', '___')
+ fn.setreg('a', '___')
feed([[gg0l<c-v>3jl"ap]])
check_events {
@@ -1077,20 +1077,20 @@ describe('lua: nvim_buf_attach on_bytes', function()
local check_events = setup_eventcheck(verify, { 'AAA', 'BBB' })
-- delete
- meths.nvim_buf_set_lines(0, 0, 1, true, {})
+ api.nvim_buf_set_lines(0, 0, 1, true, {})
check_events {
{ 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 4, 0, 0, 0 },
}
-- add
- meths.nvim_buf_set_lines(0, 0, 0, true, { 'asdf' })
+ api.nvim_buf_set_lines(0, 0, 0, true, { 'asdf' })
check_events {
{ 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 5 },
}
-- replace
- meths.nvim_buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' })
+ api.nvim_buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' })
check_events {
{ 'test1', 'bytes', 1, 5, 0, 0, 0, 1, 0, 5, 2, 0, 10 },
}
@@ -1202,13 +1202,13 @@ describe('lua: nvim_buf_attach on_bytes', function()
command('diffthis')
command('new')
command('diffthis')
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' })
feed('G')
command('diffput')
check_events {
{ 'test1', 'bytes', 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 4 },
}
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' })
feed('<C-w>pG')
command('diffget')
check_events {
@@ -1250,7 +1250,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ 'test1', 'bytes', 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 },
}
- eq('CCC|BBBB|', table.concat(meths.nvim_buf_get_lines(0, 0, -1, true), '|'))
+ eq('CCC|BBBB|', table.concat(api.nvim_buf_get_lines(0, 0, -1, true), '|'))
end)
end
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua
index 2efb57828d..28a99a86f8 100644
--- a/test/functional/lua/commands_spec.lua
+++ b/test/functional/lua/commands_spec.lua
@@ -8,10 +8,10 @@ local eval = helpers.eval
local feed = helpers.feed
local clear = helpers.clear
local matches = helpers.matches
-local meths = helpers.meths
+local api = helpers.api
local exec_lua = helpers.exec_lua
local exec_capture = helpers.exec_capture
-local funcs = helpers.funcs
+local fn = helpers.fn
local source = helpers.source
local dedent = helpers.dedent
local command = helpers.command
@@ -25,23 +25,23 @@ 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' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'TEST' }, api.nvim_buf_get_lines(0, 0, 100, false))
source([[
lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
EOF]])
- eq({ '', 'TSET' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'TSET' }, api.nvim_buf_get_lines(0, 0, 100, false))
source([[
lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
- eq({ '', 'SETT' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'SETT' }, api.nvim_buf_get_lines(0, 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' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false))
matches(
'.*Vim%(lua%):E15: Invalid expression: .*',
pcall_err(
@@ -67,7 +67,7 @@ describe(':lua command', function()
[[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({ '' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '' }, api.nvim_buf_get_lines(0, 0, 100, false))
end)
it('works with NULL errors', function()
eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)'))
@@ -81,13 +81,13 @@ 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' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false))
end)
it('preserves global and not preserves local variables', function()
eq('', exec_capture('lua gvar = 42'))
eq('', exec_capture('lua local lvar = 100500'))
- eq(NIL, funcs.luaeval('lvar'))
- eq(42, funcs.luaeval('gvar'))
+ eq(NIL, fn.luaeval('lvar'))
+ eq(42, fn.luaeval('gvar'))
end)
it('works with long strings', function()
local s = ('x'):rep(100500)
@@ -96,10 +96,10 @@ describe(':lua command', function()
'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({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s)))
- eq({ '', s }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '', s }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
it('can show multiline error messages', function()
@@ -196,31 +196,31 @@ end)
describe(':luado command', function()
it('works', function()
- meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
+ api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}'))
- eq({ 'ABC', 'def', 'gHi' }, meths.nvim_buf_get_lines(0, 0, -1, false))
- eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines'))
+ eq({ 'ABC', 'def', 'gHi' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, fn.luaeval('lines'))
-- Automatic transformation of numbers
eq('', exec_capture('luado return linenr'))
- eq({ '1', '2', '3' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '1', '2', '3' }, api.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture('luado return ("<%02x>"):format(line:byte())'))
- eq({ '<31>', '<32>', '<33>' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '<31>', '<32>', '<33>' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
it('stops processing lines when suddenly out of lines', function()
- meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
+ api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")'))
- eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
- eq(1, funcs.luaeval('runs'))
+ eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
+ eq(1, fn.luaeval('runs'))
end)
it('works correctly when changing lines out of range', function()
- meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
+ api.nvim_buf_set_lines(0, 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({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
it('fails on errors', function()
eq(
@@ -236,12 +236,12 @@ describe(':luado command', function()
eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)'))
end)
it('fails in sandbox when needed', function()
- meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
+ api.nvim_buf_set_lines(0, 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'))
+ eq(NIL, fn.luaeval('runs'))
end)
it('works with long strings', function()
local s = ('x'):rep(100500)
@@ -250,10 +250,10 @@ describe(':luado command', function()
'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'',
pcall_err(command, ('luado return "%s'):format(s))
)
- eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture(('luado return "%s"'):format(s)))
- eq({ s }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ s }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
end)
@@ -274,7 +274,7 @@ describe(':luafile', function()
]]
)
eq('', exec_capture('luafile ' .. fname))
- eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false))
+ eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false))
end)
it('correctly errors out', function()
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 523e771266..5802925339 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -6,7 +6,7 @@ local clear = helpers.clear
local exec_lua = helpers.exec_lua
local eq = helpers.eq
local matches = helpers.matches
-local meths = helpers.meths
+local api = helpers.api
local pcall_err = helpers.pcall_err
describe('vim.diagnostic', function()
@@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function()
it('can perform updates after insert_leave', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
-- Save the diagnostics
exec_lua [[
@@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function()
]]
-- No diagnostics displayed yet.
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
eq(
1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
)
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
eq(
1,
@@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function()
it('does not perform updates when not needed', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
-- Save the diagnostics
exec_lua [[
@@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function()
]]
-- No diagnostics displayed yet.
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
eq(
1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
@@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
eq(0, exec_lua [[return DisplayCount]])
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
eq(
1,
@@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function()
eq(1, exec_lua [[return DisplayCount]])
-- Go in and out of insert mode one more time.
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
-- Should not have set the virtual text again.
eq(1, exec_lua [[return DisplayCount]])
@@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function()
it('never sets virtual text, in combination with insert leave', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
-- Save the diagnostics
exec_lua [[
@@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function()
]]
-- No diagnostics displayed yet.
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
eq(
1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
@@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
eq(0, exec_lua [[return DisplayCount]])
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
eq(
1,
@@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return DisplayCount]])
-- Go in and out of insert mode one more time.
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
-- Should not have set the virtual text still.
eq(0, exec_lua [[return DisplayCount]])
@@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function()
it('can perform updates while in insert mode, if desired', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- meths.nvim_input('o')
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('o')
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
-- Save the diagnostics
exec_lua [[
@@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function()
]]
-- Diagnostics are displayed, because the user wanted them that way!
- eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
eq(
1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
)
eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
- meths.nvim_input('<esc>')
- eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
+ api.nvim_input('<esc>')
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
eq(
1,
@@ -1825,7 +1825,7 @@ describe('vim.diagnostic', function()
it('respects legacy signs placed with :sign define or sign_define #26618', function()
-- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12
- eq(0, helpers.funcs.has('nvim-0.12'))
+ eq(0, helpers.fn.has('nvim-0.12'))
helpers.command(
'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg'
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index 3f61d1bc52..8b0e0a8beb 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local exec_lua = helpers.exec_lua
local eq = helpers.eq
-local meths = helpers.meths
+local api = helpers.api
local clear = helpers.clear
local pathroot = helpers.pathroot
local command = helpers.command
@@ -165,6 +165,6 @@ describe('filetype.lua', function()
clear({
args = { '--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md' },
})
- eq('notmarkdown', meths.nvim_get_option_value('filetype', {}))
+ eq('notmarkdown', api.nvim_get_option_value('filetype', {}))
end)
end)
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua
index 9452866b8e..71eaf29009 100644
--- a/test/functional/lua/loop_spec.lua
+++ b/test/functional/lua/loop_spec.lua
@@ -1,8 +1,8 @@
-- Test suite for testing interactions with API bindings
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
-local funcs = helpers.funcs
-local meths = helpers.meths
+local fn = helpers.fn
+local api = helpers.api
local clear = helpers.clear
local sleep = vim.uv.sleep
local feed = helpers.feed
@@ -16,8 +16,8 @@ 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(fn.luaeval('vim.uv.version()') >= 72961, 'libuv version too old')
+ matches('(%d+)%.(%d+)%.(%d+)', fn.luaeval('vim.uv.version_string()'))
end)
it('timer', function()
@@ -48,13 +48,13 @@ describe('vim.uv', function()
end)()
]]
- eq(0, meths.nvim_get_var('coroutine_cnt'))
+ eq(0, api.nvim_get_var('coroutine_cnt'))
exec_lua(code)
retry(2, nil, function()
sleep(50)
- eq(2, meths.nvim_get_var('coroutine_cnt'))
+ eq(2, api.nvim_get_var('coroutine_cnt'))
end)
- eq(3, meths.nvim_get_var('coroutine_cnt_1'))
+ eq(3, api.nvim_get_var('coroutine_cnt_1'))
end)
it('is API safe', function()
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index d461acafb5..6ed7af6b6e 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -7,8 +7,8 @@ local exc_exec = helpers.exc_exec
local remove_trace = helpers.remove_trace
local exec_lua = helpers.exec_lua
local command = helpers.command
-local meths = helpers.meths
-local funcs = helpers.funcs
+local api = helpers.api
+local fn = helpers.fn
local clear = helpers.clear
local eval = helpers.eval
local feed = helpers.feed
@@ -39,7 +39,7 @@ describe('luaeval()', function()
describe('second argument', function()
it('is successfully received', function()
local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}}
- eq(t, funcs.luaeval("_A", t))
+ eq(t, fn.luaeval("_A", t))
-- Not tested: nil, funcrefs, returned object identity: behaviour will
-- most likely change.
end)
@@ -47,37 +47,37 @@ describe('luaeval()', function()
describe('lua values', function()
it('are successfully transformed', function()
eq({n=1, f=1.5, s='string', l={4, 2}},
- funcs.luaeval('{n=1, f=1.5, s="string", l={4, 2}}'))
+ fn.luaeval('{n=1, f=1.5, s="string", l={4, 2}}'))
-- Not tested: nil inside containers: behaviour will most likely change.
- eq(NIL, funcs.luaeval('nil'))
- eq({['']=1}, funcs.luaeval('{[""]=1}'))
+ eq(NIL, fn.luaeval('nil'))
+ eq({['']=1}, fn.luaeval('{[""]=1}'))
end)
end)
describe('recursive lua values', function()
it('are successfully transformed', function()
command('lua rawset(_G, "d", {})')
command('lua rawset(d, "d", d)')
- eq('\n{\'d\': {...@0}}', funcs.execute('echo luaeval("d")'))
+ eq('\n{\'d\': {...@0}}', fn.execute('echo luaeval("d")'))
command('lua rawset(_G, "l", {})')
command('lua table.insert(l, l)')
- eq('\n[[...@0]]', funcs.execute('echo luaeval("l")'))
+ eq('\n[[...@0]]', fn.execute('echo luaeval("l")'))
end)
end)
describe('strings with NULs', function()
it('are successfully converted to blobs', function()
command([[let s = luaeval('"\0"')]])
- eq('\000', meths.nvim_get_var('s'))
+ eq('\000', api.nvim_get_var('s'))
end)
it('are successfully converted to special dictionaries in table keys', function()
command([[let d = luaeval('{["\0"]=1}')]])
- eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, meths.nvim_get_var('d'))
- eq(1, funcs.eval('d._TYPE is v:msgpack_types.map'))
- eq(1, funcs.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string'))
+ eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, api.nvim_get_var('d'))
+ eq(1, fn.eval('d._TYPE is v:msgpack_types.map'))
+ eq(1, fn.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string'))
end)
it('are successfully converted to blobs from a list', function()
command([[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]])
- eq({'abc', 'a\000b', 'c\000d', 'def'}, meths.nvim_get_var('l'))
+ eq({'abc', 'a\000b', 'c\000d', 'def'}, api.nvim_get_var('l'))
end)
end)
@@ -86,68 +86,68 @@ describe('luaeval()', function()
it('correctly evaluates scalars', function()
-- Also test method call (->) syntax
- eq(1, funcs.luaeval('1'))
+ eq(1, fn.luaeval('1'))
eq(0, eval('"1"->luaeval()->type()'))
- eq(1.5, funcs.luaeval('1.5'))
+ eq(1.5, fn.luaeval('1.5'))
eq(5, eval('"1.5"->luaeval()->type()'))
- eq("test", funcs.luaeval('"test"'))
+ eq("test", fn.luaeval('"test"'))
eq(1, eval('"\'test\'"->luaeval()->type()'))
- eq('', funcs.luaeval('""'))
- eq('\000', funcs.luaeval([['\0']]))
- eq('\000\n\000', funcs.luaeval([['\0\n\0']]))
+ eq('', fn.luaeval('""'))
+ eq('\000', fn.luaeval([['\0']]))
+ eq('\000\n\000', fn.luaeval([['\0\n\0']]))
eq(10, eval([[type(luaeval("'\\0\\n\\0'"))]]))
- eq(true, funcs.luaeval('true'))
- eq(false, funcs.luaeval('false'))
- eq(NIL, funcs.luaeval('nil'))
+ eq(true, fn.luaeval('true'))
+ eq(false, fn.luaeval('false'))
+ eq(NIL, fn.luaeval('nil'))
end)
it('correctly evaluates containers', function()
- eq({}, funcs.luaeval('{}'))
+ eq({}, fn.luaeval('{}'))
eq(3, eval('type(luaeval("{}"))'))
- eq({test=1, foo=2}, funcs.luaeval('{test=1, foo=2}'))
+ eq({test=1, foo=2}, fn.luaeval('{test=1, foo=2}'))
eq(4, eval('type(luaeval("{test=1, foo=2}"))'))
- eq({4, 2}, funcs.luaeval('{4, 2}'))
+ eq({4, 2}, fn.luaeval('{4, 2}'))
eq(3, eval('type(luaeval("{4, 2}"))'))
- eq({NIL, 20}, funcs.luaeval('{[2] = 20}'))
+ eq({NIL, 20}, fn.luaeval('{[2] = 20}'))
eq(3, eval('type(luaeval("{[2] = 20}"))'))
- eq({10, NIL, 30}, funcs.luaeval('{[1] = 10, [3] = 30}'))
+ eq({10, NIL, 30}, fn.luaeval('{[1] = 10, [3] = 30}'))
eq(3, eval('type(luaeval("{[1] = 10, [3] = 30}"))'))
local level = 30
- eq(nested_by_level[level].o, funcs.luaeval(nested_by_level[level].s))
+ eq(nested_by_level[level].o, fn.luaeval(nested_by_level[level].s))
eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, '\000\n\000\000'}}},
- funcs.luaeval([[{['\0\n\0']='\0\n\0\0'}]]))
+ fn.luaeval([[{['\0\n\0']='\0\n\0\0'}]]))
eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]]))
eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0]._TYPE is v:msgpack_types.string]]))
eq({nested={{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, '\000\n\000\000'}}}}},
- funcs.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]]))
+ fn.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]]))
end)
it('correctly passes scalars as argument', function()
- eq(1, funcs.luaeval('_A', 1))
- eq(1.5, funcs.luaeval('_A', 1.5))
- eq('', funcs.luaeval('_A', ''))
- eq('test', funcs.luaeval('_A', 'test'))
- eq(NIL, funcs.luaeval('_A', NIL))
- eq(true, funcs.luaeval('_A', true))
- eq(false, funcs.luaeval('_A', false))
+ eq(1, fn.luaeval('_A', 1))
+ eq(1.5, fn.luaeval('_A', 1.5))
+ eq('', fn.luaeval('_A', ''))
+ eq('test', fn.luaeval('_A', 'test'))
+ eq(NIL, fn.luaeval('_A', NIL))
+ eq(true, fn.luaeval('_A', true))
+ eq(false, fn.luaeval('_A', false))
end)
it('correctly passes containers as argument', function()
- eq({}, funcs.luaeval('_A', {}))
- eq({test=1}, funcs.luaeval('_A', {test=1}))
- eq({4, 2}, funcs.luaeval('_A', {4, 2}))
+ eq({}, fn.luaeval('_A', {}))
+ eq({test=1}, fn.luaeval('_A', {test=1}))
+ eq({4, 2}, fn.luaeval('_A', {4, 2}))
local level = 28
- eq(nested_by_level[level].o, funcs.luaeval('_A', nested_by_level[level].o))
+ eq(nested_by_level[level].o, fn.luaeval('_A', nested_by_level[level].o))
end)
local function sp(typ, val)
@@ -399,26 +399,26 @@ describe('luaeval()', function()
eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]]))
eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]]))
- eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.array}'))
+ eq({}, fn.luaeval('{[vim.type_idx]=vim.types.array}'))
-- Presence of type_idx makes Vim ignore some keys
- eq({42}, funcs.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
- eq({foo=2}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
- eq(10, funcs.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
+ eq({42}, fn.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
+ eq({foo=2}, fn.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
+ eq(10, fn.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
-- The following should not crash
- eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary}'))
+ eq({}, fn.luaeval('{[vim.type_idx]=vim.types.dictionary}'))
end)
it('correctly converts self-containing containers', function()
- meths.nvim_set_var('l', {})
+ api.nvim_set_var('l', {})
eval('add(l, l)')
eq(true, eval('luaeval("_A == _A[1]", l)'))
eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])'))
eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})'))
eq(true, eval('luaeval("_A ~= _A[1]", [l])'))
- meths.nvim_set_var('d', {foo=42})
+ api.nvim_set_var('d', {foo=42})
eval('extend(d, {"d": d})')
eq(true, eval('luaeval("_A == _A.d", d)'))
eq(true, eval('luaeval("_A[1] == _A[1].d", [d])'))
@@ -441,7 +441,7 @@ describe('luaeval()', function()
local s = ('x'):rep(65536)
eq('Vim(call):E5107: Error loading lua [string "luaeval()"]:1: unexpected symbol near \')\'',
exc_exec([[call luaeval("(']] .. s ..[[' + )")]]))
- eq(s, funcs.luaeval('"' .. s .. '"'))
+ eq(s, fn.luaeval('"' .. s .. '"'))
end)
end)
@@ -478,7 +478,7 @@ describe('v:lua', function()
eq(7, eval('v:lua.foo(3,4,v:null)'))
eq(true, exec_lua([[return _G.val == vim.NIL]]))
eq(NIL, eval('v:lua.mymod.noisy("eval")'))
- eq("hey eval", meths.nvim_get_current_line())
+ eq("hey eval", api.nvim_get_current_line())
eq("string: abc", eval('v:lua.mymod.whatis(0z616263)'))
eq("string: ", eval('v:lua.mymod.whatis(v:_null_blob)'))
@@ -494,7 +494,7 @@ describe('v:lua', function()
eq("boop", exec_lua([[return _G.val]]))
eq(NIL, eval('"there"->v:lua.mymod.noisy()'))
- eq("hey there", meths.nvim_get_current_line())
+ eq("hey there", api.nvim_get_current_line())
eq({5, 10, 15, 20}, eval('[[1], [2, 3], [4]]->v:lua.vim.tbl_flatten()->map({_, v -> v * 5})'))
eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)",
@@ -503,7 +503,7 @@ describe('v:lua', function()
it('works in :call', function()
command(":call v:lua.mymod.noisy('command')")
- eq("hey command", meths.nvim_get_current_line())
+ eq("hey command", api.nvim_get_current_line())
eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)",
pcall_err(command, 'call v:lua.mymod.crashy()'))
end)
@@ -518,7 +518,7 @@ describe('v:lua', function()
[5] = {bold = true, foreground = Screen.colors.SeaGreen4},
})
screen:attach()
- meths.nvim_set_option_value('omnifunc', 'v:lua.mymod.omni', {})
+ api.nvim_set_option_value('omnifunc', 'v:lua.mymod.omni', {})
feed('isome st<c-x><c-o>')
screen:expect{grid=[[
some stuff^ |
@@ -528,9 +528,9 @@ describe('v:lua', function()
{1:~ }|*3
{4:-- Omni completion (^O^N^P) }{5:match 1 of 3} |
]]}
- meths.nvim_set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
+ api.nvim_set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
feed('<Esc>g@g@')
- eq("hey line", meths.nvim_get_current_line())
+ eq("hey line", api.nvim_get_current_line())
end)
it('supports packages', function()
diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua
index 12110a86c9..ecbdde3bfd 100644
--- a/test/functional/lua/overrides_spec.lua
+++ b/test/functional/lua/overrides_spec.lua
@@ -6,8 +6,8 @@ local eq = helpers.eq
local NIL = vim.NIL
local feed = helpers.feed
local clear = helpers.clear
-local funcs = helpers.funcs
-local meths = helpers.meths
+local fn = helpers.fn
+local api = helpers.api
local command = helpers.command
local write_file = helpers.write_file
local exec_capture = helpers.exec_capture
@@ -25,15 +25,15 @@ end)
describe('print', function()
it('returns nothing', function()
- eq(NIL, funcs.luaeval('print("abc")'))
- eq(0, funcs.luaeval('select("#", print("abc"))'))
+ eq(NIL, fn.luaeval('print("abc")'))
+ eq(0, fn.luaeval('select("#", print("abc"))'))
end)
it('allows catching printed text with :execute', function()
- eq('\nabc', funcs.execute('lua print("abc")'))
- eq('\nabc', funcs.execute('luado print("abc")'))
- eq('\nabc', funcs.execute('call luaeval("print(\'abc\')")'))
+ eq('\nabc', fn.execute('lua print("abc")'))
+ eq('\nabc', fn.execute('luado print("abc")'))
+ eq('\nabc', fn.execute('call luaeval("print(\'abc\')")'))
write_file(fname, 'print("abc")')
- eq('\nabc', funcs.execute('luafile ' .. fname))
+ eq('\nabc', fn.execute('luafile ' .. fname))
eq('abc', exec_capture('lua print("abc")'))
eq('abc', exec_capture('luado print("abc")'))
@@ -113,7 +113,7 @@ describe('print', function()
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.nvim_set_option_value('more', true, {})
+ api.nvim_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")]])
@@ -332,17 +332,17 @@ end)
describe('os.getenv', function()
it('returns nothing for undefined env var', function()
- eq(NIL, funcs.luaeval('os.getenv("XTEST_1")'))
+ eq(NIL, fn.luaeval('os.getenv("XTEST_1")'))
end)
it('returns env var set by the parent process', function()
local value = 'foo'
clear({ env = { ['XTEST_1'] = value } })
- eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
+ eq(value, fn.luaeval('os.getenv("XTEST_1")'))
end)
it('returns env var set by let', function()
local value = 'foo'
command('let $XTEST_1 = "' .. value .. '"')
- eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
+ eq(value, fn.luaeval('os.getenv("XTEST_1")'))
end)
end)
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
index 84948490ae..6f36ccfb9e 100644
--- a/test/functional/lua/runtime_spec.lua
+++ b/test/functional/lua/runtime_spec.lua
@@ -4,7 +4,7 @@ local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local exec = helpers.exec
-local funcs = helpers.funcs
+local fn = helpers.fn
local mkdir_p = helpers.mkdir_p
local rmdir = helpers.rmdir
local write_file = helpers.write_file
@@ -48,8 +48,8 @@ describe('runtime:', function()
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' }, fn.getcompletion('new_c', 'color'))
+ eq({ 'colors/new_colorscheme.lua' }, fn.getcompletion('colors/new_c', 'runtime'))
exec('colorscheme new_colorscheme')
@@ -126,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' }, fn.getcompletion('new_c', 'compiler'))
+ eq({ 'compiler/new_compiler.lua' }, fn.getcompletion('compiler/new_c', 'runtime'))
exec('compiler new_compiler')
@@ -168,8 +168,8 @@ describe('runtime:', function()
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' }, fn.getcompletion('new-f', 'filetype'))
+ eq({ 'ftplugin/new-ft.lua' }, fn.getcompletion('ftplugin/new-f', 'runtime'))
exec [[set filetype=new-ft]]
eq(1, eval('b:lua_ftplugin'))
@@ -281,8 +281,8 @@ describe('runtime:', function()
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' }, fn.getcompletion('new-f', 'filetype'))
+ eq({ 'indent/new-ft.lua' }, fn.getcompletion('indent/new-f', 'runtime'))
exec [[set filetype=new-ft]]
eq(1, eval('b:lua_indent'))
@@ -338,9 +338,9 @@ 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' }, fn.getcompletion('my-l', 'filetype'))
+ eq({ 'my-lang' }, fn.getcompletion('my-l', 'syntax'))
+ eq({ 'syntax/my-lang.lua' }, fn.getcompletion('syntax/my-l', 'runtime'))
end)
it("'rtp' order is respected", function()
diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua
index 0773988256..7aed711b23 100644
--- a/test/functional/lua/secure_spec.lua
+++ b/test/functional/lua/secure_spec.lua
@@ -6,11 +6,11 @@ local clear = helpers.clear
local command = helpers.command
local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os
-local meths = helpers.meths
+local api = helpers.api
local exec_lua = helpers.exec_lua
local feed_command = helpers.feed_command
local feed = helpers.feed
-local funcs = helpers.funcs
+local fn = helpers.fn
local pcall_err = helpers.pcall_err
local matches = helpers.matches
@@ -45,7 +45,7 @@ describe('vim.secure', function()
})
--- XXX: screen:expect() may fail if this path is too long.
- local cwd = funcs.getcwd()
+ local cwd = fn.getcwd()
-- Need to use feed_command instead of exec_lua because of the confirmation prompt
feed_command([[lua vim.secure.read('Xfile')]])
@@ -71,11 +71,11 @@ describe('vim.secure', function()
]],
}
- local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust))
eq(vim.NIL, exec_lua([[return vim.secure.read('Xfile')]]))
- os.remove(funcs.stdpath('state') .. pathsep .. 'trust')
+ os.remove(fn.stdpath('state') .. pathsep .. 'trust')
feed_command([[lua vim.secure.read('Xfile')]])
screen:expect {
@@ -100,12 +100,12 @@ describe('vim.secure', function()
]],
}
- local hash = funcs.sha256(helpers.read_file('Xfile'))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local hash = fn.sha256(helpers.read_file('Xfile'))
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('%s %s', hash, cwd .. pathsep .. 'Xfile'), vim.trim(trust))
eq(vim.NIL, exec_lua([[vim.secure.read('Xfile')]]))
- os.remove(funcs.stdpath('state') .. pathsep .. 'trust')
+ os.remove(fn.stdpath('state') .. pathsep .. 'trust')
feed_command([[lua vim.secure.read('Xfile')]])
screen:expect {
@@ -131,7 +131,7 @@ describe('vim.secure', function()
}
-- Trust database is not updated
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(nil, trust)
feed_command([[lua vim.secure.read('Xfile')]])
@@ -154,7 +154,7 @@ describe('vim.secure', function()
^let g:foobar = 42 |
{1:~ }|*2
{2:]]
- .. funcs.fnamemodify(cwd, ':~')
+ .. fn.fnamemodify(cwd, ':~')
.. pathsep
.. [[Xfile [RO]{MATCH:%s+}}|
|
@@ -165,12 +165,12 @@ describe('vim.secure', function()
}
-- Trust database is not updated
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(nil, trust)
-- Cannot write file
pcall_err(command, 'write')
- eq(true, meths.nvim_get_option_value('readonly', {}))
+ eq(true, api.nvim_get_option_value('readonly', {}))
end)
end)
@@ -209,71 +209,71 @@ describe('vim.secure', function()
end)
it('trust then deny then remove a file using bufnr', function()
- local cwd = funcs.getcwd()
- local hash = funcs.sha256(helpers.read_file('test_file'))
+ local cwd = fn.getcwd()
+ local hash = fn.sha256(helpers.read_file('test_file'))
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})}]]))
- local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local trust = helpers.read_file(fn.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})}]]))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.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})}]]))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq('', vim.trim(trust))
end)
it('deny then trust then remove a file using bufnr', function()
- local cwd = funcs.getcwd()
- local hash = funcs.sha256(helpers.read_file('test_file'))
+ local cwd = fn.getcwd()
+ local hash = fn.sha256(helpers.read_file('test_file'))
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})}]]))
- local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local trust = helpers.read_file(fn.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})}]]))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.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})}]]))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq('', vim.trim(trust))
end)
it('trust using bufnr then deny then remove a file using path', function()
- local cwd = funcs.getcwd()
- local hash = funcs.sha256(helpers.read_file('test_file'))
+ local cwd = fn.getcwd()
+ local hash = fn.sha256(helpers.read_file('test_file'))
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})}]]))
- local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local trust = helpers.read_file(fn.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'})}]])
)
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.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'})}]])
)
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq('', vim.trim(trust))
end)
it('deny then trust then remove a file using bufnr', function()
- local cwd = funcs.getcwd()
- local hash = funcs.sha256(helpers.read_file('test_file'))
+ local cwd = fn.getcwd()
+ local hash = fn.sha256(helpers.read_file('test_file'))
local full_path = cwd .. pathsep .. 'test_file'
command('edit test_file')
@@ -281,18 +281,18 @@ describe('vim.secure', function()
{ true, full_path },
exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])
)
- local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ local trust = helpers.read_file(fn.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})}]]))
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.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'})}]])
)
- trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq('', vim.trim(trust))
end)
diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua
index 9f9e5271de..3e46018682 100644
--- a/test/functional/lua/ui_event_spec.lua
+++ b/test/functional/lua/ui_event_spec.lua
@@ -4,7 +4,7 @@ local eq = helpers.eq
local exec_lua = helpers.exec_lua
local clear = helpers.clear
local feed = helpers.feed
-local funcs = helpers.funcs
+local fn = helpers.fn
describe('vim.ui_attach', function()
local screen
@@ -51,7 +51,7 @@ describe('vim.ui_attach', function()
]],
}
- funcs.complete(1, { 'food', 'foobar', 'foo' })
+ fn.complete(1, { 'food', 'foobar', 'foo' })
screen:expect {
grid = [[
food^ |
@@ -107,7 +107,7 @@ describe('vim.ui_attach', function()
end)
it('does not crash on exit', function()
- funcs.system({
+ fn.system({
helpers.nvim_prog,
'-u',
'NONE',
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index e938f05703..73fb4c1917 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local nvim_prog = helpers.nvim_prog
-local funcs = helpers.funcs
-local meths = helpers.meths
+local fn = helpers.fn
+local api = helpers.api
local command = helpers.command
local dedent = helpers.dedent
local insert = helpers.insert
@@ -39,93 +39,93 @@ describe('lua stdlib', function()
-- Note: Built-in Nvim comparison (on systems lacking `strcasecmp`) works
-- only on ASCII characters.
it('vim.stricmp', function()
- eq(0, funcs.luaeval('vim.stricmp("a", "A")'))
- eq(0, funcs.luaeval('vim.stricmp("A", "a")'))
- eq(0, funcs.luaeval('vim.stricmp("a", "a")'))
- eq(0, funcs.luaeval('vim.stricmp("A", "A")'))
-
- eq(0, funcs.luaeval('vim.stricmp("", "")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0", "\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0\\0", "\\0\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0a")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0A")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0a")'))
-
- eq(0, funcs.luaeval('vim.stricmp("a\\0", "A\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("A\\0", "a\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("a\\0", "a\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("A\\0", "A\\0")'))
-
- eq(0, funcs.luaeval('vim.stricmp("\\0a", "\\0A")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0A", "\\0a")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0a", "\\0a")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0A", "\\0A")'))
-
- eq(0, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0A\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0a\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0a\\0")'))
- eq(0, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0A\\0")'))
-
- eq(-1, funcs.luaeval('vim.stricmp("a", "B")'))
- eq(-1, funcs.luaeval('vim.stricmp("A", "b")'))
- eq(-1, funcs.luaeval('vim.stricmp("a", "b")'))
- eq(-1, funcs.luaeval('vim.stricmp("A", "B")'))
-
- eq(-1, funcs.luaeval('vim.stricmp("", "\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0", "\\0\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0\\0", "\\0\\0\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0b")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0B")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0b")'))
-
- eq(-1, funcs.luaeval('vim.stricmp("a\\0", "B\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("A\\0", "b\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("a\\0", "b\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("A\\0", "B\\0")'))
-
- eq(-1, funcs.luaeval('vim.stricmp("\\0a", "\\0B")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0A", "\\0b")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0a", "\\0b")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0A", "\\0B")'))
-
- eq(-1, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0B\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0b\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0b\\0")'))
- eq(-1, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0B\\0")'))
-
- eq(1, funcs.luaeval('vim.stricmp("c", "B")'))
- eq(1, funcs.luaeval('vim.stricmp("C", "b")'))
- eq(1, funcs.luaeval('vim.stricmp("c", "b")'))
- eq(1, funcs.luaeval('vim.stricmp("C", "B")'))
-
- eq(1, funcs.luaeval('vim.stricmp("\\0", "")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0", "\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0\\0", "\\0\\0\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0C", "\\0\\0\\0b")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0B")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0b")'))
-
- eq(1, funcs.luaeval('vim.stricmp("c\\0", "B\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("C\\0", "b\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("c\\0", "b\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("C\\0", "B\\0")'))
-
- eq(1, funcs.luaeval('vim.stricmp("c\\0", "B")'))
- eq(1, funcs.luaeval('vim.stricmp("C\\0", "b")'))
- eq(1, funcs.luaeval('vim.stricmp("c\\0", "b")'))
- eq(1, funcs.luaeval('vim.stricmp("C\\0", "B")'))
-
- eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0B")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0b")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0b")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0B")'))
-
- eq(1, funcs.luaeval('vim.stricmp("\\0c\\0", "\\0B\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0b\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0c\\0", "\\0b\\0")'))
- eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("a", "A")'))
+ eq(0, fn.luaeval('vim.stricmp("A", "a")'))
+ eq(0, fn.luaeval('vim.stricmp("a", "a")'))
+ eq(0, fn.luaeval('vim.stricmp("A", "A")'))
+
+ eq(0, fn.luaeval('vim.stricmp("", "")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0", "\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0\\0", "\\0\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0a")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0A")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0a")'))
+
+ eq(0, fn.luaeval('vim.stricmp("a\\0", "A\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("A\\0", "a\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("a\\0", "a\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("A\\0", "A\\0")'))
+
+ eq(0, fn.luaeval('vim.stricmp("\\0a", "\\0A")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0A", "\\0a")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0a", "\\0a")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0A", "\\0A")'))
+
+ eq(0, fn.luaeval('vim.stricmp("\\0a\\0", "\\0A\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0A\\0", "\\0a\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0a\\0", "\\0a\\0")'))
+ eq(0, fn.luaeval('vim.stricmp("\\0A\\0", "\\0A\\0")'))
+
+ eq(-1, fn.luaeval('vim.stricmp("a", "B")'))
+ eq(-1, fn.luaeval('vim.stricmp("A", "b")'))
+ eq(-1, fn.luaeval('vim.stricmp("a", "b")'))
+ eq(-1, fn.luaeval('vim.stricmp("A", "B")'))
+
+ eq(-1, fn.luaeval('vim.stricmp("", "\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0", "\\0\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0\\0", "\\0\\0\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0b")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0B")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0b")'))
+
+ eq(-1, fn.luaeval('vim.stricmp("a\\0", "B\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("A\\0", "b\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("a\\0", "b\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("A\\0", "B\\0")'))
+
+ eq(-1, fn.luaeval('vim.stricmp("\\0a", "\\0B")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0A", "\\0b")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0a", "\\0b")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0A", "\\0B")'))
+
+ eq(-1, fn.luaeval('vim.stricmp("\\0a\\0", "\\0B\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0A\\0", "\\0b\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0a\\0", "\\0b\\0")'))
+ eq(-1, fn.luaeval('vim.stricmp("\\0A\\0", "\\0B\\0")'))
+
+ eq(1, fn.luaeval('vim.stricmp("c", "B")'))
+ eq(1, fn.luaeval('vim.stricmp("C", "b")'))
+ eq(1, fn.luaeval('vim.stricmp("c", "b")'))
+ eq(1, fn.luaeval('vim.stricmp("C", "B")'))
+
+ eq(1, fn.luaeval('vim.stricmp("\\0", "")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0", "\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0\\0", "\\0\\0\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0C", "\\0\\0\\0b")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0B")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0b")'))
+
+ eq(1, fn.luaeval('vim.stricmp("c\\0", "B\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("C\\0", "b\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("c\\0", "b\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("C\\0", "B\\0")'))
+
+ eq(1, fn.luaeval('vim.stricmp("c\\0", "B")'))
+ eq(1, fn.luaeval('vim.stricmp("C\\0", "b")'))
+ eq(1, fn.luaeval('vim.stricmp("c\\0", "b")'))
+ eq(1, fn.luaeval('vim.stricmp("C\\0", "B")'))
+
+ eq(1, fn.luaeval('vim.stricmp("\\0c", "\\0B")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0C", "\\0b")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0c", "\\0b")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0C", "\\0B")'))
+
+ eq(1, fn.luaeval('vim.stricmp("\\0c\\0", "\\0B\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0b\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0c\\0", "\\0b\\0")'))
+ eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
end)
it('vim.deprecate', function()
@@ -157,14 +157,14 @@ describe('lua stdlib', function()
end)
it('vim.startswith', function()
- eq(true, funcs.luaeval('vim.startswith("123", "1")'))
- eq(true, funcs.luaeval('vim.startswith("123", "")'))
- eq(true, funcs.luaeval('vim.startswith("123", "123")'))
- eq(true, funcs.luaeval('vim.startswith("", "")'))
+ eq(true, fn.luaeval('vim.startswith("123", "1")'))
+ eq(true, fn.luaeval('vim.startswith("123", "")'))
+ eq(true, fn.luaeval('vim.startswith("123", "123")'))
+ eq(true, fn.luaeval('vim.startswith("", "")'))
- eq(false, funcs.luaeval('vim.startswith("123", " ")'))
- eq(false, funcs.luaeval('vim.startswith("123", "2")'))
- eq(false, funcs.luaeval('vim.startswith("123", "1234")'))
+ eq(false, fn.luaeval('vim.startswith("123", " ")'))
+ eq(false, fn.luaeval('vim.startswith("123", "2")'))
+ eq(false, fn.luaeval('vim.startswith("123", "1234")'))
matches(
'prefix: expected string, got nil',
@@ -174,14 +174,14 @@ describe('lua stdlib', function()
end)
it('vim.endswith', function()
- eq(true, funcs.luaeval('vim.endswith("123", "3")'))
- eq(true, funcs.luaeval('vim.endswith("123", "")'))
- eq(true, funcs.luaeval('vim.endswith("123", "123")'))
- eq(true, funcs.luaeval('vim.endswith("", "")'))
+ eq(true, fn.luaeval('vim.endswith("123", "3")'))
+ eq(true, fn.luaeval('vim.endswith("123", "")'))
+ eq(true, fn.luaeval('vim.endswith("123", "123")'))
+ eq(true, fn.luaeval('vim.endswith("", "")'))
- eq(false, funcs.luaeval('vim.endswith("123", " ")'))
- eq(false, funcs.luaeval('vim.endswith("123", "2")'))
- eq(false, funcs.luaeval('vim.endswith("123", "1234")'))
+ eq(false, fn.luaeval('vim.endswith("123", " ")'))
+ eq(false, fn.luaeval('vim.endswith("123", "2")'))
+ eq(false, fn.luaeval('vim.endswith("123", "1234")'))
matches(
'suffix: expected string, got nil',
@@ -1205,7 +1205,7 @@ describe('lua stdlib', function()
chan = vim.fn.jobstart({'cat'}, {rpc=true})
vim.rpcrequest(chan, 'nvim_set_current_line', 'meow')
]])
- eq('meow', meths.nvim_get_current_line())
+ eq('meow', api.nvim_get_current_line())
command("let x = [3, 'aa', v:true, v:null]")
eq(
true,
@@ -1250,7 +1250,7 @@ describe('lua stdlib', function()
]])
)
retry(10, nil, function()
- eq('foo', meths.nvim_get_current_line())
+ eq('foo', api.nvim_get_current_line())
end)
local screen = Screen.new(50, 7)
@@ -1282,7 +1282,7 @@ describe('lua stdlib', function()
]],
}
feed('<cr>')
- eq({ 3, NIL }, meths.nvim_get_var('yy'))
+ eq({ 3, NIL }, api.nvim_get_var('yy'))
exec_lua([[timer:close()]])
end)
@@ -1426,11 +1426,11 @@ describe('lua stdlib', function()
vim.api.nvim_set_var("to_delete", {hello="world"})
]]
- eq('hi', funcs.luaeval 'vim.g.testing')
- eq(123, funcs.luaeval 'vim.g.other')
- eq(5120.1, funcs.luaeval 'vim.g.floaty')
- eq(NIL, funcs.luaeval 'vim.g.nonexistent')
- eq(NIL, funcs.luaeval 'vim.g.nullvar')
+ eq('hi', fn.luaeval 'vim.g.testing')
+ eq(123, fn.luaeval 'vim.g.other')
+ eq(5120.1, fn.luaeval 'vim.g.floaty')
+ eq(NIL, fn.luaeval 'vim.g.nonexistent')
+ eq(NIL, fn.luaeval 'vim.g.nullvar')
-- lost over RPC, so test locally:
eq(
{ false, true },
@@ -1439,11 +1439,11 @@ describe('lua stdlib', function()
]]
)
- eq({ hello = 'world' }, funcs.luaeval 'vim.g.to_delete')
+ eq({ hello = 'world' }, fn.luaeval 'vim.g.to_delete')
exec_lua [[
vim.g.to_delete = nil
]]
- eq(NIL, funcs.luaeval 'vim.g.to_delete')
+ eq(NIL, fn.luaeval 'vim.g.to_delete')
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.g[0].testing'))
@@ -1453,7 +1453,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.g.AddCounter = add_counter
vim.g.GetCounter = get_counter
- vim.g.funcs = {add = add_counter, get = get_counter}
+ vim.g.fn = {add = add_counter, get = get_counter}
vim.g.AddParens = function(s) return '(' .. s .. ')' end
]]
@@ -1466,10 +1466,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.g.GetCounter()]]))
exec_lua([[vim.api.nvim_get_var('AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]]))
- exec_lua([[vim.g.funcs.add()]])
- eq(5, exec_lua([[return vim.g.funcs.get()]]))
- exec_lua([[vim.api.nvim_get_var('funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]]))
+ exec_lua([[vim.g.fn.add()]])
+ eq(5, exec_lua([[return vim.g.fn.get()]]))
+ exec_lua([[vim.api.nvim_get_var('fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]]))
eq('((foo))', eval([['foo'->AddParens()->AddParens()]]))
exec_lua [[
@@ -1478,7 +1478,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.api.nvim_set_var('AddCounter', add_counter)
vim.api.nvim_set_var('GetCounter', get_counter)
- vim.api.nvim_set_var('funcs', {add = add_counter, get = get_counter})
+ vim.api.nvim_set_var('fn', {add = add_counter, get = get_counter})
vim.api.nvim_set_var('AddParens', function(s) return '(' .. s .. ')' end)
]]
@@ -1491,10 +1491,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.g.GetCounter()]]))
exec_lua([[vim.api.nvim_get_var('AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]]))
- exec_lua([[vim.g.funcs.add()]])
- eq(5, exec_lua([[return vim.g.funcs.get()]]))
- exec_lua([[vim.api.nvim_get_var('funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]]))
+ exec_lua([[vim.g.fn.add()]])
+ eq(5, exec_lua([[return vim.g.fn.get()]]))
+ exec_lua([[vim.api.nvim_get_var('fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]]))
eq('((foo))', eval([['foo'->AddParens()->AddParens()]]))
exec([[
@@ -1534,13 +1534,13 @@ describe('lua stdlib', function()
vim.api.nvim_buf_set_var(BUF, "testing", "bye")
]]
- eq('hi', funcs.luaeval 'vim.b.testing')
- eq('bye', funcs.luaeval 'vim.b[BUF].testing')
- eq(123, funcs.luaeval 'vim.b.other')
- eq(5120.1, funcs.luaeval 'vim.b.floaty')
- eq(NIL, funcs.luaeval 'vim.b.nonexistent')
- eq(NIL, funcs.luaeval 'vim.b[BUF].nonexistent')
- eq(NIL, funcs.luaeval 'vim.b.nullvar')
+ eq('hi', fn.luaeval 'vim.b.testing')
+ eq('bye', fn.luaeval 'vim.b[BUF].testing')
+ eq(123, fn.luaeval 'vim.b.other')
+ eq(5120.1, fn.luaeval 'vim.b.floaty')
+ eq(NIL, fn.luaeval 'vim.b.nonexistent')
+ eq(NIL, fn.luaeval 'vim.b[BUF].nonexistent')
+ eq(NIL, fn.luaeval 'vim.b.nullvar')
-- lost over RPC, so test locally:
eq(
{ false, true },
@@ -1551,11 +1551,11 @@ describe('lua stdlib', function()
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.b[BUF][0].testing'))
- eq({ hello = 'world' }, funcs.luaeval 'vim.b.to_delete')
+ eq({ hello = 'world' }, fn.luaeval 'vim.b.to_delete')
exec_lua [[
vim.b.to_delete = nil
]]
- eq(NIL, funcs.luaeval 'vim.b.to_delete')
+ eq(NIL, fn.luaeval 'vim.b.to_delete')
exec_lua [[
local counter = 0
@@ -1563,7 +1563,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.b.AddCounter = add_counter
vim.b.GetCounter = get_counter
- vim.b.funcs = {add = add_counter, get = get_counter}
+ vim.b.fn = {add = add_counter, get = get_counter}
vim.b.AddParens = function(s) return '(' .. s .. ')' end
]]
@@ -1576,10 +1576,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.b.GetCounter()]]))
exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.b.funcs.add()]])
- eq(5, exec_lua([[return vim.b.funcs.get()]]))
- exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.b.fn.add()]])
+ eq(5, exec_lua([[return vim.b.fn.get()]]))
+ exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]]))
exec_lua [[
@@ -1588,7 +1588,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.api.nvim_buf_set_var(0, 'AddCounter', add_counter)
vim.api.nvim_buf_set_var(0, 'GetCounter', get_counter)
- vim.api.nvim_buf_set_var(0, 'funcs', {add = add_counter, get = get_counter})
+ vim.api.nvim_buf_set_var(0, 'fn', {add = add_counter, get = get_counter})
vim.api.nvim_buf_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end)
]]
@@ -1601,10 +1601,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.b.GetCounter()]]))
exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.b.funcs.add()]])
- eq(5, exec_lua([[return vim.b.funcs.get()]]))
- exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.b.fn.add()]])
+ eq(5, exec_lua([[return vim.b.fn.get()]]))
+ exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]]))
exec([[
@@ -1622,9 +1622,9 @@ describe('lua stdlib', function()
vim.cmd "vnew"
]]
- eq(NIL, funcs.luaeval 'vim.b.testing')
- eq(NIL, funcs.luaeval 'vim.b.other')
- eq(NIL, funcs.luaeval 'vim.b.nonexistent')
+ eq(NIL, fn.luaeval 'vim.b.testing')
+ eq(NIL, fn.luaeval 'vim.b.other')
+ eq(NIL, fn.luaeval 'vim.b.nonexistent')
end)
it('vim.w', function()
@@ -1640,19 +1640,19 @@ describe('lua stdlib', function()
vim.api.nvim_win_set_var(WIN, "testing", "bye")
]]
- eq('hi', funcs.luaeval 'vim.w.testing')
- eq('bye', funcs.luaeval 'vim.w[WIN].testing')
- eq(123, funcs.luaeval 'vim.w.other')
- eq(NIL, funcs.luaeval 'vim.w.nonexistent')
- eq(NIL, funcs.luaeval 'vim.w[WIN].nonexistent')
+ eq('hi', fn.luaeval 'vim.w.testing')
+ eq('bye', fn.luaeval 'vim.w[WIN].testing')
+ eq(123, fn.luaeval 'vim.w.other')
+ eq(NIL, fn.luaeval 'vim.w.nonexistent')
+ eq(NIL, fn.luaeval 'vim.w[WIN].nonexistent')
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.w[WIN][0].testing'))
- eq({ hello = 'world' }, funcs.luaeval 'vim.w.to_delete')
+ eq({ hello = 'world' }, fn.luaeval 'vim.w.to_delete')
exec_lua [[
vim.w.to_delete = nil
]]
- eq(NIL, funcs.luaeval 'vim.w.to_delete')
+ eq(NIL, fn.luaeval 'vim.w.to_delete')
exec_lua [[
local counter = 0
@@ -1660,7 +1660,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.w.AddCounter = add_counter
vim.w.GetCounter = get_counter
- vim.w.funcs = {add = add_counter, get = get_counter}
+ vim.w.fn = {add = add_counter, get = get_counter}
vim.w.AddParens = function(s) return '(' .. s .. ')' end
]]
@@ -1673,10 +1673,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.w.GetCounter()]]))
exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.w.funcs.add()]])
- eq(5, exec_lua([[return vim.w.funcs.get()]]))
- exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.w.fn.add()]])
+ eq(5, exec_lua([[return vim.w.fn.get()]]))
+ exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]]))
exec_lua [[
@@ -1685,7 +1685,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.api.nvim_win_set_var(0, 'AddCounter', add_counter)
vim.api.nvim_win_set_var(0, 'GetCounter', get_counter)
- vim.api.nvim_win_set_var(0, 'funcs', {add = add_counter, get = get_counter})
+ vim.api.nvim_win_set_var(0, 'fn', {add = add_counter, get = get_counter})
vim.api.nvim_win_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end)
]]
@@ -1698,10 +1698,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.w.GetCounter()]]))
exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.w.funcs.add()]])
- eq(5, exec_lua([[return vim.w.funcs.get()]]))
- exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.w.fn.add()]])
+ eq(5, exec_lua([[return vim.w.fn.get()]]))
+ exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]]))
exec([[
@@ -1719,9 +1719,9 @@ describe('lua stdlib', function()
vim.cmd "vnew"
]]
- eq(NIL, funcs.luaeval 'vim.w.testing')
- eq(NIL, funcs.luaeval 'vim.w.other')
- eq(NIL, funcs.luaeval 'vim.w.nonexistent')
+ eq(NIL, fn.luaeval 'vim.w.testing')
+ eq(NIL, fn.luaeval 'vim.w.other')
+ eq(NIL, fn.luaeval 'vim.w.nonexistent')
end)
it('vim.t', function()
@@ -1731,20 +1731,20 @@ describe('lua stdlib', function()
vim.api.nvim_tabpage_set_var(0, "to_delete", {hello="world"})
]]
- eq('hi', funcs.luaeval 'vim.t.testing')
- eq(123, funcs.luaeval 'vim.t.other')
- eq(NIL, funcs.luaeval 'vim.t.nonexistent')
- eq('hi', funcs.luaeval 'vim.t[0].testing')
- eq(123, funcs.luaeval 'vim.t[0].other')
- eq(NIL, funcs.luaeval 'vim.t[0].nonexistent')
+ eq('hi', fn.luaeval 'vim.t.testing')
+ eq(123, fn.luaeval 'vim.t.other')
+ eq(NIL, fn.luaeval 'vim.t.nonexistent')
+ eq('hi', fn.luaeval 'vim.t[0].testing')
+ eq(123, fn.luaeval 'vim.t[0].other')
+ eq(NIL, fn.luaeval 'vim.t[0].nonexistent')
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing'))
- eq({ hello = 'world' }, funcs.luaeval 'vim.t.to_delete')
+ eq({ hello = 'world' }, fn.luaeval 'vim.t.to_delete')
exec_lua [[
vim.t.to_delete = nil
]]
- eq(NIL, funcs.luaeval 'vim.t.to_delete')
+ eq(NIL, fn.luaeval 'vim.t.to_delete')
exec_lua [[
local counter = 0
@@ -1752,7 +1752,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.t.AddCounter = add_counter
vim.t.GetCounter = get_counter
- vim.t.funcs = {add = add_counter, get = get_counter}
+ vim.t.fn = {add = add_counter, get = get_counter}
vim.t.AddParens = function(s) return '(' .. s .. ')' end
]]
@@ -1765,10 +1765,10 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.t.GetCounter()]]))
exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.t.funcs.add()]])
- eq(5, exec_lua([[return vim.t.funcs.get()]]))
- exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.t.fn.add()]])
+ eq(5, exec_lua([[return vim.t.fn.get()]]))
+ exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]]))
exec_lua [[
@@ -1777,7 +1777,7 @@ describe('lua stdlib', function()
local function get_counter() return counter end
vim.api.nvim_tabpage_set_var(0, 'AddCounter', add_counter)
vim.api.nvim_tabpage_set_var(0, 'GetCounter', get_counter)
- vim.api.nvim_tabpage_set_var(0, 'funcs', {add = add_counter, get = get_counter})
+ vim.api.nvim_tabpage_set_var(0, 'fn', {add = add_counter, get = get_counter})
vim.api.nvim_tabpage_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end)
]]
@@ -1790,45 +1790,45 @@ describe('lua stdlib', function()
eq(3, exec_lua([[return vim.t.GetCounter()]]))
exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]])
eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]]))
- exec_lua([[vim.t.funcs.add()]])
- eq(5, exec_lua([[return vim.t.funcs.get()]]))
- exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]])
- eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]]))
+ exec_lua([[vim.t.fn.add()]])
+ eq(5, exec_lua([[return vim.t.fn.get()]]))
+ exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]])
+ eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]]))
eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]]))
exec_lua [[
vim.cmd "tabnew"
]]
- eq(NIL, funcs.luaeval 'vim.t.testing')
- eq(NIL, funcs.luaeval 'vim.t.other')
- eq(NIL, funcs.luaeval 'vim.t.nonexistent')
+ eq(NIL, fn.luaeval 'vim.t.testing')
+ eq(NIL, fn.luaeval 'vim.t.other')
+ eq(NIL, fn.luaeval 'vim.t.nonexistent')
end)
it('vim.env', function()
exec_lua([[vim.fn.setenv('A', 123)]])
- eq('123', funcs.luaeval('vim.env.A'))
+ eq('123', fn.luaeval('vim.env.A'))
exec_lua([[vim.env.A = 456]])
- eq('456', funcs.luaeval('vim.env.A'))
+ eq('456', fn.luaeval('vim.env.A'))
exec_lua([[vim.env.A = nil]])
- eq(NIL, funcs.luaeval('vim.env.A'))
+ eq(NIL, fn.luaeval('vim.env.A'))
- eq(true, funcs.luaeval('vim.env.B == nil'))
+ eq(true, fn.luaeval('vim.env.B == nil'))
command([[let $HOME = 'foo']])
- eq('foo', funcs.expand('~'))
- eq('foo', funcs.luaeval('vim.env.HOME'))
+ eq('foo', fn.expand('~'))
+ eq('foo', fn.luaeval('vim.env.HOME'))
exec_lua([[vim.env.HOME = nil]])
- eq('foo', funcs.expand('~'))
+ eq('foo', fn.expand('~'))
exec_lua([[vim.env.HOME = 'bar']])
- eq('bar', funcs.expand('~'))
- eq('bar', funcs.luaeval('vim.env.HOME'))
+ eq('bar', fn.expand('~'))
+ eq('bar', fn.luaeval('vim.env.HOME'))
end)
it('vim.v', function()
- eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval 'vim.v.progpath')
- eq(false, funcs.luaeval "vim.v['false']")
- eq(NIL, funcs.luaeval 'vim.v.null')
+ eq(fn.luaeval "vim.api.nvim_get_vvar('progpath')", fn.luaeval 'vim.v.progpath')
+ eq(false, fn.luaeval "vim.v['false']")
+ eq(NIL, fn.luaeval 'vim.v.null')
matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath'))
eq('Key is read-only: count', pcall_err(exec_lua, [[vim.v.count = 42]]))
eq('Dictionary is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]]))
@@ -1845,18 +1845,18 @@ describe('lua stdlib', function()
eq({}, eval('v:oldfiles'))
feed('i foo foo foo<Esc>0/foo<CR>')
- eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
+ eq({ 1, 1 }, api.nvim_win_get_cursor(0))
eq(1, eval('v:searchforward'))
feed('n')
- eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
+ eq({ 1, 5 }, api.nvim_win_get_cursor(0))
exec_lua([[vim.v.searchforward = 0]])
eq(0, eval('v:searchforward'))
feed('n')
- eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
+ eq({ 1, 1 }, api.nvim_win_get_cursor(0))
exec_lua([[vim.v.searchforward = 1]])
eq(1, eval('v:searchforward'))
feed('n')
- eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
+ eq({ 1, 5 }, api.nvim_win_get_cursor(0))
local screen = Screen.new(60, 3)
screen:set_default_attr_ids({
@@ -1893,21 +1893,21 @@ describe('lua stdlib', function()
end)
it('vim.bo', function()
- eq('', funcs.luaeval 'vim.bo.filetype')
+ eq('', fn.luaeval 'vim.bo.filetype')
exec_lua [[
vim.api.nvim_set_option_value("filetype", "markdown", {})
BUF = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_option_value("modifiable", false, {buf = BUF})
]]
- eq(false, funcs.luaeval 'vim.bo.modified')
- eq('markdown', funcs.luaeval 'vim.bo.filetype')
- eq(false, funcs.luaeval 'vim.bo[BUF].modifiable')
+ eq(false, fn.luaeval 'vim.bo.modified')
+ eq('markdown', fn.luaeval 'vim.bo.filetype')
+ eq(false, fn.luaeval 'vim.bo[BUF].modifiable')
exec_lua [[
vim.bo.filetype = ''
vim.bo[BUF].modifiable = true
]]
- eq('', funcs.luaeval 'vim.bo.filetype')
- eq(true, funcs.luaeval 'vim.bo[BUF].modifiable')
+ eq('', fn.luaeval 'vim.bo.filetype')
+ eq(true, fn.luaeval 'vim.bo[BUF].modifiable')
matches("Unknown option 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
matches('Expected Lua string$', pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
matches('Invalid buffer id: %-1$', pcall_err(exec_lua, 'return vim.bo[-1].filetype'))
@@ -1919,32 +1919,32 @@ describe('lua stdlib', function()
vim.cmd "split"
vim.api.nvim_set_option_value("cole", 2, {})
]]
- eq(2, funcs.luaeval 'vim.wo.cole')
+ eq(2, fn.luaeval 'vim.wo.cole')
exec_lua [[
vim.wo.conceallevel = 0
]]
- eq(0, funcs.luaeval 'vim.wo.cole')
- eq(0, funcs.luaeval 'vim.wo[0].cole')
- eq(0, funcs.luaeval 'vim.wo[1001].cole')
+ eq(0, fn.luaeval 'vim.wo.cole')
+ eq(0, fn.luaeval 'vim.wo[0].cole')
+ eq(0, fn.luaeval 'vim.wo[1001].cole')
matches("Unknown option 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt'))
matches('Invalid window id: %-1$', pcall_err(exec_lua, 'return vim.wo[-1].list'))
- eq(2, funcs.luaeval 'vim.wo[1000].cole')
+ eq(2, fn.luaeval 'vim.wo[1000].cole')
exec_lua [[
vim.wo[1000].cole = 0
]]
- eq(0, funcs.luaeval 'vim.wo[1000].cole')
+ eq(0, fn.luaeval 'vim.wo[1000].cole')
-- Can handle global-local values
exec_lua [[vim.o.scrolloff = 100]]
exec_lua [[vim.wo.scrolloff = 200]]
- eq(200, funcs.luaeval 'vim.wo.scrolloff')
+ eq(200, fn.luaeval 'vim.wo.scrolloff')
exec_lua [[vim.wo.scrolloff = -1]]
- eq(100, funcs.luaeval 'vim.wo.scrolloff')
+ eq(100, fn.luaeval 'vim.wo.scrolloff')
exec_lua [[
vim.wo[0][0].scrolloff = 200
vim.cmd "enew"
]]
- eq(100, funcs.luaeval 'vim.wo.scrolloff')
+ eq(100, fn.luaeval 'vim.wo.scrolloff')
end)
describe('vim.opt', function()
@@ -2866,15 +2866,15 @@ describe('lua stdlib', function()
vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('<abuf>')"
vim.cmd "new"
]]
- eq('2', funcs.luaeval 'BUF')
- eq(2, funcs.luaeval '#vim.api.nvim_list_bufs()')
+ eq('2', fn.luaeval 'BUF')
+ eq(2, fn.luaeval '#vim.api.nvim_list_bufs()')
-- vim.cmd can be indexed with a command name
exec_lua [[
vim.cmd.let 'g:var = 2'
]]
- eq(2, funcs.luaeval 'vim.g.var')
+ eq(2, fn.luaeval 'vim.g.var')
end)
it('vim.regex', function()
@@ -2886,7 +2886,7 @@ describe('lua stdlib', function()
eq({}, exec_lua [[return {re1:match_str("x ac")}]])
eq({ 3, 7 }, exec_lua [[return {re1:match_str("ac abbc")}]])
- meths.nvim_buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' })
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' })
eq({}, exec_lua [[return {re1:match_line(0, 0)}]])
eq({ 0, 3 }, exec_lua [[return {re1:match_line(0, 1)}]])
eq({ 3, 7 }, exec_lua [[return {re1:match_line(0, 1, 1)}]])
@@ -2970,10 +2970,10 @@ describe('lua stdlib', function()
it('allows removing on_key listeners', function()
-- Create some unused namespaces
- meths.nvim_create_namespace('unused1')
- meths.nvim_create_namespace('unused2')
- meths.nvim_create_namespace('unused3')
- meths.nvim_create_namespace('unused4')
+ api.nvim_create_namespace('unused1')
+ api.nvim_create_namespace('unused2')
+ api.nvim_create_namespace('unused3')
+ api.nvim_create_namespace('unused4')
insert([[hello world]])
@@ -3303,8 +3303,8 @@ describe('lua stdlib', function()
describe('returns -2 when interrupted', function()
before_each(function()
- local channel = meths.nvim_get_api_info()[1]
- meths.nvim_set_var('channel', channel)
+ local channel = api.nvim_get_api_info()[1]
+ api.nvim_set_var('channel', channel)
end)
it('without callback', function()
@@ -3408,14 +3408,14 @@ describe('lua stdlib', function()
describe('vim.api.nvim_buf_call', function()
it('can access buf options', function()
- local buf1 = meths.nvim_get_current_buf().id
+ local buf1 = api.nvim_get_current_buf().id
local buf2 = exec_lua [[
buf2 = vim.api.nvim_create_buf(false, true)
return buf2
]]
- eq(false, meths.nvim_get_option_value('autoindent', { buf = buf1 }))
- eq(false, meths.nvim_get_option_value('autoindent', { buf = buf2 }))
+ eq(false, api.nvim_get_option_value('autoindent', { buf = buf1 }))
+ eq(false, api.nvim_get_option_value('autoindent', { buf = buf2 }))
local val = exec_lua [[
return vim.api.nvim_buf_call(buf2, function()
@@ -3424,9 +3424,9 @@ describe('lua stdlib', function()
end)
]]
- eq(false, meths.nvim_get_option_value('autoindent', { buf = buf1 }))
- eq(true, meths.nvim_get_option_value('autoindent', { buf = buf2 }))
- eq(buf1, meths.nvim_get_current_buf().id)
+ eq(false, api.nvim_get_option_value('autoindent', { buf = buf1 }))
+ eq(true, api.nvim_get_option_value('autoindent', { buf = buf2 }))
+ eq(buf1, api.nvim_get_current_buf().id)
eq(buf2, val)
end)
@@ -3488,7 +3488,7 @@ describe('lua stdlib', function()
describe('vim.api.nvim_win_call', function()
it('can access window options', function()
command('vsplit')
- local win1 = meths.nvim_get_current_win().id
+ local win1 = api.nvim_get_current_win().id
command('wincmd w')
local win2 = exec_lua [[
win2 = vim.api.nvim_get_current_win()
@@ -3496,8 +3496,8 @@ describe('lua stdlib', function()
]]
command('wincmd p')
- eq('', meths.nvim_get_option_value('winhighlight', { win = win1 }))
- eq('', meths.nvim_get_option_value('winhighlight', { win = win2 }))
+ eq('', api.nvim_get_option_value('winhighlight', { win = win1 }))
+ eq('', api.nvim_get_option_value('winhighlight', { win = win2 }))
local val = exec_lua [[
return vim.api.nvim_win_call(win2, function()
@@ -3506,9 +3506,9 @@ describe('lua stdlib', function()
end)
]]
- eq('', meths.nvim_get_option_value('winhighlight', { win = win1 }))
- eq('Normal:Normal', meths.nvim_get_option_value('winhighlight', { win = win2 }))
- eq(win1, meths.nvim_get_current_win().id)
+ eq('', api.nvim_get_option_value('winhighlight', { win = win1 }))
+ eq('Normal:Normal', api.nvim_get_option_value('winhighlight', { win = win2 }))
+ eq(win1, api.nvim_get_current_win().id)
eq(win2, val)
end)
@@ -3819,15 +3819,13 @@ describe('lua: builtin modules', function()
clear()
command("let $VIMRUNTIME='fixtures/a'")
-- Use system([nvim,…]) instead of clear() to avoid stderr noise. #21844
- local out = funcs
- .system({
- nvim_prog,
- '--clean',
- '--luamod-dev',
- [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]],
- '+qa!',
- })
- :gsub('\r\n', '\n')
+ local out = fn.system({
+ nvim_prog,
+ '--clean',
+ '--luamod-dev',
+ [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]],
+ '+qa!',
+ }):gsub('\r\n', '\n')
eq(1, eval('v:shell_error'))
matches("'vim%.shared' not found", out)
end)
@@ -3882,7 +3880,7 @@ describe('vim.keymap', function()
feed('aa')
- eq({ 'π<M-π>foo<' }, meths.nvim_buf_get_lines(0, 0, -1, false))
+ eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
it('can overwrite a mapping', function()
@@ -4001,14 +3999,14 @@ describe('Vimscript function exists()', function()
]]
)
- eq(1, funcs.exists('v:lua.require("mpack").decode'))
- eq(1, funcs.exists("v:lua.require('mpack').decode"))
- eq(1, funcs.exists('v:lua.require"mpack".decode'))
- eq(1, funcs.exists("v:lua.require'mpack'.decode"))
- eq(1, funcs.exists("v:lua.require('vim.lsp').start"))
- eq(1, funcs.exists('v:lua.require"vim.lsp".start'))
- eq(1, funcs.exists("v:lua.require'vim.lsp'.start"))
- eq(0, funcs.exists("v:lua.require'vim.lsp'.unknown"))
- eq(0, funcs.exists('v:lua.?'))
+ eq(1, fn.exists('v:lua.require("mpack").decode'))
+ eq(1, fn.exists("v:lua.require('mpack').decode"))
+ eq(1, fn.exists('v:lua.require"mpack".decode'))
+ eq(1, fn.exists("v:lua.require'mpack'.decode"))
+ eq(1, fn.exists("v:lua.require('vim.lsp').start"))
+ eq(1, fn.exists('v:lua.require"vim.lsp".start'))
+ eq(1, fn.exists("v:lua.require'vim.lsp'.start"))
+ eq(0, fn.exists("v:lua.require'vim.lsp'.unknown"))
+ eq(0, fn.exists('v:lua.?'))
end)
end)