silverbullet/plugs/index/item.test.ts

34 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2024-08-22 02:13:40 +08:00
import "../../plug-api/lib/syscall_mock.ts";
import { parseMarkdown } from "$common/markdown_parser/parser.ts";
import { extractItems } from "./item.ts";
import { assertEquals } from "@std/assert";
const itemsMd = `
* Item 1 #tag1 #tag2 [age: 100]
* Item 1.1 #tag3 #tag1
* Item 1.1.1
`;
Deno.test("Test item extraction", async () => {
2024-09-30 18:50:54 +08:00
const t = parseMarkdown(itemsMd);
const items = await extractItems("test", t);
2024-08-22 02:13:40 +08:00
2024-09-30 18:50:54 +08:00
assertEquals(items[0].name, "Item 1");
assertEquals(items[0].age, 100);
assertEquals(items[0].page, "test");
assertEquals(items[0].parent, undefined);
assertEquals(items[0].text, "Item 1 #tag1 #tag2 [age: 100]");
assertEquals(new Set(items[0].tags), new Set(["tag1", "tag2"]));
assertEquals(new Set(items[0].itags), new Set(["item", "tag1", "tag2"]));
2024-08-22 02:13:40 +08:00
2024-09-30 18:50:54 +08:00
assertEquals(items[1].name, "Item 1.1");
assertEquals(new Set(items[1].tags), new Set(["tag3", "tag1"]));
assertEquals(
new Set(items[1].itags),
new Set(["tag3", "tag2", "tag1", "item"]),
);
assertEquals(items[1].parent, items[0].ref);
2024-08-22 02:13:40 +08:00
2024-09-30 18:50:54 +08:00
assertEquals(items[2].parent, items[1].ref);
2024-08-22 02:13:40 +08:00
});