resolvePath function implemented and tested, all green.
This commit is contained in:
@@ -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"));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user