Files
t3code/apps/server/src/pathExpansion.test.ts
T
2026-06-03 16:16:53 -07:00

35 lines
1.1 KiB
TypeScript

// @effect-diagnostics nodeBuiltinImport:off
import { homedir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vite-plus/test";
import { expandHomePath } from "./pathExpansion.ts";
describe("expandHomePath", () => {
it("returns an empty string unchanged", () => {
expect(expandHomePath("")).toBe("");
});
it("returns paths without a leading tilde unchanged", () => {
expect(expandHomePath("/absolute/path")).toBe("/absolute/path");
expect(expandHomePath("relative/path")).toBe("relative/path");
expect(expandHomePath("some~weird~path")).toBe("some~weird~path");
});
it("expands a lone tilde to the home directory", () => {
expect(expandHomePath("~")).toBe(homedir());
});
it("expands ~/ to a subpath of the home directory", () => {
expect(expandHomePath("~/.codex-work")).toBe(join(homedir(), ".codex-work"));
});
it("expands a Windows-style ~\\ prefix", () => {
expect(expandHomePath("~\\.codex")).toBe(join(homedir(), ".codex"));
});
it("does not expand ~user paths", () => {
expect(expandHomePath("~alice/foo")).toBe("~alice/foo");
});
});