Debian Codegraph @

src/tests/core.rs

raw
1 use crate::nodes::{NodeCode, NodeValue};
2
3 use super::*;
4
5 #[test]
6 fn basic() {
7 html(
8 concat!(
9 "My **document**.\n",
10 "\n",
11 "It's mine.\n",
12 "\n",
13 "> Yes.\n",
14 "\n",
15 "## Hi!\n",
16 "\n",
17 "Okay.\n"
18 ),
19 concat!(
20 "<p>My <strong>document</strong>.</p>\n",
21 "<p>It's mine.</p>\n",
22 "<blockquote>\n",
23 "<p>Yes.</p>\n",
24 "</blockquote>\n",
25 "<h2>Hi!</h2>\n",
26 "<p>Okay.</p>\n"
27 ),
28 );
29 }
30
31 #[test]
32 fn codefence() {
33 html(
34 concat!("``` rust yum\n", "fn main<'a>();\n", "```\n"),
35 concat!(
36 "<pre><code class=\"language-rust\">fn main&lt;'a&gt;();\n",
37 "</code></pre>\n"
38 ),
39 );
40 }
41
42 #[test]
43 fn lists() {
44 html(
45 concat!("2. Hello.\n", "3. Hi.\n"),
46 concat!(
47 "<ol start=\"2\">\n",
48 "<li>Hello.</li>\n",
49 "<li>Hi.</li>\n",
50 "</ol>\n"
51 ),
52 );
53
54 html(
55 concat!("- Hello.\n", "- Hi.\n"),
56 concat!("<ul>\n", "<li>Hello.</li>\n", "<li>Hi.</li>\n", "</ul>\n"),
57 );
58 }
59 #[test]
60 fn thematic_breaks() {
61 html(
62 concat!("---\n", "\n", "- - -\n", "\n", "\n", "_ _ _\n"),
63 concat!("<hr />\n", "<hr />\n", "<hr />\n"),
64 );
65 }
66
67 #[test]
68 fn atx_heading() {
69 html(
70 concat!("# h1\n", "foo\n", "## h2\n", "####### foo\n"),
71 concat!(
72 "<h1>h1</h1>\n",
73 "<p>foo</p>\n",
74 "<h2>h2</h2>\n",
75 "<p>####### foo</p>\n"
76 ),
77 );
78 }
79
80 #[test]
81 fn atx_heading_sourcepos() {
82 assert_ast_match!(
83 [],
84 "# h1\n"
85 "foo\n"
86 "## h2\n"
87 // https://spec.commonmark.org/0.31.2/#example-63
88 "####### foo\n",
89 (document (1:1-4:11) [
90 (heading (1:1-1:4) [
91 (text (1:3-1:4) "h1")
92 ])
93 (paragraph (2:1-2:3) [
94 (text (2:1-2:3) "foo")
95 ])
96 (heading (3:1-3:5) [
97 (text (3:4-3:5) "h2")
98 ])
99 (paragraph (4:1-4:11) [
100 (text (4:1-4:11) "####### foo")
101 ])
102 ])
103 );
104 }
105
106 #[test]
107 fn atx_heading_closed() {
108 let input = concat!(
109 // https://spec.commonmark.org/0.31.2/#example-71
110 "## Heading ##\n",
111 " ## Heading ##\n",
112 // https://spec.commonmark.org/0.31.2/#example-72
113 "## Heading #########\n",
114 "#### Heading ##\n",
115 // https://spec.commonmark.org/0.31.2/#example-73
116 "## Heading ### \n",
117 );
118
119 let arena = Arena::new();
120 let options = Options::default();
121 let root = parse_document(&arena, input, &options);
122
123 let headings = root
124 .descendants()
125 .filter(|n| matches!(n.data().value, NodeValue::Heading(_)));
126
127 for heading in headings {
128 if let NodeValue::Heading(ref nh) = heading.data().value {
129 assert!(
130 nh.closed,
131 "Expected all ATX headings to be closed: {:?}",
132 heading
133 );
134 }
135 }
136 }
137
138 #[test]
139 fn atx_heading_not_closed() {
140 let input = concat!(
141 // https://spec.commonmark.org/0.31.2/#example-62
142 "# Heading\n",
143 // https://spec.commonmark.org/0.31.2/#example-74
144 "### Heading ### b\n",
145 // https://spec.commonmark.org/0.31.2/#example-75
146 "# Heading#\n",
147 // https://spec.commonmark.org/0.31.2/#example-76
148 "### Heading \\###\n",
149 "## Heading #\\##\n",
150 "# Heading \\#\n",
151 );
152
153 let arena = Arena::new();
154 let options = Options::default();
155 let root = parse_document(&arena, input, &options);
156
157 let headings = root
158 .descendants()
159 .filter(|n| matches!(n.data().value, NodeValue::Heading(_)));
160
161 for heading in headings {
162 if let NodeValue::Heading(ref nh) = heading.data().value {
163 assert!(
164 !nh.closed,
165 "Expected all ATX headings to be not closed: {:?}",
166 heading
167 );
168 }
169 }
170 }
171
172 #[test]
173 fn atx_heading_closed_sourcepos() {
174 assert_ast_match!(
175 [parse.escaped_char_spans],
176 // https://spec.commonmark.org/0.31.2/#example-71
177 "## Heading ##\n"
178 " ## Heading ##\n"
179 // https://spec.commonmark.org/0.31.2/#example-72
180 "## Heading #########\n"
181 "#### Heading ##\n"
182 // Not part of the spec, but for completeness
183 "######### Not heading ##\n"
184 // https://spec.commonmark.org/0.31.2/#example-73
185 "## Heading ### \n"
186 // https://spec.commonmark.org/0.31.2/#example-74
187 "### Heading ### b\n"
188 // https://spec.commonmark.org/0.31.2/#example-75
189 "# Heading#\n"
190 // https://spec.commonmark.org/0.31.2/#example-76
191 "### Heading \\###\n"
192 "## Heading #\\##\n"
193 "# Heading \\#\n",
194 (document (1:1-11:12) [
195 (heading (1:1-1:13) [
196 (text (1:4-1:10) "Heading")
197 ])
198 (heading (2:4-2:16) [
199 (text (2:7-2:13) "Heading")
200 ])
201 (heading (3:1-3:20) [
202 (text (3:4-3:10) "Heading")
203 ])
204 (heading (4:1-4:15) [
205 (text (4:6-4:12) "Heading")
206 ])
207 (paragraph (5:1-5:24) [
208 (text (5:1-5:24) "######### Not heading ##")
209 ])
210 (heading (6:1-6:17) [
211 (text (6:4-6:10) "Heading")
212 ])
213 (heading (7:1-7:17) [
214 (text (7:5-7:17) "Heading ### b")
215 ])
216 (heading (8:1-8:10) [
217 (text (8:3-8:10) "Heading#")
218 ])
219 (heading (9:1-9:16) [
220 (text (9:5-9:12) "Heading ")
221 (escaped (9:13-9:14) [
222 (text (9:14-9:14) "#")
223 ])
224 (text (9:15-9:16) "##")
225 ])
226 (heading (10:1-10:15) [
227 (text (10:4-10:12) "Heading #")
228 (escaped (10:13-10:14) [
229 (text (10:14-10:14) "#")
230 ])
231 (text (10:15-10:15) "#")
232 ])
233 (heading (11:1-11:12) [
234 (text (11:3-11:10) "Heading ")
235 (escaped (11:11-11:12) [
236 (text (11:12-11:12) "#")
237 ])
238 ])
239 ])
240 );
241 }
242
243 #[test]
244 fn setext_heading() {
245 html(
246 concat!("Hi\n", "==\n", "\n", "Ok\n", "-----\n"),
247 concat!("<h1>Hi</h1>\n", "<h2>Ok</h2>\n"),
248 );
249 }
250
251 #[test]
252 fn setext_heading_sourcepos() {
253 assert_ast_match!(
254 [],
255 "Header\n"
256 "---\n"
257 "this",
258 (document (1:1-3:4) [
259 (heading (1:1-2:3) [
260 (text (1:1-1:6) "Header")
261 ])
262 (paragraph (3:1-3:4) [
263 (text (3:1-3:4) "this")
264 ])
265 ])
266 );
267 }
268
269 #[test]
270 fn ignore_setext_heading() {
271 html_opts!(
272 [parse.ignore_setext],
273 "text text\n---",
274 "<p>text text</p>\n<hr />\n",
275 );
276 }
277
278 #[test]
279 fn figure_with_caption_with_title() {
280 html_opts!(
281 [render.figure_with_caption],
282 "![image](https://example.com/image.png \"this is an image\")\n",
283 "<p><figure><img src=\"https://example.com/image.png\" alt=\"image\" title=\"this is an image\" /><figcaption>this is an image</figcaption></figure></p>\n",
284 );
285 }
286
287 #[test]
288 fn figure_with_caption_without_title() {
289 html_opts!(
290 [render.figure_with_caption],
291 "![image](https://example.com/image.png)\n",
292 "<p><figure><img src=\"https://example.com/image.png\" alt=\"image\" /></figure></p>\n",
293 );
294 }
295
296 #[test]
297 fn html_block_1() {
298 html_opts!(
299 [render.r#unsafe],
300 concat!(
301 "<script>\n",
302 "*ok* </script> *ok*\n",
303 "\n",
304 "*ok*\n",
305 "\n",
306 "*ok*\n",
307 "\n",
308 "<pre x>\n",
309 "*ok*\n",
310 "</style>\n",
311 "*ok*\n",
312 "<style>\n",
313 "*ok*\n",
314 "</style>\n",
315 "\n",
316 "*ok*\n"
317 ),
318 concat!(
319 "<script>\n",
320 "*ok* </script> *ok*\n",
321 "<p><em>ok</em></p>\n",
322 "<p><em>ok</em></p>\n",
323 "<pre x>\n",
324 "*ok*\n",
325 "</style>\n",
326 "<p><em>ok</em></p>\n",
327 "<style>\n",
328 "*ok*\n",
329 "</style>\n",
330 "<p><em>ok</em></p>\n"
331 ),
332 );
333 }
334
335 #[test]
336 fn html_block_2() {
337 html_opts!(
338 [render.r#unsafe],
339 concat!(" <!-- abc\n", "\n", "ok --> *hi*\n", "*hi*\n"),
340 concat!(
341 " <!-- abc\n",
342 "\n",
343 "ok --> *hi*\n",
344 "<p><em>hi</em></p>\n"
345 ),
346 );
347 }
348
349 #[test]
350 fn html_block_3() {
351 html_opts!(
352 [render.r#unsafe],
353 concat!(" <? o\n", "k ?> *a*\n", "*a*\n"),
354 concat!(" <? o\n", "k ?> *a*\n", "<p><em>a</em></p>\n"),
355 );
356 }
357
358 #[test]
359 fn html_block_4() {
360 html_opts!(
361 [render.r#unsafe],
362 concat!("<!X >\n", "ok\n", "<!X\n", "um > h\n", "ok\n"),
363 concat!("<!X >\n", "<p>ok</p>\n", "<!X\n", "um > h\n", "<p>ok</p>\n"),
364 );
365 }
366
367 #[test]
368 fn html_block_5() {
369 html_opts!(
370 [render.r#unsafe],
371 concat!(
372 "<![CDATA[\n",
373 "\n",
374 "hm >\n",
375 "*ok*\n",
376 "]]> *ok*\n",
377 "*ok*\n"
378 ),
379 concat!(
380 "<![CDATA[\n",
381 "\n",
382 "hm >\n",
383 "*ok*\n",
384 "]]> *ok*\n",
385 "<p><em>ok</em></p>\n"
386 ),
387 );
388 }
389
390 #[test]
391 fn html_block_6() {
392 html_opts!(
393 [render.r#unsafe],
394 concat!(" </table>\n", "*x*\n", "\n", "ok\n", "\n", "<li\n", "*x*\n"),
395 concat!(" </table>\n", "*x*\n", "<p>ok</p>\n", "<li\n", "*x*\n"),
396 );
397 }
398
399 #[test]
400 fn html_block_7() {
401 html_opts!(
402 [render.r#unsafe],
403 concat!(
404 "<a b >\n",
405 "ok\n",
406 "\n",
407 "<a b=>\n",
408 "ok\n",
409 "\n",
410 "<a b \n",
411 "<a b> c\n",
412 "ok\n"
413 ),
414 concat!(
415 "<a b >\n",
416 "ok\n",
417 "<p>&lt;a b=&gt;\n",
418 "ok</p>\n",
419 "<p>&lt;a b\n",
420 "<a b> c\n",
421 "ok</p>\n"
422 ),
423 );
424
425 html_opts!(
426 [render.r#unsafe],
427 concat!("<a b c=x d='y' z=\"f\" >\n", "ok\n", "\n", "ok\n"),
428 concat!("<a b c=x d='y' z=\"f\" >\n", "ok\n", "<p>ok</p>\n"),
429 );
430 }
431
432 #[test]
433 fn backticks() {
434 html(
435 "Some `code\\` yep.\n",
436 "<p>Some <code>code\\</code> yep.</p>\n",
437 );
438 }
439
440 #[test]
441 fn backticks_empty_with_newline_should_be_space() {
442 html("`\n`", "<p><code> </code></p>\n");
443 }
444
445 #[test]
446 fn blockquote_hard_linebreak_space() {
447 html(">\\\n A", "<blockquote>\n<p><br />\nA</p>\n</blockquote>\n");
448 }
449
450 #[test]
451 fn blockquote_hard_linebreak_nonlazy_space() {
452 html(
453 "> A\\\n> B",
454 "<blockquote>\n<p>A<br />\nB</p>\n</blockquote>\n",
455 );
456 }
457
458 #[test]
459 fn backticks_num() {
460 let input = "Some `code1`. More ``` code2 ```.\n";
461
462 let arena = Arena::new();
463 let options = Options::default();
464 let root = parse_document(&arena, input, &options);
465
466 let code1 = NodeValue::Code(NodeCode {
467 num_backticks: 1,
468 literal: "code1".to_string(),
469 });
470 assert_node_eq(root, &[0, 1], &code1);
471
472 let code2 = NodeValue::Code(NodeCode {
473 num_backticks: 3,
474 literal: "code2".to_string(),
475 });
476 assert_node_eq(root, &[0, 3], &code2);
477 }
478
479 #[test]
480 fn backslashes() {
481 html(
482 concat!(
483 "Some \\`fake code\\`.\n",
484 "\n",
485 "Some fake linebreaks:\\\n",
486 "Yes.\\\n",
487 "See?\n",
488 "\n",
489 "Ga\\rbage.\n"
490 ),
491 concat!(
492 "<p>Some `fake code`.</p>\n",
493 "<p>Some fake linebreaks:<br />\n",
494 "Yes.<br />\n",
495 "See?</p>\n",
496 "<p>Ga\\rbage.</p>\n"
497 ),
498 );
499 }
500
501 #[test]
502 fn entities() {
503 html(
504 concat!(
505 "This is &amp;, &copy;, &trade;, \\&trade;, &xyz;, &NotEqualTilde;.\n",
506 "\n",
507 "&#8734; &#x221e;\n"
508 ),
509 concat!(
510 "<p>This is &amp;, ©, ™, &amp;trade;, &amp;xyz;, \u{2242}\u{338}.</p>\n",
511 "<p>∞ ∞</p>\n"
512 ),
513 );
514 }
515
516 #[test]
517 fn links() {
518 html(
519 concat!(
520 "Where are you [going](https://microsoft.com (today))?\n",
521 "\n",
522 "[Where am I?](/here)\n"
523 ),
524 concat!(
525 "<p>Where are you <a href=\"https://microsoft.com\" \
526 title=\"today\">going</a>?</p>\n",
527 "<p><a href=\"/here\">Where am I?</a></p>\n"
528 ),
529 );
530 html(
531 concat!(
532 r"Where are you [going](#1\.-link (today))?",
533 "\n",
534 "\n",
535 "[Where am I?](/here)\n"
536 ),
537 concat!(
538 "<p>Where are you <a href=\"#1.-link\" \
539 title=\"today\">going</a>?</p>\n",
540 "<p><a href=\"/here\">Where am I?</a></p>\n"
541 ),
542 );
543 html(
544 r"[Link Text](\\\\)",
545 concat!(r##"<p><a href="%5C%5C">Link Text</a></p>"##, '\n'),
546 );
547 html(
548 r"[Link Text](\\\\\\\\\\)",
549 concat!(r##"<p><a href="%5C%5C%5C%5C%5C">Link Text</a></p>"##, '\n'),
550 );
551 html(
552 r"[Link Text](\\\\ (title))",
553 concat!(
554 r##"<p><a href="%5C%5C" title="title">Link Text</a></p>"##,
555 '\n'
556 ),
557 );
558 html(
559 r"[Link Text](\#)",
560 concat!(r##"<p><a href="#">Link Text</a></p>"##, '\n'),
561 );
562 }
563
564 #[test]
565 fn images() {
566 html(
567 "I am ![eating [things](/url)](http://i.imgur.com/QqK1vq7.png).\n",
568 "<p>I am <img src=\"http://i.imgur.com/QqK1vq7.png\" alt=\"eating things\" />.</p>\n",
569 );
570 }
571
572 #[test]
573 fn reference_links() {
574 html(
575 concat!(
576 "This [is] [legit], [very][honestly] legit.\n",
577 "\n",
578 "[legit]: ok\n",
579 "[honestly]: sure \"hm\"\n"
580 ),
581 "<p>This [is] <a href=\"ok\">legit</a>, <a href=\"sure\" title=\"hm\">very</a> legit.</p>\n",
582 );
583 }
584
585 #[test]
586 fn reference_links_casefold() {
587 html(
588 concat!("[ẞ]\n", "\n", "[SS]: /url \n",),
589 "<p><a href=\"/url\">ẞ</a></p>\n",
590 );
591 }
592
593 #[test]
594 fn safety() {
595 html(
596 concat!(
597 "[data:image/png](data:image/png/x)\n\n",
598 "[data:image/gif](data:image/gif/x)\n\n",
599 "[data:image/jpeg](data:image/jpeg/x)\n\n",
600 "[data:image/webp](data:image/webp/x)\n\n",
601 "[data:malicious](data:malicious/x)\n\n",
602 "[javascript:malicious](javascript:malicious)\n\n",
603 "[vbscript:malicious](vbscript:malicious)\n\n",
604 "[file:malicious](file:malicious)\n\n",
605 ),
606 concat!(
607 "<p><a href=\"data:image/png/x\">data:image/png</a></p>\n",
608 "<p><a href=\"data:image/gif/x\">data:image/gif</a></p>\n",
609 "<p><a href=\"data:image/jpeg/x\">data:image/jpeg</a></p>\n",
610 "<p><a href=\"data:image/webp/x\">data:image/webp</a></p>\n",
611 "<p><a href=\"\">data:malicious</a></p>\n",
612 "<p><a href=\"\">javascript:malicious</a></p>\n",
613 "<p><a href=\"\">vbscript:malicious</a></p>\n",
614 "<p><a href=\"\">file:malicious</a></p>\n",
615 ),
616 )
617 }
618
619 #[test]
620 fn link_backslash_requires_punct() {
621 // Test should probably be in the spec.
622 html("[a](\\ b)", "<p>[a](\\ b)</p>\n");
623 }
624
625 #[test]
626 fn nul_replacement_1() {
627 html("a\0b", "<p>a\u{fffd}b</p>\n");
628 }
629
630 #[test]
631 fn nul_replacement_2() {
632 html("a\0b\0c", "<p>a\u{fffd}b\u{fffd}c</p>\n");
633 }
634
635 #[test]
636 fn nul_replacement_3() {
637 html("a\0\nb", "<p>a\u{fffd}\nb</p>\n");
638 }
639
640 #[test]
641 fn nul_replacement_4() {
642 html("a\0\r\nb", "<p>a\u{fffd}\nb</p>\n");
643 }
644
645 #[test]
646 fn nul_replacement_5() {
647 html("a\r\n\0b", "<p>a\n\u{fffd}b</p>\n");
648 }
649
650 #[test]
651 fn case_insensitive_safety() {
652 html(
653 "[a](javascript:a) [b](Javascript:b) [c](jaVascript:c) [d](data:xyz) [e](Data:xyz) [f](vbscripT:f) [g](FILE:g)\n",
654 "<p><a href=\"\">a</a> <a href=\"\">b</a> <a href=\"\">c</a> <a href=\"\">d</a> <a href=\"\">e</a> <a href=\"\">f</a> <a href=\"\">g</a></p>\n",
655 );
656 }
657
658 #[test]
659 fn link_sourcepos_baseline() {
660 assert_ast_match!(
661 [],
662 "[ABCD](/)\n",
663 (document (1:1-1:9) [
664 (paragraph (1:1-1:9) [
665 (link (1:1-1:9) "/" [
666 (text (1:2-1:5) "ABCD")
667 ])
668 ])
669 ])
670 );
671 }
672
673 // https://github.com/kivikakk/comrak/issues/301
674 #[test]
675 fn link_sourcepos_newline() {
676 assert_ast_match!(
677 [],
678 "[AB\nCD](/)\n",
679 (document (1:1-2:6) [
680 (paragraph (1:1-2:6) [
681 (link (1:1-2:6) "/" [
682 (text (1:2-1:3) "AB")
683 (softbreak (1:4-1:4))
684 (text (2:1-2:2) "CD")
685 ])
686 ])
687 ])
688 );
689 }
690
691 // https://github.com/kivikakk/comrak/issues/572
692 #[test]
693 fn link_sourcepos_newline_n_between_dest_and_title() {
694 assert_ast_match!(
695 [],
696 "[link]( /uri\n \"title\" )\n",
697 (document (1:1-2:12) [
698 (paragraph (1:1-2:12) [
699 (link (1:1-1:14) "/uri" [
700 (text (1:2-1:5) "link")
701 ])
702 ])
703 ])
704 );
705 }
706
707 #[test]
708 fn link_sourcepos_newline_r_between_dest_and_title() {
709 assert_ast_match!(
710 [],
711 "[link]( /uri\r \"title\" )\r",
712 (document (1:1-2:12) [
713 (paragraph (1:1-2:12) [
714 (link (1:1-1:14) "/uri" [
715 (text (1:2-1:5) "link")
716 ])
717 ])
718 ])
719 );
720 }
721
722 #[test]
723 fn link_sourcepos_newline_rn_between_dest_and_title() {
724 assert_ast_match!(
725 [],
726 "[link]( /uri\r\n \"title\" )\r\n",
727 (document (1:1-2:12) [
728 (paragraph (1:1-2:12) [
729 (link (1:1-1:14) "/uri" [
730 (text (1:2-1:5) "link")
731 ])
732 ])
733 ])
734 );
735 }
736
737 #[test]
738 fn link_sourcepos_truffle() {
739 assert_ast_match!(
740 [],
741 "- A\n[![B](/B.png)](/B)\n",
742 (document (1:1-2:18) [
743 (list (1:1-2:18) [
744 (item (1:1-2:18) [
745 (paragraph (1:3-2:18) [
746 (text (1:3-1:3) "A")
747 (softbreak (1:4-1:4))
748 (link (2:1-2:18) "/B" [
749 (image (2:2-2:13) "/B.png" [
750 (text (2:4-2:4) "B")
751 ])
752 ])
753 ])
754 ])
755 ])
756 ])
757 );
758 }
759
760 #[test]
761 fn link_sourcepos_truffle_twist() {
762 assert_ast_match!(
763 [],
764 "- A\n [![B](/B.png)](/B)\n",
765 (document (1:1-2:20) [
766 (list (1:1-2:20) [
767 (item (1:1-2:20) [
768 (paragraph (1:3-2:20) [
769 (text (1:3-1:3) "A")
770 (softbreak (1:4-1:4))
771 (link (2:3-2:20) "/B" [
772 (image (2:4-2:15) "/B.png" [
773 (text (2:6-2:6) "B")
774 ])
775 ])
776 ])
777 ])
778 ])
779 ])
780 );
781 }
782
783 #[test]
784 fn link_sourcepos_truffle_bergamot() {
785 assert_ast_match!(
786 [],
787 "- A\n [![B](/B.png)](/B)\n",
788 (document (1:1-2:21) [
789 (list (1:1-2:21) [
790 (item (1:1-2:21) [
791 (paragraph (1:3-2:21) [
792 (text (1:3-1:3) "A")
793 (softbreak (1:4-1:4))
794 (link (2:4-2:21) "/B" [
795 (image (2:5-2:16) "/B.png" [
796 (text (2:7-2:7) "B")
797 ])
798 ])
799 ])
800 ])
801 ])
802 ])
803 );
804 }
805
806 #[test]
807 fn paragraph_sourcepos_multiline() {
808 assert_ast_match!(
809 [],
810 " A\n"
811 " B\n",
812 (document (1:1-2:4) [
813 (paragraph (1:3-2:4) [
814 (text (1:3-1:3) "A")
815 (softbreak (1:4-1:4))
816 (text (2:4-2:4) "B")
817 ])
818 ])
819 );
820 }
821
822 #[test]
823 fn listitem_sourcepos_multiline() {
824 assert_ast_match!(
825 [],
826 "- A\n"
827 "B\n",
828 (document (1:1-2:1) [
829 (list (1:1-2:1) [
830 (item (1:1-2:1) [
831 (paragraph (1:3-2:1) [
832 (text (1:3-1:3) "A")
833 (softbreak (1:4-1:4))
834 (text (2:1-2:1) "B")
835 ])
836 ])
837 ])
838 ])
839 );
840 }
841
842 #[test]
843 fn listitem_sourcepos_multiline_2() {
844 assert_ast_match!(
845 [],
846 "- A\n"
847 " B\n"
848 "- C\n"
849 " D",
850 (document (1:1-4:2) [
851 (list (1:1-4:2) [
852 (item (1:1-2:4) [
853 (paragraph (1:3-2:4) [
854 (text (1:3-1:3) "A")
855 (softbreak (1:4-1:4))
856 (text (2:4-2:4) "B")
857 ])
858 ])
859 (item (3:1-4:2) [
860 (paragraph (3:4-4:2) [
861 (text (3:4-3:4) "C")
862 (softbreak (3:5-3:5))
863 (text (4:2-4:2) "D")
864 ])
865 ])
866 ])
867 ])
868 );
869 }
870
871 #[test]
872 fn emphasis_sourcepos_double_1() {
873 assert_ast_match!(
874 [],
875 "_**this**_\n",
876 (document (1:1-1:10) [
877 (paragraph (1:1-1:10) [
878 (emph (1:1-1:10) [
879 (strong (1:2-1:9) [
880 (text (1:4-1:7) "this")
881 ])
882 ])
883 ])
884 ])
885 );
886 }
887
888 #[test]
889 fn emphasis_sourcepos_double_2() {
890 assert_ast_match!(
891 [],
892 "**_this_**\n",
893 (document (1:1-1:10) [
894 (paragraph (1:1-1:10) [
895 (strong (1:1-1:10) [
896 (emph (1:3-1:8) [
897 (text (1:4-1:7) "this")
898 ])
899 ])
900 ])
901 ])
902 );
903 }
904
905 #[test]
906 fn emphasis_sourcepos_double_3() {
907 assert_ast_match!(
908 [],
909 "___this___\n",
910 (document (1:1-1:10) [
911 (paragraph (1:1-1:10) [
912 (emph (1:1-1:10) [
913 (strong (1:2-1:9) [
914 (text (1:4-1:7) "this")
915 ])
916 ])
917 ])
918 ])
919 );
920 }
921
922 #[test]
923 fn emphasis_sourcepos_double_4() {
924 assert_ast_match!(
925 [],
926 "***this***\n",
927 (document (1:1-1:10) [
928 (paragraph (1:1-1:10) [
929 (emph (1:1-1:10) [
930 (strong (1:2-1:9) [
931 (text (1:4-1:7) "this")
932 ])
933 ])
934 ])
935 ])
936 );
937 }
938
939 #[test]
940 fn ipv6_host_unescaped() {
941 html(
942 "test <http://[319:3cf0:dd1d:47b9:20c:29ff:fe2c:39be]/test>",
943 "<p>test <a href=\"http://[319:3cf0:dd1d:47b9:20c:29ff:fe2c:39be]/test\">http://[319:3cf0:dd1d:47b9:20c:29ff:fe2c:39be]/test</a></p>\n",
944 );
945
946 html(
947 "[henwo](https://[2402:1f00:89aa:300::5%25eth0]:9443?target=<yes>)",
948 "<p><a href=\"https://[2402:1f00:89aa:300::5%25eth0]:9443?target=%3Cyes%3E\">henwo</a></p>\n",
949 );
950 }
951
952 #[test]
953 fn link_ref_definition_priority() {
954 html(
955 "[foo]\n\n[foo]: first\n[foo]: second\n",
956 "<p><a href=\"first\">foo</a></p>\n",
957 );
958 }
959
960 #[test]
961 fn link_ref_definition_empty() {
962 html("[foo]:\n\n[foo]", "<p>[foo]:</p>\n<p>[foo]</p>\n");
963 }