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 | |
| 3 | if !has('quickfix') |
| 4 | finish |
| 5 | endif |
| 6 | |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 7 | set encoding=utf-8 |
| 8 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 9 | func s:setup_commands(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 10 | if a:cchar == 'c' |
| 11 | command! -nargs=* -bang Xlist <mods>clist<bang> <args> |
| 12 | command! -nargs=* Xgetexpr <mods>cgetexpr <args> |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 13 | command! -nargs=* Xaddexpr <mods>caddexpr <args> |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 14 | command! -nargs=* -count Xolder <mods><count>colder <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 15 | command! -nargs=* Xnewer <mods>cnewer <args> |
| 16 | command! -nargs=* Xopen <mods>copen <args> |
| 17 | command! -nargs=* Xwindow <mods>cwindow <args> |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 18 | command! -nargs=* Xbottom <mods>cbottom <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 19 | command! -nargs=* Xclose <mods>cclose <args> |
| 20 | command! -nargs=* -bang Xfile <mods>cfile<bang> <args> |
| 21 | command! -nargs=* Xgetfile <mods>cgetfile <args> |
| 22 | command! -nargs=* Xaddfile <mods>caddfile <args> |
| 23 | command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args> |
| 24 | command! -nargs=* Xgetbuffer <mods>cgetbuffer <args> |
| 25 | command! -nargs=* Xaddbuffer <mods>caddbuffer <args> |
| 26 | command! -nargs=* Xrewind <mods>crewind <args> |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 27 | command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args> |
| 28 | command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 29 | command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args> |
| 30 | command! -nargs=* -bang Xlast <mods>clast<bang> <args> |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 31 | command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 32 | command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 33 | command! -nargs=* Xexpr <mods>cexpr <args> |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 34 | command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args> |
| 35 | command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args> |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 36 | command! -nargs=* Xgrep <mods> grep <args> |
| 37 | command! -nargs=* Xgrepadd <mods> grepadd <args> |
| 38 | command! -nargs=* Xhelpgrep helpgrep <args> |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 39 | command! -nargs=0 -count Xcc <count>cc |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 40 | command! -count=1 -nargs=0 Xbelow <mods><count>cbelow |
| 41 | command! -count=1 -nargs=0 Xabove <mods><count>cabove |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 42 | let g:Xgetlist = function('getqflist') |
| 43 | let g:Xsetlist = function('setqflist') |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 44 | call setqflist([], 'f') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 45 | else |
| 46 | command! -nargs=* -bang Xlist <mods>llist<bang> <args> |
| 47 | command! -nargs=* Xgetexpr <mods>lgetexpr <args> |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 48 | command! -nargs=* Xaddexpr <mods>laddexpr <args> |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 49 | command! -nargs=* -count Xolder <mods><count>lolder <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 50 | command! -nargs=* Xnewer <mods>lnewer <args> |
| 51 | command! -nargs=* Xopen <mods>lopen <args> |
| 52 | command! -nargs=* Xwindow <mods>lwindow <args> |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 53 | command! -nargs=* Xbottom <mods>lbottom <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 54 | command! -nargs=* Xclose <mods>lclose <args> |
| 55 | command! -nargs=* -bang Xfile <mods>lfile<bang> <args> |
| 56 | command! -nargs=* Xgetfile <mods>lgetfile <args> |
| 57 | command! -nargs=* Xaddfile <mods>laddfile <args> |
| 58 | command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args> |
| 59 | command! -nargs=* Xgetbuffer <mods>lgetbuffer <args> |
| 60 | command! -nargs=* Xaddbuffer <mods>laddbuffer <args> |
| 61 | command! -nargs=* Xrewind <mods>lrewind <args> |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 62 | command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args> |
| 63 | command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 64 | command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args> |
| 65 | command! -nargs=* -bang Xlast <mods>llast<bang> <args> |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 66 | command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args> |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 67 | command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args> |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 68 | command! -nargs=* Xexpr <mods>lexpr <args> |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 69 | command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args> |
| 70 | command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args> |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 71 | command! -nargs=* Xgrep <mods> lgrep <args> |
| 72 | command! -nargs=* Xgrepadd <mods> lgrepadd <args> |
| 73 | command! -nargs=* Xhelpgrep lhelpgrep <args> |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 74 | command! -nargs=0 -count Xcc <count>ll |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 75 | command! -count=1 -nargs=0 Xbelow <mods><count>lbelow |
| 76 | command! -count=1 -nargs=0 Xabove <mods><count>labove |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 77 | let g:Xgetlist = function('getloclist', [0]) |
| 78 | let g:Xsetlist = function('setloclist', [0]) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 79 | call setloclist(0, [], 'f') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 80 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 81 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 82 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 83 | " Tests for the :clist and :llist commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 84 | func XlistTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 85 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 86 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 87 | if a:cchar == 'l' |
| 88 | call assert_fails('llist', 'E776:') |
| 89 | endif |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 90 | " With an empty list, command should return error |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 91 | Xgetexpr [] |
| 92 | silent! Xlist |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 93 | call assert_true(v:errmsg ==# 'E42: No Errors') |
| 94 | |
| 95 | " Populate the list and then try |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 96 | Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1', |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 97 | \ 'non-error 2', 'Xtestfile2:2:2:Line2', |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 98 | \ 'non-error 3', 'Xtestfile3:3:1:Line3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 99 | |
| 100 | " List only valid entries |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 101 | let l = split(execute('Xlist', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 102 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 103 | \ ' 4 Xtestfile2:2 col 2: Line2', |
| 104 | \ ' 6 Xtestfile3:3 col 1: Line3'], l) |
| 105 | |
| 106 | " List all the entries |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 107 | let l = split(execute('Xlist!', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 108 | call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', |
| 109 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', |
| 110 | \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l) |
| 111 | |
| 112 | " List a range of errors |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 113 | let l = split(execute('Xlist 3,6', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 114 | call assert_equal([' 4 Xtestfile2:2 col 2: Line2', |
| 115 | \ ' 6 Xtestfile3:3 col 1: Line3'], l) |
| 116 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 117 | let l = split(execute('Xlist! 3,4', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 118 | call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
| 119 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 120 | let l = split(execute('Xlist -6,-4', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 121 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) |
| 122 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 123 | let l = split(execute('Xlist! -5,-3', ''), "\n") |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 124 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 125 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 126 | |
| 127 | " Test for '+' |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 128 | let l = split(execute('Xlist! +2', ''), "\n") |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 129 | call assert_equal([' 2 Xtestfile1:1 col 3: Line1', |
| 130 | \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 131 | |
| 132 | " Different types of errors |
| 133 | call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11}, |
| 134 | \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22}, |
| 135 | \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33}, |
| 136 | \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44}, |
| 137 | \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}]) |
| 138 | let l = split(execute('Xlist', ""), "\n") |
| 139 | call assert_equal([' 1:10 col 5 warning 11: Warning', |
| 140 | \ ' 2:20 col 10 error 22: Error', |
| 141 | \ ' 3:30 col 15 info 33: Info', |
| 142 | \ ' 4:40 col 20 x 44: Other', |
| 143 | \ ' 5:50 col 25 55: one'], l) |
| 144 | |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 145 | " Test for module names, one needs to explicitly set `'valid':v:true` so |
| 146 | call g:Xsetlist([ |
| 147 | \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true}, |
| 148 | \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true}, |
| 149 | \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}]) |
| 150 | let l = split(execute('Xlist', ""), "\n") |
| 151 | call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning', |
| 152 | \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning', |
| 153 | \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l) |
| 154 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 155 | " Error cases |
| 156 | call assert_fails('Xlist abc', 'E488:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 157 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 158 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 159 | func Test_clist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 160 | call XlistTests('c') |
| 161 | call XlistTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 162 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 163 | |
| 164 | " Tests for the :colder, :cnewer, :lolder and :lnewer commands |
| 165 | " Note that this test assumes that a quickfix/location list is |
Bram Moolenaar | cfc0a35 | 2016-01-09 20:23:00 +0100 | [diff] [blame] | 166 | " already set by the caller. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 167 | func XageTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 168 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 169 | |
Bram Moolenaar | 87f59b0 | 2019-04-04 14:04:11 +0200 | [diff] [blame] | 170 | if a:cchar == 'l' |
| 171 | " No location list for the current window |
| 172 | call assert_fails('lolder', 'E776:') |
| 173 | call assert_fails('lnewer', 'E776:') |
| 174 | endif |
| 175 | |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 176 | let list = [{'bufnr': bufnr('%'), 'lnum': 1}] |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 177 | call g:Xsetlist(list) |
| 178 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 179 | " Jumping to a non existent list should return error |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 180 | silent! Xolder 99 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 181 | call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') |
| 182 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 183 | silent! Xnewer 99 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 184 | call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') |
| 185 | |
| 186 | " Add three quickfix/location lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 187 | Xgetexpr ['Xtestfile1:1:3:Line1'] |
| 188 | Xgetexpr ['Xtestfile2:2:2:Line2'] |
| 189 | Xgetexpr ['Xtestfile3:3:1:Line3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 190 | |
| 191 | " Go back two lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 192 | Xolder |
| 193 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 194 | call assert_equal('Line2', l[0].text) |
| 195 | |
| 196 | " Go forward two lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 197 | Xnewer |
| 198 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 199 | call assert_equal('Line3', l[0].text) |
| 200 | |
| 201 | " Test for the optional count argument |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 202 | Xolder 2 |
| 203 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 204 | call assert_equal('Line1', l[0].text) |
| 205 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 206 | Xnewer 2 |
| 207 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 208 | call assert_equal('Line3', l[0].text) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 209 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 210 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 211 | func Test_cage() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 212 | call XageTests('c') |
| 213 | call XageTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 214 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 215 | |
| 216 | " Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen |
| 217 | " commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 218 | func XwindowTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 219 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 220 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 221 | " Opening the location list window without any errors should fail |
| 222 | if a:cchar == 'l' |
| 223 | call assert_fails('lopen', 'E776:') |
| 224 | endif |
| 225 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 226 | " Create a list with no valid entries |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 227 | Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 228 | |
| 229 | " Quickfix/Location window should not open with no valid errors |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 230 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 231 | call assert_true(winnr('$') == 1) |
| 232 | |
| 233 | " Create a list with valid entries |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 234 | Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', |
| 235 | \ 'Xtestfile3:3:1:Line3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 236 | |
| 237 | " Open the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 238 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 239 | call assert_true(winnr('$') == 2 && winnr() == 2 && |
| 240 | \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 241 | redraw! |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 242 | |
| 243 | " Close the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 244 | Xclose |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 245 | call assert_true(winnr('$') == 1) |
| 246 | |
| 247 | " Create a list with no valid entries |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 248 | Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 249 | |
| 250 | " Open the window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 251 | Xopen 5 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 252 | call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' |
| 253 | \ && winheight('.') == 5) |
| 254 | |
| 255 | " Opening the window again, should move the cursor to that window |
| 256 | wincmd t |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 257 | Xopen 7 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 258 | call assert_true(winnr('$') == 2 && winnr() == 2 && |
| 259 | \ winheight('.') == 7 && |
| 260 | \ getline('.') ==# '|| non-error 1') |
| 261 | |
| 262 | |
| 263 | " Calling cwindow should close the quickfix window with no valid errors |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 264 | Xwindow |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 265 | call assert_true(winnr('$') == 1) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 266 | |
| 267 | if a:cchar == 'c' |
| 268 | " Opening the quickfix window in multiple tab pages should reuse the |
| 269 | " quickfix buffer |
| 270 | Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', |
| 271 | \ 'Xtestfile3:3:1:Line3'] |
| 272 | Xopen |
| 273 | let qfbufnum = bufnr('%') |
| 274 | tabnew |
| 275 | Xopen |
| 276 | call assert_equal(qfbufnum, bufnr('%')) |
| 277 | new | only | tabonly |
| 278 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 279 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 280 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 281 | func Test_cwindow() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 282 | call XwindowTests('c') |
| 283 | call XwindowTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 284 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 285 | |
Bram Moolenaar | 36d5022 | 2019-05-02 20:17:40 +0200 | [diff] [blame] | 286 | func Test_copenHeight() |
| 287 | copen |
| 288 | wincmd H |
| 289 | let height = winheight(0) |
| 290 | copen 10 |
| 291 | call assert_equal(height, winheight(0)) |
| 292 | quit |
| 293 | endfunc |
| 294 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 295 | " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile |
| 296 | " commands. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 297 | func XfileTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 298 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 299 | |
| 300 | call writefile(['Xtestfile1:700:10:Line 700', |
| 301 | \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') |
| 302 | |
| 303 | enew! |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 304 | Xfile Xqftestfile1 |
| 305 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 306 | call assert_true(len(l) == 2 && |
| 307 | \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && |
| 308 | \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') |
| 309 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 310 | " Test with a non existent file |
| 311 | call assert_fails('Xfile non_existent_file', 'E40') |
| 312 | |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 313 | " Run cfile/lfile from a modified buffer |
| 314 | enew! |
| 315 | silent! put ='Quickfix' |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 316 | silent! Xfile Xqftestfile1 |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 317 | call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') |
| 318 | |
| 319 | call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 320 | Xaddfile Xqftestfile1 |
| 321 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 322 | call assert_true(len(l) == 3 && |
| 323 | \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') |
| 324 | |
| 325 | call writefile(['Xtestfile1:222:77:Line 222', |
| 326 | \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') |
| 327 | |
| 328 | enew! |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 329 | Xgetfile Xqftestfile1 |
| 330 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 331 | call assert_true(len(l) == 2 && |
| 332 | \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && |
| 333 | \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') |
| 334 | |
| 335 | call delete('Xqftestfile1') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 336 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 337 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 338 | func Test_cfile() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 339 | call XfileTests('c') |
| 340 | call XfileTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 341 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 342 | |
| 343 | " Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and |
| 344 | " :lgetbuffer commands. |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 345 | func XbufferTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 346 | call s:setup_commands(a:cchar) |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 347 | |
| 348 | enew! |
| 349 | silent! call setline(1, ['Xtestfile7:700:10:Line 700', |
| 350 | \ 'Xtestfile8:800:15:Line 800']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 351 | Xbuffer! |
| 352 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 353 | call assert_true(len(l) == 2 && |
| 354 | \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && |
| 355 | \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') |
| 356 | |
| 357 | enew! |
| 358 | silent! call setline(1, ['Xtestfile9:900:55:Line 900', |
| 359 | \ 'Xtestfile10:950:66:Line 950']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 360 | Xgetbuffer |
| 361 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 362 | call assert_true(len(l) == 2 && |
| 363 | \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && |
| 364 | \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') |
| 365 | |
| 366 | enew! |
| 367 | silent! call setline(1, ['Xtestfile11:700:20:Line 700', |
| 368 | \ 'Xtestfile12:750:25:Line 750']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 369 | Xaddbuffer |
| 370 | let l = g:Xgetlist() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 371 | call assert_true(len(l) == 4 && |
| 372 | \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && |
| 373 | \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && |
| 374 | \ 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] | 375 | enew! |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 376 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 377 | " Check for invalid buffer |
| 378 | call assert_fails('Xbuffer 199', 'E474:') |
| 379 | |
| 380 | " Check for unloaded buffer |
| 381 | edit Xtestfile1 |
| 382 | let bnr = bufnr('%') |
| 383 | enew! |
| 384 | call assert_fails('Xbuffer ' . bnr, 'E681:') |
| 385 | |
| 386 | " Check for invalid range |
| 387 | " Using Xbuffer will not run the range check in the cbuffer/lbuffer |
| 388 | " commands. So directly call the commands. |
| 389 | if (a:cchar == 'c') |
| 390 | call assert_fails('900,999cbuffer', 'E16:') |
| 391 | else |
| 392 | call assert_fails('900,999lbuffer', 'E16:') |
| 393 | endif |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 394 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 395 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 396 | func Test_cbuffer() |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 397 | call XbufferTests('c') |
| 398 | call XbufferTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 399 | endfunc |
Bram Moolenaar | da59dd5 | 2016-01-05 21:59:58 +0100 | [diff] [blame] | 400 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 401 | func XexprTests(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 402 | call s:setup_commands(a:cchar) |
| 403 | |
| 404 | call assert_fails('Xexpr 10', 'E777:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 405 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 406 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 407 | func Test_cexpr() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 408 | call XexprTests('c') |
| 409 | call XexprTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 410 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 411 | |
| 412 | " Tests for :cnext, :cprev, :cfirst, :clast commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 413 | func Xtest_browse(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 414 | call s:setup_commands(a:cchar) |
| 415 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 416 | call g:Xsetlist([], 'f') |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 417 | " Jumping to first or next location list entry without any error should |
| 418 | " result in failure |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 419 | if a:cchar == 'c' |
| 420 | let err = 'E42:' |
| 421 | else |
| 422 | let err = 'E776:' |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 423 | endif |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 424 | call assert_fails('Xnext', err) |
| 425 | call assert_fails('Xprev', err) |
| 426 | call assert_fails('Xnfile', err) |
| 427 | call assert_fails('Xpfile', err) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 428 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 429 | call s:create_test_file('Xqftestfile1') |
| 430 | call s:create_test_file('Xqftestfile2') |
| 431 | |
| 432 | Xgetexpr ['Xqftestfile1:5:Line5', |
| 433 | \ 'Xqftestfile1:6:Line6', |
| 434 | \ 'Xqftestfile2:10:Line10', |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 435 | \ 'Xqftestfile2:11:Line11', |
| 436 | \ 'RegularLine1', |
| 437 | \ 'RegularLine2'] |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 438 | |
| 439 | Xfirst |
| 440 | call assert_fails('Xprev', 'E553') |
| 441 | call assert_fails('Xpfile', 'E553') |
| 442 | Xnfile |
| 443 | call assert_equal('Xqftestfile2', bufname('%')) |
| 444 | call assert_equal(10, line('.')) |
| 445 | Xpfile |
| 446 | call assert_equal('Xqftestfile1', bufname('%')) |
| 447 | call assert_equal(6, line('.')) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 448 | 5Xcc |
| 449 | call assert_equal(5, g:Xgetlist({'idx':0}).idx) |
| 450 | 2Xcc |
| 451 | call assert_equal(2, g:Xgetlist({'idx':0}).idx) |
| 452 | 10Xcc |
| 453 | call assert_equal(6, g:Xgetlist({'idx':0}).idx) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 454 | Xlast |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 455 | Xprev |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 456 | call assert_equal('Xqftestfile2', bufname('%')) |
| 457 | call assert_equal(11, line('.')) |
| 458 | call assert_fails('Xnext', 'E553') |
| 459 | call assert_fails('Xnfile', 'E553') |
| 460 | Xrewind |
| 461 | call assert_equal('Xqftestfile1', bufname('%')) |
| 462 | call assert_equal(5, line('.')) |
| 463 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 464 | 10Xnext |
| 465 | call assert_equal('Xqftestfile2', bufname('%')) |
| 466 | call assert_equal(11, line('.')) |
| 467 | 10Xprev |
| 468 | call assert_equal('Xqftestfile1', bufname('%')) |
| 469 | call assert_equal(5, line('.')) |
| 470 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 471 | " Jumping to an error from the error window using cc command |
| 472 | Xgetexpr ['Xqftestfile1:5:Line5', |
| 473 | \ 'Xqftestfile1:6:Line6', |
| 474 | \ 'Xqftestfile2:10:Line10', |
| 475 | \ 'Xqftestfile2:11:Line11'] |
| 476 | Xopen |
| 477 | 10Xcc |
| 478 | call assert_equal(11, line('.')) |
| 479 | call assert_equal('Xqftestfile2', bufname('%')) |
| 480 | |
| 481 | " Jumping to an error from the error window (when only the error window is |
| 482 | " present) |
| 483 | Xopen | only |
| 484 | Xlast 1 |
| 485 | call assert_equal(5, line('.')) |
| 486 | call assert_equal('Xqftestfile1', bufname('%')) |
| 487 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 488 | Xexpr "" |
| 489 | call assert_fails('Xnext', 'E42:') |
| 490 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 491 | call delete('Xqftestfile1') |
| 492 | call delete('Xqftestfile2') |
Bram Moolenaar | fc2b270 | 2017-09-15 22:43:07 +0200 | [diff] [blame] | 493 | |
| 494 | " Should be able to use next/prev with invalid entries |
| 495 | Xexpr "" |
| 496 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 497 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
| 498 | Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo'] |
| 499 | call assert_equal(5, g:Xgetlist({'size' : 0}).size) |
| 500 | Xlast |
| 501 | call assert_equal(5, g:Xgetlist({'idx' : 0}).idx) |
| 502 | Xfirst |
| 503 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 504 | 2Xnext |
| 505 | call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 506 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 507 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 508 | func Test_browse() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 509 | call Xtest_browse('c') |
| 510 | call Xtest_browse('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 511 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 512 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 513 | func Test_nomem() |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 514 | call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) |
Bram Moolenaar | a260b87 | 2016-01-15 20:48:22 +0100 | [diff] [blame] | 515 | call assert_fails('vimgrep vim runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 516 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 517 | call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) |
Bram Moolenaar | a260b87 | 2016-01-15 20:48:22 +0100 | [diff] [blame] | 518 | call assert_fails('vimgrep vim runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 519 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 520 | call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) |
Bram Moolenaar | a260b87 | 2016-01-15 20:48:22 +0100 | [diff] [blame] | 521 | call assert_fails('cfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 522 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 523 | call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0) |
Bram Moolenaar | a260b87 | 2016-01-15 20:48:22 +0100 | [diff] [blame] | 524 | call assert_fails('cfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 525 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 526 | call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) |
Bram Moolenaar | a260b87 | 2016-01-15 20:48:22 +0100 | [diff] [blame] | 527 | call assert_fails('cfile runtest.vim', 'E342:') |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 528 | |
| 529 | endfunc |
| 530 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 531 | func s:test_xhelpgrep(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 532 | call s:setup_commands(a:cchar) |
| 533 | Xhelpgrep quickfix |
| 534 | Xopen |
| 535 | if a:cchar == 'c' |
| 536 | let title_text = ':helpgrep quickfix' |
| 537 | else |
| 538 | let title_text = ':lhelpgrep quickfix' |
| 539 | endif |
| 540 | call assert_true(w:quickfix_title =~ title_text, w:quickfix_title) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 541 | |
| 542 | " Jumping to a help topic should open the help window |
| 543 | only |
| 544 | Xnext |
| 545 | call assert_true(&buftype == 'help') |
| 546 | call assert_true(winnr('$') == 2) |
| 547 | " Jumping to the next match should reuse the help window |
| 548 | Xnext |
| 549 | call assert_true(&buftype == 'help') |
| 550 | call assert_true(winnr() == 1) |
| 551 | call assert_true(winnr('$') == 2) |
| 552 | " Jumping to the next match from the quickfix window should reuse the help |
| 553 | " window |
| 554 | Xopen |
| 555 | Xnext |
| 556 | call assert_true(&buftype == 'help') |
| 557 | call assert_true(winnr() == 1) |
| 558 | call assert_true(winnr('$') == 2) |
| 559 | |
Bram Moolenaar | 62ef797 | 2016-01-19 14:51:54 +0100 | [diff] [blame] | 560 | " This wipes out the buffer, make sure that doesn't cause trouble. |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 561 | Xclose |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 562 | |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 563 | if a:cchar == 'l' |
| 564 | " When a help window is present, running :lhelpgrep should reuse the |
| 565 | " help window and not the current window |
| 566 | new | only |
| 567 | call g:Xsetlist([], 'f') |
| 568 | help index.txt |
| 569 | wincmd w |
| 570 | lhelpgrep quickfix |
| 571 | call assert_equal(1, winnr()) |
| 572 | call assert_notequal([], getloclist(1)) |
| 573 | call assert_equal([], getloclist(2)) |
| 574 | endif |
| 575 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 576 | new | only |
| 577 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 578 | " Search for non existing help string |
| 579 | call assert_fails('Xhelpgrep a1b2c3', 'E480:') |
Bram Moolenaar | 108e7b4 | 2018-10-11 17:39:12 +0200 | [diff] [blame] | 580 | " Invalid regular expression |
| 581 | call assert_fails('Xhelpgrep \@<!', 'E480:') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 582 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 583 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 584 | func Test_helpgrep() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 585 | call s:test_xhelpgrep('c') |
Bram Moolenaar | cf25fdb | 2016-08-03 21:04:53 +0200 | [diff] [blame] | 586 | helpclose |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 587 | call s:test_xhelpgrep('l') |
Bram Moolenaar | 62ef797 | 2016-01-19 14:51:54 +0100 | [diff] [blame] | 588 | endfunc |
Bram Moolenaar | 75bdf6a | 2016-01-07 21:25:08 +0100 | [diff] [blame] | 589 | |
Bram Moolenaar | 6920c72 | 2016-01-22 22:44:10 +0100 | [diff] [blame] | 590 | func Test_errortitle() |
| 591 | augroup QfBufWinEnter |
| 592 | au! |
| 593 | au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') |
| 594 | augroup END |
| 595 | copen |
| 596 | 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'')'}] |
| 597 | call setqflist(a) |
| 598 | call assert_equal(':setqflist()', g:a) |
| 599 | augroup QfBufWinEnter |
| 600 | au! |
| 601 | augroup END |
| 602 | augroup! QfBufWinEnter |
| 603 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 604 | |
Bram Moolenaar | 5584df6 | 2016-03-18 21:00:51 +0100 | [diff] [blame] | 605 | func Test_vimgreptitle() |
| 606 | augroup QfBufWinEnter |
| 607 | au! |
| 608 | au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') |
| 609 | augroup END |
| 610 | try |
| 611 | vimgrep /pattern/j file |
| 612 | catch /E480/ |
| 613 | endtry |
| 614 | copen |
| 615 | call assert_equal(': vimgrep /pattern/j file', g:a) |
| 616 | augroup QfBufWinEnter |
| 617 | au! |
| 618 | augroup END |
| 619 | augroup! QfBufWinEnter |
| 620 | endfunc |
| 621 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 622 | func XqfTitleTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 623 | call s:setup_commands(a:cchar) |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 624 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 625 | Xgetexpr ['file:1:1:message'] |
| 626 | let l = g:Xgetlist() |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 627 | if a:cchar == 'c' |
| 628 | call setqflist(l, 'r') |
| 629 | else |
| 630 | call setloclist(0, l, 'r') |
| 631 | endif |
| 632 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 633 | Xopen |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 634 | if a:cchar == 'c' |
| 635 | let title = ':setqflist()' |
| 636 | else |
| 637 | let title = ':setloclist()' |
| 638 | endif |
| 639 | call assert_equal(title, w:quickfix_title) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 640 | Xclose |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 641 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 642 | |
| 643 | " Tests for quickfix window's title |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 644 | func Test_qf_title() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 645 | call XqfTitleTests('c') |
| 646 | call XqfTitleTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 647 | endfunc |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 648 | |
| 649 | " Tests for 'errorformat' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 650 | func Test_efm() |
Bram Moolenaar | e27dba4 | 2016-03-15 14:11:10 +0100 | [diff] [blame] | 651 | let save_efm = &efm |
| 652 | set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# |
| 653 | cgetexpr ['WWWW', 'EEEE', 'CCCC'] |
| 654 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 655 | call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) |
| 656 | cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] |
| 657 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 658 | call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) |
| 659 | cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] |
| 660 | let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) |
| 661 | call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l) |
| 662 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 663 | endfunc |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 664 | |
| 665 | " This will test for problems in quickfix: |
| 666 | " A. incorrectly copying location lists which caused the location list to show |
| 667 | " a different name than the file that was actually being displayed. |
| 668 | " B. not reusing the window for which the location list window is opened but |
| 669 | " instead creating new windows. |
| 670 | " C. make sure that the location list window is not reused instead of the |
| 671 | " window it belongs to. |
| 672 | " |
| 673 | " Set up the test environment: |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 674 | func ReadTestProtocol(name) |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 675 | let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') |
| 676 | let word = substitute(base, '\v(.*)\..*', '\1', '') |
| 677 | |
| 678 | setl modifiable |
| 679 | setl noreadonly |
| 680 | setl noswapfile |
| 681 | setl bufhidden=delete |
| 682 | %del _ |
| 683 | " For problem 2: |
| 684 | " 'buftype' has to be set to reproduce the constant opening of new windows |
| 685 | setl buftype=nofile |
| 686 | |
| 687 | call setline(1, word) |
| 688 | |
| 689 | setl nomodified |
| 690 | setl nomodifiable |
| 691 | setl readonly |
| 692 | exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 693 | endfunc |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 694 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 695 | func Test_locationlist() |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 696 | enew |
| 697 | |
| 698 | augroup testgroup |
| 699 | au! |
| 700 | autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) |
| 701 | augroup END |
| 702 | |
| 703 | let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] |
| 704 | |
| 705 | let qflist = [] |
| 706 | for word in words |
| 707 | call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) |
| 708 | " NOTE: problem 1: |
| 709 | " intentionally not setting 'lnum' so that the quickfix entries are not |
| 710 | " valid |
| 711 | call setloclist(0, qflist, ' ') |
| 712 | endfor |
| 713 | |
| 714 | " Test A |
| 715 | lrewind |
| 716 | enew |
| 717 | lopen |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 718 | 4lnext |
Bram Moolenaar | 1ff2b64 | 2016-03-17 22:07:02 +0100 | [diff] [blame] | 719 | vert split |
| 720 | wincmd L |
| 721 | lopen |
| 722 | wincmd p |
| 723 | lnext |
| 724 | let fileName = expand("%") |
| 725 | wincmd p |
| 726 | let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') |
| 727 | let fileName = substitute(fileName, '\\', '/', 'g') |
| 728 | let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') |
| 729 | call assert_equal("test://bar.txt", fileName) |
| 730 | call assert_equal("test://bar.txt", locationListFileName) |
| 731 | |
| 732 | wincmd n | only |
| 733 | |
| 734 | " Test B: |
| 735 | lrewind |
| 736 | lopen |
| 737 | 2 |
| 738 | exe "normal \<CR>" |
| 739 | wincmd p |
| 740 | 3 |
| 741 | exe "normal \<CR>" |
| 742 | wincmd p |
| 743 | 4 |
| 744 | exe "normal \<CR>" |
| 745 | call assert_equal(2, winnr('$')) |
| 746 | wincmd n | only |
| 747 | |
| 748 | " Test C: |
| 749 | lrewind |
| 750 | lopen |
| 751 | " Let's move the location list window to the top to check whether it (the |
| 752 | " first window found) will be reused when we try to open new windows: |
| 753 | wincmd K |
| 754 | 2 |
| 755 | exe "normal \<CR>" |
| 756 | wincmd p |
| 757 | 3 |
| 758 | exe "normal \<CR>" |
| 759 | wincmd p |
| 760 | 4 |
| 761 | exe "normal \<CR>" |
| 762 | 1wincmd w |
| 763 | call assert_equal('quickfix', &buftype) |
| 764 | 2wincmd w |
| 765 | let bufferName = expand("%") |
| 766 | let bufferName = substitute(bufferName, '\\', '/', 'g') |
| 767 | call assert_equal('test://quux.txt', bufferName) |
| 768 | |
| 769 | wincmd n | only |
| 770 | |
| 771 | augroup! testgroup |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 772 | endfunc |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 773 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 774 | func Test_locationlist_curwin_was_closed() |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 775 | augroup testgroup |
| 776 | au! |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 777 | autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>")) |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 778 | augroup END |
| 779 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 780 | func! R(n) |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 781 | quit |
| 782 | endfunc |
| 783 | |
| 784 | new |
| 785 | let q = [] |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 786 | call add(q, {'filename': 'test_curwin.txt' }) |
Bram Moolenaar | 0899d69 | 2016-03-19 13:35:03 +0100 | [diff] [blame] | 787 | call setloclist(0, q) |
| 788 | call assert_fails('lrewind', 'E924:') |
| 789 | |
| 790 | augroup! testgroup |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 791 | endfunc |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 792 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 793 | func Test_locationlist_cross_tab_jump() |
Bram Moolenaar | 0a9046f | 2016-10-15 19:28:13 +0200 | [diff] [blame] | 794 | call writefile(['loclistfoo'], 'loclistfoo') |
| 795 | call writefile(['loclistbar'], 'loclistbar') |
| 796 | set switchbuf=usetab |
| 797 | |
| 798 | edit loclistfoo |
| 799 | tabedit loclistbar |
| 800 | silent lgrep loclistfoo loclist* |
| 801 | call assert_equal(1, tabpagenr()) |
| 802 | |
| 803 | enew | only | tabonly |
| 804 | set switchbuf&vim |
| 805 | call delete('loclistfoo') |
| 806 | call delete('loclistbar') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 807 | endfunc |
Bram Moolenaar | 0a9046f | 2016-10-15 19:28:13 +0200 | [diff] [blame] | 808 | |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 809 | " More tests for 'errorformat' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 810 | func Test_efm1() |
Bram Moolenaar | 7eba3d2 | 2016-03-19 22:54:09 +0100 | [diff] [blame] | 811 | if !has('unix') |
| 812 | " The 'errorformat' setting is different on non-Unix systems. |
| 813 | " This test works only on Unix-like systems. |
| 814 | return |
| 815 | endif |
| 816 | |
| 817 | let l = [ |
| 818 | \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.', |
| 819 | \ '"Xtestfile", line 6 col 19; this is an error', |
| 820 | \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c', |
| 821 | \ 'Xtestfile:9: parse error before `asd''', |
| 822 | \ 'make: *** [vim] Error 1', |
| 823 | \ 'in file "Xtestfile" linenr 10: there is an error', |
| 824 | \ '', |
| 825 | \ '2 returned', |
| 826 | \ '"Xtestfile", line 11 col 1; this is an error', |
| 827 | \ '"Xtestfile", line 12 col 2; this is another error', |
| 828 | \ '"Xtestfile", line 14:10; this is an error in column 10', |
| 829 | \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time', |
| 830 | \ '"Xtestfile", linenr 16: yet another problem', |
| 831 | \ 'Error in "Xtestfile" at line 17:', |
| 832 | \ 'x should be a dot', |
| 833 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', |
| 834 | \ ' ^', |
| 835 | \ 'Error in "Xtestfile" at line 18:', |
| 836 | \ 'x should be a dot', |
| 837 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', |
| 838 | \ '.............^', |
| 839 | \ 'Error in "Xtestfile" at line 19:', |
| 840 | \ 'x should be a dot', |
| 841 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', |
| 842 | \ '--------------^', |
| 843 | \ 'Error in "Xtestfile" at line 20:', |
| 844 | \ 'x should be a dot', |
| 845 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', |
| 846 | \ ' ^', |
| 847 | \ '', |
| 848 | \ 'Does anyone know what is the problem and how to correction it?', |
| 849 | \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?', |
| 850 | \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?' |
| 851 | \ ] |
| 852 | |
| 853 | call writefile(l, 'Xerrorfile1') |
| 854 | call writefile(l[:-2], 'Xerrorfile2') |
| 855 | |
| 856 | let m = [ |
| 857 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2', |
| 858 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3', |
| 859 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4', |
| 860 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5', |
| 861 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6', |
| 862 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7', |
| 863 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8', |
| 864 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9', |
| 865 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10', |
| 866 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11', |
| 867 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12', |
| 868 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13', |
| 869 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14', |
| 870 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15', |
| 871 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16', |
| 872 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', |
| 873 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', |
| 874 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', |
| 875 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', |
| 876 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21', |
| 877 | \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22' |
| 878 | \ ] |
| 879 | call writefile(m, 'Xtestfile') |
| 880 | |
| 881 | let save_efm = &efm |
| 882 | set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m |
| 883 | set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m |
| 884 | |
| 885 | exe 'cf Xerrorfile2' |
| 886 | clast |
| 887 | copen |
| 888 | call assert_equal(':cf Xerrorfile2', w:quickfix_title) |
| 889 | wincmd p |
| 890 | |
| 891 | exe 'cf Xerrorfile1' |
| 892 | call assert_equal([4, 12], [line('.'), col('.')]) |
| 893 | cn |
| 894 | call assert_equal([6, 19], [line('.'), col('.')]) |
| 895 | cn |
| 896 | call assert_equal([9, 2], [line('.'), col('.')]) |
| 897 | cn |
| 898 | call assert_equal([10, 2], [line('.'), col('.')]) |
| 899 | cn |
| 900 | call assert_equal([11, 1], [line('.'), col('.')]) |
| 901 | cn |
| 902 | call assert_equal([12, 2], [line('.'), col('.')]) |
| 903 | cn |
| 904 | call assert_equal([14, 10], [line('.'), col('.')]) |
| 905 | cn |
| 906 | call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 907 | cn |
| 908 | call assert_equal([16, 2], [line('.'), col('.')]) |
| 909 | cn |
| 910 | call assert_equal([17, 6], [line('.'), col('.')]) |
| 911 | cn |
| 912 | call assert_equal([18, 7], [line('.'), col('.')]) |
| 913 | cn |
| 914 | call assert_equal([19, 8], [line('.'), col('.')]) |
| 915 | cn |
| 916 | call assert_equal([20, 9], [line('.'), col('.')]) |
| 917 | clast |
| 918 | cprev |
| 919 | cprev |
| 920 | wincmd w |
| 921 | call assert_equal(':cf Xerrorfile1', w:quickfix_title) |
| 922 | wincmd p |
| 923 | |
| 924 | let &efm = save_efm |
| 925 | call delete('Xerrorfile1') |
| 926 | call delete('Xerrorfile2') |
| 927 | call delete('Xtestfile') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 928 | endfunc |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 929 | |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 930 | " Test for quickfix directory stack support |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 931 | func s:dir_stack_tests(cchar) |
Bram Moolenaar | 38df43b | 2016-06-20 21:41:12 +0200 | [diff] [blame] | 932 | call s:setup_commands(a:cchar) |
| 933 | |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 934 | let save_efm=&efm |
| 935 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 936 | |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 937 | let lines = ["Entering dir 'dir1/a'", |
| 938 | \ 'habits2.txt:1:Nine Healthy Habits', |
| 939 | \ "Entering dir 'b'", |
| 940 | \ 'habits3.txt:2:0 Hours of television', |
| 941 | \ 'habits2.txt:7:5 Small meals', |
| 942 | \ "Entering dir 'dir1/c'", |
| 943 | \ 'habits4.txt:3:1 Hour of exercise', |
| 944 | \ "Leaving dir 'dir1/c'", |
| 945 | \ "Leaving dir 'dir1/a'", |
| 946 | \ 'habits1.txt:4:2 Liters of water', |
| 947 | \ "Entering dir 'dir2'", |
| 948 | \ 'habits5.txt:5:3 Cups of hot green tea', |
| 949 | \ "Leaving dir 'dir2'" |
| 950 | \] |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 951 | |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 952 | Xexpr "" |
| 953 | for l in lines |
| 954 | Xaddexpr l |
| 955 | endfor |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 956 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 957 | let qf = g:Xgetlist() |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 958 | |
| 959 | call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr)) |
| 960 | call assert_equal(1, qf[1].lnum) |
| 961 | call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr)) |
| 962 | call assert_equal(2, qf[3].lnum) |
| 963 | call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr)) |
| 964 | call assert_equal(7, qf[4].lnum) |
| 965 | call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr)) |
| 966 | call assert_equal(3, qf[6].lnum) |
| 967 | call assert_equal('habits1.txt', bufname(qf[9].bufnr)) |
| 968 | call assert_equal(4, qf[9].lnum) |
| 969 | call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr)) |
| 970 | call assert_equal(5, qf[11].lnum) |
| 971 | |
| 972 | let &efm=save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 973 | endfunc |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 974 | |
| 975 | " Tests for %D and %X errorformat options |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 976 | func Test_efm_dirstack() |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 977 | " Create the directory stack and files |
| 978 | call mkdir('dir1') |
| 979 | call mkdir('dir1/a') |
| 980 | call mkdir('dir1/a/b') |
| 981 | call mkdir('dir1/c') |
| 982 | call mkdir('dir2') |
| 983 | |
| 984 | let lines = ["Nine Healthy Habits", |
| 985 | \ "0 Hours of television", |
| 986 | \ "1 Hour of exercise", |
| 987 | \ "2 Liters of water", |
| 988 | \ "3 Cups of hot green tea", |
| 989 | \ "4 Short mental breaks", |
| 990 | \ "5 Small meals", |
| 991 | \ "6 AM wake up time", |
| 992 | \ "7 Minutes of laughter", |
| 993 | \ "8 Hours of sleep (at least)", |
| 994 | \ "9 PM end of the day and off to bed" |
| 995 | \ ] |
| 996 | call writefile(lines, 'habits1.txt') |
| 997 | call writefile(lines, 'dir1/a/habits2.txt') |
| 998 | call writefile(lines, 'dir1/a/b/habits3.txt') |
| 999 | call writefile(lines, 'dir1/c/habits4.txt') |
| 1000 | call writefile(lines, 'dir2/habits5.txt') |
| 1001 | |
| 1002 | call s:dir_stack_tests('c') |
| 1003 | call s:dir_stack_tests('l') |
| 1004 | |
| 1005 | call delete('dir1', 'rf') |
| 1006 | call delete('dir2', 'rf') |
| 1007 | call delete('habits1.txt') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1008 | endfunc |
Bram Moolenaar | ab47c61 | 2016-06-14 22:02:26 +0200 | [diff] [blame] | 1009 | |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1010 | " Test for resync after continuing an ignored message |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1011 | func Xefm_ignore_continuations(cchar) |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1012 | call s:setup_commands(a:cchar) |
| 1013 | |
| 1014 | let save_efm = &efm |
| 1015 | |
| 1016 | let &efm = |
| 1017 | \ '%Eerror %m %l,' . |
| 1018 | \ '%-Wignored %m %l,' . |
| 1019 | \ '%+Cmore ignored %m %l,' . |
| 1020 | \ '%Zignored end' |
| 1021 | Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4'] |
| 1022 | let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]') |
| 1023 | call assert_equal([['resync', 1, 4, 'E']], l) |
| 1024 | |
| 1025 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1026 | endfunc |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1027 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1028 | func Test_efm_ignore_continuations() |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1029 | call Xefm_ignore_continuations('c') |
| 1030 | call Xefm_ignore_continuations('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1031 | endfunc |
Bram Moolenaar | 9b45794 | 2016-10-09 16:10:05 +0200 | [diff] [blame] | 1032 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1033 | " Tests for invalid error format specifies |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1034 | func Xinvalid_efm_Tests(cchar) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1035 | call s:setup_commands(a:cchar) |
| 1036 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1037 | let save_efm = &efm |
| 1038 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1039 | set efm=%f:%l:%m,%f:%f:%l:%m |
| 1040 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:') |
| 1041 | |
| 1042 | set efm=%f:%l:%m,%f:%l:%r:%m |
| 1043 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') |
| 1044 | |
| 1045 | set efm=%f:%l:%m,%O:%f:%l:%m |
| 1046 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') |
| 1047 | |
| 1048 | set efm=%f:%l:%m,%f:%l:%*[^a-z |
| 1049 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:') |
| 1050 | |
| 1051 | set efm=%f:%l:%m,%f:%l:%*c |
| 1052 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:') |
| 1053 | |
| 1054 | set efm=%f:%l:%m,%L%M%N |
| 1055 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:') |
| 1056 | |
| 1057 | set efm=%f:%l:%m,%f:%l:%m:%R |
| 1058 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:') |
| 1059 | |
| 1060 | set efm= |
| 1061 | call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') |
| 1062 | |
| 1063 | set efm=%DEntering\ dir\ abc,%f:%l:%m |
| 1064 | call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') |
| 1065 | |
| 1066 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1067 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1068 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1069 | func Test_invalid_efm() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1070 | call Xinvalid_efm_Tests('c') |
| 1071 | call Xinvalid_efm_Tests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1072 | endfunc |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1073 | |
| 1074 | " TODO: |
| 1075 | " Add tests for the following formats in 'errorformat' |
| 1076 | " %r %O |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1077 | func Test_efm2() |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1078 | let save_efm = &efm |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1079 | |
| 1080 | " Test for %s format in efm |
| 1081 | set efm=%f:%s |
| 1082 | cexpr 'Xtestfile:Line search text' |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1083 | let l = getqflist() |
| 1084 | call assert_equal(l[0].pattern, '^\VLine search text\$') |
| 1085 | call assert_equal(l[0].lnum, 0) |
| 1086 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1087 | let l = split(execute('clist', ''), "\n") |
| 1088 | call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l) |
| 1089 | |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1090 | " Test for %P, %Q and %t format specifiers |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1091 | let lines=["[Xtestfile1]", |
| 1092 | \ "(1,17) error: ';' missing", |
| 1093 | \ "(21,2) warning: variable 'z' not defined", |
| 1094 | \ "(67,3) error: end of file found before string ended", |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1095 | \ "--", |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1096 | \ "", |
| 1097 | \ "[Xtestfile2]", |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1098 | \ "--", |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1099 | \ "", |
| 1100 | \ "[Xtestfile3]", |
| 1101 | \ "NEW compiler v1.1", |
| 1102 | \ "(2,2) warning: variable 'x' not defined", |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1103 | \ "(67,3) warning: 's' already defined", |
| 1104 | \ "--" |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1105 | \] |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1106 | set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1107 | " To exercise the push/pop file functionality in quickfix, the test files |
| 1108 | " need to be created. |
| 1109 | call writefile(['Line1'], 'Xtestfile1') |
| 1110 | call writefile(['Line2'], 'Xtestfile2') |
| 1111 | call writefile(['Line3'], 'Xtestfile3') |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1112 | cexpr "" |
| 1113 | for l in lines |
| 1114 | caddexpr l |
| 1115 | endfor |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1116 | let l = getqflist() |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1117 | call assert_equal(12, len(l)) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1118 | call assert_equal(21, l[2].lnum) |
| 1119 | call assert_equal(2, l[2].col) |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1120 | call assert_equal('w', l[2].type) |
| 1121 | call assert_equal('e', l[3].type) |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1122 | call delete('Xtestfile1') |
| 1123 | call delete('Xtestfile2') |
| 1124 | call delete('Xtestfile3') |
Bram Moolenaar | 0fcc7c6 | 2016-07-02 21:22:52 +0200 | [diff] [blame] | 1125 | |
| 1126 | " Tests for %E, %C and %Z format specifiers |
| 1127 | let lines = ["Error 275", |
| 1128 | \ "line 42", |
| 1129 | \ "column 3", |
| 1130 | \ "' ' expected after '--'" |
| 1131 | \] |
| 1132 | set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m |
| 1133 | cgetexpr lines |
| 1134 | let l = getqflist() |
| 1135 | call assert_equal(275, l[0].nr) |
| 1136 | call assert_equal(42, l[0].lnum) |
| 1137 | call assert_equal(3, l[0].col) |
| 1138 | call assert_equal('E', l[0].type) |
| 1139 | call assert_equal("\n' ' expected after '--'", l[0].text) |
| 1140 | |
| 1141 | " Test for %> |
| 1142 | let lines = ["Error in line 147 of foo.c:", |
| 1143 | \"unknown variable 'i'" |
| 1144 | \] |
| 1145 | set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m |
| 1146 | cgetexpr lines |
| 1147 | let l = getqflist() |
| 1148 | call assert_equal(147, l[0].lnum) |
| 1149 | call assert_equal('E', l[0].type) |
| 1150 | call assert_equal("\nunknown variable 'i'", l[0].text) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1151 | |
Bram Moolenaar | e87e6dd | 2016-07-17 19:25:04 +0200 | [diff] [blame] | 1152 | " Test for %A, %C and other formats |
| 1153 | let lines = [ |
| 1154 | \"==============================================================", |
| 1155 | \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)", |
| 1156 | \"--------------------------------------------------------------", |
| 1157 | \"Traceback (most recent call last):", |
| 1158 | \' File "unittests/dbfacadeTest.py", line 89, in testFoo', |
| 1159 | \" self.assertEquals(34, dtid)", |
| 1160 | \' File "/usr/lib/python2.2/unittest.py", line 286, in', |
| 1161 | \" failUnlessEqual", |
| 1162 | \" raise self.failureException, \\", |
| 1163 | \"AssertionError: 34 != 33", |
| 1164 | \"", |
| 1165 | \"--------------------------------------------------------------", |
| 1166 | \"Ran 27 tests in 0.063s" |
| 1167 | \] |
| 1168 | set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m |
| 1169 | cgetexpr lines |
| 1170 | let l = getqflist() |
| 1171 | call assert_equal(8, len(l)) |
| 1172 | call assert_equal(89, l[4].lnum) |
| 1173 | call assert_equal(1, l[4].valid) |
| 1174 | call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr)) |
| 1175 | |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1176 | " Test for %o |
| 1177 | set efm=%f(%o):%l\ %m |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1178 | cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error'] |
| 1179 | call writefile(['Line1'], 'Xotestfile') |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1180 | let l = getqflist() |
| 1181 | call assert_equal(1, len(l), string(l)) |
| 1182 | call assert_equal('Language.PureScript.Types', l[0].module) |
| 1183 | copen |
| 1184 | call assert_equal('Language.PureScript.Types|20| Error', getline(1)) |
| 1185 | call feedkeys("\<CR>", 'xn') |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1186 | call assert_equal('Xotestfile', expand('%:t')) |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1187 | cclose |
| 1188 | bd |
Bram Moolenaar | bc7845d | 2018-05-01 16:26:48 +0200 | [diff] [blame] | 1189 | call delete("Xotestfile") |
Bram Moolenaar | d76ce85 | 2018-05-01 15:02:04 +0200 | [diff] [blame] | 1190 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1191 | " The following sequence of commands used to crash Vim |
| 1192 | set efm=%W%m |
| 1193 | cgetexpr ['msg1'] |
| 1194 | let l = getqflist() |
| 1195 | call assert_equal(1, len(l), string(l)) |
| 1196 | call assert_equal('msg1', l[0].text) |
| 1197 | set efm=%C%m |
| 1198 | lexpr 'msg2' |
| 1199 | let l = getloclist(0) |
| 1200 | call assert_equal(1, len(l), string(l)) |
| 1201 | call assert_equal('msg2', l[0].text) |
| 1202 | lopen |
| 1203 | call setqflist([], 'r') |
| 1204 | caddbuf |
| 1205 | let l = getqflist() |
| 1206 | call assert_equal(1, len(l), string(l)) |
| 1207 | call assert_equal('|| msg2', l[0].text) |
| 1208 | |
Bram Moolenaar | 78ddc06 | 2018-05-15 21:56:34 +0200 | [diff] [blame] | 1209 | " When matching error lines, case should be ignored. Test for this. |
| 1210 | set noignorecase |
| 1211 | let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'}) |
| 1212 | call assert_equal(10, l.items[0].lnum) |
| 1213 | call assert_equal('Line 20', l.items[0].text) |
| 1214 | set ignorecase& |
| 1215 | |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1216 | new | only |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1217 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1218 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1219 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1220 | func XquickfixChangedByAutocmd(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1221 | call s:setup_commands(a:cchar) |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1222 | if a:cchar == 'c' |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1223 | let ErrorNr = 'E925' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1224 | func! ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1225 | colder |
| 1226 | cgetexpr [] |
| 1227 | endfunc |
| 1228 | else |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1229 | let ErrorNr = 'E926' |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1230 | func! ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1231 | lolder |
| 1232 | lgetexpr [] |
| 1233 | endfunc |
| 1234 | endif |
| 1235 | |
| 1236 | augroup testgroup |
| 1237 | au! |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1238 | autocmd BufReadCmd test_changed.txt call ReadFunc() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1239 | augroup END |
| 1240 | |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1241 | new | only |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1242 | let words = [ "a", "b" ] |
| 1243 | let qflist = [] |
| 1244 | for word in words |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1245 | call add(qflist, {'filename': 'test_changed.txt'}) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1246 | call g:Xsetlist(qflist, ' ') |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1247 | endfor |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1248 | call assert_fails('Xrewind', ErrorNr . ':') |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1249 | |
| 1250 | augroup! testgroup |
| 1251 | endfunc |
| 1252 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1253 | func Test_quickfix_was_changed_by_autocmd() |
Bram Moolenaar | ffec3c5 | 2016-03-23 20:55:42 +0100 | [diff] [blame] | 1254 | call XquickfixChangedByAutocmd('c') |
| 1255 | call XquickfixChangedByAutocmd('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1256 | endfunc |
Bram Moolenaar | 8b20179 | 2016-03-25 15:01:10 +0100 | [diff] [blame] | 1257 | |
| 1258 | func Test_caddbuffer_to_empty() |
| 1259 | helpgr quickfix |
| 1260 | call setqflist([], 'r') |
| 1261 | cad |
Bram Moolenaar | f68f1d7 | 2016-03-25 17:14:06 +0100 | [diff] [blame] | 1262 | try |
| 1263 | cn |
| 1264 | catch |
| 1265 | " number of matches is unknown |
| 1266 | call assert_true(v:exception =~ 'E553:') |
| 1267 | endtry |
Bram Moolenaar | 8b20179 | 2016-03-25 15:01:10 +0100 | [diff] [blame] | 1268 | quit! |
| 1269 | endfunc |
Bram Moolenaar | 89c64d5 | 2016-03-27 18:44:40 +0200 | [diff] [blame] | 1270 | |
| 1271 | func Test_cgetexpr_works() |
| 1272 | " this must not crash Vim |
| 1273 | cgetexpr [$x] |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1274 | lgetexpr [$x] |
Bram Moolenaar | 89c64d5 | 2016-03-27 18:44:40 +0200 | [diff] [blame] | 1275 | endfunc |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1276 | |
| 1277 | " Tests for the setqflist() and setloclist() functions |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1278 | func SetXlistTests(cchar, bnum) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1279 | call s:setup_commands(a:cchar) |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1280 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1281 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1}, |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1282 | \ {'bufnr': a:bnum, 'lnum': 2}]) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1283 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1284 | call assert_equal(2, len(l)) |
| 1285 | call assert_equal(2, l[1].lnum) |
| 1286 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1287 | Xnext |
| 1288 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') |
| 1289 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1290 | call assert_equal(3, len(l)) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1291 | Xnext |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1292 | call assert_equal(3, line('.')) |
| 1293 | |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1294 | " Appending entries to the list should not change the cursor position |
| 1295 | " in the quickfix window |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1296 | Xwindow |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1297 | 1 |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1298 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4}, |
Bram Moolenaar | 2b2b8ae | 2016-05-24 19:59:51 +0200 | [diff] [blame] | 1299 | \ {'bufnr': a:bnum, 'lnum': 5}], 'a') |
| 1300 | call assert_equal(1, line('.')) |
| 1301 | close |
| 1302 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1303 | call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}, |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1304 | \ {'bufnr': a:bnum, 'lnum': 4}, |
| 1305 | \ {'bufnr': a:bnum, 'lnum': 5}], 'r') |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1306 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1307 | call assert_equal(3, len(l)) |
| 1308 | call assert_equal(5, l[2].lnum) |
| 1309 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1310 | call g:Xsetlist([]) |
| 1311 | let l = g:Xgetlist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1312 | call assert_equal(0, len(l)) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1313 | |
Bram Moolenaar | f1d21c8 | 2017-04-22 21:20:46 +0200 | [diff] [blame] | 1314 | " Tests for setting the 'valid' flag |
| 1315 | call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}]) |
| 1316 | Xwindow |
| 1317 | call assert_equal(1, winnr('$')) |
| 1318 | let l = g:Xgetlist() |
| 1319 | call g:Xsetlist(l) |
| 1320 | call assert_equal(0, g:Xgetlist()[0].valid) |
Bram Moolenaar | 9752c72 | 2018-12-22 16:49:34 +0100 | [diff] [blame] | 1321 | " Adding a non-valid entry should not mark the list as having valid entries |
| 1322 | call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a') |
| 1323 | Xwindow |
| 1324 | call assert_equal(1, winnr('$')) |
| 1325 | |
| 1326 | " :cnext/:cprev should still work even with invalid entries in the list |
| 1327 | let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0}, |
| 1328 | \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}] |
| 1329 | call g:Xsetlist(l) |
| 1330 | Xnext |
| 1331 | call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) |
| 1332 | Xprev |
| 1333 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 1334 | " :cnext/:cprev should still work after appending invalid entries to an |
| 1335 | " empty list |
| 1336 | call g:Xsetlist([]) |
| 1337 | call g:Xsetlist(l, 'a') |
| 1338 | Xnext |
| 1339 | call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) |
| 1340 | Xprev |
| 1341 | call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) |
| 1342 | |
Bram Moolenaar | f1d21c8 | 2017-04-22 21:20:46 +0200 | [diff] [blame] | 1343 | call g:Xsetlist([{'text':'Text1', 'valid':1}]) |
| 1344 | Xwindow |
| 1345 | call assert_equal(2, winnr('$')) |
| 1346 | Xclose |
| 1347 | let save_efm = &efm |
| 1348 | set efm=%m |
| 1349 | Xgetexpr 'TestMessage' |
| 1350 | let l = g:Xgetlist() |
| 1351 | call g:Xsetlist(l) |
| 1352 | call assert_equal(1, g:Xgetlist()[0].valid) |
| 1353 | let &efm = save_efm |
| 1354 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1355 | " Error cases: |
| 1356 | " Refer to a non-existing buffer and pass a non-dictionary type |
| 1357 | call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," . |
| 1358 | \ " {'bufnr':999, 'lnum':5}])", 'E92:') |
| 1359 | call g:Xsetlist([[1, 2,3]]) |
| 1360 | call assert_equal(0, len(g:Xgetlist())) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1361 | endfunc |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1362 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1363 | func Test_setqflist() |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1364 | new Xtestfile | only |
| 1365 | let bnum = bufnr('%') |
| 1366 | call setline(1, range(1,5)) |
| 1367 | |
| 1368 | call SetXlistTests('c', bnum) |
| 1369 | call SetXlistTests('l', bnum) |
| 1370 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1371 | enew! |
Bram Moolenaar | c1808d5 | 2016-04-18 20:04:00 +0200 | [diff] [blame] | 1372 | call delete('Xtestfile') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1373 | endfunc |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1374 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1375 | func Xlist_empty_middle(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1376 | call s:setup_commands(a:cchar) |
| 1377 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1378 | " create three quickfix lists |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1379 | let @/ = 'Test_' |
| 1380 | Xvimgrep // test_quickfix.vim |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1381 | let testlen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1382 | call assert_true(testlen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1383 | Xvimgrep empty test_quickfix.vim |
| 1384 | call assert_true(len(g:Xgetlist()) > 0) |
| 1385 | Xvimgrep matches test_quickfix.vim |
| 1386 | let matchlen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1387 | call assert_true(matchlen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1388 | Xolder |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1389 | " make the middle list empty |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1390 | call g:Xsetlist([], 'r') |
| 1391 | call assert_true(len(g:Xgetlist()) == 0) |
| 1392 | Xolder |
| 1393 | call assert_equal(testlen, len(g:Xgetlist())) |
| 1394 | Xnewer |
| 1395 | Xnewer |
| 1396 | call assert_equal(matchlen, len(g:Xgetlist())) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1397 | endfunc |
| 1398 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1399 | func Test_setqflist_empty_middle() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1400 | call Xlist_empty_middle('c') |
| 1401 | call Xlist_empty_middle('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1402 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1403 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1404 | func Xlist_empty_older(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1405 | call s:setup_commands(a:cchar) |
| 1406 | |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1407 | " create three quickfix lists |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1408 | Xvimgrep one test_quickfix.vim |
| 1409 | let onelen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1410 | call assert_true(onelen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1411 | Xvimgrep two test_quickfix.vim |
| 1412 | let twolen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1413 | call assert_true(twolen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1414 | Xvimgrep three test_quickfix.vim |
| 1415 | let threelen = len(g:Xgetlist()) |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1416 | call assert_true(threelen > 0) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1417 | Xolder 2 |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1418 | " make the first list empty, check the others didn't change |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1419 | call g:Xsetlist([], 'r') |
| 1420 | call assert_true(len(g:Xgetlist()) == 0) |
| 1421 | Xnewer |
| 1422 | call assert_equal(twolen, len(g:Xgetlist())) |
| 1423 | Xnewer |
| 1424 | call assert_equal(threelen, len(g:Xgetlist())) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1425 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1426 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1427 | func Test_setqflist_empty_older() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1428 | call Xlist_empty_older('c') |
| 1429 | call Xlist_empty_older('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1430 | endfunc |
Bram Moolenaar | 1cee693 | 2016-06-09 22:17:22 +0200 | [diff] [blame] | 1431 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1432 | func XquickfixSetListWithAct(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1433 | call s:setup_commands(a:cchar) |
| 1434 | |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1435 | let list1 = [{'filename': 'fnameA', 'text': 'A'}, |
| 1436 | \ {'filename': 'fnameB', 'text': 'B'}] |
| 1437 | let list2 = [{'filename': 'fnameC', 'text': 'C'}, |
| 1438 | \ {'filename': 'fnameD', 'text': 'D'}, |
| 1439 | \ {'filename': 'fnameE', 'text': 'E'}] |
| 1440 | |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 1441 | " {action} is unspecified. Same as specifying ' '. |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1442 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1443 | silent! Xnewer 99 |
| 1444 | call g:Xsetlist(list1) |
| 1445 | call g:Xsetlist(list2) |
| 1446 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1447 | call assert_equal(3, len(li)) |
| 1448 | call assert_equal('C', li[0]['text']) |
| 1449 | call assert_equal('D', li[1]['text']) |
| 1450 | call assert_equal('E', li[2]['text']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1451 | silent! Xolder |
| 1452 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1453 | call assert_equal(2, len(li)) |
| 1454 | call assert_equal('A', li[0]['text']) |
| 1455 | call assert_equal('B', li[1]['text']) |
| 1456 | |
| 1457 | " {action} is specified ' '. |
| 1458 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1459 | silent! Xnewer 99 |
| 1460 | call g:Xsetlist(list1) |
| 1461 | call g:Xsetlist(list2, ' ') |
| 1462 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1463 | call assert_equal(3, len(li)) |
| 1464 | call assert_equal('C', li[0]['text']) |
| 1465 | call assert_equal('D', li[1]['text']) |
| 1466 | call assert_equal('E', li[2]['text']) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1467 | silent! Xolder |
| 1468 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1469 | call assert_equal(2, len(li)) |
| 1470 | call assert_equal('A', li[0]['text']) |
| 1471 | call assert_equal('B', li[1]['text']) |
| 1472 | |
| 1473 | " {action} is specified 'a'. |
| 1474 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1475 | silent! Xnewer 99 |
| 1476 | call g:Xsetlist(list1) |
| 1477 | call g:Xsetlist(list2, 'a') |
| 1478 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1479 | call assert_equal(5, len(li)) |
| 1480 | call assert_equal('A', li[0]['text']) |
| 1481 | call assert_equal('B', li[1]['text']) |
| 1482 | call assert_equal('C', li[2]['text']) |
| 1483 | call assert_equal('D', li[3]['text']) |
| 1484 | call assert_equal('E', li[4]['text']) |
| 1485 | |
| 1486 | " {action} is specified 'r'. |
| 1487 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1488 | silent! Xnewer 99 |
| 1489 | call g:Xsetlist(list1) |
| 1490 | call g:Xsetlist(list2, 'r') |
| 1491 | let li = g:Xgetlist() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1492 | call assert_equal(3, len(li)) |
| 1493 | call assert_equal('C', li[0]['text']) |
| 1494 | call assert_equal('D', li[1]['text']) |
| 1495 | call assert_equal('E', li[2]['text']) |
| 1496 | |
| 1497 | " Test for wrong value. |
| 1498 | new | only |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1499 | call assert_fails("call g:Xsetlist(0)", 'E714:') |
| 1500 | call assert_fails("call g:Xsetlist(list1, '')", 'E927:') |
| 1501 | call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:') |
| 1502 | call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:') |
| 1503 | call assert_fails("call g:Xsetlist(list1, 0)", 'E928:') |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1504 | endfunc |
| 1505 | |
Bram Moolenaar | a0ca7d0 | 2017-12-19 10:22:19 +0100 | [diff] [blame] | 1506 | func Test_setqflist_invalid_nr() |
| 1507 | " The following command used to crash Vim |
| 1508 | call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST}) |
| 1509 | endfunc |
| 1510 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1511 | func Test_quickfix_set_list_with_act() |
Bram Moolenaar | d106e5b | 2016-04-21 19:38:07 +0200 | [diff] [blame] | 1512 | call XquickfixSetListWithAct('c') |
| 1513 | call XquickfixSetListWithAct('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1514 | endfunc |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1515 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1516 | func XLongLinesTests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1517 | let l = g:Xgetlist() |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1518 | |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1519 | call assert_equal(4, len(l)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1520 | call assert_equal(1, l[0].lnum) |
| 1521 | call assert_equal(1, l[0].col) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1522 | call assert_equal(1975, len(l[0].text)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1523 | call assert_equal(2, l[1].lnum) |
| 1524 | call assert_equal(1, l[1].col) |
| 1525 | call assert_equal(4070, len(l[1].text)) |
| 1526 | call assert_equal(3, l[2].lnum) |
| 1527 | call assert_equal(1, l[2].col) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1528 | call assert_equal(4070, len(l[2].text)) |
| 1529 | call assert_equal(4, l[3].lnum) |
| 1530 | call assert_equal(1, l[3].col) |
| 1531 | call assert_equal(10, len(l[3].text)) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1532 | |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1533 | call g:Xsetlist([], 'r') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1534 | endfunc |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1535 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1536 | func s:long_lines_tests(cchar) |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1537 | call s:setup_commands(a:cchar) |
| 1538 | |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1539 | let testfile = 'samples/quickfix.txt' |
| 1540 | |
| 1541 | " file |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1542 | exe 'Xgetfile' testfile |
| 1543 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1544 | |
| 1545 | " list |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1546 | Xexpr readfile(testfile) |
| 1547 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1548 | |
| 1549 | " string |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1550 | Xexpr join(readfile(testfile), "\n") |
| 1551 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 6be8c8e | 2016-04-30 13:17:09 +0200 | [diff] [blame] | 1552 | |
| 1553 | " buffer |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1554 | exe 'edit' testfile |
| 1555 | exe 'Xbuffer' bufnr('%') |
Bram Moolenaar | f50df39 | 2016-06-21 21:33:34 +0200 | [diff] [blame] | 1556 | call XLongLinesTests(a:cchar) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1557 | endfunc |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1558 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1559 | func Test_long_lines() |
Bram Moolenaar | 3ef5bf7 | 2016-06-15 22:41:31 +0200 | [diff] [blame] | 1560 | call s:long_lines_tests('c') |
| 1561 | call s:long_lines_tests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1562 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1563 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1564 | func s:create_test_file(filename) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1565 | let l = [] |
| 1566 | for i in range(1, 20) |
| 1567 | call add(l, 'Line' . i) |
| 1568 | endfor |
| 1569 | call writefile(l, a:filename) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1570 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1571 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1572 | func Test_switchbuf() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1573 | call s:create_test_file('Xqftestfile1') |
| 1574 | call s:create_test_file('Xqftestfile2') |
| 1575 | call s:create_test_file('Xqftestfile3') |
| 1576 | |
| 1577 | new | only |
| 1578 | edit Xqftestfile1 |
| 1579 | let file1_winid = win_getid() |
| 1580 | new Xqftestfile2 |
| 1581 | let file2_winid = win_getid() |
| 1582 | cgetexpr ['Xqftestfile1:5:Line5', |
| 1583 | \ 'Xqftestfile1:6:Line6', |
| 1584 | \ 'Xqftestfile2:10:Line10', |
| 1585 | \ 'Xqftestfile2:11:Line11', |
| 1586 | \ 'Xqftestfile3:15:Line15', |
| 1587 | \ 'Xqftestfile3:16:Line16'] |
| 1588 | |
| 1589 | new |
| 1590 | let winid = win_getid() |
| 1591 | cfirst | cnext |
| 1592 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1593 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1594 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1595 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1596 | call assert_equal(winid, win_getid()) |
| 1597 | enew |
| 1598 | |
| 1599 | set switchbuf=useopen |
| 1600 | cfirst | cnext |
| 1601 | call assert_equal(file1_winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1602 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1603 | call assert_equal(file2_winid, win_getid()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1604 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1605 | call assert_equal(file2_winid, win_getid()) |
| 1606 | |
| 1607 | enew | only |
| 1608 | set switchbuf=usetab |
| 1609 | tabedit Xqftestfile1 |
| 1610 | tabedit Xqftestfile2 |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 1611 | tabedit Xqftestfile3 |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1612 | tabfirst |
| 1613 | cfirst | cnext |
| 1614 | call assert_equal(2, tabpagenr()) |
Bram Moolenaar | 99895ea | 2017-04-20 22:44:47 +0200 | [diff] [blame] | 1615 | 2cnext |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1616 | call assert_equal(3, tabpagenr()) |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 1617 | 6cnext |
| 1618 | call assert_equal(4, tabpagenr()) |
| 1619 | 2cpfile |
| 1620 | call assert_equal(2, tabpagenr()) |
| 1621 | 2cnfile |
| 1622 | call assert_equal(4, tabpagenr()) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1623 | tabfirst | tabonly | enew |
| 1624 | |
| 1625 | set switchbuf=split |
| 1626 | cfirst | cnext |
| 1627 | call assert_equal(1, winnr('$')) |
| 1628 | cnext | cnext |
| 1629 | call assert_equal(2, winnr('$')) |
| 1630 | cnext | cnext |
| 1631 | call assert_equal(3, winnr('$')) |
| 1632 | enew | only |
| 1633 | |
| 1634 | set switchbuf=newtab |
| 1635 | cfirst | cnext |
| 1636 | call assert_equal(1, tabpagenr('$')) |
| 1637 | cnext | cnext |
| 1638 | call assert_equal(2, tabpagenr('$')) |
| 1639 | cnext | cnext |
| 1640 | call assert_equal(3, tabpagenr('$')) |
| 1641 | tabfirst | enew | tabonly | only |
| 1642 | |
| 1643 | set switchbuf= |
| 1644 | edit Xqftestfile1 |
| 1645 | let file1_winid = win_getid() |
| 1646 | new Xqftestfile2 |
| 1647 | let file2_winid = win_getid() |
| 1648 | copen |
| 1649 | exe "normal 1G\<CR>" |
| 1650 | call assert_equal(file1_winid, win_getid()) |
| 1651 | copen |
| 1652 | exe "normal 3G\<CR>" |
| 1653 | call assert_equal(file2_winid, win_getid()) |
| 1654 | copen | only |
| 1655 | exe "normal 5G\<CR>" |
| 1656 | call assert_equal(2, winnr('$')) |
| 1657 | call assert_equal(1, bufwinnr('Xqftestfile3')) |
| 1658 | |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1659 | " If only quickfix window is open in the current tabpage, jumping to an |
| 1660 | " entry with 'switchubf' set to 'usetab' should search in other tabpages. |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1661 | enew | only |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1662 | set switchbuf=usetab |
| 1663 | tabedit Xqftestfile1 |
| 1664 | tabedit Xqftestfile2 |
| 1665 | tabedit Xqftestfile3 |
| 1666 | tabfirst |
| 1667 | copen | only |
| 1668 | clast |
| 1669 | call assert_equal(4, tabpagenr()) |
| 1670 | tabfirst | tabonly | enew | only |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1671 | |
| 1672 | call delete('Xqftestfile1') |
| 1673 | call delete('Xqftestfile2') |
| 1674 | call delete('Xqftestfile3') |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 1675 | set switchbuf&vim |
| 1676 | |
| 1677 | enew | only |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1678 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1679 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1680 | func Xadjust_qflnum(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1681 | call s:setup_commands(a:cchar) |
| 1682 | |
| 1683 | enew | only |
| 1684 | |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 1685 | let fname = 'Xqftestfile' . a:cchar |
| 1686 | call s:create_test_file(fname) |
| 1687 | exe 'edit ' . fname |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1688 | |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 1689 | Xgetexpr [fname . ':5:Line5', |
| 1690 | \ fname . ':10:Line10', |
| 1691 | \ fname . ':15:Line15', |
| 1692 | \ fname . ':20:Line20'] |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1693 | |
| 1694 | 6,14delete |
| 1695 | call append(6, ['Buffer', 'Window']) |
| 1696 | |
| 1697 | let l = g:Xgetlist() |
| 1698 | |
| 1699 | call assert_equal(5, l[0].lnum) |
| 1700 | call assert_equal(6, l[2].lnum) |
| 1701 | call assert_equal(13, l[3].lnum) |
| 1702 | |
| 1703 | enew! |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 1704 | call delete(fname) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1705 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1706 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1707 | func Test_adjust_lnum() |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 1708 | call setloclist(0, []) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1709 | call Xadjust_qflnum('c') |
Bram Moolenaar | c154274 | 2016-07-20 21:44:37 +0200 | [diff] [blame] | 1710 | call setqflist([]) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1711 | call Xadjust_qflnum('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1712 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1713 | |
| 1714 | " Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1715 | func s:test_xgrep(cchar) |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1716 | call s:setup_commands(a:cchar) |
| 1717 | |
| 1718 | " The following lines are used for the grep test. Don't remove. |
| 1719 | " Grep_Test_Text: Match 1 |
| 1720 | " Grep_Test_Text: Match 2 |
| 1721 | " GrepAdd_Test_Text: Match 1 |
| 1722 | " GrepAdd_Test_Text: Match 2 |
| 1723 | enew! | only |
| 1724 | set makeef&vim |
| 1725 | silent Xgrep Grep_Test_Text: test_quickfix.vim |
| 1726 | call assert_true(len(g:Xgetlist()) == 3) |
| 1727 | Xopen |
| 1728 | call assert_true(w:quickfix_title =~ '^:grep') |
| 1729 | Xclose |
| 1730 | enew |
| 1731 | set makeef=Temp_File_## |
| 1732 | silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim |
| 1733 | call assert_true(len(g:Xgetlist()) == 6) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1734 | endfunc |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1735 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1736 | func Test_grep() |
Bram Moolenaar | 049cba9 | 2016-06-26 14:38:04 +0200 | [diff] [blame] | 1737 | if !has('unix') |
| 1738 | " The grepprg may not be set on non-Unix systems |
| 1739 | return |
| 1740 | endif |
| 1741 | |
| 1742 | call s:test_xgrep('c') |
| 1743 | call s:test_xgrep('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1744 | endfunc |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1745 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1746 | func Test_two_windows() |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1747 | " Use one 'errorformat' for two windows. Add an expression to each of them, |
| 1748 | " make sure they each keep their own state. |
| 1749 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 1750 | call mkdir('Xone/a', 'p') |
| 1751 | call mkdir('Xtwo/a', 'p') |
| 1752 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 1753 | call writefile(lines, 'Xone/a/one.txt') |
| 1754 | call writefile(lines, 'Xtwo/a/two.txt') |
| 1755 | |
| 1756 | new one |
| 1757 | let one_id = win_getid() |
| 1758 | lexpr "" |
| 1759 | new two |
| 1760 | let two_id = win_getid() |
| 1761 | lexpr "" |
| 1762 | |
| 1763 | laddexpr "Entering dir 'Xtwo/a'" |
| 1764 | call win_gotoid(one_id) |
| 1765 | laddexpr "Entering dir 'Xone/a'" |
| 1766 | call win_gotoid(two_id) |
| 1767 | laddexpr 'two.txt:5:two two two' |
| 1768 | call win_gotoid(one_id) |
| 1769 | laddexpr 'one.txt:3:one one one' |
| 1770 | |
| 1771 | let loc_one = getloclist(one_id) |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1772 | call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr)) |
| 1773 | call assert_equal(3, loc_one[1].lnum) |
| 1774 | |
| 1775 | let loc_two = getloclist(two_id) |
Bram Moolenaar | 361c8f0 | 2016-07-02 15:41:47 +0200 | [diff] [blame] | 1776 | call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr)) |
| 1777 | call assert_equal(5, loc_two[1].lnum) |
| 1778 | |
| 1779 | call win_gotoid(one_id) |
| 1780 | bwipe! |
| 1781 | call win_gotoid(two_id) |
| 1782 | bwipe! |
| 1783 | call delete('Xone', 'rf') |
| 1784 | call delete('Xtwo', 'rf') |
| 1785 | endfunc |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 1786 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1787 | func XbottomTests(cchar) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1788 | call s:setup_commands(a:cchar) |
| 1789 | |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 1790 | " Calling lbottom without any errors should fail |
| 1791 | if a:cchar == 'l' |
| 1792 | call assert_fails('lbottom', 'E776:') |
| 1793 | endif |
| 1794 | |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 1795 | call g:Xsetlist([{'filename': 'foo', 'lnum': 42}]) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1796 | Xopen |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 1797 | let wid = win_getid() |
| 1798 | call assert_equal(1, line('.')) |
| 1799 | wincmd w |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 1800 | call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a') |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1801 | Xbottom |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 1802 | call win_gotoid(wid) |
| 1803 | call assert_equal(2, line('.')) |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1804 | Xclose |
Bram Moolenaar | dcb1700 | 2016-07-07 18:58:59 +0200 | [diff] [blame] | 1805 | endfunc |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1806 | |
| 1807 | " Tests for the :cbottom and :lbottom commands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1808 | func Test_cbottom() |
Bram Moolenaar | 537ef08 | 2016-07-09 17:56:19 +0200 | [diff] [blame] | 1809 | call XbottomTests('c') |
| 1810 | call XbottomTests('l') |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1811 | endfunc |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 1812 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1813 | func HistoryTest(cchar) |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 1814 | call s:setup_commands(a:cchar) |
| 1815 | |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 1816 | " clear all lists after the first one, then replace the first one. |
| 1817 | call g:Xsetlist([]) |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 1818 | call assert_fails('Xolder 99', 'E380:') |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 1819 | let entry = {'filename': 'foo', 'lnum': 42} |
| 1820 | call g:Xsetlist([entry], 'r') |
| 1821 | call g:Xsetlist([entry, entry]) |
| 1822 | call g:Xsetlist([entry, entry, entry]) |
| 1823 | let res = split(execute(a:cchar . 'hist'), "\n") |
| 1824 | call assert_equal(3, len(res)) |
| 1825 | let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()' |
| 1826 | call assert_equal(' error list 1 of 3; 1 ' . common, res[0]) |
| 1827 | call assert_equal(' error list 2 of 3; 2 ' . common, res[1]) |
| 1828 | call assert_equal('> error list 3 of 3; 3 ' . common, res[2]) |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 1829 | |
| 1830 | call g:Xsetlist([], 'f') |
| 1831 | let l = split(execute(a:cchar . 'hist'), "\n") |
| 1832 | call assert_equal('No entries', l[0]) |
Bram Moolenaar | 5b69c22 | 2019-01-11 14:50:06 +0100 | [diff] [blame] | 1833 | |
| 1834 | " An empty list should still show the stack history |
| 1835 | call g:Xsetlist([]) |
| 1836 | let res = split(execute(a:cchar . 'hist'), "\n") |
| 1837 | call assert_equal('> error list 1 of 1; 0 ' . common, res[0]) |
| 1838 | |
| 1839 | call g:Xsetlist([], 'f') |
Bram Moolenaar | f6acffb | 2016-07-16 16:54:24 +0200 | [diff] [blame] | 1840 | endfunc |
| 1841 | |
| 1842 | func Test_history() |
| 1843 | call HistoryTest('c') |
| 1844 | call HistoryTest('l') |
| 1845 | endfunc |
Bram Moolenaar | 015102e | 2016-07-16 18:24:56 +0200 | [diff] [blame] | 1846 | |
| 1847 | func Test_duplicate_buf() |
| 1848 | " make sure we can get the highest buffer number |
| 1849 | edit DoesNotExist |
| 1850 | edit DoesNotExist2 |
| 1851 | let last_buffer = bufnr("$") |
| 1852 | |
| 1853 | " make sure only one buffer is created |
| 1854 | call writefile(['this one', 'that one'], 'Xgrepthis') |
| 1855 | vimgrep one Xgrepthis |
| 1856 | vimgrep one Xgrepthis |
| 1857 | call assert_equal(last_buffer + 1, bufnr("$")) |
| 1858 | |
| 1859 | call delete('Xgrepthis') |
| 1860 | endfunc |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1861 | |
| 1862 | " Quickfix/Location list set/get properties tests |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 1863 | func Xproperty_tests(cchar) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1864 | call s:setup_commands(a:cchar) |
| 1865 | |
| 1866 | " Error cases |
| 1867 | call assert_fails('call g:Xgetlist(99)', 'E715:') |
| 1868 | call assert_fails('call g:Xsetlist(99)', 'E714:') |
| 1869 | call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') |
| 1870 | |
| 1871 | " Set and get the title |
Bram Moolenaar | b6fa30c | 2017-03-29 14:19:25 +0200 | [diff] [blame] | 1872 | call g:Xsetlist([]) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1873 | Xopen |
| 1874 | wincmd p |
| 1875 | call g:Xsetlist([{'filename':'foo', 'lnum':27}]) |
Bram Moolenaar | 86f100dc | 2017-06-28 21:26:27 +0200 | [diff] [blame] | 1876 | let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) |
| 1877 | call assert_equal(0, s) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1878 | let d = g:Xgetlist({"title":1}) |
| 1879 | call assert_equal('Sample', d.title) |
Bram Moolenaar | a2aa8a2 | 2018-04-24 13:55:00 +0200 | [diff] [blame] | 1880 | " Try setting title to a non-string value |
| 1881 | call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) |
| 1882 | call assert_equal('Sample', g:Xgetlist({"title":1}).title) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1883 | |
| 1884 | Xopen |
| 1885 | call assert_equal('Sample', w:quickfix_title) |
| 1886 | Xclose |
| 1887 | |
Bram Moolenaar | 2b529bb | 2016-08-27 13:35:35 +0200 | [diff] [blame] | 1888 | " Tests for action argument |
| 1889 | silent! Xolder 999 |
| 1890 | let qfnr = g:Xgetlist({'all':1}).nr |
| 1891 | call g:Xsetlist([], 'r', {'title' : 'N1'}) |
| 1892 | call assert_equal('N1', g:Xgetlist({'all':1}).title) |
| 1893 | call g:Xsetlist([], ' ', {'title' : 'N2'}) |
| 1894 | call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) |
Bram Moolenaar | 890680c | 2016-09-27 21:28:56 +0200 | [diff] [blame] | 1895 | |
| 1896 | let res = g:Xgetlist({'nr': 0}) |
| 1897 | call assert_equal(qfnr + 1, res.nr) |
| 1898 | call assert_equal(['nr'], keys(res)) |
| 1899 | |
Bram Moolenaar | 2b529bb | 2016-08-27 13:35:35 +0200 | [diff] [blame] | 1900 | call g:Xsetlist([], ' ', {'title' : 'N3'}) |
| 1901 | call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) |
| 1902 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1903 | " Changing the title of an earlier quickfix list |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 1904 | call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 1905 | call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) |
| 1906 | |
| 1907 | " Changing the title of an invalid quickfix list |
| 1908 | call assert_equal(-1, g:Xsetlist([], ' ', |
| 1909 | \ {'title' : 'SomeTitle', 'nr' : 99})) |
| 1910 | call assert_equal(-1, g:Xsetlist([], ' ', |
| 1911 | \ {'title' : 'SomeTitle', 'nr' : 'abc'})) |
| 1912 | |
| 1913 | if a:cchar == 'c' |
| 1914 | copen |
| 1915 | call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) |
| 1916 | cclose |
| 1917 | endif |
| 1918 | |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1919 | " Invalid arguments |
| 1920 | call assert_fails('call g:Xgetlist([])', 'E715') |
| 1921 | call assert_fails('call g:Xsetlist([], "a", [])', 'E715') |
| 1922 | let s = g:Xsetlist([], 'a', {'abc':1}) |
| 1923 | call assert_equal(-1, s) |
| 1924 | |
| 1925 | call assert_equal({}, g:Xgetlist({'abc':1})) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 1926 | call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) |
| 1927 | call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1928 | |
| 1929 | if a:cchar == 'l' |
Bram Moolenaar | 890680c | 2016-09-27 21:28:56 +0200 | [diff] [blame] | 1930 | call assert_equal({}, getloclist(99, {'title': 1})) |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 1931 | endif |
Bram Moolenaar | 8f77c5a | 2017-04-30 14:21:00 +0200 | [diff] [blame] | 1932 | |
| 1933 | " Context related tests |
Bram Moolenaar | 86f100dc | 2017-06-28 21:26:27 +0200 | [diff] [blame] | 1934 | let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) |
| 1935 | call assert_equal(0, s) |
Bram Moolenaar | 8f77c5a | 2017-04-30 14:21:00 +0200 | [diff] [blame] | 1936 | call test_garbagecollect_now() |
| 1937 | let d = g:Xgetlist({'context':1}) |
| 1938 | call assert_equal([1,2,3], d.context) |
| 1939 | call g:Xsetlist([], 'a', {'context':{'color':'green'}}) |
| 1940 | let d = g:Xgetlist({'context':1}) |
| 1941 | call assert_equal({'color':'green'}, d.context) |
| 1942 | call g:Xsetlist([], 'a', {'context':"Context info"}) |
| 1943 | let d = g:Xgetlist({'context':1}) |
| 1944 | call assert_equal("Context info", d.context) |
| 1945 | call g:Xsetlist([], 'a', {'context':246}) |
| 1946 | let d = g:Xgetlist({'context':1}) |
| 1947 | call assert_equal(246, d.context) |
| 1948 | if a:cchar == 'l' |
| 1949 | " Test for copying context across two different location lists |
| 1950 | new | only |
| 1951 | let w1_id = win_getid() |
| 1952 | let l = [1] |
| 1953 | call setloclist(0, [], 'a', {'context':l}) |
| 1954 | new |
| 1955 | let w2_id = win_getid() |
| 1956 | call add(l, 2) |
| 1957 | call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context) |
| 1958 | call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) |
| 1959 | unlet! l |
| 1960 | call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) |
| 1961 | only |
| 1962 | call setloclist(0, [], 'f') |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 1963 | call assert_equal('', getloclist(0, {'context':1}).context) |
Bram Moolenaar | 8f77c5a | 2017-04-30 14:21:00 +0200 | [diff] [blame] | 1964 | endif |
Bram Moolenaar | 6e62da3 | 2017-05-28 08:16:25 +0200 | [diff] [blame] | 1965 | |
| 1966 | " Test for changing the context of previous quickfix lists |
| 1967 | call g:Xsetlist([], 'f') |
| 1968 | Xexpr "One" |
| 1969 | Xexpr "Two" |
| 1970 | Xexpr "Three" |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 1971 | call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1}) |
| 1972 | call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2}) |
Bram Moolenaar | 6e62da3 | 2017-05-28 08:16:25 +0200 | [diff] [blame] | 1973 | " Also, check for setting the context using quickfix list number zero. |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 1974 | call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0}) |
Bram Moolenaar | 6e62da3 | 2017-05-28 08:16:25 +0200 | [diff] [blame] | 1975 | call test_garbagecollect_now() |
| 1976 | let l = g:Xgetlist({'nr' : 1, 'context' : 1}) |
| 1977 | call assert_equal([1], l.context) |
| 1978 | let l = g:Xgetlist({'nr' : 2, 'context' : 1}) |
| 1979 | call assert_equal([2], l.context) |
| 1980 | let l = g:Xgetlist({'nr' : 3, 'context' : 1}) |
| 1981 | call assert_equal([3], l.context) |
| 1982 | |
| 1983 | " Test for changing the context through reference and for garbage |
| 1984 | " collection of quickfix context |
| 1985 | let l = ["red"] |
| 1986 | call g:Xsetlist([], ' ', {'context' : l}) |
| 1987 | call add(l, "blue") |
| 1988 | let x = g:Xgetlist({'context' : 1}) |
| 1989 | call add(x.context, "green") |
| 1990 | call assert_equal(["red", "blue", "green"], l) |
| 1991 | call assert_equal(["red", "blue", "green"], x.context) |
| 1992 | unlet l |
| 1993 | call test_garbagecollect_now() |
| 1994 | let m = g:Xgetlist({'context' : 1}) |
| 1995 | call assert_equal(["red", "blue", "green"], m.context) |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 1996 | |
| 1997 | " Test for setting/getting items |
| 1998 | Xexpr "" |
| 1999 | let qfprev = g:Xgetlist({'nr':0}) |
Bram Moolenaar | 86f100dc | 2017-06-28 21:26:27 +0200 | [diff] [blame] | 2000 | let s = g:Xsetlist([], ' ', {'title':'Green', |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2001 | \ 'items' : [{'filename':'F1', 'lnum':10}]}) |
Bram Moolenaar | 86f100dc | 2017-06-28 21:26:27 +0200 | [diff] [blame] | 2002 | call assert_equal(0, s) |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2003 | let qfcur = g:Xgetlist({'nr':0}) |
| 2004 | call assert_true(qfcur.nr == qfprev.nr + 1) |
| 2005 | let l = g:Xgetlist({'items':1}) |
| 2006 | call assert_equal('F1', bufname(l.items[0].bufnr)) |
| 2007 | call assert_equal(10, l.items[0].lnum) |
| 2008 | call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20}, |
| 2009 | \ {'filename':'F2', 'lnum':30}]}) |
| 2010 | let l = g:Xgetlist({'items':1}) |
| 2011 | call assert_equal('F2', bufname(l.items[2].bufnr)) |
| 2012 | call assert_equal(30, l.items[2].lnum) |
| 2013 | call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]}) |
| 2014 | let l = g:Xgetlist({'items':1}) |
| 2015 | call assert_equal('F3', bufname(l.items[0].bufnr)) |
| 2016 | call assert_equal(40, l.items[0].lnum) |
| 2017 | call g:Xsetlist([], 'r', {'items' : []}) |
| 2018 | let l = g:Xgetlist({'items':1}) |
| 2019 | call assert_equal(0, len(l.items)) |
| 2020 | |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 2021 | call g:Xsetlist([], 'r', {'title' : 'TestTitle'}) |
| 2022 | call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) |
| 2023 | call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) |
| 2024 | call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title) |
| 2025 | |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 2026 | " Test for getting id of window associated with a location list window |
| 2027 | if a:cchar == 'l' |
| 2028 | only |
| 2029 | call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid) |
| 2030 | let wid = win_getid() |
| 2031 | Xopen |
| 2032 | call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid) |
| 2033 | wincmd w |
| 2034 | call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid) |
| 2035 | only |
| 2036 | endif |
| 2037 | |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2038 | " The following used to crash Vim with address sanitizer |
| 2039 | call g:Xsetlist([], 'f') |
| 2040 | call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) |
| 2041 | call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum) |
| 2042 | |
Bram Moolenaar | a2aa8a2 | 2018-04-24 13:55:00 +0200 | [diff] [blame] | 2043 | " Try setting the items using a string |
| 2044 | call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'})) |
| 2045 | |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2046 | " Save and restore the quickfix stack |
| 2047 | call g:Xsetlist([], 'f') |
| 2048 | call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) |
| 2049 | Xexpr "File1:10:Line1" |
| 2050 | Xexpr "File2:20:Line2" |
| 2051 | Xexpr "File3:30:Line3" |
| 2052 | let last_qf = g:Xgetlist({'nr':'$'}).nr |
| 2053 | call assert_equal(3, last_qf) |
| 2054 | let qstack = [] |
| 2055 | for i in range(1, last_qf) |
| 2056 | let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1})) |
| 2057 | endfor |
| 2058 | call g:Xsetlist([], 'f') |
| 2059 | for i in range(len(qstack)) |
| 2060 | call g:Xsetlist([], ' ', qstack[i]) |
| 2061 | endfor |
| 2062 | call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) |
| 2063 | call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum) |
| 2064 | call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum) |
| 2065 | call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum) |
| 2066 | call g:Xsetlist([], 'f') |
| 2067 | |
| 2068 | " Swap two quickfix lists |
| 2069 | Xexpr "File1:10:Line10" |
| 2070 | Xexpr "File2:20:Line20" |
| 2071 | Xexpr "File3:30:Line30" |
| 2072 | call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']}) |
| 2073 | call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']}) |
| 2074 | let l1=g:Xgetlist({'nr':1,'all':1}) |
| 2075 | let l2=g:Xgetlist({'nr':2,'all':1}) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 2076 | let save_id = l1.id |
| 2077 | let l1.id=l2.id |
| 2078 | let l2.id=save_id |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2079 | call g:Xsetlist([], 'r', l1) |
| 2080 | call g:Xsetlist([], 'r', l2) |
| 2081 | let newl1=g:Xgetlist({'nr':1,'all':1}) |
| 2082 | let newl2=g:Xgetlist({'nr':2,'all':1}) |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 2083 | call assert_equal('Fruits', newl1.title) |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2084 | call assert_equal(['Fruits'], newl1.context) |
| 2085 | call assert_equal('Line20', newl1.items[0].text) |
Bram Moolenaar | b4d5fba | 2017-09-11 19:31:28 +0200 | [diff] [blame] | 2086 | call assert_equal('Colors', newl2.title) |
Bram Moolenaar | 6a8958d | 2017-06-22 21:33:20 +0200 | [diff] [blame] | 2087 | call assert_equal(['Colors'], newl2.context) |
| 2088 | call assert_equal('Line10', newl2.items[0].text) |
| 2089 | call g:Xsetlist([], 'f') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2090 | endfunc |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2091 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2092 | func Test_qf_property() |
Bram Moolenaar | d823fa9 | 2016-08-12 16:29:27 +0200 | [diff] [blame] | 2093 | call Xproperty_tests('c') |
| 2094 | call Xproperty_tests('l') |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2095 | endfunc |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2096 | |
Bram Moolenaar | 5b69c22 | 2019-01-11 14:50:06 +0100 | [diff] [blame] | 2097 | " Test for setting the current index in the location/quickfix list |
| 2098 | func Xtest_setqfidx(cchar) |
| 2099 | call s:setup_commands(a:cchar) |
| 2100 | |
| 2101 | Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3" |
| 2102 | Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3" |
| 2103 | Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3" |
| 2104 | |
| 2105 | call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2}) |
| 2106 | call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2}) |
| 2107 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3}) |
| 2108 | Xolder 2 |
| 2109 | Xopen |
| 2110 | call assert_equal(3, line('.')) |
| 2111 | Xnewer |
| 2112 | call assert_equal(2, line('.')) |
| 2113 | Xnewer |
| 2114 | call assert_equal(2, line('.')) |
| 2115 | " Update the current index with the quickfix window open |
| 2116 | wincmd w |
| 2117 | call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3}) |
| 2118 | Xopen |
| 2119 | call assert_equal(3, line('.')) |
| 2120 | Xclose |
| 2121 | |
| 2122 | " Set the current index to the last entry |
| 2123 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'}) |
| 2124 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2125 | " A large value should set the index to the last index |
| 2126 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1}) |
| 2127 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999}) |
| 2128 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2129 | " Invalid index values |
| 2130 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1}) |
| 2131 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2132 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0}) |
| 2133 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2134 | call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'}) |
| 2135 | call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) |
| 2136 | call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:') |
| 2137 | |
| 2138 | call g:Xsetlist([], 'f') |
| 2139 | new | only |
| 2140 | endfunc |
| 2141 | |
| 2142 | func Test_setqfidx() |
| 2143 | call Xtest_setqfidx('c') |
| 2144 | call Xtest_setqfidx('l') |
| 2145 | endfunc |
| 2146 | |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2147 | " Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2148 | func QfAutoCmdHandler(loc, cmd) |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2149 | call add(g:acmds, a:loc . a:cmd) |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2150 | endfunc |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2151 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2152 | func Test_Autocmd() |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2153 | autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>')) |
| 2154 | autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>')) |
| 2155 | |
| 2156 | let g:acmds = [] |
| 2157 | cexpr "F1:10:Line 10" |
| 2158 | caddexpr "F1:20:Line 20" |
| 2159 | cgetexpr "F1:30:Line 30" |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2160 | cexpr "" |
| 2161 | caddexpr "" |
| 2162 | cgetexpr "" |
| 2163 | silent! cexpr non_existing_func() |
| 2164 | silent! caddexpr non_existing_func() |
| 2165 | silent! cgetexpr non_existing_func() |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2166 | let l = ['precexpr', |
| 2167 | \ 'postcexpr', |
| 2168 | \ 'precaddexpr', |
| 2169 | \ 'postcaddexpr', |
| 2170 | \ 'precgetexpr', |
| 2171 | \ 'postcgetexpr', |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2172 | \ 'precexpr', |
| 2173 | \ 'postcexpr', |
| 2174 | \ 'precaddexpr', |
| 2175 | \ 'postcaddexpr', |
| 2176 | \ 'precgetexpr', |
| 2177 | \ 'postcgetexpr', |
| 2178 | \ 'precexpr', |
| 2179 | \ 'precaddexpr', |
| 2180 | \ 'precgetexpr'] |
| 2181 | call assert_equal(l, g:acmds) |
| 2182 | |
| 2183 | let g:acmds = [] |
| 2184 | enew! | call append(0, "F2:10:Line 10") |
| 2185 | cbuffer! |
| 2186 | enew! | call append(0, "F2:20:Line 20") |
| 2187 | cgetbuffer |
| 2188 | enew! | call append(0, "F2:30:Line 30") |
| 2189 | caddbuffer |
| 2190 | new |
| 2191 | let bnum = bufnr('%') |
| 2192 | bunload |
| 2193 | exe 'silent! cbuffer! ' . bnum |
| 2194 | exe 'silent! cgetbuffer ' . bnum |
| 2195 | exe 'silent! caddbuffer ' . bnum |
| 2196 | enew! |
| 2197 | let l = ['precbuffer', |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2198 | \ 'postcbuffer', |
| 2199 | \ 'precgetbuffer', |
| 2200 | \ 'postcgetbuffer', |
| 2201 | \ 'precaddbuffer', |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2202 | \ 'postcaddbuffer', |
| 2203 | \ 'precbuffer', |
| 2204 | \ 'precgetbuffer', |
| 2205 | \ 'precaddbuffer'] |
Bram Moolenaar | 04c4ce6 | 2016-09-01 15:45:58 +0200 | [diff] [blame] | 2206 | call assert_equal(l, g:acmds) |
Bram Moolenaar | 1ed2276 | 2017-11-28 18:03:44 +0100 | [diff] [blame] | 2207 | |
| 2208 | call writefile(['Xtest:1:Line1'], 'Xtest') |
| 2209 | call writefile([], 'Xempty') |
| 2210 | let g:acmds = [] |
| 2211 | cfile Xtest |
| 2212 | caddfile Xtest |
| 2213 | cgetfile Xtest |
| 2214 | cfile Xempty |
| 2215 | caddfile Xempty |
| 2216 | cgetfile Xempty |
| 2217 | silent! cfile do_not_exist |
| 2218 | silent! caddfile do_not_exist |
| 2219 | silent! cgetfile do_not_exist |
| 2220 | let l = ['precfile', |
| 2221 | \ 'postcfile', |
| 2222 | \ 'precaddfile', |
| 2223 | \ 'postcaddfile', |
| 2224 | \ 'precgetfile', |
| 2225 | \ 'postcgetfile', |
| 2226 | \ 'precfile', |
| 2227 | \ 'postcfile', |
| 2228 | \ 'precaddfile', |
| 2229 | \ 'postcaddfile', |
| 2230 | \ 'precgetfile', |
| 2231 | \ 'postcgetfile', |
| 2232 | \ 'precfile', |
| 2233 | \ 'postcfile', |
| 2234 | \ 'precaddfile', |
| 2235 | \ 'postcaddfile', |
| 2236 | \ 'precgetfile', |
| 2237 | \ 'postcgetfile'] |
| 2238 | call assert_equal(l, g:acmds) |
| 2239 | |
| 2240 | let g:acmds = [] |
| 2241 | helpgrep quickfix |
| 2242 | silent! helpgrep non_existing_help_topic |
| 2243 | vimgrep test Xtest |
| 2244 | vimgrepadd test Xtest |
| 2245 | silent! vimgrep non_existing_test Xtest |
| 2246 | silent! vimgrepadd non_existing_test Xtest |
| 2247 | set makeprg= |
| 2248 | silent! make |
| 2249 | set makeprg& |
| 2250 | let l = ['prehelpgrep', |
| 2251 | \ 'posthelpgrep', |
| 2252 | \ 'prehelpgrep', |
| 2253 | \ 'posthelpgrep', |
| 2254 | \ 'previmgrep', |
| 2255 | \ 'postvimgrep', |
| 2256 | \ 'previmgrepadd', |
| 2257 | \ 'postvimgrepadd', |
| 2258 | \ 'previmgrep', |
| 2259 | \ 'postvimgrep', |
| 2260 | \ 'previmgrepadd', |
| 2261 | \ 'postvimgrepadd', |
| 2262 | \ 'premake', |
| 2263 | \ 'postmake'] |
| 2264 | call assert_equal(l, g:acmds) |
| 2265 | |
| 2266 | if has('unix') |
| 2267 | " Run this test only on Unix-like systems. The grepprg may not be set on |
| 2268 | " non-Unix systems. |
| 2269 | " The following lines are used for the grep test. Don't remove. |
| 2270 | " Grep_Autocmd_Text: Match 1 |
| 2271 | " GrepAdd_Autocmd_Text: Match 2 |
| 2272 | let g:acmds = [] |
| 2273 | silent grep Grep_Autocmd_Text test_quickfix.vim |
| 2274 | silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim |
| 2275 | silent grep abc123def Xtest |
| 2276 | silent grepadd abc123def Xtest |
| 2277 | let l = ['pregrep', |
| 2278 | \ 'postgrep', |
| 2279 | \ 'pregrepadd', |
| 2280 | \ 'postgrepadd', |
| 2281 | \ 'pregrep', |
| 2282 | \ 'postgrep', |
| 2283 | \ 'pregrepadd', |
| 2284 | \ 'postgrepadd'] |
| 2285 | call assert_equal(l, g:acmds) |
| 2286 | endif |
| 2287 | |
| 2288 | call delete('Xtest') |
| 2289 | call delete('Xempty') |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 2290 | au! QuickFixCmdPre |
| 2291 | au! QuickFixCmdPost |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2292 | endfunc |
Bram Moolenaar | 21662be | 2016-11-06 14:46:44 +0100 | [diff] [blame] | 2293 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2294 | func Test_Autocmd_Exception() |
Bram Moolenaar | 21662be | 2016-11-06 14:46:44 +0100 | [diff] [blame] | 2295 | set efm=%m |
| 2296 | lgetexpr '?' |
| 2297 | |
| 2298 | try |
| 2299 | call DoesNotExit() |
| 2300 | catch |
| 2301 | lgetexpr '1' |
| 2302 | finally |
| 2303 | lgetexpr '1' |
| 2304 | endtry |
| 2305 | |
| 2306 | call assert_equal('1', getloclist(0)[0].text) |
| 2307 | |
| 2308 | set efm&vim |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2309 | endfunc |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 2310 | |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2311 | func Test_caddbuffer_wrong() |
| 2312 | " This used to cause a memory access in freed memory. |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 2313 | let save_efm = &efm |
| 2314 | set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.# |
| 2315 | cgetexpr ['WWWW', 'EEEE', 'CCCC'] |
| 2316 | let &efm = save_efm |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2317 | caddbuffer |
Bram Moolenaar | 63bed3d | 2016-11-12 15:36:54 +0100 | [diff] [blame] | 2318 | bwipe! |
| 2319 | endfunc |
Bram Moolenaar | 2b946c9 | 2016-11-12 18:14:44 +0100 | [diff] [blame] | 2320 | |
| 2321 | func Test_caddexpr_wrong() |
| 2322 | " This used to cause a memory access in freed memory. |
| 2323 | cbuffer |
| 2324 | cbuffer |
| 2325 | copen |
| 2326 | let save_efm = &efm |
| 2327 | set efm=% |
| 2328 | call assert_fails('caddexpr ""', 'E376:') |
| 2329 | let &efm = save_efm |
| 2330 | endfunc |
Bram Moolenaar | 7618e00 | 2016-11-13 15:09:26 +0100 | [diff] [blame] | 2331 | |
| 2332 | func Test_dirstack_cleanup() |
| 2333 | " This used to cause a memory access in freed memory. |
| 2334 | let save_efm = &efm |
| 2335 | lexpr '0' |
| 2336 | lopen |
| 2337 | fun X(c) |
| 2338 | let save_efm=&efm |
| 2339 | set efm=%D%f |
| 2340 | if a:c == 'c' |
| 2341 | caddexpr '::' |
| 2342 | else |
| 2343 | laddexpr ':0:0' |
| 2344 | endif |
| 2345 | let &efm=save_efm |
| 2346 | endfun |
| 2347 | call X('c') |
| 2348 | call X('l') |
| 2349 | call setqflist([], 'r') |
| 2350 | caddbuffer |
| 2351 | let &efm = save_efm |
| 2352 | endfunc |
Bram Moolenaar | 391b1dd | 2017-03-04 13:47:11 +0100 | [diff] [blame] | 2353 | |
| 2354 | " Tests for jumping to entries from the location list window and quickfix |
| 2355 | " window |
| 2356 | func Test_cwindow_jump() |
| 2357 | set efm=%f%%%l%%%m |
| 2358 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 2359 | lopen | only |
| 2360 | lfirst |
| 2361 | call assert_true(winnr('$') == 2) |
| 2362 | call assert_true(winnr() == 1) |
| 2363 | " Location list for the new window should be set |
| 2364 | call assert_true(getloclist(0)[2].text == 'Line 30') |
| 2365 | |
| 2366 | " Open a scratch buffer |
| 2367 | " Open a new window and create a location list |
| 2368 | " Open the location list window and close the other window |
| 2369 | " Jump to an entry. |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 2370 | " 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] | 2371 | " should not be used. |
| 2372 | enew | only |
| 2373 | set buftype=nofile |
| 2374 | below new |
| 2375 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 2376 | lopen |
| 2377 | 2wincmd c |
| 2378 | lnext |
| 2379 | call assert_true(winnr('$') == 3) |
| 2380 | call assert_true(winnr() == 2) |
| 2381 | |
| 2382 | " Open two windows with two different location lists |
| 2383 | " Open the location list window and close the previous window |
| 2384 | " Jump to an entry in the location list window |
| 2385 | " Should open the file in the first window and not set the location list. |
| 2386 | enew | only |
| 2387 | lgetexpr ["F1%5%Line 5"] |
| 2388 | below new |
| 2389 | lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 2390 | lopen |
| 2391 | 2wincmd c |
| 2392 | lnext |
| 2393 | call assert_true(winnr() == 1) |
| 2394 | call assert_true(getloclist(0)[0].text == 'Line 5') |
| 2395 | |
| 2396 | enew | only |
| 2397 | cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] |
| 2398 | copen |
| 2399 | cnext |
| 2400 | call assert_true(winnr('$') == 2) |
| 2401 | call assert_true(winnr() == 1) |
| 2402 | |
| 2403 | enew | only |
| 2404 | set efm&vim |
| 2405 | endfunc |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2406 | |
| 2407 | func XvimgrepTests(cchar) |
| 2408 | call s:setup_commands(a:cchar) |
| 2409 | |
| 2410 | call writefile(['Editor:VIM vim', |
| 2411 | \ 'Editor:Emacs EmAcS', |
| 2412 | \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1') |
| 2413 | call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2') |
| 2414 | |
| 2415 | " Error cases |
| 2416 | call assert_fails('Xvimgrep /abc *', 'E682:') |
| 2417 | |
| 2418 | let @/='' |
| 2419 | call assert_fails('Xvimgrep // *', 'E35:') |
| 2420 | |
| 2421 | call assert_fails('Xvimgrep abc', 'E683:') |
| 2422 | call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:') |
| 2423 | call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:') |
| 2424 | |
| 2425 | Xexpr "" |
| 2426 | Xvimgrepadd Notepad Xtestfile1 |
| 2427 | Xvimgrepadd MacOS Xtestfile2 |
| 2428 | let l = g:Xgetlist() |
| 2429 | call assert_equal(2, len(l)) |
| 2430 | call assert_equal('Editor:Notepad NOTEPAD', l[0].text) |
| 2431 | |
| 2432 | Xvimgrep #\cvim#g Xtestfile? |
| 2433 | let l = g:Xgetlist() |
| 2434 | call assert_equal(2, len(l)) |
| 2435 | call assert_equal(8, l[0].col) |
| 2436 | call assert_equal(12, l[1].col) |
| 2437 | |
| 2438 | 1Xvimgrep ?Editor? Xtestfile* |
| 2439 | let l = g:Xgetlist() |
| 2440 | call assert_equal(1, len(l)) |
| 2441 | call assert_equal('Editor:VIM vim', l[0].text) |
| 2442 | |
| 2443 | edit +3 Xtestfile2 |
| 2444 | Xvimgrep +\cemacs+j Xtestfile1 |
| 2445 | let l = g:Xgetlist() |
| 2446 | call assert_equal('Xtestfile2', bufname('')) |
| 2447 | call assert_equal('Editor:Emacs EmAcS', l[0].text) |
| 2448 | |
Bram Moolenaar | 2225ebb | 2018-04-24 15:48:11 +0200 | [diff] [blame] | 2449 | " Test for unloading a buffer after vimgrep searched the buffer |
| 2450 | %bwipe |
| 2451 | Xvimgrep /Editor/j Xtestfile* |
| 2452 | call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) |
| 2453 | call assert_equal([], getbufinfo('Xtestfile2')) |
| 2454 | |
Bram Moolenaar | ee85df3 | 2017-03-19 14:19:50 +0100 | [diff] [blame] | 2455 | call delete('Xtestfile1') |
| 2456 | call delete('Xtestfile2') |
| 2457 | endfunc |
| 2458 | |
| 2459 | " Tests for the :vimgrep command |
| 2460 | func Test_vimgrep() |
| 2461 | call XvimgrepTests('c') |
| 2462 | call XvimgrepTests('l') |
| 2463 | endfunc |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 2464 | |
Bram Moolenaar | 1c29943 | 2018-10-28 14:36:09 +0100 | [diff] [blame] | 2465 | " Test for incsearch highlighting of the :vimgrep pattern |
| 2466 | " This test used to cause "E315: ml_get: invalid lnum" errors. |
| 2467 | func Test_vimgrep_incsearch() |
| 2468 | enew |
| 2469 | set incsearch |
| 2470 | call test_override("char_avail", 1) |
| 2471 | |
| 2472 | call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx") |
| 2473 | let l = getqflist() |
| 2474 | call assert_equal(2, len(l)) |
| 2475 | |
| 2476 | call test_override("ALL", 0) |
| 2477 | set noincsearch |
| 2478 | endfunc |
| 2479 | |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 2480 | func XfreeTests(cchar) |
| 2481 | call s:setup_commands(a:cchar) |
| 2482 | |
| 2483 | enew | only |
| 2484 | |
| 2485 | " Deleting the quickfix stack should work even When the current list is |
| 2486 | " somewhere in the middle of the stack |
| 2487 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 2488 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 2489 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 2490 | Xolder |
| 2491 | call g:Xsetlist([], 'f') |
| 2492 | call assert_equal(0, len(g:Xgetlist())) |
| 2493 | |
| 2494 | " After deleting the stack, adding a new list should create a stack with a |
| 2495 | " single list. |
| 2496 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 2497 | call assert_equal(1, g:Xgetlist({'all':1}).nr) |
| 2498 | |
| 2499 | " Deleting the stack from a quickfix window should update/clear the |
| 2500 | " quickfix/location list window. |
| 2501 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 2502 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 2503 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 2504 | Xolder |
| 2505 | Xwindow |
| 2506 | call g:Xsetlist([], 'f') |
| 2507 | call assert_equal(2, winnr('$')) |
| 2508 | call assert_equal(1, line('$')) |
| 2509 | Xclose |
| 2510 | |
| 2511 | " Deleting the stack from a non-quickfix window should update/clear the |
| 2512 | " quickfix/location list window. |
| 2513 | Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 2514 | Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] |
| 2515 | Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] |
| 2516 | Xolder |
| 2517 | Xwindow |
| 2518 | wincmd p |
| 2519 | call g:Xsetlist([], 'f') |
| 2520 | call assert_equal(0, len(g:Xgetlist())) |
| 2521 | wincmd p |
| 2522 | call assert_equal(2, winnr('$')) |
| 2523 | call assert_equal(1, line('$')) |
| 2524 | |
| 2525 | " After deleting the location list stack, if the location list window is |
| 2526 | " opened, then a new location list should be created. So opening the |
| 2527 | " location list window again should not create a new window. |
| 2528 | if a:cchar == 'l' |
| 2529 | lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] |
| 2530 | wincmd p |
| 2531 | lopen |
| 2532 | call assert_equal(2, winnr('$')) |
| 2533 | endif |
| 2534 | Xclose |
| 2535 | endfunc |
| 2536 | |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 2537 | " Tests for the quickfix free functionality |
Bram Moolenaar | 69f40be | 2017-04-02 15:15:49 +0200 | [diff] [blame] | 2538 | func Test_qf_free() |
| 2539 | call XfreeTests('c') |
| 2540 | call XfreeTests('l') |
| 2541 | endfunc |
Bram Moolenaar | 6e62da3 | 2017-05-28 08:16:25 +0200 | [diff] [blame] | 2542 | |
| 2543 | " Test for buffer overflow when parsing lines and adding new entries to |
| 2544 | " the quickfix list. |
| 2545 | func Test_bufoverflow() |
| 2546 | set efm=%f:%l:%m |
| 2547 | cgetexpr ['File1:100:' . repeat('x', 1025)] |
| 2548 | |
| 2549 | set efm=%+GCompiler:\ %.%#,%f:%l:%m |
| 2550 | cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] |
| 2551 | |
| 2552 | set efm=%DEntering\ directory\ %f,%f:%l:%m |
| 2553 | cgetexpr ['Entering directory ' . repeat('a', 1006), |
| 2554 | \ 'File1:10:Hello World'] |
| 2555 | set efm&vim |
| 2556 | endfunc |
| 2557 | |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 2558 | " Tests for getting the quickfix stack size |
| 2559 | func XsizeTests(cchar) |
| 2560 | call s:setup_commands(a:cchar) |
| 2561 | |
| 2562 | call g:Xsetlist([], 'f') |
| 2563 | call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 2564 | call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title) |
| 2565 | call assert_equal(0, g:Xgetlist({'nr':0}).nr) |
Bram Moolenaar | 875feea | 2017-06-11 16:07:51 +0200 | [diff] [blame] | 2566 | |
| 2567 | Xexpr "File1:10:Line1" |
| 2568 | Xexpr "File2:20:Line2" |
| 2569 | Xexpr "File3:30:Line3" |
| 2570 | Xolder | Xolder |
| 2571 | call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) |
| 2572 | call g:Xsetlist([], 'f') |
| 2573 | |
| 2574 | Xexpr "File1:10:Line1" |
| 2575 | Xexpr "File2:20:Line2" |
| 2576 | Xexpr "File3:30:Line3" |
| 2577 | Xolder | Xolder |
| 2578 | call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'}) |
| 2579 | call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title) |
| 2580 | endfunc |
| 2581 | |
| 2582 | func Test_Qf_Size() |
| 2583 | call XsizeTests('c') |
| 2584 | call XsizeTests('l') |
| 2585 | endfunc |
Bram Moolenaar | 1814183 | 2017-06-25 21:17:25 +0200 | [diff] [blame] | 2586 | |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 2587 | func Test_cclose_from_copen() |
| 2588 | augroup QF_Test |
| 2589 | au! |
| 2590 | au FileType qf :call assert_fails(':cclose', 'E788') |
| 2591 | augroup END |
| 2592 | copen |
| 2593 | augroup QF_Test |
| 2594 | au! |
| 2595 | augroup END |
| 2596 | augroup! QF_Test |
| 2597 | endfunc |
| 2598 | |
Bram Moolenaar | 1814183 | 2017-06-25 21:17:25 +0200 | [diff] [blame] | 2599 | func Test_cclose_in_autocmd() |
| 2600 | " Problem is only triggered if "starting" is zero, so that the OptionsSet |
| 2601 | " event will be triggered. |
| 2602 | call test_override('starting', 1) |
| 2603 | augroup QF_Test |
| 2604 | au! |
| 2605 | au FileType qf :call assert_fails(':cclose', 'E788') |
| 2606 | augroup END |
| 2607 | copen |
| 2608 | augroup QF_Test |
| 2609 | au! |
| 2610 | augroup END |
| 2611 | augroup! QF_Test |
| 2612 | call test_override('starting', 0) |
| 2613 | endfunc |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 2614 | |
Bram Moolenaar | 379fb76 | 2018-08-30 15:58:28 +0200 | [diff] [blame] | 2615 | " Check that ":file" without an argument is possible even when "curbuf_lock" |
| 2616 | " is set. |
| 2617 | func Test_file_from_copen() |
| 2618 | " Works without argument. |
| 2619 | augroup QF_Test |
| 2620 | au! |
| 2621 | au FileType qf file |
| 2622 | augroup END |
| 2623 | copen |
| 2624 | |
| 2625 | augroup QF_Test |
| 2626 | au! |
| 2627 | augroup END |
| 2628 | cclose |
| 2629 | |
| 2630 | " Fails with argument. |
| 2631 | augroup QF_Test |
| 2632 | au! |
| 2633 | au FileType qf call assert_fails(':file foo', 'E788') |
| 2634 | augroup END |
| 2635 | copen |
| 2636 | augroup QF_Test |
| 2637 | au! |
| 2638 | augroup END |
| 2639 | cclose |
| 2640 | |
| 2641 | augroup! QF_Test |
| 2642 | endfunction |
| 2643 | |
Bram Moolenaar | 9c4feff | 2017-06-28 22:26:54 +0200 | [diff] [blame] | 2644 | func Test_resize_from_copen() |
| 2645 | augroup QF_Test |
| 2646 | au! |
| 2647 | au FileType qf resize 5 |
| 2648 | augroup END |
| 2649 | try |
| 2650 | " This should succeed without any exception. No other buffers are |
| 2651 | " involved in the autocmd. |
| 2652 | copen |
| 2653 | finally |
| 2654 | augroup QF_Test |
| 2655 | au! |
| 2656 | augroup END |
| 2657 | augroup! QF_Test |
| 2658 | endtry |
| 2659 | endfunc |
Bram Moolenaar | a8788f4 | 2017-07-19 17:06:20 +0200 | [diff] [blame] | 2660 | |
| 2661 | " Tests for the quickfix buffer b:changedtick variable |
| 2662 | func Xchangedtick_tests(cchar) |
| 2663 | call s:setup_commands(a:cchar) |
| 2664 | |
| 2665 | new | only |
| 2666 | |
| 2667 | Xexpr "" | Xexpr "" | Xexpr "" |
| 2668 | |
| 2669 | Xopen |
| 2670 | Xolder |
| 2671 | Xolder |
| 2672 | Xaddexpr "F1:10:Line10" |
| 2673 | Xaddexpr "F2:20:Line20" |
| 2674 | call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a') |
| 2675 | call g:Xsetlist([], 'f') |
| 2676 | call assert_equal(8, getbufvar('%', 'changedtick')) |
| 2677 | Xclose |
| 2678 | endfunc |
| 2679 | |
| 2680 | func Test_changedtick() |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2681 | call Xchangedtick_tests('c') |
| 2682 | call Xchangedtick_tests('l') |
| 2683 | endfunc |
| 2684 | |
| 2685 | " Tests for parsing an expression using setqflist() |
| 2686 | func Xsetexpr_tests(cchar) |
| 2687 | call s:setup_commands(a:cchar) |
| 2688 | |
| 2689 | let t = ["File1:10:Line10", "File1:20:Line20"] |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2690 | call g:Xsetlist([], ' ', {'lines' : t}) |
| 2691 | call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2692 | |
| 2693 | let l = g:Xgetlist() |
| 2694 | call assert_equal(3, len(l)) |
| 2695 | call assert_equal(20, l[1].lnum) |
| 2696 | call assert_equal('Line30', l[2].text) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2697 | call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2698 | let l = g:Xgetlist() |
| 2699 | call assert_equal(1, len(l)) |
| 2700 | call assert_equal('Line5', l[0].text) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2701 | call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10})) |
| 2702 | call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"})) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2703 | |
| 2704 | call g:Xsetlist([], 'f') |
| 2705 | " Add entries to multiple lists |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2706 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]}) |
| 2707 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]}) |
| 2708 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]}) |
| 2709 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2710 | call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text) |
| 2711 | 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] | 2712 | |
| 2713 | " Adding entries using a custom efm |
| 2714 | set efm& |
| 2715 | call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m', |
| 2716 | \ 'lines' : ["F1#10#L10", "F2#20#L20"]}) |
| 2717 | call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) |
| 2718 | call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]}) |
| 2719 | call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text) |
| 2720 | call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) |
| 2721 | call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [], |
| 2722 | \ 'lines' : ['F1:10:L10']})) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2723 | endfunc |
| 2724 | |
| 2725 | func Test_setexpr() |
| 2726 | call Xsetexpr_tests('c') |
| 2727 | call Xsetexpr_tests('l') |
| 2728 | endfunc |
| 2729 | |
| 2730 | " Tests for per quickfix/location list directory stack |
| 2731 | func Xmultidirstack_tests(cchar) |
| 2732 | call s:setup_commands(a:cchar) |
| 2733 | |
| 2734 | call g:Xsetlist([], 'f') |
| 2735 | Xexpr "" | Xexpr "" |
| 2736 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2737 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]}) |
| 2738 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]}) |
| 2739 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]}) |
| 2740 | 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] | 2741 | |
| 2742 | let l1 = g:Xgetlist({'nr':1, 'items':1}) |
| 2743 | let l2 = g:Xgetlist({'nr':2, 'items':1}) |
| 2744 | call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr)) |
| 2745 | call assert_equal(3, l1.items[1].lnum) |
| 2746 | call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr)) |
| 2747 | call assert_equal(5, l2.items[1].lnum) |
| 2748 | endfunc |
| 2749 | |
| 2750 | func Test_multidirstack() |
| 2751 | call mkdir('Xone/a', 'p') |
| 2752 | call mkdir('Xtwo/a', 'p') |
| 2753 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 2754 | call writefile(lines, 'Xone/a/one.txt') |
| 2755 | call writefile(lines, 'Xtwo/a/two.txt') |
| 2756 | let save_efm = &efm |
| 2757 | set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' |
| 2758 | |
| 2759 | call Xmultidirstack_tests('c') |
| 2760 | call Xmultidirstack_tests('l') |
| 2761 | |
| 2762 | let &efm = save_efm |
| 2763 | call delete('Xone', 'rf') |
| 2764 | call delete('Xtwo', 'rf') |
| 2765 | endfunc |
| 2766 | |
| 2767 | " Tests for per quickfix/location list file stack |
| 2768 | func Xmultifilestack_tests(cchar) |
| 2769 | call s:setup_commands(a:cchar) |
| 2770 | |
| 2771 | call g:Xsetlist([], 'f') |
| 2772 | Xexpr "" | Xexpr "" |
| 2773 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2774 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]}) |
| 2775 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]}) |
| 2776 | call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]}) |
| 2777 | call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]}) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2778 | |
| 2779 | let l1 = g:Xgetlist({'nr':1, 'items':1}) |
| 2780 | let l2 = g:Xgetlist({'nr':2, 'items':1}) |
| 2781 | call assert_equal('one.txt', bufname(l1.items[1].bufnr)) |
| 2782 | call assert_equal(3, l1.items[1].lnum) |
| 2783 | call assert_equal('two.txt', bufname(l2.items[1].bufnr)) |
| 2784 | call assert_equal(5, l2.items[1].lnum) |
Bram Moolenaar | e333e79 | 2018-04-08 13:27:39 +0200 | [diff] [blame] | 2785 | |
| 2786 | " Test for start of a new error line in the same line where a previous |
| 2787 | " error line ends with a file stack. |
| 2788 | let efm_val = 'Error\ l%l\ in\ %f,' |
| 2789 | let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r' |
| 2790 | let l = g:Xgetlist({'lines' : [ |
| 2791 | \ '(one.txt', |
| 2792 | \ 'Error l4 in one.txt', |
| 2793 | \ ') (two.txt', |
| 2794 | \ 'Error l6 in two.txt', |
| 2795 | \ ')', |
| 2796 | \ 'Error l8 in one.txt' |
| 2797 | \ ], 'efm' : efm_val}) |
| 2798 | call assert_equal(3, len(l.items)) |
| 2799 | call assert_equal('one.txt', bufname(l.items[0].bufnr)) |
| 2800 | call assert_equal(4, l.items[0].lnum) |
| 2801 | call assert_equal('one.txt', l.items[0].text) |
| 2802 | call assert_equal('two.txt', bufname(l.items[1].bufnr)) |
| 2803 | call assert_equal(6, l.items[1].lnum) |
| 2804 | call assert_equal('two.txt', l.items[1].text) |
| 2805 | call assert_equal('one.txt', bufname(l.items[2].bufnr)) |
| 2806 | call assert_equal(8, l.items[2].lnum) |
| 2807 | call assert_equal('', l.items[2].text) |
Bram Moolenaar | ae33833 | 2017-08-11 20:25:26 +0200 | [diff] [blame] | 2808 | endfunc |
| 2809 | |
| 2810 | func Test_multifilestack() |
| 2811 | let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] |
| 2812 | call writefile(lines, 'one.txt') |
| 2813 | call writefile(lines, 'two.txt') |
| 2814 | let save_efm = &efm |
| 2815 | set efm=%+P[%f],(%l\\,%c)\ %m,%-Q |
| 2816 | |
| 2817 | call Xmultifilestack_tests('c') |
| 2818 | call Xmultifilestack_tests('l') |
| 2819 | |
| 2820 | let &efm = save_efm |
| 2821 | call delete('one.txt') |
| 2822 | call delete('two.txt') |
| 2823 | endfunc |
| 2824 | |
| 2825 | " Tests for per buffer 'efm' setting |
| 2826 | func Test_perbuf_efm() |
| 2827 | call writefile(["File1-10-Line10"], 'one.txt') |
| 2828 | call writefile(["File2#20#Line20"], 'two.txt') |
| 2829 | set efm=%f#%l#%m |
| 2830 | new | only |
| 2831 | new |
| 2832 | setlocal efm=%f-%l-%m |
| 2833 | cfile one.txt |
| 2834 | wincmd w |
| 2835 | caddfile two.txt |
| 2836 | |
| 2837 | let l = getqflist() |
| 2838 | call assert_equal(10, l[0].lnum) |
| 2839 | call assert_equal('Line20', l[1].text) |
| 2840 | |
| 2841 | set efm& |
| 2842 | new | only |
| 2843 | call delete('one.txt') |
| 2844 | call delete('two.txt') |
Bram Moolenaar | a8788f4 | 2017-07-19 17:06:20 +0200 | [diff] [blame] | 2845 | endfunc |
Bram Moolenaar | d28cc3f | 2017-07-27 22:03:50 +0200 | [diff] [blame] | 2846 | |
| 2847 | " Open multiple help windows using ":lhelpgrep |
| 2848 | " This test used to crash Vim |
| 2849 | func Test_Multi_LL_Help() |
| 2850 | new | only |
| 2851 | lhelpgrep window |
| 2852 | lopen |
| 2853 | e# |
| 2854 | lhelpgrep buffer |
| 2855 | call assert_equal(3, winnr('$')) |
| 2856 | call assert_true(len(getloclist(1)) != 0) |
| 2857 | call assert_true(len(getloclist(2)) != 0) |
| 2858 | new | only |
| 2859 | endfunc |
Bram Moolenaar | 55b6926 | 2017-08-13 13:42:01 +0200 | [diff] [blame] | 2860 | |
| 2861 | " Tests for adding new quickfix lists using setqflist() |
| 2862 | func XaddQf_tests(cchar) |
| 2863 | call s:setup_commands(a:cchar) |
| 2864 | |
| 2865 | " Create a new list using ' ' for action |
| 2866 | call g:Xsetlist([], 'f') |
| 2867 | call g:Xsetlist([], ' ', {'title' : 'Test1'}) |
| 2868 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2869 | call assert_equal(1, l.nr) |
| 2870 | call assert_equal('Test1', l.title) |
| 2871 | |
| 2872 | " Create a new list using ' ' for action and '$' for 'nr' |
| 2873 | call g:Xsetlist([], 'f') |
| 2874 | call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'}) |
| 2875 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2876 | call assert_equal(1, l.nr) |
| 2877 | call assert_equal('Test2', l.title) |
| 2878 | |
| 2879 | " Create a new list using 'a' for action |
| 2880 | call g:Xsetlist([], 'f') |
| 2881 | call g:Xsetlist([], 'a', {'title' : 'Test3'}) |
| 2882 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2883 | call assert_equal(1, l.nr) |
| 2884 | call assert_equal('Test3', l.title) |
| 2885 | |
| 2886 | " Create a new list using 'a' for action and '$' for 'nr' |
| 2887 | call g:Xsetlist([], 'f') |
| 2888 | call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'}) |
| 2889 | call g:Xsetlist([], 'a', {'title' : 'Test4'}) |
| 2890 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2891 | call assert_equal(1, l.nr) |
| 2892 | call assert_equal('Test4', l.title) |
| 2893 | |
| 2894 | " Adding a quickfix list should remove all the lists following the current |
| 2895 | " list. |
| 2896 | Xexpr "" | Xexpr "" | Xexpr "" |
| 2897 | silent! 10Xolder |
| 2898 | call g:Xsetlist([], ' ', {'title' : 'Test5'}) |
| 2899 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2900 | call assert_equal(2, l.nr) |
| 2901 | call assert_equal('Test5', l.title) |
| 2902 | |
| 2903 | " Add a quickfix list using '$' as the list number. |
| 2904 | let lastqf = g:Xgetlist({'nr':'$'}).nr |
| 2905 | silent! 99Xolder |
| 2906 | call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'}) |
| 2907 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2908 | call assert_equal(lastqf + 1, l.nr) |
| 2909 | call assert_equal('Test6', l.title) |
| 2910 | |
| 2911 | " Add a quickfix list using 'nr' set to one more than the quickfix |
| 2912 | " list size. |
| 2913 | let lastqf = g:Xgetlist({'nr':'$'}).nr |
| 2914 | silent! 99Xolder |
| 2915 | call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'}) |
| 2916 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2917 | call assert_equal(lastqf + 1, l.nr) |
| 2918 | call assert_equal('Test7', l.title) |
| 2919 | |
| 2920 | " Add a quickfix list to a stack with 10 lists using 'nr' set to '$' |
| 2921 | exe repeat('Xexpr "" |', 9) . 'Xexpr ""' |
| 2922 | silent! 99Xolder |
| 2923 | call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'}) |
| 2924 | let l = g:Xgetlist({'nr' : '$', 'all' : 1}) |
| 2925 | call assert_equal(10, l.nr) |
| 2926 | call assert_equal('Test8', l.title) |
| 2927 | |
| 2928 | " Add a quickfix list using 'nr' set to a value greater than 10 |
| 2929 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'})) |
| 2930 | |
| 2931 | " Try adding a quickfix list with 'nr' set to a value greater than the |
| 2932 | " quickfix list size but less than 10. |
| 2933 | call g:Xsetlist([], 'f') |
| 2934 | Xexpr "" | Xexpr "" | Xexpr "" |
| 2935 | silent! 99Xolder |
| 2936 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'})) |
| 2937 | |
| 2938 | " Add a quickfix list using 'nr' set to a some string or list |
| 2939 | call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'})) |
| 2940 | endfunc |
| 2941 | |
| 2942 | func Test_add_qf() |
| 2943 | call XaddQf_tests('c') |
| 2944 | call XaddQf_tests('l') |
| 2945 | endfunc |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2946 | |
| 2947 | " Test for getting the quickfix list items from some text without modifying |
| 2948 | " the quickfix stack |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2949 | func XgetListFromLines(cchar) |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2950 | call s:setup_commands(a:cchar) |
| 2951 | call g:Xsetlist([], 'f') |
| 2952 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2953 | let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2954 | call assert_equal(2, len(l)) |
| 2955 | call assert_equal(30, l[1].lnum) |
| 2956 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2957 | call assert_equal({}, g:Xgetlist({'lines' : 10})) |
| 2958 | call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'})) |
| 2959 | call assert_equal([], g:Xgetlist({'lines' : []}).items) |
| 2960 | call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items) |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2961 | |
Bram Moolenaar | 3653822 | 2017-09-02 19:51:44 +0200 | [diff] [blame] | 2962 | " Parse text using a custom efm |
| 2963 | set efm& |
| 2964 | let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items |
| 2965 | call assert_equal('Line30', l[0].text) |
| 2966 | let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items |
| 2967 | call assert_equal('File3:30:Line30', l[0].text) |
| 2968 | let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]}) |
| 2969 | call assert_equal({}, l) |
| 2970 | call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:') |
| 2971 | call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:') |
| 2972 | |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2973 | " Make sure that the quickfix stack is not modified |
| 2974 | call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 2975 | endfunc |
| 2976 | |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 2977 | func Test_get_list_from_lines() |
| 2978 | call XgetListFromLines('c') |
| 2979 | call XgetListFromLines('l') |
Bram Moolenaar | 7adf06f | 2017-08-27 15:23:41 +0200 | [diff] [blame] | 2980 | endfunc |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 2981 | |
| 2982 | " Tests for the quickfix list id |
| 2983 | func Xqfid_tests(cchar) |
| 2984 | call s:setup_commands(a:cchar) |
| 2985 | |
| 2986 | call g:Xsetlist([], 'f') |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 2987 | call assert_equal(0, g:Xgetlist({'id':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 2988 | Xexpr '' |
| 2989 | let start_id = g:Xgetlist({'id' : 0}).id |
| 2990 | Xexpr '' | Xexpr '' |
| 2991 | Xolder |
| 2992 | call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id) |
| 2993 | call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id) |
| 2994 | call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 2995 | call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 2996 | 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] | 2997 | call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id) |
| 2998 | call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 2999 | |
| 3000 | call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]}) |
| 3001 | call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context) |
Bram Moolenaar | 2c809b7 | 2017-09-01 18:34:02 +0200 | [diff] [blame] | 3002 | call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']}) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3003 | call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text) |
| 3004 | call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'})) |
| 3005 | call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'})) |
| 3006 | |
| 3007 | let qfid = g:Xgetlist({'id':0, 'nr':0}) |
| 3008 | call g:Xsetlist([], 'f') |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3009 | call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id) |
Bram Moolenaar | a539f4f | 2017-08-30 20:33:55 +0200 | [diff] [blame] | 3010 | endfunc |
| 3011 | |
| 3012 | func Test_qf_id() |
| 3013 | call Xqfid_tests('c') |
| 3014 | call Xqfid_tests('l') |
| 3015 | endfunc |
Bram Moolenaar | 74240d3 | 2017-12-10 15:26:15 +0100 | [diff] [blame] | 3016 | |
| 3017 | func Xqfjump_tests(cchar) |
| 3018 | call s:setup_commands(a:cchar) |
| 3019 | |
| 3020 | call writefile(["Line1\tFoo", "Line2"], 'F1') |
| 3021 | call writefile(["Line1\tBar", "Line2"], 'F2') |
| 3022 | call writefile(["Line1\tBaz", "Line2"], 'F3') |
| 3023 | |
| 3024 | call g:Xsetlist([], 'f') |
| 3025 | |
| 3026 | " Tests for |
| 3027 | " Jumping to a line using a pattern |
| 3028 | " Jumping to a column greater than the last column in a line |
| 3029 | " Jumping to a line greater than the last line in the file |
| 3030 | let l = [] |
| 3031 | for i in range(1, 7) |
| 3032 | call add(l, {}) |
| 3033 | endfor |
| 3034 | let l[0].filename='F1' |
| 3035 | let l[0].pattern='Line1' |
| 3036 | let l[1].filename='F2' |
| 3037 | let l[1].pattern='Line1' |
| 3038 | let l[2].filename='F3' |
| 3039 | let l[2].pattern='Line1' |
| 3040 | let l[3].filename='F3' |
| 3041 | let l[3].lnum=1 |
| 3042 | let l[3].col=9 |
| 3043 | let l[3].vcol=1 |
| 3044 | let l[4].filename='F3' |
| 3045 | let l[4].lnum=99 |
| 3046 | let l[5].filename='F3' |
| 3047 | let l[5].lnum=1 |
| 3048 | let l[5].col=99 |
| 3049 | let l[5].vcol=1 |
| 3050 | let l[6].filename='F3' |
| 3051 | let l[6].pattern='abcxyz' |
| 3052 | |
| 3053 | call g:Xsetlist([], ' ', {'items' : l}) |
| 3054 | Xopen | only |
| 3055 | 2Xnext |
| 3056 | call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) |
| 3057 | call assert_equal('F3', bufname('%')) |
| 3058 | Xnext |
| 3059 | call assert_equal(7, col('.')) |
| 3060 | Xnext |
| 3061 | call assert_equal(2, line('.')) |
| 3062 | Xnext |
| 3063 | call assert_equal(9, col('.')) |
| 3064 | 2 |
| 3065 | Xnext |
| 3066 | call assert_equal(2, line('.')) |
| 3067 | |
| 3068 | if a:cchar == 'l' |
| 3069 | " When jumping to a location list entry in the location list window and |
| 3070 | " no usable windows are available, then a new window should be opened. |
| 3071 | enew! | new | only |
| 3072 | call g:Xsetlist([], 'f') |
| 3073 | setlocal buftype=nofile |
| 3074 | new |
| 3075 | call g:Xsetlist([], ' ', {'lines' : ['F1:1:1:Line1', 'F1:2:2:Line2', 'F2:1:1:Line1', 'F2:2:2:Line2', 'F3:1:1:Line1', 'F3:2:2:Line2']}) |
| 3076 | Xopen |
| 3077 | let winid = win_getid() |
| 3078 | wincmd p |
| 3079 | close |
| 3080 | call win_gotoid(winid) |
| 3081 | Xnext |
| 3082 | call assert_equal(3, winnr('$')) |
| 3083 | call assert_equal(1, winnr()) |
| 3084 | call assert_equal(2, line('.')) |
| 3085 | |
| 3086 | " When jumping to an entry in the location list window and the window |
| 3087 | " associated with the location list is not present and a window containing |
| 3088 | " the file is already present, then that window should be used. |
| 3089 | close |
| 3090 | belowright new |
| 3091 | call g:Xsetlist([], 'f') |
| 3092 | edit F3 |
| 3093 | call win_gotoid(winid) |
| 3094 | Xlast |
| 3095 | call assert_equal(3, winnr()) |
| 3096 | call assert_equal(6, g:Xgetlist({'size' : 1}).size) |
| 3097 | call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid) |
| 3098 | endif |
| 3099 | |
| 3100 | " Cleanup |
| 3101 | enew! |
| 3102 | new | only |
| 3103 | |
| 3104 | call delete('F1') |
| 3105 | call delete('F2') |
| 3106 | call delete('F3') |
| 3107 | endfunc |
| 3108 | |
| 3109 | func Test_qfjump() |
| 3110 | call Xqfjump_tests('c') |
| 3111 | call Xqfjump_tests('l') |
| 3112 | endfunc |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3113 | |
| 3114 | " Tests for the getqflist() and getloclist() functions when the list is not |
| 3115 | " present or is empty |
| 3116 | func Xgetlist_empty_tests(cchar) |
| 3117 | call s:setup_commands(a:cchar) |
| 3118 | |
| 3119 | " Empty quickfix stack |
| 3120 | call g:Xsetlist([], 'f') |
| 3121 | call assert_equal('', g:Xgetlist({'context' : 0}).context) |
| 3122 | call assert_equal(0, g:Xgetlist({'id' : 0}).id) |
| 3123 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 3124 | call assert_equal([], g:Xgetlist({'items' : 0}).items) |
| 3125 | call assert_equal(0, g:Xgetlist({'nr' : 0}).nr) |
| 3126 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
| 3127 | call assert_equal('', g:Xgetlist({'title' : 0}).title) |
| 3128 | call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3129 | call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3130 | if a:cchar == 'c' |
| 3131 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3132 | \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3133 | \ 'title' : '', 'winid' : 0, 'changedtick': 0}, |
| 3134 | \ g:Xgetlist({'all' : 0})) |
| 3135 | else |
| 3136 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
| 3137 | \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3138 | \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0, |
| 3139 | \ 'qfbufnr' : 0}, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3140 | \ g:Xgetlist({'all' : 0})) |
| 3141 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3142 | |
Bram Moolenaar | 2ec364e | 2018-01-27 11:52:13 +0100 | [diff] [blame] | 3143 | " Quickfix window with empty stack |
| 3144 | silent! Xopen |
| 3145 | let qfwinid = (a:cchar == 'c') ? win_getid() : 0 |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3146 | let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0 |
Bram Moolenaar | 2ec364e | 2018-01-27 11:52:13 +0100 | [diff] [blame] | 3147 | call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid) |
| 3148 | Xclose |
| 3149 | |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3150 | " Empty quickfix list |
| 3151 | Xexpr "" |
| 3152 | call assert_equal('', g:Xgetlist({'context' : 0}).context) |
| 3153 | call assert_notequal(0, g:Xgetlist({'id' : 0}).id) |
| 3154 | call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) |
| 3155 | call assert_equal([], g:Xgetlist({'items' : 0}).items) |
| 3156 | call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr) |
| 3157 | call assert_equal(0, g:Xgetlist({'size' : 0}).size) |
| 3158 | call assert_notequal('', g:Xgetlist({'title' : 0}).title) |
| 3159 | call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3160 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3161 | |
| 3162 | let qfid = g:Xgetlist({'id' : 0}).id |
| 3163 | call g:Xsetlist([], 'f') |
| 3164 | |
| 3165 | " Non-existing quickfix identifier |
| 3166 | call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context) |
| 3167 | call assert_equal(0, g:Xgetlist({'id' : qfid}).id) |
| 3168 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx) |
| 3169 | call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items) |
| 3170 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr) |
| 3171 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size) |
| 3172 | call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title) |
| 3173 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3174 | call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3175 | if a:cchar == 'c' |
| 3176 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 3177 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3178 | \ 'qfbufnr' : qfbufnr, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3179 | \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0})) |
| 3180 | else |
| 3181 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 3182 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3183 | \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0}, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3184 | \ g:Xgetlist({'id' : qfid, 'all' : 0})) |
| 3185 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3186 | |
| 3187 | " Non-existing quickfix list number |
| 3188 | call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context) |
| 3189 | call assert_equal(0, g:Xgetlist({'nr' : 5}).nr) |
| 3190 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx) |
| 3191 | call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items) |
| 3192 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id) |
| 3193 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size) |
| 3194 | call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title) |
| 3195 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid) |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3196 | call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3197 | if a:cchar == 'c' |
| 3198 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 3199 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3200 | \ 'changedtick' : 0, 'qfbufnr' : qfbufnr}, |
| 3201 | \ g:Xgetlist({'nr' : 5, 'all' : 0})) |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3202 | else |
| 3203 | call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
| 3204 | \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3205 | \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0}, |
Bram Moolenaar | c9cc9c7 | 2018-09-02 15:18:42 +0200 | [diff] [blame] | 3206 | \ g:Xgetlist({'nr' : 5, 'all' : 0})) |
| 3207 | endif |
Bram Moolenaar | a6d4849 | 2017-12-12 22:45:31 +0100 | [diff] [blame] | 3208 | endfunc |
| 3209 | |
| 3210 | func Test_getqflist() |
| 3211 | call Xgetlist_empty_tests('c') |
| 3212 | call Xgetlist_empty_tests('l') |
| 3213 | endfunc |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3214 | |
Bram Moolenaar | a0ca7d0 | 2017-12-19 10:22:19 +0100 | [diff] [blame] | 3215 | func Test_getqflist_invalid_nr() |
| 3216 | " The following commands used to crash Vim |
| 3217 | cexpr "" |
| 3218 | call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX}) |
| 3219 | |
| 3220 | " Cleanup |
| 3221 | call setqflist([], 'r') |
| 3222 | endfunc |
| 3223 | |
Bram Moolenaar | b254af3 | 2017-12-18 19:48:58 +0100 | [diff] [blame] | 3224 | " Tests for the quickfix/location list changedtick |
| 3225 | func Xqftick_tests(cchar) |
| 3226 | call s:setup_commands(a:cchar) |
| 3227 | |
| 3228 | call g:Xsetlist([], 'f') |
| 3229 | |
| 3230 | Xexpr "F1:10:Line10" |
| 3231 | let qfid = g:Xgetlist({'id' : 0}).id |
| 3232 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3233 | Xaddexpr "F2:20:Line20\nF2:21:Line21" |
| 3234 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3235 | call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]}) |
| 3236 | call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3237 | call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]}) |
| 3238 | call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3239 | call g:Xsetlist([], 'a', {'title' : 'New Title'}) |
| 3240 | call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3241 | |
| 3242 | enew! |
| 3243 | call append(0, ["F5:50:L50", "F6:60:L60"]) |
| 3244 | Xaddbuffer |
| 3245 | call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3246 | enew! |
| 3247 | |
| 3248 | call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}}) |
| 3249 | call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3250 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 3251 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a') |
| 3252 | call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3253 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 3254 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ') |
| 3255 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3256 | call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, |
| 3257 | \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r') |
| 3258 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3259 | |
| 3260 | call writefile(["F8:80:L80", "F8:81:L81"], "Xone") |
| 3261 | Xfile Xone |
| 3262 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3263 | Xaddfile Xone |
| 3264 | call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3265 | |
| 3266 | " Test case for updating a non-current quickfix list |
| 3267 | call g:Xsetlist([], 'f') |
| 3268 | Xexpr "F1:1:L1" |
| 3269 | Xexpr "F2:2:L2" |
| 3270 | call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]}) |
| 3271 | call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) |
| 3272 | call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick) |
| 3273 | |
| 3274 | call delete("Xone") |
| 3275 | endfunc |
| 3276 | |
| 3277 | func Test_qf_tick() |
| 3278 | call Xqftick_tests('c') |
| 3279 | call Xqftick_tests('l') |
| 3280 | endfunc |
Bram Moolenaar | 1223744 | 2017-12-19 12:38:52 +0100 | [diff] [blame] | 3281 | |
Bram Moolenaar | c631f2d | 2018-08-21 21:58:13 +0200 | [diff] [blame] | 3282 | " Test helpgrep with lang specifier |
| 3283 | func Xtest_helpgrep_with_lang_specifier(cchar) |
| 3284 | call s:setup_commands(a:cchar) |
| 3285 | Xhelpgrep Vim@en |
| 3286 | call assert_equal('help', &filetype) |
| 3287 | call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr) |
| 3288 | new | only |
| 3289 | endfunc |
| 3290 | |
| 3291 | func Test_helpgrep_with_lang_specifier() |
| 3292 | call Xtest_helpgrep_with_lang_specifier('c') |
| 3293 | call Xtest_helpgrep_with_lang_specifier('l') |
| 3294 | endfunc |
| 3295 | |
Bram Moolenaar | 1223744 | 2017-12-19 12:38:52 +0100 | [diff] [blame] | 3296 | " The following test used to crash Vim. |
| 3297 | " Open the location list window and close the regular window associated with |
| 3298 | " the location list. When the garbage collection runs now, it incorrectly |
| 3299 | " marks the location list context as not in use and frees the context. |
| 3300 | func Test_ll_window_ctx() |
| 3301 | call setloclist(0, [], 'f') |
| 3302 | call setloclist(0, [], 'a', {'context' : []}) |
| 3303 | lopen | only |
| 3304 | call test_garbagecollect_now() |
| 3305 | echo getloclist(0, {'context' : 1}).context |
| 3306 | enew | only |
| 3307 | endfunc |
| 3308 | |
Bram Moolenaar | 14a4deb | 2017-12-19 16:48:55 +0100 | [diff] [blame] | 3309 | " The following test used to crash vim |
| 3310 | func Test_lfile_crash() |
| 3311 | sp Xtest |
| 3312 | au QuickFixCmdPre * bw |
| 3313 | call assert_fails('lfile', 'E40') |
| 3314 | au! QuickFixCmdPre |
| 3315 | endfunc |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 3316 | |
| 3317 | " The following test used to crash vim |
| 3318 | func Test_lbuffer_crash() |
| 3319 | sv Xtest |
| 3320 | augroup QF_Test |
| 3321 | au! |
| 3322 | au * * bw |
| 3323 | augroup END |
| 3324 | lbuffer |
| 3325 | augroup QF_Test |
| 3326 | au! |
| 3327 | augroup END |
| 3328 | endfunc |
| 3329 | |
| 3330 | " The following test used to crash vim |
| 3331 | func Test_lexpr_crash() |
| 3332 | augroup QF_Test |
| 3333 | au! |
| 3334 | au * * call setloclist(0, [], 'f') |
| 3335 | augroup END |
| 3336 | lexpr "" |
| 3337 | augroup QF_Test |
| 3338 | au! |
| 3339 | augroup END |
Bram Moolenaar | 9f84ded | 2018-10-20 20:54:02 +0200 | [diff] [blame] | 3340 | |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 3341 | enew | only |
Bram Moolenaar | 9f84ded | 2018-10-20 20:54:02 +0200 | [diff] [blame] | 3342 | augroup QF_Test |
| 3343 | au! |
| 3344 | au BufNew * call setloclist(0, [], 'f') |
| 3345 | augroup END |
| 3346 | lexpr 'x:1:x' |
| 3347 | augroup QF_Test |
| 3348 | au! |
| 3349 | augroup END |
| 3350 | |
| 3351 | enew | only |
| 3352 | lexpr '' |
| 3353 | lopen |
| 3354 | augroup QF_Test |
| 3355 | au! |
| 3356 | au FileType * call setloclist(0, [], 'f') |
| 3357 | augroup END |
| 3358 | lexpr '' |
| 3359 | augroup QF_Test |
| 3360 | au! |
| 3361 | augroup END |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 3362 | endfunc |
| 3363 | |
| 3364 | " The following test used to crash Vim |
| 3365 | func Test_lvimgrep_crash() |
| 3366 | sv Xtest |
| 3367 | augroup QF_Test |
| 3368 | au! |
| 3369 | au * * call setloclist(0, [], 'f') |
| 3370 | augroup END |
| 3371 | lvimgrep quickfix test_quickfix.vim |
| 3372 | augroup QF_Test |
| 3373 | au! |
| 3374 | augroup END |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 3375 | |
| 3376 | new | only |
| 3377 | augroup QF_Test |
| 3378 | au! |
| 3379 | au BufEnter * call setloclist(0, [], 'r') |
| 3380 | augroup END |
| 3381 | call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:') |
| 3382 | augroup QF_Test |
| 3383 | au! |
| 3384 | augroup END |
| 3385 | |
Bram Moolenaar | 3c09722 | 2017-12-21 20:54:49 +0100 | [diff] [blame] | 3386 | enew | only |
| 3387 | endfunc |
Bram Moolenaar | de04654 | 2017-12-26 13:53:11 +0100 | [diff] [blame] | 3388 | |
| 3389 | " Test for the position of the quickfix and location list window |
| 3390 | func Test_qfwin_pos() |
| 3391 | " Open two windows |
| 3392 | new | only |
| 3393 | new |
| 3394 | cexpr ['F1:10:L10'] |
| 3395 | copen |
| 3396 | " Quickfix window should be the bottom most window |
| 3397 | call assert_equal(3, winnr()) |
| 3398 | close |
| 3399 | " Open at the very top |
| 3400 | wincmd t |
| 3401 | topleft copen |
| 3402 | call assert_equal(1, winnr()) |
| 3403 | close |
| 3404 | " open left of the current window |
| 3405 | wincmd t |
| 3406 | below new |
| 3407 | leftabove copen |
| 3408 | call assert_equal(2, winnr()) |
| 3409 | close |
| 3410 | " open right of the current window |
| 3411 | rightbelow copen |
| 3412 | call assert_equal(3, winnr()) |
| 3413 | close |
| 3414 | endfunc |
Bram Moolenaar | e1bb879 | 2018-04-06 22:58:23 +0200 | [diff] [blame] | 3415 | |
| 3416 | " Tests for quickfix/location lists changed by autocommands when |
| 3417 | " :vimgrep/:lvimgrep commands are running. |
| 3418 | func Test_vimgrep_autocmd() |
| 3419 | call setqflist([], 'f') |
| 3420 | call writefile(['stars'], 'Xtest1.txt') |
| 3421 | call writefile(['stars'], 'Xtest2.txt') |
| 3422 | |
| 3423 | " Test 1: |
| 3424 | " When searching for a pattern using :vimgrep, if the quickfix list is |
| 3425 | " changed by an autocmd, the results should be added to the correct quickfix |
| 3426 | " list. |
| 3427 | autocmd BufRead Xtest2.txt cexpr '' | cexpr '' |
| 3428 | silent vimgrep stars Xtest*.txt |
| 3429 | call assert_equal(1, getqflist({'nr' : 0}).nr) |
| 3430 | call assert_equal(3, getqflist({'nr' : '$'}).nr) |
| 3431 | call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr)) |
| 3432 | au! BufRead Xtest2.txt |
| 3433 | |
| 3434 | " Test 2: |
| 3435 | " When searching for a pattern using :vimgrep, if the quickfix list is |
| 3436 | " freed, then a error should be given. |
| 3437 | silent! %bwipe! |
| 3438 | call setqflist([], 'f') |
| 3439 | autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor |
| 3440 | call assert_fails('vimgrep stars Xtest*.txt', 'E925:') |
| 3441 | au! BufRead Xtest2.txt |
| 3442 | |
| 3443 | " Test 3: |
| 3444 | " When searching for a pattern using :lvimgrep, if the location list is |
| 3445 | " freed, then the command should error out. |
| 3446 | silent! %bwipe! |
| 3447 | let g:save_winid = win_getid() |
| 3448 | autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f') |
| 3449 | call assert_fails('lvimgrep stars Xtest*.txt', 'E926:') |
| 3450 | au! BufRead Xtest2.txt |
| 3451 | |
| 3452 | call delete('Xtest1.txt') |
| 3453 | call delete('Xtest2.txt') |
| 3454 | call setqflist([], 'f') |
| 3455 | endfunc |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 3456 | |
| 3457 | " The following test used to crash Vim |
| 3458 | func Test_lhelpgrep_autocmd() |
| 3459 | lhelpgrep quickfix |
| 3460 | autocmd QuickFixCmdPost * call setloclist(0, [], 'f') |
| 3461 | lhelpgrep buffer |
| 3462 | call assert_equal('help', &filetype) |
| 3463 | call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) |
| 3464 | lhelpgrep tabpage |
| 3465 | call assert_equal('help', &filetype) |
| 3466 | call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) |
| 3467 | au! QuickFixCmdPost |
Bram Moolenaar | b6f1480 | 2018-10-21 18:47:43 +0200 | [diff] [blame] | 3468 | |
| 3469 | new | only |
| 3470 | augroup QF_Test |
| 3471 | au! |
| 3472 | au BufEnter * call setqflist([], 'f') |
| 3473 | augroup END |
| 3474 | call assert_fails('helpgrep quickfix', 'E925:') |
| 3475 | augroup QF_Test |
| 3476 | au! BufEnter |
| 3477 | augroup END |
| 3478 | |
| 3479 | new | only |
| 3480 | augroup QF_Test |
| 3481 | au! |
| 3482 | au BufEnter * call setqflist([], 'r') |
| 3483 | augroup END |
| 3484 | call assert_fails('helpgrep quickfix', 'E925:') |
| 3485 | augroup QF_Test |
| 3486 | au! BufEnter |
| 3487 | augroup END |
| 3488 | |
| 3489 | new | only |
| 3490 | augroup QF_Test |
| 3491 | au! |
| 3492 | au BufEnter * call setloclist(0, [], 'r') |
| 3493 | augroup END |
| 3494 | call assert_fails('lhelpgrep quickfix', 'E926:') |
| 3495 | augroup QF_Test |
| 3496 | au! BufEnter |
| 3497 | augroup END |
| 3498 | |
Bram Moolenaar | 3b9474b | 2018-04-23 21:29:48 +0200 | [diff] [blame] | 3499 | new | only |
| 3500 | endfunc |
Bram Moolenaar | a796d46 | 2018-05-01 14:30:36 +0200 | [diff] [blame] | 3501 | |
| 3502 | " Test for shortening/simplifying the file name when opening the |
| 3503 | " quickfix window or when displaying the quickfix list |
| 3504 | func Test_shorten_fname() |
| 3505 | if !has('unix') |
| 3506 | return |
| 3507 | endif |
| 3508 | %bwipe |
| 3509 | " Create a quickfix list with a absolute path filename |
| 3510 | let fname = getcwd() . '/test_quickfix.vim' |
| 3511 | call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) |
| 3512 | call assert_equal(fname, bufname('test_quickfix.vim')) |
| 3513 | " Opening the quickfix window should simplify the file path |
| 3514 | cwindow |
| 3515 | call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) |
| 3516 | cclose |
| 3517 | %bwipe |
| 3518 | " Create a quickfix list with a absolute path filename |
| 3519 | call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) |
| 3520 | call assert_equal(fname, bufname('test_quickfix.vim')) |
| 3521 | " Displaying the quickfix list should simplify the file path |
| 3522 | silent! clist |
| 3523 | call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) |
| 3524 | endfunc |
Bram Moolenaar | 8b62e31 | 2018-05-13 15:29:04 +0200 | [diff] [blame] | 3525 | |
| 3526 | " Quickfix title tests |
| 3527 | " In the below tests, 'exe "cmd"' is used to invoke the quickfix commands. |
| 3528 | " Otherwise due to indentation, the title is set with spaces at the beginning |
| 3529 | " of the command. |
| 3530 | func Test_qftitle() |
| 3531 | call writefile(["F1:1:Line1"], 'Xerr') |
| 3532 | |
| 3533 | " :cexpr |
| 3534 | exe "cexpr readfile('Xerr')" |
| 3535 | call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title) |
| 3536 | |
| 3537 | " :cgetexpr |
| 3538 | exe "cgetexpr readfile('Xerr')" |
| 3539 | call assert_equal(":cgetexpr readfile('Xerr')", |
| 3540 | \ getqflist({'title' : 1}).title) |
| 3541 | |
| 3542 | " :caddexpr |
| 3543 | call setqflist([], 'f') |
| 3544 | exe "caddexpr readfile('Xerr')" |
| 3545 | call assert_equal(":caddexpr readfile('Xerr')", |
| 3546 | \ getqflist({'title' : 1}).title) |
| 3547 | |
| 3548 | " :cbuffer |
| 3549 | new Xerr |
| 3550 | exe "cbuffer" |
| 3551 | call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 3552 | |
| 3553 | " :cgetbuffer |
| 3554 | edit Xerr |
| 3555 | exe "cgetbuffer" |
| 3556 | call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 3557 | |
| 3558 | " :caddbuffer |
| 3559 | call setqflist([], 'f') |
| 3560 | edit Xerr |
| 3561 | exe "caddbuffer" |
| 3562 | call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title) |
| 3563 | |
| 3564 | " :cfile |
| 3565 | exe "cfile Xerr" |
| 3566 | call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title) |
| 3567 | |
| 3568 | " :cgetfile |
| 3569 | exe "cgetfile Xerr" |
| 3570 | call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title) |
| 3571 | |
| 3572 | " :caddfile |
| 3573 | call setqflist([], 'f') |
| 3574 | exe "caddfile Xerr" |
| 3575 | call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title) |
| 3576 | |
| 3577 | " :grep |
| 3578 | set grepprg=internal |
| 3579 | exe "grep F1 Xerr" |
| 3580 | call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title) |
| 3581 | |
| 3582 | " :grepadd |
| 3583 | call setqflist([], 'f') |
| 3584 | exe "grepadd F1 Xerr" |
| 3585 | call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title) |
| 3586 | set grepprg&vim |
| 3587 | |
| 3588 | " :vimgrep |
| 3589 | exe "vimgrep F1 Xerr" |
| 3590 | call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title) |
| 3591 | |
| 3592 | " :vimgrepadd |
| 3593 | call setqflist([], 'f') |
| 3594 | exe "vimgrepadd F1 Xerr" |
| 3595 | call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title) |
| 3596 | |
| 3597 | call setqflist(['F1:10:L10'], ' ') |
| 3598 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 3599 | |
| 3600 | call setqflist([], 'f') |
| 3601 | call setqflist(['F1:10:L10'], 'a') |
| 3602 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 3603 | |
| 3604 | call setqflist([], 'f') |
| 3605 | call setqflist(['F1:10:L10'], 'r') |
| 3606 | call assert_equal(':setqflist()', getqflist({'title' : 1}).title) |
| 3607 | |
| 3608 | close |
| 3609 | call delete('Xerr') |
| 3610 | |
| 3611 | call setqflist([], ' ', {'title' : 'Errors'}) |
| 3612 | copen |
| 3613 | call assert_equal('Errors', w:quickfix_title) |
| 3614 | call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]}) |
| 3615 | call assert_equal('Errors', w:quickfix_title) |
| 3616 | cclose |
| 3617 | endfunc |
Bram Moolenaar | 600323b | 2018-06-16 22:16:47 +0200 | [diff] [blame] | 3618 | |
| 3619 | func Test_lbuffer_with_bwipe() |
| 3620 | new |
| 3621 | new |
| 3622 | augroup nasty |
| 3623 | au * * bwipe |
| 3624 | augroup END |
| 3625 | lbuffer |
| 3626 | augroup nasty |
| 3627 | au! |
| 3628 | augroup END |
| 3629 | endfunc |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 3630 | |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3631 | " Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is |
| 3632 | " running |
| 3633 | func Xexpr_acmd_freelist(cchar) |
| 3634 | call s:setup_commands(a:cchar) |
| 3635 | |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 3636 | " This was using freed memory. |
| 3637 | augroup nasty |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3638 | au * * call g:Xsetlist([], 'f') |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 3639 | augroup END |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3640 | Xexpr "x" |
Bram Moolenaar | 0366c01 | 2018-06-18 20:52:13 +0200 | [diff] [blame] | 3641 | augroup nasty |
| 3642 | au! |
| 3643 | augroup END |
| 3644 | endfunc |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3645 | |
| 3646 | func Test_cexpr_acmd_freelist() |
| 3647 | call Xexpr_acmd_freelist('c') |
| 3648 | call Xexpr_acmd_freelist('l') |
| 3649 | endfunc |
| 3650 | |
| 3651 | " Test for commands that create a new quickfix/location list and jump to the |
| 3652 | " first error automatically. |
| 3653 | func Xjumpto_first_error_test(cchar) |
| 3654 | call s:setup_commands(a:cchar) |
| 3655 | |
| 3656 | call s:create_test_file('Xtestfile1') |
| 3657 | call s:create_test_file('Xtestfile2') |
| 3658 | let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] |
| 3659 | |
| 3660 | " Test for cexpr/lexpr |
| 3661 | enew |
| 3662 | Xexpr l |
| 3663 | call assert_equal('Xtestfile1', bufname('')) |
| 3664 | call assert_equal(2, line('.')) |
| 3665 | |
| 3666 | " Test for cfile/lfile |
| 3667 | enew |
| 3668 | call writefile(l, 'Xerr') |
| 3669 | Xfile Xerr |
| 3670 | call assert_equal('Xtestfile1', bufname('')) |
| 3671 | call assert_equal(2, line('.')) |
| 3672 | |
| 3673 | " Test for cbuffer/lbuffer |
| 3674 | edit Xerr |
| 3675 | Xbuffer |
| 3676 | call assert_equal('Xtestfile1', bufname('')) |
| 3677 | call assert_equal(2, line('.')) |
| 3678 | |
| 3679 | call delete('Xerr') |
| 3680 | call delete('Xtestfile1') |
| 3681 | call delete('Xtestfile2') |
| 3682 | endfunc |
| 3683 | |
| 3684 | func Test_jumpto_first_error() |
| 3685 | call Xjumpto_first_error_test('c') |
| 3686 | call Xjumpto_first_error_test('l') |
| 3687 | endfunc |
| 3688 | |
| 3689 | " Test for a quickfix autocmd changing the quickfix/location list before |
| 3690 | " jumping to the first error in the new list. |
| 3691 | func Xautocmd_changelist(cchar) |
| 3692 | call s:setup_commands(a:cchar) |
| 3693 | |
| 3694 | " Test for cfile/lfile |
| 3695 | call s:create_test_file('Xtestfile1') |
| 3696 | call s:create_test_file('Xtestfile2') |
| 3697 | Xexpr 'Xtestfile1:2:Line2' |
| 3698 | autocmd QuickFixCmdPost * Xolder |
| 3699 | call writefile(['Xtestfile2:4:Line4'], 'Xerr') |
| 3700 | Xfile Xerr |
| 3701 | call assert_equal('Xtestfile2', bufname('')) |
| 3702 | call assert_equal(4, line('.')) |
| 3703 | autocmd! QuickFixCmdPost |
| 3704 | |
| 3705 | " Test for cbuffer/lbuffer |
| 3706 | call g:Xsetlist([], 'f') |
| 3707 | Xexpr 'Xtestfile1:2:Line2' |
| 3708 | autocmd QuickFixCmdPost * Xolder |
| 3709 | call writefile(['Xtestfile2:4:Line4'], 'Xerr') |
| 3710 | edit Xerr |
| 3711 | Xbuffer |
| 3712 | call assert_equal('Xtestfile2', bufname('')) |
| 3713 | call assert_equal(4, line('.')) |
| 3714 | autocmd! QuickFixCmdPost |
| 3715 | |
| 3716 | " Test for cexpr/lexpr |
| 3717 | call g:Xsetlist([], 'f') |
| 3718 | Xexpr 'Xtestfile1:2:Line2' |
| 3719 | autocmd QuickFixCmdPost * Xolder |
| 3720 | Xexpr 'Xtestfile2:4:Line4' |
| 3721 | call assert_equal('Xtestfile2', bufname('')) |
| 3722 | call assert_equal(4, line('.')) |
| 3723 | autocmd! QuickFixCmdPost |
| 3724 | |
Bram Moolenaar | 851332e | 2018-07-03 19:16:00 +0200 | [diff] [blame] | 3725 | " The grepprg may not be set on non-Unix systems |
| 3726 | if has('unix') |
| 3727 | " Test for grep/lgrep |
| 3728 | call g:Xsetlist([], 'f') |
| 3729 | Xexpr 'Xtestfile1:2:Line2' |
| 3730 | autocmd QuickFixCmdPost * Xolder |
| 3731 | silent Xgrep Line5 Xtestfile2 |
| 3732 | call assert_equal('Xtestfile2', bufname('')) |
| 3733 | call assert_equal(5, line('.')) |
| 3734 | autocmd! QuickFixCmdPost |
| 3735 | endif |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3736 | |
| 3737 | " Test for vimgrep/lvimgrep |
| 3738 | call g:Xsetlist([], 'f') |
| 3739 | Xexpr 'Xtestfile1:2:Line2' |
| 3740 | autocmd QuickFixCmdPost * Xolder |
| 3741 | silent Xvimgrep Line5 Xtestfile2 |
| 3742 | call assert_equal('Xtestfile2', bufname('')) |
| 3743 | call assert_equal(5, line('.')) |
| 3744 | autocmd! QuickFixCmdPost |
| 3745 | |
Bram Moolenaar | 3f347e4 | 2018-08-09 21:19:20 +0200 | [diff] [blame] | 3746 | " Test for autocommands clearing the quickfix list before jumping to the |
| 3747 | " first error. This should not result in an error |
| 3748 | autocmd QuickFixCmdPost * call g:Xsetlist([], 'r') |
| 3749 | let v:errmsg = '' |
| 3750 | " Test for cfile/lfile |
| 3751 | Xfile Xerr |
| 3752 | call assert_true(v:errmsg !~# 'E42:') |
| 3753 | " Test for cbuffer/lbuffer |
| 3754 | edit Xerr |
| 3755 | Xbuffer |
| 3756 | call assert_true(v:errmsg !~# 'E42:') |
| 3757 | " Test for cexpr/lexpr |
| 3758 | Xexpr 'Xtestfile2:4:Line4' |
| 3759 | call assert_true(v:errmsg !~# 'E42:') |
| 3760 | " Test for grep/lgrep |
| 3761 | " The grepprg may not be set on non-Unix systems |
| 3762 | if has('unix') |
| 3763 | silent Xgrep Line5 Xtestfile2 |
| 3764 | call assert_true(v:errmsg !~# 'E42:') |
| 3765 | endif |
| 3766 | " Test for vimgrep/lvimgrep |
| 3767 | call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:') |
| 3768 | autocmd! QuickFixCmdPost |
| 3769 | |
Bram Moolenaar | 531b9a3 | 2018-07-03 16:54:23 +0200 | [diff] [blame] | 3770 | call delete('Xerr') |
| 3771 | call delete('Xtestfile1') |
| 3772 | call delete('Xtestfile2') |
| 3773 | endfunc |
| 3774 | |
| 3775 | func Test_autocmd_changelist() |
| 3776 | call Xautocmd_changelist('c') |
| 3777 | call Xautocmd_changelist('l') |
| 3778 | endfunc |
Bram Moolenaar | 4cde86c | 2018-07-08 16:01:08 +0200 | [diff] [blame] | 3779 | |
| 3780 | " Tests for the ':filter /pat/ clist' command |
| 3781 | func Test_filter_clist() |
| 3782 | cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15'] |
| 3783 | call assert_equal([' 2 Xfile2:15 col 15: Line 15'], |
| 3784 | \ split(execute('filter /Line 15/ clist'), "\n")) |
| 3785 | call assert_equal([' 1 Xfile1:10 col 10: Line 10'], |
| 3786 | \ split(execute('filter /Xfile1/ clist'), "\n")) |
| 3787 | call assert_equal([], split(execute('filter /abc/ clist'), "\n")) |
| 3788 | |
| 3789 | call setqflist([{'module' : 'abc', 'pattern' : 'pat1'}, |
| 3790 | \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ') |
| 3791 | call assert_equal([' 2 pqr:pat2: '], |
| 3792 | \ split(execute('filter /pqr/ clist'), "\n")) |
| 3793 | call assert_equal([' 1 abc:pat1: '], |
| 3794 | \ split(execute('filter /pat1/ clist'), "\n")) |
| 3795 | endfunc |
Bram Moolenaar | 0a08c63 | 2018-07-25 22:36:52 +0200 | [diff] [blame] | 3796 | |
| 3797 | " Tests for the "CTRL-W <CR>" command. |
| 3798 | func Xview_result_split_tests(cchar) |
| 3799 | call s:setup_commands(a:cchar) |
| 3800 | |
| 3801 | " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list. |
| 3802 | call g:Xsetlist([]) |
| 3803 | Xopen |
| 3804 | let l:win_count = winnr('$') |
| 3805 | call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42') |
| 3806 | call assert_equal(l:win_count, winnr('$')) |
| 3807 | Xclose |
| 3808 | endfunc |
| 3809 | |
| 3810 | func Test_view_result_split() |
| 3811 | call Xview_result_split_tests('c') |
| 3812 | call Xview_result_split_tests('l') |
| 3813 | endfunc |
Bram Moolenaar | 2dfcef4 | 2018-08-15 22:29:51 +0200 | [diff] [blame] | 3814 | |
| 3815 | " Test that :cc sets curswant |
| 3816 | func Test_curswant() |
| 3817 | helpgrep quickfix |
| 3818 | normal! llll |
| 3819 | 1cc |
| 3820 | call assert_equal(getcurpos()[4], virtcol('.')) |
| 3821 | cclose | helpclose |
| 3822 | endfunc |
Bram Moolenaar | b244373 | 2018-11-11 22:50:27 +0100 | [diff] [blame] | 3823 | |
| 3824 | " Test for opening a file from the quickfix window using CTRL-W <Enter> |
| 3825 | " doesn't leave an empty buffer around. |
| 3826 | func Test_splitview() |
| 3827 | call s:create_test_file('Xtestfile1') |
| 3828 | call s:create_test_file('Xtestfile2') |
| 3829 | new | only |
| 3830 | let last_bufnr = bufnr('Test_sv_1', 1) |
| 3831 | let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] |
| 3832 | cgetexpr l |
| 3833 | copen |
| 3834 | let numbufs = len(getbufinfo()) |
| 3835 | exe "normal \<C-W>\<CR>" |
| 3836 | copen |
| 3837 | exe "normal j\<C-W>\<CR>" |
| 3838 | " Make sure new empty buffers are not created |
| 3839 | call assert_equal(numbufs, len(getbufinfo())) |
| 3840 | " Creating a new buffer should use the next available buffer number |
| 3841 | call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1)) |
| 3842 | bwipe Test_sv_1 |
| 3843 | bwipe Test_sv_2 |
| 3844 | new | only |
| 3845 | |
| 3846 | " When split opening files from location list window, make sure that two |
| 3847 | " windows doesn't refer to the same location list |
| 3848 | lgetexpr l |
| 3849 | let locid = getloclist(0, {'id' : 0}).id |
| 3850 | lopen |
| 3851 | exe "normal \<C-W>\<CR>" |
| 3852 | call assert_notequal(locid, getloclist(0, {'id' : 0}).id) |
| 3853 | call assert_equal(0, getloclist(0, {'winid' : 0}).winid) |
| 3854 | new | only |
| 3855 | |
| 3856 | " 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] | 3857 | " window should be opened with a copy of the location list. |
Bram Moolenaar | b244373 | 2018-11-11 22:50:27 +0100 | [diff] [blame] | 3858 | lhelpgrep window |
| 3859 | let locid = getloclist(0, {'id' : 0}).id |
| 3860 | lwindow |
| 3861 | exe "normal j\<C-W>\<CR>" |
| 3862 | call assert_notequal(locid, getloclist(0, {'id' : 0}).id) |
| 3863 | call assert_equal(0, getloclist(0, {'winid' : 0}).winid) |
| 3864 | new | only |
| 3865 | |
| 3866 | call delete('Xtestfile1') |
| 3867 | call delete('Xtestfile2') |
| 3868 | endfunc |
Bram Moolenaar | c45eb77 | 2019-01-31 14:27:04 +0100 | [diff] [blame] | 3869 | |
| 3870 | " Test for parsing entries using visual screen column |
| 3871 | func Test_viscol() |
| 3872 | enew |
| 3873 | call writefile(["Col1\tCol2\tCol3"], 'Xfile1') |
| 3874 | edit Xfile1 |
| 3875 | |
| 3876 | " Use byte offset for column number |
| 3877 | set efm& |
| 3878 | cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ" |
| 3879 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 3880 | cnext |
| 3881 | call assert_equal([9, 12], [col('.'), virtcol('.')]) |
| 3882 | cnext |
| 3883 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 3884 | |
| 3885 | " Use screen column offset for column number |
| 3886 | set efm=%f:%l:%v:%m |
| 3887 | cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ" |
| 3888 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 3889 | cnext |
| 3890 | call assert_equal([9, 12], [col('.'), virtcol('.')]) |
| 3891 | cnext |
| 3892 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 3893 | cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ" |
| 3894 | call assert_equal([5, 8], [col('.'), virtcol('.')]) |
| 3895 | cnext |
| 3896 | call assert_equal([10, 16], [col('.'), virtcol('.')]) |
| 3897 | cnext |
| 3898 | call assert_equal([14, 20], [col('.'), virtcol('.')]) |
| 3899 | |
| 3900 | enew |
| 3901 | call writefile(["Col1\täü\töß\tCol4"], 'Xfile1') |
| 3902 | |
| 3903 | " Use byte offset for column number |
| 3904 | set efm& |
| 3905 | cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ" |
| 3906 | call assert_equal([8, 10], [col('.'), virtcol('.')]) |
| 3907 | cnext |
| 3908 | call assert_equal([11, 17], [col('.'), virtcol('.')]) |
| 3909 | cnext |
| 3910 | call assert_equal([16, 25], [col('.'), virtcol('.')]) |
| 3911 | |
| 3912 | " Use screen column offset for column number |
| 3913 | set efm=%f:%l:%v:%m |
| 3914 | cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ" |
| 3915 | call assert_equal([8, 10], [col('.'), virtcol('.')]) |
| 3916 | cnext |
| 3917 | call assert_equal([11, 17], [col('.'), virtcol('.')]) |
| 3918 | cnext |
| 3919 | call assert_equal([16, 25], [col('.'), virtcol('.')]) |
| 3920 | |
| 3921 | enew | only |
| 3922 | set efm& |
| 3923 | call delete('Xfile1') |
| 3924 | endfunc |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 3925 | |
| 3926 | " Test for the quickfix window buffer |
| 3927 | func Xqfbuf_test(cchar) |
| 3928 | call s:setup_commands(a:cchar) |
| 3929 | |
| 3930 | " Quickfix buffer should be reused across closing and opening a quickfix |
| 3931 | " window |
| 3932 | Xexpr "F1:10:Line10" |
| 3933 | Xopen |
| 3934 | let qfbnum = bufnr('') |
| 3935 | Xclose |
| 3936 | " Even after the quickfix window is closed, the buffer should be loaded |
| 3937 | call assert_true(bufloaded(qfbnum)) |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3938 | call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 3939 | Xopen |
| 3940 | " Buffer should be reused when opening the window again |
| 3941 | call assert_equal(qfbnum, bufnr('')) |
| 3942 | Xclose |
| 3943 | |
| 3944 | if a:cchar == 'l' |
| 3945 | %bwipe |
| 3946 | " For a location list, when both the file window and the location list |
| 3947 | " window for the list are closed, then the buffer should be freed. |
| 3948 | new | only |
| 3949 | lexpr "F1:10:Line10" |
| 3950 | let wid = win_getid() |
| 3951 | lopen |
| 3952 | let qfbnum = bufnr('') |
| 3953 | call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls')) |
| 3954 | close |
| 3955 | " When the location list window is closed, the buffer name should not |
| 3956 | " change to 'Quickfix List' |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3957 | call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!')) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 3958 | call assert_true(bufloaded(qfbnum)) |
| 3959 | |
Bram Moolenaar | d82a81c | 2019-03-02 07:57:18 +0100 | [diff] [blame] | 3960 | " After deleting a location list buffer using ":bdelete", opening the |
| 3961 | " location list window should mark the buffer as a location list buffer. |
| 3962 | exe "bdelete " . qfbnum |
| 3963 | lopen |
| 3964 | call assert_equal("quickfix", &buftype) |
| 3965 | call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist) |
| 3966 | call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid) |
| 3967 | call assert_false(&swapfile) |
| 3968 | lclose |
| 3969 | |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 3970 | " When the location list is cleared for the window, the buffer should be |
| 3971 | " removed |
| 3972 | call setloclist(0, [], 'f') |
| 3973 | call assert_false(bufexists(qfbnum)) |
Bram Moolenaar | 647e24b | 2019-03-17 16:39:46 +0100 | [diff] [blame] | 3974 | call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr) |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 3975 | |
| 3976 | " When the location list is freed with the location list window open, the |
| 3977 | " location list buffer should not be lost. It should be reused when the |
| 3978 | " location list is again populated. |
| 3979 | lexpr "F1:10:Line10" |
| 3980 | lopen |
| 3981 | let wid = win_getid() |
| 3982 | let qfbnum = bufnr('') |
| 3983 | wincmd p |
| 3984 | call setloclist(0, [], 'f') |
| 3985 | lexpr "F1:10:Line10" |
| 3986 | lopen |
| 3987 | call assert_equal(wid, win_getid()) |
| 3988 | call assert_equal(qfbnum, bufnr('')) |
| 3989 | lclose |
| 3990 | |
| 3991 | " When the window with the location list is closed, the buffer should be |
| 3992 | " removed |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 3993 | new | only |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 3994 | call assert_false(bufexists(qfbnum)) |
Bram Moolenaar | ee8188f | 2019-02-05 21:23:04 +0100 | [diff] [blame] | 3995 | endif |
| 3996 | endfunc |
| 3997 | |
| 3998 | func Test_qfbuf() |
| 3999 | call Xqfbuf_test('c') |
| 4000 | call Xqfbuf_test('l') |
| 4001 | endfunc |
Bram Moolenaar | eeb1b9c | 2019-02-10 22:59:04 +0100 | [diff] [blame] | 4002 | |
| 4003 | " If there is an autocmd to use only one window, then opening the location |
| 4004 | " list window used to crash Vim. |
| 4005 | func Test_winonly_autocmd() |
| 4006 | call s:create_test_file('Xtest1') |
| 4007 | " Autocmd to show only one Vim window at a time |
| 4008 | autocmd WinEnter * only |
| 4009 | new |
| 4010 | " Load the location list |
| 4011 | lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15" |
| 4012 | let loclistid = getloclist(0, {'id' : 0}).id |
| 4013 | " Open the location list window. Only this window will be shown and the file |
| 4014 | " window is closed. |
| 4015 | lopen |
| 4016 | call assert_equal(loclistid, getloclist(0, {'id' : 0}).id) |
| 4017 | " Jump to an entry in the location list and make sure that the cursor is |
| 4018 | " positioned correctly. |
| 4019 | ll 3 |
| 4020 | call assert_equal(loclistid, getloclist(0, {'id' : 0}).id) |
| 4021 | call assert_equal('Xtest1', bufname('')) |
| 4022 | call assert_equal(15, line('.')) |
| 4023 | " Cleanup |
| 4024 | autocmd! WinEnter |
| 4025 | new | only |
| 4026 | call delete('Xtest1') |
| 4027 | endfunc |
Bram Moolenaar | 39803d8 | 2019-04-07 12:04:51 +0200 | [diff] [blame] | 4028 | |
| 4029 | " Test to make sure that an empty quickfix buffer is not reused for loading |
| 4030 | " a normal buffer. |
| 4031 | func Test_empty_qfbuf() |
| 4032 | enew | only |
| 4033 | call writefile(["Test"], 'Xfile1') |
| 4034 | call setqflist([], 'f') |
| 4035 | copen | only |
| 4036 | let qfbuf = bufnr('') |
| 4037 | edit Xfile1 |
| 4038 | call assert_notequal(qfbuf, bufnr('')) |
| 4039 | enew |
| 4040 | call delete('Xfile1') |
| 4041 | endfunc |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 4042 | |
| 4043 | " Test for the :cbelow, :cabove, :lbelow and :labove commands. |
| 4044 | func Xtest_below(cchar) |
| 4045 | call s:setup_commands(a:cchar) |
| 4046 | |
| 4047 | " No quickfix/location list |
| 4048 | call assert_fails('Xbelow', 'E42:') |
| 4049 | call assert_fails('Xabove', 'E42:') |
| 4050 | |
| 4051 | " Empty quickfix/location list |
| 4052 | call g:Xsetlist([]) |
| 4053 | call assert_fails('Xbelow', 'E42:') |
| 4054 | call assert_fails('Xabove', 'E42:') |
| 4055 | |
| 4056 | call s:create_test_file('X1') |
| 4057 | call s:create_test_file('X2') |
| 4058 | call s:create_test_file('X3') |
| 4059 | call s:create_test_file('X4') |
| 4060 | |
| 4061 | " Invalid entries |
| 4062 | edit X1 |
| 4063 | call g:Xsetlist(["E1", "E2"]) |
| 4064 | call assert_fails('Xbelow', 'E42:') |
| 4065 | call assert_fails('Xabove', 'E42:') |
| 4066 | call assert_fails('3Xbelow', 'E42:') |
| 4067 | call assert_fails('4Xabove', 'E42:') |
| 4068 | |
| 4069 | " Test the commands with various arguments |
| 4070 | Xexpr ["X1:5:L5", "X2:5:L5", "X2:10:L10", "X2:15:L15", "X3:3:L3"] |
| 4071 | edit +7 X2 |
| 4072 | Xabove |
| 4073 | call assert_equal(['X2', 5], [bufname(''), line('.')]) |
| 4074 | call assert_fails('Xabove', 'E553:') |
| 4075 | normal 2j |
| 4076 | Xbelow |
| 4077 | call assert_equal(['X2', 10], [bufname(''), line('.')]) |
| 4078 | " Last error in this file |
| 4079 | Xbelow 99 |
| 4080 | call assert_equal(['X2', 15], [bufname(''), line('.')]) |
| 4081 | call assert_fails('Xbelow', 'E553:') |
| 4082 | " First error in this file |
| 4083 | Xabove 99 |
| 4084 | call assert_equal(['X2', 5], [bufname(''), line('.')]) |
| 4085 | call assert_fails('Xabove', 'E553:') |
| 4086 | normal gg |
| 4087 | Xbelow 2 |
| 4088 | call assert_equal(['X2', 10], [bufname(''), line('.')]) |
| 4089 | normal G |
| 4090 | Xabove 2 |
| 4091 | call assert_equal(['X2', 10], [bufname(''), line('.')]) |
| 4092 | edit X4 |
| 4093 | call assert_fails('Xabove', 'E42:') |
| 4094 | call assert_fails('Xbelow', 'E42:') |
| 4095 | if a:cchar == 'l' |
| 4096 | " If a buffer has location list entries from some other window but not |
| 4097 | " from the current window, then the commands should fail. |
| 4098 | edit X1 | split | call setloclist(0, [], 'f') |
| 4099 | call assert_fails('Xabove', 'E776:') |
| 4100 | call assert_fails('Xbelow', 'E776:') |
| 4101 | close |
| 4102 | endif |
| 4103 | |
| 4104 | " Test for lines with multiple quickfix entries |
| 4105 | Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3", |
| 4106 | \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3", |
| 4107 | \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"] |
| 4108 | edit +1 X2 |
| 4109 | Xbelow 2 |
| 4110 | call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')]) |
| 4111 | normal gg |
| 4112 | Xbelow 99 |
| 4113 | call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')]) |
| 4114 | normal G |
| 4115 | Xabove 2 |
| 4116 | call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')]) |
| 4117 | normal G |
| 4118 | Xabove 99 |
| 4119 | call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')]) |
| 4120 | normal 10G |
| 4121 | Xabove |
| 4122 | call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')]) |
| 4123 | normal 10G |
| 4124 | Xbelow |
| 4125 | call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')]) |
| 4126 | |
| 4127 | " Invalid range |
| 4128 | if a:cchar == 'c' |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 4129 | call assert_fails('-2cbelow', 'E16:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 4130 | else |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 4131 | call assert_fails('-2lbelow', 'E16:') |
Bram Moolenaar | 3ff3311 | 2019-05-03 21:56:35 +0200 | [diff] [blame] | 4132 | endif |
| 4133 | |
| 4134 | call delete('X1') |
| 4135 | call delete('X2') |
| 4136 | call delete('X3') |
| 4137 | call delete('X4') |
| 4138 | endfunc |
| 4139 | |
| 4140 | func Test_cbelow() |
| 4141 | call Xtest_below('c') |
| 4142 | call Xtest_below('l') |
| 4143 | endfunc |
Bram Moolenaar | 25190db | 2019-05-04 15:05:28 +0200 | [diff] [blame] | 4144 | |
| 4145 | func Test_quickfix_count() |
| 4146 | let commands = [ |
| 4147 | \ 'cNext', |
| 4148 | \ 'cNfile', |
| 4149 | \ 'cabove', |
| 4150 | \ 'cbelow', |
| 4151 | \ 'cfirst', |
| 4152 | \ 'clast', |
| 4153 | \ 'cnewer', |
| 4154 | \ 'cnext', |
| 4155 | \ 'cnfile', |
| 4156 | \ 'colder', |
| 4157 | \ 'cprevious', |
| 4158 | \ 'crewind', |
| 4159 | \ |
| 4160 | \ 'lNext', |
| 4161 | \ 'lNfile', |
| 4162 | \ 'labove', |
| 4163 | \ 'lbelow', |
| 4164 | \ 'lfirst', |
| 4165 | \ 'llast', |
| 4166 | \ 'lnewer', |
| 4167 | \ 'lnext', |
| 4168 | \ 'lnfile', |
| 4169 | \ 'lolder', |
| 4170 | \ 'lprevious', |
| 4171 | \ 'lrewind', |
| 4172 | \ ] |
| 4173 | for cmd in commands |
| 4174 | call assert_fails('-1' .. cmd, 'E16:') |
| 4175 | call assert_fails('.' .. cmd, 'E16:') |
| 4176 | call assert_fails('%' .. cmd, 'E16:') |
| 4177 | call assert_fails('$' .. cmd, 'E16:') |
| 4178 | endfor |
| 4179 | endfunc |