robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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