diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/vim_spec.lua | 75 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 85 | ||||
-rw-r--r-- | test/functional/eval/timer_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/helpers.lua | 1 | ||||
-rw-r--r-- | test/functional/plugin/lsp/diagnostic_spec.lua | 14 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 46 | ||||
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 5 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 1 | ||||
-rw-r--r-- | test/functional/ui/wildmode_spec.lua | 60 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 17 |
10 files changed, 296 insertions, 12 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index eb5fd7eca7..c42d5c34cc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1921,4 +1921,79 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) end) + + describe('nvim_get_all_options_info', function() + it('should have key value pairs of option names', function() + local options_info = meths.get_all_options_info() + neq(nil, options_info.listchars) + neq(nil, options_info.tabstop) + + eq(meths.get_option_info'winhighlight', options_info.winhighlight) + end) + end) + + describe('nvim_get_option_info', function() + it('should error for unknown options', function() + eq("no such option: 'bogus'", pcall_err(meths.get_option_info, 'bogus')) + end) + + it('should return the same options for short and long name', function() + eq(meths.get_option_info'winhl', meths.get_option_info'winhighlight') + end) + + it('should have information about window options', function() + eq({ + commalist = false; + default = ""; + flaglist = false; + global_local = false; + last_set_chan = 0; + last_set_linenr = 0; + last_set_sid = 0; + name = "winhighlight"; + scope = "win"; + shortname = "winhl"; + type = "string"; + was_set = false; + }, meths.get_option_info'winhl') + end) + + it('should have information about buffer options', function() + eq({ + commalist = false, + default = "", + flaglist = false, + global_local = false, + last_set_chan = 0, + last_set_linenr = 0, + last_set_sid = 0, + name = "filetype", + scope = "buf", + shortname = "ft", + type = "string", + was_set = false + }, meths.get_option_info'filetype') + end) + + it('should have information about global options', function() + -- precondition: the option was changed from its default + -- in test setup. + eq(false, meths.get_option'showcmd') + + eq({ + commalist = false, + default = true, + flaglist = false, + global_local = false, + last_set_chan = 0, + last_set_linenr = 0, + last_set_sid = -2, + name = "showcmd", + scope = "global", + shortname = "sc", + type = "boolean", + was_set = true + }, meths.get_option_info'showcmd') + end) + end) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 27793ab936..ff0fdbea45 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -432,3 +432,88 @@ describe('clean', function() clear('--clean') ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) == nil) end) + +describe('user config init', function() + local xhome = 'Xhome' + local pathsep = helpers.get_pathsep() + local xconfig = xhome .. pathsep .. 'Xconfig' + local init_lua_path = table.concat({xconfig, 'nvim', 'init.lua'}, pathsep) + + before_each(function() + rmdir(xhome) + + -- TODO, make mkdir_p helper + mkdir(xhome) + mkdir(xconfig) + mkdir(xconfig .. pathsep .. 'nvim') + + write_file(init_lua_path, [[ + vim.g.lua_rc = 1 + ]]) + end) + + after_each(function() + rmdir(xhome) + end) + + it('loads init.lua from XDG config home by default', function() + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + + eq(1, eval('g:lua_rc')) + eq(init_lua_path, eval('$MYVIMRC')) + end) + + describe 'with explicitly provided config'(function() + local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) + before_each(function() + 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={ XDG_CONFIG_HOME=xconfig }} + eq(1, eval('g:custom_lua_rc')) + eq('', eval('$MYVIMRC')) + end) + end) + + describe 'VIMRC also exists'(function() + before_each(function() + 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={ XDG_CONFIG_HOME=xconfig }} + feed('<cr>') -- TODO check this, test execution is blocked without it + eq(1, eval('g:lua_rc')) + matches('Conflicting configs', meths.exec('messages', true)) + end) + end) +end) + +describe('user session', function() + local xhome = 'Xhome' + local pathsep = helpers.get_pathsep() + local session_file = table.concat({xhome, 'session.lua'}, pathsep) + + before_each(function() + rmdir(xhome) + + mkdir(xhome) + write_file(session_file, [[ + vim.g.lua_session = 1 + ]]) + end) + + after_each(function() + rmdir(xhome) + end) + + it('loads session from the provided lua file', function() + clear{ args={'-S', session_file }, env={ HOME=xhome }} + eq(1, eval('g:lua_session')) + end) +end) diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index ef7df69fdb..9ee0735e40 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -215,8 +215,8 @@ describe('timers', function() endfunc ]]) command("call timer_start(5, 'MyHandler', {'repeat': 1})") - run(nil, nil, nil, load_adjust(10)) - retry(nil, load_adjust(100), function() + run(nil, nil, nil, load_adjust(20)) + retry(nil, load_adjust(150), function() eq(1, eval("g:val")) end) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index d85a6a3cfe..0829560b9c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -442,6 +442,7 @@ function module.new_argv(...) 'NVIM_LOG_FILE', 'NVIM_RPLUGIN_MANIFEST', 'GCOV_ERROR_FILE', + 'XDG_DATA_DIRS', 'TMPDIR', }) do if not env_tbl[k] then diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 11b2beba7a..3a676359ab 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -68,20 +68,23 @@ describe('vim.lsp.diagnostic', function() describe('vim.lsp.diagnostic', function() describe('handle_publish_diagnostics', function() it('should be able to retrieve diagnostics from all buffers and clients', function() - eq(3, exec_lua [[ + local result = exec_lua [[ vim.lsp.diagnostic.save( { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 2, 1, 2, 1), - }, 0, 1 + }, 1, 1 ) vim.lsp.diagnostic.save( { make_error('Diagnostic #3', 3, 1, 3, 1), - }, 1, 2 + }, 2, 2 ) - return #vim.lsp.diagnostic.get_all() - ]]) + return vim.lsp.diagnostic.get_all() + ]] + eq(2, #result) + eq(2, #result[1]) + eq('Diagnostic #1', result[1][1].message) end) it('should be able to save and count a single client error', function() eq(1, exec_lua [[ @@ -153,7 +156,6 @@ describe('vim.lsp.diagnostic', function() } ]]) end) - it('should handle one server clearing highlights while the other still has highlights', function() -- 1 Error (1) -- 1 Warning (2) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 5b048f57e9..f01d90bbeb 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -323,23 +323,61 @@ describe('LSP', function() test_name = "capabilities_for_client_supports_method"; on_setup = function() exec_lua([=[ - vim.lsp.handlers['textDocument/hover'] = function(err, method) + BUFFER = vim.api.nvim_get_current_buf() + lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) + vim.lsp.callbacks['textDocument/typeDefinition'] = function(err, method) vim.lsp._last_lsp_callback = { err = err; method = method } end vim.lsp._unsupported_method = function(method) vim.lsp._last_unsupported_method = method return 'fake-error' end - vim.lsp.buf.hover() + vim.lsp.buf.type_definition() ]=]) end; on_init = function(client) client.stop() local method = exec_lua("return vim.lsp._last_unsupported_method") - eq("textDocument/hover", method) + eq("textDocument/typeDefinition", method) local lsp_cb_call = exec_lua("return vim.lsp._last_lsp_callback") eq("fake-error", lsp_cb_call.err) - eq("textDocument/hover", lsp_cb_call.method) + eq("textDocument/typeDefinition", lsp_cb_call.method) + exec_lua [[ + vim.api.nvim_command(BUFFER.."bwipeout") + ]] + end; + on_exit = function(code, signal) + eq(0, code, "exit code", fake_lsp_logfile) + eq(0, signal, "exit signal", fake_lsp_logfile) + end; + on_callback = function(...) + eq(table.remove(expected_callbacks), {...}, "expected callback") + end; + } + end) + + it('shouldn\'t call unsupported_method when no client and trying to call an unsupported method', function() + local expected_callbacks = { + {NIL, "shutdown", {}, 1}; + } + test_rpc_server { + test_name = "capabilities_for_client_supports_method"; + on_setup = function() + exec_lua([=[ + vim.lsp.callbacks['textDocument/typeDefinition'] = function(err, method) + vim.lsp._last_lsp_callback = { err = err; method = method } + end + vim.lsp._unsupported_method = function(method) + vim.lsp._last_unsupported_method = method + return 'fake-error' + end + vim.lsp.buf.type_definition() + ]=]) + end; + on_init = function(client) + client.stop() + eq(NIL, exec_lua("return vim.lsp._last_unsupported_method")) + eq(NIL, exec_lua("return vim.lsp._last_lsp_callback")) end; on_exit = function(code, signal) eq(0, code, "exit code", fake_lsp_logfile) diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 8e171d31aa..209537831f 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -6,6 +6,7 @@ local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.s local eq, neq = helpers.eq, helpers.neq local write_file = helpers.write_file local command= helpers.command +local exc_exec = helpers.exc_exec describe(':terminal buffer', function() local screen @@ -253,6 +254,10 @@ describe(':terminal buffer', function() ]]) command('bdelete!') end) + + it('handles wqall', function() + eq('Vim(wqall):E948: Job still running', exc_exec('wqall')) + end) end) describe('No heap-buffer-overflow when using', function() diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 77fdba7fc4..b932c58430 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -410,6 +410,7 @@ describe("'scrollback' option", function() command([[let $PROMPT='$$']]) screen = thelpers.screen_setup(nil, "['cmd.exe']", 30) else + command('let $PS1 = "$"') screen = thelpers.screen_setup(nil, "['sh']", 30) end diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 99ebc4971e..65c6fabfa8 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, feed, command = helpers.clear, helpers.feed, helpers.command local iswin = helpers.iswin local funcs = helpers.funcs +local meths = helpers.meths local eq = helpers.eq local eval = helpers.eval local retry = helpers.retry @@ -160,6 +161,7 @@ describe("'wildmenu'", function() if not iswin() then command('set shell=sh') -- Need a predictable "$" prompt. + command('let $PS1 = "$"') end command('set laststatus=0') command('vsplit') @@ -396,6 +398,64 @@ describe("'wildmenu'", function() | ]]) end) + + it('works with c_CTRL_Z standard mapping', function() + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Blue1}; + [2] = {foreground = Screen.colors.Grey0, background = Screen.colors.Yellow}; + [3] = {bold = true, reverse = true}; + } + + -- Wildcharm? where we are going we aint't no need no wildcharm. + eq(0, meths.get_option'wildcharm') + -- Don't mess the defaults yet (neovim is about backwards compatibility) + eq(9, meths.get_option'wildchar') + -- Lol what is cnoremap? Some say it can define mappings. + command 'set wildchar=0' + eq(0, meths.get_option'wildchar') + + command 'cnoremap <f2> <c-z>' + feed(':syntax <f2>') + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {2:case}{3: clear cluster > }| + :syntax case^ | + ]]} + feed '<esc>' + + command 'set wildmode=longest:full,full' + -- this will get cleaner once we have native lua expr mappings: + command [[cnoremap <expr> <tab> luaeval("not rawset(_G, 'coin', not coin).coin") ? "<c-z>" : "c"]] + + feed ':syntax <tab>' + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + :syntax c^ | + ]]} + + feed '<tab>' + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {3:case clear cluster > }| + :syntax c^ | + ]]} + + feed '<tab>' + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + :syntax cc^ | + ]]} + end) end) describe('command line completion', function() diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 356c4997fa..41954de9be 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -603,4 +603,21 @@ describe('path.c', function() eq(FAIL, path_is_absolute('not/in/my/home~/directory')) end) end) + + describe('path_with_extension', function() + local function path_with_extension(filename, extension) + local c_filename = to_cstr(filename) + local c_extension = to_cstr(extension) + return cimp.path_with_extension(c_filename, c_extension) + end + + itp('returns true if filename includes a provided extension', function() + eq(true, path_with_extension('/some/path/file.lua', 'lua')) + end) + + itp('returns false if filename does not include a provided extension', function() + eq(false, path_with_extension('/some/path/file.vim', 'lua')) + eq(false, path_with_extension('/some/path/file', 'lua')) + end) + end) end) |