aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/editor/defaults_spec.lua100
-rw-r--r--test/functional/lua/vim_spec.lua10
-rw-r--r--test/functional/options/defaults_spec.lua26
-rw-r--r--test/functional/plugin/lsp_spec.lua36
-rw-r--r--test/functional/terminal/tui_spec.lua2
-rw-r--r--test/functional/ui/multigrid_spec.lua1
-rw-r--r--test/functional/ui/popupmenu_spec.lua9
-rw-r--r--test/functional/vimscript/server_spec.lua67
-rw-r--r--test/old/testdir/setup.vim1
-rw-r--r--test/old/testdir/test_utf8.vim3
-rw-r--r--test/testutil.lua2
11 files changed, 200 insertions, 57 deletions
diff --git a/test/functional/editor/defaults_spec.lua b/test/functional/editor/defaults_spec.lua
new file mode 100644
index 0000000000..47fd177f7b
--- /dev/null
+++ b/test/functional/editor/defaults_spec.lua
@@ -0,0 +1,100 @@
+--
+-- Tests for default autocmds, mappings, commands, and menus.
+--
+-- See options/defaults_spec.lua for default options and environment decisions.
+--
+
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+local Screen = require('test.functional.ui.screen')
+
+describe('default', function()
+ describe('autocommands', function()
+ it('nvim_terminal.TermClose closes terminal with default shell on success', function()
+ n.clear()
+ n.api.nvim_set_option_value('shell', n.testprg('shell-test'), {})
+ n.command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=')
+
+ -- Should not block other events
+ n.command('let g:n=0')
+ n.command('au BufEnter * let g:n = g:n + 1')
+
+ n.command('terminal')
+ t.eq(1, n.eval('get(g:, "n", 0)'))
+
+ t.retry(nil, 1000, function()
+ t.neq('terminal', n.api.nvim_get_option_value('buftype', { buf = 0 }))
+ t.eq(2, n.eval('get(g:, "n", 0)'))
+ end)
+ end)
+ end)
+
+ describe('popupmenu', function()
+ it('can be disabled by user', function()
+ n.clear {
+ args = { '+autocmd! nvim_popupmenu', '+aunmenu PopUp' },
+ }
+ local screen = Screen.new(40, 8)
+ screen:attach()
+ n.insert([[
+ 1 line 1
+ 2 https://example.com
+ 3 line 3
+ 4 line 4]])
+
+ n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
+ screen:expect({
+ grid = [[
+ 1 line 1 |
+ 2 ht^tps://example.com |
+ 3 line 3 |
+ 4 line 4 |
+ {1:~ }|*3
+ |
+ ]],
+ })
+ end)
+
+ it('right-click on URL shows "Open in web browser"', function()
+ n.clear()
+ local screen = Screen.new(40, 8)
+ screen:attach()
+ n.insert([[
+ 1 line 1
+ 2 https://example.com
+ 3 line 3
+ 4 line 4]])
+
+ n.api.nvim_input_mouse('right', 'press', '', 0, 3, 4)
+ screen:expect({
+ grid = [[
+ 1 line 1 |
+ 2 https://example.com |
+ 3 line 3 |
+ 4 li^ne 4 |
+ {1:~ }{4: Inspect }{1: }|
+ {1:~ }{4: }{1: }|
+ {1:~ }{4: Paste }{1: }|
+ {4: Select All } |
+ ]],
+ })
+
+ n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
+ screen:expect({
+ grid = [[
+ 1 line 1 |
+ 2 ht^tps://example.com |
+ 3 l{4: Open in web browser } |
+ 4 l{4: Inspect } |
+ {1:~ }{4: }{1: }|
+ {1:~ }{4: Paste }{1: }|
+ {1:~ }{4: Select All }{1: }|
+ {4: } |
+ ]],
+ })
+ end)
+ end)
+
+ -- describe('key mappings', function()
+ -- end)
+end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index df68020d8e..7bba24483e 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -1059,7 +1059,7 @@ describe('lua stdlib', function()
local a = { a = {[2] = 3} }
local b = { a = {[3] = 3} }
local c = vim.tbl_deep_extend("force", a, b)
- return vim.deep_equal(c, {a = {[3] = 3}})
+ return vim.deep_equal(c, {a = {[2] = 3, [3] = 3}})
]]))
eq(
@@ -1071,6 +1071,14 @@ describe('lua stdlib', function()
]])
)
+ -- Fix github issue #23654
+ ok(exec_lua([[
+ local a = { sub = { [1] = 'a' } }
+ local b = { sub = { b = 'a' } }
+ local c = vim.tbl_deep_extend('force', a, b)
+ return vim.deep_equal(c, { sub = { [1] = 'a', b = 'a' } })
+ ]]))
+
matches(
'invalid "behavior": nil',
pcall_err(
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua
index 0faced5149..ca4a6eaca7 100644
--- a/test/functional/options/defaults_spec.lua
+++ b/test/functional/options/defaults_spec.lua
@@ -1,3 +1,9 @@
+--
+-- Tests for default options and environment decisions.
+--
+-- See editor/defaults_spec.lua for default autocmds, mappings, commands, and menus.
+--
+
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
@@ -1255,23 +1261,3 @@ describe('stdpath()', function()
end)
end)
end)
-
-describe('autocommands', function()
- it('closes terminal with default shell on success', function()
- clear()
- api.nvim_set_option_value('shell', n.testprg('shell-test'), {})
- command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=')
-
- -- Should not block other events
- command('let g:n=0')
- command('au BufEnter * let g:n = g:n + 1')
-
- command('terminal')
- eq(1, eval('get(g:, "n", 0)'))
-
- t.retry(nil, 1000, function()
- neq('terminal', api.nvim_get_option_value('buftype', { buf = 0 }))
- eq(2, eval('get(g:, "n", 0)'))
- end)
- end)
-end)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 1347ea9745..1d43b5d449 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2673,7 +2673,7 @@ describe('LSP', function()
describe('lsp.util.locations_to_items', function()
it('Convert Location[] to items', function()
- local expected = {
+ local expected_template = {
{
filename = '/fake/uri',
lnum = 1,
@@ -2681,7 +2681,12 @@ describe('LSP', function()
col = 3,
end_col = 4,
text = 'testing',
- user_data = {
+ user_data = {},
+ },
+ }
+ local test_params = {
+ {
+ {
uri = 'file:///fake/uri',
range = {
start = { line = 0, character = 2 },
@@ -2689,23 +2694,28 @@ describe('LSP', function()
},
},
},
- }
- local actual = exec_lua(function()
- local bufnr = vim.uri_to_bufnr('file:///fake/uri')
- local lines = { 'testing', '123' }
- vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
- local locations = {
+ {
{
uri = 'file:///fake/uri',
range = {
start = { line = 0, character = 2 },
- ['end'] = { line = 1, character = 3 },
+ -- LSP spec: if character > line length, default to the line length.
+ ['end'] = { line = 1, character = 10000 },
},
},
- }
- return vim.lsp.util.locations_to_items(locations, 'utf-16')
- end)
- eq(expected, actual)
+ },
+ }
+ for _, params in ipairs(test_params) do
+ local actual = exec_lua(function(params0)
+ local bufnr = vim.uri_to_bufnr('file:///fake/uri')
+ local lines = { 'testing', '123' }
+ vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
+ return vim.lsp.util.locations_to_items(params0, 'utf-16')
+ end, params)
+ local expected = vim.deepcopy(expected_template)
+ expected[1].user_data = params[1]
+ eq(expected, actual)
+ end
end)
it('Convert LocationLink[] to items', function()
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 50199bd83d..bba1436bdc 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -630,6 +630,8 @@ describe('TUI', function()
set mouse=a mousemodel=popup
aunmenu PopUp
+ " Delete the default MenuPopup event handler.
+ autocmd! nvim_popupmenu
menu PopUp.foo :let g:menustr = 'foo'<CR>
menu PopUp.bar :let g:menustr = 'bar'<CR>
menu PopUp.baz :let g:menustr = 'baz'<CR>
diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua
index dc48061a6c..63ae38d3c3 100644
--- a/test/functional/ui/multigrid_spec.lua
+++ b/test/functional/ui/multigrid_spec.lua
@@ -1095,6 +1095,7 @@ describe('ext_multigrid', function()
end)
it('supports mouse', function()
+ command('autocmd! nvim_popupmenu') -- Delete the default MenuPopup event handler.
insert('some text\nto be clicked')
screen:expect{grid=[[
## grid 1
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index 370a18b908..3acbd5d987 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -851,6 +851,8 @@ describe('ui/ext_popupmenu', function()
set mouse=a mousemodel=popup
aunmenu PopUp
+ " Delete the default MenuPopup event handler.
+ autocmd! nvim_popupmenu
menu PopUp.foo :let g:menustr = 'foo'<CR>
menu PopUp.bar :let g:menustr = 'bar'<CR>
menu PopUp.baz :let g:menustr = 'baz'<CR>
@@ -3805,6 +3807,8 @@ describe('builtin popupmenu', function()
call setline(1, 'popup menu test')
set mouse=a mousemodel=popup
+ " Delete the default MenuPopup event handler.
+ autocmd! nvim_popupmenu
aunmenu PopUp
menu PopUp.foo :let g:menustr = 'foo'<CR>
menu PopUp.bar :let g:menustr = 'bar'<CR>
@@ -4489,6 +4493,9 @@ describe('builtin popupmenu', function()
-- oldtest: Test_popup_command_dump()
it(':popup command', function()
exec([[
+ " Delete the default MenuPopup event handler.
+ autocmd! nvim_popupmenu
+
func ChangeMenu()
aunmenu PopUp.&Paste
nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
@@ -4646,6 +4653,8 @@ describe('builtin popupmenu', function()
screen:try_resize(50, 20)
exec([[
set mousemodel=popup_setpos
+ " Delete the default MenuPopup event handler.
+ autocmd! nvim_popupmenu
aunmenu *
source $VIMRUNTIME/menu.vim
call setline(1, join(range(20)))
diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua
index 2dabe1afc1..f3c72b7da8 100644
--- a/test/functional/vimscript/server_spec.lua
+++ b/test/functional/vimscript/server_spec.lua
@@ -1,7 +1,6 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
-local assert_log = t.assert_log
local eq, neq, eval = t.eq, t.neq, n.eval
local clear, fn, api = n.clear, n.fn, n.api
local matches = t.matches
@@ -19,12 +18,16 @@ local function clear_serverlist()
end
end
-describe('server', function()
- after_each(function()
- check_close()
- os.remove(testlog)
- end)
+after_each(function()
+ check_close()
+ os.remove(testlog)
+end)
+before_each(function()
+ os.remove(testlog)
+end)
+
+describe('server', function()
it('serverstart() stores sockets in $XDG_RUNTIME_DIR', function()
local dir = 'Xtest_xdg_run'
mkdir(dir)
@@ -88,7 +91,7 @@ describe('server', function()
}
eq(0, eval("serverstop('')"))
eq(0, eval("serverstop('bogus-socket-name')"))
- assert_log('Not listening on bogus%-socket%-name', testlog, 10)
+ t.assert_log('Not listening on bogus%-socket%-name', testlog, 10)
end)
it('parses endpoints', function()
@@ -122,7 +125,7 @@ describe('server', function()
if status then
table.insert(expected, v4)
pcall(fn.serverstart, v4) -- exists already; ignore
- assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10)
+ t.assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10)
end
local v6 = '::1:12345'
@@ -130,7 +133,7 @@ describe('server', function()
if status then
table.insert(expected, v6)
pcall(fn.serverstart, v6) -- exists already; ignore
- assert_log('Failed to start server: address already in use: ::1', testlog, 10)
+ t.assert_log('Failed to start server: address already in use: ::1', testlog, 10)
end
eq(expected, fn.serverlist())
clear_serverlist()
@@ -173,24 +176,42 @@ end)
describe('startup --listen', function()
it('validates', function()
- clear()
+ clear { env = { NVIM_LOG_FILE = testlog } }
-- Tests args with and without "--headless".
local function _test(args, expected)
- -- XXX: clear v:shell_error, sigh...
- fn.system({ n.nvim_prog, '-es', '+qall!' })
- assert(0 == eval('v:shell_error'))
- local cmd = vim.list_extend({ unpack(n.nvim_argv) }, vim.list_extend({ '--headless' }, args))
- local output = fn.system(cmd)
- assert(0 ~= eval('v:shell_error'))
- -- TODO(justinmk): output not properly captured on Windows?
+ local function run(cmd)
+ return n.exec_lua(function(cmd_)
+ return vim
+ .system(cmd_, {
+ text = true,
+ env = {
+ -- Avoid noise in the logs; we expect failures for these tests.
+ NVIM_LOG_FILE = testlog,
+ },
+ })
+ :wait()
+ end, cmd) --[[@as vim.SystemCompleted]]
+ end
+
+ local cmd = vim.list_extend({ n.nvim_prog, '+qall!', '--headless' }, args)
+ local r = run(cmd)
+ eq(1, r.code)
+ matches(expected, (r.stderr .. r.stdout):gsub('\\n', ' '))
+
if is_os('win') then
- return
+ return -- On Windows, output without --headless is garbage.
end
- matches(expected, output)
- matches(expected, fn.system(vim.list_extend({ unpack(n.nvim_argv) }, args)))
+ table.remove(cmd, 3) -- Remove '--headless'.
+ assert(not vim.tbl_contains(cmd, '--headless'))
+ r = run(cmd)
+ eq(1, r.code)
+ matches(expected, (r.stderr .. r.stdout):gsub('\\n', ' '))
end
+ t.assert_nolog('Failed to start server', testlog, 100)
+ t.assert_nolog('Host lookup failed', testlog, 100)
+
_test({ '--listen' }, 'nvim.*: Argument missing after: "%-%-listen"')
_test({ '--listen2' }, 'nvim.*: Garbage after option argument: "%-%-listen2"')
_test({ '--listen', n.eval('v:servername') }, 'nvim.*: Failed to %-%-listen: ".* already .*"')
@@ -198,10 +219,12 @@ describe('startup --listen', function()
_test(
{ '--listen', 'https://example.com' },
('nvim.*: Failed to %%-%%-listen: "%s"'):format(
- (is_os('mac') or is_os('win')) and 'unknown node or service'
- or 'service not available for socket type'
+ is_os('mac') and 'unknown node or service' or 'service not available for socket type'
)
)
+
+ t.assert_log('Failed to start server', testlog, 100)
+ t.assert_log('Host lookup failed', testlog, 100)
end)
it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function()
diff --git a/test/old/testdir/setup.vim b/test/old/testdir/setup.vim
index 6f400c5e32..e7b4bb1a88 100644
--- a/test/old/testdir/setup.vim
+++ b/test/old/testdir/setup.vim
@@ -66,6 +66,7 @@ mapclear
mapclear!
aunmenu *
tlunmenu *
+autocmd! nvim_popupmenu
" Undo the 'grepprg' and 'grepformat' setting in _defaults.lua.
set grepprg& grepformat&
diff --git a/test/old/testdir/test_utf8.vim b/test/old/testdir/test_utf8.vim
index 3248dc9d98..f46fb9d744 100644
--- a/test/old/testdir/test_utf8.vim
+++ b/test/old/testdir/test_utf8.vim
@@ -228,6 +228,9 @@ func Test_setcellwidths()
call setcellwidths([[0x2103, 0x2103, 2]])
redraw
call assert_equal(19, wincol())
+ call setcellwidths([])
+ redraw
+ call assert_equal((aw == 'single') ? 10 : 19, wincol())
endfor
set ambiwidth& isprint&
diff --git a/test/testutil.lua b/test/testutil.lua
index 01eaf25406..abfc10e806 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -143,7 +143,7 @@ end
---
---@param pat (string) Lua pattern to match lines in the log file
---@param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE)
----@param nrlines? (number) Search up to this many log lines
+---@param nrlines? (number) Search up to this many log lines (default 10)
---@param inverse? (boolean) Assert that the pattern does NOT match.
function M.assert_log(pat, logfile, nrlines, inverse)
logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog'