blob: abeb609eaa24866011375e01d279694fe104e6cb [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
3func 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')
8endfunc
9
10func 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'))
14endfunc
15
16func 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
26endfunc
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020027
Bram Moolenaar2b2207b2017-01-22 16:46:56 +010028func 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
54endfunc
55
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020056func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +020057 if !has('cmdline_compl')
58 return
59 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020060 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 Moolenaar0d3e24b2016-07-09 19:20:59 +020066 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 Moolenaaraa4d7322016-07-09 18:50:29 +020075
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020076 let l = getcompletion('v:n', 'var')
77 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020078 let l = getcompletion('v:notexists', 'var')
79 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020080
81 let l = getcompletion('', 'augroup')
82 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020083 let l = getcompletion('blahblah', 'augroup')
84 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020085
86 let l = getcompletion('', 'behave')
87 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020088 let l = getcompletion('not', 'behave')
89 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020090
91 let l = getcompletion('', 'color')
92 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020093 let l = getcompletion('dirty', 'color')
94 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020095
96 let l = getcompletion('', 'command')
97 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020098 let l = getcompletion('awake', 'command')
99 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200100
101 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200102 call assert_true(index(l, 'samples/') >= 0)
103 let l = getcompletion('NoMatch', 'dir')
104 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200105
106 let l = getcompletion('exe', 'expression')
107 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200108 let l = getcompletion('kill', 'expression')
109 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200110
111 let l = getcompletion('tag', 'function')
112 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200113 let l = getcompletion('paint', 'function')
114 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200115
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200116 let Flambda = {-> 'hello'}
117 let l = getcompletion('', 'function')
118 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200119 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200120
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200121 let l = getcompletion('run', 'file')
122 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200123 let l = getcompletion('walk', 'file')
124 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200125 set wildignore=*.vim
126 let l = getcompletion('run', 'file', 1)
127 call assert_true(index(l, 'runtest.vim') < 0)
128 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200129
130 let l = getcompletion('ha', 'filetype')
131 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200132 let l = getcompletion('horse', 'filetype')
133 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200134
135 let l = getcompletion('z', 'syntax')
136 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200137 let l = getcompletion('emacs', 'syntax')
138 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200139
140 let l = getcompletion('jikes', 'compiler')
141 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200142 let l = getcompletion('break', 'compiler')
143 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200144
145 let l = getcompletion('last', 'help')
146 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200147 let l = getcompletion('giveup', 'help')
148 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200149
150 let l = getcompletion('time', 'option')
151 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200152 let l = getcompletion('space', 'option')
153 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200154
155 let l = getcompletion('er', 'highlight')
156 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200157 let l = getcompletion('dark', 'highlight')
158 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200159
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200160 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 Moolenaarb650b982016-08-05 20:35:13 +0200165 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 Moolenaar7522f692016-08-06 14:12:50 +0200178 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 Moolenaarc1fb7632016-07-17 23:34:21 +0200191 " For others test if the name is recognized.
192 let names = ['buffer', 'environment', 'file_in_path',
193 \ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200194 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 Moolenaarc1fb7632016-07-17 23:34:21 +0200203
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 Moolenaaraa4d7322016-07-09 18:50:29 +0200214 call assert_fails('call getcompletion("", "burp")', 'E475:')
215endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200216
217func 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 Moolenaar1773ddf2016-08-28 13:38:54 +0200222 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200223 call delete('a', 'rf')
224endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100225
226func 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 Moolenaareaaa9bb2016-12-09 18:42:20 +0100246
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 Moolenaar21efc362016-12-03 14:05:49 +0100249 bwipe!
250endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100251
252func 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', @:)
264endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100265
266func Test_illegal_address()
267 new
268 2;'(
269 2;')
270 quit
271endfunc