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