This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
utils.test.js
115 lines (103 loc) · 3.02 KB
/
utils.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
const {
dartLangNode,
dartLangWithSpacesNode,
typescriptLangNode,
typescriptWithLinesGroupNode,
dartLangMetaNode,
} = require("./tests/mocks");
const { parseLanguageAndHighlightedLines, parseNodeHtml } = require("./utils");
describe("parse node to html", () => {
it("should parse no language and no highlight lines (default)", () => {
const html = parseNodeHtml(
{
value: "hello world",
lang: "",
},
{}
);
expect(html).toEqual(`<deckgo-highlight-code >
<code slot="code">hello world</code>
</deckgo-highlight-code>`);
});
it("should parse javascript", () => {
const html = parseNodeHtml(
{
value: "hello world",
lang: "javascript",
},
{}
);
expect(html).toEqual(`<deckgo-highlight-code language="javascript" >
<code slot="code">hello world</code>
</deckgo-highlight-code>`);
});
it("should parse a specific language", () => {
const html = parseNodeHtml(
{
value: "hello world",
lang: "typescript",
},
{}
);
expect(html).toEqual(`<deckgo-highlight-code language="typescript" >
<code slot="code">hello world</code>
</deckgo-highlight-code>`);
});
it("should parse highlighted lines", () => {
const html = parseNodeHtml(
{
value: "hello world",
lang: "dart{3, 2, 5-9}",
},
{}
);
expect(html)
.toEqual(`<deckgo-highlight-code language="dart" highlight-lines="3 2 5,9">
<code slot="code">hello world</code>
</deckgo-highlight-code>`);
});
it("should parse no language and no highlight lines for null language", () => {
const html = parseNodeHtml(
{
value: "hello world",
lang: null,
},
{}
);
expect(html).toEqual(`<deckgo-highlight-code >
<code slot="code">hello world</code>
</deckgo-highlight-code>`);
});
});
describe("languages extraction", () => {
test("detects the languages correctly", () => {
expect(parseLanguageAndHighlightedLines(dartLangNode).lang).toBe("dart");
expect(parseLanguageAndHighlightedLines(dartLangWithSpacesNode).lang).toBe(
"dart"
);
expect(parseLanguageAndHighlightedLines(typescriptLangNode).lang).toBe(
"typescript"
);
expect(
parseLanguageAndHighlightedLines(typescriptWithLinesGroupNode).lang
).toBe("typescript");
});
test("detects the highlight-lines correctly", () => {
expect(parseLanguageAndHighlightedLines(dartLangNode).highlightLines).toBe(
"3 4 5"
);
expect(
parseLanguageAndHighlightedLines(dartLangWithSpacesNode).highlightLines
).toBe("5 9 34 39,44");
expect(
parseLanguageAndHighlightedLines(typescriptLangNode).highlightLines
).toBe("");
expect(
parseLanguageAndHighlightedLines(typescriptWithLinesGroupNode)
.highlightLines
).toBe("3 4 5,9 22,45");
expect(
parseLanguageAndHighlightedLines(dartLangMetaNode).highlightLines
).toBe("3 4 5");
});
});