aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/lua
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.gz
rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.bz2
rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/diagnostic_spec.lua249
-rw-r--r--test/functional/lua/filetype_spec.lua14
-rw-r--r--test/functional/lua/fs_spec.lua228
-rw-r--r--test/functional/lua/func_memoize_spec.lua142
-rw-r--r--test/functional/lua/hl_spec.lua31
-rw-r--r--test/functional/lua/json_spec.lua39
-rw-r--r--test/functional/lua/loader_spec.lua18
-rw-r--r--test/functional/lua/system_spec.lua48
-rw-r--r--test/functional/lua/text_spec.lua16
-rw-r--r--test/functional/lua/thread_spec.lua20
-rw-r--r--test/functional/lua/ui_event_spec.lua177
-rw-r--r--test/functional/lua/uri_spec.lua8
-rw-r--r--test/functional/lua/vim_spec.lua13
-rw-r--r--test/functional/lua/watch_spec.lua3
-rw-r--r--test/functional/lua/with_spec.lua17
15 files changed, 917 insertions, 106 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index eb1ac3e6a1..a19f558ef2 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -5,6 +5,7 @@ local command = n.command
local clear = n.clear
local exec_lua = n.exec_lua
local eq = t.eq
+local neq = t.neq
local matches = t.matches
local api = n.api
local pcall_err = t.pcall_err
@@ -112,6 +113,18 @@ describe('vim.diagnostic', function()
)
end
+ function _G.get_virt_lines_extmarks(ns)
+ ns = vim.diagnostic.get_namespace(ns)
+ local virt_lines_ns = ns.user_data.virt_lines_ns
+ return vim.api.nvim_buf_get_extmarks(
+ _G.diagnostic_bufnr,
+ virt_lines_ns,
+ 0,
+ -1,
+ { details = true }
+ )
+ end
+
---@param ns integer
function _G.get_underline_extmarks(ns)
---@type integer
@@ -160,6 +173,11 @@ describe('vim.diagnostic', function()
'DiagnosticUnderlineOk',
'DiagnosticUnderlineWarn',
'DiagnosticUnnecessary',
+ 'DiagnosticVirtualLinesError',
+ 'DiagnosticVirtualLinesHint',
+ 'DiagnosticVirtualLinesInfo',
+ 'DiagnosticVirtualLinesOk',
+ 'DiagnosticVirtualLinesWarn',
'DiagnosticVirtualTextError',
'DiagnosticVirtualTextHint',
'DiagnosticVirtualTextInfo',
@@ -368,6 +386,9 @@ describe('vim.diagnostic', function()
end)
it('handles one namespace clearing highlights while the other still has highlights', function()
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ end)
-- 1 Error (1)
-- 1 Warning (2)
-- 1 Warning (2) + 1 Warning (1)
@@ -442,6 +463,10 @@ describe('vim.diagnostic', function()
end)
it('does not display diagnostics when disabled', function()
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ end)
+
eq(
{ 0, 2 },
exec_lua(function()
@@ -574,7 +599,7 @@ describe('vim.diagnostic', function()
vim.diagnostic.set(
_G.diagnostic_ns,
_G.diagnostic_bufnr,
- { { lnum = 0, end_lnum = 0, col = 0, end_col = 0 } }
+ { { message = '', lnum = 0, end_lnum = 0, col = 0, end_col = 0 } }
)
vim.cmd('bwipeout! ' .. _G.diagnostic_bufnr)
@@ -915,6 +940,10 @@ describe('vim.diagnostic', function()
describe('reset()', function()
it('diagnostic count is 0 and displayed diagnostics are 0 after call', function()
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ end)
+
-- 1 Error (1)
-- 1 Warning (2)
-- 1 Warning (2) + 1 Warning (1)
@@ -1005,7 +1034,7 @@ describe('vim.diagnostic', function()
vim.diagnostic.set(
_G.diagnostic_ns,
_G.diagnostic_bufnr,
- { { lnum = 0, end_lnum = 0, col = 0, end_col = 0 } }
+ { { message = '', lnum = 0, end_lnum = 0, col = 0, end_col = 0 } }
)
vim.cmd('bwipeout! ' .. _G.diagnostic_bufnr)
@@ -2105,6 +2134,139 @@ describe('vim.diagnostic', function()
end)
)
end)
+
+ it('can filter diagnostics by returning nil when formatting', function()
+ local result = exec_lua(function()
+ vim.diagnostic.config {
+ virtual_text = {
+ format = function(diagnostic)
+ if diagnostic.code == 'foo_err' then
+ return nil
+ end
+ return diagnostic.message
+ end,
+ },
+ }
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('An error here!', 0, 0, 0, 0, 'foo_server', 'foo_err'),
+ _G.make_error('An error there!', 1, 1, 1, 1, 'bar_server', 'bar_err'),
+ })
+
+ local extmarks = _G.get_virt_text_extmarks(_G.diagnostic_ns)
+ return extmarks
+ end)
+
+ eq(1, #result)
+ eq(' An error there!', result[1][4].virt_text[3][1])
+ end)
+
+ it('can only show virtual_text for the current line', function()
+ local result = exec_lua(function()
+ vim.api.nvim_win_set_cursor(0, { 1, 0 })
+
+ vim.diagnostic.config({ virtual_text = { current_line = true } })
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Error here!', 0, 0, 0, 0, 'foo_server'),
+ _G.make_error('Another error there!', 1, 0, 1, 0, 'foo_server'),
+ })
+
+ local extmarks = _G.get_virt_text_extmarks(_G.diagnostic_ns)
+ return extmarks
+ end)
+
+ eq(1, #result)
+ eq(' Error here!', result[1][4].virt_text[3][1])
+ end)
+ end)
+
+ describe('handlers.virtual_lines', function()
+ it('includes diagnostic code and message', function()
+ local result = exec_lua(function()
+ vim.diagnostic.config({ virtual_lines = true })
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Missed symbol `,`', 0, 0, 0, 0, 'lua_ls', 'miss-symbol'),
+ })
+
+ local extmarks = _G.get_virt_lines_extmarks(_G.diagnostic_ns)
+ return extmarks[1][4].virt_lines
+ end)
+
+ eq('miss-symbol: Missed symbol `,`', result[1][3][1])
+ end)
+
+ it('adds space to the left of the diagnostic', function()
+ local error_offset = 5
+ local result = exec_lua(function()
+ vim.diagnostic.config({ virtual_lines = true })
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Error here!', 0, error_offset, 0, error_offset, 'foo_server'),
+ })
+
+ local extmarks = _G.get_virt_lines_extmarks(_G.diagnostic_ns)
+ return extmarks[1][4].virt_lines
+ end)
+
+ eq(error_offset, result[1][1][1]:len())
+ end)
+
+ it('highlights diagnostics in multiple lines by default', function()
+ local result = exec_lua(function()
+ vim.diagnostic.config({ virtual_lines = true })
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Error here!', 0, 0, 0, 0, 'foo_server'),
+ _G.make_error('Another error there!', 1, 0, 1, 0, 'foo_server'),
+ })
+
+ local extmarks = _G.get_virt_lines_extmarks(_G.diagnostic_ns)
+ return extmarks
+ end)
+
+ eq(2, #result)
+ eq('Error here!', result[1][4].virt_lines[1][3][1])
+ eq('Another error there!', result[2][4].virt_lines[1][3][1])
+ end)
+
+ it('can highlight diagnostics only in the current line', function()
+ local result = exec_lua(function()
+ vim.api.nvim_win_set_cursor(0, { 1, 0 })
+
+ vim.diagnostic.config({ virtual_lines = { current_line = true } })
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Error here!', 0, 0, 0, 0, 'foo_server'),
+ _G.make_error('Another error there!', 1, 0, 1, 0, 'foo_server'),
+ })
+
+ local extmarks = _G.get_virt_lines_extmarks(_G.diagnostic_ns)
+ return extmarks
+ end)
+
+ eq(1, #result)
+ eq('Error here!', result[1][4].virt_lines[1][3][1])
+ end)
+
+ it('supports a format function for diagnostic messages', function()
+ local result = exec_lua(function()
+ vim.diagnostic.config({
+ virtual_lines = {
+ format = function()
+ return 'Error here!'
+ end,
+ },
+ })
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Invalid syntax', 0, 0, 0, 0),
+ })
+ local extmarks = _G.get_virt_lines_extmarks(_G.diagnostic_ns)
+ return extmarks[1][4].virt_lines
+ end)
+ eq('Error here!', result[1][3][1])
+ end)
end)
describe('set()', function()
@@ -2116,7 +2278,11 @@ describe('vim.diagnostic', function()
end)
it('can perform updates after insert_leave', function()
- exec_lua [[vim.api.nvim_set_current_buf( _G.diagnostic_bufnr)]]
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ vim.api.nvim_set_current_buf(_G.diagnostic_bufnr)
+ end)
+
api.nvim_input('o')
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
@@ -2257,7 +2423,10 @@ describe('vim.diagnostic', function()
end)
it('can perform updates while in insert mode, if desired', function()
- exec_lua [[vim.api.nvim_set_current_buf( _G.diagnostic_bufnr)]]
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ vim.api.nvim_set_current_buf(_G.diagnostic_bufnr)
+ end)
api.nvim_input('o')
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
@@ -2291,6 +2460,10 @@ describe('vim.diagnostic', function()
end)
it('can set diagnostics without displaying them', function()
+ exec_lua(function()
+ vim.diagnostic.config({ virtual_text = true })
+ end)
+
eq(
0,
exec_lua(function()
@@ -3212,6 +3385,74 @@ describe('vim.diagnostic', function()
end)
end)
+ describe('setqflist()', function()
+ it('updates existing diagnostics quickfix if one already exists', function()
+ local result = exec_lua(function()
+ vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
+
+ vim.fn.setqflist({}, ' ', { title = 'Diagnostics' })
+ local diagnostics_qf_id = vim.fn.getqflist({ id = 0 }).id
+
+ vim.diagnostic.setqflist({ title = 'Diagnostics' })
+ local qf_id = vim.fn.getqflist({ id = 0, nr = '$' }).id
+
+ return { diagnostics_qf_id, qf_id }
+ end)
+
+ eq(result[1], result[2])
+ end)
+
+ it('navigates to existing diagnostics quickfix if one already exists and open=true', function()
+ local result = exec_lua(function()
+ vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
+
+ vim.fn.setqflist({}, ' ', { title = 'Diagnostics' })
+ local diagnostics_qf_id = vim.fn.getqflist({ id = 0 }).id
+
+ vim.fn.setqflist({}, ' ', { title = 'Other' })
+
+ vim.diagnostic.setqflist({ title = 'Diagnostics', open = true })
+ local qf_id = vim.fn.getqflist({ id = 0 }).id
+
+ return { diagnostics_qf_id, qf_id }
+ end)
+
+ eq(result[1], result[2])
+ end)
+
+ it('sets new diagnostics quickfix as active when open=true', function()
+ local result = exec_lua(function()
+ vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
+
+ vim.fn.setqflist({}, ' ', { title = 'Other' })
+ local other_qf_id = vim.fn.getqflist({ id = 0 }).id
+
+ vim.diagnostic.setqflist({ title = 'Diagnostics', open = true })
+ local qf_id = vim.fn.getqflist({ id = 0 }).id
+
+ return { other_qf_id, qf_id }
+ end)
+
+ neq(result[1], result[2])
+ end)
+
+ it('opens quickfix window when open=true', function()
+ local qf_winid = exec_lua(function()
+ vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
+
+ vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
+ _G.make_error('Error', 1, 1, 1, 1),
+ })
+
+ vim.diagnostic.setqflist({ open = true })
+
+ return vim.fn.getqflist({ winid = 0 }).winid
+ end)
+
+ neq(0, qf_winid)
+ end)
+ end)
+
describe('match()', function()
it('matches a string', function()
local msg = 'ERROR: george.txt:19:84:Two plus two equals five'
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index b6011d5268..b75ff75b05 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -199,7 +199,19 @@ describe('filetype.lua', function()
finally(function()
uv.fs_unlink('Xfiletype/.config/git')
end)
- clear({ args = { '--clean', 'Xfiletype/.config/git/config' } })
+ local args = { '--clean', 'Xfiletype/.config/git/config' }
+ clear({ args = args })
eq('gitconfig', api.nvim_get_option_value('filetype', {}))
+ table.insert(args, 2, '--cmd')
+ table.insert(args, 3, "autocmd BufRead * call expand('<afile>')")
+ clear({ args = args })
+ eq('gitconfig', api.nvim_get_option_value('filetype', {}))
+ end)
+
+ it('works with :doautocmd BufRead #31306', function()
+ clear({ args = { '--clean' } })
+ eq('', api.nvim_get_option_value('filetype', {}))
+ command('doautocmd BufRead README.md')
+ eq('markdown', api.nvim_get_option_value('filetype', {}))
end)
end)
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index f0d49205e7..33af25f629 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -17,6 +17,8 @@ local mkdir = t.mkdir
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
+local link_limit = is_os('win') and 64 or (is_os('mac') or is_os('bsd')) and 33 or 41
+
local test_basename_dirname_eq = {
'~/foo/',
'~/foo',
@@ -152,7 +154,7 @@ describe('vim.fs', function()
)
end)
- it('works with opts.depth and opts.skip', function()
+ it('works with opts.depth, opts.skip and opts.follow', function()
io.open('testd/a1', 'w'):close()
io.open('testd/b1', 'w'):close()
io.open('testd/c1', 'w'):close()
@@ -166,10 +168,10 @@ describe('vim.fs', function()
io.open('testd/a/b/c/b4', 'w'):close()
io.open('testd/a/b/c/c4', 'w'):close()
- local function run(dir, depth, skip)
- return exec_lua(function()
- local r = {}
- local skip_f
+ local function run(dir, depth, skip, follow)
+ return exec_lua(function(follow_)
+ local r = {} --- @type table<string, string>
+ local skip_f --- @type function
if skip then
skip_f = function(n0)
if vim.tbl_contains(skip or {}, n0) then
@@ -177,11 +179,11 @@ describe('vim.fs', function()
end
end
end
- for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do
+ for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f, follow = follow_ }) do
r[name] = type_
end
return r
- end)
+ end, follow)
end
local exp = {}
@@ -197,6 +199,7 @@ describe('vim.fs', function()
exp['a/b2'] = 'file'
exp['a/c2'] = 'file'
exp['a/b'] = 'directory'
+ local lexp = vim.deepcopy(exp)
eq(exp, run('testd', 2))
@@ -213,6 +216,29 @@ describe('vim.fs', function()
exp['a/b/c/c4'] = 'file'
eq(exp, run('testd', 999))
+
+ vim.uv.fs_symlink(vim.uv.fs_realpath('testd/a'), 'testd/l', { junction = true, dir = true })
+ lexp['l'] = 'link'
+ eq(lexp, run('testd', 2, nil, false))
+
+ lexp['l/a2'] = 'file'
+ lexp['l/b2'] = 'file'
+ lexp['l/c2'] = 'file'
+ lexp['l/b'] = 'directory'
+ eq(lexp, run('testd', 2, nil, true))
+ end)
+
+ it('follow=true handles symlink loop', function()
+ local cwd = 'testd/a/b/c'
+ local symlink = cwd .. '/link_loop' ---@type string
+ vim.uv.fs_symlink(vim.uv.fs_realpath(cwd), symlink, { junction = true, dir = true })
+
+ eq(
+ link_limit,
+ exec_lua(function()
+ return #vim.iter(vim.fs.dir(cwd, { depth = math.huge, follow = true })):totable()
+ end)
+ )
end)
end)
@@ -228,6 +254,53 @@ describe('vim.fs', function()
eq({ nvim_dir }, vim.fs.find(name, { path = parent, upward = true, type = 'directory' }))
end)
+ it('follows symlinks', function()
+ local build_dir = test_source_path .. '/build' ---@type string
+ local symlink = test_source_path .. '/build_link' ---@type string
+ vim.uv.fs_symlink(build_dir, symlink, { junction = true, dir = true })
+
+ finally(function()
+ vim.uv.fs_unlink(symlink)
+ end)
+
+ eq(
+ { nvim_prog, symlink .. '/bin/' .. nvim_prog_basename },
+ vim.fs.find(nvim_prog_basename, {
+ path = test_source_path,
+ type = 'file',
+ limit = 2,
+ follow = true,
+ })
+ )
+
+ eq(
+ { nvim_prog },
+ vim.fs.find(nvim_prog_basename, {
+ path = test_source_path,
+ type = 'file',
+ limit = 2,
+ follow = false,
+ })
+ )
+ end)
+
+ it('follow=true handles symlink loop', function()
+ local cwd = test_source_path ---@type string
+ local symlink = test_source_path .. '/loop_link' ---@type string
+ vim.uv.fs_symlink(cwd, symlink, { junction = true, dir = true })
+
+ finally(function()
+ vim.uv.fs_unlink(symlink)
+ end)
+
+ eq(link_limit, #vim.fs.find(nvim_prog_basename, {
+ path = test_source_path,
+ type = 'file',
+ limit = math.huge,
+ follow = true,
+ }))
+ end)
+
it('accepts predicate as names', function()
local opts = { path = nvim_dir, upward = true, type = 'directory' }
eq(
@@ -273,14 +346,14 @@ describe('vim.fs', function()
end)
it('works with a single marker', function()
- eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
+ eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
end)
it('works with multiple markers', function()
local bufnr = api.nvim_get_current_buf()
eq(
vim.fs.joinpath(test_source_path, 'test/functional/fixtures'),
- exec_lua([[return vim.fs.root(..., {'CMakeLists.txt', '.git'})]], bufnr)
+ exec_lua([[return vim.fs.root(..., {'CMakeLists.txt', 'CMakePresets.json'})]], bufnr)
)
end)
@@ -295,26 +368,26 @@ describe('vim.fs', function()
end)
it('works with a filename argument', function()
- eq(test_source_path, exec_lua([[return vim.fs.root(..., '.git')]], nvim_prog))
+ eq(test_source_path, exec_lua([[return vim.fs.root(..., 'CMakePresets.json')]], nvim_prog))
end)
it('works with a relative path', function()
eq(
test_source_path,
- exec_lua([[return vim.fs.root(..., '.git')]], vim.fs.basename(nvim_prog))
+ exec_lua([[return vim.fs.root(..., 'CMakePresets.json')]], vim.fs.basename(nvim_prog))
)
end)
it('uses cwd for unnamed buffers', function()
command('new')
- eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
+ eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
end)
it("uses cwd for buffers with non-empty 'buftype'", function()
command('new')
command('set buftype=nofile')
command('file lua://')
- eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
+ eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
end)
end)
@@ -323,6 +396,20 @@ describe('vim.fs', function()
eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz'))
eq('foo/bar/baz', vim.fs.joinpath('foo', '/bar/', '/baz'))
end)
+ it('rewrites backslashes on Windows', function()
+ if is_os('win') then
+ eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
+ else
+ eq([[foo/\\bar\\\\baz/zub\]], vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
+ end
+ end)
+ it('strips redundant slashes', function()
+ if is_os('win') then
+ eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo//]], [[\\bar\\\\baz]], [[zub\]]))
+ else
+ eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[//bar////baz]], [[zub/]]))
+ end
+ end)
end)
describe('normalize()', function()
@@ -347,8 +434,8 @@ describe('vim.fs', function()
end)
-- Opts required for testing posix paths and win paths
- local posix_opts = is_os('win') and { win = false } or {}
- local win_opts = is_os('win') and {} or { win = true }
+ local posix_opts = { win = false }
+ local win_opts = { win = true }
it('preserves leading double slashes in POSIX paths', function()
eq('//foo', vim.fs.normalize('//foo', posix_opts))
@@ -359,6 +446,29 @@ describe('vim.fs', function()
eq('/foo/bar', vim.fs.normalize('/foo//bar////', posix_opts))
end)
+ it('normalizes drive letter', function()
+ eq('C:/', vim.fs.normalize('C:/', win_opts))
+ eq('C:/', vim.fs.normalize('c:/', win_opts))
+ eq('D:/', vim.fs.normalize('d:/', win_opts))
+ eq('C:', vim.fs.normalize('C:', win_opts))
+ eq('C:', vim.fs.normalize('c:', win_opts))
+ eq('D:', vim.fs.normalize('d:', win_opts))
+ eq('C:/foo/test', vim.fs.normalize('C:/foo/test/', win_opts))
+ eq('C:/foo/test', vim.fs.normalize('c:/foo/test/', win_opts))
+ eq('D:foo/test', vim.fs.normalize('D:foo/test/', win_opts))
+ eq('D:foo/test', vim.fs.normalize('d:foo/test/', win_opts))
+ end)
+
+ it('always treats paths as case-sensitive #31833', function()
+ eq('TEST', vim.fs.normalize('TEST', win_opts))
+ eq('test', vim.fs.normalize('test', win_opts))
+ eq('C:/FOO/test', vim.fs.normalize('C:/FOO/test', win_opts))
+ eq('C:/foo/test', vim.fs.normalize('C:/foo/test', win_opts))
+ eq('//SERVER/SHARE/FOO/BAR', vim.fs.normalize('//SERVER/SHARE/FOO/BAR', win_opts))
+ eq('//server/share/foo/bar', vim.fs.normalize('//server/share/foo/bar', win_opts))
+ eq('C:/FOO/test', vim.fs.normalize('c:/FOO/test', win_opts))
+ end)
+
it('allows backslashes on unix-based os', function()
eq('/home/user/hello\\world', vim.fs.normalize('/home/user/hello\\world', posix_opts))
end)
@@ -454,4 +564,92 @@ describe('vim.fs', function()
end)
end)
end)
+
+ describe('abspath()', function()
+ local cwd = assert(t.fix_slashes(assert(vim.uv.cwd())))
+ local home = t.fix_slashes(assert(vim.uv.os_homedir()))
+
+ it('works', function()
+ eq(cwd .. '/foo', vim.fs.abspath('foo'))
+ eq(cwd .. '/././foo', vim.fs.abspath('././foo'))
+ eq(cwd .. '/.././../foo', vim.fs.abspath('.././../foo'))
+ end)
+
+ it('works with absolute paths', function()
+ if is_os('win') then
+ eq([[C:/foo]], vim.fs.abspath([[C:\foo]]))
+ eq([[C:/foo/../.]], vim.fs.abspath([[C:\foo\..\.]]))
+ eq('//foo/bar', vim.fs.abspath('\\\\foo\\bar'))
+ else
+ eq('/foo/../.', vim.fs.abspath('/foo/../.'))
+ eq('/foo/bar', vim.fs.abspath('/foo/bar'))
+ end
+ end)
+
+ it('expands ~', function()
+ eq(home .. '/foo', vim.fs.abspath('~/foo'))
+ eq(home .. '/./.././foo', vim.fs.abspath('~/./.././foo'))
+ end)
+
+ if is_os('win') then
+ it('works with drive-specific cwd on Windows', function()
+ local cwd_drive = cwd:match('^%w:')
+
+ eq(cwd .. '/foo', vim.fs.abspath(cwd_drive .. 'foo'))
+ end)
+ end
+ end)
+
+ describe('relpath()', function()
+ it('works', function()
+ local cwd = assert(t.fix_slashes(assert(vim.uv.cwd())))
+ local my_dir = vim.fs.joinpath(cwd, 'foo')
+
+ eq(nil, vim.fs.relpath('/var/lib', '/var'))
+ eq(nil, vim.fs.relpath('/var/lib', '/bin'))
+ eq(nil, vim.fs.relpath(my_dir, 'bin'))
+ eq(nil, vim.fs.relpath(my_dir, './bin'))
+ eq(nil, vim.fs.relpath(my_dir, '././'))
+ eq(nil, vim.fs.relpath(my_dir, '../'))
+ eq(nil, vim.fs.relpath('/var/lib', '/'))
+ eq(nil, vim.fs.relpath('/var/lib', '//'))
+ eq(nil, vim.fs.relpath(' ', '/var'))
+ eq(nil, vim.fs.relpath(' ', '/var'))
+ eq('.', vim.fs.relpath('/var/lib', '/var/lib'))
+ eq('lib', vim.fs.relpath('/var/', '/var/lib'))
+ eq('var/lib', vim.fs.relpath('/', '/var/lib'))
+ eq('bar/package.json', vim.fs.relpath('/foo/test', '/foo/test/bar/package.json'))
+ eq('foo/bar', vim.fs.relpath(cwd, 'foo/bar'))
+ eq('foo/bar', vim.fs.relpath('.', vim.fs.joinpath(cwd, 'foo/bar')))
+ eq('bar', vim.fs.relpath('foo', 'foo/bar'))
+ eq(nil, vim.fs.relpath('/var/lib', '/var/library/foo'))
+
+ if is_os('win') then
+ eq(nil, vim.fs.relpath('/', ' '))
+ eq(nil, vim.fs.relpath('/', 'var'))
+ else
+ local cwd_rel_root = cwd:sub(2)
+ eq(cwd_rel_root .. '/ ', vim.fs.relpath('/', ' '))
+ eq(cwd_rel_root .. '/var', vim.fs.relpath('/', 'var'))
+ end
+
+ if is_os('win') then
+ eq(nil, vim.fs.relpath('c:/aaaa/', '/aaaa/cccc'))
+ eq(nil, vim.fs.relpath('c:/aaaa/', './aaaa/cccc'))
+ eq(nil, vim.fs.relpath('c:/aaaa/', 'aaaa/cccc'))
+ eq(nil, vim.fs.relpath('c:/blah\\blah', 'd:/games'))
+ eq(nil, vim.fs.relpath('c:/games', 'd:/games'))
+ eq(nil, vim.fs.relpath('c:/games', 'd:/games/foo'))
+ eq(nil, vim.fs.relpath('c:/aaaa/bbbb', 'c:/aaaa'))
+ eq('cccc', vim.fs.relpath('c:/aaaa/', 'c:/aaaa/cccc'))
+ eq('aaaa/bbbb', vim.fs.relpath('C:/', 'c:\\aaaa\\bbbb'))
+ eq('bar/package.json', vim.fs.relpath('C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json'))
+ eq('baz', vim.fs.relpath('\\\\foo\\bar', '\\\\foo\\bar\\baz'))
+ eq(nil, vim.fs.relpath('a/b/c', 'a\\b'))
+ eq('d', vim.fs.relpath('a/b/c', 'a\\b\\c\\d'))
+ eq('.', vim.fs.relpath('\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'))
+ eq(nil, vim.fs.relpath('C:\\foo\\test', 'C:\\foo\\Test\\bar\\package.json'))
+ end
+ end)
+ end)
end)
diff --git a/test/functional/lua/func_memoize_spec.lua b/test/functional/lua/func_memoize_spec.lua
new file mode 100644
index 0000000000..ca518ab88d
--- /dev/null
+++ b/test/functional/lua/func_memoize_spec.lua
@@ -0,0 +1,142 @@
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+local clear = n.clear
+local exec_lua = n.exec_lua
+local eq = t.eq
+
+describe('vim.func._memoize', function()
+ before_each(clear)
+
+ it('caches function results based on their parameters', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(1, exec_lua([[return _G.count]]))
+ end)
+
+ it('caches function results using a weak table by default', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat-2', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ ]])
+
+ eq(3, exec_lua([[return _G.count]]))
+ end)
+
+ it('can cache using a strong table', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat-2', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end, false)
+
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ ]])
+
+ eq(1, exec_lua([[return _G.count]]))
+ end)
+
+ it('can clear a single cache entry', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize(function(arg1, arg2)
+ return tostring(arg1) .. '%%' .. tostring(arg2)
+ end, function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder:clear(3, -4)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(2, exec_lua([[return _G.count]]))
+ end)
+
+ it('can clear the entire cache', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize(function(arg1, arg2)
+ return tostring(arg1) .. '%%' .. tostring(arg2)
+ end, function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(1, 2)
+ adder(3, -4)
+ adder(1, 2)
+ adder(3, -4)
+ adder(1, 2)
+ adder(3, -4)
+ adder:clear()
+ adder(1, 2)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(4, exec_lua([[return _G.count]]))
+ end)
+
+ it('can cache functions that return nil', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return nil
+ end)
+
+ collectgarbage('stop')
+ adder(1, 2)
+ adder(1, 2)
+ adder(1, 2)
+ adder(1, 2)
+ adder:clear()
+ adder(1, 2)
+ collectgarbage('restart')
+ ]])
+
+ eq(2, exec_lua([[return _G.count]]))
+ end)
+end)
diff --git a/test/functional/lua/hl_spec.lua b/test/functional/lua/hl_spec.lua
index 89881973bf..512f6be48f 100644
--- a/test/functional/lua/hl_spec.lua
+++ b/test/functional/lua/hl_spec.lua
@@ -104,6 +104,33 @@ describe('vim.hl.range', function()
|
]])
end)
+
+ it('removes highlight after given `timeout`', function()
+ local timeout = 100
+ exec_lua(function()
+ local ns = vim.api.nvim_create_namespace('')
+ vim.hl.range(0, ns, 'Search', { 0, 0 }, { 4, 0 }, { timeout = timeout })
+ end)
+ screen:expect({
+ grid = [[
+ {10:^asdfghjkl}{100:$} |
+ {10:«口=口»}{100:$} |
+ {10:qwertyuiop}{100:$} |
+ {10:口口=口口}{1:$} |
+ zxcvbnm{1:$} |
+ |
+ ]],
+ timeout = timeout,
+ })
+ screen:expect([[
+ ^asdfghjkl{1:$} |
+ «口=口»{1:$} |
+ qwertyuiop{1:$} |
+ 口口=口口{1:$} |
+ zxcvbnm{1:$} |
+ |
+ ]])
+ end)
end)
describe('vim.hl.on_yank', function()
@@ -144,7 +171,7 @@ describe('vim.hl.on_yank', function()
vim.api.nvim_buf_set_mark(0, ']', 1, 1, {})
vim.hl.on_yank({ timeout = math.huge, on_macro = true, event = { operator = 'y' } })
end)
- local ns = api.nvim_create_namespace('hlyank')
+ local ns = api.nvim_create_namespace('nvim.hlyank')
local win = api.nvim_get_current_win()
eq({ win }, api.nvim__ns_get(ns).wins)
command('wincmd w')
@@ -158,7 +185,7 @@ describe('vim.hl.on_yank', function()
vim.api.nvim_buf_set_mark(0, ']', 1, 1, {})
vim.hl.on_yank({ timeout = math.huge, on_macro = true, event = { operator = 'y' } })
end)
- local ns = api.nvim_create_namespace('hlyank')
+ local ns = api.nvim_create_namespace('nvim.hlyank')
eq(api.nvim_get_current_win(), api.nvim__ns_get(ns).wins[1])
command('wincmd w')
exec_lua(function()
diff --git a/test/functional/lua/json_spec.lua b/test/functional/lua/json_spec.lua
index a6e814d739..e4a1df1d4c 100644
--- a/test/functional/lua/json_spec.lua
+++ b/test/functional/lua/json_spec.lua
@@ -152,6 +152,45 @@ describe('vim.json.encode()', function()
clear()
end)
+ it('escape_slash', function()
+ -- With slash
+ eq('"Test\\/"', exec_lua([[return vim.json.encode('Test/', { escape_slash = true })]]))
+ eq(
+ 'Test/',
+ exec_lua([[return vim.json.decode(vim.json.encode('Test/', { escape_slash = true }))]])
+ )
+
+ -- Without slash
+ eq('"Test/"', exec_lua([[return vim.json.encode('Test/')]]))
+ eq('"Test/"', exec_lua([[return vim.json.encode('Test/', {})]]))
+ eq('"Test/"', exec_lua([[return vim.json.encode('Test/', { _invalid = true })]]))
+ eq('"Test/"', exec_lua([[return vim.json.encode('Test/', { escape_slash = false })]]))
+ eq(
+ '"Test/"',
+ exec_lua([[return vim.json.encode('Test/', { _invalid = true, escape_slash = false })]])
+ )
+ eq(
+ 'Test/',
+ exec_lua([[return vim.json.decode(vim.json.encode('Test/', { escape_slash = false }))]])
+ )
+
+ -- Checks for for global side-effects
+ eq(
+ '"Test/"',
+ exec_lua([[
+ vim.json.encode('Test/', { escape_slash = true })
+ return vim.json.encode('Test/')
+ ]])
+ )
+ eq(
+ '"Test\\/"',
+ exec_lua([[
+ vim.json.encode('Test/', { escape_slash = false })
+ return vim.json.encode('Test/', { escape_slash = true })
+ ]])
+ )
+ end)
+
it('dumps strings', function()
eq('"Test"', exec_lua([[return vim.json.encode('Test')]]))
eq('""', exec_lua([[return vim.json.encode('')]]))
diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua
index 8508f2aa14..20d3a940b2 100644
--- a/test/functional/lua/loader_spec.lua
+++ b/test/functional/lua/loader_spec.lua
@@ -10,7 +10,17 @@ local eq = t.eq
describe('vim.loader', function()
before_each(clear)
- it('can work in compatibility with --luamod-dev #27413', function()
+ it('can be disabled', function()
+ exec_lua(function()
+ local orig_loader = _G.loadfile
+ vim.loader.enable()
+ assert(orig_loader ~= _G.loadfile)
+ vim.loader.enable(false)
+ assert(orig_loader == _G.loadfile)
+ end)
+ end)
+
+ it('works with --luamod-dev #27413', function()
clear({ args = { '--luamod-dev' } })
exec_lua(function()
vim.loader.enable()
@@ -31,7 +41,7 @@ describe('vim.loader', function()
end)
end)
- it('handles changing files (#23027)', function()
+ it('handles changing files #23027', function()
exec_lua(function()
vim.loader.enable()
end)
@@ -63,7 +73,7 @@ describe('vim.loader', function()
)
end)
- it('handles % signs in modpath (#24491)', function()
+ it('handles % signs in modpath #24491', function()
exec_lua [[
vim.loader.enable()
]]
@@ -82,7 +92,7 @@ describe('vim.loader', function()
eq(2, exec_lua('return loadfile(...)()', tmp2))
end)
- it('correct indent on error message (#29809)', function()
+ it('indents error message #29809', function()
local errmsg = exec_lua [[
vim.loader.enable()
local _, errmsg = pcall(require, 'non_existent_module')
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
index afbada007d..6c320376c9 100644
--- a/test/functional/lua/system_spec.lua
+++ b/test/functional/lua/system_spec.lua
@@ -18,8 +18,7 @@ local function system_sync(cmd, opts)
local res = obj:wait()
-- Check the process is no longer running
- local proc = vim.api.nvim_get_proc(obj.pid)
- assert(not proc, 'process still exists')
+ assert(not vim.api.nvim_get_proc(obj.pid), 'process still exists')
return res
end)
@@ -27,23 +26,23 @@ end
local function system_async(cmd, opts)
return exec_lua(function()
- _G.done = false
+ local done = false
+ local res --- @type vim.SystemCompleted?
local obj = vim.system(cmd, opts, function(obj)
- _G.done = true
- _G.ret = obj
+ done = true
+ res = obj
end)
local ok = vim.wait(10000, function()
- return _G.done
+ return done
end)
assert(ok, 'process did not exit')
-- Check the process is no longer running
- local proc = vim.api.nvim_get_proc(obj.pid)
- assert(not proc, 'process still exists')
+ assert(not vim.api.nvim_get_proc(obj.pid), 'process still exists')
- return _G.ret
+ return res
end)
end
@@ -114,10 +113,39 @@ describe('vim.system', function()
end)
if t.is_os('win') then
- it('can resolve windows command extentions.', function()
+ it('can resolve windows command extensions', function()
t.write_file('test.bat', 'echo hello world')
system_sync({ 'chmod', '+x', 'test.bat' })
system_sync({ './test' })
end)
end
+
+ it('always captures all content of stdout/stderr #30846', function()
+ t.skip(n.fn.executable('git') == 0, 'missing "git" command')
+ t.skip(n.fn.isdirectory('.git') == 0, 'missing ".git" directory')
+ eq(
+ 0,
+ exec_lua(function()
+ local done = 0
+ local fail = 0
+ for _ = 1, 200 do
+ vim.system(
+ { 'git', 'show', ':0:test/functional/plugin/lsp_spec.lua' },
+ { text = true },
+ function(o)
+ if o.code ~= 0 or #o.stdout == 0 then
+ fail = fail + 1
+ end
+ done = done + 1
+ end
+ )
+ end
+
+ local ok = vim.wait(10000, function()
+ return done == 200
+ end, 200)
+ return fail + (ok and 0 or 1)
+ end)
+ )
+ end)
end)
diff --git a/test/functional/lua/text_spec.lua b/test/functional/lua/text_spec.lua
index be471bfd62..dd08a6ec04 100644
--- a/test/functional/lua/text_spec.lua
+++ b/test/functional/lua/text_spec.lua
@@ -26,5 +26,21 @@ describe('vim.text', function()
eq(output, vim.text.hexencode(input))
eq(input, vim.text.hexdecode(output))
end)
+
+ it('errors on invalid input', function()
+ -- Odd number of hex characters
+ do
+ local res, err = vim.text.hexdecode('ABC')
+ eq(nil, res)
+ eq('string must have an even number of hex characters', err)
+ end
+
+ -- Non-hexadecimal input
+ do
+ local res, err = vim.text.hexdecode('nothex')
+ eq(nil, res)
+ eq('string must contain only hex characters', err)
+ end
+ end)
end)
end)
diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua
index 310705fd97..8ca4bdc4f5 100644
--- a/test/functional/lua/thread_spec.lua
+++ b/test/functional/lua/thread_spec.lua
@@ -19,6 +19,26 @@ describe('thread', function()
screen = Screen.new(50, 10)
end)
+ it('handle non-string error', function()
+ exec_lua [[
+ local thread = vim.uv.new_thread(function()
+ error()
+ end)
+ vim.uv.thread_join(thread)
+ ]]
+
+ screen:expect([[
+ |
+ {1:~ }|*5
+ {3: }|
+ {9:Error in luv thread:} |
+ {9:[NULL]} |
+ {6:Press ENTER or type command to continue}^ |
+ ]])
+ feed('<cr>')
+ assert_alive()
+ end)
+
it('entry func is executed in protected mode', function()
exec_lua [[
local thread = vim.uv.new_thread(function()
diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua
index c8616e3e11..ddb10127e4 100644
--- a/test/functional/lua/ui_event_spec.lua
+++ b/test/functional/lua/ui_event_spec.lua
@@ -106,20 +106,15 @@ describe('vim.ui_attach', function()
end)
it('does not crash on exit', function()
- fn.system({
- n.nvim_prog,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ local p = n.spawn_wait(
'--cmd',
[[ lua ns = vim.api.nvim_create_namespace 'testspace' ]],
'--cmd',
[[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]],
'--cmd',
- 'quitall!',
- })
- eq(0, n.eval('v:shell_error'))
+ 'quitall!'
+ )
+ eq(0, p.status)
end)
it('can receive accurate message kinds even if they are history', function()
@@ -173,18 +168,67 @@ describe('vim.ui_attach', function()
vim.ui_attach(ns, { ext_messages = true }, function(ev)
if ev == 'msg_show' then
vim.schedule(function() vim.cmd.redraw() end)
- else
- vim.cmd.redraw()
+ elseif ev:find('cmdline') then
+ _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0)
+ vim.api.nvim_buf_set_lines(0, 0, -1, false, { tostring(_G.cmdline) })
+ vim.cmd('redraw')
end
- _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0)
end
)]])
+ screen:expect([[
+ ^ |
+ {1:~ }|*4
+ ]])
feed(':')
- n.assert_alive()
- eq(2, exec_lua('return _G.cmdline'))
- n.assert_alive()
+ screen:expect({
+ grid = [[
+ ^1 |
+ {1:~ }|*4
+ ]],
+ cmdline = { {
+ content = { { '' } },
+ firstc = ':',
+ pos = 0,
+ } },
+ })
feed('version<CR><CR>v<Esc>')
- n.assert_alive()
+ screen:expect({
+ grid = [[
+ ^2 |
+ {1:~ }|*4
+ ]],
+ cmdline = { { abort = false } },
+ })
+ feed([[:call confirm("Save changes?", "&Yes\n&No\n&Cancel")<CR>]])
+ screen:expect({
+ grid = [[
+ ^4 |
+ {1:~ }|*4
+ ]],
+ cmdline = {
+ {
+ content = { { '' } },
+ hl_id = 10,
+ pos = 0,
+ prompt = '[Y]es, (N)o, (C)ancel: ',
+ },
+ },
+ messages = {
+ {
+ content = { { '\nSave changes?\n', 6, 10 } },
+ history = false,
+ kind = 'confirm',
+ },
+ },
+ })
+ feed('n')
+ screen:expect({
+ grid = [[
+ ^4 |
+ {1:~ }|*4
+ ]],
+ cmdline = { { abort = false } },
+ })
end)
it("preserved 'incsearch/command' screen state after :redraw from ext_cmdline", function()
@@ -261,30 +305,15 @@ describe('vim.ui_attach', function()
lled in a fast event context |
{1:~ }|
]],
+ cmdline = { { abort = false } },
messages = {
{
- content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 7 } },
+ content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 6 } },
+ history = true,
kind = 'emsg',
},
},
})
- -- No fast context for prompt message kinds
- feed(':%s/Function/Replacement/c<cr>')
- screen:expect({
- grid = [[
- ^E122: {10:Function} Foo already exists, add !|
- to replace it |
- replace with Replacement (y/n/a/q/l/^E/^|
- Y)? |
- {1:~ }|
- ]],
- messages = {
- {
- content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 19 } },
- kind = 'confirm_sub',
- },
- },
- })
end)
end)
@@ -316,30 +345,36 @@ describe('vim.ui_attach', function()
vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] })
end)
]])
+ local s1 = [[
+ ^ |
+ {1:~ }|*4
+ ]]
+ screen:expect(s1)
+ feed('QQQQQQ<CR>')
screen:expect({
grid = [[
- ^ |
- {1:~ }|*4
- ]],
- })
- feed('ifoo')
- screen:expect({
- grid = [[
- foo^ |
- {1:~ }|*4
- ]],
- showmode = { { '-- INSERT --', 5, 12 } },
- })
- feed('<esc>:1mes clear<cr>:mes<cr>')
- screen:expect({
- grid = [[
- foo |
- {3: }|
- {9:Excessive errors in vim.ui_attach() call}|
- {9:back from ns: 1.} |
+ {9:obal 'err' (a nil value)} |
+ {9:stack traceback:} |
+ {9: [string "<nvim>"]:2: in function}|
+ {9: <[string "<nvim>"]:1>} |
{100:Press ENTER or type command to continue}^ |
]],
+ messages = {
+ {
+ content = { { 'Press ENTER or type command to continue', 100, 18 } },
+ history = true,
+ kind = 'return_prompt',
+ },
+ },
})
+ feed(':1mes clear<CR>:mes<CR>')
+ screen:expect([[
+ |
+ {3: }|
+ {9:Excessive errors in vim.ui_attach() call}|
+ {9:back from ns: 1.} |
+ {100:Press ENTER or type command to continue}^ |
+ ]])
feed('<cr>')
-- Also when scheduled
exec_lua([[
@@ -348,16 +383,17 @@ describe('vim.ui_attach', function()
end)
]])
screen:expect({
- any = 'fo^o',
+ grid = s1,
messages = {
{
content = {
{
'Error executing vim.schedule lua callback: [string "<nvim>"]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string "<nvim>"]:2: in function <[string "<nvim>"]:2>',
9,
- 7,
+ 6,
},
},
+ history = true,
kind = 'lua_error',
},
{
@@ -365,26 +401,35 @@ describe('vim.ui_attach', function()
{
'Error executing vim.schedule lua callback: [string "<nvim>"]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string "<nvim>"]:2: in function <[string "<nvim>"]:2>',
9,
- 7,
+ 6,
},
},
+ history = true,
kind = 'lua_error',
},
{
- content = { { 'Press ENTER or type command to continue', 100, 19 } },
+ content = { { 'Press ENTER or type command to continue', 100, 18 } },
+ history = false,
kind = 'return_prompt',
},
},
})
feed('<esc>:1mes clear<cr>:mes<cr>')
- screen:expect({
- grid = [[
- foo |
- {3: }|
- {9:Excessive errors in vim.ui_attach() call}|
- {9:back from ns: 2.} |
- {100:Press ENTER or type command to continue}^ |
- ]],
- })
+ screen:expect([[
+ |
+ {3: }|
+ {9:Excessive errors in vim.ui_attach() call}|
+ {9:back from ns: 2.} |
+ {100:Press ENTER or type command to continue}^ |
+ ]])
+ end)
+
+ it('sourcing invalid file does not crash #32166', function()
+ exec_lua([[
+ local ns = vim.api.nvim_create_namespace("")
+ vim.ui_attach(ns, { ext_messages = true }, function() end)
+ ]])
+ feed((':luafile %s<CR>'):format(testlog))
+ n.assert_alive()
end)
end)
diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua
index 258b96bc43..d706f8b78b 100644
--- a/test/functional/lua/uri_spec.lua
+++ b/test/functional/lua/uri_spec.lua
@@ -252,4 +252,12 @@ describe('URI methods', function()
end
)
end)
+
+ describe('encode to uri', function()
+ it('rfc2732 including brackets', function()
+ exec_lua("str = '[:]'")
+ exec_lua("rfc = 'rfc2732'")
+ eq('[%3a]', exec_lua('return vim.uri_encode(str, rfc)'))
+ end)
+ end)
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 3cfbfe167a..55e5158596 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -3435,7 +3435,6 @@ stack traceback:
end)
it('can discard input', function()
- clear()
-- discard every other normal 'x' command
exec_lua [[
n_key = 0
@@ -3461,7 +3460,6 @@ stack traceback:
end)
it('callback invalid return', function()
- clear()
-- second key produces an error which removes the callback
exec_lua [[
n_call = 0
@@ -3955,6 +3953,17 @@ stack traceback:
eq(win2, val)
end)
+ it('failure modes', function()
+ matches(
+ 'nvim_exec2%(%): Vim:E492: Not an editor command: fooooo',
+ pcall_err(exec_lua, [[vim.api.nvim_win_call(0, function() vim.cmd 'fooooo' end)]])
+ )
+ eq(
+ 'Error executing lua: [string "<nvim>"]:0: fooooo',
+ pcall_err(exec_lua, [[vim.api.nvim_win_call(0, function() error('fooooo') end)]])
+ )
+ end)
+
it('does not cause ml_get errors with invalid visual selection', function()
-- Add lines to the current buffer and make another window looking into an empty buffer.
exec_lua [[
diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua
index ad16df8a7c..3b109b70d5 100644
--- a/test/functional/lua/watch_spec.lua
+++ b/test/functional/lua/watch_spec.lua
@@ -91,8 +91,7 @@ describe('vim._watch', function()
skip(is_os('mac'), 'flaky test on mac')
skip(is_os('bsd'), 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38')
elseif watchfunc == 'watchdirs' and is_os('mac') then
- -- Bump this (or fix the bug) if CI continues to fail in future versions of macos CI.
- skip(is_ci() and vim.uv.os_uname().release == '24.0.0', 'weird failure for macOS arm 15 CI')
+ skip(true, 'weird failure since macOS 14 CI, see bbf208784ca279178ba0075b60d3e9c80f11da7a')
else
skip(
is_os('bsd'),
diff --git a/test/functional/lua/with_spec.lua b/test/functional/lua/with_spec.lua
index 6127e83619..92e798e7f3 100644
--- a/test/functional/lua/with_spec.lua
+++ b/test/functional/lua/with_spec.lua
@@ -1621,4 +1621,21 @@ describe('vim._with', function()
matches('Invalid buffer', get_error('{ buf = -1 }, function() end'))
matches('Invalid window', get_error('{ win = -1 }, function() end'))
end)
+
+ it('no double-free when called from :filter browse oldfiles #31501', function()
+ exec_lua([=[
+ vim.api.nvim_create_autocmd('BufEnter', {
+ callback = function()
+ vim._with({ lockmarks = true }, function() end)
+ end,
+ })
+ vim.cmd([[
+ let v:oldfiles = ['Xoldfile']
+ call nvim_input('1<CR>')
+ noswapfile filter /Xoldfile/ browse oldfiles
+ ]])
+ ]=])
+ n.assert_alive()
+ eq('Xoldfile', fn.bufname('%'))
+ end)
end)