Bram Moolenaar | aa23b37 | 2015-09-08 18:46:31 +0200 | [diff] [blame^] | 1 | Tests for the :cdo, :cfdo, :ldo and :lfdo commands |
| 2 | |
| 3 | STARTTEST |
| 4 | :so small.vim |
| 5 | :if !has('quickfix') | e! test.ok | wq! test.out | endif |
| 6 | |
| 7 | :call writefile(["Line1", "Line2", "Line3"], 'Xtestfile1') |
| 8 | :call writefile(["Line1", "Line2", "Line3"], 'Xtestfile2') |
| 9 | :call writefile(["Line1", "Line2", "Line3"], 'Xtestfile3') |
| 10 | |
| 11 | :function RunTests(cchar) |
| 12 | : let nl="\n" |
| 13 | |
| 14 | : enew |
| 15 | : " Try with an empty list |
| 16 | : exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 17 | |
| 18 | : " Populate the list and then try |
| 19 | : exe a:cchar . "getexpr ['non-error 1', 'Xtestfile1:1:3:Line1', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:3:1:Line3']" |
| 20 | : exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 21 | |
| 22 | : " Run command only on selected error lines |
| 23 | : enew |
| 24 | : exe "2,3" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 25 | : " Boundary condition tests |
| 26 | : enew |
| 27 | : exe "1,1" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 28 | : enew |
| 29 | : exe "3" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 30 | : " Range test commands |
| 31 | : enew |
| 32 | : exe "%" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 33 | : enew |
| 34 | : exe "1,$" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 35 | : enew |
| 36 | : exe a:cchar . 'prev' |
| 37 | : exe "." . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 38 | : " Invalid error lines test |
| 39 | : enew |
| 40 | : exe "27" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 41 | : exe "4,5" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 42 | |
| 43 | : " Run commands from an unsaved buffer |
| 44 | : let v:errmsg='' |
| 45 | : enew |
| 46 | : setlocal modified |
| 47 | : exe "2,2" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 48 | : if v:errmsg =~# 'No write since last change' |
| 49 | : let g:result .= 'Unsaved file change test passed' . nl |
| 50 | : else |
| 51 | : let g:result .= 'Unsaved file change test failed' . nl |
| 52 | : endif |
| 53 | |
| 54 | : " If the executed command fails, then the operation should be aborted |
| 55 | : enew! |
| 56 | : let subst_count = 0 |
| 57 | : exe a:cchar . "do s/Line/xLine/ | let subst_count += 1" |
| 58 | : if subst_count == 1 && getline('.') == 'xLine1' |
| 59 | : let g:result .= 'Abort command on error test passed' . nl |
| 60 | : else |
| 61 | : let g:result .= 'Abort command on error test failed' . nl |
| 62 | : endif |
| 63 | |
| 64 | : exe "2,2" . a:cchar . "do! let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 65 | |
| 66 | : " List with no valid error entries |
| 67 | : edit! +2 Xtestfile1 |
| 68 | : exe a:cchar . "getexpr ['non-error 1', 'non-error 2', 'non-error 3']" |
| 69 | : exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 70 | : exe "2" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 71 | : let v:errmsg='' |
| 72 | : exe "%" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 73 | : exe "1,$" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 74 | : exe "." . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 75 | : let g:result .= v:errmsg |
| 76 | |
| 77 | : " List with only one valid entry |
| 78 | : exe a:cchar . "getexpr ['Xtestfile3:3:1:Line3']" |
| 79 | : exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 80 | |
| 81 | : " Tests for :cfdo and :lfdo commands |
| 82 | : exe a:cchar . "getexpr ['non-error 1', 'Xtestfile1:1:3:Line1', 'Xtestfile1:2:1:Line2', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:2:3:Line2', 'Xtestfile3:3:1:Line3']" |
| 83 | : exe a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 84 | : exe "3" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 85 | : exe "2,3" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 86 | : exe "%" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 87 | : exe "1,$" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 88 | : exe a:cchar . 'pfile' |
| 89 | : exe "." . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 90 | |
| 91 | : " List with only one valid entry |
| 92 | : exe a:cchar . "getexpr ['Xtestfile2:2:5:Line2']" |
| 93 | : exe a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" |
| 94 | :endfunction |
| 95 | |
| 96 | :let result='' |
| 97 | :" Tests for the :cdo quickfix list command |
| 98 | :call RunTests('c') |
| 99 | :let result .= "\n" |
| 100 | :" Tests for the :ldo location list command |
| 101 | :call RunTests('l') |
| 102 | |
| 103 | :edit! test.out |
| 104 | :0put =result |
| 105 | :wq! |
| 106 | ENDTEST |
| 107 | |