summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_autocmd.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-02-03 17:36:27 +0100
committerBram Moolenaar <Bram@vim.org>2018-02-03 17:36:27 +0100
commitb7407d3fc9496f9048fb65ab17b5ba3444965c0e (patch)
treeea713a63c3771ff35b52aadef755102b55cc377d /src/testdir/test_autocmd.vim
parentddb349369d107c14fad9c38baf2f0e2b8514fbf0 (diff)
patch 8.0.1459: cannot handle change of directoryv8.0.1459
Problem: Cannot handle change of directory. Solution: Add the DirChanged autocommand event. (Andy Massimino, closes #888) Avoid changing directory for 'autochdir' too often.
Diffstat (limited to 'src/testdir/test_autocmd.vim')
-rw-r--r--src/testdir/test_autocmd.vim56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index b7d43b59ad..c504f704fc 100644
--- 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