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