blob: 5472247e7476ff584a195cb67eb7745f7dcd25c2 [file] [log] [blame]
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +02001Tests for find completion.
2
3STARTTEST
Bram Moolenaardb41fa22010-08-08 13:07:57 +02004:so small.vim
Bram Moolenaar84f888a2010-08-05 21:40:16 +02005:" Do all test in a separate window to avoid E211 when we recursively
6:" delete the Xfind directory during cleanup
7:"
8:" This will cause a few errors, do it silently.
Bram Moolenaar0be992e2010-08-12 21:50:51 +02009:set visualbell
10:set nocp viminfo+=nviminfo
Bram Moolenaar84f888a2010-08-05 21:40:16 +020011:"
12:function! DeleteDirectory(dir)
Bram Moolenaar9bc040c2010-08-11 22:05:57 +020013: if has("win16") || has("win32") || has("win64") || has("dos16") || has("dos32")
Bram Moolenaar84f888a2010-08-05 21:40:16 +020014: exec "silent !rmdir /Q /S " . a:dir
15: else
16: exec "silent !rm -rf " . a:dir
17: endif
18:endfun
19:" On windows a stale "Xfind" directory may exist, remove it so that
20:" we start from a clean state.
21:call DeleteDirectory("Xfind")
Bram Moolenaar84f888a2010-08-05 21:40:16 +020022:new
23:let cwd=getcwd()
Bram Moolenaar0be992e2010-08-12 21:50:51 +020024:let test_out = cwd . '/test.out'
Bram Moolenaardaf3b392010-08-13 19:13:18 +020025:call mkdir('Xfind')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020026:cd Xfind
27:set path=
28:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020029:exec "w! " . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020030:close
31:new
32:set path=.
33:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020034:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020035:close
36:new
37:set path=.,,
38:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020039:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020040:close
41:new
42:set path=./**
43:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020044:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020045:close
46:new
Bram Moolenaar0be992e2010-08-12 21:50:51 +020047:" We shouldn't find any file at this point, test.out must be empty.
Bram Moolenaardaf3b392010-08-13 19:13:18 +020048:call mkdir('in')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020049:cd in
Bram Moolenaardaf3b392010-08-13 19:13:18 +020050:call mkdir('path')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020051:exec "cd " . cwd
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020052:e Xfind/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020053SHoly Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020054:e Xfind/in/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020055SJimmy Hoffa:w
Bram Moolenaar84f888a2010-08-05 21:40:16 +020056:e Xfind/in/stuff.txt
57SAnother Holy Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020058:e Xfind/in/path/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020059SE.T.:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020060:set path=Xfind/**
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020061:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020062:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020063:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020064:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020065:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020066:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020067:" Rerun the previous three find completions, using fullpath in 'path'
68:exec "set path=" . cwd . "/Xfind/**"
69:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020070:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020071:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020072:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020073:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020074:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020075:" Same steps again, using relative and fullpath items that point to the same
76:" recursive location.
77:" This is to test that there are no duplicates in the completion list.
78:exec "set path+=Xfind/**"
79:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020080:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020081:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020082:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020083:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020084:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020085:find file
86:" Test find completion for directory of current buffer, which at this point
87:" is Xfind/in/file.txt.
88:set path=.
89:find st
Bram Moolenaar0be992e2010-08-12 21:50:51 +020090:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020091:" Test find completion for empty path item ",," which is the current directory
92:cd Xfind
93:set path=,,
94:find f
Bram Moolenaar0be992e2010-08-12 21:50:51 +020095:exec "w >>" . test_out
96:" Test shortening of
97:"
98:" foo/x/bar/voyager.txt
99:" foo/y/bar/voyager.txt
100:"
101:" When current directory is above foo/ they should be shortened to (in order
102:" of appearance):
103:"
104:" x/bar/voyager.txt
105:" y/bar/voyager.txt
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200106:call mkdir('foo')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200107:cd foo
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200108:call mkdir('x')
109:call mkdir('y')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200110:cd x
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200111:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200112:cd ..
113:cd y
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200114:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200115:cd ..
116:cd ..
117:" We should now be in the Xfind directory
118:e foo/x/bar/voyager.txt
119SVoyager 1:w
120:e foo/y/bar/voyager.txt
121SVoyager 2:w
122:exec "set path=" . cwd . "/Xfind/**"
123:find voyager
124:exec "w >>" . test_out
125:find voyager
126:exec "w >>" . test_out
127:"
128:" When current directory is .../foo/y/bar they should be shortened to (in
129:" order of appearance):
130:"
131:" ./voyager.txt
132:" x/bar/voyager.txt
133:cd foo
134:cd y
135:cd bar
136:find voyager
137:exec "w >> " . test_out
138:find voyager
139:exec "w >> " . test_out
140:" Check the opposite too:
141:cd ..
142:cd ..
143:cd x
144:cd bar
145:find voyager
146:exec "w >> " . test_out
147:find voyager
148:exec "w >> " . test_out
Bram Moolenaar31710262010-08-13 13:36:15 +0200149:" Check for correct handling of shorten_fname()'s behavior on windows
150:exec "cd " . cwd . "/Xfind/in"
151:find file
152:exec "w >>" . test_out
Bram Moolenaard732f9a2010-08-15 13:29:11 +0200153:" Test for relative to current buffer 'path' item
154:exec "cd " . cwd . "/Xfind/"
155:set path=./path
156:" Open the file where Jimmy Hoffa is found
157:e in/file.txt
158:" Find the file containing 'E.T.' in the Xfind/in/path directory
159:find file
160:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +0200161:q
Bram Moolenaar31710262010-08-13 13:36:15 +0200162:exec "cd " . cwd
Bram Moolenaar84f888a2010-08-05 21:40:16 +0200163:call DeleteDirectory("Xfind")
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +0200164:qa!
165ENDTEST
166