neovim/test/functional/eval/fnamemodify_spec.lua

46 lines
1.3 KiB
Lua
Raw Normal View History

2018-01-08 17:06:59 -07:00
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local iswin = helpers.iswin
local fnamemodify = helpers.funcs.fnamemodify
2018-01-11 09:05:15 -07:00
local command = helpers.command
local write_file = helpers.write_file
2018-01-08 17:06:59 -07:00
describe('fnamemodify()', function()
setup(function()
write_file('Xtest-fnamemodify.txt', [[foobar]])
end)
2018-01-08 17:06:59 -07:00
before_each(clear)
teardown(function()
os.remove('Xtest-fnamemodify.txt')
end)
2018-01-08 17:06:59 -07:00
it('works', function()
if iswin() then
local drive_f = io.popen('for %P in (%CD%) do @echo %~dP', 'r')
local drive = string.gsub(drive_f:read('*a'), '[\n\r]', '')
drive_f:close()
local root = drive..[[\]]
eq(root, fnamemodify([[\]], ':p:h'))
eq(root, fnamemodify([[\]], ':p'))
eq(root, fnamemodify([[/]], ':p:h'))
eq(root, fnamemodify([[/]], ':p'))
2018-01-11 09:05:15 -07:00
command('set shellslash')
root = drive..[[/]]
eq(root, fnamemodify([[\]], ':p:h'))
eq(root, fnamemodify([[\]], ':p'))
eq(root, fnamemodify([[/]], ':p:h'))
eq(root, fnamemodify([[/]], ':p'))
2018-01-08 17:06:59 -07:00
else
eq('/', fnamemodify([[/]], ':p:h'))
eq('/', fnamemodify([[/]], ':p'))
end
end)
it(':8 works', function()
eq('Xtest-fnamemodify.txt', fnamemodify([[Xtest-fnamemodify.txt]], ':8'))
end)
2018-01-08 17:06:59 -07:00
end)