Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 1 | Tests for find completion. |
| 2 | |
| 3 | STARTTEST |
Bram Moolenaar | db41fa2 | 2010-08-08 13:07:57 +0200 | [diff] [blame] | 4 | :so small.vim |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 5 | :" 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 Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 9 | :set visualbell |
| 10 | :set nocp viminfo+=nviminfo |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 11 | :" |
| 12 | :function! DeleteDirectory(dir) |
Bram Moolenaar | 9bc040c | 2010-08-11 22:05:57 +0200 | [diff] [blame] | 13 | : if has("win16") || has("win32") || has("win64") || has("dos16") || has("dos32") |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 14 | : 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 Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 22 | :new |
| 23 | :let cwd=getcwd() |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 24 | :let test_out = cwd . '/test.out' |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 25 | :call mkdir('Xfind') |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 26 | :cd Xfind |
| 27 | :set path= |
| 28 | :find |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 29 | :exec "w! " . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 30 | :close |
| 31 | :new |
| 32 | :set path=. |
| 33 | :find |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 34 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 35 | :close |
| 36 | :new |
| 37 | :set path=.,, |
| 38 | :find |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 39 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 40 | :close |
| 41 | :new |
| 42 | :set path=./** |
| 43 | :find |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 44 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 45 | :close |
| 46 | :new |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 47 | :" We shouldn't find any file at this point, test.out must be empty. |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 48 | :call mkdir('in') |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 49 | :cd in |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 50 | :call mkdir('path') |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 51 | :exec "cd " . cwd |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 52 | :e Xfind/file.txt |
Bram Moolenaar | 3ea5fa7 | 2010-08-04 18:27:57 +0200 | [diff] [blame] | 53 | SHoly Grail:w |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 54 | :e Xfind/in/file.txt |
Bram Moolenaar | 3ea5fa7 | 2010-08-04 18:27:57 +0200 | [diff] [blame] | 55 | SJimmy Hoffa:w |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 56 | :e Xfind/in/stuff.txt |
| 57 | SAnother Holy Grail:w |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 58 | :e Xfind/in/path/file.txt |
Bram Moolenaar | 3ea5fa7 | 2010-08-04 18:27:57 +0200 | [diff] [blame] | 59 | SE.T.:w |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 60 | :set path=Xfind/** |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 61 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 62 | :exec "w >>" . test_out |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 63 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 64 | :exec "w >>" . test_out |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 65 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 66 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 67 | :" Rerun the previous three find completions, using fullpath in 'path' |
| 68 | :exec "set path=" . cwd . "/Xfind/**" |
| 69 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 70 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 71 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 72 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 73 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 74 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 75 | :" 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 Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 80 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 81 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 82 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 83 | :find file |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 84 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 85 | :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 Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 90 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 91 | :" Test find completion for empty path item ",," which is the current directory |
| 92 | :cd Xfind |
| 93 | :set path=,, |
| 94 | :find f |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 95 | :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 Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 106 | :call mkdir('foo') |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 107 | :cd foo |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 108 | :call mkdir('x') |
| 109 | :call mkdir('y') |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 110 | :cd x |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 111 | :call mkdir('bar') |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 112 | :cd .. |
| 113 | :cd y |
Bram Moolenaar | daf3b39 | 2010-08-13 19:13:18 +0200 | [diff] [blame] | 114 | :call mkdir('bar') |
Bram Moolenaar | 0be992e | 2010-08-12 21:50:51 +0200 | [diff] [blame] | 115 | :cd .. |
| 116 | :cd .. |
| 117 | :" We should now be in the Xfind directory |
| 118 | :e foo/x/bar/voyager.txt |
| 119 | SVoyager 1:w |
| 120 | :e foo/y/bar/voyager.txt |
| 121 | SVoyager 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 Moolenaar | 3171026 | 2010-08-13 13:36:15 +0200 | [diff] [blame] | 149 | :" 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 Moolenaar | d732f9a | 2010-08-15 13:29:11 +0200 | [diff] [blame] | 153 | :" 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 Moolenaar | 811fe63 | 2013-04-24 17:34:20 +0200 | [diff] [blame] | 161 | :" |
| 162 | :" Test that completion works when path=.,, |
| 163 | :" |
| 164 | :set path=.,, |
| 165 | :" Open Jimmy Hoffa file |
| 166 | :e in/file.txt |
| 167 | :exec "w >>" . test_out |
| 168 | :" Search for the file containing Holy Grail in same directory as in/path.txt |
| 169 | :find stu |
| 170 | :exec "w >>" . test_out |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 171 | :q |
Bram Moolenaar | 3171026 | 2010-08-13 13:36:15 +0200 | [diff] [blame] | 172 | :exec "cd " . cwd |
Bram Moolenaar | 84f888a | 2010-08-05 21:40:16 +0200 | [diff] [blame] | 173 | :call DeleteDirectory("Xfind") |
Bram Moolenaar | 80a7dcf | 2010-08-04 17:07:20 +0200 | [diff] [blame] | 174 | :qa! |
| 175 | ENDTEST |
| 176 | |