neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_codestyle.vim (3069B)


      1 " Test for checking the source code style.
      2 
      3 func s:ReportError(fname, lnum, msg)
      4  if a:lnum > 0
      5    call assert_report(a:fname .. ' line ' .. a:lnum .. ': ' .. a:msg)
      6  endif
      7 endfunc
      8 
      9 func Test_test_files()
     10  for fname in glob('*.vim', 0, 1)
     11    let g:ignoreSwapExists = 'e'
     12    exe 'edit ' .. fname
     13 
     14    " some files intentionally have misplaced white space
     15    if fname =~ 'test_cindent.vim' || fname =~ 'test_join.vim'
     16      continue
     17    endif
     18 
     19    " skip files that are known to have a space before a tab
     20    if fname !~ 'test_comments.vim'
     21          \ && fname !~ 'test_listchars.vim'
     22          \ && fname !~ 'test_visual.vim'
     23      call cursor(1, 1)
     24      let skip = 'getline(".") =~ "codestyle: ignore"'
     25      let lnum = search(fname =~ "test_regexp_latin" ? '[^รก] \t' : ' \t', 'W', 0, 0, skip)
     26      call s:ReportError('testdir/' .. fname, lnum, 'space before Tab')
     27    endif
     28 
     29    " skip files that are known to have trailing white space
     30    if fname !~ 'test_cmdline.vim'
     31          \ && fname !~ 'test_let.vim'
     32          \ && fname !~ 'test_tagjump.vim'
     33          \ && fname !~ 'test_vim9_cmd.vim'
     34      call cursor(1, 1)
     35      let lnum = search(
     36            \ fname =~ 'test_vim9_assign.vim' ? '[^=]\s$'
     37            \ : fname =~ 'test_vim9_class.vim' ? '[^)]\s$'
     38            \ : fname =~ 'test_vim9_script.vim' ? '[^,:3]\s$'
     39            \ : fname =~ 'test_visual.vim' ? '[^/]\s$'
     40            \ : '[^\\]\s$')
     41      call s:ReportError('testdir/' .. fname, lnum, 'trailing white space')
     42    endif
     43  endfor
     44 
     45  bwipe!
     46 endfunc
     47 
     48 func Test_help_files()
     49  set nowrapscan
     50 
     51  for fpath in glob('../../../runtime/doc/*.txt', 0, 1)
     52    let g:ignoreSwapExists = 'e'
     53    exe 'edit ' .. fpath
     54 
     55    let fname = fnamemodify(fpath, ":t")
     56 
     57    " todo.txt is for developers, it's not need a strictly check
     58    " version*.txt is a history and large size, so it's not checked
     59    if fname == 'todo.txt' || fname =~ 'version.*\.txt'
     60      continue
     61    endif
     62 
     63    " Check for mixed tabs and spaces
     64    call cursor(1, 1)
     65    while 1
     66      let lnum = search('[^/] \t')
     67      if fname == 'visual.txt' && getline(lnum) =~ "STRING  \tjkl"
     68            \ || fname == 'usr_27.txt' && getline(lnum) =~ "\[^\? \t\]"
     69        continue
     70      endif
     71      call s:ReportError(fpath, lnum, 'space before tab')
     72      if lnum == 0
     73        break
     74      endif
     75    endwhile
     76 
     77    " Check for unnecessary whitespace at the end of a line
     78    call cursor(1, 1)
     79    while 1
     80      let lnum = search('[^/~\\]\s$')
     81      " skip line that are known to have trailing white space
     82      if fname == 'map.txt' && getline(lnum) =~ "unmap @@ $"
     83            \ || fname == 'usr_12.txt' && getline(lnum) =~ "^\t/ \t$"
     84            \ || fname == 'usr_41.txt' && getline(lnum) =~ "map <F4> o#include  $"
     85            \ || fname == 'change.txt' && getline(lnum) =~ "foobar bla $"
     86        continue
     87      endif
     88      call s:ReportError('testdir' .. fpath, lnum, 'trailing white space')
     89      if lnum == 0
     90        break
     91      endif
     92    endwhile
     93 
     94 
     95  endfor
     96 
     97  set wrapscan&vim
     98  bwipe!
     99 endfunc
    100 
    101 
    102 " vim: shiftwidth=2 sts=2 expandtab