Ori BernsteinRemove std.sleq2a3d4ab8 years agoHistory
62 lines · 1.3 KB · Text
RawDownload
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("./", ".")	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.eq(p, b)		std.fatal("mismatched paths: '{}' => '{}' != '{}'\n", a, p, b)	;;	std.slfree(p)} const eq = {a, b	if !std.eq(a, b)		std.fatal("mismatched paths: '{}' != '{}'\n", a, b)	;;}