-
Notifications
You must be signed in to change notification settings - Fork 437
Expand file tree
/
Copy pathinspect-code-cells.test.ts
More file actions
96 lines (90 loc) · 2.41 KB
/
inspect-code-cells.test.ts
File metadata and controls
96 lines (90 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* inspect-code-cells.test.ts
*
* Copyright (C) 2020-2024 Posit Software, PBC
*
*/
import { assertObjectMatch } from "https://deno.land/std@0.93.0/assert/assert_object_match.ts";
import { existsSync } from "../../../src/deno_ral/fs.ts";
import { } from "../../../src/project/types.ts";
import {
ExecuteOutput,
testQuartoCmd,
} from "../../test.ts";
import { assert } from "testing/asserts";
import { normalizePath } from "../../../src/core/path.ts";
(() => {
const input = "docs/project/book/_include.qmd";
const output = "docs/project/book/_include.json";
testQuartoCmd(
"inspect",
[input, output],
[
{
name: "inspect-code-cells",
verify: async (outputs: ExecuteOutput[]) => {
assert(existsSync(output));
const json = JSON.parse(Deno.readTextFileSync(output));
const info = json.fileInformation[normalizePath("docs/project/book/_include.qmd")];
const codeCells = info.codeCells;
assertObjectMatch(info.codeCells[0], {
start: 0,
end: 3,
source: "print(\"Hello, world\")\n",
language: "python",
metadata: {
"echo": true
}
});
}
}
],
{
teardown: async () => {
if (existsSync(output)) {
Deno.removeSync(output);
}
}
},
);
})();
(() => {
const input = "docs/inspect/10039.qmd";
const output = "docs/inspect/_10039.json";
testQuartoCmd(
"inspect",
[input, output],
[
{
name: "inspect-tagged-metadata",
verify: async (outputs: ExecuteOutput[]) => {
assert(existsSync(output));
const json = JSON.parse(Deno.readTextFileSync(output));
const info = json.fileInformation[normalizePath("docs/inspect/10039.qmd")];
const codeCells = info.codeCells;
assertObjectMatch(info.codeCells[1], {
"start": 14,
"end": 18,
"file": normalizePath("docs/inspect/10039.qmd"),
"source": "p[[1]]\n",
"language": "r",
"metadata": {
"label": "plot",
"fig-cap": {
"value": "names(p)[[1]]",
"tag": "!expr"
}
}
});
}
}
],
{
teardown: async () => {
if (existsSync(output)) {
Deno.removeSync(output);
}
}
},
);
})();