aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/mkview_spec.lua
blob: 7cc0b1da83fbeb9eeac1803702fc0756f3a67c5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)