4

I am trying to write tests using Vader plugin but unfortunately, every time I try to invoke a command/function in Execute/Do block it doesn't see seems to work on the text provided in Given block!

# contents of myplugin.vim

function! WrapLastWord(delimiter)
  execute "normal! Bi" . a:delimiter . "\<ESC>ea" . a:delimiter
endfunction

command! -nargs=0 -buffer Bold :call WrapLastWord('*')

Contents of .vader file

Given ('Sample sentence'):
  This is a sample

Do ('bold'):
  A sentence\<ESC>
  :source ../myplugin.vim\<cr>
  :Bold\<CR>

Expect ('Asterisk wrapping around last word'):
  This is a sample *sentence*

I have tried some alternatives like below but none of them seems to be making any change on text provided in Given block?

Execute:
  Bold

And Vader raises failures like below

  - Expected:
      This is a sample *sentence*
  - Got:
      This is a sample sentence

However, if I write the function's instructions in Vader Do block (normal mode Bi*\<esc>ea*) it works as expected and tests passes.

  • Why am I not able to run the same instructions when called from a function/ command written in another file? What am I doing wrong?
  • How do I double check and make sure if Vader is able to source the file and function properly?
  • Is there a better solution to testing vim plugins/scripts?

PS: Any additional help/resource/link to content on automated testing vim plugins would be highly appretiated

1
  • You shouldn't be sourcing your plugin in the Do block, it should be loaded up in the rtp before Vader is run. That will bite you in many ways. Also A isn't a command you can execute, it's a normal mode keystroke. You'll want to use an alternative to get the Execute bit working.
    – Caleb
    Mar 6 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.