blob: bfa942715d3b238583f005a61f69913f815642bd [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
16 set whichwrap&
17endfunction
18
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020019function Test_options()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020020 let caught = 'ok'
21 try
22 options
23 catch
24 let caught = v:throwpoint . "\n" . v:exception
25 endtry
26 call assert_equal('ok', caught)
27
28 " close option-window
29 close
30endfunction
31
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020032function Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020033 " Test that changing 'path' keeps two commas.
34 set path=foo,,bar
35 set path-=bar
36 set path+=bar
37 call assert_equal('foo,,bar', &path)
38
39 set path&
40endfunction
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020041
42func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +020043 if has('signs')
44 call assert_equal("auto", &signcolumn)
45 set signcolumn=yes
46 set signcolumn=no
47 call assert_fails('set signcolumn=nope')
48 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020049endfunc
50
Bram Moolenaard0b51382016-11-04 15:23:45 +010051func Test_filetype_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +010052 if !has('autocmd')
53 return
54 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +010055 set ft=valid_name
56 call assert_equal("valid_name", &filetype)
57 set ft=valid-name
58 call assert_equal("valid-name", &filetype)
59
60 call assert_fails(":set ft=wrong;name", "E474:")
61 call assert_fails(":set ft=wrong\\\\name", "E474:")
62 call assert_fails(":set ft=wrong\\|name", "E474:")
63 call assert_fails(":set ft=wrong/name", "E474:")
64 call assert_fails(":set ft=wrong\\\nname", "E474:")
65 call assert_equal("valid-name", &filetype)
66
67 exe "set ft=trunc\x00name"
68 call assert_equal("trunc", &filetype)
69endfunc
70
71func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +010072 if !has('syntax')
73 return
74 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +010075 set syn=valid_name
76 call assert_equal("valid_name", &syntax)
77 set syn=valid-name
78 call assert_equal("valid-name", &syntax)
79
80 call assert_fails(":set syn=wrong;name", "E474:")
81 call assert_fails(":set syn=wrong\\\\name", "E474:")
82 call assert_fails(":set syn=wrong\\|name", "E474:")
83 call assert_fails(":set syn=wrong/name", "E474:")
84 call assert_fails(":set syn=wrong\\\nname", "E474:")
85 call assert_equal("valid-name", &syntax)
86
87 exe "set syn=trunc\x00name"
88 call assert_equal("trunc", &syntax)
89endfunc
90
91func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +010092 if !has('keymap')
93 return
94 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +010095 call assert_fails(":set kmp=valid_name", "E544:")
96 call assert_fails(":set kmp=valid_name", "valid_name")
97 call assert_fails(":set kmp=valid-name", "E544:")
98 call assert_fails(":set kmp=valid-name", "valid-name")
99
100 call assert_fails(":set kmp=wrong;name", "E474:")
101 call assert_fails(":set kmp=wrong\\\\name", "E474:")
102 call assert_fails(":set kmp=wrong\\|name", "E474:")
103 call assert_fails(":set kmp=wrong/name", "E474:")
104 call assert_fails(":set kmp=wrong\\\nname", "E474:")
105
106 call assert_fails(":set kmp=trunc\x00name", "E544:")
107 call assert_fails(":set kmp=trunc\x00name", "trunc")
108endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100109
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100110func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100111 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100112 exe 'set ' . a:name . '=/usr/share/dict/words'
113 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
114 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
115 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
116 exe 'set ' . a:name . '=/usr/share/dict\ words'
117 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100118
119 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100120 call assert_fails("set " . a:name . "=/not&there", "E474:")
121 call assert_fails("set " . a:name . "=/not>there", "E474:")
122 call assert_fails("set " . a:name . "=/not.*there", "E474:")
123endfunc
124
125func Test_dictionary()
126 call Check_dir_option('dictionary')
127endfunc
128
129func Test_thesaurus()
130 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100131endfun
132
133func Test_set_completion()
134 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
135 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
136
137 " Expand boolan options. When doing :set no<Tab>
138 " vim displays the options names without "no" but completion uses "no...".
139 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
140 call assert_equal('"set nodiff digraph', @:)
141
142 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
143 call assert_equal('"set invdiff digraph', @:)
144
145 " Expand abbreviation of options.
146 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
147 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
148
149 " Expand current value
150 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
151 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
152
153 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
154 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
155
156 " Expand key codes.
157 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
158 call assert_equal('"set <Help> <Home>', @:)
159
160 " Expand terminal options.
161 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
162 call assert_equal('"set t_AB t_AF t_AL', @:)
163
164 " Expand directories.
165 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
166 call assert_match(' ./samples/ ', @:)
167 call assert_notmatch(' ./small.vim ', @:)
168
169 " Expand files and directories.
170 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
171 call assert_match(' ./samples/.* ./small.vim', @:)
172
173 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
174 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
175endfunc
176
177func Test_set_errors()
178 call assert_fails('set scroll=-1', 'E49:')
179 call assert_fails('set backupcopy=', 'E474:')
180 call assert_fails('set regexpengine=3', 'E474:')
181 call assert_fails('set history=10001', 'E474:')
182 call assert_fails('set numberwidth=11', 'E474:')
183 call assert_fails('set colorcolumn=-a')
184 call assert_fails('set colorcolumn=a')
185 call assert_fails('set colorcolumn=1,')
186 call assert_fails('set cmdheight=-1', 'E487:')
187 call assert_fails('set cmdwinheight=-1', 'E487:')
188 if has('conceal')
189 call assert_fails('set conceallevel=-1', 'E487:')
190 call assert_fails('set conceallevel=4', 'E474:')
191 endif
192 call assert_fails('set helpheight=-1', 'E487:')
193 call assert_fails('set history=-1', 'E487:')
194 call assert_fails('set report=-1', 'E487:')
195 call assert_fails('set shiftwidth=-1', 'E487:')
196 call assert_fails('set sidescroll=-1', 'E487:')
197 call assert_fails('set tabstop=-1', 'E487:')
198 call assert_fails('set textwidth=-1', 'E487:')
199 call assert_fails('set timeoutlen=-1', 'E487:')
200 call assert_fails('set updatecount=-1', 'E487:')
201 call assert_fails('set updatetime=-1', 'E487:')
202 call assert_fails('set winheight=-1', 'E487:')
203 call assert_fails('set tabstop!', 'E488:')
204 call assert_fails('set xxx', 'E518:')
205 call assert_fails('set beautify?', 'E519:')
206 call assert_fails('set undolevels=x', 'E521:')
207 call assert_fails('set tabstop=', 'E521:')
208 call assert_fails('set comments=-', 'E524:')
209 call assert_fails('set comments=a', 'E525:')
210 call assert_fails('set foldmarker=x', 'E536:')
211 call assert_fails('set commentstring=x', 'E537:')
212 call assert_fails('set complete=x', 'E539:')
213 call assert_fails('set statusline=%{', 'E540:')
214 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
215 call assert_fails('set statusline=%(', 'E542:')
216 call assert_fails('set guicursor=x', 'E545:')
217 call assert_fails('set backupext=~ patchmode=~', 'E589:')
218 call assert_fails('set winminheight=10 winheight=9', 'E591:')
219 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
220 call assert_fails("set showbreak=\x01", 'E595:')
221 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100222endfunc