blob: 736a31579029ac786e3320485a1d76538baa2e88 [file] [log] [blame]
Bram Moolenaar53f16732016-09-07 20:46:39 +02001
2" This is a test if a URL is recognized by "gf", with the cursor before and
3" after the "://". Also test ":\\".
Bram Moolenaar2a79ed22017-05-24 09:51:39 +02004func Test_gf_url()
Bram Moolenaar53f16732016-09-07 20:46:39 +02005 enew!
6 call append(0, [
7 \ "first test for URL://machine.name/tmp/vimtest2a and other text",
8 \ "second test for URL://machine.name/tmp/vimtest2b. And other text",
9 \ "third test for URL:\\\\machine.name\\vimtest2c and other text",
Bram Moolenaar9e3dfc62017-12-25 14:29:18 +010010 \ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text",
11 \ "fifth test for URL://machine.name/tmp?q=vim&opt=yes and other text",
Bram Moolenaarcbef8e12019-03-09 12:32:56 +010012 \ "sixth test for URL://machine.name:1234?q=vim and other text",
Bram Moolenaar53f16732016-09-07 20:46:39 +020013 \ ])
14 call cursor(1,1)
15 call search("^first")
16 call search("tmp")
17 call assert_equal("URL://machine.name/tmp/vimtest2a", expand("<cfile>"))
18 call search("^second")
19 call search("URL")
20 call assert_equal("URL://machine.name/tmp/vimtest2b", expand("<cfile>"))
21 if has("ebcdic")
22 set isf=@,240-249,/,.,-,_,+,,,$,:,~,\
23 else
Bram Moolenaarcbef8e12019-03-09 12:32:56 +010024 set isf=@,48-57,/,.,-,_,+,,,$,~,\
Bram Moolenaar53f16732016-09-07 20:46:39 +020025 endif
26 call search("^third")
27 call search("name")
28 call assert_equal("URL:\\\\machine.name\\vimtest2c", expand("<cfile>"))
29 call search("^fourth")
30 call search("URL")
31 call assert_equal("URL:\\\\machine.name\\tmp\\vimtest2d", expand("<cfile>"))
32
Bram Moolenaar9e3dfc62017-12-25 14:29:18 +010033 call search("^fifth")
34 call search("URL")
35 call assert_equal("URL://machine.name/tmp?q=vim&opt=yes", expand("<cfile>"))
36
Bram Moolenaarcbef8e12019-03-09 12:32:56 +010037 call search("^sixth")
38 call search("URL")
39 call assert_equal("URL://machine.name:1234?q=vim", expand("<cfile>"))
40
Bram Moolenaar53f16732016-09-07 20:46:39 +020041 set isf&vim
42 enew!
Bram Moolenaar2a79ed22017-05-24 09:51:39 +020043endfunc
44
45func Test_gF()
46 new
47 call setline(1, ['111', '222', '333', '444'])
48 w! Xfile
49 close
50 new
Bram Moolenaar712598f2017-05-24 10:42:37 +020051 set isfname-=:
52 call setline(1, ['one', 'Xfile:3', 'three'])
Bram Moolenaar2a79ed22017-05-24 09:51:39 +020053 2
54 call assert_fails('normal gF', 'E37:')
55 call assert_equal(2, getcurpos()[1])
56 w! Xfile2
57 normal gF
58 call assert_equal('Xfile', bufname('%'))
59 call assert_equal(3, getcurpos()[1])
60
Bram Moolenaar64e74c92019-12-22 15:38:06 +010061 enew!
62 call setline(1, ['one', 'the Xfile line 2, and more', 'three'])
63 w! Xfile2
64 normal 2GfX
65 normal gF
66 call assert_equal('Xfile', bufname('%'))
67 call assert_equal(2, getcurpos()[1])
68
Bram Moolenaar712598f2017-05-24 10:42:37 +020069 set isfname&
Bram Moolenaar2a79ed22017-05-24 09:51:39 +020070 call delete('Xfile')
71 call delete('Xfile2')
72 bwipe Xfile
73 bwipe Xfile2
74endfunc
Bram Moolenaarf0ab01f2019-05-06 22:00:00 +020075
76" Test for invoking 'gf' on a ${VAR} variable
77func Test_gf()
78 if has("ebcdic")
79 set isfname=@,240-249,/,.,-,_,+,,,$,:,~,{,}
80 else
81 set isfname=@,48-57,/,.,-,_,+,,,$,:,~,{,}
82 endif
83
84 call writefile(["Test for gf command"], "Xtest1")
85 if has("unix")
86 call writefile([" ${CDIR}/Xtest1"], "Xtestgf")
87 else
88 call writefile([" $TDIR/Xtest1"], "Xtestgf")
89 endif
90 new Xtestgf
91 if has("unix")
92 let $CDIR = "."
93 /CDIR
94 else
95 if has("amiga")
96 let $TDIR = "/testdir"
97 else
98 let $TDIR = "."
99 endif
100 /TDIR
101 endif
102
103 normal gf
104 call assert_equal('Xtest1', fnamemodify(bufname(''), ":t"))
105 close!
106
107 call delete('Xtest1')
108 call delete('Xtestgf')
109endfunc
Bram Moolenaar0208b6b2019-11-08 21:49:48 +0100110
111func Test_gf_visual()
112 call writefile([], "Xtest_gf_visual")
113 new
114 call setline(1, 'XXXtest_gf_visualXXX')
115 set hidden
116
117 " Visually select Xtest_gf_visual and use gf to go to that file
118 norm! ttvtXgf
119 call assert_equal('Xtest_gf_visual', bufname('%'))
120
121 bwipe!
122 call delete('Xtest_gf_visual')
123 set hidden&
124endfunc
125
126func Test_gf_error()
127 new
128 call assert_fails('normal gf', 'E446:')
129 call assert_fails('normal gF', 'E446:')
130 call setline(1, '/doesnotexist')
131 call assert_fails('normal gf', 'E447:')
132 call assert_fails('normal gF', 'E447:')
Bram Moolenaar1671f442020-03-10 07:48:13 +0100133 call assert_fails('normal [f', 'E447:')
134
135 " gf is not allowed when text is locked
136 au InsertCharPre <buffer> normal! gF<CR>
Bram Moolenaarff06f282020-04-21 22:01:14 +0200137 let caught_e565 = 0
Bram Moolenaar1671f442020-03-10 07:48:13 +0100138 try
139 call feedkeys("ix\<esc>", 'xt')
Bram Moolenaarff06f282020-04-21 22:01:14 +0200140 catch /^Vim\%((\a\+)\)\=:E565/ " catch E565
141 let caught_e565 = 1
Bram Moolenaar1671f442020-03-10 07:48:13 +0100142 endtry
Bram Moolenaarff06f282020-04-21 22:01:14 +0200143 call assert_equal(1, caught_e565)
Bram Moolenaar1671f442020-03-10 07:48:13 +0100144 au! InsertCharPre
145
Bram Moolenaar0208b6b2019-11-08 21:49:48 +0100146 bwipe!
147endfunc
Bram Moolenaar1671f442020-03-10 07:48:13 +0100148
149" vim: shiftwidth=2 sts=2 expandtab