2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-10-27 07:48:24 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
|
|
|
local get_pathsep = n.get_pathsep
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
|
|
|
local rmdir = n.rmdir
|
2024-04-08 02:03:20 -07:00
|
|
|
local mkdir = t.mkdir
|
2017-10-27 07:48:24 -07:00
|
|
|
|
|
|
|
local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
|
|
|
|
|
|
|
|
describe(':mkview', function()
|
|
|
|
local tmp_file_base = file_prefix .. '-tmpfile'
|
|
|
|
local local_dir = file_prefix .. '.d'
|
|
|
|
local view_dir = file_prefix .. '.view.d'
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir(view_dir)
|
|
|
|
mkdir(local_dir)
|
2017-10-27 07:48:24 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
-- Remove any views created in the view directory
|
|
|
|
rmdir(view_dir)
|
2018-01-31 19:12:37 -07:00
|
|
|
rmdir(local_dir)
|
2017-10-27 07:48:24 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('viewoption curdir restores local current directory', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local cwd_dir = fn.getcwd()
|
2017-10-27 07:48:24 -07:00
|
|
|
local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir
|
|
|
|
|
|
|
|
-- By default the local current directory should save
|
|
|
|
command(set_view_dir_command)
|
|
|
|
command('edit ' .. tmp_file_base .. '1')
|
|
|
|
command('lcd ' .. local_dir)
|
|
|
|
command('mkview')
|
|
|
|
|
|
|
|
-- Create a new instance of Nvim to remove the 'lcd'
|
|
|
|
clear()
|
|
|
|
|
|
|
|
-- Disable saving the local current directory for the second view
|
|
|
|
command(set_view_dir_command)
|
|
|
|
command('set viewoptions-=curdir')
|
|
|
|
command('edit ' .. tmp_file_base .. '2')
|
|
|
|
command('lcd ' .. local_dir)
|
|
|
|
command('mkview')
|
|
|
|
|
|
|
|
-- Create a new instance of Nvim to test saved 'lcd' option
|
|
|
|
clear()
|
|
|
|
command(set_view_dir_command)
|
|
|
|
|
|
|
|
-- Load the view without a saved local current directory
|
|
|
|
command('edit ' .. tmp_file_base .. '2')
|
|
|
|
command('loadview')
|
|
|
|
-- The view's current directory should not have changed
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(cwd_dir, fn.getcwd())
|
2017-10-27 07:48:24 -07:00
|
|
|
-- Load the view with a saved local current directory
|
|
|
|
command('edit ' .. tmp_file_base .. '1')
|
|
|
|
command('loadview')
|
|
|
|
-- The view's local directory should have been saved
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
|
2017-10-27 07:48:24 -07:00
|
|
|
end)
|
|
|
|
end)
|