0
0
mirror of https://github.com/vim/vim.git synced 2025-10-02 05:04:20 -04:00

patch 8.2.2222: Vim9: cannot keep script variables when reloading

Problem:    Vim9: cannot keep script variables when reloading.
Solution:   Add the "noclear" argument to :vim9script.
This commit is contained in:
Bram Moolenaar
2020-12-26 15:39:31 +01:00
parent b0ac4ea5e1
commit 2b32700dab
8 changed files with 161 additions and 48 deletions

View File

@@ -1158,6 +1158,53 @@ def Run_Test_import_fails_on_command_line()
StopVimInTerminal(buf)
enddef
def Test_vim9script_reload_noclear()
var lines =<< trim END
vim9script noclear
g:loadCount += 1
var s:reloaded = 'init'
def Again(): string
return 'again'
enddef
if exists('s:loaded') | finish | endif
var s:loaded = true
var s:notReloaded = 'yes'
s:reloaded = 'first'
def g:Values(): list<string>
return [s:reloaded, s:notReloaded, Once()]
enddef
def g:CallAgain(): string
return Again()
enddef
def Once(): string
return 'once'
enddef
END
writefile(lines, 'XReloaded')
g:loadCount = 0
source XReloaded
assert_equal(1, g:loadCount)
assert_equal(['first', 'yes', 'once'], g:Values())
assert_equal('again', g:CallAgain())
source XReloaded
assert_equal(2, g:loadCount)
assert_equal(['init', 'yes', 'once'], g:Values())
assert_fails('call g:CallAgain()', 'E933:')
source XReloaded
assert_equal(3, g:loadCount)
assert_equal(['init', 'yes', 'once'], g:Values())
assert_fails('call g:CallAgain()', 'E933:')
delete('Xreloaded')
delfunc g:Values
delfunc g:CallAgain
unlet g:loadCount
enddef
def Test_vim9script_reload_import()
var lines =<< trim END
vim9script