aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-10-14 00:40:46 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-10-14 12:50:04 +0100
commitda9b0abc67a936021a4ecf7634395db860edcab1 (patch)
treef193d08a729743d2f165a81486df78dfd2b6acce /test
parentd4ed51eb4492d4358eb4ab0c939802f2a5fdc636 (diff)
downloadrneovim-da9b0abc67a936021a4ecf7634395db860edcab1.tar.gz
rneovim-da9b0abc67a936021a4ecf7634395db860edcab1.tar.bz2
rneovim-da9b0abc67a936021a4ecf7634395db860edcab1.zip
feat(:source, nvim_exec): defer script item creation until s:var access
For anonymous scripts, defer the creation of script items until an attempt to access a script-local variable is made. This dramatically reduces the number of script items created when using lots of vim.cmd and nvim_exec especially. This will mean <SID> usage fails until a script-local variable access is first made.
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua22
-rw-r--r--test/functional/ex_cmds/source_spec.lua10
2 files changed, 29 insertions, 3 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index f878a50a26..d8914a3ab7 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -89,6 +89,14 @@ describe('API', function()
it(':verbose set {option}?', 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)
@@ -155,6 +163,20 @@ describe('API', function()
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/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua
index 8077b22e56..fa650d611b 100644
--- a/test/functional/ex_cmds/source_spec.lua
+++ b/test/functional/ex_cmds/source_spec.lua
@@ -26,13 +26,17 @@ describe(':source', function()
\ k: "v"
"\ (o_o)
\ }
+ let c = expand("<SID>")->empty()
let s:s = 0zbeef.cafe
- let c = s:s]])
+ let d = s:s]])
command('source')
eq('2', meths.exec('echo a', true))
eq("{'k': 'v'}", meths.exec('echo b', true))
- eq("0zBEEFCAFE", meths.exec('echo c', 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'))
@@ -62,7 +66,7 @@ describe(':source', function()
feed_command(':source')
eq('4', meths.exec('echo a', true))
eq("{'K': 'V'}", meths.exec('echo b', true))
- eq("<SNR>3_C()", meths.exec('echo D()', true))
+ eq("<SNR>1_C()", meths.exec('echo D()', true))
-- Source last line only
feed_command(':$source')