-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrender.test.ts
127 lines (124 loc) · 3.53 KB
/
render.test.ts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { expect, it, describe } from "vitest";
import { md } from "../src";
const renderTests = {
bold: [["Hello, World!", "**Hello, World!**"]],
blockquote: [["Hello, World!", "> Hello, World!"]],
boldAndItalic: [["Hello, World!", "***Hello, World!***"]],
codeBlock: [
[
'console.log("Hello, World!");',
'```\nconsole.log("Hello, World!");\n```',
],
[
'console.log("Hello, World!");',
"js",
{ ext: '[name="index.js"]' },
'```js [name="index.js"]\nconsole.log("Hello, World!");\n```',
],
[
'console.log("Hello, World!");',
"js",
'```js\nconsole.log("Hello, World!");\n```',
],
],
strikethrough: [["Hello, World!", "~~Hello, World!~~"]],
italic: [["Hello, World!", "_Hello, World!_"]],
hr: [["---"], [5, "-----"]],
image: [
// Basic
[
"https://cataas.com/cat",
"Cute Cat",
"![Cute Cat](https://cataas.com/cat)",
],
// With title
[
"https://cataas.com/cat",
"Cute Cat",
{ title: "title" },
'![Cute Cat](https://cataas.com/cat "title")',
],
// No text
["https://cataas.com/cat", "![](https://cataas.com/cat)"],
// No url
["", "Cute Cat", "![Cute Cat](#)"],
["", "", "![](#)"],
],
heading: [
["Hello, World!", "\n# Hello, World!\n"],
["Hello, World!", 1, "\n# Hello, World!\n"],
["Hello, World!", 3, "\n### Hello, World!\n"],
],
link: [
// Basic
[
"https://www.example.com",
"Example",
"[Example](https://www.example.com)",
],
// External
[
"https://www.example.com",
"Example",
{ external: true, title: "title" },
'<a href="https://www.example.com" title="title" target="_blank">Example</a>',
],
// With title
[
"https://www.example.com",
"Example",
{ title: "title" },
'[Example](https://www.example.com "title")',
],
// No text
["http://example.com", "[http://example.com](http://example.com)"],
// No link
["", "Title", "[Title](#)"],
["", "", "[](#)"],
// Relative path
["./src/markdown.md", "Markdown", "[Markdown](./src/markdown.md)"],
// URL
[
new URL("https://www.example.com/"),
"Example",
"[Example](https://www.example.com/)",
],
],
list: [
[["Item 1", "Item 2"], "- Item 1\n- Item 2"],
[["Item 1", "Item 2"], { ordered: true }, "1. Item 1\n2. Item 2"],
[["Item 1", "Item 2"], { char: "- [ ]" }, "- [ ] Item 1\n- [ ] Item 2"],
],
} as Record<keyof typeof md, any[][]>;
describe("mdbox", () => {
for (const [fn, tests] of Object.entries(renderTests)) {
describe(fn, () => {
for (const t of tests) {
const output = t.pop();
it(`${fn}(${t.map((i) => JSON.stringify(i)).join(", ")})`, () => {
expect(md[fn](...t)).toBe(output);
});
}
});
}
it("table", () => {
expect(
md.table({
columns: ["Breed", "Origin", "Size", "Temperament"],
rows: [
["Abyssinian", "Egypt", "Medium", "Active"],
["Aegean", "Greece", "Medium", "Active"],
["American Bobtail", "United States", "Medium", "Active"],
["Applehead Siamese", "Thailand", "Medium", "Active"],
],
}),
).toMatchInlineSnapshot(`
"| Breed | Origin | Size | Temperament |
| --- | --- | --- | --- |
| Abyssinian | Egypt | Medium | Active |
| Aegean | Greece | Medium | Active |
| American Bobtail | United States | Medium | Active |
| Applehead Siamese | Thailand | Medium | Active |"
`);
});
});