aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fuzz.rs
blob: 72f365efbb97028cc725b1655ecb53a6834dd624 (plain) (blame)
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
extern crate markdown;
use markdown::{mdast, to_html, to_html_with_options, to_mdast, Options};
use pretty_assertions::assert_eq;

#[test]
fn fuzz() -> Result<(), String> {
    assert_eq!(
        to_html("[\n~\na\n-\n\n"),
        "<h2>[\n~\na</h2>\n",
        "1: label, blank lines, and code"
    );

    // The first link is stopped by the `+` (so it’s `a@b.c`), but the next
    // link overlaps it (`b.c+d@e.f`).
    assert_eq!(
        to_html_with_options("a@b.c+d@e.f", &Options::gfm())?,
        "<p><a href=\"mailto:a@b.c\">a@b.c</a><a href=\"mailto:+d@e.f\">+d@e.f</a></p>",
        "2: gfm: email autolink literals running into each other"
    );

    assert_eq!(
        to_html("    x\n*    "),
        "<pre><code>x\n</code></pre>\n<ul>\n<li></li>\n</ul>",
        "3-a: containers should not pierce into indented code"
    );

    assert_eq!(
        to_html("    a\n*     b"),
        "<pre><code>a\n</code></pre>\n<ul>\n<li>\n<pre><code>b\n</code></pre>\n</li>\n</ul>",
        "3-b: containers should not pierce into indented code"
    );

    assert_eq!(
        to_html("a * "),
        "<p>a *</p>",
        "4-a: trailing whitespace and broken data"
    );

    assert_eq!(
        to_html("_  "),
        "<p>_</p>",
        "4-b: trailing whitespace and broken data (GH-13)"
    );

    assert_eq!(
        to_html_with_options("a ~ ", &Options::gfm())?,
        "<p>a ~</p>",
        "4-c: trailing whitespace and broken data (GH-14)"
    );

    assert!(
        matches!(
            to_mdast("123456789. ok", &Default::default()),
            Ok(mdast::Node::Root(_))
        ),
        "5: lists should support high start numbers (GH-17)"
    );

    assert_eq!(
        to_html("> ```\n"),
        "<blockquote>\n<pre><code>\n</code></pre>\n</blockquote>",
        "6-a: container close after unclosed fenced code, with eol (block quote, GH-16)"
    );

    assert_eq!(
        to_html("- ```\n"),
        "<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>",
        "6-b: container close after unclosed fenced code, with eol (list, GH-16)"
    );

    Ok(())
}