From 205f1d2ae8281955b22b868eb16741a86e44da58 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 10 Mar 2022 00:57:05 +0800 Subject: add path.normalize --- tests/modules/path/test.lua | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'tests/modules/path/test.lua') diff --git a/tests/modules/path/test.lua b/tests/modules/path/test.lua index 3df399b65..2d4b09238 100644 --- a/tests/modules/path/test.lua +++ b/tests/modules/path/test.lua @@ -90,34 +90,40 @@ 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("././.", {normalize = true}), ".") - t:are_equal(path.translate("../foo/..", {normalize = true}), "..") - t:are_equal(path.translate("../foo/bar/../..", {normalize = 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\\.\\.\\", {normalize = true}), "c:\\foo") - t:are_equal(path.translate("c:\\foo\\bar\\.\\..\\xyz", {normalize = true}), "c:\\foo\\xyz") - t:are_equal(path.translate("c:\\foo\\.\\..", {normalize = true}), "c:") - t:are_equal(path.translate("../..", {normalize = true}), "..\\..") - t:are_equal(path.translate("../foo/bar/..", {normalize = true}), "..\\foo") - t:are_equal(path.translate("../foo/bar/../../..", {normalize = true}), "..\\..") else 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/././", {normalize = true}), "/foo"); - t:are_equal(path.translate("/./././", {normalize = true}), "/"); - t:are_equal(path.translate("/foo/bar/.//..//xyz", {normalize = true}), "/foo/xyz"); - t:are_equal(path.translate("/foo/../..", {normalize = true}), "/"); - t:are_equal(path.translate("/foo/bar../..", {normalize = true}), "/foo"); - t:are_equal(path.translate("../..", {normalize = true}), "../.."); - t:are_equal(path.translate("../foo/bar/..", {normalize = true}), "../foo"); - t:are_equal(path.translate("../foo/bar/../../..", {normalize = true}), "../.."); + end +end + +function test_normalize(t) + t:are_equal(path.normalize("././."), ".") + t:are_equal(path.normalize("../foo/.."), "..") + t:are_equal(path.normalize("../foo/bar/../.."), "..") + if is_host("windows") then + t:are_equal(path.normalize("c:\\foo\\.\\.\\"), "c:\\foo") + t:are_equal(path.normalize("c:\\foo\\bar\\.\\..\\xyz"), "c:\\foo\\xyz") + t:are_equal(path.normalize("c:\\foo\\.\\.."), "c:") + t:are_equal(path.normalize("../.."), "..\\..") + t:are_equal(path.normalize("../foo/bar/.."), "..\\foo") + t:are_equal(path.normalize("../foo/bar/../../.."), "..\\..") + else + t:are_equal(path.normalize("/foo/././"), "/foo"); + t:are_equal(path.normalize("/./././"), "/"); + t:are_equal(path.normalize("/foo/bar/.//..//xyz"), "/foo/xyz"); + t:are_equal(path.normalize("/foo/../.."), "/"); + t:are_equal(path.normalize("/foo/bar../.."), "/foo"); + t:are_equal(path.normalize("../.."), "../.."); + t:are_equal(path.normalize("../foo/bar/.."), "../foo"); + t:are_equal(path.normalize("../foo/bar/../../.."), "../.."); end end -- cgit v1.3.1