-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.ts
85 lines (79 loc) · 2.37 KB
/
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
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { toHTML, toMarkdownV2 } from "./mod.ts";
Deno.test("URL entity inside bold must stringify to HTML correctly", () => {
assertEquals(
toHTML({
text: "Hello, https://feathers.studio!",
entities: [
{ type: "bold", offset: 0, length: "Hello, https://feathers.studio!".length },
{ type: "url", offset: "Hello, ".length, length: "https://feathers.studio".length },
],
}),
'<b>Hello, <a href="https://feathers.studio">https://feathers.studio</a>!</b>',
);
assertEquals(
toHTML({
text: "Hello, feathers.studio!",
entities: [
{ type: "bold", offset: 0, length: "Hello, feathers.studio!".length },
{
type: "text_link",
offset: "Hello, ".length,
length: "feathers.studio".length,
url: "https://feathers.studio",
},
],
}),
'<b>Hello, <a href="https://feathers.studio">feathers.studio</a>!</b>',
);
// based on https://github.com/telegraf/entity/issues/2
assertEquals(
toHTML({
text: "👉 Link :- https://example.com?x&y",
entities: [
{ offset: 0, length: 11, type: "bold" },
{ offset: 11, length: 23, type: "url" },
{ offset: 11, length: 23, type: "bold" },
],
}),
'<b>👉 Link :- </b><a href="https://example.com?x&y"><b>https://example.com?x&y</b></a>',
);
});
Deno.test("URL entity inside bold must stringify to Markdown correctly", () => {
assertEquals(
toMarkdownV2({
text: "Hello, https://feathers.studio!",
entities: [
{ type: "bold", offset: 0, length: "Hello, https://feathers.studio!".length },
{ type: "url", offset: "Hello, ".length, length: "https://feathers.studio".length },
],
}),
"*Hello, https://feathers\\.studio\\!*",
);
assertEquals(
toMarkdownV2({
text: "Hello, feathers.studio!",
entities: [
{ type: "bold", offset: 0, length: "Hello, feathers.studio!".length },
{
type: "text_link",
offset: "Hello, ".length,
length: "feathers.studio".length,
url: "https://feathers.studio",
},
],
}),
"*Hello, [feathers\\.studio](https://feathers.studio)\\!*",
);
assertEquals(
toMarkdownV2({
text: "👉 Link :- https://example.com",
entities: [
{ offset: 0, length: 11, type: "bold" },
{ offset: 11, length: 19, type: "url" },
{ offset: 11, length: 19, type: "bold" },
],
}),
"*👉 Link :\\- **https://example\\.com*",
);
});