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