path-format.test.ts 925 B

1234567891011121314151617
  1. import { expect, test } from "bun:test"
  2. import { formatPath } from "../../src/util/path-format"
  3. test("formats relative, home, and foreign paths", () => {
  4. expect(formatPath(".", { base: "/work/project" })).toBe(".")
  5. expect(formatPath("../shared/a.ts", { base: "/work/project" })).toBe("/work/shared/a.ts")
  6. expect(formatPath("/home/test/project", { base: "/work", home: "/home/test" })).toBe("~/project")
  7. expect(formatPath("src\\a.ts", { base: "/work", forwardSlashes: true })).toBe("src/a.ts")
  8. expect(formatPath("C:/", { base: "/work" })).toBe("C:/")
  9. expect(formatPath("C:\\Users\\tester", { base: "/work", forwardSlashes: true })).toBe("C:/Users/tester")
  10. expect(formatPath("..\\shared\\a.ts", { base: "C:\\work\\project", forwardSlashes: true })).toBe(
  11. "C:/work/shared/a.ts",
  12. )
  13. expect(
  14. formatPath("C:\\Users\\test\\project", { base: "C:\\work", home: "C:\\Users\\test" }),
  15. ).toBe("~/project")
  16. })