diff src/testdir/test_vim9_func.vim @ 26538:dfa658800f21 v8.2.3798

patch 8.2.3798: a :def callback function postpones an error message Commit: https://github.com/vim/vim/commit/3b309f11db7904efcae0177c2825597042c07427 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 13 18:19:55 2021 +0000 patch 8.2.3798: a :def callback function postpones an error message Problem: A :def callback function postpones an error message. Solution: Display the error after calling the function. (closes https://github.com/vim/vim/issues/9340)
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Dec 2021 19:30:03 +0100
parents 2fbd05a873e3
children 454a1c9ef797
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -2763,25 +2763,28 @@ enddef
 
 func Test_silent_echo()
   CheckScreendump
-
-  let lines =<< trim END
+  call Run_Test_silent_echo()
+endfunc
+
+def Run_Test_silent_echo()
+  var lines =<< trim END
     vim9script
     def EchoNothing()
       silent echo ''
     enddef
     defcompile
   END
-  call writefile(lines, 'XTest_silent_echo')
-
-  " Check that the balloon shows up after a mouse move
-  let buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
-  call term_sendkeys(buf, ":abc")
-  call VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
-
-  " clean up
-  call StopVimInTerminal(buf)
-  call delete('XTest_silent_echo')
-endfunc
+  writefile(lines, 'XTest_silent_echo')
+
+  # Check that the balloon shows up after a mouse move
+  var buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
+  term_sendkeys(buf, ":abc")
+  VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
+
+  # clean up
+  StopVimInTerminal(buf)
+  delete('XTest_silent_echo')
+enddef
 
 def SilentlyError()
   execute('silent! invalid')
@@ -3165,6 +3168,41 @@ def Test_opfunc()
   nunmap <F3>
 enddef
 
+func Test_opfunc_error()
+  CheckScreendump
+  call Run_Test_opfunc_error()
+endfunc
+
+def Run_Test_opfunc_error()
+  # test that the error from Opfunc() is displayed right away
+  var lines =<< trim END
+      vim9script
+
+      def Opfunc(type: string)
+        try
+          eval [][0]
+        catch /nothing/  # error not caught
+        endtry
+      enddef
+      &operatorfunc = Opfunc
+      nnoremap <expr> l <SID>L()
+      def L(): string
+        return 'l'
+      enddef
+      'x'->repeat(10)->setline(1)
+      feedkeys('g@l', 'n')
+      feedkeys('llll')
+  END
+  call writefile(lines, 'XTest_opfunc_error')
+
+  var buf = RunVimInTerminal('-S XTest_opfunc_error', {rows: 6, wait_for_ruler: 0})
+  VerifyScreenDump(buf, 'Test_opfunc_error', {})
+
+  # clean up
+  StopVimInTerminal(buf)
+  delete('XTest_opfunc_error')
+enddef
+
 " this was crashing on exit
 def Test_nested_lambda_in_closure()
   var lines =<< trim END