comparison src/testdir/test_normal.vim @ 26618:b531c26f728b v8.2.3838

patch 8.2.3838: cannot use script-local function for setting *func options Commit: https://github.com/vim/vim/commit/db1a410b610b2c1941311acc57dcc4afec20720e Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Dec 17 16:21:20 2021 +0000 patch 8.2.3838: cannot use script-local function for setting *func options Problem: Cannot use script-local function for setting *func options. Solution: Use the script context. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9362)
author Bram Moolenaar <Bram@vim.org>
date Fri, 17 Dec 2021 17:30:04 +0100
parents 255bc9a08e58
children 9c9b8d95b05f
comparison
equal deleted inserted replaced
26617:86ca0d6a6a34 26618:b531c26f728b
573 normal! g@l 573 normal! g@l
574 call assert_equal([23, 'char'], g:OpFunc1Args) 574 call assert_equal([23, 'char'], g:OpFunc1Args)
575 END 575 END
576 call CheckTransLegacySuccess(lines) 576 call CheckTransLegacySuccess(lines)
577 577
578 " Test for using a script-local function name
579 func s:OpFunc3(type)
580 let g:OpFunc3Args = [a:type]
581 endfunc
582 set opfunc=s:OpFunc3
583 let g:OpFunc3Args = []
584 normal! g@l
585 call assert_equal(['char'], g:OpFunc3Args)
586
587 let &opfunc = 's:OpFunc3'
588 let g:OpFunc3Args = []
589 normal! g@l
590 call assert_equal(['char'], g:OpFunc3Args)
591 delfunc s:OpFunc3
592
578 " Using Vim9 lambda expression in legacy context should fail 593 " Using Vim9 lambda expression in legacy context should fail
579 set opfunc=(a)\ =>\ OpFunc1(24,\ a) 594 set opfunc=(a)\ =>\ OpFunc1(24,\ a)
580 let g:OpFunc1Args = [] 595 let g:OpFunc1Args = []
581 call assert_fails('normal! g@l', 'E117:') 596 call assert_fails('normal! g@l', 'E117:')
582 call assert_equal([], g:OpFunc1Args) 597 call assert_equal([], g:OpFunc1Args)
596 611
597 " Vim9 tests 612 " Vim9 tests
598 let lines =<< trim END 613 let lines =<< trim END
599 vim9script 614 vim9script
600 615
601 # Test for using a def function with opfunc
602 def g:Vim9opFunc(val: number, type: string): void 616 def g:Vim9opFunc(val: number, type: string): void
603 g:OpFunc1Args = [val, type] 617 g:OpFunc1Args = [val, type]
604 enddef 618 enddef
619
620 # Test for using a def function with opfunc
605 set opfunc=function('g:Vim9opFunc',\ [60]) 621 set opfunc=function('g:Vim9opFunc',\ [60])
606 g:OpFunc1Args = [] 622 g:OpFunc1Args = []
607 normal! g@l 623 normal! g@l
608 assert_equal([60, 'char'], g:OpFunc1Args) 624 assert_equal([60, 'char'], g:OpFunc1Args)
625
626 # Test for using a global function name
627 &opfunc = g:OpFunc2
628 g:OpFunc2Args = []
629 normal! g@l
630 assert_equal(['char'], g:OpFunc2Args)
631 bw!
632
633 # Test for using a script-local function name
634 def s:LocalOpFunc(type: string): void
635 g:LocalOpFuncArgs = [type]
636 enddef
637 &opfunc = s:LocalOpFunc
638 g:LocalOpFuncArgs = []
639 normal! g@l
640 assert_equal(['char'], g:LocalOpFuncArgs)
641 bw!
609 END 642 END
610 call CheckScriptSuccess(lines) 643 call CheckScriptSuccess(lines)
611 644
612 " cleanup 645 " cleanup
613 set opfunc& 646 set opfunc&