آزمایش در مسیر Vim script

بیاموزید چطور تمرین‌های Vim script خود را در Exercism آزمایش کنید.


این مسیر از دو ابزار برای اجرای مجموعه‌ی test و تضمین بهترین شیوه‌ها استفاده می‌کند:

  1. vader.vim
  2. vint

اجرای testها

  1. vader.vim را نصب کنید.
  2. راه‌حل خود را باز کنید:
    $ vim exercise.vim
    
  3. فایل جاری را source کنید تا توابع سراسری آن در Vim در دسترس قرار گیرند:
    :source %
    
  4. testها را اجرا کنید:
    :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، لطفاً صفحه‌ی راهنما را ببینید.