mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
tempfile.c: add tests
This commit is contained in:
parent
286ce271e7
commit
790d81582c
61
test/unit/tempfile_spec.lua
Normal file
61
test/unit/tempfile_spec.lua
Normal file
@ -0,0 +1,61 @@
|
||||
local lfs = require 'lfs'
|
||||
local helpers = require 'test.unit.helpers'
|
||||
|
||||
local os = helpers.cimport './src/nvim/os/os.h'
|
||||
local tempfile = helpers.cimport './src/nvim/tempfile.h'
|
||||
|
||||
describe('tempfile related functions', function()
|
||||
after_each(function()
|
||||
-- This won't work because vim_deltempdir() uses global buffer
|
||||
-- that is initialized in main() and main() is not called for unit tests.
|
||||
-- But it is not a big problem: all tests can work with or without it.
|
||||
-- tempfile.vim_deltempdir()
|
||||
end)
|
||||
|
||||
local vim_gettempdir = function()
|
||||
return helpers.ffi.string(tempfile.vim_gettempdir())
|
||||
end
|
||||
|
||||
describe('vim_gettempdir', function()
|
||||
it('returns path to Neovim own temp directory', function()
|
||||
local dir = vim_gettempdir()
|
||||
assert.True(dir ~= nil and dir:len() > 0)
|
||||
-- os_file_is_writable returns 2 for a directory which we have rights
|
||||
-- to write into.
|
||||
assert.equals(os.os_file_is_writable(helpers.to_cstr(dir)), 2)
|
||||
for entry in lfs.dir(dir) do
|
||||
assert.True(entry == '.' or entry == '..')
|
||||
end
|
||||
end)
|
||||
|
||||
it('returns the same directory on each call', function()
|
||||
local dir1 = vim_gettempdir()
|
||||
local dir2 = vim_gettempdir()
|
||||
assert.equals(dir1, dir2)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim_tempname', function()
|
||||
local vim_tempname = function()
|
||||
return helpers.ffi.string(tempfile.vim_tempname())
|
||||
end
|
||||
|
||||
it('generate name of non-existing file', function()
|
||||
local file = vim_tempname()
|
||||
assert.truthy(file)
|
||||
assert.False(os.os_file_exists(file))
|
||||
end)
|
||||
|
||||
it('generate different names on each call', function()
|
||||
local fst = vim_tempname()
|
||||
local snd = vim_tempname()
|
||||
assert.not_equals(fst, snd)
|
||||
end)
|
||||
|
||||
it('generate file name in Neovim own temp directory', function()
|
||||
local dir = vim_gettempdir()
|
||||
local file = vim_tempname()
|
||||
assert.truthy(file:find('^' .. dir .. '[^/]*$'))
|
||||
end)
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user