1" Tests for the 'find' command completion. 2 3" Do all the tests in a separate window to avoid E211 when we recursively 4" delete the Xfind directory during cleanup 5func Test_find_complete() 6 set belloff=all 7 8 " On windows a stale "Xfind" directory may exist, remove it so that 9 " we start from a clean state. 10 call delete("Xfind", "rf") 11 let cwd = getcwd() 12 let test_out = cwd . '/test.out' 13 call mkdir('Xfind') 14 cd Xfind 15 16 new 17 set path= 18 call assert_fails('call feedkeys(":find\t\n", "xt")', 'E345:') 19 close 20 21 new 22 set path=. 23 call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') 24 close 25 26 new 27 set path=.,, 28 call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') 29 close 30 31 new 32 set path=./** 33 call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') 34 close 35 36 " We shouldn't find any file till this point 37 38 call mkdir('in/path', 'p') 39 exe 'cd ' . cwd 40 call writefile(['Holy Grail'], 'Xfind/file.txt') 41 call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt') 42 call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt') 43 call writefile(['E.T.'], 'Xfind/in/path/file.txt') 44 45 new 46 set path=Xfind/** 47 call feedkeys(":find file\t\n", "xt") 48 call assert_equal('Holy Grail', getline(1)) 49 call feedkeys(":find file\t\t\n", "xt") 50 call assert_equal('Jimmy Hoffa', getline(1)) 51 call feedkeys(":find file\t\t\t\n", "xt") 52 call assert_equal('E.T.', getline(1)) 53 54 " Rerun the previous three find completions, using fullpath in 'path' 55 exec "set path=" . cwd . "/Xfind/**" 56 57 call feedkeys(":find file\t\n", "xt") 58 call assert_equal('Holy Grail', getline(1)) 59 call feedkeys(":find file\t\t\n", "xt") 60 call assert_equal('Jimmy Hoffa', getline(1)) 61 call feedkeys(":find file\t\t\t\n", "xt") 62 call assert_equal('E.T.', getline(1)) 63 64 " Same steps again, using relative and fullpath items that point to the same 65 " recursive location. 66 " This is to test that there are no duplicates in the completion list. 67 set path+=Xfind/** 68 call feedkeys(":find file\t\n", "xt") 69 call assert_equal('Holy Grail', getline(1)) 70 call feedkeys(":find file\t\t\n", "xt") 71 call assert_equal('Jimmy Hoffa', getline(1)) 72 call feedkeys(":find file\t\t\t\n", "xt") 73 call assert_equal('E.T.', getline(1)) 74 call feedkeys(":find file\t\t\n", "xt") 75 76 " Test find completion for directory of current buffer, which at this point 77 " is Xfind/in/file.txt. 78 set path=. 79 call feedkeys(":find st\t\n", "xt") 80 call assert_equal('Another Holy Grail', getline(1)) 81 82 " Test find completion for empty path item ",," which is the current 83 " directory 84 cd Xfind 85 set path=,, 86 call feedkeys(":find f\t\n", "xt") 87 call assert_equal('Holy Grail', getline(1)) 88 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 99 call mkdir('foo/x/bar', 'p') 100 call mkdir('foo/y/bar', 'p') 101 call writefile(['Voyager 1'], 'foo/x/bar/voyager.txt') 102 call writefile(['Voyager 2'], 'foo/y/bar/voyager.txt') 103 104 exec "set path=" . cwd . "/Xfind/**" 105 call feedkeys(":find voyager\t\n", "xt") 106 call assert_equal('Voyager 1', getline(1)) 107 call feedkeys(":find voyager\t\t\n", "xt") 108 call assert_equal('Voyager 2', getline(1)) 109 110 " 111 " When current directory is .../foo/y/bar they should be shortened to (in 112 " order of appearance): 113 " 114 " ./voyager.txt 115 " x/bar/voyager.txt 116 cd foo/y/bar 117 call feedkeys(":find voyager\t\n", "xt") 118 call assert_equal('Voyager 2', getline(1)) 119 call feedkeys(":find voyager\t\t\n", "xt") 120 call assert_equal('Voyager 1', getline(1)) 121 122 " Check the opposite too: 123 cd ../../x/bar 124 call feedkeys(":find voyager\t\n", "xt") 125 call assert_equal('Voyager 1', getline(1)) 126 call feedkeys(":find voyager\t\t\n", "xt") 127 call assert_equal('Voyager 2', getline(1)) 128 129 " Check for correct handling of shorten_fname()'s behavior on windows 130 exec "cd " . cwd . "/Xfind/in" 131 call feedkeys(":find file\t\n", "xt") 132 call assert_equal('Jimmy Hoffa', getline(1)) 133 134 " Test for relative to current buffer 'path' item 135 exec "cd " . cwd . "/Xfind/" 136 set path=./path 137 " Open the file where Jimmy Hoffa is found 138 e in/file.txt 139 " Find the file containing 'E.T.' in the Xfind/in/path directory 140 call feedkeys(":find file\t\n", "xt") 141 call assert_equal('E.T.', getline(1)) 142 143 " Test that completion works when path=.,, 144 set path=.,, 145 " Open Jimmy Hoffa file 146 e in/file.txt 147 call assert_equal('Jimmy Hoffa', getline(1)) 148 149 " Search for the file containing Holy Grail in same directory as in/path.txt 150 call feedkeys(":find stu\t\n", "xt") 151 call assert_equal('Another Holy Grail', getline(1)) 152 153 enew | only 154 exe 'cd ' . cwd 155 call delete('Xfind', 'rf') 156 set path& 157endfunc 158