Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/break-quarto-md/break-quarto-md.test.ts
6456 views
1
/*
2
* break-quarto-md.test.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*
6
*/
7
8
import { breakQuartoMd } from "../../../src/core/lib/break-quarto-md.ts";
9
import { unitTest } from "../../test.ts";
10
import { assert } from "testing/asserts";
11
import { docs } from "../../utils.ts";
12
import { initYamlIntelligenceResourcesFromFilesystem } from "../../../src/core/schema/utils.ts";
13
import { lines } from "../../../src/core/lib/text.ts";
14
15
unitTest("break-quarto-md - empty code cells", async () => {
16
await initYamlIntelligenceResourcesFromFilesystem();
17
const qmd = Deno.readTextFileSync(
18
docs("break-quarto-md/github-issue-1034.qmd"),
19
);
20
21
const result = await breakQuartoMd(qmd);
22
assert(result.cells.length === 10);
23
});
24
25
unitTest("break-quarto-md - indented code cells", async () => {
26
await initYamlIntelligenceResourcesFromFilesystem();
27
const qmd = `---
28
title: Blah
29
---
30
31
Blah blah
32
33
\`\`\`{r}
34
1 + 1
35
\`\`\`
36
37
* The same in a list:
38
39
\`\`\`{r}
40
1 + 1
41
\`\`\`
42
43
* The same in a list again:
44
45
\`\`\`{r}
46
1 + 1
47
\`\`\`
48
`;
49
const cells = (await breakQuartoMd(qmd, false)).cells;
50
assert(cells.map((cell) => cell.sourceVerbatim.value).join("") === qmd);
51
});
52
53
unitTest("break-quarto-md - code", async () => {
54
await initYamlIntelligenceResourcesFromFilesystem();
55
const qmd = `---
56
title: mermaid test
57
format: html
58
---
59
60
## Some title
61
62
Some text
63
64
\`\`\`{mermaid}
65
graph TD;
66
A-->B;
67
A-->C;
68
B-->D;
69
C-->D;
70
\`\`\`
71
72
A cell that shouldn't be rendered by mermaid:
73
74
\`\`\`mermaid
75
Do not touch this, please.
76
\`\`\`
77
`;
78
79
const cells = (await breakQuartoMd(qmd, false)).cells;
80
assert(cells.length === 4);
81
assert(!cells[3].sourceVerbatim.value.startsWith("```"));
82
});
83
84
unitTest("break-quarto-md - nested code", async () => {
85
await initYamlIntelligenceResourcesFromFilesystem();
86
const qmd = `---
87
title: mermaid test
88
format: html
89
---
90
91
## Some title
92
93
Some text, and a markdown code chunk that shouldn't be split into a real code chunk.
94
95
\`\`\`\`{.markdown}
96
\`\`\`{mermaid}
97
graph TD;
98
A-->B;
99
A-->C;
100
B-->D;
101
C-->D;
102
\`\`\`
103
\`\`\`\`
104
105
Then some text.
106
`;
107
108
const cells = (await breakQuartoMd(qmd, false)).cells;
109
assert(cells.length === 2);
110
});
111
112
unitTest("break-quarto-md - hr cells", async () => {
113
await initYamlIntelligenceResourcesFromFilesystem();
114
const qmd = `---
115
title: "Untitled"
116
format: html
117
editor: visual
118
keep-md: true
119
---
120
121
122
Hello, an hr.
123
124
---
125
126
Hello, another thing.
127
128
---
129
130
And what about this?
131
`;
132
133
const cells = (await breakQuartoMd(qmd, false)).cells;
134
assert(cells.length <= 2 || cells[2].cell_type === "markdown");
135
});
136
137
unitTest("break-quarto-md - dot-joined language", async () => {
138
await initYamlIntelligenceResourcesFromFilesystem();
139
const qmd = `\`\`\`{python.marimo}
140
x = 1
141
\`\`\`
142
`;
143
const cells = (await breakQuartoMd(qmd, false)).cells;
144
// First cell should be the code cell with language "python.marimo"
145
assert(cells.length >= 1, "Should have at least one cell");
146
assert(typeof cells[0].cell_type === "object", "First cell should be a code cell");
147
assert(
148
(cells[0].cell_type as { language: string }).language === "python.marimo",
149
"Language should be 'python.marimo'",
150
);
151
});
152
153