import { assertEquals } from "jsr:@std/assert"
// aliasing our functions for brevity
const eq = assertEquals, fn = joinPosixPaths
eq(fn("a", "b", "c.zip"), "a/b/c.zip")
eq(fn("a", "b", "c/"), "a/b/c/")
eq(fn("a/", "b/", "c/"), "a/b/c/")
eq(fn("a", "b", "c.zip", "./"), "a/b/")
eq(fn("a", "b", "c/", "./"), "a/b/c/")
eq(fn("a", "b", "c", "../"), "a/")
eq(fn("a", "b", "c/d.txt", "./e.txt"), "a/b/c/e.txt")
eq(fn("a", "b", "c/d.txt", "../e.txt"), "a/b/e.txt")
eq(fn("a/b", "c/d.txt", "..", "e.txt"), "a/b/e.txt") // notice that you can use "." instead of "./"
eq(fn("a/", "b/", "c/", "../", "./","d.txt"), "a/b/d.txt")
eq(fn("a/b", "c/", "..", ".","d.txt"), "a/b/d.txt") // notice that you can use ".." instead of "../"
eq(fn("a/b", "c/", ".d.txt"), "a/b/c/.d.txt")
eq(fn("a/b", "c/", "..d.txt"), "a/b/c/..d.txt")
eq(fn("a/b", "c/", ".d"), "a/b/c/.d")
eq(fn("a/b", "c/", ".d."), "a/b/c/.d.")
eq(fn("a/b", "c/", "..d"), "a/b/c/..d")
eq(fn("a/b", "c/", "..d."), "a/b/c/..d.")
eq(fn("a/b", "c/", "..d.."), "a/b/c/..d..")
eq(fn("a/b", "c/", "..d.", "e.txt"), "a/b/c/..d./e.txt")
eq(fn("a/b", "c/", "..d..", "e.txt"), "a/b/c/..d../e.txt")
eq(fn("./a", "./b", "./c"), "./c")
eq(fn("./a", "/b", "/c"), "./a//b//c")
eq(fn("./a/", "/b/", "/c"), "./a//b//c")
eq(fn("/a", "b.zip", "./c.zip"), "/a/c.zip")
eq(fn("/a", "b.zip", "./c.zip/", "../d.txt"), "/a/d.txt")
eq(fn("/a", "b.zip/", "./c.txt"), "/a/b.zip/c.txt")
eq(fn("/a", "b.zip/", "./c.txt/", "../d.txt"), "/a/b.zip/d.txt")
eq(fn("file:", "//", "a/b/c", "./d"), "file:///a/b/d")
eq(fn("file:///", "a/b/c", "./d"), "file:///a/b/d")
joins multiple posix path segments into a single normalized path, correctly handling files and directories differently when the
"./"
and"../"
navigation commands are encountered.the
joinPosixPaths
function differs fromjoinSlash
in that it treats segments without a trailing slash as files by default. furthermore,joinPosixPaths
is much more quicker to compute, as opposed tojoinSlash
, which uses some complex regex on each segment. the only reason you might realistically want to usejoinSlash
is when you desire an non-normalized output.