shithub: mc

ref: b65a821ba2d8c753e974b02e541229dfd6754a6a
dir: /test/stdpathnorm.myr/

View raw version
use std

const main = {
	/* untouched */
	std.put("%s\n", std.pathnorm(""))
	std.put("%s\n", std.pathnorm("foo"))
	std.put("%s\n", std.pathnorm("foo/bar"))
	std.put("%s\n", std.pathnorm("/foo/bar"))
	std.put("%s\n", std.pathnorm("."))

	/* empty path becomes "." */
	std.put("%s\n", std.pathnorm("."))

	/* delete //, trailing / */
	std.put("%s\n", std.pathnorm("foo/"))
	std.put("%s\n", std.pathnorm("foo//bar/baz"))
	std.put("%s\n", std.pathnorm("//foo//bar/"))

	/* delete '.' */
	std.put("%s\n", std.pathnorm("foo/./bar"))
	std.put("%s\n", std.pathnorm("/foo/bar/."))
	std.put("%s\n", std.pathnorm("./foo/bar/."))

	/* elide '..' */
	std.put("%s\n", std.pathnorm("/../foo/bar"))
	std.put("%s\n", std.pathnorm("../../foo/bar"))
	std.put("%s\n", std.pathnorm("foo/bar/.."))
	std.put("%s\n", std.pathnorm("foo/bar/../.."))
	std.put("%s\n", std.pathnorm("foo/../bar/../.."))
	std.put("%s\n", std.pathnorm("/foo/../bar/../.."))

	/* mix all of the above */
	std.put("%s\n", std.pathnorm("/../foo//bar"))
	std.put("%s\n", std.pathnorm("..//../foo/bar"))
	std.put("%s\n", std.pathnorm("foo//./bar/.."))
	std.put("%s\n", std.pathnorm("foo/bar/.././.."))
	std.put("%s\n", std.pathnorm("//foo/../bar/../.."))
	std.put("%s\n", std.pathnorm("foo/../bar/../.."))

	/* vanilla pathjoin */
	std.put("%s\n", std.pathcat("a", "b"))
	std.put("%s\n", std.pathjoin(["a", "b", "c"][:]))
	/* pathjoin with empty dirs */
	std.put("%s\n", std.pathcat("", "foo"))
	std.put("%s\n", std.pathjoin(["", "foo", "bar"][:]))
}