" Test the :disassemble command, and compilation as a side effect
source check.vim
func NotCompiled()
echo "not"
endfunc
let s:scriptvar = 4
let g:globalvar = 'g'
let b:buffervar = 'b'
let w:windowvar = 'w'
let t:tabpagevar = 't'
def s:ScriptFuncLoad(arg: string)
let local = 1
buffers
echo arg
echo local
echo &lines
echo v:version
echo s:scriptvar
echo g:globalvar
echo b:buffervar
echo w:windowvar
echo t:tabpagevar
echo &tabstop
echo $ENVVAR
echo @z
enddef
def Test_disassemble_load()
assert_fails('disass NoFunc', 'E1061:')
assert_fails('disass NotCompiled', 'E1062:')
assert_fails('disass', 'E471:')
assert_fails('disass [', 'E475:')
assert_fails('disass 234', 'E129:')
assert_fails('disass <XX>foo', 'E129:')
let res = execute('disass s:ScriptFuncLoad')
assert_match('<SNR>\d*_ScriptFuncLoad.*' ..
'buffers.*' ..
' EXEC \+buffers.*' ..
' LOAD arg\[-1\].*' ..
' LOAD $0.*' ..
' LOADOPT &lines.*' ..
' LOADV v:version.*' ..
' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' ..
' LOADG g:globalvar.*' ..
' LOADB b:buffervar.*' ..
' LOADW w:windowvar.*' ..
' LOADT t:tabpagevar.*' ..
' LOADENV $ENVVAR.*' ..
' LOADREG @z.*',
res)
enddef
def s:EditExpand()
let filename = "file"
let filenr = 123
edit the`=filename``=filenr`.txt
enddef
def Test_disassemble_exec_expr()
let res = execute('disass s:EditExpand')
assert_match('<SNR>\d*_EditExpand.*' ..
' let filename = "file".*' ..
'\d PUSHS "file".*' ..
'\d STORE $0.*' ..
' let filenr = 123.*' ..
'\d STORE 123 in $1.*' ..
' edit the`=filename``=filenr`.txt.*' ..
'\d PUSHS "edit the".*' ..
'\d LOAD $0.*' ..
'\d LOAD $1.*' ..
'\d 2STRING stack\[-1\].*' ..
'\d PUSHS ".txt".*' ..
'\d EXECCONCAT 4.*' ..
'\d PUSHNR 0.*' ..
'\d RETURN',
res)
enddef
def s:ScriptFuncPush()
let localbool = true
let localspec = v:none
let localblob = 0z1234
if has('float')
let localfloat = 1.234
endif
enddef
def Test_disassemble_push()
let res = execute('disass s:ScriptFuncPush')
assert_match('<SNR>\d*_ScriptFuncPush.*' ..
'localbool = true.*' ..
' PUSH v:true.*' ..
'localspec = v:none.*' ..
' PUSH v:none.*' ..
'localblob = 0z1234.*' ..
' PUSHBLOB 0z1234.*',
res)
if has('float')
assert_match('<SNR>\d*_ScriptFuncPush.*' ..
'localfloat = 1.234.*' ..
' PUSHF 1.234.*',
res)
endif
enddef
def s:ScriptFuncStore()
let localnr = 1
localnr = 2
let localstr = 'abc'
localstr = 'xyz'
v:char = 'abc'
s:scriptvar = 'sv'
g:globalvar = 'gv'
b:buffervar = 'bv'
w:windowvar = 'wv'
t:tabpagevar = 'tv'
&tabstop = 8
$ENVVAR = 'ev'
@z = 'rv'
enddef
def Test_disassemble_store()
let res = execute('disass s:ScriptFuncStore')
assert_match('<SNR>\d*_ScriptFuncStore.*' ..
'let localnr = 1.*' ..
'localnr = 2.*' ..
' STORE 2 in $0.*' ..
'let localstr = ''abc''.*' ..
'localstr = ''xyz''.*' ..
' STORE $1.*' ..
'v:char = ''abc''.*' ..
'STOREV v:char.*' ..
's:scriptvar = ''sv''.*' ..
' STORES s:scriptvar in .*test_vim9_disassemble.vim.*' ..
'g:globalvar = ''gv''.*' ..
' STOREG g:globalvar.*' ..
'b:buffervar = ''bv''.*' ..
' STOREB b:buffervar.*' ..
'w:windowvar = ''wv''.*' ..
' STOREW w:windowvar.*' ..
't:tabpagevar = ''tv''.*' ..
' STORET t:tabpagevar.*' ..
'&tabstop = 8.*' ..
' STOREOPT &tabstop.*' ..
'$ENVVAR = ''ev''.*' ..
' STOREENV $ENVVAR.*' ..
'@z = ''rv''.*' ..
' STOREREG @z.*',
res)
enddef
def s:ScriptFuncStoreMember()
let locallist: list<number> = []
locallist[