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() |
| 17 | call writefile(['testfile1'], 'Xtestfile1') |
| 18 | call writefile(['testfile2'], 'Xtestfile2') |
| 19 | set wildmenu |
| 20 | call feedkeys(":e Xtest\t\t\r", "tx") |
| 21 | call assert_equal('testfile2', getline(1)) |
| 22 | |
| 23 | call delete('Xtestfile1') |
| 24 | call delete('Xtestfile2') |
| 25 | set nowildmenu |
| 26 | endfunc |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 27 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 28 | func Test_match_completion() |
| 29 | if !has('cmdline_compl') |
| 30 | return |
| 31 | endif |
| 32 | hi Aardig ctermfg=green |
| 33 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
| 34 | call assert_equal('"match Aardig', getreg(':')) |
| 35 | call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') |
| 36 | call assert_equal('"match none', getreg(':')) |
| 37 | endfunc |
| 38 | |
| 39 | func Test_highlight_completion() |
| 40 | if !has('cmdline_compl') |
| 41 | return |
| 42 | endif |
| 43 | hi Aardig ctermfg=green |
| 44 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 45 | call assert_equal('"hi Aardig', getreg(':')) |
| 46 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 47 | call assert_equal('"hi link', getreg(':')) |
| 48 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 49 | call assert_equal('"hi default', getreg(':')) |
| 50 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 51 | call assert_equal('"hi clear', getreg(':')) |
| 52 | endfunc |
| 53 | |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 54 | func Test_expr_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 55 | if !has('cmdline_compl') |
Bram Moolenaar | 2b2207b | 2017-01-22 16:46:56 +0100 | [diff] [blame] | 56 | return |
| 57 | endif |
| 58 | for cmd in [ |
| 59 | \ 'let a = ', |
| 60 | \ 'if', |
| 61 | \ 'elseif', |
| 62 | \ 'while', |
| 63 | \ 'for', |
| 64 | \ 'echo', |
| 65 | \ 'echon', |
| 66 | \ 'execute', |
| 67 | \ 'echomsg', |
| 68 | \ 'echoerr', |
| 69 | \ 'call', |
| 70 | \ 'return', |
| 71 | \ 'cexpr', |
| 72 | \ 'caddexpr', |
| 73 | \ 'cgetexpr', |
| 74 | \ 'lexpr', |
| 75 | \ 'laddexpr', |
| 76 | \ 'lgetexpr'] |
| 77 | call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') |
| 78 | call assert_equal('"' . cmd . ' getline(', getreg(':')) |
| 79 | endfor |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 82 | func Test_getcompletion() |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 83 | if !has('cmdline_compl') |
| 84 | return |
| 85 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 86 | let groupcount = len(getcompletion('', 'event')) |
| 87 | call assert_true(groupcount > 0) |
| 88 | let matchcount = len(getcompletion('File', 'event')) |
| 89 | call assert_true(matchcount > 0) |
| 90 | call assert_true(groupcount > matchcount) |
| 91 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 92 | if has('menu') |
| 93 | source $VIMRUNTIME/menu.vim |
| 94 | let matchcount = len(getcompletion('', 'menu')) |
| 95 | call assert_true(matchcount > 0) |
| 96 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 97 | call assert_true(matchcount > 0) |
| 98 | let matchcount = len(getcompletion('File.', 'menu')) |
| 99 | call assert_true(matchcount > 0) |
| 100 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 101 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 102 | let l = getcompletion('v:n', 'var') |
| 103 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 104 | let l = getcompletion('v:notexists', 'var') |
| 105 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 106 | |
| 107 | let l = getcompletion('', 'augroup') |
| 108 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 109 | let l = getcompletion('blahblah', 'augroup') |
| 110 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 111 | |
| 112 | let l = getcompletion('', 'behave') |
| 113 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 114 | let l = getcompletion('not', 'behave') |
| 115 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 116 | |
| 117 | let l = getcompletion('', 'color') |
| 118 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 119 | let l = getcompletion('dirty', 'color') |
| 120 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 121 | |
| 122 | let l = getcompletion('', 'command') |
| 123 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 124 | let l = getcompletion('awake', 'command') |
| 125 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 126 | |
| 127 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 128 | call assert_true(index(l, 'samples/') >= 0) |
| 129 | let l = getcompletion('NoMatch', 'dir') |
| 130 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 131 | |
| 132 | let l = getcompletion('exe', 'expression') |
| 133 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 134 | let l = getcompletion('kill', 'expression') |
| 135 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 136 | |
| 137 | let l = getcompletion('tag', 'function') |
| 138 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 139 | let l = getcompletion('paint', 'function') |
| 140 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 141 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 142 | let Flambda = {-> 'hello'} |
| 143 | let l = getcompletion('', 'function') |
| 144 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 145 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 146 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 147 | let l = getcompletion('run', 'file') |
| 148 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 149 | let l = getcompletion('walk', 'file') |
| 150 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 151 | set wildignore=*.vim |
| 152 | let l = getcompletion('run', 'file', 1) |
| 153 | call assert_true(index(l, 'runtest.vim') < 0) |
| 154 | set wildignore& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 155 | |
| 156 | let l = getcompletion('ha', 'filetype') |
| 157 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 158 | let l = getcompletion('horse', 'filetype') |
| 159 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 160 | |
| 161 | let l = getcompletion('z', 'syntax') |
| 162 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 163 | let l = getcompletion('emacs', 'syntax') |
| 164 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 165 | |
| 166 | let l = getcompletion('jikes', 'compiler') |
| 167 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 168 | let l = getcompletion('break', 'compiler') |
| 169 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 170 | |
| 171 | let l = getcompletion('last', 'help') |
| 172 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 173 | let l = getcompletion('giveup', 'help') |
| 174 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 175 | |
| 176 | let l = getcompletion('time', 'option') |
| 177 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 178 | let l = getcompletion('space', 'option') |
| 179 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 180 | |
| 181 | let l = getcompletion('er', 'highlight') |
| 182 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 183 | let l = getcompletion('dark', 'highlight') |
| 184 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 185 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 186 | let l = getcompletion('', 'messages') |
| 187 | call assert_true(index(l, 'clear') >= 0) |
| 188 | let l = getcompletion('not', 'messages') |
| 189 | call assert_equal([], l) |
| 190 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 191 | if has('cscope') |
| 192 | let l = getcompletion('', 'cscope') |
| 193 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 194 | call assert_equal(cmds, l) |
| 195 | " using cmdline completion must not change the result |
| 196 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 197 | let l = getcompletion('', 'cscope') |
| 198 | call assert_equal(cmds, l) |
| 199 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 200 | let l = getcompletion('find ', 'cscope') |
| 201 | call assert_equal(keys, l) |
| 202 | endif |
| 203 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 204 | if has('signs') |
| 205 | sign define Testing linehl=Comment |
| 206 | let l = getcompletion('', 'sign') |
| 207 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 208 | call assert_equal(cmds, l) |
| 209 | " using cmdline completion must not change the result |
| 210 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 211 | let l = getcompletion('', 'sign') |
| 212 | call assert_equal(cmds, l) |
| 213 | let l = getcompletion('list ', 'sign') |
| 214 | call assert_equal(['Testing'], l) |
| 215 | endif |
| 216 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 217 | " For others test if the name is recognized. |
| 218 | let names = ['buffer', 'environment', 'file_in_path', |
| 219 | \ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 220 | if has('cmdline_hist') |
| 221 | call add(names, 'history') |
| 222 | endif |
| 223 | if has('gettext') |
| 224 | call add(names, 'locale') |
| 225 | endif |
| 226 | if has('profile') |
| 227 | call add(names, 'syntime') |
| 228 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 229 | |
| 230 | set tags=Xtags |
| 231 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 232 | |
| 233 | for name in names |
| 234 | let matchcount = len(getcompletion('', name)) |
| 235 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 236 | endfor |
| 237 | |
| 238 | call delete('Xtags') |
| 239 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 240 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
| 241 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 242 | |
| 243 | func Test_expand_star_star() |
| 244 | call mkdir('a/b', 'p') |
| 245 | call writefile(['asdfasdf'], 'a/b/fileXname') |
| 246 | call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') |
| 247 | call assert_equal('find a/b/fileXname', getreg(':')) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 248 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 249 | call delete('a', 'rf') |
| 250 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 251 | |
| 252 | func Test_paste_in_cmdline() |
| 253 | let @a = "def" |
| 254 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 255 | call assert_equal('"abc def ghi', @:) |
| 256 | |
| 257 | new |
| 258 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 259 | |
| 260 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 261 | call assert_equal('"aaa asdf bbb', @:) |
| 262 | |
| 263 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 264 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 265 | |
| 266 | set incsearch |
| 267 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 268 | call assert_equal('"aaa verylongword bbb', @:) |
| 269 | |
| 270 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 271 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 272 | |
| 273 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 274 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 275 | bwipe! |
| 276 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 277 | |
| 278 | func Test_remove_char_in_cmdline() |
| 279 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 280 | call assert_equal('"abc ef', @:) |
| 281 | |
| 282 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 283 | call assert_equal('"abcdef', @:) |
| 284 | |
| 285 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 286 | call assert_equal('"abc ghi', @:) |
| 287 | |
| 288 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 289 | call assert_equal('"def', @:) |
| 290 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 291 | |
| 292 | func Test_illegal_address() |
| 293 | new |
| 294 | 2;'( |
| 295 | 2;') |
| 296 | quit |
| 297 | endfunc |