diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2024-03-09 15:00:41 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2024-03-09 15:00:41 -0700 |
| commit | 7a7f497b483cd65e340064f23ed1c73425ecba0a (patch) | |
| tree | d5c99ea22a1e10300d06165f8ac96df6b0dc59e1 /test/functional/vimscript | |
| parent | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (diff) | |
| parent | ade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff) | |
| download | rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.gz rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.bz2 rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.zip | |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpost
Diffstat (limited to 'test/functional/vimscript')
43 files changed, 2855 insertions, 2377 deletions
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 0a7e7c1137..4985768bb0 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -1,35 +1,35 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local luv = require('luv') local neq, eq, command = helpers.neq, helpers.eq, helpers.command -local clear, curbufmeths = helpers.clear, helpers.curbufmeths +local clear = helpers.clear local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval +local exec_lua = helpers.exec_lua local insert, pcall_err = helpers.insert, helpers.pcall_err local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed describe('eval-API', function() before_each(clear) - it("work", function() + it('work', function() command("call nvim_command('let g:test = 1')") eq(1, eval("nvim_get_var('test')")) - local buf = eval("nvim_get_current_buf()") - command("call nvim_buf_set_lines("..buf..", 0, -1, v:true, ['aa', 'bb'])") + local buf = eval('nvim_get_current_buf()') + command('call nvim_buf_set_lines(' .. buf .. ", 0, -1, v:true, ['aa', 'bb'])") expect([[ aa bb]]) - command("call nvim_win_set_cursor(0, [1, 1])") + command('call nvim_win_set_cursor(0, [1, 1])') command("call nvim_input('ax<esc>')") expect([[ aax bb]]) end) - it("throw errors for invalid arguments", function() + it('throw errors for invalid arguments', function() local err = exc_exec('call nvim_get_current_buf("foo")') eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err) @@ -37,100 +37,134 @@ describe('eval-API', function() eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err) err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])') - eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err) + eq( + 'Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', + err + ) err = exc_exec('call nvim_buf_set_lines(0, 0, -1, v:true, "string")') - eq('Vim(call):E5555: API call: Wrong type for argument 5 when calling nvim_buf_set_lines, expecting ArrayOf(String)', err) + eq( + 'Vim(call):E5555: API call: Wrong type for argument 5 when calling nvim_buf_set_lines, expecting ArrayOf(String)', + err + ) err = exc_exec('call nvim_buf_get_number("0")') - eq('Vim(call):E5555: API call: Wrong type for argument 1 when calling nvim_buf_get_number, expecting Buffer', err) + eq( + 'Vim(call):E5555: API call: Wrong type for argument 1 when calling nvim_buf_get_number, expecting Buffer', + err + ) err = exc_exec('call nvim_buf_line_count(17)') eq('Vim(call):E5555: API call: Invalid buffer id: 17', err) end) it('cannot change text or window if textlocked', function() - command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])") - matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', - pcall_err(command, "normal! yy")) - - command("autocmd TextYankPost <buffer> ++once call nvim_open_term(0, {})") - matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', - pcall_err(command, "normal! yy")) + command('autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])') + matches( + 'Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', + pcall_err(command, 'normal! yy') + ) + + command('autocmd TextYankPost <buffer> ++once call nvim_open_term(0, {})') + matches( + 'Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', + pcall_err(command, 'normal! yy') + ) -- Functions checking textlock should also not be usable from <expr> mappings. - command("inoremap <expr> <f2> nvim_win_close(0, 1)") - eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window', - pcall_err(command, [[execute "normal i\<f2>"]])) + command('inoremap <expr> <f2> nvim_win_close(0, 1)') + eq( + 'Vim(normal):E5555: API call: E565: Not allowed to change text or change window', + pcall_err(command, [[execute "normal i\<f2>"]]) + ) -- Text-changing functions gave a "Failed to save undo information" error when called from an -- <expr> mapping outside do_cmdline() (msg_list == NULL), so use feed() to test this. command("inoremap <expr> <f2> nvim_buf_set_text(0, 0, 0, 0, 0, ['hi'])") - meths.set_vvar('errmsg', '') - feed("i<f2><esc>") - eq('E5555: API call: E565: Not allowed to change text or change window', - meths.get_vvar('errmsg')) + api.nvim_set_vvar('errmsg', '') + feed('i<f2><esc>') + eq( + 'E5555: API call: E565: Not allowed to change text or change window', + api.nvim_get_vvar('errmsg') + ) -- Some functions checking textlock (usually those that may change the current window or buffer) -- also ought to not be usable in the cmdwin. - local old_win = meths.get_current_win() - feed("q:") - eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.set_current_win, old_win)) + local old_win = api.nvim_get_current_win() + feed('q:') + eq( + 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', + pcall_err(api.nvim_set_current_win, old_win) + ) -- But others, like nvim_buf_set_lines(), which just changes text, is OK. - curbufmeths.set_lines(0, -1, 1, {"wow!"}) - eq({'wow!'}, curbufmeths.get_lines(0, -1, 1)) + api.nvim_buf_set_lines(0, 0, -1, 1, { 'wow!' }) + eq({ 'wow!' }, api.nvim_buf_get_lines(0, 0, -1, 1)) -- Turning the cmdwin buffer into a terminal buffer would be pretty weird. - eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.open_term, 0, {})) + eq( + 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', + pcall_err(api.nvim_open_term, 0, {}) + ) + + matches( + 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', + pcall_err( + exec_lua, + [[ + local cmdwin_buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_call(vim.api.nvim_create_buf(false, true), function() + vim.api.nvim_open_term(cmdwin_buf, {}) + end) + ]] + ) + ) -- But turning a different buffer into a terminal from the cmdwin is OK. - local term_buf = meths.create_buf(false, true) - meths.open_term(term_buf, {}) - eq('terminal', meths.get_option_value("buftype", {buf = term_buf})) + local term_buf = api.nvim_create_buf(false, true) + api.nvim_open_term(term_buf, {}) + eq('terminal', api.nvim_get_option_value('buftype', { buf = term_buf })) end) - it("use buffer numbers and windows ids as handles", function() + it('use buffer numbers and windows ids as handles', function() local screen = Screen.new(40, 8) screen:attach() local bnr = eval("bufnr('')") - local bhnd = eval("nvim_get_current_buf()") - local wid = eval("win_getid()") - local whnd = eval("nvim_get_current_win()") + local bhnd = eval('nvim_get_current_buf()') + local wid = eval('win_getid()') + local whnd = eval('nvim_get_current_win()') eq(bnr, bhnd) eq(wid, whnd) - command("new") -- creates new buffer and new window + command('new') -- creates new buffer and new window local bnr2 = eval("bufnr('')") - local bhnd2 = eval("nvim_get_current_buf()") - local wid2 = eval("win_getid()") - local whnd2 = eval("nvim_get_current_win()") + local bhnd2 = eval('nvim_get_current_buf()') + local wid2 = eval('win_getid()') + local whnd2 = eval('nvim_get_current_win()') eq(bnr2, bhnd2) eq(wid2, whnd2) neq(bnr, bnr2) neq(wid, wid2) -- 0 is synonymous to the current buffer - eq(bnr2, eval("nvim_buf_get_number(0)")) + eq(bnr2, eval('nvim_buf_get_number(0)')) - command("bn") -- show old buffer in new window - eq(bnr, eval("nvim_get_current_buf()")) + command('bn') -- show old buffer in new window + eq(bnr, eval('nvim_get_current_buf()')) eq(bnr, eval("bufnr('')")) - eq(bnr, eval("nvim_buf_get_number(0)")) - eq(wid2, eval("win_getid()")) - eq(whnd2, eval("nvim_get_current_win()")) + eq(bnr, eval('nvim_buf_get_number(0)')) + eq(wid2, eval('win_getid()')) + eq(whnd2, eval('nvim_get_current_win()')) end) - it("get_lines and set_lines use NL to represent NUL", function() - curbufmeths.set_lines(0, -1, true, {"aa\0", "b\0b"}) - eq({'aa\n', 'b\nb'}, eval("nvim_buf_get_lines(0, 0, -1, 1)")) + it('get_lines and set_lines use NL to represent NUL', function() + api.nvim_buf_set_lines(0, 0, -1, true, { 'aa\0', 'b\0b' }) + eq({ 'aa\n', 'b\nb' }, eval('nvim_buf_get_lines(0, 0, -1, 1)')) command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') - eq({'aa\0', 'xx', '\0yy'}, curbufmeths.get_lines(0, -1, 1)) + eq({ 'aa\0', 'xx', '\0yy' }, api.nvim_buf_get_lines(0, 0, -1, 1)) end) - it("that are FUNC_ATTR_NOEVAL cannot be called", function() + it('that are FUNC_ATTR_NOEVAL cannot be called', function() -- Deprecated vim_ prefix is not exported. local err = exc_exec('call vim_get_current_buffer("foo")') eq('Vim(call):E117: Unknown function: vim_get_current_buffer', err) @@ -150,29 +184,24 @@ describe('eval-API', function() end) it('have metadata accessible with api_info()', function() - local api_keys = eval("sort(keys(api_info()))") - eq({'error_types', 'functions', 'types', - 'ui_events', 'ui_options', 'version'}, api_keys) + local api_keys = eval('sort(keys(api_info()))') + eq({ 'error_types', 'functions', 'types', 'ui_events', 'ui_options', 'version' }, api_keys) end) it('are highlighted by vim.vim syntax file', function() - if luv.fs_stat("build/runtime/syntax/vim/generated.vim").uid == nil then - pending("runtime was not built, skipping test") - return - end local screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Brown}, - [2] = {foreground = Screen.colors.DarkCyan}, - [3] = {foreground = Screen.colors.SlateBlue}, - [4] = {foreground = Screen.colors.Fuchsia}, - [5] = {bold = true, foreground = Screen.colors.Blue}, + [1] = { bold = true, foreground = Screen.colors.Brown }, + [2] = { foreground = Screen.colors.DarkCyan }, + [3] = { foreground = Screen.colors.SlateBlue }, + [4] = { foreground = Screen.colors.Fuchsia }, + [5] = { bold = true, foreground = Screen.colors.Blue }, }) - command("set ft=vim") - command("set rtp^=build/runtime/") - command("syntax on") + command('set ft=vim') + command('set rtp^=build/runtime/') + command('syntax on') insert([[ call bufnr('%') call nvim_input('typing...') @@ -182,18 +211,17 @@ describe('eval-API', function() {1:call} {2:bufnr}{3:(}{4:'%'}{3:)} | {1:call} {2:nvim_input}{3:(}{4:'typing...'}{3:)} | {1:call} not_a_function{3:(}{4:42}{3:^)} | - {5:~ }| - {5:~ }| - {5:~ }| - {5:~ }| + {5:~ }|*4 | ]]) end) it('cannot be called from sandbox', function() - eq('Vim(call):E48: Not allowed in sandbox', - pcall_err(command, "sandbox call nvim_input('ievil')")) - eq({''}, meths.buf_get_lines(0, 0, -1, true)) + eq( + 'Vim(call):E48: Not allowed in sandbox', + pcall_err(command, "sandbox call nvim_input('ievil')") + ) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, true)) end) it('converts blobs to API strings', function() diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index 2a5720fbd7..931fe640a9 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -1,17 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') - local eq = helpers.eq 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 exc_exec = helpers.exc_exec -local bufmeths = helpers.bufmeths -local curbufmeths = helpers.curbufmeths -local curwinmeths = helpers.curwinmeths -local curtabmeths = helpers.curtabmeths local get_pathsep = helpers.get_pathsep local rmdir = helpers.rmdir local pcall_err = helpers.pcall_err @@ -23,30 +17,47 @@ local dirname = fname .. '.d' before_each(clear) -for _, func in ipairs({'bufname(%s)', 'bufnr(%s)', 'bufwinnr(%s)', - 'getbufline(%s, 1)', 'getbufvar(%s, "changedtick")', - 'setbufvar(%s, "f", 0)'}) do +for _, func in ipairs({ + 'bufname(%s)', + 'bufnr(%s)', + 'bufwinnr(%s)', + 'getbufline(%s, 1)', + 'getbufvar(%s, "changedtick")', + 'setbufvar(%s, "f", 0)', +}) do local funcname = func:match('%w+') describe(funcname .. '() function', function() it('errors out when receives v:true/v:false/v:null', function() -- Not compatible with Vim: in Vim it always results in buffer not found -- without any error messages. - for _, var in ipairs({'v:true', 'v:false'}) do - eq('Vim(call):E5299: Expected a Number or a String, Boolean found', - exc_exec('call ' .. func:format(var))) + for _, var in ipairs({ 'v:true', 'v:false' }) do + eq( + 'Vim(call):E5299: Expected a Number or a String, Boolean found', + exc_exec('call ' .. func:format(var)) + ) end - eq('Vim(call):E5300: Expected a Number or a String', - exc_exec('call ' .. func:format('v:null'))) + eq( + 'Vim(call):E5300: Expected a Number or a String', + exc_exec('call ' .. func:format('v:null')) + ) end) it('errors out when receives invalid argument', function() - eq('Vim(call):E745: Expected a Number or a String, List found', - exc_exec('call ' .. func:format('[]'))) - eq('Vim(call):E728: Expected a Number or a String, Dictionary found', - exc_exec('call ' .. func:format('{}'))) - eq('Vim(call):E805: Expected a Number or a String, Float found', - exc_exec('call ' .. func:format('0.0'))) - eq('Vim(call):E703: Expected a Number or a String, Funcref found', - exc_exec('call ' .. func:format('function("tr")'))) + eq( + 'Vim(call):E745: Expected a Number or a String, List found', + exc_exec('call ' .. func:format('[]')) + ) + eq( + 'Vim(call):E728: Expected a Number or a String, Dictionary found', + exc_exec('call ' .. func:format('{}')) + ) + eq( + 'Vim(call):E805: Expected a Number or a String, Float found', + exc_exec('call ' .. func:format('0.0')) + ) + eq( + 'Vim(call):E703: Expected a Number or a String, Funcref found', + exc_exec('call ' .. func:format('function("tr")')) + ) end) end) end @@ -54,12 +65,12 @@ end describe('bufname() function', function() it('returns empty string when buffer was not found', function() command('file ' .. fname) - eq('', funcs.bufname(2)) - eq('', funcs.bufname('non-existent-buffer')) - eq('', funcs.bufname('#')) + eq('', fn.bufname(2)) + eq('', fn.bufname('non-existent-buffer')) + eq('', fn.bufname('#')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq('', funcs.bufname('X')) + eq(2, fn.bufnr('%')) + eq('', fn.bufname('X')) end) before_each(function() mkdir(dirname) @@ -68,80 +79,80 @@ describe('bufname() function', function() rmdir(dirname) end) it('returns expected buffer name', function() - eq('', funcs.bufname('%')) -- Buffer has no name yet + eq('', fn.bufname('%')) -- Buffer has no name yet command('file ' .. fname) - local wd = luv.cwd() + local wd = vim.uv.cwd() local sep = get_pathsep() - local curdirname = funcs.fnamemodify(wd, ':t') - for _, arg in ipairs({'%', 1, 'X', wd}) do - eq(fname, funcs.bufname(arg)) - meths.set_current_dir('..') - eq(curdirname .. sep .. fname, funcs.bufname(arg)) - meths.set_current_dir(curdirname) - meths.set_current_dir(dirname) - eq(wd .. sep .. fname, funcs.bufname(arg)) - meths.set_current_dir('..') - eq(fname, funcs.bufname(arg)) + local curdirname = fn.fnamemodify(wd, ':t') + for _, arg in ipairs({ '%', 1, 'X', wd }) do + eq(fname, fn.bufname(arg)) + api.nvim_set_current_dir('..') + eq(curdirname .. sep .. fname, fn.bufname(arg)) + api.nvim_set_current_dir(curdirname) + api.nvim_set_current_dir(dirname) + eq(wd .. sep .. fname, fn.bufname(arg)) + api.nvim_set_current_dir('..') + eq(fname, fn.bufname(arg)) command('enew') end - eq('', funcs.bufname('%')) - eq('', funcs.bufname('$')) - eq(2, funcs.bufnr('%')) + eq('', fn.bufname('%')) + eq('', fn.bufname('$')) + eq(2, fn.bufnr('%')) end) end) describe('bufnr() function', function() it('returns -1 when buffer was not found', function() command('file ' .. fname) - eq(-1, funcs.bufnr(2)) - eq(-1, funcs.bufnr('non-existent-buffer')) - eq(-1, funcs.bufnr('#')) + eq(-1, fn.bufnr(2)) + eq(-1, fn.bufnr('non-existent-buffer')) + eq(-1, fn.bufnr('#')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq(-1, funcs.bufnr('X')) + eq(2, fn.bufnr('%')) + eq(-1, fn.bufnr('X')) end) it('returns expected buffer number', function() - eq(1, funcs.bufnr('%')) + eq(1, fn.bufnr('%')) command('file ' .. fname) - local wd = luv.cwd() - local curdirname = funcs.fnamemodify(wd, ':t') - eq(1, funcs.bufnr(fname)) - eq(1, funcs.bufnr(wd)) - eq(1, funcs.bufnr(curdirname)) - eq(1, funcs.bufnr('X')) + local wd = vim.uv.cwd() + local curdirname = fn.fnamemodify(wd, ':t') + eq(1, fn.bufnr(fname)) + eq(1, fn.bufnr(wd)) + eq(1, fn.bufnr(curdirname)) + eq(1, fn.bufnr('X')) end) it('returns number of last buffer with "$"', function() - eq(1, funcs.bufnr('$')) + eq(1, fn.bufnr('$')) command('new') - eq(2, funcs.bufnr('$')) + eq(2, fn.bufnr('$')) command('new') - eq(3, funcs.bufnr('$')) + eq(3, fn.bufnr('$')) command('only') - eq(3, funcs.bufnr('$')) - eq(3, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(3, fn.bufnr('%')) command('buffer 1') - eq(3, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('bwipeout 2') - eq(3, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('bwipeout 3') - eq(1, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(1, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('new') - eq(4, funcs.bufnr('$')) + eq(4, fn.bufnr('$')) end) end) describe('bufwinnr() function', function() it('returns -1 when buffer was not found', function() command('file ' .. fname) - eq(-1, funcs.bufwinnr(2)) - eq(-1, funcs.bufwinnr('non-existent-buffer')) - eq(-1, funcs.bufwinnr('#')) - command('split ' .. fname2) -- It would be OK if there was one window - eq(2, funcs.bufnr('%')) - eq(-1, funcs.bufwinnr('X')) + eq(-1, fn.bufwinnr(2)) + eq(-1, fn.bufwinnr('non-existent-buffer')) + eq(-1, fn.bufwinnr('#')) + command('split ' .. fname2) -- It would be OK if there was one window + eq(2, fn.bufnr('%')) + eq(-1, fn.bufwinnr('X')) end) before_each(function() mkdir(dirname) @@ -150,162 +161,162 @@ describe('bufwinnr() function', function() rmdir(dirname) end) it('returns expected window number', function() - eq(1, funcs.bufwinnr('%')) + eq(1, fn.bufwinnr('%')) command('file ' .. fname) command('vsplit') command('split ' .. fname2) - eq(2, funcs.bufwinnr(fname)) - eq(1, funcs.bufwinnr(fname2)) - eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) - meths.set_current_dir(dirname) - eq(2, funcs.bufwinnr(fname)) - eq(1, funcs.bufwinnr(fname2)) - eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) - eq(1, funcs.bufwinnr('%')) - eq(2, funcs.bufwinnr(1)) - eq(1, funcs.bufwinnr(2)) - eq(-1, funcs.bufwinnr(3)) - eq(1, funcs.bufwinnr('$')) + eq(2, fn.bufwinnr(fname)) + eq(1, fn.bufwinnr(fname2)) + eq(-1, fn.bufwinnr(fname:sub(1, #fname - 1))) + api.nvim_set_current_dir(dirname) + eq(2, fn.bufwinnr(fname)) + eq(1, fn.bufwinnr(fname2)) + eq(-1, fn.bufwinnr(fname:sub(1, #fname - 1))) + eq(1, fn.bufwinnr('%')) + eq(2, fn.bufwinnr(1)) + eq(1, fn.bufwinnr(2)) + eq(-1, fn.bufwinnr(3)) + eq(1, fn.bufwinnr('$')) end) end) describe('getbufline() function', function() it('returns empty list when buffer was not found', function() command('file ' .. fname) - eq({}, funcs.getbufline(2, 1)) - eq({}, funcs.getbufline('non-existent-buffer', 1)) - eq({}, funcs.getbufline('#', 1)) + eq({}, fn.getbufline(2, 1)) + eq({}, fn.getbufline('non-existent-buffer', 1)) + eq({}, fn.getbufline('#', 1)) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq({}, funcs.getbufline('X', 1)) + eq(2, fn.bufnr('%')) + eq({}, fn.getbufline('X', 1)) end) it('returns empty list when range is invalid', function() - eq({}, funcs.getbufline(1, 0)) - curbufmeths.set_lines(0, 1, false, {'foo', 'bar', 'baz'}) - eq({}, funcs.getbufline(1, 2, 1)) - eq({}, funcs.getbufline(1, -10, -20)) - eq({}, funcs.getbufline(1, -2, -1)) - eq({}, funcs.getbufline(1, -1, 9999)) + eq({}, fn.getbufline(1, 0)) + api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' }) + eq({}, fn.getbufline(1, 2, 1)) + eq({}, fn.getbufline(1, -10, -20)) + eq({}, fn.getbufline(1, -2, -1)) + eq({}, fn.getbufline(1, -1, 9999)) end) it('returns expected lines', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) command('file ' .. fname) - curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'}) + api.nvim_buf_set_lines(0, 0, 1, false, { 'foo\0', '\0bar', 'baz' }) command('edit ' .. fname2) - curbufmeths.set_lines(0, 1, false, {'abc\0', '\0def', 'ghi'}) - eq({'foo\n', '\nbar', 'baz'}, funcs.getbufline(1, 1, 9999)) - eq({'abc\n', '\ndef', 'ghi'}, funcs.getbufline(2, 1, 9999)) - eq({'foo\n', '\nbar', 'baz'}, funcs.getbufline(1, 1, '$')) - eq({'baz'}, funcs.getbufline(1, '$', '$')) - eq({'baz'}, funcs.getbufline(1, '$', 9999)) + api.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) + eq({ 'foo\n', '\nbar', 'baz' }, fn.getbufline(1, 1, 9999)) + eq({ 'abc\n', '\ndef', 'ghi' }, fn.getbufline(2, 1, 9999)) + eq({ 'foo\n', '\nbar', 'baz' }, fn.getbufline(1, 1, '$')) + eq({ 'baz' }, fn.getbufline(1, '$', '$')) + eq({ 'baz' }, fn.getbufline(1, '$', 9999)) end) end) describe('getbufvar() function', function() it('returns empty list when buffer was not found', function() |