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