代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/z.lua 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
local zmod = require('z')
local windows = os.path.sep == '\\'
-----------------------------------------------------------------------
-- logo
-----------------------------------------------------------------------
function print_title(text)
print(string.rep('-', 72))
print('-- '.. text)
print(string.rep('-', 72))
end
-----------------------------------------------------------------------
-- os.path.normpath
-----------------------------------------------------------------------
print_title('os.path.normpath')
function assert_posix(path, result)
local x = os.path.normpath(path)
print('[test] normpath: ('..path..') -> (' .. result .. ')')
if x:gsub('\\', '/') ~= result then
print('failed: "' .. x .. '" != "'..result.. '"')
os.exit()
else
print('passed')
print()
end
end
function assert_windows(path, result)
local x = os.path.normpath(path)
print('[test] normpath: ('..path..') -> (' .. result .. ')')
if x ~= result then
print('failed: "' .. x .. '" != "'..result.. '"')
os.exit()
else
print('passed')
print()
end
end
assert_posix("", ".")
assert_posix("/", "/")
assert_posix("///", "/")
assert_posix("///foo/.//bar//", "/foo/bar")
assert_posix("///foo/.//bar//.//..//.//baz", "/foo/baz")
assert_posix("///..//./foo/.//bar", "/foo/bar")
if windows then
assert_windows('A//////././//.//B', 'A\\B')
assert_windows('A/./B', 'A\\B')
assert_windows('A/foo/../B', 'A\\B')
assert_windows('C:A//B', 'C:A\\B')
assert_windows('D:A/./B', 'D:A\\B')
assert_windows('e:A/foo/../B', 'e:A\\B')
assert_windows('C:///A//B', 'C:\\A\\B')
assert_windows('D:///A/./B', 'D:\\A\\B')
assert_windows('e:///A/foo/../B', 'e:\\A\\B')
assert_windows('..', '..')
assert_windows('.', '.')
assert_windows('', '.')
assert_windows('/', '\\')
assert_windows('c:/', 'c:\\')
assert_windows('/../.././..', '\\')
assert_windows('c:/../../..', 'c:\\')
assert_windows('../.././..', '..\\..\\..')
assert_windows('K:../.././..', 'K:..\\..\\..')
assert_windows('C:////a/b', 'C:\\a\\b')
end
print()
-----------------------------------------------------------------------
-- os.path.join
-----------------------------------------------------------------------
print_title('os.path.join')
function assert_join_posix(segments, result, isnt)
print('[test] join: '..zmod.dump(segments)..' -> (' .. result .. ')')
local path = ''
for _, item in ipairs(segments) do
path = os.path.join(path, item)
end
if windows and (not isnt) then
path = path:gsub('\\', '/')
end
if path ~= result then
print('failed: "' .. path .. '"')
os.exit()
else
print('passed')
end
end
function assert_join_windows(segments, result)
assert_join_posix(segments, result, 1)
end
assert_join_posix({"/foo", "bar", "/bar", "baz"}, "/bar/baz")
assert_join_posix({"/foo", "bar", "baz"}, "/foo/bar/baz")
assert_join_posix({"/foo/", "bar/", "baz/"}, "/foo/bar/baz/")
if windows then
assert_join_windows({""}, '')
assert_join_windows({"", "", ""}, '')
assert_join_windows({"a"}, 'a')
assert_join_windows({"/a"}, '/a')
assert_join_windows({"\\a"}, '\\a')
assert_join_windows({"a:"}, 'a:')
assert_join_windows({"a:", "\\b"}, 'a:\\b')
assert_join_windows({"a", "\\b"}, '\\b')
assert_join_windows({"a", "b", "c"}, 'a\\b\\c')
assert_join_windows({"a\\", "b", "c"}, 'a\\b\\c')
assert_join_windows({"a", "b\\", "c"}, 'a\\b\\c')
assert_join_windows({"a", "b", "\\c"}, '\\c')
assert_join_windows({"d:\\", "\\pleep"}, 'd:\\pleep')
assert_join_windows({"d:\\", "a", "b"}, 'd:\\a\\b')
assert_join_windows({'', 'a'}, 'a')
assert_join_windows({'', '', '', '', 'a'}, 'a')
assert_join_windows({'a', ''}, 'a\\')
assert_join_windows({'a', '', '', '', ''}, 'a\\')
assert_join_windows({'a\\', ''}, 'a\\')
assert_join_windows({'a\\', '', '', '', ''}, 'a\\')
assert_join_windows({'a/', ''}, 'a/')
assert_join_windows({'a/b', 'x/y'}, 'a/b\\x/y')
assert_join_windows({'/a/b', 'x/y'}, '/a/b\\x/y')
assert_join_windows({'/a/b/', 'x/y'}, '/a/b/x/y')
assert_join_windows({'c:', 'x/y'}, 'c:x/y')
assert_join_windows({'c:a/b', 'x/y'}, 'c:a/b\\x/y')
assert_join_windows({'c:a/b/', 'x/y'}, 'c:a/b/x/y')
assert_join_windows({'c:/', 'x/y'}, 'c:/x/y')
assert_join_windows({'c:/a/b', 'x/y'}, 'c:/a/b\\x/y')
assert_join_windows({'c:/a/b/', 'x/y'}, 'c:/a/b/x/y')
assert_join_windows({'a/b', '/x/y'}, '/x/y')
assert_join_windows({'/a/b', '/x/y'}, '/x/y')
assert_join_windows({'c:', '/x/y'}, 'c:/x/y')
assert_join_windows({'c:a/b', '/x/y'}, 'c:/x/y')
assert_join_windows({'c:/', '/x/y'}, 'c:/x/y')
assert_join_windows({'c:/a/b', '/x/y'}, 'c:/x/y')
assert_join_windows({'c:', 'C:x/y'}, 'C:x/y')
assert_join_windows({'c:a/b', 'C:x/y'}, 'C:a/b\\x/y')
assert_join_windows({'c:/', 'C:x/y'}, 'C:/x/y')
assert_join_windows({'c:/a/b', 'C:x/y'}, 'C:/a/b\\x/y')
for _, x in ipairs({'', 'a/b', '/a/b', 'c:', 'c:a/b', 'c:/', 'c:/a/b'}) do
for _, y in ipairs({'d:', 'd:x/y', 'd:/', 'd:/x/y'}) do
assert_join_windows({x, y}, y)
end
end
end
print()
-----------------------------------------------------------------------
-- os.path.split
-----------------------------------------------------------------------
print_title('os.path.split')
function assert_split(path, sep1, sep2)
print('[test] split: "' .. path ..'" -> ("' .. sep1 .. '", "' .. sep2 .. '")')
local x, y = os.path.split(path)
if x ~= sep1 or y ~= sep2 then
print('failed: ("'..x..'", "'..y..'")')
os.exit()
else
print('passed')
end
end
assert_split("", "", "")
assert_split(".", "", ".")
assert_split("/foo/bar", "/foo", "bar")
assert_split("/", "/", "")
assert_split("foo", "", "foo")
assert_split("////foo", "////", "foo")
assert_split("//foo//bar", "//foo", "bar")
if windows then
assert_split("c:\\foo\\bar", 'c:\\foo', 'bar')
assert_split("\\\\conky\\mountpoint\\foo\\bar", '\\\\conky\\mountpoint\\foo', 'bar')
assert_split("c:\\", "c:\\", '')
assert_split("c:/", "c:/", '')
assert_split("c:test", "c:", 'test')
assert_split("c:", "c:", '')
-- assert_split("\\\\conky\\mountpoint\\", "\\\\conky\\mountpoint\\", '')
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。