了解如何在 Exercism 上測試你的 Vim script 練習
這個軌道會使用兩個工具來執行測試套件,並確保符合最佳實務:
$ 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 軌道,請參閱說明頁面。