Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 1 | " Test for the quickfix feature. |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 4 | import './vim9.vim' as v9 |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 5 | CheckFeature quickfix |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | e00fdf3 | 2019-09-15 19:09:42 +0200 | [diff] [blame] | 7 | source screendump.vim |
| 8 | |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 9 | set encoding=utf-8 |
| 10 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 11 | func s:setup_commands(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 12 | if a:cchar == 'c' |
| 13 | command! -nargs=* -bang Xlist <mods>clist<bang> <args> |
| 14 | command! -nargs=* Xgetexpr <mods>cgetexpr <args> |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 15 | command! -nargs=* Xaddexpr <mods>caddexpr <args> |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 16 | command! -nargs=* -count Xolder <mods><count>colder <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 17 | command! -nargs=* Xnewer <mods>cnewer <args> |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 18 | command! -nargs=* Xopen <mods> copen <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 19 | command! -nargs=* Xwindow <mods>cwindow <args> |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 20 | command! -nargs=* Xbottom <mods>cbottom <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 21 | command! -nargs=* Xclose <mods>cclose <args> |
| 22 | command! -nargs=* -bang Xfile <mods>cfile<bang> <args> |
| 23 | command! -nargs=* Xgetfile <mods>cgetfile <args> |
| 24 | command! -nargs=* Xaddfile <mods>caddfile <args> |
| 25 | command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args> |
| 26 | command! -nargs=* Xgetbuffer <mods>cgetbuffer <args> |
| 27 | command! -nargs=* Xaddbuffer <mods>caddbuffer <args> |
| 28 | command! -nargs=* Xrewind <mods>crewind <args> |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 29 | command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args> |
| 30 | command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 31 | command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args> |
| 32 | command! -nargs=* -bang Xlast <mods>clast<bang> <args> |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 33 | command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 34 | command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 35 | command! -nargs=* Xexpr <mods>cexpr <args> |
Yegappan Lakshmanan | bb01a1e | 2021-04-26 21:17:52 +0200 | [diff] [blame] | 36 | command! -count=999 -nargs=* Xvimgrep <mods> <count>vimgrep <args> |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 37 | command! -nargs=* Xvimgrepadd <mods> vimgrepadd <args> |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 38 | command! -nargs=* Xgrep <mods> grep <args> |
| 39 | command! -nargs=* Xgrepadd <mods> grepadd <args> |
| 40 | command! -nargs=* Xhelpgrep helpgrep <args> |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 41 | command! -nargs=0 -count Xcc <count>cc |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 42 | command! -count=1 -nargs=0 Xbelow <mods><count>cbelow |
| 43 | command! -count=1 -nargs=0 Xabove <mods><count>cabove |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 44 | command! -count=1 -nargs=0 Xbefore <mods><count>cbefore |
| 45 | command! -count=1 -nargs=0 Xafter <mods><count>cafter |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 46 | let g:Xgetlist = function('getqflist') |
| 47 | let g:Xsetlist = function('setqflist') |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 48 | call setqflist([], 'f') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 49 | else |
| 50 | command! -nargs=* -bang Xlist <mods>llist<bang> <args> |
| 51 | command! -nargs=* Xgetexpr <mods>lgetexpr <args> |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 52 | command! -nargs=* Xaddexpr <mods>laddexpr <args> |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 53 | command! -nargs=* -count Xolder <mods><count>lolder <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 54 | command! -nargs=* Xnewer <mods>lnewer <args> |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 55 | command! -nargs=* Xopen <mods> lopen <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 56 | command! -nargs=* Xwindow <mods>lwindow <args> |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 57 | command! -nargs=* Xbottom <mods>lbottom <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 58 | command! -nargs=* Xclose <mods>lclose <args> |
| 59 | command! -nargs=* -bang Xfile <mods>lfile<bang> <args> |
| 60 | command! -nargs=* Xgetfile <mods>lgetfile <args> |
| 61 | command! -nargs=* Xaddfile <mods>laddfile <args> |
| 62 | command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args> |
| 63 | command! -nargs=* Xgetbuffer <mods>lgetbuffer <args> |
| 64 | command! -nargs=* Xaddbuffer <mods>laddbuffer <args> |
| 65 | command! -nargs=* Xrewind <mods>lrewind <args> |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 66 | command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args> |
| 67 | command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 68 | command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args> |
| 69 | command! -nargs=* -bang Xlast <mods>llast<bang> <args> |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 70 | command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 71 | command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 72 | command! -nargs=* Xexpr <mods>lexpr <args> |
Yegappan Lakshmanan | bb01a1e | 2021-04-26 21:17:52 +0200 | [diff] [blame] | 73 | command! -count=999 -nargs=* Xvimgrep <mods> <count>lvimgrep <args> |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 74 | command! -nargs=* Xvimgrepadd <mods> lvimgrepadd <args> |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 75 | command! -nargs=* Xgrep <mods> lgrep <args> |
| 76 | command! -nargs=* Xgrepadd <mods> lgrepadd <args> |
| 77 | command! -nargs=* Xhelpgrep lhelpgrep <args> |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 78 | command! -nargs=0 -count Xcc <count>ll |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 79 | command! -count=1 -nargs=0 Xbelow <mods><count>lbelow |
| 80 | command! -count=1 -nargs=0 Xabove <mods><count>labove |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 81 | command! -count=1 -nargs=0 Xbefore <mods><count>lbefore |
| 82 | command! -count=1 -nargs=0 Xafter <mods><count>lafter |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 83 | let g:Xgetlist = function('getloclist', [0]) |
| 84 | let g:Xsetlist = function('setloclist', [0]) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 85 | call setloclist(0, [], 'f') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 86 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 87 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 88 | |
Bram Moolenaar | a5d78d1 | 2021-12-15 12:28:22 +0000 | [diff] [blame] | 89 | " This must be run before any error lists are created. |
| 90 | func Test_AA_cc_no_errors() |
| 91 | call assert_fails('cc', 'E42:') |
| 92 | call assert_fails('ll', 'E42:') |
| 93 | endfunc |
| 94 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 95 | " Tests for the :clist and :llist commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 96 | func XlistTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 97 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 98 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 99 | if a:cchar == 'l' |
| 100 | call assert_fails('llist', 'E776:') |
| 101 | endif |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 102 | " With an empty list, command should return error |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 103 | Xgetexpr [] |
| 104 | silent! Xlist |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 105 | call assert_true(v:errmsg ==# 'E42: No Errors') |
| 106 | |
| 107 | " Populate the list and then try |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 108 | let lines =<< trim END |
| 109 | non-error 1 |
| 110 | Xtestfile1:1:3:Line1 |
| 111 | non-error 2 |
| 112 | Xtestfile2:2:2:Line2 |
| 113 | non-error| 3 |
| 114 | Xtestfile3:3:1:Line3 |
| 115 | END |
| 116 | Xgetexpr lines |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 117 | |
| 118 | " List only valid entries |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 119 | let l = split(execute('Xlist', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 120 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 121 | \ ' 4 Xtestfile2:2 col 2: Line2', |
| 122 | \ ' 6 Xtestfile3:3 col 1: Line3'], l) |
| 123 | |
| 124 | " List all the entries |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 125 | let l = split(execute('Xlist!', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 126 | call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', |
| 127 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', |
Bram Moolenaar | 88a3e2b | 2019-12-06 21:11:39 +0100 | [diff] [blame] | 128 | \ ' 5: non-error| 3', ' 6 Xtestfile3:3 col 1: Line3'], l) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 129 | |
| 130 | " List a range of errors |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 131 | let l = split(execute('Xlist 3,6', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 132 | call assert_equal([' 4 Xtestfile2:2 col 2: Line2', |
| 133 | \ ' 6 Xtestfile3:3 col 1: Line3'], l) |
| 134 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 135 | let l = split(execute('Xlist! 3,4', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 136 | call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
| 137 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 138 | let l = split(execute('Xlist -6,-4', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 139 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) |
| 140 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 141 | let l = split(execute('Xlist! -5,-3', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 142 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 143 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 144 | |
| 145 | " Test for '+' |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 146 | let l = split(execute('Xlist! +2', ''), "\n") |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 147 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 148 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 149 | |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 150 | " Ranged entries |
| 151 | call g:Xsetlist([{'lnum':10,'text':'Line1'}, |
| 152 | \ {'lnum':20,'col':10,'text':'Line2'}, |
| 153 | \ {'lnum':30,'col':15,'end_col':20,'text':'Line3'}, |
| 154 | \ {'lnum':40,'end_lnum':45,'text':'Line4'}, |
| 155 | \ {'lnum':50,'end_lnum':55,'col':15,'text':'Line5'}, |
| 156 | \ {'lnum':60,'end_lnum':65,'col':25,'end_col':35,'text':'Line6'}]) |
| 157 | let l = split(execute('Xlist', ""), "\n") |
| 158 | call assert_equal([' 1:10: Line1', |
| 159 | \ ' 2:20 col 10: Line2', |
| 160 | \ ' 3:30 col 15-20: Line3', |
| 161 | \ ' 4:40-45: Line4', |
| 162 | \ ' 5:50-55 col 15: Line5', |
| 163 | \ ' 6:60-65 col 25-35: Line6'], l) |
| 164 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 165 | " Different types of errors |
| 166 | call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11}, |
| 167 | \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22}, |
| 168 | \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33}, |
| 169 | \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44}, |
| 170 | \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}]) |
| 171 | let l = split(execute('Xlist', ""), "\n") |
| 172 | call assert_equal([' 1:10 col 5 warning 11: Warning', |
| 173 | \ ' 2:20 col 10 error 22: Error', |
| 174 | \ ' 3:30 col 15 info 33: Info', |
| 175 | \ ' 4:40 col 20 x 44: Other', |
| 176 | \ ' 5:50 col 25 55: one'], l) |
| 177 | |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 178 | " Test for module names, one needs to explicitly set `'valid':v:true` so |
| 179 | call g:Xsetlist([ |
| 180 | \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true}, |
| 181 | \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true}, |
| 182 | \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}]) |
| 183 | let l = split(execute('Xlist', ""), "\n") |
| 184 | call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning', |
| 185 | \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning', |
| 186 | \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l) |
| 187 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 188 | " For help entries in the quickfix list, only the filename without directory |
| 189 | " should be displayed |
| 190 | Xhelpgrep setqflist() |
| 191 | let l = split(execute('Xlist 1', ''), "\n") |
| 192 | call assert_match('^ 1 [^\\/]\{-}:', l[0]) |
| 193 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 194 | " Error cases |
| 195 | call assert_fails('Xlist abc', 'E488:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 196 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 197 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 198 | func Test_clist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 199 | call XlistTests('c') |
| 200 | call XlistTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 201 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 202 | |
| 203 | " Tests for the :colder, :cnewer, :lolder and :lnewer commands |
| 204 | " Note that this test assumes that a quickfix/location list is |
Bram Moolenaar | cfc0a35 | 2016-01-09 20:23:00 +0100 | [diff] [blame] | 205 | " already set by the caller. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 206 | func XageTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 207 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 208 | |
Bram Moolenaar | 87f59b0 | 2019-04-04 14:04:11 +0200 | [diff] [blame] | 209 | if a:cchar == 'l' |
| 210 | " No location list for the current window |
| 211 | call assert_fails('lolder', 'E776:') |
| 212 | call assert_fails('lnewer', 'E776:') |
| 213 | endif |
| 214 | |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 215 | let list = [{'bufnr': bufnr('%'), 'lnum': 1}] |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 216 | call g:Xsetlist(list) |
| 217 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 218 | " Jumping to a non existent list should return error |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 219 | silent! Xolder 99 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 220 | call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') |
| 221 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 222 | silent! Xnewer 99 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 223 | call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') |
| 224 | |
| 225 | " Add three quickfix/location lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 226 | Xgetexpr ['Xtestfile1:1:3:Line1'] |
| 227 | Xgetexpr ['Xtestfile2:2:2:Line2'] |
| 228 | Xgetexpr ['Xtestfile3:3:1:Line3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 229 | |
| 230 | " Go back two lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 231 | Xolder |
| 232 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 233 | call assert_equal('Line2', l[0].text) |
| 234 | |
| 235 | " Go forward two lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 236 | Xnewer |
| 237 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 238 | call assert_equal('Line3', l[0].text) |
| 239 | |
| 240 | " Test for the optional count argument |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 241 | Xolder 2 |
| 242 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 243 | call assert_equal('Line1', l[0].text) |
| 244 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 245 | Xnewer 2 |
| 246 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 247 | call assert_equal('Line3', l[0].text) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 248 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 249 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 250 | func Test_cage() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 251 | call XageTests('c') |
| 252 | call XageTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 253 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 254 | |
| 255 | " Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen |
| 256 | " commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 257 | func XwindowTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 258 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 259 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 260 | " Opening the location list window without any errors should fail |
| 261 | if a:cchar == 'l' |
| 262 | call assert_fails('lopen', 'E776:') |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 263 | call assert_fails('lwindow', 'E776:') |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 264 | endif |
| 265 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 266 | " Create a list with no valid entries |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 267 | Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 268 | |
| 269 | " Quickfix/Location window should not open with no valid errors |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 270 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 271 | call assert_true(winnr('$') == 1) |
| 272 | |
| 273 | " Create a list with valid entries |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 274 | let lines =<< trim END |
| 275 | Xtestfile1:1:3:Line1 |
| 276 | Xtestfile2:2:2:Line2 |
| 277 | Xtestfile3:3:1:Line3 |
| 278 | END |
| 279 | Xgetexpr lines |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 280 | |
| 281 | " Open the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 282 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 283 | call assert_true(winnr('$') == 2 && winnr() == 2 && |
| 284 | \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 285 | redraw! |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 286 | |
| 287 | " Close the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 288 | Xclose |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 289 | call assert_true(winnr('$') == 1) |
| 290 | |
| 291 | " Create a list with no valid entries |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 292 | Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 293 | |
| 294 | " Open the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 295 | Xopen 5 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 296 | call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' |
Bram Moolenaar | c05d1c0 | 2020-09-04 18:38:06 +0200 | [diff] [blame] | 297 | \ && winheight(0) == 5) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 298 | |
| 299 | " Opening the window again, should move the cursor to that window |
| 300 | wincmd t |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 301 | Xopen 7 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 302 | call assert_true(winnr('$') == 2 && winnr() == 2 && |
Bram Moolenaar | c05d1c0 | 2020-09-04 18:38:06 +0200 | [diff] [blame] | 303 | \ winheight(0) == 7 && |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 304 | \ getline('.') ==# '|| non-error 1') |
| 305 | |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 306 | " :cnext in quickfix window should move to the next entry |
| 307 | Xnext |
| 308 | call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 309 | |
| 310 | " Calling cwindow should close the quickfix window with no valid errors |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 311 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 312 | call assert_true(winnr('$') == 1) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 313 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 314 | " Specifying the width should adjust the width for a vertically split |
| 315 | " quickfix window. |
| 316 | vert Xopen |
| 317 | call assert_equal(10, winwidth(0)) |
| 318 | vert Xopen 12 |
| 319 | call assert_equal(12, winwidth(0)) |
| 320 | Xclose |
| 321 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 322 | " Horizontally or vertically splitting the quickfix window should create a |
| 323 | " normal window/buffer |
| 324 | Xopen |
| 325 | wincmd s |
| 326 | call assert_equal(0, getwininfo(win_getid())[0].quickfix) |
| 327 | call assert_equal(0, getwininfo(win_getid())[0].loclist) |
| 328 | call assert_notequal('quickfix', &buftype) |
| 329 | close |
| 330 | Xopen |
| 331 | wincmd v |
| 332 | call assert_equal(0, getwininfo(win_getid())[0].quickfix) |
| 333 | call assert_equal(0, getwininfo(win_getid())[0].loclist) |
| 334 | call assert_notequal('quickfix', &buftype) |
| 335 | close |
| 336 | Xopen |
| 337 | Xclose |
| 338 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 339 | if a:cchar == 'c' |
| 340 | " Opening the quickfix window in multiple tab pages should reuse the |
| 341 | " quickfix buffer |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 342 | let lines =<< trim END |
| 343 | Xtestfile1:1:3:Line1 |
| 344 | Xtestfile2:2:2:Line2 |
| 345 | Xtestfile3:3:1:Line3 |
| 346 | END |
| 347 | Xgetexpr lines |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 348 | Xopen |
| 349 | let qfbufnum = bufnr('%') |
| 350 | tabnew |
| 351 | Xopen |
| 352 | call assert_equal(qfbufnum, bufnr('%')) |
| 353 | new | only | tabonly |
| 354 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 355 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 356 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 357 | func Test_cwindow() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 358 | call XwindowTests('c') |
| 359 | call XwindowTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 360 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 361 | |
Bram Moolenaar | 36d5022 | 2019-05-02 20:17:40 +0200 | [diff] [blame] | 362 | func Test_copenHeight() |
| 363 | copen |
| 364 | wincmd H |
| 365 | let height = winheight(0) |
| 366 | copen 10 |
| 367 | call assert_equal(height, winheight(0)) |
| 368 | quit |
| 369 | endfunc |
| 370 | |
Bram Moolenaar | 1142a31 | 2019-10-16 14:51:39 +0200 | [diff] [blame] | 371 | func Test_copenHeight_tabline() |
| 372 | set tabline=foo showtabline=2 |
| 373 | copen |
| 374 | wincmd H |
| 375 | let height = winheight(0) |
| 376 | copen 10 |
| 377 | call assert_equal(height, winheight(0)) |
| 378 | quit |
| 379 | set tabline& showtabline& |
| 380 | endfunc |
| 381 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 382 | " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile |
| 383 | " commands. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 384 | func XfileTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 385 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 386 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 387 | let lines =<< trim END |
| 388 | Xtestfile1:700:10:Line 700 |
| 389 | Xtestfile2:800:15:Line 800 |
| 390 | END |
| 391 | call writefile(lines, 'Xqftestfile1') |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 392 | |
| 393 | enew! |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 394 | Xfile Xqftestfile1 |
| 395 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 396 | call assert_true(len(l) == 2 && |
| 397 | \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && |
| 398 | \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') |
| 399 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 400 | " Test with a non existent file |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 401 | call assert_fails('Xfile non_existent_file', 'E40:') |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 402 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 403 | " Run cfile/lfile from a modified buffer |
| 404 | enew! |
| 405 | silent! put ='Quickfix' |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 406 | silent! Xfile Xqftestfile1 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 407 | call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') |
| 408 | |
| 409 | call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 410 | Xaddfile Xqftestfile1 |
| 411 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 412 | call assert_true(len(l) == 3 && |
| 413 | \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') |
| 414 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 415 | let lines =<< trim END |
| 416 | Xtestfile1:222:77:Line 222 |
| 417 | Xtestfile2:333:88:Line 333 |
| 418 | END |
| 419 | call writefile(lines, 'Xqftestfile1') |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 420 | |
| 421 | enew! |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 422 | Xgetfile Xqftestfile1 |
| 423 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 424 | call assert_true(len(l) == 2 && |
| 425 | \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && |
| 426 | \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') |
| 427 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 428 | " Test for a file with a long line and without a newline at the end |
| 429 | let text = repeat('x', 1024) |
| 430 | let t = 'a.txt:18:' . text |
| 431 | call writefile([t], 'Xqftestfile1', 'b') |
| 432 | silent! Xfile Xqftestfile1 |
| 433 | call assert_equal(text, g:Xgetlist()[0].text) |
| 434 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 435 | call delete('Xqftestfile1') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 436 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 437 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 438 | func Test_cfile() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 439 | call XfileTests('c') |
| 440 | call XfileTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 441 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 442 | |
| 443 | " Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and |
| 444 | " :lgetbuffer commands. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 445 | func XbufferTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 446 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 447 | |
| 448 | enew! |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 449 | let lines =<< trim END |
| 450 | Xtestfile7:700:10:Line 700 |
| 451 | Xtestfile8:800:15:Line 800 |
| 452 | END |
| 453 | silent! call setline(1, lines) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 454 | Xbuffer! |
| 455 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 456 | call assert_true(len(l) == 2 && |
| 457 | \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && |
| 458 | \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') |
| 459 | |
| 460 | enew! |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 461 | let lines =<< trim END |
| 462 | Xtestfile9:900:55:Line 900 |
| 463 | Xtestfile10:950:66:Line 950 |
| 464 | END |
| 465 | silent! call setline(1, lines) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 466 | Xgetbuffer |
| 467 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 468 | call assert_true(len(l) == 2 && |
| 469 | \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && |
| 470 | \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') |
| 471 | |
| 472 | enew! |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 473 | let lines =<< trim END |
| 474 | Xtestfile11:700:20:Line 700 |
| 475 | Xtestfile12:750:25:Line 750 |
| 476 | END |
| 477 | silent! call setline(1, lines) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 478 | Xaddbuffer |
| 479 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 480 | call assert_true(len(l) == 4 && |
| 481 | \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && |
| 482 | \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && |
| 483 | \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 484 | enew! |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 485 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 486 | " Check for invalid buffer |
| 487 | call assert_fails('Xbuffer 199', 'E474:') |
| 488 | |
| 489 | " Check for unloaded buffer |
| 490 | edit Xtestfile1 |
| 491 | let bnr = bufnr('%') |
| 492 | enew! |
| 493 | call assert_fails('Xbuffer ' . bnr, 'E681:') |
| 494 | |
| 495 | " Check for invalid range |
| 496 | " Using Xbuffer will not run the range check in the cbuffer/lbuffer |
| 497 | " commands. So directly call the commands. |
| 498 | if (a:cchar == 'c') |
| 499 | call assert_fails('900,999cbuffer', 'E16:') |
| 500 | else |
| 501 | call assert_fails('900,999lbuffer', 'E16:') |
| 502 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 503 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 504 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 505 | func Test_cbuffer() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 506 | call XbufferTests('c') |
| 507 | call XbufferTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 508 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 509 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 510 | func XexprTests(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 511 | call s:setup_commands(a:cchar) |
| 512 | |
| 513 | call assert_fails('Xexpr 10', 'E777:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 514 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 515 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 516 | func Test_cexpr() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 517 | call XexprTests('c') |
| 518 | call XexprTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 519 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 520 | |
| 521 | " Tests for :cnext, :cprev, :cfirst, :clast commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 522 | func Xtest_browse(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 523 | call s:setup_commands(a:cchar) |
| 524 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 525 | call g:Xsetlist([], 'f') |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 526 | " Jumping to first or next location list entry without any error should |
| 527 | " result in failure |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 528 | if a:cchar == 'c' |
| 529 | let err = 'E42:' |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 530 | let cmd = '$cc' |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 531 | else |
| 532 | let err = 'E776:' |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 533 | let cmd = '$ll' |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 534 | endif |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 535 | call assert_fails('Xnext', err) |
| 536 | call assert_fails('Xprev', err) |
| 537 | call assert_fails('Xnfile', err) |
| 538 | call assert_fails('Xpfile', err) |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 539 | call assert_fails(cmd, err) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 540 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 541 | Xexpr '' |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 542 | call assert_fails(cmd, 'E42:') |
| 543 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 544 | call s:create_test_file('Xqftestfile1') |
| 545 | call s:create_test_file('Xqftestfile2') |
| 546 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 547 | let lines =<< trim END |
| 548 | Xqftestfile1:5:Line5 |
| 549 | Xqftestfile1:6:Line6 |
| 550 | Xqftestfile2:10:Line10 |
| 551 | Xqftestfile2:11:Line11 |
| 552 | RegularLine1 |
| 553 | RegularLine2 |
| 554 | END |
| 555 | Xgetexpr lines |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 556 | |
| 557 | Xfirst |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 558 | call assert_fails('-5Xcc', 'E16:') |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 559 | call assert_fails('Xprev', 'E553:') |
| 560 | call assert_fails('Xpfile', 'E553:') |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 561 | Xnfile |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 562 | call assert_equal('Xqftestfile2', @%) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 563 | call assert_equal(10, line('.')) |
| 564 | Xpfile |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 565 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 566 | call assert_equal(6, line('.')) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 567 | 5Xcc |
| 568 | call assert_equal(5, g:Xgetlist({'idx':0}).idx) |
| 569 | 2Xcc |
| 570 | call assert_equal(2, g:Xgetlist({'idx':0}).idx) |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 571 | if a:cchar == 'c' |
| 572 | cc |
| 573 | else |
| 574 | ll |
| 575 | endif |
| 576 | call assert_equal(2, g:Xgetlist({'idx':0}).idx) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 577 | 10Xcc |
| 578 | call assert_equal(6, g:Xgetlist({'idx':0}).idx) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 579 | Xlast |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 580 | Xprev |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 581 | call assert_equal('Xqftestfile2', @%) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 582 | call assert_equal(11, line('.')) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 583 | call assert_fails('Xnext', 'E553:') |
| 584 | call assert_fails('Xnfile', 'E553:') |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 585 | " To process the range using quickfix list entries, directly use the |
| 586 | " quickfix commands (don't use the user defined commands) |
| 587 | if a:cchar == 'c' |
| 588 | $cc |
| 589 | else |
| 590 | $ll |
| 591 | endif |
| 592 | call assert_equal(6, g:Xgetlist({'idx':0}).idx) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 593 | Xrewind |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 594 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 595 | call assert_equal(5, line('.')) |
| 596 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 597 | 10Xnext |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 598 | call assert_equal('Xqftestfile2', @%) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 599 | call assert_equal(11, line('.')) |
| 600 | 10Xprev |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 601 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 602 | call assert_equal(5, line('.')) |
| 603 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 604 | " Jumping to an error from the error window using cc command |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 605 | let lines =<< trim END |
| 606 | Xqftestfile1:5:Line5 |
| 607 | Xqftestfile1:6:Line6 |
| 608 | Xqftestfile2:10:Line10 |
| 609 | Xqftestfile2:11:Line11 |
| 610 | END |
| 611 | Xgetexpr lines |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 612 | Xopen |
| 613 | 10Xcc |
| 614 | call assert_equal(11, line('.')) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 615 | call assert_equal('Xqftestfile2', @%) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 616 | Xopen |
| 617 | call cursor(2, 1) |
| 618 | if a:cchar == 'c' |
| 619 | .cc |
| 620 | else |
| 621 | .ll |
| 622 | endif |
| 623 | call assert_equal(6, line('.')) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 624 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 625 | |
| 626 | " Jumping to an error from the error window (when only the error window is |
| 627 | " present) |
| 628 | Xopen | only |
| 629 | Xlast 1 |
| 630 | call assert_equal(5, line('.')) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 631 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 632 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 633 | Xexpr "" |
| 634 | call assert_fails('Xnext', 'E42:') |
| 635 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 636 | call delete('Xqftestfile1') |
| 637 | call delete('Xqftestfile2') |
Bram Moolenaar | fc2b270 | 2017-09-15 22:43:07 +0200 | [diff] [blame] | 638 | |
| 639 | " Should be able to use next/prev with invalid entries |
| 640 | Xexpr "" |
| 641 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 642 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
Bram Moolenaar | 88a3e2b | 2019-12-06 21:11:39 +0100 | [diff] [blame] | 643 | Xaddexpr ['foo', 'bar', 'baz', 'quux', 'sh|moo'] |
Bram Moolenaar | fc2b270 | 2017-09-15 22:43:07 +0200 | [diff] [blame] | 644 | call assert_equal(5, g:Xgetlist({'size' : 0}).size) |
| 645 | Xlast |
| 646 | call assert_equal(5, g:Xgetlist({'idx' : 0}).idx) |
| 647 | Xfirst |
| 648 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 649 | 2Xnext |
| 650 | call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 651 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 652 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 653 | func Test_browse() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 654 | call Xtest_browse('c') |
| 655 | call Xtest_browse('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 656 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 657 | |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 658 | " Test for memory allocation failures |
| 659 | func Xnomem_tests(cchar) |
| 660 | call s:setup_commands(a:cchar) |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 661 | |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 662 | call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) |
| 663 | call assert_fails('Xvimgrep vim runtest.vim', 'E342:') |
| 664 | |
| 665 | call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) |
| 666 | call assert_fails('Xvimgrep vim runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 667 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 668 | call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 669 | call assert_fails('Xfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 670 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 671 | call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0) |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 672 | call assert_fails('Xfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 673 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 674 | call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 675 | call assert_fails('Xfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 676 | |
Yegappan Lakshmanan | 5a2d4a3 | 2022-02-26 10:31:32 +0000 | [diff] [blame] | 677 | call test_alloc_fail(GetAllocId('qf_efm_fmtstr'), 0, 0) |
| 678 | set efm=%f |
| 679 | call assert_fails('Xexpr ["Xfile1"]', 'E342:') |
| 680 | set efm& |
| 681 | |
| 682 | call test_alloc_fail(GetAllocId('qf_efm_fmtpart'), 0, 0) |
| 683 | set efm=%f:%l:%m,%f-%l-%m |
| 684 | call assert_fails('Xaddexpr ["Xfile2", "Xfile3"]', 'E342:') |
| 685 | set efm& |
| 686 | |
| 687 | call test_alloc_fail(GetAllocId('qf_title'), 0, 0) |
| 688 | call assert_fails('Xexpr ""', 'E342:') |
| 689 | call assert_equal('', g:Xgetlist({'all': 1}).title) |
| 690 | |
| 691 | call test_alloc_fail(GetAllocId('qf_mef_name'), 0, 0) |
| 692 | set makeef=Xtmp##.err |
| 693 | call assert_fails('Xgrep needle haystack', 'E342:') |
| 694 | set makeef& |
| 695 | |
| 696 | call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) |
| 697 | call assert_fails('Xexpr "Xfile1:10:Line10"', 'E342:') |
| 698 | |
| 699 | if a:cchar == 'l' |
| 700 | for id in ['qf_qfline', 'qf_qfinfo'] |
| 701 | lgetexpr ["Xfile1:10:L10", "Xfile2:20:L20"] |
| 702 | call test_alloc_fail(GetAllocId(id), 0, 0) |
| 703 | call assert_fails('new', 'E342:') |
| 704 | call assert_equal(2, winnr('$')) |
| 705 | call assert_equal([], getloclist(0)) |
| 706 | %bw! |
| 707 | endfor |
| 708 | endif |
| 709 | |
| 710 | call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) |
| 711 | try |
| 712 | call assert_fails('Xvimgrep vim runtest.vim', 'E342:') |
| 713 | catch /^Vim:Interrupt$/ |
| 714 | endtry |
| 715 | |
| 716 | call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) |
| 717 | try |
| 718 | call assert_fails('Xvimgrep /vim/f runtest.vim', 'E342:') |
| 719 | catch /^Vim:Interrupt$/ |
| 720 | endtry |
| 721 | |
| 722 | let l = getqflist({"lines": ["Xfile1:10:L10"]}) |
| 723 | call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) |
| 724 | call assert_fails('call g:Xsetlist(l.items)', 'E342:') |
| 725 | |
| 726 | call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) |
| 727 | try |
| 728 | call assert_fails('Xhelpgrep quickfix', 'E342:') |
| 729 | catch /^Vim:Interrupt$/ |
| 730 | endtry |
| 731 | |
| 732 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 733 | call assert_fails('let l = g:Xgetlist({"lines": ["Xfile1:10:L10"]})', 'E342:') |
| 734 | call assert_equal(#{items: []}, l) |
| 735 | |
| 736 | if a:cchar == 'l' |
| 737 | call setqflist([], 'f') |
| 738 | call setloclist(0, [], 'f') |
| 739 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 740 | call assert_fails('lhelpgrep quickfix', 'E342:') |
| 741 | call assert_equal([], getloclist(0)) |
| 742 | |
| 743 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 744 | call assert_fails('lvimgrep vim runtest.vim', 'E342:') |
| 745 | |
| 746 | let l = getqflist({"lines": ["Xfile1:10:L10"]}) |
| 747 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 748 | call assert_fails('call setloclist(0, l.items)', 'E342:') |
| 749 | |
| 750 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 751 | call assert_fails('lbuffer', 'E342:') |
| 752 | |
| 753 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 754 | call assert_fails('lexpr ["Xfile1:10:L10", "Xfile2:20:L20"]', 'E342:') |
| 755 | |
| 756 | call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) |
| 757 | call assert_fails('lfile runtest.vim', 'E342:') |
| 758 | endif |
| 759 | |
| 760 | call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0) |
| 761 | set efm=%DEntering\ dir\ %f,%f:%l:%m |
| 762 | call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E342:') |
| 763 | set efm& |
| 764 | |
| 765 | call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0) |
| 766 | set efm=%+P[%f],(%l)%m |
| 767 | call assert_fails('Xexpr ["[runtest.vim]", "(1)Hello"]', 'E342:') |
| 768 | set efm& |
| 769 | |
| 770 | call test_alloc_fail(GetAllocId('qf_multiline_pfx'), 0, 0) |
| 771 | set efm=%EError,%Cline\ %l,%Z%m |
| 772 | call assert_fails('Xexpr ["Error", "line 1", "msg"]', 'E342:') |
| 773 | set efm& |
| 774 | |
| 775 | call test_alloc_fail(GetAllocId('qf_makecmd'), 0, 0) |
| 776 | call assert_fails('Xgrep vim runtest.vim', 'E342:') |
| 777 | |
| 778 | call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) |
| 779 | call assert_fails('Xexpr repeat("a", 8192)', 'E342:') |
| 780 | |
| 781 | call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) |
| 782 | call assert_fails('Xexpr [repeat("a", 8192)]', 'E342:') |
| 783 | |
| 784 | new |
| 785 | call setline(1, repeat('a', 8192)) |
| 786 | call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) |
| 787 | call assert_fails('Xbuffer', 'E342:') |
| 788 | %bw! |
| 789 | |
| 790 | call writefile([repeat('a', 8192)], 'Xtest') |
| 791 | call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) |
| 792 | call assert_fails('Xfile Xtest', 'E342:') |
| 793 | call delete('Xtest') |
| 794 | endfunc |
| 795 | |
| 796 | func Test_nomem() |
| 797 | call Xnomem_tests('c') |
| 798 | call Xnomem_tests('l') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 799 | endfunc |
| 800 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 801 | func s:test_xhelpgrep(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 802 | call s:setup_commands(a:cchar) |
| 803 | Xhelpgrep quickfix |
| 804 | Xopen |
| 805 | if a:cchar == 'c' |
| 806 | let title_text = ':helpgrep quickfix' |
| 807 | else |
| 808 | let title_text = ':lhelpgrep quickfix' |
| 809 | endif |
| 810 | call assert_true(w:quickfix_title =~ title_text, w:quickfix_title) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 811 | |
| 812 | " Jumping to a help topic should open the help window |
| 813 | only |
| 814 | Xnext |
| 815 | call assert_true(&buftype == 'help') |
| 816 | call assert_true(winnr('$') == 2) |
| 817 | " Jumping to the next match should reuse the help window |
| 818 | Xnext |
| 819 | call assert_true(&buftype == 'help') |
| 820 | call assert_true(winnr() == 1) |
| 821 | call assert_true(winnr('$') == 2) |
| 822 | " Jumping to the next match from the quickfix window should reuse the help |
| 823 | " window |
| 824 | Xopen |
| 825 | Xnext |
| 826 | call assert_true(&buftype == 'help') |
| 827 | call assert_true(winnr() == 1) |
| 828 | call assert_true(winnr('$') == 2) |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 829 | call assert_match('|\d\+ col \d\+-\d\+|', getbufline(winbufnr(2), 1)[0]) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 830 | |
Bram Moolenaar | 62ef797 | 2016-01-19 14:51:54 +0100 | [diff] [blame] | 831 | " This wipes out the buffer, make sure that doesn't cause trouble. |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 832 | Xclose |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 833 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 834 | " When the current window is vertically split, jumping to a help match |
| 835 | " should open the help window at the top. |
| 836 | only | enew |
| 837 | let w1 = win_getid() |
| 838 | vert new |
| 839 | let w2 = win_getid() |
| 840 | Xnext |
| 841 | let w3 = win_getid() |
| 842 | call assert_true(&buftype == 'help') |
| 843 | call assert_true(winnr() == 1) |
Bram Moolenaar | a106e6c | 2019-11-24 22:13:58 +0100 | [diff] [blame] | 844 | " See jump_to_help_window() for details |
| 845 | let w2_width = winwidth(w2) |
| 846 | if w2_width != &columns && w2_width < 80 |
| 847 | call assert_equal(['col', [['leaf', w3], |
| 848 | \ ['row', [['leaf', w2], ['leaf', w1]]]]], winlayout()) |
| 849 | else |
| 850 | call assert_equal(['row', [['col', [['leaf', w3], ['leaf', w2]]], |
| 851 | \ ['leaf', w1]]] , winlayout()) |
| 852 | endif |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 853 | |
| 854 | new | only |
| 855 | set buftype=help |
| 856 | set modified |
| 857 | call assert_fails('Xnext', 'E37:') |
| 858 | set nomodified |
| 859 | new | only |
| 860 | |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 861 | if a:cchar == 'l' |
| 862 | " When a help window is present, running :lhelpgrep should reuse the |
| 863 | " help window and not the current window |
| 864 | new | only |
| 865 | call g:Xsetlist([], 'f') |
| 866 | help index.txt |
| 867 | wincmd w |
| 868 | lhelpgrep quickfix |
| 869 | call assert_equal(1, winnr()) |
| 870 | call assert_notequal([], getloclist(1)) |
| 871 | call assert_equal([], getloclist(2)) |
| 872 | endif |
| 873 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 874 | new | only |
| 875 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 876 | " Search for non existing help string |
| 877 | call assert_fails('Xhelpgrep a1b2c3', 'E480:') |
Bram Moolenaar | 108e7b4 | 2018-10-11 17:39:12 +0200 | [diff] [blame] | 878 | " Invalid regular expression |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 879 | call assert_fails('Xhelpgrep \@<!', 'E866:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 880 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 881 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 882 | func Test_helpgrep() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 883 | call s:test_xhelpgrep('c') |
Bram Moolenaar | cf25fdb | 2016-08-03 21:04:53 +0200 | [diff] [blame] | 884 | helpclose |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 885 | call s:test_xhelpgrep('l') |
Bram Moolenaar | 62ef797 | 2016-01-19 14:51:54 +0100 | [diff] [blame] | 886 | endfunc |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 887 | |
Bram Moolenaar | e5a2dc8 | 2021-01-03 19:52:05 +0100 | [diff] [blame] | 888 | def Test_helpgrep_vim9_restore_cpo() |
| 889 | assert_equal('aABceFs', &cpo) |
| 890 | |
| 891 | var rtp_save = &rtp |
| 892 | var dir = 'Xruntime/after' |
| 893 | &rtp ..= ',' .. dir |
| 894 | mkdir(dir .. '/ftplugin', 'p') |
Bram Moolenaar | 39f3b14 | 2021-02-14 12:57:36 +0100 | [diff] [blame] | 895 | writefile(['vim9script'], dir .. '/ftplugin/qf.vim') |
Bram Moolenaar | e5a2dc8 | 2021-01-03 19:52:05 +0100 | [diff] [blame] | 896 | filetype plugin on |
| 897 | silent helpgrep grail |
| 898 | cwindow |
| 899 | silent helpgrep grail |
| 900 | |
| 901 | assert_equal('aABceFs', &cpo) |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 902 | delete('Xruntime', 'rf') |
Bram Moolenaar | e5a2dc8 | 2021-01-03 19:52:05 +0100 | [diff] [blame] | 903 | &rtp = rtp_save |
| 904 | cclose |
| 905 | helpclose |
| 906 | enddef |
| 907 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 908 | " When running the :helpgrep command, if an autocmd modifies the 'cpoptions' |
| 909 | " value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453) |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 910 | func Test_helpgrep_restore_cpo_aucmd() |
| 911 | let save_cpo = &cpo |
| 912 | augroup QF_Test |
| 913 | au! |
| 914 | autocmd BufNew * set cpo=acd |
| 915 | augroup END |
| 916 | |
| 917 | helpgrep quickfix |
| 918 | call assert_equal('acd', &cpo) |
| 919 | %bw! |
| 920 | |
| 921 | set cpo&vim |
| 922 | augroup QF_Test |
| 923 | au! |
| 924 | autocmd BufReadPost * set cpo= |
| 925 | augroup END |
| 926 | |
| 927 | helpgrep buffer |
| 928 | call assert_equal('', &cpo) |
| 929 | |
| 930 | augroup QF_Test |
| 931 | au! |
| 932 | augroup END |
| 933 | %bw! |
| 934 | let &cpo = save_cpo |
| 935 | endfunc |
| 936 | |
Bram Moolenaar | 5f7d4c0 | 2021-05-05 21:31:39 +0200 | [diff] [blame] | 937 | def Test_vim9_cexpr() |
| 938 | var text = 'somefile:95:error' |
| 939 | cexpr text |
| 940 | var l = getqflist() |
| 941 | assert_equal(1, l->len()) |
| 942 | assert_equal(95, l[0].lnum) |
| 943 | assert_equal('error', l[0].text) |
| 944 | |
| 945 | text = 'somefile:77:warning' |
| 946 | caddexpr text |
| 947 | l = getqflist() |
| 948 | assert_equal(2, l->len()) |
| 949 | assert_equal(77, l[1].lnum) |
| 950 | assert_equal('warning', l[1].text) |
| 951 | enddef |
| 952 | |
Bram Moolenaar | 6920c72 | 2016-01-22 22:44:10 +0100 | [diff] [blame] | 953 | func Test_errortitle() |
| 954 | augroup QfBufWinEnter |
| 955 | au! |
| 956 | au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') |
| 957 | augroup END |
| 958 | copen |
| 959 | let a=[{'lnum': 308, 'bufnr': bufnr(''), 'col': 58, 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'pattern': '', 'text': ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')'}] |
| 960 | call setqflist(a) |
| 961 | call assert_equal(':setqflist()', g:a) |
| 962 | augroup QfBufWinEnter |
| 963 | au! |
| 964 | augroup END |
| 965 | augroup! QfBufWinEnter |
| 966 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 967 | |
Bram Moolenaar | 5584df6 | 2016-03-18 21:00:51 +0100 | [diff] [blame] | 968 | func Test_vimgreptitle() |
| 969 | augroup QfBufWinEnter |
| 970 | au! |
| 971 | au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') |
| 972 | augroup END |
| 973 | try |
| 974 | vimgrep /pattern/j file |
| 975 | catch /E480/ |
| 976 | endtry |
| 977 | copen |
| 978 | call assert_equal(': vimgrep /pattern/j file', g:a) |
| 979 | augroup QfBufWinEnter |
| 980 | au! |
| 981 | augroup END |
| 982 | augroup! QfBufWinEnter |
| 983 | endfunc |
| 984 | |
Bram Moolenaar | 1d30fde | 2021-10-20 21:58:42 +0100 | [diff] [blame] | 985 | func Test_bufwinenter_once() |
| 986 | augroup QfBufWinEnter |
| 987 | au! |
| 988 | au BufWinEnter * let g:got_afile ..= 'got ' .. expand('<afile>') |
| 989 | augroup END |
| 990 | let g:got_afile = '' |
| 991 | copen |
| 992 | call assert_equal('got quickfix', g:got_afile) |
| 993 | |
| 994 | cclose |
| 995 | unlet g:got_afile |
| 996 | augroup QfBufWinEnter |
| 997 | au! |
| 998 | augroup END |
| 999 | augroup! QfBufWinEnter |
| 1000 | endfunc |
| 1001 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1002 | func XqfTitleTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1003 | call s:setup_commands(a:cchar) |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1004 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1005 | Xgetexpr ['file:1:1:message'] |
| 1006 | let l = g:Xgetlist() |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1007 | if a:cchar == 'c' |
| 1008 | call setqflist(l, 'r') |
| 1009 | else |
| 1010 | call setloclist(0, l, 'r') |
| 1011 | endif |
| 1012 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1013 | Xopen |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1014 | if a:cchar == 'c' |
| 1015 | let title = ':setqflist()' |
| 1016 | else |
| 1017 | let title = ':setloclist()' |
| 1018 | endif |
| 1019 | call assert_equal(title, w:quickfix_title) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1020 | Xclose |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1021 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1022 | |
| 1023 | " Tests for quickfix window's title |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1024 | func Test_qf_title() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1025 | call XqfTitleTests('c') |
| 1026 | call XqfTitleTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1027 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1028 | |
| 1029 | " Tests for 'errorformat' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1030 | func Test_efm() |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 1031 | let save_efm = &efm |
| 1032 | set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# |
| 1033 | cgetexpr ['WWWW', 'EEEE', 'CCCC'] |
| 1034 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 1035 | call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) |
| 1036 | cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] |
| 1037 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 1038 | call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) |
| 1039 | cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] |
| 1040 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 1041 | call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l) |
| 1042 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1043 | endfunc |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1044 | |
| 1045 | " This will test for problems in quickfix: |
| 1046 | " A. incorrectly copying location lists which caused the location list to show |
| 1047 | " a different name than the file that was actually being displayed. |
| 1048 | " B. not reusing the window for which the location list window is opened but |
| 1049 | " instead creating new windows. |
| 1050 | " C. make sure that the location list window is not reused instead of the |
| 1051 | " window it belongs to. |
| 1052 | " |
| 1053 | " Set up the test environment: |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1054 | func ReadTestProtocol(name) |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1055 | let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') |
| 1056 | let word = substitute(base, '\v(.*)\..*', '\1', '') |
| 1057 | |
| 1058 | setl modifiable |
| 1059 | setl noreadonly |
| 1060 | setl noswapfile |
| 1061 | setl bufhidden=delete |
| 1062 | %del _ |
| 1063 | " For problem 2: |
| 1064 | " 'buftype' has to be set to reproduce the constant opening of new windows |
| 1065 | setl buftype=nofile |
| 1066 | |
| 1067 | call setline(1, word) |
| 1068 | |
| 1069 | setl nomodified |
| 1070 | setl nomodifiable |
| 1071 | setl readonly |
| 1072 | exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1073 | endfunc |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1074 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1075 | func Test_locationlist() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1076 | enew |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1077 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1078 | augroup testgroup |
| 1079 | au! |
| 1080 | autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) |
| 1081 | augroup END |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1082 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1083 | let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1084 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1085 | let qflist = [] |
| 1086 | for word in words |
| 1087 | call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) |
| 1088 | " NOTE: problem 1: |
| 1089 | " intentionally not setting 'lnum' so that the quickfix entries are not |
| 1090 | " valid |
| 1091 | eval qflist->setloclist(0, ' ') |
| 1092 | endfor |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1093 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1094 | " Test A |
| 1095 | lrewind |
| 1096 | enew |
| 1097 | lopen |
| 1098 | 4lnext |
| 1099 | vert split |
| 1100 | wincmd L |
| 1101 | lopen |
| 1102 | wincmd p |
| 1103 | lnext |
| 1104 | let fileName = expand("%") |
| 1105 | wincmd p |
| 1106 | let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') |
| 1107 | let fileName = substitute(fileName, '\\', '/', 'g') |
| 1108 | let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') |
| 1109 | call assert_equal("test://bar.txt", fileName) |
| 1110 | call assert_equal("test://bar.txt", locationListFileName) |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1111 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1112 | wincmd n | only |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1113 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1114 | " Test B: |
| 1115 | lrewind |
| 1116 | lopen |
| 1117 | 2 |
| 1118 | exe "normal \<CR>" |
| 1119 | wincmd p |
| 1120 | 3 |
| 1121 | exe "normal \<CR>" |
| 1122 | wincmd p |
| 1123 | 4 |
| 1124 | exe "normal \<CR>" |
| 1125 | call assert_equal(2, winnr('$')) |
| 1126 | wincmd n | only |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1127 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1128 | " Test C: |
| 1129 | lrewind |
| 1130 | lopen |
| 1131 | " Let's move the location list window to the top to check whether it (the |
| 1132 | " first window found) will be reused when we try to open new windows: |
| 1133 | wincmd K |
| 1134 | 2 |
| 1135 | exe "normal \<CR>" |
| 1136 | wincmd p |
| 1137 | 3 |
| 1138 | exe "normal \<CR>" |
| 1139 | wincmd p |
| 1140 | 4 |
| 1141 | exe "normal \<CR>" |
| 1142 | 1wincmd w |
| 1143 | call assert_equal('quickfix', &buftype) |
| 1144 | 2wincmd w |
| 1145 | let bufferName = expand("%") |
| 1146 | let bufferName = substitute(bufferName, '\\', '/', 'g') |
| 1147 | call assert_equal('test://quux.txt', bufferName) |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1148 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1149 | wincmd n | only |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 1150 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1151 | augroup! testgroup |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1152 | endfunc |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 1153 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1154 | func Test_locationlist_curwin_was_closed() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1155 | augroup testgroup |
| 1156 | au! |
| 1157 | autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>")) |
| 1158 | augroup END |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 1159 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1160 | func! R(n) |
| 1161 | quit |
| 1162 | endfunc |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 1163 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1164 | new |
| 1165 | let q = [] |
| 1166 | call add(q, {'filename': 'test_curwin.txt' }) |
| 1167 | call setloclist(0, q) |
| 1168 | call assert_fails('lrewind', 'E924:') |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 1169 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1170 | augroup! testgroup |
Bram Moolenaar | 9b4a80a | 2022-02-01 13:54:17 +0000 | [diff] [blame] | 1171 | delfunc R |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1172 | endfunc |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1173 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1174 | func Test_locationlist_cross_tab_jump() |
Bram Moolenaar | 0a9046f | 2016-10-15 19:28:13 +0200 | [diff] [blame] | 1175 | call writefile(['loclistfoo'], 'loclistfoo') |
| 1176 | call writefile(['loclistbar'], 'loclistbar') |
| 1177 | set switchbuf=usetab |
| 1178 | |
| 1179 | edit loclistfoo |
| 1180 | tabedit loclistbar |
| 1181 | silent lgrep loclistfoo loclist* |
| 1182 | call assert_equal(1, tabpagenr()) |
| 1183 | |
| 1184 | enew | only | tabonly |
| 1185 | set switchbuf&vim |
| 1186 | call delete('loclistfoo') |
| 1187 | call delete('loclistbar') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1188 | endfunc |
Bram Moolenaar | 0a9046f | 2016-10-15 19:28:13 +0200 | [diff] [blame] | 1189 | |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1190 | " More tests for 'errorformat' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1191 | func Test_efm1() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1192 | " The 'errorformat' setting is different on non-Unix systems. |
| 1193 | " This test works only on Unix-like systems. |
| 1194 | CheckUnix |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1195 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1196 | let l =<< trim [DATA] |
| 1197 | "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set. |
| 1198 | "Xtestfile", line 6 col 19; this is an error |
| 1199 | gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c |
| 1200 | Xtestfile:9: parse error before `asd' |
| 1201 | make: *** [vim] Error 1 |
| 1202 | in file "Xtestfile" linenr 10: there is an error |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1203 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1204 | 2 returned |
| 1205 | "Xtestfile", line 11 col 1; this is an error |
| 1206 | "Xtestfile", line 12 col 2; this is another error |
| 1207 | "Xtestfile", line 14:10; this is an error in column 10 |
| 1208 | =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time |
| 1209 | "Xtestfile", linenr 16: yet another problem |
| 1210 | Error in "Xtestfile" at line 17: |
| 1211 | x should be a dot |
| 1212 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 |
| 1213 | ^ |
| 1214 | Error in "Xtestfile" at line 18: |
| 1215 | x should be a dot |
| 1216 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 |
| 1217 | .............^ |
| 1218 | Error in "Xtestfile" at line 19: |
| 1219 | x should be a dot |
| 1220 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 |
| 1221 | --------------^ |
| 1222 | Error in "Xtestfile" at line 20: |
| 1223 | x should be a dot |
| 1224 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 |
| 1225 | ^ |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1226 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1227 | Does anyone know what is the problem and how to correction it? |
| 1228 | "Xtestfile", line 21 col 9: What is the title of the quickfix window? |
| 1229 | "Xtestfile", line 22 col 9: What is the title of the quickfix window? |
| 1230 | [DATA] |
| 1231 | |
| 1232 | call writefile(l, 'Xerrorfile1') |
| 1233 | call writefile(l[:-2], 'Xerrorfile2') |
| 1234 | |
| 1235 | let m =<< [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1236 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2 |
| 1237 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3 |
| 1238 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4 |
| 1239 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5 |
| 1240 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6 |
| 1241 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7 |
| 1242 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8 |
| 1243 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9 |
| 1244 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10 |
| 1245 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11 |
| 1246 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12 |
| 1247 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13 |
| 1248 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14 |
| 1249 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15 |
| 1250 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16 |
| 1251 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 |
| 1252 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 |
| 1253 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 |
| 1254 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 |
| 1255 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21 |
| 1256 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22 |
| 1257 | [DATA] |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1258 | call writefile(m, 'Xtestfile') |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1259 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1260 | let save_efm = &efm |
| 1261 | set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m |
| 1262 | set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1263 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1264 | exe 'cf Xerrorfile2' |
| 1265 | clast |
| 1266 | copen |
| 1267 | call assert_equal(':cf Xerrorfile2', w:quickfix_title) |
| 1268 | wincmd p |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1269 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1270 | exe 'cf Xerrorfile1' |
| 1271 | call assert_equal([4, 12], [line('.'), col('.')]) |
| 1272 | cn |
| 1273 | call assert_equal([6, 19], [line('.'), col('.')]) |
| 1274 | cn |
| 1275 | call assert_equal([9, 2], [line('.'), col('.')]) |
| 1276 | cn |
| 1277 | call assert_equal([10, 2], [line('.'), col('.')]) |
| 1278 | cn |
| 1279 | call assert_equal([11, 1], [line('.'), col('.')]) |
| 1280 | cn |
| 1281 | call assert_equal([12, 2], [line('.'), col('.')]) |
| 1282 | cn |
| 1283 | call assert_equal([14, 10], [line('.'), col('.')]) |
| 1284 | cn |
| 1285 | call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 1286 | cn |
| 1287 | call assert_equal([16, 2], [line('.'), col('.')]) |
| 1288 | cn |
| 1289 | call assert_equal([17, 6], [line('.'), col('.')]) |
| 1290 | cn |
| 1291 | call assert_equal([18, 7], [line('.'), col('.')]) |
| 1292 | cn |
| 1293 | call assert_equal([19, 8], [line('.'), col('.')]) |
| 1294 | cn |
| 1295 | call assert_equal([20, 9], [line('.'), col('.')]) |
| 1296 | clast |
| 1297 | cprev |
| 1298 | cprev |
| 1299 | wincmd w |
| 1300 | call assert_equal(':cf Xerrorfile1', w:quickfix_title) |
| 1301 | wincmd p |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 1302 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1303 | let &efm = save_efm |
| 1304 | call delete('Xerrorfile1') |
| 1305 | call delete('Xerrorfile2') |
| 1306 | call delete('Xtestfile') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1307 | endfunc |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1308 | |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1309 | " Test for quickfix directory stack support |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1310 | func s:dir_stack_tests(cchar) |
Bram Moolenaar | 38df43b | 2016-06-20 21:41:12 +0200 | [diff] [blame] | 1311 | call s:setup_commands(a:cchar) |
| 1312 | |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1313 | let save_efm=&efm |
| 1314 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 1315 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1316 | let lines =<< trim END |
| 1317 | Entering dir 'dir1/a' |
| 1318 | habits2.txt:1:Nine Healthy Habits |
| 1319 | Entering dir 'b' |
| 1320 | habits3.txt:2:0 Hours of television |
| 1321 | habits2.txt:7:5 Small meals |
| 1322 | Entering dir 'dir1/c' |
| 1323 | habits4.txt:3:1 Hour of exercise |
| 1324 | Leaving dir 'dir1/c' |
| 1325 | Leaving dir 'dir1/a' |
| 1326 | habits1.txt:4:2 Liters of water |
| 1327 | Entering dir 'dir2' |
| 1328 | habits5.txt:5:3 Cups of hot green tea |
| 1329 | Leaving dir 'dir2' |
| 1330 | END |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1331 | |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1332 | Xexpr "" |
| 1333 | for l in lines |
| 1334 | Xaddexpr l |
| 1335 | endfor |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1336 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1337 | let qf = g:Xgetlist() |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1338 | |
| 1339 | call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr)) |
| 1340 | call assert_equal(1, qf[1].lnum) |
| 1341 | call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr)) |
| 1342 | call assert_equal(2, qf[3].lnum) |
| 1343 | call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr)) |
| 1344 | call assert_equal(7, qf[4].lnum) |
| 1345 | call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr)) |
| 1346 | call assert_equal(3, qf[6].lnum) |
| 1347 | call assert_equal('habits1.txt', bufname(qf[9].bufnr)) |
| 1348 | call assert_equal(4, qf[9].lnum) |
| 1349 | call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr)) |
| 1350 | call assert_equal(5, qf[11].lnum) |
| 1351 | |
| 1352 | let &efm=save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1353 | endfunc |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1354 | |
| 1355 | " Tests for %D and %X errorformat options |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1356 | func Test_efm_dirstack() |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1357 | " Create the directory stack and files |
| 1358 | call mkdir('dir1') |
| 1359 | call mkdir('dir1/a') |
| 1360 | call mkdir('dir1/a/b') |
| 1361 | call mkdir('dir1/c') |
| 1362 | call mkdir('dir2') |
| 1363 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1364 | let lines =<< trim END |
| 1365 | Nine Healthy Habits |
| 1366 | 0 Hours of television |
| 1367 | 1 Hour of exercise |
| 1368 | 2 Liters of water |
| 1369 | 3 Cups of hot green tea |
| 1370 | 4 Short mental breaks |
| 1371 | 5 Small meals |
| 1372 | 6 AM wake up time |
| 1373 | 7 Minutes of laughter |
| 1374 | 8 Hours of sleep (at least) |
| 1375 | 9 PM end of the day and off to bed |
| 1376 | END |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1377 | call writefile(lines, 'habits1.txt') |
| 1378 | call writefile(lines, 'dir1/a/habits2.txt') |
| 1379 | call writefile(lines, 'dir1/a/b/habits3.txt') |
| 1380 | call writefile(lines, 'dir1/c/habits4.txt') |
| 1381 | call writefile(lines, 'dir2/habits5.txt') |
| 1382 | |
| 1383 | call s:dir_stack_tests('c') |
| 1384 | call s:dir_stack_tests('l') |
| 1385 | |
| 1386 | call delete('dir1', 'rf') |
| 1387 | call delete('dir2', 'rf') |
| 1388 | call delete('habits1.txt') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1389 | endfunc |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1390 | |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1391 | " Test for resync after continuing an ignored message |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1392 | func Xefm_ignore_continuations(cchar) |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1393 | call s:setup_commands(a:cchar) |
| 1394 | |
| 1395 | let save_efm = &efm |
| 1396 | |
| 1397 | let &efm = |
| 1398 | \ '%Eerror %m %l,' . |
| 1399 | \ '%-Wignored %m %l,' . |
| 1400 | \ '%+Cmore ignored %m %l,' . |
| 1401 | \ '%Zignored end' |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1402 | let lines =<< trim END |
| 1403 | ignored warning 1 |
| 1404 | more ignored continuation 2 |
| 1405 | ignored end |
| 1406 | error resync 4 |
| 1407 | END |
| 1408 | Xgetexpr lines |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1409 | let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]') |
| 1410 | call assert_equal([['resync', 1, 4, 'E']], l) |
| 1411 | |
| 1412 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1413 | endfunc |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1414 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1415 | func Test_efm_ignore_continuations() |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1416 | call Xefm_ignore_continuations('c') |
| 1417 | call Xefm_ignore_continuations('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1418 | endfunc |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1419 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1420 | " Tests for invalid error format specifies |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1421 | func Xinvalid_efm_Tests(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1422 | call s:setup_commands(a:cchar) |
| 1423 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1424 | let save_efm = &efm |
| 1425 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1426 | set efm=%f:%l:%m,%f:%f:%l:%m |
| 1427 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:') |
| 1428 | |
| 1429 | set efm=%f:%l:%m,%f:%l:%r:%m |
| 1430 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') |
| 1431 | |
| 1432 | set efm=%f:%l:%m,%O:%f:%l:%m |
| 1433 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') |
| 1434 | |
| 1435 | set efm=%f:%l:%m,%f:%l:%*[^a-z |
| 1436 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:') |
| 1437 | |
| 1438 | set efm=%f:%l:%m,%f:%l:%*c |
| 1439 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:') |
| 1440 | |
| 1441 | set efm=%f:%l:%m,%L%M%N |
| 1442 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:') |
| 1443 | |
| 1444 | set efm=%f:%l:%m,%f:%l:%m:%R |
| 1445 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:') |
| 1446 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1447 | " Invalid regular expression |
| 1448 | set efm=%\\%%k |
| 1449 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E867:') |
| 1450 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1451 | set efm= |
| 1452 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') |
| 1453 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 1454 | " Empty directory name. When there is an error in parsing new entries, make |
| 1455 | " sure the previous quickfix list is made the current list. |
| 1456 | set efm& |
| 1457 | cexpr ["one", "two"] |
| 1458 | let qf_id = getqflist(#{id: 0}).id |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1459 | set efm=%DEntering\ dir\ abc,%f:%l:%m |
| 1460 | call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 1461 | call assert_equal(qf_id, getqflist(#{id: 0}).id) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1462 | |
| 1463 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1464 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1465 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1466 | func Test_invalid_efm() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1467 | call Xinvalid_efm_Tests('c') |
| 1468 | call Xinvalid_efm_Tests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1469 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1470 | |
| 1471 | " TODO: |
| 1472 | " Add tests for the following formats in 'errorformat' |
| 1473 | " %r %O |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1474 | func Test_efm2() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1475 | let save_efm = &efm |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1476 | |
| 1477 | " Test for %s format in efm |
| 1478 | set efm=%f:%s |
| 1479 | cexpr 'Xtestfile:Line search text' |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1480 | let l = getqflist() |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1481 | call assert_equal('^\VLine search text\$', l[0].pattern) |
| 1482 | call assert_equal(0, l[0].lnum) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1483 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1484 | let l = split(execute('clist', ''), "\n") |
| 1485 | call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l) |
| 1486 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1487 | " Test for a long line |
| 1488 | cexpr 'Xtestfile:' . repeat('a', 1026) |
| 1489 | let l = getqflist() |
| 1490 | call assert_equal('^\V' . repeat('a', 1019) . '\$', l[0].pattern) |
| 1491 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1492 | " Test for %P, %Q and %t format specifiers |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1493 | let lines =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1494 | [Xtestfile1] |
| 1495 | (1,17) error: ';' missing |
| 1496 | (21,2) warning: variable 'z' not defined |
| 1497 | (67,3) error: end of file found before string ended |
| 1498 | -- |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1499 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1500 | [Xtestfile2] |
| 1501 | -- |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1502 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1503 | [Xtestfile3] |
| 1504 | NEW compiler v1.1 |
| 1505 | (2,2) warning: variable 'x' not defined |
| 1506 | (67,3) warning: 's' already defined |
| 1507 | -- |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1508 | [DATA] |
| 1509 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1510 | set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1511 | " To exercise the push/pop file functionality in quickfix, the test files |
| 1512 | " need to be created. |
| 1513 | call writefile(['Line1'], 'Xtestfile1') |
| 1514 | call writefile(['Line2'], 'Xtestfile2') |
| 1515 | call writefile(['Line3'], 'Xtestfile3') |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1516 | cexpr "" |
| 1517 | for l in lines |
| 1518 | caddexpr l |
| 1519 | endfor |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1520 | let l = getqflist() |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1521 | call assert_equal(12, len(l)) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1522 | call assert_equal(21, l[2].lnum) |
| 1523 | call assert_equal(2, l[2].col) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1524 | call assert_equal('w', l[2].type) |
| 1525 | call assert_equal('e', l[3].type) |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1526 | call delete('Xtestfile1') |
| 1527 | call delete('Xtestfile2') |
| 1528 | call delete('Xtestfile3') |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1529 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1530 | " Test for %P, %Q with non-existing files |
| 1531 | cexpr lines |
| 1532 | let l = getqflist() |
| 1533 | call assert_equal(14, len(l)) |
| 1534 | call assert_equal('[Xtestfile1]', l[0].text) |
| 1535 | call assert_equal('[Xtestfile2]', l[6].text) |
| 1536 | call assert_equal('[Xtestfile3]', l[9].text) |
| 1537 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1538 | " Tests for %E, %C and %Z format specifiers |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1539 | let lines =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1540 | Error 275 |
| 1541 | line 42 |
| 1542 | column 3 |
| 1543 | ' ' expected after '--' |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1544 | [DATA] |
| 1545 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1546 | set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m |
| 1547 | cgetexpr lines |
| 1548 | let l = getqflist() |
| 1549 | call assert_equal(275, l[0].nr) |
| 1550 | call assert_equal(42, l[0].lnum) |
| 1551 | call assert_equal(3, l[0].col) |
| 1552 | call assert_equal('E', l[0].type) |
| 1553 | call assert_equal("\n' ' expected after '--'", l[0].text) |
| 1554 | |
| 1555 | " Test for %> |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1556 | let lines =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1557 | Error in line 147 of foo.c: |
| 1558 | unknown variable 'i' |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1559 | [DATA] |
| 1560 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1561 | set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m |
| 1562 | cgetexpr lines |
| 1563 | let l = getqflist() |
| 1564 | call assert_equal(147, l[0].lnum) |
| 1565 | call assert_equal('E', l[0].type) |
| 1566 | call assert_equal("\nunknown variable 'i'", l[0].text) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1567 | |
Bram Moolenaar | e87e6dd | 2016-07-17 19:25:04 +0200 | [diff] [blame] | 1568 | " Test for %A, %C and other formats |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1569 | let lines =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1570 | ============================================================== |
| 1571 | FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest) |
| 1572 | -------------------------------------------------------------- |
| 1573 | Traceback (most recent call last): |
| 1574 | File "unittests/dbfacadeTest.py", line 89, in testFoo |
| 1575 | self.assertEquals(34, dtid) |
| 1576 | File "/usr/lib/python2.2/unittest.py", line 286, in |
| 1577 | failUnlessEqual |
| 1578 | raise self.failureException, \\ |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1579 | W:AssertionError: 34 != 33 |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1580 | |
| 1581 | -------------------------------------------------------------- |
| 1582 | Ran 27 tests in 0.063s |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1583 | [DATA] |
| 1584 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1585 | set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%t:%m |
Bram Moolenaar | e87e6dd | 2016-07-17 19:25:04 +0200 | [diff] [blame] | 1586 | cgetexpr lines |
| 1587 | let l = getqflist() |
| 1588 | call assert_equal(8, len(l)) |
| 1589 | call assert_equal(89, l[4].lnum) |
| 1590 | call assert_equal(1, l[4].valid) |
| 1591 | call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr)) |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1592 | call assert_equal('W', l[4].type) |
Bram Moolenaar | e87e6dd | 2016-07-17 19:25:04 +0200 | [diff] [blame] | 1593 | |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1594 | " Test for %o |
| 1595 | set efm=%f(%o):%l\ %m |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1596 | cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error'] |
| 1597 | call writefile(['Line1'], 'Xotestfile') |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1598 | let l = getqflist() |
| 1599 | call assert_equal(1, len(l), string(l)) |
| 1600 | call assert_equal('Language.PureScript.Types', l[0].module) |
| 1601 | copen |
| 1602 | call assert_equal('Language.PureScript.Types|20| Error', getline(1)) |
| 1603 | call feedkeys("\<CR>", 'xn') |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1604 | call assert_equal('Xotestfile', expand('%:t')) |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1605 | cclose |
| 1606 | bd |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1607 | call delete("Xotestfile") |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1608 | |
Bram Moolenaar | 70077dd | 2019-11-24 12:12:42 +0100 | [diff] [blame] | 1609 | " Test for a long module name |
| 1610 | cexpr 'Xtest(' . repeat('m', 1026) . '):15 message' |
| 1611 | let l = getqflist() |
| 1612 | call assert_equal(repeat('m', 1024), l[0].module) |
| 1613 | call assert_equal(15, l[0].lnum) |
| 1614 | call assert_equal('message', l[0].text) |
| 1615 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1616 | " The following sequence of commands used to crash Vim |
| 1617 | set efm=%W%m |
| 1618 | cgetexpr ['msg1'] |
| 1619 | let l = getqflist() |
| 1620 | call assert_equal(1, len(l), string(l)) |
| 1621 | call assert_equal('msg1', l[0].text) |
| 1622 | set efm=%C%m |
| 1623 | lexpr 'msg2' |
| 1624 | let l = getloclist(0) |
| 1625 | call assert_equal(1, len(l), string(l)) |
| 1626 | call assert_equal('msg2', l[0].text) |
| 1627 | lopen |
| 1628 | call setqflist([], 'r') |
| 1629 | caddbuf |
| 1630 | let l = getqflist() |
| 1631 | call assert_equal(1, len(l), string(l)) |
| 1632 | call assert_equal('|| msg2', l[0].text) |
| 1633 | |
Bram Moolenaar | 78ddc06 | 2018-05-15 21:56:34 +0200 | [diff] [blame] | 1634 | " When matching error lines, case should be ignored. Test for this. |
| 1635 | set noignorecase |
| 1636 | let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'}) |
| 1637 | call assert_equal(10, l.items[0].lnum) |
| 1638 | call assert_equal('Line 20', l.items[0].text) |
| 1639 | set ignorecase& |
| 1640 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1641 | new | only |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1642 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1643 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1644 | |
Bram Moolenaar | e928366 | 2020-06-07 14:10:47 +0200 | [diff] [blame] | 1645 | " Test for '%t' (error type) field in 'efm' |
| 1646 | func Test_efm_error_type() |
| 1647 | let save_efm = &efm |
| 1648 | |
| 1649 | " error type |
| 1650 | set efm=%f:%l:%t:%m |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1651 | let lines =<< trim END |
| 1652 | Xfile1:10:E:msg1 |
| 1653 | Xfile1:20:W:msg2 |
| 1654 | Xfile1:30:I:msg3 |
| 1655 | Xfile1:40:N:msg4 |
| 1656 | Xfile1:50:R:msg5 |
| 1657 | END |
| 1658 | cexpr lines |
Bram Moolenaar | e928366 | 2020-06-07 14:10:47 +0200 | [diff] [blame] | 1659 | let output = split(execute('clist'), "\n") |
| 1660 | call assert_equal([ |
| 1661 | \ ' 1 Xfile1:10 error: msg1', |
| 1662 | \ ' 2 Xfile1:20 warning: msg2', |
| 1663 | \ ' 3 Xfile1:30 info: msg3', |
| 1664 | \ ' 4 Xfile1:40 note: msg4', |
| 1665 | \ ' 5 Xfile1:50 R: msg5'], output) |
| 1666 | |
| 1667 | " error type and a error number |
| 1668 | set efm=%f:%l:%t:%n:%m |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1669 | let lines =<< trim END |
| 1670 | Xfile1:10:E:2:msg1 |
| 1671 | Xfile1:20:W:4:msg2 |
| 1672 | Xfile1:30:I:6:msg3 |
| 1673 | Xfile1:40:N:8:msg4 |
| 1674 | Xfile1:50:R:3:msg5 |
| 1675 | END |
| 1676 | cexpr lines |
Bram Moolenaar | e928366 | 2020-06-07 14:10:47 +0200 | [diff] [blame] | 1677 | let output = split(execute('clist'), "\n") |
| 1678 | call assert_equal([ |
| 1679 | \ ' 1 Xfile1:10 error 2: msg1', |
| 1680 | \ ' 2 Xfile1:20 warning 4: msg2', |
| 1681 | \ ' 3 Xfile1:30 info 6: msg3', |
| 1682 | \ ' 4 Xfile1:40 note 8: msg4', |
| 1683 | \ ' 5 Xfile1:50 R 3: msg5'], output) |
| 1684 | let &efm = save_efm |
| 1685 | endfunc |
| 1686 | |
haya14busa | e023d49 | 2022-02-08 18:09:29 +0000 | [diff] [blame] | 1687 | " Test for end_lnum ('%e') and end_col ('%k') fields in 'efm' |
| 1688 | func Test_efm_end_lnum_col() |
| 1689 | let save_efm = &efm |
| 1690 | |
| 1691 | " single line |
| 1692 | set efm=%f:%l-%e:%c-%k:%t:%m |
| 1693 | cexpr ["Xfile1:10-20:1-2:E:msg1", "Xfile1:20-30:2-3:W:msg2",] |
| 1694 | let output = split(execute('clist'), "\n") |
| 1695 | call assert_equal([ |
| 1696 | \ ' 1 Xfile1:10-20 col 1-2 error: msg1', |
| 1697 | \ ' 2 Xfile1:20-30 col 2-3 warning: msg2'], output) |
| 1698 | |
| 1699 | " multiple lines |
| 1700 | set efm=%A%n)%m,%Z%f:%l-%e:%c-%k |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 1701 | let lines =<< trim END |
| 1702 | 1)msg1 |
| 1703 | Xfile1:14-24:1-2 |
| 1704 | 2)msg2 |
| 1705 | Xfile1:24-34:3-4 |
| 1706 | END |
| 1707 | cexpr lines |
haya14busa | e023d49 | 2022-02-08 18:09:29 +0000 | [diff] [blame] | 1708 | let output = split(execute('clist'), "\n") |
| 1709 | call assert_equal([ |
| 1710 | \ ' 1 Xfile1:14-24 col 1-2 error 1: msg1', |
| 1711 | \ ' 2 Xfile1:24-34 col 3-4 error 2: msg2'], output) |
| 1712 | let &efm = save_efm |
| 1713 | endfunc |
| 1714 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1715 | func XquickfixChangedByAutocmd(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1716 | call s:setup_commands(a:cchar) |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1717 | if a:cchar == 'c' |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1718 | let ErrorNr = 'E925' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1719 | func! ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1720 | colder |
| 1721 | cgetexpr [] |
| 1722 | endfunc |
| 1723 | else |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1724 | let ErrorNr = 'E926' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1725 | func! ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1726 | lolder |
| 1727 | lgetexpr [] |
| 1728 | endfunc |
| 1729 | endif |
| 1730 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 1731 | augroup QF_Test |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1732 | au! |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1733 | autocmd BufReadCmd test_changed.txt call ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1734 | augroup END |
| 1735 | |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1736 | new | only |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1737 | let words = [ "a", "b" ] |
| 1738 | let qflist = [] |
| 1739 | for word in words |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1740 | call add(qflist, {'filename': 'test_changed.txt'}) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1741 | call g:Xsetlist(qflist, ' ') |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1742 | endfor |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1743 | call assert_fails('Xrewind', ErrorNr . ':') |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1744 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 1745 | augroup QF_Test |
| 1746 | au! |
| 1747 | augroup END |
| 1748 | |
| 1749 | if a:cchar == 'c' |
| 1750 | cexpr ["Xtest1:1:Line"] |
| 1751 | cwindow |
| 1752 | only |
| 1753 | augroup QF_Test |
| 1754 | au! |
| 1755 | autocmd WinEnter * call setqflist([], 'f') |
| 1756 | augroup END |
| 1757 | call assert_fails('exe "normal \<CR>"', 'E925:') |
| 1758 | augroup QF_Test |
| 1759 | au! |
| 1760 | augroup END |
| 1761 | endif |
| 1762 | %bw! |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1763 | endfunc |
| 1764 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1765 | func Test_quickfix_was_changed_by_autocmd() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1766 | call XquickfixChangedByAutocmd('c') |
| 1767 | call XquickfixChangedByAutocmd('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1768 | endfunc |
Bram Moolenaar | 8b20179 | 2016-03-25 15:01:10 +0100 | [diff] [blame] | 1769 | |
Bram Moolenaar | 4d170af | 2020-09-13 22:21:22 +0200 | [diff] [blame] | 1770 | func Test_setloclist_in_autocommand() |
| 1771 | call writefile(['test1', 'test2'], 'Xfile') |
| 1772 | edit Xfile |
| 1773 | let s:bufnr = bufnr() |
| 1774 | call setloclist(1, |
| 1775 | \ [{'bufnr' : s:bufnr, 'lnum' : 1, 'text' : 'test1'}, |
| 1776 | \ {'bufnr' : s:bufnr, 'lnum' : 2, 'text' : 'test2'}]) |
| 1777 | |
| 1778 | augroup Test_LocList |
| 1779 | au! |
| 1780 | autocmd BufEnter * call setloclist(1, |
| 1781 | \ [{'bufnr' : s:bufnr, 'lnum' : 1, 'text' : 'test1'}, |
| 1782 | \ {'bufnr' : s:bufnr, 'lnum' : 2, 'text' : 'test2'}], 'r') |
| 1783 | augroup END |
| 1784 | |
| 1785 | lopen |
| 1786 | call assert_fails('exe "normal j\<CR>"', 'E926:') |
| 1787 | |
| 1788 | augroup Test_LocList |
| 1789 | au! |
| 1790 | augroup END |
| 1791 | call delete('Xfile') |
| 1792 | endfunc |
| 1793 | |
Bram Moolenaar | 8b20179 | 2016-03-25 15:01:10 +0100 | [diff] [blame] | 1794 | func Test_caddbuffer_to_empty() |
| 1795 | helpgr quickfix |
| 1796 | call setqflist([], 'r') |
| 1797 | cad |
Bram Moolenaar | f68f1d7 | 2016-03-25 17:14:06 +0100 | [diff] [blame] | 1798 | try |
| 1799 | cn |
| 1800 | catch |
| 1801 | " number of matches is unknown |
| 1802 | call assert_true(v:exception =~ 'E553:') |
| 1803 | endtry |
Bram Moolenaar | 8b20179 | 2016-03-25 15:01:10 +0100 | [diff] [blame] | 1804 | quit! |
| 1805 | endfunc |
Bram Moolenaar | 89c64d5 | 2016-03-27 18:44:40 +0200 | [diff] [blame] | 1806 | |
| 1807 | func Test_cgetexpr_works() |
| 1808 | " this must not crash Vim |
| 1809 | cgetexpr [$x] |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1810 | lgetexpr [$x] |
Bram Moolenaar | 89c64d5 | 2016-03-27 18:44:40 +0200 | [diff] [blame] | 1811 | endfunc |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1812 | |
| 1813 | " Tests for the setqflist() and setloclist() functions |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1814 | func SetXlistTests(cchar, bnum) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1815 | call s:setup_commands(a:cchar) |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1816 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1817 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1}, |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 1818 | \ {'bufnr': a:bnum, 'lnum': 2, 'end_lnum': 3, 'col': 4, 'end_col': 5}]) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1819 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1820 | call assert_equal(2, len(l)) |
| 1821 | call assert_equal(2, l[1].lnum) |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 1822 | call assert_equal(3, l[1].end_lnum) |
| 1823 | call assert_equal(4, l[1].col) |
| 1824 | call assert_equal(5, l[1].end_col) |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1825 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1826 | Xnext |
| 1827 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') |
| 1828 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1829 | call assert_equal(3, len(l)) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1830 | Xnext |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1831 | call assert_equal(3, line('.')) |
| 1832 | |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1833 | " Appending entries to the list should not change the cursor position |
| 1834 | " in the quickfix window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1835 | Xwindow |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1836 | 1 |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1837 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4}, |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1838 | \ {'bufnr': a:bnum, 'lnum': 5}], 'a') |
| 1839 | call assert_equal(1, line('.')) |
| 1840 | close |
| 1841 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1842 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}, |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1843 | \ {'bufnr': a:bnum, 'lnum': 4}, |
| 1844 | \ {'bufnr': a:bnum, 'lnum': 5}], 'r') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1845 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1846 | call assert_equal(3, len(l)) |
| 1847 | call assert_equal(5, l[2].lnum) |
| 1848 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1849 | call g:Xsetlist([]) |
| 1850 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1851 | call assert_equal(0, len(l)) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1852 | |
Bram Moolenaar | f1d21c8 | 2017-04-22 21:20:46 +0200 | [diff] [blame] | 1853 | " Tests for setting the 'valid' flag |
| 1854 | call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}]) |
| 1855 | Xwindow |
| 1856 | call assert_equal(1, winnr('$')) |
| 1857 | let l = g:Xgetlist() |
| 1858 | call g:Xsetlist(l) |
| 1859 | call assert_equal(0, g:Xgetlist()[0].valid) |
Bram Moolenaar | 9752c72 | 2018-12-22 16:49:34 +0100 | [diff] [blame] | 1860 | " Adding a non-valid entry should not mark the list as having valid entries |
| 1861 | call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a') |
| 1862 | Xwindow |
| 1863 | call assert_equal(1, winnr('$')) |
| 1864 | |
| 1865 | " :cnext/:cprev should still work even with invalid entries in the list |
| 1866 | let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0}, |
| 1867 | \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}] |
| 1868 | call g:Xsetlist(l) |
| 1869 | Xnext |
| 1870 | call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) |
| 1871 | Xprev |
| 1872 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 1873 | " :cnext/:cprev should still work after appending invalid entries to an |
| 1874 | " empty list |
| 1875 | call g:Xsetlist([]) |
| 1876 | call g:Xsetlist(l, 'a') |
| 1877 | Xnext |
| 1878 | call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) |
| 1879 | Xprev |
| 1880 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 1881 | |
Bram Moolenaar | f1d21c8 | 2017-04-22 21:20:46 +0200 | [diff] [blame] | 1882 | call g:Xsetlist([{'text':'Text1', 'valid':1}]) |
| 1883 | Xwindow |
| 1884 | call assert_equal(2, winnr('$')) |
| 1885 | Xclose |
| 1886 | let save_efm = &efm |
| 1887 | set efm=%m |
| 1888 | Xgetexpr 'TestMessage' |
| 1889 | let l = g:Xgetlist() |
| 1890 | call g:Xsetlist(l) |
| 1891 | call assert_equal(1, g:Xgetlist()[0].valid) |
| 1892 | let &efm = save_efm |
| 1893 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1894 | " Error cases: |
| 1895 | " Refer to a non-existing buffer and pass a non-dictionary type |
| 1896 | call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," . |
| 1897 | \ " {'bufnr':999, 'lnum':5}])", 'E92:') |
| 1898 | call g:Xsetlist([[1, 2,3]]) |
| 1899 | call assert_equal(0, len(g:Xgetlist())) |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1900 | call assert_fails('call g:Xsetlist([], [])', 'E928:') |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 1901 | call g:Xsetlist([test_null_dict()]) |
| 1902 | call assert_equal([], g:Xgetlist()) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1903 | endfunc |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1904 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1905 | func Test_setqflist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1906 | new Xtestfile | only |
| 1907 | let bnum = bufnr('%') |
| 1908 | call setline(1, range(1,5)) |
| 1909 | |
| 1910 | call SetXlistTests('c', bnum) |
| 1911 | call SetXlistTests('l', bnum) |
| 1912 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1913 | enew! |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1914 | call delete('Xtestfile') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1915 | endfunc |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1916 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1917 | func Xlist_empty_middle(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1918 | call s:setup_commands(a:cchar) |
| 1919 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1920 | " create three quickfix lists |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1921 | let @/ = 'Test_' |
| 1922 | Xvimgrep // test_quickfix.vim |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1923 | let testlen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1924 | call assert_true(testlen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1925 | Xvimgrep empty test_quickfix.vim |
| 1926 | call assert_true(len(g:Xgetlist()) > 0) |
| 1927 | Xvimgrep matches test_quickfix.vim |
| 1928 | let matchlen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1929 | call assert_true(matchlen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1930 | Xolder |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1931 | " make the middle list empty |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1932 | call g:Xsetlist([], 'r') |
| 1933 | call assert_true(len(g:Xgetlist()) == 0) |
| 1934 | Xolder |
| 1935 | call assert_equal(testlen, len(g:Xgetlist())) |
| 1936 | Xnewer |
| 1937 | Xnewer |
| 1938 | call assert_equal(matchlen, len(g:Xgetlist())) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1939 | endfunc |
| 1940 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1941 | func Test_setqflist_empty_middle() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1942 | call Xlist_empty_middle('c') |
| 1943 | call Xlist_empty_middle('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1944 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1945 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1946 | func Xlist_empty_older(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1947 | call s:setup_commands(a:cchar) |
| 1948 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1949 | " create three quickfix lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1950 | Xvimgrep one test_quickfix.vim |
| 1951 | let onelen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1952 | call assert_true(onelen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1953 | Xvimgrep two test_quickfix.vim |
| 1954 | let twolen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1955 | call assert_true(twolen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1956 | Xvimgrep three test_quickfix.vim |
| 1957 | let threelen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1958 | call assert_true(threelen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1959 | Xolder 2 |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1960 | " make the first list empty, check the others didn't change |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1961 | call g:Xsetlist([], 'r') |
| 1962 | call assert_true(len(g:Xgetlist()) == 0) |
| 1963 | Xnewer |
| 1964 | call assert_equal(twolen, len(g:Xgetlist())) |
| 1965 | Xnewer |
| 1966 | call assert_equal(threelen, len(g:Xgetlist())) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1967 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1968 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1969 | func Test_setqflist_empty_older() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1970 | call Xlist_empty_older('c') |
| 1971 | call Xlist_empty_older('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1972 | endfunc |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1973 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1974 | func XquickfixSetListWithAct(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1975 | call s:setup_commands(a:cchar) |
| 1976 | |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1977 | let list1 = [{'filename': 'fnameA', 'text': 'A'}, |
| 1978 | \ {'filename': 'fnameB', 'text': 'B'}] |
| 1979 | let list2 = [{'filename': 'fnameC', 'text': 'C'}, |
| 1980 | \ {'filename': 'fnameD', 'text': 'D'}, |
| 1981 | \ {'filename': 'fnameE', 'text': 'E'}] |
| 1982 | |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 1983 | " {action} is unspecified. Same as specifying ' '. |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1984 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1985 | silent! Xnewer 99 |
| 1986 | call g:Xsetlist(list1) |
| 1987 | call g:Xsetlist(list2) |
| 1988 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1989 | call assert_equal(3, len(li)) |
| 1990 | call assert_equal('C', li[0]['text']) |
| 1991 | call assert_equal('D', li[1]['text']) |
| 1992 | call assert_equal('E', li[2]['text']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1993 | silent! Xolder |
| 1994 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1995 | call assert_equal(2, len(li)) |
| 1996 | call assert_equal('A', li[0]['text']) |
| 1997 | call assert_equal('B', li[1]['text']) |
| 1998 | |
| 1999 | " {action} is specified ' '. |
| 2000 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2001 | silent! Xnewer 99 |
| 2002 | call g:Xsetlist(list1) |
| 2003 | call g:Xsetlist(list2, ' ') |
| 2004 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2005 | call assert_equal(3, len(li)) |
| 2006 | call assert_equal('C', li[0]['text']) |
| 2007 | call assert_equal('D', li[1]['text']) |
| 2008 | call assert_equal('E', li[2]['text']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2009 | silent! Xolder |
| 2010 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2011 | call assert_equal(2, len(li)) |
| 2012 | call assert_equal('A', li[0]['text']) |
| 2013 | call assert_equal('B', li[1]['text']) |
| 2014 | |
| 2015 | " {action} is specified 'a'. |
| 2016 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2017 | silent! Xnewer 99 |
| 2018 | call g:Xsetlist(list1) |
| 2019 | call g:Xsetlist(list2, 'a') |
| 2020 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2021 | call assert_equal(5, len(li)) |
| 2022 | call assert_equal('A', li[0]['text']) |
| 2023 | call assert_equal('B', li[1]['text']) |
| 2024 | call assert_equal('C', li[2]['text']) |
| 2025 | call assert_equal('D', li[3]['text']) |
| 2026 | call assert_equal('E', li[4]['text']) |
| 2027 | |
| 2028 | " {action} is specified 'r'. |
| 2029 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2030 | silent! Xnewer 99 |
| 2031 | call g:Xsetlist(list1) |
| 2032 | call g:Xsetlist(list2, 'r') |
| 2033 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2034 | call assert_equal(3, len(li)) |
| 2035 | call assert_equal('C', li[0]['text']) |
| 2036 | call assert_equal('D', li[1]['text']) |
| 2037 | call assert_equal('E', li[2]['text']) |
| 2038 | |
| 2039 | " Test for wrong value. |
| 2040 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2041 | call assert_fails("call g:Xsetlist(0)", 'E714:') |
| 2042 | call assert_fails("call g:Xsetlist(list1, '')", 'E927:') |
| 2043 | call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:') |
| 2044 | call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:') |
| 2045 | call assert_fails("call g:Xsetlist(list1, 0)", 'E928:') |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2046 | endfunc |
| 2047 | |
Bram Moolenaar | a0ca7d0 | 2017-12-19 10:22:19 +0100 | [diff] [blame] | 2048 | func Test_setqflist_invalid_nr() |
| 2049 | " The following command used to crash Vim |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 2050 | eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST}) |
Bram Moolenaar | a0ca7d0 | 2017-12-19 10:22:19 +0100 | [diff] [blame] | 2051 | endfunc |
| 2052 | |
Bram Moolenaar | 99234f2 | 2020-02-10 22:56:54 +0100 | [diff] [blame] | 2053 | func Test_setqflist_user_sets_buftype() |
| 2054 | call setqflist([{'text': 'foo'}, {'text': 'bar'}]) |
| 2055 | set buftype=quickfix |
| 2056 | call setqflist([], 'a') |
| 2057 | enew |
| 2058 | endfunc |
| 2059 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2060 | func Test_quickfix_set_list_with_act() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 2061 | call XquickfixSetListWithAct('c') |
| 2062 | call XquickfixSetListWithAct('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2063 | endfunc |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2064 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2065 | func XLongLinesTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2066 | let l = g:Xgetlist() |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2067 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2068 | call assert_equal(4, len(l)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2069 | call assert_equal(1, l[0].lnum) |
| 2070 | call assert_equal(1, l[0].col) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2071 | call assert_equal(1975, len(l[0].text)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2072 | call assert_equal(2, l[1].lnum) |
| 2073 | call assert_equal(1, l[1].col) |
| 2074 | call assert_equal(4070, len(l[1].text)) |
| 2075 | call assert_equal(3, l[2].lnum) |
| 2076 | call assert_equal(1, l[2].col) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2077 | call assert_equal(4070, len(l[2].text)) |
| 2078 | call assert_equal(4, l[3].lnum) |
| 2079 | call assert_equal(1, l[3].col) |
| 2080 | call assert_equal(10, len(l[3].text)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2081 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2082 | call g:Xsetlist([], 'r') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2083 | endfunc |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2084 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2085 | func s:long_lines_tests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2086 | call s:setup_commands(a:cchar) |
| 2087 | |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2088 | let testfile = 'samples/quickfix.txt' |
| 2089 | |
| 2090 | " file |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2091 | exe 'Xgetfile' testfile |
| 2092 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2093 | |
| 2094 | " list |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2095 | Xexpr readfile(testfile) |
| 2096 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2097 | |
| 2098 | " string |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2099 | Xexpr join(readfile(testfile), "\n") |
| 2100 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 2101 | |
| 2102 | " buffer |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2103 | exe 'edit' testfile |
| 2104 | exe 'Xbuffer' bufnr('%') |
Bram Moolenaar | f50df39 | 2016-06-21 21:33:34 +0200 | [diff] [blame] | 2105 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2106 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2107 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2108 | func Test_long_lines() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 2109 | call s:long_lines_tests('c') |
| 2110 | call s:long_lines_tests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2111 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2112 | |
Bram Moolenaar | 59941cb | 2020-09-05 17:03:40 +0200 | [diff] [blame] | 2113 | func Test_cgetfile_on_long_lines() |
| 2114 | " Problematic values if the line is longer than 4096 bytes. Then 1024 bytes |
| 2115 | " are read at a time. |
| 2116 | for len in [4078, 4079, 4080, 5102, 5103, 5104, 6126, 6127, 6128, 7150, 7151, 7152] |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2117 | let lines =<< trim END |
| 2118 | /tmp/file1:1:1:aaa |
| 2119 | /tmp/file2:1:1:%s |
| 2120 | /tmp/file3:1:1:bbb |
| 2121 | /tmp/file4:1:1:ccc |
| 2122 | END |
Bram Moolenaar | 59941cb | 2020-09-05 17:03:40 +0200 | [diff] [blame] | 2123 | let lines[1] = substitute(lines[1], '%s', repeat('x', len), '') |
| 2124 | call writefile(lines, 'Xcqetfile.txt') |
| 2125 | cgetfile Xcqetfile.txt |
| 2126 | call assert_equal(4, getqflist(#{size: v:true}).size, 'with length ' .. len) |
| 2127 | endfor |
| 2128 | call delete('Xcqetfile.txt') |
| 2129 | endfunc |
| 2130 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2131 | func s:create_test_file(filename) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2132 | let l = [] |
| 2133 | for i in range(1, 20) |
| 2134 | call add(l, 'Line' . i) |
| 2135 | endfor |
| 2136 | call writefile(l, a:filename) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2137 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2138 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2139 | func Test_switchbuf() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2140 | call s:create_test_file('Xqftestfile1') |
| 2141 | call s:create_test_file('Xqftestfile2') |
| 2142 | call s:create_test_file('Xqftestfile3') |
| 2143 | |
| 2144 | new | only |
| 2145 | edit Xqftestfile1 |
| 2146 | let file1_winid = win_getid() |
| 2147 | new Xqftestfile2 |
| 2148 | let file2_winid = win_getid() |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2149 | let lines =<< trim END |
| 2150 | Xqftestfile1:5:Line5 |
| 2151 | Xqftestfile1:6:Line6 |
| 2152 | Xqftestfile2:10:Line10 |
| 2153 | Xqftestfile2:11:Line11 |
| 2154 | Xqftestfile3:15:Line15 |
| 2155 | Xqftestfile3:16:Line16 |
| 2156 | END |
| 2157 | cgetexpr lines |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2158 | |
| 2159 | new |
| 2160 | let winid = win_getid() |
| 2161 | cfirst | cnext |
| 2162 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 2163 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2164 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 2165 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2166 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2167 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2168 | " Test for 'switchbuf' set to search for files in windows in the current |
| 2169 | " tabpage and jump to an existing window (if present) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2170 | set switchbuf=useopen |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2171 | enew |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2172 | cfirst | cnext |
| 2173 | call assert_equal(file1_winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 2174 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2175 | call assert_equal(file2_winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 2176 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2177 | call assert_equal(file2_winid, win_getid()) |
| 2178 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2179 | " Test for 'switchbuf' set to search for files in tabpages and jump to an |
| 2180 | " existing tabpage (if present) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2181 | enew | only |
| 2182 | set switchbuf=usetab |
| 2183 | tabedit Xqftestfile1 |
| 2184 | tabedit Xqftestfile2 |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 2185 | tabedit Xqftestfile3 |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2186 | tabfirst |
| 2187 | cfirst | cnext |
| 2188 | call assert_equal(2, tabpagenr()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 2189 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2190 | call assert_equal(3, tabpagenr()) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 2191 | 6cnext |
| 2192 | call assert_equal(4, tabpagenr()) |
| 2193 | 2cpfile |
| 2194 | call assert_equal(2, tabpagenr()) |
| 2195 | 2cnfile |
| 2196 | call assert_equal(4, tabpagenr()) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2197 | tabfirst | tabonly | enew |
| 2198 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2199 | " Test for 'switchbuf' set to open a new window for every file |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2200 | set switchbuf=split |
| 2201 | cfirst | cnext |
| 2202 | call assert_equal(1, winnr('$')) |
| 2203 | cnext | cnext |
| 2204 | call assert_equal(2, winnr('$')) |
| 2205 | cnext | cnext |
| 2206 | call assert_equal(3, winnr('$')) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2207 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2208 | " Test for 'switchbuf' set to open a new tabpage for every file |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2209 | set switchbuf=newtab |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2210 | enew | only |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2211 | cfirst | cnext |
| 2212 | call assert_equal(1, tabpagenr('$')) |
| 2213 | cnext | cnext |
| 2214 | call assert_equal(2, tabpagenr('$')) |
| 2215 | cnext | cnext |
| 2216 | call assert_equal(3, tabpagenr('$')) |
| 2217 | tabfirst | enew | tabonly | only |
| 2218 | |
Bram Moolenaar | 539aa6b | 2019-11-17 18:09:38 +0100 | [diff] [blame] | 2219 | set switchbuf=uselast |
| 2220 | split |
| 2221 | let last_winid = win_getid() |
| 2222 | copen |
| 2223 | exe "normal 1G\<CR>" |
| 2224 | call assert_equal(last_winid, win_getid()) |
| 2225 | enew | only |
| 2226 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2227 | " With an empty 'switchbuf', jumping to a quickfix entry should open the |
| 2228 | " file in an existing window (if present) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2229 | set switchbuf= |
| 2230 | edit Xqftestfile1 |
| 2231 | let file1_winid = win_getid() |
| 2232 | new Xqftestfile2 |
| 2233 | let file2_winid = win_getid() |
| 2234 | copen |
| 2235 | exe "normal 1G\<CR>" |
| 2236 | call assert_equal(file1_winid, win_getid()) |
| 2237 | copen |
| 2238 | exe "normal 3G\<CR>" |
| 2239 | call assert_equal(file2_winid, win_getid()) |
| 2240 | copen | only |
| 2241 | exe "normal 5G\<CR>" |
| 2242 | call assert_equal(2, winnr('$')) |
| 2243 | call assert_equal(1, bufwinnr('Xqftestfile3')) |
| 2244 | |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 2245 | " If only quickfix window is open in the current tabpage, jumping to an |
Bram Moolenaar | 1bc353b | 2019-09-01 14:45:28 +0200 | [diff] [blame] | 2246 | " entry with 'switchbuf' set to 'usetab' should search in other tabpages. |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2247 | enew | only |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 2248 | set switchbuf=usetab |
| 2249 | tabedit Xqftestfile1 |
| 2250 | tabedit Xqftestfile2 |
| 2251 | tabedit Xqftestfile3 |
| 2252 | tabfirst |
| 2253 | copen | only |
| 2254 | clast |
| 2255 | call assert_equal(4, tabpagenr()) |
| 2256 | tabfirst | tabonly | enew | only |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2257 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2258 | " Jumping to a file that is not present in any of the tabpages and the |
| 2259 | " current tabpage doesn't have any usable windows, should open it in a new |
| 2260 | " window in the current tabpage. |
| 2261 | copen | only |
| 2262 | cfirst |
| 2263 | call assert_equal(1, tabpagenr()) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 2264 | call assert_equal('Xqftestfile1', @%) |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2265 | |
| 2266 | " If opening a file changes 'switchbuf', then the new value should be |
| 2267 | " retained. |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 2268 | set modeline&vim |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2269 | call writefile(["vim: switchbuf=split"], 'Xqftestfile1') |
| 2270 | enew | only |
| 2271 | set switchbuf&vim |
| 2272 | cexpr "Xqftestfile1:1:10" |
| 2273 | call assert_equal('split', &switchbuf) |
| 2274 | call writefile(["vim: switchbuf=usetab"], 'Xqftestfile1') |
| 2275 | enew | only |
| 2276 | set switchbuf=useopen |
| 2277 | cexpr "Xqftestfile1:1:10" |
| 2278 | call assert_equal('usetab', &switchbuf) |
| 2279 | call writefile(["vim: switchbuf&vim"], 'Xqftestfile1') |
| 2280 | enew | only |
| 2281 | set switchbuf=useopen |
| 2282 | cexpr "Xqftestfile1:1:10" |
| 2283 | call assert_equal('', &switchbuf) |
| 2284 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2285 | call delete('Xqftestfile1') |
| 2286 | call delete('Xqftestfile2') |
| 2287 | call delete('Xqftestfile3') |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 2288 | set switchbuf&vim |
| 2289 | |
| 2290 | enew | only |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2291 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2292 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2293 | func Xadjust_qflnum(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2294 | call s:setup_commands(a:cchar) |
| 2295 | |
| 2296 | enew | only |
| 2297 | |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 2298 | let fname = 'Xqftestfile' . a:cchar |
| 2299 | call s:create_test_file(fname) |
| 2300 | exe 'edit ' . fname |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2301 | |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 2302 | Xgetexpr [fname . ':5:Line5', |
| 2303 | \ fname . ':10:Line10', |
| 2304 | \ fname . ':15:Line15', |
| 2305 | \ fname . ':20:Line20'] |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2306 | |
| 2307 | 6,14delete |
| 2308 | call append(6, ['Buffer', 'Window']) |
| 2309 | |
| 2310 | let l = g:Xgetlist() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2311 | call assert_equal(5, l[0].lnum) |
| 2312 | call assert_equal(6, l[2].lnum) |
| 2313 | call assert_equal(13, l[3].lnum) |
| 2314 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2315 | " If a file doesn't have any quickfix entries, then deleting lines in the |
| 2316 | " file should not update the quickfix list |
| 2317 | call g:Xsetlist([], 'f') |
| 2318 | 1,2delete |
| 2319 | call assert_equal([], g:Xgetlist()) |
| 2320 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2321 | enew! |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 2322 | call delete(fname) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2323 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2324 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2325 | func Test_adjust_lnum() |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 2326 | call setloclist(0, []) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2327 | call Xadjust_qflnum('c') |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 2328 | call setqflist([]) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2329 | call Xadjust_qflnum('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2330 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2331 | |
| 2332 | " Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2333 | func s:test_xgrep(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2334 | call s:setup_commands(a:cchar) |
| 2335 | |
| 2336 | " The following lines are used for the grep test. Don't remove. |
| 2337 | " Grep_Test_Text: Match 1 |
| 2338 | " Grep_Test_Text: Match 2 |
| 2339 | " GrepAdd_Test_Text: Match 1 |
| 2340 | " GrepAdd_Test_Text: Match 2 |
| 2341 | enew! | only |
| 2342 | set makeef&vim |
| 2343 | silent Xgrep Grep_Test_Text: test_quickfix.vim |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 2344 | call assert_true(len(g:Xgetlist()) == 5) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2345 | Xopen |
| 2346 | call assert_true(w:quickfix_title =~ '^:grep') |
| 2347 | Xclose |
| 2348 | enew |
| 2349 | set makeef=Temp_File_## |
| 2350 | silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 2351 | call assert_true(len(g:Xgetlist()) == 9) |
| 2352 | |
| 2353 | " Try with 'grepprg' set to 'internal' |
| 2354 | set grepprg=internal |
| 2355 | silent Xgrep Grep_Test_Text: test_quickfix.vim |
| 2356 | silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim |
| 2357 | call assert_true(len(g:Xgetlist()) == 9) |
| 2358 | set grepprg&vim |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2359 | |
| 2360 | call writefile(['Vim'], 'XtestTempFile') |
| 2361 | set makeef=XtestTempFile |
| 2362 | silent Xgrep Grep_Test_Text: test_quickfix.vim |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 2363 | call assert_equal(5, len(g:Xgetlist())) |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 2364 | call assert_false(filereadable('XtestTempFile')) |
| 2365 | set makeef&vim |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2366 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2367 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2368 | func Test_grep() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2369 | " The grepprg may not be set on non-Unix systems |
| 2370 | CheckUnix |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 2371 | |
| 2372 | call s:test_xgrep('c') |
| 2373 | call s:test_xgrep('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2374 | endfunc |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 2375 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2376 | func Test_two_windows() |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 2377 | " Use one 'errorformat' for two windows. Add an expression to each of them, |
| 2378 | " make sure they each keep their own state. |
| 2379 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 2380 | call mkdir('Xone/a', 'p') |
| 2381 | call mkdir('Xtwo/a', 'p') |
| 2382 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 2383 | call writefile(lines, 'Xone/a/one.txt') |
| 2384 | call writefile(lines, 'Xtwo/a/two.txt') |
| 2385 | |
| 2386 | new one |
| 2387 | let one_id = win_getid() |
| 2388 | lexpr "" |
| 2389 | new two |
| 2390 | let two_id = win_getid() |
| 2391 | lexpr "" |
| 2392 | |
| 2393 | laddexpr "Entering dir 'Xtwo/a'" |
| 2394 | call win_gotoid(one_id) |
| 2395 | laddexpr "Entering dir 'Xone/a'" |
| 2396 | call win_gotoid(two_id) |
| 2397 | laddexpr 'two.txt:5:two two two' |
| 2398 | call win_gotoid(one_id) |
| 2399 | laddexpr 'one.txt:3:one one one' |
| 2400 | |
| 2401 | let loc_one = getloclist(one_id) |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 2402 | call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr)) |
| 2403 | call assert_equal(3, loc_one[1].lnum) |
| 2404 | |
| 2405 | let loc_two = getloclist(two_id) |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 2406 | call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr)) |
| 2407 | call assert_equal(5, loc_two[1].lnum) |
| 2408 | |
| 2409 | call win_gotoid(one_id) |
| 2410 | bwipe! |
| 2411 | call win_gotoid(two_id) |
| 2412 | bwipe! |
| 2413 | call delete('Xone', 'rf') |
| 2414 | call delete('Xtwo', 'rf') |
| 2415 | endfunc |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 2416 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2417 | func XbottomTests(cchar) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2418 | call s:setup_commands(a:cchar) |
| 2419 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 2420 | " Calling lbottom without any errors should fail |
| 2421 | if a:cchar == 'l' |
| 2422 | call assert_fails('lbottom', 'E776:') |
| 2423 | endif |
| 2424 | |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 2425 | call g:Xsetlist([{'filename': 'foo', 'lnum': 42}]) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2426 | Xopen |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 2427 | let wid = win_getid() |
| 2428 | call assert_equal(1, line('.')) |
| 2429 | wincmd w |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 2430 | call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a') |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2431 | Xbottom |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 2432 | call win_gotoid(wid) |
| 2433 | call assert_equal(2, line('.')) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2434 | Xclose |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 2435 | endfunc |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2436 | |
| 2437 | " Tests for the :cbottom and :lbottom commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2438 | func Test_cbottom() |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 2439 | call XbottomTests('c') |
| 2440 | call XbottomTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2441 | endfunc |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 2442 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2443 | func HistoryTest(cchar) |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 2444 | call s:setup_commands(a:cchar) |
| 2445 | |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 2446 | " clear all lists after the first one, then replace the first one. |
| 2447 | call g:Xsetlist([]) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 2448 | call assert_fails('Xolder 99', 'E380:') |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 2449 | let entry = {'filename': 'foo', 'lnum': 42} |
| 2450 | call g:Xsetlist([entry], 'r') |
| 2451 | call g:Xsetlist([entry, entry]) |
| 2452 | call g:Xsetlist([entry, entry, entry]) |
| 2453 | let res = split(execute(a:cchar . 'hist'), "\n") |
| 2454 | call assert_equal(3, len(res)) |
| 2455 | let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()' |
| 2456 | call assert_equal(' error list 1 of 3; 1 ' . common, res[0]) |
| 2457 | call assert_equal(' error list 2 of 3; 2 ' . common, res[1]) |
| 2458 | call assert_equal('> error list 3 of 3; 3 ' . common, res[2]) |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 2459 | |
Bram Moolenaar | 8ffc7c8 | 2019-05-05 21:00:26 +0200 | [diff] [blame] | 2460 | " Test for changing the quickfix lists |
| 2461 | call assert_equal(3, g:Xgetlist({'nr' : 0}).nr) |
| 2462 | exe '1' . a:cchar . 'hist' |
| 2463 | call assert_equal(1, g:Xgetlist({'nr' : 0}).nr) |
| 2464 | exe '3' . a:cchar . 'hist' |
| 2465 | call assert_equal(3, g:Xgetlist({'nr' : 0}).nr) |
| 2466 | call assert_fails('-2' . a:cchar . 'hist', 'E16:') |
| 2467 | call assert_fails('4' . a:cchar . 'hist', 'E16:') |
| 2468 | |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 2469 | call g:Xsetlist([], 'f') |
| 2470 | let l = split(execute(a:cchar . 'hist'), "\n") |
| 2471 | call assert_equal('No entries', l[0]) |
Bram Moolenaar | 8ffc7c8 | 2019-05-05 21:00:26 +0200 | [diff] [blame] | 2472 | if a:cchar == 'c' |
| 2473 | call assert_fails('4chist', 'E16:') |
| 2474 | else |
| 2475 | call assert_fails('4lhist', 'E776:') |
| 2476 | endif |
Bram Moolenaar | 5b69c22 | 2019-01-11 14:50:06 +0100 | [diff] [blame] | 2477 | |
| 2478 | " An empty list should still show the stack history |
| 2479 | call g:Xsetlist([]) |
| 2480 | let res = split(execute(a:cchar . 'hist'), "\n") |
| 2481 | call assert_equal('> error list 1 of 1; 0 ' . common, res[0]) |
| 2482 | |
| 2483 | call g:Xsetlist([], 'f') |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 2484 | endfunc |
| 2485 | |
| 2486 | func Test_history() |
| 2487 | call HistoryTest('c') |
| 2488 | call HistoryTest('l') |
| 2489 | endfunc |
Bram Moolenaar | 015102e | 2016-07-16 18:24:56 +0200 | [diff] [blame] | 2490 | |
| 2491 | func Test_duplicate_buf() |
| 2492 | " make sure we can get the highest buffer number |
| 2493 | edit DoesNotExist |
| 2494 | edit DoesNotExist2 |
| 2495 | let last_buffer = bufnr("$") |
| 2496 | |
| 2497 | " make sure only one buffer is created |
| 2498 | call writefile(['this one', 'that one'], 'Xgrepthis') |
| 2499 | vimgrep one Xgrepthis |
| 2500 | vimgrep one Xgrepthis |
| 2501 | call assert_equal(last_buffer + 1, bufnr("$")) |
| 2502 | |
| 2503 | call delete('Xgrepthis') |
| 2504 | endfunc |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2505 | |
| 2506 | " Quickfix/Location list set/get properties tests |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2507 | func Xproperty_tests(cchar) |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2508 | call s:setup_commands(a:cchar) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2509 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2510 | " Error cases |
| 2511 | call assert_fails('call g:Xgetlist(99)', 'E715:') |
| 2512 | call assert_fails('call g:Xsetlist(99)', 'E714:') |
| 2513 | call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2514 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2515 | " Set and get the title |
| 2516 | call g:Xsetlist([]) |
| 2517 | Xopen |
| 2518 | wincmd p |
| 2519 | call g:Xsetlist([{'filename':'foo', 'lnum':27}]) |
| 2520 | let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) |
| 2521 | call assert_equal(0, s) |
| 2522 | let d = g:Xgetlist({"title":1}) |
| 2523 | call assert_equal('Sample', d.title) |
| 2524 | " Try setting title to a non-string value |
| 2525 | call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) |
| 2526 | call assert_equal('Sample', g:Xgetlist({"title":1}).title) |
| 2527 | |
| 2528 | Xopen |
| 2529 | call assert_equal('Sample', w:quickfix_title) |
| 2530 | Xclose |
| 2531 | |
| 2532 | " Tests for action argument |
| 2533 | silent! Xolder 999 |
| 2534 | let qfnr = g:Xgetlist({'all':1}).nr |
| 2535 | call g:Xsetlist([], 'r', {'title' : 'N1'}) |
| 2536 | call assert_equal('N1', g:Xgetlist({'all':1}).title) |
| 2537 | call g:Xsetlist([], ' ', {'title' : 'N2'}) |
| 2538 | call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) |
| 2539 | |
| 2540 | let res = g:Xgetlist({'nr': 0}) |
| 2541 | call assert_equal(qfnr + 1, res.nr) |
| 2542 | call assert_equal(['nr'], keys(res)) |
| 2543 | |
| 2544 | call g:Xsetlist([], ' ', {'title' : 'N3'}) |
| 2545 | call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) |
| 2546 | |
| 2547 | " Changing the title of an earlier quickfix list |
| 2548 | call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) |
| 2549 | call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) |
| 2550 | |
| 2551 | " Changing the title of an invalid quickfix list |
| 2552 | call assert_equal(-1, g:Xsetlist([], ' ', |
| 2553 | \ {'title' : 'SomeTitle', 'nr' : 99})) |
| 2554 | call assert_equal(-1, g:Xsetlist([], ' ', |
| 2555 | \ {'title' : 'SomeTitle', 'nr' : 'abc'})) |
| 2556 | |
| 2557 | if a:cchar == 'c' |
| 2558 | copen |
| 2559 | call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) |
| 2560 | cclose |
| 2561 | endif |
| 2562 | |
| 2563 | " Invalid arguments |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 2564 | call assert_fails('call g:Xgetlist([])', 'E715:') |
| 2565 | call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2566 | let s = g:Xsetlist([], 'a', {'abc':1}) |
| 2567 | call assert_equal(-1, s) |
| 2568 | |
| 2569 | call assert_equal({}, g:Xgetlist({'abc':1})) |
| 2570 | call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) |
| 2571 | call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) |
| 2572 | |
| 2573 | if a:cchar == 'l' |
| 2574 | call assert_equal({}, getloclist(99, {'title': 1})) |
| 2575 | endif |
| 2576 | |
| 2577 | " Context related tests |
| 2578 | let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) |
| 2579 | call assert_equal(0, s) |
| 2580 | call test_garbagecollect_now() |
| 2581 | let d = g:Xgetlist({'context':1}) |
| 2582 | call assert_equal([1,2,3], d.context) |
| 2583 | call g:Xsetlist([], 'a', {'context':{'color':'green'}}) |
| 2584 | let d = g:Xgetlist({'context':1}) |
| 2585 | call assert_equal({'color':'green'}, d.context) |
| 2586 | call g:Xsetlist([], 'a', {'context':"Context info"}) |
| 2587 | let d = g:Xgetlist({'context':1}) |
| 2588 | call assert_equal("Context info", d.context) |
| 2589 | call g:Xsetlist([], 'a', {'context':246}) |
| 2590 | let d = g:Xgetlist({'context':1}) |
| 2591 | call assert_equal(246, d.context) |
| 2592 | " set other Vim data types as context |
| 2593 | call g:Xsetlist([], 'a', {'context' : test_null_blob()}) |
| 2594 | if has('channel') |
| 2595 | call g:Xsetlist([], 'a', {'context' : test_null_channel()}) |
| 2596 | endif |
| 2597 | if has('job') |
| 2598 | call g:Xsetlist([], 'a', {'context' : test_null_job()}) |
| 2599 | endif |
| 2600 | call g:Xsetlist([], 'a', {'context' : test_null_function()}) |
| 2601 | call g:Xsetlist([], 'a', {'context' : test_null_partial()}) |
| 2602 | call g:Xsetlist([], 'a', {'context' : ''}) |
| 2603 | call test_garbagecollect_now() |
| 2604 | if a:cchar == 'l' |
| 2605 | " Test for copying context across two different location lists |
| 2606 | new | only |
| 2607 | let w1_id = win_getid() |
| 2608 | let l = [1] |
| 2609 | call setloclist(0, [], 'a', {'context':l}) |
| 2610 | new |
| 2611 | let w2_id = win_getid() |
| 2612 | call add(l, 2) |
| 2613 | call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context) |
| 2614 | call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) |
| 2615 | unlet! l |
| 2616 | call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) |
| 2617 | only |
| 2618 | call setloclist(0, [], 'f') |
| 2619 | call assert_equal('', getloclist(0, {'context':1}).context) |
| 2620 | endif |
| 2621 | |
| 2622 | " Test for changing the context of previous quickfix lists |
| 2623 | call g:Xsetlist([], 'f') |
| 2624 | Xexpr "One" |
| 2625 | Xexpr "Two" |
| 2626 | Xexpr "Three" |
| 2627 | call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1}) |
| 2628 | call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2}) |
| 2629 | " Also, check for setting the context using quickfix list number zero. |
| 2630 | call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0}) |
| 2631 | call test_garbagecollect_now() |
| 2632 | let l = g:Xgetlist({'nr' : 1, 'context' : 1}) |
| 2633 | call assert_equal([1], l.context) |
| 2634 | let l = g:Xgetlist({'nr' : 2, 'context' : 1}) |
| 2635 | call assert_equal([2], l.context) |
| 2636 | let l = g:Xgetlist({'nr' : 3, 'context' : 1}) |
| 2637 | call assert_equal([3], l.context) |
| 2638 | |
| 2639 | " Test for changing the context through reference and for garbage |
| 2640 | " collection of quickfix context |
| 2641 | let l = ["red"] |
| 2642 | call g:Xsetlist([], ' ', {'context' : l}) |
| 2643 | call add(l, "blue") |
| 2644 | let x = g:Xgetlist({'context' : 1}) |
| 2645 | call add(x.context, "green") |
| 2646 | call assert_equal(["red", "blue", "green"], l) |
| 2647 | call assert_equal(["red", "blue", "green"], x.context) |
| 2648 | unlet l |
| 2649 | call test_garbagecollect_now() |
| 2650 | let m = g:Xgetlist({'context' : 1}) |
| 2651 | call assert_equal(["red", "blue", "green"], m.context) |
| 2652 | |
| 2653 | " Test for setting/getting items |
| 2654 | Xexpr "" |
| 2655 | let qfprev = g:Xgetlist({'nr':0}) |
| 2656 | let s = g:Xsetlist([], ' ', {'title':'Green', |
| 2657 | \ 'items' : [{'filename':'F1', 'lnum':10}]}) |
| 2658 | call assert_equal(0, s) |
| 2659 | let qfcur = g:Xgetlist({'nr':0}) |
| 2660 | call assert_true(qfcur.nr == qfprev.nr + 1) |
| 2661 | let l = g:Xgetlist({'items':1}) |
| 2662 | call assert_equal('F1', bufname(l.items[0].bufnr)) |
| 2663 | call assert_equal(10, l.items[0].lnum) |
| 2664 | call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20}, |
| 2665 | \ {'filename':'F2', 'lnum':30}]}) |
| 2666 | let l = g:Xgetlist({'items':1}) |
| 2667 | call assert_equal('F2', bufname(l.items[2].bufnr)) |
| 2668 | call assert_equal(30, l.items[2].lnum) |
| 2669 | call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]}) |
| 2670 | let l = g:Xgetlist({'items':1}) |
| 2671 | call assert_equal('F3', bufname(l.items[0].bufnr)) |
| 2672 | call assert_equal(40, l.items[0].lnum) |
| 2673 | call g:Xsetlist([], 'r', {'items' : []}) |
| 2674 | let l = g:Xgetlist({'items':1}) |
| 2675 | call assert_equal(0, len(l.items)) |
| 2676 | |
| 2677 | call g:Xsetlist([], 'r', {'title' : 'TestTitle'}) |
| 2678 | call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) |
| 2679 | call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) |
| 2680 | call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title) |
| 2681 | |
| 2682 | " Test for getting id of window associated with a location list window |
| 2683 | if a:cchar == 'l' |
| 2684 | only |
| 2685 | call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid) |
| 2686 | let wid = win_getid() |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2687 | Xopen |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2688 | call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid) |
| 2689 | wincmd w |
| 2690 | call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid) |
| 2691 | only |
| 2692 | endif |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2693 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2694 | " The following used to crash Vim with address sanitizer |
| 2695 | call g:Xsetlist([], 'f') |
| 2696 | call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) |
| 2697 | call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2698 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2699 | " Try setting the items using a string |
| 2700 | call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'})) |
Bram Moolenaar | 890680c | 2016-09-27 21:28:56 +0200 | [diff] [blame] | 2701 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2702 | " Save and restore the quickfix stack |
| 2703 | call g:Xsetlist([], 'f') |
| 2704 | call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) |
| 2705 | Xexpr "File1:10:Line1" |
| 2706 | Xexpr "File2:20:Line2" |
| 2707 | Xexpr "File3:30:Line3" |
| 2708 | let last_qf = g:Xgetlist({'nr':'$'}).nr |
| 2709 | call assert_equal(3, last_qf) |
| 2710 | let qstack = [] |
| 2711 | for i in range(1, last_qf) |
| 2712 | let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1})) |
| 2713 | endfor |
| 2714 | call g:Xsetlist([], 'f') |
| 2715 | for i in range(len(qstack)) |
| 2716 | call g:Xsetlist([], ' ', qstack[i]) |
| 2717 | endfor |
| 2718 | call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) |
| 2719 | call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum) |
| 2720 | call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum) |
| 2721 | call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum) |
| 2722 | call g:Xsetlist([], 'f') |
Bram Moolenaar | 890680c | 2016-09-27 21:28:56 +0200 | [diff] [blame] | 2723 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2724 | " Swap two quickfix lists |
| 2725 | Xexpr "File1:10:Line10" |
| 2726 | Xexpr "File2:20:Line20" |
| 2727 | Xexpr "File3:30:Line30" |
| 2728 | call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']}) |
| 2729 | call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']}) |
| 2730 | let l1=g:Xgetlist({'nr':1,'all':1}) |
| 2731 | let l2=g:Xgetlist({'nr':2,'all':1}) |
| 2732 | let save_id = l1.id |
| 2733 | let l1.id=l2.id |
| 2734 | let l2.id=save_id |
| 2735 | call g:Xsetlist([], 'r', l1) |
| 2736 | call g:Xsetlist([], 'r', l2) |
| 2737 | let newl1=g:Xgetlist({'nr':1,'all':1}) |
| 2738 | let newl2=g:Xgetlist({'nr':2,'all':1}) |
| 2739 | call assert_equal('Fruits', newl1.title) |
| 2740 | call assert_equal(['Fruits'], newl1.context) |
| 2741 | call assert_equal('Line20', newl1.items[0].text) |
| 2742 | call assert_equal('Colors', newl2.title) |
| 2743 | call assert_equal(['Colors'], newl2.context) |
| 2744 | call assert_equal('Line10', newl2.items[0].text) |
| 2745 | call g:Xsetlist([], 'f') |
Bram Moolenaar | 2b529bb | 2016-08-27 13:35:35 +0200 | [diff] [blame] | 2746 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2747 | " Cannot specify both a non-empty list argument and a dict argument |
| 2748 | call assert_fails("call g:Xsetlist([{}], ' ', {})", 'E475:') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2749 | endfunc |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2750 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2751 | func Test_qf_property() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2752 | call Xproperty_tests('c') |
| 2753 | call Xproperty_tests('l') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2754 | endfunc |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2755 | |
Bram Moolenaar | 5b69c22 | 2019-01-11 14:50:06 +0100 | [diff] [blame] | 2756 | " Test for setting the current index in the location/quickfix list |
| 2757 | func Xtest_setqfidx(cchar) |
| 2758 | call s:setup_commands(a:cchar) |
| 2759 | |
| 2760 | Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3" |
| 2761 | Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3" |
| 2762 | Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3" |
| 2763 | |
| 2764 | call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2}) |
| 2765 | call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2}) |
| 2766 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3}) |
| 2767 | Xolder 2 |
| 2768 | Xopen |
| 2769 | call assert_equal(3, line('.')) |
| 2770 | Xnewer |
| 2771 | call assert_equal(2, line('.')) |
| 2772 | Xnewer |
| 2773 | call assert_equal(2, line('.')) |
| 2774 | " Update the current index with the quickfix window open |
| 2775 | wincmd w |
| 2776 | call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3}) |
| 2777 | Xopen |
| 2778 | call assert_equal(3, line('.')) |
| 2779 | Xclose |
| 2780 | |
| 2781 | " Set the current index to the last entry |
| 2782 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'}) |
| 2783 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2784 | " A large value should set the index to the last index |
| 2785 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1}) |
| 2786 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999}) |
| 2787 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2788 | " Invalid index values |
| 2789 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1}) |
| 2790 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2791 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0}) |
| 2792 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2793 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'}) |
| 2794 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2795 | call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:') |
| 2796 | |
| 2797 | call g:Xsetlist([], 'f') |
| 2798 | new | only |
| 2799 | endfunc |
| 2800 | |
| 2801 | func Test_setqfidx() |
| 2802 | call Xtest_setqfidx('c') |
| 2803 | call Xtest_setqfidx('l') |
| 2804 | endfunc |
| 2805 | |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2806 | " Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2807 | func QfAutoCmdHandler(loc, cmd) |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2808 | call add(g:acmds, a:loc . a:cmd) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2809 | endfunc |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2810 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2811 | func Test_Autocmd() |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2812 | autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>')) |
| 2813 | autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>')) |
| 2814 | |
| 2815 | let g:acmds = [] |
| 2816 | cexpr "F1:10:Line 10" |
| 2817 | caddexpr "F1:20:Line 20" |
| 2818 | cgetexpr "F1:30:Line 30" |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2819 | cexpr "" |
| 2820 | caddexpr "" |
| 2821 | cgetexpr "" |
| 2822 | silent! cexpr non_existing_func() |
| 2823 | silent! caddexpr non_existing_func() |
| 2824 | silent! cgetexpr non_existing_func() |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2825 | let l =<< trim END |
| 2826 | precexpr |
| 2827 | postcexpr |
| 2828 | precaddexpr |
| 2829 | postcaddexpr |
| 2830 | precgetexpr |
| 2831 | postcgetexpr |
| 2832 | precexpr |
| 2833 | postcexpr |
| 2834 | precaddexpr |
| 2835 | postcaddexpr |
| 2836 | precgetexpr |
| 2837 | postcgetexpr |
| 2838 | precexpr |
| 2839 | precaddexpr |
| 2840 | precgetexpr |
| 2841 | END |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2842 | call assert_equal(l, g:acmds) |
| 2843 | |
| 2844 | let g:acmds = [] |
| 2845 | enew! | call append(0, "F2:10:Line 10") |
| 2846 | cbuffer! |
| 2847 | enew! | call append(0, "F2:20:Line 20") |
| 2848 | cgetbuffer |
| 2849 | enew! | call append(0, "F2:30:Line 30") |
| 2850 | caddbuffer |
| 2851 | new |
| 2852 | let bnum = bufnr('%') |
| 2853 | bunload |
| 2854 | exe 'silent! cbuffer! ' . bnum |
| 2855 | exe 'silent! cgetbuffer ' . bnum |
| 2856 | exe 'silent! caddbuffer ' . bnum |
| 2857 | enew! |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2858 | let l =<< trim END |
| 2859 | precbuffer |
| 2860 | postcbuffer |
| 2861 | precgetbuffer |
| 2862 | postcgetbuffer |
| 2863 | precaddbuffer |
| 2864 | postcaddbuffer |
| 2865 | precbuffer |
| 2866 | precgetbuffer |
| 2867 | precaddbuffer |
| 2868 | END |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2869 | call assert_equal(l, g:acmds) |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2870 | |
| 2871 | call writefile(['Xtest:1:Line1'], 'Xtest') |
| 2872 | call writefile([], 'Xempty') |
| 2873 | let g:acmds = [] |
| 2874 | cfile Xtest |
| 2875 | caddfile Xtest |
| 2876 | cgetfile Xtest |
| 2877 | cfile Xempty |
| 2878 | caddfile Xempty |
| 2879 | cgetfile Xempty |
| 2880 | silent! cfile do_not_exist |
| 2881 | silent! caddfile do_not_exist |
| 2882 | silent! cgetfile do_not_exist |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2883 | let l =<< trim END |
| 2884 | precfile |
| 2885 | postcfile |
| 2886 | precaddfile |
| 2887 | postcaddfile |
| 2888 | precgetfile |
| 2889 | postcgetfile |
| 2890 | precfile |
| 2891 | postcfile |
| 2892 | precaddfile |
| 2893 | postcaddfile |
| 2894 | precgetfile |
| 2895 | postcgetfile |
| 2896 | precfile |
| 2897 | postcfile |
| 2898 | precaddfile |
| 2899 | postcaddfile |
| 2900 | precgetfile |
| 2901 | postcgetfile |
| 2902 | END |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2903 | call assert_equal(l, g:acmds) |
| 2904 | |
| 2905 | let g:acmds = [] |
| 2906 | helpgrep quickfix |
| 2907 | silent! helpgrep non_existing_help_topic |
| 2908 | vimgrep test Xtest |
| 2909 | vimgrepadd test Xtest |
| 2910 | silent! vimgrep non_existing_test Xtest |
| 2911 | silent! vimgrepadd non_existing_test Xtest |
| 2912 | set makeprg= |
| 2913 | silent! make |
| 2914 | set makeprg& |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2915 | let l =<< trim END |
| 2916 | prehelpgrep |
| 2917 | posthelpgrep |
| 2918 | prehelpgrep |
| 2919 | posthelpgrep |
| 2920 | previmgrep |
| 2921 | postvimgrep |
| 2922 | previmgrepadd |
| 2923 | postvimgrepadd |
| 2924 | previmgrep |
| 2925 | postvimgrep |
| 2926 | previmgrepadd |
| 2927 | postvimgrepadd |
| 2928 | premake |
| 2929 | postmake |
| 2930 | END |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2931 | call assert_equal(l, g:acmds) |
| 2932 | |
| 2933 | if has('unix') |
| 2934 | " Run this test only on Unix-like systems. The grepprg may not be set on |
| 2935 | " non-Unix systems. |
| 2936 | " The following lines are used for the grep test. Don't remove. |
| 2937 | " Grep_Autocmd_Text: Match 1 |
| 2938 | " GrepAdd_Autocmd_Text: Match 2 |
| 2939 | let g:acmds = [] |
| 2940 | silent grep Grep_Autocmd_Text test_quickfix.vim |
| 2941 | silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim |
| 2942 | silent grep abc123def Xtest |
| 2943 | silent grepadd abc123def Xtest |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 2944 | set grepprg=internal |
| 2945 | silent grep Grep_Autocmd_Text test_quickfix.vim |
| 2946 | silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim |
| 2947 | silent lgrep Grep_Autocmd_Text test_quickfix.vim |
| 2948 | silent lgrepadd GrepAdd_Autocmd_Text test_quickfix.vim |
| 2949 | set grepprg&vim |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 2950 | let l =<< trim END |
| 2951 | pregrep |
| 2952 | postgrep |
| 2953 | pregrepadd |
| 2954 | postgrepadd |
| 2955 | pregrep |
| 2956 | postgrep |
| 2957 | pregrepadd |
| 2958 | postgrepadd |
| 2959 | pregrep |
| 2960 | postgrep |
| 2961 | pregrepadd |
| 2962 | postgrepadd |
| 2963 | prelgrep |
| 2964 | postlgrep |
| 2965 | prelgrepadd |
| 2966 | postlgrepadd |
| 2967 | END |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2968 | call assert_equal(l, g:acmds) |
| 2969 | endif |
| 2970 | |
| 2971 | call delete('Xtest') |
| 2972 | call delete('Xempty') |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 2973 | au! QuickFixCmdPre |
| 2974 | au! QuickFixCmdPost |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2975 | endfunc |
Bram Moolenaar | 21662be | 2016-11-06 14:46:44 +0100 | [diff] [blame] | 2976 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2977 | func Test_Autocmd_Exception() |
Bram Moolenaar | 21662be | 2016-11-06 14:46:44 +0100 | [diff] [blame] | 2978 | set efm=%m |
| 2979 | lgetexpr '?' |
| 2980 | |
| 2981 | try |
| 2982 | call DoesNotExit() |
| 2983 | catch |
| 2984 | lgetexpr '1' |
| 2985 | finally |
| 2986 | lgetexpr '1' |
| 2987 | endtry |
| 2988 | |
| 2989 | call assert_equal('1', getloclist(0)[0].text) |
| 2990 | |
| 2991 | set efm&vim |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2992 | endfunc |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 2993 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2994 | func Test_caddbuffer_wrong() |
| 2995 | " This used to cause a memory access in freed memory. |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 2996 | let save_efm = &efm |
| 2997 | set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.# |
| 2998 | cgetexpr ['WWWW', 'EEEE', 'CCCC'] |
| 2999 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 3000 | caddbuffer |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 3001 | bwipe! |
| 3002 | endfunc |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 3003 | |
| 3004 | func Test_caddexpr_wrong() |
| 3005 | " This used to cause a memory access in freed memory. |
| 3006 | cbuffer |
| 3007 | cbuffer |
| 3008 | copen |
| 3009 | let save_efm = &efm |
| 3010 | set efm=% |
| 3011 | call assert_fails('caddexpr ""', 'E376:') |
| 3012 | let &efm = save_efm |
| 3013 | endfunc |
Bram Moolenaar | 7618e00 | 2016-11-13 15:09:26 +0100 | [diff] [blame] | 3014 | |
| 3015 | func Test_dirstack_cleanup() |
| 3016 | " This used to cause a memory access in freed memory. |
| 3017 | let save_efm = &efm |
| 3018 | lexpr '0' |
| 3019 | lopen |
| 3020 | fun X(c) |
| 3021 | let save_efm=&efm |
| 3022 | set efm=%D%f |
| 3023 | if a:c == 'c' |
| 3024 | caddexpr '::' |
| 3025 | else |
| 3026 | laddexpr ':0:0' |
| 3027 | endif |
| 3028 | let &efm=save_efm |
| 3029 | endfun |
| 3030 | call X('c') |
| 3031 | call X('l') |
| 3032 | call setqflist([], 'r') |
| 3033 | caddbuffer |
| 3034 | let &efm = save_efm |
| 3035 | endfunc |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 3036 | |
| 3037 | " Tests for jumping to entries from the location list window and quickfix |
| 3038 | " window |
| 3039 | func Test_cwindow_jump() |
| 3040 | set efm=%f%%%l%%%m |
| 3041 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 3042 | lopen | only |
| 3043 | lfirst |
| 3044 | call assert_true(winnr('$') == 2) |
| 3045 | call assert_true(winnr() == 1) |
| 3046 | " Location list for the new window should be set |
| 3047 | call assert_true(getloclist(0)[2].text == 'Line 30') |
| 3048 | |
| 3049 | " Open a scratch buffer |
| 3050 | " Open a new window and create a location list |
| 3051 | " Open the location list window and close the other window |
| 3052 | " Jump to an entry. |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 3053 | " Should create a new window and jump to the entry. The scratch buffer |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 3054 | " should not be used. |
| 3055 | enew | only |
| 3056 | set buftype=nofile |
| 3057 | below new |
| 3058 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 3059 | lopen |
| 3060 | 2wincmd c |
| 3061 | lnext |
| 3062 | call assert_true(winnr('$') == 3) |
| 3063 | call assert_true(winnr() == 2) |
| 3064 | |
| 3065 | " Open two windows with two different location lists |
| 3066 | " Open the location list window and close the previous window |
| 3067 | " Jump to an entry in the location list window |
| 3068 | " Should open the file in the first window and not set the location list. |
| 3069 | enew | only |
| 3070 | lgetexpr ["F1%5%Line 5"] |
| 3071 | below new |
| 3072 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 3073 | lopen |
| 3074 | 2wincmd c |
| 3075 | lnext |
| 3076 | call assert_true(winnr() == 1) |
| 3077 | call assert_true(getloclist(0)[0].text == 'Line 5') |
| 3078 | |
| 3079 | enew | only |
| 3080 | cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 3081 | copen |
| 3082 | cnext |
| 3083 | call assert_true(winnr('$') == 2) |
| 3084 | call assert_true(winnr() == 1) |
| 3085 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 3086 | " open the quickfix buffer in two windows and jump to an entry. Should open |
| 3087 | " the file in the first quickfix window. |
| 3088 | enew | only |
| 3089 | copen |
| 3090 | let bnum = bufnr('') |
| 3091 | exe 'sbuffer ' . bnum |
| 3092 | wincmd b |
| 3093 | cfirst |
| 3094 | call assert_equal(2, winnr()) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 3095 | call assert_equal('F1', @%) |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 3096 | enew | only |
| 3097 | exe 'sb' bnum |
| 3098 | exe 'botright sb' bnum |
| 3099 | wincmd t |
| 3100 | clast |
| 3101 | call assert_equal(2, winnr()) |
| 3102 | call assert_equal('quickfix', getwinvar(1, '&buftype')) |
| 3103 | call assert_equal('quickfix', getwinvar(3, '&buftype')) |
| 3104 | |
Bram Moolenaar | 4b96df5 | 2020-01-26 22:00:26 +0100 | [diff] [blame] | 3105 | " Jumping to a file from the location list window should find a usable |
Bram Moolenaar | 15a7bdc | 2019-11-29 22:06:47 +0100 | [diff] [blame] | 3106 | " window by wrapping around the window list. |
| 3107 | enew | only |
| 3108 | call setloclist(0, [], 'f') |
| 3109 | new | new |
| 3110 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 3111 | lopen |
| 3112 | 1close |
| 3113 | call assert_equal(0, getloclist(3, {'id' : 0}).id) |
| 3114 | lnext |
| 3115 | call assert_equal(3, winnr()) |
| 3116 | call assert_equal(getloclist(1, {'id' : 0}).id, getloclist(3, {'id' : 0}).id) |
| 3117 | |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 3118 | enew | only |
| 3119 | set efm&vim |
| 3120 | endfunc |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3121 | |
Bram Moolenaar | e00fdf3 | 2019-09-15 19:09:42 +0200 | [diff] [blame] | 3122 | func Test_cwindow_highlight() |
| 3123 | CheckScreendump |
| 3124 | |
| 3125 | let lines =<< trim END |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 3126 | call setline(1, ['some', 'text', 'with', 'matches']) |
| 3127 | write XCwindow |
| 3128 | vimgrep e XCwindow |
| 3129 | redraw |
| 3130 | cwindow 4 |
Bram Moolenaar | e00fdf3 | 2019-09-15 19:09:42 +0200 | [diff] [blame] | 3131 | END |
| 3132 | call writefile(lines, 'XtestCwindow') |
| 3133 | let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12}) |
| 3134 | call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {}) |
| 3135 | |
| 3136 | call term_sendkeys(buf, ":cnext\<CR>") |
| 3137 | call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {}) |
| 3138 | |
| 3139 | " clean up |
| 3140 | call StopVimInTerminal(buf) |
| 3141 | call delete('XtestCwindow') |
| 3142 | call delete('XCwindow') |
| 3143 | endfunc |
| 3144 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3145 | func XvimgrepTests(cchar) |
| 3146 | call s:setup_commands(a:cchar) |
| 3147 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 3148 | let lines =<< trim END |
| 3149 | Editor:VIM vim |
| 3150 | Editor:Emacs EmAcS |
| 3151 | Editor:Notepad NOTEPAD |
| 3152 | END |
| 3153 | call writefile(lines, 'Xtestfile1') |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 3154 | call writefile(['Linux', 'macOS', 'MS-Windows'], 'Xtestfile2') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3155 | |
| 3156 | " Error cases |
| 3157 | call assert_fails('Xvimgrep /abc *', 'E682:') |
| 3158 | |
| 3159 | let @/='' |
| 3160 | call assert_fails('Xvimgrep // *', 'E35:') |
| 3161 | |
| 3162 | call assert_fails('Xvimgrep abc', 'E683:') |
| 3163 | call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:') |
| 3164 | call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:') |
| 3165 | |
| 3166 | Xexpr "" |
| 3167 | Xvimgrepadd Notepad Xtestfile1 |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 3168 | Xvimgrepadd macOS Xtestfile2 |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3169 | let l = g:Xgetlist() |
| 3170 | call assert_equal(2, len(l)) |
| 3171 | call assert_equal('Editor:Notepad NOTEPAD', l[0].text) |
| 3172 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 3173 | 10Xvimgrep #\cvim#g Xtestfile? |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3174 | let l = g:Xgetlist() |
| 3175 | call assert_equal(2, len(l)) |
| 3176 | call assert_equal(8, l[0].col) |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 3177 | call assert_equal(11, l[0].end_col) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3178 | call assert_equal(12, l[1].col) |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 3179 | call assert_equal(15, l[1].end_col) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3180 | |
| 3181 | 1Xvimgrep ?Editor? Xtestfile* |
| 3182 | let l = g:Xgetlist() |
| 3183 | call assert_equal(1, len(l)) |
| 3184 | call assert_equal('Editor:VIM vim', l[0].text) |
| 3185 | |
| 3186 | edit +3 Xtestfile2 |
| 3187 | Xvimgrep +\cemacs+j Xtestfile1 |
| 3188 | let l = g:Xgetlist() |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 3189 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3190 | call assert_equal('Editor:Emacs EmAcS', l[0].text) |
| 3191 | |
Bram Moolenaar | 2225ebb | 2018-04-24 15:48:11 +0200 | [diff] [blame] | 3192 | " Test for unloading a buffer after vimgrep searched the buffer |
| 3193 | %bwipe |
| 3194 | Xvimgrep /Editor/j Xtestfile* |
| 3195 | call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) |
| 3196 | call assert_equal([], getbufinfo('Xtestfile2')) |
| 3197 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 3198 | " Test for opening the dummy buffer used by vimgrep in a window. The new |
| 3199 | " window should be closed |
| 3200 | %bw! |
| 3201 | augroup QF_Test |
| 3202 | au! |
| 3203 | autocmd BufReadPre * exe "sb " .. expand("<abuf>") |
| 3204 | augroup END |
| 3205 | call assert_fails("Xvimgrep /sublime/ Xtestfile1", 'E480:') |
| 3206 | call assert_equal(1, winnr('$')) |
| 3207 | augroup QF_Test |
| 3208 | au! |
| 3209 | augroup END |
| 3210 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 3211 | call delete('Xtestfile1') |
| 3212 | call delete('Xtestfile2') |
| 3213 | endfunc |
| 3214 | |
| 3215 | " Tests for the :vimgrep command |
| 3216 | func Test_vimgrep() |
| 3217 | call XvimgrepTests('c') |
| 3218 | call XvimgrepTests('l') |
| 3219 | endfunc |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 3220 | |
Bram Moolenaar | f8c6a17 | 2021-01-30 18:09:06 +0100 | [diff] [blame] | 3221 | func Test_vimgrep_wildcards_expanded_once() |
| 3222 | new X[id-01] file.txt |
| 3223 | call setline(1, 'some text to search for') |
| 3224 | vimgrep text % |
| 3225 | bwipe! |
| 3226 | endfunc |
| 3227 | |
Bram Moolenaar | 1c29943 | 2018-10-28 14:36:09 +0100 | [diff] [blame] | 3228 | " Test for incsearch highlighting of the :vimgrep pattern |
| 3229 | " This test used to cause "E315: ml_get: invalid lnum" errors. |
| 3230 | func Test_vimgrep_incsearch() |
| 3231 | enew |
| 3232 | set incsearch |
| 3233 | call test_override("char_avail", 1) |
| 3234 | |
| 3235 | call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx") |
| 3236 | let l = getqflist() |
| 3237 | call assert_equal(2, len(l)) |
| 3238 | |
| 3239 | call test_override("ALL", 0) |
| 3240 | set noincsearch |
| 3241 | endfunc |
| 3242 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 3243 | " Test vimgrep with the last search pattern not set |
| 3244 | func Test_vimgrep_with_no_last_search_pat() |
| 3245 | let lines =<< trim [SCRIPT] |
| 3246 | call assert_fails('vimgrep // *', 'E35:') |
| 3247 | call writefile(v:errors, 'Xresult') |
| 3248 | qall! |
| 3249 | [SCRIPT] |
| 3250 | call writefile(lines, 'Xscript') |
| 3251 | if RunVim([], [], '--clean -S Xscript') |
| 3252 | call assert_equal([], readfile('Xresult')) |
| 3253 | endif |
| 3254 | call delete('Xscript') |
| 3255 | call delete('Xresult') |
| 3256 | endfunc |
| 3257 | |
Bram Moolenaar | 997cd1a | 2020-08-31 22:16:08 +0200 | [diff] [blame] | 3258 | " Test vimgrep without swap file |
| 3259 | func Test_vimgrep_without_swap_file() |
| 3260 | let lines =<< trim [SCRIPT] |
| 3261 | vimgrep grep test_c* |
| 3262 | call writefile(['done'], 'Xresult') |
| 3263 | qall! |
| 3264 | [SCRIPT] |
| 3265 | call writefile(lines, 'Xscript') |
| 3266 | if RunVim([], [], '--clean -n -S Xscript Xscript') |
| 3267 | call assert_equal(['done'], readfile('Xresult')) |
| 3268 | endif |
| 3269 | call delete('Xscript') |
| 3270 | call delete('Xresult') |
| 3271 | endfunc |
| 3272 | |
Bram Moolenaar | 8ce4b7e | 2020-08-07 18:12:18 +0200 | [diff] [blame] | 3273 | func Test_vimgrep_existing_swapfile() |
| 3274 | call writefile(['match apple with apple'], 'Xapple') |
| 3275 | call writefile(['swapfile'], '.Xapple.swp') |
| 3276 | let g:foundSwap = 0 |
| 3277 | let g:ignoreSwapExists = 1 |
| 3278 | augroup grep |
| 3279 | au SwapExists * let foundSwap = 1 | let v:swapchoice = 'e' |
| 3280 | augroup END |
| 3281 | vimgrep apple Xapple |
| 3282 | call assert_equal(1, g:foundSwap) |
| 3283 | call assert_match('.Xapple.swo', swapname('')) |
| 3284 | |
| 3285 | call delete('Xapple') |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3286 | call delete('.Xapple.swp') |
Bram Moolenaar | 8ce4b7e | 2020-08-07 18:12:18 +0200 | [diff] [blame] | 3287 | augroup grep |
| 3288 | au! SwapExists |
| 3289 | augroup END |
| 3290 | unlet g:ignoreSwapExists |
| 3291 | endfunc |
| 3292 | |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 3293 | func XfreeTests(cchar) |
| 3294 | call s:setup_commands(a:cchar) |
| 3295 | |
| 3296 | enew | only |
| 3297 | |
| 3298 | " Deleting the quickfix stack should work even When the current list is |
| 3299 | " somewhere in the middle of the stack |
| 3300 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 3301 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 3302 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 3303 | Xolder |
| 3304 | call g:Xsetlist([], 'f') |
| 3305 | call assert_equal(0, len(g:Xgetlist())) |
| 3306 | |
| 3307 | " After deleting the stack, adding a new list should create a stack with a |
| 3308 | " single list. |
| 3309 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 3310 | call assert_equal(1, g:Xgetlist({'all':1}).nr) |
| 3311 | |
| 3312 | " Deleting the stack from a quickfix window should update/clear the |
| 3313 | " quickfix/location list window. |
| 3314 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 3315 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 3316 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 3317 | Xolder |
| 3318 | Xwindow |
| 3319 | call g:Xsetlist([], 'f') |
| 3320 | call assert_equal(2, winnr('$')) |
| 3321 | call assert_equal(1, line('$')) |
| 3322 | Xclose |
| 3323 | |
| 3324 | " Deleting the stack from a non-quickfix window should update/clear the |
| 3325 | " quickfix/location list window. |
| 3326 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 3327 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 3328 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 3329 | Xolder |
| 3330 | Xwindow |
| 3331 | wincmd p |
| 3332 | call g:Xsetlist([], 'f') |
| 3333 | call assert_equal(0, len(g:Xgetlist())) |
| 3334 | wincmd p |
| 3335 | call assert_equal(2, winnr('$')) |
| 3336 | call assert_equal(1, line('$')) |
| 3337 | |
| 3338 | " After deleting the location list stack, if the location list window is |
| 3339 | " opened, then a new location list should be created. So opening the |
| 3340 | " location list window again should not create a new window. |
| 3341 | if a:cchar == 'l' |
| 3342 | lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 3343 | wincmd p |
| 3344 | lopen |
| 3345 | call assert_equal(2, winnr('$')) |
| 3346 | endif |
| 3347 | Xclose |
| 3348 | endfunc |
| 3349 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 3350 | " Tests for the quickfix free functionality |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 3351 | func Test_qf_free() |
| 3352 | call XfreeTests('c') |
| 3353 | call XfreeTests('l') |
| 3354 | endfunc |
Bram Moolenaar | 6e62da3 | 2017-05-28 08:16:25 +0200 | [diff] [blame] | 3355 | |
| 3356 | " Test for buffer overflow when parsing lines and adding new entries to |
| 3357 | " the quickfix list. |
| 3358 | func Test_bufoverflow() |
| 3359 | set efm=%f:%l:%m |
| 3360 | cgetexpr ['File1:100:' . repeat('x', 1025)] |
| 3361 | |
| 3362 | set efm=%+GCompiler:\ %.%#,%f:%l:%m |
| 3363 | cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] |
| 3364 | |
| 3365 | set efm=%DEntering\ directory\ %f,%f:%l:%m |
| 3366 | cgetexpr ['Entering directory ' . repeat('a', 1006), |
| 3367 | \ 'File1:10:Hello World'] |
| 3368 | set efm&vim |
| 3369 | endfunc |
| 3370 | |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 3371 | " Tests for getting the quickfix stack size |
| 3372 | func XsizeTests(cchar) |
| 3373 | call s:setup_commands(a:cchar) |
| 3374 | |
| 3375 | call g:Xsetlist([], 'f') |
| 3376 | call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3377 | call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title) |
| 3378 | call assert_equal(0, g:Xgetlist({'nr':0}).nr) |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 3379 | |
| 3380 | Xexpr "File1:10:Line1" |
| 3381 | Xexpr "File2:20:Line2" |
| 3382 | Xexpr "File3:30:Line3" |
| 3383 | Xolder | Xolder |
| 3384 | call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) |
| 3385 | call g:Xsetlist([], 'f') |
| 3386 | |
| 3387 | Xexpr "File1:10:Line1" |
| 3388 | Xexpr "File2:20:Line2" |
| 3389 | Xexpr "File3:30:Line3" |
| 3390 | Xolder | Xolder |
| 3391 | call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'}) |
| 3392 | call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title) |
| 3393 | endfunc |
| 3394 | |
| 3395 | func Test_Qf_Size() |
| 3396 | call XsizeTests('c') |
| 3397 | call XsizeTests('l') |
| 3398 | endfunc |
Bram Moolenaar | 1814183 | 2017-06-25 21:17:25 +0200 | [diff] [blame] | 3399 | |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3400 | func Test_cclose_from_copen() |
| 3401 | augroup QF_Test |
| 3402 | au! |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 3403 | au FileType qf :call assert_fails(':cclose', 'E788:') |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3404 | augroup END |
| 3405 | copen |
| 3406 | augroup QF_Test |
| 3407 | au! |
| 3408 | augroup END |
| 3409 | augroup! QF_Test |
| 3410 | endfunc |
| 3411 | |
Bram Moolenaar | 1814183 | 2017-06-25 21:17:25 +0200 | [diff] [blame] | 3412 | func Test_cclose_in_autocmd() |
| 3413 | " Problem is only triggered if "starting" is zero, so that the OptionsSet |
| 3414 | " event will be triggered. |
| 3415 | call test_override('starting', 1) |
| 3416 | augroup QF_Test |
| 3417 | au! |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 3418 | au FileType qf :call assert_fails(':cclose', 'E788:') |
Bram Moolenaar | 1814183 | 2017-06-25 21:17:25 +0200 | [diff] [blame] | 3419 | augroup END |
| 3420 | copen |
| 3421 | augroup QF_Test |
| 3422 | au! |
| 3423 | augroup END |
| 3424 | augroup! QF_Test |
| 3425 | call test_override('starting', 0) |
| 3426 | endfunc |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3427 | |
Bram Moolenaar | 379fb76 | 2018-08-30 15:58:28 +0200 | [diff] [blame] | 3428 | " Check that ":file" without an argument is possible even when "curbuf_lock" |
| 3429 | " is set. |
| 3430 | func Test_file_from_copen() |
| 3431 | " Works without argument. |
| 3432 | augroup QF_Test |
| 3433 | au! |
| 3434 | au FileType qf file |
| 3435 | augroup END |
| 3436 | copen |
| 3437 | |
| 3438 | augroup QF_Test |
| 3439 | au! |
| 3440 | augroup END |
| 3441 | cclose |
| 3442 | |
| 3443 | " Fails with argument. |
| 3444 | augroup QF_Test |
| 3445 | au! |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 3446 | au FileType qf call assert_fails(':file foo', 'E788:') |
Bram Moolenaar | 379fb76 | 2018-08-30 15:58:28 +0200 | [diff] [blame] | 3447 | augroup END |
| 3448 | copen |
| 3449 | augroup QF_Test |
| 3450 | au! |
| 3451 | augroup END |
| 3452 | cclose |
| 3453 | |
| 3454 | augroup! QF_Test |
Bram Moolenaar | 6a0cc91 | 2019-10-26 16:48:44 +0200 | [diff] [blame] | 3455 | endfunc |
Bram Moolenaar | 379fb76 | 2018-08-30 15:58:28 +0200 | [diff] [blame] | 3456 | |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3457 | func Test_resize_from_copen() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3458 | augroup QF_Test |
| 3459 | au! |
| 3460 | au FileType qf resize 5 |
| 3461 | augroup END |
| 3462 | try |
| 3463 | " This should succeed without any exception. No other buffers are |
| 3464 | " involved in the autocmd. |
| 3465 | copen |
| 3466 | finally |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3467 | augroup QF_Test |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3468 | au! |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3469 | augroup END |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3470 | augroup! QF_Test |
| 3471 | endtry |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 3472 | endfunc |
Bram Moolenaar | a8788f4 | 2017-07-19 17:06:20 +0200 | [diff] [blame] | 3473 | |
Bram Moolenaar | 33aecb1 | 2020-11-14 17:25:51 +0100 | [diff] [blame] | 3474 | func Test_vimgrep_with_textlock() |
| 3475 | new |
| 3476 | |
| 3477 | " Simple way to execute something with "textwinlock" set. |
| 3478 | " Check that vimgrep without jumping can be executed. |
| 3479 | au InsertCharPre * vimgrep /RunTheTest/j runtest.vim |
| 3480 | normal ax |
| 3481 | let qflist = getqflist() |
| 3482 | call assert_true(len(qflist) > 0) |
| 3483 | call assert_match('RunTheTest', qflist[0].text) |
| 3484 | call setqflist([], 'r') |
| 3485 | au! InsertCharPre |
| 3486 | |
| 3487 | " Check that vimgrepadd without jumping can be executed. |
| 3488 | au InsertCharPre * vimgrepadd /RunTheTest/j runtest.vim |
| 3489 | normal ax |
| 3490 | let qflist = getqflist() |
| 3491 | call assert_true(len(qflist) > 0) |
| 3492 | call assert_match('RunTheTest', qflist[0].text) |
| 3493 | call setqflist([], 'r') |
| 3494 | au! InsertCharPre |
| 3495 | |
| 3496 | " Check that lvimgrep without jumping can be executed. |
| 3497 | au InsertCharPre * lvimgrep /RunTheTest/j runtest.vim |
| 3498 | normal ax |
| 3499 | let qflist = getloclist(0) |
| 3500 | call assert_true(len(qflist) > 0) |
| 3501 | call assert_match('RunTheTest', qflist[0].text) |
| 3502 | call setloclist(0, [], 'r') |
| 3503 | au! InsertCharPre |
| 3504 | |
| 3505 | " Check that lvimgrepadd without jumping can be executed. |
| 3506 | au InsertCharPre * lvimgrepadd /RunTheTest/j runtest.vim |
| 3507 | normal ax |
| 3508 | let qflist = getloclist(0) |
| 3509 | call assert_true(len(qflist) > 0) |
| 3510 | call assert_match('RunTheTest', qflist[0].text) |
| 3511 | call setloclist(0, [], 'r') |
| 3512 | au! InsertCharPre |
| 3513 | |
| 3514 | " trying to jump will give an error |
| 3515 | au InsertCharPre * vimgrep /RunTheTest/ runtest.vim |
| 3516 | call assert_fails('normal ax', 'E565:') |
| 3517 | au! InsertCharPre |
| 3518 | |
| 3519 | au InsertCharPre * vimgrepadd /RunTheTest/ runtest.vim |
| 3520 | call assert_fails('normal ax', 'E565:') |
| 3521 | au! InsertCharPre |
| 3522 | |
| 3523 | au InsertCharPre * lvimgrep /RunTheTest/ runtest.vim |
| 3524 | call assert_fails('normal ax', 'E565:') |
| 3525 | au! InsertCharPre |
| 3526 | |
| 3527 | au InsertCharPre * lvimgrepadd /RunTheTest/ runtest.vim |
| 3528 | call assert_fails('normal ax', 'E565:') |
| 3529 | au! InsertCharPre |
| 3530 | |
| 3531 | bwipe! |
| 3532 | endfunc |
| 3533 | |
Bram Moolenaar | a8788f4 | 2017-07-19 17:06:20 +0200 | [diff] [blame] | 3534 | " Tests for the quickfix buffer b:changedtick variable |
| 3535 | func Xchangedtick_tests(cchar) |
| 3536 | call s:setup_commands(a:cchar) |
| 3537 | |
| 3538 | new | only |
| 3539 | |
| 3540 | Xexpr "" | Xexpr "" | Xexpr "" |
| 3541 | |
| 3542 | Xopen |
| 3543 | Xolder |
| 3544 | Xolder |
| 3545 | Xaddexpr "F1:10:Line10" |
| 3546 | Xaddexpr "F2:20:Line20" |
| 3547 | call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a') |
| 3548 | call g:Xsetlist([], 'f') |
| 3549 | call assert_equal(8, getbufvar('%', 'changedtick')) |
| 3550 | Xclose |
| 3551 | endfunc |
| 3552 | |
| 3553 | func Test_changedtick() |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3554 | call Xchangedtick_tests('c') |
| 3555 | call Xchangedtick_tests('l') |
| 3556 | endfunc |
| 3557 | |
| 3558 | " Tests for parsing an expression using setqflist() |
| 3559 | func Xsetexpr_tests(cchar) |
| 3560 | call s:setup_commands(a:cchar) |
| 3561 | |
| 3562 | let t = ["File1:10:Line10", "File1:20:Line20"] |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3563 | call g:Xsetlist([], ' ', {'lines' : t}) |
| 3564 | call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3565 | |
| 3566 | let l = g:Xgetlist() |
| 3567 | call assert_equal(3, len(l)) |
| 3568 | call assert_equal(20, l[1].lnum) |
| 3569 | call assert_equal('Line30', l[2].text) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3570 | call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3571 | let l = g:Xgetlist() |
| 3572 | call assert_equal(1, len(l)) |
| 3573 | call assert_equal('Line5', l[0].text) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3574 | call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10})) |
| 3575 | call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"})) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3576 | |
| 3577 | call g:Xsetlist([], 'f') |
| 3578 | " Add entries to multiple lists |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3579 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]}) |
| 3580 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]}) |
| 3581 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]}) |
| 3582 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3583 | call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text) |
| 3584 | call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text) |
Bram Moolenaar | 3653822 | 2017-09-02 19:51:44 +0200 | [diff] [blame] | 3585 | |
| 3586 | " Adding entries using a custom efm |
| 3587 | set efm& |
| 3588 | call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m', |
| 3589 | \ 'lines' : ["F1#10#L10", "F2#20#L20"]}) |
| 3590 | call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) |
| 3591 | call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]}) |
| 3592 | call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text) |
| 3593 | call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) |
| 3594 | call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [], |
| 3595 | \ 'lines' : ['F1:10:L10']})) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3596 | endfunc |
| 3597 | |
| 3598 | func Test_setexpr() |
| 3599 | call Xsetexpr_tests('c') |
| 3600 | call Xsetexpr_tests('l') |
| 3601 | endfunc |
| 3602 | |
| 3603 | " Tests for per quickfix/location list directory stack |
| 3604 | func Xmultidirstack_tests(cchar) |
| 3605 | call s:setup_commands(a:cchar) |
| 3606 | |
| 3607 | call g:Xsetlist([], 'f') |
| 3608 | Xexpr "" | Xexpr "" |
| 3609 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3610 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]}) |
| 3611 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]}) |
| 3612 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]}) |
| 3613 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3614 | |
| 3615 | let l1 = g:Xgetlist({'nr':1, 'items':1}) |
| 3616 | let l2 = g:Xgetlist({'nr':2, 'items':1}) |
| 3617 | call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr)) |
| 3618 | call assert_equal(3, l1.items[1].lnum) |
| 3619 | call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr)) |
| 3620 | call assert_equal(5, l2.items[1].lnum) |
| 3621 | endfunc |
| 3622 | |
| 3623 | func Test_multidirstack() |
| 3624 | call mkdir('Xone/a', 'p') |
| 3625 | call mkdir('Xtwo/a', 'p') |
| 3626 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 3627 | call writefile(lines, 'Xone/a/one.txt') |
| 3628 | call writefile(lines, 'Xtwo/a/two.txt') |
| 3629 | let save_efm = &efm |
| 3630 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 3631 | |
| 3632 | call Xmultidirstack_tests('c') |
| 3633 | call Xmultidirstack_tests('l') |
| 3634 | |
| 3635 | let &efm = save_efm |
| 3636 | call delete('Xone', 'rf') |
| 3637 | call delete('Xtwo', 'rf') |
| 3638 | endfunc |
| 3639 | |
| 3640 | " Tests for per quickfix/location list file stack |
| 3641 | func Xmultifilestack_tests(cchar) |
| 3642 | call s:setup_commands(a:cchar) |
| 3643 | |
| 3644 | call g:Xsetlist([], 'f') |
| 3645 | Xexpr "" | Xexpr "" |
| 3646 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3647 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]}) |
| 3648 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]}) |
| 3649 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]}) |
| 3650 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3651 | |
| 3652 | let l1 = g:Xgetlist({'nr':1, 'items':1}) |
| 3653 | let l2 = g:Xgetlist({'nr':2, 'items':1}) |
| 3654 | call assert_equal('one.txt', bufname(l1.items[1].bufnr)) |
| 3655 | call assert_equal(3, l1.items[1].lnum) |
| 3656 | call assert_equal('two.txt', bufname(l2.items[1].bufnr)) |
| 3657 | call assert_equal(5, l2.items[1].lnum) |
Bram Moolenaar | e333e79 | 2018-04-08 13:27:39 +0200 | [diff] [blame] | 3658 | |
| 3659 | " Test for start of a new error line in the same line where a previous |
| 3660 | " error line ends with a file stack. |
| 3661 | let efm_val = 'Error\ l%l\ in\ %f,' |
| 3662 | let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r' |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 3663 | let lines =<< trim END |
| 3664 | (one.txt |
| 3665 | Error l4 in one.txt |
| 3666 | ) (two.txt |
| 3667 | Error l6 in two.txt |
| 3668 | ) |
| 3669 | Error l8 in one.txt |
| 3670 | END |
| 3671 | let l = g:Xgetlist({'lines': lines, 'efm' : efm_val}) |
Bram Moolenaar | e333e79 | 2018-04-08 13:27:39 +0200 | [diff] [blame] | 3672 | call assert_equal(3, len(l.items)) |
| 3673 | call assert_equal('one.txt', bufname(l.items[0].bufnr)) |
| 3674 | call assert_equal(4, l.items[0].lnum) |
| 3675 | call assert_equal('one.txt', l.items[0].text) |
| 3676 | call assert_equal('two.txt', bufname(l.items[1].bufnr)) |
| 3677 | call assert_equal(6, l.items[1].lnum) |
| 3678 | call assert_equal('two.txt', l.items[1].text) |
| 3679 | call assert_equal('one.txt', bufname(l.items[2].bufnr)) |
| 3680 | call assert_equal(8, l.items[2].lnum) |
| 3681 | call assert_equal('', l.items[2].text) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 3682 | endfunc |
| 3683 | |
| 3684 | func Test_multifilestack() |
| 3685 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 3686 | call writefile(lines, 'one.txt') |
| 3687 | call writefile(lines, 'two.txt') |
| 3688 | let save_efm = &efm |
| 3689 | set efm=%+P[%f],(%l\\,%c)\ %m,%-Q |
| 3690 | |
| 3691 | call Xmultifilestack_tests('c') |
| 3692 | call Xmultifilestack_tests('l') |
| 3693 | |
| 3694 | let &efm = save_efm |
| 3695 | call delete('one.txt') |
| 3696 | call delete('two.txt') |
| 3697 | endfunc |
| 3698 | |
| 3699 | " Tests for per buffer 'efm' setting |
| 3700 | func Test_perbuf_efm() |
| 3701 | call writefile(["File1-10-Line10"], 'one.txt') |
| 3702 | call writefile(["File2#20#Line20"], 'two.txt') |
| 3703 | set efm=%f#%l#%m |
| 3704 | new | only |
| 3705 | new |
| 3706 | setlocal efm=%f-%l-%m |
| 3707 | cfile one.txt |
| 3708 | wincmd w |
| 3709 | caddfile two.txt |
| 3710 | |
| 3711 | let l = getqflist() |
| 3712 | call assert_equal(10, l[0].lnum) |
| 3713 | call assert_equal('Line20', l[1].text) |
| 3714 | |
| 3715 | set efm& |
| 3716 | new | only |
| 3717 | call delete('one.txt') |
| 3718 | call delete('two.txt') |
Bram Moolenaar | a8788f4 | 2017-07-19 17:06:20 +0200 | [diff] [blame] | 3719 | endfunc |
Bram Moolenaar | d28cc3f | 2017-07-27 22:03:50 +0200 | [diff] [blame] | 3720 | |
| 3721 | " Open multiple help windows using ":lhelpgrep |
| 3722 | " This test used to crash Vim |
| 3723 | func Test_Multi_LL_Help() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3724 | new | only |
| 3725 | lhelpgrep window |
| 3726 | lopen |
| 3727 | e# |
| 3728 | lhelpgrep buffer |
| 3729 | call assert_equal(3, winnr('$')) |
| 3730 | call assert_true(len(getloclist(1)) != 0) |
| 3731 | call assert_true(len(getloclist(2)) != 0) |
| 3732 | new | only |
Bram Moolenaar | d28cc3f | 2017-07-27 22:03:50 +0200 | [diff] [blame] | 3733 | endfunc |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 3734 | |
| 3735 | " Tests for adding new quickfix lists using setqflist() |
| 3736 | func XaddQf_tests(cchar) |
| 3737 | call s:setup_commands(a:cchar) |
| 3738 | |
| 3739 | " Create a new list using ' ' for action |
| 3740 | call g:Xsetlist([], 'f') |
| 3741 | call g:Xsetlist([], ' ', {'title' : 'Test1'}) |
| 3742 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3743 | call assert_equal(1, l.nr) |
| 3744 | call assert_equal('Test1', l.title) |
| 3745 | |
| 3746 | " Create a new list using ' ' for action and '$' for 'nr' |
| 3747 | call g:Xsetlist([], 'f') |
| 3748 | call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'}) |
| 3749 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3750 | call assert_equal(1, l.nr) |
| 3751 | call assert_equal('Test2', l.title) |
| 3752 | |
| 3753 | " Create a new list using 'a' for action |
| 3754 | call g:Xsetlist([], 'f') |
| 3755 | call g:Xsetlist([], 'a', {'title' : 'Test3'}) |
| 3756 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3757 | call assert_equal(1, l.nr) |
| 3758 | call assert_equal('Test3', l.title) |
| 3759 | |
| 3760 | " Create a new list using 'a' for action and '$' for 'nr' |
| 3761 | call g:Xsetlist([], 'f') |
| 3762 | call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'}) |
| 3763 | call g:Xsetlist([], 'a', {'title' : 'Test4'}) |
| 3764 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3765 | call assert_equal(1, l.nr) |
| 3766 | call assert_equal('Test4', l.title) |
| 3767 | |
| 3768 | " Adding a quickfix list should remove all the lists following the current |
| 3769 | " list. |
| 3770 | Xexpr "" | Xexpr "" | Xexpr "" |
| 3771 | silent! 10Xolder |
| 3772 | call g:Xsetlist([], ' ', {'title' : 'Test5'}) |
| 3773 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3774 | call assert_equal(2, l.nr) |
| 3775 | call assert_equal('Test5', l.title) |
| 3776 | |
| 3777 | " Add a quickfix list using '$' as the list number. |
| 3778 | let lastqf = g:Xgetlist({'nr':'$'}).nr |
| 3779 | silent! 99Xolder |
| 3780 | call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'}) |
| 3781 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3782 | call assert_equal(lastqf + 1, l.nr) |
| 3783 | call assert_equal('Test6', l.title) |
| 3784 | |
| 3785 | " Add a quickfix list using 'nr' set to one more than the quickfix |
| 3786 | " list size. |
| 3787 | let lastqf = g:Xgetlist({'nr':'$'}).nr |
| 3788 | silent! 99Xolder |
| 3789 | call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'}) |
| 3790 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3791 | call assert_equal(lastqf + 1, l.nr) |
| 3792 | call assert_equal('Test7', l.title) |
| 3793 | |
| 3794 | " Add a quickfix list to a stack with 10 lists using 'nr' set to '$' |
| 3795 | exe repeat('Xexpr "" |', 9) . 'Xexpr ""' |
| 3796 | silent! 99Xolder |
| 3797 | call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'}) |
| 3798 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 3799 | call assert_equal(10, l.nr) |
| 3800 | call assert_equal('Test8', l.title) |
| 3801 | |
| 3802 | " Add a quickfix list using 'nr' set to a value greater than 10 |
| 3803 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'})) |
| 3804 | |
| 3805 | " Try adding a quickfix list with 'nr' set to a value greater than the |
| 3806 | " quickfix list size but less than 10. |
| 3807 | call g:Xsetlist([], 'f') |
| 3808 | Xexpr "" | Xexpr "" | Xexpr "" |
| 3809 | silent! 99Xolder |
| 3810 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'})) |
| 3811 | |
| 3812 | " Add a quickfix list using 'nr' set to a some string or list |
| 3813 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'})) |
| 3814 | endfunc |
| 3815 | |
| 3816 | func Test_add_qf() |
| 3817 | call XaddQf_tests('c') |
| 3818 | call XaddQf_tests('l') |
| 3819 | endfunc |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3820 | |
| 3821 | " Test for getting the quickfix list items from some text without modifying |
| 3822 | " the quickfix stack |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3823 | func XgetListFromLines(cchar) |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3824 | call s:setup_commands(a:cchar) |
| 3825 | call g:Xsetlist([], 'f') |
| 3826 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3827 | let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3828 | call assert_equal(2, len(l)) |
| 3829 | call assert_equal(30, l[1].lnum) |
| 3830 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3831 | call assert_equal({}, g:Xgetlist({'lines' : 10})) |
| 3832 | call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'})) |
| 3833 | call assert_equal([], g:Xgetlist({'lines' : []}).items) |
| 3834 | call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items) |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3835 | |
Bram Moolenaar | 3653822 | 2017-09-02 19:51:44 +0200 | [diff] [blame] | 3836 | " Parse text using a custom efm |
| 3837 | set efm& |
| 3838 | let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items |
| 3839 | call assert_equal('Line30', l[0].text) |
| 3840 | let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items |
| 3841 | call assert_equal('File3:30:Line30', l[0].text) |
| 3842 | let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]}) |
| 3843 | call assert_equal({}, l) |
| 3844 | call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:') |
| 3845 | call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:') |
| 3846 | |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3847 | " Make sure that the quickfix stack is not modified |
| 3848 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 3849 | endfunc |
| 3850 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3851 | func Test_get_list_from_lines() |
| 3852 | call XgetListFromLines('c') |
| 3853 | call XgetListFromLines('l') |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 3854 | endfunc |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3855 | |
| 3856 | " Tests for the quickfix list id |
| 3857 | func Xqfid_tests(cchar) |
| 3858 | call s:setup_commands(a:cchar) |
| 3859 | |
| 3860 | call g:Xsetlist([], 'f') |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3861 | call assert_equal(0, g:Xgetlist({'id':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3862 | Xexpr '' |
| 3863 | let start_id = g:Xgetlist({'id' : 0}).id |
| 3864 | Xexpr '' | Xexpr '' |
| 3865 | Xolder |
| 3866 | call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id) |
| 3867 | call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id) |
| 3868 | call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3869 | call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3870 | call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3871 | call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id) |
| 3872 | call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3873 | |
| 3874 | call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]}) |
| 3875 | call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3876 | call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']}) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3877 | call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text) |
| 3878 | call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'})) |
| 3879 | call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'})) |
| 3880 | |
| 3881 | let qfid = g:Xgetlist({'id':0, 'nr':0}) |
| 3882 | call g:Xsetlist([], 'f') |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3883 | call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3884 | endfunc |
| 3885 | |
| 3886 | func Test_qf_id() |
| 3887 | call Xqfid_tests('c') |
| 3888 | call Xqfid_tests('l') |
| 3889 | endfunc |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 3890 | |
| 3891 | func Xqfjump_tests(cchar) |
| 3892 | call s:setup_commands(a:cchar) |
| 3893 | |
| 3894 | call writefile(["Line1\tFoo", "Line2"], 'F1') |
| 3895 | call writefile(["Line1\tBar", "Line2"], 'F2') |
| 3896 | call writefile(["Line1\tBaz", "Line2"], 'F3') |
| 3897 | |
| 3898 | call g:Xsetlist([], 'f') |
| 3899 | |
| 3900 | " Tests for |
| 3901 | " Jumping to a line using a pattern |
| 3902 | " Jumping to a column greater than the last column in a line |
| 3903 | " Jumping to a line greater than the last line in the file |
| 3904 | let l = [] |
| 3905 | for i in range(1, 7) |
| 3906 | call add(l, {}) |
| 3907 | endfor |
| 3908 | let l[0].filename='F1' |
| 3909 | let l[0].pattern='Line1' |
| 3910 | let l[1].filename='F2' |
| 3911 | let l[1].pattern='Line1' |
| 3912 | let l[2].filename='F3' |
| 3913 | let l[2].pattern='Line1' |
| 3914 | let l[3].filename='F3' |
| 3915 | let l[3].lnum=1 |
| 3916 | let l[3].col=9 |
| 3917 | let l[3].vcol=1 |
| 3918 | let l[4].filename='F3' |
| 3919 | let l[4].lnum=99 |
| 3920 | let l[5].filename='F3' |
| 3921 | let l[5].lnum=1 |
| 3922 | let l[5].col=99 |
| 3923 | let l[5].vcol=1 |
| 3924 | let l[6].filename='F3' |
| 3925 | let l[6].pattern='abcxyz' |
| 3926 | |
| 3927 | call g:Xsetlist([], ' ', {'items' : l}) |
| 3928 | Xopen | only |
| 3929 | 2Xnext |
| 3930 | call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 3931 | call assert_equal('F3', @%) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 3932 | Xnext |
| 3933 | call assert_equal(7, col('.')) |
| 3934 | Xnext |
| 3935 | call assert_equal(2, line('.')) |
| 3936 | Xnext |
| 3937 | call assert_equal(9, col('.')) |
| 3938 | 2 |
| 3939 | Xnext |
| 3940 | call assert_equal(2, line('.')) |
| 3941 | |
| 3942 | if a:cchar == 'l' |
| 3943 | " When jumping to a location list entry in the location list window and |
| 3944 | " no usable windows are available, then a new window should be opened. |
| 3945 | enew! | new | only |
| 3946 | call g:Xsetlist([], 'f') |
| 3947 | setlocal buftype=nofile |
| 3948 | new |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 3949 | let lines =<< trim END |
| 3950 | F1:1:1:Line1 |
| 3951 | F1:2:2:Line2 |
| 3952 | F2:1:1:Line1 |
| 3953 | F2:2:2:Line2 |
| 3954 | F3:1:1:Line1 |
| 3955 | F3:2:2:Line2 |
| 3956 | END |
| 3957 | call g:Xsetlist([], ' ', {'lines': lines}) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 3958 | Xopen |
| 3959 | let winid = win_getid() |
| 3960 | wincmd p |
| 3961 | close |
| 3962 | call win_gotoid(winid) |
| 3963 | Xnext |
| 3964 | call assert_equal(3, winnr('$')) |
| 3965 | call assert_equal(1, winnr()) |
| 3966 | call assert_equal(2, line('.')) |
| 3967 | |
| 3968 | " When jumping to an entry in the location list window and the window |
| 3969 | " associated with the location list is not present and a window containing |
| 3970 | " the file is already present, then that window should be used. |
| 3971 | close |
| 3972 | belowright new |
| 3973 | call g:Xsetlist([], 'f') |
| 3974 | edit F3 |
| 3975 | call win_gotoid(winid) |
| 3976 | Xlast |
| 3977 | call assert_equal(3, winnr()) |
| 3978 | call assert_equal(6, g:Xgetlist({'size' : 1}).size) |
| 3979 | call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid) |
| 3980 | endif |
| 3981 | |
| 3982 | " Cleanup |
| 3983 | enew! |
| 3984 | new | only |
| 3985 | |
| 3986 | call delete('F1') |
| 3987 | call delete('F2') |
| 3988 | call delete('F3') |
| 3989 | endfunc |
| 3990 | |
| 3991 | func Test_qfjump() |
| 3992 | call Xqfjump_tests('c') |
| 3993 | call Xqfjump_tests('l') |
| 3994 | endfunc |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3995 | |
| 3996 | " Tests for the getqflist() and getloclist() functions when the list is not |
| 3997 | " present or is empty |
| 3998 | func Xgetlist_empty_tests(cchar) |
| 3999 | call s:setup_commands(a:cchar) |
| 4000 | |
| 4001 | " Empty quickfix stack |
| 4002 | call g:Xsetlist([], 'f') |
| 4003 | call assert_equal('', g:Xgetlist({'context' : 0}).context) |
| 4004 | call assert_equal(0, g:Xgetlist({'id' : 0}).id) |
| 4005 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 4006 | call assert_equal([], g:Xgetlist({'items' : 0}).items) |
| 4007 | call assert_equal(0, g:Xgetlist({'nr' : 0}).nr) |
| 4008 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
| 4009 | call assert_equal('', g:Xgetlist({'title' : 0}).title) |
| 4010 | call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4011 | call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4012 | if a:cchar == 'c' |
| 4013 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 4014 | \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4015 | \ 'title' : '', 'winid' : 0, 'changedtick': 0, |
| 4016 | \ 'quickfixtextfunc' : ''}, g:Xgetlist({'all' : 0})) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4017 | else |
| 4018 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
| 4019 | \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 4020 | \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4021 | \ 'qfbufnr' : 0, 'quickfixtextfunc' : ''}, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4022 | \ g:Xgetlist({'all' : 0})) |
| 4023 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 4024 | |
Bram Moolenaar | 2ec364e | 2018-01-27 11:52:13 +0100 | [diff] [blame] | 4025 | " Quickfix window with empty stack |
| 4026 | silent! Xopen |
| 4027 | let qfwinid = (a:cchar == 'c') ? win_getid() : 0 |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 4028 | let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0 |
Bram Moolenaar | 2ec364e | 2018-01-27 11:52:13 +0100 | [diff] [blame] | 4029 | call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid) |
| 4030 | Xclose |
| 4031 | |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 4032 | " Empty quickfix list |
| 4033 | Xexpr "" |
| 4034 | call assert_equal('', g:Xgetlist({'context' : 0}).context) |
| 4035 | call assert_notequal(0, g:Xgetlist({'id' : 0}).id) |
| 4036 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 4037 | call assert_equal([], g:Xgetlist({'items' : 0}).items) |
| 4038 | call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr) |
| 4039 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
| 4040 | call assert_notequal('', g:Xgetlist({'title' : 0}).title) |
| 4041 | call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4042 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 4043 | |
| 4044 | let qfid = g:Xgetlist({'id' : 0}).id |
| 4045 | call g:Xsetlist([], 'f') |
| 4046 | |
| 4047 | " Non-existing quickfix identifier |
| 4048 | call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context) |
| 4049 | call assert_equal(0, g:Xgetlist({'id' : qfid}).id) |
| 4050 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx) |
| 4051 | call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items) |
| 4052 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr) |
| 4053 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size) |
| 4054 | call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title) |
| 4055 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4056 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4057 | if a:cchar == 'c' |
| 4058 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 4059 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4060 | \ 'qfbufnr' : qfbufnr, 'quickfixtextfunc' : '', |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4061 | \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0})) |
| 4062 | else |
| 4063 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 4064 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4065 | \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0, |
| 4066 | \ 'quickfixtextfunc' : ''}, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4067 | \ g:Xgetlist({'id' : qfid, 'all' : 0})) |
| 4068 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 4069 | |
| 4070 | " Non-existing quickfix list number |
| 4071 | call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context) |
| 4072 | call assert_equal(0, g:Xgetlist({'nr' : 5}).nr) |
| 4073 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx) |
| 4074 | call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items) |
| 4075 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id) |
| 4076 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size) |
| 4077 | call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title) |
| 4078 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4079 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4080 | if a:cchar == 'c' |
| 4081 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 4082 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4083 | \ 'changedtick' : 0, 'qfbufnr' : qfbufnr, |
| 4084 | \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0})) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4085 | else |
| 4086 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 4087 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 4088 | \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0, |
| 4089 | \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0})) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 4090 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 4091 | endfunc |
| 4092 | |
| 4093 | func Test_getqflist() |
| 4094 | call Xgetlist_empty_tests('c') |
| 4095 | call Xgetlist_empty_tests('l') |
| 4096 | endfunc |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4097 | |
Bram Moolenaar | a0ca7d0 | 2017-12-19 10:22:19 +0100 | [diff] [blame] | 4098 | func Test_getqflist_invalid_nr() |
| 4099 | " The following commands used to crash Vim |
| 4100 | cexpr "" |
| 4101 | call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX}) |
| 4102 | |
| 4103 | " Cleanup |
| 4104 | call setqflist([], 'r') |
| 4105 | endfunc |
| 4106 | |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 4107 | " Tests for the quickfix/location list changedtick |
| 4108 | func Xqftick_tests(cchar) |
| 4109 | call s:setup_commands(a:cchar) |
| 4110 | |
| 4111 | call g:Xsetlist([], 'f') |
| 4112 | |
| 4113 | Xexpr "F1:10:Line10" |
| 4114 | let qfid = g:Xgetlist({'id' : 0}).id |
| 4115 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4116 | Xaddexpr "F2:20:Line20\nF2:21:Line21" |
| 4117 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4118 | call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]}) |
| 4119 | call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4120 | call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]}) |
| 4121 | call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4122 | call g:Xsetlist([], 'a', {'title' : 'New Title'}) |
| 4123 | call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4124 | |
| 4125 | enew! |
| 4126 | call append(0, ["F5:50:L50", "F6:60:L60"]) |
| 4127 | Xaddbuffer |
| 4128 | call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4129 | enew! |
| 4130 | |
| 4131 | call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}}) |
| 4132 | call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4133 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 4134 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a') |
| 4135 | call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4136 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 4137 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ') |
| 4138 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4139 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 4140 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r') |
| 4141 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4142 | |
| 4143 | call writefile(["F8:80:L80", "F8:81:L81"], "Xone") |
| 4144 | Xfile Xone |
| 4145 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4146 | Xaddfile Xone |
| 4147 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4148 | |
| 4149 | " Test case for updating a non-current quickfix list |
| 4150 | call g:Xsetlist([], 'f') |
| 4151 | Xexpr "F1:1:L1" |
| 4152 | Xexpr "F2:2:L2" |
| 4153 | call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]}) |
| 4154 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 4155 | call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick) |
| 4156 | |
| 4157 | call delete("Xone") |
| 4158 | endfunc |
| 4159 | |
| 4160 | func Test_qf_tick() |
| 4161 | call Xqftick_tests('c') |
| 4162 | call Xqftick_tests('l') |
| 4163 | endfunc |
Bram Moolenaar | 1223744 | 2017-12-19 12:38:52 +0100 | [diff] [blame] | 4164 | |
Bram Moolenaar | c631f2d | 2018-08-21 21:58:13 +0200 | [diff] [blame] | 4165 | " Test helpgrep with lang specifier |
| 4166 | func Xtest_helpgrep_with_lang_specifier(cchar) |
| 4167 | call s:setup_commands(a:cchar) |
| 4168 | Xhelpgrep Vim@en |
| 4169 | call assert_equal('help', &filetype) |
| 4170 | call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 4171 | new | only |
| 4172 | endfunc |
| 4173 | |
| 4174 | func Test_helpgrep_with_lang_specifier() |
| 4175 | call Xtest_helpgrep_with_lang_specifier('c') |
| 4176 | call Xtest_helpgrep_with_lang_specifier('l') |
| 4177 | endfunc |
| 4178 | |
Bram Moolenaar | 1223744 | 2017-12-19 12:38:52 +0100 | [diff] [blame] | 4179 | " The following test used to crash Vim. |
| 4180 | " Open the location list window and close the regular window associated with |
| 4181 | " the location list. When the garbage collection runs now, it incorrectly |
| 4182 | " marks the location list context as not in use and frees the context. |
| 4183 | func Test_ll_window_ctx() |
| 4184 | call setloclist(0, [], 'f') |
| 4185 | call setloclist(0, [], 'a', {'context' : []}) |
| 4186 | lopen | only |
| 4187 | call test_garbagecollect_now() |
| 4188 | echo getloclist(0, {'context' : 1}).context |
| 4189 | enew | only |
| 4190 | endfunc |
| 4191 | |
Bram Moolenaar | 14a4deb | 2017-12-19 16:48:55 +0100 | [diff] [blame] | 4192 | " The following test used to crash vim |
| 4193 | func Test_lfile_crash() |
| 4194 | sp Xtest |
| 4195 | au QuickFixCmdPre * bw |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 4196 | call assert_fails('lfile', 'E40:') |
Bram Moolenaar | 14a4deb | 2017-12-19 16:48:55 +0100 | [diff] [blame] | 4197 | au! QuickFixCmdPre |
| 4198 | endfunc |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4199 | |
| 4200 | " The following test used to crash vim |
| 4201 | func Test_lbuffer_crash() |
| 4202 | sv Xtest |
| 4203 | augroup QF_Test |
| 4204 | au! |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4205 | au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * bw |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4206 | augroup END |
| 4207 | lbuffer |
| 4208 | augroup QF_Test |
| 4209 | au! |
| 4210 | augroup END |
| 4211 | endfunc |
| 4212 | |
| 4213 | " The following test used to crash vim |
| 4214 | func Test_lexpr_crash() |
| 4215 | augroup QF_Test |
| 4216 | au! |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4217 | au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call setloclist(0, [], 'f') |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4218 | augroup END |
| 4219 | lexpr "" |
| 4220 | augroup QF_Test |
| 4221 | au! |
| 4222 | augroup END |
Bram Moolenaar | 9f84ded | 2018-10-20 20:54:02 +0200 | [diff] [blame] | 4223 | |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4224 | enew | only |
Bram Moolenaar | 9f84ded | 2018-10-20 20:54:02 +0200 | [diff] [blame] | 4225 | augroup QF_Test |
| 4226 | au! |
| 4227 | au BufNew * call setloclist(0, [], 'f') |
| 4228 | augroup END |
| 4229 | lexpr 'x:1:x' |
| 4230 | augroup QF_Test |
| 4231 | au! |
| 4232 | augroup END |
| 4233 | |
| 4234 | enew | only |
| 4235 | lexpr '' |
| 4236 | lopen |
| 4237 | augroup QF_Test |
| 4238 | au! |
| 4239 | au FileType * call setloclist(0, [], 'f') |
| 4240 | augroup END |
| 4241 | lexpr '' |
| 4242 | augroup QF_Test |
| 4243 | au! |
| 4244 | augroup END |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4245 | endfunc |
| 4246 | |
| 4247 | " The following test used to crash Vim |
| 4248 | func Test_lvimgrep_crash() |
| 4249 | sv Xtest |
| 4250 | augroup QF_Test |
| 4251 | au! |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4252 | au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call setloclist(0, [], 'f') |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4253 | augroup END |
| 4254 | lvimgrep quickfix test_quickfix.vim |
| 4255 | augroup QF_Test |
| 4256 | au! |
| 4257 | augroup END |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4258 | |
| 4259 | new | only |
| 4260 | augroup QF_Test |
| 4261 | au! |
| 4262 | au BufEnter * call setloclist(0, [], 'r') |
| 4263 | augroup END |
| 4264 | call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:') |
| 4265 | augroup QF_Test |
| 4266 | au! |
| 4267 | augroup END |
| 4268 | |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 4269 | enew | only |
| 4270 | endfunc |
Bram Moolenaar | de04654 | 2017-12-26 13:53:11 +0100 | [diff] [blame] | 4271 | |
Bram Moolenaar | 2573af3 | 2020-03-14 17:21:34 +0100 | [diff] [blame] | 4272 | func Test_lvimgrep_crash2() |
| 4273 | au BufNewFile x sfind |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 4274 | call assert_fails('lvimgrep x x', 'E471:') |
| 4275 | call assert_fails('lvimgrep x x x', 'E471:') |
Bram Moolenaar | 2573af3 | 2020-03-14 17:21:34 +0100 | [diff] [blame] | 4276 | |
| 4277 | au! BufNewFile |
| 4278 | endfunc |
| 4279 | |
Bram Moolenaar | de04654 | 2017-12-26 13:53:11 +0100 | [diff] [blame] | 4280 | " Test for the position of the quickfix and location list window |
| 4281 | func Test_qfwin_pos() |
| 4282 | " Open two windows |
| 4283 | new | only |
| 4284 | new |
| 4285 | cexpr ['F1:10:L10'] |
| 4286 | copen |
| 4287 | " Quickfix window should be the bottom most window |
| 4288 | call assert_equal(3, winnr()) |
| 4289 | close |
| 4290 | " Open at the very top |
| 4291 | wincmd t |
| 4292 | topleft copen |
| 4293 | call assert_equal(1, winnr()) |
| 4294 | close |
| 4295 | " open left of the current window |
| 4296 | wincmd t |
| 4297 | below new |
| 4298 | leftabove copen |
| 4299 | call assert_equal(2, winnr()) |
| 4300 | close |
| 4301 | " open right of the current window |
| 4302 | rightbelow copen |
| 4303 | call assert_equal(3, winnr()) |
| 4304 | close |
| 4305 | endfunc |
Bram Moolenaar | e1bb879 | 2018-04-06 22:58:23 +0200 | [diff] [blame] | 4306 | |
| 4307 | " Tests for quickfix/location lists changed by autocommands when |
| 4308 | " :vimgrep/:lvimgrep commands are running. |
| 4309 | func Test_vimgrep_autocmd() |
| 4310 | call setqflist([], 'f') |
| 4311 | call writefile(['stars'], 'Xtest1.txt') |
| 4312 | call writefile(['stars'], 'Xtest2.txt') |
| 4313 | |
| 4314 | " Test 1: |
| 4315 | " When searching for a pattern using :vimgrep, if the quickfix list is |
| 4316 | " changed by an autocmd, the results should be added to the correct quickfix |
| 4317 | " list. |
| 4318 | autocmd BufRead Xtest2.txt cexpr '' | cexpr '' |
| 4319 | silent vimgrep stars Xtest*.txt |
| 4320 | call assert_equal(1, getqflist({'nr' : 0}).nr) |
| 4321 | call assert_equal(3, getqflist({'nr' : '$'}).nr) |
| 4322 | call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr)) |
| 4323 | au! BufRead Xtest2.txt |
| 4324 | |
| 4325 | " Test 2: |
| 4326 | " When searching for a pattern using :vimgrep, if the quickfix list is |
| 4327 | " freed, then a error should be given. |
| 4328 | silent! %bwipe! |
| 4329 | call setqflist([], 'f') |
| 4330 | autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor |
| 4331 | call assert_fails('vimgrep stars Xtest*.txt', 'E925:') |
| 4332 | au! BufRead Xtest2.txt |
| 4333 | |
| 4334 | " Test 3: |
| 4335 | " When searching for a pattern using :lvimgrep, if the location list is |
| 4336 | " freed, then the command should error out. |
| 4337 | silent! %bwipe! |
| 4338 | let g:save_winid = win_getid() |
| 4339 | autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f') |
| 4340 | call assert_fails('lvimgrep stars Xtest*.txt', 'E926:') |
| 4341 | au! BufRead Xtest2.txt |
| 4342 | |
| 4343 | call delete('Xtest1.txt') |
| 4344 | call delete('Xtest2.txt') |
| 4345 | call setqflist([], 'f') |
| 4346 | endfunc |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 4347 | |
Bram Moolenaar | f9ae154 | 2019-11-18 22:02:16 +0100 | [diff] [blame] | 4348 | " Test for an autocmd changing the current directory when running vimgrep |
| 4349 | func Xvimgrep_autocmd_cd(cchar) |
| 4350 | call s:setup_commands(a:cchar) |
| 4351 | |
| 4352 | %bwipe |
| 4353 | let save_cwd = getcwd() |
| 4354 | |
| 4355 | augroup QF_Test |
| 4356 | au! |
| 4357 | autocmd BufRead * silent cd %:p:h |
| 4358 | augroup END |
| 4359 | |
| 4360 | 10Xvimgrep /vim/ Xdir/** |
| 4361 | let l = g:Xgetlist() |
| 4362 | call assert_equal('f1.txt', bufname(l[0].bufnr)) |
| 4363 | call assert_equal('f2.txt', fnamemodify(bufname(l[2].bufnr), ':t')) |
| 4364 | |
| 4365 | augroup QF_Test |
| 4366 | au! |
| 4367 | augroup END |
| 4368 | |
| 4369 | exe 'cd ' . save_cwd |
| 4370 | endfunc |
| 4371 | |
| 4372 | func Test_vimgrep_autocmd_cd() |
| 4373 | call mkdir('Xdir/a', 'p') |
| 4374 | call mkdir('Xdir/b', 'p') |
| 4375 | call writefile(['a_L1_vim', 'a_L2_vim'], 'Xdir/a/f1.txt') |
| 4376 | call writefile(['b_L1_vim', 'b_L2_vim'], 'Xdir/b/f2.txt') |
| 4377 | call Xvimgrep_autocmd_cd('c') |
| 4378 | call Xvimgrep_autocmd_cd('l') |
| 4379 | %bwipe |
| 4380 | call delete('Xdir', 'rf') |
| 4381 | endfunc |
| 4382 | |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 4383 | " The following test used to crash Vim |
| 4384 | func Test_lhelpgrep_autocmd() |
| 4385 | lhelpgrep quickfix |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4386 | augroup QF_Test |
| 4387 | au! |
| 4388 | autocmd QuickFixCmdPost * call setloclist(0, [], 'f') |
| 4389 | augroup END |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 4390 | lhelpgrep buffer |
| 4391 | call assert_equal('help', &filetype) |
| 4392 | call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) |
| 4393 | lhelpgrep tabpage |
| 4394 | call assert_equal('help', &filetype) |
| 4395 | call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4396 | augroup QF_Test |
| 4397 | au! |
| 4398 | augroup END |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4399 | |
| 4400 | new | only |
| 4401 | augroup QF_Test |
| 4402 | au! |
| 4403 | au BufEnter * call setqflist([], 'f') |
| 4404 | augroup END |
| 4405 | call assert_fails('helpgrep quickfix', 'E925:') |
Bram Moolenaar | dbfa795 | 2020-11-02 20:04:22 +0100 | [diff] [blame] | 4406 | " run the test with a help window already open |
| 4407 | help |
| 4408 | wincmd w |
| 4409 | call assert_fails('helpgrep quickfix', 'E925:') |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4410 | augroup QF_Test |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4411 | au! |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4412 | augroup END |
| 4413 | |
| 4414 | new | only |
| 4415 | augroup QF_Test |
| 4416 | au! |
| 4417 | au BufEnter * call setqflist([], 'r') |
| 4418 | augroup END |
| 4419 | call assert_fails('helpgrep quickfix', 'E925:') |
| 4420 | augroup QF_Test |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4421 | au! |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4422 | augroup END |
| 4423 | |
| 4424 | new | only |
| 4425 | augroup QF_Test |
| 4426 | au! |
| 4427 | au BufEnter * call setloclist(0, [], 'r') |
| 4428 | augroup END |
| 4429 | call assert_fails('lhelpgrep quickfix', 'E926:') |
| 4430 | augroup QF_Test |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4431 | au! |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 4432 | augroup END |
| 4433 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4434 | " Replace the contents of a help window location list when it is still in |
| 4435 | " use. |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 4436 | new | only |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 4437 | lhelpgrep quickfix |
| 4438 | wincmd w |
| 4439 | augroup QF_Test |
| 4440 | au! |
| 4441 | autocmd WinEnter * call setloclist(0, [], 'r') |
| 4442 | augroup END |
| 4443 | call assert_fails('lhelpgrep win_getid', 'E926:') |
| 4444 | augroup QF_Test |
| 4445 | au! |
| 4446 | augroup END |
| 4447 | |
| 4448 | %bw! |
| 4449 | endfunc |
| 4450 | |
| 4451 | " The following test used to crash Vim |
| 4452 | func Test_lhelpgrep_autocmd_free_loclist() |
| 4453 | %bw! |
| 4454 | lhelpgrep quickfix |
| 4455 | wincmd w |
| 4456 | augroup QF_Test |
| 4457 | au! |
| 4458 | autocmd WinEnter * call setloclist(0, [], 'f') |
| 4459 | augroup END |
| 4460 | lhelpgrep win_getid |
| 4461 | wincmd w |
| 4462 | wincmd w |
| 4463 | wincmd w |
| 4464 | augroup QF_Test |
| 4465 | au! |
| 4466 | augroup END |
| 4467 | %bw! |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 4468 | endfunc |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 4469 | |
| 4470 | " Test for shortening/simplifying the file name when opening the |
| 4471 | " quickfix window or when displaying the quickfix list |
| 4472 | func Test_shorten_fname() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 4473 | CheckUnix |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 4474 | %bwipe |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 4475 | " Create a quickfix list with an absolute path filename |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 4476 | let fname = getcwd() . '/test_quickfix.vim' |
| 4477 | call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) |
| 4478 | call assert_equal(fname, bufname('test_quickfix.vim')) |
| 4479 | " Opening the quickfix window should simplify the file path |
| 4480 | cwindow |
| 4481 | call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) |
| 4482 | cclose |
| 4483 | %bwipe |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 4484 | " Create a quickfix list with an absolute path filename |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 4485 | call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) |
| 4486 | call assert_equal(fname, bufname('test_quickfix.vim')) |
| 4487 | " Displaying the quickfix list should simplify the file path |
| 4488 | silent! clist |
| 4489 | call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) |
Bram Moolenaar | 8ec92c9 | 2020-09-29 22:47:03 +0200 | [diff] [blame] | 4490 | " Add a few entries for the same file with different paths and check whether |
| 4491 | " the buffer name is shortened |
| 4492 | %bwipe |
| 4493 | call setqflist([], 'f') |
| 4494 | call setqflist([{'filename' : 'test_quickfix.vim', 'lnum' : 10}, |
| 4495 | \ {'filename' : '../testdir/test_quickfix.vim', 'lnum' : 20}, |
| 4496 | \ {'filename' : fname, 'lnum' : 30}], ' ') |
| 4497 | copen |
| 4498 | call assert_equal(['test_quickfix.vim|10| ', |
| 4499 | \ 'test_quickfix.vim|20| ', |
| 4500 | \ 'test_quickfix.vim|30| '], getline(1, '$')) |
| 4501 | cclose |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 4502 | endfunc |
Bram Moolenaar | 8b62e31 | 2018-05-13 15:29:04 +0200 | [diff] [blame] | 4503 | |
| 4504 | " Quickfix title tests |
| 4505 | " In the below tests, 'exe "cmd"' is used to invoke the quickfix commands. |
| 4506 | " Otherwise due to indentation, the title is set with spaces at the beginning |
| 4507 | " of the command. |
| 4508 | func Test_qftitle() |
| 4509 | call writefile(["F1:1:Line1"], 'Xerr') |
| 4510 | |
| 4511 | " :cexpr |
| 4512 | exe "cexpr readfile('Xerr')" |
| 4513 | call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title) |
| 4514 | |
| 4515 | " :cgetexpr |
| 4516 | exe "cgetexpr readfile('Xerr')" |
| 4517 | call assert_equal(":cgetexpr readfile('Xerr')", |
| 4518 | \ getqflist({'title' : 1}).title) |
| 4519 | |
| 4520 | " :caddexpr |
| 4521 | call setqflist([], 'f') |
| 4522 | exe "caddexpr readfile('Xerr')" |
| 4523 | call assert_equal(":caddexpr readfile('Xerr')", |
| 4524 | \ getqflist({'title' : 1}).title) |
| 4525 | |
| 4526 | " :cbuffer |
| 4527 | new Xerr |
| 4528 | exe "cbuffer" |
| 4529 | call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 4530 | |
| 4531 | " :cgetbuffer |
| 4532 | edit Xerr |
| 4533 | exe "cgetbuffer" |
| 4534 | call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 4535 | |
| 4536 | " :caddbuffer |
| 4537 | call setqflist([], 'f') |
| 4538 | edit Xerr |
| 4539 | exe "caddbuffer" |
| 4540 | call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 4541 | |
| 4542 | " :cfile |
| 4543 | exe "cfile Xerr" |
| 4544 | call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title) |
| 4545 | |
| 4546 | " :cgetfile |
| 4547 | exe "cgetfile Xerr" |
| 4548 | call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title) |
| 4549 | |
| 4550 | " :caddfile |
| 4551 | call setqflist([], 'f') |
| 4552 | exe "caddfile Xerr" |
| 4553 | call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title) |
| 4554 | |
| 4555 | " :grep |
| 4556 | set grepprg=internal |
| 4557 | exe "grep F1 Xerr" |
| 4558 | call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title) |
| 4559 | |
| 4560 | " :grepadd |
| 4561 | call setqflist([], 'f') |
| 4562 | exe "grepadd F1 Xerr" |
| 4563 | call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title) |
| 4564 | set grepprg&vim |
| 4565 | |
| 4566 | " :vimgrep |
| 4567 | exe "vimgrep F1 Xerr" |
| 4568 | call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title) |
| 4569 | |
| 4570 | " :vimgrepadd |
| 4571 | call setqflist([], 'f') |
| 4572 | exe "vimgrepadd F1 Xerr" |
| 4573 | call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title) |
| 4574 | |
| 4575 | call setqflist(['F1:10:L10'], ' ') |
| 4576 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 4577 | |
| 4578 | call setqflist([], 'f') |
| 4579 | call setqflist(['F1:10:L10'], 'a') |
| 4580 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 4581 | |
| 4582 | call setqflist([], 'f') |
| 4583 | call setqflist(['F1:10:L10'], 'r') |
| 4584 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 4585 | |
| 4586 | close |
| 4587 | call delete('Xerr') |
| 4588 | |
| 4589 | call setqflist([], ' ', {'title' : 'Errors'}) |
| 4590 | copen |
| 4591 | call assert_equal('Errors', w:quickfix_title) |
| 4592 | call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]}) |
| 4593 | call assert_equal('Errors', w:quickfix_title) |
| 4594 | cclose |
Bram Moolenaar | 530bed9 | 2020-12-16 21:02:56 +0100 | [diff] [blame] | 4595 | |
| 4596 | " Switching to another quickfix list in one tab page should update the |
| 4597 | " quickfix window title and statusline in all the other tab pages also |
| 4598 | call setqflist([], 'f') |
| 4599 | %bw! |
| 4600 | cgetexpr ['file_one:1:1: error in the first quickfix list'] |
| 4601 | call setqflist([], 'a', {'title': 'first quickfix list'}) |
| 4602 | cgetexpr ['file_two:2:1: error in the second quickfix list'] |
| 4603 | call setqflist([], 'a', {'title': 'second quickfix list'}) |
| 4604 | copen |
| 4605 | wincmd t |
| 4606 | tabnew two |
| 4607 | copen |
| 4608 | wincmd t |
| 4609 | colder |
| 4610 | call assert_equal('first quickfix list', gettabwinvar(1, 2, 'quickfix_title')) |
| 4611 | call assert_equal('first quickfix list', gettabwinvar(2, 2, 'quickfix_title')) |
| 4612 | call assert_equal(1, tabpagewinnr(1)) |
| 4613 | call assert_equal(1, tabpagewinnr(2)) |
| 4614 | tabnew |
| 4615 | call setqflist([], 'a', {'title': 'new quickfix title'}) |
| 4616 | call assert_equal('new quickfix title', gettabwinvar(1, 2, 'quickfix_title')) |
| 4617 | call assert_equal('new quickfix title', gettabwinvar(2, 2, 'quickfix_title')) |
| 4618 | %bw! |
Bram Moolenaar | 8b62e31 | 2018-05-13 15:29:04 +0200 | [diff] [blame] | 4619 | endfunc |
Bram Moolenaar | 600323b | 2018-06-16 22:16:47 +0200 | [diff] [blame] | 4620 | |
| 4621 | func Test_lbuffer_with_bwipe() |
| 4622 | new |
| 4623 | new |
| 4624 | augroup nasty |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4625 | au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * bwipe |
Bram Moolenaar | 600323b | 2018-06-16 22:16:47 +0200 | [diff] [blame] | 4626 | augroup END |
| 4627 | lbuffer |
| 4628 | augroup nasty |
| 4629 | au! |
| 4630 | augroup END |
| 4631 | endfunc |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 4632 | |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4633 | " Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is |
| 4634 | " running |
| 4635 | func Xexpr_acmd_freelist(cchar) |
| 4636 | call s:setup_commands(a:cchar) |
| 4637 | |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4638 | " This was using freed memory (but with what events?) |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 4639 | augroup nasty |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 4640 | au QuickFixCmdPre,QuickFixCmdPost,BufEnter,BufLeave * call g:Xsetlist([], 'f') |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 4641 | augroup END |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4642 | Xexpr "x" |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 4643 | augroup nasty |
| 4644 | au! |
| 4645 | augroup END |
| 4646 | endfunc |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4647 | |
| 4648 | func Test_cexpr_acmd_freelist() |
| 4649 | call Xexpr_acmd_freelist('c') |
| 4650 | call Xexpr_acmd_freelist('l') |
| 4651 | endfunc |
| 4652 | |
| 4653 | " Test for commands that create a new quickfix/location list and jump to the |
| 4654 | " first error automatically. |
| 4655 | func Xjumpto_first_error_test(cchar) |
| 4656 | call s:setup_commands(a:cchar) |
| 4657 | |
| 4658 | call s:create_test_file('Xtestfile1') |
| 4659 | call s:create_test_file('Xtestfile2') |
| 4660 | let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] |
| 4661 | |
| 4662 | " Test for cexpr/lexpr |
| 4663 | enew |
| 4664 | Xexpr l |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4665 | call assert_equal('Xtestfile1', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4666 | call assert_equal(2, line('.')) |
| 4667 | |
| 4668 | " Test for cfile/lfile |
| 4669 | enew |
| 4670 | call writefile(l, 'Xerr') |
| 4671 | Xfile Xerr |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4672 | call assert_equal('Xtestfile1', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4673 | call assert_equal(2, line('.')) |
| 4674 | |
| 4675 | " Test for cbuffer/lbuffer |
| 4676 | edit Xerr |
| 4677 | Xbuffer |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4678 | call assert_equal('Xtestfile1', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4679 | call assert_equal(2, line('.')) |
| 4680 | |
| 4681 | call delete('Xerr') |
| 4682 | call delete('Xtestfile1') |
| 4683 | call delete('Xtestfile2') |
| 4684 | endfunc |
| 4685 | |
| 4686 | func Test_jumpto_first_error() |
| 4687 | call Xjumpto_first_error_test('c') |
| 4688 | call Xjumpto_first_error_test('l') |
| 4689 | endfunc |
| 4690 | |
| 4691 | " Test for a quickfix autocmd changing the quickfix/location list before |
| 4692 | " jumping to the first error in the new list. |
| 4693 | func Xautocmd_changelist(cchar) |
| 4694 | call s:setup_commands(a:cchar) |
| 4695 | |
| 4696 | " Test for cfile/lfile |
| 4697 | call s:create_test_file('Xtestfile1') |
| 4698 | call s:create_test_file('Xtestfile2') |
| 4699 | Xexpr 'Xtestfile1:2:Line2' |
| 4700 | autocmd QuickFixCmdPost * Xolder |
| 4701 | call writefile(['Xtestfile2:4:Line4'], 'Xerr') |
| 4702 | Xfile Xerr |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4703 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4704 | call assert_equal(4, line('.')) |
| 4705 | autocmd! QuickFixCmdPost |
| 4706 | |
| 4707 | " Test for cbuffer/lbuffer |
| 4708 | call g:Xsetlist([], 'f') |
| 4709 | Xexpr 'Xtestfile1:2:Line2' |
| 4710 | autocmd QuickFixCmdPost * Xolder |
| 4711 | call writefile(['Xtestfile2:4:Line4'], 'Xerr') |
| 4712 | edit Xerr |
| 4713 | Xbuffer |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4714 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4715 | call assert_equal(4, line('.')) |
| 4716 | autocmd! QuickFixCmdPost |
| 4717 | |
| 4718 | " Test for cexpr/lexpr |
| 4719 | call g:Xsetlist([], 'f') |
| 4720 | Xexpr 'Xtestfile1:2:Line2' |
| 4721 | autocmd QuickFixCmdPost * Xolder |
| 4722 | Xexpr 'Xtestfile2:4:Line4' |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4723 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4724 | call assert_equal(4, line('.')) |
| 4725 | autocmd! QuickFixCmdPost |
| 4726 | |
Bram Moolenaar | 851332e | 2018-07-03 19:16:00 +0200 | [diff] [blame] | 4727 | " The grepprg may not be set on non-Unix systems |
| 4728 | if has('unix') |
| 4729 | " Test for grep/lgrep |
| 4730 | call g:Xsetlist([], 'f') |
| 4731 | Xexpr 'Xtestfile1:2:Line2' |
| 4732 | autocmd QuickFixCmdPost * Xolder |
| 4733 | silent Xgrep Line5 Xtestfile2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4734 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | 851332e | 2018-07-03 19:16:00 +0200 | [diff] [blame] | 4735 | call assert_equal(5, line('.')) |
| 4736 | autocmd! QuickFixCmdPost |
| 4737 | endif |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4738 | |
| 4739 | " Test for vimgrep/lvimgrep |
| 4740 | call g:Xsetlist([], 'f') |
| 4741 | Xexpr 'Xtestfile1:2:Line2' |
| 4742 | autocmd QuickFixCmdPost * Xolder |
| 4743 | silent Xvimgrep Line5 Xtestfile2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 4744 | call assert_equal('Xtestfile2', @%) |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4745 | call assert_equal(5, line('.')) |
| 4746 | autocmd! QuickFixCmdPost |
| 4747 | |
Bram Moolenaar | 3f347e4 | 2018-08-09 21:19:20 +0200 | [diff] [blame] | 4748 | " Test for autocommands clearing the quickfix list before jumping to the |
| 4749 | " first error. This should not result in an error |
| 4750 | autocmd QuickFixCmdPost * call g:Xsetlist([], 'r') |
| 4751 | let v:errmsg = '' |
| 4752 | " Test for cfile/lfile |
| 4753 | Xfile Xerr |
| 4754 | call assert_true(v:errmsg !~# 'E42:') |
| 4755 | " Test for cbuffer/lbuffer |
| 4756 | edit Xerr |
| 4757 | Xbuffer |
| 4758 | call assert_true(v:errmsg !~# 'E42:') |
| 4759 | " Test for cexpr/lexpr |
| 4760 | Xexpr 'Xtestfile2:4:Line4' |
| 4761 | call assert_true(v:errmsg !~# 'E42:') |
| 4762 | " Test for grep/lgrep |
| 4763 | " The grepprg may not be set on non-Unix systems |
| 4764 | if has('unix') |
| 4765 | silent Xgrep Line5 Xtestfile2 |
| 4766 | call assert_true(v:errmsg !~# 'E42:') |
| 4767 | endif |
| 4768 | " Test for vimgrep/lvimgrep |
| 4769 | call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:') |
| 4770 | autocmd! QuickFixCmdPost |
| 4771 | |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 4772 | call delete('Xerr') |
| 4773 | call delete('Xtestfile1') |
| 4774 | call delete('Xtestfile2') |
| 4775 | endfunc |
| 4776 | |
| 4777 | func Test_autocmd_changelist() |
| 4778 | call Xautocmd_changelist('c') |
| 4779 | call Xautocmd_changelist('l') |
| 4780 | endfunc |
Bram Moolenaar | 4cde86c | 2018-07-08 16:01:08 +0200 | [diff] [blame] | 4781 | |
| 4782 | " Tests for the ':filter /pat/ clist' command |
| 4783 | func Test_filter_clist() |
| 4784 | cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15'] |
| 4785 | call assert_equal([' 2 Xfile2:15 col 15: Line 15'], |
| 4786 | \ split(execute('filter /Line 15/ clist'), "\n")) |
| 4787 | call assert_equal([' 1 Xfile1:10 col 10: Line 10'], |
| 4788 | \ split(execute('filter /Xfile1/ clist'), "\n")) |
| 4789 | call assert_equal([], split(execute('filter /abc/ clist'), "\n")) |
| 4790 | |
| 4791 | call setqflist([{'module' : 'abc', 'pattern' : 'pat1'}, |
| 4792 | \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ') |
| 4793 | call assert_equal([' 2 pqr:pat2: '], |
| 4794 | \ split(execute('filter /pqr/ clist'), "\n")) |
| 4795 | call assert_equal([' 1 abc:pat1: '], |
| 4796 | \ split(execute('filter /pat1/ clist'), "\n")) |
| 4797 | endfunc |
Bram Moolenaar | 0a08c63 | 2018-07-25 22:36:52 +0200 | [diff] [blame] | 4798 | |
| 4799 | " Tests for the "CTRL-W <CR>" command. |
| 4800 | func Xview_result_split_tests(cchar) |
| 4801 | call s:setup_commands(a:cchar) |
| 4802 | |
| 4803 | " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list. |
| 4804 | call g:Xsetlist([]) |
| 4805 | Xopen |
| 4806 | let l:win_count = winnr('$') |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 4807 | call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42:') |
Bram Moolenaar | 0a08c63 | 2018-07-25 22:36:52 +0200 | [diff] [blame] | 4808 | call assert_equal(l:win_count, winnr('$')) |
| 4809 | Xclose |
| 4810 | endfunc |
| 4811 | |
| 4812 | func Test_view_result_split() |
| 4813 | call Xview_result_split_tests('c') |
| 4814 | call Xview_result_split_tests('l') |
| 4815 | endfunc |
Bram Moolenaar | 2dfcef4 | 2018-08-15 22:29:51 +0200 | [diff] [blame] | 4816 | |
| 4817 | " Test that :cc sets curswant |
| 4818 | func Test_curswant() |
| 4819 | helpgrep quickfix |
| 4820 | normal! llll |
| 4821 | 1cc |
| 4822 | call assert_equal(getcurpos()[4], virtcol('.')) |
| 4823 | cclose | helpclose |
| 4824 | endfunc |
Bram Moolenaar | b244373 | 2018-11-11 22:50:27 +0100 | [diff] [blame] | 4825 | |
| 4826 | " Test for opening a file from the quickfix window using CTRL-W <Enter> |
| 4827 | " doesn't leave an empty buffer around. |
| 4828 | func Test_splitview() |
| 4829 | call s:create_test_file('Xtestfile1') |
| 4830 | call s:create_test_file('Xtestfile2') |
| 4831 | new | only |
| 4832 | let last_bufnr = bufnr('Test_sv_1', 1) |
| 4833 | let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] |
| 4834 | cgetexpr l |
| 4835 | copen |
| 4836 | let numbufs = len(getbufinfo()) |
| 4837 | exe "normal \<C-W>\<CR>" |
| 4838 | copen |
| 4839 | exe "normal j\<C-W>\<CR>" |
| 4840 | " Make sure new empty buffers are not created |
| 4841 | call assert_equal(numbufs, len(getbufinfo())) |
| 4842 | " Creating a new buffer should use the next available buffer number |
| 4843 | call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1)) |
| 4844 | bwipe Test_sv_1 |
| 4845 | bwipe Test_sv_2 |
| 4846 | new | only |
| 4847 | |
| 4848 | " When split opening files from location list window, make sure that two |
| 4849 | " windows doesn't refer to the same location list |
| 4850 | lgetexpr l |
| 4851 | let locid = getloclist(0, {'id' : 0}).id |
| 4852 | lopen |
| 4853 | exe "normal \<C-W>\<CR>" |
| 4854 | call assert_notequal(locid, getloclist(0, {'id' : 0}).id) |
| 4855 | call assert_equal(0, getloclist(0, {'winid' : 0}).winid) |
| 4856 | new | only |
| 4857 | |
| 4858 | " When split opening files from a helpgrep location list window, a new help |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 4859 | " window should be opened with a copy of the location list. |
Bram Moolenaar | b244373 | 2018-11-11 22:50:27 +0100 | [diff] [blame] | 4860 | lhelpgrep window |
| 4861 | let locid = getloclist(0, {'id' : 0}).id |
| 4862 | lwindow |
| 4863 | exe "normal j\<C-W>\<CR>" |
| 4864 | call assert_notequal(locid, getloclist(0, {'id' : 0}).id) |
| 4865 | call assert_equal(0, getloclist(0, {'winid' : 0}).winid) |
| 4866 | new | only |
| 4867 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 4868 | " Using :split or :vsplit from a quickfix window should behave like a :new |
| 4869 | " or a :vnew command |
| 4870 | copen |
| 4871 | split |
| 4872 | call assert_equal(3, winnr('$')) |
| 4873 | let l = getwininfo() |
| 4874 | call assert_equal([0, 0, 1], [l[0].quickfix, l[1].quickfix, l[2].quickfix]) |
| 4875 | close |
| 4876 | copen |
| 4877 | vsplit |
| 4878 | let l = getwininfo() |
| 4879 | call assert_equal([0, 0, 1], [l[0].quickfix, l[1].quickfix, l[2].quickfix]) |
| 4880 | new | only |
| 4881 | |
Bram Moolenaar | b244373 | 2018-11-11 22:50:27 +0100 | [diff] [blame] | 4882 | call delete('Xtestfile1') |
| 4883 | call delete('Xtestfile2') |
| 4884 | endfunc |
Bram Moolenaar | c45eb77 | 2019-01-31 14:27:04 +0100 | [diff] [blame] | 4885 | |
| 4886 | " Test for parsing entries using visual screen column |
| 4887 | func Test_viscol() |
| 4888 | enew |
| 4889 | call writefile(["Col1\tCol2\tCol3"], 'Xfile1') |
| 4890 | edit Xfile1 |
| 4891 | |
| 4892 | " Use byte offset for column number |
| 4893 | set efm& |
| 4894 | cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ" |
| 4895 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 4896 | cnext |
| 4897 | call assert_equal([9, 12], [col('.'), virtcol('.')]) |
| 4898 | cnext |
| 4899 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 4900 | |
| 4901 | " Use screen column offset for column number |
| 4902 | set efm=%f:%l:%v:%m |
| 4903 | cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ" |
| 4904 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 4905 | cnext |
| 4906 | call assert_equal([9, 12], [col('.'), virtcol('.')]) |
| 4907 | cnext |
| 4908 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 4909 | cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ" |
| 4910 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 4911 | cnext |
| 4912 | call assert_equal([10, 16], [col('.'), virtcol('.')]) |
| 4913 | cnext |
| 4914 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 4915 | |
| 4916 | enew |
| 4917 | call writefile(["Col1\täü\töß\tCol4"], 'Xfile1') |
| 4918 | |
| 4919 | " Use byte offset for column number |
| 4920 | set efm& |
| 4921 | cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ" |
| 4922 | call assert_equal([8, 10], [col('.'), virtcol('.')]) |
| 4923 | cnext |
| 4924 | call assert_equal([11, 17], [col('.'), virtcol('.')]) |
| 4925 | cnext |
| 4926 | call assert_equal([16, 25], [col('.'), virtcol('.')]) |
| 4927 | |
| 4928 | " Use screen column offset for column number |
| 4929 | set efm=%f:%l:%v:%m |
| 4930 | cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ" |
| 4931 | call assert_equal([8, 10], [col('.'), virtcol('.')]) |
| 4932 | cnext |
| 4933 | call assert_equal([11, 17], [col('.'), virtcol('.')]) |
| 4934 | cnext |
| 4935 | call assert_equal([16, 25], [col('.'), virtcol('.')]) |
| 4936 | |
Bram Moolenaar | c95940c | 2020-10-20 14:59:12 +0200 | [diff] [blame] | 4937 | " Use screen column number with a multi-line error message |
| 4938 | enew |
| 4939 | call writefile(["Ã test"], 'Xfile1') |
| 4940 | set efm=%E===\ %f\ ===,%C%l:%v,%Z%m |
| 4941 | cexpr ["=== Xfile1 ===", "1:3", "errormsg"] |
| 4942 | call assert_equal('Xfile1', @%) |
| 4943 | call assert_equal([0, 1, 4, 0], getpos('.')) |
| 4944 | |
| 4945 | " Repeat previous test with byte offset %c: ensure that fix to issue #7145 |
| 4946 | " does not break this |
| 4947 | set efm=%E===\ %f\ ===,%C%l:%c,%Z%m |
| 4948 | cexpr ["=== Xfile1 ===", "1:3", "errormsg"] |
| 4949 | call assert_equal('Xfile1', @%) |
| 4950 | call assert_equal([0, 1, 3, 0], getpos('.')) |
| 4951 | |
Bram Moolenaar | c45eb77 | 2019-01-31 14:27:04 +0100 | [diff] [blame] | 4952 | enew | only |
| 4953 | set efm& |
| 4954 | call delete('Xfile1') |
| 4955 | endfunc |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 4956 | |
| 4957 | " Test for the quickfix window buffer |
| 4958 | func Xqfbuf_test(cchar) |
| 4959 | call s:setup_commands(a:cchar) |
| 4960 | |
| 4961 | " Quickfix buffer should be reused across closing and opening a quickfix |
| 4962 | " window |
| 4963 | Xexpr "F1:10:Line10" |
| 4964 | Xopen |
| 4965 | let qfbnum = bufnr('') |
| 4966 | Xclose |
| 4967 | " Even after the quickfix window is closed, the buffer should be loaded |
| 4968 | call assert_true(bufloaded(qfbnum)) |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 4969 | call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 4970 | Xopen |
| 4971 | " Buffer should be reused when opening the window again |
| 4972 | call assert_equal(qfbnum, bufnr('')) |
| 4973 | Xclose |
| 4974 | |
Yegappan Lakshmanan | 56150da | 2021-12-09 09:27:06 +0000 | [diff] [blame] | 4975 | " When quickfix buffer is wiped out, getqflist() should return 0 |
| 4976 | %bw! |
| 4977 | Xexpr "" |
| 4978 | Xopen |
| 4979 | bw! |
| 4980 | call assert_equal(0, g:Xgetlist({'qfbufnr': 0}).qfbufnr) |
| 4981 | |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 4982 | if a:cchar == 'l' |
| 4983 | %bwipe |
| 4984 | " For a location list, when both the file window and the location list |
| 4985 | " window for the list are closed, then the buffer should be freed. |
| 4986 | new | only |
| 4987 | lexpr "F1:10:Line10" |
| 4988 | let wid = win_getid() |
| 4989 | lopen |
| 4990 | let qfbnum = bufnr('') |
| 4991 | call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls')) |
| 4992 | close |
| 4993 | " When the location list window is closed, the buffer name should not |
| 4994 | " change to 'Quickfix List' |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 4995 | call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!')) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 4996 | call assert_true(bufloaded(qfbnum)) |
| 4997 | |
Bram Moolenaar | d82a81c | 2019-03-02 07:57:18 +0100 | [diff] [blame] | 4998 | " After deleting a location list buffer using ":bdelete", opening the |
| 4999 | " location list window should mark the buffer as a location list buffer. |
| 5000 | exe "bdelete " . qfbnum |
| 5001 | lopen |
| 5002 | call assert_equal("quickfix", &buftype) |
| 5003 | call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist) |
| 5004 | call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid) |
| 5005 | call assert_false(&swapfile) |
| 5006 | lclose |
| 5007 | |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 5008 | " When the location list is cleared for the window, the buffer should be |
| 5009 | " removed |
| 5010 | call setloclist(0, [], 'f') |
| 5011 | call assert_false(bufexists(qfbnum)) |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 5012 | call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr) |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 5013 | |
| 5014 | " When the location list is freed with the location list window open, the |
| 5015 | " location list buffer should not be lost. It should be reused when the |
| 5016 | " location list is again populated. |
| 5017 | lexpr "F1:10:Line10" |
| 5018 | lopen |
| 5019 | let wid = win_getid() |
| 5020 | let qfbnum = bufnr('') |
| 5021 | wincmd p |
| 5022 | call setloclist(0, [], 'f') |
| 5023 | lexpr "F1:10:Line10" |
| 5024 | lopen |
| 5025 | call assert_equal(wid, win_getid()) |
| 5026 | call assert_equal(qfbnum, bufnr('')) |
| 5027 | lclose |
| 5028 | |
| 5029 | " When the window with the location list is closed, the buffer should be |
| 5030 | " removed |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 5031 | new | only |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 5032 | call assert_false(bufexists(qfbnum)) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 5033 | endif |
| 5034 | endfunc |
| 5035 | |
| 5036 | func Test_qfbuf() |
| 5037 | call Xqfbuf_test('c') |
| 5038 | call Xqfbuf_test('l') |
| 5039 | endfunc |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 5040 | |
| 5041 | " If there is an autocmd to use only one window, then opening the location |
| 5042 | " list window used to crash Vim. |
| 5043 | func Test_winonly_autocmd() |
| 5044 | call s:create_test_file('Xtest1') |
| 5045 | " Autocmd to show only one Vim window at a time |
| 5046 | autocmd WinEnter * only |
| 5047 | new |
| 5048 | " Load the location list |
| 5049 | lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15" |
| 5050 | let loclistid = getloclist(0, {'id' : 0}).id |
| 5051 | " Open the location list window. Only this window will be shown and the file |
| 5052 | " window is closed. |
| 5053 | lopen |
| 5054 | call assert_equal(loclistid, getloclist(0, {'id' : 0}).id) |
| 5055 | " Jump to an entry in the location list and make sure that the cursor is |
| 5056 | " positioned correctly. |
| 5057 | ll 3 |
| 5058 | call assert_equal(loclistid, getloclist(0, {'id' : 0}).id) |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5059 | call assert_equal('Xtest1', @%) |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 5060 | call assert_equal(15, line('.')) |
| 5061 | " Cleanup |
| 5062 | autocmd! WinEnter |
| 5063 | new | only |
| 5064 | call delete('Xtest1') |
| 5065 | endfunc |
Bram Moolenaar | 39803d8 | 2019-04-07 12:04:51 +0200 | [diff] [blame] | 5066 | |
| 5067 | " Test to make sure that an empty quickfix buffer is not reused for loading |
| 5068 | " a normal buffer. |
| 5069 | func Test_empty_qfbuf() |
| 5070 | enew | only |
| 5071 | call writefile(["Test"], 'Xfile1') |
| 5072 | call setqflist([], 'f') |
| 5073 | copen | only |
| 5074 | let qfbuf = bufnr('') |
| 5075 | edit Xfile1 |
| 5076 | call assert_notequal(qfbuf, bufnr('')) |
| 5077 | enew |
| 5078 | call delete('Xfile1') |
| 5079 | endfunc |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5080 | |
| 5081 | " Test for the :cbelow, :cabove, :lbelow and :labove commands. |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5082 | " And for the :cafter, :cbefore, :lafter and :lbefore commands. |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5083 | func Xtest_below(cchar) |
| 5084 | call s:setup_commands(a:cchar) |
| 5085 | |
| 5086 | " No quickfix/location list |
| 5087 | call assert_fails('Xbelow', 'E42:') |
| 5088 | call assert_fails('Xabove', 'E42:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5089 | call assert_fails('Xbefore', 'E42:') |
| 5090 | call assert_fails('Xafter', 'E42:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5091 | |
| 5092 | " Empty quickfix/location list |
| 5093 | call g:Xsetlist([]) |
| 5094 | call assert_fails('Xbelow', 'E42:') |
| 5095 | call assert_fails('Xabove', 'E42:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5096 | call assert_fails('Xbefore', 'E42:') |
| 5097 | call assert_fails('Xafter', 'E42:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5098 | |
| 5099 | call s:create_test_file('X1') |
| 5100 | call s:create_test_file('X2') |
| 5101 | call s:create_test_file('X3') |
| 5102 | call s:create_test_file('X4') |
| 5103 | |
| 5104 | " Invalid entries |
| 5105 | edit X1 |
| 5106 | call g:Xsetlist(["E1", "E2"]) |
| 5107 | call assert_fails('Xbelow', 'E42:') |
| 5108 | call assert_fails('Xabove', 'E42:') |
| 5109 | call assert_fails('3Xbelow', 'E42:') |
| 5110 | call assert_fails('4Xabove', 'E42:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5111 | call assert_fails('Xbefore', 'E42:') |
| 5112 | call assert_fails('Xafter', 'E42:') |
| 5113 | call assert_fails('3Xbefore', 'E42:') |
| 5114 | call assert_fails('4Xafter', 'E42:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5115 | |
| 5116 | " Test the commands with various arguments |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5117 | Xexpr ["X1:5:3:L5", "X2:5:2:L5", "X2:10:3:L10", "X2:15:4:L15", "X3:3:5:L3"] |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5118 | edit +7 X2 |
| 5119 | Xabove |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5120 | call assert_equal(['X2', 5], [@%, line('.')]) |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5121 | call assert_fails('Xabove', 'E553:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5122 | normal 7G |
| 5123 | Xbefore |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5124 | call assert_equal(['X2', 5, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5125 | call assert_fails('Xbefore', 'E553:') |
| 5126 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5127 | normal 2j |
| 5128 | Xbelow |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5129 | call assert_equal(['X2', 10], [@%, line('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5130 | normal 7G |
| 5131 | Xafter |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5132 | call assert_equal(['X2', 10, 3], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5133 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5134 | " Last error in this file |
| 5135 | Xbelow 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5136 | call assert_equal(['X2', 15], [@%, line('.')]) |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5137 | call assert_fails('Xbelow', 'E553:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5138 | normal gg |
| 5139 | Xafter 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5140 | call assert_equal(['X2', 15, 4], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5141 | call assert_fails('Xafter', 'E553:') |
| 5142 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5143 | " First error in this file |
| 5144 | Xabove 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5145 | call assert_equal(['X2', 5], [@%, line('.')]) |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5146 | call assert_fails('Xabove', 'E553:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5147 | normal G |
| 5148 | Xbefore 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5149 | call assert_equal(['X2', 5, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5150 | call assert_fails('Xbefore', 'E553:') |
| 5151 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5152 | normal gg |
| 5153 | Xbelow 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5154 | call assert_equal(['X2', 10], [@%, line('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5155 | normal gg |
| 5156 | Xafter 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5157 | call assert_equal(['X2', 10, 3], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5158 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5159 | normal G |
| 5160 | Xabove 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5161 | call assert_equal(['X2', 10], [@%, line('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5162 | normal G |
| 5163 | Xbefore 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5164 | call assert_equal(['X2', 10, 3], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5165 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5166 | edit X4 |
| 5167 | call assert_fails('Xabove', 'E42:') |
| 5168 | call assert_fails('Xbelow', 'E42:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5169 | call assert_fails('Xbefore', 'E42:') |
| 5170 | call assert_fails('Xafter', 'E42:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5171 | if a:cchar == 'l' |
| 5172 | " If a buffer has location list entries from some other window but not |
| 5173 | " from the current window, then the commands should fail. |
| 5174 | edit X1 | split | call setloclist(0, [], 'f') |
| 5175 | call assert_fails('Xabove', 'E776:') |
| 5176 | call assert_fails('Xbelow', 'E776:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5177 | call assert_fails('Xbefore', 'E776:') |
| 5178 | call assert_fails('Xafter', 'E776:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5179 | close |
| 5180 | endif |
| 5181 | |
| 5182 | " Test for lines with multiple quickfix entries |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 5183 | let lines =<< trim END |
| 5184 | X1:5:L5 |
| 5185 | X2:5:1:L5_1 |
| 5186 | X2:5:2:L5_2 |
| 5187 | X2:5:3:L5_3 |
| 5188 | X2:10:1:L10_1 |
| 5189 | X2:10:2:L10_2 |
| 5190 | X2:10:3:L10_3 |
| 5191 | X2:15:1:L15_1 |
| 5192 | X2:15:2:L15_2 |
| 5193 | X2:15:3:L15_3 |
| 5194 | X3:3:L3 |
| 5195 | END |
| 5196 | Xexpr lines |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5197 | edit +1 X2 |
| 5198 | Xbelow 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5199 | call assert_equal(['X2', 10, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5200 | normal 1G |
| 5201 | Xafter 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5202 | call assert_equal(['X2', 5, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5203 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5204 | normal gg |
| 5205 | Xbelow 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5206 | call assert_equal(['X2', 15, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5207 | normal gg |
| 5208 | Xafter 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5209 | call assert_equal(['X2', 15, 3], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5210 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5211 | normal G |
| 5212 | Xabove 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5213 | call assert_equal(['X2', 10, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5214 | normal G |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5215 | Xbefore 2 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5216 | call assert_equal(['X2', 15, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5217 | |
| 5218 | normal G |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5219 | Xabove 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5220 | call assert_equal(['X2', 5, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5221 | normal G |
| 5222 | Xbefore 99 |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5223 | call assert_equal(['X2', 5, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5224 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5225 | normal 10G |
| 5226 | Xabove |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5227 | call assert_equal(['X2', 5, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5228 | normal 10G$ |
| 5229 | 2Xbefore |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5230 | call assert_equal(['X2', 10, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5231 | |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5232 | normal 10G |
| 5233 | Xbelow |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5234 | call assert_equal(['X2', 15, 1], [@%, line('.'), col('.')]) |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5235 | normal 9G |
| 5236 | 5Xafter |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 5237 | call assert_equal(['X2', 15, 2], [@%, line('.'), col('.')]) |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5238 | |
| 5239 | " Invalid range |
| 5240 | if a:cchar == 'c' |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 5241 | call assert_fails('-2cbelow', 'E16:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5242 | call assert_fails('-2cafter', 'E16:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5243 | else |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 5244 | call assert_fails('-2lbelow', 'E16:') |
Bram Moolenaar | cf6a55c | 2019-05-05 15:02:30 +0200 | [diff] [blame] | 5245 | call assert_fails('-2lafter', 'E16:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 5246 | endif |
| 5247 | |
| 5248 | call delete('X1') |
| 5249 | call delete('X2') |
| 5250 | call delete('X3') |
| 5251 | call delete('X4') |
| 5252 | endfunc |
| 5253 | |
| 5254 | func Test_cbelow() |
| 5255 | call Xtest_below('c') |
| 5256 | call Xtest_below('l') |
| 5257 | endfunc |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 5258 | |
| 5259 | func Test_quickfix_count() |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 5260 | let commands =<< trim END |
| 5261 | cNext |
| 5262 | cNfile |
| 5263 | cabove |
| 5264 | cbelow |
| 5265 | cfirst |
| 5266 | clast |
| 5267 | cnewer |
| 5268 | cnext |
| 5269 | cnfile |
| 5270 | colder |
| 5271 | cprevious |
| 5272 | crewind |
| 5273 | lNext |
| 5274 | lNfile |
| 5275 | labove |
| 5276 | lbelow |
| 5277 | lfirst |
| 5278 | llast |
| 5279 | lnewer |
| 5280 | lnext |
| 5281 | lnfile |
| 5282 | lolder |
| 5283 | lprevious |
| 5284 | lrewind |
| 5285 | END |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 5286 | for cmd in commands |
| 5287 | call assert_fails('-1' .. cmd, 'E16:') |
| 5288 | call assert_fails('.' .. cmd, 'E16:') |
| 5289 | call assert_fails('%' .. cmd, 'E16:') |
| 5290 | call assert_fails('$' .. cmd, 'E16:') |
| 5291 | endfor |
| 5292 | endfunc |
Bram Moolenaar | 6a0cc91 | 2019-10-26 16:48:44 +0200 | [diff] [blame] | 5293 | |
| 5294 | " Test for aborting quickfix commands using QuickFixCmdPre |
| 5295 | func Xtest_qfcmd_abort(cchar) |
| 5296 | call s:setup_commands(a:cchar) |
| 5297 | |
| 5298 | call g:Xsetlist([], 'f') |
| 5299 | |
| 5300 | " cexpr/lexpr |
| 5301 | let e = '' |
| 5302 | try |
| 5303 | Xexpr ["F1:10:Line10", "F2:20:Line20"] |
| 5304 | catch /.*/ |
| 5305 | let e = v:exception |
| 5306 | endtry |
| 5307 | call assert_equal('AbortCmd', e) |
| 5308 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5309 | |
| 5310 | " cfile/lfile |
| 5311 | call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1') |
| 5312 | let e = '' |
| 5313 | try |
| 5314 | Xfile Xfile1 |
| 5315 | catch /.*/ |
| 5316 | let e = v:exception |
| 5317 | endtry |
| 5318 | call assert_equal('AbortCmd', e) |
| 5319 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5320 | call delete('Xfile1') |
| 5321 | |
| 5322 | " cgetbuffer/lgetbuffer |
| 5323 | enew! |
| 5324 | call append(0, ["F1:10:Line10", "F2:20:Line20"]) |
| 5325 | let e = '' |
| 5326 | try |
| 5327 | Xgetbuffer |
| 5328 | catch /.*/ |
| 5329 | let e = v:exception |
| 5330 | endtry |
| 5331 | call assert_equal('AbortCmd', e) |
| 5332 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5333 | enew! |
| 5334 | |
| 5335 | " vimgrep/lvimgrep |
| 5336 | let e = '' |
| 5337 | try |
| 5338 | Xvimgrep /func/ test_quickfix.vim |
| 5339 | catch /.*/ |
| 5340 | let e = v:exception |
| 5341 | endtry |
| 5342 | call assert_equal('AbortCmd', e) |
| 5343 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5344 | |
| 5345 | " helpgrep/lhelpgrep |
| 5346 | let e = '' |
| 5347 | try |
| 5348 | Xhelpgrep quickfix |
| 5349 | catch /.*/ |
| 5350 | let e = v:exception |
| 5351 | endtry |
| 5352 | call assert_equal('AbortCmd', e) |
| 5353 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5354 | |
| 5355 | " grep/lgrep |
| 5356 | if has('unix') |
| 5357 | let e = '' |
| 5358 | try |
| 5359 | silent Xgrep func test_quickfix.vim |
| 5360 | catch /.*/ |
| 5361 | let e = v:exception |
| 5362 | endtry |
| 5363 | call assert_equal('AbortCmd', e) |
| 5364 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 5365 | endif |
| 5366 | endfunc |
| 5367 | |
| 5368 | func Test_qfcmd_abort() |
| 5369 | augroup QF_Test |
| 5370 | au! |
| 5371 | autocmd QuickFixCmdPre * throw "AbortCmd" |
| 5372 | augroup END |
| 5373 | |
| 5374 | call Xtest_qfcmd_abort('c') |
| 5375 | call Xtest_qfcmd_abort('l') |
| 5376 | |
| 5377 | augroup QF_Test |
| 5378 | au! |
| 5379 | augroup END |
| 5380 | endfunc |
| 5381 | |
Bram Moolenaar | d8a8c4c | 2019-11-16 21:04:57 +0100 | [diff] [blame] | 5382 | " Test for using a file in one of the parent directories. |
| 5383 | func Test_search_in_dirstack() |
| 5384 | call mkdir('Xtestdir/a/b/c', 'p') |
| 5385 | let save_cwd = getcwd() |
| 5386 | call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1') |
| 5387 | call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2') |
| 5388 | call writefile(["X3_L1", "X3_L2"], 'Xtestdir/a/b/Xfile3') |
| 5389 | call writefile(["X4_L1", "X4_L2"], 'Xtestdir/a/b/c/Xfile4') |
| 5390 | |
| 5391 | let lines = "Entering dir Xtestdir\n" . |
| 5392 | \ "Entering dir a\n" . |
| 5393 | \ "Entering dir b\n" . |
| 5394 | \ "Xfile2:2:X2_L2\n" . |
| 5395 | \ "Leaving dir a\n" . |
| 5396 | \ "Xfile1:2:X1_L2\n" . |
| 5397 | \ "Xfile3:1:X3_L1\n" . |
| 5398 | \ "Entering dir c\n" . |
| 5399 | \ "Xfile4:2:X4_L2\n" . |
Bram Moolenaar | 88a3e2b | 2019-12-06 21:11:39 +0100 | [diff] [blame] | 5400 | \ "Leaving dir c\n" |
Bram Moolenaar | d8a8c4c | 2019-11-16 21:04:57 +0100 | [diff] [blame] | 5401 | set efm=%DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m |
Bram Moolenaar | 88a3e2b | 2019-12-06 21:11:39 +0100 | [diff] [blame] | 5402 | cexpr lines .. "Leaving dir Xtestdir|\n" | let next = 1 |
Bram Moolenaar | d8a8c4c | 2019-11-16 21:04:57 +0100 | [diff] [blame] | 5403 | call assert_equal(11, getqflist({'size' : 0}).size) |
| 5404 | call assert_equal(4, getqflist({'idx' : 0}).idx) |
| 5405 | call assert_equal('X2_L2', getline('.')) |
Bram Moolenaar | 88a3e2b | 2019-12-06 21:11:39 +0100 | [diff] [blame] | 5406 | call assert_equal(1, next) |
Bram Moolenaar | d8a8c4c | 2019-11-16 21:04:57 +0100 | [diff] [blame] | 5407 | cnext |
| 5408 | call assert_equal(6, getqflist({'idx' : 0}).idx) |
| 5409 | call assert_equal('X1_L2', getline('.')) |
| 5410 | cnext |
| 5411 | call assert_equal(7, getqflist({'idx' : 0}).idx) |
| 5412 | call assert_equal(1, line('$')) |
| 5413 | call assert_equal('', getline(1)) |
| 5414 | cnext |
| 5415 | call assert_equal(9, getqflist({'idx' : 0}).idx) |
| 5416 | call assert_equal(1, line('$')) |
| 5417 | call assert_equal('', getline(1)) |
| 5418 | |
| 5419 | set efm& |
| 5420 | exe 'cd ' . save_cwd |
| 5421 | call delete('Xtestdir', 'rf') |
| 5422 | endfunc |
| 5423 | |
Bram Moolenaar | 1860bde | 2020-01-06 21:47:21 +0100 | [diff] [blame] | 5424 | " Test for :cquit |
| 5425 | func Test_cquit() |
| 5426 | " Exit Vim with a non-zero value |
| 5427 | if RunVim([], ["cquit 7"], '') |
| 5428 | call assert_equal(7, v:shell_error) |
| 5429 | endif |
| 5430 | |
| 5431 | if RunVim([], ["50cquit"], '') |
| 5432 | call assert_equal(50, v:shell_error) |
| 5433 | endif |
| 5434 | |
| 5435 | " Exit Vim with default value |
| 5436 | if RunVim([], ["cquit"], '') |
| 5437 | call assert_equal(1, v:shell_error) |
| 5438 | endif |
| 5439 | |
| 5440 | " Exit Vim with zero value |
| 5441 | if RunVim([], ["cquit 0"], '') |
| 5442 | call assert_equal(0, v:shell_error) |
| 5443 | endif |
| 5444 | |
| 5445 | " Exit Vim with negative value |
| 5446 | call assert_fails('-3cquit', 'E16:') |
| 5447 | endfunc |
| 5448 | |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5449 | " Test for getting a specific item from a quickfix list |
| 5450 | func Xtest_getqflist_by_idx(cchar) |
| 5451 | call s:setup_commands(a:cchar) |
| 5452 | " Empty list |
| 5453 | call assert_equal([], g:Xgetlist({'idx' : 1, 'items' : 0}).items) |
| 5454 | Xexpr ['F1:10:L10', 'F1:20:L20'] |
| 5455 | let l = g:Xgetlist({'idx' : 2, 'items' : 0}).items |
| 5456 | call assert_equal(bufnr('F1'), l[0].bufnr) |
| 5457 | call assert_equal(20, l[0].lnum) |
| 5458 | call assert_equal('L20', l[0].text) |
| 5459 | call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) |
| 5460 | call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 5461 | call assert_equal({}, g:Xgetlist(#{idx: "abc"})) |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5462 | %bwipe! |
| 5463 | endfunc |
| 5464 | |
| 5465 | func Test_getqflist_by_idx() |
| 5466 | call Xtest_getqflist_by_idx('c') |
| 5467 | call Xtest_getqflist_by_idx('l') |
| 5468 | endfunc |
| 5469 | |
| 5470 | " Test for the 'quickfixtextfunc' setting |
| 5471 | func Tqfexpr(info) |
| 5472 | if a:info.quickfix |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5473 | let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5474 | else |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5475 | let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5476 | endif |
| 5477 | |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5478 | let l = [] |
| 5479 | for idx in range(a:info.start_idx - 1, a:info.end_idx - 1) |
| 5480 | let e = qfl[idx] |
| 5481 | let s = '' |
| 5482 | if e.bufnr != 0 |
| 5483 | let bname = bufname(e.bufnr) |
| 5484 | let s ..= fnamemodify(bname, ':.') |
| 5485 | endif |
| 5486 | let s ..= '-' |
| 5487 | let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' |
| 5488 | let s ..= e.text |
| 5489 | call add(l, s) |
| 5490 | endfor |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5491 | |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5492 | return l |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5493 | endfunc |
| 5494 | |
| 5495 | func Xtest_qftextfunc(cchar) |
| 5496 | call s:setup_commands(a:cchar) |
| 5497 | |
| 5498 | set efm=%f:%l:%c:%m |
| 5499 | set quickfixtextfunc=Tqfexpr |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 5500 | call assert_equal('Tqfexpr', &quickfixtextfunc) |
| 5501 | call assert_equal('', |
| 5502 | \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 5503 | call g:Xsetlist([ |
| 5504 | \ { 'filename': 'F1', 'lnum': 10, 'col': 2, |
| 5505 | \ 'end_col': 7, 'text': 'green'}, |
| 5506 | \ { 'filename': 'F1', 'lnum': 20, 'end_lnum': 25, 'col': 4, |
| 5507 | \ 'end_col': 8, 'text': 'blue'}, |
| 5508 | \ ]) |
| 5509 | |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5510 | Xwindow |
| 5511 | call assert_equal('F1-L10C2-green', getline(1)) |
| 5512 | call assert_equal('F1-L20C4-blue', getline(2)) |
| 5513 | Xclose |
| 5514 | set quickfixtextfunc&vim |
| 5515 | Xwindow |
thinca | 6864efa | 2021-06-19 20:45:20 +0200 | [diff] [blame] | 5516 | call assert_equal('F1|10 col 2-7| green', getline(1)) |
| 5517 | call assert_equal('F1|20-25 col 4-8| blue', getline(2)) |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5518 | Xclose |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 5519 | |
| 5520 | set efm=%f:%l:%c:%m |
| 5521 | set quickfixtextfunc=Tqfexpr |
| 5522 | " Update the list with only the cwindow |
| 5523 | Xwindow |
| 5524 | only |
| 5525 | call g:Xsetlist([ |
| 5526 | \ { 'filename': 'F2', 'lnum': 20, 'col': 2, |
| 5527 | \ 'end_col': 7, 'text': 'red'} |
| 5528 | \ ]) |
| 5529 | call assert_equal(['F2-L20C2-red'], getline(1, '$')) |
| 5530 | new |
| 5531 | Xclose |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5532 | set efm& |
| 5533 | set quickfixtextfunc& |
| 5534 | |
| 5535 | " Test for per list 'quickfixtextfunc' setting |
| 5536 | func PerQfText(info) |
| 5537 | if a:info.quickfix |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5538 | let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5539 | else |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5540 | let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5541 | endif |
| 5542 | if empty(qfl) |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5543 | return [] |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5544 | endif |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5545 | let l = [] |
| 5546 | for idx in range(a:info.start_idx - 1, a:info.end_idx - 1) |
| 5547 | call add(l, 'Line ' .. qfl[idx].lnum .. ', Col ' .. qfl[idx].col) |
| 5548 | endfor |
| 5549 | return l |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5550 | endfunc |
| 5551 | set quickfixtextfunc=Tqfexpr |
| 5552 | call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"}) |
| 5553 | Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] |
| 5554 | Xwindow |
| 5555 | call assert_equal('Line 10, Col 2', getline(1)) |
| 5556 | call assert_equal('Line 20, Col 4', getline(2)) |
| 5557 | Xclose |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 5558 | call assert_equal(function('PerQfText'), |
| 5559 | \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) |
Bram Moolenaar | 7ba5a7e | 2020-06-08 19:20:27 +0200 | [diff] [blame] | 5560 | " Add entries to the list when the quickfix buffer is hidden |
| 5561 | Xaddexpr ['F1:30:6:red'] |
| 5562 | Xwindow |
| 5563 | call assert_equal('Line 30, Col 6', getline(3)) |
| 5564 | Xclose |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5565 | call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 5566 | call assert_equal('', g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5567 | set quickfixtextfunc& |
| 5568 | delfunc PerQfText |
| 5569 | |
| 5570 | " Non-existing function |
| 5571 | set quickfixtextfunc=Tabc |
| 5572 | call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') |
| 5573 | call assert_fails("Xwindow", 'E117:') |
| 5574 | Xclose |
| 5575 | set quickfixtextfunc& |
| 5576 | |
| 5577 | " set option to a non-function |
| 5578 | set quickfixtextfunc=[10,\ 20] |
| 5579 | call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') |
| 5580 | call assert_fails("Xwindow", 'E117:') |
| 5581 | Xclose |
| 5582 | set quickfixtextfunc& |
| 5583 | |
| 5584 | " set option to a function with different set of arguments |
| 5585 | func Xqftext(a, b, c) |
| 5586 | return a:a .. a:b .. a:c |
| 5587 | endfunc |
| 5588 | set quickfixtextfunc=Xqftext |
| 5589 | call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E119:') |
| 5590 | call assert_fails("Xwindow", 'E119:') |
| 5591 | Xclose |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5592 | |
| 5593 | " set option to a function that returns a list with non-strings |
| 5594 | func Xqftext2(d) |
| 5595 | return ['one', [], 'two'] |
| 5596 | endfunc |
| 5597 | set quickfixtextfunc=Xqftext2 |
| 5598 | call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']", |
| 5599 | \ 'E730:') |
| 5600 | call assert_fails('Xwindow', 'E730:') |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 5601 | call assert_equal(['one', 'F1|20 col 4| blue', 'F1|30 col 6| red'], |
| 5602 | \ getline(1, '$')) |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5603 | Xclose |
| 5604 | |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5605 | set quickfixtextfunc& |
| 5606 | delfunc Xqftext |
Bram Moolenaar | 00e260b | 2020-06-11 19:35:52 +0200 | [diff] [blame] | 5607 | delfunc Xqftext2 |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 5608 | |
| 5609 | " set the global option to a lambda function |
| 5610 | set quickfixtextfunc={d\ ->\ map(g:Xgetlist({'id'\ :\ d.id,\ 'items'\ :\ 1}).items[d.start_idx-1:d.end_idx-1],\ 'v:val.text')} |
| 5611 | Xexpr ['F1:10:2:green', 'F1:20:4:blue'] |
| 5612 | Xwindow |
| 5613 | call assert_equal(['green', 'blue'], getline(1, '$')) |
| 5614 | Xclose |
| 5615 | call assert_equal("{d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1], 'v:val.text')}", &quickfixtextfunc) |
| 5616 | set quickfixtextfunc& |
| 5617 | |
| 5618 | " use a lambda function that returns an empty list |
| 5619 | set quickfixtextfunc={d\ ->\ []} |
| 5620 | Xexpr ['F1:10:2:green', 'F1:20:4:blue'] |
| 5621 | Xwindow |
| 5622 | call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'], |
| 5623 | \ getline(1, '$')) |
| 5624 | Xclose |
| 5625 | set quickfixtextfunc& |
| 5626 | |
| 5627 | " use a lambda function that returns a list with empty strings |
| 5628 | set quickfixtextfunc={d\ ->\ ['',\ '']} |
| 5629 | Xexpr ['F1:10:2:green', 'F1:20:4:blue'] |
| 5630 | Xwindow |
| 5631 | call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'], |
| 5632 | \ getline(1, '$')) |
| 5633 | Xclose |
| 5634 | set quickfixtextfunc& |
| 5635 | |
| 5636 | " set the per-quickfix list text function to a lambda function |
| 5637 | call g:Xsetlist([], ' ', |
| 5638 | \ {'quickfixtextfunc' : |
| 5639 | \ {d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1], |
| 5640 | \ "'Line ' .. v:val.lnum .. ', Col ' .. v:val.col")}}) |
| 5641 | Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] |
| 5642 | Xwindow |
| 5643 | call assert_equal('Line 10, Col 2', getline(1)) |
| 5644 | call assert_equal('Line 20, Col 4', getline(2)) |
| 5645 | Xclose |
| 5646 | call assert_match("function('<lambda>\\d\\+')", string(g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc)) |
| 5647 | call g:Xsetlist([], 'f') |
Bram Moolenaar | 858ba06 | 2020-05-31 23:11:59 +0200 | [diff] [blame] | 5648 | endfunc |
| 5649 | |
| 5650 | func Test_qftextfunc() |
| 5651 | call Xtest_qftextfunc('c') |
| 5652 | call Xtest_qftextfunc('l') |
| 5653 | endfunc |
| 5654 | |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5655 | func Test_qftextfunc_callback() |
| 5656 | let lines =<< trim END |
| 5657 | set efm=%f:%l:%c:%m |
| 5658 | |
Yegappan Lakshmanan | 04ef1fb | 2021-12-12 20:08:05 +0000 | [diff] [blame] | 5659 | #" Test for using a function name |
| 5660 | LET &qftf = 'g:Tqfexpr' |
| 5661 | cexpr "F0:0:0:L0" |
| 5662 | copen |
| 5663 | call assert_equal('F0-L0C0-L0', getline(1)) |
| 5664 | cclose |
| 5665 | |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5666 | #" Test for using a function() |
| 5667 | set qftf=function('g:Tqfexpr') |
| 5668 | cexpr "F1:1:1:L1" |
| 5669 | copen |
| 5670 | call assert_equal('F1-L1C1-L1', getline(1)) |
| 5671 | cclose |
| 5672 | |
| 5673 | #" Using a funcref variable to set 'quickfixtextfunc' |
| 5674 | VAR Fn = function('g:Tqfexpr') |
| 5675 | LET &qftf = Fn |
| 5676 | cexpr "F2:2:2:L2" |
| 5677 | copen |
| 5678 | call assert_equal('F2-L2C2-L2', getline(1)) |
| 5679 | cclose |
| 5680 | |
| 5681 | #" Using string(funcref_variable) to set 'quickfixtextfunc' |
| 5682 | LET Fn = function('g:Tqfexpr') |
| 5683 | LET &qftf = string(Fn) |
| 5684 | cexpr "F3:3:3:L3" |
| 5685 | copen |
| 5686 | call assert_equal('F3-L3C3-L3', getline(1)) |
| 5687 | cclose |
| 5688 | |
| 5689 | #" Test for using a funcref() |
| 5690 | set qftf=funcref('g:Tqfexpr') |
| 5691 | cexpr "F4:4:4:L4" |
| 5692 | copen |
| 5693 | call assert_equal('F4-L4C4-L4', getline(1)) |
| 5694 | cclose |
| 5695 | |
| 5696 | #" Using a funcref variable to set 'quickfixtextfunc' |
| 5697 | LET Fn = funcref('g:Tqfexpr') |
| 5698 | LET &qftf = Fn |
| 5699 | cexpr "F5:5:5:L5" |
| 5700 | copen |
| 5701 | call assert_equal('F5-L5C5-L5', getline(1)) |
| 5702 | cclose |
| 5703 | |
| 5704 | #" Using a string(funcref_variable) to set 'quickfixtextfunc' |
| 5705 | LET Fn = funcref('g:Tqfexpr') |
| 5706 | LET &qftf = string(Fn) |
| 5707 | cexpr "F5:5:5:L5" |
| 5708 | copen |
| 5709 | call assert_equal('F5-L5C5-L5', getline(1)) |
| 5710 | cclose |
| 5711 | |
| 5712 | #" Test for using a lambda function with set |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5713 | VAR optval = "LSTART a LMIDDLE g:Tqfexpr(a) LEND" |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5714 | LET optval = substitute(optval, ' ', '\\ ', 'g') |
| 5715 | exe "set qftf=" .. optval |
| 5716 | cexpr "F6:6:6:L6" |
| 5717 | copen |
| 5718 | call assert_equal('F6-L6C6-L6', getline(1)) |
| 5719 | cclose |
| 5720 | |
| 5721 | #" Set 'quickfixtextfunc' to a lambda expression |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5722 | LET &qftf = LSTART a LMIDDLE g:Tqfexpr(a) LEND |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5723 | cexpr "F7:7:7:L7" |
| 5724 | copen |
| 5725 | call assert_equal('F7-L7C7-L7', getline(1)) |
| 5726 | cclose |
| 5727 | |
| 5728 | #" Set 'quickfixtextfunc' to string(lambda_expression) |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5729 | LET &qftf = "LSTART a LMIDDLE g:Tqfexpr(a) LEND" |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5730 | cexpr "F8:8:8:L8" |
| 5731 | copen |
| 5732 | call assert_equal('F8-L8C8-L8', getline(1)) |
| 5733 | cclose |
| 5734 | |
| 5735 | #" Set 'quickfixtextfunc' to a variable with a lambda expression |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5736 | VAR Lambda = LSTART a LMIDDLE g:Tqfexpr(a) LEND |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5737 | LET &qftf = Lambda |
| 5738 | cexpr "F9:9:9:L9" |
| 5739 | copen |
| 5740 | call assert_equal('F9-L9C9-L9', getline(1)) |
| 5741 | cclose |
| 5742 | |
| 5743 | #" Set 'quickfixtextfunc' to a string(variable with a lambda expression) |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5744 | LET Lambda = LSTART a LMIDDLE g:Tqfexpr(a) LEND |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5745 | LET &qftf = string(Lambda) |
| 5746 | cexpr "F9:9:9:L9" |
| 5747 | copen |
| 5748 | call assert_equal('F9-L9C9-L9', getline(1)) |
| 5749 | cclose |
| 5750 | END |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 5751 | call v9.CheckLegacyAndVim9Success(lines) |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5752 | |
Yegappan Lakshmanan | db1a410 | 2021-12-17 16:21:20 +0000 | [diff] [blame] | 5753 | " Test for using a script-local function name |
| 5754 | func s:TqfFunc2(info) |
| 5755 | let g:TqfFunc2Args = [a:info.start_idx, a:info.end_idx] |
| 5756 | return '' |
| 5757 | endfunc |
| 5758 | let g:TqfFunc2Args = [] |
| 5759 | set quickfixtextfunc=s:TqfFunc2 |
| 5760 | cexpr "F10:10:10:L10" |
| 5761 | cclose |
| 5762 | call assert_equal([1, 1], g:TqfFunc2Args) |
| 5763 | |
| 5764 | let &quickfixtextfunc = 's:TqfFunc2' |
| 5765 | cexpr "F11:11:11:L11" |
| 5766 | cclose |
| 5767 | call assert_equal([1, 1], g:TqfFunc2Args) |
| 5768 | delfunc s:TqfFunc2 |
| 5769 | |
Yegappan Lakshmanan | 6ae8fae | 2021-12-12 16:26:44 +0000 | [diff] [blame] | 5770 | " set 'quickfixtextfunc' to a partial with dict. This used to cause a crash. |
| 5771 | func SetQftfFunc() |
| 5772 | let params = {'qftf': function('g:DictQftfFunc')} |
| 5773 | let &quickfixtextfunc = params.qftf |
| 5774 | endfunc |
| 5775 | func g:DictQftfFunc(_) dict |
| 5776 | endfunc |
| 5777 | call SetQftfFunc() |
| 5778 | new |
| 5779 | call SetQftfFunc() |
| 5780 | bw |
| 5781 | call test_garbagecollect_now() |
| 5782 | new |
| 5783 | set qftf= |
| 5784 | wincmd w |
| 5785 | set qftf= |
| 5786 | :%bw! |
| 5787 | |
| 5788 | " set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used |
| 5789 | " to cause a crash. |
| 5790 | let &qftf = '' |
| 5791 | func SetLocalQftfFunc() |
| 5792 | let params = {'qftf': function('g:DictQftfFunc')} |
| 5793 | call setqflist([], 'a', {'quickfixtextfunc' : params.qftf}) |
| 5794 | endfunc |
| 5795 | call SetLocalQftfFunc() |
| 5796 | call test_garbagecollect_now() |
| 5797 | call setqflist([], 'a', {'quickfixtextfunc' : ''}) |
| 5798 | delfunc g:DictQftfFunc |
| 5799 | delfunc SetQftfFunc |
| 5800 | delfunc SetLocalQftfFunc |
| 5801 | set efm& |
| 5802 | endfunc |
| 5803 | |
Yegappan Lakshmanan | ad52f96 | 2021-06-19 18:22:53 +0200 | [diff] [blame] | 5804 | " Test for updating a location list for some other window and check that |
| 5805 | " 'qftextfunc' uses the correct location list. |
| 5806 | func Test_qftextfunc_other_loclist() |
| 5807 | %bw! |
| 5808 | call setloclist(0, [], 'f') |
| 5809 | |
| 5810 | " create a window and a location list for it and open the location list |
| 5811 | " window |
| 5812 | lexpr ['F1:10:12:one', 'F1:20:14:two'] |
| 5813 | let w1_id = win_getid() |
| 5814 | call setloclist(0, [], ' ', |
| 5815 | \ {'lines': ['F1:10:12:one', 'F1:20:14:two'], |
| 5816 | \ 'quickfixtextfunc': |
| 5817 | \ {d -> map(getloclist(d.winid, {'id' : d.id, |
| 5818 | \ 'items' : 1}).items[d.start_idx-1:d.end_idx-1], |
| 5819 | \ "'Line ' .. v:val.lnum .. ', Col ' .. v:val.col")}}) |
| 5820 | lwindow |
| 5821 | let w2_id = win_getid() |
| 5822 | |
| 5823 | " create another window and a location list for it and open the location |
| 5824 | " list window |
| 5825 | topleft new |
| 5826 | let w3_id = win_getid() |
| 5827 | call setloclist(0, [], ' ', |
| 5828 | \ {'lines': ['F2:30:32:eleven', 'F2:40:34:twelve'], |
| 5829 | \ 'quickfixtextfunc': |
| 5830 | \ {d -> map(getloclist(d.winid, {'id' : d.id, |
| 5831 | \ 'items' : 1}).items[d.start_idx-1:d.end_idx-1], |
| 5832 | \ "'Ligne ' .. v:val.lnum .. ', Colonne ' .. v:val.col")}}) |
| 5833 | lwindow |
| 5834 | let w4_id = win_getid() |
| 5835 | |
| 5836 | topleft new |
| 5837 | lexpr ['F3:50:52:green', 'F3:60:54:blue'] |
| 5838 | let w5_id = win_getid() |
| 5839 | |
| 5840 | " change the location list for some other window |
| 5841 | call setloclist(0, [], 'r', {'lines': ['F3:55:56:aaa', 'F3:57:58:bbb']}) |
| 5842 | call setloclist(w1_id, [], 'r', {'lines': ['F1:62:63:bbb', 'F1:64:65:ccc']}) |
| 5843 | call setloclist(w3_id, [], 'r', {'lines': ['F2:76:77:ddd', 'F2:78:79:eee']}) |
| 5844 | call assert_equal(['Line 62, Col 63', 'Line 64, Col 65'], |
| 5845 | \ getbufline(winbufnr(w2_id), 1, '$')) |
| 5846 | call assert_equal(['Ligne 76, Colonne 77', 'Ligne 78, Colonne 79'], |
| 5847 | \ getbufline(winbufnr(w4_id), 1, '$')) |
| 5848 | call setloclist(w2_id, [], 'r', {'lines': ['F1:32:33:fff', 'F1:34:35:ggg']}) |
| 5849 | call setloclist(w4_id, [], 'r', {'lines': ['F2:46:47:hhh', 'F2:48:49:jjj']}) |
| 5850 | call assert_equal(['Line 32, Col 33', 'Line 34, Col 35'], |
| 5851 | \ getbufline(winbufnr(w2_id), 1, '$')) |
| 5852 | call assert_equal(['Ligne 46, Colonne 47', 'Ligne 48, Colonne 49'], |
| 5853 | \ getbufline(winbufnr(w4_id), 1, '$')) |
| 5854 | |
| 5855 | call win_gotoid(w5_id) |
| 5856 | lwindow |
| 5857 | call assert_equal(['F3|55 col 56| aaa', 'F3|57 col 58| bbb'], |
| 5858 | \ getline(1, '$')) |
| 5859 | %bw! |
| 5860 | endfunc |
| 5861 | |
Bram Moolenaar | ec98e93 | 2020-06-08 19:35:59 +0200 | [diff] [blame] | 5862 | " Running :lhelpgrep command more than once in a help window, doesn't jump to |
| 5863 | " the help topic |
| 5864 | func Test_lhelpgrep_from_help_window() |
| 5865 | call mkdir('Xtestdir/doc', 'p') |
| 5866 | call writefile(['window'], 'Xtestdir/doc/a.txt') |
| 5867 | call writefile(['buffer'], 'Xtestdir/doc/b.txt') |
| 5868 | let save_rtp = &rtp |
| 5869 | let &rtp = 'Xtestdir' |
| 5870 | lhelpgrep window |
| 5871 | lhelpgrep buffer |
| 5872 | call assert_equal('b.txt', fnamemodify(@%, ":p:t")) |
| 5873 | lhelpgrep window |
| 5874 | call assert_equal('a.txt', fnamemodify(@%, ":p:t")) |
| 5875 | let &rtp = save_rtp |
| 5876 | call delete('Xtestdir', 'rf') |
| 5877 | new | only! |
| 5878 | endfunc |
| 5879 | |
Bram Moolenaar | f7c4d83 | 2020-08-11 20:42:19 +0200 | [diff] [blame] | 5880 | " Test for the crash fixed by 7.3.715 |
| 5881 | func Test_setloclist_crash() |
| 5882 | %bw! |
| 5883 | let g:BufNum = bufnr() |
| 5884 | augroup QF_Test |
| 5885 | au! |
| 5886 | au BufUnload * call setloclist(0, [{'bufnr':g:BufNum, 'lnum':1, 'col':1, 'text': 'tango down'}]) |
| 5887 | augroup END |
| 5888 | |
| 5889 | try |
| 5890 | lvimgrep /.*/ *.mak |
| 5891 | catch /E926:/ |
| 5892 | endtry |
| 5893 | call assert_equal('tango down', getloclist(0, {'items' : 0}).items[0].text) |
| 5894 | call assert_equal(1, getloclist(0, {'size' : 0}).size) |
| 5895 | |
| 5896 | augroup QF_Test |
| 5897 | au! |
| 5898 | augroup END |
| 5899 | unlet g:BufNum |
| 5900 | %bw! |
| 5901 | endfunc |
| 5902 | |
Bram Moolenaar | 2ce7790 | 2020-11-14 13:15:24 +0100 | [diff] [blame] | 5903 | " Test for adding an invalid entry with the quickfix window open and making |
| 5904 | " sure that the window contents are not changed |
| 5905 | func Test_add_invalid_entry_with_qf_window() |
| 5906 | call setqflist([], 'f') |
| 5907 | cexpr "Xfile1:10:aa" |
| 5908 | copen |
| 5909 | call setqflist(['bb'], 'a') |
| 5910 | call assert_equal(1, line('$')) |
| 5911 | call assert_equal(['Xfile1|10| aa'], getline(1, '$')) |
shane.xb.qian | 0d5e1ec | 2021-06-20 16:31:00 +0200 | [diff] [blame] | 5912 | call assert_equal([{'lnum': 10 , 'end_lnum': 0 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5913 | |
| 5914 | call setqflist([{'lnum': 10 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5915 | call assert_equal(1 , line('$')) |
| 5916 | call assert_equal(['Xfile1|10| aa'] , getline(1 , '$')) |
| 5917 | call assert_equal([{'lnum': 10 , 'end_lnum': 0 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5918 | |
| 5919 | call setqflist([{'lnum': 10 , 'end_lnum': 0 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5920 | call assert_equal(1 , line('$')) |
| 5921 | call assert_equal(['Xfile1|10| aa'] , getline(1 , '$')) |
| 5922 | call assert_equal([{'lnum': 10 , 'end_lnum': 0 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5923 | |
| 5924 | call setqflist([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': -456 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5925 | call assert_equal(1 , line('$')) |
| 5926 | call assert_equal(['Xfile1|10| aa'] , getline(1 , '$')) |
| 5927 | call assert_equal([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 0 , 'end_col': -456 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5928 | |
| 5929 | call setqflist([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5930 | call assert_equal(1 , line('$')) |
| 5931 | call assert_equal(['Xfile1|10 col 666| aa'] , getline(1 , '$')) |
| 5932 | call assert_equal([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 0 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5933 | |
| 5934 | call setqflist([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': -456 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5935 | call assert_equal(1 , line('$')) |
| 5936 | call assert_equal(['Xfile1|10 col 666| aa'] , getline(1 , '$')) |
| 5937 | call assert_equal([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': -456 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5938 | |
| 5939 | call setqflist([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 222 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5940 | call assert_equal(1 , line('$')) |
| 5941 | call assert_equal(['Xfile1|10 col 666-222| aa'] , getline(1 , '$')) |
| 5942 | call assert_equal([{'lnum': 10 , 'end_lnum': -123 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 222 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
| 5943 | |
| 5944 | call setqflist([{'lnum': 10 , 'end_lnum': 6 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 222 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , 'r') |
| 5945 | call assert_equal(1 , line('$')) |
| 5946 | call assert_equal(['Xfile1|10-6 col 666-222| aa'] , getline(1 , '$')) |
| 5947 | call assert_equal([{'lnum': 10 , 'end_lnum': 6 , 'bufnr': bufnr('Xfile1') , 'col': 666 , 'end_col': 222 , 'pattern': '' , 'valid': 1 , 'vcol': 0 , 'nr': -1 , 'type': '' , 'module': '' , 'text': 'aa'}] , getqflist()) |
Bram Moolenaar | 2ce7790 | 2020-11-14 13:15:24 +0100 | [diff] [blame] | 5948 | cclose |
| 5949 | endfunc |
| 5950 | |
Bram Moolenaar | 9e40c4b | 2020-11-23 20:15:08 +0100 | [diff] [blame] | 5951 | " Test for very weird problem: autocommand causes a failure, resulting opening |
| 5952 | " the quickfix window to fail. This still splits the window, but otherwise |
| 5953 | " should not mess up buffers. |
| 5954 | func Test_quickfix_window_fails_to_open() |
| 5955 | CheckScreendump |
| 5956 | |
| 5957 | let lines =<< trim END |
| 5958 | anything |
| 5959 | try |
| 5960 | anything |
| 5961 | endtry |
| 5962 | END |
| 5963 | call writefile(lines, 'XquickfixFails') |
| 5964 | |
| 5965 | let lines =<< trim END |
| 5966 | split XquickfixFails |
| 5967 | silent vimgrep anything % |
| 5968 | normal o |
| 5969 | au BufLeave * ++once source XquickfixFails |
| 5970 | " This will trigger the autocommand, which causes an error, what follows |
| 5971 | " is aborted but the window was already split. |
| 5972 | silent! cwindow |
| 5973 | END |
| 5974 | call writefile(lines, 'XtestWinFails') |
| 5975 | let buf = RunVimInTerminal('-S XtestWinFails', #{rows: 13}) |
| 5976 | call VerifyScreenDump(buf, 'Test_quickfix_window_fails', {}) |
| 5977 | |
| 5978 | " clean up |
| 5979 | call term_sendkeys(buf, ":bwipe!\<CR>") |
| 5980 | call term_wait(buf) |
| 5981 | call StopVimInTerminal(buf) |
| 5982 | call delete('XtestWinFails') |
| 5983 | call delete('XquickfixFails') |
| 5984 | endfunc |
| 5985 | |
Bram Moolenaar | 2d870f8 | 2020-12-05 13:41:01 +0100 | [diff] [blame] | 5986 | " Test for updating the quickfix buffer whenever the associated quickfix list |
Bram Moolenaar | 287153c | 2020-11-29 14:20:27 +0100 | [diff] [blame] | 5987 | " is changed. |
| 5988 | func Xqfbuf_update(cchar) |
| 5989 | call s:setup_commands(a:cchar) |
| 5990 | |
| 5991 | Xexpr "F1:1:line1" |
| 5992 | Xopen |
| 5993 | call assert_equal(['F1|1| line1'], getline(1, '$')) |
| 5994 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 5995 | |
| 5996 | " Test setqflist() using the 'lines' key in 'what' |
| 5997 | " add a new entry |
| 5998 | call g:Xsetlist([], 'a', {'lines' : ['F2:2: line2']}) |
| 5999 | call assert_equal(['F1|1| line1', 'F2|2| line2'], getline(1, '$')) |
| 6000 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6001 | " replace all the entries with a single entry |
| 6002 | call g:Xsetlist([], 'r', {'lines' : ['F3:3: line3']}) |
| 6003 | call assert_equal(['F3|3| line3'], getline(1, '$')) |
| 6004 | call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6005 | " remove all the entries |
| 6006 | call g:Xsetlist([], 'r', {'lines' : []}) |
| 6007 | call assert_equal([''], getline(1, '$')) |
| 6008 | call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6009 | " add a new list |
| 6010 | call g:Xsetlist([], ' ', {'lines' : ['F4:4: line4']}) |
| 6011 | call assert_equal(['F4|4| line4'], getline(1, '$')) |
| 6012 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6013 | |
| 6014 | " Test setqflist() using the 'items' key in 'what' |
| 6015 | " add a new entry |
| 6016 | call g:Xsetlist([], 'a', {'items' : [{'filename' : 'F5', 'lnum' : 5, 'text' : 'line5'}]}) |
| 6017 | call assert_equal(['F4|4| line4', 'F5|5| line5'], getline(1, '$')) |
| 6018 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6019 | " replace all the entries with a single entry |
| 6020 | call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F6', 'lnum' : 6, 'text' : 'line6'}]}) |
| 6021 | call assert_equal(['F6|6| line6'], getline(1, '$')) |
| 6022 | call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6023 | " remove all the entries |
| 6024 | call g:Xsetlist([], 'r', {'items' : []}) |
| 6025 | call assert_equal([''], getline(1, '$')) |
| 6026 | call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6027 | " add a new list |
| 6028 | call g:Xsetlist([], ' ', {'items' : [{'filename' : 'F7', 'lnum' : 7, 'text' : 'line7'}]}) |
| 6029 | call assert_equal(['F7|7| line7'], getline(1, '$')) |
| 6030 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6031 | |
| 6032 | call g:Xsetlist([], ' ', {}) |
| 6033 | call assert_equal([''], getline(1, '$')) |
| 6034 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 6035 | |
| 6036 | Xclose |
| 6037 | endfunc |
| 6038 | |
| 6039 | func Test_qfbuf_update() |
| 6040 | call Xqfbuf_update('c') |
| 6041 | call Xqfbuf_update('l') |
| 6042 | endfunc |
| 6043 | |
Bram Moolenaar | 8c801b3 | 2021-03-05 20:58:22 +0100 | [diff] [blame] | 6044 | func Test_vimgrep_noswapfile() |
| 6045 | set noswapfile |
| 6046 | call writefile(['one', 'two', 'three'], 'Xgreppie') |
| 6047 | vimgrep two Xgreppie |
| 6048 | call assert_equal('two', getline('.')) |
| 6049 | |
| 6050 | call delete('Xgreppie') |
| 6051 | set swapfile |
| 6052 | endfunc |
| 6053 | |
Yegappan Lakshmanan | bb01a1e | 2021-04-26 21:17:52 +0200 | [diff] [blame] | 6054 | " Test for the :vimgrep 'f' flag (fuzzy match) |
| 6055 | func Xvimgrep_fuzzy_match(cchar) |
| 6056 | call s:setup_commands(a:cchar) |
| 6057 | |
| 6058 | Xvimgrep /three one/f Xfile* |
| 6059 | let l = g:Xgetlist() |
| 6060 | call assert_equal(2, len(l)) |
| 6061 | call assert_equal(['Xfile1', 1, 9, 'one two three'], |
| 6062 | \ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text]) |
| 6063 | call assert_equal(['Xfile2', 2, 1, 'three one two'], |
| 6064 | \ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text]) |
| 6065 | |
| 6066 | Xvimgrep /the/f Xfile* |
| 6067 | let l = g:Xgetlist() |
| 6068 | call assert_equal(3, len(l)) |
| 6069 | call assert_equal(['Xfile1', 1, 9, 'one two three'], |
| 6070 | \ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text]) |
| 6071 | call assert_equal(['Xfile2', 2, 1, 'three one two'], |
| 6072 | \ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text]) |
| 6073 | call assert_equal(['Xfile2', 4, 4, 'aaathreeaaa'], |
| 6074 | \ [bufname(l[2].bufnr), l[2].lnum, l[2].col, l[2].text]) |
| 6075 | |
| 6076 | Xvimgrep /aaa/fg Xfile* |
| 6077 | let l = g:Xgetlist() |
| 6078 | call assert_equal(4, len(l)) |
| 6079 | call assert_equal(['Xfile1', 2, 1, 'aaaaaa'], |
| 6080 | \ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text]) |
| 6081 | call assert_equal(['Xfile1', 2, 4, 'aaaaaa'], |
| 6082 | \ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text]) |
| 6083 | call assert_equal(['Xfile2', 4, 1, 'aaathreeaaa'], |
| 6084 | \ [bufname(l[2].bufnr), l[2].lnum, l[2].col, l[2].text]) |
| 6085 | call assert_equal(['Xfile2', 4, 9, 'aaathreeaaa'], |
| 6086 | \ [bufname(l[3].bufnr), l[3].lnum, l[3].col, l[3].text]) |
| 6087 | |
| 6088 | call assert_fails('Xvimgrep /xyz/fg Xfile*', 'E480:') |
| 6089 | endfunc |
| 6090 | |
| 6091 | func Test_vimgrep_fuzzy_match() |
| 6092 | call writefile(['one two three', 'aaaaaa'], 'Xfile1') |
| 6093 | call writefile(['one', 'three one two', 'two', 'aaathreeaaa'], 'Xfile2') |
| 6094 | call Xvimgrep_fuzzy_match('c') |
| 6095 | call Xvimgrep_fuzzy_match('l') |
| 6096 | call delete('Xfile1') |
| 6097 | call delete('Xfile2') |
| 6098 | endfunc |
| 6099 | |
Wei-Chung Wen | 1557b16 | 2021-07-15 13:13:39 +0200 | [diff] [blame] | 6100 | func Test_locationlist_open_in_newtab() |
| 6101 | call s:create_test_file('Xqftestfile1') |
| 6102 | call s:create_test_file('Xqftestfile2') |
| 6103 | call s:create_test_file('Xqftestfile3') |
| 6104 | |
| 6105 | %bwipe! |
| 6106 | |
Yegappan Lakshmanan | 4a7724a | 2022-04-11 15:11:39 +0100 | [diff] [blame] | 6107 | let lines =<< trim END |
| 6108 | Xqftestfile1:5:Line5 |
| 6109 | Xqftestfile2:10:Line10 |
| 6110 | Xqftestfile3:16:Line16 |
| 6111 | END |
| 6112 | lgetexpr lines |
Wei-Chung Wen | 1557b16 | 2021-07-15 13:13:39 +0200 | [diff] [blame] | 6113 | |
| 6114 | silent! llast |
| 6115 | call assert_equal(1, tabpagenr('$')) |
| 6116 | call assert_equal('Xqftestfile3', bufname()) |
| 6117 | |
| 6118 | set switchbuf=newtab |
| 6119 | |
| 6120 | silent! lfirst |
| 6121 | call assert_equal(2, tabpagenr('$')) |
| 6122 | call assert_equal('Xqftestfile1', bufname()) |
| 6123 | |
| 6124 | silent! lnext |
| 6125 | call assert_equal(3, tabpagenr('$')) |
| 6126 | call assert_equal('Xqftestfile2', bufname()) |
| 6127 | |
| 6128 | call delete('Xqftestfile1') |
| 6129 | call delete('Xqftestfile2') |
| 6130 | call delete('Xqftestfile3') |
| 6131 | set switchbuf&vim |
| 6132 | |
| 6133 | %bwipe! |
| 6134 | endfunc |
| 6135 | |
Yegappan Lakshmanan | 28d8421 | 2021-07-31 12:43:23 +0200 | [diff] [blame] | 6136 | " Test for win_gettype() in quickfix and location list windows |
| 6137 | func Test_win_gettype() |
| 6138 | copen |
| 6139 | call assert_equal("quickfix", win_gettype()) |
| 6140 | let wid = win_getid() |
| 6141 | wincmd p |
| 6142 | call assert_equal("quickfix", win_gettype(wid)) |
| 6143 | cclose |
| 6144 | lexpr '' |
| 6145 | lopen |
| 6146 | call assert_equal("loclist", win_gettype()) |
| 6147 | let wid = win_getid() |
| 6148 | wincmd p |
| 6149 | call assert_equal("loclist", win_gettype(wid)) |
| 6150 | lclose |
| 6151 | endfunc |
| 6152 | |
Christian Brabandt | 0b226f6 | 2021-12-01 10:54:24 +0000 | [diff] [blame] | 6153 | fun Test_vimgrep_nomatch() |
| 6154 | call XexprTests('c') |
| 6155 | call g:Xsetlist([{'lnum':10,'text':'Line1'}]) |
| 6156 | copen |
| 6157 | if has("win32") |
| 6158 | call assert_fails('vimgrep foo *.zzz', 'E479:') |
| 6159 | let expected = [{'lnum': 10, 'bufnr': 0, 'end_lnum': 0, 'pattern': '', 'valid': 0, 'vcol': 0, 'nr': 0, 'module': '', 'type': '', 'end_col': 0, 'col': 0, 'text': 'Line1'}] |
| 6160 | else |
| 6161 | call assert_fails('vimgrep foo *.zzz', 'E480:') |
| 6162 | let expected = [] |
| 6163 | endif |
| 6164 | call assert_equal(expected, getqflist()) |
| 6165 | cclose |
| 6166 | endfunc |
| 6167 | |
Yegappan Lakshmanan | 78a6106 | 2021-12-08 20:03:31 +0000 | [diff] [blame] | 6168 | " Test for opening the quickfix window in two tab pages and then closing one |
| 6169 | " of the quickfix windows. This should not make the quickfix buffer unlisted. |
| 6170 | " (github issue #9300). |
| 6171 | func Test_two_qf_windows() |
| 6172 | cexpr "F1:1:line1" |
| 6173 | copen |
| 6174 | tabnew |
| 6175 | copen |
| 6176 | call assert_true(&buflisted) |
| 6177 | cclose |
| 6178 | tabfirst |
| 6179 | call assert_true(&buflisted) |
| 6180 | let bnum = bufnr() |
| 6181 | cclose |
| 6182 | " if all the quickfix windows are closed, then buffer should be unlisted. |
| 6183 | call assert_false(buflisted(bnum)) |
| 6184 | %bw! |
| 6185 | |
| 6186 | " Repeat the test for a location list |
| 6187 | lexpr "F2:2:line2" |
| 6188 | lopen |
| 6189 | let bnum = bufnr() |
| 6190 | tabnew |
| 6191 | exe "buffer" bnum |
| 6192 | tabfirst |
| 6193 | lclose |
| 6194 | tablast |
| 6195 | call assert_true(buflisted(bnum)) |
| 6196 | tabclose |
| 6197 | lopen |
| 6198 | call assert_true(buflisted(bnum)) |
| 6199 | lclose |
| 6200 | call assert_false(buflisted(bnum)) |
| 6201 | %bw! |
| 6202 | endfunc |
| 6203 | |
Bram Moolenaar | 9b4a80a | 2022-02-01 13:54:17 +0000 | [diff] [blame] | 6204 | " Weird sequence of commands that caused entering a wiped-out buffer |
| 6205 | func Test_lopen_bwipe() |
| 6206 | func R() |
| 6207 | silent! tab lopen |
| 6208 | e x |
| 6209 | silent! lfile |
| 6210 | endfunc |
| 6211 | |
| 6212 | cal R() |
| 6213 | cal R() |
| 6214 | cal R() |
| 6215 | bw! |
| 6216 | delfunc R |
| 6217 | endfunc |
| 6218 | |
Bram Moolenaar | e3537ae | 2022-02-08 15:05:20 +0000 | [diff] [blame] | 6219 | " Another sequence of commands that caused all buffers to be wiped out |
| 6220 | func Test_lopen_bwipe_all() |
| 6221 | let lines =<< trim END |
| 6222 | func R() |
| 6223 | silent! tab lopen |
| 6224 | e foo |
| 6225 | silent! lfile |
| 6226 | endfunc |
| 6227 | cal R() |
| 6228 | exe "norm \<C-W>\<C-V>0" |
| 6229 | cal R() |
| 6230 | bwipe |
| 6231 | |
| 6232 | call writefile(['done'], 'Xresult') |
| 6233 | qall! |
| 6234 | END |
| 6235 | call writefile(lines, 'Xscript') |
| 6236 | if RunVim([], [], '-u NONE -n -X -Z -e -m -s -S Xscript') |
| 6237 | call assert_equal(['done'], readfile('Xresult')) |
| 6238 | endif |
| 6239 | |
| 6240 | call delete('Xscript') |
| 6241 | call delete('Xresult') |
| 6242 | endfunc |
| 6243 | |
Yegappan Lakshmanan | 9c9be05 | 2022-02-24 12:33:17 +0000 | [diff] [blame] | 6244 | " Test for calling setqflist() function recursively |
| 6245 | func Test_recursive_setqflist() |
| 6246 | augroup QF_Test |
| 6247 | au! |
| 6248 | autocmd BufWinEnter quickfix call setqflist([], 'r') |
| 6249 | augroup END |
| 6250 | |
| 6251 | copen |
| 6252 | call assert_fails("call setqflist([], 'a')", 'E952:') |
| 6253 | |
| 6254 | augroup QF_Test |
| 6255 | au! |
| 6256 | augroup END |
| 6257 | %bw! |
| 6258 | endfunc |
| 6259 | |
| 6260 | " Test for failure to create a new window when selecting a file from the |
| 6261 | " quickfix window |
| 6262 | func Test_cwindow_newwin_fails() |
| 6263 | cgetexpr ["Xfile1:10:L10", "Xfile1:20:L20"] |
| 6264 | cwindow |
| 6265 | only |
| 6266 | let qf_wid = win_getid() |
| 6267 | " create the maximum number of scratch windows |
| 6268 | let hor_win_count = (&lines - 1)/2 |
| 6269 | let hor_split_count = hor_win_count - 1 |
| 6270 | for s in range(1, hor_split_count) | new | set buftype=nofile | endfor |
| 6271 | call win_gotoid(qf_wid) |
| 6272 | call assert_fails('exe "normal \<CR>"', 'E36:') |
| 6273 | %bw! |
| 6274 | endfunc |
| 6275 | |
| 6276 | " Test for updating the location list when only the location list window is |
| 6277 | " present and the corresponding file window is closed. |
| 6278 | func Test_loclist_update_with_llwin_only() |
| 6279 | %bw! |
| 6280 | new |
| 6281 | wincmd w |
| 6282 | lexpr ["Xfile1:1:Line1"] |
| 6283 | lopen |
| 6284 | wincmd p |
| 6285 | close |
| 6286 | call setloclist(2, [], 'r', {'lines': ["Xtest2:2:Line2"]}) |
| 6287 | call assert_equal(['Xtest2|2| Line2'], getbufline(winbufnr(2), 1, '$')) |
| 6288 | %bw! |
| 6289 | endfunc |
| 6290 | |
| 6291 | " Test for getting the quickfix list after a buffer with an error is wiped out |
| 6292 | func Test_getqflist_wiped_out_buffer() |
| 6293 | %bw! |
| 6294 | cexpr ["Xtest1:34:Wiped out"] |
| 6295 | let bnum = bufnr('Xtest1') |
| 6296 | call assert_equal(bnum, getqflist()[0].bufnr) |
| 6297 | bw Xtest1 |
| 6298 | call assert_equal(0, getqflist()[0].bufnr) |
| 6299 | %bw! |
| 6300 | endfunc |
Bram Moolenaar | 9b4a80a | 2022-02-01 13:54:17 +0000 | [diff] [blame] | 6301 | |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 6302 | " Test for the status message that is displayed when opening a new quickfix |
| 6303 | " list |
| 6304 | func Test_qflist_statusmsg() |
| 6305 | cexpr "1\n2" |
| 6306 | cexpr "1\n2\n3\ntest_quickfix.vim:1:msg" |
| 6307 | call assert_equal('(4 of 4): msg', v:statusmsg) |
| 6308 | call setqflist([], 'f') |
| 6309 | %bw! |
| 6310 | |
| 6311 | " When creating a new quickfix list, if an autocmd changes the quickfix list |
| 6312 | " in the stack, then an error message should be displayed. |
| 6313 | augroup QF_Test |
| 6314 | au! |
| 6315 | au BufEnter test_quickfix.vim colder |
| 6316 | augroup END |
| 6317 | cexpr "1\n2" |
| 6318 | call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') |
| 6319 | call setqflist([], 'f') |
| 6320 | augroup QF_Test |
| 6321 | au! |
| 6322 | augroup END |
| 6323 | %bw! |
| 6324 | |
| 6325 | augroup QF_Test |
| 6326 | au! |
| 6327 | au BufEnter test_quickfix.vim caddexpr "4" |
| 6328 | augroup END |
| 6329 | call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') |
| 6330 | call setqflist([], 'f') |
| 6331 | augroup QF_Test |
| 6332 | au! |
| 6333 | augroup END |
| 6334 | %bw! |
| 6335 | endfunc |
| 6336 | |
Bram Moolenaar | 6a0cc91 | 2019-10-26 16:48:44 +0200 | [diff] [blame] | 6337 | " vim: shiftwidth=2 sts=2 expandtab |