Bram Moolenaar | 1473551 | 2016-03-26 21:00:08 +0100 | [diff] [blame] | 1 | " Tests for autocommands |
| 2 | |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 5 | source term_util.vim |
LemonBoy | 0937182 | 2022-04-08 15:18:45 +0100 | [diff] [blame] | 6 | source screendump.vim |
Bram Moolenaar | 6f2465d | 2022-03-22 18:13:01 +0000 | [diff] [blame] | 7 | import './vim9.vim' as v9 |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 8 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 9 | func s:cleanup_buffers() abort |
Bram Moolenaar | b3435b0 | 2016-09-29 20:54:59 +0200 | [diff] [blame] | 10 | for bnr in range(1, bufnr('$')) |
| 11 | if bufloaded(bnr) && bufnr('%') != bnr |
| 12 | execute 'bd! ' . bnr |
| 13 | endif |
| 14 | endfor |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 15 | endfunc |
Bram Moolenaar | b3435b0 | 2016-09-29 20:54:59 +0200 | [diff] [blame] | 16 | |
Bram Moolenaar | 1473551 | 2016-03-26 21:00:08 +0100 | [diff] [blame] | 17 | func Test_vim_did_enter() |
| 18 | call assert_false(v:vim_did_enter) |
| 19 | |
| 20 | " This script will never reach the main loop, can't check if v:vim_did_enter |
| 21 | " becomes one. |
| 22 | endfunc |
Bram Moolenaar | 40b1b54 | 2016-04-20 20:18:23 +0200 | [diff] [blame] | 23 | |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 24 | " Test for the CursorHold autocmd |
| 25 | func Test_CursorHold_autocmd() |
| 26 | CheckRunVimInTerminal |
| 27 | call writefile(['one', 'two', 'three'], 'Xfile') |
| 28 | let before =<< trim END |
| 29 | set updatetime=10 |
| 30 | au CursorHold * call writefile([line('.')], 'Xoutput', 'a') |
| 31 | END |
| 32 | call writefile(before, 'Xinit') |
| 33 | let buf = RunVimInTerminal('-S Xinit Xfile', {}) |
Bram Moolenaar | 17f6754 | 2020-08-20 18:29:13 +0200 | [diff] [blame] | 34 | call term_sendkeys(buf, "G") |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 35 | call term_wait(buf, 50) |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 36 | call term_sendkeys(buf, "gg") |
| 37 | call term_wait(buf) |
Bram Moolenaar | 17f6754 | 2020-08-20 18:29:13 +0200 | [diff] [blame] | 38 | call WaitForAssert({-> assert_equal(['1'], readfile('Xoutput')[-1:-1])}) |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 39 | call term_sendkeys(buf, "j") |
| 40 | call term_wait(buf) |
Bram Moolenaar | 17f6754 | 2020-08-20 18:29:13 +0200 | [diff] [blame] | 41 | call WaitForAssert({-> assert_equal(['1', '2'], readfile('Xoutput')[-2:-1])}) |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 42 | call term_sendkeys(buf, "j") |
| 43 | call term_wait(buf) |
Bram Moolenaar | 17f6754 | 2020-08-20 18:29:13 +0200 | [diff] [blame] | 44 | call WaitForAssert({-> assert_equal(['1', '2', '3'], readfile('Xoutput')[-3:-1])}) |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 45 | call StopVimInTerminal(buf) |
| 46 | |
Bram Moolenaar | 7591116 | 2020-07-21 19:44:47 +0200 | [diff] [blame] | 47 | call delete('Xinit') |
| 48 | call delete('Xoutput') |
| 49 | call delete('Xfile') |
| 50 | endfunc |
| 51 | |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 52 | if has('timers') |
Bram Moolenaar | 97b0075 | 2019-05-12 13:07:14 +0200 | [diff] [blame] | 53 | |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 54 | func ExitInsertMode(id) |
| 55 | call feedkeys("\<Esc>") |
| 56 | endfunc |
| 57 | |
| 58 | func Test_cursorhold_insert() |
Bram Moolenaar | f18c4db | 2016-09-08 22:10:06 +0200 | [diff] [blame] | 59 | " Need to move the cursor. |
| 60 | call feedkeys("ggG", "xt") |
| 61 | |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 62 | let g:triggered = 0 |
| 63 | au CursorHoldI * let g:triggered += 1 |
| 64 | set updatetime=20 |
Bram Moolenaar | 92bb83e | 2021-02-03 23:04:46 +0100 | [diff] [blame] | 65 | call timer_start(200, 'ExitInsertMode') |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 66 | call feedkeys('a', 'x!') |
| 67 | call assert_equal(1, g:triggered) |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 68 | unlet g:triggered |
| 69 | au! CursorHoldI |
| 70 | set updatetime& |
| 71 | endfunc |
| 72 | |
| 73 | func Test_cursorhold_insert_with_timer_interrupt() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 74 | CheckFeature job |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 75 | " Need to move the cursor. |
| 76 | call feedkeys("ggG", "xt") |
| 77 | |
| 78 | " Confirm the timer invoked in exit_cb of the job doesn't disturb |
| 79 | " CursorHoldI event. |
| 80 | let g:triggered = 0 |
| 81 | au CursorHoldI * let g:triggered += 1 |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 82 | set updatetime=100 |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 83 | call job_start(has('win32') ? 'cmd /c echo:' : 'echo', |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 84 | \ {'exit_cb': {-> timer_start(200, 'ExitInsertMode')}}) |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 85 | call feedkeys('a', 'x!') |
| 86 | call assert_equal(1, g:triggered) |
| 87 | unlet g:triggered |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 88 | au! CursorHoldI |
Bram Moolenaar | aeac900 | 2016-09-06 22:15:08 +0200 | [diff] [blame] | 89 | set updatetime& |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 90 | endfunc |
| 91 | |
| 92 | func Test_cursorhold_insert_ctrl_x() |
| 93 | let g:triggered = 0 |
| 94 | au CursorHoldI * let g:triggered += 1 |
| 95 | set updatetime=20 |
| 96 | call timer_start(100, 'ExitInsertMode') |
| 97 | " CursorHoldI does not trigger after CTRL-X |
| 98 | call feedkeys("a\<C-X>", 'x!') |
| 99 | call assert_equal(0, g:triggered) |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 100 | unlet g:triggered |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 101 | au! CursorHoldI |
Bram Moolenaar | aeac900 | 2016-09-06 22:15:08 +0200 | [diff] [blame] | 102 | set updatetime& |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 103 | endfunc |
Bram Moolenaar | 97b0075 | 2019-05-12 13:07:14 +0200 | [diff] [blame] | 104 | |
Bram Moolenaar | 5a9357d | 2021-10-03 16:22:05 +0100 | [diff] [blame] | 105 | func Test_cursorhold_insert_ctrl_g_U() |
| 106 | au CursorHoldI * : |
| 107 | set updatetime=20 |
| 108 | new |
| 109 | call timer_start(100, { -> feedkeys("\<Left>foo\<Esc>", 't') }) |
| 110 | call feedkeys("i()\<C-g>U", 'tx!') |
| 111 | sleep 200m |
| 112 | call assert_equal('(foo)', getline(1)) |
| 113 | undo |
| 114 | call assert_equal('', getline(1)) |
| 115 | |
| 116 | bwipe! |
| 117 | au! CursorHoldI |
| 118 | set updatetime& |
| 119 | endfunc |
| 120 | |
Bram Moolenaar | 97b0075 | 2019-05-12 13:07:14 +0200 | [diff] [blame] | 121 | func Test_OptionSet_modeline() |
| 122 | call test_override('starting', 1) |
| 123 | au! OptionSet |
| 124 | augroup set_tabstop |
| 125 | au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")}) |
| 126 | augroup END |
| 127 | call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline') |
| 128 | set modeline |
| 129 | let v:errmsg = '' |
| 130 | call assert_fails('split XoptionsetModeline', 'E12:') |
| 131 | call assert_equal(7, &ts) |
| 132 | call assert_equal('', v:errmsg) |
| 133 | |
| 134 | augroup set_tabstop |
| 135 | au! |
| 136 | augroup END |
| 137 | bwipe! |
| 138 | set ts& |
| 139 | call delete('XoptionsetModeline') |
| 140 | call test_override('starting', 0) |
| 141 | endfunc |
| 142 | |
| 143 | endif "has('timers') |
Bram Moolenaar | 40b1b54 | 2016-04-20 20:18:23 +0200 | [diff] [blame] | 144 | |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 145 | func Test_bufunload() |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 146 | augroup test_bufunload_group |
| 147 | autocmd! |
| 148 | autocmd BufUnload * call add(s:li, "bufunload") |
| 149 | autocmd BufDelete * call add(s:li, "bufdelete") |
| 150 | autocmd BufWipeout * call add(s:li, "bufwipeout") |
| 151 | augroup END |
Bram Moolenaar | 40b1b54 | 2016-04-20 20:18:23 +0200 | [diff] [blame] | 152 | |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 153 | let s:li = [] |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 154 | new |
| 155 | setlocal bufhidden= |
| 156 | bunload |
| 157 | call assert_equal(["bufunload", "bufdelete"], s:li) |
Bram Moolenaar | 40b1b54 | 2016-04-20 20:18:23 +0200 | [diff] [blame] | 158 | |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 159 | let s:li = [] |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 160 | new |
| 161 | setlocal bufhidden=delete |
| 162 | bunload |
| 163 | call assert_equal(["bufunload", "bufdelete"], s:li) |
| 164 | |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 165 | let s:li = [] |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 166 | new |
| 167 | setlocal bufhidden=unload |
| 168 | bwipeout |
| 169 | call assert_equal(["bufunload", "bufdelete", "bufwipeout"], s:li) |
| 170 | |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 171 | au! test_bufunload_group |
Bram Moolenaar | c67e892 | 2016-05-24 16:07:40 +0200 | [diff] [blame] | 172 | augroup! test_bufunload_group |
Bram Moolenaar | 40b1b54 | 2016-04-20 20:18:23 +0200 | [diff] [blame] | 173 | endfunc |
Bram Moolenaar | 30445cb | 2016-07-09 15:21:02 +0200 | [diff] [blame] | 174 | |
| 175 | " SEGV occurs in older versions. (At least 7.4.2005 or older) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 176 | func Test_autocmd_bufunload_with_tabnext() |
Bram Moolenaar | 30445cb | 2016-07-09 15:21:02 +0200 | [diff] [blame] | 177 | tabedit |
| 178 | tabfirst |
| 179 | |
| 180 | augroup test_autocmd_bufunload_with_tabnext_group |
| 181 | autocmd! |
| 182 | autocmd BufUnload <buffer> tabnext |
| 183 | augroup END |
| 184 | |
| 185 | quit |
| 186 | call assert_equal(2, tabpagenr('$')) |
| 187 | |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 188 | autocmd! test_autocmd_bufunload_with_tabnext_group |
Bram Moolenaar | 30445cb | 2016-07-09 15:21:02 +0200 | [diff] [blame] | 189 | augroup! test_autocmd_bufunload_with_tabnext_group |
| 190 | tablast |
| 191 | quit |
| 192 | endfunc |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 193 | |
Bram Moolenaar | 5ed58c7 | 2021-01-28 14:24:55 +0100 | [diff] [blame] | 194 | func Test_argdelete_in_next() |
| 195 | au BufNew,BufEnter,BufLeave,BufWinEnter * argdel |
| 196 | call assert_fails('next a b', 'E1156:') |
| 197 | au! BufNew,BufEnter,BufLeave,BufWinEnter * |
| 198 | endfunc |
| 199 | |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 200 | func Test_autocmd_bufwinleave_with_tabfirst() |
Bram Moolenaar | f9e687e | 2016-09-04 21:33:09 +0200 | [diff] [blame] | 201 | tabedit |
| 202 | augroup sample |
| 203 | autocmd! |
| 204 | autocmd BufWinLeave <buffer> tabfirst |
| 205 | augroup END |
| 206 | call setline(1, ['a', 'b', 'c']) |
| 207 | edit! a.txt |
Bram Moolenaar | f18c4db | 2016-09-08 22:10:06 +0200 | [diff] [blame] | 208 | tabclose |
Bram Moolenaar | f9e687e | 2016-09-04 21:33:09 +0200 | [diff] [blame] | 209 | endfunc |
| 210 | |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 211 | " SEGV occurs in older versions. (At least 7.4.2321 or older) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 212 | func Test_autocmd_bufunload_avoiding_SEGV_01() |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 213 | split aa.txt |
| 214 | let lastbuf = bufnr('$') |
| 215 | |
| 216 | augroup test_autocmd_bufunload |
| 217 | autocmd! |
| 218 | exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!' |
| 219 | augroup END |
| 220 | |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 221 | call assert_fails('edit bb.txt', 'E937:') |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 222 | |
| 223 | autocmd! test_autocmd_bufunload |
| 224 | augroup! test_autocmd_bufunload |
| 225 | bwipe! aa.txt |
| 226 | bwipe! bb.txt |
| 227 | endfunc |
| 228 | |
| 229 | " SEGV occurs in older versions. (At least 7.4.2321 or older) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 230 | func Test_autocmd_bufunload_avoiding_SEGV_02() |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 231 | setlocal buftype=nowrite |
| 232 | let lastbuf = bufnr('$') |
| 233 | |
| 234 | augroup test_autocmd_bufunload |
| 235 | autocmd! |
| 236 | exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!' |
| 237 | augroup END |
| 238 | |
| 239 | normal! i1 |
| 240 | call assert_fails('edit a.txt', 'E517:') |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 241 | |
| 242 | autocmd! test_autocmd_bufunload |
| 243 | augroup! test_autocmd_bufunload |
| 244 | bwipe! a.txt |
| 245 | endfunc |
| 246 | |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 247 | func Test_autocmd_dummy_wipeout() |
| 248 | " prepare files |
| 249 | call writefile([''], 'Xdummywipetest1.txt') |
| 250 | call writefile([''], 'Xdummywipetest2.txt') |
| 251 | augroup test_bufunload_group |
| 252 | autocmd! |
| 253 | autocmd BufUnload * call add(s:li, "bufunload") |
| 254 | autocmd BufDelete * call add(s:li, "bufdelete") |
| 255 | autocmd BufWipeout * call add(s:li, "bufwipeout") |
| 256 | augroup END |
| 257 | |
| 258 | let s:li = [] |
| 259 | split Xdummywipetest1.txt |
| 260 | silent! vimgrep /notmatched/ Xdummywipetest* |
| 261 | call assert_equal(["bufunload", "bufwipeout"], s:li) |
| 262 | |
| 263 | bwipeout |
| 264 | call delete('Xdummywipetest1.txt') |
| 265 | call delete('Xdummywipetest2.txt') |
| 266 | au! test_bufunload_group |
| 267 | augroup! test_bufunload_group |
| 268 | endfunc |
| 269 | |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 270 | func Test_win_tab_autocmd() |
| 271 | let g:record = [] |
| 272 | |
| 273 | augroup testing |
| 274 | au WinNew * call add(g:record, 'WinNew') |
naohiro ono | 23beefe | 2021-11-13 12:38:49 +0000 | [diff] [blame] | 275 | au WinClosed * call add(g:record, 'WinClosed') |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 276 | au WinEnter * call add(g:record, 'WinEnter') |
| 277 | au WinLeave * call add(g:record, 'WinLeave') |
| 278 | au TabNew * call add(g:record, 'TabNew') |
Bram Moolenaar | 12c11d5 | 2016-07-19 23:13:03 +0200 | [diff] [blame] | 279 | au TabClosed * call add(g:record, 'TabClosed') |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 280 | au TabEnter * call add(g:record, 'TabEnter') |
| 281 | au TabLeave * call add(g:record, 'TabLeave') |
| 282 | augroup END |
| 283 | |
| 284 | split |
| 285 | tabnew |
| 286 | close |
| 287 | close |
| 288 | |
| 289 | call assert_equal([ |
| 290 | \ 'WinLeave', 'WinNew', 'WinEnter', |
| 291 | \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', |
naohiro ono | 23beefe | 2021-11-13 12:38:49 +0000 | [diff] [blame] | 292 | \ 'WinLeave', 'TabLeave', 'WinClosed', 'TabClosed', 'WinEnter', 'TabEnter', |
| 293 | \ 'WinLeave', 'WinClosed', 'WinEnter' |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 294 | \ ], g:record) |
| 295 | |
Bram Moolenaar | 12c11d5 | 2016-07-19 23:13:03 +0200 | [diff] [blame] | 296 | let g:record = [] |
| 297 | tabnew somefile |
| 298 | tabnext |
| 299 | bwipe somefile |
| 300 | |
| 301 | call assert_equal([ |
| 302 | \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', |
| 303 | \ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', |
naohiro ono | 23beefe | 2021-11-13 12:38:49 +0000 | [diff] [blame] | 304 | \ 'WinClosed', 'TabClosed' |
Bram Moolenaar | 12c11d5 | 2016-07-19 23:13:03 +0200 | [diff] [blame] | 305 | \ ], g:record) |
| 306 | |
Bram Moolenaar | c917da4 | 2016-07-19 22:31:36 +0200 | [diff] [blame] | 307 | augroup testing |
| 308 | au! |
| 309 | augroup END |
| 310 | unlet g:record |
| 311 | endfunc |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 312 | |
LemonBoy | 0937182 | 2022-04-08 15:18:45 +0100 | [diff] [blame] | 313 | func Test_WinScrolled() |
| 314 | CheckRunVimInTerminal |
| 315 | |
| 316 | let lines =<< trim END |
zeertzjq | d58862d | 2022-04-12 11:32:48 +0100 | [diff] [blame] | 317 | set nowrap scrolloff=0 |
| 318 | for ii in range(1, 18) |
| 319 | call setline(ii, repeat(nr2char(96 + ii), ii * 2)) |
| 320 | endfor |
| 321 | let win_id = win_getid() |
| 322 | let g:matched = v:false |
| 323 | execute 'au WinScrolled' win_id 'let g:matched = v:true' |
| 324 | let g:scrolled = 0 |
| 325 | au WinScrolled * let g:scrolled += 1 |
| 326 | au WinScrolled * let g:amatch = str2nr(expand('<amatch>')) |
| 327 | au WinScrolled * let g:afile = str2nr(expand('<afile>')) |
LemonBoy | 0937182 | 2022-04-08 15:18:45 +0100 | [diff] [blame] | 328 | END |
| 329 | call writefile(lines, 'Xtest_winscrolled') |
| 330 | let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6}) |
| 331 | |
| 332 | call term_sendkeys(buf, ":echo g:scrolled\<CR>") |
| 333 | call WaitForAssert({-> assert_match('^0 ', term_getline(buf, 6))}, 1000) |
| 334 | |
| 335 | " Scroll left/right in Normal mode. |
| 336 | call term_sendkeys(buf, "zlzh:echo g:scrolled\<CR>") |
| 337 | call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000) |
| 338 | |
| 339 | " Scroll up/down in Normal mode. |
| 340 | call term_sendkeys(buf, "\<c-e>\<c-y>:echo g:scrolled\<CR>") |
| 341 | call WaitForAssert({-> assert_match('^4 ', term_getline(buf, 6))}, 1000) |
| 342 | |
| 343 | " Scroll up/down in Insert mode. |
| 344 | call term_sendkeys(buf, "Mi\<c-x>\<c-e>\<Esc>i\<c-x>\<c-y>\<Esc>") |
| 345 | call term_sendkeys(buf, ":echo g:scrolled\<CR>") |
| 346 | call WaitForAssert({-> assert_match('^6 ', term_getline(buf, 6))}, 1000) |
| 347 | |
| 348 | " Scroll the window horizontally to focus the last letter of the third line |
| 349 | " containing only six characters. Moving to the previous and shorter lines |
| 350 | " should trigger another autocommand as Vim has to make them visible. |
| 351 | call term_sendkeys(buf, "5zl2k") |
| 352 | call term_sendkeys(buf, ":echo g:scrolled\<CR>") |
| 353 | call WaitForAssert({-> assert_match('^8 ', term_getline(buf, 6))}, 1000) |
| 354 | |
| 355 | " Ensure the command was triggered for the specified window ID. |
| 356 | call term_sendkeys(buf, ":echo g:matched\<CR>") |
| 357 | call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) |
| 358 | |
| 359 | " Ensure the expansion of <amatch> and <afile> matches the window ID. |
| 360 | call term_sendkeys(buf, ":echo g:amatch == win_id && g:afile == win_id\<CR>") |
| 361 | call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) |
| 362 | |
| 363 | call StopVimInTerminal(buf) |
| 364 | call delete('Xtest_winscrolled') |
| 365 | endfunc |
| 366 | |
zeertzjq | d58862d | 2022-04-12 11:32:48 +0100 | [diff] [blame] | 367 | func Test_WinScrolled_close_curwin() |
| 368 | CheckRunVimInTerminal |
| 369 | |
| 370 | let lines =<< trim END |
| 371 | set nowrap scrolloff=0 |
| 372 | call setline(1, ['aaa', 'bbb']) |
| 373 | vsplit |
| 374 | au WinScrolled * close |
| 375 | au VimLeave * call writefile(['123456'], 'Xtestout') |
| 376 | END |
| 377 | call writefile(lines, 'Xtest_winscrolled_close_curwin') |
| 378 | let buf = RunVimInTerminal('-S Xtest_winscrolled_close_curwin', {'rows': 6}) |
| 379 | |
| 380 | " This was using freed memory |
| 381 | call term_sendkeys(buf, "\<C-E>") |
| 382 | call TermWait(buf) |
| 383 | call StopVimInTerminal(buf) |
| 384 | |
| 385 | call assert_equal(['123456'], readfile('Xtestout')) |
| 386 | |
| 387 | call delete('Xtest_winscrolled_close_curwin') |
| 388 | call delete('Xtestout') |
| 389 | endfunc |
| 390 | |
naohiro ono | 23beefe | 2021-11-13 12:38:49 +0000 | [diff] [blame] | 391 | func Test_WinClosed() |
| 392 | " Test that the pattern is matched against the closed window's ID, and both |
| 393 | " <amatch> and <afile> are set to it. |
| 394 | new |
| 395 | let winid = win_getid() |
| 396 | let g:matched = v:false |
| 397 | augroup test-WinClosed |
| 398 | autocmd! |
| 399 | execute 'autocmd WinClosed' winid 'let g:matched = v:true' |
| 400 | autocmd WinClosed * let g:amatch = str2nr(expand('<amatch>')) |
| 401 | autocmd WinClosed * let g:afile = str2nr(expand('<afile>')) |
| 402 | augroup END |
| 403 | close |
| 404 | call assert_true(g:matched) |
| 405 | call assert_equal(winid, g:amatch) |
| 406 | call assert_equal(winid, g:afile) |
| 407 | |
| 408 | " Test that WinClosed is non-recursive. |
| 409 | new |
| 410 | new |
| 411 | call assert_equal(3, winnr('$')) |
| 412 | let g:triggered = 0 |
| 413 | augroup test-WinClosed |
| 414 | autocmd! |
| 415 | autocmd WinClosed * let g:triggered += 1 |
| 416 | autocmd WinClosed * 2 wincmd c |
| 417 | augroup END |
| 418 | close |
| 419 | call assert_equal(1, winnr('$')) |
| 420 | call assert_equal(1, g:triggered) |
| 421 | |
| 422 | autocmd! test-WinClosed |
| 423 | augroup! test-WinClosed |
| 424 | unlet g:matched |
| 425 | unlet g:amatch |
| 426 | unlet g:afile |
| 427 | unlet g:triggered |
| 428 | endfunc |
| 429 | |
Bram Moolenaar | c947b9a | 2022-04-06 17:59:21 +0100 | [diff] [blame] | 430 | func Test_WinClosed_throws() |
| 431 | vnew |
| 432 | let bnr = bufnr() |
| 433 | call assert_equal(1, bufloaded(bnr)) |
| 434 | augroup test-WinClosed |
| 435 | autocmd WinClosed * throw 'foo' |
| 436 | augroup END |
| 437 | try |
| 438 | close |
| 439 | catch /.*/ |
| 440 | endtry |
| 441 | call assert_equal(0, bufloaded(bnr)) |
| 442 | |
| 443 | autocmd! test-WinClosed |
| 444 | augroup! test-WinClosed |
| 445 | endfunc |
| 446 | |
zeertzjq | 6a06940 | 2022-04-07 14:08:29 +0100 | [diff] [blame] | 447 | func Test_WinClosed_throws_with_tabs() |
| 448 | tabnew |
| 449 | let bnr = bufnr() |
| 450 | call assert_equal(1, bufloaded(bnr)) |
| 451 | augroup test-WinClosed |
| 452 | autocmd WinClosed * throw 'foo' |
| 453 | augroup END |
| 454 | try |
| 455 | close |
| 456 | catch /.*/ |
| 457 | endtry |
| 458 | call assert_equal(0, bufloaded(bnr)) |
| 459 | |
| 460 | autocmd! test-WinClosed |
| 461 | augroup! test-WinClosed |
| 462 | endfunc |
| 463 | |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 464 | func s:AddAnAutocmd() |
| 465 | augroup vimBarTest |
| 466 | au BufReadCmd * echo 'hello' |
| 467 | augroup END |
| 468 | call assert_equal(3, len(split(execute('au vimBarTest'), "\n"))) |
| 469 | endfunc |
| 470 | |
| 471 | func Test_early_bar() |
| 472 | " test that a bar is recognized before the {event} |
| 473 | call s:AddAnAutocmd() |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 474 | augroup vimBarTest | au! | let done = 77 | augroup END |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 475 | call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 476 | call assert_equal(77, done) |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 477 | |
| 478 | call s:AddAnAutocmd() |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 479 | augroup vimBarTest| au!| let done = 88 | augroup END |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 480 | call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 481 | call assert_equal(88, done) |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 482 | |
| 483 | " test that a bar is recognized after the {event} |
| 484 | call s:AddAnAutocmd() |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 485 | augroup vimBarTest| au!BufReadCmd| let done = 99 | augroup END |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 486 | call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) |
Bram Moolenaar | b8e642f | 2021-11-20 10:38:25 +0000 | [diff] [blame] | 487 | call assert_equal(99, done) |
Bram Moolenaar | e99e844 | 2016-07-26 20:43:40 +0200 | [diff] [blame] | 488 | |
| 489 | " test that a bar is recognized after the {group} |
| 490 | call s:AddAnAutocmd() |
| 491 | au! vimBarTest|echo 'hello' |
| 492 | call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) |
| 493 | endfunc |
Bram Moolenaar | f2c4c39 | 2016-07-29 20:50:24 +0200 | [diff] [blame] | 494 | |
Bram Moolenaar | 5c80908 | 2016-09-01 16:21:48 +0200 | [diff] [blame] | 495 | func RemoveGroup() |
| 496 | autocmd! StartOK |
| 497 | augroup! StartOK |
| 498 | endfunc |
| 499 | |
Bram Moolenaar | f2c4c39 | 2016-07-29 20:50:24 +0200 | [diff] [blame] | 500 | func Test_augroup_warning() |
| 501 | augroup TheWarning |
| 502 | au VimEnter * echo 'entering' |
| 503 | augroup END |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 504 | call assert_match("TheWarning.*VimEnter", execute('au VimEnter')) |
Bram Moolenaar | f2c4c39 | 2016-07-29 20:50:24 +0200 | [diff] [blame] | 505 | redir => res |
| 506 | augroup! TheWarning |
| 507 | redir END |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 508 | call assert_match("W19:", res) |
| 509 | call assert_match("-Deleted-.*VimEnter", execute('au VimEnter')) |
Bram Moolenaar | f2c4c39 | 2016-07-29 20:50:24 +0200 | [diff] [blame] | 510 | |
| 511 | " check "Another" does not take the pace of the deleted entry |
| 512 | augroup Another |
| 513 | augroup END |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 514 | call assert_match("-Deleted-.*VimEnter", execute('au VimEnter')) |
Bram Moolenaar | aeac900 | 2016-09-06 22:15:08 +0200 | [diff] [blame] | 515 | augroup! Another |
Bram Moolenaar | 5c80908 | 2016-09-01 16:21:48 +0200 | [diff] [blame] | 516 | |
| 517 | " no warning for postpone aucmd delete |
| 518 | augroup StartOK |
| 519 | au VimEnter * call RemoveGroup() |
| 520 | augroup END |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 521 | call assert_match("StartOK.*VimEnter", execute('au VimEnter')) |
Bram Moolenaar | 5c80908 | 2016-09-01 16:21:48 +0200 | [diff] [blame] | 522 | redir => res |
| 523 | doautocmd VimEnter |
| 524 | redir END |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 525 | call assert_notmatch("W19:", res) |
Bram Moolenaar | de653f0 | 2016-09-03 16:59:06 +0200 | [diff] [blame] | 526 | au! VimEnter |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 527 | |
| 528 | call assert_fails('augroup!', 'E471:') |
Bram Moolenaar | f2c4c39 | 2016-07-29 20:50:24 +0200 | [diff] [blame] | 529 | endfunc |
Bram Moolenaar | b62cc36 | 2016-09-03 16:43:53 +0200 | [diff] [blame] | 530 | |
Bram Moolenaar | 8d84ff1 | 2017-10-26 16:42:16 +0200 | [diff] [blame] | 531 | func Test_BufReadCmdHelp() |
| 532 | " This used to cause access to free memory |
| 533 | au BufReadCmd * e +h |
| 534 | help |
| 535 | |
Bram Moolenaar | 8d84ff1 | 2017-10-26 16:42:16 +0200 | [diff] [blame] | 536 | au! BufReadCmd |
| 537 | endfunc |
| 538 | |
| 539 | func Test_BufReadCmdHelpJump() |
| 540 | " This used to cause access to free memory |
| 541 | au BufReadCmd * e +h{ |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 542 | " } to fix highlighting |
| 543 | call assert_fails('help', 'E434:') |
Bram Moolenaar | 8d84ff1 | 2017-10-26 16:42:16 +0200 | [diff] [blame] | 544 | |
Bram Moolenaar | 8d84ff1 | 2017-10-26 16:42:16 +0200 | [diff] [blame] | 545 | au! BufReadCmd |
| 546 | endfunc |
| 547 | |
Bram Moolenaar | b62cc36 | 2016-09-03 16:43:53 +0200 | [diff] [blame] | 548 | func Test_augroup_deleted() |
Bram Moolenaar | de653f0 | 2016-09-03 16:59:06 +0200 | [diff] [blame] | 549 | " This caused a crash before E936 was introduced |
Bram Moolenaar | b62cc36 | 2016-09-03 16:43:53 +0200 | [diff] [blame] | 550 | augroup x |
Bram Moolenaar | de653f0 | 2016-09-03 16:59:06 +0200 | [diff] [blame] | 551 | call assert_fails('augroup! x', 'E936:') |
| 552 | au VimEnter * echo |
| 553 | augroup end |
Bram Moolenaar | b62cc36 | 2016-09-03 16:43:53 +0200 | [diff] [blame] | 554 | augroup! x |
Bram Moolenaar | 5dc4e2f | 2020-11-25 14:15:12 +0100 | [diff] [blame] | 555 | call assert_match("-Deleted-.*VimEnter", execute('au VimEnter')) |
Bram Moolenaar | de653f0 | 2016-09-03 16:59:06 +0200 | [diff] [blame] | 556 | au! VimEnter |
Bram Moolenaar | b62cc36 | 2016-09-03 16:43:53 +0200 | [diff] [blame] | 557 | endfunc |
| 558 | |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 559 | " Tests for autocommands on :close command. |
| 560 | " This used to be in test13. |
| 561 | func Test_three_windows() |
Bram Moolenaar | b3435b0 | 2016-09-29 20:54:59 +0200 | [diff] [blame] | 562 | " Clean up buffers, because in some cases this function fails. |
| 563 | call s:cleanup_buffers() |
| 564 | |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 565 | " Write three files and open them, each in a window. |
| 566 | " Then go to next window, with autocommand that deletes the previous one. |
| 567 | " Do this twice, writing the file. |
| 568 | e! Xtestje1 |
| 569 | call setline(1, 'testje1') |
| 570 | w |
| 571 | sp Xtestje2 |
| 572 | call setline(1, 'testje2') |
| 573 | w |
| 574 | sp Xtestje3 |
| 575 | call setline(1, 'testje3') |
| 576 | w |
| 577 | wincmd w |
| 578 | au WinLeave Xtestje2 bwipe |
| 579 | wincmd w |
| 580 | call assert_equal('Xtestje1', expand('%')) |
| 581 | |
| 582 | au WinLeave Xtestje1 bwipe Xtestje3 |
| 583 | close |
| 584 | call assert_equal('Xtestje1', expand('%')) |
| 585 | |
| 586 | " Test deleting the buffer on a Unload event. If this goes wrong there |
| 587 | " will be the ATTENTION prompt. |
| 588 | e Xtestje1 |
| 589 | au! |
| 590 | au! BufUnload Xtestje1 bwipe |
| 591 | call assert_fails('e Xtestje3', 'E937:') |
| 592 | call assert_equal('Xtestje3', expand('%')) |
| 593 | |
| 594 | e Xtestje2 |
| 595 | sp Xtestje1 |
| 596 | call assert_fails('e', 'E937:') |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 597 | call assert_equal('Xtestje1', expand('%')) |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 598 | |
| 599 | " Test changing buffers in a BufWipeout autocommand. If this goes wrong |
| 600 | " there are ml_line errors and/or a Crash. |
| 601 | au! |
| 602 | only |
| 603 | e Xanother |
| 604 | e Xtestje1 |
| 605 | bwipe Xtestje2 |
| 606 | bwipe Xtestje3 |
| 607 | au BufWipeout Xtestje1 buf Xtestje1 |
| 608 | bwipe |
| 609 | call assert_equal('Xanother', expand('%')) |
| 610 | |
| 611 | only |
| 612 | help |
| 613 | wincmd w |
| 614 | 1quit |
| 615 | call assert_equal('Xanother', expand('%')) |
| 616 | |
| 617 | au! |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 618 | enew |
Bram Moolenaar | e0ab94e | 2016-09-04 19:50:54 +0200 | [diff] [blame] | 619 | call delete('Xtestje1') |
| 620 | call delete('Xtestje2') |
| 621 | call delete('Xtestje3') |
| 622 | endfunc |
Bram Moolenaar | e13b9af | 2017-01-13 22:01:02 +0100 | [diff] [blame] | 623 | |
| 624 | func Test_BufEnter() |
| 625 | au! BufEnter |
| 626 | au Bufenter * let val = val . '+' |
| 627 | let g:val = '' |
| 628 | split NewFile |
| 629 | call assert_equal('+', g:val) |
| 630 | bwipe! |
| 631 | call assert_equal('++', g:val) |
| 632 | |
| 633 | " Also get BufEnter when editing a directory |
| 634 | call mkdir('Xdir') |
| 635 | split Xdir |
| 636 | call assert_equal('+++', g:val) |
Bram Moolenaar | e94260f | 2017-03-21 15:50:12 +0100 | [diff] [blame] | 637 | |
| 638 | " On MS-Windows we can't edit the directory, make sure we wipe the right |
| 639 | " buffer. |
| 640 | bwipe! Xdir |
Bram Moolenaar | e13b9af | 2017-01-13 22:01:02 +0100 | [diff] [blame] | 641 | |
| 642 | call delete('Xdir', 'd') |
| 643 | au! BufEnter |
| 644 | endfunc |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 645 | |
| 646 | " Closing a window might cause an endless loop |
| 647 | " E814 for older Vims |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 648 | func Test_autocmd_bufwipe_in_SessLoadPost() |
Bram Moolenaar | 1d68d9b | 2017-10-13 22:33:32 +0200 | [diff] [blame] | 649 | edit Xtest |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 650 | tabnew |
Bram Moolenaar | 1d68d9b | 2017-10-13 22:33:32 +0200 | [diff] [blame] | 651 | file Xsomething |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 652 | set noswapfile |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 653 | mksession! |
| 654 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 655 | let content =<< trim [CODE] |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 656 | call test_override('ui_delay', 10) |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 657 | set nocp noswapfile |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 658 | let v:swapchoice = "e" |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 659 | augroup test_autocmd_sessionload |
| 660 | autocmd! |
| 661 | autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!" |
| 662 | augroup END |
| 663 | |
| 664 | func WriteErrors() |
| 665 | call writefile([execute("messages")], "Xerrors") |
| 666 | endfunc |
| 667 | au VimLeave * call WriteErrors() |
| 668 | [CODE] |
| 669 | |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 670 | call writefile(content, 'Xvimrc') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 671 | call system(GetVimCommand('Xvimrc') .. ' --not-a-term --noplugins -S Session.vim -c cq') |
Bram Moolenaar | e94260f | 2017-03-21 15:50:12 +0100 | [diff] [blame] | 672 | let errors = join(readfile('Xerrors')) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 673 | call assert_match('E814:', errors) |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 674 | |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 675 | set swapfile |
Bram Moolenaar | e94260f | 2017-03-21 15:50:12 +0100 | [diff] [blame] | 676 | for file in ['Session.vim', 'Xvimrc', 'Xerrors'] |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 677 | call delete(file) |
| 678 | endfor |
| 679 | endfunc |
| 680 | |
Bram Moolenaar | 797e63b | 2021-01-15 16:22:52 +0100 | [diff] [blame] | 681 | " Using :blast and :ball for many events caused a crash, because b_nwindows was |
| 682 | " not incremented correctly. |
| 683 | func Test_autocmd_blast_badd() |
| 684 | let content =<< trim [CODE] |
| 685 | au BufNew,BufAdd,BufWinEnter,BufEnter,BufLeave,BufWinLeave,BufUnload,VimEnter foo* blast |
| 686 | edit foo1 |
| 687 | au BufNew,BufAdd,BufWinEnter,BufEnter,BufLeave,BufWinLeave,BufUnload,VimEnter foo* ball |
| 688 | edit foo2 |
| 689 | call writefile(['OK'], 'Xerrors') |
| 690 | qall |
| 691 | [CODE] |
| 692 | |
| 693 | call writefile(content, 'XblastBall') |
| 694 | call system(GetVimCommand() .. ' --clean -S XblastBall') |
| 695 | call assert_match('OK', readfile('Xerrors')->join()) |
| 696 | |
| 697 | call delete('XblastBall') |
| 698 | call delete('Xerrors') |
| 699 | endfunc |
| 700 | |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 701 | " SEGV occurs in older versions. |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 702 | func Test_autocmd_bufwipe_in_SessLoadPost2() |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 703 | tabnew |
| 704 | set noswapfile |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 705 | mksession! |
| 706 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 707 | let content =<< trim [CODE] |
| 708 | set nocp noswapfile |
| 709 | function! DeleteInactiveBufs() |
| 710 | tabfirst |
| 711 | let tabblist = [] |
| 712 | for i in range(1, tabpagenr(''$'')) |
| 713 | call extend(tabblist, tabpagebuflist(i)) |
| 714 | endfor |
| 715 | for b in range(1, bufnr(''$'')) |
| 716 | if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'') |
| 717 | exec ''bwipeout '' . b |
| 718 | endif |
| 719 | endfor |
| 720 | echomsg "SessionLoadPost DONE" |
| 721 | endfunction |
| 722 | au SessionLoadPost * call DeleteInactiveBufs() |
| 723 | |
| 724 | func WriteErrors() |
| 725 | call writefile([execute("messages")], "Xerrors") |
| 726 | endfunc |
| 727 | au VimLeave * call WriteErrors() |
| 728 | [CODE] |
| 729 | |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 730 | call writefile(content, 'Xvimrc') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 731 | call system(GetVimCommand('Xvimrc') .. ' --not-a-term --noplugins -S Session.vim -c cq') |
Bram Moolenaar | e94260f | 2017-03-21 15:50:12 +0100 | [diff] [blame] | 732 | let errors = join(readfile('Xerrors')) |
| 733 | " This probably only ever matches on unix. |
| 734 | call assert_notmatch('Caught deadly signal SEGV', errors) |
| 735 | call assert_match('SessionLoadPost DONE', errors) |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 736 | |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 737 | set swapfile |
Bram Moolenaar | e94260f | 2017-03-21 15:50:12 +0100 | [diff] [blame] | 738 | for file in ['Session.vim', 'Xvimrc', 'Xerrors'] |
Bram Moolenaar | 8c752bd | 2017-03-19 17:09:56 +0100 | [diff] [blame] | 739 | call delete(file) |
| 740 | endfor |
| 741 | endfunc |
Bram Moolenaar | faf29d7 | 2017-07-09 11:07:16 +0200 | [diff] [blame] | 742 | |
| 743 | func Test_empty_doau() |
| 744 | doau \| |
| 745 | endfunc |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 746 | |
| 747 | func s:AutoCommandOptionSet(match) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 748 | let template = "Option: <%s>, OldVal: <%s>, OldValLocal: <%s>, OldValGlobal: <%s>, NewVal: <%s>, Scope: <%s>, Command: <%s>\n" |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 749 | let item = remove(g:options, 0) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 750 | let expected = printf(template, item[0], item[1], item[2], item[3], item[4], item[5], item[6]) |
| 751 | let actual = printf(template, a:match, v:option_old, v:option_oldlocal, v:option_oldglobal, v:option_new, v:option_type, v:option_command) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 752 | let g:opt = [expected, actual] |
| 753 | "call assert_equal(expected, actual) |
| 754 | endfunc |
| 755 | |
| 756 | func Test_OptionSet() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 757 | CheckOption autochdir |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 758 | |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 759 | badd test_autocmd.vim |
| 760 | |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 761 | call test_override('starting', 1) |
| 762 | set nocp |
| 763 | au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>")) |
| 764 | |
| 765 | " 1: Setting number option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 766 | let g:options = [['number', 0, 0, 0, 1, 'global', 'set']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 767 | set nu |
| 768 | call assert_equal([], g:options) |
| 769 | call assert_equal(g:opt[0], g:opt[1]) |
| 770 | |
| 771 | " 2: Setting local number option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 772 | let g:options = [['number', 1, 1, '', 0, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 773 | setlocal nonu |
| 774 | call assert_equal([], g:options) |
| 775 | call assert_equal(g:opt[0], g:opt[1]) |
| 776 | |
| 777 | " 3: Setting global number option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 778 | let g:options = [['number', 1, '', 1, 0, 'global', 'setglobal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 779 | setglobal nonu |
| 780 | call assert_equal([], g:options) |
| 781 | call assert_equal(g:opt[0], g:opt[1]) |
| 782 | |
| 783 | " 4: Setting local autoindent option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 784 | let g:options = [['autoindent', 0, 0, '', 1, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 785 | setlocal ai |
| 786 | call assert_equal([], g:options) |
| 787 | call assert_equal(g:opt[0], g:opt[1]) |
| 788 | |
| 789 | " 5: Setting global autoindent option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 790 | let g:options = [['autoindent', 0, '', 0, 1, 'global', 'setglobal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 791 | setglobal ai |
| 792 | call assert_equal([], g:options) |
| 793 | call assert_equal(g:opt[0], g:opt[1]) |
| 794 | |
| 795 | " 6: Setting global autoindent option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 796 | let g:options = [['autoindent', 1, 1, 1, 0, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 797 | set ai! |
| 798 | call assert_equal([], g:options) |
| 799 | call assert_equal(g:opt[0], g:opt[1]) |
| 800 | |
| 801 | " 6a: Setting global autoindent option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 802 | let g:options = [['autoindent', 1, 1, 0, 0, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 803 | noa setlocal ai |
| 804 | noa setglobal noai |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 805 | set ai! |
| 806 | call assert_equal([], g:options) |
| 807 | call assert_equal(g:opt[0], g:opt[1]) |
| 808 | |
| 809 | " Should not print anything, use :noa |
| 810 | " 7: don't trigger OptionSet" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 811 | let g:options = [['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 812 | noa set nonu |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 813 | call assert_equal([['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']], g:options) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 814 | call assert_equal(g:opt[0], g:opt[1]) |
| 815 | |
| 816 | " 8: Setting several global list and number option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 817 | let g:options = [['list', 0, 0, 0, 1, 'global', 'set'], ['number', 0, 0, 0, 1, 'global', 'set']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 818 | set list nu |
| 819 | call assert_equal([], g:options) |
| 820 | call assert_equal(g:opt[0], g:opt[1]) |
| 821 | |
| 822 | " 9: don't trigger OptionSet" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 823 | let g:options = [['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid'], ['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 824 | noa set nolist nonu |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 825 | call assert_equal([['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid'], ['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']], g:options) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 826 | call assert_equal(g:opt[0], g:opt[1]) |
| 827 | |
| 828 | " 10: Setting global acd" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 829 | let g:options = [['autochdir', 0, 0, '', 1, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 830 | setlocal acd |
| 831 | call assert_equal([], g:options) |
| 832 | call assert_equal(g:opt[0], g:opt[1]) |
| 833 | |
| 834 | " 11: Setting global autoread (also sets local value)" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 835 | let g:options = [['autoread', 0, 0, 0, 1, 'global', 'set']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 836 | set ar |
| 837 | call assert_equal([], g:options) |
| 838 | call assert_equal(g:opt[0], g:opt[1]) |
| 839 | |
| 840 | " 12: Setting local autoread" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 841 | let g:options = [['autoread', 1, 1, '', 1, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 842 | setlocal ar |
| 843 | call assert_equal([], g:options) |
| 844 | call assert_equal(g:opt[0], g:opt[1]) |
| 845 | |
| 846 | " 13: Setting global autoread" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 847 | let g:options = [['autoread', 1, '', 1, 0, 'global', 'setglobal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 848 | setglobal invar |
| 849 | call assert_equal([], g:options) |
| 850 | call assert_equal(g:opt[0], g:opt[1]) |
| 851 | |
| 852 | " 14: Setting option backspace through :let" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 853 | let g:options = [['backspace', '', '', '', 'eol,indent,start', 'global', 'set']] |
| 854 | let &bs = "eol,indent,start" |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 855 | call assert_equal([], g:options) |
| 856 | call assert_equal(g:opt[0], g:opt[1]) |
| 857 | |
| 858 | " 15: Setting option backspace through setbufvar()" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 859 | let g:options = [['backup', 0, 0, '', 1, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 860 | " try twice, first time, shouldn't trigger because option name is invalid, |
| 861 | " second time, it should trigger |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 862 | let bnum = bufnr('%') |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 863 | call assert_fails("call setbufvar(bnum, '&l:bk', 1)", 'E355:') |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 864 | " should trigger, use correct option name |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 865 | call setbufvar(bnum, '&backup', 1) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 866 | call assert_equal([], g:options) |
| 867 | call assert_equal(g:opt[0], g:opt[1]) |
| 868 | |
| 869 | " 16: Setting number option using setwinvar" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 870 | let g:options = [['number', 0, 0, '', 1, 'local', 'setlocal']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 871 | call setwinvar(0, '&number', 1) |
| 872 | call assert_equal([], g:options) |
| 873 | call assert_equal(g:opt[0], g:opt[1]) |
| 874 | |
| 875 | " 17: Setting key option, shouldn't trigger" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 876 | let g:options = [['key', 'invalid', 'invalid1', 'invalid2', 'invalid3', 'invalid4', 'invalid5']] |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 877 | setlocal key=blah |
| 878 | setlocal key= |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 879 | call assert_equal([['key', 'invalid', 'invalid1', 'invalid2', 'invalid3', 'invalid4', 'invalid5']], g:options) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 880 | call assert_equal(g:opt[0], g:opt[1]) |
| 881 | |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 882 | |
| 883 | " 18a: Setting string global option" |
| 884 | let oldval = &backupext |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 885 | let g:options = [['backupext', oldval, oldval, oldval, 'foo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 886 | set backupext=foo |
| 887 | call assert_equal([], g:options) |
| 888 | call assert_equal(g:opt[0], g:opt[1]) |
| 889 | |
| 890 | " 18b: Resetting string global option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 891 | let g:options = [['backupext', 'foo', 'foo', 'foo', oldval, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 892 | set backupext& |
| 893 | call assert_equal([], g:options) |
| 894 | call assert_equal(g:opt[0], g:opt[1]) |
| 895 | |
| 896 | " 18c: Setting global string global option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 897 | let g:options = [['backupext', oldval, '', oldval, 'bar', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 898 | setglobal backupext=bar |
| 899 | call assert_equal([], g:options) |
| 900 | call assert_equal(g:opt[0], g:opt[1]) |
| 901 | |
| 902 | " 18d: Setting local string global option" |
| 903 | " As this is a global option this sets the global value even though |
| 904 | " :setlocal is used! |
| 905 | noa set backupext& " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 906 | let g:options = [['backupext', oldval, oldval, '', 'baz', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 907 | setlocal backupext=baz |
| 908 | call assert_equal([], g:options) |
| 909 | call assert_equal(g:opt[0], g:opt[1]) |
| 910 | |
| 911 | " 18e: Setting again string global option" |
| 912 | noa setglobal backupext=ext_global " Reset global and local value (without triggering autocmd) |
| 913 | noa setlocal backupext=ext_local " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 914 | let g:options = [['backupext', 'ext_local', 'ext_local', 'ext_local', 'fuu', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 915 | set backupext=fuu |
| 916 | call assert_equal([], g:options) |
| 917 | call assert_equal(g:opt[0], g:opt[1]) |
| 918 | |
| 919 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 920 | " 19a: Setting string global-local (to buffer) option" |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 921 | let oldval = &tags |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 922 | let g:options = [['tags', oldval, oldval, oldval, 'tagpath', 'global', 'set']] |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 923 | set tags=tagpath |
| 924 | call assert_equal([], g:options) |
| 925 | call assert_equal(g:opt[0], g:opt[1]) |
| 926 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 927 | " 19b: Resetting string global-local (to buffer) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 928 | let g:options = [['tags', 'tagpath', 'tagpath', 'tagpath', oldval, 'global', 'set']] |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 929 | set tags& |
| 930 | call assert_equal([], g:options) |
| 931 | call assert_equal(g:opt[0], g:opt[1]) |
| 932 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 933 | " 19c: Setting global string global-local (to buffer) option " |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 934 | let g:options = [['tags', oldval, '', oldval, 'tagpath1', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 935 | setglobal tags=tagpath1 |
| 936 | call assert_equal([], g:options) |
| 937 | call assert_equal(g:opt[0], g:opt[1]) |
| 938 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 939 | " 19d: Setting local string global-local (to buffer) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 940 | let g:options = [['tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 941 | setlocal tags=tagpath2 |
| 942 | call assert_equal([], g:options) |
| 943 | call assert_equal(g:opt[0], g:opt[1]) |
| 944 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 945 | " 19e: Setting again string global-local (to buffer) option" |
| 946 | " Note: v:option_old is the old global value for global-local string options |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 947 | " but the old local value for all other kinds of options. |
| 948 | noa setglobal tags=tag_global " Reset global and local value (without triggering autocmd) |
| 949 | noa setlocal tags=tag_local |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 950 | let g:options = [['tags', 'tag_global', 'tag_local', 'tag_global', 'tagpath', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 951 | set tags=tagpath |
| 952 | call assert_equal([], g:options) |
| 953 | call assert_equal(g:opt[0], g:opt[1]) |
| 954 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 955 | " 19f: Setting string global-local (to buffer) option to an empty string" |
| 956 | " Note: v:option_old is the old global value for global-local string options |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 957 | " but the old local value for all other kinds of options. |
| 958 | noa set tags=tag_global " Reset global and local value (without triggering autocmd) |
| 959 | noa setlocal tags= " empty string |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 960 | let g:options = [['tags', 'tag_global', '', 'tag_global', 'tagpath', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 961 | set tags=tagpath |
| 962 | call assert_equal([], g:options) |
| 963 | call assert_equal(g:opt[0], g:opt[1]) |
| 964 | |
| 965 | |
| 966 | " 20a: Setting string local (to buffer) option" |
| 967 | let oldval = &spelllang |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 968 | let g:options = [['spelllang', oldval, oldval, oldval, 'elvish,klingon', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 969 | set spelllang=elvish,klingon |
| 970 | call assert_equal([], g:options) |
| 971 | call assert_equal(g:opt[0], g:opt[1]) |
| 972 | |
| 973 | " 20b: Resetting string local (to buffer) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 974 | let g:options = [['spelllang', 'elvish,klingon', 'elvish,klingon', 'elvish,klingon', oldval, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 975 | set spelllang& |
| 976 | call assert_equal([], g:options) |
| 977 | call assert_equal(g:opt[0], g:opt[1]) |
| 978 | |
| 979 | " 20c: Setting global string local (to buffer) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 980 | let g:options = [['spelllang', oldval, '', oldval, 'elvish', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 981 | setglobal spelllang=elvish |
| 982 | call assert_equal([], g:options) |
| 983 | call assert_equal(g:opt[0], g:opt[1]) |
| 984 | |
| 985 | " 20d: Setting local string local (to buffer) option" |
| 986 | noa set spelllang& " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 987 | let g:options = [['spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 988 | setlocal spelllang=klingon |
| 989 | call assert_equal([], g:options) |
| 990 | call assert_equal(g:opt[0], g:opt[1]) |
| 991 | |
| 992 | " 20e: Setting again string local (to buffer) option" |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 993 | " Note: v:option_old is the old global value for global-local string options |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 994 | " but the old local value for all other kinds of options. |
| 995 | noa setglobal spelllang=spellglobal " Reset global and local value (without triggering autocmd) |
| 996 | noa setlocal spelllang=spelllocal |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 997 | let g:options = [['spelllang', 'spelllocal', 'spelllocal', 'spellglobal', 'foo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 998 | set spelllang=foo |
| 999 | call assert_equal([], g:options) |
| 1000 | call assert_equal(g:opt[0], g:opt[1]) |
| 1001 | |
| 1002 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1003 | " 21a: Setting string global-local (to window) option" |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1004 | let oldval = &statusline |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1005 | let g:options = [['statusline', oldval, oldval, oldval, 'foo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1006 | set statusline=foo |
| 1007 | call assert_equal([], g:options) |
| 1008 | call assert_equal(g:opt[0], g:opt[1]) |
| 1009 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1010 | " 21b: Resetting string global-local (to window) option" |
| 1011 | " Note: v:option_old is the old global value for global-local string options |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1012 | " but the old local value for all other kinds of options. |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1013 | let g:options = [['statusline', 'foo', 'foo', 'foo', oldval, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1014 | set statusline& |
| 1015 | call assert_equal([], g:options) |
| 1016 | call assert_equal(g:opt[0], g:opt[1]) |
| 1017 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1018 | " 21c: Setting global string global-local (to window) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1019 | let g:options = [['statusline', oldval, '', oldval, 'bar', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1020 | setglobal statusline=bar |
| 1021 | call assert_equal([], g:options) |
| 1022 | call assert_equal(g:opt[0], g:opt[1]) |
| 1023 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1024 | " 21d: Setting local string global-local (to window) option" |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1025 | noa set statusline& " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1026 | let g:options = [['statusline', oldval, oldval, '', 'baz', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1027 | setlocal statusline=baz |
| 1028 | call assert_equal([], g:options) |
| 1029 | call assert_equal(g:opt[0], g:opt[1]) |
| 1030 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1031 | " 21e: Setting again string global-local (to window) option" |
| 1032 | " Note: v:option_old is the old global value for global-local string options |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1033 | " but the old local value for all other kinds of options. |
| 1034 | noa setglobal statusline=bar " Reset global and local value (without triggering autocmd) |
| 1035 | noa setlocal statusline=baz |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1036 | let g:options = [['statusline', 'bar', 'baz', 'bar', 'foo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1037 | set statusline=foo |
| 1038 | call assert_equal([], g:options) |
| 1039 | call assert_equal(g:opt[0], g:opt[1]) |
| 1040 | |
| 1041 | |
| 1042 | " 22a: Setting string local (to window) option" |
| 1043 | let oldval = &foldignore |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1044 | let g:options = [['foldignore', oldval, oldval, oldval, 'fo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1045 | set foldignore=fo |
| 1046 | call assert_equal([], g:options) |
| 1047 | call assert_equal(g:opt[0], g:opt[1]) |
| 1048 | |
| 1049 | " 22b: Resetting string local (to window) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1050 | let g:options = [['foldignore', 'fo', 'fo', 'fo', oldval, 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1051 | set foldignore& |
| 1052 | call assert_equal([], g:options) |
| 1053 | call assert_equal(g:opt[0], g:opt[1]) |
| 1054 | |
| 1055 | " 22c: Setting global string local (to window) option" |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1056 | let g:options = [['foldignore', oldval, '', oldval, 'bar', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1057 | setglobal foldignore=bar |
| 1058 | call assert_equal([], g:options) |
| 1059 | call assert_equal(g:opt[0], g:opt[1]) |
| 1060 | |
| 1061 | " 22d: Setting local string local (to window) option" |
| 1062 | noa set foldignore& " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1063 | let g:options = [['foldignore', oldval, oldval, '', 'baz', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1064 | setlocal foldignore=baz |
| 1065 | call assert_equal([], g:options) |
| 1066 | call assert_equal(g:opt[0], g:opt[1]) |
| 1067 | |
| 1068 | " 22e: Setting again string local (to window) option" |
| 1069 | noa setglobal foldignore=glob " Reset global and local value (without triggering autocmd) |
| 1070 | noa setlocal foldignore=loc |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1071 | let g:options = [['foldignore', 'loc', 'loc', 'glob', 'fo', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1072 | set foldignore=fo |
| 1073 | call assert_equal([], g:options) |
| 1074 | call assert_equal(g:opt[0], g:opt[1]) |
| 1075 | |
| 1076 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1077 | " 23a: Setting global number global option" |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1078 | noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd) |
| 1079 | noa setlocal cmdheight=1 " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1080 | let g:options = [['cmdheight', '1', '', '1', '2', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1081 | setglobal cmdheight=2 |
| 1082 | call assert_equal([], g:options) |
| 1083 | call assert_equal(g:opt[0], g:opt[1]) |
| 1084 | |
| 1085 | " 23b: Setting local number global option" |
| 1086 | noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd) |
| 1087 | noa setlocal cmdheight=1 " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1088 | let g:options = [['cmdheight', '1', '1', '', '2', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1089 | setlocal cmdheight=2 |
| 1090 | call assert_equal([], g:options) |
| 1091 | call assert_equal(g:opt[0], g:opt[1]) |
| 1092 | |
| 1093 | " 23c: Setting again number global option" |
| 1094 | noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd) |
| 1095 | noa setlocal cmdheight=1 " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1096 | let g:options = [['cmdheight', '1', '1', '1', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1097 | set cmdheight=2 |
| 1098 | call assert_equal([], g:options) |
| 1099 | call assert_equal(g:opt[0], g:opt[1]) |
| 1100 | |
| 1101 | " 23d: Setting again number global option" |
| 1102 | noa set cmdheight=8 " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1103 | let g:options = [['cmdheight', '8', '8', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1104 | set cmdheight=2 |
| 1105 | call assert_equal([], g:options) |
| 1106 | call assert_equal(g:opt[0], g:opt[1]) |
| 1107 | |
| 1108 | |
| 1109 | " 24a: Setting global number global-local (to buffer) option" |
| 1110 | noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd) |
| 1111 | noa setlocal undolevels=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1112 | let g:options = [['undolevels', '8', '', '8', '2', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1113 | setglobal undolevels=2 |
| 1114 | call assert_equal([], g:options) |
| 1115 | call assert_equal(g:opt[0], g:opt[1]) |
| 1116 | |
| 1117 | " 24b: Setting local number global-local (to buffer) option" |
| 1118 | noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd) |
| 1119 | noa setlocal undolevels=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1120 | let g:options = [['undolevels', '1', '1', '', '2', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1121 | setlocal undolevels=2 |
| 1122 | call assert_equal([], g:options) |
| 1123 | call assert_equal(g:opt[0], g:opt[1]) |
| 1124 | |
| 1125 | " 24c: Setting again number global-local (to buffer) option" |
| 1126 | noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd) |
| 1127 | noa setlocal undolevels=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1128 | let g:options = [['undolevels', '1', '1', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1129 | set undolevels=2 |
| 1130 | call assert_equal([], g:options) |
| 1131 | call assert_equal(g:opt[0], g:opt[1]) |
| 1132 | |
| 1133 | " 24d: Setting again global number global-local (to buffer) option" |
| 1134 | noa set undolevels=8 " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1135 | let g:options = [['undolevels', '8', '8', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1136 | set undolevels=2 |
| 1137 | call assert_equal([], g:options) |
| 1138 | call assert_equal(g:opt[0], g:opt[1]) |
| 1139 | |
| 1140 | |
| 1141 | " 25a: Setting global number local (to buffer) option" |
| 1142 | noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd) |
| 1143 | noa setlocal wrapmargin=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1144 | let g:options = [['wrapmargin', '8', '', '8', '2', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1145 | setglobal wrapmargin=2 |
| 1146 | call assert_equal([], g:options) |
| 1147 | call assert_equal(g:opt[0], g:opt[1]) |
| 1148 | |
| 1149 | " 25b: Setting local number local (to buffer) option" |
| 1150 | noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd) |
| 1151 | noa setlocal wrapmargin=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1152 | let g:options = [['wrapmargin', '1', '1', '', '2', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1153 | setlocal wrapmargin=2 |
| 1154 | call assert_equal([], g:options) |
| 1155 | call assert_equal(g:opt[0], g:opt[1]) |
| 1156 | |
| 1157 | " 25c: Setting again number local (to buffer) option" |
| 1158 | noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd) |
| 1159 | noa setlocal wrapmargin=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1160 | let g:options = [['wrapmargin', '1', '1', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1161 | set wrapmargin=2 |
| 1162 | call assert_equal([], g:options) |
| 1163 | call assert_equal(g:opt[0], g:opt[1]) |
| 1164 | |
| 1165 | " 25d: Setting again global number local (to buffer) option" |
| 1166 | noa set wrapmargin=8 " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1167 | let g:options = [['wrapmargin', '8', '8', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1168 | set wrapmargin=2 |
| 1169 | call assert_equal([], g:options) |
| 1170 | call assert_equal(g:opt[0], g:opt[1]) |
| 1171 | |
| 1172 | |
| 1173 | " 26: Setting number global-local (to window) option. |
| 1174 | " Such option does currently not exist. |
| 1175 | |
| 1176 | |
| 1177 | " 27a: Setting global number local (to window) option" |
| 1178 | noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd) |
| 1179 | noa setlocal foldcolumn=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1180 | let g:options = [['foldcolumn', '8', '', '8', '2', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1181 | setglobal foldcolumn=2 |
| 1182 | call assert_equal([], g:options) |
| 1183 | call assert_equal(g:opt[0], g:opt[1]) |
| 1184 | |
| 1185 | " 27b: Setting local number local (to window) option" |
| 1186 | noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd) |
| 1187 | noa setlocal foldcolumn=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1188 | let g:options = [['foldcolumn', '1', '1', '', '2', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1189 | setlocal foldcolumn=2 |
| 1190 | call assert_equal([], g:options) |
| 1191 | call assert_equal(g:opt[0], g:opt[1]) |
| 1192 | |
| 1193 | " 27c: Setting again number local (to window) option" |
| 1194 | noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd) |
| 1195 | noa setlocal foldcolumn=1 |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1196 | let g:options = [['foldcolumn', '1', '1', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1197 | set foldcolumn=2 |
| 1198 | call assert_equal([], g:options) |
| 1199 | call assert_equal(g:opt[0], g:opt[1]) |
| 1200 | |
zeertzjq | b811de5 | 2021-10-21 10:50:44 +0100 | [diff] [blame] | 1201 | " 27d: Setting again global number local (to window) option" |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1202 | noa set foldcolumn=8 " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1203 | let g:options = [['foldcolumn', '8', '8', '8', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1204 | set foldcolumn=2 |
| 1205 | call assert_equal([], g:options) |
| 1206 | call assert_equal(g:opt[0], g:opt[1]) |
| 1207 | |
| 1208 | |
| 1209 | " 28a: Setting global boolean global option" |
| 1210 | noa setglobal nowrapscan " Reset global and local value (without triggering autocmd) |
| 1211 | noa setlocal wrapscan " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1212 | let g:options = [['wrapscan', '1', '', '1', '0', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1213 | setglobal nowrapscan |
| 1214 | call assert_equal([], g:options) |
| 1215 | call assert_equal(g:opt[0], g:opt[1]) |
| 1216 | |
| 1217 | " 28b: Setting local boolean global option" |
| 1218 | noa setglobal nowrapscan " Reset global and local value (without triggering autocmd) |
| 1219 | noa setlocal wrapscan " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1220 | let g:options = [['wrapscan', '1', '1', '', '0', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1221 | setlocal nowrapscan |
| 1222 | call assert_equal([], g:options) |
| 1223 | call assert_equal(g:opt[0], g:opt[1]) |
| 1224 | |
| 1225 | " 28c: Setting again boolean global option" |
| 1226 | noa setglobal nowrapscan " Reset global and local value (without triggering autocmd) |
| 1227 | noa setlocal wrapscan " Sets the global(!) value! |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1228 | let g:options = [['wrapscan', '1', '1', '1', '0', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1229 | set nowrapscan |
| 1230 | call assert_equal([], g:options) |
| 1231 | call assert_equal(g:opt[0], g:opt[1]) |
| 1232 | |
| 1233 | " 28d: Setting again global boolean global option" |
| 1234 | noa set nowrapscan " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1235 | let g:options = [['wrapscan', '0', '0', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1236 | set wrapscan |
| 1237 | call assert_equal([], g:options) |
| 1238 | call assert_equal(g:opt[0], g:opt[1]) |
| 1239 | |
| 1240 | |
| 1241 | " 29a: Setting global boolean global-local (to buffer) option" |
| 1242 | noa setglobal noautoread " Reset global and local value (without triggering autocmd) |
| 1243 | noa setlocal autoread |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1244 | let g:options = [['autoread', '0', '', '0', '1', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1245 | setglobal autoread |
| 1246 | call assert_equal([], g:options) |
| 1247 | call assert_equal(g:opt[0], g:opt[1]) |
| 1248 | |
| 1249 | " 29b: Setting local boolean global-local (to buffer) option" |
| 1250 | noa setglobal noautoread " Reset global and local value (without triggering autocmd) |
| 1251 | noa setlocal autoread |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1252 | let g:options = [['autoread', '1', '1', '', '0', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1253 | setlocal noautoread |
| 1254 | call assert_equal([], g:options) |
| 1255 | call assert_equal(g:opt[0], g:opt[1]) |
| 1256 | |
| 1257 | " 29c: Setting again boolean global-local (to buffer) option" |
| 1258 | noa setglobal noautoread " Reset global and local value (without triggering autocmd) |
| 1259 | noa setlocal autoread |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1260 | let g:options = [['autoread', '1', '1', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1261 | set autoread |
| 1262 | call assert_equal([], g:options) |
| 1263 | call assert_equal(g:opt[0], g:opt[1]) |
| 1264 | |
| 1265 | " 29d: Setting again global boolean global-local (to buffer) option" |
| 1266 | noa set noautoread " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1267 | let g:options = [['autoread', '0', '0', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1268 | set autoread |
| 1269 | call assert_equal([], g:options) |
| 1270 | call assert_equal(g:opt[0], g:opt[1]) |
| 1271 | |
| 1272 | |
| 1273 | " 30a: Setting global boolean local (to buffer) option" |
| 1274 | noa setglobal nocindent " Reset global and local value (without triggering autocmd) |
| 1275 | noa setlocal cindent |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1276 | let g:options = [['cindent', '0', '', '0', '1', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1277 | setglobal cindent |
| 1278 | call assert_equal([], g:options) |
| 1279 | call assert_equal(g:opt[0], g:opt[1]) |
| 1280 | |
| 1281 | " 30b: Setting local boolean local (to buffer) option" |
| 1282 | noa setglobal nocindent " Reset global and local value (without triggering autocmd) |
| 1283 | noa setlocal cindent |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1284 | let g:options = [['cindent', '1', '1', '', '0', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1285 | setlocal nocindent |
| 1286 | call assert_equal([], g:options) |
| 1287 | call assert_equal(g:opt[0], g:opt[1]) |
| 1288 | |
| 1289 | " 30c: Setting again boolean local (to buffer) option" |
| 1290 | noa setglobal nocindent " Reset global and local value (without triggering autocmd) |
| 1291 | noa setlocal cindent |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1292 | let g:options = [['cindent', '1', '1', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1293 | set cindent |
| 1294 | call assert_equal([], g:options) |
| 1295 | call assert_equal(g:opt[0], g:opt[1]) |
| 1296 | |
| 1297 | " 30d: Setting again global boolean local (to buffer) option" |
| 1298 | noa set nocindent " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1299 | let g:options = [['cindent', '0', '0', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1300 | set cindent |
| 1301 | call assert_equal([], g:options) |
| 1302 | call assert_equal(g:opt[0], g:opt[1]) |
| 1303 | |
| 1304 | |
| 1305 | " 31: Setting boolean global-local (to window) option |
| 1306 | " Currently no such option exists. |
| 1307 | |
| 1308 | |
| 1309 | " 32a: Setting global boolean local (to window) option" |
| 1310 | noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd) |
| 1311 | noa setlocal cursorcolumn |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1312 | let g:options = [['cursorcolumn', '0', '', '0', '1', 'global', 'setglobal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1313 | setglobal cursorcolumn |
| 1314 | call assert_equal([], g:options) |
| 1315 | call assert_equal(g:opt[0], g:opt[1]) |
| 1316 | |
| 1317 | " 32b: Setting local boolean local (to window) option" |
| 1318 | noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd) |
| 1319 | noa setlocal cursorcolumn |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1320 | let g:options = [['cursorcolumn', '1', '1', '', '0', 'local', 'setlocal']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1321 | setlocal nocursorcolumn |
| 1322 | call assert_equal([], g:options) |
| 1323 | call assert_equal(g:opt[0], g:opt[1]) |
| 1324 | |
| 1325 | " 32c: Setting again boolean local (to window) option" |
| 1326 | noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd) |
| 1327 | noa setlocal cursorcolumn |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1328 | let g:options = [['cursorcolumn', '1', '1', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1329 | set cursorcolumn |
| 1330 | call assert_equal([], g:options) |
| 1331 | call assert_equal(g:opt[0], g:opt[1]) |
| 1332 | |
| 1333 | " 32d: Setting again global boolean local (to window) option" |
| 1334 | noa set nocursorcolumn " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1335 | let g:options = [['cursorcolumn', '0', '0', '0', '1', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1336 | set cursorcolumn |
| 1337 | call assert_equal([], g:options) |
| 1338 | call assert_equal(g:opt[0], g:opt[1]) |
| 1339 | |
| 1340 | |
Bram Moolenaar | 1bc353b | 2019-09-01 14:45:28 +0200 | [diff] [blame] | 1341 | " 33: Test autocommands when an option value is converted internally. |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1342 | noa set backspace=1 " Reset global and local value (without triggering autocmd) |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1343 | let g:options = [['backspace', 'indent,eol', 'indent,eol', 'indent,eol', '2', 'global', 'set']] |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1344 | set backspace=2 |
| 1345 | call assert_equal([], g:options) |
| 1346 | call assert_equal(g:opt[0], g:opt[1]) |
| 1347 | |
| 1348 | |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1349 | " Cleanup |
| 1350 | au! OptionSet |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 1351 | " set tags& |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1352 | for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp', 'backupext', 'tags', 'spelllang', 'statusline', 'foldignore', 'cmdheight', 'undolevels', 'wrapmargin', 'foldcolumn', 'wrapscan', 'autoread', 'cindent', 'cursorcolumn'] |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 1353 | exe printf(":set %s&vim", opt) |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1354 | endfor |
| 1355 | call test_override('starting', 0) |
| 1356 | delfunc! AutoCommandOptionSet |
| 1357 | endfunc |
| 1358 | |
| 1359 | func Test_OptionSet_diffmode() |
| 1360 | call test_override('starting', 1) |
Bram Moolenaar | 26d9821 | 2019-01-27 22:32:55 +0100 | [diff] [blame] | 1361 | " 18: Changing an option when entering diff mode |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1362 | new |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 1363 | au OptionSet diff :let &l:cul = v:option_new |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1364 | |
| 1365 | call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) |
| 1366 | call assert_equal(0, &l:cul) |
| 1367 | diffthis |
| 1368 | call assert_equal(1, &l:cul) |
| 1369 | |
| 1370 | vnew |
| 1371 | call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) |
| 1372 | call assert_equal(0, &l:cul) |
| 1373 | diffthis |
| 1374 | call assert_equal(1, &l:cul) |
| 1375 | |
| 1376 | diffoff |
| 1377 | call assert_equal(0, &l:cul) |
| 1378 | call assert_equal(1, getwinvar(2, '&l:cul')) |
| 1379 | bw! |
| 1380 | |
| 1381 | call assert_equal(1, &l:cul) |
| 1382 | diffoff! |
| 1383 | call assert_equal(0, &l:cul) |
| 1384 | call assert_equal(0, getwinvar(1, '&l:cul')) |
| 1385 | bw! |
| 1386 | |
| 1387 | " Cleanup |
| 1388 | au! OptionSet |
| 1389 | call test_override('starting', 0) |
| 1390 | endfunc |
| 1391 | |
| 1392 | func Test_OptionSet_diffmode_close() |
| 1393 | call test_override('starting', 1) |
| 1394 | " 19: Try to close the current window when entering diff mode |
| 1395 | " should not segfault |
| 1396 | new |
| 1397 | au OptionSet diff close |
| 1398 | |
| 1399 | call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1400 | call assert_fails(':diffthis', 'E788:') |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1401 | call assert_equal(1, &diff) |
| 1402 | vnew |
| 1403 | call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1404 | call assert_fails(':diffthis', 'E788:') |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1405 | call assert_equal(1, &diff) |
Bram Moolenaar | a9aa86f | 2019-11-10 21:25:45 +0100 | [diff] [blame] | 1406 | set diffopt-=closeoff |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1407 | bw! |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1408 | call assert_fails(':diffoff!', 'E788:') |
Bram Moolenaar | 04f62f8 | 2017-07-19 18:18:39 +0200 | [diff] [blame] | 1409 | bw! |
| 1410 | |
| 1411 | " Cleanup |
| 1412 | au! OptionSet |
| 1413 | call test_override('starting', 0) |
| 1414 | "delfunc! AutoCommandOptionSet |
| 1415 | endfunc |
Bram Moolenaar | 4a137b4 | 2017-08-04 22:37:11 +0200 | [diff] [blame] | 1416 | |
| 1417 | " Test for Bufleave autocommand that deletes the buffer we are about to edit. |
| 1418 | func Test_BufleaveWithDelete() |
| 1419 | new | edit Xfile1 |
| 1420 | |
| 1421 | augroup test_bufleavewithdelete |
| 1422 | autocmd! |
| 1423 | autocmd BufLeave Xfile1 bwipe Xfile2 |
| 1424 | augroup END |
| 1425 | |
| 1426 | call assert_fails('edit Xfile2', 'E143:') |
| 1427 | call assert_equal('Xfile1', bufname('%')) |
| 1428 | |
| 1429 | autocmd! test_bufleavewithdelete BufLeave Xfile1 |
| 1430 | augroup! test_bufleavewithdelete |
| 1431 | |
| 1432 | new |
| 1433 | bwipe! Xfile1 |
| 1434 | endfunc |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 1435 | |
| 1436 | " Test for autocommand that changes the buffer list, when doing ":ball". |
| 1437 | func Test_Acmd_BufAll() |
| 1438 | enew! |
| 1439 | %bwipe! |
| 1440 | call writefile(['Test file Xxx1'], 'Xxx1') |
| 1441 | call writefile(['Test file Xxx2'], 'Xxx2') |
| 1442 | call writefile(['Test file Xxx3'], 'Xxx3') |
| 1443 | |
| 1444 | " Add three files to the buffer list |
| 1445 | split Xxx1 |
| 1446 | close |
| 1447 | split Xxx2 |
| 1448 | close |
| 1449 | split Xxx3 |
| 1450 | close |
| 1451 | |
| 1452 | " Wipe the buffer when the buffer is opened |
| 1453 | au BufReadPost Xxx2 bwipe |
| 1454 | |
| 1455 | call append(0, 'Test file Xxx4') |
| 1456 | ball |
| 1457 | |
| 1458 | call assert_equal(2, winnr('$')) |
| 1459 | call assert_equal('Xxx1', bufname(winbufnr(winnr('$')))) |
| 1460 | wincmd t |
| 1461 | |
| 1462 | au! BufReadPost |
| 1463 | %bwipe! |
| 1464 | call delete('Xxx1') |
| 1465 | call delete('Xxx2') |
| 1466 | call delete('Xxx3') |
| 1467 | enew! | only |
| 1468 | endfunc |
| 1469 | |
| 1470 | " Test for autocommand that changes current buffer on BufEnter event. |
| 1471 | " Check if modelines are interpreted for the correct buffer. |
| 1472 | func Test_Acmd_BufEnter() |
| 1473 | %bwipe! |
| 1474 | call writefile(['start of test file Xxx1', |
| 1475 | \ "\<Tab>this is a test", |
| 1476 | \ 'end of test file Xxx1'], 'Xxx1') |
| 1477 | call writefile(['start of test file Xxx2', |
| 1478 | \ 'vim: set noai :', |
| 1479 | \ "\<Tab>this is a test", |
| 1480 | \ 'end of test file Xxx2'], 'Xxx2') |
| 1481 | |
| 1482 | au BufEnter Xxx2 brew |
| 1483 | set ai modeline modelines=3 |
| 1484 | edit Xxx1 |
| 1485 | " edit Xxx2, autocmd will do :brew |
| 1486 | edit Xxx2 |
| 1487 | exe "normal G?this is a\<CR>" |
| 1488 | " Append text with autoindent to this file |
| 1489 | normal othis should be auto-indented |
| 1490 | call assert_equal("\<Tab>this should be auto-indented", getline('.')) |
| 1491 | call assert_equal(3, line('.')) |
| 1492 | " Remove autocmd and edit Xxx2 again |
| 1493 | au! BufEnter Xxx2 |
| 1494 | buf! Xxx2 |
| 1495 | exe "normal G?this is a\<CR>" |
| 1496 | " append text without autoindent to Xxx |
| 1497 | normal othis should be in column 1 |
| 1498 | call assert_equal("this should be in column 1", getline('.')) |
| 1499 | call assert_equal(4, line('.')) |
| 1500 | |
| 1501 | %bwipe! |
| 1502 | call delete('Xxx1') |
| 1503 | call delete('Xxx2') |
| 1504 | set ai&vim modeline&vim modelines&vim |
| 1505 | endfunc |
| 1506 | |
| 1507 | " Test for issue #57 |
| 1508 | " do not move cursor on <c-o> when autoindent is set |
| 1509 | func Test_ai_CTRL_O() |
| 1510 | enew! |
| 1511 | set ai |
| 1512 | let save_fo = &fo |
| 1513 | set fo+=r |
| 1514 | exe "normal o# abcdef\<Esc>2hi\<CR>\<C-O>d0\<Esc>" |
| 1515 | exe "normal o# abcdef\<Esc>2hi\<C-O>d0\<Esc>" |
| 1516 | call assert_equal(['# abc', 'def', 'def'], getline(2, 4)) |
| 1517 | |
| 1518 | set ai&vim |
| 1519 | let &fo = save_fo |
| 1520 | enew! |
| 1521 | endfunc |
| 1522 | |
| 1523 | " Test for autocommand that deletes the current buffer on BufLeave event. |
| 1524 | " Also test deleting the last buffer, should give a new, empty buffer. |
| 1525 | func Test_BufLeave_Wipe() |
| 1526 | %bwipe! |
| 1527 | let content = ['start of test file Xxx', |
| 1528 | \ 'this is a test', |
| 1529 | \ 'end of test file Xxx'] |
| 1530 | call writefile(content, 'Xxx1') |
| 1531 | call writefile(content, 'Xxx2') |
| 1532 | |
| 1533 | au BufLeave Xxx2 bwipe |
| 1534 | edit Xxx1 |
| 1535 | split Xxx2 |
| 1536 | " delete buffer Xxx2, we should be back to Xxx1 |
| 1537 | bwipe |
| 1538 | call assert_equal('Xxx1', bufname('%')) |
| 1539 | call assert_equal(1, winnr('$')) |
| 1540 | |
| 1541 | " Create an alternate buffer |
| 1542 | %write! test.out |
| 1543 | call assert_equal('test.out', bufname('#')) |
| 1544 | " delete alternate buffer |
| 1545 | bwipe test.out |
| 1546 | call assert_equal('Xxx1', bufname('%')) |
| 1547 | call assert_equal('', bufname('#')) |
| 1548 | |
| 1549 | au BufLeave Xxx1 bwipe |
| 1550 | " delete current buffer, get an empty one |
| 1551 | bwipe! |
| 1552 | call assert_equal(1, line('$')) |
| 1553 | call assert_equal('', bufname('%')) |
Bram Moolenaar | b2c8750 | 2017-10-14 21:15:58 +0200 | [diff] [blame] | 1554 | let g:bufinfo = getbufinfo() |
| 1555 | call assert_equal(1, len(g:bufinfo)) |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 1556 | |
| 1557 | call delete('Xxx1') |
| 1558 | call delete('Xxx2') |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1559 | call delete('test.out') |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 1560 | %bwipe |
| 1561 | au! BufLeave |
Bram Moolenaar | b2c8750 | 2017-10-14 21:15:58 +0200 | [diff] [blame] | 1562 | |
| 1563 | " check that bufinfo doesn't contain a pointer to freed memory |
| 1564 | call test_garbagecollect_now() |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 1565 | endfunc |
Bram Moolenaar | 87ffb5c | 2017-10-19 12:37:42 +0200 | [diff] [blame] | 1566 | |
| 1567 | func Test_QuitPre() |
| 1568 | edit Xfoo |
| 1569 | let winid = win_getid(winnr()) |
| 1570 | split Xbar |
| 1571 | au! QuitPre * let g:afile = expand('<afile>') |
| 1572 | " Close the other window, <afile> should be correct. |
| 1573 | exe win_id2win(winid) . 'q' |
| 1574 | call assert_equal('Xfoo', g:afile) |
| 1575 | |
| 1576 | unlet g:afile |
| 1577 | bwipe Xfoo |
| 1578 | bwipe Xbar |
| 1579 | endfunc |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1580 | |
| 1581 | func Test_Cmdline() |
Bram Moolenaar | 153b704 | 2018-01-31 15:48:32 +0100 | [diff] [blame] | 1582 | au! CmdlineChanged : let g:text = getcmdline() |
| 1583 | let g:text = 0 |
| 1584 | call feedkeys(":echom 'hello'\<CR>", 'xt') |
| 1585 | call assert_equal("echom 'hello'", g:text) |
| 1586 | au! CmdlineChanged |
| 1587 | |
| 1588 | au! CmdlineChanged : let g:entered = expand('<afile>') |
| 1589 | let g:entered = 0 |
| 1590 | call feedkeys(":echom 'hello'\<CR>", 'xt') |
| 1591 | call assert_equal(':', g:entered) |
| 1592 | au! CmdlineChanged |
| 1593 | |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1594 | au! CmdlineEnter : let g:entered = expand('<afile>') |
| 1595 | au! CmdlineLeave : let g:left = expand('<afile>') |
| 1596 | let g:entered = 0 |
| 1597 | let g:left = 0 |
| 1598 | call feedkeys(":echo 'hello'\<CR>", 'xt') |
| 1599 | call assert_equal(':', g:entered) |
| 1600 | call assert_equal(':', g:left) |
| 1601 | au! CmdlineEnter |
| 1602 | au! CmdlineLeave |
| 1603 | |
Bram Moolenaar | a4baf5b | 2018-04-22 13:27:44 +0200 | [diff] [blame] | 1604 | let save_shellslash = &shellslash |
| 1605 | set noshellslash |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1606 | au! CmdlineEnter / let g:entered = expand('<afile>') |
| 1607 | au! CmdlineLeave / let g:left = expand('<afile>') |
| 1608 | let g:entered = 0 |
| 1609 | let g:left = 0 |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1610 | new |
| 1611 | call setline(1, 'hello') |
| 1612 | call feedkeys("/hello\<CR>", 'xt') |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1613 | call assert_equal('/', g:entered) |
| 1614 | call assert_equal('/', g:left) |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1615 | bwipe! |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1616 | au! CmdlineEnter |
| 1617 | au! CmdlineLeave |
Bram Moolenaar | a4baf5b | 2018-04-22 13:27:44 +0200 | [diff] [blame] | 1618 | let &shellslash = save_shellslash |
Bram Moolenaar | fafcf0d | 2017-10-19 18:35:51 +0200 | [diff] [blame] | 1619 | endfunc |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1620 | |
| 1621 | " Test for BufWritePre autocommand that deletes or unloads the buffer. |
| 1622 | func Test_BufWritePre() |
| 1623 | %bwipe |
| 1624 | au BufWritePre Xxx1 bunload |
| 1625 | au BufWritePre Xxx2 bwipe |
| 1626 | |
| 1627 | call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1') |
| 1628 | call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2') |
| 1629 | |
| 1630 | edit Xtest |
| 1631 | e! Xxx2 |
| 1632 | bdel Xtest |
| 1633 | e Xxx1 |
| 1634 | " write it, will unload it and give an error msg |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1635 | call assert_fails('w', 'E203:') |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1636 | call assert_equal('Xxx2', bufname('%')) |
| 1637 | edit Xtest |
| 1638 | e! Xxx2 |
| 1639 | bwipe Xtest |
| 1640 | " write it, will delete the buffer and give an error msg |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1641 | call assert_fails('w', 'E203:') |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1642 | call assert_equal('Xxx1', bufname('%')) |
| 1643 | au! BufWritePre |
| 1644 | call delete('Xxx1') |
| 1645 | call delete('Xxx2') |
| 1646 | endfunc |
| 1647 | |
| 1648 | " Test for BufUnload autocommand that unloads all the other buffers |
| 1649 | func Test_bufunload_all() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 1650 | let g:test_is_flaky = 1 |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1651 | call writefile(['Test file Xxx1'], 'Xxx1')" |
| 1652 | call writefile(['Test file Xxx2'], 'Xxx2')" |
| 1653 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1654 | let content =<< trim [CODE] |
| 1655 | func UnloadAllBufs() |
| 1656 | let i = 1 |
| 1657 | while i <= bufnr('$') |
| 1658 | if i != bufnr('%') && bufloaded(i) |
| 1659 | exe i . 'bunload' |
| 1660 | endif |
| 1661 | let i += 1 |
| 1662 | endwhile |
| 1663 | endfunc |
| 1664 | au BufUnload * call UnloadAllBufs() |
| 1665 | au VimLeave * call writefile(['Test Finished'], 'Xout') |
| 1666 | edit Xxx1 |
| 1667 | split Xxx2 |
| 1668 | q |
| 1669 | [CODE] |
| 1670 | |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1671 | call writefile(content, 'Xtest') |
| 1672 | |
| 1673 | call delete('Xout') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 1674 | call system(GetVimCommandClean() .. ' -N --not-a-term -S Xtest') |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 1675 | call assert_true(filereadable('Xout')) |
| 1676 | |
| 1677 | call delete('Xxx1') |
| 1678 | call delete('Xxx2') |
| 1679 | call delete('Xtest') |
| 1680 | call delete('Xout') |
| 1681 | endfunc |
| 1682 | |
| 1683 | " Some tests for buffer-local autocommands |
| 1684 | func Test_buflocal_autocmd() |
| 1685 | let g:bname = '' |
| 1686 | edit xx |
| 1687 | au BufLeave <buffer> let g:bname = expand("%") |
| 1688 | " here, autocommand for xx should trigger. |
| 1689 | " but autocommand shall not apply to buffer named <buffer>. |
| 1690 | edit somefile |
| 1691 | call assert_equal('xx', g:bname) |
| 1692 | let g:bname = '' |
| 1693 | " here, autocommand shall be auto-deleted |
| 1694 | bwipe xx |
| 1695 | " autocmd should not trigger |
| 1696 | edit xx |
| 1697 | call assert_equal('', g:bname) |
| 1698 | " autocmd should not trigger |
| 1699 | edit somefile |
| 1700 | call assert_equal('', g:bname) |
| 1701 | enew |
| 1702 | unlet g:bname |
| 1703 | endfunc |
Bram Moolenaar | 430dc5d | 2017-11-02 21:04:47 +0100 | [diff] [blame] | 1704 | |
| 1705 | " Test for "*Cmd" autocommands |
| 1706 | func Test_Cmd_Autocmds() |
| 1707 | call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx') |
| 1708 | |
| 1709 | enew! |
| 1710 | au BufReadCmd XtestA 0r Xxx|$del |
| 1711 | edit XtestA " will read text of Xxd instead |
| 1712 | call assert_equal('start of Xxx', getline(1)) |
| 1713 | |
| 1714 | au BufWriteCmd XtestA call append(line("$"), "write") |
| 1715 | write " will append a line to the file |
| 1716 | call assert_equal('write', getline('$')) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1717 | call assert_fails('read XtestA', 'E484:') " should not read anything |
Bram Moolenaar | 430dc5d | 2017-11-02 21:04:47 +0100 | [diff] [blame] | 1718 | call assert_equal('write', getline(4)) |
| 1719 | |
| 1720 | " now we have: |
| 1721 | " 1 start of Xxx |
| 1722 | " 2 abc2 |
| 1723 | " 3 end of Xxx |
| 1724 | " 4 write |
| 1725 | |
| 1726 | au FileReadCmd XtestB '[r Xxx |
| 1727 | 2r XtestB " will read Xxx below line 2 instead |
| 1728 | call assert_equal('start of Xxx', getline(3)) |
| 1729 | |
| 1730 | " now we have: |
| 1731 | " 1 start of Xxx |
| 1732 | " 2 abc2 |
| 1733 | " 3 start of Xxx |
| 1734 | " 4 abc2 |
| 1735 | " 5 end of Xxx |
| 1736 | " 6 end of Xxx |
| 1737 | " 7 write |
| 1738 | |
| 1739 | au FileWriteCmd XtestC '[,']copy $ |
| 1740 | normal 4GA1 |
| 1741 | 4,5w XtestC " will copy lines 4 and 5 to the end |
| 1742 | call assert_equal("\tabc21", getline(8)) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1743 | call assert_fails('r XtestC', 'E484:') " should not read anything |
Bram Moolenaar | 430dc5d | 2017-11-02 21:04:47 +0100 | [diff] [blame] | 1744 | call assert_equal("end of Xxx", getline(9)) |
| 1745 | |
| 1746 | " now we have: |
| 1747 | " 1 start of Xxx |
| 1748 | " 2 abc2 |
| 1749 | " 3 start of Xxx |
| 1750 | " 4 abc21 |
| 1751 | " 5 end of Xxx |
| 1752 | " 6 end of Xxx |
| 1753 | " 7 write |
| 1754 | " 8 abc21 |
| 1755 | " 9 end of Xxx |
| 1756 | |
| 1757 | let g:lines = [] |
| 1758 | au FileAppendCmd XtestD call extend(g:lines, getline(line("'["), line("']"))) |
| 1759 | w >>XtestD " will add lines to 'lines' |
| 1760 | call assert_equal(9, len(g:lines)) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1761 | call assert_fails('$r XtestD', 'E484:') " should not read anything |
Bram Moolenaar | 430dc5d | 2017-11-02 21:04:47 +0100 | [diff] [blame] | 1762 | call assert_equal(9, line('$')) |
| 1763 | call assert_equal('end of Xxx', getline('$')) |
| 1764 | |
| 1765 | au BufReadCmd XtestE 0r Xxx|$del |
| 1766 | sp XtestE " split window with test.out |
| 1767 | call assert_equal('end of Xxx', getline(3)) |
| 1768 | |
| 1769 | let g:lines = [] |
| 1770 | exe "normal 2Goasdf\<Esc>\<C-W>\<C-W>" |
| 1771 | au BufWriteCmd XtestE call extend(g:lines, getline(0, '$')) |
| 1772 | wall " will write other window to 'lines' |
| 1773 | call assert_equal(4, len(g:lines), g:lines) |
| 1774 | call assert_equal('asdf', g:lines[2]) |
| 1775 | |
| 1776 | au! BufReadCmd |
| 1777 | au! BufWriteCmd |
| 1778 | au! FileReadCmd |
| 1779 | au! FileWriteCmd |
| 1780 | au! FileAppendCmd |
| 1781 | %bwipe! |
| 1782 | call delete('Xxx') |
| 1783 | enew! |
| 1784 | endfunc |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1785 | |
Bram Moolenaar | 0fff441 | 2020-03-29 16:06:29 +0200 | [diff] [blame] | 1786 | func s:ReadFile() |
| 1787 | setl noswapfile nomodified |
| 1788 | let filename = resolve(expand("<afile>:p")) |
| 1789 | execute 'read' fnameescape(filename) |
| 1790 | 1d_ |
| 1791 | exe 'file' fnameescape(filename) |
| 1792 | setl buftype=acwrite |
| 1793 | endfunc |
| 1794 | |
| 1795 | func s:WriteFile() |
| 1796 | let filename = resolve(expand("<afile>:p")) |
| 1797 | setl buftype= |
| 1798 | noautocmd execute 'write' fnameescape(filename) |
| 1799 | setl buftype=acwrite |
| 1800 | setl nomodified |
| 1801 | endfunc |
| 1802 | |
| 1803 | func Test_BufReadCmd() |
| 1804 | autocmd BufReadCmd *.test call s:ReadFile() |
| 1805 | autocmd BufWriteCmd *.test call s:WriteFile() |
| 1806 | |
| 1807 | call writefile(['one', 'two', 'three'], 'Xcmd.test') |
| 1808 | edit Xcmd.test |
| 1809 | call assert_match('Xcmd.test" line 1 of 3', execute('file')) |
| 1810 | normal! Gofour |
| 1811 | write |
| 1812 | call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test')) |
| 1813 | |
| 1814 | bwipe! |
| 1815 | call delete('Xcmd.test') |
| 1816 | au! BufReadCmd |
| 1817 | au! BufWriteCmd |
| 1818 | endfunc |
| 1819 | |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1820 | func SetChangeMarks(start, end) |
Bram Moolenaar | 97c6943 | 2021-01-15 16:45:21 +0100 | [diff] [blame] | 1821 | exe a:start .. 'mark [' |
| 1822 | exe a:end .. 'mark ]' |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1823 | endfunc |
| 1824 | |
| 1825 | " Verify the effects of autocmds on '[ and '] |
| 1826 | func Test_change_mark_in_autocmds() |
| 1827 | edit! Xtest |
Bram Moolenaar | 97c6943 | 2021-01-15 16:45:21 +0100 | [diff] [blame] | 1828 | call feedkeys("ia\<CR>b\<CR>c\<CR>d\<C-g>u\<Esc>", 'xtn') |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1829 | |
| 1830 | call SetChangeMarks(2, 3) |
| 1831 | write |
| 1832 | call assert_equal([1, 4], [line("'["), line("']")]) |
| 1833 | |
| 1834 | call SetChangeMarks(2, 3) |
| 1835 | au BufWritePre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 1836 | write |
| 1837 | au! BufWritePre |
| 1838 | |
Bram Moolenaar | 14ddd22 | 2020-08-05 12:02:40 +0200 | [diff] [blame] | 1839 | if has('unix') |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1840 | write XtestFilter |
| 1841 | write >> XtestFilter |
| 1842 | |
| 1843 | call SetChangeMarks(2, 3) |
| 1844 | " Marks are set to the entire range of the write |
| 1845 | au FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 1846 | " '[ is adjusted to just before the line that will receive the filtered |
| 1847 | " data |
| 1848 | au FilterReadPre * call assert_equal([4, 4], [line("'["), line("']")]) |
| 1849 | " The filtered data is read into the buffer, and the source lines are |
| 1850 | " still present, so the range is after the source lines |
| 1851 | au FilterReadPost * call assert_equal([5, 12], [line("'["), line("']")]) |
| 1852 | %!cat XtestFilter |
| 1853 | " After the filtered data is read, the original lines are deleted |
| 1854 | call assert_equal([1, 8], [line("'["), line("']")]) |
| 1855 | au! FilterWritePre,FilterReadPre,FilterReadPost |
| 1856 | undo |
| 1857 | |
| 1858 | call SetChangeMarks(1, 4) |
| 1859 | au FilterWritePre * call assert_equal([2, 3], [line("'["), line("']")]) |
| 1860 | au FilterReadPre * call assert_equal([3, 3], [line("'["), line("']")]) |
| 1861 | au FilterReadPost * call assert_equal([4, 11], [line("'["), line("']")]) |
| 1862 | 2,3!cat XtestFilter |
| 1863 | call assert_equal([2, 9], [line("'["), line("']")]) |
| 1864 | au! FilterWritePre,FilterReadPre,FilterReadPost |
| 1865 | undo |
| 1866 | |
| 1867 | call delete('XtestFilter') |
| 1868 | endif |
| 1869 | |
| 1870 | call SetChangeMarks(1, 4) |
| 1871 | au FileWritePre * call assert_equal([2, 3], [line("'["), line("']")]) |
| 1872 | 2,3write Xtest2 |
| 1873 | au! FileWritePre |
| 1874 | |
| 1875 | call SetChangeMarks(2, 3) |
| 1876 | au FileAppendPre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 1877 | write >> Xtest2 |
| 1878 | au! FileAppendPre |
| 1879 | |
| 1880 | call SetChangeMarks(1, 4) |
| 1881 | au FileAppendPre * call assert_equal([2, 3], [line("'["), line("']")]) |
| 1882 | 2,3write >> Xtest2 |
| 1883 | au! FileAppendPre |
| 1884 | |
| 1885 | call SetChangeMarks(1, 1) |
| 1886 | au FileReadPre * call assert_equal([3, 1], [line("'["), line("']")]) |
| 1887 | au FileReadPost * call assert_equal([4, 11], [line("'["), line("']")]) |
| 1888 | 3read Xtest2 |
| 1889 | au! FileReadPre,FileReadPost |
| 1890 | undo |
| 1891 | |
| 1892 | call SetChangeMarks(4, 4) |
| 1893 | " When the line is 0, it's adjusted to 1 |
| 1894 | au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 1895 | au FileReadPost * call assert_equal([1, 8], [line("'["), line("']")]) |
| 1896 | 0read Xtest2 |
| 1897 | au! FileReadPre,FileReadPost |
| 1898 | undo |
| 1899 | |
| 1900 | call SetChangeMarks(4, 4) |
| 1901 | " When the line is 0, it's adjusted to 1 |
| 1902 | au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 1903 | au FileReadPost * call assert_equal([2, 9], [line("'["), line("']")]) |
| 1904 | 1read Xtest2 |
| 1905 | au! FileReadPre,FileReadPost |
| 1906 | undo |
| 1907 | |
| 1908 | bwipe! |
| 1909 | call delete('Xtest') |
| 1910 | call delete('Xtest2') |
| 1911 | endfunc |
| 1912 | |
| 1913 | func Test_Filter_noshelltemp() |
Bram Moolenaar | aeb313f | 2020-11-27 19:13:28 +0100 | [diff] [blame] | 1914 | CheckExecutable cat |
Bram Moolenaar | aace215 | 2017-11-05 16:23:10 +0100 | [diff] [blame] | 1915 | |
| 1916 | enew! |
| 1917 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1918 | |
| 1919 | let shelltemp = &shelltemp |
| 1920 | set shelltemp |
| 1921 | |
| 1922 | let g:filter_au = 0 |
| 1923 | au FilterWritePre * let g:filter_au += 1 |
| 1924 | au FilterReadPre * let g:filter_au += 1 |
| 1925 | au FilterReadPost * let g:filter_au += 1 |
| 1926 | %!cat |
| 1927 | call assert_equal(3, g:filter_au) |
| 1928 | |
| 1929 | if has('filterpipe') |
| 1930 | set noshelltemp |
| 1931 | |
| 1932 | let g:filter_au = 0 |
| 1933 | au FilterWritePre * let g:filter_au += 1 |
| 1934 | au FilterReadPre * let g:filter_au += 1 |
| 1935 | au FilterReadPost * let g:filter_au += 1 |
| 1936 | %!cat |
| 1937 | call assert_equal(0, g:filter_au) |
| 1938 | endif |
| 1939 | |
| 1940 | au! FilterWritePre,FilterReadPre,FilterReadPost |
| 1941 | let &shelltemp = shelltemp |
| 1942 | bwipe! |
| 1943 | endfunc |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 1944 | |
| 1945 | func Test_TextYankPost() |
| 1946 | enew! |
| 1947 | call setline(1, ['foo']) |
| 1948 | |
| 1949 | let g:event = [] |
| 1950 | au TextYankPost * let g:event = copy(v:event) |
| 1951 | |
| 1952 | call assert_equal({}, v:event) |
| 1953 | call assert_fails('let v:event = {}', 'E46:') |
| 1954 | call assert_fails('let v:event.mykey = 0', 'E742:') |
| 1955 | |
| 1956 | norm "ayiw |
| 1957 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1958 | \ #{regcontents: ['foo'], regname: 'a', operator: 'y', |
| 1959 | \ regtype: 'v', visual: v:false, inclusive: v:true}, |
| 1960 | \ g:event) |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 1961 | norm y_ |
| 1962 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1963 | \ #{regcontents: ['foo'], regname: '', operator: 'y', regtype: 'V', |
| 1964 | \ visual: v:false, inclusive: v:false}, |
| 1965 | \ g:event) |
Bram Moolenaar | 37d1673 | 2020-06-12 22:09:01 +0200 | [diff] [blame] | 1966 | norm Vy |
| 1967 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1968 | \ #{regcontents: ['foo'], regname: '', operator: 'y', regtype: 'V', |
| 1969 | \ visual: v:true, inclusive: v:true}, |
| 1970 | \ g:event) |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 1971 | call feedkeys("\<C-V>y", 'x') |
| 1972 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1973 | \ #{regcontents: ['f'], regname: '', operator: 'y', regtype: "\x161", |
| 1974 | \ visual: v:true, inclusive: v:true}, |
| 1975 | \ g:event) |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 1976 | norm "xciwbar |
| 1977 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1978 | \ #{regcontents: ['foo'], regname: 'x', operator: 'c', regtype: 'v', |
| 1979 | \ visual: v:false, inclusive: v:true}, |
| 1980 | \ g:event) |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 1981 | norm "bdiw |
| 1982 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 1983 | \ #{regcontents: ['bar'], regname: 'b', operator: 'd', regtype: 'v', |
| 1984 | \ visual: v:false, inclusive: v:true}, |
| 1985 | \ g:event) |
| 1986 | |
| 1987 | call setline(1, 'foobar') |
| 1988 | " exclusive motion |
| 1989 | norm $"ay0 |
| 1990 | call assert_equal( |
| 1991 | \ #{regcontents: ['fooba'], regname: 'a', operator: 'y', regtype: 'v', |
| 1992 | \ visual: v:false, inclusive: v:false}, |
| 1993 | \ g:event) |
| 1994 | " inclusive motion |
| 1995 | norm 0"ay$ |
| 1996 | call assert_equal( |
| 1997 | \ #{regcontents: ['foobar'], regname: 'a', operator: 'y', regtype: 'v', |
| 1998 | \ visual: v:false, inclusive: v:true}, |
| 1999 | \ g:event) |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 2000 | |
| 2001 | call assert_equal({}, v:event) |
| 2002 | |
Bram Moolenaar | fccbf06 | 2020-11-26 20:34:00 +0100 | [diff] [blame] | 2003 | if has('clipboard_working') && !has('gui_running') |
| 2004 | " Test that when the visual selection is automatically copied to clipboard |
| 2005 | " register a TextYankPost is emitted |
| 2006 | call setline(1, ['foobar']) |
| 2007 | |
| 2008 | let @* = '' |
| 2009 | set clipboard=autoselect |
| 2010 | exe "norm! ggviw\<Esc>" |
| 2011 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 2012 | \ #{regcontents: ['foobar'], regname: '*', operator: 'y', |
| 2013 | \ regtype: 'v', visual: v:true, inclusive: v:false}, |
| 2014 | \ g:event) |
Bram Moolenaar | fccbf06 | 2020-11-26 20:34:00 +0100 | [diff] [blame] | 2015 | |
| 2016 | let @+ = '' |
| 2017 | set clipboard=autoselectplus |
| 2018 | exe "norm! ggviw\<Esc>" |
| 2019 | call assert_equal( |
Bram Moolenaar | a016eeb | 2022-04-09 11:37:38 +0100 | [diff] [blame] | 2020 | \ #{regcontents: ['foobar'], regname: '+', operator: 'y', |
| 2021 | \ regtype: 'v', visual: v:true, inclusive: v:false}, |
| 2022 | \ g:event) |
Bram Moolenaar | fccbf06 | 2020-11-26 20:34:00 +0100 | [diff] [blame] | 2023 | |
| 2024 | set clipboard&vim |
| 2025 | endif |
| 2026 | |
Bram Moolenaar | 7e1652c | 2017-12-16 18:27:02 +0100 | [diff] [blame] | 2027 | au! TextYankPost |
| 2028 | unlet g:event |
| 2029 | bwipe! |
| 2030 | endfunc |
Bram Moolenaar | 9bca805 | 2017-12-18 12:37:55 +0100 | [diff] [blame] | 2031 | |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 2032 | func Test_autocommand_all_events() |
| 2033 | call assert_fails('au * * bwipe', 'E1155:') |
| 2034 | call assert_fails('au * x bwipe', 'E1155:') |
Bram Moolenaar | b6db146 | 2021-12-24 19:24:47 +0000 | [diff] [blame] | 2035 | call assert_fails('au! * x bwipe', 'E1155:') |
Bram Moolenaar | 4fb921e | 2017-12-18 15:33:00 +0100 | [diff] [blame] | 2036 | endfunc |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2037 | |
Bram Moolenaar | f6246f5 | 2022-02-11 16:30:12 +0000 | [diff] [blame] | 2038 | func Test_autocmd_user() |
| 2039 | au User MyEvent let s:res = [expand("<afile>"), expand("<amatch>")] |
| 2040 | doautocmd User MyEvent |
| 2041 | call assert_equal(['MyEvent', 'MyEvent'], s:res) |
| 2042 | au! User |
| 2043 | unlet s:res |
| 2044 | endfunc |
| 2045 | |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2046 | function s:Before_test_dirchanged() |
| 2047 | augroup test_dirchanged |
| 2048 | autocmd! |
| 2049 | augroup END |
| 2050 | let s:li = [] |
| 2051 | let s:dir_this = getcwd() |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2052 | let s:dir_foo = s:dir_this . '/Xfoo' |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2053 | call mkdir(s:dir_foo) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2054 | let s:dir_bar = s:dir_this . '/Xbar' |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2055 | call mkdir(s:dir_bar) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2056 | endfunc |
| 2057 | |
| 2058 | function s:After_test_dirchanged() |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2059 | call chdir(s:dir_this) |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2060 | call delete(s:dir_foo, 'd') |
| 2061 | call delete(s:dir_bar, 'd') |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2062 | augroup test_dirchanged |
| 2063 | autocmd! |
| 2064 | augroup END |
| 2065 | endfunc |
| 2066 | |
| 2067 | function Test_dirchanged_global() |
| 2068 | call s:Before_test_dirchanged() |
Bram Moolenaar | f6246f5 | 2022-02-11 16:30:12 +0000 | [diff] [blame] | 2069 | autocmd test_dirchanged DirChangedPre global call add(s:li, expand("<amatch>") .. " pre cd " .. v:event.directory) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2070 | autocmd test_dirchanged DirChanged global call add(s:li, "cd:") |
| 2071 | autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>")) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2072 | call chdir(s:dir_foo) |
Bram Moolenaar | f6246f5 | 2022-02-11 16:30:12 +0000 | [diff] [blame] | 2073 | let expected = ["global pre cd " .. s:dir_foo, "cd:", s:dir_foo] |
Bram Moolenaar | 28e8f73 | 2022-02-09 12:58:20 +0000 | [diff] [blame] | 2074 | call assert_equal(expected, s:li) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2075 | call chdir(s:dir_foo) |
Bram Moolenaar | 28e8f73 | 2022-02-09 12:58:20 +0000 | [diff] [blame] | 2076 | call assert_equal(expected, s:li) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2077 | exe 'lcd ' .. fnameescape(s:dir_bar) |
Bram Moolenaar | 28e8f73 | 2022-02-09 12:58:20 +0000 | [diff] [blame] | 2078 | call assert_equal(expected, s:li) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2079 | call s:After_test_dirchanged() |
| 2080 | endfunc |
| 2081 | |
| 2082 | function Test_dirchanged_local() |
| 2083 | call s:Before_test_dirchanged() |
| 2084 | autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") |
| 2085 | autocmd test_dirchanged DirChanged window call add(s:li, expand("<afile>")) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2086 | call chdir(s:dir_foo) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2087 | call assert_equal([], s:li) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2088 | exe 'lcd ' .. fnameescape(s:dir_bar) |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2089 | call assert_equal(["lcd:", s:dir_bar], s:li) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2090 | exe 'lcd ' .. fnameescape(s:dir_bar) |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2091 | call assert_equal(["lcd:", s:dir_bar], s:li) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2092 | call s:After_test_dirchanged() |
| 2093 | endfunc |
| 2094 | |
| 2095 | function Test_dirchanged_auto() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2096 | CheckOption autochdir |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2097 | call s:Before_test_dirchanged() |
| 2098 | call test_autochdir() |
Bram Moolenaar | 28e8f73 | 2022-02-09 12:58:20 +0000 | [diff] [blame] | 2099 | autocmd test_dirchanged DirChangedPre auto call add(s:li, "pre cd " .. v:event.directory) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2100 | autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") |
| 2101 | autocmd test_dirchanged DirChanged auto call add(s:li, expand("<afile>")) |
| 2102 | set acd |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 2103 | cd .. |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2104 | call assert_equal([], s:li) |
Bram Moolenaar | 2caad3f | 2018-12-16 15:38:02 +0100 | [diff] [blame] | 2105 | exe 'edit ' . s:dir_foo . '/Xfile' |
| 2106 | call assert_equal(s:dir_foo, getcwd()) |
Bram Moolenaar | 28e8f73 | 2022-02-09 12:58:20 +0000 | [diff] [blame] | 2107 | let expected = ["pre cd " .. s:dir_foo, "auto:", s:dir_foo] |
| 2108 | call assert_equal(expected, s:li) |
Bram Moolenaar | b7407d3 | 2018-02-03 17:36:27 +0100 | [diff] [blame] | 2109 | set noacd |
| 2110 | bwipe! |
| 2111 | call s:After_test_dirchanged() |
| 2112 | endfunc |
Bram Moolenaar | 5a09343 | 2018-02-10 18:15:19 +0100 | [diff] [blame] | 2113 | |
| 2114 | " Test TextChangedI and TextChangedP |
| 2115 | func Test_ChangedP() |
| 2116 | new |
| 2117 | call setline(1, ['foo', 'bar', 'foobar']) |
| 2118 | call test_override("char_avail", 1) |
| 2119 | set complete=. completeopt=menuone |
| 2120 | |
| 2121 | func! TextChangedAutocmd(char) |
| 2122 | let g:autocmd .= a:char |
| 2123 | endfunc |
| 2124 | |
Christian Brabandt | db3b446 | 2021-10-16 11:58:55 +0100 | [diff] [blame] | 2125 | " TextChanged will not be triggered, only check that it isn't. |
Bram Moolenaar | 5a09343 | 2018-02-10 18:15:19 +0100 | [diff] [blame] | 2126 | au! TextChanged <buffer> :call TextChangedAutocmd('N') |
| 2127 | au! TextChangedI <buffer> :call TextChangedAutocmd('I') |
| 2128 | au! TextChangedP <buffer> :call TextChangedAutocmd('P') |
| 2129 | |
| 2130 | call cursor(3, 1) |
| 2131 | let g:autocmd = '' |
| 2132 | call feedkeys("o\<esc>", 'tnix') |
| 2133 | call assert_equal('I', g:autocmd) |
| 2134 | |
| 2135 | let g:autocmd = '' |
| 2136 | call feedkeys("Sf", 'tnix') |
| 2137 | call assert_equal('II', g:autocmd) |
| 2138 | |
| 2139 | let g:autocmd = '' |
| 2140 | call feedkeys("Sf\<C-N>", 'tnix') |
| 2141 | call assert_equal('IIP', g:autocmd) |
| 2142 | |
| 2143 | let g:autocmd = '' |
| 2144 | call feedkeys("Sf\<C-N>\<C-N>", 'tnix') |
| 2145 | call assert_equal('IIPP', g:autocmd) |
| 2146 | |
| 2147 | let g:autocmd = '' |
| 2148 | call feedkeys("Sf\<C-N>\<C-N>\<C-N>", 'tnix') |
| 2149 | call assert_equal('IIPPP', g:autocmd) |
| 2150 | |
| 2151 | let g:autocmd = '' |
| 2152 | call feedkeys("Sf\<C-N>\<C-N>\<C-N>\<C-N>", 'tnix') |
| 2153 | call assert_equal('IIPPPP', g:autocmd) |
| 2154 | |
| 2155 | call assert_equal(['foo', 'bar', 'foobar', 'foo'], getline(1, '$')) |
| 2156 | " TODO: how should it handle completeopt=noinsert,noselect? |
| 2157 | |
| 2158 | " CleanUp |
| 2159 | call test_override("char_avail", 0) |
| 2160 | au! TextChanged |
| 2161 | au! TextChangedI |
| 2162 | au! TextChangedP |
| 2163 | delfu TextChangedAutocmd |
| 2164 | unlet! g:autocmd |
| 2165 | set complete&vim completeopt&vim |
| 2166 | |
| 2167 | bw! |
| 2168 | endfunc |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 2169 | |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 2170 | let g:setline_handled = v:false |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2171 | func SetLineOne() |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 2172 | if !g:setline_handled |
| 2173 | call setline(1, "(x)") |
| 2174 | let g:setline_handled = v:true |
| 2175 | endif |
| 2176 | endfunc |
| 2177 | |
| 2178 | func Test_TextChangedI_with_setline() |
| 2179 | new |
| 2180 | call test_override('char_avail', 1) |
| 2181 | autocmd TextChangedI <buffer> call SetLineOne() |
| 2182 | call feedkeys("i(\<CR>\<Esc>", 'tx') |
| 2183 | call assert_equal('(', getline(1)) |
| 2184 | call assert_equal('x)', getline(2)) |
| 2185 | undo |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 2186 | call assert_equal('', getline(1)) |
Bram Moolenaar | 9fa9506 | 2018-08-08 22:08:32 +0200 | [diff] [blame] | 2187 | call assert_equal('', getline(2)) |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 2188 | |
Bram Moolenaar | ca34db3 | 2022-01-20 11:17:18 +0000 | [diff] [blame] | 2189 | call test_override('char_avail', 0) |
Bram Moolenaar | 91d2e78 | 2018-08-07 19:05:01 +0200 | [diff] [blame] | 2190 | bwipe! |
| 2191 | endfunc |
| 2192 | |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 2193 | func Test_Changed_FirstTime() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 2194 | CheckFeature terminal |
| 2195 | CheckNotGui |
Bram Moolenaar | 3cdcb09 | 2020-03-18 19:18:10 +0100 | [diff] [blame] | 2196 | " Starting a terminal to run Vim is always considered flaky. |
Bram Moolenaar | 30d53e2 | 2020-03-18 21:10:44 +0100 | [diff] [blame] | 2197 | let g:test_is_flaky = 1 |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 2198 | |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 2199 | " Prepare file for TextChanged event. |
| 2200 | call writefile([''], 'Xchanged.txt') |
| 2201 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) |
| 2202 | call assert_equal('running', term_getstatus(buf)) |
Bram Moolenaar | 1834d37 | 2018-03-29 17:40:46 +0200 | [diff] [blame] | 2203 | " Wait for the ruler (in the status line) to be shown. |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 2204 | " In ConPTY, there is additional character which is drawn up to the width of |
| 2205 | " the screen. |
| 2206 | if has('conpty') |
| 2207 | call WaitForAssert({-> assert_match('\<All.*$', term_getline(buf, 3))}) |
| 2208 | else |
| 2209 | call WaitForAssert({-> assert_match('\<All$', term_getline(buf, 3))}) |
| 2210 | endif |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 2211 | " It's only adding autocmd, so that no event occurs. |
| 2212 | call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>") |
| 2213 | call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>") |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 2214 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
Bram Moolenaar | 8c64a36 | 2018-03-23 22:39:31 +0100 | [diff] [blame] | 2215 | call assert_equal([''], readfile('Xchanged.txt')) |
| 2216 | |
| 2217 | " clean up |
| 2218 | call delete('Xchanged.txt') |
| 2219 | bwipe! |
| 2220 | endfunc |
Bram Moolenaar | 0566e89 | 2019-01-24 19:37:40 +0100 | [diff] [blame] | 2221 | |
Bram Moolenaar | eb93f3f | 2019-04-04 15:04:56 +0200 | [diff] [blame] | 2222 | func Test_autocmd_nested() |
| 2223 | let g:did_nested = 0 |
| 2224 | augroup Testing |
| 2225 | au WinNew * edit somefile |
| 2226 | au BufNew * let g:did_nested = 1 |
| 2227 | augroup END |
| 2228 | split |
| 2229 | call assert_equal(0, g:did_nested) |
| 2230 | close |
| 2231 | bwipe! somefile |
| 2232 | |
| 2233 | " old nested argument still works |
| 2234 | augroup Testing |
| 2235 | au! |
| 2236 | au WinNew * nested edit somefile |
| 2237 | au BufNew * let g:did_nested = 1 |
| 2238 | augroup END |
| 2239 | split |
| 2240 | call assert_equal(1, g:did_nested) |
| 2241 | close |
| 2242 | bwipe! somefile |
| 2243 | |
| 2244 | " New ++nested argument works |
| 2245 | augroup Testing |
| 2246 | au! |
| 2247 | au WinNew * ++nested edit somefile |
| 2248 | au BufNew * let g:did_nested = 1 |
| 2249 | augroup END |
| 2250 | split |
| 2251 | call assert_equal(1, g:did_nested) |
| 2252 | close |
| 2253 | bwipe! somefile |
| 2254 | |
Bram Moolenaar | f077514 | 2022-03-04 20:10:38 +0000 | [diff] [blame] | 2255 | " nested without ++ does not work in Vim9 script |
| 2256 | call assert_fails('vim9cmd au WinNew * nested echo fails', 'E1078:') |
| 2257 | |
Bram Moolenaar | eb93f3f | 2019-04-04 15:04:56 +0200 | [diff] [blame] | 2258 | augroup Testing |
| 2259 | au! |
| 2260 | augroup END |
| 2261 | |
| 2262 | call assert_fails('au WinNew * ++nested ++nested echo bad', 'E983:') |
| 2263 | call assert_fails('au WinNew * nested nested echo bad', 'E983:') |
| 2264 | endfunc |
| 2265 | |
| 2266 | func Test_autocmd_once() |
| 2267 | " Without ++once WinNew triggers twice |
| 2268 | let g:did_split = 0 |
| 2269 | augroup Testing |
| 2270 | au WinNew * let g:did_split += 1 |
| 2271 | augroup END |
| 2272 | split |
| 2273 | split |
| 2274 | call assert_equal(2, g:did_split) |
| 2275 | call assert_true(exists('#WinNew')) |
| 2276 | close |
| 2277 | close |
| 2278 | |
| 2279 | " With ++once WinNew triggers once |
| 2280 | let g:did_split = 0 |
| 2281 | augroup Testing |
| 2282 | au! |
| 2283 | au WinNew * ++once let g:did_split += 1 |
| 2284 | augroup END |
| 2285 | split |
| 2286 | split |
| 2287 | call assert_equal(1, g:did_split) |
| 2288 | call assert_false(exists('#WinNew')) |
| 2289 | close |
| 2290 | close |
| 2291 | |
| 2292 | call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') |
| 2293 | endfunc |
| 2294 | |
Bram Moolenaar | a68e595 | 2019-04-25 22:22:01 +0200 | [diff] [blame] | 2295 | func Test_autocmd_bufreadpre() |
| 2296 | new |
| 2297 | let b:bufreadpre = 1 |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 2298 | call append(0, range(1000)) |
Bram Moolenaar | a68e595 | 2019-04-25 22:22:01 +0200 | [diff] [blame] | 2299 | w! XAutocmdBufReadPre.txt |
| 2300 | autocmd BufReadPre <buffer> :let b:bufreadpre += 1 |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 2301 | norm! 500gg |
Bram Moolenaar | a68e595 | 2019-04-25 22:22:01 +0200 | [diff] [blame] | 2302 | sp |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 2303 | norm! 1000gg |
Bram Moolenaar | a68e595 | 2019-04-25 22:22:01 +0200 | [diff] [blame] | 2304 | wincmd p |
| 2305 | let g:wsv1 = winsaveview() |
| 2306 | wincmd p |
| 2307 | let g:wsv2 = winsaveview() |
| 2308 | " triggers BufReadPre, should not move the cursor in either window |
| 2309 | " The topline may change one line in a large window. |
| 2310 | edit |
| 2311 | call assert_inrange(g:wsv2.topline - 1, g:wsv2.topline + 1, winsaveview().topline) |
| 2312 | call assert_equal(g:wsv2.lnum, winsaveview().lnum) |
| 2313 | call assert_equal(2, b:bufreadpre) |
| 2314 | wincmd p |
| 2315 | call assert_equal(g:wsv1.topline, winsaveview().topline) |
| 2316 | call assert_equal(g:wsv1.lnum, winsaveview().lnum) |
| 2317 | call assert_equal(2, b:bufreadpre) |
| 2318 | " Now set the cursor position in an BufReadPre autocommand |
| 2319 | " (even though the position will be invalid, this should make Vim reset the |
| 2320 | " cursor position in the other window. |
| 2321 | wincmd p |
| 2322 | set cpo+=g |
| 2323 | " won't do anything, but try to set the cursor on an invalid lnum |
| 2324 | autocmd BufReadPre <buffer> :norm! 70gg |
| 2325 | " triggers BufReadPre, should not move the cursor in either window |
| 2326 | e |
| 2327 | call assert_equal(1, winsaveview().topline) |
| 2328 | call assert_equal(1, winsaveview().lnum) |
| 2329 | call assert_equal(3, b:bufreadpre) |
| 2330 | wincmd p |
| 2331 | call assert_equal(g:wsv1.topline, winsaveview().topline) |
| 2332 | call assert_equal(g:wsv1.lnum, winsaveview().lnum) |
| 2333 | call assert_equal(3, b:bufreadpre) |
| 2334 | close |
| 2335 | close |
| 2336 | call delete('XAutocmdBufReadPre.txt') |
| 2337 | set cpo-=g |
| 2338 | endfunc |
| 2339 | |
Bram Moolenaar | 5e66b42 | 2019-01-24 21:58:10 +0100 | [diff] [blame] | 2340 | " FileChangedShell tested in test_filechanged.vim |
Bram Moolenaar | 69ea587 | 2019-04-25 20:29:00 +0200 | [diff] [blame] | 2341 | |
| 2342 | " Tests for the following autocommands: |
| 2343 | " - FileWritePre writing a compressed file |
| 2344 | " - FileReadPost reading a compressed file |
| 2345 | " - BufNewFile reading a file template |
| 2346 | " - BufReadPre decompressing the file to be read |
| 2347 | " - FilterReadPre substituting characters in the temp file |
| 2348 | " - FilterReadPost substituting characters after filtering |
| 2349 | " - FileReadPre set options for decompression |
| 2350 | " - FileReadPost decompress the file |
| 2351 | func Test_ReadWrite_Autocmds() |
| 2352 | " Run this test only on Unix-like systems and if gzip is available |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2353 | CheckUnix |
| 2354 | CheckExecutable gzip |
Bram Moolenaar | 69ea587 | 2019-04-25 20:29:00 +0200 | [diff] [blame] | 2355 | |
| 2356 | " Make $GZIP empty, "-v" would cause trouble. |
| 2357 | let $GZIP = "" |
| 2358 | |
| 2359 | " Use a FileChangedShell autocommand to avoid a prompt for 'Xtestfile.gz' |
| 2360 | " being modified outside of Vim (noticed on Solaris). |
| 2361 | au FileChangedShell * echo 'caught FileChangedShell' |
| 2362 | |
| 2363 | " Test for the FileReadPost, FileWritePre and FileWritePost autocmds |
| 2364 | augroup Test1 |
| 2365 | au! |
| 2366 | au FileWritePre *.gz '[,']!gzip |
| 2367 | au FileWritePost *.gz undo |
| 2368 | au FileReadPost *.gz '[,']!gzip -d |
| 2369 | augroup END |
| 2370 | |
| 2371 | new |
| 2372 | set bin |
| 2373 | call append(0, [ |
| 2374 | \ 'line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2375 | \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2376 | \ 'line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2377 | \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2378 | \ 'line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2379 | \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2380 | \ 'line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2381 | \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2382 | \ 'line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2383 | \ ]) |
| 2384 | 1,9write! Xtestfile.gz |
| 2385 | enew! | close |
| 2386 | |
| 2387 | new |
| 2388 | " Read and decompress the testfile |
| 2389 | 0read Xtestfile.gz |
| 2390 | call assert_equal([ |
| 2391 | \ 'line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2392 | \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2393 | \ 'line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2394 | \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2395 | \ 'line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2396 | \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2397 | \ 'line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2398 | \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2399 | \ 'line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2400 | \ ], getline(1, 9)) |
| 2401 | enew! | close |
| 2402 | |
| 2403 | augroup Test1 |
| 2404 | au! |
| 2405 | augroup END |
| 2406 | |
| 2407 | " Test for the FileAppendPre and FileAppendPost autocmds |
| 2408 | augroup Test2 |
| 2409 | au! |
| 2410 | au BufNewFile *.c read Xtest.c |
| 2411 | au FileAppendPre *.out '[,']s/new/NEW/ |
| 2412 | au FileAppendPost *.out !cat Xtest.c >> test.out |
| 2413 | augroup END |
| 2414 | |
| 2415 | call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c') |
| 2416 | new foo.c " should load Xtest.c |
| 2417 | call assert_equal(['/*', ' * Here is a new .c file', ' */'], getline(2, 4)) |
| 2418 | w! >> test.out " append it to the output file |
| 2419 | |
| 2420 | let contents = readfile('test.out') |
| 2421 | call assert_equal(' * Here is a NEW .c file', contents[2]) |
| 2422 | call assert_equal(' * Here is a new .c file', contents[5]) |
| 2423 | |
| 2424 | call delete('test.out') |
| 2425 | enew! | close |
| 2426 | augroup Test2 |
| 2427 | au! |
| 2428 | augroup END |
| 2429 | |
| 2430 | " Test for the BufReadPre and BufReadPost autocmds |
| 2431 | augroup Test3 |
| 2432 | au! |
| 2433 | " setup autocommands to decompress before reading and re-compress |
| 2434 | " afterwards |
| 2435 | au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>")) |
| 2436 | au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) |
| 2437 | au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r")) |
| 2438 | au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r")) |
| 2439 | augroup END |
| 2440 | |
| 2441 | e! Xtestfile.gz " Edit compressed file |
| 2442 | call assert_equal([ |
| 2443 | \ 'line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2444 | \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2445 | \ 'line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2446 | \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2447 | \ 'line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2448 | \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2449 | \ 'line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2450 | \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2451 | \ 'line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2452 | \ ], getline(1, 9)) |
| 2453 | |
| 2454 | w! >> test.out " Append it to the output file |
| 2455 | |
| 2456 | augroup Test3 |
| 2457 | au! |
| 2458 | augroup END |
| 2459 | |
| 2460 | " Test for the FilterReadPre and FilterReadPost autocmds. |
| 2461 | set shelltemp " need temp files here |
| 2462 | augroup Test4 |
| 2463 | au! |
| 2464 | au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t") |
| 2465 | au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>")) |
| 2466 | au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t' |
| 2467 | au FilterReadPost *.out '[,']s/x/X/g |
| 2468 | augroup END |
| 2469 | |
| 2470 | e! test.out " Edit the output file |
| 2471 | 1,$!cat |
| 2472 | call assert_equal([ |
| 2473 | \ 'linE 2 AbcdefghijklmnopqrstuvwXyz', |
| 2474 | \ 'linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', |
| 2475 | \ 'linE 4 AbcdefghijklmnopqrstuvwXyz', |
| 2476 | \ 'linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', |
| 2477 | \ 'linE 6 AbcdefghijklmnopqrstuvwXyz', |
| 2478 | \ 'linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', |
| 2479 | \ 'linE 8 AbcdefghijklmnopqrstuvwXyz', |
| 2480 | \ 'linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', |
| 2481 | \ 'linE 10 AbcdefghijklmnopqrstuvwXyz' |
| 2482 | \ ], getline(1, 9)) |
| 2483 | call assert_equal([ |
| 2484 | \ 'line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2485 | \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2486 | \ 'line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2487 | \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2488 | \ 'line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2489 | \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2490 | \ 'line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2491 | \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2492 | \ 'line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2493 | \ ], readfile('test.out')) |
| 2494 | |
| 2495 | augroup Test4 |
| 2496 | au! |
| 2497 | augroup END |
| 2498 | set shelltemp&vim |
| 2499 | |
| 2500 | " Test for the FileReadPre and FileReadPost autocmds. |
| 2501 | augroup Test5 |
| 2502 | au! |
| 2503 | au FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>")) |
| 2504 | au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) |
| 2505 | au FileReadPost *.gz '[,']s/l/L/ |
| 2506 | augroup END |
| 2507 | |
| 2508 | new |
| 2509 | 0r Xtestfile.gz " Read compressed file |
| 2510 | call assert_equal([ |
| 2511 | \ 'Line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2512 | \ 'Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2513 | \ 'Line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2514 | \ 'Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2515 | \ 'Line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2516 | \ 'Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2517 | \ 'Line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2518 | \ 'Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2519 | \ 'Line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2520 | \ ], getline(1, 9)) |
| 2521 | call assert_equal([ |
| 2522 | \ 'line 2 Abcdefghijklmnopqrstuvwxyz', |
| 2523 | \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2524 | \ 'line 4 Abcdefghijklmnopqrstuvwxyz', |
| 2525 | \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2526 | \ 'line 6 Abcdefghijklmnopqrstuvwxyz', |
| 2527 | \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2528 | \ 'line 8 Abcdefghijklmnopqrstuvwxyz', |
| 2529 | \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 2530 | \ 'line 10 Abcdefghijklmnopqrstuvwxyz' |
| 2531 | \ ], readfile('Xtestfile.gz')) |
| 2532 | |
| 2533 | augroup Test5 |
| 2534 | au! |
| 2535 | augroup END |
| 2536 | |
| 2537 | au! FileChangedShell |
| 2538 | call delete('Xtestfile.gz') |
| 2539 | call delete('Xtest.c') |
| 2540 | call delete('test.out') |
| 2541 | endfunc |
Bram Moolenaar | 23b5139 | 2019-05-09 21:38:43 +0200 | [diff] [blame] | 2542 | |
| 2543 | func Test_throw_in_BufWritePre() |
| 2544 | new |
| 2545 | call setline(1, ['one', 'two', 'three']) |
| 2546 | call assert_false(filereadable('Xthefile')) |
| 2547 | augroup throwing |
| 2548 | au BufWritePre X* throw 'do not write' |
| 2549 | augroup END |
| 2550 | try |
| 2551 | w Xthefile |
| 2552 | catch |
| 2553 | let caught = 1 |
| 2554 | endtry |
| 2555 | call assert_equal(1, caught) |
| 2556 | call assert_false(filereadable('Xthefile')) |
| 2557 | |
| 2558 | bwipe! |
| 2559 | au! throwing |
| 2560 | endfunc |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2561 | |
Bram Moolenaar | 40fa12a | 2021-09-22 14:18:13 +0200 | [diff] [blame] | 2562 | func Test_autocmd_in_try_block() |
| 2563 | call mkdir('Xdir') |
| 2564 | au BufEnter * let g:fname = expand('%') |
| 2565 | try |
| 2566 | edit Xdir/ |
| 2567 | endtry |
| 2568 | call assert_match('Xdir', g:fname) |
| 2569 | |
| 2570 | unlet g:fname |
| 2571 | au! BufEnter |
| 2572 | call delete('Xdir', 'rf') |
| 2573 | endfunc |
| 2574 | |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2575 | func Test_autocmd_SafeState() |
| 2576 | CheckRunVimInTerminal |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 2577 | let g:test_is_flaky = 1 |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2578 | |
| 2579 | let lines =<< trim END |
| 2580 | let g:safe = 0 |
| 2581 | let g:again = '' |
| 2582 | au SafeState * let g:safe += 1 |
| 2583 | au SafeStateAgain * let g:again ..= 'x' |
| 2584 | func CallTimer() |
| 2585 | call timer_start(10, {id -> execute('let g:again ..= "t"')}) |
| 2586 | endfunc |
| 2587 | END |
| 2588 | call writefile(lines, 'XSafeState') |
| 2589 | let buf = RunVimInTerminal('-S XSafeState', #{rows: 6}) |
| 2590 | |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 2591 | " Sometimes we loop to handle a K_IGNORE, SafeState may be triggered once or |
Bram Moolenaar | 8fb1b47 | 2020-02-23 16:16:26 +0100 | [diff] [blame] | 2592 | " more often. |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2593 | call term_sendkeys(buf, ":echo g:safe\<CR>") |
Bram Moolenaar | 8fb1b47 | 2020-02-23 16:16:26 +0100 | [diff] [blame] | 2594 | call WaitForAssert({-> assert_match('^\d ', term_getline(buf, 6))}, 1000) |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2595 | |
Bram Moolenaar | 8fb1b47 | 2020-02-23 16:16:26 +0100 | [diff] [blame] | 2596 | " SafeStateAgain should be invoked at least three times |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2597 | call term_sendkeys(buf, ":echo g:again\<CR>") |
Bram Moolenaar | 8fb1b47 | 2020-02-23 16:16:26 +0100 | [diff] [blame] | 2598 | call WaitForAssert({-> assert_match('^xxx', term_getline(buf, 6))}, 1000) |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2599 | |
| 2600 | call term_sendkeys(buf, ":let g:again = ''\<CR>:call CallTimer()\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2601 | call TermWait(buf, 50) |
Bram Moolenaar | 0f6629a | 2019-09-22 23:24:13 +0200 | [diff] [blame] | 2602 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2603 | call TermWait(buf, 50) |
Bram Moolenaar | cadbe1b | 2019-09-22 21:50:09 +0200 | [diff] [blame] | 2604 | call term_sendkeys(buf, ":echo g:again\<CR>") |
| 2605 | call WaitForAssert({-> assert_match('xtx', term_getline(buf, 6))}, 1000) |
| 2606 | |
| 2607 | call StopVimInTerminal(buf) |
| 2608 | call delete('XSafeState') |
| 2609 | endfunc |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2610 | |
| 2611 | func Test_autocmd_CmdWinEnter() |
| 2612 | CheckRunVimInTerminal |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 2613 | CheckFeature cmdwin |
| 2614 | |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2615 | let lines =<< trim END |
Egor Zvorykin | 125ffd2 | 2021-11-17 14:01:14 +0000 | [diff] [blame] | 2616 | augroup vimHints | au! | augroup END |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2617 | let b:dummy_var = 'This is a dummy' |
| 2618 | autocmd CmdWinEnter * quit |
| 2619 | let winnr = winnr('$') |
| 2620 | END |
Bram Moolenaar | 1cfb9bb | 2020-12-22 11:40:45 +0100 | [diff] [blame] | 2621 | let filename = 'XCmdWinEnter' |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2622 | call writefile(lines, filename) |
| 2623 | let buf = RunVimInTerminal('-S '.filename, #{rows: 6}) |
| 2624 | |
| 2625 | call term_sendkeys(buf, "q:") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2626 | call TermWait(buf) |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2627 | call term_sendkeys(buf, ":echo b:dummy_var\<cr>") |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2628 | call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 2000) |
Bram Moolenaar | 23324a0 | 2019-10-01 17:39:04 +0200 | [diff] [blame] | 2629 | call term_sendkeys(buf, ":echo &buftype\<cr>") |
| 2630 | call WaitForAssert({-> assert_notmatch('^nofile', term_getline(buf, 6))}, 1000) |
| 2631 | call term_sendkeys(buf, ":echo winnr\<cr>") |
| 2632 | call WaitForAssert({-> assert_match('^1', term_getline(buf, 6))}, 1000) |
| 2633 | |
| 2634 | " clean up |
| 2635 | call StopVimInTerminal(buf) |
| 2636 | call delete(filename) |
| 2637 | endfunc |
Bram Moolenaar | ec66c41 | 2019-10-11 21:19:13 +0200 | [diff] [blame] | 2638 | |
| 2639 | func Test_autocmd_was_using_freed_memory() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 2640 | CheckFeature quickfix |
| 2641 | |
Bram Moolenaar | ec66c41 | 2019-10-11 21:19:13 +0200 | [diff] [blame] | 2642 | pedit xx |
| 2643 | n x |
Bram Moolenaar | 92bb83e | 2021-02-03 23:04:46 +0100 | [diff] [blame] | 2644 | augroup winenter |
| 2645 | au WinEnter * if winnr('$') > 2 | quit | endif |
| 2646 | augroup END |
Bram Moolenaar | ec66c41 | 2019-10-11 21:19:13 +0200 | [diff] [blame] | 2647 | split |
Bram Moolenaar | 92bb83e | 2021-02-03 23:04:46 +0100 | [diff] [blame] | 2648 | |
| 2649 | augroup winenter |
| 2650 | au! WinEnter |
| 2651 | augroup END |
| 2652 | |
| 2653 | bwipe xx |
| 2654 | bwipe x |
| 2655 | pclose |
Bram Moolenaar | ec66c41 | 2019-10-11 21:19:13 +0200 | [diff] [blame] | 2656 | endfunc |
Bram Moolenaar | f4a1d1c | 2019-11-16 13:50:25 +0100 | [diff] [blame] | 2657 | |
| 2658 | func Test_BufWrite_lockmarks() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 2659 | let g:test_is_flaky = 1 |
Bram Moolenaar | f4a1d1c | 2019-11-16 13:50:25 +0100 | [diff] [blame] | 2660 | edit! Xtest |
| 2661 | call setline(1, ['a', 'b', 'c', 'd']) |
| 2662 | |
| 2663 | " :lockmarks preserves the marks |
| 2664 | call SetChangeMarks(2, 3) |
| 2665 | lockmarks write |
| 2666 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 2667 | |
| 2668 | " *WritePre autocmds get the correct line range, but lockmarks preserves the |
| 2669 | " original values for the user |
| 2670 | augroup lockmarks |
| 2671 | au! |
| 2672 | au BufWritePre,FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")]) |
| 2673 | au FileWritePre * call assert_equal([3, 4], [line("'["), line("']")]) |
| 2674 | augroup END |
| 2675 | |
| 2676 | lockmarks write |
| 2677 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 2678 | |
| 2679 | if executable('cat') |
| 2680 | lockmarks %!cat |
| 2681 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 2682 | endif |
| 2683 | |
| 2684 | lockmarks 3,4write Xtest2 |
| 2685 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 2686 | |
| 2687 | au! lockmarks |
| 2688 | augroup! lockmarks |
| 2689 | call delete('Xtest') |
| 2690 | call delete('Xtest2') |
| 2691 | endfunc |
Bram Moolenaar | ce6db02 | 2020-01-07 20:11:42 +0100 | [diff] [blame] | 2692 | |
| 2693 | func Test_FileType_spell() |
| 2694 | if !isdirectory('/tmp') |
| 2695 | throw "Skipped: requires /tmp directory" |
| 2696 | endif |
| 2697 | |
| 2698 | " this was crashing with an invalid free() |
| 2699 | setglobal spellfile=/tmp/en.utf-8.add |
| 2700 | augroup crash |
| 2701 | autocmd! |
| 2702 | autocmd BufNewFile,BufReadPost crashfile setf somefiletype |
| 2703 | autocmd BufNewFile,BufReadPost crashfile set ft=anotherfiletype |
| 2704 | autocmd FileType anotherfiletype setlocal spell |
| 2705 | augroup END |
| 2706 | func! NoCrash() abort |
| 2707 | edit /tmp/crashfile |
| 2708 | endfunc |
| 2709 | call NoCrash() |
| 2710 | |
| 2711 | au! crash |
| 2712 | setglobal spellfile= |
| 2713 | endfunc |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 2714 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 2715 | " Test closing a window or editing another buffer from a FileChangedRO handler |
| 2716 | " in a readonly buffer |
| 2717 | func Test_FileChangedRO_winclose() |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 2718 | call test_override('ui_delay', 10) |
| 2719 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 2720 | augroup FileChangedROTest |
| 2721 | au! |
| 2722 | autocmd FileChangedRO * quit |
| 2723 | augroup END |
| 2724 | new |
| 2725 | set readonly |
| 2726 | call assert_fails('normal i', 'E788:') |
| 2727 | close |
| 2728 | augroup! FileChangedROTest |
| 2729 | |
| 2730 | augroup FileChangedROTest |
| 2731 | au! |
| 2732 | autocmd FileChangedRO * edit Xfile |
| 2733 | augroup END |
| 2734 | new |
| 2735 | set readonly |
| 2736 | call assert_fails('normal i', 'E788:') |
| 2737 | close |
| 2738 | augroup! FileChangedROTest |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 2739 | call test_override('ALL', 0) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 2740 | endfunc |
| 2741 | |
Bram Moolenaar | 0c81d1b | 2020-02-22 22:45:55 +0100 | [diff] [blame] | 2742 | func LogACmd() |
| 2743 | call add(g:logged, line('$')) |
| 2744 | endfunc |
| 2745 | |
| 2746 | func Test_TermChanged() |
Bram Moolenaar | d28e0b3 | 2020-02-22 23:08:52 +0100 | [diff] [blame] | 2747 | CheckNotGui |
| 2748 | |
Bram Moolenaar | 0c81d1b | 2020-02-22 22:45:55 +0100 | [diff] [blame] | 2749 | enew! |
| 2750 | tabnew |
| 2751 | call setline(1, ['a', 'b', 'c', 'd']) |
| 2752 | $ |
| 2753 | au TermChanged * call LogACmd() |
| 2754 | let g:logged = [] |
| 2755 | let term_save = &term |
| 2756 | set term=xterm |
| 2757 | call assert_equal([1, 4], g:logged) |
| 2758 | |
| 2759 | au! TermChanged |
| 2760 | let &term = term_save |
| 2761 | bwipe! |
| 2762 | endfunc |
| 2763 | |
Bram Moolenaar | e328487 | 2020-03-19 13:55:03 +0100 | [diff] [blame] | 2764 | " Test for FileReadCmd autocmd |
| 2765 | func Test_autocmd_FileReadCmd() |
| 2766 | func ReadFileCmd() |
| 2767 | call append(line('$'), "v:cmdarg = " .. v:cmdarg) |
| 2768 | endfunc |
| 2769 | augroup FileReadCmdTest |
| 2770 | au! |
| 2771 | au FileReadCmd Xtest call ReadFileCmd() |
| 2772 | augroup END |
| 2773 | |
| 2774 | new |
| 2775 | read ++bin Xtest |
| 2776 | read ++nobin Xtest |
| 2777 | read ++edit Xtest |
| 2778 | read ++bad=keep Xtest |
| 2779 | read ++bad=drop Xtest |
| 2780 | read ++bad=- Xtest |
| 2781 | read ++ff=unix Xtest |
| 2782 | read ++ff=dos Xtest |
| 2783 | read ++ff=mac Xtest |
| 2784 | read ++enc=utf-8 Xtest |
| 2785 | |
| 2786 | call assert_equal(['', |
| 2787 | \ 'v:cmdarg = ++bin', |
| 2788 | \ 'v:cmdarg = ++nobin', |
| 2789 | \ 'v:cmdarg = ++edit', |
| 2790 | \ 'v:cmdarg = ++bad=keep', |
| 2791 | \ 'v:cmdarg = ++bad=drop', |
| 2792 | \ 'v:cmdarg = ++bad=-', |
| 2793 | \ 'v:cmdarg = ++ff=unix', |
| 2794 | \ 'v:cmdarg = ++ff=dos', |
| 2795 | \ 'v:cmdarg = ++ff=mac', |
| 2796 | \ 'v:cmdarg = ++enc=utf-8'], getline(1, '$')) |
| 2797 | |
| 2798 | close! |
| 2799 | augroup FileReadCmdTest |
| 2800 | au! |
| 2801 | augroup END |
| 2802 | delfunc ReadFileCmd |
| 2803 | endfunc |
| 2804 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 2805 | " Test for passing invalid arguments to autocmd |
| 2806 | func Test_autocmd_invalid_args() |
| 2807 | " Additional character after * for event |
| 2808 | call assert_fails('autocmd *a Xfile set ff=unix', 'E215:') |
| 2809 | augroup Test |
| 2810 | augroup END |
| 2811 | " Invalid autocmd event |
| 2812 | call assert_fails('autocmd Bufabc Xfile set ft=vim', 'E216:') |
| 2813 | " Invalid autocmd event in a autocmd group |
| 2814 | call assert_fails('autocmd Test Bufabc Xfile set ft=vim', 'E216:') |
| 2815 | augroup! Test |
| 2816 | " Execute all autocmds |
| 2817 | call assert_fails('doautocmd * BufEnter', 'E217:') |
| 2818 | call assert_fails('augroup! x1a2b3', 'E367:') |
| 2819 | call assert_fails('autocmd BufNew <buffer=999> pwd', 'E680:') |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 2820 | call assert_fails('autocmd BufNew \) set ff=unix', 'E55:') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 2821 | endfunc |
| 2822 | |
| 2823 | " Test for deep nesting of autocmds |
| 2824 | func Test_autocmd_deep_nesting() |
| 2825 | autocmd BufEnter Xfile doautocmd BufEnter Xfile |
| 2826 | call assert_fails('doautocmd BufEnter Xfile', 'E218:') |
| 2827 | autocmd! BufEnter Xfile |
| 2828 | endfunc |
| 2829 | |
Bram Moolenaar | be5ee86 | 2020-06-10 20:56:58 +0200 | [diff] [blame] | 2830 | " Tests for SigUSR1 autocmd event, which is only available on posix systems. |
| 2831 | func Test_autocmd_sigusr1() |
| 2832 | CheckUnix |
Bram Moolenaar | 62cd26a | 2020-10-11 20:08:44 +0200 | [diff] [blame] | 2833 | CheckExecutable /bin/kill |
Bram Moolenaar | be5ee86 | 2020-06-10 20:56:58 +0200 | [diff] [blame] | 2834 | |
| 2835 | let g:sigusr1_passed = 0 |
| 2836 | au SigUSR1 * let g:sigusr1_passed = 1 |
| 2837 | call system('/bin/kill -s usr1 ' . getpid()) |
| 2838 | call WaitForAssert({-> assert_true(g:sigusr1_passed)}) |
| 2839 | |
| 2840 | au! SigUSR1 |
| 2841 | unlet g:sigusr1_passed |
| 2842 | endfunc |
| 2843 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 2844 | " Test for BufReadPre autocmd deleting the file |
| 2845 | func Test_BufReadPre_delfile() |
| 2846 | augroup TestAuCmd |
| 2847 | au! |
| 2848 | autocmd BufReadPre Xfile call delete('Xfile') |
| 2849 | augroup END |
| 2850 | call writefile([], 'Xfile') |
| 2851 | call assert_fails('new Xfile', 'E200:') |
| 2852 | call assert_equal('Xfile', @%) |
| 2853 | call assert_equal(1, &readonly) |
| 2854 | call delete('Xfile') |
| 2855 | augroup TestAuCmd |
| 2856 | au! |
| 2857 | augroup END |
| 2858 | close! |
| 2859 | endfunc |
| 2860 | |
| 2861 | " Test for BufReadPre autocmd changing the current buffer |
| 2862 | func Test_BufReadPre_changebuf() |
| 2863 | augroup TestAuCmd |
| 2864 | au! |
| 2865 | autocmd BufReadPre Xfile edit Xsomeotherfile |
| 2866 | augroup END |
| 2867 | call writefile([], 'Xfile') |
| 2868 | call assert_fails('new Xfile', 'E201:') |
| 2869 | call assert_equal('Xsomeotherfile', @%) |
| 2870 | call assert_equal(1, &readonly) |
| 2871 | call delete('Xfile') |
| 2872 | augroup TestAuCmd |
| 2873 | au! |
| 2874 | augroup END |
| 2875 | close! |
| 2876 | endfunc |
| 2877 | |
| 2878 | " Test for BufWipeouti autocmd changing the current buffer when reading a file |
| 2879 | " in an empty buffer with 'f' flag in 'cpo' |
| 2880 | func Test_BufDelete_changebuf() |
| 2881 | new |
| 2882 | augroup TestAuCmd |
| 2883 | au! |
| 2884 | autocmd BufWipeout * let bufnr = bufadd('somefile') | exe "b " .. bufnr |
| 2885 | augroup END |
| 2886 | let save_cpo = &cpo |
| 2887 | set cpo+=f |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 2888 | call assert_fails('r Xfile', ['E812:', 'E484:']) |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 2889 | call assert_equal('somefile', @%) |
| 2890 | let &cpo = save_cpo |
| 2891 | augroup TestAuCmd |
| 2892 | au! |
| 2893 | augroup END |
| 2894 | close! |
| 2895 | endfunc |
| 2896 | |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2897 | " Test for the temporary internal window used to execute autocmds |
| 2898 | func Test_autocmd_window() |
| 2899 | %bw! |
| 2900 | edit one.txt |
| 2901 | tabnew two.txt |
Bram Moolenaar | 41cd803 | 2021-03-13 15:47:56 +0100 | [diff] [blame] | 2902 | vnew three.txt |
| 2903 | tabnew four.txt |
| 2904 | tabprevious |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2905 | let g:blist = [] |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 2906 | augroup aucmd_win_test1 |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2907 | au! |
| 2908 | au BufEnter * call add(g:blist, [expand('<afile>'), |
| 2909 | \ win_gettype(bufwinnr(expand('<afile>')))]) |
| 2910 | augroup END |
| 2911 | |
| 2912 | doautoall BufEnter |
Bram Moolenaar | 41cd803 | 2021-03-13 15:47:56 +0100 | [diff] [blame] | 2913 | call assert_equal([ |
| 2914 | \ ['one.txt', 'autocmd'], |
| 2915 | \ ['two.txt', ''], |
| 2916 | \ ['four.txt', 'autocmd'], |
| 2917 | \ ['three.txt', ''], |
| 2918 | \ ], g:blist) |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2919 | |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 2920 | augroup aucmd_win_test1 |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2921 | au! |
| 2922 | augroup END |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 2923 | augroup! aucmd_win_test1 |
| 2924 | %bw! |
| 2925 | endfunc |
| 2926 | |
| 2927 | " Test for trying to close the temporary window used for executing an autocmd |
| 2928 | func Test_close_autocmd_window() |
| 2929 | %bw! |
| 2930 | edit one.txt |
| 2931 | tabnew two.txt |
| 2932 | augroup aucmd_win_test2 |
| 2933 | au! |
| 2934 | au BufEnter * if expand('<afile>') == 'one.txt' | 1close | endif |
| 2935 | augroup END |
| 2936 | |
| 2937 | call assert_fails('doautoall BufEnter', 'E813:') |
| 2938 | |
| 2939 | augroup aucmd_win_test2 |
| 2940 | au! |
| 2941 | augroup END |
| 2942 | augroup! aucmd_win_test2 |
Bram Moolenaar | cf84417 | 2020-06-26 19:44:06 +0200 | [diff] [blame] | 2943 | %bwipe! |
| 2944 | endfunc |
| 2945 | |
| 2946 | " Test for trying to close the tab that has the temporary window for exeucing |
| 2947 | " an autocmd. |
| 2948 | func Test_close_autocmd_tab() |
| 2949 | edit one.txt |
| 2950 | tabnew two.txt |
| 2951 | augroup aucmd_win_test |
| 2952 | au! |
| 2953 | au BufEnter * if expand('<afile>') == 'one.txt' | tabfirst | tabonly | endif |
| 2954 | augroup END |
| 2955 | |
| 2956 | call assert_fails('doautoall BufEnter', 'E813:') |
| 2957 | |
| 2958 | tabonly |
| 2959 | augroup aucmd_win_test |
| 2960 | au! |
| 2961 | augroup END |
| 2962 | augroup! aucmd_win_test |
| 2963 | %bwipe! |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 2964 | endfunc |
| 2965 | |
Bram Moolenaar | cb1956d | 2022-01-07 15:45:18 +0000 | [diff] [blame] | 2966 | func Test_Visual_doautoall_redraw() |
| 2967 | call setline(1, ['a', 'b']) |
| 2968 | new |
| 2969 | wincmd p |
| 2970 | call feedkeys("G\<C-V>", 'txn') |
| 2971 | autocmd User Explode ++once redraw |
| 2972 | doautoall User Explode |
| 2973 | %bwipe! |
| 2974 | endfunc |
| 2975 | |
Bram Moolenaar | 6bcb877 | 2021-02-03 21:23:29 +0100 | [diff] [blame] | 2976 | " This was using freed memory. |
| 2977 | func Test_BufNew_arglocal() |
| 2978 | arglocal |
| 2979 | au BufNew * arglocal |
| 2980 | call assert_fails('drop xx', 'E1156:') |
| 2981 | |
| 2982 | au! BufNew |
| 2983 | endfunc |
| 2984 | |
Bram Moolenaar | 8ab3757 | 2021-02-03 21:56:59 +0100 | [diff] [blame] | 2985 | func Test_autocmd_closes_window() |
| 2986 | au BufNew,BufWinLeave * e %e |
| 2987 | file yyy |
| 2988 | au BufNew,BufWinLeave * ball |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 2989 | n xxx |
Bram Moolenaar | 8ab3757 | 2021-02-03 21:56:59 +0100 | [diff] [blame] | 2990 | |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 2991 | %bwipe |
Bram Moolenaar | 8ab3757 | 2021-02-03 21:56:59 +0100 | [diff] [blame] | 2992 | au! BufNew |
| 2993 | au! BufWinLeave |
| 2994 | endfunc |
| 2995 | |
Bram Moolenaar | 92bb83e | 2021-02-03 23:04:46 +0100 | [diff] [blame] | 2996 | func Test_autocmd_quit_psearch() |
| 2997 | sn aa bb |
| 2998 | augroup aucmd_win_test |
| 2999 | au! |
| 3000 | au BufEnter,BufLeave,BufNew,WinEnter,WinLeave,WinNew * if winnr('$') > 1 | q | endif |
| 3001 | augroup END |
| 3002 | ps / |
| 3003 | |
| 3004 | augroup aucmd_win_test |
| 3005 | au! |
| 3006 | augroup END |
| 3007 | endfunc |
| 3008 | |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 3009 | " Fuzzer found some strange combination that caused a crash. |
| 3010 | func Test_autocmd_normal_mess() |
Bram Moolenaar | dd07c02 | 2021-02-07 13:32:46 +0100 | [diff] [blame] | 3011 | " For unknown reason this hangs on MS-Windows |
| 3012 | CheckNotMSWindows |
| 3013 | |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 3014 | augroup aucmd_normal_test |
| 3015 | au BufLeave,BufWinLeave,BufHidden,BufUnload,BufDelete,BufWipeout * norm 7q/qc |
| 3016 | augroup END |
Bram Moolenaar | 983d83f | 2021-02-07 12:12:43 +0100 | [diff] [blame] | 3017 | call assert_fails('o4', 'E1159') |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 3018 | silent! H |
Bram Moolenaar | 983d83f | 2021-02-07 12:12:43 +0100 | [diff] [blame] | 3019 | call assert_fails('e xx', 'E1159') |
Bram Moolenaar | aad5f9d | 2021-02-06 17:30:31 +0100 | [diff] [blame] | 3020 | normal G |
| 3021 | |
| 3022 | augroup aucmd_normal_test |
| 3023 | au! |
| 3024 | augroup END |
| 3025 | endfunc |
| 3026 | |
Bram Moolenaar | 8c6951f | 2021-02-06 18:08:45 +0100 | [diff] [blame] | 3027 | func Test_autocmd_closing_cmdwin() |
Bram Moolenaar | dd07c02 | 2021-02-07 13:32:46 +0100 | [diff] [blame] | 3028 | " For unknown reason this hangs on MS-Windows |
| 3029 | CheckNotMSWindows |
| 3030 | |
Bram Moolenaar | 8c6951f | 2021-02-06 18:08:45 +0100 | [diff] [blame] | 3031 | au BufWinLeave * nested q |
| 3032 | call assert_fails("norm 7q?\n", 'E855:') |
| 3033 | |
| 3034 | au! BufWinLeave |
| 3035 | new |
| 3036 | only |
| 3037 | endfunc |
| 3038 | |
Bram Moolenaar | 2c7080b | 2021-02-06 19:19:42 +0100 | [diff] [blame] | 3039 | func Test_autocmd_vimgrep() |
| 3040 | augroup aucmd_vimgrep |
| 3041 | au QuickfixCmdPre,BufNew,BufDelete,BufReadCmd * sb |
| 3042 | au QuickfixCmdPre,BufNew,BufDelete,BufReadCmd * q9 |
| 3043 | augroup END |
Bram Moolenaar | 983d83f | 2021-02-07 12:12:43 +0100 | [diff] [blame] | 3044 | %bwipe! |
Bram Moolenaar | dd07c02 | 2021-02-07 13:32:46 +0100 | [diff] [blame] | 3045 | call assert_fails('lv ?a? foo', 'E926:') |
Bram Moolenaar | 2c7080b | 2021-02-06 19:19:42 +0100 | [diff] [blame] | 3046 | |
| 3047 | augroup aucmd_vimgrep |
| 3048 | au! |
| 3049 | augroup END |
| 3050 | endfunc |
| 3051 | |
Bram Moolenaar | 73b8b0a | 2021-08-01 14:52:32 +0200 | [diff] [blame] | 3052 | func Test_autocmd_with_block() |
| 3053 | augroup block_testing |
| 3054 | au BufReadPost *.xml { |
| 3055 | setlocal matchpairs+=<:> |
| 3056 | /<start |
| 3057 | } |
Bram Moolenaar | 63b9173 | 2021-08-05 20:40:03 +0200 | [diff] [blame] | 3058 | au CursorHold * { |
| 3059 | autocmd BufReadPre * ++once echo 'one' | echo 'two' |
| 3060 | g:gotSafeState = 77 |
| 3061 | } |
Bram Moolenaar | 73b8b0a | 2021-08-01 14:52:32 +0200 | [diff] [blame] | 3062 | augroup END |
| 3063 | |
| 3064 | let expected = "\n--- Autocommands ---\nblock_testing BufRead\n *.xml {^@ setlocal matchpairs+=<:>^@ /<start^@ }" |
| 3065 | call assert_equal(expected, execute('au BufReadPost *.xml')) |
| 3066 | |
Bram Moolenaar | 63b9173 | 2021-08-05 20:40:03 +0200 | [diff] [blame] | 3067 | doautocmd CursorHold |
| 3068 | call assert_equal(77, g:gotSafeState) |
| 3069 | unlet g:gotSafeState |
| 3070 | |
Bram Moolenaar | 73b8b0a | 2021-08-01 14:52:32 +0200 | [diff] [blame] | 3071 | augroup block_testing |
| 3072 | au! |
| 3073 | augroup END |
| 3074 | endfunc |
| 3075 | |
Christian Brabandt | db3b446 | 2021-10-16 11:58:55 +0100 | [diff] [blame] | 3076 | " Test TextChangedI and TextChanged |
| 3077 | func Test_Changed_ChangedI() |
| 3078 | new |
| 3079 | call test_override("char_avail", 1) |
| 3080 | let [g:autocmd_i, g:autocmd_n] = ['',''] |
| 3081 | |
| 3082 | func! TextChangedAutocmdI(char) |
| 3083 | let g:autocmd_{tolower(a:char)} = a:char .. b:changedtick |
| 3084 | endfunc |
| 3085 | |
| 3086 | augroup Test_TextChanged |
| 3087 | au! |
| 3088 | au TextChanged <buffer> :call TextChangedAutocmdI('N') |
| 3089 | au TextChangedI <buffer> :call TextChangedAutocmdI('I') |
| 3090 | augroup END |
| 3091 | |
| 3092 | call feedkeys("ifoo\<esc>", 'tnix') |
| 3093 | " TODO: Test test does not seem to trigger TextChanged autocommand, this |
| 3094 | " requires running Vim in a terminal window. |
| 3095 | " call assert_equal('N3', g:autocmd_n) |
| 3096 | call assert_equal('I3', g:autocmd_i) |
| 3097 | |
| 3098 | call feedkeys("yyp", 'tnix') |
| 3099 | " TODO: Test test does not seem to trigger TextChanged autocommand. |
| 3100 | " call assert_equal('N4', g:autocmd_n) |
| 3101 | call assert_equal('I3', g:autocmd_i) |
| 3102 | |
| 3103 | " CleanUp |
| 3104 | call test_override("char_avail", 0) |
| 3105 | au! TextChanged <buffer> |
| 3106 | au! TextChangedI <buffer> |
| 3107 | augroup! Test_TextChanged |
| 3108 | delfu TextChangedAutocmdI |
| 3109 | unlet! g:autocmd_i g:autocmd_n |
| 3110 | |
| 3111 | bw! |
| 3112 | endfunc |
Bram Moolenaar | 2c7080b | 2021-02-06 19:19:42 +0100 | [diff] [blame] | 3113 | |
Bram Moolenaar | 6f2465d | 2022-03-22 18:13:01 +0000 | [diff] [blame] | 3114 | func Test_closing_autocmd_window() |
| 3115 | let lines =<< trim END |
| 3116 | edit Xa.txt |
| 3117 | tabnew Xb.txt |
| 3118 | autocmd BufEnter Xa.txt unhide 1 |
| 3119 | doautoall BufEnter |
| 3120 | END |
| 3121 | call v9.CheckScriptFailure(lines, 'E814:') |
| 3122 | au! BufEnter |
| 3123 | only! |
| 3124 | bwipe Xa.txt |
| 3125 | bwipe Xb.txt |
| 3126 | endfunc |
| 3127 | |
Bram Moolenaar | 347538f | 2022-03-26 16:28:06 +0000 | [diff] [blame] | 3128 | func Test_bufwipeout_changes_window() |
| 3129 | " This should not crash, but we don't have any expectations about what |
| 3130 | " happens, changing window in BufWipeout has unpredictable results. |
| 3131 | tabedit |
| 3132 | let g:window_id = win_getid() |
| 3133 | topleft new |
| 3134 | setlocal bufhidden=wipe |
| 3135 | autocmd BufWipeout <buffer> call win_gotoid(g:window_id) |
| 3136 | tabprevious |
| 3137 | +tabclose |
| 3138 | |
| 3139 | unlet g:window_id |
| 3140 | au! BufWipeout |
| 3141 | %bwipe! |
| 3142 | endfunc |
| 3143 | |
zeertzjq | 021996f | 2022-04-10 11:44:04 +0100 | [diff] [blame] | 3144 | func Test_v_event_readonly() |
| 3145 | autocmd CompleteChanged * let v:event.width = 0 |
| 3146 | call assert_fails("normal! i\<C-X>\<C-V>", 'E46:') |
| 3147 | au! CompleteChanged |
| 3148 | |
| 3149 | autocmd DirChangedPre * let v:event.directory = '' |
| 3150 | call assert_fails('cd .', 'E46:') |
| 3151 | au! DirChangedPre |
| 3152 | |
| 3153 | autocmd ModeChanged * let v:event.new_mode = '' |
| 3154 | call assert_fails('normal! cc', 'E46:') |
| 3155 | au! ModeChanged |
| 3156 | |
| 3157 | autocmd TextYankPost * let v:event.operator = '' |
| 3158 | call assert_fails('normal! yy', 'E46:') |
| 3159 | au! TextYankPost |
| 3160 | endfunc |
| 3161 | |
Bram Moolenaar | 347538f | 2022-03-26 16:28:06 +0000 | [diff] [blame] | 3162 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 3163 | " vim: shiftwidth=2 sts=2 expandtab |