Дізнайтеся, як тестувати вправи з Vim script на Exercism
Цей трек використовує два інструменти, щоб запускати набір тестів і дотримуватися найкращих практик:
$ vim exercise.vim
:source %
:Vader exercise.vader
Шляхи можуть відрізнятися.
Якщо ми хочемо мати зручне скорочення для кроків вище, додаймо це у свій 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()
Після цього відкрийте будь-який файл .vim або .vader з каталогу вправи й виконайте команду :Test.
$ vint .
Щоб дізнатися більше про трек Vim script, перегляньте сторінку довідки.