Path: blob/main/tests/unit/pandoc-partition.test.ts
6448 views
/*1* pandoc-partition.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/6import { assert } from "testing/asserts";7import { Metadata } from "../../src/config/types.ts";8import { languagesWithClasses, partitionMarkdown } from "../../src/core/pandoc/pandoc-partition.ts";9import { unitTest } from "../test.ts";1011// deno-lint-ignore require-await12unitTest("partitionYaml", async () => {13const frontMatter = "---\ntitle: foo\n---";14const headingText = "## Hello World {#cool .foobar foo=bar}";15const markdown = "\n\nThis is a paragraph\n\n:::{#refs}\n:::\n";1617const markdownstr = `${frontMatter}\n${headingText}${markdown}`;18const partmd = partitionMarkdown(markdownstr);1920const metadataMatches = (yaml?: Metadata) => {21if (yaml) {22return yaml.title === "foo" && Object.keys(yaml).length === 1;23} else {24return false;25}26};2728// Tests of the result29assert(partmd.containsRefs, "Refs Div not found");30assert(partmd.markdown === markdown, "Partitioned markdown doesn't match");31assert(32metadataMatches(partmd.yaml),33"Partitioned front matter doesn't match",34);35assert(36partmd.headingText === "Hello World",37"Heading text not parsed properly",38);39assert(40partmd.headingAttr?.id === "cool",41"Heading missing id",42);43assert(44partmd.headingAttr?.classes.includes("foobar"),45"Heading missing class",46);47assert(48partmd.headingAttr?.keyvalue[0][0] === "foo",49"Heading missing attribute key",50);51assert(52partmd.headingAttr?.keyvalue[0][1] === "bar",53"Heading missing attribute value",54);55});5657// deno-lint-ignore require-await58unitTest("languagesWithClasses - dot-joined syntax", async () => {59const md = `\`\`\`{python.marimo}60x = 161\`\`\`6263\`\`\`{python .foo}64y = 265\`\`\`66`;67const result = languagesWithClasses(md);68// {python.marimo} → language "python.marimo", no class69assert(result.has("python.marimo"), "Should have language 'python.marimo'");70assert(result.get("python.marimo") === undefined, "python.marimo should have no class");71// {python .foo} → language "python", class "foo"72assert(result.has("python"), "Should have language 'python'");73assert(result.get("python") === "foo", "python should have class 'foo'");74});757677