resolvePath function implemented and tested, all green.

This commit is contained in:
2026-07-26 16:43:39 +02:00
parent 994b93ae47
commit cd08a4bf32
8 changed files with 302 additions and 7 deletions
+63
View File
@@ -0,0 +1,63 @@
import { resolvePath } from "@core/path_resolver";
import { expectNodeNotFoundError, expectNotADirectoryError } from "@tests/helpers/error_matchers";
import { buildTestFS } from "@tests/helpers/filesystems_fixture";
import { depth7Tree } from "@tests/helpers/tree_fixture";
import { describe, expect, test } from "vitest";
const fs = buildTestFS(depth7Tree);
describe("resolvePath", () => {
test("returns an inode from an absolute path", () => {
const path = "/d1/d2/d3/d4/";
const result = resolvePath(fs, 1, path);
expect(result).toBeDefined();
expect(fs.getNode(result as number)!.name).toBe("d4");
});
test("returns an inode from a relative path", () => {
const path = "./d2/d3/d4/";
const result = resolvePath(fs, 1, path);
expect(result).toBeDefined();
expect(fs.getNode(result as number)!.name).toBe("d4");
});
test("returns an inode from a relative parent path", () => {
const path = "../d1/d2/d3/d4/";
const result = resolvePath(fs, 1, path);
expect(result).toBeDefined();
expect(fs.getNode(result as number)!.name).toBe("d4");
});
test("returns inode 0", () => {
const path = "/";
const result = resolvePath(fs, 1, path);
expect(result).toBeDefined();
expect(result).toBe(0);
expect(fs.getNode(result as number)!.name).toBe("root");
});
test("returns inode 1 (cwd)", () => {
const path = "";
const result = resolvePath(fs, 1, path);
expect(result).toBeDefined();
expect(result).toBe(1);
expect(fs.getNode(result as number)!.name).toBe("d1");
});
test("throws because of a nonexistent path", () => {
expectNodeNotFoundError(() => resolvePath(fs, 1, "/d3"));
});
test("throws because of file path component", () => {
expectNotADirectoryError(() => resolvePath(fs, 6, "./deep_file.txt/d8"));
});
test("throws because of a nonexistent cwd inode (technicaly should never happen)", () => {
expectNodeNotFoundError(() => resolvePath(fs, 69, "/d3"));
});
});