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
|
use std
const main = {
/* untouched */
norm("foo", "foo")
norm("foo/bar", "foo/bar")
norm("/foo/bar", "/foo/bar")
norm(".", ".")
/* empty path becomes "." */
norm("", ".")
/* delete //, trailing / */
norm("foo/", "foo")
norm("foo//bar/baz", "foo/bar/baz")
norm("//foo//bar/", "/foo/bar")
/* delete '.' */
norm("foo/./bar", "foo/bar")
norm("/foo/bar/.", "/foo/bar")
norm("./foo/bar/.", "foo/bar")
/* elide '..' */
norm("/../foo/bar", "/foo/bar")
norm("../../foo/bar", "../../foo/bar")
norm("foo/bar/..", "foo")
norm("foo/bar/../..", ".")
norm("foo/../bar/../..", "..")
norm("/foo/../bar/../..", "/")
/* mix all of the above */
norm("/../foo//bar", "/foo/bar")
norm("..//../foo/bar", "../../foo/bar")
norm("foo//./bar/..", "foo")
norm("foo/bar/.././..", ".")
norm("//foo/../bar/../..", "/")
norm("foo/../bar/../..", "..")
/* vanilla pathjoin */
eq(std.pathcat("a", "b"), "a/b")
eq(std.pathjoin(["a", "b", "c"][:]), "a/b/c")
/* pathjoin with empty dirs */
eq(std.pathcat("", "foo"), "foo")
eq(std.pathjoin(["", "foo", "bar"][:]), "foo/bar")
}
const norm = {a, b
var p
p = std.pathnorm(a)
if !std.sleq(p, b)
std.fatal("mismatched paths: '{}' => '{}' != '{}'\n", a, p, b)
;;
std.slfree(p)
}
const eq = {a, b
if !std.sleq(a, b)
std.fatal("mismatched paths: '{}' != '{}'\n", a, b)
;;
}
|