I recently started learning vimscript and while creating some tests with vader i ran into problems while trying to correctly scope functions locally to my script. The thing is, it gets rather messy when you try to invoke a function which is scoped only to the script (s:FunctionName) so i found a question in stackoverflow which helped me generalize a solution at least for my own purposes.
Please note that this solution was only meant for simple functions that i wanted to unit test, meaning, given a certain input, check the function returns the correct value.
This is an extract from the test suite i wrote for inflector.vim, you can see the whole file here:
" First get the SID for our plugin and define a function that receives the name
" of the private function we want to run as well as the parameter. Note that if
" you require an arbitrary number of arguments you should change the signature of
" the `ExecutePrivateFunc` to account for that `:help function-argument`
" This would be at the top of the vader file inside an Execute block:
let g:sid = matchlist(execute('scriptnames'), '\([0-9]\+\): [^ ]*plugin/inflector.vim')[1]
function! g:ExecutePrivateFunc(function_name, str)
let l:function_name = "<snr>" . g:sid . "_" . a:function_name
let l:PrivateFunction = function(l:function_name)
return PrivateFunction(a:str)
endfunction
" And then call inside other Execute blocks like so:
AssertEqual 'SOME_TEXT', g:ExecutePrivateFunc('Constantize', 'some text')