xref: /vim-8.2.3635/src/testdir/test_cmdline.vim (revision 89eaa418)
1" 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
27
28func Test_getcompletion()
29  if !has('cmdline_compl')
30    return
31  endif
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
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
47
48  let l = getcompletion('v:n', 'var')
49  call assert_true(index(l, 'v:null') >= 0)
50  let l = getcompletion('v:notexists', 'var')
51  call assert_equal([], l)
52
53  let l = getcompletion('', 'augroup')
54  call assert_true(index(l, 'END') >= 0)
55  let l = getcompletion('blahblah', 'augroup')
56  call assert_equal([], l)
57
58  let l = getcompletion('', 'behave')
59  call assert_true(index(l, 'mswin') >= 0)
60  let l = getcompletion('not', 'behave')
61  call assert_equal([], l)
62
63  let l = getcompletion('', 'color')
64  call assert_true(index(l, 'default') >= 0)
65  let l = getcompletion('dirty', 'color')
66  call assert_equal([], l)
67
68  let l = getcompletion('', 'command')
69  call assert_true(index(l, 'sleep') >= 0)
70  let l = getcompletion('awake', 'command')
71  call assert_equal([], l)
72
73  let l = getcompletion('', 'dir')
74  call assert_true(index(l, 'samples/') >= 0)
75  let l = getcompletion('NoMatch', 'dir')
76  call assert_equal([], l)
77
78  let l = getcompletion('exe', 'expression')
79  call assert_true(index(l, 'executable(') >= 0)
80  let l = getcompletion('kill', 'expression')
81  call assert_equal([], l)
82
83  let l = getcompletion('tag', 'function')
84  call assert_true(index(l, 'taglist(') >= 0)
85  let l = getcompletion('paint', 'function')
86  call assert_equal([], l)
87
88  let Flambda = {-> 'hello'}
89  let l = getcompletion('', 'function')
90  let l = filter(l, {i, v -> v =~ 'lambda'})
91  call assert_equal([], l)
92
93  let l = getcompletion('run', 'file')
94  call assert_true(index(l, 'runtest.vim') >= 0)
95  let l = getcompletion('walk', 'file')
96  call assert_equal([], l)
97
98  let l = getcompletion('ha', 'filetype')
99  call assert_true(index(l, 'hamster') >= 0)
100  let l = getcompletion('horse', 'filetype')
101  call assert_equal([], l)
102
103  let l = getcompletion('z', 'syntax')
104  call assert_true(index(l, 'zimbu') >= 0)
105  let l = getcompletion('emacs', 'syntax')
106  call assert_equal([], l)
107
108  let l = getcompletion('jikes', 'compiler')
109  call assert_true(index(l, 'jikes') >= 0)
110  let l = getcompletion('break', 'compiler')
111  call assert_equal([], l)
112
113  let l = getcompletion('last', 'help')
114  call assert_true(index(l, ':tablast') >= 0)
115  let l = getcompletion('giveup', 'help')
116  call assert_equal([], l)
117
118  let l = getcompletion('time', 'option')
119  call assert_true(index(l, 'timeoutlen') >= 0)
120  let l = getcompletion('space', 'option')
121  call assert_equal([], l)
122
123  let l = getcompletion('er', 'highlight')
124  call assert_true(index(l, 'ErrorMsg') >= 0)
125  let l = getcompletion('dark', 'highlight')
126  call assert_equal([], l)
127
128  " For others test if the name is recognized.
129  let names = ['buffer', 'environment', 'file_in_path',
130	\ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user']
131  if has('cscope')
132    call add(names, 'cscope')
133  endif
134  if has('cmdline_hist')
135    call add(names, 'history')
136  endif
137  if has('gettext')
138    call add(names, 'locale')
139  endif
140  if has('profile')
141    call add(names, 'syntime')
142  endif
143  if has('signs')
144    call add(names, 'sign')
145  endif
146
147  set tags=Xtags
148  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
149
150  for name in names
151    let matchcount = len(getcompletion('', name))
152    call assert_true(matchcount >= 0, 'No matches for ' . name)
153  endfor
154
155  call delete('Xtags')
156
157  call assert_fails('call getcompletion("", "burp")', 'E475:')
158endfunc
159