HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ubuntu/neovim/test/functional/ex_cmds/mkview_spec.lua
local t = require('test.testutil')
local n = require('test.functional.testnvim')()

local clear = n.clear
local command = n.command
local get_pathsep = n.get_pathsep
local eq = t.eq
local fn = n.fn
local rmdir = n.rmdir
local mkdir = t.mkdir

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()
    mkdir(view_dir)
    mkdir(local_dir)
  end)

  after_each(function()
    -- Remove any views created in the view directory
    rmdir(view_dir)
    rmdir(local_dir)
  end)

  it('viewoption curdir restores local current directory', function()
    local cwd_dir = fn.getcwd()
    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
    eq(cwd_dir, fn.getcwd())
    -- 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
    eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
  end)
end)