]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0199: Vim9 script commands not sufficiently tested v8.2.0199
authorBram Moolenaar <Bram@vim.org>
Sun, 2 Feb 2020 16:22:27 +0000 (17:22 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 2 Feb 2020 16:22:27 +0000 (17:22 +0100)
Problem:    Vim9 script commands not sufficiently tested.
Solution:   Add more tests.  Fix script-local function use.

src/testdir/test_vim9_script.vim
src/userfunc.c
src/version.c
src/vim9execute.c

index 749c264d42bca235630f05f4e32c629cd37e9683..ffeec5dbdfaa5bac6c161d8ffe6c5e798d3b17d9 100644 (file)
@@ -106,7 +106,7 @@ def Test_call_ufunc_count()
   Increment()
   " works with and without :call
   assert_equal(4, g:counter)
-  call assert_equal(4, g:counter)
+  assert_equal(4, g:counter)
   unlet g:counter
 enddef
 
@@ -354,7 +354,7 @@ def Test_fixed_size_list()
   l->remove(0)
   l->add(5)
   l->insert(99, 1)
-  call assert_equal([2, 99, 3, 4, 5], l)
+  assert_equal([2, 99, 3, 4, 5], l)
 enddef
 
 " Test that inside :function a Python function can be defined, :def is not
@@ -387,15 +387,52 @@ 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_match('PUSHS "yes"', instr)
+  assert_notmatch('PUSHS "no"', instr)
+  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)
+  assert_notmatch('PUSHS "yes"', instr)
+  assert_match('PUSHS "no"', instr)
+  assert_notmatch('JUMP', instr)
+enddef
+
+func NotCompiled()
+  echo "not"
+endfunc
+
+let s:scriptvar = 4
+let g:globalvar = 'g'
+
+def s:ScriptFunc(arg: string)
+  let local = 1
+  buffers
+  echo arg
+  echo local
+  echo v:version
+  echo s:scriptvar
+  echo g:globalvar
+  echo &tabstop
+  echo $ENVVAR
+  echo @z
+enddef
+
+def Test_disassemble()
+  assert_fails('disass NoFunc', 'E1061:')
+  assert_fails('disass NotCompiled', 'E1062:')
+
+  let res = execute('disass s:ScriptFunc')
+  assert_match('<SNR>\d*_ScriptFunc.*'
+        \ .. 'buffers.*'
+        \ .. ' EXEC \+buffers.*'
+        \ .. ' LOAD arg\[-1\].*'
+        \ .. ' LOAD $0.*'
+        \ .. ' LOADV v:version.*'
+        \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*'
+        \ .. ' LOADG g:globalvar.*'
+        \ .. ' LOADENV $ENVVAR.*'
+        \ .. ' LOADREG @z.*', res)
 enddef
 
 
index bdd838730470efc781107aad9f85bc5114937257..fd4d1ce5b1f1f05a2a612a7174703b9f321ddb4c 100644 (file)
@@ -1060,6 +1060,8 @@ call_user_func(
     if (fp->uf_dfunc_idx >= 0)
     {
        estack_push_ufunc(ETYPE_UFUNC, fp, 1);
+       save_current_sctx = current_sctx;
+       current_sctx = fp->uf_script_ctx;
 
        // Execute the compiled function.
        call_def_function(fp, argcount, argvars, rettv);
@@ -1067,6 +1069,7 @@ call_user_func(
        current_funccal = fc->caller;
 
        estack_pop();
+       current_sctx = save_current_sctx;
        free_funccal(fc);
        return;
     }
index 59db0095ef66d0396ee8d27442a255a5d6c5ea5f..297e74498c6e50e9d2d2dbfdf5a6f4d645645b28 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    199,
 /**/
     198,
 /**/
index 6e003d9389c065002622a23a0a56bbe469d3e601..3d7a2fc44b9da9f0672021f83619955e53115ab9 100644 (file)
@@ -1502,21 +1502,26 @@ failed:
 ex_disassemble(exarg_T *eap)
 {
 #ifdef DISASSEMBLE
-    ufunc_T    *ufunc = find_func(eap->arg, NULL);
+    char_u     *fname;
+    ufunc_T    *ufunc;
     dfunc_T    *dfunc;
     isn_T      *instr;
     int                current;
     int                line_idx = 0;
     int                prev_current = 0;
 
+    fname = trans_function_name(&eap->arg, FALSE,
+            TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF, NULL, NULL);
+    ufunc = find_func(fname, NULL);
+    vim_free(fname);
     if (ufunc == NULL)
     {
-       semsg("Cannot find function %s", eap->arg);
+       semsg("E1061: Cannot find function %s", eap->arg);
        return;
     }
     if (ufunc->uf_dfunc_idx < 0)
     {
-       semsg("Function %s is not compiled", eap->arg);
+       semsg("E1062: Function %s is not compiled", eap->arg);
        return;
     }
     if (ufunc->uf_name_exp != NULL)