0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 8.2.0757: Vim9: no test for MEMBER instruction

Problem:    Vim9: no test for MEMBER instruction.
Solution:   Add a test.  Make matches stricter.
This commit is contained in:
Bram Moolenaar 2020-05-15 19:21:31 +02:00
parent 7e6f3fcc3c
commit 4902ab16cb
2 changed files with 103 additions and 92 deletions

View File

@ -726,18 +726,18 @@ enddef
def Test_disassemble_list_index() def Test_disassemble_list_index()
let instr = execute('disassemble ListIndex') let instr = execute('disassemble ListIndex')
assert_match('ListIndex.*' .. assert_match('ListIndex\_s*' ..
'let l = \[1, 2, 3].*' .. 'let l = \[1, 2, 3]\_s*' ..
'\d PUSHNR 1.*' .. '\d PUSHNR 1\_s*' ..
'\d PUSHNR 2.*' .. '\d PUSHNR 2\_s*' ..
'\d PUSHNR 3.*' .. '\d PUSHNR 3\_s*' ..
'\d NEWLIST size 3.*' .. '\d NEWLIST size 3\_s*' ..
'\d STORE $0.*' .. '\d STORE $0\_s*' ..
'let res = l\[1].*' .. 'let res = l\[1]\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d PUSHNR 1.*' .. '\d PUSHNR 1\_s*' ..
'\d INDEX.*' .. '\d INDEX\_s*' ..
'\d STORE $1.*', '\d STORE $1\_s*',
instr) instr)
assert_equal(2, ListIndex()) assert_equal(2, ListIndex())
enddef enddef
@ -745,21 +745,27 @@ enddef
def DictMember(): number def DictMember(): number
let d = #{item: 1} let d = #{item: 1}
let res = d.item let res = d.item
res = d["item"]
return res return res
enddef enddef
def Test_disassemble_dict_member() def Test_disassemble_dict_member()
let instr = execute('disassemble DictMember') let instr = execute('disassemble DictMember')
assert_match('DictMember.*' .. assert_match('DictMember\_s*' ..
'let d = #{item: 1}.*' .. 'let d = #{item: 1}\_s*' ..
'\d PUSHS "item".*' .. '\d PUSHS "item"\_s*' ..
'\d PUSHNR 1.*' .. '\d PUSHNR 1\_s*' ..
'\d NEWDICT size 1.*' .. '\d NEWDICT size 1\_s*' ..
'\d STORE $0.*' .. '\d STORE $0\_s*' ..
'let res = d.item.*' .. 'let res = d.item\_s*' ..
'\d LOAD $0.*' .. '\d\+ LOAD $0\_s*' ..
'\d MEMBER item.*' .. '\d\+ MEMBER item\_s*' ..
'\d STORE $1.*', '\d\+ STORE $1\_s*' ..
'res = d\["item"\]\_s*' ..
'\d\+ LOAD $0\_s*' ..
'\d\+ PUSHS "item"\_s*' ..
'\d\+ MEMBER\_s*' ..
'\d\+ STORE $1\_s*',
instr) instr)
call assert_equal(1, DictMember()) call assert_equal(1, DictMember())
enddef enddef
@ -773,17 +779,17 @@ enddef
def Test_disassemble_negate_number() def Test_disassemble_negate_number()
let instr = execute('disassemble NegateNumber') let instr = execute('disassemble NegateNumber')
assert_match('NegateNumber.*' .. assert_match('NegateNumber\_s*' ..
'let nr = 9.*' .. 'let nr = 9\_s*' ..
'\d STORE 9 in $0.*' .. '\d STORE 9 in $0\_s*' ..
'let plus = +nr.*' .. 'let plus = +nr\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d CHECKNR.*' .. '\d CHECKNR\_s*' ..
'\d STORE $1.*' .. '\d STORE $1\_s*' ..
'let res = -nr.*' .. 'let res = -nr\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d NEGATENR.*' .. '\d NEGATENR\_s*' ..
'\d STORE $2.*', '\d STORE $2\_s*',
instr) instr)
call assert_equal(-9, NegateNumber()) call assert_equal(-9, NegateNumber())
enddef enddef
@ -797,18 +803,18 @@ enddef
def Test_disassemble_invert_bool() def Test_disassemble_invert_bool()
let instr = execute('disassemble InvertBool') let instr = execute('disassemble InvertBool')
assert_match('InvertBool.*' .. assert_match('InvertBool\_s*' ..
'let flag = true.*' .. 'let flag = true\_s*' ..
'\d PUSH v:true.*' .. '\d PUSH v:true\_s*' ..
'\d STORE $0.*' .. '\d STORE $0\_s*' ..
'let invert = !flag.*' .. 'let invert = !flag\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d INVERT (!val).*' .. '\d INVERT (!val)\_s*' ..
'\d STORE $1.*' .. '\d STORE $1\_s*' ..
'let res = !!flag.*' .. 'let res = !!flag\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d 2BOOL (!!val).*' .. '\d 2BOOL (!!val)\_s*' ..
'\d STORE $2.*', '\d STORE $2\_s*',
instr) instr)
call assert_equal(true, InvertBool()) call assert_equal(true, InvertBool())
enddef enddef
@ -970,26 +976,26 @@ enddef
def Test_disassemble_execute() def Test_disassemble_execute()
let res = execute('disass s:Execute') let res = execute('disass s:Execute')
assert_match('\<SNR>\d*_Execute.*' .. assert_match('\<SNR>\d*_Execute\_s*' ..
"execute 'help vim9.txt'.*" .. "execute 'help vim9.txt'\\_s*" ..
'\d PUSHS "help vim9.txt".*' .. '\d PUSHS "help vim9.txt"\_s*' ..
'\d EXECUTE 1.*' .. '\d EXECUTE 1\_s*' ..
"let cmd = 'help vim9.txt'.*" .. "let cmd = 'help vim9.txt'\\_s*" ..
'\d PUSHS "help vim9.txt".*' .. '\d PUSHS "help vim9.txt"\_s*' ..
'\d STORE $0.*' .. '\d STORE $0\_s*' ..
'execute cmd.*' .. 'execute cmd\_s*' ..
'\d LOAD $0.*' .. '\d LOAD $0\_s*' ..
'\d EXECUTE 1.*' .. '\d EXECUTE 1\_s*' ..
"let tag = 'vim9.txt'.*" .. "let tag = 'vim9.txt'\\_s*" ..
'\d PUSHS "vim9.txt".*' .. '\d PUSHS "vim9.txt"\_s*' ..
'\d STORE $1.*' .. '\d STORE $1\_s*' ..
"execute 'help ' .. tag.*" .. "execute 'help ' .. tag\\_s*" ..
'\d PUSHS "help ".*' .. '\d\+ PUSHS "help "\_s*' ..
'\d LOAD $1.*' .. '\d\+ LOAD $1\_s*' ..
'\d CONCAT.*' .. '\d\+ CONCAT\_s*' ..
'\d EXECUTE 1.*' .. '\d\+ EXECUTE 1\_s*' ..
'\d PUSHNR 0.*' .. '\d\+ PUSHNR 0\_s*' ..
'\d RETURN', '\d\+ RETURN',
res) res)
enddef enddef
@ -1000,15 +1006,15 @@ enddef
def Test_disassemble_echomsg() def Test_disassemble_echomsg()
let res = execute('disass s:Echomsg') let res = execute('disass s:Echomsg')
assert_match('\<SNR>\d*_Echomsg.*' .. assert_match('\<SNR>\d*_Echomsg\_s*' ..
"echomsg 'some' 'message'.*" .. "echomsg 'some' 'message'\\_s*" ..
'\d PUSHS "some".*' .. '\d PUSHS "some"\_s*' ..
'\d PUSHS "message".*' .. '\d PUSHS "message"\_s*' ..
'\d ECHOMSG 2.*' .. '\d ECHOMSG 2\_s*' ..
"echoerr 'went' .. 'wrong'.*" .. "echoerr 'went' .. 'wrong'\\_s*" ..
'\d PUSHS "wentwrong".*' .. '\d PUSHS "wentwrong"\_s*' ..
'\d ECHOERR 1.*' .. '\d ECHOERR 1\_s*' ..
'\d PUSHNR 0.*' .. '\d PUSHNR 0\_s*' ..
'\d RETURN', '\d RETURN',
res) res)
enddef enddef
@ -1027,21 +1033,21 @@ enddef
def Test_display_func() def Test_display_func()
let res1 = execute('function SomeStringArg') let res1 = execute('function SomeStringArg')
assert_match('.* def SomeStringArg(arg: string).*' .. assert_match('.* def SomeStringArg(arg: string)\_s*' ..
' echo arg.*' .. '\d *echo arg.*' ..
' enddef', ' *enddef',
res1) res1)
let res2 = execute('function SomeAnyArg') let res2 = execute('function SomeAnyArg')
assert_match('.* def SomeAnyArg(arg: any).*' .. assert_match('.* def SomeAnyArg(arg: any)\_s*' ..
' echo arg.*' .. '\d *echo arg\_s*' ..
' enddef', ' *enddef',
res2) res2)
let res3 = execute('function SomeStringArgAndReturn') let res3 = execute('function SomeStringArgAndReturn')
assert_match('.* def SomeStringArgAndReturn(arg: string): string.*' .. assert_match('.* def SomeStringArgAndReturn(arg: string): string\_s*' ..
' return arg.*' .. '\d *return arg\_s*' ..
' enddef', ' *enddef',
res3) res3)
enddef enddef
@ -1060,9 +1066,9 @@ def Test_vim9script_forward_func()
source Xdisassemble source Xdisassemble
" check that the first function calls the second with DCALL " check that the first function calls the second with DCALL
assert_match('\<SNR>\d*_FuncOne.*' .. assert_match('\<SNR>\d*_FuncOne\_s*' ..
'return FuncTwo().*' .. 'return FuncTwo()\_s*' ..
'\d DCALL <SNR>\d\+_FuncTwo(argc 0).*' .. '\d DCALL <SNR>\d\+_FuncTwo(argc 0)\_s*' ..
'\d RETURN', '\d RETURN',
g:res_FuncOne) g:res_FuncOne)
@ -1084,20 +1090,23 @@ enddef
def Test_simplify_const_expr() def Test_simplify_const_expr()
let res = execute('disass s:ConcatStrings') let res = execute('disass s:ConcatStrings')
assert_match('\<SNR>\d*_ConcatStrings.*' .. assert_match('<SNR>\d*_ConcatStrings\_s*' ..
'\d PUSHS "onetwothree".*' .. "return 'one' .. 'two' .. 'three'\\_s*" ..
'\d PUSHS "onetwothree"\_s*' ..
'\d RETURN', '\d RETURN',
res) res)
res = execute('disass s:ComputeConst') res = execute('disass s:ComputeConst')
assert_match('\<SNR>\d*_ComputeConst.*' .. assert_match('<SNR>\d*_ComputeConst\_s*' ..
'\d PUSHNR 11.*' .. 'return 2 + 3 \* 4 / 6 + 7\_s*' ..
'\d PUSHNR 11\_s*' ..
'\d RETURN', '\d RETURN',
res) res)
res = execute('disass s:ComputeConstParen') res = execute('disass s:ComputeConstParen')
assert_match('\<SNR>\d*_ComputeConstParen.*' .. assert_match('<SNR>\d*_ComputeConstParen\_s*' ..
'\d PUSHNR 3\>.*' .. 'return ((2 + 4) \* (8 / 2)) / (3 + 4)\_s*' ..
'\d PUSHNR 3\>\_s*' ..
'\d RETURN', '\d RETURN',
res) res)
enddef enddef

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
757,
/**/ /**/
756, 756,
/**/ /**/