aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/window_spec.lua4
-rw-r--r--test/functional/lua/fs_spec.lua76
-rw-r--r--test/functional/lua/vim_spec.lua40
-rw-r--r--test/helpers.lua37
4 files changed, 128 insertions, 29 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 48431ccfc7..774ec406a8 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -490,6 +490,8 @@ describe('API/win', function()
it('closing current (float) window of another tabpage #15313', function()
command('tabedit')
+ command('botright split')
+ local prevwin = curwin().id
eq(2, eval('tabpagenr()'))
local win = meths.open_win(0, true, {
relative='editor', row=10, col=10, width=50, height=10
@@ -499,7 +501,7 @@ describe('API/win', function()
eq(1, eval('tabpagenr()'))
meths.win_close(win, false)
- eq(1001, meths.tabpage_get_win(tab).id)
+ eq(prevwin, meths.tabpage_get_win(tab).id)
assert_alive()
end)
end)
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index fc228e54bc..88ad6ba24a 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -12,6 +12,39 @@ local is_os = helpers.is_os
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
+local test_basename_dirname_eq = {
+ '~/foo/',
+ '~/foo',
+ '~/foo/bar.lua',
+ 'foo.lua',
+ ' ',
+ '',
+ '.',
+ '..',
+ '../',
+ '~',
+ '/usr/bin',
+ '/usr/bin/gcc',
+ '/',
+ '/usr/',
+ '/usr',
+ 'c:/usr',
+ 'c:/',
+ 'c:',
+ 'c:/users/foo',
+ 'c:/users/foo/bar.lua',
+ 'c:/users/foo/bar/../',
+}
+
+local tests_windows_paths = {
+ 'c:\\usr',
+ 'c:\\',
+ 'c:',
+ 'c:\\users\\foo',
+ 'c:\\users\\foo\\bar.lua',
+ 'c:\\users\\foo\\bar\\..\\',
+}
+
before_each(clear)
describe('vim.fs', function()
@@ -41,15 +74,58 @@ describe('vim.fs', function()
local nvim_dir = ...
return vim.fs.dirname(nvim_dir)
]], nvim_dir))
+
+ local function test_paths(paths)
+ for _, path in ipairs(paths) do
+ eq(
+ exec_lua([[
+ local path = ...
+ return vim.fn.fnamemodify(path,':h'):gsub('\\', '/')
+ ]], path),
+ exec_lua([[
+ local path = ...
+ return vim.fs.dirname(path)
+ ]], path),
+ path
+ )
+ end
+ end
+
+ test_paths(test_basename_dirname_eq)
+ if is_os('win') then
+ test_paths(tests_windows_paths)
+ end
end)
end)
describe('basename()', function()
it('works', function()
+
eq(nvim_prog_basename, exec_lua([[
local nvim_prog = ...
return vim.fs.basename(nvim_prog)
]], nvim_prog))
+
+ local function test_paths(paths)
+ for _, path in ipairs(paths) do
+ eq(
+ exec_lua([[
+ local path = ...
+ return vim.fn.fnamemodify(path,':t'):gsub('\\', '/')
+ ]], path),
+ exec_lua([[
+ local path = ...
+ return vim.fs.basename(path)
+ ]], path),
+ path
+ )
+ end
+ end
+
+ test_paths(test_basename_dirname_eq)
+ if is_os('win') then
+ test_paths(tests_windows_paths)
+ end
end)
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 4266d30e73..c74e88f55d 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -2679,6 +2679,46 @@ describe('lua stdlib', function()
a.nvim_buf_call(a.nvim_create_buf(false, true), function() vim.cmd "redraw" end)
]]
end)
+
+ it('can be nested crazily with hidden buffers', function()
+ eq(true, exec_lua([[
+ local function scratch_buf_call(fn)
+ local buf = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_option(buf, 'cindent', true)
+ return vim.api.nvim_buf_call(buf, function()
+ return vim.api.nvim_get_current_buf() == buf
+ and vim.api.nvim_buf_get_option(buf, 'cindent')
+ and fn()
+ end) and vim.api.nvim_buf_delete(buf, {}) == nil
+ end
+
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return scratch_buf_call(function()
+ return true
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ end)
+ ]]))
+ end)
end)
describe('vim.api.nvim_win_call', function()
diff --git a/test/helpers.lua b/test/helpers.lua
index eef47563a0..3fe4322501 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -269,29 +269,10 @@ function module.check_logs()
table.concat(runtime_errors, ', ')))
end
--- Gets (lowercase) OS name from CMake, uname, or manually check if on Windows
-do
- local platform = nil
- function module.uname()
- if platform then
- return platform
- end
-
- if os.getenv("SYSTEM_NAME") then -- From CMAKE_HOST_SYSTEM_NAME.
- platform = string.lower(os.getenv("SYSTEM_NAME"))
- return platform
- end
-
- local status, f = pcall(module.popen_r, 'uname', '-s')
- if status then
- platform = string.lower(f:read("*l"))
- f:close()
- elseif package.config:sub(1,1) == '\\' then
- platform = 'windows'
- else
- error('unknown platform')
- end
- return platform
+function module.sysname()
+ local platform = luv.os_uname()
+ if platform and platform.sysname then
+ return platform.sysname:lower()
end
end
@@ -303,11 +284,11 @@ function module.is_os(s)
or s == 'bsd') then
error('unknown platform: '..tostring(s))
end
- return ((s == 'win' and module.uname() == 'windows')
- or (s == 'mac' and module.uname() == 'darwin')
- or (s == 'freebsd' and module.uname() == 'freebsd')
- or (s == 'openbsd' and module.uname() == 'openbsd')
- or (s == 'bsd' and string.find(module.uname(), 'bsd')))
+ return ((s == 'win' and module.sysname():find('windows'))
+ or (s == 'mac' and module.sysname() == 'darwin')
+ or (s == 'freebsd' and module.sysname() == 'freebsd')
+ or (s == 'openbsd' and module.sysname() == 'openbsd')
+ or (s == 'bsd' and module.sysname():find('bsd')))
end
local function tmpdir_get()