From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: [PATCH] refactor: format test/* --- test/functional/api/autocmd_spec.lua | 954 +++-- test/functional/api/buffer_updates_spec.lua | 464 ++- test/functional/api/command_spec.lua | 911 +++-- test/functional/api/extmark_spec.lua | 860 ++-- test/functional/api/highlight_spec.lua | 344 +- test/functional/api/keymap_spec.lua | 748 ++-- test/functional/api/menu_spec.lua | 29 +- test/functional/api/proc_spec.lua | 20 +- test/functional/api/rpc_fixture.lua | 10 +- .../api/server_notifications_spec.lua | 45 +- test/functional/api/server_requests_spec.lua | 121 +- test/functional/api/tabpage_spec.lua | 23 +- test/functional/api/ui_spec.lua | 90 +- test/functional/api/version_spec.lua | 155 +- test/functional/api/window_spec.lua | 728 ++-- .../autocmd/autocmd_oldtest_spec.lua | 23 +- test/functional/autocmd/autocmd_spec.lua | 238 +- test/functional/autocmd/bufenter_spec.lua | 25 +- .../autocmd/bufmodifiedset_spec.lua | 4 +- test/functional/autocmd/cmdline_spec.lua | 123 +- test/functional/autocmd/cursorhold_spec.lua | 20 +- test/functional/autocmd/cursormoved_spec.lua | 10 +- test/functional/autocmd/dirchanged_spec.lua | 263 +- test/functional/autocmd/filetype_spec.lua | 16 +- test/functional/autocmd/focus_spec.lua | 43 +- test/functional/autocmd/modechanged_spec.lua | 6 +- .../functional/autocmd/searchwrapped_spec.lua | 3 +- test/functional/autocmd/show_spec.lua | 59 +- test/functional/autocmd/signal_spec.lua | 12 +- test/functional/autocmd/tabclose_spec.lua | 58 +- .../functional/autocmd/tabnewentered_spec.lua | 483 ++- test/functional/autocmd/termxx_spec.lua | 115 +- test/functional/autocmd/textchanged_spec.lua | 16 +- test/functional/autocmd/textyankpost_spec.lua | 50 +- .../autocmd/win_scrolled_resized_spec.lua | 110 +- test/functional/core/channels_spec.lua | 197 +- test/functional/core/exit_spec.lua | 15 +- test/functional/core/fileio_spec.lua | 142 +- test/functional/core/job_spec.lua | 535 +-- test/functional/core/log_spec.lua | 16 +- test/functional/core/main_spec.lua | 117 +- test/functional/core/path_spec.lua | 46 +- test/functional/core/remote_spec.lua | 17 +- test/functional/core/startup_spec.lua | 812 ++-- test/functional/editor/K_spec.lua | 13 +- test/functional/editor/completion_spec.lua | 238 +- test/functional/editor/ctrl_c_spec.lua | 28 +- test/functional/editor/fold_spec.lua | 111 +- test/functional/editor/jump_spec.lua | 162 +- test/functional/editor/lang_spec.lua | 46 +- test/functional/editor/langmap_spec.lua | 42 +- test/functional/editor/macro_spec.lua | 64 +- test/functional/editor/mark_spec.lua | 374 +- test/functional/editor/meta_key_spec.lua | 6 +- test/functional/editor/mode_cmdline_spec.lua | 16 +- test/functional/editor/mode_insert_spec.lua | 34 +- test/functional/editor/put_spec.lua | 305 +- test/functional/editor/search_spec.lua | 7 +- test/functional/editor/tabpage_spec.lua | 31 +- test/functional/editor/undo_spec.lua | 34 +- test/functional/ex_cmds/append_spec.lua | 7 +- test/functional/ex_cmds/arg_spec.lua | 36 +- test/functional/ex_cmds/cd_spec.lua | 72 +- test/functional/ex_cmds/cmd_map_spec.lua | 94 +- test/functional/ex_cmds/debug_spec.lua | 8 +- .../ex_cmds/dict_notifications_spec.lua | 175 +- test/functional/ex_cmds/digraphs_spec.lua | 14 +- test/functional/ex_cmds/drop_spec.lua | 39 +- test/functional/ex_cmds/echo_spec.lua | 134 +- test/functional/ex_cmds/edit_spec.lua | 28 +- test/functional/ex_cmds/encoding_spec.lua | 5 +- test/functional/ex_cmds/excmd_spec.lua | 30 +- test/functional/ex_cmds/file_spec.lua | 15 +- test/functional/ex_cmds/grep_spec.lua | 4 +- test/functional/ex_cmds/highlight_spec.lua | 17 +- test/functional/ex_cmds/ls_spec.lua | 2 - test/functional/ex_cmds/make_spec.lua | 19 +- test/functional/ex_cmds/map_spec.lua | 22 +- test/functional/ex_cmds/menu_spec.lua | 412 +- test/functional/ex_cmds/mksession_spec.lua | 4 +- test/functional/ex_cmds/mkview_spec.lua | 4 +- test/functional/ex_cmds/oldfiles_spec.lua | 26 +- .../ex_cmds/print_commands_spec.lua | 3 +- test/functional/ex_cmds/profile_spec.lua | 12 +- .../ex_cmds/quickfix_commands_spec.lua | 126 +- test/functional/ex_cmds/quit_spec.lua | 1 - test/functional/ex_cmds/script_spec.lua | 39 +- test/functional/ex_cmds/sign_spec.lua | 10 +- test/functional/ex_cmds/source_spec.lua | 47 +- .../swapfile_preserve_recover_spec.lua | 286 +- test/functional/ex_cmds/syntax_spec.lua | 9 +- test/functional/ex_cmds/trust_spec.lua | 7 +- test/functional/ex_cmds/verbose_spec.lua | 120 +- test/functional/ex_cmds/wincmd_spec.lua | 2 +- test/functional/ex_cmds/write_spec.lua | 69 +- test/functional/ex_cmds/wundo_spec.lua | 23 +- test/functional/ex_cmds/wviminfo_spec.lua | 26 +- test/functional/example_spec.lua | 29 +- test/functional/fixtures/fake-lsp-server.lua | 661 +-- test/functional/fixtures/middle/filen.lua | 2 +- test/functional/fixtures/nvim/after/filen.lua | 2 +- test/functional/fixtures/nvim/filen.lua | 2 +- .../fixtures/pack/foo/opt/bonus/lua/bonus.lua | 6 +- .../fixtures/pack/foo/opt/funky/filen.lua | 4 +- .../pack/foo/opt/superspecial/after/filen.lua | 2 +- .../pack/foo/opt/superspecial/filen.lua | 2 +- .../fixtures/pack/foo/start/bar/lua/bar.lua | 6 +- .../pack/foo/start/bar/lua/baz-quux.lua | 6 +- .../foo/start/fancyplugin/after/filen.lua | 2 +- .../start/fancyplugin/after/lua/fancy_y.lua | 2 +- .../start/fancyplugin/after/lua/fancy_z.lua | 2 +- .../pack/foo/start/fancyplugin/filen.lua | 2 +- .../foo/start/fancyplugin/lua/fancy_x.lua | 2 +- .../start/fancyplugin/lua/fancy_x/init.lua | 2 +- .../start/fancyplugin/lua/fancy_y/init.lua | 3 +- .../start/nvim-leftpad/lua/async_leftpad.lua | 7 +- .../start/nvim-leftpad/lua/leftpad.lua | 4 +- test/functional/helpers.lua | 257 +- .../legacy/008_autocommands_spec.lua | 18 +- .../legacy/011_autocommands_spec.lua | 49 +- test/functional/legacy/012_directory_spec.lua | 8 +- .../legacy/023_edit_arguments_spec.lua | 2 +- .../legacy/025_jump_tag_hidden_spec.lua | 2 +- test/functional/legacy/029_join_spec.lua | 4 +- .../legacy/031_close_commands_spec.lua | 7 +- .../legacy/034_user_function_spec.lua | 73 +- .../036_regexp_character_classes_spec.lua | 83 +- .../legacy/038_virtual_replace_spec.lua | 4 +- .../039_visual_block_mode_commands_spec.lua | 5 +- .../legacy/055_list_and_dict_types_spec.lua | 6 +- test/functional/legacy/057_sort_spec.lua | 4 +- .../060_exists_and_has_functions_spec.lua | 9 +- .../legacy/063_match_and_matchadd_spec.lua | 13 +- .../legacy/069_multibyte_formatting_spec.lua | 9 +- .../legacy/074_global_var_in_viminfo_spec.lua | 117 +- .../legacy/078_swapfile_recover_spec.lua | 4 +- ...083_tag_search_with_file_encoding_spec.lua | 22 +- test/functional/legacy/090_sha256_spec.lua | 2 +- .../legacy/091_context_variables_spec.lua | 2 +- .../legacy/096_location_list_spec.lua | 37 +- test/functional/legacy/097_glob_path_spec.lua | 14 +- .../legacy/102_fnameescape_spec.lua | 4 +- .../legacy/106_errorformat_spec.lua | 2 +- .../108_backtrace_debug_commands_spec.lua | 2 +- test/functional/legacy/assert_spec.lua | 31 +- test/functional/legacy/autochdir_spec.lua | 56 +- .../functional/legacy/autocmd_option_spec.lua | 303 +- test/functional/legacy/breakindent_spec.lua | 16 +- test/functional/legacy/changelist_spec.lua | 2 +- test/functional/legacy/close_count_spec.lua | 40 +- test/functional/legacy/cmdline_spec.lua | 58 +- test/functional/legacy/conceal_spec.lua | 22 +- test/functional/legacy/debugger_spec.lua | 28 +- test/functional/legacy/delete_spec.lua | 4 +- test/functional/legacy/digraph_spec.lua | 6 +- test/functional/legacy/display_spec.lua | 14 +- test/functional/legacy/edit_spec.lua | 20 +- test/functional/legacy/erasebackword_spec.lua | 1 - test/functional/legacy/eval_spec.lua | 384 +- test/functional/legacy/ex_mode_spec.lua | 14 +- test/functional/legacy/excmd_spec.lua | 16 +- test/functional/legacy/fixeol_spec.lua | 10 +- test/functional/legacy/fold_spec.lua | 19 +- test/functional/legacy/function_sort_spec.lua | 26 +- test/functional/legacy/gf_spec.lua | 6 +- test/functional/legacy/global_spec.lua | 8 +- test/functional/legacy/highlight_spec.lua | 13 +- test/functional/legacy/increment_spec.lua | 1 - test/functional/legacy/lispwords_spec.lua | 2 +- test/functional/legacy/listchars_spec.lua | 8 +- test/functional/legacy/listlbr_spec.lua | 14 +- test/functional/legacy/mapping_spec.lua | 4 +- test/functional/legacy/match_spec.lua | 18 +- test/functional/legacy/matchparen_spec.lua | 24 +- test/functional/legacy/memory_usage_spec.lua | 68 +- test/functional/legacy/messages_spec.lua | 63 +- test/functional/legacy/move_spec.lua | 4 +- test/functional/legacy/normal_spec.lua | 17 +- test/functional/legacy/options_spec.lua | 4 +- test/functional/legacy/prompt_buffer_spec.lua | 26 +- test/functional/legacy/put_spec.lua | 4 +- test/functional/legacy/scroll_opt_spec.lua | 58 +- test/functional/legacy/search_spec.lua | 103 +- test/functional/legacy/search_stat_spec.lua | 10 +- test/functional/legacy/source_spec.lua | 11 +- test/functional/legacy/statusline_spec.lua | 22 +- test/functional/legacy/substitute_spec.lua | 133 +- test/functional/legacy/syn_attr_spec.lua | 4 +- test/functional/legacy/tabline_spec.lua | 12 +- test/functional/legacy/tagcase_spec.lua | 7 +- test/functional/legacy/vimscript_spec.lua | 24 +- test/functional/legacy/visual_spec.lua | 6 +- test/functional/legacy/window_cmd_spec.lua | 2 +- test/functional/legacy/wordcount_spec.lua | 77 +- test/functional/lua/api_spec.lua | 322 +- test/functional/lua/base64_spec.lua | 7 +- test/functional/lua/buffer_updates_spec.lua | 923 ++--- .../lua/command_line_completion_spec.lua | 76 +- test/functional/lua/commands_spec.lua | 204 +- test/functional/lua/diagnostic_spec.lua | 847 ++-- test/functional/lua/ffi_spec.lua | 21 +- test/functional/lua/filetype_spec.lua | 71 +- test/functional/lua/fs_spec.lua | 103 +- test/functional/lua/glob_spec.lua | 7 +- test/functional/lua/help_spec.lua | 15 +- test/functional/lua/inspector_spec.lua | 10 +- test/functional/lua/iter_spec.lua | 227 +- test/functional/lua/json_spec.lua | 73 +- test/functional/lua/loader_spec.lua | 26 +- test/functional/lua/loop_spec.lua | 25 +- test/functional/lua/mpack_spec.lua | 14 +- test/functional/lua/overrides_spec.lua | 156 +- test/functional/lua/runtime_spec.lua | 298 +- test/functional/lua/secure_spec.lua | 146 +- test/functional/lua/snippet_spec.lua | 19 +- test/functional/lua/spell_spec.lua | 41 +- test/functional/lua/system_spec.lua | 25 +- test/functional/lua/text_spec.lua | 1 - test/functional/lua/thread_spec.lua | 70 +- test/functional/lua/ui_event_spec.lua | 70 +- test/functional/lua/ui_spec.lua | 42 +- test/functional/lua/uri_spec.lua | 103 +- test/functional/lua/version_spec.lua | 181 +- test/functional/lua/vim_spec.lua | 1907 ++++++--- test/functional/lua/watch_spec.lua | 10 +- test/functional/lua/xdiff_spec.lua | 93 +- test/functional/options/autochdir_spec.lua | 14 +- test/functional/options/chars_spec.lua | 21 +- test/functional/options/cursorbind_spec.lua | 8 +- test/functional/options/defaults_spec.lua | 1084 +++-- test/functional/options/keymap_spec.lua | 35 +- test/functional/options/mousescroll_spec.lua | 10 +- test/functional/options/num_options_spec.lua | 34 +- test/functional/options/tabstop_spec.lua | 2 +- test/functional/plugin/editorconfig_spec.lua | 2 +- test/functional/plugin/health_spec.lua | 124 +- test/functional/plugin/lsp/codelens_spec.lua | 43 +- .../functional/plugin/lsp/completion_spec.lua | 90 +- .../functional/plugin/lsp/diagnostic_spec.lua | 59 +- test/functional/plugin/lsp/handler_spec.lua | 19 +- test/functional/plugin/lsp/helpers.lua | 43 +- .../plugin/lsp/incremental_sync_spec.lua | 446 +- .../functional/plugin/lsp/inlay_hint_spec.lua | 16 +- .../plugin/lsp/semantic_tokens_spec.lua | 251 +- test/functional/plugin/lsp/utils_spec.lua | 117 +- test/functional/plugin/lsp_spec.lua | 2213 +++++----- test/functional/plugin/man_spec.lua | 115 +- test/functional/plugin/matchparen_spec.lua | 13 +- test/functional/plugin/msgpack_spec.lua | 489 +-- test/functional/plugin/shada_spec.lua | 3578 ++++++++++------- test/functional/plugin/tutor_spec.lua | 6 +- test/functional/preload.lua | 26 +- test/functional/provider/clipboard_spec.lua | 181 +- test/functional/provider/define_spec.lua | 87 +- test/functional/provider/nodejs_spec.lua | 33 +- test/functional/provider/perl_spec.lua | 37 +- test/functional/provider/provider_spec.lua | 13 +- test/functional/provider/python3_spec.lua | 31 +- test/functional/provider/ruby_spec.lua | 4 +- test/functional/shada/buffers_spec.lua | 4 +- test/functional/shada/compatibility_spec.lua | 40 +- test/functional/shada/errors_spec.lua | 593 ++- test/functional/shada/helpers.lua | 23 +- test/functional/shada/history_spec.lua | 88 +- test/functional/shada/marks_spec.lua | 61 +- test/functional/shada/merging_spec.lua | 639 +-- test/functional/shada/registers_spec.lua | 169 +- test/functional/shada/shada_spec.lua | 157 +- test/functional/shada/variables_spec.lua | 54 +- test/functional/terminal/altscreen_spec.lua | 30 +- test/functional/terminal/api_spec.lua | 42 +- test/functional/terminal/buffer_spec.lua | 178 +- test/functional/terminal/channel_spec.lua | 136 +- test/functional/terminal/cursor_spec.lua | 284 +- test/functional/terminal/edit_spec.lua | 24 +- test/functional/terminal/ex_terminal_spec.lua | 88 +- test/functional/terminal/helpers.lua | 108 +- test/functional/terminal/highlight_spec.lua | 166 +- test/functional/terminal/mouse_spec.lua | 2 +- test/functional/terminal/scrollback_spec.lua | 102 +- test/functional/terminal/tui_spec.lua | 1209 +++--- test/functional/terminal/window_spec.lua | 16 +- .../terminal/window_split_tab_spec.lua | 9 +- test/functional/treesitter/fold_spec.lua | 174 +- test/functional/treesitter/highlight_spec.lua | 315 +- test/functional/treesitter/language_spec.lua | 88 +- test/functional/treesitter/node_spec.lua | 2 +- test/functional/treesitter/parser_spec.lua | 627 +-- test/functional/treesitter/utils_spec.lua | 1 - test/functional/ui/bufhl_spec.lua | 403 +- test/functional/ui/cmdline_highlight_spec.lua | 109 +- test/functional/ui/cmdline_spec.lua | 1247 +++--- test/functional/ui/cursor_spec.lua | 137 +- test/functional/ui/diff_spec.lua | 277 +- test/functional/ui/embed_spec.lua | 130 +- test/functional/ui/fold_spec.lua | 584 ++- test/functional/ui/highlight_spec.lua | 946 +++-- test/functional/ui/hlstate_spec.lua | 209 +- test/functional/ui/inccommand_spec.lua | 1050 ++--- test/functional/ui/inccommand_user_spec.lua | 24 +- test/functional/ui/input_spec.lua | 178 +- test/functional/ui/linematch_spec.lua | 196 +- test/functional/ui/messages_spec.lua | 1653 +++++--- test/functional/ui/mode_spec.lua | 188 +- test/functional/ui/mouse_spec.lua | 267 +- test/functional/ui/multibyte_spec.lua | 126 +- test/functional/ui/options_spec.lua | 148 +- test/functional/ui/output_spec.lua | 114 +- test/functional/ui/popupmenu_spec.lua | 1347 ++++--- test/functional/ui/quickfix_spec.lua | 23 +- test/functional/ui/screen.lua | 546 ++- test/functional/ui/screen_basic_spec.lua | 150 +- test/functional/ui/searchhl_spec.lua | 177 +- test/functional/ui/sign_spec.lua | 32 +- test/functional/ui/spell_spec.lua | 34 +- test/functional/ui/statuscolumn_spec.lua | 113 +- test/functional/ui/statusline_spec.lua | 186 +- test/functional/ui/syntax_conceal_spec.lua | 209 +- test/functional/ui/tabline_spec.lua | 122 +- test/functional/ui/title_spec.lua | 39 +- test/functional/ui/wildmode_spec.lua | 176 +- test/functional/ui/winbar_spec.lua | 130 +- .../vimscript/api_functions_spec.lua | 144 +- .../vimscript/buf_functions_spec.lua | 127 +- .../functional/vimscript/changedtick_spec.lua | 122 +- .../vimscript/container_functions_spec.lua | 18 +- .../vimscript/ctx_functions_spec.lua | 196 +- test/functional/vimscript/environ_spec.lua | 25 +- test/functional/vimscript/errorlist_spec.lua | 17 +- test/functional/vimscript/eval_spec.lua | 103 +- test/functional/vimscript/executable_spec.lua | 134 +- test/functional/vimscript/execute_spec.lua | 46 +- test/functional/vimscript/exepath_spec.lua | 47 +- .../functional/vimscript/fnamemodify_spec.lua | 6 +- test/functional/vimscript/getline_spec.lua | 6 +- test/functional/vimscript/glob_spec.lua | 4 +- test/functional/vimscript/has_spec.lua | 97 +- test/functional/vimscript/hostname_spec.lua | 6 +- test/functional/vimscript/input_spec.lua | 172 +- .../vimscript/json_functions_spec.lua | 781 ++-- test/functional/vimscript/lang_spec.lua | 6 +- test/functional/vimscript/let_spec.lua | 28 +- .../vimscript/map_functions_spec.lua | 85 +- .../vimscript/match_functions_spec.lua | 257 +- .../vimscript/minmax_functions_spec.lua | 37 +- test/functional/vimscript/modeline_spec.lua | 2 +- test/functional/vimscript/null_spec.lua | 150 +- test/functional/vimscript/operators_spec.lua | 22 +- test/functional/vimscript/printf_spec.lua | 2 +- test/functional/vimscript/reltime_spec.lua | 8 +- test/functional/vimscript/screenpos_spec.lua | 70 +- test/functional/vimscript/server_spec.lua | 71 +- test/functional/vimscript/setpos_spec.lua | 39 +- test/functional/vimscript/sort_spec.lua | 48 +- .../vimscript/special_vars_spec.lua | 10 +- test/functional/vimscript/state_spec.lua | 22 +- test/functional/vimscript/string_spec.lua | 177 +- test/functional/vimscript/system_spec.lua | 194 +- test/functional/vimscript/timer_spec.lua | 85 +- test/functional/vimscript/uniq_spec.lua | 12 +- test/functional/vimscript/vvar_event_spec.lua | 1 - test/functional/vimscript/wait_spec.lua | 9 +- test/functional/vimscript/writefile_spec.lua | 138 +- 363 files changed, 30631 insertions(+), 20833 deletions(-) diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index fd46a1dcfa..1590ca2eda 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -15,43 +15,74 @@ before_each(clear) describe('autocmd api', function() describe('nvim_create_autocmd', function() 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("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( + "Cannot use both 'callback' and 'command'", + pcall_err(meths.create_autocmd, 'BufReadPost', { + pattern = '*.py,*.pyi', + command = "echo 'Should Have Errored", + 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 = '' })) + 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() - eq(1, exec_lua([[ + eq( + 1, + exec_lua( + [[ local count = 0 vim.api.nvim_create_autocmd("FileType", { @@ -64,30 +95,33 @@ describe('autocmd api', function() vim.cmd "set filetype=python" return count - ]], {})) + ]], + {} + ) + ) end) it('allows passing buffer by key', function() meths.set_var('called', 0) - meths.create_autocmd("FileType", { - command = "let g:called = g:called + 1", + meths.create_autocmd('FileType', { + command = 'let g:called = g:called + 1', buffer = 0, }) - meths.command "set filetype=txt" + meths.command 'set filetype=txt' eq(1, meths.get_var('called')) -- switch to a new buffer - meths.command "new" - meths.command "set filetype=python" + meths.command 'new' + meths.command 'set filetype=python' eq(1, meths.get_var('called')) end) it('does not allow passing invalid buffers', function() local ok, msg = pcall(meths.create_autocmd, 'FileType', { - command = "let g:called = g:called + 1", + command = 'let g:called = g:called + 1', buffer = -1, }) @@ -96,55 +130,61 @@ describe('autocmd api', function() end) it('errors on non-functions for cb', function() - eq(false, pcall(exec_lua, [[ + eq( + false, + pcall( + exec_lua, + [[ vim.api.nvim_create_autocmd("BufReadPost", { pattern = "*.py,*.pyi", callback = 5, }) - ]])) + ]] + ) + ) end) it('allow passing pattern and in same pattern', function() - local ok = pcall(meths.create_autocmd, "BufReadPost", { - pattern = "*.py,", - command = "echo 'Should Not Error'" + local ok = pcall(meths.create_autocmd, 'BufReadPost', { + pattern = '*.py,', + command = "echo 'Should Not Error'", }) eq(true, ok) end) it('should handle multiple values as comma separated list', function() - meths.create_autocmd("BufReadPost", { - pattern = "*.py,*.pyi", - command = "echo 'Should Not Have Errored'" + meths.create_autocmd('BufReadPost', { + pattern = '*.py,*.pyi', + command = "echo 'Should Not Have Errored'", }) -- We should have one autocmd for *.py and one for *.pyi - eq(2, #meths.get_autocmds { event = "BufReadPost" }) + eq(2, #meths.get_autocmds { event = 'BufReadPost' }) end) it('should handle multiple values as array', function() - meths.create_autocmd("BufReadPost", { - pattern = { "*.py", "*.pyi", }, - command = "echo 'Should Not Have Errored'" + meths.create_autocmd('BufReadPost', { + pattern = { '*.py', '*.pyi' }, + command = "echo 'Should Not Have Errored'", }) -- We should have one autocmd for *.py and one for *.pyi - eq(2, #meths.get_autocmds { event = "BufReadPost" }) + eq(2, #meths.get_autocmds { event = 'BufReadPost' }) end) describe('desc', function() it('can add description to one autocmd', function() - local cmd = "echo 'Should Not Have Errored'" - local desc = "Can show description" - meths.create_autocmd("BufReadPost", { - pattern = "*.py", + local cmd = "echo 'Should Not Have Errored'" + local desc = 'Can show description' + meths.create_autocmd('BufReadPost', { + pattern = '*.py', command = cmd, desc = desc, }) - eq(desc, meths.get_autocmds { event = "BufReadPost" }[1].desc) - eq(cmd, meths.get_autocmds { event = "BufReadPost" }[1].command) + eq(desc, meths.get_autocmds { event = 'BufReadPost' }[1].desc) + eq(cmd, meths.get_autocmds { event = 'BufReadPost' }[1].command) end) it('can add description to one autocmd that uses a callback', function() @@ -182,34 +222,34 @@ describe('autocmd api', function() end) it('can add description to multiple autocmd', function() - meths.create_autocmd("BufReadPost", { - pattern = {"*.py", "*.pyi"}, + meths.create_autocmd('BufReadPost', { + pattern = { '*.py', '*.pyi' }, command = "echo 'Should Not Have Errored'", - desc = "Can show description", + desc = 'Can show description', }) - local aus = meths.get_autocmds { event = "BufReadPost" } + local aus = meths.get_autocmds { event = 'BufReadPost' } eq(2, #aus) - eq("Can show description", aus[1].desc) - eq("Can show description", aus[2].desc) + eq('Can show description', aus[1].desc) + eq('Can show description', aus[2].desc) end) end) pending('script and verbose settings', function() it('marks API client', function() - meths.create_autocmd("BufReadPost", { - pattern = "*.py", + meths.create_autocmd('BufReadPost', { + pattern = '*.py', command = "echo 'Should Not Have Errored'", - desc = "Can show description", + desc = 'Can show description', }) - local aus = meths.get_autocmds { event = "BufReadPost" } + local aus = meths.get_autocmds { event = 'BufReadPost' } eq(1, #aus, aus) end) end) it('removes an autocommand if the callback returns true', function() - meths.set_var("some_condition", false) + meths.set_var('some_condition', false) exec_lua [[ vim.api.nvim_create_autocmd("User", { @@ -221,19 +261,19 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds("User", {pattern = "Test"}) + meths.exec_autocmds('User', { pattern = 'Test' }) local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' }) local first = aus[1] eq(true, first.id > 0) - meths.set_var("some_condition", true) - meths.exec_autocmds("User", {pattern = "Test"}) - eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) + meths.set_var('some_condition', true) + meths.exec_autocmds('User', { pattern = 'Test' }) + eq({}, meths.get_autocmds({ event = 'User', pattern = 'Test' })) end) it('receives an args table', function() - local group_id = meths.create_augroup("TestGroup", {}) + local group_id = meths.create_augroup('TestGroup', {}) -- Having an existing autocmd calling expand("") shouldn't change args #18964 meths.create_autocmd('User', { group = 'TestGroup', @@ -251,15 +291,15 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds("User", {pattern = "Test pattern"}) + meths.exec_autocmds('User', { pattern = 'Test pattern' }) eq({ id = autocmd_id, group = group_id, - event = "User", - match = "Test pattern", - file = "Test pattern", + event = 'User', + match = 'Test pattern', + file = 'Test pattern', buf = 1, - }, meths.get_var("autocmd_args")) + }, meths.get_var('autocmd_args')) -- Test without a group autocmd_id = exec_lua [[ @@ -271,20 +311,23 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds("User", {pattern = "some_pat"}) + meths.exec_autocmds('User', { pattern = 'some_pat' }) eq({ id = autocmd_id, group = nil, - event = "User", - match = "some_pat", - file = "some_pat", + event = 'User', + match = 'some_pat', + file = 'some_pat', buf = 1, - }, meths.get_var("autocmd_args")) + }, meths.get_var('autocmd_args')) end) it('can receive arbitrary data', function() local function test(data) - eq(data, exec_lua([[ + eq( + data, + exec_lua( + [[ local input = ... local output vim.api.nvim_create_autocmd("User", { @@ -300,40 +343,64 @@ describe('autocmd api', function() }) return output - ]], data)) + ]], + data + ) + ) end - test("Hello") + test('Hello') test(42) test(true) - test({ "list" }) - test({ foo = "bar" }) + test({ 'list' }) + test({ foo = 'bar' }) end) 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, - })) + 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() @@ -341,7 +408,7 @@ describe('autocmd api', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] - local aus = meths.get_autocmds { event = "InsertEnter" } + local aus = meths.get_autocmds { event = 'InsertEnter' } eq(1, #aus) end) @@ -350,7 +417,7 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local aus = meths.get_autocmds { event = "InsertEnter" } + local aus = meths.get_autocmds { event = 'InsertEnter' } eq(2, #aus) end) @@ -359,8 +426,8 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local string_aus = meths.get_autocmds { event = "InsertEnter" } - local array_aus = meths.get_autocmds { event = { "InsertEnter" } } + local string_aus = meths.get_autocmds { event = 'InsertEnter' } + local array_aus = meths.get_autocmds { event = { 'InsertEnter' } } eq(string_aus, array_aus) end) @@ -370,7 +437,7 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(2, #aus) end) @@ -384,7 +451,7 @@ describe('autocmd api', function() \ }) ]] - local aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } local first = aus[1] eq(first.id, nil) @@ -393,7 +460,7 @@ describe('autocmd api', function() neq(second.id, nil) meths.del_autocmd(second.id) - local new_aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local new_aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(1, #new_aus) eq(first, new_aus[1]) end) @@ -402,8 +469,16 @@ describe('autocmd api', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] - local aus = meths.get_autocmds { event = "InsertEnter" } - eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus) + local aus = meths.get_autocmds { event = 'InsertEnter' } + eq({ + { + buflocal = false, + command = ':echo "1"', + event = 'InsertEnter', + once = false, + pattern = '*', + }, + }, aus) end) it('works with buffer numbers', function() @@ -412,77 +487,96 @@ describe('autocmd api', function() command [[au InsertEnter :echo "1"]] command [[au InsertEnter :echo "2"]] - local aus = meths.get_autocmds { event = "InsertEnter", buffer = 0 } - eq({{ - buffer = 2, - buflocal = true, - command = ':echo "2"', - event = 'InsertEnter', - once = false, - pattern = '', - }}, aus) + local aus = meths.get_autocmds { event = 'InsertEnter', buffer = 0 } + eq({ + { + buffer = 2, + buflocal = true, + command = ':echo "2"', + event = 'InsertEnter', + once = false, + pattern = '', + }, + }, aus) - aus = meths.get_autocmds { event = "InsertEnter", buffer = 1 } - eq({{ - buffer = 1, - buflocal = true, - command = ':echo "1"', - event = "InsertEnter", - once = false, - pattern = "", - }}, aus) + aus = meths.get_autocmds { event = 'InsertEnter', buffer = 1 } + eq({ + { + buffer = 1, + buflocal = true, + command = ':echo "1"', + event = 'InsertEnter', + once = false, + pattern = '', + }, + }, aus) - aus = meths.get_autocmds { event = "InsertEnter", buffer = { 1, 2 } } - eq({{ - buffer = 1, - buflocal = true, - command = ':echo "1"', - event = "InsertEnter", - once = false, - pattern = "", - }, { - buffer = 2, - buflocal = true, - command = ':echo "2"', - event = "InsertEnter", - once = false, - pattern = "", - }}, aus) + aus = meths.get_autocmds { event = 'InsertEnter', buffer = { 1, 2 } } + eq({ + { + buffer = 1, + buflocal = true, + command = ':echo "1"', + event = 'InsertEnter', + once = false, + pattern = '', + }, + { + buffer = 2, + buflocal = true, + command = ':echo "2"', + event = 'InsertEnter', + once = false, + pattern = '', + }, + }, aus) - 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 } })) + 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 = {} for _ = 1, 257 do table.insert(bufs, meths.create_buf(true, false)) end - eq("Too many buffers (maximum of 256)", 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('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"' }) + 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"' }) local aus = meths.get_autocmds { group = auid } eq(2, #aus) - local aus2 = meths.get_autocmds { group = auid, event = "InsertEnter" } + local aus2 = meths.get_autocmds { group = auid, event = 'InsertEnter' } eq(0, #aus2) end) it('returns autocmds when group is specified by name', function() - local auname = "nvim_test_augroup" + local auname = 'nvim_test_augroup' meths.create_augroup(auname, { clear = true }) - meths.create_autocmd("FileType", { group = auname, command = 'echo "1"' }) - meths.create_autocmd("FileType", { group = auname, command = 'echo "2"' }) + meths.create_autocmd('FileType', { group = auname, command = 'echo "1"' }) + meths.create_autocmd('FileType', { group = auname, command = 'echo "2"' }) local aus = meths.get_autocmds { group = auname } eq(2, #aus) - local aus2 = meths.get_autocmds { group = auname, event = "InsertEnter" } + local aus2 = meths.get_autocmds { group = auname, event = 'InsertEnter' } eq(0, #aus2) end) @@ -510,7 +604,7 @@ describe('autocmd api', function() -- 1 for the first buffer -- 2 for First.md -- 3-7 for the 5 we make in the autocmd - eq({1, 2, 3, 4, 5, 6, 7}, bufs) + eq({ 1, 2, 3, 4, 5, 6, 7 }, bufs) end) it('can retrieve a callback from an autocmd', function() @@ -534,12 +628,14 @@ describe('autocmd api', function() } ]]) - eq("function", result.cb.type) + eq('function', result.cb.type) eq(true, result.cb.can_retrieve) end) - it('will return an empty string as the command for an autocmd that uses a callback', function() - local result = exec_lua([[ + it( + 'will return an empty string as the command for an autocmd that uses a callback', + function() + local result = exec_lua([[ local callback = function() print 'I Am A Callback' end vim.api.nvim_create_autocmd("BufWritePost", { pattern = "*.py", @@ -553,8 +649,9 @@ describe('autocmd api', function() } ]]) - eq({ command = "", cbtype = 'function' }, result) - end) + eq({ command = '', cbtype = 'function' }, result) + end + ) end) describe('groups', function() @@ -574,7 +671,7 @@ describe('autocmd api', function() end) it('returns all groups if no group is specified', function() - local aus = meths.get_autocmds { event = "InsertEnter" } + local aus = meths.get_autocmds { event = 'InsertEnter' } if #aus ~= 4 then eq({}, aus) end @@ -584,32 +681,33 @@ describe('autocmd api', function() it('returns only the group specified', function() local aus = meths.get_autocmds { - event = "InsertEnter", - group = "GroupOne", + event = 'InsertEnter', + group = 'GroupOne', } eq(1, #aus) eq([[:echo "GroupOne:1"]], aus[1].command) - eq("GroupOne", aus[1].group_name) + eq('GroupOne', aus[1].group_name) end) it('returns only the group specified, multiple values', function() local aus = meths.get_autocmds { - event = "InsertEnter", - group = "GroupTwo", + event = 'InsertEnter', + group = 'GroupTwo', } eq(2, #aus) eq([[:echo "GroupTwo:2"]], aus[1].command) - eq("GroupTwo", aus[1].group_name) + eq('GroupTwo', aus[1].group_name) eq([[:echo "GroupTwo:3"]], aus[2].command) - eq("GroupTwo", aus[2].group_name) + eq('GroupTwo', aus[2].group_name) end) end) describe('groups: 2', function() it('raises error for undefined augroup name', function() - local success, code = unpack(meths.exec_lua([[ + local success, code = unpack(meths.exec_lua( + [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { pattern = "*", @@ -617,14 +715,17 @@ describe('autocmd api', function() command = "echo 'hello'", }) end)} - ]], {})) + ]], + {} + )) eq(false, success) matches("Invalid 'group': 'NotDefined'", code) end) it('raises error for undefined augroup id', function() - local success, code = unpack(meths.exec_lua([[ + local success, code = unpack(meths.exec_lua( + [[ return {pcall(function() -- Make sure the augroup is deleted vim.api.nvim_del_augroup_by_id(1) @@ -635,14 +736,17 @@ describe('autocmd api', function() command = "echo 'hello'", }) end)} - ]], {})) + ]], + {} + )) eq(false, success) matches("Invalid 'group': 1", code) end) it('raises error for invalid group type', function() - local success, code = unpack(meths.exec_lua([[ + local success, code = unpack(meths.exec_lua( + [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { pattern = "*", @@ -650,21 +754,26 @@ describe('autocmd api', function() command = "echo 'hello'", }) end)} - ]], {})) + ]], + {} + )) eq(false, success) matches("Invalid 'group': expected String or Integer, got Boolean", code) end) it('raises error for invalid pattern array', function() - local success, code = unpack(meths.exec_lua([[ + local success, code = unpack(meths.exec_lua( + [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { pattern = {{}}, command = "echo 'hello'", }) end)} - ]], {})) + ]], + {} + )) eq(false, success) matches("Invalid 'pattern' item: expected String, got Array", code) @@ -684,8 +793,8 @@ describe('autocmd api', function() it('returns for literal match', function() local aus = meths.get_autocmds { - event = "InsertEnter", - pattern = "*" + event = 'InsertEnter', + pattern = '*', } eq(1, #aus) @@ -695,8 +804,8 @@ describe('autocmd api', function() it('returns for multiple matches', function() -- vim.api.nvim_get_autocmds local aus = meths.get_autocmds { - event = "InsertEnter", - pattern = { "*.one", "*.two" }, + event = 'InsertEnter', + pattern = { '*.one', '*.two' }, } eq(3, #aus) @@ -707,18 +816,18 @@ describe('autocmd api', function() it('should work for buffer autocmds', function() local normalized_aus = meths.get_autocmds { - event = "InsertEnter", - pattern = "", + event = 'InsertEnter', + pattern = '', } local raw_aus = meths.get_autocmds { - event = "InsertEnter", - pattern = "", + event = 'InsertEnter', + pattern = '', } local zero_aus = meths.get_autocmds { - event = "InsertEnter", - pattern = "", + event = 'InsertEnter', + pattern = '', } eq(normalized_aus, raw_aus) @@ -730,165 +839,186 @@ describe('autocmd api', function() 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', {}}, {})) + 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) + it('can trigger builtin autocmds', function() + meths.set_var('autocmd_executed', false) - meths.create_autocmd("BufReadPost", { - pattern = "*", - command = "let g:autocmd_executed = v:true", + meths.create_autocmd('BufReadPost', { + pattern = '*', + command = 'let g:autocmd_executed = v:true', }) - eq(false, meths.get_var("autocmd_executed")) - meths.exec_autocmds("BufReadPost", {}) - eq(true, meths.get_var("autocmd_executed")) + eq(false, meths.get_var('autocmd_executed')) + meths.exec_autocmds('BufReadPost', {}) + eq(true, meths.get_var('autocmd_executed')) end) - it("can trigger multiple patterns", function() - meths.set_var("autocmd_executed", 0) + it('can trigger multiple patterns', function() + meths.set_var('autocmd_executed', 0) - meths.create_autocmd("BufReadPost", { - pattern = "*", - command = "let g:autocmd_executed += 1", + meths.create_autocmd('BufReadPost', { + pattern = '*', + command = 'let g:autocmd_executed += 1', }) - meths.exec_autocmds("BufReadPost", { pattern = { "*.lua", "*.vim" } }) - eq(2, meths.get_var("autocmd_executed")) + meths.exec_autocmds('BufReadPost', { pattern = { '*.lua', '*.vim' } }) + eq(2, meths.get_var('autocmd_executed')) - meths.create_autocmd("BufReadPre", { - pattern = { "bar", "foo" }, - command = "let g:autocmd_executed += 10", + meths.create_autocmd('BufReadPre', { + pattern = { 'bar', 'foo' }, + command = 'let g:autocmd_executed += 10', }) - meths.exec_autocmds("BufReadPre", { pattern = { "foo", "bar", "baz", "frederick" }}) - eq(22, meths.get_var("autocmd_executed")) + meths.exec_autocmds('BufReadPre', { pattern = { 'foo', 'bar', 'baz', 'frederick' } }) + eq(22, meths.get_var('autocmd_executed')) end) - it("can pass the buffer", function() - meths.set_var("buffer_executed", -1) - eq(-1, meths.get_var("buffer_executed")) + it('can pass the buffer', function() + meths.set_var('buffer_executed', -1) + eq(-1, meths.get_var('buffer_executed')) - meths.create_autocmd("BufLeave", { - pattern = "*", + meths.create_autocmd('BufLeave', { + pattern = '*', command = 'let g:buffer_executed = +expand("")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds("CursorHold", { buffer = 1 }) - eq(-1, meths.get_var("buffer_executed")) + meths.exec_autocmds('CursorHold', { buffer = 1 }) + eq(-1, meths.get_var('buffer_executed')) - meths.exec_autocmds("BufLeave", { buffer = 1 }) - eq(1, meths.get_var("buffer_executed")) + meths.exec_autocmds('BufLeave', { buffer = 1 }) + eq(1, meths.get_var('buffer_executed')) end) - it("can pass the filename, pattern match", function() - meths.set_var("filename_executed", 'none') - eq('none', meths.get_var("filename_executed")) + it('can pass the filename, pattern match', function() + meths.set_var('filename_executed', 'none') + eq('none', meths.get_var('filename_executed')) - meths.create_autocmd("BufEnter", { - pattern = "*.py", + meths.create_autocmd('BufEnter', { + pattern = '*.py', command = 'let g:filename_executed = expand("")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds("CursorHold", { buffer = 1 }) - eq('none', meths.get_var("filename_executed")) + meths.exec_autocmds('CursorHold', { buffer = 1 }) + eq('none', meths.get_var('filename_executed')) meths.command('edit __init__.py') - eq('__init__.py', meths.get_var("filename_executed")) + eq('__init__.py', meths.get_var('filename_executed')) end) it('cannot pass buf and fname', function() - local ok = pcall(meths.exec_autocmds, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) + local ok = pcall( + meths.exec_autocmds, + 'BufReadPre', + { pattern = 'literally_cannot_error.rs', buffer = 1 } + ) eq(false, ok) end) - it("can pass the filename, exact match", function() - meths.set_var("filename_executed", 'none') - eq('none', meths.get_var("filename_executed")) + it('can pass the filename, exact match', function() + meths.set_var('filename_executed', 'none') + eq('none', meths.get_var('filename_executed')) meths.command('edit other_file.txt') meths.command('edit __init__.py') - eq('none', meths.get_var("filename_executed")) + eq('none', meths.get_var('filename_executed')) - meths.create_autocmd("CursorHoldI", { - pattern = "__init__.py", + meths.create_autocmd('CursorHoldI', { + pattern = '__init__.py', command = 'let g:filename_executed = expand("")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds("CursorHoldI", { buffer = 1 }) - eq('none', meths.get_var("filename_executed")) + meths.exec_autocmds('CursorHoldI', { buffer = 1 }) + eq('none', meths.get_var('filename_executed')) - meths.exec_autocmds("CursorHoldI", { buffer = meths.get_current_buf() }) - eq('__init__.py', meths.get_var("filename_executed")) + meths.exec_autocmds('CursorHoldI', { buffer = meths.get_current_buf() }) + eq('__init__.py', meths.get_var('filename_executed')) -- Reset filename - meths.set_var("filename_executed", 'none') + meths.set_var('filename_executed', 'none') - meths.exec_autocmds("CursorHoldI", { pattern = '__init__.py' }) - eq('__init__.py', meths.get_var("filename_executed")) + meths.exec_autocmds('CursorHoldI', { pattern = '__init__.py' }) + eq('__init__.py', meths.get_var('filename_executed')) end) - it("works with user autocmds", function() - meths.set_var("matched", 'none') + it('works with user autocmds', function() + meths.set_var('matched', 'none') - meths.create_autocmd("User", { - pattern = "TestCommand", - command = 'let g:matched = "matched"' + meths.create_autocmd('User', { + pattern = 'TestCommand', + command = 'let g:matched = "matched"', }) - meths.exec_autocmds("User", { pattern = "OtherCommand" }) + meths.exec_autocmds('User', { pattern = 'OtherCommand' }) eq('none', meths.get_var('matched')) - meths.exec_autocmds("User", { pattern = "TestCommand" }) + meths.exec_autocmds('User', { pattern = 'TestCommand' }) eq('matched', meths.get_var('matched')) end) it('can pass group by id', function() - meths.set_var("group_executed", false) + meths.set_var('group_executed', false) - local auid = meths.create_augroup("nvim_test_augroup", { clear = true }) - meths.create_autocmd("FileType", { + local auid = meths.create_augroup('nvim_test_augroup', { clear = true }) + meths.create_autocmd('FileType', { group = auid, command = 'let g:group_executed = v:true', }) - eq(false, meths.get_var("group_executed")) - meths.exec_autocmds("FileType", { group = auid }) - eq(true, meths.get_var("group_executed")) + eq(false, meths.get_var('group_executed')) + meths.exec_autocmds('FileType', { group = auid }) + eq(true, meths.get_var('group_executed')) end) it('can pass group by name', function() - meths.set_var("group_executed", false) + meths.set_var('group_executed', false) - local auname = "nvim_test_augroup" + local auname = 'nvim_test_augroup' meths.create_augroup(auname, { clear = true }) - meths.create_autocmd("FileType", { + meths.create_autocmd('FileType', { group = auname, command = 'let g:group_executed = v:true', }) - eq(false, meths.get_var("group_executed")) - meths.exec_autocmds("FileType", { group = auname }) - eq(true, meths.get_var("group_executed")) + eq(false, meths.get_var('group_executed')) + meths.exec_autocmds('FileType', { group = auname }) + eq(true, meths.get_var('group_executed')) end) end) @@ -903,19 +1033,19 @@ describe('autocmd api', function() opts = opts or {} local resulting = { - pattern = "*", - command = "let g:executed = g:executed + 1", + pattern = '*', + command = 'let g:executed = g:executed + 1', } resulting.group = opts.group resulting.once = opts.once - meths.create_autocmd("FileType", resulting) + meths.create_autocmd('FileType', resulting) end local set_ft = function(ft) - ft = ft or "txt" - source(string.format("set filetype=%s", ft)) + ft = ft or 'txt' + source(string.format('set filetype=%s', ft)) end local get_executed_count = function() @@ -923,12 +1053,12 @@ describe('autocmd api', function() end it('can be added in a group', function() - local augroup = "TestGroup" + local augroup = 'TestGroup' meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup } - set_ft("txt") - set_ft("python") + set_ft('txt') + set_ft('python') eq(2, get_executed_count()) end) @@ -943,7 +1073,7 @@ describe('autocmd api', function() end) it('handles ++once', function() - make_counting_autocmd {once = true} + make_counting_autocmd { once = true } set_ft('txt') set_ft('help') set_ft('txt') @@ -953,9 +1083,9 @@ describe('autocmd api', function() end) it('errors on unexpected keys', function() - local success, code = pcall(meths.create_autocmd, "FileType", { - pattern = "*", - not_a_valid_key = "NotDefined", + local success, code = pcall(meths.create_autocmd, 'FileType', { + pattern = '*', + not_a_valid_key = 'NotDefined', }) eq(false, success) @@ -963,24 +1093,35 @@ describe('autocmd api', function() end) it('can execute simple callback', function() - exec_lua([[ + exec_lua( + [[ vim.g.executed = false vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() vim.g.executed = true end, }) - ]], {}) + ]], + {} + ) - - eq(true, exec_lua([[ + eq( + true, + exec_lua( + [[ vim.cmd "set filetype=txt" return vim.g.executed - ]], {})) + ]], + {} + ) + ) end) it('calls multiple lua callbacks for the same autocmd execution', function() - eq(4, exec_lua([[ + eq( + 4, + exec_lua( + [[ local count = 0 local counter = function() count = count + 1 @@ -1000,7 +1141,10 @@ describe('autocmd api', function() vim.cmd "set filetype=txt" return count - ]], {})) + ]], + {} + ) + ) end) it('properly releases functions with ++once', function() @@ -1030,82 +1174,86 @@ describe('autocmd api', function() command [[set filetype=txt]] eq(1, exec_lua([[return OnceCount]], {})) - eq(0, exec_lua([[ + eq( + 0, + exec_lua([[ local count = 0 for _ in pairs(WeakTable) do count = count + 1 end return count - ]]), "Should have no keys remaining") + ]]), + 'Should have no keys remaining' + ) end) it('groups can be cleared', function() - local augroup = "TestGroup" + local augroup = 'TestGroup' meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd("FileType", { + meths.create_autocmd('FileType', { group = augroup, - command = "let g:executed = g:executed + 1" + command = 'let g:executed = g:executed + 1', }) - set_ft("txt") - set_ft("txt") - eq(2, get_executed_count(), "should only count twice") + set_ft('txt') + set_ft('txt') + eq(2, get_executed_count(), 'should only count twice') meths.create_augroup(augroup, { clear = true }) eq({}, meths.get_autocmds { group = augroup }) - set_ft("txt") - set_ft("txt") - eq(2, get_executed_count(), "No additional counts") + set_ft('txt') + set_ft('txt') + eq(2, get_executed_count(), 'No additional counts') end) it('can delete non-existent groups with pcall', function() - eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]]) + eq(false, exec_lua [[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]]) eq('Vim:E367: No such group: "noexist"', pcall_err(meths.del_augroup_by_name, 'noexist')) - eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) + 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(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(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() - local augroup = "TestGroup" + local augroup = 'TestGroup' meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = true } - set_ft("txt") - set_ft("python") + set_ft('txt') + set_ft('python') eq(1, get_executed_count()) end) it('autocmds can be registered multiple times.', function() - local augroup = "TestGroup" + local augroup = 'TestGroup' meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } - set_ft("txt") - set_ft("python") + set_ft('txt') + set_ft('python') eq(3 * 2, get_executed_count()) end) it('can be deleted', function() - local augroup = "WillBeDeleted" + local augroup = 'WillBeDeleted' meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd({"FileType"}, { - pattern = "*", + meths.create_autocmd({ 'FileType' }, { + pattern = '*', command = "echo 'does not matter'", }) @@ -1118,20 +1266,20 @@ describe('autocmd api', function() end) it('can be used for buffer local autocmds', function() - local augroup = "WillBeDeleted" + local augroup = 'WillBeDeleted' - meths.set_var("value_set", false) + meths.set_var('value_set', false) meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd("FileType", { - pattern = "", - command = "let g:value_set = v:true", + meths.create_autocmd('FileType', { + pattern = '', + command = 'let g:value_set = v:true', }) - command "new" - command "set filetype=python" + command 'new' + command 'set filetype=python' - eq(false, meths.get_var("value_set")) + eq(false, meths.get_var('value_set')) end) it('can accept vimscript functions', function() @@ -1154,107 +1302,113 @@ describe('autocmd api', function() set filetype=txt ]] - eq(2, meths.get_var("vimscript_executed")) + eq(2, meths.get_var('vimscript_executed')) end) end) describe('augroup!', function() it('legacy: should clear and not return any autocmds for delete groups', function() - command('augroup TEMP_A') - command(' autocmd! BufReadPost *.py :echo "Hello"') - command('augroup END') + command('augroup TEMP_A') + command(' autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') - command('augroup! TEMP_A') + command('augroup! TEMP_A') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_A' })) + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_A' })) - -- For some reason, augroup! doesn't clear the autocmds themselves, which is just wild - -- but we managed to keep this behavior. - eq(1, #meths.get_autocmds { event = 'BufReadPost' }) + -- For some reason, augroup! doesn't clear the autocmds themselves, which is just wild + -- but we managed to keep this behavior. + eq(1, #meths.get_autocmds { event = 'BufReadPost' }) end) it('legacy: remove augroups that have no autocmds', function() - command('augroup TEMP_AB') - command('augroup END') + command('augroup TEMP_AB') + command('augroup END') - command('augroup! TEMP_AB') + command('augroup! TEMP_AB') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_AB' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_AB' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) end) it('legacy: multiple remove and add augroup', function() - command('augroup TEMP_ABC') - command(' au!') - command(' autocmd BufReadPost *.py echo "Hello"') - command('augroup END') + command('augroup TEMP_ABC') + command(' au!') + command(' autocmd BufReadPost *.py echo "Hello"') + command('augroup END') - command('augroup! TEMP_ABC') + command('augroup! TEMP_ABC') - -- Should still have one autocmd :'( - local aus = meths.get_autocmds { event = 'BufReadPost' } - eq(1, #aus, aus) + -- Should still have one autocmd :'( + local aus = meths.get_autocmds { event = 'BufReadPost' } + eq(1, #aus, aus) - command('augroup TEMP_ABC') - command(' au!') - command(' autocmd BufReadPost *.py echo "Hello"') - command('augroup END') + command('augroup TEMP_ABC') + command(' au!') + command(' autocmd BufReadPost *.py echo "Hello"') + command('augroup END') - -- Should now have two autocmds :'( - aus = meths.get_autocmds { event = 'BufReadPost' } - eq(2, #aus, aus) + -- Should now have two autocmds :'( + aus = meths.get_autocmds { event = 'BufReadPost' } + eq(2, #aus, aus) - command('augroup! TEMP_ABC') + command('augroup! TEMP_ABC') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABC' })) - eq(2, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABC' })) + eq(2, #meths.get_autocmds { event = 'BufReadPost' }) end) it('api: should clear and not return any autocmds for delete groups by id', function() - command('augroup TEMP_ABCD') - command('autocmd! BufReadPost *.py :echo "Hello"') - command('augroup END') + command('augroup TEMP_ABCD') + command('autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') - local augroup_id = meths.create_augroup("TEMP_ABCD", { clear = false }) - meths.del_augroup_by_id(augroup_id) + local augroup_id = meths.create_augroup('TEMP_ABCD', { clear = false }) + meths.del_augroup_by_id(augroup_id) - -- For good reason, we kill all the autocmds from del_augroup, - -- so now this works as expected - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCD' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + -- For good reason, we kill all the autocmds from del_augroup, + -- so now this works as expected + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCD' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) end) it('api: should clear and not return any autocmds for delete groups by name', function() - command('augroup TEMP_ABCDE') - command('autocmd! BufReadPost *.py :echo "Hello"') - command('augroup END') + command('augroup TEMP_ABCDE') + command('autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') - meths.del_augroup_by_name("TEMP_ABCDE") + meths.del_augroup_by_name('TEMP_ABCDE') - -- For good reason, we kill all the autocmds from del_augroup, - -- so now this works as expected - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCDE' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + -- For good reason, we kill all the autocmds from del_augroup, + -- so now this works as expected + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCDE' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) end) 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})) + 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"') - local search = { event = "InsertEnter", pattern = "*.txt" } + local search = { event = 'InsertEnter', pattern = '*.txt' } local before_delete = meths.get_autocmds(search) eq(1, #before_delete) @@ -1273,7 +1427,7 @@ describe('autocmd api', function() command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') - local search = { event = "InsertEnter"} + local search = { event = 'InsertEnter' } local before_delete = meths.get_autocmds(search) eq(2, #before_delete) @@ -1288,17 +1442,17 @@ describe('autocmd api', function() command('autocmd InsertEnter *.TestPat2 :echo "Enter 2"') command('autocmd InsertLeave *.TestPat2 :echo "Leave 2"') - local search = { pattern = "*.TestPat1"} + local search = { pattern = '*.TestPat1' } local before_delete = meths.get_autocmds(search) eq(2, #before_delete) - local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local before_delete_events = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(4, #before_delete_events) meths.clear_autocmds(search) local after_delete = meths.get_autocmds(search) eq(0, #after_delete) - local after_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local after_delete_events = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(2, #after_delete_events) end) @@ -1307,14 +1461,14 @@ describe('autocmd api', function() command('autocmd InsertEnter :echo "Enter Buffer"') command('autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"') - local search = { event = "InsertEnter" } + local search = { event = 'InsertEnter' } local before_delete = meths.get_autocmds(search) eq(2, #before_delete) meths.clear_autocmds { buffer = 0 } local after_delete = meths.get_autocmds(search) eq(1, #after_delete) - eq("*.TestPat1", after_delete[1].pattern) + eq('*.TestPat1', after_delete[1].pattern) end) it('should allow clearing by buffer and group', function() @@ -1324,7 +1478,7 @@ describe('autocmd api', function() command(' autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"') command('augroup END') - local search = { event = "InsertEnter", group = "TestNvimClearAutocmds" } + local search = { event = 'InsertEnter', group = 'TestNvimClearAutocmds' } local before_delete = meths.get_autocmds(search) eq(2, #before_delete) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 6c250ad6ce..b0efcf0dab 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -2,23 +2,25 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq, ok = helpers.eq, helpers.ok local funcs = helpers.funcs -local buffer, command, eval, nvim, next_msg = helpers.buffer, - helpers.command, helpers.eval, helpers.nvim, helpers.next_msg +local buffer, command, eval, nvim, next_msg = + helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local sleep = helpers.sleep local write_file = helpers.write_file -local origlines = {"original line 1", - "original line 2", - "original line 3", - "original line 4", - "original line 5", - "original line 6"} +local origlines = { + 'original line 1', + 'original line 2', + 'original line 3', + 'original line 4', + 'original line 5', + 'original line 6', +} local function expectn(name, args) -- expect the next message to be the specified notification event - eq({'notification', name, args}, next_msg()) + eq({ 'notification', name, args }, next_msg()) end local function sendkeys(keys) @@ -27,12 +29,13 @@ local function sendkeys(keys) -- more key presses - otherwise they all pile up in the queue and get -- processed at once local ntime = os.clock() + 0.1 - repeat until os.clock() > ntime + repeat + until os.clock() > ntime end local function open(activate, lines) local filename = helpers.tmpname() - write_file(filename, table.concat(lines, "\n").."\n", true) + write_file(filename, table.concat(lines, '\n') .. '\n', true) command('edit ' .. filename) local b = nvim('get_current_buf') -- what is the value of b:changedtick? @@ -43,7 +46,7 @@ local function open(activate, lines) if activate then local firstline = 0 ok(buffer('attach', b, true, {})) - expectn('nvim_buf_lines_event', {b, tick, firstline, -1, lines, false}) + expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false }) end return b, tick, filename @@ -60,13 +63,13 @@ end local function reopen(buf, expectedlines) ok(buffer('detach', buf)) - expectn('nvim_buf_detach_event', {buf}) + expectn('nvim_buf_detach_event', { buf }) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') ok(buffer('attach', buf, true, {})) local firstline = 0 - expectn('nvim_buf_lines_event', {buf, tick, firstline, -1, expectedlines, false}) + expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false }) command('normal! gg') return tick end @@ -81,18 +84,36 @@ local function reopenwithfolds(b) -- add a fold command('2,4fold') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 4, {'original line 2/*{{{*/', - 'original line 3', - 'original line 4/*}}}*/'}, false}) + expectn('nvim_buf_lines_event', { + b, + tick, + 1, + 4, + { + 'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/', + }, + false, + }) -- make a new fold that wraps lines 1-6 command('1,6fold') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 6, {'original line 1/*{{{*/', - 'original line 2/*{{{*/', - 'original line 3', - 'original line 4/*}}}*/', - 'original line 5', - 'original line 6/*}}}*/'}, false}) + expectn('nvim_buf_lines_event', { + b, + tick, + 0, + 6, + { + 'original line 1/*{{{*/', + 'original line 2/*{{{*/', + 'original line 3', + 'original line 4/*}}}*/', + 'original line 5', + 'original line 6/*}}}*/', + }, + false, + }) return tick end @@ -105,97 +126,105 @@ describe('API: buffer events:', function() -- add a new line at the start of the buffer command('normal! GyyggP') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 0, {'original line 6'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 0, { 'original line 6' }, false }) -- add multiple lines at the start of the file command('normal! GkkyGggP') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 0, {'original line 4', - 'original line 5', - 'original line 6'}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 0, 0, { 'original line 4', 'original line 5', 'original line 6' }, false } + ) -- add one line to the middle of the file, several times command('normal! ggYjjp') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 3, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 3, { 'original line 4' }, false }) command('normal! p') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 4, 4, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 4, 4, { 'original line 4' }, false }) command('normal! p') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 5, 5, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 5, 5, { 'original line 4' }, false }) -- add multiple lines to the middle of the file command('normal! gg4Yjjp') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 3, {'original line 4', - 'original line 5', - 'original line 6', - 'original line 4'}, false}) + expectn('nvim_buf_lines_event', { + b, + tick, + 3, + 3, + { + 'original line 4', + 'original line 5', + 'original line 6', + 'original line 4', + }, + false, + }) -- add one line to the end of the file command('normal! ggYGp') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 17, 17, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 17, 17, { 'original line 4' }, false }) -- add one line to the end of the file, several times command('normal! ggYGppp') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 18, 18, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 18, 18, { 'original line 4' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 19, 19, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 19, 19, { 'original line 4' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 20, 20, {'original line 4'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 20, 20, { 'original line 4' }, false }) -- add several lines to the end of the file, several times command('normal! gg4YGp') command('normal! Gp') command('normal! Gp') - local firstfour = {'original line 4', - 'original line 5', - 'original line 6', - 'original line 4'} + local firstfour = { 'original line 4', 'original line 5', 'original line 6', 'original line 4' } tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 21, 21, firstfour, false}) + expectn('nvim_buf_lines_event', { b, tick, 21, 21, firstfour, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 25, 25, firstfour, false}) + expectn('nvim_buf_lines_event', { b, tick, 25, 25, firstfour, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 29, 29, firstfour, false}) + expectn('nvim_buf_lines_event', { b, tick, 29, 29, firstfour, false }) -- delete the current buffer to turn off buffer events command('bdelete!') - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) -- add a line at the start of an empty file command('enew') tick = eval('b:changedtick') local b2 = nvim('get_current_buf') ok(buffer('attach', b2, true, {})) - expectn('nvim_buf_lines_event', {b2, tick, 0, -1, {""}, false}) + expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1"])') tick = tick + 1 - expectn('nvim_buf_lines_event', {b2, tick, 0, 0, {'new line 1'}, false}) + expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false }) -- turn off buffer events manually buffer('detach', b2) - expectn('nvim_buf_detach_event', {b2}) + expectn('nvim_buf_detach_event', { b2 }) -- add multiple lines to a blank file command('enew!') local b3 = nvim('get_current_buf') ok(buffer('attach', b3, true, {})) tick = eval('b:changedtick') - expectn('nvim_buf_lines_event', {b3, tick, 0, -1, {""}, false}) + expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1", "new line 2", "new line 3"])') tick = tick + 1 - expectn('nvim_buf_lines_event', {b3, tick, 0, 0, {'new line 1', - 'new line 2', - 'new line 3'}, false}) + expectn( + 'nvim_buf_lines_event', + { b3, tick, 0, 0, { 'new line 1', 'new line 2', 'new line 3' }, false } + ) -- use the API itself to add a line to the start of the buffer - buffer('set_lines', b3, 0, 0, true, {'New First Line'}) + buffer('set_lines', b3, 0, 0, true, { 'New First Line' }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b3, tick, 0, 0, {"New First Line"}, false}) + expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false }) end) it('when lines are removed', function() @@ -204,37 +233,37 @@ describe('API: buffer events:', function() -- remove one line from start of file command('normal! dd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, {}, false }) -- remove multiple lines from the start of the file command('normal! 4dd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 4, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 4, {}, false }) -- remove multiple lines from middle of file tick = reopen(b, origlines) command('normal! jj3dd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 5, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 5, {}, false }) -- remove one line from the end of the file tick = reopen(b, origlines) command('normal! Gdd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 5, 6, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 5, 6, {}, false }) -- remove multiple lines from the end of the file tick = reopen(b, origlines) command('normal! 4G3dd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 6, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 6, {}, false }) -- pretend to remove heaps lines from the end of the file but really -- just remove two tick = reopen(b, origlines) command('normal! Gk5dd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 4, 6, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 4, 6, {}, false }) end) it('when text is changed', function() @@ -243,53 +272,56 @@ describe('API: buffer events:', function() -- some normal text editing command('normal! A555') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'original line 1555'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'original line 1555' }, false }) command('normal! jj8X') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'origin3'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 3, { 'origin3' }, false }) -- modify multiple lines at once using visual block mode tick = reopen(b, origlines) command('normal! jjw') sendkeys('jjllx') tick = tick + 1 - expectn('nvim_buf_lines_event', - {b, tick, 2, 5, {'original e 3', 'original e 4', 'original e 5'}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 2, 5, { 'original e 3', 'original e 4', 'original e 5' }, false } + ) -- replace part of a line line using :s tick = reopen(b, origlines) command('3s/line 3/foo/') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original foo'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 3, { 'original foo' }, false }) -- replace parts of several lines line using :s tick = reopen(b, origlines) command('%s/line [35]/foo/') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 5, {'original foo', - 'original line 4', - 'original foo'}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 2, 5, { 'original foo', 'original line 4', 'original foo' }, false } + ) -- type text into the first line of a blank file, one character at a time command('bdelete!') tick = 2 - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) local bnew = nvim('get_current_buf') ok(buffer('attach', bnew, true, {})) - expectn('nvim_buf_lines_event', {bnew, tick, 0, -1, {''}, false}) + expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false }) sendkeys('i') sendkeys('h') sendkeys('e') sendkeys('l') sendkeys('l') sendkeys('o\nworld') - expectn('nvim_buf_lines_event', {bnew, tick + 1, 0, 1, {'h'}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 2, 0, 1, {'he'}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 3, 0, 1, {'hel'}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 4, 0, 1, {'hell'}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 5, 0, 1, {'hello'}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 6, 0, 1, {'hello', ''}, false}) - expectn('nvim_buf_lines_event', {bnew, tick + 7, 1, 2, {'world'}, false}) + expectn('nvim_buf_lines_event', { bnew, tick + 1, 0, 1, { 'h' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 2, 0, 1, { 'he' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 3, 0, 1, { 'hel' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 4, 0, 1, { 'hell' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 5, 0, 1, { 'hello' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 6, 0, 1, { 'hello', '' }, false }) + expectn('nvim_buf_lines_event', { bnew, tick + 7, 1, 2, { 'world' }, false }) end) it('when lines are replaced', function() @@ -298,145 +330,145 @@ describe('API: buffer events:', function() -- blast away parts of some lines with visual mode command('normal! jjwvjjllx') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original '}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 3, { 'original ' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 4, {}, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 4, {'e 5'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 4, { 'e 5' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 3, {'original e 5'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 3, { 'original e 5' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 4, {}, false }) -- blast away a few lines using :g tick = reopen(b, origlines) command('global/line [35]/delete') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 2, 3, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 2, 3, {}, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 4, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 4, {}, false }) end) it('when lines are filtered', function() -- Test filtering lines with !cat - local b, tick = editoriginal(true, {"A", "C", "E", "B", "D", "F"}) + local b, tick = editoriginal(true, { 'A', 'C', 'E', 'B', 'D', 'F' }) command('silent 2,5!cat') -- the change comes through as two changes: -- 1) addition of the new lines after the filtered lines -- 2) removal of the original lines tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 5, 5, {"C", "E", "B", "D"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 5, 5, { 'C', 'E', 'B', 'D' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 5, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 5, {}, false }) end) it('when you use "o"', function() - local b, tick = editoriginal(true, {'AAA', 'BBB'}) + local b, tick = editoriginal(true, { 'AAA', 'BBB' }) command('set noautoindent nosmartindent') -- use 'o' to start a new line from a line with no indent command('normal! o') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 1, {""}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 1, { '' }, false }) -- undo the change, indent line 1 a bit, and try again command('undo') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 2, {}, false }) tick = tick + 1 - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) command('set autoindent') command('normal! >>') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {"\tAAA"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { '\tAAA' }, false }) command('normal! ommm') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 1, {"\t"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 1, { '\t' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 2, {"\tmmm"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 2, { '\tmmm' }, false }) -- undo the change, and try again with 'O' command('undo') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 2, {'\t'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 2, { '\t' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 2, {}, false }) tick = tick + 1 - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) command('normal! ggOmmm') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 0, {"\t"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 0, { '\t' }, false }) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {"\tmmm"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { '\tmmm' }, false }) end) it('deactivates if the buffer is changed externally', function() -- Test changing file from outside vim and reloading using :edit - local lines = {"Line 1", "Line 2"}; + local lines = { 'Line 1', 'Line 2' } local b, tick, filename = editoriginal(true, lines) command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'ine 1'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'ine 1' }, false }) command('undo') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'Line 1'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'Line 1' }, false }) tick = tick + 1 - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) -- change the file directly - write_file(filename, "another line\n", true, true) + write_file(filename, 'another line\n', true, true) -- reopen the file and watch buffer events shut down command('edit') - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) end) it('channel can watch many buffers at once', function() -- edit 3 buffers, make sure they all have windows visible so that when we -- move between buffers, none of them are unloaded - local b1, tick1 = editoriginal(true, {'A1', 'A2'}) + local b1, tick1 = editoriginal(true, { 'A1', 'A2' }) local b1nr = eval('bufnr("")') command('split') - local b2, tick2 = open(true, {'B1', 'B2'}) + local b2, tick2 = open(true, { 'B1', 'B2' }) local b2nr = eval('bufnr("")') command('split') - local b3, tick3 = open(true, {'C1', 'C2'}) + local b3, tick3 = open(true, { 'C1', 'C2' }) local b3nr = eval('bufnr("")') -- make a new window for moving between buffers command('split') - command('b'..b1nr) + command('b' .. b1nr) command('normal! x') tick1 = tick1 + 1 - expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'1'}, false}) + expectn('nvim_buf_lines_event', { b1, tick1, 0, 1, { '1' }, false }) command('undo') tick1 = tick1 + 1 - expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'A1'}, false}) + expectn('nvim_buf_lines_event', { b1, tick1, 0, 1, { 'A1' }, false }) tick1 = tick1 + 1 - expectn('nvim_buf_changedtick_event', {b1, tick1}) + expectn('nvim_buf_changedtick_event', { b1, tick1 }) - command('b'..b2nr) + command('b' .. b2nr) command('normal! x') tick2 = tick2 + 1 - expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'1'}, false}) + expectn('nvim_buf_lines_event', { b2, tick2, 0, 1, { '1' }, false }) command('undo') tick2 = tick2 + 1 - expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'B1'}, false}) + expectn('nvim_buf_lines_event', { b2, tick2, 0, 1, { 'B1' }, false }) tick2 = tick2 + 1 - expectn('nvim_buf_changedtick_event', {b2, tick2}) + expectn('nvim_buf_changedtick_event', { b2, tick2 }) - command('b'..b3nr) + command('b' .. b3nr) command('normal! x') tick3 = tick3 + 1 - expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'1'}, false}) + expectn('nvim_buf_lines_event', { b3, tick3, 0, 1, { '1' }, false }) command('undo') tick3 = tick3 + 1 - expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'C1'}, false}) + expectn('nvim_buf_lines_event', { b3, tick3, 0, 1, { 'C1' }, false }) tick3 = tick3 + 1 - expectn('nvim_buf_changedtick_event', {b3, tick3}) + expectn('nvim_buf_changedtick_event', { b3, tick3 }) end) it('does not get confused if enabled/disabled many times', function() @@ -449,8 +481,8 @@ describe('API: buffer events:', function() ok(buffer('attach', b, true, {})) ok(buffer('attach', b, true, {})) ok(buffer('attach', b, true, {})) - expectn('nvim_buf_lines_event', {b, tick, 0, -1, origlines, false}) - eval('rpcnotify('..channel..', "Hello There")') + expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false }) + eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) -- Disable buffer events many times. @@ -459,8 +491,8 @@ describe('API: buffer events:', function() ok(buffer('detach', b)) ok(buffer('detach', b)) ok(buffer('detach', b)) - expectn('nvim_buf_detach_event', {b}) - eval('rpcnotify('..channel..', "Hello Again")') + expectn('nvim_buf_detach_event', { b }) + eval('rpcnotify(' .. channel .. ', "Hello Again")') expectn('Hello Again', {}) end) @@ -470,7 +502,7 @@ describe('API: buffer events:', function() -- create several new sessions, in addition to our main API local sessions = {} local pipe = helpers.new_pipename() - eval("serverstart('"..pipe.."')") + eval("serverstart('" .. pipe .. "')") sessions[1] = helpers.connect(pipe) sessions[2] = helpers.connect(pipe) sessions[3] = helpers.connect(pipe) @@ -485,109 +517,105 @@ describe('API: buffer events:', function() local function wantn(sessionid, name, args) local session = sessions[sessionid] - eq({'notification', name, args}, session:next_message(10000)) + eq({ 'notification', name, args }, session:next_message(10000)) end -- Edit a new file, but don't enable buffer events. - local lines = {'AAA', 'BBB'} + local lines = { 'AAA', 'BBB' } local b, tick = open(false, lines) -- Enable buffer events for sessions 1, 2 and 3. ok(request(1, 'nvim_buf_attach', b, true, {})) ok(request(2, 'nvim_buf_attach', b, true, {})) ok(request(3, 'nvim_buf_attach', b, true, {})) - wantn(1, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) - wantn(2, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) - wantn(3, 'nvim_buf_lines_event', {b, tick, 0, -1, lines, false}) + wantn(1, 'nvim_buf_lines_event', { b, tick, 0, -1, lines, false }) + wantn(2, 'nvim_buf_lines_event', { b, tick, 0, -1, lines, false }) + wantn(3, 'nvim_buf_lines_event', { b, tick, 0, -1, lines, false }) -- Change the buffer. command('normal! x') tick = tick + 1 - wantn(1, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) - wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) - wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + wantn(1, 'nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) + wantn(2, 'nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) + wantn(3, 'nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) -- Stop watching on channel 1. ok(request(1, 'nvim_buf_detach', b)) - wantn(1, 'nvim_buf_detach_event', {b}) + wantn(1, 'nvim_buf_detach_event', { b }) -- Undo the change to buffer 1. command('undo') tick = tick + 1 - wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) - wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) + wantn(2, 'nvim_buf_lines_event', { b, tick, 0, 1, { 'AAA' }, false }) + wantn(3, 'nvim_buf_lines_event', { b, tick, 0, 1, { 'AAA' }, false }) tick = tick + 1 - wantn(2, 'nvim_buf_changedtick_event', {b, tick}) - wantn(3, 'nvim_buf_changedtick_event', {b, tick}) + wantn(2, 'nvim_buf_changedtick_event', { b, tick }) + wantn(3, 'nvim_buf_changedtick_event', { b, tick }) -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 local channel1 = request(1, 'nvim_get_api_info')[1] - eval('rpcnotify('..channel1..', "Hello")') + eval('rpcnotify(' .. channel1 .. ', "Hello")') wantn(1, 'Hello', {}) -- close the buffer and channels 2 and 3 should get a nvim_buf_detach_event -- notification command('edit') - wantn(2, 'nvim_buf_detach_event', {b}) - wantn(3, 'nvim_buf_detach_event', {b}) + wantn(2, 'nvim_buf_detach_event', { b }) + wantn(3, 'nvim_buf_detach_event', { b }) -- make sure there are no other pending nvim_buf_lines_event messages going to -- channel 1 channel1 = request(1, 'nvim_get_api_info')[1] - eval('rpcnotify('..channel1..', "Hello Again")') + eval('rpcnotify(' .. channel1 .. ', "Hello Again")') wantn(1, 'Hello Again', {}) end) it('works with :diffput and :diffget', function() - local b1, tick1 = editoriginal(true, {"AAA", "BBB"}) + local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' }) local channel = nvim('get_api_info')[1] command('diffthis') command('rightbelow vsplit') - local b2, tick2 = open(true, {"BBB", "CCC"}) + local b2, tick2 = open(true, { 'BBB', 'CCC' }) command('diffthis') -- go back to first buffer, and push the 'AAA' line to the second buffer command('1wincmd w') command('normal! gg') command('diffput') tick2 = tick2 + 1 - expectn('nvim_buf_lines_event', {b2, tick2, 0, 0, {"AAA"}, false}) + expectn('nvim_buf_lines_event', { b2, tick2, 0, 0, { 'AAA' }, false }) -- use :diffget to grab the other change from buffer 2 command('normal! G') command('diffget') tick1 = tick1 + 1 - expectn('nvim_buf_lines_event', {b1, tick1, 2, 2, {"CCC"}, false}) + expectn('nvim_buf_lines_event', { b1, tick1, 2, 2, { 'CCC' }, false }) - eval('rpcnotify('..channel..', "Goodbye")') + eval('rpcnotify(' .. channel .. ', "Goodbye")') expectn('Goodbye', {}) end) it('works with :sort', function() -- test for :sort - local b, tick = editoriginal(true, {"B", "D", "C", "A", "E"}) + local b, tick = editoriginal(true, { 'B', 'D', 'C', 'A', 'E' }) command('%sort') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 5, {"A", "B", "C", "D", "E"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 5, { 'A', 'B', 'C', 'D', 'E' }, false }) end) it('works with :left', function() - local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"}) + local b, tick = editoriginal(true, { ' A', ' B', 'B', '\tB', '\t\tC' }) command('2,4left') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 4, {"B", "B", "B"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 4, { 'B', 'B', 'B' }, false }) end) it('works with :right', function() - local b, tick = editoriginal(true, {" A", - "\t B", - "\t \tBB", - " \tB", - "\t\tC"}) + local b, tick = editoriginal(true, { ' A', '\t B', '\t \tBB', ' \tB', '\t\tC' }) command('set ts=2 et') command('2,4retab') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 4, {" B", " BB", " B"}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 4, { ' B', ' BB', ' B' }, false }) end) it('works with :move', function() @@ -595,19 +623,23 @@ describe('API: buffer events:', function() -- move text down towards the end of the file command('2,3move 4') tick = tick + 2 - expectn('nvim_buf_lines_event', {b, tick, 4, 4, {"original line 2", - "original line 3"}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 4, 4, { 'original line 2', 'original line 3' }, false } + ) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 3, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 1, 3, {}, false }) -- move text up towards the start of the file tick = reopen(b, origlines) command('4,5move 2') tick = tick + 2 - expectn('nvim_buf_lines_event', {b, tick, 2, 2, {"original line 4", - "original line 5"}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 2, 2, { 'original line 4', 'original line 5' }, false } + ) tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 5, 7, {}, false}) + expectn('nvim_buf_lines_event', { b, tick, 5, 7, {}, false }) end) it('when you manually add/remove folds', function() @@ -617,13 +649,14 @@ describe('API: buffer events:', function() -- delete the inner fold command('normal! zR3Gzd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 1, 4, {'original line 2', - 'original line 3', - 'original line 4'}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 1, 4, { 'original line 2', 'original line 3', 'original line 4' }, false } + ) -- delete the outer fold command('normal! zd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 6, origlines, false }) -- discard changes and put the folds back tick = reopenwithfolds(b) @@ -631,7 +664,7 @@ describe('API: buffer events:', function() -- remove both folds at once command('normal! ggzczD') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 6, origlines, false }) -- discard changes and put the folds back tick = reopenwithfolds(b) @@ -639,101 +672,102 @@ describe('API: buffer events:', function() -- now delete all folds at once command('normal! zE') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 6, origlines, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 6, origlines, false }) -- create a fold from line 4 to the end of the file command('normal! 4GA/*{{{*/') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 4, {'original line 4/*{{{*/'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 3, 4, { 'original line 4/*{{{*/' }, false }) -- delete the fold which only has one marker command('normal! Gzd') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 3, 6, {'original line 4', - 'original line 5', - 'original line 6'}, false}) + expectn( + 'nvim_buf_lines_event', + { b, tick, 3, 6, { 'original line 4', 'original line 5', 'original line 6' }, false } + ) end) it('detaches if the buffer is closed', function() - local b, tick = editoriginal(true, {'AAA'}) + local b, tick = editoriginal(true, { 'AAA' }) local channel = nvim('get_api_info')[1] -- Test that buffer events are working. command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) command('undo') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AAA' }, false }) tick = tick + 1 - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) -- close our buffer and create a new one command('bdelete') command('enew') - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) -- Reopen the original buffer, make sure there are no buffer events sent. command('b1') command('normal! x') - eval('rpcnotify('..channel..', "Hello There")') + eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) end) it(':edit! (reload) causes detach #9642', function() - local b, tick = editoriginal(true, {'AAA', 'BBB'}) + local b, tick = editoriginal(true, { 'AAA', 'BBB' }) command('set undoreload=1') command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) command('edit!') - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) end) it(':enew! does not detach hidden buffer', function() - local b, tick = editoriginal(true, {'AAA', 'BBB'}) + local b, tick = editoriginal(true, { 'AAA', 'BBB' }) local channel = nvim('get_api_info')[1] command('set undoreload=1 hidden') command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) command('enew!') - eval('rpcnotify('..channel..', "Hello There")') + eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) end) it('stays attached if the buffer is hidden', function() - local b, tick = editoriginal(true, {'AAA'}) + local b, tick = editoriginal(true, { 'AAA' }) local channel = nvim('get_api_info')[1] -- Test that buffer events are working. command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) command('undo') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AAA' }, false }) tick = tick + 1 - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) -- Close our buffer by creating a new one. command('set hidden') command('enew') -- Assert that no nvim_buf_detach_event is sent. - eval('rpcnotify('..channel..', "Hello There")') + eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) -- Reopen the original buffer, assert that buffer events are still active. command('b1') command('normal! x') tick = tick + 1 - expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false}) + expectn('nvim_buf_lines_event', { b, tick, 0, 1, { 'AA' }, false }) end) it('detaches if the buffer is unloaded/deleted/wiped', function() @@ -741,15 +775,15 @@ describe('API: buffer events:', function() clear() -- need to make a new window with a buffer because :bunload doesn't let you -- unload the last buffer - for _, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do + for _, cmd in ipairs({ 'bunload', 'bdelete', 'bwipeout' }) do command('new') -- open a brand spanking new file - local b = open(true, {'AAA'}) + local b = open(true, { 'AAA' }) -- call :bunload or whatever the command is, and then check that we -- receive a nvim_buf_detach_event command(cmd) - expectn('nvim_buf_detach_event', {b}) + expectn('nvim_buf_detach_event', { b }) end end) @@ -757,13 +791,13 @@ describe('API: buffer events:', function() clear() local b, tick = editoriginal(false) ok(buffer('attach', b, false, {})) - expectn('nvim_buf_changedtick_event', {b, tick}) + expectn('nvim_buf_changedtick_event', { b, tick }) end) it('returns a proper error on nonempty options dict', function() clear() local b = editoriginal(false) - eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, {builtin="asfd"})) + eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, { builtin = 'asfd' })) end) it('nvim_buf_attach returns response after delay #8634', function() @@ -773,11 +807,13 @@ describe('API: buffer events:', function() eq(true, helpers.request('nvim_buf_attach', 0, false, {})) -- notification eq({ - [1] = 'notification', - [2] = 'nvim_buf_changedtick_event', - [3] = { - [1] = { id = 1 }, - [2] = 2 }, }, next_msg()) + [1] = 'notification', + [2] = 'nvim_buf_changedtick_event', + [3] = { + [1] = { id = 1 }, + [2] = 2, + }, + }, next_msg()) end) end) @@ -787,7 +823,7 @@ describe('API: buffer events:', function() end) local function lines_subset(first, second) - for i = 1,#first do + for i = 1, #first do -- need to ignore trailing spaces if first[i]:gsub(' +$', '') ~= second[i]:gsub(' +$', '') then return false @@ -803,7 +839,7 @@ describe('API: buffer events:', function() local function assert_match_somewhere(expected_lines, buffer_lines) local msg = next_msg() - while(msg ~= nil) do + while msg ~= nil do local event = msg[2] if event == 'nvim_buf_lines_event' then local args = msg[3] @@ -814,7 +850,7 @@ describe('API: buffer events:', function() -- with the test setup. Note updates are contiguous. assert(#newlines <= 23) - for i = 1,#newlines do + for i = 1, #newlines do buffer_lines[starts + i] = newlines[i] end -- we don't compare the msg area of the embedded nvim, it's too flakey @@ -834,38 +870,34 @@ describe('API: buffer events:', function() local buffer_lines = {} local expected_lines = {} funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { - env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) local b = nvim('get_current_buf') ok(buffer('attach', b, true, {})) - for _ = 1,22 do - table.insert(expected_lines,'~') + for _ = 1, 22 do + table.insert(expected_lines, '~') end expected_lines[1] = '' - expected_lines[22] = ('tmp_terminal_nvim'..(' '):rep(45) - ..'0,0-1 All') + expected_lines[22] = ('tmp_terminal_nvim' .. (' '):rep(45) .. '0,0-1 All') sendkeys('i:e tmp_terminal_nvim') assert_match_somewhere(expected_lines, buffer_lines) expected_lines[1] = 'Blarg' - expected_lines[22] = ('tmp_terminal_nvim [+]'..(' '):rep(41) - ..'1,6 All') + expected_lines[22] = ('tmp_terminal_nvim [+]' .. (' '):rep(41) .. '1,6 All') sendkeys('iBlarg') assert_match_somewhere(expected_lines, buffer_lines) - for i = 1,21 do + for i = 1, 21 do expected_lines[i] = 'xyz' end - expected_lines[22] = ('tmp_terminal_nvim [+]'..(' '):rep(41) - ..'31,4 Bot') + expected_lines[22] = ('tmp_terminal_nvim [+]' .. (' '):rep(41) .. '31,4 Bot') local s = string.rep('\nxyz', 30) sendkeys(s) assert_match_somewhere(expected_lines, buffer_lines) end) - end) diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 1ddb289ded..e286181bce 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -16,61 +16,164 @@ local feed = helpers.feed local funcs = helpers.funcs describe('nvim_get_commands', function() - local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', preview=false, range=NIL, register=false, keepscript=false, script_id=0, } - local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', preview=false, range=NIL, register=false, keepscript=false, script_id=0, } + local cmd_dict = { + addr = NIL, + bang = false, + bar = false, + complete = NIL, + complete_arg = NIL, + count = NIL, + definition = 'echo "Hello World"', + name = 'Hello', + nargs = '1', + preview = false, + range = NIL, + register = false, + keepscript = false, + script_id = 0, + } + local cmd_dict2 = { + addr = NIL, + bang = false, + bar = false, + complete = NIL, + complete_arg = NIL, + count = NIL, + definition = 'pwd', + name = 'Pwd', + nargs = '?', + preview = false, + range = NIL, + register = false, + keepscript = false, + script_id = 0, + } before_each(clear) it('gets empty list if no commands were defined', function() - eq({}, meths.get_commands({builtin=false})) + eq({}, meths.get_commands({ builtin = false })) end) it('validation', function() - eq('builtin=true not implemented', pcall_err(meths.get_commands, - {builtin=true})) - eq("Invalid key: 'foo'", pcall_err(meths.get_commands, - {foo='blah'})) + eq('builtin=true not implemented', pcall_err(meths.get_commands, { builtin = true })) + eq("Invalid key: 'foo'", pcall_err(meths.get_commands, { foo = 'blah' })) end) it('gets global user-defined commands', function() -- Define a command. command('command -nargs=1 Hello echo "Hello World"') - eq({Hello=cmd_dict}, meths.get_commands({builtin=false})) + eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false })) -- Define another command. - command('command -nargs=? Pwd pwd'); - eq({Hello=cmd_dict, Pwd=cmd_dict2}, meths.get_commands({builtin=false})) + command('command -nargs=? Pwd pwd') + eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.get_commands({ builtin = false })) -- Delete a command. command('delcommand Pwd') - eq({Hello=cmd_dict}, meths.get_commands({builtin=false})) + eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false })) end) it('gets buffer-local user-defined commands', function() -- Define a buffer-local command. command('command -buffer -nargs=1 Hello echo "Hello World"') - eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false})) + eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) -- Define another buffer-local command. command('command -buffer -nargs=? Pwd pwd') - eq({Hello=cmd_dict, Pwd=cmd_dict2}, curbufmeths.get_commands({builtin=false})) + eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, curbufmeths.get_commands({ builtin = false })) -- Delete a command. command('delcommand Pwd') - eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false})) + eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) -- {builtin=true} always returns empty for buffer-local case. - eq({}, curbufmeths.get_commands({builtin=true})) + eq({}, curbufmeths.get_commands({ builtin = true })) end) it('gets various command attributes', function() - local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd ', name='TestCmd', nargs='1', preview=false, range='10', register=false, keepscript=false, script_id=0, } - local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger ', name='Finger', nargs='+', preview=false, range=NIL, register=false, keepscript=false, script_id=1, } - local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R2_foo()', name='Cmd2', nargs='*', preview=false, range=NIL, register=false, keepscript=false, script_id=2, } - local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', preview=false, range=NIL, register=false, keepscript=false, script_id=3, } - local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', preview=false, range=NIL, register=true, keepscript=false, script_id=4, } + local cmd0 = { + addr = 'arguments', + bang = false, + bar = false, + complete = 'dir', + complete_arg = NIL, + count = '10', + definition = 'pwd ', + name = 'TestCmd', + nargs = '1', + preview = false, + range = '10', + register = false, + keepscript = false, + script_id = 0, + } + local cmd1 = { + addr = NIL, + bang = false, + bar = false, + complete = 'custom', + complete_arg = 'ListUsers', + count = NIL, + definition = '!finger ', + name = 'Finger', + nargs = '+', + preview = false, + range = NIL, + register = false, + keepscript = false, + script_id = 1, + } + local cmd2 = { + addr = NIL, + bang = true, + bar = false, + complete = NIL, + complete_arg = NIL, + count = NIL, + definition = 'call \128\253R2_foo()', + name = 'Cmd2', + nargs = '*', + preview = false, + range = NIL, + register = false, + keepscript = false, + script_id = 2, + } + local cmd3 = { + addr = NIL, + bang = false, + bar = true, + complete = NIL, + complete_arg = NIL, + count = NIL, + definition = 'call \128\253R3_ohyeah()', + name = 'Cmd3', + nargs = '0', + preview = false, + range = NIL, + register = false, + keepscript = false, + script_id = 3, + } + local cmd4 = { + addr = NIL, + bang = false, + bar = false, + complete = NIL, + complete_arg = NIL, + count = NIL, + definition = 'call \128\253R4_just_great()', + name = 'Cmd4', + nargs = '0', + preview = false, + range = NIL, + register = true, + keepscript = false, + script_id = 4, + } source([[ let s:foo = 1 command -complete=custom,ListUsers -nargs=+ Finger !finger ]]) - eq({Finger=cmd1}, meths.get_commands({builtin=false})) + eq({ Finger = cmd1 }, meths.get_commands({ builtin = false })) command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd ') - eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false})) + eq({ Finger = cmd1, TestCmd = cmd0 }, meths.get_commands({ builtin = false })) source([[ function! s:foo() abort @@ -88,7 +191,10 @@ describe('nvim_get_commands', function() command -register Cmd4 call just_great() ]]) -- TODO(justinmk): Order is stable but undefined. Sort before return? - eq({Cmd2=cmd2, Cmd3=cmd3, Cmd4=cmd4, Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false})) + eq( + { Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 }, + meths.get_commands({ builtin = false }) + ) end) end) @@ -96,7 +202,7 @@ describe('nvim_create_user_command', function() before_each(clear) it('works with strings', function() - meths.create_user_command('SomeCommand', 'let g:command_fired = ', {nargs = 1}) + meths.create_user_command('SomeCommand', 'let g:command_fired = ', { nargs = 1 }) meths.command('SomeCommand 42') eq(42, meths.eval('g:command_fired')) end) @@ -113,227 +219,245 @@ describe('nvim_create_user_command', function() }) ]] - eq({ - name = "CommandWithLuaCallback", - args = [[this\ is a\ test]], - fargs = {"this ", "is", "a test"}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = [[this\ is a\ test]], + fargs = { 'this ', 'is', 'a test' }, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [=[ + exec_lua [=[ vim.api.nvim_command([[CommandWithLuaCallback this\ is a\ test]]) return result - ]=]) + ]=] + ) - eq({ - name = "CommandWithLuaCallback", - args = [[this includes\ a backslash: \\]], - fargs = {"this", "includes a", "backslash:", "\\"}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = [[this includes\ a backslash: \\]], + fargs = { 'this', 'includes a', 'backslash:', '\\' }, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [=[ + exec_lua [=[ vim.api.nvim_command([[CommandWithLuaCallback this includes\ a backslash: \\]]) return result - ]=]) + ]=] + ) - eq({ - name = "CommandWithLuaCallback", - args = "a\\b", - fargs = {"a\\b"}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = 'a\\b', + fargs = { 'a\\b' }, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [=[ + exec_lua [=[ vim.api.nvim_command('CommandWithLuaCallback a\\b') return result - ]=]) + ]=] + ) - eq({ - name = "CommandWithLuaCallback", - args = 'h\tey ', - fargs = {[[h]], [[ey]]}, - bang = true, - line1 = 10, - line2 = 10, - mods = "confirm unsilent botright horizontal", - smods = { - browse = false, - confirm = true, - emsg_silent = false, - hide = false, - horizontal = true, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "botright", - tab = -1, - unsilent = true, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = 'h\tey ', + fargs = { [[h]], [[ey]] }, + bang = true, + line1 = 10, + line2 = 10, + mods = 'confirm unsilent botright horizontal', + smods = { + browse = false, + confirm = true, + emsg_silent = false, + hide = false, + horizontal = true, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = 'botright', + tab = -1, + unsilent = true, + verbose = -1, + vertical = false, + }, + range = 1, + count = 10, + reg = '', }, - range = 1, - count = 10, - reg = "", - }, exec_lua [=[ + exec_lua [=[ vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ') return result - ]=]) + ]=] + ) - eq({ - name = "CommandWithLuaCallback", - args = "h", - fargs = {"h"}, - bang = false, - line1 = 1, - line2 = 42, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = 'h', + fargs = { 'h' }, + bang = false, + line1 = 1, + line2 = 42, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 1, + count = 42, + reg = '', }, - range = 1, - count = 42, - reg = "", - }, exec_lua [[ + exec_lua [[ vim.api.nvim_command('CommandWithLuaCallback 42 h') return result - ]]) + ]] + ) - eq({ - name = "CommandWithLuaCallback", - args = "", - fargs = {}, -- fargs works without args - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithLuaCallback', + args = '', + fargs = {}, -- fargs works without args + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [[ + exec_lua [[ vim.api.nvim_command('CommandWithLuaCallback') return result - ]]) + ]] + ) -- f-args doesn't split when command nargs is 1 or "?" exec_lua [[ @@ -347,80 +471,86 @@ describe('nvim_create_user_command', function() }) ]] - eq({ - name = "CommandWithOneOrNoArg", - args = "hello I'm one argument", - fargs = {"hello I'm one argument"}, -- Doesn't split args - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithOneOrNoArg', + args = "hello I'm one argument", + fargs = { "hello I'm one argument" }, -- Doesn't split args + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [[ + exec_lua [[ vim.api.nvim_command('CommandWithOneOrNoArg hello I\'m one argument') return result - ]]) + ]] + ) -- f-args is an empty table if no args were passed - eq({ - name = "CommandWithOneOrNoArg", - args = "", - fargs = {}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithOneOrNoArg', + args = '', + fargs = {}, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [[ + exec_lua [[ vim.api.nvim_command('CommandWithOneOrNoArg') return result - ]]) + ]] + ) -- f-args is an empty table when the command nargs=0 exec_lua [[ @@ -434,88 +564,93 @@ describe('nvim_create_user_command', function() register = true, }) ]] - eq({ - name = "CommandWithNoArgs", - args = "", - fargs = {}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithNoArgs', + args = '', + fargs = {}, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '', }, - range = 0, - count = 2, - reg = "", - }, exec_lua [[ + exec_lua [[ vim.cmd('CommandWithNoArgs') return result - ]]) + ]] + ) -- register can be specified - eq({ - name = "CommandWithNoArgs", - args = "", - fargs = {}, - bang = false, - line1 = 1, - line2 = 1, - mods = "", - smods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = "", - tab = -1, - unsilent = false, - verbose = -1, - vertical = false, + eq( + { + name = 'CommandWithNoArgs', + args = '', + fargs = {}, + bang = false, + line1 = 1, + line2 = 1, + mods = '', + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = '', + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = '+', }, - range = 0, - count = 2, - reg = "+", - }, exec_lua [[ + exec_lua [[ vim.cmd('CommandWithNoArgs +') return result - ]]) - + ]] + ) end) it('can define buffer-local commands', function() local bufnr = meths.create_buf(false, false) - bufmeths.create_user_command(bufnr, "Hello", "", {}) - matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) + bufmeths.create_user_command(bufnr, 'Hello', '', {}) + matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) meths.set_current_buf(bufnr) - meths.command("Hello") + meths.command('Hello') assert_alive() end) @@ -543,33 +678,63 @@ describe('nvim_create_user_command', function() end) it('does not allow invalid command names', function() - eq("Invalid command name (must start with uppercase): 'test'", 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"', {}) - ]])) - eq("Invalid command name: 't@'", pcall_err(exec_lua, [[ + ]] + ) + ) + eq( + "Invalid command name: 't@'", + pcall_err( + exec_lua, + [[ vim.api.nvim_create_user_command('t@', 'echo "hi"', {}) - ]])) - eq("Invalid command name: 'T@st'", pcall_err(exec_lua, [[ + ]] + ) + ) + eq( + "Invalid command name: 'T@st'", + pcall_err( + exec_lua, + [[ vim.api.nvim_create_user_command('T@st', 'echo "hi"', {}) - ]])) - eq("Invalid command name: 'Test!'", pcall_err(exec_lua, [[ + ]] + ) + ) + eq( + "Invalid command name: 'Test!'", + pcall_err( + exec_lua, + [[ vim.api.nvim_create_user_command('Test!', 'echo "hi"', {}) - ]])) - eq("Invalid command name: '💩'", pcall_err(exec_lua, [[ + ]] + ) + ) + eq( + "Invalid command name: '💩'", + pcall_err( + exec_lua, + [[ vim.api.nvim_create_user_command('💩', 'echo "hi"', {}) - ]])) + ]] + ) + ) end) it('smods can be used with nvim_cmd', function() - exec_lua[[ + exec_lua [[ vim.api.nvim_create_user_command('MyEcho', function(opts) vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) end, {}) ]] - eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) + eq('3', meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) eq(1, #meths.list_tabpages()) - exec_lua[[ + exec_lua [[ vim.api.nvim_create_user_command('MySplit', function(opts) vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {}) end, {}) @@ -599,13 +764,13 @@ describe('nvim_del_user_command', function() meths.create_user_command('Hello', 'echo "Hi"', {}) meths.command('Hello') meths.del_user_command('Hello') - matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) + matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) end) it('can delete buffer-local commands', function() bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {}) meths.command('Hello') bufmeths.del_user_command(0, 'Hello') - matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) + matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) end) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 56383986f3..0594f36d0e 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -45,13 +45,13 @@ end local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end local rv = get_extmark_by_id(ns, mark) - eq({er, ec}, rv) - feed("u") + eq({ er, ec }, rv) + feed('u') rv = get_extmark_by_id(ns, mark) - eq({sr, sc}, rv) - feed("") + eq({ sr, sc }, rv) + feed('') rv = get_extmark_by_id(ns, mark) - eq({er, ec}, rv) + eq({ er, ec }, rv) end local function batch_set(ns_id, positions) @@ -64,20 +64,20 @@ end local function batch_check(ns_id, ids, positions) local actual, expected = {}, {} - for i,id in ipairs(ids) do + for i, id in ipairs(ids) do expected[id] = positions[i] end for _, mark in pairs(get_extmarks(ns_id, 0, -1, {})) do - actual[mark[1]] = {mark[2], mark[3]} + actual[mark[1]] = { mark[2], mark[3] } end eq(expected, actual) end local function batch_check_undo_redo(ns_id, ids, before, after) batch_check(ns_id, ids, after) - feed("u") + feed('u') batch_check(ns_id, ids, before) - feed("") + feed('') batch_check(ns_id, ids, after) end @@ -88,49 +88,78 @@ describe('API/extmarks', function() before_each(function() -- Initialize some namespaces and insert 12345 into a buffer - marks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} - positions = {{0, 0,}, {0, 2}, {0, 3}} + marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } + positions = { { 0, 0 }, { 0, 2 }, { 0, 3 } } - init_text = "12345" + init_text = '12345' row = 0 col = 2 clear() insert(init_text) - ns = request('nvim_create_namespace', "my-fancy-plugin") - ns2 = request('nvim_create_namespace', "my-fancy-plugin2") + ns = request('nvim_create_namespace', 'my-fancy-plugin') + 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 '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})) + 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', - })) + 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() + 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 + end_row = 1, }) - eq("Invalid 'end_col': out of range", - pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })) + eq( + "Invalid 'end_col': out of range", + pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 }) + ) end) - it("can end extranges past final newline when strict mode is false", function() + it('can end extranges past final newline when strict mode is false', function() set_extmark(ns, marks[1], 0, 0, { end_col = 1, end_row = 1, @@ -138,7 +167,7 @@ describe('API/extmarks', function() }) end) - it("can end extranges past final column when strict mode is false", function() + it('can end extranges past final column when strict mode is false', function() set_extmark(ns, marks[1], 0, 0, { end_col = 6, end_row = 0, @@ -150,7 +179,7 @@ describe('API/extmarks', function() local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) rv = get_extmark_by_id(ns, marks[1]) - eq({positions[1][1], positions[1][2]}, rv) + eq({ positions[1][1], positions[1][2] }, rv) -- Test adding a second mark on same row works rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2]) eq(marks[2], rv) @@ -159,14 +188,14 @@ describe('API/extmarks', function() rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) rv = get_extmark_by_id(ns, marks[2]) - eq({positions[2][1], positions[2][2]}, rv) + eq({ positions[2][1], positions[2][2] }, rv) -- Test an update, (new pos) row = positions[1][1] col = positions[1][2] + 1 rv = set_extmark(ns, marks[1], row, col) eq(marks[1], rv) rv = get_extmark_by_id(ns, marks[1]) - eq({row, col}, rv) + eq({ row, col }, rv) -- remove the test marks eq(true, curbufmeths.del_extmark(ns, marks[1])) @@ -182,14 +211,14 @@ describe('API/extmarks', function() -- force a new undo buffer feed('o') curbufmeths.clear_namespace(ns2, 0, -1) - eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') - eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('') - eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) end) it('can clear a namespace range using 0,-1', function() @@ -198,30 +227,30 @@ describe('API/extmarks', function() -- force a new undo buffer feed('o') curbufmeths.clear_namespace(-1, 0, -1) - eq({}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') - eq({}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('') - eq({}, get_extmarks(ns, {0, 0}, {-1, -1})) - eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) + eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) + eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) end) it('can undo with extmarks (#25147)', function() feed('itest') 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})) + 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})) + 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})) + 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})) + 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})) + eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) curbufmeths.clear_namespace(ns, 0, -1) end) @@ -237,112 +266,114 @@ describe('API/extmarks', function() end -- {0, 0} and {-1, -1} work as extreme values - eq({{1, 0, 0}}, get_extmarks(ns, {0, 0}, {0, 0})) - eq({}, get_extmarks(ns, {-1, -1}, {-1, -1})) - local rv = get_extmarks(ns, {0, 0}, {-1, -1}) + eq({ { 1, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { 0, 0 })) + eq({}, get_extmarks(ns, { -1, -1 }, { -1, -1 })) + local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) for i, m in ipairs(marks) do if positions[i] ~= nil then - eq({m, positions[i][1], positions[i][2]}, rv[i]) + eq({ m, positions[i][1], positions[i][2] }, rv[i]) end end -- 0 and -1 works as short hand extreme values - eq({{1, 0, 0}}, get_extmarks(ns, 0, 0)) + eq({ { 1, 0, 0 } }, get_extmarks(ns, 0, 0)) eq({}, get_extmarks(ns, -1, -1)) rv = get_extmarks(ns, 0, -1) for i, m in ipairs(marks) do if positions[i] ~= nil then - eq({m, positions[i][1], positions[i][2]}, rv[i]) + eq({ m, positions[i][1], positions[i][2] }, rv[i]) end end -- next with mark id - rv = get_extmarks(ns, marks[1], {-1, -1}, {limit=1}) - eq({{marks[1], positions[1][1], positions[1][2]}}, rv) - rv = get_extmarks(ns, marks[2], {-1, -1}, {limit=1}) - eq({{marks[2], positions[2][1], positions[2][2]}}, rv) + rv = get_extmarks(ns, marks[1], { -1, -1 }, { limit = 1 }) + eq({ { marks[1], positions[1][1], positions[1][2] } }, rv) + rv = get_extmarks(ns, marks[2], { -1, -1 }, { limit = 1 }) + eq({ { marks[2], positions[2][1], positions[2][2] } }, rv) -- next with positional when mark exists at position - rv = get_extmarks(ns, positions[1], {-1, -1}, {limit=1}) - eq({{marks[1], positions[1][1], positions[1][2]}}, rv) + rv = get_extmarks(ns, positions[1], { -1, -1 }, { limit = 1 }) + eq({ { marks[1], positions[1][1], positions[1][2] } }, rv) -- next with positional index (no mark at position) - rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {-1, -1}, {limit=1}) - eq({{marks[2], positions[2][1], positions[2][2]}}, rv) + rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { -1, -1 }, { limit = 1 }) + eq({ { marks[2], positions[2][1], positions[2][2] } }, rv) -- next with Extremity index - rv = get_extmarks(ns, {0,0}, {-1, -1}, {limit=1}) - eq({{marks[1], positions[1][1], positions[1][2]}}, rv) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 }) + eq({ { marks[1], positions[1][1], positions[1][2] } }, rv) -- nextrange with mark id rv = get_extmarks(ns, marks[1], marks[3]) - eq({marks[1], positions[1][1], positions[1][2]}, rv[1]) - eq({marks[2], positions[2][1], positions[2][2]}, rv[2]) + eq({ marks[1], positions[1][1], positions[1][2] }, rv[1]) + eq({ marks[2], positions[2][1], positions[2][2] }, rv[2]) -- nextrange with `limit` - rv = get_extmarks(ns, marks[1], marks[3], {limit=2}) + rv = get_extmarks(ns, marks[1], marks[3], { limit = 2 }) eq(2, #rv) -- nextrange with positional when mark exists at position rv = get_extmarks(ns, positions[1], positions[3]) - eq({marks[1], positions[1][1], positions[1][2]}, rv[1]) - eq({marks[2], positions[2][1], positions[2][2]}, rv[2]) + eq({ marks[1], positions[1][1], positions[1][2] }, rv[1]) + eq({ marks[2], positions[2][1], positions[2][2] }, rv[2]) rv = get_extmarks(ns, positions[2], positions[3]) eq(2, #rv) -- nextrange with positional index (no mark at position) - local lower = {positions[1][1], positions[2][2] -1} - local upper = {positions[2][1], positions[3][2] - 1} + local lower = { positions[1][1], positions[2][2] - 1 } + local upper = { positions[2][1], positions[3][2] - 1 } rv = get_extmarks(ns, lower, upper) - eq({{marks[2], positions[2][1], positions[2][2]}}, rv) - lower = {positions[3][1], positions[3][2] + 1} - upper = {positions[3][1], positions[3][2] + 2} + eq({ { marks[2], positions[2][1], positions[2][2] } }, rv) + lower = { positions[3][1], positions[3][2] + 1 } + upper = { positions[3][1], positions[3][2] + 2 } rv = get_extmarks(ns, lower, upper) eq({}, rv) -- nextrange with extremity index - lower = {positions[2][1], positions[2][2]+1} - upper = {-1, -1} + lower = { positions[2][1], positions[2][2] + 1 } + upper = { -1, -1 } rv = get_extmarks(ns, lower, upper) - eq({{marks[3], positions[3][1], positions[3][2]}}, rv) + eq({ { marks[3], positions[3][1], positions[3][2] } }, rv) -- prev with mark id - rv = get_extmarks(ns, marks[3], {0, 0}, {limit=1}) - eq({{marks[3], positions[3][1], positions[3][2]}}, rv) - rv = get_extmarks(ns, marks[2], {0, 0}, {limit=1}) - eq({{marks[2], positions[2][1], positions[2][2]}}, rv) + rv = get_extmarks(ns, marks[3], { 0, 0 }, { limit = 1 }) + eq({ { marks[3], positions[3][1], positions[3][2] } }, rv) + rv = get_extmarks(ns, marks[2], { 0, 0 }, { limit = 1 }) + eq({ { marks[2], positions[2][1], positions[2][2] } }, rv) -- prev with positional when mark exists at position - rv = get_extmarks(ns, positions[3], {0, 0}, {limit=1}) - eq({{marks[3], positions[3][1], positions[3][2]}}, rv) + rv = get_extmarks(ns, positions[3], { 0, 0 }, { limit = 1 }) + eq({ { marks[3], positions[3][1], positions[3][2] } }, rv) -- prev with positional index (no mark at position) - rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {0, 0}, {limit=1}) - eq({{marks[1], positions[1][1], positions[1][2]}}, rv) + rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { 0, 0 }, { limit = 1 }) + eq({ { marks[1], positions[1][1], positions[1][2] } }, rv) -- prev with Extremity index - rv = get_extmarks(ns, {-1,-1}, {0,0}, {limit=1}) - eq({{marks[3], positions[3][1], positions[3][2]}}, rv) + rv = get_extmarks(ns, { -1, -1 }, { 0, 0 }, { limit = 1 }) + eq({ { marks[3], positions[3][1], positions[3][2] } }, rv) -- prevrange with mark id rv = get_extmarks(ns, marks[3], marks[1]) - eq({marks[3], positions[3][1], positions[3][2]}, rv[1]) - eq({marks[2], positions[2][1], positions[2][2]}, rv[2]) - eq({marks[1], positions[1][1], positions[1][2]}, rv[3]) + eq({ marks[3], positions[3][1], positions[3][2] }, rv[1]) + eq({ marks[2], positions[2][1], positions[2][2] }, rv[2]) + eq({ marks[1], positions[1][1], positions[1][2] }, rv[3]) -- prevrange with limit - rv = get_extmarks(ns, marks[3], marks[1], {limit=2}) + rv = get_extmarks(ns, marks[3], marks[1], { limit = 2 }) eq(2, #rv) -- prevrange with positional when mark exists at position rv = get_extmarks(ns, positions[3], positions[1]) - eq({{marks[3], positions[3][1], positions[3][2]}, - {marks[2], positions[2][1], positions[2][2]}, - {marks[1], positions[1][1], positions[1][2]}}, rv) + eq({ + { marks[3], positions[3][1], positions[3][2] }, + { marks[2], positions[2][1], positions[2][2] }, + { marks[1], positions[1][1], positions[1][2] }, + }, rv) rv = get_extmarks(ns, positions[2], positions[1]) eq(2, #rv) -- prevrange with positional index (no mark at position) - lower = {positions[2][1], positions[2][2] + 1} - upper = {positions[3][1], positions[3][2] + 1} + lower = { positions[2][1], positions[2][2] + 1 } + upper = { positions[3][1], positions[3][2] + 1 } rv = get_extmarks(ns, upper, lower) - eq({{marks[3], positions[3][1], positions[3][2]}}, rv) - lower = {positions[3][1], positions[3][2] + 1} - upper = {positions[3][1], positions[3][2] + 2} + eq({ { marks[3], positions[3][1], positions[3][2] } }, rv) + lower = { positions[3][1], positions[3][2] + 1 } + upper = { positions[3][1], positions[3][2] + 2 } rv = get_extmarks(ns, upper, lower) eq({}, rv) -- prevrange with extremity index - lower = {0,0} - upper = {positions[2][1], positions[2][2] - 1} + lower = { 0, 0 } + upper = { positions[2][1], positions[2][2] - 1 } rv = get_extmarks(ns, upper, lower) - eq({{marks[1], positions[1][1], positions[1][2]}}, rv) + eq({ { marks[1], positions[1][1], positions[1][2] } }, rv) end) it('querying for information with limit', function() @@ -354,34 +385,34 @@ describe('API/extmarks', function() end end - local rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1}) + local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 }) eq(1, #rv) - rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 }) eq(2, #rv) - rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 }) eq(3, #rv) -- now in reverse - rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 }) eq(1, #rv) - rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 }) eq(2, #rv) - rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 }) eq(3, #rv) end) it('get_marks works when mark col > upper col', function() feed('A12345') feed('A12345') - set_extmark(ns, 10, 0, 2) -- this shouldn't be found - set_extmark(ns, 11, 2, 1) -- this shouldn't be found + set_extmark(ns, 10, 0, 2) -- this shouldn't be found + set_extmark(ns, 11, 2, 1) -- this shouldn't be found set_extmark(ns, marks[1], 0, 4) -- check col > our upper bound set_extmark(ns, marks[2], 1, 1) -- check col < lower bound set_extmark(ns, marks[3], 2, 0) -- check is inclusive - eq({{marks[1], 0, 4}, - {marks[2], 1, 1}, - {marks[3], 2, 0}}, - get_extmarks(ns, {0, 3}, {2, 0})) + eq( + { { marks[1], 0, 4 }, { marks[2], 1, 1 }, { marks[3], 2, 0 } }, + get_extmarks(ns, { 0, 3 }, { 2, 0 }) + ) end) it('get_marks works in reverse when mark col < lower col', function() @@ -392,28 +423,24 @@ describe('API/extmarks', function() set_extmark(ns, marks[1], 2, 1) -- check col < our lower bound set_extmark(ns, marks[2], 1, 4) -- check col > upper bound set_extmark(ns, marks[3], 0, 2) -- check is inclusive - local rv = get_extmarks(ns, {2, 3}, {0, 2}) - eq({{marks[1], 2, 1}, - {marks[2], 1, 4}, - {marks[3], 0, 2}}, - rv) + local rv = get_extmarks(ns, { 2, 3 }, { 0, 2 }) + eq({ { marks[1], 2, 1 }, { marks[2], 1, 4 }, { marks[3], 0, 2 } }, rv) end) it('get_marks limit=0 returns nothing', function() set_extmark(ns, marks[1], positions[1][1], positions[1][2]) - local rv = get_extmarks(ns, {-1, -1}, {-1, -1}, {limit=0}) + local rv = get_extmarks(ns, { -1, -1 }, { -1, -1 }, { limit = 0 }) eq({}, rv) end) - it('marks move with line insertations', function() set_extmark(ns, marks[1], 0, 0) - feed("yyP") + feed('yyP') check_undo_redo(ns, marks[1], 0, 0, 1, 0) end) it('marks move with multiline insertations', function() - feed("a2233") + feed('a2233') set_extmark(ns, marks[1], 1, 1) feed('ggVGyP') check_undo_redo(ns, marks[1], 1, 1, 4, 1) @@ -421,7 +448,7 @@ describe('API/extmarks', function() it('marks move with line join', function() -- do_join in ops.c - feed("a222") + feed('a222') set_extmark(ns, marks[1], 1, 0) feed('ggJ') check_undo_redo(ns, marks[1], 1, 0, 0, 6) @@ -430,7 +457,7 @@ describe('API/extmarks', function() it('join works when no marks are present', function() screen = Screen.new(15, 10) screen:attach() - feed("a1") + feed('a1') feed('kJ') -- This shouldn't seg fault screen:expect([[ @@ -442,21 +469,21 @@ describe('API/extmarks', function() it('marks move with multiline join', function() -- do_join in ops.c - feed("a222333444") + feed('a222333444') set_extmark(ns, marks[1], 3, 0) feed('2GVGJ') check_undo_redo(ns, marks[1], 3, 0, 1, 8) end) it('marks move with line deletes', function() - feed("a222333444") + feed('a222333444') set_extmark(ns, marks[1], 2, 1) feed('ggjdd') check_undo_redo(ns, marks[1], 2, 1, 1, 1) end) it('marks move with multiline deletes', function() - feed("a222333444") + feed('a222333444') set_extmark(ns, marks[1], 3, 0) feed('gg2dd') check_undo_redo(ns, marks[1], 3, 0, 1, 0) @@ -468,7 +495,7 @@ describe('API/extmarks', function() it('marks move with open line', function() -- open_line in change.c -- testing marks below are also moved - feed("yyP") + feed('yyP') set_extmark(ns, marks[1], 0, 4) set_extmark(ns, marks[2], 1, 4) feed('1G') @@ -492,7 +519,7 @@ describe('API/extmarks', function() | ]]) local rv = get_extmark_by_id(ns, marks[1]) - eq({0, 6}, rv) + eq({ 0, 6 }, rv) check_undo_redo(ns, marks[1], 0, 3, 0, 6) end) @@ -501,12 +528,12 @@ describe('API/extmarks', function() -- insertchar in edit.c (the ins_str branch) set_extmark(ns, marks[1], 0, 2) feed('03l') - insert("X") + insert('X') check_undo_redo(ns, marks[1], 0, 2, 0, 2) -- check multibyte chars feed('03l') - insert("~~") + insert('~~') check_undo_redo(ns, marks[1], 0, 2, 0, 2) end) @@ -530,7 +557,7 @@ describe('API/extmarks', function() it('marks move with line splits (using enter)', function() -- open_line in change.c -- testing marks below are also moved - feed("yyP") + feed('yyP') set_extmark(ns, marks[1], 0, 4) set_extmark(ns, marks[2], 1, 4) feed('1Gla') @@ -547,16 +574,16 @@ describe('API/extmarks', function() it('yet again marks move with line splits', function() -- the first test above wasn't catching all errors.. - feed("A67890") + feed('A67890') set_extmark(ns, marks[1], 0, 4) - feed("04li") + feed('04li') check_undo_redo(ns, marks[1], 0, 4, 1, 0) end) it('and one last time line splits...', function() set_extmark(ns, marks[1], 0, 1) set_extmark(ns, marks[2], 0, 2) - feed("02li") + feed('02li') check_undo_redo(ns, marks[1], 0, 1, 0, 1) check_undo_redo(ns, marks[2], 0, 2, 1, 0) end) @@ -564,7 +591,7 @@ describe('API/extmarks', function() it('multiple marks move with mark splits', function() set_extmark(ns, marks[1], 0, 1) set_extmark(ns, marks[2], 0, 3) - feed("0li") + feed('0li') check_undo_redo(ns, marks[1], 0, 1, 1, 0) check_undo_redo(ns, marks[2], 0, 3, 1, 2) end) @@ -656,11 +683,11 @@ describe('API/extmarks', function() feed('0vx') check_undo_redo(ns, marks[1], 0, 3, 0, 2) - feed("u") + feed('u') feed('0vlx') check_undo_redo(ns, marks[1], 0, 3, 0, 1) - feed("u") + feed('u') feed('0v2lx') check_undo_redo(ns, marks[1], 0, 3, 0, 0) @@ -675,16 +702,16 @@ describe('API/extmarks', function() feed('0x') check_undo_redo(ns, marks[1], 0, 3, 0, 2) - feed("u") + feed('u') feed('02x') check_undo_redo(ns, marks[1], 0, 3, 0, 1) - feed("u") + feed('u') feed('0v3lx') check_undo_redo(ns, marks[1], 0, 3, 0, 0) -- from the other side (nothing should happen) - feed("u") + feed('u') feed('$vx') check_undo_redo(ns, marks[1], 0, 3, 0, 3) end) @@ -742,27 +769,44 @@ describe('API/extmarks', function() it('delete', function() local pos1 = { - {2, 4}, {2, 12}, {2, 13}, {2, 14}, {2, 25}, - {4, 8}, {4, 10}, {4, 20}, - {5, 3}, {6, 10} + { 2, 4 }, + { 2, 12 }, + { 2, 13 }, + { 2, 14 }, + { 2, 25 }, + { 4, 8 }, + { 4, 10 }, + { 4, 20 }, + { 5, 3 }, + { 6, 10 }, } local ids = batch_set(ns, pos1) batch_check(ns, ids, pos1) feed('3Gfiv2+ftd') batch_check_undo_redo(ns, ids, pos1, { - {2, 4}, {2, 12}, {2, 13}, {2, 13}, {2, 13}, - {2, 13}, {2, 15}, {2, 25}, - {3, 3}, {4, 10} + { 2, 4 }, + { 2, 12 }, + { 2, 13 }, + { 2, 13 }, + { 2, 13 }, + { 2, 13 }, + { 2, 15 }, + { 2, 25 }, + { 3, 3 }, + { 4, 10 }, }) end) 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 })) + 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) @@ -862,33 +906,40 @@ describe('API/extmarks', function() set_extmark(ns, marks[2], 0, -1) set_extmark(ns, marks[3], 0, -1) - feed("u") - local rv = get_extmarks(ns, {0, 0}, {-1, -1}) + feed('u') + local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(3, #rv) - feed("") - rv = get_extmarks(ns, {0, 0}, {-1, -1}) + feed('') + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(3, #rv) -- Test updates feed('o') set_extmark(ns, marks[1], positions[1][1], positions[1][2]) - rv = get_extmarks(ns, marks[1], marks[1], {limit=1}) + rv = get_extmarks(ns, marks[1], marks[1], { limit = 1 }) eq(1, #rv) - feed("u") - feed("") + feed('u') + feed('') -- old value is NOT kept in history - check_undo_redo(ns, marks[1], positions[1][1], positions[1][2], positions[1][1], positions[1][2]) + check_undo_redo( + ns, + marks[1], + positions[1][1], + positions[1][2], + positions[1][1], + positions[1][2] + ) -- Test unset feed('o') curbufmeths.del_extmark(ns, marks[3]) - feed("u") - rv = get_extmarks(ns, {0, 0}, {-1, -1}) + feed('u') + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) -- undo does NOT restore deleted marks eq(2, #rv) - feed("") - rv = get_extmarks(ns, {0, 0}, {-1, -1}) + feed('') + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(2, #rv) end) @@ -905,9 +956,9 @@ describe('API/extmarks', function() eq(1, rv) rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2]) eq(1, rv) - rv = get_extmarks(ns, {0, 0}, {-1, -1}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(1, #rv) - rv = get_extmarks(ns2, {0, 0}, {-1, -1}) + rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) eq(1, #rv) -- Set more marks for testing the ranges @@ -917,14 +968,14 @@ describe('API/extmarks', function() set_extmark(ns2, marks[3], positions[3][1], positions[3][2]) -- get_next (limit set) - rv = get_extmarks(ns, {0, 0}, positions[2], {limit=1}) + rv = get_extmarks(ns, { 0, 0 }, positions[2], { limit = 1 }) eq(1, #rv) - rv = get_extmarks(ns2, {0, 0}, positions[2], {limit=1}) + rv = get_extmarks(ns2, { 0, 0 }, positions[2], { limit = 1 }) eq(1, #rv) -- get_prev (limit set) - rv = get_extmarks(ns, positions[1], {0, 0}, {limit=1}) + rv = get_extmarks(ns, positions[1], { 0, 0 }, { limit = 1 }) eq(1, #rv) - rv = get_extmarks(ns2, positions[1], {0, 0}, {limit=1}) + rv = get_extmarks(ns2, positions[1], { 0, 0 }, { limit = 1 }) eq(1, #rv) -- get_next (no limit) @@ -939,10 +990,10 @@ describe('API/extmarks', function() eq(2, #rv) curbufmeths.del_extmark(ns, marks[1]) - rv = get_extmarks(ns, {0, 0}, {-1, -1}) + rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(2, #rv) curbufmeths.del_extmark(ns2, marks[1]) - rv = get_extmarks(ns2, {0, 0}, {-1, -1}) + rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) eq(2, #rv) end) @@ -966,16 +1017,16 @@ describe('API/extmarks', function() feed(':set cindent') feed(':set autoindent') feed(':set shiftwidth=2') - feed("0iint A {1M1b") + feed('0iint A {1M1b') -- Set the mark on the M, should move.. set_extmark(ns, marks[1], 0, 12) -- Set the mark before the cursor, should stay there set_extmark(ns, marks[2], 0, 10) - feed("i") + feed('i') local rv = get_extmark_by_id(ns, marks[1]) - eq({1, 3}, rv) + eq({ 1, 3 }, rv) rv = get_extmark_by_id(ns, marks[2]) - eq({0, 10}, rv) + eq({ 0, 10 }, rv) check_undo_redo(ns, marks[1], 0, 12, 1, 3) end) @@ -984,39 +1035,39 @@ describe('API/extmarks', function() feed(':set autoindent') feed(':set shiftwidth=2') -- will force an indent of 2 - feed("0iint A {0i1M1") + feed('0iint A {0i1M1') set_extmark(ns, marks[1], 1, 1) - feed("0i") + feed('0i') local rv = get_extmark_by_id(ns, marks[1]) - eq({1, 3}, rv) + eq({ 1, 3 }, rv) check_undo_redo(ns, marks[1], 1, 1, 1, 3) -- now check when cursor at eol - feed("uA") + feed('uA') rv = get_extmark_by_id(ns, marks[1]) - eq({1, 3}, rv) + eq({ 1, 3 }, rv) end) it('removing auto indenting with works', function() feed(':set cindent') feed(':set autoindent') feed(':set shiftwidth=2') - feed("0i") + feed('0i') set_extmark(ns, marks[1], 0, 3) - feed("bi") + feed('bi') local rv = get_extmark_by_id(ns, marks[1]) - eq({0, 1}, rv) + eq({ 0, 1 }, rv) check_undo_redo(ns, marks[1], 0, 3, 0, 1) -- check when cursor at eol - feed("uA") + feed('uA') rv = get_extmark_by_id(ns, marks[1]) - eq({0, 1}, rv) + eq({ 0, 1 }, rv) end) it('indenting multiple lines with = works', function() feed(':set cindent') feed(':set autoindent') feed(':set shiftwidth=2') - feed("0iint A {1M12M2") + feed('0iint A {1M12M2') set_extmark(ns, marks[1], 1, 1) set_extmark(ns, marks[2], 2, 1) feed('=gg') @@ -1138,7 +1189,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[5], 2, 0, 3, 0) feed('u') feed([[:1,2s:3:\rxx]]) - eq({1, 3}, get_extmark_by_id(ns, marks[3])) + eq({ 1, 3 }, get_extmark_by_id(ns, marks[3])) end) it('substitutes over multiple lines with replace in substitution', function() @@ -1374,7 +1425,10 @@ describe('API/extmarks', function() it('throws consistent error codes', function() local ns_invalid = ns2 + 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(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])) @@ -1383,11 +1437,11 @@ describe('API/extmarks', function() it('when col = line-length, set the mark on eol', function() set_extmark(ns, marks[1], 0, -1) local rv = get_extmark_by_id(ns, marks[1]) - eq({0, init_text:len()}, rv) + eq({ 0, init_text:len() }, rv) -- Test another set_extmark(ns, marks[1], 0, -1) rv = get_extmark_by_id(ns, marks[1]) - eq({0, init_text:len()}, rv) + eq({ 0, init_text:len() }, rv) end) it('when col = line-length, set the mark on eol', function() @@ -1398,7 +1452,10 @@ describe('API/extmarks', function() it('fails when line > line_count', function() local invalid_col = init_text:len() + 1 local invalid_lnum = 3 - eq("Invalid 'line': out of 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) @@ -1414,17 +1471,17 @@ describe('API/extmarks', function() end) it('in read-only buffer', function() - command("view! runtime/doc/help.txt") + command('view! runtime/doc/help.txt') eq(true, meths.get_option_value('ro', {})) local id = set_extmark(ns, 0, 0, 2) - eq({{id, 0, 2}}, get_extmarks(ns,0, -1)) + eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) end) it('can set a mark to other buffer', function() local buf = request('nvim_create_buf', 0, 1) - request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""}) + request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' }) local id = bufmeths.set_extmark(buf, ns, 1, 0, {}) - eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {})) + eq({ { id, 1, 0 } }, bufmeths.get_extmarks(buf, ns, 0, -1, {})) end) it('does not crash with append/delete/undo sequence', function() @@ -1440,49 +1497,51 @@ describe('API/extmarks', function() it('works with left and right gravity', function() -- right gravity should move with inserted text, while -- left gravity should stay in place. - curbufmeths.set_extmark(ns, 0, 5, {right_gravity = false}) - curbufmeths.set_extmark(ns, 0, 5, {right_gravity = true}) + curbufmeths.set_extmark(ns, 0, 5, { right_gravity = false }) + curbufmeths.set_extmark(ns, 0, 5, { right_gravity = true }) feed([[Aasdfasdf]]) - eq({ {1, 0, 5}, {2, 0, 13} }, - curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 5 }, { 2, 0, 13 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) -- but both move when text is inserted before feed([[Iasdf]]) -- eq({}, curbufmeths.get_lines(0, -1, true)) - eq({ {1, 0, 9}, {2, 0, 17} }, - curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 9 }, { 2, 0, 17 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) -- clear text curbufmeths.set_text(0, 0, 0, 17, {}) -- handles set_text correctly as well - eq({ {1, 0, 0}, {2, 0, 0} }, - meths.buf_get_extmarks(0, ns, 0, -1, {})) - curbufmeths.set_text(0, 0, 0, 0, {'asdfasdf'}) - eq({ {1, 0, 0}, {2, 0, 8} }, - curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.buf_get_extmarks(0, ns, 0, -1, {})) + curbufmeths.set_text(0, 0, 0, 0, { 'asdfasdf' }) + eq({ { 1, 0, 0 }, { 2, 0, 8 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) feed('u') -- handles pasting exec([[let @a='asdfasdf']]) feed([["ap]]) - eq({ {1, 0, 0}, {2, 0, 8} }, - meths.buf_get_extmarks(0, ns, 0, -1, {})) + eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.buf_get_extmarks(0, ns, 0, -1, {})) end) it('can accept "end_row" or "end_line" #16548', function() set_extmark(ns, marks[1], 0, 0, { end_col = 0, - end_line = 1 + end_line = 1, }) - eq({ {1, 0, 0, { - ns_id = 1, - end_col = 0, - end_row = 1, - right_gravity = true, - end_right_gravity = false, - }} }, get_extmarks(ns, 0, -1, {details=true})) + eq({ + { + 1, + 0, + 0, + { + ns_id = 1, + end_col = 0, + end_row = 1, + right_gravity = true, + end_right_gravity = false, + }, + }, + }, get_extmarks(ns, 0, -1, { details = true })) end) it('in prompt buffer', function() @@ -1490,129 +1549,149 @@ describe('API/extmarks', function() local id = set_extmark(ns, marks[1], 0, 0, {}) meths.set_option_value('buftype', 'prompt', {}) feed('i') - eq({{id, 0, 2}}, get_extmarks(ns, 0, -1)) + 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", + conceal = 'c', + cursorline_hl_group = 'Statement', end_col = 0, end_right_gravity = true, end_row = 1, hl_eol = true, - hl_group = "String", - hl_mode = "blend", - line_hl_group = "Statement", - number_hl_group = "Statement", + hl_group = 'String', + hl_mode = 'blend', + line_hl_group = 'Statement', + number_hl_group = 'Statement', priority = 0, right_gravity = false, - sign_hl_group = "Statement", - sign_text = ">>", + sign_hl_group = 'Statement', + sign_text = '>>', spell = true, virt_lines = { - { { "lines", "Macro" }, { "???" } }, - { { "stack", { "Type", "Search" } }, { "!!!" } }, + { { 'lines', 'Macro' }, { '???' } }, + { { 'stack', { 'Type', 'Search' } }, { '!!!' } }, }, virt_lines_above = true, virt_lines_leftcol = true, - virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } }, + virt_text = { { 'text', 'Macro' }, { '???' }, { 'stack', { 'Type', 'Search' } } }, virt_text_hide = true, - virt_text_pos = "right_align", + virt_text_pos = 'right_align', }) set_extmark(ns, marks[2], 0, 0, { priority = 0, - virt_text = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } }, + virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } }, virt_text_win_col = 1, }) - eq({0, 0, { - conceal = "c", - cursorline_hl_group = "Statement", - end_col = 0, - end_right_gravity = true, - end_row = 1, - hl_eol = true, - hl_group = "String", - 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" } }, { "!!!" } }, + eq({ + 0, + 0, + { + conceal = 'c', + cursorline_hl_group = 'Statement', + end_col = 0, + end_right_gravity = true, + end_row = 1, + hl_eol = true, + hl_group = 'String', + 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_repeat_linebreak = false, + virt_text_hide = true, + virt_text_pos = 'right_align', }, - virt_lines_above = true, - virt_lines_leftcol = true, - virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } }, - virt_text_repeat_linebreak = false, - 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 = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } }, - virt_text_repeat_linebreak = false, - 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 })) + }, get_extmark_by_id(ns, marks[1], { details = true })) + eq({ + 0, + 0, + { + ns_id = 1, + right_gravity = true, + priority = 0, + virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } }, + virt_text_repeat_linebreak = false, + 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 })) + 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', "") + 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 })) + 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' }}}}) + 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' })) + 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() + it('invalidated marks are deleted', function() screen = Screen.new(40, 6) screen:attach() feed('dd6iaaa bbb cccgg') @@ -1641,8 +1720,13 @@ describe('API/extmarks', function() 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 }) + 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 @@ -1650,18 +1734,23 @@ describe('API/extmarks', function() 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) + 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) + 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 }) + 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, {})) + 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, {})) @@ -1674,29 +1763,28 @@ describe('Extmarks buffer api with many marks', function() local ns_marks = {} before_each(function() clear() - ns1 = request('nvim_create_namespace', "ns1") - ns2 = request('nvim_create_namespace', "ns2") - ns_marks = {[ns1]={}, [ns2]={}} + ns1 = request('nvim_create_namespace', 'ns1') + ns2 = request('nvim_create_namespace', 'ns2') + ns_marks = { [ns1] = {}, [ns2] = {} } local lines = {} - for i = 1,30 do - lines[#lines+1] = string.rep("x ",i) + for i = 1, 30 do + lines[#lines + 1] = string.rep('x ', i) end curbufmeths.set_lines(0, -1, true, lines) local ns = ns1 local q = 0 - for i = 0,29 do - for j = 0,i do - local id = set_extmark(ns,0, i,j) + for i = 0, 29 do + for j = 0, i do + local id = set_extmark(ns, 0, i, j) eq(nil, ns_marks[ns][id]) ok(id > 0) - ns_marks[ns][id] = {i,j} - ns = ns1+ns2-ns + ns_marks[ns][id] = { i, j } + ns = ns1 + ns2 - ns q = q + 1 end end eq(233, #ns_marks[ns1]) eq(232, #ns_marks[ns2]) - end) local function get_marks(ns) @@ -1704,18 +1792,18 @@ describe('Extmarks buffer api with many marks', function() local marks = {} for _, mark in ipairs(mark_list) do local id, row, col = unpack(mark) - eq(nil, marks[id], "duplicate mark") - marks[id] = {row,col} + eq(nil, marks[id], 'duplicate mark') + marks[id] = { row, col } end return marks end - it("can get marks", function() + it('can get marks', function() eq(ns_marks[ns1], get_marks(ns1)) eq(ns_marks[ns2], get_marks(ns2)) end) - it("can clear all marks in ns", function() + it('can clear all marks in ns', function() curbufmeths.clear_namespace(ns1, 0, -1) eq({}, get_marks(ns1)) eq(ns_marks[ns2], get_marks(ns2)) @@ -1724,7 +1812,7 @@ describe('Extmarks buffer api with many marks', function() eq({}, get_marks(ns2)) end) - it("can clear line range", function() + it('can clear line range', function() curbufmeths.clear_namespace(ns1, 10, 20) for id, mark in pairs(ns_marks[ns1]) do if 10 <= mark[1] and mark[1] < 20 then @@ -1735,12 +1823,12 @@ describe('Extmarks buffer api with many marks', function() eq(ns_marks[ns2], get_marks(ns2)) end) - it("can delete line", function() + it('can delete line', function() feed('10Gdd') for _, marks in pairs(ns_marks) do for id, mark in pairs(marks) do if mark[1] == 9 then - marks[id] = {9,0} + marks[id] = { 9, 0 } elseif mark[1] >= 10 then mark[1] = mark[1] - 1 end @@ -1750,12 +1838,12 @@ describe('Extmarks buffer api with many marks', function() eq(ns_marks[ns2], get_marks(ns2)) end) - it("can delete lines", function() + it('can delete lines', function() feed('10G10dd') for _, marks in pairs(ns_marks) do for id, mark in pairs(marks) do if 9 <= mark[1] and mark[1] < 19 then - marks[id] = {9,0} + marks[id] = { 9, 0 } elseif mark[1] >= 19 then mark[1] = mark[1] - 10 end @@ -1765,7 +1853,7 @@ describe('Extmarks buffer api with many marks', function() eq(ns_marks[ns2], get_marks(ns2)) end) - it("can wipe buffer", function() + it('can wipe buffer', function() command('bwipe!') eq({}, get_marks(ns1)) eq({}, get_marks(ns2)) @@ -1779,17 +1867,17 @@ describe('API/win_extmark', function() before_each(function() -- Initialize some namespaces and insert text into a buffer - marks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} + marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } - line1 = "non ui-watched line" - line2 = "ui-watched line" + line1 = 'non ui-watched line' + line2 = 'ui-watched line' clear() insert(line1) - feed("o") + feed('o') insert(line2) - ns = request('nvim_create_namespace', "extmark-ui") + ns = request('nvim_create_namespace', 'extmark-ui') end) it('sends and only sends ui-watched marks to ui', function() @@ -1809,8 +1897,8 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- positioned at the end of the 2nd line - { {id = 1000}, ns, marks[1], 1, 16 }, - } + { { id = 1000 }, ns, marks[1], 1, 16 }, + }, }, }) end) @@ -1820,10 +1908,10 @@ describe('API/win_extmark', function() screen:attach() feed('15A!') -- should send all of these - set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = "overlay" }) - set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = "overlay" }) - set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = "overlay" }) - set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = 'overlay' }) + set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = 'overlay' }) + set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = 'overlay' }) + set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = 'overlay' }) set_extmark(ns, marks[5], 1, 8, { ui_watched = true }) screen:expect({ grid = [[ @@ -1835,28 +1923,28 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- notification from 1st call - { {id = 1000}, ns, marks[1], 1, 0 }, + { { id = 1000 }, ns, marks[1], 1, 0 }, -- notifications from 2nd call - { {id = 1000}, ns, marks[1], 1, 0 }, - { {id = 1000}, ns, marks[2], 1, 2 }, + { { id = 1000 }, ns, marks[1], 1, 0 }, + { { id = 1000 }, ns, marks[2], 1, 2 }, -- notifications from 3rd call - { {id = 1000}, ns, marks[1], 1, 0 }, - { {id = 1000}, ns, marks[2], 1, 2 }, - { {id = 1000}, ns, marks[3], 1, 4 }, + { { id = 1000 }, ns, marks[1], 1, 0 }, + { { id = 1000 }, ns, marks[2], 1, 2 }, + { { id = 1000 }, ns, marks[3], 1, 4 }, -- notifications from 4th call - { {id = 1000}, ns, marks[1], 1, 0 }, - { {id = 1000}, ns, marks[2], 1, 2 }, - { {id = 1000}, ns, marks[3], 1, 4 }, - { {id = 1000}, ns, marks[4], 1, 6 }, + { { id = 1000 }, ns, marks[1], 1, 0 }, + { { id = 1000 }, ns, marks[2], 1, 2 }, + { { id = 1000 }, ns, marks[3], 1, 4 }, + { { id = 1000 }, ns, marks[4], 1, 6 }, -- final -- overlay - { {id = 1000}, ns, marks[1], 1, 0 }, - { {id = 1000}, ns, marks[2], 1, 2 }, - { {id = 1000}, ns, marks[3], 1, 4 }, - { {id = 1000}, ns, marks[4], 1, 6 }, + { { id = 1000 }, ns, marks[1], 1, 0 }, + { { id = 1000 }, ns, marks[2], 1, 2 }, + { { id = 1000 }, ns, marks[3], 1, 4 }, + { { id = 1000 }, ns, marks[4], 1, 6 }, -- eol - { {id = 1000}, ns, marks[5], 2, 11 }, - } + { { id = 1000 }, ns, marks[5], 2, 11 }, + }, }, }) end) @@ -1869,7 +1957,7 @@ describe('API/win_extmark', function() -- should not send this set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) -- make some changes - insert(" update") + insert(' update') screen:expect({ grid = [[ non ui-watched line | @@ -1880,13 +1968,13 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- positioned at the end of the 2nd line - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, -- updated and wrapped to 3rd line - { {id = 1000}, ns, marks[1], 2, 2 }, - } - } + { { id = 1000 }, ns, marks[1], 2, 2 }, + }, + }, }) - feed("") + feed('') screen:expect({ grid = [[ ui-watched linupdat^e| @@ -1897,18 +1985,18 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- positioned at the end of the 2nd line - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, -- updated and wrapped to 3rd line - { {id = 1000}, ns, marks[1], 2, 2 }, + { { id = 1000 }, ns, marks[1], 2, 2 }, -- scrolled up one line, should be handled by grid scroll - } - } + }, + }, }) end) it('sends ui-watched to splits', function() screen = Screen.new(20, 8) - screen:attach({ext_multigrid=true}) + screen:attach({ ext_multigrid = true }) -- should send this set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) -- should not send this @@ -1935,18 +2023,18 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- positioned at the end of the 2nd line - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, -- updated after split - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, }, [4] = { -- only after split - { {id = 1001}, ns, marks[1], 1, 16 }, - } - } + { { id = 1001 }, ns, marks[1], 1, 16 }, + }, + }, }) -- make some changes - insert(" update") + insert(' update') screen:expect({ grid = [[ ## grid 1 @@ -1968,16 +2056,16 @@ describe('API/win_extmark', function() extmarks = { [2] = { -- positioned at the end of the 2nd line - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, -- updated after split - { {id = 1000}, ns, marks[1], 1, 16 }, + { { id = 1000 }, ns, marks[1], 1, 16 }, }, [4] = { - { {id = 1001}, ns, marks[1], 1, 16 }, + { { id = 1001 }, ns, marks[1], 1, 16 }, -- updated - { {id = 1001}, ns, marks[1], 2, 2 }, - } - } + { { id = 1001 }, ns, marks[1], 2, 2 }, + }, + }, }) end) end) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index c9edbf825d..fe9e2a7727 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -10,7 +10,7 @@ local pcall_err = helpers.pcall_err local ok = helpers.ok local assert_alive = helpers.assert_alive -describe('API: highlight',function() +describe('API: highlight', function() clear() Screen.new() -- initialize Screen.colors @@ -45,31 +45,35 @@ describe('API: highlight',function() before_each(function() clear() - command("hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold") + command( + 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' + ) end) - it("nvim_get_hl_by_id", function() + it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim("get_hl_by_id", hl_id, false)) + eq(expected_cterm, nvim('get_hl_by_id', hl_id, false)) hl_id = eval("hlID('NewHighlight')") -- Test valid id. - eq(expected_rgb, nvim("get_hl_by_id", hl_id, true)) + eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) -- Test invalid id. 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') - eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true)) + eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, nvim("get_hl_by_id", hl_id, true)) + eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) -- Test nil argument. - eq('Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - pcall_err(meths.get_hl_by_id, { nil }, false)) + eq( + 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', + pcall_err(meths.get_hl_by_id, { nil }, false) + ) -- Test 0 argument. eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false)) @@ -81,76 +85,83 @@ describe('API: highlight',function() command('hi Normal ctermfg=red ctermbg=yellow') command('hi NewConstant ctermfg=green guifg=white guibg=blue') hl_id = eval("hlID('NewConstant')") - eq({foreground = 10,}, meths.get_hl_by_id(hl_id, false)) + eq({ foreground = 10 }, meths.get_hl_by_id(hl_id, false)) -- Test highlight group without ctermfg value. command('hi clear NewConstant') command('hi NewConstant ctermbg=Magenta guifg=white guibg=blue') - eq({background = 13,}, meths.get_hl_by_id(hl_id, false)) + eq({ background = 13 }, meths.get_hl_by_id(hl_id, false)) -- Test highlight group with ctermfg and ctermbg values. command('hi clear NewConstant') command('hi NewConstant ctermfg=green ctermbg=Magenta guifg=white guibg=blue') - eq({foreground = 10, background = 13,}, meths.get_hl_by_id(hl_id, false)) + eq({ foreground = 10, background = 13 }, meths.get_hl_by_id(hl_id, false)) end) - it("nvim_get_hl_by_name", function() - local expected_normal = { background = Screen.colors.Yellow, - foreground = Screen.colors.Red } + it('nvim_get_hl_by_name', function() + local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, nvim("get_hl_by_name", 'Normal', true)) + eq({}, nvim('get_hl_by_name', 'Normal', true)) - eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight', false)) - eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight', true)) + eq(expected_cterm, nvim('get_hl_by_name', 'NewHighlight', false)) + eq(expected_rgb, nvim('get_hl_by_name', 'NewHighlight', true)) -- Test `Normal` modified values. command('hi Normal guifg=red guibg=yellow') - eq(expected_normal, nvim("get_hl_by_name", 'Normal', true)) + eq(expected_normal, nvim('get_hl_by_name', 'Normal', true)) -- Test invalid name. - eq("Invalid highlight name: 'unknown_highlight'", - pcall_err(meths.get_hl_by_name , 'unknown_highlight', false)) + eq( + "Invalid highlight name: 'unknown_highlight'", + pcall_err(meths.get_hl_by_name, 'unknown_highlight', false) + ) -- Test nil argument. - eq('Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - pcall_err(meths.get_hl_by_name , { nil }, false)) + eq( + 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', + pcall_err(meths.get_hl_by_name, { nil }, false) + ) -- Test empty string argument. - eq('Invalid highlight name', - pcall_err(meths.get_hl_by_name , '', false)) + eq('Invalid highlight name', pcall_err(meths.get_hl_by_name, '', false)) -- Test "standout" attribute. #8054 - eq({ underline = true, }, - meths.get_hl_by_name('cursorline', 0)); + eq({ underline = true }, meths.get_hl_by_name('cursorline', 0)) command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('set cursorline') - eq({ underline = true, standout = true, }, - meths.get_hl_by_name('cursorline', 0)); + eq({ underline = true, standout = true }, meths.get_hl_by_name('cursorline', 0)) -- Test cterm & Normal values. #18024 (tail) & #18980 -- Ensure Normal, and groups that match Normal return their fg & bg cterm values - meths.set_hl(0, 'Normal', {ctermfg = 17, ctermbg = 213}) - meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213, nocombine = true}) + meths.set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) + meths.set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'Normal', false)) - eq({foreground = 17, background = 213, nocombine = true}, nvim("get_hl_by_name", 'NotNormal', false)) + eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) + eq( + { foreground = 17, background = 213, nocombine = true }, + nvim('get_hl_by_name', 'NotNormal', false) + ) end) 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(0, funcs.hlID("Shrubbery")) + 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") + local hl_id = meths.get_hl_id_by_name('Shrubbery') ok(hl_id > 0) - eq(hl_id, funcs.hlID("Shrubbery")) + eq(hl_id, funcs.hlID('Shrubbery')) command('hi Shrubbery guifg=#888888 guibg=#888888') - eq({foreground=tonumber("0x888888"), background=tonumber("0x888888")}, - meths.get_hl_by_id(hl_id, true)) - eq({foreground=tonumber("0x888888"), background=tonumber("0x888888")}, - meths.get_hl_by_name("Shrubbery", true)) + eq( + { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, + meths.get_hl_by_id(hl_id, true) + ) + eq( + { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, + meths.get_hl_by_name('Shrubbery', true) + ) end) it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() @@ -165,7 +176,7 @@ describe('API: highlight',function() end) end) -describe("API: set highlight", function() +describe('API: set highlight', function() local highlight_color = { fg = tonumber('0xff0000'), bg = tonumber('0x0032aa'), @@ -207,7 +218,7 @@ describe("API: set highlight", function() strikethrough = true, altfont = true, nocombine = true, - } + }, } local highlight3_result_gui = { background = highlight_color.bg, @@ -238,31 +249,35 @@ describe("API: set highlight", function() before_each(clear) 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={}})) + 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() + 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({ @@ -271,14 +286,14 @@ 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("only allows one underline attribute #22371", function() + it('only allows one underline attribute #22371', function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { underdouble = true, @@ -292,80 +307,76 @@ describe("API: set highlight", function() eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) end) - it("can set a highlight in the global namespace", function() + 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')) + eq( + 'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', + exec_capture('highlight Test_hl') + ) meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) - eq('Test_hl xxx guibg=#0032aa', - exec_capture('highlight Test_hl')) + eq('Test_hl xxx guibg=#0032aa', 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,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', - exec_capture('highlight Test_hl2')) + 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 -- with canonical casing - meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue'}) - eq('Test_hl3 xxx guifg=Blue guibg=Red', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) - 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')) + 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')) meths.set_hl(0, 'Test_hl3', { bg = 'red' }) - eq('Test_hl3 xxx guibg=Red', - exec_capture('highlight Test_hl3')) + eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12}) - eq('Test_hl3 xxx ctermfg=12 ctermbg=9', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 'red' , ctermfg = 'blue'}) - eq('Test_hl3 xxx ctermfg=12 ctermbg=9', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) - eq('Test_hl3 xxx ctermbg=9', - exec_capture('highlight Test_hl3')) + eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: 'redd'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'})) + eq("Invalid highlight color: 'redd'", pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = 'redd' })) - eq("Invalid highlight color: 'bleu'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'})) + 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')) + meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) + eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: '#FF00FF'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'})) + 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 - meths.set_hl(0, 'Test_hl3', {fg = fg_val}) - eq('Test_hl3 xxx cleared', - exec_capture('highlight Test_hl3')) + for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do + meths.set_hl(0, 'Test_hl3', { fg = fg_val }) + eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) end - meths.set_hl(0, 'Test_hl3', {fg='#FF00FF', blend=50}) - eq('Test_hl3 xxx guifg=#ff00ff blend=50', - exec_capture('highlight Test_hl3')) - + meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) + eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) 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)) + 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) @@ -380,14 +391,16 @@ describe('API: get highlight', function() local highlight1 = { bg = highlight_color.bg, fg = highlight_color.fg, - bold = true, italic = true, - cterm = {bold = true, italic = true}, + 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}, + underline = true, + reverse = true, + cterm = { underline = true, reverse = true }, } local highlight3_config = { bg = highlight_color.bg, @@ -413,8 +426,19 @@ describe('API: get highlight', function() 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} + 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() @@ -434,17 +458,16 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - eq("Invalid 'name': expected String, got Integer", - pcall_err(meths.get_hl, 0, { name = 177 })) + 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({}, nvim('get_hl', 0, { name = 'Foo', create = false })) eq(0, funcs.hlexists('Foo')) - meths.get_hl(0, {name = 'Bar', create = true}) + meths.get_hl(0, { name = 'Bar', create = true }) eq(1, funcs.hlexists('Bar')) - meths.get_hl(0, {name = 'FooBar'}) + meths.get_hl(0, { name = 'FooBar' }) eq(1, funcs.hlexists('FooBar')) end) @@ -454,11 +477,11 @@ describe('API: get highlight', function() meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) eq({ Test_hl = { - bg = 11845374 + bg = 11845374, }, Test_hl_link = { - link = 'Test_hl' - } + link = 'Test_hl', + }, }, meths.get_hl(ns, {})) end) @@ -502,8 +525,7 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ underdotted = true, cterm = { undercurl = true} }, - meths.get_hl(ns, { name = 'Test_hl' })) + eq({ underdotted = true, cterm = { undercurl = true } }, meths.get_hl(ns, { name = 'Test_hl' })) end) it('can get a highlight in the global namespace', function() @@ -533,8 +555,13 @@ describe('API: get highlight', function() 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 }, + eq({ + fg = 16711680, + bg = 16776960, + sp = 255, + bold = true, + ctermbg = 10, + cterm = { underline = true }, }, meths.get_hl(0, { id = hl_id })) -- Test 0 argument @@ -547,16 +574,30 @@ describe('API: get highlight', function() -- 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}, + 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}, + eq({ + fg = 16711680, + bg = 16776960, + sp = 255, + undercurl = true, + ctermbg = 10, + cterm = { underline = true }, }, meths.get_hl(0, { id = hl_id })) end) @@ -573,7 +614,10 @@ describe('API: get highlight', 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 })) + 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() @@ -584,57 +628,57 @@ describe('API: get highlight', function() end) it("doesn't contain unset groups", function() - local id = meths.get_hl_id_by_name "@foobar.hubbabubba" + 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"]) + 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"]) + 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"]) + eq({}, data['@foobar.hubbabubba']) + eq(nil, data['@foobar']) end) it('should return default flag', function() - meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) + 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, '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}}) + 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')) + 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'})) + 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) @@ -647,9 +691,9 @@ describe('API: set/get highlight namespace', function() end) it('set/get window highlight namespace', function() - eq(-1, meths.get_hl_ns({winid = 0})) + 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})) + 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 434f117956..50c353d764 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -39,21 +39,21 @@ describe('nvim_get_keymap', function() -- Basic mapping and table to be used to describe results local foo_bar_string = 'nnoremap foo bar' local foo_bar_map_table = { - lhs='foo', - lhsraw='foo', - script=0, - silent=0, - rhs='bar', - expr=0, - sid=0, - scriptversion=1, - buffer=0, - nowait=0, - mode='n', - mode_bits=0x01, - abbr=0, - noremap=1, - lnum=0, + lhs = 'foo', + lhsraw = 'foo', + script = 0, + silent = 0, + rhs = 'bar', + expr = 0, + sid = 0, + scriptversion = 1, + buffer = 0, + nowait = 0, + mode = 'n', + mode_bits = 0x01, + abbr = 0, + noremap = 1, + lnum = 0, } it('returns empty list when no map', function() @@ -66,10 +66,8 @@ describe('nvim_get_keymap', function() -- Should be the same as the dictionary we supplied earlier -- and the dictionary you would get from maparg -- since this is a global map, and not script local - eq({foo_bar_map_table}, meths.get_keymap('n')) - eq({funcs.maparg('foo', 'n', false, true)}, - meths.get_keymap('n') - ) + eq({ foo_bar_map_table }, meths.get_keymap('n')) + eq({ funcs.maparg('foo', 'n', false, true) }, meths.get_keymap('n')) -- Add another mapping command('nnoremap foo_longer bar_longer') @@ -78,15 +76,11 @@ describe('nvim_get_keymap', function() foolong_bar_map_table['lhsraw'] = 'foo_longer' foolong_bar_map_table['rhs'] = 'bar_longer' - eq({foolong_bar_map_table, foo_bar_map_table}, - meths.get_keymap('n') - ) + eq({ foolong_bar_map_table, foo_bar_map_table }, meths.get_keymap('n')) -- Remove a mapping command('unmap foo_longer') - eq({foo_bar_map_table}, - meths.get_keymap('n') - ) + eq({ foo_bar_map_table }, meths.get_keymap('n')) end) it('works for other modes', function() @@ -100,7 +94,7 @@ describe('nvim_get_keymap', function() insert_table['mode'] = 'i' insert_table['mode_bits'] = 0x10 - eq({insert_table}, meths.get_keymap('i')) + eq({ insert_table }, meths.get_keymap('i')) end) it('considers scope', function() @@ -117,8 +111,8 @@ describe('nvim_get_keymap', function() command('nnoremap foo bar') -- The buffer mapping should not show up - eq({foolong_bar_map_table}, meths.get_keymap('n')) - eq({buffer_table}, curbufmeths.get_keymap('n')) + eq({ foolong_bar_map_table }, meths.get_keymap('n')) + eq({ buffer_table }, curbufmeths.get_keymap('n')) end) it('considers scope for overlapping maps', function() @@ -129,8 +123,8 @@ describe('nvim_get_keymap', function() command('nnoremap foo bar') - eq({foo_bar_map_table}, meths.get_keymap('n')) - eq({buffer_table}, curbufmeths.get_keymap('n')) + eq({ foo_bar_map_table }, meths.get_keymap('n')) + eq({ buffer_table }, curbufmeths.get_keymap('n')) end) it('can retrieve mapping for different buffers', function() @@ -149,81 +143,118 @@ describe('nvim_get_keymap', function() -- Final buffer will have buffer mappings local buffer_table = shallowcopy(foo_bar_map_table) buffer_table['buffer'] = final_buffer - eq({buffer_table}, meths.buf_get_keymap(final_buffer, 'n')) - eq({buffer_table}, meths.buf_get_keymap(0, 'n')) + eq({ buffer_table }, meths.buf_get_keymap(final_buffer, 'n')) + eq({ buffer_table }, meths.buf_get_keymap(0, 'n')) command('buffer ' .. original_buffer) eq(original_buffer, curbufmeths.get_number()) -- Original buffer won't have any mappings eq({}, meths.get_keymap('n')) eq({}, curbufmeths.get_keymap('n')) - eq({buffer_table}, meths.buf_get_keymap(final_buffer, 'n')) + eq({ buffer_table }, meths.buf_get_keymap(final_buffer, 'n')) end) -- Test toggle switches for basic options -- @param option The key represented in the `maparg()` result dict - local function global_and_buffer_test(map, - option, - option_token, - global_on_result, - buffer_on_result, - global_off_result, - buffer_off_result, - new_windows) - + local function global_and_buffer_test( + map, + option, + option_token, + global_on_result, + buffer_on_result, + global_off_result, + buffer_off_result, + new_windows + ) local function make_new_windows(number_of_windows) if new_windows == nil then return nil end - for _=1,number_of_windows do + for _ = 1, number_of_windows do command('new') end end - local mode = string.sub(map, 1,1) + local mode = string.sub(map, 1, 1) -- Don't run this for the mapping, since it doesn't make sense if option_token ~= '' then - it(string.format( 'returns %d for the key "%s" when %s is used globally with %s (%s)', - global_on_result, option, option_token, map, mode), function() - make_new_windows(new_windows) - command(map .. ' ' .. option_token .. ' foo bar') - local result = meths.get_keymap(mode)[1][option] - eq(global_on_result, result) - end) + it( + string.format( + 'returns %d for the key "%s" when %s is used globally with %s (%s)', + global_on_result, + option, + option_token, + map, + mode + ), + function() + make_new_windows(new_windows) + command(map .. ' ' .. option_token .. ' foo bar') + local result = meths.get_keymap(mode)[1][option] + eq(global_on_result, result) + end + ) end - it(string.format('returns %d for the key "%s" when %s is used for buffers with %s (%s)', - buffer_on_result, option, option_token, map, mode), function() - make_new_windows(new_windows) - command(map .. ' ' .. option_token .. ' foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] - eq(buffer_on_result, result) - end) + it( + string.format( + 'returns %d for the key "%s" when %s is used for buffers with %s (%s)', + buffer_on_result, + option, + option_token, + map, + mode + ), + function() + make_new_windows(new_windows) + command(map .. ' ' .. option_token .. ' foo bar') + local result = curbufmeths.get_keymap(mode)[1][option] + eq(buffer_on_result, result) + end + ) -- Don't run these for the mapping, since it doesn't make sense if option_token ~= '' then - it(string.format('returns %d for the key "%s" when %s is not used globally with %s (%s)', - global_off_result, option, option_token, map, mode), function() - make_new_windows(new_windows) - command(map .. ' baz bat') - local result = meths.get_keymap(mode)[1][option] - eq(global_off_result, result) - end) + it( + string.format( + 'returns %d for the key "%s" when %s is not used globally with %s (%s)', + global_off_result, + option, + option_token, + map, + mode + ), + function() + make_new_windows(new_windows) + command(map .. ' baz bat') + local result = meths.get_keymap(mode)[1][option] + eq(global_off_result, result) + end + ) - it(string.format('returns %d for the key "%s" when %s is not used for buffers with %s (%s)', - buffer_off_result, option, option_token, map, mode), function() - make_new_windows(new_windows) - command(map .. ' foo bar') + it( + string.format( + 'returns %d for the key "%s" when %s is not used for buffers with %s (%s)', + buffer_off_result, + option, + option_token, + map, + mode + ), + function() + make_new_windows(new_windows) + command(map .. ' foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] - eq(buffer_off_result, result) - end) + local result = curbufmeths.get_keymap(mode)[1][option] + eq(buffer_off_result, result) + end + ) end end -- Standard modes and returns the same values in the dictionary as maparg() - local mode_list = {'nnoremap', 'nmap', 'imap', 'inoremap', 'cnoremap'} + local mode_list = { 'nnoremap', 'nmap', 'imap', 'inoremap', 'cnoremap' } for mode in pairs(mode_list) do global_and_buffer_test(mode_list[mode], 'silent', '', 1, 1, 0, 0) global_and_buffer_test(mode_list[mode], 'nowait', '', 1, 1, 0, 0) @@ -272,16 +303,16 @@ describe('nvim_get_keymap', function() it('works correctly despite various &cpo settings', function() local cpo_table = { - script=0, - silent=0, - expr=0, - sid=0, - scriptversion=1, - buffer=0, - nowait=0, - abbr=0, - noremap=1, - lnum=0, + script = 0, + silent = 0, + expr = 0, + sid = 0, + scriptversion = 1, + buffer = 0, + nowait = 0, + abbr = 0, + noremap = 1, + lnum = 0, } local function cpomap(lhs, rhs, mode) local ret = shallowcopy(cpo_table) @@ -323,57 +354,67 @@ describe('nvim_get_keymap', function() 'set cpo+=B', }) do command(cmd) - eq({cpomap('\\C-c>\\', '\\C-d>\\', 'n'), - cpomap('\\C-a>\\', '\\C-b>\\', 'n')}, - get_keymap_noraw('n')) - eq({cpomap('\\C-c>\\', '\\C-d>\\', 'x'), - cpomap('\\C-a>\\', '\\C-b>\\', 'x')}, - get_keymap_noraw('x')) - eq({cpomap('C-c>C-c> ', 'C-d>C-d>', 's'), - cpomap('C-a>C-a> ', 'C-b>C-b>', 's')}, - get_keymap_noraw('s')) - eq({cpomap('C-c>C-c> ', 'C-d>C-d>', 'o'), - cpomap('C-a>C-a> ', 'C-b>C-b>', 'o')}, - get_keymap_noraw('o')) + eq({ + cpomap('\\C-c>\\', '\\C-d>\\', 'n'), + cpomap('\\C-a>\\', '\\C-b>\\', 'n'), + }, get_keymap_noraw('n')) + eq({ + cpomap('\\C-c>\\', '\\C-d>\\', 'x'), + cpomap('\\C-a>\\', '\\C-b>\\', 'x'), + }, get_keymap_noraw('x')) + eq({ + cpomap('C-c>C-c> ', 'C-d>C-d>', 's'), + cpomap('C-a>C-a> ', 'C-b>C-b>', 's'), + }, get_keymap_noraw('s')) + eq({ + cpomap('C-c>C-c> ', 'C-d>C-d>', 'o'), + cpomap('C-a>C-a> ', 'C-b>C-b>', 'o'), + }, get_keymap_noraw('o')) end end) it('always uses space for space and bar for bar', function() local space_table = { - lhs='| |', - 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, - lnum=0, + lhs = '| |', + 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, + lnum = 0, } command('nnoremap \\| \\| ') - eq({space_table}, meths.get_keymap('n')) + eq({ space_table }, meths.get_keymap('n')) end) it('can handle lua mappings', function() - eq(0, exec_lua([[ + eq( + 0, + exec_lua([[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]])) + ]]) + ) feed('asdf\n') eq(1, exec_lua([[return GlobalCount]])) - eq(2, exec_lua([[ + eq( + 2, + exec_lua([[ vim.api.nvim_get_keymap('n')[1].callback() return GlobalCount - ]])) + ]]) + ) exec([[ call nvim_get_keymap('n')[0].callback() @@ -383,42 +424,42 @@ describe('nvim_get_keymap', function() local mapargs = meths.get_keymap('n') mapargs[1].callback = nil eq({ - lhs='asdf', - lhsraw='asdf', - script=0, - silent=0, - expr=0, - sid=sid_lua, - scriptversion=1, - buffer=0, - nowait=0, - mode='n', - mode_bits=0x01, - abbr=0, - noremap=0, - lnum=0, + lhs = 'asdf', + lhsraw = 'asdf', + script = 0, + 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() - meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) + meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq({ - lhs='lhs', - lhsraw='lhs', - rhs='rhs', - script=0, - 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' + lhs = 'lhs', + lhsraw = 'lhs', + rhs = 'rhs', + script = 0, + 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', }, meths.get_keymap('n')[1]) end) end) @@ -490,8 +531,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- assume MAXMAPLEN of 50 chars, as declared in mapping_defs.h local MAXMAPLEN = 50 local lhs = '' - for i=1,MAXMAPLEN do - lhs = lhs..(i % 10) + for i = 1, MAXMAPLEN do + lhs = lhs .. (i % 10) end -- exactly 50 chars should be fine @@ -502,23 +543,20 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq({}, get_mapargs('', lhs)) -- 51 chars should produce an error - lhs = lhs..'1' - eq('LHS exceeds maximum map length: '..lhs, - pcall_err(meths.set_keymap, '', lhs, 'rhs', {})) - eq('LHS exceeds maximum map length: '..lhs, - pcall_err(meths.del_keymap, '', lhs)) + lhs = lhs .. '1' + eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(meths.set_keymap, '', lhs, 'rhs', {})) + eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(meths.del_keymap, '', lhs)) end) it('does not throw errors when rhs is longer than MAXMAPLEN', function() local MAXMAPLEN = 50 local rhs = '' - for i=1,MAXMAPLEN do - rhs = rhs..(i % 10) + for i = 1, MAXMAPLEN do + rhs = rhs .. (i % 10) end - rhs = rhs..'1' + rhs = rhs .. '1' meths.set_keymap('', 'lhs', rhs, {}) - eq(generate_mapargs('', 'lhs', rhs), - get_mapargs('', 'lhs')) + eq(generate_mapargs('', 'lhs', rhs), get_mapargs('', 'lhs')) end) it('error on invalid mode shortname', function() @@ -534,7 +572,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function() 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: "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')) @@ -551,32 +592,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('error on invalid optnames', function() - eq("Invalid key: 'silentt'", - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true})) - eq("Invalid key: 'sidd'", - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false})) - eq("Invalid key: 'nowaiT'", - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false})) + eq("Invalid key: 'silentt'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { silentt = true })) + eq("Invalid key: 'sidd'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { sidd = false })) + eq("Invalid key: 'nowaiT'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { nowaiT = false })) end) it('error on option key', function() - eq("Invalid key: 'buffer'", - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true})) + eq("Invalid key: 'buffer'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { buffer = true })) end) it('error when "replace_keycodes" is used without "expr"', function() - eq('"replace_keycodes" requires "expr"', - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {replace_keycodes = true})) + eq( + '"replace_keycodes" requires "expr"', + pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { replace_keycodes = true }) + ) end) - local optnames = {'nowait', 'silent', 'script', 'expr', 'unique'} + local optnames = { 'nowait', 'silent', 'script', 'expr', 'unique' } for _, opt in ipairs(optnames) do -- note: need '%' to escape hyphens, which have special meaning in lua - it('throws an error when given non-boolean value for '..opt, function() + it('throws an error when given non-boolean value for ' .. opt, function() local opts = {} opts[opt] = 'fooo' - eq(opt..' is not a boolean', - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts)) + eq(opt .. ' is not a boolean', pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts)) end) end @@ -591,26 +629,21 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('does not throw when LHS or RHS have leading/trailing whitespace', function() meths.set_keymap('n', ' lhs', 'rhs', {}) - eq(generate_mapargs('n', 'lhs', 'rhs'), - get_mapargs('n', ' lhs')) + eq(generate_mapargs('n', 'lhs', 'rhs'), get_mapargs('n', ' lhs')) meths.set_keymap('n', 'lhs ', 'rhs', {}) - eq(generate_mapargs('n', 'lhs', 'rhs'), - get_mapargs('n', 'lhs ')) + eq(generate_mapargs('n', 'lhs', 'rhs'), get_mapargs('n', 'lhs ')) meths.set_keymap('v', ' lhs ', '\trhs\t\f', {}) - eq(generate_mapargs('v', 'lhs', '\trhs\t\f'), - get_mapargs('v', ' lhs ')) + eq(generate_mapargs('v', 'lhs', '\trhs\t\f'), get_mapargs('v', ' lhs ')) end) it('can set noremap mappings', function() - meths.set_keymap('x', 'lhs', 'rhs', {noremap = true}) - eq(generate_mapargs('x', 'lhs', 'rhs', {noremap = true}), - get_mapargs('x', 'lhs')) + meths.set_keymap('x', 'lhs', 'rhs', { noremap = true }) + eq(generate_mapargs('x', 'lhs', 'rhs', { noremap = true }), get_mapargs('x', 'lhs')) - meths.set_keymap('t', 'lhs', 'rhs', {noremap = true}) - eq(generate_mapargs('t', 'lhs', 'rhs', {noremap = true}), - get_mapargs('t', 'lhs')) + meths.set_keymap('t', 'lhs', 'rhs', { noremap = true }) + eq(generate_mapargs('t', 'lhs', 'rhs', { noremap = true }), get_mapargs('t', 'lhs')) end) it('can unmap mappings', function() @@ -618,14 +651,14 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.del_keymap('v', 'lhs') eq({}, get_mapargs('v', 'lhs')) - meths.set_keymap('t', 'lhs', 'rhs', {noremap = true}) + meths.set_keymap('t', 'lhs', 'rhs', { noremap = true }) meths.del_keymap('t', 'lhs') eq({}, get_mapargs('t', 'lhs')) end) -- Test some edge cases it('"!" and empty string are synonyms for mapmode-nvo', function() - local nvo_shortnames = {'', '!'} + local nvo_shortnames = { '', '!' } for _, name in ipairs(nvo_shortnames) do meths.set_keymap(name, 'lhs', 'rhs', {}) meths.del_keymap(name, 'lhs') @@ -633,12 +666,11 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end end) - local special_chars = {'', '', '', ''} + local special_chars = { '', '', '', '' } for _, lhs in ipairs(special_chars) do for _, rhs in ipairs(special_chars) do local mapmode = '!' - it('can set mappings with special characters, lhs: '..lhs..', rhs: '..rhs, - function() + it('can set mappings with special characters, lhs: ' .. lhs .. ', rhs: ' .. rhs, function() meths.set_keymap(mapmode, lhs, rhs, {}) eq(generate_mapargs(mapmode, lhs, rhs), get_mapargs(mapmode, lhs)) end) @@ -654,39 +686,34 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can set mappings whose RHS is a ', function() meths.set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({''}, curbufmeths.get_lines(0, -1, 0)) -- imap to does nothing - eq(generate_mapargs('i', 'lhs', '', {}), - get_mapargs('i', 'lhs')) + eq({ '' }, curbufmeths.get_lines(0, -1, 0)) -- imap to does nothing + eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) -- also test for case insensitivity meths.set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({''}, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, curbufmeths.get_lines(0, -1, 0)) -- note: RHS in returned mapargs() dict reflects the original RHS -- provided by the user - eq(generate_mapargs('i', 'lhs', '', {}), - get_mapargs('i', 'lhs')) + eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) meths.set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({''}, curbufmeths.get_lines(0, -1, 0)) - eq(generate_mapargs('i', 'lhs', '', {}), - get_mapargs('i', 'lhs')) + eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) -- a single ^V in RHS is also (see :h map-empty-rhs) meths.set_keymap('i', 'lhs', '\022', {}) command('normal ilhs') - eq({''}, curbufmeths.get_lines(0, -1, 0)) - eq(generate_mapargs('i', 'lhs', '\022', {}), - get_mapargs('i', 'lhs')) + eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs')) end) it('treats an empty RHS in a mapping like a ', function() meths.set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({''}, curbufmeths.get_lines(0, -1, 0)) - eq(generate_mapargs('i', 'lhs', '', {}), - get_mapargs('i', 'lhs')) + eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) end) it('can set and unset ', function() @@ -698,21 +725,24 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq({}, get_mapargs('i', '')) end) - it('interprets control sequences in expr-quotes correctly when called ' - ..'inside vim', function() - command([[call nvim_set_keymap('i', "\", "\", {})]]) - eq(generate_mapargs('i', '', '\t', {sid=0}), - get_mapargs('i', '')) - feed('i ') - eq({'\t'}, curbufmeths.get_lines(0, -1, 0)) - end) + it( + 'interprets control sequences in expr-quotes correctly when called ' .. 'inside vim', + function() + command([[call nvim_set_keymap('i', "\", "\", {})]]) + eq(generate_mapargs('i', '', '\t', { sid = 0 }), get_mapargs('i', '')) + feed('i ') + eq({ '\t' }, curbufmeths.get_lines(0, -1, 0)) + end + ) it('throws appropriate error messages when setting maps', function() meths.set_keymap('l', 'lhs', 'rhs', {}) - eq('E227: mapping already exists for lhs', - pcall_err(meths.set_keymap, 'l', 'lhs', 'rhs', {unique = true})) + eq( + 'E227: mapping already exists for lhs', + pcall_err(meths.set_keymap, 'l', 'lhs', 'rhs', { unique = true }) + ) -- different mapmode, no error should be thrown - meths.set_keymap('t', 'lhs', 'rhs', {unique = true}) + meths.set_keymap('t', 'lhs', 'rhs', { unique = true }) end) it('can set mappings whose RHS change dynamically', function() @@ -728,14 +758,14 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq(1, meths.call_function('FlipFlop', {})) eq(0, meths.call_function('FlipFlop', {})) - meths.set_keymap('i', 'lhs', 'FlipFlop()', {expr = true}) + meths.set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) command('normal ilhs') - eq({'1'}, curbufmeths.get_lines(0, -1, 0)) + eq({ '1' }, curbufmeths.get_lines(0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({'0'}, curbufmeths.get_lines(0, -1, 0)) + eq({ '0' }, curbufmeths.get_lines(0, -1, 0)) end) it('can set mappings that do trigger other mappings', function() @@ -743,30 +773,30 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.set_keymap('i', 'lhs', 'mhs', {}) command('normal imhs') - eq({'rhs'}, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({'rhs'}, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) end) it("can set noremap mappings that don't trigger other mappings", function() meths.set_keymap('i', 'mhs', 'rhs', {}) - meths.set_keymap('i', 'lhs', 'mhs', {noremap = true}) + meths.set_keymap('i', 'lhs', 'mhs', { noremap = true }) command('normal imhs') - eq({'rhs'}, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) command('normal! ggVGd') - command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping - eq({'mhs'}, curbufmeths.get_lines(0, -1, 0)) + command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping + eq({ 'mhs' }, curbufmeths.get_lines(0, -1, 0)) end) - it("can set nowait mappings that fire without waiting", function() - meths.set_keymap('i', '123456', 'longer', {}) - meths.set_keymap('i', '123', 'shorter', {nowait = true}) + it('can set nowait mappings that fire without waiting', function() + meths.set_keymap('i', '123456', 'longer', {}) + meths.set_keymap('i', '123', 'shorter', { nowait = true }) -- feed keys one at a time; if all keys arrive atomically, the longer -- mapping will trigger @@ -775,16 +805,15 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed(c) sleep(5) end - eq({'shorter456'}, curbufmeths.get_lines(0, -1, 0)) + eq({ 'shorter456' }, curbufmeths.get_lines(0, -1, 0)) end) -- Perform exhaustive tests of basic functionality - local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a'} + 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() + it('can set/unset normal mappings in mapmode ' .. mapmode, function() meths.set_keymap(mapmode, 'lhs', 'rhs', {}) - eq(generate_mapargs(mapmode, 'lhs', 'rhs'), - get_mapargs(mapmode, 'lhs')) + eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs')) -- some mapmodes (like 'o') will prevent other mapmodes (like '!') from -- taking effect, so unmap after each mapping @@ -794,10 +823,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end for _, mapmode in ipairs(mapmodes) do - it('can set/unset noremap mappings using mapmode '..mapmode, function() - meths.set_keymap(mapmode, 'lhs', 'rhs', {noremap = true}) - eq(generate_mapargs(mapmode, 'lhs', 'rhs', {noremap = true}), - get_mapargs(mapmode, 'lhs')) + it('can set/unset noremap mappings using mapmode ' .. mapmode, function() + meths.set_keymap(mapmode, 'lhs', 'rhs', { noremap = true }) + eq(generate_mapargs(mapmode, 'lhs', 'rhs', { noremap = true }), get_mapargs(mapmode, 'lhs')) meths.del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) @@ -806,53 +834,70 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Test map-arguments, using optnames from above -- remove some map arguments that are harder to test, or were already tested - optnames = {'nowait', 'silent', 'expr', 'noremap'} + optnames = { 'nowait', 'silent', 'expr', 'noremap' } for _, mapmode in ipairs(mapmodes) do -- Test with single mappings for _, maparg in ipairs(optnames) do - 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}), - get_mapargs(mapmode, 'lhs')) - meths.del_keymap(mapmode, 'lhs') - eq({}, get_mapargs(mapmode, 'lhs')) - end) - 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'), - get_mapargs(mapmode, 'lhs')) + 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 }), + get_mapargs(mapmode, 'lhs') + ) meths.del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end) + 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'), get_mapargs(mapmode, 'lhs')) + meths.del_keymap(mapmode, 'lhs') + eq({}, get_mapargs(mapmode, 'lhs')) + end + ) end -- 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 '..mapmode..'-mode mappings with mapargs '.. - opt1..', '..opt2..', '..opt3, function() - local opts = {[opt1] = true, [opt2] = false, [opt3] = true} - meths.set_keymap(mapmode, 'lhs', 'rhs', opts) - eq(generate_mapargs(mapmode, 'lhs', 'rhs', opts), - get_mapargs(mapmode, 'lhs')) - meths.del_keymap(mapmode, 'lhs') - eq({}, get_mapargs(mapmode, 'lhs')) - end) + 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) + eq(generate_mapargs(mapmode, 'lhs', 'rhs', opts), get_mapargs(mapmode, 'lhs')) + meths.del_keymap(mapmode, 'lhs') + eq({}, get_mapargs(mapmode, 'lhs')) + end + ) end end it('can make lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) end) it(':map command shows lua mapping correctly', function() @@ -861,8 +906,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ]] assert.truthy( string.match( - exec_lua[[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]], - "^\nn asdf " + exec_lua [[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]], + '^\nn asdf ' ) ) end) @@ -871,29 +916,34 @@ describe('nvim_set_keymap, nvim_del_keymap', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] - assert.truthy(string.match(funcs.mapcheck('asdf', 'n'), - "^")) + assert.truthy(string.match(funcs.mapcheck('asdf', 'n'), '^')) end) it('maparg() returns lua mapping correctly', function() - eq(0, exec_lua([[ + eq( + 0, + exec_lua([[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]])) + ]]) + ) - assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^")) + assert.truthy(string.match(funcs.maparg('asdf', 'n'), '^')) local mapargs = funcs.maparg('asdf', 'n', false, true) mapargs.callback = nil mapargs.lhsraw = nil mapargs.lhsrawalt = nil - eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs) + eq(generate_mapargs('n', 'asdf', nil, { sid = sid_lua }), mapargs) - eq(1, exec_lua([[ + eq( + 1, + exec_lua([[ vim.fn.maparg('asdf', 'n', false, true).callback() return GlobalCount - ]])) + ]]) + ) exec([[ call maparg('asdf', 'n', v:false, v:true).callback() @@ -908,7 +958,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('aa') - eq({'πfoo<'}, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'πfoo<' }, meths.buf_get_lines(0, 0, -1, false)) end) it('can make lua expr mappings without replacing keycodes', function() @@ -918,7 +968,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('iaa') - eq({''}, meths.buf_get_lines(0, 0, -1, false)) + eq({ '' }, meths.buf_get_lines(0, 0, -1, false)) end) it('lua expr mapping returning nil is equivalent to returning an empty string', function() @@ -928,41 +978,50 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('iaa') - eq({''}, meths.buf_get_lines(0, 0, -1, false)) + eq({ '' }, meths.buf_get_lines(0, 0, -1, false)) end) it('does not reset pum in lua mapping', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ VisibleCount = 0 vim.api.nvim_set_keymap('i', '', '', {callback = function() VisibleCount = VisibleCount + vim.fn.pumvisible() end}) return VisibleCount - ]]) + ]] + ) feed('i') - eq(2, exec_lua[[return VisibleCount]]) + eq(2, exec_lua [[return VisibleCount]]) end) it('redo of lua mappings in op-pending mode work', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ OpCount = 0 vim.api.nvim_set_keymap('o', '', '', {callback = function() OpCount = OpCount + 1 end}) return OpCount - ]]) + ]] + ) feed('d') - eq(1, exec_lua[[return OpCount]]) + eq(1, exec_lua [[return OpCount]]) feed('.') - eq(2, exec_lua[[return OpCount]]) + eq(2, exec_lua [[return OpCount]]) end) it('can overwrite lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) @@ -970,19 +1029,22 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('asdf\n') - eq(0, exec_lua[[return GlobalCount]]) + eq(0, exec_lua [[return GlobalCount]]) end) it('can unmap lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_del_keymap('n', 'asdf' ) @@ -990,20 +1052,23 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) it('no double-free when unmapping simplifiable lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_set_keymap('n', '', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_del_keymap('n', '') @@ -1011,15 +1076,14 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap ')) end) it('can set descriptions on mappings', function() - meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) - eq(generate_mapargs('n', 'lhs', 'rhs', {desc="map description"}), get_mapargs('n', 'lhs')) - eq("\nn lhs rhs\n map description", - helpers.exec_capture("nmap lhs")) + meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + eq(generate_mapargs('n', 'lhs', 'rhs', { desc = 'map description' }), get_mapargs('n', 'lhs')) + eq('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs')) end) it('can define !-mode abbreviations with lua callbacks', function() @@ -1035,7 +1099,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('The 1 and the bar and the 2 again', meths.get_current_line()) feed ':let x = "The foo is the one"' - eq('The 3 is the one', meths.eval'x') + eq('The 3 is the one', meths.eval 'x') end) it('can define insert mode abbreviations with lua callbacks', function() @@ -1051,7 +1115,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('The 1 and the bar and the 2 again', meths.get_current_line()) feed ':let x = "The foo is the one"' - eq('The foo is the one', meths.eval'x') + eq('The foo is the one', meths.eval 'x') end) it('can define cmdline mode abbreviations with lua callbacks', function() @@ -1067,7 +1131,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('The foo and the bar and the foo again', meths.get_current_line()) feed ':let x = "The foo is the one"' - eq('The 1 is the one', meths.eval'x') + eq('The 1 is the one', meths.eval 'x') end) end) @@ -1081,7 +1145,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() -- switch to the given buffer, abandoning any changes in the current buffer local function switch_to_buf(bufnr) - command(bufnr..'buffer!') + command(bufnr .. 'buffer!') end -- `set hidden`, then create two buffers and return their bufnr's @@ -1090,10 +1154,10 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() local function make_two_buffers(start_from_first) command('set hidden') - local first_buf = meths.call_function('bufnr', {'%'}) + local first_buf = meths.call_function('bufnr', { '%' }) command('new') - local second_buf = meths.call_function('bufnr', {'%'}) - neq(second_buf, first_buf) -- sanity check + local second_buf = meths.call_function('bufnr', { '%' }) + neq(second_buf, first_buf) -- sanity check if start_from_first then switch_to_buf(first_buf) @@ -1103,8 +1167,10 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() end it('rejects negative bufnr values', function() - eq('Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', - pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {})) + eq( + 'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', + pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}) + ) end) it('can set mappings active in the current buffer but not others', function() @@ -1112,17 +1178,17 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() bufmeths.set_keymap(0, '', 'lhs', 'irhs', {}) command('normal lhs') - eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) -- mapping should have no effect in new buffer switch_to_buf(second) command('normal lhs') - eq({''}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) -- mapping should remain active in old buffer switch_to_buf(first) command('normal ^lhs') - eq({'rhsrhs'}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhsrhs' }, bufmeths.get_lines(0, 0, 1, 1)) end) it('can set local mappings in buffer other than current', function() @@ -1131,12 +1197,12 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() -- shouldn't do anything command('normal lhs') - eq({''}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) -- should take effect switch_to_buf(first) command('normal lhs') - eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) end) it('can disable mappings made in another buffer, inside that buffer', function() @@ -1147,36 +1213,38 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() -- shouldn't do anything command('normal lhs') - eq({''}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) end) it("can't disable mappings given wrong buffer handle", function() local first, second = make_two_buffers(false) bufmeths.set_keymap(first, '', 'lhs', 'irhs', {}) - eq('E31: No such mapping', - pcall_err(bufmeths.del_keymap, second, '', 'lhs')) + eq('E31: No such mapping', pcall_err(bufmeths.del_keymap, second, '', 'lhs')) -- should still work switch_to_buf(first) command('normal lhs') - eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) end) - it("does not crash when setting mapping in a non-existing buffer #13541", function() + it('does not crash when setting mapping in a non-existing buffer #13541', function() pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs', {}) helpers.assert_alive() end) it('can make lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) end) it('can make lua expr mappings replacing keycodes', function() @@ -1186,7 +1254,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('aa') - eq({'πfoo<'}, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'πfoo<' }, meths.buf_get_lines(0, 0, -1, false)) end) it('can make lua expr mappings without replacing keycodes', function() @@ -1196,20 +1264,22 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('iaa') - eq({''}, meths.buf_get_lines(0, 0, -1, false)) + eq({ '' }, meths.buf_get_lines(0, 0, -1, false)) end) - it('can overwrite lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) @@ -1217,19 +1287,22 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('asdf\n') - eq(0, exec_lua[[return GlobalCount]]) + eq(0, exec_lua [[return GlobalCount]]) end) it('can unmap lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_buf_del_keymap(0, 'n', 'asdf' ) @@ -1237,20 +1310,23 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) it('no double-free when unmapping simplifiable lua mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.api.nvim_buf_set_keymap(0, 'n', '', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]] + ) feed('\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.api.nvim_buf_del_keymap(0, 'n', '') @@ -1258,7 +1334,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap ')) end) end) diff --git a/test/functional/api/menu_spec.lua b/test/functional/api/menu_spec.lua index 34a92477f3..44b9039393 100644 --- a/test/functional/api/menu_spec.lua +++ b/test/functional/api/menu_spec.lua @@ -5,8 +5,7 @@ local clear = helpers.clear local command = helpers.command local feed = helpers.feed -describe("update_menu notification", function() - +describe('update_menu notification', function() local screen before_each(function() @@ -16,23 +15,26 @@ describe("update_menu notification", function() end) local function expect_sent(expected) - screen:expect{condition=function() - if screen.update_menu ~= expected then - if expected then - error('update_menu was expected but not sent') - else - error('update_menu was sent unexpectedly') + screen:expect { + condition = function() + if screen.update_menu ~= expected then + if expected then + error('update_menu was expected but not sent') + else + error('update_menu was sent unexpectedly') + end end - end - end, unchanged=(not expected)} + end, + unchanged = not expected, + } end - it("should be sent when adding a menu", function() + it('should be sent when adding a menu', function() command('menu Test.Test :') expect_sent(true) end) - it("should be sent when deleting a menu", function() + it('should be sent when deleting a menu', function() command('menu Test.Test :') screen.update_menu = false @@ -40,9 +42,8 @@ describe("update_menu notification", function() expect_sent(true) end) - it("should not be sent unnecessarily", function() + it('should not be sent unnecessarily', function() feed('i12345:redraw') expect_sent(false) end) - end) diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 20edea3feb..4f99a69ce6 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -43,16 +43,16 @@ describe('API', function() end) it('validation', function() - local status, rv = pcall(request, "nvim_get_proc_children", -1) + 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) + 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) + status, rv = pcall(request, 'nvim_get_proc_children', 99999) eq(true, status) eq({}, rv) end) @@ -69,16 +69,16 @@ describe('API', function() end) it('validation', function() - local status, rv = pcall(request, "nvim_get_proc", -1) + 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) + 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) + status, rv = pcall(request, 'nvim_get_proc', 99999) eq(true, status) eq(NIL, rv) end) diff --git a/test/functional/api/rpc_fixture.lua b/test/functional/api/rpc_fixture.lua index c860a6da59..050d439a1b 100644 --- a/test/functional/api/rpc_fixture.lua +++ b/test/functional/api/rpc_fixture.lua @@ -4,8 +4,8 @@ package.path = arg[1] package.cpath = arg[2] -local StdioStream = require'test.client.uv_stream'.StdioStream -local Session = require'test.client.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) @@ -15,8 +15,8 @@ local function on_request(method, args) return 'ok' elseif method == 'write_stderr' then io.stderr:write(args[1]) - return "done!" - elseif method == "exit" then + return 'done!' + elseif method == 'exit' then session:stop() return vim.NIL end @@ -24,7 +24,7 @@ end local function on_notification(event, args) if event == 'ping' and #args == 0 then - session:notify("nvim_eval", "rpcnotify(g:channel, 'pong')") + session:notify('nvim_eval', "rpcnotify(g:channel, 'pong')") end end diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index bc43f6564d..d75bfd5324 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -1,8 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log local eq, clear, eval, command, nvim, next_msg = - helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, - helpers.next_msg + helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_msg local meths = helpers.meths local exec_lua = helpers.exec_lua local retry = helpers.retry @@ -24,11 +23,11 @@ describe('notify', function() describe('passing a valid channel id', function() it('sends the notification/args to the corresponding channel', function() - eval('rpcnotify('..channel..', "test-event", 1, 2, 3)') - eq({'notification', 'test-event', {1, 2, 3}}, next_msg()) - command('au FileType lua call rpcnotify('..channel..', "lua!")') + eval('rpcnotify(' .. channel .. ', "test-event", 1, 2, 3)') + eq({ 'notification', 'test-event', { 1, 2, 3 } }, next_msg()) + command('au FileType lua call rpcnotify(' .. channel .. ', "lua!")') command('set filetype=lua') - eq({'notification', 'lua!', {}}, next_msg()) + eq({ 'notification', 'lua!', {} }, next_msg()) end) end) @@ -38,20 +37,20 @@ describe('notify', function() eval('rpcnotify(0, "event1", 1, 2, 3)') eval('rpcnotify(0, "event2", 4, 5, 6)') eval('rpcnotify(0, "event2", 7, 8, 9)') - eq({'notification', 'event2', {4, 5, 6}}, next_msg()) - eq({'notification', 'event2', {7, 8, 9}}, next_msg()) + eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg()) + eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg()) nvim('unsubscribe', 'event2') nvim('subscribe', 'event1') eval('rpcnotify(0, "event2", 10, 11, 12)') eval('rpcnotify(0, "event1", 13, 14, 15)') - eq({'notification', 'event1', {13, 14, 15}}, next_msg()) + eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg()) end) it('does not crash for deeply nested variable', function() meths.set_var('l', {}) local nest_level = 1000 meths.command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)) - eval('rpcnotify('..channel..', "event", g:l)') + eval('rpcnotify(' .. channel .. ', "event", g:l)') local msg = next_msg() eq('notification', msg[1]) eq('event', msg[2]) @@ -77,9 +76,9 @@ describe('notify', function() end) it('unsubscribe non-existing event #8745', function() - clear{env={ - NVIM_LOG_FILE=testlog, - }} + clear { env = { + NVIM_LOG_FILE = testlog, + } } nvim('subscribe', 'event1') nvim('unsubscribe', 'doesnotexist') assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10) @@ -90,14 +89,24 @@ describe('notify', function() it('cancels stale events on channel close', function() 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 ([[ + eq( + { id = catchan, argv = { catpath }, stream = 'job', mode = 'rpc', client = {} }, + exec_lua( + [[ vim.rpcnotify(..., "nvim_call_function", 'chanclose', {..., 'rpc'}) vim.rpcnotify(..., "nvim_subscribe", "daily_rant") return vim.api.nvim_get_chan_info(...) - ]], catchan)) + ]], + catchan + ) + ) assert_alive() - eq({false, 'Invalid channel: '..catchan}, - exec_lua ([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan)) - retry(nil, 3000, function() eq({}, meths.get_chan_info(catchan)) end) -- cat be dead :( + eq( + { false, 'Invalid channel: ' .. catchan }, + exec_lua([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan) + ) + retry(nil, 3000, function() + eq({}, meths.get_chan_info(catchan)) + end) -- cat be dead :( end) end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 1ad4ad3a02..421e0b5c9a 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -40,13 +40,13 @@ describe('server -> client', function() describe('simple call', function() it('works', function() local function on_setup() - eq({4, 5, 6}, eval('rpcrequest('..cid..', "scall", 1, 2, 3)')) + eq({ 4, 5, 6 }, eval('rpcrequest(' .. cid .. ', "scall", 1, 2, 3)')) stop() end local function on_request(method, args) eq('scall', method) - eq({1, 2, 3}, args) + eq({ 1, 2, 3 }, args) nvim('command', 'let g:result = [4, 5, 6]') return eval('g:result') end @@ -61,14 +61,14 @@ describe('server -> client', function() -- elements following the empty string. it('works', function() local function on_setup() - eq({1, 2, '', 3, 'asdf'}, eval('rpcrequest('..cid..', "nstring")')) + eq({ 1, 2, '', 3, 'asdf' }, eval('rpcrequest(' .. cid .. ', "nstring")')) stop() end local function on_request() -- No need to evaluate the args, we are only interested in -- a response that contains an array with an empty string. - return {1, 2, '', 3, 'asdf'} + return { 1, 2, '', 3, 'asdf' } end run(on_request, nil, on_setup) end) @@ -81,7 +81,7 @@ describe('server -> client', function() nvim('set_var', 'result2', 0) nvim('set_var', 'result3', 0) nvim('set_var', 'result4', 0) - nvim('command', 'let g:result1 = rpcrequest('..cid..', "rcall", 2)') + nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') eq(4, nvim('get_var', 'result1')) eq(8, nvim('get_var', 'result2')) eq(16, nvim('get_var', 'result3')) @@ -95,11 +95,11 @@ describe('server -> client', function() if n <= 16 then local cmd if n == 4 then - cmd = 'let g:result2 = rpcrequest('..cid..', "rcall", '..n..')' + cmd = 'let g:result2 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' elseif n == 8 then - cmd = 'let g:result3 = rpcrequest('..cid..', "rcall", '..n..')' + cmd = 'let g:result3 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' elseif n == 16 then - cmd = 'let g:result4 = rpcrequest('..cid..', "rcall", '..n..')' + cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' end nvim('command', cmd) end @@ -113,18 +113,18 @@ describe('server -> client', function() it('does not delay notifications during pending request', function() local received = false local function on_setup() - eq("retval", funcs.rpcrequest(cid, "doit")) + eq('retval', funcs.rpcrequest(cid, 'doit')) stop() end local function on_request(method) - if method == "doit" then - funcs.rpcnotify(cid, "headsup") - eq(true,received) - return "retval" + if method == 'doit' then + funcs.rpcnotify(cid, 'headsup') + eq(true, received) + return 'retval' end end local function on_notification(method) - if method == "headsup" then + if method == 'headsup' then received = true end end @@ -148,28 +148,28 @@ describe('server -> client', function() -- of nvim's request stack). pending('will close connection if not properly synchronized', function() local function on_setup() - eq('notified!', eval('rpcrequest('..cid..', "notify")')) + eq('notified!', eval('rpcrequest(' .. cid .. ', "notify")')) end local function on_request(method) - if method == "notify" then - eq(1, eval('rpcnotify('..cid..', "notification")')) + if method == 'notify' then + eq(1, eval('rpcnotify(' .. cid .. ', "notification")')) return 'notified!' - elseif method == "nested" then + elseif method == 'nested' then -- do some busywork, so the first request will return -- before this one for _ = 1, 5 do assert_alive() end - eq(1, eval('rpcnotify('..cid..', "nested_done")')) + eq(1, eval('rpcnotify(' .. cid .. ', "nested_done")')) return 'done!' end end local function on_notification(method) - if method == "notification" then - eq('done!', eval('rpcrequest('..cid..', "nested")')) - elseif method == "nested_done" then + if method == 'notification' then + eq('done!', eval('rpcrequest(' .. cid .. ', "nested")')) + elseif method == 'nested_done' then ok(false, 'never sent', 'sent') end end @@ -182,11 +182,17 @@ describe('server -> client', function() describe('recursive (child) nvim client', function() before_each(function() - command("let vim = rpcstart('"..nvim_prog.."', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed', '--headless'])") + command( + "let vim = rpcstart('" + .. nvim_prog + .. "', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed', '--headless'])" + ) neq(0, eval('vim')) end) - after_each(function() command('call rpcstop(vim)') end) + after_each(function() + command('call rpcstop(vim)') + end) it('can send/receive notifications and make requests', function() nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") @@ -198,25 +204,27 @@ describe('server -> client', function() end) it('can communicate buffers, tabpages, and windows', function() - eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')")) + eq({ 1 }, eval("rpcrequest(vim, 'nvim_list_tabpages')")) -- Window IDs start at 1000 (LOWEST_WIN_ID in window.h) - eq({1000}, eval("rpcrequest(vim, 'nvim_list_wins')")) + eq({ 1000 }, eval("rpcrequest(vim, 'nvim_list_wins')")) local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1] eq(1, buf) - eval("rpcnotify(vim, 'buffer_set_line', "..buf..", 0, 'SOME TEXT')") - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") + nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait - eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)")) + eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) -- Call get_lines(buf, range [0,0], strict_indexing) - eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_lines', "..buf..", 0, 1, 1)")) + eq({ 'SOME TEXT' }, eval("rpcrequest(vim, 'buffer_get_lines', " .. buf .. ', 0, 1, 1)')) end) it('returns an error if the request failed', function() - eq("Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist", - pcall_err(eval, "rpcrequest(vim, 'does-not-exist')")) + eq( + "Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist", + pcall_err(eval, "rpcrequest(vim, 'does-not-exist')") + ) end) end) @@ -236,13 +244,14 @@ describe('server -> client', function() \ 'rpc': v:true \ } ]]) - meths.set_var("args", { - nvim_prog, '-ll', + meths.set_var('args', { + nvim_prog, + '-ll', 'test/functional/api/rpc_fixture.lua', package.path, package.cpath, }) - jobid = eval("jobstart(g:args, g:job_opts)") + jobid = eval('jobstart(g:args, g:job_opts)') neq(0, jobid) end) @@ -250,7 +259,9 @@ describe('server -> client', function() pcall(funcs.jobstop, jobid) end) - if helpers.skip(helpers.is_os('win')) then return end + if helpers.skip(helpers.is_os('win')) then + return + end it('rpc and text stderr can be combined', function() local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') @@ -258,18 +269,18 @@ describe('server -> client', function() error(string.format('missing nvim Lua module? (%s)', rv)) end eq('ok', rv) - funcs.rpcnotify(jobid, "ping") - eq({'notification', 'pong', {}}, next_msg()) - eq("done!",funcs.rpcrequest(jobid, "write_stderr", "fluff\n")) - eq({'notification', 'stderr', {0, {'fluff', ''}}}, next_msg()) - pcall(funcs.rpcrequest, jobid, "exit") - eq({'notification', 'stderr', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 0}}, next_msg()) + funcs.rpcnotify(jobid, 'ping') + eq({ 'notification', 'pong', {} }, next_msg()) + eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n')) + eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg()) + pcall(funcs.rpcrequest, jobid, 'exit') + eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) end) describe('connecting to another (peer) nvim', function() - local nvim_argv = merge_args(helpers.nvim_argv, {'--headless'}) + local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) local serverpid = funcs.getpid() local client = spawn(nvim_argv, false, nil, true) @@ -277,7 +288,7 @@ describe('server -> client', function() local clientpid = funcs.getpid() neq(serverpid, clientpid) - local id = funcs.sockconnect(mode, address, {rpc=true}) + local id = funcs.sockconnect(mode, address, { rpc = true }) ok(id > 0) funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') @@ -303,7 +314,7 @@ describe('server -> client', function() local server = spawn(nvim_argv) set_session(server) local address = funcs.serverlist()[1] - local first = string.sub(address,1,1) + local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') connect_test(server, 'pipe', address) end) @@ -311,11 +322,11 @@ describe('server -> client', function() it('via ipv4 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, "127.0.0.1:") + local status, address = pcall(funcs.serverstart, '127.0.0.1:') if not status then pending('no ipv4 stack') end - eq('127.0.0.1:', string.sub(address,1,10)) + eq('127.0.0.1:', string.sub(address, 1, 10)) connect_test(server, 'tcp', address) end) @@ -326,15 +337,15 @@ describe('server -> client', function() if not status then pending('no ipv6 stack') end - eq('::1:', string.sub(address,1,4)) + eq('::1:', string.sub(address, 1, 4)) connect_test(server, 'tcp', address) end) it('via hostname', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverstart("localhost:") - eq('localhost:', string.sub(address,1,10)) + local address = funcs.serverstart('localhost:') + eq('localhost:', string.sub(address, 1, 10)) connect_test(server, 'tcp', address) end) @@ -345,7 +356,7 @@ describe('server -> client', function() local client = spawn(nvim_argv, false, nil, true) set_session(client) - local id = funcs.sockconnect('pipe', address, {rpc=true}) + local id = funcs.sockconnect('pipe', address, { rpc = true }) funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) assert_alive() @@ -357,15 +368,15 @@ describe('server -> client', function() describe('connecting to its own pipe address', function() it('does not deadlock', function() local address = funcs.serverlist()[1] - local first = string.sub(address,1,1) + local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') local serverpid = funcs.getpid() - local id = funcs.sockconnect('pipe', address, {rpc=true}) + local id = funcs.sockconnect('pipe', address, { rpc = true }) funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') eq('hello', meths.get_current_line()) - eq(serverpid, funcs.rpcrequest(id, "nvim_eval", "getpid()")) + eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) end) diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index 20b3163d95..d6fc041e83 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, nvim, tabpage, curtab, eq, ok = - helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, - helpers.ok + helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok local curtabmeths = helpers.curtabmeths local funcs = helpers.funcs local request = helpers.request @@ -18,8 +17,8 @@ describe('api/tabpage', function() nvim('command', 'vsplit') local tab1, tab2 = unpack(nvim('list_tabpages')) local win1, win2, win3 = unpack(nvim('list_wins')) - eq({win1}, tabpage('list_wins', tab1)) - eq({win2, win3}, tabpage('list_wins', tab2)) + eq({ win1 }, tabpage('list_wins', tab1)) + eq({ win2, win3 }, tabpage('list_wins', tab2)) eq(win2, tabpage('get_win', tab2)) nvim('set_current_win', win3) eq(win3, tabpage('get_win', tab2)) @@ -32,9 +31,9 @@ describe('api/tabpage', function() describe('{get,set,del}_var', function() it('works', function() - curtab('set_var', 'lua', {1, 2, {['3'] = 1}}) - eq({1, 2, {['3'] = 1}}, curtab('get_var', 'lua')) - eq({1, 2, {['3'] = 1}}, nvim('eval', 't:lua')) + curtab('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, curtab('get_var', 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 't:lua')) eq(1, funcs.exists('t:lua')) curtabmeths.del_var('lua') eq(0, funcs.exists('t:lua')) @@ -46,16 +45,16 @@ describe('api/tabpage', function() end) it('tabpage_set_var returns the old value', function() - local val1 = {1, 2, {['3'] = 1}} - local val2 = {4, 7} + local val1 = { 1, 2, { ['3'] = 1 } } + local val2 = { 4, 7 } eq(NIL, request('tabpage_set_var', 0, 'lua', val1)) eq(val1, request('tabpage_set_var', 0, 'lua', val2)) end) it('tabpage_del_var returns the old value', function() - local val1 = {1, 2, {['3'] = 1}} - local val2 = {4, 7} - eq(NIL, request('tabpage_set_var', 0, 'lua', val1)) + local val1 = { 1, 2, { ['3'] = 1 } } + local val2 = { 4, 7 } + eq(NIL, request('tabpage_set_var', 0, 'lua', val1)) eq(val1, request('tabpage_set_var', 0, 'lua', val2)) eq(val2, request('tabpage_del_var', 0, 'lua')) end) diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index 6efb6726fe..dafbbe550f 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -23,42 +23,56 @@ describe('nvim_ui_attach()', function() end) it('validation', function() - eq('No such UI option: foo', - pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} })) + eq('No such UI option: foo', pcall_err(meths.ui_attach, 80, 24, { foo = { 'foo' } })) - 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( + "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', - pcall_err(request, 'nvim_ui_set_option', 'rgb', true)) - eq('UI not attached to channel: 1', - pcall_err(request, 'nvim_ui_detach')) + eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10)) + eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_set_option', 'rgb', true)) + eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_detach')) local screen = Screen.new() - screen:attach({rgb=false}) - eq('UI already attached to channel: 1', - pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false })) + screen:attach({ rgb = false }) + eq( + 'UI already attached to channel: 1', + pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb = false }) + ) end) end) it('autocmds UIEnter/UILeave', function() - clear{args_rm={'--headless'}} + clear { args_rm = { '--headless' } } exec([[ let g:evs = [] autocmd UIEnter * call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event) @@ -67,9 +81,9 @@ it('autocmds UIEnter/UILeave', function() ]]) local screen = Screen.new() screen:attach() - eq({chan=1}, eval('g:uienter_ev')) + eq({ chan = 1 }, eval('g:uienter_ev')) screen:detach() - eq({chan=1}, eval('g:uileave_ev')) + eq({ chan = 1 }, eval('g:uileave_ev')) eq({ 'VimEnter', 'UIEnter', @@ -89,21 +103,27 @@ it('autocmds VimSuspend/VimResume #22041', function() eq(false, screen.suspended) feed('') - screen:expect(function() eq(true, screen.suspended) end) + screen:expect(function() + eq(true, screen.suspended) + end) eq({ 's' }, eval('g:ev')) screen.suspended = false feed('') eq({ 's', 'r' }, eval('g:ev')) command('suspend') - screen:expect(function() eq(true, screen.suspended) end) + 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('') - screen:expect(function() eq(true, screen.suspended) end) + 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 @@ -111,7 +131,9 @@ it('autocmds VimSuspend/VimResume #22041', function() eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) command('suspend | suspend | suspend') - screen:expect(function() eq(true, screen.suspended) end) + screen:expect(function() + eq(true, screen.suspended) + end) screen:detach() eq({ 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) screen.suspended = false diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 6d466b0cc1..76cdb9cbca 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -19,41 +19,40 @@ end describe("api_info()['version']", function() before_each(clear) - it("returns API level", function() + it('returns API level', function() local version = call('api_info')['version'] local current = version['api_level'] - local compat = version['api_compatible'] - eq("number", type(current)) - eq("number", type(compat)) + local compat = version['api_compatible'] + eq('number', type(current)) + eq('number', type(compat)) assert(current >= compat) end) - it("returns Nvim version", function() + it('returns Nvim version', function() local version = call('api_info')['version'] - local major = version['major'] - local minor = version['minor'] - local patch = version['patch'] + local major = version['major'] + 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)) - eq("boolean", type(prerelease)) - eq(1, funcs.has("nvim-"..major.."."..minor.."."..patch)) - 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)) + local build = version['build'] + eq('number', type(major)) + eq('number', type(minor)) + eq('number', type(patch)) + eq('boolean', type(prerelease)) + eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) + 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) - -describe("api metadata", function() +describe('api metadata', function() before_each(clear) local function name_table(entries) local by_name = {} - for _,e in ipairs(entries) do + for _, e in ipairs(entries) do by_name[e.name] = e end return by_name @@ -63,10 +62,10 @@ describe("api metadata", function() local function filter_function_metadata(f) f.deprecated_since = nil for idx, _ in ipairs(f.parameters) do - f.parameters[idx][2] = '' -- Remove parameter name. + f.parameters[idx][2] = '' -- Remove parameter name. end - if string.sub(f.name, 1, 4) ~= "nvim" then + if string.sub(f.name, 1, 4) ~= 'nvim' then f.method = nil end return f @@ -76,7 +75,7 @@ describe("api metadata", function() -- check types of existing params are the same -- adding parameters is ok, but removing params is not (gives nil error) eq(old_e.since, new_e.since, old_e.name) - for i,p in ipairs(old_e.parameters) do + for i, p in ipairs(old_e.parameters) do eq(new_e.parameters[i][1], p[1], old_e.name) end end @@ -95,25 +94,27 @@ describe("api metadata", function() local api, compat, stable, api_level local old_api = {} setup(function() - clear() -- Ensure a session before requesting api_info. + clear() -- Ensure a session before requesting api_info. api = meths.get_api_info()[2] - compat = api.version.api_compatible + compat = api.version.api_compatible api_level = api.version.api_level if api.version.api_prerelease then - stable = api_level-1 + stable = api_level - 1 else stable = api_level end for level = compat, stable do - local path = ('test/functional/fixtures/api_level_'.. - tostring(level)..'.mpack') + local path = ('test/functional/fixtures/api_level_' .. tostring(level) .. '.mpack') old_api[level] = read_mpack_file(path) if old_api[level] == nil then - local errstr = "missing metadata fixture for stable level "..level..". " + local errstr = 'missing metadata fixture for stable level ' .. level .. '. ' if level == api_level and not api.version.api_prerelease then - errstr = (errstr.."If NVIM_API_CURRENT was bumped, ".. - "don't forget to set NVIM_API_PRERELEASE to true.") + errstr = ( + errstr + .. 'If NVIM_API_CURRENT was bumped, ' + .. "don't forget to set NVIM_API_PRERELEASE to true." + ) end error(errstr) end @@ -124,60 +125,76 @@ describe("api metadata", function() end end) - it("functions are compatible with old metadata or have new level", function() + it('functions are compatible with old metadata or have new level', function() local funcs_new = name_table(api.functions) local funcs_compat = {} for level = compat, stable do - for _,f in ipairs(old_api[level].functions) do + for _, f in ipairs(old_api[level].functions) do if funcs_new[f.name] == nil then if f.since >= compat then - error('function '..f.name..' was removed but exists in level '.. - f.since..' which nvim should be compatible with') + error( + 'function ' + .. f.name + .. ' was removed but exists in level ' + .. f.since + .. ' which nvim should be compatible with' + ) end else - eq(filter_function_metadata(f), - filter_function_metadata(funcs_new[f.name])) + eq(filter_function_metadata(f), filter_function_metadata(funcs_new[f.name])) end end funcs_compat[level] = name_table(old_api[level].functions) end - for _,f in ipairs(api.functions) do + for _, f in ipairs(api.functions) do if f.since <= stable then local f_old = funcs_compat[f.since][f.name] if f_old == nil then - if string.sub(f.name, 1, 4) == "nvim" then - local errstr = ("function "..f.name.." has too low since value. ".. - "For new functions set it to "..(stable+1)..".") + if string.sub(f.name, 1, 4) == 'nvim' then + local errstr = ( + 'function ' + .. f.name + .. ' has too low since value. ' + .. 'For new functions set it to ' + .. (stable + 1) + .. '.' + ) if not api.version.api_prerelease then - errstr = (errstr.." Also bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + errstr = ( + errstr + .. ' Also bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end error(errstr) else - error("function name '"..f.name.."' doesn't begin with 'nvim_'") + error("function name '" .. f.name .. "' doesn't begin with 'nvim_'") end end elseif f.since > api_level then if api.version.api_prerelease then - error("New function "..f.name.." should use since value ".. - api_level) + error('New function ' .. f.name .. ' should use since value ' .. api_level) else - error("function "..f.name.." has since value > api_level. ".. - "Bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + error( + 'function ' + .. f.name + .. ' has since value > api_level. ' + .. 'Bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end end end end) - it("UI events are compatible with old metadata or have new level", function() + it('UI events are compatible with old metadata or have new level', function() local ui_events_new = name_table(api.ui_events) local ui_events_compat = {} -- UI events were formalized in level 3 for level = 3, stable do - for _,e in ipairs(old_api[level].ui_events) do + for _, e in ipairs(old_api[level].ui_events) do local new_e = ui_events_new[e.name] if new_e ~= nil then check_ui_event_compatible(e, new_e) @@ -186,32 +203,44 @@ describe("api metadata", function() ui_events_compat[level] = name_table(old_api[level].ui_events) end - for _,e in ipairs(api.ui_events) do + for _, e in ipairs(api.ui_events) do if e.since <= stable then local e_old = ui_events_compat[e.since][e.name] if e_old == nil then - local errstr = ("UI event "..e.name.." has too low since value. ".. - "For new events set it to "..(stable+1)..".") + local errstr = ( + 'UI event ' + .. e.name + .. ' has too low since value. ' + .. 'For new events set it to ' + .. (stable + 1) + .. '.' + ) if not api.version.api_prerelease then - errstr = (errstr.." Also bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + errstr = ( + errstr + .. ' Also bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end error(errstr) end elseif e.since > api_level then if api.version.api_prerelease then - error("New UI event "..e.name.." should use since value ".. - api_level) + error('New UI event ' .. e.name .. ' should use since value ' .. api_level) else - error("UI event "..e.name.." has since value > api_level. ".. - "Bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + error( + 'UI event ' + .. e.name + .. ' has since value > api_level. ' + .. 'Bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end end end end) - it("ui_options are preserved from older levels", function() + it('ui_options are preserved from older levels', function() local available_options = {} for _, option in ipairs(api.ui_options) do available_options[option] = true @@ -220,7 +249,7 @@ describe("api metadata", function() for level = 4, stable do for _, option in ipairs(old_api[level].ui_options) do if not available_options[option] then - error("UI option "..option.." from stable metadata is missing") + error('UI option ' .. option .. ' from stable metadata is missing') end end end diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index f44326d0eb..7e92dd6bf3 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,9 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, - ok, feed, insert, eval, tabpage = helpers.clear, helpers.nvim, helpers.curbuf, - helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq, - helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval, +local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval, tabpage = + helpers.clear, + helpers.nvim, + helpers.curbuf, + helpers.curbuf_contents, + helpers.window, + helpers.curwin, + helpers.eq, + helpers.neq, + helpers.ok, + helpers.feed, + helpers.insert, + helpers.eval, helpers.tabpage local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths @@ -25,8 +34,7 @@ describe('API/win', function() nvim('command', 'new') nvim('set_current_win', nvim('list_wins')[2]) eq(curbuf(), window('get_buf', nvim('list_wins')[2])) - neq(window('get_buf', nvim('list_wins')[1]), - window('get_buf', nvim('list_wins')[2])) + neq(window('get_buf', nvim('list_wins')[1]), window('get_buf', nvim('list_wins')[2])) end) end) @@ -48,15 +56,25 @@ describe('API/win', 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, + relative = 'editor', + row = 10, + col = 10, + width = 50, + height = 10, }) feed('q:') - eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_set_buf, 0, new_buf)) - eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_set_buf, old_win, new_buf)) - eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_set_buf, new_win, 0)) + eq( + 'E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_set_buf, 0, new_buf) + ) + eq( + 'E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_set_buf, old_win, new_buf) + ) + eq( + 'E11: Invalid in command-line window; 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) @@ -66,63 +84,70 @@ describe('API/win', function() describe('{get,set}_cursor', function() it('works', function() - eq({1, 0}, curwin('get_cursor')) + eq({ 1, 0 }, curwin('get_cursor')) nvim('command', 'normal ityping\027o some text') eq('typing\n some text', curbuf_contents()) - eq({2, 10}, curwin('get_cursor')) - curwin('set_cursor', {2, 6}) + eq({ 2, 10 }, curwin('get_cursor')) + curwin('set_cursor', { 2, 6 }) nvim('command', 'normal i dumb') eq('typing\n some dumb text', curbuf_contents()) end) it('does not leak memory when using invalid window ID with invalid pos', function() - eq('Invalid window id: 1', pcall_err(meths.win_set_cursor, 1, {"b\na"})) + eq('Invalid window id: 1', pcall_err(meths.win_set_cursor, 1, { 'b\na' })) end) it('updates the screen, and also when the window is unfocused', function() local screen = Screen.new(30, 9) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, - [2] = {bold = true, reverse = true}; - [3] = {reverse = true}; + [1] = { bold = true, foreground = Screen.colors.Blue }, + [2] = { bold = true, reverse = true }, + [3] = { reverse = true }, }) screen:attach() - insert("prologue") + insert('prologue') feed('100o') - insert("epilogue") + insert('epilogue') local win = curwin() feed('gg') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^prologue | |*8 - ]]} + ]], + } -- cursor position is at beginning - eq({1, 0}, window('get_cursor', win)) + eq({ 1, 0 }, window('get_cursor', win)) -- move cursor to end - window('set_cursor', win, {101, 0}) - screen:expect{grid=[[ + window('set_cursor', win, { 101, 0 }) + screen:expect { + grid = [[ |*7 ^epilogue | | - ]]} + ]], + } -- move cursor to the beginning again - window('set_cursor', win, {1, 0}) - screen:expect{grid=[[ + window('set_cursor', win, { 1, 0 }) + screen:expect { + grid = [[ ^prologue | |*8 - ]]} + ]], + } -- move focus to new window - nvim('command',"new") + nvim('command', 'new') neq(win, curwin()) -- sanity check, cursor position is kept - eq({1, 0}, window('get_cursor', win)) - screen:expect{grid=[[ + eq({ 1, 0 }, window('get_cursor', win)) + screen:expect { + grid = [[ ^ | {1:~ }|*2 {2:[No Name] }| @@ -130,11 +155,13 @@ describe('API/win', function() |*2 {3:[No Name] [+] }| | - ]]} + ]], + } -- move cursor to end - window('set_cursor', win, {101, 0}) - screen:expect{grid=[[ + window('set_cursor', win, { 101, 0 }) + screen:expect { + grid = [[ ^ | {1:~ }|*2 {2:[No Name] }| @@ -142,11 +169,13 @@ describe('API/win', function() epilogue | {3:[No Name] [+] }| | - ]]} + ]], + } -- move cursor to the beginning again - window('set_cursor', win, {1, 0}) - screen:expect{grid=[[ + window('set_cursor', win, { 1, 0 }) + screen:expect { + grid = [[ ^ | {1:~ }|*2 {2:[No Name] }| @@ -154,42 +183,43 @@ describe('API/win', function() |*2 {3:[No Name] [+] }| | - ]]} + ]], + } -- curwin didn't change back neq(win, curwin()) end) it('remembers what column it wants to be in', function() - insert("first line") + insert('first line') feed('o') - insert("second line") + insert('second line') feed('gg') poke_eventloop() -- let nvim process the 'gg' command -- cursor position is at beginning local win = curwin() - eq({1, 0}, window('get_cursor', win)) + eq({ 1, 0 }, window('get_cursor', win)) -- move cursor to column 5 - window('set_cursor', win, {1, 5}) + window('set_cursor', win, { 1, 5 }) -- move down a line feed('j') poke_eventloop() -- let nvim process the 'j' command -- cursor is still in column 5 - eq({2, 5}, window('get_cursor', win)) + eq({ 2, 5 }, window('get_cursor', win)) end) it('updates cursorline and statusline ruler in non-current window', function() local screen = Screen.new(60, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [2] = {background = Screen.colors.Grey90}, -- CursorLine - [3] = {bold = true, reverse = true}, -- StatusLine - [4] = {reverse = true}, -- StatusLineNC + [1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [2] = { background = Screen.colors.Grey90 }, -- CursorLine + [3] = { bold = true, reverse = true }, -- StatusLine + [4] = { reverse = true }, -- StatusLineNC }) screen:attach() command('set ruler') @@ -210,7 +240,7 @@ describe('API/win', function() {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| | ]]) - window('set_cursor', oldwin, {1, 0}) + window('set_cursor', oldwin, { 1, 0 }) screen:expect([[ aaa │{2:aaa }| bbb │bbb | @@ -225,10 +255,10 @@ describe('API/win', function() it('updates cursorcolumn in non-current window', function() local screen = Screen.new(60, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [2] = {background = Screen.colors.Grey90}, -- CursorColumn - [3] = {bold = true, reverse = true}, -- StatusLine - [4] = {reverse = true}, -- StatusLineNC + [1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [2] = { background = Screen.colors.Grey90 }, -- CursorColumn + [3] = { bold = true, reverse = true }, -- StatusLine + [4] = { reverse = true }, -- StatusLineNC }) screen:attach() command('set cursorcolumn') @@ -248,7 +278,7 @@ describe('API/win', function() {3:[No Name] [+] }{4:[No Name] [+] }| | ]]) - window('set_cursor', oldwin, {2, 0}) + window('set_cursor', oldwin, { 2, 0 }) screen:expect([[ aa{2:a} │{2:a}aa | bb{2:b} │bbb | @@ -264,12 +294,13 @@ describe('API/win', function() describe('{get,set}_height', function() it('works', function() nvim('command', 'vsplit') - eq(window('get_height', nvim('list_wins')[2]), - window('get_height', nvim('list_wins')[1])) + eq(window('get_height', nvim('list_wins')[2]), window('get_height', nvim('list_wins')[1])) nvim('set_current_win', nvim('list_wins')[2]) nvim('command', 'split') - eq(window('get_height', nvim('list_wins')[2]), - math.floor(window('get_height', nvim('list_wins')[1]) / 2)) + eq( + window('get_height', nvim('list_wins')[2]), + math.floor(window('get_height', nvim('list_wins')[1]) / 2) + ) window('set_height', nvim('list_wins')[2], 2) eq(2, window('get_height', nvim('list_wins')[2])) end) @@ -310,12 +341,13 @@ describe('API/win', function() describe('{get,set}_width', function() it('works', function() nvim('command', 'split') - eq(window('get_width', nvim('list_wins')[2]), - window('get_width', nvim('list_wins')[1])) + eq(window('get_width', nvim('list_wins')[2]), window('get_width', nvim('list_wins')[1])) nvim('set_current_win', nvim('list_wins')[2]) nvim('command', 'vsplit') - eq(window('get_width', nvim('list_wins')[2]), - math.floor(window('get_width', nvim('list_wins')[1]) / 2)) + eq( + window('get_width', nvim('list_wins')[2]), + math.floor(window('get_width', nvim('list_wins')[1]) / 2) + ) window('set_width', nvim('list_wins')[2], 2) eq(2, window('get_width', nvim('list_wins')[2])) end) @@ -339,9 +371,9 @@ describe('API/win', function() describe('{get,set,del}_var', function() it('works', function() - curwin('set_var', 'lua', {1, 2, {['3'] = 1}}) - eq({1, 2, {['3'] = 1}}, curwin('get_var', 'lua')) - eq({1, 2, {['3'] = 1}}, nvim('eval', 'w:lua')) + curwin('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, curwin('get_var', 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'w:lua')) eq(1, funcs.exists('w:lua')) curwinmeths.del_var('lua') eq(0, funcs.exists('w:lua')) @@ -353,16 +385,16 @@ describe('API/win', function() end) it('window_set_var returns the old value', function() - local val1 = {1, 2, {['3'] = 1}} - local val2 = {4, 7} + local val1 = { 1, 2, { ['3'] = 1 } } + local val2 = { 4, 7 } eq(NIL, request('window_set_var', 0, 'lua', val1)) eq(val1, request('window_set_var', 0, 'lua', val2)) end) it('window_del_var returns the old value', function() - local val1 = {1, 2, {['3'] = 1}} - local val2 = {4, 7} - eq(NIL, request('window_set_var', 0, 'lua', val1)) + local val1 = { 1, 2, { ['3'] = 1 } } + local val2 = { 4, 7 } + eq(NIL, request('window_set_var', 0, 'lua', val1)) eq(val1, request('window_set_var', 0, 'lua', val2)) eq(val2, request('window_del_var', 0, 'lua')) end) @@ -372,18 +404,18 @@ describe('API/win', function() it('works', function() 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 + command('set modified hidden') + command('enew') -- edit new buffer, window option is preserved eq('4,3', nvim('get_option_value', 'colorcolumn', {})) -- global-local option - 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 + 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('', nvim('get_option_value', 'statusline', {win = 0})) + eq('', nvim('get_option_value', 'statusline', { win = 0 })) eq('', eval('&l:statusline')) end) @@ -391,16 +423,16 @@ describe('API/win', function() nvim('command', 'tabnew') local tab1 = unpack(nvim('list_tabpages')) local win1 = unpack(tabpage('list_wins', tab1)) - nvim('set_option_value', 'statusline', 'window-status', {win=win1.id}) + nvim('set_option_value', 'statusline', 'window-status', { win = win1.id }) nvim('command', 'split') nvim('command', 'wincmd J') nvim('command', 'wincmd j') - eq('window-status', nvim('get_option_value', 'statusline', {win = win1.id})) + eq('window-status', nvim('get_option_value', 'statusline', { win = win1.id })) assert_alive() end) it('returns values for unset local options', function() - eq(-1, nvim('get_option_value', 'scrolloff', {win=0, scope='local'})) + eq(-1, nvim('get_option_value', 'scrolloff', { win = 0, scope = 'local' })) end) end) @@ -410,13 +442,11 @@ describe('API/win', function() local width = window('get_width', nvim('list_wins')[1]) nvim('command', 'split') nvim('command', 'vsplit') - eq({0, 0}, window('get_position', nvim('list_wins')[1])) + eq({ 0, 0 }, window('get_position', nvim('list_wins')[1])) local vsplit_pos = math.floor(width / 2) local split_pos = math.floor(height / 2) - local win2row, win2col = - unpack(window('get_position', nvim('list_wins')[2])) - local win3row, win3col = - unpack(window('get_position', nvim('list_wins')[3])) + local win2row, win2col = unpack(window('get_position', nvim('list_wins')[2])) + local win3row, win3col = unpack(window('get_position', nvim('list_wins')[3])) eq(0, win2row) eq(0, win3col) ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1) @@ -428,12 +458,9 @@ describe('API/win', function() it('works', function() nvim('command', 'tabnew') nvim('command', 'vsplit') - eq(window('get_tabpage', - nvim('list_wins')[1]), nvim('list_tabpages')[1]) - eq(window('get_tabpage', - nvim('list_wins')[2]), nvim('list_tabpages')[2]) - eq(window('get_tabpage', - nvim('list_wins')[3]), nvim('list_tabpages')[2]) + eq(window('get_tabpage', nvim('list_wins')[1]), nvim('list_tabpages')[1]) + eq(window('get_tabpage', nvim('list_wins')[2]), nvim('list_tabpages')[2]) + eq(window('get_tabpage', nvim('list_wins')[3]), nvim('list_tabpages')[2]) end) end) @@ -477,16 +504,16 @@ describe('API/win', function() local oldwin = meths.get_current_win() command('split') local newwin = meths.get_current_win() - meths.win_close(newwin,false) - eq({oldwin}, meths.list_wins()) + meths.win_close(newwin, false) + eq({ oldwin }, meths.list_wins()) end) it('can close noncurrent window', function() local oldwin = meths.get_current_win() command('split') local newwin = meths.get_current_win() - meths.win_close(oldwin,false) - eq({newwin}, meths.list_wins()) + meths.win_close(oldwin, false) + eq({ newwin }, meths.list_wins()) end) it("handles changed buffer when 'hidden' is unset", function() @@ -495,9 +522,11 @@ describe('API/win', function() insert('text') command('new') local newwin = meths.get_current_win() - eq("Vim:E37: No write since last change (add ! to override)", - pcall_err(meths.win_close, oldwin,false)) - eq({newwin,oldwin}, meths.list_wins()) + eq( + 'Vim:E37: No write since last change (add ! to override)', + pcall_err(meths.win_close, oldwin, false) + ) + eq({ newwin, oldwin }, meths.list_wins()) end) it('handles changed buffer with force', function() @@ -505,8 +534,8 @@ describe('API/win', function() insert('text') command('new') local newwin = meths.get_current_win() - meths.win_close(oldwin,true) - eq({newwin}, meths.list_wins()) + meths.win_close(oldwin, true) + eq({ newwin }, meths.list_wins()) end) it('in cmdline-window #9767', function() @@ -514,15 +543,21 @@ describe('API/win', function() 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, + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, }) -- Open cmdline-window. feed('q:') eq(4, #meths.list_wins()) eq(':', funcs.getcmdwintype()) -- Not allowed to close previous window from cmdline-window. - eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_close, oldwin, true)) + eq( + 'E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_close, oldwin, true) + ) -- Closing other windows is fine. meths.win_close(otherwin, true) eq(false, meths.win_is_valid(otherwin)) @@ -538,7 +573,11 @@ describe('API/win', function() local prevwin = curwin().id eq(2, eval('tabpagenr()')) local win = meths.open_win(0, true, { - relative='editor', row=10, col=10, width=50, height=10 + relative = 'editor', + row = 10, + col = 10, + width = 50, + height = 10, }) local tab = eval('tabpagenr()') command('tabprevious') @@ -556,37 +595,45 @@ describe('API/win', function() command('split') local newwin = meths.get_current_win() meths.win_hide(newwin) - eq({oldwin}, meths.list_wins()) + eq({ oldwin }, meths.list_wins()) end) it('can hide noncurrent window', function() local oldwin = meths.get_current_win() command('split') local newwin = meths.get_current_win() meths.win_hide(oldwin) - eq({newwin}, meths.list_wins()) + eq({ newwin }, meths.list_wins()) end) it('does not close the buffer', function() local oldwin = meths.get_current_win() local oldbuf = meths.get_current_buf() local buf = meths.create_buf(true, false) local newwin = meths.open_win(buf, true, { - relative='win', row=3, col=3, width=12, height=3 + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, }) meths.win_hide(newwin) - eq({oldwin}, meths.list_wins()) - eq({oldbuf, buf}, meths.list_bufs()) + eq({ oldwin }, meths.list_wins()) + eq({ oldbuf, buf }, meths.list_bufs()) end) 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).id local newwin = meths.open_win(buf, true, { - relative='win', row=3, col=3, width=12, height=3 + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, }) - meths.set_option_value('bufhidden', 'wipe', {buf=buf}) + meths.set_option_value('bufhidden', 'wipe', { buf = buf }) meths.win_hide(newwin) - eq({oldwin}, meths.list_wins()) - eq({oldbuf}, meths.list_bufs()) + eq({ oldwin }, meths.list_wins()) + eq({ oldbuf }, meths.list_bufs()) end) it('in the cmdwin', function() feed('q:') @@ -596,12 +643,18 @@ describe('API/win', function() 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 + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, }) feed('q:') -- Cannot close the previous window. - eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_hide, old_win)) + eq( + 'E11: Invalid in command-line window; 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)) @@ -617,48 +670,66 @@ describe('API/win', function() 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 })) + 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}; + [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([[ @@ -670,7 +741,8 @@ describe('API/win', function() windo diffthis ]]) feed('24gg') - screen:expect{grid=[[ + 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!!! | @@ -693,13 +765,16 @@ describe('API/win', function() {1: }{2: 41 }{4:00000050!!!!!!!!}│{1: }{2: }{3:----------------}| {8:[No Name] [+] }{9:[No Name] [+] }| | - ]]} + ]], + } screen:try_resize(45, 3) - screen:expect{grid=[[ + 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 })) @@ -724,27 +799,51 @@ describe('API/win', function() 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 = 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 = 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 = 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 })) + 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}; + [0] = { foreground = Screen.colors.Blue1, bold = true }, + [1] = { foreground = Screen.colors.Brown }, + [2] = { background = Screen.colors.Yellow }, }) screen:attach() exec([[ @@ -752,9 +851,22 @@ describe('API/win', function() 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=[[ + 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| @@ -777,48 +889,123 @@ describe('API/win', function() {2:!!!!!!!!!}ar-foobar-foobar-foobar-foobar-fooba| r-foobar-foobar- | | - ]]} + ]], + } screen:try_resize(45, 2) - screen:expect{grid=[[ + 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 = 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 = 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 })) + 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) @@ -826,11 +1013,20 @@ describe('API/win', function() it('noautocmd option works', function() command('autocmd BufEnter,BufLeave,BufWinEnter * let g:fired = 1') meths.open_win(meths.create_buf(true, true), true, { - relative='win', row=3, col=3, width=12, height=3, noautocmd=true + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, + noautocmd = true, }) eq(0, funcs.exists('g:fired')) meths.open_win(meths.create_buf(true, true), true, { - relative='win', row=3, col=3, width=12, height=3 + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, }) eq(1, funcs.exists('g:fired')) end) @@ -838,25 +1034,51 @@ describe('API/win', function() 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; 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; executes, CTRL-C quits', - pcall_err(meths.open_win, 0, false, { - relative='editor', row=5, col=5, width=5, height=5, - })) + eq( + 'E11: Invalid in command-line window; 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; 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, - }))) + 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( + '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) @@ -865,7 +1087,11 @@ describe('API/win', 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, + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, border = b, }) @@ -875,17 +1101,21 @@ describe('API/win', function() it('includes border with highlight group', function() local b = { - {'a', 'Normal'}, - {'b', 'Special'}, - {'c', 'String'}, - {'d', 'Comment'}, - {'e', 'Visual'}, - {'f', 'Error'}, - {'g', 'Constant'}, - {'h', 'PreProc'}, + { 'a', 'Normal' }, + { 'b', 'Special' }, + { 'c', 'String' }, + { 'd', 'Comment' }, + { 'e', 'Visual' }, + { 'f', 'Error' }, + { 'g', 'Constant' }, + { 'h', 'PreProc' }, } local win = meths.open_win(0, true, { - relative='win', row=3, col=3, width=12, height=3, + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, border = b, }) @@ -894,11 +1124,17 @@ describe('API/win', function() end) it('includes title and footer', function() - local title = { {'A', {'StatusLine', 'TabLine'}}, {'B'}, {'C', 'WinBar'} } - local footer = { {'A', 'WinBar'}, {'B'}, {'C', {'StatusLine', 'TabLine'}} } + 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, + relative = 'win', + row = 3, + col = 3, + width = 12, + height = 3, + border = 'single', + title = title, + footer = footer, }) local cfg = meths.win_get_config(win) @@ -908,35 +1144,39 @@ describe('API/win', function() end) describe('set_config', function() - it('no crash with invalid title', function () + it('no crash with invalid title', function() local win = meths.open_win(0, true, { width = 10, height = 10, - relative = "editor", + relative = 'editor', row = 10, col = 10, - title = { { "test" } }, - border = "single", + title = { { 'test' } }, + border = 'single', }) - eq("title/footer cannot be an empty array", - pcall_err(meths.win_set_config, win, {title = {}})) - command("redraw!") + eq( + 'title/footer cannot be an empty array', + pcall_err(meths.win_set_config, win, { title = {} }) + ) + command('redraw!') assert_alive() end) - it('no crash with invalid footer', function () + it('no crash with invalid footer', function() local win = meths.open_win(0, true, { width = 10, height = 10, - relative = "editor", + relative = 'editor', row = 10, col = 10, - footer = { { "test" } }, - border = "single", + footer = { { 'test' } }, + border = 'single', }) - eq("title/footer cannot be an empty array", - pcall_err(meths.win_set_config, win, {footer = {}})) - command("redraw!") + eq( + 'title/footer cannot be an empty array', + pcall_err(meths.win_set_config, win, { footer = {} }) + ) + command('redraw!') assert_alive() end) end) diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua index 3ff4d9b873..62f87bfd97 100644 --- a/test/functional/autocmd/autocmd_oldtest_spec.lua +++ b/test/functional/autocmd/autocmd_oldtest_spec.lua @@ -12,7 +12,7 @@ describe('oldtests', function() before_each(clear) local exec_lines = function(str) - return funcs.split(funcs.execute(str), "\n") + return funcs.split(funcs.execute(str), '\n') end local add_an_autocmd = function() @@ -38,7 +38,6 @@ describe('oldtests', function() exec [[ augroup vimBarTest| au!| augroup END ]] eq(1, #exec_lines('au vimBarTest')) - -- test that a bar is recognized after the {event} add_an_autocmd() exec [[ augroup vimBarTest| au!BufReadCmd| augroup END ]] @@ -50,8 +49,8 @@ describe('oldtests', function() end) it('should fire on unload buf', function() - funcs.writefile({'Test file Xxx1'}, 'Xxx1') - funcs.writefile({'Test file Xxx2'}, 'Xxx2') + funcs.writefile({ 'Test file Xxx1' }, 'Xxx1') + funcs.writefile({ 'Test file Xxx2' }, 'Xxx2') local fname = 'Xtest_functional_autocmd_unload' local content = [[ @@ -72,7 +71,7 @@ describe('oldtests', function() q ]] - funcs.writefile(funcs.split(content, "\n"), fname) + funcs.writefile(funcs.split(content, '\n'), fname) funcs.delete('Xout') funcs.system(string.format('%s --clean -N -S %s', meths.get_vvar('progpath'), fname)) @@ -89,7 +88,7 @@ describe('oldtests', function() local screen = Screen.new(75, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {background = Screen.colors.Cyan}; + [1] = { background = Screen.colors.Cyan }, }) exec([[ set noshowcmd noruler scrolloff=0 @@ -97,7 +96,8 @@ describe('oldtests', function() edit test/old/testdir/samples/box.txt ]]) feed('249GVd') - screen:expect{grid=[[ + screen:expect { + grid = [[ const auto themeEmoji = _forPeer->themeEmoji(); | if (themeEmoji.isEmpty()) { | return nonCustom; | @@ -108,9 +108,11 @@ describe('oldtests', function() return nonCustom; | {1:^}} | 353 fewer lines | - ]]} + ]], + } feed('') - screen:expect{grid=[[ + screen:expect { + grid = [[ | auto BackgroundBox::Inner::resolveResetCustomPaper() const | -> std::optional { | @@ -121,6 +123,7 @@ describe('oldtests', function() 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 b9ece82420..2ae6277bd9 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -26,23 +26,23 @@ describe('autocmd', function() it(':tabnew, :split, :close events order, ', function() local expected = { - {'WinLeave', ''}, - {'TabLeave', ''}, - {'WinEnter', ''}, - {'TabNew', 'testfile1'}, -- :tabnew - {'TabEnter', ''}, - {'BufLeave', ''}, - {'BufEnter', 'testfile1'}, -- :split - {'WinLeave', 'testfile1'}, - {'WinEnter', 'testfile1'}, - {'WinLeave', 'testfile1'}, - {'WinClosed', '1002'}, -- :close, WinClosed = window-id - {'WinEnter', 'testfile1'}, - {'WinLeave', 'testfile1'}, -- :bdelete - {'WinEnter', 'testfile1'}, - {'BufLeave', 'testfile1'}, - {'BufEnter', 'testfile2'}, - {'WinClosed', '1000'}, + { 'WinLeave', '' }, + { 'TabLeave', '' }, + { 'WinEnter', '' }, + { 'TabNew', 'testfile1' }, -- :tabnew + { 'TabEnter', '' }, + { 'BufLeave', '' }, + { 'BufEnter', 'testfile1' }, -- :split + { 'WinLeave', 'testfile1' }, + { 'WinEnter', 'testfile1' }, + { 'WinLeave', 'testfile1' }, + { 'WinClosed', '1002' }, -- :close, WinClosed = window-id + { 'WinEnter', 'testfile1' }, + { 'WinLeave', 'testfile1' }, -- :bdelete + { 'WinEnter', 'testfile1' }, + { 'BufLeave', 'testfile1' }, + { 'BufEnter', 'testfile2' }, + { 'WinClosed', '1000' }, } command('let g:evs = []') command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("")])') @@ -63,10 +63,10 @@ describe('autocmd', function() it('first edit causes BufUnload on NoName', function() local expected = { - {'BufUnload', ''}, - {'BufDelete', ''}, - {'BufWipeout', ''}, - {'BufEnter', 'testfile1'}, + { 'BufUnload', '' }, + { 'BufDelete', '' }, + { 'BufWipeout', '' }, + { 'BufEnter', 'testfile1' }, } command('let g:evs = []') command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("")])') @@ -106,20 +106,23 @@ describe('autocmd', function() local buf1 = eval("bufnr('%')") command('new') local buf2 = eval("bufnr('%')") - command('autocmd WinClosed :call add(g:evs, ["WinClosed", expand("")])' - -- Attempt recursion. - ..' | bdelete '..buf2) + command( + 'autocmd WinClosed :call add(g:evs, ["WinClosed", expand("")])' + -- Attempt recursion. + .. ' | bdelete ' + .. buf2 + ) command('tabedit testfile2') command('tabedit testfile3') - command('bdelete '..buf2) + command('bdelete ' .. buf2) -- Non-recursive: only triggered once. eq({ - {'WinClosed', '2'}, + { 'WinClosed', '2' }, }, eval('g:evs')) - command('bdelete '..buf1) + command('bdelete ' .. buf1) eq({ - {'WinClosed', '2'}, - {'WinClosed', '1'}, + { 'WinClosed', '2' }, + { 'WinClosed', '1' }, }, eval('g:evs')) end) @@ -130,7 +133,7 @@ describe('autocmd', function() command('new') command('close') eq({ - {'WinClosed', '1001'}, + { 'WinClosed', '1001' }, }, eval('g:evs')) end) @@ -139,16 +142,15 @@ describe('autocmd', function() end) describe('BufLeave autocommand', function() - it('can wipe out the buffer created by :edit which triggered autocmd', - function() + it('can wipe out the buffer created by :edit which triggered autocmd', function() meths.set_option_value('hidden', true, {}) curbufmeths.set_lines(0, 1, false, { 'start of test file xx', - 'end of test file xx'}) + 'end of test file xx', + }) command('autocmd BufLeave * bwipeout yy') - eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', - exc_exec('edit yy')) + eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', exc_exec('edit yy')) expect([[ start of test file xx @@ -156,7 +158,7 @@ describe('autocmd', function() end) end) - it('++once', function() -- :help autocmd-once + it('++once', function() -- :help autocmd-once -- -- ":autocmd ... ++once" executes its handler once, then removes the handler. -- @@ -177,7 +179,8 @@ describe('autocmd', function() command('autocmd TabNew * ++once :call add(g:foo, "Once2")') command('autocmd TabNew * :call add(g:foo, "Many2")') command('autocmd TabNew * ++once :call add(g:foo, "Once3")') - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- TabNew @@ -186,18 +189,21 @@ describe('autocmd', function() :call add(g:foo, "Once2") :call add(g:foo, "Many2") :call add(g:foo, "Once3")]]), - funcs.execute('autocmd Tabnew')) + funcs.execute('autocmd Tabnew') + ) command('tabnew') command('tabnew') command('tabnew') eq(expected, eval('g:foo')) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- TabNew * :call add(g:foo, "Many1") :call add(g:foo, "Many2")]]), - funcs.execute('autocmd Tabnew')) + funcs.execute('autocmd Tabnew') + ) -- -- ":autocmd ... ++once" handlers can be deleted. @@ -218,7 +224,9 @@ describe('autocmd', function() } command('let g:foo = []') command('autocmd OptionSet binary ++nested ++once :call add(g:foo, "OptionSet-Once")') - command('autocmd CursorMoved ++once ++nested setlocal binary|:call add(g:foo, "CursorMoved-Once")') + command( + 'autocmd CursorMoved ++once ++nested setlocal binary|:call add(g:foo, "CursorMoved-Once")' + ) command("put ='foo bar baz'") feed('0llhlh') eq(expected, eval('g:foo')) @@ -231,15 +239,17 @@ describe('autocmd', function() 'Once2', } command('let g:foo = []') - command('autocmd! TabNew') -- Clear all TabNew handlers. + command('autocmd! TabNew') -- Clear all TabNew handlers. command('autocmd TabNew * ++once :call add(g:foo, "Once1")') command('autocmd TabNew * ++once :call add(g:foo, "Once2")') command('tabnew') eq(expected, eval('g:foo')) - eq(dedent([[ + eq( + dedent([[ --- Autocommands ---]]), - funcs.execute('autocmd Tabnew')) + funcs.execute('autocmd Tabnew') + ) end) it('internal `aucmd_win` window', function() @@ -250,9 +260,13 @@ describe('autocmd', function() local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {background = Screen.colors.LightMagenta}, - [3] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { background = Screen.colors.LightMagenta }, + [3] = { + background = Screen.colors.LightMagenta, + bold = true, + foreground = Screen.colors.Blue1, + }, }) source([[ @@ -276,7 +290,7 @@ describe('autocmd', function() | ]]) - feed(":enew | doautoall User") + feed(':enew | doautoall User') screen:expect([[ {2:bb }| {3:~ }|*4 @@ -293,14 +307,16 @@ describe('autocmd', function() eq(7, eval('g:test')) -- API calls are blocked when aucmd_win is not in scope - eq('Vim(call):E5555: API call: Invalid window id: 1001', - pcall_err(command, "call nvim_set_current_win(g:winid)")) + eq( + 'Vim(call):E5555: API call: Invalid window id: 1001', + pcall_err(command, 'call nvim_set_current_win(g:winid)') + ) -- second time aucmd_win is needed, a different code path is invoked -- to reuse the same window, so check again - command("let g:test = v:null") - command("let g:had_value = v:null") - feed(":doautoall User") + command('let g:test = v:null') + command('let g:had_value = v:null') + feed(':doautoall User') screen:expect([[ {2:bb }| {3:~ }|*4 @@ -318,17 +334,19 @@ describe('autocmd', function() eq(0, eval('g:had_value')) eq(7, eval('g:test')) - eq('Vim(call):E5555: API call: Invalid window id: 1001', - pcall_err(command, "call nvim_set_current_win(g:winid)")) + eq( + 'Vim(call):E5555: API call: Invalid window id: 1001', + pcall_err(command, 'call nvim_set_current_win(g:winid)') + ) end) - it("`aucmd_win` cannot be changed into a normal window #13699", function() + it('`aucmd_win` cannot be changed into a normal window #13699', function() local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids { - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {reverse = true}, - [3] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { reverse = true }, + [3] = { bold = true, reverse = true }, } -- Create specific layout and ensure it's left unchanged. @@ -371,13 +389,16 @@ describe('autocmd', function() -- After all of our messing around, aucmd_win should still be floating. -- Use :only to ensure _G.buf is hidden again (so the aucmd_win is used). - eq("editor", exec_lua [[ + eq( + 'editor', + exec_lua [[ vim.cmd "only" vim.api.nvim_buf_call(_G.buf, function() _G.config = vim.api.nvim_win_get_config(0) end) return _G.config.relative - ]]) + ]] + ) end) describe('closing last non-floating window in tab from `aucmd_win`', function() @@ -388,14 +409,18 @@ describe('autocmd', function() end) it('gives E814 when there are no other floating windows', function() - eq('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', - pcall_err(command, 'doautoall BufAdd')) + eq( + 'BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', + pcall_err(command, 'doautoall BufAdd') + ) end) it('gives E814 when there are other floating windows', function() - meths.open_win(0, true, {width = 10, height = 10, relative = 'editor', row = 10, col = 10}) - eq('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', - pcall_err(command, 'doautoall BufAdd')) + meths.open_win(0, true, { width = 10, height = 10, relative = 'editor', row = 10, col = 10 }) + eq( + 'BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', + pcall_err(command, 'doautoall BufAdd') + ) end) end) @@ -404,60 +429,88 @@ describe('autocmd', function() vim.cmd('tabnew') _G.buf = vim.api.nvim_create_buf(true, true) ]]) - matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + matches( + 'Vim:E813: Cannot close autocmd window$', + pcall_err( + exec_lua, + [[ vim.api.nvim_buf_call(_G.buf, function() local win = vim.api.nvim_get_current_win() vim.api.nvim_win_close(win, true) end) - ]])) - matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + 'Vim:E813: Cannot close autocmd window$', + pcall_err( + exec_lua, + [[ vim.api.nvim_buf_call(_G.buf, function() local win = vim.api.nvim_get_current_win() vim.cmd('tabnext') vim.api.nvim_win_close(win, true) end) - ]])) - matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + 'Vim:E813: Cannot close autocmd window$', + pcall_err( + exec_lua, + [[ vim.api.nvim_buf_call(_G.buf, function() local win = vim.api.nvim_get_current_win() vim.api.nvim_win_hide(win) end) - ]])) - matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + 'Vim:E813: Cannot close autocmd window$', + pcall_err( + exec_lua, + [[ vim.api.nvim_buf_call(_G.buf, function() local win = vim.api.nvim_get_current_win() vim.cmd('tabnext') vim.api.nvim_win_hide(win) end) - ]])) + ]] + ) + ) end) it(':doautocmd does not warn "No matching autocommands" #10689', function() local screen = Screen.new(32, 3) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, }) feed(':doautocmd User Foo') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }| :doautocmd User Foo | - ]]} + ]], + } feed(':autocmd! SessionLoadPost') feed(':doautocmd SessionLoadPost') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }| :doautocmd SessionLoadPost | - ]]} + ]], + } end) describe('v:event is readonly #18063', function() it('during ChanOpen event', function() command('autocmd ChanOpen * let v:event.info.id = 0') - funcs.jobstart({'cat'}) + funcs.jobstart({ 'cat' }) retry(nil, nil, function() eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) end) @@ -473,15 +526,19 @@ describe('autocmd', function() it('during RecordingLeave event', function() command([[autocmd RecordingLeave * let v:event.regname = '']]) - eq('RecordingLeave Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.regname"', - pcall_err(command, 'normal! qqq')) + eq( + 'RecordingLeave Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.regname"', + pcall_err(command, 'normal! qqq') + ) end) it('during TermClose event', function() command('autocmd TermClose * let v:event.status = 0') command('terminal') - eq('TermClose Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.status"', - pcall_err(command, 'bdelete!')) + eq( + 'TermClose Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.status"', + pcall_err(command, 'bdelete!') + ) end) end) @@ -549,9 +606,12 @@ describe('autocmd', function() eq(0, funcs.exists('#WinNew')) -- call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') - local ok, msg = pcall(source, [[ + local ok, msg = pcall( + source, + [[ au WinNew * ++once ++once echo bad - ]]) + ]] + ) eq(false, ok) eq(true, not not string.find(msg, 'E983:')) @@ -559,7 +619,7 @@ describe('autocmd', function() it('should have autocmds in filetypedetect group', function() source [[filetype on]] - neq({}, meths.get_autocmds { group = "filetypedetect" }) + neq({}, meths.get_autocmds { group = 'filetypedetect' }) end) it('should allow comma-separated patterns', function() @@ -571,7 +631,7 @@ describe('autocmd', function() augroup END ]] - eq(4, #meths.get_autocmds { event = "BufReadCmd", group = "TestingPatterns" }) + eq(4, #meths.get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' }) end) end) @@ -590,7 +650,7 @@ describe('autocmd', function() }) vim.cmd "tabnew" ]] - eq(1, eval('g:count')) -- Added autocommands should not be executed + eq(1, eval('g:count')) -- Added autocommands should not be executed end) it('no crash when clearing a group inside a callback #23355', function() diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua index 47f4adb0d6..af0dd887fa 100644 --- a/test/functional/autocmd/bufenter_spec.lua +++ b/test/functional/autocmd/bufenter_spec.lua @@ -12,9 +12,9 @@ describe('autocmd BufEnter', function() it("triggered by nvim_command('edit ')", function() command("autocmd BufEnter * if isdirectory(expand('')) | let g:dir_bufenter = 1 | endif") - request("nvim_command", "split .") - eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. - eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. + request('nvim_command', 'split .') + eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. + eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. end) it('triggered by "try|:split |endtry" in a function', function() @@ -27,21 +27,20 @@ describe('autocmd BufEnter', function() endtry endfunction ]]) - command("call Test()") - eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. - eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. + command('call Test()') + eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. + eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. end) it('triggered by ":split normal|:help|:bw"', function() helpers.add_builddir_to_rtp() - command("split normal") - command("wincmd j") - command("help") - command("wincmd L") - command("autocmd BufEnter normal let g:bufentered = 1") - command("bw") + command('split normal') + command('wincmd j') + command('help') + command('wincmd L') + command('autocmd BufEnter normal let g:bufentered = 1') + command('bw') eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered end) - end) diff --git a/test/functional/autocmd/bufmodifiedset_spec.lua b/test/functional/autocmd/bufmodifiedset_spec.lua index c566361e37..27fe9fcc94 100644 --- a/test/functional/autocmd/bufmodifiedset_spec.lua +++ b/test/functional/autocmd/bufmodifiedset_spec.lua @@ -14,9 +14,9 @@ describe('BufModified', function() let g:modified = 0 autocmd BufModifiedSet * let g:modified += 1 ]]) - request("nvim_command", [[normal! aa\]]) + request('nvim_command', [[normal! aa\]]) eq(1, eval('g:modified')) - request("nvim_command", [[normal! u]]) + request('nvim_command', [[normal! u]]) eq(2, eval('g:modified')) end) end) diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index 577ee53c9d..3502721ee0 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -15,7 +15,7 @@ describe('cmdline autocommands', function() before_each(function() clear() channel = meths.get_api_info()[1] - meths.set_var("channel",channel) + meths.set_var('channel', channel) command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)") command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)") command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)") @@ -24,23 +24,27 @@ describe('cmdline autocommands', function() it('works', function() feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('redraw') - eq({'notification', 'CmdlineLeave', - {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = false } } }, + next_msg() + ) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) -- note: feed('bork') might not consume 'bork' -- due to out-of-band interrupt handling feed('bork') - eq({'notification', 'CmdlineLeave', - {{cmdtype=':', cmdlevel=1, abort=true}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = true } } }, + next_msg() + ) end) it('can abort cmdline', function() - command("autocmd CmdlineLeave * let v:event.abort= len(getcmdline())>15") + command('autocmd CmdlineLeave * let v:event.abort= len(getcmdline())>15') feed(":put! ='ok'") expect([[ ok @@ -57,10 +61,10 @@ describe('cmdline autocommands', function() local screen = Screen.new(72, 8) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [4] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true, reverse = true }, }) command("autocmd CmdlineEnter * echoerr 'FAIL'") command("autocmd CmdlineLeave * echoerr 'very error'") @@ -99,7 +103,7 @@ describe('cmdline autocommands', function() command("autocmd CmdlineChanged * echoerr 'change erreor'") -- history recall still works - feed(":") + feed(':') screen:expect([[ | lorem ipsum | @@ -111,7 +115,7 @@ describe('cmdline autocommands', function() :put ='lorem ipsum'^ | ]]) - feed("") + feed('') screen:expect([[ | lorem ipsum | @@ -124,7 +128,7 @@ describe('cmdline autocommands', function() ]]) -- edit still works - feed(".") + feed('.') screen:expect([[ {4: }| : | @@ -161,62 +165,97 @@ describe('cmdline autocommands', function() it('works with nested cmdline', function() feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('=') - eq({'notification', 'CmdlineEnter', {{cmdtype='=', cmdlevel=2}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = '=', cmdlevel = 2 } } }, next_msg()) feed('') - eq({'notification', 'CmdWinEnter', {{}}}, next_msg()) + eq({ 'notification', 'CmdWinEnter', { {} } }, next_msg()) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=3}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 3 } } }, next_msg()) feed('') - eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=3, abort=true}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 3, abort = true } } }, + next_msg() + ) feed('') - eq({'notification', 'CmdWinLeave', {{}}}, next_msg()) + eq({ 'notification', 'CmdWinLeave', { {} } }, next_msg()) feed('1+2') - eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = '=', cmdlevel = 2, abort = false } } }, + next_msg() + ) end) it('no crash with recursive use of v:event #19484', function() command('autocmd CmdlineEnter * normal :') feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('') - eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = false } } }, + next_msg() + ) end) - it('supports CmdlineChanged' ,function() - command("autocmd CmdlineChanged * call rpcnotify(g:channel, 'CmdlineChanged', v:event, getcmdline())") + it('supports CmdlineChanged', function() + command( + "autocmd CmdlineChanged * call rpcnotify(g:channel, 'CmdlineChanged', v:event, getcmdline())" + ) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('l') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "l"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'l' } }, next_msg()) feed('e') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "le"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'le' } }, next_msg()) feed('t') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let' } }, next_msg()) feed('') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let ' } }, + next_msg() + ) feed('x') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x"}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x' } }, + next_msg() + ) feed('') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x ' } }, + next_msg() + ) feed('=') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x ="}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x =' } }, + next_msg() + ) feed('') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x = ' } }, + next_msg() + ) feed('=') - eq({'notification', 'CmdlineEnter', {{cmdtype='=', cmdlevel=2}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = '=', cmdlevel = 2 } } }, next_msg()) feed('1') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = '=', cmdlevel = 2 }, '1' } }, next_msg()) feed('+') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = '=', cmdlevel = 2 }, '1+' } }, next_msg()) feed('1') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = '=', cmdlevel = 2 }, '1+1' } }, next_msg()) feed('') - eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = 2"}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = '=', cmdlevel = 2, abort = false } } }, + next_msg() + ) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x = 2' } }, + next_msg() + ) feed('') - eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = false } } }, + next_msg() + ) eq(2, eval('x')) end) end) diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index e6bcb19682..535881b6cc 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -27,7 +27,7 @@ describe('CursorHold', function() retry(10, nil, function() ut = ut * 2 meths.set_option_value('updatetime', ut, {}) - feed('0') -- reset did_cursorhold + feed('0') -- reset did_cursorhold meths.set_var('cursorhold', 0) sleep(ut / 4) fn() @@ -44,15 +44,23 @@ describe('CursorHold', function() local ignore_key = meths.replace_termcodes('', true, true, true) test_cursorhold(function() end, 1) - test_cursorhold(function() feed('') end, 1) - test_cursorhold(function() meths.feedkeys('', 'n', true) end, 1) - test_cursorhold(function() feed('') end, 0) - test_cursorhold(function() meths.feedkeys(ignore_key, 'n', true) end, 0) + test_cursorhold(function() + feed('') + end, 1) + test_cursorhold(function() + meths.feedkeys('', 'n', true) + end, 1) + test_cursorhold(function() + feed('') + end, 0) + test_cursorhold(function() + meths.feedkeys(ignore_key, 'n', true) + end, 0) end) it("reducing 'updatetime' while waiting for CursorHold #20241", function() meths.set_option_value('updatetime', 10000, {}) - feed('0') -- reset did_cursorhold + feed('0') -- reset did_cursorhold meths.set_var('cursorhold', 0) sleep(50) eq(0, meths.get_var('cursorhold')) diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua index 854e14b088..3ab5c3b9b1 100644 --- a/test/functional/autocmd/cursormoved_spec.lua +++ b/test/functional/autocmd/cursormoved_spec.lua @@ -19,9 +19,9 @@ describe('CursorMoved', function() ]]) eq({}, eval('g:log')) command('new') - eq({'BufEnter2', 'CursorMoved2'}, eval('g:log')) + eq({ 'BufEnter2', 'CursorMoved2' }, eval('g:log')) command('wincmd w') - eq({'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1'}, eval('g:log')) + eq({ 'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1' }, eval('g:log')) end) it('is not triggered by temporarily switching window', function() @@ -41,13 +41,13 @@ describe('CursorMoved', function() vsplit foo autocmd CursorMoved * let g:cursormoved += 1 ]]) - meths.buf_set_lines(eval('g:buf'), 0, -1, true, {'aaa'}) + 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({ '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() + it('is not triggered by cursor movement prior to first CursorMoved instantiation', function() source([[ let g:cursormoved = 0 autocmd! CursorMoved diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 20aa07d058..208bd0f0e9 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -21,41 +21,55 @@ describe('autocmd DirChanged and DirChangedPre', function() curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3', } - setup(function() for _, dir in pairs(dirs) do helpers.mkdir(dir) end end) - teardown(function() for _, dir in pairs(dirs) do helpers.rmdir(dir) end end) + setup(function() + for _, dir in pairs(dirs) do + helpers.mkdir(dir) + end + end) + teardown(function() + for _, dir in pairs(dirs) do + helpers.rmdir(dir) + end + end) before_each(function() clear() - command('autocmd DirChangedPre * let [g:evpre, g:amatchpre, g:cdprecount] ' - ..'= [copy(v:event), expand(""), 1 + get(g:, "cdprecount", 0)]') - command('autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' - ..'= [getcwd(), copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]') + command( + 'autocmd DirChangedPre * let [g:evpre, g:amatchpre, g:cdprecount] ' + .. '= [copy(v:event), expand(""), 1 + get(g:, "cdprecount", 0)]' + ) + command( + 'autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' + .. '= [getcwd(), copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]' + ) -- Normalize path separators. - command([[autocmd DirChangedPre * let g:evpre['directory'] = substitute(g:evpre['directory'], '\\', '/', 'g')]]) + command( + [[autocmd DirChangedPre * let g:evpre['directory'] = substitute(g:evpre['directory'], '\\', '/', 'g')]] + ) command([[autocmd DirChanged * let g:ev['cwd'] = substitute(g:ev['cwd'], '\\', '/', 'g')]]) command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]]) end) it('set v:event and ', function() - command('lcd '..dirs[1]) - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('lcd ' .. dirs[1]) + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) - command('tcd '..dirs[2]) - eq({directory=dirs[2], scope='tabpage', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + command('tcd ' .. dirs[2]) + eq({ directory = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) - command('cd '..dirs[3]) - eq({directory=dirs[3], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + command('cd ' .. dirs[3]) + eq({ directory = dirs[3], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'global', changed_window = false }, eval('g:ev')) eq('global', eval('g:amatchpre')) eq('global', eval('g:amatch')) eq(3, eval('g:cdprecount')) @@ -63,22 +77,22 @@ describe('autocmd DirChanged and DirChangedPre', function() end) it('DirChanged set getcwd() during event #6260', function() - command('lcd '..dirs[1]) + command('lcd ' .. dirs[1]) eq(dirs[1], eval('g:getcwd')) - command('tcd '..dirs[2]) + command('tcd ' .. dirs[2]) eq(dirs[2], eval('g:getcwd')) - command('cd '..dirs[3]) + command('cd ' .. dirs[3]) eq(dirs[3], eval('g:getcwd')) end) it('disallow recursion', function() command('set shellslash') -- Set up a _nested_ handler. - command('autocmd DirChanged * nested lcd '..dirs[3]) - command('lcd '..dirs[1]) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('autocmd DirChanged * nested lcd ' .. dirs[3]) + command('lcd ' .. dirs[1]) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq(1, eval('g:cdcount')) -- autocmd changed to dirs[3], but did NOT trigger another DirChanged. eq(dirs[3], eval('getcwd()')) @@ -89,27 +103,36 @@ describe('autocmd DirChanged and DirChangedPre', function() command('let g:cdcount = 0') local status1, err1 = pcall(function() - command('lcd '..dirs[1]..'/doesnotexist') + command('lcd ' .. dirs[1] .. '/doesnotexist') end) - eq({directory=dirs[1]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[1] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(1, eval('g:cdprecount')) eq(0, eval('g:cdcount')) local status2, err2 = pcall(function() - command('lcd '..dirs[2]..'/doesnotexist') + command('lcd ' .. dirs[2] .. '/doesnotexist') end) - eq({directory=dirs[2]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[2] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(2, eval('g:cdprecount')) eq(0, eval('g:cdcount')) local status3, err3 = pcall(function() - command('lcd '..dirs[3]..'/doesnotexist') + command('lcd ' .. dirs[3] .. '/doesnotexist') end) - eq({directory=dirs[3]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[3] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(3, eval('g:cdprecount')) @@ -119,93 +142,93 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(false, status2) eq(false, status3) - eq('E344:', string.match(err1, "E%d*:")) - eq('E344:', string.match(err2, "E%d*:")) - eq('E344:', string.match(err3, "E%d*:")) + eq('E344:', string.match(err1, 'E%d*:')) + eq('E344:', string.match(err2, 'E%d*:')) + eq('E344:', string.match(err3, 'E%d*:')) end) it("are triggered by 'autochdir'", function() command('set autochdir') - command('split '..dirs[1]..'/foo') - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[1] .. '/foo') + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatchpre')) eq('auto', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) - command('split '..dirs[2]..'/bar') - eq({directory=dirs[2], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[2] .. '/bar') + eq({ directory = dirs[2], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end) it('do not trigger if directory has not changed', function() - command('lcd '..dirs[1]) - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('lcd ' .. dirs[1]) + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('lcd '..dirs[1]) + command('lcd ' .. dirs[1]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) if is_os('win') then - command('lcd '..win_dirs[1]) + command('lcd ' .. win_dirs[1]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) end - command('tcd '..dirs[2]) - eq({directory=dirs[2], scope='tabpage', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + command('tcd ' .. dirs[2]) + eq({ directory = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('tcd '..dirs[2]) + command('tcd ' .. dirs[2]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) if is_os('win') then - command('tcd '..win_dirs[2]) + command('tcd ' .. win_dirs[2]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end - command('cd '..dirs[3]) - eq({directory=dirs[3], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + command('cd ' .. dirs[3]) + eq({ directory = dirs[3], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'global', changed_window = false }, eval('g:ev')) eq('global', eval('g:amatch')) eq(3, eval('g:cdprecount')) eq(3, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('cd '..dirs[3]) + command('cd ' .. dirs[3]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(3, eval('g:cdprecount')) eq(3, eval('g:cdcount')) if is_os('win') then - command('cd '..win_dirs[3]) + command('cd ' .. win_dirs[3]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(3, eval('g:cdprecount')) @@ -214,23 +237,23 @@ describe('autocmd DirChanged and DirChangedPre', function() command('set autochdir') - command('split '..dirs[1]..'/foo') - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[1] .. '/foo') + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatchpre')) eq('auto', eval('g:amatch')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('split '..dirs[1]..'/bar') + command('split ' .. dirs[1] .. '/bar') eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) if is_os('win') then - command('split '..win_dirs[1]..'/baz') + command('split ' .. win_dirs[1] .. '/baz') eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(4, eval('g:cdprecount')) @@ -238,93 +261,93 @@ describe('autocmd DirChanged and DirChangedPre', function() end end) - it("are triggered by switching to win/tab with different CWD #6054", function() - command('lcd '..dirs[3]) -- window 3 - command('split '..dirs[2]..'/foo') -- window 2 - command('lcd '..dirs[2]) - command('split '..dirs[1]..'/bar') -- window 1 - command('lcd '..dirs[1]) + it('are triggered by switching to win/tab with different CWD #6054', function() + command('lcd ' .. dirs[3]) -- window 3 + command('split ' .. dirs[2] .. '/foo') -- window 2 + command('lcd ' .. dirs[2]) + command('split ' .. dirs[1] .. '/bar') -- window 1 + command('lcd ' .. dirs[1]) - command('2wincmd w') -- window 2 - eq({directory=dirs[2], scope='window', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + command('2wincmd w') -- window 2 + eq({ directory = dirs[2], scope = 'window', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = true }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) - command('tabnew') -- tab 2 (tab-local CWD) - eq(4, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tcd '..dirs[3]) - command('tabnext') -- tab 1 (no tab-local CWD) - eq({directory=dirs[2], scope='window', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + command('tabnew') -- tab 2 (tab-local CWD) + eq(4, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd ' .. dirs[3]) + command('tabnext') -- tab 1 (no tab-local CWD) + eq({ directory = dirs[2], scope = 'window', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = true }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) - command('tabnext') -- tab 2 - eq({directory=dirs[3], scope='tabpage', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[3], scope='tabpage', changed_window=true}, eval('g:ev')) + command('tabnext') -- tab 2 + eq({ directory = dirs[3], scope = 'tabpage', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'tabpage', changed_window = true }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(7, eval('g:cdprecount')) eq(7, eval('g:cdcount')) - command('tabnext') -- tab 1 - command('3wincmd w') -- window 3 + command('tabnext') -- tab 1 + command('3wincmd w') -- window 3 eq(9, eval('g:cdprecount')) eq(9, eval('g:cdcount')) - command('tabnext') -- tab 2 (has the *same* CWD) - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 (has the *same* CWD) + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event if is_os('win') then - command('tabnew') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tcd '..win_dirs[3]) - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 2 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('lcd '..win_dirs[3]) -- window 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 2 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnew') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd ' .. win_dirs[3]) + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 2 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('lcd ' .. win_dirs[3]) -- window 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event end end) it('are triggered by nvim_set_current_dir()', function() request('nvim_set_current_dir', dirs[1]) - eq({directory=dirs[1], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='global', changed_window=false}, eval('g:ev')) + eq({ directory = dirs[1], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'global', changed_window = false }, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) request('nvim_set_current_dir', dirs[2]) - eq({directory=dirs[2], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='global', changed_window=false}, eval('g:ev')) + eq({ directory = dirs[2], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'global', changed_window = false }, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) @@ -333,7 +356,7 @@ describe('autocmd DirChanged and DirChangedPre', function() end) eq(false, status) eq('Failed to change directory', string.match(err, ': (.*)')) - eq({directory='/doesnotexist', scope='global', changed_window=false}, eval('g:evpre')) + eq({ directory = '/doesnotexist', scope = 'global', changed_window = false }, eval('g:evpre')) eq(3, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end) @@ -343,7 +366,7 @@ describe('autocmd DirChanged and DirChangedPre', function() command('let g:triggered = 0') command('autocmd DirChangedPre let g:triggeredpre = 1') command('autocmd DirChanged let g:triggered = 1') - command('cd '..dirs[1]) + command('cd ' .. dirs[1]) eq(1, eval('g:triggeredpre')) eq(1, eval('g:triggered')) end) diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua index a571f6ee3b..648f830f27 100644 --- a/test/functional/autocmd/filetype_spec.lua +++ b/test/functional/autocmd/filetype_spec.lua @@ -5,13 +5,13 @@ local clear = helpers.clear local command = helpers.command describe('autocmd FileType', function() - before_each(clear) + before_each(clear) - it("is triggered by :help only once", function() - helpers.add_builddir_to_rtp() - command("let g:foo = 0") - command("autocmd FileType help let g:foo = g:foo + 1") - command("help help") - assert.same(1, eval('g:foo')) - end) + it('is triggered by :help only once', function() + helpers.add_builddir_to_rtp() + command('let g:foo = 0') + command('autocmd FileType help let g:foo = g:foo + 1') + command('help help') + assert.same(1, eval('g:foo')) + end) end) diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index 6a5cdbb96e..cd9f2c96c1 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -5,7 +5,9 @@ local clear = helpers.clear local feed_command = helpers.feed_command local feed_data = thelpers.feed_data -if helpers.skip(helpers.is_os('win')) then return end +if helpers.skip(helpers.is_os('win')) then + return +end describe('autoread TUI FocusGained/FocusLost', function() local f1 = 'xtest-foo' @@ -14,10 +16,14 @@ describe('autoread TUI FocusGained/FocusLost', function() before_each(function() clear() screen = thelpers.setup_child_nvim({ - '-u', 'NONE', - '-i', 'NONE', - '--cmd', 'colorscheme vim', - '--cmd', 'set noswapfile noshowcmd noruler notermguicolors', + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'colorscheme vim', + '--cmd', + 'set noswapfile noshowcmd noruler notermguicolors', }) end) @@ -38,36 +44,44 @@ describe('autoread TUI FocusGained/FocusLost', function() local atime = os.time() - 10 luv.fs_utime(path, atime, atime) - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: } | {4:~ }|*3 {5:[No Name] }| | {3:-- TERMINAL --} | - ]]} - feed_command('edit '..path) - screen:expect{grid=[[ + ]], + } + feed_command('edit ' .. path) + screen:expect { + grid = [[ {1: } | {4:~ }|*3 {5:xtest-foo }| :edit xtest-foo | {3:-- TERMINAL --} | - ]]} + ]], + } feed_data('\027[O') feed_data('\027[O') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: } | {4:~ }|*3 {5:xtest-foo }| :edit xtest-foo | {3:-- TERMINAL --} | - ]], unchanged=true} + ]], + unchanged = true, + } helpers.write_file(path, expected_addition) feed_data('\027[I') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1:l}ine 1 | line 2 | line 3 | @@ -75,6 +89,7 @@ describe('autoread TUI FocusGained/FocusLost', function() {5:xtest-foo }| "xtest-foo" 4L, 28B | {3:-- TERMINAL --} | - ]]} + ]], + } end) end) diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua index 69a722a0e9..8ad914a597 100644 --- a/test/functional/autocmd/modechanged_spec.lua +++ b/test/functional/autocmd/modechanged_spec.lua @@ -17,15 +17,15 @@ describe('ModeChanged', function() feed('i') eq({ old_mode = 'nt', - new_mode = 't' + new_mode = 't', }, eval('g:event')) feed('') eq({ old_mode = 't', - new_mode = 'nt' + new_mode = 'nt', }, eval('g:event')) eq(3, eval('g:count')) - command("bd!") + command('bd!') -- v:event is cleared after the autocommand is done eq({}, eval('v:event')) diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua index 46c2c99b3d..83600f6689 100644 --- a/test/functional/autocmd/searchwrapped_spec.lua +++ b/test/functional/autocmd/searchwrapped_spec.lua @@ -15,7 +15,8 @@ describe('autocmd SearchWrapped', function() command('autocmd! SearchWrapped * let g:test += 1') curbufmeths.set_lines(0, 1, false, { 'The quick brown fox', - 'jumps over the lazy dog'}) + 'jumps over the lazy dog', + }) end) it('gets triggered when search wraps the end', function() diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua index 437b664bf5..f081c918fc 100644 --- a/test/functional/autocmd/show_spec.lua +++ b/test/functional/autocmd/show_spec.lua @@ -10,24 +10,25 @@ local eval = helpers.eval local exec = helpers.exec local feed = helpers.feed -describe(":autocmd", function() +describe(':autocmd', function() before_each(function() - clear({'-u', 'NONE'}) + clear({ '-u', 'NONE' }) end) - it("should not segfault when you just do autocmd", function() - command ":autocmd" + it('should not segfault when you just do autocmd', function() + command ':autocmd' end) - it("should filter based on ++once", function() - command "autocmd! BufEnter" + it('should filter based on ++once', function() + command 'autocmd! BufEnter' command "autocmd BufEnter * :echo 'Hello'" command [[augroup TestingOne]] command [[ autocmd BufEnter * :echo "Line 1"]] command [[ autocmd BufEnter * :echo "Line 2"]] command [[augroup END]] - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- BufEnter @@ -35,15 +36,16 @@ describe(":autocmd", function() TestingOne BufEnter * :echo "Line 1" :echo "Line 2"]]), - funcs.execute('autocmd BufEnter')) + funcs.execute('autocmd BufEnter') + ) end) it('should not show group information if interrupted', function() local screen = Screen.new(50, 6) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, -- NonText - [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg - [3] = {bold = true, foreground = Screen.colors.Magenta}, -- Title + [1] = { bold = true, foreground = Screen.colors.Blue1 }, -- NonText + [2] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg + [3] = { bold = true, foreground = Screen.colors.Magenta }, -- Title }) screen:attach() exec([[ @@ -109,7 +111,8 @@ describe(":autocmd", function() autocmd User foo call Func() doautocmd User foo ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -119,7 +122,9 @@ describe(":autocmd", function() test_3 BufEnter D echo 'D' E echo 'E' - F echo 'F']]), eval('g:output')) + F echo 'F']]), + eval('g:output') + ) end) it('can filter by pattern #17973', function() @@ -145,7 +150,8 @@ describe(":autocmd", function() autocmd User B echo "B3" augroup END ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 User @@ -153,8 +159,11 @@ describe(":autocmd", function() test_2 User A echo "A2" test_3 User - A echo "A3"]]), funcs.execute('autocmd User A')) - eq(dedent([[ + A echo "A3"]]), + funcs.execute('autocmd User A') + ) + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -168,14 +177,19 @@ describe(":autocmd", function() test_2 User B echo "B2" test_3 User - B echo "B3"]]), funcs.execute('autocmd * B')) - eq(dedent([[ + B echo "B3"]]), + funcs.execute('autocmd * B') + ) + eq( + dedent([[ --- Autocommands --- test_3 BufEnter B echo "B3" test_3 User - B echo "B3"]]), funcs.execute('autocmd test_3 * B')) + B echo "B3"]]), + funcs.execute('autocmd test_3 * B') + ) end) it('should skip consecutive patterns', function() @@ -200,7 +214,8 @@ describe(":autocmd", function() let g:output = execute('autocmd BufEnter') ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -216,6 +231,8 @@ describe(":autocmd", function() echo 'C' D echo 'D' echo 'E' - echo 'F']]), eval('g:output')) + echo 'F']]), + eval('g:output') + ) end) end) diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index 738064090a..96924fb2fc 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -8,10 +8,12 @@ local next_msg = helpers.next_msg local is_os = helpers.is_os local skip = helpers.skip -if skip(is_os('win'), 'Only applies to POSIX systems') then return end +if skip(is_os('win'), 'Only applies to POSIX systems') then + return +end local function posix_kill(signame, pid) - os.execute('kill -s '..signame..' -- '..pid..' >/dev/null') + os.execute('kill -s ' .. signame .. ' -- ' .. pid .. ' >/dev/null') end describe('autocmd Signal', function() @@ -20,19 +22,19 @@ describe('autocmd Signal', function() it('matches *', function() command('autocmd Signal * call rpcnotify(1, "foo")') posix_kill('USR1', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGUSR1', function() command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') posix_kill('USR1', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGWINCH', function() command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")') posix_kill('WINCH', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('does not match unknown patterns', function() diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua index 92d860c628..c5a2b42273 100644 --- a/test/functional/autocmd/tabclose_spec.lua +++ b/test/functional/autocmd/tabclose_spec.lua @@ -7,62 +7,76 @@ describe('TabClosed', function() describe('au TabClosed', function() describe('with * as ', function() it('matches when closing any tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()') + nvim( + 'command', + 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()' + ) repeat nvim('command', 'tabnew') until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6 - eq("tabclosed:6:6:5", nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5 - eq("tabclosed:5:5:4", nvim('exec', 'close', true)) -- close last window on tab, closes tab - eq("tabclosed:2:2:3", nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3 - eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('exec', 'tabonly', true)) -- close tabs 1 and 2 + eq('tabclosed:6:6:5', nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5 + eq('tabclosed:5:5:4', nvim('exec', 'close', true)) -- close last window on tab, closes tab + eq('tabclosed:2:2:3', nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3 + eq('tabclosed:1:1:2\ntabclosed:1:1:1', nvim('exec', 'tabonly', true)) -- close tabs 1 and 2 end) it('is triggered when closing a window via bdelete from another tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()') + nvim( + 'command', + 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()' + ) nvim('command', '1tabedit Xtestfile') nvim('command', '1tabedit Xtestfile') nvim('command', 'normal! 1gt') - eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('exec', 'bdelete Xtestfile', true)) - eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + eq({ 1, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1\ntabclosed:2:2:1', nvim('exec', 'bdelete Xtestfile', true)) + eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) end) it('is triggered when closing a window via bdelete from current tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()') + nvim( + 'command', + 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()' + ) nvim('command', 'file Xtestfile1') nvim('command', '1tabedit Xtestfile2') nvim('command', '1tabedit Xtestfile2') -- Only one tab is closed, and the alternate file is used for the other. - eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:2", nvim('exec', 'bdelete Xtestfile2', true)) + eq({ 2, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:2', nvim('exec', 'bdelete Xtestfile2', true)) eq('Xtestfile1', nvim('eval', 'bufname("")')) end) end) describe('with NR as ', function() it('matches when closing a tab whose index is NR', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()') + nvim( + 'command', + 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()' + ) nvim('command', 'au! TabClosed 2 echom "tabclosed:match"') repeat - nvim('command', 'tabnew') + nvim('command', 'tabnew') until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7 -- sanity check, we shouldn't match on tabs with numbers other than 2 - eq("tabclosed:7:7:6", nvim('exec', 'tabclose', true)) + eq('tabclosed:7:7:6', nvim('exec', 'tabclose', true)) -- close tab page 2, current tab is now 5 - eq("tabclosed:2:2:5\ntabclosed:match", nvim('exec', '2tabclose', true)) + eq('tabclosed:2:2:5\ntabclosed:match', nvim('exec', '2tabclose', true)) end) end) describe('with close', function() it('is triggered', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()') - nvim('command', 'tabedit Xtestfile') - eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:1", nvim('exec', 'close', true)) - eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + nvim( + 'command', + 'au! TabClosed * echom "tabclosed:".expand("").":".expand("").":".tabpagenr()' + ) + nvim('command', 'tabedit Xtestfile') + eq({ 2, 2 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1', nvim('exec', 'close', true)) + eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) end) end) end) end) - diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua index 6e167dd55c..fd4a16a298 100644 --- a/test/functional/autocmd/tabnewentered_spec.lua +++ b/test/functional/autocmd/tabnewentered_spec.lua @@ -15,16 +15,16 @@ describe('TabNewEntered', function() it('matches when entering any new tab', function() clear() nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') - eq("tabnewentered:2:2", nvim('exec', 'tabnew', true)) - eq("tabnewentered:3:3", nvim('exec', 'tabnew test.x2', true)) - end) + eq('tabnewentered:2:2', nvim('exec', 'tabnew', true)) + eq('tabnewentered:3:3', nvim('exec', 'tabnew test.x2', true)) + end) end) describe('with FILE as ', function() it('matches when opening a new tab for FILE', function() clear() nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') eq('tabnewentered:match', nvim('exec', 'tabnew Xtest-tabnewentered', true)) - end) + end) end) describe('with CTRL-W T', function() it('works when opening a new tab with CTRL-W T', function() @@ -49,22 +49,22 @@ end) describe('TabEnter', function() before_each(clear) it('has correct previous tab when entering any new tab', function() - command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') - command('augroup END') - eq("tabenter:2:1", nvim('exec', 'tabnew', true)) - eq("tabenter:3:2", nvim('exec', 'tabnew test.x2', true)) - command('augroup! TEMP') + command('augroup TEMP') + nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('augroup END') + eq('tabenter:2:1', nvim('exec', 'tabnew', true)) + eq('tabenter:3:2', nvim('exec', 'tabnew test.x2', true)) + command('augroup! TEMP') end) it('has correct previous tab when entering any preexisting tab', function() - command('tabnew') - command('tabnew') - command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') - command('augroup END') - eq("tabenter:1:3", nvim('exec', 'tabnext', true)) - eq("tabenter:2:1", nvim('exec', 'tabnext', true)) - command('augroup! TEMP') + command('tabnew') + command('tabnew') + command('augroup TEMP') + nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('augroup END') + eq('tabenter:1:3', nvim('exec', 'tabnext', true)) + eq('tabenter:2:1', nvim('exec', 'tabnext', true)) + command('augroup! TEMP') end) end) @@ -72,18 +72,19 @@ describe('tabpage/previous', function() before_each(clear) local function switches_to_previous_after_new_tab_creation_at_end(characters) return function() - -- Add three tabs for a total of four - command('tabnew') - command('tabnew') - command('tabnew') + -- Add three tabs for a total of four + command('tabnew') + command('tabnew') + command('tabnew') - -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + -- The previous tab is now the third. + eq(3, eval("tabpagenr('#')")) - -- Switch to the previous (third) tab - feed(characters) + -- Switch to the previous (third) tab + feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -93,18 +94,29 @@ describe('tabpage/previous', function() > [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') - ) + exec_capture('tabs') + ) - -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + -- The previous tab is now the fourth. + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous via g after new tab creation at end', - switches_to_previous_after_new_tab_creation_at_end('g')) - it('switches to previous via g. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('g')) - it('switches to previous via . after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('')) - it('switches to previous via :tabn #. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end(':tabn #')) + it( + 'switches to previous via g after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('g') + ) + it( + 'switches to previous via g. after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('g') + ) + it( + 'switches to previous via . after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('') + ) + it( + 'switches to previous via :tabn #. after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end(':tabn #') + ) local function switches_to_previous_after_new_tab_creation_in_middle(characters) return function() @@ -118,11 +130,12 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -134,21 +147,29 @@ describe('tabpage/previous', function() [No Name] Tab page 5 [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('switches to previous via g after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('g')) - it('switches to previous via g after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('g')) - it('switches to previous via after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('')) - it('switches to previous via :tabn # after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle(':tabn #')) + it( + 'switches to previous via g after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('g') + ) + it( + 'switches to previous via g after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('g') + ) + it( + 'switches to previous via after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('') + ) + it( + 'switches to previous via :tabn # after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle(':tabn #') + ) local function switches_to_previous_after_switching_to_next_tab(characters) return function() @@ -160,12 +181,13 @@ describe('tabpage/previous', function() command('tabnext') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 # [No Name] @@ -175,21 +197,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the first. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) end end - it('switches to previous via g after switching to next tab', - switches_to_previous_after_switching_to_next_tab('g')) - it('switches to previous via g after switching to next tab', - switches_to_previous_after_switching_to_next_tab('g')) - it('switches to previous via after switching to next tab', - switches_to_previous_after_switching_to_next_tab('')) - it('switches to previous via :tabn # after switching to next tab', - switches_to_previous_after_switching_to_next_tab(':tabn #')) + it( + 'switches to previous via g after switching to next tab', + switches_to_previous_after_switching_to_next_tab('g') + ) + it( + 'switches to previous via g after switching to next tab', + switches_to_previous_after_switching_to_next_tab('g') + ) + it( + 'switches to previous via after switching to next tab', + switches_to_previous_after_switching_to_next_tab('') + ) + it( + 'switches to previous via :tabn # after switching to next tab', + switches_to_previous_after_switching_to_next_tab(':tabn #') + ) local function switches_to_previous_after_switching_to_last_tab(characters) return function() @@ -203,12 +233,13 @@ describe('tabpage/previous', function() command('tablast') -- The previous tab is now the second. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 > [No Name] @@ -218,21 +249,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('g')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('g')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab(':tabn #')) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('g') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('g') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab(':tabn #') + ) local function switches_to_previous_after_switching_to_previous_tab(characters) return function() @@ -244,12 +283,13 @@ describe('tabpage/previous', function() command('tabprevious') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -259,21 +299,29 @@ describe('tabpage/previous', function() # [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('switches to previous via g after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('g')) - it('switches to previous via g after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('g')) - it('switches to previous via after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('')) - it('switches to previous via :tabn # after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab(':tabn #')) + it( + 'switches to previous via g after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('g') + ) + it( + 'switches to previous via g after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('g') + ) + it( + 'switches to previous via after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('') + ) + it( + 'switches to previous via :tabn # after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab(':tabn #') + ) local function switches_to_previous_after_switching_to_first_tab(characters) return function() @@ -287,12 +335,13 @@ describe('tabpage/previous', function() command('tabfirst') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Switch to the previous (third) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 # [No Name] @@ -302,21 +351,29 @@ describe('tabpage/previous', function() > [No Name] Tab page 4 [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the first. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) end end - it('switches to previous via g after switching to first tab', - switches_to_previous_after_switching_to_first_tab('g')) - it('switches to previous via g after switching to first tab', - switches_to_previous_after_switching_to_first_tab('g')) - it('switches to previous via after switching to first tab', - switches_to_previous_after_switching_to_first_tab('')) - it('switches to previous via :tabn # after switching to first tab', - switches_to_previous_after_switching_to_first_tab(':tabn #')) + it( + 'switches to previous via g after switching to first tab', + switches_to_previous_after_switching_to_first_tab('g') + ) + it( + 'switches to previous via g after switching to first tab', + switches_to_previous_after_switching_to_first_tab('g') + ) + it( + 'switches to previous via after switching to first tab', + switches_to_previous_after_switching_to_first_tab('') + ) + it( + 'switches to previous via :tabn # after switching to first tab', + switches_to_previous_after_switching_to_first_tab(':tabn #') + ) local function switches_to_previous_after_numbered_tab_switch(characters) return function() @@ -328,12 +385,13 @@ describe('tabpage/previous', function() command('tabnext 2') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -343,21 +401,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) end end - it('switches to previous via g after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('g')) - it('switches to previous via g after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('g')) - it('switches to previous via after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('')) - it('switches to previous via :tabn # after numbered tab switch', - switches_to_previous_after_numbered_tab_switch(':tabn #')) + it( + 'switches to previous via g after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('g') + ) + it( + 'switches to previous via g after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('g') + ) + it( + 'switches to previous via after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('') + ) + it( + 'switches to previous via :tabn # after numbered tab switch', + switches_to_previous_after_numbered_tab_switch(':tabn #') + ) local function switches_to_previous_after_switching_to_previous(characters1, characters2) return function() @@ -371,12 +437,13 @@ describe('tabpage/previous', function() feed(characters1) -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters2) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -386,45 +453,77 @@ describe('tabpage/previous', function() [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous via g after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', 'g')) - it('switches to previous via g after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', 'g')) - it('switches to previous via after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', '')) - it('switches to previous via :tabn # after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', ':tabn #')) - it('switches to previous via g after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', 'g')) - it('switches to previous via g after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', 'g')) - it('switches to previous via after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', '')) - it('switches to previous via :tabn # after switching to previous via g', - switches_to_previous_after_switching_to_previous('g', ':tabn #')) - it('switches to previous via g after switching to previous via ', - switches_to_previous_after_switching_to_previous('', 'g')) - it('switches to previous via g after switching to previous via ', - switches_to_previous_after_switching_to_previous('', 'g')) - it('switches to previous via after switching to previous via ', - switches_to_previous_after_switching_to_previous('', '')) - it('switches to previous via :tabn # after switching to previous via ', - switches_to_previous_after_switching_to_previous('', ':tabn #')) - it('switches to previous via g after switching to previous via :tabn #', - switches_to_previous_after_switching_to_previous(':tabn #', 'g')) - it('switches to previous via g after switching to previous via :tabn #', - switches_to_previous_after_switching_to_previous(':tabn #', 'g')) - it('switches to previous via after switching to previous via ', - switches_to_previous_after_switching_to_previous(':tabn #', '')) - it('switches to previous via :tabn # after switching to previous via :tabn #', - switches_to_previous_after_switching_to_previous(':tabn #', ':tabn #')) + it( + 'switches to previous via g after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', 'g') + ) + it( + 'switches to previous via g after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', 'g') + ) + it( + 'switches to previous via after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', '') + ) + it( + 'switches to previous via :tabn # after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', ':tabn #') + ) + it( + 'switches to previous via g after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', 'g') + ) + it( + 'switches to previous via g after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', 'g') + ) + it( + 'switches to previous via after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', '') + ) + it( + 'switches to previous via :tabn # after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', ':tabn #') + ) + it( + 'switches to previous via g after switching to previous via ', + switches_to_previous_after_switching_to_previous('', 'g') + ) + it( + 'switches to previous via g after switching to previous via ', + switches_to_previous_after_switching_to_previous('', 'g') + ) + it( + 'switches to previous via after switching to previous via ', + switches_to_previous_after_switching_to_previous('', '') + ) + it( + 'switches to previous via :tabn # after switching to previous via ', + switches_to_previous_after_switching_to_previous('', ':tabn #') + ) + it( + 'switches to previous via g after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', 'g') + ) + it( + 'switches to previous via g after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', 'g') + ) + it( + 'switches to previous via after switching to previous via ', + switches_to_previous_after_switching_to_previous(':tabn #', '') + ) + it( + 'switches to previous via :tabn # after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', ':tabn #') + ) local function does_not_switch_to_previous_after_closing_current_tab(characters) return function() @@ -436,13 +535,14 @@ describe('tabpage/previous', function() command('wincmd c') -- The previous tab is now the "zeroth" -- there isn't one. - eq(0, eval('tabpagenr(\'#\')')) + eq(0, eval("tabpagenr('#')")) -- At this point, switching to the "previous" (i.e. fourth) tab would mean -- switching to either a dangling or a null pointer. feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -450,21 +550,29 @@ describe('tabpage/previous', function() [No Name] Tab page 3 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the "zero". - eq(0, eval('tabpagenr(\'#\')')) + eq(0, eval("tabpagenr('#')")) end end - it('does not switch to previous via g after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('g')) - it('does not switch to previous via g after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('g')) - it('does not switch to previous via after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('')) - it('does not switch to previous via :tabn # after closing current tab', - does_not_switch_to_previous_after_closing_current_tab(':tabn #')) + it( + 'does not switch to previous via g after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('g') + ) + it( + 'does not switch to previous via g after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('g') + ) + it( + 'does not switch to previous via after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('') + ) + it( + 'does not switch to previous via :tabn # after closing current tab', + does_not_switch_to_previous_after_closing_current_tab(':tabn #') + ) local function does_not_switch_to_previous_after_entering_operator_pending(characters) return function() @@ -474,7 +582,7 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Enter operator pending mode. feed('d') @@ -491,11 +599,13 @@ describe('tabpage/previous', function() eq(4, eval('tabpagenr()')) -- The previous tab is still the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('does not switch to previous via g after entering operator pending', - does_not_switch_to_previous_after_entering_operator_pending('g')) + it( + 'does not switch to previous via g after entering operator pending', + does_not_switch_to_previous_after_entering_operator_pending('g') + ) -- NOTE: When in operator pending mode, attempting to switch to previous has -- the following effect: -- - Ctrl-W exits operator pending mode @@ -506,8 +616,10 @@ describe('tabpage/previous', function() -- be the same as the normal mode command to switch to the previous tab. -- it('does not switch to previous via g after entering operator pending', -- does_not_switch_to_previous_after_entering_operator_pending('g')) - it('does not switch to previous via after entering operator pending', - does_not_switch_to_previous_after_entering_operator_pending('')) + it( + 'does not switch to previous via after entering operator pending', + does_not_switch_to_previous_after_entering_operator_pending('') + ) -- NOTE: When in operator pending mode, pressing : leaves operator pending -- mode and enters command mode, so :tabn # does in fact switch -- tabs. @@ -522,7 +634,7 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Edit : command line in command-line window feed('q:') @@ -540,31 +652,34 @@ describe('tabpage/previous', function() eq(4, eval('tabpagenr()')) -- The previous tab is still the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('cmdline-win prevents tab switch via g', - cmdline_win_prevents_tab_switch('g', 0)) - it('cmdline-win prevents tab switch via g', - cmdline_win_prevents_tab_switch('g', 1)) - it('cmdline-win prevents tab switch via ', - cmdline_win_prevents_tab_switch('', 0)) - it('cmdline-win prevents tab switch via :tabn #', - cmdline_win_prevents_tab_switch(':tabn #', 0)) + it('cmdline-win prevents tab switch via g', cmdline_win_prevents_tab_switch('g', 0)) + it( + 'cmdline-win prevents tab switch via g', + cmdline_win_prevents_tab_switch('g', 1) + ) + it('cmdline-win prevents tab switch via ', cmdline_win_prevents_tab_switch('', 0)) + it( + 'cmdline-win prevents tab switch via :tabn #', + cmdline_win_prevents_tab_switch(':tabn #', 0) + ) it(':tabs indicates correct prevtab curwin', function() - -- Add three tabs for a total of four - command('tabnew') - command('tabnew') - command('split') - command('vsplit') - feed('p') - command('tabnew') + -- Add three tabs for a total of four + command('tabnew') + command('tabnew') + command('split') + command('vsplit') + feed('p') + command('tabnew') - -- The previous tab is now the three. - eq(3, eval('tabpagenr(\'#\')')) + -- The previous tab is now the three. + eq(3, eval("tabpagenr('#')")) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -576,7 +691,7 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') - ) + exec_capture('tabs') + ) end) end) diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 332a936e3f..71ae7dfe9b 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -2,10 +2,8 @@ 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 -local eval, eq, neq, retry = - helpers.eval, helpers.eq, helpers.neq, helpers.retry +local clear, command, nvim, testprg = helpers.clear, helpers.command, helpers.nvim, helpers.testprg +local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry local matches = helpers.matches local ok = helpers.ok local feed = helpers.feed @@ -27,8 +25,10 @@ describe('autocmd TermClose', function() 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://', - pcall_err(command, 'bdelete!')) + matches( + '^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://', + pcall_err(command, 'bdelete!') + ) assert_alive() end @@ -46,8 +46,12 @@ describe('autocmd TermClose', function() command('autocmd TermClose * let g:test_termclose = 23') command('terminal') -- shell-test exits immediately. - retry(nil, nil, function() neq(-1, eval('jobwait([&channel], 0)[0]')) end) - retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) + retry(nil, nil, function() + neq(-1, eval('jobwait([&channel], 0)[0]')) + end) + retry(nil, nil, function() + eq(23, eval('g:test_termclose')) + end) end) it('triggers when long-running terminal job gets stopped', function() @@ -56,48 +60,62 @@ describe('autocmd TermClose', function() command('autocmd TermClose * let g:test_termclose = 23') command('terminal') command('call jobstop(b:terminal_job_id)') - retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) + retry(nil, nil, function() + eq(23, eval('g:test_termclose')) + end) end) it('kills job trapping SIGTERM', function() skip(is_os('win')) 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')}}) ]]) - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end) + 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')}}) ]] + ) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_started", 0)')) + end) luv.update_time() local start = luv.now() command('call jobstop(g:test_job)') - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_exited", 0)')) + end) luv.update_time() local duration = luv.now() - start -- Nvim begins SIGTERM after KILL_TIMEOUT_MS. ok(duration >= 2000) - ok(duration <= 4000) -- Epsilon for slow CI + ok(duration <= 4000) -- Epsilon for slow CI end) it('kills PTY job trapping SIGHUP and SIGTERM', function() skip(is_os('win')) 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')}, ]] - .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]]) - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end) + command( + [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] + .. [[ 'pty': 1,]] + .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] + .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]] + ) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_started", 0)')) + end) luv.update_time() local start = luv.now() command('call jobstop(g:test_job)') - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_exited", 0)')) + end) luv.update_time() local duration = luv.now() - start -- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS). ok(duration >= 4000) - ok(duration <= 7000) -- Epsilon for slow CI + ok(duration <= 7000) -- Epsilon for slow CI end) it('reports the correct ', function() @@ -109,13 +127,19 @@ describe('autocmd TermClose', function() eq(2, eval('bufnr("%")')) command('terminal ls') - retry(nil, nil, function() eq(3, eval('bufnr("%")')) end) + retry(nil, nil, function() + eq(3, eval('bufnr("%")')) + end) command('buffer 1') - retry(nil, nil, function() eq(1, eval('bufnr("%")')) end) + retry(nil, nil, function() + eq(1, eval('bufnr("%")')) + end) command('3bdelete!') - retry(nil, nil, function() eq('3', eval('g:abuf')) end) + retry(nil, nil, function() + eq('3', eval('g:abuf')) + end) feed(':qa!') end) @@ -124,10 +148,14 @@ describe('autocmd TermClose', function() command('autocmd TermClose * let g:status = v:event.status') command('terminal 0') - retry(nil, nil, function() eq(0, eval('g:status')) end) + retry(nil, nil, function() + eq(0, eval('g:status')) + end) command('terminal 42') - retry(nil, nil, function() eq(42, eval('g:status')) end) + retry(nil, nil, function() + eq(42, eval('g:status')) + end) end) end) @@ -141,27 +169,30 @@ it('autocmd TermEnter, TermLeave', function() command('terminal') feed('i') - eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, }, eval('g:evs')) + eq({ { 'TermOpen', 'n' }, { 'TermEnter', 't' } }, eval('g:evs')) feed([[]]) feed('A') - eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, {'TermLeave', 'n'}, {'TermEnter', 't'}, }, eval('g:evs')) + eq( + { { 'TermOpen', 'n' }, { 'TermEnter', 't' }, { 'TermLeave', 'n' }, { 'TermEnter', 't' } }, + eval('g:evs') + ) -- TermLeave is also triggered by :quit. command('split foo') - feed('') -- Add input to separate two RPC requests + feed('') -- Add input to separate two RPC requests command('wincmd w') feed('i') command('q!') - feed('') -- Add input to separate two RPC requests + feed('') -- Add input to separate two RPC requests eq({ - {'TermOpen', 'n'}, - {'TermEnter', 't'}, - {'TermLeave', 'n'}, - {'TermEnter', 't'}, - {'TermLeave', 'n'}, - {'TermEnter', 't'}, - {'TermClose', 't'}, - {'TermLeave', 'n'}, + { 'TermOpen', 'n' }, + { 'TermEnter', 't' }, + { 'TermLeave', 'n' }, + { 'TermEnter', 't' }, + { 'TermLeave', 'n' }, + { 'TermEnter', 't' }, + { 'TermClose', 't' }, + { 'TermLeave', 'n' }, }, eval('g:evs')) end) @@ -172,13 +203,15 @@ describe('autocmd TextChangedT', function() 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) + retry(nil, nil, function() + eq(1, meths.get_var('called')) + end) end) it('cannot delete terminal buffer', function() command([[autocmd TextChangedT * call nvim_input('') | bwipe!]]) thelpers.feed_data('a') - screen:expect({any = 'E937: '}) + 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 index b621eb36bf..850d67a18d 100644 --- a/test/functional/autocmd/textchanged_spec.lua +++ b/test/functional/autocmd/textchanged_spec.lua @@ -88,7 +88,7 @@ it('TextChangedI and TextChangedP autocommands', function() eq('IIPPPP', eval('g:autocmd')) feed('') - eq({'foo', 'bar', 'foobar', 'foo'}, eval('getline(1, "$")')) + eq({ 'foo', 'bar', 'foobar', 'foo' }, eval('getline(1, "$")')) end) -- oldtest: Test_TextChangedI_with_setline() @@ -172,11 +172,11 @@ it('TextChangedI and TextChanged', function() eq('', eval('g:autocmd_n')) end - validate_mixed_textchangedi({'o', ''}) - validate_mixed_textchangedi({'O', ''}) - validate_mixed_textchangedi({'ciw', ''}) - validate_mixed_textchangedi({'cc', ''}) - validate_mixed_textchangedi({'C', ''}) - validate_mixed_textchangedi({'s', ''}) - validate_mixed_textchangedi({'S', ''}) + validate_mixed_textchangedi({ 'o', '' }) + validate_mixed_textchangedi({ 'O', '' }) + validate_mixed_textchangedi({ 'ciw', '' }) + validate_mixed_textchangedi({ 'cc', '' }) + validate_mixed_textchangedi({ 'C', '' }) + validate_mixed_textchangedi({ 's', '' }) + validate_mixed_textchangedi({ 'S', '' }) end) diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index 1640916ad8..4250c54834 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -28,7 +28,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -42,7 +42,7 @@ describe('TextYankPost', function() regcontents = { 'baz ' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -52,8 +52,8 @@ describe('TextYankPost', function() operator = 'y', regcontents = { 'foo', 'baz' }, regname = '', - regtype = "\0223", -- ^V + block width - visual = true + regtype = '\0223', -- ^V + block width + visual = true, }, eval('g:event')) eq(3, eval('g:count')) end) @@ -66,25 +66,25 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) command('set debug=msg') -- the regcontents should not be changed without copy. - local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])') - eq(status,false) + local status, err = pcall(command, 'call extend(g:event.regcontents, ["more text"])') + eq(status, false) neq(nil, string.find(err, ':E742:')) -- can't mutate keys inside the autocommand command('autocmd! TextYankPost * let v:event.regcontents = 0') - status, err = pcall(command,'normal yy') - eq(status,false) + status, err = pcall(command, 'normal yy') + eq(status, false) neq(nil, string.find(err, ':E46:')) -- can't add keys inside the autocommand command('autocmd! TextYankPost * let v:event.mykey = 0') - status, err = pcall(command,'normal yy') - eq(status,false) + status, err = pcall(command, 'normal yy') + eq(status, false) neq(nil, string.find(err, ':E742:')) end) @@ -97,10 +97,10 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) - eq({ 'foo\nbar' }, funcs.getreg('+',1,1)) + eq({ 'foo\nbar' }, funcs.getreg('+', 1, 1)) end) it('is executed after delete and change', function() @@ -111,7 +111,7 @@ describe('TextYankPost', function() regcontents = { 'foo' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -122,7 +122,7 @@ describe('TextYankPost', function() regcontents = { '\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -133,7 +133,7 @@ describe('TextYankPost', function() regcontents = { 'baz' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(3, eval('g:count')) end) @@ -162,7 +162,7 @@ describe('TextYankPost', function() regcontents = { 'bar' }, regname = 'b', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) feed('"*yy') @@ -172,10 +172,10 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '*', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) - command("set clipboard=unnamed") + command('set clipboard=unnamed') -- regname still shows the name the user requested feed('yy') @@ -185,7 +185,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) feed('"*yy') @@ -195,7 +195,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '*', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) end) @@ -207,7 +207,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '+', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -218,7 +218,7 @@ describe('TextYankPost', function() regcontents = { 'baz text' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -229,7 +229,7 @@ describe('TextYankPost', function() regcontents = { 'baz ' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(3, eval('g:count')) @@ -240,7 +240,7 @@ describe('TextYankPost', function() regcontents = { 'baz text' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(4, eval('g:count')) end) diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua index e6fdd9560d..6f61ad7902 100644 --- a/test/functional/autocmd/win_scrolled_resized_spec.lua +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -32,12 +32,12 @@ describe('WinResized', function() -- increase window height, two windows will be reported feed('+') eq(1, eval('g:resized')) - eq({windows = {1002, 1001}}, eval('g:v_event')) + eq({ windows = { 1002, 1001 } }, eval('g:v_event')) -- increase window width, three windows will be reported feed('>') eq(2, eval('g:resized')) - eq({windows = {1002, 1001, 1000}}, eval('g:v_event')) + eq({ windows = { 1002, 1001, 1000 } }, eval('g:v_event')) end) end) @@ -63,22 +63,22 @@ describe('WinScrolled', function() end) it('is triggered by scrolling vertically', function() - local lines = {'123', '123'} + local lines = { '123', '123' } meths.buf_set_lines(0, 0, -1, true, lines) eq(0, eval('g:scrolled')) feed('') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) @@ -86,58 +86,58 @@ describe('WinScrolled', function() command('set nowrap') local width = meths.win_get_width(0) local line = '123' .. ('*'):rep(width * 2) - local lines = {line, line} + local lines = { line, line } meths.buf_set_lines(0, 0, -1, true, lines) eq(0, eval('g:scrolled')) feed('zl') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('zh') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) it('is triggered by horizontal scrolling from cursor move', function() command('set nowrap') - local lines = {'', '', 'Foo'} + local lines = { '', '', 'Foo' } meths.buf_set_lines(0, 0, -1, true, lines) - meths.win_set_cursor(0, {3, 0}) + meths.win_set_cursor(0, { 3, 0 }) eq(0, eval('g:scrolled')) feed('zl') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('zl') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('h') eq(3, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('zh') eq(4, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) @@ -145,22 +145,22 @@ describe('WinScrolled', function() it('is triggered by scrolling on a long wrapped line #19968', function() local height = meths.win_get_height(0) local width = meths.win_get_width(0) - meths.buf_set_lines(0, 0, -1, true, {('foo'):rep(height * width)}) - meths.win_set_cursor(0, {1, height * width - 1}) + meths.buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) }) + meths.win_set_cursor(0, { 1, height * width - 1 }) eq(0, eval('g:scrolled')) feed('gj') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, - ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, + all = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width }, + ['1000'] = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width }, }, eval('g:v_event')) feed('0') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, - ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = -width}, + all = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width }, + ['1000'] = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = -width }, }, eval('g:v_event')) feed('$') @@ -181,15 +181,15 @@ describe('WinScrolled', function() feed('i') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('i') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('L') @@ -198,8 +198,8 @@ describe('WinScrolled', function() feed('A') eq(3, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) end) @@ -257,30 +257,30 @@ describe('WinScrolled', function() feed('') eq({ - all = {leftcol = 0, topline = 1, topfill = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1001'] = {leftcol = 0, topline = 0, topfill = -1, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 1, topfill = 1, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1001'] = { leftcol = 0, topline = 0, topfill = -1, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('2') eq({ - all = {leftcol = 0, topline = 2, topfill = 2, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1001'] = {leftcol = 0, topline = 0, topfill = -2, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 2, topfill = 2, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1001'] = { leftcol = 0, topline = 0, topfill = -2, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('') eq({ - all = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1001'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1001'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) feed('2') eq({ - all = {leftcol = 0, topline = 3, topfill = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = -2, topfill = 0, width = 0, height = 0, skipcol = 0}, - ['1001'] = {leftcol = 0, topline = -1, topfill = 1, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 3, topfill = 1, width = 0, height = 0, skipcol = 0 }, + ['1000'] = { leftcol = 0, topline = -2, topfill = 0, width = 0, height = 0, skipcol = 0 }, + ['1001'] = { leftcol = 0, topline = -1, topfill = 1, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) @@ -297,14 +297,20 @@ describe('WinScrolled', function() eq(0, eval('g:scrolled')) local buf = meths.create_buf(true, true) - meths.buf_set_lines(buf, 0, -1, false, {'@', '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, col = 0, row = 1, relative = 'editor', - style = 'minimal' + style = 'minimal', }) screen:expect({ any = '@' }) local winid_str = tostring(win.id) @@ -315,16 +321,16 @@ describe('WinScrolled', function() eq(1, eval('g:scrolled')) eq(winid_str, eval('g:amatch')) eq({ - all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, - [winid_str] = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 }, + [winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) meths.input_mouse('wheel', 'up', '', 0, 3, 3) eq(2, eval('g:scrolled')) eq(tostring(win.id), eval('g:amatch')) eq({ - all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, - [winid_str] = {leftcol = 0, topline = -3, topfill = 0, width = 0, height = 0, skipcol = 0}, + all = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 }, + [winid_str] = { leftcol = 0, topline = -3, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) end) end) diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 5771ddcb94..0b58e8bc54 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, - helpers.eval, helpers.next_msg, helpers.ok, helpers.source +local clear, eq, eval, next_msg, ok, source = + helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths local sleep = helpers.sleep local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv @@ -40,7 +40,7 @@ describe('channels', function() meths.set_var('address', address) command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})") - local id = eval("g:id") + local id = eval('g:id') ok(id > 0) command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))") @@ -52,12 +52,11 @@ describe('channels', function() command("call chansend(g:id, msgpackdump([[0,0,'nvim_eval',['2+3']]]))") - - local res = eval("msgpackdump([[1,0,v:null,5]])") - eq({"\148\001\n\192\005"}, res) - eq({'notification', 'data', {id, res}}, next_msg()) + local res = eval('msgpackdump([[1,0,v:null,5]])') + eq({ '\148\001\n\192\005' }, res) + eq({ 'notification', 'data', { id, res } }, next_msg()) command("call chansend(g:id, msgpackdump([[2,'nvim_command',['quit']]]))") - eq({'notification', 'data', {id, {''}}}, next_msg()) + eq({ 'notification', 'data', { id, { '' } } }, next_msg()) end) it('can use stdio channel', function() @@ -68,8 +67,10 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var("nvim_prog", nvim_prog) - meths.set_var("code", [[ + meths.set_var('nvim_prog', nvim_prog) + meths.set_var( + 'code', + [[ function! OnEvent(id, data, event) dict let text = string([a:id, a:data, a:event]) call chansend(g:x, text) @@ -81,25 +82,31 @@ describe('channels', function() endfunction let g:x = stdioopen({'on_stdin':'OnEvent'}) call chansend(x, "hello") - ]]) - command("let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)") - local id = eval("g:id") + ]] + ) + command( + "let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)" + ) + local id = eval('g:id') ok(id > 0) - eq({ "notification", "stdout", {id, { "hello" } } }, next_msg()) + eq({ 'notification', 'stdout', { id, { 'hello' } } }, next_msg()) command("call chansend(id, 'howdy')") - eq({"notification", "stdout", {id, {"[1, ['howdy'], 'stdin']"}}}, next_msg()) + eq({ 'notification', 'stdout', { id, { "[1, ['howdy'], 'stdin']" } } }, next_msg()) - command("call chansend(id, 0z686f6c61)") - eq({"notification", "stdout", {id, {"[1, ['hola'], 'stdin']"}}}, next_msg()) + command('call chansend(id, 0z686f6c61)') + eq({ 'notification', 'stdout', { id, { "[1, ['hola'], 'stdin']" } } }, next_msg()) command("call chanclose(id, 'stdin')") - expect_twostreams({{"notification", "stdout", {id, {"[1, [''], 'stdin']"}}}, - {'notification', 'stdout', {id, {''}}}}, - {{"notification", "stderr", {id, {"*dies*"}}}, - {'notification', 'stderr', {id, {''}}}}) - eq({"notification", "exit", {3,0}}, next_msg()) + expect_twostreams({ + { 'notification', 'stdout', { id, { "[1, [''], 'stdin']" } } }, + { 'notification', 'stdout', { id, { '' } } }, + }, { + { 'notification', 'stderr', { id, { '*dies*' } } }, + { 'notification', 'stderr', { id, { '' } } }, + }) + eq({ 'notification', 'exit', { 3, 0 } }, next_msg()) end) it('can use stdio channel and on_print callback', function() @@ -110,8 +117,10 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var("nvim_prog", nvim_prog) - meths.set_var("code", [[ + meths.set_var('nvim_prog', nvim_prog) + meths.set_var( + 'code', + [[ function! OnStdin(id, data, event) dict echo string([a:id, a:data, a:event]) if a:data == [''] @@ -123,24 +132,27 @@ describe('channels', function() endfunction let g:x = stdioopen({'on_stdin': funcref('OnStdin'), 'on_print':'OnPrint'}) call chansend(x, "hello") - ]]) - command("let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)") - local id = eval("g:id") + ]] + ) + command( + "let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)" + ) + local id = eval('g:id') ok(id > 0) - eq({ "notification", "stdout", {id, { "hello" } } }, next_msg()) + eq({ 'notification', 'stdout', { id, { 'hello' } } }, next_msg()) command("call chansend(id, 'howdy')") - eq({"notification", "stdout", {id, {"OnPrint:[1, ['howdy'], 'stdin']"}}}, next_msg()) + eq({ 'notification', 'stdout', { id, { "OnPrint:[1, ['howdy'], 'stdin']" } } }, next_msg()) end) local function expect_twoline(id, stream, line1, line2, nobr) local msg = next_msg() - local joined = nobr and {line1..line2} or {line1, line2} - if not pcall(eq, {"notification", stream, {id, joined}}, msg) then - local sep = (not nobr) and "" or nil - eq({"notification", stream, {id, {line1, sep}}}, msg) - eq({"notification", stream, {id, {line2}}}, next_msg()) + local joined = nobr and { line1 .. line2 } or { line1, line2 } + if not pcall(eq, { 'notification', stream, { id, joined } }, msg) then + local sep = (not nobr) and '' or nil + eq({ 'notification', stream, { id, { line1, sep } } }, msg) + eq({ 'notification', stream, { id, { line2 } } }, next_msg()) end end @@ -153,50 +165,52 @@ describe('channels', function() \ 'pty': v:true, \ } ]]) - meths.set_var("nvim_prog", nvim_prog) - meths.set_var("code", [[ + meths.set_var('nvim_prog', nvim_prog) + meths.set_var( + 'code', + [[ function! OnEvent(id, data, event) dict let text = string([a:id, a:data, a:event]) call chansend(g:x, text) endfunction let g:x = stdioopen({'on_stdin':'OnEvent'}) - ]]) - command("let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)") - local id = eval("g:id") + ]] + ) + command( + "let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)" + ) + local id = eval('g:id') ok(id > 0) command("call chansend(id, 'TEXT\n')") - expect_twoline(id, "stdout", "TEXT\r", "[1, ['TEXT', ''], 'stdin']") + expect_twoline(id, 'stdout', 'TEXT\r', "[1, ['TEXT', ''], 'stdin']") - command("call chansend(id, 0z426c6f6273210a)") - expect_twoline(id, "stdout", "Blobs!\r", "[1, ['Blobs!', ''], 'stdin']") + command('call chansend(id, 0z426c6f6273210a)') + expect_twoline(id, 'stdout', 'Blobs!\r', "[1, ['Blobs!', ''], 'stdin']") command("call chansend(id, 'neovan')") - eq({"notification", "stdout", {id, {"neovan"}}}, next_msg()) + eq({ 'notification', 'stdout', { id, { 'neovan' } } }, next_msg()) command("call chansend(id, '\127\127im\n')") - expect_twoline(id, "stdout", "\b \b\b \bim\r", "[1, ['neovim', ''], 'stdin']") + expect_twoline(id, 'stdout', '\b \b\b \bim\r', "[1, ['neovim', ''], 'stdin']") command("call chansend(id, 'incomplet\004')") local bsdlike = is_os('bsd') or is_os('mac') - local extra = bsdlike and "^D\008\008" or "" - expect_twoline(id, "stdout", - "incomplet"..extra, "[1, ['incomplet'], 'stdin']", true) - + local extra = bsdlike and '^D\008\008' or '' + expect_twoline(id, 'stdout', 'incomplet' .. extra, "[1, ['incomplet'], 'stdin']", true) command("call chansend(id, '\004')") if bsdlike then - expect_twoline(id, "stdout", extra, "[1, [''], 'stdin']", true) + expect_twoline(id, 'stdout', extra, "[1, [''], 'stdin']", true) else - eq({"notification", "stdout", {id, {"[1, [''], 'stdin']"}}}, next_msg()) + eq({ 'notification', 'stdout', { id, { "[1, [''], 'stdin']" } } }, next_msg()) end -- channel is still open command("call chansend(id, 'hi again!\n')") - eq({"notification", "stdout", {id, {"hi again!\r", ""}}}, next_msg()) + eq({ 'notification', 'stdout', { id, { 'hi again!\r', '' } } }, next_msg()) end) - it('stdio channel can use rpc and stderr simultaneously', function() skip(is_os('win')) source([[ @@ -206,27 +220,33 @@ describe('channels', function() \ 'rpc': v:true, \ } ]]) - meths.set_var("nvim_prog", nvim_prog) - meths.set_var("code", [[ + meths.set_var('nvim_prog', nvim_prog) + meths.set_var( + 'code', + [[ let id = stdioopen({'rpc':v:true}) call rpcnotify(id,"nvim_call_function", "rpcnotify", [1, "message", "hi there!", id]) call chansend(v:stderr, "trouble!") - ]]) - command("let id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)") - eq({"notification", "message", {"hi there!", 1}}, next_msg()) - eq({"notification", "stderr", {3, {"trouble!"}}}, next_msg()) + ]] + ) + command( + "let id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)" + ) + eq({ 'notification', 'message', { 'hi there!', 1 } }, next_msg()) + eq({ 'notification', 'stderr', { 3, { 'trouble!' } } }, next_msg()) eq(30, eval("rpcrequest(id, 'nvim_eval', '[chansend(v:stderr, \"math??\"), 5*6][1]')")) - eq({"notification", "stderr", {3, {"math??"}}}, next_msg()) + eq({ 'notification', 'stderr', { 3, { 'math??' } } }, next_msg()) - local _, err = pcall(command,"call rpcrequest(id, 'nvim_command', 'call chanclose(v:stderr, \"stdin\")')") - ok(string.find(err,"E906: invalid stream for channel") ~= nil) + local _, err = + pcall(command, "call rpcrequest(id, 'nvim_command', 'call chanclose(v:stderr, \"stdin\")')") + ok(string.find(err, 'E906: invalid stream for channel') ~= nil) eq(1, eval("rpcrequest(id, 'nvim_eval', 'chanclose(v:stderr, \"stderr\")')")) - eq({"notification", "stderr", {3, {""}}}, next_msg()) + eq({ 'notification', 'stderr', { 3, { '' } } }, next_msg()) command("call rpcnotify(id, 'nvim_command', 'quit')") - eq({"notification", "exit", {3, 0}}, next_msg()) + eq({ 'notification', 'exit', { 3, 0 } }, next_msg()) end) it('can use buffered output mode', function() @@ -239,27 +259,29 @@ describe('channels', function() \ } ]]) command("let id = jobstart(['grep', '^[0-9]'], g:job_opts)") - local id = eval("g:id") + local id = eval('g:id') command([[call chansend(id, "stuff\n10 PRINT \"NVIM\"\nxx")]]) sleep(10) command([[call chansend(id, "xx\n20 GOTO 10\nzz\n")]]) command("call chanclose(id, 'stdin')") - eq({"notification", "stdout", {id, {'10 PRINT "NVIM"', - '20 GOTO 10', ''}}}, next_msg()) - eq({"notification", "exit", {id, 0}}, next_msg()) + eq({ + 'notification', + 'stdout', + { id, { '10 PRINT "NVIM"', '20 GOTO 10', '' } }, + }, next_msg()) + eq({ 'notification', 'exit', { id, 0 } }, next_msg()) command("let id = jobstart(['grep', '^[0-9]'], g:job_opts)") - id = eval("g:id") + id = eval('g:id') command([[call chansend(id, "is no number\nnot at all")]]) command("call chanclose(id, 'stdin')") -- works correctly with no output - eq({"notification", "stdout", {id, {''}}}, next_msg()) - eq({"notification", "exit", {id, 1}}, next_msg()) - + eq({ 'notification', 'stdout', { id, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { id, 1 } }, next_msg()) end) it('can use buffered output mode with no stream callback', function() @@ -274,31 +296,40 @@ describe('channels', function() \ } ]]) command("let id = jobstart(['grep', '^[0-9]'], g:job_opts)") - local id = eval("g:id") + local id = eval('g:id') command([[call chansend(id, "stuff\n10 PRINT \"NVIM\"\nxx")]]) sleep(10) command([[call chansend(id, "xx\n20 GOTO 10\nzz\n")]]) command("call chanclose(id, 'stdin')") - eq({"notification", "exit", {id, 0, {'10 PRINT "NVIM"', - '20 GOTO 10', ''}}}, next_msg()) + eq({ + 'notification', + 'exit', + { id, 0, { '10 PRINT "NVIM"', '20 GOTO 10', '' } }, + }, next_msg()) -- if dict is reused the new value is not stored, -- but nvim also does not crash command("let id = jobstart(['cat'], g:job_opts)") - id = eval("g:id") + id = eval('g:id') command([[call chansend(id, "cat text\n")]]) sleep(10) command("call chanclose(id, 'stdin')") -- old value was not overwritten - eq({"notification", "exit", {id, 0, {'10 PRINT "NVIM"', - '20 GOTO 10', ''}}}, next_msg()) + eq({ + 'notification', + 'exit', + { id, 0, { '10 PRINT "NVIM"', '20 GOTO 10', '' } }, + }, next_msg()) -- and an error was thrown. - eq("E5210: dict key 'stdout' already set for buffered stream in channel "..id, eval('v:errmsg')) + eq( + "E5210: dict key 'stdout' already set for buffered stream in channel " .. id, + eval('v:errmsg') + ) -- reset dictionary source([[ @@ -308,13 +339,13 @@ describe('channels', function() \ } ]]) command("let id = jobstart(['grep', '^[0-9]'], g:job_opts)") - id = eval("g:id") + id = eval('g:id') command([[call chansend(id, "is no number\nnot at all")]]) command("call chanclose(id, 'stdin')") -- works correctly with no output - eq({"notification", "exit", {id, 1, {''}}}, next_msg()) + eq({ 'notification', 'exit', { id, 1, { '' } } }, next_msg()) end) end) @@ -325,8 +356,10 @@ describe('loopback', function() end) it('does not crash when sending raw data', function() - eq("Vim(call):Can't send raw data to rpc channel", - pcall_err(command, "call chansend(chan, 'test')")) + eq( + "Vim(call):Can't send raw data to rpc channel", + pcall_err(command, "call chansend(chan, 'test')") + ) assert_alive() end) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index d474b77806..2c3ebf62aa 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -27,8 +27,8 @@ describe('v:exiting', function() local function test_exiting(setup_fn) local function on_setup() - command('autocmd VimLeavePre * call rpcrequest('..cid..', "exit", "VimLeavePre")') - command('autocmd VimLeave * call rpcrequest('..cid..', "exit", "VimLeave")') + command('autocmd VimLeavePre * call rpcrequest(' .. cid .. ', "exit", "VimLeavePre")') + command('autocmd VimLeave * call rpcrequest(' .. cid .. ', "exit", "VimLeave")') setup_fn() end local requests_args = {} @@ -39,7 +39,7 @@ describe('v:exiting', function() return '' end run(on_request, nil, on_setup) - eq({{'VimLeavePre'}, {'VimLeave'}}, requests_args) + eq({ { 'VimLeavePre' }, { 'VimLeave' } }, requests_args) end it('is 0 on normal exit', function() @@ -59,11 +59,16 @@ end) describe(':cquit', function() local function test_cq(cmdline, exit_code, redir_msg) if redir_msg then - eq(redir_msg, pcall_err(function() return exec_capture(cmdline) end)) + eq( + redir_msg, + pcall_err(function() + return exec_capture(cmdline) + end) + ) poke_eventloop() assert_alive() else - funcs.system({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline}) + funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) eq(exit_code, eval('v:shell_error')) end end diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 5ae468e560..1b9a97648c 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -34,8 +34,7 @@ local spawn = helpers.spawn local set_session = helpers.set_session describe('fileio', function() - before_each(function() - end) + before_each(function() end) after_each(function() check_close() os.remove('Xtest_startup_shada') @@ -51,25 +50,25 @@ describe('fileio', function() rmdir('Xtest_backupdir with spaces') end) - local args = { nvim_prog, '--clean', '--cmd', 'set nofsync directory=Xtest_startup_swapdir', } + local args = { nvim_prog, '--clean', '--cmd', 'set nofsync directory=Xtest_startup_swapdir' } --- Starts a new nvim session and returns an attached screen. local function startup(extra_args) extra_args = extra_args or {} - local argv = vim.tbl_flatten({args, '--embed', extra_args}) + local argv = vim.tbl_flatten({ args, '--embed', extra_args }) local screen_nvim = spawn(argv) set_session(screen_nvim) local screen = Screen.new(70, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {foreground = Screen.colors.NvimDarkGrey4}; - [2] = {background = Screen.colors.NvimDarkGrey1, foreground = Screen.colors.NvimLightGrey3}; - [3] = {foreground = Screen.colors.NvimLightCyan}; + [1] = { foreground = Screen.colors.NvimDarkGrey4 }, + [2] = { background = Screen.colors.NvimDarkGrey1, foreground = Screen.colors.NvimLightGrey3 }, + [3] = { foreground = Screen.colors.NvimLightCyan }, }) return screen end it("fsync() with 'nofsync' #8304", function() - clear({ args={ '--cmd', 'set nofsync directory=Xtest_startup_swapdir', } }) + clear({ args = { '--cmd', 'set nofsync directory=Xtest_startup_swapdir' } }) -- These cases ALWAYS force fsync (regardless of 'fsync' option): @@ -80,8 +79,8 @@ describe('fileio', function() eq(0, request('nvim__stats').fsync) command('set swapfile') command('set updatetime=1') - feed('Azubh') -- File is 'modified'. - sleep(3) -- Allow 'updatetime' to expire. + feed('Azubh') -- File is 'modified'. + sleep(3) -- Allow 'updatetime' to expire. retry(3, nil, function() eq(1, request('nvim__stats').fsync) end) @@ -101,21 +100,26 @@ describe('fileio', function() eq('foozubbaz', trim(read_file('Xtest_startup_file1'))) -- 4. Exit caused by deadly signal (+ 'swapfile'). - local j = funcs.jobstart(vim.tbl_flatten({args, '--embed'}), {rpc=true}) - funcs.rpcrequest(j, 'nvim_exec2', [[ + local j = funcs.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) + funcs.rpcrequest( + j, + 'nvim_exec2', + [[ set nofsync directory=Xtest_startup_swapdir edit Xtest_startup_file2 write put ='fsyncd text' - ]], {}) + ]], + {} + ) eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory')) - funcs.jobstop(j) -- Send deadly signal. + funcs.jobstop(j) -- Send deadly signal. local screen = startup() feed(':recover Xtest_startup_file2') - screen:expect({any = [[Using swap file "Xtest_startup_swapdir[/\]Xtest_startup_file2%.swp"]]}) + screen:expect({ any = [[Using swap file "Xtest_startup_swapdir[/\]Xtest_startup_file2%.swp"]] }) feed('') - screen:expect({any = 'fsyncd text'}) + screen:expect({ any = 'fsyncd text' }) -- 5. SIGPWR signal. -- oldtest: Test_signal_PWR() @@ -123,8 +127,14 @@ describe('fileio', function() it('backup #9709', function() skip(is_ci('cirrus')) - clear({ args={ '-i', 'Xtest_startup_shada', - '--cmd', 'set directory=Xtest_startup_swapdir' } }) + clear({ + args = { + '-i', + 'Xtest_startup_shada', + '--cmd', + 'set directory=Xtest_startup_swapdir', + }, + }) command('write Xtest_startup_file1') feed('ifoo') @@ -137,8 +147,8 @@ describe('fileio', function() local foobar_contents = trim(read_file('Xtest_startup_file1')) local bar_contents = trim(read_file('Xtest_startup_file1~')) - eq('foobar', foobar_contents); - eq('foo', bar_contents); + eq('foobar', foobar_contents) + eq('foo', bar_contents) end) it('backup with full path #11214', function() @@ -154,13 +164,16 @@ describe('fileio', function() 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/'..backup_file_name)) + local backup_file_name = string.gsub( + currentdir() .. '/Xtest_startup_file1', + is_os('win') and '[:/\\]' or '/', + '%%' + ) .. '~' + local foo_contents = trim(read_file('Xtest_backupdir/' .. backup_file_name)) local foobar_contents = trim(read_file('Xtest_startup_file1')) - eq('foobar', foobar_contents); - eq('foo', foo_contents); + eq('foobar', foobar_contents) + eq('foo', foo_contents) end) it('backup with full path with spaces', function() @@ -176,13 +189,16 @@ describe('fileio', function() 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 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); + eq('foobar', foobar_contents) + eq('foo', foo_contents) end) it('backup symlinked files #11349', function() @@ -202,11 +218,10 @@ describe('fileio', function() command('write') local backup_raw = read_file(backup_file_name) - neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. "to exist but did not") + neq(nil, backup_raw, 'Expected backup file ' .. backup_file_name .. 'to exist but did not') eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') end) - it('backup symlinked files in first available backupdir #11349', function() skip(is_ci('cirrus')) clear() @@ -228,7 +243,7 @@ describe('fileio', function() command('write') local backup_raw = read_file(backup_file_name) - neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. " to exist but did not") + neq(nil, backup_raw, 'Expected backup file ' .. backup_file_name .. ' to exist but did not') eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') end) @@ -247,7 +262,7 @@ describe('fileio', function() table.insert(text, '') eq(text, funcs.readfile(fname, 'b')) end) - it('read invalid u8 over INT_MAX doesn\'t segfault', function() + it("read invalid u8 over INT_MAX doesn't segfault", function() clear() command('call writefile(0zFFFFFFFF, "Xtest-u8-int-max")') -- This should not segfault @@ -257,18 +272,18 @@ describe('fileio', function() it(':w! does not show "file has been changed" warning', function() clear() - write_file("Xtest-overwrite-forced", 'foobar') + write_file('Xtest-overwrite-forced', 'foobar') command('set nofixendofline') - local screen = Screen.new(40,4) + local screen = Screen.new(40, 4) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4} + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) screen:attach() - command("set shortmess-=F") + command('set shortmess-=F') - command("e Xtest-overwrite-forced") + command('e Xtest-overwrite-forced') screen:expect([[ ^foobar | {1:~ }|*2 @@ -276,14 +291,14 @@ describe('fileio', function() ]]) -- Get current unix time. - local cur_unix_time = os.time(os.date("!*t")) + local cur_unix_time = os.time(os.date('!*t')) local future_time = cur_unix_time + 999999 -- Set the file's access/update time to be -- greater than the time at which it was created. - local uv = require("luv") + local uv = require('luv') uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) -- use async feed_command because nvim basically hangs on the prompt - feed_command("w") + feed_command('w') screen:expect([[ {2:WARNING: The file has been changed since}| {2: reading it!!!} | @@ -291,15 +306,15 @@ describe('fileio', function() ^ | ]]) - feed("n") - feed("") + feed('n') + feed('') screen:expect([[ ^foobar | {1:~ }|*2 | ]]) -- Use a screen test because the warning does not set v:errmsg. - command("w!") + command('w!') screen:expect([[ ^foobar | {1:~ }|*2 @@ -333,7 +348,7 @@ describe('tmpdir', function() end it('failure modes', function() - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) + clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) assert_nolog('tempdir is not a directory', testlog) assert_nolog('tempdir has invalid permissions', testlog) @@ -344,9 +359,9 @@ describe('tmpdir', function() -- "…/nvim./" is not a directory: expect_exit(command, ':qall!') rmdir(tmproot) - write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. + 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) @@ -355,9 +370,9 @@ describe('tmpdir', function() os.remove(testlog) os.remove(tmproot) mkdir(tmproot) - funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. + 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) @@ -365,14 +380,14 @@ describe('tmpdir', function() it('too long', function() 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(). + 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, } }) + clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) assert_nolog('tempdir disappeared', testlog) local function rm_tmpdir() @@ -406,12 +421,13 @@ describe('tmpdir', function() end) it('$NVIM_APPNAME relative path', function() - clear({ env={ - NVIM_APPNAME='a/b', - NVIM_LOG_FILE=testlog, - TMPDIR=os_tmpdir, - } }) + 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 b59a4ca746..9c82d0bc7c 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,11 +1,22 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim, - testprg, ok, source, write_file, mkdir, rmdir = helpers.clear, - helpers.eq, helpers.eval, helpers.exc_exec, helpers.feed_command, helpers.feed, - helpers.insert, helpers.neq, helpers.next_msg, helpers.nvim, - helpers.testprg, helpers.ok, helpers.source, - helpers.write_file, helpers.mkdir, helpers.rmdir +local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim, testprg, ok, source, write_file, mkdir, rmdir = + helpers.clear, + helpers.eq, + helpers.eval, + helpers.exc_exec, + helpers.feed_command, + helpers.feed, + helpers.insert, + helpers.neq, + helpers.next_msg, + helpers.nvim, + helpers.testprg, + helpers.ok, + helpers.source, + helpers.write_file, + helpers.mkdir, + helpers.rmdir local assert_alive = helpers.assert_alive local command = helpers.command local funcs = helpers.funcs @@ -55,7 +66,7 @@ describe('jobs', function() end) it('must specify env option as a dict', function() - command("let g:job_opts.env = v:true") + command('let g:job_opts.env = v:true') local _, err = pcall(function() if is_os('win') then nvim('command', "let j = jobstart('set', g:job_opts)") @@ -63,7 +74,7 @@ describe('jobs', function() nvim('command', "let j = jobstart('env', g:job_opts)") end end) - ok(string.find(err, "E475: Invalid argument: env") ~= nil) + ok(string.find(err, 'E475: Invalid argument: env') ~= nil) end) it('append environment #env', function() @@ -76,45 +87,39 @@ describe('jobs', function() nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end - expect_msg_seq( - { - {'notification', 'stdout', {0, {'hello world abc'}}}, - {'notification', 'stdout', {0, {'', ''}}}, - }, - { - {'notification', 'stdout', {0, {'hello world abc', ''}}}, - {'notification', 'stdout', {0, {''}}} - } - ) + expect_msg_seq({ + { 'notification', 'stdout', { 0, { 'hello world abc' } } }, + { 'notification', 'stdout', { 0, { '', '' } } }, + }, { + { 'notification', 'stdout', { 0, { 'hello world abc', '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + }) end) it('append environment with pty #env', function() nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.pty = v:true") + nvim('command', 'let g:job_opts.pty = v:true') nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end - expect_msg_seq( - { - {'notification', 'stdout', {0, {'hello world abc'}}}, - {'notification', 'stdout', {0, {'', ''}}}, - }, - { - {'notification', 'stdout', {0, {'hello world abc', ''}}}, - {'notification', 'stdout', {0, {''}}} - } - ) + expect_msg_seq({ + { 'notification', 'stdout', { 0, { 'hello world abc' } } }, + { 'notification', 'stdout', { 0, { '', '' } } }, + }, { + { 'notification', 'stdout', { 0, { 'hello world abc', '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + }) end) it('replace environment #env', function() nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - nvim('command', "let g:job_opts.clear_env = 1") + nvim('command', 'let g:job_opts.clear_env = 1') -- libuv ensures that certain "required" environment variables are -- preserved if the user doesn't provide them in a custom environment @@ -126,13 +131,13 @@ describe('jobs', function() if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ - {'notification', 'stdout', {0, {'hello world %VAR%', ''}}} + { 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } }, }) else - nvim('command', "set shell=/bin/sh") + nvim('command', 'set shell=/bin/sh') nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) expect_msg_seq({ - {'notification', 'stdout', {0, {'hello world', ''}}} + { 'notification', 'stdout', { 0, { 'hello world', '' } } }, }) end end) @@ -147,16 +152,16 @@ describe('jobs', function() else nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) end - nvim('command', "call jobwait([j])") - nvim('command', "let g:output = Normalize(g:job_opts.stdout)") + nvim('command', 'call jobwait([j])') + nvim('command', 'let g:output = Normalize(g:job_opts.stdout)') local actual = eval('g:output') local expected if is_os('win') then -- Toto is normalized to TOTO so we can detect duplicates, and because -- Windows doesn't care about case - expected = {'TOTO=def', ''} + expected = { 'TOTO=def', '' } else - expected = {'TOTO=abc', 'Toto=def', ''} + expected = { 'TOTO=abc', 'Toto=def', '' } end table.sort(actual) table.sort(expected) @@ -170,9 +175,9 @@ describe('jobs', function() else nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") end - eq({'notification', 'stdout', {0, {'abc', ''}}}, next_msg()) - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 0}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('changes to given / directory', function() @@ -182,14 +187,13 @@ describe('jobs', function() else nvim('command', "let j = jobstart('pwd', g:job_opts)") end - eq({'notification', 'stdout', - {0, {pathroot(), ''}}}, next_msg()) - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 0}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg()) + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('changes to given `cwd` directory', function() - local dir = eval("resolve(tempname())"):gsub("/", get_pathsep()) + local dir = eval('resolve(tempname())'):gsub('/', get_pathsep()) mkdir(dir) nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then @@ -198,15 +202,17 @@ describe('jobs', function() nvim('command', "let j = jobstart('pwd', g:job_opts)") end expect_msg_seq( - { {'notification', 'stdout', {0, {dir, ''} } }, - {'notification', 'stdout', {0, {''} } }, - {'notification', 'exit', {0, 0} } + { + { 'notification', 'stdout', { 0, { dir, '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + { 'notification', 'exit', { 0, 0 } }, }, -- Alternative sequence: - { {'notification', 'stdout', {0, {dir} } }, - {'notification', 'stdout', {0, {'', ''} } }, - {'notification', 'stdout', {0, {''} } }, - {'notification', 'exit', {0, 0} } + { + { 'notification', 'stdout', { 0, { dir } } }, + { 'notification', 'stdout', { 0, { '', '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + { 'notification', 'exit', { 0, 0 } }, } ) rmdir(dir) @@ -222,7 +228,7 @@ describe('jobs', function() nvim('command', "let j = jobstart('pwd', g:job_opts)") end end) - ok(string.find(err, "E475: Invalid argument: expected valid directory$") ~= nil) + ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) end) it('error on non-executable `cwd`', function() @@ -231,16 +237,18 @@ describe('jobs', function() local dir = 'Xtest_not_executable_dir' mkdir(dir) funcs.setfperm(dir, 'rw-------') - matches('^Vim%(call%):E903: Process failed to start: permission denied: .*', - pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '"..dir.."'})")) + matches( + '^Vim%(call%):E903: Process failed to start: permission denied: .*', + pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") + ) rmdir(dir) end) it('returns 0 when it fails to start', function() - eq("", eval("v:errmsg")) - feed_command("let g:test_jobid = jobstart([])") - eq(0, eval("g:test_jobid")) - eq("E474:", string.match(eval("v:errmsg"), "E%d*:")) + eq('', eval('v:errmsg')) + feed_command('let g:test_jobid = jobstart([])') + eq(0, eval('g:test_jobid')) + eq('E474:', string.match(eval('v:errmsg'), 'E%d*:')) end) it('returns -1 when target is not executable #5465', function() @@ -249,10 +257,13 @@ describe('jobs', function() end local executable_jobid = new_job() - local exe = is_os('win') and './test/functional/fixtures' or './test/functional/fixtures/non_executable.txt' - eq("Vim:E475: Invalid value for argument cmd: '"..exe.."' is not executable", - pcall_err(eval, "jobstart(['"..exe.."'])")) - eq("", eval("v:errmsg")) + local exe = is_os('win') and './test/functional/fixtures' + or './test/functional/fixtures/non_executable.txt' + eq( + "Vim:E475: Invalid value for argument cmd: '" .. exe .. "' is not executable", + pcall_err(eval, "jobstart(['" .. exe .. "'])") + ) + eq('', eval('v:errmsg')) -- Non-executable job should not increment the job ids. #5465 eq(executable_jobid + 1, new_job()) end) @@ -260,113 +271,117 @@ describe('jobs', function() it('invokes callbacks when the job writes and exits', function() nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") nvim('command', [[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) - expect_twostreams({{'notification', 'stdout', {0, {'', ''}}}, - {'notification', 'stdout', {0, {''}}}}, - {{'notification', 'stderr', {0, {''}}}}) - eq({'notification', 'exit', {0, 0}}, next_msg()) + expect_twostreams({ + { 'notification', 'stdout', { 0, { '', '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + }, { { 'notification', 'stderr', { 0, { '' } } } }) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('interactive commands', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) nvim('command', 'call jobsend(j, "abc\\n")') - eq({'notification', 'stdout', {0, {'abc', ''}}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) nvim('command', 'call jobsend(j, "123\\nxyz\\n")') expect_msg_seq( - { {'notification', 'stdout', {0, {'123', 'xyz', ''}}} - }, + { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: - { {'notification', 'stdout', {0, {'123', ''}}}, - {'notification', 'stdout', {0, {'xyz', ''}}} + { + { 'notification', 'stdout', { 0, { '123', '' } } }, + { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) nvim('command', 'call jobsend(j, [123, "xyz", ""])') expect_msg_seq( - { {'notification', 'stdout', {0, {'123', 'xyz', ''}}} - }, + { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: - { {'notification', 'stdout', {0, {'123', ''}}}, - {'notification', 'stdout', {0, {'xyz', ''}}} + { + { 'notification', 'stdout', { 0, { '123', '' } } }, + { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', "call jobstop(j)") - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 143}}, next_msg()) + nvim('command', 'call jobstop(j)') + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('preserves NULs', function() -- Make a file with NULs in it. local filename = helpers.tmpname() - write_file(filename, "abc\0def\n") + write_file(filename, 'abc\0def\n') - nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)") - eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg()) - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 0}}, next_msg()) + nvim('command', "let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") + eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg()) + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) os.remove(filename) -- jobsend() preserves NULs. nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', [[call jobsend(j, ["123\n456",""])]]) - eq({'notification', 'stdout', {0, {'123\n456', ''}}}, next_msg()) - nvim('command', "call jobstop(j)") + eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg()) + nvim('command', 'call jobstop(j)') end) - it("emits partial lines (does NOT buffer data lacking newlines)", function() + it('emits partial lines (does NOT buffer data lacking newlines)', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, "abc\\nxyz")') - eq({'notification', 'stdout', {0, {'abc', 'xyz'}}}, next_msg()) - nvim('command', "call jobstop(j)") - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 143}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg()) + nvim('command', 'call jobstop(j)') + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('preserves newlines', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') - eq({'notification', 'stdout', - {0, {'a', '', 'c', '', '', '', 'b', '', ''}}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg()) end) it('preserves NULs', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') - eq({'notification', 'stdout', {0, {'\n123\n', 'abc\nxyz\n', ''}}}, - next_msg()) - nvim('command', "call jobstop(j)") - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 143}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg()) + nvim('command', 'call jobstop(j)') + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('avoids sending final newline', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') - eq({'notification', 'stdout', {0, {'some data', 'without\nfinal nl'}}}, - next_msg()) - nvim('command', "call jobstop(j)") - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 143}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg()) + nvim('command', 'call jobstop(j)') + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('closes the job streams with jobclose', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobclose(j, "stdin")') - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 0}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) - it("disallows jobsend on a job that closed stdin", function() + it('disallows jobsend on a job that closed stdin', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobclose(j, "stdin")') - eq(false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') - end)) + eq( + false, + pcall(function() + nvim('command', 'call jobsend(j, ["some data"])') + end) + ) command("let g:job_opts.stdin = 'null'") nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - eq(false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') - end)) + eq( + false, + pcall(function() + nvim('command', 'call jobsend(j, ["some data"])') + end) + ) end) it('disallows jobsend on a non-existent job', function() @@ -377,8 +392,8 @@ describe('jobs', function() it('jobstop twice on the stopped or exited job return 0', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) - eq(1, eval("jobstop(j)")) - eq(0, eval("jobstop(j)")) + eq(1, eval('jobstop(j)')) + eq(0, eval('jobstop(j)')) end) it('will not leak memory if we leave a job running', function() @@ -390,14 +405,17 @@ describe('jobs', function() local pid = eval('jobpid(j)') neq(NIL, meths.get_proc(pid)) nvim('command', 'call jobstop(j)') - eq({'notification', 'stdout', {0, {''}}}, next_msg()) - eq({'notification', 'exit', {0, 143}}, next_msg()) + eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq(NIL, meths.get_proc(pid)) end) - it("disposed on Nvim exit", function() + it('disposed on Nvim exit', function() -- use sleep, which doesn't die on stdin close - nvim('command', "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)") + nvim( + 'command', + "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" + ) local pid = eval('jobpid(g:j)') neq(NIL, meths.get_proc(pid)) clear() @@ -406,7 +424,10 @@ describe('jobs', function() it('can survive the exit of nvim with "detach"', function() nvim('command', 'let g:job_opts.detach = 1') - nvim('command', "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)") + nvim( + 'command', + "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" + ) local pid = eval('jobpid(g:j)') neq(NIL, meths.get_proc(pid)) clear() @@ -418,25 +439,27 @@ describe('jobs', function() it('can pass user data to the callback', function() nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') nvim('command', [[call jobstart('echo foo', g:job_opts)]]) - local data = {n = 5, s = 'str', l = {1}} + local data = { n = 5, s = 'str', l = { 1 } } expect_msg_seq( - { {'notification', 'stdout', {data, {'foo', ''}}}, - {'notification', 'stdout', {data, {''}}}, + { + { 'notification', 'stdout', { data, { 'foo', '' } } }, + { 'notification', 'stdout', { data, { '' } } }, }, -- Alternative sequence: - { {'notification', 'stdout', {data, {'foo'}}}, - {'notification', 'stdout', {data, {'', ''}}}, - {'notification', 'stdout', {data, {''}}}, + { + { 'notification', 'stdout', { data, { 'foo' } } }, + { 'notification', 'stdout', { data, { '', '' } } }, + { 'notification', 'stdout', { data, { '' } } }, } ) - eq({'notification', 'exit', {data, 0}}, next_msg()) + eq({ 'notification', 'exit', { data, 0 } }, next_msg()) end) it('can omit data callbacks', function() nvim('command', 'unlet g:job_opts.on_stdout') nvim('command', 'let g:job_opts.user = 5') nvim('command', [[call jobstart('echo foo', g:job_opts)]]) - eq({'notification', 'exit', {5, 0}}, next_msg()) + eq({ 'notification', 'exit', { 5, 0 } }, next_msg()) end) it('can omit exit callback', function() @@ -444,13 +467,15 @@ describe('jobs', function() nvim('command', 'let g:job_opts.user = 5') nvim('command', [[call jobstart('echo foo', g:job_opts)]]) expect_msg_seq( - { {'notification', 'stdout', {5, {'foo', ''} } }, - {'notification', 'stdout', {5, {''} } }, + { + { 'notification', 'stdout', { 5, { 'foo', '' } } }, + { 'notification', 'stdout', { 5, { '' } } }, }, -- Alternative sequence: - { {'notification', 'stdout', {5, {'foo'} } }, - {'notification', 'stdout', {5, {'', ''} } }, - {'notification', 'stdout', {5, {''} } }, + { + { 'notification', 'stdout', { 5, { 'foo' } } }, + { 'notification', 'stdout', { 5, { '', '' } } }, + { 'notification', 'stdout', { 5, { '' } } }, } ) end) @@ -458,8 +483,8 @@ describe('jobs', function() it('will pass return code with the exit event', function() nvim('command', 'let g:job_opts.user = 5') nvim('command', "call jobstart('exit 55', g:job_opts)") - eq({'notification', 'stdout', {5, {''}}}, next_msg()) - eq({'notification', 'exit', {5, 55}}, next_msg()) + eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg()) + eq({ 'notification', 'exit', { 5, 55 } }, next_msg()) end) it('can receive dictionary functions', function() @@ -470,14 +495,14 @@ describe('jobs', function() endfunction call jobstart('exit 45', g:dict) ]]) - eq({'notification', 'exit', {45, 10}}, next_msg()) + eq({ 'notification', 'exit', { 45, 10 } }, next_msg()) end) it('can redefine callbacks being used by a job', function() local screen = Screen.new() screen:attach() screen:set_default_attr_ids({ - [1] = {bold=true, foreground=Screen.colors.Blue}, + [1] = { bold = true, foreground = Screen.colors.Blue }, }) source([[ function! g:JobHandler(job_id, data, event) @@ -496,16 +521,16 @@ describe('jobs', function() endfunction ]]) - eq("", eval("v:errmsg")) + eq('', eval('v:errmsg')) end) it('requires funcrefs for script-local (s:) functions', function() local screen = Screen.new(60, 5) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4} + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) -- Pass job callback names _without_ `function(...)`. @@ -520,7 +545,7 @@ describe('jobs', function() \ }) ]]) - screen:expect{any="{2:E120: Using not in a script context: s:OnEvent}"} + screen:expect { any = '{2:E120: Using not in a script context: s:OnEvent}' } end) it('does not repeat output with slow output handlers', function() @@ -543,22 +568,22 @@ describe('jobs', function() call jobwait([g:id]) ]]) - local expected = {'1', '2', '3', '4', '5', ''} + local expected = { '1', '2', '3', '4', '5', '' } local chunks = eval('d.data') -- check nothing was received after exit, including EOF eq(eval('g:exit_data'), chunks) - local received = {''} + local received = { '' } for i, chunk in ipairs(chunks) do if i < #chunks then -- if chunks got joined, a spurious [''] callback was not sent - neq({''}, chunk) + neq({ '' }, chunk) else -- but EOF callback is still sent - eq({''}, chunk) + eq({ '' }, chunk) end - received[#received] = received[#received]..chunk[1] + received[#received] = received[#received] .. chunk[1] for j = 2, #chunk do - received[#received+1] = chunk[j] + received[#received + 1] = chunk[j] end end eq(expected, received) @@ -586,22 +611,22 @@ describe('jobs', function() call jobwait([g:id]) ]]) - local expected = {'1', '2', '3', '4', '5', ''} + local expected = { '1', '2', '3', '4', '5', '' } local chunks = eval('d.data') -- check nothing was received after exit, including EOF eq(eval('g:exit_data'), chunks) - local received = {''} + local received = { '' } for i, chunk in ipairs(chunks) do if i < #chunks then -- if chunks got joined, a spurious [''] callback was not sent - neq({''}, chunk) + neq({ '' }, chunk) else -- but EOF callback is still sent - eq({''}, chunk) + eq({ '' }, chunk) end - received[#received] = received[#received]..chunk[1] + received[#received] = received[#received] .. chunk[1] for j = 2, #chunk do - received[#received+1] = chunk[j] + received[#received + 1] = chunk[j] end end eq(expected, received) @@ -619,11 +644,11 @@ describe('jobs', function() call jobstart('echo some text', g:job_opts) ]]) expect_msg_seq( - { {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, - }, + { { 'notification', '1', { 'foo', 'bar', { 'some text', '' }, 'stdout' } } }, -- Alternative sequence: - { {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}}, - {'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}}, + { + { 'notification', '1', { 'foo', 'bar', { 'some text' }, 'stdout' } }, + { 'notification', '1', { 'foo', 'bar', { '', '' }, 'stdout' } }, } ) end) @@ -639,11 +664,11 @@ describe('jobs', function() call jobstart('echo some text', g:job_opts) ]]) expect_msg_seq( - { {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, - }, + { { 'notification', '1', { 'foo', 'bar', { 'some text', '' }, 'stdout' } } }, -- Alternative sequence: - { {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}}, - {'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}}, + { + { 'notification', '1', { 'foo', 'bar', { 'some text' }, 'stdout' } }, + { 'notification', '1', { 'foo', 'bar', { '', '' }, 'stdout' } }, } ) end) @@ -654,18 +679,19 @@ describe('jobs', function() call jobstart('echo some text', g:job_opts) ]]) expect_msg_seq( - { {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, - }, + { { 'notification', '1', { 'foo', 'bar', { 'some text', '' }, 'stdout' } } }, -- Alternative sequence: - { {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}}, - {'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}}, + { + { 'notification', '1', { 'foo', 'bar', { 'some text' }, 'stdout' } }, + { 'notification', '1', { 'foo', 'bar', { '', '' }, 'stdout' } }, } ) end) it('jobstart() environment: $NVIM, $NVIM_LISTEN_ADDRESS #11009', function() local function get_env_in_child_job(envname, env) - return exec_lua([[ + return exec_lua( + [[ local envname, env = ... local join = function(s) return vim.fn.join(s, '') end local stdout = {} @@ -681,8 +707,9 @@ describe('jobs', function() vim.fn.jobwait({ j1 }, 10000) return join({ join(stdout), join(stderr) }) ]], - envname, - env) + envname, + env + ) end local addr = eval('v:servername') @@ -690,14 +717,18 @@ describe('jobs', function() -- $NVIM is _not_ defined in the top-level Nvim process. eq('', eval('$NVIM')) -- jobstart() shares its v:servername with the child via $NVIM. - eq('NVIM='..addr, get_env_in_child_job('NVIM')) + eq('NVIM=' .. addr, get_env_in_child_job('NVIM')) -- $NVIM_LISTEN_ADDRESS is unset by server_init in the child. eq('NVIM_LISTEN_ADDRESS=v:null', get_env_in_child_job('NVIM_LISTEN_ADDRESS')) - eq('NVIM_LISTEN_ADDRESS=v:null', get_env_in_child_job('NVIM_LISTEN_ADDRESS', - { NVIM_LISTEN_ADDRESS='Xtest_jobstart_env' })) + eq( + 'NVIM_LISTEN_ADDRESS=v:null', + get_env_in_child_job('NVIM_LISTEN_ADDRESS', { NVIM_LISTEN_ADDRESS = 'Xtest_jobstart_env' }) + ) -- User can explicitly set $NVIM_LOG_FILE, $VIM, $VIMRUNTIME. - eq('NVIM_LOG_FILE=Xtest_jobstart_env', - get_env_in_child_job('NVIM_LOG_FILE', { NVIM_LOG_FILE='Xtest_jobstart_env' })) + eq( + 'NVIM_LOG_FILE=Xtest_jobstart_env', + get_env_in_child_job('NVIM_LOG_FILE', { NVIM_LOG_FILE = 'Xtest_jobstart_env' }) + ) os.remove('Xtest_jobstart_env') end) @@ -722,7 +753,7 @@ describe('jobs', function() \ jobstart('sleep 0.310; exit 7') \ ])) ]]) - eq({'notification', 'wait', {{4, 5, 6, 7}}}, next_msg()) + eq({ 'notification', 'wait', { { 4, 5, 6, 7 } } }, next_msg()) end) it('will run callbacks while waiting', function() @@ -752,8 +783,7 @@ describe('jobs', function() \ ]) call rpcnotify(g:channel, 'wait', sort(g:jobs), sort(g:exits)) ]]) - eq({'notification', 'wait', - {{3,4,5,6}, {3,4,5,6}}}, next_msg()) + eq({ 'notification', 'wait', { { 3, 4, 5, 6 }, { 3, 4, 5, 6 } } }, next_msg()) end) it('will return status codes in the order of passed ids', function() @@ -770,7 +800,7 @@ describe('jobs', function() \ jobstart('sleep 0.010; exit 7') \ ])) ]]) - eq({'notification', 'wait', {{4, 5, 6, 7}}}, next_msg()) + eq({ 'notification', 'wait', { { 4, 5, 6, 7 } } }, next_msg()) end) it('will return -3 for invalid job ids', function() @@ -780,29 +810,33 @@ describe('jobs', function() \ jobstart((has('win32') ? 'Start-Sleep -Milliseconds 100' : 'sleep 0.01').'; exit 5'), \ ])) ]]) - eq({'notification', 'wait', {{-3, 5}}}, next_msg()) + eq({ 'notification', 'wait', { { -3, 5 } } }, next_msg()) end) it('will return -2 when interrupted without timeout', function() - feed_command('call rpcnotify(g:channel, "ready") | '.. - 'call rpcnotify(g:channel, "wait", '.. - 'jobwait([jobstart("'.. - (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. - '; exit 55")]))') - eq({'notification', 'ready', {}}, next_msg()) + feed_command( + 'call rpcnotify(g:channel, "ready") | ' + .. 'call rpcnotify(g:channel, "wait", ' + .. 'jobwait([jobstart("' + .. (is_os('win') and 'Start-Sleep 10' or 'sleep 10') + .. '; exit 55")]))' + ) + eq({ 'notification', 'ready', {} }, next_msg()) feed('') - eq({'notification', 'wait', {{-2}}}, next_msg()) + eq({ 'notification', 'wait', { { -2 } } }, next_msg()) end) it('will return -2 when interrupted with timeout', function() - feed_command('call rpcnotify(g:channel, "ready") | '.. - 'call rpcnotify(g:channel, "wait", '.. - 'jobwait([jobstart("'.. - (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. - '; exit 55")], 10000))') - eq({'notification', 'ready', {}}, next_msg()) + feed_command( + 'call rpcnotify(g:channel, "ready") | ' + .. 'call rpcnotify(g:channel, "wait", ' + .. 'jobwait([jobstart("' + .. (is_os('win') and 'Start-Sleep 10' or 'sleep 10') + .. '; exit 55")], 10000))' + ) + eq({ 'notification', 'ready', {} }, next_msg()) feed('') - eq({'notification', 'wait', {{-2}}}, next_msg()) + eq({ 'notification', 'wait', { { -2 } } }, next_msg()) end) it('can be called recursively', function() @@ -845,9 +879,9 @@ describe('jobs', function() local r for i = 10, 1, -1 do r = next_msg() - eq('job '..i..' closed', r[3][1]) + eq('job ' .. i .. ' closed', r[3][1]) r = next_msg() - eq('job '..i..' exited', r[3][1]) + eq('job ' .. i .. ' exited', r[3][1]) end eq(10, nvim('eval', 'g:counter')) end) @@ -859,7 +893,7 @@ describe('jobs', function() \ jobstart((has('win32') ? 'Start-Sleep 10' : 'sleep 10').'; exit 5'), \ ], 100)) ]]) - eq({'notification', 'wait', {{-1}}}, next_msg()) + eq({ 'notification', 'wait', { { -1 } } }, next_msg()) end) it('can pass 0 to check if a job exists', function() @@ -872,16 +906,16 @@ describe('jobs', function() \ jobstart('sleep 0.3; exit 5'), \ ], 0)) ]]) - eq({'notification', 'wait', {{-1, -1}}}, next_msg()) + 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 + [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'])]]) @@ -893,21 +927,26 @@ describe('jobs', function() endfunc ]]) feed_command('call PrintAndWait()') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 {1: }| aaa | bbb | - ]], timeout=100} - screen:expect{grid=[[ + ]], + timeout = 100, + } + screen:expect { + grid = [[ | {1: }| aaa | bbb | ccc | {2:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('') funcs.jobstop(meths.get_var('id')) end) @@ -919,29 +958,35 @@ describe('jobs', function() nvim('eval', 'jobsend(j, "abcdef")') nvim('eval', 'jobstop(j)') expect_msg_seq( - { {'notification', 'stdout', {0, {'abcdef'}}}, - {'notification', 'stdout', {0, {''}}}, - {'notification', 'stderr', {0, {''}}}, + { + { 'notification', 'stdout', { 0, { 'abcdef' } } }, + { 'notification', 'stdout', { 0, { '' } } }, + { 'notification', 'stderr', { 0, { '' } } }, }, -- Alternative sequence: - { {'notification', 'stderr', {0, {''}}}, - {'notification', 'stdout', {0, {'abcdef'}}}, - {'notification', 'stdout', {0, {''}}}, + { + { 'notification', 'stderr', { 0, { '' } } }, + { 'notification', 'stdout', { 0, { 'abcdef' } } }, + { 'notification', 'stdout', { 0, { '' } } }, }, -- Alternative sequence: - { {'notification', 'stdout', {0, {'abcdef'}}}, - {'notification', 'stderr', {0, {''}}}, - {'notification', 'stdout', {0, {''}}}, + { + { 'notification', 'stdout', { 0, { 'abcdef' } } }, + { 'notification', 'stderr', { 0, { '' } } }, + { 'notification', 'stdout', { 0, { '' } } }, } ) - eq({'notification', 'exit', {0, 143}}, next_msg()) + eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('cannot have both rpc and pty options', function() - command("let g:job_opts.pty = v:true") - command("let g:job_opts.rpc = v:true") + command('let g:job_opts.pty = v:true') + command('let g:job_opts.rpc = v:true') local _, err = pcall(command, "let j = jobstart(['cat', '-'], g:job_opts)") - ok(string.find(err, "E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set") ~= nil) + ok( + string.find(err, "E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set") + ~= nil + ) end) it('does not crash when repeatedly failing to start shell', function() @@ -954,7 +999,7 @@ describe('jobs', function() ]]) -- The crash only triggered if both jobs are cleaned up on the same event -- loop tick. This is also prevented by try-block, so feed must be used. - feed_command("call DoIt()") + feed_command('call DoIt()') feed('') -- press RETURN assert_alive() end) @@ -991,7 +1036,7 @@ describe('jobs', function() \ 'substitute(v:val, "\r", "", "")'), \ 'split(v:val, "\\s\\+")') if len(proc) == 6 - let s:procs[proc[1]] ..']]'..[[= {'name': proc[0], + let s:procs[proc[1]] .. ']]' .. [[= {'name': proc[0], \ 'Session Name': proc[2], \ 'Session': proc[3]} endif @@ -1015,10 +1060,8 @@ describe('jobs', function() endfunction ]]) end - local sleep_cmd = (is_os('win') - and 'ping -n 31 127.0.0.1' - or 'sleep 30') - local j = eval("jobstart('"..sleep_cmd..' | '..sleep_cmd..' | '..sleep_cmd.."')") + local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') + local j = eval("jobstart('" .. sleep_cmd .. ' | ' .. sleep_cmd .. ' | ' .. sleep_cmd .. "')") local ppid = funcs.jobpid(j) local children if is_os('win') then @@ -1034,7 +1077,7 @@ describe('jobs', function() error(result) end else - retry(nil, nil, function() + retry(nil, nil, function() children = meths.get_proc_children(ppid) eq(3, #children) end) @@ -1059,11 +1102,13 @@ describe('jobs', function() nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)') neq(0, eval('j')) - eq({1, 0}, eval('[jobstop(j), jobstop(j)]')) + eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]')) end) describe('running tty-test program', function() - if skip(is_os('win')) then return end + if skip(is_os('win')) then + return + end local function next_chunk() local rv while true do @@ -1097,8 +1142,8 @@ describe('jobs', function() insert(testprg('tty-test')) nvim('command', 'let g:job_opts.pty = 1') nvim('command', 'let exec = [expand(":p")]') - nvim('command', "let j = jobstart(exec, g:job_opts)") - j = eval'j' + nvim('command', 'let j = jobstart(exec, g:job_opts)') + j = eval 'j' eq('tty ready', next_chunk()) end) @@ -1117,8 +1162,8 @@ describe('jobs', function() it('jobclose() sends SIGHUP', function() nvim('command', 'call jobclose(j)') local msg = next_msg() - msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. - eq({'notification', 'exit', {0, 42}}, msg) + msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. + eq({ 'notification', 'exit', { 0, 42 } }, msg) end) it('jobstart() does not keep ptmx file descriptor open', function() @@ -1144,19 +1189,25 @@ describe('jobs', function() it('does not close the same handle twice on exit #25086', function() local filename = string.format('%s.lua', helpers.tmpname()) - write_file(filename, [[ + write_file( + filename, + [[ vim.api.nvim_create_autocmd('VimLeavePre', { callback = function() local id = vim.fn.jobstart('sleep 0') vim.fn.jobwait({id}) end, }) - ]]) + ]] + ) local screen = thelpers.setup_child_nvim({ - '--cmd', 'set notermguicolors', - '-i', 'NONE', - '-u', filename, + '--cmd', + 'set notermguicolors', + '-i', + 'NONE', + '-u', + filename, }) -- Wait for startup to complete, so that all terminal responses are received. screen:expect([[ @@ -1177,7 +1228,7 @@ describe('jobs', function() end) end) -describe("pty process teardown", function() +describe('pty process teardown', function() local screen before_each(function() clear() @@ -1190,14 +1241,22 @@ describe("pty process teardown", function() ]]) end) - it("does not prevent/delay exit. #4798 #4900", function() + it('does not prevent/delay exit. #4798 #4900', function() skip(is_os('win')) -- Use a nested nvim (in :term) to test without --headless. funcs.termopen({ - helpers.nvim_prog, '-u', 'NONE', '-i', "NONE", '--cmd', nvim_set, + helpers.nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + nvim_set, -- Use :term again in the _nested_ nvim to get a PTY process. -- Use `sleep` to simulate a long-running child of the PTY. - '+terminal', '+!(sleep 300 &)', '+qa', + '+terminal', + '+!(sleep 300 &)', + '+qa', }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } }) -- Exiting should terminate all descendants (PTY, its children, ...). diff --git a/test/functional/core/log_spec.lua b/test/functional/core/log_spec.lua index f682df4155..1637e683c1 100644 --- a/test/functional/core/log_spec.lua +++ b/test/functional/core/log_spec.lua @@ -23,7 +23,7 @@ describe('log', function() -- calls, that needs investigation. clear() eq(0, request('nvim__stats').log_skip) - clear{env={CDPATH='~doesnotexist'}} + clear { env = { CDPATH = '~doesnotexist' } } assert(request('nvim__stats').log_skip <= 13) end) @@ -32,14 +32,16 @@ describe('log', function() -- ERR 2022-05-29T12:30:03.800 T2 log_init:110: test log message -- ERR 2022-05-29T12:30:03.814 T2/child log_init:110: test log message - clear({env={ - NVIM_LOG_FILE=testlog, - -- TODO: remove this after nvim_log #7062 is merged. - __NVIM_TEST_LOG='1' - }}) + clear({ + env = { + NVIM_LOG_FILE = testlog, + -- TODO: remove this after nvim_log #7062 is merged. + __NVIM_TEST_LOG = '1', + }, + }) local tid = _G._nvim_test_id - assert_log(tid..'%.%d+%.%d +server_init:%d+: test log message', testlog, 100) + assert_log(tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100) exec_lua([[ local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict()) diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 0501a75bd6..4a9943be20 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -33,27 +33,44 @@ describe('command-line option', function() it('treats - as stdin', function() 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!', ''}) + 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 = luv.fs_stat(fname) - eq(#('42\n'), attrs.size) + eq(#'42\n', attrs.size) end) it('does not expand $VAR', function() 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( - {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless', - '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', - '-s', dollar_fname, fname}) + funcs.system({ + nvim_prog_abs(), + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '--cmd', + 'set noswapfile shortmess+=IFW fileformats=unix', + '-s', + dollar_fname, + fname, + }) eq(0, eval('v:shell_error')) local attrs = luv.fs_stat(fname) - eq(#('100500\n'), attrs.size) + eq(#'100500\n', attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() @@ -61,24 +78,33 @@ describe('command-line option', function() local screen = Screen.new(40, 8) screen:attach() local args = { - nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', - '--cmd', '"set noswapfile shortmess+=IFW fileformats=unix notermguicolors"', - '-s', '-' + nvim_prog_abs(), + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + '"set noswapfile shortmess+=IFW fileformats=unix notermguicolors"', + '-s', + '-', } -- Need to explicitly pipe to stdin so that the embedded Nvim instance doesn't try to read -- data from the terminal #18181 - funcs.termopen(string.format([[echo "" | %s]], table.concat(args, " ")), { - env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } + funcs.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) - screen:expect([[ + screen:expect( + [[ ^ | ~ |*4 {1:[No Name] 0,0-1 All}| |*2 - ]], { - [1] = {reverse = true}; - }) + ]], + { + [1] = { reverse = true }, + } + ) feed('i:cq') screen:expect([[ | @@ -101,12 +127,22 @@ describe('command-line option', function() 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', - funcs.system( - {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless', - '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', - '--cmd', 'language C', - '-s', nonexistent_fname})) + 'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n', + funcs.system({ + nvim_prog_abs(), + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '--cmd', + 'set noswapfile shortmess+=IFW fileformats=unix', + '--cmd', + 'language C', + '-s', + nonexistent_fname, + }) + ) eq(2, eval('v:shell_error')) end) @@ -114,12 +150,25 @@ describe('command-line option', function() write_file(fname, ':call setline(1, "1")\n:wqall!\n') write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') eq( - 'Attempt to open script file again: "-s '..dollar_fname..'"\n', - funcs.system( - {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless', - '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', - '--cmd', 'language C', - '-s', fname, '-s', dollar_fname, fname_2})) + 'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n', + funcs.system({ + nvim_prog_abs(), + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '--cmd', + 'set noswapfile shortmess+=IFW fileformats=unix', + '--cmd', + 'language C', + '-s', + fname, + '-s', + dollar_fname, + fname_2, + }) + ) eq(2, eval('v:shell_error')) eq(nil, luv.fs_stat(fname_2)) end) @@ -128,7 +177,7 @@ describe('command-line option', function() 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'})) + 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 97c32f7de6..21364d7c03 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -13,7 +13,7 @@ local write_file = helpers.write_file local function join_path(...) local pathsep = (is_os('win') and '\\' or '/') - return table.concat({...}, pathsep) + return table.concat({ ... }, pathsep) end describe('path collapse', function() @@ -23,40 +23,40 @@ describe('path collapse', function() before_each(function() targetdir = join_path('test', 'functional', 'fixtures') clear() - command('edit '..join_path(targetdir, 'tty-test.c')) + command('edit ' .. join_path(targetdir, 'tty-test.c')) expected_path = eval('expand("%:p")') end) it('with /./ segment #7117', function() - command('edit '..join_path(targetdir, '.', 'tty-test.c')) + command('edit ' .. join_path(targetdir, '.', 'tty-test.c')) eq(expected_path, eval('expand("%:p")')) end) it('with ./ prefix #7117', function() - command('edit '..join_path('.', targetdir, 'tty-test.c')) + command('edit ' .. join_path('.', targetdir, 'tty-test.c')) eq(expected_path, eval('expand("%:p")')) end) it('with ./ prefix, after directory change #7117', function() - command('edit '..join_path('.', targetdir, 'tty-test.c')) + command('edit ' .. join_path('.', targetdir, 'tty-test.c')) command('cd test') eq(expected_path, eval('expand("%:p")')) end) it('with /../ segment #7117', function() - command('edit '..join_path(targetdir, '..', 'fixtures', 'tty-test.c')) + command('edit ' .. join_path(targetdir, '..', 'fixtures', 'tty-test.c')) eq(expected_path, eval('expand("%:p")')) end) it('with ../ and different starting directory #7117', function() command('cd test') - command('edit '..join_path('..', targetdir, 'tty-test.c')) + command('edit ' .. join_path('..', targetdir, 'tty-test.c')) eq(expected_path, eval('expand("%:p")')) end) it('with ./../ and different starting directory #7117', function() command('cd test') - command('edit '..join_path('.', '..', targetdir, 'tty-test.c')) + command('edit ' .. join_path('.', '..', targetdir, 'tty-test.c')) eq(expected_path, eval('expand("%:p")')) end) end) @@ -67,16 +67,16 @@ describe('expand wildcard', function() it('with special characters #24421', function() local folders = is_os('win') and { '{folder}', - 'folder$name' + 'folder$name', } or { 'folder-name', - '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..'/*")')) + eq(file, eval('expand("' .. folder .. '/*")')) rmdir(folder) end end) @@ -131,14 +131,30 @@ describe('file search', function() 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]]) + 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]]) + 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' diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index a0ec748446..5eb520ef4f 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -51,7 +51,10 @@ 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({...}, { + eq( + { 0 }, + exec_lua( + [[return vim.fn.jobwait({ vim.fn.jobstart({...}, { stdout_buffered = true, stderr_buffered = true, on_stdout = function(_, data, _) @@ -60,7 +63,15 @@ describe('Remote', function() on_stderr = function(_, data, _) _G.Remote_stderr = table.concat(data, '\n') end, - }) })]], nvim_prog, '--clean', '--headless', '--server', addr, ...)) + }) })]], + nvim_prog, + '--clean', + '--headless', + '--server', + addr, + ... + ) + ) local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]]) client_starter:close() set_session(server) @@ -95,7 +106,7 @@ describe('Remote', function() end) it('send keys', function() - eq({ '', '' }, run_remote('--remote-send', ':edit '..fname..'v')) + eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. 'v')) expect(contents) eq(2, #funcs.getwininfo()) -- Only a single buffer as we're using edit and not drop like --remote does diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index f6f7711c0a..ebf9deb86b 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -36,9 +36,23 @@ local endswith = helpers.endswith describe('startup', function() it('--clean', function() clear() - ok(string.find(alter_slashes(meths.get_option_value('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_value('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() @@ -58,7 +72,7 @@ describe('startup', function() finally(function() os.remove(testfile) end) - clear({ args = {'--startuptime', testfile}}) + clear({ args = { '--startuptime', testfile } }) assert_log('sourcing', testfile, 100) assert_log("require%('vim%._editor'%)", testfile, 100) end) @@ -70,10 +84,13 @@ describe('startup', function() screen:attach() local id = funcs.termopen({ nvim_prog, - '-u', 'NONE', - '-i', 'NONE', - '--cmd', 'set noruler', - '-D' + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'set noruler', + '-D', }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), @@ -127,39 +144,48 @@ describe('startup', function() vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0') ]] -- nvim -l foo.lua -arg1 -- a b c - assert_l_out([[ + assert_l_out( + [[ bufs: nvim args: 7 lua args: { "-arg1", "--exitcode", "73", "--arg2", [0] = "test/functional/fixtures/startup.lua" }]], {}, - { '-arg1', "--exitcode", "73", '--arg2' } + { '-arg1', '--exitcode', '73', '--arg2' } ) eq(73, eval('v:shell_error')) end) it('Lua-error sets Nvim exitcode', function() eq(0, eval('v:shell_error')) - matches('E5113: .* my pearls!!', - funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) + matches( + 'E5113: .* my pearls!!', + funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) + ) eq(1, eval('v:shell_error')) - matches('E5113: .* %[string "error%("whoa"%)"%]:1: whoa', - funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")')) + matches( + 'E5113: .* %[string "error%("whoa"%)"%]:1: whoa', + funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")') + ) eq(1, eval('v:shell_error')) end) it('executes stdin "-"', function() - assert_l_out('arg0=- args=2 whoa\n', + 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\n', + "print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))" + ) + assert_l_out( + 'biiig input: 1000042\n', nil, nil, '-', - ('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42))) + ('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42)) + ) eq(0, eval('v:shell_error')) end) @@ -174,7 +200,8 @@ describe('startup', function() it('sets _G.arg', function() -- nvim -l foo.lua - assert_l_out([[ + assert_l_out( + [[ bufs: nvim args: 3 lua args: { @@ -187,7 +214,8 @@ describe('startup', function() eq(0, eval('v:shell_error')) -- nvim -l foo.lua [args] - assert_l_out([[ + assert_l_out( + [[ bufs: nvim args: 7 lua args: { "-arg1", "--arg2", "--", "arg3", @@ -200,20 +228,22 @@ describe('startup', function() eq(0, eval('v:shell_error')) -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 - assert_l_out([[ + assert_l_out( + [[ bufs: file1 file2 nvim args: 10 lua args: { "-arg1", "arg 2", "--", "file3", "file4", [0] = "test/functional/fixtures/startup.lua" } ]], - { 'file1', 'file2', }, + { 'file1', 'file2' }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) eq(0, eval('v:shell_error')) -- nvim -l foo.lua - assert_l_out([[ + assert_l_out( + [[ bufs: nvim args: 5 lua args: { "-c", "set wrap?", @@ -244,30 +274,50 @@ describe('startup', function() end) it('disables swapfile/shada/config/plugins', function() - assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1\n', + assert_l_out( + 'updatecount=0 shadafile=NONE loadplugins=false scripts=1\n', nil, nil, '-', [[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())))]]) + 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' }) + 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', - '--cmd', nvim_set, - '-c', [[echo has('ttyin') has('ttyout')]], - '+q' }) + local out = funcs.system({ + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '--cmd', + nvim_set, + '-c', + [[echo has('ttyin') has('ttyout')]], + '+q', + }) eq('0 0', out) end) @@ -292,10 +342,14 @@ describe('startup', function() -- Running in :terminal funcs.termopen({ nvim_prog, - '-u', 'NONE', - '-i', 'NONE', - '--cmd', nvim_set, - '-c', 'echo has("ttyin") has("ttyout")', + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + nvim_set, + '-c', + 'echo has("ttyin") has("ttyout")', }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), @@ -318,17 +372,24 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen(([["%s" -u NONE -i NONE --cmd "%s"]] - ..[[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] - ..[[ -c q | cat -v]]):format(nvim_prog, nvim_set), { - env = { - VIMRUNTIME = os.getenv('VIMRUNTIME'), - }, - }) + funcs.termopen( + ( + [["%s" -u NONE -i NONE --cmd "%s"]] + .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] + .. [[ -c q | cat -v]] + ):format(nvim_prog, nvim_set), + { + env = { + VIMRUNTIME = os.getenv('VIMRUNTIME'), + }, + } + ) retry(nil, 3000, function() sleep(1) - eq('1\n0\n', -- stdin is a TTY, stdout is a pipe - read_file('Xtest_startup_ttyout')) + eq( + '1\n0\n', -- stdin is a TTY, stdout is a pipe + read_file('Xtest_startup_ttyout') + ) end) end) @@ -341,18 +402,25 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen(([[echo foo | ]] -- Input from a pipe. - ..[["%s" -u NONE -i NONE --cmd "%s"]] - ..[[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] - ..[[ -c q -- -]]):format(nvim_prog, nvim_set), { - env = { - VIMRUNTIME = os.getenv('VIMRUNTIME'), - }, - }) + funcs.termopen( + ( + [[echo foo | ]] -- Input from a pipe. + .. [["%s" -u NONE -i NONE --cmd "%s"]] + .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] + .. [[ -c q -- -]] + ):format(nvim_prog, nvim_set), + { + env = { + VIMRUNTIME = os.getenv('VIMRUNTIME'), + }, + } + ) retry(nil, 3000, function() sleep(1) - eq('0\n1\n', -- stdin is a pipe, stdout is a TTY - read_file('Xtest_startup_ttyout')) + eq( + '0\n1\n', -- stdin is a pipe, stdout is a TTY + read_file('Xtest_startup_ttyout') + ) end) end) @@ -363,13 +431,18 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - funcs.termopen(([[echo foo | ]] - .. [["%s" -u NONE -i NONE --cmd "%s"]] - .. [[ -c "echo has('ttyin') has('ttyout')"]]):format(nvim_prog, nvim_set), { - env = { - VIMRUNTIME = os.getenv('VIMRUNTIME'), - }, - }) + funcs.termopen( + ( + [[echo foo | ]] + .. [["%s" -u NONE -i NONE --cmd "%s"]] + .. [[ -c "echo has('ttyin') has('ttyout')"]] + ):format(nvim_prog, nvim_set), + { + env = { + VIMRUNTIME = os.getenv('VIMRUNTIME'), + }, + } + ) screen:expect([[ ^foo | ~ | @@ -379,28 +452,44 @@ describe('startup', function() end) it('input from pipe + file args #7679', function() - eq('ohyeah\r\n0 0 bufs=3', - funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', - '+.print', - "+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')", - '+qall!', - '-', - 'test/functional/fixtures/tty-test.c', - 'test/functional/fixtures/shell-test.c', - }, - { 'ohyeah', '' })) + eq( + 'ohyeah\r\n0 0 bufs=3', + funcs.system({ + nvim_prog, + '-n', + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '+.print', + "+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')", + '+qall!', + '-', + 'test/functional/fixtures/tty-test.c', + 'test/functional/fixtures/shell-test.c', + }, { 'ohyeah', '' }) + ) end) it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function() - eq('\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', - funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', - '+ls!', - '+qall!', - '-', - 'file1', - 'file2', - }, - { '' })) + eq( + '\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', + funcs.system({ + nvim_prog, + '-n', + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '+ls!', + '+qall!', + '-', + 'file1', + 'file2', + }, { '' }) + ) end) it('stdin with -es/-Es #7679', function() @@ -410,48 +499,70 @@ describe('startup', function() -- -- -Es: read stdin as text -- - eq('partylikeits1999\n', - funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' }, - { 'partylikeits1999', '' })) - eq(inputstr, - funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, - input)) + eq( + 'partylikeits1999\n', + funcs.system({ + nvim_prog, + '-n', + '-u', + 'NONE', + '-i', + 'NONE', + '-Es', + '+.print', + 'test/functional/fixtures/tty-test.c', + }, { 'partylikeits1999', '' }) + ) + eq(inputstr, funcs.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) -- with `-u NORC` - eq('thepartycontinues\n', - funcs.system({nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, - { 'thepartycontinues', '' })) + eq( + 'thepartycontinues\n', + funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) + ) -- without `-u` - eq('thepartycontinues\n', - funcs.system({nvim_prog, '-n', '-Es', '+.print' }, - { 'thepartycontinues', '' })) + eq( + 'thepartycontinues\n', + funcs.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) + ) -- -- -es: read stdin as ex-commands -- - eq(' encoding=utf-8\n', - funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-es', 'test/functional/fixtures/tty-test.c' }, - { 'set encoding', '' })) - eq('line1\nline2\n', - funcs.system({nvim_prog, '-i', 'NONE', '-es', '-' }, - input)) + eq( + ' encoding=utf-8\n', + funcs.system({ + nvim_prog, + '-n', + '-u', + 'NONE', + '-i', + 'NONE', + '-es', + 'test/functional/fixtures/tty-test.c', + }, { 'set encoding', '' }) + ) + eq('line1\nline2\n', funcs.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) -- with `-u NORC` - eq(' encoding=utf-8\n', - funcs.system({nvim_prog, '-n', '-u', 'NORC', '-es' }, - { 'set encoding', '' })) + eq( + ' encoding=utf-8\n', + funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) + ) -- without `-u` - eq(' encoding=utf-8\n', - funcs.system({nvim_prog, '-n', '-es' }, - { 'set encoding', '' })) + eq(' encoding=utf-8\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) end) it('-es/-Es disables swapfile, user config #8540', function() - for _,arg in ipairs({'-es', '-Es'}) do - local out = funcs.system({nvim_prog, arg, - '+set swapfile? updatecount? shadafile?', - "+put =map(getscriptinfo(), {-> v:val.name})", '+%print'}) + for _, arg in ipairs({ '-es', '-Es' }) do + local out = funcs.system({ + nvim_prog, + arg, + '+set swapfile? updatecount? shadafile?', + '+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) + eq(' swapfile updatecount=0 shadafile=\n', line1) -- Standard plugins were loaded, but not user config. ok(string.find(out, 'man.lua') ~= nil) ok(string.find(out, 'init.vim') == nil) @@ -459,12 +570,18 @@ describe('startup', function() 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' })) - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({nvim_prog, '--embed', '-Es' })) - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) + matches( + 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({ nvim_prog, '--embed', '-es' }) + ) + matches( + 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({ nvim_prog, '--embed', '-Es' }) + ) + matches( + 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) + ) end) it('ENTER dismisses early message #7967', function() @@ -473,10 +590,14 @@ describe('startup', function() screen:attach() local id = funcs.termopen({ nvim_prog, - '-u', 'NONE', - '-i', 'NONE', - '--cmd', 'set noruler', - '--cmd', 'let g:foo = g:bar', + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'set noruler', + '--cmd', + 'let g:foo = g:bar', }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), @@ -530,19 +651,32 @@ describe('startup', function() expected, -- FIXME(codehex): We should really set a timeout for the system function. -- If this test fails, there will be a waiting input state. - funcs.system({nvim_prog, '-u', 'NONE', '-c', + funcs.system({ + nvim_prog, + '-u', + 'NONE', + '-c', 'for i in range(1, 100) | echo i | endfor | quit', - '--headless' + '--headless', }) ) end) - it("get command line arguments from v:argv", function() - local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', - '--cmd', nvim_set, - '-c', [[echo v:argv[-1:] len(v:argv) > 1]], - '+q' }) - eq('[\'+q\'] 1', out) + it('get command line arguments from v:argv', function() + local out = funcs.system({ + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '--cmd', + nvim_set, + '-c', + [[echo v:argv[-1:] len(v:argv) > 1]], + '+q', + }) + eq("['+q'] 1", out) end) end) @@ -574,20 +708,20 @@ describe('startup', function() clear('-e') screen:attach() -- Verify we set the proper mode both before and after :vi. - feed("put =mode(1)vi:put =mode(1)") + feed('put =mode(1)vi:put =mode(1)') screen:expect([[ cv | ^n | :put =mode(1) | ]]) - eq('cv\n', - funcs.system({nvim_prog, '-n', '-es' }, - { 'put =mode(1)', 'print', '' })) + 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', [[ + write_file( + 'Xdiff.vim', + [[ let bufnr = nvim_create_buf(0, 1) let config = { \ 'relative': 'editor', @@ -597,78 +731,92 @@ describe('startup', function() \ 'row': 3, \ 'col': 3 \ } - autocmd WinEnter * call nvim_open_win(bufnr, v:false, config)]]) + 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)})) + 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})) + eq(false, meths.get_option_value('diff', { win = float_win })) end) it('does not crash if --embed is given twice', function() - clear{args={'--embed'}} + clear { args = { '--embed' } } assert_alive() end) it('does not crash when expanding cdpath during early_init', function() - clear{env={CDPATH='~doesnotexist'}} + 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'}}) + clear({ args = { '-p', 'a', 'b', 'c' } }) local screen = Screen.new(25, 4) screen:attach() - screen:expect({grid=[[ + 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}, - }}) + 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/'}, - args_rm={'runtimepath'}, + 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/' }, + args_rm = { 'runtimepath' }, } end - it("handles &packpath during startup", function() + it('handles &packpath during startup', function() pack_clear [[ let g:x = bar#test() let g:y = leftpad#pad("heyya") ]] eq(-3, eval 'g:x') - eq(" heyya", eval 'g:y') + eq(' heyya', eval 'g:y') pack_clear [[ lua _G.y = require'bar'.doit() _G.z = require'leftpad''howdy' ]] - eq({9003, '\thowdy'}, exec_lua [[ return { _G.y, _G.z } ]]) + eq({ 9003, '\thowdy' }, exec_lua [[ return { _G.y, _G.z } ]]) end) - it("handles require from &packpath in an async handler", function() - -- NO! you cannot just speed things up by calling async functions during startup! - -- It doesn't make anything actually faster! NOOOO! + it('handles require from &packpath in an async handler', function() + -- NO! you cannot just speed things up by calling async functions during startup! + -- It doesn't make anything actually faster! NOOOO! pack_clear [[ lua require'async_leftpad'('brrrr', 'async_res') ]] -- haha, async leftpad go brrrrr eq('\tbrrrr', exec_lua [[ return _G.async_res ]]) end) - it("handles :packadd during startup", function() + it('handles :packadd during startup', function() -- control group: opt/bonus is not available by default pack_clear [[ try @@ -680,8 +828,10 @@ describe('startup', function() eq('Vim(let):E117: Unknown function: bonus#secret', eval 'g:err') pack_clear [[ lua _G.test = {pcall(function() require'bonus'.launch() end)} ]] - eq({false, [[[string ":lua"]:1: module 'bonus' not found:]]}, - exec_lua [[ _G.test[2] = string.gsub(_G.test[2], '[\r\n].*', '') return _G.test ]]) + eq( + { false, [[[string ":lua"]:1: module 'bonus' not found:]] }, + exec_lua [[ _G.test[2] = string.gsub(_G.test[2], '[\r\n].*', '') return _G.test ]] + ) -- ok, time to launch the nukes: pack_clear [[ packadd! bonus | let g:x = bonus#secret() ]] @@ -691,46 +841,77 @@ describe('startup', function() eq('CPE 1704 TKS', exec_lua [[ return _G.y ]]) end) - it("handles the correct order with start packages and after/", function() + it('handles the correct order with start packages and after/', function() pack_clear [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]] - eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq( + { 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' }, + exec_lua [[ return _G.test_loadorder ]] + ) end) - it("handles the correct order with start packages and after/ after startup", function() + it('handles the correct order with start packages and after/ after startup', function() pack_clear [[ lua _G.test_loadorder = {} ]] command [[ runtime! filen.lua ]] - eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq( + { 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' }, + exec_lua [[ return _G.test_loadorder ]] + ) end) - it("handles the correct order with globpath(&rtp, ...)", function() + it('handles the correct order with globpath(&rtp, ...)', function() pack_clear [[ set loadplugins | lua _G.test_loadorder = {} ]] command [[ for x in globpath(&rtp, "filen.lua",1,1) call v:lua.dofile(x) endfor ]] - eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq( + { 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' }, + exec_lua [[ return _G.test_loadorder ]] + ) 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) + 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) - it("handles the correct order with opt packages and after/", function() + it('handles the correct order with opt packages and after/', function() pack_clear [[ lua _G.test_loadorder = {} vim.cmd "packadd! superspecial\nruntime! filen.lua" ]] - eq({'ordinary', 'SuperSpecial', 'FANCY', 'mittel', 'FANCY after', 'SuperSpecial after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq({ + 'ordinary', + 'SuperSpecial', + 'FANCY', + 'mittel', + 'FANCY after', + 'SuperSpecial after', + 'ordinary after', + }, exec_lua [[ return _G.test_loadorder ]]) end) - it("handles the correct order with opt packages and after/ after startup", function() + it('handles the correct order with opt packages and after/ after startup', function() pack_clear [[ lua _G.test_loadorder = {} ]] command [[ packadd! superspecial runtime! filen.lua ]] - eq({'ordinary', 'SuperSpecial', 'FANCY', 'mittel', 'FANCY after', 'SuperSpecial after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq({ + 'ordinary', + 'SuperSpecial', + 'FANCY', + 'mittel', + 'FANCY after', + 'SuperSpecial after', + 'ordinary after', + }, exec_lua [[ return _G.test_loadorder ]]) end) - it("handles the correct order with opt packages and globpath(&rtp, ...)", function() + it('handles the correct order with opt packages and globpath(&rtp, ...)', function() pack_clear [[ set loadplugins | lua _G.test_loadorder = {} ]] command [[ packadd! superspecial @@ -738,18 +919,40 @@ describe('startup', function() call v:lua.dofile(x) endfor ]] - eq({'ordinary', 'SuperSpecial', 'FANCY', 'mittel', 'SuperSpecial after', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + eq({ + 'ordinary', + 'SuperSpecial', + 'FANCY', + 'mittel', + 'SuperSpecial after', + 'FANCY after', + 'ordinary after', + }, exec_lua [[ return _G.test_loadorder ]]) end) - it("handles the correct order with a package that changes packpath", function() + it('handles the correct order with a package that changes packpath', function() pack_clear [[ lua _G.test_loadorder = {} vim.cmd "packadd! funky\nruntime! filen.lua" ]] - eq({'ordinary', 'funky!', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) - eq({'ordinary', 'funky!', 'mittel', 'ordinary after'}, exec_lua [[ return _G.nested_order ]]) + eq( + { 'ordinary', 'funky!', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' }, + exec_lua [[ return _G.test_loadorder ]] + ) + eq({ 'ordinary', 'funky!', 'mittel', 'ordinary after' }, exec_lua [[ return _G.nested_order ]]) end) - it("handles the correct order when prepending packpath", function() - clear{args={'--cmd', 'set packpath^=test/functional/fixtures', '--cmd', [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} - eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) + it('handles the correct order when prepending packpath', function() + clear { + args = { + '--cmd', + 'set packpath^=test/functional/fixtures', + '--cmd', + [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]], + }, + env = { XDG_CONFIG_HOME = 'test/functional/fixtures/' }, + } + eq( + { 'ordinary', 'FANCY', 'FANCY after', 'ordinary after' }, + exec_lua [[ return _G.test_loadorder ]] + ) end) it('window widths are correct when modelines set &columns with tabpages', function() @@ -759,7 +962,7 @@ describe('startup', function() os.remove('Xtab1.noft') os.remove('Xtab2.noft') end) - clear({args = {'-p', 'Xtab1.noft', 'Xtab2.noft'}}) + clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } }) eq(81, meths.win_get_width(0)) command('tabnext') eq(81, meths.win_get_width(0)) @@ -779,16 +982,22 @@ describe('sysinit', function() mkdir(xdgdir) mkdir(xdgdir .. pathsep .. 'nvim') - write_file(table.concat({xdgdir, 'nvim', 'sysinit.vim'}, pathsep), [[ + write_file( + table.concat({ xdgdir, 'nvim', 'sysinit.vim' }, pathsep), + [[ let g:loaded = get(g:, "loaded", 0) + 1 let g:xdg = 1 - ]]) + ]] + ) mkdir(vimdir) - write_file(table.concat({vimdir, 'sysinit.vim'}, pathsep), [[ + write_file( + table.concat({ vimdir, 'sysinit.vim' }, pathsep), + [[ let g:loaded = get(g:, "loaded", 0) + 1 let g:vim = 1 - ]]) + ]] + ) mkdir(xhome) end) @@ -799,23 +1008,27 @@ describe('sysinit', function() end) it('prefers XDG_CONFIG_DIRS over VIM', function() - clear{args={'--cmd', 'set nomore undodir=. directory=. belloff='}, - args_rm={'-u', '--cmd'}, - env={ HOME=xhome, - XDG_CONFIG_DIRS=xdgdir, - VIM=vimdir }} - eq('loaded 1 xdg 1 vim 0', - eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')) + clear { + args = { '--cmd', 'set nomore undodir=. directory=. belloff=' }, + args_rm = { '-u', '--cmd' }, + env = { HOME = xhome, XDG_CONFIG_DIRS = xdgdir, VIM = vimdir }, + } + eq( + 'loaded 1 xdg 1 vim 0', + eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))') + ) end) it('uses VIM if XDG_CONFIG_DIRS unset', function() - clear{args={'--cmd', 'set nomore undodir=. directory=. belloff='}, - args_rm={'-u', '--cmd'}, - env={ HOME=xhome, - XDG_CONFIG_DIRS='', - VIM=vimdir }} - 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))')) + clear { + args = { '--cmd', 'set nomore undodir=. directory=. belloff=' }, + args_rm = { '-u', '--cmd' }, + env = { HOME = xhome, XDG_CONFIG_DIRS = '', VIM = vimdir }, + } + 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) @@ -824,8 +1037,8 @@ describe('user config init', function() local pathsep = helpers.get_pathsep() local xconfig = xhome .. pathsep .. 'Xconfig' local xdata = xhome .. pathsep .. 'Xdata' - local init_lua_path = table.concat({xconfig, 'nvim', 'init.lua'}, pathsep) - local xenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } + local init_lua_path = table.concat({ xconfig, 'nvim', 'init.lua' }, pathsep) + local xenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } before_each(function() rmdir(xhome) @@ -833,9 +1046,12 @@ describe('user config init', function() mkdir_p(xconfig .. pathsep .. 'nvim') mkdir_p(xdata) - write_file(init_lua_path, [[ + write_file( + init_lua_path, + [[ vim.g.lua_rc = 1 - ]]) + ]] + ) end) after_each(function() @@ -843,7 +1059,7 @@ 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')) @@ -852,27 +1068,42 @@ describe('user config init', 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 xstateenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata, XDG_STATE_HOME = xstate } local function setup_exrc_file(filename) exrc_path = filename - if string.find(exrc_path, "%.lua$") then - write_file(exrc_path, string.format([[ + if string.find(exrc_path, '%.lua$') then + write_file( + exrc_path, + string.format( + [[ vim.g.exrc_file = "%s" - ]], exrc_path)) + ]], + exrc_path + ) + ) else - write_file(exrc_path, string.format([[ + write_file( + exrc_path, + string.format( + [[ let g:exrc_file = "%s" - ]], exrc_path)) + ]], + exrc_path + ) + ) end end before_each(function() - write_file(init_lua_path, [[ + write_file( + init_lua_path, + [[ vim.o.exrc = true vim.g.exrc_file = '---' - ]]) + ]] + ) mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) end) @@ -885,13 +1116,13 @@ describe('user config init', function() it(filename .. ' in cwd', function() setup_exrc_file(filename) - clear{ args_rm={'-u'}, env=xstateenv } + 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')) local screen = Screen.new(50, 8) screen:attach() - funcs.termopen({nvim_prog}, { + funcs.termopen({ nvim_prog }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -907,15 +1138,19 @@ describe('user config init', function() -- TERMINAL -- | ]]) feed(':echo g:exrc_file') - screen:expect(string.format([[ + screen:expect(string.format( + [[ | ~ |*4 [No Name] 0,0-1 All| %s%s| -- TERMINAL -- | - ]], filename, string.rep(' ', 50 - #filename))) + ]], + filename, + string.rep(' ', 50 - #filename) + )) - clear{ args_rm={'-u'}, env=xstateenv } + clear { args_rm = { '-u' }, env = xstateenv } -- The 'exrc' file is now trusted. eq(filename, eval('g:exrc_file')) end) @@ -923,15 +1158,18 @@ describe('user config init', function() end) describe('with explicitly provided config', function() - local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) + local custom_lua_path = table.concat({ xhome, 'custom.lua' }, pathsep) before_each(function() - write_file(custom_lua_path, [[ + write_file( + custom_lua_path, + [[ vim.g.custom_lua_rc = 1 - ]]) + ]] + ) end) it('loads custom lua config and does not set $MYVIMRC', function() - clear{ args={'-u', custom_lua_path }, env=xenv } + clear { args = { '-u', custom_lua_path }, env = xenv } eq(1, eval('g:custom_lua_rc')) eq('', eval('$MYVIMRC')) end) @@ -939,14 +1177,17 @@ describe('user config init', function() describe('VIMRC also exists', function() before_each(function() - write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[ + write_file( + table.concat({ xconfig, 'nvim', 'init.vim' }, pathsep), + [[ let g:vim_rc = 1 - ]]) + ]] + ) end) it('loads default lua config, but shows an error', function() - clear{ args_rm={'-u'}, env=xenv } - feed('') -- Dismiss "Conflicting config …" message. + clear { args_rm = { '-u' }, env = xenv } + feed('') -- Dismiss "Conflicting config …" message. eq(1, eval('g:lua_rc')) matches('^E5422: Conflicting configs', exec_capture('messages')) end) @@ -958,7 +1199,7 @@ describe('runtime:', function() local pathsep = helpers.get_pathsep() local xconfig = xhome .. pathsep .. 'Xconfig' local xdata = xhome .. pathsep .. 'Xdata' - local xenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } + local xenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } setup(function() rmdir(xhome) @@ -971,23 +1212,24 @@ describe('runtime:', function() end) it('loads plugin/*.lua from XDG config home', function() - local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) - local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) + 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 } + clear { args_rm = { '-u' }, env = xenv } eq(1, eval('g:lua_plugin')) end) it('loads plugin/*.lua from start packages', function() - 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_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 profiler_file = 'test_startuptime.log' mkdir_p(plugin_folder_path) finally(function() @@ -997,12 +1239,16 @@ describe('runtime:', function() write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) - clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv } + clear { args_rm = { '-u' }, args = { '--startuptime', profiler_file }, env = xenv } eq(2, eval('g:lua_plugin')) -- 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) + 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') @@ -1012,12 +1258,13 @@ describe('runtime:', function() end) it('loads plugin/*.lua from site packages', function() - local nvimdata = is_os('win') and "nvim-data" or "nvim" - local plugin_path = table.concat({xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb'}, pathsep) - local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) - 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) + local nvimdata = is_os('win') and 'nvim-data' or 'nvim' + local plugin_path = + table.concat({ xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb' }, pathsep) + local plugin_folder_path = table.concat({ plugin_path, 'plugin' }, pathsep) + 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) mkdir_p(plugin_after_path) finally(function() @@ -1027,49 +1274,64 @@ describe('runtime:', function() 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 } + clear { args_rm = { '-u' }, args = { '--cmd', 'lua _G.lista = {}' }, env = xenv } - eq({'unos', 'dos'}, exec_lua "return _G.lista") + eq({ 'unos', 'dos' }, exec_lua 'return _G.lista') end) it('no crash setting &rtp in plugins with :packloadall called before #18315', function() - local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) + 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), [[ + 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), [[ + ]] + ) + write_file( + table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep), + [[ vim.o.runtimepath = vim.o.runtimepath vim.g.lua_plugin = 1 - ]]) + ]] + ) - clear{ args_rm={'-u'}, args = {'--cmd', 'packloadall'}, env=xenv } + clear { args_rm = { '-u' }, args = { '--cmd', 'packloadall' }, env = xenv } eq(1, eval('g:vim_plugin')) eq(1, eval('g:lua_plugin')) end) 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) + 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 } + -- 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) @@ -1077,15 +1339,18 @@ end) describe('user session', function() local xhome = 'Xhome' local pathsep = helpers.get_pathsep() - local session_file = table.concat({xhome, 'session.lua'}, pathsep) + local session_file = table.concat({ xhome, 'session.lua' }, pathsep) before_each(function() rmdir(xhome) mkdir(xhome) - write_file(session_file, [[ + write_file( + session_file, + [[ vim.g.lua_session = 1 - ]]) + ]] + ) end) after_each(function() @@ -1093,7 +1358,7 @@ describe('user session', function() end) it('loads session from the provided lua file', function() - clear{ args={'-S', session_file }, env={ HOME=xhome }} + clear { args = { '-S', session_file }, env = { HOME = xhome } } eq(1, eval('g:lua_session')) end) end) @@ -1104,18 +1369,27 @@ describe('inccommand on ex mode', function() local screen screen = Screen.new(60, 10) screen:attach() - local id = funcs.termopen({ nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' }, { - env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } - }) + local id = funcs.termopen( + { nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' }, + { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, + } + ) funcs.chansend(id, '%s/N') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1:^ }| {1: }|*6 {1:Entering Ex mode. Type "visual" to go to Normal mode. }| {1::%s/N }| | - ]], attr_ids={ - [1] = {background = Screen.colors.NvimDarkGrey2, foreground = Screen.colors.NvimLightGrey2}; - }} + ]], + attr_ids = { + [1] = { + background = Screen.colors.NvimDarkGrey2, + foreground = Screen.colors.NvimLightGrey2, + }, + }, + } end) end) diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index b964fb3467..92a00b28b6 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -30,13 +30,15 @@ describe('K', function() set keywordprg=echo\ fnord>>]]) -- K on the text "K_spec_out" resolves to `!echo fnord >> K_spec_out`. - feed('i'..test_file..'K') - retry(nil, nil, function() eq(1, eval('filereadable("'..test_file..'")')) end) - eq({'fnord'}, eval("readfile('"..test_file.."')")) + feed('i' .. test_file .. 'K') + retry(nil, nil, function() + eq(1, eval('filereadable("' .. test_file .. '")')) + end) + eq({ 'fnord' }, eval("readfile('" .. test_file .. "')")) -- Confirm that Neovim is still in terminal mode after K is pressed (#16692). helpers.sleep(500) eq('t', eval('mode()')) - feed('') -- Any key, not just , can be used here to escape. + feed('') -- Any key, not just , can be used here to escape. eq('n', eval('mode()')) end) @@ -60,9 +62,8 @@ describe('K', function() it('empty string falls back to :help #19298', function() meths.set_option_value('keywordprg', '', {}) - meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'}) + meths.buf_set_lines(0, 0, -1, true, { 'doesnotexist' }) feed('K') eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg')) end) - end) diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 8f14a2db83..fbb63fdba6 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -18,17 +18,17 @@ describe('completion', function() screen = Screen.new(60, 8) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {background = Screen.colors.LightMagenta}, - [2] = {background = Screen.colors.Grey}, - [3] = {bold = true}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen}, - [5] = {foreground = Screen.colors.Red}, - [6] = {background = Screen.colors.Black}, - [7] = {foreground = Screen.colors.White, background = Screen.colors.Red}, - [8] = {reverse = true}, - [9] = {bold = true, reverse = true}, - [10] = {foreground = Screen.colors.Grey0, background = Screen.colors.Yellow}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.LightMagenta }, + [2] = { background = Screen.colors.Grey }, + [3] = { bold = true }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen }, + [5] = { foreground = Screen.colors.Red }, + [6] = { background = Screen.colors.Black }, + [7] = { foreground = Screen.colors.White, background = Screen.colors.Red }, + [8] = { reverse = true }, + [9] = { bold = true, reverse = true }, + [10] = { foreground = Screen.colors.Grey0, background = Screen.colors.Yellow }, }) end) @@ -57,9 +57,10 @@ describe('completion', function() it('returns expected dict in normal completion', function() feed('ifooo') eq('foo', eval('getline(2)')) - eq({word = 'foo', abbr = '', menu = '', - info = '', kind = '', user_data = ''}, - eval('v:completed_item')) + eq( + { word = 'foo', abbr = '', menu = '', info = '', kind = '', user_data = '' }, + eval('v:completed_item') + ) end) it('is readonly', function() screen:try_resize(80, 8) @@ -107,9 +108,14 @@ describe('completion', function() {0:~ }|*4 {3:-- Omni completion (^O^N^P) }{4:match 1 of 2} | ]]) - eq({word = 'foo', abbr = 'bar', menu = 'baz', - info = 'foobar', kind = 'foobaz', user_data = ''}, - eval('v:completed_item')) + eq({ + word = 'foo', + abbr = 'bar', + menu = 'baz', + info = 'foobar', + kind = 'foobaz', + user_data = '', + }, eval('v:completed_item')) end) end) @@ -286,8 +292,8 @@ describe('completion', function() end) local tests = { - [', , '] = {'', ''}, - [', , '] = {'', ''}, + [', , '] = { '', '' }, + [', , '] = { '', '' }, } for name, seq in pairs(tests) do @@ -303,13 +309,13 @@ describe('completion', function() feed('AA') local expected = { - {'foo', 'bar', 'foo'}, - {'foo', 'bar', 'ccc'}, - {'foo', 'bar'}, - {'foo', 'bbb'}, - {'foo'}, - {'aaa'}, - {''}, + { 'foo', 'bar', 'foo' }, + { 'foo', 'bar', 'ccc' }, + { 'foo', 'bar' }, + { 'foo', 'bbb' }, + { 'foo' }, + { 'aaa' }, + { '' }, } for i = 1, #expected do @@ -329,7 +335,7 @@ describe('completion', function() end end) - describe("refresh:always", function() + describe('refresh:always', function() before_each(function() source([[ function! TestCompletion(findstart, base) abort @@ -354,9 +360,9 @@ describe('completion', function() set completeopt=menuone,noselect set completefunc=TestCompletion ]]) - end ) + end) - it('completes on each input char', function () + it('completes on each input char', function() feed('i') screen:expect([[ ^ | @@ -402,7 +408,7 @@ describe('completion', function() expect('August') end) - it("repeats correctly after backspace #2674", function () + it('repeats correctly after backspace #2674', function() feed('oJa') screen:expect([[ | @@ -471,10 +477,10 @@ describe('completion', function() return '' endfunction ]]) - feed_command("set completeopt=menuone,noselect") + feed_command('set completeopt=menuone,noselect') end) - it("works", function() + it('works', function() feed('i=TestComplete()') screen:expect([[ ^ | @@ -630,7 +636,7 @@ describe('completion', function() end) end) - it("does not indent until an item is selected #8345", function () + it('does not indent until an item is selected #8345', function() -- Indents on "ind", unindents on "unind". source([[ function! TestIndent() @@ -649,14 +655,14 @@ describe('completion', function() ]]) -- Give some words to complete. - feed("iinc uninc indent unindent") + feed('iinc uninc indent unindent') -- Does not indent when "ind" is typed. - feed("in") + feed('in') -- Completion list is generated incorrectly if we send everything at once -- via nvim_input(). So poke_eventloop() before sending . #8480 poke_eventloop() - feed("d") + feed('d') screen:expect([[ inc uninc indent unindent | @@ -667,7 +673,7 @@ describe('completion', function() ]]) -- Indents when the item is selected - feed("") + feed('') screen:expect([[ inc uninc indent unindent | indent^ | @@ -675,7 +681,7 @@ describe('completion', function() {3:-- INSERT --} | ]]) -- Indents when completion is exited using ESC. - feed("ind") + feed('ind') screen:expect([[ inc uninc indent unindent | indent | @@ -684,9 +690,9 @@ describe('completion', function() | ]]) -- Works for unindenting too. - feed("ounin") + feed('ounin') helpers.poke_eventloop() - feed("d") + feed('d') screen:expect([[ inc uninc indent unindent | indent | @@ -697,7 +703,7 @@ describe('completion', function() {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) -- Works when going back and forth. - feed("c") + feed('c') screen:expect([[ inc uninc indent unindent | indent | @@ -707,7 +713,7 @@ describe('completion', function() {0:~ }|*2 {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) - feed("d") + feed('d') screen:expect([[ inc uninc indent unindent | indent | @@ -717,7 +723,7 @@ describe('completion', function() {0:~ }|*2 {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) - feed("") + feed('') screen:expect([[ inc uninc indent unindent | indent | @@ -728,8 +734,8 @@ describe('completion', function() ]]) end) - it('disables folding during completion', function () - feed_command("set foldmethod=indent") + it('disables folding during completion', function() + feed_command('set foldmethod=indent') feed('ifoobargg') screen:expect([[ ^foo | @@ -747,8 +753,8 @@ describe('completion', function() eq(-1, eval('foldclosed(1)')) end) - it('popupmenu is not interrupted by events', function () - feed_command("set complete=.") + it('popupmenu is not interrupted by events', function() + feed_command('set complete=.') feed('ifoobar fooeggf') screen:expect([[ @@ -762,14 +768,17 @@ describe('completion', function() assert_alive() -- popupmenu still visible - screen:expect{grid=[[ + screen:expect { + grid = [[ foobar fooegg | fooegg^ | {1:foobar }{0: }| {2:fooegg }{0: }| {0:~ }|*3 {3:-- Keyword completion (^N^P) }{4:match 1 of 2} | - ]], unchanged=true} + ]], + unchanged = true, + } feed('') -- Didn't restart completion: old matches still used @@ -787,47 +796,52 @@ describe('completion', function() it('expands when there is only one match', function() feed(':lua CURRENT_TESTING_VAR = 1') feed(':lua CURRENT_TESTING_') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*6 :lua CURRENT_TESTING_VAR^ | - ]]} + ]], + } end) it('expands when there is only one match', function() feed(':lua CURRENT_TESTING_FOO = 1') feed(':lua CURRENT_TESTING_BAR = 1') feed(':lua CURRENT_TESTING_') - screen:expect{ grid = [[ + screen:expect { + grid = [[ | {0:~ }|*5 {10:CURRENT_TESTING_BAR}{9: CURRENT_TESTING_FOO }| :lua CURRENT_TESTING_BAR^ | - ]], unchanged = true } + ]], + unchanged = true, + } end) it('provides completion from `getcompletion()`', function() - eq({'vim'}, funcs.getcompletion('vi', 'lua')) - eq({'api'}, funcs.getcompletion('vim.ap', 'lua')) - eq({'tbl_filter'}, funcs.getcompletion('vim.tbl_fil', 'lua')) - eq({'vim'}, funcs.getcompletion('print(vi', 'lua')) + eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) + eq({ 'api' }, funcs.getcompletion('vim.ap', 'lua')) + eq({ 'tbl_filter' }, funcs.getcompletion('vim.tbl_fil', 'lua')) + eq({ 'vim' }, funcs.getcompletion('print(vi', 'lua')) -- fuzzy completion is not supported, so the result should be the same command('set wildoptions+=fuzzy') - eq({'vim'}, funcs.getcompletion('vi', 'lua')) + eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) 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({ '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 () + it('is cleared after CTRL-C', function() feed('q:') feed('ifoo faa fee f') screen:expect([[ @@ -837,7 +851,7 @@ describe('completion', function() {0:~ }|*3 {9:[Command Line] }| {3:-- INSERT --} | - ]] ) + ]]) feed('') screen:expect([[ | @@ -870,16 +884,18 @@ describe('completion', function() endfunction ]]) meths.set_option_value('completeopt', 'menuone,noselect', {}) - meths.set_var('_complist', {{ - word=0, - abbr=1, - menu=2, - kind=3, - info=4, - icase=5, - dup=6, - empty=7, - }}) + meths.set_var('_complist', { + { + word = 0, + abbr = 1, + menu = 2, + kind = 3, + info = 4, + icase = 5, + dup = 6, + empty = 7, + }, + }) end) it('shows correct variant as word', function() @@ -897,7 +913,8 @@ describe('completion', function() feed_command('set ignorecase infercase') feed_command('edit runtime/doc/backers.txt') feed('oX') - screen:expect{grid=[[ + screen:expect { + grid = [[ *backers.txt* Nvim | Xnull^ | {2:Xnull }{6: } | @@ -906,11 +923,12 @@ describe('completion', function() {1:Xpayn }{2: } | {1:Xinity }{2: } | {3:-- Keyword Local completion (^N^P) }{4:match 1 of 7} | - ]]} + ]], + } end) it('CompleteChanged autocommand', function() - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', ''}) + curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', '' }) source([[ set complete=. completeopt=noinsert,noselect,menuone function! OnPumChange() @@ -925,39 +943,45 @@ describe('completion', function() -- v:event.size should be set with ext_popupmenu #20646 screen:set_option('ext_popupmenu', true) feed('Sf') - screen:expect({grid = [[ + screen:expect({ + grid = [[ foo | bar | foobar | f^ | {0:~ }|*3 {3:-- Keyword completion (^N^P) }{5:Back at original} | - ]], popupmenu = { - anchor = { 1, 3, 0 }, - items = { { "foo", "", "", "" }, { "foobar", "", "", "" } }, - pos = -1 - }}) - eq({completed_item = {}, width = 0, - height = 2, size = 2, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + ]], + popupmenu = { + anchor = { 1, 3, 0 }, + items = { { 'foo', '', '', '' }, { 'foobar', '', '', '' } }, + pos = -1, + }, + }) + eq( + { completed_item = {}, width = 0, height = 2, size = 2, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('oob') - screen:expect({grid = [[ + screen:expect({ + grid = [[ foo | bar | foobar | foob^ | {0:~ }|*3 {3:-- Keyword completion (^N^P) }{5:Back at original} | - ]], popupmenu = { - anchor = { 1, 3, 0 }, - items = { { "foobar", "", "", "" } }, - pos = -1 - }}) - eq({completed_item = {}, width = 0, - height = 1, size = 1, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + ]], + popupmenu = { + anchor = { 1, 3, 0 }, + items = { { 'foobar', '', '', '' } }, + pos = -1, + }, + }) + eq( + { completed_item = {}, width = 0, height = 1, size = 1, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('') screen:set_option('ext_popupmenu', false) @@ -972,10 +996,10 @@ describe('completion', function() {0:~ }| {3:-- Keyword completion (^N^P) }{5:Back at original} | ]]) - eq({completed_item = {}, width = 15, - height = 2, size = 2, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + eq( + { completed_item = {}, width = 15, height = 2, size = 2, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('') screen:expect([[ foo | @@ -1028,7 +1052,7 @@ describe('completion', function() end) it('is stopped by :stopinsert from timer #12976', function() - screen:try_resize(32,14) + screen:try_resize(32, 14) command([[call setline(1, ['hello', 'hullo', 'heeee', ''])]]) feed('Gah') screen:expect([[ @@ -1044,7 +1068,7 @@ describe('completion', function() ]]) command([[call timer_start(100, { -> execute('stopinsert') })]]) helpers.sleep(200) - feed('k') -- cursor should move up in Normal mode + feed('k') -- cursor should move up in Normal mode screen:expect([[ hello | hullo | @@ -1084,7 +1108,8 @@ describe('completion', function() screen:try_resize(20, 9) command('set complete+=f | edit foo | edit bar |edit foa |edit .hidden') feed('i') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo^ | {2:foo }{0: }| {1:bar }{0: }| @@ -1092,15 +1117,18 @@ describe('completion', function() {1:.hidden }{0: }| {0:~ }|*3 {3:-- }{4:match 1 of 4} | - ]]} + ]], + } feed('ccf') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo^ | {2:foo }{0: }| {1:foa }{0: }| {0:~ }|*5 {3:-- }{4:match 1 of 2} | - ]]} + ]], + } end) it('restores extmarks if original text is restored #23653', function() diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index c399a35462..0321a21b35 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local poke_eventloop = helpers.poke_eventloop local sleep = helpers.sleep -describe("CTRL-C (mapped)", function() +describe('CTRL-C (mapped)', function() local screen before_each(function() @@ -14,7 +14,7 @@ describe("CTRL-C (mapped)", function() screen:attach() end) - it("interrupts :global", function() + it('interrupts :global', function() -- Crashes luajit. if helpers.skip_fragile(pending) then return @@ -25,7 +25,7 @@ describe("CTRL-C (mapped)", function() nnoremap ]]) - command("silent edit! test/functional/fixtures/bigfile.txt") + command('silent edit! test/functional/fixtures/bigfile.txt') screen:expect([[ ^0000;;Cc;0;BN;;;;;N;NULL;;;; | @@ -37,19 +37,21 @@ describe("CTRL-C (mapped)", function() ]]) local function test_ctrl_c(ms) - feed(":global/^/p") + feed(':global/^/p') screen:sleep(ms) - feed("") - screen:expect{any="Interrupt"} + feed('') + screen:expect { any = 'Interrupt' } end -- The test is time-sensitive. Try different sleep values. - local ms_values = {100, 1000, 10000} + local ms_values = { 100, 1000, 10000 } for i, ms in ipairs(ms_values) do if i < #ms_values then local status, _ = pcall(test_ctrl_c, ms) - if status then break end - else -- Call the last attempt directly. + if status then + break + end + else -- Call the last attempt directly. test_ctrl_c(ms) end end @@ -58,9 +60,9 @@ describe("CTRL-C (mapped)", function() it('interrupts :sleep', function() command('nnoremap ') feed(':sleep 100') - poke_eventloop() -- wait for :sleep to start + poke_eventloop() -- wait for :sleep to start feed('foo') - poke_eventloop() -- wait for input buffer to be flushed + poke_eventloop() -- wait for input buffer to be flushed feed('i') screen:expect([[ ^ | @@ -73,9 +75,9 @@ describe("CTRL-C (mapped)", function() command('nnoremap ') command('nmap ') feed('') - sleep(10) -- wait for the key to enter typeahead + sleep(10) -- wait for the key to enter typeahead feed('foo') - poke_eventloop() -- wait for input buffer to be flushed + poke_eventloop() -- wait for input buffer to be flushed feed('i') screen:expect([[ ^ | diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua index 424ce839a2..3889067fd4 100644 --- a/test/functional/editor/fold_spec.lua +++ b/test/functional/editor/fold_spec.lua @@ -13,8 +13,12 @@ describe('Folds', function() local tempfname = 'Xtest-fold.txt' setup(clear) - before_each(function() command('bwipe! | new') end) - after_each(function() os.remove(tempfname) end) + before_each(function() + command('bwipe! | new') + end) + after_each(function() + os.remove(tempfname) + end) it('manual folding adjusts with filter', function() insert([[ @@ -94,7 +98,8 @@ describe('Folds', function() end it('neither closes nor corrupts folds', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -112,7 +117,9 @@ a a a a - a]], '7,12m0') + a]], + '7,12m0' + ) expect([[ a a @@ -133,7 +140,7 @@ a a a]]) -- lines are not closed, folds are correct - for i = 1,funcs.line('$') do + for i = 1, funcs.line('$') do eq(-1, funcs.foldclosed(i)) if i == 1 or i == 7 or i == 13 then eq(0, funcs.foldlevel(i)) @@ -151,7 +158,8 @@ a end) it("doesn't split a fold when the move is within it", function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -161,24 +169,30 @@ a a a a -a]], '5m6') - eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds()) +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([[ + test_move_indent( + [[ a a a a a a -a]], '4,5m6') - eq({0, 1, 2, 0, 0, 0, 0}, get_folds()) +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([[ + test_move_indent( + [[ a a a @@ -191,12 +205,15 @@ a a a a - a]], '3,4m$') - eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds()) + 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([[ + test_move_indent( + [[ a a a @@ -205,12 +222,15 @@ a a a a - a]], '4m5') - eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds()) + 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([[ + test_move_indent( + [[ a a a @@ -220,34 +240,43 @@ a a a a -a]], '1,3m7') - eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds()) +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([[ + test_move_indent( + [[ a a a a a a -a]], '$m4') - eq({0, 1, 2, 2, 0, 0, 0}, get_folds()) +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([[ + test_move_indent( + [[ a a a a -a]], '2,3m0') - eq({1, 2, 0, 0, 0}, get_folds()) +a]], + '2,3m0' + ) + eq({ 1, 2, 0, 0, 0 }, get_folds()) end) it('handles shifting all remaining folds', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -262,18 +291,23 @@ a]], '2,3m0') a a a -a]], '13m7') - eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds()) +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, [[ + helpers.write_file( + tempfname, + [[ a - a]]) + a]] + ) insert([[ a a @@ -295,13 +329,13 @@ a]], '13m7') a a ]]) - for i = 1,2 do + for i = 1, 2 do eq(1, funcs.foldlevel(i)) end - for i = 3,5 do + for i = 3, 5 do eq(0, funcs.foldlevel(i)) end - for i = 6,8 do + for i = 6, 8 do eq(1, funcs.foldlevel(i)) end end) @@ -356,7 +390,9 @@ a]], '13m7') return 0 endfunction ]]) - helpers.write_file(tempfname, [[ + helpers.write_file( + tempfname, + [[ b b a @@ -364,7 +400,8 @@ a]], '13m7') d a a - c]]) + c]] + ) insert([[ a a @@ -388,7 +425,7 @@ a]], '13m7') it('no folds remain if :delete makes buffer empty #19671', function() command('setlocal foldmethod=manual') - funcs.setline(1, {'foo', 'bar', 'baz'}) + funcs.setline(1, { 'foo', 'bar', 'baz' }) command('2,3fold') command('%delete') eq(0, funcs.foldlevel(1)) diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index dc056cb252..e063924018 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -12,7 +12,7 @@ local curbufmeths = helpers.curbufmeths describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' - local fname2 = fname1..'2' + local fname2 = fname1 .. '2' before_each(clear) after_each(function() os.remove(fname1) @@ -27,7 +27,7 @@ describe('jumplist', function() write_file(fname1, 'first file contents') write_file(fname2, 'second file contents') - command('args '..fname1..' '..fname2) + command('args ' .. fname1 .. ' ' .. fname2) local buf1 = funcs.bufnr(fname1) local buf2 = funcs.bufnr(fname2) @@ -44,7 +44,7 @@ describe('jumplist', function() feed('') eq(buf1, funcs.bufnr('%')) - command('drop '..fname2) + command('drop ' .. fname2) feed('') eq(buf1, funcs.bufnr('%')) end) @@ -56,11 +56,12 @@ describe('jumplist', function() local screen = Screen.new(5, 25) screen:attach() command('set number') - command('edit '..fname1) + command('edit ' .. fname1) feed('35gg') - command('edit '..fname2) + command('edit ' .. fname2) feed('') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: 24 }foobar | {1: 25 }foobar | {1: 26 }foobar | @@ -86,9 +87,11 @@ describe('jumplist', function() {1: 46 }foobar | {1: 47 }foobar | | - ]], attr_ids={ - [1] = {foreground = Screen.colors.Brown}; - }} + ]], + attr_ids = { + [1] = { foreground = Screen.colors.Brown }, + }, + } end) end) @@ -98,9 +101,8 @@ describe("jumpoptions=stack behaves like 'tagstack'", function() feed(':clearjumps') -- Add lines so that we have locations to jump to. - for i = 1,101,1 - do - feed('iLine ' .. i .. '') + for i = 1, 101, 1 do + feed('iLine ' .. i .. '') end -- Jump around to add some locations to the jump list. @@ -115,82 +117,90 @@ describe("jumpoptions=stack behaves like 'tagstack'", function() end) after_each(function() - feed('set jumpoptions=') + feed('set jumpoptions=') end) it('discards the tail when navigating from the middle', function() feed('') feed('') - eq( '' - .. ' jump line col file/text\n' - .. ' 4 102 0 \n' - .. ' 3 1 0 Line 1\n' - .. ' 2 10 0 Line 10\n' - .. ' 1 20 0 Line 20\n' - .. '> 0 30 0 Line 30\n' - .. ' 1 40 0 Line 40\n' - .. ' 2 50 0 Line 50', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 4 102 0 \n' + .. ' 3 1 0 Line 1\n' + .. ' 2 10 0 Line 10\n' + .. ' 1 20 0 Line 20\n' + .. '> 0 30 0 Line 30\n' + .. ' 1 40 0 Line 40\n' + .. ' 2 50 0 Line 50', + exec_capture('jumps') + ) feed('90gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 5 102 0 \n' - .. ' 4 1 0 Line 1\n' - .. ' 3 10 0 Line 10\n' - .. ' 2 20 0 Line 20\n' - .. ' 1 30 0 Line 30\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 5 102 0 \n' + .. ' 4 1 0 Line 1\n' + .. ' 3 10 0 Line 10\n' + .. ' 2 20 0 Line 20\n' + .. ' 1 30 0 Line 30\n' + .. '>', + exec_capture('jumps') + ) end) it('does not add the same location twice adjacently', function() feed('60gg') feed('60gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 7 102 0 \n' - .. ' 6 1 0 Line 1\n' - .. ' 5 10 0 Line 10\n' - .. ' 4 20 0 Line 20\n' - .. ' 3 30 0 Line 30\n' - .. ' 2 40 0 Line 40\n' - .. ' 1 50 0 Line 50\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 7 102 0 \n' + .. ' 6 1 0 Line 1\n' + .. ' 5 10 0 Line 10\n' + .. ' 4 20 0 Line 20\n' + .. ' 3 30 0 Line 30\n' + .. ' 2 40 0 Line 40\n' + .. ' 1 50 0 Line 50\n' + .. '>', + exec_capture('jumps') + ) end) it('does add the same location twice nonadjacently', function() feed('10gg') feed('20gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 8 102 0 \n' - .. ' 7 1 0 Line 1\n' - .. ' 6 10 0 Line 10\n' - .. ' 5 20 0 Line 20\n' - .. ' 4 30 0 Line 30\n' - .. ' 3 40 0 Line 40\n' - .. ' 2 50 0 Line 50\n' - .. ' 1 10 0 Line 10\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 8 102 0 \n' + .. ' 7 1 0 Line 1\n' + .. ' 6 10 0 Line 10\n' + .. ' 5 20 0 Line 20\n' + .. ' 4 30 0 Line 30\n' + .. ' 3 40 0 Line 40\n' + .. ' 2 50 0 Line 50\n' + .. ' 1 10 0 Line 10\n' + .. '>', + exec_capture('jumps') + ) end) end) -describe("jumpoptions=view", function() +describe('jumpoptions=view', function() local file1 = 'Xtestfile-functional-editor-jumps' local file2 = 'Xtestfile-functional-editor-jumps-2' local function content() local c = {} - for i=1,30 do - c[i] = i .. " line" + for i = 1, 30 do + c[i] = i .. ' line' end - return table.concat(c, "\n") + return table.concat(c, '\n') end before_each(function() clear() @@ -206,9 +216,9 @@ describe("jumpoptions=view", function() it('restores the view', function() local screen = Screen.new(5, 8) screen:attach() - command("edit " .. file1) - feed("12Gztj") - feed("gg") + command('edit ' .. file1) + feed('12Gztj') + feed('gg') screen:expect([[ 12 line | ^13 line | @@ -224,10 +234,10 @@ describe("jumpoptions=view", function() it('restores the view across files', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("12Gzt") - command("next") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('12Gzt') + command('next') + feed('G') screen:expect([[ 27 line | 28 line | @@ -235,7 +245,7 @@ describe("jumpoptions=view", function() ^30 line | | ]]) - feed("") + feed('') screen:expect([[ ^12 line | 13 line | @@ -248,10 +258,10 @@ describe("jumpoptions=view", function() it('restores the view across files with ', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("12Gzt") - command("next") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('12Gzt') + command('next') + feed('G') screen:expect([[ 27 line | 28 line | @@ -259,7 +269,7 @@ describe("jumpoptions=view", function() ^30 line | | ]]) - feed("") + feed('') screen:expect([[ ^12 line | 13 line | @@ -269,11 +279,11 @@ describe("jumpoptions=view", function() ]]) end) - it('falls back to standard behavior when view can\'t be recovered', function() + it("falls back to standard behavior when view can't be recovered", function() local screen = Screen.new(5, 8) screen:attach() - command("edit " .. file1) - feed("7GzbG") + command('edit ' .. file1) + feed('7GzbG') curbufmeths.set_lines(0, 2, true, {}) -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the @@ -281,7 +291,7 @@ describe("jumpoptions=view", function() -- Therefore when trying to jump back to it it's not possible to set a 7 line offset from the -- mark position to the top line, since there's only 5 lines from the mark position to line 0. -- Therefore falls back to standard behavior which is centering the view/line. - feed("") + feed('') screen:expect([[ 4 line | 5 line | diff --git a/test/functional/editor/lang_spec.lua b/test/functional/editor/lang_spec.lua index 24d1262f5f..ee7cfac057 100644 --- a/test/functional/editor/lang_spec.lua +++ b/test/functional/editor/lang_spec.lua @@ -9,11 +9,11 @@ describe('gu and gU', function() it('works in any locale with default casemap', function() eq('internal,keepascii', eval('&casemap')) - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') end) describe('works in Turkish locale', function() @@ -21,7 +21,7 @@ describe('gu and gU', function() local err = exc_exec('lang ctype tr_TR.UTF-8') if err ~= 0 then - pending("Locale tr_TR.UTF-8 not supported", function() end) + pending('Locale tr_TR.UTF-8 not supported', function() end) return end @@ -32,29 +32,29 @@ describe('gu and gU', function() it('with default casemap', function() eq('internal,keepascii', eval('&casemap')) -- expect ASCII behavior - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') end) it('with casemap=""', function() command('set casemap=') -- expect either Turkish locale behavior or ASCII behavior local iupper = eval("toupper('i')") - if iupper == "İ" then - insert("iI") - feed("VgU") - expect("İI") - feed("Vgu") - expect("iı") - elseif iupper == "I" then - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + if iupper == 'İ' then + insert('iI') + feed('VgU') + expect('İI') + feed('Vgu') + expect('iı') + elseif iupper == 'I' then + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') else error("expected toupper('i') to be either 'I' or 'İ'") end diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index b1070ecddc..e697140889 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -14,13 +14,13 @@ describe("'langmap'", function() feed('gg0') end) - it("converts keys in normal mode", function() + it('converts keys in normal mode', function() feed('ix') expect('iii ww') feed('whello') expect('iii helloww') end) - it("gives characters that are mapped by :nmap.", function() + it('gives characters that are mapped by :nmap.', function() command('map i 0x') feed('w') expect('ii www') @@ -32,20 +32,18 @@ describe("'langmap'", function() it("'langnoremap' is by default ON", function() eq(1, eval('&langnoremap')) end) - it("Results of maps are not converted when 'langnoremap' ON.", - function() + it("Results of maps are not converted when 'langnoremap' ON.", function() command('nmap x i') feed('xdl') expect('dliii www') end) - it("applies when deciding whether to map recursively", function() + it('applies when deciding whether to map recursively', function() command('nmap l i') command('nmap w j') feed('ll') expect('liii www') end) - it("does not stop applying 'langmap' on first character of a mapping", - function() + it("does not stop applying 'langmap' on first character of a mapping", function() command('1t1') command('1t1') command('goto 1') @@ -56,8 +54,7 @@ describe("'langmap'", function() iii www ihelloii www]]) end) - it("Results of maps are converted when 'langnoremap' OFF.", - function() + it("Results of maps are converted when 'langnoremap' OFF.", function() command('set nolangnoremap') command('nmap x i') feed('xdl') @@ -65,8 +62,7 @@ describe("'langmap'", function() end) end) -- e.g. CTRL-W_j , mj , 'j and "jp - it('conversions are applied to keys in middle of command', - function() + it('conversions are applied to keys in middle of command', function() -- Works in middle of window command feed('s') local origwin = curwin() @@ -74,12 +70,12 @@ describe("'langmap'", function() neq(origwin, curwin()) -- Works when setting a mark feed('yy3p3gg0mwgg0mi') - eq({0, 3, 1, 0}, call('getpos', "'i")) - eq({0, 1, 1, 0}, call('getpos', "'w")) + eq({ 0, 3, 1, 0 }, call('getpos', "'i")) + eq({ 0, 1, 1, 0 }, call('getpos', "'w")) feed('3dd') -- Works when moving to a mark feed("'i") - eq({0, 1, 1, 0}, call('getpos', '.')) + eq({ 0, 1, 1, 0 }, call('getpos', '.')) -- Works when selecting a register feed('qillqqwhhq') eq('hh', eval('@i')) @@ -193,8 +189,7 @@ describe("'langmap'", function() eq(1, eval('gotten_one')) end) end) - it('conversions are not applied during setreg()', - function() + it('conversions are not applied during setreg()', function() call('setreg', 'i', 'ww') eq('ww', eval('@i')) end) @@ -214,12 +209,18 @@ describe("'langmap'", function() end) local function testrecording(command_string, expect_string, setup_function, expect_macro) - if setup_function then setup_function() end + if setup_function then + setup_function() + end feed('qa' .. command_string .. 'q') expect(expect_string) - eq(expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), - eval('@a')) - if setup_function then setup_function() end + eq( + expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), + eval('@a') + ) + if setup_function then + setup_function() + end -- n.b. may need nvim_replace_termcodes() here. feed('@a') expect(expect_string) @@ -276,5 +277,4 @@ describe("'langmap'", function() testrecording('', 'whello', local_setup, eval([["\<*C-w>"]])) testrecording('', 'ihello', local_setup, eval([["\<*C-i>"]])) end) - end) diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index 151d803faa..421bd3ebb8 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -11,10 +11,9 @@ local meths = helpers.meths local insert = helpers.insert local curbufmeths = helpers.curbufmeths - describe('macros', function() before_each(function() - clear({args_rm = {'--cmd'}}) + clear({ args_rm = { '--cmd' } }) end) it('can be recorded and replayed', function() feed('qiahelloq') @@ -42,16 +41,16 @@ hello]] feed [[gg]] feed [[qqAFOOq]] - eq({'helloFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[Q]] - eq({'helloFOOFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + feed [[Q]] + eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[G3Q]] - eq({'helloFOOFOO', 'hello', 'helloFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[G3Q]] + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) - feed[[ggV3jQ]] - eq({'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[ggV3jQ]] + eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @', function() @@ -61,37 +60,36 @@ hello]] feed [[gg]] feed [[qqAFOOq]] - eq({'helloFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[Q]] - eq({'helloFOOFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + feed [[Q]] + eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[G3@@]] - eq({'helloFOOFOO', 'hello', 'helloFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[G3@@]] + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) - feed[[ggV2j@@]] - eq({'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[ggV2j@@]] + eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @q and @w', function() - insert [[hello hello hello]] feed [[gg]] feed [[qqAFOOqu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) feed [[qwA123qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[V3j@q]] - eq({'helloFOO', 'helloFOO', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[V3j@q]] + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) feed [[gg]] - feed[[Vj@w]] - eq({'helloFOO123', 'helloFOO123', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[Vj@w]] + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @q and @w visual-block', function() @@ -101,17 +99,17 @@ hello]] feed [[gg]] feed [[qqAFOOqu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) feed [[qwA123qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[3j@q]] - eq({'helloFOO', 'helloFOO', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[3j@q]] + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) feed [[gg]] - feed[[j@w]] - eq({'helloFOO123', 'helloFOO123', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[j@w]] + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) end) end) @@ -140,16 +138,16 @@ describe('immediately after a macro has finished executing,', function() end) it('if the macro does not end with a mapping', function() - feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({mode = 'n', blocking = false}, meths.get_mode()) + feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op + eq({ mode = 'n', blocking = false }, meths.get_mode()) expect('') eq('', eval('@a')) end) it('if the macro ends with a mapping', function() command('nnoremap 0 ') - feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({mode = 'n', blocking = false}, meths.get_mode()) + feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op + eq({ mode = 'n', blocking = false }, meths.get_mode()) expect('') eq('', eval('@a')) end) diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 7f7d62a90a..67d8cc58ad 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -9,7 +9,9 @@ local eq = helpers.eq local feed = helpers.feed local write_file = helpers.write_file local pcall_err = helpers.pcall_err -local cursor = function() return helpers.meths.win_get_cursor(0) end +local cursor = function() + return helpers.meths.win_get_cursor(0) +end describe('named marks', function() local file1 = 'Xtestfile-functional-editor-marks' @@ -24,153 +26,153 @@ describe('named marks', function() os.remove(file2) end) - it("can be set", function() - command("edit " .. file1) - command("mark a") - eq({1, 0}, curbufmeths.get_mark("a")) - feed("jmb") - eq({2, 0}, curbufmeths.get_mark("b")) - feed("jmB") - eq({3, 0}, curbufmeths.get_mark("B")) - command("4kc") - eq({4, 0}, curbufmeths.get_mark("c")) + it('can be set', function() + command('edit ' .. file1) + command('mark a') + eq({ 1, 0 }, curbufmeths.get_mark('a')) + feed('jmb') + eq({ 2, 0 }, curbufmeths.get_mark('b')) + feed('jmB') + eq({ 3, 0 }, curbufmeths.get_mark('B')) + command('4kc') + eq({ 4, 0 }, curbufmeths.get_mark('c')) end) - it("errors when set out of range with :mark", function() - command("edit " .. file1) - local err = pcall_err(helpers.exec_capture, "1000mark x") - eq("nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x", err) + it('errors when set out of range with :mark', function() + command('edit ' .. file1) + local err = pcall_err(helpers.exec_capture, '1000mark x') + 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_exec2(): Vim(k):E16: Invalid range: 1000kx", err) + it('errors when set out of range with :k', function() + command('edit ' .. file1) + local err = pcall_err(helpers.exec_capture, '1000kx') + 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_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err) + it('errors on unknown mark name with :mark', function() + command('edit ' .. file1) + local err = pcall_err(helpers.exec_capture, 'mark #') + 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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! '#") - eq("nvim_exec2(): 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_exec2(): Vim(normal):E78: Unknown mark", err) + it('errors on unknown mark name with `', function() + command('edit ' .. file1) + local err = pcall_err(helpers.exec_capture, 'normal! `#') + 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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'z") - eq("nvim_exec2(): 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_exec2(): 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_exec2(): Vim(normal):E20: Mark not set", err) - err = pcall_err(helpers.exec_capture, "normal! `>") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + 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_exec2(): Vim(normal):E20: Mark not set', err) + err = pcall_err(helpers.exec_capture, 'normal! `>') + 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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'Z") - eq("nvim_exec2(): 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_exec2(): Vim(normal):E20: Mark not set", err) + 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_exec2(): Vim(normal):E20: Mark not set', err) end) it("can move to them using '", function() - command("args " .. file1 .. " " .. file2) - feed("j") - feed("ma") + command('args ' .. file1 .. ' ' .. file2) + feed('j') + feed('ma') feed("G'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') feed("'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) + eq({ 2, 0 }, cursor()) end) - it("can move to them using `", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") - feed("G`a") - eq({2, 2}, cursor()) - feed("mA") - command("next") - feed("`A") + it('can move to them using `', function() + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') + feed('G`a') + eq({ 2, 2 }, cursor()) + feed('mA') + command('next') + feed('`A') eq(1, meths.get_current_buf().id) - eq({2, 2}, cursor()) + eq({ 2, 2 }, cursor()) end) it("can move to them using g'", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') feed("Gg'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') feed("g'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) + eq({ 2, 0 }, cursor()) end) - it("can move to them using g`", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") - feed("Gg`a") - eq({2, 2}, cursor()) - feed("mA") - command("next") - feed("g`A") + it('can move to them using g`', function() + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') + feed('Gg`a') + eq({ 2, 2 }, cursor()) + feed('mA') + command('next') + feed('g`A') eq(1, meths.get_current_buf().id) - eq({2, 2}, cursor()) + eq({ 2, 2 }, cursor()) end) it("can move to them using :'", function() - command("args " .. file1 .. " " .. file2) - feed("j") - feed("ma") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('j') + feed('ma') + feed('G') command("'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') command("'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) + 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 ) + command('args ' .. file1 .. ' ' .. file2) + feed('mA') + command('next') + command('bw! ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'A") - eq("nvim_exec2(): Vim(normal):E92: Buffer 1 not found", err) + eq('nvim_exec2(): Vim(normal):E92: Buffer 1 not found', err) os.remove(file1) end) - it("errors when using a mark in another buffer in command range", function() + it('errors when using a mark in another buffer in command range', function() feed('ifoomA') command('enew') feed('ibar') @@ -178,147 +180,147 @@ describe('named marks', function() end) it("leave a context mark when moving with '", function() - command("edit " .. file1) - feed("llmamA") - feed("10j0") -- first col, last line + command('edit ' .. file1) + feed('llmamA') + feed('10j0') -- first col, last line local pos = cursor() feed("'a") - feed("") + feed('') eq(pos, cursor()) feed("'A") - feed("") + feed('') eq(pos, cursor()) end) - it("leave a context mark when moving with `", function() - command("edit " .. file1) - feed("llmamA") - feed("10j0") -- first col, last line + it('leave a context mark when moving with `', function() + command('edit ' .. file1) + feed('llmamA') + feed('10j0') -- first col, last line local pos = cursor() - feed("`a") - feed("") + feed('`a') + feed('') eq(pos, cursor()) - feed("`A") - feed("") + feed('`A') + feed('') eq(pos, cursor()) end) it("leave a context mark when the mark changes buffer with g'", function() - command("args " .. file1 .. " " .. file2) + command('args ' .. file1 .. ' ' .. file2) local pos - feed("GmA") - command("next") + feed('GmA') + command('next') pos = cursor() - command("clearjumps") - feed("g'A") -- since the mark is in another buffer, it leaves a context mark - feed("") + command('clearjumps') + feed("g'A") -- since the mark is in another buffer, it leaves a context mark + feed('') eq(pos, cursor()) end) - it("leave a context mark when the mark changes buffer with g`", function() - command("args " .. file1 .. " " .. file2) + it('leave a context mark when the mark changes buffer with g`', function() + command('args ' .. file1 .. ' ' .. file2) local pos - feed("GmA") - command("next") + feed('GmA') + command('next') pos = cursor() - command("clearjumps") - feed("g`A") -- since the mark is in another buffer, it leaves a context mark - feed("") + command('clearjumps') + feed('g`A') -- since the mark is in another buffer, it leaves a context mark + feed('') eq(pos, cursor()) end) it("do not leave a context mark when moving with g'", function() - command("edit " .. file1) + command('edit ' .. file1) local pos - feed("ma") + feed('ma') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("") -- should do nothing + feed('') -- should do nothing eq(pos, cursor()) - feed("mA") + feed('mA') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("") -- should do nothing + feed('') -- should do nothing eq(pos, cursor()) end) - it("do not leave a context mark when moving with g`", function() - command("edit " .. file1) + it('do not leave a context mark when moving with g`', function() + command('edit ' .. file1) local pos - feed("ma") + feed('ma') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line - feed("g`a") - feed("") -- should do nothing + feed('10j0') -- first col, last line + feed('g`a') + feed('') -- should do nothing eq(pos, cursor()) - feed("mA") + feed('mA') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("") -- should do nothing + feed('') -- should do nothing eq(pos, cursor()) end) - it("open folds when moving to them", function() - command("edit " .. file1) - feed("jzfG") -- Fold from the second line to the end - command("3mark a") - feed("G") -- On top of the fold + it('open folds when moving to them', function() + command('edit ' .. file1) + feed('jzfG') -- Fold from the second line to the end + command('3mark a') + feed('G') -- On top of the fold assert(funcs.foldclosed('.') ~= -1) -- folded feed("'a") eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded -- TODO: remove this workaround after fixing #15873 - feed("k`a") + feed('k`a') eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded feed("kg'a") eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded - feed("kg`a") + feed('kg`a') eq(-1, funcs.foldclosed('.')) end) it("do not open folds when moving to them doesn't move the cursor", function() - command("edit " .. file1) - feed("jzfG") -- Fold from the second line to the end + command('edit ' .. file1) + feed('jzfG') -- Fold from the second line to the end assert(funcs.foldclosed('.') == 2) -- folded - feed("ma") + feed('ma') feed("'a") - feed("`a") + feed('`a') feed("g'a") - feed("g`a") + feed('g`a') -- should still be folded eq(2, funcs.foldclosed('.')) end) it("getting '{ '} '( ') does not move cursor", function() - meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) - meths.win_set_cursor(0, {2, 0}) + meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + meths.win_set_cursor(0, { 2, 0 }) funcs.getpos("'{") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("'}") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("'(") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("')") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) end) it('in command range does not move cursor #19248', function() - meths.create_user_command('Test', ':', {range = true}) - meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) - meths.win_set_cursor(0, {2, 0}) + meths.create_user_command('Test', ':', { range = true }) + meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + meths.win_set_cursor(0, { 2, 0 }) command([['{,'}Test]]) - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) end) end) @@ -327,16 +329,16 @@ describe('named marks view', function() local file2 = 'Xtestfile-functional-editor-marks-2' local function content() local c = {} - for i=1,30 do - c[i] = i .. " line" + for i = 1, 30 do + c[i] = i .. ' line' end - return table.concat(c, "\n") + return table.concat(c, '\n') end before_each(function() clear() write_file(file1, content(), false, false) write_file(file2, content(), false, false) - command("set jumpoptions+=view") + command('set jumpoptions+=view') end) after_each(function() os.remove(file1) @@ -344,12 +346,12 @@ describe('named marks view', function() end) it('is restored in normal mode but not op-pending mode', function() - local screen = Screen.new(5, 8) - screen:attach() - command("edit " .. file1) - feed("jWma") - feed("G'a") - local expected = [[ + local screen = Screen.new(5, 8) + screen:attach() + command('edit ' .. file1) + feed('jWma') + feed("G'a") + local expected = [[ 2 line | ^3 line | 4 line | @@ -359,9 +361,9 @@ describe('named marks view', function() 8 line | | ]] - screen:expect({grid=expected}) - feed("G`a") - screen:expect([[ + screen:expect({ grid = expected }) + feed('G`a') + screen:expect([[ 2 line | 3 ^line | 4 line | @@ -371,9 +373,9 @@ describe('named marks view', function() 8 line | | ]]) - -- not in op-pending mode #20886 - feed("ggj=`a") - screen:expect([[ + -- not in op-pending mode #20886 + feed('ggj=`a') + screen:expect([[ 1 line | ^2 line | 3 line | @@ -388,8 +390,8 @@ describe('named marks view', function() it('is restored across files', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("mA") + command('args ' .. file1 .. ' ' .. file2) + feed('mA') local mark_view = [[ ^2 line | 3 line | @@ -398,7 +400,7 @@ describe('named marks view', function() | ]] screen:expect(mark_view) - command("next") + command('next') screen:expect([[ ^1 line | 2 line | @@ -410,14 +412,14 @@ describe('named marks view', function() screen:expect(mark_view) end) - it('fallback to standard behavior when view can\'t be recovered', function() - local screen = Screen.new(10, 10) - screen:attach() - command("edit " .. file1) - feed("7GzbmaG") -- Seven lines from the top - command("new") -- Screen size for window is now half the height can't be restored - feed("p'a") - screen:expect([[ + it("fallback to standard behavior when view can't be recovered", function() + local screen = Screen.new(10, 10) + screen:attach() + command('edit ' .. file1) + feed('7GzbmaG') -- Seven lines from the top + command('new') -- Screen size for window is now half the height can't be restored + feed("p'a") + screen:expect([[ | ~ |*3 [No Name] | diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index 825b20138a..3b66c8fc05 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -66,11 +66,11 @@ describe('meta-keys #8226 #13042', function() command('inoremap alt-j') feed('i xxx a') expect('meta-l xxx alt-j') - eq({ 0, 1, 14, 0, }, funcs.getpos('.')) + eq({ 0, 1, 14, 0 }, funcs.getpos('.')) -- Unmapped ALT-chord behaves as ESC+c. command('iunmap ') feed('0i') - eq({ 0, 1, 2, 0, }, funcs.getpos('.')) + eq({ 0, 1, 2, 0 }, funcs.getpos('.')) -- Unmapped ALT-chord has same `undo` characteristics as ESC+ command('0,$d') feed('ahello') @@ -101,7 +101,7 @@ describe('meta-keys #8226 #13042', function() eq(meta_l_seq .. 'yyy' .. meta_l_seq .. 'alt-j', exec_lua([[return _G.input_data]])) eq('t', eval('mode(1)')) feed('j') - eq({ 0, 2, 1, 0, }, funcs.getpos('.')) + eq({ 0, 2, 1, 0 }, funcs.getpos('.')) eq('nt', eval('mode(1)')) end) diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index e1fe8dead7..d36db80bdf 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -48,25 +48,29 @@ describe('cmdline', function() 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 + [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=[[ + screen:expect { + grid = [[ | {0:~ }| {1:c }| :^ | - ]]} + ]], + } feed('') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }| {1:cr }| :^ | - ]]} + ]], + } end) describe('history', function() diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index 463a6fa9ca..e96813b6f7 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -53,13 +53,13 @@ describe('insert-mode', function() 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 + [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') @@ -187,10 +187,10 @@ describe('insert-mode', function() 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 + [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') @@ -199,22 +199,26 @@ describe('insert-mode', function() command('set timeoutlen=10000') command('inoremap jk ') feed('iβββj') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo │ | foo │β^jβ | foo │{0:~ }| {0:~ }│{0:~ }| {2:[No Name] [+] }{1:[No Name] [+] }| {3:-- INSERT --} | - ]]} + ]], + } feed('k') - screen:expect{grid=[[ + 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 47068470bb..8e06794093 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -35,12 +35,12 @@ describe('put command', function() before_each(reset) local function visual_marks_zero() - for _,v in pairs(funcs.getpos("'<")) do + for _, v in pairs(funcs.getpos("'<")) do if v ~= 0 then return false end end - for _,v in pairs(funcs.getpos("'>")) do + for _, v in pairs(funcs.getpos("'>")) do if v ~= 0 then return false end @@ -51,10 +51,12 @@ describe('put command', function() -- {{{ Where test definitions are run local function run_test_variations(test_variations, extra_setup) reset() - if extra_setup then extra_setup() end + if extra_setup then + extra_setup() + end local init_contents = curbuf_contents() local init_cursorpos = funcs.getcurpos() - local assert_no_change = function (exception_table, after_undo) + local assert_no_change = function(exception_table, after_undo) expect(init_contents) -- When putting the ". register forwards, undo doesn't move -- the cursor back to where it was before. @@ -69,7 +71,9 @@ describe('put command', function() for _, test in pairs(test_variations) do it(test.description, function() - if extra_setup then extra_setup() end + if extra_setup then + extra_setup() + end local orig_dotstr = funcs.getreg('.') helpers.ok(visual_marks_zero()) -- Make sure every test starts from the same conditions @@ -115,8 +119,13 @@ describe('put command', function() end -- run_test_variations() -- }}} - local function create_test_defs(test_defs, command_base, command_creator, -- {{{ - expect_base, expect_creator) + local function create_test_defs( + test_defs, + command_base, + command_creator, -- {{{ + expect_base, + expect_creator + ) local rettab = {} local exceptions for _, v in pairs(test_defs) do @@ -125,8 +134,7 @@ describe('put command', function() else exceptions = {} end - table.insert(rettab, - { + table.insert(rettab, { test_action = command_creator(command_base, v[1]), test_assertions = expect_creator(expect_base, v[2]), description = v[3], @@ -146,7 +154,7 @@ describe('put command', function() for linenum, line in pairs(funcs.split(expect_string, '\n', 1)) do local column = line:find('x') if column then - return {linenum, column}, expect_string:gsub('x', '') + return { linenum, column }, expect_string:gsub('x', '') end end end -- find_cursor_position() }}} @@ -186,7 +194,7 @@ describe('put command', function() -- '.' command. if not (exception_table.redo_position and after_redo) then local actual_position = funcs.getcurpos() - eq(cursor_position, {actual_position[2], actual_position[5]}) + eq(cursor_position, { actual_position[2], actual_position[5] }) end end end -- expect_creator() }}} @@ -195,13 +203,13 @@ describe('put command', function() local function copy_def(def) local rettab = { '', {}, '', nil } rettab[1] = def[1] - for k,v in pairs(def[2]) do + for k, v in pairs(def[2]) do rettab[2][k] = v end rettab[3] = def[3] if def[4] then rettab[4] = {} - for k,v in pairs(def[4]) do + for k, v in pairs(def[4]) do rettab[4][k] = v end end @@ -211,52 +219,52 @@ describe('put command', function() local normal_command_defs = { { 'p', - {cursor_after = false, put_backwards = false, dot_register = false}, + { cursor_after = false, put_backwards = false, dot_register = false }, 'pastes after cursor with p', }, { 'gp', - {cursor_after = true, put_backwards = false, dot_register = false}, + { cursor_after = true, put_backwards = false, dot_register = false }, 'leaves cursor after text with gp', }, { '".p', - {cursor_after = false, put_backwards = false, dot_register = true}, + { cursor_after = false, put_backwards = false, dot_register = true }, 'works with the ". register', }, { '".gp', - {cursor_after = true, put_backwards = false, dot_register = true}, + { cursor_after = true, put_backwards = false, dot_register = true }, 'gp works with the ". register', - {redo_position = true}, + { redo_position = true }, }, { 'P', - {cursor_after = false, put_backwards = true, dot_register = false}, + { cursor_after = false, put_backwards = true, dot_register = false }, 'pastes before cursor with P', }, { 'gP', - {cursor_after = true, put_backwards = true, dot_register = false}, + { cursor_after = true, put_backwards = true, dot_register = false }, 'gP pastes before cursor and leaves cursor after text', }, { '".P', - {cursor_after = false, put_backwards = true, dot_register = true}, + { cursor_after = false, put_backwards = true, dot_register = true }, 'P works with ". register', }, { '".gP', - {cursor_after = true, put_backwards = true, dot_register = true}, + { cursor_after = true, put_backwards = true, dot_register = true }, 'gP works with ". register', - {redo_position = true}, + { redo_position = true }, }, } -- Add a definition applying a count for each definition above. -- Could do this for each transformation (p -> P, p -> gp etc), but I think -- it's neater this way (balance between being explicit and too verbose). - for i = 1,#normal_command_defs do + for i = 1, #normal_command_defs do local cur = normal_command_defs[i] -- Make modified copy of current definition that includes a count. @@ -279,35 +287,36 @@ describe('put command', function() local ex_command_defs = { { 'put', - {put_backwards = false, dot_register = false}, + { put_backwards = false, dot_register = false }, 'pastes linewise forwards with :put', }, { 'put!', - {put_backwards = true, dot_register = false}, + { put_backwards = true, dot_register = false }, 'pastes linewise backwards with :put!', }, { 'put .', - {put_backwards = false, dot_register = true}, + { put_backwards = false, dot_register = true }, 'pastes linewise with the dot register', }, { 'put! .', - {put_backwards = true, dot_register = true}, + { put_backwards = true, dot_register = true }, 'pastes linewise backwards with the dot register', }, } local function non_dotdefs(def_table) - return filter(function(d) return not d[2].dot_register end, def_table) + return filter(function(d) + return not d[2].dot_register + end, def_table) end -- }}} -- Conversion functions {{{ - local function convert_charwise(expect_base, conversion_table, - virtualedit_end, visual_put) + local function convert_charwise(expect_base, conversion_table, virtualedit_end, visual_put) expect_base = dedent(expect_base) -- There is no difference between 'P' and 'p' when VIsual_active if not visual_put then @@ -324,7 +333,7 @@ describe('put command', function() end if conversion_table.count > 1 then local rep_string = 'test_string"' - local extra_puts = rep_string:rep(conversion_table.count - 1) + local extra_puts = rep_string:rep(conversion_table.count - 1) expect_base = expect_base:gsub('test_stringx"', extra_puts .. 'test_stringx"') end if conversion_table.cursor_after then @@ -395,7 +404,7 @@ describe('put command', function() indent = '' end local rep_string = indent .. p_str .. '\n' - local extra_puts = rep_string:rep(conversion_table.count - 1) + local extra_puts = rep_string:rep(conversion_table.count - 1) local orig_string, new_string if conversion_table.cursor_after then orig_string = indent .. p_str .. '\nx' @@ -420,8 +429,13 @@ describe('put command', function() return orig_line:sub(1, prev_end - 1) .. 'x' .. orig_line:sub(prev_end) end - local function convert_blockwise(expect_base, conversion_table, visual, - use_b, trailing_whitespace) + local function convert_blockwise( + expect_base, + conversion_table, + visual, + use_b, + trailing_whitespace + ) expect_base = dedent(expect_base) local p_str = 'test_string"' if use_b then @@ -452,11 +466,9 @@ describe('put command', function() if conversion_table.count and conversion_table.count > 1 then local p_pattern = p_str:gsub('%.', '%%.') - expect_base = expect_base:gsub(p_pattern, - p_str:rep(conversion_table.count)) - expect_base = expect_base:gsub('test_stringx([b".])', - p_str:rep(conversion_table.count - 1) - .. '%0') + expect_base = expect_base:gsub(p_pattern, p_str:rep(conversion_table.count)) + expect_base = + expect_base:gsub('test_stringx([b".])', p_str:rep(conversion_table.count - 1) .. '%0') end if conversion_table.cursor_after then @@ -496,8 +508,13 @@ describe('put command', function() -- }}} -- Convenience functions {{{ - local function run_normal_mode_tests(test_string, base_map, extra_setup, - virtualedit_end, selection_string) + local function run_normal_mode_tests( + test_string, + base_map, + extra_setup, + virtualedit_end, + selection_string + ) local function convert_closure(e, c) return convert_charwise(e, c, virtualedit_end, selection_string) end @@ -532,8 +549,12 @@ describe('put command', function() local function run_linewise_tests(expect_base, base_command, extra_setup) local linewise_test_defs = create_test_defs( - ex_command_defs, base_command, - create_put_action, expect_base, convert_linewiseer) + ex_command_defs, + base_command, + create_put_action, + expect_base, + convert_linewiseer + ) run_test_variations(linewise_test_defs, extra_setup) end -- run_linewise_tests() -- }}} @@ -545,7 +566,8 @@ describe('put command', function() Line of words 2]] run_normal_mode_tests(expect_string, 'p') - run_linewise_tests([[ + run_linewise_tests( + [[ Line of words 1 xtest_string" Line of words 2]], @@ -585,11 +607,12 @@ describe('put command', function() run_test_variations( create_test_defs( linewise_put_defs, - 'put a', create_put_action, - base_expect_string, convert_linewiseer + 'put a', + create_put_action, + base_expect_string, + convert_linewiseer ) ) - end) describe('blockwise register', function() @@ -600,18 +623,13 @@ describe('put command', function() test_stringb]] local function expect_block_creator(expect_base, conversion_table) - return expect_creator(function(e,c) return convert_blockwise(e,c,nil,true) end, - expect_base, conversion_table) + return expect_creator(function(e, c) + return convert_blockwise(e, c, nil, true) + end, expect_base, conversion_table) end run_test_variations( - create_test_defs( - blockwise_put_defs, - '"bp', - create_p_action, - test_base, - expect_block_creator - ) + create_test_defs(blockwise_put_defs, '"bp', create_p_action, test_base, expect_block_creator) ) end) @@ -632,17 +650,17 @@ describe('put command', function() describe('linewise paste with autoindent', function() -- luacheck: ignore - run_linewise_tests([[ + run_linewise_tests( + [[ Line of words 1 Line of words 2 xtest_string"]], - 'put' - , + 'put', function() funcs.setline('$', ' Line of words 2') -- 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}) + funcs.setpos('.', { 0, 2, 1, 0, 8 }) command('set autoindent') end ) @@ -655,7 +673,7 @@ describe('put command', function() run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', {0, 2, 1, 2, 3}) + funcs.setpos('.', { 0, 2, 1, 2, 3 }) end) end) @@ -667,7 +685,7 @@ describe('put command', function() run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', {0, 1, 16, 1, 17}) + funcs.setpos('.', { 0, 1, 16, 1, 17 }) end, true) end) @@ -679,12 +697,10 @@ describe('put command', function() run_normal_mode_tests(test_string, 'v2ep', nil, nil, 'Line of') end) describe('over trailing newline', function() - local test_string = 'Line of test_stringx"Line of words 2' + local test_string = 'Line of test_stringx"Line of words 2' run_normal_mode_tests(test_string, 'v$p', function() - funcs.setpos('.', {0, 1, 9, 0, 9}) - end, - nil, - 'words 1\n') + funcs.setpos('.', { 0, 1, 9, 0, 9 }) + end, nil, 'words 1\n') end) describe('linewise mode', function() local test_string = [[ @@ -693,8 +709,7 @@ describe('put command', function() local function expect_vis_linewise(expect_base, conversion_table) return expect_creator(function(e, c) return convert_linewise(e, c, nil, nil) - end, - expect_base, conversion_table) + end, expect_base, conversion_table) end run_test_variations( create_test_defs( @@ -704,15 +719,16 @@ describe('put command', function() test_string, expect_vis_linewise ), - function() funcs.setpos('.', {0, 1, 1, 0, 1}) end + function() + funcs.setpos('.', { 0, 1, 1, 0, 1 }) + end ) describe('with whitespace at bol', function() local function expect_vis_lineindented(expect_base, conversion_table) local test_expect = expect_creator(function(e, c) - return convert_linewise(e, c, nil, nil, ' ') - end, - expect_base, conversion_table) + return convert_linewise(e, c, nil, nil, ' ') + end, expect_base, conversion_table) return function(exception_table, after_redo) test_expect(exception_table, after_redo) if not conversion_table.put_backwards then @@ -737,7 +753,6 @@ describe('put command', function() end ) end) - end) describe('blockwise visual mode', function() @@ -747,10 +762,10 @@ describe('put command', function() local function expect_block_creator(expect_base, conversion_table) local test_expect = expect_creator(function(e, c) - return convert_blockwise(e, c, true) - end, expect_base, conversion_table) - return function(e,c) - test_expect(e,c) + return convert_blockwise(e, c, true) + end, expect_base, conversion_table) + return function(e, c) + test_expect(e, c) if not conversion_table.put_backwards then eq('Lin\nLin', funcs.getreg('"')) end @@ -758,28 +773,26 @@ describe('put command', function() end local select_down_test_defs = create_test_defs( - normal_command_defs, - 'jllp', - create_p_action, - test_base, - expect_block_creator + normal_command_defs, + 'jllp', + create_p_action, + test_base, + expect_block_creator ) run_test_variations(select_down_test_defs) - -- Undo and redo of a visual block put leave the cursor in the top -- left of the visual block area no matter where the cursor was -- when it started. local undo_redo_no = map(function(table) - local rettab = copy_def(table) - if not rettab[4] then - rettab[4] = {} - end - rettab[4].undo_position = true - rettab[4].redo_position = true - return rettab - end, - normal_command_defs) + local rettab = copy_def(table) + if not rettab[4] then + rettab[4] = {} + end + rettab[4].undo_position = true + rettab[4].redo_position = true + return rettab + end, normal_command_defs) -- Selection direction doesn't matter run_test_variations( @@ -790,7 +803,9 @@ describe('put command', function() test_base, expect_block_creator ), - function() funcs.setpos('.', {0, 2, 1, 0, 1}) end + function() + funcs.setpos('.', { 0, 2, 1, 0, 1 }) + end ) describe('blockwise cursor after undo', function() @@ -800,62 +815,45 @@ describe('put command', function() -- the same pattern as everything else. -- Here we fix this by directly checking the undo/redo position -- in the test_assertions of our test definitions. - local function assertion_creator(_,_) - return function(_,_) + local function assertion_creator(_, _) + return function(_, _) feed('u') -- Have to use feed('u') here to set curswant, because -- ex_undo() doesn't do that. - eq({0, 1, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) feed('') - eq({0, 1, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) end end run_test_variations( - create_test_defs( - undo_redo_no, - 'kllp', - create_p_action, - test_base, - assertion_creator - ), - function() funcs.setpos('.', {0, 2, 1, 0, 1}) end + create_test_defs(undo_redo_no, 'kllp', create_p_action, test_base, assertion_creator), + function() + funcs.setpos('.', { 0, 2, 1, 0, 1 }) + end ) end) end) - describe("with 'virtualedit'", function() describe('splitting a tab character', function() local base_expect_string = [[ Line of words 1 test_stringx" Line of words 2]] - run_normal_mode_tests( - base_expect_string, - 'vp', - function() - funcs.setline('$', ' Line of words 2') - command('setlocal virtualedit=all') - funcs.setpos('.', {0, 2, 1, 2, 3}) - end, - nil, - ' ' - ) + run_normal_mode_tests(base_expect_string, 'vp', function() + funcs.setline('$', ' Line of words 2') + command('setlocal virtualedit=all') + funcs.setpos('.', { 0, 2, 1, 2, 3 }) + end, nil, ' ') end) describe('after end of line', function() local base_expect_string = [[ Line of words 1 test_stringx" Line of words 2]] - run_normal_mode_tests( - base_expect_string, - 'vp', - function() - command('setlocal virtualedit=all') - funcs.setpos('.', {0, 1, 16, 2, 18}) - end, - true, - ' ' - ) + run_normal_mode_tests(base_expect_string, 'vp', function() + command('setlocal virtualedit=all') + funcs.setpos('.', { 0, 1, 16, 2, 18 }) + end, true, ' ') end) end) end) @@ -873,9 +871,12 @@ describe('put command', function() Line of words 1 Line of words 2]]) feed('u1goj".p') - eq([[ + eq( + [[ ine of words 1 - ine of words 2]], curbuf_contents()) + ine of words 2]], + curbuf_contents() + ) end) local screen @@ -891,33 +892,42 @@ describe('put command', function() end helpers.ok(not screen.bell and not screen.visualbell) actions() - screen:expect{condition=function() - if should_ring then - if not screen.bell and not screen.visualbell then - error('Bell was not rung after action') + screen:expect { + condition = function() + if should_ring then + if not screen.bell and not screen.visualbell then + error('Bell was not rung after action') + end + else + if screen.bell or screen.visualbell then + error('Bell was rung after action') + end end - else - if screen.bell or screen.visualbell then - error('Bell was rung after action') - end - end - end, unchanged=(not should_ring)} + 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() - bell_test(function() feed('$".gp') end) + bell_test(function() + feed('$".gp') + end) -- Even if the last character is a multibyte character. reset() funcs.setline(1, 'helloม') - bell_test(function() feed('$".gp') end) + bell_test(function() + feed('$".gp') + end) end) it('should not ring the bell with gp and end of file', function() - funcs.setpos('.', {0, 2, 1, 0}) - bell_test(function() feed('$vl".gp') end) + funcs.setpos('.', { 0, 2, 1, 0 }) + bell_test(function() + feed('$vl".gp') + end) end) it('should ring the bell when deleting if not appropriate', function() @@ -926,7 +936,9 @@ describe('put command', function() expect([[ ine of words 1 Line of words 2]]) - bell_test(function() feed('".P') end, true) + bell_test(function() + feed('".P') + end, true) end) it('should restore cursor position after undo of ".p', function() @@ -946,4 +958,3 @@ describe('put command', function() end) end) end) - diff --git a/test/functional/editor/search_spec.lua b/test/functional/editor/search_spec.lua index d5df131725..46a3e298b7 100644 --- a/test/functional/editor/search_spec.lua +++ b/test/functional/editor/search_spec.lua @@ -8,10 +8,7 @@ describe('search (/)', function() before_each(clear) it('fails with huge column (%c) value #9930', function() - eq([[Vim:E951: \% value too large]], - pcall_err(command, "/\\v%18446744071562067968c")) - eq([[Vim:E951: \% value too large]], - pcall_err(command, "/\\v%2147483648c")) + eq([[Vim:E951: \% value too large]], pcall_err(command, '/\\v%18446744071562067968c')) + eq([[Vim:E951: \% value too large]], pcall_err(command, '/\\v%2147483648c')) end) end) - diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 263b753a16..f632bbb40f 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -58,7 +58,9 @@ describe('tabpage', function() end) it('no segfault with strange WinClosed autocommand #20290', function() - pcall(exec, [[ + pcall( + exec, + [[ set nohidden edit Xa split Xb @@ -66,45 +68,46 @@ describe('tabpage', function() new autocmd WinClosed * tabprev | bwipe! close - ]]) + ]] + ) assert_alive() end) it('nvim_win_close and nvim_win_hide update tabline #20285', function() eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) local win1 = curwin().id command('tabnew') eq(2, #meths.list_tabpages()) - eq({2, 1}, funcs.win_screenpos(0)) + eq({ 2, 1 }, funcs.win_screenpos(0)) local win2 = curwin().id meths.win_close(win1, true) eq(win2, curwin().id) eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) command('tabnew') eq(2, #meths.list_tabpages()) - eq({2, 1}, funcs.win_screenpos(0)) + eq({ 2, 1 }, funcs.win_screenpos(0)) local win3 = curwin().id meths.win_hide(win2) eq(win3, curwin().id) eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) end) it('switching tabpage after setting laststatus=3 #19591', function() local screen = Screen.new(40, 8) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {bold = true, reverse = true}, -- StatusLine - [2] = {reverse = true}, -- TabLineFill - [3] = {bold = true}, -- TabLineSel - [4] = {background = Screen.colors.LightGrey, underline = true}, -- TabLine - [5] = {bold = true, foreground = Screen.colors.Magenta}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, reverse = true }, -- StatusLine + [2] = { reverse = true }, -- TabLineFill + [3] = { bold = true }, -- TabLineSel + [4] = { background = Screen.colors.LightGrey, underline = true }, -- TabLine + [5] = { bold = true, foreground = Screen.colors.Magenta }, }) screen:attach() @@ -130,7 +133,7 @@ describe('tabpage', function() ]]) end) - it(":tabmove handles modifiers and addr", function() + it(':tabmove handles modifiers and addr', function() command('tabnew | tabnew | tabnew') eq(4, funcs.nvim_tabpage_get_number(0)) command(' silent :keepalt :: ::: silent! - tabmove') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index d66ab352ef..a2dc34a6b9 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -21,15 +21,23 @@ describe('u CTRL-R g- g+', function() before_each(clear) local function create_history(num_steps) - if num_steps == 0 then return end + if num_steps == 0 then + return + end insert('1') - if num_steps == 1 then return end + if num_steps == 1 then + return + end feed('o2') feed('o3') feed('u') - if num_steps == 2 then return end + if num_steps == 2 then + return + end feed('o4') - if num_steps == 3 then return end + if num_steps == 3 then + return + end feed('u') end @@ -57,13 +65,23 @@ describe('u CTRL-R g- g+', function() undo_and_redo(2, 'g-', 'g+', '1') end) it('undoes properly around a branch point', function() - undo_and_redo(3, 'u', '', [[ + undo_and_redo( + 3, + 'u', + '', + [[ 1 - 2]]) - undo_and_redo(3, 'g-', 'g+', [[ + 2]] + ) + undo_and_redo( + 3, + 'g-', + 'g+', + [[ 1 2 - 3]]) + 3]] + ) end) it('can find the previous sequence after undoing to a branch', function() undo_and_redo(4, 'u', '', '1') diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index 9f3aa2d315..b3c0584568 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -29,8 +29,7 @@ local cmdtest = function(cmd, prep, ret1) -- Used to crash because this invokes history processing which uses -- hist_char2type which after fdb68e35e4c729c7ed097d8ade1da29e5b3f4b31 -- crashed. - it(cmd .. 's' .. prep .. ' the current line by default when feeding', - function() + it(cmd .. 's' .. prep .. ' the current line by default when feeding', function() feed(':' .. cmd .. '\nabc\ndef\n.\n') eq(ret1, buffer_contents()) end) @@ -63,8 +62,8 @@ describe('the first line is redrawn correctly after inserting text in an empty b clear() screen = Screen.new(20, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, - [2] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue }, + [2] = { bold = true, reverse = true }, }) screen:attach() end) diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua index 4dea50b53e..1cb758cd23 100644 --- a/test/functional/ex_cmds/arg_spec.lua +++ b/test/functional/ex_cmds/arg_spec.lua @@ -1,30 +1,30 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local ok = helpers.ok local clear = helpers.clear -describe(":argument", function() +describe(':argument', function() before_each(function() clear() end) - it("does not restart :terminal buffer", function() - command("terminal") - helpers.feed([[]]) - command("argadd") - helpers.feed([[]]) - local bufname_before = funcs.bufname("%") - local bufnr_before = funcs.bufnr("%") - helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + it('does not restart :terminal buffer', function() + command('terminal') + helpers.feed([[]]) + command('argadd') + helpers.feed([[]]) + local bufname_before = funcs.bufname('%') + local bufnr_before = funcs.bufnr('%') + helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity - command("argument 1") - helpers.feed([[]]) + command('argument 1') + helpers.feed([[]]) - local bufname_after = funcs.bufname("%") - local bufnr_after = funcs.bufnr("%") - eq("["..bufname_before.."]", helpers.eval('trim(execute("args"))')) - ok(funcs.line('$') > 1) - eq(bufname_before, bufname_after) - eq(bufnr_before, bufnr_after) + local bufname_after = funcs.bufname('%') + local bufnr_after = funcs.bufnr('%') + eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))')) + ok(funcs.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) end) end) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index b6a3713158..a6ee5afe49 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -21,18 +21,30 @@ local directories = { } -- Shorthand writing to get the current working directory -local cwd = function(...) return call('getcwd', ...) end -- effective working dir -local wcwd = function() return cwd(0) end -- window dir -local tcwd = function() return cwd(-1, 0) end -- tab dir +local cwd = function(...) + return call('getcwd', ...) +end -- effective working dir +local wcwd = function() + return cwd(0) +end -- window dir +local tcwd = function() + return cwd(-1, 0) +end -- tab dir -- Same, except these tell us if there is a working directory at all -local lwd = function(...) return call('haslocaldir', ...) end -- effective working dir -local wlwd = function() return lwd(0) end -- window dir -local tlwd = function() return lwd(-1, 0) end -- tab dir +local lwd = function(...) + return call('haslocaldir', ...) +end -- effective working dir +local wlwd = function() + return lwd(0) +end -- window dir +local tlwd = function() + return lwd(-1, 0) +end -- tab dir --local glwd = function() return eval('haslocaldir(-1, -1)') end -- global dir -- Test both the `cd` and `chdir` variants -for _, cmd in ipairs {'cd', 'chdir'} do +for _, cmd in ipairs { 'cd', 'chdir' } do describe(':' .. cmd, function() before_each(function() clear() @@ -168,23 +180,23 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Create a new tab first and verify that is has the same working dir command('tabnew') eq(globalDir, cwd()) - eq(globalDir, tcwd()) -- has no tab-local directory + eq(globalDir, tcwd()) -- has no tab-local directory eq(0, tlwd()) - eq(globalDir, wcwd()) -- has no window-local directory + eq(globalDir, wcwd()) -- has no window-local directory eq(0, wlwd()) -- Change tab-local working directory and verify it is different command('silent t' .. cmd .. ' ' .. directories.tab) eq(globalDir .. pathsep .. directories.tab, cwd()) - eq(cwd(), tcwd()) -- working directory matches tab directory + eq(cwd(), tcwd()) -- working directory matches tab directory eq(1, tlwd()) - eq(cwd(), wcwd()) -- still no window-directory + eq(cwd(), wcwd()) -- still no window-directory eq(0, wlwd()) -- Create a new window in this tab to test `:lcd` command('new') - eq(1, tlwd()) -- Still tab-local working directory - eq(0, wlwd()) -- Still no window-local working directory + eq(1, tlwd()) -- Still tab-local working directory + eq(0, wlwd()) -- Still no window-local working directory eq(globalDir .. pathsep .. directories.tab, cwd()) command('silent l' .. cmd .. ' ../' .. directories.window) eq(globalDir .. pathsep .. directories.window, cwd()) @@ -193,13 +205,13 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Verify the first window still has the tab local directory command('wincmd w') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- No window-local directory + eq(0, wlwd()) -- No window-local directory -- Change back to initial tab and verify working directory has stayed command('tabnext') - eq(globalDir, cwd() ) + eq(globalDir, cwd()) eq(0, tlwd()) eq(0, wlwd()) @@ -207,31 +219,31 @@ for _, cmd in ipairs {'cd', 'chdir'} do command('silent ' .. cmd .. ' ' .. directories.global) eq(globalDir .. pathsep .. directories.global, cwd()) command('tabnext') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- Still no window-local directory in this window + eq(0, wlwd()) -- Still no window-local directory in this window -- Unless the global change happened in a tab with local directory command('silent ' .. cmd .. ' ..') - eq(globalDir, cwd() ) - eq(0 , tlwd()) - eq(0 , wlwd()) + eq(globalDir, cwd()) + eq(0, tlwd()) + eq(0, wlwd()) -- Which also affects the first tab command('tabnext') eq(globalDir, cwd()) -- But not in a window with its own local directory command('tabnext | wincmd w') - eq(globalDir .. pathsep .. directories.window, cwd() ) - eq(0 , tlwd()) + eq(globalDir .. pathsep .. directories.window, cwd()) + eq(0, tlwd()) eq(globalDir .. pathsep .. directories.window, wcwd()) end) end) end -- Test legal parameters for 'getcwd' and 'haslocaldir' -for _, cmd in ipairs {'getcwd', 'haslocaldir'} do - describe(cmd..'()', function() +for _, cmd in ipairs { 'getcwd', 'haslocaldir' } do + describe(cmd .. '()', function() before_each(function() clear() end) @@ -271,7 +283,7 @@ for _, cmd in ipairs {'getcwd', 'haslocaldir'} do end) end -describe("getcwd()", function () +describe('getcwd()', function() before_each(function() clear() mkdir(directories.global) @@ -281,11 +293,11 @@ describe("getcwd()", function () helpers.rmdir(directories.global) end) - it("returns empty string if working directory does not exist", function() + it('returns empty string if working directory does not exist', function() skip(is_os('win')) - command("cd "..directories.global) - command("call delete('../"..directories.global.."', 'd')") - eq("", helpers.eval("getcwd()")) + command('cd ' .. directories.global) + command("call delete('../" .. directories.global .. "', 'd')") + eq('', helpers.eval('getcwd()')) end) it("works with 'autochdir' after local directory was set (#9892)", function() diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 306cba85d5..c1a4fee38d 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -16,24 +16,24 @@ describe('mappings with ', function() local tmpfile = 'X_ex_cmds_cmd_map' local function cmdmap(lhs, rhs) - command('noremap '..lhs..' '..rhs..'') - command('noremap! '..lhs..' '..rhs..'') + command('noremap ' .. lhs .. ' ' .. rhs .. '') + command('noremap! ' .. lhs .. ' ' .. rhs .. '') end before_each(function() clear() screen = Screen.new(65, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [4] = {bold = true}, - [5] = {background = Screen.colors.LightGrey}, - [6] = {foreground = Screen.colors.Blue1}, - [7] = {bold = true, reverse = true}, - [8] = {background = Screen.colors.WebGray}, - [9] = {background = Screen.colors.LightMagenta}, - [10] = {foreground = Screen.colors.Red}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true }, + [5] = { background = Screen.colors.LightGrey }, + [6] = { foreground = Screen.colors.Blue1 }, + [7] = { bold = true, reverse = true }, + [8] = { background = Screen.colors.WebGray }, + [9] = { background = Screen.colors.LightMagenta }, + [10] = { foreground = Screen.colors.Red }, }) screen:attach() @@ -57,7 +57,7 @@ describe('mappings with ', function() feed('gg') cmdmap('', 'startinsert') cmdmap('', 'stopinsert') - command("abbr foo let g:y = 17bar") + command('abbr foo let g:y = 17bar') end) after_each(function() @@ -121,7 +121,7 @@ describe('mappings with ', function() feed('') eq('foo…bar', eval('g:str')) local str = eval([["foo\bar"]]) - command([[noremap let g:str = ']]..str..[[']]) + command([[noremap let g:str = ']] .. str .. [[']]) feed('') eq(str, eval('g:str')) command([[noremap let g:str = 'foobar']]) @@ -160,7 +160,7 @@ describe('mappings with ', function() eq('n', eval('mode(1)')) -- operator-pending mode - feed("d") + feed('d') eq('no', eval('m')) -- did leave operator-pending mode eq('n', eval('mode(1)')) @@ -171,21 +171,21 @@ describe('mappings with ', function() eq('i', eval('mode(1)')) -- replace mode - feed("") + feed('') eq('R', eval('m')) eq('R', eval('mode(1)')) feed('') eq('n', eval('mode(1)')) -- virtual replace mode - feed("gR") + feed('gR') eq('Rv', eval('m')) eq('Rv', eval('mode(1)')) feed('') eq('n', eval('mode(1)')) -- langmap works, but is not distinguished in mode(1) - feed(":set iminsert=1i") + feed(':set iminsert=1i') eq('i', eval('m')) eq('i', eval('mode(1)')) feed('') @@ -212,15 +212,15 @@ describe('mappings with ', function() -- check v:count and v:register works feed('') - eq({'n', 0, '"'}, eval('s')) + eq({ 'n', 0, '"' }, eval('s')) feed('7') - eq({'n', 7, '"'}, eval('s')) + eq({ 'n', 7, '"' }, eval('s')) feed('"e') - eq({'n', 0, 'e'}, eval('s')) + eq({ 'n', 0, 'e' }, eval('s')) feed('5"k') - eq({'n', 5, 'k'}, eval('s')) + eq({ 'n', 5, 'k' }, eval('s')) feed('"+2') - eq({'n', 2, '+'}, eval('s')) + eq({ 'n', 2, '+' }, eval('s')) -- text object enters visual mode feed('') @@ -249,7 +249,7 @@ describe('mappings with ', function() {4:-- INSERT --} | ]]) -- feedkeys were not executed immediately - eq({'n', 'of test text'}, eval('[m,a]')) + eq({ 'n', 'of test text' }, eval('[m,a]')) eq('i', eval('mode(1)')) feed('') @@ -261,7 +261,7 @@ describe('mappings with ', function() | ]]) -- feedkeys(..., 'x') was executed immediately, but insert mode gets aborted - eq({'n', 'of alphabetatest text'}, eval('[m,b]')) + eq({ 'n', 'of alphabetatest text' }, eval('[m,b]')) eq('n', eval('mode(1)')) end) @@ -270,9 +270,11 @@ describe('mappings with ', function() command('noremap ,f nosuchcommand') command('noremap ,e throw "very error"\\| call append(1, "yy")') command('noremap ,m echoerr "The message."\\| call append(1, "zz")') - command('noremap ,w for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor') + command( + 'noremap ,w for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor' + ) - feed(":normal ,x") + feed(':normal ,x') screen:expect([[ ^some short lines | aa | @@ -282,9 +284,9 @@ describe('mappings with ', function() :normal ,x | ]]) - eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec("normal ,f")) - eq('very error', exc_exec("normal ,e")) - eq('Vim(echoerr):The message.', exc_exec("normal ,m")) + eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec('normal ,f')) + eq('very error', exc_exec('normal ,e')) + eq('Vim(echoerr):The message.', exc_exec('normal ,m')) feed('w') screen:expect([[ some ^short lines | @@ -296,7 +298,7 @@ describe('mappings with ', function() ]]) command(':%d') - eq('Vim(echoerr):Err', exc_exec("normal ,w")) + eq('Vim(echoerr):Err', exc_exec('normal ,w')) screen:expect([[ ^ | 0 | @@ -332,7 +334,7 @@ describe('mappings with ', function() -- can invoke operator, ending visual mode feed('') eq('n', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('a',1,1)) + eq({ 'some short l' }, funcs.getreg('a', 1, 1)) -- error doesn't interrupt visual mode feed('ggvw') @@ -393,12 +395,12 @@ describe('mappings with ', function() -- visual mapping in select mode restart select mode after operator feed('') eq('s', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('a',1,1)) + eq({ 'some short l' }, funcs.getreg('a', 1, 1)) -- select mode mapping works, and does not restart select mode feed('') eq('n', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('b',1,1)) + eq({ 'some short l' }, funcs.getreg('b', 1, 1)) -- error doesn't interrupt temporary visual mode feed('ggvw') @@ -468,17 +470,16 @@ describe('mappings with ', function() eq('i', eval('mode(1)')) end) - it('works in operator-pending mode', function() feed('d') expect([[ lines of test text]]) - eq({'some short '}, funcs.getreg('"',1,1)) + eq({ 'some short ' }, funcs.getreg('"', 1, 1)) feed('.') expect([[ test text]]) - eq({'lines', 'of '}, funcs.getreg('"',1,1)) + eq({ 'lines', 'of ' }, funcs.getreg('"', 1, 1)) feed('uu') expect([[ some short lines @@ -504,7 +505,7 @@ describe('mappings with ', function() feed('"bd') expect([[ soest text]]) - eq(funcs.getreg('b',1,1), {'me short lines', 'of t'}) + eq(funcs.getreg('b', 1, 1), { 'me short lines', 'of t' }) -- startinsert aborts operator feed('d') @@ -514,7 +515,6 @@ describe('mappings with ', function() end) it('works in insert mode', function() - -- works the same as ww feed('iindeed little ') screen:expect([[ @@ -535,7 +535,6 @@ describe('mappings with ', function() {3:Press ENTER or type command to continue}^ | ]]) - feed('') eq('E605: Exception not caught: very error', eval('v:errmsg')) -- still in insert @@ -562,7 +561,7 @@ describe('mappings with ', function() of stuff test text]]) feed('') - eq(funcs.getreg('a',1,1), {'deed some short little lines', 'of stuff t'}) + eq(funcs.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' }) -- still in insert screen:expect([[ @@ -704,7 +703,6 @@ describe('mappings with ', function() ]]) eq('i', eval('mode(1)')) eq(9, eval('g:y')) - end) it("doesn't crash when invoking cmdline mode recursively #8859", function() @@ -726,18 +724,20 @@ describe('mappings with ', function() ]]) end) - it("works with mappings", function() + it('works with mappings', function() command('new!') - write_file(tmpfile, [[ + write_file( + tmpfile, + [[ map call do_it() function! s:do_it() let g:x = 10 endfunction - ]]) - command('source '..tmpfile) + ]] + ) + command('source ' .. tmpfile) feed('') eq('', eval('v:errmsg')) eq(10, eval('g:x')) end) end) - diff --git a/test/functional/ex_cmds/debug_spec.lua b/test/functional/ex_cmds/debug_spec.lua index 5c20cb7324..85327c87e6 100644 --- a/test/functional/ex_cmds/debug_spec.lua +++ b/test/functional/ex_cmds/debug_spec.lua @@ -9,10 +9,10 @@ describe(':debug', function() clear() screen = Screen.new(30, 14) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) screen:attach() end) diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 6a0b40bd88..821c8cf593 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -8,7 +8,6 @@ local exec_lua = helpers.exec_lua local command = helpers.command local eval = helpers.eval - describe('Vimscript dictionary notifications', function() local channel @@ -29,9 +28,9 @@ describe('Vimscript dictionary notifications', function() key = 'watched' end if opval == '' then - command(('unlet %s[\'%s\']'):format(dict_expr, key)) + command(("unlet %s['%s']"):format(dict_expr, key)) else - command(('let %s[\'%s\'] %s'):format(dict_expr, key, opval)) + command(("let %s['%s'] %s"):format(dict_expr, key, opval)) end end @@ -40,9 +39,9 @@ describe('Vimscript dictionary notifications', function() key = 'watched' end if opval == '' then - exec_lua(('vim.api.nvim_del_var(\'%s\')'):format(key)) + exec_lua(("vim.api.nvim_del_var('%s')"):format(key)) else - exec_lua(('vim.api.nvim_set_var(\'%s\', %s)'):format(key, opval)) + exec_lua(("vim.api.nvim_set_var('%s', %s)"):format(key, opval)) end end @@ -61,14 +60,14 @@ describe('Vimscript dictionary notifications', function() -- helper to verify that no notifications are sent after certain change -- to a dict nvim('command', "call rpcnotify(g:channel, 'echo')") - eq({'notification', 'echo', {}}, next_msg()) + eq({ 'notification', 'echo', {} }, next_msg()) end local function verify_value(vals, key) if not key then key = 'watched' end - eq({'notification', 'values', {key, vals}}, next_msg()) + eq({ 'notification', 'values', { key, vals } }, next_msg()) end describe(dict_expr .. ' watcher', function() @@ -81,20 +80,20 @@ describe('Vimscript dictionary notifications', function() before_each(function() source([[ function! g:Changed(dict, key, value) - if a:dict isnot ]]..dict_expr..[[ | + if a:dict isnot ]] .. dict_expr .. [[ | throw 'invalid dict' endif call rpcnotify(g:channel, 'values', a:key, a:value) endfunction - call dictwatcheradd(]]..dict_expr..[[, "watched", "g:Changed") - call dictwatcheradd(]]..dict_expr..[[, "watched2", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "watched", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "watched2", "g:Changed") ]]) end) after_each(function() source([[ - call dictwatcherdel(]]..dict_expr..[[, "watched", "g:Changed") - call dictwatcherdel(]]..dict_expr..[[, "watched2", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "watched", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "watched2", "g:Changed") ]]) update('= "test"') update('= "test2"', 'watched2') @@ -134,99 +133,99 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove()', function() update('= "test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) if is_g then it('is triggered by remove() when updated with nvim_*_var', function() update_with_api('"test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) it('is triggered by remove() when updated with vim.g', function() update_with_vim_g('= "test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) end it('is triggered by extend()', function() update('= "xtend"') - verify_value({new = 'xtend'}) + verify_value({ new = 'xtend' }) nvim('command', [[ - call extend(]]..dict_expr..[[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) + call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) ]]) - verify_value({old = 'xtend', new = 'xtend2'}) - verify_value({new = 5}, 'watched2') + verify_value({ old = 'xtend', new = 'xtend2' }) + verify_value({ new = 5 }, 'watched2') update('') - verify_value({old = 'xtend2'}) + verify_value({ old = 'xtend2' }) update('', 'watched2') - verify_value({old = 5}, 'watched2') + verify_value({ old = 5 }, 'watched2') update('', 'watched3') verify_echo() end) it('is triggered with key patterns', function() source([[ - call dictwatcheradd(]]..dict_expr..[[, "wat*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "wat*", "g:Changed") ]]) update('= 1') - verify_value({new = 1}) - verify_value({new = 1}) + verify_value({ new = 1 }) + verify_value({ new = 1 }) update('= 3', 'watched2') - verify_value({new = 3}, 'watched2') - verify_value({new = 3}, 'watched2') + verify_value({ new = 3 }, 'watched2') + verify_value({ new = 3 }, 'watched2') verify_echo() source([[ - call dictwatcherdel(]]..dict_expr..[[, "wat*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "wat*", "g:Changed") ]]) -- watch every key pattern source([[ - call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "*", "g:Changed") ]]) update('= 3', 'another_key') update('= 4', 'another_key') update('', 'another_key') update('= 2') - verify_value({new = 3}, 'another_key') - verify_value({old = 3, new = 4}, 'another_key') - verify_value({old = 4}, 'another_key') - verify_value({old = 1, new = 2}) - verify_value({old = 1, new = 2}) + verify_value({ new = 3 }, 'another_key') + verify_value({ old = 3, new = 4 }, 'another_key') + verify_value({ old = 4 }, 'another_key') + verify_value({ old = 1, new = 2 }) + verify_value({ old = 1, new = 2 }) verify_echo() source([[ - call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "*", "g:Changed") ]]) end) it('is triggered for empty keys', function() command([[ - call dictwatcheradd(]]..dict_expr..[[, "", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "", "g:Changed") ]]) update('= 1', '') - verify_value({new = 1}, '') + verify_value({ new = 1 }, '') update('= 2', '') - verify_value({old = 1, new = 2}, '') + verify_value({ old = 1, new = 2 }, '') command([[ - call dictwatcherdel(]]..dict_expr..[[, "", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "", "g:Changed") ]]) end) it('is triggered for empty keys when using catch-all *', function() command([[ - call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "*", "g:Changed") ]]) update('= 1', '') - verify_value({new = 1}, '') + verify_value({ new = 1 }, '') update('= 2', '') - verify_value({old = 1, new = 2}, '') + verify_value({ old = 1, new = 2 }, '') command([[ - call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "*", "g:Changed") ]]) end) @@ -244,31 +243,31 @@ describe('Vimscript dictionary notifications', function() end test_updates({ - {'= 3', {new = 3}}, - {'= 6', {old = 3, new = 6}}, - {'+= 3', {old = 6, new = 9}}, - {'', {old = 9}} + { '= 3', { new = 3 } }, + { '= 6', { old = 3, new = 6 } }, + { '+= 3', { old = 6, new = 9 } }, + { '', { old = 9 } }, }) test_updates({ - {'= "str"', {new = 'str'}}, - {'= "str2"', {old = 'str', new = 'str2'}}, - {'.= "2str"', {old = 'str2', new = 'str22str'}}, - {'', {old = 'str22str'}} + { '= "str"', { new = 'str' } }, + { '= "str2"', { old = 'str', new = 'str2' } }, + { '.= "2str"', { old = 'str2', new = 'str22str' } }, + { '', { old = 'str22str' } }, }) test_updates({ - {'= [1, 2]', {new = {1, 2}}}, - {'= [1, 2, 3]', {old = {1, 2}, new = {1, 2, 3}}}, + { '= [1, 2]', { new = { 1, 2 } } }, + { '= [1, 2, 3]', { old = { 1, 2 }, new = { 1, 2, 3 } } }, -- the += will update the list in place, so old and new are the same - {'+= [4, 5]', {old = {1, 2, 3, 4, 5}, new = {1, 2, 3, 4, 5}}}, - {'', {old = {1, 2, 3, 4 ,5}}} + { '+= [4, 5]', { old = { 1, 2, 3, 4, 5 }, new = { 1, 2, 3, 4, 5 } } }, + { '', { old = { 1, 2, 3, 4, 5 } } }, }) test_updates({ - {'= {"k": "v"}', {new = {k = 'v'}}}, - {'= {"k1": 2}', {old = {k = 'v'}, new = {k1 = 2}}}, - {'', {old = {k1 = 2}}}, + { '= {"k": "v"}', { new = { k = 'v' } } }, + { '= {"k1": 2}', { old = { k = 'v' }, new = { k1 = 2 } } }, + { '', { old = { k1 = 2 } } }, }) end) end @@ -295,17 +294,17 @@ describe('Vimscript dictionary notifications', function() it('invokes all callbacks when the key is changed', function() nvim('command', 'let g:key = "value"') - eq({'notification', '1', {'key', {new = 'value'}}}, next_msg()) - eq({'notification', '2', {'key', {new = 'value'}}}, next_msg()) + eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) + eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) end) it('only removes watchers that fully match dict, key and callback', function() nvim('command', 'let g:key = "value"') - eq({'notification', '1', {'key', {new = 'value'}}}, next_msg()) - eq({'notification', '2', {'key', {new = 'value'}}}, next_msg()) + eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) + eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') nvim('command', 'let g:key = "v2"') - eq({'notification', '2', {'key', {old = 'value', new = 'v2'}}}, next_msg()) + eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg()) end) end) @@ -315,8 +314,10 @@ describe('Vimscript dictionary notifications', function() call rpcnotify(g:channel, '1', a:key, a:value) endfunction ]]) - eq('Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"', - exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")')) + eq( + 'Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"', + exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")') + ) end) describe('errors', function() @@ -333,13 +334,17 @@ describe('Vimscript dictionary notifications', function() -- WARNING: This suite depends on the above tests it('fails to remove if no watcher with matching callback is found', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(g:, "key", "g:Watcher1")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(g:, "key", "g:Watcher1")') + ) end) it('fails to remove if no watcher with matching key is found', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(g:, "invalid_key", "g:Watcher2")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(g:, "invalid_key", "g:Watcher2")') + ) end) it("does not fail to add/remove if the callback doesn't exist", function() @@ -348,8 +353,10 @@ describe('Vimscript dictionary notifications', function() end) it('fails to remove watcher from v:_null_dict', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")') + ) end) --[[ @@ -373,7 +380,7 @@ describe('Vimscript dictionary notifications', function() ]]) command('call g:ReplaceWatcher2()') command('let g:key = "value"') - eq({'notification', '2b', {'key', {old = 'v2', new = 'value'}}}, next_msg()) + eq({ 'notification', '2b', { 'key', { old = 'v2', new = 'value' } } }, next_msg()) end) it('does not crash when freeing a watched dictionary', function() @@ -400,7 +407,7 @@ describe('Vimscript dictionary notifications', function() call dictwatcheradd(d, 'foo', {dict, key, value -> rpcnotify(g:channel, '2', key, value)}) let d.foo = 'bar' ]]) - eq({'notification', '2', {'foo', {old = 'baz', new = 'bar'}}}, next_msg()) + eq({ 'notification', '2', { 'foo', { old = 'baz', new = 'bar' } } }, next_msg()) end) end) @@ -412,12 +419,11 @@ describe('Vimscript dictionary notifications', function() call dictwatcheradd(b:, 'changedtick', 'OnTickChanged') ]]) - insert('t'); - eq({'notification', 'SendChangeTick', {'changedtick', {old = 2, new = 3}}}, - next_msg()) + insert('t') + eq({ 'notification', 'SendChangeTick', { 'changedtick', { old = 2, new = 3 } } }, next_msg()) command([[call dictwatcherdel(b:, 'changedtick', 'OnTickChanged')]]) - insert('t'); + insert('t') assert_alive() end) @@ -479,7 +485,7 @@ describe('Vimscript dictionary notifications', function() let g:d.foo = 23 ]]) eq(23, eval('g:d.foo')) - eq({"W1"}, eval('g:calls')) + eq({ 'W1' }, eval('g:calls')) end) it('calls watcher deleted in callback', function() @@ -507,7 +513,6 @@ describe('Vimscript dictionary notifications', function() let g:d.foo = 123 ]]) eq(123, eval('g:d.foo')) - eq({"W1", "W2", "W2", "W1"}, eval('g:calls')) + eq({ 'W1', 'W2', 'W2', 'W1' }, eval('g:calls')) end) - end) diff --git a/test/functional/ex_cmds/digraphs_spec.lua b/test/functional/ex_cmds/digraphs_spec.lua index 5de2adc191..24b6f7c53b 100644 --- a/test/functional/ex_cmds/digraphs_spec.lua +++ b/test/functional/ex_cmds/digraphs_spec.lua @@ -10,13 +10,13 @@ describe(':digraphs', function() clear() screen = Screen.new(65, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [4] = {bold = true}, - [5] = {background = Screen.colors.LightGrey}, - [6] = {foreground = Screen.colors.Blue1}, - [7] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true }, + [5] = { background = Screen.colors.LightGrey }, + [6] = { foreground = Screen.colors.Blue1 }, + [7] = { bold = true, reverse = true }, }) screen:attach() end) diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua index 41f0ada567..c78928f7a1 100644 --- a/test/functional/ex_cmds/drop_spec.lua +++ b/test/functional/ex_cmds/drop_spec.lua @@ -3,7 +3,7 @@ local command = helpers.command local Screen = require('test.functional.ui.screen') local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command -describe(":drop", function() +describe(':drop', function() local screen before_each(function() @@ -11,16 +11,16 @@ describe(":drop", function() screen = Screen.new(35, 10) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {bold = true, reverse = true}, - [2] = {reverse = true}, - [3] = {bold = true}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, reverse = true }, + [2] = { reverse = true }, + [3] = { bold = true }, }) - command("set laststatus=2 shortmess-=F") + command('set laststatus=2 shortmess-=F') end) - it("works like :e when called with only one window open", function() - feed_command("drop tmp1.vim") + it('works like :e when called with only one window open', function() + feed_command('drop tmp1.vim') screen:expect([[ ^ | {0:~ }|*7 @@ -29,11 +29,11 @@ describe(":drop", function() ]]) end) - it("switches to an open window showing the buffer", function() - feed_command("edit tmp1") - feed_command("vsplit") - feed_command("edit tmp2") - feed_command("drop tmp1") + it('switches to an open window showing the buffer', function() + feed_command('edit tmp1') + feed_command('vsplit') + feed_command('edit tmp2') + feed_command('drop tmp1') screen:expect([[ │^ | {0:~ }│{0:~ }|*7 @@ -43,12 +43,12 @@ describe(":drop", function() end) it("splits off a new window when a buffer can't be abandoned", function() - command("set nohidden") - feed_command("edit tmp1") - feed_command("vsplit") - feed_command("edit tmp2") - feed("iABC") - feed_command("drop tmp3") + command('set nohidden') + feed_command('edit tmp1') + feed_command('vsplit') + feed_command('edit tmp2') + feed('iABC') + feed_command('drop tmp3') screen:expect([[ ^ │ | {0:~ }│{0:~ }|*3 @@ -59,5 +59,4 @@ describe(":drop", function() "tmp3" [New] | ]]) end) - end) diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua index a6be04138b..4698d3de62 100644 --- a/test/functional/ex_cmds/echo_spec.lua +++ b/test/functional/ex_cmds/echo_spec.lua @@ -14,15 +14,15 @@ local exec_capture = helpers.exec_capture local matches = helpers.matches describe(':echo :echon :echomsg :echoerr', function() - local fn_tbl = {'String', 'StringN', 'StringMsg', 'StringErr'} + local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' } local function assert_same_echo_dump(expected, input, use_eval) - for _,v in pairs(fn_tbl) do - eq(expected, use_eval and eval(v..'('..input..')') or funcs[v](input)) + for _, v in pairs(fn_tbl) do + eq(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) end end local function assert_matches_echo_dump(expected, input, use_eval) - for _,v in pairs(fn_tbl) do - matches(expected, use_eval and eval(v..'('..input..')') or funcs[v](input)) + for _, v in pairs(fn_tbl) do + matches(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) end end @@ -85,14 +85,12 @@ describe(':echo :echon :echomsg :echoerr', function() eq('v:null', funcs.StringErr(NIL)) end) - it('dumps values with at most six digits after the decimal point', - function() + it('dumps values with at most six digits after the decimal point', function() assert_same_echo_dump('1.234568e-20', 1.23456789123456789123456789e-020) assert_same_echo_dump('1.234568', 1.23456789123456789123456789) end) - it('dumps values with at most seven digits before the decimal point', - function() + it('dumps values with at most seven digits before the decimal point', function() assert_same_echo_dump('1234567.891235', 1234567.89123456789123456789) assert_same_echo_dump('1.234568e7', 12345678.9123456789123456789) end) @@ -115,8 +113,8 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('dumps large values', function() - assert_same_echo_dump('2147483647', 2^31-1) - assert_same_echo_dump('-2147483648', -2^31) + assert_same_echo_dump('2147483647', 2 ^ 31 - 1) + assert_same_echo_dump('-2147483648', -2 ^ 31) end) end) @@ -198,75 +196,95 @@ describe(':echo :echon :echomsg :echoerr', function() let TestDictRef = function('TestDict', d) let d.tdr = TestDictRef ]]) - eq(dedent([[ + eq( + dedent([[ function('TestDict', {'tdr': function('TestDict', {...@1})})]]), - exec_capture('echo String(d.tdr)')) + exec_capture('echo String(d.tdr)') + ) end) it('dumps automatically created partials', function() assert_same_echo_dump( "function('1_Test2', {'f': function('1_Test2')})", '{"f": Test2_f}.f', - true) + true + ) assert_same_echo_dump( "function('1_Test2', [1], {'f': function('1_Test2', [1])})", '{"f": function(Test2_f, [1])}.f', - true) + true + ) end) it('dumps manually created partials', function() - assert_same_echo_dump("function('Test3', [1, 2], {})", - "function('Test3', [1, 2], {})", true) - assert_same_echo_dump("function('Test3', [1, 2])", - "function('Test3', [1, 2])", true) - assert_same_echo_dump("function('Test3', {})", - "function('Test3', {})", true) + assert_same_echo_dump("function('Test3', [1, 2], {})", "function('Test3', [1, 2], {})", true) + assert_same_echo_dump("function('Test3', [1, 2])", "function('Test3', [1, 2])", true) + assert_same_echo_dump("function('Test3', {})", "function('Test3', {})", true) end) - it('does not crash or halt when dumping partials with reference cycles in self', - function() - meths.set_var('d', {v=true}) - eq(dedent([[ - {'p': function('1_Test2', {...@0}), 'f': function('1_Test2'), 'v': v:true}]]), - exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) + it('does not crash or halt when dumping partials with reference cycles in self', function() + meths.set_var('d', { v = true }) + eq( + dedent( + [[ + {'p': function('1_Test2', {...@0}), 'f': function('1_Test2'), 'v': v:true}]] + ), + exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))') + ) end) - it('does not show errors when dumping partials referencing the same dictionary', - function() + it('does not show errors when dumping partials referencing the same dictionary', function() command('let d = {}') -- Regression for “eval/typval_encode: Dump empty dictionary before -- checking for refcycle”, results in error. - eq('[function(\'tr\', {}), function(\'tr\', {})]', eval('String([function("tr", d), function("tr", d)])')) + eq( + "[function('tr', {}), function('tr', {})]", + eval('String([function("tr", d), function("tr", d)])') + ) -- Regression for “eval: Work with reference cycles in partials (self) -- properly”, results in crash. eval('extend(d, {"a": 1})') - eq('[function(\'tr\', {\'a\': 1}), function(\'tr\', {\'a\': 1})]', eval('String([function("tr", d), function("tr", d)])')) + eq( + "[function('tr', {'a': 1}), function('tr', {'a': 1})]", + eval('String([function("tr", d), function("tr", d)])') + ) end) - it('does not crash or halt when dumping partials with reference cycles in arguments', - function() + it('does not crash or halt when dumping partials with reference cycles in arguments', function() meths.set_var('l', {}) eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in -- test/unit/api/private_helpers_spec.lua. eval('add(l, function("Test1", l))') - eq(dedent([=[ - function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=]), - exec_capture('echo String(function("Test1", l))')) + eq( + dedent( + [=[ + function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=] + ), + exec_capture('echo String(function("Test1", l))') + ) end) - it('does not crash or halt when dumping partials with reference cycles in self and arguments', - function() - meths.set_var('d', {v=true}) - meths.set_var('l', {}) - eval('add(l, l)') - eval('add(l, function("Test1", l))') - eval('add(l, function("Test1", d))') - eq(dedent([=[ - {'p': function('1_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('1_Test2'), 'v': v:true}]=]), - exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) - end) + it( + 'does not crash or halt when dumping partials with reference cycles in self and arguments', + function() + meths.set_var('d', { v = true }) + meths.set_var('l', {}) + eval('add(l, l)') + eval('add(l, function("Test1", l))') + eval('add(l, function("Test1", d))') + eq( + dedent( + [=[ + {'p': function('1_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('1_Test2'), 'v': v:true}]=] + ), + exec_capture( + 'echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))' + ) + ) + end + ) end) describe('used to represent lists', function() @@ -275,15 +293,15 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('dumps non-empty list', function() - assert_same_echo_dump('[1, 2]', {1,2}) + assert_same_echo_dump('[1, 2]', { 1, 2 }) end) it('dumps nested lists', function() - assert_same_echo_dump('[[[[[]]]]]', {{{{{}}}}}) + assert_same_echo_dump('[[[[[]]]]]', { { { { {} } } } }) end) it('dumps nested non-empty lists', function() - assert_same_echo_dump('[1, [[3, [[5], 4]], 2]]', {1, {{3, {{5}, 4}}, 2}}) + assert_same_echo_dump('[1, [[3, [[5], 4]], 2]]', { 1, { { 3, { { 5 }, 4 } }, 2 } }) end) it('does not error when dumping recursive lists', function() @@ -308,27 +326,25 @@ describe(':echo :echon :echomsg :echoerr', function() it('dumps list with two same empty dictionaries, also in partials', function() command('let d = {}') assert_same_echo_dump('[{}, {}]', '[d, d]', true) - eq('[function(\'tr\', {}), {}]', eval('String([function("tr", d), d])')) - eq('[{}, function(\'tr\', {})]', eval('String([d, function("tr", d)])')) + eq("[function('tr', {}), {}]", eval('String([function("tr", d), d])')) + eq("[{}, function('tr', {})]", eval('String([d, function("tr", d)])')) end) it('dumps non-empty dictionary', function() - assert_same_echo_dump("{'t''est': 1}", {["t'est"]=1}) + assert_same_echo_dump("{'t''est': 1}", { ["t'est"] = 1 }) end) it('does not error when dumping recursive dictionaries', function() - meths.set_var('d', {d=1}) + meths.set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq(0, exc_exec('echo String(d)')) end) it('dumps recursive dictionaries without the error', function() - meths.set_var('d', {d=1}) + meths.set_var('d', { d = 1 }) eval('extend(d, {"d": d})') - eq('{\'d\': {...@0}}', - exec_capture('echo String(d)')) - eq('{\'out\': {\'d\': {...@1}}}', - exec_capture('echo String({"out": d})')) + eq("{'d': {...@0}}", exec_capture('echo String(d)')) + eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})')) end) end) diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua index 6ed500a293..48ae99a0fa 100644 --- a/test/functional/ex_cmds/edit_spec.lua +++ b/test/functional/ex_cmds/edit_spec.lua @@ -1,27 +1,27 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local ok = helpers.ok local clear = helpers.clear local feed = helpers.feed -describe(":edit", function() +describe(':edit', function() before_each(function() clear() end) - it("without arguments does not restart :terminal buffer", function() - command("terminal") - feed([[]]) - local bufname_before = funcs.bufname("%") - local bufnr_before = funcs.bufnr("%") - helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + it('without arguments does not restart :terminal buffer', function() + command('terminal') + feed([[]]) + local bufname_before = funcs.bufname('%') + local bufnr_before = funcs.bufnr('%') + helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity - command("edit") + command('edit') - local bufname_after = funcs.bufname("%") - local bufnr_after = funcs.bufnr("%") - ok(funcs.line('$') > 1) - eq(bufname_before, bufname_after) - eq(bufnr_before, bufnr_after) + local bufname_after = funcs.bufname('%') + local bufnr_after = funcs.bufnr('%') + ok(funcs.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) end) end) diff --git a/test/functional/ex_cmds/encoding_spec.lua b/test/functional/ex_cmds/encoding_spec.lua index 7f2bd78a47..8953fb8eaf 100644 --- a/test/functional/ex_cmds/encoding_spec.lua +++ b/test/functional/ex_cmds/encoding_spec.lua @@ -3,7 +3,6 @@ local clear, feed_command, feed = helpers.clear, helpers.feed_command, helpers.f local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval describe('&encoding', function() - before_each(function() clear() -- sanity check: tests should run with encoding=utf-8 @@ -32,9 +31,9 @@ describe('&encoding', function() it('can be set to utf-8 without error', function() feed_command('set encoding=utf-8') - eq("", eval('v:errmsg')) + eq('', eval('v:errmsg')) clear('--cmd', 'set enc=utf-8') - eq("", eval('v:errmsg')) + eq('', eval('v:errmsg')) end) end) diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index a92329ede5..030816c6cb 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -1,4 +1,4 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear @@ -20,15 +20,25 @@ describe('Ex cmds', function() command(':later 9999999999999999999999999999999999999999') command(':echo expand("#<9999999999999999999999999999999999999999")') command(':lockvar 9999999999999999999999999999999999999999') - command(':winsize 9999999999999999999999999999999999999999 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')) + command( + ':winsize 9999999999999999999999999999999999999999 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') + ) assert_alive() end) diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua index 131661828e..bfcfccda7b 100644 --- a/test/functional/ex_cmds/file_spec.lua +++ b/test/functional/ex_cmds/file_spec.lua @@ -8,7 +8,7 @@ local rmdir = helpers.rmdir local mkdir = helpers.mkdir describe(':file', function() - local swapdir = luv.cwd()..'/Xtest-file_spec' + local swapdir = luv.cwd() .. '/Xtest-file_spec' before_each(function() clear() rmdir(swapdir) @@ -19,18 +19,17 @@ describe(':file', function() rmdir(swapdir) end) - it("rename does not lose swapfile #6487", function() + it('rename does not lose swapfile #6487', function() local testfile = 'test-file_spec' - local testfile_renamed = testfile..'-renamed' + local testfile_renamed = testfile .. '-renamed' -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. - command('set directory^='..swapdir..'//') + command('set directory^=' .. swapdir .. '//') command('set swapfile fileformat=unix undolevels=-1') - command('edit! '..testfile) + command('edit! ' .. testfile) -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. - command('file '..testfile_renamed) - eq(testfile_renamed..'.swp', - string.match(funcs.execute('swapname'), '[^%%]+$')) + command('file ' .. testfile_renamed) + eq(testfile_renamed .. '.swp', string.match(funcs.execute('swapname'), '[^%%]+$')) end) end) diff --git a/test/functional/ex_cmds/grep_spec.lua b/test/functional/ex_cmds/grep_spec.lua index 43ef1bd424..bf81ba2137 100644 --- a/test/functional/ex_cmds/grep_spec.lua +++ b/test/functional/ex_cmds/grep_spec.lua @@ -15,7 +15,7 @@ describe(':grep', function() -- Change to test directory so that the test does not run too long. feed_command('cd test') feed_command('grep a **/*') - feed('') -- Press ENTER - ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 + feed('') -- Press ENTER + ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 end) end) diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 958dd99226..6aac8c2e3a 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -1,5 +1,5 @@ local Screen = require('test.functional.ui.screen') -local helpers = require("test.functional.helpers")(after_each) +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 @@ -17,15 +17,18 @@ describe(':highlight', function() end) it('invalid color name', function() - eq('Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', - exc_exec("highlight normal ctermfg=#181818")) - eq('Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818', - exc_exec("highlight normal ctermbg=#181818")) + eq( + 'Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', + exc_exec('highlight normal ctermfg=#181818') + ) + eq( + 'Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818', + exc_exec('highlight normal ctermbg=#181818') + ) end) it('invalid group name', function() - eq('Vim(highlight):E411: Highlight group not found: foo', - exc_exec("highlight foo")) + eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec('highlight foo')) end) it('"Normal" foreground with red', function() diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index d02af21731..a2a95fbf3f 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -44,6 +44,4 @@ describe(':ls', function() eq('\n 3 %aF ', string.match(ls_output, '^\n *3 ... ')) end) end) - end) - diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index d82f59ddf9..88fd0e14e1 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -8,27 +8,30 @@ local testprg = helpers.testprg describe(':make', function() clear() - before_each(function () + before_each(function() clear() end) describe('with powershell', function() if not has_powershell() then - pending("not tested; powershell was not found", function() end) + pending('not tested; powershell was not found', function() end) return end - before_each(function () + before_each(function() helpers.set_shell_powershell() end) - it('captures stderr & non zero exit code #14349', function () - nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {}) + it('captures stderr & non zero exit code #14349', function() + nvim('set_option_value', 'makeprg', testprg('shell-test') .. ' foo', {}) local out = eval('execute("make")') -- Error message is captured in the file and printed in the footer - matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: 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 () + it('captures stderr & zero exit code #14349', function() nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between @@ -36,7 +39,5 @@ describe(':make', function() matches('LastExitCode%s+ready [$]%s+[(]', out) matches('\n.*%: ready [$]', out) end) - end) - end) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index c8855337ef..934dac6a2d 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -1,4 +1,4 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq @@ -33,23 +33,27 @@ describe(':*map', function() it('shows as mapping rhs', function() command('nmap asdf ') - eq([[ + eq( + [[ n asdf ]], - exec_capture('nmap asdf')) + exec_capture('nmap asdf') + ) end) it('mappings with description can be filtered', function() - meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) - meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) - meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) - eq([[ + meths.set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' }) + meths.set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' }) + meths.set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' }) + eq( + [[ n asdf3 qwert do the other thing n asdf1 qwert do the one thing]], - exec_capture('filter the nmap')) + exec_capture('filter the nmap') + ) end) it(' mappings ignore nore', function() @@ -75,7 +79,7 @@ n asdf1 qwert nmap increase_x_remap x(Increase_x)x nnoremap increase_x_noremap x(Increase_x)x ]] - insert("Some text") + insert('Some text') eq('Some text', eval("getline('.')")) feed('increase_x_remap') diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index b9ed32c328..d6d8cce161 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -4,9 +4,7 @@ local expect, feed = helpers.expect, helpers.feed local eq, eval = helpers.eq, helpers.eval local funcs = helpers.funcs - describe(':emenu', function() - before_each(function() clear() command('nnoremenu Test.Test inormal') @@ -41,26 +39,25 @@ describe(':emenu', function() end) it('executes correct bindings in command mode', function() - feed('ithis is a sentence^yiwo') + feed('ithis is a sentence^yiwo') - -- Invoke "Edit.Paste" in normal-mode. - nvim('command', 'emenu Edit.Paste') + -- Invoke "Edit.Paste" in normal-mode. + nvim('command', 'emenu Edit.Paste') - -- Invoke "Edit.Paste" and "Test.Test" in command-mode. - feed(':') - nvim('command', 'emenu Edit.Paste') - nvim('command', 'emenu Test.Test') + -- Invoke "Edit.Paste" and "Test.Test" in command-mode. + feed(':') + nvim('command', 'emenu Edit.Paste') + nvim('command', 'emenu Test.Test') - expect([[ + expect([[ this is a sentence this]]) - -- Assert that Edit.Paste pasted @" into the commandline. - eq('thiscmdmode', eval('getcmdline()')) + -- Assert that Edit.Paste pasted @" into the commandline. + eq('thiscmdmode', eval('getcmdline()')) end) end) describe('menu_get', function() - before_each(function() clear() command([=[ @@ -83,12 +80,12 @@ describe('menu_get', function() end) it("path='', modes='a'", function() - local m = funcs.menu_get("","a"); + local m = funcs.menu_get('', 'a') -- HINT: To print the expected table and regenerate the tests: -- print(require('vim.inspect')(m)) local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -97,45 +94,45 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 + rhs = 'insert', + silent = 0, }, s = { sid = 1, noremap = 1, enabled = 1, - rhs = "x", - silent = 0 + rhs = 'x', + silent = 0, }, n = { sid = 1, noremap = 1, enabled = 1, - rhs = "inormal", - silent = 0 + rhs = 'inormal', + silent = 0, }, v = { sid = 1, noremap = 1, enabled = 1, - rhs = "x", - silent = 0 + rhs = 'x', + silent = 0, }, c = { sid = 1, noremap = 1, enabled = 1, - rhs = "cmdmode", - silent = 0 - } + rhs = 'cmdmode', + silent = 0, + }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, { priority = 500, - name = "Nested", + name = 'Nested', submenus = { { mappings = { @@ -143,34 +140,34 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 - } + rhs = 'level1', + silent = 0, + }, }, priority = 500, - name = "test", - hidden = 0 + name = 'test', + hidden = 0, }, { mappings = { @@ -178,67 +175,67 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 - } + rhs = 'level2', + silent = 0, + }, }, priority = 500, - name = "Nested2", - hidden = 0 - } + name = 'Nested2', + hidden = 0, + }, }, - hidden = 0 - } + hidden = 0, + }, }, priority = 500, - name = "Test" + name = 'Test', }, { priority = 500, - name = "Export", + name = 'Export', submenus = { { - tooltip = "This is the tooltip", + tooltip = 'This is the tooltip', hidden = 0, - name = "Script", + name = 'Script', priority = 500, mappings = { n = { sid = 1, noremap = 1, enabled = 1, - rhs = "p", - silent = 0 - } - } - } + rhs = 'p', + silent = 0, + }, + }, + }, }, - hidden = 0 + hidden = 0, }, { priority = 500, - name = "Edit", + name = 'Edit', submenus = { { mappings = { @@ -246,27 +243,27 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "\"", - silent = 0 + rhs = '"', + silent = 0, }, n = { sid = 1, noremap = 1, enabled = 1, - rhs = "p", - silent = 0 - } + rhs = 'p', + silent = 0, + }, }, priority = 500, - name = "Paste", - hidden = 0 - } + name = 'Paste', + hidden = 0, + }, }, - hidden = 0 + hidden = 0, }, { priority = 500, - name = "]Export", + name = ']Export', submenus = { { mappings = { @@ -274,72 +271,76 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 - } + rhs = 'thisoneshouldbehidden', + silent = 0, + }, }, priority = 500, - name = "hidden", - hidden = 0 - } + name = 'hidden', + hidden = 0, + }, }, - hidden = 1 - } + hidden = 1, + }, } eq(expected, m) end) it('matching path, all modes', function() - local m = funcs.menu_get("Export", "a") - local expected = { { - hidden = 0, - name = "Export", - priority = 500, - submenus = { { - tooltip = "This is the tooltip", + local m = funcs.menu_get('Export', 'a') + local expected = { + { hidden = 0, - name = "Script", + name = 'Export', priority = 500, - mappings = { - n = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "p", - silent = 0 - } - } - } } - } } + submenus = { + { + tooltip = 'This is the tooltip', + hidden = 0, + name = 'Script', + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = 'p', + silent = 0, + }, + }, + }, + }, + }, + } eq(expected, m) end) it('no path, matching modes', function() - local m = funcs.menu_get("","i") + local m = funcs.menu_get('', 'i') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -348,27 +349,27 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 - } + rhs = 'insert', + silent = 0, + }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, }, priority = 500, - name = "Test" - } + name = 'Test', + }, } eq(expected, m) end) it('matching path and modes', function() - local m = funcs.menu_get("Test","i") + local m = funcs.menu_get('Test', 'i') local expected = { { - shortcut = "T", + shortcut = 'T', submenus = { { mappings = { @@ -376,26 +377,25 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 + rhs = 'insert', + silent = 0, }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, }, priority = 500, - name = "Test", - hidden = 0 - } + name = 'Test', + hidden = 0, + }, } eq(expected, m) end) end) describe('menu_get', function() - before_each(function() clear() command('aunmenu *') @@ -412,10 +412,10 @@ describe('menu_get', function() command('nnoremenu &Test.Test8 ') command('nnoremenu &Test.Test9 ""') - local m = funcs.menu_get(""); + local m = funcs.menu_get('') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -425,12 +425,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "inormal", - silent = 0 - } + rhs = 'inormal', + silent = 0, + }, }, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, { priority = 500, @@ -439,12 +439,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test2", - hidden = 0 + name = 'Test2', + hidden = 0, }, { priority = 500, @@ -453,19 +453,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "yA0xyz", - silent = 0 + rhs = 'yA0xyz', + silent = 0, }, v = { sid = 1, noremap = 1, enabled = 1, - rhs = "yA0xyz", - silent = 0 - } + rhs = 'yA0xyz', + silent = 0, + }, }, - name = "Test3", - hidden = 0 + name = 'Test3', + hidden = 0, }, { priority = 500, @@ -474,12 +474,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "*", - silent = 0 - } + rhs = '*', + silent = 0, + }, }, - name = "Test4", - hidden = 0 + name = 'Test4', + hidden = 0, }, { priority = 500, @@ -488,12 +488,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "+", - silent = 0 - } + rhs = '+', + silent = 0, + }, }, - name = "Test5", - hidden = 0 + name = 'Test5', + hidden = 0, }, { priority = 500, @@ -502,12 +502,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test6", - hidden = 0 + name = 'Test6', + hidden = 0, }, { priority = 500, @@ -516,12 +516,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test7", - hidden = 0 + name = 'Test7', + hidden = 0, }, { priority = 500, @@ -530,12 +530,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test8", - hidden = 0 + name = 'Test8', + hidden = 0, }, { priority = 500, @@ -544,17 +544,17 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "\"\"", - silent = 0 - } + rhs = '""', + silent = 0, + }, }, - name = "Test9", - hidden = 0 - } + name = 'Test9', + hidden = 0, + }, }, priority = 500, - name = "Test" - } + name = 'Test', + }, } eq(m, expected) @@ -565,12 +565,12 @@ describe('menu_get', function() command('nnoremenu &Test\\ 1.Test\\ 2 Wargl') command('nnoremenu &Test4.Test3 i space') - local m = funcs.menu_get(""); + local m = funcs.menu_get('') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, - actext = "Y", + actext = 'Y', submenus = { { mappings = { @@ -578,21 +578,21 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "inormal", - silent = 0 - } + rhs = 'inormal', + silent = 0, + }, }, hidden = 0, - actext = "X x", + actext = 'X x', priority = 500, - name = "Test" - } + name = 'Test', + }, }, priority = 500, - name = "Test" + name = 'Test', }, { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -602,19 +602,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "Wargl", - silent = 0 - } + rhs = 'Wargl', + silent = 0, + }, }, - name = "Test 2", - hidden = 0 - } + name = 'Test 2', + hidden = 0, + }, }, priority = 500, - name = "Test 1" + name = 'Test 1', }, { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -623,19 +623,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "i space", - silent = 0 - } + rhs = 'i space', + silent = 0, + }, }, hidden = 0, - actext = "3", + actext = '3', priority = 500, - name = "Test" - } + name = 'Test', + }, }, priority = 500, - name = "Test4" - } + name = 'Test4', + }, } eq(m, expected) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 7d9379b703..7d93b972d1 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -18,7 +18,9 @@ local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' -if helpers.skip(helpers.is_os('win')) then return end +if helpers.skip(helpers.is_os('win')) then + return +end describe(':mksession', function() local session_file = file_prefix .. '.vim' diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua index f71b826210..fa8da6e981 100644 --- a/test/functional/ex_cmds/mkview_spec.lua +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -29,8 +29,7 @@ describe(':mkview', function() it('viewoption curdir restores local current directory', function() local cwd_dir = funcs.getcwd() - local set_view_dir_command = 'set viewdir=' .. cwd_dir .. - get_pathsep() .. view_dir + local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir -- By default the local current directory should save command(set_view_dir_command) @@ -63,5 +62,4 @@ describe(':mkview', function() -- The view's local directory should have been saved eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd()) end) - end) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 19611429e0..11bebb3793 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -12,9 +12,15 @@ local eval = helpers.eval local shada_file = 'Xtest.shada' local function _clear() - clear{args={'-i', shada_file, -- Need shada for these tests. - '--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'}, - args_rm={'-i', '--cmd'}} + clear { + args = { + '-i', + shada_file, -- Need shada for these tests. + '--cmd', + 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler', + }, + args_rm = { '-i', '--cmd' }, + } end describe(':oldfiles', function() @@ -40,8 +46,8 @@ describe(':oldfiles', function() feed_command('oldfiles') screen:expect([[ | - 1: ]].. add_padding(oldfiles[1]) ..[[ | - 2: ]].. add_padding(oldfiles[2]) ..[[ | + 1: ]] .. add_padding(oldfiles[1]) .. [[ | + 2: ]] .. add_padding(oldfiles[2]) .. [[ | | Press ENTER or type command to continue^ | ]]) @@ -59,7 +65,7 @@ describe(':oldfiles', function() feed_command('rshada!') local function get_oldfiles(cmd) - local t = eval([[split(execute(']]..cmd..[['), "\n")]]) + local t = eval([[split(execute(']] .. cmd .. [['), "\n")]]) for i, _ in ipairs(t) do t[i] = t[i]:gsub('^%d+:%s+', '') end @@ -68,16 +74,16 @@ describe(':oldfiles', function() end local oldfiles = get_oldfiles('oldfiles') - eq({another, file1, file2}, oldfiles) + eq({ another, file1, file2 }, oldfiles) oldfiles = get_oldfiles('filter file_ oldfiles') - eq({file1, file2}, oldfiles) + eq({ file1, file2 }, oldfiles) oldfiles = get_oldfiles('filter /another/ oldfiles') - eq({another}, oldfiles) + eq({ another }, oldfiles) oldfiles = get_oldfiles('filter! file_ oldfiles') - eq({another}, oldfiles) + eq({ another }, oldfiles) end) end) diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua index 98c0f74635..bcb3c437ed 100644 --- a/test/functional/ex_cmds/print_commands_spec.lua +++ b/test/functional/ex_cmds/print_commands_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, command, funcs = - helpers.clear, helpers.eq, helpers.command, helpers.funcs +local clear, eq, command, funcs = helpers.clear, helpers.eq, helpers.command, helpers.funcs describe(':z^', function() before_each(clear) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index 249373a9c4..fb594c70e6 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -1,13 +1,13 @@ require('os') local luv = require('luv') -local helpers = require('test.functional.helpers')(after_each) -local eval = helpers.eval -local command = helpers.command -local eq, neq = helpers.eq, helpers.neq +local helpers = require('test.functional.helpers')(after_each) +local eval = helpers.eval +local command = helpers.command +local eq, neq = helpers.eq, helpers.neq local tempfile = helpers.tmpname() -local source = helpers.source -local matches = helpers.matches +local source = helpers.source +local matches = helpers.matches local read_file = helpers.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index d866a862cf..e694f5d1da 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -15,20 +15,24 @@ local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' before_each(clear) -for _, c in ipairs({'l', 'c'}) do +for _, c in ipairs({ 'l', 'c' }) do local file = ('%s.%s'):format(file_base, c) local filecmd = c .. 'file' local getfcmd = c .. 'getfile' local addfcmd = c .. 'addfile' - local getlist = (c == 'c') and funcs.getqflist or ( - function() return funcs.getloclist(0) end) + local getlist = (c == 'c') and funcs.getqflist or function() + return funcs.getloclist(0) + end describe((':%s*file commands'):format(c), function() before_each(function() - write_file(file, ([[ + write_file( + file, + ([[ %s-1.res:700:10:Line 700 %s-2.res:800:15:Line 800 - ]]):format(file, file)) + ]]):format(file, file) + ) end) after_each(function() os.remove(file) @@ -39,10 +43,34 @@ for _, c in ipairs({'l', 'c'}) do -- Second line of each entry (i.e. `nr=-1, …`) was obtained from actual -- results. First line (i.e. `{lnum=…`) was obtained from legacy test. local list = { - {lnum=700, end_lnum=0, col=10, end_col=0, text='Line 700', module='', - nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, - {lnum=800, end_lnum=0, col=15, end_col=0, text='Line 800', module='', - nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + { + lnum = 700, + end_lnum = 0, + col = 10, + end_col = 0, + text = 'Line 700', + module = '', + nr = -1, + bufnr = 2, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, + { + lnum = 800, + end_lnum = 0, + col = 15, + end_col = 0, + text = 'Line 800', + module = '', + nr = -1, + bufnr = 3, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, } eq(list, getlist()) eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) @@ -51,33 +79,74 @@ for _, c in ipairs({'l', 'c'}) do -- Run cfile/lfile from a modified buffer command('set nohidden') command('enew!') - curbufmeths.set_lines(1, 1, true, {'Quickfix'}) - eq(('Vim(%s):E37: No write since last change (add ! to override)'):format( - filecmd), - exc_exec(('%s %s'):format(filecmd, file))) + curbufmeths.set_lines(1, 1, true, { 'Quickfix' }) + eq( + ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), + exc_exec(('%s %s'):format(filecmd, file)) + ) - write_file(file, ([[ + write_file( + file, + ([[ %s-3.res:900:30:Line 900 - ]]):format(file)) + ]]):format(file) + ) command(('%s %s'):format(addfcmd, file)) list[#list + 1] = { - lnum=900, end_lnum=0, col=30, end_col=0, text='Line 900', module='', - nr=-1, bufnr=5, valid=1, pattern='', vcol=0, ['type']='', + lnum = 900, + end_lnum = 0, + col = 30, + end_col = 0, + text = 'Line 900', + module = '', + nr = -1, + bufnr = 5, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', } eq(list, getlist()) eq(('%s-3.res'):format(file), funcs.bufname(list[3].bufnr)) - write_file(file, ([[ + write_file( + file, + ([[ %s-1.res:222:77:Line 222 %s-2.res:333:88:Line 333 - ]]):format(file, file)) + ]]):format(file, file) + ) command('enew!') command(('%s %s'):format(getfcmd, file)) list = { - {lnum=222, end_lnum=0, col=77, end_col=0, text='Line 222', module='', - nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, - {lnum=333, end_lnum=0, col=88, end_col=0, text='Line 333', module='', - nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + { + lnum = 222, + end_lnum = 0, + col = 77, + end_col = 0, + text = 'Line 222', + module = '', + nr = -1, + bufnr = 2, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, + { + lnum = 333, + end_lnum = 0, + col = 88, + end_col = 0, + text = 'Line 333', + module = '', + nr = -1, + bufnr = 3, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, } eq(list, getlist()) eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) @@ -109,7 +178,7 @@ describe('quickfix', function() call append(0, ['New line 1', 'New line 2', 'New line 3']) silent ll ]]) - eq({0, 6, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 6, 1, 0, 1 }, funcs.getcurpos()) end) it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function() @@ -127,11 +196,14 @@ describe('quickfix', function() end) it(':vimgrep can specify Unicode pattern without delimiters', function() - eq('Vim(vimgrep):E480: No match: →', exc_exec('vimgrep → test/functional/fixtures/tty-test.c')) + eq( + 'Vim(vimgrep):E480: No match: →', + exc_exec('vimgrep → test/functional/fixtures/tty-test.c') + ) local screen = Screen.new(40, 6) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {reverse = true}, -- IncSearch + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { reverse = true }, -- IncSearch }) screen:attach() feed('i→:vimgrep →') diff --git a/test/functional/ex_cmds/quit_spec.lua b/test/functional/ex_cmds/quit_spec.lua index 3680801dae..5a1759dab3 100644 --- a/test/functional/ex_cmds/quit_spec.lua +++ b/test/functional/ex_cmds/quit_spec.lua @@ -11,4 +11,3 @@ describe(':qa', function() -- errors end) end) - diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index 62249caa5e..465397169a 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -17,7 +17,7 @@ before_each(clear) local function source(code) write_file(tmpfile, code) - command('source '..tmpfile) + command('source ' .. tmpfile) end describe('script_get-based command', function() @@ -30,29 +30,48 @@ describe('script_get-based command', function() local function test_garbage_exec(cmd, check_neq) describe(cmd, function() it('works correctly when skipping oneline variant', function() - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ if 0 %s %s endif - ]])):format(cmd, garbage))) + ]])):format(cmd, garbage) + ) + ) eq('', exec_capture('messages')) if check_neq then - neq(0, exc_exec(dedent([[ + neq( + 0, + exc_exec(dedent([[ %s %s - ]])):format(cmd, garbage)) + ]])):format(cmd, garbage) + ) end end) it('works correctly when skipping HEREdoc variant', function() - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ if 0 %s << EOF %s EOF endif - ]])):format(cmd, garbage))) + ]])):format(cmd, garbage) + ) + ) eq('', exec_capture('messages')) if check_neq then - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ let g:exc = 0 try %s << EOF @@ -61,7 +80,9 @@ describe('script_get-based command', function() catch let g:exc = v:exception endtry - ]])):format(cmd, garbage))) + ]])):format(cmd, garbage) + ) + ) neq(0, meths.get_var('exc')) end end) diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua index f280a45174..30c6f9ac47 100644 --- a/test/functional/ex_cmds/sign_spec.lua +++ b/test/functional/ex_cmds/sign_spec.lua @@ -9,21 +9,21 @@ describe('sign', function() -- place a sign with id 34 to first buffer nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') local buf1 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf1) + nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf1) -- create a second buffer and place the sign on it as well nvim('command', 'new') local buf2 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf2) + nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf2) -- now unplace without specifying a buffer nvim('command', 'sign unplace 34') - eq("--- Signs ---\n", nvim('exec', 'sign place buffer='..buf1, true)) - eq("--- Signs ---\n", nvim('exec', 'sign place buffer='..buf2, true)) + eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf1, true)) + eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf2, true)) end) end) end) describe('define {id}', function() - it ('does not leak memory when specifying multiple times the same argument', function() + it('does not leak memory when specifying multiple times the same argument', function() nvim('command', 'sign define Foo culhl=Normal culhl=Normal') assert_alive() end) diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 24987354a4..e822fe78b8 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -52,13 +52,16 @@ describe(':source', function() meths.set_option_value('shellslash', false, {}) mkdir('Xshellslash') - write_file([[Xshellslash/Xstack.vim]], [[ + write_file( + [[Xshellslash/Xstack.vim]], + [[ let g:stack1 = expand('') set shellslash let g:stack2 = expand('') set noshellslash let g:stack3 = expand('') - ]]) + ]] + ) for _ = 1, 2 do command([[source Xshellslash/Xstack.vim]]) @@ -67,13 +70,16 @@ describe(':source', function() matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3')) end - write_file([[Xshellslash/Xstack.lua]], [[ + write_file( + [[Xshellslash/Xstack.lua]], + [[ vim.g.stack1 = vim.fn.expand('') vim.o.shellslash = true vim.g.stack2 = vim.fn.expand('') vim.o.shellslash = false vim.g.stack3 = vim.fn.expand('') - ]]) + ]] + ) for _ = 1, 2 do command([[source Xshellslash/Xstack.lua]]) @@ -101,11 +107,11 @@ describe(':source', function() eq("{'k': 'v'}", exec_capture('echo b')) -- Script items are created only on script var access - eq("1", exec_capture('echo c')) - eq("0zBEEFCAFE", exec_capture('echo d')) + 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')) + eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec('source')) end) it('selection in current buffer', function() @@ -132,14 +138,14 @@ describe(':source', function() feed_command(':source') eq('4', exec_capture('echo a')) eq("{'K': 'V'}", exec_capture('echo b')) - eq("1_C()", exec_capture('echo D()')) + eq('1_C()', exec_capture('echo D()')) -- Source last line only feed_command(':$source') eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()')) exec('set cpoptions+=C') - eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec("'<,'>source")) + eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec("'<,'>source")) end) it('does not break if current buffer is modified while sourced', function() @@ -163,12 +169,15 @@ describe(':source', function() it('can source lua files', function() local test_file = 'test.lua' - write_file(test_file, [[ + write_file( + test_file, + [[ vim.g.sourced_lua = 1 vim.g.sfile_value = vim.fn.expand('') vim.g.stack_value = vim.fn.expand('') vim.g.script_value = vim.fn.expand('