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