Files
t3code/apps/server/src/pathExpansion.test.ts

35 lines
1.2 KiB
TypeScript

// @effect-diagnostics nodeBuiltinImport:off
import * as NodeOS from "node:os";
import * as NodePath 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(NodeOS.homedir());
});
it("expands ~/ to a subpath of the home directory", () => {
expect(expandHomePath("~/.codex-work")).toBe(NodePath.join(NodeOS.homedir(), ".codex-work"));
});
it("expands a Windows-style ~\\ prefix", () => {
expect(expandHomePath("~\\.codex")).toBe(NodePath.join(NodeOS.homedir(), ".codex"));
});
it("does not expand ~user paths", () => {
expect(expandHomePath("~alice/foo")).toBe("~alice/foo");
});
});