Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 1 | " Test for options |
| 2 | |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 5 | source view_util.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 6 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 7 | func Test_whichwrap() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 8 | set whichwrap=b,s |
| 9 | call assert_equal('b,s', &whichwrap) |
| 10 | |
| 11 | set whichwrap+=h,l |
| 12 | call assert_equal('b,s,h,l', &whichwrap) |
| 13 | |
| 14 | set whichwrap+=h,l |
| 15 | call assert_equal('b,s,h,l', &whichwrap) |
| 16 | |
| 17 | set whichwrap+=h,l |
| 18 | call assert_equal('b,s,h,l', &whichwrap) |
| 19 | |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 20 | set whichwrap=h,h |
| 21 | call assert_equal('h', &whichwrap) |
| 22 | |
| 23 | set whichwrap=h,h,h |
| 24 | call assert_equal('h', &whichwrap) |
| 25 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 26 | " For compatibility with Vim 3.0 and before, number values are also |
| 27 | " supported for 'whichwrap' |
| 28 | set whichwrap=1 |
| 29 | call assert_equal('b', &whichwrap) |
| 30 | set whichwrap=2 |
| 31 | call assert_equal('s', &whichwrap) |
| 32 | set whichwrap=4 |
| 33 | call assert_equal('h,l', &whichwrap) |
| 34 | set whichwrap=8 |
| 35 | call assert_equal('<,>', &whichwrap) |
| 36 | set whichwrap=16 |
| 37 | call assert_equal('[,]', &whichwrap) |
| 38 | set whichwrap=31 |
| 39 | call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) |
| 40 | |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 41 | set whichwrap& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 42 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 43 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 44 | func Test_isfname() |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 45 | " This used to cause Vim to access uninitialized memory. |
| 46 | set isfname= |
| 47 | call assert_equal("~X", expand("~X")) |
| 48 | set isfname& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 49 | endfunc |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 50 | |
zeertzjq | 0519ce0 | 2022-05-09 12:16:19 +0100 | [diff] [blame] | 51 | " Test for getting the value of 'pastetoggle' |
| 52 | func Test_pastetoggle() |
| 53 | " character with K_SPECIAL byte |
| 54 | let &pastetoggle = '…' |
| 55 | call assert_equal('…', &pastetoggle) |
| 56 | call assert_equal("\n pastetoggle=…", execute('set pastetoggle?')) |
| 57 | |
| 58 | " modified character with K_SPECIAL byte |
| 59 | let &pastetoggle = '<M-…>' |
| 60 | call assert_equal('<M-…>', &pastetoggle) |
| 61 | call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?')) |
| 62 | |
| 63 | " illegal bytes |
| 64 | let str = ":\x7f:\x80:\x90:\xd0:" |
| 65 | let &pastetoggle = str |
| 66 | call assert_equal(str, &pastetoggle) |
| 67 | call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?')) |
| 68 | unlet str |
| 69 | endfunc |
| 70 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 71 | func Test_wildchar() |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 72 | " Empty 'wildchar' used to access invalid memory. |
| 73 | call assert_fails('set wildchar=', 'E521:') |
| 74 | call assert_fails('set wildchar=abc', 'E521:') |
| 75 | set wildchar=<Esc> |
| 76 | let a=execute('set wildchar?') |
| 77 | call assert_equal("\n wildchar=<Esc>", a) |
| 78 | set wildchar=27 |
| 79 | let a=execute('set wildchar?') |
| 80 | call assert_equal("\n wildchar=<Esc>", a) |
| 81 | set wildchar& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 82 | endfunc |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 83 | |
Bram Moolenaar | 2e61e2d | 2020-05-22 14:10:36 +0200 | [diff] [blame] | 84 | func Test_wildoptions() |
| 85 | set wildoptions= |
| 86 | set wildoptions+=tagfile |
| 87 | set wildoptions+=tagfile |
| 88 | call assert_equal('tagfile', &wildoptions) |
| 89 | endfunc |
| 90 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 91 | func Test_options_command() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 92 | let caught = 'ok' |
| 93 | try |
| 94 | options |
| 95 | catch |
| 96 | let caught = v:throwpoint . "\n" . v:exception |
| 97 | endtry |
| 98 | call assert_equal('ok', caught) |
| 99 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 100 | " Check if the option-window is opened horizontally. |
| 101 | wincmd j |
| 102 | call assert_notequal('option-window', bufname('')) |
| 103 | wincmd k |
| 104 | call assert_equal('option-window', bufname('')) |
| 105 | " close option-window |
| 106 | close |
| 107 | |
| 108 | " Open the option-window vertically. |
| 109 | vert options |
| 110 | " Check if the option-window is opened vertically. |
| 111 | wincmd l |
| 112 | call assert_notequal('option-window', bufname('')) |
| 113 | wincmd h |
| 114 | call assert_equal('option-window', bufname('')) |
| 115 | " close option-window |
| 116 | close |
| 117 | |
Bram Moolenaar | 7a1637f | 2020-04-13 21:16:21 +0200 | [diff] [blame] | 118 | " Open the option-window at the top. |
| 119 | set splitbelow |
| 120 | topleft options |
| 121 | call assert_equal(1, winnr()) |
| 122 | close |
| 123 | |
| 124 | " Open the option-window at the bottom. |
| 125 | set nosplitbelow |
| 126 | botright options |
| 127 | call assert_equal(winnr('$'), winnr()) |
| 128 | close |
| 129 | set splitbelow& |
| 130 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 131 | " Open the option-window in a new tab. |
| 132 | tab options |
| 133 | " Check if the option-window is opened in a tab. |
| 134 | normal gT |
| 135 | call assert_notequal('option-window', bufname('')) |
| 136 | normal gt |
| 137 | call assert_equal('option-window', bufname('')) |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 138 | " close option-window |
| 139 | close |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 140 | |
| 141 | " Open the options window browse |
| 142 | if has('browse') |
| 143 | browse set |
| 144 | call assert_equal('option-window', bufname('')) |
| 145 | close |
| 146 | endif |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 147 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 148 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 149 | func Test_path_keep_commas() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 150 | " Test that changing 'path' keeps two commas. |
| 151 | set path=foo,,bar |
| 152 | set path-=bar |
| 153 | set path+=bar |
| 154 | call assert_equal('foo,,bar', &path) |
| 155 | |
| 156 | set path& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 157 | endfunc |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 158 | |
Dominique Pelle | f645ee4 | 2021-12-05 13:21:18 +0000 | [diff] [blame] | 159 | func Test_path_too_long() |
| 160 | exe 'set path=' .. repeat('x', 10000) |
| 161 | call assert_fails('find x', 'E854:') |
| 162 | set path& |
| 163 | endfunc |
| 164 | |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 165 | func Test_signcolumn() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 166 | CheckFeature signs |
| 167 | call assert_equal("auto", &signcolumn) |
| 168 | set signcolumn=yes |
| 169 | set signcolumn=no |
| 170 | call assert_fails('set signcolumn=nope') |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 171 | endfunc |
| 172 | |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 173 | func Test_filetype_valid() |
| 174 | set ft=valid_name |
| 175 | call assert_equal("valid_name", &filetype) |
| 176 | set ft=valid-name |
| 177 | call assert_equal("valid-name", &filetype) |
| 178 | |
| 179 | call assert_fails(":set ft=wrong;name", "E474:") |
| 180 | call assert_fails(":set ft=wrong\\\\name", "E474:") |
| 181 | call assert_fails(":set ft=wrong\\|name", "E474:") |
| 182 | call assert_fails(":set ft=wrong/name", "E474:") |
| 183 | call assert_fails(":set ft=wrong\\\nname", "E474:") |
| 184 | call assert_equal("valid-name", &filetype) |
| 185 | |
| 186 | exe "set ft=trunc\x00name" |
| 187 | call assert_equal("trunc", &filetype) |
| 188 | endfunc |
| 189 | |
| 190 | func Test_syntax_valid() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 191 | CheckFeature syntax |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 192 | set syn=valid_name |
| 193 | call assert_equal("valid_name", &syntax) |
| 194 | set syn=valid-name |
| 195 | call assert_equal("valid-name", &syntax) |
| 196 | |
| 197 | call assert_fails(":set syn=wrong;name", "E474:") |
| 198 | call assert_fails(":set syn=wrong\\\\name", "E474:") |
| 199 | call assert_fails(":set syn=wrong\\|name", "E474:") |
| 200 | call assert_fails(":set syn=wrong/name", "E474:") |
| 201 | call assert_fails(":set syn=wrong\\\nname", "E474:") |
| 202 | call assert_equal("valid-name", &syntax) |
| 203 | |
| 204 | exe "set syn=trunc\x00name" |
| 205 | call assert_equal("trunc", &syntax) |
| 206 | endfunc |
| 207 | |
| 208 | func Test_keymap_valid() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 209 | CheckFeature keymap |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 210 | call assert_fails(":set kmp=valid_name", "E544:") |
| 211 | call assert_fails(":set kmp=valid_name", "valid_name") |
| 212 | call assert_fails(":set kmp=valid-name", "E544:") |
| 213 | call assert_fails(":set kmp=valid-name", "valid-name") |
| 214 | |
| 215 | call assert_fails(":set kmp=wrong;name", "E474:") |
| 216 | call assert_fails(":set kmp=wrong\\\\name", "E474:") |
| 217 | call assert_fails(":set kmp=wrong\\|name", "E474:") |
| 218 | call assert_fails(":set kmp=wrong/name", "E474:") |
| 219 | call assert_fails(":set kmp=wrong\\\nname", "E474:") |
| 220 | |
| 221 | call assert_fails(":set kmp=trunc\x00name", "E544:") |
| 222 | call assert_fails(":set kmp=trunc\x00name", "trunc") |
| 223 | endfunc |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 224 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 225 | func Check_dir_option(name) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 226 | " Check that it's possible to set the option. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 227 | exe 'set ' . a:name . '=/usr/share/dict/words' |
| 228 | call assert_equal('/usr/share/dict/words', eval('&' . a:name)) |
| 229 | exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' |
| 230 | call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) |
| 231 | exe 'set ' . a:name . '=/usr/share/dict\ words' |
| 232 | call assert_equal('/usr/share/dict words', eval('&' . a:name)) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 233 | |
| 234 | " Check rejecting weird characters. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 235 | call assert_fails("set " . a:name . "=/not&there", "E474:") |
| 236 | call assert_fails("set " . a:name . "=/not>there", "E474:") |
| 237 | call assert_fails("set " . a:name . "=/not.*there", "E474:") |
| 238 | endfunc |
| 239 | |
Bram Moolenaar | 60629d6 | 2017-02-23 18:08:56 +0100 | [diff] [blame] | 240 | func Test_cinkeys() |
| 241 | " This used to cause invalid memory access |
| 242 | set cindent cinkeys=0 |
| 243 | norm a |
| 244 | set cindent& cinkeys& |
| 245 | endfunc |
| 246 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 247 | func Test_dictionary() |
| 248 | call Check_dir_option('dictionary') |
| 249 | endfunc |
| 250 | |
| 251 | func Test_thesaurus() |
| 252 | call Check_dir_option('thesaurus') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 253 | endfun |
| 254 | |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 255 | func Test_complete() |
| 256 | " Trailing single backslash used to cause invalid memory access. |
| 257 | set complete=s\ |
| 258 | new |
| 259 | call feedkeys("i\<C-N>\<Esc>", 'xt') |
| 260 | bwipe! |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 261 | call assert_fails('set complete=ix', 'E535:') |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 262 | set complete& |
| 263 | endfun |
| 264 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 265 | func Test_set_completion() |
| 266 | call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 267 | call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) |
| 268 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 269 | call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 270 | call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 271 | |
| 272 | call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 273 | call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 274 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 275 | " Expand boolan options. When doing :set no<Tab> |
| 276 | " vim displays the options names without "no" but completion uses "no...". |
| 277 | call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 278 | call assert_equal('"set nodiff digraph', @:) |
| 279 | |
| 280 | call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') |
| 281 | call assert_equal('"set invdiff digraph', @:) |
| 282 | |
| 283 | " Expand abbreviation of options. |
| 284 | call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | abdcfd1 | 2021-10-16 16:48:27 +0100 | [diff] [blame] | 285 | call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 286 | |
| 287 | " Expand current value |
| 288 | call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 289 | call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) |
| 290 | |
| 291 | call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') |
| 292 | call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) |
| 293 | |
| 294 | " Expand key codes. |
| 295 | call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') |
| 296 | call assert_equal('"set <Help> <Home>', @:) |
| 297 | |
| 298 | " Expand terminal options. |
| 299 | call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | e023e88 | 2020-05-31 16:42:30 +0200 | [diff] [blame] | 300 | call assert_equal('"set t_AB t_AF t_AU t_AL', @:) |
Bram Moolenaar | 0ff5ded | 2020-05-07 18:43:44 +0200 | [diff] [blame] | 301 | call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 302 | |
| 303 | " Expand directories. |
| 304 | call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 305 | call assert_match(' ./samples/ ', @:) |
Bram Moolenaar | b96a32e | 2020-08-13 18:59:55 +0200 | [diff] [blame] | 306 | call assert_notmatch(' ./summarize.vim ', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 307 | |
| 308 | " Expand files and directories. |
| 309 | call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | b96a32e | 2020-08-13 18:59:55 +0200 | [diff] [blame] | 310 | call assert_match(' ./samples/.* ./summarize.vim', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 311 | |
| 312 | call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') |
| 313 | call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 314 | set tags& |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 315 | |
| 316 | " Expanding the option names |
| 317 | call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') |
| 318 | call assert_equal('"set all', @:) |
| 319 | |
| 320 | " Expanding a second set of option names |
| 321 | call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt') |
| 322 | call assert_equal('"set wrapscan all', @:) |
| 323 | |
| 324 | " Expanding a special keycode |
| 325 | call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 326 | call assert_equal('"set <Home>', @:) |
| 327 | |
| 328 | " Expanding an invalid special keycode |
| 329 | call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 330 | call assert_equal("\"set <abcd>\<Tab>", @:) |
| 331 | |
| 332 | " Expanding a terminal keycode |
| 333 | call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') |
| 334 | call assert_equal("\"set t_AB", @:) |
| 335 | |
| 336 | " Expanding an invalid option name |
| 337 | call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 338 | call assert_equal("\"set abcde=\<Tab>", @:) |
| 339 | |
| 340 | " Expanding after a = for a boolean option |
| 341 | call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 342 | call assert_equal("\"set wrapscan=\<Tab>", @:) |
| 343 | |
| 344 | " Expanding a numeric option |
| 345 | call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 346 | call assert_equal("\"set tabstop+=" .. &tabstop, @:) |
| 347 | |
| 348 | " Expanding a non-boolean option |
| 349 | call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 350 | call assert_equal("\"set invtabstop=", @:) |
| 351 | |
| 352 | " Expand options for 'spellsuggest' |
| 353 | call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt') |
| 354 | call assert_equal("\"set spellsuggest=best,file:xyz", @:) |
| 355 | |
| 356 | " Expand value for 'key' |
| 357 | set key=abcd |
| 358 | call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 359 | call assert_equal('"set key=*****', @:) |
| 360 | set key= |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 361 | |
| 362 | " Expand values for 'filetype' |
| 363 | call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt') |
| 364 | call assert_equal('"set filetype=sshdconfig', @:) |
| 365 | call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 366 | call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 367 | endfunc |
| 368 | |
| 369 | func Test_set_errors() |
| 370 | call assert_fails('set scroll=-1', 'E49:') |
| 371 | call assert_fails('set backupcopy=', 'E474:') |
| 372 | call assert_fails('set regexpengine=3', 'E474:') |
| 373 | call assert_fails('set history=10001', 'E474:') |
Bram Moolenaar | f8a0712 | 2019-07-01 22:06:07 +0200 | [diff] [blame] | 374 | call assert_fails('set numberwidth=21', 'E474:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 375 | call assert_fails('set colorcolumn=-a', 'E474:') |
| 376 | call assert_fails('set colorcolumn=a', 'E474:') |
| 377 | call assert_fails('set colorcolumn=1,', 'E474:') |
| 378 | call assert_fails('set colorcolumn=1;', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 379 | call assert_fails('set cmdheight=-1', 'E487:') |
| 380 | call assert_fails('set cmdwinheight=-1', 'E487:') |
| 381 | if has('conceal') |
| 382 | call assert_fails('set conceallevel=-1', 'E487:') |
| 383 | call assert_fails('set conceallevel=4', 'E474:') |
| 384 | endif |
| 385 | call assert_fails('set helpheight=-1', 'E487:') |
| 386 | call assert_fails('set history=-1', 'E487:') |
| 387 | call assert_fails('set report=-1', 'E487:') |
| 388 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 389 | call assert_fails('set sidescroll=-1', 'E487:') |
| 390 | call assert_fails('set tabstop=-1', 'E487:') |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 391 | call assert_fails('set tabstop=10000', 'E474:') |
Bram Moolenaar | 8ccbbeb | 2022-03-02 19:49:38 +0000 | [diff] [blame] | 392 | call assert_fails('let &tabstop = 10000', 'E474:') |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 393 | call assert_fails('set tabstop=5500000000', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 394 | call assert_fails('set textwidth=-1', 'E487:') |
| 395 | call assert_fails('set timeoutlen=-1', 'E487:') |
| 396 | call assert_fails('set updatecount=-1', 'E487:') |
| 397 | call assert_fails('set updatetime=-1', 'E487:') |
| 398 | call assert_fails('set winheight=-1', 'E487:') |
| 399 | call assert_fails('set tabstop!', 'E488:') |
| 400 | call assert_fails('set xxx', 'E518:') |
| 401 | call assert_fails('set beautify?', 'E519:') |
| 402 | call assert_fails('set undolevels=x', 'E521:') |
| 403 | call assert_fails('set tabstop=', 'E521:') |
| 404 | call assert_fails('set comments=-', 'E524:') |
| 405 | call assert_fails('set comments=a', 'E525:') |
| 406 | call assert_fails('set foldmarker=x', 'E536:') |
| 407 | call assert_fails('set commentstring=x', 'E537:') |
Bram Moolenaar | 8ccbbeb | 2022-03-02 19:49:38 +0000 | [diff] [blame] | 408 | call assert_fails('let &commentstring = "x"', 'E537:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 409 | call assert_fails('set complete=x', 'E539:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 410 | call assert_fails('set rulerformat=%-', 'E539:') |
| 411 | call assert_fails('set rulerformat=%(', 'E542:') |
| 412 | call assert_fails('set rulerformat=%15(%%', 'E542:') |
| 413 | call assert_fails('set statusline=%$', 'E539:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 414 | call assert_fails('set statusline=%{', 'E540:') |
zeertzjq | 5dc294a | 2022-04-15 13:17:57 +0100 | [diff] [blame] | 415 | call assert_fails('set statusline=%{%', 'E540:') |
| 416 | call assert_fails('set statusline=%{%}', 'E539:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 417 | call assert_fails('set statusline=%(', 'E542:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 418 | call assert_fails('set statusline=%)', 'E542:') |
zeertzjq | 5dc294a | 2022-04-15 13:17:57 +0100 | [diff] [blame] | 419 | call assert_fails('set tabline=%$', 'E539:') |
| 420 | call assert_fails('set tabline=%{', 'E540:') |
| 421 | call assert_fails('set tabline=%{%', 'E540:') |
| 422 | call assert_fails('set tabline=%{%}', 'E539:') |
| 423 | call assert_fails('set tabline=%(', 'E542:') |
| 424 | call assert_fails('set tabline=%)', 'E542:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 425 | |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 426 | if has('cursorshape') |
| 427 | " This invalid value for 'guicursor' used to cause Vim to crash. |
| 428 | call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') |
| 429 | call assert_fails('set guicursor=i-ci', 'E545:') |
| 430 | call assert_fails('set guicursor=x', 'E545:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 431 | call assert_fails('set guicursor=x:', 'E546:') |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 432 | call assert_fails('set guicursor=r-cr:horx', 'E548:') |
| 433 | call assert_fails('set guicursor=r-cr:hor0', 'E549:') |
| 434 | endif |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 435 | if has('mouseshape') |
| 436 | call assert_fails('se mouseshape=i-r:x', 'E547:') |
| 437 | endif |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 438 | call assert_fails('set backupext=~ patchmode=~', 'E589:') |
| 439 | call assert_fails('set winminheight=10 winheight=9', 'E591:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 440 | set winminheight& winheight& |
| 441 | set winheight=10 winminheight=10 |
| 442 | call assert_fails('set winheight=9', 'E591:') |
| 443 | set winminheight& winheight& |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 444 | call assert_fails('set winminwidth=10 winwidth=9', 'E592:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 445 | set winminwidth& winwidth& |
| 446 | call assert_fails('set winwidth=9 winminwidth=10', 'E592:') |
| 447 | set winwidth& winminwidth& |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 448 | call assert_fails("set showbreak=\x01", 'E595:') |
| 449 | call assert_fails('set t_foo=', 'E846:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 450 | call assert_fails('set tabstop??', 'E488:') |
| 451 | call assert_fails('set wrapscan!!', 'E488:') |
| 452 | call assert_fails('set tabstop&&', 'E488:') |
| 453 | call assert_fails('set wrapscan<<', 'E488:') |
| 454 | call assert_fails('set wrapscan=1', 'E474:') |
| 455 | call assert_fails('set autoindent@', 'E488:') |
| 456 | call assert_fails('set wildchar=<abc>', 'E474:') |
| 457 | call assert_fails('set cmdheight=1a', 'E521:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 458 | call assert_fails('set invcmdheight', 'E474:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 459 | if has('python') || has('python3') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 460 | call assert_fails('set pyxversion=6', 'E474:') |
| 461 | endif |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 462 | call assert_fails("let &tabstop='ab'", 'E521:') |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 463 | call assert_fails('set spellcapcheck=%\\(', 'E54:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 464 | call assert_fails('set sessionoptions=curdir,sesdir', 'E474:') |
| 465 | call assert_fails('set foldmarker={{{,', 'E474:') |
| 466 | call assert_fails('set sessionoptions=sesdir,curdir', 'E474:') |
| 467 | call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:') |
| 468 | set listchars& |
| 469 | call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:') |
| 470 | set fillchars& |
| 471 | call assert_fails('set fileencoding=latin1,utf-8', 'E474:') |
| 472 | set nomodifiable |
| 473 | call assert_fails('set fileencoding=latin1', 'E21:') |
| 474 | set modifiable& |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 475 | call assert_fails('set t_#-&', 'E522:') |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 476 | endfunc |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 477 | |
Bram Moolenaar | 1349bd7 | 2022-02-22 12:34:28 +0000 | [diff] [blame] | 478 | func Test_set_encoding() |
| 479 | let save_encoding = &encoding |
| 480 | |
| 481 | set enc=iso8859-1 |
| 482 | call assert_equal('latin1', &enc) |
| 483 | set enc=iso8859_1 |
| 484 | call assert_equal('latin1', &enc) |
| 485 | set enc=iso-8859-1 |
| 486 | call assert_equal('latin1', &enc) |
| 487 | set enc=iso_8859_1 |
| 488 | call assert_equal('latin1', &enc) |
| 489 | set enc=iso88591 |
| 490 | call assert_equal('latin1', &enc) |
| 491 | set enc=iso8859 |
| 492 | call assert_equal('latin1', &enc) |
| 493 | set enc=iso-8859 |
| 494 | call assert_equal('latin1', &enc) |
| 495 | set enc=iso_8859 |
| 496 | call assert_equal('latin1', &enc) |
| 497 | call assert_fails('set enc=iso8858', 'E474:') |
| 498 | call assert_equal('latin1', &enc) |
| 499 | |
| 500 | let &encoding = save_encoding |
| 501 | endfunc |
| 502 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 503 | func CheckWasSet(name) |
| 504 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 505 | call assert_match('Last set from.*test_options.vim', verb_cm) |
| 506 | endfunc |
| 507 | func CheckWasNotSet(name) |
| 508 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 509 | call assert_notmatch('Last set from', verb_cm) |
| 510 | endfunc |
| 511 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 512 | " Must be executed before other tests that set 'term'. |
| 513 | func Test_000_term_option_verbose() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 514 | CheckNotGui |
| 515 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 516 | call CheckWasNotSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 517 | |
| 518 | let term_save = &term |
| 519 | set term=ansi |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 520 | call CheckWasSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 521 | let &term = term_save |
| 522 | endfunc |
| 523 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 524 | func Test_copy_context() |
| 525 | setlocal list |
| 526 | call CheckWasSet('list') |
| 527 | split |
| 528 | call CheckWasSet('list') |
| 529 | quit |
| 530 | setlocal nolist |
| 531 | |
| 532 | set ai |
| 533 | call CheckWasSet('ai') |
| 534 | set filetype=perl |
| 535 | call CheckWasSet('filetype') |
| 536 | set fo=tcroq |
| 537 | call CheckWasSet('fo') |
| 538 | |
| 539 | split Xsomebuf |
| 540 | call CheckWasSet('ai') |
| 541 | call CheckWasNotSet('filetype') |
| 542 | call CheckWasSet('fo') |
| 543 | endfunc |
| 544 | |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 545 | func Test_set_ttytype() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 546 | CheckUnix |
| 547 | CheckNotGui |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 548 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 549 | " Setting 'ttytype' used to cause a double-free when exiting vim and |
| 550 | " when vim is compiled with -DEXITFREE. |
| 551 | set ttytype=ansi |
| 552 | call assert_equal('ansi', &ttytype) |
| 553 | call assert_equal(&ttytype, &term) |
| 554 | set ttytype=xterm |
| 555 | call assert_equal('xterm', &ttytype) |
| 556 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 557 | try |
| 558 | set ttytype= |
| 559 | call assert_report('set ttytype= did not fail') |
Bram Moolenaar | 5daa911 | 2021-02-01 18:39:47 +0100 | [diff] [blame] | 560 | catch /E529/ |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 561 | endtry |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 562 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 563 | " Some systems accept any terminal name and return dumb settings, |
| 564 | " check for failure of finding the entry and for missing 'cm' entry. |
| 565 | try |
| 566 | set ttytype=xxx |
| 567 | call assert_report('set ttytype=xxx did not fail') |
| 568 | catch /E522\|E437/ |
| 569 | endtry |
| 570 | |
| 571 | set ttytype& |
| 572 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 573 | |
| 574 | if has('gui') && !has('gui_running') |
| 575 | call assert_fails('set term=gui', 'E531:') |
| 576 | endif |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 577 | endfunc |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 578 | |
| 579 | func Test_set_all() |
| 580 | set tw=75 |
| 581 | set iskeyword=a-z,A-Z |
| 582 | set nosplitbelow |
| 583 | let out = execute('set all') |
| 584 | call assert_match('textwidth=75', out) |
| 585 | call assert_match('iskeyword=a-z,A-Z', out) |
| 586 | call assert_match('nosplitbelow', out) |
| 587 | set tw& iskeyword& splitbelow& |
| 588 | endfunc |
| 589 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 590 | func Test_set_one_column() |
| 591 | let out_mult = execute('set all')->split("\n") |
| 592 | let out_one = execute('set! all')->split("\n") |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 593 | call assert_true(len(out_mult) < len(out_one)) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 594 | endfunc |
| 595 | |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 596 | func Test_set_values() |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 597 | " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 598 | if filereadable('opt_test.vim') |
| 599 | source opt_test.vim |
Bram Moolenaar | e8512d7 | 2017-03-07 22:33:32 +0100 | [diff] [blame] | 600 | else |
| 601 | throw 'Skipped: opt_test.vim does not exist' |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 602 | endif |
| 603 | endfunc |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 604 | |
Bram Moolenaar | 0c1e374 | 2019-12-27 13:49:24 +0100 | [diff] [blame] | 605 | func Test_renderoptions() |
| 606 | " Only do this for Windows Vista and later, fails on Windows XP and earlier. |
| 607 | " Doesn't hurt to do this on a non-Windows system. |
| 608 | if windowsversion() !~ '^[345]\.' |
| 609 | set renderoptions=type:directx |
| 610 | set rop=type:directx |
| 611 | endif |
| 612 | endfunc |
| 613 | |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 614 | func ResetIndentexpr() |
| 615 | set indentexpr= |
| 616 | endfunc |
| 617 | |
| 618 | func Test_set_indentexpr() |
| 619 | " this was causing usage of freed memory |
| 620 | set indentexpr=ResetIndentexpr() |
| 621 | new |
| 622 | call feedkeys("i\<c-f>", 'x') |
| 623 | call assert_equal('', &indentexpr) |
| 624 | bwipe! |
| 625 | endfunc |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 626 | |
| 627 | func Test_backupskip() |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 628 | " Option 'backupskip' may contain several comma-separated path |
| 629 | " specifications if one or more of the environment variables TMPDIR, TMP, |
| 630 | " or TEMP is defined. To simplify testing, convert the string value into a |
| 631 | " list. |
| 632 | let bsklist = split(&bsk, ',') |
| 633 | |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 634 | if has("mac") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 635 | let found = (index(bsklist, '/private/tmp/*') >= 0) |
| 636 | call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 637 | elseif has("unix") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 638 | let found = (index(bsklist, '/tmp/*') >= 0) |
| 639 | call assert_true(found, '/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 640 | endif |
| 641 | |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 642 | " If our test platform is Windows, the path(s) in option bsk will use |
| 643 | " backslash for the path separator and the components could be in short |
| 644 | " (8.3) format. As such, we need to replace the backslashes with forward |
| 645 | " slashes and convert the path components to long format. The expand() |
| 646 | " function will do this but it cannot handle comma-separated paths. This is |
| 647 | " why bsk was converted from a string into a list of strings above. |
| 648 | " |
| 649 | " One final complication is that the wildcard "/*" is at the end of each |
| 650 | " path and so expand() might return a list of matching files. To prevent |
| 651 | " this, we need to remove the wildcard before calling expand() and then |
| 652 | " append it afterwards. |
| 653 | if has('win32') |
| 654 | let item_nbr = 0 |
| 655 | while item_nbr < len(bsklist) |
| 656 | let path_spec = bsklist[item_nbr] |
| 657 | let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) |
| 658 | let path_spec = substitute(expand(path_spec), '\\', '/', 'g') |
| 659 | let bsklist[item_nbr] = path_spec . '/*' |
| 660 | let item_nbr += 1 |
| 661 | endwhile |
| 662 | endif |
| 663 | |
| 664 | " Option bsk will also include these environment variables if defined. |
| 665 | " If they're defined, verify they appear in the option value. |
| 666 | for var in ['$TMPDIR', '$TMP', '$TEMP'] |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 667 | if exists(var) |
| 668 | let varvalue = substitute(expand(var), '\\', '/', 'g') |
Bram Moolenaar | cbbd0f6 | 2019-01-30 22:36:18 +0100 | [diff] [blame] | 669 | let varvalue = substitute(varvalue, '/$', '', '') |
| 670 | let varvalue .= '/*' |
| 671 | let found = (index(bsklist, varvalue) >= 0) |
| 672 | call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 673 | endif |
| 674 | endfor |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 675 | |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 676 | " Duplicates from environment variables should be filtered out (option has |
| 677 | " P_NODUP). Run this in a separate instance and write v:errors in a file, |
| 678 | " so that we see what happens on startup. |
| 679 | let after =<< trim [CODE] |
| 680 | let bsklist = split(&backupskip, ',') |
| 681 | call assert_equal(uniq(copy(bsklist)), bsklist) |
| 682 | call writefile(['errors:'] + v:errors, 'Xtestout') |
| 683 | qall |
| 684 | [CODE] |
| 685 | call writefile(after, 'Xafter') |
| 686 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 687 | |
| 688 | let saveenv = {} |
| 689 | for var in ['TMPDIR', 'TMP', 'TEMP'] |
| 690 | let saveenv[var] = getenv(var) |
| 691 | call setenv(var, '/duplicate/path') |
| 692 | endfor |
| 693 | |
| 694 | exe 'silent !' . cmd |
| 695 | call assert_equal(['errors:'], readfile('Xtestout')) |
| 696 | |
| 697 | " restore environment variables |
| 698 | for var in ['TMPDIR', 'TMP', 'TEMP'] |
| 699 | call setenv(var, saveenv[var]) |
| 700 | endfor |
| 701 | |
| 702 | call delete('Xtestout') |
| 703 | call delete('Xafter') |
| 704 | |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 705 | " Duplicates should be filtered out (option has P_NODUP) |
| 706 | let backupskip = &backupskip |
| 707 | set backupskip= |
| 708 | set backupskip+=/test/dir |
| 709 | set backupskip+=/other/dir |
| 710 | set backupskip+=/test/dir |
| 711 | call assert_equal('/test/dir,/other/dir', &backupskip) |
| 712 | let &backupskip = backupskip |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 713 | endfunc |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 714 | |
| 715 | func Test_copy_winopt() |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 716 | set hidden |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 717 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 718 | " Test copy option from current buffer in window |
| 719 | split |
| 720 | enew |
| 721 | setlocal numberwidth=5 |
| 722 | wincmd w |
| 723 | call assert_equal(4,&numberwidth) |
| 724 | bnext |
| 725 | call assert_equal(5,&numberwidth) |
| 726 | bw! |
| 727 | call assert_equal(4,&numberwidth) |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 728 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 729 | " Test copy value from window that used to be display the buffer |
| 730 | split |
| 731 | enew |
| 732 | setlocal numberwidth=6 |
| 733 | bnext |
| 734 | wincmd w |
| 735 | call assert_equal(4,&numberwidth) |
| 736 | bnext |
| 737 | call assert_equal(6,&numberwidth) |
| 738 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 739 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 740 | " Test that if buffer is current, don't use the stale cached value |
| 741 | " from the last time the buffer was displayed. |
| 742 | split |
| 743 | enew |
| 744 | setlocal numberwidth=7 |
| 745 | bnext |
| 746 | bnext |
| 747 | setlocal numberwidth=8 |
| 748 | wincmd w |
| 749 | call assert_equal(4,&numberwidth) |
| 750 | bnext |
| 751 | call assert_equal(8,&numberwidth) |
| 752 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 753 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 754 | " Test value is not copied if window already has seen the buffer |
| 755 | enew |
| 756 | split |
| 757 | setlocal numberwidth=9 |
| 758 | bnext |
| 759 | setlocal numberwidth=10 |
| 760 | wincmd w |
| 761 | call assert_equal(4,&numberwidth) |
| 762 | bnext |
| 763 | call assert_equal(4,&numberwidth) |
| 764 | bw! |
| 765 | |
| 766 | set hidden& |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 767 | endfunc |
Bram Moolenaar | fc08960 | 2018-06-24 16:53:35 +0200 | [diff] [blame] | 768 | |
| 769 | func Test_shortmess_F() |
| 770 | new |
| 771 | call assert_match('\[No Name\]', execute('file')) |
| 772 | set shortmess+=F |
| 773 | call assert_match('\[No Name\]', execute('file')) |
| 774 | call assert_match('^\s*$', execute('file foo')) |
| 775 | call assert_match('foo', execute('file')) |
| 776 | set shortmess-=F |
| 777 | call assert_match('bar', execute('file bar')) |
| 778 | call assert_match('bar', execute('file')) |
| 779 | set shortmess& |
| 780 | bwipe |
| 781 | endfunc |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 782 | |
| 783 | func Test_shortmess_F2() |
| 784 | e file1 |
| 785 | e file2 |
| 786 | call assert_match('file1', execute('bn', '')) |
| 787 | call assert_match('file2', execute('bn', '')) |
| 788 | set shortmess+=F |
| 789 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 790 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 791 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 792 | call assert_false('need_fileinfo'->test_getvalue()) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 793 | set hidden |
| 794 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 795 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 796 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 797 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 798 | set nohidden |
| 799 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 800 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 801 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 802 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 803 | set shortmess& |
| 804 | call assert_match('file1', execute('bn', '')) |
| 805 | call assert_match('file2', execute('bn', '')) |
| 806 | bwipe |
| 807 | bwipe |
| 808 | endfunc |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 809 | |
| 810 | func Test_local_scrolloff() |
| 811 | set so=5 |
| 812 | set siso=7 |
| 813 | split |
| 814 | call assert_equal(5, &so) |
| 815 | setlocal so=3 |
| 816 | call assert_equal(3, &so) |
| 817 | wincmd w |
| 818 | call assert_equal(5, &so) |
| 819 | wincmd w |
| 820 | setlocal so< |
| 821 | call assert_equal(5, &so) |
| 822 | setlocal so=0 |
| 823 | call assert_equal(0, &so) |
| 824 | setlocal so=-1 |
| 825 | call assert_equal(5, &so) |
| 826 | |
| 827 | call assert_equal(7, &siso) |
| 828 | setlocal siso=3 |
| 829 | call assert_equal(3, &siso) |
| 830 | wincmd w |
| 831 | call assert_equal(7, &siso) |
| 832 | wincmd w |
| 833 | setlocal siso< |
| 834 | call assert_equal(7, &siso) |
| 835 | setlocal siso=0 |
| 836 | call assert_equal(0, &siso) |
| 837 | setlocal siso=-1 |
| 838 | call assert_equal(7, &siso) |
| 839 | |
| 840 | close |
| 841 | set so& |
| 842 | set siso& |
| 843 | endfunc |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 844 | |
| 845 | func Test_writedelay() |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 846 | CheckFunction reltimefloat |
| 847 | |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 848 | new |
| 849 | call setline(1, 'empty') |
| 850 | redraw |
| 851 | set writedelay=10 |
| 852 | let start = reltime() |
| 853 | call setline(1, repeat('x', 70)) |
| 854 | redraw |
| 855 | let elapsed = reltimefloat(reltime(start)) |
| 856 | set writedelay=0 |
| 857 | " With 'writedelay' set should take at least 30 * 10 msec |
| 858 | call assert_inrange(30 * 0.01, 999.0, elapsed) |
| 859 | |
| 860 | bwipe! |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 861 | endfunc |
| 862 | |
| 863 | func Test_visualbell() |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 864 | set belloff= |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 865 | set visualbell |
| 866 | call assert_beeps('normal 0h') |
| 867 | set novisualbell |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 868 | set belloff=all |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 869 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 870 | |
| 871 | " Test for the 'write' option |
| 872 | func Test_write() |
| 873 | new |
| 874 | call setline(1, ['L1']) |
| 875 | set nowrite |
| 876 | call assert_fails('write Xfile', 'E142:') |
| 877 | set write |
| 878 | close! |
| 879 | endfunc |
| 880 | |
| 881 | " Test for 'buftype' option |
| 882 | func Test_buftype() |
| 883 | new |
| 884 | call setline(1, ['L1']) |
| 885 | set buftype=nowrite |
| 886 | call assert_fails('write', 'E382:') |
Bram Moolenaar | a3a9c8e | 2020-03-19 12:38:34 +0100 | [diff] [blame] | 887 | |
| 888 | for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] |
| 889 | exe 'set buftype=' .. val |
| 890 | call writefile(['something'], 'XBuftype') |
| 891 | call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) |
| 892 | endfor |
| 893 | |
| 894 | call delete('XBuftype') |
| 895 | bwipe! |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 896 | endfunc |
| 897 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 898 | " Test for the 'rightleftcmd' option |
| 899 | func Test_rightleftcmd() |
| 900 | CheckFeature rightleft |
| 901 | set rightleft |
| 902 | set rightleftcmd |
| 903 | |
| 904 | let g:l = [] |
| 905 | func AddPos() |
| 906 | call add(g:l, screencol()) |
| 907 | return '' |
| 908 | endfunc |
| 909 | cmap <expr> <F2> AddPos() |
| 910 | |
| 911 | call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. |
| 912 | \ "\<Left>\<F2>\<Esc>", 'xt') |
| 913 | call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) |
| 914 | |
| 915 | cunmap <F2> |
| 916 | unlet g:l |
| 917 | set rightleftcmd& |
| 918 | set rightleft& |
| 919 | endfunc |
| 920 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 921 | " Test for the "debug" option |
| 922 | func Test_debug_option() |
| 923 | set debug=beep |
| 924 | exe "normal \<C-c>" |
| 925 | call assert_equal('Beep!', Screenline(&lines)) |
| 926 | set debug& |
| 927 | endfunc |
| 928 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 929 | " Test for the default CDPATH option |
| 930 | func Test_opt_default_cdpath() |
| 931 | CheckFeature file_in_path |
| 932 | let after =<< trim [CODE] |
| 933 | call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) |
| 934 | call writefile(v:errors, 'Xtestout') |
| 935 | qall |
| 936 | [CODE] |
| 937 | if has('unix') |
| 938 | let $CDPATH='/path/to/dir1:/path/to/dir2' |
| 939 | else |
| 940 | let $CDPATH='/path/to/dir1;/path/to/dir2' |
| 941 | endif |
| 942 | if RunVim([], after, '') |
| 943 | call assert_equal([], readfile('Xtestout')) |
| 944 | call delete('Xtestout') |
| 945 | endif |
| 946 | endfunc |
| 947 | |
| 948 | " Test for setting keycodes using set |
| 949 | func Test_opt_set_keycode() |
| 950 | call assert_fails('set <t_k1=l', 'E474:') |
| 951 | call assert_fails('set <Home=l', 'E474:') |
| 952 | set <t_k9>=abcd |
| 953 | call assert_equal('abcd', &t_k9) |
| 954 | set <t_k9>& |
| 955 | set <F9>=xyz |
| 956 | call assert_equal('xyz', &t_k9) |
| 957 | set <t_k9>& |
| 958 | endfunc |
| 959 | |
| 960 | " Test for changing options in a sandbox |
| 961 | func Test_opt_sandbox() |
| 962 | for opt in ['backupdir', 'cdpath', 'exrc'] |
| 963 | call assert_fails('sandbox set ' .. opt .. '?', 'E48:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 964 | call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 965 | endfor |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 966 | call assert_fails('sandbox let &modelineexpr = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 967 | endfunc |
| 968 | |
| 969 | " Test for setting an option with local value to global value |
| 970 | func Test_opt_local_to_global() |
| 971 | setglobal equalprg=gprg |
| 972 | setlocal equalprg=lprg |
| 973 | call assert_equal('gprg', &g:equalprg) |
| 974 | call assert_equal('lprg', &l:equalprg) |
| 975 | call assert_equal('lprg', &equalprg) |
| 976 | set equalprg< |
| 977 | call assert_equal('', &l:equalprg) |
| 978 | call assert_equal('gprg', &equalprg) |
| 979 | setglobal equalprg=gnewprg |
| 980 | setlocal equalprg=lnewprg |
| 981 | setlocal equalprg< |
| 982 | call assert_equal('gnewprg', &l:equalprg) |
| 983 | call assert_equal('gnewprg', &equalprg) |
| 984 | set equalprg& |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 985 | |
| 986 | " Test for setting the global/local value of a boolean option |
| 987 | setglobal autoread |
| 988 | setlocal noautoread |
| 989 | call assert_false(&autoread) |
| 990 | set autoread< |
| 991 | call assert_true(&autoread) |
| 992 | setglobal noautoread |
| 993 | setlocal autoread |
| 994 | setlocal autoread< |
| 995 | call assert_false(&autoread) |
| 996 | set autoread& |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 997 | endfunc |
| 998 | |
Dominique Pelle | 042414f | 2021-07-12 21:43:19 +0200 | [diff] [blame] | 999 | func Test_set_in_sandbox() |
| 1000 | " Some boolean options cannot be set in sandbox, some can. |
| 1001 | call assert_fails('sandbox set modelineexpr', 'E48:') |
| 1002 | sandbox set number |
| 1003 | call assert_true(&number) |
| 1004 | set number& |
| 1005 | |
| 1006 | " Some boolean options cannot be set in sandbox, some can. |
| 1007 | if has('python') || has('python3') |
| 1008 | call assert_fails('sandbox set pyxversion=3', 'E48:') |
| 1009 | endif |
| 1010 | sandbox set tabstop=4 |
| 1011 | call assert_equal(4, &tabstop) |
| 1012 | set tabstop& |
| 1013 | |
| 1014 | " Some string options cannot be set in sandbox, some can. |
| 1015 | call assert_fails('sandbox set backupdir=/tmp', 'E48:') |
| 1016 | sandbox set filetype=perl |
| 1017 | call assert_equal('perl', &filetype) |
| 1018 | set filetype& |
| 1019 | endfunc |
| 1020 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1021 | " Test for incrementing, decrementing and multiplying a number option value |
| 1022 | func Test_opt_num_op() |
| 1023 | set shiftwidth=4 |
| 1024 | set sw+=2 |
| 1025 | call assert_equal(6, &sw) |
| 1026 | set sw-=2 |
| 1027 | call assert_equal(4, &sw) |
| 1028 | set sw^=2 |
| 1029 | call assert_equal(8, &sw) |
| 1030 | set shiftwidth& |
| 1031 | endfunc |
| 1032 | |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1033 | " Test for setting option values using v:false and v:true |
| 1034 | func Test_opt_boolean() |
| 1035 | set number& |
| 1036 | set number |
| 1037 | call assert_equal(1, &nu) |
| 1038 | set nonu |
| 1039 | call assert_equal(0, &nu) |
| 1040 | let &nu = v:true |
| 1041 | call assert_equal(1, &nu) |
| 1042 | let &nu = v:false |
| 1043 | call assert_equal(0, &nu) |
| 1044 | set number& |
| 1045 | endfunc |
| 1046 | |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 1047 | " Test for the 'window' option |
| 1048 | func Test_window_opt() |
| 1049 | " Needs only one open widow |
| 1050 | %bw! |
| 1051 | call setline(1, range(1, 8)) |
| 1052 | set window=5 |
| 1053 | exe "normal \<C-F>" |
| 1054 | call assert_equal(4, line('w0')) |
| 1055 | exe "normal \<C-F>" |
| 1056 | call assert_equal(7, line('w0')) |
| 1057 | exe "normal \<C-F>" |
| 1058 | call assert_equal(8, line('w0')) |
| 1059 | exe "normal \<C-B>" |
| 1060 | call assert_equal(5, line('w0')) |
| 1061 | exe "normal \<C-B>" |
| 1062 | call assert_equal(2, line('w0')) |
| 1063 | exe "normal \<C-B>" |
| 1064 | call assert_equal(1, line('w0')) |
| 1065 | set window=1 |
| 1066 | exe "normal gg\<C-F>" |
| 1067 | call assert_equal(2, line('w0')) |
| 1068 | exe "normal \<C-F>" |
| 1069 | call assert_equal(3, line('w0')) |
| 1070 | exe "normal \<C-B>" |
| 1071 | call assert_equal(2, line('w0')) |
| 1072 | exe "normal \<C-B>" |
| 1073 | call assert_equal(1, line('w0')) |
| 1074 | enew! |
| 1075 | set window& |
| 1076 | endfunc |
| 1077 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1078 | " Test for the 'winminheight' option |
| 1079 | func Test_opt_winminheight() |
| 1080 | only! |
| 1081 | let &winheight = &lines + 4 |
| 1082 | call assert_fails('let &winminheight = &lines + 2', 'E36:') |
| 1083 | call assert_true(&winminheight <= &lines) |
| 1084 | set winminheight& |
| 1085 | set winheight& |
| 1086 | endfunc |
| 1087 | |
Bram Moolenaar | 39d4cab | 2021-03-01 21:02:46 +0100 | [diff] [blame] | 1088 | func Test_opt_winminheight_term() |
| 1089 | CheckRunVimInTerminal |
| 1090 | |
| 1091 | " The tabline should be taken into account. |
| 1092 | let lines =<< trim END |
| 1093 | set wmh=0 stal=2 |
| 1094 | below sp | wincmd _ |
| 1095 | below sp | wincmd _ |
| 1096 | below sp | wincmd _ |
| 1097 | below sp |
| 1098 | END |
| 1099 | call writefile(lines, 'Xwinminheight') |
| 1100 | let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) |
| 1101 | call term_sendkeys(buf, ":set wmh=1\n") |
| 1102 | call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) |
| 1103 | |
| 1104 | call StopVimInTerminal(buf) |
| 1105 | call delete('Xwinminheight') |
| 1106 | endfunc |
| 1107 | |
Bram Moolenaar | 9e813b3 | 2021-03-13 14:29:05 +0100 | [diff] [blame] | 1108 | func Test_opt_winminheight_term_tabs() |
| 1109 | CheckRunVimInTerminal |
| 1110 | |
| 1111 | " The tabline should be taken into account. |
| 1112 | let lines =<< trim END |
| 1113 | set wmh=0 stal=2 |
| 1114 | split |
| 1115 | split |
| 1116 | split |
| 1117 | split |
| 1118 | tabnew |
| 1119 | END |
| 1120 | call writefile(lines, 'Xwinminheight') |
| 1121 | let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) |
| 1122 | call term_sendkeys(buf, ":set wmh=1\n") |
| 1123 | call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) |
| 1124 | |
| 1125 | call StopVimInTerminal(buf) |
| 1126 | call delete('Xwinminheight') |
| 1127 | endfunc |
| 1128 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1129 | " Test for the 'winminwidth' option |
| 1130 | func Test_opt_winminwidth() |
| 1131 | only! |
| 1132 | let &winwidth = &columns + 4 |
| 1133 | call assert_fails('let &winminwidth = &columns + 2', 'E36:') |
| 1134 | call assert_true(&winminwidth <= &columns) |
| 1135 | set winminwidth& |
| 1136 | set winwidth& |
| 1137 | endfunc |
| 1138 | |
Bram Moolenaar | 994b89d | 2020-08-07 19:12:41 +0200 | [diff] [blame] | 1139 | " Test for setting option value containing spaces with isfname+=32 |
| 1140 | func Test_isfname_with_options() |
| 1141 | set isfname+=32 |
| 1142 | setlocal keywordprg=:term\ help.exe |
| 1143 | call assert_equal(':term help.exe', &keywordprg) |
| 1144 | set isfname& |
| 1145 | setlocal keywordprg& |
| 1146 | endfunc |
| 1147 | |
Bram Moolenaar | 7466706 | 2020-12-28 15:41:41 +0100 | [diff] [blame] | 1148 | " Test that resetting laststatus does change scroll option |
| 1149 | func Test_opt_reset_scroll() |
| 1150 | CheckRunVimInTerminal |
| 1151 | let vimrc =<< trim [CODE] |
| 1152 | set scroll=2 |
| 1153 | set laststatus=2 |
| 1154 | [CODE] |
| 1155 | call writefile(vimrc, 'Xscroll') |
| 1156 | let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45}) |
| 1157 | call term_sendkeys(buf, ":verbose set scroll?\n") |
| 1158 | call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))}) |
| 1159 | call assert_match('^\s*scroll=7$', term_getline(buf, 14)) |
| 1160 | call StopVimInTerminal(buf) |
| 1161 | |
| 1162 | " clean up |
| 1163 | call delete('Xscroll') |
| 1164 | endfunc |
| 1165 | |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 1166 | " Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm' |
| 1167 | func Test_VIM_POSIX() |
| 1168 | let saved_VIM_POSIX = getenv("VIM_POSIX") |
| 1169 | |
| 1170 | call setenv('VIM_POSIX', "1") |
| 1171 | let after =<< trim [CODE] |
| 1172 | call writefile([&cpo, &shm], 'X_VIM_POSIX') |
| 1173 | qall |
| 1174 | [CODE] |
| 1175 | if RunVim([], after, '') |
| 1176 | call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;', |
| 1177 | \ 'AS'], readfile('X_VIM_POSIX')) |
| 1178 | endif |
| 1179 | |
| 1180 | call setenv('VIM_POSIX', v:null) |
| 1181 | let after =<< trim [CODE] |
| 1182 | call writefile([&cpo, &shm], 'X_VIM_POSIX') |
| 1183 | qall |
| 1184 | [CODE] |
| 1185 | if RunVim([], after, '') |
| 1186 | call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;', |
| 1187 | \ 'S'], readfile('X_VIM_POSIX')) |
| 1188 | endif |
| 1189 | |
| 1190 | call delete('X_VIM_POSIX') |
| 1191 | call setenv('VIM_POSIX', saved_VIM_POSIX) |
| 1192 | endfunc |
| 1193 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1194 | " Test for setting an option to a Vi or Vim default |
| 1195 | func Test_opt_default() |
| 1196 | set formatoptions&vi |
| 1197 | call assert_equal('vt', &formatoptions) |
| 1198 | set formatoptions&vim |
| 1199 | call assert_equal('tcq', &formatoptions) |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 1200 | |
| 1201 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
| 1202 | set fencs=latin1 |
| 1203 | set fencs& |
| 1204 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
| 1205 | set fencs=latin1 |
| 1206 | set all& |
| 1207 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1208 | endfunc |
| 1209 | |
| 1210 | " Test for the 'cmdheight' option |
| 1211 | func Test_cmdheight() |
| 1212 | %bw! |
| 1213 | let ht = &lines |
| 1214 | set cmdheight=9999 |
| 1215 | call assert_equal(1, winheight(0)) |
| 1216 | call assert_equal(ht - 1, &cmdheight) |
| 1217 | set cmdheight& |
| 1218 | endfunc |
| 1219 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 1220 | " To specify a control character as an option value, '^' can be used |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 1221 | func Test_opt_control_char() |
| 1222 | set wildchar=^v |
| 1223 | call assert_equal("\<C-V>", nr2char(&wildchar)) |
| 1224 | set wildcharm=^r |
| 1225 | call assert_equal("\<C-R>", nr2char(&wildcharm)) |
| 1226 | " Bug: This doesn't work for the 'cedit' and 'termwinkey' options |
| 1227 | set wildchar& wildcharm& |
| 1228 | endfunc |
| 1229 | |
| 1230 | " Test for the 'errorbells' option |
| 1231 | func Test_opt_errorbells() |
| 1232 | set errorbells |
| 1233 | call assert_beeps('s/a1b2/x1y2/') |
| 1234 | set noerrorbells |
| 1235 | endfunc |
| 1236 | |
Dominique Pelle | 042414f | 2021-07-12 21:43:19 +0200 | [diff] [blame] | 1237 | func Test_opt_scrolljump() |
| 1238 | help |
| 1239 | resize 10 |
| 1240 | |
| 1241 | " Test with positive 'scrolljump'. |
| 1242 | set scrolljump=2 |
| 1243 | norm! Lj |
| 1244 | call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, |
| 1245 | \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0}, |
| 1246 | \ winsaveview()) |
| 1247 | |
| 1248 | " Test with negative 'scrolljump' (percentage of window height). |
| 1249 | set scrolljump=-40 |
| 1250 | norm! ggLj |
| 1251 | call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, |
| 1252 | \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0}, |
| 1253 | \ winsaveview()) |
| 1254 | |
| 1255 | set scrolljump& |
| 1256 | bw |
| 1257 | endfunc |
| 1258 | |
Bakudankun | 29f3a45 | 2021-12-11 12:28:08 +0000 | [diff] [blame] | 1259 | " Test for the 'cdhome' option |
| 1260 | func Test_opt_cdhome() |
| 1261 | if has('unix') || has('vms') |
| 1262 | throw 'Skipped: only works on non-Unix' |
| 1263 | endif |
| 1264 | |
| 1265 | set cdhome& |
| 1266 | call assert_equal(0, &cdhome) |
| 1267 | set cdhome |
| 1268 | |
| 1269 | " This paragraph is copied from Test_cd_no_arg(). |
| 1270 | let path = getcwd() |
| 1271 | cd |
| 1272 | call assert_equal($HOME, getcwd()) |
| 1273 | call assert_notequal(path, getcwd()) |
| 1274 | exe 'cd ' .. fnameescape(path) |
| 1275 | call assert_equal(path, getcwd()) |
| 1276 | |
| 1277 | set cdhome& |
| 1278 | endfunc |
| 1279 | |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 1280 | func Test_set_completion_2() |
| 1281 | CheckOption termguicolors |
| 1282 | |
| 1283 | " Test default option completion |
| 1284 | set wildoptions= |
| 1285 | call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1286 | call assert_equal('"set termguicolors', @:) |
| 1287 | |
| 1288 | call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1289 | call assert_equal('"set notermguicolors', @:) |
| 1290 | |
| 1291 | " Test fuzzy option completion |
| 1292 | set wildoptions=fuzzy |
| 1293 | call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1294 | call assert_equal('"set termguicolors termencoding', @:) |
| 1295 | |
| 1296 | call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1297 | call assert_equal('"set notermguicolors', @:) |
| 1298 | |
| 1299 | set wildoptions= |
| 1300 | endfunc |
| 1301 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 1302 | " vim: shiftwidth=2 sts=2 expandtab |