neovim

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

mkview_spec.lua (1965B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local clear = n.clear
      5 local command = n.command
      6 local get_pathsep = n.get_pathsep
      7 local eq = t.eq
      8 local fn = n.fn
      9 local rmdir = n.rmdir
     10 local mkdir = t.mkdir
     11 
     12 local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
     13 
     14 describe(':mkview', function()
     15  local tmp_file_base = file_prefix .. '-tmpfile'
     16  local local_dir = file_prefix .. '.d'
     17  local view_dir = file_prefix .. '.view.d'
     18 
     19  before_each(function()
     20    clear()
     21    mkdir(view_dir)
     22    mkdir(local_dir)
     23  end)
     24 
     25  after_each(function()
     26    -- Remove any views created in the view directory
     27    rmdir(view_dir)
     28    rmdir(local_dir)
     29  end)
     30 
     31  it('viewoption curdir restores local current directory', function()
     32    local cwd_dir = fn.getcwd()
     33    local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir
     34 
     35    -- By default the local current directory should save
     36    command(set_view_dir_command)
     37    command('edit ' .. tmp_file_base .. '1')
     38    command('lcd ' .. local_dir)
     39    command('mkview')
     40 
     41    -- Create a new instance of Nvim to remove the 'lcd'
     42    clear()
     43 
     44    -- Disable saving the local current directory for the second view
     45    command(set_view_dir_command)
     46    command('set viewoptions-=curdir')
     47    command('edit ' .. tmp_file_base .. '2')
     48    command('lcd ' .. local_dir)
     49    command('mkview')
     50 
     51    -- Create a new instance of Nvim to test saved 'lcd' option
     52    clear()
     53    command(set_view_dir_command)
     54 
     55    -- Load the view without a saved local current directory
     56    command('edit ' .. tmp_file_base .. '2')
     57    command('loadview')
     58    -- The view's current directory should not have changed
     59    eq(cwd_dir, fn.getcwd())
     60    -- Load the view with a saved local current directory
     61    command('edit ' .. tmp_file_base .. '1')
     62    command('loadview')
     63    -- The view's local directory should have been saved
     64    eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
     65  end)
     66 end)