aboutsummaryrefslogtreecommitdiff
path: root/test/unit/path_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 21:52:58 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 21:52:58 +0000
commit931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch)
treed8c1843a95da5ea0bb4acc09f7e37843d9995c86 /test/unit/path_spec.lua
parent142d9041391780ac15b89886a54015fdc5c73995 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-userreg.tar.gz
rneovim-userreg.tar.bz2
rneovim-userreg.zip
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'test/unit/path_spec.lua')
-rw-r--r--test/unit/path_spec.lua81
1 files changed, 46 insertions, 35 deletions
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index 1fc4e2496e..23f71cfe78 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -1,4 +1,4 @@
-local lfs = require('lfs')
+local luv = require('luv')
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
@@ -11,9 +11,11 @@ local to_cstr = helpers.to_cstr
local NULL = helpers.NULL
local OK = helpers.OK
local FAIL = helpers.FAIL
+local mkdir = helpers.mkdir
cimport('string.h')
local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h')
+local options = cimport('./src/nvim/option_vars.h')
local length = 0
local buffer = nil
@@ -21,11 +23,11 @@ local buffer = nil
describe('path.c', function()
describe('path_full_dir_name', function()
setup(function()
- lfs.mkdir('unit-test-directory')
+ mkdir('unit-test-directory')
end)
teardown(function()
- lfs.rmdir('unit-test-directory')
+ luv.fs_rmdir('unit-test-directory')
end)
local function path_full_dir_name(directory, buf, len)
@@ -35,34 +37,34 @@ describe('path.c', function()
before_each(function()
-- Create empty string buffer which will contain the resulting path.
- length = string.len(lfs.currentdir()) + 22
+ length = string.len(luv.cwd()) + 22
buffer = cstr(length, '')
end)
itp('returns the absolute directory name of a given relative one', function()
local result = path_full_dir_name('..', buffer, length)
eq(OK, result)
- local old_dir = lfs.currentdir()
- lfs.chdir('..')
- local expected = lfs.currentdir()
- lfs.chdir(old_dir)
+ local old_dir = luv.cwd()
+ luv.chdir('..')
+ local expected = luv.cwd()
+ luv.chdir(old_dir)
eq(expected, (ffi.string(buffer)))
end)
itp('returns the current directory name if the given string is empty', function()
eq(OK, (path_full_dir_name('', buffer, length)))
- eq(lfs.currentdir(), (ffi.string(buffer)))
+ eq(luv.cwd(), (ffi.string(buffer)))
end)
itp('works with a normal relative dir', function()
local result = path_full_dir_name('unit-test-directory', buffer, length)
- eq(lfs.currentdir() .. '/unit-test-directory', (ffi.string(buffer)))
+ eq(luv.cwd() .. '/unit-test-directory', (ffi.string(buffer)))
eq(OK, result)
end)
itp('works with a non-existing relative dir', function()
local result = path_full_dir_name('does-not-exist', buffer, length)
- eq(lfs.currentdir() .. '/does-not-exist', (ffi.string(buffer)))
+ eq(luv.cwd() .. '/does-not-exist', (ffi.string(buffer)))
eq(OK, result)
end)
@@ -268,27 +270,27 @@ describe('path.c', function()
end)
describe('path_try_shorten_fname', function()
- local cwd = lfs.currentdir()
+ local cwd = luv.cwd()
before_each(function()
- lfs.mkdir('ut_directory')
+ mkdir('ut_directory')
end)
after_each(function()
- lfs.chdir(cwd)
- lfs.rmdir('ut_directory')
+ luv.chdir(cwd)
+ luv.fs_rmdir('ut_directory')
end)
describe('path_try_shorten_fname', function()
itp('returns shortened path if possible', function()
- lfs.chdir('ut_directory')
- local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt')
+ luv.chdir('ut_directory')
+ local full = to_cstr(luv.cwd() .. '/subdir/file.txt')
eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full))))
end)
itp('returns `full_path` if a shorter version is not possible', function()
- local old = lfs.currentdir()
- lfs.chdir('ut_directory')
+ local old = luv.cwd()
+ luv.chdir('ut_directory')
local full = old .. '/subdir/file.txt'
eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full)))))
end)
@@ -300,7 +302,7 @@ describe('path_try_shorten_fname', function()
end)
describe('path.c path_guess_exepath', function()
- local cwd = lfs.currentdir()
+ local cwd = luv.cwd()
for _,name in ipairs({'./nvim', '.nvim', 'foo/nvim'}) do
itp('"'..name..'" returns name catenated with CWD', function()
@@ -354,7 +356,7 @@ end)
describe('path.c', function()
setup(function()
- lfs.mkdir('unit-test-directory');
+ mkdir('unit-test-directory');
io.open('unit-test-directory/test.file', 'w'):close()
-- Since the tests are executed, they are called by an executable. We use
@@ -368,7 +370,7 @@ describe('path.c', function()
teardown(function()
os.remove('unit-test-directory/test.file')
- lfs.rmdir('unit-test-directory')
+ luv.fs_rmdir('unit-test-directory')
end)
describe('vim_FullName', function()
@@ -420,7 +422,7 @@ describe('path.c', function()
end)
itp('concatenates filename if it does not contain a slash', function()
- local expected = lfs.currentdir() .. '/test.file'
+ local expected = luv.cwd() .. '/test.file'
local filename = 'test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -430,7 +432,7 @@ describe('path.c', function()
end)
itp('concatenates directory name if it does not contain a slash', function()
- local expected = lfs.currentdir() .. '/..'
+ local expected = luv.cwd() .. '/..'
local filename = '..'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -440,10 +442,10 @@ describe('path.c', function()
end)
itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function()
- local old_dir = lfs.currentdir()
- lfs.chdir('..')
- local expected = lfs.currentdir() .. '/test.file'
- lfs.chdir(old_dir)
+ local old_dir = luv.cwd()
+ luv.chdir('..')
+ local expected = luv.cwd() .. '/test.file'
+ luv.chdir(old_dir)
local filename = '../test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -472,7 +474,7 @@ describe('path.c', function()
end)
itp('works with some "normal" relative path with directories', function()
- local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
+ local expected = luv.cwd() .. '/unit-test-directory/test.file'
local filename = 'unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -482,7 +484,7 @@ describe('path.c', function()
end)
itp('does not modify the given filename', function()
- local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
+ local expected = luv.cwd() .. '/unit-test-directory/test.file'
local filename = to_cstr('unit-test-directory/test.file')
local buflen = string.len(expected) + 1
local buf = cstr(buflen, '')
@@ -505,7 +507,7 @@ describe('path.c', function()
end)
itp('does not remove trailing slash from non-existing relative directory #20847', function()
- local expected = lfs.currentdir() .. '/non_existing_dir/'
+ local expected = luv.cwd() .. '/non_existing_dir/'
local filename = 'non_existing_dir/'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -515,7 +517,7 @@ describe('path.c', function()
end)
itp('expands "./" to the current directory #7117', function()
- local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
+ local expected = luv.cwd() .. '/unit-test-directory/test.file'
local filename = './unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -525,7 +527,7 @@ describe('path.c', function()
end)
itp('collapses "foo/../foo" to "foo" #7117', function()
- local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
+ local expected = luv.cwd() .. '/unit-test-directory/test.file'
local filename = 'unit-test-directory/../unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -542,8 +544,8 @@ describe('path.c', function()
return ffi.string(c_file)
end
- before_each(function() lfs.mkdir('CamelCase') end)
- after_each(function() lfs.rmdir('CamelCase') end)
+ before_each(function() mkdir('CamelCase') end)
+ after_each(function() luv.fs_rmdir('CamelCase') end)
if ffi.os == 'Windows' or ffi.os == 'OSX' then
itp('Corrects the case of file names in Mac and Windows', function()
@@ -635,6 +637,15 @@ describe('path.c', function()
eq(false, path_with_extension('/some/path/file.vim', 'lua'))
eq(false, path_with_extension('/some/path/file', 'lua'))
end)
+
+ itp("respects 'fileignorecase' option", function()
+ options.p_fic = false
+ eq(false, path_with_extension('/some/path/file.VIM', 'vim'))
+ eq(false, path_with_extension('/some/path/file.LUA', 'lua'))
+ options.p_fic = true
+ eq(true, path_with_extension('/some/path/file.VIM', 'vim'))
+ eq(true, path_with_extension('/some/path/file.LUA', 'lua'))
+ end)
end)
describe('path_with_url', function()