Mercurial > vim
diff src/testdir/test_autocmd.vim @ 13170:6559e98f3e74 v8.0.1459
patch 8.0.1459: cannot handle change of directory
commit https://github.com/vim/vim/commit/b7407d3fc9496f9048fb65ab17b5ba3444965c0e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 3 17:36:27 2018 +0100
patch 8.0.1459: cannot handle change of directory
Problem: Cannot handle change of directory.
Solution: Add the DirChanged autocommand event. (Andy Massimino,
closes #888) Avoid changing directory for 'autochdir' too often.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 03 Feb 2018 17:45:05 +0100 |
parents | 59a16624400a |
children | f83d3a633ccb |
line wrap: on
line diff
--- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -1190,3 +1190,59 @@ func Test_nocatch_wipe_dummy_buffer() call assert_fails('lvĀ½ /x', 'E480') au! endfunc + +function s:Before_test_dirchanged() + augroup test_dirchanged + autocmd! + augroup END + let s:li = [] + let s:dir_this = getcwd() + let s:dir_other = s:dir_this . '/foo' + call mkdir(s:dir_other) +endfunc + +function s:After_test_dirchanged() + exe 'cd' s:dir_this + call delete(s:dir_other, 'd') + augroup test_dirchanged + autocmd! + augroup END +endfunc + +function Test_dirchanged_global() + call s:Before_test_dirchanged() + autocmd test_dirchanged DirChanged global call add(s:li, "cd:") + autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>")) + exe 'cd' s:dir_other + call assert_equal(["cd:", s:dir_other], s:li) + exe 'lcd' s:dir_other + call assert_equal(["cd:", s:dir_other], s:li) + 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>")) + exe 'cd' s:dir_other + call assert_equal([], s:li) + exe 'lcd' s:dir_other + call assert_equal(["lcd:", s:dir_other], s:li) + call s:After_test_dirchanged() +endfunc + +function Test_dirchanged_auto() + call s:Before_test_dirchanged() + call test_autochdir() + autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") + autocmd test_dirchanged DirChanged auto call add(s:li, expand("<afile>")) + set acd + exe 'cd ..' + call assert_equal([], s:li) + exe 'edit ' . s:dir_other . '/Xfile' + call assert_equal(s:dir_other, getcwd()) + call assert_equal(["auto:", s:dir_other], s:li) + set noacd + bwipe! + call s:After_test_dirchanged() +endfunc