robin/laufey

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

Justin M. Keyesfix(cwd): stale buffer names after temp context-switch #41433b296666e41

master
2.3 KiB70 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it = t.describe, t.it
5local clear = n.clear
6local eq = t.eq
7local fn = n.fn
8local command = n.command
9local api = n.api
10local mkdir = t.mkdir
11
12describe("'autochdir'", function()
13  it('given on the shell gets processed properly', function()
14    local start_dir = vim.uv.cwd()
15    local target_dir = t.paths.test_source_path .. '/test/functional/fixtures'
16
17    -- By default 'autochdir' is off, thus getcwd() returns the initial directory.
18    clear(target_dir .. '/tty-test.c')
19    eq(start_dir, fn.getcwd())
20
21    -- With 'autochdir' on, we should get the directory of tty-test.c.
22    clear('--cmd', 'set autochdir', target_dir .. '/tty-test.c')
23    eq(t.is_os('win') and target_dir:gsub('/', '\\') or target_dir, fn.getcwd())
24  end)
25
26  it('is not overwritten by getwinvar() call #17609', function()
27    local curdir = t.fix_slashes(vim.uv.cwd())
28    local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a'
29    local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b'
30    mkdir(dir_a)
31    mkdir(dir_b)
32    clear()
33    command('set shellslash')
34    command('set autochdir')
35    command('edit ' .. dir_a .. '/file1')
36    eq(dir_a, fn.getcwd())
37    command('lcd ' .. dir_b)
38    eq(dir_b, fn.getcwd())
39    command('botright vnew ../file2')
40    eq(curdir, fn.getcwd())
41    command('wincmd w')
42    eq(dir_a, fn.getcwd())
43    fn.getwinvar(2, 'foo')
44    eq(dir_a, fn.getcwd())
45    n.rmdir(dir_a)
46    n.rmdir(dir_b)
47  end)
48
49  it('win_execute() keeps buffer names #41417', function()
50    local root = vim.fs.normalize(t.tmpname(false))
51    mkdir(root)
52    mkdir(root .. '/a')
53    mkdir(root .. '/b')
54    clear()
55    command('set shellslash')
56    command('edit ' .. root .. '/a/file_a')
57    command('vsplit ' .. root .. '/b/file_b')
58    local win_b, buf_b = api.nvim_get_current_win(), api.nvim_get_current_buf()
59    command('wincmd p')
60    command('set autochdir')
61    -- Sit in an ancestor of both files: 'autochdir' moves away from it during win_execute(), and
62    -- both buffer names stay shortened, i.e. relative to the CWD.
63    command('cd ' .. root)
64    eq({ 'a/file_a', 'b/file_b' }, { fn.bufname('%'), fn.bufname(buf_b) })
65
66    fn.win_execute(win_b, 'echo')
67
68    eq({ 'a/file_a', 'b/file_b' }, { fn.bufname('%'), fn.bufname(buf_b) })
69  end)
70end)