Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 1 | " Test for options |
| 2 | |
Milly | 6eca04e | 2024-10-21 22:20:51 +0200 | [diff] [blame] | 3 | scriptencoding utf-8 |
| 4 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 5 | func Test_whichwrap() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 6 | set whichwrap=b,s |
| 7 | call assert_equal('b,s', &whichwrap) |
| 8 | |
| 9 | set whichwrap+=h,l |
| 10 | call assert_equal('b,s,h,l', &whichwrap) |
| 11 | |
| 12 | set whichwrap+=h,l |
| 13 | call assert_equal('b,s,h,l', &whichwrap) |
| 14 | |
| 15 | set whichwrap+=h,l |
| 16 | call assert_equal('b,s,h,l', &whichwrap) |
| 17 | |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 18 | set whichwrap=h,h |
| 19 | call assert_equal('h', &whichwrap) |
| 20 | |
| 21 | set whichwrap=h,h,h |
| 22 | call assert_equal('h', &whichwrap) |
| 23 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 24 | " For compatibility with Vim 3.0 and before, number values are also |
| 25 | " supported for 'whichwrap' |
| 26 | set whichwrap=1 |
| 27 | call assert_equal('b', &whichwrap) |
| 28 | set whichwrap=2 |
| 29 | call assert_equal('s', &whichwrap) |
| 30 | set whichwrap=4 |
| 31 | call assert_equal('h,l', &whichwrap) |
| 32 | set whichwrap=8 |
| 33 | call assert_equal('<,>', &whichwrap) |
| 34 | set whichwrap=16 |
| 35 | call assert_equal('[,]', &whichwrap) |
| 36 | set whichwrap=31 |
| 37 | call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) |
| 38 | |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 39 | set whichwrap& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 40 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 41 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 42 | func Test_isfname() |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 43 | " This used to cause Vim to access uninitialized memory. |
| 44 | set isfname= |
| 45 | call assert_equal("~X", expand("~X")) |
| 46 | set isfname& |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 47 | " Test for setting 'isfname' to an unsupported character |
| 48 | let save_isfname = &isfname |
| 49 | call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:') |
| 50 | call assert_equal(save_isfname, &isfname) |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 51 | endfunc |
Bram Moolenaar | 187a4f2 | 2017-02-23 17:07:14 +0100 | [diff] [blame] | 52 | |
zeertzjq | 0519ce0 | 2022-05-09 12:16:19 +0100 | [diff] [blame] | 53 | " Test for getting the value of 'pastetoggle' |
| 54 | func Test_pastetoggle() |
| 55 | " character with K_SPECIAL byte |
| 56 | let &pastetoggle = '…' |
| 57 | call assert_equal('…', &pastetoggle) |
| 58 | call assert_equal("\n pastetoggle=…", execute('set pastetoggle?')) |
| 59 | |
| 60 | " modified character with K_SPECIAL byte |
| 61 | let &pastetoggle = '<M-…>' |
| 62 | call assert_equal('<M-…>', &pastetoggle) |
| 63 | call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?')) |
| 64 | |
| 65 | " illegal bytes |
| 66 | let str = ":\x7f:\x80:\x90:\xd0:" |
| 67 | let &pastetoggle = str |
| 68 | call assert_equal(str, &pastetoggle) |
| 69 | call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?')) |
zeertzjq | bb404f5 | 2022-07-23 06:25:29 +0100 | [diff] [blame] | 70 | |
zeertzjq | 0519ce0 | 2022-05-09 12:16:19 +0100 | [diff] [blame] | 71 | unlet str |
zeertzjq | bb404f5 | 2022-07-23 06:25:29 +0100 | [diff] [blame] | 72 | set pastetoggle& |
zeertzjq | 0519ce0 | 2022-05-09 12:16:19 +0100 | [diff] [blame] | 73 | endfunc |
| 74 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 75 | func Test_wildchar() |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 76 | " Empty 'wildchar' used to access invalid memory. |
| 77 | call assert_fails('set wildchar=', 'E521:') |
| 78 | call assert_fails('set wildchar=abc', 'E521:') |
| 79 | set wildchar=<Esc> |
| 80 | let a=execute('set wildchar?') |
| 81 | call assert_equal("\n wildchar=<Esc>", a) |
| 82 | set wildchar=27 |
| 83 | let a=execute('set wildchar?') |
| 84 | call assert_equal("\n wildchar=<Esc>", a) |
| 85 | set wildchar& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 86 | endfunc |
Bram Moolenaar | a12e403 | 2017-02-25 21:37:57 +0100 | [diff] [blame] | 87 | |
Bram Moolenaar | 2e61e2d | 2020-05-22 14:10:36 +0200 | [diff] [blame] | 88 | func Test_wildoptions() |
| 89 | set wildoptions= |
| 90 | set wildoptions+=tagfile |
| 91 | set wildoptions+=tagfile |
| 92 | call assert_equal('tagfile', &wildoptions) |
| 93 | endfunc |
| 94 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 95 | func Test_options_command() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 96 | let caught = 'ok' |
| 97 | try |
| 98 | options |
| 99 | catch |
| 100 | let caught = v:throwpoint . "\n" . v:exception |
| 101 | endtry |
| 102 | call assert_equal('ok', caught) |
| 103 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 104 | " Check if the option-window is opened horizontally. |
| 105 | wincmd j |
| 106 | call assert_notequal('option-window', bufname('')) |
| 107 | wincmd k |
| 108 | call assert_equal('option-window', bufname('')) |
| 109 | " close option-window |
| 110 | close |
| 111 | |
| 112 | " Open the option-window vertically. |
| 113 | vert options |
| 114 | " Check if the option-window is opened vertically. |
| 115 | wincmd l |
| 116 | call assert_notequal('option-window', bufname('')) |
| 117 | wincmd h |
| 118 | call assert_equal('option-window', bufname('')) |
| 119 | " close option-window |
| 120 | close |
| 121 | |
Bram Moolenaar | 7a1637f | 2020-04-13 21:16:21 +0200 | [diff] [blame] | 122 | " Open the option-window at the top. |
| 123 | set splitbelow |
| 124 | topleft options |
| 125 | call assert_equal(1, winnr()) |
| 126 | close |
| 127 | |
| 128 | " Open the option-window at the bottom. |
| 129 | set nosplitbelow |
| 130 | botright options |
| 131 | call assert_equal(winnr('$'), winnr()) |
| 132 | close |
| 133 | set splitbelow& |
| 134 | |
Bram Moolenaar | e0b5949 | 2019-05-21 20:54:45 +0200 | [diff] [blame] | 135 | " Open the option-window in a new tab. |
| 136 | tab options |
| 137 | " Check if the option-window is opened in a tab. |
| 138 | normal gT |
| 139 | call assert_notequal('option-window', bufname('')) |
| 140 | normal gt |
| 141 | call assert_equal('option-window', bufname('')) |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 142 | " close option-window |
| 143 | close |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 144 | |
| 145 | " Open the options window browse |
| 146 | if has('browse') |
| 147 | browse set |
| 148 | call assert_equal('option-window', bufname('')) |
| 149 | close |
| 150 | endif |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 151 | endfunc |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 152 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 153 | func Test_path_keep_commas() |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 154 | " Test that changing 'path' keeps two commas. |
| 155 | set path=foo,,bar |
| 156 | set path-=bar |
| 157 | set path+=bar |
| 158 | call assert_equal('foo,,bar', &path) |
| 159 | |
| 160 | set path& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 161 | endfunc |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 162 | |
Dominique Pelle | f645ee4 | 2021-12-05 13:21:18 +0000 | [diff] [blame] | 163 | func Test_path_too_long() |
| 164 | exe 'set path=' .. repeat('x', 10000) |
| 165 | call assert_fails('find x', 'E854:') |
| 166 | set path& |
| 167 | endfunc |
| 168 | |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 169 | func Test_signcolumn() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 170 | CheckFeature signs |
| 171 | call assert_equal("auto", &signcolumn) |
| 172 | set signcolumn=yes |
| 173 | set signcolumn=no |
| 174 | call assert_fails('set signcolumn=nope') |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 175 | endfunc |
| 176 | |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 177 | func Test_filetype_valid() |
| 178 | set ft=valid_name |
| 179 | call assert_equal("valid_name", &filetype) |
| 180 | set ft=valid-name |
| 181 | call assert_equal("valid-name", &filetype) |
| 182 | |
| 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\\|name", "E474:") |
| 186 | call assert_fails(":set ft=wrong/name", "E474:") |
| 187 | call assert_fails(":set ft=wrong\\\nname", "E474:") |
| 188 | call assert_equal("valid-name", &filetype) |
| 189 | |
| 190 | exe "set ft=trunc\x00name" |
| 191 | call assert_equal("trunc", &filetype) |
| 192 | endfunc |
| 193 | |
| 194 | func Test_syntax_valid() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 195 | CheckFeature syntax |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 196 | set syn=valid_name |
| 197 | call assert_equal("valid_name", &syntax) |
| 198 | set syn=valid-name |
| 199 | call assert_equal("valid-name", &syntax) |
| 200 | |
| 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\\|name", "E474:") |
| 204 | call assert_fails(":set syn=wrong/name", "E474:") |
| 205 | call assert_fails(":set syn=wrong\\\nname", "E474:") |
| 206 | call assert_equal("valid-name", &syntax) |
| 207 | |
| 208 | exe "set syn=trunc\x00name" |
| 209 | call assert_equal("trunc", &syntax) |
| 210 | endfunc |
| 211 | |
| 212 | func Test_keymap_valid() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 213 | CheckFeature keymap |
Bram Moolenaar | d0b5138 | 2016-11-04 15:23:45 +0100 | [diff] [blame] | 214 | call assert_fails(":set kmp=valid_name", "E544:") |
| 215 | call assert_fails(":set kmp=valid_name", "valid_name") |
| 216 | call assert_fails(":set kmp=valid-name", "E544:") |
| 217 | call assert_fails(":set kmp=valid-name", "valid-name") |
| 218 | |
| 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\\|name", "E474:") |
| 222 | call assert_fails(":set kmp=wrong/name", "E474:") |
| 223 | call assert_fails(":set kmp=wrong\\\nname", "E474:") |
| 224 | |
| 225 | call assert_fails(":set kmp=trunc\x00name", "E544:") |
| 226 | call assert_fails(":set kmp=trunc\x00name", "trunc") |
| 227 | endfunc |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 228 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 229 | func Test_wildchar_valid() |
| 230 | call assert_fails("set wildchar=<CR>", "E474:") |
| 231 | call assert_fails("set wildcharm=<C-C>", "E474:") |
| 232 | endfunc |
| 233 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 234 | func Check_dir_option(name) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 235 | " Check that it's possible to set the option. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 236 | exe 'set ' . a:name . '=/usr/share/dict/words' |
| 237 | call assert_equal('/usr/share/dict/words', eval('&' . a:name)) |
| 238 | exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' |
| 239 | call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) |
| 240 | exe 'set ' . a:name . '=/usr/share/dict\ words' |
| 241 | call assert_equal('/usr/share/dict words', eval('&' . a:name)) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 242 | |
| 243 | " Check rejecting weird characters. |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 244 | call assert_fails("set " . a:name . "=/not&there", "E474:") |
| 245 | call assert_fails("set " . a:name . "=/not>there", "E474:") |
| 246 | call assert_fails("set " . a:name . "=/not.*there", "E474:") |
| 247 | endfunc |
| 248 | |
Bram Moolenaar | 60629d6 | 2017-02-23 18:08:56 +0100 | [diff] [blame] | 249 | func Test_cinkeys() |
| 250 | " This used to cause invalid memory access |
| 251 | set cindent cinkeys=0 |
| 252 | norm a |
| 253 | set cindent& cinkeys& |
| 254 | endfunc |
| 255 | |
Bram Moolenaar | f422bcc | 2016-11-26 17:45:53 +0100 | [diff] [blame] | 256 | func Test_dictionary() |
| 257 | call Check_dir_option('dictionary') |
| 258 | endfunc |
| 259 | |
| 260 | func Test_thesaurus() |
| 261 | call Check_dir_option('thesaurus') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 262 | endfun |
| 263 | |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 264 | func Test_complete() |
| 265 | " Trailing single backslash used to cause invalid memory access. |
| 266 | set complete=s\ |
| 267 | new |
| 268 | call feedkeys("i\<C-N>\<Esc>", 'xt') |
| 269 | bwipe! |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 270 | call assert_fails('set complete=ix', 'E535:') |
Girish Palya | cbe5319 | 2025-04-14 22:13:15 +0200 | [diff] [blame] | 271 | call assert_fails('set complete=x', 'E539:') |
| 272 | call assert_fails('set complete=..', 'E535:') |
Girish Palya | 14f6da5 | 2025-05-26 19:04:25 +0200 | [diff] [blame] | 273 | set complete=.,w,b,u,k,\ s,i,d,],t,U,F,o |
Girish Palya | 0ac1eb3 | 2025-04-16 20:18:33 +0200 | [diff] [blame] | 274 | call assert_fails('set complete=i^-10', 'E535:') |
| 275 | call assert_fails('set complete=i^x', 'E535:') |
zeertzjq | 67fe77d | 2025-04-20 10:21:18 +0200 | [diff] [blame] | 276 | call assert_fails('set complete=k^2,t^-1,s^', 'E535:') |
| 277 | call assert_fails('set complete=t^-1', 'E535:') |
| 278 | call assert_fails('set complete=kfoo^foo2', 'E535:') |
| 279 | call assert_fails('set complete=kfoo^', 'E535:') |
| 280 | call assert_fails('set complete=.^', 'E535:') |
Girish Palya | 14f6da5 | 2025-05-26 19:04:25 +0200 | [diff] [blame] | 281 | set complete=.,w,b,u,k,s,i,d,],t,U,F,o |
Girish Palya | cbe5319 | 2025-04-14 22:13:15 +0200 | [diff] [blame] | 282 | set complete=. |
Girish Palya | 0ac1eb3 | 2025-04-16 20:18:33 +0200 | [diff] [blame] | 283 | set complete=.^10,t^0 |
Girish Palya | 14f6da5 | 2025-05-26 19:04:25 +0200 | [diff] [blame] | 284 | set complete+=Ffuncref('foo'\\,\ [10]) |
| 285 | set complete=Ffuncref('foo'\\,\ [10])^10 |
Girish Palya | cbe5319 | 2025-04-14 22:13:15 +0200 | [diff] [blame] | 286 | set complete& |
Girish Palya | 14f6da5 | 2025-05-26 19:04:25 +0200 | [diff] [blame] | 287 | set complete+=Ffunction('g:foo'\\,\ [10\\,\ 20]) |
Bram Moolenaar | 226c534 | 2017-02-17 14:53:15 +0100 | [diff] [blame] | 288 | set complete& |
| 289 | endfun |
| 290 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 291 | func Test_set_completion() |
| 292 | call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 293 | call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) |
| 294 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 295 | call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 296 | call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 297 | |
| 298 | call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') |
| 299 | call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) |
| 300 | |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 301 | " Expand boolean options. When doing :set no<Tab> Vim prefixes the option |
| 302 | " names with "no". |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 303 | call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 304 | call assert_equal('"set nodiff nodigraph', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 305 | |
| 306 | call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 307 | call assert_equal('"set invdiff invdigraph', @:) |
| 308 | |
| 309 | " Expanding "set noinv" does nothing. |
| 310 | call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx') |
| 311 | call assert_equal('"set noinv', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 312 | |
| 313 | " Expand abbreviation of options. |
| 314 | call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | abdcfd1 | 2021-10-16 16:48:27 +0100 | [diff] [blame] | 315 | call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 316 | |
| 317 | " Expand current value |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 318 | call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx') |
| 319 | call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 320 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 321 | call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx') |
| 322 | call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 323 | |
| 324 | " Expand key codes. |
| 325 | call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') |
| 326 | call assert_equal('"set <Help> <Home>', @:) |
Yee Cheng Chin | 7d8e7df | 2025-03-27 17:43:41 +0100 | [diff] [blame] | 327 | " <BackSpace> (alt name) and <BS> should both show up in auto-complete |
| 328 | call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx') |
| 329 | call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:) |
| 330 | " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here |
| 331 | " nor show up as duplicates |
| 332 | call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx') |
| 333 | call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 334 | |
| 335 | " Expand terminal options. |
| 336 | call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | e023e88 | 2020-05-31 16:42:30 +0200 | [diff] [blame] | 337 | call assert_equal('"set t_AB t_AF t_AU t_AL', @:) |
Bram Moolenaar | 0ff5ded | 2020-05-07 18:43:44 +0200 | [diff] [blame] | 338 | 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] | 339 | |
| 340 | " Expand directories. |
| 341 | call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') |
| 342 | call assert_match(' ./samples/ ', @:) |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 343 | call assert_notmatch(' ./util/summarize.vim ', @:) |
Yee Cheng Chin | 5484485 | 2023-10-09 18:12:31 +0200 | [diff] [blame] | 344 | set cdpath& |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 345 | |
| 346 | " Expand files and directories. |
| 347 | call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 348 | call assert_match(' ./samples/.* ./test10.in', @:) |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 349 | |
| 350 | call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') |
| 351 | call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) |
Yee Cheng Chin | 5484485 | 2023-10-09 18:12:31 +0200 | [diff] [blame] | 352 | |
| 353 | " Expand files with spaces/commas in them. Make sure we delimit correctly. |
| 354 | " |
| 355 | " 'tags' allow for for spaces/commas to both act as delimiters, with actual |
| 356 | " spaces requiring double escape, and commas need a single escape. |
| 357 | " 'dictionary' is a normal comma-separated option where only commas act as |
| 358 | " delimiters, and both space/comma need one single escape. |
| 359 | " 'makeprg' is a non-comma-separated option. Commas don't need escape. |
| 360 | defer delete('Xfoo Xspace.txt') |
| 361 | defer delete('Xsp_dummy') |
| 362 | defer delete('Xbar,Xcomma.txt') |
| 363 | defer delete('Xcom_dummy') |
| 364 | call writefile([], 'Xfoo Xspace.txt') |
| 365 | call writefile([], 'Xsp_dummy') |
| 366 | call writefile([], 'Xbar,Xcomma.txt') |
| 367 | call writefile([], 'Xcom_dummy') |
| 368 | |
| 369 | call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 370 | call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:) |
| 371 | call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 372 | call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:) |
| 373 | call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 374 | call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:) |
| 375 | |
| 376 | call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 377 | call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:) |
| 378 | if has('win32') |
| 379 | " In Windows, '\,' is literal, see `:help filename-backslash`, so this |
| 380 | " means we treat it as one file name. |
| 381 | call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 382 | call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:) |
| 383 | else |
| 384 | " In other platforms, '\,' simply escape to ',', and indicate a delimiter |
| 385 | " to split into a separate file name. You need '\\,' to escape the comma |
| 386 | " as part of the file name. |
| 387 | call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 388 | call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:) |
| 389 | |
| 390 | call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') |
| 391 | call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:) |
| 392 | endif |
| 393 | call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx') |
| 394 | call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:) |
| 395 | set tags& dictionary& makeprg& |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 396 | |
| 397 | " Expanding the option names |
| 398 | call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') |
| 399 | call assert_equal('"set all', @:) |
| 400 | |
| 401 | " Expanding a second set of option names |
| 402 | call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt') |
| 403 | call assert_equal('"set wrapscan all', @:) |
| 404 | |
| 405 | " Expanding a special keycode |
| 406 | call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 407 | call assert_equal('"set <Home>', @:) |
| 408 | |
| 409 | " Expanding an invalid special keycode |
| 410 | call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 411 | call assert_equal("\"set <abcd>\<Tab>", @:) |
| 412 | |
| 413 | " Expanding a terminal keycode |
| 414 | call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') |
| 415 | call assert_equal("\"set t_AB", @:) |
| 416 | |
| 417 | " Expanding an invalid option name |
| 418 | call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 419 | call assert_equal("\"set abcde=\<Tab>", @:) |
| 420 | |
| 421 | " Expanding after a = for a boolean option |
| 422 | call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 423 | call assert_equal("\"set wrapscan=\<Tab>", @:) |
| 424 | |
| 425 | " Expanding a numeric option |
| 426 | call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 427 | call assert_equal("\"set tabstop+=" .. &tabstop, @:) |
| 428 | |
| 429 | " Expanding a non-boolean option |
| 430 | call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 431 | call assert_equal("\"set invtabstop=", @:) |
| 432 | |
| 433 | " Expand options for 'spellsuggest' |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 434 | call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt') |
| 435 | call assert_equal("\"set spellsuggest=file:test_options.vim", @:) |
| 436 | call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt') |
| 437 | call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:) |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 438 | |
Yee Cheng Chin | 6ee7b52 | 2023-10-01 09:13:22 +0200 | [diff] [blame] | 439 | " Expanding value for 'key' is disallowed |
| 440 | if exists('+key') |
| 441 | set key=abcd |
| 442 | call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 443 | call assert_equal('"set key=', @:) |
| 444 | call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 445 | call assert_equal('"set key-=', @:) |
| 446 | set key= |
| 447 | endif |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 448 | |
| 449 | " Expand values for 'filetype' |
| 450 | call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt') |
| 451 | call assert_equal('"set filetype=sshdconfig', @:) |
| 452 | call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 453 | call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:) |
Doug Kearns | 6dfdff3 | 2023-08-27 18:48:51 +0200 | [diff] [blame] | 454 | |
| 455 | " Expand values for 'syntax' |
| 456 | call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt') |
| 457 | call assert_equal('"set syntax=sshdconfig', @:) |
| 458 | call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 459 | call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:) |
Doug Kearns | 81642d9 | 2024-01-04 22:37:44 +0100 | [diff] [blame] | 460 | |
| 461 | if has('keymap') |
| 462 | " Expand values for 'keymap' |
| 463 | call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt') |
| 464 | call assert_equal('"set keymap=accents', @:) |
| 465 | call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 466 | call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:) |
| 467 | endif |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 468 | endfunc |
| 469 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 470 | " Test handling of expanding individual string option values |
| 471 | func Test_set_completion_string_values() |
| 472 | " |
| 473 | " Test basic enum string options that have well-defined enum names |
| 474 | " |
| 475 | |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 476 | call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) |
| 477 | call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline')) |
| 478 | call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 479 | |
| 480 | " Test that if a value is set, it will populate the results, but only if |
| 481 | " typed value is empty. |
| 482 | set display=uhex,lastline |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 483 | call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) |
| 484 | call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 485 | " If the set value is part of the enum list, it will show as the first |
| 486 | " result with no duplicate. |
| 487 | set display=uhex |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 488 | call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 489 | " If empty value, will just show the normal list without an empty item |
| 490 | set display= |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 491 | call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 492 | " Test escaping of the values |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 493 | call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 494 | |
| 495 | " Test comma-separated lists will expand after a comma. |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 496 | call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 497 | " Also test the positioning of the expansion is correct |
| 498 | call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt') |
| 499 | call assert_equal('"set display=truncate,lastline', @:) |
| 500 | set display& |
| 501 | |
| 502 | " Test single-value options will not expand after a comma |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 503 | call assert_equal([], getcompletion('set ambw=single,', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 504 | |
| 505 | " Test the other simple options to make sure they have basic auto-complete, |
| 506 | " but don't exhaustively validate their results. |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 507 | call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 508 | call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1]) |
Luca Saccarola | 959ef61 | 2024-12-01 16:25:53 +0100 | [diff] [blame] | 509 | call assert_equal('indent,eol,start', getcompletion('set backspace=', 'cmdline')[0]) |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 510 | call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1]) |
| 511 | call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1]) |
| 512 | call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 513 | if exists('+browsedir') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 514 | call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 515 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 516 | call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1]) |
| 517 | call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1]) |
| 518 | call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 519 | if exists('+clipboard') |
| 520 | call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1]) |
| 521 | endif |
Foxe Chen | b90c239 | 2025-06-27 21:10:35 +0200 | [diff] [blame] | 522 | if exists('+clipmethod') |
| 523 | if has('unix') || has('vms') |
| 524 | call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[1]) |
| 525 | else |
| 526 | call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[0]) |
| 527 | endif |
| 528 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 529 | call assert_equal('.', getcompletion('set complete=', 'cmdline')[1]) |
| 530 | call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1]) |
zeertzjq | 53d59ec | 2025-03-07 19:09:09 +0100 | [diff] [blame] | 531 | call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 532 | if exists('+completeslash') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 533 | call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 534 | endif |
| 535 | if exists('+cryptmethod') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 536 | call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 537 | endif |
| 538 | if exists('+cursorlineopt') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 539 | call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 540 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 541 | call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1]) |
| 542 | call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1]) |
| 543 | call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 544 | if exists('+foldclose') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 545 | call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 546 | endif |
| 547 | if exists('+foldmethod') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 548 | call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 549 | endif |
| 550 | if exists('+foldopen') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 551 | call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 552 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 553 | call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0]) |
| 554 | call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1]) |
| 555 | call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 556 | call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2]) |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 557 | call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 558 | if exists('+rightleftcmd') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 559 | call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 560 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 561 | call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1]) |
| 562 | call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1]) |
| 563 | call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 564 | if exists('+ssop') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 565 | call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 566 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 567 | call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 568 | if exists('+signcolumn') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 569 | call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 570 | endif |
| 571 | if exists('+spelloptions') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 572 | call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 573 | endif |
| 574 | if exists('+spellsuggest') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 575 | call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 576 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 577 | call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1]) |
| 578 | call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1]) |
| 579 | call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1]) |
| 580 | call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1]) |
LemonBoy | 5247b0b | 2024-07-12 19:30:58 +0200 | [diff] [blame] | 581 | if exists('+tabclose') |
| 582 | call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ') |
| 583 | endif |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 584 | if exists('+termwintype') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 585 | call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 586 | endif |
| 587 | if exists('+toolbar') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 588 | call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 589 | endif |
| 590 | if exists('+tbis') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 591 | call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 592 | endif |
| 593 | if exists('+ttymouse') |
| 594 | set ttymouse= |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 595 | call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 596 | set ttymouse& |
| 597 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 598 | call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1]) |
| 599 | call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1]) |
| 600 | call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0]) |
| 601 | call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 602 | if exists('+winaltkeys') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 603 | call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 604 | endif |
| 605 | |
| 606 | " Other string options that queries the system rather than fixed enum names |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 607 | call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1]) |
Luuk van Baal | 8cc6d8b | 2025-05-31 12:10:31 +0200 | [diff] [blame] | 608 | call assert_equal(['-BufAdd', '-BufCreate'], getcompletion('set eventignore=all,-', 'cmdline')[0:1]) |
Luuk van Baal | b7147f8 | 2025-02-08 18:52:39 +0100 | [diff] [blame] | 609 | call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1]) |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 610 | call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1]) |
| 611 | call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0]) |
| 612 | call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 613 | |
zeertzjq | 1f025b0 | 2023-09-30 12:43:07 +0200 | [diff] [blame] | 614 | call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0]) |
| 615 | call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:]) |
| 616 | call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0]) |
| 617 | call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:]) |
| 618 | call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0]) |
| 619 | call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 620 | |
| 621 | " |
| 622 | " Unique string options below |
| 623 | " |
| 624 | |
| 625 | " keyprotocol: only auto-complete when after ':' with known protocol types |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 626 | call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 627 | call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt') |
| 628 | call assert_equal('"set keyprotocol+=someterm:mok2', @:) |
Christian Brabandt | 231b4fc | 2024-12-28 16:27:49 +0100 | [diff] [blame] | 629 | call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt') |
| 630 | call assert_equal('"set keyprotocol+=someterm:kitty', @:) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 631 | set keyprotocol& |
| 632 | |
| 633 | " previewpopup / completepopup |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 634 | call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0]) |
| 635 | call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 636 | call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt') |
| 637 | call assert_equal('"set previewpopup+=border:on', @:) |
| 638 | call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt') |
| 639 | call assert_equal('"set completepopup=height:10,align:item', @:) |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 640 | call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 641 | set previewpopup& completepopup& |
| 642 | |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 643 | " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type> |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 644 | call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0]) |
| 645 | call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline')) |
| 646 | call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0]) |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 647 | call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 648 | |
| 649 | " highlight: special parsing, including auto-completing highlight groups |
| 650 | " after ':' |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 651 | call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1]) |
| 652 | call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0]) |
| 653 | call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2]) |
| 654 | call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0]) |
| 655 | call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 656 | " If all the display modes are used up we should be suggesting nothing. Make |
| 657 | " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t', |
| 658 | " and make sure nothing is suggested from that. |
| 659 | let hl_display_modes = join( |
| 660 | \ filter(map(getcompletion('set hl+=8', 'cmdline'), |
| 661 | \ {idx, val -> val[1]}), |
| 662 | \ {idx, val -> val != ':'}), |
| 663 | \ '') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 664 | call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline')) |
Yee Cheng Chin | 209ec90 | 2023-10-17 10:56:25 +0200 | [diff] [blame] | 665 | " Test completion in middle of the line |
| 666 | call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 667 | call assert_equal("\"set hl=8bi i", @:) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 668 | |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 669 | " messagesopt |
| 670 | call assert_equal(['history:', 'hit-enter', 'wait:'], |
| 671 | \ getcompletion('set messagesopt+=', 'cmdline')->sort()) |
| 672 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 673 | " |
| 674 | " Test flag lists |
| 675 | " |
| 676 | |
| 677 | " Test set=. Show the original value if nothing is typed after '='. |
| 678 | " Otherwise, the list should avoid showing what's already typed. |
| 679 | set mouse=v |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 680 | call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 681 | set mouse=nvi |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 682 | call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline')) |
| 683 | call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 684 | |
| 685 | " Test set+=. Never show original value, and it also tries to avoid listing |
| 686 | " flags that's already in the option value. |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 687 | call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline')) |
| 688 | call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline')) |
| 689 | call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 690 | |
| 691 | " Test that the position of the expansion is correct (even if there are |
| 692 | " additional values after the current cursor) |
| 693 | call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 694 | call assert_equal('"set mouse=han', @:) |
| 695 | set mouse& |
| 696 | |
| 697 | " Test that other flag list options have auto-complete, but don't |
| 698 | " exhaustively validate their results. |
| 699 | if exists('+concealcursor') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 700 | call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 701 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 702 | call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1]) |
| 703 | call assert_equal('t', getcompletion('set fo=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 704 | if exists('+guioptions') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 705 | call assert_equal('!', getcompletion('set go=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 706 | endif |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 707 | call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1]) |
| 708 | call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 709 | |
| 710 | " |
| 711 | "Test set-= |
| 712 | " |
| 713 | |
| 714 | " Normal single-value option just shows the existing value |
| 715 | set ambiwidth=double |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 716 | call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 717 | set ambiwidth& |
| 718 | |
| 719 | " Works on numbers and term options as well |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 720 | call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 721 | set t_Ce=testCe |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 722 | call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 723 | set t_Ce& |
| 724 | |
| 725 | " Comma-separated lists should present each option |
| 726 | set diffopt=context:123,,,,,iblank,iwhiteall |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 727 | call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline')) |
| 728 | call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline')) |
| 729 | call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 730 | " Don't present more than one option as it doesn't make sense in set-= |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 731 | call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 732 | " Test empty option |
| 733 | set diffopt= |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 734 | call assert_equal([], getcompletion('set diffopt-=', 'cmdline')) |
Christian Brabandt | 9162e63 | 2025-01-16 19:03:40 +0100 | [diff] [blame] | 735 | " Test all possible values |
| 736 | call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal', |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 737 | \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'], |
Christian Brabandt | 9162e63 | 2025-01-16 19:03:40 +0100 | [diff] [blame] | 738 | \ getcompletion('set diffopt=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 739 | set diffopt& |
| 740 | |
| 741 | " Test escaping output |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 742 | call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0]) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 743 | |
| 744 | " Test files with commas in name are being parsed and escaped properly |
| 745 | set path=has\\\ space,file\\,with\\,comma,normal_file |
| 746 | if exists('+completeslash') |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 747 | call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 748 | else |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 749 | call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 750 | endif |
| 751 | set path& |
| 752 | |
| 753 | " Flag list should present orig value, then individual flags |
| 754 | set mouse=v |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 755 | call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 756 | set mouse=avn |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 757 | call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 758 | " Don't auto-complete when we have at least one flags already |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 759 | call assert_equal([], getcompletion('set mouse-=n', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 760 | " Test empty option |
| 761 | set mouse= |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 762 | call assert_equal([], getcompletion('set mouse-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 763 | set mouse& |
| 764 | |
| 765 | " 'whichwrap' is an odd case where it's both flag list and comma-separated |
| 766 | set ww=b,h |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 767 | call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline')) |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 768 | set ww& |
| 769 | endfunc |
| 770 | |
zeertzjq | 4c7cb37 | 2023-06-14 16:39:54 +0100 | [diff] [blame] | 771 | func Test_set_option_errors() |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 772 | call assert_fails('set scroll=-1', 'E49:') |
| 773 | call assert_fails('set backupcopy=', 'E474:') |
| 774 | call assert_fails('set regexpengine=3', 'E474:') |
| 775 | call assert_fails('set history=10001', 'E474:') |
Bram Moolenaar | f8a0712 | 2019-07-01 22:06:07 +0200 | [diff] [blame] | 776 | call assert_fails('set numberwidth=21', 'E474:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 777 | call assert_fails('set colorcolumn=-a', 'E474:') |
| 778 | call assert_fails('set colorcolumn=a', 'E474:') |
| 779 | call assert_fails('set colorcolumn=1,', 'E474:') |
| 780 | call assert_fails('set colorcolumn=1;', 'E474:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 781 | call assert_fails('set cmdheight=-1', 'E487:') |
| 782 | call assert_fails('set cmdwinheight=-1', 'E487:') |
| 783 | if has('conceal') |
| 784 | call assert_fails('set conceallevel=-1', 'E487:') |
| 785 | call assert_fails('set conceallevel=4', 'E474:') |
| 786 | endif |
| 787 | call assert_fails('set helpheight=-1', 'E487:') |
| 788 | call assert_fails('set history=-1', 'E487:') |
| 789 | call assert_fails('set report=-1', 'E487:') |
| 790 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 791 | call assert_fails('set sidescroll=-1', 'E487:') |
| 792 | call assert_fails('set tabstop=-1', 'E487:') |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 793 | call assert_fails('set tabstop=10000', 'E474:') |
Bram Moolenaar | 8ccbbeb | 2022-03-02 19:49:38 +0000 | [diff] [blame] | 794 | call assert_fails('let &tabstop = 10000', 'E474:') |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 795 | call assert_fails('set tabstop=5500000000', 'E474:') |
Milly | 6d5f4a0 | 2024-10-22 23:17:45 +0200 | [diff] [blame] | 796 | if has('terminal') |
| 797 | call assert_fails('set termwinscroll=-1', 'E487:') |
| 798 | endif |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 799 | call assert_fails('set textwidth=-1', 'E487:') |
| 800 | call assert_fails('set timeoutlen=-1', 'E487:') |
| 801 | call assert_fails('set updatecount=-1', 'E487:') |
| 802 | call assert_fails('set updatetime=-1', 'E487:') |
| 803 | call assert_fails('set winheight=-1', 'E487:') |
| 804 | call assert_fails('set tabstop!', 'E488:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 805 | |
| 806 | " Test for setting unknown option errors |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 807 | call assert_fails('set xxx', 'E518:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 808 | call assert_fails('setlocal xxx', 'E518:') |
| 809 | call assert_fails('setglobal xxx', 'E518:') |
| 810 | call assert_fails('set xxx=', 'E518:') |
| 811 | call assert_fails('setlocal xxx=', 'E518:') |
| 812 | call assert_fails('setglobal xxx=', 'E518:') |
| 813 | call assert_fails('set xxx:', 'E518:') |
| 814 | call assert_fails('setlocal xxx:', 'E518:') |
| 815 | call assert_fails('setglobal xxx:', 'E518:') |
| 816 | call assert_fails('set xxx!', 'E518:') |
| 817 | call assert_fails('setlocal xxx!', 'E518:') |
| 818 | call assert_fails('setglobal xxx!', 'E518:') |
| 819 | call assert_fails('set xxx?', 'E518:') |
| 820 | call assert_fails('setlocal xxx?', 'E518:') |
| 821 | call assert_fails('setglobal xxx?', 'E518:') |
| 822 | call assert_fails('set xxx&', 'E518:') |
| 823 | call assert_fails('setlocal xxx&', 'E518:') |
| 824 | call assert_fails('setglobal xxx&', 'E518:') |
| 825 | call assert_fails('set xxx<', 'E518:') |
| 826 | call assert_fails('setlocal xxx<', 'E518:') |
| 827 | call assert_fails('setglobal xxx<', 'E518:') |
| 828 | |
| 829 | " Test for missing-options errors. |
| 830 | call assert_fails('set autoprint?', 'E519:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 831 | call assert_fails('set beautify?', 'E519:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 832 | call assert_fails('set flash?', 'E519:') |
| 833 | call assert_fails('set graphic?', 'E519:') |
| 834 | call assert_fails('set hardtabs?', 'E519:') |
| 835 | call assert_fails('set mesg?', 'E519:') |
| 836 | call assert_fails('set novice?', 'E519:') |
| 837 | call assert_fails('set open?', 'E519:') |
| 838 | call assert_fails('set optimize?', 'E519:') |
| 839 | call assert_fails('set redraw?', 'E519:') |
| 840 | call assert_fails('set slowopen?', 'E519:') |
| 841 | call assert_fails('set sourceany?', 'E519:') |
| 842 | call assert_fails('set w300?', 'E519:') |
| 843 | call assert_fails('set w1200?', 'E519:') |
| 844 | call assert_fails('set w9600?', 'E519:') |
| 845 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 846 | call assert_fails('set undolevels=x', 'E521:') |
| 847 | call assert_fails('set tabstop=', 'E521:') |
| 848 | call assert_fails('set comments=-', 'E524:') |
| 849 | call assert_fails('set comments=a', 'E525:') |
| 850 | call assert_fails('set foldmarker=x', 'E536:') |
| 851 | call assert_fails('set commentstring=x', 'E537:') |
Bram Moolenaar | 8ccbbeb | 2022-03-02 19:49:38 +0000 | [diff] [blame] | 852 | call assert_fails('let &commentstring = "x"', 'E537:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 853 | call assert_fails('set complete=x', 'E539:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 854 | call assert_fails('set rulerformat=%-', 'E539:') |
| 855 | call assert_fails('set rulerformat=%(', 'E542:') |
| 856 | call assert_fails('set rulerformat=%15(%%', 'E542:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 857 | |
| 858 | " Test for 'statusline' errors |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 859 | call assert_fails('set statusline=%$', 'E539:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 860 | call assert_fails('set statusline=%{', 'E540:') |
zeertzjq | 5dc294a | 2022-04-15 13:17:57 +0100 | [diff] [blame] | 861 | call assert_fails('set statusline=%{%', 'E540:') |
| 862 | call assert_fails('set statusline=%{%}', 'E539:') |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 863 | call assert_fails('set statusline=%(', 'E542:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 864 | call assert_fails('set statusline=%)', 'E542:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 865 | |
| 866 | " Test for 'tabline' errors |
zeertzjq | 5dc294a | 2022-04-15 13:17:57 +0100 | [diff] [blame] | 867 | call assert_fails('set tabline=%$', 'E539:') |
| 868 | call assert_fails('set tabline=%{', 'E540:') |
| 869 | call assert_fails('set tabline=%{%', 'E540:') |
| 870 | call assert_fails('set tabline=%{%}', 'E539:') |
| 871 | call assert_fails('set tabline=%(', 'E542:') |
| 872 | call assert_fails('set tabline=%)', 'E542:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 873 | |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 874 | if has('cursorshape') |
| 875 | " This invalid value for 'guicursor' used to cause Vim to crash. |
| 876 | call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') |
| 877 | call assert_fails('set guicursor=i-ci', 'E545:') |
| 878 | call assert_fails('set guicursor=x', 'E545:') |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 879 | call assert_fails('set guicursor=x:', 'E546:') |
Bram Moolenaar | 24922ec | 2017-02-23 17:59:22 +0100 | [diff] [blame] | 880 | call assert_fails('set guicursor=r-cr:horx', 'E548:') |
| 881 | call assert_fails('set guicursor=r-cr:hor0', 'E549:') |
| 882 | endif |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 883 | |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 884 | if has('mouseshape') |
| 885 | call assert_fails('se mouseshape=i-r:x', 'E547:') |
| 886 | endif |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 887 | |
| 888 | " Test for 'backupext' and 'patchmode' set to the same value |
| 889 | set backupext=.bak |
| 890 | set patchmode=.patch |
| 891 | call assert_fails('set patchmode=.bak', 'E589:') |
| 892 | call assert_equal('.patch', &patchmode) |
| 893 | call assert_fails('set backupext=.patch', 'E589:') |
| 894 | call assert_equal('.bak', &backupext) |
| 895 | set backupext& patchmode& |
| 896 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 897 | " 'winheight' cannot be smaller than 'winminheight' |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 898 | call assert_fails('set winminheight=10 winheight=9', 'E591:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 899 | set winminheight& winheight& |
| 900 | set winheight=10 winminheight=10 |
| 901 | call assert_fails('set winheight=9', 'E591:') |
| 902 | set winminheight& winheight& |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 903 | |
| 904 | " 'winwidth' cannot be smaller than 'winminwidth' |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 905 | call assert_fails('set winminwidth=10 winwidth=9', 'E592:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 906 | set winminwidth& winwidth& |
| 907 | call assert_fails('set winwidth=9 winminwidth=10', 'E592:') |
| 908 | set winwidth& winminwidth& |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 909 | |
Bram Moolenaar | 698f8b2 | 2017-02-04 15:53:32 +0100 | [diff] [blame] | 910 | call assert_fails("set showbreak=\x01", 'E595:') |
| 911 | call assert_fails('set t_foo=', 'E846:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 912 | call assert_fails('set tabstop??', 'E488:') |
| 913 | call assert_fails('set wrapscan!!', 'E488:') |
| 914 | call assert_fails('set tabstop&&', 'E488:') |
| 915 | call assert_fails('set wrapscan<<', 'E488:') |
| 916 | call assert_fails('set wrapscan=1', 'E474:') |
| 917 | call assert_fails('set autoindent@', 'E488:') |
| 918 | call assert_fails('set wildchar=<abc>', 'E474:') |
| 919 | call assert_fails('set cmdheight=1a', 'E521:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 920 | call assert_fails('set invcmdheight', 'E474:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 921 | if has('python') || has('python3') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 922 | call assert_fails('set pyxversion=6', 'E474:') |
| 923 | endif |
zeertzjq | 4c7cb37 | 2023-06-14 16:39:54 +0100 | [diff] [blame] | 924 | call assert_fails("let &tabstop='ab'", ['E521:', 'E521:']) |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 925 | call assert_fails('set spellcapcheck=%\\(', 'E54:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 926 | call assert_fails('set sessionoptions=curdir,sesdir', 'E474:') |
| 927 | call assert_fails('set foldmarker={{{,', 'E474:') |
| 928 | call assert_fails('set sessionoptions=sesdir,curdir', 'E474:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 929 | |
| 930 | " 'ambiwidth' conflict 'listchars' |
zeertzjq | 8ca29b6 | 2022-08-09 12:53:14 +0100 | [diff] [blame] | 931 | setlocal listchars=trail:· |
| 932 | call assert_fails('set ambiwidth=double', 'E834:') |
| 933 | setlocal listchars=trail:- |
| 934 | setglobal listchars=trail:· |
| 935 | call assert_fails('set ambiwidth=double', 'E834:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 936 | set listchars& |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 937 | |
| 938 | " 'ambiwidth' conflict 'fillchars' |
zeertzjq | 8ca29b6 | 2022-08-09 12:53:14 +0100 | [diff] [blame] | 939 | setlocal fillchars=stl:· |
| 940 | call assert_fails('set ambiwidth=double', 'E835:') |
| 941 | setlocal fillchars=stl:- |
| 942 | setglobal fillchars=stl:· |
| 943 | call assert_fails('set ambiwidth=double', 'E835:') |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 944 | set fillchars& |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 945 | |
Bram Moolenaar | 85773bf | 2021-01-17 13:48:03 +0100 | [diff] [blame] | 946 | call assert_fails('set fileencoding=latin1,utf-8', 'E474:') |
| 947 | set nomodifiable |
| 948 | call assert_fails('set fileencoding=latin1', 'E21:') |
| 949 | set modifiable& |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 950 | call assert_fails('set t_#-&', 'E522:') |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 951 | call assert_fails('let &formatoptions = "?"', 'E539:') |
| 952 | call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:') |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 953 | |
| 954 | " Should raises only one error if passing a wrong variable type. |
zeertzjq | 4c7cb37 | 2023-06-14 16:39:54 +0100 | [diff] [blame] | 955 | call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:']) |
| 956 | call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:']) |
| 957 | call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:']) |
| 958 | call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:']) |
| 959 | call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:']) |
| 960 | call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:']) |
Bram Moolenaar | 7554da4 | 2016-11-25 22:04:13 +0100 | [diff] [blame] | 961 | endfunc |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 962 | |
Bram Moolenaar | 1349bd7 | 2022-02-22 12:34:28 +0000 | [diff] [blame] | 963 | func Test_set_encoding() |
| 964 | let save_encoding = &encoding |
| 965 | |
| 966 | set enc=iso8859-1 |
| 967 | call assert_equal('latin1', &enc) |
| 968 | set enc=iso8859_1 |
| 969 | call assert_equal('latin1', &enc) |
| 970 | set enc=iso-8859-1 |
| 971 | call assert_equal('latin1', &enc) |
| 972 | set enc=iso_8859_1 |
| 973 | call assert_equal('latin1', &enc) |
| 974 | set enc=iso88591 |
| 975 | call assert_equal('latin1', &enc) |
| 976 | set enc=iso8859 |
| 977 | call assert_equal('latin1', &enc) |
| 978 | set enc=iso-8859 |
| 979 | call assert_equal('latin1', &enc) |
| 980 | set enc=iso_8859 |
| 981 | call assert_equal('latin1', &enc) |
| 982 | call assert_fails('set enc=iso8858', 'E474:') |
| 983 | call assert_equal('latin1', &enc) |
| 984 | |
| 985 | let &encoding = save_encoding |
| 986 | endfunc |
| 987 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 988 | func CheckWasSet(name) |
| 989 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 990 | call assert_match('Last set from.*test_options.vim', verb_cm) |
| 991 | endfunc |
| 992 | func CheckWasNotSet(name) |
| 993 | let verb_cm = execute('verbose set ' .. a:name .. '?') |
| 994 | call assert_notmatch('Last set from', verb_cm) |
| 995 | endfunc |
| 996 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 997 | " Must be executed before other tests that set 'term'. |
| 998 | func Test_000_term_option_verbose() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 999 | CheckNotGui |
| 1000 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 1001 | call CheckWasNotSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 1002 | |
| 1003 | let term_save = &term |
| 1004 | set term=ansi |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 1005 | call CheckWasSet('t_cm') |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 1006 | let &term = term_save |
| 1007 | endfunc |
| 1008 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 1009 | func Test_copy_context() |
| 1010 | setlocal list |
| 1011 | call CheckWasSet('list') |
| 1012 | split |
| 1013 | call CheckWasSet('list') |
| 1014 | quit |
| 1015 | setlocal nolist |
| 1016 | |
| 1017 | set ai |
| 1018 | call CheckWasSet('ai') |
| 1019 | set filetype=perl |
| 1020 | call CheckWasSet('filetype') |
| 1021 | set fo=tcroq |
| 1022 | call CheckWasSet('fo') |
| 1023 | |
| 1024 | split Xsomebuf |
| 1025 | call CheckWasSet('ai') |
| 1026 | call CheckWasNotSet('filetype') |
| 1027 | call CheckWasSet('fo') |
| 1028 | endfunc |
| 1029 | |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 1030 | func Test_set_ttytype() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1031 | CheckUnix |
| 1032 | CheckNotGui |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 1033 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1034 | " Setting 'ttytype' used to cause a double-free when exiting vim and |
| 1035 | " when vim is compiled with -DEXITFREE. |
| 1036 | set ttytype=ansi |
| 1037 | call assert_equal('ansi', &ttytype) |
| 1038 | call assert_equal(&ttytype, &term) |
| 1039 | set ttytype=xterm |
| 1040 | call assert_equal('xterm', &ttytype) |
| 1041 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1042 | try |
| 1043 | set ttytype= |
| 1044 | call assert_report('set ttytype= did not fail') |
Bram Moolenaar | 5daa911 | 2021-02-01 18:39:47 +0100 | [diff] [blame] | 1045 | catch /E529/ |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1046 | endtry |
Bram Moolenaar | f803a76 | 2017-04-09 22:54:13 +0200 | [diff] [blame] | 1047 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1048 | " Some systems accept any terminal name and return dumb settings, |
| 1049 | " check for failure of finding the entry and for missing 'cm' entry. |
| 1050 | try |
| 1051 | set ttytype=xxx |
| 1052 | call assert_report('set ttytype=xxx did not fail') |
| 1053 | catch /E522\|E437/ |
| 1054 | endtry |
| 1055 | |
| 1056 | set ttytype& |
| 1057 | call assert_equal(&ttytype, &term) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 1058 | |
| 1059 | if has('gui') && !has('gui_running') |
| 1060 | call assert_fails('set term=gui', 'E531:') |
| 1061 | endif |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 1062 | endfunc |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 1063 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1064 | " Test for :set all |
Bram Moolenaar | 2f5463d | 2017-02-25 20:40:46 +0100 | [diff] [blame] | 1065 | func Test_set_all() |
| 1066 | set tw=75 |
| 1067 | set iskeyword=a-z,A-Z |
| 1068 | set nosplitbelow |
| 1069 | let out = execute('set all') |
| 1070 | call assert_match('textwidth=75', out) |
| 1071 | call assert_match('iskeyword=a-z,A-Z', out) |
| 1072 | call assert_match('nosplitbelow', out) |
| 1073 | set tw& iskeyword& splitbelow& |
| 1074 | endfunc |
| 1075 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1076 | " Test for :set! all |
| 1077 | func Test_set_all_one_column() |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1078 | let out_mult = execute('set all')->split("\n") |
| 1079 | let out_one = execute('set! all')->split("\n") |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 1080 | call assert_true(len(out_mult) < len(out_one)) |
zeertzjq | f48558e | 2023-12-08 21:34:31 +0100 | [diff] [blame] | 1081 | call assert_equal(out_one[0], '--- Options ---') |
| 1082 | let options = out_one[1:]->mapnew({_, line -> line[2:]}) |
| 1083 | call assert_equal(sort(copy(options)), options) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1084 | endfunc |
| 1085 | |
Bram Moolenaar | 0c1e374 | 2019-12-27 13:49:24 +0100 | [diff] [blame] | 1086 | func Test_renderoptions() |
| 1087 | " Only do this for Windows Vista and later, fails on Windows XP and earlier. |
| 1088 | " Doesn't hurt to do this on a non-Windows system. |
| 1089 | if windowsversion() !~ '^[345]\.' |
| 1090 | set renderoptions=type:directx |
| 1091 | set rop=type:directx |
| 1092 | endif |
| 1093 | endfunc |
| 1094 | |
Bram Moolenaar | a701b3b | 2017-04-20 22:57:27 +0200 | [diff] [blame] | 1095 | func ResetIndentexpr() |
| 1096 | set indentexpr= |
| 1097 | endfunc |
| 1098 | |
| 1099 | func Test_set_indentexpr() |
| 1100 | " this was causing usage of freed memory |
| 1101 | set indentexpr=ResetIndentexpr() |
| 1102 | new |
| 1103 | call feedkeys("i\<c-f>", 'x') |
| 1104 | call assert_equal('', &indentexpr) |
| 1105 | bwipe! |
| 1106 | endfunc |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1107 | |
| 1108 | func Test_backupskip() |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 1109 | " Option 'backupskip' may contain several comma-separated path |
| 1110 | " specifications if one or more of the environment variables TMPDIR, TMP, |
| 1111 | " or TEMP is defined. To simplify testing, convert the string value into a |
| 1112 | " list. |
| 1113 | let bsklist = split(&bsk, ',') |
| 1114 | |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1115 | if has("mac") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 1116 | let found = (index(bsklist, '/private/tmp/*') >= 0) |
| 1117 | call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1118 | elseif has("unix") |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 1119 | let found = (index(bsklist, '/tmp/*') >= 0) |
| 1120 | call assert_true(found, '/tmp not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1121 | endif |
| 1122 | |
Bram Moolenaar | 98ad1e1 | 2019-01-30 21:51:27 +0100 | [diff] [blame] | 1123 | " If our test platform is Windows, the path(s) in option bsk will use |
| 1124 | " backslash for the path separator and the components could be in short |
| 1125 | " (8.3) format. As such, we need to replace the backslashes with forward |
| 1126 | " slashes and convert the path components to long format. The expand() |
| 1127 | " function will do this but it cannot handle comma-separated paths. This is |
| 1128 | " why bsk was converted from a string into a list of strings above. |
| 1129 | " |
| 1130 | " One final complication is that the wildcard "/*" is at the end of each |
| 1131 | " path and so expand() might return a list of matching files. To prevent |
| 1132 | " this, we need to remove the wildcard before calling expand() and then |
| 1133 | " append it afterwards. |
| 1134 | if has('win32') |
| 1135 | let item_nbr = 0 |
| 1136 | while item_nbr < len(bsklist) |
| 1137 | let path_spec = bsklist[item_nbr] |
| 1138 | let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) |
| 1139 | let path_spec = substitute(expand(path_spec), '\\', '/', 'g') |
| 1140 | let bsklist[item_nbr] = path_spec . '/*' |
| 1141 | let item_nbr += 1 |
| 1142 | endwhile |
| 1143 | endif |
| 1144 | |
| 1145 | " Option bsk will also include these environment variables if defined. |
| 1146 | " If they're defined, verify they appear in the option value. |
| 1147 | for var in ['$TMPDIR', '$TMP', '$TEMP'] |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1148 | if exists(var) |
| 1149 | let varvalue = substitute(expand(var), '\\', '/', 'g') |
Bram Moolenaar | cbbd0f6 | 2019-01-30 22:36:18 +0100 | [diff] [blame] | 1150 | let varvalue = substitute(varvalue, '/$', '', '') |
| 1151 | let varvalue .= '/*' |
| 1152 | let found = (index(bsklist, varvalue) >= 0) |
| 1153 | call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1154 | endif |
| 1155 | endfor |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 1156 | |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1157 | " Duplicates from environment variables should be filtered out (option has |
| 1158 | " P_NODUP). Run this in a separate instance and write v:errors in a file, |
| 1159 | " so that we see what happens on startup. |
| 1160 | let after =<< trim [CODE] |
| 1161 | let bsklist = split(&backupskip, ',') |
| 1162 | call assert_equal(uniq(copy(bsklist)), bsklist) |
| 1163 | call writefile(['errors:'] + v:errors, 'Xtestout') |
| 1164 | qall |
| 1165 | [CODE] |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 1166 | call writefile(after, 'Xafter', 'D') |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1167 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1168 | |
| 1169 | let saveenv = {} |
| 1170 | for var in ['TMPDIR', 'TMP', 'TEMP'] |
| 1171 | let saveenv[var] = getenv(var) |
| 1172 | call setenv(var, '/duplicate/path') |
| 1173 | endfor |
| 1174 | |
Christian Brabandt | ad503fe | 2025-04-16 20:25:47 +0200 | [diff] [blame] | 1175 | " unset $HOME, so that it won't try to read init files |
| 1176 | let saveenv['HOME'] = getenv("HOME") |
| 1177 | call setenv('HOME', v:null) |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1178 | exe 'silent !' . cmd |
| 1179 | call assert_equal(['errors:'], readfile('Xtestout')) |
| 1180 | |
| 1181 | " restore environment variables |
Christian Brabandt | ad503fe | 2025-04-16 20:25:47 +0200 | [diff] [blame] | 1182 | for var in ['TMPDIR', 'TMP', 'TEMP', 'HOME'] |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1183 | call setenv(var, saveenv[var]) |
| 1184 | endfor |
| 1185 | |
| 1186 | call delete('Xtestout') |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1187 | |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 1188 | " Duplicates should be filtered out (option has P_NODUP) |
| 1189 | let backupskip = &backupskip |
| 1190 | set backupskip= |
| 1191 | set backupskip+=/test/dir |
| 1192 | set backupskip+=/other/dir |
| 1193 | set backupskip+=/test/dir |
| 1194 | call assert_equal('/test/dir,/other/dir', &backupskip) |
| 1195 | let &backupskip = backupskip |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 1196 | endfunc |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1197 | |
Bram Moolenaar | b1fd26d | 2022-10-03 11:23:02 +0100 | [diff] [blame] | 1198 | func Test_buf_copy_winopt() |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 1199 | set hidden |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1200 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 1201 | " Test copy option from current buffer in window |
| 1202 | split |
| 1203 | enew |
| 1204 | setlocal numberwidth=5 |
| 1205 | wincmd w |
| 1206 | call assert_equal(4,&numberwidth) |
| 1207 | bnext |
| 1208 | call assert_equal(5,&numberwidth) |
| 1209 | bw! |
| 1210 | call assert_equal(4,&numberwidth) |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1211 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 1212 | " Test copy value from window that used to be display the buffer |
| 1213 | split |
| 1214 | enew |
| 1215 | setlocal numberwidth=6 |
| 1216 | bnext |
| 1217 | wincmd w |
| 1218 | call assert_equal(4,&numberwidth) |
| 1219 | bnext |
| 1220 | call assert_equal(6,&numberwidth) |
| 1221 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1222 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 1223 | " Test that if buffer is current, don't use the stale cached value |
| 1224 | " from the last time the buffer was displayed. |
| 1225 | split |
| 1226 | enew |
| 1227 | setlocal numberwidth=7 |
| 1228 | bnext |
| 1229 | bnext |
| 1230 | setlocal numberwidth=8 |
| 1231 | wincmd w |
| 1232 | call assert_equal(4,&numberwidth) |
| 1233 | bnext |
| 1234 | call assert_equal(8,&numberwidth) |
| 1235 | bw! |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1236 | |
Bram Moolenaar | 7cb33a1 | 2018-08-23 22:20:35 +0200 | [diff] [blame] | 1237 | " Test value is not copied if window already has seen the buffer |
| 1238 | enew |
| 1239 | split |
| 1240 | setlocal numberwidth=9 |
| 1241 | bnext |
| 1242 | setlocal numberwidth=10 |
| 1243 | wincmd w |
| 1244 | call assert_equal(4,&numberwidth) |
| 1245 | bnext |
| 1246 | call assert_equal(4,&numberwidth) |
| 1247 | bw! |
| 1248 | |
| 1249 | set hidden& |
Bram Moolenaar | 25782a7 | 2018-05-13 18:05:33 +0200 | [diff] [blame] | 1250 | endfunc |
Bram Moolenaar | fc08960 | 2018-06-24 16:53:35 +0200 | [diff] [blame] | 1251 | |
Bram Moolenaar | b1fd26d | 2022-10-03 11:23:02 +0100 | [diff] [blame] | 1252 | def Test_split_copy_options() |
| 1253 | var values = [ |
| 1254 | ['cursorbind', true, false], |
| 1255 | ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'], |
| 1256 | ['list', true, 0], |
| 1257 | ['listchars', '"space:-"', '"' .. &listchars .. '"'], |
| 1258 | ['number', true, 0], |
| 1259 | ['relativenumber', true, false], |
| 1260 | ['scrollbind', true, false], |
| 1261 | ['smoothscroll', true, false], |
| 1262 | ['virtualedit', '"block"', '"' .. &virtualedit .. '"'], |
| 1263 | ['wincolor', '"Search"', '"' .. &wincolor .. '"'], |
| 1264 | ['wrap', false, true], |
| 1265 | ] |
| 1266 | if has('linebreak') |
| 1267 | values += [ |
| 1268 | ['breakindent', true, false], |
| 1269 | ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'], |
| 1270 | ['linebreak', true, false], |
| 1271 | ['numberwidth', 7, 4], |
| 1272 | ['showbreak', '"++"', '"' .. &showbreak .. '"'], |
| 1273 | ] |
| 1274 | endif |
| 1275 | if has('rightleft') |
| 1276 | values += [ |
| 1277 | ['rightleft', true, false], |
| 1278 | ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'], |
| 1279 | ] |
| 1280 | endif |
| 1281 | if has('statusline') |
| 1282 | values += [ |
| 1283 | ['statusline', '"---%f---"', '"' .. &statusline .. '"'], |
| 1284 | ] |
| 1285 | endif |
| 1286 | if has('spell') |
| 1287 | values += [ |
| 1288 | ['spell', true, false], |
| 1289 | ] |
| 1290 | endif |
| 1291 | if has('syntax') |
| 1292 | values += [ |
| 1293 | ['cursorcolumn', true, false], |
| 1294 | ['cursorline', true, false], |
| 1295 | ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'], |
| 1296 | ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'], |
| 1297 | ] |
| 1298 | endif |
| 1299 | if has('diff') |
| 1300 | values += [ |
| 1301 | ['diff', true, false], |
| 1302 | ] |
| 1303 | endif |
| 1304 | if has('conceal') |
| 1305 | values += [ |
| 1306 | ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'], |
| 1307 | ['conceallevel', '3', &conceallevel], |
| 1308 | ] |
| 1309 | endif |
| 1310 | if has('terminal') |
| 1311 | values += [ |
| 1312 | ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'], |
| 1313 | ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'], |
| 1314 | ] |
| 1315 | endif |
| 1316 | if has('folding') |
| 1317 | values += [ |
| 1318 | ['foldcolumn', 5, &foldcolumn], |
| 1319 | ['foldenable', false, true], |
| 1320 | ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'], |
| 1321 | ['foldignore', '"+="', '"' .. &foldignore .. '"'], |
| 1322 | ['foldlevel', 4, &foldlevel], |
| 1323 | ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'], |
| 1324 | ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'], |
| 1325 | ['foldminlines', 3, &foldminlines], |
| 1326 | ['foldnestmax', 17, &foldnestmax], |
| 1327 | ['foldtext', '"closed"', '"' .. &foldtext .. '"'], |
| 1328 | ] |
| 1329 | endif |
| 1330 | if has('signs') |
| 1331 | values += [ |
| 1332 | ['signcolumn', '"number"', '"' .. &signcolumn .. '"'], |
| 1333 | ] |
| 1334 | endif |
| 1335 | |
| 1336 | # set options to non-default value |
| 1337 | for item in values |
| 1338 | exe $'&l:{item[0]} = {item[1]}' |
| 1339 | endfor |
| 1340 | |
| 1341 | # check values are set in new window |
| 1342 | split |
| 1343 | for item in values |
| 1344 | exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")' |
| 1345 | endfor |
| 1346 | |
| 1347 | # restore |
| 1348 | close |
| 1349 | for item in values |
| 1350 | exe $'&l:{item[0]} = {item[2]}' |
| 1351 | endfor |
| 1352 | enddef |
| 1353 | |
Bram Moolenaar | fc08960 | 2018-06-24 16:53:35 +0200 | [diff] [blame] | 1354 | func Test_shortmess_F() |
| 1355 | new |
| 1356 | call assert_match('\[No Name\]', execute('file')) |
| 1357 | set shortmess+=F |
| 1358 | call assert_match('\[No Name\]', execute('file')) |
| 1359 | call assert_match('^\s*$', execute('file foo')) |
| 1360 | call assert_match('foo', execute('file')) |
| 1361 | set shortmess-=F |
| 1362 | call assert_match('bar', execute('file bar')) |
| 1363 | call assert_match('bar', execute('file')) |
| 1364 | set shortmess& |
| 1365 | bwipe |
| 1366 | endfunc |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1367 | |
| 1368 | func Test_shortmess_F2() |
| 1369 | e file1 |
| 1370 | e file2 |
| 1371 | call assert_match('file1', execute('bn', '')) |
| 1372 | call assert_match('file2', execute('bn', '')) |
| 1373 | set shortmess+=F |
| 1374 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 1375 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1376 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 1377 | call assert_false('need_fileinfo'->test_getvalue()) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1378 | set hidden |
| 1379 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 1380 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1381 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 1382 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1383 | set nohidden |
| 1384 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 1385 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1386 | call assert_true(empty(execute('bn', ''))) |
Bram Moolenaar | eda6522 | 2019-05-16 20:29:44 +0200 | [diff] [blame] | 1387 | call assert_false(test_getvalue('need_fileinfo')) |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1388 | set shortmess& |
| 1389 | call assert_match('file1', execute('bn', '')) |
| 1390 | call assert_match('file2', execute('bn', '')) |
| 1391 | bwipe |
| 1392 | bwipe |
Yegappan Lakshmanan | e24b5e0 | 2022-09-22 13:44:00 +0100 | [diff] [blame] | 1393 | call assert_fails('call test_getvalue("abc")', 'E475:') |
Bram Moolenaar | 2f0f871 | 2018-08-21 18:50:18 +0200 | [diff] [blame] | 1394 | endfunc |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1395 | |
Shougo Matsushita | 9db39b0 | 2024-03-06 20:58:41 +0100 | [diff] [blame] | 1396 | func Test_shortmess_F3() |
zeertzjq | 8a01744 | 2024-03-07 21:48:33 +0100 | [diff] [blame] | 1397 | call writefile(['foo'], 'X_dummy', 'D') |
Shougo Matsushita | 9db39b0 | 2024-03-06 20:58:41 +0100 | [diff] [blame] | 1398 | |
| 1399 | set hidden |
| 1400 | set autoread |
| 1401 | e X_dummy |
zeertzjq | 8a01744 | 2024-03-07 21:48:33 +0100 | [diff] [blame] | 1402 | e Xotherfile |
| 1403 | call assert_equal(['foo'], getbufline('X_dummy', 1, '$')) |
Shougo Matsushita | 9db39b0 | 2024-03-06 20:58:41 +0100 | [diff] [blame] | 1404 | set shortmess+=F |
zeertzjq | 8a01744 | 2024-03-07 21:48:33 +0100 | [diff] [blame] | 1405 | echo '' |
| 1406 | |
| 1407 | if has('nanotime') |
| 1408 | sleep 10m |
| 1409 | else |
| 1410 | sleep 2 |
| 1411 | endif |
| 1412 | call writefile(['bar'], 'X_dummy') |
| 1413 | bprev |
| 1414 | call assert_equal('', Screenline(&lines)) |
| 1415 | call assert_equal(['bar'], getbufline('X_dummy', 1, '$')) |
| 1416 | |
| 1417 | if has('nanotime') |
| 1418 | sleep 10m |
| 1419 | else |
| 1420 | sleep 2 |
| 1421 | endif |
| 1422 | call writefile(['baz'], 'X_dummy') |
| 1423 | checktime |
| 1424 | call assert_equal('', Screenline(&lines)) |
| 1425 | call assert_equal(['baz'], getbufline('X_dummy', 1, '$')) |
Shougo Matsushita | 9db39b0 | 2024-03-06 20:58:41 +0100 | [diff] [blame] | 1426 | |
| 1427 | set shortmess& |
| 1428 | set autoread& |
| 1429 | set hidden& |
zeertzjq | 8a01744 | 2024-03-07 21:48:33 +0100 | [diff] [blame] | 1430 | bwipe X_dummy |
| 1431 | bwipe Xotherfile |
Shougo Matsushita | 9db39b0 | 2024-03-06 20:58:41 +0100 | [diff] [blame] | 1432 | endfunc |
| 1433 | |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1434 | func Test_local_scrolloff() |
| 1435 | set so=5 |
| 1436 | set siso=7 |
| 1437 | split |
| 1438 | call assert_equal(5, &so) |
| 1439 | setlocal so=3 |
| 1440 | call assert_equal(3, &so) |
| 1441 | wincmd w |
| 1442 | call assert_equal(5, &so) |
| 1443 | wincmd w |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1444 | call assert_equal(3, &so) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1445 | setlocal so< |
| 1446 | call assert_equal(5, &so) |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1447 | setglob so=8 |
| 1448 | call assert_equal(8, &so) |
| 1449 | call assert_equal(-1, &l:so) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1450 | setlocal so=0 |
| 1451 | call assert_equal(0, &so) |
| 1452 | setlocal so=-1 |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1453 | call assert_equal(8, &so) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1454 | |
| 1455 | call assert_equal(7, &siso) |
| 1456 | setlocal siso=3 |
| 1457 | call assert_equal(3, &siso) |
| 1458 | wincmd w |
| 1459 | call assert_equal(7, &siso) |
| 1460 | wincmd w |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1461 | call assert_equal(3, &siso) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1462 | setlocal siso< |
| 1463 | call assert_equal(7, &siso) |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1464 | setglob siso=4 |
| 1465 | call assert_equal(4, &siso) |
| 1466 | call assert_equal(-1, &l:siso) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1467 | setlocal siso=0 |
| 1468 | call assert_equal(0, &siso) |
| 1469 | setlocal siso=-1 |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 1470 | call assert_equal(4, &siso) |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 1471 | |
| 1472 | close |
| 1473 | set so& |
| 1474 | set siso& |
| 1475 | endfunc |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 1476 | |
| 1477 | func Test_writedelay() |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 1478 | CheckFunction reltimefloat |
| 1479 | |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 1480 | new |
| 1481 | call setline(1, 'empty') |
| 1482 | redraw |
| 1483 | set writedelay=10 |
| 1484 | let start = reltime() |
| 1485 | call setline(1, repeat('x', 70)) |
| 1486 | redraw |
| 1487 | let elapsed = reltimefloat(reltime(start)) |
| 1488 | set writedelay=0 |
| 1489 | " With 'writedelay' set should take at least 30 * 10 msec |
| 1490 | call assert_inrange(30 * 0.01, 999.0, elapsed) |
| 1491 | |
| 1492 | bwipe! |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 1493 | endfunc |
| 1494 | |
| 1495 | func Test_visualbell() |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 1496 | set belloff= |
Bram Moolenaar | b4e6a2d | 2019-04-03 21:53:33 +0200 | [diff] [blame] | 1497 | set visualbell |
| 1498 | call assert_beeps('normal 0h') |
| 1499 | set novisualbell |
Bram Moolenaar | 7a66627 | 2019-04-03 22:52:34 +0200 | [diff] [blame] | 1500 | set belloff=all |
Bram Moolenaar | 449ac47 | 2019-04-03 21:42:35 +0200 | [diff] [blame] | 1501 | endfunc |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 1502 | |
| 1503 | " Test for the 'write' option |
| 1504 | func Test_write() |
| 1505 | new |
| 1506 | call setline(1, ['L1']) |
| 1507 | set nowrite |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1508 | call assert_fails('write Xwrfile', 'E142:') |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 1509 | set write |
LemonBoy | 5247b0b | 2024-07-12 19:30:58 +0200 | [diff] [blame] | 1510 | " close swapfile |
| 1511 | bw! |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 1512 | endfunc |
| 1513 | |
| 1514 | " Test for 'buftype' option |
| 1515 | func Test_buftype() |
| 1516 | new |
| 1517 | call setline(1, ['L1']) |
| 1518 | set buftype=nowrite |
| 1519 | call assert_fails('write', 'E382:') |
Bram Moolenaar | a3a9c8e | 2020-03-19 12:38:34 +0100 | [diff] [blame] | 1520 | |
| 1521 | for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] |
| 1522 | exe 'set buftype=' .. val |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 1523 | call writefile(['something'], 'XBuftype', 'D') |
Bram Moolenaar | a3a9c8e | 2020-03-19 12:38:34 +0100 | [diff] [blame] | 1524 | call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) |
| 1525 | endfor |
| 1526 | |
Bram Moolenaar | a3a9c8e | 2020-03-19 12:38:34 +0100 | [diff] [blame] | 1527 | bwipe! |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 1528 | endfunc |
| 1529 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1530 | " Test for the 'rightleftcmd' option |
| 1531 | func Test_rightleftcmd() |
| 1532 | CheckFeature rightleft |
| 1533 | set rightleft |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1534 | |
| 1535 | let g:l = [] |
| 1536 | func AddPos() |
| 1537 | call add(g:l, screencol()) |
| 1538 | return '' |
| 1539 | endfunc |
| 1540 | cmap <expr> <F2> AddPos() |
| 1541 | |
zeertzjq | bb404f5 | 2022-07-23 06:25:29 +0100 | [diff] [blame] | 1542 | set rightleftcmd= |
| 1543 | call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" .. |
| 1544 | \ "\<Right>\<F2>\<Esc>", 'xt') |
| 1545 | call assert_equal([2, 5, 3, 4], g:l) |
| 1546 | |
| 1547 | let g:l = [] |
| 1548 | set rightleftcmd=search |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1549 | call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. |
| 1550 | \ "\<Left>\<F2>\<Esc>", 'xt') |
| 1551 | call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) |
| 1552 | |
| 1553 | cunmap <F2> |
| 1554 | unlet g:l |
| 1555 | set rightleftcmd& |
| 1556 | set rightleft& |
| 1557 | endfunc |
| 1558 | |
zeertzjq | 28c162f | 2022-08-14 14:49:50 +0100 | [diff] [blame] | 1559 | " Test for the 'debug' option |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1560 | func Test_debug_option() |
zeertzjq | 28c162f | 2022-08-14 14:49:50 +0100 | [diff] [blame] | 1561 | " redraw to avoid matching previous messages |
| 1562 | redraw |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1563 | set debug=beep |
| 1564 | exe "normal \<C-c>" |
| 1565 | call assert_equal('Beep!', Screenline(&lines)) |
zeertzjq | 28c162f | 2022-08-14 14:49:50 +0100 | [diff] [blame] | 1566 | call assert_equal('line 4:', Screenline(&lines - 1)) |
zeertzjq | 30585e0 | 2023-03-06 08:10:04 +0000 | [diff] [blame] | 1567 | " also check a line above, with a certain window width the colon is there |
| 1568 | call assert_match('Test_debug_option:$', |
| 1569 | \ Screenline(&lines - 3) .. Screenline(&lines - 2)) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1570 | set debug& |
| 1571 | endfunc |
| 1572 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1573 | " Test for the default CDPATH option |
| 1574 | func Test_opt_default_cdpath() |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1575 | let after =<< trim [CODE] |
| 1576 | call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) |
| 1577 | call writefile(v:errors, 'Xtestout') |
| 1578 | qall |
| 1579 | [CODE] |
| 1580 | if has('unix') |
| 1581 | let $CDPATH='/path/to/dir1:/path/to/dir2' |
| 1582 | else |
| 1583 | let $CDPATH='/path/to/dir1;/path/to/dir2' |
| 1584 | endif |
| 1585 | if RunVim([], after, '') |
| 1586 | call assert_equal([], readfile('Xtestout')) |
| 1587 | call delete('Xtestout') |
| 1588 | endif |
| 1589 | endfunc |
| 1590 | |
| 1591 | " Test for setting keycodes using set |
| 1592 | func Test_opt_set_keycode() |
| 1593 | call assert_fails('set <t_k1=l', 'E474:') |
| 1594 | call assert_fails('set <Home=l', 'E474:') |
| 1595 | set <t_k9>=abcd |
| 1596 | call assert_equal('abcd', &t_k9) |
| 1597 | set <t_k9>& |
| 1598 | set <F9>=xyz |
| 1599 | call assert_equal('xyz', &t_k9) |
| 1600 | set <t_k9>& |
Bram Moolenaar | 84f5463 | 2022-06-29 18:39:11 +0100 | [diff] [blame] | 1601 | |
| 1602 | " should we test all of them? |
| 1603 | set t_Ce=testCe |
| 1604 | set t_Cs=testCs |
| 1605 | set t_Us=testUs |
| 1606 | set t_ds=testds |
| 1607 | set t_Ds=testDs |
| 1608 | call assert_equal('testCe', &t_Ce) |
| 1609 | call assert_equal('testCs', &t_Cs) |
| 1610 | call assert_equal('testUs', &t_Us) |
| 1611 | call assert_equal('testds', &t_ds) |
| 1612 | call assert_equal('testDs', &t_Ds) |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1613 | endfunc |
| 1614 | |
| 1615 | " Test for changing options in a sandbox |
| 1616 | func Test_opt_sandbox() |
Yegappan Lakshmanan | a13f3a4 | 2024-11-02 18:40:10 +0100 | [diff] [blame] | 1617 | for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc'] |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1618 | call assert_fails('sandbox set ' .. opt .. '?', 'E48:') |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 1619 | call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1620 | endfor |
Bram Moolenaar | 1363a30 | 2020-04-12 13:50:26 +0200 | [diff] [blame] | 1621 | call assert_fails('sandbox let &modelineexpr = 1', 'E48:') |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1622 | endfunc |
| 1623 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1624 | " Test for setting string global-local option value |
| 1625 | func Test_set_string_global_local_option() |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1626 | setglobal equalprg=gprg |
| 1627 | setlocal equalprg=lprg |
| 1628 | call assert_equal('gprg', &g:equalprg) |
| 1629 | call assert_equal('lprg', &l:equalprg) |
| 1630 | call assert_equal('lprg', &equalprg) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1631 | |
| 1632 | " :set {option}< removes the local value, so that the global value will be used. |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1633 | set equalprg< |
| 1634 | call assert_equal('', &l:equalprg) |
| 1635 | call assert_equal('gprg', &equalprg) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1636 | |
| 1637 | " :setlocal {option}< set the effective value of {option} to its global value. |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1638 | setglobal equalprg=gnewprg |
| 1639 | setlocal equalprg=lnewprg |
| 1640 | setlocal equalprg< |
| 1641 | call assert_equal('gnewprg', &l:equalprg) |
| 1642 | call assert_equal('gnewprg', &equalprg) |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1643 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1644 | set equalprg& |
| 1645 | endfunc |
| 1646 | |
| 1647 | " Test for setting number global-local option value |
| 1648 | func Test_set_number_global_local_option() |
| 1649 | setglobal scrolloff=10 |
| 1650 | setlocal scrolloff=12 |
| 1651 | call assert_equal(10, &g:scrolloff) |
| 1652 | call assert_equal(12, &l:scrolloff) |
| 1653 | call assert_equal(12, &scrolloff) |
| 1654 | |
| 1655 | " :set {option}< set the effective value of {option} to its global value. |
| 1656 | set scrolloff< |
| 1657 | call assert_equal(10, &l:scrolloff) |
| 1658 | call assert_equal(10, &scrolloff) |
| 1659 | |
| 1660 | " :setlocal {option}< removes the local value, so that the global value will be used. |
| 1661 | setglobal scrolloff=15 |
| 1662 | setlocal scrolloff=18 |
| 1663 | setlocal scrolloff< |
| 1664 | call assert_equal(-1, &l:scrolloff) |
| 1665 | call assert_equal(15, &scrolloff) |
| 1666 | |
| 1667 | set scrolloff& |
| 1668 | endfunc |
| 1669 | |
| 1670 | " Test for setting boolean global-local option value |
| 1671 | func Test_set_boolean_global_local_option() |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1672 | setglobal autoread |
| 1673 | setlocal noautoread |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1674 | call assert_equal(1, &g:autoread) |
| 1675 | call assert_equal(0, &l:autoread) |
| 1676 | call assert_equal(0, &autoread) |
| 1677 | |
| 1678 | " :set {option}< set the effective value of {option} to its global value. |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1679 | set autoread< |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1680 | call assert_equal(1, &l:autoread) |
| 1681 | call assert_equal(1, &autoread) |
| 1682 | |
| 1683 | " :setlocal {option}< removes the local value, so that the global value will be used. |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1684 | setglobal noautoread |
| 1685 | setlocal autoread |
| 1686 | setlocal autoread< |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1687 | call assert_equal(-1, &l:autoread) |
| 1688 | call assert_equal(0, &autoread) |
| 1689 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1690 | set autoread& |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1691 | endfunc |
| 1692 | |
Dominique Pelle | 042414f | 2021-07-12 21:43:19 +0200 | [diff] [blame] | 1693 | func Test_set_in_sandbox() |
| 1694 | " Some boolean options cannot be set in sandbox, some can. |
| 1695 | call assert_fails('sandbox set modelineexpr', 'E48:') |
| 1696 | sandbox set number |
| 1697 | call assert_true(&number) |
| 1698 | set number& |
| 1699 | |
| 1700 | " Some boolean options cannot be set in sandbox, some can. |
| 1701 | if has('python') || has('python3') |
| 1702 | call assert_fails('sandbox set pyxversion=3', 'E48:') |
| 1703 | endif |
| 1704 | sandbox set tabstop=4 |
| 1705 | call assert_equal(4, &tabstop) |
| 1706 | set tabstop& |
| 1707 | |
| 1708 | " Some string options cannot be set in sandbox, some can. |
| 1709 | call assert_fails('sandbox set backupdir=/tmp', 'E48:') |
| 1710 | sandbox set filetype=perl |
| 1711 | call assert_equal('perl', &filetype) |
| 1712 | set filetype& |
| 1713 | endfunc |
| 1714 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1715 | " Test for setting string option value |
| 1716 | func Test_set_string_option() |
| 1717 | " :set {option}= |
| 1718 | set makeprg= |
| 1719 | call assert_equal('', &mp) |
| 1720 | set makeprg=abc |
| 1721 | call assert_equal('abc', &mp) |
| 1722 | |
| 1723 | " :set {option}: |
| 1724 | set makeprg: |
| 1725 | call assert_equal('', &mp) |
| 1726 | set makeprg:abc |
| 1727 | call assert_equal('abc', &mp) |
| 1728 | |
| 1729 | " Let string |
| 1730 | let &makeprg = '' |
| 1731 | call assert_equal('', &mp) |
| 1732 | let &makeprg = 'abc' |
| 1733 | call assert_equal('abc', &mp) |
| 1734 | |
| 1735 | " Let number converts to string |
| 1736 | let &makeprg = 42 |
| 1737 | call assert_equal('42', &mp) |
| 1738 | |
| 1739 | " Appending |
| 1740 | set makeprg=abc |
| 1741 | set makeprg+=def |
| 1742 | call assert_equal('abcdef', &mp) |
| 1743 | set makeprg+=def |
| 1744 | call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained') |
| 1745 | let &makeprg .= 'gh' |
| 1746 | call assert_equal('abcdefdefgh', &mp) |
| 1747 | let &makeprg ..= 'ij' |
| 1748 | call assert_equal('abcdefdefghij', &mp) |
| 1749 | |
| 1750 | " Removing |
| 1751 | set makeprg=abcdefghi |
| 1752 | set makeprg-=def |
| 1753 | call assert_equal('abcghi', &mp) |
| 1754 | set makeprg-=def |
| 1755 | call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained') |
| 1756 | |
| 1757 | " Prepending |
| 1758 | set makeprg=abc |
| 1759 | set makeprg^=def |
| 1760 | call assert_equal('defabc', &mp) |
| 1761 | set makeprg^=def |
| 1762 | call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained') |
| 1763 | |
| 1764 | set makeprg& |
| 1765 | endfunc |
| 1766 | |
| 1767 | " Test for setting string comma-separated list option value |
| 1768 | func Test_set_string_comma_list_option() |
| 1769 | " :set {option}= |
| 1770 | set wildignore= |
| 1771 | call assert_equal('', &wildignore) |
| 1772 | set wildignore=*.png |
| 1773 | call assert_equal('*.png', &wildignore) |
| 1774 | |
| 1775 | " :set {option}: |
| 1776 | set wildignore: |
| 1777 | call assert_equal('', &wildignore) |
| 1778 | set wildignore:*.png |
| 1779 | call assert_equal('*.png', &wildignore) |
| 1780 | |
| 1781 | " Let string |
| 1782 | let &wildignore = '' |
| 1783 | call assert_equal('', &wildignore) |
| 1784 | let &wildignore = '*.png' |
| 1785 | call assert_equal('*.png', &wildignore) |
| 1786 | |
| 1787 | " Let number converts to string |
| 1788 | let &wildignore = 42 |
| 1789 | call assert_equal('42', &wildignore) |
| 1790 | |
| 1791 | " Appending |
| 1792 | set wildignore=*.png |
| 1793 | set wildignore+=*.jpg |
| 1794 | call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value') |
| 1795 | set wildignore+=*.jpg |
| 1796 | call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained') |
| 1797 | set wildignore+=jpg |
| 1798 | call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item') |
| 1799 | let &wildignore .= 'foo' |
| 1800 | call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma') |
| 1801 | let &wildignore ..= 'bar' |
| 1802 | call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma') |
| 1803 | |
| 1804 | " Removing |
| 1805 | set wildignore=*.png,*.jpg,*.obj |
| 1806 | set wildignore-=*.jpg |
| 1807 | call assert_equal('*.png,*.obj', &wildignore) |
| 1808 | set wildignore-=*.jpg |
| 1809 | call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained') |
| 1810 | set wildignore-=jpg |
| 1811 | call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item') |
| 1812 | |
| 1813 | " Prepending |
| 1814 | set wildignore=*.png |
| 1815 | set wildignore^=*.jpg |
| 1816 | call assert_equal('*.jpg,*.png', &wildignore) |
| 1817 | set wildignore^=*.jpg |
| 1818 | call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained') |
| 1819 | set wildignore^=jpg |
| 1820 | call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item') |
| 1821 | |
| 1822 | set wildignore& |
| 1823 | endfunc |
| 1824 | |
| 1825 | " Test for setting string flags option value |
| 1826 | func Test_set_string_flags_option() |
| 1827 | " :set {option}= |
| 1828 | set formatoptions= |
| 1829 | call assert_equal('', &fo) |
| 1830 | set formatoptions=abc |
| 1831 | call assert_equal('abc', &fo) |
| 1832 | |
| 1833 | " :set {option}: |
| 1834 | set formatoptions: |
| 1835 | call assert_equal('', &fo) |
| 1836 | set formatoptions:abc |
| 1837 | call assert_equal('abc', &fo) |
| 1838 | |
| 1839 | " Let string |
| 1840 | let &formatoptions = '' |
| 1841 | call assert_equal('', &fo) |
| 1842 | let &formatoptions = 'abc' |
| 1843 | call assert_equal('abc', &fo) |
| 1844 | |
| 1845 | " Let number converts to string |
| 1846 | let &formatoptions = 12 |
| 1847 | call assert_equal('12', &fo) |
| 1848 | |
| 1849 | " Appending |
| 1850 | set formatoptions=abc |
| 1851 | set formatoptions+=pqr |
| 1852 | call assert_equal('abcpqr', &fo) |
| 1853 | set formatoptions+=pqr |
| 1854 | call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained') |
| 1855 | let &formatoptions .= 'r' |
| 1856 | call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained') |
| 1857 | let &formatoptions ..= 'r' |
| 1858 | call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained') |
| 1859 | |
| 1860 | " Removing |
| 1861 | set formatoptions=abcpqr |
| 1862 | set formatoptions-=cp |
| 1863 | call assert_equal('abqr', &fo) |
| 1864 | set formatoptions-=cp |
| 1865 | call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained') |
| 1866 | set formatoptions-=ar |
| 1867 | call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match') |
| 1868 | |
| 1869 | " Prepending |
| 1870 | set formatoptions=abc |
| 1871 | set formatoptions^=pqr |
| 1872 | call assert_equal('pqrabc', &fo) |
| 1873 | set formatoptions^=qr |
| 1874 | call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained') |
| 1875 | |
| 1876 | set formatoptions& |
| 1877 | endfunc |
| 1878 | |
| 1879 | " Test for setting number option value |
| 1880 | func Test_set_number_option() |
| 1881 | " :set {option}= |
| 1882 | set scrolljump=5 |
| 1883 | call assert_equal(5, &sj) |
| 1884 | set scrolljump=-3 |
| 1885 | call assert_equal(-3, &sj) |
| 1886 | |
| 1887 | " :set {option}: |
| 1888 | set scrolljump:7 |
| 1889 | call assert_equal(7, &sj) |
| 1890 | set scrolljump:-5 |
| 1891 | call assert_equal(-5, &sj) |
| 1892 | |
| 1893 | " Set hex |
| 1894 | set scrolljump=0x10 |
| 1895 | call assert_equal(16, &sj) |
| 1896 | set scrolljump=-0x10 |
| 1897 | call assert_equal(-16, &sj) |
| 1898 | set scrolljump=0X12 |
| 1899 | call assert_equal(18, &sj) |
| 1900 | set scrolljump=-0X12 |
| 1901 | call assert_equal(-18, &sj) |
| 1902 | |
| 1903 | " Set octal |
| 1904 | set scrolljump=010 |
| 1905 | call assert_equal(8, &sj) |
| 1906 | set scrolljump=-010 |
| 1907 | call assert_equal(-8, &sj) |
| 1908 | set scrolljump=0o12 |
| 1909 | call assert_equal(10, &sj) |
| 1910 | set scrolljump=-0o12 |
| 1911 | call assert_equal(-10, &sj) |
| 1912 | set scrolljump=0O15 |
| 1913 | call assert_equal(13, &sj) |
| 1914 | set scrolljump=-0O15 |
| 1915 | call assert_equal(-13, &sj) |
| 1916 | |
| 1917 | " Let number |
| 1918 | let &scrolljump = 4 |
| 1919 | call assert_equal(4, &sj) |
| 1920 | let &scrolljump = -6 |
| 1921 | call assert_equal(-6, &sj) |
| 1922 | |
| 1923 | " Let numeric string converts to number |
| 1924 | let &scrolljump = '7' |
| 1925 | call assert_equal(7, &sj) |
| 1926 | let &scrolljump = '-9' |
| 1927 | call assert_equal(-9, &sj) |
| 1928 | |
| 1929 | " Incrementing |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1930 | set shiftwidth=4 |
| 1931 | set sw+=2 |
| 1932 | call assert_equal(6, &sw) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1933 | let &shiftwidth += 2 |
| 1934 | call assert_equal(8, &sw) |
| 1935 | |
| 1936 | " Decrementing |
| 1937 | set shiftwidth=6 |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1938 | set sw-=2 |
| 1939 | call assert_equal(4, &sw) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1940 | let &shiftwidth -= 2 |
| 1941 | call assert_equal(2, &sw) |
| 1942 | |
| 1943 | " Multiplying |
| 1944 | set shiftwidth=4 |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1945 | set sw^=2 |
| 1946 | call assert_equal(8, &sw) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1947 | let &shiftwidth *= 2 |
| 1948 | call assert_equal(16, &sw) |
| 1949 | |
| 1950 | set scrolljump& |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 1951 | set shiftwidth& |
| 1952 | endfunc |
| 1953 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1954 | " Test for setting boolean option value |
| 1955 | func Test_set_boolean_option() |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1956 | set number& |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1957 | |
| 1958 | " :set {option} |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1959 | set number |
| 1960 | call assert_equal(1, &nu) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1961 | |
| 1962 | " :set no{option} |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1963 | set nonu |
| 1964 | call assert_equal(0, &nu) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1965 | |
| 1966 | " :set {option}! |
| 1967 | set number! |
| 1968 | call assert_equal(1, &nu) |
| 1969 | set number! |
| 1970 | call assert_equal(0, &nu) |
| 1971 | |
| 1972 | " :set inv{option} |
| 1973 | set invnumber |
| 1974 | call assert_equal(1, &nu) |
| 1975 | set invnumber |
| 1976 | call assert_equal(0, &nu) |
| 1977 | |
| 1978 | " Let number |
| 1979 | let &number = 1 |
| 1980 | call assert_equal(1, &nu) |
| 1981 | let &number = 0 |
| 1982 | call assert_equal(0, &nu) |
| 1983 | |
| 1984 | " Let numeric string converts to number |
| 1985 | let &number = '1' |
| 1986 | call assert_equal(1, &nu) |
| 1987 | let &number = '0' |
| 1988 | call assert_equal(0, &nu) |
| 1989 | |
| 1990 | " Let v:true and v:false |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1991 | let &nu = v:true |
| 1992 | call assert_equal(1, &nu) |
| 1993 | let &nu = v:false |
| 1994 | call assert_equal(0, &nu) |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1995 | |
Bram Moolenaar | 65d032c | 2020-04-24 20:57:01 +0200 | [diff] [blame] | 1996 | set number& |
| 1997 | endfunc |
| 1998 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 1999 | " Test for setting string option errors |
| 2000 | func Test_set_string_option_errors() |
| 2001 | " :set no{option} |
| 2002 | call assert_fails('set nomakeprg', 'E474:') |
| 2003 | call assert_fails('setlocal nomakeprg', 'E474:') |
| 2004 | call assert_fails('setglobal nomakeprg', 'E474:') |
| 2005 | |
| 2006 | " :set inv{option} |
| 2007 | call assert_fails('set invmakeprg', 'E474:') |
| 2008 | call assert_fails('setlocal invmakeprg', 'E474:') |
| 2009 | call assert_fails('setglobal invmakeprg', 'E474:') |
| 2010 | |
| 2011 | " :set {option}! |
| 2012 | call assert_fails('set makeprg!', 'E488:') |
| 2013 | call assert_fails('setlocal makeprg!', 'E488:') |
| 2014 | call assert_fails('setglobal makeprg!', 'E488:') |
| 2015 | |
| 2016 | " Invalid trailing chars |
| 2017 | call assert_fails('set makeprg??', 'E488:') |
| 2018 | call assert_fails('setlocal makeprg??', 'E488:') |
| 2019 | call assert_fails('setglobal makeprg??', 'E488:') |
| 2020 | call assert_fails('set makeprg&&', 'E488:') |
| 2021 | call assert_fails('setlocal makeprg&&', 'E488:') |
| 2022 | call assert_fails('setglobal makeprg&&', 'E488:') |
| 2023 | call assert_fails('set makeprg<<', 'E488:') |
| 2024 | call assert_fails('setlocal makeprg<<', 'E488:') |
| 2025 | call assert_fails('setglobal makeprg<<', 'E488:') |
| 2026 | call assert_fails('set makeprg@', 'E488:') |
| 2027 | call assert_fails('setlocal makeprg@', 'E488:') |
| 2028 | call assert_fails('setglobal makeprg@', 'E488:') |
| 2029 | |
| 2030 | " Invalid type |
| 2031 | call assert_fails("let &makeprg = ['xxx']", 'E730:') |
| 2032 | endfunc |
| 2033 | |
| 2034 | " Test for setting number option errors |
| 2035 | func Test_set_number_option_errors() |
| 2036 | " :set no{option} |
| 2037 | call assert_fails('set notabstop', 'E474:') |
| 2038 | call assert_fails('setlocal notabstop', 'E474:') |
| 2039 | call assert_fails('setglobal notabstop', 'E474:') |
| 2040 | |
| 2041 | " :set inv{option} |
| 2042 | call assert_fails('set invtabstop', 'E474:') |
| 2043 | call assert_fails('setlocal invtabstop', 'E474:') |
| 2044 | call assert_fails('setglobal invtabstop', 'E474:') |
| 2045 | |
| 2046 | " :set {option}! |
| 2047 | call assert_fails('set tabstop!', 'E488:') |
| 2048 | call assert_fails('setlocal tabstop!', 'E488:') |
| 2049 | call assert_fails('setglobal tabstop!', 'E488:') |
| 2050 | |
| 2051 | " Invalid trailing chars |
| 2052 | call assert_fails('set tabstop??', 'E488:') |
| 2053 | call assert_fails('setlocal tabstop??', 'E488:') |
| 2054 | call assert_fails('setglobal tabstop??', 'E488:') |
| 2055 | call assert_fails('set tabstop&&', 'E488:') |
| 2056 | call assert_fails('setlocal tabstop&&', 'E488:') |
| 2057 | call assert_fails('setglobal tabstop&&', 'E488:') |
| 2058 | call assert_fails('set tabstop<<', 'E488:') |
| 2059 | call assert_fails('setlocal tabstop<<', 'E488:') |
| 2060 | call assert_fails('setglobal tabstop<<', 'E488:') |
| 2061 | call assert_fails('set tabstop@', 'E488:') |
| 2062 | call assert_fails('setlocal tabstop@', 'E488:') |
| 2063 | call assert_fails('setglobal tabstop@', 'E488:') |
| 2064 | |
| 2065 | " Not a number |
| 2066 | call assert_fails('set tabstop=', 'E521:') |
| 2067 | call assert_fails('setlocal tabstop=', 'E521:') |
| 2068 | call assert_fails('setglobal tabstop=', 'E521:') |
| 2069 | call assert_fails('set tabstop=x', 'E521:') |
| 2070 | call assert_fails('setlocal tabstop=x', 'E521:') |
| 2071 | call assert_fails('setglobal tabstop=x', 'E521:') |
| 2072 | call assert_fails('set tabstop=1x', 'E521:') |
| 2073 | call assert_fails('setlocal tabstop=1x', 'E521:') |
| 2074 | call assert_fails('setglobal tabstop=1x', 'E521:') |
| 2075 | call assert_fails('set tabstop=-x', 'E521:') |
| 2076 | call assert_fails('setlocal tabstop=-x', 'E521:') |
| 2077 | call assert_fails('setglobal tabstop=-x', 'E521:') |
| 2078 | call assert_fails('set tabstop=0x', 'E521:') |
| 2079 | call assert_fails('setlocal tabstop=0x', 'E521:') |
| 2080 | call assert_fails('setglobal tabstop=0x', 'E521:') |
| 2081 | call assert_fails('set tabstop=0o', 'E521:') |
| 2082 | call assert_fails('setlocal tabstop=0o', 'E521:') |
| 2083 | call assert_fails('setglobal tabstop=0o', 'E521:') |
| 2084 | call assert_fails("let &tabstop = 'x'", 'E521:') |
| 2085 | call assert_fails("let &g:tabstop = 'x'", 'E521:') |
| 2086 | call assert_fails("let &l:tabstop = 'x'", 'E521:') |
| 2087 | |
| 2088 | " Invalid type |
| 2089 | call assert_fails("let &tabstop = 'xxx'", 'E521:') |
| 2090 | endfunc |
| 2091 | |
| 2092 | " Test for setting boolean option errors |
| 2093 | func Test_set_boolean_option_errors() |
| 2094 | " :set {option}= |
| 2095 | call assert_fails('set number=', 'E474:') |
| 2096 | call assert_fails('setlocal number=', 'E474:') |
| 2097 | call assert_fails('setglobal number=', 'E474:') |
| 2098 | call assert_fails('set number=1', 'E474:') |
| 2099 | call assert_fails('setlocal number=1', 'E474:') |
| 2100 | call assert_fails('setglobal number=1', 'E474:') |
| 2101 | |
| 2102 | " :set {option}: |
| 2103 | call assert_fails('set number:', 'E474:') |
| 2104 | call assert_fails('setlocal number:', 'E474:') |
| 2105 | call assert_fails('setglobal number:', 'E474:') |
| 2106 | call assert_fails('set number:1', 'E474:') |
| 2107 | call assert_fails('setlocal number:1', 'E474:') |
| 2108 | call assert_fails('setglobal number:1', 'E474:') |
| 2109 | |
| 2110 | " :set {option}+= |
| 2111 | call assert_fails('set number+=1', 'E474:') |
| 2112 | call assert_fails('setlocal number+=1', 'E474:') |
| 2113 | call assert_fails('setglobal number+=1', 'E474:') |
| 2114 | |
| 2115 | " :set {option}^= |
| 2116 | call assert_fails('set number^=1', 'E474:') |
| 2117 | call assert_fails('setlocal number^=1', 'E474:') |
| 2118 | call assert_fails('setglobal number^=1', 'E474:') |
| 2119 | |
| 2120 | " :set {option}-= |
| 2121 | call assert_fails('set number-=1', 'E474:') |
| 2122 | call assert_fails('setlocal number-=1', 'E474:') |
| 2123 | call assert_fails('setglobal number-=1', 'E474:') |
| 2124 | |
| 2125 | " Invalid trailing chars |
| 2126 | call assert_fails('set number!!', 'E488:') |
| 2127 | call assert_fails('setlocal number!!', 'E488:') |
| 2128 | call assert_fails('setglobal number!!', 'E488:') |
| 2129 | call assert_fails('set number??', 'E488:') |
| 2130 | call assert_fails('setlocal number??', 'E488:') |
| 2131 | call assert_fails('setglobal number??', 'E488:') |
| 2132 | call assert_fails('set number&&', 'E488:') |
| 2133 | call assert_fails('setlocal number&&', 'E488:') |
| 2134 | call assert_fails('setglobal number&&', 'E488:') |
| 2135 | call assert_fails('set number<<', 'E488:') |
| 2136 | call assert_fails('setlocal number<<', 'E488:') |
| 2137 | call assert_fails('setglobal number<<', 'E488:') |
| 2138 | call assert_fails('set number@', 'E488:') |
| 2139 | call assert_fails('setlocal number@', 'E488:') |
| 2140 | call assert_fails('setglobal number@', 'E488:') |
| 2141 | |
| 2142 | " Invalid type |
| 2143 | call assert_fails("let &number = 'xxx'", 'E521:') |
| 2144 | endfunc |
| 2145 | |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 2146 | " Test for the 'window' option |
| 2147 | func Test_window_opt() |
| 2148 | " Needs only one open widow |
| 2149 | %bw! |
| 2150 | call setline(1, range(1, 8)) |
| 2151 | set window=5 |
| 2152 | exe "normal \<C-F>" |
| 2153 | call assert_equal(4, line('w0')) |
| 2154 | exe "normal \<C-F>" |
| 2155 | call assert_equal(7, line('w0')) |
| 2156 | exe "normal \<C-F>" |
| 2157 | call assert_equal(8, line('w0')) |
| 2158 | exe "normal \<C-B>" |
| 2159 | call assert_equal(5, line('w0')) |
| 2160 | exe "normal \<C-B>" |
| 2161 | call assert_equal(2, line('w0')) |
| 2162 | exe "normal \<C-B>" |
| 2163 | call assert_equal(1, line('w0')) |
| 2164 | set window=1 |
| 2165 | exe "normal gg\<C-F>" |
| 2166 | call assert_equal(2, line('w0')) |
| 2167 | exe "normal \<C-F>" |
| 2168 | call assert_equal(3, line('w0')) |
| 2169 | exe "normal \<C-B>" |
| 2170 | call assert_equal(2, line('w0')) |
| 2171 | exe "normal \<C-B>" |
| 2172 | call assert_equal(1, line('w0')) |
| 2173 | enew! |
| 2174 | set window& |
| 2175 | endfunc |
| 2176 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 2177 | " Test for the 'winminheight' option |
| 2178 | func Test_opt_winminheight() |
| 2179 | only! |
| 2180 | let &winheight = &lines + 4 |
| 2181 | call assert_fails('let &winminheight = &lines + 2', 'E36:') |
| 2182 | call assert_true(&winminheight <= &lines) |
| 2183 | set winminheight& |
| 2184 | set winheight& |
| 2185 | endfunc |
| 2186 | |
Bram Moolenaar | 39d4cab | 2021-03-01 21:02:46 +0100 | [diff] [blame] | 2187 | func Test_opt_winminheight_term() |
| 2188 | CheckRunVimInTerminal |
| 2189 | |
| 2190 | " The tabline should be taken into account. |
| 2191 | let lines =<< trim END |
| 2192 | set wmh=0 stal=2 |
| 2193 | below sp | wincmd _ |
| 2194 | below sp | wincmd _ |
| 2195 | below sp | wincmd _ |
| 2196 | below sp |
| 2197 | END |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 2198 | call writefile(lines, 'Xwinminheight', 'D') |
Bram Moolenaar | 39d4cab | 2021-03-01 21:02:46 +0100 | [diff] [blame] | 2199 | let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) |
| 2200 | call term_sendkeys(buf, ":set wmh=1\n") |
| 2201 | call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) |
| 2202 | |
| 2203 | call StopVimInTerminal(buf) |
Bram Moolenaar | 39d4cab | 2021-03-01 21:02:46 +0100 | [diff] [blame] | 2204 | endfunc |
| 2205 | |
Bram Moolenaar | 9e813b3 | 2021-03-13 14:29:05 +0100 | [diff] [blame] | 2206 | func Test_opt_winminheight_term_tabs() |
| 2207 | CheckRunVimInTerminal |
| 2208 | |
| 2209 | " The tabline should be taken into account. |
| 2210 | let lines =<< trim END |
| 2211 | set wmh=0 stal=2 |
| 2212 | split |
| 2213 | split |
| 2214 | split |
| 2215 | split |
| 2216 | tabnew |
| 2217 | END |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 2218 | call writefile(lines, 'Xwinminheight', 'D') |
Bram Moolenaar | 9e813b3 | 2021-03-13 14:29:05 +0100 | [diff] [blame] | 2219 | let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) |
| 2220 | call term_sendkeys(buf, ":set wmh=1\n") |
| 2221 | call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) |
| 2222 | |
| 2223 | call StopVimInTerminal(buf) |
Bram Moolenaar | 9e813b3 | 2021-03-13 14:29:05 +0100 | [diff] [blame] | 2224 | endfunc |
| 2225 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 2226 | " Test for the 'winminwidth' option |
| 2227 | func Test_opt_winminwidth() |
| 2228 | only! |
| 2229 | let &winwidth = &columns + 4 |
| 2230 | call assert_fails('let &winminwidth = &columns + 2', 'E36:') |
| 2231 | call assert_true(&winminwidth <= &columns) |
| 2232 | set winminwidth& |
| 2233 | set winwidth& |
| 2234 | endfunc |
| 2235 | |
Bram Moolenaar | 994b89d | 2020-08-07 19:12:41 +0200 | [diff] [blame] | 2236 | " Test for setting option value containing spaces with isfname+=32 |
| 2237 | func Test_isfname_with_options() |
| 2238 | set isfname+=32 |
| 2239 | setlocal keywordprg=:term\ help.exe |
| 2240 | call assert_equal(':term help.exe', &keywordprg) |
| 2241 | set isfname& |
| 2242 | setlocal keywordprg& |
| 2243 | endfunc |
| 2244 | |
Bram Moolenaar | 7466706 | 2020-12-28 15:41:41 +0100 | [diff] [blame] | 2245 | " Test that resetting laststatus does change scroll option |
| 2246 | func Test_opt_reset_scroll() |
| 2247 | CheckRunVimInTerminal |
| 2248 | let vimrc =<< trim [CODE] |
| 2249 | set scroll=2 |
| 2250 | set laststatus=2 |
| 2251 | [CODE] |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 2252 | call writefile(vimrc, 'Xscroll', 'D') |
Bram Moolenaar | 7466706 | 2020-12-28 15:41:41 +0100 | [diff] [blame] | 2253 | let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45}) |
| 2254 | call term_sendkeys(buf, ":verbose set scroll?\n") |
| 2255 | call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))}) |
| 2256 | call assert_match('^\s*scroll=7$', term_getline(buf, 14)) |
Bram Moolenaar | 7466706 | 2020-12-28 15:41:41 +0100 | [diff] [blame] | 2257 | |
| 2258 | " clean up |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 2259 | call StopVimInTerminal(buf) |
Bram Moolenaar | 7466706 | 2020-12-28 15:41:41 +0100 | [diff] [blame] | 2260 | endfunc |
| 2261 | |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 2262 | " Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm' |
| 2263 | func Test_VIM_POSIX() |
| 2264 | let saved_VIM_POSIX = getenv("VIM_POSIX") |
| 2265 | |
| 2266 | call setenv('VIM_POSIX', "1") |
| 2267 | let after =<< trim [CODE] |
| 2268 | call writefile([&cpo, &shm], 'X_VIM_POSIX') |
| 2269 | qall |
| 2270 | [CODE] |
| 2271 | if RunVim([], after, '') |
glepnir | 4ade668 | 2025-07-03 20:41:23 +0200 | [diff] [blame] | 2272 | call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;~', |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 2273 | \ 'AS'], readfile('X_VIM_POSIX')) |
| 2274 | endif |
| 2275 | |
| 2276 | call setenv('VIM_POSIX', v:null) |
| 2277 | let after =<< trim [CODE] |
| 2278 | call writefile([&cpo, &shm], 'X_VIM_POSIX') |
| 2279 | qall |
| 2280 | [CODE] |
| 2281 | if RunVim([], after, '') |
Christian Brabandt | 22105fd | 2024-07-15 20:51:11 +0200 | [diff] [blame] | 2282 | call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;', |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 2283 | \ 'S'], readfile('X_VIM_POSIX')) |
| 2284 | endif |
| 2285 | |
| 2286 | call delete('X_VIM_POSIX') |
| 2287 | call setenv('VIM_POSIX', saved_VIM_POSIX) |
| 2288 | endfunc |
| 2289 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 2290 | " Test for setting an option to a Vi or Vim default |
| 2291 | func Test_opt_default() |
| 2292 | set formatoptions&vi |
| 2293 | call assert_equal('vt', &formatoptions) |
| 2294 | set formatoptions&vim |
| 2295 | call assert_equal('tcq', &formatoptions) |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 2296 | |
| 2297 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
| 2298 | set fencs=latin1 |
| 2299 | set fencs& |
| 2300 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
| 2301 | set fencs=latin1 |
| 2302 | set all& |
| 2303 | call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 2304 | endfunc |
| 2305 | |
| 2306 | " Test for the 'cmdheight' option |
Milly | 2cddf0e | 2024-11-28 18:16:55 +0100 | [diff] [blame] | 2307 | func Test_opt_cmdheight() |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 2308 | %bw! |
| 2309 | let ht = &lines |
| 2310 | set cmdheight=9999 |
| 2311 | call assert_equal(1, winheight(0)) |
| 2312 | call assert_equal(ht - 1, &cmdheight) |
| 2313 | set cmdheight& |
Milly | 2cddf0e | 2024-11-28 18:16:55 +0100 | [diff] [blame] | 2314 | |
| 2315 | " The status line should be taken into account. |
| 2316 | set laststatus=2 |
| 2317 | set cmdheight=9999 |
| 2318 | call assert_equal(ht - 2, &cmdheight) |
| 2319 | set cmdheight& laststatus& |
| 2320 | |
| 2321 | " The tabline should be taken into account only non-GUI. |
| 2322 | set showtabline=2 |
| 2323 | set cmdheight=9999 |
| 2324 | if has('gui_running') |
| 2325 | call assert_equal(ht - 1, &cmdheight) |
| 2326 | else |
| 2327 | call assert_equal(ht - 2, &cmdheight) |
| 2328 | endif |
| 2329 | set cmdheight& showtabline& |
| 2330 | |
| 2331 | " The 'winminheight' should be taken into account. |
| 2332 | set winheight=3 winminheight=3 |
| 2333 | split |
| 2334 | set cmdheight=9999 |
| 2335 | call assert_equal(ht - 8, &cmdheight) |
| 2336 | %bw! |
| 2337 | set cmdheight& winminheight& winheight& |
| 2338 | |
| 2339 | " Only the windows in the current tabpage are taken into account. |
| 2340 | set winheight=3 winminheight=3 showtabline=0 |
| 2341 | split |
| 2342 | tabnew |
| 2343 | set cmdheight=9999 |
| 2344 | call assert_equal(ht - 3, &cmdheight) |
| 2345 | %bw! |
| 2346 | set cmdheight& winminheight& winheight& showtabline& |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 2347 | endfunc |
| 2348 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 2349 | " To specify a control character as an option value, '^' can be used |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 2350 | func Test_opt_control_char() |
| 2351 | set wildchar=^v |
| 2352 | call assert_equal("\<C-V>", nr2char(&wildchar)) |
| 2353 | set wildcharm=^r |
| 2354 | call assert_equal("\<C-R>", nr2char(&wildcharm)) |
| 2355 | " Bug: This doesn't work for the 'cedit' and 'termwinkey' options |
| 2356 | set wildchar& wildcharm& |
| 2357 | endfunc |
| 2358 | |
| 2359 | " Test for the 'errorbells' option |
| 2360 | func Test_opt_errorbells() |
| 2361 | set errorbells |
| 2362 | call assert_beeps('s/a1b2/x1y2/') |
| 2363 | set noerrorbells |
| 2364 | endfunc |
| 2365 | |
Dominique Pelle | 042414f | 2021-07-12 21:43:19 +0200 | [diff] [blame] | 2366 | func Test_opt_scrolljump() |
| 2367 | help |
| 2368 | resize 10 |
| 2369 | |
| 2370 | " Test with positive 'scrolljump'. |
| 2371 | set scrolljump=2 |
| 2372 | norm! Lj |
| 2373 | call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, |
| 2374 | \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0}, |
| 2375 | \ winsaveview()) |
| 2376 | |
| 2377 | " Test with negative 'scrolljump' (percentage of window height). |
| 2378 | set scrolljump=-40 |
| 2379 | norm! ggLj |
| 2380 | call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, |
| 2381 | \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0}, |
| 2382 | \ winsaveview()) |
| 2383 | |
| 2384 | set scrolljump& |
| 2385 | bw |
| 2386 | endfunc |
| 2387 | |
Bakudankun | 29f3a45 | 2021-12-11 12:28:08 +0000 | [diff] [blame] | 2388 | " Test for the 'cdhome' option |
| 2389 | func Test_opt_cdhome() |
| 2390 | if has('unix') || has('vms') |
| 2391 | throw 'Skipped: only works on non-Unix' |
| 2392 | endif |
| 2393 | |
| 2394 | set cdhome& |
| 2395 | call assert_equal(0, &cdhome) |
| 2396 | set cdhome |
| 2397 | |
| 2398 | " This paragraph is copied from Test_cd_no_arg(). |
| 2399 | let path = getcwd() |
| 2400 | cd |
| 2401 | call assert_equal($HOME, getcwd()) |
| 2402 | call assert_notequal(path, getcwd()) |
| 2403 | exe 'cd ' .. fnameescape(path) |
| 2404 | call assert_equal(path, getcwd()) |
| 2405 | |
| 2406 | set cdhome& |
| 2407 | endfunc |
| 2408 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 2409 | func Test_set_completion_fuzzy() |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 2410 | CheckOption termguicolors |
| 2411 | |
| 2412 | " Test default option completion |
| 2413 | set wildoptions= |
| 2414 | call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 2415 | call assert_equal('"set termguicolors', @:) |
| 2416 | |
| 2417 | call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 2418 | call assert_equal('"set notermguicolors', @:) |
| 2419 | |
| 2420 | " Test fuzzy option completion |
| 2421 | set wildoptions=fuzzy |
| 2422 | call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 2423 | call assert_equal('"set termguicolors termencoding', @:) |
| 2424 | |
| 2425 | call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx') |
| 2426 | call assert_equal('"set notermguicolors', @:) |
| 2427 | |
| 2428 | set wildoptions= |
| 2429 | endfunc |
| 2430 | |
Sean Dewar | 39c46b4 | 2022-05-12 17:44:29 +0100 | [diff] [blame] | 2431 | func Test_switchbuf_reset() |
| 2432 | set switchbuf=useopen |
| 2433 | sblast |
| 2434 | call assert_equal(1, winnr('$')) |
| 2435 | set all& |
| 2436 | call assert_equal('', &switchbuf) |
| 2437 | sblast |
| 2438 | call assert_equal(2, winnr('$')) |
| 2439 | only! |
| 2440 | endfunc |
| 2441 | |
zeertzjq | fcba86c | 2022-09-22 13:57:32 +0100 | [diff] [blame] | 2442 | " :set empty string for global 'keywordprg' falls back to ":help" |
| 2443 | func Test_keywordprg_empty() |
| 2444 | let k = &keywordprg |
| 2445 | set keywordprg=man |
| 2446 | call assert_equal('man', &keywordprg) |
| 2447 | set keywordprg= |
| 2448 | call assert_equal(':help', &keywordprg) |
| 2449 | set keywordprg=man |
| 2450 | call assert_equal('man', &keywordprg) |
| 2451 | call assert_equal("\n keywordprg=:help", execute('set kp= kp?')) |
| 2452 | let &keywordprg = k |
| 2453 | endfunc |
| 2454 | |
Bram Moolenaar | 0aad88f | 2022-11-12 11:54:26 +0000 | [diff] [blame] | 2455 | " check that the very first buffer created does not have 'endoffile' set |
| 2456 | func Test_endoffile_default() |
| 2457 | let after =<< trim [CODE] |
| 2458 | call writefile([execute('set eof?')], 'Xtestout') |
| 2459 | qall! |
| 2460 | [CODE] |
| 2461 | if RunVim([], after, '') |
| 2462 | call assert_equal(["\nnoendoffile"], readfile('Xtestout')) |
| 2463 | endif |
| 2464 | call delete('Xtestout') |
| 2465 | endfunc |
| 2466 | |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 2467 | " Test for setting the 'lines' and 'columns' options to a minimum value |
| 2468 | func Test_set_min_lines_columns() |
| 2469 | let save_lines = &lines |
| 2470 | let save_columns = &columns |
| 2471 | |
| 2472 | let after =<< trim END |
| 2473 | set nomore |
| 2474 | let msg = [] |
| 2475 | let v:errmsg = '' |
| 2476 | silent! let &columns=0 |
| 2477 | call add(msg, v:errmsg) |
| 2478 | silent! set columns=0 |
| 2479 | call add(msg, v:errmsg) |
| 2480 | silent! call setbufvar('', '&columns', 0) |
| 2481 | call add(msg, v:errmsg) |
| 2482 | "call writefile(msg, 'XResultsetminlines') |
| 2483 | silent! let &lines=0 |
| 2484 | call add(msg, v:errmsg) |
| 2485 | silent! set lines=0 |
| 2486 | call add(msg, v:errmsg) |
| 2487 | silent! call setbufvar('', '&lines', 0) |
| 2488 | call add(msg, v:errmsg) |
| 2489 | call writefile(msg, 'XResultsetminlines') |
| 2490 | qall! |
| 2491 | END |
| 2492 | if RunVim([], after, '') |
| 2493 | call assert_equal(['E594: Need at least 12 columns', |
| 2494 | \ 'E594: Need at least 12 columns: columns=0', |
| 2495 | \ 'E594: Need at least 12 columns', |
| 2496 | \ 'E593: Need at least 2 lines', |
| 2497 | \ 'E593: Need at least 2 lines: lines=0', |
| 2498 | \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines')) |
| 2499 | endif |
| 2500 | |
| 2501 | call delete('XResultsetminlines') |
| 2502 | let &lines = save_lines |
| 2503 | let &columns = save_columns |
| 2504 | endfunc |
zeertzjq | fcba86c | 2022-09-22 13:57:32 +0100 | [diff] [blame] | 2505 | |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2506 | " Test for reverting a string option value if the new value is invalid. |
| 2507 | func Test_string_option_revert_on_failure() |
| 2508 | new |
| 2509 | let optlist = [ |
| 2510 | \ ['ambiwidth', 'double', 'a123'], |
| 2511 | \ ['background', 'dark', 'a123'], |
| 2512 | \ ['backspace', 'eol', 'a123'], |
| 2513 | \ ['backupcopy', 'no', 'a123'], |
| 2514 | \ ['belloff', 'showmatch', 'a123'], |
| 2515 | \ ['breakindentopt', 'min:10', 'list'], |
| 2516 | \ ['bufhidden', 'wipe', 'a123'], |
| 2517 | \ ['buftype', 'nowrite', 'a123'], |
| 2518 | \ ['casemap', 'keepascii', 'a123'], |
| 2519 | \ ['cedit', "\<C-Y>", 'z'], |
| 2520 | \ ['colorcolumn', '10', 'z'], |
| 2521 | \ ['commentstring', '#%s', 'a123'], |
| 2522 | \ ['complete', '.,t', 'a'], |
| 2523 | \ ['completefunc', 'MyCmplFunc', '1a-'], |
| 2524 | \ ['completeopt', 'popup', 'a123'], |
| 2525 | \ ['completepopup', 'width:20', 'border'], |
| 2526 | \ ['concealcursor', 'v', 'xyz'], |
glepnir | 4ade668 | 2025-07-03 20:41:23 +0200 | [diff] [blame] | 2527 | \ ['cpoptions', 'HJ', 'Q'], |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2528 | \ ['cryptmethod', 'zip', 'a123'], |
| 2529 | \ ['cursorlineopt', 'screenline', 'a123'], |
| 2530 | \ ['debug', 'throw', 'a123'], |
| 2531 | \ ['diffopt', 'iwhite', 'a123'], |
| 2532 | \ ['display', 'uhex', 'a123'], |
| 2533 | \ ['eadirection', 'hor', 'a123'], |
| 2534 | \ ['encoding', 'utf-8', 'a123'], |
| 2535 | \ ['eventignore', 'TextYankPost', 'a123'], |
Luuk van Baal | b7147f8 | 2025-02-08 18:52:39 +0100 | [diff] [blame] | 2536 | \ ['eventignorewin', 'WinScrolled', 'a123'], |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2537 | \ ['fileencoding', 'utf-8', 'a123,'], |
| 2538 | \ ['fileformat', 'mac', 'a123'], |
| 2539 | \ ['fileformats', 'mac', 'a123'], |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2540 | \ ['filetype', 'abc', 'a^b'], |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2541 | \ ['fillchars', 'diff:~', 'a123'], |
| 2542 | \ ['foldclose', 'all', 'a123'], |
| 2543 | \ ['foldmarker', '[[[,]]]', '[[['], |
| 2544 | \ ['foldmethod', 'marker', 'a123'], |
| 2545 | \ ['foldopen', 'percent', 'a123'], |
| 2546 | \ ['formatoptions', 'an', '*'], |
| 2547 | \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'], |
| 2548 | \ ['helplang', 'en', 'a'], |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2549 | \ ['highlight', '!:CursorColumn', '8:'], |
| 2550 | \ ['keymodel', 'stopsel', 'a123'], |
| 2551 | \ ['keyprotocol', 'kitty:kitty', 'kitty:'], |
| 2552 | \ ['lispoptions', 'expr:1', 'a123'], |
| 2553 | \ ['listchars', 'tab:->', 'tab:'], |
| 2554 | \ ['matchpairs', '<:>', '<:'], |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 2555 | \ ['messagesopt', 'hit-enter,history:100', 'a123'], |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2556 | \ ['mkspellmem', '100000,1000,100', '100000'], |
| 2557 | \ ['mouse', 'nvi', 'z'], |
| 2558 | \ ['mousemodel', 'extend', 'a123'], |
| 2559 | \ ['nrformats', 'alpha', 'a123'], |
| 2560 | \ ['omnifunc', 'MyOmniFunc', '1a-'], |
| 2561 | \ ['operatorfunc', 'MyOpFunc', '1a-'], |
| 2562 | \ ['previewpopup', 'width:20', 'a123'], |
| 2563 | \ ['printoptions', 'paper:A4', 'a123:'], |
| 2564 | \ ['quickfixtextfunc', 'MyQfFunc', '1a-'], |
| 2565 | \ ['rulerformat', '%l', '%['], |
| 2566 | \ ['scrollopt', 'hor,jump', 'a123'], |
| 2567 | \ ['selection', 'exclusive', 'a123'], |
| 2568 | \ ['selectmode', 'cmd', 'a123'], |
| 2569 | \ ['sessionoptions', 'options', 'a123'], |
| 2570 | \ ['shortmess', 'w', '2'], |
| 2571 | \ ['showbreak', '>>', "\x01"], |
| 2572 | \ ['showcmdloc', 'statusline', 'a123'], |
| 2573 | \ ['signcolumn', 'no', 'a123'], |
| 2574 | \ ['spellcapcheck', '[.?!]\+', '%\{'], |
| 2575 | \ ['spellfile', 'MySpell.en.add', "\x01"], |
| 2576 | \ ['spelllang', 'en', "#"], |
| 2577 | \ ['spelloptions', 'camel', 'a123'], |
| 2578 | \ ['spellsuggest', 'double', 'a123'], |
| 2579 | \ ['splitkeep', 'topline', 'a123'], |
| 2580 | \ ['statusline', '%f', '%['], |
| 2581 | \ ['swapsync', 'sync', 'a123'], |
| 2582 | \ ['switchbuf', 'usetab', 'a123'], |
| 2583 | \ ['syntax', 'abc', 'a^b'], |
| 2584 | \ ['tabline', '%f', '%['], |
| 2585 | \ ['tagcase', 'ignore', 'a123'], |
| 2586 | \ ['tagfunc', 'MyTagFunc', '1a-'], |
| 2587 | \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'], |
| 2588 | \ ['viewoptions', 'options', 'a123'], |
| 2589 | \ ['virtualedit', 'onemore', 'a123'], |
| 2590 | \ ['whichwrap', '<,>', '{,}'], |
| 2591 | \ ['wildmode', 'list', 'a123'], |
| 2592 | \ ['wildoptions', 'pum', 'a123'] |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2593 | \ ] |
| 2594 | if has('gui') |
| 2595 | call add(optlist, ['browsedir', 'buffer', 'a123']) |
| 2596 | endif |
| 2597 | if has('clipboard_working') |
| 2598 | call add(optlist, ['clipboard', 'unnamed', 'a123']) |
Foxe Chen | b90c239 | 2025-06-27 21:10:35 +0200 | [diff] [blame] | 2599 | call add(optlist, ['clipmethod', 'wayland', 'a123']) |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2600 | endif |
| 2601 | if has('win32') |
| 2602 | call add(optlist, ['completeslash', 'slash', 'a123']) |
| 2603 | endif |
| 2604 | if has('cscope') |
| 2605 | call add(optlist, ['cscopequickfix', 't-', 'z-']) |
| 2606 | endif |
| 2607 | if !has('win32') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2608 | call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-']) |
| 2609 | call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-']) |
| 2610 | endif |
| 2611 | if has('keymap') |
| 2612 | call add(optlist, ['keymap', 'greek', '[]']) |
| 2613 | endif |
| 2614 | if has('mouseshape') |
| 2615 | call add(optlist, ['mouseshape', 'm:no', 'a123:']) |
| 2616 | endif |
| 2617 | if has('win32') && has('gui') |
| 2618 | call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123']) |
| 2619 | endif |
| 2620 | if has('rightleft') |
| 2621 | call add(optlist, ['rightleftcmd', 'search', 'a123']) |
| 2622 | endif |
| 2623 | if has('terminal') |
| 2624 | call add(optlist, ['termwinkey', '<C-L>', '<C']) |
| 2625 | call add(optlist, ['termwinsize', '24x80', '100']) |
| 2626 | endif |
| 2627 | if has('win32') && has('terminal') |
| 2628 | call add(optlist, ['termwintype', 'winpty', 'a123']) |
| 2629 | endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2630 | if exists('+toolbar') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2631 | call add(optlist, ['toolbar', 'text', 'a123']) |
James McCoy | db1887c | 2023-03-02 18:36:33 +0000 | [diff] [blame] | 2632 | endif |
| 2633 | if exists('+toolbariconsize') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2634 | call add(optlist, ['toolbariconsize', 'medium', 'a123']) |
| 2635 | endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2636 | if exists('+ttymouse') && !has('gui') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2637 | call add(optlist, ['ttymouse', 'xterm', 'a123']) |
| 2638 | endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2639 | if exists('+vartabs') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2640 | call add(optlist, ['varsofttabstop', '12', 'a123']) |
| 2641 | call add(optlist, ['vartabstop', '4,20', '4,']) |
| 2642 | endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2643 | if exists('+winaltkeys') |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2644 | call add(optlist, ['winaltkeys', 'no', 'a123']) |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2645 | endif |
| 2646 | for opt in optlist |
| 2647 | exe $"let save_opt = &{opt[0]}" |
Yegappan Lakshmanan | 5da901b | 2023-02-27 12:47:47 +0000 | [diff] [blame] | 2648 | try |
| 2649 | exe $"let &{opt[0]} = '{opt[1]}'" |
| 2650 | catch |
| 2651 | call assert_report($"Caught {v:exception} with {opt->string()}") |
| 2652 | endtry |
Yegappan Lakshmanan | 8ad862a | 2023-02-23 15:05:22 +0000 | [diff] [blame] | 2653 | call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0]) |
| 2654 | call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0]) |
| 2655 | exe $"let &{opt[0]} = save_opt" |
| 2656 | endfor |
| 2657 | bw! |
| 2658 | endfunc |
| 2659 | |
Christian Brabandt | 4a8eb6e | 2023-08-13 19:43:42 +0200 | [diff] [blame] | 2660 | func Test_set_option_window_global_local() |
| 2661 | new Xbuffer1 |
| 2662 | let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ] |
| 2663 | setlocal scrolloff=2 |
| 2664 | setglobal scrolloff=3 |
| 2665 | setl modified |
| 2666 | " A new buffer has its own window-local options |
| 2667 | hide enew |
| 2668 | call assert_equal(-1, &l:scrolloff) |
| 2669 | call assert_equal(3, &g:scrolloff) |
| 2670 | " A new window opened with its own buffer-local options |
| 2671 | new |
| 2672 | call assert_equal(-1, &l:scrolloff) |
| 2673 | call assert_equal(3, &g:scrolloff) |
| 2674 | " Re-open Xbuffer1 and it should use |
| 2675 | " the previous set window-local options |
| 2676 | b Xbuffer1 |
| 2677 | call assert_equal(2, &l:scrolloff) |
| 2678 | call assert_equal(3, &g:scrolloff) |
| 2679 | bw! |
| 2680 | bw! |
| 2681 | let &g:scrolloff = _gso |
| 2682 | endfunc |
| 2683 | |
| 2684 | func GetGlobalLocalWindowOptions() |
| 2685 | new |
| 2686 | sil! r $VIMRUNTIME/doc/options.txt |
| 2687 | " Filter for global or local to window |
| 2688 | v/^'.*'.*\n.*global or local to window |global-local/d |
| 2689 | " get option value and type |
| 2690 | sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g |
| 2691 | sil %s/empty/""/g |
| 2692 | " split the result |
| 2693 | let result=getline(1,'$')->map({_, val -> split(val, ' ')}) |
| 2694 | bw! |
| 2695 | return result |
| 2696 | endfunc |
| 2697 | |
| 2698 | func Test_set_option_window_global_local_all() |
| 2699 | new Xbuffer2 |
| 2700 | |
| 2701 | let optionlist = GetGlobalLocalWindowOptions() |
| 2702 | for [opt, type, default] in optionlist |
| 2703 | let _old = eval('&g:' .. opt) |
| 2704 | if type == 'string' |
| 2705 | if opt == 'fillchars' |
| 2706 | exe 'setl ' .. opt .. '=vert:+' |
| 2707 | exe 'setg ' .. opt .. '=vert:+,fold:+' |
| 2708 | elseif opt == 'listchars' |
| 2709 | exe 'setl ' .. opt .. '=tab:>>' |
| 2710 | exe 'setg ' .. opt .. '=tab:++' |
| 2711 | elseif opt == 'virtualedit' |
| 2712 | exe 'setl ' .. opt .. '=all' |
| 2713 | exe 'setg ' .. opt .. '=block' |
| 2714 | else |
| 2715 | exe 'setl ' .. opt .. '=Local' |
| 2716 | exe 'setg ' .. opt .. '=Global' |
| 2717 | endif |
| 2718 | elseif type == 'number' |
| 2719 | exe 'setl ' .. opt .. '=5' |
| 2720 | exe 'setg ' .. opt .. '=10' |
| 2721 | endif |
| 2722 | setl modified |
| 2723 | hide enew |
| 2724 | if type == 'string' |
| 2725 | call assert_equal('', eval('&l:' .. opt)) |
| 2726 | if opt == 'fillchars' |
| 2727 | call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt) |
| 2728 | elseif opt == 'listchars' |
| 2729 | call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt) |
| 2730 | elseif opt == 'virtualedit' |
| 2731 | call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt) |
| 2732 | else |
| 2733 | call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt) |
| 2734 | endif |
| 2735 | elseif type == 'number' |
| 2736 | call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt) |
| 2737 | call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt) |
| 2738 | endif |
| 2739 | bw! |
| 2740 | exe 'let &g:' .. opt .. '=' .. default |
| 2741 | endfor |
| 2742 | bw! |
| 2743 | endfunc |
| 2744 | |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 2745 | func Test_paste_depending_options() |
| 2746 | " setting the paste option, resets all dependent options |
| 2747 | " and will be reported correctly using :verbose set <option>? |
| 2748 | let lines =<< trim [CODE] |
| 2749 | " set paste test |
| 2750 | set autoindent |
| 2751 | set expandtab |
| 2752 | " disabled, because depends on compiled feature set |
| 2753 | " set hkmap |
| 2754 | " set revins |
| 2755 | " set varsofttabstop=8,32,8 |
| 2756 | set ruler |
| 2757 | set showmatch |
| 2758 | set smarttab |
| 2759 | set softtabstop=4 |
| 2760 | set textwidth=80 |
| 2761 | set wrapmargin=10 |
| 2762 | |
| 2763 | source Xvimrc_paste2 |
| 2764 | |
| 2765 | redir > Xoutput_paste |
| 2766 | verbose set expandtab? |
| 2767 | verbose setg expandtab? |
| 2768 | verbose setl expandtab? |
| 2769 | redir END |
| 2770 | |
| 2771 | qall! |
| 2772 | [CODE] |
| 2773 | |
| 2774 | call writefile(lines, 'Xvimrc_paste', 'D') |
| 2775 | call writefile(['set paste'], 'Xvimrc_paste2', 'D') |
| 2776 | if !RunVim([], lines, '--clean') |
| 2777 | return |
| 2778 | endif |
| 2779 | |
| 2780 | let result = readfile('Xoutput_paste')->filter('!empty(v:val)') |
| 2781 | call assert_equal('noexpandtab', result[0]) |
| 2782 | call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1]) |
| 2783 | call assert_equal('noexpandtab', result[2]) |
| 2784 | call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3]) |
| 2785 | call assert_equal('noexpandtab', result[4]) |
| 2786 | call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5]) |
| 2787 | |
| 2788 | call delete('Xoutput_paste') |
| 2789 | endfunc |
| 2790 | |
| 2791 | func Test_binary_depending_options() |
| 2792 | " setting the paste option, resets all dependent options |
| 2793 | " and will be reported correctly using :verbose set <option>? |
| 2794 | let lines =<< trim [CODE] |
| 2795 | " set binary test |
| 2796 | set expandtab |
| 2797 | |
| 2798 | source Xvimrc_bin2 |
| 2799 | |
| 2800 | redir > Xoutput_bin |
| 2801 | verbose set expandtab? |
| 2802 | verbose setg expandtab? |
| 2803 | verbose setl expandtab? |
| 2804 | redir END |
| 2805 | |
| 2806 | qall! |
| 2807 | [CODE] |
| 2808 | |
| 2809 | call writefile(lines, 'Xvimrc_bin', 'D') |
| 2810 | call writefile(['set binary'], 'Xvimrc_bin2', 'D') |
| 2811 | if !RunVim([], lines, '--clean') |
| 2812 | return |
| 2813 | endif |
| 2814 | |
| 2815 | let result = readfile('Xoutput_bin')->filter('!empty(v:val)') |
| 2816 | call assert_equal('noexpandtab', result[0]) |
| 2817 | call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1]) |
| 2818 | call assert_equal('noexpandtab', result[2]) |
| 2819 | call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3]) |
| 2820 | call assert_equal('noexpandtab', result[4]) |
| 2821 | call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5]) |
| 2822 | |
| 2823 | call delete('Xoutput_bin') |
| 2824 | endfunc |
| 2825 | |
Gregory Anders | 3695d0e | 2023-09-29 20:17:20 +0200 | [diff] [blame] | 2826 | func Test_set_keyprotocol() |
| 2827 | CheckNotGui |
| 2828 | |
| 2829 | let term = &term |
| 2830 | set term=ansi |
| 2831 | call assert_equal('', &t_TI) |
| 2832 | |
| 2833 | " Setting 'keyprotocol' should affect terminal codes without needing to |
| 2834 | " reset 'term' |
| 2835 | set keyprotocol+=ansi:kitty |
| 2836 | call assert_equal("\<Esc>[=1;1u", &t_TI) |
| 2837 | let &term = term |
| 2838 | endfunc |
| 2839 | |
Luuk van Baal | 1bf1bf5 | 2023-10-28 21:43:31 +0200 | [diff] [blame] | 2840 | func Test_set_wrap() |
| 2841 | " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect |
| 2842 | " cursor position. |
| 2843 | set wrap smoothscroll scrolloff=5 |
| 2844 | |
| 2845 | call setline(1, ['', 'aaaa'->repeat(500)]) |
| 2846 | 20 split |
| 2847 | 20 vsplit |
| 2848 | norm 2G$ |
| 2849 | redraw |
| 2850 | set nowrap |
| 2851 | call assert_equal(2, winline()) |
| 2852 | |
| 2853 | set wrap& smoothscroll& scrolloff& |
| 2854 | endfunc |
| 2855 | |
zeertzjq | cd3a13e | 2024-02-24 16:51:32 +0100 | [diff] [blame] | 2856 | func Test_delcombine() |
| 2857 | new |
| 2858 | set backspace=indent,eol,start |
| 2859 | |
| 2860 | set delcombine |
| 2861 | call setline(1, 'β̳̈:β̳̈') |
| 2862 | normal! 0x |
| 2863 | call assert_equal('β̈:β̳̈', getline(1)) |
| 2864 | exe "normal! A\<BS>" |
| 2865 | call assert_equal('β̈:β̈', getline(1)) |
| 2866 | normal! 0x |
| 2867 | call assert_equal('β:β̈', getline(1)) |
| 2868 | exe "normal! A\<BS>" |
| 2869 | call assert_equal('β:β', getline(1)) |
| 2870 | normal! 0x |
| 2871 | call assert_equal(':β', getline(1)) |
| 2872 | exe "normal! A\<BS>" |
| 2873 | call assert_equal(':', getline(1)) |
| 2874 | |
| 2875 | set nodelcombine |
| 2876 | call setline(1, 'β̳̈:β̳̈') |
| 2877 | normal! 0x |
| 2878 | call assert_equal(':β̳̈', getline(1)) |
| 2879 | exe "normal! A\<BS>" |
| 2880 | call assert_equal(':', getline(1)) |
| 2881 | |
| 2882 | set backspace& delcombine& |
| 2883 | bwipe! |
| 2884 | endfunc |
| 2885 | |
Milly | 484face | 2024-10-12 11:26:06 +0200 | [diff] [blame] | 2886 | " Should not raise errors when set missing-options. |
| 2887 | func Test_set_missing_options() |
| 2888 | set autoprint |
| 2889 | set beautify |
| 2890 | set flash |
| 2891 | set graphic |
| 2892 | set hardtabs=8 |
| 2893 | set mesg |
| 2894 | set novice |
| 2895 | set open |
| 2896 | set optimize |
| 2897 | set redraw |
| 2898 | set slowopen |
| 2899 | set sourceany |
| 2900 | set w300=23 |
| 2901 | set w1200=23 |
| 2902 | set w9600=23 |
| 2903 | endfunc |
| 2904 | |
Christian Brabandt | 231b4fc | 2024-12-28 16:27:49 +0100 | [diff] [blame] | 2905 | func Test_default_keyprotocol() |
| 2906 | " default value of keyprotocol |
| 2907 | call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol) |
| 2908 | endfunc |
| 2909 | |
Bram Moolenaar | 5d98dc2 | 2020-01-29 21:57:34 +0100 | [diff] [blame] | 2910 | " vim: shiftwidth=2 sts=2 expandtab |