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