comparison src/testdir/test_vim9_import.vim @ 28447:6f753a8125f0 v8.2.4748

patch 8.2.4748: cannot use an imported function in a mapping Commit: https://github.com/vim/vim/commit/8944551534b311a2d25acf6e8db235c6d906256c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 14 12:58:23 2022 +0100 patch 8.2.4748: cannot use an imported function in a mapping Problem: Cannot use an imported function in a mapping. Solution: Recognize <SID>name.Func.
author Bram Moolenaar <Bram@vim.org>
date Thu, 14 Apr 2022 14:00:05 +0200
parents 62689b6765d6
children 862068e9e2a7
comparison
equal deleted inserted replaced
28446:224455817fac 28447:6f753a8125f0
640 enddef 640 enddef
641 641
642 def Test_use_import_in_mapping() 642 def Test_use_import_in_mapping()
643 var lines =<< trim END 643 var lines =<< trim END
644 vim9script 644 vim9script
645 export def Funcx() 645 export def Funcx(nr: number)
646 g:result = 42 646 g:result = nr
647 enddef 647 enddef
648 END 648 END
649 writefile(lines, 'XsomeExport.vim') 649 writefile(lines, 'XsomeExport.vim')
650 lines =<< trim END 650 lines =<< trim END
651 vim9script 651 vim9script
652 import './XsomeExport.vim' as some 652 import './XsomeExport.vim' as some
653 var Funcy = some.Funcx 653 var Funcy = some.Funcx
654 nnoremap <F3> :call <sid>Funcy()<cr> 654 nnoremap <F3> :call <sid>Funcy(42)<cr>
655 nnoremap <F4> :call <sid>some.Funcx(44)<cr>
655 END 656 END
656 writefile(lines, 'Xmapscript.vim') 657 writefile(lines, 'Xmapscript.vim')
657 658
658 source Xmapscript.vim 659 source Xmapscript.vim
659 feedkeys("\<F3>", "xt") 660 feedkeys("\<F3>", "xt")
660 assert_equal(42, g:result) 661 assert_equal(42, g:result)
662 feedkeys("\<F4>", "xt")
663 assert_equal(44, g:result)
661 664
662 unlet g:result 665 unlet g:result
663 delete('XsomeExport.vim') 666 delete('XsomeExport.vim')
667 delete('Xmapscript.vim')
668 nunmap <F3>
669 nunmap <F4>
670 enddef
671
672 def Test_use_autoload_import_in_mapping()
673 var lines =<< trim END
674 vim9script
675 export def Func()
676 g:result = 42
677 enddef
678 END
679 writefile(lines, 'XautoloadExport.vim')
680 lines =<< trim END
681 vim9script
682 import autoload './XautoloadExport.vim' as some
683 nnoremap <F3> :call <SID>some.Func()<CR>
684 END
685 writefile(lines, 'Xmapscript.vim')
686
687 source Xmapscript.vim
688 assert_match('\d\+ A: .*XautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
689 feedkeys("\<F3>", "xt")
690 assert_equal(42, g:result)
691
692 unlet g:result
693 delete('XautoloadExport.vim')
664 delete('Xmapscript.vim') 694 delete('Xmapscript.vim')
665 nunmap <F3> 695 nunmap <F3>
666 enddef 696 enddef
667 697
668 def Test_use_import_in_command_completion() 698 def Test_use_import_in_command_completion()