aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/api/buffer_spec.lua66
-rw-r--r--test/functional/api/tabpage_spec.lua26
-rw-r--r--test/functional/api/vim_spec.lua4
-rw-r--r--test/functional/api/window_spec.lua779
-rw-r--r--test/functional/autocmd/focus_spec.lua2
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua6
-rw-r--r--test/functional/core/main_spec.lua12
-rw-r--r--test/functional/ex_cmds/cmd_map_spec.lua4
-rw-r--r--test/functional/legacy/conceal_spec.lua269
-rw-r--r--test/functional/legacy/matchparen_spec.lua43
-rw-r--r--test/functional/legacy/memory_usage_spec.lua2
-rw-r--r--test/functional/lua/buffer_updates_spec.lua8
-rw-r--r--test/functional/lua/diagnostic_spec.lua2
-rw-r--r--test/functional/lua/ffi_spec.lua13
-rw-r--r--test/functional/lua/thread_spec.lua4
-rw-r--r--test/functional/lua/vim_spec.lua44
-rw-r--r--test/functional/lua/watch_spec.lua226
-rw-r--r--test/functional/options/defaults_spec.lua6
-rw-r--r--test/functional/options/num_options_spec.lua2
-rw-r--r--test/functional/options/winfixbuf_spec.lua54
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua10
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua14
-rw-r--r--test/functional/plugin/lsp_spec.lua411
-rw-r--r--test/functional/plugin/tohtml_spec.lua18
-rw-r--r--test/functional/provider/python3_spec.lua7
-rw-r--r--test/functional/script/luacats_grammar_spec.lua21
-rw-r--r--test/functional/script/luacats_parser_spec.lua106
-rw-r--r--test/functional/script/text_utils_spec.lua61
-rw-r--r--test/functional/shada/merging_spec.lua10
-rw-r--r--test/functional/terminal/window_spec.lua10
-rw-r--r--test/functional/treesitter/highlight_spec.lua123
-rw-r--r--test/functional/treesitter/node_spec.lua5
-rw-r--r--test/functional/treesitter/parser_spec.lua12
-rw-r--r--test/functional/ui/decorations_spec.lua15
-rw-r--r--test/functional/ui/float_spec.lua177
-rw-r--r--test/functional/ui/highlight_spec.lua43
-rw-r--r--test/functional/ui/inccommand_spec.lua4
-rw-r--r--test/functional/ui/messages_spec.lua54
-rw-r--r--test/functional/ui/statuscolumn_spec.lua13
-rw-r--r--test/functional/ui/statusline_spec.lua20
40 files changed, 2258 insertions, 448 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 78d220ff57..a560546d2d 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -121,6 +121,65 @@ describe('api/buf', function()
eq({ 5, 2 }, api.nvim_win_get_cursor(win2))
end)
+ it('cursor position is maintained consistently with viewport', function()
+ local screen = Screen.new(20, 12)
+ screen:set_default_attr_ids {
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { reverse = true, bold = true },
+ [3] = { reverse = true },
+ }
+ screen:attach()
+
+ local lines = { 'line1', 'line2', 'line3', 'line4', 'line5', 'line6' }
+ local buf = api.nvim_get_current_buf()
+
+ api.nvim_buf_set_lines(buf, 0, -1, true, lines)
+
+ command('6')
+ command('new')
+ screen:expect {
+ grid = [[
+ ^ |
+ {1:~ }|*4
+ {2:[No Name] }|
+ line5 |
+ line6 |
+ {1:~ }|*2
+ {3:[No Name] [+] }|
+ |
+ ]],
+ }
+
+ lines[5] = 'boogalo 5'
+ api.nvim_buf_set_lines(buf, 0, -1, true, lines)
+ screen:expect {
+ grid = [[
+ ^ |
+ {1:~ }|*4
+ {2:[No Name] }|
+ boogalo 5 |
+ line6 |
+ {1:~ }|*2
+ {3:[No Name] [+] }|
+ |
+ ]],
+ }
+
+ command('wincmd w')
+ screen:expect {
+ grid = [[
+ |
+ {1:~ }|*4
+ {3:[No Name] }|
+ boogalo 5 |
+ ^line6 |
+ {1:~ }|*2
+ {2:[No Name] [+] }|
+ |
+ ]],
+ }
+ end)
+
it('line_count has defined behaviour for unloaded buffers', function()
-- we'll need to know our bufnr for when it gets unloaded
local bufnr = api.nvim_buf_get_number(0)
@@ -323,20 +382,20 @@ describe('api/buf', function()
]],
}
- -- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
- mmm |
wwweeee |
xxx |
yyy |
+ zzz |
{3:[No Name] [+] }|
|
]],
+ unchanged = true,
}
end)
@@ -402,7 +461,6 @@ describe('api/buf', function()
]],
}
- -- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
@@ -412,10 +470,10 @@ describe('api/buf', function()
mmm |
wwweeee |
{2:[No Name] [+] }|
- mmm |
wwweeee |
xxx |
yyy |
+ zzz |
{3:[No Name] [+] }|
|
]],
diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua
index 36955c4ace..f7e6eed047 100644
--- a/test/functional/api/tabpage_spec.lua
+++ b/test/functional/api/tabpage_spec.lua
@@ -1,5 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok
+local exec = helpers.exec
+local feed = helpers.feed
local api = helpers.api
local fn = helpers.fn
local request = helpers.request
@@ -86,6 +88,30 @@ describe('api/tabpage', function()
pcall_err(api.nvim_tabpage_set_win, tab1, win3)
)
end)
+
+ it('does not switch window when textlocked or in the cmdwin', function()
+ local target_win = api.nvim_get_current_win()
+ feed('q:')
+ local cur_win = api.nvim_get_current_win()
+ eq(
+ 'Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(api.nvim_tabpage_set_win, 0, target_win)
+ )
+ eq(cur_win, api.nvim_get_current_win())
+ command('quit!')
+
+ exec(([[
+ new
+ call setline(1, 'foo')
+ setlocal debug=throw indentexpr=nvim_tabpage_set_win(0,%d)
+ ]]):format(target_win))
+ cur_win = api.nvim_get_current_win()
+ eq(
+ 'Vim(normal):E5555: API call: Vim:E565: Not allowed to change text or change window',
+ pcall_err(command, 'normal! ==')
+ )
+ eq(cur_win, api.nvim_get_current_win())
+ end)
end)
describe('{get,set,del}_var', function()
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 9a4a457637..09a45242ec 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -707,13 +707,13 @@ describe('API', function()
it('works', function()
api.nvim_set_current_dir('Xtestdir')
- eq(fn.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir')
+ eq(start_dir .. helpers.get_pathsep() .. 'Xtestdir', fn.getcwd())
end)
it('sets previous directory', function()
api.nvim_set_current_dir('Xtestdir')
command('cd -')
- eq(fn.getcwd(), start_dir)
+ eq(start_dir, fn.getcwd())
end)
end)
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 097a546ef2..a10c8f48ef 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -1364,6 +1364,308 @@ describe('API/win', function()
},
}, layout)
end)
+
+ local function setup_tabbed_autocmd_test()
+ local info = {}
+ info.orig_buf = api.nvim_get_current_buf()
+ info.other_buf = api.nvim_create_buf(true, true)
+ info.tab1_curwin = api.nvim_get_current_win()
+ info.tab1 = api.nvim_get_current_tabpage()
+ command('tab split | split')
+ info.tab2_curwin = api.nvim_get_current_win()
+ info.tab2 = api.nvim_get_current_tabpage()
+ exec([=[
+ tabfirst
+ let result = []
+ autocmd TabEnter * let result += [["TabEnter", nvim_get_current_tabpage()]]
+ autocmd TabLeave * let result += [["TabLeave", nvim_get_current_tabpage()]]
+ autocmd WinEnter * let result += [["WinEnter", win_getid()]]
+ autocmd WinLeave * let result += [["WinLeave", win_getid()]]
+ autocmd WinNew * let result += [["WinNew", win_getid()]]
+ autocmd WinClosed * let result += [["WinClosed", str2nr(expand("<afile>"))]]
+ autocmd BufEnter * let result += [["BufEnter", win_getid(), bufnr()]]
+ autocmd BufLeave * let result += [["BufLeave", win_getid(), bufnr()]]
+ autocmd BufWinEnter * let result += [["BufWinEnter", win_getid(), bufnr()]]
+ autocmd BufWinLeave * let result += [["BufWinLeave", win_getid(), bufnr()]]
+ ]=])
+ return info
+ end
+
+ it('fires expected autocmds when creating splits without entering', function()
+ local info = setup_tabbed_autocmd_test()
+
+ -- For these, don't want BufWinEnter if visiting the same buffer, like :{s}buffer.
+ -- Same tabpage, same buffer.
+ local new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab1_curwin })
+ eq({
+ { 'WinNew', new_win },
+ }, eval('result'))
+ eq(info.tab1_curwin, api.nvim_get_current_win())
+
+ -- Other tabpage, same buffer.
+ command('let result = []')
+ new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab2_curwin })
+ eq({
+ { 'WinNew', new_win },
+ }, eval('result'))
+ eq(info.tab1_curwin, api.nvim_get_current_win())
+
+ -- Same tabpage, other buffer.
+ command('let result = []')
+ new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab1_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'BufWinEnter', new_win, info.other_buf },
+ }, eval('result'))
+ eq(info.tab1_curwin, api.nvim_get_current_win())
+
+ -- Other tabpage, other buffer.
+ command('let result = []')
+ new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab2_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'BufWinEnter', new_win, info.other_buf },
+ }, eval('result'))
+ eq(info.tab1_curwin, api.nvim_get_current_win())
+ end)
+
+ it('fires expected autocmds when creating and entering splits', function()
+ local info = setup_tabbed_autocmd_test()
+
+ -- Same tabpage, same buffer.
+ local new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab1_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'WinLeave', info.tab1_curwin },
+ { 'WinEnter', new_win },
+ }, eval('result'))
+
+ -- Same tabpage, other buffer.
+ api.nvim_set_current_win(info.tab1_curwin)
+ command('let result = []')
+ new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab1_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'WinLeave', info.tab1_curwin },
+ { 'WinEnter', new_win },
+ { 'BufLeave', new_win, info.orig_buf },
+ { 'BufEnter', new_win, info.other_buf },
+ { 'BufWinEnter', new_win, info.other_buf },
+ }, eval('result'))
+
+ -- For these, the other tabpage's prevwin and curwin will change like we switched from its old
+ -- curwin to the new window, so the extra events near TabEnter reflect that.
+ -- Other tabpage, same buffer.
+ api.nvim_set_current_win(info.tab1_curwin)
+ command('let result = []')
+ new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab2_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'WinLeave', info.tab1_curwin },
+ { 'TabLeave', info.tab1 },
+
+ { 'WinEnter', info.tab2_curwin },
+ { 'TabEnter', info.tab2 },
+ { 'WinLeave', info.tab2_curwin },
+ { 'WinEnter', new_win },
+ }, eval('result'))
+
+ -- Other tabpage, other buffer.
+ api.nvim_set_current_win(info.tab2_curwin)
+ api.nvim_set_current_win(info.tab1_curwin)
+ command('let result = []')
+ new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'WinLeave', info.tab1_curwin },
+ { 'TabLeave', info.tab1 },
+
+ { 'WinEnter', info.tab2_curwin },
+ { 'TabEnter', info.tab2 },
+ { 'WinLeave', info.tab2_curwin },
+ { 'WinEnter', new_win },
+
+ { 'BufLeave', new_win, info.orig_buf },
+ { 'BufEnter', new_win, info.other_buf },
+ { 'BufWinEnter', new_win, info.other_buf },
+ }, eval('result'))
+
+ -- Other tabpage, other buffer; but other tabpage's curwin has a new buffer active.
+ api.nvim_set_current_win(info.tab2_curwin)
+ local new_buf = api.nvim_create_buf(true, true)
+ api.nvim_set_current_buf(new_buf)
+ api.nvim_set_current_win(info.tab1_curwin)
+ command('let result = []')
+ new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
+ eq({
+ { 'WinNew', new_win },
+ { 'BufLeave', info.tab1_curwin, info.orig_buf },
+ { 'WinLeave', info.tab1_curwin },
+ { 'TabLeave', info.tab1 },
+
+ { 'WinEnter', info.tab2_curwin },
+ { 'TabEnter', info.tab2 },
+ { 'BufEnter', info.tab2_curwin, new_buf },
+ { 'WinLeave', info.tab2_curwin },
+ { 'WinEnter', new_win },
+ { 'BufLeave', new_win, new_buf },
+ { 'BufEnter', new_win, info.other_buf },
+ { 'BufWinEnter', new_win, info.other_buf },
+ }, eval('result'))
+ end)
+
+ it('OK when new window is moved to other tabpage by autocommands', function()
+ -- Use nvim_win_set_config in the autocommands, as other methods of moving a window to a
+ -- different tabpage (e.g: wincmd T) actually creates a new window.
+ local tab0 = api.nvim_get_current_tabpage()
+ local tab0_win = api.nvim_get_current_win()
+ command('tabnew')
+ local new_buf = api.nvim_create_buf(true, true)
+ local tab1 = api.nvim_get_current_tabpage()
+ local tab1_parent = api.nvim_get_current_win()
+ command(
+ 'tabfirst | autocmd WinNew * ++once call nvim_win_set_config(0, #{split: "left", win: '
+ .. tab1_parent
+ .. '})'
+ )
+ local new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
+ eq(tab1, api.nvim_get_current_tabpage())
+ eq(new_win, api.nvim_get_current_win())
+ eq(new_buf, api.nvim_get_current_buf())
+
+ -- nvim_win_set_config called after entering. It doesn't follow a curwin that is moved to a
+ -- different tabpage, but instead moves to the win filling the space, which is tab0_win.
+ command(
+ 'tabfirst | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
+ .. tab1_parent
+ .. '})'
+ )
+ new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
+ eq(tab0, api.nvim_get_current_tabpage())
+ eq(tab0_win, api.nvim_get_current_win())
+ eq(tab1, api.nvim_win_get_tabpage(new_win))
+ eq(new_buf, api.nvim_win_get_buf(new_win))
+
+ command(
+ 'tabfirst | autocmd BufEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
+ .. tab1_parent
+ .. '})'
+ )
+ new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
+ eq(tab0, api.nvim_get_current_tabpage())
+ eq(tab0_win, api.nvim_get_current_win())
+ eq(tab1, api.nvim_win_get_tabpage(new_win))
+ eq(new_buf, api.nvim_win_get_buf(new_win))
+ end)
+
+ it('does not fire BufWinEnter if win_set_buf fails', function()
+ exec([[
+ set nohidden modified
+ autocmd WinNew * ++once only!
+ let fired = v:false
+ autocmd BufWinEnter * ++once let fired = v:true
+ ]])
+ eq(
+ 'Failed to set buffer 2',
+ pcall_err(api.nvim_open_win, api.nvim_create_buf(true, true), false, { split = 'left' })
+ )
+ eq(false, eval('fired'))
+ end)
+
+ it('fires Buf* autocommands when `!enter` if window is entered via autocommands', function()
+ exec([[
+ autocmd WinNew * ++once only!
+ let fired = v:false
+ autocmd BufEnter * ++once let fired = v:true
+ ]])
+ api.nvim_open_win(api.nvim_create_buf(true, true), false, { split = 'left' })
+ eq(true, eval('fired'))
+ end)
+
+ it('no heap-use-after-free if target buffer deleted by autocommands', function()
+ local cur_buf = api.nvim_get_current_buf()
+ local new_buf = api.nvim_create_buf(true, true)
+ command('autocmd WinNew * ++once call nvim_buf_delete(' .. new_buf .. ', #{force: 1})')
+ api.nvim_open_win(new_buf, true, { split = 'left' })
+ eq(cur_buf, api.nvim_get_current_buf())
+ end)
+
+ it('checks if splitting disallowed', function()
+ command('split | autocmd WinEnter * ++once call nvim_open_win(0, 0, #{split: "right"})')
+ matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
+
+ command('only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left"})')
+ matches(
+ 'E1159: Cannot split a window when closing the buffer$',
+ pcall_err(command, 'new | quit')
+ )
+
+ local w = api.nvim_get_current_win()
+ command(
+ 'only | new | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
+ .. w
+ .. '})'
+ )
+ matches(
+ 'E1159: Cannot split a window when closing the buffer$',
+ pcall_err(api.nvim_win_close, w, true)
+ )
+
+ -- OK when using window to different buffer than `win`s.
+ w = api.nvim_get_current_win()
+ command(
+ 'only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
+ .. w
+ .. '})'
+ )
+ command('new | quit')
+ end)
+
+ it('restores last known cursor position if BufWinEnter did not move it', function()
+ -- This test mostly exists to ensure BufWinEnter is executed before enter_buffer's epilogue.
+ local buf = api.nvim_get_current_buf()
+ insert([[
+ foo
+ bar baz .etc
+ i love autocommand bugs!
+ supercalifragilisticexpialidocious
+ marvim is actually a human
+ llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch
+ ]])
+ api.nvim_win_set_cursor(0, { 5, 2 })
+ command('set nostartofline | enew')
+ local new_win = api.nvim_open_win(buf, false, { split = 'left' })
+ eq({ 5, 2 }, api.nvim_win_get_cursor(new_win))
+
+ exec([[
+ only!
+ autocmd BufWinEnter * ++once normal! j6l
+ ]])
+ new_win = api.nvim_open_win(buf, false, { split = 'left' })
+ eq({ 2, 6 }, api.nvim_win_get_cursor(new_win))
+ end)
+
+ it('does not block all win_set_buf autocommands if !enter and !noautocmd', function()
+ local new_buf = fn.bufadd('foobarbaz')
+ exec([[
+ let triggered = ""
+ autocmd BufReadCmd * ++once let triggered = bufname()
+ ]])
+ api.nvim_open_win(new_buf, false, { split = 'left' })
+ eq('foobarbaz', eval('triggered'))
+ end)
+
+ it('sets error when no room', function()
+ matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_open_win, 0, true, { split = 'above', win = 0 })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_open_win, 0, true, { split = 'below', win = 0 })
+ )
+ end)
end)
describe('set_config', function()
@@ -1471,6 +1773,15 @@ describe('API/win', function()
config = api.nvim_win_get_config(win)
eq('', config.relative)
eq('below', config.split)
+
+ eq(
+ "non-float with 'win' requires at least 'split' or 'vertical'",
+ pcall_err(api.nvim_win_set_config, 0, { win = 0 })
+ )
+ eq(
+ "non-float with 'win' requires at least 'split' or 'vertical'",
+ pcall_err(api.nvim_win_set_config, 0, { win = 0, relative = '' })
+ )
end)
it('creates top-level splits', function()
@@ -1663,6 +1974,474 @@ describe('API/win', function()
},
}, fn.winlayout())
end)
+
+ it('closing new curwin when moving window to other tabpage works', function()
+ command('split | tabnew')
+ local t2_win = api.nvim_get_current_win()
+ command('tabfirst | autocmd WinEnter * ++once quit')
+ local t1_move_win = api.nvim_get_current_win()
+ -- win_set_config fails to switch away from "t1_move_win" because the WinEnter autocmd that
+ -- closed the window we're switched to returns us to "t1_move_win", as it filled the space.
+ eq(
+ 'Failed to switch away from window ' .. t1_move_win,
+ pcall_err(api.nvim_win_set_config, t1_move_win, { win = t2_win, split = 'left' })
+ )
+ eq(t1_move_win, api.nvim_get_current_win())
+
+ command('split | split | autocmd WinEnter * ++once quit')
+ t1_move_win = api.nvim_get_current_win()
+ -- In this case, we closed the window that we got switched to, but doing so didn't switch us
+ -- back to "t1_move_win", which is fine.
+ api.nvim_win_set_config(t1_move_win, { win = t2_win, split = 'left' })
+ neq(t1_move_win, api.nvim_get_current_win())
+ end)
+
+ it('messing with "win" or "parent" when moving "win" to other tabpage', function()
+ command('split | tabnew')
+ local t2 = api.nvim_get_current_tabpage()
+ local t2_win1 = api.nvim_get_current_win()
+ command('split')
+ local t2_win2 = api.nvim_get_current_win()
+ command('split')
+ local t2_win3 = api.nvim_get_current_win()
+
+ command('tabfirst | autocmd WinEnter * ++once call nvim_win_close(' .. t2_win1 .. ', 1)')
+ local cur_win = api.nvim_get_current_win()
+ eq(
+ 'Windows to split were closed',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_win1, split = 'left' })
+ )
+ eq(cur_win, api.nvim_get_current_win())
+
+ command('split | autocmd WinLeave * ++once quit!')
+ cur_win = api.nvim_get_current_win()
+ eq(
+ 'Windows to split were closed',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_win2, split = 'left' })
+ )
+ neq(cur_win, api.nvim_get_current_win())
+
+ exec([[
+ split
+ autocmd WinLeave * ++once
+ \ call nvim_win_set_config(0, #{relative:'editor', row:0, col:0, width:5, height:5})
+ ]])
+ cur_win = api.nvim_get_current_win()
+ eq(
+ 'Floating state of windows to split changed',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_win3, split = 'left' })
+ )
+ eq('editor', api.nvim_win_get_config(0).relative)
+ eq(cur_win, api.nvim_get_current_win())
+
+ command('autocmd WinLeave * ++once wincmd J')
+ cur_win = api.nvim_get_current_win()
+ eq(
+ 'Floating state of windows to split changed',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_win3, split = 'left' })
+ )
+ eq('', api.nvim_win_get_config(0).relative)
+ eq(cur_win, api.nvim_get_current_win())
+
+ -- Try to make "parent" floating. This should give the same error as before, but because
+ -- changing a split from another tabpage into a float isn't supported yet, check for that
+ -- error instead for now.
+ -- Use ":silent!" to avoid the one second delay from printing the error message.
+ exec(([[
+ autocmd WinLeave * ++once silent!
+ \ call nvim_win_set_config(%d, #{relative:'editor', row:0, col:0, width:5, height:5})
+ ]]):format(t2_win3))
+ cur_win = api.nvim_get_current_win()
+ api.nvim_win_set_config(0, { win = t2_win3, split = 'left' })
+ matches(
+ 'Cannot change window from different tabpage into float$',
+ api.nvim_get_vvar('errmsg')
+ )
+ -- The error doesn't abort moving the window (or maybe it should, if that's wanted?)
+ neq(cur_win, api.nvim_get_current_win())
+ eq(t2, api.nvim_win_get_tabpage(cur_win))
+ end)
+
+ it('expected autocmds when moving window to other tabpage', function()
+ local new_curwin = api.nvim_get_current_win()
+ command('split')
+ local win = api.nvim_get_current_win()
+ command('tabnew')
+ local parent = api.nvim_get_current_win()
+ exec([[
+ tabfirst
+ let result = []
+ autocmd WinEnter * let result += ["Enter", win_getid()]
+ autocmd WinLeave * let result += ["Leave", win_getid()]
+ autocmd WinNew * let result += ["New", win_getid()]
+ ]])
+ api.nvim_win_set_config(0, { win = parent, split = 'left' })
+ -- Shouldn't see WinNew, as we're not creating any new windows, just moving existing ones.
+ eq({ 'Leave', win, 'Enter', new_curwin }, eval('result'))
+ end)
+
+ it('no autocmds when moving window within same tabpage', function()
+ local parent = api.nvim_get_current_win()
+ exec([[
+ split
+ let result = []
+ autocmd WinEnter * let result += ["Enter", win_getid()]
+ autocmd WinLeave * let result += ["Leave", win_getid()]
+ autocmd WinNew * let result += ["New", win_getid()]
+ ]])
+ api.nvim_win_set_config(0, { win = parent, split = 'left' })
+ -- Shouldn't see any of those events, as we remain in the same window.
+ eq({}, eval('result'))
+ end)
+
+ it('checks if splitting disallowed', function()
+ command('split | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "right"})')
+ matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
+
+ command('autocmd BufHidden * ++once call nvim_win_set_config(0, #{split: "left"})')
+ matches(
+ 'E1159: Cannot split a window when closing the buffer$',
+ pcall_err(command, 'new | quit')
+ )
+
+ -- OK when using window to different buffer.
+ local w = api.nvim_get_current_win()
+ command('autocmd BufHidden * ++once call nvim_win_set_config(' .. w .. ', #{split: "left"})')
+ command('new | quit')
+ end)
+
+ --- Returns a function to get information about the window layout, sizes and positions of a
+ --- tabpage.
+ local function define_tp_info_function()
+ exec_lua([[
+ function tp_info(tp)
+ return {
+ layout = vim.fn.winlayout(vim.api.nvim_tabpage_get_number(tp)),
+ pos_sizes = vim.tbl_map(
+ function(w)
+ local pos = vim.fn.win_screenpos(w)
+ return {
+ row = pos[1],
+ col = pos[2],
+ width = vim.fn.winwidth(w),
+ height = vim.fn.winheight(w)
+ }
+ end,
+ vim.api.nvim_tabpage_list_wins(tp)
+ )
+ }
+ end
+ ]])
+
+ return function(tp)
+ return exec_lua('return tp_info(...)', tp)
+ end
+ end
+
+ it('attempt to move window with no room', function()
+ -- Fill the 2nd tabpage full of windows until we run out of room.
+ -- Use &laststatus=0 to ensure restoring missing statuslines doesn't affect things.
+ command('set laststatus=0 | tabnew')
+ matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
+ command('vsplit | wincmd | | wincmd p')
+ local t2 = api.nvim_get_current_tabpage()
+ local t2_cur_win = api.nvim_get_current_win()
+ local t2_top_split = fn.win_getid(1)
+ local t2_bot_split = fn.win_getid(fn.winnr('$'))
+ local t2_float = api.nvim_open_win(
+ 0,
+ false,
+ { relative = 'editor', row = 0, col = 0, width = 10, height = 10 }
+ )
+ local t2_float_config = api.nvim_win_get_config(t2_float)
+ local tp_info = define_tp_info_function()
+ local t2_info = tp_info(t2)
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t2_float, { win = t2_top_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t2_float, { win = t2_top_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t2_float, { win = t2_bot_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t2_float, { win = t2_bot_split, split = 'below' })
+ )
+ eq(t2_cur_win, api.nvim_get_current_win())
+ eq(t2_info, tp_info(t2))
+ eq(t2_float_config, api.nvim_win_get_config(t2_float))
+
+ -- Try to move windows from the 1st tabpage to the 2nd.
+ command('tabfirst | split | wincmd _')
+ local t1 = api.nvim_get_current_tabpage()
+ local t1_cur_win = api.nvim_get_current_win()
+ local t1_float = api.nvim_open_win(
+ 0,
+ false,
+ { relative = 'editor', row = 5, col = 3, width = 7, height = 6 }
+ )
+ local t1_float_config = api.nvim_win_get_config(t1_float)
+ local t1_info = tp_info(t1)
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t1_float, { win = t2_top_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t1_float, { win = t2_top_split, split = 'below' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t1_float, { win = t2_bot_split, split = 'above' })
+ )
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t1_float, { win = t2_bot_split, split = 'below' })
+ )
+ eq(t1_cur_win, api.nvim_get_current_win())
+ eq(t1_info, tp_info(t1))
+ eq(t1_float_config, api.nvim_win_get_config(t1_float))
+ end)
+
+ it('attempt to move window from other tabpage with no room', function()
+ -- Fill up the 1st tabpage with horizontal splits, then create a 2nd with only a few. Go back
+ -- to the 1st and try to move windows from the 2nd (while it's non-current) to it. Check that
+ -- window positions and sizes in the 2nd are unchanged.
+ command('set laststatus=0')
+ matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
+
+ command('tab split')
+ local t2 = api.nvim_get_current_tabpage()
+ local t2_top = api.nvim_get_current_win()
+ command('belowright split')
+ local t2_mid_left = api.nvim_get_current_win()
+ command('belowright vsplit')
+ local t2_mid_right = api.nvim_get_current_win()
+ command('split | wincmd J')
+ local t2_bot = api.nvim_get_current_win()
+ local tp_info = define_tp_info_function()
+ local t2_info = tp_info(t2)
+ eq({
+ 'col',
+ {
+ { 'leaf', t2_top },
+ {
+ 'row',
+ {
+ { 'leaf', t2_mid_left },
+ { 'leaf', t2_mid_right },
+ },
+ },
+ { 'leaf', t2_bot },
+ },
+ }, t2_info.layout)
+
+ local function try_move_t2_wins_to_t1()
+ for _, w in ipairs({ t2_bot, t2_mid_left, t2_mid_right, t2_top }) do
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, w, { win = 0, split = 'below' })
+ )
+ eq(t2_info, tp_info(t2))
+ end
+ end
+ command('tabfirst')
+ try_move_t2_wins_to_t1()
+ -- Go to the 2nd tabpage to ensure nothing changes after win_comp_pos, last_status, .etc.
+ -- from enter_tabpage.
+ command('tabnext')
+ eq(t2_info, tp_info(t2))
+
+ -- Check things are fine with the global statusline too, for good measure.
+ -- Set it while the 2nd tabpage is current, so last_status runs for it.
+ command('set laststatus=3')
+ t2_info = tp_info(t2)
+ command('tabfirst')
+ try_move_t2_wins_to_t1()
+ end)
+
+ it('handles cmdwin and textlock restrictions', function()
+ command('tabnew')
+ local t2 = api.nvim_get_current_tabpage()
+ local t2_win = api.nvim_get_current_win()
+ command('tabfirst')
+ local t1_move_win = api.nvim_get_current_win()
+ command('split')
+
+ -- Can't move the cmdwin, or its old curwin to a different tabpage.
+ local old_curwin = api.nvim_get_current_win()
+ feed('q:')
+ eq(
+ 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(api.nvim_win_set_config, 0, { split = 'left', win = t2_win })
+ )
+ eq(
+ 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(api.nvim_win_set_config, old_curwin, { split = 'left', win = t2_win })
+ )
+ -- But we can move other windows.
+ api.nvim_win_set_config(t1_move_win, { split = 'left', win = t2_win })
+ eq(t2, api.nvim_win_get_tabpage(t1_move_win))
+ command('quit!')
+
+ -- Can't configure windows such that the cmdwin would become the only non-float.
+ command('only!')
+ feed('q:')
+ eq(
+ 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(
+ api.nvim_win_set_config,
+ old_curwin,
+ { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
+ )
+ )
+ -- old_curwin is now no longer the only other non-float, so we can make it floating now.
+ local t1_new_win = api.nvim_open_win(
+ api.nvim_create_buf(true, true),
+ false,
+ { split = 'left', win = old_curwin }
+ )
+ api.nvim_win_set_config(
+ old_curwin,
+ { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
+ )
+ eq('editor', api.nvim_win_get_config(old_curwin).relative)
+ -- ...which means we shouldn't be able to also make the new window floating too!
+ eq(
+ 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(
+ api.nvim_win_set_config,
+ t1_new_win,
+ { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
+ )
+ )
+ -- Nothing ought to stop us from making the cmdwin itself floating, though...
+ api.nvim_win_set_config(0, { relative = 'editor', row = 0, col = 0, width = 5, height = 5 })
+ eq('editor', api.nvim_win_get_config(0).relative)
+ -- We can't make our new window from before floating too, as it's now the only non-float.
+ eq(
+ 'Cannot change last window into float',
+ pcall_err(
+ api.nvim_win_set_config,
+ t1_new_win,
+ { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
+ )
+ )
+ command('quit!')
+
+ -- Can't switch away from window before moving it to a different tabpage during textlock.
+ exec(([[
+ new
+ call setline(1, 'foo')
+ setlocal debug=throw indentexpr=nvim_win_set_config(0,#{split:'left',win:%d})
+ ]]):format(t2_win))
+ local cur_win = api.nvim_get_current_win()
+ matches(
+ 'E565: Not allowed to change text or change window$',
+ pcall_err(command, 'normal! ==')
+ )
+ eq(cur_win, api.nvim_get_current_win())
+ end)
+
+ it('updates statusline when moving bottom split', function()
+ local screen = Screen.new(10, 10)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ [1] = { bold = true, reverse = true }, -- StatusLine
+ })
+ screen:attach()
+ exec([[
+ set laststatus=0
+ belowright split
+ call nvim_win_set_config(0, #{split: 'above', win: win_getid(winnr('#'))})
+ ]])
+ screen:expect([[
+ ^ |
+ {0:~ }|*3
+ {1:[No Name] }|
+ |
+ {0:~ }|*3
+ |
+ ]])
+ end)
+
+ it("updates tp_curwin of moved window's original tabpage", function()
+ local t1 = api.nvim_get_current_tabpage()
+ command('tab split | split')
+ local t2 = api.nvim_get_current_tabpage()
+ local t2_alt_win = api.nvim_get_current_win()
+ command('vsplit')
+ local t2_cur_win = api.nvim_get_current_win()
+ command('tabprevious')
+ eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
+
+ -- tp_curwin is unchanged when moved within the same tabpage.
+ api.nvim_win_set_config(t2_cur_win, { split = 'left', win = t2_alt_win })
+ eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
+
+ -- Also unchanged if the move failed.
+ command('let &winwidth = &columns | let &winminwidth = &columns')
+ matches(
+ 'E36: Not enough room$',
+ pcall_err(api.nvim_win_set_config, t2_cur_win, { split = 'left', win = 0 })
+ )
+ eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
+ command('set winminwidth& winwidth&')
+
+ -- But is changed if successfully moved to a different tabpage.
+ api.nvim_win_set_config(t2_cur_win, { split = 'left', win = 0 })
+ eq(t2_alt_win, api.nvim_tabpage_get_win(t2))
+ eq(t1, api.nvim_win_get_tabpage(t2_cur_win))
+
+ -- Now do it for a float, which has different altwin logic.
+ command('tabnext')
+ t2_cur_win =
+ api.nvim_open_win(0, true, { relative = 'editor', row = 5, col = 5, width = 5, height = 5 })
+ eq(t2_alt_win, fn.win_getid(fn.winnr('#')))
+ command('tabprevious')
+ eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
+
+ api.nvim_win_set_config(t2_cur_win, { split = 'left', win = 0 })
+ eq(t2_alt_win, api.nvim_tabpage_get_win(t2))
+ eq(t1, api.nvim_win_get_tabpage(t2_cur_win))
+ end)
end)
describe('get_config', function()
diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua
index b9bab206fc..4f4a036ba8 100644
--- a/test/functional/autocmd/focus_spec.lua
+++ b/test/functional/autocmd/focus_spec.lua
@@ -86,7 +86,7 @@ describe('autoread TUI FocusGained/FocusLost', function()
line 3 |
line 4 |
{5:xtest-foo }|
- "xtest-foo" 4L, 28B |
+ :edit xtest-foo |
{3:-- TERMINAL --} |
]],
}
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index 29cd62f586..17eb7695f2 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -72,19 +72,19 @@ describe('TextYankPost', function()
command('set debug=msg')
-- the regcontents should not be changed without copy.
local status, err = pcall(command, 'call extend(g:event.regcontents, ["more text"])')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E742:'))
-- can't mutate keys inside the autocommand
command('autocmd! TextYankPost * let v:event.regcontents = 0')
status, err = pcall(command, 'normal yy')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E46:'))
-- can't add keys inside the autocommand
command('autocmd! TextYankPost * let v:event.mykey = 0')
status, err = pcall(command, 'normal yy')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E742:'))
end)
diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua
index 1d2261ee05..9d8d64c82d 100644
--- a/test/functional/core/main_spec.lua
+++ b/test/functional/core/main_spec.lua
@@ -73,6 +73,18 @@ describe('command-line option', function()
eq(#'100500\n', attrs.size)
end)
+ it('does not crash when run completion in ex mode', function()
+ fn.system({
+ nvim_prog_abs(),
+ '--clean',
+ '-e',
+ '-s',
+ '--cmd',
+ 'exe "norm! i\\<C-X>\\<C-V>"',
+ })
+ eq(0, eval('v:shell_error'))
+ end)
+
it('does not crash after reading from stdin in non-headless mode', function()
skip(is_os('win'))
local screen = Screen.new(40, 8)
diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua
index cb7d7340e2..4499b2172d 100644
--- a/test/functional/ex_cmds/cmd_map_spec.lua
+++ b/test/functional/ex_cmds/cmd_map_spec.lua
@@ -505,7 +505,7 @@ describe('mappings with <Cmd>', function()
feed('"bd<F7>')
expect([[
soest text]])
- eq(fn.getreg('b', 1, 1), { 'me short lines', 'of t' })
+ eq({ 'me short lines', 'of t' }, fn.getreg('b', 1, 1))
-- startinsert aborts operator
feed('d<F8>')
@@ -561,7 +561,7 @@ describe('mappings with <Cmd>', function()
of stuff test text]])
feed('<F5>')
- eq(fn.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' })
+ eq({ 'deed some short little lines', 'of stuff t' }, fn.getreg('a', 1, 1))
-- still in insert
screen:expect([[
diff --git a/test/functional/legacy/conceal_spec.lua b/test/functional/legacy/conceal_spec.lua
index 9a23d16c5b..e2cc3b23df 100644
--- a/test/functional/legacy/conceal_spec.lua
+++ b/test/functional/legacy/conceal_spec.lua
@@ -4,6 +4,7 @@ local clear = helpers.clear
local command = helpers.command
local exec = helpers.exec
local feed = helpers.feed
+local api = helpers.api
local expect_pos = function(row, col)
return helpers.eq({ row, col }, helpers.eval('[screenrow(), screencol()]'))
@@ -433,6 +434,68 @@ describe('Conceal', function()
]])
end)
+ -- oldtest: Test_conceal_wrapped_cursorline_wincolor()
+ it('CursorLine highlight on wrapped lines', function()
+ local screen = Screen.new(40, 4)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ [1] = { background = Screen.colors.Green }, -- CursorLine (low-priority)
+ [2] = { foreground = Screen.colors.Red }, -- CursorLine (high-priority)
+ })
+ screen:attach()
+ exec([[
+ call setline(1, 'one one one |hidden| one one one one one one one one')
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2 concealcursor=n cursorline
+ normal! g$
+ hi! CursorLine guibg=Green
+ ]])
+ screen:expect([[
+ {1:one one one one one one one on^e }|
+ {1: one one one }|
+ {0:~ }|
+ |
+ ]])
+ command('hi! CursorLine guibg=NONE guifg=Red')
+ screen:expect([[
+ {2:one one one one one one one on^e }|
+ {2: one one one }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_conceal_wrapped_cursorline_wincolor_rightleft()
+ it('CursorLine highlight on wrapped lines with rightleft', function()
+ local screen = Screen.new(40, 4)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ [1] = { background = Screen.colors.Green }, -- CursorLine (low-priority)
+ [2] = { foreground = Screen.colors.Red }, -- CursorLine (high-priority)
+ })
+ screen:attach()
+ exec([[
+ call setline(1, 'one one one |hidden| one one one one one one one one')
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2 concealcursor=n cursorline rightleft
+ normal! g$
+ hi! CursorLine guibg=Green
+ ]])
+ screen:expect([[
+ {1: ^eno eno eno eno eno eno eno eno}|
+ {1: eno eno eno }|
+ {0: ~}|
+ |
+ ]])
+ command('hi! CursorLine guibg=NONE guifg=Red')
+ screen:expect([[
+ {2: ^eno eno eno eno eno eno eno eno}|
+ {2: eno eno eno }|
+ {0: ~}|
+ |
+ ]])
+ end)
+
-- oldtest: Test_conceal_resize_term()
it('resize editor', function()
local screen = Screen.new(75, 6)
@@ -570,4 +633,210 @@ describe('Conceal', function()
feed('$')
expect_pos(9, 26)
end)
+
+ local function test_conceal_virtualedit_after_eol(wrap)
+ local screen = Screen.new(60, 3)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ })
+ screen:attach()
+ api.nvim_set_option_value('wrap', wrap, {})
+ exec([[
+ call setline(1, 'abcdefgh|hidden|ijklmnpop')
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2 concealcursor=n virtualedit=all
+ normal! $
+ ]])
+ screen:expect([[
+ abcdefghijklmnpo^p |
+ {0:~ }|
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ abcdefghijklmnpop^ |
+ {0:~ }|
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ abcdefghijklmnpop ^ |
+ {0:~ }|
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ abcdefghijklmnpop ^ |
+ {0:~ }|
+ |
+ ]])
+ feed('rr')
+ screen:expect([[
+ abcdefghijklmnpop ^r |
+ {0:~ }|
+ |
+ ]])
+ end
+
+ -- oldtest: Test_conceal_virtualedit_after_eol()
+ describe('cursor drawn at correct column with virtualedit', function()
+ it('with wrapping', function()
+ test_conceal_virtualedit_after_eol(true)
+ end)
+ it('without wrapping', function()
+ test_conceal_virtualedit_after_eol(false)
+ end)
+ end)
+
+ local function test_conceal_virtualedit_after_eol_rightleft(wrap)
+ local screen = Screen.new(60, 3)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ })
+ screen:attach()
+ api.nvim_set_option_value('wrap', wrap, {})
+ exec([[
+ call setline(1, 'abcdefgh|hidden|ijklmnpop')
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2 concealcursor=n virtualedit=all rightleft
+ normal! $
+ ]])
+ screen:expect([[
+ ^popnmlkjihgfedcba|
+ {0: ~}|
+ |
+ ]])
+ feed('h')
+ screen:expect([[
+ ^ popnmlkjihgfedcba|
+ {0: ~}|
+ |
+ ]])
+ feed('h')
+ screen:expect([[
+ ^ popnmlkjihgfedcba|
+ {0: ~}|
+ |
+ ]])
+ feed('h')
+ screen:expect([[
+ ^ popnmlkjihgfedcba|
+ {0: ~}|
+ |
+ ]])
+ feed('rr')
+ screen:expect([[
+ ^r popnmlkjihgfedcba|
+ {0: ~}|
+ |
+ ]])
+ end
+
+ -- oldtest: Test_conceal_virtualedit_after_eol_rightleft()
+ describe('cursor drawn correctly with virtualedit and rightleft', function()
+ it('with wrapping', function()
+ test_conceal_virtualedit_after_eol_rightleft(true)
+ end)
+ it('without wrapping', function()
+ test_conceal_virtualedit_after_eol_rightleft(false)
+ end)
+ end)
+
+ local function test_conceal_double_width(wrap)
+ local screen = Screen.new(60, 4)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue },
+ [1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey },
+ [2] = { background = Screen.colors.LightRed },
+ })
+ screen:attach()
+ api.nvim_set_option_value('wrap', wrap, {})
+ exec([[
+ call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
+ syntax match test /口=口/ conceal cchar=β
+ set conceallevel=2 concealcursor=n colorcolumn=30
+ normal! $
+ ]])
+ screen:expect([[
+ aaaaa{1:β}bbbbb{1:β}cccc^c {2: } |
+ foobar {2: } |
+ {0:~ }|
+ |
+ ]])
+ feed('gM')
+ screen:expect([[
+ aaaaa{1:β}bb^bbb{1:β}ccccc {2: } |
+ foobar {2: } |
+ {0:~ }|
+ |
+ ]])
+ command('set conceallevel=3')
+ screen:expect([[
+ aaaaabb^bbbccccc {2: } |
+ foobar {2: } |
+ {0:~ }|
+ |
+ ]])
+ feed('$')
+ screen:expect([[
+ aaaaabbbbbcccc^c {2: } |
+ foobar {2: } |
+ {0:~ }|
+ |
+ ]])
+ end
+
+ -- oldtest: Test_conceal_double_width()
+ describe('cursor drawn correctly when double-width chars are concealed', function()
+ it('with wrapping', function()
+ test_conceal_double_width(true)
+ end)
+ it('without wrapping', function()
+ test_conceal_double_width(false)
+ end)
+ end)
+
+ -- oldtest: Test_conceal_double_width_wrap()
+ it('line wraps correctly when double-width chars are concealed', function()
+ local screen = Screen.new(20, 4)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue },
+ [1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey },
+ [2] = { background = Screen.colors.LightRed },
+ })
+ screen:attach()
+ exec([[
+ call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
+ syntax match test /口=口/ conceal cchar=β
+ set conceallevel=2 concealcursor=n
+ normal! $
+ ]])
+ screen:expect([[
+ aaaaaaaaaa{1:β}bbbbb |
+ bbbbb{1:β}ccccccccc^c |
+ {0:~ }|
+ |
+ ]])
+ feed('gM')
+ screen:expect([[
+ aaaaaaaaaa{1:β}bbbbb |
+ ^bbbbb{1:β}cccccccccc |
+ {0:~ }|
+ |
+ ]])
+ command('set conceallevel=3')
+ screen:expect([[
+ aaaaaaaaaabbbbb |
+ ^bbbbbcccccccccc |
+ {0:~ }|
+ |
+ ]])
+ feed('$')
+ screen:expect([[
+ aaaaaaaaaabbbbb |
+ bbbbbccccccccc^c |
+ {0:~ }|
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/legacy/matchparen_spec.lua b/test/functional/legacy/matchparen_spec.lua
index b03107deb0..137448acbd 100644
--- a/test/functional/legacy/matchparen_spec.lua
+++ b/test/functional/legacy/matchparen_spec.lua
@@ -61,13 +61,15 @@ describe('matchparen', function()
set hidden
call setline(1, ['()'])
normal 0
+
+ func OtherBuffer()
+ enew
+ exe "normal iaa\<Esc>0"
+ endfunc
]])
screen:expect(screen1)
- exec([[
- enew
- exe "normal iaa\<Esc>0"
- ]])
+ exec('call OtherBuffer()')
screen:expect(screen2)
feed('<C-^>')
@@ -77,6 +79,39 @@ describe('matchparen', function()
screen:expect(screen2)
end)
+ -- oldtest: Test_matchparen_win_execute()
+ it('matchparen highlight when switching buffer in win_execute()', function()
+ local screen = Screen.new(20, 5)
+ screen:set_default_attr_ids({
+ [1] = { background = Screen.colors.Cyan },
+ [2] = { reverse = true, bold = true },
+ [3] = { reverse = true },
+ })
+ screen:attach()
+
+ exec([[
+ source $VIMRUNTIME/plugin/matchparen.vim
+ let s:win = win_getid()
+ call setline(1, '{}')
+ split
+
+ func SwitchBuf()
+ call win_execute(s:win, 'enew | buffer #')
+ endfunc
+ ]])
+ screen:expect([[
+ {1:^{}} |
+ {2:[No Name] [+] }|
+ {} |
+ {3:[No Name] [+] }|
+ |
+ ]])
+
+ -- Switching buffer away and back shouldn't change matchparen highlight.
+ exec('call SwitchBuf()')
+ screen:expect_unchanged()
+ end)
+
-- oldtest: Test_matchparen_pum_clear()
it('is cleared when completion popup is shown', function()
local screen = Screen.new(30, 9)
diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua
index a05e9fdf57..3a6eb2c31c 100644
--- a/test/functional/legacy/memory_usage_spec.lua
+++ b/test/functional/legacy/memory_usage_spec.lua
@@ -59,7 +59,7 @@ local monitor_memory_usage = {
end
table.remove(self.hist, 1)
self.last = self.hist[#self.hist]
- eq(#result, 1)
+ eq(1, #result)
end)
end,
dump = function(self)
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 714e1b951f..2479a433e6 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -312,15 +312,15 @@ describe('lua buffer event callbacks: on_lines', function()
feed('G0')
feed('p')
-- Is the last arg old_byte_size correct? Doesn't matter for this PR
- eq(api.nvim_get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 })
+ eq({ 'lines', 1, 4, 2, 3, 5, 4 }, api.nvim_get_var('linesev'))
feed('2G0')
feed('p')
- eq(api.nvim_get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 })
+ eq({ 'lines', 1, 5, 1, 4, 4, 8 }, api.nvim_get_var('linesev'))
feed('1G0')
feed('P')
- eq(api.nvim_get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 })
+ eq({ 'lines', 1, 6, 0, 3, 3, 9 }, api.nvim_get_var('linesev'))
end)
it(
@@ -541,7 +541,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
feed 'cc'
check_events {
- { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 },
+ { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 15, 15, 0, 0, 0 },
}
feed '<ESC>'
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 5802925339..716c1e0f30 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -205,7 +205,7 @@ describe('vim.diagnostic', function()
diag[1].col = 10000
return vim.diagnostic.get()[1].col == 10000
]]
- eq(result, false)
+ eq(false, result)
end)
it('resolves buffer number 0 to the current buffer', function()
diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua
index c9e8e9d4ca..4229e4af9b 100644
--- a/test/functional/lua/ffi_spec.lua
+++ b/test/functional/lua/ffi_spec.lua
@@ -13,15 +13,19 @@ describe('ffi.cdef', function()
eq(
12,
- exec_lua [[
+ exec_lua [=[
local ffi = require('ffi')
- ffi.cdef('int curwin_col_off(void);')
+ ffi.cdef [[
+ typedef struct window_S win_T;
+ int win_col_off(win_T *wp);
+ extern win_T *curwin;
+ ]]
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
- return ffi.C.curwin_col_off()
- ]]
+ return ffi.C.win_col_off(ffi.C.curwin)
+ ]=]
)
eq(
@@ -30,7 +34,6 @@ describe('ffi.cdef', function()
local ffi = require('ffi')
ffi.cdef[[
- typedef struct window_S win_T;
typedef struct {} stl_hlrec_t;
typedef struct {} StlClickRecord;
typedef struct {} statuscol_T;
diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua
index c1981e19d4..9bbee73e27 100644
--- a/test/functional/lua/thread_spec.lua
+++ b/test/functional/lua/thread_spec.lua
@@ -166,7 +166,7 @@ describe('thread', function()
]]
local msg = next_msg()
- eq(msg[1], 'notification')
+ eq('notification', msg[1])
assert(tonumber(msg[2]) >= 72961)
end)
@@ -327,7 +327,7 @@ describe('threadpool', function()
]]
local msg = next_msg()
- eq(msg[1], 'notification')
+ eq('notification', msg[1])
assert(tonumber(msg[2]) >= 72961)
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index a262d239e8..7ab009659b 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -2016,7 +2016,7 @@ describe('lua stdlib', function()
vim.opt.scrolloff = 10
return vim.o.scrolloff
]]
- eq(scrolloff, 10)
+ eq(10, scrolloff)
end)
pending('should handle STUPID window things', function()
@@ -2037,7 +2037,7 @@ describe('lua stdlib', function()
vim.opt.wildignore = { 'hello', 'world' }
return vim.o.wildignore
]]
- eq(wildignore, 'hello,world')
+ eq('hello,world', wildignore)
end)
it('should allow setting tables with shortnames', function()
@@ -2045,7 +2045,7 @@ describe('lua stdlib', function()
vim.opt.wig = { 'hello', 'world' }
return vim.o.wildignore
]]
- eq(wildignore, 'hello,world')
+ eq('hello,world', wildignore)
end)
it('should error when you attempt to set string values to numeric options', function()
@@ -2451,13 +2451,13 @@ describe('lua stdlib', function()
vim.opt.wildignore = 'foo'
return vim.o.wildignore
]]
- eq(wildignore, 'foo')
+ eq('foo', wildignore)
wildignore = exec_lua [[
vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
return vim.o.wildignore
]]
- eq(wildignore, 'foo,bar,baz')
+ eq('foo,bar,baz', wildignore)
end)
it('should handle adding duplicates', function()
@@ -2465,19 +2465,19 @@ describe('lua stdlib', function()
vim.opt.wildignore = 'foo'
return vim.o.wildignore
]]
- eq(wildignore, 'foo')
+ eq('foo', wildignore)
wildignore = exec_lua [[
vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
return vim.o.wildignore
]]
- eq(wildignore, 'foo,bar,baz')
+ eq('foo,bar,baz', wildignore)
wildignore = exec_lua [[
vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
return vim.o.wildignore
]]
- eq(wildignore, 'foo,bar,baz')
+ eq('foo,bar,baz', wildignore)
end)
it('should allow adding multiple times', function()
@@ -2486,7 +2486,7 @@ describe('lua stdlib', function()
vim.opt.wildignore = vim.opt.wildignore + 'bar' + 'baz'
return vim.o.wildignore
]]
- eq(wildignore, 'foo,bar,baz')
+ eq('foo,bar,baz', wildignore)
end)
it('should remove values when you use minus', function()
@@ -2494,19 +2494,19 @@ describe('lua stdlib', function()
vim.opt.wildignore = 'foo'
return vim.o.wildignore
]]
- eq(wildignore, 'foo')
+ eq('foo', wildignore)
wildignore = exec_lua [[
vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
return vim.o.wildignore
]]
- eq(wildignore, 'foo,bar,baz')
+ eq('foo,bar,baz', wildignore)
wildignore = exec_lua [[
vim.opt.wildignore = vim.opt.wildignore - 'bar'
return vim.o.wildignore
]]
- eq(wildignore, 'foo,baz')
+ eq('foo,baz', wildignore)
end)
it('should prepend values when using ^', function()
@@ -2521,7 +2521,7 @@ describe('lua stdlib', function()
vim.opt.wildignore = vim.opt.wildignore ^ 'super_first'
return vim.o.wildignore
]]
- eq(wildignore, 'super_first,first,foo')
+ eq('super_first,first,foo', wildignore)
end)
it('should not remove duplicates from wildmode: #14708', function()
@@ -2530,7 +2530,7 @@ describe('lua stdlib', function()
return vim.o.wildmode
]]
- eq(wildmode, 'full,list,full')
+ eq('full,list,full', wildmode)
end)
describe('option types', function()
@@ -2738,7 +2738,7 @@ describe('lua stdlib', function()
return vim.go.whichwrap
]]
- eq(ww, 'b,s')
+ eq('b,s', ww)
eq(
'b,s,<,>,[,]',
exec_lua [[
@@ -3664,6 +3664,20 @@ describe('lua stdlib', function()
]]
)
end)
+
+ it('layout in current tabpage does not affect windows in others', function()
+ command('tab split')
+ local t2_move_win = api.nvim_get_current_win()
+ command('vsplit')
+ local t2_other_win = api.nvim_get_current_win()
+ command('tabprevious')
+ matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
+ command('vsplit')
+
+ -- Without vim-patch:8.2.3862, this gives E36, despite just the 1st tabpage being full.
+ exec_lua('vim.api.nvim_win_call(..., function() vim.cmd.wincmd "J" end)', t2_move_win)
+ eq({ 'col', { { 'leaf', t2_other_win }, { 'leaf', t2_move_win } } }, fn.winlayout(2))
+ end)
end)
describe('vim.iconv', function()
diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua
index 044d707499..115fee8091 100644
--- a/test/functional/lua/watch_spec.lua
+++ b/test/functional/lua/watch_spec.lua
@@ -2,180 +2,126 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local exec_lua = helpers.exec_lua
local clear = helpers.clear
+local is_ci = helpers.is_ci
local is_os = helpers.is_os
local skip = helpers.skip
+-- Create a file via a rename to avoid multiple
+-- events which can happen with some backends on some platforms
+local function touch(path)
+ local tmp = helpers.tmpname()
+ io.open(tmp, 'w'):close()
+ assert(vim.uv.fs_rename(tmp, path))
+end
+
describe('vim._watch', function()
before_each(function()
clear()
end)
- describe('watch', function()
- it('detects file changes', function()
- skip(is_os('bsd'), 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38')
- local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
-
- local result = exec_lua(
- [[
- local root_dir = ...
-
- local events = {}
-
- local expected_events = 0
- local function wait_for_events()
- assert(vim.wait(100, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events))
- end
-
- local stop = vim._watch.watch(root_dir, {}, function(path, change_type)
- table.insert(events, { path = path, change_type = change_type })
- end)
-
- -- Only BSD seems to need some extra time for the watch to be ready to respond to events
- if vim.fn.has('bsd') then
- vim.wait(50)
- end
+ local function run(watchfunc)
+ it('detects file changes (watchfunc=' .. watchfunc .. '())', function()
+ if watchfunc == 'fswatch' then
+ skip(is_os('mac'), 'flaky test on mac')
+ skip(
+ not is_ci() and helpers.fn.executable('fswatch') == 0,
+ 'fswatch not installed and not on CI'
+ )
+ skip(is_os('win'), 'not supported on windows')
+ end
- local watched_path = root_dir .. '/file'
- local watched, err = io.open(watched_path, 'w')
- assert(not err, err)
+ if watchfunc == 'watch' then
+ skip(is_os('bsd'), 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38')
+ else
+ skip(
+ is_os('bsd'),
+ 'kqueue only reports events on watched folder itself, not contained files #26110'
+ )
+ end
- expected_events = expected_events + 1
- wait_for_events()
+ local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
- watched:close()
- os.remove(watched_path)
+ local expected_events = 0
+ local function wait_for_event()
expected_events = expected_events + 1
- wait_for_events()
-
- stop()
- -- No events should come through anymore
-
- local watched_path = root_dir .. '/file'
- local watched, err = io.open(watched_path, 'w')
- assert(not err, err)
-
- vim.wait(50)
-
- watched:close()
- os.remove(watched_path)
-
- vim.wait(50)
-
- return events
- ]],
- root_dir
- )
-
- local expected = {
- {
- change_type = exec_lua([[return vim._watch.FileChangeType.Created]]),
- path = root_dir .. '/file',
- },
- {
- change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]),
- path = root_dir .. '/file',
- },
- }
-
- -- kqueue only reports events on the watched path itself, so creating a file within a
- -- watched directory results in a "rename" libuv event on the directory.
- if is_os('bsd') then
- expected = {
- {
- change_type = exec_lua([[return vim._watch.FileChangeType.Created]]),
- path = root_dir,
- },
- {
- change_type = exec_lua([[return vim._watch.FileChangeType.Created]]),
- path = root_dir,
- },
- }
+ exec_lua(
+ [[
+ local expected_events = ...
+ assert(
+ vim.wait(3000, function()
+ return #_G.events == expected_events
+ end),
+ string.format(
+ 'Timed out waiting for expected event no. %d. Current events seen so far: %s',
+ expected_events,
+ vim.inspect(events)
+ )
+ )
+ ]],
+ expected_events
+ )
end
- eq(expected, result)
- end)
- end)
-
- describe('poll', function()
- it('detects file changes', function()
- skip(
- is_os('bsd'),
- 'kqueue only reports events on watched folder itself, not contained files #26110'
- )
- local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
+ local unwatched_path = root_dir .. '/file.unwatched'
+ local watched_path = root_dir .. '/file'
- local result = exec_lua(
+ exec_lua(
[[
- local root_dir = ...
- local lpeg = vim.lpeg
-
- local events = {}
-
- local debounce = 100
- local wait_ms = debounce + 200
+ local root_dir, watchfunc = ...
- local expected_events = 0
- local function wait_for_events()
- assert(vim.wait(wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events))
- end
+ _G.events = {}
- local incl = lpeg.P(root_dir) * lpeg.P("/file")^-1
- local excl = lpeg.P(root_dir..'/file.unwatched')
- local stop = vim._watch.poll(root_dir, {
- debounce = debounce,
- include_pattern = incl,
- exclude_pattern = excl,
+ _G.stop_watch = vim._watch[watchfunc](root_dir, {
+ debounce = 100,
+ include_pattern = vim.lpeg.P(root_dir) * vim.lpeg.P("/file") ^ -1,
+ exclude_pattern = vim.lpeg.P(root_dir .. '/file.unwatched'),
}, function(path, change_type)
- table.insert(events, { path = path, change_type = change_type })
- end)
+ table.insert(_G.events, { path = path, change_type = change_type })
+ end)
+ ]],
+ root_dir,
+ watchfunc
+ )
- local watched_path = root_dir .. '/file'
- local watched, err = io.open(watched_path, 'w')
- assert(not err, err)
- local unwatched_path = root_dir .. '/file.unwatched'
- local unwatched, err = io.open(unwatched_path, 'w')
- assert(not err, err)
+ if watchfunc ~= 'watch' then
+ vim.uv.sleep(200)
+ end
- expected_events = expected_events + 1
- wait_for_events()
+ touch(watched_path)
+ touch(unwatched_path)
- watched:close()
- os.remove(watched_path)
- unwatched:close()
- os.remove(unwatched_path)
+ wait_for_event()
- expected_events = expected_events + 1
- wait_for_events()
+ os.remove(watched_path)
+ os.remove(unwatched_path)
- stop()
- -- No events should come through anymore
+ wait_for_event()
- local watched_path = root_dir .. '/file'
- local watched, err = io.open(watched_path, 'w')
- assert(not err, err)
+ exec_lua [[_G.stop_watch()]]
- watched:close()
- os.remove(watched_path)
+ -- No events should come through anymore
- return events
- ]],
- root_dir
- )
+ vim.uv.sleep(100)
+ touch(watched_path)
+ vim.uv.sleep(100)
+ os.remove(watched_path)
+ vim.uv.sleep(100)
- local created = exec_lua([[return vim._watch.FileChangeType.Created]])
- local deleted = exec_lua([[return vim._watch.FileChangeType.Deleted]])
- local expected = {
+ eq({
{
- change_type = created,
+ change_type = exec_lua([[return vim._watch.FileChangeType.Created]]),
path = root_dir .. '/file',
},
{
- change_type = deleted,
+ change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]),
path = root_dir .. '/file',
},
- }
- eq(expected, result)
+ }, exec_lua [[return _G.events]])
end)
- end)
+ end
+
+ run('watch')
+ run('watchdirs')
+ run('fswatch')
end)
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua
index d27fa375ee..a7cdc5f9fa 100644
--- a/test/functional/options/defaults_spec.lua
+++ b/test/functional/options/defaults_spec.lua
@@ -1243,11 +1243,11 @@ describe('autocommands', function()
command('au BufEnter * let g:n = g:n + 1')
command('terminal')
- eq(eval('get(g:, "n", 0)'), 1)
+ eq(1, eval('get(g:, "n", 0)'))
helpers.retry(nil, 1000, function()
- neq(api.nvim_get_option_value('buftype', { buf = 0 }), 'terminal')
- eq(eval('get(g:, "n", 0)'), 2)
+ 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/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua
index 0614bcf814..3b411b109c 100644
--- a/test/functional/options/num_options_spec.lua
+++ b/test/functional/options/num_options_spec.lua
@@ -12,7 +12,7 @@ local function should_fail(opt, value, errmsg)
eq(errmsg, eval('v:errmsg'):match('E%d*'))
feed_command('let v:errmsg = ""')
local status, err = pcall(api.nvim_set_option_value, opt, value, {})
- eq(status, false)
+ eq(false, status)
eq(errmsg, err:match('E%d*'))
eq('', eval('v:errmsg'))
end
diff --git a/test/functional/options/winfixbuf_spec.lua b/test/functional/options/winfixbuf_spec.lua
new file mode 100644
index 0000000000..20407b9bb7
--- /dev/null
+++ b/test/functional/options/winfixbuf_spec.lua
@@ -0,0 +1,54 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local exec_lua = helpers.exec_lua
+
+describe("Nvim API calls with 'winfixbuf'", function()
+ before_each(function()
+ clear()
+ end)
+
+ it("Calling vim.api.nvim_win_set_buf with 'winfixbuf'", function()
+ local results = exec_lua([[
+ local function _setup_two_buffers()
+ local buffer = vim.api.nvim_create_buf(true, true)
+
+ vim.api.nvim_create_buf(true, true) -- Make another buffer
+
+ local current_window = 0
+ vim.api.nvim_set_option_value("winfixbuf", true, {win=current_window})
+
+ return buffer
+ end
+
+ local other_buffer = _setup_two_buffers()
+ local current_window = 0
+ local results, _ = pcall(vim.api.nvim_win_set_buf, current_window, other_buffer)
+
+ return results
+ ]])
+
+ assert(results == false)
+ end)
+
+ it("Calling vim.api.nvim_set_current_buf with 'winfixbuf'", function()
+ local results = exec_lua([[
+ local function _setup_two_buffers()
+ local buffer = vim.api.nvim_create_buf(true, true)
+
+ vim.api.nvim_create_buf(true, true) -- Make another buffer
+
+ local current_window = 0
+ vim.api.nvim_set_option_value("winfixbuf", true, {win=current_window})
+
+ return buffer
+ end
+
+ local other_buffer = _setup_two_buffers()
+ local results, _ = pcall(vim.api.nvim_set_current_buf, other_buffer)
+
+ return results
+ ]])
+
+ assert(results == false)
+ end)
+end)
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index 705c182df7..72531db021 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -257,7 +257,7 @@ describe('vim.lsp.diagnostic', function()
}, {client_id=client_id})
return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2"))
]]
- eq(bufnr, -1)
+ eq(-1, bufnr)
-- Create buffer on diagnostics
bufnr = exec_lua [[
@@ -269,8 +269,8 @@ describe('vim.lsp.diagnostic', function()
}, {client_id=client_id})
return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2"))
]]
- neq(bufnr, -1)
- eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 1)
+ neq(-1, bufnr)
+ eq(1, exec_lua([[return #vim.diagnostic.get(...)]], bufnr))
-- Clear diagnostics after buffer was created
bufnr = exec_lua [[
@@ -280,8 +280,8 @@ describe('vim.lsp.diagnostic', function()
}, {client_id=client_id})
return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2"))
]]
- neq(bufnr, -1)
- eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 0)
+ neq(-1, bufnr)
+ eq(0, exec_lua([[return #vim.diagnostic.get(...)]], bufnr))
end)
end)
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
index 192797b312..864394d7e0 100644
--- a/test/functional/plugin/lsp/inlay_hint_spec.lua
+++ b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -169,12 +169,12 @@ describe('vim.lsp.inlay_hint', function()
--- @type vim.lsp.inlay_hint.get.ret
local res = exec_lua([[return vim.lsp.inlay_hint.get()]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 1, inlay_hint = expected[1] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[2] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[3] },
{ bufnr = 1, client_id = 2, inlay_hint = expected2 },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
@@ -183,9 +183,9 @@ describe('vim.lsp.inlay_hint', function()
["end"] = { line = 2, character = 10 },
},
})]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 2, inlay_hint = expected2 },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
@@ -195,16 +195,16 @@ describe('vim.lsp.inlay_hint', function()
["end"] = { line = 5, character = 17 },
},
})]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 1, inlay_hint = expected[2] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[3] },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
bufnr = vim.api.nvim_get_current_buf() + 1,
})]])
- eq(res, {})
+ eq({}, res)
end)
end)
end)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 0fdcd0dd1d..0cb2b88948 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -205,8 +205,8 @@ describe('LSP', function()
client.stop()
end,
on_exit = function(code, signal)
- eq(0, code, 'exit code', fake_lsp_logfile)
- eq(0, signal, 'exit signal', fake_lsp_logfile)
+ eq(0, code, 'exit code')
+ eq(0, signal, 'exit signal')
end,
settings = {
dummy = 1,
@@ -641,11 +641,11 @@ describe('LSP', function()
vim.lsp.stop_client(client_id)
return server.messages
]])
- eq(#messages, 4)
- eq(messages[1].method, 'initialize')
- eq(messages[2].method, 'initialized')
- eq(messages[3].method, 'shutdown')
- eq(messages[4].method, 'exit')
+ eq(4, #messages)
+ eq('initialize', messages[1].method)
+ eq('initialized', messages[2].method)
+ eq('shutdown', messages[3].method)
+ eq('exit', messages[4].method)
end)
it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function()
@@ -2383,12 +2383,13 @@ describe('LSP', function()
[[
local old = select(1, ...)
local new = select(2, ...)
+ local old_bufnr = vim.fn.bufadd(old)
+ vim.fn.bufload(old_bufnr)
vim.lsp.util.rename(old, new)
-
- -- after rename the target file must have the contents of the source file
- local bufnr = vim.fn.bufadd(new)
- vim.fn.bufload(new)
- return vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
+ -- the existing buffer is renamed in-place and its contents is kept
+ local new_bufnr = vim.fn.bufadd(new)
+ vim.fn.bufload(new_bufnr)
+ return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true)
]],
old,
new
@@ -2400,87 +2401,6 @@ describe('LSP', function()
eq(true, exists)
os.remove(new)
end)
- it('Kills old buffer after renaming an existing file', function()
- local old = tmpname()
- write_file(old, 'Test content')
- local new = tmpname()
- os.remove(new) -- only reserve the name, file must not exist for the test scenario
- local lines = exec_lua(
- [[
- local old = select(1, ...)
- local oldbufnr = vim.fn.bufadd(old)
- local new = select(2, ...)
- vim.lsp.util.rename(old, new)
- return vim.fn.bufloaded(oldbufnr)
- ]],
- old,
- new
- )
- eq(0, lines)
- os.remove(new)
- end)
- it('new buffer remains unlisted and unloaded if the old was not in window before', function()
- local old = tmpname()
- write_file(old, 'Test content')
- local new = tmpname()
- os.remove(new) -- only reserve the name, file must not exist for the test scenario
- local actual = exec_lua(
- [[
- local old = select(1, ...)
- local oldbufnr = vim.fn.bufadd(old)
- local new = select(2, ...)
- local newbufnr = vim.fn.bufadd(new)
- vim.lsp.util.rename(old, new)
- return {
- buflisted = vim.bo[newbufnr].buflisted,
- bufloaded = vim.api.nvim_buf_is_loaded(newbufnr)
- }
- ]],
- old,
- new
- )
-
- local expected = {
- buflisted = false,
- bufloaded = false,
- }
-
- eq(expected, actual)
-
- os.remove(new)
- end)
- it('new buffer is listed and loaded if the old was in window before', function()
- local old = tmpname()
- write_file(old, 'Test content')
- local new = tmpname()
- os.remove(new) -- only reserve the name, file must not exist for the test scenario
- local actual = exec_lua(
- [[
- local win = vim.api.nvim_get_current_win()
- local old = select(1, ...)
- local oldbufnr = vim.fn.bufadd(old)
- vim.api.nvim_win_set_buf(win, oldbufnr)
- local new = select(2, ...)
- vim.lsp.util.rename(old, new)
- local newbufnr = vim.fn.bufadd(new)
- return {
- buflisted = vim.bo[newbufnr].buflisted,
- bufloaded = vim.api.nvim_buf_is_loaded(newbufnr)
- }
- ]],
- old,
- new
- )
-
- local expected = {
- buflisted = true,
- bufloaded = true,
- }
-
- eq(expected, actual)
-
- os.remove(new)
- end)
it('Can rename a directory', function()
-- only reserve the name, file must not exist for the test scenario
local old_dir = tmpname()
@@ -2497,21 +2417,25 @@ describe('LSP', function()
[[
local old_dir = select(1, ...)
local new_dir = select(2, ...)
- local pathsep = select(3, ...)
- local oldbufnr = vim.fn.bufadd(old_dir .. pathsep .. 'file')
-
+ local pathsep = select(3, ...)
+ local file = select(4, ...)
+ local old_bufnr = vim.fn.bufadd(old_dir .. pathsep .. file)
+ vim.fn.bufload(old_bufnr)
vim.lsp.util.rename(old_dir, new_dir)
- return vim.fn.bufloaded(oldbufnr)
+ -- the existing buffer is renamed in-place and its contents is kept
+ local new_bufnr = vim.fn.bufadd(new_dir .. pathsep .. file)
+ vim.fn.bufload(new_bufnr)
+ return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true)
]],
old_dir,
new_dir,
- pathsep
+ pathsep,
+ file
)
- eq(0, lines)
+ eq({ 'Test content' }, lines)
eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old_dir))
eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir))
eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir .. pathsep .. file))
- eq('Test content', read_file(new_dir .. pathsep .. file))
os.remove(new_dir)
end)
@@ -2593,6 +2517,88 @@ describe('LSP', function()
eq('New file', read_file(new))
end
)
+ it('Maintains undo information for loaded buffer', function()
+ local old = tmpname()
+ write_file(old, 'line')
+ local new = tmpname()
+ os.remove(new)
+
+ local undo_kept = exec_lua(
+ [[
+ local old = select(1, ...)
+ local new = select(2, ...)
+ vim.opt.undofile = true
+ vim.cmd.edit(old)
+ vim.cmd.normal('dd')
+ vim.cmd.write()
+ local undotree = vim.fn.undotree()
+ vim.lsp.util.rename(old, new)
+ -- Renaming uses :saveas, which updates the "last write" information.
+ -- Other than that, the undotree should remain the same.
+ undotree.save_cur = undotree.save_cur + 1
+ undotree.save_last = undotree.save_last + 1
+ undotree.entries[1].save = undotree.entries[1].save + 1
+ return vim.deep_equal(undotree, vim.fn.undotree())
+ ]],
+ old,
+ new
+ )
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(true, undo_kept)
+ end)
+ it('Maintains undo information for unloaded buffer', function()
+ local old = tmpname()
+ write_file(old, 'line')
+ local new = tmpname()
+ os.remove(new)
+
+ local undo_kept = exec_lua(
+ [[
+ local old = select(1, ...)
+ local new = select(2, ...)
+ vim.opt.undofile = true
+ vim.cmd.split(old)
+ vim.cmd.normal('dd')
+ vim.cmd.write()
+ local undotree = vim.fn.undotree()
+ vim.cmd.bdelete()
+ vim.lsp.util.rename(old, new)
+ vim.cmd.edit(new)
+ return vim.deep_equal(undotree, vim.fn.undotree())
+ ]],
+ old,
+ new
+ )
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(true, undo_kept)
+ end)
+ it('Does not rename file when it conflicts with a buffer without file', function()
+ local old = tmpname()
+ write_file(old, 'Old File')
+ local new = tmpname()
+ os.remove(new)
+
+ local lines = exec_lua(
+ [[
+ local old = select(1, ...)
+ local new = select(2, ...)
+ local old_buf = vim.fn.bufadd(old)
+ vim.fn.bufload(old_buf)
+ local conflict_buf = vim.api.nvim_create_buf(true, false)
+ vim.api.nvim_buf_set_name(conflict_buf, new)
+ vim.api.nvim_buf_set_lines(conflict_buf, 0, -1, true, {'conflict'})
+ vim.api.nvim_win_set_buf(0, conflict_buf)
+ vim.lsp.util.rename(old, new)
+ return vim.api.nvim_buf_get_lines(conflict_buf, 0, -1, true)
+ ]],
+ old,
+ new
+ )
+ eq({ 'conflict' }, lines)
+ eq('Old File', read_file(old))
+ end)
it('Does override target if overwrite is true', function()
local old = tmpname()
write_file(old, 'Old file')
@@ -4215,7 +4221,7 @@ describe('LSP', function()
server:shutdown()
return vim.json.decode(init)
]]
- eq(result.method, 'initialize')
+ eq('initialize', result.method)
end)
it('can connect to lsp server via rpc.domain_socket_connect', function()
local tmpfile
@@ -4251,7 +4257,7 @@ describe('LSP', function()
]],
tmpfile
)
- eq(result.method, 'initialize')
+ eq('initialize', result.method)
end)
end)
@@ -4438,113 +4444,140 @@ describe('LSP', function()
end)
describe('vim.lsp._watchfiles', function()
- it('sends notifications when files change', function()
- skip(
- is_os('bsd'),
- 'kqueue only reports events on watched folder itself, not contained files #26110'
- )
- local root_dir = tmpname()
- os.remove(root_dir)
- mkdir(root_dir)
+ local function test_filechanges(watchfunc)
+ it(
+ string.format('sends notifications when files change (watchfunc=%s)', watchfunc),
+ function()
+ if watchfunc == 'fswatch' then
+ skip(
+ not is_ci() and fn.executable('fswatch') == 0,
+ 'fswatch not installed and not on CI'
+ )
+ skip(is_os('win'), 'not supported on windows')
+ skip(is_os('mac'), 'flaky')
+ end
- exec_lua(create_server_definition)
- local result = exec_lua(
- [[
- local root_dir = ...
+ skip(
+ is_os('bsd'),
+ 'kqueue only reports events on watched folder itself, not contained files #26110'
+ )
- local server = _create_server()
- local client_id = vim.lsp.start({
- name = 'watchfiles-test',
- cmd = server.cmd,
- root_dir = root_dir,
- capabilities = {
- workspace = {
- didChangeWatchedFiles = {
- dynamicRegistration = true,
+ local root_dir = tmpname()
+ os.remove(root_dir)
+ mkdir(root_dir)
+
+ exec_lua(create_server_definition)
+ local result = exec_lua(
+ [[
+ local root_dir, watchfunc = ...
+
+ local server = _create_server()
+ local client_id = vim.lsp.start({
+ name = 'watchfiles-test',
+ cmd = server.cmd,
+ root_dir = root_dir,
+ capabilities = {
+ workspace = {
+ didChangeWatchedFiles = {
+ dynamicRegistration = true,
+ },
},
},
- },
- })
+ })
- local expected_messages = 2 -- initialize, initialized
+ require('vim.lsp._watchfiles')._watchfunc = require('vim._watch')[watchfunc]
- local watchfunc = require('vim.lsp._watchfiles')._watchfunc
- local msg_wait_timeout = watchfunc == vim._watch.poll and 2500 or 200
- local function wait_for_messages()
- assert(vim.wait(msg_wait_timeout, function() return #server.messages == expected_messages end), 'Timed out waiting for expected number of messages. Current messages seen so far: ' .. vim.inspect(server.messages))
- end
+ local expected_messages = 0
- wait_for_messages()
+ local msg_wait_timeout = watchfunc == 'watch' and 200 or 2500
- vim.lsp.handlers['client/registerCapability'](nil, {
- registrations = {
- {
- id = 'watchfiles-test-0',
- method = 'workspace/didChangeWatchedFiles',
- registerOptions = {
- watchers = {
- {
- globPattern = '**/watch',
- kind = 7,
+ local function wait_for_message(incr)
+ expected_messages = expected_messages + (incr or 1)
+ assert(
+ vim.wait(msg_wait_timeout, function()
+ return #server.messages == expected_messages
+ end),
+ 'Timed out waiting for expected number of messages. Current messages seen so far: '
+ .. vim.inspect(server.messages)
+ )
+ end
+
+ wait_for_message(2) -- initialize, initialized
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-0',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/watch',
+ kind = 7,
+ },
},
},
},
},
- },
- }, { client_id = client_id })
+ }, { client_id = client_id })
- if watchfunc == vim._watch.poll then
- vim.wait(100)
- end
+ if watchfunc ~= 'watch' then
+ vim.wait(100)
+ end
- local path = root_dir .. '/watch'
- local file = io.open(path, 'w')
- file:close()
+ local path = root_dir .. '/watch'
+ local tmp = vim.fn.tempname()
+ io.open(tmp, 'w'):close()
+ vim.uv.fs_rename(tmp, path)
- expected_messages = expected_messages + 1
- wait_for_messages()
+ wait_for_message()
- os.remove(path)
+ os.remove(path)
- expected_messages = expected_messages + 1
- wait_for_messages()
+ wait_for_message()
- return server.messages
- ]],
- root_dir
- )
+ vim.lsp.stop_client(client_id)
- local function watched_uri(fname)
- return exec_lua(
- [[
- local root_dir, fname = ...
- return vim.uri_from_fname(root_dir .. '/' .. fname)
- ]],
- root_dir,
- fname
- )
- end
+ return server.messages
+ ]],
+ root_dir,
+ watchfunc
+ )
- eq(4, #result)
- eq('workspace/didChangeWatchedFiles', result[3].method)
- eq({
- changes = {
- {
- type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
- uri = watched_uri('watch'),
- },
- },
- }, result[3].params)
- eq('workspace/didChangeWatchedFiles', result[4].method)
- eq({
- changes = {
- {
- type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
- uri = watched_uri('watch'),
- },
- },
- }, result[4].params)
- end)
+ local uri = vim.uri_from_fname(root_dir .. '/watch')
+
+ eq(6, #result)
+
+ eq({
+ method = 'workspace/didChangeWatchedFiles',
+ params = {
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = uri,
+ },
+ },
+ },
+ }, result[3])
+
+ eq({
+ method = 'workspace/didChangeWatchedFiles',
+ params = {
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
+ uri = uri,
+ },
+ },
+ },
+ }, result[4])
+ end
+ )
+ end
+
+ test_filechanges('watch')
+ test_filechanges('watchdirs')
+ test_filechanges('fswatch')
it('correctly registers and unregisters', function()
local root_dir = '/some_dir'
diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua
index 66dcfde3aa..2ac0fe1fa3 100644
--- a/test/functional/plugin/tohtml_spec.lua
+++ b/test/functional/plugin/tohtml_spec.lua
@@ -115,18 +115,20 @@ end
---@param func function?
local function run_tohtml_and_assert(screen, func)
exec('norm! ggO-;')
- exec('norm! gg0f;:\r')
- screen:sleep(10)
- local snapshot = { grid = screen:get_snapshot().grid, attr_ids = screen:get_snapshot().attr_ids }
+ screen:expect({ any = vim.pesc('-^;') })
+ exec('norm! :\rh')
+ screen:expect({ any = vim.pesc('^-;') })
+ local expected = screen:get_snapshot()
do
(func or exec)('TOhtml')
end
exec('only')
html_syntax_match()
html_to_extmarks()
- exec('norm! gg0f;:\r')
- screen:sleep(10)
- eq(snapshot, { grid = screen:get_snapshot().grid, attr_ids = screen:get_snapshot().attr_ids })
+ exec('norm! gg0f;')
+ screen:expect({ any = vim.pesc('-^;') })
+ exec('norm! :\rh')
+ screen:expect({ grid = expected.grid, attr_ids = expected.attr_ids })
end
describe(':TOhtml', function()
@@ -288,7 +290,7 @@ describe(':TOhtml', function()
--api.nvim_buf_set_extmark(0,ns,3,0,{virt_text={{'foo'}},virt_text_pos='right_align'})
run_tohtml_and_assert(screen)
end)
- it('highlgith', function()
+ it('highlight', function()
insert [[
line1
]]
@@ -315,7 +317,7 @@ describe(':TOhtml', function()
fn.setline(1, '\tfoo\t')
fn.setline(2, ' foo foo ')
fn.setline(3, ' foo foo ')
- fn.setline(4, 'foo\x2cfoo')
+ fn.setline(4, 'foo\194\160 \226\128\175foo')
run_tohtml_and_assert(screen)
exec('new|only')
fn.setline(1, '\tfoo\t')
diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua
index 9bde57f777..80b3552e82 100644
--- a/test/functional/provider/python3_spec.lua
+++ b/test/functional/provider/python3_spec.lua
@@ -20,6 +20,12 @@ do
matches(expected, pcall_err(command, 'py3 print("foo")'))
matches(expected, pcall_err(command, 'py3file foo'))
end)
+ it('feature test when Python 3 provider is missing', function()
+ eq(0, eval('has("python3")'))
+ eq(0, eval('has("python3_compiled")'))
+ eq(0, eval('has("python3_dynamic")'))
+ eq(0, eval('has("pythonx")'))
+ end)
pending(
string.format('Python 3 (or the pynvim module) is broken/missing (%s)', reason),
function() end
@@ -38,6 +44,7 @@ describe('python3 provider', function()
eq(1, eval('has("python3")'))
eq(1, eval('has("python3_compiled")'))
eq(1, eval('has("python3_dynamic")'))
+ eq(1, eval('has("pythonx")'))
eq(0, eval('has("python3_dynamic_")'))
eq(0, eval('has("python3_")'))
end)
diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua
index 931fe42dd0..c3ac9fe722 100644
--- a/test/functional/script/luacats_grammar_spec.lua
+++ b/test/functional/script/luacats_grammar_spec.lua
@@ -130,4 +130,25 @@ describe('luacats grammar', function()
type = 'b',
desc = 'desc',
})
+
+ test(
+ '@field prefix? string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)',
+ {
+ kind = 'field',
+ name = 'prefix?',
+ type = 'string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)',
+ }
+ )
+
+ test('@field [integer] integer', {
+ kind = 'field',
+ name = '[integer]',
+ type = 'integer',
+ })
+
+ test('@field [1] integer', {
+ kind = 'field',
+ name = '[1]',
+ type = 'integer',
+ })
end)
diff --git a/test/functional/script/luacats_parser_spec.lua b/test/functional/script/luacats_parser_spec.lua
new file mode 100644
index 0000000000..e10aa81003
--- /dev/null
+++ b/test/functional/script/luacats_parser_spec.lua
@@ -0,0 +1,106 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+
+local parser = require('scripts/luacats_parser')
+
+--- @param name string
+--- @param text string
+--- @param exp table<string,string>
+local function test(name, text, exp)
+ exp = vim.deepcopy(exp, true)
+ it(name, function()
+ eq(exp, parser.parse_str(text, 'myfile.lua'))
+ end)
+end
+
+describe('luacats parser', function()
+ local exp = {
+ myclass = {
+ kind = 'class',
+ module = 'myfile.lua',
+ name = 'myclass',
+ fields = {
+ { kind = 'field', name = 'myclass', type = 'integer' },
+ },
+ },
+ }
+
+ test(
+ 'basic class',
+ [[
+ --- @class myclass
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ exp.myclass.inlinedoc = true
+
+ test(
+ 'class with @inlinedoc (1)',
+ [[
+ --- @class myclass
+ --- @inlinedoc
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ test(
+ 'class with @inlinedoc (2)',
+ [[
+ --- @inlinedoc
+ --- @class myclass
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ exp.myclass.inlinedoc = nil
+ exp.myclass.nodoc = true
+
+ test(
+ 'class with @nodoc',
+ [[
+ --- @nodoc
+ --- @class myclass
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ exp.myclass.nodoc = nil
+ exp.myclass.access = 'private'
+
+ test(
+ 'class with (private)',
+ [[
+ --- @class (private) myclass
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ exp.myclass.fields[1].desc = 'Field\ndocumentation'
+
+ test(
+ 'class with field doc above',
+ [[
+ --- @class (private) myclass
+ --- Field
+ --- documentation
+ --- @field myclass integer
+ ]],
+ exp
+ )
+
+ exp.myclass.fields[1].desc = 'Field documentation'
+ test(
+ 'class with field doc inline',
+ [[
+ --- @class (private) myclass
+ --- @field myclass integer Field documentation
+ ]],
+ exp
+ )
+end)
diff --git a/test/functional/script/text_utils_spec.lua b/test/functional/script/text_utils_spec.lua
index c429d306d5..190c617e1d 100644
--- a/test/functional/script/text_utils_spec.lua
+++ b/test/functional/script/text_utils_spec.lua
@@ -2,18 +2,28 @@ local helpers = require('test.functional.helpers')(after_each)
local exec_lua = helpers.exec_lua
local eq = helpers.eq
-local function md_to_vimdoc(text)
+local function md_to_vimdoc(text, start_indent, indent, text_width)
return exec_lua(
[[
+ local text, start_indent, indent, text_width = ...
+ start_indent = start_indent or 0
+ indent = indent or 0
+ text_width = text_width or 70
local text_utils = require('scripts/text_utils')
- return text_utils.md_to_vimdoc(table.concat(..., '\n'), 0, 0, 70)
+ return text_utils.md_to_vimdoc(table.concat(text, '\n'), start_indent, indent, text_width)
]],
- text
+ text,
+ start_indent,
+ indent,
+ text_width
)
end
-local function test(act, exp)
- eq(table.concat(exp, '\n'), md_to_vimdoc(act))
+local function test(what, act, exp, ...)
+ local argc, args = select('#', ...), { ... }
+ it(what, function()
+ eq(table.concat(exp, '\n'), md_to_vimdoc(act, unpack(args, 1, argc)))
+ end)
end
describe('md_to_vimdoc', function()
@@ -21,19 +31,30 @@ describe('md_to_vimdoc', function()
helpers.clear()
end)
- it('can render para after fenced code', function()
- test({
- '- Para1',
- ' ```',
- ' code',
- ' ```',
- ' Para2',
- }, {
- '• Para1 >',
- ' code',
- '<',
- ' Para2',
- '',
- })
- end)
+ test('can render para after fenced code', {
+ '- Para1',
+ ' ```',
+ ' code',
+ ' ```',
+ ' Para2',
+ }, {
+ '• Para1 >',
+ ' code',
+ '<',
+ ' Para2',
+ '',
+ })
+
+ test('start_indent only applies to first line', {
+ 'para1',
+ '',
+ 'para2',
+ }, {
+ 'para1',
+ '',
+ ' para2',
+ '',
+ }, 0, 10, 78)
+
+ test('inline 1', { '(`string`)' }, { '(`string`)', '' })
end)
diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua
index 1b5c0eab5d..ff81ce4eb9 100644
--- a/test/functional/shada/merging_spec.lua
+++ b/test/functional/shada/merging_spec.lua
@@ -1003,7 +1003,7 @@ describe('ShaDa jumps support code', function()
eq(jumps[found].line, v.value.l)
end
end
- eq(found, #jumps)
+ eq(#jumps, found)
end)
it('merges JUMPLISTSIZE jumps when writing', function()
@@ -1041,7 +1041,7 @@ describe('ShaDa jumps support code', function()
eq(jumps[found].line, v.value.l)
end
end
- eq(found, 100)
+ eq(100, found)
end)
end)
@@ -1132,7 +1132,7 @@ describe('ShaDa changes support code', function()
eq(changes[found].line, v.value.l or 1)
end
end
- eq(found, #changes)
+ eq(#changes, found)
end)
it('merges JUMPLISTSIZE changes when writing', function()
@@ -1170,7 +1170,7 @@ describe('ShaDa changes support code', function()
eq(changes[found].line, v.value.l)
end
end
- eq(found, 100)
+ eq(100, found)
end)
it('merges JUMPLISTSIZE changes when writing, with new items between old', function()
@@ -1213,6 +1213,6 @@ describe('ShaDa changes support code', function()
eq(changes[found].line, v.value.l)
end
end
- eq(found, 100)
+ eq(100, found)
end)
end)
diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua
index 3781933cad..b63e61d9e7 100644
--- a/test/functional/terminal/window_spec.lua
+++ b/test/functional/terminal/window_spec.lua
@@ -35,6 +35,7 @@ describe(':terminal window', function()
describe("with 'number'", function()
it('wraps text', function()
+ skip(is_os('win')) -- todo(clason): unskip when reenabling reflow
feed([[<C-\><C-N>]])
feed([[:set numberwidth=1 number<CR>i]])
screen:expect([[
@@ -64,7 +65,7 @@ describe(':terminal window', function()
{7: 1 }tty ready |
{7: 2 }rows: 6, cols: 48 |
{7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
- {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 |
+ {7: 4 }WXYZrows: 6, cols: 41 |
{7: 5 }{1: } |
{7: 6 } |
{3:-- TERMINAL --} |
@@ -74,7 +75,7 @@ describe(':terminal window', function()
{7: 1 }tty ready |
{7: 2 }rows: 6, cols: 48 |
{7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
- {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 |
+ {7: 4 }WXYZrows: 6, cols: 41 |
{7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN|
{7: 6 }OPQRSTUVWXYZ{1: } |
{3:-- TERMINAL --} |
@@ -84,6 +85,7 @@ describe(':terminal window', function()
describe("with 'statuscolumn'", function()
it('wraps text', function()
+ skip(is_os('win')) -- todo(clason): unskip when reenabling reflow
command([[set number statuscolumn=++%l\ \ ]])
screen:expect([[
{7:++1 }tty ready |
@@ -108,9 +110,9 @@ describe(':terminal window', function()
screen:expect([[
{7:++7 } |
{7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
- {7:++9 }STUVWXYZ |
+ {7:++9 }TUVWXYZ |
{7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
- {7:++11 }STUVWXYZrows: 6, cols: 44 |
+ {7:++11 }TUVWXYZrows: 6, cols: 44 |
{7:++12 }{1: } |
{3:-- TERMINAL --} |
]])
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 2bf230fe69..8b405615e0 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -681,6 +681,12 @@ describe('treesitter highlighting (C)', function()
((identifier) @Identifier
(#set! conceal "")
(#eq? @Identifier "lstate"))
+
+ ((call_expression
+ function: (identifier) @function
+ arguments: (argument_list) @arguments)
+ (#eq? @function "multiqueue_put")
+ (#set! @function conceal "V"))
]]}})
]=]
@@ -697,7 +703,7 @@ describe('treesitter highlighting (C)', function()
|
LuaRef cb = nlua_ref(, 1); |
|
- multiqueue_put(main_loop.events, nlua_schedule_event, |
+ {11:V}(main_loop.events, nlua_schedule_event, |
1, (void *)(ptrdiff_t)cb); |
return 0; |
^} |
@@ -758,6 +764,44 @@ describe('treesitter highlighting (C)', function()
end)
end)
+describe('treesitter highlighting (lua)', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(65, 18)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = { bold = true, foreground = Screen.colors.Blue },
+ [2] = { foreground = Screen.colors.DarkCyan },
+ [3] = { foreground = Screen.colors.Magenta },
+ [4] = { foreground = Screen.colors.SlateBlue },
+ [5] = { bold = true, foreground = Screen.colors.Brown },
+ }
+ end)
+
+ it('supports language injections', function()
+ insert [[
+ local ffi = require('ffi')
+ ffi.cdef("int (*fun)(int, char *);")
+ ]]
+
+ exec_lua [[
+ vim.bo.filetype = 'lua'
+ vim.treesitter.start()
+ ]]
+
+ screen:expect {
+ grid = [[
+ {5:local} {2:ffi} {5:=} {4:require(}{3:'ffi'}{4:)} |
+ {2:ffi}{4:.}{2:cdef}{4:(}{3:"}{4:int}{3: }{4:(}{5:*}{3:fun}{4:)(int,}{3: }{4:char}{3: }{5:*}{4:);}{3:"}{4:)} |
+ ^ |
+ {1:~ }|*14
+ |
+ ]],
+ }
+ end)
+end)
+
describe('treesitter highlighting (help)', function()
local screen
@@ -823,6 +867,40 @@ describe('treesitter highlighting (help)', function()
]],
}
end)
+
+ it('correctly redraws injections subpriorities', function()
+ -- The top level string node will be highlighted first
+ -- with an extmark spanning multiple lines.
+ -- When the next line is drawn, which includes an injection,
+ -- make sure the highlight appears above the base tree highlight
+
+ insert([=[
+ local s = [[
+ local also = lua
+ ]]
+ ]=])
+
+ exec_lua [[
+ parser = vim.treesitter.get_parser(0, "lua", {
+ injections = {
+ lua = '(string content: (_) @injection.content (#set! injection.language lua))'
+ }
+ })
+
+ vim.treesitter.highlighter.new(parser)
+ ]]
+
+ screen:expect {
+ grid = [=[
+ {3:local} {4:s} {3:=} {5:[[} |
+ {5: }{3:local}{5: }{4:also}{5: }{3:=}{5: }{4:lua} |
+ {5:]]} |
+ ^ |
+ {2:~ }|
+ |
+ ]=],
+ }
+ end)
end)
describe('treesitter highlighting (nested injections)', function()
@@ -891,3 +969,46 @@ vim.cmd([[
}
end)
end)
+
+describe('treesitter highlighting (markdown)', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(40, 6)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = { foreground = Screen.colors.Blue1 },
+ [2] = { bold = true, foreground = Screen.colors.Blue1 },
+ [3] = { bold = true, foreground = Screen.colors.Brown },
+ [4] = { foreground = Screen.colors.Cyan4 },
+ [5] = { foreground = Screen.colors.Magenta1 },
+ }
+ end)
+
+ it('supports hyperlinks', function()
+ local url = 'https://example.com'
+ insert(string.format('[This link text](%s) is a hyperlink.', url))
+ exec_lua([[
+ vim.bo.filetype = 'markdown'
+ vim.treesitter.start()
+ ]])
+
+ screen:expect {
+ grid = [[
+ {4:[}{6:This link text}{4:](}{7:https://example.com}{4:)} is|
+ a hyperlink^. |
+ {2:~ }|*3
+ |
+ ]],
+ attr_ids = {
+ [1] = { foreground = Screen.colors.Blue1 },
+ [2] = { bold = true, foreground = Screen.colors.Blue1 },
+ [3] = { bold = true, foreground = Screen.colors.Brown },
+ [4] = { foreground = Screen.colors.Cyan4 },
+ [5] = { foreground = Screen.colors.Magenta },
+ [6] = { foreground = Screen.colors.Cyan4, url = url },
+ [7] = { underline = true, foreground = Screen.colors.SlateBlue },
+ },
+ }
+ end)
+end)
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index c852e25ea6..f114d36823 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -50,7 +50,7 @@ describe('treesitter node API', function()
lang = 'lua',
})
]])
- eq('foo', lua_eval('vim.treesitter.query.get_node_text(node, 0)'))
+ eq('foo', lua_eval('vim.treesitter.get_node_text(node, 0)'))
eq('identifier', lua_eval('node:type()'))
end)
@@ -62,14 +62,13 @@ describe('treesitter node API', function()
]])
exec_lua([[
- query = require"vim.treesitter.query"
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
root = tree:root()
lang = vim.treesitter.language.inspect('c')
function node_text(node)
- return query.get_node_text(node, 0)
+ return vim.treesitter.get_node_text(node, 0)
end
]])
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index bc7a1958ce..24f395c1ef 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -563,7 +563,7 @@ end]]
local function is_main(match, pattern, bufnr, predicate)
local nodes = match[ predicate[2] ]
for _, node in ipairs(nodes) do
- if query.get_node_text(node, bufnr) == 'main' then
+ if vim.treesitter.get_node_text(node, bufnr) == 'main' then
return true
end
end
@@ -602,7 +602,7 @@ end]]
local function is_main(match, pattern, bufnr, predicate)
local node = match[ predicate[2] ]
- return query.get_node_text(node, bufnr) == 'main'
+ return vim.treesitter.get_node_text(node, bufnr) == 'main'
end
local parser = vim.treesitter.get_parser(0, "c")
@@ -828,7 +828,7 @@ end]]
return parser:included_regions()
]]
- eq(range_tbl, { { { 0, 0, 0, 17, 1, 508 } } })
+ eq({ { { 0, 0, 0, 17, 1, 508 } } }, range_tbl)
end)
it('allows to set complex ranges', function()
@@ -1111,7 +1111,7 @@ int x = INT_MAX;
return sub_tree == parser:children().c
]])
- eq(result, true)
+ eq(true, result)
end)
end)
@@ -1135,7 +1135,7 @@ int x = INT_MAX;
return result
]])
- eq(result, 'value')
+ eq('value', result)
end)
describe('when setting a key on a capture', function()
@@ -1158,7 +1158,7 @@ int x = INT_MAX;
end
]])
- eq(result, 'value')
+ eq('value', result)
end)
it('it should not overwrite the nested table', function()
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index e57e719192..98d221be7d 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -2301,8 +2301,21 @@ describe('extmark decorations', function()
]]}
end)
+ it('virtual text does not crash with blend, conceal and wrap #27836', function()
+ screen:try_resize(50, 3)
+ insert(('a'):rep(45) .. '|hidden|' .. ('b'):rep(45))
+ command('syntax match test /|hidden|/ conceal')
+ command('set conceallevel=2 concealcursor=n')
+ api.nvim_buf_set_extmark(0, ns, 0, 0, {virt_text = {{'FOO'}}, virt_text_pos='right_align', hl_mode='blend'})
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa FOO|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb^b |
+ |
+ ]]}
+ end)
+
it('works with both hl_group and sign_hl_group', function()
- screen:try_resize(screen._width, 3)
+ screen:try_resize(50, 3)
insert('abcdefghijklmn')
api.nvim_buf_set_extmark(0, ns, 0, 0, {sign_text='S', sign_hl_group='NonText', hl_group='Error', end_col=14})
screen:expect{grid=[[
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
index 4d06a24d3f..361ea3e778 100644
--- a/test/functional/ui/float_spec.lua
+++ b/test/functional/ui/float_spec.lua
@@ -550,6 +550,43 @@ describe('float window', function()
eq({ w0 }, api.nvim_list_wins())
end)
+ it('win_splitmove() can move float into a split', function()
+ command('split')
+ eq({'col', {{'leaf', 1001}, {'leaf', 1000}}}, fn.winlayout())
+
+ local win1 = api.nvim_open_win(0, true, {relative = 'editor', row = 1, col = 1, width = 5, height = 5})
+ fn.win_splitmove(win1, 1001, {vertical = true})
+ eq({'col', {{'row', {{'leaf', win1}, {'leaf', 1001}}}, {'leaf', 1000}}}, fn.winlayout())
+ eq('', api.nvim_win_get_config(win1).relative)
+
+ -- Should be unable to create a split relative to a float, though.
+ local win2 = api.nvim_open_win(0, true, {relative = 'editor', row = 1, col = 1, width = 5, height = 5})
+ eq('Vim:E957: Invalid window number', pcall_err(fn.win_splitmove, win1, win2, {vertical = true}))
+ end)
+
+ it('tp_curwin updated if external window is moved into split', function()
+ local screen = Screen.new(20, 7)
+ screen:attach { ext_multigrid = true }
+
+ command('tabnew')
+ local external_win = api.nvim_open_win(0, true, {external = true, width = 5, height = 5})
+ eq(external_win, api.nvim_get_current_win())
+ eq(2, fn.tabpagenr())
+ command('tabfirst')
+ api.nvim_set_current_win(external_win)
+ eq(external_win, api.nvim_get_current_win())
+ eq(1, fn.tabpagenr())
+
+ command('wincmd J')
+ eq(external_win, api.nvim_get_current_win())
+ eq(false, api.nvim_win_get_config(external_win).external)
+ command('tabnext')
+ eq(2, fn.tabpagenr())
+ neq(external_win, api.nvim_get_current_win())
+
+ screen:detach()
+ end)
+
describe('with only one tabpage,', function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local old_buf, old_win
@@ -836,6 +873,57 @@ describe('float window', function()
end)
end)
+ describe(':close on non-float with floating windows', function()
+ -- XXX: it isn't really clear whether this should quit Nvim, as if the autocommand
+ -- here is BufUnload then it does quit Nvim.
+ -- But with BufWinLeave, this doesn't quit Nvim if there are no floating windows,
+ -- so it shouldn't quit Nvim if there are floating windows.
+ it('does not quit Nvim if BufWinLeave makes it the only non-float', function()
+ exec([[
+ let g:buf = bufnr()
+ new
+ let s:midwin = win_getid()
+ new
+ setlocal bufhidden=wipe
+ call nvim_win_set_config(s:midwin,
+ \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
+ autocmd BufWinLeave * ++once exe g:buf .. 'bwipe!'
+ ]])
+ eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
+ assert_alive()
+ end)
+
+ pending('does not crash if BufUnload makes it the only non-float in tabpage', function()
+ exec([[
+ tabnew
+ let g:buf = bufnr()
+ new
+ let s:midwin = win_getid()
+ new
+ setlocal bufhidden=wipe
+ call nvim_win_set_config(s:midwin,
+ \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
+ autocmd BufUnload * ++once exe g:buf .. 'bwipe!'
+ ]])
+ command('close')
+ assert_alive()
+ end)
+
+ it('does not crash if WinClosed from floating window closes it', function()
+ exec([[
+ tabnew
+ new
+ let s:win = win_getid()
+ call nvim_win_set_config(s:win,
+ \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
+ wincmd t
+ exe $"autocmd WinClosed {s:win} 1close"
+ ]])
+ command('close')
+ assert_alive()
+ end)
+ end)
+
local function with_ext_multigrid(multigrid)
local screen, attrs
before_each(function()
@@ -6169,7 +6257,7 @@ describe('float window', function()
run(on_request, nil, on_setup)
os.remove('Xtest_written')
os.remove('Xtest_written2')
- eq(exited, true)
+ eq(true, exited)
end)
it(':quit two floats in a row', function()
@@ -9030,6 +9118,93 @@ describe('float window', function()
]])
end
end)
+
+ it('correctly placed in or above message area', function()
+ local float_opts = {relative='editor', width=5, height=1, row=100, col=1, border = 'single'}
+ api.nvim_set_option_value('cmdheight', 3, {})
+ command("echo 'cmdline'")
+ local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
+ -- Not hidden behind message area but placed above it.
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|*4
+ [3:----------------------------------------]|*3
+ ## grid 2
+ |
+ {0:~ }|*3
+ ## grid 3
+ cmdline |
+ |*2
+ ## grid 4
+ {5:┌─────┐}|
+ {5:│}{1:^ }{5:│}|
+ {5:└─────┘}|
+ ]], float_pos={
+ [4] = {1001, "NW", 1, 100, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌─────┐}{0: }|
+ {0:~}{5:│}{1:^ }{5:│}{0: }|
+ {0:~}{5:└─────┘}{0: }|
+ cmdline |
+ |*2
+ ]]}
+ end
+ -- Not placed above message area and visible on top of it.
+ api.nvim_win_set_config(win, {zindex = 300})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|*4
+ [3:----------------------------------------]|*3
+ ## grid 2
+ |
+ {0:~ }|*3
+ ## grid 3
+ cmdline |
+ |*2
+ ## grid 4
+ {5:┌─────┐}|
+ {5:│}{1:^ }{5:│}|
+ {5:└─────┘}|
+ ]], float_pos={
+ [4] = {1001, "NW", 1, 100, 1, true, 300};
+ }, win_viewport={
+ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~ }|*3
+ c{5:┌─────┐} |
+ {5:│}{1:^ }{5:│} |
+ {5:└─────┘} |
+ ]]}
+ end
+ end)
+
+ it('attempt to turn into split with no room', function()
+ eq('Vim(split):E36: Not enough room', pcall_err(command, 'execute "split |"->repeat(&lines)'))
+ command('vsplit | wincmd | | wincmd p')
+ api.nvim_open_win(0, true, {relative = "editor", row = 0, col = 0, width = 5, height = 5})
+ local config = api.nvim_win_get_config(0)
+ eq('editor', config.relative)
+
+ local layout = fn.winlayout()
+ local restcmd = fn.winrestcmd()
+ eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd K'))
+ eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd J'))
+ eq(layout, fn.winlayout())
+ eq(restcmd, fn.winrestcmd())
+ eq(config, api.nvim_win_get_config(0))
+ end)
end
describe('with ext_multigrid', function()
diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua
index 727dc38829..f6d262c6fd 100644
--- a/test/functional/ui/highlight_spec.lua
+++ b/test/functional/ui/highlight_spec.lua
@@ -1380,6 +1380,8 @@ describe('CursorColumn highlight', function()
[1] = { background = Screen.colors.Gray90 }, -- CursorColumn
[2] = { bold = true, foreground = Screen.colors.Blue1 }, -- NonText
[3] = { bold = true }, -- ModeMsg
+ [4] = { background = Screen.colors.Red },
+ [5] = { background = Screen.colors.Blue },
})
screen:attach()
end)
@@ -1454,6 +1456,47 @@ describe('CursorColumn highlight', function()
]],
})
end)
+
+ it('is not shown on current line with virtualedit', function()
+ exec([[
+ hi! CursorColumn guibg=Red
+ hi! CursorLine guibg=Blue
+ set virtualedit=all cursorline cursorcolumn
+ ]])
+ insert('line 1\nline 2\nline 3')
+ feed('k')
+ screen:expect([[
+ line {4:1} |
+ {5:line ^2 }|
+ line {4:3} |
+ {2:~ }|*4
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ line 1{4: } |
+ {5:line 2^ }|
+ line 3{4: } |
+ {2:~ }|*4
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ line 1 {4: } |
+ {5:line 2 ^ }|
+ line 3 {4: } |
+ {2:~ }|*4
+ |
+ ]])
+ feed('l')
+ screen:expect([[
+ line 1 {4: } |
+ {5:line 2 ^ }|
+ line 3 {4: } |
+ {2:~ }|*4
+ |
+ ]])
+ end)
end)
describe('ColorColumn highlight', function()
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index 29c8c43ca1..d143c594f5 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -204,8 +204,8 @@ describe(":substitute, 'inccommand' preserves", function()
feed(':%s/as/glork/')
poke_eventloop()
feed('<enter>')
- eq(api.nvim_get_option_value('undolevels', { scope = 'global' }), 139)
- eq(api.nvim_get_option_value('undolevels', { buf = 0 }), 34)
+ eq(139, api.nvim_get_option_value('undolevels', { scope = 'global' }))
+ eq(34, api.nvim_get_option_value('undolevels', { buf = 0 }))
end)
end
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index 31b1464589..131622bcc5 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -844,7 +844,7 @@ describe('ui/ext_messages', function()
}
end)
- it('implies ext_cmdline and ignores cmdheight', function()
+ it("implies ext_cmdline but allows changing 'cmdheight'", function()
eq(0, eval('&cmdheight'))
feed(':set cmdheight=1')
screen:expect {
@@ -864,15 +864,17 @@ describe('ui/ext_messages', function()
feed('<cr>')
screen:expect([[
^ |
- {1:~ }|*4
+ {1:~ }|*3
+ |
]])
- eq(0, eval('&cmdheight'))
+ eq(1, eval('&cmdheight'))
feed(':set cmdheight=0')
screen:expect {
grid = [[
^ |
- {1:~ }|*4
+ {1:~ }|*3
+ |
]],
cmdline = {
{
@@ -1625,13 +1627,41 @@ describe('ui/ext_messages', function()
{1:~ }|*5
]])
- feed('<c-l>')
- screen:expect([[
+ -- <c-l> (same as :mode) does _not_ clear intro message
+ feed('<c-l>i')
+ screen:expect {
+ grid = [[
^ |
+ {1:~ }|*4
+ {MATCH:.*}|
+ {1:~ }|
+ {1:~ }Nvim is open source and freely distributable{1: }|
+ {1:~ }https://neovim.io/#chat{1: }|
+ {1:~ }|
+ {1:~ }type :help nvim{5:<Enter>} if you are new! {1: }|
+ {1:~ }type :checkhealth{5:<Enter>} to optimize Nvim{1: }|
+ {1:~ }type :q{5:<Enter>} to exit {1: }|
+ {1:~ }type :help{5:<Enter>} for help {1: }|
+ {1:~ }|
+ {1:~{MATCH: +}}type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}{1:{MATCH: +}}|
+ {1:~ }|
+ {MATCH:.*}|*2
+ {1:~ }|*5
+ ]],
+ showmode = { { '-- INSERT --', 3 } },
+ }
+
+ -- but editing text does..
+ feed('x')
+ screen:expect {
+ grid = [[
+ x^ |
{1:~ }|*23
- ]])
+ ]],
+ showmode = { { '-- INSERT --', 3 } },
+ }
- feed(':intro<cr>')
+ feed('<esc>:intro<cr>')
screen:expect {
grid = [[
^ |
@@ -1655,6 +1685,14 @@ describe('ui/ext_messages', function()
{ content = { { 'Press ENTER or type command to continue', 4 } }, kind = 'return_prompt' },
},
}
+
+ feed('<cr>')
+ screen:expect {
+ grid = [[
+ ^x |
+ {1:~ }|*23
+ ]],
+ }
end)
it('supports global statusline', function()
diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua
index 3a3ff25c39..41406a5860 100644
--- a/test/functional/ui/statuscolumn_spec.lua
+++ b/test/functional/ui/statuscolumn_spec.lua
@@ -927,4 +927,17 @@ describe('statuscolumn', function()
|
]])
end)
+
+ it('line increase properly redraws buffer text with relativenumber #27709', function()
+ screen:try_resize(33, 4)
+ command([[set rnu nuw=3 stc=%l\ ]])
+ command('call setline(1, range(1, 99))')
+ feed('Gyyp')
+ screen:expect([[
+ 98 98 |
+ 99 99 |
+ 100 ^99 |
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua
index fee4b64d44..000e2b1b04 100644
--- a/test/functional/ui/statusline_spec.lua
+++ b/test/functional/ui/statusline_spec.lua
@@ -11,6 +11,7 @@ local exec = helpers.exec
local exec_lua = helpers.exec_lua
local eval = helpers.eval
local sleep = vim.uv.sleep
+local pcall_err = helpers.pcall_err
local mousemodels = { 'extend', 'popup', 'popup_setpos' }
@@ -474,6 +475,25 @@ describe('global statusline', function()
|
]])
end)
+
+ it('horizontal separators unchanged when failing to split-move window', function()
+ exec([[
+ botright split
+ let &winwidth = &columns
+ let &winminwidth = &columns
+ ]])
+ eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd L'))
+ command('mode')
+ screen:expect([[
+ |
+ {1:~ }|*5
+ ────────────────────────────────────────────────────────────|
+ ^ |
+ {1:~ }|*6
+ {2:[No Name] 0,0-1 All}|
+ |
+ ]])
+ end)
end)
it('statusline does not crash if it has Arabic characters #19447', function()