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 ट्रैक के बारे में और ज़्यादा जानकारी के लिए मदद पेज देखिए।