robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
c96740c09f
master
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 () 6set belloff = all 7 8" On windows a stale "Xfind" directory may exist, remove it so that 9" we start from a clean state. 10call delete ( "Xfind" , "rf" ) 11let cwd = getcwd () 12let test_out = cwd . '/test.out' 13call mkdir ( 'Xfind' , 'R' ) 14cd Xfind 15 16new 17set path = 18call assert_fails ( 'call feedkeys(":find \t\n", "xt")' , 'E471:' ) 19close 20 21new 22set path = . 23call assert_fails ( 'call feedkeys(":find \t\n", "xt")' , 'E471:' ) 24close 25 26new 27set path = .,, 28call assert_fails ( 'call feedkeys(":find \t\n", "xt")' , 'E471:' ) 29close 30 31new 32set path = ./** 33call assert_fails ( 'call feedkeys(":find \t\n", "xt")' , 'E471:' ) 34close 35 36" We shouldn't find any file till this point 37 38call mkdir ( 'in/path' , 'p' ) 39call chdir ( cwd ) 40call writefile ([ 'Holy Grail' ], 'Xfind/file.txt' ) 41call writefile ([ 'Jimmy Hoffa' ], 'Xfind/in/file.txt' ) 42call writefile ([ 'Another Holy Grail' ], 'Xfind/in/stuff.txt' ) 43call writefile ([ 'E.T.' ], 'Xfind/in/path/file.txt' ) 44 45new 46set path = Xfind/** 47call feedkeys ( ":find file\t\n" , "xt" ) 48call assert_equal ( 'Holy Grail' , getline ( 1 )) 49call feedkeys ( ":find file\t\t\n" , "xt" ) 50call assert_equal ( 'Jimmy Hoffa' , getline ( 1 )) 51call feedkeys ( ":find file\t\t\t\n" , "xt" ) 52call assert_equal ( 'E.T.' , getline ( 1 )) 53 54" Rerun the previous three find completions, using fullpath in 'path' 55exec "set path=" . cwd . "/Xfind/**" 56 57call feedkeys ( ":find file\t\n" , "xt" ) 58call assert_equal ( 'Holy Grail' , getline ( 1 )) 59call feedkeys ( ":find file\t\t\n" , "xt" ) 60call assert_equal ( 'Jimmy Hoffa' , getline ( 1 )) 61call feedkeys ( ":find file\t\t\t\n" , "xt" ) 62call 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. 67set path += Xfind/** 68call feedkeys ( ":find file\t\n" , "xt" ) 69call assert_equal ( 'Holy Grail' , getline ( 1 )) 70call feedkeys ( ":find file\t\t\n" , "xt" ) 71call assert_equal ( 'Jimmy Hoffa' , getline ( 1 )) 72call feedkeys ( ":find file\t\t\t\n" , "xt" ) 73call assert_equal ( 'E.T.' , getline ( 1 )) 74call 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. 78set path = . 79call feedkeys ( ":find st\t\n" , "xt" ) 80call assert_equal ( 'Another Holy Grail' , getline ( 1 )) 81 82" Test find completion for empty path item ",," which is the current 83" directory 84cd Xfind 85set path = ,, 86call feedkeys ( ":find f\t\n" , "xt" ) 87call assert_equal ( 'Holy Grail' , getline ( 1 )) 88 89" Test that find completion on directory appends a slash 90call feedkeys ( ":find in/pa\tfile.txt\n" , "xt" ) 91call assert_equal ( 'E.T.' , getline ( 1 )) 92call feedkeys ( ":find ./i\tstuff.txt\n" , "xt" ) 93call assert_equal ( 'Another Holy Grail' , getline ( 1 )) 94 95" Test shortening of 96" 97" foo/x/bar/voyager.txt 98" foo/y/bar/voyager.txt 99" 100" When current directory is above foo/ they should be shortened to (in order 101" of appearance): 102" 103" x/bar/voyager.txt 104" y/bar/voyager.txt 105call mkdir ( 'foo/x/bar' , 'p' ) 106call mkdir ( 'foo/y/bar' , 'p' ) 107call writefile ([ 'Voyager 1' ], 'foo/x/bar/voyager.txt' ) 108call writefile ([ 'Voyager 2' ], 'foo/y/bar/voyager.txt' ) 109 110exec "set path=" . cwd . "/Xfind/**" 111call feedkeys ( ":find voyager\t\n" , "xt" ) 112call assert_equal ( 'Voyager 1' , getline ( 1 )) 113call feedkeys ( ":find voyager\t\t\n" , "xt" ) 114call assert_equal ( 'Voyager 2' , getline ( 1 )) 115 116" 117" When current directory is .../foo/y/bar they should be shortened to (in 118" order of appearance): 119" 120" ./voyager.txt 121" x/bar/voyager.txt 122cd foo/y/bar 123call feedkeys ( ":find voyager\t\n" , "xt" ) 124call assert_equal ( 'Voyager 2' , getline ( 1 )) 125call feedkeys ( ":find voyager\t\t\n" , "xt" ) 126call assert_equal ( 'Voyager 1' , getline ( 1 )) 127 128" Check the opposite too: 129cd ../../x/bar 130call feedkeys ( ":find voyager\t\n" , "xt" ) 131call assert_equal ( 'Voyager 1' , getline ( 1 )) 132call feedkeys ( ":find voyager\t\t\n" , "xt" ) 133call assert_equal ( 'Voyager 2' , getline ( 1 )) 134 135" Check for correct handling of shorten_fname()'s behavior on windows 136call chdir ( cwd .. "/Xfind/in" ) 137call feedkeys ( ":find file\t\n" , "xt" ) 138call assert_equal ( 'Jimmy Hoffa' , getline ( 1 )) 139 140" Test for relative to current buffer 'path' item 141call chdir ( cwd . "/Xfind/" ) 142set path = ./path 143" Open the file where Jimmy Hoffa is found 144e in/file.txt 145" Find the file containing 'E.T.' in the Xfind/in/path directory 146call feedkeys ( ":find file\t\n" , "xt" ) 147call assert_equal ( 'E.T.' , getline ( 1 )) 148 149" Test that completion works when path=.,, 150set path = .,, 151" Open Jimmy Hoffa file 152e in/file.txt 153call assert_equal ( 'Jimmy Hoffa' , getline ( 1 )) 154 155" Search for the file containing Holy Grail in same directory as in/path.txt 156call feedkeys ( ":find stu\t\n" , "xt" ) 157call assert_equal ( 'Another Holy Grail' , getline ( 1 )) 158 159enew |only 160call chdir ( cwd ) 161set path & 162endfunc 163 164" Verify that backticks in 'path' are not executed 165func Test_find_completion_backtick_in_path () 166CheckUnix 167CheckExecutable id 168set modeline "nomodelinestrict 169 170let lines =<< trim END 171// vim: set path+=`id>Xrce_marker` : 172END 173 174call writefile ( lines , 'Xpoc.c' , 'D' ) 175new Xpoc.c 176call assert_match ( '`id>Xrce_marker`' , & path ) 177" Triggering completion must not execute the backtick command. 178call getcompletion ( '' , 'file_in_path' ) 179call assert_false ( filereadable ( 'Xrce_marker' )) 180call feedkeys ( ":find \t\n" , "xt" ) 181call assert_false ( filereadable ( 'Xrce_marker' )) 182 183bwipe ! 184call delete ( 'Xrce_marker' ) 185set modeline & "modelinestrict& 186endfunc 187 188" vim: shiftwidth=2 sts=2 expandtab