-
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
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
import { assertEquals } from "https://deno.land/std@0.161.0/testing/asserts.ts";
import { parse } from "./mod.ts";
import {
bold,
channel,
code,
command,
emoji,
italic,
pre,
quote,
root,
strike,
text,
url,
user,
} from "./tests/helpers.ts";
Deno.test(`Should parse "foo bar" as text`, () => {
assertEquals(parse("foo bar"), root([text("foo bar")]));
});
Deno.test('Should parse "`foo`" as code', () => {
assertEquals(
parse("`foo`"),
root([code("foo")]),
);
});
Deno.test('Should parse "` foo `" as code', () => {
assertEquals(
parse("` foo `"),
root([code(" foo ")]),
);
});
Deno.test('Should parse "```foo```" as pretext', () => {
assertEquals(
parse("```foo```"),
root([pre("foo")]),
);
});
Deno.test('Should parse "``` foo ```" as pretext', () => {
assertEquals(
parse("``` foo ```"),
root([pre(" foo ")]),
);
});
Deno.test('Should parse "``` foo ``` bar ``` baz ```" as two pretexts', () => {
assertEquals(
parse("``` foo ``` bar ``` baz ```"),
root([pre(" foo "), text(" bar "), pre(" baz ")]),
);
});
Deno.test('Should not parse "``` ```" as pretext', () => {
assertEquals(parse("``` ```"), root([text("``` ```")]));
});
Deno.test('Should not parse "foo```bar```baz" as pretext', () => {
assertEquals(parse("foo```bar```baz"), root([text("foo```bar```baz")]));
});
Deno.test('Should parse "*foo*" as bold', () => {
assertEquals(parse("*foo*"), root([bold([text("foo")])]));
});
Deno.test('Should parse "foo *bar* baz" as bold', () => {
assertEquals(
parse("foo *bar* baz"),
root([text("foo "), bold([text("bar")]), text(" baz")]),
);
});
Deno.test('Should not parse "foo*bar*baz" as bold', () => {
assertEquals(parse("foo*bar*baz"), root([text("foo*bar*baz")]));
});
Deno.test('Should not parse "*foo*bar" as bold', () => {
assertEquals(parse("*foo*bar"), root([text("*foo*bar")]));
});
Deno.test('Should not parse "foo * bar * baz" as bold', () => {
assertEquals(parse("foo * bar * baz"), root([text("foo * bar * baz")]));
});
Deno.test('Should parse "Hey, <@FOO>!" as user link', () => {
assertEquals(
parse("Hey, <@FOO>!"),
root([text("Hey, "), user("FOO"), text("!")]),
);
});
Deno.test('Should parse "Goto <#FOO>?" as channel link', () => {
assertEquals(
parse("Goto <#FOO>?"),
root([text("Goto "), channel("FOO"), text("?")]),
);
});
Deno.test('Should parse "foo <!bar> baz" as command', () => {
assertEquals(
parse("foo <!bar> baz"),
root([text("foo "), command("bar", []), text(" baz")]),
);
});
Deno.test("Should parse command arguments", () => {
assertEquals(parse("<!foo^bar>"), root([command("foo", ["bar"])]));
});
Deno.test('Should parse "Visit <http://foo.bar> or email to <mailto:foo@bar>" as url', () => {
const expected = root([
text("Visit "),
url("http://foo.bar"),
text(" or email to "),
url("mailto:foo@bar"),
]);
assertEquals(
parse("Visit <http://foo.bar> or email to <mailto:foo@bar>"),
expected,
);
});
Deno.test("Should not allow nested link", () => {
assertEquals(
parse("<http://foo|<http://bar>>"),
root([text("<http://foo|"), url("http://bar"), text(">")]),
);
});
Deno.test("Should parse label", () => {
assertEquals(
parse("<http://foo|bar>"),
root([url("http://foo", [text("bar")])]),
);
});
Deno.test("Should allow formated text in label", () => {
const expected = root([
url("http://foo", [bold([text("bar "), strike([text("baz")])])]),
]);
assertEquals(parse("<http://foo|*bar ~baz~*>"), expected);
});
Deno.test('Should parse "foo :bar: baz" as emoji', () => {
assertEquals(
parse("foo :bar: baz"),
root([text("foo "), emoji("bar"), text(" baz")]),
);
});
Deno.test("Should parse emoji with skin-tone variation", () => {
assertEquals(
parse(":foo::skin-tone-1:"),
root([emoji("foo", "skin-tone-1")]),
);
});
Deno.test("Should parse sequential emojis", () => {
assertEquals(
parse("ab:cd::ef::skin-tone-1:g:h::i:jk"),
root([
text("ab"),
emoji("cd"),
emoji("ef", "skin-tone-1"),
text("g"),
emoji("h"),
emoji("i"),
text("jk"),
]),
);
});
Deno.test('Should parse "foo:bar:baz" as emoji', () => {
assertEquals(
parse("foo:bar:baz"),
root([text("foo"), emoji("bar"), text("baz")]),
);
});
Deno.test("Should not parse invalid emoji names", () => {
assertEquals(
parse("(11/3 - 4:30pm): ok"),
root([text("(11/3 - 4:30pm): ok")]),
);
});
Deno.test("Should parse quote text", () => {
assertEquals(
parse("> foo *bar*"),
root([quote([text(" foo "), bold([text("bar")])], true)]),
);
});
Deno.test("Should parse quote located in second line", () => {
assertEquals(
parse("foo\n>bar"),
root([text("foo\n"), quote([text("bar")], true)]),
);
});
Deno.test("Should parse multiline quote", () => {
assertEquals(
parse("foo\n>>>bar\n\nbaz"),
root([text("foo\n"), quote([text("bar\n\nbaz")])]),
);
});
Deno.test('Should not parse "foo>bar" as quote', () => {
assertEquals(parse("foo>bar"), root([text("foo>bar")]));
});
Deno.test('Should parse ">>>" as quoted ">>"', () => {
assertEquals(parse(">>>"), root([quote([text(">>")], true)]));
});
Deno.test('Should delimit with "?"', () => {
assertEquals(parse("*foo*?"), root([bold([text("foo")]), text("?")]));
});
Deno.test('Should delimit with "!"', () => {
assertEquals(parse("*foo*!"), root([bold([text("foo")]), text("!")]));
});
Deno.test('Should delimit with "."', () => {
assertEquals(parse("*foo*."), root([bold([text("foo")]), text(".")]));
});
Deno.test('Should delimit with "()"', () => {
assertEquals(
parse("(*foo*)"),
root([text("("), bold([text("foo")]), text(")")]),
);
assertEquals(parse(")*foo*("), root([text(")*foo*(")]));
});
Deno.test('Should delimit with "[]"', () => {
assertEquals(
parse("[*foo*]"),
root([text("["), bold([text("foo")]), text("]")]),
);
assertEquals(parse("]*foo*["), root([text("]*foo*[")]));
});
Deno.test('Should delimit with "{}"', () => {
assertEquals(
parse("{*foo*}"),
root([text("{"), bold([text("foo")]), text("}")]),
);
assertEquals(parse("}*foo*{"), root([text("}*foo*{")]));
});
Deno.test('Should delimit with "-" or "="', () => {
assertEquals(
parse("-*foo*="),
root([text("-"), bold([text("foo")]), text("=")]),
);
});
Deno.test("Should parse slack message", () => {
const expected = root([
user("FOO", [
text("abc "),
strike([
text("def "),
italic([
text("ghi "),
bold([text("jkl "), emoji("+1")]),
text(" mno"),
]),
text(" pqr"),
]),
text(" stu "),
pre("vwx"),
]),
]);
assertEquals(
parse("<@FOO|abc ~def _ghi *jkl :+1:* mno_ pqr~ stu ```vwx```>"),
expected,
);
});