blob: 67fe4551de872b2c2e6da970b7cb3a568102946a [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 Moolenaarc3c766e2017-03-08 22:55:19 +01005:set belloff=all
Bram Moolenaar84f888a2010-08-05 21:40:16 +02006:" Do all test in a separate window to avoid E211 when we recursively
7:" delete the Xfind directory during cleanup
8:"
9:" This will cause a few errors, do it silently.
Bram Moolenaar0be992e2010-08-12 21:50:51 +020010:set visualbell
11:set nocp viminfo+=nviminfo
Bram Moolenaar84f888a2010-08-05 21:40:16 +020012:"
Bram Moolenaar84f888a2010-08-05 21:40:16 +020013:" On windows a stale "Xfind" directory may exist, remove it so that
14:" we start from a clean state.
Bram Moolenaarabc70bb2016-06-08 21:48:50 +020015:call delete("Xfind", "rf")
Bram Moolenaar84f888a2010-08-05 21:40:16 +020016:new
17:let cwd=getcwd()
Bram Moolenaar0be992e2010-08-12 21:50:51 +020018:let test_out = cwd . '/test.out'
Bram Moolenaardaf3b392010-08-13 19:13:18 +020019:call mkdir('Xfind')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020020:cd Xfind
21:set path=
22:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020023:exec "w! " . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020024:close
25:new
26:set path=.
27:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020028:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020029:close
30:new
31:set path=.,,
32:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020033:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020034:close
35:new
36:set path=./**
37:find
Bram Moolenaar0be992e2010-08-12 21:50:51 +020038:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020039:close
40:new
Bram Moolenaar0be992e2010-08-12 21:50:51 +020041:" We shouldn't find any file at this point, test.out must be empty.
Bram Moolenaardaf3b392010-08-13 19:13:18 +020042:call mkdir('in')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020043:cd in
Bram Moolenaardaf3b392010-08-13 19:13:18 +020044:call mkdir('path')
Bram Moolenaar84f888a2010-08-05 21:40:16 +020045:exec "cd " . cwd
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020046:e Xfind/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020047SHoly Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020048:e Xfind/in/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020049SJimmy Hoffa:w
Bram Moolenaar84f888a2010-08-05 21:40:16 +020050:e Xfind/in/stuff.txt
51SAnother Holy Grail:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020052:e Xfind/in/path/file.txt
Bram Moolenaar3ea5fa72010-08-04 18:27:57 +020053SE.T.:w
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020054:set path=Xfind/**
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020055:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020056:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020057:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020058:exec "w >>" . test_out
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +020059:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020060:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020061:" Rerun the previous three find completions, using fullpath in 'path'
62:exec "set path=" . cwd . "/Xfind/**"
63:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020064:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020065:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020066:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020067:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020068:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020069:" Same steps again, using relative and fullpath items that point to the same
70:" recursive location.
71:" This is to test that there are no duplicates in the completion list.
72:exec "set path+=Xfind/**"
73:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020074:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020075:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020076:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020077:find file
Bram Moolenaar0be992e2010-08-12 21:50:51 +020078:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020079:find file
80:" Test find completion for directory of current buffer, which at this point
81:" is Xfind/in/file.txt.
82:set path=.
83:find st
Bram Moolenaar0be992e2010-08-12 21:50:51 +020084:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +020085:" Test find completion for empty path item ",," which is the current directory
86:cd Xfind
87:set path=,,
88:find f
Bram Moolenaar0be992e2010-08-12 21:50:51 +020089:exec "w >>" . test_out
90:" Test shortening of
91:"
92:" foo/x/bar/voyager.txt
93:" foo/y/bar/voyager.txt
94:"
95:" When current directory is above foo/ they should be shortened to (in order
96:" of appearance):
97:"
98:" x/bar/voyager.txt
99:" y/bar/voyager.txt
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200100:call mkdir('foo')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200101:cd foo
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200102:call mkdir('x')
103:call mkdir('y')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200104:cd x
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200105:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200106:cd ..
107:cd y
Bram Moolenaardaf3b392010-08-13 19:13:18 +0200108:call mkdir('bar')
Bram Moolenaar0be992e2010-08-12 21:50:51 +0200109:cd ..
110:cd ..
111:" We should now be in the Xfind directory
112:e foo/x/bar/voyager.txt
113SVoyager 1:w
114:e foo/y/bar/voyager.txt
115SVoyager 2:w
116:exec "set path=" . cwd . "/Xfind/**"
117:find voyager
118:exec "w >>" . test_out
119:find voyager
120:exec "w >>" . test_out
121:"
122:" When current directory is .../foo/y/bar they should be shortened to (in
123:" order of appearance):
124:"
125:" ./voyager.txt
126:" x/bar/voyager.txt
127:cd foo
128:cd y
129:cd bar
130:find voyager
131:exec "w >> " . test_out
132:find voyager
133:exec "w >> " . test_out
134:" Check the opposite too:
135:cd ..
136:cd ..
137:cd x
138:cd bar
139:find voyager
140:exec "w >> " . test_out
141:find voyager
142:exec "w >> " . test_out
Bram Moolenaar31710262010-08-13 13:36:15 +0200143:" Check for correct handling of shorten_fname()'s behavior on windows
144:exec "cd " . cwd . "/Xfind/in"
145:find file
146:exec "w >>" . test_out
Bram Moolenaard732f9a2010-08-15 13:29:11 +0200147:" Test for relative to current buffer 'path' item
148:exec "cd " . cwd . "/Xfind/"
149:set path=./path
150:" Open the file where Jimmy Hoffa is found
151:e in/file.txt
152:" Find the file containing 'E.T.' in the Xfind/in/path directory
153:find file
154:exec "w >>" . test_out
Bram Moolenaar811fe632013-04-24 17:34:20 +0200155:"
156:" Test that completion works when path=.,,
157:"
158:set path=.,,
159:" Open Jimmy Hoffa file
160:e in/file.txt
161:exec "w >>" . test_out
162:" Search for the file containing Holy Grail in same directory as in/path.txt
163:find stu
164:exec "w >>" . test_out
Bram Moolenaar84f888a2010-08-05 21:40:16 +0200165:q
Bram Moolenaar31710262010-08-13 13:36:15 +0200166:exec "cd " . cwd
Bram Moolenaarabc70bb2016-06-08 21:48:50 +0200167:call delete("Xfind", "rf")
Bram Moolenaar80a7dcf2010-08-04 17:07:20 +0200168:qa!
169ENDTEST
170