Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 1 | " Test for options |
| 2 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 4 | source view_util.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 6 | func Test_whichwrap() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 7 | set whichwrap=b,s |
| 8 | call assert_equal('b,s', &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+=h,l |
| 17 | call assert_equal('b,s,h,l', &whichwrap) |
| 18 | |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 19 | set whichwrap=h,h |
| 20 | call assert_equal('h', &whichwrap) |
| 21 | |
| 22 | set whichwrap=h,h,h |
| 23 | call assert_equal('h', &whichwrap) |
| 24 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 25 | " For compatibility with Vim 3.0 and before, number values are also |
| 26 | " supported for 'whichwrap' |
| 27 | set whichwrap=1 |
| 28 | call assert_equal('b', &whichwrap) |
| 29 | set whichwrap=2 |
| 30 | call assert_equal('s', &whichwrap) |
| 31 | set whichwrap=4 |
| 32 | call assert_equal('h,l', &whichwrap) |
| 33 | set whichwrap=8 |
| 34 | call assert_equal('<,>', &whichwrap) |
| 35 | set whichwrap=16 |
| 36 | call assert_equal('[,]', &whichwrap) |
| 37 | set whichwrap=31 |
| 38 | call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) |
| 39 | |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 40 | set whichwrap& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 41 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 42 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 43 | func Test_isfname() |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 44 | " This used to cause Vim to access uninitialized memory. |
| 45 | set isfname= |
| 46 | call assert_equal("~X", expand("~X")) |
| 47 | set isfname& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 48 | endfunc |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 49 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 50 | func Test_wildchar() |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 51 | " Empty 'wildchar' used to access invalid memory. |
| 52 | call assert_fails('set wildchar=', 'E521:') |
| 53 | call assert_fails('set wildchar=abc', 'E521:') |
| 54 | set wildchar=<Esc> |
| 55 | let a=execute('set wildchar?') |
| 56 | call assert_equal("\n wildchar=<Esc>", a) |
| 57 | set wildchar=27 |
| 58 | let a=execute('set wildchar?') |
| 59 | call assert_equal("\n wildchar=<Esc>", a) |
| 60 | set wildchar& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 61 | endfunc |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 62 | |
Bram Moolenaar | 2e61e2d | 2020-05-22 14:10:36 +0200 | [diff] [blame] | 63 | func Test_wildoptions() |
| 64 | set wildoptions= |
| 65 | set wildoptions+=tagfile |
| 66 | set wildoptions+=tagfile |
| 67 | call assert_equal('tagfile', &wildoptions) |
| 68 | endfunc |
| 69 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 70 | func Test_options_command() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 71 | let caught = 'ok' |
| 72 | try |
| 73 | options |
| 74 | catch |
| 75 | let caught = v:throwpoint . "\n" . v:exception |
| 76 | endtry |
| 77 | call assert_equal('ok', caught) |
| 78 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 79 | " Check if the option-window is opened horizontally. |
| 80 | wincmd j |
| 81 | call assert_notequal('option-window', bufname('')) |
| 82 | wincmd k |
| 83 | call assert_equal('option-window', bufname('')) |
| 84 | " close option-window |
| 85 | close |
| 86 | |
| 87 | " Open the option-window vertically. |
| 88 | vert options |
| 89 | " Check if the option-window is opened vertically. |
| 90 | wincmd l |
| 91 | call assert_notequal('option-window', bufname('')) |
| 92 | wincmd h |
| 93 | call assert_equal('option-window', bufname('')) |
| 94 | " close option-window |
| 95 | close |
| 96 | |
Bram Moolenaar | 7a1637f | 2020-04-13 21:16:21 +0200 | [diff] [blame] | 97 | " Open the option-window at the top. |
| 98 | set splitbelow |
| 99 | topleft options |
| 100 | call assert_equal(1, winnr()) |
| 101 | close |
| 102 | |
| 103 | " Open the option-window at the bottom. |
| 104 | set nosplitbelow |
| 105 | botright options |
| 106 | call assert_equal(winnr('$'), winnr()) |
| 107 | close |
| 108 | set splitbelow& |
| 109 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 110 | " Open the option-window in a new tab. |
| 111 | tab options |
| 112 | " Check if the option-window is opened in a tab. |
| 113 | normal gT |
| 114 | call assert_notequal('option-window', bufname('')) |
| 115 | normal gt |
| 116 | call assert_equal('option-window', bufname('')) |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 117 | " close option-window |
| 118 | close |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 119 | |
| 120 | " Open the options window browse |
| 121 | if has('browse') |
| 122 | browse set |
| 123 | call assert_equal('option-window', bufname('')) |
| 124 | close |
| 125 | endif |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 126 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 127 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 128 | func Test_path_keep_commas() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 129 | " Test that changing 'path' keeps two commas. |
| 130 | set path=foo,,bar |
| 131 | set path-=bar |
| 132 | set path+=bar |
| 133 | call assert_equal('foo,,bar', &path) |
| 134 | |
| 135 | set path& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 136 | endfunc |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 137 | |
| 138 | func Test_signcolumn() |
Bram Moolenaar | ebcccad | 2016-08-12 19:17:13 +0200 | [diff] [blame] | 139 | if has('signs') |
| 140 | call assert_equal("auto", &signcolumn) |
| 141 | set signcolumn=yes |
| 142 | set signcolumn=no |
| 143 | call assert_fails('set signcolumn=nope') |
| 144 | endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 145 | endfunc |
| 146 | |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 147 | func Test_filetype_valid() |
| 148 | set ft=valid_name |
| 149 | call assert_equal("valid_name", &filetype) |
| 150 | set ft=valid-name |
| 151 | call assert_equal("valid-name", &filetype) |
| 152 | |
| 153 | call assert_fails(":set ft=wrong;name", "E474:") |
| 154 | call assert_fails(":set ft=wrong\\\\name", "E474:") |
| 155 | call assert_fails(":set ft=wrong\\|name", "E474:") |
| 156 | call assert_fails(":set ft=wrong/name", "E474:") |
| 157 | call assert_fails(":set ft=wrong\\\nname", "E474:") |
| 158 | call assert_equal("valid-name", &filetype) |
| 159 | |
| 160 | exe "set ft=trunc\x00name" |
| 161 | call assert_equal("trunc", &filetype) |
| 162 | endfunc |
| 163 | |
| 164 | func Test_syntax_valid() |
Bram Moolenaar | 9376f5f | 2016-11-04 16:41:20 +0100 | [diff] [blame] | 165 | if !has('syntax') |
| 166 | return |
| 167 | endif |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 168 | set syn=valid_name |
| 169 | call assert_equal("valid_name", &syntax) |
| 170 | set syn=valid-name |
| 171 | call assert_equal("valid-name", &syntax) |
| 172 | |
| 173 | call assert_fails(":set syn=wrong;name", "E474:") |
| 174 | call assert_fails(":set syn=wrong\\\\name", "E474:") |
| 175 | call assert_fails(":set syn=wrong\\|name", "E474:") |
| 176 | call assert_fails(":set syn=wrong/name", "E474:") |
| 177 | call assert_fails(":set syn=wrong\\\nname", "E474:") |
| 178 | call assert_equal("valid-name", &syntax) |
| 179 | |
| 180 | exe "set syn=trunc\x00name" |
| 181 | call assert_equal("trunc", &syntax) |
| 182 | endfunc |
| 183 | |
| 184 | func Test_keymap_valid() |
Bram Moolenaar | 9376f5f | 2016-11-04 16:41:20 +0100 | [diff] [blame] | 185 | if !has('keymap') |
| 186 | return |
| 187 | endif |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 188 | call assert_fails(":set kmp=valid_name", "E544:") |
| 189 | call assert_fails(":set kmp=valid_name", "valid_name") |
| 190 | call assert_fails(":set kmp=valid-name", "E544:") |
| 191 | call assert_fails(":set kmp=valid-name", "valid-name") |
| 192 | |
| 193 | call assert_fails(":set kmp=wrong;name", "E474:") |
| 194 | call assert_fails(":set kmp=wrong\\\\name", "E474:") |
| 195 | call assert_fails(":set kmp=wrong\\|name", "E474:") |
| 196 | call assert_fails(":set kmp=wrong/name", "E474:") |
| 197 | call assert_fails(":set kmp=wrong\\\nname", "E474:") |
| 198 | |
| 199 | call assert_fails(":set kmp=trunc\x00name", "E544:") |
| 200 | call assert_fails(":set kmp=trunc\x00name", "trunc") |
| 201 | endfunc |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 202 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 203 | func Check_dir_option(name) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 204 | " Check that it's possible to set the option. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 205 | exe 'set ' . a:name . '=/usr/share/dict/words' |
| 206 | call assert_equal('/usr/share/dict/words', eval('&' . a:name)) |
| 207 | exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' |
| 208 | call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) |
| 209 | exe 'set ' . a:name . '=/usr/share/dict\ words' |
| 210 | call assert_equal('/usr/share/dict words', eval('&' . a:name)) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 211 | |
| 212 | " Check rejecting weird characters. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 213 | call assert_fails("set " . a:name . "=/not&there", "E474:") |
| 214 | call assert_fails("set " . a:name . "=/not>there", "E474:") |
| 215 | call assert_fails("set " . a:name . "=/not.*there", "E474:") |
| 216 | endfunc |
| 217 | |
Bram Moolenaar | 60629d6 | 2017-02-23 18:08:56 +0100 | [diff] [blame] | 218 | func Test_cinkeys() |
| 219 | " This used to cause invalid memory access |
| 220 | set cindent cinkeys=0 |
| 221 | norm a |
| 222 | set cindent& cinkeys& |
| 223 | endfunc |
| 224 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 225 | func Test_dictionary() |
| 226 | call Check_dir_option('dictionary') |
| 227 | endfunc |
| 228 | |
| 229 | func Test_thesaurus() |
| 230 | call Check_dir_option('thesaurus') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 231 | endfun |
| 232 | |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 233 | func Test_complete() |
| 234 | " Trailing single backslash used to cause invalid memory access. |
| 235 | set complete=s\ |
| 236 | new |
| 237 | call feedkeys("i\<C-N>\<Esc>", 'xt') |
| 238 | bwipe! |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 239 | call assert_fails('set complete=ix', 'E535:') |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 240 | set complete& |
| 241 | endfun |
| 242 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 243 | func Test_set_completion() |
| 244 | call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 245 | call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) |
| 246 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 247 | call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 248 | call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 249 | |
| 250 | call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 251 | call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 252 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 253 | " Expand boolan options. When doing :set no<Tab> |
| 254 | " vim displays the options names without "no" but completion uses "no...". |
| 255 | call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 256 | call assert_equal('"set nodiff digraph', @:) |
| 257 | |
| 258 | call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 259 | call assert_equal('"set invdiff digraph', @:) |
| 260 | |
| 261 | " Expand abbreviation of options. |
| 262 | call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') |
| 263 | call assert_equal('"set tabstop thesaurus ttyscroll', @:) |
| 264 | |
| 265 | " Expand current value |
| 266 | call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 267 | call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) |
| 268 | |
| 269 | call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') |
| 270 | call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) |
| 271 | |
| 272 | " Expand key codes. |
| 273 | call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') |
| 274 | call assert_equal('"set <Help> <Home>', @:) |
| 275 | |
| 276 | " Expand terminal options. |
| 277 | call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | e023e88 | 2020-05-31 16:42:30 +0200 | [diff] [blame] | 278 | call assert_equal('"set t_AB t_AF t_AU t_AL', @:) |
Bram Moolenaar | 0ff5ded | 2020-05-07 18:43:44 +0200 | [diff] [blame] | 279 | call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 280 | |
| 281 | " Expand directories. |
| 282 | call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 283 | call assert_match(' ./samples/ ', @:) |
| 284 | call assert_notmatch(' ./small.vim ', @:) |
| 285 | |
| 286 | " Expand files and directories. |
| 287 | call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 288 | call assert_match(' ./samples/.* ./small.vim', @:) |
| 289 | |
| 290 | call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') |
| 291 | call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 292 | set tags& |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 293 | |
| 294 | " Expanding the option names |
| 295 | call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') |
| 296 | call assert_equal('"set all', @:) |
| 297 | |
| 298 | " Expanding a second set of option names |
| 299 | call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt') |
| 300 | call assert_equal('"set wrapscan all', @:) |
| 301 | |
| 302 | " Expanding a special keycode |
| 303 | call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 304 | call assert_equal('"set <Home>', @:) |
| 305 | |
| 306 | " Expanding an invalid special keycode |
| 307 | call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 308 | call assert_equal("\"set <abcd>\<Tab>", @:) |
| 309 | |
| 310 | " Expanding a terminal keycode |
| 311 | call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') |
| 312 | call assert_equal("\"set t_AB", @:) |
| 313 | |
| 314 | " Expanding an invalid option name |
| 315 | call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 316 | call assert_equal("\"set abcde=\<Tab>", @:) |
| 317 | |
| 318 | " Expanding after a = for a boolean option |
| 319 | call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 320 | call assert_equal("\"set wrapscan=\<Tab>", @:) |
| 321 | |
| 322 | " Expanding a numeric option |
| 323 | call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 324 | call assert_equal("\"set tabstop+=" .. &tabstop, @:) |
| 325 | |
| 326 | " Expanding a non-boolean option |
| 327 | call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 328 | call assert_equal("\"set invtabstop=", @:) |
| 329 | |
| 330 | " Expand options for 'spellsuggest' |
| 331 | call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt') |
| 332 | call assert_equal("\"set spellsuggest=best,file:xyz", @:) |
| 333 | |
| 334 | " Expand value for 'key' |
| 335 | set key=abcd |
| 336 | call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 337 | call assert_equal('"set key=*****', @:) |
| 338 | set key= |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 339 | endfunc |
| 340 | |
| 341 | func Test_set_errors() |
| 342 | call assert_fails('set scroll=-1', 'E49:') |
| 343 | call assert_fails('set backupcopy=', 'E474:') |
| 344 | call assert_fails('set regexpengine=3', 'E474:') |
| 345 | call assert_fails('set history=10001', 'E474:') |
Bram Moolenaar | f8a0712 | 2019-07-01 22:06:07 +0200 | [diff] [blame] | 346 | call assert_fails('set numberwidth=21', 'E474:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 347 | call assert_fails('set colorcolumn=-a', 'E474:') |
| 348 | call assert_fails('set colorcolumn=a', 'E474:') |
| 349 | call assert_fails('set colorcolumn=1,', 'E474:') |
| 350 | call assert_fails('set colorcolumn=1;', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 351 | call assert_fails('set cmdheight=-1', 'E487:') |
| 352 | call assert_fails('set cmdwinheight=-1', 'E487:') |
| 353 | if has('conceal') |
| 354 | call assert_fails('set conceallevel=-1', 'E487:') |
| 355 | call assert_fails('set conceallevel=4', 'E474:') |
| 356 | endif |
| 357 | call assert_fails('set helpheight=-1', 'E487:') |
| 358 | call assert_fails('set history=-1', 'E487:') |
| 359 | call assert_fails('set report=-1', 'E487:') |
| 360 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 361 | call assert_fails('set sidescroll=-1', 'E487:') |
| 362 | call assert_fails('set tabstop=-1', 'E487:') |
| 363 | call assert_fails('set textwidth=-1', 'E487:') |
| 364 | call assert_fails('set timeoutlen=-1', 'E487:') |
| 365 | call assert_fails('set updatecount=-1', 'E487:') |
| 366 | call assert_fails('set updatetime=-1', 'E487:') |
| 367 | call assert_fails('set winheight=-1', 'E487:') |
| 368 | call assert_fails('set tabstop!', 'E488:') |
| 369 | call assert_fails('set xxx', 'E518:') |
| 370 | call assert_fails('set beautify?', 'E519:') |
| 371 | call assert_fails('set undolevels=x', 'E521:') |
| 372 | call assert_fails('set tabstop=', 'E521:') |
| 373 | call assert_fails('set comments=-', 'E524:') |
| 374 | call assert_fails('set comments=a', 'E525:') |
| 375 | call assert_fails('set foldmarker=x', 'E536:') |
| 376 | call assert_fails('set commentstring=x', 'E537:') |
| 377 | call assert_fails('set complete=x', 'E539:') |
| 378 | call assert_fails('set statusline=%{', 'E540:') |
| 379 | call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') |
| 380 | call assert_fails('set statusline=%(', 'E542:') |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 381 | if has('cursorshape') |
| 382 | " This invalid value for 'guicursor' used to cause Vim to crash. |
| 383 | call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') |
| 384 | call assert_fails('set guicursor=i-ci', 'E545:') |
| 385 | call assert_fails('set guicursor=x', 'E545:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 386 | call assert_fails('set guicursor=x:', 'E546:') |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 387 | call assert_fails('set guicursor=r-cr:horx', 'E548:') |
| 388 | call assert_fails('set guicursor=r-cr:hor0', 'E549:') |
| 389 | endif |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 390 | if has('mouseshape') |
| 391 | call assert_fails('se mouseshape=i-r:x', 'E547:') |
| 392 | endif |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 393 | call assert_fails('set backupext=~ patchmode=~', 'E589:') |
| 394 | call assert_fails('set winminheight=10 winheight=9', 'E591:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 395 | set winminheight& winheight& |
| 396 | set winheight=10 winminheight=10 |
| 397 | call assert_fails('set winheight=9', 'E591:') |
| 398 | set winminheight& winheight& |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 399 | call assert_fails('set winminwidth=10 winwidth=9', 'E592:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 400 | set winminwidth& winwidth& |
| 401 | call assert_fails('set winwidth=9 winminwidth=10', 'E592:') |
| 402 | set winwidth& winminwidth& |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 403 | call assert_fails("set showbreak=\x01", 'E595:') |
| 404 | call assert_fails('set t_foo=', 'E846:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 405 | call assert_fails('set tabstop??', 'E488:') |
| 406 | call assert_fails('set wrapscan!!', 'E488:') |
| 407 | call assert_fails('set tabstop&&', 'E488:') |
| 408 | call assert_fails('set wrapscan<<', 'E488:') |
| 409 | call assert_fails('set wrapscan=1', 'E474:') |
| 410 | call assert_fails('set autoindent@', 'E488:') |
| 411 | call assert_fails('set wildchar=<abc>', 'E474:') |
| 412 | call assert_fails('set cmdheight=1a', 'E521:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 413 | call assert_fails('set invcmdheight', 'E474:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 414 | if has('python') && has('python3') |
| 415 | call assert_fails('set pyxversion=6', 'E474:') |
| 416 | endif |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 417 | call assert_fails("let &tabstop='ab'", 'E521:') |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 418 | endfunc |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 419 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 420 | func CheckWasSet(name) |
| 421 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 422 | call assert_match('Last set from.*test_options.vim', verb_cm) |
| 423 | endfunc |
| 424 | func CheckWasNotSet(name) |
| 425 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 426 | call assert_notmatch('Last set from', verb_cm) |
| 427 | endfunc |
| 428 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 429 | " Must be executed before other tests that set 'term'. |
| 430 | func Test_000_term_option_verbose() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 431 | CheckNotGui |
| 432 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 433 | call CheckWasNotSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 434 | |
| 435 | let term_save = &term |
| 436 | set term=ansi |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 437 | call CheckWasSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 438 | let &term = term_save |
| 439 | endfunc |
| 440 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 441 | func Test_copy_context() |
| 442 | setlocal list |
| 443 | call CheckWasSet('list') |
| 444 | split |
| 445 | call CheckWasSet('list') |
| 446 | quit |
| 447 | setlocal nolist |
| 448 | |
| 449 | set ai |
| 450 | call CheckWasSet('ai') |
| 451 | set filetype=perl |
| 452 | call CheckWasSet('filetype') |
| 453 | set fo=tcroq |
| 454 | call CheckWasSet('fo') |
| 455 | |
| 456 | split Xsomebuf |
| 457 | call CheckWasSet('ai') |
| 458 | call CheckWasNotSet('filetype') |
| 459 | call CheckWasSet('fo') |
| 460 | endfunc |
| 461 | |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 462 | func Test_set_ttytype() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 463 | CheckUnix |
| 464 | CheckNotGui |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 465 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 466 | " Setting 'ttytype' used to cause a double-free when exiting vim and |
| 467 | " when vim is compiled with -DEXITFREE. |
| 468 | set ttytype=ansi |
| 469 | call assert_equal('ansi', &ttytype) |
| 470 | call assert_equal(&ttytype, &term) |
| 471 | set ttytype=xterm |
| 472 | call assert_equal('xterm', &ttytype) |
| 473 | call assert_equal(&ttytype, &term) |
| 474 | " "set ttytype=" gives E522 instead of E529 |
| 475 | " in travis on some builds. Why? Catch both for now |
| 476 | try |
| 477 | set ttytype= |
| 478 | call assert_report('set ttytype= did not fail') |
| 479 | catch /E529\|E522/ |
| 480 | endtry |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 481 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 482 | " Some systems accept any terminal name and return dumb settings, |
| 483 | " check for failure of finding the entry and for missing 'cm' entry. |
| 484 | try |
| 485 | set ttytype=xxx |
| 486 | call assert_report('set ttytype=xxx did not fail') |
| 487 | catch /E522\|E437/ |
| 488 | endtry |
| 489 | |
| 490 | set ttytype& |
| 491 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 492 | |
| 493 | if has('gui') && !has('gui_running') |
| 494 | call assert_fails('set term=gui', 'E531:') |
| 495 | endif |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 496 | endfunc |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 497 | |
| 498 | func Test_set_all() |
| 499 | set tw=75 |
| 500 | set iskeyword=a-z,A-Z |
| 501 | set nosplitbelow |
| 502 | let out = execute('set all') |
| 503 | call assert_match('textwidth=75', out) |
| 504 | call assert_match('iskeyword=a-z,A-Z', out) |
| 505 | call assert_match('nosplitbelow', out) |
| 506 | set tw& iskeyword& splitbelow& |
| 507 | endfunc |
| 508 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 509 | func Test_set_one_column() |
| 510 | let out_mult = execute('set all')->split("\n") |
| 511 | let out_one = execute('set! all')->split("\n") |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 512 | call assert_true(len(out_mult) < len(out_one)) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 513 | endfunc |
| 514 | |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 515 | func Test_set_values() |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 516 | if filereadable('opt_test.vim') |
| 517 | source opt_test.vim |
Bram Moolenaar | e8512d7 | 2017-03-07 22:33:32 +0100 | [diff] [blame] | 518 | else |
| 519 | throw 'Skipped: opt_test.vim does not exist' |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 520 | endif |
| 521 | endfunc |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 522 | |
Bram Moolenaar | 0c1e374 | 2019-12-27 13:49:24 +0100 | [diff] [blame] | 523 | func Test_renderoptions() |
| 524 | " Only do this for Windows Vista and later, fails on Windows XP and earlier. |
| 525 | " Doesn't hurt to do this on a non-Windows system. |
| 526 | if windowsversion() !~ '^[345]\.' |
| 527 | set renderoptions=type:directx |
| 528 | set rop=type:directx |
| 529 | endif |
| 530 | endfunc |
| 531 | |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 532 | func ResetIndentexpr() |
| 533 | set indentexpr= |
| 534 | endfunc |
| 535 | |
| 536 | func Test_set_indentexpr() |
| 537 | " this was causing usage of freed memory |
| 538 | set indentexpr=ResetIndentexpr() |
| 539 | new |
| 540 | call feedkeys("i\<c-f>", 'x') |
| 541 | call assert_equal('', &indentexpr) |
| 542 | bwipe! |
| 543 | endfunc |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 544 | |
| 545 | func Test_backupskip() |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 546 | " Option 'backupskip' may contain several comma-separated path |
| 547 | " specifications if one or more of the environment variables TMPDIR, TMP, |
| 548 | " or TEMP is defined. To simplify testing, convert the string value into a |
| 549 | " list. |
| 550 | let bsklist = split(&bsk, ',') |
| 551 | |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 552 | if has("mac") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 553 | let found = (index(bsklist, '/private/tmp/*') >= 0) |
| 554 | call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 555 | elseif has("unix") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 556 | let found = (index(bsklist, '/tmp/*') >= 0) |
| 557 | call assert_true(found, '/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 558 | endif |
| 559 | |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 560 | " If our test platform is Windows, the path(s) in option bsk will use |
| 561 | " backslash for the path separator and the components could be in short |
| 562 | " (8.3) format. As such, we need to replace the backslashes with forward |
| 563 | " slashes and convert the path components to long format. The expand() |
| 564 | " function will do this but it cannot handle comma-separated paths. This is |
| 565 | " why bsk was converted from a string into a list of strings above. |
| 566 | " |
| 567 | " One final complication is that the wildcard "/*" is at the end of each |
| 568 | " path and so expand() might return a list of matching files. To prevent |
| 569 | " this, we need to remove the wildcard before calling expand() and then |
| 570 | " append it afterwards. |
| 571 | if has('win32') |
| 572 | let item_nbr = 0 |
| 573 | while item_nbr < len(bsklist) |
| 574 | let path_spec = bsklist[item_nbr] |
| 575 | let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) |
| 576 | let path_spec = substitute(expand(path_spec), '\\', '/', 'g') |
| 577 | let bsklist[item_nbr] = path_spec . '/*' |
| 578 | let item_nbr += 1 |
| 579 | endwhile |
| 580 | endif |
| 581 | |
| 582 | " Option bsk will also include these environment variables if defined. |
| 583 | " If they're defined, verify they appear in the option value. |
| 584 | for var in ['$TMPDIR', '$TMP', '$TEMP'] |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 585 | if exists(var) |
| 586 | let varvalue = substitute(expand(var), '\\', '/', 'g') |
Bram Moolenaar | cbbd0f6 | 2019-01-30 22:36:18 +0100 | [diff] [blame] | 587 | let varvalue = substitute(varvalue, '/$', '', '') |
| 588 | let varvalue .= '/*' |
| 589 | let found = (index(bsklist, varvalue) >= 0) |
| 590 | call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 591 | endif |
| 592 | endfor |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 593 | |
| 594 | " Duplicates should be filtered out (option has P_NODUP) |
| 595 | let backupskip = &backupskip |
| 596 | set backupskip= |
| 597 | set backupskip+=/test/dir |
| 598 | set backupskip+=/other/dir |
| 599 | set backupskip+=/test/dir |
| 600 | call assert_equal('/test/dir,/other/dir', &backupskip) |
| 601 | let &backupskip = backupskip |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 602 | endfunc |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 603 | |
| 604 | func Test_copy_winopt() |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 605 | set hidden |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 606 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 607 | " Test copy option from current buffer in window |
| 608 | split |
| 609 | enew |
| 610 | setlocal numberwidth=5 |
| 611 | wincmd w |
| 612 | call assert_equal(4,&numberwidth) |
| 613 | bnext |
| 614 | call assert_equal(5,&numberwidth) |
| 615 | bw! |
| 616 | call assert_equal(4,&numberwidth) |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 617 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 618 | " Test copy value from window that used to be display the buffer |
| 619 | split |
| 620 | enew |
| 621 | setlocal numberwidth=6 |
| 622 | bnext |
| 623 | wincmd w |
| 624 | call assert_equal(4,&numberwidth) |
| 625 | bnext |
| 626 | call assert_equal(6,&numberwidth) |
| 627 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 628 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 629 | " Test that if buffer is current, don't use the stale cached value |
| 630 | " from the last time the buffer was displayed. |
| 631 | split |
| 632 | enew |
| 633 | setlocal numberwidth=7 |
| 634 | bnext |
| 635 | bnext |
| 636 | setlocal numberwidth=8 |
| 637 | wincmd w |
| 638 | call assert_equal(4,&numberwidth) |
| 639 | bnext |
| 640 | call assert_equal(8,&numberwidth) |
| 641 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 642 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 643 | " Test value is not copied if window already has seen the buffer |
| 644 | enew |
| 645 | split |
| 646 | setlocal numberwidth=9 |
| 647 | bnext |
| 648 | setlocal numberwidth=10 |
| 649 | wincmd w |
| 650 | call assert_equal(4,&numberwidth) |
| 651 | bnext |
| 652 | call assert_equal(4,&numberwidth) |
| 653 | bw! |
| 654 | |
| 655 | set hidden& |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 656 | endfunc |
Bram Moolenaar | fc08960 | 2018-06-24 16:53:35 +0200 | [diff] [blame] | 657 | |
| 658 | func Test_shortmess_F() |
| 659 | new |
| 660 | call assert_match('\[No Name\]', execute('file')) |
| 661 | set shortmess+=F |
| 662 | call assert_match('\[No Name\]', execute('file')) |
| 663 | call assert_match('^\s*$', execute('file foo')) |
| 664 | call assert_match('foo', execute('file')) |
| 665 | set shortmess-=F |
| 666 | call assert_match('bar', execute('file bar')) |
| 667 | call assert_match('bar', execute('file')) |
| 668 | set shortmess& |
| 669 | bwipe |
| 670 | endfunc |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 671 | |
| 672 | func Test_shortmess_F2() |
| 673 | e file1 |
| 674 | e file2 |
| 675 | call assert_match('file1', execute('bn', '')) |
| 676 | call assert_match('file2', execute('bn', '')) |
| 677 | set shortmess+=F |
| 678 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 679 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 680 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 681 | call assert_false('need_fileinfo'->test_getvalue()) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 682 | set hidden |
| 683 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 684 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 685 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 686 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 687 | set nohidden |
| 688 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 689 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 690 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 691 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 692 | set shortmess& |
| 693 | call assert_match('file1', execute('bn', '')) |
| 694 | call assert_match('file2', execute('bn', '')) |
| 695 | bwipe |
| 696 | bwipe |
| 697 | endfunc |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 698 | |
| 699 | func Test_local_scrolloff() |
| 700 | set so=5 |
| 701 | set siso=7 |
| 702 | split |
| 703 | call assert_equal(5, &so) |
| 704 | setlocal so=3 |
| 705 | call assert_equal(3, &so) |
| 706 | wincmd w |
| 707 | call assert_equal(5, &so) |
| 708 | wincmd w |
| 709 | setlocal so< |
| 710 | call assert_equal(5, &so) |
| 711 | setlocal so=0 |
| 712 | call assert_equal(0, &so) |
| 713 | setlocal so=-1 |
| 714 | call assert_equal(5, &so) |
| 715 | |
| 716 | call assert_equal(7, &siso) |
| 717 | setlocal siso=3 |
| 718 | call assert_equal(3, &siso) |
| 719 | wincmd w |
| 720 | call assert_equal(7, &siso) |
| 721 | wincmd w |
| 722 | setlocal siso< |
| 723 | call assert_equal(7, &siso) |
| 724 | setlocal siso=0 |
| 725 | call assert_equal(0, &siso) |
| 726 | setlocal siso=-1 |
| 727 | call assert_equal(7, &siso) |
| 728 | |
| 729 | close |
| 730 | set so& |
| 731 | set siso& |
| 732 | endfunc |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 733 | |
| 734 | func Test_writedelay() |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 735 | CheckFunction reltimefloat |
| 736 | |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 737 | new |
| 738 | call setline(1, 'empty') |
| 739 | redraw |
| 740 | set writedelay=10 |
| 741 | let start = reltime() |
| 742 | call setline(1, repeat('x', 70)) |
| 743 | redraw |
| 744 | let elapsed = reltimefloat(reltime(start)) |
| 745 | set writedelay=0 |
| 746 | " With 'writedelay' set should take at least 30 * 10 msec |
| 747 | call assert_inrange(30 * 0.01, 999.0, elapsed) |
| 748 | |
| 749 | bwipe! |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 750 | endfunc |
| 751 | |
| 752 | func Test_visualbell() |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 753 | set belloff= |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 754 | set visualbell |
| 755 | call assert_beeps('normal 0h') |
| 756 | set novisualbell |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 757 | set belloff=all |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 758 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 759 | |
| 760 | " Test for the 'write' option |
| 761 | func Test_write() |
| 762 | new |
| 763 | call setline(1, ['L1']) |
| 764 | set nowrite |
| 765 | call assert_fails('write Xfile', 'E142:') |
| 766 | set write |
| 767 | close! |
| 768 | endfunc |
| 769 | |
| 770 | " Test for 'buftype' option |
| 771 | func Test_buftype() |
| 772 | new |
| 773 | call setline(1, ['L1']) |
| 774 | set buftype=nowrite |
| 775 | call assert_fails('write', 'E382:') |
Bram Moolenaar | a3a9c8e | 2020-03-19 12:38:34 +0100 | [diff] [blame] | 776 | |
| 777 | for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] |
| 778 | exe 'set buftype=' .. val |
| 779 | call writefile(['something'], 'XBuftype') |
| 780 | call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) |
| 781 | endfor |
| 782 | |
| 783 | call delete('XBuftype') |
| 784 | bwipe! |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 785 | endfunc |
| 786 | |
Bram Moolenaar | 4d23c52 | 2020-04-09 18:42:11 +0200 | [diff] [blame] | 787 | " Test for the 'shell' option |
| 788 | func Test_shell() |
| 789 | CheckUnix |
| 790 | let save_shell = &shell |
| 791 | set shell= |
| 792 | call assert_fails('shell', 'E91:') |
| 793 | let &shell = save_shell |
| 794 | endfunc |
| 795 | |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 796 | " Test for the 'shellquote' option |
| 797 | func Test_shellquote() |
| 798 | CheckUnix |
| 799 | set shellquote=# |
| 800 | set verbose=20 |
| 801 | redir => v |
| 802 | silent! !echo Hello |
| 803 | redir END |
| 804 | set verbose& |
| 805 | set shellquote& |
| 806 | call assert_match(': "#echo Hello#"', v) |
| 807 | endfunc |
| 808 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 809 | " Test for the 'rightleftcmd' option |
| 810 | func Test_rightleftcmd() |
| 811 | CheckFeature rightleft |
| 812 | set rightleft |
| 813 | set rightleftcmd |
| 814 | |
| 815 | let g:l = [] |
| 816 | func AddPos() |
| 817 | call add(g:l, screencol()) |
| 818 | return '' |
| 819 | endfunc |
| 820 | cmap <expr> <F2> AddPos() |
| 821 | |
| 822 | call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. |
| 823 | \ "\<Left>\<F2>\<Esc>", 'xt') |
| 824 | call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) |
| 825 | |
| 826 | cunmap <F2> |
| 827 | unlet g:l |
| 828 | set rightleftcmd& |
| 829 | set rightleft& |
| 830 | endfunc |
| 831 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 832 | " Test for the "debug" option |
| 833 | func Test_debug_option() |
| 834 | set debug=beep |
| 835 | exe "normal \<C-c>" |
| 836 | call assert_equal('Beep!', Screenline(&lines)) |
| 837 | set debug& |
| 838 | endfunc |
| 839 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 840 | " Test for the default CDPATH option |
| 841 | func Test_opt_default_cdpath() |
| 842 | CheckFeature file_in_path |
| 843 | let after =<< trim [CODE] |
| 844 | call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) |
| 845 | call writefile(v:errors, 'Xtestout') |
| 846 | qall |
| 847 | [CODE] |
| 848 | if has('unix') |
| 849 | let $CDPATH='/path/to/dir1:/path/to/dir2' |
| 850 | else |
| 851 | let $CDPATH='/path/to/dir1;/path/to/dir2' |
| 852 | endif |
| 853 | if RunVim([], after, '') |
| 854 | call assert_equal([], readfile('Xtestout')) |
| 855 | call delete('Xtestout') |
| 856 | endif |
| 857 | endfunc |
| 858 | |
| 859 | " Test for setting keycodes using set |
| 860 | func Test_opt_set_keycode() |
| 861 | call assert_fails('set <t_k1=l', 'E474:') |
| 862 | call assert_fails('set <Home=l', 'E474:') |
| 863 | set <t_k9>=abcd |
| 864 | call assert_equal('abcd', &t_k9) |
| 865 | set <t_k9>& |
| 866 | set <F9>=xyz |
| 867 | call assert_equal('xyz', &t_k9) |
| 868 | set <t_k9>& |
| 869 | endfunc |
| 870 | |
| 871 | " Test for changing options in a sandbox |
| 872 | func Test_opt_sandbox() |
| 873 | for opt in ['backupdir', 'cdpath', 'exrc'] |
| 874 | call assert_fails('sandbox set ' .. opt .. '?', 'E48:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 875 | call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 876 | endfor |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 877 | call assert_fails('sandbox let &modelineexpr = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 878 | endfunc |
| 879 | |
| 880 | " Test for setting an option with local value to global value |
| 881 | func Test_opt_local_to_global() |
| 882 | setglobal equalprg=gprg |
| 883 | setlocal equalprg=lprg |
| 884 | call assert_equal('gprg', &g:equalprg) |
| 885 | call assert_equal('lprg', &l:equalprg) |
| 886 | call assert_equal('lprg', &equalprg) |
| 887 | set equalprg< |
| 888 | call assert_equal('', &l:equalprg) |
| 889 | call assert_equal('gprg', &equalprg) |
| 890 | setglobal equalprg=gnewprg |
| 891 | setlocal equalprg=lnewprg |
| 892 | setlocal equalprg< |
| 893 | call assert_equal('gnewprg', &l:equalprg) |
| 894 | call assert_equal('gnewprg', &equalprg) |
| 895 | set equalprg& |
| 896 | endfunc |
| 897 | |
| 898 | " Test for incrementing, decrementing and multiplying a number option value |
| 899 | func Test_opt_num_op() |
| 900 | set shiftwidth=4 |
| 901 | set sw+=2 |
| 902 | call assert_equal(6, &sw) |
| 903 | set sw-=2 |
| 904 | call assert_equal(4, &sw) |
| 905 | set sw^=2 |
| 906 | call assert_equal(8, &sw) |
| 907 | set shiftwidth& |
| 908 | endfunc |
| 909 | |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 910 | " Test for setting option values using v:false and v:true |
| 911 | func Test_opt_boolean() |
| 912 | set number& |
| 913 | set number |
| 914 | call assert_equal(1, &nu) |
| 915 | set nonu |
| 916 | call assert_equal(0, &nu) |
| 917 | let &nu = v:true |
| 918 | call assert_equal(1, &nu) |
| 919 | let &nu = v:false |
| 920 | call assert_equal(0, &nu) |
| 921 | set number& |
| 922 | endfunc |
| 923 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 924 | " vim: shiftwidth=2 sts=2 expandtab |