Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 1 | " Tests for editing the command line. |
| 2 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | source screendump.vim |
| 5 | |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 6 | func Test_complete_tab() |
| 7 | call writefile(['testfile'], 'Xtestfile') |
| 8 | call feedkeys(":e Xtest\t\r", "tx") |
| 9 | call assert_equal('testfile', getline(1)) |
| 10 | call delete('Xtestfile') |
| 11 | endfunc |
| 12 | |
| 13 | func Test_complete_list() |
| 14 | " We can't see the output, but at least we check the code runs properly. |
| 15 | call feedkeys(":e test\<C-D>\r", "tx") |
| 16 | call assert_equal('test', expand('%:t')) |
| 17 | endfunc |
| 18 | |
| 19 | func Test_complete_wildmenu() |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 20 | call mkdir('Xdir1/Xdir2', 'p') |
| 21 | call writefile(['testfile1'], 'Xdir1/Xtestfile1') |
| 22 | call writefile(['testfile2'], 'Xdir1/Xtestfile2') |
| 23 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') |
| 24 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 25 | set wildmenu |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 26 | |
| 27 | " Pressing <Tab> completes, and moves to next files when pressing again. |
| 28 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') |
| 29 | call assert_equal('testfile1', getline(1)) |
| 30 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 31 | call assert_equal('testfile2', getline(1)) |
| 32 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 33 | " <S-Tab> is like <Tab> but begin with the last match and then go to |
| 34 | " previous. |
| 35 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') |
| 36 | call assert_equal('testfile2', getline(1)) |
| 37 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') |
| 38 | call assert_equal('testfile1', getline(1)) |
| 39 | |
| 40 | " <Left>/<Right> to move to previous/next file. |
| 41 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') |
| 42 | call assert_equal('testfile1', getline(1)) |
| 43 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') |
| 44 | call assert_equal('testfile2', getline(1)) |
| 45 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') |
| 46 | call assert_equal('testfile1', getline(1)) |
| 47 | |
| 48 | " <Up>/<Down> to go up/down directories. |
| 49 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') |
| 50 | call assert_equal('testfile3', getline(1)) |
| 51 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') |
| 52 | call assert_equal('testfile1', getline(1)) |
| 53 | |
| 54 | " cleanup |
| 55 | %bwipe |
| 56 | call delete('Xdir1/Xdir2/Xtestfile4') |
| 57 | call delete('Xdir1/Xdir2/Xtestfile3') |
| 58 | call delete('Xdir1/Xtestfile2') |
| 59 | call delete('Xdir1/Xtestfile1') |
| 60 | call delete('Xdir1/Xdir2', 'd') |
| 61 | call delete('Xdir1', 'd') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 62 | set nowildmenu |
| 63 | endfunc |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 64 | |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 65 | func Test_map_completion() |
| 66 | if !has('cmdline_compl') |
| 67 | return |
| 68 | endif |
| 69 | call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') |
| 70 | call assert_equal('"map <unique> <silent>', getreg(':')) |
| 71 | call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') |
| 72 | call assert_equal('"map <script> <unique>', getreg(':')) |
| 73 | call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') |
| 74 | call assert_equal('"map <expr> <script>', getreg(':')) |
| 75 | call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') |
| 76 | call assert_equal('"map <buffer> <expr>', getreg(':')) |
| 77 | call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') |
| 78 | call assert_equal('"map <nowait> <buffer>', getreg(':')) |
| 79 | call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') |
| 80 | call assert_equal('"map <special> <nowait>', getreg(':')) |
| 81 | call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') |
| 82 | call assert_equal('"map <silent> <special>', getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 83 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 84 | map <Middle>x middle |
| 85 | |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 86 | map ,f commaf |
| 87 | map ,g commaf |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 88 | map <Left> left |
| 89 | map <A-Left>x shiftleft |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 90 | call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') |
| 91 | call assert_equal('"map ,f', getreg(':')) |
| 92 | call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') |
| 93 | call assert_equal('"map ,g', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 94 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 95 | call assert_equal('"map <Left>', getreg(':')) |
| 96 | call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 97 | call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 98 | unmap ,f |
| 99 | unmap ,g |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 100 | unmap <Left> |
| 101 | unmap <A-Left>x |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 102 | |
| 103 | set cpo-=< cpo-=B cpo-=k |
| 104 | map <Left> left |
| 105 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 106 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 107 | call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 108 | call assert_equal("\"map <M\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 109 | unmap <Left> |
| 110 | |
| 111 | set cpo+=< |
| 112 | map <Left> left |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 113 | exe "set t_k6=\<Esc>[17~" |
| 114 | call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 115 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 116 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 510671a | 2019-05-04 19:26:56 +0200 | [diff] [blame] | 117 | if !has('gui_running') |
| 118 | call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') |
| 119 | call assert_equal("\"map <F6>x", getreg(':')) |
| 120 | endif |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 121 | unmap <Left> |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 122 | call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 123 | set cpo-=< |
| 124 | |
| 125 | set cpo+=B |
| 126 | map <Left> left |
| 127 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 128 | call assert_equal('"map <Left>', getreg(':')) |
| 129 | unmap <Left> |
| 130 | set cpo-=B |
| 131 | |
| 132 | set cpo+=k |
| 133 | map <Left> left |
| 134 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 135 | call assert_equal('"map <Left>', getreg(':')) |
| 136 | unmap <Left> |
| 137 | set cpo-=k |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 138 | |
| 139 | unmap <Middle>x |
| 140 | set cpo&vim |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 141 | endfunc |
| 142 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 143 | func Test_match_completion() |
| 144 | if !has('cmdline_compl') |
| 145 | return |
| 146 | endif |
| 147 | hi Aardig ctermfg=green |
| 148 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
| 149 | call assert_equal('"match Aardig', getreg(':')) |
| 150 | call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') |
| 151 | call assert_equal('"match none', getreg(':')) |
| 152 | endfunc |
| 153 | |
| 154 | func Test_highlight_completion() |
| 155 | if !has('cmdline_compl') |
| 156 | return |
| 157 | endif |
| 158 | hi Aardig ctermfg=green |
| 159 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 160 | call assert_equal('"hi Aardig', getreg(':')) |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 161 | call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') |
| 162 | call assert_equal('"hi default Aardig', getreg(':')) |
| 163 | call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 164 | call assert_equal('"hi clear Aardig', getreg(':')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 165 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 166 | call assert_equal('"hi link', getreg(':')) |
| 167 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 168 | call assert_equal('"hi default', getreg(':')) |
| 169 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 170 | call assert_equal('"hi clear', getreg(':')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 171 | |
| 172 | " A cleared group does not show up in completions. |
| 173 | hi Anders ctermfg=green |
| 174 | call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) |
| 175 | hi clear Aardig |
| 176 | call assert_equal(['Anders'], getcompletion('A', 'highlight')) |
| 177 | hi clear Anders |
| 178 | call assert_equal([], getcompletion('A', 'highlight')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 179 | endfunc |
| 180 | |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 181 | func Test_expr_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 182 | if !has('cmdline_compl') |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 183 | return |
| 184 | endif |
| 185 | for cmd in [ |
| 186 | \ 'let a = ', |
Bram Moolenaar | 8f76e6b | 2019-11-26 16:50:30 +0100 | [diff] [blame] | 187 | \ 'const a = ', |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 188 | \ 'if', |
| 189 | \ 'elseif', |
| 190 | \ 'while', |
| 191 | \ 'for', |
| 192 | \ 'echo', |
| 193 | \ 'echon', |
| 194 | \ 'execute', |
| 195 | \ 'echomsg', |
| 196 | \ 'echoerr', |
| 197 | \ 'call', |
| 198 | \ 'return', |
| 199 | \ 'cexpr', |
| 200 | \ 'caddexpr', |
| 201 | \ 'cgetexpr', |
| 202 | \ 'lexpr', |
| 203 | \ 'laddexpr', |
| 204 | \ 'lgetexpr'] |
| 205 | call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') |
| 206 | call assert_equal('"' . cmd . ' getline(', getreg(':')) |
| 207 | endfor |
| 208 | endfunc |
| 209 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 210 | func Test_getcompletion() |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 211 | if !has('cmdline_compl') |
| 212 | return |
| 213 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 214 | let groupcount = len(getcompletion('', 'event')) |
| 215 | call assert_true(groupcount > 0) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 216 | let matchcount = len('File'->getcompletion('event')) |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 217 | call assert_true(matchcount > 0) |
| 218 | call assert_true(groupcount > matchcount) |
| 219 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 220 | if has('menu') |
| 221 | source $VIMRUNTIME/menu.vim |
| 222 | let matchcount = len(getcompletion('', 'menu')) |
| 223 | call assert_true(matchcount > 0) |
| 224 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 225 | call assert_true(matchcount > 0) |
| 226 | let matchcount = len(getcompletion('File.', 'menu')) |
| 227 | call assert_true(matchcount > 0) |
| 228 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 229 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 230 | let l = getcompletion('v:n', 'var') |
| 231 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 232 | let l = getcompletion('v:notexists', 'var') |
| 233 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 234 | |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 235 | args a.c b.c |
| 236 | let l = getcompletion('', 'arglist') |
| 237 | call assert_equal(['a.c', 'b.c'], l) |
| 238 | %argdelete |
| 239 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 240 | let l = getcompletion('', 'augroup') |
| 241 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 242 | let l = getcompletion('blahblah', 'augroup') |
| 243 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 244 | |
| 245 | let l = getcompletion('', 'behave') |
| 246 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 247 | let l = getcompletion('not', 'behave') |
| 248 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 249 | |
| 250 | let l = getcompletion('', 'color') |
| 251 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 252 | let l = getcompletion('dirty', 'color') |
| 253 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 254 | |
| 255 | let l = getcompletion('', 'command') |
| 256 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 257 | let l = getcompletion('awake', 'command') |
| 258 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 259 | |
| 260 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 261 | call assert_true(index(l, 'samples/') >= 0) |
| 262 | let l = getcompletion('NoMatch', 'dir') |
| 263 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 264 | |
| 265 | let l = getcompletion('exe', 'expression') |
| 266 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 267 | let l = getcompletion('kill', 'expression') |
| 268 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 269 | |
| 270 | let l = getcompletion('tag', 'function') |
| 271 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 272 | let l = getcompletion('paint', 'function') |
| 273 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 274 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 275 | let Flambda = {-> 'hello'} |
| 276 | let l = getcompletion('', 'function') |
| 277 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 278 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 279 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 280 | let l = getcompletion('run', 'file') |
| 281 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 282 | let l = getcompletion('walk', 'file') |
| 283 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 284 | set wildignore=*.vim |
| 285 | let l = getcompletion('run', 'file', 1) |
| 286 | call assert_true(index(l, 'runtest.vim') < 0) |
| 287 | set wildignore& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 288 | |
| 289 | let l = getcompletion('ha', 'filetype') |
| 290 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 291 | let l = getcompletion('horse', 'filetype') |
| 292 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 293 | |
| 294 | let l = getcompletion('z', 'syntax') |
| 295 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 296 | let l = getcompletion('emacs', 'syntax') |
| 297 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 298 | |
| 299 | let l = getcompletion('jikes', 'compiler') |
| 300 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 301 | let l = getcompletion('break', 'compiler') |
| 302 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 303 | |
| 304 | let l = getcompletion('last', 'help') |
| 305 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 306 | let l = getcompletion('giveup', 'help') |
| 307 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 308 | |
| 309 | let l = getcompletion('time', 'option') |
| 310 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 311 | let l = getcompletion('space', 'option') |
| 312 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 313 | |
| 314 | let l = getcompletion('er', 'highlight') |
| 315 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 316 | let l = getcompletion('dark', 'highlight') |
| 317 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 318 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 319 | let l = getcompletion('', 'messages') |
| 320 | call assert_true(index(l, 'clear') >= 0) |
| 321 | let l = getcompletion('not', 'messages') |
| 322 | call assert_equal([], l) |
| 323 | |
Bram Moolenaar | cae92dc | 2017-08-06 15:22:15 +0200 | [diff] [blame] | 324 | let l = getcompletion('', 'mapclear') |
| 325 | call assert_true(index(l, '<buffer>') >= 0) |
| 326 | let l = getcompletion('not', 'mapclear') |
| 327 | call assert_equal([], l) |
| 328 | |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 329 | let l = getcompletion('.', 'shellcmd') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 330 | call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 331 | call assert_equal(-1, match(l[2:], '^\.\.\?/$')) |
| 332 | let root = has('win32') ? 'C:\\' : '/' |
| 333 | let l = getcompletion(root, 'shellcmd') |
| 334 | let expected = map(filter(glob(root . '*', 0, 1), |
| 335 | \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') |
| 336 | call assert_equal(expected, l) |
| 337 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 338 | if has('cscope') |
| 339 | let l = getcompletion('', 'cscope') |
| 340 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 341 | call assert_equal(cmds, l) |
| 342 | " using cmdline completion must not change the result |
| 343 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 344 | let l = getcompletion('', 'cscope') |
| 345 | call assert_equal(cmds, l) |
| 346 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 347 | let l = getcompletion('find ', 'cscope') |
| 348 | call assert_equal(keys, l) |
| 349 | endif |
| 350 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 351 | if has('signs') |
| 352 | sign define Testing linehl=Comment |
| 353 | let l = getcompletion('', 'sign') |
| 354 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 355 | call assert_equal(cmds, l) |
| 356 | " using cmdline completion must not change the result |
| 357 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 358 | let l = getcompletion('', 'sign') |
| 359 | call assert_equal(cmds, l) |
| 360 | let l = getcompletion('list ', 'sign') |
| 361 | call assert_equal(['Testing'], l) |
| 362 | endif |
| 363 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 364 | " For others test if the name is recognized. |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 365 | let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 366 | if has('cmdline_hist') |
| 367 | call add(names, 'history') |
| 368 | endif |
| 369 | if has('gettext') |
| 370 | call add(names, 'locale') |
| 371 | endif |
| 372 | if has('profile') |
| 373 | call add(names, 'syntime') |
| 374 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 375 | |
| 376 | set tags=Xtags |
| 377 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 378 | |
| 379 | for name in names |
| 380 | let matchcount = len(getcompletion('', name)) |
| 381 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 382 | endfor |
| 383 | |
| 384 | call delete('Xtags') |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 385 | set tags& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 386 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 387 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
| 388 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 389 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 390 | func Test_shellcmd_completion() |
| 391 | let save_path = $PATH |
| 392 | |
| 393 | call mkdir('Xpathdir/Xpathsubdir', 'p') |
| 394 | call writefile([''], 'Xpathdir/Xfile.exe') |
| 395 | call setfperm('Xpathdir/Xfile.exe', 'rwx------') |
| 396 | |
| 397 | " Set PATH to example directory without trailing slash. |
| 398 | let $PATH = getcwd() . '/Xpathdir' |
| 399 | |
| 400 | " Test for the ":!<TAB>" case. Previously, this would include subdirs of |
| 401 | " dirs in the PATH, even though they won't be executed. We check that only |
| 402 | " subdirs of the PWD and executables from the PATH are included in the |
| 403 | " suggestions. |
| 404 | let actual = getcompletion('X', 'shellcmd') |
| 405 | let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') |
| 406 | call insert(expected, 'Xfile.exe') |
| 407 | call assert_equal(expected, actual) |
| 408 | |
| 409 | call delete('Xpathdir', 'rf') |
| 410 | let $PATH = save_path |
| 411 | endfunc |
| 412 | |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 413 | func Test_expand_star_star() |
| 414 | call mkdir('a/b', 'p') |
| 415 | call writefile(['asdfasdf'], 'a/b/fileXname') |
| 416 | call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') |
| 417 | call assert_equal('find a/b/fileXname', getreg(':')) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 418 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 419 | call delete('a', 'rf') |
| 420 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 421 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 422 | func Test_cmdline_paste() |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 423 | let @a = "def" |
| 424 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 425 | call assert_equal('"abc def ghi', @:) |
| 426 | |
| 427 | new |
| 428 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 429 | |
| 430 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 431 | call assert_equal('"aaa asdf bbb', @:) |
| 432 | |
| 433 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 434 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 435 | |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 436 | call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') |
| 437 | call assert_equal('"aaa '.getline(1).' bbb', @:) |
| 438 | |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 439 | set incsearch |
| 440 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 441 | call assert_equal('"aaa verylongword bbb', @:) |
| 442 | |
| 443 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 444 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 445 | |
| 446 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 447 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 448 | bwipe! |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 449 | |
| 450 | " Error while typing a command used to cause that it was not executed |
| 451 | " in the end. |
| 452 | new |
| 453 | try |
| 454 | call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') |
| 455 | catch /^Vim\%((\a\+)\)\=:E32/ |
| 456 | " ignore error E32 |
| 457 | endtry |
| 458 | call assert_equal("Xtestfile", bufname("%")) |
| 459 | bwipe! |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 460 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 461 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 462 | func Test_cmdline_remove_char() |
| 463 | let encoding_save = &encoding |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 464 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 465 | for e in ['utf8', 'latin1'] |
| 466 | exe 'set encoding=' . e |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 467 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 468 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 469 | call assert_equal('"abc ef', @:, e) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 470 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 471 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 472 | call assert_equal('"abcdef', @:) |
| 473 | |
| 474 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 475 | call assert_equal('"abc ghi', @:, e) |
| 476 | |
| 477 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 478 | call assert_equal('"def', @:, e) |
| 479 | endfor |
| 480 | |
| 481 | let &encoding = encoding_save |
| 482 | endfunc |
| 483 | |
| 484 | func Test_cmdline_keymap_ctrl_hat() |
| 485 | if !has('keymap') |
| 486 | return |
| 487 | endif |
| 488 | |
| 489 | set keymap=esperanto |
| 490 | call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') |
| 491 | call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) |
| 492 | set keymap= |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 493 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 494 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 495 | func Test_illegal_address1() |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 496 | new |
| 497 | 2;'( |
| 498 | 2;') |
| 499 | quit |
| 500 | endfunc |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 501 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 502 | func Test_illegal_address2() |
| 503 | call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') |
| 504 | new |
| 505 | source Xtest.vim |
| 506 | " Trigger calling validate_cursor() |
| 507 | diffsp Xtest.vim |
| 508 | quit! |
| 509 | bwipe! |
| 510 | call delete('Xtest.vim') |
| 511 | endfunc |
| 512 | |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 513 | func Test_cmdline_complete_wildoptions() |
| 514 | help |
| 515 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 516 | let a = join(sort(split(@:)),' ') |
| 517 | set wildoptions=tagfile |
| 518 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 519 | let b = join(sort(split(@:)),' ') |
| 520 | call assert_equal(a, b) |
| 521 | bw! |
| 522 | endfunc |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 523 | |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 524 | func Test_cmdline_complete_user_cmd() |
| 525 | command! -complete=color -nargs=1 Foo : |
| 526 | call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') |
| 527 | call assert_equal('"Foo blue', @:) |
| 528 | call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') |
| 529 | call assert_equal('"Foo blue', @:) |
| 530 | delcommand Foo |
| 531 | endfunc |
| 532 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 533 | func Test_cmdline_complete_user_names() |
| 534 | if has('unix') && executable('whoami') |
| 535 | let whoami = systemlist('whoami')[0] |
| 536 | let first_letter = whoami[0] |
| 537 | if len(first_letter) > 0 |
| 538 | " Trying completion of :e ~x where x is the first letter of |
| 539 | " the user name should complete to at least the user name. |
| 540 | call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') |
| 541 | call assert_match('^"e \~.*\<' . whoami . '\>', @:) |
| 542 | endif |
| 543 | endif |
| 544 | if has('win32') |
| 545 | " Just in case: check that the system has an Administrator account. |
| 546 | let names = system('net user') |
| 547 | if names =~ 'Administrator' |
| 548 | " Trying completion of :e ~A should complete to Administrator. |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 549 | " There could be other names starting with "A" before Administrator. |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 550 | call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 551 | call assert_match('^"e \~.*Administrator', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 552 | endif |
| 553 | endif |
| 554 | endfunc |
| 555 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 556 | func Test_cmdline_complete_bang() |
| 557 | if executable('whoami') |
Bram Moolenaar | 731a799 | 2019-12-28 14:06:50 +0100 | [diff] [blame] | 558 | call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') |
| 559 | call assert_match('^".*\<whoami\>', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 560 | endif |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 561 | endfunc |
| 562 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 563 | funct Test_cmdline_complete_languages() |
| 564 | let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') |
| 565 | |
| 566 | call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') |
| 567 | call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) |
| 568 | |
| 569 | if has('unix') |
| 570 | " TODO: these tests don't work on Windows. lang appears to be 'C' |
| 571 | " but C does not appear in the completion. Why? |
| 572 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 573 | |
| 574 | call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') |
| 575 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 576 | |
| 577 | call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') |
| 578 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 579 | |
| 580 | call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') |
| 581 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 582 | endif |
| 583 | endfunc |
| 584 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 585 | func Test_cmdline_complete_env_variable() |
| 586 | let $X_VIM_TEST_COMPLETE_ENV = 'foo' |
| 587 | |
| 588 | call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') |
| 589 | call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) |
| 590 | |
| 591 | unlet $X_VIM_TEST_COMPLETE_ENV |
| 592 | endfunc |
| 593 | |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 594 | func Test_cmdline_write_alternatefile() |
| 595 | new |
| 596 | call setline('.', ['one', 'two']) |
| 597 | f foo.txt |
| 598 | new |
| 599 | f #-A |
| 600 | call assert_equal('foo.txt-A', expand('%')) |
| 601 | f #<-B.txt |
| 602 | call assert_equal('foo-B.txt', expand('%')) |
| 603 | f %< |
| 604 | call assert_equal('foo-B', expand('%')) |
| 605 | new |
| 606 | call assert_fails('f #<', 'E95') |
| 607 | bw! |
| 608 | f foo-B.txt |
| 609 | f %<-A |
| 610 | call assert_equal('foo-B-A', expand('%')) |
| 611 | bw! |
| 612 | bw! |
| 613 | endfunc |
| 614 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 615 | " using a leading backslash here |
| 616 | set cpo+=C |
| 617 | |
| 618 | func Test_cmdline_search_range() |
| 619 | new |
| 620 | call setline(1, ['a', 'b', 'c', 'd']) |
| 621 | /d |
| 622 | 1,\/s/b/B/ |
| 623 | call assert_equal('B', getline(2)) |
| 624 | |
| 625 | /a |
| 626 | $ |
| 627 | \?,4s/c/C/ |
| 628 | call assert_equal('C', getline(3)) |
| 629 | |
| 630 | call setline(1, ['a', 'b', 'c', 'd']) |
| 631 | %s/c/c/ |
| 632 | 1,\&s/b/B/ |
| 633 | call assert_equal('B', getline(2)) |
| 634 | |
| 635 | bwipe! |
| 636 | endfunc |
| 637 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 638 | " Tests for getcmdline(), getcmdpos() and getcmdtype() |
| 639 | func Check_cmdline(cmdtype) |
| 640 | call assert_equal('MyCmd a', getcmdline()) |
| 641 | call assert_equal(8, getcmdpos()) |
| 642 | call assert_equal(a:cmdtype, getcmdtype()) |
| 643 | return '' |
| 644 | endfunc |
| 645 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 646 | set cpo& |
| 647 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 648 | func Test_getcmdtype() |
| 649 | call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") |
| 650 | |
| 651 | let cmdtype = '' |
| 652 | debuggreedy |
| 653 | call feedkeys(":debug echo 'test'\<CR>", "t") |
| 654 | call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") |
| 655 | call feedkeys("cont\<CR>", "xt") |
| 656 | 0debuggreedy |
| 657 | call assert_equal('>', cmdtype) |
| 658 | |
| 659 | call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") |
| 660 | call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") |
| 661 | |
| 662 | call feedkeys(":call input('Answer?')\<CR>", "t") |
Bram Moolenaar | 31eb139 | 2017-02-09 21:44:03 +0100 | [diff] [blame] | 663 | call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 664 | |
| 665 | call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") |
| 666 | |
| 667 | cnoremap <expr> <F6> Check_cmdline('=') |
| 668 | call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") |
| 669 | cunmap <F6> |
| 670 | endfunc |
| 671 | |
Bram Moolenaar | 81612b7 | 2018-06-23 14:55:03 +0200 | [diff] [blame] | 672 | func Test_getcmdwintype() |
| 673 | call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 674 | call assert_equal('/', a) |
| 675 | |
| 676 | call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 677 | call assert_equal('?', a) |
| 678 | |
| 679 | call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 680 | call assert_equal(':', a) |
| 681 | |
| 682 | call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 683 | call assert_equal(':', a) |
| 684 | |
| 685 | call assert_equal('', getcmdwintype()) |
| 686 | endfunc |
| 687 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 688 | func Test_getcmdwin_autocmd() |
| 689 | let s:seq = [] |
| 690 | augroup CmdWin |
| 691 | au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) |
| 692 | au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) |
| 693 | au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) |
| 694 | au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) |
| 695 | au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) |
| 696 | au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) |
| 697 | |
| 698 | let org_winid = win_getid() |
| 699 | let org_bufnr = bufnr() |
| 700 | call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') |
| 701 | call assert_equal(':', a) |
| 702 | call assert_equal([ |
| 703 | \ 'WinLeave ' .. org_winid, |
| 704 | \ 'WinEnter ' .. s:cmd_winid, |
| 705 | \ 'BufLeave ' .. org_bufnr, |
| 706 | \ 'BufEnter ' .. s:cmd_bufnr, |
| 707 | \ 'CmdWinEnter ' .. s:cmd_winid, |
| 708 | \ 'CmdWinLeave ' .. s:cmd_winid, |
| 709 | \ 'BufLeave ' .. s:cmd_bufnr, |
| 710 | \ 'WinLeave ' .. s:cmd_winid, |
| 711 | \ 'WinEnter ' .. org_winid, |
| 712 | \ 'BufEnter ' .. org_bufnr, |
| 713 | \ ], s:seq) |
| 714 | |
| 715 | au! |
| 716 | augroup END |
| 717 | endfunc |
| 718 | |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 719 | func Test_verbosefile() |
| 720 | set verbosefile=Xlog |
| 721 | echomsg 'foo' |
| 722 | echomsg 'bar' |
| 723 | set verbosefile= |
| 724 | let log = readfile('Xlog') |
| 725 | call assert_match("foo\nbar", join(log, "\n")) |
| 726 | call delete('Xlog') |
| 727 | endfunc |
| 728 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 729 | func Test_verbose_option() |
| 730 | CheckScreendump |
| 731 | |
| 732 | let lines =<< trim [SCRIPT] |
| 733 | command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v |
| 734 | call feedkeys("\r", 't') " for the hit-enter prompt |
| 735 | set verbose=20 |
| 736 | [SCRIPT] |
| 737 | call writefile(lines, 'XTest_verbose') |
| 738 | |
| 739 | let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) |
| 740 | call term_wait(buf, 100) |
| 741 | call term_sendkeys(buf, ":DoSomething\<CR>") |
| 742 | call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) |
| 743 | |
| 744 | " clean up |
| 745 | call StopVimInTerminal(buf) |
| 746 | call delete('XTest_verbose') |
| 747 | endfunc |
| 748 | |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 749 | func Test_setcmdpos() |
| 750 | func InsertTextAtPos(text, pos) |
| 751 | call assert_equal(0, setcmdpos(a:pos)) |
| 752 | return a:text |
| 753 | endfunc |
| 754 | |
| 755 | " setcmdpos() with position in the middle of the command line. |
| 756 | call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 757 | call assert_equal('"1ab2', @:) |
| 758 | |
| 759 | call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 760 | call assert_equal('"1b2a', @:) |
| 761 | |
| 762 | " setcmdpos() with position beyond the end of the command line. |
| 763 | call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') |
| 764 | call assert_equal('"12ab', @:) |
| 765 | |
| 766 | " setcmdpos() returns 1 when not editing the command line. |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 767 | call assert_equal(1, 3->setcmdpos()) |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 768 | endfunc |
| 769 | |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 770 | func Test_cmdline_overstrike() |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 771 | let encodings = ['latin1', 'utf8'] |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 772 | let encoding_save = &encoding |
| 773 | |
| 774 | for e in encodings |
| 775 | exe 'set encoding=' . e |
| 776 | |
| 777 | " Test overstrike in the middle of the command line. |
| 778 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 779 | call assert_equal('"0ab1cd4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 780 | |
| 781 | " Test overstrike going beyond end of command line. |
| 782 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 783 | call assert_equal('"0ab1cdefgh', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 784 | |
| 785 | " Test toggling insert/overstrike a few times. |
| 786 | call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 787 | call assert_equal('"ab0cd3ef4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 788 | endfor |
| 789 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 790 | " Test overstrike with multi-byte characters. |
| 791 | call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 792 | call assert_equal('"テabキcdエディタ', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 793 | |
| 794 | let &encoding = encoding_save |
| 795 | endfunc |
Bram Moolenaar | a046b37 | 2019-09-15 17:26:07 +0200 | [diff] [blame] | 796 | |
| 797 | func Test_cmdwin_bug() |
| 798 | let winid = win_getid() |
| 799 | sp |
| 800 | try |
| 801 | call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') |
| 802 | catch /^Vim\%((\a\+)\)\=:E11/ |
| 803 | endtry |
| 804 | bw! |
| 805 | endfunc |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 806 | |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 807 | func Test_cmdwin_restore() |
| 808 | CheckScreendump |
| 809 | |
| 810 | let lines =<< trim [SCRIPT] |
| 811 | call setline(1, range(30)) |
| 812 | 2split |
| 813 | [SCRIPT] |
| 814 | call writefile(lines, 'XTest_restore') |
| 815 | |
| 816 | let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) |
| 817 | call term_wait(buf, 100) |
| 818 | call term_sendkeys(buf, "q:") |
| 819 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) |
| 820 | |
| 821 | " normal restore |
| 822 | call term_sendkeys(buf, ":q\<CR>") |
| 823 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) |
| 824 | |
| 825 | " restore after setting 'lines' with one window |
| 826 | call term_sendkeys(buf, ":close\<CR>") |
| 827 | call term_sendkeys(buf, "q:") |
| 828 | call term_sendkeys(buf, ":set lines=18\<CR>") |
| 829 | call term_sendkeys(buf, ":q\<CR>") |
| 830 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) |
| 831 | |
| 832 | " clean up |
| 833 | call StopVimInTerminal(buf) |
| 834 | call delete('XTest_restore') |
| 835 | endfunc |
| 836 | |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 837 | func Test_buffers_lastused() |
| 838 | " check that buffers are sorted by time when wildmode has lastused |
| 839 | call test_settime(1550020000) " middle |
| 840 | edit bufa |
| 841 | enew |
| 842 | call test_settime(1550030000) " newest |
| 843 | edit bufb |
| 844 | enew |
| 845 | call test_settime(1550010000) " oldest |
| 846 | edit bufc |
| 847 | enew |
| 848 | call test_settime(0) |
| 849 | enew |
| 850 | |
| 851 | call assert_equal(['bufa', 'bufb', 'bufc'], |
| 852 | \ getcompletion('', 'buffer')) |
| 853 | |
| 854 | let save_wildmode = &wildmode |
| 855 | set wildmode=full:lastused |
| 856 | |
| 857 | let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" |
| 858 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 859 | call assert_equal('b bufb', X) |
| 860 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 861 | call assert_equal('b bufa', X) |
| 862 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 863 | call assert_equal('b bufc', X) |
| 864 | enew |
| 865 | |
| 866 | edit other |
| 867 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 868 | call assert_equal('b bufb', X) |
| 869 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 870 | call assert_equal('b bufa', X) |
| 871 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 872 | call assert_equal('b bufc', X) |
| 873 | enew |
| 874 | |
| 875 | let &wildmode = save_wildmode |
| 876 | |
| 877 | bwipeout bufa |
| 878 | bwipeout bufb |
| 879 | bwipeout bufc |
| 880 | endfunc |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 881 | |
| 882 | func Test_cmdwin_feedkeys() |
| 883 | " This should not generate E488 |
| 884 | call feedkeys("q:\<CR>", 'x') |
| 885 | endfunc |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 886 | |
| 887 | " Tests for the issues fixed in 7.4.441. |
| 888 | " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim |
| 889 | func Test_cmdwin_cedit() |
| 890 | exe "set cedit=\<C-c>" |
| 891 | normal! : |
| 892 | call assert_equal(1, winnr('$')) |
| 893 | |
| 894 | let g:cmd_wintype = '' |
| 895 | func CmdWinType() |
| 896 | let g:cmd_wintype = getcmdwintype() |
| 897 | return '' |
| 898 | endfunc |
| 899 | |
| 900 | call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") |
| 901 | echo input('') |
| 902 | call assert_equal('@', g:cmd_wintype) |
| 903 | |
| 904 | set cedit&vim |
| 905 | delfunc CmdWinType |
| 906 | endfunc |
| 907 | |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 908 | func Test_cmdlineclear_tabenter() |
| 909 | CheckScreendump |
| 910 | |
| 911 | let lines =<< trim [SCRIPT] |
| 912 | call setline(1, range(30)) |
| 913 | [SCRIPT] |
| 914 | |
| 915 | call writefile(lines, 'XtestCmdlineClearTabenter') |
| 916 | let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) |
| 917 | call term_wait(buf, 50) |
| 918 | " in one tab make the command line higher with CTRL-W - |
| 919 | call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") |
| 920 | call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) |
| 921 | |
| 922 | call StopVimInTerminal(buf) |
| 923 | call delete('XtestCmdlineClearTabenter') |
| 924 | endfunc |
| 925 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 926 | " Test for failure in expanding special keywords in cmdline |
| 927 | func Test_cmdline_expand_special() |
| 928 | %bwipe! |
| 929 | call assert_fails('e #', 'E499:') |
| 930 | call assert_fails('e <afile>', 'E495:') |
| 931 | call assert_fails('e <abuf>', 'E496:') |
| 932 | call assert_fails('e <amatch>', 'E497:') |
| 933 | endfunc |
| 934 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 935 | " vim: shiftwidth=2 sts=2 expandtab |