Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 1 | " Tests for editing the command line. |
| 2 | |
| 3 | func Test_complete_tab() |
| 4 | call writefile(['testfile'], 'Xtestfile') |
| 5 | call feedkeys(":e Xtest\t\r", "tx") |
| 6 | call assert_equal('testfile', getline(1)) |
| 7 | call delete('Xtestfile') |
| 8 | endfunc |
| 9 | |
| 10 | func Test_complete_list() |
| 11 | " We can't see the output, but at least we check the code runs properly. |
| 12 | call feedkeys(":e test\<C-D>\r", "tx") |
| 13 | call assert_equal('test', expand('%:t')) |
| 14 | endfunc |
| 15 | |
| 16 | func Test_complete_wildmenu() |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 17 | call mkdir('Xdir1/Xdir2', 'p') |
| 18 | call writefile(['testfile1'], 'Xdir1/Xtestfile1') |
| 19 | call writefile(['testfile2'], 'Xdir1/Xtestfile2') |
| 20 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') |
| 21 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 22 | set wildmenu |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 23 | |
| 24 | " Pressing <Tab> completes, and moves to next files when pressing again. |
| 25 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') |
| 26 | call assert_equal('testfile1', getline(1)) |
| 27 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 28 | call assert_equal('testfile2', getline(1)) |
| 29 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 30 | " <S-Tab> is like <Tab> but begin with the last match and then go to |
| 31 | " previous. |
| 32 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') |
| 33 | call assert_equal('testfile2', getline(1)) |
| 34 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') |
| 35 | call assert_equal('testfile1', getline(1)) |
| 36 | |
| 37 | " <Left>/<Right> to move to previous/next file. |
| 38 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') |
| 39 | call assert_equal('testfile1', getline(1)) |
| 40 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') |
| 41 | call assert_equal('testfile2', getline(1)) |
| 42 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') |
| 43 | call assert_equal('testfile1', getline(1)) |
| 44 | |
| 45 | " <Up>/<Down> to go up/down directories. |
| 46 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') |
| 47 | call assert_equal('testfile3', getline(1)) |
| 48 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') |
| 49 | call assert_equal('testfile1', getline(1)) |
| 50 | |
| 51 | " cleanup |
| 52 | %bwipe |
| 53 | call delete('Xdir1/Xdir2/Xtestfile4') |
| 54 | call delete('Xdir1/Xdir2/Xtestfile3') |
| 55 | call delete('Xdir1/Xtestfile2') |
| 56 | call delete('Xdir1/Xtestfile1') |
| 57 | call delete('Xdir1/Xdir2', 'd') |
| 58 | call delete('Xdir1', 'd') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 59 | set nowildmenu |
| 60 | endfunc |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 61 | |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 62 | func Test_map_completion() |
| 63 | if !has('cmdline_compl') |
| 64 | return |
| 65 | endif |
| 66 | call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') |
| 67 | call assert_equal('"map <unique> <silent>', getreg(':')) |
| 68 | call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') |
| 69 | call assert_equal('"map <script> <unique>', getreg(':')) |
| 70 | call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') |
| 71 | call assert_equal('"map <expr> <script>', getreg(':')) |
| 72 | call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') |
| 73 | call assert_equal('"map <buffer> <expr>', getreg(':')) |
| 74 | call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') |
| 75 | call assert_equal('"map <nowait> <buffer>', getreg(':')) |
| 76 | call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') |
| 77 | call assert_equal('"map <special> <nowait>', getreg(':')) |
| 78 | call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') |
| 79 | call assert_equal('"map <silent> <special>', getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 80 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 81 | map <Middle>x middle |
| 82 | |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 83 | map ,f commaf |
| 84 | map ,g commaf |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 85 | map <Left> left |
| 86 | map <A-Left>x shiftleft |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 87 | call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') |
| 88 | call assert_equal('"map ,f', getreg(':')) |
| 89 | call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') |
| 90 | call assert_equal('"map ,g', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 91 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 92 | call assert_equal('"map <Left>', getreg(':')) |
| 93 | call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 94 | call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 95 | unmap ,f |
| 96 | unmap ,g |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 97 | unmap <Left> |
| 98 | unmap <A-Left>x |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 99 | |
| 100 | set cpo-=< cpo-=B cpo-=k |
| 101 | map <Left> left |
| 102 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 103 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 104 | call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 105 | call assert_equal("\"map <M\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 106 | unmap <Left> |
| 107 | |
| 108 | set cpo+=< |
| 109 | map <Left> left |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 110 | exe "set t_k6=\<Esc>[17~" |
| 111 | call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 112 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 113 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 510671a | 2019-05-04 19:26:56 +0200 | [diff] [blame] | 114 | if !has('gui_running') |
| 115 | call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') |
| 116 | call assert_equal("\"map <F6>x", getreg(':')) |
| 117 | endif |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 118 | unmap <Left> |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 119 | call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 120 | set cpo-=< |
| 121 | |
| 122 | set cpo+=B |
| 123 | map <Left> left |
| 124 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 125 | call assert_equal('"map <Left>', getreg(':')) |
| 126 | unmap <Left> |
| 127 | set cpo-=B |
| 128 | |
| 129 | set cpo+=k |
| 130 | map <Left> left |
| 131 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 132 | call assert_equal('"map <Left>', getreg(':')) |
| 133 | unmap <Left> |
| 134 | set cpo-=k |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 135 | |
| 136 | unmap <Middle>x |
| 137 | set cpo&vim |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 138 | endfunc |
| 139 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 140 | func Test_match_completion() |
| 141 | if !has('cmdline_compl') |
| 142 | return |
| 143 | endif |
| 144 | hi Aardig ctermfg=green |
| 145 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
| 146 | call assert_equal('"match Aardig', getreg(':')) |
| 147 | call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') |
| 148 | call assert_equal('"match none', getreg(':')) |
| 149 | endfunc |
| 150 | |
| 151 | func Test_highlight_completion() |
| 152 | if !has('cmdline_compl') |
| 153 | return |
| 154 | endif |
| 155 | hi Aardig ctermfg=green |
| 156 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 157 | call assert_equal('"hi Aardig', getreg(':')) |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 158 | call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') |
| 159 | call assert_equal('"hi default Aardig', getreg(':')) |
| 160 | call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 161 | call assert_equal('"hi clear Aardig', getreg(':')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 162 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 163 | call assert_equal('"hi link', getreg(':')) |
| 164 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 165 | call assert_equal('"hi default', getreg(':')) |
| 166 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 167 | call assert_equal('"hi clear', getreg(':')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 168 | |
| 169 | " A cleared group does not show up in completions. |
| 170 | hi Anders ctermfg=green |
| 171 | call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) |
| 172 | hi clear Aardig |
| 173 | call assert_equal(['Anders'], getcompletion('A', 'highlight')) |
| 174 | hi clear Anders |
| 175 | call assert_equal([], getcompletion('A', 'highlight')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 176 | endfunc |
| 177 | |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 178 | func Test_expr_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 179 | if !has('cmdline_compl') |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 180 | return |
| 181 | endif |
| 182 | for cmd in [ |
| 183 | \ 'let a = ', |
| 184 | \ 'if', |
| 185 | \ 'elseif', |
| 186 | \ 'while', |
| 187 | \ 'for', |
| 188 | \ 'echo', |
| 189 | \ 'echon', |
| 190 | \ 'execute', |
| 191 | \ 'echomsg', |
| 192 | \ 'echoerr', |
| 193 | \ 'call', |
| 194 | \ 'return', |
| 195 | \ 'cexpr', |
| 196 | \ 'caddexpr', |
| 197 | \ 'cgetexpr', |
| 198 | \ 'lexpr', |
| 199 | \ 'laddexpr', |
| 200 | \ 'lgetexpr'] |
| 201 | call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') |
| 202 | call assert_equal('"' . cmd . ' getline(', getreg(':')) |
| 203 | endfor |
| 204 | endfunc |
| 205 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 206 | func Test_getcompletion() |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 207 | if !has('cmdline_compl') |
| 208 | return |
| 209 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 210 | let groupcount = len(getcompletion('', 'event')) |
| 211 | call assert_true(groupcount > 0) |
| 212 | let matchcount = len(getcompletion('File', 'event')) |
| 213 | call assert_true(matchcount > 0) |
| 214 | call assert_true(groupcount > matchcount) |
| 215 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 216 | if has('menu') |
| 217 | source $VIMRUNTIME/menu.vim |
| 218 | let matchcount = len(getcompletion('', 'menu')) |
| 219 | call assert_true(matchcount > 0) |
| 220 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 221 | call assert_true(matchcount > 0) |
| 222 | let matchcount = len(getcompletion('File.', 'menu')) |
| 223 | call assert_true(matchcount > 0) |
| 224 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 225 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 226 | let l = getcompletion('v:n', 'var') |
| 227 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 228 | let l = getcompletion('v:notexists', 'var') |
| 229 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 230 | |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 231 | args a.c b.c |
| 232 | let l = getcompletion('', 'arglist') |
| 233 | call assert_equal(['a.c', 'b.c'], l) |
| 234 | %argdelete |
| 235 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 236 | let l = getcompletion('', 'augroup') |
| 237 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 238 | let l = getcompletion('blahblah', 'augroup') |
| 239 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 240 | |
| 241 | let l = getcompletion('', 'behave') |
| 242 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 243 | let l = getcompletion('not', 'behave') |
| 244 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 245 | |
| 246 | let l = getcompletion('', 'color') |
| 247 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 248 | let l = getcompletion('dirty', 'color') |
| 249 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 250 | |
| 251 | let l = getcompletion('', 'command') |
| 252 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 253 | let l = getcompletion('awake', 'command') |
| 254 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 255 | |
| 256 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 257 | call assert_true(index(l, 'samples/') >= 0) |
| 258 | let l = getcompletion('NoMatch', 'dir') |
| 259 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 260 | |
| 261 | let l = getcompletion('exe', 'expression') |
| 262 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 263 | let l = getcompletion('kill', 'expression') |
| 264 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 265 | |
| 266 | let l = getcompletion('tag', 'function') |
| 267 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 268 | let l = getcompletion('paint', 'function') |
| 269 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 270 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 271 | let Flambda = {-> 'hello'} |
| 272 | let l = getcompletion('', 'function') |
| 273 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 274 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 275 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 276 | let l = getcompletion('run', 'file') |
| 277 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 278 | let l = getcompletion('walk', 'file') |
| 279 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 280 | set wildignore=*.vim |
| 281 | let l = getcompletion('run', 'file', 1) |
| 282 | call assert_true(index(l, 'runtest.vim') < 0) |
| 283 | set wildignore& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 284 | |
| 285 | let l = getcompletion('ha', 'filetype') |
| 286 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 287 | let l = getcompletion('horse', 'filetype') |
| 288 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 289 | |
| 290 | let l = getcompletion('z', 'syntax') |
| 291 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 292 | let l = getcompletion('emacs', 'syntax') |
| 293 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 294 | |
| 295 | let l = getcompletion('jikes', 'compiler') |
| 296 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 297 | let l = getcompletion('break', 'compiler') |
| 298 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 299 | |
| 300 | let l = getcompletion('last', 'help') |
| 301 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 302 | let l = getcompletion('giveup', 'help') |
| 303 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 304 | |
| 305 | let l = getcompletion('time', 'option') |
| 306 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 307 | let l = getcompletion('space', 'option') |
| 308 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 309 | |
| 310 | let l = getcompletion('er', 'highlight') |
| 311 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 312 | let l = getcompletion('dark', 'highlight') |
| 313 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 314 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 315 | let l = getcompletion('', 'messages') |
| 316 | call assert_true(index(l, 'clear') >= 0) |
| 317 | let l = getcompletion('not', 'messages') |
| 318 | call assert_equal([], l) |
| 319 | |
Bram Moolenaar | cae92dc | 2017-08-06 15:22:15 +0200 | [diff] [blame] | 320 | let l = getcompletion('', 'mapclear') |
| 321 | call assert_true(index(l, '<buffer>') >= 0) |
| 322 | let l = getcompletion('not', 'mapclear') |
| 323 | call assert_equal([], l) |
| 324 | |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 325 | let l = getcompletion('.', 'shellcmd') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 326 | call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 327 | call assert_equal(-1, match(l[2:], '^\.\.\?/$')) |
| 328 | let root = has('win32') ? 'C:\\' : '/' |
| 329 | let l = getcompletion(root, 'shellcmd') |
| 330 | let expected = map(filter(glob(root . '*', 0, 1), |
| 331 | \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') |
| 332 | call assert_equal(expected, l) |
| 333 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 334 | if has('cscope') |
| 335 | let l = getcompletion('', 'cscope') |
| 336 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 337 | call assert_equal(cmds, l) |
| 338 | " using cmdline completion must not change the result |
| 339 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 340 | let l = getcompletion('', 'cscope') |
| 341 | call assert_equal(cmds, l) |
| 342 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 343 | let l = getcompletion('find ', 'cscope') |
| 344 | call assert_equal(keys, l) |
| 345 | endif |
| 346 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 347 | if has('signs') |
| 348 | sign define Testing linehl=Comment |
| 349 | let l = getcompletion('', 'sign') |
| 350 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 351 | call assert_equal(cmds, l) |
| 352 | " using cmdline completion must not change the result |
| 353 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 354 | let l = getcompletion('', 'sign') |
| 355 | call assert_equal(cmds, l) |
| 356 | let l = getcompletion('list ', 'sign') |
| 357 | call assert_equal(['Testing'], l) |
| 358 | endif |
| 359 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 360 | " For others test if the name is recognized. |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 361 | let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 362 | if has('cmdline_hist') |
| 363 | call add(names, 'history') |
| 364 | endif |
| 365 | if has('gettext') |
| 366 | call add(names, 'locale') |
| 367 | endif |
| 368 | if has('profile') |
| 369 | call add(names, 'syntime') |
| 370 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 371 | |
| 372 | set tags=Xtags |
| 373 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 374 | |
| 375 | for name in names |
| 376 | let matchcount = len(getcompletion('', name)) |
| 377 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 378 | endfor |
| 379 | |
| 380 | call delete('Xtags') |
| 381 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 382 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
| 383 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 384 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 385 | func Test_shellcmd_completion() |
| 386 | let save_path = $PATH |
| 387 | |
| 388 | call mkdir('Xpathdir/Xpathsubdir', 'p') |
| 389 | call writefile([''], 'Xpathdir/Xfile.exe') |
| 390 | call setfperm('Xpathdir/Xfile.exe', 'rwx------') |
| 391 | |
| 392 | " Set PATH to example directory without trailing slash. |
| 393 | let $PATH = getcwd() . '/Xpathdir' |
| 394 | |
| 395 | " Test for the ":!<TAB>" case. Previously, this would include subdirs of |
| 396 | " dirs in the PATH, even though they won't be executed. We check that only |
| 397 | " subdirs of the PWD and executables from the PATH are included in the |
| 398 | " suggestions. |
| 399 | let actual = getcompletion('X', 'shellcmd') |
| 400 | let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') |
| 401 | call insert(expected, 'Xfile.exe') |
| 402 | call assert_equal(expected, actual) |
| 403 | |
| 404 | call delete('Xpathdir', 'rf') |
| 405 | let $PATH = save_path |
| 406 | endfunc |
| 407 | |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 408 | func Test_expand_star_star() |
| 409 | call mkdir('a/b', 'p') |
| 410 | call writefile(['asdfasdf'], 'a/b/fileXname') |
| 411 | call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') |
| 412 | call assert_equal('find a/b/fileXname', getreg(':')) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 413 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 414 | call delete('a', 'rf') |
| 415 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 416 | |
| 417 | func Test_paste_in_cmdline() |
| 418 | let @a = "def" |
| 419 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 420 | call assert_equal('"abc def ghi', @:) |
| 421 | |
| 422 | new |
| 423 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 424 | |
| 425 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 426 | call assert_equal('"aaa asdf bbb', @:) |
| 427 | |
| 428 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 429 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 430 | |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 431 | call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') |
| 432 | call assert_equal('"aaa '.getline(1).' bbb', @:) |
| 433 | |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 434 | set incsearch |
| 435 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 436 | call assert_equal('"aaa verylongword bbb', @:) |
| 437 | |
| 438 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 439 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 440 | |
| 441 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 442 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 443 | bwipe! |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 444 | |
| 445 | " Error while typing a command used to cause that it was not executed |
| 446 | " in the end. |
| 447 | new |
| 448 | try |
| 449 | call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') |
| 450 | catch /^Vim\%((\a\+)\)\=:E32/ |
| 451 | " ignore error E32 |
| 452 | endtry |
| 453 | call assert_equal("Xtestfile", bufname("%")) |
| 454 | bwipe! |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 455 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 456 | |
| 457 | func Test_remove_char_in_cmdline() |
| 458 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 459 | call assert_equal('"abc ef', @:) |
| 460 | |
| 461 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 462 | call assert_equal('"abcdef', @:) |
| 463 | |
| 464 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 465 | call assert_equal('"abc ghi', @:) |
| 466 | |
| 467 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 468 | call assert_equal('"def', @:) |
| 469 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 470 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 471 | func Test_illegal_address1() |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 472 | new |
| 473 | 2;'( |
| 474 | 2;') |
| 475 | quit |
| 476 | endfunc |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 477 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 478 | func Test_illegal_address2() |
| 479 | call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') |
| 480 | new |
| 481 | source Xtest.vim |
| 482 | " Trigger calling validate_cursor() |
| 483 | diffsp Xtest.vim |
| 484 | quit! |
| 485 | bwipe! |
| 486 | call delete('Xtest.vim') |
| 487 | endfunc |
| 488 | |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 489 | func Test_cmdline_complete_wildoptions() |
| 490 | help |
| 491 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 492 | let a = join(sort(split(@:)),' ') |
| 493 | set wildoptions=tagfile |
| 494 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 495 | let b = join(sort(split(@:)),' ') |
| 496 | call assert_equal(a, b) |
| 497 | bw! |
| 498 | endfunc |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 499 | |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 500 | func Test_cmdline_complete_user_cmd() |
| 501 | command! -complete=color -nargs=1 Foo : |
| 502 | call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') |
| 503 | call assert_equal('"Foo blue', @:) |
| 504 | call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') |
| 505 | call assert_equal('"Foo blue', @:) |
| 506 | delcommand Foo |
| 507 | endfunc |
| 508 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 509 | func Test_cmdline_complete_user_names() |
| 510 | if has('unix') && executable('whoami') |
| 511 | let whoami = systemlist('whoami')[0] |
| 512 | let first_letter = whoami[0] |
| 513 | if len(first_letter) > 0 |
| 514 | " Trying completion of :e ~x where x is the first letter of |
| 515 | " the user name should complete to at least the user name. |
| 516 | call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') |
| 517 | call assert_match('^"e \~.*\<' . whoami . '\>', @:) |
| 518 | endif |
| 519 | endif |
| 520 | if has('win32') |
| 521 | " Just in case: check that the system has an Administrator account. |
| 522 | let names = system('net user') |
| 523 | if names =~ 'Administrator' |
| 524 | " Trying completion of :e ~A should complete to Administrator. |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 525 | " There could be other names starting with "A" before Administrator. |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 526 | call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 527 | call assert_match('^"e \~.*Administrator', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 528 | endif |
| 529 | endif |
| 530 | endfunc |
| 531 | |
| 532 | funct Test_cmdline_complete_languages() |
| 533 | let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') |
| 534 | |
| 535 | call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') |
| 536 | call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) |
| 537 | |
| 538 | if has('unix') |
| 539 | " TODO: these tests don't work on Windows. lang appears to be 'C' |
| 540 | " but C does not appear in the completion. Why? |
| 541 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 542 | |
| 543 | call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') |
| 544 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 545 | |
| 546 | call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') |
| 547 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 548 | |
| 549 | call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') |
| 550 | call assert_match('^"language .*\<' . lang . '\>', @:) |
| 551 | endif |
| 552 | endfunc |
| 553 | |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 554 | func Test_cmdline_write_alternatefile() |
| 555 | new |
| 556 | call setline('.', ['one', 'two']) |
| 557 | f foo.txt |
| 558 | new |
| 559 | f #-A |
| 560 | call assert_equal('foo.txt-A', expand('%')) |
| 561 | f #<-B.txt |
| 562 | call assert_equal('foo-B.txt', expand('%')) |
| 563 | f %< |
| 564 | call assert_equal('foo-B', expand('%')) |
| 565 | new |
| 566 | call assert_fails('f #<', 'E95') |
| 567 | bw! |
| 568 | f foo-B.txt |
| 569 | f %<-A |
| 570 | call assert_equal('foo-B-A', expand('%')) |
| 571 | bw! |
| 572 | bw! |
| 573 | endfunc |
| 574 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 575 | " using a leading backslash here |
| 576 | set cpo+=C |
| 577 | |
| 578 | func Test_cmdline_search_range() |
| 579 | new |
| 580 | call setline(1, ['a', 'b', 'c', 'd']) |
| 581 | /d |
| 582 | 1,\/s/b/B/ |
| 583 | call assert_equal('B', getline(2)) |
| 584 | |
| 585 | /a |
| 586 | $ |
| 587 | \?,4s/c/C/ |
| 588 | call assert_equal('C', getline(3)) |
| 589 | |
| 590 | call setline(1, ['a', 'b', 'c', 'd']) |
| 591 | %s/c/c/ |
| 592 | 1,\&s/b/B/ |
| 593 | call assert_equal('B', getline(2)) |
| 594 | |
| 595 | bwipe! |
| 596 | endfunc |
| 597 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 598 | " Tests for getcmdline(), getcmdpos() and getcmdtype() |
| 599 | func Check_cmdline(cmdtype) |
| 600 | call assert_equal('MyCmd a', getcmdline()) |
| 601 | call assert_equal(8, getcmdpos()) |
| 602 | call assert_equal(a:cmdtype, getcmdtype()) |
| 603 | return '' |
| 604 | endfunc |
| 605 | |
| 606 | func Test_getcmdtype() |
| 607 | call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") |
| 608 | |
| 609 | let cmdtype = '' |
| 610 | debuggreedy |
| 611 | call feedkeys(":debug echo 'test'\<CR>", "t") |
| 612 | call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") |
| 613 | call feedkeys("cont\<CR>", "xt") |
| 614 | 0debuggreedy |
| 615 | call assert_equal('>', cmdtype) |
| 616 | |
| 617 | call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") |
| 618 | call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") |
| 619 | |
| 620 | call feedkeys(":call input('Answer?')\<CR>", "t") |
Bram Moolenaar | 31eb139 | 2017-02-09 21:44:03 +0100 | [diff] [blame] | 621 | call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 622 | |
| 623 | call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") |
| 624 | |
| 625 | cnoremap <expr> <F6> Check_cmdline('=') |
| 626 | call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") |
| 627 | cunmap <F6> |
| 628 | endfunc |
| 629 | |
Bram Moolenaar | 81612b7 | 2018-06-23 14:55:03 +0200 | [diff] [blame] | 630 | func Test_getcmdwintype() |
| 631 | call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 632 | call assert_equal('/', a) |
| 633 | |
| 634 | call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 635 | call assert_equal('?', a) |
| 636 | |
| 637 | call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 638 | call assert_equal(':', a) |
| 639 | |
| 640 | call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 641 | call assert_equal(':', a) |
| 642 | |
| 643 | call assert_equal('', getcmdwintype()) |
| 644 | endfunc |
| 645 | |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 646 | func Test_verbosefile() |
| 647 | set verbosefile=Xlog |
| 648 | echomsg 'foo' |
| 649 | echomsg 'bar' |
| 650 | set verbosefile= |
| 651 | let log = readfile('Xlog') |
| 652 | call assert_match("foo\nbar", join(log, "\n")) |
| 653 | call delete('Xlog') |
| 654 | endfunc |
| 655 | |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 656 | func Test_setcmdpos() |
| 657 | func InsertTextAtPos(text, pos) |
| 658 | call assert_equal(0, setcmdpos(a:pos)) |
| 659 | return a:text |
| 660 | endfunc |
| 661 | |
| 662 | " setcmdpos() with position in the middle of the command line. |
| 663 | call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 664 | call assert_equal('"1ab2', @:) |
| 665 | |
| 666 | call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 667 | call assert_equal('"1b2a', @:) |
| 668 | |
| 669 | " setcmdpos() with position beyond the end of the command line. |
| 670 | call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') |
| 671 | call assert_equal('"12ab', @:) |
| 672 | |
| 673 | " setcmdpos() returns 1 when not editing the command line. |
| 674 | call assert_equal(1, setcmdpos(3)) |
| 675 | endfunc |
| 676 | |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 677 | func Test_cmdline_overstrike() |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 678 | let encodings = ['latin1', 'utf8'] |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 679 | let encoding_save = &encoding |
| 680 | |
| 681 | for e in encodings |
| 682 | exe 'set encoding=' . e |
| 683 | |
| 684 | " Test overstrike in the middle of the command line. |
| 685 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
| 686 | call assert_equal('"0ab1cd4', @:) |
| 687 | |
| 688 | " Test overstrike going beyond end of command line. |
| 689 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') |
| 690 | call assert_equal('"0ab1cdefgh', @:) |
| 691 | |
| 692 | " Test toggling insert/overstrike a few times. |
| 693 | call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') |
| 694 | call assert_equal('"ab0cd3ef4', @:) |
| 695 | endfor |
| 696 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 697 | " Test overstrike with multi-byte characters. |
| 698 | call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
| 699 | call assert_equal('"テabキcdエディタ', @:) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 700 | |
| 701 | let &encoding = encoding_save |
| 702 | endfunc |
| 703 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 704 | set cpo& |