comparison 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
comparison
equal deleted inserted replaced
7652:a6555549858d 7653:d4370fef0175
1 Tests for getcwd(), haslocaldir(), and :lcd vim: set ft=vim :
2
3 STARTTEST
4 :so small.vim
5 :" Do all test in a separate window to avoid E211 when we recursively
6 :" delete the Xtopdir directory during cleanup
7 :"
8 :" This will cause a few errors, do it silently.
9 :set visualbell
10 :set nocp viminfo+=nviminfo
11 :"
12 :function! DeleteDirectory(dir)
13 : if has("win16") || has("win32") || has("win64") || has("dos16") || has("dos32")
14 : exec "silent !rmdir /Q /S " . a:dir
15 : else
16 : exec "silent !rm -rf " . a:dir
17 : endif
18 :endfun
19 :"
20 :function! GetCwdInfo(win, tab)
21 : let tab_changed = 0
22 : let mod = ":t"
23 : if a:tab > 0 && a:tab != tabpagenr()
24 : let tab_changed = 1
25 : exec "tabnext " . a:tab
26 : endif
27 : let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
28 : if tab_changed
29 : tabprevious
30 : endif
31 : if a:win == 0 && a:tab == 0
32 : let dirname = fnamemodify(getcwd(), mod)
33 : let lflag = haslocaldir()
34 : elseif a:tab == 0
35 : let dirname = fnamemodify(getcwd(a:win), mod)
36 : let lflag = haslocaldir(a:win)
37 : else
38 : let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
39 : let lflag = haslocaldir(a:win, a:tab)
40 : endif
41 : return bufname . ' ' . dirname . ' ' . lflag
42 :endfunction
43 :" On windows a stale "Xtopdir" directory may exist, remove it so that
44 :" we start from a clean state.
45 :call DeleteDirectory("Xtopdir")
46 :let r=[]
47 :new
48 :let cwd=getcwd()
49 :let test_out = cwd . '/test.out'
50 :call mkdir('Xtopdir')
51 :cd Xtopdir
52 :call mkdir('Xdir1')
53 :call mkdir('Xdir2')
54 :call mkdir('Xdir3')
55 :new a
56 :new b
57 :new c
58 :3wincmd w
59 :lcd Xdir1
60 :call add(r, GetCwdInfo(0, 0))
61 :wincmd W
62 :call add(r, GetCwdInfo(0, 0))
63 :wincmd W
64 :lcd Xdir3
65 :call add(r, GetCwdInfo(0, 0))
66 :call add(r, GetCwdInfo(bufwinnr("a"), 0))
67 :call add(r, GetCwdInfo(bufwinnr("b"), 0))
68 :call add(r, GetCwdInfo(bufwinnr("c"), 0))
69 :wincmd W
70 :call add(r, GetCwdInfo(bufwinnr("a"), tabpagenr()))
71 :call add(r, GetCwdInfo(bufwinnr("b"), tabpagenr()))
72 :call add(r, GetCwdInfo(bufwinnr("c"), tabpagenr()))
73 :"
74 :tabnew x
75 :new y
76 :new z
77 :3wincmd w
78 :call add(r, GetCwdInfo(0, 0))
79 :wincmd W
80 :lcd Xdir2
81 :call add(r, GetCwdInfo(0, 0))
82 :wincmd W
83 :lcd Xdir3
84 :call add(r, GetCwdInfo(0, 0))
85 :call add(r, GetCwdInfo(bufwinnr("x"), 0))
86 :call add(r, GetCwdInfo(bufwinnr("y"), 0))
87 :call add(r, GetCwdInfo(bufwinnr("z"), 0))
88 :let tp_nr = tabpagenr()
89 :tabrewind
90 :call add(r, GetCwdInfo(3, tp_nr))
91 :call add(r, GetCwdInfo(2, tp_nr))
92 :call add(r, GetCwdInfo(1, tp_nr))
93 :"
94 :call writefile(r, test_out, "a")
95 :q
96 :exec "cd " . cwd
97 :call DeleteDirectory("Xtopdir")
98 :qa!
99 ENDTEST
100
101