comparison 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
comparison
equal deleted inserted replaced
26537:22dbda400a1d 26538:dfa658800f21
2761 assert_equal(['x', 'x2'], ['x', 'y', 'a', 'x2', 'c']->Filter()) 2761 assert_equal(['x', 'x2'], ['x', 'y', 'a', 'x2', 'c']->Filter())
2762 enddef 2762 enddef
2763 2763
2764 func Test_silent_echo() 2764 func Test_silent_echo()
2765 CheckScreendump 2765 CheckScreendump
2766 2766 call Run_Test_silent_echo()
2767 let lines =<< trim END 2767 endfunc
2768
2769 def Run_Test_silent_echo()
2770 var lines =<< trim END
2768 vim9script 2771 vim9script
2769 def EchoNothing() 2772 def EchoNothing()
2770 silent echo '' 2773 silent echo ''
2771 enddef 2774 enddef
2772 defcompile 2775 defcompile
2773 END 2776 END
2774 call writefile(lines, 'XTest_silent_echo') 2777 writefile(lines, 'XTest_silent_echo')
2775 2778
2776 " Check that the balloon shows up after a mouse move 2779 # Check that the balloon shows up after a mouse move
2777 let buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6}) 2780 var buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
2778 call term_sendkeys(buf, ":abc") 2781 term_sendkeys(buf, ":abc")
2779 call VerifyScreenDump(buf, 'Test_vim9_silent_echo', {}) 2782 VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
2780 2783
2781 " clean up 2784 # clean up
2782 call StopVimInTerminal(buf) 2785 StopVimInTerminal(buf)
2783 call delete('XTest_silent_echo') 2786 delete('XTest_silent_echo')
2784 endfunc 2787 enddef
2785 2788
2786 def SilentlyError() 2789 def SilentlyError()
2787 execute('silent! invalid') 2790 execute('silent! invalid')
2788 g:did_it = 'yes' 2791 g:did_it = 'yes'
2789 enddef 2792 enddef
3163 3166
3164 bwipe! 3167 bwipe!
3165 nunmap <F3> 3168 nunmap <F3>
3166 enddef 3169 enddef
3167 3170
3171 func Test_opfunc_error()
3172 CheckScreendump
3173 call Run_Test_opfunc_error()
3174 endfunc
3175
3176 def Run_Test_opfunc_error()
3177 # test that the error from Opfunc() is displayed right away
3178 var lines =<< trim END
3179 vim9script
3180
3181 def Opfunc(type: string)
3182 try
3183 eval [][0]
3184 catch /nothing/ # error not caught
3185 endtry
3186 enddef
3187 &operatorfunc = Opfunc
3188 nnoremap <expr> l <SID>L()
3189 def L(): string
3190 return 'l'
3191 enddef
3192 'x'->repeat(10)->setline(1)
3193 feedkeys('g@l', 'n')
3194 feedkeys('llll')
3195 END
3196 call writefile(lines, 'XTest_opfunc_error')
3197
3198 var buf = RunVimInTerminal('-S XTest_opfunc_error', {rows: 6, wait_for_ruler: 0})
3199 VerifyScreenDump(buf, 'Test_opfunc_error', {})
3200
3201 # clean up
3202 StopVimInTerminal(buf)
3203 delete('XTest_opfunc_error')
3204 enddef
3205
3168 " this was crashing on exit 3206 " this was crashing on exit
3169 def Test_nested_lambda_in_closure() 3207 def Test_nested_lambda_in_closure()
3170 var lines =<< trim END 3208 var lines =<< trim END
3171 vim9script 3209 vim9script
3172 command WriteDone writefile(['Done'], 'XnestedDone') 3210 command WriteDone writefile(['Done'], 'XnestedDone')