了解如何在 Exercism 上测试你的 Vim script 练习
本 track 使用两个工具来运行测试套件,并确保符合最佳实践:
$ 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 track 的更多详细信息,请查看帮助页面。