Path: blob/main/tests/unit/break-quarto-md/break-quarto-md.test.ts
6456 views
/*1* break-quarto-md.test.ts2*3* Copyright (C) 2022 Posit Software, PBC4*5*/67import { breakQuartoMd } from "../../../src/core/lib/break-quarto-md.ts";8import { unitTest } from "../../test.ts";9import { assert } from "testing/asserts";10import { docs } from "../../utils.ts";11import { initYamlIntelligenceResourcesFromFilesystem } from "../../../src/core/schema/utils.ts";12import { lines } from "../../../src/core/lib/text.ts";1314unitTest("break-quarto-md - empty code cells", async () => {15await initYamlIntelligenceResourcesFromFilesystem();16const qmd = Deno.readTextFileSync(17docs("break-quarto-md/github-issue-1034.qmd"),18);1920const result = await breakQuartoMd(qmd);21assert(result.cells.length === 10);22});2324unitTest("break-quarto-md - indented code cells", async () => {25await initYamlIntelligenceResourcesFromFilesystem();26const qmd = `---27title: Blah28---2930Blah blah3132\`\`\`{r}331 + 134\`\`\`3536* The same in a list:3738\`\`\`{r}391 + 140\`\`\`4142* The same in a list again:4344\`\`\`{r}451 + 146\`\`\`47`;48const cells = (await breakQuartoMd(qmd, false)).cells;49assert(cells.map((cell) => cell.sourceVerbatim.value).join("") === qmd);50});5152unitTest("break-quarto-md - code", async () => {53await initYamlIntelligenceResourcesFromFilesystem();54const qmd = `---55title: mermaid test56format: html57---5859## Some title6061Some text6263\`\`\`{mermaid}64graph TD;65A-->B;66A-->C;67B-->D;68C-->D;69\`\`\`7071A cell that shouldn't be rendered by mermaid:7273\`\`\`mermaid74Do not touch this, please.75\`\`\`76`;7778const cells = (await breakQuartoMd(qmd, false)).cells;79assert(cells.length === 4);80assert(!cells[3].sourceVerbatim.value.startsWith("```"));81});8283unitTest("break-quarto-md - nested code", async () => {84await initYamlIntelligenceResourcesFromFilesystem();85const qmd = `---86title: mermaid test87format: html88---8990## Some title9192Some text, and a markdown code chunk that shouldn't be split into a real code chunk.9394\`\`\`\`{.markdown}95\`\`\`{mermaid}96graph TD;97A-->B;98A-->C;99B-->D;100C-->D;101\`\`\`102\`\`\`\`103104Then some text.105`;106107const cells = (await breakQuartoMd(qmd, false)).cells;108assert(cells.length === 2);109});110111unitTest("break-quarto-md - hr cells", async () => {112await initYamlIntelligenceResourcesFromFilesystem();113const qmd = `---114title: "Untitled"115format: html116editor: visual117keep-md: true118---119120121Hello, an hr.122123---124125Hello, another thing.126127---128129And what about this?130`;131132const cells = (await breakQuartoMd(qmd, false)).cells;133assert(cells.length <= 2 || cells[2].cell_type === "markdown");134});135136unitTest("break-quarto-md - dot-joined language", async () => {137await initYamlIntelligenceResourcesFromFilesystem();138const qmd = `\`\`\`{python.marimo}139x = 1140\`\`\`141`;142const cells = (await breakQuartoMd(qmd, false)).cells;143// First cell should be the code cell with language "python.marimo"144assert(cells.length >= 1, "Should have at least one cell");145assert(typeof cells[0].cell_type === "object", "First cell should be a code cell");146assert(147(cells[0].cell_type as { language: string }).language === "python.marimo",148"Language should be 'python.marimo'",149);150});151152153