1" Test for the gf and gF (goto file) commands 2 3" This is a test if a URL is recognized by "gf", with the cursor before and 4" after the "://". Also test ":\\". 5func Test_gf_url() 6 enew! 7 call append(0, [ 8 \ "first test for URL://machine.name/tmp/vimtest2a and other text", 9 \ "second test for URL://machine.name/tmp/vimtest2b. And other text", 10 \ "third test for URL:\\\\machine.name\\vimtest2c and other text", 11 \ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text", 12 \ "fifth test for URL://machine.name/tmp?q=vim&opt=yes and other text", 13 \ "sixth test for URL://machine.name:1234?q=vim and other text", 14 \ ]) 15 call cursor(1,1) 16 call search("^first") 17 call search("tmp") 18 call assert_equal("URL://machine.name/tmp/vimtest2a", expand("<cfile>")) 19 call search("^second") 20 call search("URL") 21 call assert_equal("URL://machine.name/tmp/vimtest2b", expand("<cfile>")) 22 if has("ebcdic") 23 set isf=@,240-249,/,.,-,_,+,,,$,:,~,\ 24 else 25 set isf=@,48-57,/,.,-,_,+,,,$,~,\ 26 endif 27 call search("^third") 28 call search("name") 29 call assert_equal("URL:\\\\machine.name\\vimtest2c", expand("<cfile>")) 30 call search("^fourth") 31 call search("URL") 32 call assert_equal("URL:\\\\machine.name\\tmp\\vimtest2d", expand("<cfile>")) 33 34 call search("^fifth") 35 call search("URL") 36 call assert_equal("URL://machine.name/tmp?q=vim&opt=yes", expand("<cfile>")) 37 38 call search("^sixth") 39 call search("URL") 40 call assert_equal("URL://machine.name:1234?q=vim", expand("<cfile>")) 41 42 set isf&vim 43 enew! 44endfunc 45 46func Test_gF() 47 new 48 call setline(1, ['111', '222', '333', '444']) 49 w! Xfile 50 close 51 new 52 set isfname-=: 53 call setline(1, ['one', 'Xfile:3', 'three']) 54 2 55 call assert_fails('normal gF', 'E37:') 56 call assert_equal(2, getcurpos()[1]) 57 w! Xfile2 58 normal gF 59 call assert_equal('Xfile', bufname('%')) 60 call assert_equal(3, getcurpos()[1]) 61 62 enew! 63 call setline(1, ['one', 'the Xfile line 2, and more', 'three']) 64 w! Xfile2 65 normal 2GfX 66 normal gF 67 call assert_equal('Xfile', bufname('%')) 68 call assert_equal(2, getcurpos()[1]) 69 70 set isfname& 71 call delete('Xfile') 72 call delete('Xfile2') 73 bwipe Xfile 74 bwipe Xfile2 75endfunc 76 77" Test for invoking 'gf' on a ${VAR} variable 78func Test_gf() 79 if has("ebcdic") 80 set isfname=@,240-249,/,.,-,_,+,,,$,:,~,{,} 81 else 82 set isfname=@,48-57,/,.,-,_,+,,,$,:,~,{,} 83 endif 84 85 call writefile(["Test for gf command"], "Xtest1") 86 if has("unix") 87 call writefile([" ${CDIR}/Xtest1"], "Xtestgf") 88 else 89 call writefile([" $TDIR/Xtest1"], "Xtestgf") 90 endif 91 new Xtestgf 92 if has("unix") 93 let $CDIR = "." 94 /CDIR 95 else 96 if has("amiga") 97 let $TDIR = "/testdir" 98 else 99 let $TDIR = "." 100 endif 101 /TDIR 102 endif 103 104 normal gf 105 call assert_equal('Xtest1', fnamemodify(bufname(''), ":t")) 106 close! 107 108 call delete('Xtest1') 109 call delete('Xtestgf') 110endfunc 111 112func Test_gf_visual() 113 call writefile(['one', 'two', 'three', 'four'], "Xtest_gf_visual") 114 new 115 call setline(1, 'XXXtest_gf_visualXXX') 116 set hidden 117 118 " Visually select Xtest_gf_visual and use gf to go to that file 119 norm! ttvtXgf 120 call assert_equal('Xtest_gf_visual', bufname('%')) 121 122 " if multiple lines are selected, then gf should fail 123 call setline(1, ["one", "two"]) 124 normal VGgf 125 call assert_equal('Xtest_gf_visual', @%) 126 127 " following line number is used for gF 128 bwipe! 129 new 130 call setline(1, 'XXXtest_gf_visual:3XXX') 131 norm! 0ttvt:gF 132 call assert_equal('Xtest_gf_visual', bufname('%')) 133 call assert_equal(3, getcurpos()[1]) 134 135 " line number in visual area is used for file name 136 if has('unix') 137 bwipe! 138 call writefile([], "Xtest_gf_visual:3") 139 new 140 call setline(1, 'XXXtest_gf_visual:3XXX') 141 norm! 0ttvtXgF 142 call assert_equal('Xtest_gf_visual:3', bufname('%')) 143 call delete('Xtest_gf_visual:3') 144 endif 145 146 bwipe! 147 call delete('Xtest_gf_visual') 148 set nohidden 149endfunc 150 151func Test_gf_error() 152 new 153 call assert_fails('normal gf', 'E446:') 154 call assert_fails('normal gF', 'E446:') 155 call setline(1, '/doesnotexist') 156 call assert_fails('normal gf', 'E447:') 157 call assert_fails('normal gF', 'E447:') 158 bwipe! 159endfunc 160