Debian Codegraph @

src/tests/autolink.rs

raw
1 use super::*;
2
3 #[test]
4 fn autolink_www() {
5 html_opts!(
6 [extension.autolink],
7 "www.autolink.com\n",
8 "<p><a href=\"http://www.autolink.com\">www.autolink.com</a></p>\n",
9 );
10 }
11
12 #[test]
13 fn autolink_email() {
14 html_opts!(
15 [extension.autolink],
16 "[email protected]\n",
17 "<p><a href=\"mailto:[email protected]\">[email protected]</a></p>\n",
18 );
19 }
20
21 #[test]
22 fn autolink_scheme() {
23 html_opts!(
24 [extension.autolink],
25 concat!("https://google.com/search\n", "rdar://localhost.com/blah"),
26 concat!(
27 "<p><a href=\"https://google.com/search\">https://google.com/search</a>\n",
28 "rdar://localhost.com/blah</p>\n"
29 ),
30 );
31 }
32
33 #[test]
34 fn autolink_scheme_multiline() {
35 html_opts!(
36 [extension.autolink],
37 "https://google.com/search\nhttps://www.google.com/maps",
38 "<p><a href=\"https://google.com/search\">https://google.com/search</a>\n<a href=\"https://www.google.com/maps\">https://www.google.com/maps</a></p>\n",
39 );
40 }
41
42 #[test]
43 fn autolink_no_link_bad() {
44 html_opts!(
45 [extension.autolink],
46 concat!("@a.b.c@. x\n", "\n", "n@. x\n"),
47 concat!("<p>@a.b.c@. x</p>\n", "<p>n@. x</p>\n"),
48 );
49 }
50
51 #[test]
52 fn autolink_parentheses_balanced() {
53 let examples = [
54 [
55 "http://www.pokemon.com/Pikachu_(Electric)",
56 "<p><a href=\"http://www.pokemon.com/Pikachu_(Electric)\">http://www.pokemon.com/Pikachu_(Electric)</a></p>\n",
57 ],
58 [
59 "http://www.pokemon.com/Pikachu_((Electric)",
60 "<p><a href=\"http://www.pokemon.com/Pikachu_((Electric)\">http://www.pokemon.com/Pikachu_((Electric)</a></p>\n",
61 ],
62 [
63 "http://www.pokemon.com/Pikachu_(Electric))",
64 "<p><a href=\"http://www.pokemon.com/Pikachu_(Electric)\">http://www.pokemon.com/Pikachu_(Electric)</a>)</p>\n",
65 ],
66 [
67 "http://www.pokemon.com/Pikachu_((Electric))",
68 "<p><a href=\"http://www.pokemon.com/Pikachu_((Electric))\">http://www.pokemon.com/Pikachu_((Electric))</a></p>\n",
69 ],
70 ];
71
72 for example in examples {
73 html_opts!([extension.autolink], example[0], example[1]);
74 }
75
76 for example in examples {
77 html_opts!(
78 [extension.autolink, parse.relaxed_autolinks],
79 example[0],
80 example[1]
81 );
82 }
83 }
84
85 #[test]
86 fn autolink_brackets_unbalanced() {
87 html_opts!(
88 [extension.autolink],
89 "http://example.com/[abc]]...\n",
90 "<p><a href=\"http://example.com/%5Babc%5D%5D\">http://example.com/[abc]]</a>...</p>\n",
91 );
92 }
93
94 #[test]
95 fn autolink_ignore_links_in_brackets() {
96 let examples = [
97 ["[https://foo.com]", "<p>[https://foo.com]</p>\n"],
98 ["[[https://foo.com]]", "<p>[[https://foo.com]]</p>\n"],
99 [
100 "[[Foo|https://foo.com]]",
101 "<p>[[Foo|https://foo.com]]</p>\n",
102 ],
103 [
104 "[<https://foo.com>]",
105 "<p>[<a href=\"https://foo.com\">https://foo.com</a>]</p>\n",
106 ],
107 ];
108
109 for example in examples {
110 html_opts!([extension.autolink], example[0], example[1], no_roundtrip);
111 }
112 }
113
114 #[test]
115 fn autolink_relaxed_links_in_brackets() {
116 let examples = [
117 [
118 "[https://foo.com]",
119 "<p>[<a href=\"https://foo.com\">https://foo.com</a>]</p>\n",
120 ],
121 [
122 "[[https://foo.com]]",
123 "<p>[[<a href=\"https://foo.com\">https://foo.com</a>]]</p>\n",
124 ],
125 [
126 "[[Foo|https://foo.com]]",
127 "<p>[[Foo|<a href=\"https://foo.com\">https://foo.com</a>]]</p>\n",
128 ],
129 [
130 "[<https://foo.com>]",
131 "<p>[<a href=\"https://foo.com\">https://foo.com</a>]</p>\n",
132 ],
133 [
134 "[http://foo.com/](url)",
135 "<p><a href=\"url\">http://foo.com/</a></p>\n",
136 ],
137 ["[http://foo.com/](url", "<p>[http://foo.com/](url</p>\n"],
138 [
139 "[www.foo.com/](url)",
140 "<p><a href=\"url\">www.foo.com/</a></p>\n",
141 ],
142 [
143 "{https://foo.com}",
144 "<p>{<a href=\"https://foo.com\">https://foo.com</a>}</p>\n",
145 ],
146 [
147 "[this http://and.com that](url)",
148 "<p><a href=\"url\">this http://and.com that</a></p>\n",
149 ],
150 [
151 "[this <http://and.com> that](url)",
152 "<p><a href=\"url\">this http://and.com that</a></p>\n",
153 ],
154 [
155 "{this http://and.com that}(url)",
156 "<p>{this <a href=\"http://and.com\">http://and.com</a> that}(url)</p>\n",
157 ],
158 [
159 "[http://foo.com](url)\n[http://bar.com]\n\n[http://bar.com]: http://bar.com/extra",
160 "<p><a href=\"url\">http://foo.com</a>\n<a href=\"http://bar.com/extra\">http://bar.com</a></p>\n",
161 ],
162 ];
163
164 for example in examples {
165 html_opts!(
166 [extension.autolink, parse.relaxed_autolinks],
167 example[0],
168 example[1]
169 );
170 }
171 }
172
173 #[test]
174 fn autolink_relaxed_links_brackets_balanced() {
175 html_opts!(
176 [extension.autolink, parse.relaxed_autolinks],
177 "http://example.com/[abc]]...\n",
178 "<p><a href=\"http://example.com/%5Babc%5D\">http://example.com/[abc]</a>]...</p>\n",
179 );
180 }
181
182 #[test]
183 fn autolink_relaxed_links_curly_braces_balanced() {
184 html_opts!(
185 [extension.autolink, parse.relaxed_autolinks],
186 "http://example.com/{abc}}...\n",
187 "<p><a href=\"http://example.com/%7Babc%7D\">http://example.com/{abc}</a>}...</p>\n",
188 );
189 }
190
191 #[test]
192 fn autolink_relaxed_links_curly_parentheses_balanced() {
193 html_opts!(
194 [extension.autolink, parse.relaxed_autolinks],
195 "http://example.com/(abc))...\n",
196 "<p><a href=\"http://example.com/(abc)\">http://example.com/(abc)</a>)...</p>\n",
197 );
198 }
199
200 #[test]
201 fn autolink_relaxed_links_schemes() {
202 let examples = [
203 [
204 "https://foo.com",
205 "<p><a href=\"https://foo.com\">https://foo.com</a></p>\n",
206 ],
207 [
208 "smb:///Volumes/shared/foo.pdf",
209 "<p><a href=\"smb:///Volumes/shared/foo.pdf\">smb:///Volumes/shared/foo.pdf</a></p>\n",
210 ],
211 [
212 "irc://irc.freenode.net/git",
213 "<p><a href=\"irc://irc.freenode.net/git\">irc://irc.freenode.net/git</a></p>\n",
214 ],
215 [
216 "rdar://localhost.com/blah",
217 "<p><a href=\"rdar://localhost.com/blah\">rdar://localhost.com/blah</a></p>\n",
218 ],
219 ];
220
221 for example in examples {
222 html_opts!(
223 [extension.autolink, parse.relaxed_autolinks],
224 example[0],
225 example[1]
226 );
227 }
228 }
229
230 #[test]
231 fn sourcepos_correctly_restores_context() {
232 assert_ast_match!(
233 [],
234 "ab _cde_ [email protected] h*ijklm* n",
235 (document (1:1-1:26) [
236 (paragraph (1:1-1:26) [
237 (text (1:1-1:3) "ab ")
238 (emph (1:4-1:8) [
239 (text (1:5-1:7) "cde")
240 ])
241 (text (1:9-1:17) " [email protected] h")
242 (emph (1:18-1:24) [
243 (text (1:19-1:23) "ijklm")
244 ])
245 (text (1:25-1:26) " n")
246 ])
247 ])
248 );
249
250 assert_ast_match!(
251 [extension.autolink],
252 "ab _cde_ [email protected] h*ijklm* n",
253 (document (1:1-1:26) [
254 (paragraph (1:1-1:26) [
255 (text (1:1-1:3) "ab ")
256 (emph (1:4-1:8) [
257 (text (1:5-1:7) "cde")
258 ])
259 (text (1:9-1:9) " ")
260 (link (1:10-1:15) "mailto:[email protected]" [
261 (text (1:10-1:15) "[email protected]")
262 ])
263 (text (1:16-1:17) " h")
264 (emph (1:18-1:24) [
265 (text (1:19-1:23) "ijklm")
266 ])
267 (text (1:25-1:26) " n")
268 ])
269 ])
270 );
271 }
272
273 #[test]
274 fn autolink_cmark_edge_382() {
275 html_opts!(
276 [extension.autolink],
277 "See &lt;&lt;&lt;http://example.com/&gt;&gt;&gt;",
278 "<p>See &lt;&lt;&lt;<a href=\"http://example.com/\">http://example.com/</a>&gt;&gt;&gt;</p>\n",
279 );
280 }
281
282 #[test]
283 fn autolink_cmark_edge_388() {
284 html_opts!(
285 [extension.autolink],
286 "http://example.com/src/_mocks_/vscode.js",
287 "<p><a href=\"http://example.com/src/_mocks_/vscode.js\">http://example.com/src/_mocks_/vscode.js</a></p>\n",
288 );
289 }
290
291 #[test]
292 fn autolink_cmark_edge_423() {
293 html_opts!(
294 [extension.autolink, extension.strikethrough],
295 concat!(
296 "Here's an autolink: ",
297 "https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022",
298 " and another one ",
299 "https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022",
300 ".",
301 ),
302 concat!(
303 "<p>Here's an autolink: ",
304 r#"<a href="https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022">"#,
305 "https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022",
306 "</a> and another one ",
307 r#"<a href="https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022">"#,
308 "https://www.unicode.org/review/pri453/feedback.html#:~:text=Fri%20Jun%2024%2009:56:01%20CDT%202022",
309 "</a>.</p>\n",
310 ),
311 );
312 }
313
314 #[test]
315 fn autolink_cmark_edge_58() {
316 html_opts!(
317 [extension.autolink, extension.superscript],
318 "https://www.wolframalpha.com/input/?i=x^2+(y-(x^2)^(1/3))^2=1",
319 concat!(
320 "<p>",
321 r#"<a href="https://www.wolframalpha.com/input/?i=x%5E2+(y-(x%5E2)%5E(1/3))%5E2=1">"#,
322 "https://www.wolframalpha.com/input/?i=x^2+(y-(x^2)^(1/3))^2=1",
323 "</a></p>\n",
324 ),
325 );
326 }
327
328 #[test]
329 fn autolink_failing_spec_image() {
330 html_opts!(
331 [extension.autolink],
332 "![http://inline.com/image](http://inline.com/image)",
333 "<p><img src=\"http://inline.com/image\" alt=\"http://inline.com/image\" /></p>\n",
334 );
335 }
336
337 #[test]
338 fn autolink_failing_spec_underscores() {
339 html_opts!(
340 [extension.autolink],
341 "Underscores not allowed in host name www.xxx.yyy._zzz",
342 "<p>Underscores not allowed in host name www.xxx.yyy._zzz</p>\n",
343 );
344 }
345
346 #[test]
347 fn autolink_fuzz_leading_colon() {
348 html_opts!(
349 [extension.autolink, parse.relaxed_autolinks],
350 "://-",
351 "<p><a href=\"://-\">://-</a></p>\n",
352 no_roundtrip,
353 );
354 }
355
356 #[test]
357 fn autolink_fuzz_we() {
358 html_opts!(
359 [extension.autolink, parse.relaxed_autolinks],
360 "we://w",
361 "<p><a href=\"we://w\">we://w</a></p>\n",
362 no_roundtrip,
363 );
364 }
365
366 #[test]
367 fn autolink_sourcepos() {
368 assert_ast_match!(
369 [extension.autolink],
370 "a www.makea.fish x\n"
371 "\n"
372 "b https://www.com y\n"
373 "\n"
374 "c [email protected] z\n"
375 ,
376 (document (1:1-5:17) [
377 (paragraph (1:1-1:20) [
378 (text (1:1-1:3) "a ")
379 (link (1:4-1:17) "http://www.makea.fish" [
380 (text (1:4-1:17) "www.makea.fish")
381 ])
382 (text (1:18-1:20) " x")
383 ])
384 (paragraph (3:1-3:21) [
385 (text (3:1-3:3) "b ")
386 (link (3:4-3:18) "https://www.com" [
387 (text (3:4-3:18) "https://www.com")
388 ])
389 (text (3:19-3:21) " y")
390 ])
391 (paragraph (5:1-5:17) [
392 (text (5:1-5:3) "c ")
393 (link (5:4-5:14) "mailto:[email protected]" [
394 (text (5:4-5:14) "[email protected]")
395 ])
396 (text (5:15-5:17) " z")
397 ])
398 ])
399 );
400 }
401
402 #[test]
403 fn autolink_consecutive_email() {
404 assert_ast_match!(
405 [extension.autolink],
406 "[email protected]/[email protected]",
407 (document (1:1-1:40) [
408 (paragraph (1:1-1:40) [
409 (link (1:1-1:19) "mailto:[email protected]" [
410 (text (1:1-1:19) "[email protected]")
411 ])
412 (text (1:20-1:20) "/")
413 (link (1:21-1:40) "mailto:[email protected]" [
414 (text (1:21-1:40) "[email protected]")
415 ])
416 ])
417 ])
418 );
419 }
420
421 #[test]
422 fn autolink_consecutive_email_smart() {
423 assert_ast_match!(
424 [extension.autolink, parse.smart],
425 "[email protected]@pokemon.com",
426 (document (1:1-1:41) [
427 (paragraph (1:1-1:41) [
428 (link (1:1-1:19) "mailto:[email protected]" [
429 (text (1:1-1:19) "[email protected]")
430 ])
431 (text (1:20-1:21) "–") // en-dash
432 (link (1:22-1:41) "mailto:[email protected]" [
433 (text (1:22-1:41) "[email protected]")
434 ])
435 ])
436 ])
437 );
438 }
439
440 #[test]
441 fn autolink_not_generated_inside_links() {
442 html_opts!(
443 [extension.autolink],
444 "[Contact [email protected] for help](http://support.example.com)",
445 "<p><a href=\"http://support.example.com\">Contact [email protected] for help</a></p>\n",
446 );
447
448 html_opts!(
449 [extension.autolink],
450 "[Visit https://www.example.com](http://example.com)",
451 "<p><a href=\"http://example.com\">Visit https://www.example.com</a></p>\n",
452 );
453
454 html_opts!(
455 [extension.autolink],
456 "[Check out www.example.com](http://example.com)",
457 "<p><a href=\"http://example.com\">Check out www.example.com</a></p>\n",
458 );
459 }
460
461 #[test]
462 fn autolink_not_generated_inside_images() {
463 // Test that emails inside image alt text don't become autolinks
464 html_opts!(
465 [extension.autolink],
466 "![Contact [email protected]](image.png)",
467 "<p><img src=\"image.png\" alt=\"Contact [email protected]\" /></p>\n",
468 );
469
470 html_opts!(
471 [extension.autolink],
472 "![Visit https://www.example.com](image.png)",
473 "<p><img src=\"image.png\" alt=\"Visit https://www.example.com\" /></p>\n",
474 );
475
476 html_opts!(
477 [extension.autolink],
478 "![Check www.example.com](image.png)",
479 "<p><img src=\"image.png\" alt=\"Check www.example.com\" /></p>\n",
480 );
481 }
482
483 #[test]
484 fn autolink_not_generated_inside_wikilinks() {
485 html_opts!(
486 [extension.autolink, extension.wikilinks_title_after_pipe],
487 "[[http://example.com|Contact [email protected]]]",
488 "<p><a href=\"http://example.com\" data-wikilink=\"true\">Contact [email protected]</a></p>\n",
489 );
490
491 html_opts!(
492 [extension.autolink, extension.wikilinks_title_after_pipe],
493 "[[http://example.com|Visit https://www.example.com]]",
494 "<p><a href=\"http://example.com\" data-wikilink=\"true\">Visit https://www.example.com</a></p>\n",
495 );
496
497 html_opts!(
498 [extension.autolink, extension.wikilinks_title_before_pipe],
499 "[[Check www.example.com|http://example.com]]",
500 "<p><a href=\"http://example.com\" data-wikilink=\"true\">Check www.example.com</a></p>\n",
501 );
502 }
503
504 #[test]
505 fn ipv6_host_scoped() {
506 html_opts!(
507 [extension.autolink, parse.relaxed_autolinks],
508 "scoped https://[fe80::1ff:fe23:4567:890a%25eth2]",
509 "<p>scoped <a href=\"https://[fe80::1ff:fe23:4567:890a%25eth2]\">https://[fe80::1ff:fe23:4567:890a%25eth2]</a></p>\n",
510 );
511 }
512
513 #[test]
514 fn ipv6_relaxed() {
515 html_opts!(
516 [extension.autolink],
517 "hi: nex://[fe80::1ff:fe23:4567:890a%25eth2]/z/x",
518 "<p>hi: nex://[fe80::1ff:fe23:4567:890a%25eth2]/z/x</p>\n",
519 );
520
521 html_opts!(
522 [extension.autolink, parse.relaxed_autolinks],
523 "hi: nex://[fe80::1ff:fe23:4567:890a%25eth2]/z/x",
524 "<p>hi: <a href=\"nex://[fe80::1ff:fe23:4567:890a%25eth2]/z/x\">nex://[fe80::1ff:fe23:4567:890a%25eth2]/z/x</a></p>\n",
525 );
526 }
527
528 #[test]
529 fn autolink_bare_www() {
530 html_opts!(
531 [extension.autolink],
532 "foo www. foo",
533 "<p>foo www. foo</p>\n",
534 );
535
536 html_opts!(
537 [extension.autolink, parse.relaxed_autolinks],
538 "foo www. foo",
539 "<p>foo <a href=\"http://www\">www</a>. foo</p>\n",
540 );
541 }
542
543 #[test]
544 fn autolink_bare_scheme() {
545 html_opts!(
546 [extension.autolink],
547 "foo http:// foo",
548 "<p>foo http:// foo</p>\n",
549 );
550
551 html_opts!(
552 [extension.autolink, parse.relaxed_autolinks],
553 "foo http:// foo",
554 "<p>foo <a href=\"http://\">http://</a> foo</p>\n",
555 );
556 }
557
558 #[test]
559 fn autolink_with_unicode_isolation() {
560 html_opts!(
561 [extension.autolink],
562 "https://www.example.com/",
563 "<p><a href=\"https://www.example.com/\">https://www.example.com/</a></p>\n",
564 );
565
566 html_opts!(
567 [extension.autolink],
568 "\u{2068}https://www.example.com/\u{2069}",
569 "<p>\u{2068}<a href=\"https://www.example.com/\">https://www.example.com/</a>\u{2069}</p>\n",
570 );
571 }