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