import { describe, it, expect } from "vitest"; import { extractFrontmatterId } from "../../parser/parseFrontmatter"; describe("extractFrontmatterId", () => { it("extracts id from frontmatter", () => { const md = `--- id: test-id title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("test-id"); }); it("returns null when no frontmatter", () => { const md = `Content without frontmatter.`; expect(extractFrontmatterId(md)).toBe(null); }); it("returns null when no id field", () => { const md = `--- title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe(null); }); it("converts numeric id to string", () => { const md = `--- id: 123 title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("123"); }); it("handles quoted id", () => { const md = `--- id: "quoted-id" title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("quoted-id"); }); it("handles single-quoted id", () => { const md = `--- id: 'single-quoted' title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("single-quoted"); }); it("handles id with colon in value", () => { const md = `--- id: "id:with:colons" title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("id:with:colons"); }); it("returns null when frontmatter not closed", () => { const md = `--- id: test-id title: Test Content here. `; expect(extractFrontmatterId(md)).toBe(null); }); it("handles id without space after colon", () => { const md = `--- id:test-id title: Test --- Content here. `; expect(extractFrontmatterId(md)).toBe("test-id"); }); });