diff src/testdir/test_getcwd.in @ 7653:d4370fef0175 v7.4.1126

commit https://github.com/vim/vim/commit/c970330676eaae7ba7cd05cfa46df5a413853ef9 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 17 21:49:33 2016 +0100 patch 7.4.1126 Problem: Can only get the directory of the current window. Solution: Add window and tab arguments to getcwd() and haslocaldir(). (Thinca, Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jan 2016 22:00:05 +0100
parents
children 05e7d084c6c2
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_getcwd.in
@@ -0,0 +1,101 @@
+Tests for getcwd(), haslocaldir(), and :lcd                   vim: set ft=vim :
+
+STARTTEST
+:so small.vim
+:" Do all test in a separate window to avoid E211 when we recursively
+:" delete the Xtopdir directory during cleanup
+:"
+:" This will cause a few errors, do it silently.
+:set visualbell
+:set nocp viminfo+=nviminfo
+:"
+:function! DeleteDirectory(dir)
+: if has("win16") || has("win32") || has("win64") || has("dos16") || has("dos32")
+:  exec "silent !rmdir /Q /S " . a:dir
+: else
+:  exec "silent !rm -rf " . a:dir
+: endif
+:endfun
+:"
+:function! GetCwdInfo(win, tab)
+: let tab_changed = 0
+: let mod = ":t"
+: if a:tab > 0 && a:tab != tabpagenr()
+:   let tab_changed = 1
+:   exec "tabnext " . a:tab
+: endif
+: let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
+: if tab_changed
+:   tabprevious
+: endif
+: if a:win == 0 && a:tab == 0
+:   let dirname = fnamemodify(getcwd(), mod)
+:   let lflag = haslocaldir()
+: elseif a:tab == 0
+:   let dirname = fnamemodify(getcwd(a:win), mod)
+:   let lflag = haslocaldir(a:win)
+: else
+:   let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
+:   let lflag = haslocaldir(a:win, a:tab)
+: endif
+: return bufname . ' ' . dirname . ' ' . lflag
+:endfunction
+:" On windows a stale "Xtopdir" directory may exist, remove it so that
+:" we start from a clean state.
+:call DeleteDirectory("Xtopdir")
+:let r=[]
+:new
+:let cwd=getcwd()
+:let test_out = cwd . '/test.out'
+:call mkdir('Xtopdir')
+:cd Xtopdir
+:call mkdir('Xdir1')
+:call mkdir('Xdir2')
+:call mkdir('Xdir3')
+:new a
+:new b
+:new c
+:3wincmd w
+:lcd Xdir1
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir3
+:call add(r, GetCwdInfo(0, 0))
+:call add(r, GetCwdInfo(bufwinnr("a"), 0))
+:call add(r, GetCwdInfo(bufwinnr("b"), 0))
+:call add(r, GetCwdInfo(bufwinnr("c"), 0))
+:wincmd W
+:call add(r, GetCwdInfo(bufwinnr("a"), tabpagenr()))
+:call add(r, GetCwdInfo(bufwinnr("b"), tabpagenr()))
+:call add(r, GetCwdInfo(bufwinnr("c"), tabpagenr()))
+:"
+:tabnew x
+:new y
+:new z
+:3wincmd w
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir2
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir3
+:call add(r, GetCwdInfo(0, 0))
+:call add(r, GetCwdInfo(bufwinnr("x"), 0))
+:call add(r, GetCwdInfo(bufwinnr("y"), 0))
+:call add(r, GetCwdInfo(bufwinnr("z"), 0))
+:let tp_nr = tabpagenr()
+:tabrewind
+:call add(r, GetCwdInfo(3, tp_nr))
+:call add(r, GetCwdInfo(2, tp_nr))
+:call add(r, GetCwdInfo(1, tp_nr))
+:"
+:call writefile(r, test_out, "a")
+:q
+:exec "cd " . cwd
+:call DeleteDirectory("Xtopdir")
+:qa!
+ENDTEST
+
+