الاختبار في مسار Vim script

تعرّف على كيفية اختبار تمارين Vim script على Exercism


يستخدم هذا المسار أداتين لتشغيل مجموعة الاختبارات وضمان اتباع أفضل الممارسات:

  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، راجع صفحة المساعدة.