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