neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

autochdir_spec.lua (1485B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local clear = n.clear
      5 local eq = t.eq
      6 local fn = n.fn
      7 local command = n.command
      8 local mkdir = t.mkdir
      9 
     10 describe("'autochdir'", function()
     11  it('given on the shell gets processed properly', function()
     12    local start_dir = vim.uv.cwd()
     13    local target_dir = t.paths.test_source_path .. '/test/functional/fixtures'
     14 
     15    -- By default 'autochdir' is off, thus getcwd() returns the initial directory.
     16    clear(target_dir .. '/tty-test.c')
     17    eq(start_dir, fn.getcwd())
     18 
     19    -- With 'autochdir' on, we should get the directory of tty-test.c.
     20    clear('--cmd', 'set autochdir', target_dir .. '/tty-test.c')
     21    eq(t.is_os('win') and target_dir:gsub('/', '\\') or target_dir, fn.getcwd())
     22  end)
     23 
     24  it('is not overwritten by getwinvar() call #17609', function()
     25    local curdir = t.fix_slashes(vim.uv.cwd())
     26    local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a'
     27    local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b'
     28    mkdir(dir_a)
     29    mkdir(dir_b)
     30    clear()
     31    command('set shellslash')
     32    command('set autochdir')
     33    command('edit ' .. dir_a .. '/file1')
     34    eq(dir_a, fn.getcwd())
     35    command('lcd ' .. dir_b)
     36    eq(dir_b, fn.getcwd())
     37    command('botright vnew ../file2')
     38    eq(curdir, fn.getcwd())
     39    command('wincmd w')
     40    eq(dir_a, fn.getcwd())
     41    fn.getwinvar(2, 'foo')
     42    eq(dir_a, fn.getcwd())
     43    n.rmdir(dir_a)
     44    n.rmdir(dir_b)
     45  end)
     46 end)