-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
117 lines (103 loc) · 2.96 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
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
///<reference types="bun" />
import { describe, test, expect } from "bun:test";
import markdownit from "markdown-it";
import markdownitTypograf from "./index.js";
/**
* @param {import('markdown-it').Options} [options]
* @param {import("./index.js").PluginOptions} [pluginOptions]
* @returns {markdownit}
*/
function getMd(options = {}, pluginOptions) {
return markdownit(options).use(markdownitTypograf, {
typografOptions: {
locale: "ru",
disableRule: "*",
enableRule: "common/number/mathSigns",
},
...pluginOptions,
});
}
/** @type {Array<[string, string]>} */
const CASES = [["!=", "≠"]];
describe("configuration", () => {
test("typografOptions is optional", () => {
expect(() => {
const md = markdownit().use(markdownitTypograf, {
typografSetup(tp) {
tp.disableRule("*");
},
});
md.render(CASES[0][0]);
}).not.toThrow();
});
test("typografSetup is optional", () => {
expect(() => {
const md = markdownit().use(markdownitTypograf, {
typografOptions: { locale: "ru", disableRule: "*" },
});
md.render(CASES[0][0]);
}).not.toThrow();
});
test("plugin options is optional", () => {
expect(() => {
const md = markdownit().use(markdownitTypograf);
md.render(CASES[0][0]);
}).not.toThrow();
});
test("typografOptions in use", () => {
const md = markdownit().use(markdownitTypograf, {
typografOptions: {
locale: "ru",
disableRule: "*",
},
});
expect(md.render("!=")).toBe("<p>!=</p>\n");
});
test("typografSetup in use", () => {
const md = markdownit().use(markdownitTypograf, {
typografSetup(tp) {
tp.disableRule("*");
},
});
expect(md.render("!=")).toBe("<p>!=</p>\n");
});
});
describe("rendering", () => {
test.each(CASES)("works on text", (i, o) => {
const md = getMd();
expect(md.render(i)).toBe(`<p>${o}</p>\n`);
});
test.each(CASES)("works in markdown", (i, o) => {
const md = getMd();
expect(md.render(`- ${i}`)).toBe(`<ul>\n<li>${o}</li>\n</ul>\n`);
});
test.each(CASES)("works in nested markdown", (i, o) => {
const md = getMd();
expect(md.render(`- ${i}\n - ${i}`)).toBe(
`<ul>\n<li>${o}\n<ul>\n<li>${o}</li>\n</ul>\n</li>\n</ul>\n`,
);
});
test.each(CASES)("works in html", (i, o) => {
const md = getMd({ html: true });
expect(md.render(`<div>${i}</div>`)).toBe(`<div>${o}</div>`);
});
test.each(CASES)("works in nested html", (i, o) => {
const md = getMd({ html: true });
expect(md.render(`<div><div>${i}</div></div>`)).toBe(
`<div><div>${o}</div></div>`,
);
});
test.each(CASES)("safe tag works", (i, _o) => {
const md = getMd(
{ html: true },
{
typografSetup(tp) {
tp.addSafeTag("<no-tp>", "</no-tp>");
},
},
);
expect(md.render(`<div><no-tp>${i}</no-tp></div>`)).toBe(
`<div><no-tp>${i}</no-tp></div>`,
);
});
});