blob: 623e46c6f64194f59350ac30d1ee44708b4e35ec [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
Bram Moolenaar60629d62017-02-23 18:08:56 +0100138func Test_cinkeys()
139 " This used to cause invalid memory access
140 set cindent cinkeys=0
141 norm a
142 set cindent& cinkeys&
143endfunc
144
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100145func Test_dictionary()
146 call Check_dir_option('dictionary')
147endfunc
148
149func Test_thesaurus()
150 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100151endfun
152
Bram Moolenaar226c5342017-02-17 14:53:15 +0100153func Test_complete()
154 " Trailing single backslash used to cause invalid memory access.
155 set complete=s\
156 new
157 call feedkeys("i\<C-N>\<Esc>", 'xt')
158 bwipe!
159 set complete&
160endfun
161
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100162func Test_set_completion()
163 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
164 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
165
166 " Expand boolan options. When doing :set no<Tab>
167 " vim displays the options names without "no" but completion uses "no...".
168 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
169 call assert_equal('"set nodiff digraph', @:)
170
171 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
172 call assert_equal('"set invdiff digraph', @:)
173
174 " Expand abbreviation of options.
175 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
176 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
177
178 " Expand current value
179 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
180 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
181
182 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
183 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
184
185 " Expand key codes.
186 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
187 call assert_equal('"set <Help> <Home>', @:)
188
189 " Expand terminal options.
190 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
191 call assert_equal('"set t_AB t_AF t_AL', @:)
192
193 " Expand directories.
194 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
195 call assert_match(' ./samples/ ', @:)
196 call assert_notmatch(' ./small.vim ', @:)
197
198 " Expand files and directories.
199 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
200 call assert_match(' ./samples/.* ./small.vim', @:)
201
202 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
203 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
204endfunc
205
206func Test_set_errors()
207 call assert_fails('set scroll=-1', 'E49:')
208 call assert_fails('set backupcopy=', 'E474:')
209 call assert_fails('set regexpengine=3', 'E474:')
210 call assert_fails('set history=10001', 'E474:')
211 call assert_fails('set numberwidth=11', 'E474:')
212 call assert_fails('set colorcolumn=-a')
213 call assert_fails('set colorcolumn=a')
214 call assert_fails('set colorcolumn=1,')
215 call assert_fails('set cmdheight=-1', 'E487:')
216 call assert_fails('set cmdwinheight=-1', 'E487:')
217 if has('conceal')
218 call assert_fails('set conceallevel=-1', 'E487:')
219 call assert_fails('set conceallevel=4', 'E474:')
220 endif
221 call assert_fails('set helpheight=-1', 'E487:')
222 call assert_fails('set history=-1', 'E487:')
223 call assert_fails('set report=-1', 'E487:')
224 call assert_fails('set shiftwidth=-1', 'E487:')
225 call assert_fails('set sidescroll=-1', 'E487:')
226 call assert_fails('set tabstop=-1', 'E487:')
227 call assert_fails('set textwidth=-1', 'E487:')
228 call assert_fails('set timeoutlen=-1', 'E487:')
229 call assert_fails('set updatecount=-1', 'E487:')
230 call assert_fails('set updatetime=-1', 'E487:')
231 call assert_fails('set winheight=-1', 'E487:')
232 call assert_fails('set tabstop!', 'E488:')
233 call assert_fails('set xxx', 'E518:')
234 call assert_fails('set beautify?', 'E519:')
235 call assert_fails('set undolevels=x', 'E521:')
236 call assert_fails('set tabstop=', 'E521:')
237 call assert_fails('set comments=-', 'E524:')
238 call assert_fails('set comments=a', 'E525:')
239 call assert_fails('set foldmarker=x', 'E536:')
240 call assert_fails('set commentstring=x', 'E537:')
241 call assert_fails('set complete=x', 'E539:')
242 call assert_fails('set statusline=%{', 'E540:')
243 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
244 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100245 if has('cursorshape')
246 " This invalid value for 'guicursor' used to cause Vim to crash.
247 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
248 call assert_fails('set guicursor=i-ci', 'E545:')
249 call assert_fails('set guicursor=x', 'E545:')
250 call assert_fails('set guicursor=r-cr:horx', 'E548:')
251 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
252 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100253 call assert_fails('set backupext=~ patchmode=~', 'E589:')
254 call assert_fails('set winminheight=10 winheight=9', 'E591:')
255 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
256 call assert_fails("set showbreak=\x01", 'E595:')
257 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100258endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100259
260func Test_set_ttytype()
261 if !has('gui_running') && has('unix')
262 " Setting 'ttytype' used to cause a double-free when exiting vim and
263 " when vim is compiled with -DEXITFREE.
264 set ttytype=ansi
265 call assert_equal('ansi', &ttytype)
266 call assert_equal(&ttytype, &term)
267 set ttytype=xterm
268 call assert_equal('xterm', &ttytype)
269 call assert_equal(&ttytype, &term)
270 " FIXME: "set ttytype=" gives E522 instead of E529
271 " in travis on some builds. Why? Commented out this test for now.
272 " call assert_fails('set ttytype=', 'E529:')
273 call assert_fails('set ttytype=xxx', 'E522:')
274 set ttytype&
275 call assert_equal(&ttytype, &term)
276 endif
277endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100278
279func Test_set_all()
280 set tw=75
281 set iskeyword=a-z,A-Z
282 set nosplitbelow
283 let out = execute('set all')
284 call assert_match('textwidth=75', out)
285 call assert_match('iskeyword=a-z,A-Z', out)
286 call assert_match('nosplitbelow', out)
287 set tw& iskeyword& splitbelow&
288endfunc
289
290func Test_set_values()
291 " The file is only generated when running "make test" in the src directory.
292 if filereadable('opt_test.vim')
293 source opt_test.vim
294 endif
295endfunc