Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/inspect/inspect-code-cells.test.ts
12921 views
1
/*
2
* inspect-code-cells.test.ts
3
*
4
* Copyright (C) 2020-2024 Posit Software, PBC
5
*
6
*/
7
8
import { assertObjectMatch } from "https://deno.land/[email protected]/assert/assert_object_match.ts";
9
import { existsSync } from "../../../src/deno_ral/fs.ts";
10
import { } from "../../../src/project/types.ts";
11
import {
12
ExecuteOutput,
13
testQuartoCmd,
14
} from "../../test.ts";
15
import { assert } from "testing/asserts";
16
17
(() => {
18
const input = "docs/project/book/_include.qmd";
19
const output = "docs/project/book/_include.json";
20
testQuartoCmd(
21
"inspect",
22
[input, output],
23
[
24
{
25
name: "inspect-code-cells",
26
verify: async (outputs: ExecuteOutput[]) => {
27
assert(existsSync(output));
28
const json = JSON.parse(Deno.readTextFileSync(output));
29
const info = json.fileInformation["docs/project/book/_include.qmd"];
30
const codeCells = info.codeCells;
31
assertObjectMatch(info.codeCells[0], {
32
start: 0,
33
end: 3,
34
source: "print(\"Hello, world\")\n",
35
language: "python",
36
metadata: {
37
"echo": true
38
}
39
});
40
}
41
}
42
],
43
{
44
teardown: async () => {
45
if (existsSync(output)) {
46
Deno.removeSync(output);
47
}
48
}
49
},
50
);
51
52
53
54
})();
55
56
(() => {
57
const input = "docs/inspect/10039.qmd";
58
const output = "docs/inspect/_10039.json";
59
testQuartoCmd(
60
"inspect",
61
[input, output],
62
[
63
{
64
name: "inspect-tagged-metadata",
65
verify: async (outputs: ExecuteOutput[]) => {
66
assert(existsSync(output));
67
const json = JSON.parse(Deno.readTextFileSync(output));
68
const info = json.fileInformation["docs/inspect/10039.qmd"];
69
const codeCells = info.codeCells;
70
assertObjectMatch(info.codeCells[1], {
71
"start": 14,
72
"end": 18,
73
"file": "docs/inspect/10039.qmd",
74
"source": "p[[1]]\n",
75
"language": "r",
76
"metadata": {
77
"label": "plot",
78
"fig-cap": {
79
"value": "names(p)[[1]]",
80
"tag": "!expr"
81
}
82
}
83
});
84
}
85
}
86
],
87
{
88
teardown: async () => {
89
if (existsSync(output)) {
90
Deno.removeSync(output);
91
}
92
}
93
},
94
);
95
})();
96