Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pathExpansion.test.ts

34 lines1.2 KB

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