summaryrefslogtreecommitdiff
path: root/tests/modules/path/test.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-09 23:16:56 +0800
committerruki <[email protected]>2022-03-09 23:16:56 +0800
commit4eb65435961776fbefcc11ed774b778532c2c8dd (patch)
tree47f0dec0172dd20025c11b9ae66b6e381836ecbc /tests/modules/path/test.lua
parentf2030d90fa6363fb83fb03b38ff7d789ec2ea79a (diff)
add path test
Diffstat (limited to 'tests/modules/path/test.lua')
-rw-r--r--tests/modules/path/test.lua88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/modules/path/test.lua b/tests/modules/path/test.lua
index 80e87c5aa..7f0224b86 100644
--- a/tests/modules/path/test.lua
+++ b/tests/modules/path/test.lua
@@ -33,3 +33,91 @@ function test_extension(t)
t:are_equal(path.extension("/home/foo.so"), ".so")
t:are_equal(path.extension("\\home\\foo.so"), ".so")
end
+
+function test_directory(t)
+ --[[
+ t:are_equal(path.directory(""), nil)
+ t:are_equal(path.directory("."), nil)
+ if is_host("windows") then
+ t:are_equal(path.directory("c:"), nil)
+ t:are_equal(path.directory("c:\\"), nil)
+ t:are_equal(path.directory("c:\\xxx"), "c:")
+ t:are_equal(path.directory("c:\\xxx\\yyy"), "c:\\xxx")
+ else
+ t:are_equal(path.directory("/tmp"), "/")
+ t:are_equal(path.directory("/tmp/"), "/")
+ t:are_equal(path.directory("/tmp/xxx"), "/tmp")
+ t:are_equal(path.directory("/tmp/xxx/"), "/tmp")
+ t:are_equal(path.directory("/"), nil)
+ end]]
+end
+
+function test_absolute(t)
+ t:are_equal(path.absolute("", ""), nil)
+ t:are_equal(path.absolute(".", "."), ".")
+ if is_host("windows") then
+ t:are_equal(path.absolute("foo", "c:"), "c:\\foo")
+ t:are_equal(path.absolute("foo", "c:\\"), "c:\\foo")
+ t:are_equal(path.absolute("foo", "c:\\tmp"), "c:\\tmp\\foo")
+ t:are_equal(path.absolute("foo", "c:\\tmp\\"), "c:\\tmp\\foo")
+ else
+ t:are_equal(path.absolute("", "/"), nil)
+ t:are_equal(path.absolute("/", "/"), "/")
+ t:are_equal(path.absolute(".", "/"), "/")
+ t:are_equal(path.absolute("foo", "/tmp/"), "/tmp/foo")
+ t:are_equal(path.absolute("foo", "/tmp"), "/tmp/foo")
+ end
+end
+
+function test_relative(t)
+ t:are_equal(path.relative("", ""), nil)
+ t:are_equal(path.relative(".", "."), ".")
+ if is_host("windows") then
+ t:are_equal(path.relative("c:", "c:\\"), ".")
+ t:are_equal(path.relative("c:\\foo", "c:\\foo"), ".")
+ t:are_equal(path.relative("c:\\foo", "c:\\"), "foo")
+ t:are_equal(path.relative("c:\\tmp\\foo", "c:\\tmp"), "foo")
+ t:are_equal(path.relative("c:\\tmp\\foo", "c:\\tmp\\"), "foo")
+ else
+ t:are_equal(path.relative("", "/"), nil)
+ t:are_equal(path.relative("/", "/"), ".")
+ t:are_equal(path.relative("/tmp/foo", "/tmp/"), "foo")
+ t:are_equal(path.relative("/tmp/foo", "/tmp"), "foo")
+ end
+end
+
+function test_translate(t)
+ t:are_equal(path.translate(""), nil)
+ t:are_equal(path.translate("."), ".")
+ t:are_equal(path.translate(".."), "..")
+ t:are_equal(path.translate("././."), ".")
+ t:are_equal(path.translate("../foo/..", {reduce_dot2 = true}), "..")
+ t:are_equal(path.translate("../foo/bar/../..", {reduce_dot2 = true}), "..")
+ if is_host("windows") then
+ t:are_equal(path.translate("c:"), "c:")
+ t:are_equal(path.translate("c:\\"), "c:")
+ t:are_equal(path.translate("c:\\foo\\.\\.\\"), "c:\\foo")
+ t:are_equal(path.translate("c:\\foo\\\\\\"), "c:\\foo")
+ t:are_equal(path.translate("c:\\foo\\..\\.."), "c:\\foo\\..\\..")
+ t:are_equal(path.translate("c:\\foo\\bar\\.\\..\\xyz", {reduce_dot2 = true}), "c:\\foo\\xyz")
+ t:are_equal(path.translate("c:\\foo\\.\\..", {reduce_dot2 = true}), "c:")
+ t:are_equal(path.translate("../..", {reduce_dot2 = true}), "..\\..")
+ t:are_equal(path.translate("../foo/bar/..", {reduce_dot2 = true}), "..\\foo")
+ t:are_equal(path.translate("../foo/bar/../../..", {reduce_dot2 = true}), "..\\..")
+ else
+ t:are_equal(path.translate("/"), "/");
+ t:are_equal(path.translate("////"), "/");
+ t:are_equal(path.translate("/./././"), "/");
+ t:are_equal(path.translate("/foo/././"), "/foo");
+ t:are_equal(path.translate("/foo//////"), "/foo");
+ t:are_equal(path.translate("/foo/../.."), "/foo/../..");
+ t:are_equal(path.translate("/foo/../../"), "/foo/../..");
+ t:are_equal(path.translate("/foo/bar/.//..//xyz", {reduce_dot2 = true}), "/foo/xyz");
+ t:are_equal(path.translate("/foo/../..", {reduce_dot2 = true}), "/");
+ t:are_equal(path.translate("/foo/bar../..", {reduce_dot2 = true}), "/foo");
+ t:are_equal(path.translate("../..", {reduce_dot2 = true}), "../..");
+ t:are_equal(path.translate("../foo/bar/..", {reduce_dot2 = true}), "../foo");
+ t:are_equal(path.translate("../foo/bar/../../..", {reduce_dot2 = true}), "../..");
+ end
+end
+