Testing vim plugin private functions -
i'm creating vim plugin has couple of private functions , i'm trying add unitary testing using vim-vspec.
what best way invoke these private functions in test file?
for now, created public function invokes private one, don't think that's approach because i'm loosing point of having private function. here's of code
" file foo.vim (the plugin) " private function fu! s:foo(arg) ... endfu " public function fu! invokefoo(arg) call <sid>foo(a:arg) endfu
" file foo-unittest.vim (the test file) runtime! plugin/foo.vim describe 'foo function' 'should have behavior' call invokefoo(...) " expectations ... end end
i tried creating maps private functions when call exe map_combination
doesn't have effect on testing buffer.
i found solution question here, , gives 1 approach variables , functions.
variables
for variables, used vim's scopes. calling :help internal-variables:
the scope name can used dictionary. example, delete script-local variables:
:for k in keys(s:) : unlet s:[k] :endfor
so access :s
scope making getter function dictionary:
fun! sscope() return s: endfu
and variable s:variable
accessed by:
let l:scope = sscope() echom l:scope['variable']
functions
the functions bit more complicated due <sid>
string. if read manual you'll get
when executing map command, vim replace
<sid>
special key code , followed number that's unique script, , underscore. example:
:map <sid>add
define mapping "23_add".
so, need access unique number , 1 way define map serve accesor using maparg
inside function:
fu! sid() return maparg('<sid>', 'n') endfu nnoremap <sid> <sid>
then, call function make little hack:
call call(substitute('s:my_function', '^s:', sid(), ''), [arg1, arg2, ...])