diff options
| author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-03-20 18:08:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-20 18:08:16 -0400 |
| commit | dc8da7ba40feac55d383bfca5fe69d1f63e5abf1 (patch) | |
| tree | 856bec510e9abc97a4ae9a7bf7fc44f66762d5c5 /src/nvim/testdir/script_util.vim | |
| parent | 049213b419b0b5134224be0bcd0ec2e94589c6b0 (diff) | |
| parent | 79575cfe8a191dabb1352f8d75d984a7866d70fd (diff) | |
| download | rneovim-dc8da7ba40feac55d383bfca5fe69d1f63e5abf1.tar.gz rneovim-dc8da7ba40feac55d383bfca5fe69d1f63e5abf1.tar.bz2 rneovim-dc8da7ba40feac55d383bfca5fe69d1f63e5abf1.zip | |
Merge pull request #14060 from andymass/vim-8.2.1703
[RFC] vim-patch:8.2.{1693,1703,1705}
Diffstat (limited to 'src/nvim/testdir/script_util.vim')
| -rw-r--r-- | src/nvim/testdir/script_util.vim | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/nvim/testdir/script_util.vim b/src/nvim/testdir/script_util.vim new file mode 100644 index 0000000000..9913b1dfaf --- /dev/null +++ b/src/nvim/testdir/script_util.vim @@ -0,0 +1,69 @@ +" Functions shared by the tests for Vim Script + +" Commands to track the execution path of a script +com! XpathINIT let g:Xpath = '' +com! -nargs=1 -bar Xpath let g:Xpath ..= <args> +com! XloopINIT let g:Xloop = 1 +com! -nargs=1 -bar Xloop let g:Xpath ..= <args> .. g:Xloop +com! XloopNEXT let g:Xloop += 1 + +" MakeScript() - Make a script file from a function. {{{2 +" +" Create a script that consists of the body of the function a:funcname. +" Replace any ":return" by a ":finish", any argument variable by a global +" variable, and every ":call" by a ":source" for the next following argument +" in the variable argument list. This function is useful if similar tests are +" to be made for a ":return" from a function call or a ":finish" in a script +" file. +func MakeScript(funcname, ...) + let script = tempname() + execute "redir! >" . script + execute "function" a:funcname + redir END + execute "edit" script + " Delete the "function" and the "endfunction" lines. Do not include the + " word "function" in the pattern since it might be translated if LANG is + " set. When MakeScript() is being debugged, this deletes also the debugging + " output of its line 3 and 4. + exec '1,/.*' . a:funcname . '(.*)/d' + /^\d*\s*endfunction\>/,$d + %s/^\d*//e + %s/return/finish/e + %s/\<a:\(\h\w*\)/g:\1/ge + normal gg0 + let cnt = 0 + while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0 + let cnt = cnt + 1 + s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/ + endwhile + g/^\s*$/d + write + bwipeout + return script +endfunc + +" ExecAsScript - Source a temporary script made from a function. {{{2 +" +" Make a temporary script file from the function a:funcname, ":source" it, and +" delete it afterwards. However, if an exception is thrown the file may remain, +" the caller should call DeleteTheScript() afterwards. +let s:script_name = '' +function! ExecAsScript(funcname) + " Make a script from the function passed as argument. + let s:script_name = MakeScript(a:funcname) + + " Source and delete the script. + exec "source" s:script_name + call delete(s:script_name) + let s:script_name = '' +endfunction + +function! DeleteTheScript() + if s:script_name + call delete(s:script_name) + let s:script_name = '' + endif +endfunc + +com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>) + |