diff options
Diffstat (limited to 'test/functional/ex_cmds/cd_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/cd_spec.lua | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index b6a3713158..1815c672dc 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -1,6 +1,5 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq @@ -21,18 +20,30 @@ local directories = { } -- Shorthand writing to get the current working directory -local cwd = function(...) return call('getcwd', ...) end -- effective working dir -local wcwd = function() return cwd(0) end -- window dir -local tcwd = function() return cwd(-1, 0) end -- tab dir +local cwd = function(...) + return call('getcwd', ...) +end -- effective working dir +local wcwd = function() + return cwd(0) +end -- window dir +local tcwd = function() + return cwd(-1, 0) +end -- tab dir -- Same, except these tell us if there is a working directory at all -local lwd = function(...) return call('haslocaldir', ...) end -- effective working dir -local wlwd = function() return lwd(0) end -- window dir -local tlwd = function() return lwd(-1, 0) end -- tab dir +local lwd = function(...) + return call('haslocaldir', ...) +end -- effective working dir +local wlwd = function() + return lwd(0) +end -- window dir +local tlwd = function() + return lwd(-1, 0) +end -- tab dir --local glwd = function() return eval('haslocaldir(-1, -1)') end -- global dir -- Test both the `cd` and `chdir` variants -for _, cmd in ipairs {'cd', 'chdir'} do +for _, cmd in ipairs { 'cd', 'chdir' } do describe(':' .. cmd, function() before_each(function() clear() @@ -44,7 +55,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do after_each(function() for _, d in pairs(directories) do - luv.fs_rmdir(d) + vim.uv.fs_rmdir(d) end end) @@ -168,23 +179,23 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Create a new tab first and verify that is has the same working dir command('tabnew') eq(globalDir, cwd()) - eq(globalDir, tcwd()) -- has no tab-local directory + eq(globalDir, tcwd()) -- has no tab-local directory eq(0, tlwd()) - eq(globalDir, wcwd()) -- has no window-local directory + eq(globalDir, wcwd()) -- has no window-local directory eq(0, wlwd()) -- Change tab-local working directory and verify it is different command('silent t' .. cmd .. ' ' .. directories.tab) eq(globalDir .. pathsep .. directories.tab, cwd()) - eq(cwd(), tcwd()) -- working directory matches tab directory + eq(cwd(), tcwd()) -- working directory matches tab directory eq(1, tlwd()) - eq(cwd(), wcwd()) -- still no window-directory + eq(cwd(), wcwd()) -- still no window-directory eq(0, wlwd()) -- Create a new window in this tab to test `:lcd` command('new') - eq(1, tlwd()) -- Still tab-local working directory - eq(0, wlwd()) -- Still no window-local working directory + eq(1, tlwd()) -- Still tab-local working directory + eq(0, wlwd()) -- Still no window-local working directory eq(globalDir .. pathsep .. directories.tab, cwd()) command('silent l' .. cmd .. ' ../' .. directories.window) eq(globalDir .. pathsep .. directories.window, cwd()) @@ -193,13 +204,13 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Verify the first window still has the tab local directory command('wincmd w') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- No window-local directory + eq(0, wlwd()) -- No window-local directory -- Change back to initial tab and verify working directory has stayed command('tabnext') - eq(globalDir, cwd() ) + eq(globalDir, cwd()) eq(0, tlwd()) eq(0, wlwd()) @@ -207,31 +218,31 @@ for _, cmd in ipairs {'cd', 'chdir'} do command('silent ' .. cmd .. ' ' .. directories.global) eq(globalDir .. pathsep .. directories.global, cwd()) command('tabnext') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- Still no window-local directory in this window + eq(0, wlwd()) -- Still no window-local directory in this window -- Unless the global change happened in a tab with local directory command('silent ' .. cmd .. ' ..') - eq(globalDir, cwd() ) - eq(0 , tlwd()) - eq(0 , wlwd()) + eq(globalDir, cwd()) + eq(0, tlwd()) + eq(0, wlwd()) -- Which also affects the first tab command('tabnext') eq(globalDir, cwd()) -- But not in a window with its own local directory command('tabnext | wincmd w') - eq(globalDir .. pathsep .. directories.window, cwd() ) - eq(0 , tlwd()) + eq(globalDir .. pathsep .. directories.window, cwd()) + eq(0, tlwd()) eq(globalDir .. pathsep .. directories.window, wcwd()) end) end) end -- Test legal parameters for 'getcwd' and 'haslocaldir' -for _, cmd in ipairs {'getcwd', 'haslocaldir'} do - describe(cmd..'()', function() +for _, cmd in ipairs { 'getcwd', 'haslocaldir' } do + describe(cmd .. '()', function() before_each(function() clear() end) @@ -271,7 +282,7 @@ for _, cmd in ipairs {'getcwd', 'haslocaldir'} do end) end -describe("getcwd()", function () +describe('getcwd()', function() before_each(function() clear() mkdir(directories.global) @@ -281,11 +292,11 @@ describe("getcwd()", function () helpers.rmdir(directories.global) end) - it("returns empty string if working directory does not exist", function() + it('returns empty string if working directory does not exist', function() skip(is_os('win')) - command("cd "..directories.global) - command("call delete('../"..directories.global.."', 'd')") - eq("", helpers.eval("getcwd()")) + command('cd ' .. directories.global) + command("call delete('../" .. directories.global .. "', 'd')") + eq('', helpers.eval('getcwd()')) end) it("works with 'autochdir' after local directory was set (#9892)", function() |