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')) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 17 | |
| 18 | " If a command doesn't support completion, then CTRL-D should be literally |
| 19 | " used. |
| 20 | call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') |
| 21 | call assert_equal("\"chistory \<C-D>", @:) |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 22 | endfunc |
| 23 | |
| 24 | func Test_complete_wildmenu() |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 25 | call mkdir('Xdir1/Xdir2', 'p') |
| 26 | call writefile(['testfile1'], 'Xdir1/Xtestfile1') |
| 27 | call writefile(['testfile2'], 'Xdir1/Xtestfile2') |
| 28 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') |
| 29 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 30 | set wildmenu |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 31 | |
| 32 | " Pressing <Tab> completes, and moves to next files when pressing again. |
| 33 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') |
| 34 | call assert_equal('testfile1', getline(1)) |
| 35 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 36 | call assert_equal('testfile2', getline(1)) |
| 37 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 38 | " <S-Tab> is like <Tab> but begin with the last match and then go to |
| 39 | " previous. |
| 40 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') |
| 41 | call assert_equal('testfile2', getline(1)) |
| 42 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') |
| 43 | call assert_equal('testfile1', getline(1)) |
| 44 | |
| 45 | " <Left>/<Right> to move to previous/next file. |
| 46 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') |
| 47 | call assert_equal('testfile1', getline(1)) |
| 48 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') |
| 49 | call assert_equal('testfile2', getline(1)) |
| 50 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') |
| 51 | call assert_equal('testfile1', getline(1)) |
| 52 | |
| 53 | " <Up>/<Down> to go up/down directories. |
| 54 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') |
| 55 | call assert_equal('testfile3', getline(1)) |
| 56 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') |
| 57 | call assert_equal('testfile1', getline(1)) |
| 58 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 59 | " Test for canceling the wild menu by adding a character |
| 60 | redrawstatus |
| 61 | call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt') |
| 62 | call assert_equal('"e Xdir1/Xdir2/x', @:) |
| 63 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 64 | " Completion using a relative path |
| 65 | cd Xdir1/Xdir2 |
| 66 | call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 67 | call assert_equal('"e Xtestfile3 Xtestfile4', @:) |
| 68 | cd - |
| 69 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 70 | " cleanup |
| 71 | %bwipe |
| 72 | call delete('Xdir1/Xdir2/Xtestfile4') |
| 73 | call delete('Xdir1/Xdir2/Xtestfile3') |
| 74 | call delete('Xdir1/Xtestfile2') |
| 75 | call delete('Xdir1/Xtestfile1') |
| 76 | call delete('Xdir1/Xdir2', 'd') |
| 77 | call delete('Xdir1', 'd') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 78 | set nowildmenu |
| 79 | endfunc |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 80 | |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 81 | func Test_map_completion() |
| 82 | if !has('cmdline_compl') |
| 83 | return |
| 84 | endif |
| 85 | call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') |
| 86 | call assert_equal('"map <unique> <silent>', getreg(':')) |
| 87 | call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') |
| 88 | call assert_equal('"map <script> <unique>', getreg(':')) |
| 89 | call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') |
| 90 | call assert_equal('"map <expr> <script>', getreg(':')) |
| 91 | call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') |
| 92 | call assert_equal('"map <buffer> <expr>', getreg(':')) |
| 93 | call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') |
| 94 | call assert_equal('"map <nowait> <buffer>', getreg(':')) |
| 95 | call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') |
| 96 | call assert_equal('"map <special> <nowait>', getreg(':')) |
| 97 | call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') |
| 98 | call assert_equal('"map <silent> <special>', getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 99 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 100 | map <Middle>x middle |
| 101 | |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 102 | map ,f commaf |
| 103 | map ,g commaf |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 104 | map <Left> left |
| 105 | map <A-Left>x shiftleft |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 106 | call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') |
| 107 | call assert_equal('"map ,f', getreg(':')) |
| 108 | call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') |
| 109 | call assert_equal('"map ,g', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 110 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 111 | call assert_equal('"map <Left>', getreg(':')) |
| 112 | call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 113 | call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 114 | unmap ,f |
| 115 | unmap ,g |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 116 | unmap <Left> |
| 117 | unmap <A-Left>x |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 118 | |
| 119 | set cpo-=< cpo-=B cpo-=k |
| 120 | map <Left> left |
| 121 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 122 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 123 | call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 124 | call assert_equal("\"map <M\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 125 | unmap <Left> |
| 126 | |
| 127 | set cpo+=< |
| 128 | map <Left> left |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 129 | exe "set t_k6=\<Esc>[17~" |
| 130 | call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 131 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 132 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 510671a | 2019-05-04 19:26:56 +0200 | [diff] [blame] | 133 | if !has('gui_running') |
| 134 | call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') |
| 135 | call assert_equal("\"map <F6>x", getreg(':')) |
| 136 | endif |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 137 | unmap <Left> |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 138 | call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 139 | set cpo-=< |
| 140 | |
| 141 | set cpo+=B |
| 142 | map <Left> left |
| 143 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 144 | call assert_equal('"map <Left>', getreg(':')) |
| 145 | unmap <Left> |
| 146 | set cpo-=B |
| 147 | |
| 148 | set cpo+=k |
| 149 | map <Left> left |
| 150 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 151 | call assert_equal('"map <Left>', getreg(':')) |
| 152 | unmap <Left> |
| 153 | set cpo-=k |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 154 | |
| 155 | unmap <Middle>x |
| 156 | set cpo&vim |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 157 | endfunc |
| 158 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 159 | func Test_match_completion() |
| 160 | if !has('cmdline_compl') |
| 161 | return |
| 162 | endif |
| 163 | hi Aardig ctermfg=green |
| 164 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
| 165 | call assert_equal('"match Aardig', getreg(':')) |
| 166 | call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') |
| 167 | call assert_equal('"match none', getreg(':')) |
| 168 | endfunc |
| 169 | |
| 170 | func Test_highlight_completion() |
| 171 | if !has('cmdline_compl') |
| 172 | return |
| 173 | endif |
| 174 | hi Aardig ctermfg=green |
| 175 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 176 | call assert_equal('"hi Aardig', getreg(':')) |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 177 | call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') |
| 178 | call assert_equal('"hi default Aardig', getreg(':')) |
| 179 | call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 180 | call assert_equal('"hi clear Aardig', getreg(':')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 181 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 182 | call assert_equal('"hi link', getreg(':')) |
| 183 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 184 | call assert_equal('"hi default', getreg(':')) |
| 185 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 186 | call assert_equal('"hi clear', getreg(':')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 187 | |
| 188 | " A cleared group does not show up in completions. |
| 189 | hi Anders ctermfg=green |
| 190 | call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) |
| 191 | hi clear Aardig |
| 192 | call assert_equal(['Anders'], getcompletion('A', 'highlight')) |
| 193 | hi clear Anders |
| 194 | call assert_equal([], getcompletion('A', 'highlight')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 195 | endfunc |
| 196 | |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 197 | func Test_expr_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 198 | if !has('cmdline_compl') |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 199 | return |
| 200 | endif |
| 201 | for cmd in [ |
| 202 | \ 'let a = ', |
Bram Moolenaar | 8f76e6b | 2019-11-26 16:50:30 +0100 | [diff] [blame] | 203 | \ 'const a = ', |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 204 | \ 'if', |
| 205 | \ 'elseif', |
| 206 | \ 'while', |
| 207 | \ 'for', |
| 208 | \ 'echo', |
| 209 | \ 'echon', |
| 210 | \ 'execute', |
| 211 | \ 'echomsg', |
| 212 | \ 'echoerr', |
| 213 | \ 'call', |
| 214 | \ 'return', |
| 215 | \ 'cexpr', |
| 216 | \ 'caddexpr', |
| 217 | \ 'cgetexpr', |
| 218 | \ 'lexpr', |
| 219 | \ 'laddexpr', |
| 220 | \ 'lgetexpr'] |
| 221 | call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') |
| 222 | call assert_equal('"' . cmd . ' getline(', getreg(':')) |
| 223 | endfor |
| 224 | endfunc |
| 225 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 226 | func Test_getcompletion() |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 227 | if !has('cmdline_compl') |
| 228 | return |
| 229 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 230 | let groupcount = len(getcompletion('', 'event')) |
| 231 | call assert_true(groupcount > 0) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 232 | let matchcount = len('File'->getcompletion('event')) |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 233 | call assert_true(matchcount > 0) |
| 234 | call assert_true(groupcount > matchcount) |
| 235 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 236 | if has('menu') |
| 237 | source $VIMRUNTIME/menu.vim |
| 238 | let matchcount = len(getcompletion('', 'menu')) |
| 239 | call assert_true(matchcount > 0) |
| 240 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 241 | call assert_true(matchcount > 0) |
| 242 | let matchcount = len(getcompletion('File.', 'menu')) |
| 243 | call assert_true(matchcount > 0) |
| 244 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 245 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 246 | let l = getcompletion('v:n', 'var') |
| 247 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 248 | let l = getcompletion('v:notexists', 'var') |
| 249 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 250 | |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 251 | args a.c b.c |
| 252 | let l = getcompletion('', 'arglist') |
| 253 | call assert_equal(['a.c', 'b.c'], l) |
| 254 | %argdelete |
| 255 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 256 | let l = getcompletion('', 'augroup') |
| 257 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 258 | let l = getcompletion('blahblah', 'augroup') |
| 259 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 260 | |
| 261 | let l = getcompletion('', 'behave') |
| 262 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 263 | let l = getcompletion('not', 'behave') |
| 264 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 265 | |
| 266 | let l = getcompletion('', 'color') |
| 267 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 268 | let l = getcompletion('dirty', 'color') |
| 269 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 270 | |
| 271 | let l = getcompletion('', 'command') |
| 272 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 273 | let l = getcompletion('awake', 'command') |
| 274 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 275 | |
| 276 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 277 | call assert_true(index(l, 'samples/') >= 0) |
| 278 | let l = getcompletion('NoMatch', 'dir') |
| 279 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 280 | |
| 281 | let l = getcompletion('exe', 'expression') |
| 282 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 283 | let l = getcompletion('kill', 'expression') |
| 284 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 285 | |
| 286 | let l = getcompletion('tag', 'function') |
| 287 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 288 | let l = getcompletion('paint', 'function') |
| 289 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 290 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 291 | let Flambda = {-> 'hello'} |
| 292 | let l = getcompletion('', 'function') |
| 293 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 294 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 295 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 296 | let l = getcompletion('run', 'file') |
| 297 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 298 | let l = getcompletion('walk', 'file') |
| 299 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 300 | set wildignore=*.vim |
| 301 | let l = getcompletion('run', 'file', 1) |
| 302 | call assert_true(index(l, 'runtest.vim') < 0) |
| 303 | set wildignore& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 304 | |
| 305 | let l = getcompletion('ha', 'filetype') |
| 306 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 307 | let l = getcompletion('horse', 'filetype') |
| 308 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 309 | |
| 310 | let l = getcompletion('z', 'syntax') |
| 311 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 312 | let l = getcompletion('emacs', 'syntax') |
| 313 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 314 | |
| 315 | let l = getcompletion('jikes', 'compiler') |
| 316 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 317 | let l = getcompletion('break', 'compiler') |
| 318 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 319 | |
| 320 | let l = getcompletion('last', 'help') |
| 321 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 322 | let l = getcompletion('giveup', 'help') |
| 323 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 324 | |
| 325 | let l = getcompletion('time', 'option') |
| 326 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 327 | let l = getcompletion('space', 'option') |
| 328 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 329 | |
| 330 | let l = getcompletion('er', 'highlight') |
| 331 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 332 | let l = getcompletion('dark', 'highlight') |
| 333 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 334 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 335 | let l = getcompletion('', 'messages') |
| 336 | call assert_true(index(l, 'clear') >= 0) |
| 337 | let l = getcompletion('not', 'messages') |
| 338 | call assert_equal([], l) |
| 339 | |
Bram Moolenaar | cae92dc | 2017-08-06 15:22:15 +0200 | [diff] [blame] | 340 | let l = getcompletion('', 'mapclear') |
| 341 | call assert_true(index(l, '<buffer>') >= 0) |
| 342 | let l = getcompletion('not', 'mapclear') |
| 343 | call assert_equal([], l) |
| 344 | |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 345 | let l = getcompletion('.', 'shellcmd') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 346 | call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 347 | call assert_equal(-1, match(l[2:], '^\.\.\?/$')) |
| 348 | let root = has('win32') ? 'C:\\' : '/' |
| 349 | let l = getcompletion(root, 'shellcmd') |
| 350 | let expected = map(filter(glob(root . '*', 0, 1), |
| 351 | \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') |
| 352 | call assert_equal(expected, l) |
| 353 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 354 | if has('cscope') |
| 355 | let l = getcompletion('', 'cscope') |
| 356 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 357 | call assert_equal(cmds, l) |
| 358 | " using cmdline completion must not change the result |
| 359 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 360 | let l = getcompletion('', 'cscope') |
| 361 | call assert_equal(cmds, l) |
| 362 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 363 | let l = getcompletion('find ', 'cscope') |
| 364 | call assert_equal(keys, l) |
| 365 | endif |
| 366 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 367 | if has('signs') |
| 368 | sign define Testing linehl=Comment |
| 369 | let l = getcompletion('', 'sign') |
| 370 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 371 | call assert_equal(cmds, l) |
| 372 | " using cmdline completion must not change the result |
| 373 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 374 | let l = getcompletion('', 'sign') |
| 375 | call assert_equal(cmds, l) |
| 376 | let l = getcompletion('list ', 'sign') |
| 377 | call assert_equal(['Testing'], l) |
| 378 | endif |
| 379 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 380 | " For others test if the name is recognized. |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 381 | let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 382 | if has('cmdline_hist') |
| 383 | call add(names, 'history') |
| 384 | endif |
| 385 | if has('gettext') |
| 386 | call add(names, 'locale') |
| 387 | endif |
| 388 | if has('profile') |
| 389 | call add(names, 'syntime') |
| 390 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 391 | |
| 392 | set tags=Xtags |
| 393 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 394 | |
| 395 | for name in names |
| 396 | let matchcount = len(getcompletion('', name)) |
| 397 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 398 | endfor |
| 399 | |
| 400 | call delete('Xtags') |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 401 | set tags& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 402 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 403 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
| 404 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 405 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 406 | func Test_shellcmd_completion() |
| 407 | let save_path = $PATH |
| 408 | |
| 409 | call mkdir('Xpathdir/Xpathsubdir', 'p') |
| 410 | call writefile([''], 'Xpathdir/Xfile.exe') |
| 411 | call setfperm('Xpathdir/Xfile.exe', 'rwx------') |
| 412 | |
| 413 | " Set PATH to example directory without trailing slash. |
| 414 | let $PATH = getcwd() . '/Xpathdir' |
| 415 | |
| 416 | " Test for the ":!<TAB>" case. Previously, this would include subdirs of |
| 417 | " dirs in the PATH, even though they won't be executed. We check that only |
| 418 | " subdirs of the PWD and executables from the PATH are included in the |
| 419 | " suggestions. |
| 420 | let actual = getcompletion('X', 'shellcmd') |
| 421 | let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') |
| 422 | call insert(expected, 'Xfile.exe') |
| 423 | call assert_equal(expected, actual) |
| 424 | |
| 425 | call delete('Xpathdir', 'rf') |
| 426 | let $PATH = save_path |
| 427 | endfunc |
| 428 | |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 429 | func Test_expand_star_star() |
| 430 | call mkdir('a/b', 'p') |
| 431 | call writefile(['asdfasdf'], 'a/b/fileXname') |
| 432 | call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') |
| 433 | call assert_equal('find a/b/fileXname', getreg(':')) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 434 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 435 | call delete('a', 'rf') |
| 436 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 437 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 438 | func Test_cmdline_paste() |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 439 | let @a = "def" |
| 440 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 441 | call assert_equal('"abc def ghi', @:) |
| 442 | |
| 443 | new |
| 444 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 445 | |
| 446 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 447 | call assert_equal('"aaa asdf bbb', @:) |
| 448 | |
| 449 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 450 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 451 | |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 452 | call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') |
| 453 | call assert_equal('"aaa '.getline(1).' bbb', @:) |
| 454 | |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 455 | set incsearch |
| 456 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 457 | call assert_equal('"aaa verylongword bbb', @:) |
| 458 | |
| 459 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 460 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 461 | |
| 462 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 463 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 464 | bwipe! |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 465 | |
| 466 | " Error while typing a command used to cause that it was not executed |
| 467 | " in the end. |
| 468 | new |
| 469 | try |
| 470 | call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') |
| 471 | catch /^Vim\%((\a\+)\)\=:E32/ |
| 472 | " ignore error E32 |
| 473 | endtry |
| 474 | call assert_equal("Xtestfile", bufname("%")) |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 475 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 476 | " Try to paste an invalid register using <C-R> |
| 477 | call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') |
| 478 | call assert_equal('"onetwo', @:) |
| 479 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 480 | " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 481 | let @a = "xy\<C-H>z" |
| 482 | call feedkeys(":\"\<C-R>a\<CR>", 'xt') |
| 483 | call assert_equal('"xz', @:) |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 484 | call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') |
| 485 | call assert_equal("\"xy\<C-H>z", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 486 | call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') |
| 487 | call assert_equal("\"xy\<C-H>z", @:) |
| 488 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 489 | " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R |
| 490 | let @a = "xy\<C-V>z" |
| 491 | call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') |
| 492 | call assert_equal('"xyz', @:) |
| 493 | call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') |
| 494 | call assert_equal("\"xy\<C-V>z", @:) |
| 495 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 496 | call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') |
| 497 | |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 498 | bwipe! |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 499 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 500 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 501 | func Test_cmdline_remove_char() |
| 502 | let encoding_save = &encoding |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 503 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 504 | for e in ['utf8', 'latin1'] |
| 505 | exe 'set encoding=' . e |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 506 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 507 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 508 | call assert_equal('"abc ef', @:, e) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 509 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 510 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 511 | call assert_equal('"abcdef', @:) |
| 512 | |
| 513 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 514 | call assert_equal('"abc ghi', @:, e) |
| 515 | |
| 516 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 517 | call assert_equal('"def', @:, e) |
| 518 | endfor |
| 519 | |
| 520 | let &encoding = encoding_save |
| 521 | endfunc |
| 522 | |
| 523 | func Test_cmdline_keymap_ctrl_hat() |
| 524 | if !has('keymap') |
| 525 | return |
| 526 | endif |
| 527 | |
| 528 | set keymap=esperanto |
| 529 | call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') |
| 530 | call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) |
| 531 | set keymap= |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 532 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 533 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 534 | func Test_illegal_address1() |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 535 | new |
| 536 | 2;'( |
| 537 | 2;') |
| 538 | quit |
| 539 | endfunc |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 540 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 541 | func Test_illegal_address2() |
| 542 | call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') |
| 543 | new |
| 544 | source Xtest.vim |
| 545 | " Trigger calling validate_cursor() |
| 546 | diffsp Xtest.vim |
| 547 | quit! |
| 548 | bwipe! |
| 549 | call delete('Xtest.vim') |
| 550 | endfunc |
| 551 | |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 552 | func Test_cmdline_complete_wildoptions() |
| 553 | help |
| 554 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 555 | let a = join(sort(split(@:)),' ') |
| 556 | set wildoptions=tagfile |
| 557 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 558 | let b = join(sort(split(@:)),' ') |
| 559 | call assert_equal(a, b) |
| 560 | bw! |
| 561 | endfunc |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 562 | |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 563 | func Test_cmdline_complete_user_cmd() |
| 564 | command! -complete=color -nargs=1 Foo : |
| 565 | call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') |
| 566 | call assert_equal('"Foo blue', @:) |
| 567 | call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') |
| 568 | call assert_equal('"Foo blue', @:) |
| 569 | delcommand Foo |
| 570 | endfunc |
| 571 | |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 572 | func s:ScriptLocalFunction() |
| 573 | echo 'yes' |
| 574 | endfunc |
| 575 | |
| 576 | func Test_cmdline_complete_user_func() |
| 577 | call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') |
| 578 | call assert_match('"func Test_cmdline_complete_user', @:) |
| 579 | call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') |
| 580 | call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) |
| 581 | endfunc |
| 582 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 583 | func Test_cmdline_complete_user_names() |
| 584 | if has('unix') && executable('whoami') |
| 585 | let whoami = systemlist('whoami')[0] |
| 586 | let first_letter = whoami[0] |
| 587 | if len(first_letter) > 0 |
| 588 | " Trying completion of :e ~x where x is the first letter of |
| 589 | " the user name should complete to at least the user name. |
| 590 | call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') |
| 591 | call assert_match('^"e \~.*\<' . whoami . '\>', @:) |
| 592 | endif |
| 593 | endif |
| 594 | if has('win32') |
| 595 | " Just in case: check that the system has an Administrator account. |
| 596 | let names = system('net user') |
| 597 | if names =~ 'Administrator' |
| 598 | " Trying completion of :e ~A should complete to Administrator. |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 599 | " There could be other names starting with "A" before Administrator. |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 600 | call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 601 | call assert_match('^"e \~.*Administrator', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 602 | endif |
| 603 | endif |
| 604 | endfunc |
| 605 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 606 | func Test_cmdline_complete_bang() |
| 607 | if executable('whoami') |
Bram Moolenaar | 731a799 | 2019-12-28 14:06:50 +0100 | [diff] [blame] | 608 | call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') |
| 609 | call assert_match('^".*\<whoami\>', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 610 | endif |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 611 | endfunc |
| 612 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 613 | funct Test_cmdline_complete_languages() |
| 614 | let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') |
| 615 | |
| 616 | call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') |
| 617 | call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) |
| 618 | |
| 619 | if has('unix') |
| 620 | " TODO: these tests don't work on Windows. lang appears to be 'C' |
| 621 | " but C does not appear in the completion. Why? |
| 622 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 623 | |
| 624 | call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') |
| 625 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 626 | |
| 627 | call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') |
| 628 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 629 | |
| 630 | call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') |
| 631 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 632 | endif |
| 633 | endfunc |
| 634 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 635 | func Test_cmdline_complete_env_variable() |
| 636 | let $X_VIM_TEST_COMPLETE_ENV = 'foo' |
| 637 | |
| 638 | call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') |
| 639 | call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) |
| 640 | |
| 641 | unlet $X_VIM_TEST_COMPLETE_ENV |
| 642 | endfunc |
| 643 | |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 644 | func Test_cmdline_write_alternatefile() |
| 645 | new |
| 646 | call setline('.', ['one', 'two']) |
| 647 | f foo.txt |
| 648 | new |
| 649 | f #-A |
| 650 | call assert_equal('foo.txt-A', expand('%')) |
| 651 | f #<-B.txt |
| 652 | call assert_equal('foo-B.txt', expand('%')) |
| 653 | f %< |
| 654 | call assert_equal('foo-B', expand('%')) |
| 655 | new |
| 656 | call assert_fails('f #<', 'E95') |
| 657 | bw! |
| 658 | f foo-B.txt |
| 659 | f %<-A |
| 660 | call assert_equal('foo-B-A', expand('%')) |
| 661 | bw! |
| 662 | bw! |
| 663 | endfunc |
| 664 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 665 | " using a leading backslash here |
| 666 | set cpo+=C |
| 667 | |
| 668 | func Test_cmdline_search_range() |
| 669 | new |
| 670 | call setline(1, ['a', 'b', 'c', 'd']) |
| 671 | /d |
| 672 | 1,\/s/b/B/ |
| 673 | call assert_equal('B', getline(2)) |
| 674 | |
| 675 | /a |
| 676 | $ |
| 677 | \?,4s/c/C/ |
| 678 | call assert_equal('C', getline(3)) |
| 679 | |
| 680 | call setline(1, ['a', 'b', 'c', 'd']) |
| 681 | %s/c/c/ |
| 682 | 1,\&s/b/B/ |
| 683 | call assert_equal('B', getline(2)) |
| 684 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 685 | let @/ = 'apple' |
| 686 | call assert_fails('\/print', 'E486:') |
| 687 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 688 | bwipe! |
| 689 | endfunc |
| 690 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 691 | " Test for the tick mark (') in an excmd range |
| 692 | func Test_tick_mark_in_range() |
| 693 | " If only the tick is passed as a range and no command is specified, there |
| 694 | " should not be an error |
| 695 | call feedkeys(":'\<CR>", 'xt') |
| 696 | call assert_equal("'", getreg(':')) |
| 697 | call assert_fails("',print", 'E78:') |
| 698 | endfunc |
| 699 | |
| 700 | " Test for using a line number followed by a search pattern as range |
| 701 | func Test_lnum_and_pattern_as_range() |
| 702 | new |
| 703 | call setline(1, ['foo 1', 'foo 2', 'foo 3']) |
| 704 | let @" = '' |
| 705 | 2/foo/yank |
| 706 | call assert_equal("foo 3\n", @") |
| 707 | call assert_equal(1, line('.')) |
| 708 | close! |
| 709 | endfunc |
| 710 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 711 | " Tests for getcmdline(), getcmdpos() and getcmdtype() |
| 712 | func Check_cmdline(cmdtype) |
| 713 | call assert_equal('MyCmd a', getcmdline()) |
| 714 | call assert_equal(8, getcmdpos()) |
| 715 | call assert_equal(a:cmdtype, getcmdtype()) |
| 716 | return '' |
| 717 | endfunc |
| 718 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 719 | set cpo& |
| 720 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 721 | func Test_getcmdtype() |
| 722 | call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") |
| 723 | |
| 724 | let cmdtype = '' |
| 725 | debuggreedy |
| 726 | call feedkeys(":debug echo 'test'\<CR>", "t") |
| 727 | call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") |
| 728 | call feedkeys("cont\<CR>", "xt") |
| 729 | 0debuggreedy |
| 730 | call assert_equal('>', cmdtype) |
| 731 | |
| 732 | call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") |
| 733 | call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") |
| 734 | |
| 735 | call feedkeys(":call input('Answer?')\<CR>", "t") |
Bram Moolenaar | 31eb139 | 2017-02-09 21:44:03 +0100 | [diff] [blame] | 736 | call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 737 | |
| 738 | call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") |
| 739 | |
| 740 | cnoremap <expr> <F6> Check_cmdline('=') |
| 741 | call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") |
| 742 | cunmap <F6> |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 743 | |
| 744 | call assert_equal('', getcmdline()) |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 745 | endfunc |
| 746 | |
Bram Moolenaar | 81612b7 | 2018-06-23 14:55:03 +0200 | [diff] [blame] | 747 | func Test_getcmdwintype() |
| 748 | call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 749 | call assert_equal('/', a) |
| 750 | |
| 751 | call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 752 | call assert_equal('?', a) |
| 753 | |
| 754 | call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 755 | call assert_equal(':', a) |
| 756 | |
| 757 | call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 758 | call assert_equal(':', a) |
| 759 | |
| 760 | call assert_equal('', getcmdwintype()) |
| 761 | endfunc |
| 762 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 763 | func Test_getcmdwin_autocmd() |
| 764 | let s:seq = [] |
| 765 | augroup CmdWin |
| 766 | au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) |
| 767 | au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) |
| 768 | au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) |
| 769 | au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) |
| 770 | au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) |
| 771 | au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) |
| 772 | |
| 773 | let org_winid = win_getid() |
| 774 | let org_bufnr = bufnr() |
| 775 | call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') |
| 776 | call assert_equal(':', a) |
| 777 | call assert_equal([ |
| 778 | \ 'WinLeave ' .. org_winid, |
| 779 | \ 'WinEnter ' .. s:cmd_winid, |
| 780 | \ 'BufLeave ' .. org_bufnr, |
| 781 | \ 'BufEnter ' .. s:cmd_bufnr, |
| 782 | \ 'CmdWinEnter ' .. s:cmd_winid, |
| 783 | \ 'CmdWinLeave ' .. s:cmd_winid, |
| 784 | \ 'BufLeave ' .. s:cmd_bufnr, |
| 785 | \ 'WinLeave ' .. s:cmd_winid, |
| 786 | \ 'WinEnter ' .. org_winid, |
| 787 | \ 'BufEnter ' .. org_bufnr, |
| 788 | \ ], s:seq) |
| 789 | |
| 790 | au! |
| 791 | augroup END |
| 792 | endfunc |
| 793 | |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 794 | func Test_verbosefile() |
| 795 | set verbosefile=Xlog |
| 796 | echomsg 'foo' |
| 797 | echomsg 'bar' |
| 798 | set verbosefile= |
| 799 | let log = readfile('Xlog') |
| 800 | call assert_match("foo\nbar", join(log, "\n")) |
| 801 | call delete('Xlog') |
| 802 | endfunc |
| 803 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 804 | func Test_verbose_option() |
| 805 | CheckScreendump |
| 806 | |
| 807 | let lines =<< trim [SCRIPT] |
| 808 | command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v |
| 809 | call feedkeys("\r", 't') " for the hit-enter prompt |
| 810 | set verbose=20 |
| 811 | [SCRIPT] |
| 812 | call writefile(lines, 'XTest_verbose') |
| 813 | |
| 814 | let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) |
| 815 | call term_wait(buf, 100) |
| 816 | call term_sendkeys(buf, ":DoSomething\<CR>") |
| 817 | call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) |
| 818 | |
| 819 | " clean up |
| 820 | call StopVimInTerminal(buf) |
| 821 | call delete('XTest_verbose') |
| 822 | endfunc |
| 823 | |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 824 | func Test_setcmdpos() |
| 825 | func InsertTextAtPos(text, pos) |
| 826 | call assert_equal(0, setcmdpos(a:pos)) |
| 827 | return a:text |
| 828 | endfunc |
| 829 | |
| 830 | " setcmdpos() with position in the middle of the command line. |
| 831 | call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 832 | call assert_equal('"1ab2', @:) |
| 833 | |
| 834 | call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 835 | call assert_equal('"1b2a', @:) |
| 836 | |
| 837 | " setcmdpos() with position beyond the end of the command line. |
| 838 | call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') |
| 839 | call assert_equal('"12ab', @:) |
| 840 | |
| 841 | " setcmdpos() returns 1 when not editing the command line. |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 842 | call assert_equal(1, 3->setcmdpos()) |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 843 | endfunc |
| 844 | |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 845 | func Test_cmdline_overstrike() |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 846 | let encodings = ['latin1', 'utf8'] |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 847 | let encoding_save = &encoding |
| 848 | |
| 849 | for e in encodings |
| 850 | exe 'set encoding=' . e |
| 851 | |
| 852 | " Test overstrike in the middle of the command line. |
| 853 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 854 | call assert_equal('"0ab1cd4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 855 | |
| 856 | " Test overstrike going beyond end of command line. |
| 857 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 858 | call assert_equal('"0ab1cdefgh', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 859 | |
| 860 | " Test toggling insert/overstrike a few times. |
| 861 | 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] | 862 | call assert_equal('"ab0cd3ef4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 863 | endfor |
| 864 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 865 | " Test overstrike with multi-byte characters. |
| 866 | call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 867 | call assert_equal('"テabキcdエディタ', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 868 | |
| 869 | let &encoding = encoding_save |
| 870 | endfunc |
Bram Moolenaar | a046b37 | 2019-09-15 17:26:07 +0200 | [diff] [blame] | 871 | |
| 872 | func Test_cmdwin_bug() |
| 873 | let winid = win_getid() |
| 874 | sp |
| 875 | try |
| 876 | call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') |
| 877 | catch /^Vim\%((\a\+)\)\=:E11/ |
| 878 | endtry |
| 879 | bw! |
| 880 | endfunc |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 881 | |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 882 | func Test_cmdwin_restore() |
| 883 | CheckScreendump |
| 884 | |
| 885 | let lines =<< trim [SCRIPT] |
| 886 | call setline(1, range(30)) |
| 887 | 2split |
| 888 | [SCRIPT] |
| 889 | call writefile(lines, 'XTest_restore') |
| 890 | |
| 891 | let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) |
| 892 | call term_wait(buf, 100) |
| 893 | call term_sendkeys(buf, "q:") |
| 894 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) |
| 895 | |
| 896 | " normal restore |
| 897 | call term_sendkeys(buf, ":q\<CR>") |
| 898 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) |
| 899 | |
| 900 | " restore after setting 'lines' with one window |
| 901 | call term_sendkeys(buf, ":close\<CR>") |
| 902 | call term_sendkeys(buf, "q:") |
| 903 | call term_sendkeys(buf, ":set lines=18\<CR>") |
| 904 | call term_sendkeys(buf, ":q\<CR>") |
| 905 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) |
| 906 | |
| 907 | " clean up |
| 908 | call StopVimInTerminal(buf) |
| 909 | call delete('XTest_restore') |
| 910 | endfunc |
| 911 | |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 912 | func Test_buffers_lastused() |
| 913 | " check that buffers are sorted by time when wildmode has lastused |
| 914 | call test_settime(1550020000) " middle |
| 915 | edit bufa |
| 916 | enew |
| 917 | call test_settime(1550030000) " newest |
| 918 | edit bufb |
| 919 | enew |
| 920 | call test_settime(1550010000) " oldest |
| 921 | edit bufc |
| 922 | enew |
| 923 | call test_settime(0) |
| 924 | enew |
| 925 | |
| 926 | call assert_equal(['bufa', 'bufb', 'bufc'], |
| 927 | \ getcompletion('', 'buffer')) |
| 928 | |
| 929 | let save_wildmode = &wildmode |
| 930 | set wildmode=full:lastused |
| 931 | |
| 932 | let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" |
| 933 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 934 | call assert_equal('b bufb', X) |
| 935 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 936 | call assert_equal('b bufa', X) |
| 937 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 938 | call assert_equal('b bufc', X) |
| 939 | enew |
| 940 | |
| 941 | edit other |
| 942 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 943 | call assert_equal('b bufb', X) |
| 944 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 945 | call assert_equal('b bufa', X) |
| 946 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 947 | call assert_equal('b bufc', X) |
| 948 | enew |
| 949 | |
| 950 | let &wildmode = save_wildmode |
| 951 | |
| 952 | bwipeout bufa |
| 953 | bwipeout bufb |
| 954 | bwipeout bufc |
| 955 | endfunc |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 956 | |
| 957 | func Test_cmdwin_feedkeys() |
| 958 | " This should not generate E488 |
| 959 | call feedkeys("q:\<CR>", 'x') |
| 960 | endfunc |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 961 | |
| 962 | " Tests for the issues fixed in 7.4.441. |
| 963 | " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim |
| 964 | func Test_cmdwin_cedit() |
| 965 | exe "set cedit=\<C-c>" |
| 966 | normal! : |
| 967 | call assert_equal(1, winnr('$')) |
| 968 | |
| 969 | let g:cmd_wintype = '' |
| 970 | func CmdWinType() |
| 971 | let g:cmd_wintype = getcmdwintype() |
Bram Moolenaar | 00f3b4e | 2020-02-14 14:32:22 +0100 | [diff] [blame] | 972 | let g:wintype = win_gettype() |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 973 | return '' |
| 974 | endfunc |
| 975 | |
| 976 | call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") |
| 977 | echo input('') |
| 978 | call assert_equal('@', g:cmd_wintype) |
Bram Moolenaar | 00f3b4e | 2020-02-14 14:32:22 +0100 | [diff] [blame] | 979 | call assert_equal('command', g:wintype) |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 980 | |
| 981 | set cedit&vim |
| 982 | delfunc CmdWinType |
| 983 | endfunc |
| 984 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 985 | " Test for CmdwinEnter autocmd |
| 986 | func Test_cmdwin_autocmd() |
| 987 | augroup CmdWin |
| 988 | au! |
| 989 | autocmd CmdwinEnter * startinsert |
| 990 | augroup END |
| 991 | |
| 992 | call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') |
| 993 | call assert_equal('xyz', @:) |
| 994 | |
| 995 | augroup CmdWin |
| 996 | au! |
| 997 | augroup END |
| 998 | augroup! CmdWin |
| 999 | endfunc |
| 1000 | |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 1001 | func Test_cmdlineclear_tabenter() |
| 1002 | CheckScreendump |
| 1003 | |
| 1004 | let lines =<< trim [SCRIPT] |
| 1005 | call setline(1, range(30)) |
| 1006 | [SCRIPT] |
| 1007 | |
| 1008 | call writefile(lines, 'XtestCmdlineClearTabenter') |
| 1009 | let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) |
| 1010 | call term_wait(buf, 50) |
| 1011 | " in one tab make the command line higher with CTRL-W - |
| 1012 | call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") |
| 1013 | call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) |
| 1014 | |
| 1015 | call StopVimInTerminal(buf) |
| 1016 | call delete('XtestCmdlineClearTabenter') |
| 1017 | endfunc |
| 1018 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1019 | " Test for failure in expanding special keywords in cmdline |
| 1020 | func Test_cmdline_expand_special() |
| 1021 | %bwipe! |
| 1022 | call assert_fails('e #', 'E499:') |
| 1023 | call assert_fails('e <afile>', 'E495:') |
| 1024 | call assert_fails('e <abuf>', 'E496:') |
| 1025 | call assert_fails('e <amatch>', 'E497:') |
| 1026 | endfunc |
| 1027 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1028 | func Test_cmdwin_jump_to_win() |
| 1029 | call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') |
| 1030 | new |
| 1031 | set modified |
| 1032 | call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:') |
| 1033 | close! |
| 1034 | call feedkeys("q/:close\<CR>", "xt") |
| 1035 | call assert_equal(1, winnr('$')) |
| 1036 | call feedkeys("q/:exit\<CR>", "xt") |
| 1037 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1038 | |
| 1039 | " opening command window twice should fail |
| 1040 | call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') |
| 1041 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1042 | endfunc |
| 1043 | |
| 1044 | " Test for backtick expression in the command line |
| 1045 | func Test_cmd_backtick() |
| 1046 | %argd |
| 1047 | argadd `=['a', 'b', 'c']` |
| 1048 | call assert_equal(['a', 'b', 'c'], argv()) |
| 1049 | %argd |
| 1050 | endfunc |
| 1051 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 1052 | " Test for the :! command |
| 1053 | func Test_cmd_bang() |
| 1054 | if !has('unix') |
| 1055 | return |
| 1056 | endif |
| 1057 | |
| 1058 | let lines =<< trim [SCRIPT] |
| 1059 | " Test for no previous command |
| 1060 | call assert_fails('!!', 'E34:') |
| 1061 | set nomore |
| 1062 | " Test for cmdline expansion with :! |
| 1063 | call setline(1, 'foo!') |
| 1064 | silent !echo <cWORD> > Xfile.out |
| 1065 | call assert_equal(['foo!'], readfile('Xfile.out')) |
| 1066 | " Test for using previous command |
| 1067 | silent !echo \! ! |
| 1068 | call assert_equal(['! echo foo!'], readfile('Xfile.out')) |
| 1069 | call writefile(v:errors, 'Xresult') |
| 1070 | call delete('Xfile.out') |
| 1071 | qall! |
| 1072 | [SCRIPT] |
| 1073 | call writefile(lines, 'Xscript') |
| 1074 | if RunVim([], [], '--clean -S Xscript') |
| 1075 | call assert_equal([], readfile('Xresult')) |
| 1076 | endif |
| 1077 | call delete('Xscript') |
| 1078 | call delete('Xresult') |
| 1079 | endfunc |
| 1080 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1081 | " Test for using ~ for home directory in cmdline completion matches |
| 1082 | func Test_cmdline_expand_home() |
| 1083 | call mkdir('Xdir') |
| 1084 | call writefile([], 'Xdir/Xfile1') |
| 1085 | call writefile([], 'Xdir/Xfile2') |
| 1086 | cd Xdir |
| 1087 | let save_HOME = $HOME |
| 1088 | let $HOME = getcwd() |
| 1089 | call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1090 | call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) |
| 1091 | let $HOME = save_HOME |
| 1092 | cd .. |
| 1093 | call delete('Xdir', 'rf') |
| 1094 | endfunc |
| 1095 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1096 | " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode |
| 1097 | " or insert mode (when 'insertmode' is set) |
| 1098 | func Test_cmdline_ctrl_g() |
| 1099 | new |
| 1100 | call setline(1, 'abc') |
| 1101 | call cursor(1, 3) |
| 1102 | " If command line is entered from insert mode, using C-\ C-G should back to |
| 1103 | " insert mode |
| 1104 | call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') |
| 1105 | call assert_equal('abxyc', getline(1)) |
| 1106 | call assert_equal(4, col('.')) |
| 1107 | |
| 1108 | " If command line is entered in 'insertmode', using C-\ C-G should back to |
| 1109 | " 'insertmode' |
| 1110 | call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') |
| 1111 | call assert_equal('ab12xyc', getline(1)) |
| 1112 | close! |
| 1113 | endfunc |
| 1114 | |
| 1115 | " Return the 'len' characters in screen starting from (row,col) |
| 1116 | func s:ScreenLine(row, col, len) |
| 1117 | let s = '' |
| 1118 | for i in range(a:len) |
| 1119 | let s .= nr2char(screenchar(a:row, a:col + i)) |
| 1120 | endfor |
| 1121 | return s |
| 1122 | endfunc |
| 1123 | |
| 1124 | " Test for 'wildmode' |
| 1125 | func Test_wildmode() |
| 1126 | func T(a, c, p) |
| 1127 | return "oneA\noneB\noneC" |
| 1128 | endfunc |
| 1129 | command -nargs=1 -complete=custom,T MyCmd |
| 1130 | |
| 1131 | func SaveScreenLine() |
| 1132 | let g:Sline = s:ScreenLine(&lines - 1, 1, 20) |
| 1133 | return '' |
| 1134 | endfunc |
| 1135 | cnoremap <expr> <F2> SaveScreenLine() |
| 1136 | |
| 1137 | set nowildmenu |
| 1138 | set wildmode=full,list |
| 1139 | let g:Sline = '' |
| 1140 | call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') |
| 1141 | call assert_equal('oneA oneB oneC ', g:Sline) |
| 1142 | call assert_equal('"MyCmd oneA', @:) |
| 1143 | |
| 1144 | set wildmode=longest,full |
| 1145 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 1146 | call assert_equal('"MyCmd one', @:) |
| 1147 | call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') |
| 1148 | call assert_equal('"MyCmd oneC', @:) |
| 1149 | |
| 1150 | set wildmode=longest |
| 1151 | call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') |
| 1152 | call assert_equal('"MyCmd one', @:) |
| 1153 | |
| 1154 | set wildmode=list:longest |
| 1155 | let g:Sline = '' |
| 1156 | call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') |
| 1157 | call assert_equal('oneA oneB oneC ', g:Sline) |
| 1158 | call assert_equal('"MyCmd one', @:) |
| 1159 | |
| 1160 | set wildmode="" |
| 1161 | call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') |
| 1162 | call assert_equal('"MyCmd oneA', @:) |
| 1163 | |
| 1164 | delcommand MyCmd |
| 1165 | delfunc T |
| 1166 | delfunc SaveScreenLine |
| 1167 | cunmap <F2> |
| 1168 | set wildmode& |
| 1169 | endfunc |
| 1170 | |
| 1171 | " Test for interrupting the command-line completion |
| 1172 | func Test_interrupt_compl() |
| 1173 | func F(lead, cmdl, p) |
| 1174 | if a:lead =~ 'tw' |
| 1175 | call interrupt() |
| 1176 | return |
| 1177 | endif |
| 1178 | return "one\ntwo\nthree" |
| 1179 | endfunc |
| 1180 | command -nargs=1 -complete=custom,F Tcmd |
| 1181 | |
| 1182 | set nowildmenu |
| 1183 | set wildmode=full |
| 1184 | let interrupted = 0 |
| 1185 | try |
| 1186 | call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1187 | catch /^Vim:Interrupt$/ |
| 1188 | let interrupted = 1 |
| 1189 | endtry |
| 1190 | call assert_equal(1, interrupted) |
| 1191 | |
| 1192 | delcommand Tcmd |
| 1193 | delfunc F |
| 1194 | set wildmode& |
| 1195 | endfunc |
| 1196 | |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1197 | " Test for moving the cursor on the : command line |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1198 | func Test_cmdline_edit() |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1199 | let str = ":one two\<C-U>" |
| 1200 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1201 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1202 | let str ..= "\<Left>five\<Right>" |
| 1203 | let str ..= "\<Home>two " |
| 1204 | let str ..= "\<C-Left>one " |
| 1205 | let str ..= "\<C-Right> three" |
| 1206 | let str ..= "\<End>\<S-Left>four " |
| 1207 | let str ..= "\<S-Right> six" |
| 1208 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 1209 | call feedkeys(str, 'xt') |
| 1210 | call assert_equal("\"one two three four five six seven", @:) |
| 1211 | endfunc |
| 1212 | |
| 1213 | " Test for moving the cursor on the / command line in 'rightleft' mode |
| 1214 | func Test_cmdline_edit_rightleft() |
| 1215 | CheckFeature rightleft |
| 1216 | set rightleft |
| 1217 | set rightleftcmd=search |
| 1218 | let str = "/one two\<C-U>" |
| 1219 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1220 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1221 | let str ..= "\<Right>five\<Left>" |
| 1222 | let str ..= "\<Home>two " |
| 1223 | let str ..= "\<C-Right>one " |
| 1224 | let str ..= "\<C-Left> three" |
| 1225 | let str ..= "\<End>\<S-Right>four " |
| 1226 | let str ..= "\<S-Left> six" |
| 1227 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 1228 | call assert_fails("call feedkeys(str, 'xt')", 'E486:') |
| 1229 | call assert_equal("\"one two three four five six seven", @/) |
| 1230 | set rightleftcmd& |
| 1231 | set rightleft& |
| 1232 | endfunc |
| 1233 | |
| 1234 | " Test for using <C-\>e in the command line to evaluate an expression |
| 1235 | func Test_cmdline_expr() |
| 1236 | " Evaluate an expression from the beginning of a command line |
| 1237 | call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') |
| 1238 | call assert_equal('"hello', @:) |
| 1239 | |
| 1240 | " Use an invalid expression for <C-\>e |
| 1241 | call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') |
| 1242 | |
| 1243 | " Insert literal <CTRL-\> in the command line |
| 1244 | call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') |
| 1245 | call assert_equal("\"e \<C-\>\<C-Y>", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1246 | endfunc |
| 1247 | |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 1248 | " Test for 'imcmdline' and 'imsearch' |
| 1249 | " This test doesn't actually test the input method functionality. |
| 1250 | func Test_cmdline_inputmethod() |
| 1251 | new |
| 1252 | call setline(1, ['', 'abc', '']) |
| 1253 | set imcmdline |
| 1254 | |
| 1255 | call feedkeys(":\"abc\<CR>", 'xt') |
| 1256 | call assert_equal("\"abc", @:) |
| 1257 | call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1258 | call assert_equal("\"abc", @:) |
| 1259 | call feedkeys("/abc\<CR>", 'xt') |
| 1260 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1261 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1262 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1263 | |
| 1264 | set imsearch=2 |
| 1265 | call cursor(1, 1) |
| 1266 | call feedkeys("/abc\<CR>", 'xt') |
| 1267 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1268 | call cursor(1, 1) |
| 1269 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1270 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1271 | set imdisable |
| 1272 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1273 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1274 | set imdisable& |
| 1275 | set imsearch& |
| 1276 | |
| 1277 | set imcmdline& |
| 1278 | %bwipe! |
| 1279 | endfunc |
| 1280 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1281 | " Test for opening the command-line window when too many windows are present |
| 1282 | func Test_cmdwin_fail_to_open() |
| 1283 | " Open as many windows as possible |
| 1284 | for i in range(100) |
| 1285 | try |
| 1286 | new |
| 1287 | catch /E36:/ |
| 1288 | break |
| 1289 | endtry |
| 1290 | endfor |
| 1291 | call assert_beeps('call feedkeys("q:\<CR>", "xt")') |
| 1292 | only |
| 1293 | endfunc |
| 1294 | |
| 1295 | " Test for recursively getting multiple command line inputs |
| 1296 | func Test_cmdwin_multi_input() |
| 1297 | call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') |
| 1298 | call assert_equal('"cyan', @:) |
| 1299 | endfunc |
| 1300 | |
| 1301 | " Test for using CTRL-_ in the command line with 'allowrevins' |
| 1302 | func Test_cmdline_revins() |
| 1303 | CheckNotMSWindows |
| 1304 | CheckFeature rightleft |
| 1305 | call feedkeys(":\"abc\<c-_>\<cr>", 'xt') |
| 1306 | call assert_equal("\"abc\<c-_>", @:) |
| 1307 | set allowrevins |
| 1308 | call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') |
| 1309 | call assert_equal('"abcñèæ', @:) |
| 1310 | set allowrevins& |
| 1311 | endfunc |
| 1312 | |
| 1313 | " Test for typing UTF-8 composing characters in the command line |
| 1314 | func Test_cmdline_composing_chars() |
| 1315 | call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') |
| 1316 | call assert_equal('"ゔ', @:) |
| 1317 | endfunc |
| 1318 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 1319 | " vim: shiftwidth=2 sts=2 expandtab |