Vim script 트랙에서 테스트하기

Exercism에서 Vim script 연습 문제를 테스트하는 방법을 알아봐요


이 트랙은 테스트 스위트를 실행하고 모범 사례를 지키기 위해 두 가지 도구를 사용해요:

  1. vader.vim
  2. vint

테스트 실행하기

  1. vader.vim을 설치해요.
  2. 풀이를 열어요:
    $ vim exercise.vim
    
  3. 현재 파일을 소스해서 전역 함수를 Vim에서 사용할 수 있게 해요:
    :source %
    
  4. 테스트를 실행해요:
    :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 명령을 실행해요.

Vim 파일 린트하기

  1. vint를 설치해요.
  2. 모든 Vim 파일을 재귀적으로 린트해요:
    $ vint .
    

Vim script 트랙에 대해 더 자세히 알고 싶다면 도움말 페이지를 참고해요.