aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 21:52:58 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 21:52:58 +0000
commit931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch)
treed8c1843a95da5ea0bb4acc09f7e37843d9995c86 /test/functional
parent142d9041391780ac15b89886a54015fdc5c73995 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-userreg.tar.gz
rneovim-userreg.tar.bz2
rneovim-userreg.zip
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/api/autocmd_spec.lua191
-rw-r--r--test/functional/api/buffer_spec.lua1276
-rw-r--r--test/functional/api/buffer_updates_spec.lua4
-rw-r--r--test/functional/api/command_spec.lua16
-rw-r--r--test/functional/api/extmark_spec.lua240
-rw-r--r--test/functional/api/highlight_spec.lua375
-rw-r--r--test/functional/api/keymap_spec.lua214
-rw-r--r--test/functional/api/proc_spec.lua12
-rw-r--r--test/functional/api/rpc_fixture.lua7
-rw-r--r--test/functional/api/server_notifications_spec.lua3
-rw-r--r--test/functional/api/server_requests_spec.lua19
-rw-r--r--test/functional/api/ui_spec.lua84
-rw-r--r--test/functional/api/version_spec.lua2
-rw-r--r--test/functional/api/vim_spec.lua876
-rw-r--r--test/functional/api/window_spec.lua354
-rw-r--r--test/functional/autocmd/autocmd_oldtest_spec.lua54
-rw-r--r--test/functional/autocmd/autocmd_spec.lua36
-rw-r--r--test/functional/autocmd/cursorhold_spec.lua6
-rw-r--r--test/functional/autocmd/cursormoved_spec.lua49
-rw-r--r--test/functional/autocmd/dirchanged_spec.lua4
-rw-r--r--test/functional/autocmd/focus_spec.lua5
-rw-r--r--test/functional/autocmd/modechanged_spec.lua39
-rw-r--r--test/functional/autocmd/safestate_spec.lua57
-rw-r--r--test/functional/autocmd/show_spec.lua41
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua12
-rw-r--r--test/functional/autocmd/termxx_spec.lua63
-rw-r--r--test/functional/autocmd/textchanged_spec.lua182
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua2
-rw-r--r--test/functional/autocmd/win_scrolled_resized_spec.lua3
-rw-r--r--test/functional/core/channels_spec.lua2
-rw-r--r--test/functional/core/exit_spec.lua38
-rw-r--r--test/functional/core/fileio_spec.lua108
-rw-r--r--test/functional/core/job_spec.lua41
-rw-r--r--test/functional/core/main_spec.lua29
-rw-r--r--test/functional/core/path_spec.lua114
-rw-r--r--test/functional/core/remote_spec.lua41
-rw-r--r--test/functional/core/spellfile_spec.lua26
-rw-r--r--test/functional/core/startup_spec.lua402
-rw-r--r--test/functional/editor/K_spec.lua2
-rw-r--r--test/functional/editor/completion_spec.lua127
-rw-r--r--test/functional/editor/fold_spec.lua140
-rw-r--r--test/functional/editor/jump_spec.lua42
-rw-r--r--test/functional/editor/mark_spec.lua87
-rw-r--r--test/functional/editor/mode_cmdline_spec.lua28
-rw-r--r--test/functional/editor/mode_insert_spec.lua85
-rw-r--r--test/functional/editor/put_spec.lua41
-rw-r--r--test/functional/ex_cmds/append_spec.lua3
-rw-r--r--test/functional/ex_cmds/cd_spec.lua9
-rw-r--r--test/functional/ex_cmds/cmd_map_spec.lua6
-rw-r--r--test/functional/ex_cmds/dict_notifications_spec.lua2
-rw-r--r--test/functional/ex_cmds/excmd_spec.lua37
-rw-r--r--test/functional/ex_cmds/file_spec.lua7
-rw-r--r--test/functional/ex_cmds/help_spec.lua17
-rw-r--r--test/functional/ex_cmds/highlight_spec.lua30
-rw-r--r--test/functional/ex_cmds/ls_spec.lua2
-rw-r--r--test/functional/ex_cmds/make_spec.lua12
-rw-r--r--test/functional/ex_cmds/map_spec.lua4
-rw-r--r--test/functional/ex_cmds/mksession_spec.lua20
-rw-r--r--test/functional/ex_cmds/mkview_spec.lua6
-rw-r--r--test/functional/ex_cmds/oldfiles_spec.lua5
-rw-r--r--test/functional/ex_cmds/profile_spec.lua13
-rw-r--r--test/functional/ex_cmds/script_spec.lua5
-rw-r--r--test/functional/ex_cmds/source_spec.lua130
-rw-r--r--test/functional/ex_cmds/swapfile_preserve_recover_spec.lua235
-rw-r--r--test/functional/ex_cmds/trust_spec.lua117
-rw-r--r--test/functional/ex_cmds/verbose_spec.lua25
-rw-r--r--test/functional/ex_cmds/write_spec.lua12
-rw-r--r--test/functional/ex_cmds/wviminfo_spec.lua8
-rw-r--r--test/functional/fixtures/api_level_11.mpackbin0 -> 31225 bytes
-rw-r--r--test/functional/fixtures/autoload/health/broken.vim3
-rw-r--r--test/functional/fixtures/autoload/health/full_render.vim8
-rw-r--r--test/functional/fixtures/autoload/health/success1.vim6
-rw-r--r--test/functional/fixtures/autoload/health/success2.vim4
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua74
-rw-r--r--test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim3
-rw-r--r--test/functional/fixtures/lua/test_plug/full_render/health.lua12
-rw-r--r--test/functional/fixtures/lua/test_plug/health/init.lua8
-rw-r--r--test/functional/fixtures/lua/test_plug/submodule/health.lua8
-rw-r--r--test/functional/fixtures/lua/test_plug/submodule_failed/health.lua11
-rw-r--r--test/functional/fixtures/lua/test_plug/success1/health.lua10
-rw-r--r--test/functional/fixtures/lua/test_plug/success2/health.lua8
-rw-r--r--test/functional/fixtures/printargs-test.c3
-rw-r--r--test/functional/fixtures/printenv-test.c3
-rw-r--r--test/functional/fixtures/shell-test.c3
-rw-r--r--test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua2
-rw-r--r--test/functional/fixtures/streams-test.c3
-rw-r--r--test/functional/fixtures/tty-test.c11
-rw-r--r--test/functional/fixtures/wildpum/Xnamedir/XdirA/XdirB/XfileC (renamed from test/functional/fixtures/wildpum/Xdir/XdirA/XdirB/XfileC)0
-rw-r--r--test/functional/fixtures/wildpum/Xnamedir/XdirA/XfileB (renamed from test/functional/fixtures/wildpum/Xdir/XdirA/XfileB)0
-rw-r--r--test/functional/fixtures/wildpum/Xnamedir/XfileA (renamed from test/functional/fixtures/wildpum/Xdir/XfileA)0
-rw-r--r--test/functional/helpers.lua102
-rw-r--r--test/functional/legacy/011_autocommands_spec.lua6
-rw-r--r--test/functional/legacy/012_directory_spec.lua28
-rw-r--r--test/functional/legacy/061_undo_tree_spec.lua17
-rw-r--r--test/functional/legacy/074_global_var_in_viminfo_spec.lua4
-rw-r--r--test/functional/legacy/088_conceal_tabs_spec.lua97
-rw-r--r--test/functional/legacy/assert_spec.lua8
-rw-r--r--test/functional/legacy/autochdir_spec.lua4
-rw-r--r--test/functional/legacy/autocmd_option_spec.lua148
-rw-r--r--test/functional/legacy/breakindent_spec.lua36
-rw-r--r--test/functional/legacy/buffer_spec.lua2
-rw-r--r--test/functional/legacy/cmdline_spec.lua25
-rw-r--r--test/functional/legacy/conceal_spec.lua587
-rw-r--r--test/functional/legacy/crash_spec.lua16
-rw-r--r--test/functional/legacy/debugger_spec.lua85
-rw-r--r--test/functional/legacy/delete_spec.lua2
-rw-r--r--test/functional/legacy/digraph_spec.lua6
-rw-r--r--test/functional/legacy/display_spec.lua190
-rw-r--r--test/functional/legacy/edit_spec.lua66
-rw-r--r--test/functional/legacy/eval_spec.lua10
-rw-r--r--test/functional/legacy/filechanged_spec.lua4
-rw-r--r--test/functional/legacy/glob2regpat_spec.lua8
-rw-r--r--test/functional/legacy/highlight_spec.lua (renamed from test/functional/legacy/051_highlight_spec.lua)34
-rw-r--r--test/functional/legacy/matchparen_spec.lua116
-rw-r--r--test/functional/legacy/memory_usage_spec.lua8
-rw-r--r--test/functional/legacy/messages_spec.lua119
-rw-r--r--test/functional/legacy/move_spec.lua49
-rw-r--r--test/functional/legacy/normal_spec.lua41
-rw-r--r--test/functional/legacy/options_spec.lua2
-rw-r--r--test/functional/legacy/prompt_buffer_spec.lua133
-rw-r--r--test/functional/legacy/put_spec.lua53
-rw-r--r--test/functional/legacy/scroll_opt_spec.lua1193
-rw-r--r--test/functional/legacy/search_spec.lua44
-rw-r--r--test/functional/legacy/search_stat_spec.lua64
-rw-r--r--test/functional/legacy/vimscript_spec.lua2
-rw-r--r--test/functional/legacy/visual_mode_spec.lua79
-rw-r--r--test/functional/legacy/visual_spec.lua69
-rw-r--r--test/functional/legacy/window_cmd_spec.lua110
-rw-r--r--test/functional/lua/api_spec.lua54
-rw-r--r--test/functional/lua/base64_spec.lua105
-rw-r--r--test/functional/lua/buffer_updates_spec.lua110
-rw-r--r--test/functional/lua/command_line_completion_spec.lua15
-rw-r--r--test/functional/lua/commands_spec.lua53
-rw-r--r--test/functional/lua/diagnostic_spec.lua102
-rw-r--r--test/functional/lua/ffi_spec.lua10
-rw-r--r--test/functional/lua/filetype_spec.lua37
-rw-r--r--test/functional/lua/fs_spec.lua58
-rw-r--r--test/functional/lua/help_spec.lua9
-rw-r--r--test/functional/lua/highlight_spec.lua2
-rw-r--r--test/functional/lua/inspector_spec.lua60
-rw-r--r--test/functional/lua/iter_spec.lua402
-rw-r--r--test/functional/lua/json_spec.lua111
-rw-r--r--test/functional/lua/loader_spec.lua56
-rw-r--r--test/functional/lua/loop_spec.lua18
-rw-r--r--test/functional/lua/luaeval_spec.lua18
-rw-r--r--test/functional/lua/overrides_spec.lua57
-rw-r--r--test/functional/lua/runtime_spec.lua216
-rw-r--r--test/functional/lua/secure_spec.lua27
-rw-r--r--test/functional/lua/snippet_spec.lua202
-rw-r--r--test/functional/lua/system_spec.lua100
-rw-r--r--test/functional/lua/text_spec.lua23
-rw-r--r--test/functional/lua/thread_spec.lua42
-rw-r--r--test/functional/lua/ui_event_spec.lua8
-rw-r--r--test/functional/lua/ui_spec.lua27
-rw-r--r--test/functional/lua/version_spec.lua273
-rw-r--r--test/functional/lua/vim_spec.lua487
-rw-r--r--test/functional/lua/watch_spec.lua178
-rw-r--r--test/functional/options/autochdir_spec.lua9
-rw-r--r--test/functional/options/cursorbind_spec.lua1
-rw-r--r--test/functional/options/defaults_spec.lua146
-rw-r--r--test/functional/options/keymap_spec.lua4
-rw-r--r--test/functional/options/mousescroll_spec.lua2
-rw-r--r--test/functional/options/num_options_spec.lua22
-rw-r--r--test/functional/options/pastetoggle_spec.lua90
-rw-r--r--test/functional/plugin/editorconfig_spec.lua19
-rw-r--r--test/functional/plugin/health_spec.lua131
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua239
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua159
-rw-r--r--test/functional/plugin/lsp/helpers.lua13
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua2
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua204
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua450
-rw-r--r--test/functional/plugin/lsp/snippet_spec.lua261
-rw-r--r--test/functional/plugin/lsp/utils_spec.lua226
-rw-r--r--test/functional/plugin/lsp/watchfiles_spec.lua222
-rw-r--r--test/functional/plugin/lsp_spec.lua1206
-rw-r--r--test/functional/plugin/man_spec.lua60
-rw-r--r--test/functional/plugin/shada_spec.lua34
-rw-r--r--test/functional/plugin/tutor_spec.lua95
-rw-r--r--test/functional/provider/clipboard_spec.lua6
-rw-r--r--test/functional/provider/perl_spec.lua9
-rw-r--r--test/functional/provider/provider_spec.lua2
-rw-r--r--test/functional/provider/ruby_spec.lua3
-rw-r--r--test/functional/shada/buffers_spec.lua8
-rw-r--r--test/functional/shada/helpers.lua1
-rw-r--r--test/functional/shada/history_spec.lua9
-rw-r--r--test/functional/shada/marks_spec.lua46
-rw-r--r--test/functional/shada/merging_spec.lua2
-rw-r--r--test/functional/shada/shada_spec.lua82
-rw-r--r--test/functional/terminal/api_spec.lua8
-rw-r--r--test/functional/terminal/buffer_spec.lua158
-rw-r--r--test/functional/terminal/channel_spec.lua96
-rw-r--r--test/functional/terminal/cursor_spec.lua71
-rw-r--r--test/functional/terminal/edit_spec.lua7
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua59
-rw-r--r--test/functional/terminal/helpers.lua9
-rw-r--r--test/functional/terminal/mouse_spec.lua78
-rw-r--r--test/functional/terminal/scrollback_spec.lua75
-rw-r--r--test/functional/terminal/tui_spec.lua923
-rw-r--r--test/functional/terminal/window_spec.lua45
-rw-r--r--test/functional/terminal/window_split_tab_spec.lua4
-rw-r--r--test/functional/treesitter/fold_spec.lua474
-rw-r--r--test/functional/treesitter/highlight_spec.lua291
-rw-r--r--test/functional/treesitter/language_spec.lua21
-rw-r--r--test/functional/treesitter/node_spec.lua28
-rw-r--r--test/functional/treesitter/parser_spec.lua573
-rw-r--r--test/functional/treesitter/utils_spec.lua17
-rw-r--r--test/functional/ui/bufhl_spec.lua11
-rw-r--r--test/functional/ui/cmdline_highlight_spec.lua17
-rw-r--r--test/functional/ui/cmdline_spec.lua181
-rw-r--r--test/functional/ui/cursor_spec.lua12
-rw-r--r--test/functional/ui/decorations_spec.lua3296
-rw-r--r--test/functional/ui/diff_spec.lua94
-rw-r--r--test/functional/ui/embed_spec.lua53
-rw-r--r--test/functional/ui/float_spec.lua3002
-rw-r--r--test/functional/ui/fold_spec.lua1306
-rw-r--r--test/functional/ui/highlight_spec.lua136
-rw-r--r--test/functional/ui/inccommand_spec.lua151
-rw-r--r--test/functional/ui/inccommand_user_spec.lua146
-rw-r--r--test/functional/ui/linematch_spec.lua230
-rw-r--r--test/functional/ui/messages_spec.lua190
-rw-r--r--test/functional/ui/mode_spec.lua22
-rw-r--r--test/functional/ui/mouse_spec.lua237
-rw-r--r--test/functional/ui/multibyte_spec.lua137
-rw-r--r--test/functional/ui/multigrid_spec.lua1608
-rw-r--r--test/functional/ui/options_spec.lua33
-rw-r--r--test/functional/ui/output_spec.lua7
-rw-r--r--test/functional/ui/popupmenu_spec.lua6213
-rw-r--r--test/functional/ui/quickfix_spec.lua2
-rw-r--r--test/functional/ui/screen.lua58
-rw-r--r--test/functional/ui/screen_basic_spec.lua217
-rw-r--r--test/functional/ui/searchhl_spec.lua111
-rw-r--r--test/functional/ui/sign_spec.lua44
-rw-r--r--test/functional/ui/spell_spec.lua366
-rw-r--r--test/functional/ui/statuscolumn_spec.lua536
-rw-r--r--test/functional/ui/statusline_spec.lua598
-rw-r--r--test/functional/ui/tabline_spec.lua73
-rw-r--r--test/functional/ui/title_spec.lua138
-rw-r--r--test/functional/ui/wildmode_spec.lua99
-rw-r--r--test/functional/ui/winbar_spec.lua66
-rw-r--r--test/functional/vimscript/api_functions_spec.lua50
-rw-r--r--test/functional/vimscript/buf_functions_spec.lua33
-rw-r--r--test/functional/vimscript/ctx_functions_spec.lua6
-rw-r--r--test/functional/vimscript/environ_spec.lua2
-rw-r--r--test/functional/vimscript/eval_spec.lua112
-rw-r--r--test/functional/vimscript/executable_spec.lua6
-rw-r--r--test/functional/vimscript/execute_spec.lua26
-rw-r--r--test/functional/vimscript/exepath_spec.lua43
-rw-r--r--test/functional/vimscript/glob_spec.lua7
-rw-r--r--test/functional/vimscript/has_spec.lua21
-rw-r--r--test/functional/vimscript/input_spec.lua36
-rw-r--r--test/functional/vimscript/json_functions_spec.lua2
-rw-r--r--test/functional/vimscript/let_spec.lua14
-rw-r--r--test/functional/vimscript/map_functions_spec.lua12
-rw-r--r--test/functional/vimscript/null_spec.lua12
-rw-r--r--test/functional/vimscript/screenpos_spec.lua50
-rw-r--r--test/functional/vimscript/special_vars_spec.lua6
-rw-r--r--test/functional/vimscript/state_spec.lua86
-rw-r--r--test/functional/vimscript/system_spec.lua16
-rw-r--r--test/functional/vimscript/timer_spec.lua10
-rw-r--r--test/functional/vimscript/writefile_spec.lua19
261 files changed, 32227 insertions, 7323 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua
index 22a1311ee9..fd46a1dcfa 100644
--- a/test/functional/api/autocmd_spec.lua
+++ b/test/functional/api/autocmd_spec.lua
@@ -14,14 +14,40 @@ before_each(clear)
describe('autocmd api', function()
describe('nvim_create_autocmd', function()
- it('"command" and "callback" are mutually exclusive', function()
- local rv = pcall_err(meths.create_autocmd, "BufReadPost", {
- pattern = "*.py,*.pyi",
+ it('validation', function()
+ eq("Cannot use both 'callback' and 'command'", pcall_err(meths.create_autocmd, 'BufReadPost', {
+ pattern = '*.py,*.pyi',
command = "echo 'Should Have Errored",
- callback = "NotAllowed",
- })
-
- eq("specify either 'callback' or 'command', not both", rv)
+ callback = 'NotAllowed',
+ }))
+ eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", pcall_err(meths.create_autocmd, 'FileType', {
+ command = 'let g:called = g:called + 1',
+ buffer = 0,
+ pattern = '*.py',
+ }))
+ eq("Required: 'event'", pcall_err(meths.create_autocmd, {}, {
+ command = 'ls',
+ }))
+ eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', {
+ }))
+ eq("Invalid 'desc': expected String, got Integer", pcall_err(meths.create_autocmd, 'FileType', {
+ command = 'ls',
+ desc = 42,
+ }))
+ eq("Invalid 'callback': expected Lua function or Vim function name, got Integer", pcall_err(meths.create_autocmd, 'FileType', {
+ callback = 0,
+ }))
+ eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd,
+ {'FileType', {}}, {}))
+ eq("Invalid 'group': 0", pcall_err(meths.create_autocmd, 'FileType', {
+ group = 0,
+ command = 'ls',
+ }))
+
+ eq("Invalid 'event': 'foo'", pcall_err(meths.create_autocmd, 'foo', { command = '' }))
+ eq("Invalid 'event': 'VimEnter '", pcall_err(meths.create_autocmd, 'VimEnter ', { command = '' }))
+ eq("Invalid 'event': 'VimEnter foo'", pcall_err(meths.create_autocmd, 'VimEnter foo', { command = '' }))
+ eq("Invalid 'event': 'BufAdd,BufDelete'", pcall_err(meths.create_autocmd, 'BufAdd,BufDelete', { command = '' }))
end)
it('doesnt leak when you use ++once', function()
@@ -59,18 +85,8 @@ describe('autocmd api', function()
eq(1, meths.get_var('called'))
end)
- it('does not allow passing buffer and patterns', function()
- local rv = pcall_err(meths.create_autocmd, "Filetype", {
- command = "let g:called = g:called + 1",
- buffer = 0,
- pattern = "*.py",
- })
-
- eq("cannot pass both: 'pattern' and 'buffer' for the same autocmd", rv)
- end)
-
it('does not allow passing invalid buffers', function()
- local ok, msg = pcall(meths.create_autocmd, "Filetype", {
+ local ok, msg = pcall(meths.create_autocmd, 'FileType', {
command = "let g:called = g:called + 1",
buffer = -1,
})
@@ -209,7 +225,7 @@ describe('autocmd api', function()
local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' })
local first = aus[1]
- eq(first.id, 1)
+ eq(true, first.id > 0)
meths.set_var("some_condition", true)
meths.exec_autocmds("User", {pattern = "Test"})
@@ -217,23 +233,28 @@ describe('autocmd api', function()
end)
it('receives an args table', function()
- local res = exec_lua [[
- local group_id = vim.api.nvim_create_augroup("TestGroup", {})
- local autocmd_id = vim.api.nvim_create_autocmd("User", {
+ local group_id = meths.create_augroup("TestGroup", {})
+ -- Having an existing autocmd calling expand("<afile>") shouldn't change args #18964
+ meths.create_autocmd('User', {
+ group = 'TestGroup',
+ pattern = 'Te*',
+ command = 'call expand("<afile>")',
+ })
+
+ local autocmd_id = exec_lua [[
+ return vim.api.nvim_create_autocmd("User", {
group = "TestGroup",
pattern = "Te*",
callback = function(args)
vim.g.autocmd_args = args
end,
})
-
- return {group_id, autocmd_id}
]]
meths.exec_autocmds("User", {pattern = "Test pattern"})
eq({
- id = res[2],
- group = res[1],
+ id = autocmd_id,
+ group = group_id,
event = "User",
match = "Test pattern",
file = "Test pattern",
@@ -241,27 +262,24 @@ describe('autocmd api', function()
}, meths.get_var("autocmd_args"))
-- Test without a group
- res = exec_lua [[
- local autocmd_id = vim.api.nvim_create_autocmd("User", {
+ autocmd_id = exec_lua [[
+ return vim.api.nvim_create_autocmd("User", {
pattern = "*",
callback = function(args)
vim.g.autocmd_args = args
end,
})
-
- return {autocmd_id}
]]
meths.exec_autocmds("User", {pattern = "some_pat"})
eq({
- id = res[1],
+ id = autocmd_id,
group = nil,
event = "User",
match = "some_pat",
file = "some_pat",
buf = 1,
}, meths.get_var("autocmd_args"))
-
end)
it('can receive arbitrary data', function()
@@ -294,8 +312,32 @@ describe('autocmd api', function()
end)
describe('nvim_get_autocmds', function()
+ it('validation', function()
+ eq("Invalid 'group': 9997999", pcall_err(meths.get_autocmds, {
+ group = 9997999,
+ }))
+ eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, {
+ group = 'bogus',
+ }))
+ eq("Invalid 'group': 0", pcall_err(meths.get_autocmds, {
+ group = 0,
+ }))
+ eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, {
+ group = {},
+ }))
+ eq("Invalid 'buffer': expected Integer or Array, got Boolean", pcall_err(meths.get_autocmds, {
+ buffer = true,
+ }))
+ eq("Invalid 'event': expected String or Array", pcall_err(meths.get_autocmds, {
+ event = true,
+ }))
+ eq("Invalid 'pattern': expected String or Array, got Boolean", pcall_err(meths.get_autocmds, {
+ pattern = true,
+ }))
+ end)
+
describe('events', function()
- it('should return one autocmd when there is only one for an event', function()
+ it('returns one autocmd when there is only one for an event', function()
command [[au! InsertEnter]]
command [[au InsertEnter * :echo "1"]]
@@ -303,7 +345,7 @@ describe('autocmd api', function()
eq(1, #aus)
end)
- it('should return two autocmds when there are two for an event', function()
+ it('returns two autocmds when there are two for an event', function()
command [[au! InsertEnter]]
command [[au InsertEnter * :echo "1"]]
command [[au InsertEnter * :echo "2"]]
@@ -312,7 +354,7 @@ describe('autocmd api', function()
eq(2, #aus)
end)
- it('should return the same thing if you use string or list', function()
+ it('returns the same thing if you use string or list', function()
command [[au! InsertEnter]]
command [[au InsertEnter * :echo "1"]]
command [[au InsertEnter * :echo "2"]]
@@ -322,7 +364,7 @@ describe('autocmd api', function()
eq(string_aus, array_aus)
end)
- it('should return two autocmds when there are two for an event', function()
+ it('returns two autocmds when there are two for an event', function()
command [[au! InsertEnter]]
command [[au! InsertLeave]]
command [[au InsertEnter * :echo "1"]]
@@ -332,7 +374,7 @@ describe('autocmd api', function()
eq(2, #aus)
end)
- it('should return different IDs for different autocmds', function()
+ it('returns different IDs for different autocmds', function()
command [[au! InsertEnter]]
command [[au! InsertLeave]]
command [[au InsertEnter * :echo "1"]]
@@ -356,7 +398,7 @@ describe('autocmd api', function()
eq(first, new_aus[1])
end)
- it('should return event name', function()
+ it('returns event name', function()
command [[au! InsertEnter]]
command [[au InsertEnter * :echo "1"]]
@@ -364,7 +406,7 @@ describe('autocmd api', function()
eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus)
end)
- it('should work with buffer numbers', function()
+ it('works with buffer numbers', function()
command [[new]]
command [[au! InsertEnter]]
command [[au InsertEnter <buffer=1> :echo "1"]]
@@ -407,8 +449,8 @@ describe('autocmd api', function()
pattern = "<buffer=2>",
}}, aus)
- eq("Invalid value for 'buffer': must be an integer or array of integers", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" }))
- eq("Invalid value for 'buffer': must be an integer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } }))
+ eq("Invalid 'buffer': expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" }))
+ eq("Invalid 'buffer': expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } }))
eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } }))
local bufs = {}
@@ -416,10 +458,10 @@ describe('autocmd api', function()
table.insert(bufs, meths.create_buf(true, false))
end
- eq("Too many buffers. Please limit yourself to 256 or fewer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs }))
+ eq("Too many buffers (maximum of 256)", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs }))
end)
- it('should return autocmds when group is specified by id', function()
+ it('returns autocmds when group is specified by id', function()
local auid = meths.create_augroup("nvim_test_augroup", { clear = true })
meths.create_autocmd("FileType", { group = auid, command = 'echo "1"' })
meths.create_autocmd("FileType", { group = auid, command = 'echo "2"' })
@@ -431,7 +473,7 @@ describe('autocmd api', function()
eq(0, #aus2)
end)
- it('should return autocmds when group is specified by name', function()
+ it('returns autocmds when group is specified by name', function()
local auname = "nvim_test_augroup"
meths.create_augroup(auname, { clear = true })
meths.create_autocmd("FileType", { group = auname, command = 'echo "1"' })
@@ -531,7 +573,7 @@ describe('autocmd api', function()
command [[augroup END]]
end)
- it('should return all groups if no group is specified', function()
+ it('returns all groups if no group is specified', function()
local aus = meths.get_autocmds { event = "InsertEnter" }
if #aus ~= 4 then
eq({}, aus)
@@ -540,7 +582,7 @@ describe('autocmd api', function()
eq(4, #aus)
end)
- it('should return only the group specified', function()
+ it('returns only the group specified', function()
local aus = meths.get_autocmds {
event = "InsertEnter",
group = "GroupOne",
@@ -551,7 +593,7 @@ describe('autocmd api', function()
eq("GroupOne", aus[1].group_name)
end)
- it('should return only the group specified, multiple values', function()
+ it('returns only the group specified, multiple values', function()
local aus = meths.get_autocmds {
event = "InsertEnter",
group = "GroupTwo",
@@ -578,7 +620,7 @@ describe('autocmd api', function()
]], {}))
eq(false, success)
- matches('invalid augroup: NotDefined', code)
+ matches("Invalid 'group': 'NotDefined'", code)
end)
it('raises error for undefined augroup id', function()
@@ -596,7 +638,7 @@ describe('autocmd api', function()
]], {}))
eq(false, success)
- matches('invalid augroup: 1', code)
+ matches("Invalid 'group': 1", code)
end)
it('raises error for invalid group type', function()
@@ -611,7 +653,7 @@ describe('autocmd api', function()
]], {}))
eq(false, success)
- matches("'group' must be a string or an integer", code)
+ matches("Invalid 'group': expected String or Integer, got Boolean", code)
end)
it('raises error for invalid pattern array', function()
@@ -625,7 +667,7 @@ describe('autocmd api', function()
]], {}))
eq(false, success)
- matches("All entries in 'pattern' must be strings", code)
+ matches("Invalid 'pattern' item: expected String, got Array", code)
end)
end)
@@ -640,7 +682,7 @@ describe('autocmd api', function()
command [[au InsertEnter <buffer> :echo "Buffer"]]
end)
- it('should should return for literal match', function()
+ it('returns for literal match', function()
local aus = meths.get_autocmds {
event = "InsertEnter",
pattern = "*"
@@ -650,7 +692,7 @@ describe('autocmd api', function()
eq([[:echo "No Group"]], aus[1].command)
end)
- it('should return for multiple matches', function()
+ it('returns for multiple matches', function()
-- vim.api.nvim_get_autocmds
local aus = meths.get_autocmds {
event = "InsertEnter",
@@ -687,6 +729,26 @@ describe('autocmd api', function()
end)
describe('nvim_exec_autocmds', function()
+ it('validation', function()
+ eq("Invalid 'group': 9997999", pcall_err(meths.exec_autocmds, 'FileType', {
+ group = 9997999,
+ }))
+ eq("Invalid 'group': 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', {
+ group = 'bogus',
+ }))
+ eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', {
+ group = {},
+ }))
+ eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', {
+ group = 0,
+ }))
+ eq("Invalid 'buffer': expected Buffer, got Array", pcall_err(meths.exec_autocmds, 'FileType', {
+ buffer = {},
+ }))
+ eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds,
+ {'FileType', {}}, {}))
+ end)
+
it("can trigger builtin autocmds", function()
meths.set_var("autocmd_executed", false)
@@ -1004,6 +1066,12 @@ describe('autocmd api', function()
eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]])
eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312))
+
+ eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 0)]])
+ eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 0))
+
+ eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 12342)]])
+ eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 12312))
end)
it('groups work with once', function()
@@ -1036,7 +1104,7 @@ describe('autocmd api', function()
local augroup = "WillBeDeleted"
meths.create_augroup(augroup, { clear = true })
- meths.create_autocmd({"Filetype"}, {
+ meths.create_autocmd({"FileType"}, {
pattern = "*",
command = "echo 'does not matter'",
})
@@ -1055,7 +1123,7 @@ describe('autocmd api', function()
meths.set_var("value_set", false)
meths.create_augroup(augroup, { clear = true })
- meths.create_autocmd("Filetype", {
+ meths.create_autocmd("FileType", {
pattern = "<buffer>",
command = "let g:value_set = v:true",
})
@@ -1171,6 +1239,17 @@ describe('autocmd api', function()
end)
describe('nvim_clear_autocmds', function()
+ it('validation', function()
+ eq("Cannot use both 'pattern' and 'buffer'", pcall_err(meths.clear_autocmds, {
+ pattern = '*',
+ buffer = 42,
+ }))
+ eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, {
+ event = {'FileType', {}}
+ }))
+ eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, {group = 0}))
+ end)
+
it('should clear based on event + pattern', function()
command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"')
command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"')
@@ -1254,7 +1333,7 @@ describe('autocmd api', function()
local without_group = meths.get_autocmds(search)
eq(2, #without_group)
- -- Doest clear with passing group.
+ -- Doesn't clear with passing group.
meths.clear_autocmds { buffer = 0, group = search.group }
local with_group = meths.get_autocmds(search)
eq(1, #with_group)
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 6b13729994..6ed9aa574a 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -16,6 +16,7 @@ local command = helpers.command
local bufmeths = helpers.bufmeths
local feed = helpers.feed
local pcall_err = helpers.pcall_err
+local assert_alive = helpers.assert_alive
describe('api/buf', function()
before_each(clear)
@@ -41,6 +42,14 @@ describe('api/buf', function()
eq(1, curbuf_depr('line_count'))
end)
+ it("doesn't crash just after set undolevels=1 #24894", function()
+ local buf = meths.create_buf(false, true)
+ meths.buf_set_option(buf, 'undolevels', -1)
+ meths.buf_set_lines(buf, 0, 1, false, { })
+
+ assert_alive()
+ end)
+
it('cursor position is maintained after lines are inserted #9961', function()
-- replace the buffer contents with these three lines.
request('nvim_buf_set_lines', 0, 0, -1, 1, {"line1", "line2", "line3", "line4"})
@@ -76,6 +85,38 @@ describe('api/buf', function()
eq({4, 2}, curwin('get_cursor'))
end)
+ it('cursor position is maintained in non-current window', function()
+ meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"})
+ meths.win_set_cursor(0, {3, 2})
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('new')
+
+ meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"})
+ eq({"line1", "line5", "line6", "line3", "line4"}, meths.buf_get_lines(buf, 0, -1, true))
+ eq({4, 2}, meths.win_get_cursor(win))
+ end)
+
+ it('cursor position is maintained in TWO non-current windows', function()
+ meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"})
+ meths.win_set_cursor(0, {3, 2})
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('split')
+ meths.win_set_cursor(0, {4, 2})
+ local win2 = meths.get_current_win()
+
+ -- set current window to third one with another buffer
+ command("new")
+
+ meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"})
+ eq({"line1", "line5", "line6", "line3", "line4"}, meths.buf_get_lines(buf, 0, -1, true))
+ eq({4, 2}, meths.win_get_cursor(win))
+ eq({5, 2}, meths.win_get_cursor(win2))
+ 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 = curbuf('get_number')
@@ -105,6 +146,285 @@ describe('api/buf', function()
-- it's impossible to get out-of-bounds errors for an unloaded buffer
eq({}, buffer('get_lines', bufnr, 8888, 9999, 1))
end)
+
+ describe('handles topline', function()
+ local screen
+ before_each(function()
+ 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()
+ meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
+ meths.set_option_value('modified', false, {})
+ end)
+
+ it('of current window', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('new | wincmd w')
+ meths.win_set_cursor(win, {8,0})
+
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] }|
+ |
+ ]]}
+
+ meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] [+] }|
+ |
+ ]]}
+
+ -- replacing topline keeps it the topline
+ meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ wwweeee |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] [+] }|
+ |
+ ]]}
+
+ -- inserting just before topline does not scroll up if cursor would be moved
+ meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ wwweeee |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] [+] }|
+ |
+ ]], unchanged=true}
+
+ meths.win_set_cursor(0, {7, 0})
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ wwweeee |
+ xxx |
+ ^yyy |
+ zzz |
+ {2:[No Name] [+] }|
+ |
+ ]]}
+
+ meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"})
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ mmmeeeee |
+ wwweeee |
+ xxx |
+ ^yyy |
+ {2:[No Name] [+] }|
+ |
+ ]]}
+ end)
+
+ it('of non-current window', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('new')
+ meths.win_set_cursor(win, {8,0})
+
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] }|
+ |
+ ]]}
+
+ meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+
+ -- replacing topline keeps it the topline
+ meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ wwweeee |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+
+ -- inserting just before topline scrolls up
+ meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ mmm |
+ wwweeee |
+ xxx |
+ yyy |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+ end)
+
+ it('of split windows with same buffer', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('split')
+ meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(0, {1,0})
+
+ screen:expect{grid=[[
+ ^aaa |
+ bbb |
+ ccc |
+ ddd |
+ www |
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] }|
+ |
+ ]]}
+ meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
+
+ screen:expect{grid=[[
+ ^aaabbb |
+ ccc |
+ ddd |
+ www |
+ xxx |
+ {2:[No Name] [+] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+
+ -- replacing topline keeps it the topline
+ meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
+ screen:expect{grid=[[
+ ^aaabbb |
+ ccc |
+ ddd |
+ wwweeee |
+ xxx |
+ {2:[No Name] [+] }|
+ wwweeee |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+
+ -- inserting just before topline scrolls up
+ meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
+ screen:expect{grid=[[
+ ^aaabbb |
+ ccc |
+ ddd |
+ mmm |
+ wwweeee |
+ {2:[No Name] [+] }|
+ mmm |
+ wwweeee |
+ xxx |
+ yyy |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+ end)
+ end)
+
+ it('handles clearing out non-current buffer #24911', function()
+ local buf = meths.get_current_buf()
+ meths.buf_set_lines(buf, 0, -1, true, {"aaa", "bbb", "ccc"})
+ command("new")
+
+ meths.buf_set_lines(0, 0, -1, true, {"xxx", "yyy", "zzz"})
+
+ meths.buf_set_lines(buf, 0, -1, true, {})
+ eq({"xxx", "yyy", "zzz"}, meths.buf_get_lines(0, 0, -1, true))
+ eq({''}, meths.buf_get_lines(buf, 0, -1, true))
+ end)
end)
describe('deprecated: {get,set,del}_line', function()
@@ -193,7 +513,7 @@ describe('api/buf', function()
it('fails correctly when input is not valid', function()
eq(1, api.curbufmeths.get_number())
- eq([[String cannot contain newlines]],
+ eq([['replacement string' item contains newlines]],
pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'}))
end)
@@ -393,6 +713,21 @@ describe('api/buf', function()
feed('<c-w>p')
eq(3, funcs.winnr())
end)
+
+ it('set_lines on unloaded buffer #8659 #22670', function()
+ local bufnr = curbuf('get_number')
+ meths.buf_set_lines(bufnr, 0, -1, false, {'a', 'b', 'c'})
+ meths.buf_set_name(bufnr, 'set_lines')
+ finally(function()
+ os.remove('set_lines')
+ end)
+ command('write!')
+ command('new')
+ command('bunload! '..bufnr)
+ local new_bufnr = funcs.bufnr('set_lines', true)
+ meths.buf_set_lines(new_bufnr, 0, -1, false, {})
+ eq({''}, meths.buf_get_lines(new_bufnr, 0, -1, false))
+ end)
end)
describe('nvim_buf_set_text', function()
@@ -437,6 +772,10 @@ describe('api/buf', function()
-- can append to a line
set_text(1, 4, -1, 4, {' and', 'more'})
eq({'goodbye bar', 'text and', 'more'}, get_lines(0, 3, true))
+
+ -- can use negative column numbers
+ set_text(0, -5, 0, -1, {'!'})
+ eq({'goodbye!'}, get_lines(0, 1, true))
end)
it('works with undo', function()
@@ -480,6 +819,754 @@ describe('api/buf', function()
eq({1, 9}, curwin('get_cursor'))
end)
+ it('updates the cursor position in non-current window', function()
+ insert([[
+ hello world!]])
+
+ -- position the cursor on `!`
+ meths.win_set_cursor(0, {1, 11})
+
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command("new")
+
+ -- replace 'world' with 'foo'
+ meths.buf_set_text(buf, 0, 6, 0, 11, {'foo'})
+ eq({'hello foo!'}, meths.buf_get_lines(buf, 0, -1, true))
+ -- cursor should be moved left by two columns (replacement is shorter by 2 chars)
+ eq({1, 9}, meths.win_get_cursor(win))
+ end)
+
+ it('updates the cursor position in TWO non-current windows', function()
+ insert([[
+ hello world!]])
+
+ -- position the cursor on `!`
+ meths.win_set_cursor(0, {1, 11})
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command("split")
+ local win2 = meths.get_current_win()
+ -- position the cursor on `w`
+ meths.win_set_cursor(0, {1, 6})
+
+ command("new")
+
+ -- replace 'hello' with 'foo'
+ meths.buf_set_text(buf, 0, 0, 0, 5, {'foo'})
+ eq({'foo world!'}, meths.buf_get_lines(buf, 0, -1, true))
+
+ -- both cursors should be moved left by two columns (replacement is shorter by 2 chars)
+ eq({1, 9}, meths.win_get_cursor(win))
+ eq({1, 4}, meths.win_get_cursor(win2))
+ end)
+
+ describe('when text is being added right at cursor position #22526', function()
+ it('updates the cursor position in NORMAL mode', function()
+ insert([[
+ abcd]])
+
+ -- position the cursor on 'c'
+ curwin('set_cursor', {1, 2})
+ -- add 'xxx' before 'c'
+ set_text(0, 2, 0, 2, {'xxx'})
+ eq({'abxxxcd'}, get_lines(0, -1, true))
+ -- cursor should be on 'c'
+ eq({1, 5}, curwin('get_cursor'))
+ end)
+
+ it('updates the cursor position only in non-current window when in INSERT mode', function()
+ insert([[
+ abcd]])
+
+ -- position the cursor on 'c'
+ curwin('set_cursor', {1, 2})
+ -- open vertical split
+ feed('<c-w>v')
+ -- get into INSERT mode to treat cursor
+ -- as being after 'b', not on 'c'
+ feed('i')
+ -- add 'xxx' between 'b' and 'c'
+ set_text(0, 2, 0, 2, {'xxx'})
+ eq({'abxxxcd'}, get_lines(0, -1, true))
+ -- in the current window cursor should stay after 'b'
+ eq({1, 2}, curwin('get_cursor'))
+ -- quit INSERT mode
+ feed('<esc>')
+ -- close current window
+ feed('<c-w>c')
+ -- in another window cursor should be on 'c'
+ eq({1, 5}, curwin('get_cursor'))
+ end)
+ end)
+
+ describe('when text is being deleted right at cursor position', function()
+ it('leaves cursor at the same position in NORMAL mode', function()
+ insert([[
+ abcd]])
+
+ -- position the cursor on 'b'
+ curwin('set_cursor', {1, 1})
+ -- delete 'b'
+ set_text(0, 1, 0, 2, {})
+ eq({'acd'}, get_lines(0, -1, true))
+ -- cursor is now on 'c'
+ eq({1, 1}, curwin('get_cursor'))
+ end)
+
+ it('leaves cursor at the same position in INSERT mode in current and non-current window', function()
+ insert([[
+ abcd]])
+
+ -- position the cursor on 'b'
+ curwin('set_cursor', {1, 1})
+ -- open vertical split
+ feed('<c-w>v')
+ -- get into INSERT mode to treat cursor
+ -- as being after 'a', not on 'b'
+ feed('i')
+ -- delete 'b'
+ set_text(0, 1, 0, 2, {})
+ eq({'acd'}, get_lines(0, -1, true))
+ -- cursor in the current window should stay after 'a'
+ eq({1, 1}, curwin('get_cursor'))
+ -- quit INSERT mode
+ feed('<esc>')
+ -- close current window
+ feed('<c-w>c')
+ -- cursor in non-current window should stay on 'c'
+ eq({1, 1}, curwin('get_cursor'))
+ end)
+ end)
+
+ describe('when cursor is inside replaced row range', function()
+ it('keeps cursor at the same position if cursor is at start_row, but before start_col', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on ' ' before 'first'
+ curwin('set_cursor', {1, 14})
+
+ set_text(0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay at the same position
+ eq({1, 14}, curwin('get_cursor'))
+ end)
+
+ it('keeps cursor at the same position if cursor is at start_row and column is still valid', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'f' in 'first'
+ curwin('set_cursor', {1, 15})
+
+ set_text(0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay at the same position
+ eq({1, 15}, curwin('get_cursor'))
+ end)
+
+ it('adjusts cursor column to keep it valid if start_row got smaller', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 't' in 'first'
+ curwin('set_cursor', {1, 19})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'This should be last' }, get_lines(0, -1, true))
+ -- cursor should end up on 't' in 'last'
+ eq({1, 18}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 18}, cursor)
+ end)
+
+ it('adjusts cursor column to keep it valid if start_row got smaller in INSERT mode', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 't' in 'first'
+ curwin('set_cursor', {1, 19})
+ -- enter INSERT mode to treat cursor as being after 't'
+ feed('a')
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'This should be last' }, get_lines(0, -1, true))
+ -- cursor should end up after 't' in 'last'
+ eq({1, 19}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 19}, cursor)
+ end)
+
+ it('adjusts cursor column to keep it valid in a row after start_row if it got smaller', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'w' in 'want'
+ curwin('set_cursor', {2, 31})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ '1',
+ 'then 2',
+ 'and then',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be 1',
+ 'then 2',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor column should end up at the end of a row
+ eq({2, 5}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 5}, cursor)
+ end)
+
+ it('adjusts cursor column to keep it valid in a row after start_row if it got smaller in INSERT mode', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'w' in 'want'
+ curwin('set_cursor', {2, 31})
+ -- enter INSERT mode
+ feed('a')
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ '1',
+ 'then 2',
+ 'and then',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be 1',
+ 'then 2',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor column should end up at the end of a row
+ eq({2, 6}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 6}, cursor)
+ end)
+
+ it('adjusts cursor line and column to keep it inside replacement range', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'n' in 'finally'
+ curwin('set_cursor', {3, 6})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up on 'y' in 'hopefully'
+ -- to stay in the range, because it got smaller
+ eq({2, 12}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 12}, cursor)
+ end)
+
+ it('adjusts cursor line and column if replacement is empty', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'r' in 'there'
+ curwin('set_cursor', {2, 8})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'This should be the last one' }, get_lines(0, -1, true))
+ -- cursor should end up on the next column after deleted range
+ eq({1, 15}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 15}, cursor)
+ end)
+
+ it('adjusts cursor line and column if replacement is empty and start_col == 0', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'r' in 'there'
+ curwin('set_cursor', {2, 8})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'finally the last one' }, get_lines(0, -1, true))
+ -- cursor should end up in column 0
+ eq({1, 0}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 0}, cursor)
+ end)
+
+ it('adjusts cursor column if replacement ends at cursor row, after cursor column', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'y' in 'finally'
+ curwin('set_cursor', {3, 10})
+ set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' })
+
+ eq({
+ 'This should be 1',
+ 'this 2',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up on 'n' in 'then'
+ eq({3, 7}, curwin('get_cursor'))
+ end)
+
+ it('adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'y' at 'finally'
+ curwin('set_cursor', {3, 10})
+ -- enter INSERT mode to treat cursor as being between 'l' and 'y'
+ feed('i')
+ set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' })
+
+ eq({
+ 'This should be 1',
+ 'this 2',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up after 'n' in 'then'
+ eq({3, 8}, curwin('get_cursor'))
+ end)
+
+ it('adjusts cursor column if replacement is inside of a single line', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'y' in 'finally'
+ curwin('set_cursor', {3, 10})
+ set_text(2, 4, 2, 11, { 'then' })
+
+ eq({
+ 'This should be first',
+ 'then there is a line we do not want',
+ 'and then the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up on 'n' in 'then'
+ eq({3, 7}, curwin('get_cursor'))
+ end)
+
+ it('does not move cursor column after end of a line', function()
+ insert([[
+ This should be the only line here
+ !!!]])
+
+ -- position cursor on the last '1'
+ curwin('set_cursor', {2, 2})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'This should be the only line here' }, get_lines(0, -1, true))
+ -- cursor should end up on '!'
+ eq({1, 32}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 32}, cursor)
+ end)
+
+ it('does not move cursor column before start of a line', function()
+ insert('\n!!!')
+
+ -- position cursor on the last '1'
+ curwin('set_cursor', {2, 2})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ '' }, get_lines(0, -1, true))
+ -- cursor should end up on '!'
+ eq({1, 0}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 0}, cursor)
+ end)
+
+ describe('with virtualedit', function()
+ it('adjusts cursor line and column to keep it inside replacement range if cursor is not after eol', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position cursor on 't' in 'want'
+ curwin('set_cursor', {2, 34})
+ -- turn on virtualedit
+ command('set virtualedit=all')
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up on 'y' in 'hopefully'
+ -- to stay in the range
+ eq({2, 12}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 12}, cursor)
+ -- coladd should be 0
+ eq(0, exec_lua([[
+ return vim.fn.winsaveview().coladd
+ ]]))
+ end)
+
+ it('does not change cursor screen column when cursor is after eol and row got shorter', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position cursor on 't' in 'want'
+ curwin('set_cursor', {2, 34})
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol
+ exec_lua([[
+ vim.fn.winrestview({ coladd = 5 })
+ ]])
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up at eol of a new row
+ eq({2, 26}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 26}, cursor)
+ -- coladd should be increased so that cursor stays in the same screen column
+ eq(13, exec_lua([[
+ return vim.fn.winsaveview().coladd
+ ]]))
+ end)
+
+ it('does not change cursor screen column when cursor is after eol and row got longer', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position cursor on 't' in 'first'
+ curwin('set_cursor', {1, 19})
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol
+ exec_lua([[
+ vim.fn.winrestview({ coladd = 21 })
+ ]])
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up at eol of a new row
+ eq({1, 38}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 38}, cursor)
+ -- coladd should be increased so that cursor stays in the same screen column
+ eq(2, exec_lua([[
+ return vim.fn.winsaveview().coladd
+ ]]))
+ end)
+
+ it('does not change cursor screen column when cursor is after eol and row extended past cursor column', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position cursor on 't' in 'first'
+ curwin('set_cursor', {1, 19})
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol just a bit
+ exec_lua([[
+ vim.fn.winrestview({ coladd = 3 })
+ ]])
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay at the same screen column
+ eq({1, 22}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 22}, cursor)
+ -- coladd should become 0
+ eq(0, exec_lua([[
+ return vim.fn.winsaveview().coladd
+ ]]))
+ end)
+
+ it('does not change cursor screen column when cursor is after eol and row range decreased', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and one more
+ and finally the last one]])
+
+ -- position cursor on 'e' in 'more'
+ curwin('set_cursor', {3, 11})
+ -- turn on virtualedit
+ command('set virtualedit=all')
+ -- move cursor after eol
+ exec_lua([[
+ vim.fn.winrestview({ coladd = 28 })
+ ]])
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 15, 3, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should end up at eol of a new row
+ eq({2, 26}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({2, 26}, cursor)
+ -- coladd should be increased so that cursor stays in the same screen column
+ eq(13, exec_lua([[
+ return vim.fn.winsaveview().coladd
+ ]]))
+ end)
+ end)
+ end)
+
+ describe('when cursor is at end_row and after end_col', function()
+ it('adjusts cursor column when only a newline is added or deleted', function()
+ insert([[
+ first line
+ second
+ line]])
+
+ -- position the cursor on 'i'
+ curwin('set_cursor', {3, 2})
+ set_text(1, 6, 2, 0, {})
+ eq({'first line', 'second line'}, get_lines(0, -1, true))
+ -- cursor should stay on 'i'
+ eq({2, 8}, curwin('get_cursor'))
+
+ -- add a newline back
+ set_text(1, 6, 1, 6, {'', ''})
+ eq({'first line', 'second', ' line'}, get_lines(0, -1, true))
+ -- cursor should return back to the original position
+ eq({3, 2}, curwin('get_cursor'))
+ end)
+
+ it('adjusts cursor column if the range is not bound to either start or end of a line', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 'h' in 'the'
+ curwin('set_cursor', {3, 13})
+ set_text(0, 14, 2, 11, {})
+ eq({'This should be the last one'}, get_lines(0, -1, true))
+ -- cursor should stay on 'h'
+ eq({1, 16}, curwin('get_cursor'))
+ -- add deleted lines back
+ set_text(0, 14, 0, 14, {
+ ' first',
+ 'then there is a line we do not want',
+ 'and finally',
+ })
+ eq({
+ 'This should be first',
+ 'then there is a line we do not want',
+ 'and finally the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should return back to the original position
+ eq({3, 13}, curwin('get_cursor'))
+ end)
+
+ it('adjusts cursor column if replacing lines in range, not just deleting and adding', function()
+ insert([[
+ This should be first
+ then there is a line we do not want
+ and finally the last one]])
+
+ -- position the cursor on 's' in 'last'
+ curwin('set_cursor', {3, 18})
+ set_text(0, 15, 2, 11, {
+ 'the line we do not want',
+ 'but hopefully',
+ })
+
+ eq({
+ 'This should be the line we do not want',
+ 'but hopefully the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should stay on 's'
+ eq({2, 20}, curwin('get_cursor'))
+
+ set_text(0, 15, 1, 13, {
+ 'first',
+ 'then there is a line we do not want',
+ 'and finally',
+ })
+
+ eq({
+ 'This should be first',
+ 'then there is a line we do not want',
+ 'and finally the last one',
+ }, get_lines(0, -1, true))
+ -- cursor should return back to the original position
+ eq({3, 18}, curwin('get_cursor'))
+ end)
+
+ it('does not move cursor column after end of a line', function()
+ insert([[
+ This should be the only line here
+ ]])
+
+ -- position cursor at the empty line
+ curwin('set_cursor', {2, 0})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 33, 1, 0, {'!'})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ 'This should be the only line here!' }, get_lines(0, -1, true))
+ -- cursor should end up on '!'
+ eq({1, 33}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 33}, cursor)
+ end)
+
+ it('does not move cursor column before start of a line', function()
+ insert('\n')
+
+ eq({ '', '' }, get_lines(0, -1, true))
+
+ -- position cursor on the last '1'
+ curwin('set_cursor', {2, 2})
+
+ local cursor = exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 0, 1, 0, {''})
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+
+ eq({ '' }, get_lines(0, -1, true))
+ -- cursor should end up on '!'
+ eq({1, 0}, curwin('get_cursor'))
+ -- immediate call to nvim_win_get_cursor should have returned the same position
+ eq({1, 0}, cursor)
+ end)
+ end)
+
it('can handle NULs', function()
set_text(0, 0, 0, 0, {'ab\0cd'})
eq('ab\0cd', curbuf_depr('get_line', 0))
@@ -553,20 +1640,20 @@ describe('api/buf', function()
insert([[
hello foo!
text]])
- eq('start_row out of bounds', pcall_err(set_text, 2, 0, 3, 0, {}))
- eq('start_row out of bounds', pcall_err(set_text, -3, 0, 0, 0, {}))
- eq('end_row out of bounds', pcall_err(set_text, 0, 0, 2, 0, {}))
- eq('end_row out of bounds', pcall_err(set_text, 0, 0, -3, 0, {}))
- eq('start_col out of bounds', pcall_err(set_text, 1, 5, 1, 5, {}))
- eq('end_col out of bounds', pcall_err(set_text, 1, 0, 1, 5, {}))
+ eq("Invalid 'start_row': out of range", pcall_err(set_text, 2, 0, 3, 0, {}))
+ eq("Invalid 'start_row': out of range", pcall_err(set_text, -3, 0, 0, 0, {}))
+ eq("Invalid 'end_row': out of range", pcall_err(set_text, 0, 0, 2, 0, {}))
+ eq("Invalid 'end_row': out of range", pcall_err(set_text, 0, 0, -3, 0, {}))
+ eq("Invalid 'start_col': out of range", pcall_err(set_text, 1, 5, 1, 5, {}))
+ eq("Invalid 'end_col': out of range", pcall_err(set_text, 1, 0, 1, 5, {}))
end)
it('errors when start is greater than end', function()
insert([[
hello foo!
text]])
- eq('start is higher than end', pcall_err(set_text, 1, 0, 0, 0, {}))
- eq('start is higher than end', pcall_err(set_text, 0, 1, 0, 0, {}))
+ eq("'start' is higher than 'end'", pcall_err(set_text, 1, 0, 0, 0, {}))
+ eq("'start' is higher than 'end'", pcall_err(set_text, 0, 1, 0, 0, {}))
end)
it('no heap-use-after-free when called consecutively #19643', function()
@@ -579,6 +1666,139 @@ describe('api/buf', function()
]])
eq({'one', 'two'}, get_lines(0, 2, true))
end)
+
+ describe('handles topline', function()
+ local screen
+ before_each(function()
+ 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()
+ meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
+ meths.set_option_value('modified', false, {})
+ end)
+
+ it('of current window', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('new | wincmd w')
+ meths.win_set_cursor(win, {8,0})
+
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] }|
+ |
+ ]]}
+ meths.buf_set_text(buf, 0,3, 1,0, {"X"})
+
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ ^zzz |
+ {2:[No Name] [+] }|
+ |
+ ]]}
+ end)
+
+ it('of non-current window', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('new')
+ meths.win_set_cursor(win, {8,0})
+
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] }|
+ |
+ ]]}
+
+ meths.buf_set_text(buf, 0,3, 1,0, {"X"})
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+ end)
+
+ it('of split windows with same buffer', function()
+ local win = meths.get_current_win()
+ local buf = meths.get_current_buf()
+
+ command('split')
+ meths.win_set_cursor(win, {8,0})
+ meths.win_set_cursor(0, {1,1})
+
+ screen:expect{grid=[[
+ a^aa |
+ bbb |
+ ccc |
+ ddd |
+ www |
+ {2:[No Name] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] }|
+ |
+ ]]}
+ meths.buf_set_text(buf, 0,3, 1,0, {"X"})
+
+ screen:expect{grid=[[
+ a^aaXbbb |
+ ccc |
+ ddd |
+ www |
+ xxx |
+ {2:[No Name] [+] }|
+ www |
+ xxx |
+ yyy |
+ zzz |
+ {3:[No Name] [+] }|
+ |
+ ]]}
+ end)
+ end)
end)
describe_lua_and_rpc('nvim_buf_get_text', function(api)
@@ -611,7 +1831,7 @@ describe('api/buf', function()
end)
it('errors when start is greater than end', function()
- eq('start is higher than end', pcall_err(get_text, 1, 0, 0, 0, {}))
+ eq("'start' is higher than 'end'", pcall_err(get_text, 1, 0, 0, 0, {}))
eq('start_col must be less than end_col', pcall_err(get_text, 0, 1, 0, 0, {}))
end)
end)
@@ -630,19 +1850,19 @@ describe('api/buf', function()
eq('Index out of bounds', pcall_err(get_offset, 6))
eq('Index out of bounds', pcall_err(get_offset, -1))
- curbufmeths.set_option('eol', false)
- curbufmeths.set_option('fixeol', false)
+ meths.set_option_value('eol', false, {})
+ meths.set_option_value('fixeol', false, {})
eq(28, get_offset(5))
-- fileformat is ignored
- curbufmeths.set_option('fileformat', 'dos')
+ meths.set_option_value('fileformat', 'dos', {})
eq(0, get_offset(0))
eq(6, get_offset(1))
eq(15, get_offset(2))
eq(16, get_offset(3))
eq(24, get_offset(4))
eq(28, get_offset(5))
- curbufmeths.set_option('eol', true)
+ meths.set_option_value('eol', true, {})
eq(29, get_offset(5))
command("set hidden")
@@ -650,6 +1870,18 @@ describe('api/buf', function()
eq(6, bufmeths.get_offset(1,1))
command("bunload! 1")
eq(-1, bufmeths.get_offset(1,1))
+ eq(-1, bufmeths.get_offset(1,0))
+ end)
+
+ it('works in empty buffer', function()
+ eq(0, get_offset(0))
+ eq(1, get_offset(1))
+ end)
+
+ it('works in buffer with one line inserted', function()
+ feed('itext')
+ eq(0, get_offset(0))
+ eq(5, get_offset(1))
end)
end)
@@ -697,23 +1929,23 @@ describe('api/buf', function()
end)
end)
- describe('nvim_buf_get_option, nvim_buf_set_option', function()
+ describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function()
- eq(8, curbuf('get_option', 'shiftwidth'))
- curbuf('set_option', 'shiftwidth', 4)
- eq(4, curbuf('get_option', 'shiftwidth'))
+ eq(8, nvim('get_option_value', 'shiftwidth', {}))
+ nvim('set_option_value', 'shiftwidth', 4, {})
+ eq(4, nvim('get_option_value', 'shiftwidth', {}))
-- global-local option
- curbuf('set_option', 'define', 'test')
- eq('test', curbuf('get_option', 'define'))
+ nvim('set_option_value', 'define', 'test', {buf = 0})
+ eq('test', nvim('get_option_value', 'define', {buf = 0}))
-- Doesn't change the global value
- eq([[^\s*#\s*define]], nvim('get_option', 'define'))
+ eq("", nvim('get_option_value', 'define', {scope='global'}))
end)
it('returns values for unset local options', function()
-- 'undolevels' is only set to its "unset" value when a new buffer is
-- created
command('enew')
- eq(-123456, curbuf('get_option', 'undolevels'))
+ eq(-123456, nvim('get_option_value', 'undolevels', {buf=0}))
end)
end)
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index d5f06c8f1f..80e29c1ff2 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -75,7 +75,7 @@ local function reopenwithfolds(b)
local tick = reopen(b, origlines)
-- use markers for folds, make all folds open by default
- command('setlocal foldmethod=marker foldlevel=20')
+ command('setlocal foldmethod=marker foldlevel=20 commentstring=/*%s*/')
-- add a fold
command('2,4fold')
@@ -762,7 +762,7 @@ describe('API: buffer events:', function()
it('returns a proper error on nonempty options dict', function()
clear()
local b = editoriginal(false)
- eq("unexpected key: builtin", pcall_err(buffer, 'attach', b, false, {builtin="asfd"}))
+ eq("Invalid 'opts' key: 'builtin'", pcall_err(buffer, 'attach', b, false, {builtin="asfd"}))
end)
it('nvim_buf_attach returns response after delay #8634', function()
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index d0fb26edc7..1ddb289ded 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -24,7 +24,7 @@ describe('nvim_get_commands', function()
eq({}, meths.get_commands({builtin=false}))
end)
- it('validates input', function()
+ it('validation', function()
eq('builtin=true not implemented', pcall_err(meths.get_commands,
{builtin=true}))
eq("Invalid key: 'foo'", pcall_err(meths.get_commands,
@@ -543,23 +543,19 @@ describe('nvim_create_user_command', function()
end)
it('does not allow invalid command names', function()
- matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[
+ eq("Invalid command name (must start with uppercase): 'test'", pcall_err(exec_lua, [[
vim.api.nvim_create_user_command('test', 'echo "hi"', {})
]]))
-
- matches('Invalid command name', pcall_err(exec_lua, [[
+ eq("Invalid command name: 't@'", pcall_err(exec_lua, [[
vim.api.nvim_create_user_command('t@', 'echo "hi"', {})
]]))
-
- matches('Invalid command name', pcall_err(exec_lua, [[
+ eq("Invalid command name: 'T@st'", pcall_err(exec_lua, [[
vim.api.nvim_create_user_command('T@st', 'echo "hi"', {})
]]))
-
- matches('Invalid command name', pcall_err(exec_lua, [[
+ eq("Invalid command name: 'Test!'", pcall_err(exec_lua, [[
vim.api.nvim_create_user_command('Test!', 'echo "hi"', {})
]]))
-
- matches('Invalid command name', pcall_err(exec_lua, [[
+ eq("Invalid command name: '💩'", pcall_err(exec_lua, [[
vim.api.nvim_create_user_command('💩', 'echo "hi"', {})
]]))
end)
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 00f5b25b8a..44a151cf6a 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -11,6 +11,7 @@ local insert = helpers.insert
local feed = helpers.feed
local clear = helpers.clear
local command = helpers.command
+local exec = helpers.exec
local meths = helpers.meths
local assert_alive = helpers.assert_alive
@@ -101,12 +102,31 @@ describe('API/extmarks', function()
ns2 = request('nvim_create_namespace', "my-fancy-plugin2")
end)
+ it('validation', function()
+ eq("Invalid 'end_col': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 }))
+ eq("Invalid 'end_row': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} }))
+ eq("Invalid 'virt_text_pos': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 }))
+ eq("Invalid 'virt_text_pos': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' }))
+ eq("Invalid 'hl_mode': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 }))
+ eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' }))
+ eq("Invalid 'id': expected Integer, got Array", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 }))
+ eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1}))
+ eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1}))
+ -- No memory leak with virt_text, virt_lines, sign_text
+ eq("right_gravity is not a boolean", pcall_err(set_extmark, ns, marks[2], 0, 0, {
+ virt_text = {{'foo', 'Normal'}},
+ virt_lines = {{{'bar', 'Normal'}}},
+ sign_text = 'a',
+ right_gravity = 'baz',
+ }))
+ end)
+
it("can end extranges past final newline using end_col = 0", function()
set_extmark(ns, marks[1], 0, 0, {
end_col = 0,
end_row = 1
})
- eq("end_col value outside range",
+ eq("Invalid 'end_col': out of range",
pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 }))
end)
@@ -188,6 +208,23 @@ describe('API/extmarks', function()
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
end)
+ it('can undo with extmarks (#25147)', function()
+ feed('itest<esc>')
+ set_extmark(ns, 1, 0, 0)
+ set_extmark(ns, 2, 1, 0)
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ feed('dd')
+ eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ curbufmeths.clear_namespace(ns, 0, -1)
+ eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
+ set_extmark(ns, 1, 0, 0, { right_gravity = false })
+ set_extmark(ns, 2, 1, 0, { right_gravity = false })
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ feed('u')
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ curbufmeths.clear_namespace(ns, 0, -1)
+ end)
+
it('querying for information and ranges', function()
--marks = {1, 2, 3}
--positions = {{0, 0,}, {0, 2}, {0, 3}}
@@ -733,7 +770,14 @@ describe('API/extmarks', function()
})
end)
- -- TODO(bfredl): add more tests!
+ it('can get overlapping extmarks', function()
+ set_extmark(ns, 1, 0, 0, {end_row = 5, end_col=0})
+ set_extmark(ns, 2, 2, 5, {end_row = 2, end_col=30})
+ set_extmark(ns, 3, 0, 5, {end_row = 2, end_col=10})
+ set_extmark(ns, 4, 0, 0, {end_row = 1, end_col=0})
+ eq({{ 2, 2, 5 }}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=false }))
+ eq({{ 1, 0, 0 }, { 3, 0, 5}, {2, 2, 5}}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=true }))
+ end)
end)
it('replace works', function()
@@ -1344,10 +1388,10 @@ describe('API/extmarks', function()
it('throws consistent error codes', function()
local ns_invalid = ns2 + 1
- eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
- eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
- eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
- eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
+ eq("Invalid 'ns_id': 3", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
+ eq("Invalid 'ns_id': 3", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
+ eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
+ eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end)
it('when col = line-length, set the mark on eol', function()
@@ -1362,13 +1406,13 @@ describe('API/extmarks', function()
it('when col = line-length, set the mark on eol', function()
local invalid_col = init_text:len() + 1
- eq("col value outside range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col))
+ eq("Invalid 'col': out of range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col))
end)
it('fails when line > line_count', function()
local invalid_col = init_text:len() + 1
local invalid_lnum = 3
- eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
+ eq("Invalid 'line': out of range", pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
eq({}, get_extmark_by_id(ns, marks[1]))
end)
@@ -1385,7 +1429,7 @@ describe('API/extmarks', function()
it('in read-only buffer', function()
command("view! runtime/doc/help.txt")
- eq(true, curbufmeths.get_option('ro'))
+ eq(true, meths.get_option_value('ro', {}))
local id = set_extmark(ns, 0, 0, 2)
eq({{id, 0, 2}}, get_extmarks(ns,0, -1))
end)
@@ -1398,12 +1442,12 @@ describe('API/extmarks', function()
end)
it('does not crash with append/delete/undo sequence', function()
- meths.exec([[
+ exec([[
let ns = nvim_create_namespace('myplugin')
call nvim_buf_set_extmark(0, ns, 0, 0, {})
call append(0, '')
%delete
- undo]],false)
+ undo]])
assert_alive()
end)
@@ -1435,7 +1479,7 @@ describe('API/extmarks', function()
feed('u')
-- handles pasting
- meths.exec([[let @a='asdfasdf']], false)
+ exec([[let @a='asdfasdf']])
feed([["ap]])
eq({ {1, 0, 0}, {2, 0, 8} },
meths.buf_get_extmarks(0, ns, 0, -1, {}))
@@ -1447,6 +1491,7 @@ describe('API/extmarks', function()
end_line = 1
})
eq({ {1, 0, 0, {
+ ns_id = 1,
end_col = 0,
end_row = 1,
right_gravity = true,
@@ -1454,52 +1499,187 @@ describe('API/extmarks', function()
}} }, get_extmarks(ns, 0, -1, {details=true}))
end)
+ it('in prompt buffer', function()
+ feed('dd')
+ local id = set_extmark(ns, marks[1], 0, 0, {})
+ meths.set_option_value('buftype', 'prompt', {})
+ feed('i<esc>')
+ eq({{id, 0, 2}}, get_extmarks(ns, 0, -1))
+ end)
+
it('can get details', function()
set_extmark(ns, marks[1], 0, 0, {
+ conceal = "c",
+ cursorline_hl_group = "Statement",
end_col = 0,
- end_row = 1,
- right_gravity = false,
end_right_gravity = true,
- priority = 0,
+ end_row = 1,
hl_eol = true,
- hl_mode = "blend",
hl_group = "String",
- virt_text = { { "text", "Statement" } },
- virt_text_pos = "right_align",
- virt_text_hide = true,
- virt_lines = { { { "lines", "Statement" } }},
+ hl_mode = "blend",
+ line_hl_group = "Statement",
+ number_hl_group = "Statement",
+ priority = 0,
+ right_gravity = false,
+ sign_hl_group = "Statement",
+ sign_text = ">>",
+ spell = true,
+ virt_lines = {
+ { { "lines", "Macro" }, { "???" } },
+ { { "stack", { "Type", "Search" } }, { "!!!" } },
+ },
virt_lines_above = true,
virt_lines_leftcol = true,
+ virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } },
+ virt_text_hide = true,
+ virt_text_pos = "right_align",
})
set_extmark(ns, marks[2], 0, 0, {
priority = 0,
- virt_text = { { "text", "Statement" } },
+ virt_text = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } },
virt_text_win_col = 1,
})
eq({0, 0, {
+ conceal = "c",
+ cursorline_hl_group = "Statement",
end_col = 0,
- end_row = 1,
- right_gravity = false,
end_right_gravity = true,
- priority = 0,
+ end_row = 1,
hl_eol = true,
- hl_mode = "blend",
hl_group = "String",
- virt_text = { { "text", "Statement" } },
- virt_text_pos = "right_align",
- virt_text_hide = true,
- virt_lines = { { { "lines", "Statement" } }},
+ hl_mode = "blend",
+ line_hl_group = "Statement",
+ ns_id = 1,
+ number_hl_group = "Statement",
+ priority = 0,
+ right_gravity = false,
+ sign_hl_group = "Statement",
+ sign_text = ">>",
+ spell = true,
+ virt_lines = {
+ { { "lines", "Macro" }, { "???" } },
+ { { "stack", { "Type", "Search" } }, { "!!!" } },
+ },
virt_lines_above = true,
virt_lines_leftcol = true,
+ virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } },
+ virt_text_hide = true,
+ virt_text_pos = "right_align",
} }, get_extmark_by_id(ns, marks[1], { details = true }))
eq({0, 0, {
+ ns_id = 1,
right_gravity = true,
priority = 0,
- virt_text = { { "text", "Statement" } },
+ virt_text = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } },
virt_text_hide = false,
virt_text_pos = "win_col",
virt_text_win_col = 1,
} }, get_extmark_by_id(ns, marks[2], { details = true }))
+ set_extmark(ns, marks[3], 0, 0, { cursorline_hl_group = "Statement" })
+ eq({0, 0, {
+ ns_id = 1,
+ cursorline_hl_group = "Statement",
+ priority = 4096,
+ right_gravity = true,
+ } }, get_extmark_by_id(ns, marks[3], { details = true }))
+ curbufmeths.clear_namespace(ns, 0, -1)
+ -- legacy sign mark includes sign name
+ command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
+ command('sign place 1 name=sign1 line=1')
+ eq({ {1, 0, 0, {
+ cursorline_hl_group = 'CursorLine',
+ invalidate = true,
+ line_hl_group = 'LineNr',
+ ns_id = 0,
+ number_hl_group = 'Normal',
+ priority = 10,
+ right_gravity = true,
+ sign_hl_group = 'Title',
+ sign_name = 'sign1',
+ sign_text = 's1',
+ undo_restore = false
+ } } }, get_extmarks(-1, 0, -1, { details = true }))
+ end)
+
+ it('can get marks from anonymous namespaces', function()
+ ns = request('nvim_create_namespace', "")
+ ns2 = request('nvim_create_namespace', "")
+ set_extmark(ns, 1, 0, 0, {})
+ set_extmark(ns2, 2, 1, 0, {})
+ eq({{ 1, 0, 0, { ns_id = ns, right_gravity = true }},
+ { 2, 1, 0, { ns_id = ns2, right_gravity = true }}},
+ get_extmarks(-1, 0, -1, { details = true }))
+ end)
+
+ it('can filter by extmark properties', function()
+ set_extmark(ns, 1, 0, 0, {})
+ set_extmark(ns, 2, 0, 0, { hl_group = 'Normal' })
+ set_extmark(ns, 3, 0, 0, { sign_text = '>>' })
+ set_extmark(ns, 4, 0, 0, { virt_text = {{'text', 'Normal'}}})
+ set_extmark(ns, 5, 0, 0, { virt_lines = {{{ 'line', 'Normal' }}}})
+ eq(5, #get_extmarks(-1, 0, -1, {}))
+ eq({{ 2, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'highlight' }))
+ eq({{ 3, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'sign' }))
+ eq({{ 4, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_text' }))
+ eq({{ 5, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_lines' }))
+ end)
+
+ it("invalidated marks are deleted", function()
+ screen = Screen.new(40, 6)
+ screen:attach()
+ feed('dd6iaaa bbb ccc<CR><ESC>gg')
+ set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1' })
+ set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2' })
+ -- mark with invalidate is removed
+ command('d')
+ screen:expect([[
+ S2^aaa bbb ccc |
+ aaa bbb ccc |
+ aaa bbb ccc |
+ aaa bbb ccc |
+ aaa bbb ccc |
+ |
+ ]])
+ -- mark is restored with undo_restore == true
+ command('silent undo')
+ screen:expect([[
+ S1^aaa bbb ccc |
+ S2aaa bbb ccc |
+ aaa bbb ccc |
+ aaa bbb ccc |
+ aaa bbb ccc |
+ |
+ ]])
+ -- mark is deleted with undo_restore == false
+ set_extmark(ns, 1, 0, 0, { invalidate = true, undo_restore = false, sign_text = 'S1' })
+ set_extmark(ns, 2, 1, 0, { invalidate = true, undo_restore = false, sign_text = 'S2' })
+ command('1d 2')
+ eq(0, #get_extmarks(-1, 0, -1, {}))
+ -- mark is not removed when deleting bytes before the range
+ set_extmark(ns, 3, 0, 4, { invalidate = true, undo_restore = false,
+ hl_group = 'Error', end_col = 7 })
+ feed('dw')
+ eq(3, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
+ -- mark is not removed when deleting bytes at the start of the range
+ feed('x')
+ eq(2, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
+ -- mark is not removed when deleting bytes from the end of the range
+ feed('lx')
+ eq(1, get_extmark_by_id(ns, 3, { details = true})[3].end_col)
+ -- mark is not removed when deleting bytes beyond end of the range
+ feed('x')
+ eq(1, get_extmark_by_id(ns, 3, { details = true})[3].end_col)
+ -- mark is removed when all bytes in the range are deleted
+ feed('hx')
+ eq({}, get_extmark_by_id(ns, 3, {}))
+ -- multiline mark is not removed when start of its range is deleted
+ set_extmark(ns, 4, 1, 4, { undo_restore = false, invalidate = true,
+ hl_group = 'Error', end_col = 7, end_row = 3 })
+ feed('ddDdd')
+ eq({0, 0}, get_extmark_by_id(ns, 4, {}))
+ -- multiline mark is removed when entirety of its range is deleted
+ feed('vj2ed')
+ eq({}, get_extmark_by_id(ns, 4, {}))
end)
end)
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 5941d4c68b..7d7d07e30e 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -57,9 +57,7 @@ describe('API: highlight',function()
eq(expected_rgb, nvim("get_hl_by_id", hl_id, true))
-- Test invalid id.
- local err, emsg = pcall(meths.get_hl_by_id, 30000, false)
- eq(false, err)
- eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: 30000', pcall_err(meths.get_hl_by_id, 30000, false))
-- Test all highlight properties.
command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
@@ -70,22 +68,14 @@ describe('API: highlight',function()
eq(expected_undercurl, nvim("get_hl_by_id", hl_id, true))
-- Test nil argument.
- err, emsg = pcall(meths.get_hl_by_id, { nil }, false)
- eq(false, err)
eq('Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer',
- string.match(emsg, 'Wrong.*'))
+ pcall_err(meths.get_hl_by_id, { nil }, false))
-- Test 0 argument.
- err, emsg = pcall(meths.get_hl_by_id, 0, false)
- eq(false, err)
- eq('Invalid highlight id: 0',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false))
-- Test -1 argument.
- err, emsg = pcall(meths.get_hl_by_id, -1, false)
- eq(false, err)
- eq('Invalid highlight id: -1',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: -1', pcall_err(meths.get_hl_by_id, -1, false))
-- Test highlight group without ctermbg value.
command('hi Normal ctermfg=red ctermbg=yellow')
@@ -119,22 +109,16 @@ describe('API: highlight',function()
eq(expected_normal, nvim("get_hl_by_name", 'Normal', true))
-- Test invalid name.
- local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false)
- eq(false, err)
- eq('Invalid highlight name: unknown_highlight',
- string.match(emsg, 'Invalid.*'))
+ eq("Invalid highlight name: 'unknown_highlight'",
+ pcall_err(meths.get_hl_by_name , 'unknown_highlight', false))
-- Test nil argument.
- err, emsg = pcall(meths.get_hl_by_name , { nil }, false)
- eq(false, err)
eq('Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String',
- string.match(emsg, 'Wrong.*'))
+ pcall_err(meths.get_hl_by_name , { nil }, false))
-- Test empty string argument.
- err, emsg = pcall(meths.get_hl_by_name , '', false)
- eq(false, err)
- eq('Invalid highlight name: ',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight name',
+ pcall_err(meths.get_hl_by_name , '', false))
-- Test "standout" attribute. #8054
eq({ underline = true, },
@@ -155,7 +139,7 @@ describe('API: highlight',function()
it('nvim_get_hl_id_by_name', function()
-- precondition: use a hl group that does not yet exist
- eq('Invalid highlight name: Shrubbery', pcall_err(meths.get_hl_by_name, "Shrubbery", true))
+ eq("Invalid highlight name: 'Shrubbery'", pcall_err(meths.get_hl_by_name, "Shrubbery", true))
eq(0, funcs.hlID("Shrubbery"))
local hl_id = meths.get_hl_id_by_name("Shrubbery")
@@ -171,9 +155,9 @@ describe('API: highlight',function()
it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function()
command('vsplit file')
- local err, _ = pcall(meths.buf_set_option, 1, 'undofile', false)
+ local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 })
eq(true, err)
- err, _ = pcall(meths.buf_set_option, 1, 'undolevels', -1)
+ err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 })
eq(true, err)
err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1)
eq(true, err)
@@ -214,7 +198,7 @@ describe("API: set highlight", function()
bold = true,
italic = true,
reverse = true,
- underline = true,
+ underdashed = true,
strikethrough = true,
altfont = true,
cterm = {
@@ -231,7 +215,7 @@ describe("API: set highlight", function()
bold = true,
italic = true,
reverse = true,
- underline = true,
+ underdashed = true,
strikethrough = true,
altfont = true,
}
@@ -253,25 +237,32 @@ describe("API: set highlight", function()
before_each(clear)
- it ("can set gui highlight", function()
+ it('validation', function()
+ eq("Invalid 'blend': out of range",
+ pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend=999}))
+ eq("Invalid 'blend': expected Integer, got Array",
+ pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend={}}))
+ end)
+
+ it("can set gui highlight", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.get_hl_by_name('Test_hl', true))
end)
- it ("can set cterm highlight", function()
+ it("can set cterm highlight", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight2_config)
eq(highlight2_result, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can set empty cterm attr", function()
+ it("can set empty cterm attr", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.get_hl_by_name('Test_hl', false))
end)
- it ("cterm attr defaults to gui attr", function()
+ it("cterm attr defaults to gui attr", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight1)
eq({
@@ -280,14 +271,28 @@ describe("API: set highlight", function()
}, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can overwrite attr for cterm", function()
+ it("can overwrite attr for cterm", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result_gui, meths.get_hl_by_name('Test_hl', true))
eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can set a highlight in the global namespace", function()
+ it("only allows one underline attribute #22371", function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', {
+ underdouble = true,
+ underdotted = true,
+ cterm = {
+ underline = true,
+ undercurl = true,
+ },
+ })
+ eq({ undercurl = true }, meths.get_hl_by_name('Test_hl', false))
+ eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true))
+ end)
+
+ it("can set a highlight in the global namespace", function()
meths.set_hl(0, 'Test_hl', highlight2_config)
eq('Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse',
exec_capture('highlight Test_hl'))
@@ -297,7 +302,7 @@ describe("API: set highlight", function()
exec_capture('highlight Test_hl'))
meths.set_hl(0, 'Test_hl2', highlight3_config)
- eq('Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underline,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa',
+ eq('Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa',
exec_capture('highlight Test_hl2'))
-- Colors are stored with the name they are defined, but
@@ -307,7 +312,7 @@ describe("API: set highlight", function()
exec_capture('highlight Test_hl3'))
end)
- it ("can modify a highlight in the global namespace", function()
+ it("can modify a highlight in the global namespace", function()
meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue'})
eq('Test_hl3 xxx guifg=Blue guibg=Red',
exec_capture('highlight Test_hl3'))
@@ -328,17 +333,17 @@ describe("API: set highlight", function()
eq('Test_hl3 xxx ctermbg=9',
exec_capture('highlight Test_hl3'))
- eq("'redd' is not a valid color",
+ eq("Invalid highlight color: 'redd'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'}))
- eq("'bleu' is not a valid color",
+ eq("Invalid highlight color: 'bleu'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'}))
meths.set_hl(0, 'Test_hl3', {fg='#FF00FF'})
eq('Test_hl3 xxx guifg=#ff00ff',
exec_capture('highlight Test_hl3'))
- eq("'#FF00FF' is not a valid color",
+ eq("Invalid highlight color: '#FF00FF'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'}))
for _, fg_val in ipairs{ nil, 'NONE', 'nOnE', '', -1 } do
@@ -353,14 +358,298 @@ describe("API: set highlight", function()
end)
- it ("correctly sets 'Normal' internal properties", function()
+ it("correctly sets 'Normal' internal properties", function()
-- Normal has some special handling internally. #18024
meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'})
eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true))
end)
it('does not segfault on invalid group name #20009', function()
- eq('Invalid highlight name: foo bar', pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
+ eq("Invalid highlight name: 'foo bar'", pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
assert_alive()
end)
end)
+
+describe('API: get highlight', function()
+ local highlight_color = {
+ fg = tonumber('0xff0000'),
+ bg = tonumber('0x0032aa'),
+ ctermfg = 8,
+ ctermbg = 15,
+ }
+ local highlight1 = {
+ bg = highlight_color.bg,
+ fg = highlight_color.fg,
+ bold = true, italic = true,
+ cterm = {bold = true, italic = true},
+ }
+ local highlight2 = {
+ ctermbg = highlight_color.ctermbg,
+ ctermfg = highlight_color.ctermfg,
+ underline = true, reverse = true,
+ cterm = {underline = true, reverse = true},
+ }
+ local highlight3_config = {
+ bg = highlight_color.bg,
+ fg = highlight_color.fg,
+ ctermbg = highlight_color.ctermbg,
+ ctermfg = highlight_color.ctermfg,
+ bold = true,
+ italic = true,
+ reverse = true,
+ underdashed = true,
+ strikethrough = true,
+ altfont = true,
+ cterm = {
+ italic = true,
+ reverse = true,
+ strikethrough = true,
+ altfont = true,
+ nocombine = true,
+ },
+ }
+ local highlight3_result = {
+ bg = highlight_color.bg,
+ fg = highlight_color.fg,
+ ctermbg = highlight_color.ctermbg,
+ ctermfg = highlight_color.ctermfg,
+ bold = true, italic = true, reverse = true, underdashed = true, strikethrough = true, altfont = true,
+ cterm = {italic = true, nocombine = true, reverse = true, strikethrough = true, altfont = true}
+ }
+
+ local function get_ns()
+ -- Test namespace filtering behavior
+ local ns2 = meths.create_namespace('Another_namespace')
+ meths.set_hl(ns2, 'Test_hl', { ctermfg = 23 })
+ meths.set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' })
+ meths.set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' })
+ meths.set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' })
+
+ local ns = meths.create_namespace('Test_set_hl')
+ meths.set_hl_ns(ns)
+
+ return ns
+ end
+
+ before_each(clear)
+
+ it('validation', function()
+ eq("Invalid 'name': expected String, got Integer",
+ pcall_err(meths.get_hl, 0, { name = 177 }))
+ eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' }))
+ end)
+
+ it('nvim_get_hl with create flag', function()
+ eq({}, nvim("get_hl", 0, {name = 'Foo', create = false}))
+ eq(0, funcs.hlexists('Foo'))
+ meths.get_hl(0, {name = 'Bar', create = true})
+ eq(1, funcs.hlexists('Bar'))
+ meths.get_hl(0, {name = 'FooBar'})
+ eq(1, funcs.hlexists('FooBar'))
+ end)
+
+ it('can get all highlights in current namespace', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' })
+ meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' })
+ eq({
+ Test_hl = {
+ bg = 11845374
+ },
+ Test_hl_link = {
+ link = 'Test_hl'
+ }
+ }, meths.get_hl(ns, {}))
+ end)
+
+ it('can get gui highlight', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', highlight1)
+ eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('can get cterm highlight', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', highlight2)
+ eq(highlight2, meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('can get empty cterm attr', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', { cterm = {} })
+ eq({}, meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('cterm attr defaults to gui attr', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', highlight1)
+ eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('can overwrite attr for cterm', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', highlight3_config)
+ eq(highlight3_result, meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('only allows one underline attribute #22371', function()
+ local ns = get_ns()
+ meths.set_hl(ns, 'Test_hl', {
+ underdouble = true,
+ underdotted = true,
+ cterm = {
+ underline = true,
+ undercurl = true,
+ },
+ })
+ eq({ underdotted = true, cterm = { undercurl = true} },
+ meths.get_hl(ns, { name = 'Test_hl' }))
+ end)
+
+ it('can get a highlight in the global namespace', function()
+ meths.set_hl(0, 'Test_hl', highlight2)
+ eq(highlight2, meths.get_hl(0, { name = 'Test_hl' }))
+
+ meths.set_hl(0, 'Test_hl', { background = highlight_color.bg })
+ eq({
+ bg = 12970,
+ }, meths.get_hl(0, { name = 'Test_hl' }))
+
+ meths.set_hl(0, 'Test_hl2', highlight3_config)
+ eq(highlight3_result, meths.get_hl(0, { name = 'Test_hl2' }))
+
+ -- Colors are stored with the name they are defined, but
+ -- with canonical casing
+ meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' })
+ eq({
+ bg = 16711680,
+ fg = 255,
+ }, meths.get_hl(0, { name = 'Test_hl3' }))
+ end)
+
+ it('nvim_get_hl by id', function()
+ local hl_id = meths.get_hl_id_by_name('NewHighlight')
+
+ command(
+ 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold'
+ )
+ eq({ fg = 16711680, bg = 16776960, sp = 255, bold = true,
+ ctermbg = 10, cterm = { underline = true },
+ }, meths.get_hl(0, { id = hl_id }))
+
+ -- Test 0 argument
+ eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 }))
+
+ eq(
+ "Invalid 'id': expected Integer, got String",
+ pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' })
+ )
+
+ -- Test all highlight properties.
+ command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
+ eq({ fg = 16711680, bg = 16776960, sp = 255,
+ altfont = true, bold = true, italic = true, nocombine = true, reverse = true, strikethrough = true, underline = true,
+ ctermbg = 10, cterm = {underline = true},
+ }, meths.get_hl(0, { id = hl_id }))
+
+ -- Test undercurl
+ command('hi NewHighlight gui=undercurl')
+ eq({ fg = 16711680, bg = 16776960, sp = 255, undercurl = true,
+ ctermbg = 10,
+ cterm = {underline = true},
+ }, meths.get_hl(0, { id = hl_id }))
+ end)
+
+ it('can correctly detect links', function()
+ command('hi String guifg=#a6e3a1')
+ command('hi link @string string')
+ command('hi link @string.cpp @string')
+ eq({ fg = 10937249 }, meths.get_hl(0, { name = 'String' }))
+ eq({ link = 'String' }, meths.get_hl(0, { name = '@string' }))
+ eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false }))
+ end)
+
+ it('can get all attributes for a linked group', function()
+ command('hi Bar guifg=red')
+ command('hi Foo guifg=#00ff00 gui=bold,underline')
+ command('hi! link Foo Bar')
+ eq({ link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, meths.get_hl(0, { name = 'Foo', link = true }))
+ end)
+
+ it('can set link as well as other attributes', function()
+ command('hi Bar guifg=red')
+ local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } }
+ meths.set_hl(0, 'Foo', hl)
+ eq(hl, meths.get_hl(0, { name = 'Foo', link = true }))
+ end)
+
+ it("doesn't contain unset groups", function()
+ local id = meths.get_hl_id_by_name "@foobar.hubbabubba"
+ ok(id > 0)
+
+ local data = meths.get_hl(0, {})
+ eq(nil, data["@foobar.hubbabubba"])
+ eq(nil, data["@foobar"])
+
+ command 'hi @foobar.hubbabubba gui=bold'
+ data = meths.get_hl(0, {})
+ eq({bold = true}, data["@foobar.hubbabubba"])
+ eq(nil, data["@foobar"])
+
+ -- @foobar.hubbabubba was explicitly cleared and thus shows up
+ -- but @foobar was never touched, and thus doesn't
+ command 'hi clear @foobar.hubbabubba'
+ data = meths.get_hl(0, {})
+ eq({}, data["@foobar.hubbabubba"])
+ eq(nil, data["@foobar"])
+ end)
+
+ it('should return default flag', function()
+ meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true })
+ eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' }))
+ end)
+
+ it('should not output empty gui and cterm #23474', function()
+ meths.set_hl(0, 'Foo', {default = true})
+ meths.set_hl(0, 'Bar', { default = true, fg = '#ffffff' })
+ meths.set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = {bold = true} })
+ meths.set_hl(0, 'FooBarA', { default = true, fg = '#ffffff', cterm = {bold = true,italic = true}})
+
+ eq('Foo xxx cleared',
+ exec_capture('highlight Foo'))
+ eq({default = true}, meths.get_hl(0, {name = 'Foo'}))
+ eq('Bar xxx guifg=#ffffff',
+ exec_capture('highlight Bar'))
+ eq('FooBar xxx cterm=bold guifg=#ffffff',
+ exec_capture('highlight FooBar'))
+ eq('FooBarA xxx cterm=bold,italic guifg=#ffffff',
+ exec_capture('highlight FooBarA'))
+ end)
+
+ it('can override exist highlight group by force #20323', function()
+ local white = tonumber('ffffff', 16)
+ local green = tonumber('00ff00', 16)
+ meths.set_hl(0, 'Foo', { fg=white })
+ meths.set_hl(0, 'Foo', { fg=green, force = true })
+ eq({ fg = green },meths.get_hl(0, {name = 'Foo'}))
+ meths.set_hl(0, 'Bar', {link = 'Comment', default = true})
+ meths.set_hl(0, 'Bar', {link = 'Foo',default = true, force = true})
+ eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'}))
+ end)
+end)
+
+describe('API: set/get highlight namespace', function()
+ it('set/get highlight namespace', function()
+ eq(0, meths.get_hl_ns({}))
+ local ns = meths.create_namespace('')
+ meths.set_hl_ns(ns)
+ eq(ns, meths.get_hl_ns({}))
+ end)
+
+ it('set/get window highlight namespace', function()
+ eq(-1, meths.get_hl_ns({winid = 0}))
+ local ns = meths.create_namespace('')
+ meths.win_set_hl_ns(0, ns)
+ eq(ns, meths.get_hl_ns({winid = 0}))
+ end)
+end)
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index 5be4425162..434f117956 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -19,6 +19,20 @@ local sleep = helpers.sleep
local sid_api_client = -9
local sid_lua = -8
+local mode_bits_map = {
+ ['n'] = 0x01,
+ ['x'] = 0x02,
+ ['o'] = 0x04,
+ ['c'] = 0x08,
+ ['i'] = 0x10,
+ ['l'] = 0x20,
+ ['s'] = 0x40,
+ ['t'] = 0x80,
+ [' '] = 0x47,
+ ['v'] = 0x42,
+ ['!'] = 0x18,
+}
+
describe('nvim_get_keymap', function()
before_each(clear)
@@ -32,9 +46,12 @@ describe('nvim_get_keymap', function()
rhs='bar',
expr=0,
sid=0,
+ scriptversion=1,
buffer=0,
nowait=0,
mode='n',
+ mode_bits=0x01,
+ abbr=0,
noremap=1,
lnum=0,
}
@@ -81,6 +98,7 @@ describe('nvim_get_keymap', function()
-- The table will be the same except for the mode
local insert_table = shallowcopy(foo_bar_map_table)
insert_table['mode'] = 'i'
+ insert_table['mode_bits'] = 0x10
eq({insert_table}, meths.get_keymap('i'))
end)
@@ -258,8 +276,10 @@ describe('nvim_get_keymap', function()
silent=0,
expr=0,
sid=0,
+ scriptversion=1,
buffer=0,
nowait=0,
+ abbr=0,
noremap=1,
lnum=0,
}
@@ -268,6 +288,7 @@ describe('nvim_get_keymap', function()
ret.lhs = lhs
ret.rhs = rhs
ret.mode = mode
+ ret.mode_bits = mode_bits_map[mode]
return ret
end
@@ -323,10 +344,13 @@ describe('nvim_get_keymap', function()
lhsraw='| |',
rhs='| |',
mode='n',
+ mode_bits=0x01,
+ abbr=0,
script=0,
silent=0,
expr=0,
sid=0,
+ scriptversion=1,
buffer=0,
nowait=0,
noremap=1,
@@ -365,15 +389,18 @@ describe('nvim_get_keymap', function()
silent=0,
expr=0,
sid=sid_lua,
+ scriptversion=1,
buffer=0,
nowait=0,
mode='n',
+ mode_bits=0x01,
+ abbr=0,
noremap=0,
lnum=0,
}, mapargs[1])
end)
- it ('can handle map descriptions', function()
+ it('can handle map descriptions', function()
meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"})
eq({
lhs='lhs',
@@ -383,9 +410,12 @@ describe('nvim_get_keymap', function()
silent=0,
expr=0,
sid=sid_api_client,
+ scriptversion=1,
buffer=0,
nowait=0,
mode='n',
+ mode_bits=0x01,
+ abbr=0,
noremap=0,
lnum=0,
desc='map description'
@@ -400,6 +430,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- maparg(), which does not accept "!" (though it returns "!" in its output
-- if getting a mapping set with |:map!|).
local function normalize_mapmode(mode, generate_expected)
+ if mode:sub(-1) == 'a' then
+ mode = mode:sub(1, -2)
+ end
if not generate_expected and mode == '!' then
-- Cannot retrieve mapmode-ic mappings with "!", but can with "i" or "c".
mode = 'i'
@@ -417,7 +450,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end
local to_return = {}
- to_return.mode = normalize_mapmode(mode, true)
+ local expected_mode = normalize_mapmode(mode, true)
+ to_return.mode = expected_mode
+ to_return.mode_bits = mode_bits_map[expected_mode]
+ to_return.abbr = mode:sub(-1) == 'a' and 1 or 0
to_return.noremap = not opts.noremap and 0 or 1
to_return.lhs = lhs
to_return.rhs = rhs
@@ -426,6 +462,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
to_return.nowait = not opts.nowait and 0 or 1
to_return.expr = not opts.expr and 0 or 1
to_return.sid = not opts.sid and sid_api_client or opts.sid
+ to_return.scriptversion = 1
to_return.buffer = not opts.buffer and 0 or opts.buffer
to_return.lnum = not opts.lnum and 0 or opts.lnum
to_return.desc = opts.desc
@@ -435,7 +472,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Gets a maparg() dict from Nvim, if one exists.
local function get_mapargs(mode, lhs)
- local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), false, true)
+ local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true)
-- drop "lhsraw" and "lhsrawalt" which are hard to check
mapargs.lhsraw = nil
mapargs.lhsrawalt = nil
@@ -450,7 +487,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
it('error if LHS longer than MAXMAPLEN', function()
- -- assume MAXMAPLEN of 50 chars, as declared in vim.h
+ -- assume MAXMAPLEN of 50 chars, as declared in mapping_defs.h
local MAXMAPLEN = 50
local lhs = ''
for i=1,MAXMAPLEN do
@@ -484,35 +521,33 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
get_mapargs('', 'lhs'))
end)
- it('throws errors when given too-long mode shortnames', function()
- eq('Shortname is too long: map',
- pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {}))
-
- eq('Shortname is too long: vmap',
- pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {}))
-
- eq('Shortname is too long: xnoremap',
- pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}))
-
- eq('Shortname is too long: map', pcall_err(meths.del_keymap, 'map', 'lhs'))
- eq('Shortname is too long: vmap', pcall_err(meths.del_keymap, 'vmap', 'lhs'))
- eq('Shortname is too long: xnoremap', pcall_err(meths.del_keymap, 'xnoremap', 'lhs'))
- end)
-
it('error on invalid mode shortname', function()
- eq('Invalid mode shortname: " "',
- pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {}))
- eq('Invalid mode shortname: "m"',
- pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {}))
- eq('Invalid mode shortname: "?"',
- pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {}))
- eq('Invalid mode shortname: "y"',
- pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {}))
- eq('Invalid mode shortname: "p"',
- pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: " "', pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "m"', pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "?"', pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "y"', pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "p"', pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "a"', pcall_err(meths.set_keymap, 'a', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "oa"', pcall_err(meths.set_keymap, 'oa', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "!o"', pcall_err(meths.set_keymap, '!o', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "!i"', pcall_err(meths.set_keymap, '!i', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "!!"', pcall_err(meths.set_keymap, '!!', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "map"', pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "vmap"', pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}))
+ eq('Invalid mode shortname: " "', pcall_err(meths.del_keymap, ' ', 'lhs'))
+ eq('Invalid mode shortname: "m"', pcall_err(meths.del_keymap, 'm', 'lhs'))
eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs'))
eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs'))
eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs'))
+ eq('Invalid mode shortname: "a"', pcall_err(meths.del_keymap, 'a', 'lhs'))
+ eq('Invalid mode shortname: "oa"', pcall_err(meths.del_keymap, 'oa', 'lhs'))
+ eq('Invalid mode shortname: "!o"', pcall_err(meths.del_keymap, '!o', 'lhs'))
+ eq('Invalid mode shortname: "!i"', pcall_err(meths.del_keymap, '!i', 'lhs'))
+ eq('Invalid mode shortname: "!!"', pcall_err(meths.del_keymap, '!!', 'lhs'))
+ eq('Invalid mode shortname: "map"', pcall_err(meths.del_keymap, 'map', 'lhs'))
+ eq('Invalid mode shortname: "vmap"', pcall_err(meths.del_keymap, 'vmap', 'lhs'))
+ eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.del_keymap, 'xnoremap', 'lhs'))
end)
it('error on invalid optnames', function()
@@ -681,13 +716,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
it('can set <expr> mappings whose RHS change dynamically', function()
- meths.exec([[
+ exec([[
function! FlipFlop() abort
if !exists('g:flip') | let g:flip = 0 | endif
let g:flip = !g:flip
return g:flip
endfunction
- ]], true)
+ ]])
eq(1, meths.call_function('FlipFlop', {}))
eq(0, meths.call_function('FlipFlop', {}))
eq(1, meths.call_function('FlipFlop', {}))
@@ -744,7 +779,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
-- Perform exhaustive tests of basic functionality
- local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', ''}
+ local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a'}
for _, mapmode in ipairs(mapmodes) do
it('can set/unset normal mappings in mapmode '..mapmode, function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {})
@@ -773,11 +808,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- remove some map arguments that are harder to test, or were already tested
optnames = {'nowait', 'silent', 'expr', 'noremap'}
for _, mapmode in ipairs(mapmodes) do
- local printable_mode = normalize_mapmode(mapmode)
-
-- Test with single mappings
for _, maparg in ipairs(optnames) do
- it('can set/unset '..printable_mode..'-mappings with maparg: '..maparg,
+ it('can set/unset '..mapmode..'-mappings with maparg: '..maparg,
function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = true})
eq(generate_mapargs(mapmode, 'lhs', 'rhs', {[maparg] = true}),
@@ -785,7 +818,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
meths.del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end)
- it ('can set/unset '..printable_mode..'-mode mappings with maparg '..
+ it ('can set/unset '..mapmode..'-mode mappings with maparg '..
maparg..', whose value is false', function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = false})
eq(generate_mapargs(mapmode, 'lhs', 'rhs'),
@@ -798,7 +831,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Test with triplets of mappings, one of which is false
for i = 1, (#optnames - 2) do
local opt1, opt2, opt3 = optnames[i], optnames[i + 1], optnames[i + 2]
- it('can set/unset '..printable_mode..'-mode mappings with mapargs '..
+ it('can set/unset '..mapmode..'-mode mappings with mapargs '..
opt1..', '..opt2..', '..opt3, function()
local opts = {[opt1] = true, [opt2] = false, [opt3] = true}
meths.set_keymap(mapmode, 'lhs', 'rhs', opts)
@@ -813,33 +846,36 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can make lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
feed('asdf\n')
eq(1, exec_lua[[return GlobalCount]])
-
end)
- it (':map command shows lua mapping correctly', function()
+ it(':map command shows lua mapping correctly', function()
exec_lua [[
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end })
]]
- assert.truthy(string.match(exec_lua[[return vim.api.nvim_exec(':nmap asdf', true)]],
- "^\nn asdf <Lua %d+>"))
+ assert.truthy(
+ string.match(
+ exec_lua[[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]],
+ "^\nn asdf <Lua %d+>"
+ )
+ )
end)
- it ('mapcheck() returns lua mapping correctly', function()
+ it('mapcheck() returns lua mapping correctly', function()
exec_lua [[
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end })
]]
assert.truthy(string.match(funcs.mapcheck('asdf', 'n'),
"^<Lua %d+>"))
end)
- it ('maparg() returns lua mapping correctly', function()
+ it('maparg() returns lua mapping correctly', function()
eq(0, exec_lua([[
GlobalCount = 0
vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
@@ -867,7 +903,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can make lua expr mappings replacing keycodes', function()
exec_lua [[
- vim.api.nvim_set_keymap ('n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
+ vim.api.nvim_set_keymap('n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
]]
feed('aa')
@@ -877,7 +913,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can make lua expr mappings without replacing keycodes', function()
exec_lua [[
- vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return '<space>' end, expr = true })
+ vim.api.nvim_set_keymap('i', 'aa', '', {callback = function() return '<space>' end, expr = true })
]]
feed('iaa<esc>')
@@ -887,7 +923,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('lua expr mapping returning nil is equivalent to returning an empty string', function()
exec_lua [[
- vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return nil end, expr = true })
+ vim.api.nvim_set_keymap('i', 'aa', '', {callback = function() return nil end, expr = true })
]]
feed('iaa<esc>')
@@ -898,17 +934,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('does not reset pum in lua mapping', function()
eq(0, exec_lua [[
VisibleCount = 0
- vim.api.nvim_set_keymap ('i', '<F2>', '', {callback = function() VisibleCount = VisibleCount + vim.fn.pumvisible() end})
+ vim.api.nvim_set_keymap('i', '<F2>', '', {callback = function() VisibleCount = VisibleCount + vim.fn.pumvisible() end})
return VisibleCount
]])
feed('i<C-X><C-V><F2><F2><esc>')
eq(2, exec_lua[[return VisibleCount]])
end)
+ it('redo of lua mappings in op-pending mode work', function()
+ eq(0, exec_lua [[
+ OpCount = 0
+ vim.api.nvim_set_keymap('o', '<F2>', '', {callback = function() OpCount = OpCount + 1 end})
+ return OpCount
+ ]])
+ feed('d<F2>')
+ eq(1, exec_lua[[return OpCount]])
+ feed('.')
+ eq(2, exec_lua[[return OpCount]])
+ end)
+
it('can overwrite lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
@@ -917,7 +965,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq(1, exec_lua[[return GlobalCount]])
exec_lua [[
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end })
]]
feed('asdf\n')
@@ -928,7 +976,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can unmap lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
@@ -973,6 +1021,54 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq("\nn lhs rhs\n map description",
helpers.exec_capture("nmap lhs"))
end)
+
+ it('can define !-mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('!a', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The 1 and the bar and the 2 again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The 3 is the one', meths.eval'x')
+ end)
+
+ it('can define insert mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('ia', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The 1 and the bar and the 2 again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The foo is the one', meths.eval'x')
+ end)
+
+ it('can define cmdline mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('ca', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The foo and the bar and the foo again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The 1 is the one', meths.eval'x')
+ end)
end)
describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
@@ -1074,7 +1170,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('can make lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
@@ -1085,7 +1181,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('can make lua expr mappings replacing keycodes', function()
exec_lua [[
- vim.api.nvim_buf_set_keymap (0, 'n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
+ vim.api.nvim_buf_set_keymap(0, 'n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
]]
feed('aa')
@@ -1095,7 +1191,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('can make lua expr mappings without replacing keycodes', function()
exec_lua [[
- vim.api.nvim_buf_set_keymap (0, 'i', 'aa', '', {callback = function() return '<space>' end, expr = true })
+ vim.api.nvim_buf_set_keymap(0, 'i', 'aa', '', {callback = function() return '<space>' end, expr = true })
]]
feed('iaa<esc>')
@@ -1107,7 +1203,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('can overwrite lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
@@ -1116,7 +1212,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
eq(1, exec_lua[[return GlobalCount]])
exec_lua [[
- vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end })
+ vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end })
]]
feed('asdf\n')
@@ -1127,7 +1223,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('can unmap lua mappings', function()
eq(0, exec_lua [[
GlobalCount = 0
- vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
]])
diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua
index 2028a8fba5..20edea3feb 100644
--- a/test/functional/api/proc_spec.lua
+++ b/test/functional/api/proc_spec.lua
@@ -42,14 +42,14 @@ describe('API', function()
end)
end)
- it('validates input', function()
+ it('validation', function()
local status, rv = pcall(request, "nvim_get_proc_children", -1)
eq(false, status)
- eq("Invalid pid: -1", string.match(rv, "Invalid.*"))
+ eq("Invalid 'pid': -1", string.match(rv, "Invalid.*"))
status, rv = pcall(request, "nvim_get_proc_children", 0)
eq(false, status)
- eq("Invalid pid: 0", string.match(rv, "Invalid.*"))
+ eq("Invalid 'pid': 0", string.match(rv, "Invalid.*"))
-- Assume PID 99999 does not exist.
status, rv = pcall(request, "nvim_get_proc_children", 99999)
@@ -68,14 +68,14 @@ describe('API', function()
neq(pid, pinfo.ppid)
end)
- it('validates input', function()
+ it('validation', function()
local status, rv = pcall(request, "nvim_get_proc", -1)
eq(false, status)
- eq("Invalid pid: -1", string.match(rv, "Invalid.*"))
+ eq("Invalid 'pid': -1", string.match(rv, "Invalid.*"))
status, rv = pcall(request, "nvim_get_proc", 0)
eq(false, status)
- eq("Invalid pid: 0", string.match(rv, "Invalid.*"))
+ eq("Invalid 'pid': 0", string.match(rv, "Invalid.*"))
-- Assume PID 99999 does not exist.
status, rv = pcall(request, "nvim_get_proc", 99999)
diff --git a/test/functional/api/rpc_fixture.lua b/test/functional/api/rpc_fixture.lua
index 94df751363..c860a6da59 100644
--- a/test/functional/api/rpc_fixture.lua
+++ b/test/functional/api/rpc_fixture.lua
@@ -4,9 +4,8 @@
package.path = arg[1]
package.cpath = arg[2]
-local mpack = require('mpack')
-local StdioStream = require('nvim.stdio_stream')
-local Session = require('nvim.session')
+local StdioStream = require'test.client.uv_stream'.StdioStream
+local Session = require'test.client.session'
local stdio_stream = StdioStream.open()
local session = Session.new(stdio_stream)
@@ -19,7 +18,7 @@ local function on_request(method, args)
return "done!"
elseif method == "exit" then
session:stop()
- return mpack.NIL
+ return vim.NIL
end
end
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua
index 53642858b2..bc43f6564d 100644
--- a/test/functional/api/server_notifications_spec.lua
+++ b/test/functional/api/server_notifications_spec.lua
@@ -6,9 +6,7 @@ local eq, clear, eval, command, nvim, next_msg =
local meths = helpers.meths
local exec_lua = helpers.exec_lua
local retry = helpers.retry
-local is_ci = helpers.is_ci
local assert_alive = helpers.assert_alive
-local skip = helpers.skip
local testlog = 'Xtest-server-notify-log'
@@ -90,7 +88,6 @@ describe('notify', function()
end)
it('cancels stale events on channel close', function()
- skip(is_ci(), 'hangs on CI #14083 #15251')
local catchan = eval("jobstart(['cat'], {'rpc': v:true})")
local catpath = eval('exepath("cat")')
eq({id=catchan, argv={catpath}, stream='job', mode='rpc', client = {}}, exec_lua ([[
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index ceff390dc5..1ad4ad3a02 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -199,7 +199,7 @@ describe('server -> client', function()
it('can communicate buffers, tabpages, and windows', function()
eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')"))
- -- Window IDs start at 1000 (LOWEST_WIN_ID in vim.h)
+ -- Window IDs start at 1000 (LOWEST_WIN_ID in window.h)
eq({1000}, eval("rpcrequest(vim, 'nvim_list_wins')"))
local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1]
@@ -237,7 +237,7 @@ describe('server -> client', function()
\ }
]])
meths.set_var("args", {
- helpers.test_lua_prg,
+ nvim_prog, '-ll',
'test/functional/api/rpc_fixture.lua',
package.path,
package.cpath,
@@ -337,6 +337,21 @@ describe('server -> client', function()
eq('localhost:', string.sub(address,1,10))
connect_test(server, 'tcp', address)
end)
+
+ it('does not crash on receiving UI events', function()
+ local server = spawn(nvim_argv)
+ set_session(server)
+ local address = funcs.serverlist()[1]
+ local client = spawn(nvim_argv, false, nil, true)
+ set_session(client)
+
+ local id = funcs.sockconnect('pipe', address, {rpc=true})
+ funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {})
+ assert_alive()
+
+ server:close()
+ client:close()
+ end)
end)
describe('connecting to its own pipe address', function()
diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua
index 279cd1856d..6efb6726fe 100644
--- a/test/functional/api/ui_spec.lua
+++ b/test/functional/api/ui_spec.lua
@@ -1,8 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
+local exec = helpers.exec
+local feed = helpers.feed
local meths = helpers.meths
local request = helpers.request
local pcall_err = helpers.pcall_err
@@ -11,17 +14,35 @@ describe('nvim_ui_attach()', function()
before_each(function()
clear()
end)
+
it('handles very large width/height #2180', function()
local screen = Screen.new(999, 999)
screen:attach()
eq(999, eval('&lines'))
eq(999, eval('&columns'))
end)
- it('invalid option returns error', function()
+
+ it('validation', function()
eq('No such UI option: foo',
pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} }))
- end)
- it('validates channel arg', function()
+
+ eq("Invalid 'ext_linegrid': expected Boolean, got Array",
+ pcall_err(meths.ui_attach, 80, 24, { ext_linegrid={} }))
+ eq("Invalid 'override': expected Boolean, got Array",
+ pcall_err(meths.ui_attach, 80, 24, { override={} }))
+ eq("Invalid 'rgb': expected Boolean, got Array",
+ pcall_err(meths.ui_attach, 80, 24, { rgb={} }))
+ eq("Invalid 'term_name': expected String, got Boolean",
+ pcall_err(meths.ui_attach, 80, 24, { term_name=true }))
+ eq("Invalid 'term_colors': expected Integer, got Boolean",
+ pcall_err(meths.ui_attach, 80, 24, { term_colors=true }))
+ eq("Invalid 'stdin_fd': expected Integer, got String",
+ pcall_err(meths.ui_attach, 80, 24, { stdin_fd='foo' }))
+ eq("Invalid 'stdin_tty': expected Boolean, got String",
+ pcall_err(meths.ui_attach, 80, 24, { stdin_tty='foo' }))
+ eq("Invalid 'stdout_tty': expected Boolean, got String",
+ pcall_err(meths.ui_attach, 80, 24, { stdout_tty='foo' }))
+
eq('UI not attached to channel: 1',
pcall_err(request, 'nvim_ui_try_resize', 40, 10))
eq('UI not attached to channel: 1',
@@ -37,14 +58,13 @@ describe('nvim_ui_attach()', function()
end)
it('autocmds UIEnter/UILeave', function()
- clear{
- args_rm={'--headless'},
- args={
- '--cmd', 'let g:evs = []',
- '--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)',
- '--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)',
- '--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")',
- }}
+ clear{args_rm={'--headless'}}
+ exec([[
+ let g:evs = []
+ autocmd UIEnter * call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)
+ autocmd UILeave * call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)
+ autocmd VimEnter * call add(g:evs, "VimEnter")
+ ]])
local screen = Screen.new()
screen:attach()
eq({chan=1}, eval('g:uienter_ev'))
@@ -56,3 +76,45 @@ it('autocmds UIEnter/UILeave', function()
'UILeave',
}, eval('g:evs'))
end)
+
+it('autocmds VimSuspend/VimResume #22041', function()
+ clear()
+ local screen = Screen.new()
+ screen:attach()
+ exec([[
+ let g:ev = []
+ autocmd VimResume * :call add(g:ev, 'r')
+ autocmd VimSuspend * :call add(g:ev, 's')
+ ]])
+
+ eq(false, screen.suspended)
+ feed('<C-Z>')
+ screen:expect(function() eq(true, screen.suspended) end)
+ eq({ 's' }, eval('g:ev'))
+ screen.suspended = false
+ feed('<Ignore>')
+ eq({ 's', 'r' }, eval('g:ev'))
+
+ command('suspend')
+ screen:expect(function() eq(true, screen.suspended) end)
+ eq({ 's', 'r', 's' }, eval('g:ev'))
+ screen.suspended = false
+ meths.input_mouse('move', '', '', 0, 0, 0)
+ eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
+
+ feed('<C-Z><C-Z><C-Z>')
+ screen:expect(function() eq(true, screen.suspended) end)
+ meths.ui_set_focus(false)
+ eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev'))
+ screen.suspended = false
+ meths.ui_set_focus(true)
+ eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
+
+ command('suspend | suspend | suspend')
+ screen:expect(function() eq(true, screen.suspended) end)
+ screen:detach()
+ eq({ 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev'))
+ screen.suspended = false
+ screen:attach()
+ eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
+end)
diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua
index 771192e9ab..6d466b0cc1 100644
--- a/test/functional/api/version_spec.lua
+++ b/test/functional/api/version_spec.lua
@@ -34,6 +34,7 @@ describe("api_info()['version']", function()
local minor = version['minor']
local patch = version['patch']
local prerelease = version['prerelease']
+ local build = version['build']
eq("number", type(major))
eq("number", type(minor))
eq("number", type(patch))
@@ -42,6 +43,7 @@ describe("api_info()['version']", function()
eq(0, funcs.has("nvim-"..major.."."..minor.."."..(patch + 1)))
eq(0, funcs.has("nvim-"..major.."."..(minor + 1).."."..patch))
eq(0, funcs.has("nvim-"..(major + 1).."."..minor.."."..patch))
+ assert(build == nil or type(build) == 'string')
end)
end)
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 8fcdd9620b..8bbadda9b0 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1,6 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
-local lfs = require('lfs')
local luv = require('luv')
local fmt = string.format
@@ -9,6 +8,7 @@ local NIL = helpers.NIL
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
local command = helpers.command
local exec = helpers.exec
+local exec_capture = helpers.exec_capture
local eval = helpers.eval
local expect = helpers.expect
local funcs = helpers.funcs
@@ -28,7 +28,6 @@ local write_file = helpers.write_file
local exec_lua = helpers.exec_lua
local exc_exec = helpers.exc_exec
local insert = helpers.insert
-local expect_exit = helpers.expect_exit
local skip = helpers.skip
local pcall_err = helpers.pcall_err
@@ -59,7 +58,7 @@ describe('API', function()
-- XXX: This must be the last one, else next one will fail:
-- "Packer instance already working. Use another Packer ..."
- matches("can't serialize object$",
+ matches("can't serialize object of type .$",
pcall_err(request, nil))
end)
@@ -89,132 +88,145 @@ describe('API', function()
eq({mode='i', blocking=false}, nvim("get_mode"))
end)
- describe('nvim_exec', function()
+ describe('nvim_exec2', function()
+ it('always returns table', function()
+ -- In built version this results into `vim.empty_dict()`
+ eq({}, nvim('exec2', 'echo "Hello"', {}))
+ eq({}, nvim('exec2', 'echo "Hello"', { output = false }))
+ eq({ output = 'Hello' }, nvim('exec2', 'echo "Hello"', { output = true }))
+ end)
+
+ it('default options', function()
+ -- Should be equivalent to { output = false }
+ nvim('exec2', "let x0 = 'a'", {})
+ eq('a', nvim('get_var', 'x0'))
+ end)
+
it('one-line input', function()
- nvim('exec', "let x1 = 'a'", false)
+ nvim('exec2', "let x1 = 'a'", { output = false })
eq('a', nvim('get_var', 'x1'))
end)
it(':verbose set {option}?', function()
- nvim('exec', 'set nowrap', false)
- eq('nowrap\n\tLast set from anonymous :source',
- nvim('exec', 'verbose set wrap?', true))
+ nvim('exec2', 'set nowrap', { output = false })
+ eq({ output = 'nowrap\n\tLast set from anonymous :source' },
+ nvim('exec2', 'verbose set wrap?', { output = true }))
-- Using script var to force creation of a script item
- nvim('exec', [[
+ nvim('exec2', [[
let s:a = 1
set nowrap
- ]], false)
- eq('nowrap\n\tLast set from anonymous :source (script id 1)',
- nvim('exec', 'verbose set wrap?', true))
+ ]], { output = false })
+ eq({ output = 'nowrap\n\tLast set from anonymous :source (script id 1)' },
+ nvim('exec2', 'verbose set wrap?', { output = true }))
end)
it('multiline input', function()
-- Heredoc + empty lines.
- nvim('exec', "let x2 = 'a'\n", false)
+ nvim('exec2', "let x2 = 'a'\n", { output = false })
eq('a', nvim('get_var', 'x2'))
- nvim('exec','lua <<EOF\n\n\n\ny=3\n\n\nEOF', false)
+ nvim('exec2','lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false })
eq(3, nvim('eval', "luaeval('y')"))
- eq('', nvim('exec', 'lua <<EOF\ny=3\nEOF', false))
+ eq({}, nvim('exec2', 'lua <<EOF\ny=3\nEOF', { output = false }))
eq(3, nvim('eval', "luaeval('y')"))
-- Multiple statements
- nvim('exec', 'let x1=1\nlet x2=2\nlet x3=3\n', false)
+ nvim('exec2', 'let x1=1\nlet x2=2\nlet x3=3\n', { output = false })
eq(1, nvim('eval', 'x1'))
eq(2, nvim('eval', 'x2'))
eq(3, nvim('eval', 'x3'))
-- Functions
- nvim('exec', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', false)
+ nvim('exec2', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', { output = false })
eq('', nvim('get_current_line'))
- nvim('exec', 'call Foo()', false)
+ nvim('exec2', 'call Foo()', { output = false })
eq('xxx', nvim('get_current_line'))
-- Autocmds
- nvim('exec','autocmd BufAdd * :let x1 = "Hello"', false)
+ nvim('exec2','autocmd BufAdd * :let x1 = "Hello"', { output = false })
nvim('command', 'new foo')
eq('Hello', request('nvim_eval', 'g:x1'))
-- Line continuations
- nvim('exec', [[
+ nvim('exec2', [[
let abc = #{
\ a: 1,
"\ b: 2,
\ c: 3
- \ }]], false)
+ \ }]], { output = false })
eq({a = 1, c = 3}, request('nvim_eval', 'g:abc'))
-- try no spaces before continuations to catch off-by-one error
- nvim('exec', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', false)
+ nvim('exec2', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false })
eq({a = 98}, request('nvim_eval', 'g:ab'))
-- Script scope (s:)
- eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ eq({ output = 'ahoy! script-scoped varrrrr' }, nvim('exec2', [[
let s:pirate = 'script-scoped varrrrr'
function! s:avast_ye_hades(s) abort
return a:s .. ' ' .. s:pirate
endfunction
echo <sid>avast_ye_hades('ahoy!')
- ]], true))
+ ]], { output = true }))
- eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ eq({ output = "{'output': 'ahoy! script-scoped varrrrr'}" }, nvim('exec2', [[
let s:pirate = 'script-scoped varrrrr'
function! Avast_ye_hades(s) abort
return a:s .. ' ' .. s:pirate
endfunction
- echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1)
- ]], true))
+ echo nvim_exec2('echo Avast_ye_hades(''ahoy!'')', {'output': v:true})
+ ]], { output = true }))
matches('Vim%(echo%):E121: Undefined variable: s:pirate$',
- pcall_err(request, 'nvim_exec', [[
+ pcall_err(request, 'nvim_exec2', [[
let s:pirate = 'script-scoped varrrrr'
- call nvim_exec('echo s:pirate', 1)
- ]], false))
+ call nvim_exec2('echo s:pirate', {'output': v:true})
+ ]], { output = false }))
-- Script items are created only on script var access
- eq('1\n0', nvim('exec', [[
+ eq({ output = '1\n0' }, nvim('exec2', [[
echo expand("<SID>")->empty()
let s:a = 123
echo expand("<SID>")->empty()
- ]], true))
+ ]], { output = true }))
- eq('1\n0', nvim('exec', [[
+ eq({ output = '1\n0' }, nvim('exec2', [[
echo expand("<SID>")->empty()
function s:a() abort
endfunction
echo expand("<SID>")->empty()
- ]], true))
+ ]], { output = true }))
end)
it('non-ASCII input', function()
- nvim('exec', [=[
+ nvim('exec2', [=[
new
exe "normal! i ax \n Ax "
:%s/ax/--a1234--/g | :%s/Ax/--A1234--/g
- ]=], false)
+ ]=], { output = false })
nvim('command', '1')
eq(' --a1234-- ', nvim('get_current_line'))
nvim('command', '2')
eq(' --A1234-- ', nvim('get_current_line'))
- nvim('exec', [[
+ nvim('exec2', [[
new
call setline(1,['xxx'])
call feedkeys('r')
call feedkeys('ñ', 'xt')
- ]], false)
+ ]], { output = false })
eq('ñxx', nvim('get_current_line'))
end)
it('execution error', function()
- eq('nvim_exec(): Vim:E492: Not an editor command: bogus_command',
- pcall_err(request, 'nvim_exec', 'bogus_command', false))
+ eq('nvim_exec2(): Vim:E492: Not an editor command: bogus_command',
+ pcall_err(request, 'nvim_exec2', 'bogus_command', {}))
eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
- eq('nvim_exec(): Vim(buffer):E86: Buffer 23487 does not exist',
- pcall_err(request, 'nvim_exec', 'buffer 23487', false))
+ eq('nvim_exec2(): Vim(buffer):E86: Buffer 23487 does not exist',
+ pcall_err(request, 'nvim_exec2', 'buffer 23487', {}))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
@@ -222,17 +234,17 @@ describe('API', function()
it('recursion', function()
local fname = tmpname()
write_file(fname, 'let x1 = "set from :source file"\n')
- -- nvim_exec
+ -- nvim_exec2
-- :source
- -- nvim_exec
- request('nvim_exec', [[
+ -- nvim_exec2
+ request('nvim_exec2', [[
let x2 = substitute('foo','o','X','g')
let x4 = 'should be overwritten'
- call nvim_exec("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec','g')\nlet x5='overwritten'\nlet x4=x5\n", v:false)
- ]], false)
+ call nvim_exec2("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec2','g')\nlet x5='overwritten'\nlet x4=x5\n", {'output': v:false})
+ ]], { output = false })
eq('set from :source file', request('nvim_get_var', 'x1'))
eq('fXX', request('nvim_get_var', 'x2'))
- eq('set by recursive nvim_exec', request('nvim_get_var', 'x3'))
+ eq('set by recursive nvim_exec2', request('nvim_get_var', 'x3'))
eq('overwritten', request('nvim_get_var', 'x4'))
eq('overwritten', request('nvim_get_var', 'x5'))
os.remove(fname)
@@ -242,35 +254,35 @@ describe('API', function()
local fname = tmpname()
write_file(fname, 'echo "hello"\n')
local sourcing_fname = tmpname()
- write_file(sourcing_fname, 'call nvim_exec("source '..fname..'", v:false)\n')
- meths.exec('set verbose=2', false)
+ write_file(sourcing_fname, 'call nvim_exec2("source '..fname..'", {"output": v:false})\n')
+ meths.exec2('set verbose=2', { output = false })
local traceback_output = 'line 0: sourcing "'..sourcing_fname..'"\n'..
'line 0: sourcing "'..fname..'"\n'..
'hello\n'..
'finished sourcing '..fname..'\n'..
- 'continuing in nvim_exec() called at '..sourcing_fname..':1\n'..
+ 'continuing in nvim_exec2() called at '..sourcing_fname..':1\n'..
'finished sourcing '..sourcing_fname..'\n'..
- 'continuing in nvim_exec() called at nvim_exec():0'
- eq(traceback_output,
- meths.exec('call nvim_exec("source '..sourcing_fname..'", v:false)', true))
+ 'continuing in nvim_exec2() called at nvim_exec2():0'
+ eq({ output = traceback_output },
+ meths.exec2('call nvim_exec2("source '..sourcing_fname..'", {"output": v:false})', { output = true }))
os.remove(fname)
os.remove(sourcing_fname)
end)
it('returns output', function()
- eq('this is spinal tap',
- nvim('exec', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', true))
- eq('', nvim('exec', 'echo', true))
- eq('foo 42', nvim('exec', 'echo "foo" 42', true))
+ eq({ output = 'this is spinal tap' },
+ nvim('exec2', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }))
+ eq({ output = '' }, nvim('exec2', 'echo', { output = true }))
+ eq({ output = 'foo 42' }, nvim('exec2', 'echo "foo" 42', { output = true }))
end)
- it('displays messages when output=false', function()
+ it('displays messages when opts.output=false', function()
local screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
[0] = {bold=true, foreground=Screen.colors.Blue},
})
- meths.exec("echo 'hello'", false)
+ meths.exec2("echo 'hello'", { output = false })
screen:expect{grid=[[
^ |
{0:~ }|
@@ -289,7 +301,7 @@ describe('API', function()
screen:set_default_attr_ids({
[0] = {bold=true, foreground=Screen.colors.Blue},
})
- meths.exec("echo 'hello'", true)
+ meths.exec2("echo 'hello'", { output = true })
screen:expect{grid=[[
^ |
{0:~ }|
@@ -300,7 +312,7 @@ describe('API', function()
]]}
exec([[
func Print()
- call nvim_exec('echo "hello"', v:true)
+ call nvim_exec2('echo "hello"', { 'output': v:true })
endfunc
]])
feed([[:echon 1 | call Print() | echon 5<CR>]])
@@ -322,8 +334,7 @@ describe('API', function()
nvim('command', 'edit '..fname)
nvim('command', 'normal itesting\napi')
nvim('command', 'w')
- local f = io.open(fname)
- ok(f ~= nil)
+ local f = assert(io.open(fname))
if is_os('win') then
eq('testing\r\napi\r\n', f:read('*a'))
else
@@ -333,21 +344,27 @@ describe('API', function()
os.remove(fname)
end)
- it('VimL validation error: fails with specific error', function()
+ it('Vimscript validation error: fails with specific error', function()
local status, rv = pcall(nvim, "command", "bogus_command")
eq(false, status) -- nvim_command() failed.
- eq("E492:", string.match(rv, "E%d*:")) -- VimL error was returned.
+ eq("E492:", string.match(rv, "E%d*:")) -- Vimscript error was returned.
eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
- it('VimL execution error: fails with specific error', function()
+ it('Vimscript execution error: fails with specific error', function()
local status, rv = pcall(nvim, "command", "buffer 23487")
eq(false, status) -- nvim_command() failed.
eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*"))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
+
+ it('gives E493 instead of prompting on backwards range', function()
+ command('split')
+ eq('Vim(windo):E493: Backwards range given: 2,1windo echo',
+ pcall_err(command, '2,1windo echo'))
+ end)
end)
describe('nvim_command_output', function()
@@ -403,7 +420,7 @@ describe('API', function()
eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]]))
end)
- it('VimL validation error: fails with specific error', function()
+ it('Vimscript validation error: fails with specific error', function()
local status, rv = pcall(nvim, "command_output", "bogus commannnd")
eq(false, status) -- nvim_command_output() failed.
eq("E492: Not an editor command: bogus commannnd",
@@ -413,7 +430,7 @@ describe('API', function()
eq({mode='n', blocking=false}, nvim("get_mode"))
end)
- it('VimL execution error: fails with specific error', function()
+ it('Vimscript execution error: fails with specific error', function()
local status, rv = pcall(nvim, "command_output", "buffer 42")
eq(false, status) -- nvim_command_output() failed.
eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*"))
@@ -422,7 +439,7 @@ describe('API', function()
eq({mode='n', blocking=false}, nvim("get_mode"))
end)
- it('Does not cause heap buffer overflow with large output', function()
+ it('does not cause heap buffer overflow with large output', function()
eq(eval('string(range(1000000))'),
nvim('command_output', 'echo range(1000000)'))
end)
@@ -444,7 +461,7 @@ describe('API', function()
eq(2, request("vim_eval", "1+1"))
end)
- it("VimL error: returns error details, does NOT update v:errmsg", function()
+ it("Vimscript error: returns error details, does NOT update v:errmsg", function()
eq('Vim:E121: Undefined variable: bogus',
pcall_err(request, 'nvim_eval', 'bogus expression'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
@@ -459,7 +476,7 @@ describe('API', function()
eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'}))
end)
- it("VimL validation error: returns specific error, does NOT update v:errmsg", function()
+ it("Vimscript validation error: returns specific error, does NOT update v:errmsg", function()
eq('Vim:E117: Unknown function: bogus function',
pcall_err(request, 'nvim_call_function', 'bogus function', {'arg1'}))
eq('Vim:E119: Not enough arguments for function: atan',
@@ -468,7 +485,7 @@ describe('API', function()
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
- it("VimL error: returns error details, does NOT update v:errmsg", function()
+ it("Vimscript error: returns error details, does NOT update v:errmsg", function()
eq('Vim:E808: Number or Float required',
pcall_err(request, 'nvim_call_function', 'atan', {'foo'}))
eq('Vim:Invalid channel stream "xxx"',
@@ -479,7 +496,7 @@ describe('API', function()
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
- it("VimL exception: returns exception details, does NOT update v:errmsg", function()
+ it("Vimscript exception: returns exception details, does NOT update v:errmsg", function()
source([[
function! Foo() abort
throw 'wtf'
@@ -490,7 +507,7 @@ describe('API', function()
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
- it('validates args', function()
+ it('validation', function()
local too_many_args = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }
source([[
function! Foo(...) abort
@@ -504,7 +521,7 @@ describe('API', function()
end)
describe('nvim_call_dict_function', function()
- it('invokes VimL dict function', function()
+ it('invokes Vimscript dict function', function()
source([[
function! F(name) dict
return self.greeting.', '.a:name.'!'
@@ -532,7 +549,7 @@ describe('API', function()
eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G'}, 'G', {}))
end)
- it('validates args', function()
+ it('validation', function()
command('let g:d={"baz":"zub","meep":[]}')
eq('Not found: bogus',
pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', {1,2}))
@@ -559,7 +576,6 @@ describe('API', function()
local start_dir
before_each(function()
- clear()
funcs.mkdir("Xtestdir")
start_dir = funcs.getcwd()
end)
@@ -575,7 +591,7 @@ describe('API', function()
it('sets previous directory', function()
meths.set_current_dir("Xtestdir")
- meths.exec('cd -', false)
+ command('cd -')
eq(funcs.getcwd(), start_dir)
end)
end)
@@ -634,7 +650,7 @@ describe('API', function()
end)
describe('nvim_input', function()
- it("VimL error: does NOT fail, updates v:errmsg", function()
+ it("Vimscript error: does NOT fail, updates v:errmsg", function()
local status, _ = pcall(nvim, "input", ":call bogus_fn()<CR>")
local v_errnum = string.match(nvim("eval", "v:errmsg"), "E%d*:")
eq(true, status) -- nvim_input() did not fail.
@@ -648,10 +664,10 @@ describe('API', function()
end)
describe('nvim_paste', function()
- it('validates args', function()
- eq('Invalid phase: -2',
+ it('validation', function()
+ eq("Invalid 'phase': -2",
pcall_err(request, 'nvim_paste', 'foo', true, -2))
- eq('Invalid phase: 4',
+ eq("Invalid 'phase': 4",
pcall_err(request, 'nvim_paste', 'foo', true, 4))
end)
local function run_streamed_paste_tests()
@@ -1032,7 +1048,7 @@ describe('API', function()
line 3
]])
eq({0,4,1,0}, funcs.getpos('.')) -- Cursor follows the paste.
- eq(false, nvim('get_option', 'paste'))
+ eq(false, nvim('get_option_value', 'paste', {}))
command('%delete _')
-- Without final "\n".
nvim('paste', 'line 1\nline 2\nline 3', true, -1)
@@ -1072,7 +1088,7 @@ describe('API', function()
nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1)
expect('line 1\n\n\nline 2\nline 3\nline 4\n')
eq({0,7,1,0}, funcs.getpos('.'))
- eq(false, nvim('get_option', 'paste'))
+ eq(false, nvim('get_option_value', 'paste', {}))
end)
it('Replace-mode', function()
-- Within single line
@@ -1154,10 +1170,10 @@ describe('API', function()
end)
describe('nvim_put', function()
- it('validates args', function()
- eq('Invalid lines (expected array of strings)',
+ it('validation', function()
+ eq("Invalid 'line': expected String, got Integer",
pcall_err(request, 'nvim_put', {42}, 'l', false, false))
- eq("Invalid type: 'x'",
+ eq("Invalid 'type': 'x'",
pcall_err(request, 'nvim_put', {'foo'}, 'x', false, false))
end)
it("fails if 'nomodifiable'", function()
@@ -1259,9 +1275,9 @@ describe('API', function()
yyybc line 2
line 3
]])
- eq("Invalid type: 'bx'",
+ eq("Invalid 'type': 'bx'",
pcall_err(meths.put, {'xxx', 'yyy'}, 'bx', false, true))
- eq("Invalid type: 'b3x'",
+ eq("Invalid 'type': 'b3x'",
pcall_err(meths.put, {'xxx', 'yyy'}, 'b3x', false, true))
end)
end)
@@ -1288,6 +1304,11 @@ describe('API', function()
end)
describe('set/get/del variables', function()
+ it('validation', function()
+ eq('Key not found: bogus', pcall_err(meths.get_var, 'bogus'))
+ eq('Key not found: bogus', pcall_err(meths.del_var, 'bogus'))
+ end)
+
it('nvim_get_var, nvim_set_var, nvim_del_var', function()
nvim('set_var', 'lua', {1, 2, {['3'] = 1}})
eq({1, 2, {['3'] = 1}}, nvim('get_var', 'lua'))
@@ -1329,12 +1350,59 @@ describe('API', function()
end)
it('nvim_get_vvar, nvim_set_vvar', function()
- -- Set readonly v: var.
- eq('Key is read-only: count',
- pcall_err(request, 'nvim_set_vvar', 'count', 42))
- -- Set writable v: var.
+ eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42))
+ eq('Dictionary is locked', pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42))
meths.set_vvar('errmsg', 'set by API')
eq('set by API', meths.get_vvar('errmsg'))
+ meths.set_vvar('errmsg', 42)
+ eq('42', eval('v:errmsg'))
+ meths.set_vvar('oldfiles', { 'one', 'two' })
+ eq({ 'one', 'two' }, eval('v:oldfiles'))
+ meths.set_vvar('oldfiles', {})
+ eq({}, eval('v:oldfiles'))
+ eq('Setting v:oldfiles to value with wrong type', pcall_err(meths.set_vvar, 'oldfiles', 'a'))
+ eq({}, eval('v:oldfiles'))
+
+ feed('i foo foo foo<Esc>0/foo<CR>')
+ eq({1, 1}, meths.win_get_cursor(0))
+ eq(1, eval('v:searchforward'))
+ feed('n')
+ eq({1, 5}, meths.win_get_cursor(0))
+ meths.set_vvar('searchforward', 0)
+ eq(0, eval('v:searchforward'))
+ feed('n')
+ eq({1, 1}, meths.win_get_cursor(0))
+ meths.set_vvar('searchforward', 1)
+ eq(1, eval('v:searchforward'))
+ feed('n')
+ eq({1, 5}, meths.win_get_cursor(0))
+
+ local screen = Screen.new(60, 3)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ [1] = {background = Screen.colors.Yellow},
+ })
+ screen:attach()
+ eq(1, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ {1:foo} {1:^foo} {1:foo} |
+ {0:~ }|
+ |
+ ]]}
+ meths.set_vvar('hlsearch', 0)
+ eq(0, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ foo ^foo foo |
+ {0:~ }|
+ |
+ ]]}
+ meths.set_vvar('hlsearch', 1)
+ eq(1, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ {1:foo} {1:^foo} {1:foo} |
+ {0:~ }|
+ |
+ ]]}
end)
it('vim_set_var returns the old value', function()
@@ -1358,56 +1426,71 @@ describe('API', function()
end)
end)
- describe('nvim_get_option, nvim_set_option', function()
+ describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function()
- ok(nvim('get_option', 'equalalways'))
- nvim('set_option', 'equalalways', false)
- ok(not nvim('get_option', 'equalalways'))
+ ok(nvim('get_option_value', 'equalalways', {}))
+ nvim('set_option_value', 'equalalways', false, {})
+ ok(not nvim('get_option_value', 'equalalways', {}))
end)
it('works to get global value of local options', function()
- eq(false, nvim('get_option', 'lisp'))
- eq(8, nvim('get_option', 'shiftwidth'))
+ eq(false, nvim('get_option_value', 'lisp', {}))
+ eq(8, nvim('get_option_value', 'shiftwidth', {}))
end)
it('works to set global value of local options', function()
- nvim('set_option', 'lisp', true)
- eq(true, nvim('get_option', 'lisp'))
- eq(false, helpers.curbuf('get_option', 'lisp'))
+ nvim('set_option_value', 'lisp', true, {scope='global'})
+ eq(true, nvim('get_option_value', 'lisp', {scope='global'}))
+ eq(false, nvim('get_option_value', 'lisp', {}))
eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp'))
eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp'))
- nvim('set_option', 'shiftwidth', 20)
+ nvim('set_option_value', 'shiftwidth', 20, {scope='global'})
eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+'))
eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+'))
end)
- it('most window-local options have no global value', function()
- local status, err = pcall(nvim, 'get_option', 'foldcolumn')
- eq(false, status)
- ok(err:match('Invalid option name') ~= nil)
- end)
-
it('updates where the option was last set from', function()
- nvim('set_option', 'equalalways', false)
+ nvim('set_option_value', 'equalalways', false, {})
local status, rv = pcall(nvim, 'command_output',
'verbose set equalalways?')
eq(true, status)
ok(nil ~= string.find(rv, 'noequalalways\n'..
'\tLast set from API client %(channel id %d+%)'))
- nvim('exec_lua', 'vim.api.nvim_set_option("equalalways", true)', {})
+ nvim('exec_lua', 'vim.api.nvim_set_option_value("equalalways", true, {})', {})
status, rv = pcall(nvim, 'command_output',
'verbose set equalalways?')
eq(true, status)
eq(' equalalways\n\tLast set from Lua', rv)
end)
- end)
- describe('nvim_get_option_value, nvim_set_option_value', function()
- it('works', function()
- ok(nvim('get_option_value', 'equalalways', {}))
- nvim('set_option_value', 'equalalways', false, {})
- ok(not nvim('get_option_value', 'equalalways', {}))
+ it('updates whether the option has ever been set #25025', function()
+ eq(false, nvim('get_option_info2', 'autochdir', {}).was_set)
+ nvim('set_option_value', 'autochdir', true, {})
+ eq(true, nvim('get_option_info2', 'autochdir', {}).was_set)
+
+ eq(false, nvim('get_option_info2', 'cmdwinheight', {}).was_set)
+ nvim('set_option_value', 'cmdwinheight', 10, {})
+ eq(true, nvim('get_option_info2', 'cmdwinheight', {}).was_set)
+
+ eq(false, nvim('get_option_info2', 'debug', {}).was_set)
+ nvim('set_option_value', 'debug', 'beep', {})
+ eq(true, nvim('get_option_info2', 'debug', {}).was_set)
+ end)
+
+ it('validation', function()
+ eq("Invalid 'scope': expected 'local' or 'global'",
+ pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 'bogus'}))
+ eq("Invalid 'scope': expected 'local' or 'global'",
+ pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'}))
+ eq("Invalid 'scope': expected String, got Integer",
+ pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42}))
+ eq("Invalid 'value': expected valid option type, got Array",
+ pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {}))
+ eq("Invalid value for option 'scrolloff': expected Number, got Boolean true",
+ pcall_err(nvim, 'set_option_value', 'scrolloff', true, {}))
+ eq("Invalid value for option 'scrolloff': expected Number, got String \"wrong\"",
+ pcall_err(nvim, 'set_option_value', 'scrolloff', 'wrong', {}))
end)
it('can get local values when global value is set', function()
@@ -1453,19 +1536,22 @@ describe('API', function()
-- Now try with options with a special "local is unset" value (e.g. 'undolevels')
nvim('set_option_value', 'undolevels', 1000, {})
- eq(1000, nvim('get_option_value', 'undolevels', {scope = 'local'}))
+ nvim('set_option_value', 'undolevels', 1200, {scope = 'local'})
+ eq(1200, nvim('get_option_value', 'undolevels', {scope = 'local'}))
nvim('set_option_value', 'undolevels', NIL, {scope = 'local'})
eq(-123456, nvim('get_option_value', 'undolevels', {scope = 'local'}))
+ eq(1000, nvim('get_option_value', 'undolevels', {}))
nvim('set_option_value', 'autoread', true, {})
- eq(true, nvim('get_option_value', 'autoread', {scope = 'local'}))
+ nvim('set_option_value', 'autoread', false, {scope = 'local'})
+ eq(false, nvim('get_option_value', 'autoread', {scope = 'local'}))
nvim('set_option_value', 'autoread', NIL, {scope = 'local'})
eq(NIL, nvim('get_option_value', 'autoread', {scope = 'local'}))
+ eq(true, nvim('get_option_value', 'autoread', {}))
end)
it('set window options', function()
- -- Same as to nvim_win_set_option
- nvim('set_option_value', 'colorcolumn', '4,3', {win=0})
+ nvim('set_option_value', 'colorcolumn', '4,3', {})
eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
command("set modified hidden")
command("enew") -- edit new buffer, window option is preserved
@@ -1473,7 +1559,6 @@ describe('API', function()
end)
it('set local window options', function()
- -- Different to nvim_win_set_option
nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'})
eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'}))
command("set modified hidden")
@@ -1484,11 +1569,11 @@ describe('API', function()
it('get buffer or window-local options', function()
nvim('command', 'new')
local buf = nvim('get_current_buf').id
- nvim('buf_set_option', buf, 'tagfunc', 'foobar')
+ nvim('set_option_value', 'tagfunc', 'foobar', {buf=buf})
eq('foobar', nvim('get_option_value', 'tagfunc', {buf = buf}))
local win = nvim('get_current_win').id
- nvim('win_set_option', win, 'number', true)
+ nvim('set_option_value', 'number', true, {win=win})
eq(true, nvim('get_option_value', 'number', {win = win}))
end)
@@ -1502,6 +1587,40 @@ describe('API', function()
nvim('get_option_value', 'filetype', {buf = buf})
eq({1, 9}, nvim('win_get_cursor', win))
end)
+
+ it('can get default option values for filetypes', function()
+ command('filetype plugin on')
+ for ft, opts in pairs {
+ lua = { commentstring = '-- %s' },
+ vim = { commentstring = '"%s' },
+ man = { tagfunc = 'v:lua.require\'man\'.goto_tag' },
+ xml = { formatexpr = 'xmlformat#Format()' }
+ } do
+ for option, value in pairs(opts) do
+ eq(value, nvim('get_option_value', option, { filetype = ft }))
+ end
+ end
+
+ command'au FileType lua setlocal commentstring=NEW\\ %s'
+
+ eq('NEW %s', nvim('get_option_value', 'commentstring', { filetype = 'lua' }))
+ end)
+
+ it('errors for bad FileType autocmds', function()
+ command'au FileType lua setlocal commentstring=BAD'
+ eq([[FileType Autocommands for "lua": Vim(setlocal):E537: 'commentstring' must be empty or contain %s: commentstring=BAD]],
+ pcall_err(nvim, 'get_option_value', 'commentstring', { filetype = 'lua' }))
+ end)
+
+ it("value of 'modified' is always false for scratch buffers", function()
+ nvim('set_current_buf', nvim('create_buf', true, true))
+ insert([[
+ foo
+ bar
+ baz
+ ]])
+ eq(false, nvim('get_option_value', 'modified', {}))
+ end)
end)
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
@@ -1774,15 +1893,32 @@ describe('API', function()
feed('<C-D>')
expect('a') -- recognized i_0_CTRL-D
end)
+
+ it("does not interrupt with 'digraph'", function()
+ command('set digraph')
+ feed('i,')
+ eq(2, eval('1+1')) -- causes K_EVENT key
+ feed('<BS>')
+ eq(2, eval('1+1')) -- causes K_EVENT key
+ feed('.')
+ expect('…') -- digraph ",." worked
+ feed('<Esc>')
+ feed(':,')
+ eq(2, eval('1+1')) -- causes K_EVENT key
+ feed('<BS>')
+ eq(2, eval('1+1')) -- causes K_EVENT key
+ feed('.')
+ eq('…', funcs.getcmdline()) -- digraph ",." worked
+ end)
end)
describe('nvim_get_context', function()
- it('validates args', function()
+ it('validation', function()
eq("Invalid key: 'blah'",
pcall_err(nvim, 'get_context', {blah={}}))
- eq('invalid value for key: types',
+ eq("Invalid 'types': expected Array, got Integer",
pcall_err(nvim, 'get_context', {types=42}))
- eq('unexpected type: zub',
+ eq("Invalid 'type': 'zub'",
pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}}))
end)
it('returns map of current editor state', function()
@@ -1843,6 +1979,13 @@ describe('API', function()
nvim('load_context', ctx)
eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]'))
end)
+
+ it('errors when context dictionary is invalid', function()
+ eq('E474: Failed to convert list to msgpack string buffer',
+ pcall_err(nvim, 'load_context', { regs = { {} }, jumps = { {} } }))
+ eq("Empty dictionary keys aren't allowed",
+ pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } }))
+ end)
end)
describe('nvim_replace_termcodes', function()
@@ -1886,6 +2029,12 @@ describe('API', function()
-- value.
eq('', meths.replace_termcodes('', true, true, true))
end)
+
+ -- Not exactly the case, as nvim_replace_termcodes() escapes K_SPECIAL in Unicode
+ it('translates the result of keytrans() on string with 0x80 byte back', function()
+ local s = 'ff\128\253\097tt'
+ eq(s, meths.replace_termcodes(funcs.keytrans(s), true, true, true))
+ end)
end)
describe('nvim_feedkeys', function()
@@ -1916,6 +2065,19 @@ describe('API', function()
end)
describe('nvim_out_write', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(40, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ [1] = {bold = true, foreground = Screen.colors.SeaGreen},
+ [2] = {bold = true, reverse = true},
+ [3] = {foreground = Screen.colors.Blue},
+ })
+ end)
+
it('prints long messages correctly #20534', function()
exec([[
set more
@@ -1935,6 +2097,46 @@ describe('API', function()
]])
eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out'))
end)
+
+ it('blank line in message', function()
+ feed([[:call nvim_out_write("\na\n")<CR>]])
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {2: }|
+ |
+ a |
+ {1:Press ENTER or type command to continue}^ |
+ ]]}
+ feed('<CR>')
+ feed([[:call nvim_out_write("b\n\nc\n")<CR>]])
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {2: }|
+ b |
+ |
+ c |
+ {1:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
+
+ it('NUL bytes in message', function()
+ feed([[:lua vim.api.nvim_out_write('aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')<CR>]])
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {2: }|
+ aaa{3:^@}bbb{3:^@^@}ccc |
+ ddd{3:^@^@^@}eee |
+ {1:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
end)
describe('nvim_err_write', function()
@@ -2023,6 +2225,60 @@ describe('API', function()
]])
feed('<cr>') -- exit the press ENTER screen
end)
+
+ it('NUL bytes in message', function()
+ nvim_async('err_write', 'aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3: }|
+ {1:aaa^@bbb^@^@ccc} |
+ {1:ddd^@^@^@eee} |
+ {2:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
+ end)
+
+ describe('nvim_err_writeln', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(40, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {bold=true, foreground=Screen.colors.Blue},
+ [1] = {foreground = Screen.colors.White, background = Screen.colors.Red},
+ [2] = {bold = true, foreground = Screen.colors.SeaGreen},
+ [3] = {bold = true, reverse = true},
+ })
+ end)
+
+ it('shows only one return prompt after all lines are shown', function()
+ nvim_async('err_writeln', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK')
+ screen:expect([[
+ |
+ {0:~ }|
+ {3: }|
+ {1:FAILURE} |
+ {1:ERROR} |
+ {1:EXCEPTION} |
+ {1:TRACEBACK} |
+ {2:Press ENTER or type command to continue}^ |
+ ]])
+ feed('<CR>')
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
end)
describe('nvim_list_chans, nvim_get_chan_info', function()
@@ -2115,7 +2371,7 @@ describe('API', function()
it('stream=job :terminal channel', function()
command(':terminal')
eq({id=1}, meths.get_current_buf())
- eq(3, meths.buf_get_option(1, 'channel'))
+ eq(3, meths.get_option_value('channel', {buf=1}))
local info = {
stream='job',
@@ -2223,15 +2479,14 @@ describe('API', function()
eq(5, meths.get_var('avar'))
end)
- it('throws error on malformed arguments', function()
+ it('validation', function()
local req = {
{'nvim_set_var', {'avar', 1}},
{'nvim_set_var'},
{'nvim_set_var', {'avar', 2}},
}
- local status, err = pcall(meths.call_atomic, req)
- eq(false, status)
- ok(err:match('Items in calls array must be arrays of size 2') ~= nil)
+ eq("Invalid 'calls' item: expected 2-item Array",
+ pcall_err(meths.call_atomic, req))
-- call before was done, but not after
eq(1, meths.get_var('avar'))
@@ -2239,18 +2494,16 @@ describe('API', function()
{ 'nvim_set_var', { 'bvar', { 2, 3 } } },
12,
}
- status, err = pcall(meths.call_atomic, req)
- eq(false, status)
- ok(err:match('Items in calls array must be arrays') ~= nil)
+ eq("Invalid 'calls' item: expected Array, got Integer",
+ pcall_err(meths.call_atomic, req))
eq({2,3}, meths.get_var('bvar'))
req = {
{'nvim_set_current_line', 'little line'},
{'nvim_set_var', {'avar', 3}},
}
- status, err = pcall(meths.call_atomic, req)
- eq(false, status)
- ok(err:match('Args must be Array') ~= nil)
+ eq("Invalid call args: expected Array, got String",
+ pcall_err(meths.call_atomic, req))
-- call before was done, but not after
eq(1, meths.get_var('avar'))
eq({''}, meths.buf_get_lines(0, 0, -1, true))
@@ -2271,45 +2524,45 @@ describe('API', function()
end)
it('returns nothing with empty &runtimepath', function()
- meths.set_option('runtimepath', '')
+ meths.set_option_value('runtimepath', '', {})
eq({}, meths.list_runtime_paths())
end)
it('returns single runtimepath', function()
- meths.set_option('runtimepath', 'a')
+ meths.set_option_value('runtimepath', 'a', {})
eq({'a'}, meths.list_runtime_paths())
end)
it('returns two runtimepaths', function()
- meths.set_option('runtimepath', 'a,b')
+ meths.set_option_value('runtimepath', 'a,b', {})
eq({'a', 'b'}, meths.list_runtime_paths())
end)
it('returns empty strings when appropriate', function()
- meths.set_option('runtimepath', 'a,,b')
+ meths.set_option_value('runtimepath', 'a,,b', {})
eq({'a', '', 'b'}, meths.list_runtime_paths())
- meths.set_option('runtimepath', ',a,b')
+ meths.set_option_value('runtimepath', ',a,b', {})
eq({'', 'a', 'b'}, meths.list_runtime_paths())
-- Trailing "," is ignored. Use ",," if you really really want CWD.
- meths.set_option('runtimepath', 'a,b,')
+ meths.set_option_value('runtimepath', 'a,b,', {})
eq({'a', 'b'}, meths.list_runtime_paths())
- meths.set_option('runtimepath', 'a,b,,')
+ meths.set_option_value('runtimepath', 'a,b,,', {})
eq({'a', 'b', ''}, meths.list_runtime_paths())
end)
it('truncates too long paths', function()
local long_path = ('/a'):rep(8192)
- meths.set_option('runtimepath', long_path)
+ meths.set_option_value('runtimepath', long_path, {})
local paths_list = meths.list_runtime_paths()
eq({}, paths_list)
end)
end)
it('can throw exceptions', function()
- local status, err = pcall(nvim, 'get_option', 'invalid-option')
+ local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {})
eq(false, status)
- ok(err:match('Invalid option name') ~= nil)
+ ok(err:match("Unknown option 'invalid%-option'") ~= nil)
end)
it('does not truncate error message <1 MB #5984', function()
local very_long_name = 'A'..('x'):rep(10000)..'Z'
- local status, err = pcall(nvim, 'get_option', very_long_name)
+ local status, err = pcall(nvim, 'get_option_value', very_long_name, {})
eq(false, status)
eq(very_long_name, err:match('Ax+Z?'))
end)
@@ -2322,7 +2575,7 @@ describe('API', function()
describe('nvim_parse_expression', function()
before_each(function()
- meths.set_option('isident', '')
+ meths.set_option_value('isident', '', {})
end)
local function simplify_east_api_node(line, east_api_node)
@@ -2536,20 +2789,26 @@ describe('API', function()
{
chan = 1,
ext_cmdline = false,
- ext_popupmenu = false,
- ext_tabline = false,
- ext_wildmenu = false,
+ ext_hlstate = false,
ext_linegrid = screen._options.ext_linegrid or false,
+ ext_messages = false,
ext_multigrid = false,
- ext_hlstate = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
ext_termcolors = false,
- ext_messages = false,
+ ext_wildmenu = false,
height = 4,
- rgb = true,
override = true,
+ rgb = true,
+ stdin_tty = false,
+ stdout_tty = false,
+ term_background = '',
+ term_colors = 0,
+ term_name = '',
width = 20,
}
}
+
eq(expected, nvim("list_uis"))
screen:detach()
@@ -2601,9 +2860,9 @@ describe('API', function()
end)
it('can change buftype before visiting', function()
- meths.set_option("hidden", false)
+ meths.set_option_value("hidden", false, {})
eq({id=2}, meths.create_buf(true, false))
- meths.buf_set_option(2, "buftype", "nofile")
+ meths.set_option_value("buftype", "nofile", {buf=2})
meths.buf_set_lines(2, 0, -1, true, {"test text"})
command("split | buffer 2")
eq({id=2}, meths.get_current_buf())
@@ -2622,6 +2881,18 @@ describe('API', function()
eq(false, eval('g:fired'))
end)
+ it('TextChanged and TextChangedI do not trigger without changes', function()
+ local buf = meths.create_buf(true, false)
+ command([[let g:changed = '']])
+ meths.create_autocmd({'TextChanged', 'TextChangedI'}, {
+ buffer = buf,
+ command = 'let g:changed ..= mode()',
+ })
+ meths.set_current_buf(buf)
+ feed('i')
+ eq('', meths.get_var('changed'))
+ end)
+
it('scratch-buffer', function()
eq({id=2}, meths.create_buf(false, true))
eq({id=3}, meths.create_buf(true, true))
@@ -2630,7 +2901,7 @@ describe('API', function()
eq(' 1 %a "[No Name]" line 1\n'..
' 3 h "[Scratch]" line 0\n'..
' 4 h "[Scratch]" line 0',
- meths.exec('ls', true))
+ exec_capture('ls'))
-- current buffer didn't change
eq({id=1}, meths.get_current_buf())
@@ -2646,10 +2917,10 @@ describe('API', function()
local edited_buf = 2
meths.buf_set_lines(edited_buf, 0, -1, true, {"some text"})
for _,b in ipairs(scratch_bufs) do
- eq('nofile', meths.buf_get_option(b, 'buftype'))
- eq('hide', meths.buf_get_option(b, 'bufhidden'))
- eq(false, meths.buf_get_option(b, 'swapfile'))
- eq(false, meths.buf_get_option(b, 'modeline'))
+ eq('nofile', meths.get_option_value('buftype', {buf=b}))
+ eq('hide', meths.get_option_value('bufhidden', {buf=b}))
+ eq(false, meths.get_option_value('swapfile', {buf=b}))
+ eq(false, meths.get_option_value('modeline', {buf=b}))
end
--
@@ -2662,10 +2933,10 @@ describe('API', function()
{1:~ }|
|
]])
- eq('nofile', meths.buf_get_option(edited_buf, 'buftype'))
- eq('hide', meths.buf_get_option(edited_buf, 'bufhidden'))
- eq(false, meths.buf_get_option(edited_buf, 'swapfile'))
- eq(false, meths.buf_get_option(edited_buf, 'modeline'))
+ eq('nofile', meths.get_option_value('buftype', {buf=edited_buf}))
+ eq('hide', meths.get_option_value('bufhidden', {buf=edited_buf}))
+ eq(false, meths.get_option_value('swapfile', {buf=edited_buf}))
+ eq(false, meths.get_option_value('modeline', {buf=edited_buf}))
-- Scratch buffer can be wiped without error.
command('bwipe')
@@ -2679,7 +2950,9 @@ describe('API', function()
it('does not cause heap-use-after-free on exit while setting options', function()
command('au OptionSet * q')
- expect_exit(command, 'silent! call nvim_create_buf(0, 1)')
+ command('silent! call nvim_create_buf(0, 1)')
+ -- nowadays this works because we don't execute any spurious autocmds at all #24824
+ assert_alive()
end)
end)
@@ -2744,13 +3017,13 @@ describe('API', function()
end)
it('should not crash when echoed', function()
- meths.exec("echo nvim_get_all_options_info()", true)
+ meths.exec2("echo nvim_get_all_options_info()", { output = true })
end)
end)
describe('nvim_get_option_info', function()
it('should error for unknown options', function()
- eq("no such option: 'bogus'", pcall_err(meths.get_option_info, 'bogus'))
+ eq("Invalid option (not found): 'bogus'", pcall_err(meths.get_option_info, 'bogus'))
end)
it('should return the same options for short and long name', function()
@@ -2796,7 +3069,7 @@ describe('API', function()
it('should have information about global options', function()
-- precondition: the option was changed from its default
-- in test setup.
- eq(false, meths.get_option'showcmd')
+ eq(false, meths.get_option_value('showcmd', {}))
eq({
allows_duplicates = true,
@@ -2813,6 +3086,117 @@ describe('API', function()
type = "boolean",
was_set = true
}, meths.get_option_info'showcmd')
+
+ meths.set_option_value('showcmd', true, {})
+
+ eq({
+ allows_duplicates = true,
+ commalist = false,
+ default = true,
+ flaglist = false,
+ global_local = false,
+ last_set_chan = 1,
+ last_set_linenr = 0,
+ last_set_sid = -9,
+ name = "showcmd",
+ scope = "global",
+ shortname = "sc",
+ type = "boolean",
+ was_set = true
+ }, meths.get_option_info'showcmd')
+ end)
+ end)
+
+ describe('nvim_get_option_info2', function()
+ local fname
+ local bufs
+ local wins
+
+ before_each(function()
+ fname = tmpname()
+ write_file(fname, [[
+ setglobal dictionary=mydict " 1, global-local (buffer)
+ setlocal formatprg=myprg " 2, global-local (buffer)
+ setglobal equalprg=prg1 " 3, global-local (buffer)
+ setlocal equalprg=prg2 " 4, global-local (buffer)
+ setglobal fillchars=stl:x " 5, global-local (window)
+ setlocal listchars=eol:c " 6, global-local (window)
+ setglobal showbreak=aaa " 7, global-local (window)
+ setlocal showbreak=bbb " 8, global-local (window)
+ setglobal completeopt=menu " 9, global
+ ]])
+
+ exec_lua 'vim.cmd.vsplit()'
+ meths.create_buf(false, false)
+
+ bufs = meths.list_bufs()
+ wins = meths.list_wins()
+
+ meths.win_set_buf(wins[1].id, bufs[1].id)
+ meths.win_set_buf(wins[2].id, bufs[2].id)
+
+ meths.set_current_win(wins[2].id)
+ meths.exec('source ' .. fname, false)
+
+ meths.set_current_win(wins[1].id)
+ end)
+
+ after_each(function()
+ os.remove(fname)
+ end)
+
+ it('should return option information', function()
+ eq(meths.get_option_info('dictionary'), meths.get_option_info2('dictionary', {})) -- buffer
+ eq(meths.get_option_info('fillchars'), meths.get_option_info2('fillchars', {})) -- window
+ eq(meths.get_option_info('completeopt'), meths.get_option_info2('completeopt', {})) -- global
+ end)
+
+ describe('last set', function()
+ local tests = {
+ {desc="(buf option, global requested, global set) points to global", linenr=1, sid=1, args={'dictionary', {scope='global'}}},
+ {desc="(buf option, global requested, local set) is not set", linenr=0, sid=0, args={'formatprg', {scope='global'}}},
+ {desc="(buf option, global requested, both set) points to global", linenr=3, sid=1, args={'equalprg', {scope='global'}}},
+ {desc="(buf option, local requested, global set) is not set", linenr=0, sid=0, args={'dictionary', {scope='local'}}},
+ {desc="(buf option, local requested, local set) points to local", linenr=2, sid=1, args={'formatprg', {scope='local'}}},
+ {desc="(buf option, local requested, both set) points to local", linenr=4, sid=1, args={'equalprg', {scope='local'}}},
+ {desc="(buf option, fallback requested, global set) points to global", linenr=1, sid=1, args={'dictionary', {}}},
+ {desc="(buf option, fallback requested, local set) points to local", linenr=2, sid=1, args={'formatprg', {}}},
+ {desc="(buf option, fallback requested, both set) points to local", linenr=4, sid=1, args={'equalprg', {}}},
+ {desc="(win option, global requested, global set) points to global", linenr=5, sid=1, args={'fillchars', {scope='global'}}},
+ {desc="(win option, global requested, local set) is not set", linenr=0, sid=0, args={'listchars', {scope='global'}}},
+ {desc="(win option, global requested, both set) points to global", linenr=7, sid=1, args={'showbreak', {scope='global'}}},
+ {desc="(win option, local requested, global set) is not set", linenr=0, sid=0, args={'fillchars', {scope='local'}}},
+ {desc="(win option, local requested, local set) points to local", linenr=6, sid=1, args={'listchars', {scope='local'}}},
+ {desc="(win option, local requested, both set) points to local", linenr=8, sid=1, args={'showbreak', {scope='local'}}},
+ {desc="(win option, fallback requested, global set) points to global", linenr=5, sid=1, args={'fillchars', {}}},
+ {desc="(win option, fallback requested, local set) points to local", linenr=6, sid=1, args={'listchars', {}}},
+ {desc="(win option, fallback requested, both set) points to local", linenr=8, sid=1, args={'showbreak', {}}},
+ {desc="(global option, global requested) points to global", linenr=9, sid=1, args={'completeopt', {scope='global'}}},
+ {desc="(global option, local requested) is not set", linenr=0, sid=0, args={'completeopt', {scope='local'}}},
+ {desc="(global option, fallback requested) points to global", linenr=9, sid=1, args={'completeopt', {}}},
+ }
+
+ for _, t in pairs(tests) do
+ it(t.desc, function()
+ -- Switch to the target buffer/window so that curbuf/curwin are used.
+ meths.set_current_win(wins[2].id)
+ local info = meths.get_option_info2(unpack(t.args))
+ eq(t.linenr, info.last_set_linenr)
+ eq(t.sid, info.last_set_sid)
+ end)
+ end
+
+ it('is provided for cross-buffer requests', function()
+ local info = meths.get_option_info2('formatprg', {buf=bufs[2].id})
+ eq(2, info.last_set_linenr)
+ eq(1, info.last_set_sid)
+ end)
+
+ it('is provided for cross-window requests', function()
+ local info = meths.get_option_info2('listchars', {win=wins[2].id})
+ eq(6, info.last_set_linenr)
+ eq(1, info.last_set_sid)
+ end)
end)
end)
@@ -2820,11 +3204,10 @@ describe('API', function()
local screen
before_each(function()
- clear()
screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
- [0] = {bold=true, foreground=Screen.colors.Blue},
+ [0] = {bold = true, foreground = Screen.colors.Blue},
[1] = {bold = true, foreground = Screen.colors.SeaGreen},
[2] = {bold = true, reverse = true},
[3] = {foreground = Screen.colors.Brown, bold = true}, -- Statement
@@ -2879,13 +3262,13 @@ describe('API', function()
it('can save message history', function()
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
nvim("echo", {{"msg\nmsg"}, {"msg"}}, true, {})
- eq("msg\nmsgmsg", meths.exec('messages', true))
+ eq("msg\nmsgmsg", exec_capture('messages'))
end)
it('can disable saving message history', function()
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
nvim_async("echo", {{"msg\nmsg"}, {"msg"}}, false, {})
- eq("", meths.exec("messages", true))
+ eq("", exec_capture('messages'))
end)
end)
@@ -2894,7 +3277,6 @@ describe('API', function()
local screen
before_each(function()
- clear()
screen = Screen.new(100, 35)
screen:attach()
screen:set_default_attr_ids({
@@ -3031,10 +3413,10 @@ describe('API', function()
eq(true, meths.del_mark('F'))
eq({0, 0}, meths.buf_get_mark(buf, 'F'))
end)
- it('fails when invalid marks are used', function()
- eq(false, pcall(meths.del_mark, 'f'))
- eq(false, pcall(meths.del_mark, '!'))
- eq(false, pcall(meths.del_mark, 'fail'))
+ it('validation', function()
+ eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.del_mark, 'f'))
+ eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.del_mark, '!'))
+ eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.del_mark, 'fail'))
end)
end)
describe('nvim_get_mark', function()
@@ -3048,10 +3430,10 @@ describe('API', function()
assert(string.find(mark[4], "mybuf$"))
eq({2, 2, buf.id, mark[4]}, mark)
end)
- it('fails when invalid marks are used', function()
- eq(false, pcall(meths.del_mark, 'f'))
- eq(false, pcall(meths.del_mark, '!'))
- eq(false, pcall(meths.del_mark, 'fail'))
+ it('validation', function()
+ eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.get_mark, 'f', {}))
+ eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.get_mark, '!', {}))
+ eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.get_mark, 'fail', {}))
end)
it('returns the expected when mark is not set', function()
eq(true, meths.del_mark('A'))
@@ -3113,15 +3495,15 @@ describe('API', function()
meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 }))
end)
it('rejects multiple-character fillchar', function()
- eq('fillchar must be a single character',
+ eq("Invalid 'fillchar': expected single character",
pcall_err(meths.eval_statusline, '', { fillchar = 'aa' }))
end)
it('rejects empty string fillchar', function()
- eq('fillchar must be a single character',
+ eq("Invalid 'fillchar': expected single character",
pcall_err(meths.eval_statusline, '', { fillchar = '' }))
end)
it('rejects non-string fillchar', function()
- eq('fillchar must be a single character',
+ eq("Invalid 'fillchar': expected String, got Integer",
pcall_err(meths.eval_statusline, '', { fillchar = 1 }))
end)
it('rejects invalid string', function()
@@ -3213,6 +3595,38 @@ describe('API', function()
'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
{ use_winbar = true, highlights = true }))
end)
+ it('works with statuscolumn', function()
+ exec([[
+ let &stc='%C%s%=%l '
+ set cul nu nuw=3 scl=yes:2 fdc=2
+ call setline(1, repeat(['aaaaa'], 5))
+ let g:ns = nvim_create_namespace('')
+ call sign_define('a', {'text':'aa', 'texthl':'IncSearch', 'numhl':'Normal'})
+ call sign_place(2, 1, 'a', bufnr(), {'lnum':4})
+ call nvim_buf_set_extmark(0, g:ns, 3, 1, { 'sign_text':'bb', 'sign_hl_group':'ErrorMsg' })
+ 1,5fold | 1,5 fold | foldopen!
+ norm 4G
+ ]])
+ eq({
+ str = '││aabb 4 ',
+ width = 9,
+ highlights = {
+ { group = 'CursorLineFold', start = 0 },
+ { group = 'Normal', start = 6 },
+ { group = 'IncSearch', start = 6 },
+ { group = 'ErrorMsg', start = 8 },
+ { group = 'Normal', start = 10 }
+ }
+ }, meths.eval_statusline('%C%s%=%l ', { use_statuscol_lnum = 4, highlights = true }))
+ eq({
+ str = '3 ' ,
+ width = 2,
+ highlights = {
+ { group = 'LineNr', start = 0 },
+ { group = 'ErrorMsg', start = 1 }
+ }
+ }, meths.eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true }))
+ end)
it('no memory leak with click functions', function()
meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {})
eq({
@@ -3226,6 +3640,7 @@ describe('API', function()
end)
end)
end)
+
describe('nvim_parse_cmd', function()
it('works', function()
eq({
@@ -3708,7 +4123,7 @@ describe('API', function()
}
}, meths.parse_cmd('MyCommand test it', {}))
end)
- it('errors for invalid command', function()
+ it('validates command', function()
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {}))
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {}))
eq('Error while parsing command line: E492: Not an editor command: Fubar',
@@ -3807,20 +4222,87 @@ describe('API', function()
meths.cmd(meths.parse_cmd("set cursorline", {}), {})
eq(true, meths.get_option_value("cursorline", {}))
end)
+ it('no side-effects (error messages) in pcall() #20339', function()
+ eq({ false, 'Error while parsing command line: E16: Invalid range' },
+ exec_lua([=[return {pcall(vim.api.nvim_parse_cmd, "'<,'>n", {})}]=]))
+ eq('', eval('v:errmsg'))
+ end)
end)
+
describe('nvim_cmd', function()
it('works', function ()
meths.cmd({ cmd = "set", args = { "cursorline" } }, {})
eq(true, meths.get_option_value("cursorline", {}))
end)
+
+ it('validation', function()
+ eq("Invalid 'cmd': expected non-empty String",
+ pcall_err(meths.cmd, { cmd = ""}, {}))
+ eq("Invalid 'cmd': expected String, got Array",
+ pcall_err(meths.cmd, { cmd = {}}, {}))
+ eq("Invalid 'args': expected Array, got Boolean",
+ pcall_err(meths.cmd, { cmd = "set", args = true }, {}))
+ eq("Invalid command arg: expected non-whitespace",
+ pcall_err(meths.cmd, { cmd = "set", args = {' '}, }, {}))
+ eq("Invalid command arg: expected valid type, got Array",
+ pcall_err(meths.cmd, { cmd = "set", args = {{}}, }, {}))
+ eq("Wrong number of arguments",
+ pcall_err(meths.cmd, { cmd = "aboveleft", args = {}, }, {}))
+ eq("Command cannot accept bang: print",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, bang = true }, {}))
+
+ eq("Command cannot accept range: set",
+ pcall_err(meths.cmd, { cmd = "set", args = {}, range = {1} }, {}))
+ eq("Invalid 'range': expected Array, got Boolean",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, range = true }, {}))
+ eq("Invalid 'range': expected <=2 elements",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, range = {1,2,3,4} }, {}))
+ eq("Invalid range element: expected non-negative Integer",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, range = {-1} }, {}))
+
+ eq("Command cannot accept count: set",
+ pcall_err(meths.cmd, { cmd = "set", args = {}, count = 1 }, {}))
+ eq("Invalid 'count': expected Integer, got Boolean",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, count = true }, {}))
+ eq("Invalid 'count': expected non-negative Integer",
+ pcall_err(meths.cmd, { cmd = "print", args = {}, count = -1 }, {}))
+
+ eq("Command cannot accept register: set",
+ pcall_err(meths.cmd, { cmd = "set", args = {}, reg = 'x' }, {}))
+ eq('Cannot use register "=',
+ pcall_err(meths.cmd, { cmd = "put", args = {}, reg = '=' }, {}))
+ eq("Invalid 'reg': expected single character, got xx",
+ pcall_err(meths.cmd, { cmd = "put", args = {}, reg = 'xx' }, {}))
+
+ -- #20681
+ eq('Invalid command: "win_getid"', pcall_err(meths.cmd, { cmd = 'win_getid'}, {}))
+ eq('Invalid command: "echo "hi""', pcall_err(meths.cmd, { cmd = 'echo "hi"'}, {}))
+ eq('Invalid command: "win_getid"', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]]))
+
+ -- Lua call allows empty {} for dict item.
+ eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]]))
+ eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]]))
+ eq('', meths.cmd({ cmd = "set", args = {}, magic = {} }, {}))
+
+ -- Lua call does not allow non-empty list-like {} for dict item.
+ eq("Invalid 'magic': Expected Dict-like Lua table",
+ pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { 'a' } }]]))
+ eq("Invalid key: 'bogus'",
+ pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { bogus = true } }]]))
+ eq("Invalid key: 'bogus'",
+ pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, mods = { bogus = true } }]]))
+ end)
+
it('captures output', function()
eq("foo", meths.cmd({ cmd = "echo", args = { '"foo"' } }, { output = true }))
end)
+
it('sets correct script context', function()
meths.cmd({ cmd = "set", args = { "cursorline" } }, {})
- local str = meths.exec([[verbose set cursorline?]], true)
+ local str = exec_capture([[verbose set cursorline?]])
neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)"))
end)
+
it('works with range', function()
insert [[
line1
@@ -3867,7 +4349,7 @@ describe('API', function()
line6
]]
meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {})
- meths.exec("1put a", false)
+ command('1put a')
expect [[
line1
line2
@@ -3914,7 +4396,7 @@ describe('API', function()
meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = true } } },
{ output = true }))
- -- with emsg_silent = true error is suppresed
+ -- with emsg_silent = true error is suppressed
feed([[:lua vim.api.nvim_cmd({ cmd = 'call', mods = { emsg_silent = true } }, {})<CR>]])
eq('', meths.cmd({ cmd = 'messages' }, { output = true }))
-- error from the next command typed is not suppressed #21420
@@ -3927,16 +4409,16 @@ describe('API', function()
vim.api.nvim_echo({{ opts.fargs[1] }}, false, {})
end, { nargs = 1 })
]])
- eq(lfs.currentdir(),
+ eq(luv.cwd(),
meths.cmd({ cmd = "Foo", args = { '%:p:h' }, magic = { file = true } },
{ output = true }))
end)
it('splits arguments correctly', function()
- meths.exec([[
+ exec([[
function! FooFunc(...)
echo a:000
endfunction
- ]], false)
+ ]])
meths.create_user_command("Foo", "call FooFunc(<f-args>)", { nargs = '+' })
eq([=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=],
meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}},
@@ -3948,7 +4430,7 @@ describe('API', function()
it('splits arguments correctly for Lua callback', function()
meths.exec_lua([[
local function FooFunc(opts)
- vim.pretty_print(opts.fargs)
+ vim.print(opts.fargs)
end
vim.api.nvim_create_user_command("Foo", FooFunc, { nargs = '+' })
@@ -4054,8 +4536,6 @@ describe('API', function()
eq('1', meths.cmd({cmd = 'echo', args = {true}}, {output = true}))
end)
describe('first argument as count', function()
- before_each(clear)
-
it('works', function()
command('vsplit | enew')
meths.cmd({cmd = 'bdelete', args = {meths.get_current_buf()}}, {})
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index ecab6a4713..6737c2d15b 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -43,6 +43,25 @@ describe('API/win', function()
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
end)
+
+ it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function()
+ local new_buf = meths.create_buf(true, true)
+ local old_win = meths.get_current_win()
+ local new_win = meths.open_win(new_buf, false, {
+ relative='editor', row=10, col=10, width=50, height=10,
+ })
+ feed('q:')
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_set_buf, 0, new_buf))
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_set_buf, old_win, new_buf))
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_set_buf, new_win, 0))
+
+ local next_buf = meths.create_buf(true, true)
+ meths.win_set_buf(new_win, next_buf)
+ eq(next_buf, meths.win_get_buf(new_win))
+ end)
end)
describe('{get,set}_cursor', function()
@@ -285,6 +304,22 @@ describe('API/win', function()
eq(2, window('get_height', nvim('list_wins')[2]))
end)
+ it('correctly handles height=1', function()
+ nvim('command', 'split')
+ nvim('set_current_win', nvim('list_wins')[1])
+ window('set_height', nvim('list_wins')[2], 1)
+ eq(1, window('get_height', nvim('list_wins')[2]))
+ end)
+
+ it('correctly handles height=1 with a winbar', function()
+ nvim('command', 'set winbar=foobar')
+ nvim('command', 'set winminheight=0')
+ nvim('command', 'split')
+ nvim('set_current_win', nvim('list_wins')[1])
+ window('set_height', nvim('list_wins')[2], 1)
+ eq(1, window('get_height', nvim('list_wins')[2]))
+ end)
+
it('do not cause ml_get errors with foldmethod=expr #19989', function()
insert([[
aaaaa
@@ -363,22 +398,22 @@ describe('API/win', function()
end)
end)
- describe('nvim_win_get_option, nvim_win_set_option', function()
+ describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function()
- curwin('set_option', 'colorcolumn', '4,3')
- eq('4,3', curwin('get_option', 'colorcolumn'))
+ nvim('set_option_value', 'colorcolumn', '4,3', {})
+ eq('4,3', nvim('get_option_value', 'colorcolumn', {}))
command("set modified hidden")
command("enew") -- edit new buffer, window option is preserved
- eq('4,3', curwin('get_option', 'colorcolumn'))
+ eq('4,3', nvim('get_option_value', 'colorcolumn', {}))
-- global-local option
- curwin('set_option', 'statusline', 'window-status')
- eq('window-status', curwin('get_option', 'statusline'))
- eq('', nvim('get_option', 'statusline'))
+ nvim('set_option_value', 'statusline', 'window-status', {win=0})
+ eq('window-status', nvim('get_option_value', 'statusline', {win=0}))
+ eq('', nvim('get_option_value', 'statusline', {scope='global'}))
command("set modified")
command("enew") -- global-local: not preserved in new buffer
-- confirm local value was not copied
- eq('', curwin('get_option', 'statusline'))
+ eq('', nvim('get_option_value', 'statusline', {win = 0}))
eq('', eval('&l:statusline'))
end)
@@ -386,16 +421,16 @@ describe('API/win', function()
nvim('command', 'tabnew')
local tab1 = unpack(nvim('list_tabpages'))
local win1 = unpack(tabpage('list_wins', tab1))
- window('set_option', win1, 'statusline', 'window-status')
+ nvim('set_option_value', 'statusline', 'window-status', {win=win1.id})
nvim('command', 'split')
nvim('command', 'wincmd J')
nvim('command', 'wincmd j')
- eq('window-status', window('get_option', win1, 'statusline'))
+ eq('window-status', nvim('get_option_value', 'statusline', {win = win1.id}))
assert_alive()
end)
it('returns values for unset local options', function()
- eq(-1, curwin('get_option', 'scrolloff'))
+ eq(-1, nvim('get_option_value', 'scrolloff', {win=0, scope='local'}))
end)
end)
@@ -508,15 +543,21 @@ describe('API/win', function()
command('split')
eq(2, #meths.list_wins())
local oldwin = meths.get_current_win()
+ local otherwin = meths.open_win(0, false, {
+ relative='editor', row=10, col=10, width=10, height=10,
+ })
-- Open cmdline-window.
feed('q:')
- eq(3, #meths.list_wins())
+ eq(4, #meths.list_wins())
eq(':', funcs.getcmdwintype())
- -- Vim: not allowed to close other windows from cmdline-window.
+ -- Not allowed to close previous window from cmdline-window.
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
- pcall_err(meths.win_close, oldwin, true))
+ pcall_err(meths.win_close, oldwin, true))
+ -- Closing other windows is fine.
+ meths.win_close(otherwin, true)
+ eq(false, meths.win_is_valid(otherwin))
-- Close cmdline-window.
- meths.win_close(0,true)
+ meths.win_close(0, true)
eq(2, #meths.list_wins())
eq('', funcs.getcmdwintype())
end)
@@ -568,15 +609,247 @@ describe('API/win', function()
it('deletes the buffer when bufhidden=wipe', function()
local oldwin = meths.get_current_win()
local oldbuf = meths.get_current_buf()
- local buf = meths.create_buf(true, false)
+ local buf = meths.create_buf(true, false).id
local newwin = meths.open_win(buf, true, {
relative='win', row=3, col=3, width=12, height=3
})
- meths.buf_set_option(buf, 'bufhidden', 'wipe')
+ meths.set_option_value('bufhidden', 'wipe', {buf=buf})
meths.win_hide(newwin)
eq({oldwin}, meths.list_wins())
eq({oldbuf}, meths.list_bufs())
end)
+ it('in the cmdwin', function()
+ feed('q:')
+ -- Can close the cmdwin.
+ meths.win_hide(0)
+ eq('', funcs.getcmdwintype())
+
+ local old_win = meths.get_current_win()
+ local other_win = meths.open_win(0, false, {
+ relative='win', row=3, col=3, width=12, height=3
+ })
+ feed('q:')
+ -- Cannot close the previous window.
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_hide, old_win))
+ -- Can close other windows.
+ meths.win_hide(other_win)
+ eq(false, meths.win_is_valid(other_win))
+ end)
+ end)
+
+ describe('text_height', function()
+ it('validation', function()
+ local X = meths.get_vvar('maxcol')
+ insert([[
+ aaa
+ bbb
+ ccc
+ ddd
+ eee]])
+ eq("Invalid window id: 23",
+ pcall_err(meths.win_text_height, 23, {}))
+ eq("Line index out of bounds",
+ pcall_err(curwinmeths.text_height, { start_row = 5 }))
+ eq("Line index out of bounds",
+ pcall_err(curwinmeths.text_height, { start_row = -6 }))
+ eq("Line index out of bounds",
+ pcall_err(curwinmeths.text_height, { end_row = 5 }))
+ eq("Line index out of bounds",
+ pcall_err(curwinmeths.text_height, { end_row = -6 }))
+ eq("'start_row' is higher than 'end_row'",
+ pcall_err(curwinmeths.text_height, { start_row = 3, end_row = 1 }))
+ eq("'start_vcol' specified without 'start_row'",
+ pcall_err(curwinmeths.text_height, { end_row = 2, start_vcol = 0 }))
+ eq("'end_vcol' specified without 'end_row'",
+ pcall_err(curwinmeths.text_height, { start_row = 2, end_vcol = 0 }))
+ eq("Invalid 'start_vcol': out of range",
+ pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = -1 }))
+ eq("Invalid 'start_vcol': out of range",
+ pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = X + 1 }))
+ eq("Invalid 'end_vcol': out of range",
+ pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = -1 }))
+ eq("Invalid 'end_vcol': out of range",
+ pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = X + 1 }))
+ eq("'start_vcol' is higher than 'end_vcol'",
+ pcall_err(curwinmeths.text_height, { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 }))
+ end)
+
+ it('with two diff windows', function()
+ local X = meths.get_vvar('maxcol')
+ local screen = Screen.new(45, 22)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue1, bold = true};
+ [1] = {foreground = Screen.colors.Blue4, background = Screen.colors.Grey};
+ [2] = {foreground = Screen.colors.Brown};
+ [3] = {foreground = Screen.colors.Blue1, background = Screen.colors.LightCyan1, bold = true};
+ [4] = {background = Screen.colors.LightBlue};
+ [5] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey};
+ [6] = {background = Screen.colors.Plum1};
+ [7] = {background = Screen.colors.Red, bold = true};
+ [8] = {reverse = true};
+ [9] = {bold = true, reverse = true};
+ })
+ screen:attach()
+ exec([[
+ set diffopt+=context:2 number
+ let expr = 'printf("%08d", v:val) .. repeat("!", v:val)'
+ call setline(1, map(range(1, 20) + range(25, 45), expr))
+ vnew
+ call setline(1, map(range(3, 20) + range(28, 50), expr))
+ windo diffthis
+ ]])
+ feed('24gg')
+ screen:expect{grid=[[
+ {1: }{2: }{3:----------------}│{1: }{2: 1 }{4:00000001! }|
+ {1: }{2: }{3:----------------}│{1: }{2: 2 }{4:00000002!! }|
+ {1: }{2: 1 }00000003!!! │{1: }{2: 3 }00000003!!! |
+ {1: }{2: 2 }00000004!!!! │{1: }{2: 4 }00000004!!!! |
+ {1:+ }{2: 3 }{5:+-- 14 lines: 00}│{1:+ }{2: 5 }{5:+-- 14 lines: 00}|
+ {1: }{2: 17 }00000019!!!!!!!!│{1: }{2: 19 }00000019!!!!!!!!|
+ {1: }{2: 18 }00000020!!!!!!!!│{1: }{2: 20 }00000020!!!!!!!!|
+ {1: }{2: }{3:----------------}│{1: }{2: 21 }{4:00000025!!!!!!!!}|
+ {1: }{2: }{3:----------------}│{1: }{2: 22 }{4:00000026!!!!!!!!}|
+ {1: }{2: }{3:----------------}│{1: }{2: 23 }{4:00000027!!!!!!!!}|
+ {1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!|
+ {1: }{2: 20 }00000029!!!!!!!!│{1: }{2: 25 }00000029!!!!!!!!|
+ {1:+ }{2: 21 }{5:+-- 14 lines: 00}│{1:+ }{2: 26 }{5:+-- 14 lines: 00}|
+ {1: }{2: 35 }00000044!!!!!!!!│{1: }{2: 40 }00000044!!!!!!!!|
+ {1: }{2: 36 }00000045!!!!!!!!│{1: }{2: 41 }00000045!!!!!!!!|
+ {1: }{2: 37 }{4:00000046!!!!!!!!}│{1: }{2: }{3:----------------}|
+ {1: }{2: 38 }{4:00000047!!!!!!!!}│{1: }{2: }{3:----------------}|
+ {1: }{2: 39 }{4:00000048!!!!!!!!}│{1: }{2: }{3:----------------}|
+ {1: }{2: 40 }{4:00000049!!!!!!!!}│{1: }{2: }{3:----------------}|
+ {1: }{2: 41 }{4:00000050!!!!!!!!}│{1: }{2: }{3:----------------}|
+ {8:[No Name] [+] }{9:[No Name] [+] }|
+ |
+ ]]}
+ screen:try_resize(45, 3)
+ screen:expect{grid=[[
+ {1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!|
+ {8:[No Name] [+] }{9:[No Name] [+] }|
+ |
+ ]]}
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1000, {}))
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1001, {}))
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1000, { start_row = 0 }))
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { start_row = 0 }))
+ eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = -1 }))
+ eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = 40 }))
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = -1 }))
+ eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = 40 }))
+ eq({ all = 10, fill = 5 }, meths.win_text_height(1000, { start_row = 23 }))
+ eq({ all = 13, fill = 3 }, meths.win_text_height(1001, { start_row = 18 }))
+ eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { end_row = 23 }))
+ eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 }))
+ eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { start_row = 3, end_row = 39 }))
+ eq({ all = 11, fill = 3 }, meths.win_text_height(1001, { start_row = 1, end_row = 34 }))
+ eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 4, end_row = 38 }))
+ eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 2, end_row = 33 }))
+ eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 5, end_row = 37 }))
+ eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 3, end_row = 32 }))
+ eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 17, end_row = 25 }))
+ eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 15, end_row = 20 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(1000, { start_row = 18, end_row = 24 }))
+ eq({ all = 7, fill = 3 }, meths.win_text_height(1001, { start_row = 16, end_row = 19 }))
+ eq({ all = 6, fill = 5 }, meths.win_text_height(1000, { start_row = -1 }))
+ eq({ all = 5, fill = 5 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X }))
+ eq({ all = 0, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 }))
+ eq({ all = 0, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X }))
+ eq({ all = 3, fill = 2 }, meths.win_text_height(1001, { end_row = 0 }))
+ eq({ all = 2, fill = 2 }, meths.win_text_height(1001, { end_row = 0, end_vcol = 0 }))
+ eq({ all = 2, fill = 2 }, meths.win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 }))
+ eq({ all = 0, fill = 0 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X }))
+ eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 }))
+ eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 }))
+ eq({ all = 10, fill = 5 }, meths.win_text_height(1001, { end_row = 18, end_vcol = 0 }))
+ eq({ all = 8, fill = 3 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 }))
+ end)
+
+ it('with wrapped lines', function()
+ local X = meths.get_vvar('maxcol')
+ local screen = Screen.new(45, 22)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue1, bold = true};
+ [1] = {foreground = Screen.colors.Brown};
+ [2] = {background = Screen.colors.Yellow};
+ })
+ screen:attach()
+ exec([[
+ set number cpoptions+=n
+ call setline(1, repeat([repeat('foobar-', 36)], 3))
+ ]])
+ local ns = meths.create_namespace('')
+ meths.buf_set_extmark(0, ns, 1, 100, { virt_text = {{('?'):rep(15), 'Search'}}, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 2, 200, { virt_text = {{('!'):rep(75), 'Search'}}, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ {1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
+ -foobar-foobar-foobar-foobar-foobar-foobar-fo|
+ obar-foobar-foobar-foobar-foobar-foobar-fooba|
+ r-foobar-foobar-foobar-foobar-foobar-foobar-f|
+ oobar-foobar-foobar-foobar-foobar-foobar-foob|
+ ar-foobar-foobar-foobar-foobar- |
+ {1: 2 }foobar-foobar-foobar-foobar-foobar-foobar|
+ -foobar-foobar-foobar-foobar-foobar-foobar-fo|
+ obar-foobar-fo{2:???????????????}obar-foobar-foob|
+ ar-foobar-foobar-foobar-foobar-foobar-foobar-|
+ foobar-foobar-foobar-foobar-foobar-foobar-foo|
+ bar-foobar-foobar-foobar-foobar-foobar-foobar|
+ - |
+ {1: 3 }foobar-foobar-foobar-foobar-foobar-foobar|
+ -foobar-foobar-foobar-foobar-foobar-foobar-fo|
+ obar-foobar-foobar-foobar-foobar-foobar-fooba|
+ r-foobar-foobar-foobar-foobar-foobar-foobar-f|
+ oobar-foobar-foobar-foob{2:!!!!!!!!!!!!!!!!!!!!!}|
+ {2:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}|
+ {2:!!!!!!!!!}ar-foobar-foobar-foobar-foobar-fooba|
+ r-foobar-foobar- |
+ |
+ ]]}
+ screen:try_resize(45, 2)
+ screen:expect{grid=[[
+ {1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
+ |
+ ]]}
+ eq({ all = 21, fill = 0 }, meths.win_text_height(0, {}))
+ eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 0, end_row = 0 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, end_row = 1 }))
+ eq({ all = 8, fill = 0 }, meths.win_text_height(0, { start_row = 2, end_row = 2 }))
+ eq({ all = 0, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 }))
+ eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 }))
+ eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 }))
+ eq({ all = 3, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 }))
+ eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X }))
+ eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X }))
+ eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X }))
+ eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X }))
+ eq({ all = 5, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X }))
+ eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X }))
+ eq({ all = 0, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 }))
+ eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 }))
+ eq({ all = 18, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 131 }))
+ eq({ all = 19, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 130 }))
+ eq({ all = 20, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 311 }))
+ eq({ all = 21, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 312 }))
+ eq({ all = 17, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 }))
+ eq({ all = 19, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 }))
+ eq({ all = 16, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 221 }))
+ eq({ all = 17, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 220 }))
+ eq({ all = 14, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 41 }))
+ eq({ all = 15, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 42 }))
+ eq({ all = 9, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 }))
+ eq({ all = 11, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 }))
+ end)
end)
describe('open_win', function()
@@ -591,19 +864,45 @@ describe('API/win', function()
})
eq(1, funcs.exists('g:fired'))
end)
+
+ it('disallowed in cmdwin if enter=true or buf=curbuf', function()
+ local new_buf = meths.create_buf(true, true)
+ feed('q:')
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.open_win, new_buf, true, {
+ relative='editor', row=5, col=5, width=5, height=5,
+ }))
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.open_win, 0, false, {
+ relative='editor', row=5, col=5, width=5, height=5,
+ }))
+
+ eq(new_buf, meths.win_get_buf(meths.open_win(new_buf, false, {
+ relative='editor', row=5, col=5, width=5, height=5,
+ })))
+ end)
+
+ it('aborts if buffer is invalid', function()
+ local wins_before = meths.list_wins()
+ eq('Invalid buffer id: 1337', pcall_err(meths.open_win, 1337, false, {
+ relative='editor', row=5, col=5, width=5, height=5,
+ }))
+ eq(wins_before, meths.list_wins())
+ end)
end)
describe('get_config', function()
it('includes border', function()
local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }
local win = meths.open_win(0, true, {
- relative='win', row=3, col=3, width=12, height=3,
- border = b,
+ relative='win', row=3, col=3, width=12, height=3,
+ border = b,
})
local cfg = meths.win_get_config(win)
eq(b, cfg.border)
end)
+
it('includes border with highlight group', function()
local b = {
{'a', 'Normal'},
@@ -616,12 +915,25 @@ describe('API/win', function()
{'h', 'PreProc'},
}
local win = meths.open_win(0, true, {
- relative='win', row=3, col=3, width=12, height=3,
- border = b,
+ relative='win', row=3, col=3, width=12, height=3,
+ border = b,
})
local cfg = meths.win_get_config(win)
eq(b, cfg.border)
end)
+
+ it('includes title and footer', function()
+ local title = { {'A', {'StatusLine', 'TabLine'}}, {'B'}, {'C', 'WinBar'} }
+ local footer = { {'A', 'WinBar'}, {'B'}, {'C', {'StatusLine', 'TabLine'}} }
+ local win = meths.open_win(0, true, {
+ relative='win', row=3, col=3, width=12, height=3,
+ border = 'single', title = title, footer = footer,
+ })
+
+ local cfg = meths.win_get_config(win)
+ eq(title, cfg.title)
+ eq(footer, cfg.footer)
+ end)
end)
end)
diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua
index ad3687d7b0..dfd746a06e 100644
--- a/test/functional/autocmd/autocmd_oldtest_spec.lua
+++ b/test/functional/autocmd/autocmd_oldtest_spec.lua
@@ -1,13 +1,12 @@
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local eq = helpers.eq
local meths = helpers.meths
local funcs = helpers.funcs
-
-local exec = function(str)
- meths.exec(str, false)
-end
+local exec = helpers.exec
+local feed = helpers.feed
describe('oldtests', function()
before_each(clear)
@@ -53,6 +52,7 @@ describe('oldtests', function()
it('should fire on unload buf', function()
funcs.writefile({'Test file Xxx1'}, 'Xxx1')
funcs.writefile({'Test file Xxx2'}, 'Xxx2')
+ local fname = 'Xtest_functional_autocmd_unload'
local content = [[
func UnloadAllBufs()
@@ -72,15 +72,55 @@ describe('oldtests', function()
q
]]
- funcs.writefile(funcs.split(content, "\n"), 'Xtest')
+ funcs.writefile(funcs.split(content, "\n"), fname)
funcs.delete('Xout')
- funcs.system(meths.get_vvar('progpath') .. ' -u NORC -i NONE -N -S Xtest')
+ funcs.system(string.format('%s -u NORC -i NONE -N -S %s', meths.get_vvar('progpath'), fname))
eq(1, funcs.filereadable('Xout'))
funcs.delete('Xxx1')
funcs.delete('Xxx2')
- funcs.delete('Xtest')
+ funcs.delete(fname)
funcs.delete('Xout')
end)
+
+ -- oldtest: Test_delete_ml_get_errors()
+ it('no ml_get error with TextChanged autocommand and delete', function()
+ local screen = Screen.new(75, 10)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {background = Screen.colors.Cyan};
+ })
+ exec([[
+ set noshowcmd noruler scrolloff=0
+ source test/old/testdir/samples/matchparen.vim
+ edit test/old/testdir/samples/box.txt
+ ]])
+ feed('249GV<C-End>d')
+ screen:expect{grid=[[
+ const auto themeEmoji = _forPeer->themeEmoji(); |
+ if (themeEmoji.isEmpty()) { |
+ return nonCustom; |
+ } |
+ const auto &themes = _forPeer->owner().cloudThemes(); |
+ const auto theme = themes.themeForEmoji(themeEmoji); |
+ if (!theme) {1:{} |
+ return nonCustom; |
+ {1:^}} |
+ 353 fewer lines |
+ ]]}
+ feed('<PageUp>')
+ screen:expect{grid=[[
+ |
+ auto BackgroundBox::Inner::resolveResetCustomPaper() const |
+ -> std::optional<Data::WallPaper> { |
+ if (!_forPeer) { |
+ return {}; |
+ } |
+ const auto nonCustom = Window::Theme::Background()->paper(); |
+ const auto themeEmoji = _forPeer->themeEmoji(); |
+ ^if (themeEmoji.isEmpty()) { |
+ 353 fewer lines |
+ ]]}
+ end)
end)
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua
index fb5bab445c..63a487c8bc 100644
--- a/test/functional/autocmd/autocmd_spec.lua
+++ b/test/functional/autocmd/autocmd_spec.lua
@@ -141,7 +141,7 @@ describe('autocmd', function()
describe('BufLeave autocommand', function()
it('can wipe out the buffer created by :edit which triggered autocmd',
function()
- meths.set_option('hidden', true)
+ meths.set_option_value('hidden', true, {})
curbufmeths.set_lines(0, 1, false, {
'start of test file xx',
'end of test file xx'})
@@ -611,4 +611,38 @@ describe('autocmd', function()
eq(4, #meths.get_autocmds { event = "BufReadCmd", group = "TestingPatterns" })
end)
end)
+
+ it('no use-after-free when adding autocommands from a callback', function()
+ exec_lua [[
+ vim.cmd "autocmd! TabNew"
+ vim.g.count = 0
+ vim.api.nvim_create_autocmd('TabNew', {
+ callback = function()
+ vim.g.count = vim.g.count + 1
+ for _ = 1, 100 do
+ vim.cmd "autocmd TabNew * let g:count += 1"
+ end
+ return true
+ end,
+ })
+ vim.cmd "tabnew"
+ ]]
+ eq(1, eval('g:count')) -- Added autocommands should not be executed
+ end)
+
+ it('no crash when clearing a group inside a callback #23355', function()
+ exec_lua [[
+ vim.cmd "autocmd! TabNew"
+ local group = vim.api.nvim_create_augroup('Test', {})
+ local id
+ id = vim.api.nvim_create_autocmd('TabNew', {
+ group = group,
+ callback = function()
+ vim.api.nvim_del_autocmd(id)
+ vim.api.nvim_create_augroup('Test', { clear = true })
+ end,
+ })
+ vim.cmd "tabnew"
+ ]]
+ end)
end)
diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua
index b04bd5233a..e6bcb19682 100644
--- a/test/functional/autocmd/cursorhold_spec.lua
+++ b/test/functional/autocmd/cursorhold_spec.lua
@@ -26,7 +26,7 @@ describe('CursorHold', function()
-- if testing with small 'updatetime' fails, double its value and test again
retry(10, nil, function()
ut = ut * 2
- meths.set_option('updatetime', ut)
+ meths.set_option_value('updatetime', ut, {})
feed('0') -- reset did_cursorhold
meths.set_var('cursorhold', 0)
sleep(ut / 4)
@@ -51,12 +51,12 @@ describe('CursorHold', function()
end)
it("reducing 'updatetime' while waiting for CursorHold #20241", function()
- meths.set_option('updatetime', 10000)
+ meths.set_option_value('updatetime', 10000, {})
feed('0') -- reset did_cursorhold
meths.set_var('cursorhold', 0)
sleep(50)
eq(0, meths.get_var('cursorhold'))
- meths.set_option('updatetime', 20)
+ meths.set_option_value('updatetime', 20, {})
sleep(10)
eq(1, meths.get_var('cursorhold'))
end)
diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua
index 85d8628d7e..854e14b088 100644
--- a/test/functional/autocmd/cursormoved_spec.lua
+++ b/test/functional/autocmd/cursormoved_spec.lua
@@ -3,40 +3,55 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
-local funcs = helpers.funcs
+local meths = helpers.meths
local source = helpers.source
+local command = helpers.command
describe('CursorMoved', function()
before_each(clear)
- it('is triggered by changing windows', function()
+ it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
source([[
- let g:cursormoved = 0
- vsplit
- autocmd CursorMoved * let g:cursormoved += 1
- wincmd w
- wincmd w
+ call setline(1, 'foo')
+ let g:log = []
+ autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
+ autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
]])
- eq(2, eval('g:cursormoved'))
+ eq({}, eval('g:log'))
+ command('new')
+ eq({'BufEnter2', 'CursorMoved2'}, eval('g:log'))
+ command('wincmd w')
+ eq({'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1'}, eval('g:log'))
+ end)
+
+ it('is not triggered by temporarily switching window', function()
+ source([[
+ let g:cursormoved = 0
+ vnew
+ autocmd CursorMoved * let g:cursormoved += 1
+ ]])
+ command('wincmd w | wincmd p')
+ eq(0, eval('g:cursormoved'))
end)
it("is not triggered by functions that don't change the window", function()
source([[
- let g:cursormoved = 0
- let g:buf = bufnr('%')
- vsplit foo
- autocmd CursorMoved * let g:cursormoved += 1
- call nvim_buf_set_lines(g:buf, 0, -1, v:true, ['aaa'])
+ let g:cursormoved = 0
+ let g:buf = bufnr('%')
+ vsplit foo
+ autocmd CursorMoved * let g:cursormoved += 1
]])
- eq({'aaa'}, funcs.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
+ meths.buf_set_lines(eval('g:buf'), 0, -1, true, {'aaa'})
+ eq(0, eval('g:cursormoved'))
+ eq({'aaa'}, meths.buf_get_lines(eval('g:buf'), 0, -1, true))
eq(0, eval('g:cursormoved'))
end)
it("is not triggered by cursor movement prior to first CursorMoved instantiation", function()
source([[
- let g:cursormoved = 0
- autocmd! CursorMoved
- autocmd CursorMoved * let g:cursormoved += 1
+ let g:cursormoved = 0
+ autocmd! CursorMoved
+ autocmd CursorMoved * let g:cursormoved += 1
]])
eq(0, eval('g:cursormoved'))
end)
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua
index 828cffa460..20aa07d058 100644
--- a/test/functional/autocmd/dirchanged_spec.lua
+++ b/test/functional/autocmd/dirchanged_spec.lua
@@ -1,4 +1,4 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
@@ -9,7 +9,7 @@ local request = helpers.request
local is_os = helpers.is_os
describe('autocmd DirChanged and DirChangedPre', function()
- local curdir = string.gsub(lfs.currentdir(), '\\', '/')
+ local curdir = string.gsub(luv.cwd(), '\\', '/')
local dirs = {
curdir .. '/Xtest-functional-autocmd-dirchanged.dir1',
curdir .. '/Xtest-functional-autocmd-dirchanged.dir2',
diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua
index d7a87e17ed..33e4d88c7b 100644
--- a/test/functional/autocmd/focus_spec.lua
+++ b/test/functional/autocmd/focus_spec.lua
@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
-local lfs = require('lfs')
+local luv = require('luv')
local clear = helpers.clear
local nvim_prog = helpers.nvim_prog
local feed_command = helpers.feed_command
@@ -32,7 +32,8 @@ describe('autoread TUI FocusGained/FocusLost', function()
]]
helpers.write_file(path, '')
- lfs.touch(path, os.time() - 10)
+ local atime = os.time() - 10
+ luv.fs_utime(path, atime, atime)
screen:expect{grid=[[
{1: } |
diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua
index be5a291ac9..69a722a0e9 100644
--- a/test/functional/autocmd/modechanged_spec.lua
+++ b/test/functional/autocmd/modechanged_spec.lua
@@ -1,17 +1,19 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
local feed, command = helpers.feed, helpers.command
+local exec_lua = helpers.exec_lua
describe('ModeChanged', function()
before_each(function()
clear()
+ end)
+
+ it('picks up terminal mode changes', function()
command('let g:count = 0')
command('au ModeChanged * let g:event = copy(v:event)')
command('au ModeChanged * let g:count += 1')
- end)
- it('picks up terminal mode changes', function()
- command("term")
+ command('term')
feed('i')
eq({
old_mode = 'nt',
@@ -28,4 +30,35 @@ describe('ModeChanged', function()
-- v:event is cleared after the autocommand is done
eq({}, eval('v:event'))
end)
+
+ it('does not repeatedly trigger for scheduled callback', function()
+ exec_lua([[
+ vim.g.s_count = 0
+ vim.g.s_mode = ""
+ vim.g.t_count = 0
+ vim.g.t_mode = ""
+ vim.api.nvim_create_autocmd("ModeChanged", {
+ callback = function()
+ vim.g.s_count = vim.g.s_count + 1
+ vim.g.s_mode = vim.api.nvim_get_mode().mode
+ vim.schedule(function()
+ vim.g.t_count = vim.g.t_count + 1
+ vim.g.t_mode = vim.api.nvim_get_mode().mode
+ end)
+ end,
+ })
+ ]])
+
+ feed('d')
+ eq(1, eval('g:s_count'))
+ eq('no', eval('g:s_mode'))
+ eq(1, eval('g:t_count'))
+ eq('no', eval('g:t_mode'))
+
+ feed('<Esc>')
+ eq(2, eval('g:s_count'))
+ eq('n', eval('g:s_mode'))
+ eq(2, eval('g:t_count'))
+ eq('n', eval('g:t_mode'))
+ end)
end)
diff --git a/test/functional/autocmd/safestate_spec.lua b/test/functional/autocmd/safestate_spec.lua
new file mode 100644
index 0000000000..73693749e4
--- /dev/null
+++ b/test/functional/autocmd/safestate_spec.lua
@@ -0,0 +1,57 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+local exec = helpers.exec
+local feed = helpers.feed
+local meths = helpers.meths
+
+before_each(clear)
+
+describe('SafeState autocommand', function()
+ local function create_autocmd()
+ exec([[
+ let g:safe = 0
+ autocmd SafeState * ++once let g:safe += 1
+ ]])
+ end
+
+ it('with pending operator', function()
+ feed('d')
+ create_autocmd()
+ eq(0, meths.get_var('safe'))
+ feed('d')
+ eq(1, meths.get_var('safe'))
+ end)
+
+ it('with specified register', function()
+ feed('"r')
+ create_autocmd()
+ eq(0, meths.get_var('safe'))
+ feed('x')
+ eq(1, meths.get_var('safe'))
+ end)
+
+ it('with i_CTRL-O', function()
+ feed('i<C-O>')
+ create_autocmd()
+ eq(0, meths.get_var('safe'))
+ feed('x')
+ eq(1, meths.get_var('safe'))
+ end)
+
+ it('with Insert mode completion', function()
+ feed('i<C-X><C-V>')
+ create_autocmd()
+ eq(0, meths.get_var('safe'))
+ feed('<C-X><C-Z>')
+ eq(1, meths.get_var('safe'))
+ end)
+
+ it('with Cmdline completion', function()
+ feed(':<Tab>')
+ create_autocmd()
+ eq(0, meths.get_var('safe'))
+ feed('<C-E>')
+ eq(1, meths.get_var('safe'))
+ end)
+end)
diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua
index 505bed834b..9e0a5b819a 100644
--- a/test/functional/autocmd/show_spec.lua
+++ b/test/functional/autocmd/show_spec.lua
@@ -180,4 +180,45 @@ describe(":autocmd", function()
test_3 User
B echo "B3"]]), funcs.execute('autocmd test_3 * B'))
end)
+
+ it('should skip consecutive patterns', function()
+ exec([[
+ autocmd! BufEnter
+ augroup test_1
+ autocmd BufEnter A echo 'A'
+ autocmd BufEnter A echo 'B'
+ autocmd BufEnter A echo 'C'
+ autocmd BufEnter B echo 'D'
+ autocmd BufEnter B echo 'E'
+ autocmd BufEnter B echo 'F'
+ augroup END
+ augroup test_2
+ autocmd BufEnter C echo 'A'
+ autocmd BufEnter C echo 'B'
+ autocmd BufEnter C echo 'C'
+ autocmd BufEnter D echo 'D'
+ autocmd BufEnter D echo 'E'
+ autocmd BufEnter D echo 'F'
+ augroup END
+
+ let g:output = execute('autocmd BufEnter')
+ ]])
+ eq(dedent([[
+
+ --- Autocommands ---
+ test_1 BufEnter
+ A echo 'A'
+ echo 'B'
+ echo 'C'
+ B echo 'D'
+ echo 'E'
+ echo 'F'
+ test_2 BufEnter
+ C echo 'A'
+ echo 'B'
+ echo 'C'
+ D echo 'D'
+ echo 'E'
+ echo 'F']]), eval('g:output'))
+ end)
end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index b186aa1f50..6e167dd55c 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -21,9 +21,9 @@ describe('TabNewEntered', function()
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
+ clear()
nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
- eq('tabnewentered:4:4\ntabnewentered:match',
- nvim('exec', 'tabnew Xtest-tabnewentered', true))
+ eq('tabnewentered:match', nvim('exec', 'tabnew Xtest-tabnewentered', true))
end)
end)
describe('with CTRL-W T', function()
@@ -35,6 +35,14 @@ describe('TabNewEntered', function()
eq('entered', nvim('exec', 'execute "normal \\<C-W>T"', true))
end)
end)
+ describe('with tab split #4334', function()
+ it('works when create a tab by using tab split command', function()
+ clear()
+ nvim('command', 'au! TabNewEntered * let b:entered = "entered"')
+ nvim('command', 'tab split')
+ eq('entered', nvim('exec', 'echo b:entered', true))
+ end)
+ end)
end)
end)
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua
index 0a33f1b2ac..332a936e3f 100644
--- a/test/functional/autocmd/termxx_spec.lua
+++ b/test/functional/autocmd/termxx_spec.lua
@@ -1,5 +1,6 @@
local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
+local thelpers = require('test.functional.terminal.helpers')
local clear, command, nvim, testprg =
helpers.clear, helpers.command, helpers.nvim, helpers.testprg
@@ -8,6 +9,7 @@ local eval, eq, neq, retry =
local matches = helpers.matches
local ok = helpers.ok
local feed = helpers.feed
+local meths = helpers.meths
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
local skip = helpers.skip
@@ -16,12 +18,13 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function()
before_each(function()
clear()
- nvim('set_option', 'shell', testprg('shell-test'))
+ nvim('set_option_value', 'shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
end)
-
local function test_termclose_delete_own_buf()
+ -- The terminal process needs to keep running so that TermClose isn't triggered immediately.
+ nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!')
command('terminal')
matches('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://',
@@ -48,7 +51,8 @@ describe('autocmd TermClose', function()
end)
it('triggers when long-running terminal job gets stopped', function()
- nvim('set_option', 'shell', is_os('win') and 'cmd.exe' or 'sh')
+ skip(is_os('win'))
+ nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {})
command('autocmd TermClose * let g:test_termclose = 23')
command('terminal')
command('call jobstop(b:terminal_job_id)')
@@ -57,8 +61,8 @@ describe('autocmd TermClose', function()
it('kills job trapping SIGTERM', function()
skip(is_os('win'))
- nvim('set_option', 'shell', 'sh')
- nvim('set_option', 'shellcmdflag', '-c')
+ nvim('set_option_value', 'shell', 'sh', {})
+ nvim('set_option_value', 'shellcmdflag', '-c', {})
command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
@@ -77,8 +81,8 @@ describe('autocmd TermClose', function()
it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(is_os('win'))
- nvim('set_option', 'shell', 'sh')
- nvim('set_option', 'shellcmdflag', '-c')
+ nvim('set_option_value', 'shell', 'sh', {})
+ nvim('set_option_value', 'shellcmdflag', '-c', {})
command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
.. [[ 'pty': 1,]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
@@ -98,12 +102,13 @@ describe('autocmd TermClose', function()
it('reports the correct <abuf>', function()
command('set hidden')
+ command('set shellcmdflag=EXE')
command('autocmd TermClose * let g:abuf = expand("<abuf>")')
command('edit foo')
command('edit bar')
eq(2, eval('bufnr("%")'))
- command('terminal')
+ command('terminal ls')
retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
command('buffer 1')
@@ -143,19 +148,37 @@ it('autocmd TermEnter, TermLeave', function()
-- TermLeave is also triggered by :quit.
command('split foo')
+ feed('<Ignore>') -- Add input to separate two RPC requests
command('wincmd w')
feed('i')
command('q!')
- eq(
- {
- {'TermOpen', 'n'},
- {'TermEnter', 't'},
- {'TermLeave', 'n'},
- {'TermEnter', 't'},
- {'TermLeave', 'n'},
- {'TermEnter', 't'},
- {'TermClose', 't'},
- {'TermLeave', 'n'},
- },
- eval('g:evs'))
+ feed('<Ignore>') -- Add input to separate two RPC requests
+ eq({
+ {'TermOpen', 'n'},
+ {'TermEnter', 't'},
+ {'TermLeave', 'n'},
+ {'TermEnter', 't'},
+ {'TermLeave', 'n'},
+ {'TermEnter', 't'},
+ {'TermClose', 't'},
+ {'TermLeave', 'n'},
+ }, eval('g:evs'))
+end)
+
+describe('autocmd TextChangedT', function()
+ clear()
+ local screen = thelpers.screen_setup()
+
+ it('works', function()
+ command('autocmd TextChangedT * ++once let g:called = 1')
+ thelpers.feed_data('a')
+ retry(nil, nil, function() eq(1, meths.get_var('called')) end)
+ end)
+
+ it('cannot delete terminal buffer', function()
+ command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]])
+ thelpers.feed_data('a')
+ screen:expect({any = 'E937: '})
+ matches('^E937: Attempt to delete a buffer that is in use: term://', meths.get_vvar('errmsg'))
+ end)
end)
diff --git a/test/functional/autocmd/textchanged_spec.lua b/test/functional/autocmd/textchanged_spec.lua
new file mode 100644
index 0000000000..b621eb36bf
--- /dev/null
+++ b/test/functional/autocmd/textchanged_spec.lua
@@ -0,0 +1,182 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local exec = helpers.exec
+local command = helpers.command
+local feed = helpers.feed
+local eq = helpers.eq
+local neq = helpers.neq
+local eval = helpers.eval
+local poke_eventloop = helpers.poke_eventloop
+
+before_each(clear)
+
+-- oldtest: Test_ChangedP()
+it('TextChangedI and TextChangedP autocommands', function()
+ -- The oldtest uses feedkeys() with 'x' flag, which never triggers TextChanged.
+ -- So don't add TextChanged autocommand here.
+ exec([[
+ call setline(1, ['foo', 'bar', 'foobar'])
+ set complete=. completeopt=menuone
+ au! TextChangedI <buffer> let g:autocmd ..= 'I'
+ au! TextChangedP <buffer> let g:autocmd ..= 'P'
+ call cursor(3, 1)
+ ]])
+
+ command([[let g:autocmd = '']])
+ feed('o')
+ poke_eventloop()
+ feed('<esc>')
+ -- TextChangedI triggers only if text is actually changed in Insert mode
+ eq('I', eval('g:autocmd'))
+
+ command([[let g:autocmd = '']])
+ feed('S')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ eq('II', eval('g:autocmd'))
+ feed('<esc>')
+
+ command([[let g:autocmd = '']])
+ feed('S')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ eq('IIP', eval('g:autocmd'))
+ feed('<esc>')
+
+ command([[let g:autocmd = '']])
+ feed('S')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ eq('IIPP', eval('g:autocmd'))
+ feed('<esc>')
+
+ command([[let g:autocmd = '']])
+ feed('S')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ eq('IIPPP', eval('g:autocmd'))
+ feed('<esc>')
+
+ command([[let g:autocmd = '']])
+ feed('S')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ poke_eventloop()
+ feed('<C-N>')
+ eq('IIPPPP', eval('g:autocmd'))
+ feed('<esc>')
+
+ eq({'foo', 'bar', 'foobar', 'foo'}, eval('getline(1, "$")'))
+end)
+
+-- oldtest: Test_TextChangedI_with_setline()
+it('TextChangedI with setline()', function()
+ exec([[
+ let g:setline_handled = v:false
+ func SetLineOne()
+ if !g:setline_handled
+ call setline(1, "(x)")
+ let g:setline_handled = v:true
+ endif
+ endfunc
+ autocmd TextChangedI <buffer> call SetLineOne()
+ ]])
+
+ feed('i')
+ poke_eventloop()
+ feed('(')
+ poke_eventloop()
+ feed('<CR>')
+ poke_eventloop()
+ feed('<Esc>')
+ eq('(', eval('getline(1)'))
+ eq('x)', eval('getline(2)'))
+ command('undo')
+ eq('', eval('getline(1)'))
+ eq('', eval('getline(2)'))
+end)
+
+-- oldtest: Test_Changed_ChangedI()
+it('TextChangedI and TextChanged', function()
+ exec([[
+ let [g:autocmd_i, g:autocmd_n] = ['','']
+
+ func! TextChangedAutocmdI(char)
+ let g:autocmd_{tolower(a:char)} = a:char .. b:changedtick
+ endfunc
+
+ augroup Test_TextChanged
+ au!
+ au TextChanged <buffer> :call TextChangedAutocmdI('N')
+ au TextChangedI <buffer> :call TextChangedAutocmdI('I')
+ augroup END
+ ]])
+
+ feed('i')
+ poke_eventloop()
+ feed('f')
+ poke_eventloop()
+ feed('o')
+ poke_eventloop()
+ feed('o')
+ poke_eventloop()
+ feed('<esc>')
+ eq('', eval('g:autocmd_n'))
+ eq('I5', eval('g:autocmd_i'))
+
+ feed('yyp')
+ eq('N6', eval('g:autocmd_n'))
+ eq('I5', eval('g:autocmd_i'))
+
+ -- TextChangedI should only trigger if change was done in Insert mode
+ command([[let g:autocmd_i = '']])
+ feed('yypi<esc>')
+ eq('', eval('g:autocmd_i'))
+
+ -- TextChanged should only trigger if change was done in Normal mode
+ command([[let g:autocmd_n = '']])
+ feed('ibar<esc>')
+ eq('', eval('g:autocmd_n'))
+
+ local function validate_mixed_textchangedi(keys)
+ feed('ifoo<esc>')
+ command([[let g:autocmd_i = '']])
+ command([[let g:autocmd_n = '']])
+ for _, s in ipairs(keys) do
+ feed(s)
+ poke_eventloop()
+ end
+ neq('', eval('g:autocmd_i'))
+ eq('', eval('g:autocmd_n'))
+ end
+
+ validate_mixed_textchangedi({'o', '<esc>'})
+ validate_mixed_textchangedi({'O', '<esc>'})
+ validate_mixed_textchangedi({'ciw', '<esc>'})
+ validate_mixed_textchangedi({'cc', '<esc>'})
+ validate_mixed_textchangedi({'C', '<esc>'})
+ validate_mixed_textchangedi({'s', '<esc>'})
+ validate_mixed_textchangedi({'S', '<esc>'})
+end)
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index 3898d59e58..1640916ad8 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -8,7 +8,7 @@ describe('TextYankPost', function()
clear()
-- emulate the clipboard so system clipboard isn't affected
- command('let &rtp = "test/functional/fixtures,".&rtp')
+ command('set rtp^=test/functional/fixtures')
command('let g:count = 0')
command('autocmd TextYankPost * let g:event = copy(v:event)')
diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua
index 4957f56dd4..e6fdd9560d 100644
--- a/test/functional/autocmd/win_scrolled_resized_spec.lua
+++ b/test/functional/autocmd/win_scrolled_resized_spec.lua
@@ -297,7 +297,7 @@ describe('WinScrolled', function()
eq(0, eval('g:scrolled'))
local buf = meths.create_buf(true, true)
- meths.buf_set_lines(buf, 0, -1, false, {'a', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'})
+ meths.buf_set_lines(buf, 0, -1, false, {'@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'})
local win = meths.open_win(buf, false, {
height = 5,
width = 10,
@@ -306,6 +306,7 @@ describe('WinScrolled', function()
relative = 'editor',
style = 'minimal'
})
+ screen:expect({ any = '@' })
local winid_str = tostring(win.id)
-- WinScrolled should not be triggered when creating a new floating window
eq(0, eval('g:scrolled'))
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua
index 8275575c24..5771ddcb94 100644
--- a/test/functional/core/channels_spec.lua
+++ b/test/functional/core/channels_spec.lua
@@ -230,6 +230,7 @@ describe('channels', function()
end)
it('can use buffered output mode', function()
+ skip(funcs.executable('grep') == 0, 'missing "grep" command')
source([[
let g:job_opts = {
\ 'on_stdout': function('OnEvent'),
@@ -262,6 +263,7 @@ describe('channels', function()
end)
it('can use buffered output mode with no stream callback', function()
+ skip(funcs.executable('grep') == 0, 'missing "grep" command')
source([[
function! OnEvent(id, data, event) dict
call rpcnotify(1, a:event, a:id, a:data, self.stdout)
diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua
index 05a69e1992..d474b77806 100644
--- a/test/functional/core/exit_spec.lua
+++ b/test/functional/core/exit_spec.lua
@@ -25,30 +25,34 @@ describe('v:exiting', function()
eq(1, eval('v:exiting is v:null'))
end)
- it('is 0 on normal exit', function()
+ local function test_exiting(setup_fn)
local function on_setup()
- command('autocmd VimLeavePre * call rpcrequest('..cid..', "")')
- command('autocmd VimLeave * call rpcrequest('..cid..', "")')
- command('quit')
+ command('autocmd VimLeavePre * call rpcrequest('..cid..', "exit", "VimLeavePre")')
+ command('autocmd VimLeave * call rpcrequest('..cid..', "exit", "VimLeave")')
+ setup_fn()
end
- local function on_request()
+ local requests_args = {}
+ local function on_request(name, args)
+ eq('exit', name)
+ table.insert(requests_args, args)
eq(0, eval('v:exiting'))
return ''
end
run(on_request, nil, on_setup)
+ eq({{'VimLeavePre'}, {'VimLeave'}}, requests_args)
+ end
+
+ it('is 0 on normal exit', function()
+ test_exiting(function()
+ command('quit')
+ end)
end)
+
it('is 0 on exit from Ex mode involving try-catch vim-patch:8.0.0184', function()
- local function on_setup()
- command('autocmd VimLeavePre * call rpcrequest('..cid..', "")')
- command('autocmd VimLeave * call rpcrequest('..cid..', "")')
+ test_exiting(function()
feed('gQ')
feed_command('try', 'call NoFunction()', 'catch', 'echo "bye"', 'endtry', 'quit')
- end
- local function on_request()
- eq(0, eval('v:exiting'))
- return ''
- end
- run(on_request, nil, on_setup)
+ end)
end)
end)
@@ -89,14 +93,14 @@ describe(':cquit', function()
end)
it('exits with redir msg for multiple exit codes after :cquit 1 2', function()
- test_cq('cquit 1 2', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2')
+ test_cq('cquit 1 2', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2')
end)
it('exits with redir msg for non-number exit code after :cquit X', function()
- test_cq('cquit X', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: X: cquit X')
+ test_cq('cquit X', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: X: cquit X')
end)
it('exits with redir msg for negative exit code after :cquit -1', function()
- test_cq('cquit -1', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: -1: cquit -1')
+ test_cq('cquit -1', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: -1: cquit -1')
end)
end)
diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua
index 4e9891a4de..65f947132e 100644
--- a/test/functional/core/fileio_spec.lua
+++ b/test/functional/core/fileio_spec.lua
@@ -1,4 +1,4 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local assert_log = helpers.assert_log
@@ -15,10 +15,10 @@ local request = helpers.request
local retry = helpers.retry
local rmdir = helpers.rmdir
local matches = helpers.matches
+local meths = helpers.meths
local mkdir = helpers.mkdir
local sleep = helpers.sleep
local read_file = helpers.read_file
-local tmpname = helpers.tmpname
local trim = helpers.trim
local currentdir = helpers.funcs.getcwd
local assert_alive = helpers.assert_alive
@@ -40,15 +40,18 @@ describe('fileio', function()
os.remove('Xtest_startup_file1')
os.remove('Xtest_startup_file1~')
os.remove('Xtest_startup_file2')
+ os.remove('Xtest_startup_file2~')
os.remove('Xtest_тест.md')
os.remove('Xtest-u8-int-max')
os.remove('Xtest-overwrite-forced')
rmdir('Xtest_startup_swapdir')
rmdir('Xtest_backupdir')
+ rmdir('Xtest_backupdir with spaces')
end)
it('fsync() codepaths #8304', function()
clear({ args={ '-i', 'Xtest_startup_shada',
+ '--cmd', 'set nofsync',
'--cmd', 'set directory=Xtest_startup_swapdir' } })
-- These cases ALWAYS force fsync (regardless of 'fsync' option):
@@ -132,6 +135,28 @@ describe('fileio', function()
eq('foo', foo_contents);
end)
+ it('backup with full path with spaces', function()
+ skip(is_ci('cirrus'))
+ clear()
+ mkdir('Xtest_backupdir with spaces')
+ command('set backup')
+ command('set backupdir=Xtest_backupdir\\ with\\ spaces//')
+ command('write Xtest_startup_file1')
+ feed('ifoo<esc>')
+ command('write')
+ feed('Abar<esc>')
+ command('write')
+
+ -- Backup filename = fullpath, separators replaced with "%".
+ local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
+ is_os('win') and '[:/\\]' or '/', '%%') .. '~'
+ local foo_contents = trim(read_file('Xtest_backupdir with spaces/'..backup_file_name))
+ local foobar_contents = trim(read_file('Xtest_startup_file1'))
+
+ eq('foobar', foobar_contents);
+ eq('foo', foo_contents);
+ end)
+
it('backup symlinked files #11349', function()
skip(is_ci('cirrus'))
clear()
@@ -141,7 +166,7 @@ describe('fileio', function()
local backup_file_name = link_file_name .. '~'
write_file('Xtest_startup_file1', initial_content, false)
- lfs.link('Xtest_startup_file1', link_file_name, true)
+ luv.fs_symlink('Xtest_startup_file1', link_file_name)
command('set backup')
command('set backupcopy=yes')
command('edit ' .. link_file_name)
@@ -165,7 +190,7 @@ describe('fileio', function()
local backup_file_name = backup_dir .. sep .. link_file_name .. '~'
write_file('Xtest_startup_file1', initial_content, false)
- lfs.link('Xtest_startup_file1', link_file_name, true)
+ luv.fs_symlink('Xtest_startup_file1', link_file_name)
mkdir(backup_dir)
command('set backup')
command('set backupcopy=yes')
@@ -235,8 +260,8 @@ describe('fileio', function()
screen:expect([[
{2:WARNING: The file has been changed since}|
{2: reading it!!!} |
- {3:Do you really want to write to it (y/n)^?}|
- |
+ {3:Do you really want to write to it (y/n)?}|
+ ^ |
]])
feed("n")
@@ -261,13 +286,11 @@ end)
describe('tmpdir', function()
local tmproot_pat = [=[.*[/\\]nvim%.[^/\\]+]=]
local testlog = 'Xtest_tmpdir_log'
- local faketmp
+ local os_tmpdir
before_each(function()
-- Fake /tmp dir so that we can mess it up.
- faketmp = tmpname()
- os.remove(faketmp)
- mkdir(faketmp)
+ os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
end)
after_each(function()
@@ -275,16 +298,21 @@ describe('tmpdir', function()
os.remove(testlog)
end)
- it('failure modes', function()
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } })
- assert_nolog('tempdir is not a directory', testlog)
- assert_nolog('tempdir has invalid permissions', testlog)
-
+ local function get_tmproot()
-- Tempfiles typically look like: "…/nvim.<user>/xxx/0".
-- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims.
-- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally).
local tmproot = (funcs.tempname()):match(tmproot_pat)
ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot)
+ return tmproot
+ end
+
+ it('failure modes', function()
+ clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
+ assert_nolog('tempdir is not a directory', testlog)
+ assert_nolog('tempdir has invalid permissions', testlog)
+
+ local tmproot = get_tmproot()
-- Test how Nvim handles invalid tmpdir root (by hostile users or accidents).
--
@@ -292,7 +320,7 @@ describe('tmpdir', function()
expect_exit(command, ':qall!')
rmdir(tmproot)
write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it.
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } })
+ clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled.
assert_log('tempdir root not a directory', testlog, 100)
@@ -303,18 +331,62 @@ describe('tmpdir', function()
os.remove(tmproot)
mkdir(tmproot)
funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it.
- clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } })
+ clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled.
assert_log('tempdir root has invalid permissions', testlog, 100)
end)
it('too long', function()
- local bigname = ('%s/%s'):format(faketmp, ('x'):rep(666))
+ local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666))
mkdir(bigname)
clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=bigname, } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir().
local len = (funcs.tempname()):len()
ok(len > 4 and len < 256, '4 < len < 256', tostring(len))
end)
+
+ it('disappeared #1432', function()
+ clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } })
+ assert_nolog('tempdir disappeared', testlog)
+
+ local function rm_tmpdir()
+ local tmpname1 = funcs.tempname()
+ local tmpdir1 = funcs.fnamemodify(tmpname1, ':h')
+ eq(funcs.stdpath('run'), tmpdir1)
+
+ rmdir(tmpdir1)
+ retry(nil, 1000, function()
+ eq(0, funcs.isdirectory(tmpdir1))
+ end)
+ local tmpname2 = funcs.tempname()
+ local tmpdir2 = funcs.fnamemodify(tmpname2, ':h')
+ neq(tmpdir1, tmpdir2)
+ end
+
+ -- Your antivirus hates you...
+ rm_tmpdir()
+ assert_log('tempdir disappeared', testlog, 100)
+ funcs.tempname()
+ funcs.tempname()
+ funcs.tempname()
+ eq('', meths.get_vvar('errmsg'))
+ rm_tmpdir()
+ funcs.tempname()
+ funcs.tempname()
+ funcs.tempname()
+ eq('E5431: tempdir disappeared (2 times)', meths.get_vvar('errmsg'))
+ rm_tmpdir()
+ eq('E5431: tempdir disappeared (3 times)', meths.get_vvar('errmsg'))
+ end)
+
+ it('$NVIM_APPNAME relative path', function()
+ clear({ env={
+ NVIM_APPNAME='a/b',
+ NVIM_LOG_FILE=testlog,
+ TMPDIR=os_tmpdir,
+ } })
+ matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname())
+ end)
+
end)
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index 1bae626b98..038368c387 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -88,7 +88,6 @@ describe('jobs', function()
end)
it('append environment with pty #env', function()
- skip(is_os('win'))
nvim('command', "let $VAR = 'abc'")
nvim('command', "let $TOTO = 'goodbye world'")
nvim('command', "let g:job_opts.pty = v:true")
@@ -701,7 +700,7 @@ describe('jobs', function()
os.remove('Xtest_jobstart_env')
end)
- describe('jobwait', function()
+ describe('jobwait()', function()
before_each(function()
if is_os('win') then
helpers.set_shell_powershell()
@@ -806,7 +805,6 @@ describe('jobs', function()
end)
it('can be called recursively', function()
- skip(is_os('win'), "TODO: Need `cat`")
source([[
let g:opts = {}
let g:counter = 0
@@ -876,6 +874,43 @@ describe('jobs', function()
eq({'notification', 'wait', {{-1, -1}}}, next_msg())
end)
end)
+
+ it('hides cursor and flushes messages before blocking', function()
+ local screen = Screen.new(50, 6)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue, bold = true}; -- NonText
+ [1] = {bold = true, reverse = true}; -- MsgSeparator
+ [2] = {bold = true, foreground = Screen.colors.SeaGreen}; -- MoreMsg
+ })
+ screen:attach()
+ command([[let g:id = jobstart([v:progpath, '--clean', '--headless'])]])
+ source([[
+ func PrintAndWait()
+ echon "aaa\nbbb"
+ call jobwait([g:id], 300)
+ echon "\nccc"
+ endfunc
+ ]])
+ feed_command('call PrintAndWait()')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {1: }|
+ aaa |
+ bbb |
+ ]], timeout=100}
+ screen:expect{grid=[[
+ |
+ {1: }|
+ aaa |
+ bbb |
+ ccc |
+ {2:Press ENTER or type command to continue}^ |
+ ]]}
+ feed('<CR>')
+ funcs.jobstop(meths.get_var('id'))
+ end)
end)
pending('exit event follows stdout, stderr', function()
diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua
index ab11e14a67..19c7a93730 100644
--- a/test/functional/core/main_spec.lua
+++ b/test/functional/core/main_spec.lua
@@ -1,8 +1,9 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local eq = helpers.eq
+local matches = helpers.matches
local feed = helpers.feed
local eval = helpers.eval
local clear = helpers.clear
@@ -12,34 +13,38 @@ local write_file = helpers.write_file
local is_os = helpers.is_os
local skip = helpers.skip
-describe('Command-line option', function()
+describe('command-line option', function()
describe('-s', function()
local fname = 'Xtest-functional-core-main-s'
local fname_2 = fname .. '.2'
local nonexistent_fname = fname .. '.nonexistent'
local dollar_fname = '$' .. fname
+
before_each(function()
clear()
os.remove(fname)
os.remove(dollar_fname)
end)
+
after_each(function()
os.remove(fname)
os.remove(dollar_fname)
end)
+
it('treats - as stdin', function()
- eq(nil, lfs.attributes(fname))
+ eq(nil, luv.fs_stat(fname))
funcs.system(
{nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless',
'--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
'-s', '-', fname},
{':call setline(1, "42")', ':wqall!', ''})
eq(0, eval('v:shell_error'))
- local attrs = lfs.attributes(fname)
+ local attrs = luv.fs_stat(fname)
eq(#('42\n'), attrs.size)
end)
+
it('does not expand $VAR', function()
- eq(nil, lfs.attributes(fname))
+ eq(nil, luv.fs_stat(fname))
eq(true, not not dollar_fname:find('%$%w+'))
write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n')
funcs.system(
@@ -47,9 +52,10 @@ describe('Command-line option', function()
'--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
'-s', dollar_fname, fname})
eq(0, eval('v:shell_error'))
- local attrs = lfs.attributes(fname)
+ local attrs = luv.fs_stat(fname)
eq(#('100500\n'), attrs.size)
end)
+
it('does not crash after reading from stdin in non-headless mode', function()
skip(is_os('win'))
local screen = Screen.new(40, 8)
@@ -100,6 +106,7 @@ describe('Command-line option', function()
]])
]=]
end)
+
it('errors out when trying to use nonexistent file with -s', function()
eq(
'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n',
@@ -110,6 +117,7 @@ describe('Command-line option', function()
'-s', nonexistent_fname}))
eq(2, eval('v:shell_error'))
end)
+
it('errors out when trying to use -s twice', function()
write_file(fname, ':call setline(1, "1")\n:wqall!\n')
write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
@@ -121,7 +129,14 @@ describe('Command-line option', function()
'--cmd', 'language C',
'-s', fname, '-s', dollar_fname, fname_2}))
eq(2, eval('v:shell_error'))
- eq(nil, lfs.attributes(fname_2))
+ eq(nil, luv.fs_stat(fname_2))
end)
end)
+
+ it('nvim -v, :version', function()
+ matches('Run ":verbose version"', funcs.execute(':version'))
+ matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version'))
+ matches('Run "nvim %-V1 %-v"', funcs.system({nvim_prog_abs(), '-v'}))
+ matches('Compilation: .*Run :checkhealth', funcs.system({nvim_prog_abs(), '-V1', '-v'}))
+ end)
end)
diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua
index a786887bbd..97c32f7de6 100644
--- a/test/functional/core/path_spec.lua
+++ b/test/functional/core/path_spec.lua
@@ -1,21 +1,25 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
+local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
-local command = helpers.command
-local insert = helpers.insert
local feed = helpers.feed
+local funcs = helpers.funcs
+local insert = helpers.insert
local is_os = helpers.is_os
+local mkdir = helpers.mkdir
+local rmdir = helpers.rmdir
+local write_file = helpers.write_file
+
+local function join_path(...)
+ local pathsep = (is_os('win') and '\\' or '/')
+ return table.concat({...}, pathsep)
+end
describe('path collapse', function()
local targetdir
local expected_path
- local function join_path(...)
- local pathsep = (is_os('win') and '\\' or '/')
- return table.concat({...}, pathsep)
- end
-
before_each(function()
targetdir = join_path('test', 'functional', 'fixtures')
clear()
@@ -57,14 +61,108 @@ describe('path collapse', function()
end)
end)
+describe('expand wildcard', function()
+ before_each(clear)
+
+ it('with special characters #24421', function()
+ local folders = is_os('win') and {
+ '{folder}',
+ 'folder$name'
+ } or {
+ 'folder-name',
+ 'folder#name'
+ }
+ for _, folder in ipairs(folders) do
+ mkdir(folder)
+ local file = join_path(folder, 'file.txt')
+ write_file(file, '')
+ eq(file, eval('expand("'..folder..'/*")'))
+ rmdir(folder)
+ end
+ end)
+end)
+
describe('file search', function()
+ local testdir = 'Xtest_path_spec'
+
before_each(clear)
- it('find multibyte file name in line #20517', function()
+ setup(function()
+ mkdir(testdir)
+ end)
+
+ teardown(function()
+ rmdir(testdir)
+ end)
+
+ it('gf finds multibyte filename in line #20517', function()
command('cd test/functional/fixtures')
insert('filename_with_unicode_ααα')
eq('', eval('expand("%")'))
feed('gf')
eq('filename_with_unicode_ααα', eval('expand("%:t")'))
end)
+
+ it('gf/<cfile> matches Windows drive-letter filepaths (without ":" in &isfname)', function()
+ local iswin = is_os('win')
+ local function test_cfile(input, expected, expected_win)
+ expected = (iswin and expected_win or expected) or input
+ command('%delete')
+ insert(input)
+ command('norm! 0')
+ eq(expected, eval('expand("<cfile>")'))
+ end
+
+ test_cfile([[c:/d:/foo/bar.txt]]) -- TODO(justinmk): should return "d:/foo/bar.txt" ?
+ test_cfile([[//share/c:/foo/bar/]])
+ test_cfile([[file://c:/foo/bar]])
+ test_cfile([[file://c:/foo/bar:42]])
+ test_cfile([[file://c:/foo/bar:42:666]])
+ test_cfile([[https://c:/foo/bar]])
+ test_cfile([[\foo\bar]], [[foo]], [[\foo\bar]])
+ test_cfile([[/foo/bar]], [[/foo/bar]])
+ test_cfile([[c:\foo\bar]], [[c:]], [[c:\foo\bar]])
+ test_cfile([[c:\foo\bar:42:666]], [[c:]], [[c:\foo\bar]])
+ test_cfile([[c:/foo/bar]])
+ test_cfile([[c:/foo/bar:42]], [[c:/foo/bar]])
+ test_cfile([[c:/foo/bar:42:666]], [[c:/foo/bar]])
+ test_cfile([[c:foo\bar]], [[c]])
+ test_cfile([[c:foo/bar]], [[c]])
+ test_cfile([[c:foo]], [[c]])
+ -- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file
+ test_cfile([[c:\temp\test-file.txt]], [[c:]], [[c:\temp\test-file.txt]])
+ test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]])
+ test_cfile([[\\LOCALHOST\c$\temp\test-file.txt]], [[LOCALHOST]], [[\\LOCALHOST\c$\temp\test-file.txt]])
+ -- not supported yet
+ test_cfile([[\\.\c:\temp\test-file.txt]], [[.]], [[\\.\c]])
+ -- not supported yet
+ test_cfile([[\\?\c:\temp\test-file.txt]], [[c:]], [[\\]])
+ test_cfile([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]], [[.]], [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]])
+ test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]])
+ end)
+
+ ---@param funcname 'finddir' | 'findfile'
+ local function test_find_func(funcname, folder, item)
+ local d = join_path(testdir, folder)
+ mkdir(d)
+ local expected = join_path(d, item)
+ if funcname == 'finddir' then
+ mkdir(expected)
+ else
+ write_file(expected, '')
+ end
+ eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]])))
+ end
+
+ it('finddir()', function()
+ test_find_func('finddir', 'directory', 'folder')
+ test_find_func('finddir', 'directory', 'folder name')
+ test_find_func('finddir', 'fold#er name', 'directory')
+ end)
+
+ it('findfile()', function()
+ test_find_func('findfile', 'directory', 'file.txt')
+ test_find_func('findfile', 'directory', 'file name.txt')
+ test_find_func('findfile', 'fold#er name', 'file.txt')
+ end)
end)
diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua
index 846d79abf3..a0ec748446 100644
--- a/test/functional/core/remote_spec.lua
+++ b/test/functional/core/remote_spec.lua
@@ -3,11 +3,12 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
+local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua
local expect = helpers.expect
local funcs = helpers.funcs
local insert = helpers.insert
-local meths = helpers.meths
+local nvim_prog = helpers.nvim_prog
local new_argv = helpers.new_argv
local neq = helpers.neq
local set_session = helpers.set_session
@@ -38,10 +39,10 @@ describe('Remote', function()
server:close()
end)
+ -- Run a `nvim --remote*` command and return { stdout, stderr } of the process
local function run_remote(...)
set_session(server)
local addr = funcs.serverlist()[1]
- local client_argv = new_argv({args={'--server', addr, ...}})
-- Create an nvim instance just to run the remote-invoking nvim. We want
-- to wait for the remote instance to exit and calling jobwait blocks
@@ -50,32 +51,43 @@ describe('Remote', function()
local client_starter = spawn(new_argv(), false, nil, true)
set_session(client_starter)
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
- eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], client_argv))
+ eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, {
+ stdout_buffered = true,
+ stderr_buffered = true,
+ on_stdout = function(_, data, _)
+ _G.Remote_stdout = table.concat(data, '\n')
+ end,
+ on_stderr = function(_, data, _)
+ _G.Remote_stderr = table.concat(data, '\n')
+ end,
+ }) })]], nvim_prog, '--clean', '--headless', '--server', addr, ...))
+ local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]])
client_starter:close()
set_session(server)
+ return res
end
it('edit a single file', function()
- run_remote('--remote', fname)
+ eq({ '', '' }, run_remote('--remote', fname))
expect(contents)
eq(2, #funcs.getbufinfo())
end)
it('tab edit a single file with a non-changed buffer', function()
- run_remote('--remote-tab', fname)
+ eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents)
eq(1, #funcs.gettabinfo())
end)
it('tab edit a single file with a changed buffer', function()
insert('hello')
- run_remote('--remote-tab', fname)
+ eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents)
eq(2, #funcs.gettabinfo())
end)
it('edit multiple files', function()
- run_remote('--remote', fname, other_fname)
+ eq({ '', '' }, run_remote('--remote', fname, other_fname))
expect(contents)
command('next')
expect(other_contents)
@@ -83,7 +95,7 @@ describe('Remote', function()
end)
it('send keys', function()
- run_remote('--remote-send', ':edit '..fname..'<CR><C-W>v')
+ eq({ '', '' }, run_remote('--remote-send', ':edit '..fname..'<CR><C-W>v'))
expect(contents)
eq(2, #funcs.getwininfo())
-- Only a single buffer as we're using edit and not drop like --remote does
@@ -91,8 +103,13 @@ describe('Remote', function()
end)
it('evaluate expressions', function()
- run_remote('--remote-expr', 'setline(1, "Yo")')
+ eq({ '0', '' }, run_remote('--remote-expr', 'setline(1, "Yo")'))
+ eq({ 'Yo', '' }, run_remote('--remote-expr', 'getline(1)'))
expect('Yo')
+ eq({ ('k'):rep(1234), '' }, run_remote('--remote-expr', 'repeat("k", 1234)'))
+ eq({ '1.25', '' }, run_remote('--remote-expr', '1.25'))
+ eq({ 'no', '' }, run_remote('--remote-expr', '0z6E6F'))
+ eq({ '\t', '' }, run_remote('--remote-expr', '"\t"'))
end)
end)
@@ -101,7 +118,7 @@ describe('Remote', function()
expect(contents)
eq(1, #funcs.getbufinfo())
-- Since we didn't pass silent, we should get a complaint
- neq(nil, string.find(meths.exec('messages', true), 'E247'))
+ neq(nil, string.find(exec_capture('messages'), 'E247:'))
end)
it('creates server if not found with tabs', function()
@@ -110,10 +127,10 @@ describe('Remote', function()
eq(2, #funcs.gettabinfo())
eq(2, #funcs.getbufinfo())
-- We passed silent, so no message should be issued about the server not being found
- eq(nil, string.find(meths.exec('messages', true), 'E247'))
+ eq(nil, string.find(exec_capture('messages'), 'E247:'))
end)
- pending('exits with error on', function()
+ describe('exits with error on', function()
local function run_and_check_exit_code(...)
local bogus_argv = new_argv(...)
diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua
index afd2c1bce4..e3a59085cf 100644
--- a/test/functional/core/spellfile_spec.lua
+++ b/test/functional/core/spellfile_spec.lua
@@ -1,5 +1,4 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
local eq = helpers.eq
local clear = helpers.clear
@@ -7,6 +6,7 @@ local meths = helpers.meths
local exc_exec = helpers.exc_exec
local rmdir = helpers.rmdir
local write_file = helpers.write_file
+local mkdir = helpers.mkdir
local testdir = 'Xtest-functional-spell-spellfile.d'
@@ -14,8 +14,8 @@ describe('spellfile', function()
before_each(function()
clear()
rmdir(testdir)
- lfs.mkdir(testdir)
- lfs.mkdir(testdir .. '/spell')
+ mkdir(testdir)
+ mkdir(testdir .. '/spell')
end)
after_each(function()
rmdir(testdir)
@@ -24,7 +24,7 @@ describe('spellfile', function()
-- │ ┌ Spell file version (#VIMSPELLVERSION)
local spellheader = 'VIMspell\050'
it('errors out when prefcond section is truncated', function()
- meths.set_option('runtimepath', testdir)
+ meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
@@ -34,12 +34,12 @@ describe('spellfile', function()
-- │ ┌ Condition length (1 byte)
-- │ │ ┌ Condition regex (missing!)
.. '\000\001\001')
- meths.set_option('spelllang', 'en')
+ meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E758: Truncated spell file',
exc_exec('set spell'))
end)
it('errors out when prefcond regexp contains NUL byte', function()
- meths.set_option('runtimepath', testdir)
+ meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
@@ -54,12 +54,12 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
- meths.set_option('spelllang', 'en')
+ meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell'))
end)
it('errors out when region contains NUL byte', function()
- meths.set_option('runtimepath', testdir)
+ meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_REGION)
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
@@ -71,12 +71,12 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
- meths.set_option('spelllang', 'en')
+ meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell'))
end)
it('errors out when SAL section contains NUL byte', function()
- meths.set_option('runtimepath', testdir)
+ meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_SAL)
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
@@ -95,15 +95,15 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
- meths.set_option('spelllang', 'en')
+ meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell'))
end)
it('errors out when spell header contains NUL bytes', function()
- meths.set_option('runtimepath', testdir)
+ meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl',
spellheader:sub(1, -3) .. '\000\000')
- meths.set_option('spelllang', 'en')
+ meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E757: This does not look like a spell file',
exc_exec('set spell'))
end)
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index 1be5de6488..94ec3d4907 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -9,6 +9,8 @@ local ok = helpers.ok
local eq = helpers.eq
local matches = helpers.matches
local eval = helpers.eval
+local exec = helpers.exec
+local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua
local feed = helpers.feed
local funcs = helpers.funcs
@@ -27,21 +29,36 @@ local meths = helpers.meths
local alter_slashes = helpers.alter_slashes
local is_os = helpers.is_os
local dedent = helpers.dedent
-
-local testfile = 'Xtest_startuptime'
-after_each(function()
- os.remove(testfile)
-end)
+local tbl_map = helpers.tbl_map
+local tbl_filter = helpers.tbl_filter
+local endswith = helpers.endswith
describe('startup', function()
it('--clean', function()
clear()
- ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) ~= nil)
+ ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) ~= nil)
clear('--clean')
- ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) == nil)
+ ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) == nil)
+ end)
+
+ it('prevents remote UI infinite loop', function()
+ clear()
+ local screen
+ screen = Screen.new(84, 3)
+ screen:attach()
+ funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' })
+ screen:expect([[
+ ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) |
+ |
+ |
+ ]])
end)
it('--startuptime', function()
+ local testfile = 'Xtest_startuptime'
+ finally(function()
+ os.remove(testfile)
+ end)
clear({ args = {'--startuptime', testfile}})
assert_log('sourcing', testfile, 100)
assert_log("require%('vim%._editor'%)", testfile, 100)
@@ -58,7 +75,7 @@ describe('startup', function()
^ |
|
Entering Debug mode. Type "cont" to continue. |
- nvim_exec() |
+ nvim_exec2() |
cmd: aunmenu * |
> |
|
@@ -77,13 +94,7 @@ describe('startup', function()
end)
describe('startup', function()
- before_each(function()
- clear()
- os.remove('Xtest_startup_ttyout')
- end)
- after_each(function()
- os.remove('Xtest_startup_ttyout')
- end)
+ before_each(clear)
describe('-l Lua', function()
local function assert_l_out(expected, nvim_args, lua_args, script, input)
@@ -102,6 +113,14 @@ describe('startup', function()
end)
it('os.exit() sets Nvim exitcode', function()
+ -- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it
+ exec_lua [[
+ local asan_options = os.getenv('ASAN_OPTIONS') or ''
+ if asan_options ~= '' then
+ asan_options = asan_options .. ':'
+ end
+ vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0')
+ ]]
-- nvim -l foo.lua -arg1 -- a b c
assert_l_out([[
bufs:
@@ -126,12 +145,12 @@ describe('startup', function()
end)
it('executes stdin "-"', function()
- assert_l_out('arg0=- args=2 whoa',
+ assert_l_out('arg0=- args=2 whoa\n',
nil,
{ 'arg1', 'arg 2' },
'-',
"print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))")
- assert_l_out('biiig input: 1000042',
+ assert_l_out('biiig input: 1000042\n',
nil,
nil,
'-',
@@ -139,14 +158,37 @@ describe('startup', function()
eq(0, eval('v:shell_error'))
end)
+ it('does not truncate long print() message', function()
+ assert_l_out(('k'):rep(1234) .. '\n', nil, nil, '-', "print(('k'):rep(1234))")
+ end)
+
+ it('does not add newline when unnecessary', function()
+ assert_l_out('', nil, nil, '-', '')
+ assert_l_out('foobar\n', nil, nil, '-', [[print('foobar\n')]])
+ end)
+
it('sets _G.arg', function()
+ -- nvim -l foo.lua
+ assert_l_out([[
+ bufs:
+ nvim args: 3
+ lua args: {
+ [0] = "test/functional/fixtures/startup.lua"
+ }
+ ]],
+ {},
+ {}
+ )
+ eq(0, eval('v:shell_error'))
+
-- nvim -l foo.lua [args]
assert_l_out([[
bufs:
nvim args: 7
lua args: { "-arg1", "--arg2", "--", "arg3",
[0] = "test/functional/fixtures/startup.lua"
- }]],
+ }
+ ]],
{},
{ '-arg1', '--arg2', '--', 'arg3' }
)
@@ -158,7 +200,8 @@ describe('startup', function()
nvim args: 10
lua args: { "-arg1", "arg 2", "--", "file3", "file4",
[0] = "test/functional/fixtures/startup.lua"
- }]],
+ }
+ ]],
{ 'file1', 'file2', },
{ '-arg1', 'arg 2', '--', 'file3', 'file4' }
)
@@ -170,7 +213,8 @@ describe('startup', function()
nvim args: 5
lua args: { "-c", "set wrap?",
[0] = "test/functional/fixtures/startup.lua"
- }]],
+ }
+ ]],
{},
{ '-c', 'set wrap?' }
)
@@ -186,7 +230,8 @@ describe('startup', function()
nvim args: 7
lua args: { "-c", "set wrap?",
[0] = "test/functional/fixtures/startup.lua"
- }]],
+ }
+ ]],
{ '-c', 'set wrap?' },
{ '-c', 'set wrap?' }
)
@@ -194,15 +239,24 @@ describe('startup', function()
end)
it('disables swapfile/shada/config/plugins', function()
- assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1',
+ assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1\n',
nil,
nil,
'-',
- [[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format(
- vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.split(vim.fn.execute('scriptnames'),'\n'))))]])
+ [[print(('updatecount=%d shadafile=%s loadplugins=%s scripts=%d'):format(
+ vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]])
end)
end)
+ it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function()
+ local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless',
+ '--cmd', 'lua print(("A"):rep(1234))',
+ '-c', 'lua print(("B"):rep(1234))',
+ '+lua print(("C"):rep(1234))',
+ '+q' })
+ eq(('A'):rep(1234) .. '\r\n' .. ('B'):rep(1234) .. '\r\n' .. ('C'):rep(1234), out)
+ end)
+
it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function()
-- system() puts a pipe at both ends.
local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless',
@@ -247,6 +301,10 @@ describe('startup', function()
if is_os('win') then
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end
+ os.remove('Xtest_startup_ttyout')
+ finally(function()
+ os.remove('Xtest_startup_ttyout')
+ end)
-- Running in :terminal
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
..nvim_set..[[\"]]
@@ -264,6 +322,10 @@ describe('startup', function()
if is_os('win') then
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end
+ os.remove('Xtest_startup_ttyout')
+ finally(function()
+ os.remove('Xtest_startup_ttyout')
+ end)
-- Running in :terminal
command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
..[[%s -u NONE -i NONE --cmd \"]]
@@ -323,28 +385,6 @@ describe('startup', function()
{ '' }))
end)
- it('-e/-E interactive #7679', function()
- clear('-e')
- local screen = Screen.new(25, 3)
- screen:attach()
- feed("put ='from -e'<CR>")
- screen:expect([[
- :put ='from -e' |
- from -e |
- :^ |
- ]])
-
- clear('-E')
- screen = Screen.new(25, 3)
- screen:attach()
- feed("put ='from -E'<CR>")
- screen:expect([[
- :put ='from -E' |
- from -E |
- :^ |
- ]])
- end)
-
it('stdin with -es/-Es #7679', function()
local input = { 'append', 'line1', 'line2', '.', '%print', '' }
local inputstr = table.concat(input, '\n')
@@ -390,33 +430,16 @@ describe('startup', function()
for _,arg in ipairs({'-es', '-Es'}) do
local out = funcs.system({nvim_prog, arg,
'+set swapfile? updatecount? shadafile?',
- "+put =execute('scriptnames')", '+%print'})
+ "+put =map(getscriptinfo(), {-> v:val.name})", '+%print'})
local line1 = string.match(out, '^.-\n')
-- updatecount=0 means swapfile was disabled.
eq(" swapfile updatecount=0 shadafile=\n", line1)
-- Standard plugins were loaded, but not user config.
- eq('health.vim', string.match(out, 'health.vim'))
- eq(nil, string.match(out, 'init.vim'))
+ ok(string.find(out, 'man.lua') ~= nil)
+ ok(string.find(out, 'init.vim') == nil)
end
end)
- it('-e sets ex mode', function()
- local screen = Screen.new(25, 3)
- clear('-e')
- screen:attach()
- -- Verify we set the proper mode both before and after :vi.
- feed("put =mode(1)<CR>vi<CR>:put =mode(1)<CR>")
- screen:expect([[
- cv |
- ^n |
- :put =mode(1) |
- ]])
-
- eq('cv\n',
- funcs.system({nvim_prog, '-n', '-es' },
- { 'put =mode(1)', 'print', '' }))
- end)
-
it('fails on --embed with -es/-Es/-l', function()
matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
funcs.system({nvim_prog, '--embed', '-es' }))
@@ -426,17 +449,6 @@ describe('startup', function()
funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' }))
end)
- it('does not crash if --embed is given twice', function()
- clear{args={'--embed'}}
- assert_alive()
- end)
-
- it('does not crash when expanding cdpath during early_init', function()
- clear{env={CDPATH='~doesnotexist'}}
- assert_alive()
- eq(',~doesnotexist', eval('&cdpath'))
- end)
-
it('ENTER dismisses early message #7967', function()
local screen
screen = Screen.new(60, 6)
@@ -462,22 +474,24 @@ describe('startup', function()
]])
end)
- it("sets 'shortmess' when loading other tabs", function()
- clear({args={'-p', 'a', 'b', 'c'}})
- local screen = Screen.new(25, 4)
- screen:attach()
- screen:expect({grid=[[
- {1: a }{2: b c }{3: }{2:X}|
- ^ |
- {4:~ }|
- |
- ]],
- attr_ids={
- [1] = {bold = true},
- [2] = {background = Screen.colors.LightGrey, underline = true},
- [3] = {reverse = true},
- [4] = {bold = true, foreground = Screen.colors.Blue1},
- }})
+ it('-r works without --headless in PTY #23294', function()
+ exec([[
+ func Normalize(data) abort
+ " Windows: remove ^M and term escape sequences
+ return map(a:data, 'substitute(substitute(v:val, "\r", "", "g"), "\x1b\\%(\\]\\d\\+;.\\{-}\x07\\|\\[.\\{-}[\x40-\x7E]\\)", "", "g")')
+ endfunc
+ func OnOutput(id, data, event) dict
+ let g:stdout = Normalize(a:data)
+ endfunc
+ call jobstart([v:progpath, '-u', 'NONE', '-i', 'NONE', '-r'], {
+ \ 'pty': v:true,
+ \ 'stdout_buffered': v:true,
+ \ 'on_stdout': function('OnOutput'),
+ \ })
+ ]])
+ retry(nil, nil, function()
+ eq('Swap files found:', eval('g:stdout[0]'))
+ end)
end)
it('fixed hang issue with --headless (#11386)', function()
@@ -505,7 +519,102 @@ describe('startup', function()
'+q' })
eq('[\'+q\'] 1', out)
end)
+end)
+describe('startup', function()
+ it('-e/-E interactive #7679', function()
+ clear('-e')
+ local screen = Screen.new(25, 3)
+ screen:attach()
+ feed("put ='from -e'<CR>")
+ screen:expect([[
+ :put ='from -e' |
+ from -e |
+ :^ |
+ ]])
+
+ clear('-E')
+ screen = Screen.new(25, 3)
+ screen:attach()
+ feed("put ='from -E'<CR>")
+ screen:expect([[
+ :put ='from -E' |
+ from -E |
+ :^ |
+ ]])
+ end)
+
+ it('-e sets ex mode', function()
+ local screen = Screen.new(25, 3)
+ clear('-e')
+ screen:attach()
+ -- Verify we set the proper mode both before and after :vi.
+ feed("put =mode(1)<CR>vi<CR>:put =mode(1)<CR>")
+ screen:expect([[
+ cv |
+ ^n |
+ :put =mode(1) |
+ ]])
+
+ eq('cv\n',
+ funcs.system({nvim_prog, '-n', '-es' },
+ { 'put =mode(1)', 'print', '' }))
+ end)
+
+ it('-d does not diff non-arglist windows #13720 #21289', function()
+ write_file('Xdiff.vim', [[
+ let bufnr = nvim_create_buf(0, 1)
+ let config = {
+ \ 'relative': 'editor',
+ \ 'focusable': v:false,
+ \ 'width': 1,
+ \ 'height': 1,
+ \ 'row': 3,
+ \ 'col': 3
+ \ }
+ autocmd WinEnter * call nvim_open_win(bufnr, v:false, config)]])
+ finally(function()
+ os.remove('Xdiff.vim')
+ end)
+ clear{args={'-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim'}}
+ eq(true, meths.get_option_value('diff', {win = funcs.win_getid(1)}))
+ eq(true, meths.get_option_value('diff', {win = funcs.win_getid(2)}))
+ local float_win = funcs.win_getid(3)
+ eq('editor', meths.win_get_config(float_win).relative)
+ eq(false, meths.get_option_value('diff', {win = float_win}))
+ end)
+
+ it('does not crash if --embed is given twice', function()
+ clear{args={'--embed'}}
+ assert_alive()
+ end)
+
+ it('does not crash when expanding cdpath during early_init', function()
+ clear{env={CDPATH='~doesnotexist'}}
+ assert_alive()
+ eq(',~doesnotexist', eval('&cdpath'))
+ end)
+
+ it("sets 'shortmess' when loading other tabs", function()
+ clear({args={'-p', 'a', 'b', 'c'}})
+ local screen = Screen.new(25, 4)
+ screen:attach()
+ screen:expect({grid=[[
+ {1: a }{2: b c }{3: }{2:X}|
+ ^ |
+ {4:~ }|
+ |
+ ]],
+ attr_ids={
+ [1] = {bold = true},
+ [2] = {background = Screen.colors.LightGrey, underline = true},
+ [3] = {reverse = true},
+ [4] = {bold = true, foreground = Screen.colors.Blue1},
+ }})
+ end)
+end)
+
+describe('startup', function()
local function pack_clear(cmd)
-- add packages after config dir in rtp but before config/after
clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'},
@@ -513,7 +622,6 @@ describe('startup', function()
}
end
-
it("handles &packpath during startup", function()
pack_clear [[
let g:x = bar#test()
@@ -578,7 +686,7 @@ describe('startup', function()
]]
eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]])
- local rtp = meths.get_option'rtp'
+ local rtp = meths.get_option_value('rtp', {})
ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'),
'startswith(…)', 'rtp='..rtp)
end)
@@ -620,13 +728,13 @@ describe('startup', function()
end)
it('window widths are correct when modelines set &columns with tabpages', function()
- write_file('tab1.noft', 'vim: columns=81')
- write_file('tab2.noft', 'vim: columns=81')
+ write_file('Xtab1.noft', 'vim: columns=81')
+ write_file('Xtab2.noft', 'vim: columns=81')
finally(function()
- os.remove('tab1.noft')
- os.remove('tab2.noft')
+ os.remove('Xtab1.noft')
+ os.remove('Xtab2.noft')
end)
- clear({args = {'-p', 'tab1.noft', 'tab2.noft'}})
+ clear({args = {'-p', 'Xtab1.noft', 'Xtab2.noft'}})
eq(81, meths.win_get_width(0))
command('tabnext')
eq(81, meths.win_get_width(0))
@@ -684,7 +792,6 @@ describe('sysinit', function()
eq('loaded 1 xdg 0 vim 1',
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
end)
-
end)
describe('user config init', function()
@@ -711,15 +818,16 @@ describe('user config init', function()
end)
it('loads init.lua from XDG config home by default', function()
- clear{ args_rm={'-u' }, env=xenv }
+ clear{ args_rm={'-u'}, env=xenv }
eq(1, eval('g:lua_rc'))
eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
end)
- describe('with existing .exrc in cwd', function()
+ describe('loads existing', function()
local exrc_path = '.exrc'
local xstate = 'Xstate'
+ local xstateenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata, XDG_STATE_HOME=xstate }
local function setup_exrc_file(filename)
exrc_path = filename
@@ -749,10 +857,10 @@ describe('user config init', function()
end)
for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do
- it('loads ' .. filename, function ()
+ it(filename .. ' in cwd', function()
setup_exrc_file(filename)
- clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
+ clear{ args_rm={'-u'}, env=xstateenv }
-- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI.
eq('---', eval('g:exrc_file'))
@@ -784,7 +892,7 @@ describe('user config init', function()
-- TERMINAL -- |
]], filename, string.rep(' ', 50 - #filename)))
- clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
+ clear{ args_rm={'-u'}, env=xstateenv }
-- The 'exrc' file is now trusted.
eq(filename, eval('g:exrc_file'))
end)
@@ -817,7 +925,7 @@ describe('user config init', function()
clear{ args_rm={'-u'}, env=xenv }
feed('<cr><c-c>') -- Dismiss "Conflicting config …" message.
eq(1, eval('g:lua_rc'))
- matches('^E5422: Conflicting configs', meths.exec('messages', true))
+ matches('^E5422: Conflicting configs', exec_capture('messages'))
end)
end)
end)
@@ -843,40 +951,41 @@ describe('runtime:', function()
local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
mkdir_p(plugin_folder_path)
+ finally(function()
+ rmdir(plugin_folder_path)
+ end)
write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])
clear{ args_rm={'-u'}, env=xenv }
eq(1, eval('g:lua_plugin'))
- rmdir(plugin_folder_path)
end)
it('loads plugin/*.lua from start packages', function()
- local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category',
- 'start', 'test_plugin'}, pathsep)
+ local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin'}, pathsep)
local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
- local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
- pathsep)
+ local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
local profiler_file = 'test_startuptime.log'
-
mkdir_p(plugin_folder_path)
+ finally(function()
+ os.remove(profiler_file)
+ rmdir(plugin_path)
+ end)
+
write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv }
eq(2, eval('g:lua_plugin'))
- -- Check if plugin_file_path is listed in :scriptname
- local scripts = meths.exec(':scriptnames', true)
- assert(scripts:find(plugin_file_path))
+ -- Check if plugin_file_path is listed in getscriptinfo()
+ local scripts = tbl_map(function(s) return s.name end, funcs.getscriptinfo())
+ ok(#tbl_filter(function(s) return endswith(s, plugin_file_path) end, scripts) > 0)
-- Check if plugin_file_path is listed in startup profile
local profile_reader = io.open(profiler_file, 'r')
local profile_log = profile_reader:read('*a')
profile_reader:close()
- assert(profile_log:find(plugin_file_path))
-
- os.remove(profiler_file)
- rmdir(plugin_path)
+ ok(profile_log:find(plugin_file_path) ~= nil)
end)
it('loads plugin/*.lua from site packages', function()
@@ -886,30 +995,59 @@ describe('runtime:', function()
local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep)
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
local plugin_after_file_path = table.concat({plugin_after_path, 'helloo.lua'}, pathsep)
-
mkdir_p(plugin_folder_path)
- write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]])
mkdir_p(plugin_after_path)
+ finally(function()
+ rmdir(plugin_path)
+ end)
+
+ write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]])
write_file(plugin_after_file_path, [[table.insert(_G.lista, "dos")]])
clear{ args_rm={'-u'}, args={'--cmd', 'lua _G.lista = {}'}, env=xenv }
eq({'unos', 'dos'}, exec_lua "return _G.lista")
-
- rmdir(plugin_path)
end)
+ it('no crash setting &rtp in plugins with :packloadall called before #18315', function()
+ local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
+ mkdir_p(plugin_folder_path)
+ finally(function()
+ rmdir(plugin_folder_path)
+ end)
+
+ write_file(table.concat({plugin_folder_path, 'plugin.vim'}, pathsep), [[
+ let &runtimepath = &runtimepath
+ let g:vim_plugin = 1
+ ]])
+ write_file(table.concat({plugin_folder_path, 'plugin.lua'}, pathsep), [[
+ vim.o.runtimepath = vim.o.runtimepath
+ vim.g.lua_plugin = 1
+ ]])
- it('loads ftdetect/*.lua', function()
- local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
- local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
- mkdir_p(ftdetect_folder)
- write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])
+ clear{ args_rm={'-u'}, args = {'--cmd', 'packloadall'}, env=xenv }
- clear{ args_rm={'-u'}, env=xenv }
+ eq(1, eval('g:vim_plugin'))
+ eq(1, eval('g:lua_plugin'))
+ end)
- eq(1, eval('g:lua_ftdetect'))
- rmdir(ftdetect_folder)
+ it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function()
+ local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
+ local after_ftdetect_folder = table.concat({xconfig, 'nvim', 'after', 'ftdetect'}, pathsep)
+ mkdir_p(ftdetect_folder)
+ mkdir_p(after_ftdetect_folder)
+ finally(function()
+ rmdir(ftdetect_folder)
+ rmdir(after_ftdetect_folder)
+ end)
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/ftdetect/ are loaded after all files in ftdetect/.
+ write_file(table.concat({ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'A']])
+ write_file(table.concat({ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({after_ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'b']])
+ clear{ args_rm={'-u'}, args = {'--cmd', 'let g:seq = ""'}, env=xenv }
+ eq('ABab', eval('g:seq'))
end)
end)
diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua
index 3b5580540f..b964fb3467 100644
--- a/test/functional/editor/K_spec.lua
+++ b/test/functional/editor/K_spec.lua
@@ -59,7 +59,7 @@ describe('K', function()
end)
it('empty string falls back to :help #19298', function()
- meths.set_option('keywordprg', '')
+ meths.set_option_value('keywordprg', '', {})
meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'})
feed('K')
eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg'))
diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua
index 22857efe5b..cbaf401f06 100644
--- a/test/functional/editor/completion_spec.lua
+++ b/test/functional/editor/completion_spec.lua
@@ -941,6 +941,15 @@ describe('completion', function()
end)
end)
+ it('cmdline completion supports various string options', function()
+ eq('auto', funcs.getcompletion('set foldcolumn=', 'cmdline')[2])
+ eq({'nosplit', 'split'}, funcs.getcompletion('set inccommand=', 'cmdline'))
+ eq({'ver:3,hor:6', 'hor:', 'ver:'}, funcs.getcompletion('set mousescroll=', 'cmdline'))
+ eq('BS', funcs.getcompletion('set termpastefilter=', 'cmdline')[2])
+ eq('SpecialKey', funcs.getcompletion('set winhighlight=', 'cmdline')[1])
+ eq('SpecialKey', funcs.getcompletion('set winhighlight=NonText:', 'cmdline')[1])
+ end)
+
describe('from the commandline window', function()
it('is cleared after CTRL-C', function ()
feed('q:')
@@ -988,7 +997,7 @@ describe('completion', function()
return ''
endfunction
]])
- meths.set_option('completeopt', 'menuone,noselect')
+ meths.set_option_value('completeopt', 'menuone,noselect', {})
meths.set_var('_complist', {{
word=0,
abbr=1,
@@ -1032,93 +1041,6 @@ describe('completion', function()
]])
end)
- -- oldtest: Test_ChangedP()
- it('TextChangedI and TextChangedP autocommands', function()
- curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar'})
- source([[
- set complete=. completeopt=menuone
- let g:foo = []
- autocmd! TextChanged * :call add(g:foo, "N")
- autocmd! TextChangedI * :call add(g:foo, "I")
- autocmd! TextChangedP * :call add(g:foo, "P")
- call cursor(3, 1)
- ]])
-
- command('let g:foo = []')
- feed('o')
- poke_eventloop()
- feed('<esc>')
- eq({'I'}, eval('g:foo'))
-
- command('let g:foo = []')
- feed('S')
- poke_eventloop()
- feed('f')
- poke_eventloop()
- eq({'I', 'I'}, eval('g:foo'))
- feed('<esc>')
-
- command('let g:foo = []')
- feed('S')
- poke_eventloop()
- feed('f')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- eq({'I', 'I', 'P'}, eval('g:foo'))
- feed('<esc>')
-
- command('let g:foo = []')
- feed('S')
- poke_eventloop()
- feed('f')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- eq({'I', 'I', 'P', 'P'}, eval('g:foo'))
- feed('<esc>')
-
- command('let g:foo = []')
- feed('S')
- poke_eventloop()
- feed('f')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- eq({'I', 'I', 'P', 'P', 'P'}, eval('g:foo'))
- feed('<esc>')
-
- command('let g:foo = []')
- feed('S')
- poke_eventloop()
- feed('f')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- poke_eventloop()
- feed('<C-N>')
- eq({'I', 'I', 'P', 'P', 'P', 'P'}, eval('g:foo'))
- feed('<esc>')
-
- eq({'foo', 'bar', 'foobar', 'foo'}, eval('getline(1, "$")'))
-
- source([[
- au! TextChanged
- au! TextChangedI
- au! TextChangedP
- set complete&vim completeopt&vim
- ]])
- end)
-
it('CompleteChanged autocommand', function()
curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', ''})
source([[
@@ -1306,4 +1228,33 @@ describe('completion', function()
expect('colorscheme NOSUCHCOLORSCHEME')
assert_alive()
end)
+
+ it('complete with f flag #25598', function()
+ screen:try_resize(20, 9)
+ command('set complete+=f | edit foo | edit bar |edit foa |edit .hidden')
+ feed('i<C-n>')
+ screen:expect{grid=[[
+ foo^ |
+ {2:foo }{0: }|
+ {1:bar }{0: }|
+ {1:foa }{0: }|
+ {1:.hidden }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- }{4:match 1 of 4} |
+ ]]}
+ feed('<Esc>ccf<C-n>')
+ screen:expect{grid=[[
+ foo^ |
+ {2:foo }{0: }|
+ {1:foa }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- }{4:match 1 of 2} |
+ ]]}
+ end)
end)
diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua
index 00e83bedc8..424ce839a2 100644
--- a/test/functional/editor/fold_spec.lua
+++ b/test/functional/editor/fold_spec.lua
@@ -4,17 +4,18 @@ local clear = helpers.clear
local insert = helpers.insert
local feed = helpers.feed
local expect = helpers.expect
-local feed_command = helpers.feed_command
+local command = helpers.command
local funcs = helpers.funcs
-local foldlevel = funcs.foldlevel
-local foldclosedend = funcs.foldclosedend
local eq = helpers.eq
+local neq = helpers.neq
describe('Folds', function()
local tempfname = 'Xtest-fold.txt'
- clear()
- before_each(function() feed_command('enew!') end)
+
+ setup(clear)
+ before_each(function() command('bwipe! | new') end)
after_each(function() os.remove(tempfname) end)
+
it('manual folding adjusts with filter', function()
insert([[
1
@@ -37,8 +38,11 @@ describe('Folds', function()
18
19
20]])
- feed_command('4,$fold', '%foldopen', '10,$fold', '%foldopen')
- feed_command('1,8! cat')
+ command('4,$fold')
+ command('%foldopen')
+ command('10,$fold')
+ command('%foldopen')
+ command('1,8! cat')
feed('5ggzdzMGdd')
expect([[
1
@@ -51,22 +55,24 @@ describe('Folds', function()
8
9]])
end)
+
describe('adjusting folds after :move', function()
local function manually_fold_indent()
-- setting foldmethod twice is a trick to get vim to set the folds for me
- feed_command('set foldmethod=indent', 'set foldmethod=manual')
+ command('setlocal foldmethod=indent')
+ command('setlocal foldmethod=manual')
-- Ensure that all folds will get closed (makes it easier to test the
-- length of folds).
- feed_command('set foldminlines=0')
+ command('setlocal foldminlines=0')
-- Start with all folds open (so :move ranges aren't affected by closed
-- folds).
- feed_command('%foldopen!')
+ command('%foldopen!')
end
local function get_folds()
local rettab = {}
for i = 1, funcs.line('$') do
- table.insert(rettab, foldlevel(i))
+ table.insert(rettab, funcs.foldlevel(i))
end
return rettab
end
@@ -75,16 +81,16 @@ describe('Folds', function()
-- This test is easy because we just need to ensure that the resulting
-- fold is the same as calculated when creating folds from scratch.
insert(insert_string)
- feed_command(move_command)
+ command(move_command)
local after_move_folds = get_folds()
-- Doesn't change anything, but does call foldUpdateAll()
- feed_command('set foldminlines=0')
+ command('setlocal foldminlines=0')
eq(after_move_folds, get_folds())
-- Set up the buffer with insert_string for the manual fold testing.
- feed_command('enew!')
+ command('enew!')
insert(insert_string)
manually_fold_indent()
- feed_command(move_command)
+ command(move_command)
end
it('neither closes nor corrupts folds', function()
@@ -130,19 +136,20 @@ a
for i = 1,funcs.line('$') do
eq(-1, funcs.foldclosed(i))
if i == 1 or i == 7 or i == 13 then
- eq(0, foldlevel(i))
+ eq(0, funcs.foldlevel(i))
elseif i == 4 then
- eq(2, foldlevel(i))
+ eq(2, funcs.foldlevel(i))
else
- eq(1, foldlevel(i))
+ eq(1, funcs.foldlevel(i))
end
end
-- folds are not corrupted
feed('zM')
- eq(6, foldclosedend(2))
- eq(12, foldclosedend(8))
- eq(18, foldclosedend(14))
+ eq(6, funcs.foldclosedend(2))
+ eq(12, funcs.foldclosedend(8))
+ eq(18, funcs.foldclosedend(14))
end)
+
it("doesn't split a fold when the move is within it", function()
test_move_indent([[
a
@@ -157,6 +164,7 @@ a
a]], '5m6')
eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds())
end)
+
it('truncates folds that end in the moved range', function()
test_move_indent([[
a
@@ -168,6 +176,7 @@ a
a]], '4,5m6')
eq({0, 1, 2, 0, 0, 0, 0}, get_folds())
end)
+
it('moves folds that start between moved range and destination', function()
test_move_indent([[
a
@@ -185,6 +194,7 @@ a
a]], '3,4m$')
eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds())
end)
+
it('does not affect folds outside changed lines', function()
test_move_indent([[
a
@@ -198,6 +208,7 @@ a
a]], '4m5')
eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds())
end)
+
it('moves and truncates folds that start in moved range', function()
test_move_indent([[
a
@@ -212,6 +223,7 @@ a
a]], '1,3m7')
eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds())
end)
+
it('breaks a fold when moving text into it', function()
test_move_indent([[
a
@@ -223,6 +235,7 @@ a
a]], '$m4')
eq({0, 1, 2, 2, 0, 0, 0}, get_folds())
end)
+
it('adjusts correctly when moving a range backwards', function()
test_move_indent([[
a
@@ -232,6 +245,7 @@ a
a]], '2,3m0')
eq({1, 2, 0, 0, 0}, get_folds())
end)
+
it('handles shifting all remaining folds', function()
test_move_indent([[
a
@@ -252,6 +266,7 @@ a]], '13m7')
eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds())
end)
end)
+
it('updates correctly on :read', function()
-- luacheck: ignore 621
helpers.write_file(tempfname, [[
@@ -265,8 +280,10 @@ a]], '13m7')
a
a
]])
- feed_command('set foldmethod=indent', '2', '%foldopen')
- feed_command('read ' .. tempfname)
+ command('setlocal foldmethod=indent')
+ command('2')
+ command('%foldopen')
+ command('read ' .. tempfname)
-- Just to check we have the correct file text.
expect([[
a
@@ -288,6 +305,7 @@ a]], '13m7')
eq(1, funcs.foldlevel(i))
end
end)
+
it('combines folds when removing separating space', function()
-- luacheck: ignore 621
insert([[
@@ -300,9 +318,11 @@ a]], '13m7')
a
a
]])
- feed_command('set foldmethod=indent', '3,5d')
+ command('setlocal foldmethod=indent')
+ command('3,5d')
eq(5, funcs.foldclosedend(1))
end)
+
it("doesn't combine folds that have a specified end", function()
insert([[
{{{
@@ -314,9 +334,12 @@ a]], '13m7')
}}}
]])
- feed_command('set foldmethod=marker', '3,5d', '%foldclose')
+ command('setlocal foldmethod=marker')
+ command('3,5d')
+ command('%foldclose')
eq(2, funcs.foldclosedend(1))
end)
+
it('splits folds according to >N and <N with foldexpr', function()
helpers.source([[
function TestFoldExpr(lnum)
@@ -350,8 +373,11 @@ a]], '13m7')
a
a
]])
- feed_command('set foldmethod=expr', 'set foldexpr=TestFoldExpr(v:lnum)', '2', 'foldopen')
- feed_command('read ' .. tempfname, '%foldclose')
+ command('setlocal foldmethod=expr foldexpr=TestFoldExpr(v:lnum)')
+ command('2')
+ command('foldopen')
+ command('read ' .. tempfname)
+ command('%foldclose')
eq(2, funcs.foldclosedend(1))
eq(0, funcs.foldlevel(3))
eq(0, funcs.foldlevel(4))
@@ -359,4 +385,64 @@ a]], '13m7')
eq(10, funcs.foldclosedend(7))
eq(14, funcs.foldclosedend(11))
end)
+
+ it('no folds remain if :delete makes buffer empty #19671', function()
+ command('setlocal foldmethod=manual')
+ funcs.setline(1, {'foo', 'bar', 'baz'})
+ command('2,3fold')
+ command('%delete')
+ eq(0, funcs.foldlevel(1))
+ end)
+
+ it('multibyte fold markers work #20438', function()
+ command('setlocal foldmethod=marker foldmarker=«,» commentstring=/*%s*/')
+ insert([[
+ bbbbb
+ bbbbb
+ bbbbb]])
+ feed('zfgg')
+ expect([[
+ bbbbb/*«*/
+ bbbbb
+ bbbbb/*»*/]])
+ eq(1, funcs.foldlevel(1))
+ end)
+
+ it('updates correctly with indent method and visual blockwise insertion #22898', function()
+ insert([[
+ a
+ b
+ ]])
+ command('setlocal foldmethod=indent shiftwidth=2')
+ feed('gg0<C-v>jI <Esc>') -- indent both lines using visual blockwise mode
+ eq(1, funcs.foldlevel(1))
+ eq(1, funcs.foldlevel(2))
+ end)
+
+ it("doesn't open folds with indent method when inserting lower foldlevel line", function()
+ insert([[
+ insert an unindented line under this line
+ keep the lines under this line folded
+ keep this line folded 1
+ keep this line folded 2
+ ]])
+ command('set foldmethod=indent shiftwidth=2 noautoindent')
+ eq(1, funcs.foldlevel(1))
+ eq(1, funcs.foldlevel(2))
+ eq(2, funcs.foldlevel(3))
+ eq(2, funcs.foldlevel(4))
+
+ feed('zo') -- open the outer fold
+ neq(-1, funcs.foldclosed(3)) -- make sure the inner fold is not open
+
+ feed('gg0oa<Esc>') -- insert unindented line
+
+ eq(1, funcs.foldlevel(1)) --| insert an unindented line under this line
+ eq(0, funcs.foldlevel(2)) --|a
+ eq(1, funcs.foldlevel(3)) --| keep the lines under this line folded
+ eq(2, funcs.foldlevel(4)) --| keep this line folded 1
+ eq(2, funcs.foldlevel(5)) --| keep this line folded 2
+
+ neq(-1, funcs.foldclosed(4)) -- make sure the inner fold is still not open
+ end)
end)
diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua
index 63f522fe6e..dc056cb252 100644
--- a/test/functional/editor/jump_spec.lua
+++ b/test/functional/editor/jump_spec.lua
@@ -48,6 +48,48 @@ describe('jumplist', function()
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
end)
+
+ it('<C-O> scrolls cursor halfway when switching buffer #25763', function()
+ write_file(fname1, ('foobar\n'):rep(100))
+ write_file(fname2, 'baz')
+
+ local screen = Screen.new(5, 25)
+ screen:attach()
+ command('set number')
+ command('edit '..fname1)
+ feed('35gg')
+ command('edit '..fname2)
+ feed('<C-O>')
+ screen:expect{grid=[[
+ {1: 24 }foobar |
+ {1: 25 }foobar |
+ {1: 26 }foobar |
+ {1: 27 }foobar |
+ {1: 28 }foobar |
+ {1: 29 }foobar |
+ {1: 30 }foobar |
+ {1: 31 }foobar |
+ {1: 32 }foobar |
+ {1: 33 }foobar |
+ {1: 34 }foobar |
+ {1: 35 }^foobar |
+ {1: 36 }foobar |
+ {1: 37 }foobar |
+ {1: 38 }foobar |
+ {1: 39 }foobar |
+ {1: 40 }foobar |
+ {1: 41 }foobar |
+ {1: 42 }foobar |
+ {1: 43 }foobar |
+ {1: 44 }foobar |
+ {1: 45 }foobar |
+ {1: 46 }foobar |
+ {1: 47 }foobar |
+ |
+ ]], attr_ids={
+ [1] = {foreground = Screen.colors.Brown};
+ }}
+ end)
end)
describe("jumpoptions=stack behaves like 'tagstack'", function()
diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua
index b3b190ef79..e669d7f2bb 100644
--- a/test/functional/editor/mark_spec.lua
+++ b/test/functional/editor/mark_spec.lua
@@ -24,7 +24,6 @@ describe('named marks', function()
os.remove(file2)
end)
-
it("can be set", function()
command("edit " .. file1)
command("mark a")
@@ -40,59 +39,59 @@ describe('named marks', function()
it("errors when set out of range with :mark", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "1000mark x")
- eq("nvim_exec(): Vim(mark):E16: Invalid range: 1000mark x", err)
+ eq("nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x", err)
end)
it("errors when set out of range with :k", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "1000kx")
- eq("nvim_exec(): Vim(k):E16: Invalid range: 1000kx", err)
+ eq("nvim_exec2(): Vim(k):E16: Invalid range: 1000kx", err)
end)
it("errors on unknown mark name with :mark", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "mark #")
- eq("nvim_exec(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err)
+ eq("nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err)
end)
it("errors on unknown mark name with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! '#")
- eq("nvim_exec(): Vim(normal):E78: Unknown mark", err)
+ eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err)
end)
it("errors on unknown mark name with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `#")
- eq("nvim_exec(): Vim(normal):E78: Unknown mark", err)
+ eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err)
end)
it("errors when moving to a mark that is not set with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! 'z")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
err = pcall_err(helpers.exec_capture, "normal! '.")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)
it("errors when moving to a mark that is not set with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `z")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
err = pcall_err(helpers.exec_capture, "normal! `>")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)
it("errors when moving to a global mark that is not set with '", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! 'Z")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)
it("errors when moving to a global mark that is not set with `", function()
command("edit " .. file1)
local err = pcall_err(helpers.exec_capture, "normal! `Z")
- eq("nvim_exec(): Vim(normal):E20: Mark not set", err)
+ eq("nvim_exec2(): Vim(normal):E20: Mark not set", err)
end)
it("can move to them using '", function()
@@ -147,13 +146,27 @@ describe('named marks', function()
eq({2, 2}, cursor())
end)
+ it("can move to them using :'", function()
+ command("args " .. file1 .. " " .. file2)
+ feed("j")
+ feed("ma")
+ feed("G")
+ command("'a")
+ eq({2, 0}, cursor())
+ feed("mA")
+ command("next")
+ command("'A")
+ eq(1, meths.get_current_buf().id)
+ eq({2, 0}, cursor())
+ end)
+
it("errors when it can't find the buffer", function()
command("args " .. file1 .. " " .. file2)
feed("mA")
command("next")
command("bw! " .. file1 )
local err = pcall_err(helpers.exec_capture, "normal! 'A")
- eq("nvim_exec(): Vim(normal):E92: Buffer 1 not found", err)
+ eq("nvim_exec2(): Vim(normal):E92: Buffer 1 not found", err)
os.remove(file1)
end)
@@ -161,7 +174,7 @@ describe('named marks', function()
feed('ifoo<Esc>mA')
command('enew')
feed('ibar<Esc>')
- eq('Vim(print):E20: Mark not set', pcall_err(command, [['Aprint]]))
+ eq("Vim(print):E20: Mark not set: 'Aprint", pcall_err(command, [['Aprint]]))
end)
it("leave a context mark when moving with '", function()
@@ -413,8 +426,52 @@ describe('named marks view', function()
6 line |
^7 line |
8 line |
- {MATCH:.*} |
+ {MATCH:.*marks} |
|
]])
end)
+
+ it('fallback to standard behavior when mark is loaded from shada', function()
+ local screen = Screen.new(10, 6)
+ screen:attach()
+ command('edit ' .. file1)
+ feed('G')
+ feed('mA')
+ screen:expect([[
+ 26 line |
+ 27 line |
+ 28 line |
+ 29 line |
+ ^30 line |
+ |
+ ]])
+ command('set shadafile=Xtestfile-functional-editor-marks-shada')
+ finally(function()
+ command('set shadafile=NONE')
+ os.remove('Xtestfile-functional-editor-marks-shada')
+ end)
+ command('wshada!')
+ command('bwipe!')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ command('rshada!')
+ command('edit ' .. file1)
+ feed('`"')
+ screen:expect([[
+ 26 line |
+ 27 line |
+ 28 line |
+ 29 line |
+ ^30 line |
+ |
+ ]])
+ feed('`A')
+ screen:expect_unchanged()
+ end)
end)
diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua
index 50cc5e17ee..d34b5a1a28 100644
--- a/test/functional/editor/mode_cmdline_spec.lua
+++ b/test/functional/editor/mode_cmdline_spec.lua
@@ -1,9 +1,11 @@
-- Cmdline-mode tests.
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear, insert, funcs, eq, feed =
helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed
local eval = helpers.eval
+local command = helpers.command
local meths = helpers.meths
describe('cmdline', function()
@@ -43,6 +45,30 @@ describe('cmdline', function()
eq('"<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>', eval('@:'))
end)
+ it('redraws statusline when toggling overstrike', function()
+ local screen = Screen.new(60, 4)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {reverse = true, bold = true}, -- StatusLine
+ })
+ screen:attach()
+ command('set laststatus=2 statusline=%!mode(1)')
+ feed(':')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {1:c }|
+ :^ |
+ ]]}
+ feed('<Insert>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {1:cr }|
+ :^ |
+ ]]}
+ end)
+
describe('history', function()
it('correctly clears start of the history', function()
-- Regression test: check absence of the memory leak when clearing start of
@@ -55,7 +81,7 @@ describe('cmdline', function()
it('correctly clears end of the history', function()
-- Regression test: check absence of the memory leak when clearing end of
-- the history using ex_getln.c/clr_history().
- meths.set_option('history', 1)
+ meths.set_option_value('history', 1, {})
eq(1, funcs.histadd(':', 'foo'))
eq(1, funcs.histdel(':'))
eq('', funcs.histget(':', -1))
diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua
index cd51a65be3..37651164f5 100644
--- a/test/functional/editor/mode_insert_spec.lua
+++ b/test/functional/editor/mode_insert_spec.lua
@@ -1,6 +1,7 @@
-- Insert-mode tests.
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local expect = helpers.expect
local command = helpers.command
@@ -48,6 +49,56 @@ describe('insert-mode', function()
feed('i<C-r>"')
expect('påskägg')
end)
+
+ it('double quote is removed after hit-enter prompt #22609', function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {foreground = Screen.colors.Blue}, -- SpecialKey
+ [2] = {foreground = Screen.colors.SlateBlue},
+ [3] = {bold = true}, -- ModeMsg
+ [4] = {reverse = true, bold = true}, -- MsgSeparator
+ [5] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
+ [6] = {foreground = Screen.colors.SeaGreen, bold = true}, -- MoreMsg
+ })
+ screen:attach()
+ feed('i<C-R>')
+ screen:expect([[
+ {1:^"} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- INSERT --} |
+ ]])
+ feed('={}')
+ screen:expect([[
+ {1:"} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ={2:{}}^ |
+ ]])
+ feed('<CR>')
+ screen:expect([[
+ {1:"} |
+ {0:~ }|
+ {4: }|
+ ={2:{}} |
+ {5:E731: Using a Dictionary as a String} |
+ {6:Press ENTER or type command to continue}^ |
+ ]])
+ feed('<CR>')
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- INSERT --} |
+ ]])
+ end)
end)
describe('Ctrl-O', function()
@@ -141,4 +192,38 @@ describe('insert-mode', function()
feed('i<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><Esc>')
expect('<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>')
end)
+
+ it('multi-char mapping updates screen properly #25626', function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [1] = {bold = true, reverse = true}; -- StatusLine
+ [2] = {reverse = true}; -- StatusLineNC
+ [3] = {bold = true}; -- ModeMsg
+ })
+ screen:attach()
+ command('vnew')
+ insert('foo\nfoo\nfoo')
+ command('wincmd w')
+ command('set timeoutlen=10000')
+ command('inoremap jk <Esc>')
+ feed('i<CR>βββ<Left><Left>j')
+ screen:expect{grid=[[
+ foo │ |
+ foo │β^jβ |
+ foo │{0:~ }|
+ {0:~ }│{0:~ }|
+ {2:[No Name] [+] }{1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]]}
+ feed('k')
+ screen:expect{grid=[[
+ foo │ |
+ foo │^βββ |
+ foo │{0:~ }|
+ {0:~ }│{0:~ }|
+ {2:[No Name] [+] }{1:[No Name] [+] }|
+ |
+ ]]}
+ end)
end)
diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua
index 5050edff5c..47068470bb 100644
--- a/test/functional/editor/put_spec.lua
+++ b/test/functional/editor/put_spec.lua
@@ -9,22 +9,21 @@ local eq = helpers.eq
local map = helpers.tbl_map
local filter = helpers.tbl_filter
local feed_command = helpers.feed_command
+local command = helpers.command
local curbuf_contents = helpers.curbuf_contents
local funcs = helpers.funcs
local dedent = helpers.dedent
-local getreg = funcs.getreg
local function reset()
- feed_command('enew!')
+ command('bwipe! | new')
insert([[
Line of words 1
Line of words 2]])
- feed_command('goto 1')
+ command('goto 1')
feed('itest_string.<esc>u')
funcs.setreg('a', 'test_stringa', 'V')
funcs.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b')
funcs.setreg('"', 'test_string"', 'v')
- feed_command('set virtualedit=')
end
-- We check the last inserted register ". in each of these tests because it is
@@ -508,10 +507,10 @@ describe('put command', function()
test_expect(exception_table, after_redo)
if selection_string then
if not conversion_table.put_backwards then
- eq(selection_string, getreg('"'))
+ eq(selection_string, funcs.getreg('"'))
end
else
- eq('test_string"', getreg('"'))
+ eq('test_string"', funcs.getreg('"'))
end
end
end
@@ -644,7 +643,7 @@ describe('put command', function()
-- Set curswant to '8' to be at the end of the tab character
-- This is where the cursor is put back after the 'u' command.
funcs.setpos('.', {0, 2, 1, 0, 8})
- feed_command('set autoindent')
+ command('set autoindent')
end
)
end)
@@ -655,7 +654,7 @@ describe('put command', function()
test_stringx" Line of words 2]]
run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2')
- feed_command('set virtualedit=all')
+ command('setlocal virtualedit=all')
funcs.setpos('.', {0, 2, 1, 2, 3})
end)
end)
@@ -667,7 +666,7 @@ describe('put command', function()
Line of words 2]]
run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2')
- feed_command('set virtualedit=all')
+ command('setlocal virtualedit=all')
funcs.setpos('.', {0, 1, 16, 1, 17})
end, true)
end)
@@ -717,7 +716,7 @@ describe('put command', function()
return function(exception_table, after_redo)
test_expect(exception_table, after_redo)
if not conversion_table.put_backwards then
- eq('Line of words 1\n', getreg('"'))
+ eq('Line of words 1\n', funcs.getreg('"'))
end
end
end
@@ -753,7 +752,7 @@ describe('put command', function()
return function(e,c)
test_expect(e,c)
if not conversion_table.put_backwards then
- eq('Lin\nLin', getreg('"'))
+ eq('Lin\nLin', funcs.getreg('"'))
end
end
end
@@ -836,7 +835,7 @@ describe('put command', function()
'vp',
function()
funcs.setline('$', ' Line of words 2')
- feed_command('set virtualedit=all')
+ command('setlocal virtualedit=all')
funcs.setpos('.', {0, 2, 1, 2, 3})
end,
nil,
@@ -851,7 +850,7 @@ describe('put command', function()
base_expect_string,
'vp',
function()
- feed_command('set virtualedit=all')
+ command('setlocal virtualedit=all')
funcs.setpos('.', {0, 1, 16, 2, 18})
end,
true,
@@ -903,6 +902,8 @@ describe('put command', function()
end
end
end, unchanged=(not should_ring)}
+ screen.bell = false
+ screen.visualbell = false
end
it('should not ring the bell with gp at end of line', function()
@@ -920,12 +921,12 @@ describe('put command', function()
end)
it('should ring the bell when deleting if not appropriate', function()
- feed_command('goto 2')
- feed('i<bs><esc>')
- expect([[
- ine of words 1
- Line of words 2]])
- bell_test(function() feed('".P') end, true)
+ command('goto 2')
+ feed('i<bs><esc>')
+ expect([[
+ ine of words 1
+ Line of words 2]])
+ bell_test(function() feed('".P') end, true)
end)
it('should restore cursor position after undo of ".p', function()
@@ -935,7 +936,7 @@ describe('put command', function()
end)
it("should be unaffected by 'autoindent' with V\".2p", function()
- feed_command('set autoindent')
+ command('set autoindent')
feed('i test_string.<esc>u')
feed('V".2p')
expect([[
diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua
index fadb5c9b42..4134eed87e 100644
--- a/test/functional/ex_cmds/append_spec.lua
+++ b/test/functional/ex_cmds/append_spec.lua
@@ -8,6 +8,7 @@ local clear = helpers.clear
local funcs = helpers.funcs
local command = helpers.command
local curbufmeths = helpers.curbufmeths
+local meths = helpers.meths
local Screen = require('test.functional.ui.screen')
local cmdtest = function(cmd, prep, ret1)
@@ -42,7 +43,7 @@ local cmdtest = function(cmd, prep, ret1)
eq(hisline, funcs.histget(':', -2))
eq(cmd, funcs.histget(':'))
-- Test that command-line window was launched
- eq('nofile', curbufmeths.get_option('buftype'))
+ eq('nofile', meths.get_option_value('buftype', {}))
eq('n', funcs.mode(1))
feed('<CR>')
eq('c', funcs.mode(1))
diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua
index 5ed71651c7..b6a3713158 100644
--- a/test/functional/ex_cmds/cd_spec.lua
+++ b/test/functional/ex_cmds/cd_spec.lua
@@ -1,6 +1,6 @@
-- Specs for :cd, :tcd, :lcd and getcwd()
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
@@ -11,6 +11,7 @@ local exc_exec = helpers.exc_exec
local pathsep = helpers.get_pathsep()
local skip = helpers.skip
local is_os = helpers.is_os
+local mkdir = helpers.mkdir
-- These directories will be created for testing
local directories = {
@@ -36,14 +37,14 @@ for _, cmd in ipairs {'cd', 'chdir'} do
before_each(function()
clear()
for _, d in pairs(directories) do
- lfs.mkdir(d)
+ mkdir(d)
end
directories.start = cwd()
end)
after_each(function()
for _, d in pairs(directories) do
- lfs.rmdir(d)
+ luv.fs_rmdir(d)
end
end)
@@ -273,7 +274,7 @@ end
describe("getcwd()", function ()
before_each(function()
clear()
- lfs.mkdir(directories.global)
+ mkdir(directories.global)
end)
after_each(function()
diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua
index 919d167712..2a2628350d 100644
--- a/test/functional/ex_cmds/cmd_map_spec.lua
+++ b/test/functional/ex_cmds/cmd_map_spec.lua
@@ -90,7 +90,7 @@ describe('mappings with <Cmd>', function()
{1:~ }|
{1:~ }|
{1:~ }|
- {2:E5521: <Cmd> mapping must end with <CR> before second <Cmd>} |
+ {2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} |
]])
command('noremap <F3> <Cmd>let x = 3')
@@ -103,7 +103,7 @@ describe('mappings with <Cmd>', function()
{1:~ }|
{1:~ }|
{1:~ }|
- {2:E5520: <Cmd> mapping must end with <CR>} |
+ {2:E1255: <Cmd> mapping must end with <CR>} |
]])
eq(0, eval('x'))
end)
@@ -451,7 +451,7 @@ describe('mappings with <Cmd>', function()
]])
eq('s', funcs.mode(1))
- -- visual mapping in select mode restart selct mode after operator
+ -- visual mapping in select mode restart select mode after operator
feed('<F5>')
eq('s', funcs.mode(1))
eq({'some short l'}, funcs.getreg('a',1,1))
diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua
index afa6b519d5..6a0b40bd88 100644
--- a/test/functional/ex_cmds/dict_notifications_spec.lua
+++ b/test/functional/ex_cmds/dict_notifications_spec.lua
@@ -9,7 +9,7 @@ local command = helpers.command
local eval = helpers.eval
-describe('VimL dictionary notifications', function()
+describe('Vimscript dictionary notifications', function()
local channel
before_each(function()
diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua
index e243f3c524..a92329ede5 100644
--- a/test/functional/ex_cmds/excmd_spec.lua
+++ b/test/functional/ex_cmds/excmd_spec.lua
@@ -2,6 +2,7 @@ local helpers = require("test.functional.helpers")(after_each)
local command = helpers.command
local eq = helpers.eq
local clear = helpers.clear
+local funcs = helpers.funcs
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
@@ -10,21 +11,43 @@ describe('Ex cmds', function()
clear()
end)
+ local function check_excmd_err(cmd, err)
+ eq(err .. ': ' .. cmd, pcall_err(command, cmd))
+ end
+
it('handle integer overflow from user-input #5555', function()
command(':9999999999999999999999999999999999999999')
command(':later 9999999999999999999999999999999999999999')
command(':echo expand("#<9999999999999999999999999999999999999999")')
command(':lockvar 9999999999999999999999999999999999999999')
command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999')
- eq('Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999',
- pcall_err(command, ':tabnext 9999999999999999999999999999999999999999'))
- eq('Vim(Next):E939: Positive count required',
- pcall_err(command, ':N 9999999999999999999999999999999999999999'))
+ check_excmd_err(':tabnext 9999999999999999999999999999999999999999',
+ 'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999')
+ check_excmd_err(':N 9999999999999999999999999999999999999999',
+ 'Vim(Next):E939: Positive count required')
+ check_excmd_err(':bdelete 9999999999999999999999999999999999999999',
+ 'Vim(bdelete):E939: Positive count required')
eq('Vim(menu):E329: No menu "9999999999999999999999999999999999999999"',
pcall_err(command, ':menu 9999999999999999999999999999999999999999'))
- eq('Vim(bdelete):E939: Positive count required',
- pcall_err(command, ':bdelete 9999999999999999999999999999999999999999'))
assert_alive()
end)
-end)
+ it('listing long user command does not crash', function()
+ command('execute "command" repeat("T", 255) ":"')
+ command('command')
+ end)
+
+ it(':def is an unknown command #23149', function()
+ eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
+ eq(1, funcs.exists(':d'))
+ eq('delete', funcs.fullcommand('d'))
+ eq(1, funcs.exists(':de'))
+ eq('delete', funcs.fullcommand('de'))
+ eq(0, funcs.exists(':def'))
+ eq('', funcs.fullcommand('def'))
+ eq(1, funcs.exists(':defe'))
+ eq('defer', funcs.fullcommand('defe'))
+ eq(2, funcs.exists(':defer'))
+ eq('defer', funcs.fullcommand('defer'))
+ end)
+end)
diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua
index 771c283134..131661828e 100644
--- a/test/functional/ex_cmds/file_spec.lua
+++ b/test/functional/ex_cmds/file_spec.lua
@@ -1,17 +1,18 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local funcs = helpers.funcs
local rmdir = helpers.rmdir
+local mkdir = helpers.mkdir
describe(':file', function()
- local swapdir = lfs.currentdir()..'/Xtest-file_spec'
+ local swapdir = luv.cwd()..'/Xtest-file_spec'
before_each(function()
clear()
rmdir(swapdir)
- lfs.mkdir(swapdir)
+ mkdir(swapdir)
end)
after_each(function()
command('%bwipeout!')
diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua
index 0ec7249218..aca0cbbaa6 100644
--- a/test/functional/ex_cmds/help_spec.lua
+++ b/test/functional/ex_cmds/help_spec.lua
@@ -4,6 +4,10 @@ local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local funcs = helpers.funcs
+local meths = helpers.meths
+local mkdir = helpers.mkdir
+local rmdir = helpers.rmdir
+local write_file = helpers.write_file
describe(':help', function()
before_each(clear)
@@ -25,4 +29,17 @@ describe(':help', function()
-- Before #9773, Nvim would crash on quitting the help window.
eq(1002, funcs.win_getid())
end)
+
+ it('multibyte help tags work #23975', function()
+ mkdir('Xhelptags')
+ finally(function()
+ rmdir('Xhelptags')
+ end)
+ mkdir('Xhelptags/doc')
+ write_file('Xhelptags/doc/Xhelptags.txt', '*…*')
+ command('helptags Xhelptags/doc')
+ command('set rtp+=Xhelptags')
+ command('help …')
+ eq('*…*', meths.get_current_line())
+ end)
end)
diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua
index 1cd6759a53..958dd99226 100644
--- a/test/functional/ex_cmds/highlight_spec.lua
+++ b/test/functional/ex_cmds/highlight_spec.lua
@@ -3,6 +3,9 @@ local helpers = require("test.functional.helpers")(after_each)
local eq, command = helpers.eq, helpers.command
local clear = helpers.clear
local eval, exc_exec = helpers.eval, helpers.exc_exec
+local exec = helpers.exec
+local funcs = helpers.funcs
+local meths = helpers.meths
describe(':highlight', function()
local screen
@@ -21,7 +24,7 @@ describe(':highlight', function()
end)
it('invalid group name', function()
- eq('Vim(highlight):E411: highlight group not found: foo',
+ eq('Vim(highlight):E411: Highlight group not found: foo',
exc_exec("highlight foo"))
end)
@@ -36,4 +39,29 @@ describe(':highlight', function()
command('highlight normal ctermbg=red')
eq('9', eval('synIDattr(hlID("Normal"), "bg", "cterm")'))
end)
+
+ it('only the last underline style takes effect #22371', function()
+ command('highlight NonText gui=underline,undercurl')
+ eq('', eval('synIDattr(hlID("NonText"), "underline", "gui")'))
+ eq('1', eval('synIDattr(hlID("NonText"), "undercurl", "gui")'))
+ command('highlight NonText gui=undercurl,underline')
+ eq('', eval('synIDattr(hlID("NonText"), "undercurl", "gui")'))
+ eq('1', eval('synIDattr(hlID("NonText"), "underline", "gui")'))
+ end)
+
+ it('clear', function()
+ meths.set_var('colors_name', 'foo')
+ eq(1, funcs.exists('g:colors_name'))
+ command('hi clear')
+ eq(0, funcs.exists('g:colors_name'))
+ meths.set_var('colors_name', 'foo')
+ eq(1, funcs.exists('g:colors_name'))
+ exec([[
+ func HiClear()
+ hi clear
+ endfunc
+ ]])
+ funcs.HiClear()
+ eq(0, funcs.exists('g:colors_name'))
+ end)
end)
diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua
index 2583d80269..d02af21731 100644
--- a/test/functional/ex_cmds/ls_spec.lua
+++ b/test/functional/ex_cmds/ls_spec.lua
@@ -14,7 +14,7 @@ describe(':ls', function()
end)
it('R, F for :terminal buffers', function()
- nvim('set_option', 'shell', string.format('"%s" INTERACT', testprg('shell-test')))
+ nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('edit foo')
command('set hidden')
diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua
index bf585ee44c..d82f59ddf9 100644
--- a/test/functional/ex_cmds/make_spec.lua
+++ b/test/functional/ex_cmds/make_spec.lua
@@ -22,20 +22,18 @@ describe(':make', function()
end)
it('captures stderr & non zero exit code #14349', function ()
- nvim('set_option', 'makeprg', testprg('shell-test')..' foo')
+ nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {})
local out = eval('execute("make")')
- -- Make program exit code correctly captured
- matches('\nshell returned 3', out)
-- Error message is captured in the file and printed in the footer
- matches('\n.*%: Unknown first argument%: foo', out)
+ matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out)
end)
it('captures stderr & zero exit code #14349', function ()
- nvim('set_option', 'makeprg', testprg('shell-test'))
+ nvim('set_option_value', 'makeprg', testprg('shell-test'), {})
local out = eval('execute("make")')
-- Ensure there are no "shell returned X" messages between
- -- command and last line (indicating zero exit)
- matches('LastExitCode%s+[(]', out)
+ -- command and last line (indicating zero exit)
+ matches('LastExitCode%s+ready [$]%s+[(]', out)
matches('\n.*%: ready [$]', out)
end)
diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua
index ec912053b2..a580e88b93 100644
--- a/test/functional/ex_cmds/map_spec.lua
+++ b/test/functional/ex_cmds/map_spec.lua
@@ -18,7 +18,7 @@ describe(':*map', function()
it('are not affected by &isident', function()
meths.set_var('counter', 0)
command('nnoremap <C-x> :let counter+=1<CR>')
- meths.set_option('isident', ('%u'):format(('>'):byte()))
+ meths.set_option_value('isident', ('%u'):format(('>'):byte()), {})
command('nnoremap <C-y> :let counter+=1<CR>')
-- &isident used to disable keycode parsing here as well
feed('\24\25<C-x><C-y>')
@@ -152,7 +152,7 @@ describe('Screen', function()
~ |
~ |
~ |
- > |
+ -- INSERT -- |
]])
end)
diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua
index 0a0c7ca410..7522d4a99c 100644
--- a/test/functional/ex_cmds/mksession_spec.lua
+++ b/test/functional/ex_cmds/mksession_spec.lua
@@ -1,4 +1,3 @@
-local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
@@ -15,16 +14,19 @@ local sleep = helpers.sleep
local meths = helpers.meths
local skip = helpers.skip
local is_os = helpers.is_os
+local mkdir = helpers.mkdir
local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec'
+if helpers.skip(helpers.is_os('win')) then return end
+
describe(':mksession', function()
local session_file = file_prefix .. '.vim'
local tab_dir = file_prefix .. '.d'
before_each(function()
clear()
- lfs.mkdir(tab_dir)
+ mkdir(tab_dir)
end)
after_each(function()
@@ -79,13 +81,13 @@ describe(':mksession', function()
local buf_count = #meths.list_bufs()
eq(2, buf_count)
- eq('terminal', meths.buf_get_option(0, 'buftype'))
+ eq('terminal', meths.get_option_value('buftype', {}))
test_terminal_session_disabled(2)
-- no terminal should be set. As a side effect we end up with a blank buffer
- eq('', meths.buf_get_option(meths.list_bufs()[1], 'buftype'))
- eq('', meths.buf_get_option(meths.list_bufs()[2], 'buftype'))
+ eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] }))
+ eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] }))
end
)
@@ -110,7 +112,7 @@ describe(':mksession', function()
it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function()
command('terminal')
- eq('terminal', meths.buf_get_option(0, 'buftype'))
+ eq('terminal', meths.get_option_value('buftype', {}))
local buf_count = #meths.list_bufs()
eq(1, buf_count)
@@ -118,7 +120,7 @@ describe(':mksession', function()
test_terminal_session_disabled(1)
-- no terminal should be set
- eq('', meths.buf_get_option(0, 'buftype'))
+ eq('', meths.get_option_value('buftype', {}))
end)
it('restores tab-local working directories', function()
@@ -247,7 +249,7 @@ describe(':mksession', function()
style = 'minimal',
}
meths.open_win(buf, false, config)
- local cmdheight = meths.get_option('cmdheight')
+ local cmdheight = meths.get_option_value('cmdheight', {})
command('mksession ' .. session_file)
-- Create a new test instance of Nvim.
@@ -260,7 +262,7 @@ describe(':mksession', function()
-- window was not restored.
eq(1, funcs.winnr('$'))
-- The command-line height should remain the same as it was.
- eq(cmdheight, meths.get_option('cmdheight'))
+ eq(cmdheight, meths.get_option_value('cmdheight', {}))
os.remove(tmpfile)
end)
diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua
index fef8065b2e..f71b826210 100644
--- a/test/functional/ex_cmds/mkview_spec.lua
+++ b/test/functional/ex_cmds/mkview_spec.lua
@@ -1,4 +1,3 @@
-local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
@@ -7,6 +6,7 @@ local get_pathsep = helpers.get_pathsep
local eq = helpers.eq
local funcs = helpers.funcs
local rmdir = helpers.rmdir
+local mkdir = helpers.mkdir
local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
@@ -17,8 +17,8 @@ describe(':mkview', function()
before_each(function()
clear()
- lfs.mkdir(view_dir)
- lfs.mkdir(local_dir)
+ mkdir(view_dir)
+ mkdir(local_dir)
end)
after_each(function()
diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua
index 5f87c3cdd9..19611429e0 100644
--- a/test/functional/ex_cmds/oldfiles_spec.lua
+++ b/test/functional/ex_cmds/oldfiles_spec.lua
@@ -2,6 +2,8 @@ local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
+local command = helpers.command
+local expect_exit = helpers.expect_exit
local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command
local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop
local ok = helpers.ok
@@ -19,6 +21,7 @@ describe(':oldfiles', function()
before_each(_clear)
after_each(function()
+ expect_exit(command, 'qall!')
os.remove(shada_file)
end)
@@ -42,6 +45,7 @@ describe(':oldfiles', function()
|
Press ENTER or type command to continue^ |
]])
+ feed('<CR>')
end)
it('can be filtered with :filter', function()
@@ -107,6 +111,7 @@ describe(':browse oldfiles', function()
end)
after_each(function()
+ expect_exit(command, 'qall!')
os.remove(shada_file)
end)
diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua
index 2b92f8d0de..249373a9c4 100644
--- a/test/functional/ex_cmds/profile_spec.lua
+++ b/test/functional/ex_cmds/profile_spec.lua
@@ -1,5 +1,5 @@
require('os')
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local eval = helpers.eval
@@ -12,25 +12,24 @@ local read_file = helpers.read_file
-- tmpname() also creates the file on POSIX systems. Remove it again.
-- We just need the name, ignoring any race conditions.
-if lfs.attributes(tempfile, 'uid') then
+if luv.fs_stat(tempfile).uid then
os.remove(tempfile)
end
local function assert_file_exists(filepath)
- -- Use 2-argument lfs.attributes() so no extra table gets created.
- -- We don't really care for the uid.
- neq(nil, lfs.attributes(filepath, 'uid'))
+ neq(nil, luv.fs_stat(filepath).uid)
end
local function assert_file_exists_not(filepath)
- eq(nil, lfs.attributes(filepath, 'uid'))
+ eq(nil, luv.fs_stat(filepath))
end
describe(':profile', function()
before_each(helpers.clear)
after_each(function()
- if lfs.attributes(tempfile, 'uid') ~= nil then
+ helpers.expect_exit(command, 'qall!')
+ if luv.fs_stat(tempfile).uid ~= nil then
os.remove(tempfile)
end
end)
diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua
index bf69ada820..62249caa5e 100644
--- a/test/functional/ex_cmds/script_spec.lua
+++ b/test/functional/ex_cmds/script_spec.lua
@@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local neq = helpers.neq
local command = helpers.command
+local exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local meths = helpers.meths
local clear = helpers.clear
@@ -34,7 +35,7 @@ describe('script_get-based command', function()
%s %s
endif
]])):format(cmd, garbage)))
- eq('', meths.exec('messages', true))
+ eq('', exec_capture('messages'))
if check_neq then
neq(0, exc_exec(dedent([[
%s %s
@@ -49,7 +50,7 @@ describe('script_get-based command', function()
EOF
endif
]])):format(cmd, garbage)))
- eq('', meths.exec('messages', true))
+ eq('', exec_capture('messages'))
if check_neq then
eq(true, pcall(source, (dedent([[
let g:exc = 0
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua
index 64c3464be7..24987354a4 100644
--- a/test/functional/ex_cmds/source_spec.lua
+++ b/test/functional/ex_cmds/source_spec.lua
@@ -7,6 +7,7 @@ local meths = helpers.meths
local feed = helpers.feed
local feed_command = helpers.feed_command
local write_file = helpers.write_file
+local tmpname = helpers.tmpname
local exec = helpers.exec
local exc_exec = helpers.exc_exec
local exec_lua = helpers.exec_lua
@@ -48,7 +49,7 @@ describe(':source', function()
pending("'shellslash' only works on Windows")
return
end
- meths.set_option('shellslash', false)
+ meths.set_option_value('shellslash', false, {})
mkdir('Xshellslash')
write_file([[Xshellslash/Xstack.vim]], [[
@@ -96,12 +97,12 @@ describe(':source', function()
let d = s:s]])
command('source')
- eq('2', meths.exec('echo a', true))
- eq("{'k': 'v'}", meths.exec('echo b', true))
+ eq('2', exec_capture('echo a'))
+ eq("{'k': 'v'}", exec_capture('echo b'))
-- Script items are created only on script var access
- eq("1", meths.exec('echo c', true))
- eq("0zBEEFCAFE", meths.exec('echo d', true))
+ eq("1", exec_capture('echo c'))
+ eq("0zBEEFCAFE", exec_capture('echo d'))
exec('set cpoptions+=C')
eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source'))
@@ -124,14 +125,14 @@ describe(':source', function()
-- Source the 2nd line only
feed('ggjV')
feed_command(':source')
- eq('3', meths.exec('echo a', true))
+ eq('3', exec_capture('echo a'))
-- Source from 2nd line to end of file
feed('ggjVG')
feed_command(':source')
- eq('4', meths.exec('echo a', true))
- eq("{'K': 'V'}", meths.exec('echo b', true))
- eq("<SNR>1_C()", meths.exec('echo D()', true))
+ eq('4', exec_capture('echo a'))
+ eq("{'K': 'V'}", exec_capture('echo b'))
+ eq("<SNR>1_C()", exec_capture('echo D()'))
-- Source last line only
feed_command(':$source')
@@ -147,7 +148,7 @@ describe(':source', function()
let a = 123
]]
command('source')
- eq('123', meths.exec('echo a', true))
+ eq('123', exec_capture('echo a'))
end)
it('multiline heredoc command', function()
@@ -157,7 +158,7 @@ describe(':source', function()
EOF]])
command('source')
- eq('4', meths.exec('echo luaeval("y")', true))
+ eq('4', exec_capture('echo luaeval("y")'))
end)
it('can source lua files', function()
@@ -179,56 +180,65 @@ describe(':source', function()
os.remove(test_file)
end)
- it('can source selected region in lua file', function()
- local test_file = 'test.lua'
-
- write_file (test_file, [[
- vim.g.b = 5
- vim.g.b = 6
- vim.g.b = 7
- a = [=[
- "\ a
- \ b]=]
- ]])
-
- command('edit '..test_file)
-
- feed('ggjV')
- feed_command(':source')
- eq(6, eval('g:b'))
-
- feed('GVkk')
- feed_command(':source')
- eq(' "\\ a\n \\ b', exec_lua('return _G.a'))
-
- os.remove(test_file)
- end)
-
- it('can source current lua buffer without argument', function()
- local test_file = 'test.lua'
-
- write_file(test_file, [[
- vim.g.c = 10
- vim.g.c = 11
- vim.g.c = 12
- a = [=[
- \ 1
- "\ 2]=]
- vim.g.sfile_value = vim.fn.expand('<sfile>')
- vim.g.stack_value = vim.fn.expand('<stack>')
- vim.g.script_value = vim.fn.expand('<script>')
- ]])
-
- command('edit '..test_file)
- feed_command(':source')
-
- eq(12, eval('g:c'))
- eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
- eq(':source (no file)', meths.get_var('sfile_value'))
- eq(':source (no file)', meths.get_var('stack_value'))
- eq(':source (no file)', meths.get_var('script_value'))
+ describe('can source current buffer', function()
+ local function test_source_lua_curbuf()
+ it('selected region', function()
+ insert([[
+ vim.g.b = 5
+ vim.g.b = 6
+ vim.g.b = 7
+ a = [=[
+ "\ a
+ \ b]=]
+ ]])
+ feed('dd')
+
+ feed('ggjV')
+ feed_command(':source')
+ eq(6, eval('g:b'))
+
+ feed('GVkk')
+ feed_command(':source')
+ eq(' "\\ a\n \\ b', exec_lua('return _G.a'))
+ end)
+
+ it('whole buffer', function()
+ insert([[
+ vim.g.c = 10
+ vim.g.c = 11
+ vim.g.c = 12
+ a = [=[
+ \ 1
+ "\ 2]=]
+ vim.g.sfile_value = vim.fn.expand('<sfile>')
+ vim.g.stack_value = vim.fn.expand('<stack>')
+ vim.g.script_value = vim.fn.expand('<script>')
+ ]])
+ feed('dd')
+
+ feed_command(':source')
+
+ eq(12, eval('g:c'))
+ eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
+ eq(':source (no file)', meths.get_var('sfile_value'))
+ eq(':source (no file)', meths.get_var('stack_value'))
+ eq(':source (no file)', meths.get_var('script_value'))
+ end)
+ end
- os.remove(test_file)
+ describe('with ft=lua', function()
+ before_each(function()
+ command('setlocal ft=lua')
+ end)
+ test_source_lua_curbuf()
+ end)
+
+ describe('with .lua extension', function()
+ before_each(function()
+ command('edit ' .. tmpname() .. '.lua')
+ end)
+ test_source_lua_curbuf()
+ end)
end)
it("doesn't throw E484 for lua parsing/runtime errors", function()
diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
index 8eed00c973..436873b464 100644
--- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
+++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
@@ -1,6 +1,5 @@
local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
local luv = require('luv')
local eq, eval, expect, exec =
helpers.eq, helpers.eval, helpers.expect, helpers.exec
@@ -13,13 +12,19 @@ local nvim_prog = helpers.nvim_prog
local ok = helpers.ok
local rmdir = helpers.rmdir
local new_argv = helpers.new_argv
+local new_pipename = helpers.new_pipename
local pesc = helpers.pesc
local os_kill = helpers.os_kill
local set_session = helpers.set_session
local spawn = helpers.spawn
-local nvim_async = helpers.nvim_async
+local async_meths = helpers.async_meths
local expect_msg_seq = helpers.expect_msg_seq
local pcall_err = helpers.pcall_err
+local mkdir = helpers.mkdir
+local poke_eventloop = helpers.poke_eventloop
+local meths = helpers.meths
+local retry = helpers.retry
+local write_file = helpers.write_file
describe(':recover', function()
before_each(clear)
@@ -37,40 +42,40 @@ describe(':recover', function()
end)
-describe(':preserve', function()
- local swapdir = lfs.currentdir()..'/Xtest_recover_dir'
+describe("preserve and (R)ecover with custom 'directory'", function()
+ local swapdir = luv.cwd()..'/Xtest_recover_dir'
+ local testfile = 'Xtest_recover_file1'
+ -- Put swapdir at the start of the 'directory' list. #1836
+ -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
+ -- attempt to create a swapfile in different directory.
+ local init = [[
+ set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
+ set swapfile fileformat=unix undolevels=-1
+ ]]
+
+ local nvim0
before_each(function()
- clear()
+ nvim0 = spawn(new_argv())
+ set_session(nvim0)
rmdir(swapdir)
- lfs.mkdir(swapdir)
+ mkdir(swapdir)
end)
after_each(function()
command('%bwipeout!')
rmdir(swapdir)
end)
- it("saves to custom 'directory' and (R)ecovers #1836", function()
- local testfile = 'Xtest_recover_file1'
- -- Put swapdir at the start of the 'directory' list. #1836
- -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
- -- attempt to create a swapfile in different directory.
- local init = [[
- set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
- set swapfile fileformat=unix undolevels=-1
- ]]
-
+ local function setup_swapname()
exec(init)
command('edit! '..testfile)
feed('isometext<esc>')
- command('preserve')
exec('redir => g:swapname | silent swapname | redir END')
+ return eval('g:swapname')
+ end
- local swappath1 = eval('g:swapname')
-
- os_kill(eval('getpid()'))
+ local function test_recover(swappath1)
-- Start another Nvim instance.
- local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'},
- true)
+ local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true)
set_session(nvim2)
exec(init)
@@ -90,12 +95,41 @@ describe(':preserve', function()
-- Verify that :swapname was not truncated (:help 'shortmess').
ok(nil == string.find(swappath1, '%.%.%.'))
ok(nil == string.find(swappath2, '%.%.%.'))
+ end
+
+ it('with :preserve and SIGKILL', function()
+ local swappath1 = setup_swapname()
+ command('preserve')
+ os_kill(eval('getpid()'))
+ test_recover(swappath1)
+ end)
+
+ it('closing stdio channel without :preserve #22096', function()
+ local swappath1 = setup_swapname()
+ nvim0:close()
+ test_recover(swappath1)
+ end)
+
+ it('killing TUI process without :preserve #22096', function()
+ helpers.skip(helpers.is_os('win'))
+ local screen0 = Screen.new()
+ screen0:attach()
+ local child_server = new_pipename()
+ funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server})
+ screen0:expect({any = pesc('[No Name]')}) -- Wait for the child process to start.
+ local child_session = helpers.connect(child_server)
+ set_session(child_session)
+ local swappath1 = setup_swapname()
+ set_session(nvim0)
+ command('call chanclose(&channel)') -- Kill the child process.
+ screen0:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop.
+ test_recover(swappath1)
end)
end)
describe('swapfile detection', function()
- local swapdir = lfs.currentdir()..'/Xtest_swapdialog_dir'
+ local swapdir = luv.cwd()..'/Xtest_swapdialog_dir'
local nvim0
-- Put swapdir at the start of the 'directory' list. #1836
-- Note: `set swapfile` *must* go after `set directory`: otherwise it may
@@ -108,7 +142,7 @@ describe('swapfile detection', function()
nvim0 = spawn(new_argv())
set_session(nvim0)
rmdir(swapdir)
- lfs.mkdir(swapdir)
+ mkdir(swapdir)
end)
after_each(function()
set_session(nvim0)
@@ -137,6 +171,7 @@ describe('swapfile detection', function()
local screen2 = Screen.new(256, 40)
screen2:attach()
exec(init)
+ command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
-- With shortmess+=F
command('set shortmess+=F')
@@ -160,7 +195,7 @@ describe('swapfile detection', function()
feed('e') -- Chose "Edit" at the swap dialog.
screen2:expect(expected_no_dialog)
- -- With API (via eval/VimL) call and shortmess+=F
+ -- With API (via eval/Vimscript) call and shortmess+=F
feed(':call nvim_command("edit %")<CR>')
screen2:expect{any=[[Found a swap file by the name ".*]]
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
@@ -169,7 +204,7 @@ describe('swapfile detection', function()
screen2:expect(expected_no_dialog)
-- With API call and shortmess+=F
- nvim_async('command', 'edit %')
+ async_meths.command('edit %')
screen2:expect{any=[[Found a swap file by the name ".*]]
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
feed('e') -- Chose "Edit" at the swap dialog.
@@ -185,11 +220,29 @@ describe('swapfile detection', function()
nvim2:close()
end)
+ it('default SwapExists handler selects "(E)dit" and skips prompt', function()
+ exec(init)
+ command('edit Xfile1')
+ command("put ='some text...'")
+ command('preserve') -- Make sure the swap file exists.
+ local nvimpid = funcs.getpid()
+
+ local nvim1 = spawn(new_argv(), true, nil, true)
+ set_session(nvim1)
+ local screen = Screen.new(75, 18)
+ screen:attach()
+ exec(init)
+ feed(':edit Xfile1\n')
+
+ screen:expect({ any = ('W325: Ignoring swapfile from Nvim process %d'):format(nvimpid) })
+ nvim1:close()
+ end)
+
-- oldtest: Test_swap_prompt_splitwin()
it('selecting "q" in the attention prompt', function()
exec(init)
command('edit Xfile1')
- command('preserve') -- should help to make sure the swap file exists
+ command('preserve') -- Make sure the swap file exists.
local screen = Screen.new(75, 18)
screen:set_default_attr_ids({
@@ -201,7 +254,9 @@ describe('swapfile detection', function()
set_session(nvim1)
screen:attach()
exec(init)
+ command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
feed(':split Xfile1\n')
+ -- The default SwapExists handler does _not_ skip this prompt.
screen:expect({
any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^')
})
@@ -233,6 +288,7 @@ describe('swapfile detection', function()
set_session(nvim2)
screen:attach()
exec(init)
+ command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
command('set more')
command('au bufadd * let foo_w = wincol()')
feed(':e Xfile1<CR>')
@@ -266,8 +322,9 @@ describe('swapfile detection', function()
nvim2:close()
end)
- -- oldtest: Test_nocatch_process_still_running()
- it('allows deleting swapfile created before boot vim-patch:8.2.2586', function()
+ --- @param swapexists boolean Enable the default SwapExists handler.
+ --- @param on_swapfile_running fun(screen: any) Called after swapfile ("STILL RUNNING") prompt.
+ local function test_swapfile_after_reboot(swapexists, on_swapfile_running)
local screen = Screen.new(75, 30)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
@@ -277,6 +334,9 @@ describe('swapfile detection', function()
screen:attach()
exec(init)
+ if not swapexists then
+ command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog).
+ end
command('set nohidden')
exec([=[
@@ -313,12 +373,7 @@ describe('swapfile detection', function()
os.rename('Xswap', swname)
feed(':edit Xswaptest<CR>')
- screen:expect({any = table.concat({
- pesc('{2:E325: ATTENTION}'),
- 'file name: .*Xswaptest',
- 'process ID: %d* %(STILL RUNNING%)',
- pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'),
- }, '.*')})
+ on_swapfile_running(screen)
feed('e')
@@ -330,7 +385,8 @@ describe('swapfile detection', function()
]])
-- pretend that the swapfile was created before boot
- lfs.touch(swname, os.time() - luv.uptime() - 10)
+ local atime = os.time() - luv.uptime() - 10
+ luv.fs_utime(swname, atime, atime)
feed(':edit Xswaptest<CR>')
screen:expect({any = table.concat({
@@ -339,5 +395,112 @@ describe('swapfile detection', function()
}, '.*')})
feed('e')
+ end
+
+ -- oldtest: Test_nocatch_process_still_running()
+ it('swapfile created before boot vim-patch:8.2.2586', function()
+ test_swapfile_after_reboot(false, function(screen)
+ screen:expect({any = table.concat({
+ pesc('{2:E325: ATTENTION}'),
+ 'file name: .*Xswaptest',
+ 'process ID: %d* %(STILL RUNNING%)',
+ pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'),
+ }, '.*')})
+ end)
+ end)
+
+ it('swapfile created before boot + default SwapExists handler', function()
+ test_swapfile_after_reboot(true, function(screen)
+ screen:expect({ any = 'W325: Ignoring swapfile from Nvim process' })
+ end)
+ end)
+
+end)
+
+describe('quitting swapfile dialog on startup stops TUI properly', function()
+ local swapdir = luv.cwd()..'/Xtest_swapquit_dir'
+ local testfile = 'Xtest_swapquit_file1'
+ local otherfile = 'Xtest_swapquit_file2'
+ -- Put swapdir at the start of the 'directory' list. #1836
+ -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
+ -- attempt to create a swapfile in different directory.
+ local init_dir = [[set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//]]
+ local init_set = [[set swapfile fileformat=unix nomodified undolevels=-1 nohidden]]
+
+ before_each(function()
+ clear({args = {'--cmd', init_dir, '--cmd', init_set}})
+ rmdir(swapdir)
+ mkdir(swapdir)
+ write_file(testfile, [[
+ first
+ second
+ third
+
+ ]])
+ command('edit! '..testfile)
+ feed('Gisometext<esc>')
+ poke_eventloop()
+ clear() -- Leaves a swap file behind
+ meths.ui_attach(80, 30, {})
+ end)
+ after_each(function()
+ rmdir(swapdir)
+ os.remove(testfile)
+ os.remove(otherfile)
+ end)
+
+ it('(Q)uit at first file argument', function()
+ local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE',
+ '--cmd', init_dir, '--cmd', init_set,
+ testfile})
+ retry(nil, nil, function()
+ eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
+ eval("getline('$')->trim(' ', 2)"))
+ end)
+ meths.chan_send(chan, 'q')
+ retry(nil, nil, function()
+ eq({'', '[Process exited 1]', ''},
+ eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
+ end)
+ end)
+
+ it('(A)bort at second file argument with -p', function()
+ local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE',
+ '--cmd', init_dir, '--cmd', init_set,
+ '-p', otherfile, testfile})
+ retry(nil, nil, function()
+ eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
+ eval("getline('$')->trim(' ', 2)"))
+ end)
+ meths.chan_send(chan, 'a')
+ retry(nil, nil, function()
+ eq({'', '[Process exited 1]', ''},
+ eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
+ end)
+ end)
+
+ it('(Q)uit at file opened by -t', function()
+ write_file(otherfile, ([[
+ !_TAG_FILE_ENCODING utf-8 //
+ first %s /^ \zsfirst$/
+ second %s /^ \zssecond$/
+ third %s /^ \zsthird$/]]):format(testfile, testfile, testfile))
+ local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE',
+ '--cmd', init_dir, '--cmd', init_set,
+ '--cmd', 'set tags='..otherfile, '-tsecond'})
+ retry(nil, nil, function()
+ eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
+ eval("getline('$')->trim(' ', 2)"))
+ end)
+ meths.chan_send(chan, 'q')
+ retry(nil, nil, function()
+ eq('Press ENTER or type command to continue',
+ eval("getline('$')->trim(' ', 2)"))
+ end)
+ meths.chan_send(chan, '\r')
+ retry(nil, nil, function()
+ eq({'', '[Process exited 1]', ''},
+ eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
+ end)
end)
end)
diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua
index 10ee02a790..fe13bd7cd2 100644
--- a/test/functional/ex_cmds/trust_spec.lua
+++ b/test/functional/ex_cmds/trust_spec.lua
@@ -1,9 +1,10 @@
local helpers = require('test.functional.helpers')(after_each)
-local Screen = require('test.functional.ui.screen')
local eq = helpers.eq
local clear = helpers.clear
local command = helpers.command
+local exec_capture = helpers.exec_capture
+local matches = helpers.matches
local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os
local funcs = helpers.funcs
@@ -29,147 +30,49 @@ describe(':trust', function()
end)
it('trust then deny then remove a file using current buffer', function()
- local screen = Screen.new(80, 8)
- screen:attach()
- screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- })
-
local cwd = funcs.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file'))
command('edit test_file')
- command('trust')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}|
- ]])
+ matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
- command('trust ++deny')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
- ]])
+ matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
- command('trust ++remove')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
- ]])
+ matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust))
end)
it('deny then trust then remove a file using current buffer', function()
- local screen = Screen.new(80, 8)
- screen:attach()
- screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- })
-
local cwd = funcs.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file'))
command('edit test_file')
- command('trust ++deny')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
- ]])
+ matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
- command('trust')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}|
- ]])
+ matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
- command('trust ++remove')
- screen:expect([[
- ^test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
- ]])
+ matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust))
end)
it('deny then remove a file using file path', function()
- local screen = Screen.new(80, 8)
- screen:attach()
- screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- })
-
local cwd = funcs.getcwd()
- command('trust ++deny test_file')
- screen:expect([[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
- ]])
+ matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
- command('trust ++remove test_file')
- screen:expect([[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
- ]])
+ matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust))
end)
diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua
index 000e746f1c..50077e9e0c 100644
--- a/test/functional/ex_cmds/verbose_spec.lua
+++ b/test/functional/ex_cmds/verbose_spec.lua
@@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local call_viml_function = helpers.meths.call_function
-describe('lua :verbose', function()
+local function last_set_tests(cmd)
local script_location, script_file
-- All test cases below use the same nvim instance.
setup(function()
@@ -18,17 +18,17 @@ describe('lua :verbose', function()
script_location = table.concat{current_dir, helpers.get_pathsep(), script_file}
write_file(script_file, [[
-vim.api.nvim_set_option('hlsearch', false)
+vim.api.nvim_set_option_value('hlsearch', false, {})
vim.bo.expandtab = true
vim.opt.number = true
vim.api.nvim_set_keymap('n', '<leader>key1', ':echo "test"<cr>', {noremap = true})
vim.keymap.set('n', '<leader>key2', ':echo "test"<cr>')
-vim.api.nvim_exec("augroup test_group\
+vim.api.nvim_exec2("augroup test_group\
autocmd!\
autocmd FileType c setl cindent\
augroup END\
- ", false)
+ ", {})
vim.api.nvim_command("command Bdelete :bd")
vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {})
@@ -46,7 +46,7 @@ endfunction\
let &tw = s:return80()\
", true)
]])
- exec(':source '..script_file)
+ exec(cmd .. ' ' .. script_file)
end)
teardown(function()
@@ -106,6 +106,9 @@ test_group FileType
end)
it('"Last set" for command defined by nvim_command', function()
+ if cmd == 'luafile' then
+ pending('nvim_command does not set the script context')
+ end
local result = exec_capture(':verbose command Bdelete')
eq(string.format([[
Name Args Address Complete Definition
@@ -123,7 +126,7 @@ test_group FileType
script_location), result)
end)
- it('"Last set for function', function()
+ it('"Last set" for function', function()
local result = exec_capture(':verbose function Close_Window')
eq(string.format([[
function Close_Window() abort
@@ -140,6 +143,14 @@ test_group FileType
Last set from %s line 22]],
script_location), result)
end)
+end
+
+describe('lua :verbose when using :source', function()
+ last_set_tests('source')
+end)
+
+describe('lua :verbose when using :luafile', function()
+ last_set_tests('luafile')
end)
describe('lua verbose:', function()
@@ -149,7 +160,7 @@ describe('lua verbose:', function()
clear()
script_file = 'test_luafile.lua'
write_file(script_file, [[
- vim.api.nvim_set_option('hlsearch', false)
+ vim.api.nvim_set_option_value('hlsearch', false, {})
]])
exec(':source '..script_file)
end)
diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua
index 1ccd27875e..0b8ce93b09 100644
--- a/test/functional/ex_cmds/write_spec.lua
+++ b/test/functional/ex_cmds/write_spec.lua
@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local eq, eval, clear, write_file, source, insert =
helpers.eq, helpers.eval, helpers.clear, helpers.write_file,
helpers.source, helpers.insert
@@ -129,18 +129,18 @@ describe(':write', function()
eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
pcall_err(command, 'write .'))
end
- meths.set_option('writeany', true)
+ meths.set_option_value('writeany', true, {})
-- Message from buf_write
eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .'))
funcs.mkdir(fname_bak)
- meths.set_option('backupdir', '.')
- meths.set_option('backup', true)
+ meths.set_option_value('backupdir', '.', {})
+ meths.set_option_value('backup', true, {})
write_file(fname, 'content0')
command('edit ' .. fname)
funcs.setline(1, 'TTY')
eq('Vim(write):E510: Can\'t make backup file (add ! to override)',
pcall_err(command, 'write'))
- meths.set_option('backup', false)
+ meths.set_option_value('backup', false, {})
funcs.setfperm(fname, 'r--------')
eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)',
pcall_err(command, 'write'))
@@ -153,7 +153,7 @@ describe(':write', function()
end
write_file(fname_bak, 'TTYX')
skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]])
- lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true)
+ luv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname)
eq('Vim(write):E166: Can\'t open linked file for writing',
pcall_err(command, 'write!'))
end)
diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua
index 861a977ea6..7525343891 100644
--- a/test/functional/ex_cmds/wviminfo_spec.lua
+++ b/test/functional/ex_cmds/wviminfo_spec.lua
@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local clear = helpers.clear
local command, eq, neq, write_file =
helpers.command, helpers.eq, helpers.neq, helpers.write_file
@@ -21,10 +21,10 @@ describe(':wshada', function()
it('creates a shada file', function()
-- file should _not_ exist
- eq(nil, lfs.attributes(shada_file))
+ eq(nil, luv.fs_stat(shada_file))
command('wsh! '..shada_file)
-- file _should_ exist
- neq(nil, lfs.attributes(shada_file))
+ neq(nil, luv.fs_stat(shada_file))
end)
it('overwrites existing files', function()
@@ -35,7 +35,7 @@ describe(':wshada', function()
-- sanity check
eq(text, read_file(shada_file))
- neq(nil, lfs.attributes(shada_file))
+ neq(nil, luv.fs_stat(shada_file))
command('wsh! '..shada_file)
diff --git a/test/functional/fixtures/api_level_11.mpack b/test/functional/fixtures/api_level_11.mpack
new file mode 100644
index 0000000000..2399854c42
--- /dev/null
+++ b/test/functional/fixtures/api_level_11.mpack
Binary files differ
diff --git a/test/functional/fixtures/autoload/health/broken.vim b/test/functional/fixtures/autoload/health/broken.vim
deleted file mode 100644
index a2a595b96f..0000000000
--- a/test/functional/fixtures/autoload/health/broken.vim
+++ /dev/null
@@ -1,3 +0,0 @@
-function! health#broken#check()
- throw 'caused an error'
-endfunction
diff --git a/test/functional/fixtures/autoload/health/full_render.vim b/test/functional/fixtures/autoload/health/full_render.vim
deleted file mode 100644
index 2064b8606e..0000000000
--- a/test/functional/fixtures/autoload/health/full_render.vim
+++ /dev/null
@@ -1,8 +0,0 @@
-function! health#full_render#check()
- call health#report_start("report 1")
- call health#report_ok("life is fine")
- call health#report_warn("no what installed", ["pip what", "make what"])
- call health#report_start("report 2")
- call health#report_info("stuff is stable")
- call health#report_error("why no hardcopy", [":h :hardcopy", ":h :TOhtml"])
-endfunction
diff --git a/test/functional/fixtures/autoload/health/success1.vim b/test/functional/fixtures/autoload/health/success1.vim
deleted file mode 100644
index a360347455..0000000000
--- a/test/functional/fixtures/autoload/health/success1.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-function! health#success1#check()
- call health#report_start("report 1")
- call health#report_ok("everything is fine")
- call health#report_start("report 2")
- call health#report_ok("nothing to see here")
-endfunction
diff --git a/test/functional/fixtures/autoload/health/success2.vim b/test/functional/fixtures/autoload/health/success2.vim
deleted file mode 100644
index b742b4879d..0000000000
--- a/test/functional/fixtures/autoload/health/success2.vim
+++ /dev/null
@@ -1,4 +0,0 @@
-function! health#success2#check()
- call health#report_start("another 1")
- call health#report_ok("ok")
-endfunction
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index aa47198f7a..0db9265a29 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -272,6 +272,7 @@ function tests.text_document_save_did_open()
end;
body = function()
notify('start')
+ expect_notification('textDocument/didClose')
expect_notification('textDocument/didOpen')
expect_notification('textDocument/didSave')
notify('shutdown')
@@ -787,6 +788,9 @@ function tests.code_action_server_side_command()
codeActionProvider = {
resolveProvider = false,
},
+ executeCommandProvider = {
+ commands = {"dummy1"}
+ },
},
}
end,
@@ -830,21 +834,21 @@ function tests.code_action_filter()
isPreferred = true,
command = 'preferred_command',
}
- local quickfix_action = {
+ local type_annotate_action = {
title = 'Action 3',
- kind = 'quickfix',
- command = 'quickfix_command',
+ kind = 'type-annotate',
+ command = 'type_annotate_command',
}
- local quickfix_foo_action = {
+ local type_annotate_foo_action = {
title = 'Action 4',
- kind = 'quickfix.foo',
- command = 'quickfix_foo_command',
+ kind = 'type-annotate.foo',
+ command = 'type_annotate_foo_command',
}
expect_request('textDocument/codeAction', function()
- return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, }
+ return nil, { action, preferred_action, type_annotate_action, type_annotate_foo_action, }
end)
expect_request('textDocument/codeAction', function()
- return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, }
+ return nil, { action, preferred_action, type_annotate_action, type_annotate_foo_action, }
end)
notify('shutdown')
end;
@@ -927,10 +931,53 @@ function tests.basic_formatting()
}
end
--- Tests will be indexed by TEST_NAME
+function tests.set_defaults_all_capabilities()
+ skeleton {
+ on_init = function(_)
+ return {
+ capabilities = {
+ definitionProvider = true,
+ completionProvider = true,
+ documentRangeFormattingProvider = true,
+ hoverProvider = true,
+ }
+ }
+ end;
+ body = function()
+ notify('test')
+ end;
+ }
+end
+
+function tests.inlay_hint()
+ skeleton {
+ on_init = function(params)
+ local expected_capabilities = protocol.make_client_capabilities()
+ assert_eq(params.capabilities, expected_capabilities)
+ return {
+ capabilities = {
+ inlayHintProvider = true;
+ }
+ }
+ end;
+ body = function()
+ notify('start')
+ expect_request('textDocument/inlayHint', function()
+ return nil, {}
+ end)
+ expect_notification("finish")
+ notify('finish')
+ end;
+ }
+end
+
+-- Tests will be indexed by test_name
+local test_name = arg[1]
+local timeout = arg[2]
+assert(type(test_name) == 'string', 'test_name must be specified as first arg.')
-local kill_timer = vim.loop.new_timer()
-kill_timer:start(_G.TIMEOUT or 1e3, 0, function()
+local kill_timer = vim.uv.new_timer()
+kill_timer:start(timeout or 1e3, 0, function()
kill_timer:stop()
kill_timer:close()
log('ERROR', 'LSP', 'TIMEOUT')
@@ -938,14 +985,11 @@ kill_timer:start(_G.TIMEOUT or 1e3, 0, function()
os.exit(100)
end)
-local test_name = _G.TEST_NAME -- lualint workaround
-assert(type(test_name) == 'string', 'TEST_NAME must be specified.')
local status, err = pcall(assert(tests[test_name], "Test not found"))
kill_timer:stop()
kill_timer:close()
if not status then
log('ERROR', 'LSP', tostring(err))
io.stderr:write(err)
- os.exit(101)
+ vim.cmd [[101cquit]]
end
-os.exit(0)
diff --git a/test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim b/test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim
deleted file mode 100644
index de05f56e9e..0000000000
--- a/test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim
+++ /dev/null
@@ -1,3 +0,0 @@
-function! health#success1#check()
- call health#report_start("If you see this I'm broken")
-endfunction
diff --git a/test/functional/fixtures/lua/test_plug/full_render/health.lua b/test/functional/fixtures/lua/test_plug/full_render/health.lua
new file mode 100644
index 0000000000..10833f6239
--- /dev/null
+++ b/test/functional/fixtures/lua/test_plug/full_render/health.lua
@@ -0,0 +1,12 @@
+local M = {}
+
+M.check = function()
+ vim.health.start('report 1')
+ vim.health.ok('life is fine')
+ vim.health.warn('no what installed', { 'pip what', 'make what' })
+ vim.health.start('report 2')
+ vim.health.info('stuff is stable')
+ vim.health.error('why no hardcopy', { ':h :hardcopy', ':h :TOhtml' })
+end
+
+return M
diff --git a/test/functional/fixtures/lua/test_plug/health/init.lua b/test/functional/fixtures/lua/test_plug/health/init.lua
index 58162d4515..ef0c5ae3cd 100644
--- a/test/functional/fixtures/lua/test_plug/health/init.lua
+++ b/test/functional/fixtures/lua/test_plug/health/init.lua
@@ -1,10 +1,10 @@
local M = {}
M.check = function()
- vim.health.report_start("report 1")
- vim.health.report_ok("everything is fine")
- vim.health.report_start("report 2")
- vim.health.report_ok("nothing to see here")
+ vim.health.start('report 1')
+ vim.health.ok('everything is fine')
+ vim.health.start('report 2')
+ vim.health.ok('nothing to see here')
end
return M
diff --git a/test/functional/fixtures/lua/test_plug/submodule/health.lua b/test/functional/fixtures/lua/test_plug/submodule/health.lua
index 58162d4515..ef0c5ae3cd 100644
--- a/test/functional/fixtures/lua/test_plug/submodule/health.lua
+++ b/test/functional/fixtures/lua/test_plug/submodule/health.lua
@@ -1,10 +1,10 @@
local M = {}
M.check = function()
- vim.health.report_start("report 1")
- vim.health.report_ok("everything is fine")
- vim.health.report_start("report 2")
- vim.health.report_ok("nothing to see here")
+ vim.health.start('report 1')
+ vim.health.ok('everything is fine')
+ vim.health.start('report 2')
+ vim.health.ok('nothing to see here')
end
return M
diff --git a/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua b/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua
deleted file mode 100644
index ee5f4e404b..0000000000
--- a/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua
+++ /dev/null
@@ -1,11 +0,0 @@
-local M = {}
-
-M.check = function()
- vim.health.report_start("report 1")
- vim.health.report_ok("everything is fine")
- vim.health.report_warn("About to add a number to nil")
- local a = nil + 2
- return a
-end
-
-return M
diff --git a/test/functional/fixtures/lua/test_plug/success1/health.lua b/test/functional/fixtures/lua/test_plug/success1/health.lua
new file mode 100644
index 0000000000..ef0c5ae3cd
--- /dev/null
+++ b/test/functional/fixtures/lua/test_plug/success1/health.lua
@@ -0,0 +1,10 @@
+local M = {}
+
+M.check = function()
+ vim.health.start('report 1')
+ vim.health.ok('everything is fine')
+ vim.health.start('report 2')
+ vim.health.ok('nothing to see here')
+end
+
+return M
diff --git a/test/functional/fixtures/lua/test_plug/success2/health.lua b/test/functional/fixtures/lua/test_plug/success2/health.lua
new file mode 100644
index 0000000000..240a2d33de
--- /dev/null
+++ b/test/functional/fixtures/lua/test_plug/success2/health.lua
@@ -0,0 +1,8 @@
+local M = {}
+
+M.check = function()
+ vim.health.start('another 1')
+ vim.health.ok('ok')
+end
+
+return M
diff --git a/test/functional/fixtures/printargs-test.c b/test/functional/fixtures/printargs-test.c
index be54605817..2c25cf8447 100644
--- a/test/functional/fixtures/printargs-test.c
+++ b/test/functional/fixtures/printargs-test.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdio.h>
int main(int argc, char **argv)
diff --git a/test/functional/fixtures/printenv-test.c b/test/functional/fixtures/printenv-test.c
index 295b4f04c3..f826a28db4 100644
--- a/test/functional/fixtures/printenv-test.c
+++ b/test/functional/fixtures/printenv-test.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdio.h>
#ifdef MSWIN
diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c
index 4196716799..ef9f23e3f9 100644
--- a/test/functional/fixtures/shell-test.c
+++ b/test/functional/fixtures/shell-test.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdio.h>
#include <string.h>
#include <stdint.h>
diff --git a/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua b/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua
index 45226ce24b..ffbd8a4f83 100644
--- a/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua
+++ b/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua
@@ -1,5 +1,5 @@
return function (val, res)
local handle
- handle = vim.loop.new_async(function() _G[res] = require'leftpad'(val) handle:close() end)
+ handle = vim.uv.new_async(function() _G[res] = require'leftpad'(val) handle:close() end)
handle:send()
end
diff --git a/test/functional/fixtures/streams-test.c b/test/functional/fixtures/streams-test.c
index be40edfe7e..5a59abb33b 100644
--- a/test/functional/fixtures/streams-test.c
+++ b/test/functional/fixtures/streams-test.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
/// Helper program to exit and keep stdout open (like "xclip -i -loops 1").
#include <stdio.h>
diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c
index 6ee7715021..f94af2fd12 100644
--- a/test/functional/fixtures/tty-test.c
+++ b/test/functional/fixtures/tty-test.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -11,8 +8,6 @@
# include <unistd.h>
#endif
-// -V:STRUCT_CAST:641
-#define STRUCT_CAST(Type, obj) ((Type *)(obj))
#define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY)
#define BUF_SIZE 0xfff
#define CTRL_C 0x03
@@ -108,10 +103,10 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
.len = (size_t)cnt
#endif
};
- uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
+ uv_write(&req, (uv_stream_t *)&out, &b, 1, NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);
- uv_close(STRUCT_CAST(uv_handle_t, &out), NULL);
+ uv_close((uv_handle_t *)&out, NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);
if (uv_loop_close(&write_loop)) {
abort();
@@ -181,7 +176,7 @@ int main(int argc, char **argv)
#endif
uv_tty_set_mode(&tty, UV_TTY_MODE_RAW);
tty.data = &interrupted;
- uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb);
+ uv_read_start((uv_stream_t *)&tty, alloc_cb, read_cb);
#ifndef MSWIN
struct sigaction sa;
sigemptyset(&sa.sa_mask);
diff --git a/test/functional/fixtures/wildpum/Xdir/XdirA/XdirB/XfileC b/test/functional/fixtures/wildpum/Xnamedir/XdirA/XdirB/XfileC
index e69de29bb2..e69de29bb2 100644
--- a/test/functional/fixtures/wildpum/Xdir/XdirA/XdirB/XfileC
+++ b/test/functional/fixtures/wildpum/Xnamedir/XdirA/XdirB/XfileC
diff --git a/test/functional/fixtures/wildpum/Xdir/XdirA/XfileB b/test/functional/fixtures/wildpum/Xnamedir/XdirA/XfileB
index e69de29bb2..e69de29bb2 100644
--- a/test/functional/fixtures/wildpum/Xdir/XdirA/XfileB
+++ b/test/functional/fixtures/wildpum/Xnamedir/XdirA/XfileB
diff --git a/test/functional/fixtures/wildpum/Xdir/XfileA b/test/functional/fixtures/wildpum/Xnamedir/XfileA
index e69de29bb2..e69de29bb2 100644
--- a/test/functional/fixtures/wildpum/Xdir/XfileA
+++ b/test/functional/fixtures/wildpum/Xnamedir/XfileA
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 6400db9f87..dcaaa664b9 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,14 +1,10 @@
-require('coxpcall')
local luv = require('luv')
-local lfs = require('lfs')
-local mpack = require('mpack')
local global_helpers = require('test.helpers')
--- nvim client: Found in .deps/usr/share/lua/<version>/nvim/ if "bundled".
-local Session = require('nvim.session')
-local TcpStream = require('nvim.tcp_stream')
-local SocketStream = require('nvim.socket_stream')
-local ChildProcessStream = require('nvim.child_process_stream')
+local Session = require('test.client.session')
+local uv_stream = require('test.client.uv_stream')
+local SocketStream = uv_stream.SocketStream
+local ChildProcessStream = uv_stream.ChildProcessStream
local check_cores = global_helpers.check_cores
local check_logs = global_helpers.check_logs
@@ -22,12 +18,9 @@ local sleep = global_helpers.sleep
local tbl_contains = global_helpers.tbl_contains
local fail = global_helpers.fail
-local module = {
- NIL = mpack.NIL,
- mkdir = lfs.mkdir,
-}
+local module = {}
-local start_dir = lfs.currentdir()
+local start_dir = luv.cwd()
local runtime_set = 'set runtimepath^=./build/lib/nvim/'
module.nvim_prog = (
os.getenv('NVIM_PRG')
@@ -89,6 +82,13 @@ end
local session, loop_running, last_error, method_error
+if not is_os('win') then
+ local sigpipe_handler = luv.new_signal()
+ luv.signal_start(sigpipe_handler, "sigpipe", function()
+ print("warning: got SIGPIPE signal. Likely related to a crash in nvim")
+ end)
+end
+
function module.get_session()
return session
end
@@ -202,7 +202,7 @@ function module.expect_msg_seq(...)
end
local function call_and_stop_on_error(lsession, ...)
- local status, result = copcall(...) -- luacheck: ignore
+ local status, result = Session.safe_pcall(...) -- luacheck: ignore
if not status then
lsession:stop()
last_error = result
@@ -271,7 +271,7 @@ function module.nvim_prog_abs()
end
end
--- Executes an ex-command. VimL errors manifest as client (lua) errors, but
+-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but
-- v:errmsg will not be updated.
function module.command(cmd)
module.request('nvim_command', cmd)
@@ -295,26 +295,26 @@ function module.expect_exit(fn_or_timeout, ...)
end
end
--- Evaluates a VimL expression.
--- Fails on VimL error, but does not update v:errmsg.
+-- Evaluates a Vimscript expression.
+-- Fails on Vimscript error, but does not update v:errmsg.
function module.eval(expr)
return module.request('nvim_eval', expr)
end
--- Executes a VimL function via RPC.
--- Fails on VimL error, but does not update v:errmsg.
+-- Executes a Vimscript function via RPC.
+-- Fails on Vimscript error, but does not update v:errmsg.
function module.call(name, ...)
return module.request('nvim_call_function', name, {...})
end
--- Executes a VimL function via Lua.
--- Fails on VimL error, but does not update v:errmsg.
+-- Executes a Vimscript function via Lua.
+-- Fails on Vimscript error, but does not update v:errmsg.
function module.call_lua(name, ...)
return module.exec_lua([[return vim.call(...)]], name, ...)
end
-- Sends user input to Nvim.
--- Does not fail on VimL error, but v:errmsg will be updated.
+-- Does not fail on Vimscript error, but v:errmsg will be updated.
local function nvim_feed(input)
while #input > 0 do
local written = module.request('nvim_input', input)
@@ -428,7 +428,7 @@ end
-- Creates a new Session connected by domain socket (named pipe) or TCP.
function module.connect(file_or_address)
local addr, port = string.match(file_or_address, "(.*):(%d+)")
- local stream = (addr and port) and TcpStream.open(addr, port) or
+ local stream = (addr and port) and SocketStream.connect(addr, port) or
SocketStream.open(file_or_address)
return Session.new(stream)
end
@@ -524,7 +524,7 @@ function module.insert(...)
nvim_feed('<ESC>')
end
--- Executes an ex-command by user input. Because nvim_input() is used, VimL
+-- Executes an ex-command by user input. Because nvim_input() is used, Vimscript
-- errors will not manifest as client (lua) errors. Use command() for that.
function module.feed_command(...)
for _, v in ipairs({...}) do
@@ -537,7 +537,7 @@ function module.feed_command(...)
end
end
--- @deprecated use nvim_exec()
+-- @deprecated use nvim_exec2()
function module.source(code)
module.exec(dedent(code))
end
@@ -557,16 +557,18 @@ function module.set_shell_powershell(fake)
assert(found)
end
local shell = found and (is_os('win') and 'powershell' or 'pwsh') or module.testprg('pwsh-test')
- local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();'
- local cmd = set_encoding..'Remove-Item -Force '..table.concat(is_os('win')
- and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort'}
+ local cmd = 'Remove-Item -Force '..table.concat(is_os('win')
+ and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort', 'alias:tee'}
or {'alias:echo'}, ',')..';'
module.exec([[
let &shell = ']]..shell..[['
set shellquote= shellxquote=
- let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[['
- let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
- let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
+ let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command '
+ let &shellcmdflag .= '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();'
+ let &shellcmdflag .= '$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';'
+ let &shellcmdflag .= ']]..cmd..[['
+ let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode'
+ let &shellpipe = '2>&1 | %%{ "$_" } | tee %s; exit $LastExitCode'
]])
return found
end
@@ -732,21 +734,17 @@ function module.assert_visible(bufnr, visible)
end
local function do_rmdir(path)
- local mode, errmsg, errcode = lfs.attributes(path, 'mode')
- if mode == nil then
- if errcode == 2 then
- -- "No such file or directory", don't complain.
- return
- end
- error(string.format('rmdir: %s (%d)', errmsg, errcode))
+ local stat = luv.fs_stat(path)
+ if stat == nil then
+ return
end
- if mode ~= 'directory' then
+ if stat.type ~= 'directory' then
error(string.format('rmdir: not a directory: %s', path))
end
- for file in lfs.dir(path) do
+ for file in vim.fs.dir(path) do
if file ~= '.' and file ~= '..' then
local abspath = path..'/'..file
- if lfs.attributes(abspath, 'mode') == 'directory' then
+ if global_helpers.isdir(abspath) then
do_rmdir(abspath) -- recurse
else
local ret, err = os.remove(abspath)
@@ -766,9 +764,9 @@ local function do_rmdir(path)
end
end
end
- local ret, err = lfs.rmdir(path)
+ local ret, err = luv.fs_rmdir(path)
if not ret then
- error('lfs.rmdir('..path..'): '..err)
+ error('luv.fs_rmdir('..path..'): '..err)
end
end
@@ -828,13 +826,15 @@ function module.skip_fragile(pending_fn, cond)
end
function module.exec(code)
- return module.meths.exec(code, false)
+ module.meths.exec2(code, {})
end
function module.exec_capture(code)
- return module.meths.exec(code, true)
+ return module.meths.exec2(code, { output = true }).output
end
+--- @param code string
+--- @return any
function module.exec_lua(code, ...)
return module.meths.exec_lua(code, {...})
end
@@ -858,12 +858,20 @@ function module.testprg(name)
return ('%s/%s%s'):format(module.nvim_dir, name, ext)
end
+function module.is_asan()
+ local version = module.eval('execute("verbose version")')
+ return version:match('-fsanitize=[a-z,]*address')
+end
+
-- Returns a valid, platform-independent Nvim listen address.
-- Useful for communicating with child instances.
function module.new_pipename()
-- HACK: Start a server temporarily, get the name, then stop it.
local pipename = module.eval('serverstart()')
module.funcs.serverstop(pipename)
+ -- Remove the pipe so that trying to connect to it without a server listening
+ -- will be an error instead of a hang.
+ os.remove(pipename)
return pipename
end
@@ -902,7 +910,7 @@ local load_factor = 1
if global_helpers.is_ci() then
-- Compute load factor only once (but outside of any tests).
module.clear()
- module.request('nvim_command', 'source src/nvim/testdir/load.vim')
+ module.request('nvim_command', 'source test/old/testdir/load.vim')
load_factor = module.request('nvim_eval', 'g:test_load_factor')
end
function module.load_adjust(num)
@@ -944,8 +952,10 @@ function module.mkdir_p(path)
or 'mkdir -p '..path))
end
+--- @class test.functional.helpers: test.helpers
module = global_helpers.tbl_extend('error', module, global_helpers)
+--- @return test.functional.helpers
return function(after_each)
if after_each then
after_each(function()
diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua
index 7ae851467f..5b6d030567 100644
--- a/test/functional/legacy/011_autocommands_spec.lua
+++ b/test/functional/legacy/011_autocommands_spec.lua
@@ -13,7 +13,7 @@
-- being modified outside of Vim (noticed on Solaris).
local helpers= require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local clear, feed_command, expect, eq, neq, dedent, write_file, feed =
helpers.clear, helpers.feed_command, helpers.expect, helpers.eq, helpers.neq,
helpers.dedent, helpers.write_file, helpers.feed
@@ -31,8 +31,8 @@ local function prepare_gz_file(name, text)
-- Compress the file with gzip.
command([[call system(['gzip', '--force', ']]..name..[['])]])
-- This should create the .gz file and delete the original.
- neq(nil, lfs.attributes(name..'.gz'))
- eq(nil, lfs.attributes(name))
+ neq(nil, luv.fs_stat(name..'.gz'))
+ eq(nil, luv.fs_stat(name))
end
describe('file reading, writing and bufnew and filter autocommands', function()
diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua
index dd207ca0b4..25d0dcb81e 100644
--- a/test/functional/legacy/012_directory_spec.lua
+++ b/test/functional/legacy/012_directory_spec.lua
@@ -4,7 +4,7 @@
-- - "dir", in directory relative to current dir
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local eq = helpers.eq
local neq = helpers.neq
@@ -15,12 +15,12 @@ local clear = helpers.clear
local insert = helpers.insert
local command = helpers.command
local write_file = helpers.write_file
-local curbufmeths = helpers.curbufmeths
local expect_exit = helpers.expect_exit
+local mkdir = helpers.mkdir
local function ls_dir_sorted(dirname)
local files = {}
- for f in lfs.dir(dirname) do
+ for f in vim.fs.dir(dirname) do
if f ~= "." and f~= ".." then
table.insert(files, f)
end
@@ -38,8 +38,8 @@ describe("'directory' option", function()
end of testfile
]]
write_file('Xtest1', text)
- lfs.mkdir('Xtest.je')
- lfs.mkdir('Xtest2')
+ mkdir('Xtest.je')
+ mkdir('Xtest2')
write_file('Xtest2/Xtest3', text)
clear()
end)
@@ -57,33 +57,33 @@ describe("'directory' option", function()
line 3 Abcdefghij
end of testfile]])
- meths.set_option('swapfile', true)
- curbufmeths.set_option('swapfile', true)
- meths.set_option('directory', '.')
+ meths.set_option_value('swapfile', true, {})
+ meths.set_option_value('swapfile', true, {})
+ meths.set_option_value('directory', '.', {})
-- sanity check: files should not exist yet.
- eq(nil, lfs.attributes('.Xtest1.swp'))
+ eq(nil, luv.fs_stat('.Xtest1.swp'))
command('edit! Xtest1')
poke_eventloop()
eq('Xtest1', funcs.buffer_name('%'))
-- Verify that the swapfile exists. In the legacy test this was done by
-- reading the output from :!ls.
- neq(nil, lfs.attributes('.Xtest1.swp'))
+ neq(nil, luv.fs_stat('.Xtest1.swp'))
- meths.set_option('directory', './Xtest2,.')
+ meths.set_option_value('directory', './Xtest2,.', {})
command('edit Xtest1')
poke_eventloop()
-- swapfile should no longer exist in CWD.
- eq(nil, lfs.attributes('.Xtest1.swp'))
+ eq(nil, luv.fs_stat('.Xtest1.swp'))
eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))
- meths.set_option('directory', 'Xtest.je')
+ meths.set_option_value('directory', 'Xtest.je', {})
command('bdelete')
command('edit Xtest2/Xtest3')
- eq(true, curbufmeths.get_option('swapfile'))
+ eq(true, meths.get_option_value('swapfile', {}))
poke_eventloop()
eq({ "Xtest3" }, ls_dir_sorted("Xtest2"))
diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua
index 1a8ef067d0..b5af8f7d52 100644
--- a/test/functional/legacy/061_undo_tree_spec.lua
+++ b/test/functional/legacy/061_undo_tree_spec.lua
@@ -22,29 +22,30 @@ end
describe('undo tree:', function()
before_each(clear)
+ local fname = 'Xtest_functional_legacy_undotree'
teardown(function()
- os.remove('Xtest.source')
+ os.remove(fname .. '.source')
end)
describe(':earlier and :later', function()
before_each(function()
- os.remove('Xtest')
+ os.remove(fname)
end)
teardown(function()
- os.remove('Xtest')
+ os.remove(fname)
end)
it('time specifications, g- g+', function()
-- We write the test text to a file in order to prevent nvim to record
-- the inserting of the text into the undo history.
- write_file('Xtest', '\n123456789\n')
+ write_file(fname, '\n123456789\n')
-- `:earlier` and `:later` are (obviously) time-sensitive, so this test
-- sometimes fails if the system is under load. It is wrapped in a local
-- function to allow multiple attempts.
local function test_earlier_later()
clear()
- feed_command('e Xtest')
+ feed_command('e ' .. fname)
-- Assert that no undo history is present.
eq({}, eval('undotree().entries'))
-- Delete three characters and undo.
@@ -103,7 +104,7 @@ describe('undo tree:', function()
it('file-write specifications', function()
feed('ione one one<esc>')
- feed_command('w Xtest')
+ feed_command('w ' .. fname)
feed('otwo<esc>')
feed('otwo<esc>')
feed_command('w')
@@ -187,7 +188,7 @@ describe('undo tree:', function()
it('undo an expression-register', function()
local normal_commands = 'o1\027a2\018=string(123)\n\027'
- write_file('Xtest.source', normal_commands)
+ write_file(fname .. '.source', normal_commands)
feed('oa<esc>')
feed('ob<esc>')
@@ -221,7 +222,7 @@ describe('undo tree:', function()
c
12]])
feed('od<esc>')
- feed_command('so! Xtest.source')
+ feed_command('so! ' .. fname .. '.source')
expect([[
a
diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua
index 445d742c1f..06d8b276d7 100644
--- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua
+++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua
@@ -1,7 +1,7 @@
-- Tests for storing global variables in the .shada file
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local clear, command, eq, neq, eval, poke_eventloop =
helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval,
helpers.poke_eventloop
@@ -39,7 +39,7 @@ describe('storing global variables in ShaDa files', function()
poke_eventloop()
-- Assert that the shada file exists.
- neq(nil, lfs.attributes(tempname))
+ neq(nil, luv.fs_stat(tempname))
command('unlet MY_GLOBAL_DICT')
command('unlet MY_GLOBAL_LIST')
-- Assert that the variables where deleted.
diff --git a/test/functional/legacy/088_conceal_tabs_spec.lua b/test/functional/legacy/088_conceal_tabs_spec.lua
deleted file mode 100644
index a4c7e26583..0000000000
--- a/test/functional/legacy/088_conceal_tabs_spec.lua
+++ /dev/null
@@ -1,97 +0,0 @@
--- Tests for correct display (cursor column position) with +conceal and
--- tabulators.
-
-local helpers = require('test.functional.helpers')(after_each)
-local feed, insert, clear, feed_command =
- helpers.feed, helpers.insert, helpers.clear, helpers.feed_command
-
-local expect_pos = function(row, col)
- return helpers.eq({row, col}, helpers.eval('[screenrow(), screencol()]'))
-end
-
-describe('cursor and column position with conceal and tabulators', function()
- setup(clear)
-
- -- luacheck: ignore 621 (Indentation)
- it('are working', function()
- insert([[
- start:
- .concealed. text
- |concealed| text
-
- .concealed. text
- |concealed| text
-
- .a. .b. .c. .d.
- |a| |b| |c| |d|]])
-
- -- Conceal settings.
- feed_command('set conceallevel=2')
- feed_command('set concealcursor=nc')
- feed_command('syntax match test /|/ conceal')
- -- Start test.
- feed_command('/^start:')
- feed('ztj')
- expect_pos(2, 1)
- -- We should end up in the same column when running these commands on the
- -- two lines.
- feed('ft')
- expect_pos(2, 17)
- feed('$')
- expect_pos(2, 20)
- feed('0j')
- expect_pos(3, 1)
- feed('ft')
- expect_pos(3, 17)
- feed('$')
- expect_pos(3, 20)
- feed('j0j')
- expect_pos(5, 8)
- -- Same for next test block.
- feed('ft')
- expect_pos(5, 25)
- feed('$')
- expect_pos(5, 28)
- feed('0j')
- expect_pos(6, 8)
- feed('ft')
- expect_pos(6, 25)
- feed('$')
- expect_pos(6, 28)
- feed('0j0j')
- expect_pos(8, 1)
- -- And check W with multiple tabs and conceals in a line.
- feed('W')
- expect_pos(8, 9)
- feed('W')
- expect_pos(8, 17)
- feed('W')
- expect_pos(8, 25)
- feed('$')
- expect_pos(8, 27)
- feed('0j')
- expect_pos(9, 1)
- feed('W')
- expect_pos(9, 9)
- feed('W')
- expect_pos(9, 17)
- feed('W')
- expect_pos(9, 25)
- feed('$')
- expect_pos(9, 26)
- feed_command('set lbr')
- feed('$')
- expect_pos(9, 26)
- feed_command('set list listchars=tab:>-')
- feed('0')
- expect_pos(9, 1)
- feed('W')
- expect_pos(9, 9)
- feed('W')
- expect_pos(9, 17)
- feed('W')
- expect_pos(9, 25)
- feed('$')
- expect_pos(9, 26)
- end)
-end)
diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua
index 4829a0bbe1..d49d7d665a 100644
--- a/test/functional/legacy/assert_spec.lua
+++ b/test/functional/legacy/assert_spec.lua
@@ -145,10 +145,10 @@ describe('assert function:', function()
call assert_true('', 'file two')
]])
expected_errors({
- "nvim_exec(): equal assertion failed: Expected 1 but got 100",
- "nvim_exec(): true assertion failed: Expected False but got 'true'",
- "nvim_exec(): false assertion failed: Expected True but got 'false'",
- "nvim_exec(): file two: Expected True but got ''",
+ "nvim_exec2(): equal assertion failed: Expected 1 but got 100",
+ "nvim_exec2(): true assertion failed: Expected False but got 'true'",
+ "nvim_exec2(): false assertion failed: Expected True but got 'false'",
+ "nvim_exec2(): file two: Expected True but got ''",
})
end)
end)
diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua
index 13cb6cd287..5da54b4850 100644
--- a/test/functional/legacy/autochdir_spec.lua
+++ b/test/functional/legacy/autochdir_spec.lua
@@ -1,8 +1,8 @@
-local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each)
local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches
local eval, command, call, meths = helpers.eval, helpers.command, helpers.call, helpers.meths
local source, exec_capture = helpers.source, helpers.exec_capture
+local mkdir = helpers.mkdir
local function expected_empty()
eq({}, meths.get_vvar('errors'))
@@ -12,7 +12,7 @@ describe('autochdir behavior', function()
local dir = 'Xtest_functional_legacy_autochdir'
before_each(function()
- lfs.mkdir(dir)
+ mkdir(dir)
clear()
command('set shellslash')
end)
diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua
index e00b468c16..6034d13e2a 100644
--- a/test/functional/legacy/autocmd_option_spec.lua
+++ b/test/functional/legacy/autocmd_option_spec.lua
@@ -48,10 +48,10 @@ end
local function expected_table(option, oldval, oldval_l, oldval_g, newval, scope, cmd, attr)
return {
option = option,
- oldval = tostring(oldval),
- oldval_l = tostring(oldval_l),
- oldval_g = tostring(oldval_g),
- newval = tostring(newval),
+ oldval = oldval,
+ oldval_l = oldval_l,
+ oldval_g = oldval_g,
+ newval = newval,
scope = scope,
cmd = cmd,
attr = attr,
@@ -129,44 +129,44 @@ describe('au OptionSet', function()
it('should be called in setting number option', function()
command('set nu')
- expected_combination({'number', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'number', false, false, false, true, 'global', 'set'})
command('setlocal nonu')
- expected_combination({'number', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'number', true, true, '', false, 'local', 'setlocal'})
command('setglobal nonu')
- expected_combination({'number', 1, '', 1, 0, 'global', 'setglobal'})
+ expected_combination({'number', true, '', true, false, 'global', 'setglobal'})
end)
it('should be called in setting autoindent option',function()
command('setlocal ai')
- expected_combination({'autoindent', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'autoindent', false, false, '', true, 'local', 'setlocal'})
command('setglobal ai')
- expected_combination({'autoindent', 0, '', 0, 1, 'global', 'setglobal'})
+ expected_combination({'autoindent', false, '', false, true, 'global', 'setglobal'})
command('set noai')
- expected_combination({'autoindent', 1, 1, 1, 0, 'global', 'set'})
+ expected_combination({'autoindent', true, true, true, false, 'global', 'set'})
end)
it('should be called in inverting global autoindent option',function()
command('set ai!')
- expected_combination({'autoindent', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'autoindent', false, false, false, true, 'global', 'set'})
end)
it('should be called in being unset local autoindent option',function()
command('setlocal ai')
- expected_combination({'autoindent', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'autoindent', false, false, '', true, 'local', 'setlocal'})
command('setlocal ai<')
- expected_combination({'autoindent', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'autoindent', true, true, '', false, 'local', 'setlocal'})
end)
it('should be called in setting global list and number option at the same time',function()
command('set list nu')
expected_combination(
- {'list', 0, 0, 0, 1, 'global', 'set'},
- {'number', 0, 0, 0, 1, 'global', 'set'}
+ {'list', false, false, false, true, 'global', 'set'},
+ {'number', false, false, false, true, 'global', 'set'}
)
end)
@@ -177,20 +177,20 @@ describe('au OptionSet', function()
it('should be called in setting local acd', function()
command('setlocal acd')
- expected_combination({'autochdir', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'autochdir', false, false, '', true, 'local', 'setlocal'})
end)
it('should be called in setting autoread', function()
command('set noar')
- expected_combination({'autoread', 1, 1, 1, 0, 'global', 'set'})
+ expected_combination({'autoread', true, true, true, false, 'global', 'set'})
command('setlocal ar')
- expected_combination({'autoread', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'autoread', false, false, '', true, 'local', 'setlocal'})
end)
it('should be called in inverting global autoread', function()
command('setglobal invar')
- expected_combination({'autoread', 1, '', 1, 0, 'global', 'setglobal'})
+ expected_combination({'autoread', true, '', true, false, 'global', 'setglobal'})
end)
it('should be called in setting backspace option through :let', function()
@@ -208,7 +208,7 @@ describe('au OptionSet', function()
it('should trigger using correct option name', function()
command('call setbufvar(1, "&backup", 1)')
- expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'backup', false, false, '', true, 'local', 'setlocal'})
end)
it('should trigger if the current buffer is different from the targeted buffer', function()
@@ -260,7 +260,7 @@ describe('au OptionSet', function()
command('setlocal tags=tagpath2')
expected_combination({'tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal'})
- -- Note: v:option_old is the old global value for global-local string options
+ -- Note: v:option_old is the old global value for global-local options.
-- but the old local value for all other kinds of options.
command('noa setglobal tags=tag_global')
command('noa setlocal tags=tag_local')
@@ -269,12 +269,12 @@ describe('au OptionSet', function()
'tags', 'tag_global', 'tag_local', 'tag_global', 'tagpath', 'global', 'set'
})
- -- Note: v:option_old is the old global value for global-local string options
+ -- Note: v:option_old is the old global value for global-local options.
-- but the old local value for all other kinds of options.
command('noa set tags=tag_global')
command('noa setlocal tags=')
command('set tags=tagpath')
- expected_combination({'tags', 'tag_global', '', 'tag_global', 'tagpath', 'global', 'set'})
+ expected_combination({'tags', 'tag_global', 'tag_global', 'tag_global', 'tagpath', 'global', 'set'})
end)
it('with string local (to buffer) option', function()
@@ -295,7 +295,7 @@ describe('au OptionSet', function()
command('setlocal spelllang=klingon')
expected_combination({'spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal'})
- -- Note: v:option_old is the old global value for global-local string options
+ -- Note: v:option_old is the old global value for global-local options.
-- but the old local value for all other kinds of options.
command('noa setglobal spelllang=spellglobal')
command('noa setlocal spelllang=spelllocal')
@@ -311,7 +311,7 @@ describe('au OptionSet', function()
command('set statusline=foo')
expected_combination({'statusline', oldval, oldval, '', 'foo', 'global', 'set'})
- -- Note: v:option_old is the old global value for global-local string options
+ -- Note: v:option_old is the old global value for global-local options.
-- but the old local value for all other kinds of options.
command('set statusline&')
expected_combination({'statusline', 'foo', 'foo', 'foo', oldval, 'global', 'set'})
@@ -323,7 +323,7 @@ describe('au OptionSet', function()
command('setlocal statusline=baz')
expected_combination({'statusline', oldval, oldval, '', 'baz', 'local', 'setlocal'})
- -- Note: v:option_old is the old global value for global-local string options
+ -- Note: v:option_old is the old global value for global-local options.
-- but the old local value for all other kinds of options.
command('noa setglobal statusline=bar')
command('noa setlocal statusline=baz')
@@ -364,11 +364,15 @@ describe('au OptionSet', function()
command('setlocal cmdheight=2')
expected_combination({'cmdheight', 1, 1, '', 2, 'local', 'setlocal'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa setglobal cmdheight=8')
command('noa setlocal cmdheight=1') -- Sets the global(!) value
command('set cmdheight=2')
expected_combination({'cmdheight', 1, 1, 1, 2, 'global', 'set'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa set cmdheight=8')
command('set cmdheight=2')
expected_combination({'cmdheight', 8, 8, 8, 2, 'global', 'set'})
@@ -385,11 +389,15 @@ describe('au OptionSet', function()
command('setlocal undolevels=2')
expected_combination({'undolevels', 1, 1, '', 2, 'local', 'setlocal'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa setglobal undolevels=8')
command('noa setlocal undolevels=1')
command('set undolevels=2')
- expected_combination({'undolevels', 1, 1, 8, 2, 'global', 'set'})
+ expected_combination({'undolevels', 8, 1, 8, 2, 'global', 'set'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa set undolevels=8')
command('set undolevels=2')
expected_combination({'undolevels', 8, 8, 8, 2, 'global', 'set'})
@@ -427,11 +435,15 @@ describe('au OptionSet', function()
command('setlocal scrolloff=2')
expected_combination({'scrolloff', 1, 1, '', 2, 'local', 'setlocal'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa setglobal scrolloff=8')
command('noa setlocal scrolloff=1')
command('set scrolloff=2')
- expected_combination({'scrolloff', 1, 1, 8, 2, 'global', 'set'})
+ expected_combination({'scrolloff', 8, 1, 8, 2, 'global', 'set'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa set scrolloff=8')
command('set scrolloff=2')
expected_combination({'scrolloff', 8, 8, 8, 2, 'global', 'set'})
@@ -441,114 +453,111 @@ describe('au OptionSet', function()
command('noa setglobal foldcolumn=8')
command('noa setlocal foldcolumn=1')
command('setglobal foldcolumn=2')
- expected_combination({'foldcolumn', 8, '', 8, 2, 'global', 'setglobal'})
+ expected_combination({'foldcolumn', '8', '', '8', '2', 'global', 'setglobal'})
command('noa setglobal foldcolumn=8')
command('noa setlocal foldcolumn=1')
command('setlocal foldcolumn=2')
- expected_combination({'foldcolumn', 1, 1, '', 2, 'local', 'setlocal'})
+ expected_combination({'foldcolumn', '1', '1', '', '2', 'local', 'setlocal'})
command('noa setglobal foldcolumn=8')
command('noa setlocal foldcolumn=1')
command('set foldcolumn=2')
- expected_combination({'foldcolumn', 1, 1, 8, 2, 'global', 'set'})
+ expected_combination({'foldcolumn', '1', '1', '8', '2', 'global', 'set'})
command('noa set foldcolumn=8')
command('set foldcolumn=2')
- expected_combination({'foldcolumn', 8, 8, 8, 2, 'global', 'set'})
+ expected_combination({'foldcolumn', '8', '8', '8', '2', 'global', 'set'})
end)
it('with boolean global option', function()
command('noa setglobal nowrapscan')
command('noa setlocal wrapscan') -- Sets the global(!) value
command('setglobal nowrapscan')
- expected_combination({'wrapscan', 1, '', 1, 0, 'global', 'setglobal'})
+ expected_combination({'wrapscan', true, '', true, false, 'global', 'setglobal'})
command('noa setglobal nowrapscan')
command('noa setlocal wrapscan') -- Sets the global(!) value
command('setlocal nowrapscan')
- expected_combination({'wrapscan', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'wrapscan', true, true, '', false, 'local', 'setlocal'})
command('noa setglobal nowrapscan')
command('noa setlocal wrapscan') -- Sets the global(!) value
command('set nowrapscan')
- expected_combination({'wrapscan', 1, 1, 1, 0, 'global', 'set'})
+ expected_combination({'wrapscan', true, true, true, false, 'global', 'set'})
command('noa set nowrapscan')
command('set wrapscan')
- expected_combination({'wrapscan', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'wrapscan', false, false, false, true, 'global', 'set'})
end)
it('with boolean global-local (to buffer) option', function()
command('noa setglobal noautoread')
command('noa setlocal autoread')
command('setglobal autoread')
- expected_combination({'autoread', 0, '', 0, 1, 'global', 'setglobal'})
+ expected_combination({'autoread', false, '', false, true, 'global', 'setglobal'})
command('noa setglobal noautoread')
command('noa setlocal autoread')
command('setlocal noautoread')
- expected_combination({'autoread', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'autoread', true, true, '', false, 'local', 'setlocal'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa setglobal noautoread')
command('noa setlocal autoread')
command('set autoread')
- expected_combination({'autoread', 1, 1, 0, 1, 'global', 'set'})
+ expected_combination({'autoread', false, true, false, true, 'global', 'set'})
+ -- Note: v:option_old is the old global value for global-local options.
+ -- but the old local value for all other kinds of options.
command('noa set noautoread')
command('set autoread')
- expected_combination({'autoread', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'autoread', false, false, false, true, 'global', 'set'})
end)
it('with boolean local (to buffer) option', function()
command('noa setglobal nocindent')
command('noa setlocal cindent')
command('setglobal cindent')
- expected_combination({'cindent', 0, '', 0, 1, 'global', 'setglobal'})
+ expected_combination({'cindent', false, '', false, true, 'global', 'setglobal'})
command('noa setglobal nocindent')
command('noa setlocal cindent')
command('setlocal nocindent')
- expected_combination({'cindent', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'cindent', true, true, '', false, 'local', 'setlocal'})
command('noa setglobal nocindent')
command('noa setlocal cindent')
command('set cindent')
- expected_combination({'cindent', 1, 1, 0, 1, 'global', 'set'})
+ expected_combination({'cindent', true, true, false, true, 'global', 'set'})
command('noa set nocindent')
command('set cindent')
- expected_combination({'cindent', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'cindent', false, false, false, true, 'global', 'set'})
end)
it('with boolean local (to window) option', function()
command('noa setglobal nocursorcolumn')
command('noa setlocal cursorcolumn')
command('setglobal cursorcolumn')
- expected_combination({'cursorcolumn', 0, '', 0, 1, 'global', 'setglobal'})
+ expected_combination({'cursorcolumn', false, '', false, true, 'global', 'setglobal'})
command('noa setglobal nocursorcolumn')
command('noa setlocal cursorcolumn')
command('setlocal nocursorcolumn')
- expected_combination({'cursorcolumn', 1, 1, '', 0, 'local', 'setlocal'})
+ expected_combination({'cursorcolumn', true, true, '', false, 'local', 'setlocal'})
command('noa setglobal nocursorcolumn')
command('noa setlocal cursorcolumn')
command('set cursorcolumn')
- expected_combination({'cursorcolumn', 1, 1, 0, 1, 'global', 'set'})
+ expected_combination({'cursorcolumn', true, true, false, true, 'global', 'set'})
command('noa set nocursorcolumn')
command('set cursorcolumn')
- expected_combination({'cursorcolumn', 0, 0, 0, 1, 'global', 'set'})
+ expected_combination({'cursorcolumn', false, false, false, true, 'global', 'set'})
end)
- it('with option value converted internally', function()
- command('noa set backspace=1')
- command('set backspace=2')
- expected_combination(({
- 'backspace', 'indent,eol', 'indent,eol', 'indent,eol', '2', 'global', 'set'
- }))
- end)
end)
describe('with specific option', function()
@@ -566,13 +575,13 @@ describe('au OptionSet', function()
expected_empty()
command('setlocal ro')
- expected_combination({'readonly', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'readonly', false, false, '', true, 'local', 'setlocal'})
command('setglobal ro')
- expected_combination({'readonly', 0, '', 0, 1, 'global', 'setglobal'})
+ expected_combination({'readonly', false, '', false, true, 'global', 'setglobal'})
command('set noro')
- expected_combination({'readonly', 1, 1, 1, 0, 'global', 'set'})
+ expected_combination({'readonly', true, true, true, false, 'global', 'set'})
end)
describe('being set by setbufvar()', function()
@@ -587,7 +596,7 @@ describe('au OptionSet', function()
set_hook('backup')
command('call setbufvar(1, "&backup", 1)')
- expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'backup', false, false, '', true, 'local', 'setlocal'})
end)
it('should trigger if the current buffer is different from the targeted buffer', function()
@@ -597,7 +606,8 @@ describe('au OptionSet', function()
local new_bufnr = buf.get_number(new_buffer)
command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
- expected_combination({'buftype', '', '', '', 'nofile', 'local', 'setlocal', {bufnr = new_bufnr}})
+ expected_combination({ 'buftype', '', '', '', 'nofile', 'local', 'setlocal',
+ { bufnr = new_bufnr } })
end)
end)
@@ -613,7 +623,7 @@ describe('au OptionSet', function()
set_hook('backup')
command('call setwinvar(1, "&backup", 1)')
- expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'})
+ expected_combination({'backup', false, false, '', true, 'local', 'setlocal'})
end)
it('should not trigger if the current window is different from the targeted window', function()
@@ -622,7 +632,7 @@ describe('au OptionSet', function()
local new_winnr = get_new_window_number()
command('call setwinvar(' .. new_winnr .. ', "&cursorcolumn", 1)')
- -- expected_combination({'cursorcolumn', 0, 1, 'local', {winnr = new_winnr}})
+ -- expected_combination({'cursorcolumn', false, true, 'local', {winnr = new_winnr}})
expected_empty()
end)
end)
@@ -631,24 +641,24 @@ describe('au OptionSet', function()
it('should trigger if a boolean option be set globally', function()
set_hook('autochdir')
- nvim.set_option('autochdir', true)
- eq(true, nvim.get_option('autochdir'))
- expected_combination({'autochdir', 0, '', 0, 1, 'global', 'setglobal'})
+ nvim.set_option_value('autochdir', true, {scope='global'})
+ eq(true, nvim.get_option_value('autochdir', {scope='global'}))
+ expected_combination({'autochdir', false, '', false, true, 'global', 'setglobal'})
end)
it('should trigger if a number option be set globally', function()
set_hook('cmdheight')
- nvim.set_option('cmdheight', 5)
- eq(5, nvim.get_option('cmdheight'))
+ nvim.set_option_value('cmdheight', 5, {scope='global'})
+ eq(5, nvim.get_option_value('cmdheight', {scope='global'}))
expected_combination({'cmdheight', 1, '', 1, 5, 'global', 'setglobal'})
end)
it('should trigger if a string option be set globally', function()
set_hook('ambiwidth')
- nvim.set_option('ambiwidth', 'double')
- eq('double', nvim.get_option('ambiwidth'))
+ nvim.set_option_value('ambiwidth', 'double', {scope='global'})
+ eq('double', nvim.get_option_value('ambiwidth', {scope='global'}))
expected_combination({'ambiwidth', 'single', '', 'single', 'double', 'global', 'setglobal'})
end)
end)
diff --git a/test/functional/legacy/breakindent_spec.lua b/test/functional/legacy/breakindent_spec.lua
index d7779684a4..3913ba935a 100644
--- a/test/functional/legacy/breakindent_spec.lua
+++ b/test/functional/legacy/breakindent_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local command = helpers.command
local exec = helpers.exec
local feed = helpers.feed
@@ -17,28 +18,47 @@ describe('breakindent', function()
})
screen:attach()
exec([[
+ set listchars=eol:$
let &signcolumn = 'yes'
- let &showbreak = '+'
+ let &showbreak = '++'
+ let &breakindentopt = 'shift:2'
let leftcol = win_getid()->getwininfo()->get(0, {})->get('textoff')
eval repeat('x', &columns - leftcol - 1)->setline(1)
eval 'second line'->setline(2)
]])
+ feed('AX')
screen:expect([[
- {1: }^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
- {1: }second line |
+ {1: }xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX|
+ {1: }^second line |
{0:~ }|
{0:~ }|
{0:~ }|
- |
+ {2:-- INSERT --} |
]])
- feed('AX')
- screen:expect([[
+ -- No line wraps, so changing 'showbreak' should lead to the same screen.
+ command('setlocal showbreak=+')
+ screen:expect_unchanged()
+ -- No line wraps, so setting 'breakindent' should lead to the same screen.
+ command('setlocal breakindent')
+ screen:expect_unchanged()
+ -- The first line now wraps because of "eol" in 'listchars'.
+ command('setlocal list')
+ screen:expect{grid=[[
{1: }xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX|
- {1: }^second line |
+ {1: } {0:+^$} |
+ {1: }second line{0:$} |
{0:~ }|
{0:~ }|
+ {2:-- INSERT --} |
+ ]]}
+ command('setlocal nobreakindent')
+ screen:expect{grid=[[
+ {1: }xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX|
+ {1: }{0:+^$} |
+ {1: }second line{0:$} |
+ {0:~ }|
{0:~ }|
{2:-- INSERT --} |
- ]])
+ ]]}
end)
end)
diff --git a/test/functional/legacy/buffer_spec.lua b/test/functional/legacy/buffer_spec.lua
index acaa9a51f1..1e8909f0d0 100644
--- a/test/functional/legacy/buffer_spec.lua
+++ b/test/functional/legacy/buffer_spec.lua
@@ -10,7 +10,7 @@ describe('buffer', function()
before_each(function()
clear()
meths.ui_attach(80, 24, {})
- meths.set_option('hidden', false)
+ meths.set_option_value('hidden', false, {})
end)
it('deleting a modified buffer with :confirm', function()
diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua
index 2fceb6a132..3cbff2a01b 100644
--- a/test/functional/legacy/cmdline_spec.lua
+++ b/test/functional/legacy/cmdline_spec.lua
@@ -225,9 +225,9 @@ describe('cmdline', function()
[3] = {reverse = true}, -- TabLineFill
})
screen:attach()
- meths.set_option('laststatus', 2)
- meths.set_option('showtabline', 2)
- meths.set_option('cmdheight', 1)
+ meths.set_option_value('laststatus', 2, {})
+ meths.set_option_value('showtabline', 2, {})
+ meths.set_option_value('cmdheight', 1, {})
screen:expect([[
{2: [No Name] }{3: }|
^ |
@@ -239,6 +239,25 @@ describe('cmdline', function()
|
]])
end)
+
+ -- oldtest: Test_rulerformat_position()
+ it("ruler has correct position with 'rulerformat' set", function()
+ local screen = Screen.new(20, 3)
+ screen:set_default_attr_ids {
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ }
+ screen:attach()
+ meths.set_option_value('ruler', true, {})
+ meths.set_option_value('rulerformat', 'longish', {})
+ meths.set_option_value('laststatus', 0, {})
+ meths.set_option_value('winwidth', 1, {})
+ feed [[<C-W>v<C-W>|<C-W>p]]
+ screen:expect [[
+ │^ |
+ {0:~ }│{0:~}|
+ longish |
+ ]]
+ end)
end)
describe('cmdwin', function()
diff --git a/test/functional/legacy/conceal_spec.lua b/test/functional/legacy/conceal_spec.lua
new file mode 100644
index 0000000000..6aaa93f886
--- /dev/null
+++ b/test/functional/legacy/conceal_spec.lua
@@ -0,0 +1,587 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local command = helpers.command
+local exec = helpers.exec
+local feed = helpers.feed
+
+local expect_pos = function(row, col)
+ return helpers.eq({row, col}, helpers.eval('[screenrow(), screencol()]'))
+end
+
+describe('Conceal', function()
+ before_each(function()
+ clear()
+ command('set nohlsearch')
+ end)
+
+ -- oldtest: Test_conceal_two_windows()
+ it('works', function()
+ local screen = Screen.new(75, 12)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {bold = true, reverse = true}, -- StatusLine
+ [2] = {reverse = true}, -- StatusLineNC, IncSearch
+ [3] = {bold = true}, -- ModeMsg
+ })
+ screen:attach()
+ exec([[
+ let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
+ call setline(1, lines)
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2
+ set concealcursor=
+ exe "normal /here\r"
+ new
+ call setline(1, lines)
+ call setline(4, "Second window")
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2
+ set concealcursor=nc
+ exe "normal /here\r"
+ ]])
+
+ -- Check that cursor line is concealed
+ screen:expect([[
+ one one one one one |
+ two ^here |
+ three three |
+ Second window |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three three |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ /here |
+ ]])
+
+ -- Check that with concealed text vertical cursor movement is correct.
+ feed('k')
+ screen:expect([[
+ one one one o^ne one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three three |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ /here |
+ ]])
+
+ -- Check that with cursor line is not concealed
+ feed('j')
+ command('set concealcursor=')
+ screen:expect([[
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ Second window |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three three |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ /here |
+ ]])
+
+ -- Check that with cursor line is not concealed when moving cursor down
+ feed('j')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three |hidden^| three |
+ Second window |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three three |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ /here |
+ ]])
+
+ -- Check that with cursor line is not concealed when switching windows
+ feed('<C-W><C-W>')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ /here |
+ ]])
+
+ -- Check that with cursor line is only concealed in Normal mode
+ command('set concealcursor=n')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ /here |
+ ]])
+ feed('a')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h^ere |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Esc>/e')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h{2:e}re |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ /e^ |
+ ]])
+ feed('<Esc>v')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- VISUAL --} |
+ ]])
+ feed('<Esc>')
+
+ -- Check that with cursor line is only concealed in Insert mode
+ command('set concealcursor=i')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ |
+ ]])
+ feed('a')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two h^ere |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Esc>/e')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h{2:e}re |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ /e^ |
+ ]])
+ feed('<Esc>v')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- VISUAL --} |
+ ]])
+ feed('<Esc>')
+
+ -- Check that with cursor line is only concealed in Visual mode
+ command('set concealcursor=v')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ |
+ ]])
+ feed('a')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h^ere |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Esc>/e')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h{2:e}re |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ /e^ |
+ ]])
+ feed('<Esc>v')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two ^here |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- VISUAL --} |
+ ]])
+ feed('<Esc>')
+
+ -- Check moving the cursor while in insert mode.
+ command('set concealcursor=')
+ feed('a')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two |hidden| h^ere |
+ three three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Down>')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three |hidden|^ three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Esc>')
+
+ -- Check the "o" command
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three |hidden^| three |
+ {0:~ }|
+ {1:[No Name] [+] }|
+ |
+ ]])
+ feed('o')
+ screen:expect([[
+ one one one one one |
+ two here |
+ three three |
+ Second window |
+ {0:~ }|
+ {2:[No Name] [+] }|
+ one one one one one |
+ two here |
+ three three |
+ ^ |
+ {1:[No Name] [+] }|
+ {3:-- INSERT --} |
+ ]])
+ feed('<Esc>')
+ end)
+
+ -- oldtest: Test_conceal_with_cursorcolumn()
+ it('CursorColumn and ColorColumn on wrapped line', function()
+ local screen = Screen.new(40, 10)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {background = Screen.colors.Grey90}, -- CursorColumn
+ [2] = {background = Screen.colors.LightRed}, -- ColorColumn
+ })
+ screen:attach()
+ -- Check that cursorcolumn and colorcolumn don't get broken in presence of
+ -- wrapped lines containing concealed text
+ -- luacheck: push ignore 613 (trailing whitespace in a string)
+ exec([[
+ let lines = ["one one one |hidden| one one one one one one one one",
+ \ "two two two two |hidden| here two two",
+ \ "three |hidden| three three three three three three three three"]
+ call setline(1, lines)
+ set wrap linebreak
+ set showbreak=\ >>>\
+ syntax match test /|hidden|/ conceal
+ set conceallevel=2
+ set concealcursor=
+ exe "normal /here\r"
+ set cursorcolumn
+ set colorcolumn=50
+ ]])
+ -- luacheck: pop
+
+ screen:expect([[
+ one one one one one one {1:o}ne |
+ {0: >>> }one {2:o}ne one one |
+ two two two two |hidden| ^here two two |
+ three three three three {1:t}hree |
+ {0: >>> }thre{2:e} three three three |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ /here |
+ ]])
+
+ -- move cursor to the end of line (the cursor jumps to the next screen line)
+ feed('$')
+ screen:expect([[
+ one one one one one one one |
+ {0: >>> }one {2:o}ne one one |
+ two two two two |hidden| here two tw^o |
+ three three three three three |
+ {0: >>> }thre{2:e} three three three |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ /here |
+ ]])
+ end)
+
+ -- oldtest: Test_conceal_resize_term()
+ it('resize editor', function()
+ local screen = Screen.new(75, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {foreground = Screen.colors.Blue}, -- Comment
+ })
+ screen:attach()
+ exec([[
+ call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
+ setl cocu=n cole=3
+ syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
+ normal fb
+ ]])
+ screen:expect([[
+ one two three four five, the ^backticks should be concealed |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+
+ screen:try_resize(75, 7)
+ screen:expect([[
+ one two three four five, the ^backticks should be concealed |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_conceal_linebreak()
+ it('with linebreak', function()
+ local screen = Screen.new(75, 8)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+ exec([[
+ let &wrap = v:true
+ let &conceallevel = 2
+ let &concealcursor = 'nc'
+ let &linebreak = v:true
+ let &showbreak = '+ '
+ let line = 'a`a`a`a`'
+ \ .. 'a'->repeat(&columns - 15)
+ \ .. ' b`b`'
+ \ .. 'b'->repeat(&columns - 10)
+ \ .. ' cccccc'
+ eval ['x'->repeat(&columns), '', line]->setline(1)
+ syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends
+ ]])
+ screen:expect([[
+ ^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
+ |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+ {0:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
+ {0:+ }cccccc |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
+ -- Tests for correct display (cursor column position) with +conceal and tabulators.
+ -- oldtest: Test_conceal_cursor_pos()
+ it('cursor and column position with conceal and tabulators', function()
+ exec([[
+ let l = ['start:', '.concealed. text', "|concealed|\ttext"]
+ let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
+ let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
+ call append(0, l)
+ call cursor(1, 1)
+ " Conceal settings.
+ set conceallevel=2
+ set concealcursor=nc
+ syntax match test /|/ conceal
+ ]])
+ feed('ztj')
+ expect_pos(2, 1)
+ -- We should end up in the same column when running these commands on the
+ -- two lines.
+ feed('ft')
+ expect_pos(2, 17)
+ feed('$')
+ expect_pos(2, 20)
+ feed('0j')
+ expect_pos(3, 1)
+ feed('ft')
+ expect_pos(3, 17)
+ feed('$')
+ expect_pos(3, 20)
+ feed('j0j')
+ expect_pos(5, 8)
+ -- Same for next test block.
+ feed('ft')
+ expect_pos(5, 25)
+ feed('$')
+ expect_pos(5, 28)
+ feed('0j')
+ expect_pos(6, 8)
+ feed('ft')
+ expect_pos(6, 25)
+ feed('$')
+ expect_pos(6, 28)
+ feed('0j0j')
+ expect_pos(8, 1)
+ -- And check W with multiple tabs and conceals in a line.
+ feed('W')
+ expect_pos(8, 9)
+ feed('W')
+ expect_pos(8, 17)
+ feed('W')
+ expect_pos(8, 25)
+ feed('$')
+ expect_pos(8, 27)
+ feed('0j')
+ expect_pos(9, 1)
+ feed('W')
+ expect_pos(9, 9)
+ feed('W')
+ expect_pos(9, 17)
+ feed('W')
+ expect_pos(9, 25)
+ feed('$')
+ expect_pos(9, 26)
+ command('set lbr')
+ feed('$')
+ expect_pos(9, 26)
+ command('set list listchars=tab:>-')
+ feed('0')
+ expect_pos(9, 1)
+ feed('W')
+ expect_pos(9, 9)
+ feed('W')
+ expect_pos(9, 17)
+ feed('W')
+ expect_pos(9, 25)
+ feed('$')
+ expect_pos(9, 26)
+ end)
+end)
diff --git a/test/functional/legacy/crash_spec.lua b/test/functional/legacy/crash_spec.lua
new file mode 100644
index 0000000000..5094f81847
--- /dev/null
+++ b/test/functional/legacy/crash_spec.lua
@@ -0,0 +1,16 @@
+local helpers = require('test.functional.helpers')(after_each)
+local assert_alive = helpers.assert_alive
+local clear = helpers.clear
+local command = helpers.command
+local feed = helpers.feed
+
+before_each(clear)
+
+-- oldtest: Test_crash1()
+it('no crash when ending Visual mode while editing buffer closes window', function()
+ command('new')
+ command('autocmd ModeChanged v:n ++once close')
+ feed('v')
+ command('enew')
+ assert_alive()
+end)
diff --git a/test/functional/legacy/debugger_spec.lua b/test/functional/legacy/debugger_spec.lua
new file mode 100644
index 0000000000..e6fb81719f
--- /dev/null
+++ b/test/functional/legacy/debugger_spec.lua
@@ -0,0 +1,85 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local command = helpers.command
+local feed = helpers.feed
+local write_file = helpers.write_file
+
+before_each(clear)
+
+describe('debugger', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(999, 10)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue};
+ [1] = {reverse = true, bold = true};
+ })
+ screen:attach()
+ end)
+
+ -- oldtest: Test_Debugger_breakadd_expr()
+ it(':breakadd expr', function()
+ write_file('XdebugBreakExpr.vim', 'let g:Xtest_var += 1')
+ finally(function()
+ os.remove('XdebugBreakExpr.vim')
+ end)
+
+ command('edit XdebugBreakExpr.vim')
+ command(':let g:Xtest_var = 10')
+ command(':breakadd expr g:Xtest_var')
+ feed(':source %<CR>')
+ screen:expect{grid=[[
+ ^let g:Xtest_var += 1{MATCH: *}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ :source %{MATCH: *}|
+ ]]}
+ feed(':source %<CR>')
+ screen:expect{grid=[[
+ let g:Xtest_var += 1{MATCH: *}|
+ {0:~{MATCH: *}}|
+ {1:{MATCH: *}}|
+ Breakpoint in "{MATCH:.*}XdebugBreakExpr.vim" line 1{MATCH: *}|
+ Entering Debug mode. Type "cont" to continue.{MATCH: *}|
+ Oldval = "10"{MATCH: *}|
+ Newval = "11"{MATCH: *}|
+ {MATCH:.*}XdebugBreakExpr.vim{MATCH: *}|
+ line 1: let g:Xtest_var += 1{MATCH: *}|
+ >^{MATCH: *}|
+ ]]}
+ feed('cont<CR>')
+ screen:expect{grid=[[
+ ^let g:Xtest_var += 1{MATCH: *}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {0:~{MATCH: *}}|
+ {MATCH: *}|
+ ]]}
+ feed(':source %<CR>')
+ screen:expect{grid=[[
+ let g:Xtest_var += 1{MATCH: *}|
+ {0:~{MATCH: *}}|
+ {1:{MATCH: *}}|
+ Breakpoint in "{MATCH:.*}XdebugBreakExpr.vim" line 1{MATCH: *}|
+ Entering Debug mode. Type "cont" to continue.{MATCH: *}|
+ Oldval = "11"{MATCH: *}|
+ Newval = "12"{MATCH: *}|
+ {MATCH:.*}XdebugBreakExpr.vim{MATCH: *}|
+ line 1: let g:Xtest_var += 1{MATCH: *}|
+ >^{MATCH: *}|
+ ]]}
+ end)
+end)
diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua
index cefcd6c6c4..1b9ec9af62 100644
--- a/test/functional/legacy/delete_spec.lua
+++ b/test/functional/legacy/delete_spec.lua
@@ -63,6 +63,6 @@ describe('Test for delete()', function()
it('gives correct emsgs', function()
eq('Vim(call):E474: Invalid argument', exc_exec("call delete('')"))
- eq('Vim(call):E15: Invalid expression: 0', exc_exec("call delete('foo', 0)"))
+ eq('Vim(call):E15: Invalid expression: "0"', exc_exec("call delete('foo', 0)"))
end)
end)
diff --git a/test/functional/legacy/digraph_spec.lua b/test/functional/legacy/digraph_spec.lua
index 0cb0bb84be..7eeb83eb5f 100644
--- a/test/functional/legacy/digraph_spec.lua
+++ b/test/functional/legacy/digraph_spec.lua
@@ -22,7 +22,7 @@ describe('digraph', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {2:-- INSERT -} |
+ {2:-- INSERT --}|
]])
feed('1')
screen:expect([[
@@ -31,7 +31,7 @@ describe('digraph', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {2:-- INSERT -} |
+ {2:-- INSERT --}|
]])
feed('2')
screen:expect([[
@@ -40,7 +40,7 @@ describe('digraph', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {2:-- INSERT -} |
+ {2:-- INSERT --}|
]])
end)
end)
diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua
index f9b78f5dcd..9c6f521882 100644
--- a/test/functional/legacy/display_spec.lua
+++ b/test/functional/legacy/display_spec.lua
@@ -58,51 +58,6 @@ describe('display', function()
]])
end)
- -- oldtest: Test_matchparen_clear_highlight()
- it('matchparen highlight is cleared when switching buffer', function()
- local screen = Screen.new(20, 5)
- screen:set_default_attr_ids({
- [0] = {bold = true, foreground = Screen.colors.Blue},
- [1] = {background = Screen.colors.Cyan},
- })
- screen:attach()
-
- local screen1 = [[
- {1:^()} |
- {0:~ }|
- {0:~ }|
- {0:~ }|
- |
- ]]
- local screen2 = [[
- ^aa |
- {0:~ }|
- {0:~ }|
- {0:~ }|
- |
- ]]
-
- exec([[
- source $VIMRUNTIME/plugin/matchparen.vim
- set hidden
- call setline(1, ['()'])
- normal 0
- ]])
- screen:expect(screen1)
-
- exec([[
- enew
- exe "normal iaa\<Esc>0"
- ]])
- screen:expect(screen2)
-
- feed('<C-^>')
- screen:expect(screen1)
-
- feed('<C-^>')
- screen:expect(screen2)
- end)
-
local function run_test_display_lastline(euro)
local screen = Screen.new(75, 10)
screen:set_default_attr_ids({
@@ -194,4 +149,149 @@ describe('display', function()
it('display "lastline" works correctly with multibyte fillchar', function()
run_test_display_lastline(true)
end)
+
+ -- oldtest: Test_display_long_lastline()
+ it('"lastline" shows correct text when end of wrapped line is deleted', function()
+ local screen = Screen.new(35, 14)
+ screen:attach()
+ exec([[
+ set display=lastline smoothscroll scrolloff=0
+ call setline(1, [
+ \'aaaaa'->repeat(150),
+ \'bbbbb '->repeat(7) .. 'ccccc '->repeat(7) .. 'ddddd '->repeat(7)
+ \])
+ ]])
+ feed('736|')
+ screen:expect([[
+ <<<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ ^aaaaaaaaaaaaaaa |
+ |
+ ]])
+ -- The correct part of the last line is moved into view.
+ feed('D')
+ screen:expect([[
+ <<<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^a|
+ bbbbb bbbbb bbbbb bbbbb bbbbb bb@@@|
+ |
+ ]])
+ -- "w_skipcol" does not change because the topline is still long enough
+ -- to maintain the current skipcol.
+ feed('g04l11gkD')
+ screen:expect([[
+ <<<^a |
+ bbbbb bbbbb bbbbb bbbbb bbbbb bbbbb|
+ bbbbb ccccc ccccc ccccc ccccc cccc|
+ c ccccc ccccc ddddd ddddd ddddd ddd|
+ dd ddddd ddddd ddddd |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ -- "w_skipcol" is reset to bring the entire topline into view because
+ -- the line length is now smaller than the current skipcol + marker.
+ feed('x')
+ screen:expect([[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aa^a |
+ bbbbb bbbbb bbbbb bbbbb bbbbb bbbbb|
+ bbbbb ccccc ccccc ccccc ccccc cccc|
+ c ccccc ccccc ddddd ddddd ddddd @@@|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_display_cursor_long_line()
+ it("correctly shows line that doesn't fit in the window", function()
+ local screen = Screen.new(75, 8)
+ screen:attach()
+ exec([[
+ call setline(1, ['a', 'b ' .. 'bbbbb'->repeat(150), 'c'])
+ norm $j
+ ]])
+ screen:expect([[
+ <<<bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ b^b |
+ |
+ ]])
+ -- FIXME: moving the cursor above the topline does not set w_skipcol
+ -- correctly with cpo+=n and zero scrolloff (curs_columns() extra == 1).
+ exec('set number cpo+=n scrolloff=0')
+ feed('$0')
+ screen:expect([[
+ <<<b^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ |
+ ]])
+ -- Going to the start of the line with "b" did not set w_skipcol correctly with 'smoothscroll'.
+ exec('set smoothscroll')
+ feed('$b')
+ screen:expect([[
+ 2 b ^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ |
+ ]])
+ -- Same for "ge".
+ feed('$ge')
+ screen:expect([[
+ 2 ^b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua
index 362d33a0fd..939999e21b 100644
--- a/test/functional/legacy/edit_spec.lua
+++ b/test/functional/legacy/edit_spec.lua
@@ -43,7 +43,7 @@ describe('edit', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {2:-- INSERT -} |
+ {2:-- INSERT --}|
]])
feed('=')
screen:expect([[
@@ -55,4 +55,68 @@ describe('edit', function()
=^ |
]])
end)
+
+ -- oldtest: Test_edit_ctrl_r_failed()
+ it('positioning cursor after CTRL-R expression failed', function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {foreground = Screen.colors.Blue}, -- SpecialKey
+ [2] = {foreground = Screen.colors.SlateBlue},
+ [3] = {bold = true}, -- ModeMsg
+ [4] = {reverse = true, bold = true}, -- MsgSeparator
+ [5] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
+ [6] = {foreground = Screen.colors.SeaGreen, bold = true}, -- MoreMsg
+ })
+ screen:attach()
+
+ feed('i<C-R>')
+ screen:expect([[
+ {1:^"} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- INSERT --} |
+ ]])
+ feed('={}')
+ screen:expect([[
+ {1:"} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ={2:{}}^ |
+ ]])
+ -- trying to insert a dictionary produces an error
+ feed('<CR>')
+ screen:expect([[
+ {1:"} |
+ {0:~ }|
+ {4: }|
+ ={2:{}} |
+ {5:E731: Using a Dictionary as a String} |
+ {6:Press ENTER or type command to continue}^ |
+ ]])
+
+ feed(':')
+ screen:expect([[
+ :^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- INSERT --} |
+ ]])
+ -- ending Insert mode should put the cursor back on the ':'
+ feed('<Esc>')
+ screen:expect([[
+ ^: |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua
index b5e45a86c1..c531c59fd1 100644
--- a/test/functional/legacy/eval_spec.lua
+++ b/test/functional/legacy/eval_spec.lua
@@ -613,15 +613,15 @@ describe('eval', function()
Executing call setreg(1, 2, 3, 4)
Vim(call):E118: Too many arguments for function: setreg
Executing call setreg([], 2)
- Vim(call):E730: using List as a String
+ Vim(call):E730: Using a List as a String
Executing call setreg(1, 2, [])
- Vim(call):E730: using List as a String
+ Vim(call):E730: Using a List as a String
Executing call setreg("/", ["1", "2"])
- Vim(call):E883: search pattern and expression register may not contain two or more lines
+ Vim(call):E883: Search pattern and expression register may not contain two or more lines
Executing call setreg("=", ["1", "2"])
- Vim(call):E883: search pattern and expression register may not contain two or more lines
+ Vim(call):E883: Search pattern and expression register may not contain two or more lines
Executing call setreg(1, ["", "", [], ""])
- Vim(call):E730: using List as a String]])
+ Vim(call):E730: Using a List as a String]])
end)
it('function name not starting with a capital', function()
diff --git a/test/functional/legacy/filechanged_spec.lua b/test/functional/legacy/filechanged_spec.lua
index cea1d6ac30..c8e772f597 100644
--- a/test/functional/legacy/filechanged_spec.lua
+++ b/test/functional/legacy/filechanged_spec.lua
@@ -12,8 +12,8 @@ describe('file changed dialog', function()
before_each(function()
clear()
meths.ui_attach(80, 24, {})
- meths.set_option('autoread', false)
- meths.set_option('fsync', true)
+ meths.set_option_value('autoread', false, {})
+ meths.set_option_value('fsync', true, {})
end)
it('works', function()
diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua
index 029d95206e..de304f3e4b 100644
--- a/test/functional/legacy/glob2regpat_spec.lua
+++ b/test/functional/legacy/glob2regpat_spec.lua
@@ -1,16 +1,10 @@
--- Tests for signs
-
local helpers = require('test.functional.helpers')(after_each)
-local clear, exc_exec = helpers.clear, helpers.exc_exec
+local clear = helpers.clear
local eq, eval = helpers.eq, helpers.eval
describe('glob2regpat()', function()
before_each(clear)
- it('handles invalid input', function()
- eq('Vim(call):E806: using Float as a String',
- exc_exec('call glob2regpat(1.33)'))
- end)
it('returns ^$ for empty input', function()
eq('^$', eval("glob2regpat('')"))
end)
diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/highlight_spec.lua
index d3f2897493..0a130f1607 100644
--- a/test/functional/legacy/051_highlight_spec.lua
+++ b/test/functional/legacy/highlight_spec.lua
@@ -1,5 +1,3 @@
--- Tests for ":highlight".
-
local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
local clear, feed = helpers.clear, helpers.feed
@@ -8,10 +6,11 @@ local eq = helpers.eq
local poke_eventloop = helpers.poke_eventloop
local exc_exec = helpers.exc_exec
local feed_command = helpers.feed_command
+local exec = helpers.exec
-describe(':highlight', function()
- setup(clear)
+before_each(clear)
+describe(':highlight', function()
it('is working', function()
local screen = Screen.new(35, 10)
screen:attach()
@@ -94,3 +93,30 @@ describe(':highlight', function()
Group3 xxx cleared]])
end)
end)
+
+describe('Visual selection highlight', function()
+ -- oldtest: Test_visual_sbr()
+ it("when 'showbreak' is set", function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {background = Screen.colors.LightGrey}, -- Visual
+ [2] = {bold = true}, -- ModeMsg
+ })
+ screen:attach()
+ exec([[
+ set showbreak=>
+ call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')
+ exe "normal! z1\<CR>"
+ ]])
+ feed('v$')
+ screen:expect([[
+ {0:>}{1:n, no sea takimata sanctus est Lorem ipsum dolor sit amet.}^ |
+ |
+ |
+ |
+ |
+ {2:-- VISUAL --} |
+ ]])
+ end)
+end)
diff --git a/test/functional/legacy/matchparen_spec.lua b/test/functional/legacy/matchparen_spec.lua
new file mode 100644
index 0000000000..22d9247698
--- /dev/null
+++ b/test/functional/legacy/matchparen_spec.lua
@@ -0,0 +1,116 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local exec = helpers.exec
+local feed = helpers.feed
+
+describe('matchparen', function()
+ before_each(clear)
+
+ -- oldtest: Test_visual_block_scroll()
+ it('redraws properly after scrolling with scrolloff=1', function()
+ local screen = Screen.new(30, 7)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true},
+ [2] = {background = Screen.colors.LightGrey},
+ })
+
+ exec([[
+ source $VIMRUNTIME/plugin/matchparen.vim
+ set scrolloff=1
+ call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
+ call cursor(5, 1)
+ ]])
+
+ feed('V<c-d><c-d>')
+ screen:expect([[
+ {2:{} |
+ {2:}} |
+ {2:{} |
+ {2:f} |
+ ^g |
+ } |
+ {1:-- VISUAL LINE --} |
+ ]])
+ end)
+
+ -- oldtest: Test_matchparen_clear_highlight()
+ it('matchparen highlight is cleared when switching buffer', function()
+ local screen = Screen.new(20, 5)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ [1] = {background = Screen.colors.Cyan},
+ })
+ screen:attach()
+
+ local screen1 = [[
+ {1:^()} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]
+ local screen2 = [[
+ ^aa |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]
+
+ exec([[
+ source $VIMRUNTIME/plugin/matchparen.vim
+ set hidden
+ call setline(1, ['()'])
+ normal 0
+ ]])
+ screen:expect(screen1)
+
+ exec([[
+ enew
+ exe "normal iaa\<Esc>0"
+ ]])
+ screen:expect(screen2)
+
+ feed('<C-^>')
+ screen:expect(screen1)
+
+ feed('<C-^>')
+ screen:expect(screen2)
+ end)
+
+ -- oldtest: Test_matchparen_pum_clear()
+ it('is cleared when completion popup is shown', function()
+ local screen = Screen.new(30, 9)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue};
+ [1] = {background = Screen.colors.Plum1};
+ [2] = {background = Screen.colors.Grey};
+ [3] = {bold = true};
+ [4] = {bold = true, foreground = Screen.colors.SeaGreen};
+ })
+
+ exec([[
+ source $VIMRUNTIME/plugin/matchparen.vim
+ set completeopt=menuone
+ call setline(1, ['aa', 'aaa', 'aaaa', '(a)'])
+ call cursor(4, 3)
+ ]])
+
+ feed('i<C-X><C-N><C-N>')
+ screen:expect{grid=[[
+ aa |
+ aaa |
+ aaaa |
+ (aaa^) |
+ {1: aa }{0: }|
+ {2: aaa }{0: }|
+ {1: aaaa }{0: }|
+ {0:~ }|
+ {3:-- }{4:match 2 of 3} |
+ ]]}
+ end)
+end)
diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua
index 59839157ea..5f722e5190 100644
--- a/test/functional/legacy/memory_usage_spec.lua
+++ b/test/functional/legacy/memory_usage_spec.lua
@@ -11,14 +11,10 @@ local load_adjust = helpers.load_adjust
local write_file = helpers.write_file
local is_os = helpers.is_os
local is_ci = helpers.is_ci
-
-local function isasan()
- local version = eval('execute("version")')
- return version:match('-fsanitize=[a-z,]*address')
-end
+local is_asan = helpers.is_asan
clear()
-if isasan() then
+if is_asan() then
pending('ASAN build is difficult to estimate memory usage', function() end)
return
elseif is_os('win') then
diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua
index 71a53c8381..e0cc1dc79c 100644
--- a/test/functional/legacy/messages_spec.lua
+++ b/test/functional/legacy/messages_spec.lua
@@ -6,6 +6,7 @@ local exec = helpers.exec
local feed = helpers.feed
local meths = helpers.meths
local nvim_dir = helpers.nvim_dir
+local assert_alive = helpers.assert_alive
before_each(clear)
@@ -49,6 +50,71 @@ describe('messages', function()
]])
end)
+ -- oldtest: Test_message_not_cleared_after_mode()
+ it('clearing mode does not remove message', function()
+ screen = Screen.new(60, 10)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
+ })
+ screen:attach()
+ exec([[
+ nmap <silent> gx :call DebugSilent('normal')<CR>
+ vmap <silent> gx :call DebugSilent('visual')<CR>
+ function DebugSilent(arg)
+ echomsg "from DebugSilent" a:arg
+ endfunction
+ set showmode
+ set cmdheight=1
+ call setline(1, ['one', 'NoSuchFile', 'three'])
+ ]])
+
+ feed('gx')
+ screen:expect([[
+ ^one |
+ NoSuchFile |
+ three |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ from DebugSilent normal |
+ ]])
+
+ -- removing the mode message used to also clear the intended message
+ feed('vEgx')
+ screen:expect([[
+ ^one |
+ NoSuchFile |
+ three |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ from DebugSilent visual |
+ ]])
+
+ -- removing the mode message used to also clear the error message
+ command('set cmdheight=2')
+ feed('2GvEgf')
+ screen:expect([[
+ one |
+ NoSuchFil^e |
+ three |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ from DebugSilent visual |
+ {1:E447: Can't find file "NoSuchFile" in path} |
+ ]])
+ end)
+
describe('more prompt', function()
before_each(function()
command('set more')
@@ -361,9 +427,9 @@ describe('messages', function()
screen:attach()
command('cd '..nvim_dir)
- meths.set_option('shell', './shell-test')
- meths.set_option('shellcmdflag', 'REP 20')
- meths.set_option('shellxquote', '') -- win: avoid extra quotes
+ meths.set_option_value('shell', './shell-test', {})
+ meths.set_option_value('shellcmdflag', 'REP 20', {})
+ meths.set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
-- display a page and go back, results in exactly the same view
feed([[:4 verbose echo system('foo')<CR>]])
@@ -661,6 +727,46 @@ describe('messages', function()
]])
end)
+ -- oldtest: Test_fileinfo_tabpage_cmdheight()
+ it("fileinfo works when 'cmdheight' has just decreased", function()
+ screen = Screen.new(40, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [1] = {bold = true}; -- TabLineSel
+ [2] = {underline = true, background = Screen.colors.LightGrey}; -- TabLine
+ [3] = {reverse = true}; -- TabLineFill
+ })
+ screen:attach()
+
+ exec([[
+ set shortmess-=o
+ set shortmess-=O
+ set shortmess-=F
+ tabnew
+ set cmdheight=2
+ ]])
+ command('mode') -- FIXME: bottom is invalid after scrolling
+ screen:expect([[
+ {2: [No Name] }{1: [No Name] }{3: }{2:X}|
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ |
+ ]])
+
+ feed(':tabprev | edit Xfileinfo.txt<CR>')
+ screen:expect([[
+ {1: Xfileinfo.txt }{2: [No Name] }{3: }{2:X}|
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ "Xfileinfo.txt" [New] |
+ ]])
+ assert_alive()
+ end)
+
-- oldtest: Test_fileinfo_after_echo()
it('fileinfo does not overwrite echo message vim-patch:8.2.4156', function()
screen = Screen.new(40, 6)
@@ -668,6 +774,7 @@ describe('messages', function()
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
})
screen:attach()
+
exec([[
set shortmess-=F
@@ -681,6 +788,7 @@ describe('messages', function()
autocmd CursorHold * buf b.txt | w | echo "'b' written"
]])
+
command('set updatetime=50')
feed('0$')
screen:expect([[
@@ -693,4 +801,9 @@ describe('messages', function()
]])
os.remove('b.txt')
end)
+
+ it('no crash when truncating overlong message', function()
+ pcall(command, 'source test/old/testdir/crash/vim_msg_trunc_poc')
+ assert_alive()
+ end)
end)
diff --git a/test/functional/legacy/move_spec.lua b/test/functional/legacy/move_spec.lua
new file mode 100644
index 0000000000..855996da8f
--- /dev/null
+++ b/test/functional/legacy/move_spec.lua
@@ -0,0 +1,49 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local feed = helpers.feed
+local funcs = helpers.funcs
+
+before_each(clear)
+
+describe(':move', function()
+ -- oldtest: Test_move_undo()
+ it('redraws correctly when undone', function()
+ local screen = Screen.new(60, 10)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+
+ funcs.setline(1, {'First', 'Second', 'Third', 'Fourth'})
+ feed('gg:move +1<CR>')
+ screen:expect([[
+ Second |
+ ^First |
+ Third |
+ Fourth |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ :move +1 |
+ ]])
+
+ -- here the display would show the last few lines scrolled down
+ feed('u')
+ feed(':<Esc>')
+ screen:expect([[
+ ^First |
+ Second |
+ Third |
+ Fourth |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+end)
diff --git a/test/functional/legacy/normal_spec.lua b/test/functional/legacy/normal_spec.lua
new file mode 100644
index 0000000000..ba875460f5
--- /dev/null
+++ b/test/functional/legacy/normal_spec.lua
@@ -0,0 +1,41 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local exec = helpers.exec
+
+before_each(clear)
+
+describe('normal', function()
+ -- oldtest: Test_normal_j_below_botline()
+ it([["j" does not skip lines when scrolling below botline and 'foldmethod' is not "manual"]], function()
+ local screen = Screen.new(40, 19)
+ screen:attach()
+ screen:set_default_attr_ids({{foreground = Screen.colors.Brown}})
+ exec([[
+ set number foldmethod=diff scrolloff=0
+ call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
+ norm Lj
+ ]])
+ screen:expect([[
+ {1: 2 }222222222222222222222222222222222222|
+ {1: }222222222222222222222222222222222222|
+ {1: }222222222222222222222222222222222222|
+ {1: }222222222222222222222222222222222222|
+ {1: }222222222222222222222222222222222222|
+ {1: }22222222222222222222 |
+ {1: 3 }333333333333333333333333333333333333|
+ {1: }333333333333333333333333333333333333|
+ {1: }333333333333333333333333333333333333|
+ {1: }333333333333333333333333333333333333|
+ {1: }333333333333333333333333333333333333|
+ {1: }33333333333333333333 |
+ {1: 4 }^444444444444444444444444444444444444|
+ {1: }444444444444444444444444444444444444|
+ {1: }444444444444444444444444444444444444|
+ {1: }444444444444444444444444444444444444|
+ {1: }444444444444444444444444444444444444|
+ {1: }44444444444444444444 |
+ |
+ ]])
+ end)
+end)
diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua
index bd14f3bc53..ce46ea013d 100644
--- a/test/functional/legacy/options_spec.lua
+++ b/test/functional/legacy/options_spec.lua
@@ -1,4 +1,4 @@
--- See also: src/nvim/testdir/test_options.vim
+-- See also: test/old/testdir/test_options.vim
local helpers = require('test.functional.helpers')(after_each)
local command, clear = helpers.command, helpers.clear
local source, expect = helpers.source, helpers.expect
diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua
index 63338b8dba..5c3f8a6f8c 100644
--- a/test/functional/legacy/prompt_buffer_spec.lua
+++ b/test/functional/legacy/prompt_buffer_spec.lua
@@ -3,10 +3,11 @@ local Screen = require('test.functional.ui.screen')
local feed = helpers.feed
local source = helpers.source
local clear = helpers.clear
-local feed_command = helpers.feed_command
+local command = helpers.command
local poke_eventloop = helpers.poke_eventloop
local meths = helpers.meths
local eq = helpers.eq
+local neq = helpers.neq
describe('prompt buffer', function()
local screen
@@ -15,65 +16,78 @@ describe('prompt buffer', function()
clear()
screen = Screen.new(25, 10)
screen:attach()
+ command('set laststatus=0 nohidden')
+ end)
+
+ local function source_script()
source([[
func TextEntered(text)
if a:text == "exit"
+ " Reset &modified to allow the buffer to be closed.
set nomodified
stopinsert
close
else
+ " Add the output above the current prompt.
call append(line("$") - 1, 'Command: "' . a:text . '"')
+ " Reset &modified to allow the buffer to be closed.
set nomodified
call timer_start(20, {id -> TimerFunc(a:text)})
endif
endfunc
func TimerFunc(text)
+ " Add the output above the current prompt.
call append(line("$") - 1, 'Result: "' . a:text .'"')
+ " Reset &modified to allow the buffer to be closed.
+ set nomodified
endfunc
func SwitchWindows()
call timer_start(0, {-> execute("wincmd p", "")})
endfunc
- ]])
- feed_command("set noshowmode | set laststatus=0")
- feed_command("call setline(1, 'other buffer')")
- feed_command("new")
- feed_command("set buftype=prompt")
- feed_command("call prompt_setcallback(bufnr(''), function('TextEntered'))")
- feed_command("eval bufnr('')->prompt_setprompt('cmd: ')")
- end)
- after_each(function()
- screen:detach()
- end)
-
- it('works', function()
+ call setline(1, "other buffer")
+ set nomodified
+ new
+ set buftype=prompt
+ call prompt_setcallback(bufnr(''), function("TextEntered"))
+ eval bufnr("")->prompt_setprompt("cmd: ")
+ startinsert
+ ]])
screen:expect([[
- ^ |
+ cmd: ^ |
~ |
~ |
~ |
- [Prompt] |
+ [Prompt] [+] |
other buffer |
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
- feed("i")
+ end
+
+ after_each(function()
+ screen:detach()
+ end)
+
+ -- oldtest: Test_prompt_basic()
+ it('works', function()
+ source_script()
feed("hello\n")
screen:expect([[
cmd: hello |
Command: "hello" |
Result: "hello" |
cmd: ^ |
- [Prompt] [+] |
+ [Prompt] |
other buffer |
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
feed("exit\n")
screen:expect([[
@@ -90,20 +104,9 @@ describe('prompt buffer', function()
]])
end)
+ -- oldtest: Test_prompt_editing()
it('editing', function()
- screen:expect([[
- ^ |
- ~ |
- ~ |
- ~ |
- [Prompt] |
- other buffer |
- ~ |
- ~ |
- ~ |
- |
- ]])
- feed("i")
+ source_script()
feed("hello<BS><BS>")
screen:expect([[
cmd: hel^ |
@@ -115,7 +118,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
feed("<Left><Left><Left><BS>-")
screen:expect([[
@@ -128,7 +131,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
feed("<C-O>lz")
screen:expect([[
@@ -141,7 +144,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
feed("<End>x")
screen:expect([[
@@ -154,7 +157,7 @@ describe('prompt buffer', function()
~ |
~ |
~ |
- |
+ -- INSERT -- |
]])
feed("<C-U>exit\n")
screen:expect([[
@@ -171,21 +174,9 @@ describe('prompt buffer', function()
]])
end)
+ -- oldtest: Test_prompt_switch_windows()
it('switch windows', function()
- feed_command("set showmode")
- feed("i")
- screen:expect([[
- cmd: ^ |
- ~ |
- ~ |
- ~ |
- [Prompt] [+] |
- other buffer |
- ~ |
- ~ |
- ~ |
- -- INSERT -- |
- ]])
+ source_script()
feed("<C-O>:call SwitchWindows()<CR>")
screen:expect{grid=[[
cmd: |
@@ -227,13 +218,49 @@ describe('prompt buffer', function()
]])
end)
+ -- oldtest: Test_prompt_while_writing_to_hidden_buffer()
it('keeps insert mode after aucmd_restbuf in callback', function()
+ source_script()
source [[
let s:buf = nvim_create_buf(1, 1)
call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])})
- startinsert
]]
poke_eventloop()
- eq({ mode = "i", blocking = false }, meths.get_mode())
+ eq({ mode = 'i', blocking = false }, meths.get_mode())
+ end)
+
+ -- oldtest: Test_prompt_appending_while_hidden()
+ it('accessing hidden prompt buffer does not start insert mode', function()
+ local prev_win = meths.get_current_win()
+ source([[
+ new prompt
+ set buftype=prompt
+ set bufhidden=hide
+
+ func s:TextEntered(text)
+ if a:text == 'exit'
+ close
+ endif
+ let g:entered = a:text
+ endfunc
+ call prompt_setcallback(bufnr(), function('s:TextEntered'))
+
+ func DoAppend()
+ call appendbufline('prompt', '$', 'Test')
+ return ''
+ endfunc
+ ]])
+ feed('asomething<CR>')
+ eq('something', meths.get_var('entered'))
+ neq(prev_win, meths.get_current_win())
+ feed('exit<CR>')
+ eq(prev_win, meths.get_current_win())
+ eq({ mode = 'n', blocking = false }, meths.get_mode())
+ command('call DoAppend()')
+ eq({ mode = 'n', blocking = false }, meths.get_mode())
+ feed('i')
+ eq({ mode = 'i', blocking = false }, meths.get_mode())
+ command('call DoAppend()')
+ eq({ mode = 'i', blocking = false }, meths.get_mode())
end)
end)
diff --git a/test/functional/legacy/put_spec.lua b/test/functional/legacy/put_spec.lua
index 3ddf65490e..4a42a1c8a3 100644
--- a/test/functional/legacy/put_spec.lua
+++ b/test/functional/legacy/put_spec.lua
@@ -1,4 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local exec_lua = helpers.exec_lua
local meths = helpers.meths
@@ -42,4 +43,56 @@ describe('put', function()
bwipe!
]]
end)
+
+ -- oldtest: Test_put_other_window()
+ it('above topline in buffer in two splits', function()
+ local screen = Screen.new(80, 10)
+ screen:attach()
+ source([[
+ 40vsplit
+ 0put ='some text at the top'
+ put =' one more text'
+ put =' two more text'
+ put =' three more text'
+ put =' four more text'
+ ]])
+
+ screen:expect([[
+ some text at the top │some text at the top |
+ one more text │ one more text |
+ two more text │ two more text |
+ three more text │ three more text |
+ ^four more text │ four more text |
+ │ |
+ ~ │~ |
+ ~ │~ |
+ [No Name] [+] [No Name] [+] |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_put_in_last_displayed_line()
+ it('in last displayed line', function()
+ local screen = Screen.new(75, 10)
+ screen:attach()
+ source([[
+ autocmd CursorMoved * eval line('w$')
+ let @a = 'x'->repeat(&columns * 2 - 2)
+ eval range(&lines)->setline(1)
+ call feedkeys('G"ap')
+ ]])
+
+ screen:expect([[
+ 2 |
+ 3 |
+ 4 |
+ 5 |
+ 6 |
+ 7 |
+ 8 |
+ 9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^x |
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua
new file mode 100644
index 0000000000..8ac1141c2b
--- /dev/null
+++ b/test/functional/legacy/scroll_opt_spec.lua
@@ -0,0 +1,1193 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local exec = helpers.exec
+local feed = helpers.feed
+local assert_alive = helpers.assert_alive
+
+before_each(clear)
+
+describe('smoothscroll', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(40, 12)
+ screen:attach()
+ end)
+
+ -- oldtest: Test_CtrlE_CtrlY_stop_at_end()
+ it('disabled does not break <C-E> and <C-Y> stop at end', function()
+ exec([[
+ enew
+ call setline(1, ['one', 'two'])
+ set number
+ ]])
+ feed('<C-Y>')
+ screen:expect({any = " 1 ^one"})
+ feed('<C-E><C-E><C-E>')
+ screen:expect({any = " 2 ^two"})
+ end)
+
+ -- oldtest: Test_smoothscroll_CtrlE_CtrlY()
+ it('works with <C-E> and <C-E>', function()
+ exec([[
+ call setline(1, [ 'line one', 'word '->repeat(20), 'line three', 'long word '->repeat(7), 'line', 'line', 'line', ])
+ set smoothscroll scrolloff=5
+ :5
+ ]])
+ local s1 = [[
+ word word word word word word word word |
+ word word word word word word word word |
+ word word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ ^line |
+ line |
+ line |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s2 = [[
+ <<<d word word word word word word word |
+ word word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ ^line |
+ line |
+ line |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s3 = [[
+ <<<d word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ ^line |
+ line |
+ line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s4 = [[
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ line |
+ line |
+ ^line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s5 = [[
+ <<<d word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ line |
+ line |
+ ^line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s6 = [[
+ <<<d word word word word word word word |
+ word word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ line |
+ line |
+ ^line |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s7 = [[
+ word word word word word word word word |
+ word word word word word word word word |
+ word word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ line |
+ line |
+ ^line |
+ ~ |
+ ~ |
+ |
+ ]]
+ local s8 = [[
+ line one |
+ word word word word word word word word |
+ word word word word word word word word |
+ word word word word |
+ line three |
+ long word long word long word long word |
+ long word long word long word |
+ line |
+ line |
+ ^line |
+ ~ |
+ |
+ ]]
+ feed('<C-E>')
+ screen:expect(s1)
+ feed('<C-E>')
+ screen:expect(s2)
+ feed('<C-E>')
+ screen:expect(s3)
+ feed('<C-E>')
+ screen:expect(s4)
+ feed('<C-Y>')
+ screen:expect(s5)
+ feed('<C-Y>')
+ screen:expect(s6)
+ feed('<C-Y>')
+ screen:expect(s7)
+ feed('<C-Y>')
+ screen:expect(s8)
+ exec('set foldmethod=indent')
+ -- move the cursor so we can reuse the same dumps
+ feed('5G<C-E>')
+ screen:expect(s1)
+ feed('<C-E>')
+ screen:expect(s2)
+ feed('7G<C-Y>')
+ screen:expect(s7)
+ feed('<C-Y>')
+ screen:expect(s8)
+ end)
+
+ -- oldtest: Test_smoothscroll_multibyte()
+ it('works with multibyte characters', function()
+ screen:try_resize(40, 6)
+ exec([[
+ set scrolloff=0 smoothscroll
+ call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
+ exe "normal G35l\<C-E>k"
+ ]])
+ screen:expect([[
+ ϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛ^ϛϛϛϛϛ|
+ ϛϛϛϛϛ |
+ 222222222222222222222222222222222222 |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_number()
+ it("works 'number' and 'cpo'+=n", function()
+ exec([[
+ call setline(1, [ 'one ' .. 'word '->repeat(20), 'two ' .. 'long word '->repeat(7), 'line', 'line', 'line', ])
+ set smoothscroll scrolloff=5
+ set splitkeep=topline
+ set number cpo+=n
+ :3
+ func g:DoRel()
+ set number relativenumber scrolloff=0
+ :%del
+ call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ])
+ exe "normal 2Gzt\<C-E>"
+ endfunc
+ ]])
+ screen:expect([[
+ 1 one word word word word word word wo|
+ rd word word word word word word word wo|
+ rd word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long word |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<<word word word word word word word wo|
+ rd word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long word |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<<word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long word |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ exec('set cpo-=n')
+ screen:expect([[
+ <<< d word word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long wor|
+ d |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('<C-Y>')
+ screen:expect([[
+ <<< rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long wor|
+ d |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('<C-Y>')
+ screen:expect([[
+ 1 one word word word word word word wo|
+ rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long wor|
+ d |
+ 3 ^line |
+ 4 line |
+ 5 line |
+ ~ |
+ ~ |
+ |
+ ]])
+ exec('botright split')
+ feed('gg')
+ screen:expect([[
+ 1 one word word word word word word wo|
+ rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word@@@|
+ [No Name] [+] |
+ 1 ^one word word word word word word wo|
+ rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word lo|
+ ng word long word long word long @@@|
+ [No Name] [+] |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ 1 one word word word word word word wo|
+ rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word@@@|
+ [No Name] [+] |
+ <<< rd word word word word word word wor|
+ d word word word word word word^ |
+ 2 two long word long word long word lo|
+ ng word long word long word long wor|
+ d |
+ [No Name] [+] |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ 1 one word word word word word word wo|
+ rd word word word word word word wor|
+ d word word word word word word |
+ 2 two long word long word long word@@@|
+ [No Name] [+] |
+ <<< d word word word word word word^ |
+ 2 two long word long word long word lo|
+ ng word long word long word long wor|
+ d |
+ 3 line |
+ [No Name] [+] |
+ |
+ ]])
+ exec('close')
+ exec('call DoRel()')
+ screen:expect([[
+ 2<<<^ong text very long text very long te|
+ xt very long text very long text ver|
+ y long text very long text very long|
+ text very long text very long text |
+ 1 three |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ --No lines in buffer-- |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_list()
+ it("works with list mode", function()
+ screen:try_resize(40, 8)
+ exec([[
+ set smoothscroll scrolloff=0
+ set list
+ call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ])
+ exe "normal 2Gzt\<C-E>"
+ ]])
+ screen:expect([[
+ <<<t very long text very long text very |
+ ^long text very long text very long text |
+ very long text very long text very long |
+ text very long text- |
+ three |
+ ~ |
+ ~ |
+ |
+ ]])
+ exec('set listchars+=precedes:#')
+ screen:expect([[
+ #ext very long text very long text very |
+ ^long text very long text very long text |
+ very long text very long text very long |
+ text very long text- |
+ three |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_diff_mode()
+ it("works with diff mode", function()
+ screen:try_resize(40, 8)
+ exec([[
+ let text = 'just some text here'
+ call setline(1, text)
+ set smoothscroll
+ diffthis
+ new
+ call setline(1, text)
+ set smoothscroll
+ diffthis
+ ]])
+ screen:expect([[
+ - ^just some text here |
+ ~ |
+ ~ |
+ [No Name] [+] |
+ - just some text here |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('<C-Y>')
+ screen:expect_unchanged()
+ feed('<C-E>')
+ screen:expect_unchanged()
+ end)
+
+ -- oldtest: Test_smoothscroll_wrap_scrolloff_zero()
+ it("works with zero 'scrolloff'", function()
+ screen:try_resize(40, 8)
+ exec([[
+ call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
+ set smoothscroll scrolloff=0 display=
+ :3
+ ]])
+ screen:expect([[
+ <<<h some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ ^Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ |
+ ]])
+ feed('j')
+ screen:expect_unchanged()
+ -- moving cursor down - whole bottom line shows
+ feed('<C-E>j')
+ screen:expect_unchanged()
+ feed('G')
+ screen:expect_unchanged()
+ feed('4<C-Y>G')
+ screen:expect_unchanged()
+ -- moving cursor up right after the <<< marker - no need to show whole line
+ feed('2gj3l2k')
+ screen:expect([[
+ <<<^h some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ |
+ ]])
+ -- moving cursor up where the <<< marker is - whole top line shows
+ feed('2j02k')
+ screen:expect([[
+ ^Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ @ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_wrap_long_line()
+ it("adjusts the cursor position in a long line", function()
+ screen:try_resize(40, 6)
+ exec([[
+ call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
+ set smoothscroll scrolloff=0
+ normal 3G10|zt
+ ]])
+ -- scrolling up, cursor moves screen line down
+ screen:expect([[
+ Line with^ lots of text with lots of text|
+ with lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text with lots of te|
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<<th lot^s of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text with lots of te|
+ xt with lots of text with lots of text w|
+ |
+ ]])
+ feed('5<C-E>')
+ screen:expect([[
+ <<< lots ^of text with lots of text with |
+ lots of text with lots of text with lots|
+ of text with lots of text with lots of |
+ text with lots of text with lots of text|
+ with lots of text with lots of text wit|
+ |
+ ]])
+ -- scrolling down, cursor moves screen line up
+ feed('5<C-Y>')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text with lots of te|
+ xt with l^ots of text with lots of text w|
+ |
+ ]])
+ feed('<C-Y>')
+ screen:expect([[
+ Line with lots of text with lots of text|
+ with lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text wi^th lots of text with lots of te|
+ |
+ ]])
+ -- 'scrolloff' set to 1, scrolling up, cursor moves screen line down
+ exec('set scrolloff=1')
+ feed('10|<C-E>')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of^ text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text with lots of te|
+ xt with lots of text with lots of text w|
+ |
+ ]])
+ -- 'scrolloff' set to 1, scrolling down, cursor moves screen line up
+ feed('<C-E>gjgj<C-Y>')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text wi^th lots of text with lots of te|
+ xt with lots of text with lots of text w|
+ |
+ ]])
+ -- 'scrolloff' set to 2, scrolling up, cursor moves screen line down
+ exec('set scrolloff=2')
+ feed('10|<C-E>')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of tex^t with lots of text with lots o|
+ f text with lots of text with lots of te|
+ xt with lots of text with lots of text w|
+ |
+ ]])
+ -- 'scrolloff' set to 2, scrolling down, cursor moves screen line up
+ feed('<C-E>gj<C-Y>')
+ screen:expect_unchanged()
+ -- 'scrolloff' set to 0, move cursor down one line. Cursor should move properly,
+ -- and since this is a really long line, it will be put on top of the screen.
+ exec('set scrolloff=0')
+ feed('0j')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text end |
+ ^four |
+ |
+ ]])
+ -- Test zt/zz/zb that they work properly when a long line is above it
+ feed('zt')
+ screen:expect([[
+ ^four |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('zz')
+ screen:expect([[
+ <<<of text with lots of text with lots o|
+ f text with lots of text end |
+ ^four |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('zb')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text end |
+ ^four |
+ |
+ ]])
+ -- Repeat the step and move the cursor down again.
+ -- This time, use a shorter long line that is barely long enough to span more
+ -- than one window. Note that the cursor is at the bottom this time because
+ -- Vim prefers to do so if we are scrolling a few lines only.
+ exec("call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])")
+ -- Currently visible lines were replaced, test that the lines and cursor
+ -- are correctly displayed.
+ screen:expect_unchanged()
+ feed('3Gztj')
+ screen:expect_unchanged()
+ -- Repeat the step but this time start it when the line is smooth-scrolled by
+ -- one line. This tests that the offset calculation is still correct and
+ -- still end up scrolling down to the next line with cursor at bottom of
+ -- screen.
+ feed('3Gzt<C-E>j')
+ screen:expect([[
+ <<<th lots of text with lots of text wit|
+ h lots of text with lots of text with lo|
+ ts of text with lots of text with lots o|
+ f text with lots of text end |
+ fou^r |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_one_long_line()
+ it("scrolls correctly when moving the cursor", function()
+ screen:try_resize(40, 6)
+ exec([[
+ call setline(1, 'with lots of text '->repeat(7))
+ set smoothscroll scrolloff=0
+ ]])
+ local s1 = [[
+ ^with lots of text with lots of text with|
+ lots of text with lots of text with lot|
+ s of text with lots of text with lots of|
+ text |
+ ~ |
+ |
+ ]]
+ screen:expect(s1)
+ feed('<C-E>')
+ screen:expect([[
+ <<<ts of text with lots of text with lot|
+ ^s of text with lots of text with lots of|
+ text |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('0')
+ screen:expect(s1)
+ end)
+
+ -- oldtest: Test_smoothscroll_long_line_showbreak()
+ it("cursor is not one screen line too far down", function()
+ screen:try_resize(40, 6)
+ -- a line that spans four screen lines
+ exec("call setline(1, 'with lots of text in one line '->repeat(6))")
+ exec('set smoothscroll scrolloff=0 showbreak=+++\\ ')
+ local s1 = [[
+ ^with lots of text in one line with lots |
+ +++ of text in one line with lots of tex|
+ +++ t in one line with lots of text in o|
+ +++ ne line with lots of text in one lin|
+ +++ e with lots of text in one line |
+ |
+ ]]
+ screen:expect(s1)
+ feed('<C-E>')
+ screen:expect([[
+ +++ ^of text in one line with lots of tex|
+ +++ t in one line with lots of text in o|
+ +++ ne line with lots of text in one lin|
+ +++ e with lots of text in one line |
+ ~ |
+ |
+ ]])
+ feed('0')
+ screen:expect(s1)
+ end)
+
+ -- oldtest: Test_smoothscroll_marker_over_double_width_dump()
+ it('marker is drawn over double-width char correctly', function()
+ screen:try_resize(40, 6)
+ exec([[
+ call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
+ setlocal smoothscroll
+ ]])
+ screen:expect([[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ 口口口口口口口口口口 |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<< 口口口口口口口^口 |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_zero_width()
+ it("does not divide by zero with a narrow window", function()
+ screen:try_resize(12, 2)
+ screen:set_default_attr_ids({
+ [1] = {foreground = Screen.colors.Brown},
+ [2] = {foreground = Screen.colors.Blue1, bold = true},
+ })
+ exec([[
+ call setline(1, ['a'->repeat(100)])
+ set wrap smoothscroll number laststatus=0
+ wincmd v
+ wincmd v
+ wincmd v
+ wincmd v
+ ]])
+ screen:expect([[
+ {1: 1^ }│{1: }│{1: }│{1: }│{1: }|
+ |
+ ]])
+ feed('llllllllll<C-W>o')
+ screen:expect([[
+ {2:<<<}{1: }aa^aaaaaa|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_ins_lines()
+ it("does not unnecessarily insert lines", function()
+ screen:try_resize(40, 6)
+ exec([=[
+ set wrap smoothscroll scrolloff=0 conceallevel=2 concealcursor=nc
+ call setline(1, [
+ \'line one' .. 'with lots of text in one line '->repeat(2),
+ \'line two',
+ \'line three',
+ \'line four',
+ \'line five'
+ \])
+ ]=])
+ feed('<C-E>gjgk')
+ screen:expect([[
+ <<<lots of text in one line^ |
+ line two |
+ line three |
+ line four |
+ line five |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_cursormoved_line()
+ it("does not place the cursor in the command line", function()
+ screen:try_resize(40, 6)
+ exec([=[
+ set smoothscroll
+ call setline(1, [
+ \'',
+ \'_'->repeat(&lines * &columns),
+ \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
+ \])
+ autocmd CursorMoved * eval [line('w0'), line('w$')]
+ call search('xxx')
+ ]=])
+ screen:expect([[
+ <<<_____________________________________|
+ ________________________________________|
+ ______________________________________^xx|
+ x______________________________________x|
+ xx |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_eob()
+ it("does not scroll halfway at end of buffer", function()
+ screen:try_resize(40, 10)
+ exec([[
+ set smoothscroll
+ call setline(1, ['']->repeat(100))
+ norm G
+ ]])
+ -- does not scroll halfway when scrolling to end of buffer
+ screen:expect([[
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ ^ |
+ |
+ ]])
+ exec("call setline(92, 'a'->repeat(100))")
+ feed('<C-B>G')
+ -- cursor is not placed below window
+ screen:expect([[
+ <<<aaaaaaaaaaaaaaaaa |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ ^ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_incsearch()
+ it("does not reset skipcol when doing incremental search on the same word", function()
+ screen:try_resize(40, 8)
+ screen:set_default_attr_ids({
+ [1] = {foreground = Screen.colors.Brown},
+ [2] = {foreground = Screen.colors.Blue1, bold = true},
+ [3] = {background = Screen.colors.Yellow1},
+ [4] = {reverse = true},
+ })
+ exec([[
+ set smoothscroll number scrolloff=0 incsearch
+ call setline(1, repeat([''], 20))
+ call setline(11, repeat('a', 100))
+ call setline(14, 'bbbb')
+ ]])
+ feed('/b')
+ screen:expect([[
+ {2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+ {1: 12 } |
+ {1: 13 } |
+ {1: 14 }{4:b}{3:bbb} |
+ {1: 15 } |
+ {1: 16 } |
+ {1: 17 } |
+ /b^ |
+ ]])
+ feed('b')
+ screen:expect([[
+ {2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+ {1: 12 } |
+ {1: 13 } |
+ {1: 14 }{4:bb}{3:bb} |
+ {1: 15 } |
+ {1: 16 } |
+ {1: 17 } |
+ /bb^ |
+ ]])
+ feed('b')
+ screen:expect([[
+ {2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+ {1: 12 } |
+ {1: 13 } |
+ {1: 14 }{4:bbb}b |
+ {1: 15 } |
+ {1: 16 } |
+ {1: 17 } |
+ /bbb^ |
+ ]])
+ feed('b')
+ screen:expect([[
+ {2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+ {1: 12 } |
+ {1: 13 } |
+ {1: 14 }{4:bbbb} |
+ {1: 15 } |
+ {1: 16 } |
+ {1: 17 } |
+ /bbbb^ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_multi_skipcol()
+ it('scrolling multiple lines and stopping at non-zero skipcol', function()
+ screen:try_resize(40, 10)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue, bold = true},
+ [1] = {background = Screen.colors.Grey90},
+ })
+ exec([[
+ setlocal cursorline scrolloff=0 smoothscroll
+ call setline(1, repeat([''], 8))
+ call setline(3, repeat('a', 50))
+ call setline(4, repeat('a', 50))
+ call setline(7, 'bbb')
+ call setline(8, 'ccc')
+ redraw
+ ]])
+ screen:expect([[
+ {1:^ }|
+ |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaa |
+ |
+ |
+ bbb |
+ |
+ ]])
+ feed('3<C-E>')
+ screen:expect([[
+ {0:<<<}{1:aaaaaa^a }|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaa |
+ |
+ |
+ bbb |
+ ccc |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ feed('2<C-E>')
+ screen:expect([[
+ {0:<<<}{1:aaaaaa^a }|
+ |
+ |
+ bbb |
+ ccc |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot()
+ it('does not divide by zero in zero-width window', function()
+ screen:try_resize(40, 19)
+ screen:set_default_attr_ids({
+ [1] = {foreground = Screen.colors.Brown}; -- LineNr
+ [2] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [3] = {bold = true, reverse = true}; -- StatusLine
+ [4] = {reverse = true}; -- StatusLineNC
+ })
+ exec([[
+ silent normal yy
+ silent normal 19p
+ set cpoptions+=n
+ vsplit
+ vertical resize 0
+ set foldcolumn=1
+ set number
+ set smoothscroll
+ silent normal 20G
+ ]])
+ screen:expect([[
+ {1: }│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:@}│ |
+ {2:^@}│ |
+ {3:< }{4:[No Name] [+] }|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_cursor_top()
+ it('resets skipcol when scrolling cursor to top', function()
+ screen:try_resize(40, 12)
+ exec([[
+ set smoothscroll scrolloff=2
+ new | 11resize | wincmd j
+ call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
+ exe "norm G3\<C-E>k"
+ ]])
+ screen:expect([[
+ |
+ [No Name] |
+ line1 |
+ line2 |
+ ^line3line3line3line3line3line3line3line3|
+ line3line3line3line3line3line3line3line3|
+ line3line3line3line3 |
+ line4 |
+ ~ |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_smoothscroll_crash()
+ it('does not crash with small window and cpo+=n', function()
+ screen:try_resize(40, 12)
+ exec([[
+ 20 new
+ vsp
+ put =repeat('aaaa', 20)
+ set nu fdc=1 smoothscroll cpo+=n
+ vert resize 0
+ exe "norm! 0\<c-e>"
+ ]])
+ feed('2<C-E>')
+ assert_alive()
+ end)
+
+ it("works with virt_lines above and below", function()
+ screen:try_resize(55, 7)
+ exec([=[
+ call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(3))
+ set smoothscroll
+ let ns = nvim_create_namespace('')
+ call nvim_buf_set_extmark(0, ns, 0, 0, {'virt_lines':[[['virt_below1']]]})
+ call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_above1']]],'virt_lines_above':1})
+ call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_below2']]]})
+ call nvim_buf_set_extmark(0, ns, 2, 0, {'virt_lines':[[['virt_above2']]],'virt_lines_above':1})
+ norm ggL
+ ]=])
+ screen:expect([[
+ Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ virt_below1 |
+ virt_above1 |
+ ^Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<<e text with some text with some text with some text |
+ virt_below1 |
+ virt_above1 |
+ ^Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ virt_below2 |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ virt_below1 |
+ virt_above1 |
+ ^Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ virt_below2 |
+ virt_above2 |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ virt_above1 |
+ ^Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ virt_below2 |
+ virt_above2 |
+ Line with some text with some text with some text wi@@@|
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ ^Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ virt_below2 |
+ virt_above2 |
+ Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ <<<e text with some text with some text with some tex^t |
+ virt_below2 |
+ virt_above2 |
+ Line with some text with some text with some text with |
+ some text with some text with some text with some text |
+ ~ |
+ |
+ ]])
+ end)
+
+ it('<<< marker shows with tabline, winbar and splits', function()
+ screen:try_resize(40, 12)
+ exec([[
+ call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
+ set smoothscroll scrolloff=0
+ norm sj
+ ]])
+ screen:expect([[
+ <<<e text with some text with some text |
+ with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ [No Name] [+] |
+ <<<e text with some text with some text |
+ ^with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some te@@@|
+ [No Name] [+] |
+ |
+ ]])
+ exec('set showtabline=2')
+ feed('<C-E>')
+ screen:expect([[
+ 2+ [No Name] |
+ <<<e text with some text with some text |
+ with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some text |
+ with some text with some text |
+ [No Name] [+] |
+ <<<e text with some text with some text |
+ ^with some text with some text |
+ Line with some text with some text wi@@@|
+ [No Name] [+] |
+ |
+ ]])
+ exec('set winbar=winbar')
+ feed('<C-w>k<C-E>')
+ screen:expect([[
+ 2+ [No Name] |
+ winbar |
+ <<<e text with some text with some text |
+ ^with some text with some text |
+ Line with some text with some text with |
+ some text with some text with some te@@@|
+ [No Name] [+] |
+ winbar |
+ <<<e text with some text with some text |
+ with some text with some text |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+
+ it('works with very long line', function()
+ screen:set_default_attr_ids({
+ [1] = {foreground = Screen.colors.Brown},
+ [2] = {foreground = Screen.colors.Blue1, bold = true},
+ })
+ exec([[
+ edit test/functional/fixtures/bigfile_oneline.txt
+ setlocal smoothscroll number
+ ]])
+ screen:expect([[
+ {1: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;|
+ {1: }; 0001;<control>;Cc;0;BN;;;;;N;START|
+ {1: } OF HEADING;;;; 0002;<control>;Cc;0;|
+ {1: }BN;;;;;N;START OF TEXT;;;; 0003;<con|
+ {1: }trol>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
+ {1: }0004;<control>;Cc;0;BN;;;;;N;END OF |
+ {1: }TRANSMISSION;;;; 0005;<control>;Cc;0|
+ {1: };BN;;;;;N;ENQUIRY;;;; 0006;<control>|
+ {1: };Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; 0007;|
+ {1: }<control>;Cc;0;BN;;;;;N;BELL;;;; 000|
+ {1: }8;<control>;Cc;0;BN;;;;;N;BACKSPACE;|
+ |
+ ]])
+ feed('j')
+ screen:expect([[
+ {2:<<<}{1: }CJK COMPATIBILITY IDEOGRAPH-2F91F;Lo|
+ {1: };0;L;243AB;;;;N;;;;; 2F920;CJK COMPA|
+ {1: }TIBILITY IDEOGRAPH-2F920;Lo;0;L;7228|
+ {1: };;;;N;;;;; 2F921;CJK COMPATIBILITY I|
+ {1: }DEOGRAPH-2F921;Lo;0;L;7235;;;;N;;;;;|
+ {1: } 2F922;CJK COMPATIBILITY IDEOGRAPH-2|
+ {1: }F922;Lo;0;L;7250;;;;N;;;;; |
+ {1: 2 }^2F923;CJK COMPATIBILITY IDEOGRAPH-2F|
+ {1: }923;Lo;0;L;24608;;;;N;;;;; |
+ {1: 3 }2F924;CJK COMPATIBILITY IDEOGRAPH-2F|
+ {1: }924;Lo;0;L;7280;;;;N;;;;; |
+ |
+ ]])
+ end)
+end)
diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua
index 3f1f85cf28..25620f5262 100644
--- a/test/functional/legacy/search_spec.lua
+++ b/test/functional/legacy/search_spec.lua
@@ -290,8 +290,8 @@ describe('search cmdline', function()
-- First match
feed('/thei')
screen:expect([[
+ 3 the |
4 {inc:thei}r |
- 5 there |
/thei^ |
]])
-- Match from initial cursor position when modifying search
@@ -642,7 +642,7 @@ describe('search cmdline', function()
end)
-- oldtest: Test_incsearch_substitute_dump2()
- it('detects empty pattern properly vim-patch:8.2.2295', function()
+ it('incsearch detects empty pattern properly vim-patch:8.2.2295', function()
screen:try_resize(70, 6)
exec([[
set incsearch hlsearch scrolloff=0
@@ -675,6 +675,46 @@ describe('search cmdline', function()
:1,5s/\v|^ |
]])
end)
+
+ -- oldtest: Test_incsearch_restore_view()
+ it('incsearch restores viewport', function()
+ screen:try_resize(20, 6)
+ exec([[
+ set incsearch nohlsearch
+ setlocal scrolloff=0 smoothscroll
+ call setline(1, [join(range(25), ' '), '', '', '', '', 'xxx'])
+ call feedkeys("2\<C-E>", 't')
+ ]])
+ local s = [[
+ {tilde:<<<} 18 19 20 21 22 2|
+ ^3 24 |
+ |
+ |
+ |
+ |
+ ]]
+ screen:expect(s)
+ feed('/xx')
+ screen:expect([[
+ |
+ |
+ |
+ |
+ {inc:xx}x |
+ /xx^ |
+ ]])
+ feed('x')
+ screen:expect([[
+ |
+ |
+ |
+ |
+ {inc:xxx} |
+ /xxx^ |
+ ]])
+ feed('<Esc>')
+ screen:expect(s)
+ end)
end)
describe('Search highlight', function()
diff --git a/test/functional/legacy/search_stat_spec.lua b/test/functional/legacy/search_stat_spec.lua
index 9fcf798836..bd5ab68e5c 100644
--- a/test/functional/legacy/search_stat_spec.lua
+++ b/test/functional/legacy/search_stat_spec.lua
@@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, feed, exec, command = helpers.clear, helpers.feed, helpers.exec, helpers.command
-local poke_eventloop = helpers.poke_eventloop
describe('search stat', function()
local screen
@@ -11,8 +10,9 @@ describe('search stat', function()
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
[2] = {background = Screen.colors.Yellow}, -- Search
- [3] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey}, -- Folded
+ [3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, -- Folded
[4] = {reverse = true}, -- IncSearch, TabLineFill
+ [5] = {foreground = Screen.colors.Red}, -- WarningMsg
})
screen:attach()
end)
@@ -80,12 +80,11 @@ describe('search stat', function()
{1:~ }|
/foo [1/2] |
]])
+ -- Note: there is an intermediate state where the search stat disappears.
feed('n')
- poke_eventloop()
- screen:expect_unchanged()
+ screen:expect_unchanged(true)
feed('n')
- poke_eventloop()
- screen:expect_unchanged()
+ screen:expect_unchanged(true)
end)
-- oldtest: Test_search_stat_then_gd()
@@ -185,4 +184,57 @@ describe('search stat', function()
/abc^ |
]])
end)
+
+ -- oldtest: Test_search_stat_backwards()
+ it('when searching backwards', function()
+ screen:try_resize(60, 10)
+ exec([[
+ set shm-=S
+ call setline(1, ['test', ''])
+ ]])
+
+ feed('*')
+ screen:expect([[
+ {2:^test} |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ /\<test\> [1/1] |
+ ]])
+
+ feed('N')
+ screen:expect([[
+ {2:^test} |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ?\<test\> [1/1] |
+ ]])
+
+ command('set shm+=S')
+ feed('N')
+ -- shows "Search Hit Bottom.."
+ screen:expect([[
+ {2:^test} |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {5:search hit TOP, continuing at BOTTOM} |
+ ]])
+ end)
end)
diff --git a/test/functional/legacy/vimscript_spec.lua b/test/functional/legacy/vimscript_spec.lua
index f59a87f824..16a1080396 100644
--- a/test/functional/legacy/vimscript_spec.lua
+++ b/test/functional/legacy/vimscript_spec.lua
@@ -12,7 +12,7 @@ describe('Vim script', function()
it('Error when if/for/while/try/function is nested too deep',function()
local screen = Screen.new(80, 24)
screen:attach()
- meths.set_option('laststatus', 2)
+ meths.set_option_value('laststatus', 2, {})
exec([[
" Deep nesting of if ... endif
func Test1()
diff --git a/test/functional/legacy/visual_mode_spec.lua b/test/functional/legacy/visual_mode_spec.lua
deleted file mode 100644
index 1a08fb4c0e..0000000000
--- a/test/functional/legacy/visual_mode_spec.lua
+++ /dev/null
@@ -1,79 +0,0 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local feed = helpers.feed
-local exec = helpers.exec
-
-before_each(clear)
-
-describe('visual line mode', function()
- -- oldtest: Test_visual_block_scroll()
- it('redraws properly after scrolling with matchparen loaded and scrolloff=1', function()
- local screen = Screen.new(30, 7)
- screen:attach()
- screen:set_default_attr_ids({
- [1] = {bold = true},
- [2] = {background = Screen.colors.LightGrey},
- })
-
- exec([[
- source $VIMRUNTIME/plugin/matchparen.vim
- set scrolloff=1
- call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
- call cursor(5, 1)
- ]])
-
- feed('V<c-d><c-d>')
- screen:expect([[
- {2:{} |
- {2:}} |
- {2:{} |
- {2:f} |
- ^g |
- } |
- {1:-- VISUAL LINE --} |
- ]])
- end)
-end)
-
-describe('visual block mode', function()
- -- oldtest: Test_visual_block_with_virtualedit()
- it('shows selection correctly with virtualedit=block', function()
- local screen = Screen.new(30, 7)
- screen:set_default_attr_ids({
- [1] = {bold = true}, -- ModeMsg
- [2] = {background = Screen.colors.LightGrey}, -- Visual
- [3] = {foreground = Screen.colors.Blue, bold = true} -- NonText
- })
- screen:attach()
-
- exec([[
- call setline(1, ['aaaaaa', 'bbbb', 'cc'])
- set virtualedit=block
- normal G
- ]])
-
- feed('<C-V>gg$')
- screen:expect([[
- {2:aaaaaa}^ |
- {2:bbbb } |
- {2:cc } |
- {3:~ }|
- {3:~ }|
- {3:~ }|
- {1:-- VISUAL BLOCK --} |
- ]])
-
- feed('<Esc>gg<C-V>G$')
- screen:expect([[
- {2:aaaaaa } |
- {2:bbbb } |
- {2:cc}^ {2: } |
- {3:~ }|
- {3:~ }|
- {3:~ }|
- {1:-- VISUAL BLOCK --} |
- ]])
- end)
-end)
diff --git a/test/functional/legacy/visual_spec.lua b/test/functional/legacy/visual_spec.lua
new file mode 100644
index 0000000000..629fab5eb5
--- /dev/null
+++ b/test/functional/legacy/visual_spec.lua
@@ -0,0 +1,69 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local feed = helpers.feed
+local exec = helpers.exec
+
+before_each(clear)
+
+describe('Visual highlight', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(50, 6)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue, bold = true}, -- NonText
+ [1] = {bold = true}, -- ModeMsg
+ [2] = {background = Screen.colors.LightGrey}, -- Visual
+ })
+ screen:attach()
+ end)
+
+ -- oldtest: Test_visual_block_with_virtualedit()
+ it('shows selection correctly with virtualedit=block', function()
+ exec([[
+ call setline(1, ['aaaaaa', 'bbbb', 'cc'])
+ set virtualedit=block
+ normal G
+ ]])
+
+ feed('<C-V>gg$')
+ screen:expect([[
+ {2:aaaaaa}^ |
+ {2:bbbb } |
+ {2:cc } |
+ {0:~ }|
+ {0:~ }|
+ {1:-- VISUAL BLOCK --} |
+ ]])
+
+ feed('<Esc>gg<C-V>G$')
+ screen:expect([[
+ {2:aaaaaa } |
+ {2:bbbb } |
+ {2:cc}^ {2: } |
+ {0:~ }|
+ {0:~ }|
+ {1:-- VISUAL BLOCK --} |
+ ]])
+ end)
+
+ -- oldtest: Test_visual_hl_with_showbreak()
+ it("with cursor at end of screen line and 'showbreak'", function()
+ exec([[
+ setlocal showbreak=+
+ call setline(1, repeat('a', &columns + 10))
+ normal g$v4lo
+ ]])
+
+ screen:expect([[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^a|
+ {0:+}{2:aaaa}aaaaaa |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {1:-- VISUAL --} |
+ ]])
+ end)
+end)
diff --git a/test/functional/legacy/window_cmd_spec.lua b/test/functional/legacy/window_cmd_spec.lua
index 0e9775060d..979b46ae47 100644
--- a/test/functional/legacy/window_cmd_spec.lua
+++ b/test/functional/legacy/window_cmd_spec.lua
@@ -3,8 +3,37 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local exec = helpers.exec
local exec_lua = helpers.exec_lua
+local command = helpers.command
local feed = helpers.feed
+-- oldtest: Test_window_cmd_ls0_split_scrolling()
+it('scrolling with laststatus=0 and :botright split', function()
+ clear('--cmd', 'set ruler')
+ local screen = Screen.new(40, 10)
+ screen:set_default_attr_ids({
+ [1] = {reverse = true}, -- StatusLineNC
+ })
+ screen:attach()
+ exec([[
+ set laststatus=0
+ call setline(1, range(1, 100))
+ normal! G
+ ]])
+ command('botright split')
+ screen:expect([[
+ 97 |
+ 98 |
+ 99 |
+ 100 |
+ {1:[No Name] [+] 100,1 Bot}|
+ 97 |
+ 98 |
+ 99 |
+ ^100 |
+ 100,1 Bot |
+ ]])
+end)
+
describe('splitkeep', function()
local screen
@@ -14,6 +43,61 @@ describe('splitkeep', function()
screen:attach()
end)
+ -- oldtest: Test_splitkeep_cursor()
+ it('does not adjust cursor in window that did not change size', function()
+ screen:try_resize(75, 8)
+ -- FIXME: bottom window is different without the "vsplit | close"
+ exec([[
+ vsplit | close
+ set scrolloff=5
+ set splitkeep=screen
+ autocmd CursorMoved * wincmd p | wincmd p
+ call setline(1, range(1, 200))
+ func CursorEqualize()
+ call cursor(100, 1)
+ wincmd =
+ endfunc
+ wincmd s
+ call CursorEqualize()
+ ]])
+
+ screen:expect([[
+ 99 |
+ ^100 |
+ 101 |
+ [No Name] [+] |
+ 5 |
+ 6 |
+ [No Name] [+] |
+ |
+ ]])
+
+ feed('j')
+ screen:expect([[
+ 100 |
+ ^101 |
+ 102 |
+ [No Name] [+] |
+ 5 |
+ 6 |
+ [No Name] [+] |
+ |
+ ]])
+
+ command('set scrolloff=0')
+ feed('G')
+ screen:expect([[
+ 198 |
+ 199 |
+ ^200 |
+ [No Name] [+] |
+ 5 |
+ 6 |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+
-- oldtest: Test_splitkeep_callback()
it('does not scroll when split in callback', function()
exec([[
@@ -116,6 +200,7 @@ describe('splitkeep', function()
-- oldtest: Test_splitkeep_fold()
it('does not scroll when window has closed folds', function()
exec([[
+ set commentstring=/*%s*/
set splitkeep=screen
set foldmethod=marker
set number
@@ -224,4 +309,29 @@ describe('splitkeep', function()
|
]])
end)
+
+ -- oldtest: Test_splitkeep_skipcol()
+ it('skipcol is not reset unnecessarily and is copied to new window', function()
+ screen:try_resize(40, 12)
+ exec([[
+ set splitkeep=topline smoothscroll splitbelow scrolloff=0
+ call setline(1, 'with lots of text in one line '->repeat(6))
+ norm 2
+ wincmd s
+ ]])
+ screen:expect([[
+ <<<e line with lots of text in one line |
+ with lots of text in one line with lots |
+ of text in one line |
+ ~ |
+ [No Name] [+] |
+ <<<e line with lots of text in one line |
+ ^with lots of text in one line with lots |
+ of text in one line |
+ ~ |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index 03832978a4..d808693a9e 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -9,6 +9,7 @@ local eval = helpers.eval
local NIL = helpers.NIL
local eq = helpers.eq
local exec_lua = helpers.exec_lua
+local pcall_err = helpers.pcall_err
before_each(clear)
@@ -33,7 +34,7 @@ describe('luaeval(vim.api.…)', function()
describe('with errors', function()
it('transforms API error from nvim_buf_set_lines into lua error', function()
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
- eq({false, 'String cannot contain newlines'},
+ eq({false, "'replacement string' item contains newlines"},
funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}'))
end)
@@ -103,9 +104,9 @@ describe('luaeval(vim.api.…)', function()
eq(NIL, funcs.luaeval('vim.api.nvim__id(nil)'))
-- API strings from Blobs can work as NUL-terminated C strings
- eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ',
+ eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
exc_exec('call nvim_eval(v:_null_blob)'))
- eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ',
+ eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
exc_exec('call nvim_eval(0z)'))
eq(1, eval('nvim_eval(0z31)'))
@@ -171,9 +172,32 @@ describe('luaeval(vim.api.…)', function()
eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]]))
end)
+ it('converts booleans in positional args', function()
+ eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, false) ]])
+ eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, nil) ]])
+ eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, true) ]]))
+ eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 1) ]]))
+
+ -- this follows lua conventions for bools (not api convention for Boolean)
+ eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 0) ]]))
+ eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, {}) ]]))
+ end)
+
+ it('converts booleans in optional args', function()
+ eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=false}) ]])
+ eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {}) ]]) -- same as {output=nil}
+
+ -- API conventions (not lua conventions): zero is falsy
+ eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=0}) ]])
+
+ eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=true}) ]])
+ eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=1}) ]])
+ eq([[Invalid 'output': not a boolean]], pcall_err(exec_lua, [[ return vim.api.nvim_exec2("echo 'foobar'", {output={}}) ]]))
+ end)
+
it('errors out correctly when working with API', function()
-- Conversion errors
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Cannot convert given lua table',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]])))
-- Errors in number of arguments
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
@@ -183,32 +207,32 @@ describe('luaeval(vim.api.…)', function()
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 2 arguments',
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]])))
-- Error in argument types
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua string',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'name': Expected Lua string]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua number',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Number is not integral]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua number',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'window': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]])))
- eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
+ eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])))
-- TODO: check for errors with Tabpage argument
diff --git a/test/functional/lua/base64_spec.lua b/test/functional/lua/base64_spec.lua
new file mode 100644
index 0000000000..f0d112c23e
--- /dev/null
+++ b/test/functional/lua/base64_spec.lua
@@ -0,0 +1,105 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local exec_lua = helpers.exec_lua
+local eq = helpers.eq
+local pcall_err = helpers.pcall_err
+local matches = helpers.matches
+
+describe('vim.base64', function()
+ before_each(clear)
+
+ local function encode(s)
+ return exec_lua([[return vim.base64.encode(...)]], s)
+ end
+
+ local function decode(s)
+ return exec_lua([[return vim.base64.decode(...)]], s)
+ end
+
+ it('works', function()
+ local values = {
+ '',
+ 'Many hands make light work.',
+ [[
+ Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in
+ my purse, and nothing particular to interest me on shore, I thought I would sail about a
+ little and see the watery part of the world.
+ ]],
+ [[
+ It is a truth universally acknowledged, that a single man in possession of a good fortune,
+ must be in want of a wife.
+ ]],
+ 'Happy families are all alike; every unhappy family is unhappy in its own way.',
+ 'ЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя',
+ 'ÅÍÎÏ˝ÓÔÒÚÆ☃',
+ '𐐜 𐐔𐐇𐐝𐐀𐐡𐐇𐐓 𐐙𐐊𐐡𐐝𐐓/𐐝𐐇𐐗𐐊𐐤𐐔 𐐒𐐋𐐗 𐐒𐐌 𐐜 𐐡𐐀𐐖𐐇𐐤𐐓𐐝 𐐱𐑂 𐑄 𐐔𐐇𐐝𐐀𐐡𐐇𐐓 𐐏𐐆𐐅𐐤𐐆𐐚𐐊𐐡𐐝𐐆𐐓𐐆',
+ '👨‍👩‍👦 👨‍👩‍👧‍👦 👨‍👨‍👦 👩‍👩‍👧 👨‍👦 👨‍👧‍👦 👩‍👦 👩‍👧‍👦',
+ 'مُنَاقَشَةُ سُبُلِ اِسْتِخْدَامِ اللُّغَةِ فِي النُّظُمِ الْقَائِمَةِ وَفِيم يَخُصَّ التَّطْبِيقَاتُ الْحاسُوبِيَّةُ،',
+ [[
+ Ṱ̺̺̕o͞ ̷i̲̬͇̪͙n̝̗͕v̟̜̘̦͟o̶̙̰̠kè͚̮̺̪̹̱̤ ̖t̝͕̳̣̻̪͞h̼͓̲̦̳̘̲e͇̣̰̦̬͎ ̢̼̻̱̘h͚͎͙̜̣̲ͅi̦̲̣̰̤v̻͍e̺̭̳̪̰-m̢iͅn̖̺̞̲̯̰d̵̼̟͙̩̼̘̳ ̞̥̱̳̭r̛̗̘e͙p͠r̼̞̻̭̗e̺̠̣͟s̘͇̳͍̝͉e͉̥̯̞̲͚̬͜ǹ̬͎͎̟̖͇̤t͍̬̤͓̼̭͘ͅi̪̱n͠g̴͉ ͏͉ͅc̬̟h͡a̫̻̯͘o̫̟̖͍̙̝͉s̗̦̲.̨̹͈̣
+ ̡͓̞ͅI̗̘̦͝n͇͇͙v̮̫ok̲̫̙͈i̖͙̭̹̠̞n̡̻̮̣̺g̲͈͙̭͙̬͎ ̰t͔̦h̞̲e̢̤ ͍̬̲͖f̴̘͕̣è͖ẹ̥̩l͖͔͚i͓͚̦͠n͖͍̗͓̳̮g͍ ̨o͚̪͡f̘̣̬ ̖̘͖̟͙̮c҉͔̫͖͓͇͖ͅh̵̤̣͚͔á̗̼͕ͅo̼̣̥s̱͈̺̖̦̻͢.̛̖̞̠̫̰
+ ̗̺͖̹̯͓Ṯ̤͍̥͇͈h̲́e͏͓̼̗̙̼̣͔ ͇̜̱̠͓͍ͅN͕͠e̗̱z̘̝̜̺͙p̤̺̹͍̯͚e̠̻̠͜r̨̤͍̺̖͔̖̖d̠̟̭̬̝͟i̦͖̩͓͔̤a̠̗̬͉̙n͚͜ ̻̞̰͚ͅh̵͉i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟
+ ̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕
+ Z̮̞̠͙͔ͅḀ̗̞͈̻̗Ḷ͙͎̯̹̞͓G̻O̭̗̮
+ ]],
+ }
+
+ for _, v in ipairs(values) do
+ eq(v, decode(encode(v)))
+ end
+
+ -- Explicitly check encoded output
+ eq('VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=', encode('The quick brown fox jumps over the lazy dog\n'))
+
+ -- Test vectors from rfc4648
+ local rfc4648 = {
+ { '', '' },
+ { 'f', 'Zg==', },
+ { 'fo', 'Zm8=' },
+ { 'foo', 'Zm9v' },
+ { 'foob', 'Zm9vYg==' },
+ { 'fooba', 'Zm9vYmE=' },
+ { 'foobar', 'Zm9vYmFy' },
+ }
+
+ for _, v in ipairs(rfc4648) do
+ local input = v[1]
+ local output = v[2]
+ eq(output, encode(input))
+ eq(input, decode(output))
+ end
+ end)
+
+ it('detects invalid input', function()
+ local invalid = {
+ 'A',
+ 'AA',
+ 'AAA',
+ 'A..A',
+ 'AA=A',
+ 'AA/=',
+ 'A/==',
+ 'A===',
+ '====',
+ 'Zm9vYmFyZm9vYmFyA..A',
+ 'Zm9vYmFyZm9vYmFyAA=A',
+ 'Zm9vYmFyZm9vYmFyAA/=',
+ 'Zm9vYmFyZm9vYmFyA/==',
+ 'Zm9vYmFyZm9vYmFyA===',
+ 'A..AZm9vYmFyZm9vYmFy',
+ 'Zm9vYmFyZm9vAA=A',
+ 'Zm9vYmFyZm9vAA/=',
+ 'Zm9vYmFyZm9vA/==',
+ 'Zm9vYmFyZm9vA===',
+ }
+
+ for _, v in ipairs(invalid) do
+ eq('Invalid input', pcall_err(decode, v))
+ end
+
+ eq('Expected 1 argument', pcall_err(encode))
+ eq('Expected 1 argument', pcall_err(decode))
+ matches('expected string', pcall_err(encode, 42))
+ matches('expected string', pcall_err(decode, 42))
+ end)
+end)
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 2fd44b8b5f..51e4548edb 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -1,6 +1,6 @@
-- Test suite for testing interactions with API bindings
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local command = helpers.command
local meths = helpers.meths
@@ -317,7 +317,18 @@ describe('lua buffer event callbacks: on_lines', function()
feed('1G0')
feed('P')
eq(meths.get_var('linesev'), { "lines", 1, 6, 0, 3, 3, 9 })
+ end)
+ it('calling nvim_buf_call() from callback does not cause Normal mode CTRL-A to misbehave #16729', function()
+ exec_lua([[
+ vim.api.nvim_buf_attach(0, false, {
+ on_lines = function(...)
+ vim.api.nvim_buf_call(0, function() end)
+ end,
+ })
+ ]])
+ feed('itest123<Esc><C-A>')
+ eq('test124', meths.get_current_line())
end)
end)
@@ -404,7 +415,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines', function()
local check_events = setup_eventcheck(verify, origlines)
- -- meths.buf_set_option(0, 'autoindent', true)
+ -- meths.set_option_value('autoindent', true, {})
feed 'Go'
check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 1 };
@@ -417,7 +428,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines with autoindent', function()
local check_events = setup_eventcheck(verify, origlines)
- meths.buf_set_option(0, 'autoindent', true)
+ meths.set_option_value('autoindent', true, {})
feed 'Go'
check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 5 };
@@ -451,8 +462,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('continuing comments with fo=or', function()
local check_events = setup_eventcheck(verify, {'// Comment'})
- meths.buf_set_option(0, 'formatoptions', 'ro')
- meths.buf_set_option(0, 'filetype', 'c')
+ meths.set_option_value('formatoptions', 'ro', {})
+ meths.set_option_value('filetype', 'c', {})
feed 'A<CR>'
check_events {
{ "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 };
@@ -592,7 +603,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('inccomand=nosplit and substitute', function()
local check_events = setup_eventcheck(verify,
{"abcde", "12345"})
- meths.set_option('inccommand', 'nosplit')
+ meths.set_option_value('inccommand', 'nosplit', {})
-- linewise substitute
feed(':%s/bcd/')
@@ -743,7 +754,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
write_file("Xtest-reload", dedent [[
old line 1
old line 2]])
- lfs.touch("Xtest-reload", os.time() - 10)
+ local atime = os.time() - 10
+ luv.fs_utime("Xtest-reload", atime, atime)
command "e Xtest-reload"
command "set autoread"
@@ -814,53 +826,53 @@ describe('lua: nvim_buf_attach on_bytes', function()
feed("<esc>u")
check_events {
- { "test1", "bytes", 1, 8, 0, 0, 0, 0, 1, 1, 0, 4, 4 },
- { "test1", "bytes", 1, 8, 0, 0, 0, 0, 4, 4, 0, 0, 0 }
+ { "test1", "bytes", 1, 9, 0, 0, 0, 0, 1, 1, 0, 4, 4 },
+ { "test1", "bytes", 1, 9, 0, 0, 0, 0, 4, 4, 0, 0, 0 }
}
-- in REPLACE mode
feed("R<tab><tab>")
check_events {
- { "test1", "bytes", 1, 9, 0, 0, 0, 0, 1, 1, 0, 1, 1 },
- { "test1", "bytes", 1, 10, 0, 1, 1, 0, 0, 0, 0, 1, 1 },
- { "test1", "bytes", 1, 11, 0, 2, 2, 0, 1, 1, 0, 1, 1 },
- { "test1", "bytes", 1, 12, 0, 3, 3, 0, 0, 0, 0, 1, 1 },
- { "test1", "bytes", 1, 13, 0, 0, 0, 0, 4, 4, 0, 1, 1 },
+ { "test1", "bytes", 1, 10, 0, 0, 0, 0, 1, 1, 0, 1, 1 },
+ { "test1", "bytes", 1, 11, 0, 1, 1, 0, 0, 0, 0, 1, 1 },
+ { "test1", "bytes", 1, 12, 0, 2, 2, 0, 1, 1, 0, 1, 1 },
+ { "test1", "bytes", 1, 13, 0, 3, 3, 0, 0, 0, 0, 1, 1 },
+ { "test1", "bytes", 1, 14, 0, 0, 0, 0, 4, 4, 0, 1, 1 },
}
feed("<esc>u")
check_events {
- { "test1", "bytes", 1, 14, 0, 0, 0, 0, 1, 1, 0, 4, 4 },
- { "test1", "bytes", 1, 14, 0, 2, 2, 0, 2, 2, 0, 1, 1 },
- { "test1", "bytes", 1, 14, 0, 0, 0, 0, 2, 2, 0, 1, 1 }
+ { "test1", "bytes", 1, 16, 0, 0, 0, 0, 1, 1, 0, 4, 4 },
+ { "test1", "bytes", 1, 16, 0, 2, 2, 0, 2, 2, 0, 1, 1 },
+ { "test1", "bytes", 1, 16, 0, 0, 0, 0, 2, 2, 0, 1, 1 }
}
-- in VISUALREPLACE mode
feed("gR<tab><tab>")
check_events {
- { "test1", "bytes", 1, 15, 0, 0, 0, 0, 1, 1, 0, 1, 1 };
- { "test1", "bytes", 1, 16, 0, 1, 1, 0, 1, 1, 0, 1, 1 };
- { "test1", "bytes", 1, 17, 0, 2, 2, 0, 1, 1, 0, 1, 1 };
- { "test1", "bytes", 1, 18, 0, 3, 3, 0, 1, 1, 0, 1, 1 };
- { "test1", "bytes", 1, 19, 0, 3, 3, 0, 1, 1, 0, 0, 0 };
- { "test1", "bytes", 1, 20, 0, 3, 3, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 22, 0, 2, 2, 0, 1, 1, 0, 0, 0 };
- { "test1", "bytes", 1, 23, 0, 2, 2, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 25, 0, 1, 1, 0, 1, 1, 0, 0, 0 };
- { "test1", "bytes", 1, 26, 0, 1, 1, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 28, 0, 0, 0, 0, 1, 1, 0, 0, 0 };
- { "test1", "bytes", 1, 29, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 31, 0, 0, 0, 0, 4, 4, 0, 1, 1 };
+ { "test1", "bytes", 1, 17, 0, 0, 0, 0, 1, 1, 0, 1, 1 };
+ { "test1", "bytes", 1, 18, 0, 1, 1, 0, 1, 1, 0, 1, 1 };
+ { "test1", "bytes", 1, 19, 0, 2, 2, 0, 1, 1, 0, 1, 1 };
+ { "test1", "bytes", 1, 20, 0, 3, 3, 0, 1, 1, 0, 1, 1 };
+ { "test1", "bytes", 1, 21, 0, 3, 3, 0, 1, 1, 0, 0, 0 };
+ { "test1", "bytes", 1, 22, 0, 3, 3, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 24, 0, 2, 2, 0, 1, 1, 0, 0, 0 };
+ { "test1", "bytes", 1, 25, 0, 2, 2, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 27, 0, 1, 1, 0, 1, 1, 0, 0, 0 };
+ { "test1", "bytes", 1, 28, 0, 1, 1, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 30, 0, 0, 0, 0, 1, 1, 0, 0, 0 };
+ { "test1", "bytes", 1, 31, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 33, 0, 0, 0, 0, 4, 4, 0, 1, 1 };
}
-- inserting tab after other tabs
command("set sw=4")
feed("<esc>0a<tab>")
check_events {
- { "test1", "bytes", 1, 32, 0, 1, 1, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 33, 0, 2, 2, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 34, 0, 3, 3, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 35, 0, 4, 4, 0, 0, 0, 0, 1, 1 };
- { "test1", "bytes", 1, 36, 0, 1, 1, 0, 4, 4, 0, 1, 1 };
+ { "test1", "bytes", 1, 34, 0, 1, 1, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 35, 0, 2, 2, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 36, 0, 3, 3, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 37, 0, 4, 4, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 38, 0, 1, 1, 0, 4, 4, 0, 1, 1 };
}
end)
@@ -986,7 +998,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it("virtual edit", function ()
local check_events = setup_eventcheck(verify, { "", " " })
- meths.set_option("virtualedit", "all")
+ meths.set_option_value('virtualedit', "all", {})
feed [[<Right><Right>iab<ESC>]]
@@ -1152,12 +1164,36 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it("works with accepting spell suggestions", function()
- local check_events = setup_eventcheck(verify, {"hallo"})
+ local check_events = setup_eventcheck(verify, {"hallo world", "hallo world"})
feed("gg0z=4<cr><cr>") -- accepts 'Hello'
check_events {
{ "test1", "bytes", 1, 3, 0, 0, 0, 0, 2, 2, 0, 2, 2 };
}
+
+ command("spellrepall") -- replaces whole words
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 12, 0, 5, 5, 0, 5, 5 };
+ }
+ end)
+
+ it('works with :diffput and :diffget', function()
+ local check_events = setup_eventcheck(verify, {"AAA"})
+ command('diffthis')
+ command('new')
+ command('diffthis')
+ meths.buf_set_lines(0, 0, -1, true, {"AAA", "BBB"})
+ feed('G')
+ command('diffput')
+ check_events {
+ { "test1", "bytes", 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 4 };
+ }
+ meths.buf_set_lines(0, 0, -1, true, {"AAA", "CCC"})
+ feed('<C-w>pG')
+ command('diffget')
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 4, 1, 0, 4, 1, 0, 4 };
+ }
end)
local function test_lockmarks(mode)
diff --git a/test/functional/lua/command_line_completion_spec.lua b/test/functional/lua/command_line_completion_spec.lua
index 3a5966755e..177e077f4a 100644
--- a/test/functional/lua/command_line_completion_spec.lua
+++ b/test/functional/lua/command_line_completion_spec.lua
@@ -5,7 +5,7 @@ local eq = helpers.eq
local exec_lua = helpers.exec_lua
local get_completions = function(input, env)
- return exec_lua("return {vim._expand_pat(...)}", '^' .. input, env)
+ return exec_lua("return {vim._expand_pat(...)}", input, env)
end
local get_compl_parts = function(parts)
@@ -31,14 +31,12 @@ describe('nlua_expand_pat', function()
eq(
{{
'nvim_buf_set_lines',
- 'nvim_buf_set_option'
}, 8
},
get_completions('vim.api.nvim_buf_', {
vim = {
api = {
nvim_buf_set_lines = true,
- nvim_buf_set_option = true,
nvim_win_doesnt_match = true,
},
other_key = true,
@@ -68,14 +66,12 @@ describe('nlua_expand_pat', function()
eq(
{{
'nvim_buf_set_lines',
- 'nvim_buf_set_option'
}, 11
},
get_completions('vim["api"].nvim_buf_', {
vim = {
api = {
nvim_buf_set_lines = true,
- nvim_buf_set_option = true,
nvim_win_doesnt_match = true,
},
other_key = true,
@@ -88,7 +84,6 @@ describe('nlua_expand_pat', function()
eq(
{{
'nvim_buf_set_lines',
- 'nvim_buf_set_option'
}, 21
},
get_completions('vim["nested"]["api"].nvim_buf_', {
@@ -96,7 +91,6 @@ describe('nlua_expand_pat', function()
nested = {
api = {
nvim_buf_set_lines = true,
- nvim_buf_set_option = true,
nvim_win_doesnt_match = true,
},
},
@@ -107,9 +101,12 @@ describe('nlua_expand_pat', function()
end)
it('should work with lazy submodules of "vim" global', function()
- eq({{ 'inspect' }, 4 },
+ eq({{ 'inspect', 'inspect_pos' }, 4 },
get_completions('vim.inspec'))
+ eq({{ 'treesitter' }, 4 },
+ get_completions('vim.treesi'))
+
eq({{ 'set' }, 11 },
get_completions('vim.keymap.se'))
end)
@@ -118,7 +115,6 @@ describe('nlua_expand_pat', function()
eq(
{{
'nvim_buf_set_lines',
- 'nvim_buf_set_option'
}, 12
},
get_completions('vim[MY_VAR].nvim_buf_', {
@@ -126,7 +122,6 @@ describe('nlua_expand_pat', function()
vim = {
api = {
nvim_buf_set_lines = true,
- nvim_buf_set_option = true,
nvim_win_doesnt_match = true,
},
other_key = true,
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua
index b8346df290..fca619348d 100644
--- a/test/functional/lua/commands_spec.lua
+++ b/test/functional/lua/commands_spec.lua
@@ -7,7 +7,10 @@ local NIL = helpers.NIL
local eval = helpers.eval
local feed = helpers.feed
local clear = helpers.clear
+local matches = helpers.matches
local meths = helpers.meths
+local exec_lua = helpers.exec_lua
+local exec_capture = helpers.exec_capture
local funcs = helpers.funcs
local source = helpers.source
local dedent = helpers.dedent
@@ -15,7 +18,6 @@ local command = helpers.command
local exc_exec = helpers.exc_exec
local pcall_err = helpers.pcall_err
local write_file = helpers.write_file
-local exec_capture = helpers.exec_capture
local curbufmeths = helpers.curbufmeths
local remove_trace = helpers.remove_trace
@@ -26,22 +28,27 @@ describe(':lua command', function()
eq('', exec_capture(
'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false))
- source(dedent([[
+ source([[
lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
- EOF]]))
+ EOF]])
eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false))
- source(dedent([[
+ source([[
lua << EOF
- vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]))
+ vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false))
- source(dedent([[
+ source([[
lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
- EOF]]))
+ EOF]])
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
+ matches('.*Vim%(lua%):E15: Invalid expression: .*', pcall_err(source, [[
+ lua << eval EOF
+ {}
+ EOF
+ ]]))
end)
it('throws catchable errors', function()
eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
@@ -142,22 +149,30 @@ describe(':lua command', function()
]]}
end)
- it('Can print results of =expr', function()
- helpers.exec_lua("x = 5")
- eq("5", helpers.exec_capture(':lua =x'))
- helpers.exec_lua("function x() return 'hello' end")
- eq([["hello"]], helpers.exec_capture(':lua = x()'))
- helpers.exec_lua("x = {a = 1, b = 2}")
- eq("{\n a = 1,\n b = 2\n}", helpers.exec_capture(':lua =x'))
- helpers.exec_lua([[function x(success)
+ it('prints result of =expr', function()
+ exec_lua("x = 5")
+ eq("5", exec_capture(':lua =x'))
+ eq("5", exec_capture('=x'))
+ exec_lua("function x() return 'hello' end")
+ eq('hello', exec_capture(':lua = x()'))
+ exec_lua("x = {a = 1, b = 2}")
+ eq("{\n a = 1,\n b = 2\n}", exec_capture(':lua =x'))
+ exec_lua([[function x(success)
if success then
return true, "Return value"
else
return false, nil, "Error message"
end
end]])
- eq([[true "Return value"]], helpers.exec_capture(':lua =x(true)'))
- eq([[false nil "Error message"]], helpers.exec_capture(':lua =x(false)'))
+ eq(dedent[[
+ true
+ Return value]],
+ exec_capture(':lua =x(true)'))
+ eq(dedent[[
+ false
+ nil
+ Error message]],
+ exec_capture('=x(false)'))
end)
end)
@@ -183,7 +198,7 @@ describe(':luado command', function()
end)
it('works correctly when changing lines out of range', function()
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
- eq('Vim(luado):E322: line number out of range: 1 past the end',
+ eq('Vim(luado):E322: Line number out of range: 1 past the end',
pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr'))
eq({''}, curbufmeths.get_lines(0, -1, false))
end)
@@ -199,7 +214,7 @@ describe(':luado command', function()
end)
it('fails in sandbox when needed', function()
curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"})
- eq('Vim(luado):E48: Not allowed in sandbox',
+ eq('Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1',
pcall_err(command, 'sandbox luado runs = (runs or 0) + 1'))
eq(NIL, funcs.luaeval('runs'))
end)
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index d364986ad7..f061fac50a 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -79,13 +79,10 @@ describe('vim.diagnostic', function()
]])
end)
- after_each(function()
- clear()
- end)
-
it('creates highlight groups', function()
command('runtime plugin/diagnostic.vim')
eq({
+ 'DiagnosticDeprecated',
'DiagnosticError',
'DiagnosticFloatingError',
'DiagnosticFloatingHint',
@@ -105,6 +102,7 @@ describe('vim.diagnostic', function()
'DiagnosticUnderlineInfo',
'DiagnosticUnderlineOk',
'DiagnosticUnderlineWarn',
+ 'DiagnosticUnnecessary',
'DiagnosticVirtualTextError',
'DiagnosticVirtualTextHint',
'DiagnosticVirtualTextInfo',
@@ -183,6 +181,18 @@ describe('vim.diagnostic', function()
eq(0, #diagnostics)
end)
+ it('always returns a copy of diagnostic tables', function()
+ local result = exec_lua [[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Diagnostic #1', 1, 1, 1, 1),
+ })
+ local diag = vim.diagnostic.get()
+ diag[1].col = 10000
+ return vim.diagnostic.get()[1].col == 10000
+ ]]
+ eq(result, false)
+ end)
+
it('resolves buffer number 0 to the current buffer', function()
eq(2, exec_lua [[
vim.api.nvim_set_current_buf(diagnostic_bufnr)
@@ -862,7 +872,7 @@ end)
]])
end)
- it('returns only requested diagnostics when severity is supplied', function()
+ it('returns only requested diagnostics when severity range is supplied', function()
eq({2, 3, 2}, exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
make_error("Error 1", 1, 1, 1, 5),
@@ -884,6 +894,28 @@ end)
]])
end)
+ it('returns only requested diagnostics when severities are supplied', function()
+ eq({1, 1, 2}, exec_lua [[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 1, 1, 2, 3),
+ make_info("Ignored information", 1, 1, 2, 3),
+ make_hint("Here's a hint", 1, 1, 2, 3),
+ })
+
+ return {
+ #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.WARN} }),
+ #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.ERROR} }),
+ #vim.diagnostic.get(diagnostic_bufnr, {
+ severity = {
+ vim.diagnostic.severity.INFO,
+ vim.diagnostic.severity.WARN,
+ }
+ }),
+ }
+ ]])
+ end)
+
it('allows filtering by line', function()
eq(1, exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
@@ -1044,7 +1076,7 @@ end)
local virt_text = get_virt_text_extmarks(diagnostic_ns)[1][4].virt_text
local virt_texts = {}
- for i = 2, #virt_text do
+ for i = 2, #virt_text - 1 do
table.insert(virt_texts, (string.gsub(virt_text[i][2], "DiagnosticVirtualText", "")))
end
@@ -1088,7 +1120,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]]
eq(' source x: Some error', result)
@@ -1103,7 +1135,7 @@ end)
}, diagnostic_ns)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]]
eq(' Some error', result)
@@ -1123,7 +1155,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = {extmarks[1][4].virt_text[2][1], extmarks[2][4].virt_text[2][1]}
+ local virt_text = {extmarks[1][4].virt_text[3][1], extmarks[2][4].virt_text[3][1]}
return virt_text
]]
eq(' source x: Some error', result[1])
@@ -1153,8 +1185,8 @@ end)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
- eq(" 👀 Warning", result[1][2][1])
- eq(" 🔥 Error", result[2][2][1])
+ eq(" 👀 Warning", result[1][3][1])
+ eq(" 🔥 Error", result[2][3][1])
end)
it('includes source for formatted diagnostics', function()
@@ -1181,8 +1213,48 @@ end)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
- eq(" some_linter: 👀 Warning", result[1][2][1])
- eq(" another_linter: 🔥 Error", result[2][2][1])
+ eq(" some_linter: 👀 Warning", result[1][3][1])
+ eq(" another_linter: 🔥 Error", result[2][3][1])
+ end)
+
+ it('can add a prefix to virtual text', function()
+ eq('E Some error', exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = 'E',
+ suffix = '',
+ }
+ })
+
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
+ local prefix = extmarks[1][4].virt_text[2][1]
+ local message = extmarks[1][4].virt_text[3][1]
+ return prefix .. message
+ ]])
+
+ eq('[(1/1) err-code] Some error', exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0, nil, 'err-code'),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = function(diag, i, total) return string.format('[(%d/%d) %s]', i, total, diag.code) end,
+ suffix = '',
+ }
+ })
+
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
+ local prefix = extmarks[1][4].virt_text[2][1]
+ local message = extmarks[1][4].virt_text[3][1]
+ return prefix .. message
+ ]])
end)
it('can add a suffix to virtual text', function()
@@ -1200,7 +1272,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]])
@@ -1218,7 +1290,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]])
end)
diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua
index 18b13a8959..3a37b18cd1 100644
--- a/test/functional/lua/ffi_spec.lua
+++ b/test/functional/lua/ffi_spec.lua
@@ -25,7 +25,6 @@ describe('ffi.cdef', function()
local ffi = require('ffi')
ffi.cdef[[
- typedef unsigned char char_u;
typedef struct window_S win_T;
typedef struct {} stl_hlrec_t;
typedef struct {} StlClickRecord;
@@ -63,5 +62,14 @@ describe('ffi.cdef', function()
nil
)
]=])
+
+ -- Check that extern symbols are exported and accessible
+ eq(true, exec_lua[[
+ local ffi = require('ffi')
+
+ ffi.cdef('uint64_t display_tick;')
+
+ return ffi.C.display_tick >= 0
+ ]])
end)
end)
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index 2a7be53164..b3d95e1c7f 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -94,11 +94,46 @@ describe('vim.filetype', function()
return vim.filetype.match({ buf = 0 })
]])
end)
+
+ it('works with contents #22180', function()
+ eq('sh', exec_lua [[
+ -- Needs to be set so detect#sh doesn't fail
+ vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
+ return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })
+ ]])
+ end)
+
+ it('considers extension mappings when matching from hashbang', function()
+ eq('fooscript', exec_lua [[
+ vim.filetype.add({
+ extension = {
+ foo = 'fooscript',
+ }
+ })
+ return vim.filetype.match({ contents = { '#!/usr/bin/env foo' } })
+ ]])
+ end)
+
+ it('can get default option values for filetypes via vim.filetype.get_option()', function()
+ command('filetype plugin on')
+
+ for ft, opts in pairs {
+ lua = { commentstring = '-- %s' },
+ vim = { commentstring = '"%s' },
+ man = { tagfunc = 'v:lua.require\'man\'.goto_tag' },
+ xml = { formatexpr = 'xmlformat#Format()' }
+ } do
+ for option, value in pairs(opts) do
+ eq(value, exec_lua([[ return vim.filetype.get_option(...) ]], ft, option))
+ end
+ end
+
+ end)
end)
describe('filetype.lua', function()
it('does not override user autocommands that set filetype #20333', function()
clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}})
- eq('notmarkdown', meths.buf_get_option(0, 'filetype'))
+ eq('notmarkdown', meths.get_option_value('filetype', {}))
end)
end)
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index 642d36f63a..6bdb9ed79d 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local uv = require('luv')
local clear = helpers.clear
local exec_lua = helpers.exec_lua
@@ -8,8 +8,10 @@ local mkdir_p = helpers.mkdir_p
local rmdir = helpers.rmdir
local nvim_dir = helpers.nvim_dir
local test_build_dir = helpers.test_build_dir
+local test_source_path = helpers.test_source_path
local nvim_prog = helpers.nvim_prog
local is_os = helpers.is_os
+local mkdir = helpers.mkdir
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
@@ -132,10 +134,10 @@ describe('vim.fs', function()
describe('dir()', function()
before_each(function()
- lfs.mkdir('testd')
- lfs.mkdir('testd/a')
- lfs.mkdir('testd/a/b')
- lfs.mkdir('testd/a/b/c')
+ mkdir('testd')
+ mkdir('testd/a')
+ mkdir('testd/a/b')
+ mkdir('testd/a/b/c')
end)
after_each(function()
@@ -222,7 +224,7 @@ describe('vim.fs', function()
describe('find()', function()
it('works', function()
- eq({test_build_dir}, exec_lua([[
+ eq({test_build_dir .. "/build"}, exec_lua([[
local dir = ...
return vim.fs.find('build', { path = dir, upward = true, type = 'directory' })
]], nvim_dir))
@@ -238,7 +240,7 @@ describe('vim.fs', function()
end)
it('accepts predicate as names', function()
- eq({test_build_dir}, exec_lua([[
+ eq({test_build_dir .. "/build"}, exec_lua([[
local dir = ...
local opts = { path = dir, upward = true, type = 'directory' }
return vim.fs.find(function(x) return x == 'build' end, opts)
@@ -252,6 +254,27 @@ describe('vim.fs', function()
local opts = { path = dir, upward = true, type = 'directory' }
return vim.fs.find(function(x) return x == 'no-match' end, opts)
]], nvim_dir))
+ eq(
+ exec_lua([[
+ local dir = ...
+ return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true))
+ ]], test_source_path),
+ exec_lua([[
+ local dir = ...
+ local opts = { path = dir .. "/contrib", limit = math.huge }
+ return vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts))
+ ]], test_source_path))
+ end)
+ end)
+
+ describe('joinpath()', function()
+ it('works', function()
+ eq('foo/bar/baz', exec_lua([[
+ return vim.fs.joinpath('foo', 'bar', 'baz')
+ ]], nvim_dir))
+ eq('foo/bar/baz', exec_lua([[
+ return vim.fs.joinpath('foo', '/bar/', '/baz')
+ ]], nvim_dir))
end)
end)
@@ -259,11 +282,19 @@ describe('vim.fs', function()
it('works with backward slashes', function()
eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]])
end)
+ it('removes trailing /', function()
+ eq('/home/user', exec_lua [[ return vim.fs.normalize('/home/user/') ]])
+ end)
+ it('works with /', function()
+ eq('/', exec_lua [[ return vim.fs.normalize('/') ]])
+ end)
it('works with ~', function()
- if is_os('win') then
- pending([[$HOME does not exist on Windows ¯\_(ツ)_/¯]])
- end
- eq(os.getenv('HOME') .. '/src/foo', exec_lua [[ return vim.fs.normalize('~/src/foo') ]])
+ eq(
+ exec_lua([[
+ local home = ...
+ return home .. '/src/foo'
+ ]], vim.fs.normalize(uv.os_homedir())),
+ exec_lua [[ return vim.fs.normalize('~/src/foo') ]])
end)
it('works with environment variables', function()
local xdg_config_home = test_build_dir .. '/.config'
@@ -272,5 +303,10 @@ describe('vim.fs', function()
return vim.fs.normalize('$XDG_CONFIG_HOME/nvim')
]], xdg_config_home))
end)
+ if is_os('win') then
+ it('Last slash is not truncated from root drive', function()
+ eq('C:/', exec_lua [[ return vim.fs.normalize('C:/') ]])
+ end)
+ end
end)
end)
diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua
index b396e2ba30..ef1b8ebf3f 100644
--- a/test/functional/lua/help_spec.lua
+++ b/test/functional/lua/help_spec.lua
@@ -8,6 +8,8 @@ local exec_lua = helpers.exec_lua
local eq = helpers.eq
local ok = helpers.ok
+if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then return end
+
describe(':help docs', function()
before_each(clear)
it('validate', function()
@@ -19,11 +21,12 @@ describe(':help docs', function()
local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]])
-- Check that we actually found helpfiles.
ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles)
+
+ eq({}, rv.parse_errors, 'no parse errors')
+ eq(0, rv.err_count, 'no parse errors')
eq({}, rv.invalid_links, 'invalid tags in :help docs')
eq({}, rv.invalid_urls, 'invalid URLs in :help docs')
- -- Check that parse errors did not increase wildly.
- -- TODO: Fix all parse errors in :help files.
- ok(rv.err_count < 250, '<250 parse errors', rv.err_count)
+ eq({}, rv.invalid_spelling, 'invalid spelling in :help docs (see spell_dict in scripts/gen_help_html.lua)')
end)
it('gen_help_html.lua generates HTML', function()
diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua
index 60d0ed5017..8e499f1e79 100644
--- a/test/functional/lua/highlight_spec.lua
+++ b/test/functional/lua/highlight_spec.lua
@@ -24,7 +24,7 @@ describe('vim.highlight.on_yank', function()
it('does not close timer twice', function()
exec_lua([[
vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y"}})
- vim.loop.sleep(10)
+ vim.uv.sleep(10)
vim.schedule(function()
vim.highlight.on_yank({timeout = 0, on_macro = true, event = {operator = "y"}})
end)
diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua
index 5e488bb082..c369956e56 100644
--- a/test/functional/lua/inspector_spec.lua
+++ b/test/functional/lua/inspector_spec.lua
@@ -12,19 +12,62 @@ describe('vim.inspect_pos', function()
it('it returns items', function()
local ret = exec_lua([[
local buf = vim.api.nvim_create_buf(true, false)
+ local buf1 = vim.api.nvim_create_buf(true, false)
+ local ns1 = vim.api.nvim_create_namespace("ns1")
+ local ns2 = vim.api.nvim_create_namespace("")
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
- vim.api.nvim_buf_set_option(buf, "filetype", "lua")
+ vim.api.nvim_buf_set_lines(buf1, 0, -1, false, {"--commentline"})
+ vim.bo[buf].filetype = 'lua'
+ vim.bo[buf1].filetype = 'lua'
+ vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" })
+ vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" })
vim.cmd("syntax on")
- return {buf, vim.inspect_pos(0, 0, 10)}
+ return {buf, vim.inspect_pos(0, 0, 10), vim.inspect_pos(buf1, 0, 10).syntax }
]])
- local buf, items = unpack(ret)
+ local buf, items, other_buf_syntax = unpack(ret)
+
eq('', eval('v:errmsg'))
eq({
buffer = buf,
col = 10,
row = 0,
- extmarks = {},
+ extmarks = {
+ {
+ col = 10,
+ end_col = 11,
+ end_row = 0,
+ id = 1,
+ ns = 'ns1',
+ ns_id = 1,
+ opts = {
+ hl_eol = false,
+ hl_group = 'Normal',
+ hl_group_link = 'Normal',
+ ns_id = 1,
+ priority = 4096,
+ right_gravity = true
+ },
+ row = 0
+ },
+ {
+ col = 10,
+ end_col = 11,
+ end_row = 0,
+ id = 1,
+ ns = '',
+ ns_id = 2,
+ opts = {
+ hl_eol = false,
+ hl_group = 'Normal',
+ hl_group_link = 'Normal',
+ ns_id = 2,
+ priority = 4096,
+ right_gravity = true
+ },
+ row = 0
+ }
+ },
treesitter = {},
semantic_tokens = {},
syntax = {
@@ -34,6 +77,13 @@ describe('vim.inspect_pos', function()
},
},
}, items)
+
+ eq({
+ {
+ hl_group = 'luaComment',
+ hl_group_link = 'Comment',
+ },
+ }, other_buf_syntax)
end)
end)
@@ -47,7 +97,7 @@ describe('vim.show_pos', function()
local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
- vim.api.nvim_buf_set_option(buf, "filetype", "lua")
+ vim.bo[buf].filetype = 'lua'
vim.cmd("syntax on")
return {buf, vim.show_pos(0, 0, 10)}
]])
diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua
new file mode 100644
index 0000000000..ffa28e7b11
--- /dev/null
+++ b/test/functional/lua/iter_spec.lua
@@ -0,0 +1,402 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+local matches = helpers.matches
+local pcall_err = helpers.pcall_err
+
+describe('vim.iter', function()
+ it('new() on iterable class instance', function()
+ local rb = vim.ringbuf(3)
+ rb:push("a")
+ rb:push("b")
+
+ local it = vim.iter(rb)
+ eq({"a", "b"}, it:totable())
+ end)
+
+ it('filter()', function()
+ local function odd(v)
+ return v % 2 ~= 0
+ end
+
+ local t = { 1, 2, 3, 4, 5 }
+ eq({ 1, 3, 5 }, vim.iter(t):filter(odd):totable())
+ eq({ 2, 4 }, vim.iter(t):filter(function(v) return not odd(v) end):totable())
+ eq({}, vim.iter(t):filter(function(v) return v > 5 end):totable())
+
+ do
+ local it = vim.iter(ipairs(t))
+ it:filter(function(i, v) return i > 1 and v < 5 end)
+ it:map(function(_, v) return v * 2 end)
+ eq({ 4, 6, 8 }, it:totable())
+ end
+
+ local it = vim.iter(string.gmatch('the quick brown fox', '%w+'))
+ eq({'the', 'fox'}, it:filter(function(s) return #s <= 3 end):totable())
+ end)
+
+ it('map()', function()
+ local t = { 1, 2, 3, 4, 5 }
+ eq(
+ { 2, 4, 6, 8, 10 },
+ vim
+ .iter(t)
+ :map(function(v)
+ return 2 * v
+ end)
+ :totable()
+ )
+
+ local it = vim.gsplit(
+ [[
+ Line 1
+ Line 2
+ Line 3
+ Line 4
+ ]],
+ '\n'
+ )
+
+ eq(
+ { 'Lion 2', 'Lion 4' },
+ vim
+ .iter(it)
+ :map(function(s)
+ local lnum = s:match('(%d+)')
+ if lnum and tonumber(lnum) % 2 == 0 then
+ return vim.trim(s:gsub('Line', 'Lion'))
+ end
+ end)
+ :totable()
+ )
+ end)
+
+ it('for loops', function()
+ local t = {1, 2, 3, 4, 5}
+ local acc = 0
+ for v in vim.iter(t):map(function(v) return v * 3 end) do
+ acc = acc + v
+ end
+ eq(45, acc)
+ end)
+
+ it('totable()', function()
+ do
+ local it = vim.iter({1, 2, 3}):map(function(v) return v, v*v end)
+ eq({{1, 1}, {2, 4}, {3, 9}}, it:totable())
+ end
+
+ do
+ local it = vim.iter(string.gmatch('1,4,lol,17,blah,2,9,3', '%d+')):map(tonumber)
+ eq({1, 4, 17, 2, 9, 3}, it:totable())
+ end
+ end)
+
+ it('next()', function()
+ local it = vim.iter({1, 2, 3}):map(function(v) return 2 * v end)
+ eq(2, it:next())
+ eq(4, it:next())
+ eq(6, it:next())
+ eq(nil, it:next())
+ end)
+
+ it('rev()', function()
+ eq({3, 2, 1}, vim.iter({1, 2, 3}):rev():totable())
+
+ local it = vim.iter(string.gmatch("abc", "%w"))
+ matches('rev%(%) requires a list%-like table', pcall_err(it.rev, it))
+ end)
+
+ it('skip()', function()
+ do
+ local t = {4, 3, 2, 1}
+ eq(t, vim.iter(t):skip(0):totable())
+ eq({3, 2, 1}, vim.iter(t):skip(1):totable())
+ eq({2, 1}, vim.iter(t):skip(2):totable())
+ eq({1}, vim.iter(t):skip(#t - 1):totable())
+ eq({}, vim.iter(t):skip(#t):totable())
+ eq({}, vim.iter(t):skip(#t + 1):totable())
+ end
+
+ do
+ local function skip(n)
+ return vim.iter(vim.gsplit('a|b|c|d', '|')):skip(n):totable()
+ end
+ eq({'a', 'b', 'c', 'd'}, skip(0))
+ eq({'b', 'c', 'd'}, skip(1))
+ eq({'c', 'd'}, skip(2))
+ eq({'d'}, skip(3))
+ eq({}, skip(4))
+ eq({}, skip(5))
+ end
+ end)
+
+ it('skipback()', function()
+ do
+ local t = {4, 3, 2, 1}
+ eq(t, vim.iter(t):skipback(0):totable())
+ eq({4, 3, 2}, vim.iter(t):skipback(1):totable())
+ eq({4, 3}, vim.iter(t):skipback(2):totable())
+ eq({4}, vim.iter(t):skipback(#t - 1):totable())
+ eq({}, vim.iter(t):skipback(#t):totable())
+ eq({}, vim.iter(t):skipback(#t + 1):totable())
+ end
+
+ local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
+ matches('skipback%(%) requires a list%-like table', pcall_err(it.skipback, it, 0))
+ end)
+
+ it('slice()', function()
+ local t = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+ eq({3, 4, 5, 6, 7}, vim.iter(t):slice(3, 7):totable())
+ eq({}, vim.iter(t):slice(6, 5):totable())
+ eq({}, vim.iter(t):slice(0, 0):totable())
+ eq({1}, vim.iter(t):slice(1, 1):totable())
+ eq({1, 2}, vim.iter(t):slice(1, 2):totable())
+ eq({10}, vim.iter(t):slice(10, 10):totable())
+ eq({8, 9, 10}, vim.iter(t):slice(8, 11):totable())
+
+ local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
+ matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3))
+ end)
+
+ it('nth()', function()
+ do
+ local t = {4, 3, 2, 1}
+ eq(nil, vim.iter(t):nth(0))
+ eq(4, vim.iter(t):nth(1))
+ eq(3, vim.iter(t):nth(2))
+ eq(2, vim.iter(t):nth(3))
+ eq(1, vim.iter(t):nth(4))
+ eq(nil, vim.iter(t):nth(5))
+ end
+
+ do
+ local function nth(n)
+ return vim.iter(vim.gsplit('a|b|c|d', '|')):nth(n)
+ end
+ eq(nil, nth(0))
+ eq('a', nth(1))
+ eq('b', nth(2))
+ eq('c', nth(3))
+ eq('d', nth(4))
+ eq(nil, nth(5))
+ end
+ end)
+
+ it('nthback()', function()
+ do
+ local t = {4, 3, 2, 1}
+ eq(nil, vim.iter(t):nthback(0))
+ eq(1, vim.iter(t):nthback(1))
+ eq(2, vim.iter(t):nthback(2))
+ eq(3, vim.iter(t):nthback(3))
+ eq(4, vim.iter(t):nthback(4))
+ eq(nil, vim.iter(t):nthback(5))
+ end
+
+ local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
+ matches('skipback%(%) requires a list%-like table', pcall_err(it.nthback, it, 1))
+ end)
+
+ it('any()', function()
+ local function odd(v)
+ return v % 2 ~= 0
+ end
+
+ do
+ local t = { 4, 8, 9, 10 }
+ eq(true, vim.iter(t):any(odd))
+ end
+
+ do
+ local t = { 4, 8, 10 }
+ eq(false, vim.iter(t):any(odd))
+ end
+
+ do
+ eq(true, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'd' end))
+ eq(false, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'e' end))
+ end
+ end)
+
+ it('all()', function()
+ local function odd(v)
+ return v % 2 ~= 0
+ end
+
+ do
+ local t = { 3, 5, 7, 9 }
+ eq(true, vim.iter(t):all(odd))
+ end
+
+ do
+ local t = { 3, 5, 7, 10 }
+ eq(false, vim.iter(t):all(odd))
+ end
+
+ do
+ eq(true, vim.iter(vim.gsplit('a|a|a|a', '|')):all(function(s) return s == 'a' end))
+ eq(false, vim.iter(vim.gsplit('a|a|a|b', '|')):all(function(s) return s == 'a' end))
+ end
+ end)
+
+ it('last()', function()
+ local s = 'abcdefghijklmnopqrstuvwxyz'
+ eq('z', vim.iter(vim.split(s, '')):last())
+ eq('z', vim.iter(vim.gsplit(s, '')):last())
+ end)
+
+ it('enumerate()', function()
+ local it = vim.iter(vim.gsplit('abc', '')):enumerate()
+ eq({1, 'a'}, {it:next()})
+ eq({2, 'b'}, {it:next()})
+ eq({3, 'c'}, {it:next()})
+ eq({}, {it:next()})
+ end)
+
+ it('peek()', function()
+ do
+ local it = vim.iter({ 3, 6, 9, 12 })
+ eq(3, it:peek())
+ eq(3, it:peek())
+ eq(3, it:next())
+ end
+
+ do
+ local it = vim.iter(vim.gsplit('hi', ''))
+ matches('peek%(%) requires a list%-like table', pcall_err(it.peek, it))
+ end
+ end)
+
+ it('find()', function()
+ local t = {3, 6, 9, 12}
+ eq(12, vim.iter(t):find(12))
+ eq(nil, vim.iter(t):find(15))
+ eq(12, vim.iter(t):find(function(v) return v % 4 == 0 end))
+
+ do
+ local it = vim.iter(t)
+ local pred = function(v) return v % 3 == 0 end
+ eq(3, it:find(pred))
+ eq(6, it:find(pred))
+ eq(9, it:find(pred))
+ eq(12, it:find(pred))
+ eq(nil, it:find(pred))
+ end
+
+ do
+ local it = vim.iter(vim.gsplit('AbCdE', ''))
+ local pred = function(s) return s:match('[A-Z]') end
+ eq('A', it:find(pred))
+ eq('C', it:find(pred))
+ eq('E', it:find(pred))
+ eq(nil, it:find(pred))
+ end
+ end)
+
+ it('rfind()', function()
+ local t = {1, 2, 3, 2, 1}
+ do
+ local it = vim.iter(t)
+ eq(1, it:rfind(1))
+ eq(1, it:rfind(1))
+ eq(nil, it:rfind(1))
+ end
+
+ do
+ local it = vim.iter(t):enumerate()
+ local pred = function(i) return i % 2 ~= 0 end
+ eq({5, 1}, {it:rfind(pred)})
+ eq({3, 3}, {it:rfind(pred)})
+ eq({1, 1}, {it:rfind(pred)})
+ eq(nil, it:rfind(pred))
+ end
+
+ do
+ local it = vim.iter(vim.gsplit('AbCdE', ''))
+ matches('rfind%(%) requires a list%-like table', pcall_err(it.rfind, it, 'E'))
+ end
+ end)
+
+ it('nextback()', function()
+ do
+ local it = vim.iter({ 1, 2, 3, 4 })
+ eq(4, it:nextback())
+ eq(3, it:nextback())
+ eq(2, it:nextback())
+ eq(1, it:nextback())
+ eq(nil, it:nextback())
+ eq(nil, it:nextback())
+ end
+
+ do
+ local it = vim.iter(vim.gsplit('hi', ''))
+ matches('nextback%(%) requires a list%-like table', pcall_err(it.nextback, it))
+ end
+ end)
+
+ it('peekback()', function()
+ do
+ local it = vim.iter({ 1, 2, 3, 4 })
+ eq(4, it:peekback())
+ eq(4, it:peekback())
+ eq(4, it:nextback())
+ end
+
+ do
+ local it = vim.iter(vim.gsplit('hi', ''))
+ matches('peekback%(%) requires a list%-like table', pcall_err(it.peekback, it))
+ end
+ end)
+
+ it('fold()', function()
+ local t = {1, 2, 3, 4, 5}
+ eq(115, vim.iter(t):fold(100, function(acc, v) return acc + v end))
+ eq({5, 4, 3, 2, 1}, vim.iter(t):fold({}, function(acc, v)
+ table.insert(acc, 1, v)
+ return acc
+ end))
+ end)
+
+ it('handles map-like tables', function()
+ local it = vim.iter({ a = 1, b = 2, c = 3 }):map(function(k, v)
+ if v % 2 ~= 0 then
+ return k:upper(), v * 2
+ end
+ end)
+
+ local t = it:fold({}, function(t, k, v)
+ t[k] = v
+ return t
+ end)
+ eq({ A = 2, C = 6 }, t)
+ end)
+
+ it('handles table values mid-pipeline', function()
+ local map = {
+ item = {
+ file = 'test',
+ },
+ item_2 = {
+ file = 'test',
+ },
+ item_3 = {
+ file = 'test',
+ },
+ }
+
+ local output = vim.iter(map):map(function(key, value)
+ return { [key] = value.file }
+ end):totable()
+
+ table.sort(output, function(a, b)
+ return next(a) < next(b)
+ end)
+
+ eq({
+ { item = 'test' },
+ { item_2 = 'test' },
+ { item_3 = 'test' },
+ }, output)
+ end)
+end)
diff --git a/test/functional/lua/json_spec.lua b/test/functional/lua/json_spec.lua
index fbb21bfd57..25fdb48eea 100644
--- a/test/functional/lua/json_spec.lua
+++ b/test/functional/lua/json_spec.lua
@@ -1,20 +1,57 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
-local NIL = helpers.NIL
local exec_lua = helpers.exec_lua
local eq = helpers.eq
+local pcall_err = helpers.pcall_err
-describe('vim.json.decode function', function()
+describe('vim.json.decode()', function()
before_each(function()
clear()
end)
it('parses null, true, false', function()
- eq(NIL, exec_lua([[return vim.json.decode('null')]]))
+ eq(vim.NIL, exec_lua([[return vim.json.decode('null')]]))
eq(true, exec_lua([[return vim.json.decode('true')]]))
eq(false, exec_lua([[return vim.json.decode('false')]]))
end)
+ it('validation', function()
+ eq('Expected object key string but found invalid token at character 2',
+ pcall_err(exec_lua, [[return vim.json.decode('{a:"b"}')]]))
+ end)
+
+ it('options', function()
+ local jsonstr = '{"arr":[1,2,null],"bar":[3,7],"foo":{"a":"b"},"baz":null}'
+ eq({
+ arr = { 1, 2, vim.NIL },
+ bar = { 3, 7 },
+ baz = vim.NIL,
+ foo = { a = 'b' },
+ },
+ exec_lua([[return vim.json.decode(..., {})]], jsonstr))
+ eq({
+ arr = { 1, 2, vim.NIL },
+ bar = { 3, 7 },
+ -- baz = nil,
+ foo = { a = 'b' },
+ },
+ exec_lua([[return vim.json.decode(..., { luanil = { object = true } })]], jsonstr))
+ eq({
+ arr = { 1, 2 },
+ bar = { 3, 7 },
+ baz = vim.NIL,
+ foo = { a = 'b' },
+ },
+ exec_lua([[return vim.json.decode(..., { luanil = { array = true } })]], jsonstr))
+ eq({
+ arr = { 1, 2 },
+ bar = { 3, 7 },
+ -- baz = nil,
+ foo = { a = 'b' },
+ },
+ exec_lua([[return vim.json.decode(..., { luanil = { array = true, object = true } })]], jsonstr))
+ end)
+
it('parses integer numbers', function()
eq(100000, exec_lua([[return vim.json.decode('100000')]]))
eq(-100000, exec_lua([[return vim.json.decode('-100000')]]))
@@ -60,7 +97,7 @@ describe('vim.json.decode function', function()
it('parses containers', function()
eq({1}, exec_lua([[return vim.json.decode('[1]')]]))
- eq({NIL, 1}, exec_lua([[return vim.json.decode('[null, 1]')]]))
+ eq({vim.NIL, 1}, exec_lua([[return vim.json.decode('[null, 1]')]]))
eq({['1']=2}, exec_lua([[return vim.json.decode('{"1": 2}')]]))
eq({['1']=2, ['3']={{['4']={['5']={{}, 1}}}}},
exec_lua([[return vim.json.decode('{"1": 2, "3": [{"4": {"5": [ [], 1]}}]}')]]))
@@ -88,43 +125,43 @@ describe('vim.json.decode function', function()
end)
-describe('vim.json.encode function', function()
+describe('vim.json.encode()', function()
before_each(function()
clear()
end)
- it('dumps strings', function()
- eq('"Test"', exec_lua([[return vim.json.encode('Test')]]))
- eq('""', exec_lua([[return vim.json.encode('')]]))
- eq('"\\t"', exec_lua([[return vim.json.encode('\t')]]))
- eq('"\\n"', exec_lua([[return vim.json.encode('\n')]]))
- -- vim.fn.json_encode return \\u001B
- eq('"\\u001b"', exec_lua([[return vim.json.encode('\27')]]))
- eq('"þÿþ"', exec_lua([[return vim.json.encode('þÿþ')]]))
- end)
-
- it('dumps numbers', function()
- eq('0', exec_lua([[return vim.json.encode(0)]]))
- eq('10', exec_lua([[return vim.json.encode(10)]]))
- eq('-10', exec_lua([[return vim.json.encode(-10)]]))
- end)
-
- it('dumps floats', function()
- eq('10.5', exec_lua([[return vim.json.encode(10.5)]]))
- eq('-10.5', exec_lua([[return vim.json.encode(-10.5)]]))
- eq('-1e-05', exec_lua([[return vim.json.encode(-1e-5)]]))
- end)
-
- it('dumps lists', function()
- eq('[]', exec_lua([[return vim.json.encode({})]]))
- eq('[[]]', exec_lua([[return vim.json.encode({{}})]]))
- eq('[[],[]]', exec_lua([[return vim.json.encode({{}, {}})]]))
- end)
-
- it('dumps dictionaries', function()
- eq('{}', exec_lua([[return vim.json.encode(vim.empty_dict())]]))
- eq('{"d":[]}', exec_lua([[return vim.json.encode({d={}})]]))
- end)
+ it('dumps strings', function()
+ eq('"Test"', exec_lua([[return vim.json.encode('Test')]]))
+ eq('""', exec_lua([[return vim.json.encode('')]]))
+ eq('"\\t"', exec_lua([[return vim.json.encode('\t')]]))
+ eq('"\\n"', exec_lua([[return vim.json.encode('\n')]]))
+ -- vim.fn.json_encode return \\u001B
+ eq('"\\u001b"', exec_lua([[return vim.json.encode('\27')]]))
+ eq('"þÿþ"', exec_lua([[return vim.json.encode('þÿþ')]]))
+ end)
+
+ it('dumps numbers', function()
+ eq('0', exec_lua([[return vim.json.encode(0)]]))
+ eq('10', exec_lua([[return vim.json.encode(10)]]))
+ eq('-10', exec_lua([[return vim.json.encode(-10)]]))
+ end)
+
+ it('dumps floats', function()
+ eq('10.5', exec_lua([[return vim.json.encode(10.5)]]))
+ eq('-10.5', exec_lua([[return vim.json.encode(-10.5)]]))
+ eq('-1e-05', exec_lua([[return vim.json.encode(-1e-5)]]))
+ end)
+
+ it('dumps lists', function()
+ eq('[]', exec_lua([[return vim.json.encode({})]]))
+ eq('[[]]', exec_lua([[return vim.json.encode({{}})]]))
+ eq('[[],[]]', exec_lua([[return vim.json.encode({{}, {}})]]))
+ end)
+
+ it('dumps dictionaries', function()
+ eq('{}', exec_lua([[return vim.json.encode(vim.empty_dict())]]))
+ eq('{"d":[]}', exec_lua([[return vim.json.encode({d={}})]]))
+ end)
it('dumps vim.NIL', function()
eq('null', exec_lua([[return vim.json.encode(vim.NIL)]]))
diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua
new file mode 100644
index 0000000000..34c36b04ef
--- /dev/null
+++ b/test/functional/lua/loader_spec.lua
@@ -0,0 +1,56 @@
+-- Test suite for testing interactions with API bindings
+local helpers = require('test.functional.helpers')(after_each)
+
+local exec_lua = helpers.exec_lua
+local command = helpers.command
+local eq = helpers.eq
+
+describe('vim.loader', function()
+ before_each(helpers.clear)
+
+ it('handles changing files (#23027)', function()
+ exec_lua[[
+ vim.loader.enable()
+ ]]
+
+ local tmp = helpers.tmpname()
+ command('edit ' .. tmp)
+
+ eq(1, exec_lua([[
+ vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=1'})
+ vim.cmd.write()
+ loadfile(...)()
+ return _G.TEST
+ ]], tmp))
+
+ -- fs latency
+ helpers.sleep(10)
+
+ eq(2, exec_lua([[
+ vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=2'})
+ vim.cmd.write()
+ loadfile(...)()
+ return _G.TEST
+ ]], tmp))
+ end)
+
+ it('handles % signs in modpath (#24491)', function()
+ exec_lua[[
+ vim.loader.enable()
+ ]]
+
+ local tmp1, tmp2 = (function (t)
+ assert(os.remove(t))
+ assert(helpers.mkdir(t))
+ assert(helpers.mkdir(t .. '/%'))
+ return t .. '/%/x', t .. '/%%x'
+ end)(helpers.tmpname())
+
+ helpers.write_file(tmp1, 'return 1', true)
+ helpers.write_file(tmp2, 'return 2', true)
+ vim.uv.fs_utime(tmp1, 0, 0)
+ vim.uv.fs_utime(tmp2, 0, 0)
+ eq(1, exec_lua('return loadfile(...)()', tmp1))
+ eq(2, exec_lua('return loadfile(...)()', tmp2))
+ end)
+end)
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua
index 7f3787d7bf..c0924fa0c0 100644
--- a/test/functional/lua/loop_spec.lua
+++ b/test/functional/lua/loop_spec.lua
@@ -14,24 +14,24 @@ local retry = helpers.retry
before_each(clear)
-describe('vim.loop', function()
+describe('vim.uv', function()
it('version', function()
- assert(funcs.luaeval('vim.loop.version()')>=72961, "libuv version too old")
- matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.loop.version_string()'))
+ assert(funcs.luaeval('vim.uv.version()')>=72961, "libuv version too old")
+ matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.uv.version_string()'))
end)
it('timer', function()
exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {})
local code=[[
- local loop = vim.loop
+ local uv = vim.uv
local touch = 0
local function wait(ms)
local this = coroutine.running()
assert(this)
- local timer = loop.new_timer()
+ local timer = uv.new_timer()
timer:start(ms, 0, vim.schedule_wrap(function ()
timer:close()
touch = touch + 1
@@ -73,7 +73,7 @@ describe('vim.loop', function()
-- deferred API functions are disabled, as their safety can't be guaranteed
exec_lua([[
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(20, 0, function ()
_G.is_fast = vim.in_fast_event()
timer:close()
@@ -101,7 +101,7 @@ describe('vim.loop', function()
-- callbacks can be scheduled to be executed in the main event loop
-- where the entire API is available
exec_lua([[
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(20, 0, vim.schedule_wrap(function ()
_G.is_fast = vim.in_fast_event()
timer:close()
@@ -127,7 +127,7 @@ describe('vim.loop', function()
-- fast (not deferred) API functions are allowed to be called directly
exec_lua([[
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(20, 0, function ()
timer:close()
-- input is queued for processing after the callback returns
@@ -151,6 +151,6 @@ describe('vim.loop', function()
end)
it("is equal to require('luv')", function()
- eq(true, exec_lua("return vim.loop == require('luv')"))
+ eq(true, exec_lua("return vim.uv == require('luv')"))
end)
end)
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 9f313eab9e..dfbd2fb18b 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -514,7 +514,7 @@ describe('v:lua', function()
[5] = {bold = true, foreground = Screen.colors.SeaGreen4},
})
screen:attach()
- meths.buf_set_option(0, 'omnifunc', 'v:lua.mymod.omni')
+ meths.set_option_value('omnifunc', 'v:lua.mymod.omni', {})
feed('isome st<c-x><c-o>')
screen:expect{grid=[[
some stuff^ |
@@ -526,7 +526,7 @@ describe('v:lua', function()
{1:~ }|
{4:-- Omni completion (^O^N^P) }{5:match 1 of 3} |
]]}
- meths.set_option('operatorfunc', 'v:lua.mymod.noisy')
+ meths.set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
feed('<Esc>g@g@')
eq("hey line", meths.get_current_line())
end)
@@ -539,13 +539,13 @@ describe('v:lua', function()
end)
it('throw errors for invalid use', function()
- eq('Vim(let):E15: Invalid expression: v:lua.func', pcall_err(command, "let g:Func = v:lua.func"))
- eq('Vim(let):E15: Invalid expression: v:lua', pcall_err(command, "let g:Func = v:lua"))
- eq("Vim(let):E15: Invalid expression: v:['lua']", pcall_err(command, "let g:Func = v:['lua']"))
+ eq([[Vim(let):E15: Invalid expression: "v:lua.func"]], pcall_err(command, "let g:Func = v:lua.func"))
+ eq([[Vim(let):E15: Invalid expression: "v:lua"]], pcall_err(command, "let g:Func = v:lua"))
+ eq([[Vim(let):E15: Invalid expression: "v:['lua']"]], pcall_err(command, "let g:Func = v:['lua']"))
- eq("Vim:E15: Invalid expression: v:['lua'].foo()", pcall_err(eval, "v:['lua'].foo()"))
+ eq([[Vim:E15: Invalid expression: "v:['lua'].foo()"]], pcall_err(eval, "v:['lua'].foo()"))
eq("Vim(call):E461: Illegal variable name: v:['lua']", pcall_err(command, "call v:['lua'].baar()"))
- eq("Vim:E117: Unknown function: v:lua", pcall_err(eval, "v:lua()"))
+ eq("Vim:E1085: Not a callable type: v:lua", pcall_err(eval, "v:lua()"))
eq("Vim(let):E46: Cannot change read-only variable \"v:['lua']\"", pcall_err(command, "let v:['lua'] = 'xx'"))
eq("Vim(let):E46: Cannot change read-only variable \"v:lua\"", pcall_err(command, "let v:lua = 'xx'"))
@@ -553,7 +553,7 @@ describe('v:lua', function()
eq("Vim:E107: Missing parentheses: v:lua.func", pcall_err(eval, "'bad'->v:lua.func"))
eq("Vim:E274: No white space allowed before parenthesis", pcall_err(eval, "'bad'->v:lua.func ()"))
eq("Vim:E107: Missing parentheses: v:lua", pcall_err(eval, "'bad'->v:lua"))
- eq("Vim:E117: Unknown function: v:lua", pcall_err(eval, "'bad'->v:lua()"))
- eq("Vim:E15: Invalid expression: v:lua.()", pcall_err(eval, "'bad'->v:lua.()"))
+ eq("Vim:E1085: Not a callable type: v:lua", pcall_err(eval, "'bad'->v:lua()"))
+ eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, "'bad'->v:lua.()"))
end)
end)
diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua
index 3f107811ae..c08f3d06a9 100644
--- a/test/functional/lua/overrides_spec.lua
+++ b/test/functional/lua/overrides_spec.lua
@@ -15,8 +15,6 @@ local exec_lua = helpers.exec_lua
local pcall_err = helpers.pcall_err
local is_os = helpers.is_os
-local screen
-
local fname = 'Xtest-functional-lua-overrides-luafile'
before_each(clear)
@@ -56,7 +54,7 @@ describe('print', function()
-- TODO(bfredl): these look weird, print() should not use "E5114:" style errors..
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]',
pcall_err(command, 'lua print("foo", v_nilerr, "bar")'))
- eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:0: abc',
+ eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc',
pcall_err(command, 'lua print("foo", v_abcerr, "bar")'))
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',
pcall_err(command, 'lua print("foo", v_tblout, "bar")'))
@@ -86,9 +84,9 @@ describe('print', function()
end
]])
eq('', exec_capture('luafile ' .. fname))
- eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: my mistake',
+ eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake',
pcall_err(command, 'lua string_error()'))
- eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: 1234',
+ eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234',
pcall_err(command, 'lua number_error()'))
eq('Vim(lua):E5108: Error executing lua [NULL]',
pcall_err(command, 'lua nil_error()'))
@@ -100,7 +98,7 @@ describe('print', function()
pcall_err(command, 'lua bad_custom_error()'))
end)
it('prints strings with NULs and NLs correctly', function()
- meths.set_option('more', true)
+ meths.set_option_value('more', true, {})
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n',
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]))
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@',
@@ -119,7 +117,7 @@ describe('print', function()
exec_lua([[
local cmd = ...
function test()
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
local done = false
timer:start(10, 0, function()
print("very fast")
@@ -130,7 +128,7 @@ describe('print', function()
-- loop until we know for sure the callback has been executed
while not done do
os.execute(cmd)
- vim.loop.run("nowait") -- fake os_breakcheck()
+ vim.uv.run("nowait") -- fake os_breakcheck()
end
print("very slow")
vim.api.nvim_command("sleep 1m") -- force deferred event processing
@@ -138,9 +136,44 @@ describe('print', function()
]], (is_os('win') and "timeout 1") or "sleep 0.1")
eq('very slow\nvery fast', exec_capture('lua test()'))
end)
+
+ it('blank line in message works', function()
+ local screen = Screen.new(40, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground=Screen.colors.Blue},
+ [1] = {bold = true, foreground = Screen.colors.SeaGreen},
+ [2] = {bold = true, reverse = true},
+ })
+ feed([[:lua print('\na')<CR>]])
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {2: }|
+ |
+ a |
+ {1:Press ENTER or type command to continue}^ |
+ ]]}
+ feed('<CR>')
+ feed([[:lua print('b\n\nc')<CR>]])
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {2: }|
+ b |
+ |
+ c |
+ {1:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
end)
describe('debug.debug', function()
+ local screen
+
before_each(function()
screen = Screen.new()
screen:attach()
@@ -338,3 +371,11 @@ describe('os.getenv', function()
eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
end)
end)
+
+-- "bit" module is always available, regardless if nvim is built with
+-- luajit or PUC lua 5.1.
+describe('bit module', function()
+ it('works', function()
+ eq (9, exec_lua [[ return require'bit'.band(11,13) ]])
+ end)
+end)
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
index b659f2eacb..0b8b2234db 100644
--- a/test/functional/lua/runtime_spec.lua
+++ b/test/functional/lua/runtime_spec.lua
@@ -18,6 +18,11 @@ describe('runtime:', function()
io.open(init, 'w'):close() -- touch init file
clear{args = {'-u', init}}
exec('set rtp+=' .. plug_dir)
+ exec([[
+ set shell=doesnotexist
+ set completeslash=slash
+ set isfname+=(,)
+ ]])
end)
teardown(function()
@@ -35,91 +40,199 @@ describe('runtime:', function()
describe('colors', function()
local colorscheme_folder = plug_dir .. sep .. 'colors'
-
- it('loads lua colorscheme', function()
- local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme.lua'
+ before_each(function()
mkdir_p(colorscheme_folder)
+ end)
+
+ it('lua colorschemes work and are included in cmdline completion', function()
+ local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep)
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
+ eq({'colors/new_colorscheme.lua'}, funcs.getcompletion('colors/new_c', 'runtime'))
exec('colorscheme new_colorscheme')
eq(1, eval('g:lua_colorscheme'))
- rmdir(colorscheme_folder)
end)
- it('loads vim colorscheme when both lua and vim version exist', function()
- local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme'
- mkdir_p(colorscheme_folder)
- write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
- write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])
+ it("'rtp'/'pp' order is respected", function()
+ local pack_dir = 'Test_Pack'
+ mkdir_p(pack_dir)
+ finally(function()
+ rmdir(pack_dir)
+ end)
+ exec('set pp+=' .. pack_dir)
+
+ local pack_opt_dir = table.concat({pack_dir, 'pack', 'some_name', 'opt'}, sep)
+ local colors_opt_dir = table.concat({pack_opt_dir, 'some_pack', 'colors'}, sep)
+ mkdir_p(colors_opt_dir)
+
+ local after_colorscheme_folder = table.concat({plug_dir, 'after', 'colors'}, sep)
+ mkdir_p(after_colorscheme_folder)
+ exec('set rtp+=' .. plug_dir .. '/after')
+
+ write_file(table.concat({colors_opt_dir, 'new_colorscheme.lua'}, sep),
+ [[vim.g.colorscheme = 'lua_pp']])
+ exec('colorscheme new_colorscheme')
+ eq('lua_pp', eval('g:colorscheme'))
+
+ write_file(table.concat({colors_opt_dir, 'new_colorscheme.vim'}, sep),
+ [[let g:colorscheme = 'vim_pp']])
+ exec('colorscheme new_colorscheme')
+ eq('vim_pp', eval('g:colorscheme'))
+ write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.lua'}, sep),
+ [[vim.g.colorscheme = 'lua_rtp_after']])
exec('colorscheme new_colorscheme')
+ eq('lua_rtp_after', eval('g:colorscheme'))
- eq('vim', eval('g:colorscheme'))
- rmdir(colorscheme_folder)
+ write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.vim'}, sep),
+ [[let g:colorscheme = 'vim_rtp_after']])
+ exec('colorscheme new_colorscheme')
+ eq('vim_rtp_after', eval('g:colorscheme'))
+
+ write_file(table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep),
+ [[vim.g.colorscheme = 'lua_rtp']])
+ exec('colorscheme new_colorscheme')
+ eq('lua_rtp', eval('g:colorscheme'))
+
+ write_file(table.concat({colorscheme_folder, 'new_colorscheme.vim'}, sep),
+ [[let g:colorscheme = 'vim_rtp']])
+ exec('colorscheme new_colorscheme')
+ eq('vim_rtp', eval('g:colorscheme'))
end)
end)
describe('compiler', function()
- local compiler_folder = plug_dir .. sep .. 'compiler'
+ local compiler_folder = table.concat({plug_dir, 'compiler'}, sep)
+ before_each(function()
+ mkdir_p(compiler_folder)
+ end)
- it('loads lua compilers', function()
+ it('lua compilers work and are included in cmdline completion', function()
local compiler_file = compiler_folder .. sep .. 'new_compiler.lua'
- mkdir_p(compiler_folder)
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
+ eq({'compiler/new_compiler.lua'}, funcs.getcompletion('compiler/new_c', 'runtime'))
exec('compiler new_compiler')
eq(1, eval('b:lua_compiler'))
- rmdir(compiler_folder)
end)
- it('loads vim compilers when both lua and vim version exist', function()
- local compiler_file = compiler_folder .. sep .. 'new_compiler'
- mkdir_p(compiler_folder)
- write_file(compiler_file..'.vim', [[let b:compiler = 'vim']])
- write_file(compiler_file..'.lua', [[vim.b.compiler = 'lua']])
-
+ it("'rtp' order is respected", function()
+ local after_compiler_folder = table.concat({plug_dir, 'after', 'compiler'}, sep)
+ mkdir_p(table.concat({compiler_folder, 'new_compiler'}, sep))
+ mkdir_p(table.concat({after_compiler_folder, 'new_compiler'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/compiler/ are loaded after all files in compiler/.
+ write_file(table.concat({compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({after_compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
exec('compiler new_compiler')
-
- eq('vim', eval('b:compiler'))
- rmdir(compiler_folder)
+ eq('ABab', eval('g:seq'))
end)
end)
describe('ftplugin', function()
local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep)
- it('loads lua ftplugins', function()
- local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
+ it('lua ftplugins work and are included in cmdline completion', function()
mkdir_p(ftplugin_folder)
+ local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
+ eq({'ftplugin/new-ft.lua'}, funcs.getcompletion('ftplugin/new-f', 'runtime'))
exec [[set filetype=new-ft]]
eq(1, eval('b:lua_ftplugin'))
- rmdir(ftplugin_folder)
+ end)
+
+ it("'rtp' order is respected", function()
+ local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
+ mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
+ mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/ftplugin/ are loaded after all files in ftplugin/.
+ write_file(table.concat({ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'E']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'c']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
+ exec('setfiletype new-ft')
+ eq('ABCDEFabcdef', eval('g:seq'))
+ end)
+
+ it("'rtp' order is respected with 'fileignorecase'", function()
+ exec('set fileignorecase')
+ local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
+ mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
+ mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/ftplugin/ are loaded after all files in ftplugin/.
+ write_file(table.concat({ftplugin_folder, 'new-ft.VIM'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({ftplugin_folder, 'new-ft.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.VIM'}, sep), [[let g:seq ..= 'E']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.VIM'}, sep), [[let g:seq ..= 'c']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
+ exec('setfiletype new-ft')
+ eq('ABCDEFabcdef', eval('g:seq'))
end)
end)
describe('indent', function()
local indent_folder = table.concat({plug_dir, 'indent'}, sep)
- it('loads lua indents', function()
- local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
+ it('lua indents work and are included in cmdline completion', function()
mkdir_p(indent_folder)
+ local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
write_file(indent_file , [[vim.b.lua_indent = 1]])
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
+ eq({'indent/new-ft.lua'}, funcs.getcompletion('indent/new-f', 'runtime'))
exec [[set filetype=new-ft]]
eq(1, eval('b:lua_indent'))
- rmdir(indent_folder)
+ end)
+
+ it("'rtp' order is respected", function()
+ local after_indent_folder = table.concat({plug_dir, 'after', 'indent'}, sep)
+ mkdir_p(table.concat({indent_folder, 'new-ft'}, sep))
+ mkdir_p(table.concat({after_indent_folder, 'new-ft'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/indent/ are loaded after all files in indent/.
+ write_file(table.concat({indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({after_indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ exec('setfiletype new-ft')
+ eq('ABab', eval('g:seq'))
end)
end)
@@ -127,8 +240,8 @@ describe('runtime:', function()
local syntax_folder = table.concat({plug_dir, 'syntax'}, sep)
before_each(function()
- local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
mkdir_p(syntax_folder)
+ local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
write_file(syntax_file , [[vim.b.current_syntax = 'my-lang']])
exec([[let b:current_syntax = '']])
end)
@@ -152,8 +265,47 @@ describe('runtime:', function()
it('lua syntaxes are included in cmdline completion', function()
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
+ eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime'))
+ end)
+
+ it("'rtp' order is respected", function()
+ local after_syntax_folder = table.concat({plug_dir, 'after', 'syntax'}, sep)
+ mkdir_p(table.concat({syntax_folder, 'my-lang'}, sep))
+ mkdir_p(table.concat({after_syntax_folder, 'my-lang'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/syntax/ are loaded after all files in syntax/.
+ write_file(table.concat({syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'C']])
+ write_file(table.concat({syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
+ write_file(table.concat({after_syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ write_file(table.concat({after_syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'c']])
+ write_file(table.concat({after_syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
+ exec('setfiletype my-lang')
+ eq('ABCDabcd', eval('g:seq'))
end)
end)
-end)
+ describe('spell', function()
+ it("loads spell/LANG.{vim,lua} respecting 'rtp' order", function()
+ local spell_folder = table.concat({plug_dir, 'spell'}, sep)
+ local after_spell_folder = table.concat({plug_dir, 'after', 'spell'}, sep)
+ mkdir_p(table.concat({spell_folder, 'Xtest'}, sep))
+ mkdir_p(table.concat({after_spell_folder, 'Xtest'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/spell/ are loaded after all files in spell/.
+ write_file(table.concat({spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({after_spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ exec('set spelllang=Xtest')
+ eq('ABab', eval('g:seq'))
+ end)
+ end)
+end)
diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua
index 2647b2be46..fc20a06390 100644
--- a/test/functional/lua/secure_spec.lua
+++ b/test/functional/lua/secure_spec.lua
@@ -6,7 +6,7 @@ local clear = helpers.clear
local command = helpers.command
local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os
-local curbufmeths = helpers.curbufmeths
+local meths = helpers.meths
local exec_lua = helpers.exec_lua
local feed_command = helpers.feed_command
local feed = helpers.feed
@@ -19,21 +19,14 @@ describe('vim.secure', function()
local xstate = 'Xstate'
setup(function()
+ clear{env={XDG_STATE_HOME=xstate}}
helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
- end)
-
- teardown(function()
- helpers.rmdir(xstate)
- end)
-
- before_each(function()
helpers.write_file('Xfile', [[
let g:foobar = 42
]])
- clear{env={XDG_STATE_HOME=xstate}}
end)
- after_each(function()
+ teardown(function()
os.remove('Xfile')
helpers.rmdir(xstate)
end)
@@ -48,6 +41,7 @@ describe('vim.secure', function()
[4] = {reverse = true},
})
+ --- XXX: screen:expect() may fail if this path is too long.
local cwd = funcs.getcwd()
-- Need to use feed_command instead of exec_lua because of the confirmation prompt
@@ -59,7 +53,7 @@ describe('vim.secure', function()
{1:~ }|
{2: }|
:lua vim.secure.read('Xfile') |
- {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}|
+ {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
]]}
feed('d')
@@ -88,7 +82,7 @@ describe('vim.secure', function()
{1:~ }|
{2: }|
:lua vim.secure.read('Xfile') |
- {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}|
+ {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
]]}
feed('a')
@@ -118,7 +112,7 @@ describe('vim.secure', function()
{1:~ }|
{2: }|
:lua vim.secure.read('Xfile') |
- {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}|
+ {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
]]}
feed('i')
@@ -145,7 +139,7 @@ describe('vim.secure', function()
{1:~ }|
{2: }|
:lua vim.secure.read('Xfile') |
- {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}|
+ {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ |
]]}
feed('v')
@@ -153,7 +147,7 @@ describe('vim.secure', function()
^let g:foobar = 42 |
{1:~ }|
{1:~ }|
- {2:]] .. funcs.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}|
+ {2:]] .. funcs.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}}|
|
{1:~ }|
{4:[No Name] }|
@@ -166,7 +160,7 @@ describe('vim.secure', function()
-- Cannot write file
pcall_err(command, 'write')
- eq(true, curbufmeths.get_option('readonly'))
+ eq(true, meths.get_option_value('readonly', {}))
end)
end)
@@ -174,6 +168,7 @@ describe('vim.secure', function()
local xstate = 'Xstate'
setup(function()
+ clear{env={XDG_STATE_HOME=xstate}}
helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
end)
diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua
new file mode 100644
index 0000000000..f0b3b44139
--- /dev/null
+++ b/test/functional/lua/snippet_spec.lua
@@ -0,0 +1,202 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local buf_lines = helpers.buf_lines
+local clear = helpers.clear
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local feed = helpers.feed
+local matches = helpers.matches
+local pcall_err = helpers.pcall_err
+local sleep = helpers.sleep
+
+describe('vim.snippet', function()
+ before_each(function()
+ clear()
+
+ exec_lua([[
+ vim.keymap.set({ 'i', 's' }, '<Tab>', function() vim.snippet.jump(1) end, { buffer = true })
+ vim.keymap.set({ 'i', 's' }, '<S-Tab>', function() vim.snippet.jump(-1) end, { buffer = true })
+ ]])
+ end)
+ after_each(clear)
+
+ --- @param snippet string[]
+ --- @param expected string[]
+ --- @param settings? string
+ --- @param prefix? string
+ local function test_expand_success(snippet, expected, settings, prefix)
+ if settings then
+ exec_lua(settings)
+ end
+ if prefix then
+ feed('i' .. prefix)
+ end
+ exec_lua('vim.snippet.expand(...)', table.concat(snippet, '\n'))
+ eq(expected, buf_lines(0))
+ end
+
+ --- @param snippet string
+ --- @param err string
+ local function test_expand_fail(snippet, err)
+ matches(err, pcall_err(exec_lua, string.format('vim.snippet.expand("%s")', snippet)))
+ end
+
+ it('adds base indentation to inserted text', function()
+ test_expand_success(
+ { 'function $1($2)', ' $0', 'end' },
+ { ' function ()', ' ', ' end' },
+ '',
+ ' '
+ )
+ end)
+
+ it('adds indentation based on the start of snippet lines', function()
+ test_expand_success({ 'if $1 then', ' $0', 'end' }, { 'if then', ' ', 'end' })
+ end)
+
+ it('replaces tabs with spaces when expandtab is set', function()
+ test_expand_success(
+ { 'function $1($2)', '\t$0', 'end' },
+ { 'function ()', ' ', 'end' },
+ [[
+ vim.o.expandtab = true
+ vim.o.shiftwidth = 2
+ ]]
+ )
+ end)
+
+ it('respects tabs when expandtab is not set', function()
+ test_expand_success(
+ { 'function $1($2)', '\t$0', 'end' },
+ { 'function ()', '\t', 'end' },
+ 'vim.o.expandtab = false'
+ )
+ end)
+
+ it('inserts known variable value', function()
+ test_expand_success({ '; print($TM_CURRENT_LINE)' }, { 'foo; print(foo)' }, nil, 'foo')
+ end)
+
+ it('uses default when variable is not set', function()
+ test_expand_success({ 'print(${TM_CURRENT_WORD:foo})' }, { 'print(foo)' })
+ end)
+
+ it('replaces unknown variables by placeholders', function()
+ test_expand_success({ 'print($UNKNOWN)' }, { 'print(UNKNOWN)' })
+ end)
+
+ it('does not jump outside snippet range', function()
+ test_expand_success({ 'function $1($2)', ' $0', 'end' }, { 'function ()', ' ', 'end' })
+ eq(false, exec_lua('return vim.snippet.jumpable(-1)'))
+ feed('<Tab><Tab>i')
+ eq(false, exec_lua('return vim.snippet.jumpable(1)'))
+ end)
+
+ it('navigates backwards', function()
+ test_expand_success({ 'function $1($2) end' }, { 'function () end' })
+ feed('<Tab><S-Tab>foo')
+ eq({ 'function foo() end' }, buf_lines(0))
+ end)
+
+ it('visits all tabstops', function()
+ local function cursor()
+ return exec_lua('return vim.api.nvim_win_get_cursor(0)')
+ end
+
+ test_expand_success({ 'function $1($2)', ' $0', 'end' }, { 'function ()', ' ', 'end' })
+ eq({ 1, 9 }, cursor())
+ feed('<Tab>')
+ eq({ 1, 10 }, cursor())
+ feed('<Tab>')
+ eq({ 2, 2 }, cursor())
+ end)
+
+ it('syncs text of tabstops with equal indexes', function()
+ test_expand_success({ 'var double = ${1:x} + ${1:x}' }, { 'var double = x + x' })
+ feed('123')
+ eq({ 'var double = 123 + 123' }, buf_lines(0))
+ end)
+
+ it('cancels session with changes outside the snippet', function()
+ test_expand_success({ 'print($1)' }, { 'print()' })
+ feed('<Esc>O-- A comment')
+ eq(false, exec_lua('return vim.snippet.active()'))
+ eq({ '-- A comment', 'print()' }, buf_lines(0))
+ end)
+
+ it('handles non-consecutive tabstops', function()
+ test_expand_success({ 'class $1($3) {', ' $0', '}' }, { 'class () {', ' ', '}' })
+ feed('Foo') -- First tabstop
+ feed('<Tab><Tab>') -- Jump to $0
+ feed('// Inside') -- Insert text
+ eq({ 'class Foo() {', ' // Inside', '}' }, buf_lines(0))
+ end)
+
+ it('handles multiline placeholders', function()
+ test_expand_success(
+ { 'public void foo() {', ' ${0:// TODO Auto-generated', ' throw;}', '}' },
+ { 'public void foo() {', ' // TODO Auto-generated', ' throw;', '}' }
+ )
+ end)
+
+ it('inserts placeholder in all tabstops when the first tabstop has the placeholder', function()
+ test_expand_success(
+ { 'for (${1:int} ${2:x} = ${3:0}; $2 < ${4:N}; $2++) {', ' $0', '}' },
+ { 'for (int x = 0; x < N; x++) {', ' ', '}' }
+ )
+ end)
+
+ it('inserts placeholder in all tabstops when a later tabstop has the placeholder', function()
+ test_expand_success(
+ { 'for (${1:int} $2 = ${3:0}; ${2:x} < ${4:N}; $2++) {', ' $0', '}' },
+ { 'for (int x = 0; x < N; x++) {', ' ', '}' }
+ )
+ end)
+
+ it('errors with multiple placeholders for the same index', function()
+ test_expand_fail('class ${1:Foo} { void ${1:foo}() {} }', 'multiple placeholders for tabstop $1')
+ end)
+
+ it('errors with multiple $0 tabstops', function()
+ test_expand_fail('function $1() { $0 }$0', 'multiple $0 tabstops')
+ end)
+
+ it('cancels session when deleting the snippet', function()
+ test_expand_success({ 'local function $1()', ' $0', 'end' }, { 'local function ()', ' ', 'end' })
+ feed('<esc>Vjjd')
+ eq(false, exec_lua('return vim.snippet.active()'))
+ end)
+
+ it('cancels session when inserting outside snippet region', function()
+ feed('i<cr>')
+ test_expand_success({ 'local function $1()', ' $0', 'end' }, { '', 'local function ()', ' ', 'end' })
+ feed('<esc>O-- A comment')
+ eq(false, exec_lua('return vim.snippet.active()'))
+ end)
+
+ it('inserts choice', function ()
+ test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
+ sleep(100)
+ feed('<Down><C-y>')
+ eq({ 'console.log()' }, buf_lines(0))
+ end)
+
+ it('closes the choice completion menu when jumping', function ()
+ test_expand_success({ 'console.${1|assert,log,error|}($2)' }, { 'console.()' })
+ sleep(100)
+ exec_lua('vim.snippet.jump(1)')
+ eq(0, exec_lua('return vim.fn.pumvisible()'))
+ end)
+
+ it('jumps to next tabstop after inserting choice', function()
+ test_expand_success(
+ { '${1|public,protected,private|} function ${2:name}() {', '\t$0', '}' },
+ { ' function name() {', '\t', '}' }
+ )
+ sleep(100)
+ feed('<C-y><Tab>')
+ sleep(10)
+ feed('foo')
+ eq({ 'public function foo() {', '\t', '}' }, buf_lines(0))
+ end)
+end)
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
new file mode 100644
index 0000000000..a988d3f0d7
--- /dev/null
+++ b/test/functional/lua/system_spec.lua
@@ -0,0 +1,100 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local exec_lua = helpers.exec_lua
+local eq = helpers.eq
+
+local function system_sync(cmd, opts)
+ return exec_lua([[
+ local cmd, opts = ...
+ local obj = vim.system(...)
+
+ if opts.timeout then
+ -- Minor delay before calling wait() so the timeout uv timer can have a headstart over the
+ -- internal call to vim.wait() in wait().
+ vim.wait(10)
+ end
+
+ local res = obj:wait()
+
+ -- Check the process is no longer running
+ local proc = vim.api.nvim_get_proc(obj.pid)
+ assert(not proc, 'process still exists')
+
+ return res
+ ]], cmd, opts)
+end
+
+local function system_async(cmd, opts)
+ return exec_lua([[
+ local cmd, opts = ...
+ _G.done = false
+ local obj = vim.system(cmd, opts, function(obj)
+ _G.done = true
+ _G.ret = obj
+ end)
+
+ local ok = vim.wait(10000, function()
+ return _G.done
+ end)
+
+ assert(ok, 'process did not exit')
+
+ -- Check the process is no longer running
+ local proc = vim.api.nvim_get_proc(obj.pid)
+ assert(not proc, 'process still exists')
+
+ return _G.ret
+ ]], cmd, opts)
+end
+
+describe('vim.system', function()
+ before_each(function()
+ clear()
+ end)
+
+ for name, system in pairs{ sync = system_sync, async = system_async, } do
+ describe('('..name..')', function()
+ it('can run simple commands', function()
+ eq('hello\n', system({'echo', 'hello' }, { text = true }).stdout)
+ end)
+
+ it('handle input', function()
+ eq('hellocat', system({ 'cat' }, { stdin = 'hellocat', text = true }).stdout)
+ end)
+
+ it('supports timeout', function()
+ eq({
+ code = 124,
+ signal = 15,
+ stdout = '',
+ stderr = ''
+ }, system({ 'sleep', '10' }, { timeout = 1000 }))
+ end)
+ end)
+ end
+
+ it('kill processes', function()
+ exec_lua([[
+ local signal
+ local cmd = vim.system({ 'cat', '-' }, { stdin = true }, function(r)
+ signal = r.signal
+ end) -- run forever
+
+ cmd:kill('sigint')
+
+ -- wait for the process not to exist
+ local done = vim.wait(2000, function()
+ return signal ~= nil
+ end)
+
+ assert(done, 'process did not exit')
+
+ -- Check the process is no longer running
+ local proc = vim.api.nvim_get_proc(cmd.pid)
+ assert(not proc, 'process still exists')
+
+ assert(signal == 2)
+ ]])
+ end)
+
+end)
diff --git a/test/functional/lua/text_spec.lua b/test/functional/lua/text_spec.lua
new file mode 100644
index 0000000000..68206557c3
--- /dev/null
+++ b/test/functional/lua/text_spec.lua
@@ -0,0 +1,23 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+
+describe('vim.text', function()
+ before_each(clear)
+
+ describe('hexencode() and hexdecode()', function()
+ it('works', function()
+ local cases = {
+ { 'Hello world!', '48656C6C6F20776F726C6421' },
+ { '😂', 'F09F9882' },
+ }
+
+ for _, v in ipairs(cases) do
+ local input, output = unpack(v)
+ eq(output, vim.text.hexencode(input))
+ eq(input, vim.text.hexdecode(output))
+ end
+ end)
+ end)
+end)
+
diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua
index c7f2783cf3..e79d26a641 100644
--- a/test/functional/lua/thread_spec.lua
+++ b/test/functional/lua/thread_spec.lua
@@ -27,10 +27,10 @@ describe('thread', function()
it('entry func is executed in protected mode', function()
exec_lua [[
- local thread = vim.loop.new_thread(function()
+ local thread = vim.uv.new_thread(function()
error('Error in thread entry func')
end)
- vim.loop.thread_join(thread)
+ vim.uv.thread_join(thread)
]]
screen:expect([[
@@ -51,17 +51,17 @@ describe('thread', function()
it('callback is executed in protected mode', function()
exec_lua [[
- local thread = vim.loop.new_thread(function()
- local timer = vim.loop.new_timer()
+ local thread = vim.uv.new_thread(function()
+ local timer = vim.uv.new_timer()
local function ontimeout()
timer:stop()
timer:close()
error('Error in thread callback')
end
timer:start(10, 0, ontimeout)
- vim.loop.run()
+ vim.uv.run()
end)
- vim.loop.thread_join(thread)
+ vim.uv.thread_join(thread)
]]
screen:expect([[
@@ -83,10 +83,10 @@ describe('thread', function()
describe('print', function()
it('works', function()
exec_lua [[
- local thread = vim.loop.new_thread(function()
+ local thread = vim.uv.new_thread(function()
print('print in thread')
end)
- vim.loop.thread_join(thread)
+ vim.uv.thread_join(thread)
]]
screen:expect([[
@@ -105,10 +105,10 @@ describe('thread', function()
it('vim.inspect', function()
exec_lua [[
- local thread = vim.loop.new_thread(function()
+ local thread = vim.uv.new_thread(function()
print(vim.inspect({1,2}))
end)
- vim.loop.thread_join(thread)
+ vim.uv.thread_join(thread)
]]
screen:expect([[
@@ -140,13 +140,13 @@ describe('thread', function()
function Thread_Test:do_test()
local async
local on_async = self.on_async
- async = vim.loop.new_async(function(ret)
+ async = vim.uv.new_async(function(ret)
on_async(ret)
async:close()
end)
local thread =
- vim.loop.new_thread(self.entry_func, async, self.entry_str, self.args)
- vim.loop.thread_join(thread)
+ vim.uv.new_thread(self.entry_func, async, self.entry_str, self.args)
+ vim.uv.thread_join(thread)
end
Thread_Test.new = function(entry, on_async, ...)
@@ -175,10 +175,10 @@ describe('thread', function()
eq({'notification', 'result', {true}}, next_msg())
end)
- it('loop', function()
+ it('uv', function()
exec_lua [[
local entry = function(async)
- async:send(vim.loop.version())
+ async:send(vim.uv.version())
end
local on_async = function(ret)
vim.rpcnotify(1, ret)
@@ -259,7 +259,7 @@ describe('threadpool', function()
local after_work_fn = function(ret)
vim.rpcnotify(1, 'result', ret)
end
- local work = vim.loop.new_work(work_fn, after_work_fn)
+ local work = vim.uv.new_work(work_fn, after_work_fn)
work:queue()
]]
@@ -268,7 +268,7 @@ describe('threadpool', function()
it('with invalid argument', function()
local status = pcall_err(exec_lua, [[
- local work = vim.loop.new_thread(function() end, function() end)
+ local work = vim.uv.new_thread(function() end, function() end)
work:queue({})
]])
@@ -288,7 +288,7 @@ describe('threadpool', function()
})
exec_lua [[
- local work = vim.loop.new_work(function() return {} end, function() end)
+ local work = vim.uv.new_work(function() return {} end, function() end)
work:queue()
]]
@@ -319,7 +319,7 @@ describe('threadpool', function()
function Threadpool_Test:do_test()
local work =
- vim.loop.new_work(self.work_fn, self.after_work)
+ vim.uv.new_work(self.work_fn, self.after_work)
work:queue(self.work_fn_str, self.args)
end
@@ -334,10 +334,10 @@ describe('threadpool', function()
]]
end)
- it('loop', function()
+ it('uv', function()
exec_lua [[
local work_fn = function()
- return vim.loop.version()
+ return vim.uv.version()
end
local after_work_fn = function(ret)
vim.rpcnotify(1, ret)
diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua
index 6481da900e..373d45da61 100644
--- a/test/functional/lua/ui_event_spec.lua
+++ b/test/functional/lua/ui_event_spec.lua
@@ -77,13 +77,7 @@ describe('vim.ui_attach', function()
}
feed '<c-y>'
- screen:expect{grid=[[
- foobar^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]], intermediate=true}
+ screen:expect_unchanged()
expect_events {
{ "popupmenu_hide" };
}
diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua
index 9ee99b4905..d4c150c5f2 100644
--- a/test/functional/lua/ui_spec.lua
+++ b/test/functional/lua/ui_spec.lua
@@ -1,9 +1,12 @@
local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
+local matches = helpers.matches
local exec_lua = helpers.exec_lua
local clear = helpers.clear
local feed = helpers.feed
local eval = helpers.eval
+local is_ci = helpers.is_ci
+local is_os = helpers.is_os
local poke_eventloop = helpers.poke_eventloop
describe('vim.ui', function()
@@ -11,8 +14,7 @@ describe('vim.ui', function()
clear()
end)
-
- describe('select', function()
+ describe('select()', function()
it('can select an item', function()
local result = exec_lua[[
local items = {
@@ -47,7 +49,7 @@ describe('vim.ui', function()
end)
end)
- describe('input', function()
+ describe('input()', function()
it('can input text', function()
local result = exec_lua[[
local opts = {
@@ -130,4 +132,23 @@ describe('vim.ui', function()
end)
end)
+
+ describe('open()', function()
+ it('validation', function()
+ if is_os('win') or not is_ci('github') then
+ exec_lua[[vim.system = function() return { wait=function() return { code=3} end } end]]
+ end
+ if not is_os('bsd') then
+ matches('vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }',
+ exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]])
+ end
+
+ exec_lua[[
+ vim.fn.has = function() return 0 end
+ vim.fn.executable = function() return 0 end
+ ]]
+ eq('vim.ui.open: no handler found (tried: wslview, xdg-open)',
+ exec_lua[[local _, err = vim.ui.open('foo') ; return err]])
+ end)
+ end)
end)
diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua
new file mode 100644
index 0000000000..d1c981c388
--- /dev/null
+++ b/test/functional/lua/version_spec.lua
@@ -0,0 +1,273 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+local ok = helpers.ok
+local exec_lua = helpers.exec_lua
+local matches = helpers.matches
+local pcall_err = helpers.pcall_err
+
+local function v(ver)
+ return vim.version._version(ver)
+end
+
+describe('version', function()
+
+ it('package', function()
+ clear()
+ eq({ major = 42, minor = 3, patch = 99 }, exec_lua("return vim.version.parse('v42.3.99')"))
+ end)
+
+ it('version() returns Nvim version', function()
+ local expected = exec_lua('return vim.fn.api_info().version')
+ local actual = exec_lua('return vim.version()')
+ eq(expected.major, actual.major)
+ eq(expected.minor, actual.minor)
+ eq(expected.patch, actual.patch)
+ eq(expected.prerelease and 'dev' or nil, actual.prerelease)
+
+ -- tostring() #23863
+ matches([[%d+%.%d+%.%d+]], exec_lua('return tostring(vim.version())'))
+ end)
+
+ describe('_version()', function()
+ local tests = {
+ ['v1.2.3'] = { major = 1, minor = 2, patch = 3 },
+ ['v1.2'] = { major = 1, minor = 2, patch = 0 },
+ ['v1.2.3-prerelease'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease' },
+ ['v1.2-prerelease'] = { major = 1, minor = 2, patch = 0, prerelease = 'prerelease' },
+ ['v1.2.3-prerelease+build'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease', build = 'build' },
+ ['1.2.3+build'] = { major = 1, minor = 2, patch = 3, build = 'build' },
+ }
+ for input, output in pairs(tests) do
+ it('parses ' .. input, function()
+ eq(output, v(input))
+ end)
+ end
+ end)
+
+ describe('range', function()
+ local tests = {
+ ['1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 4 } },
+ ['1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
+ ['=1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 4 } },
+ ['>1.2.3'] = { from = { 1, 2, 4 } },
+ ['>=1.2.3'] = { from = { 1, 2, 3 } },
+ ['<1.2.3'] = { from = { 0, 0, 0 }, to = { 1, 2, 3 } },
+ ['<=1.2.3'] = { from = { 0, 0, 0 }, to = { 1, 2, 4 } },
+ ['~1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 3, 0 } },
+ ['^1.2.3'] = { from = { 1, 2, 3 }, to = { 2, 0, 0 } },
+ ['^0.2.3'] = { from = { 0, 2, 3 }, to = { 0, 3, 0 } },
+ ['^0.0.1'] = { from = { 0, 0, 1 }, to = { 0, 0, 2 } },
+ ['^1.2'] = { from = { 1, 2, 0 }, to = { 2, 0, 0 } },
+ ['~1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
+ ['~1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
+ ['^1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
+ ['1.*'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
+ ['1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
+ ['1.x'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
+ ['1.2.x'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
+ ['1.2.*'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
+ ['*'] = { from = { 0, 0, 0 } },
+ ['1.2 - 2.3.0'] = { from = { 1, 2, 0 }, to = { 2, 3, 0 } },
+ ['1.2.3 - 2.3.4'] = { from = { 1, 2, 3 }, to = { 2, 3, 4 } },
+ ['1.2.3 - 2'] = { from = { 1, 2, 3 }, to = { 3, 0, 0 } },
+ }
+ for input, output in pairs(tests) do
+ output.from = v(output.from)
+ output.to = output.to and v(output.to)
+ local range = vim.version.range(input)
+
+ it('parses ' .. input, function()
+ eq(output, range)
+ end)
+
+ it('[from] in range ' .. input, function()
+ assert(range:has(output.from))
+ end)
+
+ it('[from-1] not in range ' .. input, function()
+ local lower = vim.deepcopy(range.from)
+ lower.major = lower.major - 1
+ assert(not range:has(lower))
+ end)
+
+ it('[to] not in range ' .. input .. ' to:' .. tostring(range.to), function()
+ if range.to then
+ assert(not (range.to < range.to))
+ assert(not range:has(range.to))
+ end
+ end)
+ end
+
+ it('handles prerelease', function()
+ assert(not vim.version.range('1.2.3'):has('1.2.3-alpha'))
+ assert(vim.version.range('1.2.3-alpha'):has('1.2.3-alpha'))
+ assert(not vim.version.range('1.2.3-alpha'):has('1.2.3-beta'))
+ end)
+ end)
+
+ describe('cmp()', function()
+ local testcases = {
+ { v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1, },
+ { v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1, },
+ { v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1, },
+ { v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0, },
+ { v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1, },
+ { v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1, },
+ { v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1, },
+ { v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0, },
+
+ -- prerelease 💩 https://semver.org/#spec-item-11
+ { v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1, },
+ { v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1, },
+ { v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1, },
+ { v1 = '1.0.0-2', v2 = '1.0.0-9', want = -1, },
+ { v1 = '1.0.0-2', v2 = '1.0.0-2.0', want = -1, },
+ { v1 = '1.0.0-2.0', v2 = '1.0.0-2', want = 1, },
+ { v1 = '1.0.0-2.0', v2 = '1.0.0-2.0', want = 0, },
+ { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha', want = 0, },
+ { v1 = '1.0.0-alpha', v2 = '1.0.0-beta', want = -1, },
+ { v1 = '1.0.0-beta', v2 = '1.0.0-alpha', want = 1, },
+ { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.1', want = -1, },
+ { v1 = '1.0.0-alpha.1', v2 = '1.0.0-alpha', want = 1, },
+ { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1, },
+ { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1, },
+ { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1, },
+ { v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1, },
+ { v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1, },
+ { v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1, },
+ { v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0, },
+ { v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1, },
+ }
+ for _, tc in ipairs(testcases) do
+ local msg = function(s) return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<')) end
+ it(string.format('(v1 = %s, v2 = %s)', tc.v1, tc.v2),
+ function()
+ local rv = vim.version.cmp(tc.v1, tc.v2, { strict = true })
+ ok(tc.want == rv, msg(tc.want), msg(rv))
+ end
+ )
+ end
+ end)
+
+ describe('parse()', function()
+ describe('strict=true', function()
+ local testcases = {
+ { desc = 'Nvim version', version = 'v0.9.0-dev-1233+g210120dde81e', want = { major = 0, minor = 9, patch = 0, prerelease = 'dev-1233', build = 'g210120dde81e', }, },
+ { desc = 'no v', version = '10.20.123', want = { major = 10, minor = 20, patch = 123, prerelease = nil, build = nil, }, },
+ { desc = 'with v', version = 'v1.2.3', want = { major = 1, minor = 2, patch = 3 }, },
+ { desc = 'prerelease', version = '1.2.3-alpha', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' }, },
+ { desc = 'prerelease.x', version = '1.2.3-alpha.1', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' }, },
+ { desc = 'build.x', version = '1.2.3+build.15', want = { major = 1, minor = 2, patch = 3, build = 'build.15' }, },
+ { desc = 'prerelease and build', version = '1.2.3-rc1+build.15', want = { major = 1, minor = 2, patch = 3, prerelease = 'rc1', build = 'build.15', }, },
+ }
+ for _, tc in ipairs(testcases) do
+ it(
+ string.format('%q: version = %q', tc.desc, tc.version),
+ function()
+ eq(tc.want, vim.version.parse(tc.version))
+ end
+ )
+ end
+ end)
+
+ describe('strict=false', function()
+ local testcases = {
+ { version = '1.2', want = { major = 1, minor = 2, patch = 0 }, },
+ { version = '1', want = { major = 1, minor = 0, patch = 0 }, },
+ { version = '1.1-0', want = { major = 1, minor = 1, patch = 0, prerelease = '0' }, },
+ { version = '1-1.0', want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' }, },
+ { version = 'v1.2.3 ', want = { major = 1, minor = 2, patch = 3 }, },
+ { version = ' v1.2.3', want = { major = 1, minor = 2, patch = 3 }, },
+ { version = 'tmux 3.2a', want = { major = 3, minor = 2, patch = 0, }, },
+ }
+ for _, tc in ipairs(testcases) do
+ it(
+ string.format('version = %q', tc.version),
+ function()
+ eq(tc.want, vim.version.parse(tc.version, { strict = false }))
+ end
+ )
+ end
+ end)
+
+ describe('invalid semver', function()
+ local testcases = {
+ { version = 'foo' },
+ { version = '' },
+ { version = '0.0.0.' },
+ { version = '.0.0.0' },
+ { version = '-1.0.0' },
+ { version = '0.-1.0' },
+ { version = '0.0.-1' },
+ { version = 'foobar1.2.3' },
+ { version = '1.2.3foobar' },
+ { version = '1.2.3-%?' },
+ { version = '1.2.3+%?' },
+ { version = '1.2.3+build.0-rc1' },
+ { version = '3.2a', },
+ { version = 'tmux 3.2a', },
+ }
+
+ local function quote_empty(s)
+ return tostring(s) == '' and '""' or tostring(s)
+ end
+
+ for _, tc in ipairs(testcases) do
+ it(quote_empty(tc.version), function()
+ eq(nil, vim.version.parse(tc.version, { strict = true }))
+ end)
+ end
+ end)
+
+ describe('invalid shape', function()
+ local testcases = {
+ { desc = 'no parameters' },
+ { desc = 'nil', version = nil },
+ { desc = 'number', version = 0 },
+ { desc = 'float', version = 0.01 },
+ { desc = 'table', version = {} },
+ }
+ for _, tc in ipairs(testcases) do
+ it(string.format('(%s): %s', tc.desc, tostring(tc.version)), function()
+ local expected = string.format(type(tc.version) == 'string'
+ and 'invalid version: "%s"' or 'invalid version: %s', tostring(tc.version))
+ matches(expected, pcall_err(vim.version.parse, tc.version, { strict = true }))
+ end)
+ end
+ end)
+ end)
+
+ it('relational metamethods (== < >)', function()
+ assert(v('v1.2.3') == v('1.2.3'))
+ assert(not (v('v1.2.3') < v('1.2.3')))
+ assert(v('v1.2.3') > v('1.2.3-prerelease'))
+ assert(v('v1.2.3-alpha') < v('1.2.3-beta'))
+ assert(v('v1.2.3-prerelease') < v('1.2.3'))
+ assert(v('v1.2.3') >= v('1.2.3'))
+ assert(v('v1.2.3') >= v('1.0.3'))
+ assert(v('v1.2.3') >= v('1.2.2'))
+ assert(v('v1.2.3') > v('1.2.2'))
+ assert(v('v1.2.3') > v('1.0.3'))
+ eq(vim.version.last({ v('1.2.3'), v('2.0.0') }), v('2.0.0'))
+ eq(vim.version.last({ v('2.0.0'), v('1.2.3') }), v('2.0.0'))
+ end)
+
+ it('lt()', function()
+ eq(true, vim.version.lt('1', '2'))
+ eq(false, vim.version.lt({3}, {0, 7, 4}))
+ eq(false, vim.version.lt({major=3, minor=3, patch=0}, {3, 2, 0}))
+ end)
+
+ it('gt()', function()
+ eq(true, vim.version.gt('2', '1'))
+ eq(true, vim.version.gt({3}, {0, 7, 4}))
+ eq(true, vim.version.gt({major=3, minor=3, patch=0}, {3, 2, 0}))
+ end)
+
+ it('eq()', function()
+ eq(true, vim.version.eq('2', '2'))
+ eq(true, vim.version.eq({3, 1, 0}, '3.1.0'))
+ eq(true, vim.version.eq({major=3, minor=3, patch=0}, {3, 3, 0}))
+ end)
+end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 867f366d06..ebe5fc254e 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -6,10 +6,12 @@ local nvim_prog = helpers.nvim_prog
local funcs = helpers.funcs
local meths = helpers.meths
local command = helpers.command
+local dedent = helpers.dedent
local insert = helpers.insert
local clear = helpers.clear
local eq = helpers.eq
local ok = helpers.ok
+local pesc = helpers.pesc
local eval = helpers.eval
local feed = helpers.feed
local pcall_err = helpers.pcall_err
@@ -126,6 +128,22 @@ describe('lua stdlib', function()
eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
end)
+ it('vim.deprecate', function()
+ -- vim.deprecate(name, alternative, version, plugin, backtrace)
+ eq(dedent[[
+ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated
+ This feature will be removed in Nvim version 2.17]],
+ exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '2.17'))
+ -- Same message, skipped.
+ eq(vim.NIL,
+ exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '2.17'))
+ -- When `plugin` is specified, don't show ":help deprecated". #22235
+ eq(dedent[[
+ foo.bar() is deprecated, use zub.wooo{ok=yay} instead.
+ This feature will be removed in my-plugin.nvim version 0.3.0]],
+ exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.3.0', 'my-plugin.nvim', false))
+ end)
+
it('vim.startswith', function()
eq(true, funcs.luaeval('vim.startswith("123", "1")'))
eq(true, funcs.luaeval('vim.startswith("123", "")'))
@@ -259,7 +277,7 @@ describe('lua stdlib', function()
|
]]}
- -- nvim_command causes a vimL exception, check that it is properly caught
+ -- nvim_command causes a Vimscript exception, check that it is properly caught
-- and propagated as an error message in async contexts.. #10809
exec_lua([[
vim.schedule(function()
@@ -275,51 +293,53 @@ describe('lua stdlib', function()
]]}
end)
- it("vim.split", function()
- local split = function(str, sep, kwargs)
- return exec_lua('return vim.split(...)', str, sep, kwargs)
- end
-
+ it('vim.gsplit, vim.split', function()
local tests = {
- { "a,b", ",", false, false, { 'a', 'b' } },
- { ":aa::bb:", ":", false, false, { '', 'aa', '', 'bb', '' } },
- { ":aa::bb:", ":", false, true, { 'aa', '', 'bb' } },
- { "::ee::ff:", ":", false, false, { '', '', 'ee', '', 'ff', '' } },
- { "::ee::ff:", ":", false, true, { 'ee', '', 'ff' } },
- { "ab", ".", false, false, { '', '', '' } },
- { "a1b2c", "[0-9]", false, false, { 'a', 'b', 'c' } },
- { "xy", "", false, false, { 'x', 'y' } },
- { "here be dragons", " ", false, false, { "here", "be", "dragons"} },
- { "axaby", "ab?", false, false, { '', 'x', 'y' } },
- { "f v2v v3v w2w ", "([vw])2%1", false, false, { 'f ', ' v3v ', ' ' } },
- { "", "", false, false, {} },
- { "", "a", false, false, { '' } },
- { "x*yz*oo*l", "*", true, false, { 'x', 'yz', 'oo', 'l' } },
+ -- plain trimempty
+ { 'a,b', ',', false, false, { 'a', 'b' } },
+ { ':aa::::bb:', ':', false, false, { '', 'aa', '', '', '', 'bb', '' } },
+ { ':aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } },
+ { 'aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } },
+ { ':aa::bb:', ':', false, true, { 'aa', '', 'bb' } },
+ { '/a/b:/b/\n', '[:\n]', false, true, { '/a/b', '/b/' } },
+ { '::ee::ff:', ':', false, false, { '', '', 'ee', '', 'ff', '' } },
+ { '::ee::ff::', ':', false, true, { 'ee', '', 'ff' } },
+ { 'ab', '.', false, false, { '', '', '' } },
+ { 'a1b2c', '[0-9]', false, false, { 'a', 'b', 'c' } },
+ { 'xy', '', false, false, { 'x', 'y' } },
+ { 'here be dragons', ' ', false, false, { 'here', 'be', 'dragons'} },
+ { 'axaby', 'ab?', false, false, { '', 'x', 'y' } },
+ { 'f v2v v3v w2w ', '([vw])2%1', false, false, { 'f ', ' v3v ', ' ' } },
+ { '', '', false, false, {} },
+ { '', '', false, true, {} },
+ { '\n', '[:\n]', false, true, {} },
+ { '', 'a', false, false, { '' } },
+ { 'x*yz*oo*l', '*', true, false, { 'x', 'yz', 'oo', 'l' } },
}
for _, t in ipairs(tests) do
- eq(t[5], split(t[1], t[2], {plain=t[3], trimempty=t[4]}))
+ eq(t[5], vim.split(t[1], t[2], {plain=t[3], trimempty=t[4]}), t[1])
end
-- Test old signature
- eq({'x', 'yz', 'oo', 'l'}, split("x*yz*oo*l", "*", true))
+ eq({'x', 'yz', 'oo', 'l'}, vim.split("x*yz*oo*l", "*", true))
local loops = {
{ "abc", ".-" },
}
for _, t in ipairs(loops) do
- matches("Infinite loop detected", pcall_err(split, t[1], t[2]))
+ matches("Infinite loop detected", pcall_err(vim.split, t[1], t[2]))
end
-- Validates args.
- eq(true, pcall(split, 'string', 'string'))
+ eq(true, pcall(vim.split, 'string', 'string'))
matches('s: expected string, got number',
- pcall_err(split, 1, 'string'))
+ pcall_err(vim.split, 1, 'string'))
matches('sep: expected string, got number',
- pcall_err(split, 'string', 1))
- matches('kwargs: expected table, got number',
- pcall_err(split, 'string', 'string', 1))
+ pcall_err(vim.split, 'string', 1))
+ matches('opts: expected table, got number',
+ pcall_err(vim.split, 'string', 'string', 1))
end)
it('vim.trim', function()
@@ -444,6 +464,22 @@ describe('lua stdlib', function()
pcall_err(exec_lua, [[return vim.pesc(2)]]))
end)
+ it('vim.list_contains', function()
+ eq(true, exec_lua("return vim.list_contains({'a','b','c'}, 'c')"))
+ eq(false, exec_lua("return vim.list_contains({'a','b','c'}, 'd')"))
+ end)
+
+ it('vim.tbl_contains', function()
+ eq(true, exec_lua("return vim.tbl_contains({'a','b','c'}, 'c')"))
+ eq(false, exec_lua("return vim.tbl_contains({'a','b','c'}, 'd')"))
+ eq(true, exec_lua("return vim.tbl_contains({[2]='a',foo='b',[5] = 'c'}, 'c')"))
+ eq(true, exec_lua([[
+ return vim.tbl_contains({ 'a', { 'b', 'c' } }, function(v)
+ return vim.deep_equal(v, { 'b', 'c' })
+ end, { predicate = true })
+ ]]))
+ end)
+
it('vim.tbl_keys', function()
eq({}, exec_lua("return vim.tbl_keys({})"))
for _, v in pairs(exec_lua("return vim.tbl_keys({'a', 'b', 'c'})")) do
@@ -488,6 +524,19 @@ describe('lua stdlib', function()
]]))
end)
+ it('vim.tbl_isarray', function()
+ eq(true, exec_lua("return vim.tbl_isarray({})"))
+ eq(false, exec_lua("return vim.tbl_isarray(vim.empty_dict())"))
+ eq(true, exec_lua("return vim.tbl_isarray({'a', 'b', 'c'})"))
+ eq(false, exec_lua("return vim.tbl_isarray({'a', '32', a='hello', b='baz'})"))
+ eq(false, exec_lua("return vim.tbl_isarray({1, a='hello', b='baz'})"))
+ eq(false, exec_lua("return vim.tbl_isarray({a='hello', b='baz', 1})"))
+ eq(false, exec_lua("return vim.tbl_isarray({1, 2, nil, a='hello'})"))
+ eq(true, exec_lua("return vim.tbl_isarray({1, 2, nil, 4})"))
+ eq(true, exec_lua("return vim.tbl_isarray({nil, 2, 3, 4})"))
+ eq(false, exec_lua("return vim.tbl_isarray({1, [1.5]=2, [3]=3})"))
+ end)
+
it('vim.tbl_islist', function()
eq(true, exec_lua("return vim.tbl_islist({})"))
eq(false, exec_lua("return vim.tbl_islist(vim.empty_dict())"))
@@ -496,6 +545,9 @@ describe('lua stdlib', function()
eq(false, exec_lua("return vim.tbl_islist({1, a='hello', b='baz'})"))
eq(false, exec_lua("return vim.tbl_islist({a='hello', b='baz', 1})"))
eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, a='hello'})"))
+ eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, 4})"))
+ eq(false, exec_lua("return vim.tbl_islist({nil, 2, 3, 4})"))
+ eq(false, exec_lua("return vim.tbl_islist({1, [1.5]=2, [3]=3})"))
end)
it('vim.tbl_isempty', function()
@@ -780,7 +832,7 @@ describe('lua stdlib', function()
it('vim.call, vim.fn', function()
eq(true, exec_lua([[return vim.call('sin', 0.0) == 0.0 ]]))
eq(true, exec_lua([[return vim.fn.sin(0.0) == 0.0 ]]))
- -- compat: nvim_call_function uses "special" value for vimL float
+ -- compat: nvim_call_function uses "special" value for Vimscript float
eq(false, exec_lua([[return vim.api.nvim_call_function('sin', {0.0}) == 0.0 ]]))
exec([[
@@ -831,7 +883,7 @@ describe('lua stdlib', function()
it('vim.fn is allowed in "fast" context by some functions #18306', function()
exec_lua([[
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(0, 0, function()
timer:close()
assert(vim.in_fast_event())
@@ -897,7 +949,7 @@ describe('lua stdlib', function()
})
screen:attach()
exec_lua([[
- timer = vim.loop.new_timer()
+ timer = vim.uv.new_timer()
timer:start(20, 0, function ()
-- notify ok (executed later when safe)
vim.rpcnotify(chan, 'nvim_set_var', 'yy', {3, vim.NIL})
@@ -1440,14 +1492,68 @@ describe('lua stdlib', function()
eq(NIL, funcs.luaeval "vim.v.null")
matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.v[0].progpath'))
+ eq('Key is read-only: count', pcall_err(exec_lua, [[vim.v.count = 42]]))
+ eq('Dictionary is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]]))
+ eq('Key is fixed: errmsg', pcall_err(exec_lua, [[vim.v.errmsg = nil]]))
+ exec_lua([[vim.v.errmsg = 'set by Lua']])
+ eq('set by Lua', eval('v:errmsg'))
+ exec_lua([[vim.v.errmsg = 42]])
+ eq('42', eval('v:errmsg'))
+ exec_lua([[vim.v.oldfiles = { 'one', 'two' }]])
+ eq({ 'one', 'two' }, eval('v:oldfiles'))
+ exec_lua([[vim.v.oldfiles = {}]])
+ eq({}, eval('v:oldfiles'))
+ eq('Setting v:oldfiles to value with wrong type', pcall_err(exec_lua, [[vim.v.oldfiles = 'a']]))
+ eq({}, eval('v:oldfiles'))
+
+ feed('i foo foo foo<Esc>0/foo<CR>')
+ eq({1, 1}, meths.win_get_cursor(0))
+ eq(1, eval('v:searchforward'))
+ feed('n')
+ eq({1, 5}, meths.win_get_cursor(0))
+ exec_lua([[vim.v.searchforward = 0]])
+ eq(0, eval('v:searchforward'))
+ feed('n')
+ eq({1, 1}, meths.win_get_cursor(0))
+ exec_lua([[vim.v.searchforward = 1]])
+ eq(1, eval('v:searchforward'))
+ feed('n')
+ eq({1, 5}, meths.win_get_cursor(0))
+
+ local screen = Screen.new(60, 3)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ [1] = {background = Screen.colors.Yellow},
+ })
+ screen:attach()
+ eq(1, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ {1:foo} {1:^foo} {1:foo} |
+ {0:~ }|
+ |
+ ]]}
+ exec_lua([[vim.v.hlsearch = 0]])
+ eq(0, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ foo ^foo foo |
+ {0:~ }|
+ |
+ ]]}
+ exec_lua([[vim.v.hlsearch = 1]])
+ eq(1, eval('v:hlsearch'))
+ screen:expect{grid=[[
+ {1:foo} {1:^foo} {1:foo} |
+ {0:~ }|
+ |
+ ]]}
end)
it('vim.bo', function()
eq('', funcs.luaeval "vim.bo.filetype")
exec_lua [[
- vim.api.nvim_buf_set_option(0, "filetype", "markdown")
+ vim.api.nvim_set_option_value("filetype", "markdown", {})
BUF = vim.api.nvim_create_buf(false, true)
- vim.api.nvim_buf_set_option(BUF, "modifiable", false)
+ vim.api.nvim_set_option_value("modifiable", false, {buf = BUF})
]]
eq(false, funcs.luaeval "vim.bo.modified")
eq('markdown', funcs.luaeval "vim.bo.filetype")
@@ -1458,9 +1564,9 @@ describe('lua stdlib', function()
]]
eq('', funcs.luaeval "vim.bo.filetype")
eq(true, funcs.luaeval "vim.bo[BUF].modifiable")
- matches("no such option: 'nosuchopt'$",
+ matches("Unknown option 'nosuchopt'$",
pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
- matches("Expected lua string$",
+ matches("Expected Lua string$",
pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
matches("Invalid buffer id: %-1$",
pcall_err(exec_lua, 'return vim.bo[-1].filetype'))
@@ -1468,9 +1574,9 @@ describe('lua stdlib', function()
it('vim.wo', function()
exec_lua [[
- vim.api.nvim_win_set_option(0, "cole", 2)
+ vim.api.nvim_set_option_value("cole", 2, {})
vim.cmd "split"
- vim.api.nvim_win_set_option(0, "cole", 2)
+ vim.api.nvim_set_option_value("cole", 2, {})
]]
eq(2, funcs.luaeval "vim.wo.cole")
exec_lua [[
@@ -1479,10 +1585,8 @@ describe('lua stdlib', function()
eq(0, funcs.luaeval "vim.wo.cole")
eq(0, funcs.luaeval "vim.wo[0].cole")
eq(0, funcs.luaeval "vim.wo[1001].cole")
- matches("no such option: 'notanopt'$",
+ matches("Unknown option 'notanopt'$",
pcall_err(exec_lua, 'return vim.wo.notanopt'))
- matches("Expected lua string$",
- pcall_err(exec_lua, 'return vim.wo[0][0].list'))
matches("Invalid window id: %-1$",
pcall_err(exec_lua, 'return vim.wo[-1].list'))
eq(2, funcs.luaeval "vim.wo[1000].cole")
@@ -1497,6 +1601,11 @@ describe('lua stdlib', function()
eq(200, funcs.luaeval "vim.wo.scrolloff")
exec_lua [[vim.wo.scrolloff = -1]]
eq(100, funcs.luaeval "vim.wo.scrolloff")
+ exec_lua [[
+ vim.wo[0][0].scrolloff = 200
+ vim.cmd "enew"
+ ]]
+ eq(100, funcs.luaeval "vim.wo.scrolloff")
end)
describe('vim.opt', function()
@@ -1515,8 +1624,8 @@ describe('lua stdlib', function()
local result = exec_lua [[
local result = {}
- table.insert(result, vim.api.nvim_get_option('scrolloff'))
- table.insert(result, vim.api.nvim_win_get_option(0, 'scrolloff'))
+ table.insert(result, vim.api.nvim_get_option_value('scrolloff', {scope='global'}))
+ table.insert(result, vim.api.nvim_get_option_value('scrolloff', {win=0}))
return result
]]
@@ -1580,20 +1689,20 @@ describe('lua stdlib', function()
local result = {}
vim.opt.makeprg = "global-local"
- table.insert(result, vim.api.nvim_get_option('makeprg'))
- table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
+ table.insert(result, vim.go.makeprg)
+ table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt_local.mp = "only-local"
- table.insert(result, vim.api.nvim_get_option('makeprg'))
- table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
+ table.insert(result, vim.go.makeprg)
+ table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt_global.makeprg = "only-global"
- table.insert(result, vim.api.nvim_get_option('makeprg'))
- table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
+ table.insert(result, vim.go.makeprg)
+ table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt.makeprg = "global-local"
- table.insert(result, vim.api.nvim_get_option('makeprg'))
- table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
+ table.insert(result, vim.go.makeprg)
+ table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
return result
]]
@@ -2122,7 +2231,7 @@ describe('lua stdlib', function()
it('can handle isfname ,,,', function()
local result = exec_lua [[
vim.opt.isfname = "a,b,,,c"
- return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') }
+ return { vim.opt.isfname:get(), vim.go.isfname }
]]
eq({{",", "a", "b", "c"}, "a,b,,,c"}, result)
@@ -2132,7 +2241,7 @@ describe('lua stdlib', function()
it('can handle isfname ,^,,', function()
local result = exec_lua [[
vim.opt.isfname = "a,b,^,,c"
- return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') }
+ return { vim.opt.isfname:get(), vim.go.isfname }
]]
eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result)
@@ -2203,8 +2312,8 @@ describe('lua stdlib', function()
end)
end) -- vim.opt
- describe('opt_local', function()
- it('should be able to append to an array list type option', function()
+ describe('vim.opt_local', function()
+ it('appends into global value when changing local option value', function()
eq({ "foo,bar,baz,qux" }, exec_lua [[
local result = {}
@@ -2219,6 +2328,19 @@ describe('lua stdlib', function()
end)
end)
+ describe('vim.opt_global', function()
+ it('gets current global option value', function()
+ eq({ "yes" }, exec_lua [[
+ local result = {}
+
+ vim.cmd "setglobal signcolumn=yes"
+ table.insert(result, vim.opt_global.signcolumn:get())
+
+ return result
+ ]])
+ end)
+ end)
+
it('vim.cmd', function()
exec_lua [[
vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('<abuf>')"
@@ -2269,17 +2391,36 @@ describe('lua stdlib', function()
describe('vim.region', function()
it('charwise', function()
- insert(helpers.dedent( [[
+ insert(dedent( [[
text tααt tααt text
text tαxt txtα tex
text tαxt tαxt
]]))
- eq({5,15}, exec_lua[[ return vim.region(0,{1,5},{1,14},'v',true)[1] ]])
+ eq({5,13}, exec_lua[[ return vim.region(0,{0,5},{0,13},'v',false)[0] ]])
+ eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,13},'v',true)[0] ]])
+ eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,14},'v',true)[0] ]])
+ eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,15},'v',false)[0] ]])
+ eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,15},'v',true)[0] ]])
+ eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,16},'v',true)[0] ]])
+ eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,17},'v',false)[0] ]])
+ eq({5,18}, exec_lua[[ return vim.region(0,{0,5},{0,17},'v',true)[0] ]])
end)
it('blockwise', function()
insert([[αα]])
eq({0,5}, exec_lua[[ return vim.region(0,{0,0},{0,4},'3',true)[0] ]])
end)
+ it('linewise', function()
+ insert(dedent( [[
+ text tααt tααt text
+ text tαxt txtα tex
+ text tαxt tαxt
+ ]]))
+ eq({0,-1}, exec_lua[[ return vim.region(0,{1,5},{1,14},'V',true)[1] ]])
+ end)
+ it('getpos() input', function()
+ insert('getpos')
+ eq({0,6}, exec_lua[[ return vim.region(0,{0,0},'.','v',true)[0] ]])
+ end)
end)
describe('vim.on_key', function()
@@ -2305,6 +2446,12 @@ describe('lua stdlib', function()
end)
it('allows removing on_key listeners', function()
+ -- Create some unused namespaces
+ meths.create_namespace('unused1')
+ meths.create_namespace('unused2')
+ meths.create_namespace('unused3')
+ meths.create_namespace('unused4')
+
insert([[hello world]])
exec_lua [[
@@ -2420,13 +2567,12 @@ describe('lua stdlib', function()
]])
end)
-
it('should not block other events', function()
eq({time = true, wait_result = true}, exec_lua[[
start_time = get_time()
vim.g.timer_result = false
- timer = vim.loop.new_timer()
+ timer = vim.uv.new_timer()
timer:start(100, 0, vim.schedule_wrap(function()
vim.g.timer_result = true
end))
@@ -2448,7 +2594,7 @@ describe('lua stdlib', function()
start_time = get_time()
vim.g.timer_result = false
- timer = vim.loop.new_timer()
+ timer = vim.uv.new_timer()
timer:start(100, 0, vim.schedule_wrap(function()
vim.g.timer_result = true
end))
@@ -2462,6 +2608,7 @@ describe('lua stdlib', function()
}
]])
end)
+
it('should work with vim.defer_fn', function()
eq({time = true, wait_result = true}, exec_lua[[
start_time = get_time()
@@ -2491,17 +2638,17 @@ describe('lua stdlib', function()
it('should allow waiting with no callback, explicit', function()
eq(true, exec_lua [[
- local start_time = vim.loop.hrtime()
+ local start_time = vim.uv.hrtime()
vim.wait(50, nil)
- return vim.loop.hrtime() - start_time > 25000
+ return vim.uv.hrtime() - start_time > 25000
]])
end)
it('should allow waiting with no callback, implicit', function()
eq(true, exec_lua [[
- local start_time = vim.loop.hrtime()
+ local start_time = vim.uv.hrtime()
vim.wait(50)
- return vim.loop.hrtime() - start_time > 25000
+ return vim.uv.hrtime() - start_time > 25000
]])
end)
@@ -2623,6 +2770,23 @@ describe('lua stdlib', function()
eq({'notification', 'wait', {-2}}, next_msg(500))
end)
end)
+
+ it('should not run in fast callbacks #26122', function()
+ local screen = Screen.new(80, 10)
+ screen:attach()
+ exec_lua([[
+ local timer = vim.uv.new_timer()
+ timer:start(0, 0, function()
+ timer:close()
+ vim.wait(100, function() end)
+ end)
+ ]])
+ screen:expect({
+ any = pesc('E5560: vim.wait must not be called in a lua loop callback'),
+ })
+ feed('<CR>')
+ assert_alive()
+ end)
end)
it('vim.notify_once', function()
@@ -2679,14 +2843,14 @@ describe('lua stdlib', function()
describe('vim.api.nvim_buf_call', function()
it('can access buf options', function()
- local buf1 = meths.get_current_buf()
+ local buf1 = meths.get_current_buf().id
local buf2 = exec_lua [[
buf2 = vim.api.nvim_create_buf(false, true)
return buf2
]]
- eq(false, meths.buf_get_option(buf1, 'autoindent'))
- eq(false, meths.buf_get_option(buf2, 'autoindent'))
+ eq(false, meths.get_option_value('autoindent', {buf=buf1}))
+ eq(false, meths.get_option_value('autoindent', {buf=buf2}))
local val = exec_lua [[
return vim.api.nvim_buf_call(buf2, function()
@@ -2695,20 +2859,20 @@ describe('lua stdlib', function()
end)
]]
- eq(false, meths.buf_get_option(buf1, 'autoindent'))
- eq(true, meths.buf_get_option(buf2, 'autoindent'))
- eq(buf1, meths.get_current_buf())
+ eq(false, meths.get_option_value('autoindent', {buf=buf1}))
+ eq(true, meths.get_option_value('autoindent', {buf=buf2}))
+ eq(buf1, meths.get_current_buf().id)
eq(buf2, val)
end)
it('does not cause ml_get errors with invalid visual selection', function()
-- Should be fixed by vim-patch:8.2.4028.
exec_lua [[
- local a = vim.api
- local t = function(s) return a.nvim_replace_termcodes(s, true, true, true) end
- a.nvim_buf_set_lines(0, 0, -1, true, {"a", "b", "c"})
- a.nvim_feedkeys(t "G<C-V>", "txn", false)
- a.nvim_buf_call(a.nvim_create_buf(false, true), function() vim.cmd "redraw" end)
+ local api = vim.api
+ local t = function(s) return api.nvim_replace_termcodes(s, true, true, true) end
+ api.nvim_buf_set_lines(0, 0, -1, true, {"a", "b", "c"})
+ api.nvim_feedkeys(t "G<C-V>", "txn", false)
+ api.nvim_buf_call(api.nvim_create_buf(false, true), function() vim.cmd "redraw" end)
]]
end)
@@ -2716,10 +2880,10 @@ describe('lua stdlib', function()
eq(true, exec_lua([[
local function scratch_buf_call(fn)
local buf = vim.api.nvim_create_buf(false, true)
- vim.api.nvim_buf_set_option(buf, 'cindent', true)
+ vim.api.nvim_set_option_value('cindent', true, {buf = buf})
return vim.api.nvim_buf_call(buf, function()
return vim.api.nvim_get_current_buf() == buf
- and vim.api.nvim_buf_get_option(buf, 'cindent')
+ and vim.api.nvim_get_option_value('cindent', {buf = buf})
and fn()
end) and vim.api.nvim_buf_delete(buf, {}) == nil
end
@@ -2756,7 +2920,7 @@ describe('lua stdlib', function()
describe('vim.api.nvim_win_call', function()
it('can access window options', function()
command('vsplit')
- local win1 = meths.get_current_win()
+ local win1 = meths.get_current_win().id
command('wincmd w')
local win2 = exec_lua [[
win2 = vim.api.nvim_get_current_win()
@@ -2764,8 +2928,8 @@ describe('lua stdlib', function()
]]
command('wincmd p')
- eq('', meths.win_get_option(win1, 'winhighlight'))
- eq('', meths.win_get_option(win2, 'winhighlight'))
+ eq('', meths.get_option_value('winhighlight', {win=win1}))
+ eq('', meths.get_option_value('winhighlight', {win=win2}))
local val = exec_lua [[
return vim.api.nvim_win_call(win2, function()
@@ -2774,38 +2938,38 @@ describe('lua stdlib', function()
end)
]]
- eq('', meths.win_get_option(win1, 'winhighlight'))
- eq('Normal:Normal', meths.win_get_option(win2, 'winhighlight'))
- eq(win1, meths.get_current_win())
+ eq('', meths.get_option_value('winhighlight', {win=win1}))
+ eq('Normal:Normal', meths.get_option_value('winhighlight', {win=win2}))
+ eq(win1, meths.get_current_win().id)
eq(win2, val)
end)
it('does not cause ml_get errors with invalid visual selection', function()
-- Add lines to the current buffer and make another window looking into an empty buffer.
exec_lua [[
- _G.a = vim.api
- _G.t = function(s) return a.nvim_replace_termcodes(s, true, true, true) end
- _G.win_lines = a.nvim_get_current_win()
+ _G.api = vim.api
+ _G.t = function(s) return api.nvim_replace_termcodes(s, true, true, true) end
+ _G.win_lines = api.nvim_get_current_win()
vim.cmd "new"
- _G.win_empty = a.nvim_get_current_win()
- a.nvim_set_current_win(win_lines)
- a.nvim_buf_set_lines(0, 0, -1, true, {"a", "b", "c"})
+ _G.win_empty = api.nvim_get_current_win()
+ api.nvim_set_current_win(win_lines)
+ api.nvim_buf_set_lines(0, 0, -1, true, {"a", "b", "c"})
]]
-- Start Visual in current window, redraw in other window with fewer lines.
-- Should be fixed by vim-patch:8.2.4018.
exec_lua [[
- a.nvim_feedkeys(t "G<C-V>", "txn", false)
- a.nvim_win_call(win_empty, function() vim.cmd "redraw" end)
+ api.nvim_feedkeys(t "G<C-V>", "txn", false)
+ api.nvim_win_call(win_empty, function() vim.cmd "redraw" end)
]]
-- Start Visual in current window, extend it in other window with more lines.
-- Fixed for win_execute by vim-patch:8.2.4026, but nvim_win_call should also not be affected.
exec_lua [[
- a.nvim_feedkeys(t "<Esc>gg", "txn", false)
- a.nvim_set_current_win(win_empty)
- a.nvim_feedkeys(t "gg<C-V>", "txn", false)
- a.nvim_win_call(win_lines, function() a.nvim_feedkeys(t "G<C-V>", "txn", false) end)
+ api.nvim_feedkeys(t "<Esc>gg", "txn", false)
+ api.nvim_set_current_win(win_empty)
+ api.nvim_feedkeys(t "gg<C-V>", "txn", false)
+ api.nvim_win_call(win_lines, function() api.nvim_feedkeys(t "G<C-V>", "txn", false) end)
vim.cmd "redraw"
]]
end)
@@ -2819,14 +2983,14 @@ describe('lua stdlib', function()
}
screen:attach()
exec_lua [[
- _G.a = vim.api
+ _G.api = vim.api
vim.opt.ruler = true
local lines = {}
for i = 0, 499 do lines[#lines + 1] = tostring(i) end
- a.nvim_buf_set_lines(0, 0, -1, true, lines)
- a.nvim_win_set_cursor(0, {20, 0})
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
+ api.nvim_win_set_cursor(0, {20, 0})
vim.cmd "split"
- _G.win = a.nvim_get_current_win()
+ _G.win = api.nvim_get_current_win()
vim.cmd "wincmd w | redraw"
]]
screen:expect [[
@@ -2837,7 +3001,7 @@ describe('lua stdlib', function()
|
]]
exec_lua [[
- a.nvim_win_call(win, function() a.nvim_win_set_cursor(0, {100, 0}) end)
+ api.nvim_win_call(win, function() api.nvim_win_set_cursor(0, {100, 0}) end)
vim.cmd "redraw"
]]
screen:expect [[
@@ -2898,8 +3062,133 @@ describe('lua stdlib', function()
return a
]])
end)
+
+ it('accepts the key name', function()
+ eq({ b = 'b', c = 'c' }, exec_lua [[
+ local a = vim.defaulttable(function(k) return k end)
+ local _ = a.b
+ local _ = a.c
+ return a
+ ]])
+ end)
end)
+ it('vim.lua_omnifunc', function()
+ local screen = Screen.new(60,5)
+ screen:set_default_attr_ids {
+ [1] = {foreground = Screen.colors.Blue1, bold = true};
+ [2] = {background = Screen.colors.WebGray};
+ [3] = {background = Screen.colors.LightMagenta};
+ [4] = {bold = true};
+ [5] = {foreground = Screen.colors.SeaGreen, bold = true};
+ }
+ screen:attach()
+ command [[ set omnifunc=v:lua.vim.lua_omnifunc ]]
+
+ -- Note: the implementation is shared with lua command line completion.
+ -- More tests for completion in lua/command_line_completion_spec.lua
+ feed [[ivim.insp<c-x><c-o>]]
+ screen:expect{grid=[[
+ vim.inspect^ |
+ {1:~ }{2: inspect }{1: }|
+ {1:~ }{3: inspect_pos }{1: }|
+ {1:~ }|
+ {4:-- Omni completion (^O^N^P) }{5:match 1 of 2} |
+ ]]}
+ end)
+
+ it('vim.print', function()
+ -- vim.print() returns its args.
+ eq({42, 'abc', { a = { b = 77 }}},
+ exec_lua[[return {vim.print(42, 'abc', { a = { b = 77 }})}]])
+
+ -- vim.print() pretty-prints the args.
+ eq(dedent[[
+
+ 42
+ abc
+ {
+ a = {
+ b = 77
+ }
+ }]],
+ eval[[execute('lua vim.print(42, "abc", { a = { b = 77 }})')]])
+ end)
+
+ it('vim.F.if_nil', function()
+ local function if_nil(...)
+ return exec_lua([[
+ local args = {...}
+ local nargs = select('#', ...)
+ for i = 1, nargs do
+ if args[i] == vim.NIL then
+ args[i] = nil
+ end
+ end
+ return vim.F.if_nil(unpack(args, 1, nargs))
+ ]], ...)
+ end
+
+ local a = NIL
+ local b = NIL
+ local c = 42
+ local d = false
+ eq(42, if_nil(a, c))
+ eq(false, if_nil(d, b))
+ eq(42, if_nil(a, b, c, d))
+ eq(false, if_nil(d))
+ eq(false, if_nil(d, c))
+ eq(NIL, if_nil(a))
+ end)
+
+ it('lpeg', function()
+ eq(5, exec_lua [[
+ local m = vim.lpeg
+ return m.match(m.R'09'^1, '4504ab')
+ ]])
+
+ eq(4, exec_lua [[ return vim.re.match("abcde", '[a-c]+') ]])
+ end)
+
+ it("vim.ringbuf", function()
+ local results = exec_lua([[
+ local ringbuf = vim.ringbuf(3)
+ ringbuf:push("a") -- idx: 0
+ local peeka1 = ringbuf:peek()
+ local peeka2 = ringbuf:peek()
+ local popa = ringbuf:pop()
+ local popnil = ringbuf:pop()
+ ringbuf:push("a") -- idx: 1
+ ringbuf:push("b") -- idx: 2
+
+ -- doesn't read last added item, but uses separate read index
+ local pop_after_add_b = ringbuf:pop()
+
+ ringbuf:push("c") -- idx: 3 wraps around, overrides idx: 0 "a"
+ ringbuf:push("d") -- idx: 4 wraps around, overrides idx: 1 "a"
+ return {
+ peeka1 = peeka1,
+ peeka2 = peeka2,
+ pop1 = popa,
+ pop2 = popnil,
+ pop3 = ringbuf:pop(),
+ pop4 = ringbuf:pop(),
+ pop5 = ringbuf:pop(),
+ pop_after_add_b = pop_after_add_b,
+ }
+ ]])
+ local expected = {
+ peeka1 = "a",
+ peeka2 = "a",
+ pop1 = "a",
+ pop2 = nil,
+ pop3 = "b",
+ pop4 = "c",
+ pop5 = "d",
+ pop_after_add_b = "a",
+ }
+ eq(expected, results)
+ end)
end)
describe('lua: builtin modules', function()
diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua
new file mode 100644
index 0000000000..cdcef08a1a
--- /dev/null
+++ b/test/functional/lua/watch_spec.lua
@@ -0,0 +1,178 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local clear = helpers.clear
+local is_os = helpers.is_os
+local skip = helpers.skip
+
+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 watched_path = root_dir .. '/file'
+ local watched, err = io.open(watched_path, 'w')
+ assert(not err, err)
+
+ expected_events = expected_events + 1
+ wait_for_events()
+
+ watched:close()
+ os.remove(watched_path)
+
+ 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,
+ },
+ }
+ end
+
+ eq(expected, result)
+ end)
+ end)
+
+ describe('poll', function()
+ it('detects file changes', function()
+ skip(is_os('bsd'), "bsd only reports rename on folders if file inside change")
+ local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
+
+ local result = exec_lua(
+ [[
+ local root_dir = ...
+ local lpeg = vim.lpeg
+
+ local events = {}
+
+ local debounce = 100
+ local wait_ms = debounce + 200
+
+ 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
+
+ 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,
+ }, function(path, change_type)
+ table.insert(events, { path = path, change_type = change_type })
+ end)
+
+ 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)
+
+ expected_events = expected_events + 1
+ wait_for_events()
+
+ watched:close()
+ os.remove(watched_path)
+ unwatched:close()
+ os.remove(unwatched_path)
+
+ 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)
+
+ watched:close()
+ os.remove(watched_path)
+
+ return events
+ ]],
+ root_dir
+ )
+
+ local created = exec_lua([[return vim._watch.FileChangeType.Created]])
+ local deleted = exec_lua([[return vim._watch.FileChangeType.Deleted]])
+ local expected = {
+ {
+ change_type = created,
+ path = root_dir .. "/file",
+ },
+ {
+ change_type = deleted,
+ path = root_dir .. "/file",
+ }
+ }
+ eq(expected, result)
+ end)
+ end)
+end)
diff --git a/test/functional/options/autochdir_spec.lua b/test/functional/options/autochdir_spec.lua
index 0b6fe9533c..c75a98f35b 100644
--- a/test/functional/options/autochdir_spec.lua
+++ b/test/functional/options/autochdir_spec.lua
@@ -1,9 +1,10 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local funcs = helpers.funcs
local command = helpers.command
+local mkdir = helpers.mkdir
describe("'autochdir'", function()
it('given on the shell gets processed properly', function()
@@ -20,11 +21,11 @@ describe("'autochdir'", function()
end)
it('is not overwritten by getwinvar() call #17609',function()
- local curdir = string.gsub(lfs.currentdir(), '\\', '/')
+ local curdir = string.gsub(luv.cwd(), '\\', '/')
local dir_a = curdir..'/Xtest-functional-options-autochdir.dir_a'
local dir_b = curdir..'/Xtest-functional-options-autochdir.dir_b'
- lfs.mkdir(dir_a)
- lfs.mkdir(dir_b)
+ mkdir(dir_a)
+ mkdir(dir_b)
clear()
command('set shellslash')
command('set autochdir')
diff --git a/test/functional/options/cursorbind_spec.lua b/test/functional/options/cursorbind_spec.lua
index 1a03ed099a..498206936a 100644
--- a/test/functional/options/cursorbind_spec.lua
+++ b/test/functional/options/cursorbind_spec.lua
@@ -8,6 +8,7 @@ local feed = helpers.feed
before_each(clear)
describe("'cursorbind'", function()
+ -- oldtest: Test_cursorline_cursorbind_horizontal_scroll()
it("behaves consistently whether 'cursorline' is set or not vim-patch:8.2.4795", function()
local screen = Screen.new(60, 8)
screen:set_default_attr_ids({
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua
index 84ec43f4cb..7858b626de 100644
--- a/test/functional/options/defaults_spec.lua
+++ b/test/functional/options/defaults_spec.lua
@@ -8,6 +8,7 @@ local meths = helpers.meths
local command = helpers.command
local clear = helpers.clear
local exc_exec = helpers.exc_exec
+local exec_lua = helpers.exec_lua
local eval = helpers.eval
local eq = helpers.eq
local ok = helpers.ok
@@ -199,11 +200,23 @@ describe('startup defaults', function()
it("'shadafile' ('viminfofile')", function()
local env = {XDG_DATA_HOME='Xtest-userdata', XDG_STATE_HOME='Xtest-userstate', XDG_CONFIG_HOME='Xtest-userconfig'}
+ finally(function()
+ command('set shadafile=NONE') -- Avoid writing shada file on exit
+ rmdir('Xtest-userstate')
+ os.remove('Xtest-foo')
+ end)
+
clear{args={}, args_rm={'-i'}, env=env}
-- Default 'shadafile' is empty.
-- This means use the default location. :help shada-file-name
- eq('', meths.get_option('shadafile'))
- eq('', meths.get_option('viminfofile'))
+ eq('', meths.get_option_value('shadafile', {}))
+ eq('', meths.get_option_value('viminfofile', {}))
+ -- Handles viminfo/viminfofile as alias for shada/shadafile.
+ eq('\n shadafile=', eval('execute("set shadafile?")'))
+ eq('\n shadafile=', eval('execute("set viminfofile?")'))
+ eq("\n shada=!,'100,<50,s10,h", eval('execute("set shada?")'))
+ eq("\n shada=!,'100,<50,s10,h", eval('execute("set viminfo?")'))
+
-- Check that shada data (such as v:oldfiles) is saved/restored.
command('edit Xtest-foo')
command('write')
@@ -212,14 +225,6 @@ describe('startup defaults', function()
expect_exit(command, 'qall')
clear{args={}, args_rm={'-i'}, env=env}
eq({ f }, eval('v:oldfiles'))
- os.remove('Xtest-foo')
- rmdir('Xtest-userstate')
-
- -- Handles viminfo/viminfofile as alias for shada/shadafile.
- eq('\n shadafile=', eval('execute("set shadafile?")'))
- eq('\n shadafile=', eval('execute("set viminfofile?")'))
- eq("\n shada=!,'100,<50,s10,h", eval('execute("set shada?")'))
- eq("\n shada=!,'100,<50,s10,h", eval('execute("set viminfo?")'))
end)
it("'packpath'", function()
@@ -227,13 +232,13 @@ describe('startup defaults', function()
args_rm={'runtimepath'},
}
-- Defaults to &runtimepath.
- eq(meths.get_option('runtimepath'), meths.get_option('packpath'))
+ eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
-- Does not follow modifications to runtimepath.
meths.command('set runtimepath+=foo')
- neq(meths.get_option('runtimepath'), meths.get_option('packpath'))
+ neq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
meths.command('set packpath+=foo')
- eq(meths.get_option('runtimepath'), meths.get_option('packpath'))
+ eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
end)
it('v:progpath is set to the absolute path', function()
@@ -318,10 +323,10 @@ describe('XDG defaults', function()
USER=nil,
}})
- eq('.', meths.get_option('backupdir'))
- eq('.', meths.get_option('viewdir'))
- eq('.', meths.get_option('directory'))
- eq('.', meths.get_option('undodir'))
+ eq('.', meths.get_option_value('backupdir', {}))
+ eq('.', meths.get_option_value('viewdir', {}))
+ eq('.', meths.get_option_value('directory', {}))
+ eq('.', meths.get_option_value('undodir', {}))
ok((funcs.tempname()):len() > 4)
end)
end)
@@ -383,7 +388,7 @@ describe('XDG defaults', function()
.. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after'
- ):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/'))
+ ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
@@ -407,15 +412,15 @@ describe('XDG defaults', function()
.. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after'
- ):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/'))
+ ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq('.,' .. root_path .. ('/X'):rep(4096).. '/' .. state_dir .. '/backup//',
- (meths.get_option('backupdir'):gsub('\\', '/')))
+ (meths.get_option_value('backupdir', {}):gsub('\\', '/')))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//',
- (meths.get_option('directory')):gsub('\\', '/'))
+ (meths.get_option_value('directory', {})):gsub('\\', '/'))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//',
- (meths.get_option('undodir')):gsub('\\', '/'))
+ (meths.get_option_value('undodir', {})):gsub('\\', '/'))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//',
- (meths.get_option('viewdir')):gsub('\\', '/'))
+ (meths.get_option_value('viewdir', {})):gsub('\\', '/'))
end)
end)
@@ -431,7 +436,12 @@ describe('XDG defaults', function()
XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR',
XDG_STATE_HOME='$XDG_CONFIG_HOME',
XDG_DATA_DIRS='$XDG_CONFIG_DIRS',
- }})
+ }
+ })
+ end)
+
+ after_each(function()
+ command('set shadafile=NONE') -- Avoid writing shada file on exit
end)
it('are not expanded', function()
@@ -450,7 +460,7 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
- ):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/'))
+ ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
@@ -466,15 +476,15 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
- ):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/'))
+ ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
- meths.get_option('backupdir'):gsub('\\', '/'))
+ meths.get_option_value('backupdir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
- meths.get_option('directory'):gsub('\\', '/'))
+ meths.get_option_value('directory', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
- meths.get_option('undodir'):gsub('\\', '/'))
+ meths.get_option_value('undodir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
- meths.get_option('viewdir'):gsub('\\', '/'))
+ meths.get_option_value('viewdir', {}):gsub('\\', '/'))
meths.command('set all&')
eq(('$XDG_DATA_HOME/nvim'
.. ',$XDG_DATA_DIRS/nvim'
@@ -486,15 +496,15 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after'
- ):gsub('\\', '/'), (meths.get_option('runtimepath')):gsub('\\', '/'))
+ ):gsub('\\', '/'), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
- meths.get_option('backupdir'):gsub('\\', '/'))
+ meths.get_option_value('backupdir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
- meths.get_option('directory'):gsub('\\', '/'))
+ meths.get_option_value('directory', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
- meths.get_option('undodir'):gsub('\\', '/'))
+ meths.get_option_value('undodir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
- meths.get_option('viewdir'):gsub('\\', '/'))
+ meths.get_option_value('viewdir', {}):gsub('\\', '/'))
eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR'))
end)
end)
@@ -529,7 +539,7 @@ describe('XDG defaults', function()
.. ',-\\,-\\,-' .. path_sep .. 'nvim' .. path_sep .. 'after'
.. ',\\,-\\,-\\,' .. path_sep .. 'nvim' .. path_sep .. 'after'
.. ',\\, \\, \\,' .. path_sep .. 'nvim' .. path_sep .. 'after'
- ), meths.get_option('runtimepath'))
+ ), meths.get_option_value('runtimepath', {}))
meths.command('set runtimepath&')
meths.command('set backupdir&')
meths.command('set directory&')
@@ -549,15 +559,15 @@ describe('XDG defaults', function()
.. ',-\\,-\\,-' .. path_sep ..'nvim' .. path_sep ..'after'
.. ',\\,-\\,-\\,' .. path_sep ..'nvim' .. path_sep ..'after'
.. ',\\, \\, \\,' .. path_sep ..'nvim' .. path_sep ..'after'
- ), meths.get_option('runtimepath'))
+ ), meths.get_option_value('runtimepath', {}))
eq('.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep ..'backup' .. (path_sep):rep(2),
- meths.get_option('backupdir'))
+ meths.get_option_value('backupdir', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'swap' .. (path_sep):rep(2),
- meths.get_option('directory'))
+ meths.get_option_value('directory', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'undo' .. (path_sep):rep(2),
- meths.get_option('undodir'))
+ meths.get_option_value('undodir', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'view' .. (path_sep):rep(2),
- meths.get_option('viewdir'))
+ meths.get_option_value('viewdir', {}))
end)
end)
end)
@@ -566,8 +576,12 @@ end)
describe('stdpath()', function()
-- Windows appends 'nvim-data' instead of just 'nvim' to prevent collisions
-- due to XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME being the same.
- local datadir = is_os('win') and 'nvim-data' or 'nvim'
- local statedir = is_os('win') and 'nvim-data' or 'nvim'
+ local function maybe_data(name)
+ return is_os('win') and name .. '-data' or name
+ end
+
+ local datadir = maybe_data('nvim')
+ local statedir = maybe_data('nvim')
local env_sep = is_os('win') and ';' or ':'
it('acceptance', function()
@@ -583,7 +597,45 @@ describe('stdpath()', function()
assert_alive() -- Check for crash. #8393
end)
- context('returns a String', function()
+ it('reacts to $NVIM_APPNAME', function()
+ local appname = 'NVIM_APPNAME_TEST' .. ('_'):rep(106)
+ clear({env={ NVIM_APPNAME=appname }})
+ eq(appname, funcs.fnamemodify(funcs.stdpath('config'), ':t'))
+ eq(appname, funcs.fnamemodify(funcs.stdpath('cache'), ':t'))
+ eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('log'), ':t'))
+ eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('data'), ':t'))
+ eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('state'), ':t'))
+ -- config_dirs and data_dirs are empty on windows, so don't check them on
+ -- that platform
+ if not is_os('win') then
+ eq(appname, funcs.fnamemodify(funcs.stdpath('config_dirs')[1], ':t'))
+ eq(appname, funcs.fnamemodify(funcs.stdpath('data_dirs')[1], ':t'))
+ end
+ assert_alive() -- Check for crash. #8393
+
+ -- Check that Nvim rejects invalid APPNAMEs
+ -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
+ local function test_appname(testAppname, expected_exitcode)
+ local lua_code = string.format([[
+ local child = vim.fn.jobstart({ vim.v.progpath, '--clean', '--headless', '+qall!' }, { env = { NVIM_APPNAME = %q } })
+ return vim.fn.jobwait({ child }, %d)[1]
+ ]], alter_slashes(testAppname), 3000)
+ eq(expected_exitcode, exec_lua(lua_code))
+ end
+ -- Invalid appnames:
+ test_appname('a/../b', 1)
+ test_appname('../a', 1)
+ test_appname('a/..', 1)
+ test_appname('..', 1)
+ test_appname('.', 1)
+ test_appname('/', 1)
+ test_appname(is_os('win') and 'C:/a/b' or '/a/b', 1)
+ -- Valid appnames:
+ test_appname('a/b', 0)
+ test_appname('a/b\\c', 0)
+ end)
+
+ describe('returns a String', function()
describe('with "config"' , function ()
it('knows XDG_CONFIG_HOME', function()
@@ -718,7 +770,7 @@ describe('stdpath()', function()
end)
end)
- context('returns a List', function()
+ describe('returns a List', function()
-- Some OS specific variables the system would have set.
local function base_env()
if is_os('win') then
@@ -870,8 +922,8 @@ describe('stdpath()', function()
end)
it('on non-strings', function()
- eq('Vim(call):E731: using Dictionary as a String', exc_exec('call stdpath({"eris": 23})'))
- eq('Vim(call):E730: using List as a String', exc_exec('call stdpath([23])'))
+ eq('Vim(call):E731: Using a Dictionary as a String', exc_exec('call stdpath({"eris": 23})'))
+ eq('Vim(call):E730: Using a List as a String', exc_exec('call stdpath([23])'))
end)
end)
end)
diff --git a/test/functional/options/keymap_spec.lua b/test/functional/options/keymap_spec.lua
index 4fdc6ef4be..c390e3d943 100644
--- a/test/functional/options/keymap_spec.lua
+++ b/test/functional/options/keymap_spec.lua
@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq
local expect, command, eval = helpers.expect, helpers.command, helpers.eval
local insert, call = helpers.insert, helpers.call
-local funcs, dedent = helpers.funcs, helpers.dedent
+local exec_capture, dedent = helpers.exec_capture, helpers.dedent
-- First test it's implemented using the :lmap and :lnoremap commands, then
-- check those mappings behave as expected.
@@ -30,7 +30,7 @@ describe("'keymap' / :lmap", function()
command('lmapclear <buffer>')
command('set keymap=dvorak')
command('set nomore')
- local bindings = funcs.nvim_exec('lmap', true)
+ local bindings = exec_capture('lmap')
eq(dedent([[
l " @_
diff --git a/test/functional/options/mousescroll_spec.lua b/test/functional/options/mousescroll_spec.lua
index 5bff45a836..38a9692792 100644
--- a/test/functional/options/mousescroll_spec.lua
+++ b/test/functional/options/mousescroll_spec.lua
@@ -20,7 +20,7 @@ end
describe("'mousescroll'", function()
local invalid_arg = 'Vim(set):E474: Invalid argument: mousescroll='
- local digit_expected = 'Vim(set):E548: digit expected: mousescroll='
+ local digit_expected = 'Vim(set):E5080: Digit expected: mousescroll='
local function should_fail(val, errorstr)
eq(errorstr..val, exc_exec('set mousescroll='..val))
diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua
index f343e2da75..16a53c75e6 100644
--- a/test/functional/options/num_options_spec.lua
+++ b/test/functional/options/num_options_spec.lua
@@ -11,7 +11,7 @@ local function should_fail(opt, value, errmsg)
feed_command('setlocal ' .. opt .. '=' .. value)
eq(errmsg, eval("v:errmsg"):match("E%d*"))
feed_command('let v:errmsg = ""')
- local status, err = pcall(meths.set_option, opt, value)
+ local status, err = pcall(meths.set_option_value, opt, value, {})
eq(status, false)
eq(errmsg, err:match("E%d*"))
eq('', eval("v:errmsg"))
@@ -20,8 +20,8 @@ end
local function should_succeed(opt, value)
feed_command('setglobal ' .. opt .. '=' .. value)
feed_command('setlocal ' .. opt .. '=' .. value)
- meths.set_option(opt, value)
- eq(value, meths.get_option(opt))
+ meths.set_option_value(opt, value, {})
+ eq(value, meths.get_option_value(opt, {}))
eq('', eval("v:errmsg"))
end
@@ -29,12 +29,12 @@ describe(':setlocal', function()
before_each(clear)
it('setlocal sets only local value', function()
- eq(0, meths.get_option('iminsert'))
+ eq(0, meths.get_option_value('iminsert', {scope='global'}))
feed_command('setlocal iminsert=1')
- eq(0, meths.get_option('iminsert'))
- eq(-1, meths.get_option('imsearch'))
+ eq(0, meths.get_option_value('iminsert', {scope='global'}))
+ eq(-1, meths.get_option_value('imsearch', {scope='global'}))
feed_command('setlocal imsearch=1')
- eq(-1, meths.get_option('imsearch'))
+ eq(-1, meths.get_option_value('imsearch', {scope='global'}))
end)
end)
@@ -77,8 +77,8 @@ describe(':set validation', function()
-- If smaller than 1 this one is set to 'lines'-1
feed_command('setglobal window=-10')
- meths.set_option('window', -10)
- eq(23, meths.get_option('window'))
+ meths.set_option_value('window', -10, {})
+ eq(23, meths.get_option_value('window', {}))
eq('', eval("v:errmsg"))
-- 'scrolloff' and 'sidescrolloff' can have a -1 value when
@@ -112,8 +112,8 @@ describe(':set validation', function()
local function setto(value)
feed_command('setglobal maxcombine=' .. value)
feed_command('setlocal maxcombine=' .. value)
- meths.set_option('maxcombine', value)
- eq(6, meths.get_option('maxcombine'))
+ meths.set_option_value('maxcombine', value, {})
+ eq(6, meths.get_option_value('maxcombine', {}))
eq('', eval("v:errmsg"))
end
setto(0)
diff --git a/test/functional/options/pastetoggle_spec.lua b/test/functional/options/pastetoggle_spec.lua
deleted file mode 100644
index 40c14fa187..0000000000
--- a/test/functional/options/pastetoggle_spec.lua
+++ /dev/null
@@ -1,90 +0,0 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local feed = helpers.feed
-local command = helpers.command
-local eq = helpers.eq
-local expect = helpers.expect
-local eval = helpers.eval
-local insert = helpers.insert
-local meths = helpers.meths
-local sleep = helpers.sleep
-
-describe("'pastetoggle' option", function()
- before_each(clear)
- it("toggles 'paste'", function()
- command('set pastetoggle=a')
- eq(0, eval('&paste'))
- feed('a')
- -- Need another key so that the vgetorpeek() function returns.
- feed('j')
- eq(1, eval('&paste'))
- end)
- describe("multiple key 'pastetoggle'", function()
- before_each(function()
- eq(0, eval('&paste'))
- command('set timeoutlen=1 ttimeoutlen=10000')
- end)
- it('is waited for when chars are typed', function()
- local pastetoggle = 'lllll'
- command('set pastetoggle=' .. pastetoggle)
- feed(pastetoggle:sub(0, 2))
- -- sleep() for long enough that vgetorpeek() is gotten into, but short
- -- enough that ttimeoutlen is not reached.
- sleep(200)
- feed(pastetoggle:sub(3, -1))
- -- Need another key so that the vgetorpeek() function returns.
- feed('j')
- eq(1, eval('&paste'))
- end)
-
- it('is not waited for when there are no typed chars after mapped chars', function()
- command('set pastetoggle=abc')
- command('imap d a')
- meths.feedkeys('id', 't', true)
- -- sleep() for long enough that vgetorpeek() is gotten into, but short
- -- enough that ttimeoutlen is not reached.
- sleep(200)
- feed('bc')
- -- Need another key so that the vgetorpeek() function returns.
- feed('j')
- -- 'ttimeoutlen' should NOT apply
- eq(0, eval('&paste'))
- end)
-
- it('is waited for when there are typed chars after mapped chars', function()
- command('set pastetoggle=abc')
- command('imap d a')
- meths.feedkeys('idb', 't', true)
- -- sleep() for long enough that vgetorpeek() is gotten into, but short
- -- enough that ttimeoutlen is not reached.
- sleep(200)
- feed('c')
- -- Need another key so that the vgetorpeek() function returns.
- feed('j')
- -- 'ttimeoutlen' should apply
- eq(1, eval('&paste'))
- end)
-
- it('is waited for when there are typed chars after noremapped chars', function()
- command('set pastetoggle=abc')
- command('inoremap d a')
- meths.feedkeys('idb', 't', true)
- -- sleep() for long enough that vgetorpeek() is gotten into, but short
- -- enough that ttimeoutlen is not reached.
- sleep(200)
- feed('c')
- -- Need another key so that the vgetorpeek() function returns.
- feed('j')
- -- 'ttimeoutlen' should apply
- eq(1, eval('&paste'))
- end)
- end)
- it('does not interfere with character-find', function()
- insert('foo,bar')
- feed('0')
- command('set pastetoggle=,sp')
- feed('dt,')
- expect(',bar')
- end)
-end)
diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua
index e6a2550aba..ac78003a8c 100644
--- a/test/functional/plugin/editorconfig_spec.lua
+++ b/test/functional/plugin/editorconfig_spec.lua
@@ -3,9 +3,9 @@ local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local pathsep = helpers.get_pathsep()
-local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs
local meths = helpers.meths
+local exec_lua = helpers.exec_lua
local testdir = 'Xtest-editorconfig'
@@ -13,7 +13,7 @@ local function test_case(name, expected)
local filename = testdir .. pathsep .. name
command('edit ' .. filename)
for opt, val in pairs(expected) do
- eq(val, curbufmeths.get_option(opt), name)
+ eq(val, meths.get_option_value(opt, {buf=0}), name)
end
end
@@ -160,8 +160,8 @@ describe('editorconfig', function()
end)
it('sets newline options', function()
- test_case('with_newline.txt', { fixendofline = true, endofline = true })
- test_case('without_newline.txt', { fixendofline = false, endofline = false })
+ test_case('with_newline.txt', { fixendofline = true })
+ test_case('without_newline.txt', { fixendofline = false })
end)
it('respects trim_trailing_whitespace', function()
@@ -207,4 +207,15 @@ But not this one
test_case('3_space.txt', { shiftwidth = 42 })
test_case('4_space.py', { shiftwidth = 4 })
end)
+
+ it('does not operate on invalid buffers', function()
+ local ok, err = unpack(exec_lua([[
+ vim.cmd.edit('test.txt')
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.cmd.bwipeout(bufnr)
+ return {pcall(require('editorconfig').config, bufnr)}
+ ]]))
+
+ eq(true, ok, err)
+ end)
end)
diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua
index 97d32313e5..50b1d03f36 100644
--- a/test/functional/plugin/health_spec.lua
+++ b/test/functional/plugin/health_spec.lua
@@ -1,5 +1,4 @@
local helpers = require('test.functional.helpers')(after_each)
-local global_helpers = require('test.helpers')
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
@@ -43,20 +42,17 @@ end)
describe('health.vim', function()
before_each(function()
clear{args={'-u', 'NORC'}}
- -- Provides functions:
- -- health#broken#check()
- -- health#success1#check()
- -- health#success2#check()
+ -- Provides healthcheck functions
command("set runtimepath+=test/functional/fixtures")
end)
describe(":checkhealth", function()
- it("functions health#report_*() render correctly", function()
+ it("functions report_*() render correctly", function()
command("checkhealth full_render")
helpers.expect([[
==============================================================================
- full_render: health#full_render#check
+ test_plug.full_render: require("test_plug.full_render.health").check()
report 1 ~
- OK life is fine
@@ -79,7 +75,7 @@ describe('health.vim', function()
helpers.expect([[
==============================================================================
- success1: health#success1#check
+ test_plug: require("test_plug.health").check()
report 1 ~
- OK everything is fine
@@ -88,36 +84,19 @@ describe('health.vim', function()
- OK nothing to see here
==============================================================================
- success2: health#success2#check
-
- another 1 ~
- - OK ok
-
- ==============================================================================
- test_plug: require("test_plug.health").check()
+ test_plug.success1: require("test_plug.success1.health").check()
report 1 ~
- OK everything is fine
report 2 ~
- OK nothing to see here
- ]])
- end)
-
- it("lua plugins, skips vimscript healthchecks with the same name", function()
- command("checkhealth test_plug")
- -- Existing file in test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim
- -- and the Lua healthcheck is used instead.
- helpers.expect([[
==============================================================================
- test_plug: require("test_plug.health").check()
-
- report 1 ~
- - OK everything is fine
+ test_plug.success2: require("test_plug.success2.health").check()
- report 2 ~
- - OK nothing to see here
+ another 1 ~
+ - OK ok
]])
end)
@@ -136,57 +115,6 @@ describe('health.vim', function()
]])
end)
- it("lua plugins submodules with expression '*'", function()
- command("checkhealth test_plug*")
- local buf_lines = helpers.curbuf('get_lines', 0, -1, true)
- -- avoid dealing with path separators
- local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5)
- local expected = helpers.dedent([[
-
- ==============================================================================
- test_plug: require("test_plug.health").check()
-
- report 1 ~
- - OK everything is fine
-
- report 2 ~
- - OK nothing to see here
-
- ==============================================================================
- test_plug.submodule: require("test_plug.submodule.health").check()
-
- report 1 ~
- - OK everything is fine
-
- report 2 ~
- - OK nothing to see here
-
- ==============================================================================
- test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
-
- - ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty.
-
- ==============================================================================
- test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
-
- - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
- function health#check, line 25]])
- eq(expected, received)
- end)
-
- it("gracefully handles broken healthcheck", function()
- command("checkhealth broken")
- helpers.expect([[
-
- ==============================================================================
- broken: health#broken#check
-
- - ERROR Failed to run healthcheck for "broken" plugin. Exception:
- function health#check[25]..health#broken#check, line 1
- caused an error
- ]])
- end)
-
it("... including empty reports", function()
command("checkhealth test_plug.submodule_empty")
helpers.expect([[
@@ -198,36 +126,17 @@ describe('health.vim', function()
]])
end)
- it("gracefully handles broken lua healthcheck", function()
- command("checkhealth test_plug.submodule_failed")
- local buf_lines = helpers.curbuf('get_lines', 0, -1, true)
- local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5)
- -- avoid dealing with path separators
- local lua_err = "attempt to perform arithmetic on a nil value"
- local last_line = buf_lines[#buf_lines - 4]
- assert(string.find(last_line, lua_err) ~= nil, "Lua error not present")
-
- local expected = global_helpers.dedent([[
-
- ==============================================================================
- test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
-
- - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
- function health#check, line 25]])
- eq(expected, received)
- end)
-
it("highlights OK, ERROR", function()
local screen = Screen.new(50, 12)
screen:attach()
screen:set_default_attr_ids({
- Ok = { foreground = Screen.colors.Grey3, background = 6291200 },
- Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
+ Ok = { foreground = Screen.colors.LightGreen },
+ Error = { foreground = Screen.colors.Red },
Heading = { foreground = tonumber('0x6a0dad') },
Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey },
})
command("checkhealth foo success1")
- command("set nowrap laststatus=0")
+ command("set nofoldenable nowrap laststatus=0")
screen:expect{grid=[[
^ |
{Bar:──────────────────────────────────────────────────}|
@@ -236,7 +145,7 @@ describe('health.vim', function()
- {Error:ERROR} No healthcheck found for "foo" plugin. |
|
{Bar:──────────────────────────────────────────────────}|
- {Heading:success1: health#success1#check} |
+ {Heading:test_plug.success1: require("test_plug.success1.he}|
|
{Heading:report 1} |
- {Ok:OK} everything is fine |
@@ -244,6 +153,22 @@ describe('health.vim', function()
]]}
end)
+ it("fold healthchecks", function()
+ local screen = Screen.new(50, 7)
+ screen:attach()
+ command("checkhealth foo success1")
+ command("set nowrap laststatus=0")
+ screen:expect{grid=[[
+ ^ |
+ ──────────────────────────────────────────────────|
+ +WE 4 lines: foo: ·······························|
+ ──────────────────────────────────────────────────|
+ +-- 8 lines: test_plug.success1: require("test_pl|
+ ~ |
+ |
+ ]]}
+ end)
+
it("gracefully handles invalid healthcheck", function()
command("checkhealth non_existent_healthcheck")
-- luacheck: ignore 613
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
new file mode 100644
index 0000000000..9354654afe
--- /dev/null
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -0,0 +1,239 @@
+---@diagnostic disable: no-unknown
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+
+
+--- Convert completion results.
+---
+---@param line string line contents. Mark cursor position with `|`
+---@param candidates lsp.CompletionList|lsp.CompletionItem[]
+---@param lnum? integer 0-based, defaults to 0
+---@return {items: table[], server_start_boundary: integer?}
+local function complete(line, candidates, lnum)
+ lnum = lnum or 0
+ -- nvim_win_get_cursor returns 0 based column, line:find returns 1 based
+ local cursor_col = line:find("|") - 1
+ line = line:gsub("|", "")
+ return exec_lua([[
+ local line, cursor_col, lnum, result = ...
+ local line_to_cursor = line:sub(1, cursor_col)
+ local client_start_boundary = vim.fn.match(line_to_cursor, '\\k*$')
+ local items, server_start_boundary = require("vim.lsp._completion")._convert_results(
+ line,
+ lnum,
+ cursor_col,
+ client_start_boundary,
+ nil,
+ result,
+ "utf-16"
+ )
+ return {
+ items = items,
+ server_start_boundary = server_start_boundary
+ }
+ ]], line, cursor_col, lnum, candidates)
+end
+
+
+describe("vim.lsp._completion", function()
+ before_each(helpers.clear)
+
+ -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+ it('prefers textEdit over label as word', function()
+ local range0 = {
+ start = { line = 0, character = 0 },
+ ["end"] = { line = 0, character = 0 },
+ }
+ local completion_list = {
+ -- resolves into label
+ { label = 'foobar', sortText = 'a', documentation = 'documentation' },
+ {
+ label = 'foobar',
+ sortText = 'b',
+ documentation = { value = 'documentation' },
+ },
+ -- resolves into insertText
+ { label = 'foocar', sortText = 'c', insertText = 'foobar' },
+ { label = 'foocar', sortText = 'd', insertText = 'foobar' },
+ -- resolves into textEdit.newText
+ { label = 'foocar', sortText = 'e', insertText = 'foodar', textEdit = { newText = 'foobar', range = range0 } },
+ { label = 'foocar', sortText = 'f', textEdit = { newText = 'foobar', range = range0 } },
+ -- real-world snippet text
+ {
+ label = 'foocar',
+ sortText = 'g',
+ insertText = 'foodar',
+ insertTextFormat = 2,
+ textEdit = { newText = 'foobar(${1:place holder}, ${2:more ...holder{\\}})', range = range0 },
+ },
+ {
+ label = 'foocar',
+ sortText = 'h',
+ insertText = 'foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}',
+ insertTextFormat = 2,
+ },
+ -- nested snippet tokens
+ {
+ label = 'foocar',
+ sortText = 'i',
+ insertText = 'foodar(${1:${2|typ1,typ2|}}) {$0\\}',
+ insertTextFormat = 2,
+ },
+ -- braced tabstop
+ { label = 'foocar', sortText = 'j', insertText = 'foodar()${0}', insertTextFormat = 2},
+ -- plain text
+ {
+ label = 'foocar',
+ sortText = 'k',
+ insertText = 'foodar(${1:var1})',
+ insertTextFormat = 1,
+ },
+ }
+ local expected = {
+ {
+ abbr = 'foobar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foobar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foobar',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foobar(place holder, more ...holder{})',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foodar(var1 typ1, var2 *typ2) {}',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foodar(typ1) {}',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foodar()',
+ },
+ {
+ abbr = 'foocar',
+ word = 'foodar(${1:var1})',
+ },
+ }
+ local result = complete('|', completion_list)
+ result = vim.tbl_map(function(x)
+ return {
+ abbr = x.abbr,
+ word = x.word
+ }
+ end, result.items)
+ eq(expected, result)
+ end)
+ it("uses correct start boundary", function()
+ local completion_list = {
+ isIncomplete = false,
+ items = {
+ {
+ filterText = "this_thread",
+ insertText = "this_thread",
+ insertTextFormat = 1,
+ kind = 9,
+ label = " this_thread",
+ score = 1.3205767869949,
+ sortText = "4056f757this_thread",
+ textEdit = {
+ newText = "this_thread",
+ range = {
+ start = { line = 0, character = 7 },
+ ["end"] = { line = 0, character = 11 },
+ },
+ }
+ },
+ }
+ }
+ local expected = {
+ abbr = ' this_thread',
+ dup = 1,
+ empty = 1,
+ icase = 1,
+ kind = 'Module',
+ menu = '',
+ word = 'this_thread',
+ }
+ local result = complete(" std::this|", completion_list)
+ eq(7, result.server_start_boundary)
+ local item = result.items[1]
+ item.user_data = nil
+ eq(expected, item)
+ end)
+
+ it("should search from start boundary to cursor position", function()
+ local completion_list = {
+ isIncomplete = false,
+ items = {
+ {
+ filterText = "this_thread",
+ insertText = "this_thread",
+ insertTextFormat = 1,
+ kind = 9,
+ label = " this_thread",
+ score = 1.3205767869949,
+ sortText = "4056f757this_thread",
+ textEdit = {
+ newText = "this_thread",
+ range = {
+ start = { line = 0, character = 7 },
+ ["end"] = { line = 0, character = 11 },
+ },
+ }
+ },
+ {
+ filterText = "notthis_thread",
+ insertText = "notthis_thread",
+ insertTextFormat = 1,
+ kind = 9,
+ label = " notthis_thread",
+ score = 1.3205767869949,
+ sortText = "4056f757this_thread",
+ textEdit = {
+ newText = "notthis_thread",
+ range = {
+ start = { line = 0, character = 7 },
+ ["end"] = { line = 0, character = 11 },
+ },
+ }
+ },
+ }
+ }
+ local expected = {
+ abbr = ' this_thread',
+ dup = 1,
+ empty = 1,
+ icase = 1,
+ kind = 'Module',
+ menu = '',
+ word = 'this_thread',
+ }
+ local result = complete(" std::this|is", completion_list)
+ eq(1, #result.items)
+ local item = result.items[1]
+ item.user_data = nil
+ eq(expected, item)
+ end)
+end)
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index f73ffc29b0..1da0222114 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -1,10 +1,13 @@
local helpers = require('test.functional.helpers')(after_each)
+local lsp_helpers = require('test.functional.plugin.lsp.helpers')
local clear = helpers.clear
local exec_lua = helpers.exec_lua
local eq = helpers.eq
local neq = require('test.helpers').neq
+local create_server_definition = lsp_helpers.create_server_definition
+
describe('vim.lsp.diagnostic', function()
local fake_uri
@@ -81,6 +84,7 @@ describe('vim.lsp.diagnostic', function()
local lines = {"1st line of text", "2nd line of text", "wow", "cool", "more", "lines"}
vim.fn.bufload(diagnostic_bufnr)
vim.api.nvim_buf_set_lines(diagnostic_bufnr, 0, 1, false, lines)
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
return diagnostic_bufnr
]], fake_uri)
end)
@@ -97,7 +101,6 @@ describe('vim.lsp.diagnostic', function()
}
diagnostics[1].code = 42
- diagnostics[1].tags = {"foo", "bar"}
diagnostics[1].data = "Hello world"
vim.lsp.diagnostic.on_publish_diagnostics(nil, {
@@ -110,10 +113,9 @@ describe('vim.lsp.diagnostic', function()
vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1)[1],
}
]]
- eq({code = 42, tags = {"foo", "bar"}, data = "Hello world"}, result[1].user_data.lsp)
+ eq({code = 42, data = "Hello world"}, result[1].user_data.lsp)
eq(42, result[1].code)
eq(42, result[2].code)
- eq({"foo", "bar"}, result[2].tags)
eq("Hello world", result[2].data)
end)
end)
@@ -267,4 +269,155 @@ describe('vim.lsp.diagnostic', function()
eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 0)
end)
end)
+
+ describe('vim.lsp.diagnostic.on_diagnostic', function()
+ before_each(function()
+ exec_lua(create_server_definition)
+ exec_lua([[
+ server = _create_server({
+ capabilities = {
+ diagnosticProvider = {
+ }
+ }
+ })
+
+ function get_extmarks(bufnr, client_id)
+ local namespace = vim.lsp.diagnostic.get_namespace(client_id, true)
+ local ns = vim.diagnostic.get_namespace(namespace)
+ local extmarks = {}
+ if ns.user_data.virt_text_ns then
+ for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.virt_text_ns, 0, -1, {details=true})) do
+ table.insert(extmarks, e)
+ end
+ end
+ if ns.user_data.underline_ns then
+ for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.underline_ns, 0, -1, {details=true})) do
+ table.insert(extmarks, e)
+ end
+ end
+ return extmarks
+ end
+
+ client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ ]])
+ end)
+
+ it('adds diagnostics to vim.diagnostics', function()
+ local diags = exec_lua([[
+ vim.lsp.diagnostic.on_diagnostic(nil,
+ {
+ kind = 'full',
+ items = {
+ make_error('Pull Diagnostic', 4, 4, 4, 4),
+ }
+ },
+ {
+ params = {
+ textDocument = { uri = fake_uri },
+ },
+ uri = fake_uri,
+ client_id = client_id,
+ },
+ {}
+ )
+
+ return vim.diagnostic.get(diagnostic_bufnr)
+ ]])
+ eq(1, #diags)
+ eq('Pull Diagnostic', diags[1].message)
+ end)
+
+ it('allows configuring the virtual text via vim.lsp.with', function()
+ local expected_spacing = 10
+ local extmarks = exec_lua(
+ [[
+ Diagnostic = vim.lsp.with(vim.lsp.diagnostic.on_diagnostic, {
+ virtual_text = {
+ spacing = ...,
+ },
+ })
+
+ Diagnostic(nil,
+ {
+ kind = 'full',
+ items = {
+ make_error('Pull Diagnostic', 4, 4, 4, 4),
+ }
+ },
+ {
+ params = {
+ textDocument = { uri = fake_uri },
+ },
+ uri = fake_uri,
+ client_id = client_id,
+ },
+ {}
+ )
+
+ return get_extmarks(diagnostic_bufnr, client_id)
+ ]],
+ expected_spacing
+ )
+ eq(2, #extmarks)
+ eq(expected_spacing, #extmarks[1][4].virt_text[1][1])
+ end)
+
+ it('clears diagnostics when client detaches', function()
+ exec_lua([[
+ vim.lsp.diagnostic.on_diagnostic(nil,
+ {
+ kind = 'full',
+ items = {
+ make_error('Pull Diagnostic', 4, 4, 4, 4),
+ }
+ },
+ {
+ params = {
+ textDocument = { uri = fake_uri },
+ },
+ uri = fake_uri,
+ client_id = client_id,
+ },
+ {}
+ )
+ ]])
+ local diags = exec_lua([[return vim.diagnostic.get(diagnostic_bufnr)]])
+ eq(1, #diags)
+
+ exec_lua([[ vim.lsp.stop_client(client_id) ]])
+
+ diags = exec_lua([[return vim.diagnostic.get(diagnostic_bufnr)]])
+ eq(0, #diags)
+ end)
+
+ it('keeps diagnostics when one client detaches and others still are attached', function()
+ exec_lua([[
+ client_id2 = vim.lsp.start({ name = 'dummy2', cmd = server.cmd })
+
+ vim.lsp.diagnostic.on_diagnostic(nil,
+ {
+ kind = 'full',
+ items = {
+ make_error('Pull Diagnostic', 4, 4, 4, 4),
+ }
+ },
+ {
+ params = {
+ textDocument = { uri = fake_uri },
+ },
+ uri = fake_uri,
+ client_id = client_id,
+ },
+ {}
+ )
+ ]])
+ local diags = exec_lua([[return vim.diagnostic.get(diagnostic_bufnr)]])
+ eq(1, #diags)
+
+ exec_lua([[ vim.lsp.stop_client(client_id2) ]])
+
+ diags = exec_lua([[return vim.diagnostic.get(diagnostic_bufnr)]])
+ eq(1, #diags)
+ end)
+ end)
end)
diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua
index 028ccb9e2c..15e6a62781 100644
--- a/test/functional/plugin/lsp/helpers.lua
+++ b/test/functional/plugin/lsp/helpers.lua
@@ -13,6 +13,7 @@ function M.clear_notrace()
-- solution: don't look too closely for dragons
clear {env={
NVIM_LUA_NOTRACK="1";
+ NVIM_APPNAME="nvim_lsp_test";
VIMRUNTIME=os.getenv"VIMRUNTIME";
}}
end
@@ -80,17 +81,15 @@ M.fake_lsp_logfile = 'Xtest-fake-lsp.log'
local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
exec_lua([=[
lsp = require('vim.lsp')
- local test_name, fixture_filename, logfile, timeout, options, settings = ...
+ local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ...
TEST_RPC_CLIENT_ID = lsp.start_client {
cmd_env = {
- NVIM_LOG_FILE = logfile;
+ NVIM_LOG_FILE = fake_lsp_logfile;
NVIM_LUA_NOTRACK = "1";
+ NVIM_APPNAME = "nvim_lsp_test";
};
cmd = {
- vim.v.progpath, '-Es', '-u', 'NONE', '--headless',
- "-c", string.format("lua TEST_NAME = %q", test_name),
- "-c", string.format("lua TIMEOUT = %d", timeout),
- "-c", "luafile "..fixture_filename,
+ vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout),
};
handlers = setmetatable({}, {
__index = function(t, method)
@@ -100,7 +99,7 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
end;
});
workspace_folders = {{
- uri = 'file://' .. vim.loop.cwd(),
+ uri = 'file://' .. vim.uv.cwd(),
name = 'test_folder',
}};
on_init = function(client, result)
diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua
index 4985da9cd7..724b3efb97 100644
--- a/test/functional/plugin/lsp/incremental_sync_spec.lua
+++ b/test/functional/plugin/lsp/incremental_sync_spec.lua
@@ -21,7 +21,7 @@ before_each(function ()
-- ["mac"] = '\r',
-- }
- -- local line_ending = format_line_ending[vim.api.nvim_buf_get_option(0, 'fileformat')]
+ -- local line_ending = format_line_ending[vim.api.nvim_get_option_value('fileformat', {})]
function test_register(bufnr, id, offset_encoding, line_ending)
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
new file mode 100644
index 0000000000..d0d55df72b
--- /dev/null
+++ b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -0,0 +1,204 @@
+local helpers = require('test.functional.helpers')(after_each)
+local lsp_helpers = require('test.functional.plugin.lsp.helpers')
+local Screen = require('test.functional.ui.screen')
+
+local eq = helpers.eq
+local dedent = helpers.dedent
+local exec_lua = helpers.exec_lua
+local insert = helpers.insert
+
+local clear_notrace = lsp_helpers.clear_notrace
+local create_server_definition = lsp_helpers.create_server_definition
+
+local text = dedent([[
+auto add(int a, int b) { return a + b; }
+
+int main() {
+ int x = 1;
+ int y = 2;
+ return add(x,y);
+}
+}]])
+
+local response = [==[
+[
+{"kind":1,"paddingLeft":false,"label":"-> int","position":{"character":22,"line":0},"paddingRight":false},
+{"kind":2,"paddingLeft":false,"label":"a:","position":{"character":15,"line":5},"paddingRight":true},
+{"kind":2,"paddingLeft":false,"label":"b:","position":{"character":17,"line":5},"paddingRight":true}
+]
+]==]
+
+local grid_without_inlay_hints = [[
+ auto add(int a, int b) { return a + b; } |
+ |
+ int main() { |
+ int x = 1; |
+ int y = 2; |
+ return add(x,y); |
+ } |
+ ^} |
+ |
+]]
+
+local grid_with_inlay_hints = [[
+ auto add(int a, int b)-> int { return a + b; } |
+ |
+ int main() { |
+ int x = 1; |
+ int y = 2; |
+ return add(a: x,b: y); |
+ } |
+ ^} |
+ |
+]]
+
+--- @type test.functional.ui.screen
+local screen
+before_each(function()
+ clear_notrace()
+ screen = Screen.new(50, 9)
+ screen:attach()
+
+ exec_lua(create_server_definition)
+ exec_lua([[
+ local response = ...
+ server = _create_server({
+ capabilities = {
+ inlayHintProvider = true,
+ },
+ handlers = {
+ ['textDocument/inlayHint'] = function()
+ return vim.json.decode(response)
+ end,
+ }
+ })
+
+ bufnr = vim.api.nvim_get_current_buf()
+ vim.api.nvim_win_set_buf(0, bufnr)
+
+ client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ ]], response)
+
+ insert(text)
+ exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints })
+end)
+
+after_each(function()
+ exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+end)
+
+describe('vim.lsp.inlay_hint', function()
+ it('clears inlay hints when sole client detaches', function()
+ exec_lua([[vim.lsp.stop_client(client_id)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ end)
+
+ it('does not clear inlay hints when one of several clients detaches', function()
+ exec_lua([[
+ server2 = _create_server({
+ capabilities = {
+ inlayHintProvider = true,
+ },
+ handlers = {
+ ['textDocument/inlayHint'] = function()
+ return {}
+ end,
+ }
+ })
+ client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
+ vim.lsp.inlay_hint.enable(bufnr)
+ ]])
+
+ exec_lua([[ vim.lsp.stop_client(client2) ]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
+
+ describe('enable()', function()
+ it('clears/applies inlay hints when passed false/true/nil', function()
+ exec_lua([[vim.lsp.inlay_hint.enable(bufnr, false)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+
+ exec_lua([[vim.lsp.inlay_hint.enable(bufnr, true)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+
+ exec_lua([[vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr))]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+
+ exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
+ end)
+
+ describe('get()', function()
+ it('returns filtered inlay hints', function()
+ --- @type lsp.InlayHint[]
+ local expected = vim.json.decode(response)
+ local expected2 = {
+ kind = 1,
+ paddingLeft = false,
+ label = ': int',
+ position = {
+ character = 10,
+ line = 2,
+ },
+ paddingRight = false,
+ }
+
+ exec_lua([[
+ local expected2 = ...
+ server2 = _create_server({
+ capabilities = {
+ inlayHintProvider = true,
+ },
+ handlers = {
+ ['textDocument/inlayHint'] = function()
+ return { expected2 }
+ end,
+ }
+ })
+ client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
+ vim.lsp.inlay_hint.enable(bufnr)
+ ]], expected2)
+
+ --- @type vim.lsp.inlay_hint.get.ret
+ local res = exec_lua([[return vim.lsp.inlay_hint.get()]])
+ eq(res, {
+ { 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 },
+ })
+
+ --- @type vim.lsp.inlay_hint.get.ret
+ res = exec_lua([[return vim.lsp.inlay_hint.get({
+ range = {
+ start = { line = 2, character = 10 },
+ ["end"] = { line = 2, character = 10 },
+ },
+ })]])
+ eq(res, {
+ { bufnr = 1, client_id = 2, inlay_hint = expected2 },
+ })
+
+ --- @type vim.lsp.inlay_hint.get.ret
+ res = exec_lua([[return vim.lsp.inlay_hint.get({
+ bufnr = vim.api.nvim_get_current_buf(),
+ range = {
+ start = { line = 4, character = 18 },
+ ["end"] = { line = 5, character = 17 },
+ },
+ })]])
+ eq(res, {
+ { bufnr = 1, client_id = 1, inlay_hint = expected[2] },
+ { bufnr = 1, client_id = 1, inlay_hint = expected[3] },
+ })
+
+ --- @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, {})
+ end)
+ end)
+end)
diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua
index 9c1ba86fe1..b7ac53f270 100644
--- a/test/functional/plugin/lsp/semantic_tokens_spec.lua
+++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua
@@ -24,6 +24,27 @@ end)
describe('semantic token highlighting', function()
+ local screen
+ before_each(function()
+ screen = Screen.new(40, 16)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = { bold = true, foreground = Screen.colors.Blue1 };
+ [2] = { foreground = Screen.colors.DarkCyan };
+ [3] = { foreground = Screen.colors.SlateBlue };
+ [4] = { bold = true, foreground = Screen.colors.SeaGreen };
+ [5] = { foreground = tonumber('0x6a0dad') };
+ [6] = { foreground = Screen.colors.Blue1 };
+ [7] = { bold = true, foreground = Screen.colors.DarkCyan };
+ [8] = { bold = true, foreground = Screen.colors.SlateBlue };
+ [9] = { bold = true, foreground = tonumber('0x6a0dad') };
+ }
+ command([[ hi link @lsp.type.namespace Type ]])
+ command([[ hi link @lsp.type.function Special ]])
+ command([[ hi link @lsp.type.comment Comment ]])
+ command([[ hi @lsp.mod.declaration gui=bold ]])
+ end)
+
describe('general', function()
local text = dedent([[
#include <iostream>
@@ -58,24 +79,7 @@ describe('semantic token highlighting', function()
"resultId":"2"
}]]
- local screen
before_each(function()
- screen = Screen.new(40, 16)
- screen:attach()
- screen:set_default_attr_ids {
- [1] = { bold = true, foreground = Screen.colors.Blue1 };
- [2] = { foreground = Screen.colors.DarkCyan };
- [3] = { foreground = Screen.colors.SlateBlue };
- [4] = { bold = true, foreground = Screen.colors.SeaGreen };
- [5] = { foreground = tonumber('0x6a0dad') };
- [6] = { foreground = Screen.colors.Blue1 };
- [7] = { bold = true, foreground = Screen.colors.DarkCyan };
- [8] = { bold = true, foreground = Screen.colors.SlateBlue };
- }
- command([[ hi link @namespace Type ]])
- command([[ hi link @function Special ]])
- command([[ hi @declaration gui=bold ]])
-
exec_lua(create_server_definition)
exec_lua([[
local legend, response, edit_response = ...
@@ -102,6 +106,7 @@ describe('semantic token highlighting', function()
exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_buf(0, bufnr)
+ vim.bo[bufnr].filetype = 'some-filetype'
client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
]])
@@ -127,6 +132,46 @@ describe('semantic token highlighting', function()
]] }
end)
+ it('use LspTokenUpdate and highlight_token', function()
+ exec_lua([[
+ vim.api.nvim_create_autocmd("LspTokenUpdate", {
+ callback = function(args)
+ local token = args.data.token
+ if token.type == "function" and token.modifiers.declaration then
+ vim.lsp.semantic_tokens.highlight_token(
+ token, args.buf, args.data.client_id, "Macro"
+ )
+ end
+ end,
+ })
+ bufnr = vim.api.nvim_get_current_buf()
+ vim.api.nvim_win_set_buf(0, bufnr)
+ client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ ]])
+
+ insert(text)
+
+ screen:expect { grid = [[
+ #include <iostream> |
+ |
+ int {9:main}() |
+ { |
+ int {7:x}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {2:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:#endif} |
+ } |
+ ^} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]] }
+
+ end)
+
it('buffer is unhighlighted when client is detached', function()
exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
@@ -578,16 +623,33 @@ describe('semantic token highlighting', function()
expected = {
{
line = 0,
- modifiers = {
- 'declaration',
- 'globalScope',
- },
+ modifiers = { declaration = true, globalScope = true },
start_col = 6,
end_col = 9,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
},
+ expected_screen = function()
+ screen:expect{grid=[[
+ char* {7:foo} = "\n"^; |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'clangd-15 on C++',
@@ -613,67 +675,67 @@ int main()
expected = {
{ -- main
line = 1,
- modifiers = { 'declaration', 'globalScope' },
+ modifiers = { declaration = true, globalScope = true },
start_col = 4,
end_col = 8,
type = 'function',
- extmark_added = true,
+ marked = true,
},
{ -- __cplusplus
line = 3,
- modifiers = { 'globalScope' },
+ modifiers = { globalScope = true },
start_col = 9,
end_col = 20,
type = 'macro',
- extmark_added = true,
+ marked = true,
},
{ -- x
line = 4,
- modifiers = { 'declaration', 'readonly', 'functionScope' },
+ modifiers = { declaration = true, readonly = true, functionScope = true },
start_col = 12,
end_col = 13,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{ -- std
line = 5,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
start_col = 2,
end_col = 5,
type = 'namespace',
- extmark_added = true,
+ marked = true,
},
{ -- cout
line = 5,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
start_col = 7,
end_col = 11,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{ -- x
line = 5,
- modifiers = { 'readonly', 'functionScope' },
+ modifiers = { readonly = true, functionScope = true },
start_col = 15,
end_col = 16,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{ -- std
line = 5,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
start_col = 20,
end_col = 23,
type = 'namespace',
- extmark_added = true,
+ marked = true,
},
{ -- endl
line = 5,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
start_col = 25,
end_col = 29,
type = 'function',
- extmark_added = true,
+ marked = true,
},
{ -- #else comment #endif
line = 6,
@@ -681,7 +743,7 @@ int main()
start_col = 0,
end_col = 7,
type = 'comment',
- extmark_added = true,
+ marked = true,
},
{
line = 7,
@@ -689,7 +751,7 @@ int main()
start_col = 0,
end_col = 11,
type = 'comment',
- extmark_added = true,
+ marked = true,
},
{
line = 8,
@@ -697,9 +759,29 @@ int main()
start_col = 0,
end_col = 8,
type = 'comment',
- extmark_added = true,
+ marked = true,
},
},
+ expected_screen = function()
+ screen:expect{grid=[[
+ #include <iostream> |
+ int {8:main}() |
+ { |
+ #ifdef {5:__cplusplus} |
+ const int {7:x} = 1; |
+ {4:std}::{2:cout} << {2:x} << {4:std}::{3:endl}; |
+ {6: #else} |
+ {6: comment} |
+ {6: #endif} |
+ ^} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'sumneko_lua',
@@ -722,25 +804,45 @@ b = "as"]],
start_col = 0,
end_col = 10,
type = 'comment', -- comment
- extmark_added = true,
+ marked = true,
},
{
line = 1,
- modifiers = { 'declaration' }, -- a
+ modifiers = { declaration = true }, -- a
start_col = 6,
end_col = 7,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{
line = 2,
- modifiers = { 'static' }, -- b (global)
+ modifiers = { static = true }, -- b (global)
start_col = 0,
end_col = 1,
type = 'variable',
- extmark_added = true,
+ marked = true,
},
},
+ expected_screen = function()
+ screen:expect{grid=[[
+ {6:-- comment} |
+ local {7:a} = 1 |
+ {2:b} = "as^" |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'rust-analyzer',
@@ -768,7 +870,7 @@ b = "as"]],
start_col = 0,
end_col = 3, -- pub
type = 'keyword',
- extmark_added = true,
+ marked = true,
},
{
line = 0,
@@ -776,15 +878,15 @@ b = "as"]],
start_col = 4,
end_col = 6, -- fn
type = 'keyword',
- extmark_added = true,
+ marked = true,
},
{
line = 0,
- modifiers = { 'declaration', 'public' },
+ modifiers = { declaration = true, public = true },
start_col = 7,
end_col = 11, -- main
type = 'function',
- extmark_added = true,
+ marked = true,
},
{
line = 0,
@@ -792,7 +894,7 @@ b = "as"]],
start_col = 11,
end_col = 12,
type = 'parenthesis',
- extmark_added = true,
+ marked = true,
},
{
line = 0,
@@ -800,7 +902,7 @@ b = "as"]],
start_col = 12,
end_col = 13,
type = 'parenthesis',
- extmark_added = true,
+ marked = true,
},
{
line = 0,
@@ -808,15 +910,15 @@ b = "as"]],
start_col = 14,
end_col = 15,
type = 'brace',
- extmark_added = true,
+ marked = true,
},
{
line = 1,
- modifiers = { 'controlFlow' },
+ modifiers = { controlFlow = true },
start_col = 4,
end_col = 9, -- break
type = 'keyword',
- extmark_added = true,
+ marked = true,
},
{
line = 1,
@@ -824,7 +926,7 @@ b = "as"]],
start_col = 10,
end_col = 13, -- rust
type = 'unresolvedReference',
- extmark_added = true,
+ marked = true,
},
{
line = 1,
@@ -832,15 +934,15 @@ b = "as"]],
start_col = 13,
end_col = 13,
type = 'semicolon',
- extmark_added = true,
+ marked = true,
},
{
line = 2,
- modifiers = { 'documentation' },
+ modifiers = { documentation = true },
start_col = 4,
end_col = 11,
type = 'comment', -- /// what?
- extmark_added = true,
+ marked = true,
},
{
line = 3,
@@ -848,9 +950,29 @@ b = "as"]],
start_col = 0,
end_col = 1,
type = 'brace',
- extmark_added = true,
+ marked = true,
},
},
+ expected_screen = function()
+ screen:expect{grid=[[
+ pub fn {8:main}() { |
+ break rust; |
+ //{6:/ what?} |
+ } |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
}) do
it(test.it, function()
@@ -877,6 +999,8 @@ b = "as"]],
insert(test.text)
+ test.expected_screen()
+
local highlights = exec_lua([[
local semantic_tokens = vim.lsp.semantic_tokens
return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights
@@ -906,28 +1030,68 @@ b = "as"]],
{
line = 0,
modifiers = {
- 'declaration',
- 'globalScope',
+ declaration = true,
+ globalScope = true,
},
start_col = 6,
end_col = 9,
type = 'variable',
- extmark_added = true,
+ marked = true,
}
},
expected2 = {
{
line = 1,
modifiers = {
- 'declaration',
- 'globalScope',
+ declaration = true,
+ globalScope = true,
},
start_col = 6,
end_col = 9,
type = 'variable',
- extmark_added = true,
+ marked = true,
}
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ char* {7:foo} = "\n"^; |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ ^ |
+ char* {7:foo} = "\n"; |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'response with multiple delta edits',
@@ -976,55 +1140,55 @@ int main()
line = 2,
start_col = 4,
end_col = 8,
- modifiers = { 'declaration', 'globalScope' },
+ modifiers = { declaration = true, globalScope = true },
type = 'function',
- extmark_added = true,
+ marked = true,
},
{
line = 4,
start_col = 8,
end_col = 9,
- modifiers = { 'declaration', 'functionScope' },
+ modifiers = { declaration = true, functionScope = true },
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{
line = 5,
start_col = 7,
end_col = 18,
- modifiers = { 'globalScope' },
+ modifiers = { globalScope = true },
type = 'macro',
- extmark_added = true,
+ marked = true,
},
{
line = 6,
start_col = 4,
end_col = 7,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
type = 'namespace',
- extmark_added = true,
+ marked = true,
},
{
line = 6,
start_col = 9,
end_col = 13,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{
line = 6,
start_col = 17,
end_col = 18,
- extmark_added = true,
- modifiers = { 'functionScope' },
+ marked = true,
+ modifiers = { functionScope = true },
type = 'variable',
},
{
line = 7,
start_col = 0,
end_col = 5,
- extmark_added = true,
+ marked = true,
modifiers = {},
type = 'comment',
},
@@ -1034,7 +1198,7 @@ int main()
modifiers = {},
start_col = 0,
type = 'comment',
- extmark_added = true,
+ marked = true,
},
{
line = 9,
@@ -1042,7 +1206,7 @@ int main()
end_col = 6,
modifiers = {},
type = 'comment',
- extmark_added = true,
+ marked = true,
}
},
expected2 = {
@@ -1050,63 +1214,63 @@ int main()
line = 2,
start_col = 4,
end_col = 8,
- modifiers = { 'declaration', 'globalScope' },
+ modifiers = { declaration = true, globalScope = true },
type = 'function',
- extmark_added = true,
+ marked = true,
},
{
line = 4,
start_col = 8,
end_col = 9,
- modifiers = { 'declaration', 'globalScope' },
+ modifiers = { declaration = true, globalScope = true },
type = 'function',
- extmark_added = true,
+ marked = true,
},
{
line = 5,
end_col = 12,
start_col = 11,
- modifiers = { 'declaration', 'functionScope' },
+ modifiers = { declaration = true, functionScope = true },
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{
line = 6,
start_col = 7,
end_col = 18,
- modifiers = { 'globalScope' },
+ modifiers = { globalScope = true },
type = 'macro',
- extmark_added = true,
+ marked = true,
},
{
line = 7,
start_col = 4,
end_col = 7,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
type = 'namespace',
- extmark_added = true,
+ marked = true,
},
{
line = 7,
start_col = 9,
end_col = 13,
- modifiers = { 'defaultLibrary', 'globalScope' },
+ modifiers = { defaultLibrary = true, globalScope = true },
type = 'variable',
- extmark_added = true,
+ marked = true,
},
{
line = 7,
start_col = 17,
end_col = 18,
- extmark_added = true,
- modifiers = { 'globalScope' },
+ marked = true,
+ modifiers = { globalScope = true },
type = 'function',
},
{
line = 8,
start_col = 0,
end_col = 5,
- extmark_added = true,
+ marked = true,
modifiers = {},
type = 'comment',
},
@@ -1116,7 +1280,7 @@ int main()
modifiers = {},
start_col = 0,
type = 'comment',
- extmark_added = true,
+ marked = true,
},
{
line = 10,
@@ -1124,9 +1288,49 @@ int main()
end_col = 6,
modifiers = {},
type = 'comment',
- extmark_added = true,
+ marked = true,
}
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ #include <iostream> |
+ |
+ int {8:main}() |
+ { |
+ int {7:x}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {2:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:#endif} |
+ ^} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ #include <iostream> |
+ |
+ int {8:main}() |
+ { |
+ int {8:x}(); |
+ double {7:y}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {3:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:^#endif} |
+ } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'optional token_edit.data on deletion',
@@ -1146,16 +1350,56 @@ int main()
{
line = 0,
modifiers = {
- 'declaration',
+ declaration = true,
},
start_col = 0,
end_col = 6,
type = 'variable',
- extmark_added = true,
+ marked = true,
}
},
expected2 = {
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ {7:string} = "test^" |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
}) do
it(test.it, function()
@@ -1192,6 +1436,8 @@ int main()
insert(test.text1)
+ test.expected_screen1()
+
local highlights = exec_lua([[
return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights
]])
@@ -1204,10 +1450,12 @@ int main()
exec_lua([[
local text = ...
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.fn.split(text, "\n"))
- vim.wait(15) -- wait fot debounce
+ vim.wait(15) -- wait for debounce
]], test.text2)
end
+ test.expected_screen2()
+
highlights = exec_lua([[
return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights
]])
diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua
index 7903885420..ba8bc7fe04 100644
--- a/test/functional/plugin/lsp/snippet_spec.lua
+++ b/test/functional/plugin/lsp/snippet_spec.lua
@@ -1,130 +1,71 @@
local helpers = require('test.functional.helpers')(after_each)
-local snippet = require('vim.lsp._snippet')
+local snippet = require('vim.lsp._snippet_grammar')
+local type = snippet.NodeType
local eq = helpers.eq
local exec_lua = helpers.exec_lua
-describe('vim.lsp._snippet', function()
+describe('vim.lsp._snippet_grammar', function()
before_each(helpers.clear)
after_each(helpers.clear)
local parse = function(...)
- return exec_lua('return require("vim.lsp._snippet").parse(...)', ...)
+ local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...)
+ return res.data.children
end
- it('should parse only text', function()
+ it('parses only text', function()
eq({
- type = snippet.NodeType.SNIPPET,
- children = {
- {
- type = snippet.NodeType.TEXT,
- raw = 'TE\\$\\}XT',
- esc = 'TE$}XT',
- },
- },
+ { type = type.Text, data = { text = 'TE$}XT' } },
}, parse('TE\\$\\}XT'))
end)
- it('should parse tabstop', function()
+ it('parses tabstops', function()
eq({
- type = snippet.NodeType.SNIPPET,
- children = {
- {
- type = snippet.NodeType.TABSTOP,
- tabstop = 1,
- },
- {
- type = snippet.NodeType.TABSTOP,
- tabstop = 2,
- },
- },
+ { type = type.Tabstop, data = { tabstop = 1 } },
+ { type = type.Tabstop, data = { tabstop = 2 } },
}, parse('$1${2}'))
end)
- it('should parse placeholders', function()
+ it('parses nested placeholders', function()
eq({
- type = snippet.NodeType.SNIPPET,
- children = {
- {
- type = snippet.NodeType.PLACEHOLDER,
+ {
+ type = type.Placeholder,
+ data = {
tabstop = 1,
- children = {
- {
- type = snippet.NodeType.PLACEHOLDER,
+ value = {
+ type = type.Placeholder,
+ data = {
tabstop = 2,
- children = {
- {
- type = snippet.NodeType.TEXT,
- raw = 'TE\\$\\}XT',
- esc = 'TE$}XT',
- },
- {
- type = snippet.NodeType.TABSTOP,
- tabstop = 3,
- },
- {
- type = snippet.NodeType.TABSTOP,
- tabstop = 1,
- transform = {
- type = snippet.NodeType.TRANSFORM,
- pattern = 'regex',
- option = 'i',
- format = {
- {
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- modifier = 'upcase',
- },
- },
- },
- },
- {
- type = snippet.NodeType.TEXT,
- raw = 'TE\\$\\}XT',
- esc = 'TE$}XT',
- },
- },
+ value = { type = type.Tabstop, data = { tabstop = 3 } },
},
},
},
},
- }, parse('${1:${2:TE\\$\\}XT$3${1/regex/${1:/upcase}/i}TE\\$\\}XT}}'))
+ }, parse('${1:${2:${3}}}'))
end)
- it('should parse variables', function()
+ it('parses variables', function()
eq({
- type = snippet.NodeType.SNIPPET,
- children = {
- {
- type = snippet.NodeType.VARIABLE,
- name = 'VAR',
- },
- {
- type = snippet.NodeType.VARIABLE,
+ { type = type.Variable, data = { name = 'VAR' } },
+ { type = type.Variable, data = { name = 'VAR' } },
+ {
+ type = type.Variable,
+ data = {
name = 'VAR',
+ default = { type = type.Tabstop, data = { tabstop = 1 } },
},
- {
- type = snippet.NodeType.VARIABLE,
+ },
+ {
+ type = type.Variable,
+ data = {
name = 'VAR',
- children = {
+ regex = 'regex',
+ options = '',
+ format = {
{
- type = snippet.NodeType.TABSTOP,
- tabstop = 1,
- },
- },
- },
- {
- type = snippet.NodeType.VARIABLE,
- name = 'VAR',
- transform = {
- type = snippet.NodeType.TRANSFORM,
- pattern = 'regex',
- format = {
- {
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- modifier = 'upcase',
- },
+ type = type.Format,
+ data = { capture = 1, modifier = 'upcase' },
},
},
},
@@ -132,105 +73,99 @@ describe('vim.lsp._snippet', function()
}, parse('$VAR${VAR}${VAR:$1}${VAR/regex/${1:/upcase}/}'))
end)
- it('should parse choice', function()
+ it('parses choice', function()
eq({
- type = snippet.NodeType.SNIPPET,
- children = {
- {
- type = snippet.NodeType.CHOICE,
- tabstop = 1,
- items = {
- ',',
- '|',
- },
- },
+ {
+ type = type.Choice,
+ data = { tabstop = 1, values = { ',', '|' } },
},
}, parse('${1|\\,,\\||}'))
end)
- it('should parse format', function()
- eq({
- type = snippet.NodeType.SNIPPET,
- children = {
+ it('parses format', function()
+ eq(
+ {
{
- type = snippet.NodeType.VARIABLE,
- name = 'VAR',
- transform = {
- type = snippet.NodeType.TRANSFORM,
- pattern = 'regex',
+ type = type.Variable,
+ data = {
+ name = 'VAR',
+ regex = 'regex',
+ options = '',
format = {
{
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- modifier = 'upcase',
+ type = type.Format,
+ data = { capture = 1, modifier = 'upcase' },
},
{
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- if_text = 'if_text',
- else_text = '',
+ type = type.Format,
+ data = { capture = 1, if_text = 'if_text' },
},
{
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- if_text = '',
- else_text = 'else_text',
+ type = type.Format,
+ data = { capture = 1, else_text = 'else_text' },
},
{
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- else_text = 'else_text',
- if_text = 'if_text',
+ type = type.Format,
+ data = { capture = 1, if_text = 'if_text', else_text = 'else_text' },
},
{
- type = snippet.NodeType.FORMAT,
- capture_index = 1,
- if_text = '',
- else_text = 'else_text',
+ type = type.Format,
+ data = { capture = 1, else_text = 'else_text' },
},
},
},
},
},
- }, parse('${VAR/regex/${1:/upcase}${1:+if_text}${1:-else_text}${1:?if_text:else_text}${1:else_text}/}'))
+ parse(
+ '${VAR/regex/${1:/upcase}${1:+if_text}${1:-else_text}${1:?if_text:else_text}${1:else_text}/}'
+ )
+ )
end)
- it('should parse empty strings', function()
+ it('parses empty strings', function()
eq({
- children = {
- {
- children = { {
- esc = '',
- raw = '',
- type = 7,
- } },
+ {
+ type = type.Placeholder,
+ data = {
tabstop = 1,
- type = 2,
- },
- {
- esc = ' ',
- raw = ' ',
- type = 7,
+ value = { type = type.Text, data = { text = '' } },
},
- {
+ },
+ {
+ type = type.Text,
+ data = { text = ' ' },
+ },
+ {
+ type = type.Variable,
+ data = {
name = 'VAR',
- transform = {
- format = {
- {
- capture_index = 1,
- else_text = '',
- if_text = '',
- type = 6,
- },
+ regex = 'erg',
+ format = {
+ {
+ type = type.Format,
+ data = { capture = 1, if_text = '' },
},
- option = 'g',
- pattern = 'erg',
- type = 5,
},
- type = 3,
+ options = 'g',
},
},
- type = 0,
- }, parse('${1:} ${VAR/erg/${1:?:}/g}'))
+ }, parse('${1:} ${VAR/erg/${1:+}/g}'))
+ end)
+
+ it('parses closing curly brace as text', function()
+ eq(
+ {
+ { type = type.Text, data = { text = 'function ' } },
+ { type = type.Tabstop, data = { tabstop = 1 } },
+ { type = type.Text, data = { text = '() {\n ' } },
+ { type = type.Tabstop, data = { tabstop = 0 } },
+ { type = type.Text, data = { text = '\n}' } },
+ },
+ parse(table.concat({
+ 'function $1() {',
+ ' $0',
+ '}',
+ }, '\n'))
+ )
end)
end)
diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua
new file mode 100644
index 0000000000..804dc32f0d
--- /dev/null
+++ b/test/functional/plugin/lsp/utils_spec.lua
@@ -0,0 +1,226 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local feed = helpers.feed
+
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+
+describe('vim.lsp.util', function()
+ before_each(helpers.clear)
+
+ describe('stylize_markdown', function()
+ local stylize_markdown = function(content, opts)
+ return exec_lua([[
+ local bufnr = vim.uri_to_bufnr("file:///fake/uri")
+ vim.fn.bufload(bufnr)
+
+ local args = { ... }
+ local content = args[1]
+ local opts = args[2]
+ local stripped_content = vim.lsp.util.stylize_markdown(bufnr, content, opts)
+
+ return stripped_content
+ ]], content, opts)
+ end
+
+ it('code fences', function()
+ local lines = {
+ "```lua",
+ "local hello = 'world'",
+ "```",
+ }
+ local expected = {
+ "local hello = 'world'",
+ }
+ local opts = {}
+ eq(expected, stylize_markdown(lines, opts))
+ end)
+
+ it('code fences with whitespace surrounded info string', function()
+ local lines = {
+ "``` lua ",
+ "local hello = 'world'",
+ "```",
+ }
+ local expected = {
+ "local hello = 'world'",
+ }
+ local opts = {}
+ eq(expected, stylize_markdown(lines, opts))
+ end)
+
+ it('adds separator after code block', function()
+ local lines = {
+ "```lua",
+ "local hello = 'world'",
+ "```",
+ "",
+ "something",
+ }
+ local expected = {
+ "local hello = 'world'",
+ "─────────────────────",
+ "something",
+ }
+ local opts = { separator = true }
+ eq(expected, stylize_markdown(lines, opts))
+ end)
+
+ it('replaces supported HTML entities', function()
+ local lines = {
+ "1 &lt; 2",
+ "3 &gt; 2",
+ "&quot;quoted&quot;",
+ "&apos;apos&apos;",
+ "&ensp; &emsp;",
+ "&amp;",
+ }
+ local expected = {
+ "1 < 2",
+ "3 > 2",
+ '"quoted"',
+ "'apos'",
+ " ",
+ "&",
+ }
+ local opts = {}
+ eq(expected, stylize_markdown(lines, opts))
+ end)
+ end)
+
+ describe('normalize_markdown', function ()
+ it('collapses consecutive blank lines', function ()
+ local result = exec_lua [[
+ local lines = {
+ 'foo',
+ '',
+ '',
+ '',
+ 'bar',
+ '',
+ 'baz'
+ }
+ return vim.lsp.util._normalize_markdown(lines)
+ ]]
+ local expected = {'foo', '', 'bar', '', 'baz'}
+ eq(expected, result)
+ end)
+
+ it('removes preceding and trailing empty lines', function ()
+ local result = exec_lua [[
+ local lines = {
+ '',
+ 'foo',
+ 'bar',
+ '',
+ ''
+ }
+ return vim.lsp.util._normalize_markdown(lines)
+ ]]
+ local expected = {'foo', 'bar'}
+ eq(expected, result)
+ end)
+ end)
+
+ describe("make_floating_popup_options", function ()
+
+ local function assert_anchor(anchor_bias, expected_anchor)
+ local opts = exec_lua([[
+ local args = { ... }
+ local anchor_bias = args[1]
+ return vim.lsp.util.make_floating_popup_options(30, 10, { anchor_bias = anchor_bias })
+ ]], anchor_bias)
+
+ eq(expected_anchor, string.sub(opts.anchor, 1, 1))
+ end
+
+ local screen
+ before_each(function ()
+ helpers.clear()
+ screen = Screen.new(80, 80)
+ screen:attach()
+ feed("79i<CR><Esc>") -- fill screen with empty lines
+ end)
+
+ describe('when on the first line it places window below', function ()
+ before_each(function ()
+ feed('gg')
+ end)
+
+ it('for anchor_bias = "auto"', function ()
+ assert_anchor('auto', 'N')
+ end)
+
+ it('for anchor_bias = "above"', function ()
+ assert_anchor('above', 'N')
+ end)
+
+ it('for anchor_bias = "below"', function ()
+ assert_anchor('below', 'N')
+ end)
+ end)
+
+ describe('when on the last line it places window above', function ()
+ before_each(function ()
+ feed('G')
+ end)
+
+ it('for anchor_bias = "auto"', function ()
+ assert_anchor('auto', 'S')
+ end)
+
+ it('for anchor_bias = "above"', function ()
+ assert_anchor('above', 'S')
+ end)
+
+ it('for anchor_bias = "below"', function ()
+ assert_anchor('below', 'S')
+ end)
+ end)
+
+ describe('with 20 lines above, 59 lines below', function ()
+ before_each(function ()
+ feed('gg20j')
+ end)
+
+ it('places window below for anchor_bias = "auto"', function ()
+ assert_anchor('auto', 'N')
+ end)
+
+ it('places window above for anchor_bias = "above"', function ()
+ assert_anchor('above', 'S')
+ end)
+
+ it('places window below for anchor_bias = "below"', function ()
+ assert_anchor('below', 'N')
+ end)
+ end)
+
+ describe('with 59 lines above, 20 lines below', function ()
+ before_each(function ()
+ feed('G20k')
+ end)
+
+ it('places window above for anchor_bias = "auto"', function ()
+ assert_anchor('auto', 'S')
+ end)
+
+ it('places window above for anchor_bias = "above"', function ()
+ assert_anchor('above', 'S')
+ end)
+
+ it('places window below for anchor_bias = "below"', function ()
+ assert_anchor('below', 'N')
+ end)
+
+ it('bordered window truncates dimensions correctly', function ()
+ local opts = exec_lua([[
+ return vim.lsp.util.make_floating_popup_options(100, 100, { border = 'single' })
+ ]])
+
+ eq(56, opts.height)
+ end)
+ end)
+ end)
+
+end)
diff --git a/test/functional/plugin/lsp/watchfiles_spec.lua b/test/functional/plugin/lsp/watchfiles_spec.lua
new file mode 100644
index 0000000000..a8260e0c98
--- /dev/null
+++ b/test/functional/plugin/lsp/watchfiles_spec.lua
@@ -0,0 +1,222 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+
+describe('vim.lsp._watchfiles', function()
+ before_each(helpers.clear)
+ after_each(helpers.clear)
+
+ local match = function(...)
+ return exec_lua('return require("vim.lsp._watchfiles")._match(...)', ...)
+ end
+
+ describe('glob matching', function()
+ it('should match literal strings', function()
+ eq(true, match('', ''))
+ eq(false, match('', 'a'))
+ eq(true, match('a', 'a'))
+ eq(true, match('/', '/'))
+ eq(true, match('abc', 'abc'))
+ eq(false, match('abc', 'abcdef'))
+ eq(false, match('abc', 'a'))
+ eq(false, match('abc', 'bc'))
+ eq(false, match('a', 'b'))
+ eq(false, match('.', 'a'))
+ eq(true, match('$', '$'))
+ eq(true, match('/dir', '/dir'))
+ eq(true, match('dir/', 'dir/'))
+ eq(true, match('dir/subdir', 'dir/subdir'))
+ eq(false, match('dir/subdir', 'subdir'))
+ eq(false, match('dir/subdir', 'dir/subdir/file'))
+ eq(true, match('🤠', '🤠'))
+ end)
+
+ it('should match * wildcards', function()
+ eq(false, match('*', ''))
+ eq(true, match('*', 'a'))
+ eq(false, match('*', '/'))
+ eq(false, match('*', '/a'))
+ eq(false, match('*', 'a/'))
+ eq(true, match('*', 'aaa'))
+ eq(true, match('*a', 'aa'))
+ eq(true, match('*a', 'abca'))
+ eq(true, match('*.txt', 'file.txt'))
+ eq(false, match('*.txt', 'file.txtxt'))
+ eq(false, match('*.txt', 'dir/file.txt'))
+ eq(false, match('*.txt', '/dir/file.txt'))
+ eq(false, match('*.txt', 'C:/dir/file.txt'))
+ eq(false, match('*.dir', 'test.dir/file'))
+ eq(true, match('file.*', 'file.txt'))
+ eq(false, match('file.*', 'not-file.txt'))
+ eq(true, match('*/file.txt', 'dir/file.txt'))
+ eq(false, match('*/file.txt', 'dir/subdir/file.txt'))
+ eq(false, match('*/file.txt', '/dir/file.txt'))
+ eq(true, match('dir/*', 'dir/file.txt'))
+ eq(false, match('dir/*', 'dir'))
+ eq(false, match('dir/*.txt', 'file.txt'))
+ eq(true, match('dir/*.txt', 'dir/file.txt'))
+ eq(false, match('dir/*.txt', 'dir/subdir/file.txt'))
+ eq(false, match('dir/*/file.txt', 'dir/file.txt'))
+ eq(true, match('dir/*/file.txt', 'dir/subdir/file.txt'))
+ eq(false, match('dir/*/file.txt', 'dir/subdir/subdir/file.txt'))
+
+ -- TODO: The spec does not describe this, but VSCode only interprets ** when it's by
+ -- itself in a path segment, and otherwise interprets ** as consecutive * directives.
+ -- The following tests show how this behavior should work, but is not yet fully implemented.
+ -- Currently, "a**" parses incorrectly as "a" "**" and "**a" parses correctly as "*" "*" "a".
+ -- see: https://github.com/microsoft/vscode/blob/eef30e7165e19b33daa1e15e92fa34ff4a5df0d3/src/vs/base/common/glob.ts#L112
+ eq(true, match('a**', 'abc')) -- '**' should parse as two '*'s when not by itself in a path segment
+ eq(true, match('**c', 'abc'))
+ -- eq(false, match('a**', 'ab')) -- each '*' should still represent at least one character
+ eq(false, match('**c', 'bc'))
+ eq(true, match('a**', 'abcd'))
+ eq(true, match('**d', 'abcd'))
+ -- eq(false, match('a**', 'abc/d'))
+ eq(false, match('**d', 'abc/d'))
+ end)
+
+ it('should match ? wildcards', function()
+ eq(false, match('?', ''))
+ eq(true, match('?', 'a'))
+ eq(false, match('??', 'a'))
+ eq(false, match('?', 'ab'))
+ eq(true, match('??', 'ab'))
+ eq(true, match('a?c', 'abc'))
+ eq(false, match('a?c', 'a/c'))
+ end)
+
+ it('should match ** wildcards', function()
+ eq(true, match('**', ''))
+ eq(true, match('**', 'a'))
+ eq(true, match('**', '/'))
+ eq(true, match('**', 'a/'))
+ eq(true, match('**', '/a'))
+ eq(true, match('**', 'C:/a'))
+ eq(true, match('**', 'a/a'))
+ eq(true, match('**', 'a/a/a'))
+ eq(false, match('/**', '')) -- /** matches leading / literally
+ eq(true, match('/**', '/'))
+ eq(true, match('/**', '/a/b/c'))
+ eq(true, match('**/', '')) -- **/ absorbs trailing /
+ eq(true, match('**/', '/a/b/c'))
+ eq(true, match('**/**', ''))
+ eq(true, match('**/**', 'a'))
+ eq(false, match('a/**', ''))
+ eq(false, match('a/**', 'a'))
+ eq(true, match('a/**', 'a/b'))
+ eq(true, match('a/**', 'a/b/c'))
+ eq(false, match('a/**', 'b/a'))
+ eq(false, match('a/**', '/a'))
+ eq(false, match('**/a', ''))
+ eq(true, match('**/a', 'a'))
+ eq(false, match('**/a', 'a/b'))
+ eq(true, match('**/a', '/a'))
+ eq(true, match('**/a', '/b/a'))
+ eq(true, match('**/a', '/c/b/a'))
+ eq(true, match('**/a', '/a/a'))
+ eq(true, match('**/a', '/abc/a'))
+ eq(false, match('a/**/c', 'a'))
+ eq(false, match('a/**/c', 'c'))
+ eq(true, match('a/**/c', 'a/c'))
+ eq(true, match('a/**/c', 'a/b/c'))
+ eq(true, match('a/**/c', 'a/b/b/c'))
+ eq(false, match('**/a/**', 'a'))
+ eq(true, match('**/a/**', 'a/'))
+ eq(false, match('**/a/**', '/dir/a'))
+ eq(false, match('**/a/**', 'dir/a'))
+ eq(true, match('**/a/**', 'dir/a/'))
+ eq(true, match('**/a/**', 'a/dir'))
+ eq(true, match('**/a/**', 'dir/a/dir'))
+ eq(true, match('**/a/**', '/a/dir'))
+ eq(true, match('**/a/**', 'C:/a/dir'))
+ eq(false, match('**/a/**', 'a.txt'))
+ end)
+
+ it('should match {} groups', function()
+ eq(true, match('{}', ''))
+ eq(false, match('{}', 'a'))
+ eq(true, match('a{}', 'a'))
+ eq(true, match('{}a', 'a'))
+ eq(true, match('{,}', ''))
+ eq(true, match('{a,}', ''))
+ eq(true, match('{a,}', 'a'))
+ eq(true, match('{a}', 'a'))
+ eq(false, match('{a}', 'aa'))
+ eq(false, match('{a}', 'ab'))
+ eq(true, match('{a?c}', 'abc'))
+ eq(false, match('{ab}', 'a'))
+ eq(false, match('{ab}', 'b'))
+ eq(true, match('{ab}', 'ab'))
+ eq(true, match('{a,b}', 'a'))
+ eq(true, match('{a,b}', 'b'))
+ eq(false, match('{a,b}', 'ab'))
+ eq(true, match('{ab,cd}', 'ab'))
+ eq(false, match('{ab,cd}', 'a'))
+ eq(true, match('{ab,cd}', 'cd'))
+ eq(true, match('{a,b,c}', 'c'))
+ eq(true, match('{a,{b,c}}', 'c'))
+ end)
+
+ it('should match [] groups', function()
+ eq(true, match('[]', '[]')) -- empty [] is a literal
+ eq(false, match('[a-z]', ''))
+ eq(true, match('[a-z]', 'a'))
+ eq(false, match('[a-z]', 'ab'))
+ eq(true, match('[a-z]', 'z'))
+ eq(true, match('[a-z]', 'j'))
+ eq(false, match('[a-f]', 'j'))
+ eq(false, match('[a-z]', '`')) -- 'a' - 1
+ eq(false, match('[a-z]', '{')) -- 'z' + 1
+ eq(false, match('[a-z]', 'A'))
+ eq(false, match('[a-z]', '5'))
+ eq(true, match('[A-Z]', 'A'))
+ eq(true, match('[A-Z]', 'Z'))
+ eq(true, match('[A-Z]', 'J'))
+ eq(false, match('[A-Z]', '@')) -- 'A' - 1
+ eq(false, match('[A-Z]', '[')) -- 'Z' + 1
+ eq(false, match('[A-Z]', 'a'))
+ eq(false, match('[A-Z]', '5'))
+ eq(true, match('[a-zA-Z0-9]', 'z'))
+ eq(true, match('[a-zA-Z0-9]', 'Z'))
+ eq(true, match('[a-zA-Z0-9]', '9'))
+ eq(false, match('[a-zA-Z0-9]', '&'))
+ end)
+
+ it('should match [!...] groups', function()
+ eq(true, match('[!]', '[!]')) -- [!] is a literal
+ eq(false, match('[!a-z]', ''))
+ eq(false, match('[!a-z]', 'a'))
+ eq(false, match('[!a-z]', 'z'))
+ eq(false, match('[!a-z]', 'j'))
+ eq(true, match('[!a-f]', 'j'))
+ eq(false, match('[!a-f]', 'jj'))
+ eq(true, match('[!a-z]', '`')) -- 'a' - 1
+ eq(true, match('[!a-z]', '{')) -- 'z' + 1
+ eq(false, match('[!a-zA-Z0-9]', 'a'))
+ eq(false, match('[!a-zA-Z0-9]', 'A'))
+ eq(false, match('[!a-zA-Z0-9]', '0'))
+ eq(true, match('[!a-zA-Z0-9]', '!'))
+ end)
+
+ it('should match complex patterns', function()
+ eq(false, match('**/*.{c,h}', ''))
+ eq(false, match('**/*.{c,h}', 'c'))
+ eq(false, match('**/*.{c,h}', 'file.m'))
+ eq(true, match('**/*.{c,h}', 'file.c'))
+ eq(true, match('**/*.{c,h}', 'file.h'))
+ eq(true, match('**/*.{c,h}', '/file.c'))
+ eq(true, match('**/*.{c,h}', 'dir/subdir/file.c'))
+ eq(true, match('**/*.{c,h}', 'dir/subdir/file.h'))
+ eq(true, match('**/*.{c,h}', '/dir/subdir/file.c'))
+ eq(true, match('**/*.{c,h}', 'C:/dir/subdir/file.c'))
+ eq(true, match('/dir/**/*.{c,h}', '/dir/file.c'))
+ eq(false, match('/dir/**/*.{c,h}', 'dir/file.c'))
+ eq(true, match('/dir/**/*.{c,h}', '/dir/subdir/subdir/file.c'))
+
+ eq(true, match('{[0-9],[a-z]}', '0'))
+ eq(true, match('{[0-9],[a-z]}', 'a'))
+ eq(false, match('{[0-9],[a-z]}', 'A'))
+ end)
+ end)
+end)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 5229022564..56d31a0e44 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -23,6 +23,7 @@ local is_ci = helpers.is_ci
local meths = helpers.meths
local is_os = helpers.is_os
local skip = helpers.skip
+local mkdir = helpers.mkdir
local clear_notrace = lsp_helpers.clear_notrace
local create_server_definition = lsp_helpers.create_server_definition
@@ -30,6 +31,13 @@ local fake_lsp_code = lsp_helpers.fake_lsp_code
local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile
local test_rpc_server = lsp_helpers.test_rpc_server
+local function get_buf_option(name, bufnr)
+ bufnr = bufnr or "BUFFER"
+ return exec_lua(
+ string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr)
+ )
+end
+
-- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837
if skip(is_os('win')) then return end
@@ -46,19 +54,18 @@ describe('LSP', function()
local test_name = "basic_init"
exec_lua([=[
lsp = require('vim.lsp')
- local test_name, fixture_filename, logfile = ...
+ local test_name, fake_lsp_code, fake_lsp_logfile = ...
function test__start_client()
return lsp.start_client {
cmd_env = {
- NVIM_LOG_FILE = logfile;
+ NVIM_LOG_FILE = fake_lsp_logfile;
+ NVIM_APPNAME = "nvim_lsp_test";
};
cmd = {
- vim.v.progpath, '-Es', '-u', 'NONE', '--headless',
- "-c", string.format("lua TEST_NAME = %q", test_name),
- "-c", "luafile "..fixture_filename;
+ vim.v.progpath, '-l', fake_lsp_code, test_name;
};
workspace_folders = {{
- uri = 'file://' .. vim.loop.cwd(),
+ uri = 'file://' .. vim.uv.cwd(),
name = 'test_folder',
}};
}
@@ -75,7 +82,7 @@ describe('LSP', function()
describe('server_name specified', function()
it('start_client(), stop_client()', function()
retry(nil, 4000, function()
- eq(1, exec_lua('return #lsp.get_active_clients()'))
+ eq(1, exec_lua('return #lsp.get_clients()'))
end)
eq(2, exec_lua([[
TEST_CLIENT2 = test__start_client()
@@ -86,20 +93,20 @@ describe('LSP', function()
return TEST_CLIENT3
]]))
retry(nil, 4000, function()
- eq(3, exec_lua('return #lsp.get_active_clients()'))
+ eq(3, exec_lua('return #lsp.get_clients()'))
end)
eq(false, exec_lua('return lsp.get_client_by_id(TEST_CLIENT1) == nil'))
eq(false, exec_lua('return lsp.get_client_by_id(TEST_CLIENT1).is_stopped()'))
exec_lua('return lsp.get_client_by_id(TEST_CLIENT1).stop()')
retry(nil, 4000, function()
- eq(2, exec_lua('return #lsp.get_active_clients()'))
+ eq(2, exec_lua('return #lsp.get_clients()'))
end)
eq(true, exec_lua('return lsp.get_client_by_id(TEST_CLIENT1) == nil'))
exec_lua('lsp.stop_client({TEST_CLIENT2, TEST_CLIENT3})')
retry(nil, 4000, function()
- eq(0, exec_lua('return #lsp.get_active_clients()'))
+ eq(0, exec_lua('return #lsp.get_clients()'))
end)
end)
@@ -109,12 +116,12 @@ describe('LSP', function()
TEST_CLIENT3 = test__start_client()
]])
retry(nil, 4000, function()
- eq(3, exec_lua('return #lsp.get_active_clients()'))
+ eq(3, exec_lua('return #lsp.get_clients()'))
end)
-- Stop all clients.
- exec_lua('lsp.stop_client(lsp.get_active_clients())')
+ exec_lua('lsp.stop_client(lsp.get_clients())')
retry(nil, 4000, function()
- eq(0, exec_lua('return #lsp.get_active_clients()'))
+ eq(0, exec_lua('return #lsp.get_clients()'))
end)
end)
end)
@@ -144,7 +151,7 @@ describe('LSP', function()
describe('basic_init test', function()
after_each(function()
stop()
- exec_lua("lsp.stop_client(lsp.get_active_clients(), true)")
+ exec_lua("lsp.stop_client(lsp.get_clients(), true)")
exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
end)
@@ -211,6 +218,34 @@ describe('LSP', function()
})
end)
+ it("should set the client's offset_encoding when positionEncoding capability is supported", function()
+ clear()
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local server = _create_server({
+ capabilities = {
+ positionEncoding = "utf-8"
+ },
+ })
+
+ local client_id = vim.lsp.start({
+ name = 'dummy',
+ cmd = server.cmd,
+ })
+
+ if not client_id then
+ return 'vim.lsp.start did not return client_id'
+ end
+
+ local client = vim.lsp.get_client_by_id(client_id)
+ if not client then
+ return 'No client found with id ' .. client_id
+ end
+ return client.offset_encoding
+ ]])
+ eq('utf-8', result)
+ end)
+
it('should succeed with manual shutdown', function()
if is_ci() then
pending('hangs the build on CI #14028, re-enable with freeze timeout #14204')
@@ -314,6 +349,118 @@ describe('LSP', function()
}
end)
+ it('should set default options on attach', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_init = function(_client)
+ client = _client
+ exec_lua [[
+ BUFFER = vim.api.nvim_create_buf(false, true)
+ lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)
+ ]]
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc"))
+ eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc"))
+ eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr"))
+ eq('', get_buf_option("keywordprg"))
+ eq(true, exec_lua[[
+ local keymap
+ vim.api.nvim_buf_call(BUFFER, function()
+ keymap = vim.fn.maparg("K", "n", false, true)
+ end)
+ return keymap.callback == vim.lsp.buf.hover
+ ]])
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('', get_buf_option("tagfunc"))
+ eq('', get_buf_option("omnifunc"))
+ eq('', get_buf_option("formatexpr"))
+ eq('', exec_lua[[
+ local keymap
+ vim.api.nvim_buf_call(BUFFER, function()
+ keymap = vim.fn.maparg("K", "n", false, false)
+ end)
+ return keymap
+ ]])
+ end;
+ }
+ end)
+
+ it('should overwrite options set by ftplugins', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_init = function(_client)
+ client = _client
+ exec_lua [[
+ vim.api.nvim_command('filetype plugin on')
+ BUFFER_1 = vim.api.nvim_create_buf(false, true)
+ BUFFER_2 = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_set_option_value('filetype', 'man', { buf = BUFFER_1 })
+ vim.api.nvim_set_option_value('filetype', 'xml', { buf = BUFFER_2 })
+ ]]
+
+ -- Sanity check to ensure that some values are set after setting filetype.
+ eq('v:lua.require\'man\'.goto_tag', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('xmlcomplete#CompleteTags', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('xmlformat#Format()', get_buf_option("formatexpr", "BUFFER_2"))
+
+ exec_lua [[
+ lsp.buf_attach_client(BUFFER_1, TEST_RPC_CLIENT_ID)
+ lsp.buf_attach_client(BUFFER_2, TEST_RPC_CLIENT_ID)
+ ]]
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr", "BUFFER_2"))
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('', get_buf_option("formatexpr", "BUFFER_2"))
+ end;
+ }
+ end)
+
+ it('should not overwrite user-defined options', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_init = function(_client)
+ client = _client
+ exec_lua [[
+ BUFFER = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_set_option_value('tagfunc', 'tfu', { buf = BUFFER })
+ vim.api.nvim_set_option_value('omnifunc', 'ofu', { buf = BUFFER })
+ vim.api.nvim_set_option_value('formatexpr', 'fex', { buf = BUFFER })
+ lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)
+ ]]
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('tfu', get_buf_option("tagfunc"))
+ eq('ofu', get_buf_option("omnifunc"))
+ eq('fex', get_buf_option("formatexpr"))
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('tfu', get_buf_option("tagfunc"))
+ eq('ofu', get_buf_option("omnifunc"))
+ eq('fex', get_buf_option("formatexpr"))
+ end;
+ }
+ end)
+
it('should detach buffer on bufwipe', function()
clear()
exec_lua(create_server_definition)
@@ -844,7 +991,7 @@ describe('LSP', function()
test_name = "check_tracked_requests_cleared";
on_init = function(_client)
command('let g:requests = 0')
- command('autocmd User LspRequest let g:requests+=1')
+ command('autocmd LspRequest * let g:requests+=1')
client = _client
client.request("slow_request")
eq(1, eval('g:requests'))
@@ -938,7 +1085,7 @@ describe('LSP', function()
eq(full_kind, client.server_capabilities().textDocumentSync.change)
eq(true, client.server_capabilities().textDocumentSync.openClose)
exec_lua [[
- assert(not lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID), "Shouldn't attach twice")
+ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID), "Already attached, returns true")
]]
end;
on_exit = function(code, signal)
@@ -1064,7 +1211,7 @@ describe('LSP', function()
"testing";
"123";
})
- vim.api.nvim_buf_set_option(BUFFER, 'eol', false)
+ vim.bo[BUFFER].eol = false
]]
end;
on_init = function(_client)
@@ -1097,6 +1244,67 @@ describe('LSP', function()
}
end)
+ it('should send correct range for inlay hints with noeol', function()
+ local expected_handlers = {
+ {NIL, {}, {method="shutdown", client_id=1}};
+ {NIL, {}, {method="finish", client_id=1}};
+ {NIL, {}, {
+ method="textDocument/inlayHint",
+ params = {
+ textDocument = {
+ uri = 'file://',
+ },
+ range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 1, character = 3 },
+ }
+ },
+ bufnr=2,
+ client_id=1,
+ }};
+ {NIL, {}, {method="start", client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "inlay_hint";
+ on_setup = function()
+ exec_lua [[
+ BUFFER = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, {
+ "testing";
+ "123";
+ })
+ vim.bo[BUFFER].eol = false
+ ]]
+ end;
+ on_init = function(_client)
+ client = _client
+ eq(true, client.supports_method('textDocument/inlayHint'))
+ exec_lua [[
+ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID))
+ ]]
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code")
+ eq(0, signal, "exit signal")
+ end;
+ on_handler = function(err, result, ctx)
+ if ctx.method == 'start' then
+ exec_lua [[
+ vim.lsp.inlay_hint.enable(BUFFER)
+ ]]
+ end
+ if ctx.method == 'textDocument/inlayHint' then
+ client.notify('finish')
+ end
+ eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler")
+ if ctx.method == 'finish' then
+ client.stop()
+ end
+ end;
+ }
+ end)
+
it('should check the body and didChange incremental', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};
@@ -1547,6 +1755,54 @@ describe('LSP', function()
'foobar';
}, buf_lines(1))
end)
+ it('it restores marks', function()
+ local edits = {
+ make_edit(1, 0, 2, 5, "foobar");
+ make_edit(4, 0, 5, 0, "barfoo");
+ }
+ eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 1, {})'))
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16")
+ eq({
+ 'First line of text';
+ 'foobar line of text';
+ 'Fourth line of text';
+ 'barfoo';
+ }, buf_lines(1))
+ local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ eq({ 2, 1 }, mark)
+ end)
+
+ it('it restores marks to last valid col', function()
+ local edits = {
+ make_edit(1, 0, 2, 15, "foobar");
+ make_edit(4, 0, 5, 0, "barfoo");
+ }
+ eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 10, {})'))
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16")
+ eq({
+ 'First line of text';
+ 'foobarext';
+ 'Fourth line of text';
+ 'barfoo';
+ }, buf_lines(1))
+ local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ eq({ 2, 9 }, mark)
+ end)
+
+ it('it restores marks to last valid line', function()
+ local edits = {
+ make_edit(1, 0, 4, 5, "foobar");
+ make_edit(4, 0, 5, 0, "barfoo");
+ }
+ eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 4, 1, {})'))
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16")
+ eq({
+ 'First line of text';
+ 'foobaro';
+ }, buf_lines(1))
+ local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ eq({ 2, 1 }, mark)
+ end)
describe('cursor position', function()
it('don\'t fix the cursor if the range contains the cursor', function()
@@ -1592,7 +1848,7 @@ describe('LSP', function()
eq({
'First line of text';
}, buf_lines(1))
- eq({ 1, 6 }, funcs.nvim_win_get_cursor(0))
+ eq({ 1, 17 }, funcs.nvim_win_get_cursor(0))
end)
it('fix the cursor row', function()
@@ -1611,6 +1867,9 @@ describe('LSP', function()
end)
it('fix the cursor col', function()
+ -- append empty last line. See #22636
+ exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, {''})
+
funcs.nvim_win_set_cursor(0, { 2, 11 })
local edits = {
make_edit(1, 7, 1, 11, '')
@@ -1622,6 +1881,7 @@ describe('LSP', function()
'Third line of text';
'Fourth line of text';
'å å ɧ 汉语 ↥ 🤦 🦄';
+ '';
}, buf_lines(1))
eq({ 2, 7 }, funcs.nvim_win_get_cursor(0))
end)
@@ -1923,7 +2183,7 @@ describe('LSP', function()
}
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
end)
it('Supports file creation in folder that needs to be created with CreateFile payload', function()
local tmpfile = helpers.tmpname()
@@ -1939,7 +2199,7 @@ describe('LSP', function()
}
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
end)
it('createFile does not touch file if it exists and ignoreIfExists is set', function()
local tmpfile = helpers.tmpname()
@@ -1957,7 +2217,7 @@ describe('LSP', function()
}
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
eq('Dummy content', read_file(tmpfile))
end)
it('createFile overrides file if overwrite is set', function()
@@ -1977,7 +2237,7 @@ describe('LSP', function()
}
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
eq('', read_file(tmpfile))
end)
it('DeleteFile delete file and buffer', function()
@@ -1998,7 +2258,7 @@ describe('LSP', function()
}
}
eq(true, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16'))
- eq(false, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile))
end)
it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function()
@@ -2017,58 +2277,13 @@ describe('LSP', function()
}
}
eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit))
- eq(false, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile))
- end)
- end)
-
- describe('completion_list_to_complete_items', function()
- -- Completion option precedence:
- -- textEdit.newText > insertText > label
- -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
- it('should choose right completion option', function ()
- local prefix = 'foo'
- local completion_list = {
- -- resolves into label
- { label='foobar', sortText="a" },
- { label='foobar', sortText="b", textEdit={} },
- -- resolves into insertText
- { label='foocar', sortText="c", insertText='foobar' },
- { label='foocar', sortText="d", insertText='foobar', textEdit={} },
- -- resolves into textEdit.newText
- { label='foocar', sortText="e", insertText='foodar', textEdit={newText='foobar'} },
- { label='foocar', sortText="f", textEdit={newText='foobar'} },
- -- real-world snippet text
- { label='foocar', sortText="g", insertText='foodar', insertTextFormat=2, textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} },
- { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', insertTextFormat=2, textEdit={} },
- -- nested snippet tokens
- { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', insertTextFormat=2, textEdit={} },
- -- braced tabstop
- { label='foocar', sortText="j", insertText='foodar()${0}', insertTextFormat=2, textEdit={} },
- -- plain text
- { label='foocar', sortText="k", insertText='foodar(${1:var1})', insertTextFormat=1, textEdit={} },
- }
- local completion_list_items = {items=completion_list}
- local expected = {
- { abbr = 'foobar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label = 'foobar', sortText="a" } } } } },
- { abbr = 'foobar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foobar', sortText="b", textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="c", insertText='foobar' } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="d", insertText='foobar', textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="e", insertText='foodar', textEdit={newText='foobar'} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="f", textEdit={newText='foobar'} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar(place holder, more ...holder{})', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="g", insertText='foodar', insertTextFormat=2, textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ1, var2 *typ2) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', insertTextFormat=2, textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ2 tail) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', insertTextFormat=2, textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar()', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="j", insertText='foodar()${0}', insertTextFormat=2, textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(${1:var1})', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="k", insertText='foodar(${1:var1})', insertTextFormat=1, textEdit={} } } } } },
- }
-
- eq(expected, exec_lua([[return vim.lsp.util.text_document_completion_list_to_complete_items(...)]], completion_list, prefix))
- eq(expected, exec_lua([[return vim.lsp.util.text_document_completion_list_to_complete_items(...)]], completion_list_items, prefix))
- eq({}, exec_lua([[return vim.lsp.util.text_document_completion_list_to_complete_items(...)]], {}, prefix))
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
end)
end)
describe('lsp.util.rename', function()
+ local pathsep = helpers.get_pathsep()
+
it('Can rename an existing file', function()
local old = helpers.tmpname()
write_file(old, 'Test content')
@@ -2085,12 +2300,56 @@ describe('LSP', function()
return vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
]], old, new)
eq({'Test content'}, lines)
- local exists = exec_lua('return vim.loop.fs_stat(...) ~= nil', old)
+ local exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', old)
eq(false, exists)
- exists = exec_lua('return vim.loop.fs_stat(...) ~= nil', new)
+ exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', new)
eq(true, exists)
os.remove(new)
end)
+ it("Kills old buffer after renaming an existing file", function()
+ local old = helpers.tmpname()
+ write_file(old, 'Test content')
+ local new = helpers.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('Can rename a directory', function()
+ -- only reserve the name, file must not exist for the test scenario
+ local old_dir = helpers.tmpname()
+ local new_dir = helpers.tmpname()
+ os.remove(old_dir)
+ os.remove(new_dir)
+
+ helpers.mkdir_p(old_dir)
+
+ local file = 'file.txt'
+ write_file(old_dir .. pathsep .. file, 'Test content')
+
+ local lines = exec_lua([[
+ local old_dir = select(1, ...)
+ local new_dir = select(2, ...)
+ local pathsep = select(3, ...)
+ local oldbufnr = vim.fn.bufadd(old_dir .. pathsep .. 'file')
+
+ vim.lsp.util.rename(old_dir, new_dir)
+ return vim.fn.bufloaded(oldbufnr)
+ ]], old_dir, new_dir, pathsep)
+ eq(0, 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)
it('Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function()
local old = helpers.tmpname()
write_file(old, 'Old File')
@@ -2104,7 +2363,7 @@ describe('LSP', function()
vim.lsp.util.rename(old, new, { ignoreIfExists = true })
]], old, new)
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
eq('New file', read_file(new))
exec_lua([[
@@ -2114,7 +2373,7 @@ describe('LSP', function()
vim.lsp.util.rename(old, new, { overwrite = false })
]], old, new)
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
eq('New file', read_file(new))
end)
it('Does override target if overwrite is true', function()
@@ -2129,8 +2388,8 @@ describe('LSP', function()
vim.lsp.util.rename(old, new, { overwrite = true })
]], old, new)
- eq(false, exec_lua('return vim.loop.fs_stat(...) ~= nil', old))
- eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', new))
+ eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
eq('Old file\n', read_file(new))
end)
end)
@@ -2142,7 +2401,14 @@ describe('LSP', function()
filename = '/fake/uri',
lnum = 1,
col = 3,
- text = 'testing'
+ text = 'testing',
+ user_data = {
+ uri = 'file:///fake/uri',
+ range = {
+ start = { line = 0, character = 2 },
+ ['end'] = { line = 0, character = 3 },
+ }
+ }
},
}
local actual = exec_lua [[
@@ -2168,7 +2434,18 @@ describe('LSP', function()
filename = '/fake/uri',
lnum = 1,
col = 3,
- text = 'testing'
+ text = 'testing',
+ user_data = {
+ targetUri = "file:///fake/uri",
+ targetRange = {
+ start = { line = 0, character = 2 },
+ ['end'] = { line = 0, character = 3 },
+ },
+ targetSelectionRange = {
+ start = { line = 0, character = 2 },
+ ['end'] = { line = 0, character = 3 },
+ }
+ }
},
}
local actual = exec_lua [[
@@ -2445,18 +2722,6 @@ describe('LSP', function()
end)
end)
- describe('lsp.util._get_completion_item_kind_name', function()
- it('returns the name specified by protocol', function()
- eq("Text", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1)"))
- eq("TypeParameter", exec_lua("return vim.lsp.util._get_completion_item_kind_name(25)"))
- end)
- it('returns the name not specified by protocol', function()
- eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(nil)"))
- eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(vim.NIL)"))
- eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1000)"))
- end)
- end)
-
describe('lsp.util._get_symbol_kind_name', function()
it('returns the name specified by protocol', function()
eq("File", exec_lua("return vim.lsp.util._get_symbol_kind_name(1)"))
@@ -2745,6 +3010,18 @@ describe('LSP', function()
it('calculates size correctly with wrapping', function()
eq({15,5}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents,{width = 15, wrap_at = 14})} ]])
end)
+
+ it('handles NUL bytes in text', function()
+ exec_lua([[ contents = {
+ '\000\001\002\003\004\005\006\007\008\009',
+ '\010\011\012\013\014\015\016\017\018\019',
+ '\020\021\022\023\024\025\026\027\028\029',
+ } ]])
+ command('set list listchars=')
+ eq({20,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]])
+ command('set display+=uhex')
+ eq({40,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]])
+ end)
end)
describe('lsp.util.trim.trim_empty_lines', function()
@@ -2761,7 +3038,7 @@ describe('LSP', function()
activeSignature = -1,
signatures = {
{
- documentation = "",
+ documentation = "some doc",
label = "TestEntity.TestEntity()",
parameters = {}
},
@@ -2769,7 +3046,7 @@ describe('LSP', function()
}
return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'cs', {','})
]]
- local expected = {'```cs', 'TestEntity.TestEntity()', '```', ''}
+ local expected = {'```cs', 'TestEntity.TestEntity()', '```', 'some doc'}
eq(expected, result)
end)
end)
@@ -2777,8 +3054,8 @@ describe('LSP', function()
describe('lsp.util.get_effective_tabstop', function()
local function test_tabstop(tabsize, shiftwidth)
exec_lua(string.format([[
- vim.api.nvim_buf_set_option(0, 'shiftwidth', %d)
- vim.api.nvim_buf_set_option(0, 'tabstop', 2)
+ vim.bo.shiftwidth = %d
+ vim.bo.tabstop = 2
]], shiftwidth))
eq(tabsize, exec_lua('return vim.lsp.util.get_effective_tabstop()'))
end
@@ -3000,9 +3277,10 @@ describe('LSP', function()
eq(0, signal, "exit signal")
end;
on_handler = function(err, result, ctx)
- -- Don't compare & assert params, they're not relevant for the testcase
+ -- Don't compare & assert params and version, they're not relevant for the testcase
-- This allows us to be lazy and avoid declaring them
ctx.params = nil
+ ctx.version = nil
eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler")
if ctx.method == 'start' then
@@ -3084,6 +3362,7 @@ describe('LSP', function()
end,
on_handler = function(err, result, ctx)
ctx.params = nil -- don't compare in assert
+ ctx.version = nil
eq(table.remove(expected_handlers), { err, result, ctx })
if ctx.method == 'start' then
exec_lua([[
@@ -3125,22 +3404,22 @@ describe('LSP', function()
vim.lsp.commands['executed_preferred'] = function()
end
end
- vim.lsp.commands['quickfix_command'] = function(cmd)
- vim.lsp.commands['executed_quickfix'] = function()
+ vim.lsp.commands['type_annotate_command'] = function(cmd)
+ vim.lsp.commands['executed_type_annotate'] = function()
end
end
local bufnr = vim.api.nvim_get_current_buf()
vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID)
vim.lsp.buf.code_action({ filter = function(a) return a.isPreferred end, apply = true, })
vim.lsp.buf.code_action({
- -- expect to be returned actions 'quickfix' and 'quickfix.foo'
- context = { only = {'quickfix'}, },
+ -- expect to be returned actions 'type-annotate' and 'type-annotate.foo'
+ context = { only = { 'type-annotate' }, },
apply = true,
filter = function(a)
- if a.kind == 'quickfix.foo' then
- vim.lsp.commands['filtered_quickfix_foo'] = function() end
+ if a.kind == 'type-annotate.foo' then
+ vim.lsp.commands['filtered_type_annotate_foo'] = function() end
return false
- elseif a.kind == 'quickfix' then
+ elseif a.kind == 'type-annotate' then
return true
else
assert(nil, 'unreachable')
@@ -3150,13 +3429,57 @@ describe('LSP', function()
]])
elseif ctx.method == 'shutdown' then
eq('function', exec_lua[[return type(vim.lsp.commands['executed_preferred'])]])
- eq('function', exec_lua[[return type(vim.lsp.commands['filtered_quickfix_foo'])]])
- eq('function', exec_lua[[return type(vim.lsp.commands['executed_quickfix'])]])
+ eq('function', exec_lua[[return type(vim.lsp.commands['filtered_type_annotate_foo'])]])
+ eq('function', exec_lua[[return type(vim.lsp.commands['executed_type_annotate'])]])
client.stop()
end
end
}
end)
+ it("Fallback to command execution on resolve error", function()
+ clear()
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local server = _create_server({
+ capabilities = {
+ executeCommandProvider = {
+ commands = {"command:1"},
+ },
+ codeActionProvider = {
+ resolveProvider = true
+ }
+ },
+ handlers = {
+ ["textDocument/codeAction"] = function()
+ return {
+ {
+ title = "Code Action 1",
+ command = {
+ title = "Command 1",
+ command = "command:1",
+ }
+ }
+ }
+ end,
+ ["codeAction/resolve"] = function()
+ return nil, "resolve failed"
+ end,
+ }
+ })
+
+ local client_id = vim.lsp.start({
+ name = "dummy",
+ cmd = server.cmd,
+ })
+
+ vim.lsp.buf.code_action({ apply = true })
+ vim.lsp.stop_client(client_id)
+ return server.messages
+ ]])
+ eq("codeAction/resolve", result[4].method)
+ eq("workspace/executeCommand", result[5].method)
+ eq("command:1", result[5].params.command)
+ end)
end)
describe('vim.lsp.commands', function()
it('Accepts only string keys', function()
@@ -3423,6 +3746,7 @@ describe('LSP', function()
vim.cmd.normal('v')
vim.api.nvim_win_set_cursor(0, { 2, 3 })
vim.lsp.buf.format({ bufnr = bufnr, false })
+ vim.lsp.stop_client(client_id)
return server.messages
]])
eq("textDocument/rangeFormatting", result[3].method)
@@ -3432,6 +3756,52 @@ describe('LSP', function()
}
eq(expected_range, result[3].params.range)
end)
+ it('format formats range in visual line mode', function()
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local server = _create_server({ capabilities = {
+ documentFormattingProvider = true,
+ documentRangeFormattingProvider = true,
+ }})
+ local bufnr = vim.api.nvim_get_current_buf()
+ local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ vim.api.nvim_win_set_buf(0, bufnr)
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {'foo', 'bar baz'})
+ vim.api.nvim_win_set_cursor(0, { 1, 2 })
+ vim.cmd.normal('V')
+ vim.api.nvim_win_set_cursor(0, { 2, 1 })
+ vim.lsp.buf.format({ bufnr = bufnr, false })
+
+ -- Format again with visual lines going from bottom to top
+ -- Must result in same formatting
+ vim.cmd.normal("<ESC>")
+ vim.api.nvim_win_set_cursor(0, { 2, 1 })
+ vim.cmd.normal('V')
+ vim.api.nvim_win_set_cursor(0, { 1, 2 })
+ vim.lsp.buf.format({ bufnr = bufnr, false })
+
+ vim.lsp.stop_client(client_id)
+ return server.messages
+ ]])
+ local expected_methods = {
+ "initialize",
+ "initialized",
+ "textDocument/rangeFormatting",
+ "$/cancelRequest",
+ "textDocument/rangeFormatting",
+ "$/cancelRequest",
+ "shutdown",
+ "exit",
+ }
+ eq(expected_methods, vim.tbl_map(function(x) return x.method end, result))
+ -- uses first column of start line and last column of end line
+ local expected_range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 1, character = 7 },
+ }
+ eq(expected_range, result[3].params.range)
+ eq(expected_range, result[5].params.range)
+ end)
it('Aborts with notify if no clients support requested method', function()
exec_lua(create_server_definition)
exec_lua([[
@@ -3468,7 +3838,7 @@ describe('LSP', function()
describe('cmd', function()
it('can connect to lsp server via rpc.connect', function()
local result = exec_lua [[
- local uv = vim.loop
+ local uv = vim.uv
local server = uv.new_tcp()
local init = nil
server:bind('127.0.0.1', 0)
@@ -3496,7 +3866,7 @@ describe('LSP', function()
describe('handlers', function()
it('handler can return false as response', function()
local result = exec_lua [[
- local uv = vim.loop
+ local uv = vim.uv
local server = uv.new_tcp()
local messages = {}
local responses = {}
@@ -3563,4 +3933,626 @@ describe('LSP', function()
eq(expected, result)
end)
end)
+
+ describe('#dynamic vim.lsp._dynamic', function()
+ it('supports dynamic registration', function()
+ local root_dir = helpers.tmpname()
+ os.remove(root_dir)
+ mkdir(root_dir)
+ local tmpfile = root_dir .. '/dynamic.foo'
+ local file = io.open(tmpfile, 'w')
+ file:close()
+
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local root_dir, tmpfile = ...
+
+ local server = _create_server()
+ local client_id = vim.lsp.start({
+ name = 'dynamic-test',
+ cmd = server.cmd,
+ root_dir = root_dir,
+ capabilities = {
+ textDocument = {
+ formatting = {
+ dynamicRegistration = true,
+ },
+ rangeFormatting = {
+ dynamicRegistration = true,
+ },
+ },
+ },
+ })
+
+ local expected_messages = 2 -- initialize, initialized
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'formatting',
+ method = 'textDocument/formatting',
+ registerOptions = {
+ documentSelector = {{
+ pattern = root_dir .. '/*.foo',
+ }},
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'range-formatting',
+ method = 'textDocument/rangeFormatting',
+ },
+ },
+ }, { client_id = client_id })
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'completion',
+ method = 'textDocument/completion',
+ },
+ },
+ }, { client_id = client_id })
+
+ local result = {}
+ local function check(method, fname)
+ local bufnr = fname and vim.fn.bufadd(fname) or nil
+ local client = vim.lsp.get_client_by_id(client_id)
+ result[#result + 1] = {method = method, fname = fname, supported = client.supports_method(method, {bufnr = bufnr})}
+ end
+
+
+ check("textDocument/formatting")
+ check("textDocument/formatting", tmpfile)
+ check("textDocument/rangeFormatting")
+ check("textDocument/rangeFormatting", tmpfile)
+ check("textDocument/completion")
+
+ return result
+ ]], root_dir, tmpfile)
+
+ eq(5, #result)
+ eq({method = 'textDocument/formatting', supported = false}, result[1])
+ eq({method = 'textDocument/formatting', supported = true, fname = tmpfile}, result[2])
+ eq({method = 'textDocument/rangeFormatting', supported = true}, result[3])
+ eq({method = 'textDocument/rangeFormatting', supported = true, fname = tmpfile}, result[4])
+ eq({method = 'textDocument/completion', supported = false}, result[5])
+ end)
+ end)
+
+ describe('vim.lsp._watchfiles', function()
+ it('sends notifications when files change', function()
+ skip(is_os('bsd'), "bsd only reports rename on folders if file inside change")
+ local root_dir = helpers.tmpname()
+ os.remove(root_dir)
+ mkdir(root_dir)
+
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local root_dir = ...
+
+ 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
+
+ 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
+
+ wait_for_messages()
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-0',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/watch',
+ kind = 7,
+ },
+ },
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ if watchfunc == vim._watch.poll then
+ vim.wait(100)
+ end
+
+ local path = root_dir .. '/watch'
+ local file = io.open(path, 'w')
+ file:close()
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ os.remove(path)
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ return server.messages
+ ]], root_dir)
+
+ local function watched_uri(fname)
+ return exec_lua([[
+ local root_dir, fname = ...
+ return vim.uri_from_fname(root_dir .. '/' .. fname)
+ ]], root_dir, fname)
+ end
+
+ 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)
+
+ it('correctly registers and unregisters', function()
+ local root_dir = '/some_dir'
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local root_dir = ...
+
+ 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
+ local function wait_for_messages()
+ assert(vim.wait(200, 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_messages()
+
+ local send_event
+ require('vim.lsp._watchfiles')._watchfunc = function(_, _, callback)
+ local stopped = false
+ send_event = function(...)
+ if not stopped then
+ callback(...)
+ end
+ end
+ return function()
+ stopped = true
+ end
+ end
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-0',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/*.watch0',
+ },
+ },
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ send_event(root_dir .. '/file.watch0', vim._watch.FileChangeType.Created)
+ send_event(root_dir .. '/file.watch1', vim._watch.FileChangeType.Created)
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-1',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/*.watch1',
+ },
+ },
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ vim.lsp.handlers['client/unregisterCapability'](nil, {
+ unregisterations = {
+ {
+ id = 'watchfiles-test-0',
+ method = 'workspace/didChangeWatchedFiles',
+ },
+ },
+ }, { client_id = client_id })
+
+ send_event(root_dir .. '/file.watch0', vim._watch.FileChangeType.Created)
+ send_event(root_dir .. '/file.watch1', vim._watch.FileChangeType.Created)
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ return server.messages
+ ]], root_dir)
+
+ local function watched_uri(fname)
+ return exec_lua([[
+ local root_dir, fname = ...
+ return vim.uri_from_fname(root_dir .. '/' .. fname)
+ ]], root_dir, fname)
+ end
+
+ eq(4, #result)
+ eq('workspace/didChangeWatchedFiles', result[3].method)
+ eq({
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('file.watch0'),
+ },
+ },
+ }, result[3].params)
+ eq('workspace/didChangeWatchedFiles', result[4].method)
+ eq({
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('file.watch1'),
+ },
+ },
+ }, result[4].params)
+ end)
+
+ it('correctly handles the registered watch kind', function()
+ local root_dir = 'some_dir'
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local root_dir = ...
+
+ 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
+ local function wait_for_messages()
+ assert(vim.wait(200, 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_messages()
+
+ local watch_callbacks = {}
+ local function send_event(...)
+ for _, cb in ipairs(watch_callbacks) do
+ cb(...)
+ end
+ end
+ require('vim.lsp._watchfiles')._watchfunc = function(_, _, callback)
+ table.insert(watch_callbacks, callback)
+ return function()
+ -- noop because this test never stops the watch
+ end
+ end
+
+ local protocol = require('vim.lsp.protocol')
+
+ local watchers = {}
+ local max_kind = protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete
+ for i = 0, max_kind do
+ table.insert(watchers, {
+ globPattern = {
+ baseUri = vim.uri_from_fname('/dir'),
+ pattern = 'watch'..tostring(i),
+ },
+ kind = i,
+ })
+ end
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-kind',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = watchers,
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ for i = 0, max_kind do
+ local filename = '/dir/watch' .. tostring(i)
+ send_event(filename, vim._watch.FileChangeType.Created)
+ send_event(filename, vim._watch.FileChangeType.Changed)
+ send_event(filename, vim._watch.FileChangeType.Deleted)
+ end
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ return server.messages
+ ]], root_dir)
+
+ local function watched_uri(fname)
+ return exec_lua([[
+ local fname = ...
+ return vim.uri_from_fname('/dir/' .. fname)
+ ]], fname)
+ end
+
+ eq(3, #result)
+ eq('workspace/didChangeWatchedFiles', result[3].method)
+ eq({
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('watch1'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]),
+ uri = watched_uri('watch2'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('watch3'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]),
+ uri = watched_uri('watch3'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
+ uri = watched_uri('watch4'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('watch5'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
+ uri = watched_uri('watch5'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]),
+ uri = watched_uri('watch6'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
+ uri = watched_uri('watch6'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('watch7'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]),
+ uri = watched_uri('watch7'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]),
+ uri = watched_uri('watch7'),
+ },
+ },
+ }, result[3].params)
+ end)
+
+ it('prunes duplicate events', function()
+ local root_dir = 'some_dir'
+ exec_lua(create_server_definition)
+ local result = exec_lua([[
+ local root_dir = ...
+
+ 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
+ local function wait_for_messages()
+ assert(vim.wait(200, 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_messages()
+
+ local send_event
+ require('vim.lsp._watchfiles')._watchfunc = function(_, _, callback)
+ send_event = callback
+ return function()
+ -- noop because this test never stops the watch
+ end
+ end
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-kind',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/*',
+ },
+ },
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ send_event('file1', vim._watch.FileChangeType.Created)
+ send_event('file1', vim._watch.FileChangeType.Created) -- pruned
+ send_event('file1', vim._watch.FileChangeType.Changed)
+ send_event('file2', vim._watch.FileChangeType.Created)
+ send_event('file1', vim._watch.FileChangeType.Changed) -- pruned
+
+ expected_messages = expected_messages + 1
+ wait_for_messages()
+
+ return server.messages
+ ]], root_dir)
+
+ local function watched_uri(fname)
+ return exec_lua([[
+ return vim.uri_from_fname(...)
+ ]], fname)
+ end
+
+ eq(3, #result)
+ eq('workspace/didChangeWatchedFiles', result[3].method)
+ eq({
+ changes = {
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('file1'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]),
+ uri = watched_uri('file1'),
+ },
+ {
+ type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]),
+ uri = watched_uri('file2'),
+ },
+ },
+ }, result[3].params)
+ end)
+
+ it("ignores registrations by servers when the client doesn't advertise support", function()
+ exec_lua(create_server_definition)
+ exec_lua([[
+ server = _create_server()
+ require('vim.lsp._watchfiles')._watchfunc = function(_, _, callback)
+ -- Since the registration is ignored, this should not execute and `watching` should stay false
+ watching = true
+ return function() end
+ end
+ ]])
+
+ local function check_registered(capabilities)
+ return exec_lua([[
+ watching = false
+ local client_id = vim.lsp.start({
+ name = 'watchfiles-test',
+ cmd = server.cmd,
+ root_dir = 'some_dir',
+ capabilities = ...,
+ }, {
+ reuse_client = function() return false end,
+ })
+
+ vim.lsp.handlers['client/registerCapability'](nil, {
+ registrations = {
+ {
+ id = 'watchfiles-test-kind',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/*',
+ },
+ },
+ },
+ },
+ },
+ }, { client_id = client_id })
+
+ -- Ensure no errors occur when unregistering something that was never really registered.
+ vim.lsp.handlers['client/unregisterCapability'](nil, {
+ unregisterations = {
+ {
+ id = 'watchfiles-test-kind',
+ method = 'workspace/didChangeWatchedFiles',
+ },
+ },
+ }, { client_id = client_id })
+
+ vim.lsp.stop_client(client_id, true)
+ return watching
+ ]], capabilities)
+ end
+
+ eq(true, check_registered(nil)) -- start{_client}() defaults to make_client_capabilities().
+ eq(false, check_registered(vim.empty_dict()))
+ eq(false, check_registered({
+ workspace = {
+ ignoreMe = true,
+ },
+ }))
+ eq(false, check_registered({
+ workspace = {
+ didChangeWatchedFiles = {
+ dynamicRegistration = false,
+ },
+ },
+ }))
+ eq(true, check_registered({
+ workspace = {
+ didChangeWatchedFiles = {
+ dynamicRegistration = true,
+ },
+ },
+ }))
+ end)
+ end)
end)
+
diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua
index c6c7d2b03d..815ddbc523 100644
--- a/test/functional/plugin/man_spec.lua
+++ b/test/functional/plugin/man_spec.lua
@@ -8,9 +8,30 @@ local nvim_prog = helpers.nvim_prog
local matches = helpers.matches
local write_file = helpers.write_file
local tmpname = helpers.tmpname
+local eq = helpers.eq
+local pesc = helpers.pesc
local skip = helpers.skip
local is_ci = helpers.is_ci
+-- Collects all names passed to find_path() after attempting ":Man foo".
+local function get_search_history(name)
+ local args = vim.split(name, ' ')
+ local code = [[
+ local args = ...
+ local man = require('runtime.lua.man')
+ local res = {}
+ man.find_path = function(sect, name)
+ table.insert(res, {sect, name})
+ return nil
+ end
+ local ok, rv = pcall(man.open_page, -1, {tab = 0}, args)
+ assert(not ok)
+ assert(rv and rv:match('no manual entry'))
+ return res
+ ]]
+ return exec_lua(code, args)
+end
+
clear()
if funcs.executable('man') == 0 then
pending('missing "man" command', function() end)
@@ -59,7 +80,7 @@ describe(':Man', function()
screen:expect([[
^this {b:is} {b:a} test |
- with {u:overstruck} text |
+ with {i:overstruck} text |
{eob:~ }|
{eob:~ }|
|
@@ -98,7 +119,7 @@ describe(':Man', function()
screen:expect([[
^this {b:is} {b:あ} test |
- with {u:överstrũck} te{i:xt¶} |
+ with {i:överstrũck} te{i:xt¶} |
{eob:~ }|
{eob:~ }|
|
@@ -115,7 +136,7 @@ describe(':Man', function()
screen:expect([[
{b:^_begins} |
{b:mid_dle} |
- {u:mid_dle} |
+ {i:mid_dle} |
{eob:~ }|
|
]])
@@ -169,8 +190,39 @@ describe(':Man', function()
write_file(actual_file, '')
local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'}
matches(('Error detected while processing command line:\r\n' ..
- 'man.lua: "no manual entry for %s"'):format(actual_file),
+ 'man.lua: "no manual entry for %s"'):format(pesc(actual_file)),
funcs.system(args, {''}))
os.remove(actual_file)
end)
+
+ it('tries variants with spaces, underscores #22503', function()
+ eq({
+ {'', 'NAME WITH SPACES'},
+ {'', 'NAME_WITH_SPACES'},
+ }, get_search_history('NAME WITH SPACES'))
+ eq({
+ {'3', 'some other man'},
+ {'3', 'some_other_man'},
+ }, get_search_history('3 some other man'))
+ eq({
+ {'3x', 'some other man'},
+ {'3x', 'some_other_man'},
+ }, get_search_history('3X some other man'))
+ eq({
+ {'3tcl', 'some other man'},
+ {'3tcl', 'some_other_man'},
+ }, get_search_history('3tcl some other man'))
+ eq({
+ {'n', 'some other man'},
+ {'n', 'some_other_man'},
+ }, get_search_history('n some other man'))
+ eq({
+ {'', '123some other man'},
+ {'', '123some_other_man'},
+ }, get_search_history('123some other man'))
+ eq({
+ {'1', 'other_man'},
+ {'1', 'other_man'},
+ }, get_search_history('other_man(1)'))
+ end)
end)
diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua
index 93cf6d2b77..8d37100607 100644
--- a/test/functional/plugin/shada_spec.lua
+++ b/test/functional/plugin/shada_spec.lua
@@ -2150,6 +2150,7 @@ describe('plugin/shada.vim', function()
teardown(function()
os.remove(fname)
+ os.remove(fname .. '.tst')
os.remove(fname_tmp)
end)
@@ -2180,8 +2181,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "a"',
}, nvim_eval('getline(1, "$")'))
- eq(false, curbuf('get_option', 'modified'))
- eq('shada', curbuf('get_option', 'filetype'))
+ eq(false, nvim('get_option_value', 'modified', {}))
+ eq('shada', nvim('get_option_value', 'filetype', {}))
nvim_command('edit ' .. fname_tmp)
eq({
'History entry with timestamp ' .. epoch .. ':',
@@ -2190,8 +2191,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "b"',
}, nvim_eval('getline(1, "$")'))
- eq(false, curbuf('get_option', 'modified'))
- eq('shada', curbuf('get_option', 'filetype'))
+ eq(false, nvim('get_option_value', 'modified', {}))
+ eq('shada', nvim('get_option_value', 'filetype', {}))
eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
neq({
'History entry with timestamp ' .. epoch .. ':',
@@ -2200,7 +2201,7 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "a"',
}, nvim_eval('getline(1, "$")'))
- neq(true, curbuf('get_option', 'modified'))
+ neq(true, nvim('get_option_value', 'modified', {}))
end)
it('event FileReadCmd', function()
@@ -2216,8 +2217,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "a"',
}, nvim_eval('getline(1, "$")'))
- eq(true, curbuf('get_option', 'modified'))
- neq('shada', curbuf('get_option', 'filetype'))
+ eq(true, nvim('get_option_value', 'modified', {}))
+ neq('shada', nvim('get_option_value', 'filetype', {}))
nvim_command('1,$read ' .. fname_tmp)
eq({
'',
@@ -2232,9 +2233,9 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "b"',
}, nvim_eval('getline(1, "$")'))
- eq(true, curbuf('get_option', 'modified'))
- neq('shada', curbuf('get_option', 'filetype'))
- curbuf('set_option', 'modified', false)
+ eq(true, nvim('get_option_value', 'modified', {}))
+ neq('shada', nvim('get_option_value', 'filetype', {}))
+ nvim('set_option_value', 'modified', false, {})
eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
eq({
'',
@@ -2249,7 +2250,7 @@ describe('plugin/shada.vim', function()
' - contents "ab"',
' - "b"',
}, nvim_eval('getline(1, "$")'))
- neq(true, curbuf('get_option', 'modified'))
+ neq(true, nvim('get_option_value', 'modified', {}))
end)
it('event BufWriteCmd', function()
@@ -2419,6 +2420,9 @@ describe('plugin/shada.vim', function()
it('event SourceCmd', function()
reset(fname)
+ finally(function()
+ nvim_command('set shadafile=NONE') -- Avoid writing shada file on exit
+ end)
wshada('\004\000\006\146\000\196\002ab')
wshada_tmp('\004\001\006\146\000\196\002bc')
eq(0, exc_exec('source ' .. fname))
@@ -2513,10 +2517,10 @@ describe('ftplugin/shada.vim', function()
it('sets options correctly', function()
nvim_command('filetype plugin indent on')
nvim_command('setlocal filetype=shada')
- eq(true, curbuf('get_option', 'expandtab'))
- eq(2, curbuf('get_option', 'tabstop'))
- eq(2, curbuf('get_option', 'softtabstop'))
- eq(2, curbuf('get_option', 'shiftwidth'))
+ eq(true, nvim('get_option_value', 'expandtab', {}))
+ eq(2, nvim('get_option_value', 'tabstop', {}))
+ eq(2, nvim('get_option_value', 'softtabstop', {}))
+ eq(2, nvim('get_option_value', 'shiftwidth', {}))
end)
it('sets indentkeys correctly', function()
diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua
new file mode 100644
index 0000000000..bd214e9c03
--- /dev/null
+++ b/test/functional/plugin/tutor_spec.lua
@@ -0,0 +1,95 @@
+local Screen = require('test.functional.ui.screen')
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local command = helpers.command
+local feed = helpers.feed
+local is_os = helpers.is_os
+
+describe(':Tutor', function()
+ local screen
+
+ before_each(function()
+ clear({ args = { '--clean' } })
+ command('set cmdheight=0')
+ command('Tutor')
+ screen = Screen.new(80, 30)
+ screen:set_default_attr_ids({
+ [0] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.Gray },
+ [1] = { bold = true },
+ [2] = { underline = true, foreground = tonumber('0x0088ff') },
+ [3] = { foreground = Screen.colors.SlateBlue },
+ [4] = { bold = true, foreground = Screen.colors.Brown },
+ [5] = { bold = true, foreground = Screen.colors.Magenta1 },
+ })
+ screen:attach()
+ end)
+
+ it('applies {unix:…,win:…} transform', function()
+ local expected = is_os('win') and [[
+ {0: }^ |
+ {0: } 3. To verify that a file was retrieved, cursor back and notice that there |
+ {0: } are now two copies of Lesson 5.3, the original and the retrieved version. |
+ {0: } |
+ {0: }{1:NOTE}: You can also read the output of an external command. For example, |
+ {0: } |
+ {0: } :r {4:!}dir |
+ {0: } |
+ {0: } reads the output of the ls command and puts it below the cursor. |
+ {0: } |
+ {0: }{3:#}{5: Lesson 5 SUMMARY} |
+ {0: } |
+ {0: } 1. {2::!command} executes an external command. |
+ {0: } |
+ {0: } Some useful examples are: |
+ {0: } :{4:!}dir - shows a directory listing |
+ {0: } :{4:!}del FILENAME - removes file FILENAME |
+ {0: } |
+ {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with |
+ {0: } name FILENAME. |
+ {0: } |
+ {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file |
+ {0: } FILENAME. |
+ {0: } |
+ {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it |
+ {0: } below the cursor position. |
+ {0: } |
+ {0: } 5. {2::r !dir} reads the output of the dir command and |
+ {0: } puts it below the cursor position. |
+ {0: } |
+ ]] or [[
+ {0: }^ |
+ {0: } 3. To verify that a file was retrieved, cursor back and notice that there |
+ {0: } are now two copies of Lesson 5.3, the original and the retrieved version. |
+ {0: } |
+ {0: }{1:NOTE}: You can also read the output of an external command. For example, |
+ {0: } |
+ {0: } :r {4:!}ls |
+ {0: } |
+ {0: } reads the output of the ls command and puts it below the cursor. |
+ {0: } |
+ {0: }{3:#}{5: Lesson 5 SUMMARY} |
+ {0: } |
+ {0: } 1. {2::!command} executes an external command. |
+ {0: } |
+ {0: } Some useful examples are: |
+ {0: } :{4:!}ls - shows a directory listing |
+ {0: } :{4:!}rm FILENAME - removes file FILENAME |
+ {0: } |
+ {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with |
+ {0: } name FILENAME. |
+ {0: } |
+ {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file |
+ {0: } FILENAME. |
+ {0: } |
+ {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it |
+ {0: } below the cursor position. |
+ {0: } |
+ {0: } 5. {2::r !ls} reads the output of the ls command and |
+ {0: } puts it below the cursor position. |
+ {0: } |
+ ]]
+
+ feed(':700<CR>zt')
+ screen:expect(expected)
+ end)
+end)
diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua
index 2c5185a974..0099183302 100644
--- a/test/functional/provider/clipboard_spec.lua
+++ b/test/functional/provider/clipboard_spec.lua
@@ -211,7 +211,7 @@ describe('clipboard', function()
eq('', eval('provider#clipboard#Error()'))
end)
- it('g:clipboard using VimL functions', function()
+ it('g:clipboard using Vimscript functions', function()
-- Implements a fake clipboard provider. cache_enabled is meaningless here.
source([[let g:clipboard = {
\ 'name': 'custom',
@@ -245,7 +245,7 @@ describe('clipboard', function()
eq({{'star', ''}, 'b'}, eval("g:dummy_clipboard_star"))
end)
- describe('g:clipboard[paste] VimL function', function()
+ describe('g:clipboard[paste] Vimscript function', function()
it('can return empty list for empty clipboard', function()
source([[let g:dummy_clipboard = []
let g:clipboard = {
@@ -301,7 +301,7 @@ end)
describe('clipboard (with fake clipboard.vim)', function()
local function reset(...)
- clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp', ...)
+ clear('--cmd', 'set rtp^=test/functional/fixtures', ...)
end
before_each(function()
diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua
index ce92831f4c..8049f0f3e2 100644
--- a/test/functional/provider/perl_spec.lua
+++ b/test/functional/provider/perl_spec.lua
@@ -5,12 +5,10 @@ local command = helpers.command
local write_file = helpers.write_file
local eval = helpers.eval
local retry = helpers.retry
-local curbufmeths = helpers.curbufmeths
+local meths = helpers.meths
local insert = helpers.insert
local expect = helpers.expect
local feed = helpers.feed
-local is_os = helpers.is_os
-local skip = helpers.skip
do
clear()
@@ -26,8 +24,6 @@ before_each(function()
end)
describe('legacy perl provider', function()
- skip(is_os('win'))
-
it('feature test', function()
eq(1, eval('has("perl")'))
end)
@@ -49,7 +45,7 @@ describe('legacy perl provider', function()
-- :perldo 1; doesn't change $_,
-- the buffer should not be changed
command('normal :perldo 1;')
- eq(false, curbufmeths.get_option('modified'))
+ eq(false, meths.get_option_value('modified', {}))
-- insert some text
insert('abc\ndef\nghi')
expect([[
@@ -70,7 +66,6 @@ describe('legacy perl provider', function()
end)
describe('perl provider', function()
- skip(is_os('win'))
teardown(function ()
os.remove('Xtest-perl-hello.pl')
os.remove('Xtest-perl-hello-plugin.pl')
diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua
index 3895b8613f..b1c326d04c 100644
--- a/test/functional/provider/provider_spec.lua
+++ b/test/functional/provider/provider_spec.lua
@@ -7,7 +7,7 @@ local pcall_err = helpers.pcall_err
describe('providers', function()
before_each(function()
- clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp')
+ clear('--cmd', 'set rtp^=test/functional/fixtures')
end)
it('with #Call(), missing g:loaded_xx_provider', function()
diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua
index fba96100fc..d3b967dfbe 100644
--- a/test/functional/provider/ruby_spec.lua
+++ b/test/functional/provider/ruby_spec.lua
@@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive
local clear = helpers.clear
local command = helpers.command
-local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
local exc_exec = helpers.exc_exec
local expect = helpers.expect
@@ -98,7 +97,7 @@ describe(':rubydo command', function()
it('does not modify the buffer if no changes are made', function()
command('normal :rubydo 42')
- eq(false, curbufmeths.get_option('modified'))
+ eq(false, meths.get_option_value('modified', {}))
end)
end)
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua
index 26a4569fce..b1c4ded541 100644
--- a/test/functional/shada/buffers_spec.lua
+++ b/test/functional/shada/buffers_spec.lua
@@ -1,7 +1,7 @@
-- shada buffer list saving/reading support
local helpers = require('test.functional.helpers')(after_each)
-local nvim_command, funcs, eq, curbufmeths =
- helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths
+local nvim_command, funcs, eq, curbufmeths, meths =
+ helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
@@ -48,7 +48,7 @@ describe('shada support code', function()
reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
- curbufmeths.set_option('buflisted', false)
+ meths.set_option_value('buflisted', false, {})
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(2, funcs.bufnr('$'))
@@ -60,7 +60,7 @@ describe('shada support code', function()
reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
- curbufmeths.set_option('buftype', 'quickfix')
+ meths.set_option_value('buftype', 'quickfix', {})
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(2, funcs.bufnr('$'))
diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua
index fb3ec4a87c..cd99d38345 100644
--- a/test/functional/shada/helpers.lua
+++ b/test/functional/shada/helpers.lua
@@ -33,6 +33,7 @@ local function reset(o)
end
local clear = function()
+ helpers.expect_exit(helpers.command, 'qall!')
os.remove(tmpname)
end
diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua
index d1daf6c7cc..433db3171e 100644
--- a/test/functional/shada/history_spec.lua
+++ b/test/functional/shada/history_spec.lua
@@ -32,7 +32,6 @@ describe('ShaDa support code', function()
nvim_command('rshada')
eq('" Test 2', funcs.histget(':', -1))
eq('" Test', funcs.histget(':', -2))
- expect_exit(nvim_command, 'qall')
end)
it('respects &history when dumping',
@@ -107,13 +106,13 @@ describe('ShaDa support code', function()
end)
it('dumps and loads last search pattern with offset', function()
- meths.set_option('wrapscan', false)
+ meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0/a/e+1\n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
nvim_command('wshada')
reset()
- meths.set_option('wrapscan', false)
+ meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
@@ -122,13 +121,13 @@ describe('ShaDa support code', function()
it('dumps and loads last search pattern with offset and backward direction',
function()
- meths.set_option('wrapscan', false)
+ meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'})
nvim_feed('G$?a?e+1\n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
nvim_command('wshada')
reset()
- meths.set_option('wrapscan', false)
+ meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'})
nvim_feed('G$n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua
index a91be18841..7f03022ab8 100644
--- a/test/functional/shada/marks_spec.lua
+++ b/test/functional/shada/marks_spec.lua
@@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq =
helpers.meths, helpers.curwinmeths, helpers.curbufmeths, helpers.command,
helpers.funcs, helpers.eq
+local feed = helpers.feed
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
local expect_exit = helpers.expect_exit
@@ -248,4 +249,49 @@ describe('ShaDa support code', function()
eq('', funcs.system(argv))
eq(0, exc_exec('rshada'))
end)
+
+ it('updates deleted marks with :delmarks', function()
+ nvim_command('edit ' .. testfilename)
+
+ nvim_command('mark A')
+ nvim_command('mark a')
+ -- create a change to set the '.' mark,
+ -- since it can't be set via :mark
+ feed('ggifoobar<esc>')
+ nvim_command('wshada')
+
+ reset()
+ nvim_command('edit ' .. testfilename)
+ nvim_command('normal! `A`a`.')
+ nvim_command('delmarks A a .')
+ nvim_command('wshada')
+
+ reset()
+ nvim_command('edit ' .. testfilename)
+ eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
+ eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
+ eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
+ end)
+
+ it('updates deleted marks with :delmarks!', function()
+ nvim_command('edit ' .. testfilename)
+
+ nvim_command('mark A')
+ nvim_command('mark a')
+ feed('ggifoobar<esc>')
+ nvim_command('wshada')
+
+ reset()
+ nvim_command('edit ' .. testfilename)
+ nvim_command('normal! `A`a`.')
+ nvim_command('delmarks!')
+ nvim_command('wshada')
+
+ reset()
+ nvim_command('edit ' .. testfilename)
+ eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
+ eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
+ -- Make sure that uppercase marks aren't deleted.
+ nvim_command('normal! `A')
+ end)
end)
diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua
index da2fbbe029..dad7aa851d 100644
--- a/test/functional/shada/merging_spec.lua
+++ b/test/functional/shada/merging_spec.lua
@@ -1115,5 +1115,3 @@ describe('ShaDa changes support code', function()
eq(found, 100)
end)
end)
-
--- vim: ts=2 sw=2
diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua
index 88a99d9b55..3a3238eb34 100644
--- a/test/functional/shada/shada_spec.lua
+++ b/test/functional/shada/shada_spec.lua
@@ -8,7 +8,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec =
local is_os = helpers.is_os
local skip = helpers.skip
-local lfs = require('lfs')
+local luv = require('luv')
local paths = require('test.cmakeconfig.paths')
local mpack = require('mpack')
@@ -29,7 +29,7 @@ describe('ShaDa support code', function()
after_each(function()
clear()
clean()
- lfs.rmdir(dirname)
+ luv.fs_rmdir(dirname)
end)
it('preserves `s` item size limit with unknown entries', function()
@@ -81,7 +81,7 @@ describe('ShaDa support code', function()
wshada('Some text file')
eq(0, exc_exec('wshada! ' .. shada_fname))
eq(1, read_shada_file(shada_fname)[1].type)
- eq(nil, lfs.attributes(shada_fname .. '.tmp.a'))
+ eq(nil, luv.fs_stat(shada_fname .. '.tmp.a'))
end)
it('leaves .tmp.b in-place when there is error in original ShaDa and it has .tmp.a', function()
@@ -126,34 +126,16 @@ describe('ShaDa support code', function()
wshada(s .. table.concat(msgpack, e .. s) .. e)
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
- local typ = mpack.unpack(s)
+ local typ = mpack.decode(s)
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == typ then
found = found + 1
- eq(mpack.unpack(msgpack[found]), v.timestamp)
+ eq(mpack.decode(msgpack[found]), v.timestamp)
end
end
eq(#msgpack, found)
end)
- it('does not write NONE file', function()
- local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
- '--headless', '--cmd', 'qall'}, true)
- session:close()
- eq(nil, lfs.attributes('NONE'))
- eq(nil, lfs.attributes('NONE.tmp.a'))
- end)
-
- it('does not read NONE file', function()
- write_file('NONE', '\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
- local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
- '--headless'}, true)
- set_session(session)
- eq('', funcs.getreg('a'))
- session:close()
- os.remove('NONE')
- end)
-
local marklike = {[7]=true, [8]=true, [10]=true, [11]=true}
local find_file = function(fname)
local found = {}
@@ -214,30 +196,30 @@ describe('ShaDa support code', function()
end)
it('is able to set &shada after &viminfo', function()
- meths.set_option('viminfo', '\'10')
- eq('\'10', meths.get_option('viminfo'))
- eq('\'10', meths.get_option('shada'))
- meths.set_option('shada', '')
- eq('', meths.get_option('viminfo'))
- eq('', meths.get_option('shada'))
+ meths.set_option_value('viminfo', '\'10', {})
+ eq('\'10', meths.get_option_value('viminfo', {}))
+ eq('\'10', meths.get_option_value('shada', {}))
+ meths.set_option_value('shada', '', {})
+ eq('', meths.get_option_value('viminfo', {}))
+ eq('', meths.get_option_value('shada', {}))
end)
it('is able to set all& after setting &shada', function()
- meths.set_option('shada', '\'10')
- eq('\'10', meths.get_option('viminfo'))
- eq('\'10', meths.get_option('shada'))
+ meths.set_option_value('shada', '\'10', {})
+ eq('\'10', meths.get_option_value('viminfo', {}))
+ eq('\'10', meths.get_option_value('shada', {}))
nvim_command('set all&')
- eq('!,\'100,<50,s10,h', meths.get_option('viminfo'))
- eq('!,\'100,<50,s10,h', meths.get_option('shada'))
+ eq('!,\'100,<50,s10,h', meths.get_option_value('viminfo', {}))
+ eq('!,\'100,<50,s10,h', meths.get_option_value('shada', {}))
end)
it('is able to set &shada after &viminfo using :set', function()
nvim_command('set viminfo=\'10')
- eq('\'10', meths.get_option('viminfo'))
- eq('\'10', meths.get_option('shada'))
+ eq('\'10', meths.get_option_value('viminfo', {}))
+ eq('\'10', meths.get_option_value('shada', {}))
nvim_command('set shada=')
- eq('', meths.get_option('viminfo'))
- eq('', meths.get_option('shada'))
+ eq('', meths.get_option_value('viminfo', {}))
+ eq('', meths.get_option_value('shada', {}))
end)
it('setting &shada gives proper error message on missing number', function()
@@ -255,11 +237,31 @@ describe('ShaDa support code', function()
funcs.mkdir(dirname, '', 0)
eq(0, funcs.filewritable(dirname))
reset{shadafile=dirshada, args={'--cmd', 'set shada='}}
- meths.set_option('shada', '\'10')
+ meths.set_option_value('shada', '\'10', {})
eq('Vim(wshada):E886: System error while opening ShaDa file '
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
.. 'before writing it: permission denied',
exc_exec('wshada'))
- meths.set_option('shada', '')
+ meths.set_option_value('shada', '', {})
+ end)
+end)
+
+describe('ShaDa support code', function()
+ it('does not write NONE file', function()
+ local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
+ '--headless', '--cmd', 'qall'}, true)
+ session:close()
+ eq(nil, luv.fs_stat('NONE'))
+ eq(nil, luv.fs_stat('NONE.tmp.a'))
+ end)
+
+ it('does not read NONE file', function()
+ write_file('NONE', '\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
+ local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
+ '--headless'}, true)
+ set_session(session)
+ eq('', funcs.getreg('a'))
+ session:close()
+ os.remove('NONE')
end)
end)
diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua
index 724791343d..93641fc576 100644
--- a/test/functional/terminal/api_spec.lua
+++ b/test/functional/terminal/api_spec.lua
@@ -66,10 +66,10 @@ describe('api', function()
screen:expect([[
[tui] insert-mode |
- [socket 1] this is more t{4: }|
- han 25 columns {4: }|
- [socket 2] input{1: } {4: }|
- {4:~ }|
+ [socket 1] this is more t |
+ han 25 columns |
+ [socket 2] input{1: } |
+ {4:~ } |
{3:-- INSERT --} |
{3:-- TERMINAL --} |
]])
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 9c8b983ff7..6fcd029a5b 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -17,14 +17,14 @@ local sleep = helpers.sleep
local funcs = helpers.funcs
local is_os = helpers.is_os
local skip = helpers.skip
+local nvim_prog = helpers.nvim_prog
describe(':terminal buffer', function()
local screen
before_each(function()
clear()
- feed_command('set modifiable swapfile undolevels=20')
- poke_eventloop()
+ command('set modifiable swapfile undolevels=20')
screen = thelpers.screen_setup()
end)
@@ -197,12 +197,11 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies.
- nvim('set_option', 'statusline', '==========')
- feed_command('set laststatus=0')
+ nvim('set_option_value', 'statusline', '==========', {})
-- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")')
- local exitcmd = helpers.is_os('win')
+ local exitcmd = is_os('win')
and "['cmd', '/c', 'exit']"
or "['sh', '-c', 'exit']"
source([[
@@ -231,8 +230,6 @@ describe(':terminal buffer', function()
neq(tbuf, eval('bufnr("%")'))
feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")'))
-
- feed_command('set laststatus=1') -- Restore laststatus to the default.
end)
it('term_close() use-after-free #4393', function()
@@ -281,6 +278,7 @@ describe(':terminal buffer', function()
end)
it('requires bang (!) to close a running job #15402', function()
+ skip(is_os('win'), "Test freezes the CI and makes it time out")
eq('Vim(wqall):E948: Job still running', exc_exec('wqall'))
for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do
matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$',
@@ -412,14 +410,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function()
feed_command('bdelete!')
eq('', exec_lua([[return _G.cb_error]]))
end)
-
- it('runs TextChangedT event', function()
- meths.set_var('called', 0)
- command('autocmd TextChangedT * ++once let g:called = 1')
- feed_command('terminal')
- feed('iaa')
- eq(1, meths.get_var('called'))
- end)
end)
it('terminal truncates number of composing characters to 5', function()
@@ -429,3 +419,141 @@ it('terminal truncates number of composing characters to 5', function()
meths.chan_send(chan, 'a' .. composing:rep(8))
retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end)
end)
+
+describe('terminal input', function()
+ before_each(function()
+ clear()
+ exec_lua([[
+ _G.input_data = ''
+ vim.api.nvim_open_term(0, { on_input = function(_, _, _, data)
+ _G.input_data = _G.input_data .. data
+ end })
+ ]])
+ feed('i')
+ poke_eventloop()
+ end)
+
+ it('<C-Space> is sent as NUL byte', function()
+ feed('aaa<C-Space>bbb')
+ eq('aaa\0bbb', exec_lua([[return _G.input_data]]))
+ end)
+
+ it('unknown special keys are not sent', function()
+ feed('aaa<Help>bbb')
+ eq('aaabbb', exec_lua([[return _G.input_data]]))
+ end)
+end)
+
+describe('terminal input', function()
+ it('sends various special keys with modifiers', function()
+ clear()
+ local screen = thelpers.screen_setup(0,
+ string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--cmd", "startinsert"]]=], nvim_prog))
+ screen:expect{grid=[[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,1 All}|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]]}
+ for _, key in ipairs({
+ '<M-Tab>', '<M-CR>', '<M-Esc>',
+ '<BS>', '<S-Tab>', '<Insert>', '<Del>', '<PageUp>', '<PageDown>',
+ '<S-Up>', '<C-Up>', '<Up>', '<S-Down>', '<C-Down>', '<Down>',
+ '<S-Left>', '<C-Left>', '<Left>', '<S-Right>', '<C-Right>', '<Right>',
+ '<S-Home>', '<C-Home>', '<Home>', '<S-End>', '<C-End>', '<End>',
+ '<C-LeftMouse>', '<C-LeftRelease>', '<2-LeftMouse>', '<2-LeftRelease>',
+ '<S-RightMouse>', '<S-RightRelease>', '<2-RightMouse>', '<2-RightRelease>',
+ '<M-MiddleMouse>', '<M-MiddleRelease>', '<2-MiddleMouse>', '<2-MiddleRelease>',
+ '<S-ScrollWheelUp>', '<S-ScrollWheelDown>', '<ScrollWheelUp>', '<ScrollWheelDown>',
+ '<S-ScrollWheelLeft>', '<S-ScrollWheelRight>', '<ScrollWheelLeft>', '<ScrollWheelRight>',
+ }) do
+ feed('<CR><C-V>' .. key)
+ retry(nil, nil, function() eq(key, meths.get_current_line()) end)
+ end
+ end)
+end)
+
+if is_os('win') then
+ describe(':terminal in Windows', function()
+ local screen
+
+ before_each(function()
+ clear()
+ feed_command('set modifiable swapfile undolevels=20')
+ poke_eventloop()
+ local cmd = '["cmd.exe","/K","PROMPT=$g$s"]'
+ screen = thelpers.screen_setup(nil, cmd)
+ end)
+
+ it('"put" operator sends data normally', function()
+ feed('<c-\\><c-n>G')
+ feed_command('let @a = ":: tty ready"')
+ feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
+ feed('"ap"ap')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ ]])
+ -- operator count is also taken into consideration
+ feed('3"ap')
+ screen:expect([[
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ ]])
+ end)
+
+ it('":put" command sends data normally', function()
+ feed('<c-\\><c-n>G')
+ feed_command('let @a = ":: tty ready"')
+ feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
+ feed_command('put a')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > {2: } |
+ |
+ ^ |
+ :put a |
+ ]])
+ -- line argument is only used to move the cursor
+ feed_command('6put a')
+ screen:expect([[
+ |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ > :: tty ready |
+ > :: appended :: tty ready |
+ ^> {2: } |
+ :6put a |
+ ]])
+ end)
+ end)
+end
+
+describe('termopen()', function()
+ before_each(clear)
+
+ it('disallowed when textlocked and in cmdwin buffer', function()
+ command("autocmd TextYankPost <buffer> ++once call termopen('foo')")
+ matches("Vim%(call%):E565: Not allowed to change text or change window$",
+ pcall_err(command, "normal! yy"))
+
+ feed("q:")
+ eq("Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits",
+ pcall_err(funcs.termopen, "bar"))
+ end)
+end)
diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua
index 2ca7cdb0a2..8510df5347 100644
--- a/test/functional/terminal/channel_spec.lua
+++ b/test/functional/terminal/channel_spec.lua
@@ -8,6 +8,10 @@ local pcall_err = helpers.pcall_err
local feed = helpers.feed
local poke_eventloop = helpers.poke_eventloop
local is_os = helpers.is_os
+local meths = helpers.meths
+local async_meths = helpers.async_meths
+local testprg = helpers.testprg
+local assert_alive = helpers.assert_alive
describe('terminal channel is closed and later released if', function()
local screen
@@ -24,6 +28,7 @@ describe('terminal channel is closed and later released if', function()
-- channel hasn't been released yet
eq("Vim(call):Can't send data to closed stream",
pcall_err(command, [[bdelete! | call chansend(id, 'test')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -40,6 +45,7 @@ describe('terminal channel is closed and later released if', function()
feed('i<CR>')
-- need to first process input
poke_eventloop()
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after another main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -55,6 +61,7 @@ describe('terminal channel is closed and later released if', function()
-- channel still hasn't been released yet
eq("Vim(call):Can't send data to closed stream",
pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -72,6 +79,7 @@ describe('terminal channel is closed and later released if', function()
feed('i<CR>')
-- need to first process input
poke_eventloop()
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after another main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -89,21 +97,105 @@ describe('terminal channel is closed and later released if', function()
-- channel still hasn't been released yet
eq("Vim(call):Can't send data to closed stream",
pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
end)
it('chansend sends lines to terminal channel in proper order', function()
- clear()
+ clear({args = {'--cmd', 'set laststatus=2'}})
local screen = Screen.new(100, 20)
screen:attach()
local shells = is_os('win') and {'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop'} or {'sh'}
for _, sh in ipairs(shells) do
- command([[bdelete! | let id = termopen(']] .. sh .. [[')]])
+ command([[let id = termopen(']] .. sh .. [[')]])
command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]])
screen:expect{
any=[[echo "hello".*echo "world"]]
}
+ command('bdelete!')
+ screen:expect{
+ any='%[No Name%]'
+ }
end
end)
+
+describe('no crash when TermOpen autocommand', function()
+ local screen
+
+ before_each(function()
+ clear()
+ meths.set_option_value('shell', testprg('shell-test'), {})
+ command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
+ screen = Screen.new(60, 4)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue};
+ })
+ screen:attach()
+ end)
+
+ it('processes job exit event when using termopen()', function()
+ command([[autocmd TermOpen * call input('')]])
+ async_meths.command('terminal foobar')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ready $ foobar |
+ |
+ [Process exited 0] |
+ |
+ ]]}
+ feed('i<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+
+ it('wipes buffer and processes events when using termopen()', function()
+ command([[autocmd TermOpen * bwipe! | call input('')]])
+ async_meths.command('terminal foobar')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+
+ it('wipes buffer and processes events when using nvim_open_term()', function()
+ command([[autocmd TermOpen * bwipe! | call input('')]])
+ async_meths.open_term(0, {})
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+end)
diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua
index 98ac03211a..8285bcc26e 100644
--- a/test/functional/terminal/cursor_spec.lua
+++ b/test/functional/terminal/cursor_spec.lua
@@ -6,7 +6,7 @@ local testprg, command = helpers.testprg, helpers.command
local nvim_prog = helpers.nvim_prog
local eq, eval = helpers.eq, helpers.eval
local matches = helpers.matches
-local feed_command = helpers.feed_command
+local poke_eventloop = helpers.poke_eventloop
local hide_cursor = thelpers.hide_cursor
local show_cursor = thelpers.show_cursor
local is_os = helpers.is_os
@@ -153,7 +153,8 @@ describe('cursor with customized highlighting', function()
})
screen:attach({rgb=false})
command('call termopen(["'..testprg('tty-test')..'"])')
- feed_command('startinsert')
+ feed('i')
+ poke_eventloop()
end)
it('overrides the default highlighting', function()
@@ -187,13 +188,16 @@ describe('buffer cursor position is correct in terminal without number column',
..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
-- <Left> and <Right> don't always work
..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
+ -- Also check for real cursor position, as it is used for stuff like input methods
+ screen._handle_busy_start = function() end
+ screen._handle_busy_stop = function() end
screen:expect([[
|
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :{1: } |
+ :{1:^ } |
{3:-- TERMINAL --} |
]])
end
@@ -213,7 +217,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :aaaaaaaa{1: } |
+ :aaaaaaaa{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 9}, eval('nvim_win_get_cursor(0)'))
@@ -238,7 +242,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :aaaaaa{1:a}a |
+ :aaaaaa{1:^a}a |
{3:-- TERMINAL --} |
]])
eq({6, 7}, eval('nvim_win_get_cursor(0)'))
@@ -263,7 +267,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :a{1:a}aaaaaa |
+ :a{1:^a}aaaaaa |
{3:-- TERMINAL --} |
]])
eq({6, 2}, eval('nvim_win_get_cursor(0)'))
@@ -294,7 +298,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µµµµµµµµ{1: } |
+ :µµµµµµµµ{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 17}, eval('nvim_win_get_cursor(0)'))
@@ -319,7 +323,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µµµµµµ{1:µ}µ |
+ :µµµµµµ{1:^µ}µ |
{3:-- TERMINAL --} |
]])
eq({6, 13}, eval('nvim_win_get_cursor(0)'))
@@ -344,7 +348,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µ{1:µ}µµµµµµ |
+ :µ{1:^µ}µµµµµµ |
{3:-- TERMINAL --} |
]])
eq({6, 3}, eval('nvim_win_get_cursor(0)'))
@@ -377,7 +381,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } |
+ :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 33}, eval('nvim_win_get_cursor(0)'))
@@ -402,7 +406,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ |
+ :µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ |
{3:-- TERMINAL --} |
]])
eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -427,7 +431,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
+ :µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
{3:-- TERMINAL --} |
]])
eq({6, 5}, eval('nvim_win_get_cursor(0)'))
@@ -446,7 +450,7 @@ describe('buffer cursor position is correct in terminal without number column',
end)
describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
- skip(is_os('win'), "Encoding problem?")
+ if skip(is_os('win'), "Encoding problem?") then return end
before_each(function()
setup_ex_register('哦哦哦哦哦哦哦哦')
@@ -460,7 +464,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :哦哦哦哦哦哦哦哦{1: } |
+ :哦哦哦哦哦哦哦哦{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -485,7 +489,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :哦哦哦哦哦哦{1:哦}哦 |
+ :哦哦哦哦哦哦{1:^哦}哦 |
{3:-- TERMINAL --} |
]])
eq({6, 19}, eval('nvim_win_get_cursor(0)'))
@@ -510,7 +514,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :哦{1:哦}哦哦哦哦哦哦 |
+ :哦{1:^哦}哦哦哦哦哦哦 |
{3:-- TERMINAL --} |
]])
eq({6, 4}, eval('nvim_win_get_cursor(0)'))
@@ -537,7 +541,7 @@ describe('buffer cursor position is correct in terminal without number column',
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
- :aaaaaaaa {1: } |
+ :aaaaaaaa {1:^ } |
{3:-- TERMINAL --} |
]])
matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))
@@ -564,13 +568,16 @@ describe('buffer cursor position is correct in terminal with number column', fun
..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
-- <Left> and <Right> don't always work
..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
+ -- Also check for real cursor position, as it is used for stuff like input methods
+ screen._handle_busy_start = function() end
+ screen._handle_busy_stop = function() end
screen:expect([[
{7: 1 } |
{7: 2 } |
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:{1: } |
+ {7: 6 }:{1:^ } |
{3:-- TERMINAL --} |
]])
end
@@ -593,7 +600,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:aaaaaaaa{1: } |
+ {7: 6 }:aaaaaaaa{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 9}, eval('nvim_win_get_cursor(0)'))
@@ -618,7 +625,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:aaaaaa{1:a}a |
+ {7: 6 }:aaaaaa{1:^a}a |
{3:-- TERMINAL --} |
]])
eq({6, 7}, eval('nvim_win_get_cursor(0)'))
@@ -643,7 +650,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:a{1:a}aaaaaa |
+ {7: 6 }:a{1:^a}aaaaaa |
{3:-- TERMINAL --} |
]])
eq({6, 2}, eval('nvim_win_get_cursor(0)'))
@@ -674,7 +681,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µµµµµµµµ{1: } |
+ {7: 6 }:µµµµµµµµ{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 17}, eval('nvim_win_get_cursor(0)'))
@@ -699,7 +706,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µµµµµµ{1:µ}µ |
+ {7: 6 }:µµµµµµ{1:^µ}µ |
{3:-- TERMINAL --} |
]])
eq({6, 13}, eval('nvim_win_get_cursor(0)'))
@@ -724,7 +731,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µ{1:µ}µµµµµµ |
+ {7: 6 }:µ{1:^µ}µµµµµµ |
{3:-- TERMINAL --} |
]])
eq({6, 3}, eval('nvim_win_get_cursor(0)'))
@@ -757,7 +764,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } |
+ {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 33}, eval('nvim_win_get_cursor(0)'))
@@ -782,7 +789,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ |
+ {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ |
{3:-- TERMINAL --} |
]])
eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -807,7 +814,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
+ {7: 6 }:µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
{3:-- TERMINAL --} |
]])
eq({6, 5}, eval('nvim_win_get_cursor(0)'))
@@ -826,7 +833,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
end)
describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
- skip(is_os('win'), "Encoding problem?")
+ if skip(is_os('win'), "Encoding problem?") then return end
before_each(function()
setup_ex_register('哦哦哦哦哦哦哦哦')
@@ -840,7 +847,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:哦哦哦哦哦哦哦哦{1: } |
+ {7: 6 }:哦哦哦哦哦哦哦哦{1:^ } |
{3:-- TERMINAL --} |
]])
eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -865,7 +872,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:哦哦哦哦哦哦{1:哦}哦 |
+ {7: 6 }:哦哦哦哦哦哦{1:^哦}哦 |
{3:-- TERMINAL --} |
]])
eq({6, 19}, eval('nvim_win_get_cursor(0)'))
@@ -890,7 +897,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:哦{1:哦}哦哦哦哦哦哦 |
+ {7: 6 }:哦{1:^哦}哦哦哦哦哦哦 |
{3:-- TERMINAL --} |
]])
eq({6, 4}, eval('nvim_win_get_cursor(0)'))
@@ -917,7 +924,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } |
{7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
- {7: 6 }:aaaaaaaa {1: } |
+ {7: 6 }:aaaaaaaa {1:^ } |
{3:-- TERMINAL --} |
]])
matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index 80287bb3d0..29361bc0fa 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -21,8 +21,8 @@ describe(':edit term://*', function()
before_each(function()
clear()
- meths.set_option('shell', testprg('shell-test'))
- meths.set_option('shellcmdflag', 'EXE')
+ meths.set_option_value('shell', testprg('shell-test'), {})
+ meths.set_option_value('shellcmdflag', 'EXE', {})
end)
it('runs TermOpen event', function()
@@ -36,11 +36,10 @@ describe(':edit term://*', function()
end)
it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
- if helpers.skip(helpers.is_os('win')) then return end
local columns, lines = 20, 4
local scr = get_screen(columns, lines)
local rep = 97
- meths.set_option('shellcmdflag', 'REP ' .. rep)
+ meths.set_option_value('shellcmdflag', 'REP ' .. rep, {})
command('set shellxquote=') -- win: avoid extra quotes
local sb = 10
command('autocmd TermOpen * :setlocal scrollback='..tostring(sb)
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 6b7e93a864..f628e261a2 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -99,7 +99,7 @@ describe(':terminal', function()
end)
it('nvim_get_mode() in :terminal', function()
- command(':terminal')
+ command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('i')
eq({ blocking=false, mode='t' }, nvim('get_mode'))
@@ -108,21 +108,37 @@ describe(':terminal', function()
end)
it(':stopinsert RPC request exits terminal-mode #7807', function()
- command(':terminal')
+ command('terminal')
feed('i[tui] insert-mode')
eq({ blocking=false, mode='t' }, nvim('get_mode'))
command('stopinsert')
+ feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
end)
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
- command(':terminal')
+ command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
- command(':stopinsert')
+ command('stopinsert')
+ feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('a')
eq({ blocking=false, mode='t' }, nvim('get_mode'))
end)
+
+ it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function()
+ command('terminal')
+ command('vnew')
+ feed('i')
+ command('let g:events = []')
+ command('autocmd InsertLeave * let g:events += ["InsertLeave"]')
+ command('autocmd TermEnter * let g:events += ["TermEnter"]')
+ command('inoremap <F2> <Cmd>wincmd p<CR>')
+ eq({ blocking=false, mode='i' }, nvim('get_mode'))
+ feed('<F2>')
+ eq({ blocking=false, mode='t' }, nvim('get_mode'))
+ eq({'InsertLeave', 'TermEnter'}, eval('g:events'))
+ end)
end)
describe(':terminal (with fake shell)', function()
@@ -133,31 +149,37 @@ describe(':terminal (with fake shell)', function()
screen = Screen.new(50, 4)
screen:attach({rgb=false})
-- shell-test.c is a fake shell that prints its arguments and exits.
- nvim('set_option', 'shell', testprg('shell-test'))
- nvim('set_option', 'shellcmdflag', 'EXE')
+ nvim('set_option_value', 'shell', testprg('shell-test'), {})
+ nvim('set_option_value', 'shellcmdflag', 'EXE', {})
+ nvim('set_option_value', 'shellxquote', '', {})
end)
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
- -- the {cmd} and exits immediately .
+ -- the {cmd} and exits immediately.
+ -- When no argument is given and the exit code is zero, the terminal buffer
+ -- closes automatically.
local function terminal_with_fake_shell(cmd)
feed_command("terminal "..(cmd and cmd or ""))
end
it('with no argument, acts like termopen()', function()
skip(is_os('win'))
- terminal_with_fake_shell()
+ -- Use the EXIT subcommand to end the process with a non-zero exit code to
+ -- prevent the buffer from closing automatically
+ nvim('set_option_value', 'shellcmdflag', 'EXIT', {})
+ terminal_with_fake_shell(1)
retry(nil, 4 * screen.timeout, function()
screen:expect([[
- ^ready $ |
- [Process exited 0] |
+ ^ |
+ [Process exited 1] |
|
- :terminal |
+ :terminal 1 |
]])
end)
end)
it("with no argument, and 'shell' is set to empty string", function()
- nvim('set_option', 'shell', '')
+ nvim('set_option_value', 'shell', '', {})
terminal_with_fake_shell()
screen:expect([[
^ |
@@ -169,7 +191,7 @@ describe(':terminal (with fake shell)', function()
it("with no argument, but 'shell' has arguments, acts like termopen()", function()
skip(is_os('win'))
- nvim('set_option', 'shell', testprg('shell-test')..' -t jeff')
+ nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {})
terminal_with_fake_shell()
screen:expect([[
^jeff $ |
@@ -193,7 +215,7 @@ describe(':terminal (with fake shell)', function()
it("executes a given command through the shell, when 'shell' has arguments", function()
skip(is_os('win'))
- nvim('set_option', 'shell', testprg('shell-test')..' -t jeff')
+ nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {})
command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi')
screen:expect([[
@@ -243,12 +265,13 @@ describe(':terminal (with fake shell)', function()
it('works with :find', function()
skip(is_os('win'))
- terminal_with_fake_shell()
+ nvim('set_option_value', 'shellcmdflag', 'EXIT', {})
+ terminal_with_fake_shell(1)
screen:expect([[
- ^ready $ |
- [Process exited 0] |
+ ^ |
+ [Process exited 1] |
|
- :terminal |
+ :terminal 1 |
]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
feed([[<C-\><C-N>]])
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index 7247361649..62d3dd67a3 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen')
local testprg = helpers.testprg
local exec_lua = helpers.exec_lua
-local feed_command, nvim = helpers.feed_command, helpers.nvim
+local nvim = helpers.nvim
local function feed_data(data)
if type(data) == 'table' then
@@ -82,15 +82,16 @@ local function screen_setup(extra_rows, command, cols, opts)
screen:attach(opts or {rgb=false})
- feed_command('enew | call termopen('..command..')')
+ nvim('command', 'enew | call termopen('..command..')')
nvim('input', '<CR>')
local vim_errmsg = nvim('eval', 'v:errmsg')
if vim_errmsg and "" ~= vim_errmsg then
error(vim_errmsg)
end
- feed_command('setlocal scrollback=10')
- feed_command('startinsert')
+ nvim('command', 'setlocal scrollback=10')
+ nvim('command', 'startinsert')
+ nvim('input', '<Ignore>') -- Add input to separate two RPC requests
-- tty-test puts the terminal into raw mode and echoes input. Tests work by
-- feeding termcodes to control the display and asserting by screen:expect.
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 50c8f5e7df..3291a38e03 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -11,7 +11,7 @@ describe(':terminal mouse', function()
before_each(function()
clear()
- nvim('set_option', 'statusline', '==========')
+ nvim('set_option_value', 'statusline', '==========', {})
command('highlight StatusLine cterm=NONE')
command('highlight StatusLineNC cterm=NONE')
command('highlight VertSplit cterm=NONE')
@@ -67,9 +67,23 @@ describe(':terminal mouse', function()
eq('nt', eval('mode(1)'))
end)
- it('does not leave terminal mode on left-release', function()
- skip(is_os('win'))
- feed('<LeftRelease>')
+ it('will not exit focus on left-release', function()
+ eq('t', eval('mode(1)'))
+ feed('<LeftRelease><0,0>')
+ eq('t', eval('mode(1)'))
+ command('setlocal number')
+ eq('t', eval('mode(1)'))
+ feed('<LeftRelease><0,0>')
+ eq('t', eval('mode(1)'))
+ end)
+
+ it('will not exit focus on mouse movement', function()
+ eq('t', eval('mode(1)'))
+ feed('<MouseMove><0,0>')
+ eq('t', eval('mode(1)'))
+ command('setlocal number')
+ eq('t', eval('mode(1)'))
+ feed('<MouseMove><0,0>')
eq('t', eval('mode(1)'))
end)
@@ -232,7 +246,6 @@ describe(':terminal mouse', function()
end)
describe('with a split window and other buffer', function()
- skip(is_os('win'))
before_each(function()
feed('<c-\\><c-n>:vsp<cr>')
screen:expect([[
@@ -289,7 +302,7 @@ describe(':terminal mouse', function()
]])
end)
- it("won't lose focus if another window is scrolled", function()
+ it("scrolling another window keeps focus and respects 'mousescroll'", function()
feed('<ScrollWheelUp><4,0><ScrollWheelUp><4,0>')
screen:expect([[
{7: 21 }line │line30 |
@@ -310,22 +323,8 @@ describe(':terminal mouse', function()
========== ========== |
{3:-- TERMINAL --} |
]])
- end)
-
- it("scrolling another window respects 'mousescroll'", function()
- command('set mousescroll=ver:1')
- feed('<ScrollWheelUp><4,0>')
- screen:expect([[
- {7: 26 }line │line30 |
- {7: 27 }line │rows: 5, cols: 25 |
- {7: 28 }line │rows: 5, cols: 24 |
- {7: 29 }line │mouse enabled |
- {7: 30 }line │{1: } |
- ========== ========== |
- {3:-- TERMINAL --} |
- ]])
command('set mousescroll=ver:10')
- feed('<ScrollWheelUp><4,0>')
+ feed('<ScrollWheelUp><0,0>')
screen:expect([[
{7: 16 }line │line30 |
{7: 17 }line │rows: 5, cols: 25 |
@@ -336,8 +335,41 @@ describe(':terminal mouse', function()
{3:-- TERMINAL --} |
]])
command('set mousescroll=ver:0')
- feed('<ScrollWheelUp><4,0>')
+ feed('<ScrollWheelUp><0,0>')
screen:expect_unchanged()
+ feed([[<C-\><C-N><C-W>w]])
+ command('setlocal nowrap')
+ feed('0<C-V>gg3ly$4p<C-W>wi')
+ screen:expect([[
+ {7: 1 }linelinelinelineline │line30 |
+ {7: 2 }linelinelinelineline │rows: 5, cols: 25 |
+ {7: 3 }linelinelinelineline │rows: 5, cols: 24 |
+ {7: 4 }linelinelinelineline │mouse enabled |
+ {7: 5 }linelinelinelineline │{1: } |
+ ========== ========== |
+ {3:-- TERMINAL --} |
+ ]])
+ feed('<ScrollWheelRight><4,0>')
+ screen:expect([[
+ {7: 1 }nelinelineline │line30 |
+ {7: 2 }nelinelineline │rows: 5, cols: 25 |
+ {7: 3 }nelinelineline │rows: 5, cols: 24 |
+ {7: 4 }nelinelineline │mouse enabled |
+ {7: 5 }nelinelineline │{1: } |
+ ========== ========== |
+ {3:-- TERMINAL --} |
+ ]])
+ command('set mousescroll=hor:4')
+ feed('<ScrollWheelLeft><4,0>')
+ screen:expect([[
+ {7: 1 }nelinelinelineline │line30 |
+ {7: 2 }nelinelinelineline │rows: 5, cols: 25 |
+ {7: 3 }nelinelinelineline │rows: 5, cols: 24 |
+ {7: 4 }nelinelinelineline │mouse enabled |
+ {7: 5 }nelinelinelineline │{1: } |
+ ========== ========== |
+ {3:-- TERMINAL --} |
+ ]])
end)
it('will lose focus if another window is clicked', function()
@@ -354,7 +386,7 @@ describe(':terminal mouse', function()
end)
it('handles terminal size when switching buffers', function()
- nvim('set_option', 'hidden', true)
+ nvim('set_option_value', 'hidden', true, {})
feed('<c-\\><c-n><c-w><c-w>')
screen:expect([[
{7: 27 }line │line30 |
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index a4899c8219..1e278e4cff 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -2,13 +2,12 @@ local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
-local feed, testprg, feed_command = helpers.feed, helpers.testprg, helpers.feed_command
+local feed, testprg = helpers.feed, helpers.testprg
local eval = helpers.eval
local command = helpers.command
-local matches = helpers.matches
local poke_eventloop = helpers.poke_eventloop
local retry = helpers.retry
-local curbufmeths = helpers.curbufmeths
+local meths = helpers.meths
local nvim = helpers.nvim
local feed_data = thelpers.feed_data
local pcall_err = helpers.pcall_err
@@ -140,7 +139,6 @@ describe(':terminal scrollback', function()
describe('and height decreased by 1', function()
- if skip(is_os('win')) then return end
local function will_hide_top_line()
feed([[<C-\><C-N>]])
screen:try_resize(screen._width - 2, screen._height - 1)
@@ -347,12 +345,10 @@ end)
describe(':terminal prints more lines than the screen height and exits', function()
it('will push extra lines to scrollback', function()
- skip(is_os('win'))
clear()
local screen = Screen.new(30, 7)
screen:attach({rgb=false})
- feed_command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
- poke_eventloop()
+ command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
screen:expect([[
line6 |
line7 |
@@ -382,9 +378,7 @@ describe("'scrollback' option", function()
end)
local function set_fake_shell()
- -- shell-test.c is a fake shell that prints its arguments and exits.
- nvim('set_option', 'shell', testprg('shell-test'))
- nvim('set_option', 'shellcmdflag', 'EXE')
+ nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
end
local function expect_lines(expected, epsilon)
@@ -403,7 +397,7 @@ describe("'scrollback' option", function()
screen = thelpers.screen_setup(nil, "['sh']", 30)
end
- curbufmeths.set_option('scrollback', 0)
+ meths.set_option_value('scrollback', 0, {})
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
screen:expect{any='30: line '}
retry(nil, nil, function() expect_lines(7) end)
@@ -419,7 +413,7 @@ describe("'scrollback' option", function()
screen = thelpers.screen_setup(nil, "['sh']", 30)
end
- curbufmeths.set_option('scrollback', 200)
+ meths.set_option_value('scrollback', 200, {})
-- Wait for prompt.
screen:expect{any='%$'}
@@ -428,10 +422,10 @@ describe("'scrollback' option", function()
screen:expect{any='30: line '}
retry(nil, nil, function() expect_lines(33, 2) end)
- curbufmeths.set_option('scrollback', 10)
+ meths.set_option_value('scrollback', 10, {})
poke_eventloop()
retry(nil, nil, function() expect_lines(16) end)
- curbufmeths.set_option('scrollback', 10000)
+ meths.set_option_value('scrollback', 10000, {})
retry(nil, nil, function() expect_lines(16) end)
-- Terminal job data is received asynchronously, may happen before the
-- 'scrollback' option is synchronized with the internal sb_buffer.
@@ -462,8 +456,8 @@ describe("'scrollback' option", function()
expect_lines(58)
-- Verify off-screen state
- matches((is_os('win') and '^36: line[ ]*$' or '^35: line[ ]*$'), eval("getline(line('w0') - 1)"))
- matches((is_os('win') and '^27: line[ ]*$' or '^26: line[ ]*$'), eval("getline(line('w0') - 10)"))
+ eq((is_os('win') and '36: line' or '35: line'), eval("getline(line('w0') - 1)->trim(' ', 2)"))
+ eq((is_os('win') and '27: line' or '26: line'), eval("getline(line('w0') - 10)->trim(' ', 2)"))
end)
it('deletes extra lines immediately', function()
@@ -486,18 +480,18 @@ describe("'scrollback' option", function()
]])
local term_height = 6 -- Actual terminal screen height, not the scrollback
-- Initial
- local scrollback = curbufmeths.get_option('scrollback')
+ local scrollback = meths.get_option_value('scrollback', {})
eq(scrollback + term_height, eval('line("$")'))
-- Reduction
scrollback = scrollback - 2
- curbufmeths.set_option('scrollback', scrollback)
+ meths.set_option_value('scrollback', scrollback, {})
eq(scrollback + term_height, eval('line("$")'))
end)
it('defaults to 10000 in :terminal buffers', function()
set_fake_shell()
command('terminal')
- eq(10000, curbufmeths.get_option('scrollback'))
+ eq(10000, meths.get_option_value('scrollback', {}))
end)
it('error if set to invalid value', function()
@@ -509,7 +503,7 @@ describe("'scrollback' option", function()
it('defaults to -1 on normal buffers', function()
command('new')
- eq(-1, curbufmeths.get_option('scrollback'))
+ eq(-1, meths.get_option_value('scrollback', {}))
end)
it(':setlocal in a :terminal buffer', function()
@@ -518,45 +512,45 @@ describe("'scrollback' option", function()
-- _Global_ scrollback=-1 defaults :terminal to 10_000.
command('setglobal scrollback=-1')
command('terminal')
- eq(10000, curbufmeths.get_option('scrollback'))
+ eq(10000, meths.get_option_value('scrollback', {}))
-- _Local_ scrollback=-1 in :terminal forces the _maximum_.
command('setlocal scrollback=-1')
retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
- eq(100000, curbufmeths.get_option('scrollback'))
+ eq(100000, meths.get_option_value('scrollback', {}))
end)
-- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605
command('setglobal scrollback=-1')
command('autocmd TermOpen * setlocal scrollback=-1')
command('terminal')
- eq(100000, curbufmeths.get_option('scrollback'))
+ eq(100000, meths.get_option_value('scrollback', {}))
end)
it(':setlocal in a normal buffer', function()
command('new')
-- :setlocal to -1.
command('setlocal scrollback=-1')
- eq(-1, curbufmeths.get_option('scrollback'))
+ eq(-1, meths.get_option_value('scrollback', {}))
-- :setlocal to anything except -1. Currently, this just has no effect.
command('setlocal scrollback=42')
- eq(42, curbufmeths.get_option('scrollback'))
+ eq(42, meths.get_option_value('scrollback', {}))
end)
it(':set updates local value and global default', function()
set_fake_shell()
command('set scrollback=42') -- set global value
- eq(42, curbufmeths.get_option('scrollback'))
+ eq(42, meths.get_option_value('scrollback', {}))
command('terminal')
- eq(42, curbufmeths.get_option('scrollback')) -- inherits global default
+ eq(42, meths.get_option_value('scrollback', {})) -- inherits global default
command('setlocal scrollback=99')
- eq(99, curbufmeths.get_option('scrollback'))
+ eq(99, meths.get_option_value('scrollback', {}))
command('set scrollback<') -- reset to global default
- eq(42, curbufmeths.get_option('scrollback'))
+ eq(42, meths.get_option_value('scrollback', {}))
command('setglobal scrollback=734') -- new global default
- eq(42, curbufmeths.get_option('scrollback')) -- local value did not change
+ eq(42, meths.get_option_value('scrollback', {})) -- local value did not change
command('terminal')
- eq(734, curbufmeths.get_option('scrollback'))
+ eq(734, meths.get_option_value('scrollback', {}))
end)
end)
@@ -577,12 +571,12 @@ describe("pending scrollback line handling", function()
it("does not crash after setting 'number' #14891", function()
exec_lua [[
- local a = vim.api
- local buf = a.nvim_create_buf(true, true)
- local chan = a.nvim_open_term(buf, {})
- a.nvim_win_set_option(0, "number", true)
- a.nvim_chan_send(chan, ("a\n"):rep(11) .. "a")
- a.nvim_win_set_buf(0, buf)
+ local api = vim.api
+ local buf = api.nvim_create_buf(true, true)
+ local chan = api.nvim_open_term(buf, {})
+ vim.wo.number = true
+ api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a")
+ api.nvim_win_set_buf(0, buf)
]]
screen:expect [[
{1: 1 }^a |
@@ -609,12 +603,11 @@ describe("pending scrollback line handling", function()
it("does not crash after nvim_buf_call #14891", function()
skip(is_os('win'))
exec_lua [[
- local a = vim.api
- local bufnr = a.nvim_create_buf(false, true)
- a.nvim_buf_call(bufnr, function()
+ local bufnr = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_call(bufnr, function()
vim.fn.termopen({"echo", ("hi\n"):rep(11)})
end)
- a.nvim_win_set_buf(0, bufnr)
+ vim.api.nvim_win_set_buf(0, bufnr)
vim.cmd("startinsert")
]]
screen:expect [[
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index b28728057f..b17eed00f9 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -8,12 +8,12 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local Screen = require('test.functional.ui.screen')
local eq = helpers.eq
-local feed_command = helpers.feed_command
local feed_data = thelpers.feed_data
local clear = helpers.clear
local command = helpers.command
local dedent = helpers.dedent
local exec = helpers.exec
+local exec_lua = helpers.exec_lua
local testprg = helpers.testprg
local retry = helpers.retry
local nvim_prog = helpers.nvim_prog
@@ -27,10 +27,9 @@ local is_os = helpers.is_os
local new_pipename = helpers.new_pipename
local spawn_argv = helpers.spawn_argv
local set_session = helpers.set_session
-local feed = helpers.feed
-local eval = helpers.eval
+local write_file = helpers.write_file
-if helpers.skip(helpers.is_os('win')) then return end
+if helpers.skip(is_os('win')) then return end
describe('TUI', function()
local screen
@@ -68,13 +67,13 @@ describe('TUI', function()
local function expect_child_buf_lines(expected)
assert(type({}) == type(expected))
retry(nil, nil, function()
- local _, buflines = child_session:request(
- 'nvim_buf_get_lines', 0, 0, -1, false)
+ local _, buflines = child_session:request('nvim_buf_get_lines', 0, 0, -1, false)
eq(expected, buflines)
end)
end
it('rapid resize #7572 #7628', function()
+ helpers.skip(helpers.is_asan(), 'Test extra unstable with ASAN. See #23762')
-- Need buffer rows to provoke the behavior.
feed_data(":edit test/functional/fixtures/bigfile.txt\n")
screen:expect([[
@@ -108,14 +107,14 @@ describe('TUI', function()
end)
it('accepts resize while pager is active', function()
- child_session:request("nvim_command", [[
- set more
- func! ManyErr()
- for i in range(10)
- echoerr "FAIL ".i
- endfor
- endfunc
- ]])
+ child_session:request('nvim_exec2', [[
+ set more
+ func! ManyErr()
+ for i in range(20)
+ echoerr "FAIL ".i
+ endfor
+ endfunc
+ ]], {})
feed_data(':call ManyErr()\r')
screen:expect{grid=[[
{8:Error detected while processing function ManyErr:} |
@@ -127,7 +126,35 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]]}
- feed_data('d')
+ screen:try_resize(50,10)
+ screen:expect{grid=[[
+ :call ManyErr() |
+ {8:Error detected while processing function ManyErr:} |
+ {11:line 2:} |
+ {8:FAIL 0} |
+ {8:FAIL 1} |
+ {8:FAIL 2} |
+ |
+ |
+ {10:-- More --}{1: } |
+ {3:-- TERMINAL --} |
+ ]]}
+
+ feed_data('j')
+ screen:expect{grid=[[
+ {8:Error detected while processing function ManyErr:} |
+ {11:line 2:} |
+ {8:FAIL 0} |
+ {8:FAIL 1} |
+ {8:FAIL 2} |
+ {8:FAIL 3} |
+ {8:FAIL 4} |
+ {8:FAIL 5} |
+ {10:-- More --}{1: } |
+ {3:-- TERMINAL --} |
+ ]]}
+
+ screen:try_resize(50,7)
screen:expect{grid=[[
{8:FAIL 1} |
{8:FAIL 2} |
@@ -211,7 +238,7 @@ describe('TUI', function()
it('interprets leading <Esc> byte as ALT modifier in normal-mode', function()
local keys = 'dfghjkl'
for c in keys:gmatch('.') do
- feed_command('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>')
+ feed_data(':nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>\r')
feed_data('\027'..c)
end
screen:expect([[
@@ -251,9 +278,11 @@ describe('TUI', function()
end)
it('interprets <Esc>[27u as <Esc>', function()
- feed_command('nnoremap <M-;> <Nop>')
- feed_command('nnoremap <Esc> AESC<Esc>')
- feed_command('nnoremap ; Asemicolon<Esc>')
+ child_session:request('nvim_exec2', [[
+ nnoremap <M-;> <Nop>
+ nnoremap <Esc> AESC<Esc>
+ nnoremap ; Asemicolon<Esc>
+ ]], {})
feed_data('\027[27u;')
screen:expect([[
ESCsemicolo{1:n} |
@@ -290,22 +319,22 @@ describe('TUI', function()
local attrs = screen:get_default_attr_ids()
attrs[11] = {foreground = 81}
screen:expect([[
- {11:^G^V^M}{1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] [+] }|
- {3:-- INSERT --} |
- {3:-- TERMINAL --} |
+ {11:^G^V^M}{1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
]], attrs)
end)
- it('accepts mouse wheel events #19992', function()
- child_session:request('nvim_command', [[
+ local function test_mouse_wheel(esc)
+ child_session:request('nvim_exec2', [[
set number nostartofline nowrap mousescroll=hor:1,ver:1
call setline(1, repeat([join(range(10), '----')], 10))
vsplit
- ]])
+ ]], {})
screen:expect([[
{11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----|
{11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
@@ -316,7 +345,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelDown> in active window
- feed_data('\027[<65;8;1M')
+ if esc then
+ feed_data('\027[<65;8;1M')
+ else
+ meths.input_mouse('wheel', 'down', '', 0, 0, 7)
+ end
screen:expect([[
{11: 2 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----|
{11: 3 }0----1----2----3----4│{11: 2 }0----1----2----3----|
@@ -327,7 +360,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelDown> in inactive window
- feed_data('\027[<65;48;1M')
+ if esc then
+ feed_data('\027[<65;48;1M')
+ else
+ meths.input_mouse('wheel', 'down', '', 0, 0, 47)
+ end
screen:expect([[
{11: 2 }{1:0}----1----2----3----4│{11: 2 }0----1----2----3----|
{11: 3 }0----1----2----3----4│{11: 3 }0----1----2----3----|
@@ -338,7 +375,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelRight> in active window
- feed_data('\027[<67;8;1M')
+ if esc then
+ feed_data('\027[<67;8;1M')
+ else
+ meths.input_mouse('wheel', 'right', '', 0, 0, 7)
+ end
screen:expect([[
{11: 2 }{1:-}---1----2----3----4-│{11: 2 }0----1----2----3----|
{11: 3 }----1----2----3----4-│{11: 3 }0----1----2----3----|
@@ -349,7 +390,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelRight> in inactive window
- feed_data('\027[<67;48;1M')
+ if esc then
+ feed_data('\027[<67;48;1M')
+ else
+ meths.input_mouse('wheel', 'right', '', 0, 0, 47)
+ end
screen:expect([[
{11: 2 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4|
{11: 3 }----1----2----3----4-│{11: 3 }----1----2----3----4|
@@ -360,7 +405,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelDown> in active window
- feed_data('\027[<69;8;1M')
+ if esc then
+ feed_data('\027[<69;8;1M')
+ else
+ meths.input_mouse('wheel', 'down', 'S', 0, 0, 7)
+ end
screen:expect([[
{11: 5 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4|
{11: 6 }----1----2----3----4-│{11: 3 }----1----2----3----4|
@@ -371,7 +420,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelDown> in inactive window
- feed_data('\027[<69;48;1M')
+ if esc then
+ feed_data('\027[<69;48;1M')
+ else
+ meths.input_mouse('wheel', 'down', 'S', 0, 0, 47)
+ end
screen:expect([[
{11: 5 }{1:-}---1----2----3----4-│{11: 5 }----1----2----3----4|
{11: 6 }----1----2----3----4-│{11: 6 }----1----2----3----4|
@@ -382,7 +435,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelRight> in active window
- feed_data('\027[<71;8;1M')
+ if esc then
+ feed_data('\027[<71;8;1M')
+ else
+ meths.input_mouse('wheel', 'right', 'S', 0, 0, 7)
+ end
screen:expect([[
{11: 5 }{1:-}---6----7----8----9 │{11: 5 }----1----2----3----4|
{11: 6 }----6----7----8----9 │{11: 6 }----1----2----3----4|
@@ -393,7 +450,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelRight> in inactive window
- feed_data('\027[<71;48;1M')
+ if esc then
+ feed_data('\027[<71;48;1M')
+ else
+ meths.input_mouse('wheel', 'right', 'S', 0, 0, 47)
+ end
screen:expect([[
{11: 5 }{1:-}---6----7----8----9 │{11: 5 }5----6----7----8----|
{11: 6 }----6----7----8----9 │{11: 6 }5----6----7----8----|
@@ -404,7 +465,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelUp> in active window
- feed_data('\027[<64;8;1M')
+ if esc then
+ feed_data('\027[<64;8;1M')
+ else
+ meths.input_mouse('wheel', 'up', '', 0, 0, 7)
+ end
screen:expect([[
{11: 4 }----6----7----8----9 │{11: 5 }5----6----7----8----|
{11: 5 }{1:-}---6----7----8----9 │{11: 6 }5----6----7----8----|
@@ -415,7 +480,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelUp> in inactive window
- feed_data('\027[<64;48;1M')
+ if esc then
+ feed_data('\027[<64;48;1M')
+ else
+ meths.input_mouse('wheel', 'up', '', 0, 0, 47)
+ end
screen:expect([[
{11: 4 }----6----7----8----9 │{11: 4 }5----6----7----8----|
{11: 5 }{1:-}---6----7----8----9 │{11: 5 }5----6----7----8----|
@@ -426,7 +495,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelLeft> in active window
- feed_data('\027[<66;8;1M')
+ if esc then
+ feed_data('\027[<66;8;1M')
+ else
+ meths.input_mouse('wheel', 'left', '', 0, 0, 7)
+ end
screen:expect([[
{11: 4 }5----6----7----8----9│{11: 4 }5----6----7----8----|
{11: 5 }5{1:-}---6----7----8----9│{11: 5 }5----6----7----8----|
@@ -437,7 +510,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <ScrollWheelLeft> in inactive window
- feed_data('\027[<66;48;1M')
+ if esc then
+ feed_data('\027[<66;48;1M')
+ else
+ meths.input_mouse('wheel', 'left', '', 0, 0, 47)
+ end
screen:expect([[
{11: 4 }5----6----7----8----9│{11: 4 }-5----6----7----8---|
{11: 5 }5{1:-}---6----7----8----9│{11: 5 }-5----6----7----8---|
@@ -448,7 +525,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelUp> in active window
- feed_data('\027[<68;8;1M')
+ if esc then
+ feed_data('\027[<68;8;1M')
+ else
+ meths.input_mouse('wheel', 'up', 'S', 0, 0, 7)
+ end
screen:expect([[
{11: 1 }5----6----7----8----9│{11: 4 }-5----6----7----8---|
{11: 2 }5----6----7----8----9│{11: 5 }-5----6----7----8---|
@@ -459,7 +540,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelUp> in inactive window
- feed_data('\027[<68;48;1M')
+ if esc then
+ feed_data('\027[<68;48;1M')
+ else
+ meths.input_mouse('wheel', 'up', 'S', 0, 0, 47)
+ end
screen:expect([[
{11: 1 }5----6----7----8----9│{11: 1 }-5----6----7----8---|
{11: 2 }5----6----7----8----9│{11: 2 }-5----6----7----8---|
@@ -470,7 +555,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelLeft> in active window
- feed_data('\027[<70;8;1M')
+ if esc then
+ feed_data('\027[<70;8;1M')
+ else
+ meths.input_mouse('wheel', 'left', 'S', 0, 0, 7)
+ end
screen:expect([[
{11: 1 }0----1----2----3----4│{11: 1 }-5----6----7----8---|
{11: 2 }0----1----2----3----4│{11: 2 }-5----6----7----8---|
@@ -481,7 +570,11 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
-- <S-ScrollWheelLeft> in inactive window
- feed_data('\027[<70;48;1M')
+ if esc then
+ feed_data('\027[<70;48;1M')
+ else
+ meths.input_mouse('wheel', 'left', 'S', 0, 0, 47)
+ end
screen:expect([[
{11: 1 }0----1----2----3----4│{11: 1 }0----1----2----3----|
{11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
@@ -491,6 +584,136 @@ describe('TUI', function()
|
{3:-- TERMINAL --} |
]])
+ end
+
+ describe('accepts mouse wheel events', function()
+ it('(mouse events sent to host)', function()
+ test_mouse_wheel(false)
+ end)
+
+ it('(escape sequences sent to child)', function()
+ test_mouse_wheel(true)
+ end)
+ end)
+
+ local function test_mouse_popup(esc)
+ child_session:request('nvim_exec2', [[
+ call setline(1, 'popup menu test')
+ set mouse=a mousemodel=popup
+
+ aunmenu PopUp
+ menu PopUp.foo :let g:menustr = 'foo'<CR>
+ menu PopUp.bar :let g:menustr = 'bar'<CR>
+ menu PopUp.baz :let g:menustr = 'baz'<CR>
+ highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
+ highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
+ ]], {})
+ if esc then
+ feed_data('\027[<2;5;1M')
+ else
+ meths.input_mouse('right', 'press', '', 0, 0, 4)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }{13: foo }{4: }|
+ {4:~ }{13: bar }{4: }|
+ {4:~ }{13: baz }{4: }|
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]])
+ if esc then
+ feed_data('\027[<2;5;1m')
+ else
+ meths.input_mouse('right', 'release', '', 0, 0, 4)
+ end
+ screen:expect_unchanged()
+ if esc then
+ feed_data('\027[<35;7;4M')
+ else
+ meths.input_mouse('move', '', '', 0, 3, 6)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }{13: foo }{4: }|
+ {4:~ }{13: bar }{4: }|
+ {4:~ }{14: baz }{4: }|
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]])
+ if esc then
+ feed_data('\027[<0;7;3M')
+ else
+ meths.input_mouse('left', 'press', '', 0, 2, 6)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ :let g:menustr = 'bar' |
+ {3:-- TERMINAL --} |
+ ]])
+ if esc then
+ feed_data('\027[<0;7;3m')
+ else
+ meths.input_mouse('left', 'release', '', 0, 2, 6)
+ end
+ screen:expect_unchanged()
+ if esc then
+ feed_data('\027[<2;45;3M')
+ else
+ meths.input_mouse('right', 'press', '', 0, 2, 44)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }{13: foo }{4: }|
+ {5:[No Name] [+] }{13: bar }{5: }|
+ :let g:menustr = 'bar' {13: baz } |
+ {3:-- TERMINAL --} |
+ ]])
+ if esc then
+ feed_data('\027[<34;48;6M')
+ else
+ meths.input_mouse('right', 'drag', '', 0, 5, 47)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }{13: foo }{4: }|
+ {5:[No Name] [+] }{13: bar }{5: }|
+ :let g:menustr = 'bar' {14: baz } |
+ {3:-- TERMINAL --} |
+ ]])
+ if esc then
+ feed_data('\027[<2;48;6m')
+ else
+ meths.input_mouse('right', 'release', '', 0, 5, 47)
+ end
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ :let g:menustr = 'baz' |
+ {3:-- TERMINAL --} |
+ ]])
+ end
+
+ describe('mouse events work with right-click menu', function()
+ it('(mouse events sent to host)', function()
+ test_mouse_popup(false)
+ end)
+
+ it('(escape sequences sent to child)', function()
+ test_mouse_popup(true)
+ end)
end)
it('accepts keypad keys from kitty keyboard protocol #19180', function()
@@ -631,11 +854,11 @@ describe('TUI', function()
|
{3:-- TERMINAL --} |
]])
- child_session:request('nvim_command', [[
+ child_session:request('nvim_exec2', [[
tab split
tabnew
highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline
- ]])
+ ]], {})
screen:expect([[
{12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}|
{1: } |
@@ -667,52 +890,26 @@ describe('TUI', function()
]])
end)
- it('mouse events work with right-click menu', function()
- child_session:request('nvim_command', [[
- call setline(1, 'popup menu test')
- set mouse=a mousemodel=popup
-
- aunmenu PopUp
- menu PopUp.foo :let g:menustr = 'foo'<CR>
- menu PopUp.bar :let g:menustr = 'bar'<CR>
- menu PopUp.baz :let g:menustr = 'baz'<CR>
- highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
- highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
- ]])
- meths.input_mouse('right', 'press', '', 0, 0, 4)
- screen:expect([[
- {1:p}opup menu test |
- {4:~ }{13: foo }{4: }|
- {4:~ }{13: bar }{4: }|
- {4:~ }{13: baz }{4: }|
- {5:[No Name] [+] }|
- |
- {3:-- TERMINAL --} |
- ]])
- meths.input_mouse('right', 'release', '', 0, 0, 4)
- screen:expect_unchanged()
- meths.input_mouse('move', '', '', 0, 3, 6)
- screen:expect([[
- {1:p}opup menu test |
- {4:~ }{13: foo }{4: }|
- {4:~ }{13: bar }{4: }|
- {4:~ }{14: baz }{4: }|
- {5:[No Name] [+] }|
- |
- {3:-- TERMINAL --} |
- ]])
- meths.input_mouse('left', 'press', '', 0, 2, 6)
+ it('supports Super and Meta modifiers', function()
+ feed_data('i')
+ feed_data('\022\027[106;9u') -- Super + j
+ feed_data('\022\027[107;33u') -- Meta + k
+ feed_data('\022\027[13;41u') -- Super + Meta + Enter
+ feed_data('\022\027[127;48u') -- Shift + Alt + Ctrl + Super + Meta + Backspace
+ feed_data('\n')
+ feed_data('\022\027[57376;9u') -- Super + F13
+ feed_data('\022\027[57377;33u') -- Meta + F14
+ feed_data('\022\027[57378;41u') -- Super + Meta + F15
+ feed_data('\022\027[57379;48u') -- Shift + Alt + Ctrl + Super + Meta + F16
screen:expect([[
- {1:p}opup menu test |
- {4:~ }|
+ <D-j><T-k><T-D-CR><M-T-C-S-D-BS> |
+ <D-F13><T-F14><T-D-F15><M-T-C-S-D-F16>{1: } |
{4:~ }|
{4:~ }|
{5:[No Name] [+] }|
- :let g:menustr = 'bar' |
+ {3:-- INSERT --} |
{3:-- TERMINAL --} |
]])
- meths.input_mouse('left', 'release', '', 0, 2, 6)
- screen:expect_unchanged()
end)
it('paste: Insert mode', function()
@@ -752,8 +949,7 @@ describe('TUI', function()
]])
-- Dot-repeat/redo.
feed_data('2.')
- expect_child_buf_lines(
- {'"pasted from terminapasted from terminalpasted from terminall"'})
+ expect_child_buf_lines({'"pasted from terminapasted from terminalpasted from terminall"'})
screen:expect([[
"pasted from terminapasted from terminalpasted fro|
m termina{1:l}l" |
@@ -806,13 +1002,13 @@ describe('TUI', function()
'this is line 2',
'line 3 is here',
'',
- }
+ }
-- Redo.
feed_data('\18') -- <C-r>
expect_child_buf_lines{
'thisjust paste it™3 is here',
'',
- }
+ }
end)
it('paste: terminal mode', function()
@@ -874,17 +1070,15 @@ describe('TUI', function()
screen:expect{grid=expected_grid1, attr_ids=expected_attr}
-- Dot-repeat/redo.
feed_data('.')
- screen:expect{
- grid=[[
- ESC:{11:^[} / CR: |
- xline 1 |
- ESC:{11:^[} / CR: |
- {1:x} |
- {5:[No Name] [+] 5,1 Bot}|
- |
- {3:-- TERMINAL --} |
- ]],
- attr_ids=expected_attr}
+ screen:expect{grid=[[
+ ESC:{11:^[} / CR: |
+ xline 1 |
+ ESC:{11:^[} / CR: |
+ {1:x} |
+ {5:[No Name] [+] 5,1 Bot}|
+ |
+ {3:-- TERMINAL --} |
+ ]], attr_ids=expected_attr}
-- Undo.
feed_data('u')
expect_child_buf_lines(expected_crlf)
@@ -1171,8 +1365,7 @@ describe('TUI', function()
{5:[No Name] [+] }|
{3:-- INSERT --} |
{3:-- TERMINAL --} |
- ]],
- attr_ids={
+ ]], attr_ids={
[1] = {reverse = true},
[2] = {background = tonumber('0x00000b')},
[3] = {bold = true},
@@ -1351,7 +1544,7 @@ describe('TUI', function()
it('forwards :term palette colors with termguicolors', function()
if is_ci('github') then
- pending("tty-test complains about not owning the terminal -- actions/runner#241")
+ pending("tty-test complains about not owning the terminal -- actions/runner#241")
end
screen:set_rgb_cterm(true)
screen:set_default_attr_ids({
@@ -1397,24 +1590,41 @@ describe('TUI', function()
]]}
end)
- it('is included in nvim_list_uis()', function()
- feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\r')
- screen:expect([=[
- |
- {4:~ }|
- {5: }|
- [[['chan', 1], ['height', 6], ['override', v:false|
- ], ['rgb', v:false], ['width', 50]]] |
- {10:Press ENTER or type command to continue}{1: } |
- {3:-- TERMINAL --} |
- ]=])
+ it('in nvim_list_uis()', function()
+ -- $TERM in :terminal.
+ local exp_term = is_os('bsd') and 'builtin_xterm' or 'xterm-256color'
+ local expected = {
+ {
+ chan = 1,
+ ext_cmdline = false,
+ ext_hlstate = false,
+ ext_linegrid = true,
+ ext_messages = false,
+ ext_multigrid = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
+ ext_termcolors = true,
+ ext_wildmenu = false,
+ height = 6,
+ override = false,
+ rgb = false,
+ stdin_tty = true,
+ stdout_tty = true,
+ term_background = '',
+ term_colors = 256,
+ term_name = exp_term,
+ width = 50
+ },
+ }
+ local _, rv = child_session:request('nvim_list_uis')
+ eq(expected, rv)
end)
it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function()
child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { ('℃'):rep(60), ('℃'):rep(60) })
- child_session:request('nvim_win_set_option', 0, 'cursorline', true)
- child_session:request('nvim_win_set_option', 0, 'list', true)
- child_session:request('nvim_win_set_option', 0, 'listchars', 'eol:$')
+ child_session:request('nvim_set_option_value', 'cursorline', true, {})
+ child_session:request('nvim_set_option_value', 'list', true, {})
+ child_session:request('nvim_set_option_value', 'listchars', 'eol:$', {win=0})
feed_data('gg')
local singlewidth_screen = [[
{13:℃}{12:℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}|
@@ -1425,21 +1635,21 @@ describe('TUI', function()
|
{3:-- TERMINAL --} |
]]
- -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width, the
- -- second cell of "℃" is a space and the attributes of the "℃" are applied to it.
+ -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width,
+ -- the second cell of "℃" is a space and the attributes of the "℃" are applied to it.
local doublewidth_screen = [[
{13:℃}{12: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }|
{12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }|
{12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{15:$}{12: }|
- ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ >{4:@@@}|
+ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ {4:@@@@}|
{5:[No Name] [+] }|
|
{3:-- TERMINAL --} |
]]
screen:expect(singlewidth_screen)
- child_session:request('nvim_set_option', 'ambiwidth', 'double')
+ child_session:request('nvim_set_option_value', 'ambiwidth', 'double', {})
screen:expect(doublewidth_screen)
- child_session:request('nvim_set_option', 'ambiwidth', 'single')
+ child_session:request('nvim_set_option_value', 'ambiwidth', 'single', {})
screen:expect(singlewidth_screen)
child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 2}}})
screen:expect(doublewidth_screen)
@@ -1448,22 +1658,19 @@ describe('TUI', function()
end)
it('draws correctly when cursor_address overflows #21643', function()
- helpers.skip(helpers.is_os('mac'), 'FIXME: crashes/errors on macOS')
- screen:try_resize(77, 834)
+ helpers.skip(is_os('mac'), 'FIXME: crashes/errors on macOS')
+ screen:try_resize(77, 855)
retry(nil, nil, function()
- eq({true, 831}, {child_session:request('nvim_win_get_height', 0)})
+ eq({true, 852}, {child_session:request('nvim_win_get_height', 0)})
end)
-- Use full screen message so that redrawing afterwards is more deterministic.
child_session:notify('nvim_command', 'intro')
screen:expect({any = 'Nvim'})
-- Going to top-left corner needs 3 bytes.
-- Setting underline attribute needs 9 bytes.
- -- With screen width 77, 63857 characters need 829 full screen lines.
- -- Drawing each full screen line needs 77 + 2 = 79 bytes (2 bytes for CR LF).
- -- The incomplete screen line needs 24 + 3 = 27 bytes.
- -- The whole line needs 3 + 9 + 79 * 829 + 27 = 65530 bytes.
+ -- The whole line needs 3 + 9 + 65515 + 3 = 65530 bytes.
-- The cursor_address that comes after will overflow the 65535-byte buffer.
- local line = ('a'):rep(63857) .. '℃'
+ local line = ('a'):rep(65515) .. '℃'
child_session:notify('nvim_exec_lua', [[
vim.api.nvim_buf_set_lines(0, 0, -1, true, {...})
vim.o.cursorline = true
@@ -1472,8 +1679,8 @@ describe('TUI', function()
feed_data('\n')
screen:expect(
'{13:a}{12:' .. ('a'):rep(76) .. '}|\n'
- .. ('{12:' .. ('a'):rep(77) .. '}|\n'):rep(828)
- .. '{12:' .. ('a'):rep(24) .. '℃' .. (' '):rep(52) .. '}|\n' .. dedent([[
+ .. ('{12:' .. ('a'):rep(77) .. '}|\n'):rep(849)
+ .. '{12:' .. ('a'):rep(65) .. '℃' .. (' '):rep(11) .. '}|\n' .. dedent([[
b |
{5:[No Name] [+] }|
|
@@ -1506,13 +1713,107 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]]}
end)
+
+ it('no assert failure on deadly signal #21896', function()
+ exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]])
+ screen:expect{grid=[[
+ Vim: Caught deadly signal 'SIGTERM' |
+ |
+ |
+ [Process exited 1]{1: } |
+ |
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+ end)
+
+ it('no stack-use-after-scope with cursor color #22432', function()
+ screen:set_option('rgb', true)
+ command('set termguicolors')
+ child_session:request('nvim_exec2', [[
+ set tgc
+ hi Cursor guifg=Red guibg=Green
+ set guicursor=n:block-Cursor/lCursor
+ ]], {})
+ screen:set_default_attr_ids({
+ [1] = {reverse = true},
+ [2] = {bold = true, foreground = Screen.colors.Blue},
+ [3] = {foreground = Screen.colors.Blue},
+ [4] = {reverse = true, bold = true},
+ [5] = {bold = true},
+ })
+ screen:expect([[
+ {1: } |
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {4:[No Name] }|
+ |
+ {5:-- TERMINAL --} |
+ ]])
+ feed_data('i')
+ screen:expect([[
+ {1: } |
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {4:[No Name] }|
+ {5:-- INSERT --} |
+ {5:-- TERMINAL --} |
+ ]])
+ end)
+
+ it('redraws on SIGWINCH even if terminal size is unchanged #23411', function()
+ child_session:request('nvim_echo', {{'foo'}}, false, {})
+ screen:expect([[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ foo |
+ {3:-- TERMINAL --} |
+ ]])
+ exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]])
+ screen:expect([[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ |
+ {3:-- TERMINAL --} |
+ ]])
+ end)
+
+ it('supports hiding cursor', function()
+ child_session:request('nvim_command',
+ "let g:id = jobstart([v:progpath, '--clean', '--headless'])")
+ feed_data(':call jobwait([g:id])\n')
+ screen:expect([[
+ |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ :call jobwait([g:id]) |
+ {3:-- TERMINAL --} |
+ ]])
+ feed_data('\003')
+ screen:expect([[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ Type :qa and press <Enter> to exit Nvim |
+ {3:-- TERMINAL --} |
+ ]])
+ end)
end)
describe('TUI', function()
before_each(clear)
- after_each(function()
- os.remove('testF')
- end)
it('resize at startup #17285 #15044 #11330', function()
local screen = Screen.new(50, 10)
@@ -1538,12 +1839,51 @@ describe('TUI', function()
{2:~ }│{4:~ }|
{2:~ }│{5:[No Name] 0,0-1 All}|
{2:~ }│ |
- {5:new }{MATCH:<.*[/\]nvim }|
+ {5:new }{1:{MATCH:<.*[/\]nvim }}|
|
]])
end)
+ it('argv[0] can be overridden #23953', function()
+ if not exec_lua('return pcall(require, "ffi")') then
+ pending('missing LuaJIT FFI')
+ end
+ local script_file = 'Xargv0.lua'
+ write_file(script_file, [=[
+ local ffi = require('ffi')
+ ffi.cdef([[int execl(const char *, const char *, ...);]])
+ ffi.C.execl(vim.v.progpath, 'Xargv0nvim', '--clean')
+ ]=])
+ finally(function()
+ os.remove(script_file)
+ end)
+ local screen = thelpers.screen_setup(0, string.format([=[["%s", "--clean", "-l", "%s"]]=],
+ nvim_prog, script_file))
+ screen:expect{grid=[[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+ feed_data(':put =v:argv + [v:progname]\n')
+ screen:expect{grid=[[
+ Xargv0nvim |
+ --embed |
+ --clean |
+ {1:X}argv0nvim |
+ {5:[No Name] [+] 5,1 Bot}|
+ 4 more lines |
+ {3:-- TERMINAL --} |
+ ]]}
+ end)
+
it('with non-tty (pipe) stdout/stderr', function()
+ finally(function()
+ os.remove('testF')
+ end)
local screen = thelpers.screen_setup(0, '"'..nvim_prog
..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')
feed_data(':w testF\n:q\n')
@@ -1582,6 +1922,30 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
end)
+
+ it('draws line with many trailing spaces correctly #24955', function()
+ local screen = thelpers.screen_setup(0, '["'..nvim_prog..[[", "-u", "NONE", "-i", "NONE"]]
+ ..[[, "--cmd", "call setline(1, ['1st line' .. repeat(' ', 153), '2nd line'])"]]..']', 80)
+ screen:expect{grid=[[
+ {1:1}st line |
+ |
+ |
+ 2nd line |
+ {5:[No Name] [+] 1,1 All}|
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+ feed_data('$')
+ screen:expect{grid=[[
+ 1st line |
+ |
+ {1: } |
+ 2nd line |
+ {5:[No Name] [+] 1,161 All}|
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+ end)
end)
describe('TUI UIEnter/UILeave', function()
@@ -1620,12 +1984,16 @@ end)
describe('TUI FocusGained/FocusLost', function()
local screen
+ local child_session
before_each(function()
clear()
- screen = thelpers.screen_setup(0, '["'..nvim_prog
- ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]')
- screen:expect{grid=[[
+ local child_server = new_pipename()
+ screen = thelpers.screen_setup(0,
+ string.format(
+ [=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]]=],
+ nvim_prog, child_server))
+ screen:expect([[
{1: } |
{4:~ }|
{4:~ }|
@@ -1633,22 +2001,16 @@ describe('TUI FocusGained/FocusLost', function()
{5:[No Name] }|
|
{3:-- TERMINAL --} |
- ]]}
- feed_data(":autocmd FocusGained * echo 'gained'\n")
- feed_data(":autocmd FocusLost * echo 'lost'\n")
+ ]])
+ child_session = helpers.connect(child_server)
+ child_session:request('nvim_exec2', [[
+ autocmd FocusGained * echo 'gained'
+ autocmd FocusLost * echo 'lost'
+ ]], {})
feed_data("\034\016") -- CTRL-\ CTRL-N
end)
it('in normal-mode', function()
- screen:expect{grid=[[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] }|
- :autocmd FocusLost * echo 'lost' |
- {3:-- TERMINAL --} |
- ]]}
retry(2, 3 * screen.timeout, function()
feed_data('\027[I')
screen:expect([[
@@ -1675,7 +2037,7 @@ describe('TUI FocusGained/FocusLost', function()
end)
it('in insert-mode', function()
- feed_command('set noshowmode')
+ feed_data(':set noshowmode\r')
feed_data('i')
screen:expect{grid=[[
{1: } |
@@ -1740,18 +2102,11 @@ describe('TUI FocusGained/FocusLost', function()
-- Set up autocmds that modify the buffer, instead of just calling :echo.
-- This is how we can test handling of focus gained/lost during cmdline-mode.
-- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
- feed_data(":autocmd!\n")
- feed_data(":autocmd FocusLost * call append(line('$'), 'lost')\n")
- feed_data(":autocmd FocusGained * call append(line('$'), 'gained')\n")
- screen:expect{grid=[[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] }|
- |
- {3:-- TERMINAL --} |
- ]]}
+ child_session:request('nvim_exec2', [[
+ autocmd!
+ autocmd FocusLost * call append(line('$'), 'lost')
+ autocmd FocusGained * call append(line('$'), 'gained')
+ ]], {})
retry(2, 3 * screen.timeout, function()
-- Enter cmdline-mode.
feed_data(':')
@@ -1768,26 +2123,26 @@ describe('TUI FocusGained/FocusLost', function()
end)
it('in terminal-mode', function()
- feed_data(':set shell='..testprg('shell-test')..'\n')
+ feed_data(':set shell='..testprg('shell-test')..' shellcmdflag=EXE\n')
feed_data(':set noshowmode laststatus=0\n')
- feed_data(':terminal\n')
+ feed_data(':terminal zia\n')
-- Wait for terminal to be ready.
screen:expect{grid=[[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
- :terminal |
+ :terminal zia |
{3:-- TERMINAL --} |
]]}
feed_data('\027[I')
screen:expect{grid=[[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
gained |
@@ -1796,9 +2151,9 @@ describe('TUI FocusGained/FocusLost', function()
feed_data('\027[O')
screen:expect([[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
lost |
@@ -1839,7 +2194,7 @@ describe("TUI 't_Co' (terminal colors)", function()
local screen
local function assert_term_colors(term, colorterm, maxcolors)
- helpers.clear({env={TERM=term}, args={}})
+ clear({env={TERM=term}, args={}})
-- This is ugly because :term/termopen() forces TERM=xterm-256color.
-- TODO: Revisit this after jobstart/termopen accept `env` dict.
screen = thelpers.screen_setup(0, string.format(
@@ -2204,45 +2559,44 @@ describe("TUI", function()
end)
+-- See test/unit/tui_spec.lua for unit tests.
describe('TUI bg color', function()
local screen
- local function setup()
- -- Only single integration test.
- -- See test/unit/tui_spec.lua for unit tests.
+ local function setup_bg_test()
clear()
screen = thelpers.screen_setup(0, '["'..nvim_prog
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile", '
..'"-c", "autocmd OptionSet background echo \\"did OptionSet, yay!\\""]')
end
- before_each(setup)
+ before_each(setup_bg_test)
it('triggers OptionSet event on unsplit terminal-response', function()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
- feed_data('\027]11;rgb:ffff/ffff/ffff\007')
+ feed_data('\027]11;rgb:ffff/ffff/ffff\027\\')
screen:expect{any='did OptionSet, yay!'}
feed_data(':echo "new_bg=".&background\n')
screen:expect{any='new_bg=light'}
- setup()
+ setup_bg_test()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
feed_data('\027]11;rgba:ffff/ffff/ffff/8000\027\\')
screen:expect{any='did OptionSet, yay!'}
@@ -2253,13 +2607,13 @@ describe('TUI bg color', function()
it('triggers OptionSet event with split terminal-response', function()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
-- Send a background response with the OSC command part split.
feed_data('\027]11;rgb')
@@ -2269,19 +2623,19 @@ describe('TUI bg color', function()
feed_data(':echo "new_bg=".&background\n')
screen:expect{any='new_bg=light'}
- setup()
+ setup_bg_test()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
-- Send a background response with the Pt portion split.
feed_data('\027]11;rgba:ffff/fff')
- feed_data('f/ffff/8000\007')
+ feed_data('f/ffff/8000\027\\')
screen:expect{any='did OptionSet, yay!'}
feed_data(':echo "new_bg=".&background\n')
@@ -2290,13 +2644,13 @@ describe('TUI bg color', function()
it('not triggers OptionSet event with invalid terminal-response', function()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
feed_data('\027]11;rgb:ffff/ffff/ffff/8000\027\\')
screen:expect_unchanged()
@@ -2304,17 +2658,17 @@ describe('TUI bg color', function()
feed_data(':echo "new_bg=".&background\n')
screen:expect{any='new_bg=dark'}
- setup()
+ setup_bg_test()
screen:expect([[
- {1: } |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] 0,0-1 All}|
- |
- {3:-- TERMINAL --} |
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] 0,0-1 All}|
+ |
+ {3:-- TERMINAL --} |
]])
- feed_data('\027]11;rgba:ffff/foo/ffff/8000\007')
+ feed_data('\027]11;rgba:ffff/foo/ffff/8000\027\\')
screen:expect_unchanged()
feed_data(':echo "new_bg=".&background\n')
@@ -2359,18 +2713,31 @@ describe("TUI as a client", function()
set_session(client_super)
local screen_client = thelpers.screen_setup(0,
- string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=],
+ string.format([=[["%s", "--server", "%s", "--remote-ui"]]=],
nvim_prog, server_pipe))
- screen_client:expect{grid=[[
- Hello, Worl{1:d} |
- {4:~ }|
- {4:~ }|
- {4:~ }|
- {5:[No Name] [+] }|
- |
- {3:-- TERMINAL --} |
- ]]}
+ screen_client:expect{grid=[[
+ Hello, Worl{1:d} |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+
+ -- grid smaller than containing terminal window is cleared properly
+ feed_data(":call setline(1,['a'->repeat(&columns)]->repeat(&lines))\n")
+ feed_data("0:set lines=3\n")
+ screen_server:expect{grid=[[
+ {1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {5:[No Name] [+] }|
+ |
+ |
+ |
+ |
+ {3:-- TERMINAL --} |
+ ]]}
feed_data(":q!\n")
@@ -2379,19 +2746,19 @@ describe("TUI as a client", function()
end)
it("connects to remote instance (--headless)", function()
- local server = helpers.spawn_argv(false) -- equivalent to clear()
+ local server = spawn_argv(false) -- equivalent to clear()
local client_super = spawn_argv(true)
set_session(server)
- local server_pipe = eval'v:servername'
- feed'iHalloj!<esc>'
+ local server_pipe = meths.get_vvar('servername')
+ server:request('nvim_input', 'iHalloj!<Esc>')
set_session(client_super)
- local screen = thelpers.screen_setup(0,
- string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=],
+ local screen_client = thelpers.screen_setup(0,
+ string.format([=[["%s", "--server", "%s", "--remote-ui"]]=],
nvim_prog, server_pipe))
- screen:expect{grid=[[
+ screen_client:expect{grid=[[
Halloj{1:!} |
{4:~ }|
{4:~ }|
@@ -2401,15 +2768,32 @@ describe("TUI as a client", function()
{3:-- TERMINAL --} |
]]}
+ -- No heap-use-after-free when receiving UI events after deadly signal #22184
+ server:request('nvim_input', ('a'):rep(1000))
+ exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]])
+ screen_client:expect{grid=[[
+ Vim: Caught deadly signal 'SIGTERM' |
+ |
+ |
+ [Process exited 1]{1: } |
+ |
+ |
+ {3:-- TERMINAL --} |
+ ]]}
+
+ eq(0, meths.get_vvar('shell_error'))
+ -- exits on input eof #22244
+ funcs.system({nvim_prog, '--server', server_pipe, '--remote-ui'})
+ eq(1, meths.get_vvar('shell_error'))
+
client_super:close()
server:close()
end)
-
it("throws error when no server exists", function()
clear()
local screen = thelpers.screen_setup(0,
- string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "127.0.0.1:2436546", "--remote-ui"]]=],
+ string.format([=[["%s", "--server", "127.0.0.1:2436546", "--remote-ui"]]=],
nvim_prog), 60)
screen:expect([[
@@ -2423,7 +2807,7 @@ describe("TUI as a client", function()
]])
end)
- it("exits when server quits", function()
+ local function test_remote_tui_quit(status)
local server_super = spawn_argv(false) -- equivalent to clear()
local client_super = spawn_argv(true)
@@ -2432,6 +2816,15 @@ describe("TUI as a client", function()
local screen_server = thelpers.screen_setup(0,
string.format([=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark"]]=],
nvim_prog, server_pipe, nvim_set))
+ screen_server:expect{grid=[[
+ {1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ |
+ {3:-- TERMINAL --} |
+ ]]}
feed_data("iHello, World")
screen_server:expect{grid=[[
@@ -2456,7 +2849,7 @@ describe("TUI as a client", function()
set_session(client_super)
local screen_client = thelpers.screen_setup(0,
- string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=],
+ string.format([=[["%s", "--server", "%s", "--remote-ui"]]=],
nvim_prog, server_pipe))
screen_client:expect{grid=[[
@@ -2471,13 +2864,39 @@ describe("TUI as a client", function()
-- quitting the server
set_session(server_super)
- feed_data(":q!\n")
- screen_server:expect({any="Process exited 0"})
-
+ feed_data(status and ':' .. status .. 'cquit!\n' or ":quit!\n")
+ status = status and status or 0
+ screen_server:expect{grid=[[
+ |
+ [Process exited ]] .. status .. [[]{1: }{MATCH:%s+}|
+ |
+ |
+ |
+ |
+ {3:-- TERMINAL --} |
+ ]]}
-- assert that client has exited
- screen_client:expect({any="Process exited 0"})
+ screen_client:expect{grid=[[
+ |
+ [Process exited ]] .. status .. [[]{1: }{MATCH:%s+}|
+ |
+ |
+ |
+ |
+ {3:-- TERMINAL --} |
+ ]]}
server_super:close()
client_super:close()
+ end
+
+ describe("exits when server quits", function()
+ it("with :quit", function()
+ test_remote_tui_quit()
+ end)
+
+ it("with :cquit", function()
+ test_remote_tui_quit(42)
+ end)
end)
end)
diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua
index 80e9d78400..39fc2c2562 100644
--- a/test/functional/terminal/window_spec.lua
+++ b/test/functional/terminal/window_spec.lua
@@ -44,7 +44,7 @@ describe(':terminal window', function()
{7:6 } |
{3:-- TERMINAL --} |
]])
- feed_data({'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'})
+ feed_data('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
screen:expect([[
{7:1 }tty ready |
{7:2 }rows: 6, cols: 48 |
@@ -55,8 +55,6 @@ describe(':terminal window', function()
{3:-- TERMINAL --} |
]])
- skip(is_os('win'), 'win: :terminal resize is unreliable #7007')
-
-- numberwidth=9
feed([[<C-\><C-N>]])
feed([[:set numberwidth=9 number<CR>i]])
@@ -64,17 +62,17 @@ describe(':terminal window', function()
{7: 1 }tty ready |
{7: 2 }rows: 6, cols: 48 |
{7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
- {7: 4 }WXYZrows: 6, cols: 41 |
+ {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 |
{7: 5 }{1: } |
{7: 6 } |
{3:-- TERMINAL --} |
]])
- feed_data({' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'})
+ feed_data(' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
screen:expect([[
{7: 1 }tty ready |
{7: 2 }rows: 6, cols: 48 |
{7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
- {7: 4 }WXYZrows: 6, cols: 41 |
+ {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 |
{7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN|
{7: 6 }OPQRSTUVWXYZ{1: } |
{3:-- TERMINAL --} |
@@ -82,6 +80,41 @@ describe(':terminal window', function()
end)
end)
+ describe("with 'statuscolumn'", function()
+ it('wraps text', function()
+ command([[set number statuscolumn=++%l\ \ ]])
+ screen:expect([[
+ {7:++1 }tty ready |
+ {7:++2 }rows: 6, cols: 45 |
+ {7:++3 }{1: } |
+ {7:++4 } |
+ {7:++5 } |
+ {7:++6 } |
+ {3:-- TERMINAL --} |
+ ]])
+ feed_data('\n\n\n\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
+ screen:expect([[
+ {7:++4 } |
+ {7:++5 } |
+ {7:++6 } |
+ {7:++7 } |
+ {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS|
+ {7:++9 }TUVWXYZ{1: } |
+ {3:-- TERMINAL --} |
+ ]])
+ feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
+ screen:expect([[
+ {7:++7 } |
+ {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
+ {7:++9 }STUVWXYZ |
+ {7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
+ {7:++11 }STUVWXYZrows: 6, cols: 44 |
+ {7:++12 }{1: } |
+ {3:-- TERMINAL --} |
+ ]])
+ end)
+ end)
+
describe("with 'colorcolumn'", function()
before_each(function()
feed([[<C-\><C-N>]])
diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua
index 1d77e1e92e..da14531fa2 100644
--- a/test/functional/terminal/window_split_tab_spec.lua
+++ b/test/functional/terminal/window_split_tab_spec.lua
@@ -19,7 +19,7 @@ describe(':terminal', function()
clear()
-- set the statusline to a constant value because of variables like pid
-- and current directory and to improve visibility of splits
- meths.set_option('statusline', '==========')
+ meths.set_option_value('statusline', '==========', {})
command('highlight StatusLine cterm=NONE')
command('highlight StatusLineNC cterm=NONE')
command('highlight VertSplit cterm=NONE')
@@ -71,7 +71,7 @@ describe(':terminal', function()
end)
it('does not change size if updated when not visible in any window #19665', function()
- local channel = meths.buf_get_option(0, 'channel')
+ local channel = meths.get_option_value('channel', {})
command('enew')
sleep(100)
meths.chan_send(channel, 'foo')
diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua
new file mode 100644
index 0000000000..a8abbc002b
--- /dev/null
+++ b/test/functional/treesitter/fold_spec.lua
@@ -0,0 +1,474 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+local insert = helpers.insert
+local exec_lua = helpers.exec_lua
+local command = helpers.command
+local feed = helpers.feed
+local Screen = require('test.functional.ui.screen')
+
+before_each(clear)
+
+describe('treesitter foldexpr', function()
+ clear()
+
+ local test_text = [[
+void ui_refresh(void)
+{
+ int width = INT_MAX, height = INT_MAX;
+ bool ext_widgets[kUIExtCount];
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
+ ext_widgets[i] = true;
+ }
+
+ bool inclusive = ui_override();
+ for (size_t i = 0; i < ui_count; i++) {
+ UI *ui = uis[i];
+ width = MIN(ui->width, width);
+ height = MIN(ui->height, height);
+ foo = BAR(ui->bazaar, bazaar);
+ for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
+ ext_widgets[j] &= (ui->ui_ext[j] || inclusive);
+ }
+ }
+}]]
+
+ local function get_fold_levels()
+ return exec_lua([[
+ local res = {}
+ for i = 1, vim.api.nvim_buf_line_count(0) do
+ res[i] = vim.treesitter.foldexpr(i)
+ end
+ return res
+ ]])
+ end
+
+ it("can compute fold levels", function()
+ insert(test_text)
+
+ exec_lua([[vim.treesitter.get_parser(0, "c")]])
+
+ eq({
+ [1] = '>1',
+ [2] = '1',
+ [3] = '1',
+ [4] = '1',
+ [5] = '>2',
+ [6] = '2',
+ [7] = '2',
+ [8] = '1',
+ [9] = '1',
+ [10] = '>2',
+ [11] = '2',
+ [12] = '2',
+ [13] = '2',
+ [14] = '2',
+ [15] = '>3',
+ [16] = '3',
+ [17] = '3',
+ [18] = '2',
+ [19] = '1' }, get_fold_levels())
+
+ end)
+
+ it("recomputes fold levels after lines are added/removed", function()
+ insert(test_text)
+
+ exec_lua([[vim.treesitter.get_parser(0, "c")]])
+
+ command('1,2d')
+
+ eq({
+ [1] = '0',
+ [2] = '0',
+ [3] = '>1',
+ [4] = '1',
+ [5] = '1',
+ [6] = '0',
+ [7] = '0',
+ [8] = '>1',
+ [9] = '1',
+ [10] = '1',
+ [11] = '1',
+ [12] = '1',
+ [13] = '>2',
+ [14] = '2',
+ [15] = '2',
+ [16] = '1',
+ [17] = '0' }, get_fold_levels())
+
+ command('1put!')
+
+ eq({
+ [1] = '>1',
+ [2] = '1',
+ [3] = '1',
+ [4] = '1',
+ [5] = '>2',
+ [6] = '2',
+ [7] = '2',
+ [8] = '1',
+ [9] = '1',
+ [10] = '>2',
+ [11] = '2',
+ [12] = '2',
+ [13] = '2',
+ [14] = '2',
+ [15] = '>3',
+ [16] = '3',
+ [17] = '3',
+ [18] = '2',
+ [19] = '1' }, get_fold_levels())
+ end)
+
+ it("updates folds in all windows", function()
+ local screen = Screen.new(60, 48)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue};
+ [2] = {bold = true, foreground = Screen.colors.Blue1};
+ [3] = {bold = true, reverse = true};
+ [4] = {reverse = true};
+ })
+
+ exec_lua([[vim.treesitter.get_parser(0, "c")]])
+ command([[set foldmethod=expr foldexpr=v:lua.vim.treesitter.foldexpr() foldcolumn=1 foldlevel=9]])
+ command('split')
+
+ insert(test_text)
+
+ screen:expect{grid=[[
+ {1:-}void ui_refresh(void) |
+ {1:│}{ |
+ {1:│} int width = INT_MAX, height = INT_MAX; |
+ {1:│} bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:2} ext_widgets[i] = true; |
+ {1:2} } |
+ {1:│} |
+ {1:│} bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:2} UI *ui = uis[i]; |
+ {1:2} width = MIN(ui->width, width); |
+ {1:2} height = MIN(ui->height, height); |
+ {1:2} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:3} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:3} } |
+ {1:2} } |
+ {1:│}^} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ {1:-}void ui_refresh(void) |
+ {1:│}{ |
+ {1:│} int width = INT_MAX, height = INT_MAX; |
+ {1:│} bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:2} ext_widgets[i] = true; |
+ {1:2} } |
+ {1:│} |
+ {1:│} bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:2} UI *ui = uis[i]; |
+ {1:2} width = MIN(ui->width, width); |
+ {1:2} height = MIN(ui->height, height); |
+ {1:2} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:3} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:3} } |
+ {1:2} } |
+ {1:│}} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {4:[No Name] [+] }|
+ |
+ ]]}
+
+ command('1,2d')
+
+ screen:expect{grid=[[
+ {1: } ^int width = INT_MAX, height = INT_MAX; |
+ {1: } bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:│} ext_widgets[i] = true; |
+ {1:│} } |
+ {1: } |
+ {1: } bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:│} UI *ui = uis[i]; |
+ {1:│} width = MIN(ui->width, width); |
+ {1:│} height = MIN(ui->height, height); |
+ {1:│} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:2} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:2} } |
+ {1:│} } |
+ {1: }} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ {1: } int width = INT_MAX, height = INT_MAX; |
+ {1: } bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:│} ext_widgets[i] = true; |
+ {1:│} } |
+ {1: } |
+ {1: } bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:│} UI *ui = uis[i]; |
+ {1:│} width = MIN(ui->width, width); |
+ {1:│} height = MIN(ui->height, height); |
+ {1:│} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:2} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:2} } |
+ {1:│} } |
+ {1: }} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {4:[No Name] [+] }|
+ |
+ ]]}
+
+
+ feed([[O<C-u><C-r>"<BS><Esc>]])
+
+ screen:expect{grid=[[
+ {1:-}void ui_refresh(void) |
+ {1:│}^{ |
+ {1:│} int width = INT_MAX, height = INT_MAX; |
+ {1:│} bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:2} ext_widgets[i] = true; |
+ {1:2} } |
+ {1:│} |
+ {1:│} bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:2} UI *ui = uis[i]; |
+ {1:2} width = MIN(ui->width, width); |
+ {1:2} height = MIN(ui->height, height); |
+ {1:2} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:3} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:3} } |
+ {1:2} } |
+ {1:│}} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ {1:-}void ui_refresh(void) |
+ {1:│}{ |
+ {1:│} int width = INT_MAX, height = INT_MAX; |
+ {1:│} bool ext_widgets[kUIExtCount]; |
+ {1:-} for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ {1:2} ext_widgets[i] = true; |
+ {1:2} } |
+ {1:│} |
+ {1:│} bool inclusive = ui_override(); |
+ {1:-} for (size_t i = 0; i < ui_count; i++) { |
+ {1:2} UI *ui = uis[i]; |
+ {1:2} width = MIN(ui->width, width); |
+ {1:2} height = MIN(ui->height, height); |
+ {1:2} foo = BAR(ui->bazaar, bazaar); |
+ {1:-} for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1:3} ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1:3} } |
+ {1:2} } |
+ {1:│}} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {4:[No Name] [+] }|
+ |
+ ]]}
+
+ end)
+
+ it("doesn't open folds in diff mode", function()
+ local screen = Screen.new(60, 36)
+ screen:attach()
+
+ exec_lua([[vim.treesitter.get_parser(0, "c")]])
+ command([[set foldmethod=expr foldexpr=v:lua.vim.treesitter.foldexpr() foldcolumn=1 foldlevel=9]])
+ insert(test_text)
+ command('16d')
+
+ command('new')
+ insert(test_text)
+
+ command('windo diffthis')
+ feed('do')
+
+ screen:expect{grid=[[
+ {1:+ }{2:+-- 9 lines: void ui_refresh(void)·······················}|
+ {1: } for (size_t i = 0; i < ui_count; i++) { |
+ {1: } UI *ui = uis[i]; |
+ {1: } width = MIN(ui->width, width); |
+ {1: } height = MIN(ui->height, height); |
+ {1: } foo = BAR(ui->bazaar, bazaar); |
+ {1: } for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1: } ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1: } } |
+ {1: } } |
+ {1: }} |
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {4:[No Name] [+] }|
+ {1:+ }{2:+-- 9 lines: void ui_refresh(void)·······················}|
+ {1: } for (size_t i = 0; i < ui_count; i++) { |
+ {1: } UI *ui = uis[i]; |
+ {1: } width = MIN(ui->width, width); |
+ {1: } height = MIN(ui->height, height); |
+ {1: } foo = BAR(ui->bazaar, bazaar); |
+ {1: } for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ {1: } ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ {1: } ^} |
+ {1: } } |
+ {1: }} |
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {5:[No Name] [+] }|
+ |
+ ]], attr_ids={
+ [1] = {background = Screen.colors.Grey, foreground = Screen.colors.Blue4};
+ [2] = {background = Screen.colors.LightGrey, foreground = Screen.colors.Blue4};
+ [3] = {foreground = Screen.colors.Blue, bold = true};
+ [4] = {reverse = true};
+ [5] = {reverse = true, bold = true};
+ }}
+ end)
+
+end)
+
+describe('treesitter foldtext', function()
+ local test_text = [[
+void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *))
+{
+ int width = INT_MAX, height = INT_MAX;
+ bool ext_widgets[kUIExtCount];
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
+ ext_widgets[i] = true;
+ }
+
+ bool inclusive = ui_override();
+ for (size_t i = 0; i < ui_count; i++) {
+ UI *ui = uis[i];
+ width = MIN(ui->width, width);
+ height = MIN(ui->height, height);
+ foo = BAR(ui->bazaar, bazaar);
+ for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
+ ext_widgets[j] &= (ui->ui_ext[j] || inclusive);
+ }
+ }
+}]]
+ local screen
+
+ before_each(function()
+ screen = Screen.new(60, 5)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue, bold = true},
+ [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray};
+ [2] = {bold = true, background = Screen.colors.LightGray, foreground = Screen.colors.SeaGreen};
+ [3] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGray};
+ [4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightGray};
+ [5] = {bold = true, background = Screen.colors.LightGray, foreground = Screen.colors.Brown};
+ [6] = {background = Screen.colors.Red1};
+ [7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Red};
+ [8] = {foreground = Screen.colors.Brown, bold = true, background = Screen.colors.Red};
+ [9] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Red};
+ [10] = {bold = true};
+ })
+ screen:attach()
+ end)
+
+ it('displays highlighted content', function()
+ command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext() updatetime=50]])
+ insert(test_text)
+ exec_lua([[vim.treesitter.get_parser(0, "c")]])
+
+ feed('ggVGzf')
+ screen:expect{grid=[[
+ {2:^void}{1: }{3:qsort}{4:(}{2:void}{1: }{5:*}{3:base}{4:,}{1: }{2:size_t}{1: }{3:nel}{4:,}{1: }{2:size_t}{1: }{3:width}{4:,}{1: }{2:int}{1: }{4:(}{5:*}{3:compa}|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end)
+
+ it('handles deep nested captures', function()
+ command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext() updatetime=50]])
+ insert([[
+function FoldInfo.new()
+ return setmetatable({
+ start_counts = {},
+ stop_counts = {},
+ levels0 = {},
+ levels = {},
+ }, FoldInfo)
+end]])
+ exec_lua([[vim.treesitter.get_parser(0, "lua")]])
+
+ feed('ggjVGkzfgg')
+ screen:expect{grid=[[
+ ^function FoldInfo.new() |
+ {1: }{5:return}{1: }{4:setmetatable({}{1:·····································}|
+ end |
+ {0:~ }|
+ |
+ ]]}
+
+ command('hi! Visual guibg=Red')
+ feed('GVgg')
+ screen:expect{grid=[[
+ ^f{6:unction FoldInfo.new()} |
+ {7: }{8:return}{7: }{9:setmetatable({}{7:·····································}|
+ {6:end} |
+ {0:~ }|
+ {10:-- VISUAL LINE --} |
+ ]]}
+
+ feed('10l<C-V>')
+ screen:expect{grid=[[
+ {6:function F}^oldInfo.new() |
+ {7: }{8:return}{7: }{9:se}{4:tmetatable({}{1:·····································}|
+ {6:end} |
+ {0:~ }|
+ {10:-- VISUAL BLOCK --} |
+ ]]}
+ end)
+
+ it('falls back to default', function()
+ command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext()]])
+ insert(test_text)
+
+ feed('ggVGzf')
+ screen:expect{grid=[[
+ {1:^+-- 19 lines: void qsort(void *base, size_t nel, size_t widt}|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end)
+end)
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 2a2311c0fa..e037c9e215 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -11,7 +11,7 @@ local eq = helpers.eq
before_each(clear)
-local hl_query = [[
+local hl_query_c = [[
(ERROR) @error
"if" @keyword
@@ -47,7 +47,7 @@ local hl_query = [[
(comment) @comment
]]
-local hl_text = [[
+local hl_text_c = [[
/// Schedule Lua callback on main loop's event queue
static int nlua_schedule(lua_State *const lstate)
{
@@ -64,7 +64,7 @@ static int nlua_schedule(lua_State *const lstate)
return 0;
}]]
-local test_text = [[
+local test_text_c = [[
void ui_refresh(void)
{
int width = INT_MAX, height = INT_MAX;
@@ -85,7 +85,57 @@ void ui_refresh(void)
}
}]]
-describe('treesitter highlighting', function()
+local injection_text_c = [[
+int x = INT_MAX;
+#define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+#define foo void main() { \
+ return 42; \
+ }
+]]
+
+local injection_grid_c = [[
+ int x = INT_MAX; |
+ #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) |
+ #define foo void main() { \ |
+ return 42; \ |
+ } |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+]]
+
+local injection_grid_expected_c = [[
+ {3:int} x = {5:INT_MAX}; |
+ #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) |
+ #define foo {3:void} main() { \ |
+ {4:return} {5:42}; \ |
+ } |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+]]
+
+describe('treesitter highlighting (C)', function()
local screen
before_each(function()
@@ -105,13 +155,13 @@ describe('treesitter highlighting', function()
[11] = {foreground = Screen.colors.Cyan4};
}
- exec_lua([[ hl_query = ... ]], hl_query)
+ exec_lua([[ hl_query = ... ]], hl_query_c)
command [[ hi link @error ErrorMsg ]]
command [[ hi link @warning WarningMsg ]]
end)
it('is updated with edits', function()
- insert(hl_text)
+ insert(hl_text_c)
screen:expect{grid=[[
/// Schedule Lua callback on main loop's event queue |
static int nlua_schedule(lua_State *const lstate) |
@@ -274,7 +324,7 @@ describe('treesitter highlighting', function()
end)
it('is updated with :sort', function()
- insert(test_text)
+ insert(test_text_c)
exec_lua [[
local parser = vim.treesitter.get_parser(0, "c")
test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query}})
@@ -351,7 +401,7 @@ describe('treesitter highlighting', function()
[1] = {bold = true, foreground = Screen.colors.SeaGreen4};
}
- insert(test_text)
+ insert(test_text_c)
screen:expect{ grid= [[
int width = INT_MAX, height = INT_MAX; |
@@ -376,7 +426,7 @@ describe('treesitter highlighting', function()
exec_lua [[
parser = vim.treesitter.get_parser(0, "c")
- query = vim.treesitter.parse_query("c", "(declaration) @decl")
+ query = vim.treesitter.query.parse("c", "(declaration) @decl")
local nodes = {}
for _, node in query:iter_captures(parser:parse()[1]:root(), 0, 0, 19) do
@@ -411,85 +461,58 @@ describe('treesitter highlighting', function()
end)
it("supports injected languages", function()
- insert([[
- int x = INT_MAX;
- #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
- #define foo void main() { \
- return 42; \
- }
- ]])
+ insert(injection_text_c)
- screen:expect{grid=[[
- int x = INT_MAX; |
- #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))|
- #define foo void main() { \ |
- return 42; \ |
- } |
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
+ screen:expect{grid=injection_grid_c}
exec_lua [[
local parser = vim.treesitter.get_parser(0, "c", {
- injections = {c = "(preproc_def (preproc_arg) @c) (preproc_function_def value: (preproc_arg) @c)"}
+ injections = {c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "c")) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "c"))'}
})
local highlighter = vim.treesitter.highlighter
test_hl = highlighter.new(parser, {queries = {c = hl_query}})
]]
- screen:expect{grid=[[
- {3:int} x = {5:INT_MAX}; |
- #define {5:READ_STRING}(x, y) ({3:char_u} *)read_string((x), ({3:size_t})(y))|
- #define foo {3:void} main() { \ |
- {4:return} {5:42}; \ |
- } |
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
+ screen:expect{grid=injection_grid_expected_c}
+ end)
+
+ it("supports injecting by ft name in metadata['injection.language']", function()
+ insert(injection_text_c)
+
+ screen:expect{grid=injection_grid_c}
+
+ exec_lua [[
+ vim.treesitter.language.register("c", "foo")
+ local parser = vim.treesitter.get_parser(0, "c", {
+ injections = {c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "fOO")) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "fOO"))'}
+ })
+ local highlighter = vim.treesitter.highlighter
+ test_hl = highlighter.new(parser, {queries = {c = hl_query}})
+ ]]
+
+ screen:expect{grid=injection_grid_expected_c}
end)
it("supports overriding queries, like ", function()
insert([[
int x = INT_MAX;
- #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
+ #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define foo void main() { \
return 42; \
}
]])
exec_lua [[
- local injection_query = "(preproc_def (preproc_arg) @c) (preproc_function_def value: (preproc_arg) @c)"
- require('vim.treesitter.query').set_query("c", "highlights", hl_query)
- require('vim.treesitter.query').set_query("c", "injections", injection_query)
+ local injection_query = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "c")) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "c"))'
+ vim.treesitter.query.set("c", "highlights", hl_query)
+ vim.treesitter.query.set("c", "injections", injection_query)
vim.treesitter.highlighter.new(vim.treesitter.get_parser(0, "c"))
]]
screen:expect{grid=[[
{3:int} x = {5:INT_MAX}; |
- #define {5:READ_STRING}(x, y) ({3:char_u} *)read_string((x), ({3:size_t})(y))|
+ #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) |
#define foo {3:void} main() { \ |
{4:return} {5:42}; \ |
} |
@@ -510,7 +533,7 @@ describe('treesitter highlighting', function()
end)
it("supports highlighting with custom highlight groups", function()
- insert(hl_text)
+ insert(hl_text_c)
exec_lua [[
local parser = vim.treesitter.get_parser(0, "c")
@@ -567,7 +590,7 @@ describe('treesitter highlighting', function()
it("supports highlighting with priority", function()
insert([[
int x = INT_MAX;
- #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
+ #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define foo void main() { \
return 42; \
}
@@ -575,12 +598,12 @@ describe('treesitter highlighting', function()
exec_lua [[
local parser = vim.treesitter.get_parser(0, "c")
- test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query..'\n((translation_unit) @Error (set! "priority" 101))\n'}})
+ test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query..'\n((translation_unit) @constant (#set! "priority" 101))\n'}})
]]
- -- expect everything to have Error highlight
+ -- expect everything to have Constant highlight
screen:expect{grid=[[
{12:int}{8: x = INT_MAX;} |
- {8:#define READ_STRING(x, y) (}{12:char_u}{8: *)read_string((x), (}{12:size_t}{8:)(y))}|
+ {8:#define READ_STRING(x, y) (}{12:char}{8: *)read_string((x), (}{12:size_t}{8:)(y))} |
{8:#define foo }{12:void}{8: main() { \} |
{8: }{12:return}{8: 42; \} |
{8: }} |
@@ -599,13 +622,13 @@ describe('treesitter highlighting', function()
|
]], attr_ids={
[1] = {bold = true, foreground = Screen.colors.Blue1};
- [8] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
+ [8] = {foreground = Screen.colors.Magenta1};
-- bold will not be overwritten at the moment
- [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Grey100};
+ [12] = {bold = true, foreground = Screen.colors.Magenta1};
}}
eq({
- {capture='Error', metadata = { priority='101' }, lang='c' };
+ {capture='constant', metadata = { priority='101' }, lang='c' };
{capture='type', metadata = { }, lang='c' };
}, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]])
end)
@@ -692,7 +715,7 @@ describe('treesitter highlighting', function()
end)
it("supports conceal attribute", function()
- insert(hl_text)
+ insert(hl_text_c)
-- conceal can be empty or a single cchar.
exec_lua [=[
@@ -753,3 +776,129 @@ describe('treesitter highlighting', function()
eq(nil, get_hl"@total.nonsense.but.a.lot.of.dots")
end)
end)
+
+describe('treesitter highlighting (help)', 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("correctly redraws added/removed injections", function()
+ insert[[
+ >ruby
+ -- comment
+ local this_is = 'actually_lua'
+ <
+ ]]
+
+ exec_lua [[
+ vim.bo.filetype = 'help'
+ vim.treesitter.start()
+ ]]
+
+ screen:expect{grid=[[
+ {1:>ruby} |
+ {1: -- comment} |
+ {1: local this_is = 'actually_lua'} |
+ < |
+ ^ |
+ |
+ ]]}
+
+ helpers.curbufmeths.set_text(0, 1, 0, 5, {'lua'})
+
+ screen:expect{grid=[[
+ {1:>lua} |
+ {1: -- comment} |
+ {1: }{3:local}{1: }{4:this_is}{1: }{3:=}{1: }{5:'actually_lua'} |
+ < |
+ ^ |
+ |
+ ]]}
+
+ helpers.curbufmeths.set_text(0, 1, 0, 4, {'ruby'})
+
+ screen:expect{grid=[[
+ {1:>ruby} |
+ {1: -- comment} |
+ {1: local this_is = 'actually_lua'} |
+ < |
+ ^ |
+ |
+ ]]}
+ end)
+
+end)
+
+describe('treesitter highlighting (nested injections)', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(80, 7)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = {foreground = Screen.colors.SlateBlue};
+ [2] = {bold = true, foreground = Screen.colors.Brown};
+ [3] = {foreground = Screen.colors.Cyan4};
+ [4] = {foreground = Screen.colors.Fuchsia};
+ }
+ end)
+
+ it("correctly redraws nested injections (GitHub #25252)", function()
+ insert[=[
+function foo() print("Lua!") end
+
+local lorem = {
+ ipsum = {},
+ bar = {},
+}
+vim.cmd([[
+ augroup RustLSP
+ autocmd CursorHold silent! lua vim.lsp.buf.document_highlight()
+ augroup END
+]])
+ ]=]
+
+ exec_lua [[
+ vim.opt.scrolloff = 0
+ vim.bo.filetype = 'lua'
+ vim.treesitter.start()
+ ]]
+
+ -- invalidate the language tree
+ feed("ggi--[[<ESC>04x")
+
+ screen:expect{grid=[[
+ {2:^function} {3:foo}{1:()} {1:print(}{4:"Lua!"}{1:)} {2:end} |
+ |
+ {2:local} {3:lorem} {2:=} {1:{} |
+ {3:ipsum} {2:=} {1:{},} |
+ {3:bar} {2:=} {1:{},} |
+ {1:}} |
+ |
+ ]]}
+
+ -- spam newline insert/delete to invalidate Lua > Vim > Lua region
+ feed("3jo<ESC>ddko<ESC>ddko<ESC>ddko<ESC>ddk0")
+
+ screen:expect{grid=[[
+ {2:function} {3:foo}{1:()} {1:print(}{4:"Lua!"}{1:)} {2:end} |
+ |
+ {2:local} {3:lorem} {2:=} {1:{} |
+ ^ {3:ipsum} {2:=} {1:{},} |
+ {3:bar} {2:=} {1:{},} |
+ {1:}} |
+ |
+ ]]}
+ end)
+
+end)
diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua
index f95b05a1cc..9b871a72fb 100644
--- a/test/functional/treesitter/language_spec.lua
+++ b/test/functional/treesitter/language_spec.lua
@@ -18,22 +18,27 @@ describe('treesitter language API', function()
-- actual message depends on platform
matches("Failed to load parser for language 'borklang': uv_dlopen: .+",
- pcall_err(exec_lua, "parser = vim.treesitter.require_language('borklang', 'borkbork.so')"))
+ pcall_err(exec_lua, "parser = vim.treesitter.language.add('borklang', { path = 'borkbork.so' })"))
- -- Should not throw an error when silent
- eq(false, exec_lua("return vim.treesitter.require_language('borklang', nil, true)"))
- eq(false, exec_lua("return vim.treesitter.require_language('borklang', 'borkbork.so', true)"))
+ eq(false, exec_lua("return pcall(vim.treesitter.language.add, 'borklang')"))
+
+ eq(false, exec_lua("return pcall(vim.treesitter.language.add, 'borklang', { path = 'borkbork.so' })"))
eq(".../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
- pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')"))
+ pcall_err(exec_lua, "parser = vim.treesitter.language.inspect('borklang')"))
matches("Failed to load parser: uv_dlsym: .+",
- pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")'))
+ pcall_err(exec_lua, 'vim.treesitter.language.add("c", { symbol_name = "borklang" })'))
+ end)
+
+ it('shows error for invalid language name', function()
+ eq(".../language.lua:0: '/foo/' is not a valid language name",
+ pcall_err(exec_lua, 'vim.treesitter.language.add("/foo/")'))
end)
it('inspects language', function()
local keys, fields, symbols = unpack(exec_lua([[
- local lang = vim.treesitter.inspect_language('c')
+ local lang = vim.treesitter.language.inspect('c')
local keys, symbols = {}, {}
for k,_ in pairs(lang) do
keys[k] = true
@@ -77,7 +82,7 @@ describe('treesitter language API', function()
command("set filetype=borklang")
-- Should throw an error when filetype changes to borklang
eq(".../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
- pcall_err(exec_lua, "new_parser = vim.treesitter.get_parser(0)"))
+ pcall_err(exec_lua, "new_parser = vim.treesitter.get_parser(0, 'borklang')"))
end)
it('retrieve the tree given a range', function ()
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index a82dce47b7..eef75d0e91 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -4,6 +4,7 @@ local clear = helpers.clear
local eq = helpers.eq
local exec_lua = helpers.exec_lua
local insert = helpers.insert
+local assert_alive = helpers.assert_alive
before_each(clear)
@@ -14,6 +15,31 @@ end
describe('treesitter node API', function()
clear()
+ it('double free tree', function()
+ insert('F')
+ exec_lua([[
+ vim.treesitter.start(0, 'lua')
+ vim.treesitter.get_node():tree()
+ vim.treesitter.get_node():tree()
+ collectgarbage()
+ ]])
+ assert_alive()
+ end)
+
+ it('double free tree 2', function()
+ exec_lua([[
+ parser = vim.treesitter.get_parser(0, "c")
+ local x = parser:parse()[1]:root():tree()
+ vim.api.nvim_buf_set_text(0, 0,0, 0,0, {'y'})
+ parser:parse()
+ vim.api.nvim_buf_set_text(0, 0,0, 0,1, {'z'})
+ parser:parse()
+ collectgarbage()
+ x:root()
+ ]])
+ assert_alive()
+ end)
+
it('can move between siblings', function()
insert([[
int main(int x, int y, int z) {
@@ -26,7 +52,7 @@ describe('treesitter node API', function()
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
root = tree:root()
- lang = vim.treesitter.inspect_language('c')
+ lang = vim.treesitter.language.inspect('c')
function node_text(node)
return query.get_node_text(node, 0)
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index f006ad4539..6f386115ae 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -1,17 +1,21 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
+local dedent = helpers.dedent
local eq = helpers.eq
local insert = helpers.insert
local exec_lua = helpers.exec_lua
+local pcall_err = helpers.pcall_err
local feed = helpers.feed
local is_os = helpers.is_os
-local skip = helpers.skip
-
-before_each(clear)
describe('treesitter parser API', function()
- clear()
+ before_each(function()
+ clear()
+ exec_lua[[
+ vim.g.__ts_debug = 1
+ ]]
+ end)
it('parses buffer', function()
insert([[
@@ -23,7 +27,7 @@ describe('treesitter parser API', function()
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
root = tree:root()
- lang = vim.treesitter.inspect_language('c')
+ lang = vim.treesitter.language.inspect('c')
]])
eq("<tree>", exec_lua("return tostring(tree)"))
@@ -124,6 +128,18 @@ void ui_refresh(void)
}, res)
end)
+ it('does not get parser for empty filetype', function()
+ insert(test_text);
+
+ eq('.../treesitter.lua:0: There is no parser available for buffer 1 and one'
+ .. ' could not be created because lang could not be determined. Either'
+ .. ' pass lang or set the buffer filetype',
+ pcall_err(exec_lua, 'vim.treesitter.get_parser(0)'))
+
+ -- Must provide language for buffers with an empty filetype
+ exec_lua("vim.treesitter.get_parser(0, 'c')")
+ end)
+
it('allows to get a child by field', function()
insert(test_text);
@@ -159,7 +175,7 @@ void ui_refresh(void)
it("supports runtime queries", function()
local ret = exec_lua [[
- return require"vim.treesitter.query".get_query("c", "highlights").captures[1]
+ return vim.treesitter.query.get("c", "highlights").captures[1]
]]
eq('variable', ret)
@@ -170,11 +186,11 @@ void ui_refresh(void)
local function q(n)
return exec_lua ([[
local query, n = ...
- local before = vim.loop.hrtime()
+ local before = vim.uv.hrtime()
for i=1,n,1 do
- cquery = vim.treesitter.parse_query("c", ...)
+ cquery = vim.treesitter.query.parse("c", ...)
end
- local after = vim.loop.hrtime()
+ local after = vim.uv.hrtime()
return after - before
]], long_query, n)
end
@@ -182,15 +198,16 @@ void ui_refresh(void)
local firstrun = q(1)
local manyruns = q(100)
- -- First run should be at least 4x slower.
- assert(400 * manyruns < firstrun, ('firstrun: %d ms, manyruns: %d ms'):format(firstrun / 1000, manyruns / 1000))
+ -- First run should be at least 200x slower than an 100 subsequent runs.
+ local factor = is_os('win') and 100 or 200
+ assert(factor * manyruns < firstrun, ('firstrun: %f ms, manyruns: %f ms'):format(firstrun / 1e6, manyruns / 1e6))
end)
it('support query and iter by capture', function()
insert(test_text)
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", ...)
+ cquery = vim.treesitter.query.parse("c", ...)
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
res = {}
@@ -219,7 +236,7 @@ void ui_refresh(void)
insert(test_text)
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", ...)
+ cquery = vim.treesitter.query.parse("c", ...)
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
res = {}
@@ -263,13 +280,13 @@ void ui_refresh(void)
eq('void', res2)
end)
- it('support getting text where start of node is past EOF', function()
+ it('support getting text where start of node is one past EOF', function()
local text = [[
def run
a = <<~E
end]]
insert(text)
- local result = exec_lua([[
+ eq('', exec_lua[[
local fake_node = {}
function fake_node:start()
return 3, 0, 23
@@ -277,9 +294,14 @@ end]]
function fake_node:end_()
return 3, 0, 23
end
- return vim.treesitter.get_node_text(fake_node, 0) == nil
+ function fake_node:range(bytes)
+ if bytes then
+ return 3, 0, 23, 3, 0, 23
+ end
+ return 3, 0, 3, 0
+ end
+ return vim.treesitter.get_node_text(fake_node, 0)
]])
- eq(true, result)
end)
it('support getting empty text if node range is zero width', function()
@@ -296,6 +318,9 @@ end]]
function fake_node:end_()
return 1, 0, 7
end
+ function fake_node:range()
+ return 1, 0, 1, 0
+ end
return vim.treesitter.get_node_text(fake_node, 0) == ''
]])
eq(true, result)
@@ -305,7 +330,7 @@ end]]
insert('char* astring = "\\n"; (1 + 1) * 2 != 2;')
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", '([_] @plus (#vim-match? @plus "^\\\\+$"))'..
+ cquery = vim.treesitter.query.parse("c", '([_] @plus (#vim-match? @plus "^\\\\+$"))'..
'([_] @times (#vim-match? @times "^\\\\*$"))'..
'([_] @paren (#vim-match? @paren "^\\\\($"))'..
'([_] @escape (#vim-match? @escape "^\\\\\\\\n$"))'..
@@ -355,7 +380,7 @@ end]]
]])
exec_lua([[
function get_query_result(query_text)
- cquery = vim.treesitter.parse_query("c", query_text)
+ cquery = vim.treesitter.query.parse("c", query_text)
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
res = {}
@@ -395,7 +420,7 @@ end]]
insert('char* astring = "Hello World!";')
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", '([_] @quote (#vim-match? @quote "^\\"$")) ([_] @quote (#lua-match? @quote "^\\"$"))')
+ cquery = vim.treesitter.query.parse("c", '([_] @quote (#vim-match? @quote "^\\"$")) ([_] @quote (#lua-match? @quote "^\\"$"))')
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
res = {}
@@ -428,7 +453,7 @@ end]]
local custom_query = "((identifier) @main (#is-main? @main))"
local res = exec_lua([[
- local query = require"vim.treesitter.query"
+ local query = vim.treesitter.query
local function is_main(match, pattern, bufnr, predicate)
local node = match[ predicate[2] ]
@@ -440,7 +465,7 @@ end]]
query.add_predicate("is-main?", is_main)
- local query = query.parse_query("c", ...)
+ local query = query.parse("c", ...)
local nodes = {}
for _, node in query:iter_captures(parser:parse()[1]:root(), 0) do
@@ -453,7 +478,7 @@ end]]
eq({{0, 4, 0, 8}}, res)
local res_list = exec_lua[[
- local query = require'vim.treesitter.query'
+ local query = vim.treesitter.query
local list = query.list_predicates()
@@ -462,10 +487,9 @@ end]]
return list
]]
- eq({ 'any-of?', 'contains?', 'eq?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
+ eq({ 'any-of?', 'contains?', 'eq?', 'has-ancestor?', 'has-parent?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
end)
-
it('allows to set simple ranges', function()
insert(test_text)
@@ -482,22 +506,12 @@ end]]
local root = parser:parse()[1]:root()
parser:set_included_regions({{root:child(0)}})
parser:invalidate()
- return { parser:parse()[1]:root():range() }
+ return { parser:parse(true)[1]:root():range() }
]]
eq({0, 0, 18, 1}, res2)
- local range = exec_lua [[
- local res = {}
- for _, region in ipairs(parser:included_regions()) do
- for _, node in ipairs(region) do
- table.insert(res, {node:range()})
- end
- end
- return res
- ]]
-
- eq(range, { { 0, 0, 18, 1 } })
+ eq({ { { 0, 0, 0, 18, 1, 512 } } }, exec_lua [[ return parser:included_regions() ]])
local range_tbl = exec_lua [[
parser:set_included_regions { { { 0, 0, 17, 1 } } }
@@ -507,12 +521,13 @@ end]]
eq(range_tbl, { { { 0, 0, 0, 17, 1, 508 } } })
end)
+
it("allows to set complex ranges", function()
insert(test_text)
local res = exec_lua [[
parser = vim.treesitter.get_parser(0, "c")
- query = vim.treesitter.parse_query("c", "(declaration) @decl")
+ query = vim.treesitter.query.parse("c", "(declaration) @decl")
local nodes = {}
for _, node in query:iter_captures(parser:parse()[1]:root(), 0) do
@@ -521,7 +536,7 @@ end]]
parser:set_included_regions({nodes})
- local root = parser:parse()[1]:root()
+ local root = parser:parse(true)[1]:root()
local res = {}
for i=0,(root:named_child_count() - 1) do
@@ -560,7 +575,7 @@ end]]
local parser = vim.treesitter.get_string_parser(str, "c")
local nodes = {}
- local query = vim.treesitter.parse_query("c", '((identifier) @id (eq? @id "foo"))')
+ local query = vim.treesitter.query.parse("c", '((identifier) @id (eq? @id "foo"))')
for _, node in query:iter_captures(parser:parse()[1]:root(), str) do
table.insert(nodes, { node:range() })
@@ -582,7 +597,7 @@ end]]
local parser = vim.treesitter.get_string_parser(str, "c")
local nodes = {}
- local query = vim.treesitter.parse_query("c", '((identifier) @foo)')
+ local query = vim.treesitter.query.parse("c", '((identifier) @foo)')
local first_child = parser:parse()[1]:root():child(1)
for _, node in query:iter_captures(first_child, str) do
@@ -606,8 +621,8 @@ end]]
before_each(function()
insert([[
int x = INT_MAX;
-#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
-#define READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
+#define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+#define READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
#define VALUE 123
#define VALUE1 123
#define VALUE2 123
@@ -619,7 +634,8 @@ int x = INT_MAX;
exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
injections = {
- c = "(preproc_def (preproc_arg) @c) (preproc_function_def value: (preproc_arg) @c)"}})
+ c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "c")) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "c"))'}})
+ parser:parse(true)
]])
eq("table", exec_lua("return type(parser:children().c)"))
@@ -629,8 +645,19 @@ int x = INT_MAX;
{3, 14, 3, 17}, -- VALUE 123
{4, 15, 4, 18}, -- VALUE1 123
{5, 15, 5, 18}, -- VALUE2 123
- {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
- {2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
+ {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
+ }, get_ranges())
+
+ helpers.feed('ggo<esc>')
+ eq(5, exec_lua("return #parser:children().c:trees()"))
+ eq({
+ {0, 0, 8, 0}, -- root tree
+ {4, 14, 4, 17}, -- VALUE 123
+ {5, 15, 5, 18}, -- VALUE1 123
+ {6, 15, 6, 18}, -- VALUE2 123
+ {2, 26, 2, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ {3, 29, 3, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges())
end)
end)
@@ -640,7 +667,8 @@ int x = INT_MAX;
exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
injections = {
- c = "(preproc_def (preproc_arg) @c @combined) (preproc_function_def value: (preproc_arg) @c @combined)"}})
+ c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "c") (#set! injection.combined)) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "c") (#set! injection.combined))'}})
+ parser:parse(true)
]])
eq("table", exec_lua("return type(parser:children().c)"))
@@ -650,52 +678,54 @@ int x = INT_MAX;
{3, 14, 5, 18}, -- VALUE 123
-- VALUE1 123
-- VALUE2 123
- {1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
- -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
+ {1, 26, 2, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges())
- end)
- end)
-
- describe("when providing parsing information through a directive", function()
- it("should inject a language", function()
- exec_lua([=[
- vim.treesitter.add_directive("inject-clang!", function(match, _, _, pred, metadata)
- metadata.language = "c"
- metadata.combined = true
- metadata.content = pred[2]
- end)
-
- parser = vim.treesitter.get_parser(0, "c", {
- injections = {
- c = "(preproc_def ((preproc_arg) @_c (#inject-clang! @_c)))" ..
- "(preproc_function_def value: ((preproc_arg) @_a (#inject-clang! @_a)))"}})
- ]=])
+ helpers.feed('ggo<esc>')
eq("table", exec_lua("return type(parser:children().c)"))
eq(2, exec_lua("return #parser:children().c:trees()"))
eq({
- {0, 0, 7, 0}, -- root tree
- {3, 14, 5, 18}, -- VALUE 123
+ {0, 0, 8, 0}, -- root tree
+ {4, 14, 6, 18}, -- VALUE 123
-- VALUE1 123
-- VALUE2 123
- {1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
- -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
+ {2, 26, 3, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges())
end)
+ end)
- it("should not inject bad languages", function()
- skip(is_os('win'))
- exec_lua([=[
- vim.treesitter.add_directive("inject-bad!", function(match, _, _, pred, metadata)
- metadata.language = "{"
- metadata.combined = true
- metadata.content = pred[2]
- end)
-
+ describe("when using injection.self", function()
+ it("should inject the source language", function()
+ exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
injections = {
- c = "(preproc_function_def value: ((preproc_arg) @_a (#inject-bad! @_a)))"}})
- ]=])
+ c = '(preproc_def (preproc_arg) @injection.content (#set! injection.self)) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.self))'}})
+ parser:parse(true)
+ ]])
+
+ eq("table", exec_lua("return type(parser:children().c)"))
+ eq(5, exec_lua("return #parser:children().c:trees()"))
+ eq({
+ {0, 0, 7, 0}, -- root tree
+ {3, 14, 3, 17}, -- VALUE 123
+ {4, 15, 4, 18}, -- VALUE1 123
+ {5, 15, 5, 18}, -- VALUE2 123
+ {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
+ }, get_ranges())
+
+ helpers.feed('ggo<esc>')
+ eq(5, exec_lua("return #parser:children().c:trees()"))
+ eq({
+ {0, 0, 8, 0}, -- root tree
+ {4, 14, 4, 17}, -- VALUE 123
+ {5, 15, 5, 18}, -- VALUE1 123
+ {6, 15, 6, 18}, -- VALUE2 123
+ {2, 26, 2, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ {3, 29, 3, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
+ }, get_ranges())
end)
end)
@@ -704,22 +734,23 @@ int x = INT_MAX;
exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
injections = {
- c = "(preproc_def ((preproc_arg) @c (#offset! @c 0 2 0 -1))) (preproc_function_def value: (preproc_arg) @c)"}})
+ c = '(preproc_def ((preproc_arg) @injection.content (#set! injection.language "c") (#offset! @injection.content 0 2 0 -1))) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.language "c"))'}})
+ parser:parse(true)
]])
eq("table", exec_lua("return type(parser:children().c)"))
eq({
{0, 0, 7, 0}, -- root tree
- {3, 15, 3, 16}, -- VALUE 123
- {4, 16, 4, 17}, -- VALUE1 123
- {5, 16, 5, 17}, -- VALUE2 123
- {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
- {2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
+ {3, 16, 3, 16}, -- VALUE 123
+ {4, 17, 4, 17}, -- VALUE1 123
+ {5, 17, 5, 17}, -- VALUE2 123
+ {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
+ {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges())
end)
it("should list all directives", function()
local res_list = exec_lua[[
- local query = require'vim.treesitter.query'
+ local query = vim.treesitter.query
local list = query.list_directives()
@@ -728,7 +759,7 @@ int x = INT_MAX;
return list
]]
- eq({ 'offset!', 'set!' }, res_list)
+ eq({ 'gsub!', 'offset!', 'set!', 'trim!' }, res_list)
end)
end)
end)
@@ -744,7 +775,8 @@ int x = INT_MAX;
it("should return the correct language tree", function()
local result = exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
- injections = { c = "(preproc_def (preproc_arg) @c)"}})
+ injections = { c = '(preproc_def (preproc_arg) @injection.content (#set! injection.language "c"))'}})
+ parser:parse(true)
local sub_tree = parser:language_for_range({1, 18, 1, 19})
@@ -765,7 +797,7 @@ int x = INT_MAX;
local result = exec_lua([[
local result
- query = vim.treesitter.parse_query("c", '((number_literal) @number (#set! "key" "value"))')
+ query = vim.treesitter.query.parse("c", '((number_literal) @number (#set! "key" "value"))')
parser = vim.treesitter.get_parser(0, "c")
for pattern, match, metadata in query:iter_matches(parser:parse()[1]:root(), 0) do
@@ -785,10 +817,10 @@ int x = INT_MAX;
]])
local result = exec_lua([[
- local query = require("vim.treesitter.query")
+ local query = vim.treesitter.query
local value
- query = vim.treesitter.parse_query("c", '((number_literal) @number (#set! @number "key" "value"))')
+ query = vim.treesitter.query.parse("c", '((number_literal) @number (#set! @number "key" "value"))')
parser = vim.treesitter.get_parser(0, "c")
for pattern, match, metadata in query:iter_matches(parser:parse()[1]:root(), 0) do
@@ -807,10 +839,10 @@ int x = INT_MAX;
]])
local result = exec_lua([[
- local query = require("vim.treesitter.query")
+ local query = vim.treesitter.query
local result
- query = vim.treesitter.parse_query("c", '((number_literal) @number (#set! @number "key" "value") (#set! @number "key2" "value2"))')
+ query = vim.treesitter.query.parse("c", '((number_literal) @number (#set! @number "key" "value") (#set! @number "key2" "value2"))')
parser = vim.treesitter.get_parser(0, "c")
for pattern, match, metadata in query:iter_matches(parser:parse()[1]:root(), 0) do
@@ -829,4 +861,355 @@ int x = INT_MAX;
end)
end)
end)
+
+ it('tracks the root range properly (#22911)', function()
+ insert([[
+ int main() {
+ int x = 3;
+ }]])
+
+ local query0 = [[
+ (declaration) @declaration
+ (function_definition) @function
+ ]]
+
+ exec_lua([[
+ vim.treesitter.start(0, 'c')
+ ]])
+
+ local function run_query()
+ return exec_lua([[
+ local query = vim.treesitter.query.parse("c", ...)
+ parser = vim.treesitter.get_parser()
+ tree = parser:parse()[1]
+ res = {}
+ for id, node in query:iter_captures(tree:root()) do
+ table.insert(res, {query.captures[id], node:range()})
+ end
+ return res
+ ]], query0)
+ end
+
+ eq({
+ { 'function', 0, 0, 2, 1 },
+ { 'declaration', 1, 2, 1, 12 }
+ }, run_query())
+
+ helpers.command'normal ggO'
+ insert('int a;')
+
+ eq({
+ { 'declaration', 0, 0, 0, 6 },
+ { 'function', 1, 0, 3, 1 },
+ { 'declaration', 2, 2, 2, 12 }
+ }, run_query())
+
+ end)
+
+ it('handles ranges when source is a multiline string (#20419)', function()
+ local source = [==[
+ vim.cmd[[
+ set number
+ set cmdheight=2
+ set lastsatus=2
+ ]]
+
+ set query = [[;; query
+ ((function_call
+ name: [
+ (identifier) @_cdef_identifier
+ (_ _ (identifier) @_cdef_identifier)
+ ]
+ arguments: (arguments (string content: _ @injection.content)))
+ (#set! injection.language "c")
+ (#eq? @_cdef_identifier "cdef"))
+ ]]
+ ]==]
+
+ local r = exec_lua([[
+ local parser = vim.treesitter.get_string_parser(..., 'lua')
+ parser:parse(true)
+ local ranges = {}
+ parser:for_each_tree(function(tstree, tree)
+ ranges[tree:lang()] = { tstree:root():range(true) }
+ end)
+ return ranges
+ ]], source)
+
+ eq({
+ lua = { 0, 6, 6, 16, 4, 438 },
+ query = { 6, 20, 113, 15, 6, 431 },
+ vim = { 1, 0, 16, 4, 6, 89 }
+ }, r)
+
+ -- The above ranges are provided directly from treesitter, however query directives may mutate
+ -- the ranges but only provide a Range4. Strip the byte entries from the ranges and make sure
+ -- add_bytes() produces the same result.
+
+ local rb = exec_lua([[
+ local r, source = ...
+ local add_bytes = require('vim.treesitter._range').add_bytes
+ for lang, range in pairs(r) do
+ r[lang] = {range[1], range[2], range[4], range[5]}
+ r[lang] = add_bytes(source, r[lang])
+ end
+ return r
+ ]], r, source)
+
+ eq(rb, r)
+
+ end)
+
+ it("does not produce empty injection ranges (#23409)", function()
+ insert [[
+ Examples: >lua
+ local a = {}
+<
+ ]]
+
+ -- This is not a valid injection since (code) has children and include-children is not set
+ exec_lua [[
+ parser1 = require('vim.treesitter.languagetree').new(0, "vimdoc", {
+ injections = {
+ vimdoc = "((codeblock (language) @injection.language (code) @injection.content))"
+ }
+ })
+ parser1:parse(true)
+ ]]
+
+ eq(0, exec_lua("return #vim.tbl_keys(parser1:children())"))
+
+ exec_lua [[
+ parser2 = require('vim.treesitter.languagetree').new(0, "vimdoc", {
+ injections = {
+ vimdoc = "((codeblock (language) @injection.language (code) @injection.content) (#set! injection.include-children))"
+ }
+ })
+ parser2:parse(true)
+ ]]
+
+ eq(1, exec_lua("return #vim.tbl_keys(parser2:children())"))
+ eq( { { { 1, 0, 21, 2, 0, 42 } } }, exec_lua("return parser2:children().lua:included_regions()"))
+
+ end)
+
+ it("parsers injections incrementally", function()
+ insert(dedent[[
+ >lua
+ local a = {}
+ <
+
+ >lua
+ local b = {}
+ <
+
+ >lua
+ local c = {}
+ <
+
+ >lua
+ local d = {}
+ <
+
+ >lua
+ local e = {}
+ <
+
+ >lua
+ local f = {}
+ <
+
+ >lua
+ local g = {}
+ <
+ ]])
+
+ exec_lua [[
+ parser = require('vim.treesitter.languagetree').new(0, "vimdoc", {
+ injections = {
+ vimdoc = "((codeblock (language) @injection.language (code) @injection.content) (#set! injection.include-children))"
+ }
+ })
+ ]]
+
+ --- Do not parse injections by default
+ eq(0, exec_lua [[
+ parser:parse()
+ return #vim.tbl_keys(parser:children())
+ ]])
+
+ --- Only parse injections between lines 0, 2
+ eq(1, exec_lua [[
+ parser:parse({0, 2})
+ return #parser:children().lua:trees()
+ ]])
+
+ eq(2, exec_lua [[
+ parser:parse({2, 6})
+ return #parser:children().lua:trees()
+ ]])
+
+ eq(7, exec_lua [[
+ parser:parse(true)
+ return #parser:children().lua:trees()
+ ]])
+ end)
+
+ it('fails to load queries', function()
+ local function test(exp, cquery)
+ eq(exp, pcall_err(exec_lua, "vim.treesitter.query.parse('c', ...)", cquery))
+ end
+
+ -- Invalid node type
+ test(
+ '.../query.lua:0: Query error at 1:2. Invalid node type "dentifier":\n'..
+ '(dentifier) @variable\n'..
+ ' ^',
+ '(dentifier) @variable')
+
+ -- Impossible pattern
+ test(
+ '.../query.lua:0: Query error at 1:13. Impossible pattern:\n'..
+ '(identifier (identifier) @variable)\n'..
+ ' ^',
+ '(identifier (identifier) @variable)')
+
+ -- Invalid syntax
+ test(
+ '.../query.lua:0: Query error at 1:13. Invalid syntax:\n'..
+ '(identifier @variable\n'..
+ ' ^',
+ '(identifier @variable')
+
+ -- Invalid field name
+ test(
+ '.../query.lua:0: Query error at 1:15. Invalid field name "invalid_field":\n'..
+ '((identifier) invalid_field: (identifier))\n'..
+ ' ^',
+ '((identifier) invalid_field: (identifier))')
+
+ -- Invalid capture name
+ test(
+ '.../query.lua:0: Query error at 3:2. Invalid capture name "ok.capture":\n'..
+ '@ok.capture\n'..
+ ' ^',
+ '((identifier) @id \n(#eq? @id\n@ok.capture\n))')
+ end)
+
+ describe('is_valid()', function()
+ before_each(function()
+ insert(dedent[[
+ Treesitter integration *treesitter*
+
+ Nvim integrates the `tree-sitter` library for incremental parsing of buffers:
+ https://tree-sitter.github.io/tree-sitter/
+
+ ]])
+
+ feed(':set ft=help<cr>')
+
+ exec_lua [[
+ vim.treesitter.get_parser(0, "vimdoc", {
+ injections = {
+ vimdoc = "((codeblock (language) @injection.language (code) @injection.content) (#set! injection.include-children))"
+ }
+ })
+ ]]
+ end)
+
+ it('is valid excluding, invalid including children initially', function()
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is fully valid after a full parse', function()
+ exec_lua('vim.treesitter.get_parser():parse(true)')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is fully valid after a parsing a range on parsed tree', function()
+ exec_lua('vim.treesitter.get_parser():parse({5, 7})')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ describe('when adding content with injections', function()
+ before_each(function()
+ feed('G')
+ insert(dedent[[
+ >lua
+ local a = {}
+ <
+
+ ]])
+ end)
+
+ it('is fully invalid after changes', function()
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is valid excluding, invalid including children after a rangeless parse', function()
+ exec_lua('vim.treesitter.get_parser():parse()')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is fully valid after a range parse that leads to parsing not parsed injections', function()
+ exec_lua('vim.treesitter.get_parser():parse({5, 7})')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is valid excluding, invalid including children after a range parse that does not lead to parsing not parsed injections', function()
+ exec_lua('vim.treesitter.get_parser():parse({2, 4})')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+ end)
+
+ describe('when removing content with injections', function()
+ before_each(function()
+ feed('G')
+ insert(dedent[[
+ >lua
+ local a = {}
+ <
+
+ >lua
+ local a = {}
+ <
+
+ ]])
+
+ exec_lua('vim.treesitter.get_parser():parse(true)')
+
+ feed('Gd3k')
+ end)
+
+ it('is fully invalid after changes', function()
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is valid excluding, invalid including children after a rangeless parse', function()
+ exec_lua('vim.treesitter.get_parser():parse()')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is fully valid after a range parse that leads to parsing modified child tree', function()
+ exec_lua('vim.treesitter.get_parser():parse({5, 7})')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+
+ it('is valid excluding, invalid including children after a range parse that does not lead to parsing modified child tree', function()
+ exec_lua('vim.treesitter.get_parser():parse({2, 4})')
+ eq(true, exec_lua('return vim.treesitter.get_parser():is_valid(true)'))
+ eq(false, exec_lua('return vim.treesitter.get_parser():is_valid()'))
+ end)
+ end)
+ end)
end)
diff --git a/test/functional/treesitter/utils_spec.lua b/test/functional/treesitter/utils_spec.lua
index 7f5a864c3d..9c07959098 100644
--- a/test/functional/treesitter/utils_spec.lua
+++ b/test/functional/treesitter/utils_spec.lua
@@ -28,4 +28,21 @@ describe('treesitter utils', function()
eq(true, exec_lua('return vim.treesitter.is_ancestor(ancestor, child)'))
eq(false, exec_lua('return vim.treesitter.is_ancestor(child, ancestor)'))
end)
+
+ it('can detect if a position is contained in a node', function()
+ exec_lua([[
+ node = {
+ range = function()
+ return 0, 4, 0, 8
+ end,
+ }
+ ]])
+
+ eq(false, exec_lua('return vim.treesitter.is_in_node_range(node, 0, 3)'))
+ for i = 4, 7 do
+ eq(true, exec_lua('return vim.treesitter.is_in_node_range(node, 0, ...)', i))
+ end
+ -- End column exclusive
+ eq(false, exec_lua('return vim.treesitter.is_in_node_range(node, 0, 8)'))
+ end)
end)
diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua
index 46bfae8de2..81e514c9aa 100644
--- a/test/functional/ui/bufhl_spec.lua
+++ b/test/functional/ui/bufhl_spec.lua
@@ -303,7 +303,7 @@ describe('Buffer highlighting', function()
{1:~ }|
{1:~ }|
{1:~ }|
- 2 change3; before #3 {MATCH:.*}|
+ 2 changes; before #3 {MATCH:.*}|
]]}
command('undo')
@@ -751,8 +751,8 @@ describe('Buffer highlighting', function()
it('validates contents', function()
-- this used to leak memory
- eq('Chunk is not an array', pcall_err(set_virtual_text, id1, 0, {"texty"}, {}))
- eq('Chunk is not an array', pcall_err(set_virtual_text, id1, 0, {{"very"}, "texty"}, {}))
+ eq("Invalid 'chunk': expected Array, got String", pcall_err(set_virtual_text, id1, 0, {"texty"}, {}))
+ eq("Invalid 'chunk': expected Array, got String", pcall_err(set_virtual_text, id1, 0, {{"very"}, "texty"}, {}))
end)
it('can be retrieved', function()
@@ -762,10 +762,9 @@ describe('Buffer highlighting', function()
local s1 = {{'Köttbullar', 'Comment'}, {'Kräuterbutter'}}
local s2 = {{'こんにちは', 'Comment'}}
- -- TODO: only a virtual text from the same ns currently overrides
- -- an existing virtual text. We might add a prioritation system.
set_virtual_text(id1, 0, s1, {})
eq({{1, 0, 0, {
+ ns_id = 1,
priority = 0,
virt_text = s1,
-- other details
@@ -774,10 +773,10 @@ describe('Buffer highlighting', function()
virt_text_hide = false,
}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
- -- TODO: is this really valid? shouldn't the max be line_count()-1?
local lastline = line_count()
set_virtual_text(id1, line_count(), s2, {})
eq({{3, lastline, 0, {
+ ns_id = 1,
priority = 0,
virt_text = s2,
-- other details
diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua
index eb5de693bd..e4766103c2 100644
--- a/test/functional/ui/cmdline_highlight_spec.lua
+++ b/test/functional/ui/cmdline_highlight_spec.lua
@@ -7,6 +7,7 @@ local clear = helpers.clear
local meths = helpers.meths
local funcs = helpers.funcs
local source = helpers.source
+local exec_capture = helpers.exec_capture
local dedent = helpers.dedent
local command = helpers.command
local curbufmeths = helpers.curbufmeths
@@ -177,7 +178,7 @@ end
describe('Command-line coloring', function()
it('works', function()
set_color_cb('RainBowParens')
- meths.set_option('more', false)
+ meths.set_option_value('more', false, {})
start_prompt()
screen:expect([[
|
@@ -362,7 +363,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
- eq('', meths.exec('messages', true))
+ eq('', exec_capture('messages'))
end)
it('silences :echon', function()
set_color_cb('Echoning')
@@ -377,7 +378,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
- eq('', meths.exec('messages', true))
+ eq('', exec_capture('messages'))
end)
it('silences :echomsg', function()
set_color_cb('Echomsging')
@@ -392,7 +393,7 @@ describe('Command-line coloring', function()
{EOB:~ }|
:e^ |
]])
- eq('', meths.exec('messages', true))
+ eq('', exec_capture('messages'))
end)
it('does the right thing when throwing', function()
set_color_cb('Throwing')
@@ -576,10 +577,10 @@ describe('Command-line coloring', function()
|
{EOB:~ }|
{EOB:~ }|
+ {EOB:~ }|
{MSEP: }|
:+ |
{ERR:E5404: Chunk 1 end 3 not in range (1, 2]}|
- |
:++^ |
]])
end)
@@ -853,12 +854,12 @@ describe('Ex commands coloring', function()
:# |
{ERR:Error detected while processing :} |
{ERR:E605: Exception not caught: 42} |
- {ERR:E749: empty buffer} |
+ {ERR:E749: Empty buffer} |
{PE:Press ENTER or type command to continue}^ |
]])
feed('<CR>')
- eq('Error detected while processing :\nE605: Exception not caught: 42\nE749: empty buffer',
- meths.exec('messages', true))
+ eq('Error detected while processing :\nE605: Exception not caught: 42\nE749: Empty buffer',
+ exec_capture('messages'))
end)
it('errors out when failing to get callback', function()
meths.set_var('Nvim_color_cmdline', 42)
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua
index 1c9ac7f7ba..188b9ee87b 100644
--- a/test/functional/ui/cmdline_spec.lua
+++ b/test/functional/ui/cmdline_spec.lua
@@ -24,6 +24,7 @@ local function new_screen(opt)
[7] = {bold = true, foreground = Screen.colors.Brown},
[8] = {background = Screen.colors.LightGrey},
[9] = {bold = true},
+ [10] = {background = Screen.colors.Yellow1};
})
return screen
end
@@ -316,7 +317,7 @@ local function test_cmdline(linegrid)
screen:expect{grid=[[
|
{2:[No Name] }|
- {1::}make^ |
+ {1::}mak^e |
{3:[Command Line] }|
|
]]}
@@ -326,7 +327,7 @@ local function test_cmdline(linegrid)
screen:expect{grid=[[
|
{2:[No Name] }|
- {1::}make^ |
+ {1::}mak^e |
{3:[Command Line] }|
|
]], cmdline={nil, {
@@ -339,7 +340,7 @@ local function test_cmdline(linegrid)
screen:expect{grid=[[
|
{2:[No Name] }|
- {1::}make^ |
+ {1::}mak^e |
{3:[Command Line] }|
|
]], cmdline={nil, {
@@ -352,7 +353,7 @@ local function test_cmdline(linegrid)
screen:expect{grid=[[
|
{2:[No Name] }|
- {1::}make^ |
+ {1::}mak^e |
{3:[Command Line] }|
|
]]}
@@ -771,6 +772,84 @@ describe('cmdline redraw', function()
:^abc |
]])
end)
+
+ it('with rightleftcmd', function()
+ command('set rightleft rightleftcmd=search shortmess+=s')
+ meths.buf_set_lines(0, 0, -1, true, {"let's rock!"})
+ screen:expect{grid=[[
+ !kcor s'te^l|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ |
+ ]]}
+
+ feed '/'
+ screen:expect{grid=[[
+ !kcor s'tel|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^ /|
+ ]]}
+
+ feed "let's"
+ -- note: cursor looks off but looks alright in real use
+ -- when rendered as a block so it touches the end of the text
+ screen:expect{grid=[[
+ !kcor {2:s'tel}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^ s'tel/|
+ ]]}
+
+ -- cursor movement
+ feed "<space>"
+ screen:expect{grid=[[
+ !kcor{2: s'tel}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^ s'tel/|
+ ]]}
+
+ feed "rock"
+ screen:expect{grid=[[
+ !{2:kcor s'tel}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^ kcor s'tel/|
+ ]]}
+
+ feed "<right>"
+ screen:expect{grid=[[
+ !{2:kcor s'tel}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^kcor s'tel/|
+ ]]}
+
+ feed "<left>"
+ screen:expect{grid=[[
+ !{2:kcor s'tel}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ^ kcor s'tel/|
+ ]]}
+
+ feed "<cr>"
+ screen:expect{grid=[[
+ !{10:kcor s'te^l}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ kcor s'tel/ |
+ ]]}
+ end)
end)
describe('statusline is redrawn on entering cmdline', function()
@@ -944,15 +1023,64 @@ describe('statusline is redrawn on entering cmdline', function()
end)
end)
+it('tabline is not redrawn in Ex mode #24122', function()
+ clear()
+ local screen = Screen.new(60, 5)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {bold = true, reverse = true}, -- MsgSeparator
+ [2] = {reverse = true}, -- TabLineFill
+ })
+ screen:attach()
+
+ exec([[
+ set showtabline=2
+ set tabline=%!MyTabLine()
+
+ function! MyTabLine()
+
+ return "foo"
+ endfunction
+ ]])
+
+ feed('gQ')
+ screen:expect{grid=[[
+ {2:foo }|
+ |
+ {1: }|
+ Entering Ex mode. Type "visual" to go to Normal mode. |
+ :^ |
+ ]]}
+
+ feed('echo 1<CR>')
+ screen:expect{grid=[[
+ {1: }|
+ Entering Ex mode. Type "visual" to go to Normal mode. |
+ :echo 1 |
+ 1 |
+ :^ |
+ ]]}
+end)
+
describe("cmdline height", function()
+ before_each(clear)
+
it("does not crash resized screen #14263", function()
- clear()
local screen = Screen.new(25, 10)
screen:attach()
command('set cmdheight=9999')
screen:try_resize(25, 5)
assert_alive()
end)
+
+ it('unchanged when restoring window sizes with global statusline', function()
+ command('set cmdheight=2 laststatus=2')
+ feed('q:')
+ command('set cmdheight=1 laststatus=3 | quit')
+ -- Available lines changed, so closing cmdwin should skip restoring window sizes, leaving the
+ -- cmdheight unchanged.
+ eq(1, eval('&cmdheight'))
+ end)
end)
describe('cmdheight=0', function()
@@ -972,6 +1100,26 @@ describe('cmdheight=0', function()
screen:attach()
end)
+ it("with redrawdebug=invalid resize -1", function()
+ command("set redrawdebug=invalid cmdheight=0 noruler laststatus=0")
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ feed(":resize -1<CR>")
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+
it("with cmdheight=1 noruler laststatus=2", function()
command("set cmdheight=1 noruler laststatus=2")
screen:expect{grid=[[
@@ -1226,6 +1374,7 @@ describe('cmdheight=0', function()
it('with multigrid', function()
clear{args={'--cmd', 'set cmdheight=0'}}
screen:attach{ext_multigrid=true}
+ meths.buf_set_lines(0, 0, -1, true, {'p'})
screen:expect{grid=[[
## grid 1
[2:-------------------------]|
@@ -1234,14 +1383,14 @@ describe('cmdheight=0', function()
[2:-------------------------]|
[2:-------------------------]|
## grid 2
- ^ |
+ ^p |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
feed '/p'
@@ -1253,7 +1402,7 @@ describe('cmdheight=0', function()
[2:-------------------------]|
[3:-------------------------]|
## grid 2
- |
+ {6:p} |
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1261,7 +1410,7 @@ describe('cmdheight=0', function()
## grid 3
/p^ |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
end)
@@ -1378,7 +1527,21 @@ describe('cmdheight=0', function()
|
]])
command('set cmdheight=0')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ ]]}
command('resize -1')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ |
+ ]]}
command('resize +1')
screen:expect([[
^ |
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
index e261f0dfab..05057ca080 100644
--- a/test/functional/ui/cursor_spec.lua
+++ b/test/functional/ui/cursor_spec.lua
@@ -212,10 +212,10 @@ describe('ui/cursor', function()
if m.blinkwait then m.blinkwait = 700 end
end
if m.hl_id then
- m.hl_id = 60
+ m.hl_id = 64
m.attr = {background = Screen.colors.DarkGray}
end
- if m.id_lm then m.id_lm = 62 end
+ if m.id_lm then m.id_lm = 67 end
end
-- Assert the new expectation.
@@ -265,8 +265,8 @@ describe('ui/cursor', function()
}
-- Another cursor style.
- meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173'
- ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42')
+ meths.set_option_value('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173'
+ ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42', {})
screen:expect(function()
local named = {}
for _, m in ipairs(screen._mode_info) do
@@ -288,7 +288,7 @@ describe('ui/cursor', function()
end)
-- If there is no setting for guicursor, it becomes the default setting.
- meths.set_option('guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor')
+ meths.set_option_value('guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor', {})
screen:expect(function()
for _,m in ipairs(screen._mode_info) do
if m.name ~= 'normal' then
@@ -304,7 +304,7 @@ describe('ui/cursor', function()
end)
it("empty 'guicursor' sets cursor_shape=block in all modes", function()
- meths.set_option('guicursor', '')
+ meths.set_option_value('guicursor', '', {})
screen:expect(function()
-- Empty 'guicursor' sets enabled=false.
eq(false, screen._cursor_style_enabled)
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 489c33d8b1..e8fcfc46fc 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -8,7 +8,12 @@ local exec_lua = helpers.exec_lua
local exec = helpers.exec
local expect_events = helpers.expect_events
local meths = helpers.meths
+local funcs = helpers.funcs
+local curbufmeths = helpers.curbufmeths
local command = helpers.command
+local eq = helpers.eq
+local assert_alive = helpers.assert_alive
+local pcall_err = helpers.pcall_err
describe('decorations providers', function()
local screen
@@ -31,8 +36,10 @@ describe('decorations providers', function()
[12] = {foreground = tonumber('0x990000')};
[13] = {background = Screen.colors.LightBlue};
[14] = {background = Screen.colors.WebGray, foreground = Screen.colors.DarkBlue};
- [15] = {special = Screen.colors.Blue1, undercurl = true},
+ [15] = {special = Screen.colors.Blue, undercurl = true},
[16] = {special = Screen.colors.Red, undercurl = true},
+ [17] = {foreground = Screen.colors.Red},
+ [18] = {bold = true, foreground = Screen.colors.SeaGreen};
}
end)
@@ -47,15 +54,15 @@ describe('decorations providers', function()
local function setup_provider(code)
return exec_lua ([[
- local a = vim.api
- _G.ns1 = a.nvim_create_namespace "ns1"
+ local api = vim.api
+ _G.ns1 = api.nvim_create_namespace "ns1"
]] .. (code or [[
beamtrace = {}
local function on_do(kind, ...)
table.insert(beamtrace, {kind, ...})
end
]]) .. [[
- a.nvim_set_decoration_provider(_G.ns1, {
+ api.nvim_set_decoration_provider(_G.ns1, {
on_start = on_do; on_buf = on_do;
on_win = on_do; on_line = on_do;
on_end = on_do; _on_spell_nav = on_do;
@@ -75,10 +82,10 @@ describe('decorations providers', function()
-- rather than append, which used to spin in an infinite loop allocating
-- memory until nvim crashed/was killed.
setup_provider([[
- local ns2 = a.nvim_create_namespace "ns2"
- a.nvim_set_decoration_provider(ns2, {})
+ local ns2 = api.nvim_create_namespace "ns2"
+ api.nvim_set_decoration_provider(ns2, {})
]])
- helpers.assert_alive()
+ assert_alive()
end)
it('leave a trace', function()
@@ -98,7 +105,7 @@ describe('decorations providers', function()
]]}
check_trace {
{ "start", 4 };
- { "win", 1000, 1, 0, 8 };
+ { "win", 1000, 1, 0, 6 };
{ "line", 1000, 1, 0 };
{ "line", 1000, 1, 1 };
{ "line", 1000, 1, 2 };
@@ -122,8 +129,8 @@ describe('decorations providers', function()
]]}
check_trace {
{ "start", 5 };
- { "buf", 1 };
- { "win", 1000, 1, 0, 8 };
+ { "buf", 1, 5 };
+ { "win", 1000, 1, 0, 6 };
{ "line", 1000, 1, 6 };
{ "end", 5 };
}
@@ -132,12 +139,12 @@ describe('decorations providers', function()
it('can have single provider', function()
insert(mulholland)
setup_provider [[
- local hl = a.nvim_get_hl_id_by_name "ErrorMsg"
- local test_ns = a.nvim_create_namespace "mulholland"
+ local hl = api.nvim_get_hl_id_by_name "ErrorMsg"
+ local test_ns = api.nvim_create_namespace "mulholland"
function on_do(event, ...)
if event == "line" then
local win, buf, line = ...
- a.nvim_buf_set_extmark(buf, test_ns, line, line,
+ api.nvim_buf_set_extmark(buf, test_ns, line, line,
{ end_line = line, end_col = line+1,
hl_group = hl,
ephemeral = true
@@ -172,11 +179,11 @@ describe('decorations providers', function()
]]
setup_provider [[
- local ns = a.nvim_create_namespace "spell"
+ local ns = api.nvim_create_namespace "spell"
beamtrace = {}
local function on_do(kind, ...)
if kind == 'win' or kind == 'spell' then
- a.nvim_buf_set_extmark(0, ns, 0, 0, {
+ api.nvim_buf_set_extmark(0, ns, 0, 0, {
end_row = 2,
end_col = 23,
spell = true,
@@ -190,7 +197,7 @@ describe('decorations providers', function()
check_trace {
{ "start", 5 };
- { "win", 1000, 1, 0, 5 };
+ { "win", 1000, 1, 0, 3 };
{ "line", 1000, 1, 0 };
{ "line", 1000, 1, 1 };
{ "line", 1000, 1, 2 };
@@ -201,14 +208,14 @@ describe('decorations providers', function()
feed "gg0"
screen:expect{grid=[[
- ^I am well written text. |
- {15:i} am not capitalized. |
- I am a {16:speling} {16:mistakke}. |
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ ^I am well written text. |
+ {15:i} am not capitalized. |
+ I am a {16:speling} {16:mistakke}. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]]}
feed "]s"
@@ -216,14 +223,14 @@ describe('decorations providers', function()
{ "spell", 1000, 1, 1, 0, 1, -1 };
}
screen:expect{grid=[[
- I am well written text. |
- {15:^i} am not capitalized. |
- I am a {16:speling} {16:mistakke}. |
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ I am well written text. |
+ {15:^i} am not capitalized. |
+ I am a {16:speling} {16:mistakke}. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]]}
feed "]s"
@@ -231,43 +238,68 @@ describe('decorations providers', function()
{ "spell", 1000, 1, 2, 7, 2, -1 };
}
screen:expect{grid=[[
- I am well written text. |
- {15:i} am not capitalized. |
- I am a {16:^speling} {16:mistakke}. |
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ I am well written text. |
+ {15:i} am not capitalized. |
+ I am a {16:^speling} {16:mistakke}. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]]}
- -- spell=false with lower priority doesn't disable spell
+ -- spell=false with higher priority does disable spell
local ns = meths.create_namespace "spell"
- local id = helpers.curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false })
+ local id = curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false })
screen:expect{grid=[[
- I am well written text. |
- i am not capitalized. |
- I am a ^speling mistakke. |
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ I am well written text. |
+ i am not capitalized. |
+ I am a ^speling mistakke. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]]}
- -- spell=false with higher priority does disable spell
- helpers.curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false })
+ feed "]s"
+ screen:expect{grid=[[
+ I am well written text. |
+ i am not capitalized. |
+ I am a ^speling mistakke. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {17:search hit BOTTOM, continuing at TOP} |
+ ]]}
+ command('echo ""')
+
+ -- spell=false with lower priority doesn't disable spell
+ curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false })
screen:expect{grid=[[
- I am well written text. |
- {15:i} am not capitalized. |
- I am a {16:^speling} {16:mistakke}. |
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ I am well written text. |
+ {15:i} am not capitalized. |
+ I am a {16:^speling} {16:mistakke}. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ feed "]s"
+ screen:expect{grid=[[
+ I am well written text. |
+ {15:i} am not capitalized. |
+ I am a {16:speling} {16:^mistakke}. |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]]}
end)
@@ -330,12 +362,12 @@ describe('decorations providers', function()
]]}
exec_lua [[
- local a = vim.api
- local thewin = a.nvim_get_current_win()
- local ns2 = a.nvim_create_namespace 'ns2'
- a.nvim_set_decoration_provider (ns2, {
+ local api = vim.api
+ local thewin = api.nvim_get_current_win()
+ local ns2 = api.nvim_create_namespace 'ns2'
+ api.nvim_set_decoration_provider (ns2, {
on_win = function (_, win, buf)
- a.nvim_set_hl_ns_fast(win == thewin and _G.ns1 or ns2)
+ api.nvim_set_hl_ns_fast(win == thewin and _G.ns1 or ns2)
end;
})
]]
@@ -436,12 +468,12 @@ describe('decorations providers', function()
it('can have virtual text', function()
insert(mulholland)
setup_provider [[
- local hl = a.nvim_get_hl_id_by_name "ErrorMsg"
- local test_ns = a.nvim_create_namespace "mulholland"
+ local hl = api.nvim_get_hl_id_by_name "ErrorMsg"
+ local test_ns = api.nvim_create_namespace "mulholland"
function on_do(event, ...)
if event == "line" then
local win, buf, line = ...
- a.nvim_buf_set_extmark(buf, test_ns, line, 0, {
+ api.nvim_buf_set_extmark(buf, test_ns, line, 0, {
virt_text = {{'+', 'ErrorMsg'}};
virt_text_pos='overlay';
ephemeral = true;
@@ -465,12 +497,12 @@ describe('decorations providers', function()
it('can have virtual text of the style: right_align', function()
insert(mulholland)
setup_provider [[
- local hl = a.nvim_get_hl_id_by_name "ErrorMsg"
- local test_ns = a.nvim_create_namespace "mulholland"
+ local hl = api.nvim_get_hl_id_by_name "ErrorMsg"
+ local test_ns = api.nvim_create_namespace "mulholland"
function on_do(event, ...)
if event == "line" then
local win, buf, line = ...
- a.nvim_buf_set_extmark(buf, test_ns, line, 0, {
+ api.nvim_buf_set_extmark(buf, test_ns, line, 0, {
virt_text = {{'+'}, {string.rep(' ', line+1), 'ErrorMsg'}};
virt_text_pos='right_align';
ephemeral = true;
@@ -491,15 +523,81 @@ describe('decorations providers', function()
]]}
end)
+ it('virtual text works with wrapped lines', function()
+ insert(mulholland)
+ feed('ggJj3JjJ')
+ setup_provider [[
+ local hl = api.nvim_get_hl_id_by_name "ErrorMsg"
+ local test_ns = api.nvim_create_namespace "mulholland"
+ function on_do(event, ...)
+ if event == "line" then
+ local win, buf, line = ...
+ api.nvim_buf_set_extmark(buf, test_ns, line, 0, {
+ virt_text = {{string.rep('/', line+1), 'ErrorMsg'}};
+ virt_text_pos='eol';
+ ephemeral = true;
+ })
+ api.nvim_buf_set_extmark(buf, test_ns, line, 6, {
+ virt_text = {{string.rep('*', line+1), 'ErrorMsg'}};
+ virt_text_pos='overlay';
+ ephemeral = true;
+ })
+ api.nvim_buf_set_extmark(buf, test_ns, line, 39, {
+ virt_text = {{string.rep('!', line+1), 'ErrorMsg'}};
+ virt_text_win_col=20;
+ ephemeral = true;
+ })
+ api.nvim_buf_set_extmark(buf, test_ns, line, 40, {
+ virt_text = {{string.rep('?', line+1), 'ErrorMsg'}};
+ virt_text_win_col=10;
+ ephemeral = true;
+ })
+ api.nvim_buf_set_extmark(buf, test_ns, line, 40, {
+ virt_text = {{string.rep(';', line+1), 'ErrorMsg'}};
+ virt_text_pos='overlay';
+ ephemeral = true;
+ })
+ api.nvim_buf_set_extmark(buf, test_ns, line, 40, {
+ virt_text = {{'+'}, {string.rep(' ', line+1), 'ErrorMsg'}};
+ virt_text_pos='right_align';
+ ephemeral = true;
+ })
+ end
+ end
+ ]]
+
+ screen:expect{grid=[[
+ // jus{2:*} to see if th{2:!}re was an accident |
+ {2:;}n Mulholl{2:?}nd Drive {2:/} +{2: }|
+ try_st{2:**}t(); bufref_{2:!!}save_buf; switch_b|
+ {2:;;}fer(&sav{2:??}buf, buf); {2://} +{2: }|
+ posp ={2:***}tmark(mark,{2:!!!}lse);^ restore_buf|
+ {2:;;;}(&save_{2:???}); {2:///} +{2: }|
+ {1:~ }|
+ |
+ ]]}
+ command('setlocal breakindent breakindentopt=shift:2')
+ screen:expect{grid=[[
+ // jus{2:*} to see if th{2:!}re was an accident |
+ {2:;}n Mulho{2:?}land Drive {2:/} +{2: }|
+ try_st{2:**}t(); bufref_{2:!!}save_buf; switch_b|
+ {2:;;}fer(&s{2:??}e_buf, buf); {2://} +{2: }|
+ posp ={2:***}tmark(mark,{2:!!!}lse);^ restore_buf|
+ {2:;;;}(&sav{2:???}uf); {2:///} +{2: }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
it('can highlight beyond EOL', function()
insert(mulholland)
setup_provider [[
- local test_ns = a.nvim_create_namespace "veberod"
+ local test_ns = api.nvim_create_namespace "veberod"
function on_do(event, ...)
if event == "line" then
local win, buf, line = ...
- if string.find(a.nvim_buf_get_lines(buf, line, line+1, true)[1], "buf") then
- a.nvim_buf_set_extmark(buf, test_ns, line, 0, {
+ if string.find(api.nvim_buf_get_lines(buf, line, line+1, true)[1], "buf") then
+ api.nvim_buf_set_extmark(buf, test_ns, line, 0, {
end_line = line+1;
hl_group = 'DiffAdd';
hl_eol = true;
@@ -534,9 +632,9 @@ describe('decorations providers', function()
local function on_do(kind, winid, bufnr, topline, botline_guess)
if kind == 'win' then
if topline < 100 and botline_guess > 100 then
- vim.api.nvim_buf_set_extmark(bufnr, ns1, 99, -1, { sign_text = 'X' })
+ api.nvim_buf_set_extmark(bufnr, ns1, 99, -1, { sign_text = 'X' })
else
- vim.api.nvim_buf_clear_namespace(bufnr, ns1, 0, -1)
+ api.nvim_buf_clear_namespace(bufnr, ns1, 0, -1)
end
end
end
@@ -565,8 +663,60 @@ describe('decorations providers', function()
|
]])
end)
+
+ it('does allow removing extmarks during on_line callbacks', function()
+ exec_lua([[
+ eok = true
+ ]])
+ setup_provider([[
+ local function on_do(kind, winid, bufnr, topline, botline_guess)
+ if kind == 'line' then
+ api.nvim_buf_set_extmark(bufnr, ns1, 1, -1, { sign_text = 'X' })
+ eok = pcall(api.nvim_buf_clear_namespace, bufnr, ns1, 0, -1)
+ end
+ end
+ ]])
+ exec_lua([[
+ assert(eok == true)
+ ]])
+ end)
+
+ it('errors gracefully', function()
+ insert(mulholland)
+
+ setup_provider [[
+ function on_do(...)
+ error "Foo"
+ end
+ ]]
+
+ screen:expect{grid=[[
+ {2:Error in decoration provider ns1.start:} |
+ {2:Error executing lua: [string "<nvim>"]:4}|
+ {2:: Foo} |
+ {2:stack traceback:} |
+ {2: [C]: in function 'error'} |
+ {2: [string "<nvim>"]:4: in function}|
+ {2: <[string "<nvim>"]:3>} |
+ {18:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
end)
+local example_text = [[
+for _,item in ipairs(items) do
+ local text, hl_id_cell, count = unpack(item)
+ if hl_id_cell ~= nil then
+ hl_id = hl_id_cell
+ end
+ for _ = 1, (count or 1) do
+ local cell = line[colpos]
+ cell.text = text
+ cell.hl_id = hl_id
+ colpos = colpos+1
+ end
+end]]
+
describe('extmark decorations', function()
local screen, ns
before_each( function()
@@ -592,7 +742,7 @@ describe('extmark decorations', function()
[16] = {blend = 30, background = Screen.colors.Red1, foreground = Screen.colors.Magenta1};
[17] = {bold = true, foreground = Screen.colors.Brown, background = Screen.colors.LightGrey};
[18] = {background = Screen.colors.LightGrey};
- [19] = {foreground = Screen.colors.Cyan4, background = Screen.colors.LightGrey};
+ [19] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGrey};
[20] = {foreground = tonumber('0x180606'), background = tonumber('0xf13f3f')};
[21] = {foreground = Screen.colors.Gray0, background = tonumber('0xf13f3f')};
[22] = {foreground = tonumber('0xb20000'), background = tonumber('0xf13f3f')};
@@ -601,25 +751,25 @@ describe('extmark decorations', function()
[25] = {background = Screen.colors.LightRed};
[26] = {background=Screen.colors.DarkGrey, foreground=Screen.colors.LightGrey};
[27] = {background = Screen.colors.Plum1};
+ [28] = {underline = true, foreground = Screen.colors.SlateBlue};
+ [29] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightGray, underline = true};
+ [30] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGray, underline = true};
+ [31] = {underline = true, foreground = Screen.colors.DarkCyan};
+ [32] = {underline = true};
+ [33] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray};
+ [34] = {background = Screen.colors.Yellow};
+ [35] = {background = Screen.colors.Yellow, bold = true, foreground = Screen.colors.Blue};
+ [36] = {foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.Red};
+ [37] = {background = Screen.colors.WebGray, foreground = Screen.colors.DarkBlue};
+ [38] = {background = Screen.colors.LightBlue};
+ [39] = {foreground = Screen.colors.Blue1, background = Screen.colors.LightCyan1, bold = true};
+ [40] = {reverse = true};
+ [41] = {bold = true, reverse = true};
}
ns = meths.create_namespace 'test'
end)
- local example_text = [[
-for _,item in ipairs(items) do
- local text, hl_id_cell, count = unpack(item)
- if hl_id_cell ~= nil then
- hl_id = hl_id_cell
- end
- for _ = 1, (count or 1) do
- local cell = line[colpos]
- cell.text = text
- cell.hl_id = hl_id
- colpos = colpos+1
- end
-end]]
-
it('empty virtual text at eol should not break colorcolumn #17860', function()
insert(example_text)
feed('gg')
@@ -660,14 +810,14 @@ end]]
-- can "float" beyond end of line
meths.buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'})
-- bound check: right edge of window
- meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork '}, {'bork bork bork', 'ErrorMsg'}}, virt_text_pos='overlay'})
+ meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork'}, {(' bork'):rep(10), 'ErrorMsg'}}, virt_text_pos='overlay'})
-- empty virt_text should not change anything
meths.buf_set_extmark(0, ns, 6, 16, { virt_text={{''}}, virt_text_pos='overlay'})
screen:expect{grid=[[
^for _,item in ipairs(items) do |
{2:|} local text, hl_id_cell, count = unpack(item) |
- {2:|} if hl_id_cell ~= nil tbork bork bork {4:bork bork}|
+ {2:|} if hl_id_cell ~= nil tbork bork bork{4: bork bork}|
{2:|} {1:|} hl_id = hl_id_cell |
{2:|} end |
{2:|} for _ = 1, (count or 1) {4:loopy} |
@@ -682,7 +832,6 @@ end]]
|
]]}
-
-- handles broken lines
screen:try_resize(22, 25)
screen:expect{grid=[[
@@ -692,7 +841,7 @@ end]]
cell, count = unpack(i|
tem) |
{2:|} if hl_id_cell ~= n|
- il tbork bork bork {4:bor}|
+ il tbork bork bork{4: bor}|
{2:|} {1:|} hl_id = hl_id_|
cell |
{2:|} end |
@@ -712,6 +861,248 @@ end]]
{1:~ }|
|
]]}
+
+ -- truncating in the middle of a char leaves a space
+ meths.buf_set_lines(0, 0, 1, true, {'for _,item in ipairs(items) do -- 古古古'})
+ meths.buf_set_lines(0, 10, 12, true, {' end -- ??????????', 'end -- ?古古古古?古古'})
+ meths.buf_set_extmark(0, ns, 0, 35, { virt_text={{'A', 'ErrorMsg'}, {'AA'}}, virt_text_pos='overlay'})
+ meths.buf_set_extmark(0, ns, 10, 19, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'})
+ meths.buf_set_extmark(0, ns, 11, 21, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'})
+ meths.buf_set_extmark(0, ns, 11, 8, { virt_text={{'口口', 'ErrorMsg'}}, virt_text_pos='overlay'})
+ screen:expect{grid=[[
+ ^for _,item in ipairs(i|
+ tems) do -- {4:A}AA 古 |
+ {2:|} local text, hl_id_|
+ cell, count = unpack(i|
+ tem) |
+ {2:|} if hl_id_cell ~= n|
+ il tbork bork bork{4: bor}|
+ {2:|} {1:|} hl_id = hl_id_|
+ cell |
+ {2:|} end |
+ {2:|} for _ = 1, (count |
+ or 1) {4:loopy} |
+ {2:|} {1:|} local cell = l|
+ ine[colpos] |
+ {2:|} {1:|} cell.text = te|
+ xt |
+ {2:|} {1:|} cell.hl_id = h|
+ l_id |
+ {2:|} {1:|} cofoo{3:bar}{4:!!}olpo|
+ s+1 |
+ end -- ???????{4:口 }|
+ end -- {4:口口} 古古{4:口口 }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ screen:try_resize(82, 13)
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do -- {4:A}AA 古 |
+ {2:|} local text, hl_id_cell, count = unpack(item) |
+ {2:|} if hl_id_cell ~= nil tbork bork bork{4: bork bork bork bork bork bork bork bork b}|
+ {2:|} {1:|} hl_id = hl_id_cell |
+ {2:|} end |
+ {2:|} for _ = 1, (count or 1) {4:loopy} |
+ {2:|} {1:|} local cell = line[colpos] |
+ {2:|} {1:|} cell.text = text |
+ {2:|} {1:|} cell.hl_id = hl_id |
+ {2:|} {1:|} cofoo{3:bar}{4:!!}olpos+1 |
+ end -- ???????{4:口口口} |
+ end -- {4:口口} 古古{4:口口口} |
+ |
+ ]]}
+
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do -- 古古古 |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end -- ?????????? |
+ end -- ?古古古古?古古 |
+ |
+ ]]}
+ end)
+
+ it('overlay virtual text works with wrapped lines #25158', function()
+ screen:try_resize(50, 6)
+ insert(('ab'):rep(100))
+ for i = 0, 9 do
+ meths.buf_set_extmark(0, ns, 0, 42 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay'})
+ meths.buf_set_extmark(0, ns, 0, 91 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true})
+ end
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {4:89}abababababababababababababababababababa{4:012345678}|
+ {4:9}babababababababababababababababababababababababab|
+ ababababababababababababababababababababababababa^b|
+ {1:~ }|
+ |
+ ]]}
+
+ command('set showbreak=++')
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {1:++}{4:89}abababababababababababababababababababa{4:0123456}|
+ {1:++}{4:789}babababababababababababababababababababababab|
+ {1:++}abababababababababababababababababababababababab|
+ {1:++}ababa^b |
+ |
+ ]]}
+
+ feed('2gkvg0')
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {1:++}{4:89}abababababababababababababababababababa{4:0123456}|
+ {1:++}^a{18:babab}ababababababababababababababababababababab|
+ {1:++}abababababababababababababababababababababababab|
+ {1:++}ababab |
+ {24:-- VISUAL --} |
+ ]]}
+
+ feed('o')
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {1:++}{4:89}abababababababababababababababababababa{4:0123456}|
+ {1:++}{18:ababa}^bababababababababababababababababababababab|
+ {1:++}abababababababababababababababababababababababab|
+ {1:++}ababab |
+ {24:-- VISUAL --} |
+ ]]}
+
+ feed('gk')
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {1:++}{4:89}aba^b{18:ababababababababababababababababababababab}|
+ {1:++}{18:a}{4:89}babababababababababababababababababababababab|
+ {1:++}abababababababababababababababababababababababab|
+ {1:++}ababab |
+ {24:-- VISUAL --} |
+ ]]}
+
+ feed('o')
+ screen:expect{grid=[[
+ ababababababababababababababababababababab{4:01234567}|
+ {1:++}{4:89}aba{18:bababababababababababababababababababababab}|
+ {1:++}^a{4:89}babababababababababababababababababababababab|
+ {1:++}abababababababababababababababababababababababab|
+ {1:++}ababab |
+ {24:-- VISUAL --} |
+ ]]}
+
+ feed('<Esc>$')
+ command('set number showbreak=')
+ screen:expect{grid=[[
+ {2: 1 }ababababababababababababababababababababab{4:0123}|
+ {2: }{4:456789}abababababababababababababababababababa{4:0}|
+ {2: }{4:123456789}babababababababababababababababababab|
+ {2: }ababababababababababababababababababababababab|
+ {2: }abababababababa^b |
+ |
+ ]]}
+
+ command('set cpoptions+=n')
+ screen:expect{grid=[[
+ {2: 1 }ababababababababababababababababababababab{4:0123}|
+ {4:456789}abababababababababababababababababababa{4:01234}|
+ {4:56789}babababababababababababababababababababababab|
+ ababababababababababababababababababababababababab|
+ aba^b |
+ |
+ ]]}
+
+ feed('0g$hi<Tab>')
+ screen:expect{grid=[[
+ {2: 1 }ababababababababababababababababababababab{4:01} |
+ {4:^23456789}abababababababababababababababababababa{4:0}|
+ {4:123456789}babababababababababababababababababababab|
+ ababababababababababababababababababababababababab|
+ abababab |
+ {24:-- INSERT --} |
+ ]]}
+ end)
+
+ it('virt_text_hide hides overlay virtual text when extmark is off-screen', function()
+ screen:try_resize(50, 3)
+ command('set nowrap')
+ meths.buf_set_lines(0, 0, -1, true, {'-- ' .. ('…'):rep(57)})
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text={{'?????', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true})
+ meths.buf_set_extmark(0, ns, 0, 123, { virt_text={{'!!!!!', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true})
+ screen:expect{grid=[[
+ {4:^?????}……………………………………………………………………………………………………{4:!!!!!}……|
+ {1:~ }|
+ |
+ ]]}
+ feed('40zl')
+ screen:expect{grid=[[
+ ^………{4:!!!!!}……………………………… |
+ {1:~ }|
+ |
+ ]]}
+ feed('3zl')
+ screen:expect{grid=[[
+ {4:^!!!!!}……………………………… |
+ {1:~ }|
+ |
+ ]]}
+ feed('7zl')
+ screen:expect{grid=[[
+ ^………………………… |
+ {1:~ }|
+ |
+ ]]}
+
+ command('set wrap smoothscroll')
+ screen:expect{grid=[[
+ {4:?????}……………………………………………………………………………………………………{4:!!!!!}……|
+ ^………………………… |
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}………………^… |
+ {1:~ }|
+ |
+ ]]}
+ screen:try_resize(40, 3)
+ screen:expect{grid=[[
+ {1:<<<}{4:!!!!!}……………………………^… |
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-Y>')
+ screen:expect{grid=[[
+ {4:?????}……………………………………………………………………………………………|
+ ………{4:!!!!!}……………………………^… |
+ |
+ ]]}
+ end)
+
+ it('overlay virtual text works on and after a TAB #24022', function()
+ screen:try_resize(40, 3)
+ meths.buf_set_lines(0, 0, -1, true, {'\t\tline 1'})
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 0, 1, { virt_text = {{'BB', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' })
+ screen:expect{grid=[[
+ {34:AA} ^ {34:BB} {34:CC}ne 1 |
+ {1:~ }|
+ |
+ ]]}
+ command('setlocal list listchars=tab:<->')
+ screen:expect{grid=[[
+ {35:^AA}{1:----->}{35:BB}{1:----->}{34:CC}ne 1 |
+ {1:~ }|
+ |
+ ]]}
end)
it('can have virtual text of overlay position and styling', function()
@@ -805,25 +1196,30 @@ end]]
]]}
end)
- it('can have virtual text of fixed win_col position', function()
+ it('can have virtual text of right_align and fixed win_col position', function()
insert(example_text)
feed 'gg'
- meths.buf_set_extmark(0, ns, 1, 0, { virt_text={{'Very', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
- meths.buf_set_extmark(0, ns, 2, 10, { virt_text={{'Much', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
- meths.buf_set_extmark(0, ns, 3, 15, { virt_text={{'Error', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 1, 0, { virt_text={{'Very', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 1, 0, { virt_text={{'VERY', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 2, 10, { virt_text={{'Much', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 2, 10, { virt_text={{'MUCH', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 3, 14, { virt_text={{'Error', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 3, 14, { virt_text={{'ERROR', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'})
meths.buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_win_col=4, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_pos='right_align', hl_mode='blend'})
-- empty virt_text should not change anything
meths.buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_win_col=14, hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_pos='right_align', hl_mode='blend'})
screen:expect{grid=[[
^for _,item in ipairs(items) do |
- local text, hl_id_cell, cou{4:Very} unpack(item) |
- if hl_id_cell ~= nil then {4:Much} |
- hl_id = hl_id_cell {4:Error} |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ hl_id = hl_id_cell {4:Error} {4:ERROR}|
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
- {1:-} cell.text = text |
+ {1:-} cell.text = text {1:-}|
cell.hl_id = hl_id |
colpos = colpos+1 |
end |
@@ -836,14 +1232,14 @@ end]]
feed '3G12|i<cr><esc>'
screen:expect{grid=[[
for _,item in ipairs(items) do |
- local text, hl_id_cell, cou{4:Very} unpack(item) |
- if hl_i {4:Much} |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if hl_i {4:Much} {4:MUCH}|
^d_cell ~= nil then |
- hl_id = hl_id_cell {4:Error} |
+ hl_id = hl_id_cell {4:Error} {4:ERROR}|
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
- {1:-} cell.text = text |
+ {1:-} cell.text = text {1:-}|
cell.hl_id = hl_id |
colpos = colpos+1 |
end |
@@ -855,13 +1251,13 @@ end]]
feed 'u:<cr>'
screen:expect{grid=[[
for _,item in ipairs(items) do |
- local text, hl_id_cell, cou{4:Very} unpack(item) |
- if hl_i^d_cell ~= nil then {4:Much} |
- hl_id = hl_id_cell {4:Error} |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if hl_i^d_cell ~= nil then {4:Much} {4:MUCH}|
+ hl_id = hl_id_cell {4:Error} {4:ERROR}|
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
- {1:-} cell.text = text |
+ {1:-} cell.text = text {1:-}|
cell.hl_id = hl_id |
colpos = colpos+1 |
end |
@@ -874,14 +1270,14 @@ end]]
feed '8|i<cr><esc>'
screen:expect{grid=[[
for _,item in ipairs(items) do |
- local text, hl_id_cell, cou{4:Very} unpack(item) |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
if |
- ^hl_id_cell ~= nil then {4:Much} |
- hl_id = hl_id_cell {4:Error} |
+ ^hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ hl_id = hl_id_cell {4:Error} {4:ERROR}|
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
- {1:-} cell.text = text |
+ {1:-} cell.text = text {1:-}|
cell.hl_id = hl_id |
colpos = colpos+1 |
end |
@@ -889,9 +1285,273 @@ end]]
{1:~ }|
|
]]}
+
+ feed 'jI-- <esc>..........'
+ screen:expect{grid=[[
+ for _,item in ipairs(items) do |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if |
+ hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ --^ -- -- -- -- -- -- --{4:Error}- -- hl_i{4:ERROR}|
+ l_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ {1:-} cell.text = text {1:-}|
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 4, 50, { virt_text={{'EOL', 'NonText'}} })
+ screen:expect{grid=[[
+ for _,item in ipairs(items) do |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if |
+ hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ --^ -- -- -- -- -- -- --{4:Error}- -- hl_i{4:ERROR}|
+ l_id_cell {1:EOL} |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ {1:-} cell.text = text {1:-}|
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ |
+ ]]}
+
+ feed '.'
+ screen:expect{grid=[[
+ for _,item in ipairs(items) do |
+ local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
+ if |
+ hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ --^ -- -- -- -- -- -- -- -- -- -- -- hl_id |
+ = hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ {1:-} cell.text = text {1:-}|
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ |
+ ]]}
+
+ command 'set number'
+ screen:expect{grid=[[
+ {2: 1 }for _,item in ipairs(items) do |
+ {2: 2 } local text, hl_id_cell, cou{4:Very} unpack{4:VERY}|
+ {2: }m) |
+ {2: 3 } if |
+ {2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ {2: 5 } --^ -- -- -- -- -- -- -- -- -- -- -- hl|
+ {2: }_id = hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
+ {2: 6 } end |
+ {2: 7 } for _ = 1, (count or 1) do |
+ {2: 8 } local cell = line[colpos] |
+ {2: 9 } {1:-} cell.text = text {1:-}|
+ {2: 10 } cell.hl_id = hl_id |
+ {2: 11 } colpos = colpos+1 |
+ {2: 12 } end |
+ |
+ ]]}
+
+ command 'set cpoptions+=n'
+ screen:expect{grid=[[
+ {2: 1 }for _,item in ipairs(items) do |
+ {2: 2 } local text, hl_id_cell, cou{4:Very} unpack{4:VERY}|
+ m) |
+ {2: 3 } if |
+ {2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ {2: 5 } --^ -- -- -- -- -- -- -- -- -- -- -- hl|
+ _id = hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
+ {2: 6 } end |
+ {2: 7 } for _ = 1, (count or 1) do |
+ {2: 8 } local cell = line[colpos] |
+ {2: 9 } {1:-} cell.text = text {1:-}|
+ {2: 10 } cell.hl_id = hl_id |
+ {2: 11 } colpos = colpos+1 |
+ {2: 12 } end |
+ |
+ ]]}
+
+ command 'set cpoptions-=n nowrap'
+ screen:expect{grid=[[
+ {2: 1 }for _,item in ipairs(items) do |
+ {2: 2 } local text, hl_id_cell, cou{4:Very} unpack{4:VERY}|
+ {2: 3 } if |
+ {2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ {2: 5 } --^ -- -- -- -- -- -- --{4:Error}- -- {4:ERROR}|
+ {2: 6 } end |
+ {2: 7 } for _ = 1, (count or 1) do |
+ {2: 8 } local cell = line[colpos] |
+ {2: 9 } {1:-} cell.text = text {1:-}|
+ {2: 10 } cell.hl_id = hl_id |
+ {2: 11 } colpos = colpos+1 |
+ {2: 12 } end |
+ {2: 13 }end |
+ {1:~ }|
+ |
+ ]]}
+
+ feed '12zl'
+ screen:expect{grid=[[
+ {2: 1 }n ipairs(items) do |
+ {2: 2 }xt, hl_id_cell, count = unpack({4:Very}) {4:VERY}|
+ {2: 3 } |
+ {2: 4 }= nil then {4:Much} {4:MUCH}|
+ {2: 5 }^- -- -- -- -- -- -- -- -- -- --{4:Error}d = h{4:ERROR}|
+ {2: 6 } |
+ {2: 7 }1, (count or 1) do |
+ {2: 8 }l cell = line[colpos] |
+ {2: 9 }.tex{1:-} = text {1:-}|
+ {2: 10 }.hl_id = hl_id |
+ {2: 11 }os = colpos+1 |
+ {2: 12 } |
+ {2: 13 } |
+ {1:~ }|
+ |
+ ]]}
+
+ feed('fhi<Tab>')
+ screen:expect{grid=[[
+ {2: 1 }n ipairs(items) do |
+ {2: 2 }xt, hl_id_cell, count = unpack({4:Very}) {4:VERY}|
+ {2: 3 } |
+ {2: 4 }= nil then {4:Much} {4:MUCH}|
+ {2: 5 }- -- -- -- -- -- -- -- -- -- --{4:Error}^hl_id{4:ERROR}|
+ {2: 6 } |
+ {2: 7 }1, (count or 1) do |
+ {2: 8 }l cell = line[colpos] |
+ {2: 9 }.tex{1:-} = text {1:-}|
+ {2: 10 }.hl_id = hl_id |
+ {2: 11 }os = colpos+1 |
+ {2: 12 } |
+ {2: 13 } |
+ {1:~ }|
+ {24:-- INSERT --} |
+ ]]}
+
+ feed('<Esc>0')
+ screen:expect{grid=[[
+ {2: 1 }for _,item in ipairs(items) do |
+ {2: 2 } local text, hl_id_cell, cou{4:Very} unpack{4:VERY}|
+ {2: 3 } if |
+ {2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
+ {2: 5 }^ -- -- -- -- -- -- -- --{4:Error}- -- {4:ERROR}|
+ {2: 6 } end |
+ {2: 7 } for _ = 1, (count or 1) do |
+ {2: 8 } local cell = line[colpos] |
+ {2: 9 } {1:-} cell.text = text {1:-}|
+ {2: 10 } cell.hl_id = hl_id |
+ {2: 11 } colpos = colpos+1 |
+ {2: 12 } end |
+ {2: 13 }end |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('virtual text win_col out of window does not break display #25645', function()
+ screen:try_resize(51, 6)
+ command('vnew')
+ meths.buf_set_lines(0, 0, -1, false, { string.rep('a', 50) })
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaa│ |
+ aaaaaaaaaaaaaaaaaaaaaaaaa│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {41:[No Name] [+] }{40:[No Name] }|
+ |
+ ]]}
+ local extmark_opts = { virt_text_win_col = 35, virt_text = { { ' ', 'Comment' } } }
+ meths.buf_set_extmark(0, ns, 0, 0, extmark_opts)
+ screen:expect_unchanged()
+ assert_alive()
+ end)
+
+ it('can have virtual text on folded line', function()
+ insert([[
+ 11111
+ 22222
+ 33333]])
+ command('1,2fold')
+ screen:try_resize(50, 3)
+ feed('zb')
+ -- XXX: the behavior of overlay virtual text at non-zero column is strange:
+ -- 1. With 'wrap' it is never shown.
+ -- 2. With 'nowrap' it is shown only if the extmark is hidden before leftcol.
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'overlay' })
+ meths.buf_set_extmark(0, ns, 0, 5, { virt_text = {{'BB', 'Underlined'}}, hl_mode = 'combine', virt_text_win_col = 10 })
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'right_align' })
+ screen:expect{grid=[[
+ {29:AA}{33:- 2 lin}{29:BB}{33:: 11111·····························}{29:CC}|
+ 3333^3 |
+ |
+ ]]}
+ command('set nowrap')
+ screen:expect_unchanged()
+ feed('zl')
+ screen:expect{grid=[[
+ {29:AA}{33:- 2 lin}{29:BB}{33:: 11111·····························}{29:CC}|
+ 333^3 |
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {29:AA}{33:- 2 lin}{29:BB}{33:: 11111·····························}{29:CC}|
+ 33^3 |
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {29:AA}{33:- 2 lin}{29:BB}{33:: 11111·····························}{29:CC}|
+ 3^3 |
+ |
+ ]]}
+ end)
+
+ it('virtual text works below diff filler lines', function()
+ screen:try_resize(53, 8)
+ insert([[
+ aaaaa
+ bbbbb
+ ccccc
+ ddddd
+ eeeee]])
+ command('rightbelow vnew')
+ insert([[
+ bbbbb
+ ccccc
+ ddddd
+ eeeee]])
+ command('windo diffthis')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, virt_text_pos = 'overlay' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'BB', 'Underlined'}}, virt_text_win_col = 10 })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'CC', 'Underlined'}}, virt_text_pos = 'right_align' })
+ screen:expect{grid=[[
+ {37: }{38:aaaaa }│{37: }{39:------------------------}|
+ {37: }bbbbb │{37: }{28:AA}bbb {28:BB} {28:CC}|
+ {37: }ccccc │{37: }ccccc |
+ {37: }ddddd │{37: }ddddd |
+ {37: }eeeee │{37: }eeee^e |
+ {1:~ }│{1:~ }|
+ {40:[No Name] [+] }{41:[No Name] [+] }|
+ |
+ ]]}
+ command('windo set wrap')
+ screen:expect_unchanged()
end)
it('can have virtual text which combines foreground and background groups', function()
+ screen:try_resize(20, 5)
+
screen:set_default_attr_ids {
[1] = {bold=true, foreground=Screen.colors.Blue};
[2] = {background = tonumber('0x123456'), foreground = tonumber('0xbbbbbb')};
@@ -909,30 +1569,24 @@ end]]
hi VeryBold gui=bold
]]
- meths.buf_set_extmark(0, ns, 0, 0, { virt_text={
+ insert('##')
+ local vt = {
{'a', {'BgOne', 'FgEin'}};
{'b', {'BgOne', 'FgZwei'}};
{'c', {'BgTwo', 'FgEin'}};
{'d', {'BgTwo', 'FgZwei'}};
{'X', {'BgTwo', 'FgZwei', 'VeryBold'}};
- }})
-
+ }
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'eol' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'right_align' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_lines = { vt, vt } })
screen:expect{grid=[[
- ^ {2:a}{3:b}{4:c}{5:d}{6:X} |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
+ {2:a}{3:b}{4:c}{5:d}{6:X}#^# {2:a}{3:b}{4:c}{5:d}{6:X} {2:a}{3:b}{4:c}{5:d}{6:X}|
+ {2:a}{3:b}{4:c}{5:d}{6:X} |
+ {2:a}{3:b}{4:c}{5:d}{6:X} |
+ {1:~ }|
+ |
]]}
end)
@@ -980,21 +1634,94 @@ end]]
{1:~ }|
|
]]}
- helpers.assert_alive()
+ assert_alive()
end)
- it('conceal #19007', function()
+ it('conceal with conceal char #19007', function()
screen:try_resize(50, 5)
insert('foo\n')
- command('let &conceallevel=2')
meths.buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='X'})
+ command('set conceallevel=2')
screen:expect([[
- {26:X} |
- ^ |
- {1:~ }|
- {1:~ }|
- |
- ]])
+ {26:X} |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ command('set conceallevel=1')
+ screen:expect_unchanged()
+
+ eq("conceal char has to be printable", pcall_err(meths.buf_set_extmark, 0, ns, 0, 0, {end_col=0, end_row=2, conceal='\255'}))
+ end)
+
+ it('conceal with composed conceal char', function()
+ screen:try_resize(50, 5)
+ insert('foo\n')
+ meths.buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='ẍ̲'})
+ command('set conceallevel=2')
+ screen:expect([[
+ {26:ẍ̲} |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ command('set conceallevel=1')
+ screen:expect_unchanged()
+
+ -- this is rare, but could happen. Save at least the first codepoint
+ meths._invalidate_glyph_cache()
+ screen:expect{grid=[[
+ {26:x} |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('conceal without conceal char #24782', function()
+ screen:try_resize(50, 5)
+ insert('foobar\n')
+ meths.buf_set_extmark(0, ns, 0, 0, {end_col=3, conceal=''})
+ command('set listchars=conceal:?')
+ command('let &conceallevel=1')
+ screen:expect([[
+ {26:?}bar |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ command('let &conceallevel=2')
+ screen:expect([[
+ bar |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end)
+
+ it('conceal works just before truncated double-width char #21486', function()
+ screen:try_resize(40, 4)
+ meths.buf_set_lines(0, 0, -1, true, {'', ('a'):rep(37) .. '<>古'})
+ meths.buf_set_extmark(0, ns, 1, 37, {end_col=39, conceal=''})
+ command('setlocal conceallevel=2')
+ screen:expect{grid=[[
+ ^ |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{1:>} |
+ 古 |
+ |
+ ]]}
+ feed('j')
+ screen:expect{grid=[[
+ |
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<>{1:>}|
+ 古 |
+ |
+ ]]}
end)
it('avoids redraw issue #20651', function()
@@ -1045,6 +1772,2005 @@ end]]
end)
+ it('underline attribute with higher priority takes effect #22371', function()
+ screen:try_resize(50, 3)
+ insert('aaabbbaaa')
+ exec([[
+ hi TestUL gui=underline guifg=Blue
+ hi TestUC gui=undercurl guisp=Red
+ hi TestBold gui=bold
+ ]])
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue};
+ [1] = {underline = true, foreground = Screen.colors.Blue};
+ [2] = {undercurl = true, special = Screen.colors.Red};
+ [3] = {underline = true, foreground = Screen.colors.Blue, special = Screen.colors.Red};
+ [4] = {undercurl = true, foreground = Screen.colors.Blue, special = Screen.colors.Red};
+ [5] = {bold = true, underline = true, foreground = Screen.colors.Blue};
+ [6] = {bold = true, undercurl = true, special = Screen.colors.Red};
+ })
+
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 20 })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 30 })
+ screen:expect([[
+ {1:aaa}{4:bbb}{1:aa^a} |
+ {0:~ }|
+ |
+ ]])
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 20 })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 30 })
+ screen:expect([[
+ {2:aaa}{3:bbb}{2:aa^a} |
+ {0:~ }|
+ |
+ ]])
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 30 })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 20 })
+ screen:expect([[
+ {1:aaa}{3:bbb}{1:aa^a} |
+ {0:~ }|
+ |
+ ]])
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 30 })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 20 })
+ screen:expect([[
+ {2:aaa}{4:bbb}{2:aa^a} |
+ {0:~ }|
+ |
+ ]])
+
+ -- When only one highlight group has an underline attribute, it should always take effect.
+ for _, d in ipairs({-5, 5}) do
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ screen:expect([[
+ aaabbbaa^a |
+ {0:~ }|
+ |
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 25 + d })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d })
+ screen:expect([[
+ {1:aaa}{5:bbb}{1:aa^a} |
+ {0:~ }|
+ |
+ ]])
+ end
+ for _, d in ipairs({-5, 5}) do
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ screen:expect([[
+ aaabbbaa^a |
+ {0:~ }|
+ |
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 25 + d })
+ meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d })
+ screen:expect([[
+ {2:aaa}{6:bbb}{2:aa^a} |
+ {0:~ }|
+ |
+ ]])
+ end
+ end)
+
+ it('highlight is combined with syntax and sign linehl #20004', function()
+ screen:try_resize(50, 3)
+ insert([[
+ function Func()
+ end]])
+ feed('gg')
+ command('set ft=lua')
+ command('syntax on')
+ meths.buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_mode = 'combine', hl_group = 'Visual' })
+ command('hi default MyLine gui=underline')
+ command('sign define CurrentLine linehl=MyLine')
+ funcs.sign_place(6, 'Test', 'CurrentLine', '', { lnum = 1 })
+ screen:expect{grid=[[
+ {30:^fun}{31:ction}{32: Func() }|
+ {6:end} |
+ |
+ ]]}
+ end)
+
+ it('highlight works after TAB with sidescroll #14201', function()
+ screen:try_resize(50, 3)
+ command('set nowrap')
+ meths.buf_set_lines(0, 0, -1, true, {'\tword word word word'})
+ meths.buf_set_extmark(0, ns, 0, 1, { end_col = 3, hl_group = 'ErrorMsg' })
+ screen:expect{grid=[[
+ ^ {4:wo}rd word word word |
+ {1:~ }|
+ |
+ ]]}
+ feed('7zl')
+ screen:expect{grid=[[
+ {4:^wo}rd word word word |
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {4:^wo}rd word word word |
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {4:^o}rd word word word |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('highlights the beginning of a TAB char correctly #23734', function()
+ screen:try_resize(50, 3)
+ meths.buf_set_lines(0, 0, -1, true, {'this is the\ttab'})
+ meths.buf_set_extmark(0, ns, 0, 11, { end_col = 15, hl_group = 'ErrorMsg' })
+ screen:expect{grid=[[
+ ^this is the{4: tab} |
+ {1:~ }|
+ |
+ ]]}
+
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ meths.buf_set_extmark(0, ns, 0, 12, { end_col = 15, hl_group = 'ErrorMsg' })
+ screen:expect{grid=[[
+ ^this is the {4:tab} |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('highlight applies to a full TAB on line with matches #20885', function()
+ screen:try_resize(50, 3)
+ meths.buf_set_lines(0, 0, -1, true, {'\t-- match1', ' -- match2'})
+ funcs.matchadd('Underlined', 'match')
+ meths.buf_set_extmark(0, ns, 0, 0, { end_row = 1, end_col = 0, hl_group = 'Visual' })
+ meths.buf_set_extmark(0, ns, 1, 0, { end_row = 2, end_col = 0, hl_group = 'Visual' })
+ screen:expect{grid=[[
+ {18: ^ -- }{29:match}{18:1} |
+ {18: -- }{29:match}{18:2} |
+ |
+ ]]}
+ end)
+
+ pending('highlight applies to a full TAB in visual block mode', function()
+ screen:try_resize(50, 8)
+ meths.buf_set_lines(0, 0, -1, true, {'asdf', '\tasdf', '\tasdf', '\tasdf', 'asdf'})
+ meths.buf_set_extmark(0, ns, 0, 0, {end_row = 5, end_col = 0, hl_group = 'Underlined'})
+ screen:expect([[
+ {28:^asdf} |
+ {28: asdf} |
+ {28: asdf} |
+ {28: asdf} |
+ {28:asdf} |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ feed('<C-V>Gll')
+ screen:expect([[
+ {29:asd}{28:f} |
+ {29: }{28: asdf} |
+ {29: }{28: asdf} |
+ {29: }{28: asdf} |
+ {29:as}{28:^df} |
+ {1:~ }|
+ {1:~ }|
+ {24:-- VISUAL BLOCK --} |
+ ]])
+ end)
+
+ it('supports multiline highlights', function()
+ insert(example_text)
+ feed 'gg'
+ for _,i in ipairs {1,2,3,5,6,7} do
+ for _,j in ipairs {2,5,10,15} do
+ meths.buf_set_extmark(0, ns, i, j, { end_col=j+2, hl_group = 'NonText'})
+ end
+ end
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ {1: }l{1:oc}al {1:te}xt,{1: h}l_id_cell, count = unpack(item) |
+ {1: }i{1:f }hl_{1:id}_ce{1:ll} ~= nil then |
+ {1: } {1: } hl{1:_i}d ={1: h}l_id_cell |
+ end |
+ {1: }f{1:or} _ {1:= }1, {1:(c}ount or 1) do |
+ {1: } {1: } lo{1:ca}l c{1:el}l = line[colpos] |
+ {1: } {1: } ce{1:ll}.te{1:xt} = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed'5<c-e>'
+ screen:expect{grid=[[
+ ^ {1: }f{1:or} _ {1:= }1, {1:(c}ount or 1) do |
+ {1: } {1: } lo{1:ca}l c{1:el}l = line[colpos] |
+ {1: } {1: } ce{1:ll}.te{1:xt} = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 1, 0, { end_line=8, end_col=10, hl_group = 'ErrorMsg'})
+ screen:expect{grid=[[
+ {4:^ }{36: }{4:f}{36:or}{4: _ }{36:= }{4:1, }{36:(c}{4:ount or 1) do} |
+ {4: }{36: }{4: }{36: }{4: lo}{36:ca}{4:l c}{36:el}{4:l = line[colpos]} |
+ {4: }{36: }{4: }{36: }{4: ce}{36:ll}{4:.te}{36:xt}{4: = text} |
+ {4: ce}ll.hl_id = hl_id |
+ colpos = colpos+1 |
+ end |
+ end |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ local function with_undo_restore(val)
+ screen:try_resize(50, 5)
+ insert(example_text)
+ feed'gg'
+ meths.buf_set_extmark(0, ns, 0, 6, { end_col=13, hl_group = 'NonText', undo_restore=val})
+ screen:expect{grid=[[
+ ^for _,{1:item in} ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ |
+ ]]}
+
+ meths.buf_set_text(0, 0, 4, 0, 8, {''})
+ screen:expect{grid=[[
+ ^for {1:em in} ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ |
+ ]]}
+ end
+
+ it("highlights do reapply to restored text after delete", function()
+ with_undo_restore(true) -- also default behavior
+
+ command('silent undo')
+ screen:expect{grid=[[
+ ^for _,{1:item in} ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ |
+ ]]}
+ end)
+
+ it("highlights don't reapply to restored text after delete with undo_restore=false", function()
+ with_undo_restore(false)
+
+ command('silent undo')
+ screen:expect{grid=[[
+ ^for _,it{1:em in} ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ |
+ ]]}
+
+ eq({ { 1, 0, 8, { end_col = 13, end_right_gravity = false, end_row = 0,
+ hl_eol = false, hl_group = "NonText", undo_restore = false,
+ ns_id = 1, priority = 4096, right_gravity = true } } },
+ meths.buf_get_extmarks(0, ns, {0,0}, {0, -1}, {details=true}))
+ end)
+
+ it('virtual text works with rightleft', function()
+ screen:try_resize(50, 3)
+ insert('abcdefghijklmn')
+ feed('0')
+ command('set rightleft')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'EOL', 'Underlined'}}})
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'right_align', 'Underlined'}}, virt_text_pos = 'right_align' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'win_col', 'Underlined'}}, virt_text_win_col = 20 })
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' })
+ screen:expect{grid=[[
+ {28:ngila_thgir} {28:loc_niw} {28:LOE} nml{28:deyalrevo}b^a|
+ {1: ~}|
+ |
+ ]]}
+
+ insert(('#'):rep(32))
+ feed('0')
+ screen:expect{grid=[[
+ {28:ngila_tdeyalrevo}ba#####{28:loc_niw}###################^#|
+ {1: ~}|
+ |
+ ]]}
+
+ insert(('#'):rep(16))
+ feed('0')
+ screen:expect{grid=[[
+ {28:ngila_thgir}############{28:loc_niw}###################^#|
+ {28:LOE} nml{28:deyalrevo}|
+ |
+ ]]}
+
+ insert('###')
+ feed('0')
+ screen:expect{grid=[[
+ #################################################^#|
+ {28:ngila_thgir} {28:loc_niw} {28:LOE} nml{28:deyalrevo}ba#|
+ |
+ ]]}
+
+ command('set number')
+ screen:expect{grid=[[
+ #############################################^#{2: 1 }|
+ {28:ngila_thgir} {28:loc_niw} nml{28:deyalrevo}ba#####{2: }|
+ |
+ ]]}
+
+ command('set cpoptions+=n')
+ screen:expect{grid=[[
+ #############################################^#{2: 1 }|
+ {28:ngila_thgir} {28:loc_niw} nml{28:deyalrevo}ba#####|
+ |
+ ]]}
+ end)
+
+ it('works with double width char and rightleft', function()
+ screen:try_resize(50, 3)
+ insert('abcdefghij口klmnopqrstu口vwx口yz')
+ feed('0')
+ command('set rightleft')
+ screen:expect{grid=[[
+ zy口xwv口utsrqponmlk口jihgfedcb^a|
+ {1: ~}|
+ |
+ ]]}
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' })
+ meths.buf_set_extmark(0, ns, 0, 14, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' })
+ meths.buf_set_extmark(0, ns, 0, 20, { virt_text = {{'\t', 'Underlined'}}, virt_text_pos = 'overlay' })
+ meths.buf_set_extmark(0, ns, 0, 29, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' })
+ screen:expect{grid=[[
+ zy {28:古}wv {28: }qpon{28:古}k {28:deyalrevo}b^a|
+ {1: ~}|
+ |
+ ]]}
+ end)
+
+ it('works with both hl_group and sign_hl_group', function()
+ screen:try_resize(screen._width, 3)
+ insert('abcdefghijklmn')
+ meths.buf_set_extmark(0, ns, 0, 0, {sign_text='S', sign_hl_group='NonText', hl_group='Error', end_col=14})
+ screen:expect{grid=[[
+ {1:S }{4:abcdefghijklm^n} |
+ {1:~ }|
+ |
+ ]]}
+ end)
+end)
+
+describe('decorations: inline virtual text', function()
+ local screen, ns
+ before_each( function()
+ clear()
+ screen = Screen.new(50, 3)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = {bold=true, foreground=Screen.colors.Blue};
+ [2] = {foreground = Screen.colors.Brown};
+ [3] = {bold = true, foreground = Screen.colors.SeaGreen};
+ [4] = {background = Screen.colors.Red1, foreground = Screen.colors.Gray100};
+ [5] = {background = Screen.colors.Red1, bold = true};
+ [6] = {foreground = Screen.colors.DarkCyan};
+ [7] = {background = Screen.colors.LightGrey};
+ [8] = {bold = true};
+ [9] = {background = Screen.colors.Plum1};
+ [10] = {foreground = Screen.colors.SlateBlue};
+ [11] = {blend = 30, background = Screen.colors.Red1};
+ [12] = {background = Screen.colors.Yellow};
+ [13] = {reverse = true};
+ [14] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightMagenta};
+ [15] = {bold = true, reverse = true};
+ [16] = {foreground = Screen.colors.Red};
+ [17] = {background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue};
+ [18] = {background = Screen.colors.LightGrey, foreground = Screen.colors.Red};
+ [19] = {background = Screen.colors.Yellow, foreground = Screen.colors.SlateBlue};
+ [20] = {background = Screen.colors.LightGrey, foreground = Screen.colors.SlateBlue};
+ [21] = {reverse = true, foreground = Screen.colors.SlateBlue}
+ }
+
+ ns = meths.create_namespace 'test'
+ end)
+
+
+ it('works', function()
+ screen:try_resize(50, 10)
+ insert(example_text)
+ feed 'gg'
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{': ', 'Special'}, {'string', 'Type'}}, virt_text_pos='inline'})
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text{10:: }{3:string}, hl_id_cell, count = unpack|
+ (item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ |
+ ]]}
+
+ screen:try_resize(55, 10)
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text{10:: }{3:string}, hl_id_cell, count = unpack(item|
+ ) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ |
+ ]]}
+
+ screen:try_resize(56, 10)
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text{10:: }{3:string}, hl_id_cell, count = unpack(item)|
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ |
+ ]]}
+ end)
+
+ it('works with 0-width chunk', function()
+ screen:try_resize(50, 10)
+ insert(example_text)
+ feed 'gg'
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text, hl_id_cell, count = unpack(item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 0, 5, {virt_text={{''}, {''}}, virt_text_pos='inline'})
+ meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {': ', 'Special'}}, virt_text_pos='inline'})
+ meths.buf_set_extmark(0, ns, 1, 48, {virt_text={{''}, {''}}, virt_text_pos='inline'})
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ local text{10:: }, hl_id_cell, count = unpack(item)|
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {'string', 'Type'}}, virt_text_pos='inline'})
+ feed('V')
+ screen:expect{grid=[[
+ ^f{7:or _,item in ipairs(items) do} |
+ local text{10:: }{3:string}, hl_id_cell, count = unpack|
+ (item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ {8:-- VISUAL LINE --} |
+ ]]}
+
+ feed('<Esc>jf,')
+ screen:expect{grid=[[
+ for _,item in ipairs(items) do |
+ local text{10:: }{3:string}^, hl_id_cell, count = unpack|
+ (item) |
+ if hl_id_cell ~= nil then |
+ hl_id = hl_id_cell |
+ end |
+ for _ = 1, (count or 1) do |
+ local cell = line[colpos] |
+ cell.text = text |
+ |
+ ]]}
+ end)
+
+ it('Normal mode "gM" command works properly', function()
+ command([[call setline(1, '123456789')]])
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 7, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' })
+ feed('gM')
+ screen:expect{grid=[[
+ 12{10:bbb}34^567{10:bbb}89 |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ local function test_normal_gj_gk()
+ screen:try_resize(60, 6)
+ command([[call setline(1, repeat([repeat('a', 55)], 2))]])
+ meths.buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 1, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gj')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ ^aaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gj')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gj')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ ^aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gk')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gk')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ ^aaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ feed('gk')
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa|
+ aaaaa |
+ {1:~ }|
+ |
+ ]]}
+ end
+
+ describe('Normal mode "gj" "gk" commands work properly', function()
+ it('with virtualedit=', function()
+ test_normal_gj_gk()
+ end)
+
+ it('with virtualedit=all', function()
+ command('set virtualedit=all')
+ test_normal_gj_gk()
+ end)
+ end)
+
+ it('cursor positions are correct with multiple inline virtual text', function()
+ insert('12345678')
+ meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' })
+ feed '^'
+ feed '4l'
+ screen:expect{grid=[[
+ 1234{10: virtual text virtual text }^5678 |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('adjusts cursor location correctly when inserting around inline virtual text', function()
+ insert('12345678')
+ feed '$'
+ meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' })
+
+ screen:expect{grid=[[
+ 1234{10: virtual text }567^8 |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('has correct highlighting with multi-byte characters', function()
+ insert('12345678')
+ meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'múlti-byté chñröcters 修补', 'Special' } }, virt_text_pos = 'inline' })
+
+ screen:expect{grid=[[
+ 1234{10:múlti-byté chñröcters 修补}567^8 |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('has correct cursor position when inserting around virtual text', function()
+ insert('12345678')
+ meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ feed '^'
+ feed '3l'
+ feed 'a'
+ screen:expect{grid=[[
+ 1234{10:^virtual text}5678 |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed '<ESC>'
+ screen:expect{grid=[[
+ 123^4{10:virtual text}5678 |
+ {1:~ }|
+ |
+ ]]}
+ feed '^'
+ feed '4l'
+ feed 'i'
+ screen:expect{grid=[[
+ 1234{10:^virtual text}5678 |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ end)
+
+ it('has correct cursor position with virtual text on an empty line', function()
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ {10:^virtual text} |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('text is drawn correctly with a wrapping virtual text', function()
+ screen:try_resize(60, 8)
+ exec([[
+ call setline(1, ['', 'aaa', '', 'bbbbbb'])
+ normal gg0
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('X', 60), 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 2, 0, { virt_text = { { string.rep('X', 61), 'Special' } }, virt_text_pos = 'inline' })
+ feed('$')
+ screen:expect{grid=[[
+ {10:^XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ aaa |
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('j')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ aa^a |
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('j')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ aaa |
+ {10:^XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('j')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ aaa |
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ bbbbb^b |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('0<C-V>2l2k')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {7:aa}^a |
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ {7:bbb}bbb |
+ {1:~ }|
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed([[<Esc>/aaa\n\%V<CR>]])
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {12:^aaa } |
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:X} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ {16:search hit BOTTOM, continuing at TOP} |
+ ]]}
+ feed('3ggic')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {12:aaa } |
+ c{10:^XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:XX} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed([[<Esc>/aaa\nc\%V<CR>]])
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {12:^aaa } |
+ {12:c}{10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:XX} |
+ bbbbbb |
+ {1:~ }|
+ {1:~ }|
+ {16:search hit BOTTOM, continuing at TOP} |
+ ]]}
+ end)
+
+ it('cursor position is correct with virtual text attached to hard TABs', function()
+ command('set noexpandtab')
+ feed('i')
+ feed('<TAB>')
+ feed('<TAB>')
+ feed('test')
+ feed('<ESC>')
+ meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ feed('0')
+ screen:expect{grid=[[
+ ^ {10:virtual text} test |
+ {1:~ }|
+ |
+ ]]}
+
+ feed('l')
+ screen:expect{grid=[[
+ {10:virtual text} ^ test |
+ {1:~ }|
+ |
+ ]]}
+
+ feed('l')
+ screen:expect{grid=[[
+ {10:virtual text} ^test |
+ {1:~ }|
+ |
+ ]]}
+
+ feed('l')
+ screen:expect{grid=[[
+ {10:virtual text} t^est |
+ {1:~ }|
+ |
+ ]]}
+
+ feed('l')
+ screen:expect{grid=[[
+ {10:virtual text} te^st |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('cursor position is correct with virtual text on an empty line', function()
+ command('set linebreak')
+ insert('one twoword')
+ feed('0')
+ meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { ': virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ ^one{10:: virtual text} twoword |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('search highlight is correct', function()
+ insert('foo foo foo bar\nfoo foo foo bar')
+ feed('gg0')
+ meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ screen:expect{grid=[[
+ ^foo foo f{10:AAABBB}oo bar |
+ foo foo f{10:CCCDDD}oo bar |
+ |
+ ]]}
+
+ feed('/foo')
+ screen:expect{grid=[[
+ {12:foo} {13:foo} {12:f}{10:AAA}{19:BBB}{12:oo} bar |
+ {12:foo} {12:foo} {12:f}{19:CCC}{10:DDD}{12:oo} bar |
+ /foo^ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 0, 13, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ feed('<C-G>')
+ screen:expect{grid=[[
+ {12:foo} {12:foo} {13:f}{10:AAA}{21:BBB}{13:oo} b{10:EEE}ar |
+ {12:foo} {12:foo} {12:f}{19:CCC}{10:DDD}{12:oo} bar |
+ /foo^ |
+ ]]}
+ end)
+
+ it('Visual select highlight is correct', function()
+ insert('foo foo foo bar\nfoo foo foo bar')
+ feed('gg0')
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ feed('8l')
+ screen:expect{grid=[[
+ foo foo {10:AAABBB}^foo bar |
+ foo foo {10:CCCDDD}foo bar |
+ |
+ ]]}
+
+ feed('<C-V>')
+ feed('2hj')
+ screen:expect{grid=[[
+ foo fo{7:o }{10:AAA}{20:BBB}{7:f}oo bar |
+ foo fo^o{7: }{20:CCC}{10:DDD}{7:f}oo bar |
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 0, 10, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ screen:expect{grid=[[
+ foo fo{7:o }{10:AAA}{20:BBB}{7:f}o{10:EEE}o bar |
+ foo fo^o{7: }{20:CCC}{10:DDD}{7:f}oo bar |
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ end)
+
+ it('inside highlight range of another extmark', function()
+ insert('foo foo foo bar\nfoo foo foo bar')
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ meths.buf_set_extmark(0, ns, 0, 4, { end_col = 11, hl_group = 'Search' })
+ meths.buf_set_extmark(0, ns, 1, 4, { end_col = 11, hl_group = 'Search' })
+ screen:expect{grid=[[
+ foo {12:foo }{10:AAA}{19:BBB}{12:foo} bar |
+ foo {12:foo }{19:CCC}{10:DDD}{12:foo} ba^r |
+ |
+ ]]}
+ end)
+
+ it('inside highlight range of syntax', function()
+ insert('foo foo foo bar\nfoo foo foo bar')
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ command([[syntax match Search 'foo \zsfoo foo\ze bar']])
+ screen:expect{grid=[[
+ foo {12:foo }{10:AAA}{19:BBB}{12:foo} bar |
+ foo {12:foo }{19:CCC}{10:DDD}{12:foo} ba^r |
+ |
+ ]]}
+ end)
+
+ it('cursor position is correct when inserting around a virtual text with left gravity', function()
+ screen:try_resize(27, 4)
+ insert(('a'):rep(15))
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { ('>'):rep(43), 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ command('setlocal showbreak=+ breakindent breakindentopt=shift:2')
+ feed('08l')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}^aaaaaaa |
+ |
+ ]]}
+ feed('i')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}^aaaaaaa |
+ {8:-- INSERT --} |
+ ]]}
+ feed([[<C-\><C-O>]])
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}^aaaaaaa |
+ {8:-- (insert) --} |
+ ]]}
+ feed('D')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:^~ }|
+ {8:-- INSERT --} |
+ ]]}
+ command('setlocal list listchars=eol:$')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+^$} |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<C-U>')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>}{1:^$} |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('a')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>}a{1:^$} |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('<Esc>')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>}^a{1:$} |
+ {1:~ }|
+ |
+ ]]}
+ feed('x')
+ screen:expect{grid=[[
+ {10:^>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>>>>>>>}{1:$} |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('cursor position is correct when inserting around virtual texts with both left and right gravity', function()
+ screen:try_resize(30, 4)
+ command('setlocal showbreak=+ breakindent breakindentopt=shift:2')
+ insert(('a'):rep(15))
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('>'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = false })
+ meths.buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('<'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = true })
+ feed('08l')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>><<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<}^aaaaaaa |
+ |
+ ]]}
+ feed('i')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>^<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<}aaaaaaa |
+ {8:-- INSERT --} |
+ ]]}
+ feed('a')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>}a{10:^<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<<}aaaaaaa |
+ {8:-- INSERT --} |
+ ]]}
+ feed([[<C-\><C-O>]])
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>}a{10:<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<<}^aaaaaaa |
+ {8:-- (insert) --} |
+ ]]}
+ feed('D')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>}a{10:^<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<BS>')
+ screen:expect{grid=[[
+ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>>>>>>>>>^<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<<<<<<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<C-U>')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>^<<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ feed('a')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>}a{10:^<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<Esc>')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>}^a{10:<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<<} |
+ |
+ ]]}
+ feed('x')
+ screen:expect{grid=[[
+ {10:^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>><<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<} |
+ |
+ ]]}
+ feed('i')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:>>^<<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<<<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ screen:try_resize(32, 4)
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<<<} |
+ {8:-- INSERT --} |
+ ]]}
+ command('setlocal nobreakindent')
+ screen:expect{grid=[[
+ {10:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}|
+ {1:+}{10:^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}|
+ {1:+}{10:<} |
+ {8:-- INSERT --} |
+ ]]}
+ end)
+
+ it('draws correctly with no wrap multiple virtual text, where one is hidden', function()
+ insert('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')
+ command("set nowrap")
+ meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ feed('$')
+ screen:expect{grid=[[
+ opqrstuvwxyzabcdefghijklmnopqrstuvwx{10:virtual text}y^z|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('draws correctly with no wrap and a long virtual text', function()
+ insert('abcdefghi')
+ command("set nowrap")
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' })
+ feed('$')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}cdefgh^i|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('tabs are the correct length with no wrap following virtual text', function()
+ command('set nowrap')
+ feed('itest<TAB>a<ESC>')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' })
+ feed('gg$')
+ screen:expect{grid=[[
+ {10:aaaaaaaaaaaaaaaaaaaaaaaaa}test ^a |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('highlighting does not extend with no wrap and a long virtual text', function()
+ insert('abcdef')
+ command("set nowrap")
+ meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 50), 'Special' } }, virt_text_pos = 'inline' })
+ feed('$')
+ screen:expect{grid=[[
+ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}de^f|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('hidden virtual text does not interfere with Visual highlight', function()
+ insert('abcdef')
+ command('set nowrap')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'XXX', 'Special' } }, virt_text_pos = 'inline' })
+ feed('V2zl')
+ screen:expect{grid=[[
+ {10:X}{7:abcde}^f |
+ {1:~ }|
+ {8:-- VISUAL LINE --} |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {7:abcde}^f |
+ {1:~ }|
+ {8:-- VISUAL LINE --} |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ {7:bcde}^f |
+ {1:~ }|
+ {8:-- VISUAL LINE --} |
+ ]]}
+ end)
+
+ it('highlighting is correct when virtual text wraps with number', function()
+ screen:try_resize(50, 5)
+ insert([[
+ test
+ test]])
+ command('set number')
+ meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' })
+ feed('gg0')
+ screen:expect{grid=[[
+ {2: 1 }^t{10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {2: }{10:XXXXXXXXXX}est |
+ {2: 2 }test |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('highlighting is correct when virtual text is proceeded with a match', function()
+ insert([[test]])
+ meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ feed('gg0')
+ command('match ErrorMsg /e/')
+ screen:expect{grid=[[
+ ^t{4:e}{10:virtual text}st |
+ {1:~ }|
+ |
+ ]]}
+ command('match ErrorMsg /s/')
+ screen:expect{grid=[[
+ ^te{10:virtual text}{4:s}t |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('smoothscroll works correctly when virtual text wraps', function()
+ insert('foobar')
+ meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' })
+ command('setlocal smoothscroll')
+ screen:expect{grid=[[
+ foo{10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
+ {10:XXXXXXXX}ba^r |
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}{10:XXXXX}ba^r |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('in diff mode is highlighted correct', function()
+ screen:try_resize(50, 10)
+ insert([[
+ 9000
+ 0009
+ 0009
+ 9000
+ 0009
+ ]])
+ insert('aaa\tbbb')
+ command("set diff")
+ meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ meths.buf_set_extmark(0, ns, 5, 0, { virt_text = { { '!', 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 5, 3, { virt_text = { { '' } }, virt_text_pos = 'inline' })
+ command("vnew")
+ insert([[
+ 000
+ 000
+ 000
+ 000
+ 000
+ ]])
+ insert('aaabbb')
+ command("set diff")
+ feed('gg0')
+ screen:expect{grid=[[
+ {9:^000 }│{5:9}{14:test}{9:000 }|
+ {9:000 }│{9:000}{5:9}{9: }|
+ {9:000 }│{9:000}{5:9}{9: }|
+ {9:000 }│{5:9}{9:000 }|
+ {9:000 }│{9:000}{5:9}{9: }|
+ {9:aaabbb }│{14:!}{9:aaa}{5: }{9:bbb }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {15:[No Name] [+] }{13:[No Name] [+] }|
+ |
+ ]]}
+ command('wincmd w | set nowrap')
+ feed('zl')
+ screen:expect{grid=[[
+ {9:000 }│{14:test}{9:000 }|
+ {9:000 }│{9:00}{5:9}{9: }|
+ {9:000 }│{9:00}{5:9}{9: }|
+ {9:000 }│{9:000 }|
+ {9:000 }│{9:00}{5:9}{9: }|
+ {9:aaabbb }│{9:aaa}{5: }{9:bb^b }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {13:[No Name] [+] }{15:[No Name] [+] }|
+ |
+ ]]}
+ end)
+
+ it('correctly draws when there are multiple overlapping virtual texts on the same line with nowrap', function()
+ command('set nowrap')
+ insert('a')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('b', 55), 'Special' } }, virt_text_pos = 'inline' })
+ feed('$')
+ screen:expect{grid=[[
+ {10:bbbbbbbbbbbbbbbbbbbbbbbbb}^a |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('correctly draws when overflowing virtual text is followed by TAB with no wrap', function()
+ command('set nowrap')
+ feed('i<TAB>test<ESC>')
+ meths.buf_set_extmark( 0, ns, 0, 0, { virt_text = { { string.rep('a', 60), 'Special' } }, virt_text_pos = 'inline' })
+ feed('0')
+ screen:expect({grid=[[
+ {10:aaaaaaaaaaaaaaaaaaaaaa} ^ test |
+ {1:~ }|
+ |
+ ]]})
+ end)
+
+ it('does not crash at column 0 when folded in a wide window', function()
+ screen:try_resize(82, 5)
+ command('hi! CursorLine guibg=NONE guifg=Red gui=NONE')
+ command('set cursorline')
+ insert([[
+ aaaaa
+ bbbbb
+
+ ccccc]])
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'foo'}}, virt_text_pos = 'inline' })
+ meths.buf_set_extmark(0, ns, 2, 0, { virt_text = {{'bar'}}, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ fooaaaaa |
+ bbbbb |
+ bar |
+ {16:cccc^c }|
+ |
+ ]]}
+ command('1,2fold')
+ screen:expect{grid=[[
+ {17:+-- 2 lines: aaaaa·······························································}|
+ bar |
+ {16:cccc^c }|
+ {1:~ }|
+ |
+ ]]}
+ feed('2k')
+ screen:expect{grid=[[
+ {18:^+-- 2 lines: aaaaa·······························································}|
+ bar |
+ ccccc |
+ {1:~ }|
+ |
+ ]]}
+ command('3,4fold')
+ screen:expect{grid=[[
+ {18:^+-- 2 lines: aaaaa·······························································}|
+ {17:+-- 2 lines: ccccc·······························································}|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('j')
+ screen:expect{grid=[[
+ {17:+-- 2 lines: aaaaa·······························································}|
+ {18:^+-- 2 lines: ccccc·······························································}|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('does not crash at right edge of wide window #23848', function()
+ screen:try_resize(82, 5)
+ meths.buf_set_extmark(0, ns, 0, 0, {virt_text = {{('a'):rep(82)}, {'b'}}, virt_text_pos = 'inline'})
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ b |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ command('set nowrap')
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('82i0<Esc>0')
+ screen:expect{grid=[[
+ ^0000000000000000000000000000000000000000000000000000000000000000000000000000000000|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ command('set wrap')
+ screen:expect{grid=[[
+ ^0000000000000000000000000000000000000000000000000000000000000000000000000000000000|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ b |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('lcs-extends is drawn with inline virtual text at end of screen line', function()
+ exec([[
+ setlocal nowrap list listchars=extends:!
+ call setline(1, repeat('a', 51))
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' })
+ feed('20l')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaa{1:!}|
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{1:!}|
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:b}{1:!}|
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bb}{1:!}|
+ {1:~ }|
+ |
+ ]]}
+ feed('zl')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbb}a|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('lcs-extends is drawn with only inline virtual text offscreen', function()
+ command('set nowrap')
+ command('set list')
+ command('set listchars+=extends:c')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline' })
+ insert(string.rep('a', 50))
+ feed('gg0')
+ screen:expect{grid=[[
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{1:c}|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('blockwise Visual highlight with double-width virtual text (replace)', function()
+ screen:try_resize(60, 6)
+ insert('123456789\n123456789\n123456789\n123456789')
+ meths.buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ meths.buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
+ feed('gg0')
+ screen:expect{grid=[[
+ ^123456789 |
+ 1{10:-口-}23456789 |
+ 12{10:口}3456789 |
+ 123456789 |
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-V>3jl')
+ screen:expect{grid=[[
+ {7:12}3456789 |
+ {7:1}{10:-口-}23456789 |
+ {7:12}{10:口}3456789 |
+ {7:1}^23456789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ {7:123}456789 |
+ {7:1}{10:-口-}23456789 |
+ {7:12}{10:口}3456789 |
+ {7:12}^3456789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('4l')
+ screen:expect{grid=[[
+ {7:1234567}89 |
+ {7:1}{10:-口-}{7:23}456789 |
+ {7:12}{10:口}{7:345}6789 |
+ {7:123456}^789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('Ol')
+ screen:expect{grid=[[
+ 1{7:234567}89 |
+ 1{10:-口-}{7:23}456789 |
+ 1{7:2}{10:口}{7:345}6789 |
+ 1^2{7:34567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ 12{7:34567}89 |
+ 1{10:-口-}{7:23}456789 |
+ 12{10:口}{7:345}6789 |
+ 12^3{7:4567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ 123{7:4567}89 |
+ 1{10:-口-}{7:23}456789 |
+ 12{10:口}{7:345}6789 |
+ 123^4{7:567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ end)
+
+ it('blockwise Visual highlight with double-width virtual text (combine)', function()
+ screen:try_resize(60, 6)
+ insert('123456789\n123456789\n123456789\n123456789')
+ meths.buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ meths.buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
+ feed('gg0')
+ screen:expect{grid=[[
+ ^123456789 |
+ 1{10:-口-}23456789 |
+ 12{10:口}3456789 |
+ 123456789 |
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-V>3jl')
+ screen:expect{grid=[[
+ {7:12}3456789 |
+ {7:1}{20:-}{10:口-}23456789 |
+ {7:12}{10:口}3456789 |
+ {7:1}^23456789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ {7:123}456789 |
+ {7:1}{20:-口}{10:-}23456789 |
+ {7:12}{20:口}3456789 |
+ {7:12}^3456789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('4l')
+ screen:expect{grid=[[
+ {7:1234567}89 |
+ {7:1}{20:-口-}{7:23}456789 |
+ {7:12}{20:口}{7:345}6789 |
+ {7:123456}^789 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('Ol')
+ screen:expect{grid=[[
+ 1{7:234567}89 |
+ 1{20:-口-}{7:23}456789 |
+ 1{7:2}{20:口}{7:345}6789 |
+ 1^2{7:34567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ 12{7:34567}89 |
+ 1{10:-}{20:口-}{7:23}456789 |
+ 12{20:口}{7:345}6789 |
+ 12^3{7:4567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ feed('l')
+ screen:expect{grid=[[
+ 123{7:4567}89 |
+ 1{10:-}{20:口-}{7:23}456789 |
+ 12{20:口}{7:345}6789 |
+ 123^4{7:567}89 |
+ {1:~ }|
+ {8:-- VISUAL BLOCK --} |
+ ]]}
+ end)
+
+ local function test_virt_inline_showbreak_smoothscroll()
+ screen:try_resize(30, 6)
+ exec([[
+ highlight! link LineNr Normal
+ setlocal number showbreak=+ breakindent breakindentopt=shift:2
+ setlocal scrolloff=0 smoothscroll
+ call setline(1, repeat('a', 28))
+ normal! $
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 27, { virt_text = { { ('123'):rep(23) } }, virt_text_pos = 'inline' })
+ feed(':<CR>') -- Have a screen line that doesn't start with spaces
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}a1231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}12312312312312312312312|
+ {1:+}3^a |
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}a1231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}12312312312312312312312|
+ {1:+}3^a |
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}23123123123123123123123|
+ {1:+}12312312312312312312312|
+ {1:+}3^a |
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}12312312312312312312312|
+ {1:+}3^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}3^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('zbi')
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}a^1231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}12312312312312312312312|
+ {1:+}3a |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<BS>')
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}^12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}a |
+ {8:-- INSERT --} |
+ ]]}
+ feed('<Esc>l')
+ feed(':<CR>') -- Have a screen line that doesn't start with spaces
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('023x$')
+ screen:expect{grid=[[
+ 1 aaa12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}23123123123123123123123|
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ : |
+ ]]}
+ feed('zbi')
+ screen:expect{grid=[[
+ 1 aaa^12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:+}a |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('<C-U>')
+ screen:expect{grid=[[
+ 1 ^12312312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123a |
+ {1:~ }|
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('<Esc>')
+ screen:expect{grid=[[
+ 1 12312312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123^a |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:+}23123123123123123123^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('zbx')
+ screen:expect{grid=[[
+ 1 ^12312312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123 |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('26ia<Esc>a')
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}^12312312312312312312312|
+ {1:+}31231231231231231231231|
+ {1:+}23123123123123123123123|
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed([[<C-\><C-O>:setlocal breakindentopt=<CR>]])
+ screen:expect{grid=[[
+ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}^1231231231231231231231231|
+ {1:+}2312312312312312312312312|
+ {1:+}3123123123123123123 |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ end
+
+ describe('with showbreak, smoothscroll', function()
+ it('and cpoptions-=n', function()
+ test_virt_inline_showbreak_smoothscroll()
+ end)
+
+ it('and cpoptions+=n', function()
+ command('set cpoptions+=n')
+ -- because of 'breakindent' the screen states are the same
+ test_virt_inline_showbreak_smoothscroll()
+ end)
+ end)
+
+ it('before TABs with smoothscroll', function()
+ screen:try_resize(30, 6)
+ exec([[
+ setlocal list listchars=tab:<-> scrolloff=0 smoothscroll
+ call setline(1, repeat("\t", 4) .. 'a')
+ normal! $
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { ('12'):rep(32) } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ {1:<------><------><------>}121212|
+ 121212121212121212121212121212|
+ 1212121212121212121212121212{1:<-}|
+ {1:----->}^a |
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}212121212121212121212121212|
+ 1212121212121212121212121212{1:<-}|
+ {1:----->}^a |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}2121212121212121212121212{1:<-}|
+ {1:----->}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<-->}^a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('zbh')
+ screen:expect{grid=[[
+ {1:<------><------><------>}121212|
+ 121212121212121212121212121212|
+ 1212121212121212121212121212{1:^<-}|
+ {1:----->}a |
+ {1:~ }|
+ |
+ ]]}
+ feed('i')
+ screen:expect{grid=[[
+ {1:<------><------><------>}^121212|
+ 121212121212121212121212121212|
+ 1212121212121212121212121212{1:<-}|
+ {1:----->}a |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('<C-O>:setlocal nolist<CR>')
+ screen:expect{grid=[[
+ ^121212|
+ 121212121212121212121212121212|
+ 1212121212121212121212121212 |
+ a |
+ {1:~ }|
+ {8:-- INSERT --} |
+ ]]}
+ feed('<Esc>l')
+ screen:expect{grid=[[
+ 121212|
+ 121212121212121212121212121212|
+ 1212121212121212121212121212 |
+ ^ a |
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}212121212121212121212121212|
+ 1212121212121212121212121212 |
+ ^ a |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<}2121212121212121212121212 |
+ ^ a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('<C-E>')
+ screen:expect{grid=[[
+ {1:<<<} ^ a |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('before a space with linebreak', function()
+ screen:try_resize(50, 6)
+ exec([[
+ setlocal linebreak showbreak=+ breakindent breakindentopt=shift:2
+ call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45))
+ normal! $
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { ('b'):rep(10) } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:+}bbbbbbbbbb |
+ {1:+}cccccccccccccccccccccccccccccccccccccccccccc^c |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ feed('05x$')
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb|
+ {1:+}bbbbb |
+ {1:+}cccccccccccccccccccccccccccccccccccccccccccc^c |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('before double-width char that wraps', function()
+ exec([[
+ call setline(1, repeat('a', 40) .. '口' .. '12345')
+ normal! $
+ ]])
+ meths.buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(9) } }, virt_text_pos = 'inline' })
+ screen:expect{grid=[[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb{1:>}|
+ 口1234^5 |
+ |
+ ]]}
+ end)
end)
describe('decorations: virtual lines', function()
@@ -1055,7 +3781,7 @@ describe('decorations: virtual lines', function()
screen:attach()
screen:set_default_attr_ids {
[1] = {bold=true, foreground=Screen.colors.Blue};
- [2] = {foreground = Screen.colors.Cyan4};
+ [2] = {foreground = Screen.colors.DarkCyan};
[3] = {background = Screen.colors.Yellow1};
[4] = {bold = true};
[5] = {background = Screen.colors.Yellow, foreground = Screen.colors.Blue};
@@ -1068,7 +3794,7 @@ describe('decorations: virtual lines', function()
ns = meths.create_namespace 'test'
end)
- local example_text = [[
+ local example_text2 = [[
if (h->n_buckets < new_n_buckets) { // expand
khkey_t *new_keys = (khkey_t *)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t));
h->keys = new_keys;
@@ -1079,7 +3805,7 @@ if (h->n_buckets < new_n_buckets) { // expand
}]]
it('works with one line', function()
- insert(example_text)
+ insert(example_text2)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, 33, {
virt_lines={ {{">> ", "NonText"}, {"krealloc", "Identifier"}, {": change the size of an allocation"}}};
@@ -1170,6 +3896,7 @@ if (h->n_buckets < new_n_buckets) { // expand
]]}
meths.buf_clear_namespace(0, ns, 0, -1)
+ -- Cursor should be drawn on the correct line. #22704
screen:expect{grid=[[
if (h->n_buckets < new_n_buckets) { // expand |
khkey_t *new_keys = (khkey_t *) |
@@ -1177,8 +3904,8 @@ if (h->n_buckets < new_n_buckets) { // expand
hkey_t)); |
h->keys = new_keys; |
if (kh_is_map && val_size) { |
- char *new_vals = {3:krealloc}( h->vals_buf, new_n_|
- buck^ets * val_size); |
+ ^char *new_vals = {3:krealloc}( h->vals_buf, new_n_|
+ buckets * val_size); |
h->vals_buf = new_vals; |
} |
} |
@@ -1186,9 +3913,8 @@ if (h->n_buckets < new_n_buckets) { // expand
]]}
end)
-
it('works with text at the beginning of the buffer', function()
- insert(example_text)
+ insert(example_text2)
feed 'gg'
screen:expect{grid=[[
@@ -1249,7 +3975,7 @@ if (h->n_buckets < new_n_buckets) { // expand
end)
it('works with text at the end of the buffer', function()
- insert(example_text)
+ insert(example_text2)
feed 'G'
screen:expect{grid=[[
@@ -1368,7 +4094,7 @@ if (h->n_buckets < new_n_buckets) { // expand
end)
it('works beyond end of the buffer with virt_lines_above', function()
- insert(example_text)
+ insert(example_text2)
feed 'G'
screen:expect{grid=[[
@@ -1639,7 +4365,7 @@ if (h->n_buckets < new_n_buckets) { // expand
end)
it('works with sign and numbercolumns', function()
- insert(example_text)
+ insert(example_text2)
feed 'gg'
command 'set number signcolumn=yes'
screen:expect{grid=[[
@@ -1704,8 +4430,8 @@ if (h->n_buckets < new_n_buckets) { // expand
end)
- it('works with hard tabs', function()
- insert(example_text)
+ it('works with hard TABs', function()
+ insert(example_text2)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, 0, {
virt_lines={ {{">>", "NonText"}, {"\tvery\ttabby", "Identifier"}, {"text\twith\ttabs"}}};
@@ -1774,6 +4500,106 @@ if (h->n_buckets < new_n_buckets) { // expand
]]}
end)
+ it('does not show twice if end_row or end_col is specified #18622', function()
+ screen:try_resize(50, 8)
+ insert([[
+ aaa
+ bbb
+ ccc
+ ddd]])
+ meths.buf_set_extmark(0, ns, 0, 0, {end_row = 2, virt_lines = {{{'VIRT LINE 1', 'NonText'}}}})
+ meths.buf_set_extmark(0, ns, 3, 0, {end_col = 2, virt_lines = {{{'VIRT LINE 2', 'NonText'}}}})
+ screen:expect{grid=[[
+ aaa |
+ {1:VIRT LINE 1} |
+ bbb |
+ ccc |
+ dd^d |
+ {1:VIRT LINE 2} |
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('works with rightleft', function()
+ screen:try_resize(50, 8)
+ insert([[
+ aaa
+ bbb
+ ccc
+ ddd]])
+ command('set number rightleft')
+ meths.buf_set_extmark(0, ns, 0, 0, {virt_lines = {{{'VIRT LINE 1', 'NonText'}}}, virt_lines_leftcol = true})
+ meths.buf_set_extmark(0, ns, 3, 0, {virt_lines = {{{'VIRT LINE 2', 'NonText'}}}})
+ screen:expect{grid=[[
+ aaa{9: 1 }|
+ {1:1 ENIL TRIV}|
+ bbb{9: 2 }|
+ ccc{9: 3 }|
+ ^ddd{9: 4 }|
+ {1:2 ENIL TRIV}{9: }|
+ {1: ~}|
+ |
+ ]]}
+ end)
+
+ it('works when using dd or yyp #23915 #23916', function()
+ insert([[
+ line1
+ line2
+ line3
+ line4
+ line5]])
+ meths.buf_set_extmark(0, ns, 0, 0, {virt_lines={{{"foo"}}, {{"bar"}}, {{"baz"}}}})
+ screen:expect{grid=[[
+ line1 |
+ foo |
+ bar |
+ baz |
+ line2 |
+ line3 |
+ line4 |
+ line^5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ feed('gg')
+ feed('dd')
+ screen:expect{grid=[[
+ ^line2 |
+ foo |
+ bar |
+ baz |
+ line3 |
+ line4 |
+ line5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ feed('yyp')
+ screen:expect{grid=[[
+ line2 |
+ foo |
+ bar |
+ baz |
+ ^line2 |
+ line3 |
+ line4 |
+ line5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
end)
describe('decorations: signs', function()
@@ -1789,10 +4615,10 @@ describe('decorations: signs', function()
}
ns = meths.create_namespace 'test'
- meths.win_set_option(0, 'signcolumn', 'auto:9')
+ meths.set_option_value('signcolumn', 'auto:9', {})
end)
- local example_text = [[
+ local example_test3 = [[
l1
l2
l3
@@ -1801,7 +4627,7 @@ l5
]]
it('can add a single sign (no end row)', function()
- insert(example_text)
+ insert(example_test3)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S'})
@@ -1822,7 +4648,7 @@ l5
end)
it('can add a single sign (with end row)', function()
- insert(example_text)
+ insert(example_test3)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row=1})
@@ -1842,9 +4668,29 @@ l5
end)
+ it('can add a single sign and text highlight', function()
+ insert(example_test3)
+ feed 'gg'
+
+ meths.buf_set_extmark(0, ns, 1, 0, {sign_text='S', hl_group='Todo', end_col=1})
+ screen:expect{grid=[[
+ {1: }^l1 |
+ S {3:l}2 |
+ {1: }l3 |
+ {1: }l4 |
+ {1: }l5 |
+ {1: } |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ |
+ ]]}
+
+ meths.buf_clear_namespace(0, ns, 0, -1)
+ end)
+
it('can add multiple signs (single extmark)', function()
- pending('TODO(lewis6991): Support ranged signs')
- insert(example_text)
+ insert(example_test3)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row = 2})
@@ -1865,8 +4711,7 @@ l5
end)
it('can add multiple signs (multiple extmarks)', function()
- pending('TODO(lewis6991): Support ranged signs')
- insert(example_text)
+ insert(example_test3)
feed'gg'
meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S1'})
@@ -1884,21 +4729,19 @@ l5
{2:~ }|
|
]]}
-
end)
it('can add multiple signs (multiple extmarks) 2', function()
- insert(example_text)
+ insert(example_test3)
feed 'gg'
- meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S1'})
- meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2'})
-
+ meths.buf_set_extmark(0, ns, 3, -1, {sign_text='S1'})
+ meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row = 3})
screen:expect{grid=[[
{1: }^l1 |
- S2S1l2 |
- {1: }l3 |
- {1: }l4 |
+ S2{1: }l2 |
+ S2{1: }l3 |
+ S1S2l4 |
{1: }l5 |
{1: } |
{2:~ }|
@@ -1906,29 +4749,11 @@ l5
{2:~ }|
|
]]}
-
- -- TODO(lewis6991): Support ranged signs
- -- meths.buf_set_extmark(1, ns, 1, -1, {sign_text='S3', end_row = 2})
-
- -- screen:expect{grid=[[
- -- {1: }^l1 |
- -- S3S2S1l2 |
- -- S3{1: }l3 |
- -- {1: }l4 |
- -- {1: }l5 |
- -- {1: } |
- -- {2:~ }|
- -- {2:~ }|
- -- {2:~ }|
- -- |
- -- ]]}
-
end)
it('can add multiple signs (multiple extmarks) 3', function()
- pending('TODO(lewis6991): Support ranged signs')
- insert(example_text)
+ insert(example_test3)
feed 'gg'
meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S1', end_row=2})
@@ -1937,7 +4762,7 @@ l5
screen:expect{grid=[[
{1: }^l1 |
S1{1: }l2 |
- S2S1l3 |
+ S1S2l3 |
S2{1: }l4 |
{1: }l5 |
{1: } |
@@ -1949,7 +4774,7 @@ l5
end)
it('can add multiple signs (multiple extmarks) 4', function()
- insert(example_text)
+ insert(example_test3)
feed 'gg'
meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=0})
@@ -1970,7 +4795,7 @@ l5
end)
it('works with old signs', function()
- insert(example_text)
+ insert(example_test3)
feed 'gg'
helpers.command('sign define Oldsign text=x')
@@ -1982,7 +4807,7 @@ l5
meths.buf_set_extmark(0, ns, 2, -1, {sign_text='S5'})
screen:expect{grid=[[
- S4S1^l1 |
+ S1S4^l1 |
x S2l2 |
S5{1: }l3 |
{1: }l4 |
@@ -1996,8 +4821,7 @@ l5
end)
it('works with old signs (with range)', function()
- pending('TODO(lewis6991): Support ranged signs')
- insert(example_text)
+ insert(example_test3)
feed 'gg'
helpers.command('sign define Oldsign text=x')
@@ -2010,9 +4834,9 @@ l5
meths.buf_set_extmark(0, ns, 2, -1, {sign_text='S5'})
screen:expect{grid=[[
- S3S4S1^l1 |
- S2S3x l2 |
- S5S3{1: }l3 |
+ S1S3S4^l1 |
+ x S2S3l2 |
+ S3S5{1: }l3 |
S3{1: }l4 |
S3{1: }l5 |
{1: } |
@@ -2024,9 +4848,7 @@ l5
end)
it('can add a ranged sign (with start out of view)', function()
- pending('TODO(lewis6991): Support ranged signs')
-
- insert(example_text)
+ insert(example_test3)
command 'set signcolumn=yes:2'
feed 'gg'
feed '2<C-e>'
@@ -2068,26 +4890,26 @@ l5
end
screen:expect{grid=[[
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
- X Y Z W {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:^h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:h} |
+ W X Y Z {3:a} {3:b} {3:c} {3:d} {3:e} {3:f} {3:g} {3:^h} |
|
]]}
end)
it('works with priority #19716', function()
screen:try_resize(20, 3)
- insert(example_text)
+ insert(example_test3)
feed 'gg'
- helpers.command('sign define Oldsign text=O3')
- helpers.command([[exe 'sign place 42 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command('sign define Oldsign text=O3')
+ command([[exe 'sign place 42 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S4', priority=100})
meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S2', priority=5})
@@ -2101,7 +4923,7 @@ l5
]]}
-- Check truncation works too
- meths.win_set_option(0, 'signcolumn', 'auto')
+ meths.set_option_value('signcolumn', 'auto', {})
screen:expect{grid=[[
S5^l1 |
@@ -2109,6 +4931,52 @@ l5
|
]]}
end)
+
+ it('does not overflow with many old signs #23852', function()
+ screen:try_resize(20, 3)
+
+ command('set signcolumn:auto:9')
+ command('sign define Oldsign text=O3')
+ command([[exe 'sign place 01 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 02 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 03 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 04 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 05 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 06 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 07 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 08 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ command([[exe 'sign place 09 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]])
+ screen:expect{grid=[[
+ O3O3O3O3O3O3O3O3O3^ |
+ {2:~ }|
+ |
+ ]]}
+
+ meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1})
+ screen:expect_unchanged()
+
+ meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200})
+ screen:expect{grid=[[
+ O3O3O3O3O3O3O3O3S5^ |
+ {2:~ }|
+ |
+ ]]}
+
+ assert_alive()
+ end)
+
+ it('does not set signcolumn for signs without text', function()
+ screen:try_resize(20, 3)
+ meths.set_option_value('signcolumn', 'auto', {})
+ insert(example_test3)
+ feed 'gg'
+ meths.buf_set_extmark(0, ns, 0, -1, {number_hl_group='Error'})
+ screen:expect{grid=[[
+ ^l1 |
+ l2 |
+ |
+ ]]}
+ end)
end)
describe('decorations: virt_text', function()
diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua
index dbdf3823ec..92b7235885 100644
--- a/test/functional/ui/diff_spec.lua
+++ b/test/functional/ui/diff_spec.lua
@@ -1251,6 +1251,98 @@ AAAB]]
]]}
end)
end)
+
+ it('redraws with a change to non-current buffer', function()
+ write_file(fname, "aaa\nbbb\nccc\n\nxx", false)
+ write_file(fname_2, "aaa\nbbb\nccc\n\nyy", false)
+ reread()
+ local buf = meths.get_current_buf()
+ command('botright new')
+ screen:expect{grid=[[
+ {1: }aaa │{1: }aaa |
+ {1: }bbb │{1: }bbb |
+ {1: }ccc │{1: }ccc |
+ {1: } │{1: } |
+ {1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
+ {6:~ }│{6:~ }|
+ {3:<onal-diff-screen-1 <l-diff-screen-1.2 }|
+ ^ |
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {7:[No Name] }|
+ :e |
+ ]]}
+
+ meths.buf_set_lines(buf, 1, 2, true, {'BBB'})
+ screen:expect{grid=[[
+ {1: }aaa │{1: }aaa |
+ {1: }{8:BBB}{9: }│{1: }{8:bbb}{9: }|
+ {1: }ccc │{1: }ccc |
+ {1: } │{1: } |
+ {1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
+ {6:~ }│{6:~ }|
+ {3:<-diff-screen-1 [+] <l-diff-screen-1.2 }|
+ ^ |
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {6:~ }|
+ {7:[No Name] }|
+ :e |
+ ]]}
+ end)
+
+ it('redraws with a change current buffer in another window', function()
+ write_file(fname, "aaa\nbbb\nccc\n\nxx", false)
+ write_file(fname_2, "aaa\nbbb\nccc\n\nyy", false)
+ reread()
+ local buf = meths.get_current_buf()
+ command('botright split | diffoff')
+ screen:expect{grid=[[
+ {1: }aaa │{1: }aaa |
+ {1: }bbb │{1: }bbb |
+ {1: }ccc │{1: }ccc |
+ {1: } │{1: } |
+ {1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
+ {6:~ }│{6:~ }|
+ {3:<onal-diff-screen-1 <l-diff-screen-1.2 }|
+ ^aaa |
+ bbb |
+ ccc |
+ |
+ xx |
+ {6:~ }|
+ {6:~ }|
+ {7:Xtest-functional-diff-screen-1 }|
+ :e |
+ ]]}
+
+ meths.buf_set_lines(buf, 1, 2, true, {'BBB'})
+ screen:expect{grid=[[
+ {1: }aaa │{1: }aaa |
+ {1: }{8:BBB}{9: }│{1: }{8:bbb}{9: }|
+ {1: }ccc │{1: }ccc |
+ {1: } │{1: } |
+ {1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
+ {6:~ }│{6:~ }|
+ {3:<-diff-screen-1 [+] <l-diff-screen-1.2 }|
+ ^aaa |
+ BBB |
+ ccc |
+ |
+ xx |
+ {6:~ }|
+ {6:~ }|
+ {7:Xtest-functional-diff-screen-1 [+] }|
+ :e |
+ ]]}
+ end)
end)
it('win_update redraws lines properly', function()
@@ -1325,6 +1417,7 @@ it('win_update redraws lines properly', function()
]]}
end)
+-- oldtest: Test_diff_rnu()
it('diff updates line numbers below filler lines', function()
clear()
local screen = Screen.new(40, 14)
@@ -1401,6 +1494,7 @@ it('diff updates line numbers below filler lines', function()
]])
end)
+-- oldtest: Test_diff_with_scroll_and_change()
it('Align the filler lines when changing text in diff mode', function()
clear()
local screen = Screen.new(40, 20)
diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua
index cd2b48213d..9729f65355 100644
--- a/test/functional/ui/embed_spec.lua
+++ b/test/functional/ui/embed_spec.lua
@@ -5,7 +5,12 @@ local Screen = require('test.functional.ui.screen')
local feed = helpers.feed
local eq = helpers.eq
+local neq = helpers.neq
local clear = helpers.clear
+local ok = helpers.ok
+local funcs = helpers.funcs
+local nvim_prog = helpers.nvim_prog
+local retry = helpers.retry
local function test_embed(ext_linegrid)
local screen
@@ -98,6 +103,7 @@ describe('--embed UI', function()
-- attach immediately after startup, for early UI
local screen = Screen.new(40, 8)
+ screen.rpc_async = true -- Avoid hanging. #24888
screen:attach {stdin_fd=3}
screen:set_default_attr_ids {
[1] = {bold = true, foreground = Screen.colors.Blue1};
@@ -132,3 +138,50 @@ describe('--embed UI', function()
]]}
end)
end)
+
+describe('--embed --listen UI', function()
+ it('waits for connection on listening address', function()
+ helpers.skip(helpers.is_os('win'))
+ clear()
+ local child_server = assert(helpers.new_pipename())
+ funcs.jobstart({nvim_prog, '--embed', '--listen', child_server, '--clean'})
+ retry(nil, nil, function() neq(nil, uv.fs_stat(child_server)) end)
+
+ local child_session = helpers.connect(child_server)
+
+ local info_ok, api_info = child_session:request('nvim_get_api_info')
+ ok(info_ok)
+ eq(2, #api_info)
+ ok(api_info[1] > 2, 'channel_id > 2', api_info[1])
+
+ child_session:request('nvim_exec2', [[
+ let g:evs = []
+ autocmd UIEnter * call add(g:evs, $"UIEnter:{v:event.chan}")
+ autocmd VimEnter * call add(g:evs, "VimEnter")
+ ]], {})
+
+ -- VimEnter and UIEnter shouldn't be triggered until after attach
+ local var_ok, var = child_session:request('nvim_get_var', 'evs')
+ ok(var_ok)
+ eq({}, var)
+
+ local child_screen = Screen.new(40, 6)
+ child_screen:attach(nil, child_session)
+ child_screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] 0,0-1 All}|
+ |
+ ]], attr_ids={
+ [1] = {foreground = Screen.colors.Blue, bold = true};
+ [2] = {reverse = true, bold = true};
+ }}
+
+ -- VimEnter and UIEnter should now be triggered
+ var_ok, var = child_session:request('nvim_get_var', 'evs')
+ ok(var_ok)
+ eq({'VimEnter', ('UIEnter:%d'):format(api_info[1])}, var)
+ end)
+end)
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
index 6759510ad1..2902b4a4a5 100644
--- a/test/functional/ui/float_spec.lua
+++ b/test/functional/ui/float_spec.lua
@@ -9,6 +9,7 @@ local eval = helpers.eval
local eq = helpers.eq
local neq = helpers.neq
local expect = helpers.expect
+local exec = helpers.exec
local exec_lua = helpers.exec_lua
local insert = helpers.insert
local meths = helpers.meths
@@ -65,20 +66,20 @@ describe('float window', function()
it('closed immediately by autocmd #11383', function()
eq('Window was closed immediately',
pcall_err(exec_lua, [[
- local a = vim.api
+ local api = vim.api
local function crashes(contents)
- local buf = a.nvim_create_buf(false, true)
- local floatwin = a.nvim_open_win(buf, true, {
+ local buf = api.nvim_create_buf(false, true)
+ local floatwin = api.nvim_open_win(buf, true, {
relative = 'cursor';
style = 'minimal';
row = 0; col = 0;
height = #contents;
width = 10;
})
- a.nvim_buf_set_lines(buf, 0, -1, true, contents)
+ api.nvim_buf_set_lines(buf, 0, -1, true, contents)
local winnr = vim.fn.win_id2win(floatwin)
- a.nvim_command('wincmd p')
- a.nvim_command('autocmd CursorMoved * ++once '..winnr..'wincmd c')
+ api.nvim_command('wincmd p')
+ api.nvim_command('autocmd BufEnter * ++once '..winnr..'wincmd c')
return buf, floatwin
end
crashes{'foo'}
@@ -102,9 +103,32 @@ describe('float window', function()
assert_alive()
end)
+ it('open with WinNew autocmd', function()
+ local res = exec_lua([[
+ local triggerd = false
+ local buf = vim.api.nvim_create_buf(true, true)
+ vim.api.nvim_create_autocmd('WinNew', {
+ callback = function(opt)
+ if opt.buf == buf then
+ triggerd = true
+ end
+ end
+ })
+ local opts = {
+ relative = "win",
+ row = 0, col = 0,
+ width = 1, height = 1,
+ noautocmd = false,
+ }
+ vim.api.nvim_open_win(buf, true, opts)
+ return triggerd
+ ]])
+ eq(true, res)
+ end)
+
it('opened with correct height', function()
local height = exec_lua([[
- vim.api.nvim_set_option("winheight", 20)
+ vim.go.winheight = 20
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
@@ -126,7 +150,7 @@ describe('float window', function()
it('opened with correct width', function()
local width = exec_lua([[
- vim.api.nvim_set_option("winwidth", 20)
+ vim.go.winwidth = 20
local bufnr = vim.api.nvim_create_buf(false, true)
local opts = {
@@ -414,6 +438,46 @@ describe('float window', function()
eq(winids, eval('winids'))
end)
+ it("open does not trigger BufEnter #15300", function()
+ local res = exec_lua[[
+ local times = {}
+ local buf = vim.api.nvim_create_buf(fasle, true)
+ vim.api.nvim_create_autocmd('BufEnter', {
+ callback = function(opt)
+ if opt.buf == buf then
+ times[#times + 1] = 1
+ end
+ end
+ })
+ local win_id
+ local fconfig = {
+ relative = 'editor',
+ row = 10,
+ col = 10,
+ width = 10,
+ height = 10,
+ }
+ --enter is false doesn't trigger
+ win_id = vim.api.nvim_open_win(buf, false, fconfig)
+ vim.api.nvim_win_close(win_id, true)
+ times[#times + 1] = #times == 0 and true or nil
+
+ --enter is true trigger
+ win_id = vim.api.nvim_open_win(buf, true, fconfig)
+ vim.api.nvim_win_close(win_id, true)
+ times[#times + 1] = #times == 2 and true or nil
+
+ --enter is true and fconfig.noautocmd is true doesn't trigger
+ fconfig.noautocmd = true
+ win_id = vim.api.nvim_open_win(buf, true, fconfig)
+ vim.api.nvim_win_close(win_id, true)
+ times[#times + 1] = #times == 2 and true or nil
+
+ return times
+ ]]
+ eq({true, 1, true}, res)
+ end)
+
it('no crash with bufpos and non-existent window', function()
command('new')
local closed_win = meths.get_current_win().id
@@ -426,17 +490,57 @@ describe('float window', function()
it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts)
- meths.win_set_option(float_win, 'fillchars', NIL)
+ meths.set_option_value('fillchars', NIL, {win=float_win.id})
float_opts.style = 'minimal'
meths.win_set_config(float_win, float_opts)
assert_alive()
+ end)
+
+ it("should re-apply 'style' when present", function()
+ local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1}
+ local float_win = meths.open_win(0, true, float_opts)
+ meths.set_option_value('number', true, { win = float_win })
+ float_opts.row = 2
+ meths.win_set_config(float_win, float_opts)
+ eq(false, meths.get_option_value('number', { win = float_win }))
+ end)
+
+ it("should not re-apply 'style' when missing", function()
+ local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1}
+ local float_win = meths.open_win(0, true, float_opts)
+ meths.set_option_value('number', true, { win = float_win })
+ float_opts.row = 2
+ float_opts.style = nil
+ meths.win_set_config(float_win, float_opts)
+ eq(true, meths.get_option_value('number', { win = float_win }))
end)
it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function()
- meths.set_option('splitkeep', 'screen')
+ meths.set_option_value('splitkeep', 'screen', {})
local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10}
local float_win = meths.open_win(0, true, float_opts)
- eq(5, meths.win_get_option(float_win, 'scroll'))
+ eq(5, meths.get_option_value('scroll', {win=float_win.id}))
+ end)
+
+ it(':unhide works when there are floating windows', function()
+ local float_opts = {relative = 'editor', row = 1, col = 1, width = 5, height = 5}
+ local w0 = curwin()
+ meths.open_win(0, false, float_opts)
+ meths.open_win(0, false, float_opts)
+ eq(3, #meths.list_wins())
+ command('unhide')
+ eq({ w0 }, meths.list_wins())
+ end)
+
+ it(':all works when there are floating windows', function()
+ command('args Xa.txt')
+ local float_opts = {relative = 'editor', row = 1, col = 1, width = 5, height = 5}
+ local w0 = curwin()
+ meths.open_win(0, false, float_opts)
+ meths.open_win(0, false, float_opts)
+ eq(3, #meths.list_wins())
+ command('all')
+ eq({ w0 }, meths.list_wins())
end)
describe('with only one tabpage,', function()
@@ -738,7 +842,7 @@ describe('float window', function()
[4] = {bold = true, reverse = true},
[5] = {reverse = true},
[6] = {background = Screen.colors.LightMagenta, bold = true, reverse = true},
- [7] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
+ [7] = {foreground = Screen.colors.White, background = Screen.colors.Red},
[8] = {bold = true, foreground = Screen.colors.SeaGreen4},
[9] = {background = Screen.colors.LightGrey, underline = true},
[10] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta},
@@ -879,6 +983,71 @@ describe('float window', function()
end
end)
+ it('window position fixed', function()
+ command('rightbelow 20vsplit')
+ local buf = meths.create_buf(false,false)
+ local win = meths.open_win(buf, false, {
+ relative='win', width=15, height=2, row=2, col=10, anchor='NW', fixed=true})
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ {5:[No Name] }{4:[No Name] }|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 5
+ {1: }|
+ {2:~ }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NW", 4, 2, 10, true};
+ }}
+ else
+ screen:expect([[
+ {5:│}^ |
+ {0:~ }{5:│}{0:~ }|
+ {0:~ }{5:│}{0:~ }{1: }|
+ {0:~ }{5:│}{0:~ }{2:~ }|
+ {0:~ }{5:│}{0:~ }|
+ {5:[No Name] }{4:[No Name] }|
+ |
+ ]])
+ end
+
+ meths.win_set_config(win, {fixed=false})
+
+ if multigrid then
+ screen:expect_unchanged()
+ else
+ screen:expect([[
+ {5:│}^ |
+ {0:~ }{5:│}{0:~ }|
+ {0:~ }{5:│}{0:~ }{1: }|
+ {0:~ }{5:│}{0:~ }{2:~ }|
+ {0:~ }{5:│}{0:~ }|
+ {5:[No Name] }{4:[No Name] }|
+ |
+ ]])
+ end
+ end)
+
it('draws correctly with redrawdebug=compositor', function()
-- NB: we do not test that it produces the "correct" debug info
-- (as it is intermediate only, and is allowed to change by internal
@@ -1003,14 +1172,14 @@ describe('float window', function()
it('return their configuration', function()
local buf = meths.create_buf(false, false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5, zindex=60})
- local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20, zindex=60}
+ local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20, zindex=60, hide=false}
eq(expected, meths.win_get_config(win))
- eq({relative='', external=false, focusable=true}, meths.win_get_config(0))
+ eq({relative='', external=false, focusable=true, hide=false}, meths.win_get_config(0))
if multigrid then
meths.win_set_config(win, {external=true, width=10, height=1})
- eq({external=true,focusable=true,width=10,height=1,relative=''}, meths.win_get_config(win))
+ eq({external=true,focusable=true,width=10,height=1,relative='',hide=false}, meths.win_get_config(win))
end
end)
@@ -1425,16 +1594,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔═════════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1468,16 +1637,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:┌─────────┐}|
{5:│}{1: halloj! }{5:│}|
{5:│}{1: BORDAA }{5:│}|
{5:└─────────┘}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1511,16 +1680,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╭─────────╮}|
{5:│}{1: halloj! }{5:│}|
{5:│}{1: BORDAA }{5:│}|
{5:╰─────────╯}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1554,16 +1723,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5: }|
{5: }{1: halloj! }{5: }|
{5: }{1: BORDAA }{5: }|
{5: }|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1598,16 +1767,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:x}{7:ååååååååå}{5:\}|
{17:n̈̊}{1: halloj! }{17:n̈̊}|
{17:n̈̊}{1: BORDAA }{17:n̈̊}|
{5:\}{7:ååååååååå}{5:x}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1641,14 +1810,14 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1: halloj! }|
{1: BORDAA }|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1682,14 +1851,14 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:<}{1: halloj! }{5:>}|
{5:<}{1: BORDAA }{5:>}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1723,16 +1892,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:_________}|
{1: halloj! }|
{1: BORDAA }|
{5:---------}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1774,15 +1943,15 @@ describe('float window', function()
^ |
## grid 3
|
- ## grid 5
+ ## grid 4
{1: halloj! }{25: }|
{1: BORDAA }{26: }|
{25: }{26: }|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 6, curline = 5, curcol = 0, linecount = 6};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 6, curline = 5, curcol = 0, linecount = 6, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1831,6 +2000,94 @@ describe('float window', function()
eq('center', title_pos)
end)
+ it('validates footer footer_pos', function()
+ local buf = meths.create_buf(false,false)
+ eq("footer requires border to be set",
+ pcall_err(meths.open_win,buf, false, {
+ relative='editor', width=9, height=2, row=2, col=5, footer='Footer',
+ }))
+ eq("footer_pos requires footer to be set",
+ pcall_err(meths.open_win,buf, false, {
+ relative='editor', width=9, height=2, row=2, col=5,
+ border='single', footer_pos='left',
+ }))
+ end)
+
+ it('validate footer_pos in nvim_win_get_config', function()
+ local footer_pos = exec_lua([[
+ local bufnr = vim.api.nvim_create_buf(false, false)
+ local opts = {
+ relative = 'editor',
+ col = 2,
+ row = 5,
+ height = 2,
+ width = 9,
+ border = 'double',
+ footer = 'Test',
+ footer_pos = 'center'
+ }
+
+ local win_id = vim.api.nvim_open_win(bufnr, true, opts)
+ return vim.api.nvim_win_get_config(win_id).footer_pos
+ ]])
+
+ eq('center', footer_pos)
+ end)
+
+ it('center aligned title longer than window width #25746', function()
+ local buf = meths.create_buf(false, false)
+ meths.buf_set_lines(buf, 0, -1, true, {' halloj! ',
+ ' BORDAA '})
+ local win = meths.open_win(buf, false, {
+ relative='editor', width=9, height=2, row=2, col=5, border="double",
+ title = "abcdefghijklmnopqrstuvwxyz",title_pos = "center",
+ })
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔}{11:abcdefghi}{5:╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚═════════╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔}{11:abcdefghi}{5:╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚═════════╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_close(win, false)
+ assert_alive()
+ end)
it('border with title', function()
local buf = meths.create_buf(false, false)
@@ -1860,16 +2117,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔}{11:Left}{5:═════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1903,16 +2160,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔═}{11:Center}{5:══╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1946,16 +2203,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔════}{11:Right}{5:╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -1989,16 +2246,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔═════}🦄BB{5:╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -2013,9 +2270,376 @@ describe('float window', function()
end
end)
+ it('border with footer', function()
+ local buf = meths.create_buf(false, false)
+ meths.buf_set_lines(buf, 0, -1, true, {' halloj! ',
+ ' BORDAA '})
+ local win = meths.open_win(buf, false, {
+ relative='editor', width=9, height=2, row=2, col=5, border="double",
+ footer = "Left",footer_pos = "left",
+ })
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚}{11:Left}{5:═════╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═════════╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚}{11:Left}{5:═════╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_set_config(win, {footer= "Center",footer_pos="center"})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚═}{11:Center}{5:══╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═════════╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚═}{11:Center}{5:══╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_set_config(win, {footer= "Right",footer_pos="right"})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚════}{11:Right}{5:╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═════════╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚════}{11:Right}{5:╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_set_config(win, {footer= { {"🦄"},{"BB"}},footer_pos="right"})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚═════}🦄BB{5:╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═════════╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚═════}🦄BB{5:╝}{0: }|
+ |
+ ]]}
+ end
+ end)
+
+ it('border with title and footer', function()
+ local buf = meths.create_buf(false, false)
+ meths.buf_set_lines(buf, 0, -1, true, {' halloj! ',
+ ' BORDAA '})
+ local win = meths.open_win(buf, false, {
+ relative='editor', width=9, height=2, row=2, col=5, border="double",
+ title = "Left", title_pos = "left", footer = "Right", footer_pos = "right",
+ })
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔}{11:Left}{5:═════╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚════}{11:Right}{5:╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔}{11:Left}{5:═════╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚════}{11:Right}{5:╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_set_config(win, {title= "Center",title_pos="center",footer= "Center",footer_pos="center"})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═}{11:Center}{5:══╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚═}{11:Center}{5:══╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═}{11:Center}{5:══╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚═}{11:Center}{5:══╝}{0: }|
+ |
+ ]]}
+ end
+
+ meths.win_set_config(win, {title= "Right",title_pos="right",footer= "Left",footer_pos="left"})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔════}{11:Right}{5:╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚}{11:Left}{5:═════╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔════}{11:Right}{5:╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚}{11:Left}{5:═════╝}{0: }|
+ |
+ ]]}
+ end
+
+ command('hi B0 guibg=Red guifg=Black')
+ command('hi B1 guifg=White')
+ meths.win_set_config(win, {
+ title = {{"🦄"}, {"BB", {"B0", "B1"}}}, title_pos = "right",
+ footer= {{"🦄"}, {"BB", {"B0", "B1"}}}, footer_pos = "right",
+ })
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════}🦄{7:BB}{5:╗}|
+ {5:║}{1: halloj! }{5:║}|
+ {5:║}{1: BORDAA }{5:║}|
+ {5:╚═════}🦄{7:BB}{5:╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 2, 5, true }
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }{5:╔═════}🦄{7:BB}{5:╗}{0: }|
+ {0:~ }{5:║}{1: halloj! }{5:║}{0: }|
+ {0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
+ {0:~ }{5:╚═════}🦄{7:BB}{5:╝}{0: }|
+ |
+ ]]}
+ end
+ end)
+
it('terminates border on edge of viewport when window extends past viewport', function()
local buf = meths.create_buf(false, false)
- meths.open_win(buf, false, {relative='editor', width=40, height=7, row=0, col=0, border="single"})
+ meths.open_win(buf, false, {relative='editor', width=40, height=7, row=0, col=0, border="single", zindex=201})
if multigrid then
screen:expect{grid=[[
## grid 1
@@ -2046,10 +2670,10 @@ describe('float window', function()
{5:│}{2:~ }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [4] = { { id = 1001 }, "NW", 1, 0, 0, true }
+ [4] = { { id = 1001 }, "NW", 1, 0, 0, true, 201 }
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -2058,8 +2682,8 @@ describe('float window', function()
{5:│}{2:~ }{5:│}|
{5:│}{2:~ }{5:│}|
{5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
{5:└──────────────────────────────────────┘}|
- |
]]}
end
end)
@@ -2097,17 +2721,17 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:╔═════════╗}|
{5:║}{1:aaa aab }{5:║}|
{5:║}{1:abb acc }{5:║}|
{5:║}{1:^ }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 0, 5, true }
+ [4] = { { id = 1001 }, "NW", 1, 0, 5, true };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 2, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 2, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -2150,23 +2774,23 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- }{8:match 1 of 4} |
- ## grid 5
+ ## grid 4
{5:╔═════════╗}|
{5:║}{1:aaa aab }{5:║}|
{5:║}{1:abb acc }{5:║}|
{5:║}{1:acc^ }{5:║}|
{5:╚═════════╝}|
- ## grid 6
+ ## grid 5
{1: aaa }|
{1: aab }|
{1: abb }|
{13: acc }|
]], float_pos={
- [5] = { { id = 1002 }, "NW", 1, 0, 5, true, 50 },
- [6] = { { id = -1 }, "NW", 5, 4, 0, false, 100 }
+ [4] = { { id = 1001 }, "NW", 1, 0, 5, true, 50 };
+ [5] = { { id = -1 }, "NW", 4, 4, 0, false, 100 };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 2, curcol = 3, linecount=3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 2, curcol = 3, linecount=3, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -2182,6 +2806,374 @@ describe('float window', function()
{3:-- }{8:match 1 of 4} |
]]}
end
+
+ feed '<esc>'
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1:aaa aab }{5:║}|
+ {5:║}{1:abb acc }{5:║}|
+ {5:║}{1:ac^c }{5:║}|
+ {5:╚═════════╝}|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 0, 5, true };
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {5:╔═════════╗} |
+ {0:~ }{5:║}{1:aaa aab }{5:║}{0: }|
+ {0:~ }{5:║}{1:abb acc }{5:║}{0: }|
+ {0:~ }{5:║}{1:ac^c }{5:║}{0: }|
+ {0:~ }{5:╚═════════╝}{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end
+
+ exec([[
+ nnoremenu Test.foo :
+ nnoremenu Test.bar :
+ nnoremenu Test.baz :
+ ]])
+ feed ':popup Test<CR>'
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :popup Test |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1:aaa aab }{5:║}|
+ {5:║}{1:abb acc }{5:║}|
+ {5:║}{1:ac^c }{5:║}|
+ {5:╚═════════╝}|
+ ## grid 5
+ {1: foo }|
+ {1: bar }|
+ {1: baz }|
+ ]], float_pos={
+ [4] = { { id = 1001 }, "NW", 1, 0, 5, true };
+ [5] = { { id = -1 }, "NW", 4, 4, 2, false, 250 };
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {5:╔═════════╗} |
+ {0:~ }{5:║}{1:aaa aab }{5:║}{0: }|
+ {0:~ }{5:║}{1:abb acc }{5:║}{0: }|
+ {0:~ }{5:║}{1:ac^c }{5:║}{0: }|
+ {0:~ }{5:╚═}{1: foo }{5:═══╝}{0: }|
+ {0:~ }{1: bar }{0: }|
+ {0:~ }{1: baz }{0: }|
+ {0:~ }|
+ {0:~ }|
+ :popup Test |
+ ]]}
+ end
+ end)
+
+ it('show ruler of current floating window', function()
+ command 'set ruler'
+ local buf = meths.create_buf(false, false)
+ meths.buf_set_lines(buf, 0, -1, true, {'aaa aab ',
+ 'abb acc '})
+ meths.open_win(buf, true, {relative='editor', width=9, height=3, row=0, col=5})
+ feed 'gg'
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ 1,1 All |
+ ## grid 4
+ {1:^aaa aab }|
+ {1:abb acc }|
+ {2:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {1:^aaa aab } |
+ {0:~ }{1:abb acc }{0: }|
+ {0:~ }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ 1,1 All |
+ ]]}
+ end
+
+ feed 'w'
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ 1,5 All |
+ ## grid 4
+ {1:aaa ^aab }|
+ {1:abb acc }|
+ {2:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 4, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {1:aaa ^aab } |
+ {0:~ }{1:abb acc }{0: }|
+ {0:~ }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ 1,5 All |
+ ]]}
+ end
+ end)
+
+ it("correct ruler position in current float with 'rulerformat' set", function()
+ command 'set ruler rulerformat=fish:<><'
+ meths.open_win(0, true, {relative='editor', width=9, height=3, row=0, col=5})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ fish:<>< |
+ ## grid 4
+ {1:^ }|
+ {2:~ }|
+ {2:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {1:^ } |
+ {0:~ }{2:~ }{0: }|
+ {0:~ }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ fish:<>< |
+ ]]}
+ end
+ end)
+
+ it('does not show ruler of not-last current float during ins-completion', function()
+ screen:try_resize(50,9)
+ command 'set ruler showmode'
+ meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=0})
+ meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=5})
+ feed '<c-w>w'
+ neq('', meths.win_get_config(0).relative)
+ neq(funcs.winnr '$', funcs.winnr())
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [3:--------------------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ 0,0-1 All |
+ ## grid 4
+ {1: }|
+ {2:~ }|
+ {2:~ }|
+ ## grid 5
+ {1:^ }|
+ {2:~ }|
+ {2:~ }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 0, 0, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {1: } {1:^ } |
+ {2:~ }{0: }{2:~ }{0: }|
+ {2:~ }{0: }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ 0,0-1 All |
+ ]]}
+ end
+ feed 'i<c-x>'
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [3:--------------------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)} |
+ ## grid 4
+ {1: }|
+ {2:~ }|
+ {2:~ }|
+ ## grid 5
+ {1:^ }|
+ {2:~ }|
+ {2:~ }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 0, 0, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {1: } {1:^ } |
+ {2:~ }{0: }{2:~ }{0: }|
+ {2:~ }{0: }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)} |
+ ]]}
+ end
end)
it('can have minimum size', function()
@@ -2208,10 +3200,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:x}|
]], float_pos={
- [5] = {{id = 1002}, "NW", 2, 0, 4, false}
+ [4] = {{id = 1001}, "NW", 2, 0, 4, false}
}}
else
screen:expect([[
@@ -2245,10 +3237,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:x}|
]], float_pos={
- [5] = {{id = 1002}, "NW", 2, 0, 15, false}
+ [4] = {{id = 1001}, "NW", 2, 0, 15, false}
}}
else
screen:expect([[
@@ -2296,6 +3288,154 @@ describe('float window', function()
end
end)
+ describe('no crash when rearranging windows', function()
+ local function test_rearrange_windows(cmd)
+ command('set laststatus=2')
+ screen:try_resize(40, 13)
+
+ command('args X1 X2 X3 X4 X5 X6')
+ command('sargument 2')
+ command('sargument 3')
+ local w3 = curwin()
+ command('sargument 4')
+ local w4 = curwin()
+ command('sargument 5')
+ command('sargument 6')
+
+ local float_opts = { relative = 'editor', row = 6, col = 0, width = 40, height = 1 }
+ meths.win_set_config(w3, float_opts)
+ meths.win_set_config(w4, float_opts)
+ command('wincmd =')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [8:----------------------------------------]|
+ [8:----------------------------------------]|
+ {4:X6 }|
+ [7:----------------------------------------]|
+ [7:----------------------------------------]|
+ {5:X5 }|
+ [4:----------------------------------------]|
+ [4:----------------------------------------]|
+ {5:X2 }|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ {5:X1 }|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ |
+ {0:~ }|
+ ## grid 5
+ {1: }|
+ ## grid 6
+ {1: }|
+ ## grid 7
+ |
+ {0:~ }|
+ ## grid 8
+ ^ |
+ {0:~ }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NW", 1, 6, 0, true, 50};
+ [6] = {{id = 1003}, "NW", 1, 6, 0, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [6] = {win = {id = 1003}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [7] = {win = {id = 1004}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [8] = {win = {id = 1005}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {4:X6 }|
+ |
+ {0:~ }|
+ {5:X5 }|
+ {1: }|
+ {0:~ }|
+ {5:X2 }|
+ |
+ {0:~ }|
+ {5:X1 }|
+ |
+ ]]}
+ end
+
+ command(cmd)
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ {4:X1 }|
+ [4:----------------------------------------]|
+ {5:X2 }|
+ [9:----------------------------------------]|
+ {5:X3 }|
+ [10:----------------------------------------]|
+ {5:X4 }|
+ [7:----------------------------------------]|
+ {5:X5 }|
+ [8:----------------------------------------]|
+ {5:X6 }|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ ## grid 3
+ |
+ ## grid 4
+ |
+ ## grid 7
+ |
+ ## grid 8
+ |
+ ## grid 9
+ |
+ ## grid 10
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [7] = {win = {id = 1004}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [8] = {win = {id = 1005}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [9] = {win = {id = 1006}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [10] = {win = {id = 1007}, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {4:X1 }|
+ |
+ {5:X2 }|
+ |
+ {5:X3 }|
+ |
+ {5:X4 }|
+ |
+ {5:X5 }|
+ |
+ {5:X6 }|
+ |
+ ]]}
+ end
+ end
+
+ it('using :unhide', function()
+ test_rearrange_windows('unhide')
+ end)
+
+ it('using :all', function()
+ test_rearrange_windows('all')
+ end)
+ end)
+
it('API has proper error messages', function()
local buf = meths.create_buf(false,false)
eq("Invalid key: 'bork'",
@@ -2496,7 +3636,6 @@ describe('float window', function()
]])
end
-
meths.win_set_config(win, {relative='win', win=oldwin, row=1, col=10, anchor='NW'})
if multigrid then
screen:expect{grid=[[
@@ -2618,7 +3757,8 @@ describe('float window', function()
curline = 0,
curcol = 3,
linecount = 2,
- win = { id = 1000 }
+ sum_scroll_delta = 0,
+ win = { id = 1000 },
},
[4] = {
topline = 0,
@@ -2626,6 +3766,7 @@ describe('float window', function()
curline = 0,
curcol = 3,
linecount = 2,
+ sum_scroll_delta = 0,
win = { id = 1001 }
},
[5] = {
@@ -2634,6 +3775,7 @@ describe('float window', function()
curline = 0,
curcol = 0,
linecount = 1,
+ sum_scroll_delta = 0,
win = { id = 1002 }
}
}}
@@ -2741,13 +3883,13 @@ describe('float window', function()
{0:~ }|
{0:~ }|
{0:~ }|
- ## grid 6
+ ## grid 5
{5:╔═════════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [6] = {{id = 1003}, "NW", 4, 1, 14, true}
+ [5] = {{id = 1002}, "NW", 4, 1, 14, true}
}}
else
screen:expect([[
@@ -2798,13 +3940,13 @@ describe('float window', function()
{0:~ }|
{0:~ }|
{0:~ }|
- ## grid 6
+ ## grid 5
{5:╔═════════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [6] = {{id = 1003}, "NE", 4, 0, 14, true}
+ [5] = {{id = 1002}, "NE", 4, 0, 14, true}
}}
else
screen:expect([[
@@ -2855,13 +3997,13 @@ describe('float window', function()
{0:~ }|
{0:~ }|
{0:~ }|
- ## grid 6
+ ## grid 5
{5:╔═════════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [6] = {{id = 1003}, "SE", 4, 1, 14, true}
+ [5] = {{id = 1002}, "SE", 4, 1, 14, true}
}}
else
screen:expect([[
@@ -2912,13 +4054,13 @@ describe('float window', function()
{0:~ }|
{0:~ }|
{0:~ }|
- ## grid 6
+ ## grid 5
{5:╔═════════╗}|
{5:║}{1: halloj! }{5:║}|
{5:║}{1: BORDAA }{5:║}|
{5:╚═════════╝}|
]], float_pos={
- [6] = {{id = 1003}, "SW", 4, 0, 14, true}
+ [5] = {{id = 1002}, "SW", 4, 0, 14, true}
}}
else
screen:expect([[
@@ -2939,6 +4081,198 @@ describe('float window', function()
end
end)
+ it('anchored to another floating window updated in the same call #14735', function()
+ feed('i<CR><CR><CR><Esc>')
+
+ exec([[
+ let b1 = nvim_create_buf(v:true, v:false)
+ let b2 = nvim_create_buf(v:true, v:false)
+ let b3 = nvim_create_buf(v:true, v:false)
+ let b4 = nvim_create_buf(v:true, v:false)
+ let b5 = nvim_create_buf(v:true, v:false)
+ let b6 = nvim_create_buf(v:true, v:false)
+ let b7 = nvim_create_buf(v:true, v:false)
+ let b8 = nvim_create_buf(v:true, v:false)
+ call setbufline(b1, 1, '1')
+ call setbufline(b2, 1, '2')
+ call setbufline(b3, 1, '3')
+ call setbufline(b4, 1, '4')
+ call setbufline(b5, 1, '5')
+ call setbufline(b6, 1, '6')
+ call setbufline(b7, 1, '7')
+ call setbufline(b8, 1, '8')
+ let o1 = #{relative: 'editor', row: 1, col: 10, width: 5, height: 1}
+ let w1 = nvim_open_win(b1, v:false, o1)
+ let o2 = extendnew(o1, #{col: 30})
+ let w2 = nvim_open_win(b2, v:false, o2)
+ let o3 = extendnew(o1, #{relative: 'win', win: w1, anchor: 'NE', col: 0})
+ let w3 = nvim_open_win(b3, v:false, o3)
+ let o4 = extendnew(o3, #{win: w2})
+ let w4 = nvim_open_win(b4, v:false, o4)
+ let o5 = extendnew(o3, #{win: w3, anchor: 'SE', row: 0})
+ let w5 = nvim_open_win(b5, v:false, o5)
+ let o6 = extendnew(o5, #{win: w4})
+ let w6 = nvim_open_win(b6, v:false, o6)
+ let o7 = extendnew(o5, #{win: w5, anchor: 'SW', col: 5})
+ let w7 = nvim_open_win(b7, v:false, o7)
+ let o8 = extendnew(o7, #{win: w6})
+ let w8 = nvim_open_win(b8, v:false, o8)
+ ]])
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ |
+ |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 5
+ {1:1 }|
+ ## grid 6
+ {1:2 }|
+ ## grid 7
+ {1:3 }|
+ ## grid 8
+ {1:4 }|
+ ## grid 9
+ {1:5 }|
+ ## grid 10
+ {1:6 }|
+ ## grid 11
+ {1:7 }|
+ ## grid 12
+ {1:8 }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NW", 1, 1, 10, true, 50};
+ [6] = {{id = 1003}, "NW", 1, 1, 30, true, 50};
+ [7] = {{id = 1004}, "NE", 5, 1, 0, true, 50};
+ [8] = {{id = 1005}, "NE", 6, 1, 0, true, 50};
+ [9] = {{id = 1006}, "SE", 7, 0, 0, true, 50};
+ [10] = {{id = 1007}, "SE", 8, 0, 0, true, 50};
+ [11] = {{id = 1008}, "SW", 9, 0, 5, true, 50};
+ [12] = {{id = 1009}, "SW", 10, 0, 5, true, 50};
+ }}
+ else
+ screen:expect([[
+ {1:7 } {1:8 } |
+ {1:5 } {1:1 } {1:6 } {1:2 } |
+ {1:3 } {1:4 } |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ -- Reconfigure in different directions
+ exec([[
+ let o1 = extendnew(o1, #{anchor: 'NW'})
+ call nvim_win_set_config(w8, o1)
+ let o2 = extendnew(o2, #{anchor: 'NW'})
+ call nvim_win_set_config(w4, o2)
+ let o3 = extendnew(o3, #{win: w8})
+ call nvim_win_set_config(w2, o3)
+ let o4 = extendnew(o4, #{win: w4})
+ call nvim_win_set_config(w1, o4)
+ let o5 = extendnew(o5, #{win: w2})
+ call nvim_win_set_config(w6, o5)
+ let o6 = extendnew(o6, #{win: w1})
+ call nvim_win_set_config(w3, o6)
+ let o7 = extendnew(o7, #{win: w6})
+ call nvim_win_set_config(w5, o7)
+ let o8 = extendnew(o8, #{win: w3})
+ call nvim_win_set_config(w7, o8)
+ ]])
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ |
+ |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 5
+ {1:1 }|
+ ## grid 6
+ {1:2 }|
+ ## grid 7
+ {1:3 }|
+ ## grid 8
+ {1:4 }|
+ ## grid 9
+ {1:5 }|
+ ## grid 10
+ {1:6 }|
+ ## grid 11
+ {1:7 }|
+ ## grid 12
+ {1:8 }|
+ ]], float_pos={
+ [5] = {{id = 1002}, "NE", 8, 1, 0, true, 50};
+ [6] = {{id = 1003}, "NE", 12, 1, 0, true, 50};
+ [7] = {{id = 1004}, "SE", 5, 0, 0, true, 50};
+ [8] = {{id = 1005}, "NW", 1, 1, 30, true, 50};
+ [9] = {{id = 1006}, "SW", 10, 0, 5, true, 50};
+ [10] = {{id = 1007}, "SE", 6, 0, 0, true, 50};
+ [11] = {{id = 1008}, "SW", 7, 0, 5, true, 50};
+ [12] = {{id = 1009}, "NW", 1, 1, 10, true, 50};
+ }}
+ else
+ screen:expect([[
+ {1:5 } {1:7 } |
+ {1:6 } {1:8 } {1:3 } {1:4 } |
+ {1:2 } {1:1 } |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ -- Not clear how cycles should behave, but they should not hang or crash
+ exec([[
+ let o1 = extendnew(o1, #{relative: 'win', win: w7})
+ call nvim_win_set_config(w1, o1)
+ let o2 = extendnew(o2, #{relative: 'win', win: w8})
+ call nvim_win_set_config(w2, o2)
+ let o3 = extendnew(o3, #{win: w1})
+ call nvim_win_set_config(w3, o3)
+ let o4 = extendnew(o4, #{win: w2})
+ call nvim_win_set_config(w4, o4)
+ let o5 = extendnew(o5, #{win: w3})
+ call nvim_win_set_config(w5, o5)
+ let o6 = extendnew(o6, #{win: w4})
+ call nvim_win_set_config(w6, o6)
+ let o7 = extendnew(o7, #{win: w5})
+ call nvim_win_set_config(w7, o7)
+ let o8 = extendnew(o8, #{win: w6})
+ call nvim_win_set_config(w8, o8)
+ redraw
+ ]])
+ end)
+
it('can be placed relative text in a window', function()
screen:try_resize(30,5)
local firstwin = meths.get_current_win().id
@@ -2988,12 +4322,10 @@ describe('float window', function()
|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 3, 2, true }
+ [4] = { { id = 1001 }, "NW", 2, 3, 2, true }
}}
else
screen:expect{grid=[[
@@ -3004,7 +4336,7 @@ describe('float window', function()
|
]]}
end
- eq({relative='win', width=12, height=1, bufpos={1,32}, anchor='NW',
+ eq({relative='win', width=12, height=1, bufpos={1,32}, anchor='NW', hide=false,
external=false, col=0, row=1, win=firstwin, focusable=true, zindex=50}, meths.win_get_config(win))
feed('<c-e>')
@@ -3023,12 +4355,10 @@ describe('float window', function()
|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 2, 2, true }
+ [4] = { { id = 1001 }, "NW", 2, 2, 2, true },
}}
else
screen:expect{grid=[[
@@ -3057,12 +4387,10 @@ describe('float window', function()
more text |
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 1, 32, true }
+ [4] = { { id = 1001 }, "NW", 2, 1, 32, true }
}}
else
-- note: appears misaligned due to cursor
@@ -3101,12 +4429,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 2, 7, true }
+ [4] = { { id = 1001 }, "NW", 2, 2, 7, true }
}}
else
screen:expect{grid=[[
@@ -3149,12 +4475,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "SW", 2, 1, 7, true }
+ [4] = { { id = 1001 }, "SW", 2, 1, 7, true }
}}
else
screen:expect{grid=[[
@@ -3176,15 +4500,15 @@ describe('float window', function()
if multigrid then
screen:expect{grid=[[
## grid 1
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
- [2:----]{5:│}[6:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
+ [2:----]{5:│}[5:--------------------]|
[3:-------------------------]|
## grid 2
exam|
@@ -3198,9 +4522,9 @@ describe('float window', function()
the |
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
- ## grid 6
+ ## grid 5
^ |
{0:~ }|
{0:~ }|
@@ -3211,9 +4535,7 @@ describe('float window', function()
{0:~ }|
{0:~ }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "SW", 2, 8, 0, true }
+ [4] = { { id = 1001 }, "SW", 2, 8, 0, true }
}}
else
screen:expect{grid=[[
@@ -3257,12 +4579,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 2, 5, true }
+ [4] = { { id = 1001 }, "NW", 2, 2, 5, true }
}}
else
screen:expect{grid=[[
@@ -3305,12 +4625,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 3, 7, true }
+ [4] = { { id = 1001 }, "NW", 2, 3, 7, true }
}}
else
screen:expect{grid=[[
@@ -3353,12 +4671,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some info! }|
]], float_pos={
- [5] = { {
- id = 1002
- }, "NW", 2, 2, 0, true }
+ [4] = { { id = 1001 }, "NW", 2, 2, 0, true }
}}
else
screen:expect{grid=[[
@@ -3424,10 +4740,10 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:some floaty text }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 3, 1, true}
+ [4] = {{id = 1001}, "NW", 1, 3, 1, true}
}}
else
screen:expect([[
@@ -3483,7 +4799,7 @@ describe('float window', function()
meths.buf_set_lines(buf, 0, -1, true, {'such', 'very', 'float'})
local win = meths.open_win(buf, false, {relative='editor', width=15, height=4, row=2, col=10})
local expected_pos = {
- [5]={{id=1002}, 'NW', 1, 2, 10, true},
+ [4]={{id=1001}, 'NW', 1, 2, 10, true},
}
if multigrid then
screen:expect{grid=[[
@@ -3504,7 +4820,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:float }|
@@ -3538,7 +4854,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:float }|
@@ -3568,7 +4884,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:float }|
@@ -3595,7 +4911,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:float }|
@@ -3620,7 +4936,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:^float }|
@@ -3628,9 +4944,9 @@ describe('float window', function()
]], float_pos=expected_pos}
else
screen:expect([[
- {1:very } |
- {0:~ }{1:^float }{0: }|
- |
+ {1:such } |
+ {0:~ }{1:very }{0: }|
+ ^ |
]])
end
@@ -3654,7 +4970,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:such }|
{1:very }|
{1:^float }|
@@ -3693,7 +5009,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3730,7 +5046,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3767,7 +5083,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3804,7 +5120,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3841,7 +5157,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3878,7 +5194,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3915,7 +5231,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3952,7 +5268,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -3980,7 +5296,7 @@ describe('float window', function()
|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -4012,7 +5328,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^such }|
{1:very }|
{1:float }|
@@ -4162,8 +5478,8 @@ describe('float window', function()
describe('and completion', function()
before_each(function()
local buf = meths.create_buf(false,false)
- local win = meths.open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5})
- meths.win_set_option(win , 'winhl', 'Normal:ErrorMsg')
+ local win = meths.open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5}).id
+ meths.set_option_value('winhl', 'Normal:ErrorMsg', {win=win})
if multigrid then
screen:expect{grid=[[
## grid 1
@@ -4672,12 +5988,12 @@ describe('float window', function()
{13:aa }|
{1:word }|
{1:longtext }|
- ## grid 6
+ ## grid 5
{15:some info }|
{15:about item }|
]], float_pos={
[4] = {{id = -1}, "NW", 2, 1, 0, false, 100},
- [6] = {{id = 1002}, "NW", 2, 1, 12, true, 50},
+ [5] = {{id = 1001}, "NW", 2, 1, 12, true, 50},
}}
else
screen:expect([[
@@ -4713,11 +6029,11 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- INSERT --} |
- ## grid 6
+ ## grid 5
{15:some info }|
{15:about item }|
]], float_pos={
- [6] = {{id = 1002}, "NW", 2, 1, 12, true},
+ [5] = {{id = 1001}, "NW", 2, 1, 12, true},
}}
else
screen:expect([[
@@ -4840,6 +6156,53 @@ describe('float window', function()
end)
end)
+ it("can use Normal as background", function()
+ local buf = meths.create_buf(false,false)
+ meths.buf_set_lines(buf,0,-1,true,{"here", "float"})
+ local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
+ meths.set_option_value('winhl', 'Normal:Normal', {win=win})
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ here |
+ float |
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 2, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }here {0: }|
+ {0:~ }float {0: }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end
+ end)
+
describe("handles :wincmd", function()
local win
local expected_pos
@@ -5153,7 +6516,7 @@ describe('float window', function()
end
if multigrid then
- meths.input_mouse('left', 'press', '', 1, 0, 0)
+ meths.input_mouse('left', 'press', '', 2, 0, 0)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -5232,7 +6595,7 @@ describe('float window', function()
end
if multigrid then
- meths.input_mouse('left', 'press', '', 1, 0, 0)
+ meths.input_mouse('left', 'press', '', 2, 0, 0)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7142,18 +8505,18 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:foo }|
{1:bar }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 2, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'press', '', 5, 0, 0)
+ meths.input_mouse('left', 'press', '', 4, 0, 0)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7172,18 +8535,18 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{1:^foo }|
{1:bar }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 2, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'drag', '', 5, 1, 2)
+ meths.input_mouse('left', 'drag', '', 4, 1, 2)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7202,15 +8565,15 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- VISUAL --} |
- ## grid 5
+ ## grid 4
{27:foo}{1: }|
{27:ba}{1:^r }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 2, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -7270,20 +8633,20 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:┌────────────────────┐}|
{5:│}{1:foo }{5:│}|
{5:│}{1:bar }{5:│}|
{5:│}{1:baz }{5:│}|
{5:└────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'press', '', 5, 1, 1)
+ meths.input_mouse('left', 'press', '', 4, 1, 1)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7302,20 +8665,20 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:┌────────────────────┐}|
{5:│}{1:^foo }{5:│}|
{5:│}{1:bar }{5:│}|
{5:│}{1:baz }{5:│}|
{5:└────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'drag', '', 5, 2, 3)
+ meths.input_mouse('left', 'drag', '', 4, 2, 3)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7334,17 +8697,17 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- VISUAL --} |
- ## grid 5
+ ## grid 4
{5:┌────────────────────┐}|
{5:│}{27:foo}{1: }{5:│}|
{5:│}{27:ba}{1:^r }{5:│}|
{5:│}{1:baz }{5:│}|
{5:└────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 0, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -7385,7 +8748,7 @@ describe('float window', function()
local buf = meths.create_buf(false,false)
meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'})
local float_win = meths.open_win(buf, false, {relative='editor', width=20, height=4, row=1, col=5})
- meths.win_set_option(float_win, 'winbar', 'floaty bar')
+ meths.set_option_value('winbar', 'floaty bar', {win=float_win.id})
if multigrid then
screen:expect{grid=[[
## grid 1
@@ -7405,19 +8768,19 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{3:floaty bar }|
{1:foo }|
{1:bar }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 1, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 1, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'press', '', 5, 1, 0)
+ meths.input_mouse('left', 'press', '', 4, 1, 0)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7436,19 +8799,19 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{3:floaty bar }|
{1:^foo }|
{1:bar }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 1, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 1, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
}}
- meths.input_mouse('left', 'drag', '', 5, 2, 2)
+ meths.input_mouse('left', 'drag', '', 4, 2, 2)
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
@@ -7467,16 +8830,16 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- VISUAL --} |
- ## grid 5
+ ## grid 4
{3:floaty bar }|
{27:foo}{1: }|
{27:ba}{1:^r }|
{1:baz }|
]], float_pos={
- [5] = {{id = 1002}, "NW", 1, 1, 5, true, 50};
+ [4] = {{id = 1001}, "NW", 1, 1, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -7521,11 +8884,11 @@ describe('float window', function()
if multigrid then
screen:expect([[
## grid 1
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
@@ -7536,7 +8899,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
^foo |
bar |
baz |
@@ -7544,14 +8907,14 @@ describe('float window', function()
{0:~ }|
]])
- meths.input_mouse('left', 'press', '', 5, 2, 2)
+ meths.input_mouse('left', 'press', '', 4, 2, 2)
screen:expect([[
## grid 1
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
@@ -7562,7 +8925,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
foo |
bar |
ba^z |
@@ -7570,14 +8933,14 @@ describe('float window', function()
{0:~ }|
]])
- meths.input_mouse('left', 'drag', '', 5, 1, 1)
+ meths.input_mouse('left', 'drag', '', 4, 1, 1)
screen:expect([[
## grid 1
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
- [2:-------------------]{5:│}[5:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
+ [2:-------------------]{5:│}[4:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
@@ -7588,7 +8951,7 @@ describe('float window', function()
{0:~ }|
## grid 3
{3:-- VISUAL --} |
- ## grid 5
+ ## grid 4
foo |
b^a{27:r} |
{27:baz} |
@@ -7630,6 +8993,186 @@ describe('float window', function()
end
end)
+ it('left click sets correct curswant in float window with border', function()
+ local buf = meths.create_buf(false,false)
+ meths.buf_set_lines(buf, 0, -1, true, {'', '', ''})
+ meths.open_win(buf, false, {relative='editor', width=20, height=3, row=0, col=5, border='single'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:┌────────────────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{1: }{5:│}|
+ {5:│}{1: }{5:│}|
+ {5:└────────────────────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ ^ {5:┌────────────────────┐} |
+ {0:~ }{5:│}{1: }{5:│}{0: }|
+ {0:~ }{5:│}{1: }{5:│}{0: }|
+ {0:~ }{5:│}{1: }{5:│}{0: }|
+ {0:~ }{5:└────────────────────┘}{0: }|
+ {0:~ }|
+ |
+ ]]}
+ end
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 3, 1)
+ else
+ meths.input_mouse('left', 'press', '', 0, 3, 6)
+ end
+ eq({0, 3, 1, 0, 1}, funcs.getcurpos())
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 3, 2)
+ else
+ meths.input_mouse('left', 'press', '', 0, 3, 7)
+ end
+ eq({0, 3, 1, 0, 2}, funcs.getcurpos())
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 3, 10)
+ else
+ meths.input_mouse('left', 'press', '', 0, 3, 15)
+ end
+ eq({0, 3, 1, 0, 10}, funcs.getcurpos())
+
+ command('setlocal foldcolumn=1')
+ feed('zfkgg')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:┌────────────────────┐}|
+ {5:│}{19: }{1:^ }{5:│}|
+ {5:│}{19:+}{28:+-- 2 lines: ·····}{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────────────────────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 4, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ {5:┌────────────────────┐} |
+ {0:~ }{5:│}{19: }{1:^ }{5:│}{0: }|
+ {0:~ }{5:│}{19:+}{28:+-- 2 lines: ·····}{5:│}{0: }|
+ {0:~ }{5:│}{2:~ }{5:│}{0: }|
+ {0:~ }{5:└────────────────────┘}{0: }|
+ {0:~ }|
+ |
+ ]]}
+ end
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 1)
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:┌────────────────────┐}|
+ {5:│}{19: }{1:^ }{5:│}|
+ {5:│}{19:-}{1: }{5:│}|
+ {5:│}{19:│}{1: }{5:│}|
+ {5:└────────────────────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 0, 5, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0};
+ }}
+ else
+ meths.input_mouse('left', 'press', '', 0, 2, 6)
+ screen:expect{grid=[[
+ {5:┌────────────────────┐} |
+ {0:~ }{5:│}{19: }{1:^ }{5:│}{0: }|
+ {0:~ }{5:│}{19:-}{1: }{5:│}{0: }|
+ {0:~ }{5:│}{19:│}{1: }{5:│}{0: }|
+ {0:~ }{5:└────────────────────┘}{0: }|
+ {0:~ }|
+ |
+ ]]}
+ end
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 2)
+ else
+ meths.input_mouse('left', 'press', '', 0, 2, 7)
+ end
+ eq({0, 2, 1, 0, 1}, funcs.getcurpos())
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 3)
+ else
+ meths.input_mouse('left', 'press', '', 0, 2, 8)
+ end
+ eq({0, 2, 1, 0, 2}, funcs.getcurpos())
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 11)
+ else
+ meths.input_mouse('left', 'press', '', 0, 2, 16)
+ end
+ eq({0, 2, 1, 0, 10}, funcs.getcurpos())
+ end)
+
it("'winblend' option", function()
screen:try_resize(50,9)
screen:set_default_attr_ids({
@@ -7641,10 +9184,23 @@ describe('float window', function()
[6] = {foreground = tonumber('0x332533'), background = tonumber('0xfff1ff')},
[7] = {background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0x0000d8')},
[8] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1},
- [9] = {background = Screen.colors.LightMagenta, blend=30},
- [10] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend=0},
- [11] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend=80},
- [12] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend=30},
+ [9] = {background = Screen.colors.LightMagenta, blend = 30},
+ [10] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 0},
+ [11] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 80},
+ [12] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend = 30},
+ [13] = {background = Screen.colors.LightGray, blend = 30},
+ [14] = {foreground = Screen.colors.Grey0, background = Screen.colors.Grey88},
+ [15] = {foreground = tonumber('0x939393'), background = Screen.colors.Grey88},
+ [16] = {background = Screen.colors.Grey90};
+ [17] = {blend = 100};
+ [18] = {background = Screen.colors.LightMagenta, blend = 100};
+ [19] = {background = Screen.colors.LightMagenta, bold = true, blend = 100, foreground = Screen.colors.Blue1};
+ [20] = {background = Screen.colors.White, foreground = Screen.colors.Gray0};
+ [21] = {background = Screen.colors.White, bold = true, foreground = tonumber('0x00007f')};
+ [22] = {background = Screen.colors.Gray90, foreground = Screen.colors.Gray0};
+ [23] = {blend = 100, bold = true, foreground = Screen.colors.Magenta};
+ [24] = {foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.White};
+ [25] = {foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.Grey90};
})
insert([[
Lorem ipsum dolor sit amet, consectetur
@@ -7684,11 +9240,11 @@ describe('float window', function()
laborum^. |
## grid 3
|
- ## grid 5
+ ## grid 4
{1:test }|
{1: }|
{1:popup text }|
- ]], float_pos={[5] = {{id = 1002}, "NW", 1, 2, 5, true}}}
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}}
else
screen:expect([[
Ut enim ad minim veniam, quis nostrud |
@@ -7703,7 +9259,7 @@ describe('float window', function()
]])
end
- meths.win_set_option(win, "winblend", 30)
+ meths.set_option_value("winblend", 30, {win=win.id})
if multigrid then
screen:expect{grid=[[
## grid 1
@@ -7727,11 +9283,11 @@ describe('float window', function()
laborum^. |
## grid 3
|
- ## grid 5
+ ## grid 4
{9:test }|
{9: }|
{9:popup text }|
- ]], float_pos={[5] = {{id = 1002}, "NW", 1, 2, 5, true}}, unchanged=true}
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}, unchanged=true}
else
screen:expect([[
Ut enim ad minim veniam, quis nostrud |
@@ -7746,6 +9302,58 @@ describe('float window', function()
]])
end
+ -- Check that 'winblend' works with NormalNC highlight
+ meths.set_option_value('winhighlight', 'NormalNC:Visual', {win = win})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [3:--------------------------------------------------]|
+ ## grid 2
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ ea commodo consequat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ laborum^. |
+ ## grid 3
+ |
+ ## grid 4
+ {13:test }|
+ {13: }|
+ {13:popup text }|
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}}
+ else
+ screen:expect([[
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ ea co{14:test}{15:o consequat}. Duis aute irure dolor in |
+ repre{15:henderit in vol}uptate velit esse cillum |
+ dolor{14:popup}{15:fugi}{14:text}{15:ul}la pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ laborum^. |
+ |
+ ]])
+ end
+
+ -- Also test with global NormalNC highlight
+ exec_lua([[
+ vim.api.nvim_set_option_value('winhighlight', '', {win = ...})
+ vim.api.nvim_set_hl(0, 'NormalNC', {link = 'Visual'})
+ ]], win)
+ screen:expect_unchanged()
+ command('hi clear NormalNC')
+
command('hi SpecialRegion guifg=Red blend=0')
meths.buf_add_highlight(buf, -1, "SpecialRegion", 2, 0, -1)
if multigrid then
@@ -7771,11 +9379,11 @@ describe('float window', function()
laborum^. |
## grid 3
|
- ## grid 5
+ ## grid 4
{9:test }|
{9: }|
{10:popup text}{9: }|
- ]], float_pos={[5] = {{id = 1002}, "NW", 1, 2, 5, true}}}
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}}
else
screen:expect([[
Ut enim ad minim veniam, quis nostrud |
@@ -7814,11 +9422,11 @@ describe('float window', function()
laborum^. |
## grid 3
|
- ## grid 5
+ ## grid 4
{9:test }|
{9: }|
{11:popup text}{9: }|
- ]], float_pos={[5] = {{id = 1002}, "NW", 1, 2, 5, true}}, unchanged=true}
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}, unchanged=true}
else
screen:expect([[
Ut enim ad minim veniam, quis nostrud |
@@ -7835,7 +9443,7 @@ describe('float window', function()
-- Test scrolling by mouse
if multigrid then
- meths.input_mouse('wheel', 'down', '', 5, 2, 2)
+ meths.input_mouse('wheel', 'down', '', 4, 2, 2)
screen:expect{grid=[[
## grid 1
[2:--------------------------------------------------]|
@@ -7858,11 +9466,11 @@ describe('float window', function()
laborum^. |
## grid 3
|
- ## grid 5
+ ## grid 4
{11:popup text}{9: }|
{12:~ }|
{12:~ }|
- ]], float_pos={[5] = {{id = 1002}, "NW", 1, 2, 5, true}}}
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}}
else
meths.input_mouse('wheel', 'down', '', 0, 4, 7)
screen:expect([[
@@ -7877,6 +9485,56 @@ describe('float window', function()
|
]])
end
+
+ -- Check that 'winblend' applies to border/title/footer
+ meths.win_set_config(win, {border='single', title='Title', footer='Footer'})
+ meths.set_option_value('winblend', 100, {win=win.id})
+ meths.set_option_value("cursorline", true, {win=0})
+ command('hi clear VertSplit')
+ feed('k0')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [2:--------------------------------------------------]|
+ [3:--------------------------------------------------]|
+ ## grid 2
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ ea commodo consequat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ {16:^qui officia deserunt mollit anim id est }|
+ laborum. |
+ ## grid 3
+ |
+ ## grid 4
+ {17:┌}{23:Title}{17:──────────┐}|
+ {17:│}{11:popup text}{18: }{17:│}|
+ {17:│}{19:~ }{17:│}|
+ {17:│}{19:~ }{17:│}|
+ {17:└}{23:Footer}{17:─────────┘}|
+ ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}}
+ else
+ screen:expect([[
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ ea co{20:┌}{24:Title}{20:──────────┐}Duis aute irure dolor in |
+ repre{20:│}{5:popup}{6:it i}{5:text}{20:lu│}tate velit esse cillum |
+ dolor{20:│}{21:~}{20:eu fugiat null│} pariatur. Excepteur sint |
+ occae{20:│}{21:~}{20:t cupidatat no│} proident, sunt in culpa |
+ {16:^qui o}{22:└}{25:Footer}{22:─────────┘}{16:ollit anim id est }|
+ laborum. |
+ |
+ ]])
+ end
end)
it('can overlap doublewidth chars', function()
@@ -7884,6 +9542,7 @@ describe('float window', function()
# TODO: 测试字典信息的准确性
# FIXME: 测试字典信息的准确性]])
local buf = meths.create_buf(false,false)
+ meths.buf_set_lines(buf, 0, -1, true, {'口', '口'})
local win = meths.open_win(buf, false, {relative='editor', width=5, height=3, row=0, col=11, style='minimal'})
if multigrid then
screen:expect{grid=[[
@@ -7905,14 +9564,14 @@ describe('float window', function()
## grid 3
|
## grid 4
- {1: }|
- {1: }|
+ {1:口 }|
+ {1:口 }|
{1: }|
]], float_pos={ [4] = { { id = 1001 }, "NW", 1, 0, 11, true } }}
else
screen:expect([[
- # TODO: 测 {1: }信息的准确性 |
- # FIXME: 测{1: } 信息的准确^性 |
+ # TODO: 测 {1:口 }信息的准确性 |
+ # FIXME: 测{1:口 } 信息的准确^性 |
{0:~ }{1: }{0: }|
{0:~ }|
{0:~ }|
@@ -7959,7 +9618,7 @@ describe('float window', function()
-- at least. Also check invisible EndOfBuffer region blends correctly.
meths.buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"})
win = meths.open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'})
- meths.win_set_option(win, 'winblend', 30)
+ meths.set_option_value('winblend', 30, {win=win.id})
screen:set_default_attr_ids({
[1] = {foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff')},
[2] = {foreground = Screen.colors.Grey0, background = tonumber('0xffcfff')},
@@ -7986,14 +9645,12 @@ describe('float window', function()
{3:~ }|
## grid 3
|
- ## grid 6
+ ## grid 5
{5: x x x xx}|
{5: x x x x}|
{5: }|
]], float_pos={
- [6] = { {
- id = 1003
- }, "NW", 1, 0, 11, true }
+ [5] = { { id = 1002 }, "NW", 1, 0, 11, true }
}}
else
screen:expect([[
@@ -8027,14 +9684,12 @@ describe('float window', function()
{3:~ }|
## grid 3
|
- ## grid 6
+ ## grid 5
{5: x x x xx}|
{5: x x x x}|
{5: }|
]], float_pos={
- [6] = { {
- id = 1003
- }, "NW", 1, 0, 12, true }
+ [5] = { { id = 1002 }, "NW", 1, 0, 12, true }
}}
else
screen:expect([[
@@ -8096,11 +9751,11 @@ describe('float window', function()
{1:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{2:^long }|
{2:longer }|
{2:longest}|
- ## grid 6
+ ## grid 5
{2:---------}|
{2:- -}|
{2:- -}|
@@ -8110,11 +9765,11 @@ describe('float window', function()
[1] = {foreground = Screen.colors.Blue1, bold = true};
[2] = {background = Screen.colors.LightMagenta};
}, float_pos={
+ [4] = { {
+ id = 1001
+ }, "NW", 1, 1, 1, true },
[5] = { {
id = 1002
- }, "NW", 1, 1, 1, true },
- [6] = { {
- id = 1003
}, "NW", 1, 0, 0, true }
}}
else
@@ -8164,11 +9819,11 @@ describe('float window', function()
{1:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{2:^l}|
{2:o}|
{2:n}|
- ## grid 6
+ ## grid 5
{2:---}|
{2:- -}|
{2:- -}|
@@ -8178,12 +9833,8 @@ describe('float window', function()
[1] = {foreground = Screen.colors.Blue1, bold = true};
[2] = {background = Screen.colors.LightMagenta};
}, float_pos={
- [5] = { {
- id = 1002
- }, "NW", 1, 1, 1, true },
- [6] = { {
- id = 1003
- }, "NW", 1, 0, 0, true }
+ [4] = { { id = 1001 }, "NW", 1, 1, 1, true },
+ [5] = { { id = 1002 }, "NW", 1, 0, 0, true }
}}
else
screen:expect([[
@@ -8201,7 +9852,7 @@ describe('float window', function()
it("correctly orders multiple opened floats (current last)", function()
local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
- meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg")
+ meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id})
if multigrid then
screen:expect{grid=[[
@@ -8228,8 +9879,8 @@ describe('float window', function()
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8246,10 +9897,10 @@ describe('float window', function()
exec_lua [[
local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
- vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal")
+ vim.wo[win].winhl = "EndOfBuffer:Normal"
buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
- vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search")
+ vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
]]
if multigrid then
@@ -8285,10 +9936,10 @@ describe('float window', function()
[5] = { { id = 1002 }, "NW", 1, 3, 8, true };
[6] = { { id = 1003 }, "NW", 1, 4, 10, true };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1};
- [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1, sum_scroll_delta = 0};
+ [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount=1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8306,7 +9957,7 @@ describe('float window', function()
it("correctly orders multiple opened floats (non-current last)", function()
local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
- meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg")
+ meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id})
if multigrid then
screen:expect{grid=[[
@@ -8333,8 +9984,8 @@ describe('float window', function()
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8351,10 +10002,10 @@ describe('float window', function()
exec_lua [[
local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
- vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search")
+ vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
- vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal")
+ vim.wo[win].winhl = "EndOfBuffer:Normal"
]]
if multigrid then
@@ -8390,10 +10041,10 @@ describe('float window', function()
[5] = { { id = 1002 }, "NW", 1, 4, 10, true };
[6] = { { id = 1003 }, "NW", 1, 3, 8, true };
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8411,11 +10062,11 @@ describe('float window', function()
it('can use z-index', function()
local buf = meths.create_buf(false,false)
local win1 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=1, col=5, zindex=30})
- meths.win_set_option(win1, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg")
+ meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win1.id})
local win2 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=6, zindex=50})
- meths.win_set_option(win2, "winhl", "Normal:Search,EndOfBuffer:Search")
+ meths.set_option_value("winhl", "Normal:Search,EndOfBuffer:Search", {win=win2.id})
local win3 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=3, col=7, zindex=40})
- meths.win_set_option(win3, "winhl", "Normal:Question,EndOfBuffer:Question")
+ meths.set_option_value("winhl", "Normal:Question,EndOfBuffer:Question", {win=win3.id})
if multigrid then
screen:expect{grid=[[
@@ -8453,10 +10104,10 @@ describe('float window', function()
[5] = {{id = 1002}, "NW", 1, 2, 6, true, 50};
[6] = {{id = 1003}, "NW", 1, 3, 7, true, 40};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8474,7 +10125,7 @@ describe('float window', function()
it('can use winbar', function()
local buf = meths.create_buf(false,false)
local win1 = meths.open_win(buf, false, {relative='editor', width=15, height=3, row=1, col=5})
- meths.win_set_option(win1, 'winbar', 'floaty bar')
+ meths.set_option_value('winbar', 'floaty bar', {win=win1.id})
if multigrid then
screen:expect{grid=[[
@@ -8502,8 +10153,8 @@ describe('float window', function()
]], float_pos={
[4] = {{id = 1001}, "NW", 1, 1, 5, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8549,8 +10200,8 @@ describe('float window', function()
]], float_pos={
[4] = {{id = 1001}, "NW", 1, 0, 4, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8594,7 +10245,7 @@ describe('float window', function()
{0:~ }|
{0:~ }|
## grid 3
- ## grid 5
+ ## grid 4
{5:┌────────────────────────────────────────┐}|
{5:│}{1: }{5:│}|
{5:│}{1: }{5:│}|
@@ -8602,10 +10253,10 @@ describe('float window', function()
{5:│}{1: }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "SW", 1, 9, 0, true, 50};
+ [4] = {{id = 1001}, "SW", 1, 9, 0, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8650,16 +10301,16 @@ describe('float window', function()
{0:~ }|
{0:~ }|
## grid 3
- ## grid 5
+ ## grid 4
{5:┌────────────────────────────────────────┐}|
{5:│}{1: }{5:│}|
{5:│}{1: }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "SW", 1, 9, 0, true, 50};
+ [4] = {{id = 1001}, "SW", 1, 9, 0, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8701,7 +10352,7 @@ describe('float window', function()
{0:~ }|
## grid 3
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8746,7 +10397,7 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:┌────────────────────────────────────────┐}|
{5:│}{1: }{5:│}|
{5:│}{1: }{5:│}|
@@ -8754,10 +10405,10 @@ describe('float window', function()
{5:│}{1: }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50};
+ [4] = {{id = 1001}, "SW", 1, 8, 0, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8806,7 +10457,7 @@ describe('float window', function()
## grid 3
|
{8:Press ENTER or type command to continue}^ |
- ## grid 5
+ ## grid 4
{5:┌────────────────────────────────────────┐}|
{5:│}{1: }{5:│}|
{5:│}{1: }{5:│}|
@@ -8814,10 +10465,10 @@ describe('float window', function()
{5:│}{1: }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50};
+ [4] = {{id = 1001}, "SW", 1, 8, 0, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8857,16 +10508,16 @@ describe('float window', function()
{0:~ }|
## grid 3
|
- ## grid 5
+ ## grid 4
{5:┌────────────────────────────────────────┐}|
{5:│}{1: }{5:│}|
{5:│}{1: }{5:│}|
{5:└────────────────────────────────────────┘}|
]], float_pos={
- [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50};
+ [4] = {{id = 1001}, "SW", 1, 8, 0, true, 50};
}, win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
else
screen:expect{grid=[[
@@ -8907,9 +10558,8 @@ describe('float window', function()
## grid 3
|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
-
else
screen:expect{grid=[[
^ |
@@ -8952,6 +10602,696 @@ describe('float window', function()
test_float_move_close('autocmd BufWinLeave * ++once redraw')
end)
end)
+
+ it(':sleep cursor placement #22639', function()
+ local float_opts = {relative = 'editor', row = 1, col = 1, width = 4, height = 3}
+ local win = meths.open_win(meths.create_buf(false, false), true, float_opts)
+ feed('iab<CR>cd<Esc>')
+ feed(':sleep 100')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100^ |
+ ## grid 4
+ {1:ab }|
+ {1:cd }|
+ {2:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{1:ab }{0: }|
+ {0:~}{1:cd }{0: }|
+ {0:~}{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ :sleep 100^ |
+ ]]}
+ end
+
+ feed('<CR>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100 |
+ ## grid 4
+ {1:ab }|
+ {1:c^d }|
+ {2:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{1:ab }{0: }|
+ {0:~}{1:c^d }{0: }|
+ {0:~}{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ :sleep 100 |
+ ]]}
+ end
+ feed('<C-C>')
+ screen:expect_unchanged()
+
+ meths.win_set_config(win, {border = 'single'})
+ feed(':sleep 100')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100^ |
+ ## grid 4
+ {5:┌────┐}|
+ {5:│}{1:ab }{5:│}|
+ {5:│}{1:cd }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌────┐}{0: }|
+ {0:~}{5:│}{1:ab }{5:│}{0: }|
+ {0:~}{5:│}{1:cd }{5:│}{0: }|
+ {0:~}{5:│}{2:~ }{5:│}{0: }|
+ {0:~}{5:└────┘}{0: }|
+ :sleep 100^ |
+ ]]}
+ end
+
+ feed('<CR>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100 |
+ ## grid 4
+ {5:┌────┐}|
+ {5:│}{1:ab }{5:│}|
+ {5:│}{1:c^d }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌────┐}{0: }|
+ {0:~}{5:│}{1:ab }{5:│}{0: }|
+ {0:~}{5:│}{1:c^d }{5:│}{0: }|
+ {0:~}{5:│}{2:~ }{5:│}{0: }|
+ {0:~}{5:└────┘}{0: }|
+ :sleep 100 |
+ ]]}
+ end
+ feed('<C-C>')
+ screen:expect_unchanged()
+
+ command('setlocal winbar=foo')
+ feed(':sleep 100')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100^ |
+ ## grid 4
+ {5:┌────┐}|
+ {5:│}{3:foo }{5:│}|
+ {5:│}{1:ab }{5:│}|
+ {5:│}{1:cd }{5:│}|
+ {5:└────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌────┐}{0: }|
+ {0:~}{5:│}{3:foo }{5:│}{0: }|
+ {0:~}{5:│}{1:ab }{5:│}{0: }|
+ {0:~}{5:│}{1:cd }{5:│}{0: }|
+ {0:~}{5:└────┘}{0: }|
+ :sleep 100^ |
+ ]]}
+ end
+
+ feed('<CR>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ :sleep 100 |
+ ## grid 4
+ {5:┌────┐}|
+ {5:│}{3:foo }{5:│}|
+ {5:│}{1:ab }{5:│}|
+ {5:│}{1:c^d }{5:│}|
+ {5:└────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌────┐}{0: }|
+ {0:~}{5:│}{3:foo }{5:│}{0: }|
+ {0:~}{5:│}{1:ab }{5:│}{0: }|
+ {0:~}{5:│}{1:c^d }{5:│}{0: }|
+ {0:~}{5:└────┘}{0: }|
+ :sleep 100 |
+ ]]}
+ end
+ feed('<C-C>')
+ screen:expect_unchanged()
+ end)
+
+ it('with rightleft and border #22640', function()
+ local float_opts = {relative='editor', width=5, height=3, row=1, col=1, border='single'}
+ meths.open_win(meths.create_buf(false, false), true, float_opts)
+ command('setlocal rightleft')
+ feed('iabc<CR>def<Esc>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:┌─────┐}|
+ {5:│}{1: cba}{5:│}|
+ {5:│}{1: ^fed}{5:│}|
+ {5:│}{2: ~}{5:│}|
+ {5:└─────┘}|
+ ]], float_pos={
+ [4] = {{id = 1001}, "NW", 1, 1, 1, true, 50};
+ }, win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 2, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect{grid=[[
+ |
+ {0:~}{5:┌─────┐}{0: }|
+ {0:~}{5:│}{1: cba}{5:│}{0: }|
+ {0:~}{5:│}{1: ^fed}{5:│}{0: }|
+ {0:~}{5:│}{2: ~}{5:│}{0: }|
+ {0:~}{5:└─────┘}{0: }|
+ |
+ ]]}
+ end
+ end)
+
+ it('float window with hide option', function()
+ local buf = meths.create_buf(false,false)
+ local win = meths.open_win(buf, false, {relative='editor', width=10, height=2, row=2, col=5, hide = true})
+ local expected_pos = {
+ [4]={{id=1001}, 'NW', 1, 2, 5, true},
+ }
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4 (hidden)
+ {1: }|
+ {2:~ }|
+ ]], float_pos = {}}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ meths.win_set_config(win, {hide = false})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4
+ {1: }|
+ {2:~ }|
+ ]], float_pos = expected_pos}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }{1: }{0: }|
+ {0:~ }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ meths.win_set_config(win, {hide=true})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4 (hidden)
+ {1: }|
+ {2:~ }|
+ ]], float_pos = {}}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+ end)
+
+ it(':fclose command #9663', function()
+ local buf_a = meths.create_buf(false,false)
+ local buf_b = meths.create_buf(false,false)
+ local buf_c = meths.create_buf(false,false)
+ local buf_d = meths.create_buf(false,false)
+ local config_a = {relative='editor', width=11, height=11, row=5, col=5, border ='single', zindex=50}
+ local config_b = {relative='editor', width=8, height=8, row=7, col=7, border ='single', zindex=70}
+ local config_c = {relative='editor', width=4, height=4, row=9, col=9, border ='single',zindex=90}
+ local config_d = {relative='editor', width=2, height=2, row=10, col=10, border ='single',zindex=100}
+ meths.open_win(buf_a, false, config_a)
+ meths.open_win(buf_b, false, config_b)
+ meths.open_win(buf_c, false, config_c)
+ meths.open_win(buf_d, false, config_d)
+ local expected_pos = {
+ [4]={{id=1001}, 'NW', 1, 5, 5, true, 50},
+ [5]={{id=1002}, 'NW', 1, 7, 7, true, 70},
+ [6]={{id=1003}, 'NW', 1, 9, 9, true, 90},
+ [7]={{id=1004}, 'NW', 1, 10, 10, true, 100},
+ }
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {5:┌───────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└───────────┘}|
+ ## grid 5
+ {5:┌────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────────┘}|
+ ## grid 6
+ {5:┌────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────┘}|
+ ## grid 7
+ {5:┌──┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└──┘}|
+ ]], float_pos=expected_pos}
+ else
+ screen:expect([[
+ ^ {5:┌─┌─┌────┐─┐┐} |
+ {0:~ }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│┌──┐│}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:││}{1: }{5:││}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:││}{2:~ }{5:││}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:└└──┘┘}{2: }{5:││}{0: }|
+ |
+ ]])
+ end
+ -- close the window with the highest zindex value
+ command('fclose')
+ expected_pos[7] = nil
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4
+ {5:┌───────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└───────────┘}|
+ ## grid 5
+ {5:┌────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────────┘}|
+ ## grid 6
+ {5:┌────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────┘}|
+ ]], float_pos=expected_pos}
+ else
+ screen:expect([[
+ ^ {5:┌─┌─┌────┐─┐┐} |
+ {0:~ }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~}{5:└────┘}{2: }{5:││}{0: }|
+ |
+ ]])
+ end
+ -- with range
+ command('1fclose')
+ expected_pos[6] = nil
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4
+ {5:┌───────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└───────────┘}|
+ ## grid 5
+ {5:┌────────┐}|
+ {5:│}{1: }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:│}{2:~ }{5:│}|
+ {5:└────────┘}|
+ ]], float_pos=expected_pos}
+ else
+ screen:expect([[
+ ^ {5:┌─┌────────┐┐} |
+ {0:~ }{5:│}{1: }{5:│}{1: }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }|
+ {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }|
+ |
+ ]])
+ end
+ -- with bang
+ command('fclose!')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ]], float_pos={}}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+ end)
end
describe('with ext_multigrid', function()
diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua
index 46a478c1ea..1addf7088e 100644
--- a/test/functional/ui/fold_spec.lua
+++ b/test/functional/ui/fold_spec.lua
@@ -4,11 +4,9 @@ local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq
local command = helpers.command
local feed_command = helpers.feed_command
local insert = helpers.insert
-local expect = helpers.expect
local funcs = helpers.funcs
local meths = helpers.meths
local exec = helpers.exec
-local exec_lua = helpers.exec_lua
local assert_alive = helpers.assert_alive
@@ -29,23 +27,29 @@ describe("folded lines", function()
local function with_ext_multigrid(multigrid)
local screen
before_each(function()
- clear()
- command('hi VertSplit gui=reverse')
screen = Screen.new(45, 8)
screen:attach({rgb=true, ext_multigrid=multigrid})
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1},
[2] = {reverse = true},
[3] = {bold = true, reverse = true},
- [4] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
+ [4] = {foreground = Screen.colors.White, background = Screen.colors.Red},
[5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
[6] = {background = Screen.colors.Yellow},
[7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
[8] = {foreground = Screen.colors.Brown },
[9] = {bold = true, foreground = Screen.colors.Brown},
[10] = {background = Screen.colors.LightGrey, underline = true},
- [11] = {bold=true},
- [12] = {background = Screen.colors.Grey90},
+ [11] = {bold = true},
+ [12] = {foreground = Screen.colors.Red},
+ [13] = {foreground = Screen.colors.Red, background = Screen.colors.LightGrey},
+ [14] = {background = Screen.colors.Red},
+ [15] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Red},
+ [16] = {background = Screen.colors.LightGrey},
+ [17] = {background = Screen.colors.Yellow, foreground = Screen.colors.Red},
+ [18] = {background = Screen.colors.LightGrey, bold = true, foreground = Screen.colors.Blue},
+ [19] = {background = Screen.colors.Yellow, foreground = Screen.colors.DarkBlue},
+ [20] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue},
})
end)
@@ -89,11 +93,11 @@ describe("folded lines", function()
end
end)
- it("highlights with CursorLineFold when 'cursorline' is set", function()
- command("set cursorline foldcolumn=2 foldmethod=marker")
+ local function test_folded_cursorline()
+ command("set number cursorline foldcolumn=2")
command("hi link CursorLineFold Search")
insert(content1)
- feed("zf3j")
+ feed("ggzf3jj")
if multigrid then
screen:expect([[
## grid 1
@@ -106,26 +110,26 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {7: }in his cave. |
- {6: }{12:^ }|
+ {7:+ }{8: 1 }{5:+-- 4 lines: This is a················}|
+ {6: }{9: 5 }{12:^in his cave. }|
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {7: }in his cave. |
- {6: }{12:^ }|
- {1:~ }|
- |
+ {7:+ }{8: 1 }{5:+-- 4 lines: This is a················}|
+ {6: }{9: 5 }{12:^in his cave. }|
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]])
end
feed("k")
@@ -141,28 +145,34 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {6: }{12:^in his cave. }|
- {7: } |
+ {6:+ }{9: 1 }{13:^+-- 4 lines: This is a················}|
+ {7: }{8: 5 }in his cave. |
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {6: }{12:^in his cave. }|
- {7: } |
- {1:~ }|
- |
+ {6:+ }{9: 1 }{13:^+-- 4 lines: This is a················}|
+ {7: }{8: 5 }in his cave. |
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]])
end
+ -- CursorLine is applied correctly with screenrow motions #22232
+ feed("jgk")
+ screen:expect_unchanged()
+ -- CursorLine is applied correctly when closing a fold when cursor is not at fold start
+ feed("zo4Gzc")
+ screen:expect_unchanged()
command("set cursorlineopt=line")
if multigrid then
screen:expect([[
@@ -176,28 +186,79 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {7: }{12:^in his cave. }|
- {7: } |
+ {7:+ }{8: 1 }{13:^+-- 4 lines: This is a················}|
+ {7: }{8: 5 }in his cave. |
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
- {7: }This is a |
- {7: }valid English |
- {7: }sentence composed by |
- {7: }an exhausted developer |
- {7: }{12:^in his cave. }|
- {7: } |
- {1:~ }|
- |
+ {7:+ }{8: 1 }{13:^+-- 4 lines: This is a················}|
+ {7: }{8: 5 }in his cave. |
+ {7: }{8: 6 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+ command("set relativenumber cursorlineopt=number")
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {6:+ }{9:1 }{5:^+-- 4 lines: This is a················}|
+ {7: }{8: 1 }in his cave. |
+ {7: }{8: 2 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]])
+ else
+ screen:expect([[
+ {6:+ }{9:1 }{5:^+-- 4 lines: This is a················}|
+ {7: }{8: 1 }in his cave. |
+ {7: }{8: 2 } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
]])
end
+ end
+
+ describe("when 'cursorline' is set", function()
+ it('with high-priority CursorLine', function()
+ command("hi! CursorLine guibg=NONE guifg=Red gui=NONE")
+ test_folded_cursorline()
+ end)
+
+ it('with low-priority CursorLine', function()
+ command("hi! CursorLine guibg=NONE guifg=NONE gui=underline")
+ local attrs = screen:get_default_attr_ids()
+ attrs[12] = {underline = true}
+ attrs[13] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey, underline = true}
+ screen:set_default_attr_ids(attrs)
+ test_folded_cursorline()
+ end)
end)
it("work with spell", function()
@@ -362,6 +423,119 @@ describe("folded lines", function()
:set norightleft |
]])
end
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 2, 0, 0)
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {7:▸ }{5:^+-- 6 lines: aa···························}|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :set norightleft |
+ ]])
+ else
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ screen:expect([[
+ {7:▸ }{5:^+-- 6 lines: aa···························}|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :set norightleft |
+ ]])
+ end
+
+ -- Add a winbar to avoid double-clicks
+ command('setlocal winbar=!!!!!!')
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 2, 1, 0)
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {11:!!!!!! }|
+ {7:▾▸}{5:^+--- 5 lines: aa··························}|
+ {7:│ }ff |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :set norightleft |
+ ]])
+ else
+ meths.input_mouse('left', 'press', '', 0, 1, 0)
+ screen:expect([[
+ {11:!!!!!! }|
+ {7:▾▸}{5:^+--- 5 lines: aa··························}|
+ {7:│ }ff |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :set norightleft |
+ ]])
+ end
+
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 2, 1, 1)
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {11:!!!!!! }|
+ {7:▾▾}^aa |
+ {7:││}bb |
+ {7:││}cc |
+ {7:││}dd |
+ {7:││}ee |
+ {7:│ }ff |
+ ## grid 3
+ :set norightleft |
+ ]])
+ else
+ meths.input_mouse('left', 'press', '', 0, 1, 1)
+ screen:expect([[
+ {11:!!!!!! }|
+ {7:▾▾}^aa |
+ {7:││}bb |
+ {7:││}cc |
+ {7:││}dd |
+ {7:││}ee |
+ {7:│ }ff |
+ :set norightleft |
+ ]])
+ end
end)
it("works with split", function()
@@ -928,9 +1102,7 @@ describe("folded lines", function()
end)
it("works with multibyte text", function()
- -- Currently the only allowed value of 'maxcombine'
- eq(6, meths.get_option('maxcombine'))
- eq(true, meths.get_option('arabicshape'))
+ eq(true, meths.get_option_value('arabicshape', {}))
insert([[
å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢͟ العَرَبِيَّة
möre text]])
@@ -946,7 +1118,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ |
+ å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ ﺎﻠﻋَﺮَﺒِﻳَّﺓ |
möre tex^t |
{1:~ }|
{1:~ }|
@@ -958,7 +1130,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ |
+ å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ ﺎﻠﻋَﺮَﺒِﻳَّﺓ |
möre tex^t |
{1:~ }|
{1:~ }|
@@ -982,7 +1154,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}|
+ {5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -994,7 +1166,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}|
+ {5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1018,7 +1190,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}|
+ {5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ العَرَبِيَّة·················}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1030,7 +1202,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}|
+ {5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ العَرَبِيَّة·················}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1054,7 +1226,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}|
+ {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ العَرَبِيَّة···········}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1066,7 +1238,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}|
+ {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ العَرَبِيَّة···········}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -1091,7 +1263,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {5:···········ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}{8: 1 }{7: +}|
+ {5:···········ةيَّبِرَعَلا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}{8: 1 }{7: +}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1103,7 +1275,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {5:···········ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}{8: 1 }{7: +}|
+ {5:···········ةيَّبِرَعَلا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}{8: 1 }{7: +}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1127,7 +1299,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
+ {5:·················ةيَّبِرَعَلا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1139,7 +1311,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
+ {5:·················ةيَّبِرَعَلا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1163,7 +1335,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
+ {5:·················ﺔﻴَّﺑِﺮَﻌَﻟﺍ x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1175,7 +1347,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
+ {5:·················ﺔﻴَّﺑِﺮَﻌَﻟﺍ x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -1199,7 +1371,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- ﺔﻴَّﺑِﺮَﻌَ^ﻟﺍ x̎͂̀̂͛͛ 语 å|
+ ﺔﻴَّﺑِﺮَﻌَ^ﻟﺍ x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å|
txet eröm|
{1: ~}|
{1: ~}|
@@ -1211,7 +1383,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- ﺔﻴَّﺑِﺮَﻌَ^ﻟﺍ x̎͂̀̂͛͛ 语 å|
+ ﺔﻴَّﺑِﺮَﻌَ^ﻟﺍ x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å|
txet eröm|
{1: ~}|
{1: ~}|
@@ -1235,7 +1407,7 @@ describe("folded lines", function()
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
- ةيَّبِرَعَ^لا x̎͂̀̂͛͛ 语 å|
+ ةيَّبِرَعَ^لا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å|
txet eröm|
{1: ~}|
{1: ~}|
@@ -1247,7 +1419,7 @@ describe("folded lines", function()
]])
else
screen:expect([[
- ةيَّبِرَعَ^لا x̎͂̀̂͛͛ 语 å|
+ ةيَّبِرَعَ^لا x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢ 语 å|
txet eröm|
{1: ~}|
{1: ~}|
@@ -1854,21 +2026,19 @@ describe("folded lines", function()
end
end)
- it('fold attached virtual lines are drawn correctly #21837', function()
+ it('fold attached virtual lines are drawn and scrolled correctly #21837', function()
funcs.setline(1, 'line 1')
funcs.setline(2, 'line 2')
funcs.setline(3, 'line 3')
funcs.setline(4, 'line 4')
feed("zfj")
- exec_lua([[
- local ns = vim.api.nvim_create_namespace("ns")
- vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines_above = true, virt_lines = {{{"virt_line above line 1", ""}}} })
- vim.api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_lines = {{{"virt_line below line 2", ""}}} })
- vim.api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_lines_above = true, virt_lines = {{{"virt_line above line 3", ""}}} })
- vim.api.nvim_buf_set_extmark(0, ns, 3, 0, { virt_lines = {{{"virt_line below line 4", ""}}} })
- ]])
+ local ns = meths.create_namespace('ns')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_lines_above = true, virt_lines = {{{"virt_line above line 1", ""}}} })
+ meths.buf_set_extmark(0, ns, 1, 0, { virt_lines = {{{"virt_line below line 2", ""}}} })
+ meths.buf_set_extmark(0, ns, 2, 0, { virt_lines_above = true, virt_lines = {{{"virt_line above line 3", ""}}} })
+ meths.buf_set_extmark(0, ns, 3, 0, { virt_lines = {{{"virt_line below line 4", ""}}} })
if multigrid then
- screen:expect([[
+ screen:expect{grid=[[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
@@ -1888,7 +2058,9 @@ describe("folded lines", function()
{1:~ }|
## grid 3
|
- ]])
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 5, curline = 0, curcol = 0, linecount = 4, sum_scroll_delta = 0};
+ }}
else
screen:expect([[
{5:^+-- 2 lines: line 1·························}|
@@ -1904,7 +2076,7 @@ describe("folded lines", function()
feed('jzfj')
if multigrid then
- screen:expect([[
+ screen:expect{grid=[[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
@@ -1924,7 +2096,9 @@ describe("folded lines", function()
{1:~ }|
## grid 3
|
- ]])
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 5, curline = 2, curcol = 0, linecount = 4, sum_scroll_delta = 0};
+ }}
else
screen:expect([[
{5:+-- 2 lines: line 1·························}|
@@ -1941,7 +2115,7 @@ describe("folded lines", function()
feed('kzo<C-Y>')
funcs.setline(5, 'line 5')
if multigrid then
- screen:expect([[
+ screen:expect{grid=[[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
@@ -1961,7 +2135,9 @@ describe("folded lines", function()
{1:~ }|
## grid 3
|
- ]])
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 6, curline = 0, curcol = 0, linecount = 5, sum_scroll_delta = -1};
+ }}
else
screen:expect([[
virt_line above line 1 |
@@ -1974,6 +2150,940 @@ describe("folded lines", function()
|
]])
end
+
+ meths.input_mouse('left', 'press', '', multigrid and 2 or 0, 4, 0)
+ eq({
+ screencol = 1,
+ screenrow = 5,
+ winid = 1000,
+ wincol = 1,
+ winrow = 5,
+ line = 3,
+ column = 1,
+ coladd = 0,
+ }, funcs.getmousepos())
+
+ meths.buf_set_extmark(0, ns, 1, 0, { virt_lines = {{{"more virt_line below line 2", ""}}} })
+ feed('G<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ line 1 |
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect([[
+ line 1 |
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 1, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 1};
+ }}
+ else
+ screen:expect([[
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 2};
+ }}
+ else
+ screen:expect([[
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 3};
+ }}
+ else
+ screen:expect([[
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 4};
+ }}
+ else
+ screen:expect([[
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('<C-E>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 4, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 5};
+ }}
+ else
+ screen:expect([[
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ feed('3<C-Y>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 2};
+ }}
+ else
+ screen:expect([[
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^line 5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+
+ meths.input_mouse('left', 'press', '3', multigrid and 2 or 0, 3, 0)
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^l{16:ine 5} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL LINE --} |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 2};
+ }}
+ else
+ screen:expect([[
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^l{16:ine 5} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL LINE --} |
+ ]])
+ end
+
+ meths.input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 0)
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^l{16:ine 5} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL LINE --} |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 0, linecount = 5, sum_scroll_delta = 3};
+ }}
+ else
+ screen:expect([[
+ more virt_line below line 2 |
+ {5:+-- 2 lines: line 3·························}|
+ ^l{16:ine 5} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL LINE --} |
+ ]])
+ end
+
+ meths.input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 5)
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {5:+-- 2 lines: line 3·························}|
+ {16:line }^5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL LINE --} |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 2, botline = 6, curline = 4, curcol = 5, linecount = 5, sum_scroll_delta = 4};
+ }}
+ else
+ screen:expect([[
+ {5:+-- 2 lines: line 3·························}|
+ {16:line }^5 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL LINE --} |
+ ]])
+ end
+
+ feed('<Esc>gg')
+ command('botright 1split | wincmd w')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ {3:[No Name] [+] }|
+ [4:---------------------------------------------]|
+ {2:[No Name] [+] }|
+ [3:---------------------------------------------]|
+ ## grid 2
+ ^line 1 |
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ ## grid 3
+ |
+ ## grid 4
+ line 1 |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 5, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 5, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect([[
+ ^line 1 |
+ line 2 |
+ virt_line below line 2 |
+ more virt_line below line 2 |
+ {3:[No Name] [+] }|
+ line 1 |
+ {2:[No Name] [+] }|
+ |
+ ]])
+ end
+
+ feed('<C-Y>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ {3:[No Name] [+] }|
+ [4:---------------------------------------------]|
+ {2:[No Name] [+] }|
+ [3:---------------------------------------------]|
+ ## grid 2
+ virt_line above line 1 |
+ ^line 1 |
+ line 2 |
+ virt_line below line 2 |
+ ## grid 3
+ |
+ ## grid 4
+ line 1 |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 5, sum_scroll_delta = -1};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 5, sum_scroll_delta = 0};
+ }}
+ else
+ screen:expect([[
+ virt_line above line 1 |
+ ^line 1 |
+ line 2 |
+ virt_line below line 2 |
+ {3:[No Name] [+] }|
+ line 1 |
+ {2:[No Name] [+] }|
+ |
+ ]])
+ end
+ end)
+
+ it('Folded and Visual highlights are combined #19691', function()
+ command('hi! Visual guibg=Red')
+ insert([[
+ " foofoofoofoofoofoo
+ " 口 {{{1
+ set nocp
+ " }}}1
+ " barbarbarbarbarbar
+ " 口 {{{1
+ set foldmethod=marker
+ " }}}1
+ " bazbazbazbazbazbaz]])
+ feed('gg')
+ command('source')
+ feed('<C-V>G15l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {14:" foofoofoofoofo}ofoo |
+ {15:+-- 3 lines: " }{5:口···························}|
+ {14:" barbarbarbarba}rbar |
+ {15:+-- 3 lines: " }{5:口···························}|
+ {14:" bazbazbazbazb}^azbaz |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ {14:" foofoofoofoofo}ofoo |
+ {15:+-- 3 lines: " }{5:口···························}|
+ {14:" barbarbarbarba}rbar |
+ {15:+-- 3 lines: " }{5:口···························}|
+ {14:" bazbazbazbazb}^azbaz |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+
+ feed('l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {14:" foofoofoofoofoo}foo |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" barbarbarbarbar}bar |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" bazbazbazbazba}^zbaz |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ {14:" foofoofoofoofoo}foo |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" barbarbarbarbar}bar |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" bazbazbazbazba}^zbaz |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+
+ feed('l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {14:" foofoofoofoofoof}oo |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" barbarbarbarbarb}ar |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" bazbazbazbazbaz}^baz |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ {14:" foofoofoofoofoof}oo |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" barbarbarbarbarb}ar |
+ {15:+-- 3 lines: " 口}{5:···························}|
+ {14:" bazbazbazbazbaz}^baz |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+
+ feed('2l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {14:" foofoofoofoofoofoo} |
+ {15:+-- 3 lines: " 口··}{5:·························}|
+ {14:" barbarbarbarbarbar} |
+ {15:+-- 3 lines: " 口··}{5:·························}|
+ {14:" bazbazbazbazbazba}^z |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ {14:" foofoofoofoofoofoo} |
+ {15:+-- 3 lines: " 口··}{5:·························}|
+ {14:" barbarbarbarbarbar} |
+ {15:+-- 3 lines: " 口··}{5:·························}|
+ {14:" bazbazbazbazbazba}^z |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+
+ feed('O16l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ " foofoofoofoofo{14:ofoo} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " barbarbarbarba{14:rbar} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " bazbazbazbazba^z{14:baz} |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ " foofoofoofoofo{14:ofoo} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " barbarbarbarba{14:rbar} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " bazbazbazbazba^z{14:baz} |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+
+ feed('l')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ " foofoofoofoofoo{14:foo} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " barbarbarbarbar{14:bar} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " bazbazbazbazbaz^b{14:az} |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ else
+ screen:expect([[
+ " foofoofoofoofoo{14:foo} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " barbarbarbarbar{14:bar} |
+ {5:+-- 3 lines: " }{15:口··}{5:·························}|
+ " bazbazbazbazbaz^b{14:az} |
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL BLOCK --} |
+ ]])
+ end
+ end)
+
+ it('do not show search or match highlight #24084', function()
+ insert([[
+ line 1
+ line 2
+ line 3
+ line 4]])
+ command('2,3fold')
+ feed('/line')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {2:line} 1 |
+ {5:+-- 2 lines: line 2·························}|
+ {6:line} 4 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ /line^ |
+ ]])
+ else
+ screen:expect([[
+ {2:line} 1 |
+ {5:+-- 2 lines: line 2·························}|
+ {6:line} 4 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ /line^ |
+ ]])
+ end
+ feed('<Esc>')
+ funcs.matchadd('Search', 'line')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [2:---------------------------------------------]|
+ [3:---------------------------------------------]|
+ ## grid 2
+ {6:line} 1 |
+ {5:+-- 2 lines: line 2·························}|
+ {6:line} ^4 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]])
+ else
+ screen:expect([[
+ {6:line} 1 |
+ {5:+-- 2 lines: line 2·························}|
+ {6:line} ^4 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+ end)
+
+ it('support foldtext with virtual text format', function()
+ screen:try_resize(30, 7)
+ insert(content1)
+ command("hi! CursorLine guibg=NONE guifg=Red gui=NONE")
+ command('hi F0 guibg=Red guifg=Black')
+ command('hi F1 guifg=White')
+ meths.set_option_value('cursorline', true, {})
+ meths.set_option_value('foldcolumn', '4', {})
+ meths.set_option_value('foldtext', '['
+ .. '["▶", ["F0", "F1"]], '
+ .. '[v:folddashes], '
+ .. '["\t", "Search"], '
+ .. '[getline(v:foldstart), "NonText"]]', {})
+
+ command('3,4fold')
+ command('5,6fold')
+ command('2,6fold')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [3:------------------------------]|
+ ## grid 2
+ {7: }This is a |
+ {7:+ }{4:^▶}{13:-}{17: }{18:valid English}{13:·····}|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]])
+ else
+ screen:expect([[
+ {7: }This is a |
+ {7:+ }{4:^▶}{13:-}{17: }{18:valid English}{13:·····}|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+ eq('▶-\tvalid English', funcs.foldtextresult(2))
+
+ feed('zo')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [3:------------------------------]|
+ ## grid 2
+ {7: }This is a |
+ {7:- }valid English |
+ {7:│+ }{4:▶}{5:--}{19: }{18:sentence composed }|
+ {7:│+ }{4:^▶}{13:--}{17: }{18:in his cave.}{13:······}|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]])
+ else
+ screen:expect([[
+ {7: }This is a |
+ {7:- }valid English |
+ {7:│+ }{4:▶}{5:--}{19: }{18:sentence composed }|
+ {7:│+ }{4:^▶}{13:--}{17: }{18:in his cave.}{13:······}|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end
+ eq('▶--\tsentence composed by', funcs.foldtextresult(3))
+ eq('▶--\tin his cave.', funcs.foldtextresult(5))
+
+ command('hi! Visual guibg=Red')
+ feed('V2k')
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [3:------------------------------]|
+ ## grid 2
+ {7: }This is a |
+ {7:- }^v{14:alid English} |
+ {7:│+ }{4:▶}{15:--}{19: }{20:sentence composed }|
+ {7:│+ }{4:▶}{15:--}{19: }{20:in his cave.}{15:······}|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {11:-- VISUAL LINE --} |
+ ]])
+ else
+ screen:expect([[
+ {7: }This is a |
+ {7:- }^v{14:alid English} |
+ {7:│+ }{4:▶}{15:--}{19: }{20:sentence composed }|
+ {7:│+ }{4:▶}{15:--}{19: }{20:in his cave.}{15:······}|
+ {1:~ }|
+ {1:~ }|
+ {11:-- VISUAL LINE --} |
+ ]])
+ end
+
+ meths.set_option_value('rightleft', true, {})
+ if multigrid then
+ screen:expect([[
+ ## grid 1
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [2:------------------------------]|
+ [3:------------------------------]|
+ ## grid 2
+ a si sihT{7: }|
+ {14:hsilgnE dila}^v{7: -}|
+ {20: desopmoc ecnetnes}{19: }{15:--}{4:▶}{7: +│}|
+ {15:······}{20:.evac sih ni}{19: }{15:--}{4:▶}{7: +│}|
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ {11:-- VISUAL LINE --} |
+ ]])
+ else
+ screen:expect([[
+ a si sihT{7: }|
+ {14:hsilgnE dila}^v{7: -}|
+ {20: desopmoc ecnetnes}{19: }{15:--}{4:▶}{7: +│}|
+ {15:······}{20:.evac sih ni}{19: }{15:--}{4:▶}{7: +│}|
+ {1: ~}|
+ {1: ~}|
+ {11:-- VISUAL LINE --} |
+ ]])
+ end
end)
end
@@ -1984,26 +3094,4 @@ describe("folded lines", function()
describe('without ext_multigrid', function()
with_ext_multigrid(false)
end)
-
- it('no folds remains if :delete makes buffer empty #19671', function()
- funcs.setline(1, {'foo', 'bar', 'baz'})
- command('2,3fold')
- command('%delete')
- eq(0, funcs.foldlevel(1))
- end)
-
- it('multibyte fold markers work #20438', function()
- meths.win_set_option(0, 'foldmethod', 'marker')
- meths.win_set_option(0, 'foldmarker', '«,»')
- insert([[
- bbbbb
- bbbbb
- bbbbb]])
- feed('zfgg')
- expect([[
- bbbbb/*«*/
- bbbbb
- bbbbb/*»*/]])
- eq(1, funcs.foldlevel(1))
- end)
end)
diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua
index 288c2a214f..7776e024b0 100644
--- a/test/functional/ui/highlight_spec.lua
+++ b/test/functional/ui/highlight_spec.lua
@@ -8,6 +8,7 @@ local feed_command, eq = helpers.feed_command, helpers.eq
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs
local meths = helpers.meths
+local exec_lua = helpers.exec_lua
describe('colorscheme compatibility', function()
before_each(function()
@@ -376,7 +377,6 @@ describe('highlight', function()
-- Vertical cursor: highlights char-at-cursor. #8983
command('set guicursor=a:block-blinkon175')
- feed('<esc>gg$vhhh')
screen:expect([[
line1 foo{1:^ bar} |
|
@@ -427,7 +427,7 @@ describe('highlight', function()
^ |
{2:~ }|
|
- ]],{
+ ]], {
[1] = {strikethrough = true},
[2] = {bold = true, foreground = Screen.colors.Blue1},
})
@@ -516,7 +516,7 @@ describe('highlight', function()
{1:neovim} tabbed^ |
{0:~ }|
{5:-- INSERT --} |
- ]],{
+ ]], {
[0] = {bold=true, foreground=Screen.colors.Blue},
[1] = {background = Screen.colors.Yellow, foreground = Screen.colors.Red,
special = Screen.colors.Red},
@@ -527,6 +527,41 @@ describe('highlight', function()
})
end)
+
+ it("'diff', syntax and extmark #23722", function()
+ local screen = Screen.new(25,10)
+ screen:attach()
+ exec([[
+ new
+ call setline(1, ['', '01234 6789'])
+ windo diffthis
+ wincmd w
+ syn match WarningMsg "^.*$"
+ call nvim_buf_add_highlight(0, -1, 'ErrorMsg', 1, 2, 8)
+ ]])
+ screen:expect([[
+ {1: }^ |
+ {1: }{2:01}{3:234 67}{2:89}{5: }|
+ {4:~ }|
+ {4:~ }|
+ {7:[No Name] [+] }|
+ {1: } |
+ {1: }{6:-----------------------}|
+ {4:~ }|
+ {8:[No Name] }|
+ |
+ ]], {
+ [0] = {Screen.colors.WebGray, foreground = Screen.colors.DarkBlue},
+ [1] = {background = Screen.colors.Grey, foreground = Screen.colors.Blue4},
+ [2] = {foreground = Screen.colors.Red, background = Screen.colors.LightBlue},
+ [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.LightBlue},
+ [4] = {bold = true, foreground = Screen.colors.Blue},
+ [5] = {background = Screen.colors.LightBlue},
+ [6] = {bold = true, background = Screen.colors.LightCyan, foreground = Screen.colors.Blue1},
+ [7] = {reverse = true, bold = true},
+ [8] = {reverse = true},
+ })
+ end)
end)
describe("'listchars' highlight", function()
@@ -1412,10 +1447,10 @@ describe('ColorColumn highlight', function()
[3] = {foreground = Screen.colors.Brown}, -- LineNr
[4] = {foreground = Screen.colors.Brown, bold = true}, -- CursorLineNr
[5] = {foreground = Screen.colors.Blue, bold = true}, -- NonText
- -- NonText and ColorColumn
[6] = {foreground = Screen.colors.Blue, background = Screen.colors.LightRed, bold = true},
[7] = {reverse = true, bold = true}, -- StatusLine
[8] = {reverse = true}, -- StatusLineNC
+ [9] = {background = Screen.colors.Grey90, foreground = Screen.colors.Red},
})
screen:attach()
end)
@@ -1501,6 +1536,25 @@ describe('ColorColumn highlight', function()
|
]])
end)
+
+ it('is combined with low-priority CursorLine highlight #23016', function()
+ screen:try_resize(40, 2)
+ command('set colorcolumn=30 cursorline')
+ screen:expect([[
+ {2:^ }{1: }{2: }|
+ |
+ ]])
+ command('hi clear ColorColumn')
+ screen:expect([[
+ {2:^ }|
+ |
+ ]])
+ command('hi ColorColumn guifg=Red')
+ screen:expect([[
+ {2:^ }{9: }{2: }|
+ |
+ ]])
+ end)
end)
describe("MsgSeparator highlight and msgsep fillchar", function()
@@ -1812,6 +1866,31 @@ describe("'winhighlight' highlight", function()
]])
end)
+ it('works for background color in rightleft window #22640', function()
+ -- Use a wide screen to also check that this doesn't overflow linebuf_attr.
+ screen:try_resize(80, 6)
+ insert('aa')
+ command('setlocal rightleft')
+ command('setlocal winhl=Normal:Background1')
+ screen:expect([[
+ {1: ^aa}|
+ {2: ~}|
+ {2: ~}|
+ {2: ~}|
+ {2: ~}|
+ |
+ ]])
+ command('botright vsplit')
+ screen:expect([[
+ {1: aa│ ^aa}|
+ {2: ~}{1:│}{2: ~}|
+ {2: ~}{1:│}{2: ~}|
+ {2: ~}{1:│}{2: ~}|
+ {4:[No Name] [+] }{3:[No Name] [+] }|
+ |
+ ]])
+ end)
+
it('handles undefined groups', function()
command("set winhl=Normal:Background1")
screen:expect([[
@@ -2408,6 +2487,23 @@ describe("'winhighlight' highlight", function()
|
]]}
end)
+
+ it('can link to empty highlight group', function()
+ command 'hi NormalNC guibg=Red' -- czerwone time
+ command 'set winhl=NormalNC:Normal'
+ command 'split'
+
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {3:[No Name] }|
+ |
+ {0:~ }|
+ {4:[No Name] }|
+ |
+ ]]}
+ end)
end)
describe('highlight namespaces', function()
@@ -2427,6 +2523,8 @@ describe('highlight namespaces', function()
[6] = {bold = true, reverse = true};
[7] = {reverse = true};
[8] = {foreground = Screen.colors.Gray20};
+ [9] = {foreground = Screen.colors.Blue};
+ [10] = {bold = true, foreground = Screen.colors.SeaGreen};
}
ns1 = meths.create_namespace 'grungy'
@@ -2546,4 +2644,34 @@ describe('highlight namespaces', function()
|
]]}
end)
+
+ it('winhl does not accept invalid value #24586', function()
+ local res = exec_lua([[
+ local curwin = vim.api.nvim_get_current_win()
+ vim.api.nvim_command("set winhl=Normal:Visual")
+ local _, msg = pcall(vim.api.nvim_command,"set winhl='Normal:Wrong'")
+ return { msg, vim.wo[curwin].winhl }
+ ]])
+ eq({
+ "Vim(set):E5248: Invalid character in group name",
+ "Normal:Visual",
+ },res)
+ end)
+
+ it('Normal in set_hl #25474', function()
+ meths.set_hl(0, 'Normal', {bg='#333333'})
+ command('highlight Ignore')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {6: }|
+ |
+ Ignore {8:xxx} {9:ctermf}|
+ {9:g=}15 {9:guifg=}|
+ bg |
+ {10:Press ENTER or type comma}|
+ {10:nd to continue}^ |
+ ]]}
+ end)
end)
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index 6fbf9b72c8..3ee67a710c 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
-local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
local eval = helpers.eval
local feed_command = helpers.feed_command
@@ -175,11 +174,14 @@ describe(":substitute, 'inccommand' preserves", function()
it("'undolevels' (inccommand="..case..")", function()
feed_command("set undolevels=139")
feed_command("setlocal undolevels=34")
+ feed_command("split") -- Show the buffer in multiple windows
feed_command("set inccommand=" .. case)
insert("as")
- feed(":%s/as/glork/<enter>")
- eq(meths.get_option('undolevels'), 139)
- eq(curbufmeths.get_option('undolevels'), 34)
+ feed(":%s/as/glork/")
+ poke_eventloop()
+ feed("<enter>")
+ eq(meths.get_option_value('undolevels', {scope='global'}), 139)
+ eq(meths.get_option_value('undolevels', {buf=0}), 34)
end)
end
@@ -745,10 +747,11 @@ describe(":substitute, 'inccommand' preserves undo", function()
end)
describe(":substitute, inccommand=split", function()
- local screen = Screen.new(30,15)
+ local screen
before_each(function()
clear()
+ screen = Screen.new(30,15)
common_setup(screen, "split", default_text .. default_text)
end)
@@ -1191,7 +1194,7 @@ describe(":substitute, inccommand=split", function()
it("deactivates if 'redrawtime' is exceeded #5602", function()
-- prevent redraws from 'incsearch'
- meths.set_option('incsearch', false)
+ meths.set_option_value('incsearch', false, {})
-- Assert that 'inccommand' is ENABLED initially.
eq("split", eval("&inccommand"))
-- Set 'redrawtime' to minimal value, to ensure timeout is triggered.
@@ -1413,10 +1416,11 @@ describe(":substitute, inccommand=split", function()
end)
describe("inccommand=nosplit", function()
- local screen = Screen.new(20,10)
+ local screen
before_each(function()
clear()
+ screen = Screen.new(20,10)
common_setup(screen, "nosplit", default_text .. default_text)
end)
@@ -1644,11 +1648,12 @@ describe("inccommand=nosplit", function()
end)
describe(":substitute, 'inccommand' with a failing expression", function()
- local screen = Screen.new(20,10)
+ local screen
local cases = { "", "split", "nosplit" }
local function refresh(case)
clear()
+ screen = Screen.new(20,10)
common_setup(screen, case, default_text)
end
@@ -1717,7 +1722,7 @@ describe("'inccommand' and :cnoremap", function()
local function refresh(case, visual)
clear()
- screen = visual and Screen.new(50,10) or nil
+ screen = visual and Screen.new(80,10) or nil
common_setup(screen, case, default_text)
end
@@ -2127,9 +2132,10 @@ describe("'inccommand' with 'gdefault'", function()
end)
describe(":substitute", function()
- local screen = Screen.new(30,15)
+ local screen
before_each(function()
clear()
+ screen = Screen.new(30,15)
end)
it("inccommand=split, highlights multiline substitutions", function()
@@ -2335,8 +2341,7 @@ describe(":substitute", function()
]])
end)
- it("inccommand=split, substitutions of different length",
- function()
+ it("inccommand=split, substitutions of different length", function()
common_setup(screen, "split", "T T123 T2T TTT T090804\nx")
feed(":%s/T\\([0-9]\\+\\)/\\1\\1/g")
@@ -2462,16 +2467,14 @@ describe(":substitute", function()
end)
it("inccommand=split, contraction of two subsequent NL chars", function()
- -- luacheck: push ignore 611
local text = [[
AAA AA
-
+
BBB BB
-
+
CCC CC
-
+
]]
- -- luacheck: pop
-- This used to crash, but more than 20 highlight entries are required
-- to reproduce it (so that the marktree has multiple nodes)
@@ -2498,16 +2501,14 @@ describe(":substitute", function()
end)
it("inccommand=nosplit, contraction of two subsequent NL chars", function()
- -- luacheck: push ignore 611
local text = [[
AAA AA
-
+
BBB BB
-
+
CCC CC
-
+
]]
- -- luacheck: pop
common_setup(screen, "nosplit", string.rep(text,10))
feed(":%s/\\n\\n/<c-v><c-m>/g")
@@ -2872,8 +2873,8 @@ it(':substitute with inccommand during :terminal activity', function()
return
end
retry(2, 40000, function()
- local screen = Screen.new(30,15)
clear()
+ local screen = Screen.new(30,15)
command("set cmdwinheight=3")
feed(([[:terminal "%s" REP 5000 xxx<cr>]]):format(testprg('shell-test')))
@@ -2886,14 +2887,15 @@ it(':substitute with inccommand during :terminal activity', function()
feed('gg')
feed(':%s/foo/ZZZ')
sleep(20) -- Allow some terminal activity.
- helpers.poke_eventloop()
+ poke_eventloop()
+ screen:sleep(0)
screen:expect_unchanged()
end)
end)
it(':substitute with inccommand, timer-induced :redraw #9777', function()
- local screen = Screen.new(30,12)
clear()
+ local screen = Screen.new(30,12)
command('set cmdwinheight=3')
command('call timer_start(10, {-> execute("redraw")}, {"repeat":-1})')
command('call timer_start(10, {-> execute("redrawstatus")}, {"repeat":-1})')
@@ -2919,15 +2921,24 @@ it(':substitute with inccommand, timer-induced :redraw #9777', function()
end)
it(':substitute with inccommand, allows :redraw before first separator is typed #18857', function()
- local screen = Screen.new(30,6)
clear()
+ local screen = Screen.new(30,6)
common_setup(screen, 'split', 'foo bar baz\nbar baz fox\nbar foo baz')
command('hi! link NormalFloat CursorLine')
local float_buf = meths.create_buf(false, true)
meths.open_win(float_buf, false, {
relative = 'editor', height = 1, width = 5, row = 3, col = 0, focusable = false,
})
- feed(':%s')
+ feed(':')
+ screen:expect([[
+ foo bar baz |
+ bar baz fox |
+ bar foo baz |
+ {16: }{15: }|
+ {15:~ }|
+ :^ |
+ ]])
+ feed('%s')
screen:expect([[
foo bar baz |
bar baz fox |
@@ -2949,8 +2960,8 @@ it(':substitute with inccommand, allows :redraw before first separator is typed
end)
it(':substitute with inccommand, does not crash if range contains invalid marks', function()
- local screen = Screen.new(30, 6)
clear()
+ local screen = Screen.new(30, 6)
common_setup(screen, 'split', 'test')
feed([[:'a,'bs]])
screen:expect([[
@@ -2975,8 +2986,8 @@ it(':substitute with inccommand, does not crash if range contains invalid marks'
end)
it(':substitute with inccommand, no unnecessary redraw if preview is not shown', function()
- local screen = Screen.new(60, 6)
clear()
+ local screen = Screen.new(60, 6)
common_setup(screen, 'split', 'test')
feed(':ls<CR>')
screen:expect([[
@@ -3028,8 +3039,8 @@ it(':substitute with inccommand, no unnecessary redraw if preview is not shown',
end)
it(":substitute doesn't crash with inccommand, if undo is empty #12932", function()
- local screen = Screen.new(10,5)
clear()
+ local screen = Screen.new(10,5)
command('set undolevels=-1')
common_setup(screen, 'split', 'test')
feed(':%s/test')
@@ -3048,8 +3059,8 @@ it(":substitute doesn't crash with inccommand, if undo is empty #12932", functio
end)
it(':substitute with inccommand works properly if undo is not synced #20029', function()
- local screen = Screen.new(30, 6)
clear()
+ local screen = Screen.new(30, 6)
common_setup(screen, 'nosplit', 'foo\nbar\nbaz')
meths.set_keymap('x', '<F2>', '<Esc>`<Oaaaaa asdf<Esc>`>obbbbb asdf<Esc>V`<k:s/asdf/', {})
feed('gg0<C-V>lljj<F2>')
@@ -3084,11 +3095,40 @@ it(':substitute with inccommand works properly if undo is not synced #20029', fu
baz]])
end)
+it(':substitute with inccommand does not unexpectedly change viewport #25697', function()
+ clear()
+ local screen = Screen.new(45, 5)
+ common_setup(screen, 'nosplit', long_multiline_text)
+ command('vnew | tabnew | tabclose')
+ screen:expect([[
+ ^ │£ m n |
+ {15:~ }│t œ ¥ |
+ {15:~ }│ |
+ {11:[No Name] }{10:[No Name] [+] }|
+ |
+ ]])
+ feed(':s/')
+ screen:expect([[
+ │£ m n |
+ {15:~ }│t œ ¥ |
+ {15:~ }│ |
+ {11:[No Name] }{10:[No Name] [+] }|
+ :s/^ |
+ ]])
+ feed('<Esc>')
+ screen:expect([[
+ ^ │£ m n |
+ {15:~ }│t œ ¥ |
+ {15:~ }│ |
+ {11:[No Name] }{10:[No Name] [+] }|
+ |
+ ]])
+end)
+
it('long :%s/ with inccommand does not collapse cmdline', function()
- local screen = Screen.new(10,5)
clear()
- common_setup(screen)
- command('set inccommand=nosplit')
+ local screen = Screen.new(10,5)
+ common_setup(screen, 'nosplit')
feed(':%s/AAAAAAA', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A')
screen:expect([[
@@ -3100,6 +3140,21 @@ it('long :%s/ with inccommand does not collapse cmdline', function()
]])
end)
+it("with 'inccommand' typing invalid `={expr}` does not show error", function()
+ clear()
+ local screen = Screen.new(30, 6)
+ common_setup(screen, 'nosplit')
+ feed(':edit `=`')
+ screen:expect([[
+ |
+ {15:~ }|
+ {15:~ }|
+ {15:~ }|
+ {15:~ }|
+ :edit `=`^ |
+ ]])
+end)
+
it("with 'inccommand' typing :filter doesn't segfault or leak memory #19057", function()
clear()
common_setup(nil, 'nosplit')
@@ -3112,3 +3167,31 @@ it("with 'inccommand' typing :filter doesn't segfault or leak memory #19057", fu
feed('i')
assert_alive()
end)
+
+it("'inccommand' cannot be changed during preview #23136", function()
+ clear()
+ local screen = Screen.new(30, 6)
+ common_setup(screen, 'nosplit', 'foo\nbar\nbaz')
+ source([[
+ function! IncCommandToggle()
+ let prev = &inccommand
+
+ if &inccommand ==# 'split'
+ set inccommand=nosplit
+ elseif &inccommand ==# 'nosplit'
+ set inccommand=split
+ elseif &inccommand ==# ''
+ set inccommand=nosplit
+ else
+ throw 'unknown inccommand'
+ endif
+
+ return " \<BS>"
+ endfun
+
+ cnoremap <expr> <C-E> IncCommandToggle()
+ ]])
+
+ feed(':%s/foo/bar<C-E><C-E><C-E>')
+ assert_alive()
+end)
diff --git a/test/functional/ui/inccommand_user_spec.lua b/test/functional/ui/inccommand_user_spec.lua
index 43e9b94feb..da7508fad1 100644
--- a/test/functional/ui/inccommand_user_spec.lua
+++ b/test/functional/ui/inccommand_user_spec.lua
@@ -239,7 +239,8 @@ describe("'inccommand' for user commands", function()
[1] = {background = Screen.colors.Yellow1},
[2] = {foreground = Screen.colors.Blue1, bold = true},
[3] = {reverse = true},
- [4] = {reverse = true, bold = true}
+ [4] = {reverse = true, bold = true},
+ [5] = {foreground = Screen.colors.Blue},
})
screen:attach()
exec_lua(setup_replace_cmd)
@@ -391,7 +392,7 @@ describe("'inccommand' for user commands", function()
vim.api.nvim_create_user_command('Replace', function() end, {
nargs = '*',
preview = function()
- vim.api.nvim_set_option('inccommand', 'split')
+ vim.api.nvim_set_option_value('inccommand', 'split', {})
return 2
end,
})
@@ -401,6 +402,147 @@ describe("'inccommand' for user commands", function()
feed('e')
assert_alive()
end)
+
+ it('no crash when adding highlight after :substitute #21495', function()
+ command('set inccommand=nosplit')
+ exec_lua([[
+ vim.api.nvim_create_user_command("Crash", function() end, {
+ preview = function(_, preview_ns, _)
+ vim.cmd("%s/text/cats/g")
+ vim.api.nvim_buf_add_highlight(0, preview_ns, "Search", 0, 0, -1)
+ return 1
+ end,
+ })
+ ]])
+ feed(':C')
+ screen:expect([[
+ {1: cats on line 1} |
+ more cats on line 2 |
+ oh no, even more cats |
+ will the cats ever stop |
+ oh well |
+ did the cats stop |
+ why won't it stop |
+ make the cats stop |
+ |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ :C^ |
+ ]])
+ assert_alive()
+ end)
+
+ it('no crash if preview callback executes undo #20036', function()
+ command('set inccommand=nosplit')
+ exec_lua([[
+ vim.api.nvim_create_user_command('Foo', function() end, {
+ nargs = '?',
+ preview = function(_, _, _)
+ vim.cmd.undo()
+ end,
+ })
+ ]])
+
+ -- Clear undo history
+ command('set undolevels=-1')
+ feed('ggyyp')
+ command('set undolevels=1000')
+
+ feed('yypp:Fo')
+ assert_alive()
+ feed('<Esc>:Fo')
+ assert_alive()
+ end)
+
+ local function test_preview_break_undo()
+ command('set inccommand=nosplit')
+ exec_lua([[
+ vim.api.nvim_create_user_command('Test', function() end, {
+ nargs = 1,
+ preview = function(opts, _, _)
+ vim.cmd('norm i' .. opts.args)
+ return 1
+ end
+ })
+ ]])
+ feed(':Test a.a.a.a.')
+ screen:expect([[
+ text on line 1 |
+ more text on line 2 |
+ oh no, even more text |
+ will the text ever stop |
+ oh well |
+ did the text stop |
+ why won't it stop |
+ make the text stop |
+ a.a.a.a. |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ :Test a.a.a.a.^ |
+ ]])
+ feed('<C-V><Esc>u')
+ screen:expect([[
+ text on line 1 |
+ more text on line 2 |
+ oh no, even more text |
+ will the text ever stop |
+ oh well |
+ did the text stop |
+ why won't it stop |
+ make the text stop |
+ a.a.a. |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ :Test a.a.a.a.{5:^[}u^ |
+ ]])
+ feed('<Esc>')
+ screen:expect([[
+ text on line 1 |
+ more text on line 2 |
+ oh no, even more text |
+ will the text ever stop |
+ oh well |
+ did the text stop |
+ why won't it stop |
+ make the text stop |
+ ^ |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ |
+ ]])
+ end
+
+ describe('breaking undo chain in Insert mode works properly', function()
+ it('when using i_CTRL-G_u #20248', function()
+ command('inoremap . .<C-G>u')
+ test_preview_break_undo()
+ end)
+
+ it('when setting &l:undolevels to itself #24575', function()
+ command('inoremap . .<Cmd>let &l:undolevels = &l:undolevels<CR>')
+ test_preview_break_undo()
+ end)
+ end)
end)
describe("'inccommand' with multiple buffers", function()
diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua
index 697677aa67..ef47ea7ed0 100644
--- a/test/functional/ui/linematch_spec.lua
+++ b/test/functional/ui/linematch_spec.lua
@@ -779,6 +779,192 @@ something
end)
end)
+ describe('setup a diff with 2 files and set linematch:30', function()
+ before_each(function()
+ feed(':set diffopt+=linematch:30<cr>')
+ local f1 = [[
+// abc d
+// d
+// d
+ ]]
+ local f2 = [[
+
+abc d
+d
+ ]]
+ write_file(fname, f1, false)
+ write_file(fname_2, f2, false)
+ reread()
+ end)
+
+ it('display results', function()
+ screen:expect([[
+ {1: }{10: 1 }{4:^ }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 2 }{9:abc d }│{1: }{10: 1 }{8:// }{9:abc d }|
+ {1: }{10: 3 }{9:d }│{1: }{10: 2 }{8:// }{9:d }|
+ {1: }{10: }{2:-------------------------------------------}│{1: }{10: 3 }{4:// d }|
+ {1: }{10: 4 } │{1: }{10: 4 } |
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }|
+ :e |
+ ]])
+ end)
+ end)
+ describe('setup a diff with 2 files and set linematch:30, with ignore white', function()
+ before_each(function()
+ feed(':set diffopt+=linematch:30<cr>:set diffopt+=iwhiteall<cr>')
+ local f1 = [[
+void testFunction () {
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ }
+ }
+}
+ ]]
+ local f2 = [[
+void testFunction () {
+ // for (int j = 0; j < 10; i++) {
+ // }
+}
+ ]]
+ write_file(fname, f1, false)
+ write_file(fname_2, f2, false)
+ reread()
+ end)
+
+ it('display results', function()
+ screen:expect([[
+ {1: }{10: 1 }^void testFunction () { │{1: }{10: 1 }void testFunction () { |
+ {1: }{10: }{2:-------------------------------------------}│{1: }{10: 2 }{4: for (int i = 0; i < 10; i++) { }|
+ {1: }{10: 2 }{9: }{8:// for (int j = 0; j < 10; i}{9:++) { }│{1: }{10: 3 }{9: }{8:for (int j = 0; j < 10; j}{9:++) { }|
+ {1: }{10: 3 }{9: }{8:// }{9:} }│{1: }{10: 4 }{9: } }|
+ {1: }{10: }{2:-------------------------------------------}│{1: }{10: 5 }{4: } }|
+ {1: }{10: 4 }} │{1: }{10: 6 }} |
+ {1: }{10: 5 } │{1: }{10: 7 } |
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }|
+ :e |
+ ]])
+ end)
+ end)
+ describe('a diff that would result in multiple groups before grouping optimization', function()
+ before_each(function()
+ feed(':set diffopt+=linematch:30<cr>')
+ local f1 = [[
+!A
+!B
+!C
+ ]]
+ local f2 = [[
+?Z
+?A
+?B
+?C
+?A
+?B
+?B
+?C
+ ]]
+ write_file(fname, f1, false)
+ write_file(fname_2, f2, false)
+ reread()
+ end)
+
+ it('display results', function()
+ screen:expect([[
+ {1: }{10: 1 }{4:^?Z }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 2 }{8:?}{9:A }│{1: }{10: 1 }{8:!}{9:A }|
+ {1: }{10: 3 }{8:?}{9:B }│{1: }{10: 2 }{8:!}{9:B }|
+ {1: }{10: 4 }{8:?}{9:C }│{1: }{10: 3 }{8:!}{9:C }|
+ {1: }{10: 5 }{4:?A }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 6 }{4:?B }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 7 }{4:?B }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 8 }{4:?C }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 9 } │{1: }{10: 4 } |
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }|
+ :e |
+ ]])
+ end)
+ end)
+ describe('a diff that would result in multiple groups before grouping optimization', function()
+ before_each(function()
+ feed(':set diffopt+=linematch:30<cr>')
+ local f1 = [[
+!A
+!B
+!C
+ ]]
+ local f2 = [[
+?A
+?Z
+?B
+?C
+?A
+?B
+?C
+?C
+ ]]
+ write_file(fname, f1, false)
+ write_file(fname_2, f2, false)
+ reread()
+ end)
+
+ it('display results', function()
+ screen:expect([[
+ {1: }{10: 1 }{4:^?A }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 2 }{4:?Z }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 3 }{4:?B }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 4 }{4:?C }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 5 }{8:?}{9:A }│{1: }{10: 1 }{8:!}{9:A }|
+ {1: }{10: 6 }{8:?}{9:B }│{1: }{10: 2 }{8:!}{9:B }|
+ {1: }{10: 7 }{8:?}{9:C }│{1: }{10: 3 }{8:!}{9:C }|
+ {1: }{10: 8 }{4:?C }│{1: }{10: }{2:--------------------------------------------}|
+ {1: }{10: 9 } │{1: }{10: 4 } |
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {6:~ }│{6:~ }|
+ {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }|
+ :e |
+ ]])
+ end)
+ end)
describe('setup a diff with 2 files and set linematch:10', function()
before_each(function()
feed(':set diffopt+=linematch:10<cr>')
@@ -992,4 +1178,48 @@ describe('regressions', function()
helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010)..'world' })
helpers.exec 'windo diffthis'
end)
+
+ it("properly computes filler lines for hunks bigger than linematch limit", function()
+ clear()
+ feed(':set diffopt+=linematch:10<cr>')
+ screen = Screen.new(100, 20)
+ screen:attach()
+ local lines = {}
+ for i = 0, 29 do
+ lines[#lines + 1] = tostring(i)
+ end
+ helpers.curbufmeths.set_lines(0, -1, false, lines)
+ helpers.exec 'vnew'
+ helpers.curbufmeths.set_lines(0, -1, false, { '00', '29' })
+ helpers.exec 'windo diffthis'
+ feed('<C-e>')
+ screen:expect{grid=[[
+ {1: }{2:------------------------------------------------}│{1: }{3:^1 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:2 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:3 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:4 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:5 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:6 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:7 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:8 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:9 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:10 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:11 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:12 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:13 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:14 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:15 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:16 }|
+ {1: }{2:------------------------------------------------}│{1: }{3:17 }|
+ {1: }29 │{1: }{3:18 }|
+ {4:[No Name] [+] }{5:[No Name] [+] }|
+ |
+ ]], attr_ids={
+ [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Grey};
+ [2] = {bold = true, background = Screen.colors.LightCyan, foreground = Screen.colors.Blue1};
+ [3] = {background = Screen.colors.LightBlue};
+ [4] = {reverse = true};
+ [5] = {reverse = true, bold = true};
+ }}
+ end)
end)
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index 3052a74f38..1d11a12af4 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -10,15 +10,19 @@ local async_meths = helpers.async_meths
local test_build_dir = helpers.test_build_dir
local nvim_prog = helpers.nvim_prog
local exec = helpers.exec
+local exec_capture = helpers.exec_capture
local exc_exec = helpers.exc_exec
local exec_lua = helpers.exec_lua
local poke_eventloop = helpers.poke_eventloop
local assert_alive = helpers.assert_alive
local is_os = helpers.is_os
local is_ci = helpers.is_ci
+local funcs = helpers.funcs
+local skip = helpers.skip
describe('ui/ext_messages', function()
local screen
+ local fname = 'Xtest_functional_ui_messages_spec'
before_each(function()
clear()
@@ -38,7 +42,7 @@ describe('ui/ext_messages', function()
})
end)
after_each(function()
- os.remove('Xtest')
+ os.remove(fname)
end)
it('msg_clear follows msg_show kind of confirm', function()
@@ -123,7 +127,7 @@ describe('ui/ext_messages', function()
feed('nq')
-- kind=wmsg (editing readonly file)
- command('write Xtest')
+ command('write ' .. fname)
command('set readonly nohls')
feed('G$x')
screen:expect{grid=[[
@@ -329,6 +333,36 @@ describe('ui/ext_messages', function()
]]}
end)
+ it(':echoerr multiline', function()
+ exec_lua([[vim.g.multi = table.concat({ "bork", "fail" }, "\n")]])
+ feed(':echoerr g:multi<cr>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]], messages={{
+ content = {{ "bork\nfail", 2 }},
+ kind = "echoerr"
+ }}}
+
+ feed(':messages<cr>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]], messages={{
+ content = {{ "Press ENTER or type command to continue", 4 }},
+ kind = "return_prompt"
+ }}, msg_history={{
+ content = {{ "bork\nfail", 2 }},
+ kind = "echoerr"
+ }}}
+ end)
+
it('shortmess-=S', function()
command('set shortmess-=S')
feed('iline 1\nline 2<esc>')
@@ -474,8 +508,7 @@ describe('ui/ext_messages', function()
]], msg_history={{
content = {{ "stuff" }},
kind = "echomsg",
- }}, showmode={{ "-- INSERT --", 3 }},
- messages={{
+ }}, messages={{
content = {{ "Press ENTER or type command to continue", 4}},
kind = "return_prompt"
}}}
@@ -801,6 +834,19 @@ stack traceback:
end}
end)
+ it('supports multiline messages for :map', function()
+ command('mapclear')
+ command('nmap Y y$')
+ command('nmap Q @@')
+ command('nnoremap j k')
+ feed(':map<cr>')
+
+ screen:expect{messages={{
+ content = {{ "\nn Q @@\nn Y y$\nn j " }, { "*", 5 }, { " k" }},
+ kind = ''
+ }}}
+ end)
+
it('wildmode=list', function()
screen:try_resize(25, 7)
screen:set_option('ext_popupmenu', false)
@@ -910,9 +956,9 @@ stack traceback:
end)
it('does not truncate messages', function()
- command('write Xtest')
+ command('write '.. fname)
screen:expect({messages={
- {content = { { '"Xtest" [New] 0L, 0B written' } }, kind = "" }
+ {content = { { string.format('"%s" [New] 0L, 0B written', fname) } }, kind = "" }
}})
end)
end)
@@ -985,7 +1031,7 @@ describe('ui/builtin messages', function()
-- screen size doesn't affect internal output #10285
eq('ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red',
- meths.exec("hi ErrorMsg", true))
+ exec_capture("hi ErrorMsg"))
end)
it(':syntax list langGroup output', function()
@@ -1024,10 +1070,57 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
match /\<endif\s\+".*$/ms=s+5,lc=5 contains=@vimCommentGroup,vimCommentString
match /\<else\s\+".*$/ms=s+4,lc=4 contains=@vimCommentGroup,vimCommentString
links to Comment]],
- meths.exec('syntax list vimComment', true))
+ exec_capture('syntax list vimComment'))
-- luacheck: pop
end)
+ it('no empty line after :silent #12099', function()
+ exec([[
+ func T1()
+ silent !echo
+ echo "message T1"
+ endfunc
+ func T2()
+ silent lua print("lua message")
+ echo "message T2"
+ endfunc
+ func T3()
+ silent call nvim_out_write("api message\n")
+ echo "message T3"
+ endfunc
+ ]])
+ feed(':call T1()<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ message T1 |
+ ]]}
+ feed(':call T2()<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ message T2 |
+ ]]}
+ feed(':call T3()<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ message T3 |
+ ]]}
+ end)
+
it('supports ruler with laststatus=0', function()
command("set ruler laststatus=0")
screen:expect{grid=[[
@@ -1232,17 +1325,54 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
]])
end)
- it('echo messages are shown correctly when getchar() immediately follows', function()
- feed([[:echo 'foo' | echo 'bar' | call getchar()<CR>]])
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {3: }|
- foo |
- bar^ |
- ]])
+ describe('echo messages are shown when immediately followed by', function()
+ --- @param to_block string command to cause a blocking wait
+ --- @param to_unblock number|string number: timeout for blocking screen
+ --- string: keys to stop the blocking wait
+ local function test_flush_before_block(to_block, to_unblock)
+ local timeout = type(to_unblock) == 'number' and to_unblock or nil
+ exec(([[
+ func PrintAndWait()
+ echon "aaa\nbbb"
+ %s
+ echon "\nccc"
+ endfunc
+ ]]):format(to_block))
+ feed(':call PrintAndWait()<CR>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3: }|
+ aaa |
+ bbb^ |
+ ]], timeout=timeout}
+ if type(to_unblock) == 'string' then
+ feed(to_unblock)
+ end
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {3: }|
+ aaa |
+ bbb |
+ ccc |
+ {4:Press ENTER or type command to continue}^ |
+ ]]}
+ end
+
+ it('getchar()', function()
+ test_flush_before_block([[call getchar()]], 'k')
+ end)
+
+ it('wait()', function()
+ test_flush_before_block([[call wait(300, '0')]], 100)
+ end)
+
+ it('lua vim.wait()', function()
+ test_flush_before_block([[lua vim.wait(300, function() end)]], 100)
+ end)
end)
it('consecutive calls to win_move_statusline() work after multiline message #21014',function()
@@ -1270,7 +1400,20 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
{1:~ }|
|
]])
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
+ end)
+
+ it('using nvim_echo in VimResized does not cause hit-enter prompt #26139', function()
+ command([[au VimResized * lua vim.api.nvim_echo({ { '123456' } }, true, {})]])
+ screen:try_resize(60, 5)
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ eq({ mode = 'n', blocking = false }, meths.get_mode())
end)
end)
@@ -1322,7 +1465,7 @@ describe('ui/ext_messages', function()
{1:~ }type :q{5:<Enter>} to exit {1: }|
{1:~ }type :help{5:<Enter>} for help {1: }|
{1:~ }|
- {1:~ }type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}|
+ {1:~{MATCH: +}}type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}{1:{MATCH: +}}|
{1:~ }|
{MATCH:.*}|
{MATCH:.*}|
@@ -1363,7 +1506,7 @@ describe('ui/ext_messages', function()
feed(":intro<cr>")
screen:expect{grid=[[
- |
+ ^ |
|
|
|
@@ -1378,7 +1521,7 @@ describe('ui/ext_messages', function()
type :q{5:<Enter>} to exit |
type :help{5:<Enter>} for help |
|
- type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}|
+ {MATCH: +}type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+ +}|
|
{MATCH:.*}|
{MATCH:.*}|
@@ -1917,6 +2060,7 @@ aliquip ex ea commodo consequat.]])
end)
it('with :!cmd does not crash on resize', function()
+ skip(funcs.executable('sleep') == 0, 'missing "sleep" command')
feed(':!sleep 1<cr>')
screen:expect{grid=[[
|
diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua
index cf4eb034e0..e870d6f25f 100644
--- a/test/functional/ui/mode_spec.lua
+++ b/test/functional/ui/mode_spec.lua
@@ -44,7 +44,10 @@ describe('ui mode_change event', function()
{0:~ }|
|
]], mode="normal"}
+ end)
+ -- oldtest: Test_mouse_shape_after_failed_change()
+ it('is restored to Normal mode after failed "c"', function()
screen:try_resize(50, 4)
command('set nomodifiable')
@@ -65,6 +68,25 @@ describe('ui mode_change event', function()
]], mode="normal"}
end)
+ -- oldtest: Test_mouse_shape_after_cancelling_gr()
+ it('is restored to Normal mode after cancelling "gr"', function()
+ feed('gr')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]], mode="replace"}
+
+ feed('<Esc>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]], mode="normal"}
+ end)
+
it('works in insert mode', function()
feed('i')
screen:expect{grid=[[
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
index f705678bd5..1356ba3db8 100644
--- a/test/functional/ui/mouse_spec.lua
+++ b/test/functional/ui/mouse_spec.lua
@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths
local insert, feed_command = helpers.insert, helpers.feed_command
local eq, funcs = helpers.eq, helpers.funcs
+local poke_eventloop = helpers.poke_eventloop
local command = helpers.command
local exec = helpers.exec
@@ -11,8 +12,8 @@ describe('ui/mouse/input', function()
before_each(function()
clear()
- meths.set_option('mouse', 'a')
- meths.set_option('list', true)
+ meths.set_option_value('mouse', 'a', {})
+ meths.set_option_value('list', true, {})
-- NB: this is weird, but mostly irrelevant to the test
-- So I didn't bother to change it
command('set listchars=eol:$')
@@ -32,6 +33,7 @@ describe('ui/mouse/input', function()
[5] = {bold = true, reverse = true},
[6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[7] = {bold = true, foreground = Screen.colors.SeaGreen4},
+ [8] = {foreground = Screen.colors.Brown},
})
command("set mousemodel=extend")
feed('itesting<cr>mouse<cr>support and selection<esc>')
@@ -64,7 +66,7 @@ describe('ui/mouse/input', function()
end)
it("in external ui works with unset 'mouse'", function()
- meths.set_option('mouse', '')
+ meths.set_option_value('mouse', '', {})
feed('<LeftMouse><2,1>')
screen:expect{grid=[[
testing |
@@ -379,7 +381,7 @@ describe('ui/mouse/input', function()
end)
it('left click in default tabline (position 24) closes tab', function()
- meths.set_option('hidden', true)
+ meths.set_option_value('hidden', true, {})
feed_command('%delete')
insert('this is foo')
feed_command('silent file foo | tabnew | file bar')
@@ -402,7 +404,7 @@ describe('ui/mouse/input', function()
end)
it('double click in default tabline (position 4) opens new tab', function()
- meths.set_option('hidden', true)
+ meths.set_option_value('hidden', true, {})
feed_command('%delete')
insert('this is foo')
feed_command('silent file foo | tabnew | file bar')
@@ -437,8 +439,8 @@ describe('ui/mouse/input', function()
return call('Test', a:000 + [2])
endfunction
]])
- meths.set_option('tabline', '%@Test@test%X-%5@Test2@test2')
- meths.set_option('showtabline', 2)
+ meths.set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {})
+ meths.set_option_value('showtabline', 2, {})
screen:expect([[
{fill:test-test2 }|
testing |
@@ -786,11 +788,11 @@ describe('ui/mouse/input', function()
end)
it('ctrl + left click will search for a tag', function()
- meths.set_option('tags', './non-existent-tags-file')
+ meths.set_option_value('tags', './non-existent-tags-file', {})
feed('<C-LeftMouse><0,0>')
screen:expect([[
{6:E433: No tags file} |
- {6:E426: tag not found: test}|
+ {6:E426: Tag not found: test}|
{6:ing} |
{7:Press ENTER or type comma}|
{7:nd to continue}^ |
@@ -798,6 +800,66 @@ describe('ui/mouse/input', function()
feed('<cr>')
end)
+ it('dragging vertical separator', function()
+ screen:try_resize(45, 5)
+ command('setlocal nowrap')
+ local oldwin = meths.get_current_win().id
+ command('rightbelow vnew')
+ screen:expect([[
+ testing │{0:^$} |
+ mouse │{0:~ }|
+ support and selection │{0:~ }|
+ {4:[No Name] [+] }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 0, 22)
+ poke_eventloop()
+ meths.input_mouse('left', 'drag', '', 0, 1, 12)
+ screen:expect([[
+ testing │{0:^$} |
+ mouse │{0:~ }|
+ support and │{0:~ }|
+ {4:< Name] [+] }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'drag', '', 0, 2, 2)
+ screen:expect([[
+ te│{0:^$} |
+ mo│{0:~ }|
+ su│{0:~ }|
+ {4:< }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'release', '', 0, 2, 2)
+ meths.set_option_value('statuscolumn', 'foobar', { win = oldwin })
+ screen:expect([[
+ {8:fo}│{0:^$} |
+ {8:fo}│{0:~ }|
+ {8:fo}│{0:~ }|
+ {4:< }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 0, 2)
+ poke_eventloop()
+ meths.input_mouse('left', 'drag', '', 0, 1, 12)
+ screen:expect([[
+ {8:foobar}testin│{0:^$} |
+ {8:foobar}mouse │{0:~ }|
+ {8:foobar}suppor│{0:~ }|
+ {4:< Name] [+] }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'drag', '', 0, 2, 22)
+ screen:expect([[
+ {8:foobar}testing │{0:^$} |
+ {8:foobar}mouse │{0:~ }|
+ {8:foobar}support and sele│{0:~ }|
+ {4:[No Name] [+] }{5:[No Name] }|
+ |
+ ]])
+ meths.input_mouse('left', 'release', '', 0, 2, 22)
+ end)
+
local function wheel(use_api)
feed('ggdG')
insert([[
@@ -1011,37 +1073,7 @@ describe('ui/mouse/input', function()
]])
end)
- describe('on concealed text', function()
- -- Helpful for reading the test expectations:
- -- :match Error /\^/
-
- before_each(function()
- screen:try_resize(25, 7)
- screen:set_default_attr_ids({
- [0] = {bold=true, foreground=Screen.colors.Blue},
- c = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray },
- sm = {bold = true},
- })
- feed('ggdG')
-
- feed_command('set concealcursor=ni')
- feed_command('set nowrap')
- feed_command('set shiftwidth=2 tabstop=4 list')
- feed_command('setl listchars=tab:>-')
- feed_command('syntax match NonText "\\*" conceal')
- feed_command('syntax match NonText "cats" conceal cchar=X')
- feed_command('syntax match NonText "x" conceal cchar=>')
-
- -- First column is there to retain the tabs.
- insert([[
- |Section *t1*
- | *t2* *t3* *t4*
- |x 私は猫が大好き *cats* ✨🐈✨
- ]])
-
- feed('gg<c-v>Gxgg')
- end)
-
+ local function test_mouse_click_conceal()
it('(level 1) click on non-wrapped lines', function()
feed_command('let &conceallevel=1', 'echo')
@@ -1433,7 +1465,6 @@ describe('ui/mouse/input', function()
]])
end) -- level 2 - wrapped
-
it('(level 3) click on non-wrapped lines', function()
feed_command('let &conceallevel=3', 'echo')
@@ -1471,6 +1502,7 @@ describe('ui/mouse/input', function()
]])
feed('<esc><LeftMouse><20,2>')
+ feed('zH') -- FIXME: unnecessary horizontal scrolling
screen:expect([[
Section{0:>>--->--->---}t1 |
{0:>--->--->---} t2 t3 t4 |
@@ -1574,12 +1606,80 @@ describe('ui/mouse/input', function()
]])
end) -- level 3 - wrapped
+ end
+
+ describe('on concealed text', function()
+ -- Helpful for reading the test expectations:
+ -- :match Error /\^/
+
+ before_each(function()
+ screen:try_resize(25, 7)
+ screen:set_default_attr_ids({
+ [0] = { bold = true, foreground = Screen.colors.Blue },
+ c = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray },
+ sm = { bold = true },
+ })
+ feed('ggdG')
+
+ command([[setlocal concealcursor=ni nowrap shiftwidth=2 tabstop=4 list listchars=tab:>-]])
+ command([[highlight link X0 Normal]])
+ command([[highlight link X1 NonText]])
+ command([[highlight link X2 NonText]])
+ command([[highlight link X3 NonText]])
+
+ -- First column is there to retain the tabs.
+ insert([[
+ |Section *t1*
+ | *t2* *t3* *t4*
+ |x 私は猫が大好き *cats* ✨🐈✨
+ ]])
+
+ feed('gg<c-v>Gxgg')
+ end)
+
+ describe('(syntax)', function()
+ before_each(function()
+ command([[syntax region X0 matchgroup=X1 start=/\*/ end=/\*/ concealends contains=X2]])
+ command([[syntax match X2 /cats/ conceal cchar=X contained]])
+ command([[syntax match X3 /\n\@<=x/ conceal cchar=>]])
+ end)
+ test_mouse_click_conceal()
+ end)
+
+ describe('(matchadd())', function()
+ before_each(function()
+ funcs.matchadd('Conceal', [[\*]])
+ funcs.matchadd('Conceal', [[cats]], 10, -1, { conceal = 'X' })
+ funcs.matchadd('Conceal', [[\n\@<=x]], 10, -1, { conceal = '>' })
+ end)
+ test_mouse_click_conceal()
+ end)
+
+ describe('(extmarks)', function()
+ before_each(function()
+ local ns = meths.create_namespace('conceal')
+ meths.buf_set_extmark(0, ns, 0, 11, { end_col = 12, conceal = '' })
+ meths.buf_set_extmark(0, ns, 0, 14, { end_col = 15, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 5, { end_col = 6, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 8, { end_col = 9, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 10, { end_col = 11, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 13, { end_col = 14, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 15, { end_col = 16, conceal = '' })
+ meths.buf_set_extmark(0, ns, 1, 18, { end_col = 19, conceal = '' })
+ meths.buf_set_extmark(0, ns, 2, 24, { end_col = 25, conceal = '' })
+ meths.buf_set_extmark(0, ns, 2, 29, { end_col = 30, conceal = '' })
+ meths.buf_set_extmark(0, ns, 2, 25, { end_col = 29, conceal = 'X' })
+ meths.buf_set_extmark(0, ns, 2, 0, { end_col = 1, conceal = '>' })
+ end)
+ test_mouse_click_conceal()
+ end)
+
end)
- it('getmousepos works correctly', function()
- local winwidth = meths.get_option('winwidth')
+ it('getmousepos() works correctly', function()
+ local winwidth = meths.get_option_value('winwidth', {})
-- Set winwidth=1 so that window sizes don't change.
- meths.set_option('winwidth', 1)
+ meths.set_option_value('winwidth', 1, {})
command('tabedit')
local tabpage = meths.get_current_tabpage()
insert('hello')
@@ -1597,8 +1697,8 @@ describe('ui/mouse/input', function()
}
local float = meths.open_win(meths.get_current_buf(), false, opts)
command('redraw')
- local lines = meths.get_option('lines')
- local columns = meths.get_option('columns')
+ local lines = meths.get_option_value('lines', {})
+ local columns = meths.get_option_value('columns', {})
-- Test that screenrow and screencol are set properly for all positions.
for row = 0, lines - 1 do
@@ -1617,6 +1717,7 @@ describe('ui/mouse/input', function()
eq(0, mousepos.wincol)
eq(0, mousepos.line)
eq(0, mousepos.column)
+ eq(0, mousepos.coladd)
end
end
end
@@ -1636,15 +1737,18 @@ describe('ui/mouse/input', function()
eq(win_col + 1, mousepos.wincol)
local line = 0
local column = 0
+ local coladd = 0
if win_row > 0 and win_row < opts.height + 1
and win_col > 0 and win_col < opts.width + 1 then
-- Because of border, win_row and win_col don't need to be
-- incremented by 1.
line = math.min(win_row, funcs.line('$'))
column = math.min(win_col, #funcs.getline(line) + 1)
+ coladd = win_col - column
end
eq(line, mousepos.line)
eq(column, mousepos.column)
+ eq(coladd, mousepos.coladd)
end
end
@@ -1664,14 +1768,16 @@ describe('ui/mouse/input', function()
eq(win_col + 1, mousepos.wincol)
local line = math.min(win_row + 1, funcs.line('$'))
local column = math.min(win_col + 1, #funcs.getline(line) + 1)
+ local coladd = win_col + 1 - column
eq(line, mousepos.line)
eq(column, mousepos.column)
+ eq(coladd, mousepos.coladd)
end
end
-- Test that mouse position values are properly set for ordinary windows.
-- Set the float to be unfocusable instead of closing, to additionally test
- -- that getmousepos does not consider unfocusable floats. (see discussion
+ -- that getmousepos() does not consider unfocusable floats. (see discussion
-- in PR #14937 for details).
opts.focusable = false
meths.win_set_config(float, opts)
@@ -1688,15 +1794,17 @@ describe('ui/mouse/input', function()
eq(win_col + 1, mousepos.wincol)
local line = math.min(win_row + 1, funcs.line('$'))
local column = math.min(win_col + 1, #funcs.getline(line) + 1)
+ local coladd = win_col + 1 - column
eq(line, mousepos.line)
eq(column, mousepos.column)
+ eq(coladd, mousepos.coladd)
end
end
end
-- Restore state and release mouse.
command('tabclose!')
- meths.set_option('winwidth', winwidth)
+ meths.set_option_value('winwidth', winwidth, {})
meths.input_mouse('left', 'release', '', 0, 0, 0)
end)
@@ -1840,16 +1948,6 @@ describe('ui/mouse/input', function()
eq({2, 9}, meths.win_get_cursor(0))
eq('', funcs.getreg('"'))
- -- Try clicking on the status line
- funcs.setreg('"', '')
- meths.win_set_cursor(0, {1, 9})
- feed('vee')
- meths.input_mouse('right', 'press', '', 0, 5, 1)
- meths.input_mouse('right', 'release', '', 0, 5, 1)
- feed('<Down><CR>')
- eq({1, 9}, meths.win_get_cursor(0))
- eq('ran away', funcs.getreg('"'))
-
-- Try clicking outside the window
funcs.setreg('"', '')
meths.win_set_cursor(0, {2, 1})
@@ -1859,5 +1957,28 @@ describe('ui/mouse/input', function()
feed('<Down><CR>')
eq(2, funcs.winnr())
eq('', funcs.getreg('"'))
+
+ -- Test for right click in visual mode inside the selection with vertical splits
+ command('wincmd t')
+ command('rightbelow vsplit')
+ funcs.setreg('"', '')
+ meths.win_set_cursor(0, {1, 9})
+ feed('vee')
+ meths.input_mouse('right', 'press', '', 0, 0, 52)
+ meths.input_mouse('right', 'release', '', 0, 0, 52)
+ feed('<Down><CR>')
+ eq({1, 9}, meths.win_get_cursor(0))
+ eq('ran away', funcs.getreg('"'))
+
+ -- Test for right click inside visual selection at bottom of window with winbar
+ command('setlocal winbar=WINBAR')
+ feed('2yyP')
+ funcs.setreg('"', '')
+ feed('G$vbb')
+ meths.input_mouse('right', 'press', '', 0, 4, 61)
+ meths.input_mouse('right', 'release', '', 0, 4, 61)
+ feed('<Down><CR>')
+ eq({4, 20}, meths.win_get_cursor(0))
+ eq('the moon', funcs.getreg('"'))
end)
end)
diff --git a/test/functional/ui/multibyte_spec.lua b/test/functional/ui/multibyte_spec.lua
index d4e237bcb4..d72bf27d6b 100644
--- a/test/functional/ui/multibyte_spec.lua
+++ b/test/functional/ui/multibyte_spec.lua
@@ -17,10 +17,11 @@ describe("multibyte rendering", function()
screen = Screen.new(60, 6)
screen:attach({rgb=true})
screen:set_default_attr_ids({
- [1] = {bold = true, foreground = Screen.colors.Blue1},
+ [1] = {bold = true, foreground = Screen.colors.Blue},
[2] = {background = Screen.colors.WebGray},
[3] = {background = Screen.colors.LightMagenta},
[4] = {bold = true},
+ [5] = {foreground = Screen.colors.Blue},
})
end)
@@ -119,6 +120,19 @@ describe("multibyte rendering", function()
]])
end)
+ it('0xffff is shown as 4 hex digits', function()
+ command([[call setline(1, "\uFFFF!!!")]])
+ feed('$')
+ screen:expect{grid=[[
+ {5:<ffff>}!!^! |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
it('works with a lot of unicode (zalgo) text', function()
screen:try_resize(65, 10)
meths.buf_set_lines(0,0,-1,true, split(dedent [[
@@ -146,6 +160,103 @@ describe("multibyte rendering", function()
{1:~ }|
|
]]}
+
+ -- nvim will reset the zalgo text^W^W glyph cache if it gets too full.
+ -- this should be exceedingly rare, but fake it to make sure it works
+ meths._invalidate_glyph_cache()
+ screen:expect{grid=[[
+ ^L̓̉̑̒̌̚ơ̗̌̒̄̀ŕ̈̈̎̐̕è̇̅̄̄̐m̖̟̟̅̄̚ ̛̓̑̆̇̍i̗̟̞̜̅̐p̗̞̜̉̆̕s̟̜̘̍̑̏ū̟̞̎̃̉ḿ̘̙́́̐ ̖̍̌̇̉̚d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚ȯ̖̞̋̀̐r̓̇̌̃̃̚ ̗̘̀̏̍́s̜̀̎̎̑̕i̟̗̐̄̄̚t̝̎̆̓̐̒ ̘̇̔̓̊̚ȃ̛̟̗̏̅m̜̟̙̞̈̓é̘̞̟̔̆t̝̂̂̈̑̔,̜̜̖̅̄̍ ̛̗̊̓̆̚c̟̍̆̍̈̔ȯ̖̖̝̑̀n̜̟̎̊̃̚s̟̏̇̎̒̚e̙̐̈̓̌̚c̙̍̈̏̅̕ť̇̄̇̆̓e̛̓̌̈̓̈t̟̍̀̉̆̅u̝̞̎̂̄̚r̘̀̅̈̅̐ ̝̞̓́̇̉ã̏̀̆̅̕d̛̆̐̉̆̋ȉ̞̟̍̃̚p̛̜̊̍̂̓ȋ̏̅̃̋̚ṥ̛̏̃̕č̛̞̝̀̂í̗̘̌́̎n̔̎́̒̂̕ǧ̗̜̋̇̂ ̛̜̔̄̎̃ê̛̔̆̇̕l̘̝̏̐̊̏ĩ̛̍̏̏̄t̟̐́̀̐̎,̙̘̍̆̉̐ ̋̂̏̄̌̅s̙̓̌̈́̇e̛̗̋̒̎̏d̜̗̊̍̊̚ |
+ ď̘̋̌̌̕ǒ̝̗̔̇̕ ̙̍́̄̄̉è̛̛̞̌̌i̜̖̐̈̆̚ȕ̇̈̓̃̓ŝ̛̞̙̉̋m̜̐̂̄̋̂ȯ̈̎̎̅̕d̜̙̓̔̋̑ ̞̗̄̂̂̚t̝̊́̃́̄e̛̘̜̞̓̑m̊̅̏̉̌̕p̛̈̂̇̀̐ỏ̙̘̈̉̔r̘̞̋̍̃̚ ̝̄̀̇̅̇ỉ̛̖̍̓̈n̛̛̝̎̕̕c̛̛̊̅́̐ĭ̗̓̀̍̐d̞̜̋̐̅̚i̟̙̇̄̊̄d̞̊̂̀̇̚ủ̝̉̑̃̕n̜̏̇̄̐̋ť̗̜̞̋̉ ̝̒̓̌̓̚ȕ̖̙̀̚̕t̖̘̎̉̂̌ ̛̝̄̍̌̂l̛̟̝̃̑̋á̛̝̝̔̅b̝̙̜̗̅̒ơ̖̌̒̄̆r̒̇̓̎̈̄e̛̛̖̅̏̇ ̖̗̜̝̃́e̛̛̘̅̔̌ẗ̛̙̗̐̕ ̖̟̇̋̌̈d̞̙̀̉̑̕ŏ̝̂́̐̑l̞̟̗̓̓̀ơ̘̎̃̄̂r̗̗̖̔̆̍ẻ̖̝̞̋̅ ̜̌̇̍̈̊m̈̉̇̄̒̀a̜̞̘̔̅̆g̗̖̈̃̈̉n̙̖̄̈̉̄â̛̝̜̄̃ ̛́̎̕̕̚ā̊́́̆̌l̟̙̞̃̒́i̖̇̎̃̀̋q̟̇̒̆́̊ủ́̌̇̑̚ã̛̘̉̐̚.̛́̏̐̍̊ |
+ U̝̙̎̈̐̆t̜̍̌̀̔̏ ̞̉̍̇̈̃e̟̟̊̄̕̕n̝̜̒̓̆̕i̖̒̌̅̇̚m̞̊̃̔̊̂ ̛̜̊̎̄̂a̘̜̋̒̚̚d̟̊̎̇̂̍ ̜̖̏̑̉̕m̜̒̎̅̄̚i̝̖̓̂̍̕n̙̉̒̑̀̔ỉ̖̝̌̒́m̛̖̘̅̆̎ ̖̉̎̒̌̕v̖̞̀̔́̎e̖̙̗̒̎̉n̛̗̝̎̀̂ȉ̞̗̒̕̚ȧ̟̜̝̅̚m̆̉̐̐̇̈,̏̐̎́̍́ ̜̞̙̘̏̆q̙̖̙̅̓̂ủ̇́̀̔̚í̙̟̟̏̐s̖̝̍̏̂̇ ̛̘̋̈̕̕ń̛̞̜̜̎o̗̜̔̔̈̆s̞̘̘̄̒̋t̛̅̋́̔̈ȓ̓̒́̇̅ủ̜̄̃̒̍d̙̝̘̊̏̚ ̛̟̞̄́̔e̛̗̝̍̃̀x̞̖̃̄̂̅e̖̅̇̐̔̃r̗̞̖̔̎̚c̘̜̖̆̊̏ï̙̝̙̂̕t̖̏́̓̋̂ă̖̄̆̑̒t̜̟̍̉̑̏i̛̞̞̘̒̑ǒ̜̆̅̃̉ṅ̖̜̒̎̚ |
+ u̗̞̓̔̈̏ĺ̟̝́̎̚l̛̜̅̌̎̆a̒̑̆̔̇̃m̜̗̈̊̎̚ċ̘̋̇̂̚ơ̟̖̊́̕ ̖̟̍̉̏̚l̙̔̓̀̅̏ä̞̗̘̙̅ḃ̟̎̄̃̕o̞̎̓̓̓̚r̗̜̊̓̈̒ï̗̜̃̃̅s̀̒̌̂̎̂ ̖̗̗̋̎̐n̝̟̝̘̄̚i̜̒̀̒̐̕s̘̘̄̊̃̀ī̘̜̏̌̕ ̗̖̞̐̈̒ư̙̞̄́̌t̟̘̖̙̊̚ ̌̅̋̆̚̚ä̇̊̇̕̕l̝̞̘̋̔̅i̍̋́̆̑̈q̛̆̐̈̐̚ư̏̆̊́̚î̜̝̑́̊p̗̓̅̑̆̏ ̆́̓̔̋̋e̟̊̋̏̓̚x̗̍̑̊̎̈ ̟̞̆̄̂̍ë̄̎̄̃̅a̛̜̅́̃̈ ̔̋̀̎̐̀c̖̖̍̀̒̂ơ̛̙̖̄̒m̘̔̍̏̆̕ḿ̖̙̝̏̂ȍ̓̋̈̀̕d̆̂̊̅̓̚o̖̔̌̑̚̕ ̙̆́̔̊̒c̖̘̖̀̄̍o̓̄̑̐̓̒ñ̞̒̎̈̚s̞̜̘̈̄̄e̙̊̀̇̌̋q̐̒̓́̔̃ư̗̟̔̔̚å̖̙̞̄̏t̛̙̟̒̇̏.̙̗̓̃̓̎ |
+ D̜̖̆̏̌̌ư̑̃̌̍̕i̝̊̊̊̊̄s̛̙̒́̌̇ ̛̃̔̄̆̌ă̘̔̅̅̀ú̟̟̟̃̃t̟̂̄̈̈̃e̘̅̌̒̂̆ ̖̟̐̉̉̌î̟̟̙̜̇r̛̙̞̗̄̌ú̗̗̃̌̎r̛̙̘̉̊̕e̒̐̔̃̓̋ ̊̊̍̋̑̉d̛̝̙̉̀̓o̘̜̐̐̓̐l̞̋̌̆̍́o̊̊̐̃̃̚ṙ̛̖̘̃̕ ̞̊̀̍̒̕ȉ́̑̐̇̅ǹ̜̗̜̞̏ ̛̜̐̄̄̚r̜̖̈̇̅̋ĕ̗̉̃̔̚p̟̝̀̓̔̆r̜̈̆̇̃̃e̘̔̔̏̎̓h̗̒̉̑̆̚ė̛̘̘̈̐n̘̂̀̒̕̕d̗̅̂̋̅́ê̗̜̜̜̕r̟̋̄̐̅̂i̛̔̌̒̂̕t̛̗̓̎̀̎ ̙̗̀̉̂̚ȉ̟̗̐̓̚n̙̂̍̏̓̉ ̙̘̊̋̍̕v̜̖̀̎̆̐ő̜̆̉̃̎l̑̋̒̉̔̆ư̙̓̓́̚p̝̘̖̎̏̒t̛̘̝̞̂̓ȁ̘̆̔́̊t̖̝̉̒̐̎e̞̟̋̀̅̄ ̆̌̃̀̑̔v̝̘̝̍̀̇ȅ̝̊̄̓̕l̞̝̑̔̂̋ĭ̝̄̅̆̍t̝̜̉̂̈̇ |
+ ē̟̊̇̕̚s̖̘̘̒̄̑s̛̘̀̊̆̇e̛̝̘̒̏̚ ̉̅̑̂̐̎c̛̟̙̎̋̓i̜̇̒̏̆̆l̟̄́̆̊̌l̍̊̋̃̆̌ủ̗̙̒̔̚m̛̘̘̖̅̍ ̖̙̈̎̂̕d̞̟̏̋̈̔ơ̟̝̌̃̄l̗̙̝̂̉̒õ̒̃̄̄̚ŕ̗̏̏̊̍ê̞̝̞̋̈ ̜̔̒̎̃̚e̞̟̞̒̃̄ư̖̏̄̑̃ ̛̗̜̄̓̎f̛̖̞̅̓̃ü̞̏̆̋̕g̜̝̞̑̑̆i̛̘̐̐̅̚à̜̖̌̆̎t̙̙̎̉̂̍ ̋̔̈̎̎̉n̞̓́̔̊̕ư̘̅̋̔̚l̗̍̒̄̀̚l̞̗̘̙̓̍â̘̔̒̎̚ ̖̓̋̉̃̆p̛̛̘̋̌̀ä̙̔́̒̕r̟̟̖̋̐̋ì̗̙̎̓̓ȃ̔̋̑̚̕t̄́̎̓̂̋ư̏̈̂̑̃r̖̓̋̊̚̚.̒̆̑̆̊̎ ̘̜̍̐̂̚E̞̅̐̇́̂x̄́̈̌̉̕ć̘̃̉̃̕è̘̂̑̏̑p̝̘̑̂̌̆t̔̐̅̍̌̂ȇ̞̈̐̚̕ű̝̞̜́̚ŕ̗̝̉̆́ |
+ š̟́̔̏̀ȉ̝̟̝̏̅n̑̆̇̒̆̚t̝̒́̅̋̏ ̗̑̌̋̇̚ơ̙̗̟̆̅c̙̞̙̎̊̎c̘̟̍̔̊̊a̛̒̓̉́̐e̜̘̙̒̅̇ć̝̝̂̇̕ả̓̍̎̂̚t̗̗̗̟̒̃ ̘̒̓̐̇́c̟̞̉̐̓̄ȕ̙̗̅́̏p̛̍̋̈́̅i̖̓̒̍̈̄d̞̃̈̌̆̐a̛̗̝̎̋̉t̞̙̀̊̆̇a̛̙̒̆̉̚t̜̟̘̉̓̚ ̝̘̗̐̇̕n̛̘̑̏̂́ō̑̋̉̏́ň̞̊̆̄̃ ̙̙̙̜̄̏p̒̆̋̋̓̏r̖̖̅̉́̚ơ̜̆̑̈̚i̟̒̀̃̂̌d̛̏̃̍̋̚ë̖̞̙̗̓n̛̘̓̒̅̎t̟̗̙̊̆̚,̘̙̔̊̚̕ ̟̗̘̜̑̔s̜̝̍̀̓̌û̞̙̅̇́n̘̗̝̒̃̎t̗̅̀̅̊̈ ̗̖̅̅̀̄i̛̖̍̅̋̂n̙̝̓̓̎̚ ̞̋̅̋̃̚c̗̒̀̆̌̎ū̞̂̑̌̓ĺ̛̐̍̑́p̝̆̌̎̈̚a̖̙̒̅̈̌ ̝̝̜̂̈̀q̝̖̔̍̒̚ư̔̐̂̎̊ǐ̛̟̖̘̕ |
+ o̖̜̔̋̅̚f̛̊̀̉́̕f̏̉̀̔̃̃i̘̍̎̐̔̎c̙̅̑̂̐̅ȋ̛̜̀̒̚a̋̍̇̏̀̋ ̖̘̒̅̃̒d̗̘̓̈̇̋é̝́̎̒̄š̙̒̊̉̋e̖̓̐̀̍̕r̗̞̂̅̇̄ù̘̇̐̉̀n̐̑̀̄̍̐t̟̀̂̊̄̚ ̟̝̂̍̏́m̜̗̈̂̏̚ő̞̊̑̇̒l̘̑̏́̔̄l̛̛̇̃̋̊i̓̋̒̃̉̌t̛̗̜̏̀̋ ̙̟̒̂̌̐a̙̝̔̆̏̅n̝̙̙̗̆̅i̍̔́̊̃̕m̖̝̟̒̍̚ ̛̃̃̑̌́ǐ̘̉̔̅̚d̝̗̀̌̏̒ ̖̝̓̑̊̚ȇ̞̟̖̌̕š̙̙̈̔̀t̂̉̒̍̄̄ ̝̗̊̋̌̄l̛̞̜̙̘̔å̝̍̂̍̅b̜̆̇̈̉̌ǒ̜̙̎̃̆r̝̀̄̍́̕ư̋̊́̊̕m̜̗̒̐̕̚.̟̘̀̒̌̚ |
+ {1:~ }|
+ |
+ ]], reset=true}
+ end)
+
+ it('works with arabic input and arabicshape', function()
+ command('set arabic')
+
+ command('set noarabicshape')
+ feed('isghl!<esc>')
+ screen:expect{grid=[[
+ ^!مالس|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ |
+ ]]}
+
+ command('set arabicshape')
+ screen:expect{grid=[[
+ ^!ﻡﻼﺳ|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ |
+ ]]}
+ end)
+
+ it('works with arabic input and arabicshape and norightleft', function()
+ command('set arabic norightleft')
+
+ command('set noarabicshape')
+ feed('isghl!<esc>')
+ screen:expect{grid=[[
+ سلام^! |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ command('set arabicshape')
+ screen:expect{grid=[[
+ ﺱﻼﻣ^! |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ end)
+
+ it('works with arabicshape and multiple composing chars', function()
+ -- this tests an important edge case: arabicshape might increase the byte size of the base
+ -- character in a way so that the last composing char no longer fits. use "g8" on the text
+ -- to observe what is happening (the final E1 80 B7 gets deleted with 'arabicshape')
+ -- If we would increase the schar_t size, say from 32 to 64 bytes, we need to extend the
+ -- test text with even more zalgo energy to still touch this edge case.
+
+ meths.buf_set_lines(0,0,-1,true, {"سلام့̀́̂̃̄̅̆̇̈̉̊̋̌"})
+ command('set noarabicshape')
+
+ screen:expect{grid=[[
+ ^سلام့̀́̂̃̄̅̆̇̈̉̊̋̌ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ command('set arabicshape')
+ screen:expect{grid=[[
+ ^ﺱﻼﻣ̀́̂̃̄̅̆̇̈̉̊̋̌ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
end)
end)
@@ -158,6 +269,7 @@ describe('multibyte rendering: statusline', function()
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1},
[2] = {bold = true, reverse = true},
+ [3] = {background = Screen.colors.Red, foreground = Screen.colors.Gray100};
})
screen:attach()
command('set laststatus=2')
@@ -220,4 +332,27 @@ describe('multibyte rendering: statusline', function()
|
]]}
end)
+
+ it('unprintable chars in filename with default stl', function()
+ command("file 🧑‍💻")
+ -- TODO: this is wrong but avoids a crash
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {2:🧑�💻 }|
+ |
+ ]]}
+ end)
+
+ it('unprintable chars in filename with custom stl', function()
+ command('set statusline=xx%#ErrorMsg#%f%##yy')
+ command("file 🧑‍💻")
+ -- TODO: this is also wrong but also avoids a crash
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {2:xx}{3:🧑<200d>💻}{2:yy }|
+ |
+ ]]}
+ end)
end)
diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua
index 71adeb42a4..5b982df2b5 100644
--- a/test/functional/ui/multigrid_spec.lua
+++ b/test/functional/ui/multigrid_spec.lua
@@ -37,6 +37,10 @@ describe('ext_multigrid', function()
[18] = {bold = true, foreground = Screen.colors.Magenta},
[19] = {foreground = Screen.colors.Brown},
[20] = {background = Screen.colors.LightGrey},
+ [21] = {background = Screen.colors.LightMagenta},
+ [22] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue},
+ [23] = {background = Screen.colors.Grey90},
+ [24] = {background = Screen.colors.Grey},
})
end)
@@ -884,7 +888,6 @@ describe('ext_multigrid', function()
it('gets written till grid width', function()
insert(('a'):rep(60).."\n")
-
screen:expect{grid=[[
## grid 1
[2:-----------------------------------------------------]|
@@ -927,8 +930,95 @@ describe('ext_multigrid', function()
]]}
end)
+ it('"g$" works correctly with double-width characters and no wrapping', function()
+ command('set nowrap')
+ insert(('a'):rep(58) .. ('哦'):rep(3))
+ feed('0')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa哦|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]]}
+ feed('g$')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^哦|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ]]}
+ end)
+
it('wraps with grid width', function()
- insert(('b'):rep(80).."\n")
+ insert(('b'):rep(160).."\n")
screen:expect{grid=[[
## grid 1
[2:-----------------------------------------------------]|
@@ -947,7 +1037,8 @@ describe('ext_multigrid', function()
[3:-----------------------------------------------------]|
## grid 2
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
- bbbbbbbbbbbbbbbbbbbb |
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
^ |
{1:~ }|
{1:~ }|
@@ -965,6 +1056,47 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
{1:~ }|
+ ## grid 3
+ |
+ ]]}
+ feed('2gk')
+ command('setlocal cursorline cursorlineopt=screenline')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
+ {23:^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
{1:~ }|
## grid 3
|
@@ -1060,6 +1192,255 @@ describe('ext_multigrid', function()
|
]]}
end)
+
+ it('anchored float window "bufpos"', function()
+ insert(('c'):rep(1111))
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccc^c |
+ {1:~ }|
+ ## grid 3
+ |
+ ]]}
+ local float_buf = meths.create_buf(false, false)
+ meths.open_win(float_buf, false, {
+ relative = 'win',
+ win = curwin(),
+ bufpos = {0, 1018},
+ anchor = 'SE',
+ width = 5,
+ height = 5,
+ })
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|
+ cccccccccccccccccccccccccccccc^c |
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {21: }|
+ {22:~ }|
+ {22:~ }|
+ {22:~ }|
+ {22:~ }|
+ ]], float_pos={
+ [4] = {{id = 1001}, "SE", 2, 16, 58, true, 50};
+ }}
+ end)
+
+ it('completion popup position', function()
+ insert(('\n'):rep(14) .. ('foo bar '):rep(7))
+ feed('A<C-X><C-N>')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- Keyword Local completion (^N^P) }{15:match 1 of 2} |
+ ## grid 4
+ {24: foo}|
+ {21: bar}|
+ ]], float_pos={
+ [4] = {{id = -1}, "NW", 2, 15, 55, false, 100};
+ }}
+ feed('<C-E><Esc>')
+
+ command('setlocal rightleft')
+ feed('o<C-X><C-N>')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ rab oof rab oof rab oof rab oof rab oof rab oof rab oof|
+ ^ oof|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ {7:-- Keyword Local completion (^N^P) }{15:match 1 of 2} |
+ ## grid 4
+ {24: oof}|
+ {21: rab}|
+ ]], float_pos={
+ [4] = {{id = -1}, "NW", 2, 16, 45, false, 100};
+ }}
+ feed('<C-E><Esc>')
+
+ command('set wildoptions+=pum')
+ feed(':sign un<Tab>')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ rab oof rab oof rab oof rab oof rab oof rab oof rab oof|
+ |
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ :sign undefine^ |
+ ## grid 4
+ {24: undefine }|
+ {21: unplace }|
+ ]], float_pos={
+ [4] = {{id = -1}, "SW", 1, 13, 5, false, 250};
+ }}
+ end)
end)
it('multiline messages scroll over windows', function()
@@ -1926,6 +2307,7 @@ describe('ext_multigrid', function()
{1:~ }|
]]}
+ -- XXX: mouse_check_grid() doesn't work properly when clicking on grid 1
meths.input_mouse('left', 'press', '', 1, 6, 20)
-- TODO(bfredl): "batching" input_mouse is formally not supported yet.
-- Normally it should work fine in async context when nvim is not blocked,
@@ -2003,7 +2385,7 @@ describe('ext_multigrid', function()
{1:~ }|
]]}
- meths.input_mouse('left', 'press', '', 1,8, 26)
+ meths.input_mouse('left', 'press', '', 1, 8, 26)
poke_eventloop()
meths.input_mouse('left', 'drag', '', 1, 6, 30)
screen:expect{grid=[[
@@ -2044,6 +2426,625 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]]}
+
+ command('aunmenu PopUp | vmenu PopUp.Copy y')
+
+ funcs.setreg('"', '')
+ meths.input_mouse('left', 'press', '2', 2, 1, 6)
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {12:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] }{11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be {20:clicke}^d |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be {20:clicked} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ meths.input_mouse('right', 'press', '', 2, 1, 6)
+ meths.input_mouse('right', 'release', '', 2, 1, 6)
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {12:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] }{11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be {20:clicke}^d |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be {20:clicked} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 6
+ {21: Copy }|
+ ]], float_pos={
+ [6] = {{id = -1}, "NW", 2, 2, 5, false, 250};
+ }}
+ feed('<Down><CR>')
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {12:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] }{11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be ^clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ eq('clicked', funcs.getreg('"'))
+
+ funcs.setreg('"', '')
+ meths.input_mouse('left', 'press', '2', 4, 0, 64)
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do {20:eiusm}^o |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ meths.input_mouse('right', 'press', '', 4, 0, 64)
+ meths.input_mouse('right', 'release', '', 4, 0, 64)
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do {20:eiusm}^o |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 6
+ {21: Copy }|
+ ]], float_pos={
+ [6] = {{id = -1}, "NW", 4, 1, 63, false, 250};
+ }}
+ feed('<Down><CR>')
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ^eiusmo |
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ eq('eiusmo', funcs.getreg('"'))
+
+ command('wincmd J')
+ screen:try_resize_grid(4, 7, 10)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ ^eiusmo|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+
+ funcs.setreg('"', '')
+ meths.input_mouse('left', 'press', '2', 4, 9, 1)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ {20:eiusm}^o|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ meths.input_mouse('right', 'press', '', 4, 9, 1)
+ meths.input_mouse('right', 'release', '', 4, 9, 1)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ {20:eiusm}^o|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 6
+ {21: Copy }|
+ ]], float_pos={
+ [6] = {{id = -1}, "SW", 4, 9, 0, false, 250};
+ }}
+ feed('<Down><CR>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ ^eiusmo|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ eq('eiusmo', funcs.getreg('"'))
+
+ screen:try_resize_grid(4, 7, 11)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ ^eiusmo|
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+
+ funcs.setreg('"', '')
+ meths.input_mouse('left', 'press', '2', 4, 9, 1)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ {20:eiusm}^o|
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ meths.input_mouse('right', 'press', '', 4, 9, 1)
+ meths.input_mouse('right', 'release', '', 4, 9, 1)
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {7:-- VISUAL --} |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ {20:eiusm}^o|
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 6
+ {21: Copy }|
+ ]], float_pos={
+ [6] = {{id = -1}, "NW", 4, 10, 0, false, 250};
+ }}
+ feed('<Down><CR>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ [5:------------------------------]│[2:----------------------]|
+ {12:[No Name] [+] [No Name] [+] }|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ [4:-----------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ Lorem i|
+ psum do|
+ lor sit|
+ amet, |
+ consect|
+ etur ad|
+ ipiscin|
+ g elit,|
+ sed do|
+ ^eiusmo|
+ {1:~ }|
+ ## grid 5
+ some text |
+ to be clicked |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ eq('eiusmo', funcs.getreg('"'))
end)
it('supports mouse drag with mouse=a', function()
@@ -2127,7 +3128,7 @@ describe('ext_multigrid', function()
## grid 3
|
]], win_viewport={
- [2] = {win = { id = 1000 }, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}
+ [2] = {win = { id = 1000 }, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}
}}
insert([[
Lorem ipsum dolor sit amet, consectetur
@@ -2162,7 +3163,7 @@ describe('ext_multigrid', function()
## grid 3
|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11, sum_scroll_delta = 5},
}}
@@ -2187,7 +3188,7 @@ describe('ext_multigrid', function()
## grid 3
|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 2, botline = 9, curline = 7, curcol = 0, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 2, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 2},
}}
command("split")
@@ -2211,8 +3212,8 @@ describe('ext_multigrid', function()
reprehenderit in voluptate velit esse cillum |
^dolore eu fugiat nulla pariatur. Excepteur sint |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11},
- [4] = {win = {id = 1001}, topline = 5, botline = 9, curline = 7, curcol = 0, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6},
+ [4] = {win = {id = 1001}, topline = 5, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 5},
}}
feed("b")
@@ -2236,8 +3237,8 @@ describe('ext_multigrid', function()
reprehenderit in voluptate velit esse ^cillum |
dolore eu fugiat nulla pariatur. Excepteur sint |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11},
- [4] = {win = {id = 1001}, topline = 5, botline = 9, curline = 6, curcol = 38, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6},
+ [4] = {win = {id = 1001}, topline = 5, botline = 9, curline = 6, curcol = 38, linecount = 11, sum_scroll_delta = 5},
}}
feed("2k")
@@ -2261,8 +3262,8 @@ describe('ext_multigrid', function()
ea commodo consequat. Duis aute irure dolor in |
reprehenderit in voluptate velit esse cillum |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11},
- [4] = {win = {id = 1001}, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6},
+ [4] = {win = {id = 1001}, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4},
}}
-- handles non-current window
@@ -2287,8 +3288,561 @@ describe('ext_multigrid', function()
ea commodo consequat. Duis aute irure dolor in |
reprehenderit in voluptate velit esse cillum |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11},
- [4] = {win = {id = 1001}, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0},
+ [4] = {win = {id = 1001}, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4},
+ }}
+
+ -- sum_scroll_delta works with folds
+ feed('zfj')
+ screen:expect{grid=[[
+ ## grid 1
+ [4:------------------------------------------------]|
+ [4:------------------------------------------------]|
+ [4:------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [2:------------------------------------------------]|
+ [2:------------------------------------------------]|
+ {12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet, consectetur |
+ adipisicing elit, sed do eiusmod tempor |
+ ## grid 3
+ |
+ ## grid 4
+ {13:^+-- 2 lines: exercitation ullamco laboris nisi }|
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0},
+ [4] = {win = {id = 1001}, topline = 4, botline = 9, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4},
+ }}
+
+ feed('<c-e>')
+ screen:expect{grid=[[
+ ## grid 1
+ [4:------------------------------------------------]|
+ [4:------------------------------------------------]|
+ [4:------------------------------------------------]|
+ {11:[No Name] [+] }|
+ [2:------------------------------------------------]|
+ [2:------------------------------------------------]|
+ {12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet, consectetur |
+ adipisicing elit, sed do eiusmod tempor |
+ ## grid 3
+ |
+ ## grid 4
+ ^reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0},
+ [4] = {win = {id = 1001}, topline = 6, botline = 10, curline = 6, curcol = 0, linecount = 11, sum_scroll_delta = 5},
+ }}
+
+ command('close | 21vsplit | setlocal number smoothscroll')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {19: 1 }Lorem ipsu^m dolor|
+ {19: } sit amet, consec|
+ {19: }tetur |
+ {19: 2 }adipisicing elit,|
+ {19: } sed do eiusmod t|
+ {19: }empor |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ }}
+
+ feed('5<C-E>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {1:<<<}{19: }empo^r |
+ {19: 3 }incididunt ut lab|
+ {19: }ore et dolore mag|
+ {19: }na aliqua. |
+ {19: 4 }Ut enim ad minim |
+ {19: }veniam, quis n{1:@@@}|
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 5};
+ }}
+
+ feed('<C-Y>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {1:<<<}{19: } sed do eiusmod t|
+ {19: }empo^r |
+ {19: 3 }incididunt ut lab|
+ {19: }ore et dolore mag|
+ {19: }na aliqua. |
+ {19: 4 }Ut enim ad min{1:@@@}|
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 4};
+ }}
+
+ command('set cpoptions+=n')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {1:<<<}d do eiusmod tempo|
+ ^r |
+ {19: 3 }incididunt ut lab|
+ ore et dolore magna a|
+ liqua. |
+ {19: 4 }Ut enim ad min{1:@@@}|
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 4};
+ }}
+
+ feed('4<C-E>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {1:<<<}ua^. |
+ {19: 4 }Ut enim ad minim |
+ veniam, quis nostrud |
+ {19: 5 }exercitation ulla|
+ mco laboris nisi ut a|
+ liquip ex |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 2, botline = 6, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 8};
+ }}
+
+ feed('2<C-Y>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {19: 3 }incididunt ut lab|
+ ore et dolore magna a|
+ liqua^. |
+ {19: 4 }Ut enim ad minim |
+ veniam, quis nostrud |
+ {19: 5 }exercitation u{1:@@@}|
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 6};
+ }}
+
+ command('setlocal numberwidth=12')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {19: 3 }incididun|
+ t ut labore et dolore|
+ magna aliqua^. |
+ {19: 4 }Ut enim a|
+ d minim veniam, quis |
+ nostrud |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 6};
+ }}
+
+ feed('2<C-E>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {1:<<<}gna aliqua^. |
+ {19: 4 }Ut enim a|
+ d minim veniam, quis |
+ nostrud |
+ {19: 5 }exercitat|
+ ion ullamco labori{1:@@@}|
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 8};
+ }}
+
+ feed('<C-E>')
+ screen:expect{grid=[[
+ ## grid 1
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ [5:---------------------]│[2:--------------------------]|
+ {11:[No Name] [+] }{12:[No Name] [+] }|
+ [3:------------------------------------------------]|
+ ## grid 2
+ Lorem ipsum dolor sit amet|
+ , consectetur |
+ adipisicing elit, sed do e|
+ iusmod tempor |
+ incididunt ut labore et do|
+ lore magna aliqua. |
+ ## grid 3
+ |
+ ## grid 5
+ {19: 4 }Ut enim a|
+ d minim veniam, quis |
+ nostru^d |
+ {19: 5 }exercitat|
+ ion ullamco laboris n|
+ isi ut aliquip ex |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0};
+ [5] = {win = {id = 1002}, topline = 3, botline = 6, curline = 3, curcol = 36, linecount = 11, sum_scroll_delta = 9};
+ }}
+ end)
+
+ it('scroll_delta is approximated reasonably when scrolling many lines #24234', function()
+ command('setlocal number nowrap')
+ command('edit test/functional/fixtures/bigfile.txt')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
+ {19: 2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
+ {19: 3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
+ {19: 4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
+ {19: 5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
+ {19: 6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;; |
+ {19: 7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; |
+ {19: 8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
+ {19: 9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;; |
+ {19: 10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATIO|
+ {19: 11 }000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;; |
+ {19: 12 }000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 13, curline = 0, curcol = 0, linecount = 30592, sum_scroll_delta = 0};
+ }}
+ feed('G')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19:30581 }E01E8;VARIATION SELECTOR-249;Mn;0;NSM;;;;;N;;;;|
+ {19:30582 }E01E9;VARIATION SELECTOR-250;Mn;0;NSM;;;;;N;;;;|
+ {19:30583 }E01EA;VARIATION SELECTOR-251;Mn;0;NSM;;;;;N;;;;|
+ {19:30584 }E01EB;VARIATION SELECTOR-252;Mn;0;NSM;;;;;N;;;;|
+ {19:30585 }E01EC;VARIATION SELECTOR-253;Mn;0;NSM;;;;;N;;;;|
+ {19:30586 }E01ED;VARIATION SELECTOR-254;Mn;0;NSM;;;;;N;;;;|
+ {19:30587 }E01EE;VARIATION SELECTOR-255;Mn;0;NSM;;;;;N;;;;|
+ {19:30588 }E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;|
+ {19:30589 }F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;|
+ {19:30590 }FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N|
+ {19:30591 }100000;<Plane 16 Private Use, First>;Co;0;L;;;;|
+ {19:30592 }^10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 30580, botline = 30592, curline = 30591, curcol = 0, linecount = 30592, sum_scroll_delta = 30580};
+ }}
+ feed('gg')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
+ {19: 2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
+ {19: 3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
+ {19: 4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
+ {19: 5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
+ {19: 6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;; |
+ {19: 7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; |
+ {19: 8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
+ {19: 9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;; |
+ {19: 10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATIO|
+ {19: 11 }000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;; |
+ {19: 12 }000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 13, curline = 0, curcol = 0, linecount = 30592, sum_scroll_delta = 0};
+ }}
+ command('setlocal wrap')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
+ {19: 2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
+ {19: };; |
+ {19: 3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
+ {19: 4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
+ {19: 5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
+ {19: }N;;;; |
+ {19: 6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;; |
+ {19: 7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; |
+ {19: 8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
+ {19: 9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;; |
+ {19: 10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULA{1:@@@}|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 10, curline = 0, curcol = 0, linecount = 30592, sum_scroll_delta = 0};
+ }}
+ feed('G')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19:30587 }E01EE;VARIATION SELECTOR-255;Mn;0;NSM;;;;;N;;;;|
+ {19: }; |
+ {19:30588 }E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;|
+ {19: }; |
+ {19:30589 }F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;|
+ {19: }N;;;;; |
+ {19:30590 }FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N|
+ {19: };;;;; |
+ {19:30591 }100000;<Plane 16 Private Use, First>;Co;0;L;;;;|
+ {19: };N;;;;; |
+ {19:30592 }^10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;|
+ {19: }N;;;;; |
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 30586, botline = 30592, curline = 30591, curcol = 0, linecount = 30592, sum_scroll_delta = 30588};
+ }}
+ feed('gg')
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ [2:-----------------------------------------------------]|
+ {11:test/functional/fixtures/bigfile.txt }|
+ [3:-----------------------------------------------------]|
+ ## grid 2
+ {19: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
+ {19: 2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
+ {19: };; |
+ {19: 3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
+ {19: 4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
+ {19: 5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
+ {19: }N;;;; |
+ {19: 6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;; |
+ {19: 7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; |
+ {19: 8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
+ {19: 9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;; |
+ {19: 10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULA{1:@@@}|
+ ## grid 3
+ |
+ ]], win_viewport={
+ [2] = {win = {id = 1000}, topline = 0, botline = 10, curline = 0, curcol = 0, linecount = 30592, sum_scroll_delta = 0};
}}
end)
@@ -2314,7 +3868,7 @@ describe('ext_multigrid', function()
## grid 3
|
]], win_viewport={
- [2] = {win = { id = 1000 }, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}
+ [2] = {win = { id = 1000 }, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}
}}
insert([[
Lorem ipsum dolor sit amet, consectetur
@@ -2349,7 +3903,7 @@ describe('ext_multigrid', function()
## grid 3
|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11, sum_scroll_delta = 5},
}}
meths.input_mouse('left', 'press', '', 1,5, 1)
@@ -2376,7 +3930,7 @@ describe('ext_multigrid', function()
## grid 3
{7:-- VISUAL --} |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 6, botline = 12, curline = 10, curcol = 1, linecount = 11},
+ [2] = {win = {id = 1000}, topline = 6, botline = 12, curline = 10, curcol = 1, linecount = 11, sum_scroll_delta = 6},
}}
end)
@@ -2414,8 +3968,8 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
-- XXX: hack to get notifications. Could use next_msg() also.
@@ -2459,8 +4013,8 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
eq({}, win_pos)
@@ -2497,14 +4051,14 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
- [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
+ [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
}}
eq({}, win_pos)
end)
it('with winbar dragging statusline with mouse works correctly', function()
- meths.set_option('winbar', 'Set Up The Bars')
+ meths.set_option_value('winbar', 'Set Up The Bars', {})
command('split')
screen:expect([[
## grid 1
@@ -2644,7 +4198,7 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]])
- eq(3, meths.get_option('cmdheight'))
+ eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 1, 12, 10)
screen:expect([[
@@ -2679,6 +4233,6 @@ describe('ext_multigrid', function()
{1:~ }|
{1:~ }|
]])
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
end)
end)
diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua
index 9d20229ce1..2c649709c6 100644
--- a/test/functional/ui/options_spec.lua
+++ b/test/functional/ui/options_spec.lua
@@ -19,9 +19,11 @@ describe('UI receives option updates', function()
linespace=0,
pumblend=0,
mousefocus=false,
+ mousehide=true,
mousemoveevent=false,
showtabline=1,
termguicolors=false,
+ termsync=true,
ttimeout=true,
ttimeoutlen=50,
verbose=0,
@@ -68,15 +70,18 @@ describe('UI receives option updates', function()
eq({'mouse_on'}, evs)
end)
command("set mouse=")
+ screen:expect(function()
+ eq({'mouse_on', 'mouse_off'}, evs)
+ end)
command("set mouse&")
screen:expect(function()
- eq({'mouse_on','mouse_off', 'mouse_on'}, evs)
+ eq({'mouse_on', 'mouse_off', 'mouse_on'}, evs)
end)
screen:detach()
- eq({'mouse_on','mouse_off', 'mouse_on'}, evs)
+ eq({'mouse_on', 'mouse_off', 'mouse_on'}, evs)
screen:attach()
screen:expect(function()
- eq({'mouse_on','mouse_off','mouse_on', 'mouse_on'}, evs)
+ eq({'mouse_on', 'mouse_off', 'mouse_on', 'mouse_on'}, evs)
end)
end)
@@ -133,6 +138,12 @@ describe('UI receives option updates', function()
eq(expected, screen.options)
end)
+ command("set nomousehide")
+ expected.mousehide = false
+ screen:expect(function()
+ eq(expected, screen.options)
+ end)
+
command("set mousemoveevent")
expected.mousemoveevent = true
screen:expect(function()
@@ -200,22 +211,6 @@ describe('UI can set terminal option', function()
screen = Screen.new(20,5)
end)
- it('term_background', function()
- eq('dark', eval '&background')
-
- screen:attach {term_background='light'}
- eq('light', eval '&background')
- end)
-
- it("term_background but not if 'background' already set by user", function()
- eq('dark', eval '&background')
- command 'set background=dark'
-
- screen:attach {term_background='light'}
-
- eq('dark', eval '&background')
- end)
-
it('term_name', function()
eq('nvim', eval '&term')
diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua
index 223844405e..7b93b74eac 100644
--- a/test/functional/ui/output_spec.lua
+++ b/test/functional/ui/output_spec.lua
@@ -15,6 +15,8 @@ local set_shell_powershell = helpers.set_shell_powershell
local skip = helpers.skip
local is_os = helpers.is_os
+clear() -- for has_powershell()
+
describe("shell command :!", function()
local screen
before_each(function()
@@ -54,6 +56,7 @@ describe("shell command :!", function()
it("throttles shell-command output greater than ~10KB", function()
skip(is_os('openbsd'), 'FIXME #10804')
+ skip(is_os('win'))
child_session.feed_data((":!%s REP 30001 foo\n"):format(testprg('shell-test')))
-- If we observe any line starting with a dot, then throttling occurred.
@@ -222,8 +225,8 @@ describe("shell command :!", function()
å |
ref: å̲ |
1: å̲ |
- 2: å ̲ |
- 3: å ̲ |
+ 2: å ̲ |
+ 3: å ̲ |
|
{3:Press ENTER or type command to continue}^ |
]])
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index c681453294..a6cd216d84 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -5,6 +5,7 @@ local clear, feed = helpers.clear, helpers.feed
local source = helpers.source
local insert = helpers.insert
local meths = helpers.meths
+local async_meths = helpers.async_meths
local command = helpers.command
local funcs = helpers.funcs
local eq = helpers.eq
@@ -1023,1870 +1024,11 @@ describe('ui/ext_popupmenu', function()
end)
end)
+describe("builtin popupmenu 'pumblend'", function()
+ before_each(clear)
-describe('builtin popupmenu', function()
- local screen
- before_each(function()
- clear()
- screen = Screen.new(32, 20)
- screen:attach()
- screen:set_default_attr_ids({
- -- popup selected item / scrollbar track
- ['s'] = {background = Screen.colors.WebGray},
- -- popup non-selected item
- ['n'] = {background = Screen.colors.LightMagenta},
- -- popup scrollbar knob
- ['c'] = {background = Screen.colors.Grey0},
- [1] = {bold = true, foreground = Screen.colors.Blue},
- [2] = {bold = true},
- [3] = {reverse = true},
- [4] = {bold = true, reverse = true},
- [5] = {bold = true, foreground = Screen.colors.SeaGreen},
- [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
- [7] = {background = Screen.colors.Yellow}, -- Search
- [8] = {foreground = Screen.colors.Red},
- })
- end)
-
- it('with preview-window above', function()
- feed(':ped<CR><c-w>4+')
- feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
- feed('<c-x><c-n>')
- screen:expect([[
- aa bb cc dd ee ff gg hh ii jj |
- aa |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {3:[No Name] [Preview][+] }|
- aa bb cc dd ee ff gg hh ii jj |
- aa^ |
- {s:aa }{c: }{1: }|
- {n:bb }{c: }{1: }|
- {n:cc }{c: }{1: }|
- {n:dd }{c: }{1: }|
- {n:ee }{c: }{1: }|
- {n:ff }{c: }{1: }|
- {n:gg }{s: }{1: }|
- {n:hh }{s: }{4: }|
- {2:-- }{5:match 1 of 10} |
- ]])
- end)
-
- it('with preview-window below', function()
- feed(':ped<CR><c-w>4+<c-w>r')
- feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
- feed('<c-x><c-n>')
- screen:expect([[
- aa bb cc dd ee ff gg hh ii jj |
- aa^ |
- {s:aa }{c: }{1: }|
- {n:bb }{c: }{1: }|
- {n:cc }{c: }{1: }|
- {n:dd }{c: }{1: }|
- {n:ee }{c: }{1: }|
- {n:ff }{c: }{1: }|
- {n:gg }{s: }{1: }|
- {n:hh }{s: }{4: }|
- aa bb cc dd ee ff gg hh ii jj |
- aa |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {3:[No Name] [Preview][+] }|
- {2:-- }{5:match 1 of 10} |
- ]])
- end)
-
- it('with preview-window above and tall and inverted', function()
- feed(':ped<CR><c-w>8+')
- feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
- feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
- feed('kk<cr>ll<cr>mm<cr>nn<cr>oo<cr>')
- feed('<c-x><c-n>')
- screen:expect([[
- aa |
- bb |
- cc |
- dd |
- {s:aa }{c: }{3:ew][+] }|
- {n:bb }{c: } |
- {n:cc }{c: } |
- {n:dd }{c: } |
- {n:ee }{c: } |
- {n:ff }{c: } |
- {n:gg }{c: } |
- {n:hh }{c: } |
- {n:ii }{c: } |
- {n:jj }{c: } |
- {n:kk }{c: } |
- {n:ll }{s: } |
- {n:mm }{s: } |
- aa^ |
- {4:[No Name] [+] }|
- {2:-- }{5:match 1 of 15} |
- ]])
- end)
-
- it('with preview-window above and short and inverted', function()
- feed(':ped<CR><c-w>4+')
- feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
- feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
- feed('<c-x><c-n>')
- screen:expect([[
- aa |
- bb |
- cc |
- dd |
- ee |
- ff |
- gg |
- hh |
- {s:aa }{c: }{3:ew][+] }|
- {n:bb }{c: } |
- {n:cc }{c: } |
- {n:dd }{c: } |
- {n:ee }{c: } |
- {n:ff }{c: } |
- {n:gg }{c: } |
- {n:hh }{c: } |
- {n:ii }{s: } |
- aa^ |
- {4:[No Name] [+] }|
- {2:-- }{5:match 1 of 10} |
- ]])
- end)
-
- it('with preview-window below and inverted', function()
- feed(':ped<CR><c-w>4+<c-w>r')
- feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
- feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
- feed('<c-x><c-n>')
- screen:expect([[
- {s:aa }{c: } |
- {n:bb }{c: } |
- {n:cc }{c: } |
- {n:dd }{c: } |
- {n:ee }{c: } |
- {n:ff }{c: } |
- {n:gg }{s: } |
- {n:hh }{s: } |
- aa^ |
- {4:[No Name] [+] }|
- aa |
- bb |
- cc |
- dd |
- ee |
- ff |
- gg |
- hh |
- {3:[No Name] [Preview][+] }|
- {2:-- }{5:match 1 of 10} |
- ]])
- end)
-
- -- oldtest: Test_pum_with_preview_win()
- it('preview window opened during completion', function()
- exec([[
- funct Omni_test(findstart, base)
- if a:findstart
- return col(".") - 1
- endif
- return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
- endfunc
- set omnifunc=Omni_test
- set completeopt+=longest
- ]])
- feed('Gi<C-X><C-O>')
- screen:expect([[
- ^ |
- {n:one }{1: }|
- {n:two }{1: }|
- {n:three }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- }{8:Back at original} |
- ]])
- feed('<C-N>')
- screen:expect([[
- 1info |
- |
- {1:~ }|
- {3:[Scratch] [Preview] }|
- one^ |
- {s:one }{1: }|
- {n:two }{1: }|
- {n:three }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4:[No Name] [+] }|
- {2:-- }{5:match 1 of 3} |
- ]])
- end)
-
- it('with vsplits', function()
- insert('aaa aab aac\n')
- feed(':vsplit<cr>')
- screen:expect([[
- aaa aab aac │aaa aab aac|
- ^ │ |
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {4:[No Name] [+] }{3:<Name] [+] }|
- :vsplit |
- ]])
-
- feed('ibbb a<c-x><c-n>')
- screen:expect([[
- aaa aab aac │aaa aab aac|
- bbb aaa^ │bbb aaa |
- {1:~ }{s: aaa }{1: }│{1:~ }|
- {1:~ }{n: aab }{1: }│{1:~ }|
- {1:~ }{n: aac }{1: }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {4:[No Name] [+] }{3:<Name] [+] }|
- {2:-- }{5:match 1 of 3} |
- ]])
-
- feed('<esc><c-w><c-w>oc a<c-x><c-n>')
- screen:expect([[
- aaa aab aac│aaa aab aac |
- bbb aaa │bbb aaa |
- c aaa │c aaa^ |
- {1:~ }│{1:~}{s: aaa }{1: }|
- {1:~ }│{1:~}{n: aab }{1: }|
- {1:~ }│{1:~}{n: aac }{1: }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {1:~ }│{1:~ }|
- {3:<Name] [+] }{4:[No Name] [+] }|
- {2:-- }{5:match 1 of 3} |
- ]])
- end)
-
- it('with split and scroll', function()
- screen:try_resize(60,14)
- command("split")
- command("set completeopt+=noinsert")
- command("set mouse=a")
- insert([[
- Lorem ipsum dolor sit amet, consectetur
- adipisicing elit, sed do eiusmod tempor
- incididunt ut labore et dolore magna aliqua.
- Ut enim ad minim veniam, quis nostrud
- exercitation ullamco laboris nisi ut aliquip ex
- ea commodo consequat. Duis aute irure dolor in
- reprehenderit in voluptate velit esse cillum
- dolore eu fugiat nulla pariatur. Excepteur sint
- occaecat cupidatat non proident, sunt in culpa
- qui officia deserunt mollit anim id est
- laborum.
- ]])
-
- screen:expect([[
- reprehenderit in voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- occaecat cupidatat non proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- ^ |
- {4:[No Name] [+] }|
- Lorem ipsum dolor sit amet, consectetur |
- adipisicing elit, sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {3:[No Name] [+] }|
- |
- ]])
-
- feed('ggOEst <c-x><c-p>')
- screen:expect([[
- Est ^ |
- L{n: sunt }{s: }sit amet, consectetur |
- a{n: in }{s: }sed do eiusmod tempor |
- i{n: culpa }{s: }re et dolore magna aliqua. |
- U{n: qui }{s: }eniam, quis nostrud |
- e{n: officia }{s: }co laboris nisi ut aliquip ex |
- {4:[No}{n: deserunt }{s: }{4: }|
- L{n: mollit }{s: }sit amet, consectetur |
- a{n: anim }{s: }sed do eiusmod tempor |
- i{n: id }{s: }re et dolore magna aliqua. |
- U{n: est }{s: }eniam, quis nostrud |
- e{n: laborum }{c: }co laboris nisi ut aliquip ex |
- {3:[No}{s: Est }{c: }{3: }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- meths.input_mouse('wheel', 'down', '', 0, 9, 40)
- screen:expect([[
- Est ^ |
- L{n: sunt }{s: }sit amet, consectetur |
- a{n: in }{s: }sed do eiusmod tempor |
- i{n: culpa }{s: }re et dolore magna aliqua. |
- U{n: qui }{s: }eniam, quis nostrud |
- e{n: officia }{s: }co laboris nisi ut aliquip ex |
- {4:[No}{n: deserunt }{s: }{4: }|
- U{n: mollit }{s: }eniam, quis nostrud |
- e{n: anim }{s: }co laboris nisi ut aliquip ex |
- e{n: id }{s: }at. Duis aute irure dolor in |
- r{n: est }{s: }oluptate velit esse cillum |
- d{n: laborum }{c: }ulla pariatur. Excepteur sint |
- {3:[No}{s: Est }{c: }{3: }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- feed('e')
- screen:expect([[
- Est e^ |
- L{n: elit } sit amet, consectetur |
- a{n: eiusmod } sed do eiusmod tempor |
- i{n: et }ore et dolore magna aliqua. |
- U{n: enim }veniam, quis nostrud |
- e{n: exercitation }mco laboris nisi ut aliquip ex |
- {4:[No}{n: ex }{4: }|
- U{n: ea }veniam, quis nostrud |
- e{n: esse }mco laboris nisi ut aliquip ex |
- e{n: eu }uat. Duis aute irure dolor in |
- r{s: est }voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- meths.input_mouse('wheel', 'up', '', 0, 9, 40)
- screen:expect([[
- Est e^ |
- L{n: elit } sit amet, consectetur |
- a{n: eiusmod } sed do eiusmod tempor |
- i{n: et }ore et dolore magna aliqua. |
- U{n: enim }veniam, quis nostrud |
- e{n: exercitation }mco laboris nisi ut aliquip ex |
- {4:[No}{n: ex }{4: }|
- L{n: ea } sit amet, consectetur |
- a{n: esse } sed do eiusmod tempor |
- i{n: eu }ore et dolore magna aliqua. |
- U{s: est }veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- feed('s')
- screen:expect([[
- Est es^ |
- L{n: esse } sit amet, consectetur |
- a{s: est } sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {4:[No Name] [+] }|
- Lorem ipsum dolor sit amet, consectetur |
- adipisicing elit, sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- meths.input_mouse('wheel', 'down', '', 0, 9, 40)
- screen:expect([[
- Est es^ |
- L{n: esse } sit amet, consectetur |
- a{s: est } sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {4:[No Name] [+] }|
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- ea commodo consequat. Duis aute irure dolor in |
- reprehenderit in voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- feed('<bs>')
- screen:expect([[
- Est e^ |
- L{n: elit } sit amet, consectetur |
- a{n: eiusmod } sed do eiusmod tempor |
- i{n: et }ore et dolore magna aliqua. |
- U{n: enim }veniam, quis nostrud |
- e{n: exercitation }mco laboris nisi ut aliquip ex |
- {4:[No}{n: ex }{4: }|
- U{n: ea }veniam, quis nostrud |
- e{n: esse }mco laboris nisi ut aliquip ex |
- e{n: eu }uat. Duis aute irure dolor in |
- r{s: est }voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
- ]])
-
- feed('<c-p>')
- screen:expect([[
- Est eu^ |
- L{n: elit } sit amet, consectetur |
- a{n: eiusmod } sed do eiusmod tempor |
- i{n: et }ore et dolore magna aliqua. |
- U{n: enim }veniam, quis nostrud |
- e{n: exercitation }mco laboris nisi ut aliquip ex |
- {4:[No}{n: ex }{4: }|
- U{n: ea }veniam, quis nostrud |
- e{n: esse }mco laboris nisi ut aliquip ex |
- e{s: eu }uat. Duis aute irure dolor in |
- r{n: est }voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} |
- ]])
-
- meths.input_mouse('wheel', 'down', '', 0, 9, 40)
- screen:expect([[
- Est eu^ |
- L{n: elit } sit amet, consectetur |
- a{n: eiusmod } sed do eiusmod tempor |
- i{n: et }ore et dolore magna aliqua. |
- U{n: enim }veniam, quis nostrud |
- e{n: exercitation }mco laboris nisi ut aliquip ex |
- {4:[No}{n: ex }{4: }|
- r{n: ea }voluptate velit esse cillum |
- d{n: esse }nulla pariatur. Excepteur sint |
- o{s: eu }t non proident, sunt in culpa |
- q{n: est }unt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} |
- ]])
-
-
- funcs.complete(4, {'ea', 'eeeeeeeeeeeeeeeeee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö'})
- screen:expect([[
- Est eu^ |
- {s: ea }t amet, consectetur |
- {n: eeeeeeeeeeeeeeeeee }d do eiusmod tempor |
- {n: ei } et dolore magna aliqua. |
- {n: eo }iam, quis nostrud |
- {n: eu } laboris nisi ut aliquip ex |
- {4:[N}{n: ey }{4: }|
- {n: eå }uptate velit esse cillum |
- {n: eä }la pariatur. Excepteur sint |
- {n: eö }on proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- Keyword Local completion (^N^P) }{5:match 1 of 9} |
- ]])
-
- funcs.complete(4, {'ea', 'eee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö'})
- screen:expect([[
- Est eu^ |
- {s: ea }r sit amet, consectetur |
- {n: eee }, sed do eiusmod tempor |
- {n: ei }bore et dolore magna aliqua. |
- {n: eo } veniam, quis nostrud |
- {n: eu }amco laboris nisi ut aliquip ex |
- {4:[N}{n: ey }{4: }|
- {n: eå } voluptate velit esse cillum |
- {n: eä } nulla pariatur. Excepteur sint |
- {n: eö }at non proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-n>')
- screen:expect([[
- Esteee^ |
- {n: ea }r sit amet, consectetur |
- {s: eee }, sed do eiusmod tempor |
- {n: ei }bore et dolore magna aliqua. |
- {n: eo } veniam, quis nostrud |
- {n: eu }amco laboris nisi ut aliquip ex |
- {4:[N}{n: ey }{4: }|
- {n: eå } voluptate velit esse cillum |
- {n: eä } nulla pariatur. Excepteur sint |
- {n: eö }at non proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]])
-
- funcs.complete(6, {'foo', 'bar'})
- screen:expect([[
- Esteee^ |
- Lo{s: foo }sit amet, consectetur |
- ad{n: bar }sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {4:[No Name] [+] }|
- reprehenderit in voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- occaecat cupidatat non proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-y>')
- screen:expect([[
- Esteefoo^ |
- Lorem ipsum dolor sit amet, consectetur |
- adipisicing elit, sed do eiusmod tempor |
- incididunt ut labore et dolore magna aliqua. |
- Ut enim ad minim veniam, quis nostrud |
- exercitation ullamco laboris nisi ut aliquip ex |
- {4:[No Name] [+] }|
- reprehenderit in voluptate velit esse cillum |
- dolore eu fugiat nulla pariatur. Excepteur sint |
- occaecat cupidatat non proident, sunt in culpa |
- qui officia deserunt mollit anim id est |
- laborum. |
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]])
- end)
-
- it('can be moved due to wrap or resize', function()
- feed('isome long prefix before the ')
- command("set completeopt+=noinsert,noselect")
- command("set linebreak")
- funcs.complete(29, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- some long prefix before the ^ |
- {1:~ }{n: word }|
- {1:~ }{n: choice}|
- {1:~ }{n: text }|
- {1:~ }{n: thing }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-p>')
- screen:expect([[
- some long prefix before the |
- thing^ |
- {n:word }{1: }|
- {n:choice }{1: }|
- {n:text }{1: }|
- {s:thing }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-p>')
- screen:expect([[
- some long prefix before the text|
- {1:^~ }{n: word }|
- {1:~ }{n: choice}|
- {1:~ }{s: text }|
- {1:~ }{n: thing }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- screen:try_resize(30,8)
- screen:expect([[
- some long prefix before the |
- text^ |
- {n:word }{1: }|
- {n:choice }{1: }|
- {s:text }{1: }|
- {n:thing }{1: }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- screen:try_resize(50,8)
- screen:expect([[
- some long prefix before the text^ |
- {1:~ }{n: word }{1: }|
- {1:~ }{n: choice }{1: }|
- {1:~ }{s: text }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- screen:try_resize(25,10)
- screen:expect([[
- some long prefix before |
- the text^ |
- {1:~ }{n: word }{1: }|
- {1:~ }{n: choice }{1: }|
- {1:~ }{s: text }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- screen:try_resize(12,5)
- screen:expect([[
- some long |
- prefix |
- bef{n: word } |
- tex{n: }^ |
- {2:-- INSERT -} |
- ]])
-
- -- can't draw the pum, but check we don't crash
- screen:try_resize(12,2)
- screen:expect([[
- text^ |
- {2:-- INSERT -} |
- ]])
-
- -- but state is preserved, pum reappears
- screen:try_resize(20,8)
- screen:expect([[
- some long prefix |
- before the text^ |
- {1:~ }{n: word }{1: }|
- {1:~ }{n: choice }{1: }|
- {1:~ }{s: text }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
-
- it('with VimResized autocmd', function()
- feed('isome long prefix before the ')
- command("set completeopt+=noinsert,noselect")
- command("autocmd VimResized * redraw!")
- command("set linebreak")
- funcs.complete(29, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- some long prefix before the ^ |
- {1:~ }{n: word }|
- {1:~ }{n: choice}|
- {1:~ }{n: text }|
- {1:~ }{n: thing }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- screen:try_resize(16,10)
- screen:expect([[
- some long |
- prefix before |
- the ^ |
- {1:~ }{n: word }|
- {1:~ }{n: choice }|
- {1:~ }{n: text }|
- {1:~ }{n: thing }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
-
- it('with rightleft window', function()
- command("set rl wildoptions+=pum")
- feed('isome rightleft ')
- screen:expect([[
- ^ tfelthgir emos|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {2:-- INSERT --} |
- ]])
-
- command("set completeopt+=noinsert,noselect")
- funcs.complete(16, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- ^ tfelthgir emos|
- {1: }{n: drow}{1: ~}|
- {1: }{n: eciohc}{1: ~}|
- {1: }{n: txet}{1: ~}|
- {1: }{n: gniht}{1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-n>')
- screen:expect([[
- ^ drow tfelthgir emos|
- {1: }{s: drow}{1: ~}|
- {1: }{n: eciohc}{1: ~}|
- {1: }{n: txet}{1: ~}|
- {1: }{n: gniht}{1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-y>')
- screen:expect([[
- ^ drow tfelthgir emos|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {2:-- INSERT --} |
- ]])
-
- -- not rightleft on the cmdline
- feed('<esc>:sign ')
- screen:expect{grid=[[
- drow tfelthgir emos|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- :sign ^ |
- ]]}
-
- feed('<tab>')
- screen:expect{grid=[[
- drow tfelthgir emos|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: ~}|
- {1: }{s: define }{1: ~}|
- {1: }{n: jump }{1: ~}|
- {1: }{n: list }{1: ~}|
- {1: }{n: place }{1: ~}|
- {1: }{n: undefine }{1: ~}|
- {1: }{n: unplace }{1: ~}|
- :sign define^ |
- ]]}
- end)
-
- it('with multiline messages', function()
- screen:try_resize(40,8)
- feed('ixx<cr>')
- command('imap <f2> <cmd>echoerr "very"\\|echoerr "much"\\|echoerr "error"<cr>')
- funcs.complete(1, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- xx |
- word^ |
- {s:word }{1: }|
- {n:choice }{1: }|
- {n:text }{1: }|
- {n:thing }{1: }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<f2>')
- screen:expect([[
- xx |
- word |
- {s:word }{1: }|
- {4: }|
- {6:very} |
- {6:much} |
- {6:error} |
- {5:Press ENTER or type command to continue}^ |
- ]])
-
- feed('<cr>')
- screen:expect([[
- xx |
- word^ |
- {s:word }{1: }|
- {n:choice }{1: }|
- {n:text }{1: }|
- {n:thing }{1: }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-n>')
- screen:expect([[
- xx |
- choice^ |
- {n:word }{1: }|
- {s:choice }{1: }|
- {n:text }{1: }|
- {n:thing }{1: }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- command("split")
- screen:expect([[
- xx |
- choice^ |
- {n:word }{1: }|
- {s:choice }{4: }|
- {n:text } |
- {n:thing } |
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]])
-
- meths.input_mouse('wheel', 'down', '', 0, 6, 15)
- screen:expect{grid=[[
- xx |
- choice^ |
- {n:word }{1: }|
- {s:choice }{4: }|
- {n:text } |
- {n:thing }{1: }|
- {3:[No Name] [+] }|
- {2:-- INSERT --} |
- ]], unchanged=true}
- end)
-
- it('with kind, menu and abbr attributes', function()
- screen:try_resize(40,8)
- feed('ixx ')
- funcs.complete(4, {{word='wordey', kind= 'x', menu='extrainfo'}, 'thing', {word='secret', abbr='sneaky', menu='bar'}})
- screen:expect([[
- xx wordey^ |
- {1:~ }{s: wordey x extrainfo }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }{n: sneaky bar }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-p>')
- screen:expect([[
- xx ^ |
- {1:~ }{n: wordey x extrainfo }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }{n: sneaky bar }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<c-p>')
- screen:expect([[
- xx secret^ |
- {1:~ }{n: wordey x extrainfo }{1: }|
- {1:~ }{n: thing }{1: }|
- {1:~ }{s: sneaky bar }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
-
- feed('<esc>')
- screen:expect([[
- xx secre^t |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]])
- end)
-
- it('wildoptions=pum', function()
- screen:try_resize(32,10)
- command('set wildmenu')
- command('set wildoptions=pum')
- command('set shellslash')
- command("cd test/functional/fixtures/wildpum")
-
- feed(':sign ')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign ^ |
- ]])
-
- feed('<Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign define^ |
- ]])
-
- feed('<Right><Right>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{s: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign list^ |
- ]])
-
- feed('<C-N>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{s: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign place^ |
- ]])
-
- feed('<C-P>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{s: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign list^ |
- ]])
-
- feed('<Left>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{s: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign jump^ |
- ]])
-
- -- pressing <C-E> should end completion and go back to the original match
- feed('<C-E>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign ^ |
- ]])
-
- -- pressing <C-Y> should select the current match and end completion
- feed('<Tab><C-P><C-P><C-Y>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign unplace^ |
- ]])
-
- -- showing popup menu in different columns in the cmdline
- feed('<C-U>sign define <Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: culhl= }{1: }|
- {1:~ }{n: icon= }{1: }|
- {1:~ }{n: linehl= }{1: }|
- {1:~ }{n: numhl= }{1: }|
- {1:~ }{n: text= }{1: }|
- {1:~ }{n: texthl= }{1: }|
- :sign define culhl=^ |
- ]])
-
- feed('<Space><Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: culhl= }{1: }|
- {1:~ }{n: icon= }{1: }|
- {1:~ }{n: linehl= }{1: }|
- {1:~ }{n: numhl= }{1: }|
- {1:~ }{n: text= }{1: }|
- {1:~ }{n: texthl= }{1: }|
- :sign define culhl= culhl=^ |
- ]])
-
- feed('<C-U>e Xdi<Tab><Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: XdirA/ }{1: }|
- {1:~ }{n: XfileA }{1: }|
- :e Xdir/XdirA/^ |
- ]])
-
- -- Pressing <Down> on a directory name should go into that directory
- feed('<Down>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: XdirB/ }{1: }|
- {1:~ }{n: XfileB }{1: }|
- :e Xdir/XdirA/XdirB/^ |
- ]])
-
- -- Pressing <Up> on a directory name should go to the parent directory
- feed('<Up>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: XdirA/ }{1: }|
- {1:~ }{n: XfileA }{1: }|
- :e Xdir/XdirA/^ |
- ]])
-
- -- Pressing <C-A> when the popup menu is displayed should list all the
- -- matches and remove the popup menu
- feed(':<C-U>sign <Tab><C-A>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- :sign define jump list place und|
- efine unplace^ |
- ]])
-
- -- Pressing <Left> after that should move the cursor
- feed('<Left>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- :sign define jump list place und|
- efine unplac^e |
- ]])
- feed('<End>')
-
- -- Pressing <C-D> when the popup menu is displayed should remove the popup
- -- menu
- feed('<C-U>sign <Tab><C-D>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- :sign define |
- define |
- :sign define^ |
- ]])
-
- -- Pressing <S-Tab> should open the popup menu with the last entry selected
- feed('<C-U><CR>:sign <S-Tab><C-P>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{s: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign undefine^ |
- ]])
-
- -- Pressing <Esc> should close the popup menu and cancel the cmd line
- feed('<C-U><CR>:sign <Tab><Esc>')
- screen:expect([[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]])
-
- -- Typing a character when the popup is open, should close the popup
- feed(':sign <Tab>x')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign definex^ |
- ]])
-
- -- When the popup is open, entering the cmdline window should close the popup
- feed('<C-U>sign <Tab><C-F>')
- screen:expect([[
- |
- {3:[No Name] }|
- {1::}sign define |
- {1::}sign define^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4:[Command Line] }|
- :sign define |
- ]])
- feed(':q<CR>')
-
- -- After the last popup menu item, <C-N> should show the original string
- feed(':sign u<Tab><C-N><C-N>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign u^ |
- ]])
-
- -- Use the popup menu for the command name
- feed('<C-U>bu<Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {s: bufdo }{1: }|
- {n: buffer }{1: }|
- {n: buffers }{1: }|
- {n: bunload }{1: }|
- :bufdo^ |
- ]])
-
- -- Pressing <BS> should remove the popup menu and erase the last character
- feed('<C-E><C-U>sign <Tab><BS>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign defin^ |
- ]])
-
- -- Pressing <C-W> should remove the popup menu and erase the previous word
- feed('<C-E><C-U>sign <Tab><C-W>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign ^ |
- ]])
-
- -- Pressing <C-U> should remove the popup menu and erase the entire line
- feed('<C-E><C-U>sign <Tab><C-U>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :^ |
- ]])
-
- -- Using <C-E> to cancel the popup menu and then pressing <Up> should recall
- -- the cmdline from history
- feed('sign xyz<Esc>:sign <Tab><C-E><Up>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign xyz^ |
- ]])
-
- feed('<esc>')
-
- -- Check "list" still works
- command('set wildmode=longest,list')
- feed(':cn<Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- :cn |
- cnewer cnoreabbrev |
- cnext cnoremap |
- cnfile cnoremenu |
- :cn^ |
- ]])
- feed('s')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- :cn |
- cnewer cnoreabbrev |
- cnext cnoremap |
- cnfile cnoremenu |
- :cns^ |
- ]])
-
- feed('<esc>')
- command('set wildmode=full')
-
- -- Tests a directory name contained full-width characters.
- feed(':e あいう/<Tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: 123 }{1: }|
- {1:~ }{n: abc }{1: }|
- {1:~ }{n: xyz }{1: }|
- :e あいう/123^ |
- ]])
- feed('<Esc>')
-
- -- Pressing <PageDown> should scroll the menu downward
- feed(':sign <Tab><PageDown>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{s: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign undefine^ |
- ]])
- feed('<PageDown>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{s: unplace }{1: }|
- :sign unplace^ |
- ]])
- feed('<PageDown>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign ^ |
- ]])
- feed('<PageDown>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign define^ |
- ]])
- feed('<C-U>sign <Tab><Right><Right><PageDown>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{s: unplace }{1: }|
- :sign unplace^ |
- ]])
-
- -- Pressing <PageUp> should scroll the menu upward
- feed('<C-U>sign <Tab><PageUp>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign ^ |
- ]])
- feed('<PageUp>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{s: unplace }{1: }|
- :sign unplace^ |
- ]])
- feed('<PageUp>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{n: define }{1: }|
- {1:~ }{s: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign jump^ |
- ]])
- feed('<PageUp>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign define^ |
- ]])
-
- feed('<Esc>')
-
- -- check positioning with multibyte char in pattern
- command("e långfile1")
- command("sp långfile2")
- feed(':b lå<tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4:långfile2 }|
- |
- {1:~ }|
- {1:~ }{s: långfile1 }{1: }|
- {3:lå}{n: långfile2 }{3: }|
- :b långfile1^ |
- ]])
-
- -- check doesn't crash on screen resize
- screen:try_resize(20,6)
- screen:expect([[
- |
- {1:~ }|
- {4:långfile2 }|
- {s: långfile1 } |
- {3:lå}{n: långfile2 }{3: }|
- :b långfile1^ |
- ]])
-
- screen:try_resize(50,15)
- screen:expect([[
- |
- {1:~ }|
- {4:långfile2 }|
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: långfile1 }{1: }|
- {3:lå}{n: långfile2 }{3: }|
- :b långfile1^ |
- ]])
-
- -- position is calculated correctly with "longest"
- feed('<esc>')
- command('set wildmode=longest:full,full')
- feed(':b lå<tab>')
- screen:expect([[
- |
- {1:~ }|
- {4:långfile2 }|
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{n: långfile1 }{1: }|
- {3:lå}{n: långfile2 }{3: }|
- :b långfile^ |
- ]])
-
- feed('<esc>')
- command("close")
- command('set wildmode=full')
-
- -- special case: when patterns ends with "/", show menu items aligned
- -- after the "/"
- feed(':e compdir/<tab>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: file1 }{1: }|
- {1:~ }{n: file2 }{1: }|
- :e compdir/file1^ |
- ]])
- end)
-
- it('wildoptions=pum with scrolled messages', function()
- screen:try_resize(40,10)
- command('set wildmenu')
- command('set wildoptions=pum')
-
- feed(':echoerr "fail"|echoerr "error"<cr>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- {6:fail} |
- {6:error} |
- {5:Press ENTER or type command to continue}^ |
- ]]}
-
- feed(':sign <tab>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {4: }{n: place }{4: }|
- {6:fail} {n: undefine } |
- {6:error}{n: unplace } |
- :sign define^ |
- ]]}
-
- feed('d')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {4: }|
- {6:fail} |
- {6:error} |
- :sign defined^ |
- ]]}
- end)
-
- it('wildoptions=pum and wildmode=longest,full #11622', function()
- screen:try_resize(30,8)
- command('set wildmenu')
- command('set wildoptions=pum')
- command('set wildmode=longest,full')
-
- -- With 'wildmode' set to 'longest,full', completing a match should display
- -- the longest match, the wildmenu should not be displayed.
- feed(':sign u<Tab>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :sign un^ |
- ]]}
- eq(0, funcs.wildmenumode())
-
- -- pressing <Tab> should display the wildmenu
- feed('<Tab>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{s: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign undefine^ |
- ]]}
- eq(1, funcs.wildmenumode())
-
- -- pressing <Tab> second time should select the next entry in the menu
- feed('<Tab>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{s: unplace }{1: }|
- :sign unplace^ |
- ]]}
- end)
-
- it('wildoptions=pum with a wrapped line in buffer vim-patch:8.2.4655', function()
- screen:try_resize(32, 10)
- meths.buf_set_lines(0, 0, -1, true, { ('a'):rep(100) })
- command('set wildoptions+=pum')
- feed('$')
- feed(':sign <Tab>')
- screen:expect([[
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
- aaaa {s: define } |
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign define^ |
- ]])
- end)
-
- -- oldtest: Test_wildmenu_pum_clear_entries()
- it('wildoptions=pum when using Ctrl-E as wildchar vim-patch:9.0.1030', function()
- screen:try_resize(30, 10)
- exec([[
- set wildoptions=pum
- set wildchar=<C-E>
- ]])
- feed(':sign <C-E><C-E>')
- screen:expect([[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }{s: define }{1: }|
- {1:~ }{n: jump }{1: }|
- {1:~ }{n: list }{1: }|
- {1:~ }{n: place }{1: }|
- {1:~ }{n: undefine }{1: }|
- {1:~ }{n: unplace }{1: }|
- :sign define^ |
- ]])
- assert_alive()
- end)
-
- it("'pumblend' RGB-color", function()
- screen:try_resize(60,14)
+ it('RGB-color', function()
+ local screen = Screen.new(60, 14)
screen:set_default_attr_ids({
[1] = {background = Screen.colors.Yellow},
[2] = {bold = true, reverse = true},
@@ -2934,6 +1076,7 @@ describe('builtin popupmenu', function()
[44] = {foreground = tonumber('0x3f3f3f'), background = tonumber('0x7f5d7f')},
[45] = {background = Screen.colors.WebGray, blend=0},
})
+ screen:attach()
command('syntax on')
command('set mouse=a')
command('set pumblend=10')
@@ -3082,10 +1225,8 @@ describe('builtin popupmenu', function()
]])
end)
- it("'pumblend' 256-color (non-RGB)", function()
- screen:detach()
- screen = Screen.new(60, 8)
- screen:attach({rgb=false, ext_popupmenu=false})
+ it('256-color (non-RGB)', function()
+ local screen = Screen.new(60, 8)
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.Grey0, background = tonumber('0x000007')},
[2] = {foreground = tonumber('0x000055'), background = tonumber('0x000007')},
@@ -3098,6 +1239,7 @@ describe('builtin popupmenu', function()
[9] = {bold = true},
[10] = {foreground = tonumber('0x000002')},
})
+ screen:attach({rgb=false})
command('set notermguicolors pumblend=10')
insert([[
Lorem ipsum dolor sit amet, consectetur
@@ -3118,651 +1260,3738 @@ describe('builtin popupmenu', function()
{9:-- Keyword Local completion (^N^P) }{10:match 1 of 3} |
]])
end)
+end)
- it("'pumheight'", function()
- screen:try_resize(32,8)
- feed('isome long prefix before the ')
- command("set completeopt+=noinsert,noselect")
- command("set linebreak")
- command("set pumheight=2")
- funcs.complete(29, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- some long prefix before the ^ |
- {1:~ }{n: word }{c: }|
- {1:~ }{n: choice}{s: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
+describe('builtin popupmenu', function()
+ before_each(clear)
+
+ local function with_ext_multigrid(multigrid)
+ local screen
+ before_each(function()
+ screen = Screen.new(32, 20)
+ screen:set_default_attr_ids({
+ -- popup selected item / scrollbar track
+ ['s'] = {background = Screen.colors.WebGray},
+ -- popup non-selected item
+ ['n'] = {background = Screen.colors.LightMagenta},
+ -- popup scrollbar knob
+ ['c'] = {background = Screen.colors.Grey0},
+ [1] = {bold = true, foreground = Screen.colors.Blue},
+ [2] = {bold = true},
+ [3] = {reverse = true},
+ [4] = {bold = true, reverse = true},
+ [5] = {bold = true, foreground = Screen.colors.SeaGreen},
+ [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
+ [7] = {background = Screen.colors.Yellow}, -- Search
+ [8] = {foreground = Screen.colors.Red},
+ })
+ screen:attach({ext_multigrid=multigrid})
+ end)
- it("'pumwidth'", function()
- screen:try_resize(32,8)
- feed('isome long prefix before the ')
- command("set completeopt+=noinsert,noselect")
- command("set linebreak")
- command("set pumwidth=8")
- funcs.complete(29, {'word', 'choice', 'text', 'thing'})
- screen:expect([[
- some long prefix before the ^ |
- {1:~ }{n: word }|
- {1:~ }{n: choice}|
- {1:~ }{n: text }|
- {1:~ }{n: thing }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
+ it('with preview-window above', function()
+ feed(':ped<CR><c-w>4+')
+ feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
+ feed('<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ {3:[No Name] [Preview][+] }|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aa bb cc dd ee ff gg hh ii jj |
+ aa^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 10} |
+ ## grid 4
+ aa bb cc dd ee ff gg hh ii jj |
+ aa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 5
+ {s:aa }{c: }|
+ {n:bb }{c: }|
+ {n:cc }{c: }|
+ {n:dd }{c: }|
+ {n:ee }{c: }|
+ {n:ff }{c: }|
+ {n:gg }{s: }|
+ {n:hh }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 2, 2, 0, false, 100};
+ }}
+ else
+ screen:expect([[
+ aa bb cc dd ee ff gg hh ii jj |
+ aa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] [Preview][+] }|
+ aa bb cc dd ee ff gg hh ii jj |
+ aa^ |
+ {s:aa }{c: }{1: }|
+ {n:bb }{c: }{1: }|
+ {n:cc }{c: }{1: }|
+ {n:dd }{c: }{1: }|
+ {n:ee }{c: }{1: }|
+ {n:ff }{c: }{1: }|
+ {n:gg }{s: }{1: }|
+ {n:hh }{s: }{4: }|
+ {2:-- }{5:match 1 of 10} |
+ ]])
+ end
+ end)
+
+ it('with preview-window below', function()
+ feed(':ped<CR><c-w>4+<c-w>r')
+ feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
+ feed('<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {4:[No Name] [+] }|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ {3:[No Name] [Preview][+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aa bb cc dd ee ff gg hh ii jj |
+ aa^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 10} |
+ ## grid 4
+ aa bb cc dd ee ff gg hh ii jj |
+ aa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 5
+ {s:aa }{c: }|
+ {n:bb }{c: }|
+ {n:cc }{c: }|
+ {n:dd }{c: }|
+ {n:ee }{c: }|
+ {n:ff }{c: }|
+ {n:gg }{s: }|
+ {n:hh }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 2, 2, 0, false, 100};
+ }}
+ else
+ screen:expect([[
+ aa bb cc dd ee ff gg hh ii jj |
+ aa^ |
+ {s:aa }{c: }{1: }|
+ {n:bb }{c: }{1: }|
+ {n:cc }{c: }{1: }|
+ {n:dd }{c: }{1: }|
+ {n:ee }{c: }{1: }|
+ {n:ff }{c: }{1: }|
+ {n:gg }{s: }{1: }|
+ {n:hh }{s: }{4: }|
+ aa bb cc dd ee ff gg hh ii jj |
+ aa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] [Preview][+] }|
+ {2:-- }{5:match 1 of 10} |
+ ]])
+ end
+ end)
+
+ it('with preview-window above and tall and inverted', function()
+ feed(':ped<CR><c-w>8+')
+ feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
+ feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
+ feed('kk<cr>ll<cr>mm<cr>nn<cr>oo<cr>')
+ feed('<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ {3:[No Name] [Preview][+] }|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ ii |
+ jj |
+ kk |
+ ll |
+ mm |
+ nn |
+ oo |
+ aa^ |
+ ## grid 3
+ {2:-- }{5:match 1 of 15} |
+ ## grid 4
+ aa |
+ bb |
+ cc |
+ dd |
+ ## grid 5
+ {s:aa }{c: }|
+ {n:bb }{c: }|
+ {n:cc }{c: }|
+ {n:dd }{c: }|
+ {n:ee }{c: }|
+ {n:ff }{c: }|
+ {n:gg }{c: }|
+ {n:hh }{c: }|
+ {n:ii }{c: }|
+ {n:jj }{c: }|
+ {n:kk }{c: }|
+ {n:ll }{s: }|
+ {n:mm }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "SW", 2, 12, 0, false, 100};
+ }}
+ else
+ screen:expect([[
+ aa |
+ bb |
+ cc |
+ dd |
+ {s:aa }{c: }{3:ew][+] }|
+ {n:bb }{c: } |
+ {n:cc }{c: } |
+ {n:dd }{c: } |
+ {n:ee }{c: } |
+ {n:ff }{c: } |
+ {n:gg }{c: } |
+ {n:hh }{c: } |
+ {n:ii }{c: } |
+ {n:jj }{c: } |
+ {n:kk }{c: } |
+ {n:ll }{s: } |
+ {n:mm }{s: } |
+ aa^ |
+ {4:[No Name] [+] }|
+ {2:-- }{5:match 1 of 15} |
+ ]])
+ end
+ end)
+
+ it('with preview-window above and short and inverted', function()
+ feed(':ped<CR><c-w>4+')
+ feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
+ feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
+ feed('<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ {3:[No Name] [Preview][+] }|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ ii |
+ jj |
+ aa^ |
+ ## grid 3
+ {2:-- }{5:match 1 of 10} |
+ ## grid 4
+ aa |
+ bb |
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ ## grid 5
+ {s:aa }{c: }|
+ {n:bb }{c: }|
+ {n:cc }{c: }|
+ {n:dd }{c: }|
+ {n:ee }{c: }|
+ {n:ff }{c: }|
+ {n:gg }{c: }|
+ {n:hh }{c: }|
+ {n:ii }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "SW", 2, 8, 0, false, 100};
+ }}
+ else
+ screen:expect([[
+ aa |
+ bb |
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ {s:aa }{c: }{3:ew][+] }|
+ {n:bb }{c: } |
+ {n:cc }{c: } |
+ {n:dd }{c: } |
+ {n:ee }{c: } |
+ {n:ff }{c: } |
+ {n:gg }{c: } |
+ {n:hh }{c: } |
+ {n:ii }{s: } |
+ aa^ |
+ {4:[No Name] [+] }|
+ {2:-- }{5:match 1 of 10} |
+ ]])
+ end
+ end)
- it('does not crash when displayed in the last column with rightleft (#12032)', function()
- local col = 30
- local items = {'word', 'choice', 'text', 'thing'}
- local max_len = 0
- for _, v in ipairs(items) do
- max_len = max_len < #v and #v or max_len
+ it('with preview-window below and inverted', function()
+ feed(':ped<CR><c-w>4+<c-w>r')
+ feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
+ feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
+ feed('<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {4:[No Name] [+] }|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ [4:--------------------------------]|
+ {3:[No Name] [Preview][+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ ii |
+ jj |
+ aa^ |
+ ## grid 3
+ {2:-- }{5:match 1 of 10} |
+ ## grid 4
+ aa |
+ bb |
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ ## grid 5
+ {s:aa }{c: }|
+ {n:bb }{c: }|
+ {n:cc }{c: }|
+ {n:dd }{c: }|
+ {n:ee }{c: }|
+ {n:ff }{c: }|
+ {n:gg }{s: }|
+ {n:hh }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "SW", 2, 8, 0, false, 100};
+ }}
+ else
+ screen:expect([[
+ {s:aa }{c: } |
+ {n:bb }{c: } |
+ {n:cc }{c: } |
+ {n:dd }{c: } |
+ {n:ee }{c: } |
+ {n:ff }{c: } |
+ {n:gg }{s: } |
+ {n:hh }{s: } |
+ aa^ |
+ {4:[No Name] [+] }|
+ aa |
+ bb |
+ cc |
+ dd |
+ ee |
+ ff |
+ gg |
+ hh |
+ {3:[No Name] [Preview][+] }|
+ {2:-- }{5:match 1 of 10} |
+ ]])
+ end
+ end)
+
+ if not multigrid then
+ -- oldtest: Test_pum_with_preview_win()
+ it('preview window opened during completion', function()
+ exec([[
+ funct Omni_test(findstart, base)
+ if a:findstart
+ return col(".") - 1
+ endif
+ return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
+ endfunc
+ set omnifunc=Omni_test
+ set completeopt+=longest
+ ]])
+ feed('Gi<C-X><C-O>')
+ screen:expect([[
+ ^ |
+ {n:one }{1: }|
+ {n:two }{1: }|
+ {n:three }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- }{8:Back at original} |
+ ]])
+ feed('<C-N>')
+ screen:expect([[
+ 1info |
+ |
+ {1:~ }|
+ {3:[Scratch] [Preview] }|
+ one^ |
+ {s:one }{1: }|
+ {n:two }{1: }|
+ {n:three }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4:[No Name] [+] }|
+ {2:-- }{5:match 1 of 3} |
+ ]])
+ end)
+
+ -- oldtest: Test_scrollbar_on_wide_char()
+ it('scrollbar overwrites half of double-width char below properly', function()
+ screen:try_resize(32, 10)
+ exec([[
+ call setline(1, ['a', ' 啊啊啊',
+ \ ' 哦哦哦',
+ \ ' 呃呃呃'])
+ call setline(5, range(10)->map({i, v -> 'aa' .. v .. 'bb'}))
+ ]])
+ feed('A<C-X><C-N>')
+ screen:expect([[
+ aa0bb^ |
+ {s:aa0bb }{c: }啊 |
+ {n:aa1bb }{c: } 哦 |
+ {n:aa2bb }{c: }呃呃 |
+ {n:aa3bb }{c: } |
+ {n:aa4bb }{c: } |
+ {n:aa5bb }{c: } |
+ {n:aa6bb }{s: } |
+ {n:aa7bb }{s: } |
+ {2:-- }{5:match 1 of 10} |
+ ]])
+ end)
end
- screen:try_resize(col, 8)
- command('set rightleft')
- command('call setline(1, repeat(" ", &columns - '..max_len..'))')
- feed('$i')
- funcs.complete(col - max_len, items)
- feed('<c-y>')
- assert_alive()
- end)
- it('truncates double-width character correctly when there is no scrollbar', function()
- screen:try_resize(32,8)
- command('set completeopt+=menuone,noselect')
- feed('i' .. string.rep(' ', 13))
- funcs.complete(14, {'哦哦哦哦哦哦哦哦哦哦'})
- screen:expect([[
- ^ |
- {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
+ it('with vsplits', function()
+ screen:try_resize(32, 8)
+ insert('aaa aab aac\n')
+ feed(':vsplit<cr>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ {4:[No Name] [+] }{3:<Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aaa aab aac|
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :vsplit |
+ ## grid 4
+ aaa aab aac |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]]}
+ else
+ screen:expect([[
+ aaa aab aac │aaa aab aac|
+ ^ │ |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {4:[No Name] [+] }{3:<Name] [+] }|
+ :vsplit |
+ ]])
+ end
+
+ feed('ibbb a<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ [4:--------------------]│[2:-----------]|
+ {4:[No Name] [+] }{3:<Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aaa aab aac|
+ bbb aaa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 3} |
+ ## grid 4
+ aaa aab aac |
+ bbb aaa^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 5
+ {s: aaa }|
+ {n: aab }|
+ {n: aac }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 4, 2, 3, false, 100};
+ }}
+ else
+ screen:expect([[
+ aaa aab aac │aaa aab aac|
+ bbb aaa^ │bbb aaa |
+ {1:~ }{s: aaa }{1: }│{1:~ }|
+ {1:~ }{n: aab }{1: }│{1:~ }|
+ {1:~ }{n: aac }{1: }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {4:[No Name] [+] }{3:<Name] [+] }|
+ {2:-- }{5:match 1 of 3} |
+ ]])
+ end
+
+ feed('<esc><c-w><c-w>oc a<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ {3:<Name] [+] }{4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aaa aab aac |
+ bbb aaa |
+ c aaa^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 3} |
+ ## grid 4
+ aaa aab aac|
+ bbb aaa |
+ c aaa |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 5
+ {s: aaa }|
+ {n: aab }|
+ {n: aac }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 2, 3, 1, false, 100};
+ }}
+ else
+ screen:expect([[
+ aaa aab aac│aaa aab aac |
+ bbb aaa │bbb aaa |
+ c aaa │c aaa^ |
+ {1:~ }│{1:~}{s: aaa }{1: }|
+ {1:~ }│{1:~}{n: aab }{1: }|
+ {1:~ }│{1:~}{n: aac }{1: }|
+ {3:<Name] [+] }{4:[No Name] [+] }|
+ {2:-- }{5:match 1 of 3} |
+ ]])
+ end
+
+ feed('bcdef ccc a<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ {3:<Name] [+] }{4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aaa aab aac |
+ bbb aaa |
+ c aaabcdef ccc aaa^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 4} |
+ ## grid 4
+ aaa aab aac|
+ bbb aaa |
+ c aaabcdef |
+ ccc aaa |
+ {1:~ }|
+ {1:~ }|
+ ## grid 5
+ {s: aaa }|
+ {n: aab }|
+ {n: aac }|
+ {n: aaabcdef}|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 2, 3, 11, false, 100};
+ }}
+ else
+ screen:expect([[
+ aaa aab aac│aaa aab aac |
+ bbb aaa │bbb aaa |
+ c aaabcdef │c aaabcdef ccc aaa^ |
+ ccc aaa │{1:~ }{s: aaa }|
+ {1:~ }│{1:~ }{n: aab }|
+ {1:~ }│{1:~ }{n: aac }|
+ {3:<Name] [+] }{4:[No Name] [}{n: aaabcdef}|
+ {2:-- }{5:match 1 of 4} |
+ ]])
+ end
+
+ feed('\n<c-x><c-n>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ [4:-----------]│[2:--------------------]|
+ {3:<Name] [+] }{4:[No Name] [+] }|
+ [3:--------------------------------]|
+ ## grid 2
+ aaa aab aac |
+ bbb aaa |
+ c aaabcdef ccc aaa |
+ aaa^ |
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- }{5:match 1 of 6} |
+ ## grid 4
+ aaa aab aac|
+ bbb aaa |
+ c aaabcdef |
+ ccc aaa |
+ aaa |
+ {1:~ }|
+ ## grid 5
+ {s: aaa }{c: }|
+ {n: aab }{s: }|
+ {n: aac }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 2, 4, -1, false, 100};
+ }}
+ else
+ screen:expect([[
+ aaa aab aac│aaa aab aac |
+ bbb aaa │bbb aaa |
+ c aaabcdef │c aaabcdef ccc aaa |
+ ccc aaa │aaa^ |
+ aaa {s: aaa }{c: }{1: }|
+ {1:~ }{n: aab }{s: }{1: }|
+ {3:<Name] [+] }{n: aac }{s: }{4: }|
+ {2:-- }{5:match 1 of 6} |
+ ]])
+ end
+ end)
- it('truncates double-width character correctly when there is scrollbar', function()
- screen:try_resize(32,8)
- command('set completeopt+=noselect')
- command('set pumheight=4')
- feed('i' .. string.rep(' ', 12))
- local items = {}
- for _ = 1, 8 do
- table.insert(items, {word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1})
+ if not multigrid then
+ it('with split and scroll', function()
+ screen:try_resize(60,14)
+ command("split")
+ command("set completeopt+=noinsert")
+ command("set mouse=a")
+ insert([[
+ Lorem ipsum dolor sit amet, consectetur
+ adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua.
+ Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex
+ ea commodo consequat. Duis aute irure dolor in
+ reprehenderit in voluptate velit esse cillum
+ dolore eu fugiat nulla pariatur. Excepteur sint
+ occaecat cupidatat non proident, sunt in culpa
+ qui officia deserunt mollit anim id est
+ laborum.
+ ]])
+
+ screen:expect([[
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ laborum. |
+ ^ |
+ {4:[No Name] [+] }|
+ Lorem ipsum dolor sit amet, consectetur |
+ adipisicing elit, sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ {3:[No Name] [+] }|
+ |
+ ]])
+
+ feed('ggOEst <c-x><c-p>')
+ screen:expect([[
+ Est ^ |
+ L{n: sunt }{s: }sit amet, consectetur |
+ a{n: in }{s: }sed do eiusmod tempor |
+ i{n: culpa }{s: }re et dolore magna aliqua. |
+ U{n: qui }{s: }eniam, quis nostrud |
+ e{n: officia }{s: }co laboris nisi ut aliquip ex |
+ {4:[No}{n: deserunt }{s: }{4: }|
+ Est{n: mollit }{s: } |
+ L{n: anim }{s: }sit amet, consectetur |
+ a{n: id }{s: }sed do eiusmod tempor |
+ i{n: est }{s: }re et dolore magna aliqua. |
+ U{n: laborum }{c: }eniam, quis nostrud |
+ {3:[No}{s: Est }{c: }{3: }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ meths.input_mouse('wheel', 'down', '', 0, 9, 40)
+ screen:expect([[
+ Est ^ |
+ L{n: sunt }{s: }sit amet, consectetur |
+ a{n: in }{s: }sed do eiusmod tempor |
+ i{n: culpa }{s: }re et dolore magna aliqua. |
+ U{n: qui }{s: }eniam, quis nostrud |
+ e{n: officia }{s: }co laboris nisi ut aliquip ex |
+ {4:[No}{n: deserunt }{s: }{4: }|
+ i{n: mollit }{s: }re et dolore magna aliqua. |
+ U{n: anim }{s: }eniam, quis nostrud |
+ e{n: id }{s: }co laboris nisi ut aliquip ex |
+ e{n: est }{s: }at. Duis aute irure dolor in |
+ r{n: laborum }{c: }oluptate velit esse cillum |
+ {3:[No}{s: Est }{c: }{3: }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ feed('e')
+ screen:expect([[
+ Est e^ |
+ L{n: elit } sit amet, consectetur |
+ a{n: eiusmod } sed do eiusmod tempor |
+ i{n: et }ore et dolore magna aliqua. |
+ U{n: enim }veniam, quis nostrud |
+ e{n: exercitation }mco laboris nisi ut aliquip ex |
+ {4:[No}{n: ex }{4: }|
+ i{n: ea }ore et dolore magna aliqua. |
+ U{n: esse }veniam, quis nostrud |
+ e{n: eu }mco laboris nisi ut aliquip ex |
+ e{s: est }uat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ meths.input_mouse('wheel', 'up', '', 0, 9, 40)
+ screen:expect([[
+ Est e^ |
+ L{n: elit } sit amet, consectetur |
+ a{n: eiusmod } sed do eiusmod tempor |
+ i{n: et }ore et dolore magna aliqua. |
+ U{n: enim }veniam, quis nostrud |
+ e{n: exercitation }mco laboris nisi ut aliquip ex |
+ {4:[No}{n: ex }{4: }|
+ Est{n: ea } |
+ L{n: esse } sit amet, consectetur |
+ a{n: eu } sed do eiusmod tempor |
+ i{s: est }ore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ feed('s')
+ screen:expect([[
+ Est es^ |
+ L{n: esse } sit amet, consectetur |
+ a{s: est } sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ {4:[No Name] [+] }|
+ Est es |
+ Lorem ipsum dolor sit amet, consectetur |
+ adipisicing elit, sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ meths.input_mouse('wheel', 'down', '', 0, 9, 40)
+ screen:expect([[
+ Est es^ |
+ L{n: esse } sit amet, consectetur |
+ a{s: est } sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ {4:[No Name] [+] }|
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ ea commodo consequat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ feed('<bs>')
+ screen:expect([[
+ Est e^ |
+ L{n: elit } sit amet, consectetur |
+ a{n: eiusmod } sed do eiusmod tempor |
+ i{n: et }ore et dolore magna aliqua. |
+ U{n: enim }veniam, quis nostrud |
+ e{n: exercitation }mco laboris nisi ut aliquip ex |
+ {4:[No}{n: ex }{4: }|
+ i{n: ea }ore et dolore magna aliqua. |
+ U{n: esse }veniam, quis nostrud |
+ e{n: eu }mco laboris nisi ut aliquip ex |
+ e{s: est }uat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} |
+ ]])
+
+ feed('<c-p>')
+ screen:expect([[
+ Est eu^ |
+ L{n: elit } sit amet, consectetur |
+ a{n: eiusmod } sed do eiusmod tempor |
+ i{n: et }ore et dolore magna aliqua. |
+ U{n: enim }veniam, quis nostrud |
+ e{n: exercitation }mco laboris nisi ut aliquip ex |
+ {4:[No}{n: ex }{4: }|
+ i{n: ea }ore et dolore magna aliqua. |
+ U{n: esse }veniam, quis nostrud |
+ e{s: eu }mco laboris nisi ut aliquip ex |
+ e{n: est }uat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} |
+ ]])
+
+ meths.input_mouse('wheel', 'down', '', 0, 9, 40)
+ screen:expect([[
+ Est eu^ |
+ L{n: elit } sit amet, consectetur |
+ a{n: eiusmod } sed do eiusmod tempor |
+ i{n: et }ore et dolore magna aliqua. |
+ U{n: enim }veniam, quis nostrud |
+ e{n: exercitation }mco laboris nisi ut aliquip ex |
+ {4:[No}{n: ex }{4: }|
+ e{n: ea }uat. Duis aute irure dolor in |
+ r{n: esse }voluptate velit esse cillum |
+ d{s: eu }nulla pariatur. Excepteur sint |
+ o{n: est }t non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} |
+ ]])
+
+ funcs.complete(4, {'ea', 'eeeeeeeeeeeeeeeeee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö'})
+ screen:expect([[
+ Est eu^ |
+ {s: ea }t amet, consectetur |
+ {n: eeeeeeeeeeeeeeeeee }d do eiusmod tempor |
+ {n: ei } et dolore magna aliqua. |
+ {n: eo }iam, quis nostrud |
+ {n: eu } laboris nisi ut aliquip ex |
+ {4:[N}{n: ey }{4: }|
+ {n: eå }. Duis aute irure dolor in |
+ {n: eä }uptate velit esse cillum |
+ {n: eö }la pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- Keyword Local completion (^N^P) }{5:match 1 of 9} |
+ ]])
+
+ funcs.complete(4, {'ea', 'eee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö'})
+ screen:expect([[
+ Est eu^ |
+ {s: ea }r sit amet, consectetur |
+ {n: eee }, sed do eiusmod tempor |
+ {n: ei }bore et dolore magna aliqua. |
+ {n: eo } veniam, quis nostrud |
+ {n: eu }amco laboris nisi ut aliquip ex |
+ {4:[N}{n: ey }{4: }|
+ {n: eå }quat. Duis aute irure dolor in |
+ {n: eä } voluptate velit esse cillum |
+ {n: eö } nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-n>')
+ screen:expect([[
+ Esteee^ |
+ {n: ea }r sit amet, consectetur |
+ {s: eee }, sed do eiusmod tempor |
+ {n: ei }bore et dolore magna aliqua. |
+ {n: eo } veniam, quis nostrud |
+ {n: eu }amco laboris nisi ut aliquip ex |
+ {4:[N}{n: ey }{4: }|
+ {n: eå }quat. Duis aute irure dolor in |
+ {n: eä } voluptate velit esse cillum |
+ {n: eö } nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+
+ funcs.complete(6, {'foo', 'bar'})
+ screen:expect([[
+ Esteee^ |
+ Lo{s: foo }sit amet, consectetur |
+ ad{n: bar }sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ {4:[No Name] [+] }|
+ ea commodo consequat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-y>')
+ screen:expect([[
+ Esteefoo^ |
+ Lorem ipsum dolor sit amet, consectetur |
+ adipisicing elit, sed do eiusmod tempor |
+ incididunt ut labore et dolore magna aliqua. |
+ Ut enim ad minim veniam, quis nostrud |
+ exercitation ullamco laboris nisi ut aliquip ex |
+ {4:[No Name] [+] }|
+ ea commodo consequat. Duis aute irure dolor in |
+ reprehenderit in voluptate velit esse cillum |
+ dolore eu fugiat nulla pariatur. Excepteur sint |
+ occaecat cupidatat non proident, sunt in culpa |
+ qui officia deserunt mollit anim id est |
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+ end)
+
+ it('can be moved due to wrap or resize', function()
+ feed('isome long prefix before the ')
+ command("set completeopt+=noinsert,noselect")
+ command("set linebreak")
+ funcs.complete(29, {'word', 'choice', 'text', 'thing'})
+ screen:expect([[
+ some long prefix before the ^ |
+ {1:~ }{n: word }|
+ {1:~ }{n: choice}|
+ {1:~ }{n: text }|
+ {1:~ }{n: thing }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-p>')
+ screen:expect([[
+ some long prefix before the |
+ thing^ |
+ {n:word }{1: }|
+ {n:choice }{1: }|
+ {n:text }{1: }|
+ {s:thing }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-p>')
+ screen:expect([[
+ some long prefix before the text|
+ {1:^~ }{n: word }|
+ {1:~ }{n: choice}|
+ {1:~ }{s: text }|
+ {1:~ }{n: thing }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ screen:try_resize(30,8)
+ screen:expect([[
+ some long prefix before the |
+ text^ |
+ {n:word }{1: }|
+ {n:choice }{1: }|
+ {s:text }{1: }|
+ {n:thing }{1: }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ screen:try_resize(50,8)
+ screen:expect([[
+ some long prefix before the text^ |
+ {1:~ }{n: word }{1: }|
+ {1:~ }{n: choice }{1: }|
+ {1:~ }{s: text }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ screen:try_resize(25,10)
+ screen:expect([[
+ some long prefix before |
+ the text^ |
+ {1:~ }{n: word }{1: }|
+ {1:~ }{n: choice }{1: }|
+ {1:~ }{s: text }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ screen:try_resize(12,5)
+ screen:expect([[
+ some long |
+ prefix |
+ bef{n: word } |
+ tex{n: }^ |
+ {2:-- INSERT --}|
+ ]])
+
+ -- can't draw the pum, but check we don't crash
+ screen:try_resize(12,2)
+ screen:expect([[
+ {1:<<<}t^ |
+ {2:-- INSERT --}|
+ ]])
+
+ -- but state is preserved, pum reappears
+ screen:try_resize(20,8)
+ screen:expect([[
+ some long prefix |
+ before the text^ |
+ {1:~ }{n: word }{1: }|
+ {1:~ }{n: choice }{1: }|
+ {1:~ }{s: text }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end)
+
+ it('with VimResized autocmd', function()
+ feed('isome long prefix before the ')
+ command("set completeopt+=noinsert,noselect")
+ command("autocmd VimResized * redraw!")
+ command("set linebreak")
+ funcs.complete(29, {'word', 'choice', 'text', 'thing'})
+ screen:expect([[
+ some long prefix before the ^ |
+ {1:~ }{n: word }|
+ {1:~ }{n: choice}|
+ {1:~ }{n: text }|
+ {1:~ }{n: thing }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ screen:try_resize(16,10)
+ screen:expect([[
+ some long |
+ prefix before |
+ the ^ |
+ {1:~ }{n: word }|
+ {1:~ }{n: choice }|
+ {1:~ }{n: text }|
+ {1:~ }{n: thing }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end)
+
+ it('with rightleft window', function()
+ command("set rl wildoptions+=pum")
+ feed('isome rightleft ')
+ screen:expect([[
+ ^ tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {2:-- INSERT --} |
+ ]])
+
+ command("set completeopt+=noinsert,noselect")
+ funcs.complete(16, {'word', 'choice', 'text', 'thing'})
+ screen:expect([[
+ ^ tfelthgir emos|
+ {1: }{n: drow }{1: ~}|
+ {1: }{n: eciohc }{1: ~}|
+ {1: }{n: txet }{1: ~}|
+ {1: }{n: gniht }{1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-n>')
+ screen:expect([[
+ ^ drow tfelthgir emos|
+ {1: }{s: drow }{1: ~}|
+ {1: }{n: eciohc }{1: ~}|
+ {1: }{n: txet }{1: ~}|
+ {1: }{n: gniht }{1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-y>')
+ screen:expect([[
+ ^ drow tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {2:-- INSERT --} |
+ ]])
+
+ -- not rightleft on the cmdline
+ feed('<esc>:sign ')
+ screen:expect{grid=[[
+ drow tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ :sign ^ |
+ ]]}
+
+ feed('<tab>')
+ screen:expect{grid=[[
+ drow tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ {1: }{s: define }{1: ~}|
+ {1: }{n: jump }{1: ~}|
+ {1: }{n: list }{1: ~}|
+ {1: }{n: place }{1: ~}|
+ {1: }{n: undefine }{1: ~}|
+ {1: }{n: unplace }{1: ~}|
+ :sign define^ |
+ ]]}
+ end)
end
- funcs.complete(13, items)
- screen:expect([[
- ^ |
- {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
- {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
- {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
- {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
- {1:~ }|
- {1:~ }|
- {2:-- INSERT --} |
- ]])
- end)
- it('supports mousemodel=popup', function()
- screen:try_resize(32, 6)
- exec([[
- call setline(1, 'popup menu test')
- set mouse=a mousemodel=popup
+ it('with rightleft vsplits', function()
+ screen:try_resize(40, 6)
+ command('set rightleft')
+ command('rightbelow vsplit')
+ command('set completeopt+=noinsert,noselect')
+ command('set pumheight=2')
+ feed('isome rightleft ')
+ funcs.complete(16, {'word', 'choice', 'text', 'thing'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ [3:----------------------------------------]|
+ ## grid 2
+ tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ ^ tfelthgir emos|
+ {1: ~}|
+ {1: ~}|
+ {1: ~}|
+ ## grid 5
+ {c: }{n: drow }|
+ {s: }{n: eciohc }|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 4, 1, -11, false, 100};
+ }}
+ else
+ screen:expect([[
+ tfelthgir emos│ ^ tfelthgir emos|
+ {1: }{c: }{n: drow }{1: ~}|
+ {1: }{s: }{n: eciohc }{1: ~}|
+ {1: ~}│{1: ~}|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ feed('<C-E><CR>')
+ funcs.complete(1, {'word', 'choice', 'text', 'thing'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ [3:----------------------------------------]|
+ ## grid 2
+ tfelthgir emos|
+ |
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ tfelthgir emos|
+ ^ |
+ {1: ~}|
+ {1: ~}|
+ ## grid 5
+ {c: }{n: drow}|
+ {s: }{n: eciohc}|
+ ]], float_pos={
+ [5] = {{id = -1}, "NW", 4, 2, 4, false, 100};
+ }}
+ else
+ screen:expect([[
+ tfelthgir emos│ tfelthgir emos|
+ │ ^ |
+ {1: ~}│{1: }{c: }{n: drow}|
+ {1: ~}│{1: }{s: }{n: eciohc}|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ feed('<C-E>')
+ async_meths.call_function('input', {'', '', 'sign'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ [3:----------------------------------------]|
+ ## grid 2
+ tfelthgir emos|
+ |
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ ^ |
+ ## grid 4
+ tfelthgir emos|
+ |
+ {1: ~}|
+ {1: ~}|
+ ]]}
+ else
+ screen:expect([[
+ tfelthgir emos│ tfelthgir emos|
+ │ |
+ {1: ~}│{1: ~}|
+ {1: ~}│{1: ~}|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ ^ |
+ ]])
+ end
+ command('set wildoptions+=pum')
+ feed('<Tab>')
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ [2:-------------------]│[4:--------------------]|
+ {3:[No Name] [+] }{4:[No Name] [+] }|
+ [3:----------------------------------------]|
+ ## grid 2
+ tfelthgir emos|
+ |
+ {1: ~}|
+ {1: ~}|
+ ## grid 3
+ define^ |
+ ## grid 4
+ tfelthgir emos|
+ |
+ {1: ~}|
+ {1: ~}|
+ ## grid 5
+ {s:define }{c: }|
+ {n:jump }{s: }|
+ ]], float_pos={
+ [5] = {{id = -1}, "SW", 1, 5, 0, false, 250};
+ }}
+ else
+ screen:expect([[
+ tfelthgir emos│ tfelthgir emos|
+ │ |
+ {1: ~}│{1: ~}|
+ {s:define }{c: }{1: ~}│{1: ~}|
+ {n:jump }{s: }{3: }{4:[No Name] [+] }|
+ define^ |
+ ]])
+ end
+ end)
- aunmenu PopUp
- menu PopUp.foo :let g:menustr = 'foo'<CR>
- menu PopUp.bar :let g:menustr = 'bar'<CR>
- menu PopUp.baz :let g:menustr = 'baz'<CR>
- ]])
- feed('<RightMouse><4,0>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- {1:~ }|
- |
- ]])
- feed('<Down>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{s: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- {1:~ }|
- |
- ]])
- feed('<Down>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{s: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- {1:~ }|
- |
- ]])
- feed('<CR>')
- screen:expect([[
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :let g:menustr = 'bar' |
- ]])
- eq('bar', meths.get_var('menustr'))
- feed('<RightMouse><20,1>')
- screen:expect([[
- ^popup menu test |
- {1:~ }|
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- :let g:menustr = 'bar' |
- ]])
- feed('<LeftMouse><22,4>')
- screen:expect([[
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :let g:menustr = 'baz' |
- ]])
- eq('baz', meths.get_var('menustr'))
- feed('<RightMouse><4,0>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- {1:~ }|
- :let g:menustr = 'baz' |
- ]])
- feed('<RightDrag><6,3>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{s: baz }{1: }|
- {1:~ }|
- :let g:menustr = 'baz' |
- ]])
- feed('<RightRelease><6,1>')
- screen:expect([[
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :let g:menustr = 'foo' |
- ]])
- eq('foo', meths.get_var('menustr'))
- eq(false, screen.options.mousemoveevent)
- feed('<RightMouse><4,0>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{n: baz }{1: }|
- {1:~ }|
- :let g:menustr = 'foo' |
- ]])
- eq(true, screen.options.mousemoveevent)
- feed('<MouseMove><6,3>')
- screen:expect([[
- ^popup menu test |
- {1:~ }{n: foo }{1: }|
- {1:~ }{n: bar }{1: }|
- {1:~ }{s: baz }{1: }|
- {1:~ }|
- :let g:menustr = 'foo' |
- ]])
- eq(true, screen.options.mousemoveevent)
- feed('<LeftMouse><6,2>')
- screen:expect([[
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :let g:menustr = 'bar' |
- ]])
- eq(false, screen.options.mousemoveevent)
- eq('bar', meths.get_var('menustr'))
- end)
+ if not multigrid then
+ it('with multiline messages', function()
+ screen:try_resize(40,8)
+ feed('ixx<cr>')
+ command('imap <f2> <cmd>echoerr "very"\\|echoerr "much"\\|echoerr "error"<cr>')
+ funcs.complete(1, {'word', 'choice', 'text', 'thing'})
+ screen:expect([[
+ xx |
+ word^ |
+ {s:word }{1: }|
+ {n:choice }{1: }|
+ {n:text }{1: }|
+ {n:thing }{1: }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<f2>')
+ screen:expect([[
+ xx |
+ word |
+ {s:word }{1: }|
+ {4: }|
+ {6:very} |
+ {6:much} |
+ {6:error} |
+ {5:Press ENTER or type command to continue}^ |
+ ]])
+
+ feed('<cr>')
+ screen:expect([[
+ xx |
+ word^ |
+ {s:word }{1: }|
+ {n:choice }{1: }|
+ {n:text }{1: }|
+ {n:thing }{1: }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-n>')
+ screen:expect([[
+ xx |
+ choice^ |
+ {n:word }{1: }|
+ {s:choice }{1: }|
+ {n:text }{1: }|
+ {n:thing }{1: }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ command("split")
+ screen:expect([[
+ xx |
+ choice^ |
+ {n:word }{1: }|
+ {s:choice }{4: }|
+ {n:text } |
+ {n:thing } |
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]])
+
+ meths.input_mouse('wheel', 'down', '', 0, 6, 15)
+ screen:expect{grid=[[
+ xx |
+ choice^ |
+ {n:word }{1: }|
+ {s:choice }{4: }|
+ {n:text } |
+ {n:thing }{1: }|
+ {3:[No Name] [+] }|
+ {2:-- INSERT --} |
+ ]], unchanged=true}
+ end)
+
+ it('with kind, menu and abbr attributes', function()
+ screen:try_resize(40,8)
+ feed('ixx ')
+ funcs.complete(4, {{word='wordey', kind= 'x', menu='extrainfo'}, 'thing', {word='secret', abbr='sneaky', menu='bar'}})
+ screen:expect([[
+ xx wordey^ |
+ {1:~ }{s: wordey x extrainfo }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }{n: sneaky bar }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-p>')
+ screen:expect([[
+ xx ^ |
+ {1:~ }{n: wordey x extrainfo }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }{n: sneaky bar }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<c-p>')
+ screen:expect([[
+ xx secret^ |
+ {1:~ }{n: wordey x extrainfo }{1: }|
+ {1:~ }{n: thing }{1: }|
+ {1:~ }{s: sneaky bar }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<esc>')
+ screen:expect([[
+ xx secre^t |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end)
+
+ it('wildoptions=pum', function()
+ screen:try_resize(32,10)
+ command('set wildmenu')
+ command('set wildoptions=pum')
+ command('set shellslash')
+ command("cd test/functional/fixtures/wildpum")
+
+ feed(':sign ')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign ^ |
+ ]])
+
+ feed('<Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+
+ feed('<Right><Right>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{s: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign list^ |
+ ]])
+
+ feed('<C-N>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{s: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign place^ |
+ ]])
+
+ feed('<C-P>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{s: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign list^ |
+ ]])
+
+ feed('<Left>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{s: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign jump^ |
+ ]])
+
+ -- pressing <C-E> should end completion and go back to the original match
+ feed('<C-E>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign ^ |
+ ]])
+
+ -- pressing <C-Y> should select the current match and end completion
+ feed('<Tab><C-P><C-P><C-Y>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign unplace^ |
+ ]])
+
+ -- showing popup menu in different columns in the cmdline
+ feed('<C-U>sign define <Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: culhl= }{1: }|
+ {1:~ }{n: icon= }{1: }|
+ {1:~ }{n: linehl= }{1: }|
+ {1:~ }{n: numhl= }{1: }|
+ {1:~ }{n: text= }{1: }|
+ {1:~ }{n: texthl= }{1: }|
+ :sign define culhl=^ |
+ ]])
+
+ feed('<Space><Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: culhl= }{1: }|
+ {1:~ }{n: icon= }{1: }|
+ {1:~ }{n: linehl= }{1: }|
+ {1:~ }{n: numhl= }{1: }|
+ {1:~ }{n: text= }{1: }|
+ {1:~ }{n: texthl= }{1: }|
+ :sign define culhl= culhl=^ |
+ ]])
+
+ feed('<C-U>e Xnamedi<Tab><Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: XdirA/ }{1: }|
+ {1:~ }{n: XfileA }{1: }|
+ :e Xnamedir/XdirA/^ |
+ ]])
+
+ -- Pressing <Down> on a directory name should go into that directory
+ feed('<Down>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: XdirB/ }{1: }|
+ {1:~ }{n: XfileB }{1: }|
+ :e Xnamedir/XdirA/XdirB/^ |
+ ]])
+
+ -- Pressing <Up> on a directory name should go to the parent directory
+ feed('<Up>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: XdirA/ }{1: }|
+ {1:~ }{n: XfileA }{1: }|
+ :e Xnamedir/XdirA/^ |
+ ]])
+
+ -- Pressing <C-A> when the popup menu is displayed should list all the
+ -- matches and remove the popup menu
+ feed(':<C-U>sign <Tab><C-A>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ :sign define jump list place und|
+ efine unplace^ |
+ ]])
+
+ -- Pressing <Left> after that should move the cursor
+ feed('<Left>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ :sign define jump list place und|
+ efine unplac^e |
+ ]])
+ feed('<End>')
+
+ -- Pressing <C-D> when the popup menu is displayed should remove the popup
+ -- menu
+ feed('<C-U>sign <Tab><C-D>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ :sign define |
+ define |
+ :sign define^ |
+ ]])
+
+ -- Pressing <S-Tab> should open the popup menu with the last entry selected
+ feed('<C-U><CR>:sign <S-Tab><C-P>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{s: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign undefine^ |
+ ]])
+
+ -- Pressing <Esc> should close the popup menu and cancel the cmd line
+ feed('<C-U><CR>:sign <Tab><Esc>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+
+ -- Typing a character when the popup is open, should close the popup
+ feed(':sign <Tab>x')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign definex^ |
+ ]])
+
+ -- When the popup is open, entering the cmdline window should close the popup
+ feed('<C-U>sign <Tab><C-F>')
+ screen:expect([[
+ |
+ {3:[No Name] }|
+ {1::}sign define |
+ {1::}sign defin^e |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4:[Command Line] }|
+ :sign define |
+ ]])
+ feed(':q<CR>')
+
+ -- After the last popup menu item, <C-N> should show the original string
+ feed(':sign u<Tab><C-N><C-N>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign u^ |
+ ]])
+
+ -- Use the popup menu for the command name
+ feed('<C-U>bu<Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {s: bufdo }{1: }|
+ {n: buffer }{1: }|
+ {n: buffers }{1: }|
+ {n: bunload }{1: }|
+ :bufdo^ |
+ ]])
+
+ -- Pressing <BS> should remove the popup menu and erase the last character
+ feed('<C-E><C-U>sign <Tab><BS>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign defin^ |
+ ]])
+
+ -- Pressing <C-W> should remove the popup menu and erase the previous word
+ feed('<C-E><C-U>sign <Tab><C-W>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign ^ |
+ ]])
+
+ -- Pressing <C-U> should remove the popup menu and erase the entire line
+ feed('<C-E><C-U>sign <Tab><C-U>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :^ |
+ ]])
+
+ -- Using <C-E> to cancel the popup menu and then pressing <Up> should recall
+ -- the cmdline from history
+ feed('sign xyz<Esc>:sign <Tab><C-E><Up>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign xyz^ |
+ ]])
+
+ feed('<esc>')
+
+ -- Check "list" still works
+ command('set wildmode=longest,list')
+ feed(':cn<Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ :cn |
+ cnewer cnoreabbrev |
+ cnext cnoremap |
+ cnfile cnoremenu |
+ :cn^ |
+ ]])
+ feed('s')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ :cn |
+ cnewer cnoreabbrev |
+ cnext cnoremap |
+ cnfile cnoremenu |
+ :cns^ |
+ ]])
+
+ feed('<esc>')
+ command('set wildmode=full')
+
+ -- Tests a directory name contained full-width characters.
+ feed(':e あいう/<Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: 123 }{1: }|
+ {1:~ }{n: abc }{1: }|
+ {1:~ }{n: xyz }{1: }|
+ :e あいう/123^ |
+ ]])
+ feed('<Esc>')
+
+ -- Pressing <PageDown> should scroll the menu downward
+ feed(':sign <Tab><PageDown>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{s: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign undefine^ |
+ ]])
+ feed('<PageDown>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{s: unplace }{1: }|
+ :sign unplace^ |
+ ]])
+ feed('<PageDown>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign ^ |
+ ]])
+ feed('<PageDown>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+ feed('<C-U>sign <Tab><Right><Right><PageDown>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{s: unplace }{1: }|
+ :sign unplace^ |
+ ]])
+
+ -- Pressing <PageUp> should scroll the menu upward
+ feed('<C-U>sign <Tab><PageUp>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign ^ |
+ ]])
+ feed('<PageUp>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{s: unplace }{1: }|
+ :sign unplace^ |
+ ]])
+ feed('<PageUp>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{s: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign jump^ |
+ ]])
+ feed('<PageUp>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+
+ -- pressing <C-E> to end completion should work in middle of the line too
+ feed('<Esc>:set wildchazz<Left><Left><Tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: wildchar }{1: }|
+ {1:~ }{n: wildcharm }{1: }|
+ :set wildchar^zz |
+ ]])
+ feed('<C-E>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :set wildcha^zz |
+ ]])
+
+ -- pressing <C-Y> should select the current match and end completion
+ feed('<Esc>:set wildchazz<Left><Left><Tab><C-Y>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :set wildchar^zz |
+ ]])
+
+ feed('<Esc>')
+
+ -- check positioning with multibyte char in pattern
+ command("e långfile1")
+ command("sp långfile2")
+ feed(':b lå<tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4:långfile2 }|
+ |
+ {1:~ }|
+ {1:~ }{s: långfile1 }{1: }|
+ {3:lå}{n: långfile2 }{3: }|
+ :b långfile1^ |
+ ]])
+
+ -- check doesn't crash on screen resize
+ screen:try_resize(20,6)
+ screen:expect([[
+ |
+ {1:~ }|
+ {4:långfile2 }|
+ {s: långfile1 } |
+ {3:lå}{n: långfile2 }{3: }|
+ :b långfile1^ |
+ ]])
+
+ screen:try_resize(50,15)
+ screen:expect([[
+ |
+ {1:~ }|
+ {4:långfile2 }|
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: långfile1 }{1: }|
+ {3:lå}{n: långfile2 }{3: }|
+ :b långfile1^ |
+ ]])
+
+ -- position is calculated correctly with "longest"
+ feed('<esc>')
+ command('set wildmode=longest:full,full')
+ feed(':b lå<tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {4:långfile2 }|
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: långfile1 }{1: }|
+ {3:lå}{n: långfile2 }{3: }|
+ :b långfile^ |
+ ]])
+
+ feed('<esc>')
+ command("close")
+ command('set wildmode=full')
+
+ -- special case: when patterns ends with "/", show menu items aligned
+ -- after the "/"
+ feed(':e compdir/<tab>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: file1 }{1: }|
+ {1:~ }{n: file2 }{1: }|
+ :e compdir/file1^ |
+ ]])
+ end)
+
+ it('wildoptions=pum with scrolled messages', function()
+ screen:try_resize(40,10)
+ command('set wildmenu')
+ command('set wildoptions=pum')
+
+ feed(':echoerr "fail"|echoerr "error"<cr>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ {6:fail} |
+ {6:error} |
+ {5:Press ENTER or type command to continue}^ |
+ ]]}
+
+ feed(':sign <tab>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {4: }{n: place }{4: }|
+ {6:fail} {n: undefine } |
+ {6:error}{n: unplace } |
+ :sign define^ |
+ ]]}
+
+ feed('d')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {4: }|
+ {6:fail} |
+ {6:error} |
+ :sign defined^ |
+ ]]}
+ end)
+
+ it('wildoptions=pum and wildmode=longest,full #11622', function()
+ screen:try_resize(30,8)
+ command('set wildmenu')
+ command('set wildoptions=pum')
+ command('set wildmode=longest,full')
+
+ -- With 'wildmode' set to 'longest,full', completing a match should display
+ -- the longest match, the wildmenu should not be displayed.
+ feed(':sign u<Tab>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :sign un^ |
+ ]]}
+ eq(0, funcs.wildmenumode())
+
+ -- pressing <Tab> should display the wildmenu
+ feed('<Tab>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign undefine^ |
+ ]]}
+ eq(1, funcs.wildmenumode())
+
+ -- pressing <Tab> second time should select the next entry in the menu
+ feed('<Tab>')
+ screen:expect{grid=[[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{s: unplace }{1: }|
+ :sign unplace^ |
+ ]]}
+ end)
+
+ it('wildoptions=pum with a wrapped line in buffer vim-patch:8.2.4655', function()
+ screen:try_resize(32, 10)
+ meths.buf_set_lines(0, 0, -1, true, { ('a'):rep(100) })
+ command('set wildoptions+=pum')
+ feed('$')
+ feed(':sign <Tab>')
+ screen:expect([[
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaa {s: define } |
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+ end)
+
+ -- oldtest: Test_wildmenu_pum_odd_wildchar()
+ it('wildoptions=pum with odd wildchar', function()
+ screen:try_resize(30, 10)
+ -- Test odd wildchar interactions with pum. Make sure they behave properly
+ -- and don't lead to memory corruption due to improperly cleaned up memory.
+ exec([[
+ set wildoptions=pum
+ set wildchar=<C-E>
+ ]])
+
+ feed(':sign <C-E>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+
+ -- <C-E> being a wildchar takes priority over its original functionality
+ feed('<C-E>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: define }{1: }|
+ {1:~ }{s: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign jump^ |
+ ]])
+
+ feed('<Esc>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+
+ -- Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
+ -- command-line, and we need to make sure to clean up properly.
+ command('set wildchar=<Esc>')
+ feed(':sign <Esc>')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+
+ feed('<Esc>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+
+ -- <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
+ -- and we again need to make sure we clean up properly.
+ command([[set wildchar=<C-\>]])
+ feed([[:sign <C-\><C-\>]])
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{s: define }{1: }|
+ {1:~ }{n: jump }{1: }|
+ {1:~ }{n: list }{1: }|
+ {1:~ }{n: place }{1: }|
+ {1:~ }{n: undefine }{1: }|
+ {1:~ }{n: unplace }{1: }|
+ :sign define^ |
+ ]])
+
+ feed('<C-N>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end)
+ end
- -- oldtest: Test_popup_command_dump()
- it(':popup command', function()
- exec([[
- func ChangeMenu()
- aunmenu PopUp.&Paste
- nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
- echomsg 'changed'
- return "\<Ignore>"
- endfunc
-
- let lines =<< trim END
- one two three four five
- and one two Xthree four five
- one more two three four five
- END
- call setline(1, lines)
-
- aunmenu *
- source $VIMRUNTIME/menu.vim
- ]])
- feed('/X<CR>:popup PopUp<CR>')
- screen:expect([[
- one two three four five |
- and one two {7:^X}three four five |
- one more tw{n: Undo } |
- {1:~ }{n: }{1: }|
- {1:~ }{n: Paste }{1: }|
- {1:~ }{n: }{1: }|
- {1:~ }{n: Select Word }{1: }|
- {1:~ }{n: Select Sentence }{1: }|
- {1:~ }{n: Select Paragraph }{1: }|
- {1:~ }{n: Select Line }{1: }|
- {1:~ }{n: Select Block }{1: }|
- {1:~ }{n: Select All }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :popup PopUp |
- ]])
+ it("'pumheight'", function()
+ screen:try_resize(32,8)
+ feed('isome long prefix before the ')
+ command("set completeopt+=noinsert,noselect")
+ command("set linebreak")
+ command("set pumheight=2")
+ funcs.complete(29, {'word', 'choice', 'text', 'thing'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ some long prefix before the ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ {n: word }{c: }|
+ {n: choice}{s: }|
+ ]], float_pos={
+ [4] = {{id = -1}, "NW", 2, 1, 24, false, 100};
+ }}
+ else
+ screen:expect([[
+ some long prefix before the ^ |
+ {1:~ }{n: word }{c: }|
+ {1:~ }{n: choice}{s: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ end)
- -- go to the Paste entry in the menu
- feed('jj')
- screen:expect([[
- one two three four five |
- and one two {7:^X}three four five |
- one more tw{n: Undo } |
- {1:~ }{n: }{1: }|
- {1:~ }{s: Paste }{1: }|
- {1:~ }{n: }{1: }|
- {1:~ }{n: Select Word }{1: }|
- {1:~ }{n: Select Sentence }{1: }|
- {1:~ }{n: Select Paragraph }{1: }|
- {1:~ }{n: Select Line }{1: }|
- {1:~ }{n: Select Block }{1: }|
- {1:~ }{n: Select All }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :popup PopUp |
- ]])
+ it("'pumwidth'", function()
+ screen:try_resize(32,8)
+ feed('isome long prefix before the ')
+ command("set completeopt+=noinsert,noselect")
+ command("set linebreak")
+ command("set pumwidth=8")
+ funcs.complete(29, {'word', 'choice', 'text', 'thing'})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ some long prefix before the ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ {n: word }|
+ {n: choice}|
+ {n: text }|
+ {n: thing }|
+ ]], float_pos={
+ [4] = {{id = -1}, "NW", 2, 1, 25, false, 100};
+ }}
+ else
+ screen:expect([[
+ some long prefix before the ^ |
+ {1:~ }{n: word }|
+ {1:~ }{n: choice}|
+ {1:~ }{n: text }|
+ {1:~ }{n: thing }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ end)
- -- Select a word
- feed('j')
- screen:expect([[
- one two three four five |
- and one two {7:^X}three four five |
- one more tw{n: Undo } |
- {1:~ }{n: }{1: }|
- {1:~ }{n: Paste }{1: }|
- {1:~ }{n: }{1: }|
- {1:~ }{s: Select Word }{1: }|
- {1:~ }{n: Select Sentence }{1: }|
- {1:~ }{n: Select Paragraph }{1: }|
- {1:~ }{n: Select Line }{1: }|
- {1:~ }{n: Select Block }{1: }|
- {1:~ }{n: Select All }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- :popup PopUp |
- ]])
+ it('does not crash when displayed in the last column with rightleft #12032', function()
+ local col = 30
+ local items = {'word', 'choice', 'text', 'thing'}
+ local max_len = 0
+ for _, v in ipairs(items) do
+ max_len = max_len < #v and #v or max_len
+ end
+ screen:try_resize(col, 8)
+ command('set rightleft')
+ command('call setline(1, repeat(" ", &columns - '..max_len..'))')
+ feed('$i')
+ funcs.complete(col - max_len, items)
+ feed('<c-y>')
+ assert_alive()
+ end)
- feed('<Esc>')
+ it('truncates double-width character correctly without scrollbar', function()
+ screen:try_resize(32, 8)
+ command('set completeopt+=menuone,noselect')
+ feed('i' .. string.rep(' ', 13))
+ funcs.complete(14, {'哦哦哦哦哦哦哦哦哦哦'})
+ if multigrid then
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ {n: 哦哦哦哦哦哦哦哦哦>}|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 12, false, 100}}})
+ else
+ screen:expect([[
+ ^ |
+ {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ end)
- -- Set an <expr> mapping to change a menu entry while it's displayed.
- -- The text should not change but the command does.
- -- Also verify that "changed" shows up, which means the mapping triggered.
- command('nnoremap <expr> <F2> ChangeMenu()')
- feed('/X<CR>:popup PopUp<CR><F2>')
- screen:expect([[
- one two three four five |
- and one two {7:^X}three four five |
- one more tw{n: Undo } |
- {1:~ }{n: }{1: }|
- {1:~ }{n: Paste }{1: }|
- {1:~ }{n: }{1: }|
- {1:~ }{n: Select Word }{1: }|
- {1:~ }{n: Select Sentence }{1: }|
- {1:~ }{n: Select Paragraph }{1: }|
- {1:~ }{n: Select Line }{1: }|
- {1:~ }{n: Select Block }{1: }|
- {1:~ }{n: Select All }{1: }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- changed |
- ]])
+ it('truncates double-width character correctly with scrollbar', function()
+ screen:try_resize(32,8)
+ command('set completeopt+=noselect')
+ command('set pumheight=4')
+ feed('i' .. string.rep(' ', 12))
+ local items = {}
+ for _ = 1, 8 do
+ table.insert(items, {word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1})
+ end
+ funcs.complete(13, items)
+ if multigrid then
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ {2:-- INSERT --} |
+ ## grid 4
+ {n: 哦哦哦哦哦哦哦哦哦>}{c: }|
+ {n: 哦哦哦哦哦哦哦哦哦>}{c: }|
+ {n: 哦哦哦哦哦哦哦哦哦>}{s: }|
+ {n: 哦哦哦哦哦哦哦哦哦>}{s: }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 11, false, 100}}})
+ else
+ screen:expect([[
+ ^ |
+ {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
+ {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
+ {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
+ {1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end
+ end)
- -- Select the Paste entry, executes the changed menu item.
- feed('jj<CR>')
- screen:expect([[
- one two three four five |
- and one two {7:^X}three four five |
- one more two three four five |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- pasted |
- ]])
- end)
-end)
+ it('supports mousemodel=popup', function()
+ screen:try_resize(32, 6)
+ exec([[
+ call setline(1, 'popup menu test')
+ set mouse=a mousemodel=popup
-describe('builtin popupmenu with ui/ext_multigrid', function()
- local screen
- before_each(function()
- clear()
- screen = Screen.new(32, 20)
- screen:attach({ext_multigrid=true})
- screen:set_default_attr_ids({
- -- popup selected item / scrollbar track
- ['s'] = {background = Screen.colors.WebGray},
- -- popup non-selected item
- ['n'] = {background = Screen.colors.LightMagenta},
- -- popup scrollbar knob
- ['c'] = {background = Screen.colors.Grey0},
- [1] = {bold = true, foreground = Screen.colors.Blue},
- [2] = {bold = true},
- [3] = {reverse = true},
- [4] = {bold = true, reverse = true},
- [5] = {bold = true, foreground = Screen.colors.SeaGreen},
- [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
- })
- end)
+ aunmenu PopUp
+ menu PopUp.foo :let g:menustr = 'foo'<CR>
+ menu PopUp.bar :let g:menustr = 'bar'<CR>
+ menu PopUp.baz :let g:menustr = 'baz'<CR>
+ ]])
- it('truncates double-width character correctly when there is no scrollbar', function()
- screen:try_resize(32,8)
- command('set completeopt+=menuone,noselect')
- feed('i' .. string.rep(' ', 13))
- funcs.complete(14, {'哦哦哦哦哦哦哦哦哦哦'})
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- {2:-- INSERT --} |
- ## grid 4
- {n: 哦哦哦哦哦哦哦哦哦>}|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 12, false, 100}}})
- end)
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 2, 0, 4)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ feed('<RightMouse><4,0>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{n: baz }{1: }|
+ {1:~ }|
+ |
+ ]])
+ end
+ feed('<Down>')
+ if multigrid then
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {s: foo }|
+ {n: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{s: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{n: baz }{1: }|
+ {1:~ }|
+ |
+ ]])
+ end
+ feed('<Down>')
+ if multigrid then
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ |
+ ## grid 4
+ {n: foo }|
+ {s: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{s: bar }{1: }|
+ {1:~ }{n: baz }{1: }|
+ {1:~ }|
+ |
+ ]])
+ end
+ feed('<CR>')
+ if multigrid then
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'bar' |
+ ]]})
+ else
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :let g:menustr = 'bar' |
+ ]])
+ end
+ eq('bar', meths.get_var('menustr'))
+
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 2, 2, 20)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'bar' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 3, 19, false, 250}}})
+ else
+ feed('<RightMouse><20,2>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ :let g:menustr = 'b{n: baz } |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 2)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'baz' |
+ ]]})
+ else
+ feed('<LeftMouse><22,5>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :let g:menustr = 'baz' |
+ ]])
+ end
+ eq('baz', meths.get_var('menustr'))
+
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 2, 0, 4)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'baz' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ feed('<RightMouse><4,0>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{n: baz }{1: }|
+ {1:~ }|
+ :let g:menustr = 'baz' |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('right', 'drag', '', 2, 3, 6)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'baz' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {s: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ feed('<RightDrag><6,3>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{s: baz }{1: }|
+ {1:~ }|
+ :let g:menustr = 'baz' |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('right', 'release', '', 2, 1, 6)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'foo' |
+ ]]})
+ else
+ feed('<RightRelease><6,1>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :let g:menustr = 'foo' |
+ ]])
+ end
+ eq('foo', meths.get_var('menustr'))
+
+ eq(false, screen.options.mousemoveevent)
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 2, 0, 4)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'foo' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {n: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ feed('<RightMouse><4,0>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{n: baz }{1: }|
+ {1:~ }|
+ :let g:menustr = 'foo' |
+ ]])
+ end
+ eq(true, screen.options.mousemoveevent)
+ if multigrid then
+ meths.input_mouse('move', '', '', 2, 3, 6)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'foo' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {s: baz }|
+ ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 250}}})
+ else
+ feed('<MouseMove><6,3>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {1:~ }{n: bar }{1: }|
+ {1:~ }{s: baz }{1: }|
+ {1:~ }|
+ :let g:menustr = 'foo' |
+ ]])
+ end
+ eq(true, screen.options.mousemoveevent)
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 2, 2, 6)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'bar' |
+ ]]})
+ else
+ feed('<LeftMouse><6,2>')
+ screen:expect([[
+ ^popup menu test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :let g:menustr = 'bar' |
+ ]])
+ end
+ eq(false, screen.options.mousemoveevent)
+ eq('bar', meths.get_var('menustr'))
+
+ command('set laststatus=0 | botright split')
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 5, 1, 20)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:--------------------------------]|
+ [5:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'bar' |
+ ## grid 4
+ {n: foo }|
+ {n: bar }|
+ {n: baz }|
+ ## grid 5
+ ^popup menu test |
+ {1:~ }|
+ ]], float_pos={[4] = {{id = -1}, "SW", 5, 1, 19, false, 250}}})
+ else
+ feed('<RightMouse><20,4>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }{n: foo }{1: }|
+ {3:[No Name] [+] }{n: bar }{3: }|
+ ^popup menu test {n: baz } |
+ {1:~ }|
+ :let g:menustr = 'bar' |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 2, 2)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:--------------------------------]|
+ [5:--------------------------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'baz' |
+ ## grid 5
+ ^popup menu test |
+ {1:~ }|
+ ]]})
+ else
+ feed('<LeftMouse><22,3>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }|
+ {3:[No Name] [+] }|
+ ^popup menu test |
+ {1:~ }|
+ :let g:menustr = 'baz' |
+ ]])
+ end
+ eq('baz', meths.get_var('menustr'))
+
+ command('set winwidth=1 | rightbelow vsplit')
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 6, 1, 14)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:---------------]│[6:----------------]|
+ [5:---------------]│[6:----------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'baz' |
+ ## grid 4
+ {n: foo}|
+ {n: bar}|
+ {n: baz}|
+ ## grid 5
+ popup menu test|
+ {1:~ }|
+ ## grid 6
+ ^popup menu test |
+ {1:~ }|
+ ]], float_pos={[4] = {{id = -1}, "SW", 6, 1, 12, false, 250}}})
+ else
+ feed('<RightMouse><30,4>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }{n: foo}|
+ {3:[No Name] [+] }{n: bar}|
+ popup menu test│^popup menu t{n: baz}|
+ {1:~ }│{1:~ }|
+ :let g:menustr = 'baz' |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 0, 2)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:---------------]│[6:----------------]|
+ [5:---------------]│[6:----------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'foo' |
+ ## grid 5
+ popup menu test|
+ {1:~ }|
+ ## grid 6
+ ^popup menu test |
+ {1:~ }|
+ ]]})
+ else
+ feed('<LeftMouse><31,1>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }|
+ {3:[No Name] [+] }|
+ popup menu test│^popup menu test |
+ {1:~ }│{1:~ }|
+ :let g:menustr = 'foo' |
+ ]])
+ end
+ eq('foo', meths.get_var('menustr'))
+
+ command('setlocal winbar=WINBAR')
+ if multigrid then
+ meths.input_mouse('right', 'press', '', 6, 1, 14)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:---------------]│[6:----------------]|
+ [5:---------------]│[6:----------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'foo' |
+ ## grid 4
+ {n: foo}|
+ {n: bar}|
+ {n: baz}|
+ ## grid 5
+ popup menu test|
+ {1:~ }|
+ ## grid 6
+ {2:WINBAR }|
+ ^popup menu test |
+ ]], float_pos={[4] = {{id = -1}, "SW", 6, 1, 12, false, 250}}})
+ else
+ feed('<RightMouse><30,4>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }{n: foo}|
+ {3:[No Name] [+] }{n: bar}|
+ popup menu test│{2:WINBAR }{n: baz}|
+ {1:~ }│^popup menu test |
+ :let g:menustr = 'foo' |
+ ]])
+ end
+ if multigrid then
+ meths.input_mouse('left', 'press', '', 4, 1, 2)
+ screen:expect({grid=[[
+ ## grid 1
+ [2:--------------------------------]|
+ [2:--------------------------------]|
+ {3:[No Name] [+] }|
+ [5:---------------]│[6:----------------]|
+ [5:---------------]│[6:----------------]|
+ [3:--------------------------------]|
+ ## grid 2
+ popup menu test |
+ {1:~ }|
+ ## grid 3
+ :let g:menustr = 'bar' |
+ ## grid 5
+ popup menu test|
+ {1:~ }|
+ ## grid 6
+ {2:WINBAR }|
+ ^popup menu test |
+ ]]})
+ else
+ feed('<LeftMouse><31,2>')
+ screen:expect([[
+ popup menu test |
+ {1:~ }|
+ {3:[No Name] [+] }|
+ popup menu test│{2:WINBAR }|
+ {1:~ }│^popup menu test |
+ :let g:menustr = 'bar' |
+ ]])
+ end
+ eq('bar', meths.get_var('menustr'))
+ end)
- it('truncates double-width character correctly when there is scrollbar', function()
- screen:try_resize(32,8)
- command('set completeopt+=noselect')
- command('set pumheight=4')
- feed('i' .. string.rep(' ', 12))
- local items = {}
- for _ = 1, 8 do
- table.insert(items, {word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1})
+ if not multigrid then
+ -- oldtest: Test_popup_command_dump()
+ it(':popup command', function()
+ exec([[
+ func ChangeMenu()
+ aunmenu PopUp.&Paste
+ nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
+ echomsg 'changed'
+ return "\<Ignore>"
+ endfunc
+
+ let lines =<< trim END
+ one two three four five
+ and one two Xthree four five
+ one more two three four five
+ END
+ call setline(1, lines)
+
+ aunmenu *
+ source $VIMRUNTIME/menu.vim
+ ]])
+ feed('/X<CR>:popup PopUp<CR>')
+ screen:expect([[
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more tw{n: Undo } |
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Paste }{1: }|
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Select Word }{1: }|
+ {1:~ }{n: Select Sentence }{1: }|
+ {1:~ }{n: Select Paragraph }{1: }|
+ {1:~ }{n: Select Line }{1: }|
+ {1:~ }{n: Select Block }{1: }|
+ {1:~ }{n: Select All }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :popup PopUp |
+ ]])
+
+ -- go to the Paste entry in the menu
+ feed('jj')
+ screen:expect([[
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more tw{n: Undo } |
+ {1:~ }{n: }{1: }|
+ {1:~ }{s: Paste }{1: }|
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Select Word }{1: }|
+ {1:~ }{n: Select Sentence }{1: }|
+ {1:~ }{n: Select Paragraph }{1: }|
+ {1:~ }{n: Select Line }{1: }|
+ {1:~ }{n: Select Block }{1: }|
+ {1:~ }{n: Select All }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :popup PopUp |
+ ]])
+
+ -- Select a word
+ feed('j')
+ screen:expect([[
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more tw{n: Undo } |
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Paste }{1: }|
+ {1:~ }{n: }{1: }|
+ {1:~ }{s: Select Word }{1: }|
+ {1:~ }{n: Select Sentence }{1: }|
+ {1:~ }{n: Select Paragraph }{1: }|
+ {1:~ }{n: Select Line }{1: }|
+ {1:~ }{n: Select Block }{1: }|
+ {1:~ }{n: Select All }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :popup PopUp |
+ ]])
+
+ feed('<Esc>')
+
+ -- Set an <expr> mapping to change a menu entry while it's displayed.
+ -- The text should not change but the command does.
+ -- Also verify that "changed" shows up, which means the mapping triggered.
+ command('nnoremap <expr> <F2> ChangeMenu()')
+ feed('/X<CR>:popup PopUp<CR><F2>')
+ screen:expect([[
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more tw{n: Undo } |
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Paste }{1: }|
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Select Word }{1: }|
+ {1:~ }{n: Select Sentence }{1: }|
+ {1:~ }{n: Select Paragraph }{1: }|
+ {1:~ }{n: Select Line }{1: }|
+ {1:~ }{n: Select Block }{1: }|
+ {1:~ }{n: Select All }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ changed |
+ ]])
+
+ -- Select the Paste entry, executes the changed menu item.
+ feed('jj<CR>')
+ screen:expect([[
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more two three four five |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ pasted |
+ ]])
+
+ -- Add a window toolbar to the window and check the :popup menu position.
+ command('setlocal winbar=TEST')
+ feed('/X<CR>:popup PopUp<CR>')
+ screen:expect([[
+ {2:TEST }|
+ one two three four five |
+ and one two {7:^X}three four five |
+ one more tw{n: Undo } |
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Paste }{1: }|
+ {1:~ }{n: }{1: }|
+ {1:~ }{n: Select Word }{1: }|
+ {1:~ }{n: Select Sentence }{1: }|
+ {1:~ }{n: Select Paragraph }{1: }|
+ {1:~ }{n: Select Line }{1: }|
+ {1:~ }{n: Select Block }{1: }|
+ {1:~ }{n: Select All }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :popup PopUp |
+ ]])
+
+ feed('<Esc>')
+ end)
+
+ describe('"kind" and "menu"', function()
+ before_each(function()
+ screen:try_resize(30, 8)
+ exec([[
+ func CompleteFunc( findstart, base )
+ if a:findstart
+ return 0
+ endif
+ return {
+ \ 'words': [
+ \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
+ \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
+ \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
+ \]}
+ endfunc
+ set completeopt=menu
+ set completefunc=CompleteFunc
+ ]])
+ end)
+
+ -- oldtest: Test_pum_highlights_default()
+ it('default highlight groups', function()
+ feed('iaw<C-X><C-u>')
+ screen:expect([[
+ aword1^ |
+ {s:aword1 W extra text 1 }{1: }|
+ {n:aword2 W extra text 2 }{1: }|
+ {n:aword3 W extra text 3 }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- }{5:match 1 of 3} |
+ ]])
+ end)
+
+ -- oldtest: Test_pum_highlights_custom()
+ it('custom highlight groups', function()
+ exec([[
+ hi PmenuKind guifg=Red guibg=Magenta
+ hi PmenuKindSel guifg=Red guibg=Grey
+ hi PmenuExtra guifg=White guibg=Magenta
+ hi PmenuExtraSel guifg=Black guibg=Grey
+ ]])
+ local attrs = screen:get_default_attr_ids()
+ attrs.kn = {foreground = Screen.colors.Red, background = Screen.colors.Magenta}
+ attrs.ks = {foreground = Screen.colors.Red, background = Screen.colors.Grey}
+ attrs.xn = {foreground = Screen.colors.White, background = Screen.colors.Magenta}
+ attrs.xs = {foreground = Screen.colors.Black, background = Screen.colors.Grey}
+ feed('iaw<C-X><C-u>')
+ screen:expect([[
+ aword1^ |
+ {s:aword1 }{ks:W }{xs:extra text 1 }{1: }|
+ {n:aword2 }{kn:W }{xn:extra text 2 }{1: }|
+ {n:aword3 }{kn:W }{xn:extra text 3 }{1: }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- }{5:match 1 of 3} |
+ ]], attrs)
+ end)
+ end)
end
- funcs.complete(13, items)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- {2:-- INSERT --} |
- ## grid 4
- {n: 哦哦哦哦哦哦哦哦哦>}{c: }|
- {n: 哦哦哦哦哦哦哦哦哦>}{c: }|
- {n: 哦哦哦哦哦哦哦哦哦>}{s: }|
- {n: 哦哦哦哦哦哦哦哦哦>}{s: }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 11, false, 100}}})
- end)
+ end
- it('supports mousemodel=popup', function()
- screen:try_resize(32, 6)
- exec([[
- call setline(1, 'popup menu test')
- set mouse=a mousemodel=popup
+ describe('with ext_multigrid', function()
+ with_ext_multigrid(true)
+ end)
- aunmenu PopUp
- menu PopUp.foo :let g:menustr = 'foo'<CR>
- menu PopUp.bar :let g:menustr = 'bar'<CR>
- menu PopUp.baz :let g:menustr = 'baz'<CR>
- ]])
- meths.input_mouse('right', 'press', '', 2, 1, 20)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- |
- ## grid 4
- {n: foo }|
- {n: bar }|
- {n: baz }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 2, 19, false, 100}}})
- meths.input_mouse('left', 'press', '', 4, 2, 2)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'baz' |
- ]]})
- eq('baz', meths.get_var('menustr'))
- meths.input_mouse('right', 'press', '', 2, 0, 4)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'baz' |
- ## grid 4
- {n: foo }|
- {n: bar }|
- {n: baz }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
- meths.input_mouse('right', 'drag', '', 2, 3, 6)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'baz' |
- ## grid 4
- {n: foo }|
- {n: bar }|
- {s: baz }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
- meths.input_mouse('right', 'release', '', 2, 1, 6)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'foo' |
- ]]})
- eq('foo', meths.get_var('menustr'))
- eq(false, screen.options.mousemoveevent)
- meths.input_mouse('right', 'press', '', 2, 0, 4)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'foo' |
- ## grid 4
- {n: foo }|
- {n: bar }|
- {n: baz }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
- eq(true, screen.options.mousemoveevent)
- meths.input_mouse('move', '', '', 2, 3, 6)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'foo' |
- ## grid 4
- {n: foo }|
- {n: bar }|
- {s: baz }|
- ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
- eq(true, screen.options.mousemoveevent)
- meths.input_mouse('left', 'press', '', 2, 2, 6)
- screen:expect({grid=[[
- ## grid 1
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [2:--------------------------------]|
- [3:--------------------------------]|
- ## grid 2
- ^popup menu test |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- ## grid 3
- :let g:menustr = 'bar' |
- ]]})
- eq(false, screen.options.mousemoveevent)
- eq('bar', meths.get_var('menustr'))
+ describe('without ext_multigrid', function()
+ with_ext_multigrid(false)
end)
end)
diff --git a/test/functional/ui/quickfix_spec.lua b/test/functional/ui/quickfix_spec.lua
index b0d89ee3b6..df43871e60 100644
--- a/test/functional/ui/quickfix_spec.lua
+++ b/test/functional/ui/quickfix_spec.lua
@@ -27,7 +27,7 @@ describe('quickfix selection highlight', function()
[12] = {foreground = Screen.colors.Brown, background = Screen.colors.Fuchsia},
})
- meths.set_option('errorformat', '%m %l')
+ meths.set_option_value('errorformat', '%m %l', {})
command('syntax on')
command('highlight Search guibg=Green')
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 3b9cce0e6f..810a68d387 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -75,6 +75,7 @@ local busted = require('busted')
local deepcopy = helpers.deepcopy
local shallowcopy = helpers.shallowcopy
local concat_tables = helpers.concat_tables
+local pesc = helpers.pesc
local run_session = helpers.run_session
local eq = helpers.eq
local dedent = helpers.dedent
@@ -87,6 +88,7 @@ local function isempty(v)
return type(v) == 'table' and next(v) == nil
end
+--- @class test.functional.ui.screen
local Screen = {}
Screen.__index = Screen
@@ -149,6 +151,7 @@ function Screen.new(width, height)
msg_grid = nil,
msg_grid_pos = nil,
_session = nil,
+ rpc_async = false,
messages = {},
msg_history = {},
showmode = {},
@@ -172,9 +175,13 @@ function Screen.new(width, height)
_busy = false,
}, Screen)
local function ui(method, ...)
- local status, rv = self._session:request('nvim_ui_'..method, ...)
- if not status then
- error(rv[2])
+ if self.rpc_async then
+ self._session:notify('nvim_ui_'..method, ...)
+ else
+ local status, rv = self._session:request('nvim_ui_'..method, ...)
+ if not status then
+ error(rv[2])
+ end
end
end
self.uimeths = create_callindex(ui)
@@ -214,7 +221,7 @@ function Screen:attach(options, session)
-- simplify test code by doing the same.
self._options.rgb = true
end
- if self._options.ext_multigrid or self._options.ext_float then
+ if self._options.ext_multigrid then
self._options.ext_linegrid = true
end
end
@@ -257,7 +264,7 @@ local ext_keys = {
-- grid: Expected screen state (string). Each line represents a screen
-- row. Last character of each row (typically "|") is stripped.
-- Common indentation is stripped.
--- "{MATCH:x}|" lines are matched against Lua pattern `x`.
+-- "{MATCH:x}" in a line is matched against Lua pattern `x`.
-- attr_ids: Expected text attributes. Screen rows are transformed according
-- to this table, as follows: each substring S composed of
-- characters having the same attributes will be substituted by
@@ -382,8 +389,20 @@ function Screen:expect(expected, attr_ids, ...)
end
for i, row in ipairs(expected_rows) do
msg_expected_rows[i] = row
- local m = (row ~= actual_rows[i] and row:match('{MATCH:(.*)}') or nil)
- if row ~= actual_rows[i] and (not m or not (actual_rows[i] and actual_rows[i]:match(m))) then
+ local pat = nil
+ if actual_rows[i] and row ~= actual_rows[i] then
+ local after = row
+ while true do
+ local s, e, m = after:find('{MATCH:(.-)}')
+ if not s then
+ pat = pat and (pat .. pesc(after))
+ break
+ end
+ pat = (pat or '') .. pesc(after:sub(1, s - 1)) .. m
+ after = after:sub(e + 1)
+ end
+ end
+ if row ~= actual_rows[i] and (not pat or not actual_rows[i]:match(pat)) then
msg_expected_rows[i] = '*' .. msg_expected_rows[i]
if i <= #actual_rows then
actual_rows[i] = '*' .. actual_rows[i]
@@ -470,15 +489,19 @@ screen:redraw_debug() to show all intermediate screen states. ]])
end, expected)
end
-function Screen:expect_unchanged(waittime_ms, ignore_attrs, request_cb)
+function Screen:expect_unchanged(intermediate, waittime_ms, ignore_attrs)
waittime_ms = waittime_ms and waittime_ms or 100
-- Collect the current screen state.
- self:sleep(0, request_cb)
local kwargs = self:get_snapshot(nil, ignore_attrs)
- -- Check that screen state does not change.
- kwargs.unchanged = true
+ if intermediate then
+ kwargs.intermediate = true
+ else
+ kwargs.unchanged = true
+ end
+
kwargs.timeout = waittime_ms
+ -- Check that screen state does not change.
self:expect(kwargs)
end
@@ -540,6 +563,7 @@ function Screen:_wait(check, flags)
self._session:stop()
end
elseif success_seen and #args > 0 then
+ success_seen = false
failure_after_success = true
-- print(inspect(args))
end
@@ -785,14 +809,17 @@ function Screen:_handle_win_pos(grid, win, startrow, startcol, width, height)
self.float_pos[grid] = nil
end
-function Screen:_handle_win_viewport(grid, win, topline, botline, curline, curcol, linecount)
+function Screen:_handle_win_viewport(grid, win, topline, botline, curline, curcol, linecount, scroll_delta)
+ -- accumulate scroll delta
+ local last_scroll_delta = self.win_viewport[grid] and self.win_viewport[grid].sum_scroll_delta or 0
self.win_viewport[grid] = {
win = win,
topline = topline,
botline = botline,
curline = curline,
curcol = curcol,
- linecount = linecount
+ linecount = linecount,
+ sum_scroll_delta = scroll_delta + last_scroll_delta
}
end
@@ -926,6 +953,7 @@ end
function Screen:_handle_grid_line(grid, row, col, items)
assert(self._options.ext_linegrid)
+ assert(#items > 0)
local line = self._grids[grid].rows[row+1]
local colpos = col+1
local hl_id = 0
@@ -1248,7 +1276,7 @@ end
function Screen:render(headers, attr_state, preview)
headers = headers and (self._options.ext_multigrid or self._options._debug_float)
local rv = {}
- for igrid,grid in pairs(self._grids) do
+ for igrid,grid in vim.spairs(self._grids) do
if headers then
local suffix = ""
if igrid > 1 and self.win_position[igrid] == nil
@@ -1330,7 +1358,7 @@ local function fmt_ext_state(name, state)
for k,v in pairs(state) do
str = (str.." ["..k.."] = {win = {id = "..v.win.id.."}, topline = "
..v.topline..", botline = "..v.botline..", curline = "..v.curline
- ..", curcol = "..v.curcol..", linecount = "..v.linecount.."};\n")
+ ..", curcol = "..v.curcol..", linecount = "..v.linecount..", sum_scroll_delta = "..v.sum_scroll_delta.."};\n")
end
return str .. "}"
elseif name == "float_pos" then
diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua
index 3bd2289a73..7cc1accd3f 100644
--- a/test/functional/ui/screen_basic_spec.lua
+++ b/test/functional/ui/screen_basic_spec.lua
@@ -4,9 +4,7 @@ local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.cl
local feed, command = helpers.feed, helpers.command
local insert = helpers.insert
local eq = helpers.eq
-local eval = helpers.eval
-local funcs, meths, exec_lua = helpers.funcs, helpers.meths, helpers.exec_lua
-local is_os = helpers.is_os
+local funcs, meths = helpers.funcs, helpers.meths
describe('screen', function()
local screen
@@ -61,37 +59,10 @@ local function screen_tests(linegrid)
[5] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Fuchsia},
[6] = {bold = true, foreground = Screen.colors.Fuchsia},
[7] = {bold = true, foreground = Screen.colors.SeaGreen},
+ [8] = {foreground = Screen.colors.White, background = Screen.colors.Red},
} )
end)
- describe(':suspend', function()
- it('is forwarded to the UI', function()
- local function check()
- eq(true, screen.suspended)
- end
-
- command('let g:ev = []')
- command('autocmd VimResume * :call add(g:ev, "r")')
- command('autocmd VimSuspend * :call add(g:ev, "s")')
-
- eq(false, screen.suspended)
- command('suspend')
- eq({ 's', 'r' }, eval('g:ev'))
-
- screen:expect(check)
- screen.suspended = false
-
- feed('<c-z>')
- eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
-
- screen:expect(check)
- screen.suspended = false
-
- command('suspend')
- eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
- end)
- end)
-
describe('bell/visual bell', function()
it('is forwarded to the UI', function()
feed('<left>')
@@ -117,78 +88,13 @@ local function screen_tests(linegrid)
screen:expect(function()
eq(expected, screen.title)
end)
- end)
-
- it('has correct default title with unnamed file', function()
- local expected = '[No Name] - NVIM'
- command('set title')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
-
- it('has correct default title with named file', function()
- local expected = (is_os('win') and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM')
- command('set title')
- command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
+ screen:detach()
+ screen.title = nil
+ screen:attach()
screen:expect(function()
eq(expected, screen.title)
end)
end)
-
- describe('is not changed by', function()
- local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
- local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2'
- local expected = (is_os('win') and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM')
- local buf2
-
- before_each(function()
- command('edit '..file1)
- buf2 = funcs.bufadd(file2)
- command('set title')
- end)
-
- it('calling setbufvar() to set an option in a hidden buffer from i_CTRL-R', function()
- command([[inoremap <F2> <C-R>=setbufvar(]]..buf2..[[, '&autoindent', 1) ? '' : ''<CR>]])
- feed('i<F2><Esc>')
- command('redraw!')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
-
- it('an RPC call to nvim_buf_set_option in a hidden buffer', function()
- meths.buf_set_option(buf2, 'autoindent', true)
- command('redraw!')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
-
- it('a Lua callback calling nvim_buf_set_option in a hidden buffer', function()
- exec_lua(string.format([[
- vim.schedule(function()
- vim.api.nvim_buf_set_option(%d, 'autoindent', true)
- end)
- ]], buf2))
- command('redraw!')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
-
- it('a Lua callback calling nvim_buf_call in a hidden buffer', function()
- exec_lua(string.format([[
- vim.schedule(function()
- vim.api.nvim_buf_call(%d, function() end)
- end)
- ]], buf2))
- command('redraw!')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
- end)
end)
describe(':set icon', function()
@@ -199,6 +105,12 @@ local function screen_tests(linegrid)
screen:expect(function()
eq(expected, screen.icon)
end)
+ screen:detach()
+ screen.icon = nil
+ screen:attach()
+ screen:expect(function()
+ eq(expected, screen.icon)
+ end)
end)
end)
@@ -866,12 +778,9 @@ local function screen_tests(linegrid)
end)
describe('resize', function()
- before_each(function()
+ it('rebuilds the whole screen', function()
screen:try_resize(25, 5)
feed('iresize')
- end)
-
- it('rebuilds the whole screen', function()
screen:expect([[
resize^ |
{0:~ }|
@@ -882,10 +791,11 @@ local function screen_tests(linegrid)
end)
it('has minimum width/height values', function()
+ feed('iresize')
screen:try_resize(1, 1)
screen:expect([[
resize^ |
- {2:-- INSERT -} |
+ {2:-- INSERT --}|
]])
feed('<esc>:ls')
@@ -896,11 +806,12 @@ local function screen_tests(linegrid)
end)
it('VimResized autocommand does not cause invalid UI events #20692 #20759', function()
- feed('<Esc>')
+ screen:try_resize(25, 5)
+ feed('iresize<Esc>')
command([[autocmd VimResized * redrawtabline]])
command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]])
command([[autocmd VimResized * let g:echospace = v:echospace]])
- meths.set_option('showtabline', 2)
+ meths.set_option_value('showtabline', 2, {})
screen:expect([[
{2: + [No Name] }{3: }|
resiz^e |
@@ -919,6 +830,77 @@ local function screen_tests(linegrid)
]])
eq(29, meths.get_var('echospace'))
end)
+
+ it('messages from the same Ex command as resize are visible #22225', function()
+ feed(':set columns=20 | call<CR>')
+ screen:expect([[
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ {1: }|
+ {8:E471: Argument requi}|
+ {8:red} |
+ {7:Press ENTER or type }|
+ {7:command to continue}^ |
+ ]])
+ feed('<CR>')
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ feed(':set columns=0<CR>')
+ screen:expect([[
+ |
+ |
+ |
+ |
+ |
+ {1: }|
+ {8:E594: Need a}|
+ {8:t least 12 c}|
+ {8:olumns: colu}|
+ {8:mns=0} |
+ {7:Press ENTER }|
+ {7:or type comm}|
+ {7:and to conti}|
+ {7:nue}^ |
+ ]])
+ feed('<CR>')
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end)
end)
describe('press enter', function()
@@ -1057,8 +1039,8 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
clear()
local screen = Screen.new(100, 100)
screen:attach()
- eq(100, meths.get_option('lines'))
- eq(99, meths.get_option('window'))
+ eq(100, meths.get_option_value('lines', {}))
+ eq(99, meths.get_option_value('window', {}))
eq(99, meths.win_get_height(0))
feed('1000o<Esc>')
eq(903, funcs.line('w0'))
@@ -1072,8 +1054,8 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
eq(903, funcs.line('w0'))
feed('G')
screen:try_resize(50, 50)
- eq(50, meths.get_option('lines'))
- eq(49, meths.get_option('window'))
+ eq(50, meths.get_option_value('lines', {}))
+ eq(49, meths.get_option_value('window', {}))
eq(49, meths.win_get_height(0))
eq(953, funcs.line('w0'))
feed('<C-B>')
@@ -1085,3 +1067,18 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
feed('<C-F>')
eq(953, funcs.line('w0'))
end)
+
+it("showcmd doesn't cause empty grid_line with redrawdebug=compositor #22593", function()
+ clear()
+ local screen = Screen.new(30, 2)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ })
+ screen:attach()
+ command('set showcmd redrawdebug=compositor')
+ feed('d')
+ screen:expect{grid=[[
+ ^ |
+ d |
+ ]]}
+end)
diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua
index 18bbb56a61..dc7ef666bd 100644
--- a/test/functional/ui/searchhl_spec.lua
+++ b/test/functional/ui/searchhl_spec.lua
@@ -10,7 +10,6 @@ local testprg = helpers.testprg
describe('search highlighting', function()
local screen
- local colors = Screen.colors
before_each(function()
clear()
@@ -18,9 +17,10 @@ describe('search highlighting', function()
screen:attach()
screen:set_default_attr_ids( {
[1] = {bold=true, foreground=Screen.colors.Blue},
- [2] = {background = colors.Yellow}, -- Search
+ [2] = {background = Screen.colors.Yellow}, -- Search
[3] = {reverse = true},
- [4] = {foreground = colors.Red}, -- Message
+ [4] = {foreground = Screen.colors.Red}, -- WarningMsg
+ [5] = {bold = true, reverse = true}, -- StatusLine
[6] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey}, -- Folded
})
end)
@@ -53,11 +53,11 @@ describe('search highlighting', function()
{1:~ }|
/text^ |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 9, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 8, linecount = 2, sum_scroll_delta = 0};
}}
end)
- it('works', function()
+ local function test_search_hl()
insert([[
some text
more textstuff
@@ -110,6 +110,26 @@ describe('search highlighting', function()
{1:~ }|
:nohlsearch |
]])
+ end
+
+ it("works when 'winhighlight' is not set", function()
+ test_search_hl()
+ end)
+
+ it("works when 'winhighlight' doesn't change Search highlight", function()
+ command('setlocal winhl=NonText:Underlined')
+ local attrs = screen:get_default_attr_ids()
+ attrs[1] = {foreground = Screen.colors.SlateBlue, underline = true}
+ screen:set_default_attr_ids(attrs)
+ test_search_hl()
+ end)
+
+ it("works when 'winhighlight' changes Search highlight", function()
+ command('setlocal winhl=Search:Underlined')
+ local attrs = screen:get_default_attr_ids()
+ attrs[2] = {foreground = Screen.colors.SlateBlue, underline = true}
+ screen:set_default_attr_ids(attrs)
+ test_search_hl()
end)
describe('CurSearch highlight', function()
@@ -307,18 +327,33 @@ describe('search highlighting', function()
it('is preserved during :terminal activity', function()
feed((':terminal "%s" REP 5000 foo<cr>'):format(testprg('shell-test')))
-
feed(':file term<CR>')
+ screen:expect([[
+ ^0: foo |
+ 1: foo |
+ 2: foo |
+ 3: foo |
+ 4: foo |
+ 5: foo |
+ :file term |
+ ]])
+
feed('G') -- Follow :terminal output.
feed(':vnew<CR>')
insert([[
foo bar baz
bar baz foo
- bar foo baz
- ]])
+ bar foo baz]])
feed('/foo')
- helpers.poke_eventloop()
- screen:expect_unchanged()
+ screen:expect([[
+ {3:foo} bar baz │{MATCH:%d+}: {2:foo}{MATCH:%s+}|
+ bar baz {2:foo} │{MATCH:%d+}: {2:foo}{MATCH:%s+}|
+ bar {2:foo} baz │{MATCH:%d+}: {2:foo}{MATCH:%s+}|
+ {1:~ }│{MATCH:.*}|
+ {1:~ }│{MATCH:.*}|
+ {5:[No Name] [+] }{3:term }|
+ /foo^ |
+ ]])
end)
it('works with incsearch', function()
@@ -498,6 +533,50 @@ describe('search highlighting', function()
{1:~ }│{1:~ }|
//^ |
]])
+ feed('<Esc>')
+
+ -- incsearch works after c_CTRL-R_CTRL-R
+ command('let @" = "file"')
+ feed('/<C-R><C-R>"')
+ screen:expect([[
+ the first line │the first line |
+ in a little {3:file} │in a little {2:file} |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ /file^ |
+ ]])
+ feed('<Esc>')
+
+ command('set rtp^=test/functional/fixtures')
+ -- incsearch works after c_CTRL-R inserts clipboard register
+
+ command('let @* = "first"')
+ feed('/<C-R>*')
+ screen:expect([[
+ the {3:first} line │the {2:first} line |
+ in a little file │in a little file |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ /first^ |
+ ]])
+ feed('<Esc>')
+
+ command('let @+ = "little"')
+ feed('/<C-R>+')
+ screen:expect([[
+ the first line │the first line |
+ in a {3:little} file │in a {2:little} file |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ /little^ |
+ ]])
+ feed('<Esc>')
end)
it('works with incsearch and offset', function()
@@ -572,12 +651,12 @@ describe('search highlighting', function()
it('works with matchadd and syntax', function()
screen:set_default_attr_ids {
[1] = {bold=true, foreground=Screen.colors.Blue};
- [2] = {background = colors.Yellow};
+ [2] = {background = Screen.colors.Yellow};
[3] = {reverse = true};
- [4] = {foreground = colors.Red};
- [5] = {bold = true, background = colors.Green};
- [6] = {italic = true, background = colors.Magenta};
- [7] = {bold = true, background = colors.Yellow};
+ [4] = {foreground = Screen.colors.Red};
+ [5] = {bold = true, background = Screen.colors.Green};
+ [6] = {italic = true, background = Screen.colors.Magenta};
+ [7] = {bold = true, background = Screen.colors.Yellow};
[8] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGray};
}
feed_command('set hlsearch')
@@ -602,7 +681,7 @@ describe('search highlighting', function()
{1:~ }|
{4:search hit BOTTOM, continuing at TOP} |
]], win_viewport={
- [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 11, linecount = 2};
+ [2] = {win = {id = 1000}, topline = 0, botline = 3, curline = 0, curcol = 11, linecount = 2, sum_scroll_delta = 0};
}}
-- check highlights work also in folds
diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua
index 7dcd4cff25..b12e79bd42 100644
--- a/test/functional/ui/sign_spec.lua
+++ b/test/functional/ui/sign_spec.lua
@@ -274,9 +274,9 @@ describe('Signs', function()
-- Line 3 checks that with a limit over the maximum number
-- of signs, the ones with the highest Ids are being picked,
-- and presented by their sorted Id order.
- command('sign place 4 line=3 name=pietSearch buffer=1')
- command('sign place 5 line=3 name=pietWarn buffer=1')
- command('sign place 3 line=3 name=pietError buffer=1')
+ command('sign place 6 line=3 name=pietSearch buffer=1')
+ command('sign place 7 line=3 name=pietWarn buffer=1')
+ command('sign place 5 line=3 name=pietError buffer=1')
screen:expect([[
{1:>>}{8:XX}{6: 1 }a |
{8:XX}{1:>>}{6: 2 }b |
@@ -467,6 +467,27 @@ describe('Signs', function()
{0:~ }|
|
]])
+ -- should not increase size because sign with existing id is moved
+ command('sign place 4 line=1 name=pietSearch buffer=1')
+ screen:expect_unchanged()
+ command('sign unplace 4')
+ screen:expect([[
+ {1:>>>>>>}{6: 1 }a |
+ {2: }{6: 2 }b |
+ {2: }{6: 3 }c |
+ {2: }{6: 4 }^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ command('sign place 4 line=1 name=pietSearch buffer=1')
-- should keep the column at maximum size when signs are
-- exceeding the maximum
command('sign place 5 line=1 name=pietSearch buffer=1')
@@ -685,4 +706,21 @@ describe('Signs', function()
|
]])
end)
+
+ it('numhl highlight is applied when signcolumn=no', function()
+ screen:try_resize(screen._width, 4)
+ command([[
+ set nu scl=no
+ call setline(1, ['line1', 'line2', 'line3'])
+ call nvim_buf_set_extmark(0, nvim_create_namespace('test'), 0, 0, {'number_hl_group':'Error'})
+ call sign_define('foo', { 'text':'F', 'numhl':'Error' })
+ call sign_place(0, '', 'foo', bufnr(''), { 'lnum':2 })
+ ]])
+ screen:expect([[
+ {8: 1 }^line1 |
+ {8: 2 }line2 |
+ {6: 3 }line3 |
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua
index 361f83d1ce..d18e19e5b2 100644
--- a/test/functional/ui/spell_spec.lua
+++ b/test/functional/ui/spell_spec.lua
@@ -3,9 +3,11 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local exec = helpers.exec
local feed = helpers.feed
local insert = helpers.insert
-local command = helpers.command
+local meths = helpers.meths
+local curbufmeths = helpers.curbufmeths
local is_os = helpers.is_os
describe("'spell'", function()
@@ -18,17 +20,21 @@ describe("'spell'", function()
screen:set_default_attr_ids( {
[0] = {bold=true, foreground=Screen.colors.Blue},
[1] = {special = Screen.colors.Red, undercurl = true},
- [2] = {special = Screen.colors.Blue1, undercurl = true},
+ [2] = {special = Screen.colors.Blue, undercurl = true},
[3] = {foreground = tonumber('0x6a0dad')},
[4] = {foreground = Screen.colors.Magenta},
[5] = {bold = true, foreground = Screen.colors.SeaGreen},
[6] = {foreground = Screen.colors.Red},
+ [7] = {foreground = Screen.colors.Blue},
+ [8] = {foreground = Screen.colors.Blue, special = Screen.colors.Red, undercurl = true},
+ [9] = {bold = true},
+ [10] = {background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue},
})
end)
it('joins long lines #7937', function()
if is_os('openbsd') then pending('FIXME #12104', function() end) return end
- command('set spell')
+ exec('set spell')
insert([[
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
@@ -53,114 +59,374 @@ describe("'spell'", function()
-- oldtest: Test_spell_screendump()
it('has correct highlight at start of line', function()
- insert([[
- "This is some text without any spell errors. Everything",
- "should just be black, nothing wrong here.",
- "",
- "This line has a sepll error. and missing caps.",
- "And and this is the the duplication.",
- "with missing caps here.",
- ]])
- command('set spell spelllang=en_nz')
- screen:expect([[
- "This is some text without any spell errors. Everything", |
- "should just be black, nothing wrong here.", |
- "", |
- "This line has a {1:sepll} error. {2:and} missing caps.", |
- "{1:And and} this is {1:the the} duplication.", |
- "with missing caps here.", |
- ^ |
- |
+ exec([=[
+ call setline(1, [
+ \"This is some text without any spell errors. Everything",
+ \"should just be black, nothing wrong here.",
+ \"",
+ \"This line has a sepll error. and missing caps.",
+ \"And and this is the the duplication.",
+ \"with missing caps here.",
+ \])
+ set spell spelllang=en_nz
+ ]=])
+ screen:expect([[
+ ^This is some text without any spell errors. Everything |
+ should just be black, nothing wrong here. |
+ |
+ This line has a {1:sepll} error. {2:and} missing caps. |
+ {1:And and} this is {1:the the} duplication. |
+ {2:with} missing caps here. |
+ {0:~ }|
+ |
]])
end)
- it('"noplainbuffer" and syntax #20385', function()
- command('set filetype=c')
- command('syntax on')
- command('set spell')
+ -- oldtest: Test_spell_screendump_spellcap()
+ it('SpellCap highlight at start of line', function()
+ exec([=[
+ call setline(1, [
+ \" This line has a sepll error. and missing caps and trailing spaces. ",
+ \"another missing cap here.",
+ \"",
+ \"and here.",
+ \" ",
+ \"and here."
+ \])
+ set spell spelllang=en
+ ]=])
+ screen:expect([[
+ ^ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap here. |
+ |
+ {2:and} here. |
+ |
+ {2:and} here. |
+ {0:~ }|
+ |
+ ]])
+ -- After adding word missing Cap in next line is updated
+ feed('3GANot<Esc>')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap here. |
+ No^t |
+ and here. |
+ |
+ {2:and} here. |
+ {0:~ }|
+ |
+ ]])
+ -- Deleting a full stop removes missing Cap in next line
+ feed('5Gdd<C-L>k$x')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap here. |
+ Not |
+ and her^e |
+ and here. |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Undo also updates the next line (go to command line to remove message)
+ feed('u:<Esc>')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap here. |
+ Not |
+ and here^. |
+ {2:and} here. |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Folding an empty line does not remove Cap in next line
+ feed('uzfk:<Esc>')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap here. |
+ Not |
+ {10:^+-- 2 lines: and here.·························································}|
+ {2:and} here. |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Folding the end of a sentence does not remove Cap in next line
+ -- and editing a line does not remove Cap in current line
+ feed('Jzfkk$x')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ {2:another} missing cap her^e |
+ {10:+-- 2 lines: Not·······························································}|
+ {2:and} here. |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Cap is correctly applied in the first row of a window
+ feed('<C-E><C-L>')
+ screen:expect([[
+ {2:another} missing cap her^e |
+ {10:+-- 2 lines: Not·······························································}|
+ {2:and} here. |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Adding an empty line does not remove Cap in "mod_bot" area
+ feed('zbO<Esc>')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ ^ |
+ {2:another} missing cap here |
+ {10:+-- 2 lines: Not·······························································}|
+ {2:and} here. |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Multiple empty lines does not remove Cap in the line after
+ feed('O<Esc><C-L>')
+ screen:expect([[
+ This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
+ ^ |
+ |
+ {2:another} missing cap here |
+ {10:+-- 2 lines: Not·······························································}|
+ {2:and} here. |
+ {0:~ }|
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_spell_compatible()
+ it([[redraws properly when using "C" and "$" is in 'cpo']], function()
+ exec([=[
+ call setline(1, [
+ \ "test "->repeat(20),
+ \ "",
+ \ "end",
+ \ ])
+ set spell cpo+=$
+ ]=])
+ feed('51|C')
+ screen:expect([[
+ {2:test} test test test test test test test test test ^test test test test test test |
+ test test test test$ |
+ |
+ {2:end} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {9:-- INSERT --} |
+ ]])
+ feed('x')
+ screen:expect([[
+ {2:test} test test test test test test test test test x^est test test test test test |
+ test test test test$ |
+ |
+ {2:end} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {9:-- INSERT --} |
+ ]])
+ end)
+
+ it('extmarks, "noplainbuffer" and syntax #20385 #23398', function()
+ exec('set filetype=c')
+ exec('syntax on')
+ exec('set spell')
insert([[
#include <stdbool.h>
- bool func(void);]])
+ bool func(void);
+ // I am a speling mistakke]])
+ feed('ge')
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:spelin^g}{7: }{8:mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ feed(']s')
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:speling}{7: }{8:^mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ feed(']s')
screen:expect([[
{3:#include }{4:<stdbool.h>} |
- {5:bool} func({5:void})^; |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:^speling}{7: }{8:mistakke} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
+ {6:search hit BOTTOM, continuing at TOP} |
+ ]])
+ exec('echo ""')
+ local ns = meths.create_namespace("spell")
+ -- extmark with spell=true enables spell
+ local id = curbufmeths.set_extmark(ns, 1, 4, { end_row = 1, end_col = 10, spell = true })
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} {1:func}({5:void}); |
+ {7:// I am a }{8:^speling}{7: }{8:mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
{0:~ }|
|
]])
feed('[s')
screen:expect([[
{3:#include }{4:<stdbool.h>} |
- {5:bool} func({5:void})^; |
+ {5:bool} {1:^func}({5:void}); |
+ {7:// I am a }{8:speling}{7: }{8:mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ curbufmeths.del_extmark(ns, id)
+ -- extmark with spell=false disables spell
+ id = curbufmeths.set_extmark(ns, 2, 18, { end_row = 2, end_col = 26, spell = false })
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} ^func({5:void}); |
+ {7:// I am a }{8:speling}{7: mistakke} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
+ |
+ ]])
+ feed('[s')
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:^speling}{7: mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
{0:~ }|
{6:search hit TOP, continuing at BOTTOM} |
]])
- -- "noplainbuffer" shouldn't change spellchecking behavior with syntax enabled
- command('set spelloptions+=noplainbuffer')
- screen:expect_unchanged()
+ exec('echo ""')
+ curbufmeths.del_extmark(ns, id)
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:^speling}{7: }{8:mistakke} |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
feed(']s')
screen:expect([[
{3:#include }{4:<stdbool.h>} |
- {5:bool} func({5:void})^; |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:speling}{7: }{8:^mistakke} |
+ {0:~ }|
+ {0:~ }|
{0:~ }|
{0:~ }|
+ |
+ ]])
+ -- "noplainbuffer" shouldn't change spellchecking behavior with syntax enabled
+ exec('set spelloptions+=noplainbuffer')
+ screen:expect_unchanged()
+ feed('[s')
+ screen:expect([[
+ {3:#include }{4:<stdbool.h>} |
+ {5:bool} func({5:void}); |
+ {7:// I am a }{8:^speling}{7: }{8:mistakke} |
+ {0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {6:search hit BOTTOM, continuing at TOP} |
+ |
]])
-- no spellchecking with "noplainbuffer" and syntax disabled
- command('syntax off')
+ exec('syntax off')
screen:expect([[
#include <stdbool.h> |
- bool func(void)^; |
+ bool func(void); |
+ // I am a ^speling mistakke |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {6:search hit BOTTOM, continuing at TOP} |
+ |
]])
- feed('[s')
+ feed(']s')
screen:expect([[
#include <stdbool.h> |
- bool func(void)^; |
+ bool func(void); |
+ // I am a ^speling mistakke |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {6:search hit TOP, continuing at BOTTOM} |
+ {6:search hit BOTTOM, continuing at TOP} |
]])
+ exec('echo ""')
-- everything is spellchecked without "noplainbuffer" with syntax disabled
- command('set spelloptions&')
+ exec('set spelloptions&')
screen:expect([[
#include <{1:stdbool}.h> |
- {1:bool} {1:func}(void)^; |
- {0:~ }|
+ {1:bool} {1:func}(void); |
+ // I am a {1:^speling} {1:mistakke} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {6:search hit TOP, continuing at BOTTOM} |
+ |
]])
- feed(']s')
+ feed('[s')
screen:expect([[
- #include <{1:^stdbool}.h> |
- {1:bool} {1:func}(void); |
- {0:~ }|
+ #include <{1:stdbool}.h> |
+ {1:bool} {1:^func}(void); |
+ // I am a {1:speling} {1:mistakke} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {6:search hit BOTTOM, continuing at TOP} |
+ |
+ ]])
+ end)
+
+ it('and syntax does not clear extmark highlighting at the start of a word', function()
+ screen:try_resize(43, 3)
+ exec([[
+ set spell
+ syntax match Constant "^.*$"
+ call setline(1, "This is some text without any spell errors.")
+ ]])
+ local ns = meths.create_namespace("spell")
+ curbufmeths.set_extmark(ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 })
+ screen:expect([[
+ {6:^This is some text without any spell errors.}|
+ {0:~ }|
+ |
]])
end)
end)
diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua
index ae3b95fb0f..6eaf15cfad 100644
--- a/test/functional/ui/statuscolumn_spec.lua
+++ b/test/functional/ui/statuscolumn_spec.lua
@@ -3,11 +3,15 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
+local exec = helpers.exec
local eval = helpers.eval
local exec_lua = helpers.exec_lua
local feed = helpers.feed
local meths = helpers.meths
local pcall_err = helpers.pcall_err
+local assert_alive = helpers.assert_alive
+
+local mousemodels = { "extend", "popup", "popup_setpos" }
describe('statuscolumn', function()
local screen
@@ -15,6 +19,7 @@ describe('statuscolumn', function()
clear('--cmd', 'set number nuw=1 | call setline(1, repeat(["aaaaa"], 16)) | norm GM')
screen = Screen.new()
screen:attach()
+ exec_lua('ns = vim.api.nvim_create_namespace("")')
end)
it("fails with invalid 'statuscolumn'", function()
@@ -41,22 +46,17 @@ describe('statuscolumn', function()
end)
it("widens with irregular 'statuscolumn' width", function()
- command([[set stc=%{v:relnum?v:relnum:(v:lnum==5?'bbbbb':v:lnum)}]])
- command('norm 5G | redraw!')
+ screen:try_resize(screen._width, 4)
+ command([=[
+ set stc=%{v:relnum?v:relnum:(v:lnum==5?'bbbbb':v:lnum)}
+ let ns = nvim_create_namespace('')
+ call nvim_buf_set_extmark(0, ns, 3, 0, {'virt_text':[['virt_text']]})
+ norm 5G | redraw!
+ ]=])
screen:expect([[
- 1 aaaaa |
+ 1 aaaaa virt_text |
bbbbba^eaaa |
1 aaaaa |
- 2 aaaaa |
- 3 aaaaa |
- 4 aaaaa |
- 5 aaaaa |
- 6 aaaaa |
- 7 aaaaa |
- 8 aaaaa |
- 9 aaaaa |
- 10 aaaaa |
- 11 aaaaa |
|
]])
end)
@@ -193,8 +193,10 @@ describe('statuscolumn', function()
[2] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGrey},
[3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
[4] = {bold = true, foreground = Screen.colors.Brown},
- [5] = {background = Screen.colors.Grey90},
+ [5] = {foreground = Screen.colors.Red},
+ [6] = {foreground = Screen.colors.Red, background = Screen.colors.LightGrey},
})
+ command('hi! CursorLine guifg=Red guibg=NONE')
screen:expect([[
{1: 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1: │ }a |
@@ -211,7 +213,7 @@ describe('statuscolumn', function()
{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}|
|
]])
- command("set stc=%C%s%=%l│\\ ")
+ command([[set stc=%C%s%=%l│\ ]])
screen:expect_unchanged()
command('set signcolumn=auto:2 foldcolumn=auto')
command('sign define piet1 text=>> texthl=LineNr')
@@ -265,7 +267,7 @@ describe('statuscolumn', function()
{2: }{1: │}{2: }{1: }aaaaaa |
{2: }{1: 7│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa |
- {2:+}{4: 8│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2:+}{4: 8│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 9│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa |
{2: }{1:10│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
@@ -283,7 +285,7 @@ describe('statuscolumn', function()
{2: }{1: 6│}{2: }{1: }aaaaaa |
{2: }{1: 7│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 7│}{2: }{1: }aaaaaa |
- {2:+}{4: 8│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2:+}{4: 8│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 9│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 9│}{2: }{1: }aaaaaa |
{2: }{1:10│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
@@ -301,7 +303,7 @@ describe('statuscolumn', function()
{2: }{1: 2│}{2: }{1: }aaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 1│}{2: }{1: }aaaaaa |
- {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 1│}{2: }{1: }aaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
@@ -318,7 +320,7 @@ describe('statuscolumn', function()
{2: }{1: │}{2: }{1: }aaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa |
- {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
@@ -343,16 +345,74 @@ describe('statuscolumn', function()
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa |
- {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaa}|
+ {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa |
|
]])
+ -- Also test fold and sign column when 'cpoptions' includes "n"
+ command('set cpoptions+=n')
+ feed('Hgjg0')
+ screen:expect([[
+ {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2: }{5:^aaaaaaaaaaaaaaaaaaaa }|
+ {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2:+}{1: 4│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
+ {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ |
+ ]])
+ command('set breakindent')
+ command('sign unplace 2')
+ feed('J2gjg0')
+ screen:expect([[
+ {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2: } {5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaa}|
+ {2: } {5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2: } {5:^aaaaaaaaaaa }|
+ {2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: } aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: } aaaaaaaaaaaaaaaaaaaa |
+ {2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
+ {2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: } aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: } aaaaaaaaaaaaaaaaaaaa |
+ |
+ ]])
+ command('set nobreakindent')
+ feed('$g0')
+ screen:expect([[
+ {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2: }{5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa}|
+ {2: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {2: }{5:^aaa }|
+ {2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}|
+ {2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ {2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {2: }aaaaaaaaaaaaaaaaaaaa |
+ |
+ ]])
+ command('silent undo')
+ feed('8gg')
+ command('set cpoptions-=n')
-- Status column is re-evaluated for virt_lines, buffer line, and wrapped line
exec_lua([[
- local ns = vim.api.nvim_create_namespace("ns")
vim.api.nvim_buf_set_extmark(0, ns, 5, 0, {
virt_lines_above = true, virt_lines = {{{"virt_line above", ""}}} })
vim.api.nvim_buf_set_extmark(0, ns, 4, 0, { virt_lines = {{{"virt_line", ""}}} })
@@ -365,57 +425,216 @@ describe('statuscolumn', function()
{1:buffer 0 5}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1:wrapped 1 5}aaaaaaaa |
{1:virtual-2 5}virt_line |
- {1:virtual-2 5}virt_line above |
+ {1:virtual-1 5}virt_line above |
{1:buffer 0 6}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1:wrapped 1 6}aaaaaaaa |
{1:buffer 0 7}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1:wrapped 1 7}aaaaaaaa |
- {4:buffer 0 8}{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {4:buffer 0 8}{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{1:buffer 0 9}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1:wrapped 1 9}aaaaaaaa |
|
]])
+ -- Also test virt_lines at the end of buffer
+ exec_lua([[
+ vim.api.nvim_buf_set_extmark(0, ns, 15, 0, { virt_lines = {{{"END", ""}}} })
+ ]])
+ feed('GkJzz')
+ screen:expect([[
+ {1:buffer 0 12}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 12}aaaaaaaaa |
+ {1:buffer 0 13}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 13}aaaaaaaaa |
+ {1:buffer 0 14}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 14}aaaaaaaaa |
+ {4:buffer 0 15}{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {4:wrapped 1 15}{5:aaaaaaaaa^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {4:wrapped 2 15}{5:aaaaaaaaaaaaaaaaaaa }|
+ {1:virtual-1 15}END |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ -- Also test virt_lines when 'cpoptions' includes "n"
+ exec_lua([[
+ vim.opt.cpoptions:append("n")
+ vim.api.nvim_buf_set_extmark(0, ns, 14, 0, { virt_lines = {{{"virt_line1", ""}}} })
+ vim.api.nvim_buf_set_extmark(0, ns, 14, 0, { virt_lines = {{{"virt_line2", ""}}} })
+ ]])
+ screen:expect([[
+ {1:buffer 0 12}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaa |
+ {1:buffer 0 13}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaa |
+ {1:buffer 0 14}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ aaaaaaaaa |
+ {4:buffer 0 15}{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {5:aaaaaaaaa^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
+ {5:aaaaaaa }|
+ {1:virtual-3 15}virt_line1 |
+ {1:virtual-2 15}virt_line2 |
+ {1:virtual-1 15}END |
+ {0:~ }|
+ |
+ ]])
end)
- it("works with 'statuscolumn' clicks", function()
- command('set mousemodel=extend')
- command([[
- function! MyClickFunc(minwid, clicks, button, mods)
- let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line)
- if a:mods !=# ' '
- let g:testvar ..= '(' .. a:mods .. ')'
- endif
- endfunction
- set stc=%0@MyClickFunc@%=%l%T
- ]])
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 1 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 2 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 3 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 4 l 4', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 1 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 2 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 3 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 4 r 7', eval("g:testvar"))
- command('set laststatus=2 winbar=%f')
- command('let g:testvar=""')
- -- Check that winbar click doesn't register as statuscolumn click
- meths.input_mouse('right', 'press', '', 0, 0, 0)
- eq('', eval("g:testvar"))
- -- Check that statusline click doesn't register as statuscolumn click
- meths.input_mouse('right', 'press', '', 0, 12, 0)
- eq('', eval("g:testvar"))
+ it('does not corrupt the screen with minwid sign item', function()
+ screen:try_resize(screen._width, 3)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Brown},
+ [1] = {foreground = Screen.colors.Blue4, background = Screen.colors.Gray},
+ })
+ command([[set stc=%6s\ %l]])
+ exec_lua('vim.api.nvim_buf_set_extmark(0, ns, 7, 0, {sign_text = "𒀀"})')
+ screen:expect([[
+ {0: 𒀀 8}^aaaaa |
+ {0: }{1: }{0: 9}aaaaa |
+ |
+ ]])
end)
- it('click labels do not leak memory', function()
- command([[
+ for _, model in ipairs(mousemodels) do
+ describe('with mousemodel=' .. model, function()
+ before_each(function()
+ command('set mousemodel=' .. model)
+ exec([[
+ function! MyClickFunc(minwid, clicks, button, mods)
+ let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line)
+ if a:mods !=# ' '
+ let g:testvar ..= '(' .. a:mods .. ')'
+ endif
+ endfunction
+ let g:testvar = ''
+ ]])
+ end)
+
+ it('clicks work with mousemodel=' .. model, function()
+ meths.set_option_value('statuscolumn', '%0@MyClickFunc@%=%l%T', {})
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 1 l 4', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 2 l 4', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 3 l 4', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 4 l 4', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 1 r 7', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 2 r 7', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 3 r 7', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 4 r 7', eval("g:testvar"))
+
+ command('rightbelow vsplit')
+ meths.input_mouse('left', 'press', '', 0, 0, 27)
+ eq('0 1 l 4', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 27)
+ eq('0 1 r 7', eval("g:testvar"))
+ command('setlocal rightleft')
+ meths.input_mouse('left', 'press', '', 0, 0, 52)
+ eq('0 1 l 4', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 52)
+ eq('0 1 r 7', eval("g:testvar"))
+ command('wincmd H')
+ meths.input_mouse('left', 'press', '', 0, 0, 25)
+ eq('0 1 l 4', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 3, 25)
+ eq('0 1 r 7', eval("g:testvar"))
+ command('close')
+
+ command('set laststatus=2 winbar=%f')
+ command('let g:testvar = ""')
+ -- Check that winbar click doesn't register as statuscolumn click
+ meths.input_mouse('right', 'press', '', 0, 0, 0)
+ eq('', eval("g:testvar"))
+ -- Check that statusline click doesn't register as statuscolumn click
+ meths.input_mouse('right', 'press', '', 0, 12, 0)
+ eq('', eval("g:testvar"))
+ -- Check that cmdline click doesn't register as statuscolumn click
+ meths.input_mouse('right', 'press', '', 0, 13, 0)
+ eq('', eval("g:testvar"))
+ end)
+
+ it('clicks and highlights work with control characters', function()
+ meths.set_option_value('statuscolumn', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {})
+ screen:expect{grid=[[
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}^aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ |
+ ]], attr_ids={
+ [0] = {foreground = Screen.colors.Blue, bold = true}; -- NonText
+ [1] = {foreground = Screen.colors.Brown}; -- LineNr
+ }}
+ meths.input_mouse('right', 'press', '', 0, 4, 3)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 5, 8)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 4)
+ eq('0 1 r 10', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 7, 7)
+ eq('0 1 l 11', eval("g:testvar"))
+ end)
+
+ it('popupmenu callback does not drag mouse on close', function()
+ screen:try_resize(screen._width, 2)
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Brown},
+ [1] = {background = Screen.colors.Plum1},
+ })
+ meths.set_option_value('statuscolumn', '%0@MyClickFunc@%l%T', {})
+ exec([[
+ function! MyClickFunc(minwid, clicks, button, mods)
+ let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line)
+ menu PopupStc.Echo <cmd>echo g:testvar<CR>
+ popup PopupStc
+ endfunction
+ ]])
+ -- clicking an item does not drag mouse
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ screen:expect([[
+ {0:8 }^aaaaa |
+ {1: Echo } |
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 1, 5)
+ meths.input_mouse('left', 'release', '', 0, 1, 5)
+ screen:expect([[
+ {0:8 }^aaaaa |
+ 0 1 l 8 |
+ ]])
+ command('echo')
+ -- clicking outside to close the menu does not drag mouse
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ screen:expect([[
+ {0:8 }^aaaaa |
+ {1: Echo } |
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 0, 10)
+ meths.input_mouse('left', 'release', '', 0, 0, 10)
+ screen:expect([[
+ {0:8 }^aaaaa |
+ |
+ ]])
+ end)
+ end)
+ end
+
+ it('click labels do not leak memory #21878', function()
+ exec([[
set laststatus=2
setlocal statuscolumn=%0@MyClickFunc@abcd%T
4vsplit
@@ -427,19 +646,29 @@ describe('statuscolumn', function()
]])
end)
+ it('click labels do not crash when initial width is 0 #24428', function()
+ exec([[
+ set nonumber
+ bwipe!
+ setlocal statuscolumn=abcd
+ redraw
+ setlocal statuscolumn=%0@MyClickFunc@abcd%T
+ redraw
+ ]])
+ assert_alive()
+ end)
+
it('works with foldcolumn', function()
-- Fits maximum multibyte foldcolumn #21759
command([[set stc=%C%=%l\ fdc=9 fillchars=foldsep:𒀀]])
for _ = 0,8 do command('norm zfjzo') end
-- 'statuscolumn' is not drawn for `virt_lines_leftcol` lines
exec_lua([[
- local ns = vim.api.nvim_create_namespace("ns")
vim.api.nvim_buf_set_extmark(0, ns, 6, 0, {
virt_lines_leftcol = true, virt_lines = {{{"virt", ""}}} })
vim.api.nvim_buf_set_extmark(0, ns, 7, 0, {
virt_lines_leftcol = true, virt_lines = {{{"virt", ""}}} })
]])
- feed('lh') -- force update wcol/row
screen:expect([[
4 aaaaa |
5 aaaaa |
@@ -456,7 +685,188 @@ describe('statuscolumn', function()
14 aaaaa |
|
]])
- command('set stc=') -- also for the default sign column
+ command('set stc=') -- also for the default fold column
screen:expect_unchanged()
+ -- 'statuscolumn' is not too wide with custom (bogus) fold column
+ command([[set stc=%{foldlevel(v:lnum)>0?repeat('-',foldlevel(v:lnum)):''}%=%l\ ]])
+ feed('Gd10Ggg<C-l>')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 aaaaa |
+ 3 aaaaa |
+ 4 aaaaa |
+ 5 aaaaa |
+ 6 aaaaa |
+ 7 aaaaa |
+ virt |
+ ---------8 aaaaa |
+ virt |
+ ---------9 aaaaa |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ it('works with cmdwin', function()
+ feed(':set stc=%l<CR>q:k$')
+ screen:expect([[
+ 7 aaaaa |
+ 8 aaaaa |
+ 9 aaaaa |
+ 10aaaaa |
+ [No Name] [+] |
+ :1set stc=%^l |
+ :2 |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ [Command Line] |
+ : |
+ ]])
+ end)
+
+ it("has correct width when toggling '(relative)number'", function()
+ screen:try_resize(screen._width, 6)
+ command('call setline(1, repeat(["aaaaa"], 100))')
+ command('set relativenumber')
+ command([[set stc=%{!&nu&&!&rnu?'':&rnu?v:relnum?v:relnum:&nu?v:lnum:'0':v:lnum}]])
+ screen:expect([[
+ 1 aaaaa |
+ 8 ^aaaaa |
+ 1 aaaaa |
+ 2 aaaaa |
+ 3 aaaaa |
+ |
+ ]])
+ -- width correctly estimated with "w_nrwidth_line_count" when setting 'stc'
+ command([[set stc=%{!&nu&&!&rnu?'':&rnu?v:relnum?v:relnum:&nu?v:lnum:'0':v:lnum}]])
+ screen:expect_unchanged()
+ -- zero width when disabling 'number'
+ command('set norelativenumber nonumber')
+ screen:expect([[
+ aaaaa |
+ ^aaaaa |
+ aaaaa |
+ aaaaa |
+ aaaaa |
+ |
+ ]])
+ -- width correctly estimated with "w_nrwidth_line_count" when setting 'nu'
+ command('set number')
+ screen:expect([[
+ 7 aaaaa |
+ 8 ^aaaaa |
+ 9 aaaaa |
+ 10 aaaaa |
+ 11 aaaaa |
+ |
+ ]])
+ end)
+
+ it("has correct width with custom sign column when (un)placing signs", function()
+ screen:try_resize(screen._width, 3)
+ exec_lua([[
+ vim.cmd.norm('gg')
+ vim.o.signcolumn = 'no'
+ vim.fn.sign_define('sign', { text = 'ss' })
+ _G.StatusCol = function()
+ local s = vim.fn.sign_getplaced(1)[1].signs
+ local es = vim.api.nvim_buf_get_extmarks(0, ns, 0, -1, {type = "sign"})
+ local sign = ''
+ local signs = #s + #es
+ if signs > 0 then
+ sign = (vim.v.lnum == 2 and 'ss' or ' '):rep(signs)
+ end
+ return vim.v.lnum .. '%=' .. sign
+ end
+ vim.o.number = true
+ vim.o.numberwidth = 2
+ vim.o.statuscolumn = "%!v:lua.StatusCol()"
+ ]])
+ command('sign place 1 line=2 name=sign')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssaaaaa |
+ |
+ ]])
+ command('sign place 2 line=2 name=sign')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssssaaaaa |
+ |
+ ]])
+ command('sign unplace 2')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssaaaaa |
+ |
+ ]])
+ command('sign unplace 1')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 aaaaa |
+ |
+ ]])
+ -- Also for extmark signs
+ exec_lua('id1 = vim.api.nvim_buf_set_extmark(0, ns, 1, 0, {sign_text = "ss"})')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssaaaaa |
+ |
+ ]])
+ exec_lua('id2 = vim.api.nvim_buf_set_extmark(0, ns, 1, 0, {sign_text = "ss"})')
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssssaaaaa |
+ |
+ ]])
+ exec_lua("vim.api.nvim_buf_del_extmark(0, ns, id1)")
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 ssaaaaa |
+ |
+ ]])
+ exec_lua("vim.api.nvim_buf_del_extmark(0, ns, id2)")
+ screen:expect([[
+ 1 ^aaaaa |
+ 2 aaaaa |
+ |
+ ]])
+ -- In all windows
+ command('wincmd v | set ls=0')
+ command('sign place 1 line=2 name=sign')
+ screen:expect([[
+ 1 ^aaaaa │1 aaaaa |
+ 2 ssaaaaa │2 ssaaaaa |
+ |
+ ]])
+ end)
+
+ it("is only evaluated twice, once to estimate and once to draw", function()
+ command([[
+ let g:stcnr = 0
+ func! Stc()
+ let g:stcnr += 1
+ return '12345'
+ endfunc
+ set stc=%!Stc()
+ norm ggdG
+ ]])
+ eq(2, eval('g:stcnr'))
+ end)
+
+ it('does not wrap multibyte characters at the end of a line', function()
+ screen:try_resize(33, 4)
+ command([[set spell stc=%l\ ]])
+ command('call setline(8, "This is a line that contains ᶏ multibyte character.")')
+ screen:expect([[
+ 8 ^This is a line that contains ᶏ|
+ multibyte character. |
+ 9 aaaaa |
+ |
+ ]])
end)
end)
diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua
index 1c184ff27d..182e0cdadf 100644
--- a/test/functional/ui/statusline_spec.lua
+++ b/test/functional/ui/statusline_spec.lua
@@ -10,179 +10,215 @@ local meths = helpers.meths
local exec = helpers.exec
local exec_lua = helpers.exec_lua
local eval = helpers.eval
-
-describe('statusline clicks', function()
- local screen
-
- before_each(function()
- clear()
- screen = Screen.new(40, 8)
- screen:attach()
- command('set laststatus=2 mousemodel=extend')
- exec([=[
- function! MyClickFunc(minwid, clicks, button, mods)
- let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
- if a:mods !=# ' '
- let g:testvar ..= '(' .. a:mods .. ')'
- endif
- endfunction
- ]=])
- end)
-
- it('works', function()
- meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 2 l', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 3 l', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 4 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 1 r', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 2 r', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 3 r', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 4 r', eval("g:testvar"))
- end)
-
- it('works for winbar', function()
- meths.set_option('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.input_mouse('left', 'press', '', 0, 0, 17)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 0, 17)
- eq('0 1 r', eval("g:testvar"))
- end)
-
- it('works for winbar in floating window', function()
- meths.open_win(0, true, { width=30, height=4, relative='editor', row=1, col=5,
- border = "single" })
- meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T',
- { scope = 'local' })
- meths.input_mouse('left', 'press', '', 0, 2, 23)
- eq('0 1 l', eval("g:testvar"))
- end)
-
- it('works when there are multiple windows', function()
- command('split')
- meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.set_option('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.input_mouse('left', 'press', '', 0, 0, 17)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 4, 17)
- eq('0 1 r', eval("g:testvar"))
- meths.input_mouse('middle', 'press', '', 0, 3, 17)
- eq('0 1 m', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 1 l', eval("g:testvar"))
- end)
-
- it('works with Lua function', function()
- exec_lua([[
+local sleep = helpers.sleep
+
+local mousemodels = { "extend", "popup", "popup_setpos" }
+
+for _, model in ipairs(mousemodels) do
+ describe('statusline clicks with mousemodel=' .. model, function()
+ local screen
+
+ before_each(function()
+ clear()
+ screen = Screen.new(40, 8)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [1] = {bold = true, reverse = true}; -- StatusLine
+ })
+ screen:attach()
+ command('set laststatus=2 mousemodel=' .. model)
+ exec([=[
+ function! MyClickFunc(minwid, clicks, button, mods)
+ let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
+ if a:mods !=# ' '
+ let g:testvar ..= '(' .. a:mods .. ')'
+ endif
+ endfunction
+ let g:testvar = ''
+ ]=])
+ end)
+
+ it('works', function()
+ meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ meths.input_mouse('left', 'press', '', 0, 6, 16)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 29)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 2 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 3 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 4 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 28)
+ eq('0 1 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 28)
+ eq('0 2 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 28)
+ eq('0 3 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 28)
+ eq('0 4 r', eval("g:testvar"))
+ end)
+
+ it('works with control characters and highlight', function()
+ meths.set_option_value('statusline', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {})
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {1:^I}{0:^A^I^A^I}{1:^A }|
+ |
+ ]]}
+ meths.input_mouse('right', 'press', '', 0, 6, 3)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 8)
+ eq('', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 4)
+ eq('0 1 r', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 7)
+ eq('0 1 l', eval("g:testvar"))
+ end)
+
+ it('works for winbar', function()
+ meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ meths.input_mouse('left', 'press', '', 0, 0, 17)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 0, 17)
+ eq('0 1 r', eval("g:testvar"))
+ end)
+
+ it('works for winbar in floating window', function()
+ meths.open_win(0, true, { width=30, height=4, relative='editor', row=1, col=5,
+ border = "single" })
+ meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T',
+ { scope = 'local' })
+ meths.input_mouse('left', 'press', '', 0, 2, 23)
+ eq('0 1 l', eval("g:testvar"))
+ end)
+
+ it('works when there are multiple windows', function()
+ command('split')
+ meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ meths.input_mouse('left', 'press', '', 0, 0, 17)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 4, 17)
+ eq('0 1 r', eval("g:testvar"))
+ meths.input_mouse('middle', 'press', '', 0, 3, 17)
+ eq('0 1 m', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 1 l', eval("g:testvar"))
+ end)
+
+ it('works with Lua function', function()
+ exec_lua([[
function clicky_func(minwid, clicks, button, mods)
vim.g.testvar = string.format("%d %d %s", minwid, clicks, button)
end
- ]])
- meths.set_option('statusline', 'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T')
- meths.input_mouse('left', 'press', '', 0, 6, 17)
- eq('0 1 l', eval("g:testvar"))
- end)
-
- it('ignores unsupported click items', function()
- command('tabnew | tabprevious')
- meths.set_option('statusline', '%2TNot clicky stuff%T')
- meths.input_mouse('left', 'press', '', 0, 6, 0)
- eq(1, meths.get_current_tabpage().id)
- meths.set_option('statusline', '%2XNot clicky stuff%X')
- meths.input_mouse('left', 'press', '', 0, 6, 0)
- eq(2, #meths.list_tabpages())
- end)
-
- it("right click works when statusline isn't focused #18994", function()
- meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 1 r', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 17)
- eq('0 2 r', eval("g:testvar"))
- end)
-
- it("works with modifiers #18994", function()
- meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
- meths.input_mouse('left', 'press', 'S', 0, 6, 17)
- eq('0 1 l(s )', eval("g:testvar"))
- meths.input_mouse('right', 'press', 'S', 0, 6, 17)
- eq('0 1 r(s )', eval("g:testvar"))
- meths.input_mouse('left', 'press', 'A', 0, 6, 17)
- eq('0 1 l( a )', eval("g:testvar"))
- meths.input_mouse('right', 'press', 'A', 0, 6, 17)
- eq('0 1 r( a )', eval("g:testvar"))
- meths.input_mouse('left', 'press', 'AS', 0, 6, 17)
- eq('0 1 l(s a )', eval("g:testvar"))
- meths.input_mouse('right', 'press', 'AS', 0, 6, 17)
- eq('0 1 r(s a )', eval("g:testvar"))
- meths.input_mouse('left', 'press', 'T', 0, 6, 17)
- eq('0 1 l( m)', eval("g:testvar"))
- meths.input_mouse('right', 'press', 'T', 0, 6, 17)
- eq('0 1 r( m)', eval("g:testvar"))
- meths.input_mouse('left', 'press', 'TS', 0, 6, 17)
- eq('0 1 l(s m)', eval("g:testvar"))
- meths.input_mouse('right', 'press', 'TS', 0, 6, 17)
- eq('0 1 r(s m)', eval("g:testvar"))
- meths.input_mouse('left', 'press', 'C', 0, 6, 17)
- eq('0 1 l( c )', eval("g:testvar"))
- -- <C-RightMouse> is for tag jump
- end)
-
- it("works for global statusline with vertical splits #19186", function()
- command('set laststatus=3')
- meths.set_option('statusline', '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T')
- command('vsplit')
- screen:expect([[
- ^ │ |
- ~ │~ |
- ~ │~ |
- ~ │~ |
- ~ │~ |
- ~ │~ |
- Clicky stuff Clicky stuff|
- |
- ]])
-
- -- clickable area on the right
- meths.input_mouse('left', 'press', '', 0, 6, 35)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 35)
- eq('0 1 r', eval("g:testvar"))
-
- -- clickable area on the left
- meths.input_mouse('left', 'press', '', 0, 6, 5)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 5)
- eq('0 1 r', eval("g:testvar"))
- end)
-
- it('no memory leak with zero-width click labels', function()
- command([[
+ ]])
+ meths.set_option_value('statusline', 'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T', {})
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 1 l', eval("g:testvar"))
+ end)
+
+ it('ignores unsupported click items', function()
+ command('tabnew | tabprevious')
+ meths.set_option_value('statusline', '%2TNot clicky stuff%T', {})
+ meths.input_mouse('left', 'press', '', 0, 6, 0)
+ eq(1, meths.get_current_tabpage().id)
+ meths.set_option_value('statusline', '%2XNot clicky stuff%X', {})
+ meths.input_mouse('left', 'press', '', 0, 6, 0)
+ eq(2, #meths.list_tabpages())
+ end)
+
+ it("right click works when statusline isn't focused #18994", function()
+ meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ meths.input_mouse('right', 'press', '', 0, 6, 17)
+ eq('0 1 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 17)
+ eq('0 2 r', eval("g:testvar"))
+ end)
+
+ it("works with modifiers #18994", function()
+ meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
+ -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
+ meths.input_mouse('left', 'press', 'S', 0, 6, 17)
+ eq('0 1 l(s )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'S', 0, 6, 17)
+ eq('0 1 r(s )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'A', 0, 6, 17)
+ eq('0 1 l( a )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'A', 0, 6, 17)
+ eq('0 1 r( a )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'AS', 0, 6, 17)
+ eq('0 1 l(s a )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'AS', 0, 6, 17)
+ eq('0 1 r(s a )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'T', 0, 6, 17)
+ eq('0 1 l( m)', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'T', 0, 6, 17)
+ eq('0 1 r( m)', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'TS', 0, 6, 17)
+ eq('0 1 l(s m)', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'TS', 0, 6, 17)
+ eq('0 1 r(s m)', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'C', 0, 6, 17)
+ eq('0 1 l( c )', eval("g:testvar"))
+ -- <C-RightMouse> is for tag jump
+ end)
+
+ it("works for global statusline with vertical splits #19186", function()
+ command('set laststatus=3')
+ meths.set_option_value('statusline', '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T', {})
+ command('vsplit')
+ screen:expect{grid=[[
+ ^ │ |
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {1:Clicky stuff Clicky stuff}|
+ |
+ ]]}
+
+ -- clickable area on the right
+ meths.input_mouse('left', 'press', '', 0, 6, 35)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 35)
+ eq('0 1 r', eval("g:testvar"))
+
+ -- clickable area on the left
+ meths.input_mouse('left', 'press', '', 0, 6, 5)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 5)
+ eq('0 1 r', eval("g:testvar"))
+ end)
+
+ it('no memory leak with zero-width click labels', function()
+ command([[
let &stl = '%@Test@%T%@MyClickFunc@%=%T%@Test@'
- ]])
- meths.input_mouse('left', 'press', '', 0, 6, 0)
- eq('0 1 l', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 39)
- eq('0 1 r', eval("g:testvar"))
- end)
-
- it('no memory leak with truncated click labels', function()
- command([[
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 6, 0)
+ eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 39)
+ eq('0 1 r', eval("g:testvar"))
+ end)
+
+ it('no memory leak with truncated click labels', function()
+ command([[
let &stl = '%@MyClickFunc@foo%X' .. repeat('a', 40) .. '%<t%@Test@bar%X%@Test@baz'
- ]])
- meths.input_mouse('left', 'press', '', 0, 6, 2)
- eq('0 1 l', eval("g:testvar"))
+ ]])
+ meths.input_mouse('left', 'press', '', 0, 6, 2)
+ eq('0 1 l', eval("g:testvar"))
+ end)
end)
-end)
+end
describe('global statusline', function()
local screen
@@ -389,38 +425,38 @@ describe('global statusline', function()
end)
it('win_move_statusline() can reduce cmdheight to 1', function()
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, -1)
- eq(2, meths.get_option('cmdheight'))
+ eq(2, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, -1)
- eq(3, meths.get_option('cmdheight'))
+ eq(3, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, 1)
- eq(2, meths.get_option('cmdheight'))
+ eq(2, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, 1)
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
end)
it('mouse dragging can reduce cmdheight to 1', function()
command('set mouse=a')
meths.input_mouse('left', 'press', '', 0, 14, 10)
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 13, 10)
- eq(2, meths.get_option('cmdheight'))
+ eq(2, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 12, 10)
- eq(3, meths.get_option('cmdheight'))
+ eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 13, 10)
- eq(2, meths.get_option('cmdheight'))
+ eq(2, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 14, 10)
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 15, 10)
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 14, 10)
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
end)
it('cmdline row is correct after setting cmdheight #20514', function()
command('botright split test/functional/fixtures/bigfile.txt')
- meths.set_option('cmdheight', 1)
+ meths.set_option_value('cmdheight', 1, {})
feed('L')
screen:expect([[
|
@@ -459,7 +495,7 @@ describe('global statusline', function()
{2:test/functional/fixtures/bigfile.txt 8,1 0%}|
|
]])
- meths.set_option('showtabline', 2)
+ meths.set_option_value('showtabline', 2, {})
screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
|
@@ -478,7 +514,7 @@ describe('global statusline', function()
{2:test/functional/fixtures/bigfile.txt 8,1 0%}|
|
]])
- meths.set_option('cmdheight', 0)
+ meths.set_option_value('cmdheight', 0, {})
screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
|
@@ -497,7 +533,7 @@ describe('global statusline', function()
^0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
{2:test/functional/fixtures/bigfile.txt 8,1 0%}|
]])
- meths.set_option('cmdheight', 1)
+ meths.set_option_value('cmdheight', 1, {})
screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
|
@@ -521,8 +557,8 @@ end)
it('statusline does not crash if it has Arabic characters #19447', function()
clear()
- meths.set_option('statusline', 'غً')
- meths.set_option('laststatus', 2)
+ meths.set_option_value('statusline', 'غً', {})
+ meths.set_option_value('laststatus', 2, {})
command('redraw!')
assert_alive()
end)
@@ -589,3 +625,195 @@ it('showcmdloc=statusline does not show if statusline is too narrow', function()
feed('1234')
screen:expect_unchanged()
end)
+
+it('K_EVENT does not trigger a statusline redraw unnecessarily', function()
+ clear()
+ local screen = Screen.new(40, 8)
+ screen:attach()
+ -- does not redraw on vim.schedule (#17937)
+ command([[
+ set laststatus=2
+ let g:counter = 0
+ func Status()
+ let g:counter += 1
+ lua vim.schedule(function() end)
+ return g:counter
+ endfunc
+ set statusline=%!Status()
+ ]])
+ sleep(50)
+ eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
+ -- also in insert mode
+ feed('i')
+ sleep(50)
+ eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
+ -- does not redraw on timer call (#14303)
+ command([[
+ let g:counter = 0
+ func Timer(timer)
+ endfunc
+ call timer_start(1, 'Timer', {'repeat': 100})
+ ]])
+ sleep(50)
+ eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
+end)
+
+it('statusline is redrawn on various state changes', function()
+ clear()
+ local screen = Screen.new(40, 4)
+ screen:attach()
+
+ -- recording state change #22683
+ command('set ls=2 stl=%{repeat(reg_recording(),5)}')
+ screen:expect([[
+ ^ |
+ ~ |
+ |
+ |
+ ]])
+ feed('qQ')
+ screen:expect([[
+ ^ |
+ ~ |
+ QQQQQ |
+ recording @Q |
+ ]])
+ feed('q')
+ screen:expect([[
+ ^ |
+ ~ |
+ |
+ |
+ ]])
+
+ -- Visual mode change #23932
+ command('set ls=2 stl=%{mode(1)}')
+ screen:expect([[
+ ^ |
+ ~ |
+ n |
+ |
+ ]])
+ feed('v')
+ screen:expect([[
+ ^ |
+ ~ |
+ v |
+ -- VISUAL -- |
+ ]])
+ feed('V')
+ screen:expect([[
+ ^ |
+ ~ |
+ V |
+ -- VISUAL LINE -- |
+ ]])
+ feed('<C-V>')
+ screen:expect([[
+ ^ |
+ ~ |
+ ^V |
+ -- VISUAL BLOCK -- |
+ ]])
+ feed('<Esc>')
+ screen:expect([[
+ ^ |
+ ~ |
+ n |
+ |
+ ]])
+end)
+
+it('ruler is redrawn in cmdline with redrawstatus #22804', function()
+ clear()
+ local screen = Screen.new(40, 2)
+ screen:attach()
+ command([[
+ let g:n = 'initial value'
+ set ls=1 ru ruf=%{g:n}
+ redraw
+ let g:n = 'other value'
+ redrawstatus
+ ]])
+ screen:expect([[
+ ^ |
+ other value |
+ ]])
+end)
+
+it("shows correct ruler in cmdline with no statusline", function()
+ clear()
+ local screen = Screen.new(30, 8)
+ screen:set_default_attr_ids {
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [2] = {bold = true, reverse = true}, -- StatusLine
+ [3] = {reverse = true}, -- StatusLineNC
+ }
+ screen:attach()
+ -- Use long ruler to check 'ruler' with 'rulerformat' set has correct width.
+ command [[
+ set ruler rulerformat=%{winnr()}longlonglong ls=0 winwidth=10
+ split
+ wincmd b
+ vsplit
+ wincmd t
+ wincmd |
+ mode
+ ]]
+ -- Window 1 is current. It has a statusline, so cmdline should show the
+ -- last window's ruler, which has no statusline.
+ command '1wincmd w'
+ screen:expect [[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] 1longlonglong }|
+ │ |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ 3longlonglong |
+ ]]
+ -- Window 2 is current. It has no statusline, so cmdline should show its
+ -- ruler instead.
+ command '2wincmd w'
+ screen:expect [[
+ |
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] 1longlonglong }|
+ ^ │ |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ 2longlonglong |
+ ]]
+ -- Window 3 is current. Cmdline should again show its ruler.
+ command '3wincmd w'
+ screen:expect [[
+ |
+ {1:~ }|
+ {1:~ }|
+ {3:[No Name] 1longlonglong }|
+ │^ |
+ {1:~ }│{1:~ }|
+ {1:~ }│{1:~ }|
+ 3longlonglong |
+ ]]
+end)
+
+it('uses "stl" and "stlnc" fillchars even if they are the same #19803', function()
+ clear()
+ local screen = Screen.new(53, 4)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ command('hi clear StatusLine')
+ command('hi clear StatusLineNC')
+ command('vsplit')
+ screen:expect{grid=[[
+ ^ │ |
+ {1:~ }│{1:~ }|
+ [No Name] [No Name] |
+ |
+ ]]}
+end)
diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua
index 2cdec62d01..befdb7c5d1 100644
--- a/test/functional/ui/tabline_spec.lua
+++ b/test/functional/ui/tabline_spec.lua
@@ -1,6 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, command, eq = helpers.clear, helpers.command, helpers.eq
+local insert = helpers.insert
+local meths = helpers.meths
+local assert_alive = helpers.assert_alive
describe('ui/ext_tabline', function()
local screen
@@ -92,6 +95,10 @@ describe("tabline", function()
clear()
screen = Screen.new(42, 5)
screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [1] = {reverse = true}; -- TabLineFill
+ })
end)
it('redraws when tabline option is set', function()
@@ -100,24 +107,18 @@ describe("tabline", function()
screen:expect{grid=[[
{1:asdf }|
^ |
- {2:~ }|
- {2:~ }|
+ {0:~ }|
+ {0:~ }|
|
- ]], attr_ids={
- [1] = {reverse = true};
- [2] = {bold = true, foreground = Screen.colors.Blue1};
- }}
+ ]]}
command('set tabline=jkl')
screen:expect{grid=[[
{1:jkl }|
^ |
- {2:~ }|
- {2:~ }|
+ {0:~ }|
+ {0:~ }|
|
- ]], attr_ids={
- [1] = {reverse = true};
- [2] = {bold = true, foreground = Screen.colors.Blue};
- }}
+ ]]}
end)
it('click definitions do not leak memory #21765', function()
@@ -125,4 +126,52 @@ describe("tabline", function()
command('set showtabline=2')
command('redrawtabline')
end)
+
+ it('clicks work with truncated double-width label #24187', function()
+ insert('tab1')
+ command('tabnew')
+ insert('tab2')
+ command('tabprev')
+ meths.set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {})
+ screen:expect{grid=[[
+ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
+ tab^1 |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ meths.input_mouse('left', 'press', '', 0, 0, 1)
+ screen:expect{grid=[[
+ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
+ tab^2 |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ meths.input_mouse('left', 'press', '', 0, 0, 0)
+ screen:expect{grid=[[
+ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
+ tab^1 |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ meths.input_mouse('left', 'press', '', 0, 0, 39)
+ screen:expect{grid=[[
+ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
+ tab^2 |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ meths.input_mouse('left', 'press', '', 0, 0, 40)
+ screen:expect{grid=[[
+ tab^1 |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end)
end)
diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua
new file mode 100644
index 0000000000..66c0ff5c9c
--- /dev/null
+++ b/test/functional/ui/title_spec.lua
@@ -0,0 +1,138 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local command = helpers.command
+local curwin = helpers.curwin
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local feed = helpers.feed
+local funcs = helpers.funcs
+local meths = helpers.meths
+local is_os = helpers.is_os
+
+describe('title', function()
+ local screen
+
+ before_each(function()
+ clear()
+ screen = Screen.new()
+ screen:attach()
+ end)
+
+ it('has correct default title with unnamed file', function()
+ local expected = '[No Name] - NVIM'
+ command('set title')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('has correct default title with named file', function()
+ local expected = (is_os('win') and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM')
+ command('set title')
+ command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ describe('is not changed by', function()
+ local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
+ local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2'
+ local expected = (is_os('win') and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM')
+ local buf2
+
+ before_each(function()
+ command('edit '..file1)
+ buf2 = funcs.bufadd(file2)
+ command('set title')
+ end)
+
+ it('calling setbufvar() to set an option in a hidden buffer from i_CTRL-R', function()
+ command([[inoremap <F2> <C-R>=setbufvar(]]..buf2..[[, '&autoindent', 1) ?? ''<CR>]])
+ feed('i<F2><Esc>')
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('an RPC call to nvim_set_option_value in a hidden buffer', function()
+ meths.set_option_value('autoindent', true, { buf = buf2 })
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('a Lua callback calling nvim_set_option_value in a hidden buffer', function()
+ exec_lua(string.format([[
+ vim.schedule(function()
+ vim.api.nvim_set_option_value('autoindent', true, { buf = %d })
+ end)
+ ]], buf2))
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('a Lua callback calling nvim_buf_call in a hidden buffer', function()
+ exec_lua(string.format([[
+ vim.schedule(function()
+ vim.api.nvim_buf_call(%d, function() end)
+ end)
+ ]], buf2))
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('setting the buffer of another window using RPC', function()
+ local oldwin = curwin().id
+ command('split')
+ meths.win_set_buf(oldwin, buf2)
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('setting the buffer of another window using Lua callback', function()
+ local oldwin = curwin().id
+ command('split')
+ exec_lua(string.format([[
+ vim.schedule(function()
+ vim.api.nvim_win_set_buf(%d, %d)
+ end)
+ ]], oldwin, buf2))
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('creating a floating window using RPC', function()
+ meths.open_win(buf2, false, {
+ relative = 'editor', width = 5, height = 5, row = 0, col = 0,
+ })
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+
+ it('creating a floating window using Lua callback', function()
+ exec_lua(string.format([[
+ vim.api.nvim_open_win(%d, false, {
+ relative = 'editor', width = 5, height = 5, row = 0, col = 0,
+ })
+ ]], buf2))
+ command('redraw!')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end)
+ end)
+end)
diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua
index 50466c9473..3201135b67 100644
--- a/test/functional/ui/wildmode_spec.lua
+++ b/test/functional/ui/wildmode_spec.lua
@@ -17,6 +17,85 @@ describe("'wildmenu'", function()
screen:attach()
end)
+ -- oldtest: Test_wildmenu_screendump()
+ it('works', function()
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
+ [1] = {foreground = Screen.colors.Black, background = Screen.colors.Yellow}; -- WildMenu
+ [2] = {bold = true, reverse = true}; -- StatusLine
+ })
+ -- Test simple wildmenu
+ feed(':sign <Tab>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {1:define}{2: jump list > }|
+ :sign define^ |
+ ]]}
+
+ feed('<Tab>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {2:define }{1:jump}{2: list > }|
+ :sign jump^ |
+ ]]}
+
+ feed('<Tab>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {2:define jump }{1:list}{2: > }|
+ :sign list^ |
+ ]]}
+
+ -- Looped back to the original value
+ feed('<Tab><Tab><Tab><Tab>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {2:define jump list > }|
+ :sign ^ |
+ ]]}
+
+ -- Test that the wild menu is cleared properly
+ feed('<Space>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ :sign ^ |
+ ]]}
+
+ -- Test that a different wildchar still works
+ feed('<Esc>')
+ command('set wildchar=<Esc>')
+ feed(':sign <Esc>')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ {1:define}{2: jump list > }|
+ :sign define^ |
+ ]]}
+
+ -- Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
+ -- sure clean up is properly done in edge case like this.
+ feed('<Esc>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ end)
+
it('C-E to cancel wildmenu completion restore original input', function()
feed(':sign <tab>')
screen:expect([[
@@ -367,12 +446,12 @@ describe("'wildmenu'", function()
}
-- Wildcharm? where we are going we aint't no need no wildcharm.
- eq(0, meths.get_option'wildcharm')
+ eq(0, meths.get_option_value('wildcharm', {}))
-- Don't mess the defaults yet (neovim is about backwards compatibility)
- eq(9, meths.get_option'wildchar')
+ eq(9, meths.get_option_value('wildchar', {}))
-- Lol what is cnoremap? Some say it can define mappings.
command 'set wildchar=0'
- eq(0, meths.get_option'wildchar')
+ eq(0, meths.get_option_value('wildchar', {}))
command 'cnoremap <f2> <c-z>'
feed(':syntax <f2>')
@@ -481,9 +560,9 @@ describe('command line completion', function()
end)
it('does not leak memory with <S-Tab> with wildmenu and only one match #19874', function()
- meths.set_option('wildmenu', true)
- meths.set_option('wildmode', 'full')
- meths.set_option('wildoptions', 'pum')
+ meths.set_option_value('wildmenu', true, {})
+ meths.set_option_value('wildmode', 'full', {})
+ meths.set_option_value('wildoptions', 'pum', {})
feed(':sign unpla<S-Tab>')
screen:expect([[
@@ -505,8 +584,8 @@ describe('command line completion', function()
end)
it('does not show matches with <S-Tab> without wildmenu with wildmode=full', function()
- meths.set_option('wildmenu', false)
- meths.set_option('wildmode', 'full')
+ meths.set_option_value('wildmenu', false, {})
+ meths.set_option_value('wildmode', 'full', {})
feed(':sign <S-Tab>')
screen:expect([[
@@ -519,8 +598,8 @@ describe('command line completion', function()
end)
it('shows matches with <S-Tab> without wildmenu with wildmode=list', function()
- meths.set_option('wildmenu', false)
- meths.set_option('wildmode', 'list')
+ meths.set_option_value('wildmenu', false, {})
+ meths.set_option_value('wildmode', 'list', {})
feed(':sign <S-Tab>')
screen:expect([[
diff --git a/test/functional/ui/winbar_spec.lua b/test/functional/ui/winbar_spec.lua
index ece27ec3ff..78bbcd3a63 100644
--- a/test/functional/ui/winbar_spec.lua
+++ b/test/functional/ui/winbar_spec.lua
@@ -31,7 +31,7 @@ describe('winbar', function()
[10] = {background = Screen.colors.LightGrey, underline = true},
[11] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta},
})
- meths.set_option('winbar', 'Set Up The Bars')
+ meths.set_option_value('winbar', 'Set Up The Bars', {})
end)
it('works', function()
@@ -114,6 +114,41 @@ describe('winbar', function()
{2:[No Name] [No Name] }|
|
]])
+ -- 'showcmdloc' "statusline" should not interfere with winbar redrawing #23030
+ command('set showcmd showcmdloc=statusline')
+ feed('<C-W>w')
+ feed('<C-W>')
+ screen:expect([[
+ {6:Set Up The Bars }│{6:Set Up The Bars }|
+ │ |
+ {3:~ }│{3:~ }|
+ {3:~ }│{2:[No Name] }|
+ {3:~ }│{5:Set Up The Bars }|
+ {3:~ }│^ |
+ {3:~ }│{3:~ }|
+ {3:~ }│{4:[No Name] ^W }|
+ {3:~ }│{6:Set Up The Bars }|
+ {3:~ }│ |
+ {3:~ }│{3:~ }|
+ {2:[No Name] [No Name] }|
+ |
+ ]])
+ feed('w<C-W>W')
+ screen:expect([[
+ {6:Set Up The Bars }│{6:Set Up The Bars }|
+ │ |
+ {3:~ }│{3:~ }|
+ {3:~ }│{2:[No Name] }|
+ {3:~ }│{5:Set Up The Bars }|
+ {3:~ }│^ |
+ {3:~ }│{3:~ }|
+ {3:~ }│{4:[No Name] }|
+ {3:~ }│{6:Set Up The Bars }|
+ {3:~ }│ |
+ {3:~ }│{3:~ }|
+ {2:[No Name] [No Name] }|
+ |
+ ]])
end)
it('works when switching value of \'winbar\'', function()
@@ -171,7 +206,7 @@ describe('winbar', function()
insert [[
just some
random text]]
- meths.set_option('winbar', 'Hello, I am a ruler: %l,%c')
+ meths.set_option_value('winbar', 'Hello, I am a ruler: %l,%c', {})
screen:expect{grid=[[
{1:Hello, I am a ruler: 2,11 }|
just some |
@@ -415,7 +450,7 @@ describe('winbar', function()
|
|
]])
- eq(3, meths.get_option('cmdheight'))
+ eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 1, 11, 10)
screen:expect([[
@@ -433,7 +468,7 @@ describe('winbar', function()
{2:[No Name] }|
|
]])
- eq(1, meths.get_option('cmdheight'))
+ eq(1, meths.get_option_value('cmdheight', {}))
end)
it('properly equalizes window height for window-local value', function()
@@ -678,3 +713,26 @@ describe('local winbar with tabs', function()
]]}
end)
end)
+
+it('winbar works properly when redrawing is postponed #23534', function()
+ clear({args = {
+ '-c', 'set laststatus=2 lazyredraw',
+ '-c', 'setlocal statusline=(statusline) winbar=(winbar)',
+ '-c', 'call nvim_input(":<Esc>")',
+ }})
+ local screen = Screen.new(60, 6)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [0] = {foreground = Screen.colors.Blue, bold = true},
+ [1] = {bold = true},
+ [2] = {bold = true, reverse = true},
+ })
+ screen:expect([[
+ {1:(winbar) }|
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {2:(statusline) }|
+ |
+ ]])
+end)
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua
index c032ac3030..0a7e7c1137 100644
--- a/test/functional/vimscript/api_functions_spec.lua
+++ b/test/functional/vimscript/api_functions_spec.lua
@@ -1,12 +1,13 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
-local lfs = require('lfs')
+local luv = require('luv')
local neq, eq, command = helpers.neq, helpers.eq, helpers.command
local clear, curbufmeths = helpers.clear, helpers.curbufmeths
local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval
local insert, pcall_err = helpers.insert, helpers.pcall_err
local matches = helpers.matches
local meths = helpers.meths
+local feed = helpers.feed
describe('eval-API', function()
before_each(clear)
@@ -32,8 +33,8 @@ describe('eval-API', function()
local err = exc_exec('call nvim_get_current_buf("foo")')
eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err)
- err = exc_exec('call nvim_set_option("hlsearch")')
- eq('Vim(call):E119: Not enough arguments for function: nvim_set_option', err)
+ err = exc_exec('call nvim_set_option_value("hlsearch")')
+ eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err)
err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])')
eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err)
@@ -48,10 +49,47 @@ describe('eval-API', function()
eq('Vim(call):E5555: API call: Invalid buffer id: 17', err)
end)
- it('cannot change texts if textlocked', function()
+ it('cannot change text or window if textlocked', function()
command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])")
matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$',
pcall_err(command, "normal! yy"))
+
+ command("autocmd TextYankPost <buffer> ++once call nvim_open_term(0, {})")
+ matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$',
+ pcall_err(command, "normal! yy"))
+
+ -- Functions checking textlock should also not be usable from <expr> mappings.
+ command("inoremap <expr> <f2> nvim_win_close(0, 1)")
+ eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window',
+ pcall_err(command, [[execute "normal i\<f2>"]]))
+
+ -- Text-changing functions gave a "Failed to save undo information" error when called from an
+ -- <expr> mapping outside do_cmdline() (msg_list == NULL), so use feed() to test this.
+ command("inoremap <expr> <f2> nvim_buf_set_text(0, 0, 0, 0, 0, ['hi'])")
+ meths.set_vvar('errmsg', '')
+ feed("i<f2><esc>")
+ eq('E5555: API call: E565: Not allowed to change text or change window',
+ meths.get_vvar('errmsg'))
+
+ -- Some functions checking textlock (usually those that may change the current window or buffer)
+ -- also ought to not be usable in the cmdwin.
+ local old_win = meths.get_current_win()
+ feed("q:")
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.set_current_win, old_win))
+
+ -- But others, like nvim_buf_set_lines(), which just changes text, is OK.
+ curbufmeths.set_lines(0, -1, 1, {"wow!"})
+ eq({'wow!'}, curbufmeths.get_lines(0, -1, 1))
+
+ -- Turning the cmdwin buffer into a terminal buffer would be pretty weird.
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.open_term, 0, {}))
+
+ -- But turning a different buffer into a terminal from the cmdwin is OK.
+ local term_buf = meths.create_buf(false, true)
+ meths.open_term(term_buf, {})
+ eq('terminal', meths.get_option_value("buftype", {buf = term_buf}))
end)
it("use buffer numbers and windows ids as handles", function()
@@ -118,7 +156,7 @@ describe('eval-API', function()
end)
it('are highlighted by vim.vim syntax file', function()
- if lfs.attributes("build/runtime/syntax/vim/generated.vim",'uid') == nil then
+ if luv.fs_stat("build/runtime/syntax/vim/generated.vim").uid == nil then
pending("runtime was not built, skipping test")
return
end
@@ -133,7 +171,7 @@ describe('eval-API', function()
})
command("set ft=vim")
- command("let &rtp='build/runtime/,'.&rtp")
+ command("set rtp^=build/runtime/")
command("syntax on")
insert([[
call bufnr('%')
diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua
index b521620320..2a5720fbd7 100644
--- a/test/functional/vimscript/buf_functions_spec.lua
+++ b/test/functional/vimscript/buf_functions_spec.lua
@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
local eq = helpers.eq
local clear = helpers.clear
@@ -9,13 +9,13 @@ local meths = helpers.meths
local command = helpers.command
local exc_exec = helpers.exc_exec
local bufmeths = helpers.bufmeths
-local winmeths = helpers.winmeths
local curbufmeths = helpers.curbufmeths
local curwinmeths = helpers.curwinmeths
local curtabmeths = helpers.curtabmeths
local get_pathsep = helpers.get_pathsep
local rmdir = helpers.rmdir
local pcall_err = helpers.pcall_err
+local mkdir = helpers.mkdir
local fname = 'Xtest-functional-eval-buf_functions'
local fname2 = fname .. '.2'
@@ -62,7 +62,7 @@ describe('bufname() function', function()
eq('', funcs.bufname('X'))
end)
before_each(function()
- lfs.mkdir(dirname)
+ mkdir(dirname)
end)
after_each(function()
rmdir(dirname)
@@ -70,7 +70,7 @@ describe('bufname() function', function()
it('returns expected buffer name', function()
eq('', funcs.bufname('%')) -- Buffer has no name yet
command('file ' .. fname)
- local wd = lfs.currentdir()
+ local wd = luv.cwd()
local sep = get_pathsep()
local curdirname = funcs.fnamemodify(wd, ':t')
for _, arg in ipairs({'%', 1, 'X', wd}) do
@@ -103,7 +103,7 @@ describe('bufnr() function', function()
it('returns expected buffer number', function()
eq(1, funcs.bufnr('%'))
command('file ' .. fname)
- local wd = lfs.currentdir()
+ local wd = luv.cwd()
local curdirname = funcs.fnamemodify(wd, ':t')
eq(1, funcs.bufnr(fname))
eq(1, funcs.bufnr(wd))
@@ -144,7 +144,7 @@ describe('bufwinnr() function', function()
eq(-1, funcs.bufwinnr('X'))
end)
before_each(function()
- lfs.mkdir(dirname)
+ mkdir(dirname)
end)
after_each(function()
rmdir(dirname)
@@ -188,7 +188,7 @@ describe('getbufline() function', function()
eq({}, funcs.getbufline(1, -1, 9999))
end)
it('returns expected lines', function()
- meths.set_option('hidden', true)
+ meths.set_option_value('hidden', true, {})
command('file ' .. fname)
curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'})
command('edit ' .. fname2)
@@ -268,24 +268,25 @@ describe('setbufvar() function', function()
end)
it('may set options, including window-local and global values', function()
local buf1 = meths.get_current_buf()
- eq(false, curwinmeths.get_option('number'))
+ eq(false, meths.get_option_value('number', {}))
command('split')
command('new')
eq(2, bufmeths.get_number(curwinmeths.get_buf()))
funcs.setbufvar(1, '&number', true)
local windows = curtabmeths.list_wins()
- eq(false, winmeths.get_option(windows[1], 'number'))
- eq(true, winmeths.get_option(windows[2], 'number'))
- eq(false, winmeths.get_option(windows[3], 'number'))
- eq(false, winmeths.get_option(meths.get_current_win(), 'number'))
+ eq(false, meths.get_option_value('number', {win=windows[1].id}))
+ eq(true, meths.get_option_value('number', {win=windows[2].id}))
+ eq(false, meths.get_option_value('number', {win=windows[3].id}))
+ eq(false, meths.get_option_value('number', {win=meths.get_current_win().id}))
- eq(true, meths.get_option('hidden'))
+
+ eq(true, meths.get_option_value('hidden', {}))
funcs.setbufvar(1, '&hidden', 0)
- eq(false, meths.get_option('hidden'))
+ eq(false, meths.get_option_value('hidden', {}))
- eq(false, bufmeths.get_option(buf1, 'autoindent'))
+ eq(false, meths.get_option_value('autoindent', {buf=buf1.id}))
funcs.setbufvar(1, '&autoindent', true)
- eq(true, bufmeths.get_option(buf1, 'autoindent'))
+ eq(true, meths.get_option_value('autoindent', {buf=buf1.id}))
eq('Vim(call):E355: Unknown option: xxx',
exc_exec('call setbufvar(1, "&xxx", 0)'))
end)
diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua
index 5ee84a6d13..17607f0794 100644
--- a/test/functional/vimscript/ctx_functions_spec.lua
+++ b/test/functional/vimscript/ctx_functions_spec.lua
@@ -375,6 +375,12 @@ describe('context functions', function()
eq(outofbounds, pcall_err(call, 'ctxset', {dummy = 1}, 0))
end)
+ it('errors when context dictionary is invalid', function()
+ call('ctxpush')
+ eq('Vim:E474: Failed to convert list to msgpack string buffer',
+ pcall_err(call, 'ctxset', { regs = { {} }, jumps = { {} } }))
+ end)
+
it('sets context dictionary at index in context stack', function()
nvim('set_var', 'one', 1)
nvim('set_var', 'Two', 2)
diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua
index 9e19568249..52218d3cc9 100644
--- a/test/functional/vimscript/environ_spec.lua
+++ b/test/functional/vimscript/environ_spec.lua
@@ -26,6 +26,8 @@ end)
describe('empty $HOME', function()
local original_home = os.getenv('HOME')
+ before_each(clear)
+
-- recover $HOME after each test
after_each(function()
if original_home ~= nil then
diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua
index a8a901042b..ab0ffccd4d 100644
--- a/test/functional/vimscript/eval_spec.lua
+++ b/test/functional/vimscript/eval_spec.lua
@@ -12,7 +12,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
-local lfs = require('lfs')
+local mkdir = helpers.mkdir
local clear = helpers.clear
local eq = helpers.eq
local exc_exec = helpers.exc_exec
@@ -56,11 +56,11 @@ end)
describe("backtick expansion", function()
setup(function()
clear()
- lfs.mkdir("test-backticks")
+ mkdir("test-backticks")
write_file("test-backticks/file1", "test file 1")
write_file("test-backticks/file2", "test file 2")
write_file("test-backticks/file3", "test file 3")
- lfs.mkdir("test-backticks/subdir")
+ mkdir("test-backticks/subdir")
write_file("test-backticks/subdir/file4", "test file 4")
-- Long path might cause "Press ENTER" prompt; use :silent to avoid it.
command('silent cd test-backticks')
@@ -153,11 +153,6 @@ end)
describe("uncaught exception", function()
before_each(clear)
- after_each(function()
- os.remove('throw1.vim')
- os.remove('throw2.vim')
- os.remove('throw3.vim')
- end)
it('is not forgotten #13490', function()
command('autocmd BufWinEnter * throw "i am error"')
@@ -173,10 +168,45 @@ describe("uncaught exception", function()
let result ..= 'X'
]]):format(i, i))
end
+ finally(function()
+ for i = 1, 3 do
+ os.remove('throw' .. i .. '.vim')
+ end
+ end)
+
command('set runtimepath+=. | let result = ""')
eq('throw1', exc_exec('try | runtime! throw*.vim | endtry'))
eq('123', eval('result'))
end)
+
+ it('multiline exception remains multiline #25350', function()
+ local screen = Screen.new(80, 11)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, reverse = true}; -- MsgSeparator
+ [2] = {foreground = Screen.colors.White, background = Screen.colors.Red}; -- ErrorMsg
+ [3] = {bold = true, foreground = Screen.colors.SeaGreen}; -- MoreMsg
+ })
+ screen:attach()
+ exec_lua([[
+ function _G.Oops()
+ error("oops")
+ end
+ ]])
+ feed(':try\rlua _G.Oops()\rendtry\r')
+ screen:expect{grid=[[
+ {1: }|
+ :try |
+ : lua _G.Oops() |
+ : endtry |
+ {2:Error detected while processing :} |
+ {2:E5108: Error executing lua [string "<nvim>"]:2: oops} |
+ {2:stack traceback:} |
+ {2: [C]: in function 'error'} |
+ {2: [string "<nvim>"]:2: in function 'Oops'} |
+ {2: [string ":lua"]:1: in main chunk} |
+ {3:Press ENTER or type command to continue}^ |
+ ]]}
+ end)
end)
describe('listing functions using :function', function()
@@ -191,11 +221,10 @@ describe('listing functions using :function', function()
endfunction]]):format(num), exec_capture(('function <lambda>%s'):format(num)))
end)
- -- FIXME: If the same function is deleted, the crash still happens. #20790
it('does not crash if another function is deleted while listing', function()
local screen = Screen.new(80, 24)
screen:attach()
- matches('Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[
+ matches('Vim%(function%):E454: Function list was modified$', pcall_err(exec_lua, [=[
vim.cmd([[
func Func1()
endfunc
@@ -219,4 +248,67 @@ describe('listing functions using :function', function()
]=]))
assert_alive()
end)
+
+ it('does not crash if the same function is deleted while listing', function()
+ local screen = Screen.new(80, 24)
+ screen:attach()
+ matches('Vim%(function%):E454: Function list was modified$', pcall_err(exec_lua, [=[
+ vim.cmd([[
+ func Func1()
+ endfunc
+ func Func2()
+ endfunc
+ func Func3()
+ endfunc
+ ]])
+
+ local ns = vim.api.nvim_create_namespace('test')
+
+ vim.ui_attach(ns, { ext_messages = true }, function(event, _, content)
+ if event == 'msg_show' and content[1][2] == 'function Func1()' then
+ vim.cmd('delfunc Func2')
+ end
+ end)
+
+ vim.cmd('function')
+
+ vim.ui_detach(ns)
+ ]=]))
+ assert_alive()
+ end)
+end)
+
+it('no double-free in garbage collection #16287', function()
+ clear()
+ -- Don't use exec() here as using a named script reproduces the issue better.
+ write_file('Xgarbagecollect.vim', [[
+ func Foo() abort
+ let s:args = [a:000]
+ let foo0 = ""
+ let foo1 = ""
+ let foo2 = ""
+ let foo3 = ""
+ let foo4 = ""
+ let foo5 = ""
+ let foo6 = ""
+ let foo7 = ""
+ let foo8 = ""
+ let foo9 = ""
+ let foo10 = ""
+ let foo11 = ""
+ let foo12 = ""
+ let foo13 = ""
+ let foo14 = ""
+ endfunc
+
+ set updatetime=1
+ call Foo()
+ call Foo()
+ ]])
+ finally(function()
+ os.remove('Xgarbagecollect.vim')
+ end)
+ command('source Xgarbagecollect.vim')
+ sleep(10)
+ assert_alive()
end)
diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua
index 43e4a29e1a..2b8e3f6218 100644
--- a/test/functional/vimscript/executable_spec.lua
+++ b/test/functional/vimscript/executable_spec.lua
@@ -137,12 +137,16 @@ describe('executable() (Windows)', function()
end)
it('system([…]), jobstart([…]) use $PATHEXT #9569', function()
+ -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
+ clear({env={PATHEXT=''}})
-- Invoking `cmdscript` should find/execute `cmdscript.cmd`.
eq('much success\n', call('system', {'test/functional/fixtures/cmdscript'}))
assert(0 < call('jobstart', {'test/functional/fixtures/cmdscript'}))
end)
it('full path with extension', function()
+ -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
+ clear({env={PATHEXT=''}})
-- Some executable we can expect in the test env.
local exe = 'printargs-test'
local exedir = eval("fnamemodify(v:progpath, ':h')")
@@ -153,6 +157,8 @@ describe('executable() (Windows)', function()
end)
it('full path without extension', function()
+ -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
+ clear({env={PATHEXT=''}})
-- Some executable we can expect in the test env.
local exe = 'printargs-test'
local exedir = eval("fnamemodify(v:progpath, ':h')")
diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua
index 5fe3d787cb..bb28938708 100644
--- a/test/functional/vimscript/execute_spec.lua
+++ b/test/functional/vimscript/execute_spec.lua
@@ -4,6 +4,7 @@ local eval = helpers.eval
local clear = helpers.clear
local source = helpers.source
local exc_exec = helpers.exc_exec
+local pcall_err = helpers.pcall_err
local funcs = helpers.funcs
local Screen = require('test.functional.ui.screen')
local command = helpers.command
@@ -92,18 +93,14 @@ describe('execute()', function()
it('captures errors', function()
local ret
- ret = exc_exec('call execute(0.0)')
- eq('Vim(call):E806: using Float as a String', ret)
ret = exc_exec('call execute(v:_null_dict)')
- eq('Vim(call):E731: using Dictionary as a String', ret)
+ eq('Vim(call):E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(function("tr"))')
- eq('Vim(call):E729: using Funcref as a String', ret)
- ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])')
- eq('Vim:E806: using Float as a String', ret)
+ eq('Vim(call):E729: Using a Funcref as a String', ret)
ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])')
- eq('Vim:E731: using Dictionary as a String', ret)
+ eq('Vim:E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])')
- eq('Vim:E729: using Funcref as a String', ret)
+ eq('Vim:E729: Using a Funcref as a String', ret)
end)
it('captures output with highlights', function()
@@ -284,6 +281,14 @@ describe('execute()', function()
eq('42', eval('g:mes'))
end)
+ it('gives E493 instead of prompting on backwards range for ""', function()
+ command('split')
+ eq('Vim(windo):E493: Backwards range given: 2,1windo echo',
+ pcall_err(funcs.execute, '2,1windo echo', ''))
+ eq('Vim(windo):E493: Backwards range given: 2,1windo echo',
+ pcall_err(funcs.execute, {'2,1windo echo'}, ''))
+ end)
+
it('captures but does not display output for "silent"', function()
local screen = Screen.new(40, 5)
screen:attach()
@@ -321,11 +326,8 @@ describe('execute()', function()
it('propagates errors for "" and "silent"', function()
local ret
- ret = exc_exec('call execute(0.0, "")')
- eq('Vim(call):E806: using Float as a String', ret)
-
ret = exc_exec('call execute(v:_null_dict, "silent")')
- eq('Vim(call):E731: using Dictionary as a String', ret)
+ eq('Vim(call):E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute("echo add(1, 1)", "")')
eq('Vim(echo):E897: List or Blob required', ret)
diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua
index 056f67e0ad..da3d61cbe0 100644
--- a/test/functional/vimscript/exepath_spec.lua
+++ b/test/functional/vimscript/exepath_spec.lua
@@ -5,21 +5,21 @@ local command = helpers.command
local exc_exec = helpers.exc_exec
local matches = helpers.matches
local is_os = helpers.is_os
+local set_shell_powershell = helpers.set_shell_powershell
+local eval = helpers.eval
+
+local find_dummies = function(ext_pat)
+ local tmp_path = eval('$PATH')
+ command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
+ matches('null' .. ext_pat, call('exepath', 'null'))
+ matches('true' .. ext_pat, call('exepath', 'true'))
+ matches('false' .. ext_pat, call('exepath', 'false'))
+ command("let $PATH = '"..tmp_path.."'")
+end
describe('exepath()', function()
before_each(clear)
- it('returns 1 for commands in $PATH', function()
- local exe = is_os('win') and 'ping' or 'ls'
- local ext_pat = is_os('win') and '%.EXE$' or '$'
- matches(exe .. ext_pat, call('exepath', exe))
- command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
- ext_pat = is_os('win') and '%.CMD$' or '$'
- matches('null' .. ext_pat, call('exepath', 'null'))
- matches('true' .. ext_pat, call('exepath', 'true'))
- matches('false' .. ext_pat, call('exepath', 'false'))
- end)
-
it('fails for invalid values', function()
for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')'))
@@ -32,11 +32,32 @@ describe('exepath()', function()
end)
if is_os('win') then
+ it('returns 1 for commands in $PATH (Windows)', function()
+ local exe = 'ping'
+ matches(exe .. '%.EXE$', call('exepath', exe))
+ end)
+
it('append extension if omitted', function()
local filename = 'cmd'
local pathext = '.exe'
clear({env={PATHEXT=pathext}})
eq(call('exepath', filename..pathext), call('exepath', filename))
end)
+
+ it('returns file WITH extension if files both with and without extension exist in $PATH', function()
+ local ext_pat = '%.CMD$'
+ find_dummies(ext_pat)
+ set_shell_powershell()
+ find_dummies(ext_pat)
+ end)
+ else
+ it('returns 1 for commands in $PATH (not Windows)', function()
+ local exe = 'ls'
+ matches(exe .. '$', call('exepath', exe))
+ end)
+
+ it('returns file WITHOUT extension if files both with and without extension exist in $PATH', function()
+ find_dummies('$')
+ end)
end
end)
diff --git a/test/functional/vimscript/glob_spec.lua b/test/functional/vimscript/glob_spec.lua
index b8807ecfcc..948a63f050 100644
--- a/test/functional/vimscript/glob_spec.lua
+++ b/test/functional/vimscript/glob_spec.lua
@@ -1,17 +1,18 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq
+local mkdir = helpers.mkdir
before_each(function()
clear()
- lfs.mkdir('test-glob')
+ mkdir('test-glob')
-- Long path might cause "Press ENTER" prompt; use :silent to avoid it.
command('silent cd test-glob')
end)
after_each(function()
- lfs.rmdir('test-glob')
+ luv.fs_rmdir('test-glob')
end)
describe('glob()', function()
diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua
index 2e26d603b3..78a761d370 100644
--- a/test/functional/vimscript/has_spec.lua
+++ b/test/functional/vimscript/has_spec.lua
@@ -1,8 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
+local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local connect = helpers.connect
+local eq = helpers.eq
local funcs = helpers.funcs
local is_os = helpers.is_os
+local nvim_prog = helpers.nvim_prog
describe('has()', function()
before_each(clear)
@@ -69,8 +72,22 @@ describe('has()', function()
end
end)
+ it('"gui_running"', function()
+ eq(0, funcs.has('gui_running'))
+ local tui = Screen.new(50,15)
+ local gui_session = connect(funcs.serverstart())
+ local gui = Screen.new(50,15)
+ eq(0, funcs.has('gui_running'))
+ tui:attach({ext_linegrid=true, rgb=true, stdin_tty=true, stdout_tty=true})
+ gui:attach({ext_multigrid=true, rgb=true}, gui_session)
+ eq(1, funcs.has('gui_running'))
+ tui:detach()
+ eq(1, funcs.has('gui_running'))
+ gui:detach()
+ eq(0, funcs.has('gui_running'))
+ end)
+
it('does not change v:shell_error', function()
- local nvim_prog = helpers.nvim_prog
funcs.system({nvim_prog, '-es', '+73cquit'})
funcs.has('python3') -- use a call whose implementation shells out
eq(73, funcs.eval('v:shell_error'))
diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua
index f50b39c2c5..e1179d29cc 100644
--- a/test/functional/vimscript/input_spec.lua
+++ b/test/functional/vimscript/input_spec.lua
@@ -222,17 +222,17 @@ describe('input()', function()
eq('DEF2', meths.get_var('var'))
end)
it('errors out on invalid inputs', function()
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input([])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input("", [])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input("", "", [])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input({"prompt": []})'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input({"default": []})'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call input({"completion": []})'))
eq('Vim(call):E5050: {opts} must be the only argument',
exc_exec('call input({}, "default")'))
@@ -418,17 +418,17 @@ describe('inputdialog()', function()
eq('DEF2', meths.get_var('var'))
end)
it('errors out on invalid inputs', function()
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog([])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog("", [])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog("", "", [])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog({"prompt": []})'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog({"default": []})'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
exc_exec('call inputdialog({"completion": []})'))
eq('Vim(call):E5050: {opts} must be the only argument',
exc_exec('call inputdialog({}, "default")'))
@@ -452,8 +452,8 @@ end)
describe('confirm()', function()
-- oldtest: Test_confirm()
it('works', function()
- meths.set_option('more', false) -- Avoid hit-enter prompt
- meths.set_option('laststatus', 2)
+ meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt
+ meths.set_option_value('laststatus', 2, {})
-- screen:expect() calls are needed to avoid feeding input too early
screen:expect({any = '%[No Name%]'})
@@ -512,13 +512,13 @@ describe('confirm()', function()
eq(1, meths.get_var('a'))
end
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
pcall_err(command, 'call confirm([])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
pcall_err(command, 'call confirm("Are you sure?", [])'))
eq('Vim(call):E745: Using a List as a Number',
pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", [])'))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])'))
end)
@@ -552,7 +552,7 @@ describe('confirm()', function()
feed(':silent edit foo<cr>')
check_and_clear(':silent edit foo |\n')
- -- With API (via eval/VimL) call and shortmess+=F
+ -- With API (via eval/Vimscript) call and shortmess+=F
feed(':call nvim_command("edit x")<cr>')
check_and_clear(':call nvim_command("edit |\n')
diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua
index 70d0934756..a9dab8431c 100644
--- a/test/functional/vimscript/json_functions_spec.lua
+++ b/test/functional/vimscript/json_functions_spec.lua
@@ -754,7 +754,7 @@ describe('json_encode() function', function()
end)
it('ignores improper values in &isprint', function()
- meths.set_option('isprint', '1')
+ meths.set_option_value('isprint', '1', {})
eq(1, eval('"\1" =~# "\\\\p"'))
eq('"\\u0001"', funcs.json_encode('\1'))
end)
diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua
index 164fa86452..11417c5846 100644
--- a/test/functional/vimscript/let_spec.lua
+++ b/test/functional/vimscript/let_spec.lua
@@ -92,6 +92,20 @@ describe(':let', function()
]])
eq(1, eval('1'))
end)
+
+ it('can apply operator to boolean option', function()
+ eq(true, meths.get_option_value('equalalways', {}))
+ command('let &equalalways -= 1')
+ eq(false, meths.get_option_value('equalalways', {}))
+ command('let &equalalways += 1')
+ eq(true, meths.get_option_value('equalalways', {}))
+ command('let &equalalways *= 1')
+ eq(true, meths.get_option_value('equalalways', {}))
+ command('let &equalalways /= 1')
+ eq(true, meths.get_option_value('equalalways', {}))
+ command('let &equalalways %= 1')
+ eq(false, meths.get_option_value('equalalways', {}))
+ end)
end)
describe(':let and :const', function()
diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua
index ba1b4d7a76..acba5e9708 100644
--- a/test/functional/vimscript/map_functions_spec.lua
+++ b/test/functional/vimscript/map_functions_spec.lua
@@ -26,9 +26,12 @@ describe('maparg()', function()
rhs='bar',
expr=0,
sid=0,
+ scriptversion=1,
buffer=0,
nowait=0,
mode='n',
+ mode_bits=0x01,
+ abbr=0,
noremap=1,
lnum=0,
}
@@ -155,10 +158,13 @@ describe('maparg()', function()
buffer = 0,
expr = 0,
mode = 'n',
+ mode_bits = 0x01,
+ abbr = 0,
noremap = 1,
nowait = 0,
- script=0,
+ script = 0,
sid = 0,
+ scriptversion = 1,
silent = 0,
lnum = 0,
}
@@ -246,9 +252,9 @@ describe('mapset()', function()
end)
it('does not leak memory if lhs is missing', function()
- eq('Vim:E460: entries missing in mapset() dict argument',
+ eq('Vim:E460: Entries missing in mapset() dict argument',
pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]]))
- eq('Vim:E460: entries missing in mapset() dict argument',
+ eq('Vim:E460: Entries missing in mapset() dict argument',
pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]]))
end)
end)
diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua
index 1153baac46..d4c36d835b 100644
--- a/test/functional/vimscript/null_spec.lua
+++ b/test/functional/vimscript/null_spec.lua
@@ -53,19 +53,15 @@ describe('NULL', function()
end)
end
describe('list', function()
- -- Incorrect behaviour
- -- FIXME Should error out with different message
- null_test('makes :unlet act as if it is not a list', ':unlet L[0]',
- 'Vim(unlet):E689: Can only index a List, Dictionary or Blob')
-
-- Subjectable behaviour
-
null_expr_test('is equal to empty list', 'L == []', 0, 1)
null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 1)
-- Correct behaviour
+ null_test('can be :unlet item with error message for empty list', ':unlet L[0]',
+ 'Vim(unlet):E684: List index out of range: 0')
null_expr_test('can be indexed with error message for empty list', 'L[0]',
- 'E684: list index out of range: 0', nil)
+ 'E684: List index out of range: 0', nil)
null_expr_test('can be splice-indexed', 'L[:]', 0, {})
null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0)
null_test('is accepted by :for', 'for x in L|throw x|endfor', 0)
@@ -80,7 +76,7 @@ describe('NULL', function()
null_expr_test('can be copied', 'copy(L)', 0, {})
null_expr_test('can be deepcopied', 'deepcopy(L)', 0, {})
null_expr_test('does not crash when indexed', 'L[1]',
- 'E684: list index out of range: 1', nil)
+ 'E684: List index out of range: 1', nil)
null_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0)
null_expr_test('does not crash col()', 'col(L)', 0, 0)
null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0)
diff --git a/test/functional/vimscript/screenpos_spec.lua b/test/functional/vimscript/screenpos_spec.lua
index 75e5c02298..8b8276457d 100644
--- a/test/functional/vimscript/screenpos_spec.lua
+++ b/test/functional/vimscript/screenpos_spec.lua
@@ -1,12 +1,12 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eq, meths = helpers.clear, helpers.eq, helpers.meths
local command, funcs = helpers.command, helpers.funcs
+local feed = helpers.feed
before_each(clear)
describe('screenpos() function', function()
it('works in floating window with border', function()
- local bufnr = meths.create_buf(false, true)
local opts = {
relative='editor',
height=8,
@@ -18,34 +18,56 @@ describe('screenpos() function', function()
border='none',
focusable=1
}
- local float = meths.open_win(bufnr, false, opts)
+ local float = meths.open_win(meths.create_buf(false, true), false, opts)
command('redraw')
- local pos = funcs.screenpos(bufnr, 1, 1)
- eq(7, pos.row)
- eq(9, pos.col)
+ eq({row = 7, col = 9, endcol = 9, curscol = 9}, funcs.screenpos(float, 1, 1))
-- only left border
opts.border = {'', '', '', '', '', '', '', '|'}
meths.win_set_config(float, opts)
command('redraw')
- pos = funcs.screenpos(bufnr, 1, 1)
- eq(7, pos.row)
- eq(10, pos.col)
+ eq({row = 7, col = 10, endcol = 10, curscol = 10}, funcs.screenpos(float, 1, 1))
-- only top border
opts.border = {'', '_', '', '', '', '', '', ''}
meths.win_set_config(float, opts)
command('redraw')
- pos = funcs.screenpos(bufnr, 1, 1)
- eq(8, pos.row)
- eq(9, pos.col)
+ eq({row = 8, col = 9, endcol = 9, curscol = 9}, funcs.screenpos(float, 1, 1))
-- both left and top border
opts.border = 'single'
meths.win_set_config(float, opts)
command('redraw')
- pos = funcs.screenpos(bufnr, 1, 1)
- eq(8, pos.row)
- eq(10, pos.col)
+ eq({row = 8, col = 10, endcol = 10, curscol = 10}, funcs.screenpos(float, 1, 1))
+ end)
+
+ it('works for folded line with virt_lines attached to line above', function()
+ meths.buf_set_lines(0, 0, -1, true, {'aaa', 'bbb', 'ccc', 'ddd'})
+ local ns = meths.create_namespace('')
+ meths.buf_set_extmark(0, ns, 0, 0, { virt_lines = {{{'abb'}}, {{'acc'}}, {{'add'}}} })
+ command('2,3fold')
+ eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1))
+ eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1))
+ eq({row = 6, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1))
+
+ feed('<C-E>')
+ eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1))
+ eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1))
+ eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1))
+
+ feed('<C-E>')
+ eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1))
+ eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1))
+ eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1))
+
+ feed('<C-E>')
+ eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1))
+ eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1))
+ eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1))
+
+ feed('<C-E>')
+ eq({row = 1, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1))
+ eq({row = 1, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1))
+ eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1))
end)
end)
diff --git a/test/functional/vimscript/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua
index 14ccbc3827..217f0b2c2b 100644
--- a/test/functional/vimscript/special_vars_spec.lua
+++ b/test/functional/vimscript/special_vars_spec.lua
@@ -130,6 +130,12 @@ describe('Special values', function()
eq("v:false", eval('"" . v:false'))
end)
+ it('work with ?? (falsy operator)', function()
+ eq(true, eval('v:true ?? 42'))
+ eq(42, eval('v:false ?? 42'))
+ eq(42, eval('v:null ?? 42'))
+ end)
+
it('work with type()', function()
eq(6, funcs.type(true))
eq(6, funcs.type(false))
diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua
new file mode 100644
index 0000000000..0508b8b1da
--- /dev/null
+++ b/test/functional/vimscript/state_spec.lua
@@ -0,0 +1,86 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+local exec = helpers.exec
+local exec_lua = helpers.exec_lua
+local feed = helpers.feed
+local meths = helpers.meths
+local poke_eventloop = helpers.poke_eventloop
+
+before_each(clear)
+
+describe('state() function', function()
+ -- oldtest: Test_state()
+ it('works', function()
+ meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt
+
+ exec_lua([[
+ function _G.Get_state_mode()
+ _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) }
+ end
+ function _G.Run_timer()
+ local timer = vim.uv.new_timer()
+ timer:start(0, 0, function()
+ _G.Get_state_mode()
+ timer:close()
+ end)
+ end
+ ]])
+ exec([[
+ call setline(1, ['one', 'two', 'three'])
+ map ;; gg
+ set complete=.
+ func RunTimer()
+ call timer_start(0, {id -> v:lua.Get_state_mode()})
+ endfunc
+ au Filetype foobar call v:lua.Get_state_mode()
+ ]])
+
+ -- Using a ":" command Vim is busy, thus "S" is returned
+ feed([[:call v:lua.Get_state_mode()<CR>]])
+ eq({ 'S', 'n' }, exec_lua('return _G.res'))
+
+ -- Using a timer callback
+ feed([[:call RunTimer()<CR>]])
+ poke_eventloop() -- Process pending input
+ poke_eventloop() -- Process time_event
+ eq({ 'c', 'n' }, exec_lua('return _G.res'))
+
+ -- Halfway a mapping
+ feed([[:call v:lua.Run_timer()<CR>;]])
+ meths.get_mode() -- Process pending input and luv timer callback
+ feed(';')
+ eq({ 'mS', 'n' }, exec_lua('return _G.res'))
+
+ -- An operator is pending
+ feed([[:call RunTimer()<CR>y]])
+ poke_eventloop() -- Process pending input
+ poke_eventloop() -- Process time_event
+ feed('y')
+ eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
+
+ -- A register was specified
+ feed([[:call RunTimer()<CR>"r]])
+ poke_eventloop() -- Process pending input
+ poke_eventloop() -- Process time_event
+ feed('yy')
+ eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
+
+ -- Insert mode completion
+ feed([[:call RunTimer()<CR>Got<C-N>]])
+ poke_eventloop() -- Process pending input
+ poke_eventloop() -- Process time_event
+ feed('<Esc>')
+ eq({ 'aSc', 'i' }, exec_lua('return _G.res'))
+
+ -- Autocommand executing
+ feed([[:set filetype=foobar<CR>]])
+ eq({ 'xS', 'n' }, exec_lua('return _G.res'))
+
+ -- messages scrolled
+ feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"<CR>]])
+ meths.get_mode() -- Process pending input and luv timer callback
+ feed('<CR>')
+ eq({ 'Ss', 'r' }, exec_lua('return _G.res'))
+ end)
+end)
diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua
index 7ada1c4bea..90aab48d61 100644
--- a/test/functional/vimscript/system_spec.lua
+++ b/test/functional/vimscript/system_spec.lua
@@ -210,8 +210,8 @@ describe('system()', function()
end)
it('prints verbose information', function()
- nvim('set_option', 'shell', 'fake_shell')
- nvim('set_option', 'shellcmdflag', 'cmdflag')
+ nvim('set_option_value', 'shell', 'fake_shell', {})
+ nvim('set_option_value', 'shellcmdflag', 'cmdflag', {})
screen:try_resize(72, 14)
feed(':4verbose echo system("echo hi")<cr>')
@@ -335,12 +335,12 @@ describe('system()', function()
if is_os('win') then
eq("echoed\n", eval('system("echo echoed")'))
else
- eq("echoed", eval('system("echo -n echoed")'))
+ eq("echoed", eval('system("printf echoed")'))
end
end)
it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. May get E5677.
- feed_command('call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "echo -n echoed &")')
+ feed_command('call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "printf echoed &")')
local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
if v_errnum then
eq("E5677:", v_errnum)
@@ -393,7 +393,7 @@ describe('system()', function()
end)
describe('with output containing NULs', function()
- local fname = 'Xtest'
+ local fname = 'Xtest_functional_vimscript_system_nuls'
before_each(create_file_with_nuls(fname))
after_each(delete_file(fname))
@@ -549,7 +549,7 @@ describe('systemlist()', function()
end)
describe('with output containing NULs', function()
- local fname = 'Xtest'
+ local fname = 'Xtest_functional_vimscript_systemlist_nuls'
before_each(function()
command('set ff=unix')
@@ -644,12 +644,12 @@ describe('shell :!', function()
if is_os('win') then
feed(':4verbose %!sort /R<cr>')
screen:expect{
- any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
+ any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | %%{ "$_" } | Out%-File .*; exit $LastExitCode"]]
}
else
feed(':4verbose %!sort -r<cr>')
screen:expect{
- any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
+ any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | %%{ "$_" } | Out%-File .*; exit $LastExitCode"]]
}
end
feed('<CR>')
diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua
index 1818a71ea2..a58cd6ae7f 100644
--- a/test/functional/vimscript/timer_spec.lua
+++ b/test/functional/vimscript/timer_spec.lua
@@ -251,15 +251,7 @@ describe('timers', function()
:good^ |
]])
command('let g:val = 1')
-
- screen:expect{grid=[[
- |
- {0:~ }|
- {0:~ }|
- {0:~ }|
- {0:~ }|
- :good^ |
- ]], intermediate=true, timeout=load_adjust(200)}
+ screen:expect_unchanged(true, load_adjust(200))
eq(2, eval('g:val'))
end)
diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua
index 8c8da9dc88..88c19bd839 100644
--- a/test/functional/vimscript/writefile_spec.lua
+++ b/test/functional/vimscript/writefile_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
-local lfs = require('lfs')
+local luv = require('luv')
+local mkdir = helpers.mkdir
local clear = helpers.clear
local eq = helpers.eq
local funcs = helpers.funcs
@@ -19,16 +20,16 @@ local ddname_tail = '2'
local ddname = dname .. '/' .. ddname_tail
before_each(function()
- lfs.mkdir(dname)
- lfs.mkdir(ddname)
+ mkdir(dname)
+ mkdir(ddname)
clear()
end)
after_each(function()
os.remove(fname)
os.remove(dfname)
- lfs.rmdir(ddname)
- lfs.rmdir(dname)
+ luv.fs_rmdir(ddname)
+ luv.fs_rmdir(dname)
end)
describe('writefile()', function()
@@ -144,13 +145,11 @@ describe('writefile()', function()
pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname)))
end
for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do
- eq('Vim(call):E806: using Float as a String',
- pcall_err(command, ('call writefile(%s)'):format(args:format('0.0'))))
- eq('Vim(call):E730: using List as a String',
+ eq('Vim(call):E730: Using a List as a String',
pcall_err(command, ('call writefile(%s)'):format(args:format('[]'))))
- eq('Vim(call):E731: using Dictionary as a String',
+ eq('Vim(call):E731: Using a Dictionary as a String',
pcall_err(command, ('call writefile(%s)'):format(args:format('{}'))))
- eq('Vim(call):E729: using Funcref as a String',
+ eq('Vim(call):E729: Using a Funcref as a String',
pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")'))))
end
eq('Vim(call):E5060: Unknown flag: «»',