aboutsummaryrefslogtreecommitdiffstats
path: root/tests/heading_atx.rs
blob: b75d058401a3cd52c91a3a50978042e9474cd9f7 (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
205
206
207
208
extern crate micromark;
use micromark::micromark;
#[test]
fn heading_atx() {
    assert_eq!(
        micromark("# foo"),
        "<h1>foo</h1>",
        "should support a heading w/ rank 1"
    );

    assert_eq!(
        micromark("## foo"),
        "<h2>foo</h2>",
        "should support a heading w/ rank 2"
    );

    assert_eq!(
        micromark("### foo"),
        "<h3>foo</h3>",
        "should support a heading w/ rank 3"
    );

    assert_eq!(
        micromark("#### foo"),
        "<h4>foo</h4>",
        "should support a heading w/ rank 4"
    );

    assert_eq!(
        micromark("##### foo"),
        "<h5>foo</h5>",
        "should support a heading w/ rank 5"
    );

    assert_eq!(
        micromark("###### foo"),
        "<h6>foo</h6>",
        "should support a heading w/ rank 6"
    );

    assert_eq!(
        micromark("####### foo"),
        "<p>####### foo</p>",
        "should not support a heading w/ rank 7"
    );

    assert_eq!(
        micromark("#5 bolt"),
        "<p>#5 bolt</p>",
        "should not support a heading for a number sign not followed by whitespace (1)"
    );

    assert_eq!(
        micromark("#hashtag"),
        "<p>#hashtag</p>",
        "should not support a heading for a number sign not followed by whitespace (2)"
    );

    // To do: phrasing.
    // assert_eq!(
    //     micromark("\\## foo"),
    //     "<p>## foo</p>",
    //     "should not support a heading for an escaped number sign"
    // );

    // assert_eq!(
    //     micromark("# foo *bar* \\*baz\\*"),
    //     "<h1>foo <em>bar</em> *baz*</h1>",
    //     "should support text content in headings"
    // );

    assert_eq!(
        micromark("#                  foo                     "),
        "<h1>foo</h1>",
        "should support arbitrary initial and final whitespace"
    );

    assert_eq!(
        micromark(" ### foo"),
        "<h3>foo</h3>",
        "should support an initial space"
    );

    assert_eq!(
        micromark("  ## foo"),
        "<h2>foo</h2>",
        "should support two initial spaces"
    );

    assert_eq!(
        micromark("   # foo"),
        "<h1>foo</h1>",
        "should support three initial spaces"
    );

    assert_eq!(
        micromark("    # foo"),
        "<pre><code># foo\n</code></pre>",
        "should not support four initial spaces"
    );

    // To do: lazy.
    // assert_eq!(
    //     micromark("foo\n    # bar"),
    //     "<p>foo\n# bar</p>",
    //     "should not support four initial spaces when interrupting"
    // );

    assert_eq!(
        micromark("## foo ##"),
        "<h2>foo</h2>",
        "should support a closing sequence (1)"
    );

    assert_eq!(
        micromark("  ###   bar    ###"),
        "<h3>bar</h3>",
        "should support a closing sequence (2)"
    );

    assert_eq!(
        micromark("# foo ##################################"),
        "<h1>foo</h1>",
        "should support a closing sequence w/ an arbitrary number of number signs (1)"
    );

    assert_eq!(
        micromark("##### foo ##"),
        "<h5>foo</h5>",
        "should support a closing sequence w/ an arbitrary number of number signs (2)"
    );

    assert_eq!(
        micromark("### foo ###     "),
        "<h3>foo</h3>",
        "should support trailing whitespace after a closing sequence"
    );

    assert_eq!(
        micromark("### foo ### b"),
        "<h3>foo ### b</h3>",
        "should not support other content after a closing sequence"
    );

    assert_eq!(
        micromark("# foo#"),
        "<h1>foo#</h1>",
        "should not support a closing sequence w/o whitespace before it"
    );

    // Phrasing.
    // assert_eq!(
    //     micromark("### foo \\###"),
    //     "<h3>foo ###</h3>",
    //     "should not support an “escaped” closing sequence (1)"
    // );

    // assert_eq!(
    //     micromark("## foo #\\##"),
    //     "<h2>foo ###</h2>",
    //     "should not support an “escaped” closing sequence (2)"
    // );

    // assert_eq!(
    //     micromark("# foo \\#"),
    //     "<h1>foo #</h1>",
    //     "should not support an “escaped” closing sequence (3)"
    // );

    assert_eq!(
        micromark("****\n## foo\n****"),
        "<hr />\n<h2>foo</h2>\n<hr />",
        "should support atx headings when not surrounded by blank lines"
    );

    assert_eq!(
        micromark("Foo bar\n# baz\nBar foo"),
        "<p>Foo bar</p>\n<h1>baz</h1>\n<p>Bar foo</p>",
        "should support atx headings interrupting paragraphs"
    );

    // Line endings.
    assert_eq!(
        micromark("## \n#\n### ###"),
        "<h2></h2>\n<h1></h1>\n<h3></h3>",
        "should support empty atx headings"
    );

    // To do: block quote.
    // assert_eq!(
    //     micromark("> #\na"),
    //     "<blockquote>\n<h1></h1>\n</blockquote>\n<p>a</p>",
    //     "should not support lazyness (1)"
    // );

    // assert_eq!(
    //     micromark("> a\n#"),
    //     "<blockquote>\n<p>a</p>\n</blockquote>\n<h1></h1>",
    //     "should not support lazyness (2)"
    // );

    // Extensions:
    // assert_eq!(
    //   micromark("# a", {extensions: [{disable: {null: ["headingAtx"]}}]}),
    //   "<p># a</p>",
    //   "should support turning off heading (atx)"
    // );
}