0
0
mirror of https://github.com/vim/vim.git synced 2025-10-03 05:14:07 -04:00

patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines

Problem:    Vim9 script: cannot use "if has()" to skip lines.
Solution:   Evaluate constant expression at runtime.
This commit is contained in:
Bram Moolenaar
2020-01-31 20:10:50 +01:00
parent 92be6e3f46
commit a259d8d30b
6 changed files with 311 additions and 34 deletions

View File

@@ -368,5 +368,35 @@ def do_something():
EOF
endfunc
def HasEval()
if has('eval')
echo 'yes'
else
echo 'no'
endif
enddef
def HasNothing()
if has('nothing')
echo 'yes'
else
echo 'no'
endif
enddef
def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
call assert_match('PUSHS "yes"', instr)
call assert_notmatch('PUSHS "no"', instr)
call assert_notmatch('JUMP', instr)
assert_equal("\nno", execute('call HasNothing()'))
instr = execute('disassemble HasNothing')
call assert_notmatch('PUSHS "yes"', instr)
call assert_match('PUSHS "no"', instr)
call assert_notmatch('JUMP', instr)
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker