2016-11-14 08:19:06 -07:00
|
|
|
|
" Tests for autocommands
|
|
|
|
|
|
2018-08-14 22:13:38 -07:00
|
|
|
|
source shared.vim
|
2020-09-14 22:49:54 -07:00
|
|
|
|
source check.vim
|
|
|
|
|
source term_util.vim
|
2022-04-11 01:24:15 -07:00
|
|
|
|
source screendump.vim
|
2023-09-22 21:41:09 -07:00
|
|
|
|
source vim9.vim
|
2022-11-17 02:34:13 -07:00
|
|
|
|
source load.vim
|
2018-08-14 22:13:38 -07:00
|
|
|
|
|
2022-02-06 14:34:20 -07:00
|
|
|
|
func s:cleanup_buffers() abort
|
2017-03-21 02:15:22 -07:00
|
|
|
|
for bnr in range(1, bufnr('$'))
|
|
|
|
|
if bufloaded(bnr) && bufnr('%') != bnr
|
|
|
|
|
execute 'bd! ' . bnr
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
2018-02-01 17:51:56 -07:00
|
|
|
|
endfunc
|
2017-03-21 02:15:22 -07:00
|
|
|
|
|
2016-11-14 08:19:06 -07:00
|
|
|
|
func Test_vim_did_enter()
|
|
|
|
|
call assert_false(v:vim_did_enter)
|
|
|
|
|
|
|
|
|
|
" This script will never reach the main loop, can't check if v:vim_did_enter
|
|
|
|
|
" becomes one.
|
|
|
|
|
endfunc
|
2016-11-21 14:52:51 -07:00
|
|
|
|
|
2022-11-17 02:34:13 -07:00
|
|
|
|
" Test for the CursorHold autocmd
|
|
|
|
|
func Test_CursorHold_autocmd()
|
|
|
|
|
CheckRunVimInTerminal
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['one', 'two', 'three'], 'XoneTwoThree', 'D')
|
2022-11-17 02:34:13 -07:00
|
|
|
|
let before =<< trim END
|
|
|
|
|
set updatetime=10
|
2023-08-21 01:27:14 -07:00
|
|
|
|
au CursorHold * call writefile([line('.')], 'XCHoutput', 'a')
|
2022-11-17 02:34:13 -07:00
|
|
|
|
END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(before, 'XCHinit', 'D')
|
2023-08-21 01:27:14 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S XCHinit XoneTwoThree', {})
|
2022-11-17 15:47:51 -07:00
|
|
|
|
call term_sendkeys(buf, "G")
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call term_wait(buf, 50)
|
2022-11-17 02:34:13 -07:00
|
|
|
|
call term_sendkeys(buf, "gg")
|
|
|
|
|
call term_wait(buf)
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal(['1'], readfile('XCHoutput')[-1:-1])})
|
2022-11-17 02:34:13 -07:00
|
|
|
|
call term_sendkeys(buf, "j")
|
|
|
|
|
call term_wait(buf)
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal(['1', '2'], readfile('XCHoutput')[-2:-1])})
|
2022-11-17 02:34:13 -07:00
|
|
|
|
call term_sendkeys(buf, "j")
|
|
|
|
|
call term_wait(buf)
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal(['1', '2', '3'], readfile('XCHoutput')[-3:-1])})
|
2022-11-17 02:34:13 -07:00
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call delete('XCHoutput')
|
2022-11-17 02:34:13 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2016-12-27 15:39:21 -07:00
|
|
|
|
if has('timers')
|
2019-01-16 13:20:38 -07:00
|
|
|
|
|
2016-12-27 15:39:21 -07:00
|
|
|
|
func ExitInsertMode(id)
|
|
|
|
|
call feedkeys("\<Esc>")
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_cursorhold_insert()
|
2023-04-15 16:27:11 -07:00
|
|
|
|
" depends on timing
|
|
|
|
|
let g:test_is_flaky = 1
|
|
|
|
|
|
2017-03-21 02:19:01 -07:00
|
|
|
|
" Need to move the cursor.
|
|
|
|
|
call feedkeys("ggG", "xt")
|
|
|
|
|
|
2016-12-27 15:39:21 -07:00
|
|
|
|
let g:triggered = 0
|
|
|
|
|
au CursorHoldI * let g:triggered += 1
|
|
|
|
|
set updatetime=20
|
2021-11-23 20:58:44 -07:00
|
|
|
|
call timer_start(LoadAdjust(200), 'ExitInsertMode')
|
2016-12-27 15:39:21 -07:00
|
|
|
|
call feedkeys('a', 'x!')
|
|
|
|
|
call assert_equal(1, g:triggered)
|
2019-04-25 20:58:44 -07:00
|
|
|
|
unlet g:triggered
|
|
|
|
|
au! CursorHoldI
|
|
|
|
|
set updatetime&
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_cursorhold_insert_with_timer_interrupt()
|
2021-10-17 07:04:53 -07:00
|
|
|
|
CheckFeature job
|
2019-04-25 20:58:44 -07:00
|
|
|
|
" Need to move the cursor.
|
|
|
|
|
call feedkeys("ggG", "xt")
|
|
|
|
|
|
|
|
|
|
" Confirm the timer invoked in exit_cb of the job doesn't disturb
|
|
|
|
|
" CursorHoldI event.
|
|
|
|
|
let g:triggered = 0
|
|
|
|
|
au CursorHoldI * let g:triggered += 1
|
|
|
|
|
set updatetime=500
|
|
|
|
|
call job_start(has('win32') ? 'cmd /c echo:' : 'echo',
|
2020-01-03 20:58:09 -07:00
|
|
|
|
\ {'exit_cb': {-> timer_start(1000, 'ExitInsertMode')}})
|
2019-04-25 20:58:44 -07:00
|
|
|
|
call feedkeys('a', 'x!')
|
|
|
|
|
call assert_equal(1, g:triggered)
|
|
|
|
|
unlet g:triggered
|
2017-01-04 21:06:09 -07:00
|
|
|
|
au! CursorHoldI
|
2017-03-21 02:24:40 -07:00
|
|
|
|
set updatetime&
|
2016-12-27 15:39:21 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_cursorhold_insert_ctrl_x()
|
|
|
|
|
let g:triggered = 0
|
|
|
|
|
au CursorHoldI * let g:triggered += 1
|
|
|
|
|
set updatetime=20
|
2019-01-16 13:20:38 -07:00
|
|
|
|
call timer_start(LoadAdjust(100), 'ExitInsertMode')
|
2016-12-27 15:39:21 -07:00
|
|
|
|
" CursorHoldI does not trigger after CTRL-X
|
|
|
|
|
call feedkeys("a\<C-X>", 'x!')
|
|
|
|
|
call assert_equal(0, g:triggered)
|
2019-04-25 20:58:44 -07:00
|
|
|
|
unlet g:triggered
|
2017-01-04 21:06:09 -07:00
|
|
|
|
au! CursorHoldI
|
2017-03-21 02:24:40 -07:00
|
|
|
|
set updatetime&
|
2016-12-27 15:39:21 -07:00
|
|
|
|
endfunc
|
2019-05-12 06:03:59 -07:00
|
|
|
|
|
2023-09-27 03:58:43 -07:00
|
|
|
|
func Test_cursorhold_insert_ctrl_g_U()
|
|
|
|
|
au CursorHoldI * :
|
|
|
|
|
set updatetime=20
|
|
|
|
|
new
|
|
|
|
|
call timer_start(100, { -> feedkeys("\<Left>foo\<Esc>", 't') })
|
|
|
|
|
call feedkeys("i()\<C-g>U", 'tx!')
|
|
|
|
|
sleep 200m
|
|
|
|
|
call assert_equal('(foo)', getline(1))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal('', getline(1))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
au! CursorHoldI
|
|
|
|
|
set updatetime&
|
|
|
|
|
endfunc
|
|
|
|
|
|
2019-05-12 06:03:59 -07:00
|
|
|
|
func Test_OptionSet_modeline()
|
2021-03-26 20:06:39 -07:00
|
|
|
|
CheckFunction test_override
|
2019-05-12 06:03:59 -07:00
|
|
|
|
call test_override('starting', 1)
|
|
|
|
|
au! OptionSet
|
|
|
|
|
augroup set_tabstop
|
|
|
|
|
au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
|
|
|
|
|
augroup END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline', 'D')
|
2019-05-12 06:03:59 -07:00
|
|
|
|
set modeline
|
|
|
|
|
let v:errmsg = ''
|
|
|
|
|
call assert_fails('split XoptionsetModeline', 'E12:')
|
|
|
|
|
call assert_equal(7, &ts)
|
|
|
|
|
call assert_equal('', v:errmsg)
|
|
|
|
|
|
|
|
|
|
augroup set_tabstop
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
bwipe!
|
|
|
|
|
set ts&
|
|
|
|
|
call test_override('starting', 0)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
endif "has('timers')
|
2016-11-21 14:52:51 -07:00
|
|
|
|
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_bufunload()
|
2016-12-27 15:39:21 -07:00
|
|
|
|
augroup test_bufunload_group
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufUnload * call add(s:li, "bufunload")
|
|
|
|
|
autocmd BufDelete * call add(s:li, "bufdelete")
|
|
|
|
|
autocmd BufWipeout * call add(s:li, "bufwipeout")
|
|
|
|
|
augroup END
|
2016-11-21 14:52:51 -07:00
|
|
|
|
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let s:li = []
|
2016-12-27 15:39:21 -07:00
|
|
|
|
new
|
|
|
|
|
setlocal bufhidden=
|
|
|
|
|
bunload
|
|
|
|
|
call assert_equal(["bufunload", "bufdelete"], s:li)
|
|
|
|
|
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let s:li = []
|
2016-12-27 15:39:21 -07:00
|
|
|
|
new
|
|
|
|
|
setlocal bufhidden=delete
|
|
|
|
|
bunload
|
|
|
|
|
call assert_equal(["bufunload", "bufdelete"], s:li)
|
|
|
|
|
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let s:li = []
|
2016-12-27 15:39:21 -07:00
|
|
|
|
new
|
|
|
|
|
setlocal bufhidden=unload
|
|
|
|
|
bwipeout
|
|
|
|
|
call assert_equal(["bufunload", "bufdelete", "bufwipeout"], s:li)
|
2016-11-21 14:52:51 -07:00
|
|
|
|
|
2017-01-04 21:06:09 -07:00
|
|
|
|
au! test_bufunload_group
|
2016-12-27 15:39:21 -07:00
|
|
|
|
augroup! test_bufunload_group
|
2016-11-21 14:52:51 -07:00
|
|
|
|
endfunc
|
2017-01-04 21:06:09 -07:00
|
|
|
|
|
2017-01-07 07:56:51 -07:00
|
|
|
|
" SEGV occurs in older versions. (At least 7.4.2005 or older)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufunload_with_tabnext()
|
2017-01-07 07:56:51 -07:00
|
|
|
|
tabedit
|
|
|
|
|
tabfirst
|
|
|
|
|
|
|
|
|
|
augroup test_autocmd_bufunload_with_tabnext_group
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufUnload <buffer> tabnext
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
quit
|
|
|
|
|
call assert_equal(2, tabpagenr('$'))
|
|
|
|
|
|
2017-03-20 06:01:22 -07:00
|
|
|
|
autocmd! test_autocmd_bufunload_with_tabnext_group
|
2017-01-07 07:56:51 -07:00
|
|
|
|
augroup! test_autocmd_bufunload_with_tabnext_group
|
|
|
|
|
tablast
|
|
|
|
|
quit
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-10-05 06:18:13 -07:00
|
|
|
|
func Test_argdelete_in_next()
|
|
|
|
|
au BufNew,BufEnter,BufLeave,BufWinEnter * argdel
|
|
|
|
|
call assert_fails('next a b', 'E1156:')
|
|
|
|
|
au! BufNew,BufEnter,BufLeave,BufWinEnter *
|
|
|
|
|
endfunc
|
|
|
|
|
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufwinleave_with_tabfirst()
|
2017-03-21 02:39:24 -07:00
|
|
|
|
tabedit
|
|
|
|
|
augroup sample
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufWinLeave <buffer> tabfirst
|
|
|
|
|
augroup END
|
|
|
|
|
call setline(1, ['a', 'b', 'c'])
|
|
|
|
|
edit! a.txt
|
|
|
|
|
tabclose
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-20 06:01:22 -07:00
|
|
|
|
" SEGV occurs in older versions. (At least 7.4.2321 or older)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufunload_avoiding_SEGV_01()
|
2017-03-20 06:01:22 -07:00
|
|
|
|
split aa.txt
|
|
|
|
|
let lastbuf = bufnr('$')
|
|
|
|
|
|
|
|
|
|
augroup test_autocmd_bufunload
|
|
|
|
|
autocmd!
|
|
|
|
|
exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!'
|
|
|
|
|
augroup END
|
|
|
|
|
|
2022-11-11 02:50:52 -07:00
|
|
|
|
call assert_fails('edit bb.txt', 'E937:')
|
2017-03-20 06:01:22 -07:00
|
|
|
|
|
|
|
|
|
autocmd! test_autocmd_bufunload
|
|
|
|
|
augroup! test_autocmd_bufunload
|
|
|
|
|
bwipe! aa.txt
|
|
|
|
|
bwipe! bb.txt
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" SEGV occurs in older versions. (At least 7.4.2321 or older)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufunload_avoiding_SEGV_02()
|
2017-03-20 06:01:22 -07:00
|
|
|
|
setlocal buftype=nowrite
|
|
|
|
|
let lastbuf = bufnr('$')
|
|
|
|
|
|
|
|
|
|
augroup test_autocmd_bufunload
|
|
|
|
|
autocmd!
|
|
|
|
|
exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!'
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
normal! i1
|
|
|
|
|
call assert_fails('edit a.txt', 'E517:')
|
|
|
|
|
|
|
|
|
|
autocmd! test_autocmd_bufunload
|
|
|
|
|
augroup! test_autocmd_bufunload
|
|
|
|
|
bwipe! a.txt
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-06-23 19:46:02 -07:00
|
|
|
|
func Test_autocmd_dummy_wipeout()
|
|
|
|
|
" prepare files
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile([''], 'Xdummywipetest1.txt', 'D')
|
|
|
|
|
call writefile([''], 'Xdummywipetest2.txt', 'D')
|
2021-06-23 19:46:02 -07:00
|
|
|
|
augroup test_bufunload_group
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufUnload * call add(s:li, "bufunload")
|
|
|
|
|
autocmd BufDelete * call add(s:li, "bufdelete")
|
|
|
|
|
autocmd BufWipeout * call add(s:li, "bufwipeout")
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
let s:li = []
|
|
|
|
|
split Xdummywipetest1.txt
|
|
|
|
|
silent! vimgrep /notmatched/ Xdummywipetest*
|
|
|
|
|
call assert_equal(["bufunload", "bufwipeout"], s:li)
|
|
|
|
|
|
|
|
|
|
bwipeout
|
|
|
|
|
au! test_bufunload_group
|
|
|
|
|
augroup! test_bufunload_group
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-01-08 06:05:41 -07:00
|
|
|
|
func Test_win_tab_autocmd()
|
|
|
|
|
let g:record = []
|
|
|
|
|
|
|
|
|
|
augroup testing
|
|
|
|
|
au WinNew * call add(g:record, 'WinNew')
|
2021-11-17 19:11:09 -07:00
|
|
|
|
au WinClosed * call add(g:record, 'WinClosed')
|
2017-01-08 06:05:41 -07:00
|
|
|
|
au WinEnter * call add(g:record, 'WinEnter')
|
|
|
|
|
au WinLeave * call add(g:record, 'WinLeave')
|
|
|
|
|
au TabNew * call add(g:record, 'TabNew')
|
2017-01-08 08:12:52 -07:00
|
|
|
|
au TabClosed * call add(g:record, 'TabClosed')
|
2017-01-08 06:05:41 -07:00
|
|
|
|
au TabEnter * call add(g:record, 'TabEnter')
|
|
|
|
|
au TabLeave * call add(g:record, 'TabLeave')
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
split
|
|
|
|
|
tabnew
|
|
|
|
|
close
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'WinLeave', 'WinNew', 'WinEnter',
|
|
|
|
|
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
2021-11-17 19:11:09 -07:00
|
|
|
|
\ 'WinLeave', 'TabLeave', 'WinClosed', 'TabClosed', 'WinEnter', 'TabEnter',
|
|
|
|
|
\ 'WinLeave', 'WinClosed', 'WinEnter'
|
2017-01-08 06:05:41 -07:00
|
|
|
|
\ ], g:record)
|
|
|
|
|
|
2017-01-08 08:12:52 -07:00
|
|
|
|
let g:record = []
|
|
|
|
|
tabnew somefile
|
|
|
|
|
tabnext
|
|
|
|
|
bwipe somefile
|
|
|
|
|
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
|
|
|
|
\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
|
2021-11-17 19:11:09 -07:00
|
|
|
|
\ 'WinClosed', 'TabClosed'
|
2017-01-08 08:12:52 -07:00
|
|
|
|
\ ], g:record)
|
|
|
|
|
|
2017-01-08 06:05:41 -07:00
|
|
|
|
augroup testing
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
unlet g:record
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
func Test_WinResized()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set scrolloff=0
|
|
|
|
|
call setline(1, ['111', '222'])
|
|
|
|
|
vnew
|
|
|
|
|
call setline(1, ['aaa', 'bbb'])
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['foo', 'bar'])
|
|
|
|
|
|
|
|
|
|
let g:resized = 0
|
|
|
|
|
au WinResized * let g:resized += 1
|
|
|
|
|
|
|
|
|
|
func WriteResizedEvent()
|
|
|
|
|
call writefile([json_encode(v:event)], 'XresizeEvent')
|
|
|
|
|
endfunc
|
|
|
|
|
au WinResized * call WriteResizedEvent()
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xtest_winresized', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winresized', {'rows': 10})
|
|
|
|
|
|
|
|
|
|
" redraw now to avoid a redraw after the :echo command
|
|
|
|
|
call term_sendkeys(buf, ":redraw!\<CR>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":echo g:resized\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^0$', term_getline(buf, 10))}, 1000)
|
|
|
|
|
|
|
|
|
|
" increase window height, two windows will be reported
|
|
|
|
|
call term_sendkeys(buf, "\<C-W>+")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
call term_sendkeys(buf, ":echo g:resized\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^1$', term_getline(buf, 10))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XresizeEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'windows': [1002, 1001],
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
" increase window width, three windows will be reported
|
|
|
|
|
call term_sendkeys(buf, "\<C-W>>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
call term_sendkeys(buf, ":echo g:resized\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^2$', term_getline(buf, 10))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XresizeEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'windows': [1002, 1001, 1000],
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
call delete('XresizeEvent')
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-11 01:24:15 -07:00
|
|
|
|
func Test_WinScrolled()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
2022-04-12 04:16:47 -07:00
|
|
|
|
set nowrap scrolloff=0
|
|
|
|
|
for ii in range(1, 18)
|
|
|
|
|
call setline(ii, repeat(nr2char(96 + ii), ii * 2))
|
|
|
|
|
endfor
|
|
|
|
|
let win_id = win_getid()
|
|
|
|
|
let g:matched = v:false
|
2022-11-22 18:54:48 -07:00
|
|
|
|
func WriteScrollEvent()
|
|
|
|
|
call writefile([json_encode(v:event)], 'XscrollEvent')
|
|
|
|
|
endfunc
|
2022-04-12 04:16:47 -07:00
|
|
|
|
execute 'au WinScrolled' win_id 'let g:matched = v:true'
|
|
|
|
|
let g:scrolled = 0
|
|
|
|
|
au WinScrolled * let g:scrolled += 1
|
|
|
|
|
au WinScrolled * let g:amatch = str2nr(expand('<amatch>'))
|
|
|
|
|
au WinScrolled * let g:afile = str2nr(expand('<afile>'))
|
2022-11-22 18:54:48 -07:00
|
|
|
|
au WinScrolled * call WriteScrollEvent()
|
2022-04-11 01:24:15 -07:00
|
|
|
|
END
|
2022-11-19 17:38:46 -07:00
|
|
|
|
call writefile(lines, 'Xtest_winscrolled', 'D')
|
2022-04-11 01:24:15 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^0 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
" Scroll left/right in Normal mode.
|
|
|
|
|
call term_sendkeys(buf, "zlzh:echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
2022-12-07 03:34:39 -07:00
|
|
|
|
\ 'all': {'leftcol': 1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': -1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
|
2022-11-22 18:54:48 -07:00
|
|
|
|
\ }, event)
|
|
|
|
|
|
2022-04-11 01:24:15 -07:00
|
|
|
|
" Scroll up/down in Normal mode.
|
|
|
|
|
call term_sendkeys(buf, "\<c-e>\<c-y>:echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^4 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
2022-12-07 03:34:39 -07:00
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
|
2022-11-22 18:54:48 -07:00
|
|
|
|
\ }, event)
|
|
|
|
|
|
2022-04-11 01:24:15 -07:00
|
|
|
|
" Scroll up/down in Insert mode.
|
|
|
|
|
call term_sendkeys(buf, "Mi\<c-x>\<c-e>\<Esc>i\<c-x>\<c-y>\<Esc>")
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^6 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
2022-12-07 03:34:39 -07:00
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
|
2022-11-22 18:54:48 -07:00
|
|
|
|
\ }, event)
|
|
|
|
|
|
2022-04-11 01:24:15 -07:00
|
|
|
|
" Scroll the window horizontally to focus the last letter of the third line
|
|
|
|
|
" containing only six characters. Moving to the previous and shorter lines
|
|
|
|
|
" should trigger another autocommand as Vim has to make them visible.
|
|
|
|
|
call term_sendkeys(buf, "5zl2k")
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^8 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
2022-12-07 03:34:39 -07:00
|
|
|
|
\ 'all': {'leftcol': 5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': -5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
|
2022-11-22 18:54:48 -07:00
|
|
|
|
\ }, event)
|
|
|
|
|
|
2022-04-11 01:24:15 -07:00
|
|
|
|
" Ensure the command was triggered for the specified window ID.
|
|
|
|
|
call term_sendkeys(buf, ":echo g:matched\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
" Ensure the expansion of <amatch> and <afile> matches the window ID.
|
|
|
|
|
call term_sendkeys(buf, ":echo g:amatch == win_id && g:afile == win_id\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
2022-11-22 18:54:48 -07:00
|
|
|
|
call delete('XscrollEvent')
|
2022-04-11 01:24:15 -07:00
|
|
|
|
call StopVimInTerminal(buf)
|
2022-11-19 17:38:46 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_WinScrolled_mouse()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set nowrap scrolloff=0
|
|
|
|
|
set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard=
|
|
|
|
|
call setline(1, ['foo']->repeat(32))
|
|
|
|
|
split
|
|
|
|
|
let g:scrolled = 0
|
|
|
|
|
au WinScrolled * let g:scrolled += 1
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_mouse', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_mouse', {'rows': 10})
|
|
|
|
|
|
|
|
|
|
" With the upper split focused, send a scroll-down event to the unfocused one.
|
|
|
|
|
call test_setmouse(7, 1)
|
|
|
|
|
call term_sendkeys(buf, "\<ScrollWheelDown>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^1', term_getline(buf, 10))}, 1000)
|
|
|
|
|
|
|
|
|
|
" Again, but this time while we're in insert mode.
|
|
|
|
|
call term_sendkeys(buf, "i\<ScrollWheelDown>\<Esc>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^2', term_getline(buf, 10))}, 1000)
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
2022-04-11 01:24:15 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-12 04:16:47 -07:00
|
|
|
|
func Test_WinScrolled_close_curwin()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set nowrap scrolloff=0
|
|
|
|
|
call setline(1, ['aaa', 'bbb'])
|
|
|
|
|
vsplit
|
|
|
|
|
au WinScrolled * close
|
|
|
|
|
au VimLeave * call writefile(['123456'], 'Xtestout')
|
|
|
|
|
END
|
2022-11-19 17:38:46 -07:00
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_close_curwin', 'D')
|
2022-04-12 04:16:47 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_close_curwin', {'rows': 6})
|
|
|
|
|
|
|
|
|
|
" This was using freed memory
|
|
|
|
|
call term_sendkeys(buf, "\<C-E>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
|
2022-11-19 17:38:46 -07:00
|
|
|
|
" check the startup script finished to the end
|
2022-04-12 04:16:47 -07:00
|
|
|
|
call assert_equal(['123456'], readfile('Xtestout'))
|
|
|
|
|
call delete('Xtestout')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-11-19 17:38:46 -07:00
|
|
|
|
func Test_WinScrolled_once_only()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set cmdheight=2
|
|
|
|
|
call setline(1, ['aaa', 'bbb'])
|
|
|
|
|
let trigger_count = 0
|
|
|
|
|
func ShowInfo(id)
|
|
|
|
|
echo g:trigger_count g:winid winlayout()
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
vsplit
|
|
|
|
|
split
|
|
|
|
|
" use a timer to show the info after a redraw
|
|
|
|
|
au WinScrolled * let trigger_count += 1 | let winid = expand('<amatch>') | call timer_start(100, 'ShowInfo')
|
|
|
|
|
wincmd j
|
|
|
|
|
wincmd l
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_once', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_once', #{rows: 10, cols: 60, statusoff: 2})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<C-E>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_winscrolled_once_only_1', {})
|
|
|
|
|
|
2022-11-20 06:11:57 -07:00
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Check that WinScrolled is not triggered immediately when defined and there
|
|
|
|
|
" are split windows.
|
|
|
|
|
func Test_WinScrolled_not_when_defined()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
call setline(1, ['aaa', 'bbb'])
|
|
|
|
|
echo 'nothing happened'
|
|
|
|
|
func ShowTriggered(id)
|
|
|
|
|
echo 'triggered'
|
|
|
|
|
endfunc
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_not', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_not', #{rows: 10, cols: 60, statusoff: 2})
|
|
|
|
|
call term_sendkeys(buf, ":split\<CR>")
|
|
|
|
|
call TermWait(buf)
|
|
|
|
|
" use a timer to show the message after redrawing
|
|
|
|
|
call term_sendkeys(buf, ":au WinScrolled * call timer_start(100, 'ShowTriggered')\<CR>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_1', {})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<C-E>")
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_2', {})
|
|
|
|
|
|
2022-11-19 17:38:46 -07:00
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-28 15:16:20 -07:00
|
|
|
|
func Test_WinScrolled_long_wrapped()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set scrolloff=0
|
|
|
|
|
let height = winheight(0)
|
|
|
|
|
let width = winwidth(0)
|
|
|
|
|
let g:scrolled = 0
|
|
|
|
|
au WinScrolled * let g:scrolled += 1
|
|
|
|
|
call setline(1, repeat('foo', height * width))
|
|
|
|
|
call cursor(1, height * width)
|
|
|
|
|
END
|
2022-11-19 17:38:46 -07:00
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_long_wrapped', 'D')
|
2022-08-28 15:16:20 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^0 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, 'gj')
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^1 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, '0')
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, '$')
|
|
|
|
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000)
|
2022-12-07 03:34:39 -07:00
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_WinScrolled_diff()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set diffopt+=foldcolumn:0
|
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
|
|
|
|
|
vnew
|
|
|
|
|
call setline(1, ['d', 'e', 'f', 'g', 'h', 'i'])
|
|
|
|
|
windo diffthis
|
|
|
|
|
func WriteScrollEvent()
|
|
|
|
|
call writefile([json_encode(v:event)], 'XscrollEvent')
|
|
|
|
|
endfunc
|
|
|
|
|
au WinScrolled * call WriteScrollEvent()
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'Xtest_winscrolled_diff', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_diff', {'rows': 8})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<C-E>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^d', term_getline(buf, 3))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -1, 'width': 0, 'height': 0, 'skipcol': 0}
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "2\<C-E>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^f', term_getline(buf, 3))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 2, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -2, 'width': 0, 'height': 0, 'skipcol': 0}
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<C-E>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^g', term_getline(buf, 3))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1001': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "2\<C-Y>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^e', term_getline(buf, 3))}, 1000)
|
|
|
|
|
|
|
|
|
|
let event = readfile('XscrollEvent')[0]->json_decode()
|
|
|
|
|
call assert_equal({
|
|
|
|
|
\ 'all': {'leftcol': 0, 'topline': 3, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1000': {'leftcol': 0, 'topline': -2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
|
|
|
|
|
\ '1001': {'leftcol': 0, 'topline': -1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0}
|
|
|
|
|
\ }, event)
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
2023-01-17 15:27:26 -07:00
|
|
|
|
call delete('XscrollEvent')
|
2022-08-28 15:16:20 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2021-11-17 19:11:09 -07:00
|
|
|
|
func Test_WinClosed()
|
|
|
|
|
" Test that the pattern is matched against the closed window's ID, and both
|
|
|
|
|
" <amatch> and <afile> are set to it.
|
|
|
|
|
new
|
|
|
|
|
let winid = win_getid()
|
|
|
|
|
let g:matched = v:false
|
|
|
|
|
augroup test-WinClosed
|
|
|
|
|
autocmd!
|
|
|
|
|
execute 'autocmd WinClosed' winid 'let g:matched = v:true'
|
|
|
|
|
autocmd WinClosed * let g:amatch = str2nr(expand('<amatch>'))
|
|
|
|
|
autocmd WinClosed * let g:afile = str2nr(expand('<afile>'))
|
|
|
|
|
augroup END
|
|
|
|
|
close
|
|
|
|
|
call assert_true(g:matched)
|
|
|
|
|
call assert_equal(winid, g:amatch)
|
|
|
|
|
call assert_equal(winid, g:afile)
|
|
|
|
|
|
|
|
|
|
" Test that WinClosed is non-recursive.
|
|
|
|
|
new
|
|
|
|
|
new
|
|
|
|
|
call assert_equal(3, winnr('$'))
|
|
|
|
|
let g:triggered = 0
|
|
|
|
|
augroup test-WinClosed
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd WinClosed * let g:triggered += 1
|
|
|
|
|
autocmd WinClosed * 2 wincmd c
|
|
|
|
|
augroup END
|
|
|
|
|
close
|
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
|
call assert_equal(1, g:triggered)
|
|
|
|
|
|
|
|
|
|
autocmd! test-WinClosed
|
|
|
|
|
augroup! test-WinClosed
|
|
|
|
|
unlet g:matched
|
|
|
|
|
unlet g:amatch
|
|
|
|
|
unlet g:afile
|
|
|
|
|
unlet g:triggered
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-07 16:57:50 -07:00
|
|
|
|
func Test_WinClosed_throws()
|
|
|
|
|
vnew
|
|
|
|
|
let bnr = bufnr()
|
|
|
|
|
call assert_equal(1, bufloaded(bnr))
|
|
|
|
|
augroup test-WinClosed
|
2022-04-07 16:58:34 -07:00
|
|
|
|
autocmd WinClosed * throw 'foo'
|
|
|
|
|
augroup END
|
|
|
|
|
try
|
|
|
|
|
close
|
|
|
|
|
catch /.*/
|
|
|
|
|
endtry
|
|
|
|
|
call assert_equal(0, bufloaded(bnr))
|
|
|
|
|
|
|
|
|
|
autocmd! test-WinClosed
|
|
|
|
|
augroup! test-WinClosed
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_WinClosed_throws_with_tabs()
|
|
|
|
|
tabnew
|
|
|
|
|
let bnr = bufnr()
|
|
|
|
|
call assert_equal(1, bufloaded(bnr))
|
|
|
|
|
augroup test-WinClosed
|
2022-04-07 16:57:50 -07:00
|
|
|
|
autocmd WinClosed * throw 'foo'
|
|
|
|
|
augroup END
|
|
|
|
|
try
|
|
|
|
|
close
|
|
|
|
|
catch /.*/
|
|
|
|
|
endtry
|
|
|
|
|
call assert_equal(0, bufloaded(bnr))
|
|
|
|
|
|
|
|
|
|
autocmd! test-WinClosed
|
|
|
|
|
augroup! test-WinClosed
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-09-22 16:14:32 -07:00
|
|
|
|
" This used to trigger WinClosed twice for the same window, and the window's
|
|
|
|
|
" buffer was NULL in the second autocommand.
|
|
|
|
|
func Test_WinClosed_switch_tab()
|
|
|
|
|
edit Xa
|
|
|
|
|
split Xb
|
|
|
|
|
split Xc
|
|
|
|
|
tab split
|
|
|
|
|
new
|
|
|
|
|
augroup test-WinClosed
|
|
|
|
|
autocmd WinClosed * tabprev | bwipe!
|
|
|
|
|
augroup END
|
|
|
|
|
close
|
|
|
|
|
" Check that the tabline has been fully removed
|
|
|
|
|
call assert_equal([1, 1], win_screenpos(0))
|
|
|
|
|
|
|
|
|
|
autocmd! test-WinClosed
|
|
|
|
|
augroup! test-WinClosed
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-03-09 16:03:36 -07:00
|
|
|
|
" This used to trigger WinClosed twice for the same window, and the window's
|
|
|
|
|
" buffer was NULL in the second autocommand.
|
|
|
|
|
func Test_WinClosed_BufUnload_close_other()
|
|
|
|
|
tabnew
|
|
|
|
|
let g:tab = tabpagenr()
|
|
|
|
|
let g:buf = bufnr()
|
|
|
|
|
new
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
augroup test-WinClosed
|
|
|
|
|
autocmd BufUnload * ++once exe g:buf .. 'bwipe!'
|
|
|
|
|
autocmd WinClosed * call tabpagebuflist(g:tab)
|
|
|
|
|
augroup END
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
unlet g:tab
|
|
|
|
|
unlet g:buf
|
|
|
|
|
autocmd! test-WinClosed
|
|
|
|
|
augroup! test-WinClosed
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-01-04 21:06:09 -07:00
|
|
|
|
func s:AddAnAutocmd()
|
|
|
|
|
augroup vimBarTest
|
|
|
|
|
au BufReadCmd * echo 'hello'
|
|
|
|
|
augroup END
|
|
|
|
|
call assert_equal(3, len(split(execute('au vimBarTest'), "\n")))
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_early_bar()
|
|
|
|
|
" test that a bar is recognized before the {event}
|
|
|
|
|
call s:AddAnAutocmd()
|
2022-11-07 04:50:51 -07:00
|
|
|
|
augroup vimBarTest | au! | let done = 77 | augroup END
|
2017-01-04 21:06:09 -07:00
|
|
|
|
call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
|
2022-11-07 04:50:51 -07:00
|
|
|
|
call assert_equal(77, done)
|
2017-01-04 21:06:09 -07:00
|
|
|
|
|
|
|
|
|
call s:AddAnAutocmd()
|
2022-11-07 04:50:51 -07:00
|
|
|
|
augroup vimBarTest| au!| let done = 88 | augroup END
|
2017-01-04 21:06:09 -07:00
|
|
|
|
call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
|
2022-11-07 04:50:51 -07:00
|
|
|
|
call assert_equal(88, done)
|
2017-01-04 21:06:09 -07:00
|
|
|
|
|
|
|
|
|
" test that a bar is recognized after the {event}
|
|
|
|
|
call s:AddAnAutocmd()
|
2022-11-07 04:50:51 -07:00
|
|
|
|
augroup vimBarTest| au!BufReadCmd| let done = 99 | augroup END
|
2017-01-04 21:06:09 -07:00
|
|
|
|
call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
|
2022-11-07 04:50:51 -07:00
|
|
|
|
call assert_equal(99, done)
|
2017-01-04 21:06:09 -07:00
|
|
|
|
|
|
|
|
|
" test that a bar is recognized after the {group}
|
|
|
|
|
call s:AddAnAutocmd()
|
|
|
|
|
au! vimBarTest|echo 'hello'
|
|
|
|
|
call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
|
|
|
|
|
endfunc
|
2017-01-08 17:41:45 -07:00
|
|
|
|
|
2017-01-08 20:00:56 -07:00
|
|
|
|
func RemoveGroup()
|
|
|
|
|
autocmd! StartOK
|
|
|
|
|
augroup! StartOK
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-01-08 17:41:45 -07:00
|
|
|
|
func Test_augroup_warning()
|
|
|
|
|
augroup TheWarning
|
|
|
|
|
au VimEnter * echo 'entering'
|
|
|
|
|
augroup END
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_match("TheWarning.*VimEnter", execute('au VimEnter'))
|
2017-01-08 17:41:45 -07:00
|
|
|
|
redir => res
|
|
|
|
|
augroup! TheWarning
|
|
|
|
|
redir END
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_match("W19:", res)
|
|
|
|
|
call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
|
2017-01-08 17:41:45 -07:00
|
|
|
|
|
|
|
|
|
" check "Another" does not take the pace of the deleted entry
|
|
|
|
|
augroup Another
|
|
|
|
|
augroup END
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
|
2017-03-21 02:24:40 -07:00
|
|
|
|
augroup! Another
|
2017-01-08 20:00:56 -07:00
|
|
|
|
|
|
|
|
|
" no warning for postpone aucmd delete
|
|
|
|
|
augroup StartOK
|
|
|
|
|
au VimEnter * call RemoveGroup()
|
|
|
|
|
augroup END
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_match("StartOK.*VimEnter", execute('au VimEnter'))
|
2017-01-08 20:00:56 -07:00
|
|
|
|
redir => res
|
|
|
|
|
doautocmd VimEnter
|
|
|
|
|
redir END
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_notmatch("W19:", res)
|
2017-01-08 21:15:10 -07:00
|
|
|
|
au! VimEnter
|
2022-11-04 21:26:17 -07:00
|
|
|
|
|
|
|
|
|
call assert_fails('augroup!', 'E471:')
|
2017-01-08 17:41:45 -07:00
|
|
|
|
endfunc
|
2017-01-08 21:01:50 -07:00
|
|
|
|
|
2018-08-14 07:18:08 -07:00
|
|
|
|
func Test_BufReadCmdHelp()
|
|
|
|
|
" This used to cause access to free memory
|
|
|
|
|
au BufReadCmd * e +h
|
|
|
|
|
help
|
|
|
|
|
|
|
|
|
|
au! BufReadCmd
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_BufReadCmdHelpJump()
|
|
|
|
|
" This used to cause access to free memory
|
|
|
|
|
au BufReadCmd * e +h{
|
2018-08-14 15:19:56 -07:00
|
|
|
|
" } to fix highlighting
|
|
|
|
|
call assert_fails('help', 'E434:')
|
2018-08-14 07:18:08 -07:00
|
|
|
|
|
|
|
|
|
au! BufReadCmd
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-26 07:39:13 -07:00
|
|
|
|
" BufReadCmd is triggered for a "nofile" buffer. Check all values.
|
2022-08-26 04:04:20 -07:00
|
|
|
|
func Test_BufReadCmdNofile()
|
2022-08-26 07:39:13 -07:00
|
|
|
|
for val in ['nofile',
|
|
|
|
|
\ 'nowrite',
|
|
|
|
|
\ 'acwrite',
|
|
|
|
|
\ 'quickfix',
|
|
|
|
|
\ 'help',
|
2022-09-22 05:18:06 -07:00
|
|
|
|
"\ 'terminal',
|
2022-08-26 07:39:13 -07:00
|
|
|
|
\ 'prompt',
|
2022-09-22 05:18:06 -07:00
|
|
|
|
"\ 'popup',
|
2022-08-26 07:39:13 -07:00
|
|
|
|
\ ]
|
|
|
|
|
new somefile
|
|
|
|
|
exe 'set buftype=' .. val
|
|
|
|
|
au BufReadCmd somefile call setline(1, 'triggered')
|
|
|
|
|
edit
|
|
|
|
|
call assert_equal('triggered', getline(1))
|
|
|
|
|
|
|
|
|
|
au! BufReadCmd
|
|
|
|
|
bwipe!
|
|
|
|
|
endfor
|
2022-08-26 04:04:20 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2017-01-08 21:01:50 -07:00
|
|
|
|
func Test_augroup_deleted()
|
2017-01-08 21:15:10 -07:00
|
|
|
|
" This caused a crash before E936 was introduced
|
2017-01-08 21:01:50 -07:00
|
|
|
|
augroup x
|
2017-01-08 21:15:10 -07:00
|
|
|
|
call assert_fails('augroup! x', 'E936:')
|
|
|
|
|
au VimEnter * echo
|
|
|
|
|
augroup end
|
2017-01-08 21:01:50 -07:00
|
|
|
|
augroup! x
|
2021-04-12 22:39:24 -07:00
|
|
|
|
call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
|
2017-01-08 21:15:10 -07:00
|
|
|
|
au! VimEnter
|
2017-01-08 21:01:50 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-20 06:01:22 -07:00
|
|
|
|
" Tests for autocommands on :close command.
|
|
|
|
|
" This used to be in test13.
|
|
|
|
|
func Test_three_windows()
|
2017-03-21 02:15:22 -07:00
|
|
|
|
" Clean up buffers, because in some cases this function fails.
|
|
|
|
|
call s:cleanup_buffers()
|
|
|
|
|
|
2017-03-20 06:01:22 -07:00
|
|
|
|
" Write three files and open them, each in a window.
|
|
|
|
|
" Then go to next window, with autocommand that deletes the previous one.
|
|
|
|
|
" Do this twice, writing the file.
|
|
|
|
|
e! Xtestje1
|
|
|
|
|
call setline(1, 'testje1')
|
|
|
|
|
w
|
|
|
|
|
sp Xtestje2
|
|
|
|
|
call setline(1, 'testje2')
|
|
|
|
|
w
|
|
|
|
|
sp Xtestje3
|
|
|
|
|
call setline(1, 'testje3')
|
|
|
|
|
w
|
|
|
|
|
wincmd w
|
|
|
|
|
au WinLeave Xtestje2 bwipe
|
|
|
|
|
wincmd w
|
|
|
|
|
call assert_equal('Xtestje1', expand('%'))
|
|
|
|
|
|
|
|
|
|
au WinLeave Xtestje1 bwipe Xtestje3
|
|
|
|
|
close
|
|
|
|
|
call assert_equal('Xtestje1', expand('%'))
|
|
|
|
|
|
|
|
|
|
" Test deleting the buffer on a Unload event. If this goes wrong there
|
|
|
|
|
" will be the ATTENTION prompt.
|
|
|
|
|
e Xtestje1
|
|
|
|
|
au!
|
|
|
|
|
au! BufUnload Xtestje1 bwipe
|
|
|
|
|
call assert_fails('e Xtestje3', 'E937:')
|
|
|
|
|
call assert_equal('Xtestje3', expand('%'))
|
|
|
|
|
|
|
|
|
|
e Xtestje2
|
|
|
|
|
sp Xtestje1
|
|
|
|
|
call assert_fails('e', 'E937:')
|
2022-07-05 02:31:49 -07:00
|
|
|
|
call assert_equal('Xtestje1', expand('%'))
|
2017-03-20 06:01:22 -07:00
|
|
|
|
|
|
|
|
|
" Test changing buffers in a BufWipeout autocommand. If this goes wrong
|
|
|
|
|
" there are ml_line errors and/or a Crash.
|
|
|
|
|
au!
|
|
|
|
|
only
|
|
|
|
|
e Xanother
|
|
|
|
|
e Xtestje1
|
|
|
|
|
bwipe Xtestje2
|
|
|
|
|
bwipe Xtestje3
|
|
|
|
|
au BufWipeout Xtestje1 buf Xtestje1
|
|
|
|
|
bwipe
|
|
|
|
|
call assert_equal('Xanother', expand('%'))
|
|
|
|
|
|
|
|
|
|
only
|
2017-03-21 17:19:13 -07:00
|
|
|
|
|
2017-03-20 06:01:22 -07:00
|
|
|
|
help
|
|
|
|
|
wincmd w
|
|
|
|
|
1quit
|
|
|
|
|
call assert_equal('Xanother', expand('%'))
|
|
|
|
|
|
|
|
|
|
au!
|
2017-03-21 15:36:27 -07:00
|
|
|
|
enew
|
2017-03-20 06:01:22 -07:00
|
|
|
|
call delete('Xtestje1')
|
|
|
|
|
call delete('Xtestje2')
|
|
|
|
|
call delete('Xtestje3')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-20 05:59:11 -07:00
|
|
|
|
func Test_BufEnter()
|
|
|
|
|
au! BufEnter
|
|
|
|
|
au Bufenter * let val = val . '+'
|
|
|
|
|
let g:val = ''
|
|
|
|
|
split NewFile
|
|
|
|
|
call assert_equal('+', g:val)
|
|
|
|
|
bwipe!
|
|
|
|
|
call assert_equal('++', g:val)
|
|
|
|
|
|
|
|
|
|
" Also get BufEnter when editing a directory
|
2023-04-15 20:46:17 -07:00
|
|
|
|
call mkdir('Xbufenterdir', 'D')
|
|
|
|
|
split Xbufenterdir
|
2017-03-20 05:59:11 -07:00
|
|
|
|
call assert_equal('+++', g:val)
|
2017-07-30 18:54:18 -07:00
|
|
|
|
|
|
|
|
|
" On MS-Windows we can't edit the directory, make sure we wipe the right
|
|
|
|
|
" buffer.
|
2023-04-15 20:46:17 -07:00
|
|
|
|
bwipe! Xbufenterdir
|
2017-03-20 05:59:11 -07:00
|
|
|
|
au! BufEnter
|
2022-08-26 05:18:02 -07:00
|
|
|
|
|
|
|
|
|
" Editing a "nofile" buffer doesn't read the file but does trigger BufEnter
|
2022-08-26 07:39:13 -07:00
|
|
|
|
" for historic reasons. Also test other 'buftype' values.
|
|
|
|
|
for val in ['nofile',
|
|
|
|
|
\ 'nowrite',
|
|
|
|
|
\ 'acwrite',
|
|
|
|
|
\ 'quickfix',
|
|
|
|
|
\ 'help',
|
2022-09-22 05:18:06 -07:00
|
|
|
|
"\ 'terminal',
|
2022-08-26 07:39:13 -07:00
|
|
|
|
\ 'prompt',
|
2022-09-22 05:18:06 -07:00
|
|
|
|
"\ 'popup',
|
2022-08-26 07:39:13 -07:00
|
|
|
|
\ ]
|
|
|
|
|
new somefile
|
|
|
|
|
exe 'set buftype=' .. val
|
|
|
|
|
au BufEnter somefile call setline(1, 'some text')
|
|
|
|
|
edit
|
|
|
|
|
call assert_equal('some text', getline(1))
|
|
|
|
|
bwipe!
|
|
|
|
|
au! BufEnter
|
|
|
|
|
endfor
|
2017-03-20 05:59:11 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-19 18:48:28 -07:00
|
|
|
|
" Closing a window might cause an endless loop
|
|
|
|
|
" E814 for older Vims
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufwipe_in_SessLoadPost()
|
2018-02-11 08:15:12 -07:00
|
|
|
|
edit Xtest
|
2017-03-19 18:48:28 -07:00
|
|
|
|
tabnew
|
2018-02-11 08:15:12 -07:00
|
|
|
|
file Xsomething
|
2017-03-19 18:48:28 -07:00
|
|
|
|
set noswapfile
|
|
|
|
|
mksession!
|
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
|
let content =<< trim [CODE]
|
|
|
|
|
set nocp noswapfile
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let v:swapchoice = "e"
|
2019-09-23 13:12:02 -07:00
|
|
|
|
augroup test_autocmd_sessionload
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
func WriteErrors()
|
2023-08-22 03:17:03 -07:00
|
|
|
|
call writefile([execute("messages")], "XerrorsBwipe")
|
2019-09-23 13:12:02 -07:00
|
|
|
|
endfunc
|
|
|
|
|
au VimLeave * call WriteErrors()
|
|
|
|
|
[CODE]
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(content, 'Xvimrc', 'D')
|
2022-02-14 03:56:30 -07:00
|
|
|
|
call system(GetVimCommand('Xvimrc') .. ' --headless --noplugins -S Session.vim -c cq')
|
2023-08-22 03:14:19 -07:00
|
|
|
|
sleep 100m
|
2023-08-22 03:17:03 -07:00
|
|
|
|
let errors = join(readfile('XerrorsBwipe'))
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call assert_match('E814:', errors)
|
2017-03-19 18:48:28 -07:00
|
|
|
|
|
|
|
|
|
set swapfile
|
2023-08-22 03:17:03 -07:00
|
|
|
|
for file in ['Session.vim', 'XerrorsBwipe']
|
2017-03-19 18:48:28 -07:00
|
|
|
|
call delete(file)
|
|
|
|
|
endfor
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-05-11 19:17:12 -07:00
|
|
|
|
" Using :blast and :ball for many events caused a crash, because b_nwindows was
|
|
|
|
|
" not incremented correctly.
|
|
|
|
|
func Test_autocmd_blast_badd()
|
|
|
|
|
let content =<< trim [CODE]
|
|
|
|
|
au BufNew,BufAdd,BufWinEnter,BufEnter,BufLeave,BufWinLeave,BufUnload,VimEnter foo* blast
|
|
|
|
|
edit foo1
|
|
|
|
|
au BufNew,BufAdd,BufWinEnter,BufEnter,BufLeave,BufWinLeave,BufUnload,VimEnter foo* ball
|
|
|
|
|
edit foo2
|
2023-08-22 03:17:03 -07:00
|
|
|
|
call writefile(['OK'], 'XerrorsBlast')
|
2021-05-11 19:17:12 -07:00
|
|
|
|
qall
|
|
|
|
|
[CODE]
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(content, 'XblastBall', 'D')
|
2021-05-11 19:17:12 -07:00
|
|
|
|
call system(GetVimCommand() .. ' --clean -S XblastBall')
|
2023-08-22 03:14:19 -07:00
|
|
|
|
sleep 100m
|
2023-08-22 03:17:03 -07:00
|
|
|
|
call assert_match('OK', readfile('XerrorsBlast')->join())
|
2021-05-11 19:17:12 -07:00
|
|
|
|
|
2023-08-22 03:17:03 -07:00
|
|
|
|
call delete('XerrorsBlast')
|
2021-05-11 19:17:12 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-19 18:48:28 -07:00
|
|
|
|
" SEGV occurs in older versions.
|
2018-02-01 17:51:56 -07:00
|
|
|
|
func Test_autocmd_bufwipe_in_SessLoadPost2()
|
2017-03-19 18:48:28 -07:00
|
|
|
|
tabnew
|
|
|
|
|
set noswapfile
|
|
|
|
|
mksession!
|
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
|
let content =<< trim [CODE]
|
|
|
|
|
set nocp noswapfile
|
|
|
|
|
function! DeleteInactiveBufs()
|
|
|
|
|
tabfirst
|
|
|
|
|
let tabblist = []
|
|
|
|
|
for i in range(1, tabpagenr(''$''))
|
|
|
|
|
call extend(tabblist, tabpagebuflist(i))
|
|
|
|
|
endfor
|
|
|
|
|
for b in range(1, bufnr(''$''))
|
|
|
|
|
if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')
|
|
|
|
|
exec ''bwipeout '' . b
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
echomsg "SessionLoadPost DONE"
|
|
|
|
|
endfunction
|
|
|
|
|
au SessionLoadPost * call DeleteInactiveBufs()
|
|
|
|
|
|
|
|
|
|
func WriteErrors()
|
2023-08-22 03:17:03 -07:00
|
|
|
|
call writefile([execute("messages")], "XerrorsPost")
|
2019-09-23 13:12:02 -07:00
|
|
|
|
endfunc
|
|
|
|
|
au VimLeave * call WriteErrors()
|
|
|
|
|
[CODE]
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(content, 'Xvimrc', 'D')
|
2022-02-14 03:56:30 -07:00
|
|
|
|
call system(GetVimCommand('Xvimrc') .. ' --headless --noplugins -S Session.vim -c cq')
|
2023-08-22 03:14:19 -07:00
|
|
|
|
sleep 100m
|
2023-08-22 03:17:03 -07:00
|
|
|
|
let errors = join(readfile('XerrorsPost'))
|
2017-07-30 18:54:18 -07:00
|
|
|
|
" This probably only ever matches on unix.
|
|
|
|
|
call assert_notmatch('Caught deadly signal SEGV', errors)
|
|
|
|
|
call assert_match('SessionLoadPost DONE', errors)
|
|
|
|
|
|
2017-03-19 18:48:28 -07:00
|
|
|
|
set swapfile
|
2023-08-22 03:17:03 -07:00
|
|
|
|
for file in ['Session.vim', 'XerrorsPost']
|
2017-03-19 18:48:28 -07:00
|
|
|
|
call delete(file)
|
|
|
|
|
endfor
|
|
|
|
|
endfunc
|
2017-11-22 14:35:20 -07:00
|
|
|
|
|
2018-02-01 18:30:21 -07:00
|
|
|
|
func Test_empty_doau()
|
|
|
|
|
doau \|
|
2018-02-01 17:42:17 -07:00
|
|
|
|
endfunc
|
2018-02-01 17:51:56 -07:00
|
|
|
|
|
|
|
|
|
func s:AutoCommandOptionSet(match)
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let template = "Option: <%s>, OldVal: <%s>, OldValLocal: <%s>, OldValGlobal: <%s>, NewVal: <%s>, Scope: <%s>, Command: <%s>\n"
|
2018-02-01 17:51:56 -07:00
|
|
|
|
let item = remove(g:options, 0)
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let expected = printf(template, item[0], item[1], item[2], item[3], item[4], item[5], item[6])
|
|
|
|
|
let actual = printf(template, a:match, v:option_old, v:option_oldlocal, v:option_oldglobal, v:option_new, v:option_type, v:option_command)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
let g:opt = [expected, actual]
|
|
|
|
|
"call assert_equal(expected, actual)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_OptionSet()
|
2021-03-26 20:06:39 -07:00
|
|
|
|
CheckFunction test_override
|
2021-10-17 07:04:53 -07:00
|
|
|
|
CheckOption autochdir
|
2018-02-01 17:51:56 -07:00
|
|
|
|
|
|
|
|
|
call test_override('starting', 1)
|
|
|
|
|
set nocp
|
|
|
|
|
au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>"))
|
|
|
|
|
|
|
|
|
|
" 1: Setting number option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['number', 0, 0, 0, 1, 'global', 'set']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
set nu
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 2: Setting local number option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['number', 1, 1, '', 0, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setlocal nonu
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 3: Setting global number option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['number', 1, '', 1, 0, 'global', 'setglobal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setglobal nonu
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 4: Setting local autoindent option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoindent', 0, 0, '', 1, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setlocal ai
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 5: Setting global autoindent option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoindent', 0, '', 0, 1, 'global', 'setglobal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setglobal ai
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 6: Setting global autoindent option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoindent', 1, 1, 1, 0, 'global', 'set']]
|
|
|
|
|
set ai!
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 6a: Setting global autoindent option"
|
|
|
|
|
let g:options = [['autoindent', 1, 1, 0, 0, 'global', 'set']]
|
|
|
|
|
noa setlocal ai
|
|
|
|
|
noa setglobal noai
|
2018-02-01 17:51:56 -07:00
|
|
|
|
set ai!
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" Should not print anything, use :noa
|
|
|
|
|
" 7: don't trigger OptionSet"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
noa set nonu
|
2021-11-22 00:50:14 -07:00
|
|
|
|
call assert_equal([['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']], g:options)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 8: Setting several global list and number option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['list', 0, 0, 0, 1, 'global', 'set'], ['number', 0, 0, 0, 1, 'global', 'set']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
set list nu
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 9: don't trigger OptionSet"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid'], ['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
noa set nolist nonu
|
2021-11-22 00:50:14 -07:00
|
|
|
|
call assert_equal([['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid'], ['invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid', 'invalid']], g:options)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 10: Setting global acd"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autochdir', 0, 0, '', 1, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setlocal acd
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 11: Setting global autoread (also sets local value)"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoread', 0, 0, 0, 1, 'global', 'set']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
set ar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 12: Setting local autoread"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoread', 1, 1, '', 1, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setlocal ar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 13: Setting global autoread"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['autoread', 1, '', 1, 0, 'global', 'setglobal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setglobal invar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 14: Setting option backspace through :let"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['backspace', '', '', '', 'eol,indent,start', 'global', 'set']]
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let &bs = "eol,indent,start"
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 15: Setting option backspace through setbufvar()"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['backup', 0, 0, '', 1, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
" try twice, first time, shouldn't trigger because option name is invalid,
|
|
|
|
|
" second time, it should trigger
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let bnum = bufnr('%')
|
|
|
|
|
call assert_fails("call setbufvar(bnum, '&l:bk', 1)", 'E355:')
|
2018-02-01 17:51:56 -07:00
|
|
|
|
" should trigger, use correct option name
|
2021-11-22 00:50:14 -07:00
|
|
|
|
call setbufvar(bnum, '&backup', 1)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 16: Setting number option using setwinvar"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['number', 0, 0, '', 1, 'local', 'setlocal']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call setwinvar(0, '&number', 1)
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 17: Setting key option, shouldn't trigger"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['key', 'invalid', 'invalid1', 'invalid2', 'invalid3', 'invalid4', 'invalid5']]
|
2018-02-01 17:51:56 -07:00
|
|
|
|
setlocal key=blah
|
|
|
|
|
setlocal key=
|
2021-11-22 00:50:14 -07:00
|
|
|
|
call assert_equal([['key', 'invalid', 'invalid1', 'invalid2', 'invalid3', 'invalid4', 'invalid5']], g:options)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
|
|
|
|
|
" 18a: Setting string global option"
|
|
|
|
|
let oldval = &backupext
|
|
|
|
|
let g:options = [['backupext', oldval, oldval, oldval, 'foo', 'global', 'set']]
|
|
|
|
|
set backupext=foo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 18b: Resetting string global option"
|
|
|
|
|
let g:options = [['backupext', 'foo', 'foo', 'foo', oldval, 'global', 'set']]
|
|
|
|
|
set backupext&
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 18c: Setting global string global option"
|
|
|
|
|
let g:options = [['backupext', oldval, '', oldval, 'bar', 'global', 'setglobal']]
|
|
|
|
|
setglobal backupext=bar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 18d: Setting local string global option"
|
|
|
|
|
" As this is a global option this sets the global value even though
|
|
|
|
|
" :setlocal is used!
|
|
|
|
|
noa set backupext& " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['backupext', oldval, oldval, '', 'baz', 'local', 'setlocal']]
|
|
|
|
|
setlocal backupext=baz
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 18e: Setting again string global option"
|
|
|
|
|
noa setglobal backupext=ext_global " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal backupext=ext_local " Sets the global(!) value!
|
|
|
|
|
let g:options = [['backupext', 'ext_local', 'ext_local', 'ext_local', 'fuu', 'global', 'set']]
|
|
|
|
|
set backupext=fuu
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19a: Setting string global-local (to buffer) option"
|
2018-02-01 18:38:10 -07:00
|
|
|
|
let oldval = &tags
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['tags', oldval, oldval, oldval, 'tagpath', 'global', 'set']]
|
2018-02-01 18:38:10 -07:00
|
|
|
|
set tags=tagpath
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19b: Resetting string global-local (to buffer) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['tags', 'tagpath', 'tagpath', 'tagpath', oldval, 'global', 'set']]
|
2018-02-01 18:38:10 -07:00
|
|
|
|
set tags&
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19c: Setting global string global-local (to buffer) option "
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['tags', oldval, '', oldval, 'tagpath1', 'global', 'setglobal']]
|
|
|
|
|
setglobal tags=tagpath1
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19d: Setting local string global-local (to buffer) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal']]
|
|
|
|
|
setlocal tags=tagpath2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19e: Setting again string global-local (to buffer) option"
|
|
|
|
|
" Note: v:option_old is the old global value for global-local string options
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" but the old local value for all other kinds of options.
|
|
|
|
|
noa setglobal tags=tag_global " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal tags=tag_local
|
|
|
|
|
let g:options = [['tags', 'tag_global', 'tag_local', 'tag_global', 'tagpath', 'global', 'set']]
|
|
|
|
|
set tags=tagpath
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 19f: Setting string global-local (to buffer) option to an empty string"
|
|
|
|
|
" Note: v:option_old is the old global value for global-local string options
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" but the old local value for all other kinds of options.
|
|
|
|
|
noa set tags=tag_global " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal tags= " empty string
|
|
|
|
|
let g:options = [['tags', 'tag_global', '', 'tag_global', 'tagpath', 'global', 'set']]
|
|
|
|
|
set tags=tagpath
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 20a: Setting string local (to buffer) option"
|
|
|
|
|
let oldval = &spelllang
|
|
|
|
|
let g:options = [['spelllang', oldval, oldval, oldval, 'elvish,klingon', 'global', 'set']]
|
|
|
|
|
set spelllang=elvish,klingon
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 20b: Resetting string local (to buffer) option"
|
|
|
|
|
let g:options = [['spelllang', 'elvish,klingon', 'elvish,klingon', 'elvish,klingon', oldval, 'global', 'set']]
|
|
|
|
|
set spelllang&
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 20c: Setting global string local (to buffer) option"
|
|
|
|
|
let g:options = [['spelllang', oldval, '', oldval, 'elvish', 'global', 'setglobal']]
|
|
|
|
|
setglobal spelllang=elvish
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 20d: Setting local string local (to buffer) option"
|
|
|
|
|
noa set spelllang& " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal']]
|
|
|
|
|
setlocal spelllang=klingon
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 20e: Setting again string local (to buffer) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" Note: v:option_old is the old global value for global-local string options
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" but the old local value for all other kinds of options.
|
|
|
|
|
noa setglobal spelllang=spellglobal " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal spelllang=spelllocal
|
|
|
|
|
let g:options = [['spelllang', 'spelllocal', 'spelllocal', 'spellglobal', 'foo', 'global', 'set']]
|
|
|
|
|
set spelllang=foo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 21a: Setting string global-local (to window) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let oldval = &statusline
|
|
|
|
|
let g:options = [['statusline', oldval, oldval, oldval, 'foo', 'global', 'set']]
|
|
|
|
|
set statusline=foo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 21b: Resetting string global-local (to window) option"
|
|
|
|
|
" Note: v:option_old is the old global value for global-local string options
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" but the old local value for all other kinds of options.
|
|
|
|
|
let g:options = [['statusline', 'foo', 'foo', 'foo', oldval, 'global', 'set']]
|
|
|
|
|
set statusline&
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 21c: Setting global string global-local (to window) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
let g:options = [['statusline', oldval, '', oldval, 'bar', 'global', 'setglobal']]
|
|
|
|
|
setglobal statusline=bar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 21d: Setting local string global-local (to window) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
noa set statusline& " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['statusline', oldval, oldval, '', 'baz', 'local', 'setlocal']]
|
|
|
|
|
setlocal statusline=baz
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 21e: Setting again string global-local (to window) option"
|
|
|
|
|
" Note: v:option_old is the old global value for global-local string options
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" but the old local value for all other kinds of options.
|
|
|
|
|
noa setglobal statusline=bar " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal statusline=baz
|
|
|
|
|
let g:options = [['statusline', 'bar', 'baz', 'bar', 'foo', 'global', 'set']]
|
|
|
|
|
set statusline=foo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 22a: Setting string local (to window) option"
|
|
|
|
|
let oldval = &foldignore
|
|
|
|
|
let g:options = [['foldignore', oldval, oldval, oldval, 'fo', 'global', 'set']]
|
|
|
|
|
set foldignore=fo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 22b: Resetting string local (to window) option"
|
|
|
|
|
let g:options = [['foldignore', 'fo', 'fo', 'fo', oldval, 'global', 'set']]
|
|
|
|
|
set foldignore&
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 22c: Setting global string local (to window) option"
|
|
|
|
|
let g:options = [['foldignore', oldval, '', oldval, 'bar', 'global', 'setglobal']]
|
|
|
|
|
setglobal foldignore=bar
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 22d: Setting local string local (to window) option"
|
|
|
|
|
noa set foldignore& " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['foldignore', oldval, oldval, '', 'baz', 'local', 'setlocal']]
|
|
|
|
|
setlocal foldignore=baz
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 22e: Setting again string local (to window) option"
|
|
|
|
|
noa setglobal foldignore=glob " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal foldignore=loc
|
|
|
|
|
let g:options = [['foldignore', 'loc', 'loc', 'glob', 'fo', 'global', 'set']]
|
|
|
|
|
set foldignore=fo
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 23a: Setting global number global option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cmdheight=1 " Sets the global(!) value!
|
|
|
|
|
let g:options = [['cmdheight', '1', '', '1', '2', 'global', 'setglobal']]
|
|
|
|
|
setglobal cmdheight=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 23b: Setting local number global option"
|
|
|
|
|
noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cmdheight=1 " Sets the global(!) value!
|
|
|
|
|
let g:options = [['cmdheight', '1', '1', '', '2', 'local', 'setlocal']]
|
|
|
|
|
setlocal cmdheight=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 23c: Setting again number global option"
|
|
|
|
|
noa setglobal cmdheight=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cmdheight=1 " Sets the global(!) value!
|
|
|
|
|
let g:options = [['cmdheight', '1', '1', '1', '2', 'global', 'set']]
|
|
|
|
|
set cmdheight=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 23d: Setting again number global option"
|
|
|
|
|
noa set cmdheight=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['cmdheight', '8', '8', '8', '2', 'global', 'set']]
|
|
|
|
|
set cmdheight=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 24a: Setting global number global-local (to buffer) option"
|
|
|
|
|
noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal undolevels=1
|
|
|
|
|
let g:options = [['undolevels', '8', '', '8', '2', 'global', 'setglobal']]
|
|
|
|
|
setglobal undolevels=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 24b: Setting local number global-local (to buffer) option"
|
|
|
|
|
noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal undolevels=1
|
|
|
|
|
let g:options = [['undolevels', '1', '1', '', '2', 'local', 'setlocal']]
|
|
|
|
|
setlocal undolevels=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 24c: Setting again number global-local (to buffer) option"
|
|
|
|
|
noa setglobal undolevels=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal undolevels=1
|
|
|
|
|
let g:options = [['undolevels', '1', '1', '8', '2', 'global', 'set']]
|
|
|
|
|
set undolevels=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 24d: Setting again global number global-local (to buffer) option"
|
|
|
|
|
noa set undolevels=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['undolevels', '8', '8', '8', '2', 'global', 'set']]
|
|
|
|
|
set undolevels=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 25a: Setting global number local (to buffer) option"
|
|
|
|
|
noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapmargin=1
|
|
|
|
|
let g:options = [['wrapmargin', '8', '', '8', '2', 'global', 'setglobal']]
|
|
|
|
|
setglobal wrapmargin=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 25b: Setting local number local (to buffer) option"
|
|
|
|
|
noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapmargin=1
|
|
|
|
|
let g:options = [['wrapmargin', '1', '1', '', '2', 'local', 'setlocal']]
|
|
|
|
|
setlocal wrapmargin=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 25c: Setting again number local (to buffer) option"
|
|
|
|
|
noa setglobal wrapmargin=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapmargin=1
|
|
|
|
|
let g:options = [['wrapmargin', '1', '1', '8', '2', 'global', 'set']]
|
|
|
|
|
set wrapmargin=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 25d: Setting again global number local (to buffer) option"
|
|
|
|
|
noa set wrapmargin=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['wrapmargin', '8', '8', '8', '2', 'global', 'set']]
|
|
|
|
|
set wrapmargin=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 26: Setting number global-local (to window) option.
|
|
|
|
|
" Such option does currently not exist.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 27a: Setting global number local (to window) option"
|
|
|
|
|
noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal foldcolumn=1
|
|
|
|
|
let g:options = [['foldcolumn', '8', '', '8', '2', 'global', 'setglobal']]
|
|
|
|
|
setglobal foldcolumn=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 27b: Setting local number local (to window) option"
|
|
|
|
|
noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal foldcolumn=1
|
|
|
|
|
let g:options = [['foldcolumn', '1', '1', '', '2', 'local', 'setlocal']]
|
|
|
|
|
setlocal foldcolumn=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 27c: Setting again number local (to window) option"
|
|
|
|
|
noa setglobal foldcolumn=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal foldcolumn=1
|
|
|
|
|
let g:options = [['foldcolumn', '1', '1', '8', '2', 'global', 'set']]
|
|
|
|
|
set foldcolumn=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
2021-11-22 00:50:14 -07:00
|
|
|
|
" 27d: Setting again global number local (to window) option"
|
2021-11-22 00:50:14 -07:00
|
|
|
|
noa set foldcolumn=8 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['foldcolumn', '8', '8', '8', '2', 'global', 'set']]
|
|
|
|
|
set foldcolumn=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 28a: Setting global boolean global option"
|
|
|
|
|
noa setglobal nowrapscan " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapscan " Sets the global(!) value!
|
|
|
|
|
let g:options = [['wrapscan', '1', '', '1', '0', 'global', 'setglobal']]
|
|
|
|
|
setglobal nowrapscan
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 28b: Setting local boolean global option"
|
|
|
|
|
noa setglobal nowrapscan " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapscan " Sets the global(!) value!
|
|
|
|
|
let g:options = [['wrapscan', '1', '1', '', '0', 'local', 'setlocal']]
|
|
|
|
|
setlocal nowrapscan
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 28c: Setting again boolean global option"
|
|
|
|
|
noa setglobal nowrapscan " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal wrapscan " Sets the global(!) value!
|
|
|
|
|
let g:options = [['wrapscan', '1', '1', '1', '0', 'global', 'set']]
|
|
|
|
|
set nowrapscan
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 28d: Setting again global boolean global option"
|
|
|
|
|
noa set nowrapscan " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['wrapscan', '0', '0', '0', '1', 'global', 'set']]
|
|
|
|
|
set wrapscan
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 29a: Setting global boolean global-local (to buffer) option"
|
|
|
|
|
noa setglobal noautoread " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal autoread
|
|
|
|
|
let g:options = [['autoread', '0', '', '0', '1', 'global', 'setglobal']]
|
|
|
|
|
setglobal autoread
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 29b: Setting local boolean global-local (to buffer) option"
|
|
|
|
|
noa setglobal noautoread " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal autoread
|
|
|
|
|
let g:options = [['autoread', '1', '1', '', '0', 'local', 'setlocal']]
|
|
|
|
|
setlocal noautoread
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 29c: Setting again boolean global-local (to buffer) option"
|
|
|
|
|
noa setglobal noautoread " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal autoread
|
|
|
|
|
let g:options = [['autoread', '1', '1', '0', '1', 'global', 'set']]
|
|
|
|
|
set autoread
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 29d: Setting again global boolean global-local (to buffer) option"
|
|
|
|
|
noa set noautoread " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['autoread', '0', '0', '0', '1', 'global', 'set']]
|
|
|
|
|
set autoread
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 30a: Setting global boolean local (to buffer) option"
|
|
|
|
|
noa setglobal nocindent " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cindent
|
|
|
|
|
let g:options = [['cindent', '0', '', '0', '1', 'global', 'setglobal']]
|
|
|
|
|
setglobal cindent
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 30b: Setting local boolean local (to buffer) option"
|
|
|
|
|
noa setglobal nocindent " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cindent
|
|
|
|
|
let g:options = [['cindent', '1', '1', '', '0', 'local', 'setlocal']]
|
|
|
|
|
setlocal nocindent
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 30c: Setting again boolean local (to buffer) option"
|
|
|
|
|
noa setglobal nocindent " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cindent
|
|
|
|
|
let g:options = [['cindent', '1', '1', '0', '1', 'global', 'set']]
|
|
|
|
|
set cindent
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 30d: Setting again global boolean local (to buffer) option"
|
|
|
|
|
noa set nocindent " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['cindent', '0', '0', '0', '1', 'global', 'set']]
|
|
|
|
|
set cindent
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 31: Setting boolean global-local (to window) option
|
|
|
|
|
" Currently no such option exists.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 32a: Setting global boolean local (to window) option"
|
|
|
|
|
noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cursorcolumn
|
|
|
|
|
let g:options = [['cursorcolumn', '0', '', '0', '1', 'global', 'setglobal']]
|
|
|
|
|
setglobal cursorcolumn
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 32b: Setting local boolean local (to window) option"
|
|
|
|
|
noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cursorcolumn
|
|
|
|
|
let g:options = [['cursorcolumn', '1', '1', '', '0', 'local', 'setlocal']]
|
|
|
|
|
setlocal nocursorcolumn
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 32c: Setting again boolean local (to window) option"
|
|
|
|
|
noa setglobal nocursorcolumn " Reset global and local value (without triggering autocmd)
|
|
|
|
|
noa setlocal cursorcolumn
|
|
|
|
|
let g:options = [['cursorcolumn', '1', '1', '0', '1', 'global', 'set']]
|
|
|
|
|
set cursorcolumn
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
" 32d: Setting again global boolean local (to window) option"
|
|
|
|
|
noa set nocursorcolumn " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['cursorcolumn', '0', '0', '0', '1', 'global', 'set']]
|
|
|
|
|
set cursorcolumn
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" 33: Test autocommands when an option value is converted internally.
|
|
|
|
|
noa set backspace=1 " Reset global and local value (without triggering autocmd)
|
|
|
|
|
let g:options = [['backspace', 'indent,eol', 'indent,eol', 'indent,eol', '2', 'global', 'set']]
|
|
|
|
|
set backspace=2
|
|
|
|
|
call assert_equal([], g:options)
|
|
|
|
|
call assert_equal(g:opt[0], g:opt[1])
|
|
|
|
|
|
|
|
|
|
|
2018-02-01 17:51:56 -07:00
|
|
|
|
" Cleanup
|
|
|
|
|
au! OptionSet
|
2019-06-16 05:31:58 -07:00
|
|
|
|
" set tags&
|
2021-11-22 00:50:14 -07:00
|
|
|
|
for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp', 'backupext', 'tags', 'spelllang', 'statusline', 'foldignore', 'cmdheight', 'undolevels', 'wrapmargin', 'foldcolumn', 'wrapscan', 'autoread', 'cindent', 'cursorcolumn']
|
2018-08-08 16:02:32 -07:00
|
|
|
|
exe printf(":set %s&vim", opt)
|
2018-02-01 17:51:56 -07:00
|
|
|
|
endfor
|
|
|
|
|
call test_override('starting', 0)
|
|
|
|
|
delfunc! AutoCommandOptionSet
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_OptionSet_diffmode()
|
2021-03-26 20:06:39 -07:00
|
|
|
|
CheckFunction test_override
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call test_override('starting', 1)
|
2019-04-25 20:58:44 -07:00
|
|
|
|
" 18: Changing an option when entering diff mode
|
2018-02-01 17:51:56 -07:00
|
|
|
|
new
|
2021-06-23 19:46:02 -07:00
|
|
|
|
au OptionSet diff :let &l:cul = v:option_new
|
2018-02-01 17:51:56 -07:00
|
|
|
|
|
|
|
|
|
call setline(1, ['buffer 1', 'line2', 'line3', 'line4'])
|
|
|
|
|
call assert_equal(0, &l:cul)
|
|
|
|
|
diffthis
|
|
|
|
|
call assert_equal(1, &l:cul)
|
|
|
|
|
|
|
|
|
|
vnew
|
|
|
|
|
call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4'])
|
|
|
|
|
call assert_equal(0, &l:cul)
|
|
|
|
|
diffthis
|
|
|
|
|
call assert_equal(1, &l:cul)
|
|
|
|
|
|
|
|
|
|
diffoff
|
|
|
|
|
call assert_equal(0, &l:cul)
|
|
|
|
|
call assert_equal(1, getwinvar(2, '&l:cul'))
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
call assert_equal(1, &l:cul)
|
|
|
|
|
diffoff!
|
|
|
|
|
call assert_equal(0, &l:cul)
|
|
|
|
|
call assert_equal(0, getwinvar(1, '&l:cul'))
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
" Cleanup
|
|
|
|
|
au! OptionSet
|
|
|
|
|
call test_override('starting', 0)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_OptionSet_diffmode_close()
|
2021-03-26 20:06:39 -07:00
|
|
|
|
CheckFunction test_override
|
2018-02-01 17:51:56 -07:00
|
|
|
|
call test_override('starting', 1)
|
|
|
|
|
" 19: Try to close the current window when entering diff mode
|
|
|
|
|
" should not segfault
|
|
|
|
|
new
|
|
|
|
|
au OptionSet diff close
|
|
|
|
|
|
|
|
|
|
call setline(1, ['buffer 1', 'line2', 'line3', 'line4'])
|
|
|
|
|
call assert_fails(':diffthis', 'E788')
|
|
|
|
|
call assert_equal(1, &diff)
|
|
|
|
|
vnew
|
|
|
|
|
call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4'])
|
|
|
|
|
call assert_fails(':diffthis', 'E788')
|
|
|
|
|
call assert_equal(1, &diff)
|
2020-11-24 20:17:04 -07:00
|
|
|
|
set diffopt-=closeoff
|
2018-02-01 17:51:56 -07:00
|
|
|
|
bw!
|
|
|
|
|
call assert_fails(':diffoff!', 'E788')
|
|
|
|
|
bw!
|
|
|
|
|
|
|
|
|
|
" Cleanup
|
|
|
|
|
au! OptionSet
|
|
|
|
|
call test_override('starting', 0)
|
|
|
|
|
"delfunc! AutoCommandOptionSet
|
|
|
|
|
endfunc
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
" Test for Bufleave autocommand that deletes the buffer we are about to edit.
|
|
|
|
|
func Test_BufleaveWithDelete()
|
2023-08-21 01:27:14 -07:00
|
|
|
|
new | edit XbufLeave1
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
augroup test_bufleavewithdelete
|
|
|
|
|
autocmd!
|
2023-08-21 01:27:14 -07:00
|
|
|
|
autocmd BufLeave XbufLeave1 bwipe XbufLeave2
|
2018-02-01 18:30:21 -07:00
|
|
|
|
augroup END
|
|
|
|
|
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call assert_fails('edit XbufLeave2', 'E143:')
|
|
|
|
|
call assert_equal('XbufLeave1', bufname('%'))
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
2023-08-21 01:27:14 -07:00
|
|
|
|
autocmd! test_bufleavewithdelete BufLeave XbufLeave1
|
2018-02-01 18:30:21 -07:00
|
|
|
|
augroup! test_bufleavewithdelete
|
|
|
|
|
|
|
|
|
|
new
|
2023-08-21 01:27:14 -07:00
|
|
|
|
bwipe! XbufLeave1
|
2018-02-01 18:30:21 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for autocommand that changes the buffer list, when doing ":ball".
|
|
|
|
|
func Test_Acmd_BufAll()
|
|
|
|
|
enew!
|
|
|
|
|
%bwipe!
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['Test file Xxx1'], 'Xxx1', 'D')
|
|
|
|
|
call writefile(['Test file Xxx2'], 'Xxx2', 'D')
|
|
|
|
|
call writefile(['Test file Xxx3'], 'Xxx3', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
" Add three files to the buffer list
|
|
|
|
|
split Xxx1
|
|
|
|
|
close
|
|
|
|
|
split Xxx2
|
|
|
|
|
close
|
|
|
|
|
split Xxx3
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
" Wipe the buffer when the buffer is opened
|
|
|
|
|
au BufReadPost Xxx2 bwipe
|
|
|
|
|
|
|
|
|
|
call append(0, 'Test file Xxx4')
|
|
|
|
|
ball
|
|
|
|
|
|
|
|
|
|
call assert_equal(2, winnr('$'))
|
|
|
|
|
call assert_equal('Xxx1', bufname(winbufnr(winnr('$'))))
|
|
|
|
|
wincmd t
|
|
|
|
|
|
|
|
|
|
au! BufReadPost
|
|
|
|
|
%bwipe!
|
|
|
|
|
enew! | only
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for autocommand that changes current buffer on BufEnter event.
|
|
|
|
|
" Check if modelines are interpreted for the correct buffer.
|
|
|
|
|
func Test_Acmd_BufEnter()
|
|
|
|
|
%bwipe!
|
|
|
|
|
call writefile(['start of test file Xxx1',
|
|
|
|
|
\ "\<Tab>this is a test",
|
2023-08-22 02:48:57 -07:00
|
|
|
|
\ 'end of test file Xxx1'], 'Xxx1', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
call writefile(['start of test file Xxx2',
|
|
|
|
|
\ 'vim: set noai :',
|
|
|
|
|
\ "\<Tab>this is a test",
|
2023-08-22 02:48:57 -07:00
|
|
|
|
\ 'end of test file Xxx2'], 'Xxx2', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
au BufEnter Xxx2 brew
|
|
|
|
|
set ai modeline modelines=3
|
|
|
|
|
edit Xxx1
|
|
|
|
|
" edit Xxx2, autocmd will do :brew
|
|
|
|
|
edit Xxx2
|
|
|
|
|
exe "normal G?this is a\<CR>"
|
|
|
|
|
" Append text with autoindent to this file
|
|
|
|
|
normal othis should be auto-indented
|
|
|
|
|
call assert_equal("\<Tab>this should be auto-indented", getline('.'))
|
|
|
|
|
call assert_equal(3, line('.'))
|
|
|
|
|
" Remove autocmd and edit Xxx2 again
|
|
|
|
|
au! BufEnter Xxx2
|
|
|
|
|
buf! Xxx2
|
|
|
|
|
exe "normal G?this is a\<CR>"
|
|
|
|
|
" append text without autoindent to Xxx
|
|
|
|
|
normal othis should be in column 1
|
|
|
|
|
call assert_equal("this should be in column 1", getline('.'))
|
|
|
|
|
call assert_equal(4, line('.'))
|
|
|
|
|
|
|
|
|
|
%bwipe!
|
|
|
|
|
set ai&vim modeline&vim modelines&vim
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for issue #57
|
|
|
|
|
" do not move cursor on <c-o> when autoindent is set
|
|
|
|
|
func Test_ai_CTRL_O()
|
|
|
|
|
enew!
|
|
|
|
|
set ai
|
|
|
|
|
let save_fo = &fo
|
|
|
|
|
set fo+=r
|
|
|
|
|
exe "normal o# abcdef\<Esc>2hi\<CR>\<C-O>d0\<Esc>"
|
|
|
|
|
exe "normal o# abcdef\<Esc>2hi\<C-O>d0\<Esc>"
|
|
|
|
|
call assert_equal(['# abc', 'def', 'def'], getline(2, 4))
|
|
|
|
|
|
|
|
|
|
set ai&vim
|
|
|
|
|
let &fo = save_fo
|
|
|
|
|
enew!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for autocommand that deletes the current buffer on BufLeave event.
|
|
|
|
|
" Also test deleting the last buffer, should give a new, empty buffer.
|
|
|
|
|
func Test_BufLeave_Wipe()
|
|
|
|
|
%bwipe!
|
|
|
|
|
let content = ['start of test file Xxx',
|
|
|
|
|
\ 'this is a test',
|
|
|
|
|
\ 'end of test file Xxx']
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(content, 'Xxx1', 'D')
|
|
|
|
|
call writefile(content, 'Xxx2', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
au BufLeave Xxx2 bwipe
|
|
|
|
|
edit Xxx1
|
|
|
|
|
split Xxx2
|
|
|
|
|
" delete buffer Xxx2, we should be back to Xxx1
|
|
|
|
|
bwipe
|
|
|
|
|
call assert_equal('Xxx1', bufname('%'))
|
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
|
|
|
|
|
|
" Create an alternate buffer
|
|
|
|
|
%write! test.out
|
|
|
|
|
call assert_equal('test.out', bufname('#'))
|
|
|
|
|
" delete alternate buffer
|
|
|
|
|
bwipe test.out
|
|
|
|
|
call assert_equal('Xxx1', bufname('%'))
|
|
|
|
|
call assert_equal('', bufname('#'))
|
|
|
|
|
|
|
|
|
|
au BufLeave Xxx1 bwipe
|
|
|
|
|
" delete current buffer, get an empty one
|
|
|
|
|
bwipe!
|
|
|
|
|
call assert_equal(1, line('$'))
|
|
|
|
|
call assert_equal('', bufname('%'))
|
|
|
|
|
let g:bufinfo = getbufinfo()
|
|
|
|
|
call assert_equal(1, len(g:bufinfo))
|
|
|
|
|
|
|
|
|
|
call delete('test.out')
|
|
|
|
|
%bwipe
|
|
|
|
|
au! BufLeave
|
|
|
|
|
|
|
|
|
|
" check that bufinfo doesn't contain a pointer to freed memory
|
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_QuitPre()
|
|
|
|
|
edit Xfoo
|
|
|
|
|
let winid = win_getid(winnr())
|
|
|
|
|
split Xbar
|
|
|
|
|
au! QuitPre * let g:afile = expand('<afile>')
|
|
|
|
|
" Close the other window, <afile> should be correct.
|
|
|
|
|
exe win_id2win(winid) . 'q'
|
|
|
|
|
call assert_equal('Xfoo', g:afile)
|
|
|
|
|
|
|
|
|
|
unlet g:afile
|
|
|
|
|
bwipe Xfoo
|
|
|
|
|
bwipe Xbar
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_Cmdline()
|
2018-01-31 08:17:05 -07:00
|
|
|
|
au! CmdlineChanged : let g:text = getcmdline()
|
|
|
|
|
let g:text = 0
|
|
|
|
|
call feedkeys(":echom 'hello'\<CR>", 'xt')
|
|
|
|
|
call assert_equal("echom 'hello'", g:text)
|
|
|
|
|
au! CmdlineChanged
|
|
|
|
|
|
|
|
|
|
au! CmdlineChanged : let g:entered = expand('<afile>')
|
|
|
|
|
let g:entered = 0
|
|
|
|
|
call feedkeys(":echom 'hello'\<CR>", 'xt')
|
|
|
|
|
call assert_equal(':', g:entered)
|
|
|
|
|
au! CmdlineChanged
|
|
|
|
|
|
2023-02-11 04:01:43 -07:00
|
|
|
|
autocmd CmdlineChanged : let g:log += [getcmdline()]
|
|
|
|
|
|
2023-02-06 16:54:33 -07:00
|
|
|
|
let g:log = []
|
|
|
|
|
cnoremap <F1> <Cmd>call setcmdline('ls')<CR>
|
|
|
|
|
call feedkeys(":\<F1>", 'xt')
|
|
|
|
|
call assert_equal(['ls'], g:log)
|
|
|
|
|
cunmap <F1>
|
|
|
|
|
|
|
|
|
|
let g:log = []
|
|
|
|
|
call feedkeys(":sign \<Tab>\<Tab>\<C-N>\<C-P>\<S-Tab>\<S-Tab>\<Esc>", 'xt')
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 's',
|
|
|
|
|
\ 'si',
|
|
|
|
|
\ 'sig',
|
|
|
|
|
\ 'sign',
|
|
|
|
|
\ 'sign ',
|
|
|
|
|
\ 'sign define',
|
|
|
|
|
\ 'sign jump',
|
|
|
|
|
\ 'sign list',
|
|
|
|
|
\ 'sign jump',
|
|
|
|
|
\ 'sign define',
|
|
|
|
|
\ 'sign ',
|
|
|
|
|
\ ], g:log)
|
|
|
|
|
let g:log = []
|
|
|
|
|
set wildmenu wildoptions+=pum
|
|
|
|
|
call feedkeys(":sign \<S-Tab>\<PageUp>\<kPageUp>\<kPageDown>\<PageDown>\<Esc>", 'xt')
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 's',
|
|
|
|
|
\ 'si',
|
|
|
|
|
\ 'sig',
|
|
|
|
|
\ 'sign',
|
|
|
|
|
\ 'sign ',
|
|
|
|
|
\ 'sign unplace',
|
|
|
|
|
\ 'sign jump',
|
|
|
|
|
\ 'sign define',
|
|
|
|
|
\ 'sign undefine',
|
|
|
|
|
\ 'sign unplace',
|
|
|
|
|
\ ], g:log)
|
|
|
|
|
set wildmenu& wildoptions&
|
2023-02-11 04:01:43 -07:00
|
|
|
|
|
|
|
|
|
let g:log = []
|
|
|
|
|
let @r = 'abc'
|
|
|
|
|
call feedkeys(":0\<C-R>r1\<C-R>\<C-O>r2\<C-R>\<C-R>r3\<Esc>", 'xt')
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ '0',
|
|
|
|
|
\ '0a',
|
|
|
|
|
\ '0ab',
|
|
|
|
|
\ '0abc',
|
|
|
|
|
\ '0abc1',
|
|
|
|
|
\ '0abc1abc',
|
|
|
|
|
\ '0abc1abc2',
|
|
|
|
|
\ '0abc1abc2abc',
|
|
|
|
|
\ '0abc1abc2abc3',
|
|
|
|
|
\ ], g:log)
|
|
|
|
|
|
2023-02-06 16:54:33 -07:00
|
|
|
|
unlet g:log
|
|
|
|
|
au! CmdlineChanged
|
|
|
|
|
|
2018-02-01 18:30:21 -07:00
|
|
|
|
au! CmdlineEnter : let g:entered = expand('<afile>')
|
|
|
|
|
au! CmdlineLeave : let g:left = expand('<afile>')
|
|
|
|
|
let g:entered = 0
|
|
|
|
|
let g:left = 0
|
|
|
|
|
call feedkeys(":echo 'hello'\<CR>", 'xt')
|
|
|
|
|
call assert_equal(':', g:entered)
|
|
|
|
|
call assert_equal(':', g:left)
|
|
|
|
|
au! CmdlineEnter
|
|
|
|
|
au! CmdlineLeave
|
|
|
|
|
|
2018-12-10 20:41:37 -07:00
|
|
|
|
let save_shellslash = &shellslash
|
|
|
|
|
set noshellslash
|
2018-02-01 18:30:21 -07:00
|
|
|
|
au! CmdlineEnter / let g:entered = expand('<afile>')
|
|
|
|
|
au! CmdlineLeave / let g:left = expand('<afile>')
|
|
|
|
|
let g:entered = 0
|
|
|
|
|
let g:left = 0
|
|
|
|
|
new
|
|
|
|
|
call setline(1, 'hello')
|
|
|
|
|
call feedkeys("/hello\<CR>", 'xt')
|
|
|
|
|
call assert_equal('/', g:entered)
|
|
|
|
|
call assert_equal('/', g:left)
|
|
|
|
|
bwipe!
|
|
|
|
|
au! CmdlineEnter
|
|
|
|
|
au! CmdlineLeave
|
2018-12-10 20:41:37 -07:00
|
|
|
|
let &shellslash = save_shellslash
|
2018-02-01 18:30:21 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for BufWritePre autocommand that deletes or unloads the buffer.
|
|
|
|
|
func Test_BufWritePre()
|
|
|
|
|
%bwipe
|
|
|
|
|
au BufWritePre Xxx1 bunload
|
|
|
|
|
au BufWritePre Xxx2 bwipe
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1', 'D')
|
|
|
|
|
call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
edit Xtest
|
|
|
|
|
e! Xxx2
|
|
|
|
|
bdel Xtest
|
|
|
|
|
e Xxx1
|
|
|
|
|
" write it, will unload it and give an error msg
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call assert_fails('w', 'E203:')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
call assert_equal('Xxx2', bufname('%'))
|
|
|
|
|
edit Xtest
|
|
|
|
|
e! Xxx2
|
|
|
|
|
bwipe Xtest
|
|
|
|
|
" write it, will delete the buffer and give an error msg
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call assert_fails('w', 'E203:')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
call assert_equal('Xxx1', bufname('%'))
|
|
|
|
|
au! BufWritePre
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for BufUnload autocommand that unloads all the other buffers
|
|
|
|
|
func Test_bufunload_all()
|
2023-08-21 00:30:20 -07:00
|
|
|
|
let g:test_is_flaky = 1
|
2023-09-09 02:47:28 -07:00
|
|
|
|
call writefile(['Test file Xxx1'], 'Xxx1', 'D')
|
|
|
|
|
call writefile(['Test file Xxx2'], 'Xxx2', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
|
let content =<< trim [CODE]
|
|
|
|
|
func UnloadAllBufs()
|
|
|
|
|
let i = 1
|
|
|
|
|
while i <= bufnr('$')
|
|
|
|
|
if i != bufnr('%') && bufloaded(i)
|
|
|
|
|
exe i . 'bunload'
|
|
|
|
|
endif
|
|
|
|
|
let i += 1
|
|
|
|
|
endwhile
|
|
|
|
|
endfunc
|
|
|
|
|
au BufUnload * call UnloadAllBufs()
|
|
|
|
|
au VimLeave * call writefile(['Test Finished'], 'Xout')
|
2021-08-17 20:30:58 -07:00
|
|
|
|
set nohidden
|
2019-09-23 13:12:02 -07:00
|
|
|
|
edit Xxx1
|
|
|
|
|
split Xxx2
|
|
|
|
|
q
|
|
|
|
|
[CODE]
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(content, 'Xbunloadtest', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
call delete('Xout')
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call system(GetVimCommandClean() .. ' -N --headless -S Xbunloadtest')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
call assert_true(filereadable('Xout'))
|
|
|
|
|
|
|
|
|
|
call delete('Xout')
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Some tests for buffer-local autocommands
|
|
|
|
|
func Test_buflocal_autocmd()
|
|
|
|
|
let g:bname = ''
|
|
|
|
|
edit xx
|
|
|
|
|
au BufLeave <buffer> let g:bname = expand("%")
|
|
|
|
|
" here, autocommand for xx should trigger.
|
|
|
|
|
" but autocommand shall not apply to buffer named <buffer>.
|
|
|
|
|
edit somefile
|
|
|
|
|
call assert_equal('xx', g:bname)
|
|
|
|
|
let g:bname = ''
|
|
|
|
|
" here, autocommand shall be auto-deleted
|
|
|
|
|
bwipe xx
|
|
|
|
|
" autocmd should not trigger
|
|
|
|
|
edit xx
|
|
|
|
|
call assert_equal('', g:bname)
|
|
|
|
|
" autocmd should not trigger
|
|
|
|
|
edit somefile
|
|
|
|
|
call assert_equal('', g:bname)
|
|
|
|
|
enew
|
|
|
|
|
unlet g:bname
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for "*Cmd" autocommands
|
|
|
|
|
func Test_Cmd_Autocmds()
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx', 'D')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
enew!
|
|
|
|
|
au BufReadCmd XtestA 0r Xxx|$del
|
|
|
|
|
edit XtestA " will read text of Xxd instead
|
|
|
|
|
call assert_equal('start of Xxx', getline(1))
|
|
|
|
|
|
|
|
|
|
au BufWriteCmd XtestA call append(line("$"), "write")
|
|
|
|
|
write " will append a line to the file
|
|
|
|
|
call assert_equal('write', getline('$'))
|
|
|
|
|
call assert_fails('read XtestA', 'E484') " should not read anything
|
|
|
|
|
call assert_equal('write', getline(4))
|
|
|
|
|
|
|
|
|
|
" now we have:
|
|
|
|
|
" 1 start of Xxx
|
|
|
|
|
" 2 abc2
|
|
|
|
|
" 3 end of Xxx
|
|
|
|
|
" 4 write
|
|
|
|
|
|
|
|
|
|
au FileReadCmd XtestB '[r Xxx
|
|
|
|
|
2r XtestB " will read Xxx below line 2 instead
|
|
|
|
|
call assert_equal('start of Xxx', getline(3))
|
|
|
|
|
|
|
|
|
|
" now we have:
|
|
|
|
|
" 1 start of Xxx
|
|
|
|
|
" 2 abc2
|
|
|
|
|
" 3 start of Xxx
|
|
|
|
|
" 4 abc2
|
|
|
|
|
" 5 end of Xxx
|
|
|
|
|
" 6 end of Xxx
|
|
|
|
|
" 7 write
|
|
|
|
|
|
|
|
|
|
au FileWriteCmd XtestC '[,']copy $
|
|
|
|
|
normal 4GA1
|
|
|
|
|
4,5w XtestC " will copy lines 4 and 5 to the end
|
|
|
|
|
call assert_equal("\tabc21", getline(8))
|
|
|
|
|
call assert_fails('r XtestC', 'E484') " should not read anything
|
|
|
|
|
call assert_equal("end of Xxx", getline(9))
|
|
|
|
|
|
|
|
|
|
" now we have:
|
|
|
|
|
" 1 start of Xxx
|
|
|
|
|
" 2 abc2
|
|
|
|
|
" 3 start of Xxx
|
|
|
|
|
" 4 abc21
|
|
|
|
|
" 5 end of Xxx
|
|
|
|
|
" 6 end of Xxx
|
|
|
|
|
" 7 write
|
|
|
|
|
" 8 abc21
|
|
|
|
|
" 9 end of Xxx
|
|
|
|
|
|
|
|
|
|
let g:lines = []
|
|
|
|
|
au FileAppendCmd XtestD call extend(g:lines, getline(line("'["), line("']")))
|
|
|
|
|
w >>XtestD " will add lines to 'lines'
|
|
|
|
|
call assert_equal(9, len(g:lines))
|
|
|
|
|
call assert_fails('$r XtestD', 'E484') " should not read anything
|
|
|
|
|
call assert_equal(9, line('$'))
|
|
|
|
|
call assert_equal('end of Xxx', getline('$'))
|
|
|
|
|
|
|
|
|
|
au BufReadCmd XtestE 0r Xxx|$del
|
|
|
|
|
sp XtestE " split window with test.out
|
|
|
|
|
call assert_equal('end of Xxx', getline(3))
|
|
|
|
|
|
|
|
|
|
let g:lines = []
|
|
|
|
|
exe "normal 2Goasdf\<Esc>\<C-W>\<C-W>"
|
|
|
|
|
au BufWriteCmd XtestE call extend(g:lines, getline(0, '$'))
|
|
|
|
|
wall " will write other window to 'lines'
|
|
|
|
|
call assert_equal(4, len(g:lines), g:lines)
|
2022-07-09 15:59:58 -07:00
|
|
|
|
call assert_equal("asdf", g:lines[2])
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
au! BufReadCmd
|
|
|
|
|
au! BufWriteCmd
|
|
|
|
|
au! FileReadCmd
|
|
|
|
|
au! FileWriteCmd
|
|
|
|
|
au! FileAppendCmd
|
|
|
|
|
%bwipe!
|
|
|
|
|
enew!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-03-29 23:06:48 -07:00
|
|
|
|
func s:ReadFile()
|
|
|
|
|
setl noswapfile nomodified
|
|
|
|
|
let filename = resolve(expand("<afile>:p"))
|
|
|
|
|
execute 'read' fnameescape(filename)
|
|
|
|
|
1d_
|
|
|
|
|
exe 'file' fnameescape(filename)
|
|
|
|
|
setl buftype=acwrite
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func s:WriteFile()
|
|
|
|
|
let filename = resolve(expand("<afile>:p"))
|
|
|
|
|
setl buftype=
|
|
|
|
|
noautocmd execute 'write' fnameescape(filename)
|
|
|
|
|
setl buftype=acwrite
|
|
|
|
|
setl nomodified
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_BufReadCmd()
|
|
|
|
|
autocmd BufReadCmd *.test call s:ReadFile()
|
|
|
|
|
autocmd BufWriteCmd *.test call s:WriteFile()
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['one', 'two', 'three'], 'Xcmd.test', 'D')
|
2020-03-29 23:06:48 -07:00
|
|
|
|
edit Xcmd.test
|
|
|
|
|
call assert_match('Xcmd.test" line 1 of 3', execute('file'))
|
|
|
|
|
normal! Gofour
|
|
|
|
|
write
|
|
|
|
|
call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
au! BufReadCmd
|
|
|
|
|
au! BufWriteCmd
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-30 15:27:39 -07:00
|
|
|
|
func Test_BufWriteCmd()
|
|
|
|
|
autocmd BufWriteCmd Xbufwritecmd let g:written = 1
|
|
|
|
|
new
|
|
|
|
|
file Xbufwritecmd
|
|
|
|
|
set buftype=acwrite
|
2023-04-15 20:46:17 -07:00
|
|
|
|
call mkdir('Xbufwritecmd', 'D')
|
2022-08-30 15:27:39 -07:00
|
|
|
|
write
|
|
|
|
|
" BufWriteCmd should be triggered even if a directory has the same name
|
|
|
|
|
call assert_equal(1, g:written)
|
|
|
|
|
unlet g:written
|
|
|
|
|
au! BufWriteCmd
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2018-02-01 18:30:21 -07:00
|
|
|
|
func SetChangeMarks(start, end)
|
2021-01-16 18:44:13 -07:00
|
|
|
|
exe a:start .. 'mark ['
|
|
|
|
|
exe a:end .. 'mark ]'
|
2018-02-01 18:30:21 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Verify the effects of autocmds on '[ and ']
|
|
|
|
|
func Test_change_mark_in_autocmds()
|
|
|
|
|
edit! Xtest
|
2021-01-16 18:44:13 -07:00
|
|
|
|
call feedkeys("ia\<CR>b\<CR>c\<CR>d\<C-g>u\<Esc>", 'xtn')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
call SetChangeMarks(2, 3)
|
|
|
|
|
write
|
|
|
|
|
call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(2, 3)
|
|
|
|
|
au BufWritePre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
write
|
|
|
|
|
au! BufWritePre
|
|
|
|
|
|
2020-08-07 18:45:17 -07:00
|
|
|
|
if has('unix')
|
2018-02-01 18:30:21 -07:00
|
|
|
|
write XtestFilter
|
|
|
|
|
write >> XtestFilter
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(2, 3)
|
|
|
|
|
" Marks are set to the entire range of the write
|
|
|
|
|
au FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
" '[ is adjusted to just before the line that will receive the filtered
|
|
|
|
|
" data
|
|
|
|
|
au FilterReadPre * call assert_equal([4, 4], [line("'["), line("']")])
|
|
|
|
|
" The filtered data is read into the buffer, and the source lines are
|
|
|
|
|
" still present, so the range is after the source lines
|
|
|
|
|
au FilterReadPost * call assert_equal([5, 12], [line("'["), line("']")])
|
|
|
|
|
%!cat XtestFilter
|
|
|
|
|
" After the filtered data is read, the original lines are deleted
|
|
|
|
|
call assert_equal([1, 8], [line("'["), line("']")])
|
|
|
|
|
au! FilterWritePre,FilterReadPre,FilterReadPost
|
|
|
|
|
undo
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(1, 4)
|
|
|
|
|
au FilterWritePre * call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
au FilterReadPre * call assert_equal([3, 3], [line("'["), line("']")])
|
|
|
|
|
au FilterReadPost * call assert_equal([4, 11], [line("'["), line("']")])
|
|
|
|
|
2,3!cat XtestFilter
|
|
|
|
|
call assert_equal([2, 9], [line("'["), line("']")])
|
|
|
|
|
au! FilterWritePre,FilterReadPre,FilterReadPost
|
|
|
|
|
undo
|
|
|
|
|
|
|
|
|
|
call delete('XtestFilter')
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(1, 4)
|
|
|
|
|
au FileWritePre * call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
2,3write Xtest2
|
|
|
|
|
au! FileWritePre
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(2, 3)
|
|
|
|
|
au FileAppendPre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
write >> Xtest2
|
|
|
|
|
au! FileAppendPre
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(1, 4)
|
|
|
|
|
au FileAppendPre * call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
2,3write >> Xtest2
|
|
|
|
|
au! FileAppendPre
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(1, 1)
|
|
|
|
|
au FileReadPre * call assert_equal([3, 1], [line("'["), line("']")])
|
|
|
|
|
au FileReadPost * call assert_equal([4, 11], [line("'["), line("']")])
|
|
|
|
|
3read Xtest2
|
|
|
|
|
au! FileReadPre,FileReadPost
|
|
|
|
|
undo
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(4, 4)
|
|
|
|
|
" When the line is 0, it's adjusted to 1
|
|
|
|
|
au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
au FileReadPost * call assert_equal([1, 8], [line("'["), line("']")])
|
|
|
|
|
0read Xtest2
|
|
|
|
|
au! FileReadPre,FileReadPost
|
|
|
|
|
undo
|
|
|
|
|
|
|
|
|
|
call SetChangeMarks(4, 4)
|
|
|
|
|
" When the line is 0, it's adjusted to 1
|
|
|
|
|
au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
au FileReadPost * call assert_equal([2, 9], [line("'["), line("']")])
|
|
|
|
|
1read Xtest2
|
|
|
|
|
au! FileReadPre,FileReadPost
|
|
|
|
|
undo
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
call delete('Xtest')
|
|
|
|
|
call delete('Xtest2')
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_Filter_noshelltemp()
|
2022-11-07 04:40:30 -07:00
|
|
|
|
CheckExecutable cat
|
2018-02-01 18:30:21 -07:00
|
|
|
|
|
|
|
|
|
enew!
|
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
|
|
|
|
|
|
let shelltemp = &shelltemp
|
|
|
|
|
set shelltemp
|
|
|
|
|
|
|
|
|
|
let g:filter_au = 0
|
|
|
|
|
au FilterWritePre * let g:filter_au += 1
|
|
|
|
|
au FilterReadPre * let g:filter_au += 1
|
|
|
|
|
au FilterReadPost * let g:filter_au += 1
|
|
|
|
|
%!cat
|
|
|
|
|
call assert_equal(3, g:filter_au)
|
|
|
|
|
|
|
|
|
|
if has('filterpipe')
|
|
|
|
|
set noshelltemp
|
|
|
|
|
|
|
|
|
|
let g:filter_au = 0
|
|
|
|
|
au FilterWritePre * let g:filter_au += 1
|
|
|
|
|
au FilterReadPre * let g:filter_au += 1
|
|
|
|
|
au FilterReadPost * let g:filter_au += 1
|
|
|
|
|
%!cat
|
|
|
|
|
call assert_equal(0, g:filter_au)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
au! FilterWritePre,FilterReadPre,FilterReadPost
|
|
|
|
|
let &shelltemp = shelltemp
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_TextYankPost()
|
|
|
|
|
enew!
|
|
|
|
|
call setline(1, ['foo'])
|
|
|
|
|
|
|
|
|
|
let g:event = []
|
|
|
|
|
au TextYankPost * let g:event = copy(v:event)
|
|
|
|
|
|
|
|
|
|
call assert_equal({}, v:event)
|
|
|
|
|
call assert_fails('let v:event = {}', 'E46:')
|
|
|
|
|
call assert_fails('let v:event.mykey = 0', 'E742:')
|
|
|
|
|
|
|
|
|
|
norm "ayiw
|
|
|
|
|
call assert_equal(
|
2020-06-03 07:51:25 -07:00
|
|
|
|
\{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'a', 'operator': 'y', 'visual': v:false, 'regtype': 'v'},
|
2018-02-01 18:30:21 -07:00
|
|
|
|
\g:event)
|
|
|
|
|
norm y_
|
|
|
|
|
call assert_equal(
|
2020-06-03 07:51:25 -07:00
|
|
|
|
\{'regcontents': ['foo'], 'inclusive': v:false, 'regname': '', 'operator': 'y', 'visual': v:false, 'regtype': 'V'},
|
2018-02-01 18:30:21 -07:00
|
|
|
|
\g:event)
|
2020-06-12 21:46:43 -07:00
|
|
|
|
norm Vy
|
|
|
|
|
call assert_equal(
|
|
|
|
|
\{'regcontents': ['foo'], 'inclusive': v:true, 'regname': '', 'operator': 'y', 'visual': v:true, 'regtype': 'V'},
|
|
|
|
|
\g:event)
|
2018-02-01 18:30:21 -07:00
|
|
|
|
call feedkeys("\<C-V>y", 'x')
|
|
|
|
|
call assert_equal(
|
2020-06-03 07:51:25 -07:00
|
|
|
|
\{'regcontents': ['f'], 'inclusive': v:true, 'regname': '', 'operator': 'y', 'visual': v:true, 'regtype': "\x161"},
|
2018-02-01 18:30:21 -07:00
|
|
|
|
\g:event)
|
|
|
|
|
norm "xciwbar
|
|
|
|
|
call assert_equal(
|
2020-06-03 07:51:25 -07:00
|
|
|
|
\{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'x', 'operator': 'c', 'visual': v:false, 'regtype': 'v'},
|
2018-02-01 18:30:21 -07:00
|
|
|
|
\g:event)
|
|
|
|
|
norm "bdiw
|
|
|
|
|
call assert_equal(
|
2020-06-03 07:51:25 -07:00
|
|
|
|
\{'regcontents': ['bar'], 'inclusive': v:true, 'regname': 'b', 'operator': 'd', 'visual': v:false, 'regtype': 'v'},
|
2018-02-01 18:30:21 -07:00
|
|
|
|
\g:event)
|
|
|
|
|
|
|
|
|
|
call assert_equal({}, v:event)
|
|
|
|
|
|
|
|
|
|
au! TextYankPost
|
|
|
|
|
unlet g:event
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-01-28 21:06:30 -07:00
|
|
|
|
func Test_autocommand_all_events()
|
|
|
|
|
call assert_fails('au * * bwipe', 'E1155:')
|
|
|
|
|
call assert_fails('au * x bwipe', 'E1155:')
|
2022-10-05 06:30:25 -07:00
|
|
|
|
call assert_fails('au! * x bwipe', 'E1155:')
|
2018-08-14 21:27:03 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-02-16 15:08:13 -07:00
|
|
|
|
func Test_autocmd_user()
|
|
|
|
|
au User MyEvent let s:res = [expand("<afile>"), expand("<amatch>")]
|
|
|
|
|
doautocmd User MyEvent
|
|
|
|
|
call assert_equal(['MyEvent', 'MyEvent'], s:res)
|
|
|
|
|
au! User
|
|
|
|
|
unlet s:res
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-10-17 07:04:53 -07:00
|
|
|
|
function s:Before_test_dirchanged()
|
|
|
|
|
augroup test_dirchanged
|
|
|
|
|
autocmd!
|
|
|
|
|
augroup END
|
|
|
|
|
let s:li = []
|
|
|
|
|
let s:dir_this = getcwd()
|
2021-10-17 07:04:53 -07:00
|
|
|
|
let s:dir_foo = s:dir_this . '/Xfoo'
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call mkdir(s:dir_foo)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
let s:dir_bar = s:dir_this . '/Xbar'
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call mkdir(s:dir_bar)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
function s:After_test_dirchanged()
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call chdir(s:dir_this)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call delete(s:dir_foo, 'd')
|
|
|
|
|
call delete(s:dir_bar, 'd')
|
2021-10-17 07:04:53 -07:00
|
|
|
|
augroup test_dirchanged
|
|
|
|
|
autocmd!
|
|
|
|
|
augroup END
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
function Test_dirchanged_global()
|
|
|
|
|
call s:Before_test_dirchanged()
|
2022-02-16 15:08:13 -07:00
|
|
|
|
autocmd test_dirchanged DirChangedPre global call add(s:li, expand("<amatch>") .. " pre cd " .. v:event.directory)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
autocmd test_dirchanged DirChanged global call add(s:li, "cd:")
|
|
|
|
|
autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>"))
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call chdir(s:dir_foo)
|
2022-02-16 15:08:13 -07:00
|
|
|
|
let expected = ["global pre cd " .. s:dir_foo, "cd:", s:dir_foo]
|
2022-02-10 21:44:47 -07:00
|
|
|
|
call assert_equal(expected, s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call chdir(s:dir_foo)
|
2022-02-10 21:44:47 -07:00
|
|
|
|
call assert_equal(expected, s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
exe 'lcd ' .. fnameescape(s:dir_bar)
|
2022-02-10 21:44:47 -07:00
|
|
|
|
call assert_equal(expected, s:li)
|
2022-06-12 04:06:30 -07:00
|
|
|
|
|
|
|
|
|
exe 'cd ' .. s:dir_foo
|
|
|
|
|
exe 'cd ' .. s:dir_bar
|
|
|
|
|
autocmd! test_dirchanged DirChanged global let g:result = expand("<afile>")
|
|
|
|
|
cd -
|
2022-06-13 01:05:22 -07:00
|
|
|
|
call assert_equal(s:dir_foo, substitute(g:result, '\\', '/', 'g'))
|
2022-06-12 04:06:30 -07:00
|
|
|
|
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call s:After_test_dirchanged()
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
function Test_dirchanged_local()
|
|
|
|
|
call s:Before_test_dirchanged()
|
|
|
|
|
autocmd test_dirchanged DirChanged window call add(s:li, "lcd:")
|
|
|
|
|
autocmd test_dirchanged DirChanged window call add(s:li, expand("<afile>"))
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call chdir(s:dir_foo)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call assert_equal([], s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
exe 'lcd ' .. fnameescape(s:dir_bar)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call assert_equal(["lcd:", s:dir_bar], s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
exe 'lcd ' .. fnameescape(s:dir_bar)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call assert_equal(["lcd:", s:dir_bar], s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call s:After_test_dirchanged()
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
function Test_dirchanged_auto()
|
2021-10-17 07:04:53 -07:00
|
|
|
|
CheckFunction test_autochdir
|
|
|
|
|
CheckOption autochdir
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call s:Before_test_dirchanged()
|
|
|
|
|
call test_autochdir()
|
2022-02-10 21:44:47 -07:00
|
|
|
|
autocmd test_dirchanged DirChangedPre auto call add(s:li, "pre cd " .. v:event.directory)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
autocmd test_dirchanged DirChanged auto call add(s:li, "auto:")
|
|
|
|
|
autocmd test_dirchanged DirChanged auto call add(s:li, expand("<afile>"))
|
|
|
|
|
set acd
|
2021-10-17 07:04:53 -07:00
|
|
|
|
cd ..
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call assert_equal([], s:li)
|
2023-11-12 18:08:02 -07:00
|
|
|
|
exe 'edit ' . s:dir_foo . '/Xautofile'
|
2021-10-17 07:04:53 -07:00
|
|
|
|
call assert_equal(s:dir_foo, getcwd())
|
2022-02-10 21:44:47 -07:00
|
|
|
|
let expected = ["pre cd " .. s:dir_foo, "auto:", s:dir_foo]
|
|
|
|
|
call assert_equal(expected, s:li)
|
2021-10-17 07:04:53 -07:00
|
|
|
|
set noacd
|
|
|
|
|
bwipe!
|
|
|
|
|
call s:After_test_dirchanged()
|
|
|
|
|
endfunc
|
|
|
|
|
|
2018-02-11 06:37:14 -07:00
|
|
|
|
" Test TextChangedI and TextChangedP
|
2018-05-19 03:38:14 -07:00
|
|
|
|
func Test_ChangedP()
|
2023-09-27 03:51:40 -07:00
|
|
|
|
throw 'Skipped: use test/functional/autocmd/textchanged_spec.lua'
|
2018-02-11 06:37:14 -07:00
|
|
|
|
new
|
|
|
|
|
call setline(1, ['foo', 'bar', 'foobar'])
|
|
|
|
|
call test_override("char_avail", 1)
|
|
|
|
|
set complete=. completeopt=menuone
|
|
|
|
|
|
|
|
|
|
func! TextChangedAutocmd(char)
|
|
|
|
|
let g:autocmd .= a:char
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-09-27 03:51:40 -07:00
|
|
|
|
" TextChanged will not be triggered, only check that it isn't.
|
2018-02-11 06:37:14 -07:00
|
|
|
|
au! TextChanged <buffer> :call TextChangedAutocmd('N')
|
|
|
|
|
au! TextChangedI <buffer> :call TextChangedAutocmd('I')
|
|
|
|
|
au! TextChangedP <buffer> :call TextChangedAutocmd('P')
|
|
|
|
|
|
|
|
|
|
call cursor(3, 1)
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("o\<esc>", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('I', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("Sf", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('II', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("Sf\<C-N>", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('IIP', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("Sf\<C-N>\<C-N>", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('IIPP', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("Sf\<C-N>\<C-N>\<C-N>", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('IIPPP', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
let g:autocmd = ''
|
|
|
|
|
call feedkeys("Sf\<C-N>\<C-N>\<C-N>\<C-N>", 'tnix')
|
2023-10-27 19:42:18 -07:00
|
|
|
|
call assert_equal('IIPPPP', g:autocmd)
|
2018-02-11 06:37:14 -07:00
|
|
|
|
|
|
|
|
|
call assert_equal(['foo', 'bar', 'foobar', 'foo'], getline(1, '$'))
|
|
|
|
|
" TODO: how should it handle completeopt=noinsert,noselect?
|
|
|
|
|
|
|
|
|
|
" CleanUp
|
|
|
|
|
call test_override("char_avail", 0)
|
|
|
|
|
au! TextChanged
|
|
|
|
|
au! TextChangedI
|
|
|
|
|
au! TextChangedP
|
|
|
|
|
delfu TextChangedAutocmd
|
|
|
|
|
unlet! g:autocmd
|
|
|
|
|
set complete&vim completeopt&vim
|
|
|
|
|
|
|
|
|
|
bw!
|
|
|
|
|
endfunc
|
2018-08-08 16:02:32 -07:00
|
|
|
|
|
|
|
|
|
let g:setline_handled = v:false
|
2020-11-29 23:08:27 -07:00
|
|
|
|
func SetLineOne()
|
2018-08-08 16:02:32 -07:00
|
|
|
|
if !g:setline_handled
|
|
|
|
|
call setline(1, "(x)")
|
|
|
|
|
let g:setline_handled = v:true
|
|
|
|
|
endif
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_TextChangedI_with_setline()
|
2023-09-27 03:51:40 -07:00
|
|
|
|
throw 'Skipped: use test/functional/autocmd/textchanged_spec.lua'
|
2018-08-08 16:02:32 -07:00
|
|
|
|
new
|
|
|
|
|
call test_override('char_avail', 1)
|
|
|
|
|
autocmd TextChangedI <buffer> call SetLineOne()
|
|
|
|
|
call feedkeys("i(\<CR>\<Esc>", 'tx')
|
|
|
|
|
call assert_equal('(', getline(1))
|
|
|
|
|
call assert_equal('x)', getline(2))
|
|
|
|
|
undo
|
|
|
|
|
call assert_equal('', getline(1))
|
2018-08-08 16:11:32 -07:00
|
|
|
|
call assert_equal('', getline(2))
|
2018-08-08 16:02:32 -07:00
|
|
|
|
|
2024-02-09 15:53:26 -07:00
|
|
|
|
call test_override('char_avail', 0)
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_TextChanged_with_norm()
|
|
|
|
|
" For unknown reason this fails on MS-Windows
|
|
|
|
|
CheckNotMSWindows
|
|
|
|
|
CheckFeature terminal
|
|
|
|
|
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
|
|
|
|
|
call assert_equal('running', term_getstatus(buf))
|
|
|
|
|
call term_sendkeys(buf, ":let g:a=0\<cr>")
|
|
|
|
|
call term_wait(buf, 50)
|
|
|
|
|
call term_sendkeys(buf, ":au! TextChanged * :let g:a+=1\<cr>")
|
|
|
|
|
call term_wait(buf, 50)
|
|
|
|
|
call term_sendkeys(buf, ":norm! ia\<cr>")
|
|
|
|
|
call term_wait(buf, 50)
|
|
|
|
|
call term_sendkeys(buf, ":echo g:a\<cr>")
|
|
|
|
|
call term_wait(buf, 50)
|
|
|
|
|
call WaitForAssert({-> assert_match('^1.*$', term_getline(buf, 3))})
|
2018-08-08 16:02:32 -07:00
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
2018-08-14 22:13:38 -07:00
|
|
|
|
|
|
|
|
|
func Test_Changed_FirstTime()
|
2021-03-23 19:28:01 -07:00
|
|
|
|
CheckFeature terminal
|
|
|
|
|
CheckNotGui
|
|
|
|
|
" Starting a terminal to run Vim is always considered flaky.
|
2021-03-23 19:32:38 -07:00
|
|
|
|
let g:test_is_flaky = 1
|
2021-03-23 19:28:01 -07:00
|
|
|
|
|
2018-08-14 22:13:38 -07:00
|
|
|
|
" Prepare file for TextChanged event.
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile([''], 'Xchanged.txt', 'D')
|
2018-08-14 22:13:38 -07:00
|
|
|
|
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
|
|
|
|
|
call assert_equal('running', term_getstatus(buf))
|
2019-09-01 21:24:34 -07:00
|
|
|
|
" Wait for the ruler (in the status line) to be shown.
|
2023-11-12 22:24:10 -07:00
|
|
|
|
" In ConPTY, there is additional character which is drawn up to the width of
|
|
|
|
|
" the screen.
|
|
|
|
|
if has('conpty')
|
|
|
|
|
call WaitForAssert({-> assert_match('\<All.*$', term_getline(buf, 3))})
|
|
|
|
|
else
|
|
|
|
|
call WaitForAssert({-> assert_match('\<All$', term_getline(buf, 3))})
|
|
|
|
|
endif
|
2018-08-14 22:13:38 -07:00
|
|
|
|
" It's only adding autocmd, so that no event occurs.
|
|
|
|
|
call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>")
|
|
|
|
|
call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>")
|
2019-09-20 16:08:01 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))})
|
2018-08-14 22:13:38 -07:00
|
|
|
|
call assert_equal([''], readfile('Xchanged.txt'))
|
|
|
|
|
|
|
|
|
|
" clean up
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
2019-04-06 14:28:05 -07:00
|
|
|
|
|
|
|
|
|
func Test_autocmd_nested()
|
|
|
|
|
let g:did_nested = 0
|
|
|
|
|
augroup Testing
|
|
|
|
|
au WinNew * edit somefile
|
|
|
|
|
au BufNew * let g:did_nested = 1
|
|
|
|
|
augroup END
|
|
|
|
|
split
|
|
|
|
|
call assert_equal(0, g:did_nested)
|
|
|
|
|
close
|
|
|
|
|
bwipe! somefile
|
|
|
|
|
|
|
|
|
|
" old nested argument still works
|
|
|
|
|
augroup Testing
|
|
|
|
|
au!
|
|
|
|
|
au WinNew * nested edit somefile
|
|
|
|
|
au BufNew * let g:did_nested = 1
|
|
|
|
|
augroup END
|
|
|
|
|
split
|
|
|
|
|
call assert_equal(1, g:did_nested)
|
|
|
|
|
close
|
|
|
|
|
bwipe! somefile
|
|
|
|
|
|
|
|
|
|
" New ++nested argument works
|
|
|
|
|
augroup Testing
|
|
|
|
|
au!
|
|
|
|
|
au WinNew * ++nested edit somefile
|
|
|
|
|
au BufNew * let g:did_nested = 1
|
|
|
|
|
augroup END
|
|
|
|
|
split
|
|
|
|
|
call assert_equal(1, g:did_nested)
|
|
|
|
|
close
|
|
|
|
|
bwipe! somefile
|
|
|
|
|
|
|
|
|
|
augroup Testing
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
call assert_fails('au WinNew * ++nested ++nested echo bad', 'E983:')
|
|
|
|
|
call assert_fails('au WinNew * nested nested echo bad', 'E983:')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-23 02:45:45 -07:00
|
|
|
|
func Test_autocmd_nested_cursor_invalid()
|
|
|
|
|
set laststatus=0
|
|
|
|
|
copen
|
|
|
|
|
cclose
|
|
|
|
|
call setline(1, ['foo', 'bar', 'baz'])
|
|
|
|
|
3
|
|
|
|
|
augroup nested_inv
|
|
|
|
|
autocmd User foo ++nested copen
|
|
|
|
|
autocmd BufAdd * let &laststatus = 2 - &laststatus
|
|
|
|
|
augroup END
|
|
|
|
|
doautocmd User foo
|
|
|
|
|
|
|
|
|
|
augroup nested_inv
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
set laststatus&
|
2022-07-27 20:24:32 -07:00
|
|
|
|
cclose
|
2022-07-23 02:45:45 -07:00
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-27 20:27:58 -07:00
|
|
|
|
func Test_autocmd_nested_keeps_cursor_pos()
|
|
|
|
|
enew
|
|
|
|
|
call setline(1, 'foo')
|
|
|
|
|
autocmd User foo ++nested normal! $a
|
|
|
|
|
autocmd InsertLeave * :
|
|
|
|
|
doautocmd User foo
|
|
|
|
|
call assert_equal([0, 1, 3, 0], getpos('.'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-27 20:24:32 -07:00
|
|
|
|
func Test_autocmd_nested_switch_window()
|
|
|
|
|
" run this in a separate Vim so that SafeState works
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
vim9script
|
|
|
|
|
['()']->writefile('Xautofile')
|
|
|
|
|
autocmd VimEnter * ++nested edit Xautofile | split
|
|
|
|
|
autocmd BufReadPost * autocmd SafeState * ++once foldclosed('.')
|
|
|
|
|
autocmd WinEnter * matchadd('ErrorMsg', 'pat')
|
|
|
|
|
END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(lines, 'Xautoscript', 'D')
|
2022-07-27 20:24:32 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S Xautoscript', {'rows': 10})
|
|
|
|
|
call VerifyScreenDump(buf, 'Test_autocmd_nested_switch', {})
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete('Xautofile')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2019-04-06 14:28:05 -07:00
|
|
|
|
func Test_autocmd_once()
|
|
|
|
|
" Without ++once WinNew triggers twice
|
|
|
|
|
let g:did_split = 0
|
|
|
|
|
augroup Testing
|
|
|
|
|
au WinNew * let g:did_split += 1
|
|
|
|
|
augroup END
|
|
|
|
|
split
|
|
|
|
|
split
|
|
|
|
|
call assert_equal(2, g:did_split)
|
|
|
|
|
call assert_true(exists('#WinNew'))
|
|
|
|
|
close
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
" With ++once WinNew triggers once
|
|
|
|
|
let g:did_split = 0
|
|
|
|
|
augroup Testing
|
|
|
|
|
au!
|
|
|
|
|
au WinNew * ++once let g:did_split += 1
|
|
|
|
|
augroup END
|
|
|
|
|
split
|
|
|
|
|
split
|
|
|
|
|
call assert_equal(1, g:did_split)
|
|
|
|
|
call assert_false(exists('#WinNew'))
|
|
|
|
|
close
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
call assert_fails('au WinNew * ++once ++once echo bad', 'E983:')
|
|
|
|
|
endfunc
|
2019-04-26 04:04:10 -07:00
|
|
|
|
|
2019-05-08 09:01:21 -07:00
|
|
|
|
func Test_autocmd_bufreadpre()
|
|
|
|
|
new
|
|
|
|
|
let b:bufreadpre = 1
|
|
|
|
|
call append(0, range(100))
|
|
|
|
|
w! XAutocmdBufReadPre.txt
|
|
|
|
|
autocmd BufReadPre <buffer> :let b:bufreadpre += 1
|
|
|
|
|
norm! 50gg
|
|
|
|
|
sp
|
|
|
|
|
norm! 100gg
|
|
|
|
|
wincmd p
|
|
|
|
|
let g:wsv1 = winsaveview()
|
|
|
|
|
wincmd p
|
|
|
|
|
let g:wsv2 = winsaveview()
|
|
|
|
|
" triggers BufReadPre, should not move the cursor in either window
|
|
|
|
|
" The topline may change one line in a large window.
|
|
|
|
|
edit
|
|
|
|
|
call assert_inrange(g:wsv2.topline - 1, g:wsv2.topline + 1, winsaveview().topline)
|
|
|
|
|
call assert_equal(g:wsv2.lnum, winsaveview().lnum)
|
|
|
|
|
call assert_equal(2, b:bufreadpre)
|
|
|
|
|
wincmd p
|
|
|
|
|
call assert_equal(g:wsv1.topline, winsaveview().topline)
|
|
|
|
|
call assert_equal(g:wsv1.lnum, winsaveview().lnum)
|
|
|
|
|
call assert_equal(2, b:bufreadpre)
|
|
|
|
|
" Now set the cursor position in an BufReadPre autocommand
|
|
|
|
|
" (even though the position will be invalid, this should make Vim reset the
|
|
|
|
|
" cursor position in the other window.
|
|
|
|
|
wincmd p
|
2022-07-11 22:28:17 -07:00
|
|
|
|
1 " set cpo+=g
|
2019-05-08 09:01:21 -07:00
|
|
|
|
" won't do anything, but try to set the cursor on an invalid lnum
|
|
|
|
|
autocmd BufReadPre <buffer> :norm! 70gg
|
|
|
|
|
" triggers BufReadPre, should not move the cursor in either window
|
|
|
|
|
e
|
|
|
|
|
call assert_equal(1, winsaveview().topline)
|
|
|
|
|
call assert_equal(1, winsaveview().lnum)
|
|
|
|
|
call assert_equal(3, b:bufreadpre)
|
|
|
|
|
wincmd p
|
|
|
|
|
call assert_equal(g:wsv1.topline, winsaveview().topline)
|
|
|
|
|
call assert_equal(g:wsv1.lnum, winsaveview().lnum)
|
|
|
|
|
call assert_equal(3, b:bufreadpre)
|
|
|
|
|
close
|
|
|
|
|
close
|
|
|
|
|
call delete('XAutocmdBufReadPre.txt')
|
2023-02-17 15:52:56 -07:00
|
|
|
|
set cpo-=g
|
2019-05-08 09:01:21 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-11 22:28:17 -07:00
|
|
|
|
" FileChangedShell tested in test_filechanged.vim
|
|
|
|
|
|
2019-04-26 04:04:10 -07:00
|
|
|
|
" Tests for the following autocommands:
|
|
|
|
|
" - FileWritePre writing a compressed file
|
|
|
|
|
" - FileReadPost reading a compressed file
|
|
|
|
|
" - BufNewFile reading a file template
|
|
|
|
|
" - BufReadPre decompressing the file to be read
|
|
|
|
|
" - FilterReadPre substituting characters in the temp file
|
|
|
|
|
" - FilterReadPost substituting characters after filtering
|
|
|
|
|
" - FileReadPre set options for decompression
|
|
|
|
|
" - FileReadPost decompress the file
|
|
|
|
|
func Test_ReadWrite_Autocmds()
|
|
|
|
|
" Run this test only on Unix-like systems and if gzip is available
|
|
|
|
|
if !has('unix') || !executable("gzip")
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
" Make $GZIP empty, "-v" would cause trouble.
|
|
|
|
|
let $GZIP = ""
|
|
|
|
|
|
|
|
|
|
" Use a FileChangedShell autocommand to avoid a prompt for 'Xtestfile.gz'
|
|
|
|
|
" being modified outside of Vim (noticed on Solaris).
|
|
|
|
|
au FileChangedShell * echo 'caught FileChangedShell'
|
|
|
|
|
|
|
|
|
|
" Test for the FileReadPost, FileWritePre and FileWritePost autocmds
|
|
|
|
|
augroup Test1
|
|
|
|
|
au!
|
|
|
|
|
au FileWritePre *.gz '[,']!gzip
|
|
|
|
|
au FileWritePost *.gz undo
|
|
|
|
|
au FileReadPost *.gz '[,']!gzip -d
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
set bin
|
|
|
|
|
call append(0, [
|
|
|
|
|
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ])
|
|
|
|
|
1,9write! Xtestfile.gz
|
|
|
|
|
enew! | close
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
" Read and decompress the testfile
|
|
|
|
|
0read Xtestfile.gz
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ], getline(1, 9))
|
|
|
|
|
enew! | close
|
|
|
|
|
|
|
|
|
|
augroup Test1
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
" Test for the FileAppendPre and FileAppendPost autocmds
|
|
|
|
|
augroup Test2
|
|
|
|
|
au!
|
|
|
|
|
au BufNewFile *.c read Xtest.c
|
|
|
|
|
au FileAppendPre *.out '[,']s/new/NEW/
|
|
|
|
|
au FileAppendPost *.out !cat Xtest.c >> test.out
|
|
|
|
|
augroup END
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c', 'D')
|
2019-04-26 04:04:10 -07:00
|
|
|
|
new foo.c " should load Xtest.c
|
|
|
|
|
call assert_equal(['/*', ' * Here is a new .c file', ' */'], getline(2, 4))
|
|
|
|
|
w! >> test.out " append it to the output file
|
|
|
|
|
|
|
|
|
|
let contents = readfile('test.out')
|
|
|
|
|
call assert_equal(' * Here is a NEW .c file', contents[2])
|
|
|
|
|
call assert_equal(' * Here is a new .c file', contents[5])
|
|
|
|
|
|
|
|
|
|
call delete('test.out')
|
|
|
|
|
enew! | close
|
|
|
|
|
augroup Test2
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
" Test for the BufReadPre and BufReadPost autocmds
|
|
|
|
|
augroup Test3
|
|
|
|
|
au!
|
|
|
|
|
" setup autocommands to decompress before reading and re-compress
|
|
|
|
|
" afterwards
|
|
|
|
|
au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>"))
|
|
|
|
|
au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
|
|
|
|
|
au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r"))
|
|
|
|
|
au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r"))
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
e! Xtestfile.gz " Edit compressed file
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ], getline(1, 9))
|
|
|
|
|
|
|
|
|
|
w! >> test.out " Append it to the output file
|
|
|
|
|
|
|
|
|
|
augroup Test3
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
" Test for the FilterReadPre and FilterReadPost autocmds.
|
|
|
|
|
set shelltemp " need temp files here
|
|
|
|
|
augroup Test4
|
|
|
|
|
au!
|
|
|
|
|
au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t")
|
|
|
|
|
au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>"))
|
|
|
|
|
au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t'
|
|
|
|
|
au FilterReadPost *.out '[,']s/x/X/g
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
e! test.out " Edit the output file
|
|
|
|
|
1,$!cat
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'linE 2 AbcdefghijklmnopqrstuvwXyz',
|
|
|
|
|
\ 'linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
|
|
|
|
\ 'linE 4 AbcdefghijklmnopqrstuvwXyz',
|
|
|
|
|
\ 'linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
|
|
|
|
\ 'linE 6 AbcdefghijklmnopqrstuvwXyz',
|
|
|
|
|
\ 'linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
|
|
|
|
\ 'linE 8 AbcdefghijklmnopqrstuvwXyz',
|
|
|
|
|
\ 'linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
|
|
|
|
\ 'linE 10 AbcdefghijklmnopqrstuvwXyz'
|
|
|
|
|
\ ], getline(1, 9))
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ], readfile('test.out'))
|
|
|
|
|
|
|
|
|
|
augroup Test4
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
set shelltemp&vim
|
|
|
|
|
|
|
|
|
|
" Test for the FileReadPre and FileReadPost autocmds.
|
|
|
|
|
augroup Test5
|
|
|
|
|
au!
|
|
|
|
|
au FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>"))
|
|
|
|
|
au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))
|
|
|
|
|
au FileReadPost *.gz '[,']s/l/L/
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
0r Xtestfile.gz " Read compressed file
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'Line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'Line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'Line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'Line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'Line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ], getline(1, 9))
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ 'line 2 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 4 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 6 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 8 Abcdefghijklmnopqrstuvwxyz',
|
|
|
|
|
\ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
|
|
|
\ 'line 10 Abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
\ ], readfile('Xtestfile.gz'))
|
|
|
|
|
|
|
|
|
|
augroup Test5
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
au! FileChangedShell
|
|
|
|
|
call delete('Xtestfile.gz')
|
|
|
|
|
call delete('test.out')
|
|
|
|
|
endfunc
|
2019-06-08 04:58:04 -07:00
|
|
|
|
|
2019-08-04 16:54:17 -07:00
|
|
|
|
func Test_throw_in_BufWritePre()
|
|
|
|
|
new
|
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
|
call assert_false(filereadable('Xthefile'))
|
|
|
|
|
augroup throwing
|
|
|
|
|
au BufWritePre X* throw 'do not write'
|
|
|
|
|
augroup END
|
|
|
|
|
try
|
|
|
|
|
w Xthefile
|
|
|
|
|
catch
|
|
|
|
|
let caught = 1
|
|
|
|
|
endtry
|
|
|
|
|
call assert_equal(1, caught)
|
|
|
|
|
call assert_false(filereadable('Xthefile'))
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
au! throwing
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-03-25 17:27:29 -07:00
|
|
|
|
func Test_autocmd_in_try_block()
|
2023-04-15 20:46:17 -07:00
|
|
|
|
call mkdir('Xintrydir', 'R')
|
2022-03-25 17:27:29 -07:00
|
|
|
|
au BufEnter * let g:fname = expand('%')
|
|
|
|
|
try
|
2023-04-15 20:46:17 -07:00
|
|
|
|
edit Xintrydir/
|
2022-03-25 17:27:29 -07:00
|
|
|
|
endtry
|
2023-04-15 20:46:17 -07:00
|
|
|
|
call assert_match('Xintrydir', g:fname)
|
2022-03-25 17:27:29 -07:00
|
|
|
|
|
|
|
|
|
unlet g:fname
|
|
|
|
|
au! BufEnter
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-08-20 22:13:48 -07:00
|
|
|
|
func Test_autocmd_SafeState()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
let g:safe = 0
|
|
|
|
|
let g:again = ''
|
|
|
|
|
au SafeState * let g:safe += 1
|
|
|
|
|
au SafeStateAgain * let g:again ..= 'x'
|
|
|
|
|
func CallTimer()
|
|
|
|
|
call timer_start(10, {id -> execute('let g:again ..= "t"')})
|
|
|
|
|
endfunc
|
|
|
|
|
END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile(lines, 'XSafeState', 'D')
|
2023-08-20 22:13:48 -07:00
|
|
|
|
let buf = RunVimInTerminal('-S XSafeState', #{rows: 6})
|
|
|
|
|
|
2023-08-22 02:48:57 -07:00
|
|
|
|
" Sometimes we loop to handle a K_IGNORE, SafeState may be triggered once or
|
2023-08-21 00:21:00 -07:00
|
|
|
|
" more often.
|
2023-08-20 22:13:48 -07:00
|
|
|
|
call term_sendkeys(buf, ":echo g:safe\<CR>")
|
2023-08-21 00:21:00 -07:00
|
|
|
|
call WaitForAssert({-> assert_match('^\d ', term_getline(buf, 6))}, 1000)
|
2023-08-20 22:13:48 -07:00
|
|
|
|
|
2023-08-21 00:21:00 -07:00
|
|
|
|
" SafeStateAgain should be invoked at least three times
|
2023-08-20 22:13:48 -07:00
|
|
|
|
call term_sendkeys(buf, ":echo g:again\<CR>")
|
2023-08-21 00:21:00 -07:00
|
|
|
|
call WaitForAssert({-> assert_match('^xxx', term_getline(buf, 6))}, 1000)
|
2023-08-20 22:13:48 -07:00
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":let g:again = ''\<CR>:call CallTimer()\<CR>")
|
2023-08-20 23:59:52 -07:00
|
|
|
|
call TermWait(buf, 50)
|
2023-08-20 22:21:21 -07:00
|
|
|
|
call term_sendkeys(buf, ":\<CR>")
|
2023-08-20 23:59:52 -07:00
|
|
|
|
call TermWait(buf, 50)
|
2023-08-20 22:13:48 -07:00
|
|
|
|
call term_sendkeys(buf, ":echo g:again\<CR>")
|
|
|
|
|
call WaitForAssert({-> assert_match('xtx', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-09-14 22:49:54 -07:00
|
|
|
|
func Test_autocmd_CmdWinEnter()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
" There is not cmdwin switch, so
|
|
|
|
|
" test for cmdline_hist
|
|
|
|
|
" (both are available with small builds)
|
|
|
|
|
CheckFeature cmdline_hist
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
let b:dummy_var = 'This is a dummy'
|
|
|
|
|
autocmd CmdWinEnter * quit
|
|
|
|
|
let winnr = winnr('$')
|
|
|
|
|
END
|
2021-06-23 19:46:02 -07:00
|
|
|
|
let filename = 'XCmdWinEnter'
|
2020-09-14 22:49:54 -07:00
|
|
|
|
call writefile(lines, filename)
|
|
|
|
|
let buf = RunVimInTerminal('-S '.filename, #{rows: 6})
|
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "q:")
|
2023-08-20 23:59:52 -07:00
|
|
|
|
call TermWait(buf)
|
2020-09-14 22:49:54 -07:00
|
|
|
|
call term_sendkeys(buf, ":echo b:dummy_var\<cr>")
|
2023-01-21 05:50:46 -07:00
|
|
|
|
call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 2000)
|
2020-09-14 22:49:54 -07:00
|
|
|
|
call term_sendkeys(buf, ":echo &buftype\<cr>")
|
|
|
|
|
call WaitForAssert({-> assert_notmatch('^nofile', term_getline(buf, 6))}, 1000)
|
|
|
|
|
call term_sendkeys(buf, ":echo winnr\<cr>")
|
|
|
|
|
call WaitForAssert({-> assert_match('^1', term_getline(buf, 6))}, 1000)
|
|
|
|
|
|
|
|
|
|
" clean up
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
call delete(filename)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-11-23 19:48:55 -07:00
|
|
|
|
func Test_autocmd_was_using_freed_memory()
|
2023-11-12 22:31:30 -07:00
|
|
|
|
CheckFeature quickfix
|
|
|
|
|
|
2021-11-23 19:48:55 -07:00
|
|
|
|
pedit xx
|
|
|
|
|
n x
|
2021-11-23 20:58:44 -07:00
|
|
|
|
augroup winenter
|
|
|
|
|
au WinEnter * if winnr('$') > 2 | quit | endif
|
|
|
|
|
augroup END
|
2021-11-23 19:48:55 -07:00
|
|
|
|
" Nvim needs large 'winwidth' and 'nowinfixwidth' to crash
|
|
|
|
|
set winwidth=99999 nowinfixwidth
|
|
|
|
|
split
|
2021-11-23 20:58:44 -07:00
|
|
|
|
|
|
|
|
|
augroup winenter
|
|
|
|
|
au! WinEnter
|
|
|
|
|
augroup END
|
|
|
|
|
|
2021-11-23 19:48:55 -07:00
|
|
|
|
set winwidth& winfixwidth&
|
2021-11-23 20:58:44 -07:00
|
|
|
|
bwipe xx
|
|
|
|
|
bwipe x
|
|
|
|
|
pclose
|
2021-11-23 19:48:55 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2021-12-28 19:01:02 -07:00
|
|
|
|
func Test_BufWrite_lockmarks()
|
2023-08-21 00:30:20 -07:00
|
|
|
|
let g:test_is_flaky = 1
|
2021-12-28 19:01:02 -07:00
|
|
|
|
edit! Xtest
|
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
|
|
|
|
|
|
" :lockmarks preserves the marks
|
|
|
|
|
call SetChangeMarks(2, 3)
|
|
|
|
|
lockmarks write
|
|
|
|
|
call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
|
|
|
|
|
" *WritePre autocmds get the correct line range, but lockmarks preserves the
|
|
|
|
|
" original values for the user
|
|
|
|
|
augroup lockmarks
|
|
|
|
|
au!
|
|
|
|
|
au BufWritePre,FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")])
|
|
|
|
|
au FileWritePre * call assert_equal([3, 4], [line("'["), line("']")])
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
lockmarks write
|
|
|
|
|
call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
|
|
|
|
|
if executable('cat')
|
|
|
|
|
lockmarks %!cat
|
|
|
|
|
call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
lockmarks 3,4write Xtest2
|
|
|
|
|
call assert_equal([2, 3], [line("'["), line("']")])
|
|
|
|
|
|
|
|
|
|
au! lockmarks
|
|
|
|
|
augroup! lockmarks
|
|
|
|
|
call delete('Xtest')
|
|
|
|
|
call delete('Xtest2')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-13 00:49:33 -07:00
|
|
|
|
func Test_FileType_spell()
|
|
|
|
|
if !isdirectory('/tmp')
|
|
|
|
|
throw "Skipped: requires /tmp directory"
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
" this was crashing with an invalid free()
|
|
|
|
|
setglobal spellfile=/tmp/en.utf-8.add
|
|
|
|
|
augroup crash
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufNewFile,BufReadPost crashfile setf somefiletype
|
|
|
|
|
autocmd BufNewFile,BufReadPost crashfile set ft=anotherfiletype
|
|
|
|
|
autocmd FileType anotherfiletype setlocal spell
|
|
|
|
|
augroup END
|
|
|
|
|
func! NoCrash() abort
|
|
|
|
|
edit /tmp/crashfile
|
|
|
|
|
endfunc
|
|
|
|
|
call NoCrash()
|
|
|
|
|
|
|
|
|
|
au! crash
|
|
|
|
|
setglobal spellfile=
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-10-15 01:10:56 -07:00
|
|
|
|
" this was wiping out the current buffer and using freed memory
|
|
|
|
|
func Test_SpellFileMissing_bwipe()
|
|
|
|
|
next 0
|
|
|
|
|
au SpellFileMissing 0 bwipe
|
|
|
|
|
call assert_fails('set spell spelllang=0', 'E937:')
|
|
|
|
|
|
|
|
|
|
au! SpellFileMissing
|
2022-11-19 17:38:46 -07:00
|
|
|
|
set nospell spelllang=en
|
2022-10-15 01:10:56 -07:00
|
|
|
|
bwipe
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-11 22:28:17 -07:00
|
|
|
|
" Test closing a window or editing another buffer from a FileChangedRO handler
|
|
|
|
|
" in a readonly buffer
|
|
|
|
|
func Test_FileChangedRO_winclose()
|
|
|
|
|
augroup FileChangedROTest
|
|
|
|
|
au!
|
|
|
|
|
autocmd FileChangedRO * quit
|
|
|
|
|
augroup END
|
|
|
|
|
new
|
|
|
|
|
set readonly
|
|
|
|
|
call assert_fails('normal i', 'E788:')
|
|
|
|
|
close
|
|
|
|
|
augroup! FileChangedROTest
|
|
|
|
|
|
|
|
|
|
augroup FileChangedROTest
|
|
|
|
|
au!
|
2023-11-12 18:08:02 -07:00
|
|
|
|
autocmd FileChangedRO * edit Xrofile
|
2022-07-11 22:28:17 -07:00
|
|
|
|
augroup END
|
|
|
|
|
new
|
|
|
|
|
set readonly
|
|
|
|
|
call assert_fails('normal i', 'E788:')
|
|
|
|
|
close
|
|
|
|
|
augroup! FileChangedROTest
|
|
|
|
|
endfunc
|
2020-03-19 19:36:51 -07:00
|
|
|
|
|
2020-11-24 20:25:23 -07:00
|
|
|
|
func LogACmd()
|
|
|
|
|
call add(g:logged, line('$'))
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_TermChanged()
|
2020-11-24 20:30:01 -07:00
|
|
|
|
throw 'skipped: Nvim does not support TermChanged event'
|
|
|
|
|
CheckNotGui
|
|
|
|
|
|
2020-11-24 20:25:23 -07:00
|
|
|
|
enew!
|
|
|
|
|
tabnew
|
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
|
$
|
|
|
|
|
au TermChanged * call LogACmd()
|
|
|
|
|
let g:logged = []
|
|
|
|
|
let term_save = &term
|
|
|
|
|
set term=xterm
|
|
|
|
|
call assert_equal([1, 4], g:logged)
|
|
|
|
|
|
|
|
|
|
au! TermChanged
|
|
|
|
|
let &term = term_save
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-03-19 19:36:51 -07:00
|
|
|
|
" Test for FileReadCmd autocmd
|
|
|
|
|
func Test_autocmd_FileReadCmd()
|
|
|
|
|
func ReadFileCmd()
|
|
|
|
|
call append(line('$'), "v:cmdarg = " .. v:cmdarg)
|
|
|
|
|
endfunc
|
|
|
|
|
augroup FileReadCmdTest
|
|
|
|
|
au!
|
|
|
|
|
au FileReadCmd Xtest call ReadFileCmd()
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
read ++bin Xtest
|
|
|
|
|
read ++nobin Xtest
|
|
|
|
|
read ++edit Xtest
|
|
|
|
|
read ++bad=keep Xtest
|
|
|
|
|
read ++bad=drop Xtest
|
|
|
|
|
read ++bad=- Xtest
|
|
|
|
|
read ++ff=unix Xtest
|
|
|
|
|
read ++ff=dos Xtest
|
|
|
|
|
read ++ff=mac Xtest
|
|
|
|
|
read ++enc=utf-8 Xtest
|
|
|
|
|
|
|
|
|
|
call assert_equal(['',
|
|
|
|
|
\ 'v:cmdarg = ++bin',
|
|
|
|
|
\ 'v:cmdarg = ++nobin',
|
|
|
|
|
\ 'v:cmdarg = ++edit',
|
|
|
|
|
\ 'v:cmdarg = ++bad=keep',
|
|
|
|
|
\ 'v:cmdarg = ++bad=drop',
|
|
|
|
|
\ 'v:cmdarg = ++bad=-',
|
|
|
|
|
\ 'v:cmdarg = ++ff=unix',
|
|
|
|
|
\ 'v:cmdarg = ++ff=dos',
|
|
|
|
|
\ 'v:cmdarg = ++ff=mac',
|
|
|
|
|
\ 'v:cmdarg = ++enc=utf-8'], getline(1, '$'))
|
|
|
|
|
|
2023-04-18 20:08:24 -07:00
|
|
|
|
bwipe!
|
2020-03-19 19:36:51 -07:00
|
|
|
|
augroup FileReadCmdTest
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
delfunc ReadFileCmd
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-22 19:38:53 -07:00
|
|
|
|
" Test for passing invalid arguments to autocmd
|
|
|
|
|
func Test_autocmd_invalid_args()
|
|
|
|
|
" Additional character after * for event
|
2023-11-12 18:08:02 -07:00
|
|
|
|
call assert_fails('autocmd *a Xinvfile set ff=unix', 'E215:')
|
2022-08-22 19:38:53 -07:00
|
|
|
|
augroup Test
|
|
|
|
|
augroup END
|
|
|
|
|
" Invalid autocmd event
|
2023-11-12 18:08:02 -07:00
|
|
|
|
call assert_fails('autocmd Bufabc Xinvfile set ft=vim', 'E216:')
|
2022-08-22 19:38:53 -07:00
|
|
|
|
" Invalid autocmd event in a autocmd group
|
2023-11-12 18:08:02 -07:00
|
|
|
|
call assert_fails('autocmd Test Bufabc Xinvfile set ft=vim', 'E216:')
|
2022-08-22 19:38:53 -07:00
|
|
|
|
augroup! Test
|
|
|
|
|
" Execute all autocmds
|
|
|
|
|
call assert_fails('doautocmd * BufEnter', 'E217:')
|
|
|
|
|
call assert_fails('augroup! x1a2b3', 'E367:')
|
|
|
|
|
call assert_fails('autocmd BufNew <buffer=999> pwd', 'E680:')
|
2022-11-06 00:52:42 -07:00
|
|
|
|
call assert_fails('autocmd BufNew \) set ff=unix', 'E55:')
|
2022-08-22 19:38:53 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for deep nesting of autocmds
|
|
|
|
|
func Test_autocmd_deep_nesting()
|
2023-11-12 18:08:02 -07:00
|
|
|
|
autocmd BufEnter Xdeepfile doautocmd BufEnter Xdeepfile
|
|
|
|
|
call assert_fails('doautocmd BufEnter Xdeepfile', 'E218:')
|
|
|
|
|
autocmd! BufEnter Xdeepfile
|
2022-08-22 19:38:53 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2020-10-21 21:30:07 -07:00
|
|
|
|
" Tests for SigUSR1 autocmd event, which is only available on posix systems.
|
|
|
|
|
func Test_autocmd_sigusr1()
|
|
|
|
|
CheckUnix
|
|
|
|
|
|
|
|
|
|
let g:sigusr1_passed = 0
|
|
|
|
|
au Signal SIGUSR1 let g:sigusr1_passed = 1
|
2021-08-15 21:24:59 -07:00
|
|
|
|
call system('kill -s usr1 ' . getpid())
|
2020-10-21 21:30:07 -07:00
|
|
|
|
call WaitForAssert({-> assert_true(g:sigusr1_passed)})
|
|
|
|
|
|
|
|
|
|
au! Signal
|
|
|
|
|
unlet g:sigusr1_passed
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-08-19 06:40:22 -07:00
|
|
|
|
" Test for BufReadPre autocmd deleting the file
|
|
|
|
|
func Test_BufReadPre_delfile()
|
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
2023-08-21 01:27:14 -07:00
|
|
|
|
autocmd BufReadPre XbufreadPre call delete('XbufreadPre')
|
2022-08-19 06:40:22 -07:00
|
|
|
|
augroup END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile([], 'XbufreadPre', 'D')
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call assert_fails('new XbufreadPre', 'E200:')
|
|
|
|
|
call assert_equal('XbufreadPre', @%)
|
2022-08-19 06:40:22 -07:00
|
|
|
|
call assert_equal(1, &readonly)
|
2023-08-22 02:48:57 -07:00
|
|
|
|
|
2022-08-19 06:40:22 -07:00
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for BufReadPre autocmd changing the current buffer
|
|
|
|
|
func Test_BufReadPre_changebuf()
|
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
2023-08-21 01:27:14 -07:00
|
|
|
|
autocmd BufReadPre Xchangebuf edit Xsomeotherfile
|
2022-08-19 06:40:22 -07:00
|
|
|
|
augroup END
|
2023-08-22 02:48:57 -07:00
|
|
|
|
call writefile([], 'Xchangebuf', 'D')
|
2023-08-21 01:27:14 -07:00
|
|
|
|
call assert_fails('new Xchangebuf', 'E201:')
|
2022-08-19 06:40:22 -07:00
|
|
|
|
call assert_equal('Xsomeotherfile', @%)
|
|
|
|
|
call assert_equal(1, &readonly)
|
2023-08-22 02:48:57 -07:00
|
|
|
|
|
2022-08-19 06:40:22 -07:00
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test for BufWipeouti autocmd changing the current buffer when reading a file
|
|
|
|
|
" in an empty buffer with 'f' flag in 'cpo'
|
|
|
|
|
func Test_BufDelete_changebuf()
|
|
|
|
|
new
|
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
|
|
|
|
autocmd BufWipeout * let bufnr = bufadd('somefile') | exe "b " .. bufnr
|
|
|
|
|
augroup END
|
|
|
|
|
let save_cpo = &cpo
|
|
|
|
|
set cpo+=f
|
2022-11-04 16:24:06 -07:00
|
|
|
|
call assert_fails('r Xfile', ['E812:', 'E484:'])
|
2022-08-19 06:40:22 -07:00
|
|
|
|
call assert_equal('somefile', @%)
|
|
|
|
|
let &cpo = save_cpo
|
|
|
|
|
augroup TestAuCmd
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
close!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-11-25 00:27:10 -07:00
|
|
|
|
" Test for the temporary internal window used to execute autocmds
|
|
|
|
|
func Test_autocmd_window()
|
|
|
|
|
%bw!
|
|
|
|
|
edit one.txt
|
|
|
|
|
tabnew two.txt
|
2021-03-13 10:24:24 -07:00
|
|
|
|
vnew three.txt
|
|
|
|
|
tabnew four.txt
|
|
|
|
|
tabprevious
|
2020-11-25 00:27:10 -07:00
|
|
|
|
let g:blist = []
|
2021-03-13 10:24:24 -07:00
|
|
|
|
augroup aucmd_win_test1
|
2020-11-25 00:27:10 -07:00
|
|
|
|
au!
|
|
|
|
|
au BufEnter * call add(g:blist, [expand('<afile>'),
|
|
|
|
|
\ win_gettype(bufwinnr(expand('<afile>')))])
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
doautoall BufEnter
|
2021-03-13 10:24:24 -07:00
|
|
|
|
call assert_equal([
|
|
|
|
|
\ ['one.txt', 'autocmd'],
|
|
|
|
|
\ ['two.txt', ''],
|
|
|
|
|
\ ['four.txt', 'autocmd'],
|
|
|
|
|
\ ['three.txt', ''],
|
|
|
|
|
\ ], g:blist)
|
2020-11-25 00:27:10 -07:00
|
|
|
|
|
2021-03-13 10:24:24 -07:00
|
|
|
|
augroup aucmd_win_test1
|
2020-11-25 00:27:10 -07:00
|
|
|
|
au!
|
|
|
|
|
augroup END
|
2021-03-13 10:24:24 -07:00
|
|
|
|
augroup! aucmd_win_test1
|
2020-11-25 00:27:10 -07:00
|
|
|
|
%bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-10 00:56:42 -07:00
|
|
|
|
" Test for trying to close the temporary window used for executing an autocmd
|
|
|
|
|
func Test_close_autocmd_window()
|
|
|
|
|
%bw!
|
|
|
|
|
edit one.txt
|
|
|
|
|
tabnew two.txt
|
|
|
|
|
augroup aucmd_win_test2
|
|
|
|
|
au!
|
|
|
|
|
" Nvim makes aucmd_win the last window
|
|
|
|
|
" au BufEnter * if expand('<afile>') == 'one.txt' | 1close | endif
|
|
|
|
|
au BufEnter * if expand('<afile>') == 'one.txt' | close | endif
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
call assert_fails('doautoall BufEnter', 'E813:')
|
|
|
|
|
|
|
|
|
|
augroup aucmd_win_test2
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
augroup! aucmd_win_test2
|
|
|
|
|
%bw!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-05-11 18:20:32 -07:00
|
|
|
|
" Test for trying to close the tab that has the temporary window for exeucing
|
|
|
|
|
" an autocmd.
|
|
|
|
|
func Test_close_autocmd_tab()
|
|
|
|
|
edit one.txt
|
|
|
|
|
tabnew two.txt
|
|
|
|
|
augroup aucmd_win_test
|
|
|
|
|
au!
|
|
|
|
|
au BufEnter * if expand('<afile>') == 'one.txt' | tabfirst | tabonly | endif
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
call assert_fails('doautoall BufEnter', 'E813:')
|
|
|
|
|
|
|
|
|
|
tabonly
|
|
|
|
|
augroup aucmd_win_test
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
augroup! aucmd_win_test
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-07 10:33:01 -07:00
|
|
|
|
func Test_Visual_doautoall_redraw()
|
|
|
|
|
call setline(1, ['a', 'b'])
|
|
|
|
|
new
|
|
|
|
|
wincmd p
|
|
|
|
|
call feedkeys("G\<C-V>", 'txn')
|
|
|
|
|
autocmd User Explode ++once redraw
|
|
|
|
|
doautoall User Explode
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-10-05 06:33:08 -07:00
|
|
|
|
" This was using freed memory.
|
|
|
|
|
func Test_BufNew_arglocal()
|
|
|
|
|
arglocal
|
|
|
|
|
au BufNew * arglocal
|
|
|
|
|
call assert_fails('drop xx', 'E1156:')
|
|
|
|
|
|
|
|
|
|
au! BufNew
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-02-03 16:38:46 -07:00
|
|
|
|
func Test_autocmd_closes_window()
|
|
|
|
|
au BufNew,BufWinLeave * e %e
|
|
|
|
|
file yyy
|
|
|
|
|
au BufNew,BufWinLeave * ball
|
2022-04-19 18:18:39 -07:00
|
|
|
|
n xxx
|
2021-02-03 16:38:46 -07:00
|
|
|
|
|
2022-04-19 18:18:39 -07:00
|
|
|
|
%bwipe
|
2021-02-03 16:38:46 -07:00
|
|
|
|
au! BufNew
|
|
|
|
|
au! BufWinLeave
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-11-23 20:58:44 -07:00
|
|
|
|
func Test_autocmd_quit_psearch()
|
|
|
|
|
sn aa bb
|
|
|
|
|
augroup aucmd_win_test
|
|
|
|
|
au!
|
|
|
|
|
au BufEnter,BufLeave,BufNew,WinEnter,WinLeave,WinNew * if winnr('$') > 1 | q | endif
|
|
|
|
|
augroup END
|
|
|
|
|
ps /
|
|
|
|
|
|
|
|
|
|
augroup aucmd_win_test
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
2022-04-21 03:28:37 -07:00
|
|
|
|
new
|
|
|
|
|
pclose
|
2021-11-23 20:58:44 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-19 18:18:39 -07:00
|
|
|
|
" Fuzzer found some strange combination that caused a crash.
|
|
|
|
|
func Test_autocmd_normal_mess()
|
2022-04-19 20:09:20 -07:00
|
|
|
|
" For unknown reason this hangs on MS-Windows
|
|
|
|
|
CheckNotMSWindows
|
|
|
|
|
|
2022-04-19 18:18:39 -07:00
|
|
|
|
augroup aucmd_normal_test
|
|
|
|
|
au BufLeave,BufWinLeave,BufHidden,BufUnload,BufDelete,BufWipeout * norm 7q/qc
|
|
|
|
|
augroup END
|
|
|
|
|
" Nvim has removed :open
|
2022-04-19 19:05:02 -07:00
|
|
|
|
" call assert_fails('o4', 'E1159')
|
|
|
|
|
call assert_fails('e4', 'E1159')
|
2022-04-19 18:18:39 -07:00
|
|
|
|
silent! H
|
2022-04-19 19:05:02 -07:00
|
|
|
|
call assert_fails('e xx', 'E1159')
|
2022-04-19 18:18:39 -07:00
|
|
|
|
normal G
|
|
|
|
|
|
|
|
|
|
augroup aucmd_normal_test
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-05-11 19:27:21 -07:00
|
|
|
|
func Test_autocmd_closing_cmdwin()
|
2022-04-19 20:09:20 -07:00
|
|
|
|
" For unknown reason this hangs on MS-Windows
|
|
|
|
|
CheckNotMSWindows
|
|
|
|
|
|
2021-05-11 19:27:21 -07:00
|
|
|
|
au BufWinLeave * nested q
|
|
|
|
|
call assert_fails("norm 7q?\n", 'E855:')
|
|
|
|
|
|
|
|
|
|
au! BufWinLeave
|
|
|
|
|
new
|
|
|
|
|
only
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-19 18:44:12 -07:00
|
|
|
|
func Test_autocmd_vimgrep()
|
|
|
|
|
augroup aucmd_vimgrep
|
2022-04-19 20:11:39 -07:00
|
|
|
|
au QuickfixCmdPre,BufNew,BufReadCmd * sb
|
2022-04-21 03:28:37 -07:00
|
|
|
|
" Nvim makes aucmd_win the last window
|
|
|
|
|
" au QuickfixCmdPre,BufNew,BufReadCmd * q9
|
|
|
|
|
au QuickfixCmdPre,BufNew,BufReadCmd * exe 'q' .. (winnr('$') - (win_gettype(winnr('$')) == 'autocmd'))
|
2022-04-19 18:44:12 -07:00
|
|
|
|
augroup END
|
2022-04-19 20:09:20 -07:00
|
|
|
|
call assert_fails('lv ?a? foo', 'E926:')
|
2022-04-19 18:44:12 -07:00
|
|
|
|
|
|
|
|
|
augroup aucmd_vimgrep
|
|
|
|
|
au!
|
|
|
|
|
augroup END
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-09-22 21:41:09 -07:00
|
|
|
|
func Test_closing_autocmd_window()
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
edit Xa.txt
|
|
|
|
|
tabnew Xb.txt
|
|
|
|
|
autocmd BufEnter Xa.txt unhide 1
|
|
|
|
|
doautoall BufEnter
|
|
|
|
|
END
|
|
|
|
|
call CheckScriptFailure(lines, 'E814:')
|
|
|
|
|
au! BufEnter
|
|
|
|
|
bwipe Xa.txt
|
|
|
|
|
bwipe Xb.txt
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-09-24 14:50:03 -07:00
|
|
|
|
func Test_switch_window_in_autocmd_window()
|
|
|
|
|
edit Xa.txt
|
|
|
|
|
tabnew Xb.txt
|
|
|
|
|
autocmd BufEnter Xa.txt wincmd w
|
|
|
|
|
doautoall BufEnter
|
|
|
|
|
au! BufEnter
|
|
|
|
|
bwipe Xa.txt
|
|
|
|
|
call assert_false(bufexists('Xa.txt'))
|
|
|
|
|
bwipe Xb.txt
|
|
|
|
|
call assert_false(bufexists('Xb.txt'))
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-04-07 15:25:22 -07:00
|
|
|
|
" Test that using the autocommand window doesn't change current directory.
|
|
|
|
|
func Test_autocmd_window_cwd()
|
|
|
|
|
let saveddir = getcwd()
|
|
|
|
|
call mkdir('Xcwd/a/b/c/d', 'pR')
|
|
|
|
|
|
|
|
|
|
new Xa.txt
|
|
|
|
|
tabnew
|
|
|
|
|
new Xb.txt
|
|
|
|
|
|
|
|
|
|
tabprev
|
|
|
|
|
cd Xcwd
|
|
|
|
|
call assert_match('/Xcwd$', getcwd())
|
|
|
|
|
call assert_match('\[global\] .*/Xcwd$', trim(execute('verbose pwd')))
|
|
|
|
|
|
|
|
|
|
autocmd BufEnter Xb.txt lcd ./a/b/c/d
|
|
|
|
|
doautoall BufEnter
|
|
|
|
|
au! BufEnter
|
|
|
|
|
call assert_match('/Xcwd$', getcwd())
|
|
|
|
|
call assert_match('\[global\] .*/Xcwd$', trim(execute('verbose pwd')))
|
|
|
|
|
|
|
|
|
|
tabnext
|
|
|
|
|
cd ./a
|
|
|
|
|
tcd ./b
|
|
|
|
|
lcd ./c
|
|
|
|
|
call assert_match('/Xcwd/a/b/c$', getcwd())
|
|
|
|
|
call assert_match('\[window\] .*/Xcwd/a/b/c$', trim(execute('verbose pwd')))
|
|
|
|
|
|
|
|
|
|
autocmd BufEnter Xa.txt call assert_match('Xcwd/a/b/c$', getcwd())
|
|
|
|
|
doautoall BufEnter
|
|
|
|
|
au! BufEnter
|
|
|
|
|
call assert_match('/Xcwd/a/b/c$', getcwd())
|
|
|
|
|
call assert_match('\[window\] .*/Xcwd/a/b/c$', trim(execute('verbose pwd')))
|
|
|
|
|
bwipe!
|
|
|
|
|
call assert_match('/Xcwd/a/b$', getcwd())
|
|
|
|
|
call assert_match('\[tabpage\] .*/Xcwd/a/b$', trim(execute('verbose pwd')))
|
|
|
|
|
bwipe!
|
|
|
|
|
call assert_match('/Xcwd/a$', getcwd())
|
|
|
|
|
call assert_match('\[global\] .*/Xcwd/a$', trim(execute('verbose pwd')))
|
|
|
|
|
bwipe!
|
|
|
|
|
|
|
|
|
|
call chdir(saveddir)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-03-26 17:57:57 -07:00
|
|
|
|
func Test_bufwipeout_changes_window()
|
|
|
|
|
" This should not crash, but we don't have any expectations about what
|
|
|
|
|
" happens, changing window in BufWipeout has unpredictable results.
|
|
|
|
|
tabedit
|
|
|
|
|
let g:window_id = win_getid()
|
|
|
|
|
topleft new
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
autocmd BufWipeout <buffer> call win_gotoid(g:window_id)
|
|
|
|
|
tabprevious
|
|
|
|
|
+tabclose
|
|
|
|
|
|
|
|
|
|
unlet g:window_id
|
|
|
|
|
au! BufWipeout
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-10 03:45:11 -07:00
|
|
|
|
func Test_v_event_readonly()
|
|
|
|
|
autocmd CompleteChanged * let v:event.width = 0
|
|
|
|
|
call assert_fails("normal! i\<C-X>\<C-V>", 'E46:')
|
|
|
|
|
au! CompleteChanged
|
|
|
|
|
|
|
|
|
|
autocmd DirChangedPre * let v:event.directory = ''
|
|
|
|
|
call assert_fails('cd .', 'E46:')
|
|
|
|
|
au! DirChangedPre
|
|
|
|
|
|
|
|
|
|
autocmd ModeChanged * let v:event.new_mode = ''
|
|
|
|
|
call assert_fails('normal! cc', 'E46:')
|
|
|
|
|
au! ModeChanged
|
|
|
|
|
|
|
|
|
|
autocmd TextYankPost * let v:event.operator = ''
|
|
|
|
|
call assert_fails('normal! yy', 'E46:')
|
|
|
|
|
au! TextYankPost
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-07-26 15:19:59 -07:00
|
|
|
|
" Test for ModeChanged pattern
|
|
|
|
|
func Test_mode_changes()
|
|
|
|
|
let g:index = 0
|
2023-04-26 08:53:55 -07:00
|
|
|
|
let g:mode_seq = ['n', 'i', 'n', 'v', 'V', 'i', 'ix', 'i', 'ic', 'i', 'n', 'no', 'noV', 'n', 'V', 'v', 's', 'n']
|
2022-07-26 15:19:59 -07:00
|
|
|
|
func! TestMode()
|
|
|
|
|
call assert_equal(g:mode_seq[g:index], get(v:event, "old_mode"))
|
|
|
|
|
call assert_equal(g:mode_seq[g:index + 1], get(v:event, "new_mode"))
|
|
|
|
|
call assert_equal(mode(1), get(v:event, "new_mode"))
|
|
|
|
|
let g:index += 1
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
au ModeChanged * :call TestMode()
|
|
|
|
|
let g:n_to_any = 0
|
|
|
|
|
au ModeChanged n:* let g:n_to_any += 1
|
2023-04-26 08:53:55 -07:00
|
|
|
|
call feedkeys("i\<esc>vVca\<CR>\<C-X>\<C-L>\<esc>ggdV\<MouseMove>G", 'tnix')
|
2022-07-26 15:19:59 -07:00
|
|
|
|
|
|
|
|
|
let g:V_to_v = 0
|
|
|
|
|
au ModeChanged V:v let g:V_to_v += 1
|
|
|
|
|
call feedkeys("Vv\<C-G>\<esc>", 'tnix')
|
|
|
|
|
call assert_equal(len(filter(g:mode_seq[1:], {idx, val -> val == 'n'})), g:n_to_any)
|
|
|
|
|
call assert_equal(1, g:V_to_v)
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
|
|
|
|
|
|
|
|
|
let g:n_to_i = 0
|
|
|
|
|
au ModeChanged n:i let g:n_to_i += 1
|
|
|
|
|
let g:n_to_niI = 0
|
|
|
|
|
au ModeChanged i:niI let g:n_to_niI += 1
|
|
|
|
|
let g:niI_to_i = 0
|
|
|
|
|
au ModeChanged niI:i let g:niI_to_i += 1
|
|
|
|
|
let g:nany_to_i = 0
|
|
|
|
|
au ModeChanged n*:i let g:nany_to_i += 1
|
|
|
|
|
let g:i_to_n = 0
|
|
|
|
|
au ModeChanged i:n let g:i_to_n += 1
|
|
|
|
|
let g:nori_to_any = 0
|
|
|
|
|
au ModeChanged [ni]:* let g:nori_to_any += 1
|
|
|
|
|
let g:i_to_any = 0
|
|
|
|
|
au ModeChanged i:* let g:i_to_any += 1
|
|
|
|
|
let g:index = 0
|
|
|
|
|
let g:mode_seq = ['n', 'i', 'niI', 'i', 'n']
|
|
|
|
|
call feedkeys("a\<C-O>l\<esc>", 'tnix')
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
|
|
|
|
call assert_equal(1, g:n_to_i)
|
|
|
|
|
call assert_equal(1, g:n_to_niI)
|
|
|
|
|
call assert_equal(1, g:niI_to_i)
|
|
|
|
|
call assert_equal(2, g:nany_to_i)
|
|
|
|
|
call assert_equal(1, g:i_to_n)
|
|
|
|
|
call assert_equal(2, g:i_to_any)
|
|
|
|
|
call assert_equal(3, g:nori_to_any)
|
|
|
|
|
|
|
|
|
|
if has('terminal')
|
|
|
|
|
let g:mode_seq += ['c', 'n', 't', 'nt', 'c', 'nt', 'n']
|
|
|
|
|
call feedkeys(":term\<CR>\<C-W>N:bd!\<CR>", 'tnix')
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
|
|
|
|
call assert_equal(1, g:n_to_i)
|
|
|
|
|
call assert_equal(1, g:n_to_niI)
|
|
|
|
|
call assert_equal(1, g:niI_to_i)
|
|
|
|
|
call assert_equal(2, g:nany_to_i)
|
|
|
|
|
call assert_equal(1, g:i_to_n)
|
|
|
|
|
call assert_equal(2, g:i_to_any)
|
|
|
|
|
call assert_equal(5, g:nori_to_any)
|
|
|
|
|
endif
|
|
|
|
|
|
2022-10-18 16:05:54 -07:00
|
|
|
|
let g:n_to_c = 0
|
|
|
|
|
au ModeChanged n:c let g:n_to_c += 1
|
|
|
|
|
let g:c_to_n = 0
|
|
|
|
|
au ModeChanged c:n let g:c_to_n += 1
|
|
|
|
|
let g:mode_seq += ['c', 'n', 'c', 'n']
|
|
|
|
|
call feedkeys("q:\<C-C>\<Esc>", 'tnix')
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
|
|
|
|
call assert_equal(2, g:n_to_c)
|
|
|
|
|
call assert_equal(2, g:c_to_n)
|
|
|
|
|
|
|
|
|
|
let g:n_to_v = 0
|
|
|
|
|
au ModeChanged n:v let g:n_to_v += 1
|
|
|
|
|
let g:v_to_n = 0
|
|
|
|
|
au ModeChanged v:n let g:v_to_n += 1
|
|
|
|
|
let g:mode_seq += ['v', 'n']
|
|
|
|
|
call feedkeys("v\<C-C>", 'tnix')
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
|
|
|
|
call assert_equal(1, g:n_to_v)
|
|
|
|
|
call assert_equal(1, g:v_to_n)
|
2023-11-28 15:51:00 -07:00
|
|
|
|
|
|
|
|
|
let g:mode_seq += ['c', 'cr', 'c', 'cr', 'n']
|
|
|
|
|
call feedkeys(":\<Insert>\<Insert>\<Insert>\<CR>", 'tnix')
|
|
|
|
|
call assert_equal(len(g:mode_seq) - 1, g:index)
|
2022-07-26 15:19:59 -07:00
|
|
|
|
|
|
|
|
|
au! ModeChanged
|
|
|
|
|
delfunc TestMode
|
|
|
|
|
unlet! g:mode_seq
|
|
|
|
|
unlet! g:index
|
|
|
|
|
unlet! g:n_to_any
|
|
|
|
|
unlet! g:V_to_v
|
|
|
|
|
unlet! g:n_to_i
|
|
|
|
|
unlet! g:n_to_niI
|
|
|
|
|
unlet! g:niI_to_i
|
|
|
|
|
unlet! g:nany_to_i
|
|
|
|
|
unlet! g:i_to_n
|
|
|
|
|
unlet! g:nori_to_any
|
|
|
|
|
unlet! g:i_to_any
|
2023-11-28 15:51:00 -07:00
|
|
|
|
unlet! g:n_to_c
|
|
|
|
|
unlet! g:c_to_n
|
|
|
|
|
unlet! g:n_to_v
|
|
|
|
|
unlet! g:v_to_n
|
2022-07-26 15:19:59 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_recursive_ModeChanged()
|
|
|
|
|
au! ModeChanged * norm 0u
|
|
|
|
|
sil! norm
|
|
|
|
|
au! ModeChanged
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_ModeChanged_starts_visual()
|
|
|
|
|
" This was triggering ModeChanged before setting VIsual, causing a crash.
|
|
|
|
|
au! ModeChanged * norm 0u
|
|
|
|
|
sil! norm
|
|
|
|
|
|
|
|
|
|
au! ModeChanged
|
|
|
|
|
endfunc
|
2022-03-26 17:57:57 -07:00
|
|
|
|
|
2022-04-19 20:11:39 -07:00
|
|
|
|
func Test_noname_autocmd()
|
|
|
|
|
augroup test_noname_autocmd_group
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufEnter * call add(s:li, ["BufEnter", expand("<afile>")])
|
|
|
|
|
autocmd BufDelete * call add(s:li, ["BufDelete", expand("<afile>")])
|
|
|
|
|
autocmd BufLeave * call add(s:li, ["BufLeave", expand("<afile>")])
|
|
|
|
|
autocmd BufUnload * call add(s:li, ["BufUnload", expand("<afile>")])
|
|
|
|
|
autocmd BufWipeout * call add(s:li, ["BufWipeout", expand("<afile>")])
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
let s:li = []
|
|
|
|
|
edit foo
|
|
|
|
|
call assert_equal([['BufUnload', ''], ['BufDelete', ''], ['BufWipeout', ''], ['BufEnter', 'foo']], s:li)
|
|
|
|
|
|
|
|
|
|
au! test_noname_autocmd_group
|
|
|
|
|
augroup! test_noname_autocmd_group
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-10-18 16:10:22 -07:00
|
|
|
|
func Test_autocmd_split_dummy()
|
|
|
|
|
" Autocommand trying to split a window containing a dummy buffer.
|
|
|
|
|
auto BufReadPre * exe "sbuf " .. expand("<abuf>")
|
|
|
|
|
" Avoid the "W11" prompt
|
|
|
|
|
au FileChangedShell * let v:fcs_choice = 'reload'
|
|
|
|
|
func Xautocmd_changelist()
|
|
|
|
|
cal writefile(['Xtestfile2:4:4'], 'Xerr')
|
|
|
|
|
edit Xerr
|
|
|
|
|
lex 'Xtestfile2:4:4'
|
|
|
|
|
endfunc
|
|
|
|
|
call Xautocmd_changelist()
|
2022-10-18 16:15:08 -07:00
|
|
|
|
" Should get E86, but it doesn't always happen (timing?)
|
|
|
|
|
silent! call Xautocmd_changelist()
|
2022-10-18 16:10:22 -07:00
|
|
|
|
|
|
|
|
|
au! BufReadPre
|
|
|
|
|
au! FileChangedShell
|
|
|
|
|
delfunc Xautocmd_changelist
|
|
|
|
|
bwipe! Xerr
|
|
|
|
|
call delete('Xerr')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-11-29 03:20:11 -07:00
|
|
|
|
" This was crashing because there was only one window to execute autocommands
|
|
|
|
|
" in.
|
|
|
|
|
func Test_autocmd_nested_setbufvar()
|
|
|
|
|
CheckFeature python3
|
|
|
|
|
|
|
|
|
|
set hidden
|
|
|
|
|
edit Xaaa
|
|
|
|
|
edit Xbbb
|
|
|
|
|
call setline(1, 'bar')
|
|
|
|
|
enew
|
|
|
|
|
au BufWriteCmd Xbbb ++nested call setbufvar('Xaaa', '&ft', 'foo') | bw! Xaaa
|
|
|
|
|
au FileType foo call py3eval('vim.current.buffer.options["cindent"]')
|
|
|
|
|
wall
|
|
|
|
|
|
|
|
|
|
au! BufWriteCmd
|
|
|
|
|
au! FileType foo
|
|
|
|
|
set nohidden
|
|
|
|
|
call delete('Xaaa')
|
|
|
|
|
call delete('Xbbb')
|
|
|
|
|
%bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2023-04-15 09:16:36 -07:00
|
|
|
|
func SetupVimTest_shm()
|
|
|
|
|
let g:bwe = []
|
|
|
|
|
let g:brp = []
|
2023-09-25 03:26:01 -07:00
|
|
|
|
set shortmess-=l
|
2023-04-15 16:27:11 -07:00
|
|
|
|
messages clear
|
2023-04-15 09:16:36 -07:00
|
|
|
|
|
|
|
|
|
let dirname='XVimTestSHM'
|
|
|
|
|
call mkdir(dirname, 'R')
|
|
|
|
|
call writefile(['test'], dirname .. '/1')
|
|
|
|
|
call writefile(['test'], dirname .. '/2')
|
|
|
|
|
call writefile(['test'], dirname .. '/3')
|
|
|
|
|
|
|
|
|
|
augroup test
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd BufWinEnter * call add(g:bwe, $'BufWinEnter: {expand('<amatch>')}')
|
|
|
|
|
autocmd BufReadPost * call add(g:brp, $'BufReadPost: {expand('<amatch>')}')
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
call setqflist([
|
|
|
|
|
\ {'filename': dirname .. '/1', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0},
|
|
|
|
|
\ {'filename': dirname .. '/2', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0},
|
|
|
|
|
\ {'filename': dirname .. '/3', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0}
|
|
|
|
|
\ ])
|
|
|
|
|
cdo! substitute/test/TEST
|
|
|
|
|
|
|
|
|
|
" clean up
|
|
|
|
|
noa enew!
|
|
|
|
|
set shortmess&vim
|
|
|
|
|
augroup test
|
|
|
|
|
autocmd!
|
|
|
|
|
augroup END
|
|
|
|
|
augroup! test
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func Test_autocmd_shortmess()
|
|
|
|
|
CheckNotMSWindows
|
|
|
|
|
|
|
|
|
|
call SetupVimTest_shm()
|
|
|
|
|
let output = execute(':mess')->split('\n')
|
|
|
|
|
|
|
|
|
|
let info = copy(output)->filter({idx, val -> val =~# '\d of 3'} )
|
|
|
|
|
let bytes = copy(output)->filter({idx, val -> val =~# 'bytes'} )
|
|
|
|
|
|
|
|
|
|
" We test the following here:
|
|
|
|
|
" BufReadPost should have been triggered 3 times, once per file
|
|
|
|
|
" BufWinEnter should have been triggered 3 times, once per file
|
|
|
|
|
" FileInfoMessage should have been shown 3 times, regardless of shm option
|
|
|
|
|
" "(x of 3)" message from :cnext has been shown 3 times
|
|
|
|
|
|
|
|
|
|
call assert_equal(3, g:brp->len())
|
|
|
|
|
call assert_equal(3, g:bwe->len())
|
|
|
|
|
call assert_equal(3, info->len())
|
|
|
|
|
call assert_equal(3, bytes->len())
|
|
|
|
|
|
|
|
|
|
delfunc SetupVimTest_shm
|
|
|
|
|
endfunc
|
2022-11-29 03:20:11 -07:00
|
|
|
|
|
2024-02-15 15:35:30 -07:00
|
|
|
|
func Test_autocmd_invalidates_undo_on_textchanged()
|
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
let script =<< trim END
|
|
|
|
|
set hidden
|
|
|
|
|
" create quickfix list (at least 2 lines to move line)
|
|
|
|
|
vimgrep /u/j %
|
|
|
|
|
|
|
|
|
|
" enter quickfix window
|
|
|
|
|
cwindow
|
|
|
|
|
|
|
|
|
|
" set modifiable
|
|
|
|
|
setlocal modifiable
|
|
|
|
|
|
|
|
|
|
" set autocmd to clear quickfix list
|
|
|
|
|
|
|
|
|
|
autocmd! TextChanged <buffer> call setqflist([])
|
|
|
|
|
" move line
|
|
|
|
|
move+1
|
|
|
|
|
END
|
|
|
|
|
call writefile(script, 'XTest_autocmd_invalidates_undo_on_textchanged', 'D')
|
|
|
|
|
let buf = RunVimInTerminal('XTest_autocmd_invalidates_undo_on_textchanged', {'rows': 20})
|
|
|
|
|
call term_sendkeys(buf, ":so %\<cr>")
|
|
|
|
|
call term_sendkeys(buf, "G")
|
|
|
|
|
call WaitForAssert({-> assert_match('^XTest_autocmd_invalidates_undo_on_textchanged\s*$', term_getline(buf, 20))}, 1000)
|
|
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
|
endfunc
|
|
|
|
|
|
vim-patch:9.1.0143: [security]: autocmd causes use-after-free in set_curbuf() (#27664)
Problem: [security]: autocmd cause use-after-free in set_curbuf()
(kawarimidoll)
Solution: check side-effect of BufLeave autocommand, when the number
of windows changed, close windows containing buffers that will
be wiped, if curbuf changed unexpectedly make sure b_nwindows
is decremented otherwise it cannot be wiped
set_curbuf() already makes some efforts to ensure the BufLeave
autocommands do not cause issues. However there are still 2 issues
that are not taken care of:
1) If a BufLeave autocommand opens a new window containing the same
buffer as that is going got be closed in close_buffer() a bit later,
we suddenly have another window open, containing a free'd buffer. So we
must check if the number of windows changed and if it does (and the
current buffer is going to be wiped (according to the 'bufhidden'
setting), let's immediately close all windows containing the current
buffer using close_windows()
2) If a BufLeave autocommand changes our current buffer (displays it in
the current window), buf->b_nwindow will be incremented. As part of
set_curbuf() we will however enter another buffer soon, which means, the
newly created curbuf will have b_nwindows still have set, even so the
buffer is no longer displayed in a window. This causes later problems,
because it will no longer be possible to wipe such a buffer. So just
before entering the final buffer, check if the curbuf changed when
calling the BufLeave autocommand and if it does (and curbuf is still
valid), decrement curbuf->b_nwindows.
Both issues can be verified using the provided test (however the second
issue only because such an impacted buffer won't be wiped, causing
futher issues in later tests).
fixes: vim/vim#13839
closes: vim/vim#14104
https://github.com/vim/vim/commit/55f8bba73be5f9c3a5a4d0d6c5f56e65f2c7d3fc
Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-02-28 17:33:02 -07:00
|
|
|
|
func Test_autocmd_creates_new_buffer_on_bufleave()
|
|
|
|
|
e a.txt
|
|
|
|
|
e b.txt
|
|
|
|
|
setlocal bufhidden=wipe
|
|
|
|
|
autocmd BufLeave <buffer> diffsplit c.txt
|
|
|
|
|
bn
|
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
|
call assert_equal('a.txt', bufname('%'))
|
|
|
|
|
bw a.txt
|
|
|
|
|
bw c.txt
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-03-26 14:41:41 -07:00
|
|
|
|
" Ensure `expected` was just recently written as a Vim session
|
|
|
|
|
func s:assert_session_path(expected)
|
|
|
|
|
call assert_equal(a:expected, v:this_session)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Check for `expected` after a session is written to-disk.
|
|
|
|
|
func s:watch_for_session_path(expected)
|
|
|
|
|
execute 'autocmd SessionWritePost * ++once execute "call s:assert_session_path(\"'
|
|
|
|
|
\ . a:expected
|
|
|
|
|
\ . '\")"'
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Ensure v:this_session gets the full session path, if explicitly stated
|
|
|
|
|
func Test_explicit_session_absolute_path()
|
|
|
|
|
%bwipeout!
|
|
|
|
|
|
|
|
|
|
let directory = getcwd()
|
|
|
|
|
|
|
|
|
|
let v:this_session = ""
|
|
|
|
|
let name = "some_file.vim"
|
|
|
|
|
let expected = fnamemodify(name, ":p")
|
|
|
|
|
call s:watch_for_session_path(expected)
|
|
|
|
|
execute "mksession! " .. expected
|
|
|
|
|
|
|
|
|
|
call delete(expected)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Ensure v:this_session gets the full session path, if explicitly stated
|
|
|
|
|
func Test_explicit_session_relative_path()
|
|
|
|
|
%bwipeout!
|
|
|
|
|
|
|
|
|
|
let directory = getcwd()
|
|
|
|
|
|
|
|
|
|
let v:this_session = ""
|
|
|
|
|
let name = "some_file.vim"
|
|
|
|
|
let expected = fnamemodify(name, ":p")
|
|
|
|
|
call s:watch_for_session_path(expected)
|
|
|
|
|
execute "mksession! " .. name
|
|
|
|
|
|
|
|
|
|
call delete(expected)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Ensure v:this_session gets the full session path, if not specified
|
|
|
|
|
func Test_implicit_session()
|
|
|
|
|
%bwipeout!
|
|
|
|
|
|
|
|
|
|
let directory = getcwd()
|
|
|
|
|
|
|
|
|
|
let v:this_session = ""
|
|
|
|
|
let expected = fnamemodify("Session.vim", ":p")
|
|
|
|
|
call s:watch_for_session_path(expected)
|
|
|
|
|
mksession!
|
|
|
|
|
|
|
|
|
|
call delete(expected)
|
|
|
|
|
endfunc
|
|
|
|
|
|
2024-03-31 14:39:52 -07:00
|
|
|
|
" Test TextChangedI and TextChanged
|
2024-04-03 15:11:17 -07:00
|
|
|
|
func Test_Changed_ChangedI()
|
2024-04-01 06:49:44 -07:00
|
|
|
|
" Run this test in a terminal because it requires running the main loop.
|
2024-04-03 15:11:17 -07:00
|
|
|
|
" Don't use CheckRunVimInTerminal as that will skip the test on Windows.
|
|
|
|
|
CheckFeature terminal
|
|
|
|
|
CheckNotGui
|
|
|
|
|
" Starting a terminal to run Vim is always considered flaky.
|
|
|
|
|
let g:test_is_flaky = 1
|
|
|
|
|
|
2024-03-31 14:39:52 -07:00
|
|
|
|
call writefile(['one', 'two', 'three'], 'XTextChangedI2', 'D')
|
|
|
|
|
let before =<< trim END
|
2024-04-03 15:11:17 -07:00
|
|
|
|
set ttimeout ttimeoutlen=10
|
2024-04-01 06:49:44 -07:00
|
|
|
|
let [g:autocmd_n, g:autocmd_i] = ['','']
|
|
|
|
|
|
|
|
|
|
func TextChangedAutocmd(char)
|
|
|
|
|
let g:autocmd_{tolower(a:char)} = a:char .. b:changedtick
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call writefile([$'{g:autocmd_n},{g:autocmd_i}'], 'XTextChangedI3')
|
2024-04-01 06:49:44 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
au TextChanged <buffer> :call TextChangedAutocmd('N')
|
|
|
|
|
au TextChangedI <buffer> :call TextChangedAutocmd('I')
|
|
|
|
|
|
2024-03-31 14:39:52 -07:00
|
|
|
|
nnoremap <CR> o<Esc>
|
2024-04-04 16:24:25 -07:00
|
|
|
|
autocmd SafeState * ++once call writefile([''], 'XTextChangedI3')
|
2024-03-31 14:39:52 -07:00
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
call writefile(before, 'Xinit', 'D')
|
2024-04-03 15:11:17 -07:00
|
|
|
|
let buf = term_start(
|
|
|
|
|
\ GetVimCommandCleanTerm() .. '-n -S Xinit XTextChangedI2',
|
|
|
|
|
\ {'term_rows': 10})
|
|
|
|
|
call assert_equal('running', term_getstatus(buf))
|
2024-04-01 06:49:44 -07:00
|
|
|
|
call WaitForAssert({-> assert_true(filereadable('XTextChangedI3'))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
defer delete('XTextChangedI3')
|
2024-04-04 16:24:25 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal([''], readfile('XTextChangedI3'))})
|
2024-03-31 14:39:52 -07:00
|
|
|
|
|
2024-04-03 15:11:17 -07:00
|
|
|
|
" TextChanged should trigger if a mapping enters and leaves Insert mode.
|
|
|
|
|
call term_sendkeys(buf, "\<CR>")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "i")
|
|
|
|
|
call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
" TextChangedI should trigger if change is done in Insert mode.
|
|
|
|
|
call term_sendkeys(buf, "f")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,I5', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call term_sendkeys(buf, "o")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,I6', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call term_sendkeys(buf, "o")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
" TextChanged shouldn't trigger when leaving Insert mode and TextChangedI
|
|
|
|
|
" has been triggered.
|
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
|
|
|
|
|
" TextChanged should trigger if change is done in Normal mode.
|
|
|
|
|
call term_sendkeys(buf, "yyp")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
|
|
|
|
|
" TextChangedI shouldn't trigger if change isn't done in Insert mode.
|
|
|
|
|
call term_sendkeys(buf, "i")
|
|
|
|
|
call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
|
|
|
|
|
" TextChangedI should trigger if change is a mix of Normal and Insert modes.
|
|
|
|
|
func! s:validate_mixed_textchangedi(buf, keys)
|
|
|
|
|
let buf = a:buf
|
|
|
|
|
call term_sendkeys(buf, "ifoo")
|
|
|
|
|
call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))})
|
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))})
|
|
|
|
|
call term_sendkeys(buf, ":let [g:autocmd_n, g:autocmd_i] = ['', '']\<CR>")
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call writefile([], 'XTextChangedI3')
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call term_sendkeys(buf, a:keys)
|
|
|
|
|
call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))})
|
2024-04-05 14:59:04 -07:00
|
|
|
|
call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')->join("\n"))})
|
2024-04-03 15:11:17 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "o")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "O")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "ciw")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "cc")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "C")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "s")
|
|
|
|
|
call s:validate_mixed_textchangedi(buf, "S")
|
|
|
|
|
|
|
|
|
|
" clean up
|
|
|
|
|
bwipe!
|
2024-03-31 14:39:52 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2024-03-31 15:12:11 -07:00
|
|
|
|
" Test that filetype detection still works when SwapExists autocommand sets
|
|
|
|
|
" filetype in another buffer.
|
|
|
|
|
func Test_SwapExists_set_other_buf_filetype()
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set nocompatible directory=.
|
|
|
|
|
filetype on
|
|
|
|
|
|
|
|
|
|
let g:buf = bufnr()
|
|
|
|
|
new
|
|
|
|
|
|
|
|
|
|
func SwapExists()
|
|
|
|
|
let v:swapchoice = 'o'
|
|
|
|
|
call setbufvar(g:buf, '&filetype', 'text')
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func SafeState()
|
|
|
|
|
edit <script>
|
|
|
|
|
redir! > XftSwapExists.out
|
|
|
|
|
set readonly? filetype?
|
|
|
|
|
redir END
|
|
|
|
|
qall!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
autocmd SwapExists * ++nested call SwapExists()
|
|
|
|
|
autocmd SafeState * ++nested ++once call SafeState()
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'XftSwapExists.vim', 'D')
|
|
|
|
|
|
|
|
|
|
new XftSwapExists.vim
|
|
|
|
|
if RunVim('', '', ' -S XftSwapExists.vim')
|
|
|
|
|
call assert_equal(
|
|
|
|
|
\ ['', ' readonly', ' filetype=vim'],
|
|
|
|
|
\ readfile('XftSwapExists.out'))
|
|
|
|
|
call delete('XftSwapExists.out')
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
" Test that file is not marked as modified when SwapExists autocommand sets
|
|
|
|
|
" 'modified' in another buffer.
|
|
|
|
|
func Test_SwapExists_set_other_buf_modified()
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
set nocompatible directory=.
|
|
|
|
|
|
|
|
|
|
let g:buf = bufnr()
|
|
|
|
|
new
|
|
|
|
|
|
|
|
|
|
func SwapExists()
|
|
|
|
|
let v:swapchoice = 'o'
|
|
|
|
|
call setbufvar(g:buf, '&modified', 1)
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
func SafeState()
|
|
|
|
|
edit <script>
|
|
|
|
|
redir! > XmodSwapExists.out
|
|
|
|
|
set readonly? modified?
|
|
|
|
|
redir END
|
|
|
|
|
qall!
|
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
autocmd SwapExists * ++nested call SwapExists()
|
|
|
|
|
autocmd SafeState * ++nested ++once call SafeState()
|
|
|
|
|
END
|
|
|
|
|
call writefile(lines, 'XmodSwapExists.vim', 'D')
|
|
|
|
|
|
|
|
|
|
new XmodSwapExists.vim
|
|
|
|
|
if RunVim('', '', ' -S XmodSwapExists.vim')
|
|
|
|
|
call assert_equal(
|
|
|
|
|
\ ['', ' readonly', 'nomodified'],
|
|
|
|
|
\ readfile('XmodSwapExists.out'))
|
|
|
|
|
call delete('XmodSwapExists.out')
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2020-03-19 19:36:51 -07:00
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|