import { describe, expect, it } from "vitest"; import { longestCommonPrefix, parentDir, splitPath } from "./paths.js"; describe("splitPath", () => { it("splits on the last slash, keeping it with the directory", () => { expect(splitPath("/home/n/wo")).toEqual({ dir: "/home/n/", prefix: "wo" }); expect(splitPath("/home/n/")).toEqual({ dir: "/home/n/", prefix: "" }); }); it("treats a slash-free value as all prefix", () => { expect(splitPath("work")).toEqual({ dir: "", prefix: "work" }); expect(splitPath("")).toEqual({ dir: "", prefix: "" }); }); }); describe("longestCommonPrefix", () => { it("returns the shared head", () => { expect(longestCommonPrefix(["maestro", "maestro-web"])).toBe("maestro"); expect(longestCommonPrefix(["abc"])).toBe("abc"); }); it("is empty when nothing is shared", () => { expect(longestCommonPrefix(["abc", "xyz"])).toBe(""); expect(longestCommonPrefix([])).toBe(""); }); it("preserves on-disk casing rather than folding it", () => { expect(longestCommonPrefix(["Alpha", "alpha"])).toBe(""); }); }); describe("parentDir", () => { it("drops the last segment", () => { expect(parentDir("/home/user/tea/maestro")).toBe("/home/user/tea"); expect(parentDir("/home/user/tea/maestro/")).toBe("/home/user/tea"); }); it("keeps the root for a top-level path", () => { expect(parentDir("/maestro")).toBe("/"); expect(parentDir("/")).toBe("/"); }); it("is empty for a bare name", () => { expect(parentDir("maestro")).toBe(""); }); });