|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { joinPath } from "./utils"; |
| 3 | + |
| 4 | +describe("joinPath", () => { |
| 5 | + it("joins relative path segments as an absolute normalized path", () => { |
| 6 | + expect(joinPath("path1", "path2")).toBe("/path1/path2"); |
| 7 | + }); |
| 8 | + |
| 9 | + it("does not create duplicate slashes when segments already contain slashes", () => { |
| 10 | + expect(joinPath("/path1", "/path2")).toBe("/path1/path2"); |
| 11 | + expect(joinPath("/path1/", "/path2/")).toBe("/path1/path2"); |
| 12 | + expect(joinPath("path1/", "path2/")).toBe("/path1/path2"); |
| 13 | + expect(joinPath("/path1/", "path2")).toBe("/path1/path2"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("keeps root-relative behavior when the first segment is empty", () => { |
| 17 | + expect(joinPath("", "file.txt")).toBe("/file.txt"); |
| 18 | + expect(joinPath("", "dir", "file.txt")).toBe("/dir/file.txt"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("handles root path segments", () => { |
| 22 | + expect(joinPath("/", "file.txt")).toBe("/file.txt"); |
| 23 | + expect(joinPath("/", "dir", "file.txt")).toBe("/dir/file.txt"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("skips empty path segments", () => { |
| 27 | + expect(joinPath("dir", "", "file.txt")).toBe("/dir/file.txt"); |
| 28 | + expect(joinPath("", "dir", "", "file.txt", "")).toBe("/dir/file.txt"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("returns empty string when no meaningful path is provided", () => { |
| 32 | + expect(joinPath()).toBe(""); |
| 33 | + expect(joinPath("")).toBe(""); |
| 34 | + expect(joinPath("", "")).toBe(""); |
| 35 | + expect(joinPath("/")).toBe(""); |
| 36 | + expect(joinPath("/", "")).toBe(""); |
| 37 | + }); |
| 38 | + |
| 39 | + it("normalizes multiple adjacent slashes inside segments", () => { |
| 40 | + expect(joinPath("//path1//", "//path2//")).toBe("/path1/path2"); |
| 41 | + expect(joinPath("path1//nested", "path2")).toBe("/path1/nested/path2"); |
| 42 | + }); |
| 43 | +}); |
0 commit comments