1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
function test_splitenv_win(t)
if not is_host("windows") then
return t:skip("wrong host platform")
end
t:are_equal(path.splitenv(""), {})
t:are_equal(path.splitenv("a"), {'a'})
t:are_equal(path.splitenv("a;b"), {'a','b'})
t:are_equal(path.splitenv(";;a;;b;"), {'a','b'})
t:are_equal(path.splitenv('c:/a;c:\\b'), {'c:/a', 'c:\\b'})
t:are_equal(path.splitenv('"a;aa;aa;;"'), {"a;aa;aa;;"})
t:are_equal(path.splitenv('"a;aa;aa;;";bb;;'), {"a;aa;aa;;", 'bb'})
t:are_equal(path.splitenv('"a;aa;aa;;";"a;cc;aa;;";bb;"d";'), {"a;aa;aa;;","a;cc;aa;;", 'bb', 'd' })
end
function test_splitenv_unix(t)
if is_host("windows") then
return t:skip("wrong host platform")
end
t:are_equal(path.splitenv(""), {})
t:are_equal(path.splitenv("a"), {'a'})
t:are_equal(path.splitenv("a:b"), {'a','b'})
t:are_equal(path.splitenv("::a::b:"), {'a','b'})
t:are_equal(path.splitenv('a%tag:b'), {'a','b'})
t:are_equal(path.splitenv('a%tag:b%tag'), {'a','b'})
t:are_equal(path.splitenv('a%tag:b%%tag%%'), {'a','b'})
t:are_equal(path.splitenv('a%tag:b:%tag:'), {'a','b'})
end
function test_extension(t)
t:are_equal(path.extension("1.1/abc"), "")
t:are_equal(path.extension("1.1\\abc"), "")
t:are_equal(path.extension("foo.so"), ".so")
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)
t:are_equal(path.directory("foo"), ".")
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
|