1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodePath from "node:path";
3import { describe, expect, it } from "vite-plus/test";
4
5import { expandHomePath } from "./pathExpansion.ts";
6
7const home = "/home/ada";
8
9describe("expandHomePath", () => {
10 it("returns an empty string unchanged", () => {
11 expect(expandHomePath("", home)).toBe("");
12 });
13
14 it("returns paths without a leading tilde unchanged", () => {
15 expect(expandHomePath("/absolute/path", home)).toBe("/absolute/path");
16 expect(expandHomePath("relative/path", home)).toBe("relative/path");
17 expect(expandHomePath("some~weird~path", home)).toBe("some~weird~path");
18 });
19
20 it("expands a lone tilde to the home directory", () => {
21 expect(expandHomePath("~", home)).toBe(home);
22 });
23
24 it("expands ~/ to a subpath of the home directory", () => {
25 expect(expandHomePath("~/.codex-work", home)).toBe(NodePath.join(home, ".codex-work"));
26 });
27
28 it("expands a Windows-style ~\\ prefix", () => {
29 expect(expandHomePath("~\\.codex", home)).toBe(NodePath.join(home, ".codex"));
30 });
31
32 it("does not expand ~user paths", () => {
33 expect(expandHomePath("~alice/foo", home)).toBe("~alice/foo");
34 });
35});