aboutsummaryrefslogtreecommitdiffstats
path: root/tests/thematic_break.rs
blob: 735829df2889afc1f4036418403a83325a0391b7 (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
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
extern crate markdown;
use markdown::{
    mdast::{Node, Root, ThematicBreak},
    to_html, to_html_with_options, to_mdast,
    unist::Position,
    Constructs, Options, ParseOptions,
};
use pretty_assertions::assert_eq;

#[test]
fn thematic_break() -> Result<(), String> {
    assert_eq!(
        to_html("***\n---\n___"),
        "<hr />\n<hr />\n<hr />",
        "should support thematic breaks w/ asterisks, dashes, and underscores"
    );

    assert_eq!(
        to_html("+++"),
        "<p>+++</p>",
        "should not support thematic breaks w/ plusses"
    );

    assert_eq!(
        to_html("==="),
        "<p>===</p>",
        "should not support thematic breaks w/ equals"
    );

    assert_eq!(
        to_html("--"),
        "<p>--</p>",
        "should not support thematic breaks w/ two dashes"
    );

    assert_eq!(
        to_html("**"),
        "<p>**</p>",
        "should not support thematic breaks w/ two asterisks"
    );

    assert_eq!(
        to_html("__"),
        "<p>__</p>",
        "should not support thematic breaks w/ two underscores"
    );

    assert_eq!(
        to_html(" ***"),
        "<hr />",
        "should support thematic breaks w/ 1 space"
    );

    assert_eq!(
        to_html("  ***"),
        "<hr />",
        "should support thematic breaks w/ 2 spaces"
    );

    assert_eq!(
        to_html("   ***"),
        "<hr />",
        "should support thematic breaks w/ 3 spaces"
    );

    assert_eq!(
        to_html("    ***"),
        "<pre><code>***\n</code></pre>",
        "should not support thematic breaks w/ 4 spaces"
    );

    assert_eq!(
        to_html("Foo\n    ***"),
        "<p>Foo\n***</p>",
        "should not support thematic breaks w/ 4 spaces as paragraph continuation"
    );

    assert_eq!(
        to_html("_____________________________________"),
        "<hr />",
        "should support thematic breaks w/ many markers"
    );

    assert_eq!(
        to_html(" - - -"),
        "<hr />",
        "should support thematic breaks w/ spaces (1)"
    );

    assert_eq!(
        to_html(" **  * ** * ** * **"),
        "<hr />",
        "should support thematic breaks w/ spaces (2)"
    );

    assert_eq!(
        to_html("-     -      -      -"),
        "<hr />",
        "should support thematic breaks w/ spaces (3)"
    );

    assert_eq!(
        to_html("- - - -    "),
        "<hr />",
        "should support thematic breaks w/ trailing spaces"
    );

    assert_eq!(
        to_html("_ _ _ _ a"),
        "<p>_ _ _ _ a</p>",
        "should not support thematic breaks w/ other characters (1)"
    );

    assert_eq!(
        to_html("a------"),
        "<p>a------</p>",
        "should not support thematic breaks w/ other characters (2)"
    );

    assert_eq!(
        to_html("---a---"),
        "<p>---a---</p>",
        "should not support thematic breaks w/ other characters (3)"
    );

    assert_eq!(
        to_html(" *-*"),
        "<p><em>-</em></p>",
        "should not support thematic breaks w/ mixed markers"
    );

    assert_eq!(
        to_html("- foo\n***\n- bar"),
        "<ul>\n<li>foo</li>\n</ul>\n<hr />\n<ul>\n<li>bar</li>\n</ul>",
        "should support thematic breaks mixed w/ lists (1)"
    );

    assert_eq!(
        to_html("* Foo\n* * *\n* Bar"),
        "<ul>\n<li>Foo</li>\n</ul>\n<hr />\n<ul>\n<li>Bar</li>\n</ul>",
        "should support thematic breaks mixed w/ lists (2)"
    );

    assert_eq!(
        to_html("Foo\n***\nbar"),
        "<p>Foo</p>\n<hr />\n<p>bar</p>",
        "should support thematic breaks interrupting paragraphs"
    );

    assert_eq!(
        to_html("Foo\n---\nbar"),
        "<h2>Foo</h2>\n<p>bar</p>",
        "should not support thematic breaks w/ dashes interrupting paragraphs (setext heading)"
    );

    assert_eq!(
        to_html("- Foo\n- * * *"),
        "<ul>\n<li>Foo</li>\n<li>\n<hr />\n</li>\n</ul>",
        "should support thematic breaks in lists"
    );

    assert_eq!(
        to_html("> ---\na"),
        "<blockquote>\n<hr />\n</blockquote>\n<p>a</p>",
        "should not support lazyness (1)"
    );

    assert_eq!(
        to_html("> a\n---"),
        "<blockquote>\n<p>a</p>\n</blockquote>\n<hr />",
        "should not support lazyness (2)"
    );

    assert_eq!(
        to_html_with_options(
            "***",
            &Options {
                parse: ParseOptions {
                    constructs: Constructs {
                        thematic_break: false,
                        ..Constructs::default()
                    },
                    ..ParseOptions::default()
                },
                ..Options::default()
            }
        )?,
        "<p>***</p>",
        "should support turning off thematic breaks"
    );

    assert_eq!(
        to_mdast("***", &ParseOptions::default())?,
        Node::Root(Root {
            children: vec![Node::ThematicBreak(ThematicBreak {
                position: Some(Position::new(1, 1, 0, 1, 4, 3))
            })],
            position: Some(Position::new(1, 1, 0, 1, 4, 3))
        }),
        "should support thematic breaks as `ThematicBreak`s in mdast"
    );

    Ok(())
}