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
|
2018-01-13 06:25:11 -07:00
|
|
|
local write_file = helpers.write_file
|
2018-01-08 17:06:59 -07:00
|
|
|
|
|
|
|
describe('fnamemodify()', function()
|
2018-01-13 06:25:11 -07:00
|
|
|
setup(function()
|
|
|
|
write_file('Xtest-fnamemodify.txt', [[foobar]])
|
|
|
|
end)
|
|
|
|
|
2018-01-08 17:06:59 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2018-01-13 06:25:11 -07:00
|
|
|
teardown(function()
|
|
|
|
os.remove('Xtest-fnamemodify.txt')
|
|
|
|
end)
|
|
|
|
|
2018-01-08 17:06:59 -07:00
|
|
|
it('works', function()
|
|
|
|
if iswin() then
|
2018-01-11 17:16:39 -07:00
|
|
|
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()
|
2018-01-11 15:31:29 -07:00
|
|
|
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')
|
2018-01-11 15:31:29 -07:00
|
|
|
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)
|
2018-01-13 06:25:11 -07:00
|
|
|
|
|
|
|
it(':8 works', function()
|
|
|
|
eq('Xtest-fnamemodify.txt', fnamemodify([[Xtest-fnamemodify.txt]], ':8'))
|
|
|
|
end)
|
2018-01-08 17:06:59 -07:00
|
|
|
end)
|