neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

002_filename_recognition_spec.lua (1651B)


      1 -- Test if URLs are recognized as filenames by commands such as "gf". Here
      2 -- we'll use `expand("<cfile>")` since "gf" would need to open the file.
      3 
      4 local n = require('test.functional.testnvim')()
      5 
      6 local clear, feed, insert = n.clear, n.feed, n.insert
      7 local feed_command, expect = n.feed_command, n.expect
      8 
      9 describe('filename recognition', function()
     10  setup(clear)
     11 
     12  it('is working', function()
     13    -- insert some lines containing URLs
     14    insert([[
     15      first test for URL://machine.name/tmp/vimtest2a and other text
     16      second test for URL://machine.name/tmp/vimtest2b. And other text
     17      third test for URL:\\machine.name\vimtest2c and other text
     18      fourth test for URL:\\machine.name\tmp\vimtest2d, and other text]])
     19 
     20    -- Go to the first URL and append it to the beginning
     21    feed_command('/^first', '/tmp', 'call append(0, expand("<cfile>"))')
     22 
     23    -- Repeat for the second URL
     24    -- this time, navigate to the word "URL" instead of "tmp"
     25    feed_command('/^second', '/URL', 'call append(1, expand("<cfile>"))')
     26 
     27    -- Repeat for the remaining URLs. This time, the 'isfname' option must be
     28    -- set to allow '\' in filenames
     29    feed_command('set isf=@,48-57,/,.,-,_,+,,,$,:,~,\\')
     30    feed_command('/^third', '/name', 'call append(2, expand("<cfile>"))')
     31    feed_command('/^fourth', '/URL', 'call append(3, expand("<cfile>"))')
     32 
     33    -- Delete the initial text, which now starts at line 5
     34    feed('5GdG')
     35 
     36    -- The buffer should now contain:
     37    expect([[
     38      URL://machine.name/tmp/vimtest2a
     39      URL://machine.name/tmp/vimtest2b
     40      URL:\\machine.name\vimtest2c
     41      URL:\\machine.name\tmp\vimtest2d]])
     42  end)
     43 end)