blob: 054d39b0f09e54aff15473a4603b1e9b955ca6c1 [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)
50
51 let l = getcompletion('', 'augroup')
52 call assert_true(index(l, 'END') >= 0)
53
54 let l = getcompletion('', 'behave')
55 call assert_true(index(l, 'mswin') >= 0)
56
57 let l = getcompletion('', 'color')
58 call assert_true(index(l, 'default') >= 0)
59
60 let l = getcompletion('', 'command')
61 call assert_true(index(l, 'sleep') >= 0)
62
63 let l = getcompletion('', 'dir')
64 call assert_true(index(l, 'samples') >= 0)
65
66 let l = getcompletion('exe', 'expression')
67 call assert_true(index(l, 'executable(') >= 0)
68
69 let l = getcompletion('tag', 'function')
70 call assert_true(index(l, 'taglist(') >= 0)
71
72 let l = getcompletion('run', 'file')
73 call assert_true(index(l, 'runtest.vim') >= 0)
74
75 let l = getcompletion('ha', 'filetype')
76 call assert_true(index(l, 'hamster') >= 0)
77
78 let l = getcompletion('z', 'syntax')
79 call assert_true(index(l, 'zimbu') >= 0)
80
81 let l = getcompletion('jikes', 'compiler')
82 call assert_true(index(l, 'jikes') >= 0)
83
84 let l = getcompletion('last', 'help')
85 call assert_true(index(l, ':tablast') >= 0)
86
87 let l = getcompletion('time', 'option')
88 call assert_true(index(l, 'timeoutlen') >= 0)
89
90 let l = getcompletion('er', 'highlight')
91 call assert_true(index(l, 'ErrorMsg') >= 0)
92
93 " For others test if the name is recognized.
94 let names = ['buffer', 'environment', 'file_in_path',
95 \ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user']
96 if has('cscope')
97 call add(names, 'cscope')
98 endif
99 if has('cmdline_hist')
100 call add(names, 'history')
101 endif
102 if has('gettext')
103 call add(names, 'locale')
104 endif
105 if has('profile')
106 call add(names, 'syntime')
107 endif
108 if has('signs')
109 call add(names, 'sign')
110 endif
111
112 set tags=Xtags
113 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
114
115 for name in names
116 let matchcount = len(getcompletion('', name))
117 call assert_true(matchcount >= 0, 'No matches for ' . name)
118 endfor
119
120 call delete('Xtags')
121
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200122 call assert_fails('call getcompletion("", "burp")', 'E475:')
123endfunc