-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
73 lines (52 loc) · 1.47 KB
/
index.test.js
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
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkMusic from ".";
describe("remark music", () => {
it("does not affect normal markdown", async () => {
const markdown = `
# Heading
Paragraph.
`;
const parsed = await unified().use(remarkParse).parse(markdown);
const result = await unified().use(remarkMusic).run(parsed);
expect(result).toStrictEqual(parsed);
});
it("does not affect code blocks", async () => {
const markdown = `
# Python code
\`\`\`python
print("Hello, world!")
\`\`\`
Code in a different language
\`\`\`
(print "Hello, world!")
\`\`\`
`;
const parsed = await unified().use(remarkParse).parse(markdown);
const result = await unified().use(remarkMusic).run(parsed);
expect(result).toStrictEqual(parsed);
});
it("replaces `abc` code blocks with `abc` nodes", async () => {
const markdown = `
# ABC code
\`\`\`abc
X:1
T:My Song
M:4/4
L:1/8
K:C
\`\`\`
Code in a different language
\`\`\`
(print "Hello, world!")
\`\`\`
`;
const parsed = await unified().use(remarkParse).parse(markdown);
const result = await unified().use(remarkMusic).run(parsed);
expect(result).not.toStrictEqual(parsed);
expect(result.children.map((node) => node.type)).toContainEqual("abc");
const abcNode = result.children.find((node) => node.type === "abc");
expect(abcNode.value).toBe("X:1\nT:My Song\nM:4/4\nL:1/8\nK:C");
expect(abcNode.data).toHaveProperty("hName", "div");
});
});