robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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