diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2021-10-17 06:20:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 06:20:35 -0700 |
commit | 30af69509dc91552dc41451857b18907f018c1bd (patch) | |
tree | 7700d6d0b75e59ba40c351c328c3cf151b81e88c /test/functional/api/vim_spec.lua | |
parent | f19dc0608161622f7786eb3cddee27d086cc3ea3 (diff) | |
parent | da9b0abc67a936021a4ecf7634395db860edcab1 (diff) | |
download | rneovim-30af69509dc91552dc41451857b18907f018c1bd.tar.gz rneovim-30af69509dc91552dc41451857b18907f018c1bd.tar.bz2 rneovim-30af69509dc91552dc41451857b18907f018c1bd.zip |
Merge #15994 feat(:source, nvim_exec): script-local scope
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 45 |
1 files changed, 45 insertions, 0 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() |