diff src/testdir/test_vim9_script.vim @ 19253:a8d2d3c8f0b3 v8.2.0185

patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines Commit: https://github.com/vim/vim/commit/a259d8d30bc289764925fc42db1dbe774f0bb3f8 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 31 20:10:50 2020 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 31 Jan 2020 20:15:05 +0100
parents 17d878a2ddaa
children 9fcdeaa18bd1
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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