test(autochdir_spec): use better patterns

This commit is contained in:
zeertzjq 2022-03-06 09:25:58 +08:00
parent eb70540ff0
commit 0442635a50

View File

@ -14,19 +14,20 @@ describe('autochdir behavior', function()
before_each(function()
lfs.mkdir(dir)
clear()
command('set shellslash')
end)
after_each(function()
helpers.rmdir(dir)
end)
-- Tests vim/vim/777 without test_autochdir().
-- Tests vim/vim#777 without test_autochdir().
it('sets filename', function()
command('set acd')
command('new')
command('w '..dir..'/Xtest')
eq('Xtest', eval("expand('%')"))
eq(dir, eval([[substitute(getcwd(), '.*[/\\]\(\k*\)', '\1', '')]]))
eq(dir, eval([[substitute(getcwd(), '.*/\(\k*\)', '\1', '')]]))
end)
it(':file in win_execute() does not cause wrong directory', function()
@ -68,11 +69,11 @@ describe('autochdir behavior', function()
call('mkdir', subdir)
local winid = eval('win_getid()')
command('new '..subdir..'/file')
matches('.*'..dir..'[/\\]'..subdir, eval('getcwd()'))
matches(dir..'/'..subdir..'$', eval('getcwd()'))
command('cd ..')
matches('.*'..dir, eval('getcwd()'))
matches(dir..'$', eval('getcwd()'))
call('win_execute', winid, 'echo')
matches('.*'..dir, eval('getcwd()'))
matches(dir..'$', eval('getcwd()'))
end)
it(':verbose pwd shows whether autochdir is used', function()
@ -80,36 +81,36 @@ describe('autochdir behavior', function()
command('cd '..dir)
local cwd = eval('getcwd()')
command('edit global.txt')
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
matches('%[global%].*'..dir..'$', exec_capture('verbose pwd'))
call('mkdir', subdir)
command('split '..subdir..'/local.txt')
command('lcd '..subdir)
matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
matches('%[window%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd'))
command('set acd')
command('wincmd w')
matches('%[autochdir%].*'..dir, exec_capture('verbose pwd'))
matches('%[autochdir%].*'..dir..'$', exec_capture('verbose pwd'))
command('tcd '..cwd)
matches('%[tabpage%].*'..dir, exec_capture('verbose pwd'))
matches('%[tabpage%].*'..dir..'$', exec_capture('verbose pwd'))
command('cd '..cwd)
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
matches('%[global%].*'..dir..'$', exec_capture('verbose pwd'))
command('lcd '..cwd)
matches('%[window%].*'..dir, exec_capture('verbose pwd'))
matches('%[window%].*'..dir..'$', exec_capture('verbose pwd'))
command('edit')
matches('%[autochdir%].*'..dir, exec_capture('verbose pwd'))
matches('%[autochdir%].*'..dir..'$', exec_capture('verbose pwd'))
command('enew')
command('wincmd w')
matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd'))
command('wincmd w')
matches('%[window%].*'..dir, exec_capture('verbose pwd'))
matches('%[window%].*'..dir..'$', exec_capture('verbose pwd'))
command('wincmd w')
matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd'))
command('set noacd')
matches('%[autochdir%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
matches('%[autochdir%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd'))
command('wincmd w')
matches('%[window%].*'..dir, exec_capture('verbose pwd'))
matches('%[window%].*'..dir..'$', exec_capture('verbose pwd'))
command('cd '..cwd)
matches('%[global%].*'..dir, exec_capture('verbose pwd'))
matches('%[global%].*'..dir..'$', exec_capture('verbose pwd'))
command('wincmd w')
matches('%[window%].*'..dir..'[/\\]'..subdir, exec_capture('verbose pwd'))
matches('%[window%].*'..dir..'/'..subdir..'$', exec_capture('verbose pwd'))
end)
end)