Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 1 | " Test for options |
| 2 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 3 | func Test_whichwrap() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 4 | set whichwrap=b,s |
| 5 | call assert_equal('b,s', &whichwrap) |
| 6 | |
| 7 | set whichwrap+=h,l |
| 8 | call assert_equal('b,s,h,l', &whichwrap) |
| 9 | |
| 10 | set whichwrap+=h,l |
| 11 | call assert_equal('b,s,h,l', &whichwrap) |
| 12 | |
| 13 | set whichwrap+=h,l |
| 14 | call assert_equal('b,s,h,l', &whichwrap) |
| 15 | |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 16 | set whichwrap=h,h |
| 17 | call assert_equal('h', &whichwrap) |
| 18 | |
| 19 | set whichwrap=h,h,h |
| 20 | call assert_equal('h', &whichwrap) |
| 21 | |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 22 | set whichwrap& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 23 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 24 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 25 | func Test_isfname() |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 26 | " This used to cause Vim to access uninitialized memory. |
| 27 | set isfname= |
| 28 | call assert_equal("~X", expand("~X")) |
| 29 | set isfname& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 30 | endfunc |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 31 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 32 | func Test_wildchar() |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 33 | " Empty 'wildchar' used to access invalid memory. |
| 34 | call assert_fails('set wildchar=', 'E521:') |
| 35 | call assert_fails('set wildchar=abc', 'E521:') |
| 36 | set wildchar=<Esc> |
| 37 | let a=execute('set wildchar?') |
| 38 | call assert_equal("\n wildchar=<Esc>", a) |
| 39 | set wildchar=27 |
| 40 | let a=execute('set wildchar?') |
| 41 | call assert_equal("\n wildchar=<Esc>", a) |
| 42 | set wildchar& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 43 | endfunc |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 44 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 45 | func Test_options() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 46 | let caught = 'ok' |
| 47 | try |
| 48 | options |
| 49 | catch |
| 50 | let caught = v:throwpoint . "\n" . v:exception |
| 51 | endtry |
| 52 | call assert_equal('ok', caught) |
| 53 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 54 | " Check if the option-window is opened horizontally. |
| 55 | wincmd j |
| 56 | call assert_notequal('option-window', bufname('')) |
| 57 | wincmd k |
| 58 | call assert_equal('option-window', bufname('')) |
| 59 | " close option-window |
| 60 | close |
| 61 | |
| 62 | " Open the option-window vertically. |
| 63 | vert options |
| 64 | " Check if the option-window is opened vertically. |
| 65 | wincmd l |
| 66 | call assert_notequal('option-window', bufname('')) |
| 67 | wincmd h |
| 68 | call assert_equal('option-window', bufname('')) |
| 69 | " close option-window |
| 70 | close |
| 71 | |
| 72 | " Open the option-window in a new tab. |
| 73 | tab options |
| 74 | " Check if the option-window is opened in a tab. |
| 75 | normal gT |
| 76 | call assert_notequal('option-window', bufname('')) |
| 77 | normal gt |
| 78 | call assert_equal('option-window', bufname('')) |
| 79 | |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 80 | " close option-window |
| 81 | close |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 82 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 83 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 84 | func Test_path_keep_commas() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 85 | " Test that changing 'path' keeps two commas. |
| 86 | set path=foo,,bar |
| 87 | set path-=bar |
| 88 | set path+=bar |
| 89 | call assert_equal('foo,,bar', &path) |
| 90 | |
| 91 | set path& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 92 | endfunc |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 93 | |
| 94 | func Test_signcolumn() |
Bram Moolenaar | ebcccad | 2016-08-12 19:17:13 +0200 | [diff] [blame] | 95 | if has('signs') |
| 96 | call assert_equal("auto", &signcolumn) |
| 97 | set signcolumn=yes |
| 98 | set signcolumn=no |
| 99 | call assert_fails('set signcolumn=nope') |
| 100 | endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 101 | endfunc |
| 102 | |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 103 | func Test_filetype_valid() |
| 104 | set ft=valid_name |
| 105 | call assert_equal("valid_name", &filetype) |
| 106 | set ft=valid-name |
| 107 | call assert_equal("valid-name", &filetype) |
| 108 | |
| 109 | call assert_fails(":set ft=wrong;name", "E474:") |
| 110 | call assert_fails(":set ft=wrong\\\\name", "E474:") |
| 111 | call assert_fails(":set ft=wrong\\|name", "E474:") |
| 112 | call assert_fails(":set ft=wrong/name", "E474:") |
| 113 | call assert_fails(":set ft=wrong\\\nname", "E474:") |
| 114 | call assert_equal("valid-name", &filetype) |
| 115 | |
| 116 | exe "set ft=trunc\x00name" |
| 117 | call assert_equal("trunc", &filetype) |
| 118 | endfunc |
| 119 | |
| 120 | func Test_syntax_valid() |
Bram Moolenaar | 9376f5f | 2016-11-04 16:41:20 +0100 | [diff] [blame] | 121 | if !has('syntax') |
| 122 | return |
| 123 | endif |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 124 | set syn=valid_name |
| 125 | call assert_equal("valid_name", &syntax) |
| 126 | set syn=valid-name |
| 127 | call assert_equal("valid-name", &syntax) |
| 128 | |
| 129 | call assert_fails(":set syn=wrong;name", "E474:") |
| 130 | call assert_fails(":set syn=wrong\\\\name", "E474:") |
| 131 | call assert_fails(":set syn=wrong\\|name", "E474:") |
| 132 | call assert_fails(":set syn=wrong/name", "E474:") |
| 133 | call assert_fails(":set syn=wrong\\\nname", "E474:") |
| 134 | call assert_equal("valid-name", &syntax) |
| 135 | |
| 136 | exe "set syn=trunc\x00name" |
| 137 | call assert_equal("trunc", &syntax) |
| 138 | endfunc |
| 139 | |
| 140 | func Test_keymap_valid() |
Bram Moolenaar | 9376f5f | 2016-11-04 16:41:20 +0100 | [diff] [blame] | 141 | if !has('keymap') |
| 142 | return |
| 143 | endif |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 144 | call assert_fails(":set kmp=valid_name", "E544:") |
| 145 | call assert_fails(":set kmp=valid_name", "valid_name") |
| 146 | call assert_fails(":set kmp=valid-name", "E544:") |
| 147 | call assert_fails(":set kmp=valid-name", "valid-name") |
| 148 | |
| 149 | call assert_fails(":set kmp=wrong;name", "E474:") |
| 150 | call assert_fails(":set kmp=wrong\\\\name", "E474:") |
| 151 | call assert_fails(":set kmp=wrong\\|name", "E474:") |
| 152 | call assert_fails(":set kmp=wrong/name", "E474:") |
| 153 | call assert_fails(":set kmp=wrong\\\nname", "E474:") |
| 154 | |
| 155 | call assert_fails(":set kmp=trunc\x00name", "E544:") |
| 156 | call assert_fails(":set kmp=trunc\x00name", "trunc") |
| 157 | endfunc |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 158 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 159 | func Check_dir_option(name) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 160 | " Check that it's possible to set the option. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 161 | exe 'set ' . a:name . '=/usr/share/dict/words' |
| 162 | call assert_equal('/usr/share/dict/words', eval('&' . a:name)) |
| 163 | exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' |
| 164 | call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) |
| 165 | exe 'set ' . a:name . '=/usr/share/dict\ words' |
| 166 | call assert_equal('/usr/share/dict words', eval('&' . a:name)) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 167 | |
| 168 | " Check rejecting weird characters. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 169 | call assert_fails("set " . a:name . "=/not&there", "E474:") |
| 170 | call assert_fails("set " . a:name . "=/not>there", "E474:") |
| 171 | call assert_fails("set " . a:name . "=/not.*there", "E474:") |
| 172 | endfunc |
| 173 | |
Bram Moolenaar | 60629d6 | 2017-02-23 18:08:56 +0100 | [diff] [blame] | 174 | func Test_cinkeys() |
| 175 | " This used to cause invalid memory access |
| 176 | set cindent cinkeys=0 |
| 177 | norm a |
| 178 | set cindent& cinkeys& |
| 179 | endfunc |
| 180 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 181 | func Test_dictionary() |
| 182 | call Check_dir_option('dictionary') |
| 183 | endfunc |
| 184 | |
| 185 | func Test_thesaurus() |
| 186 | call Check_dir_option('thesaurus') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 187 | endfun |
| 188 | |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 189 | func Test_complete() |
| 190 | " Trailing single backslash used to cause invalid memory access. |
| 191 | set complete=s\ |
| 192 | new |
| 193 | call feedkeys("i\<C-N>\<Esc>", 'xt') |
| 194 | bwipe! |
| 195 | set complete& |
| 196 | endfun |
| 197 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 198 | func Test_set_completion() |
| 199 | call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 200 | call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) |
| 201 | |
| 202 | " Expand boolan options. When doing :set no<Tab> |
| 203 | " vim displays the options names without "no" but completion uses "no...". |
| 204 | call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 205 | call assert_equal('"set nodiff digraph', @:) |
| 206 | |
| 207 | call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 208 | call assert_equal('"set invdiff digraph', @:) |
| 209 | |
| 210 | " Expand abbreviation of options. |
| 211 | call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') |
| 212 | call assert_equal('"set tabstop thesaurus ttyscroll', @:) |
| 213 | |
| 214 | " Expand current value |
| 215 | call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 216 | call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) |
| 217 | |
| 218 | call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') |
| 219 | call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) |
| 220 | |
| 221 | " Expand key codes. |
| 222 | call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') |
| 223 | call assert_equal('"set <Help> <Home>', @:) |
| 224 | |
| 225 | " Expand terminal options. |
| 226 | call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') |
| 227 | call assert_equal('"set t_AB t_AF t_AL', @:) |
| 228 | |
| 229 | " Expand directories. |
| 230 | call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 231 | call assert_match(' ./samples/ ', @:) |
| 232 | call assert_notmatch(' ./small.vim ', @:) |
| 233 | |
| 234 | " Expand files and directories. |
| 235 | call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 236 | call assert_match(' ./samples/.* ./small.vim', @:) |
| 237 | |
| 238 | call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') |
| 239 | call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) |
| 240 | endfunc |
| 241 | |
| 242 | func Test_set_errors() |
| 243 | call assert_fails('set scroll=-1', 'E49:') |
| 244 | call assert_fails('set backupcopy=', 'E474:') |
| 245 | call assert_fails('set regexpengine=3', 'E474:') |
| 246 | call assert_fails('set history=10001', 'E474:') |
| 247 | call assert_fails('set numberwidth=11', 'E474:') |
| 248 | call assert_fails('set colorcolumn=-a') |
| 249 | call assert_fails('set colorcolumn=a') |
| 250 | call assert_fails('set colorcolumn=1,') |
| 251 | call assert_fails('set cmdheight=-1', 'E487:') |
| 252 | call assert_fails('set cmdwinheight=-1', 'E487:') |
| 253 | if has('conceal') |
| 254 | call assert_fails('set conceallevel=-1', 'E487:') |
| 255 | call assert_fails('set conceallevel=4', 'E474:') |
| 256 | endif |
| 257 | call assert_fails('set helpheight=-1', 'E487:') |
| 258 | call assert_fails('set history=-1', 'E487:') |
| 259 | call assert_fails('set report=-1', 'E487:') |
| 260 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 261 | call assert_fails('set sidescroll=-1', 'E487:') |
| 262 | call assert_fails('set tabstop=-1', 'E487:') |
| 263 | call assert_fails('set textwidth=-1', 'E487:') |
| 264 | call assert_fails('set timeoutlen=-1', 'E487:') |
| 265 | call assert_fails('set updatecount=-1', 'E487:') |
| 266 | call assert_fails('set updatetime=-1', 'E487:') |
| 267 | call assert_fails('set winheight=-1', 'E487:') |
| 268 | call assert_fails('set tabstop!', 'E488:') |
| 269 | call assert_fails('set xxx', 'E518:') |
| 270 | call assert_fails('set beautify?', 'E519:') |
| 271 | call assert_fails('set undolevels=x', 'E521:') |
| 272 | call assert_fails('set tabstop=', 'E521:') |
| 273 | call assert_fails('set comments=-', 'E524:') |
| 274 | call assert_fails('set comments=a', 'E525:') |
| 275 | call assert_fails('set foldmarker=x', 'E536:') |
| 276 | call assert_fails('set commentstring=x', 'E537:') |
| 277 | call assert_fails('set complete=x', 'E539:') |
| 278 | call assert_fails('set statusline=%{', 'E540:') |
| 279 | call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') |
| 280 | call assert_fails('set statusline=%(', 'E542:') |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 281 | if has('cursorshape') |
| 282 | " This invalid value for 'guicursor' used to cause Vim to crash. |
| 283 | call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') |
| 284 | call assert_fails('set guicursor=i-ci', 'E545:') |
| 285 | call assert_fails('set guicursor=x', 'E545:') |
| 286 | call assert_fails('set guicursor=r-cr:horx', 'E548:') |
| 287 | call assert_fails('set guicursor=r-cr:hor0', 'E549:') |
| 288 | endif |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 289 | call assert_fails('set backupext=~ patchmode=~', 'E589:') |
| 290 | call assert_fails('set winminheight=10 winheight=9', 'E591:') |
| 291 | call assert_fails('set winminwidth=10 winwidth=9', 'E592:') |
| 292 | call assert_fails("set showbreak=\x01", 'E595:') |
| 293 | call assert_fails('set t_foo=', 'E846:') |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 294 | endfunc |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 295 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 296 | " Must be executed before other tests that set 'term'. |
| 297 | func Test_000_term_option_verbose() |
Bram Moolenaar | 4f88875 | 2018-10-02 15:06:40 +0200 | [diff] [blame] | 298 | if has('gui_running') |
| 299 | return |
| 300 | endif |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 301 | let verb_cm = execute('verbose set t_cm') |
| 302 | call assert_notmatch('Last set from', verb_cm) |
| 303 | |
| 304 | let term_save = &term |
| 305 | set term=ansi |
| 306 | let verb_cm = execute('verbose set t_cm') |
| 307 | call assert_match('Last set from.*test_options.vim', verb_cm) |
| 308 | let &term = term_save |
| 309 | endfunc |
| 310 | |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 311 | func Test_set_ttytype() |
| 312 | if !has('gui_running') && has('unix') |
| 313 | " Setting 'ttytype' used to cause a double-free when exiting vim and |
| 314 | " when vim is compiled with -DEXITFREE. |
| 315 | set ttytype=ansi |
| 316 | call assert_equal('ansi', &ttytype) |
| 317 | call assert_equal(&ttytype, &term) |
| 318 | set ttytype=xterm |
| 319 | call assert_equal('xterm', &ttytype) |
| 320 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 321 | " "set ttytype=" gives E522 instead of E529 |
| 322 | " in travis on some builds. Why? Catch both for now |
| 323 | try |
| 324 | set ttytype= |
Bram Moolenaar | 69e0569 | 2018-05-10 14:11:52 +0200 | [diff] [blame] | 325 | call assert_report('set ttytype= did not fail') |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 326 | catch /E529\|E522/ |
| 327 | endtry |
| 328 | |
| 329 | " Some systems accept any terminal name and return dumb settings, |
| 330 | " check for failure of finding the entry and for missing 'cm' entry. |
| 331 | try |
| 332 | set ttytype=xxx |
Bram Moolenaar | 69e0569 | 2018-05-10 14:11:52 +0200 | [diff] [blame] | 333 | call assert_report('set ttytype=xxx did not fail') |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 334 | catch /E522\|E437/ |
| 335 | endtry |
| 336 | |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 337 | set ttytype& |
| 338 | call assert_equal(&ttytype, &term) |
| 339 | endif |
| 340 | endfunc |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 341 | |
| 342 | func Test_set_all() |
| 343 | set tw=75 |
| 344 | set iskeyword=a-z,A-Z |
| 345 | set nosplitbelow |
| 346 | let out = execute('set all') |
| 347 | call assert_match('textwidth=75', out) |
| 348 | call assert_match('iskeyword=a-z,A-Z', out) |
| 349 | call assert_match('nosplitbelow', out) |
| 350 | set tw& iskeyword& splitbelow& |
| 351 | endfunc |
| 352 | |
| 353 | func Test_set_values() |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 354 | if filereadable('opt_test.vim') |
| 355 | source opt_test.vim |
Bram Moolenaar | e8512d7 | 2017-03-07 22:33:32 +0100 | [diff] [blame] | 356 | else |
| 357 | throw 'Skipped: opt_test.vim does not exist' |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 358 | endif |
| 359 | endfunc |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 360 | |
| 361 | func ResetIndentexpr() |
| 362 | set indentexpr= |
| 363 | endfunc |
| 364 | |
| 365 | func Test_set_indentexpr() |
| 366 | " this was causing usage of freed memory |
| 367 | set indentexpr=ResetIndentexpr() |
| 368 | new |
| 369 | call feedkeys("i\<c-f>", 'x') |
| 370 | call assert_equal('', &indentexpr) |
| 371 | bwipe! |
| 372 | endfunc |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 373 | |
| 374 | func Test_backupskip() |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 375 | " Option 'backupskip' may contain several comma-separated path |
| 376 | " specifications if one or more of the environment variables TMPDIR, TMP, |
| 377 | " or TEMP is defined. To simplify testing, convert the string value into a |
| 378 | " list. |
| 379 | let bsklist = split(&bsk, ',') |
| 380 | |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 381 | if has("mac") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 382 | let found = (index(bsklist, '/private/tmp/*') >= 0) |
| 383 | call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 384 | elseif has("unix") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 385 | let found = (index(bsklist, '/tmp/*') >= 0) |
| 386 | call assert_true(found, '/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 387 | endif |
| 388 | |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 389 | " If our test platform is Windows, the path(s) in option bsk will use |
| 390 | " backslash for the path separator and the components could be in short |
| 391 | " (8.3) format. As such, we need to replace the backslashes with forward |
| 392 | " slashes and convert the path components to long format. The expand() |
| 393 | " function will do this but it cannot handle comma-separated paths. This is |
| 394 | " why bsk was converted from a string into a list of strings above. |
| 395 | " |
| 396 | " One final complication is that the wildcard "/*" is at the end of each |
| 397 | " path and so expand() might return a list of matching files. To prevent |
| 398 | " this, we need to remove the wildcard before calling expand() and then |
| 399 | " append it afterwards. |
| 400 | if has('win32') |
| 401 | let item_nbr = 0 |
| 402 | while item_nbr < len(bsklist) |
| 403 | let path_spec = bsklist[item_nbr] |
| 404 | let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) |
| 405 | let path_spec = substitute(expand(path_spec), '\\', '/', 'g') |
| 406 | let bsklist[item_nbr] = path_spec . '/*' |
| 407 | let item_nbr += 1 |
| 408 | endwhile |
| 409 | endif |
| 410 | |
| 411 | " Option bsk will also include these environment variables if defined. |
| 412 | " If they're defined, verify they appear in the option value. |
| 413 | for var in ['$TMPDIR', '$TMP', '$TEMP'] |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 414 | if exists(var) |
| 415 | let varvalue = substitute(expand(var), '\\', '/', 'g') |
Bram Moolenaar | cbbd0f6 | 2019-01-30 22:36:18 +0100 | [diff] [blame] | 416 | let varvalue = substitute(varvalue, '/$', '', '') |
| 417 | let varvalue .= '/*' |
| 418 | let found = (index(bsklist, varvalue) >= 0) |
| 419 | call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 420 | endif |
| 421 | endfor |
| 422 | endfunc |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 423 | |
| 424 | func Test_copy_winopt() |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 425 | set hidden |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 426 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 427 | " Test copy option from current buffer in window |
| 428 | split |
| 429 | enew |
| 430 | setlocal numberwidth=5 |
| 431 | wincmd w |
| 432 | call assert_equal(4,&numberwidth) |
| 433 | bnext |
| 434 | call assert_equal(5,&numberwidth) |
| 435 | bw! |
| 436 | call assert_equal(4,&numberwidth) |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 437 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 438 | " Test copy value from window that used to be display the buffer |
| 439 | split |
| 440 | enew |
| 441 | setlocal numberwidth=6 |
| 442 | bnext |
| 443 | wincmd w |
| 444 | call assert_equal(4,&numberwidth) |
| 445 | bnext |
| 446 | call assert_equal(6,&numberwidth) |
| 447 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 448 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 449 | " Test that if buffer is current, don't use the stale cached value |
| 450 | " from the last time the buffer was displayed. |
| 451 | split |
| 452 | enew |
| 453 | setlocal numberwidth=7 |
| 454 | bnext |
| 455 | bnext |
| 456 | setlocal numberwidth=8 |
| 457 | wincmd w |
| 458 | call assert_equal(4,&numberwidth) |
| 459 | bnext |
| 460 | call assert_equal(8,&numberwidth) |
| 461 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 462 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 463 | " Test value is not copied if window already has seen the buffer |
| 464 | enew |
| 465 | split |
| 466 | setlocal numberwidth=9 |
| 467 | bnext |
| 468 | setlocal numberwidth=10 |
| 469 | wincmd w |
| 470 | call assert_equal(4,&numberwidth) |
| 471 | bnext |
| 472 | call assert_equal(4,&numberwidth) |
| 473 | bw! |
| 474 | |
| 475 | set hidden& |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 476 | endfunc |
Bram Moolenaar | fc08960 | 2018-06-24 16:53:35 +0200 | [diff] [blame] | 477 | |
| 478 | func Test_shortmess_F() |
| 479 | new |
| 480 | call assert_match('\[No Name\]', execute('file')) |
| 481 | set shortmess+=F |
| 482 | call assert_match('\[No Name\]', execute('file')) |
| 483 | call assert_match('^\s*$', execute('file foo')) |
| 484 | call assert_match('foo', execute('file')) |
| 485 | set shortmess-=F |
| 486 | call assert_match('bar', execute('file bar')) |
| 487 | call assert_match('bar', execute('file')) |
| 488 | set shortmess& |
| 489 | bwipe |
| 490 | endfunc |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 491 | |
| 492 | func Test_shortmess_F2() |
| 493 | e file1 |
| 494 | e file2 |
| 495 | call assert_match('file1', execute('bn', '')) |
| 496 | call assert_match('file2', execute('bn', '')) |
| 497 | set shortmess+=F |
| 498 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 499 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 500 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 501 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 502 | set hidden |
| 503 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 504 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 505 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 506 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 507 | set nohidden |
| 508 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 509 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 510 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 511 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 512 | set shortmess& |
| 513 | call assert_match('file1', execute('bn', '')) |
| 514 | call assert_match('file2', execute('bn', '')) |
| 515 | bwipe |
| 516 | bwipe |
| 517 | endfunc |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 518 | |
| 519 | func Test_local_scrolloff() |
| 520 | set so=5 |
| 521 | set siso=7 |
| 522 | split |
| 523 | call assert_equal(5, &so) |
| 524 | setlocal so=3 |
| 525 | call assert_equal(3, &so) |
| 526 | wincmd w |
| 527 | call assert_equal(5, &so) |
| 528 | wincmd w |
| 529 | setlocal so< |
| 530 | call assert_equal(5, &so) |
| 531 | setlocal so=0 |
| 532 | call assert_equal(0, &so) |
| 533 | setlocal so=-1 |
| 534 | call assert_equal(5, &so) |
| 535 | |
| 536 | call assert_equal(7, &siso) |
| 537 | setlocal siso=3 |
| 538 | call assert_equal(3, &siso) |
| 539 | wincmd w |
| 540 | call assert_equal(7, &siso) |
| 541 | wincmd w |
| 542 | setlocal siso< |
| 543 | call assert_equal(7, &siso) |
| 544 | setlocal siso=0 |
| 545 | call assert_equal(0, &siso) |
| 546 | setlocal siso=-1 |
| 547 | call assert_equal(7, &siso) |
| 548 | |
| 549 | close |
| 550 | set so& |
| 551 | set siso& |
| 552 | endfunc |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 553 | |
| 554 | func Test_writedelay() |
| 555 | if !has('reltime') |
| 556 | return |
| 557 | endif |
| 558 | new |
| 559 | call setline(1, 'empty') |
| 560 | redraw |
| 561 | set writedelay=10 |
| 562 | let start = reltime() |
| 563 | call setline(1, repeat('x', 70)) |
| 564 | redraw |
| 565 | let elapsed = reltimefloat(reltime(start)) |
| 566 | set writedelay=0 |
| 567 | " With 'writedelay' set should take at least 30 * 10 msec |
| 568 | call assert_inrange(30 * 0.01, 999.0, elapsed) |
| 569 | |
| 570 | bwipe! |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 571 | endfunc |
| 572 | |
| 573 | func Test_visualbell() |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 574 | set belloff= |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 575 | set visualbell |
| 576 | call assert_beeps('normal 0h') |
| 577 | set novisualbell |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 578 | set belloff=all |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 579 | endfunc |