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