blob: a0b9ae8a146adde591d6a5600be09ef26a5a7928 [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:"
Bram Moolenaar84f888a2010-08-05 21:40:16 +020012:" On windows a stale "Xfind" directory may exist, remove it so that
13:" we start from a clean state.
Bram Moolenaarabc70bb2016-06-08 21:48:50 +020014:call delete("Xfind", "rf")
Bram Moolenaar84f888a2010-08-05 21:40:16 +020015:new
16:let cwd=getcwd()
Bram Moolenaar0be992e2010-08-12 21:50:51 +020017:let test_out = cwd . '/test.out'
Bram Moolenaardaf3b392010-08-13 19:13:18 +020018:call mkdir('Xfind')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020019:cd Xfind
20:set path=
21:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020022:exec "w! " . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020023:close
24:new
25:set path=.
26:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020027:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020028:close
29:new
30:set path=.,,
31:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020032:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020033:close
34:new
35:set path=./**
36:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020037:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020038:close
39:new
Bram Moolenaar0be992e2010-08-12 21:50:51 +020040:" We shouldn't find any file at this point, test.out must be empty.
Bram Moolenaardaf3b392010-08-13 19:13:18 +020041:call mkdir('in')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020042:cd in
Bram Moolenaardaf3b392010-08-13 19:13:18 +020043:call mkdir('path')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020044:exec "cd " . cwd
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020045:e Xfind/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020046SHoly Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020047:e Xfind/in/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020048SJimmy Hoffa:w
Bram Moolenaar84f888a2010-08-05 21:40:16 +020049:e Xfind/in/stuff.txt
50SAnother Holy Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020051:e Xfind/in/path/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020052SE.T.:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020053:set path=Xfind/**
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020054:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020055:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020056:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020057:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020058:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020059:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020060:" Rerun the previous three find completions, using fullpath in 'path'
61:exec "set path=" . cwd . "/Xfind/**"
62:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020063:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020064:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020065:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020066:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020067:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020068:" Same steps again, using relative and fullpath items that point to the same
69:" recursive location.
70:" This is to test that there are no duplicates in the completion list.
71:exec "set path+=Xfind/**"
72:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020073:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020074:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020075:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020076:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020077:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020078:find file
79:" Test find completion for directory of current buffer, which at this point
80:" is Xfind/in/file.txt.
81:set path=.
82:find st
Bram Moolenaar0be992e2010-08-12 21:50:51 +020083:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020084:" Test find completion for empty path item ",," which is the current directory
85:cd Xfind
86:set path=,,
87:find f
Bram Moolenaar0be992e2010-08-12 21:50:51 +020088:exec "w >>" . test_out
89:" Test shortening of
90:"
91:" foo/x/bar/voyager.txt
92:" foo/y/bar/voyager.txt
93:"
94:" When current directory is above foo/ they should be shortened to (in order
95:" of appearance):
96:"
97:" x/bar/voyager.txt
98:" y/bar/voyager.txt
Bram Moolenaardaf3b392010-08-13 19:13:18 +020099:call mkdir('foo')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200100:cd foo
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200101:call mkdir('x')
102:call mkdir('y')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200103:cd x
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200104:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200105:cd ..
106:cd y
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200107:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200108:cd ..
109:cd ..
110:" We should now be in the Xfind directory
111:e foo/x/bar/voyager.txt
112SVoyager 1:w
113:e foo/y/bar/voyager.txt
114SVoyager 2:w
115:exec "set path=" . cwd . "/Xfind/**"
116:find voyager
117:exec "w >>" . test_out
118:find voyager
119:exec "w >>" . test_out
120:"
121:" When current directory is .../foo/y/bar they should be shortened to (in
122:" order of appearance):
123:"
124:" ./voyager.txt
125:" x/bar/voyager.txt
126:cd foo
127:cd y
128:cd bar
129:find voyager
130:exec "w >> " . test_out
131:find voyager
132:exec "w >> " . test_out
133:" Check the opposite too:
134:cd ..
135:cd ..
136:cd x
137:cd bar
138:find voyager
139:exec "w >> " . test_out
140:find voyager
141:exec "w >> " . test_out
Bram Moolenaar31710262010-08-13 13:36:15 +0200142:" Check for correct handling of shorten_fname()'s behavior on windows
143:exec "cd " . cwd . "/Xfind/in"
144:find file
145:exec "w >>" . test_out
Bram Moolenaard732f9a2010-08-15 13:29:11 +0200146:" Test for relative to current buffer 'path' item
147:exec "cd " . cwd . "/Xfind/"
148:set path=./path
149:" Open the file where Jimmy Hoffa is found
150:e in/file.txt
151:" Find the file containing 'E.T.' in the Xfind/in/path directory
152:find file
153:exec "w >>" . test_out
Bram Moolenaar811fe632013-04-24 17:34:20 +0200154:"
155:" Test that completion works when path=.,,
156:"
157:set path=.,,
158:" Open Jimmy Hoffa file
159:e in/file.txt
160:exec "w >>" . test_out
161:" Search for the file containing Holy Grail in same directory as in/path.txt
162:find stu
163:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +0200164:q
Bram Moolenaar31710262010-08-13 13:36:15 +0200165:exec "cd " . cwd
Bram Moolenaarabc70bb2016-06-08 21:48:50 +0200166:call delete("Xfind", "rf")
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +0200167:qa!
168ENDTEST
169