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