Files
plainleaf/plug-api/lib/attribute.test.ts
T
MaksandGitHub 8a3782e946 improve dependency management (#770)
* use import_map.json instead of per-file import

* remove test_deps.ts in favor of import_map

* remove common/deps.ts in favor of import_map

* use import_map instead of server/deps.ts

* make all plug-api files usable without an import_map

* make all lib files usable without an import_map

* remove web/deps.ts in favor of import_map

* fix plug build

* remove plug-api/deps.ts in favor of lib/deps.ts

* fix server deps bundled in client deps
2024-03-16 15:29:24 +01:00

41 lines
1.4 KiB
TypeScript

import "$sb/lib/syscall_mock.ts";
import { parse } from "$common/markdown_parser/parse_tree.ts";
import { extractAttributes } from "$sb/lib/attribute.ts";
import { assertEquals } from "$std/testing/asserts.ts";
import { renderToText } from "./tree.ts";
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
const inlineAttributeSample = `
# My document
Top level attributes: [name:: sup] [age:: 42] [children: [pete, "john", mary]]
* [ ] Attribute in a task [tag:: foo]
* Regular item [tag:: bar]
1. Itemized list [tag:: baz]
`;
const cleanedInlineAttributeSample = `
# My document
Top level attributes:
* [ ] Attribute in a task [tag:: foo]
* Regular item [tag:: bar]
1. Itemized list [tag:: baz]
`;
Deno.test("Test attribute extraction", async () => {
const tree = parse(extendedMarkdownLanguage, inlineAttributeSample);
const toplevelAttributes = await extractAttributes(["test"], tree, false);
// console.log("All attributes", toplevelAttributes);
assertEquals(toplevelAttributes.name, "sup");
assertEquals(toplevelAttributes.age, 42);
assertEquals(toplevelAttributes.children, ["pete", "john", "mary"]);
// Check if the attributes are still there
assertEquals(renderToText(tree), inlineAttributeSample);
// Now once again with cleaning
await extractAttributes(["test"], tree, true);
assertEquals(renderToText(tree), cleanedInlineAttributeSample);
});