blob: 3a35637b7eaddff278eb27eca3fb9bb45632c282 [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
28func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +020029 if !has('cmdline_compl')
30 return
31 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020032 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 Moolenaar0d3e24b2016-07-09 19:20:59 +020038 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 Moolenaaraa4d7322016-07-09 18:50:29 +020047
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020048 let l = getcompletion('v:n', 'var')
49 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020050 let l = getcompletion('v:notexists', 'var')
51 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020052
53 let l = getcompletion('', 'augroup')
54 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020055 let l = getcompletion('blahblah', 'augroup')
56 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020057
58 let l = getcompletion('', 'behave')
59 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020060 let l = getcompletion('not', 'behave')
61 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020062
63 let l = getcompletion('', 'color')
64 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020065 let l = getcompletion('dirty', 'color')
66 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020067
68 let l = getcompletion('', 'command')
69 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020070 let l = getcompletion('awake', 'command')
71 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020072
73 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +020074 call assert_true(index(l, 'samples/') >= 0)
75 let l = getcompletion('NoMatch', 'dir')
76 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020077
78 let l = getcompletion('exe', 'expression')
79 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020080 let l = getcompletion('kill', 'expression')
81 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020082
83 let l = getcompletion('tag', 'function')
84 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020085 let l = getcompletion('paint', 'function')
86 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020087
Bram Moolenaarb49edc12016-07-23 15:47:34 +020088 let Flambda = {-> 'hello'}
89 let l = getcompletion('', 'function')
90 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +020091 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +020092
Bram Moolenaarc1fb7632016-07-17 23:34:21 +020093 let l = getcompletion('run', 'file')
94 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +020095 let l = getcompletion('walk', 'file')
96 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +020097 set wildignore=*.vim
98 let l = getcompletion('run', 'file', 1)
99 call assert_true(index(l, 'runtest.vim') < 0)
100 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200101
102 let l = getcompletion('ha', 'filetype')
103 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200104 let l = getcompletion('horse', 'filetype')
105 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200106
107 let l = getcompletion('z', 'syntax')
108 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200109 let l = getcompletion('emacs', 'syntax')
110 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200111
112 let l = getcompletion('jikes', 'compiler')
113 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200114 let l = getcompletion('break', 'compiler')
115 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200116
117 let l = getcompletion('last', 'help')
118 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200119 let l = getcompletion('giveup', 'help')
120 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200121
122 let l = getcompletion('time', 'option')
123 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200124 let l = getcompletion('space', 'option')
125 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200126
127 let l = getcompletion('er', 'highlight')
128 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200129 let l = getcompletion('dark', 'highlight')
130 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200131
Bram Moolenaarb650b982016-08-05 20:35:13 +0200132 if has('cscope')
133 let l = getcompletion('', 'cscope')
134 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
135 call assert_equal(cmds, l)
136 " using cmdline completion must not change the result
137 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
138 let l = getcompletion('', 'cscope')
139 call assert_equal(cmds, l)
140 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
141 let l = getcompletion('find ', 'cscope')
142 call assert_equal(keys, l)
143 endif
144
Bram Moolenaar7522f692016-08-06 14:12:50 +0200145 if has('signs')
146 sign define Testing linehl=Comment
147 let l = getcompletion('', 'sign')
148 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
149 call assert_equal(cmds, l)
150 " using cmdline completion must not change the result
151 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
152 let l = getcompletion('', 'sign')
153 call assert_equal(cmds, l)
154 let l = getcompletion('list ', 'sign')
155 call assert_equal(['Testing'], l)
156 endif
157
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200158 " For others test if the name is recognized.
159 let names = ['buffer', 'environment', 'file_in_path',
160 \ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200161 if has('cmdline_hist')
162 call add(names, 'history')
163 endif
164 if has('gettext')
165 call add(names, 'locale')
166 endif
167 if has('profile')
168 call add(names, 'syntime')
169 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200170
171 set tags=Xtags
172 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
173
174 for name in names
175 let matchcount = len(getcompletion('', name))
176 call assert_true(matchcount >= 0, 'No matches for ' . name)
177 endfor
178
179 call delete('Xtags')
180
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200181 call assert_fails('call getcompletion("", "burp")', 'E475:')
182endfunc