blob: 11466dc16ac9667a55779b024448b36cd5d690cd [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
3function! Test_whichwrap()
4 set whichwrap=b,s
5 call assert_equal('b,s', &whichwrap)
6
7 set whichwrap+=h,l
8 call assert_equal('b,s,h,l', &whichwrap)
9
10 set whichwrap+=h,l
11 call assert_equal('b,s,h,l', &whichwrap)
12
13 set whichwrap+=h,l
14 call assert_equal('b,s,h,l', &whichwrap)
15
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010016 set whichwrap=h,h
17 call assert_equal('h', &whichwrap)
18
19 set whichwrap=h,h,h
20 call assert_equal('h', &whichwrap)
21
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020022 set whichwrap&
23endfunction
24
Bram Moolenaar187a4f22017-02-23 17:07:14 +010025function! Test_isfname()
26 " This used to cause Vim to access uninitialized memory.
27 set isfname=
28 call assert_equal("~X", expand("~X"))
29 set isfname&
30endfunction
31
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020032function Test_options()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020033 let caught = 'ok'
34 try
35 options
36 catch
37 let caught = v:throwpoint . "\n" . v:exception
38 endtry
39 call assert_equal('ok', caught)
40
41 " close option-window
42 close
43endfunction
44
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020045function Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020046 " Test that changing 'path' keeps two commas.
47 set path=foo,,bar
48 set path-=bar
49 set path+=bar
50 call assert_equal('foo,,bar', &path)
51
52 set path&
53endfunction
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020054
55func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +020056 if has('signs')
57 call assert_equal("auto", &signcolumn)
58 set signcolumn=yes
59 set signcolumn=no
60 call assert_fails('set signcolumn=nope')
61 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020062endfunc
63
Bram Moolenaard0b51382016-11-04 15:23:45 +010064func Test_filetype_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +010065 if !has('autocmd')
66 return
67 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +010068 set ft=valid_name
69 call assert_equal("valid_name", &filetype)
70 set ft=valid-name
71 call assert_equal("valid-name", &filetype)
72
73 call assert_fails(":set ft=wrong;name", "E474:")
74 call assert_fails(":set ft=wrong\\\\name", "E474:")
75 call assert_fails(":set ft=wrong\\|name", "E474:")
76 call assert_fails(":set ft=wrong/name", "E474:")
77 call assert_fails(":set ft=wrong\\\nname", "E474:")
78 call assert_equal("valid-name", &filetype)
79
80 exe "set ft=trunc\x00name"
81 call assert_equal("trunc", &filetype)
82endfunc
83
84func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +010085 if !has('syntax')
86 return
87 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +010088 set syn=valid_name
89 call assert_equal("valid_name", &syntax)
90 set syn=valid-name
91 call assert_equal("valid-name", &syntax)
92
93 call assert_fails(":set syn=wrong;name", "E474:")
94 call assert_fails(":set syn=wrong\\\\name", "E474:")
95 call assert_fails(":set syn=wrong\\|name", "E474:")
96 call assert_fails(":set syn=wrong/name", "E474:")
97 call assert_fails(":set syn=wrong\\\nname", "E474:")
98 call assert_equal("valid-name", &syntax)
99
100 exe "set syn=trunc\x00name"
101 call assert_equal("trunc", &syntax)
102endfunc
103
104func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100105 if !has('keymap')
106 return
107 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100108 call assert_fails(":set kmp=valid_name", "E544:")
109 call assert_fails(":set kmp=valid_name", "valid_name")
110 call assert_fails(":set kmp=valid-name", "E544:")
111 call assert_fails(":set kmp=valid-name", "valid-name")
112
113 call assert_fails(":set kmp=wrong;name", "E474:")
114 call assert_fails(":set kmp=wrong\\\\name", "E474:")
115 call assert_fails(":set kmp=wrong\\|name", "E474:")
116 call assert_fails(":set kmp=wrong/name", "E474:")
117 call assert_fails(":set kmp=wrong\\\nname", "E474:")
118
119 call assert_fails(":set kmp=trunc\x00name", "E544:")
120 call assert_fails(":set kmp=trunc\x00name", "trunc")
121endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100122
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100123func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100124 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100125 exe 'set ' . a:name . '=/usr/share/dict/words'
126 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
127 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
128 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
129 exe 'set ' . a:name . '=/usr/share/dict\ words'
130 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100131
132 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100133 call assert_fails("set " . a:name . "=/not&there", "E474:")
134 call assert_fails("set " . a:name . "=/not>there", "E474:")
135 call assert_fails("set " . a:name . "=/not.*there", "E474:")
136endfunc
137
138func Test_dictionary()
139 call Check_dir_option('dictionary')
140endfunc
141
142func Test_thesaurus()
143 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100144endfun
145
Bram Moolenaar226c5342017-02-17 14:53:15 +0100146func Test_complete()
147 " Trailing single backslash used to cause invalid memory access.
148 set complete=s\
149 new
150 call feedkeys("i\<C-N>\<Esc>", 'xt')
151 bwipe!
152 set complete&
153endfun
154
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100155func Test_set_completion()
156 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
157 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
158
159 " Expand boolan options. When doing :set no<Tab>
160 " vim displays the options names without "no" but completion uses "no...".
161 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
162 call assert_equal('"set nodiff digraph', @:)
163
164 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
165 call assert_equal('"set invdiff digraph', @:)
166
167 " Expand abbreviation of options.
168 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
169 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
170
171 " Expand current value
172 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
173 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
174
175 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
176 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
177
178 " Expand key codes.
179 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
180 call assert_equal('"set <Help> <Home>', @:)
181
182 " Expand terminal options.
183 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
184 call assert_equal('"set t_AB t_AF t_AL', @:)
185
186 " Expand directories.
187 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
188 call assert_match(' ./samples/ ', @:)
189 call assert_notmatch(' ./small.vim ', @:)
190
191 " Expand files and directories.
192 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
193 call assert_match(' ./samples/.* ./small.vim', @:)
194
195 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
196 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
197endfunc
198
199func Test_set_errors()
200 call assert_fails('set scroll=-1', 'E49:')
201 call assert_fails('set backupcopy=', 'E474:')
202 call assert_fails('set regexpengine=3', 'E474:')
203 call assert_fails('set history=10001', 'E474:')
204 call assert_fails('set numberwidth=11', 'E474:')
205 call assert_fails('set colorcolumn=-a')
206 call assert_fails('set colorcolumn=a')
207 call assert_fails('set colorcolumn=1,')
208 call assert_fails('set cmdheight=-1', 'E487:')
209 call assert_fails('set cmdwinheight=-1', 'E487:')
210 if has('conceal')
211 call assert_fails('set conceallevel=-1', 'E487:')
212 call assert_fails('set conceallevel=4', 'E474:')
213 endif
214 call assert_fails('set helpheight=-1', 'E487:')
215 call assert_fails('set history=-1', 'E487:')
216 call assert_fails('set report=-1', 'E487:')
217 call assert_fails('set shiftwidth=-1', 'E487:')
218 call assert_fails('set sidescroll=-1', 'E487:')
219 call assert_fails('set tabstop=-1', 'E487:')
220 call assert_fails('set textwidth=-1', 'E487:')
221 call assert_fails('set timeoutlen=-1', 'E487:')
222 call assert_fails('set updatecount=-1', 'E487:')
223 call assert_fails('set updatetime=-1', 'E487:')
224 call assert_fails('set winheight=-1', 'E487:')
225 call assert_fails('set tabstop!', 'E488:')
226 call assert_fails('set xxx', 'E518:')
227 call assert_fails('set beautify?', 'E519:')
228 call assert_fails('set undolevels=x', 'E521:')
229 call assert_fails('set tabstop=', 'E521:')
230 call assert_fails('set comments=-', 'E524:')
231 call assert_fails('set comments=a', 'E525:')
232 call assert_fails('set foldmarker=x', 'E536:')
233 call assert_fails('set commentstring=x', 'E537:')
234 call assert_fails('set complete=x', 'E539:')
235 call assert_fails('set statusline=%{', 'E540:')
236 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
237 call assert_fails('set statusline=%(', 'E542:')
238 call assert_fails('set guicursor=x', 'E545:')
239 call assert_fails('set backupext=~ patchmode=~', 'E589:')
240 call assert_fails('set winminheight=10 winheight=9', 'E591:')
241 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
242 call assert_fails("set showbreak=\x01", 'E595:')
243 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100244endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100245
246func Test_set_ttytype()
247 if !has('gui_running') && has('unix')
248 " Setting 'ttytype' used to cause a double-free when exiting vim and
249 " when vim is compiled with -DEXITFREE.
250 set ttytype=ansi
251 call assert_equal('ansi', &ttytype)
252 call assert_equal(&ttytype, &term)
253 set ttytype=xterm
254 call assert_equal('xterm', &ttytype)
255 call assert_equal(&ttytype, &term)
256 " FIXME: "set ttytype=" gives E522 instead of E529
257 " in travis on some builds. Why? Commented out this test for now.
258 " call assert_fails('set ttytype=', 'E529:')
259 call assert_fails('set ttytype=xxx', 'E522:')
260 set ttytype&
261 call assert_equal(&ttytype, &term)
262 endif
263endfunc