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