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