mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
test: typing for helpers.meths
This commit is contained in:
@@ -54,9 +54,9 @@ end)
|
||||
describe('lua buffer event callbacks: on_lines', function()
|
||||
local function setup_eventcheck(verify, utf_sizes, lines)
|
||||
local lastsize
|
||||
meths.buf_set_lines(0, 0, -1, true, lines)
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, lines)
|
||||
if verify then
|
||||
lastsize = meths.buf_get_offset(0, meths.buf_line_count(0))
|
||||
lastsize = meths.nvim_buf_get_offset(0, meths.nvim_buf_line_count(0))
|
||||
end
|
||||
exec_lua('return test_register(...)', 0, 'on_lines', 'test1', false, utf_sizes)
|
||||
local verify_name = 'test1'
|
||||
@@ -76,8 +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.buf_get_offset(0, endline) - meths.buf_get_offset(0, startline)
|
||||
local newsize = meths.buf_get_offset(0, meths.buf_line_count(0))
|
||||
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 oldrange = newrange + lastsize - newsize
|
||||
eq(oldrange, event[8])
|
||||
lastsize = newsize
|
||||
@@ -97,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.buf_get_changedtick(0)
|
||||
local tick = meths.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.buf_set_lines(0, 3, 5, true, { 'changed line' })
|
||||
meths.nvim_buf_set_lines(0, 3, 5, true, { 'changed line' })
|
||||
tick = tick + 1
|
||||
check_events { { 'test1', 'lines', 1, tick, 3, 5, 4, 32 } }
|
||||
|
||||
@@ -141,7 +142,7 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
-- simulate next callback returning true
|
||||
exec_lua("test_unreg = 'test1'")
|
||||
|
||||
meths.buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' })
|
||||
meths.nvim_buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' })
|
||||
tick = tick + 1
|
||||
|
||||
-- plugins can opt in to receive changedtick events, or choose
|
||||
@@ -153,7 +154,7 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
|
||||
verify_name 'test2'
|
||||
|
||||
meths.buf_set_lines(0, 1, 1, true, { 'added' })
|
||||
meths.nvim_buf_set_lines(0, 1, 1, true, { 'added' })
|
||||
tick = tick + 1
|
||||
check_events { { 'test2', 'lines', 1, tick, 1, 1, 2, 0 } }
|
||||
|
||||
@@ -205,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.buf_get_changedtick(0)
|
||||
local tick = meths.nvim_buf_get_changedtick(0)
|
||||
|
||||
feed('ggdd')
|
||||
tick = tick + 1
|
||||
@@ -253,7 +254,7 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
end)
|
||||
|
||||
it('has valid cursor position while shifting', function()
|
||||
meths.buf_set_lines(0, 0, -1, true, { 'line1' })
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, { 'line1' })
|
||||
exec_lua([[
|
||||
vim.api.nvim_buf_attach(0, false, {
|
||||
on_lines = function()
|
||||
@@ -262,15 +263,15 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
})
|
||||
]])
|
||||
feed('>>')
|
||||
eq(1, meths.get_var('listener_cursor_line'))
|
||||
eq(1, meths.nvim_get_var('listener_cursor_line'))
|
||||
end)
|
||||
|
||||
it('has valid cursor position while deleting lines', function()
|
||||
meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' })
|
||||
meths.win_set_cursor(0, { 2, 0 })
|
||||
eq(2, meths.win_get_cursor(0)[1])
|
||||
meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' })
|
||||
eq(2, meths.win_get_cursor(0)[1])
|
||||
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])
|
||||
end)
|
||||
|
||||
it('does not SEGFAULT when accessing window buffer info in on_detach #14998', function()
|
||||
@@ -298,7 +299,7 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
end)
|
||||
|
||||
it('#12718 lnume', function()
|
||||
meths.buf_set_lines(0, 0, -1, true, { '1', '2', '3' })
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, { '1', '2', '3' })
|
||||
exec_lua([[
|
||||
vim.api.nvim_buf_attach(0, false, {
|
||||
on_lines = function(...)
|
||||
@@ -311,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.get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 })
|
||||
eq(meths.nvim_get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 })
|
||||
|
||||
feed('2G0')
|
||||
feed('p')
|
||||
eq(meths.get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 })
|
||||
eq(meths.nvim_get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 })
|
||||
|
||||
feed('1G0')
|
||||
feed('P')
|
||||
eq(meths.get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 })
|
||||
eq(meths.nvim_get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 })
|
||||
end)
|
||||
|
||||
it(
|
||||
@@ -333,7 +334,7 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
})
|
||||
]])
|
||||
feed('itest123<Esc><C-A>')
|
||||
eq('test124', meths.get_current_line())
|
||||
eq('test124', meths.nvim_get_current_line())
|
||||
end
|
||||
)
|
||||
end)
|
||||
@@ -345,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.buf_set_lines(0, 0, -1, true, start_txt)
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, start_txt)
|
||||
else
|
||||
start_txt = meths.buf_get_lines(0, 0, -1, true)
|
||||
start_txt = meths.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.buf_get_offset(0, meths.buf_line_count(0))
|
||||
local len = meths.nvim_buf_get_offset(0, meths.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.buf_get_changedtick(0)
|
||||
meths.nvim_buf_get_changedtick(0)
|
||||
|
||||
local verify_name = 'test1'
|
||||
local function check_events(expected)
|
||||
@@ -384,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.buf_get_lines(0, 0, -1, true), '\n') .. '\n'
|
||||
shadowbytes = table.concat(meths.nvim_buf_get_lines(0, 0, -1, true), '\n') .. '\n'
|
||||
end
|
||||
end
|
||||
|
||||
local text = meths.buf_get_lines(0, 0, -1, true)
|
||||
local text = meths.nvim_buf_get_lines(0, 0, -1, true)
|
||||
local bytes = table.concat(text, '\n') .. '\n'
|
||||
|
||||
eq(
|
||||
@@ -425,7 +426,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
|
||||
it('opening lines', function()
|
||||
local check_events = setup_eventcheck(verify, origlines)
|
||||
-- meths.set_option_value('autoindent', true, {})
|
||||
-- meths.nvim_set_option_value('autoindent', true, {})
|
||||
feed 'Go'
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 1 },
|
||||
@@ -438,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.set_option_value('autoindent', true, {})
|
||||
meths.nvim_set_option_value('autoindent', true, {})
|
||||
feed 'Go'
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 5 },
|
||||
@@ -463,7 +464,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
{ 'test1', 'bytes', 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 },
|
||||
}
|
||||
|
||||
local buf_len = meths.buf_line_count(0)
|
||||
local buf_len = meths.nvim_buf_line_count(0)
|
||||
funcs.setline(buf_len + 1, 'baz')
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 },
|
||||
@@ -472,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.set_option_value('formatoptions', 'ro', {})
|
||||
meths.set_option_value('filetype', 'c', {})
|
||||
meths.nvim_set_option_value('formatoptions', 'ro', {})
|
||||
meths.nvim_set_option_value('filetype', 'c', {})
|
||||
feed 'A<CR>'
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 },
|
||||
@@ -611,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.set_option_value('inccommand', 'nosplit', {})
|
||||
meths.nvim_set_option_value('inccommand', 'nosplit', {})
|
||||
|
||||
-- linewise substitute
|
||||
feed(':%s/bcd/')
|
||||
@@ -696,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.buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' })
|
||||
meths.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.buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' })
|
||||
meths.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.buf_get_lines(0, 0, -1, true)
|
||||
meths.nvim_buf_get_lines(0, 0, -1, true)
|
||||
)
|
||||
end)
|
||||
|
||||
it('nvim_buf_set_text replace', function()
|
||||
local check_events = setup_eventcheck(verify, origlines)
|
||||
|
||||
meths.buf_set_text(0, 2, 3, 2, 8, { 'very text' })
|
||||
meths.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.buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' })
|
||||
meths.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.buf_set_text(0, 0, 8, 1, 2, { 'JOINY' })
|
||||
meths.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.buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' })
|
||||
meths.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 },
|
||||
}
|
||||
@@ -742,20 +743,20 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
'line l line 4',
|
||||
'was 5,6',
|
||||
' indented line',
|
||||
}, meths.buf_get_lines(0, 0, -1, true))
|
||||
}, meths.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.buf_set_text(0, 0, 0, 1, 0, {})
|
||||
meths.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.buf_set_text(0, 4, 15, 5, 17, { '' })
|
||||
meths.nvim_buf_set_text(0, 4, 15, 5, 17, { '' })
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 },
|
||||
}
|
||||
@@ -765,7 +766,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
'original line 4',
|
||||
'original line 5',
|
||||
'original line 6',
|
||||
}, meths.buf_get_lines(0, 0, -1, true))
|
||||
}, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
end)
|
||||
|
||||
it('checktime autoread', function()
|
||||
@@ -800,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.buf_get_lines(0, 0, -1, true))
|
||||
eq({ 'new line 1 new line 2', 'new line 3' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
-- check we can undo and redo a reload event.
|
||||
feed 'u'
|
||||
@@ -924,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.buf_set_extmark(0, ns, 0, 0, {})
|
||||
meths.nvim_buf_set_extmark(0, ns, 0, 0, {})
|
||||
|
||||
eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true))
|
||||
eq({ '12345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
-- splice
|
||||
feed('gg0d2l')
|
||||
|
||||
eq({ '345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true))
|
||||
eq({ '345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
-- move
|
||||
command('.m+1')
|
||||
|
||||
eq({ 'hello world', '345' }, meths.buf_get_lines(0, 0, -1, true))
|
||||
eq({ 'hello world', '345' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
-- reload undofile and undo changes
|
||||
command('w')
|
||||
@@ -949,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.buf_get_lines(0, 0, -1, true))
|
||||
eq({ '345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 },
|
||||
@@ -957,7 +958,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
}
|
||||
|
||||
feed('u')
|
||||
eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true))
|
||||
eq({ '12345', 'hello world' }, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
|
||||
check_events {
|
||||
{ 'test1', 'bytes', 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 },
|
||||
@@ -968,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.buf_get_lines(0, 0, -1, true))
|
||||
-- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
feed('gg0<c-v>jj$d')
|
||||
|
||||
check_events {
|
||||
@@ -1022,7 +1023,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
it('virtual edit', function()
|
||||
local check_events = setup_eventcheck(verify, { '', ' ' })
|
||||
|
||||
meths.set_option_value('virtualedit', 'all', {})
|
||||
meths.nvim_set_option_value('virtualedit', 'all', {})
|
||||
|
||||
feed [[<Right><Right>iab<ESC>]]
|
||||
|
||||
@@ -1076,20 +1077,20 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
local check_events = setup_eventcheck(verify, { 'AAA', 'BBB' })
|
||||
|
||||
-- delete
|
||||
meths.buf_set_lines(0, 0, 1, true, {})
|
||||
meths.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.buf_set_lines(0, 0, 0, true, { 'asdf' })
|
||||
meths.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.buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' })
|
||||
meths.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 },
|
||||
}
|
||||
@@ -1201,13 +1202,13 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
||||
command('diffthis')
|
||||
command('new')
|
||||
command('diffthis')
|
||||
meths.buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' })
|
||||
meths.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.buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' })
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' })
|
||||
feed('<C-w>pG')
|
||||
command('diffget')
|
||||
check_events {
|
||||
@@ -1249,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.buf_get_lines(0, 0, -1, true), '|'))
|
||||
eq('CCC|BBBB|', table.concat(meths.nvim_buf_get_lines(0, 0, -1, true), '|'))
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ describe(':lua command', function()
|
||||
it('accepts embedded NLs without heredoc', function()
|
||||
-- Such code is usually used for `:execute 'lua' {generated_string}`:
|
||||
-- heredocs do not work in this case.
|
||||
meths.command([[
|
||||
meths.nvim_command([[
|
||||
lua
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
|
||||
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
|
||||
|
||||
@@ -165,6 +165,6 @@ describe('filetype.lua', function()
|
||||
clear({
|
||||
args = { '--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md' },
|
||||
})
|
||||
eq('notmarkdown', meths.get_option_value('filetype', {}))
|
||||
eq('notmarkdown', meths.nvim_get_option_value('filetype', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -48,13 +48,13 @@ describe('vim.uv', function()
|
||||
end)()
|
||||
]]
|
||||
|
||||
eq(0, meths.get_var('coroutine_cnt'))
|
||||
eq(0, meths.nvim_get_var('coroutine_cnt'))
|
||||
exec_lua(code)
|
||||
retry(2, nil, function()
|
||||
sleep(50)
|
||||
eq(2, meths.get_var('coroutine_cnt'))
|
||||
eq(2, meths.nvim_get_var('coroutine_cnt'))
|
||||
end)
|
||||
eq(3, meths.get_var('coroutine_cnt_1'))
|
||||
eq(3, meths.nvim_get_var('coroutine_cnt_1'))
|
||||
end)
|
||||
|
||||
it('is API safe', function()
|
||||
|
||||
@@ -67,17 +67,17 @@ describe('luaeval()', function()
|
||||
describe('strings with NULs', function()
|
||||
it('are successfully converted to blobs', function()
|
||||
command([[let s = luaeval('"\0"')]])
|
||||
eq('\000', meths.get_var('s'))
|
||||
eq('\000', meths.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.get_var('d'))
|
||||
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'))
|
||||
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.get_var('l'))
|
||||
eq({'abc', 'a\000b', 'c\000d', 'def'}, meths.nvim_get_var('l'))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -411,14 +411,14 @@ describe('luaeval()', function()
|
||||
end)
|
||||
|
||||
it('correctly converts self-containing containers', function()
|
||||
meths.set_var('l', {})
|
||||
meths.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.set_var('d', {foo=42})
|
||||
meths.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])'))
|
||||
@@ -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.get_current_line())
|
||||
eq("hey eval", meths.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.get_current_line())
|
||||
eq("hey there", meths.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.get_current_line())
|
||||
eq("hey command", meths.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.set_option_value('omnifunc', 'v:lua.mymod.omni', {})
|
||||
meths.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.set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
|
||||
meths.nvim_set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
|
||||
feed('<Esc>g@g@')
|
||||
eq("hey line", meths.get_current_line())
|
||||
eq("hey line", meths.nvim_get_current_line())
|
||||
end)
|
||||
|
||||
it('supports packages', function()
|
||||
|
||||
@@ -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.set_option_value('more', true, {})
|
||||
meths.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")]])
|
||||
@@ -341,7 +341,7 @@ describe('os.getenv', function()
|
||||
end)
|
||||
it('returns env var set by let', function()
|
||||
local value = 'foo'
|
||||
meths.command('let $XTEST_1 = "' .. value .. '"')
|
||||
meths.nvim_command('let $XTEST_1 = "' .. value .. '"')
|
||||
eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -170,7 +170,7 @@ describe('vim.secure', function()
|
||||
|
||||
-- Cannot write file
|
||||
pcall_err(command, 'write')
|
||||
eq(true, meths.get_option_value('readonly', {}))
|
||||
eq(true, meths.nvim_get_option_value('readonly', {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -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.get_current_line())
|
||||
eq('meow', meths.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.get_current_line())
|
||||
eq('foo', meths.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.get_var('yy'))
|
||||
eq({ 3, NIL }, meths.nvim_get_var('yy'))
|
||||
|
||||
exec_lua([[timer:close()]])
|
||||
end)
|
||||
@@ -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.win_get_cursor(0))
|
||||
eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
|
||||
eq(1, eval('v:searchforward'))
|
||||
feed('n')
|
||||
eq({ 1, 5 }, meths.win_get_cursor(0))
|
||||
eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
|
||||
exec_lua([[vim.v.searchforward = 0]])
|
||||
eq(0, eval('v:searchforward'))
|
||||
feed('n')
|
||||
eq({ 1, 1 }, meths.win_get_cursor(0))
|
||||
eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
|
||||
exec_lua([[vim.v.searchforward = 1]])
|
||||
eq(1, eval('v:searchforward'))
|
||||
feed('n')
|
||||
eq({ 1, 5 }, meths.win_get_cursor(0))
|
||||
eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
|
||||
|
||||
local screen = Screen.new(60, 3)
|
||||
screen:set_default_attr_ids({
|
||||
@@ -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.buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' })
|
||||
meths.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.create_namespace('unused1')
|
||||
meths.create_namespace('unused2')
|
||||
meths.create_namespace('unused3')
|
||||
meths.create_namespace('unused4')
|
||||
meths.nvim_create_namespace('unused1')
|
||||
meths.nvim_create_namespace('unused2')
|
||||
meths.nvim_create_namespace('unused3')
|
||||
meths.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.get_api_info()[1]
|
||||
meths.set_var('channel', channel)
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
meths.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.get_current_buf().id
|
||||
local buf1 = meths.nvim_get_current_buf().id
|
||||
local buf2 = exec_lua [[
|
||||
buf2 = vim.api.nvim_create_buf(false, true)
|
||||
return buf2
|
||||
]]
|
||||
|
||||
eq(false, meths.get_option_value('autoindent', { buf = buf1 }))
|
||||
eq(false, meths.get_option_value('autoindent', { buf = buf2 }))
|
||||
eq(false, meths.nvim_get_option_value('autoindent', { buf = buf1 }))
|
||||
eq(false, meths.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.get_option_value('autoindent', { buf = buf1 }))
|
||||
eq(true, meths.get_option_value('autoindent', { buf = buf2 }))
|
||||
eq(buf1, meths.get_current_buf().id)
|
||||
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(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.get_current_win().id
|
||||
local win1 = meths.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.get_option_value('winhighlight', { win = win1 }))
|
||||
eq('', meths.get_option_value('winhighlight', { win = win2 }))
|
||||
eq('', meths.nvim_get_option_value('winhighlight', { win = win1 }))
|
||||
eq('', meths.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.get_option_value('winhighlight', { win = win1 }))
|
||||
eq('Normal:Normal', meths.get_option_value('winhighlight', { win = win2 }))
|
||||
eq(win1, meths.get_current_win().id)
|
||||
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(win2, val)
|
||||
end)
|
||||
|
||||
@@ -3882,7 +3882,7 @@ describe('vim.keymap', function()
|
||||
|
||||
feed('aa')
|
||||
|
||||
eq({ 'π<M-π>foo<' }, meths.buf_get_lines(0, 0, -1, false))
|
||||
eq({ 'π<M-π>foo<' }, meths.nvim_buf_get_lines(0, 0, -1, false))
|
||||
end)
|
||||
|
||||
it('can overwrite a mapping', function()
|
||||
|
||||
Reference in New Issue
Block a user