Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 9342:8ce61744ed94 v7.4.1953
commit https://github.com/vim/vim/commit/049cba9e9760152b5695399a991dc61cea9ba143
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 26 14:38:04 2016 +0200
patch 7.4.1953
Problem: Not all parts of the quickfix code are tested.
Solution: Add more tests. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 26 Jun 2016 14:45:05 +0200 |
parents | 52bda0e40ea2 |
children | e08e8b00fe48 |
comparison
equal
deleted
inserted
replaced
9341:9632879014c1 | 9342:8ce61744ed94 |
---|---|
23 command! -nargs=* Xaddbuffer <mods>caddbuffer <args> | 23 command! -nargs=* Xaddbuffer <mods>caddbuffer <args> |
24 command! -nargs=* Xrewind <mods>crewind <args> | 24 command! -nargs=* Xrewind <mods>crewind <args> |
25 command! -nargs=* -bang Xnext <mods>cnext<bang> <args> | 25 command! -nargs=* -bang Xnext <mods>cnext<bang> <args> |
26 command! -nargs=* Xexpr <mods>cexpr <args> | 26 command! -nargs=* Xexpr <mods>cexpr <args> |
27 command! -nargs=* Xvimgrep <mods>vimgrep <args> | 27 command! -nargs=* Xvimgrep <mods>vimgrep <args> |
28 command! -nargs=* Xgrep <mods> grep <args> | |
29 command! -nargs=* Xgrepadd <mods> grepadd <args> | |
30 command! -nargs=* Xhelpgrep helpgrep <args> | |
28 let g:Xgetlist = function('getqflist') | 31 let g:Xgetlist = function('getqflist') |
29 let g:Xsetlist = function('setqflist') | 32 let g:Xsetlist = function('setqflist') |
30 else | 33 else |
31 command! -nargs=* -bang Xlist <mods>llist<bang> <args> | 34 command! -nargs=* -bang Xlist <mods>llist<bang> <args> |
32 command! -nargs=* Xgetexpr <mods>lgetexpr <args> | 35 command! -nargs=* Xgetexpr <mods>lgetexpr <args> |
43 command! -nargs=* Xaddbuffer <mods>laddbuffer <args> | 46 command! -nargs=* Xaddbuffer <mods>laddbuffer <args> |
44 command! -nargs=* Xrewind <mods>lrewind <args> | 47 command! -nargs=* Xrewind <mods>lrewind <args> |
45 command! -nargs=* -bang Xnext <mods>lnext<bang> <args> | 48 command! -nargs=* -bang Xnext <mods>lnext<bang> <args> |
46 command! -nargs=* Xexpr <mods>lexpr <args> | 49 command! -nargs=* Xexpr <mods>lexpr <args> |
47 command! -nargs=* Xvimgrep <mods>lvimgrep <args> | 50 command! -nargs=* Xvimgrep <mods>lvimgrep <args> |
51 command! -nargs=* Xgrep <mods> lgrep <args> | |
52 command! -nargs=* Xgrepadd <mods> lgrepadd <args> | |
53 command! -nargs=* Xhelpgrep lhelpgrep <args> | |
48 let g:Xgetlist = function('getloclist', [0]) | 54 let g:Xgetlist = function('getloclist', [0]) |
49 let g:Xsetlist = function('setloclist', [0]) | 55 let g:Xsetlist = function('setloclist', [0]) |
50 endif | 56 endif |
51 endfunction | 57 endfunction |
52 | 58 |
226 let l = g:Xgetlist() | 232 let l = g:Xgetlist() |
227 call assert_true(len(l) == 2 && | 233 call assert_true(len(l) == 2 && |
228 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && | 234 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && |
229 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') | 235 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') |
230 | 236 |
237 " Test with a non existent file | |
238 call assert_fails('Xfile non_existent_file', 'E40') | |
239 | |
231 " Run cfile/lfile from a modified buffer | 240 " Run cfile/lfile from a modified buffer |
232 enew! | 241 enew! |
233 silent! put ='Quickfix' | 242 silent! put ='Quickfix' |
234 silent! Xfile Xqftestfile1 | 243 silent! Xfile Xqftestfile1 |
235 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') | 244 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') |
315 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) | 324 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) |
316 call assert_fails('cfile runtest.vim', 'E342:') | 325 call assert_fails('cfile runtest.vim', 'E342:') |
317 | 326 |
318 endfunc | 327 endfunc |
319 | 328 |
329 function! s:test_xhelpgrep(cchar) | |
330 call s:setup_commands(a:cchar) | |
331 Xhelpgrep quickfix | |
332 Xopen | |
333 if a:cchar == 'c' | |
334 let title_text = ':helpgrep quickfix' | |
335 else | |
336 let title_text = ':lhelpgrep quickfix' | |
337 endif | |
338 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title) | |
339 " This wipes out the buffer, make sure that doesn't cause trouble. | |
340 Xclose | |
341 endfunction | |
342 | |
320 function Test_helpgrep() | 343 function Test_helpgrep() |
321 helpgrep quickfix | 344 call s:test_xhelpgrep('c') |
322 copen | 345 call s:test_xhelpgrep('l') |
323 " This wipes out the buffer, make sure that doesn't cause trouble. | |
324 cclose | |
325 endfunc | 346 endfunc |
326 | 347 |
327 func Test_errortitle() | 348 func Test_errortitle() |
328 augroup QfBufWinEnter | 349 augroup QfBufWinEnter |
329 au! | 350 au! |
725 call delete('dir1', 'rf') | 746 call delete('dir1', 'rf') |
726 call delete('dir2', 'rf') | 747 call delete('dir2', 'rf') |
727 call delete('habits1.txt') | 748 call delete('habits1.txt') |
728 endfunction | 749 endfunction |
729 | 750 |
751 " TODO: | |
752 " Add tests for the following formats in 'errorformat' | |
753 " %n %t %r %+ %- %O | |
754 function! Test_efm2() | |
755 let save_efm = &efm | |
756 | |
757 " Test for invalid efm | |
758 set efm=%L%M%N | |
759 call assert_fails('cexpr "abc.txt:1:Hello world"', 'E376:') | |
760 call assert_fails('lexpr "abc.txt:1:Hello world"', 'E376:') | |
761 | |
762 " Test for %s format in efm | |
763 set efm=%f:%s | |
764 cexpr 'Xtestfile:Line search text' | |
765 | |
766 let l = getqflist() | |
767 call assert_equal(l[0].pattern, '^\VLine search text\$') | |
768 call assert_equal(l[0].lnum, 0) | |
769 | |
770 let lines=["[Xtestfile1]", | |
771 \ "(1,17) error: ';' missing", | |
772 \ "(21,2) warning: variable 'z' not defined", | |
773 \ "(67,3) error: end of file found before string ended", | |
774 \ "", | |
775 \ "[Xtestfile2]", | |
776 \ "", | |
777 \ "[Xtestfile3]", | |
778 \ "NEW compiler v1.1", | |
779 \ "(2,2) warning: variable 'x' not defined", | |
780 \ "(67,3) warning: 's' already defined" | |
781 \] | |
782 set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q | |
783 cgetexpr lines | |
784 let l = getqflist() | |
785 call assert_equal(9, len(l)) | |
786 call assert_equal(21, l[2].lnum) | |
787 call assert_equal(2, l[2].col) | |
788 | |
789 let &efm = save_efm | |
790 endfunction | |
791 | |
730 function XquickfixChangedByAutocmd(cchar) | 792 function XquickfixChangedByAutocmd(cchar) |
731 call s:setup_commands(a:cchar) | 793 call s:setup_commands(a:cchar) |
732 if a:cchar == 'c' | 794 if a:cchar == 'c' |
733 let ErrorNr = 'E925' | 795 let ErrorNr = 'E925' |
734 function! ReadFunc() | 796 function! ReadFunc() |
970 endfunction | 1032 endfunction |
971 | 1033 |
972 function XLongLinesTests(cchar) | 1034 function XLongLinesTests(cchar) |
973 let l = g:Xgetlist() | 1035 let l = g:Xgetlist() |
974 | 1036 |
975 call assert_equal(3, len(l)) | 1037 call assert_equal(4, len(l)) |
976 call assert_equal(1, l[0].lnum) | 1038 call assert_equal(1, l[0].lnum) |
977 call assert_equal(1, l[0].col) | 1039 call assert_equal(1, l[0].col) |
978 call assert_equal(4070, len(l[0].text)) | 1040 call assert_equal(1975, len(l[0].text)) |
979 call assert_equal(2, l[1].lnum) | 1041 call assert_equal(2, l[1].lnum) |
980 call assert_equal(1, l[1].col) | 1042 call assert_equal(1, l[1].col) |
981 call assert_equal(4070, len(l[1].text)) | 1043 call assert_equal(4070, len(l[1].text)) |
982 call assert_equal(3, l[2].lnum) | 1044 call assert_equal(3, l[2].lnum) |
983 call assert_equal(1, l[2].col) | 1045 call assert_equal(1, l[2].col) |
984 call assert_equal(10, len(l[2].text)) | 1046 call assert_equal(4070, len(l[2].text)) |
1047 call assert_equal(4, l[3].lnum) | |
1048 call assert_equal(1, l[3].col) | |
1049 call assert_equal(10, len(l[3].text)) | |
985 | 1050 |
986 call g:Xsetlist([], 'r') | 1051 call g:Xsetlist([], 'r') |
987 endfunction | 1052 endfunction |
988 | 1053 |
989 function s:long_lines_tests(cchar) | 1054 function s:long_lines_tests(cchar) |
1011 | 1076 |
1012 function Test_long_lines() | 1077 function Test_long_lines() |
1013 call s:long_lines_tests('c') | 1078 call s:long_lines_tests('c') |
1014 call s:long_lines_tests('l') | 1079 call s:long_lines_tests('l') |
1015 endfunction | 1080 endfunction |
1081 | |
1082 function! s:create_test_file(filename) | |
1083 let l = [] | |
1084 for i in range(1, 20) | |
1085 call add(l, 'Line' . i) | |
1086 endfor | |
1087 call writefile(l, a:filename) | |
1088 endfunction | |
1089 | |
1090 function! Test_switchbuf() | |
1091 call s:create_test_file('Xqftestfile1') | |
1092 call s:create_test_file('Xqftestfile2') | |
1093 call s:create_test_file('Xqftestfile3') | |
1094 | |
1095 new | only | |
1096 edit Xqftestfile1 | |
1097 let file1_winid = win_getid() | |
1098 new Xqftestfile2 | |
1099 let file2_winid = win_getid() | |
1100 cgetexpr ['Xqftestfile1:5:Line5', | |
1101 \ 'Xqftestfile1:6:Line6', | |
1102 \ 'Xqftestfile2:10:Line10', | |
1103 \ 'Xqftestfile2:11:Line11', | |
1104 \ 'Xqftestfile3:15:Line15', | |
1105 \ 'Xqftestfile3:16:Line16'] | |
1106 | |
1107 new | |
1108 let winid = win_getid() | |
1109 cfirst | cnext | |
1110 call assert_equal(winid, win_getid()) | |
1111 cnext | cnext | |
1112 call assert_equal(winid, win_getid()) | |
1113 cnext | cnext | |
1114 call assert_equal(winid, win_getid()) | |
1115 enew | |
1116 | |
1117 set switchbuf=useopen | |
1118 cfirst | cnext | |
1119 call assert_equal(file1_winid, win_getid()) | |
1120 cnext | cnext | |
1121 call assert_equal(file2_winid, win_getid()) | |
1122 cnext | cnext | |
1123 call assert_equal(file2_winid, win_getid()) | |
1124 | |
1125 enew | only | |
1126 set switchbuf=usetab | |
1127 tabedit Xqftestfile1 | |
1128 tabedit Xqftestfile2 | |
1129 tabfirst | |
1130 cfirst | cnext | |
1131 call assert_equal(2, tabpagenr()) | |
1132 cnext | cnext | |
1133 call assert_equal(3, tabpagenr()) | |
1134 cnext | cnext | |
1135 call assert_equal(3, tabpagenr()) | |
1136 tabfirst | tabonly | enew | |
1137 | |
1138 set switchbuf=split | |
1139 cfirst | cnext | |
1140 call assert_equal(1, winnr('$')) | |
1141 cnext | cnext | |
1142 call assert_equal(2, winnr('$')) | |
1143 cnext | cnext | |
1144 call assert_equal(3, winnr('$')) | |
1145 enew | only | |
1146 | |
1147 set switchbuf=newtab | |
1148 cfirst | cnext | |
1149 call assert_equal(1, tabpagenr('$')) | |
1150 cnext | cnext | |
1151 call assert_equal(2, tabpagenr('$')) | |
1152 cnext | cnext | |
1153 call assert_equal(3, tabpagenr('$')) | |
1154 tabfirst | enew | tabonly | only | |
1155 | |
1156 set switchbuf= | |
1157 edit Xqftestfile1 | |
1158 let file1_winid = win_getid() | |
1159 new Xqftestfile2 | |
1160 let file2_winid = win_getid() | |
1161 copen | |
1162 exe "normal 1G\<CR>" | |
1163 call assert_equal(file1_winid, win_getid()) | |
1164 copen | |
1165 exe "normal 3G\<CR>" | |
1166 call assert_equal(file2_winid, win_getid()) | |
1167 copen | only | |
1168 exe "normal 5G\<CR>" | |
1169 call assert_equal(2, winnr('$')) | |
1170 call assert_equal(1, bufwinnr('Xqftestfile3')) | |
1171 | |
1172 enew | only | |
1173 | |
1174 call delete('Xqftestfile1') | |
1175 call delete('Xqftestfile2') | |
1176 call delete('Xqftestfile3') | |
1177 endfunction | |
1178 | |
1179 function! Xadjust_qflnum(cchar) | |
1180 call s:setup_commands(a:cchar) | |
1181 | |
1182 enew | only | |
1183 | |
1184 call s:create_test_file('Xqftestfile') | |
1185 edit Xqftestfile | |
1186 | |
1187 Xgetexpr ['Xqftestfile:5:Line5', | |
1188 \ 'Xqftestfile:10:Line10', | |
1189 \ 'Xqftestfile:15:Line15', | |
1190 \ 'Xqftestfile:20:Line20'] | |
1191 | |
1192 6,14delete | |
1193 call append(6, ['Buffer', 'Window']) | |
1194 | |
1195 let l = g:Xgetlist() | |
1196 | |
1197 call assert_equal(5, l[0].lnum) | |
1198 call assert_equal(6, l[2].lnum) | |
1199 call assert_equal(13, l[3].lnum) | |
1200 | |
1201 enew! | |
1202 call delete('Xqftestfile') | |
1203 endfunction | |
1204 | |
1205 function! Test_adjust_lnum() | |
1206 call Xadjust_qflnum('c') | |
1207 call Xadjust_qflnum('l') | |
1208 endfunction | |
1209 | |
1210 " Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands | |
1211 function! s:test_xgrep(cchar) | |
1212 call s:setup_commands(a:cchar) | |
1213 | |
1214 " The following lines are used for the grep test. Don't remove. | |
1215 " Grep_Test_Text: Match 1 | |
1216 " Grep_Test_Text: Match 2 | |
1217 " GrepAdd_Test_Text: Match 1 | |
1218 " GrepAdd_Test_Text: Match 2 | |
1219 enew! | only | |
1220 set makeef&vim | |
1221 silent Xgrep Grep_Test_Text: test_quickfix.vim | |
1222 call assert_true(len(g:Xgetlist()) == 3) | |
1223 Xopen | |
1224 call assert_true(w:quickfix_title =~ '^:grep') | |
1225 Xclose | |
1226 enew | |
1227 set makeef=Temp_File_## | |
1228 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim | |
1229 call assert_true(len(g:Xgetlist()) == 6) | |
1230 endfunction | |
1231 | |
1232 function! Test_grep() | |
1233 if !has('unix') | |
1234 " The grepprg may not be set on non-Unix systems | |
1235 return | |
1236 endif | |
1237 | |
1238 call s:test_xgrep('c') | |
1239 call s:test_xgrep('l') | |
1240 endfunction |