diff src/testdir/test_vim9_disassemble.vim @ 19334:61646c189622 v8.2.0225

patch 8.2.0225: compiling lambda not tested yet Commit: https://github.com/vim/vim/commit/777770fbb0f3c091cbfa22572b953c0723355710 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 6 21:27:08 2020 +0100 patch 8.2.0225: compiling lambda not tested yet Problem: compiling lambda not tested yet. Solution: Add test for lambda and funcref. Drop unused instruction arg.
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Feb 2020 21:30:03 +0100
parents d6e8a9e80be4
children 1cd6eab65ce0
line wrap: on
line diff
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -278,5 +278,52 @@ def Test_compile_const_expr()
   assert_notmatch('JUMP', instr)
 enddef
 
+def WithLambda(): string
+  let F = {a -> "X" .. a .. "X"}
+  return F("x")
+enddef
+
+def Test_compile_lambda()
+  assert_equal("XxX", WithLambda())
+  let instr = execute('disassemble WithLambda')
+  assert_match('WithLambda.*'
+        \ .. 'let F = {a -> "X" .. a .. "X"}.*'
+        \ .. ' FUNCREF <lambda>\d\+.*'
+        \ .. 'PUSHS "x".*'
+        \ .. ' LOAD $0.*'
+        \ .. ' PCALL (argc 1).*'
+        \ .. ' CHECKTYPE string stack\[-1].*'
+        \, instr)
+enddef
+
+def AndOr(arg): string
+  if arg == 1 && arg != 2 || arg == 4
+    return 'yes'
+  endif
+  return 'no'
+enddef
+
+def Test_compile_and_or()
+  assert_equal("yes", AndOr(1))
+  assert_equal("no", AndOr(2))
+  assert_equal("yes", AndOr(4))
+  let instr = execute('disassemble AndOr')
+  assert_match('AndOr.*'
+        \ .. 'if arg == 1 && arg != 2 || arg == 4.*'
+        \ .. '\d LOAD arg\[-1].*'
+        \ .. '\d PUSHNR 1.*'
+        \ .. '\d COMPAREANY ==.*'
+        \ .. '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*'
+        \ .. '\d LOAD arg\[-1].*'
+        \ .. '\d PUSHNR 2.*'
+        \ .. '\d COMPAREANY !=.*'
+        \ .. '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*'
+        \ .. '\d LOAD arg\[-1].*'
+        \ .. '\d PUSHNR 4.*'
+        \ .. '\d COMPAREANY ==.*'
+        \ .. '\d JUMP_IF_FALSE -> \d\+.*'
+        \, instr)
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker