Learn how to test your Vim script exercises on Exercism
This track uses two tools to run the test suite and ensure best practices:
$ vim exercise.vim
:source %
:Vader exercise.vader
Paths may vary.
If you want a convenient shortcut to the above steps, put this in your vimrc:
function! s:exercism_tests()
if expand('%:e') == 'vim'
let testfile = printf('%s/%s.vader', expand('%:p:h'),
\ tr(expand('%:p:h:t'), '-', '_'))
if !filereadable(testfile)
echoerr 'File does not exist: '. testfile
return
endif
source %
execute 'Vader' testfile
else
let sourcefile = printf('%s/%s.vim', expand('%:p:h'),
\ tr(expand('%:p:h:t'), '-', '_'))
if !filereadable(sourcefile)
echoerr 'File does not exist: '. sourcefile
return
endif
execute 'source' sourcefile
Vader
endif
endfunction
autocmd BufRead *.{vader,vim}
\ command! -buffer Test call s:exercism_tests()
Afterwards open any .vim
or .vader
file from an exercise directory and run
the :Test
command.
$ vint .
For more detailed information about the Vim script track, please see the help page.