I'm using Vimrunner to unit-test a Vim plugin. Everything is working, but I'm looking for a better/canonical way to execute script-local functions. Since they're not directly visible outside the script, I'm currently exposing the script's <SID> and prepending that to my calls in order to run them.
I have to add this code to my plugin to expose the SID:
function! s:SID()
let fullname = expand("<sfile>")
return matchstr(fullname, '<SNR>\d\+_')
endfunction
let g:my_plugin_SID = s:SID()
That will expose the SID as e.g. <SNR>18_. Since Vim functions are all global, and just name-munged, script-local functions can be invoked outside the script by prefixing the SID:
:call <SNR>18_some_function()
Then I do this in a spec:
describe "s:reverse_string" do
let!(:sid) { VIM.command("echo g:my_plugin_SID") }
def reverse_string(string)
VIM.command("echo #{sid}reverse_string('#{string}')")
end
it "does something" do
reverse_string("foo").should == "oof"
end
end
Is there a better way to do this?