Mercurial > vim
diff 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 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -642,8 +642,8 @@ enddef def Test_use_import_in_mapping() var lines =<< trim END vim9script - export def Funcx() - g:result = 42 + export def Funcx(nr: number) + g:result = nr enddef END writefile(lines, 'XsomeExport.vim') @@ -651,18 +651,48 @@ def Test_use_import_in_mapping() vim9script import './XsomeExport.vim' as some var Funcy = some.Funcx - nnoremap <F3> :call <sid>Funcy()<cr> + nnoremap <F3> :call <sid>Funcy(42)<cr> + nnoremap <F4> :call <sid>some.Funcx(44)<cr> END writefile(lines, 'Xmapscript.vim') source Xmapscript.vim feedkeys("\<F3>", "xt") assert_equal(42, g:result) + feedkeys("\<F4>", "xt") + assert_equal(44, g:result) unlet g:result delete('XsomeExport.vim') delete('Xmapscript.vim') nunmap <F3> + nunmap <F4> +enddef + +def Test_use_autoload_import_in_mapping() + var lines =<< trim END + vim9script + export def Func() + g:result = 42 + enddef + END + writefile(lines, 'XautoloadExport.vim') + lines =<< trim END + vim9script + import autoload './XautoloadExport.vim' as some + nnoremap <F3> :call <SID>some.Func()<CR> + END + writefile(lines, 'Xmapscript.vim') + + source Xmapscript.vim + assert_match('\d\+ A: .*XautoloadExport.vim', execute('scriptnames')->split("\n")[-1]) + feedkeys("\<F3>", "xt") + assert_equal(42, g:result) + + unlet g:result + delete('XautoloadExport.vim') + delete('Xmapscript.vim') + nunmap <F3> enddef def Test_use_import_in_command_completion()