Markdown parser fork with extended syntax for personal use.
at main 133 lines 4.2 kB view raw
1use markdown::{mdast, message, to_html, to_html_with_options, to_mdast, Options}; 2use pretty_assertions::assert_eq; 3 4#[test] 5fn fuzz() -> Result<(), message::Message> { 6 assert_eq!( 7 to_html("[\n~\na\n-\n\n"), 8 "<h2>[\n~\na</h2>\n", 9 "1: label, blank lines, and code" 10 ); 11 12 // The first link is stopped by the `+` (so it’s `a@b.c`), but the next 13 // link overlaps it (`b.c+d@e.f`). 14 assert_eq!( 15 to_html_with_options("a@b.c+d@e.f", &Options::gfm())?, 16 "<p><a href=\"mailto:a@b.c\">a@b.c</a><a href=\"mailto:+d@e.f\">+d@e.f</a></p>", 17 "2: gfm: email autolink literals running into each other" 18 ); 19 20 assert_eq!( 21 to_html(" x\n* "), 22 "<pre><code>x\n</code></pre>\n<ul>\n<li></li>\n</ul>", 23 "3-a: containers should not pierce into indented code" 24 ); 25 26 assert_eq!( 27 to_html(" a\n* b"), 28 "<pre><code>a\n</code></pre>\n<ul>\n<li>\n<pre><code>b\n</code></pre>\n</li>\n</ul>", 29 "3-b: containers should not pierce into indented code" 30 ); 31 32 assert_eq!( 33 to_html("a * "), 34 "<p>a *</p>", 35 "4-a: trailing whitespace and broken data" 36 ); 37 38 assert_eq!( 39 to_html("_ "), 40 "<p>_</p>", 41 "4-b: trailing whitespace and broken data (GH-13)" 42 ); 43 44 assert_eq!( 45 to_html_with_options("a ~ ", &Options::gfm())?, 46 "<p>a ~</p>", 47 "4-c: trailing whitespace and broken data (GH-14)" 48 ); 49 50 assert!( 51 matches!( 52 to_mdast("123456789. ok", &Default::default()), 53 Ok(mdast::Node::Root(_)) 54 ), 55 "5: lists should support high start numbers (GH-17)" 56 ); 57 58 assert_eq!( 59 to_html("> ```\n"), 60 "<blockquote>\n<pre><code>\n</code></pre>\n</blockquote>", 61 "6-a: container close after unclosed fenced code, with eol (block quote, GH-16)" 62 ); 63 64 assert_eq!( 65 to_html("- ```\n"), 66 "<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>", 67 "6-b: container close after unclosed fenced code, with eol (list, GH-16)" 68 ); 69 70 assert_eq!( 71 to_html_with_options("> x\n``", &Options::gfm()), 72 Ok("<blockquote>\n<p>x</p>\n</blockquote>\n<p>``</p>".into()), 73 "7: lazy container lines almost starting fenced code (GH-19)" 74 ); 75 76 assert_eq!( 77 to_html_with_options("a\tb@c.d", &Options::gfm()), 78 Ok("<p>a\t<a href=\"mailto:b@c.d\">b@c.d</a></p>".into()), 79 "8-a: autolink literals after tabs (GH-18)" 80 ); 81 82 assert_eq!( 83 to_html_with_options("aa\tb@c.d", &Options::gfm()), 84 Ok("<p>aa\t<a href=\"mailto:b@c.d\">b@c.d</a></p>".into()), 85 "8-b: autolink literals after tabs (GH-18)" 86 ); 87 88 assert_eq!( 89 to_html_with_options("aaa\tb@c.d", &Options::gfm()), 90 Ok("<p>aaa\t<a href=\"mailto:b@c.d\">b@c.d</a></p>".into()), 91 "8-c: autolink literals after tabs (GH-18)" 92 ); 93 94 assert_eq!( 95 to_html_with_options("aaaa\tb@c.d", &Options::gfm()), 96 Ok("<p>aaaa\t<a href=\"mailto:b@c.d\">b@c.d</a></p>".into()), 97 "8-d: autolink literals after tabs (GH-18)" 98 ); 99 100 assert_eq!( 101 to_html_with_options("| a |\n| - |\n| www.a|", &Options::gfm()), 102 Ok("<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"http://www.a\">www.a</a></td>\n</tr>\n</tbody>\n</table>".into()), 103 "9: autolink literals that end in table cell delimiter (GH-20)" 104 ); 105 106 assert_eq!( 107 to_html_with_options("[*]() [*]()", &Options::gfm()), 108 Ok("<p><a href=\"\">*</a> <a href=\"\">*</a></p>".into()), 109 "10: attention in different links (GH-21)" 110 ); 111 112 assert!( 113 matches!( 114 to_mdast("* [ ]\na", &Default::default()), 115 Ok(mdast::Node::Root(_)) 116 ), 117 "11: gfm task list items followed by eols (GH-24)" 118 ); 119 120 assert_eq!( 121 markdown::to_html_with_options( 122 "<", 123 &markdown::Options { 124 parse: markdown::ParseOptions::mdx(), 125 ..Default::default() 126 } 127 ), 128 Ok("<p>&lt;</p>".to_string()), 129 "12: mdx: handle invalid mdx without panic (GH-26)" 130 ); 131 132 Ok(()) 133}