neovim

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

autochdir_spec.lua (4812B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local clear, eq, matches = n.clear, t.eq, t.matches
      5 local eval, command, call, api = n.eval, n.command, n.call, n.api
      6 local source, exec_capture = n.source, n.exec_capture
      7 local mkdir = t.mkdir
      8 
      9 local function expected_empty()
     10  eq({}, api.nvim_get_vvar('errors'))
     11 end
     12 
     13 describe('autochdir behavior', function()
     14  local dir = 'Xtest_functional_legacy_autochdir'
     15 
     16  before_each(function()
     17    mkdir(dir)
     18    clear()
     19    command('set shellslash')
     20  end)
     21 
     22  after_each(function()
     23    n.rmdir(dir)
     24  end)
     25 
     26  -- Tests vim/vim#777 without test_autochdir().
     27  it('sets filename', function()
     28    command('set acd')
     29    command('new')
     30    command('w ' .. dir .. '/Xtest')
     31    eq('Xtest', eval("expand('%')"))
     32    eq(dir, eval([[substitute(getcwd(), '.*/\(\k*\)', '\1', '')]]))
     33  end)
     34 
     35  -- oldtest: Test_set_filename_other_window()
     36  it(':file in win_execute() does not cause wrong directory', function()
     37    command('cd ' .. dir)
     38    source([[
     39      func Test_set_filename_other_window()
     40        let cwd = getcwd()
     41        call mkdir('Xa')
     42        call mkdir('Xb')
     43        call mkdir('Xc')
     44        try
     45          args Xa/aaa.txt Xb/bbb.txt
     46          set acd
     47          let winid = win_getid()
     48          snext
     49          call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
     50          call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
     51          call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
     52        finally
     53          set noacd
     54          call chdir(cwd)
     55          call delete('Xa', 'rf')
     56          call delete('Xb', 'rf')
     57          call delete('Xc', 'rf')
     58          bwipe! aaa.txt
     59          bwipe! bbb.txt
     60          bwipe! ccc.txt
     61        endtry
     62      endfunc
     63    ]])
     64    call('Test_set_filename_other_window')
     65    expected_empty()
     66  end)
     67 
     68  -- oldtest: Test_acd_win_execute()
     69  it('win_execute() does not change directory', function()
     70    local subdir = 'Xfile'
     71    command('cd ' .. dir)
     72    command('set acd')
     73    call('mkdir', subdir)
     74    local winid = eval('win_getid()')
     75    command('new ' .. subdir .. '/file')
     76    matches(dir .. '/' .. subdir .. '$', eval('getcwd()'))
     77    command('cd ..')
     78    matches(dir .. '$', eval('getcwd()'))
     79    call('win_execute', winid, 'echo')
     80    matches(dir .. '$', eval('getcwd()'))
     81  end)
     82 
     83  -- oldtest: Test_verbose_pwd()
     84  it(':verbose pwd shows whether autochdir is used', function()
     85    local subdir = 'Xautodir'
     86    command('cd ' .. dir)
     87    local cwd = eval('getcwd()')
     88    command('edit global.txt')
     89    matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
     90    call('mkdir', subdir)
     91    command('split ' .. subdir .. '/local.txt')
     92    command('lcd ' .. subdir)
     93    matches('%[window%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
     94    command('set acd')
     95    command('wincmd w')
     96    matches('%[autochdir%].*' .. dir .. '$', exec_capture('verbose pwd'))
     97    command('tcd ' .. cwd)
     98    matches('%[tabpage%].*' .. dir .. '$', exec_capture('verbose pwd'))
     99    command('cd ' .. cwd)
    100    matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
    101    command('lcd ' .. cwd)
    102    matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
    103    command('edit')
    104    matches('%[autochdir%].*' .. dir .. '$', exec_capture('verbose pwd'))
    105    command('enew')
    106    command('wincmd w')
    107    matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
    108    command('wincmd w')
    109    matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
    110    command('wincmd w')
    111    matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
    112    command('set noacd')
    113    matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
    114    command('wincmd w')
    115    matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
    116    command('cd ' .. cwd)
    117    matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
    118    command('wincmd w')
    119    matches('%[window%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
    120  end)
    121 
    122  it('overriding via :lcd is not clobbered by win_execute()', function()
    123    command('cd ' .. dir)
    124    source([[
    125      func Test_lcd_win_execute()
    126        let startdir = getcwd()
    127        call mkdir('Xsubdir', 'R')
    128        set autochdir
    129        edit Xsubdir/file
    130        call assert_match('_autochdir.Xsubdir.file$', expand('%:p'))
    131        split
    132        lcd ..
    133        call assert_match('_autochdir.Xsubdir.file$', expand('%:p'))
    134        call win_execute(win_getid(2), "")
    135        call assert_match('_autochdir.Xsubdir.file$', expand('%:p'))
    136 
    137        set noautochdir
    138        bwipe!
    139        call chdir(startdir)
    140      endfunc
    141    ]])
    142    call('Test_lcd_win_execute')
    143    expected_empty()
    144  end)
    145 end)