diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/vim_spec.lua | 45 | ||||
-rw-r--r-- | test/functional/autocmd/dirchanged_spec.lua | 120 | ||||
-rw-r--r-- | test/functional/ex_cmds/source_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 72 |
4 files changed, 241 insertions, 16 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6b644ed519..d8914a3ab7 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -91,6 +91,14 @@ describe('API', function() nvim('exec', 'set nowrap', false) eq('nowrap\n\tLast set from anonymous :source', nvim('exec', 'verbose set wrap?', true)) + + -- Using script var to force creation of a script item + nvim('exec', [[ + let s:a = 1 + set nowrap + ]], false) + eq('nowrap\n\tLast set from anonymous :source (script id 1)', + nvim('exec', 'verbose set wrap?', true)) end) it('multiline input', function() @@ -132,6 +140,43 @@ describe('API', function() -- try no spaces before continuations to catch off-by-one error nvim('exec', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', false) eq({a = 98}, request('nvim_eval', 'g:ab')) + + -- Script scope (s:) + eq('ahoy! script-scoped varrrrr', nvim('exec', [[ + let s:pirate = 'script-scoped varrrrr' + function! s:avast_ye_hades(s) abort + return a:s .. ' ' .. s:pirate + endfunction + echo <sid>avast_ye_hades('ahoy!') + ]], true)) + + eq('ahoy! script-scoped varrrrr', nvim('exec', [[ + let s:pirate = 'script-scoped varrrrr' + function! Avast_ye_hades(s) abort + return a:s .. ' ' .. s:pirate + endfunction + echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1) + ]], true)) + + eq('Vim(call):E5555: API call: Vim(echo):E121: Undefined variable: s:pirate', + pcall_err(request, 'nvim_exec', [[ + let s:pirate = 'script-scoped varrrrr' + call nvim_exec('echo s:pirate', 1) + ]], false)) + + -- Script items are created only on script var access + eq('1\n0', nvim('exec', [[ + echo expand("<SID>")->empty() + let s:a = 123 + echo expand("<SID>")->empty() + ]], true)) + + eq('1\n0', nvim('exec', [[ + echo expand("<SID>")->empty() + function s:a() abort + endfunction + echo expand("<SID>")->empty() + ]], true)) end) it('non-ASCII input', function() diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 6f2da24cf2..f4a1642ebf 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -6,6 +6,7 @@ local command = h.command local eq = h.eq local eval = h.eval local request = h.request +local iswin = h.iswin describe('autocmd DirChanged', function() local curdir = string.gsub(lfs.currentdir(), '\\', '/') @@ -14,6 +15,11 @@ describe('autocmd DirChanged', function() curdir .. '/Xtest-functional-autocmd-dirchanged.dir2', curdir .. '/Xtest-functional-autocmd-dirchanged.dir3', } + local win_dirs = { + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR1', + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR2', + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3', + } setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end) teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end) @@ -27,17 +33,20 @@ describe('autocmd DirChanged', function() command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]]) end) - it('sets v:event', function() + it('sets v:event and <amatch>', function() command('lcd '..dirs[1]) eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('window', eval('g:amatch')) eq(1, eval('g:cdcount')) command('tcd '..dirs[2]) - eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev')) + eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdcount')) command('cd '..dirs[3]) eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + eq('global', eval('g:amatch')) eq(3, eval('g:cdcount')) end) @@ -63,17 +72,6 @@ describe('autocmd DirChanged', function() eq(dirs[3], eval('getcwd()')) end) - it('sets <amatch> to CWD "scope"', function() - command('lcd '..dirs[1]) - eq('window', eval('g:amatch')) - - command('tcd '..dirs[2]) - eq('tab', eval('g:amatch')) - - command('cd '..dirs[3]) - eq('global', eval('g:amatch')) - end) - it('does not trigger if :cd fails', function() command('let g:ev = {}') @@ -106,13 +104,79 @@ describe('autocmd DirChanged', function() command('split '..dirs[1]..'/foo') eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) command('split '..dirs[2]..'/bar') eq({cwd=dirs[2], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) eq(2, eval('g:cdcount')) end) + it('does not trigger if directory has not changed', function() + command('lcd '..dirs[1]) + eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('window', eval('g:amatch')) + eq(1, eval('g:cdcount')) + command('let g:ev = {}') + command('lcd '..dirs[1]) + eq({}, eval('g:ev')) + eq(1, eval('g:cdcount')) + + if iswin() then + command('lcd '..win_dirs[1]) + eq({}, eval('g:ev')) + eq(1, eval('g:cdcount')) + end + + command('tcd '..dirs[2]) + eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) + eq(2, eval('g:cdcount')) + command('let g:ev = {}') + command('tcd '..dirs[2]) + eq({}, eval('g:ev')) + eq(2, eval('g:cdcount')) + + if iswin() then + command('tcd '..win_dirs[2]) + eq({}, eval('g:ev')) + eq(2, eval('g:cdcount')) + end + + command('cd '..dirs[3]) + eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + eq('global', eval('g:amatch')) + eq(3, eval('g:cdcount')) + command('let g:ev = {}') + command('cd '..dirs[3]) + eq({}, eval('g:ev')) + eq(3, eval('g:cdcount')) + + if iswin() then + command('cd '..win_dirs[3]) + eq({}, eval('g:ev')) + eq(3, eval('g:cdcount')) + end + + command('set autochdir') + + command('split '..dirs[1]..'/foo') + eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) + eq(4, eval('g:cdcount')) + command('let g:ev = {}') + command('split '..dirs[1]..'/bar') + eq({}, eval('g:ev')) + eq(4, eval('g:cdcount')) + + if iswin() then + command('split '..win_dirs[1]..'/baz') + eq({}, eval('g:ev')) + eq(4, eval('g:cdcount')) + end + end) + it("is triggered by switching to win/tab with different CWD #6054", function() command('lcd '..dirs[3]) -- window 3 command('split '..dirs[2]..'/foo') -- window 2 @@ -122,6 +186,7 @@ describe('autocmd DirChanged', function() command('2wincmd w') -- window 2 eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + eq('window', eval('g:amatch')) eq(4, eval('g:cdcount')) command('tabnew') -- tab 2 (tab-local CWD) @@ -129,8 +194,10 @@ describe('autocmd DirChanged', function() command('tcd '..dirs[3]) command('tabnext') -- tab 1 (no tab-local CWD) eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + eq('window', eval('g:amatch')) command('tabnext') -- tab 2 - eq({cwd=dirs[3], scope='tab', changed_window=true}, eval('g:ev')) + eq({cwd=dirs[3], scope='tabpage', changed_window=true}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) eq(7, eval('g:cdcount')) command('tabnext') -- tab 1 @@ -138,6 +205,31 @@ describe('autocmd DirChanged', function() eq(9, eval('g:cdcount')) command('tabnext') -- tab 2 (has the *same* CWD) eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + + if iswin() then + command('tabnew') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd '..win_dirs[3]) + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 2 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('lcd '..win_dirs[3]) -- window 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + end end) it('is triggered by nvim_set_current_dir()', function() diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index bdf6ae76d1..fa650d611b 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -25,12 +25,19 @@ describe(':source', function() let b = #{ \ k: "v" "\ (o_o) - \ }]]) + \ } + let c = expand("<SID>")->empty() + let s:s = 0zbeef.cafe + let d = s:s]]) command('source') eq('2', meths.exec('echo a', true)) eq("{'k': 'v'}", meths.exec('echo b', true)) + -- Script items are created only on script var access + eq("1", meths.exec('echo c', true)) + eq("0zBEEFCAFE", meths.exec('echo d', true)) + exec('set cpoptions+=C') eq('Vim(let):E15: Invalid expression: #{', exc_exec('source')) end) @@ -43,7 +50,11 @@ describe(':source', function() let b = #{ "\ (>_<) \ K: "V" - \ }]]) + \ } + function! s:C() abort + return expand("<SID>") .. "C()" + endfunction + let D = {-> s:C()}]]) -- Source the 2nd line only feed('ggjV') @@ -55,6 +66,11 @@ describe(':source', function() feed_command(':source') eq('4', meths.exec('echo a', true)) eq("{'K': 'V'}", meths.exec('echo b', true)) + eq("<SNR>1_C()", meths.exec('echo D()', true)) + + -- 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):E15: Invalid expression: #{', exc_exec("'<,'>source")) diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index a08c8d8681..33469597a1 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -473,6 +473,78 @@ describe('vim.diagnostic', function() end) describe('config()', function() + it('works with global, namespace, and ephemeral options', function() + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = true, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = false, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(0, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, { + virtual_text = {} -- An empty table uses default values + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + end) + it('can use functions for config values', function() exec_lua [[ vim.diagnostic.config({ |