Debian Codegraph @

src/tests/regressions.rs

raw
1 use super::*;
2
3 #[test]
4 fn pointy_brace() {
5 html_opts!(
6 [render.r#unsafe],
7 concat!(
8 "URI autolink: <https://www.pixiv.net>\n",
9 "\n",
10 "Email autolink: <[email protected]>\n",
11 "\n",
12 "* Inline <em>tag</em> **ha**.\n",
13 "* Inline <!-- comment --> **ha**.\n",
14 "* Inline <? processing instruction ?> **ha**.\n",
15 "* Inline <!DECLARATION OKAY> **ha**.\n",
16 "* Inline <![CDATA[ok]ha **ha** ]]> **ha**.\n"
17 ),
18 concat!(
19 "<p>URI autolink: <a \
20 href=\"https://www.pixiv.net\">https://www.pixiv.net</a></p>\n",
21 "<p>Email autolink: <a \
22 href=\"mailto:[email protected]\">[email protected]</a></p>\n",
23 "<ul>\n",
24 "<li>Inline <em>tag</em> <strong>ha</strong>.</li>\n",
25 "<li>Inline <!-- comment --> <strong>ha</strong>.</li>\n",
26 "<li>Inline <? processing instruction ?> <strong>ha</strong>.</li>\n",
27 "<li>Inline <!DECLARATION OKAY> <strong>ha</strong>.</li>\n",
28 "<li>Inline <![CDATA[ok]ha **ha** ]]> <strong>ha</strong>.</li>\n",
29 "</ul>\n"
30 ),
31 );
32 }
33
34 #[test]
35 fn no_control_characters_in_reference_links() {
36 html(
37 "[A]:\u{1b}\n\nX [A] Y\n",
38 "<p>[A]:\u{1b}</p>\n<p>X [A] Y</p>\n",
39 )
40 }
41
42 #[test]
43 fn link_entity_regression() {
44 html(
45 "[link](&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29)",
46 "<p><a href=\"&amp;#x6A&amp;#x61&amp;#x76&amp;#x61&amp;#x73&amp;#x63&amp;#x72&amp;#x69&amp;#x70&amp;#x74&amp;#x3A&amp;#x61&amp;#x6C&amp;#x65&amp;#x72&amp;#x74&amp;#x28&amp;#x27&amp;#x58&amp;#x53&amp;#x53&amp;#x27&amp;#x29\">link</a></p>\n",
47 );
48 }
49
50 #[test]
51 fn regression_back_to_back_ranges() {
52 html(
53 "**bold*****bold+italic***",
54 "<p><strong>bold</strong><em><strong>bold+italic</strong></em></p>\n",
55 );
56 }
57
58 #[test]
59 fn no_panic_on_empty_bookended_atx_headers() {
60 html("# #", "<h1></h1>\n");
61 }
62
63 #[test]
64 fn no_stack_smash_html() {
65 let s: String = ">".repeat(150_000);
66 let arena = Arena::new();
67 let root = parse_document(&arena, &s, &Options::default());
68 let mut output = String::new();
69 html::format_document(root, &Options::default(), &mut output).unwrap()
70 }
71
72 #[test]
73 fn no_stack_smash_cm() {
74 let s: String = ">".repeat(150_000);
75 let arena = Arena::new();
76 let root = parse_document(&arena, &s, &Options::default());
77 let mut output = String::new();
78 cm::format_document(root, &Options::default(), &mut output).unwrap()
79 }
80
81 #[test]
82 fn cm_autolink_regression() {
83 // Testing that the cm renderer handles this case without crashing
84 html("<a+c:dd>", "<p><a href=\"a+c:dd\">a+c:dd</a></p>\n");
85 }
86
87 #[test]
88 fn regression_424() {
89 html(
90 "*text* [link](#section)",
91 "<p><em>text</em> <a href=\"#section\">link</a></p>\n",
92 );
93 }
94
95 #[test]
96 fn example_61() {
97 html(
98 r##"
99 `Foo
100 ----
101 `
102
103 <a title="a lot
104 ---
105 of dashes"/>
106 "##,
107 r##"<h2>`Foo</h2>
108 <p>`</p>
109 <h2>&lt;a title=&quot;a lot</h2>
110 <p>of dashes&quot;/&gt;</p>
111 "##,
112 );
113 }
114
115 #[test]
116 fn nul_at_eof() {
117 html("foo\0", "<p>foo\u{fffd}</p>\n");
118 html("foo\0nl", "<p>foo\u{fffd}nl</p>\n");
119 html("foo\0nl\0", "<p>foo\u{fffd}nl\u{fffd}</p>\n");
120 }
121
122 #[test]
123 fn sourcepos_para() {
124 html_opts!(
125 [render.sourcepos],
126 "abc\ndef\n\nghi\n",
127 "<p data-sourcepos=\"1:1-2:3\">abc\ndef</p>\n<p data-sourcepos=\"4:1-4:3\">ghi</p>\n",
128 );
129 }
130
131 #[test]
132 #[cfg(feature = "shortcodes")]
133 fn gemoji() {
134 html_opts!([extension.shortcodes], ":x:", "<p>❌</p>\n");
135 }
136
137 #[test]
138 fn sourcepos_lone_backtick() {
139 assert_ast_match!(
140 [],
141 "``\n",
142 (document (1:1-1:2) [
143 (paragraph (1:1-1:2) [
144 (text (1:1-1:2) "``")
145 ])
146 ])
147 );
148 }
149
150 #[ignore] // This one will require a bit of thinking.
151 #[test]
152 fn sourcepos_link_items() {
153 assert_ast_match!(
154 [],
155 "- ab\n"
156 "- cdef\n"
157 "\n"
158 "\n"
159 "g\n"
160 ,
161 (document (1:1-5:1) [
162 (list (1:1-2:6) [
163 (item (1:1-1:4) [
164 (paragraph (1:3-1:4) [
165 (text (1:3-1:4) "ab")
166 ])
167 ])
168 (item (2:1-2:6) [
169 (paragraph (2:3-2:6) [
170 (text (2:3-2:6) "cdef")
171 ])
172 ])
173 ])
174 (paragraph (5:1-5:1) [
175 (text (5:1-5:1) "g")
176 ])
177 ])
178 );
179 }
180
181 #[test]
182 fn assorted_links() {
183 assert_ast_match!(
184 [extension.autolink],
185 r#"hello <https://example.com/fooo> world
186 hello [foo](https://example.com) world
187 hello [foo] world
188 hello [bar][bar] world
189 hello https://example.com/foo world
190 hello www.example.com world
191 hello [email protected] world
192
193 [foo]: https://example.com
194 [bar]: https://example.com"#,
195 (document (1:1-10:26) [
196 (paragraph (1:1-7:27) [
197 (text (1:1-1:6) "hello ")
198 (link (1:7-1:32) "https://example.com/fooo" [
199 (text (1:8-1:31) "https://example.com/fooo")
200 ])
201 (text (1:33-1:38) " world")
202 (softbreak (1:39-1:39))
203 (text (2:1-2:6) "hello ")
204 (link (2:7-2:32) "https://example.com" [
205 (text (2:8-2:10) "foo")
206 ])
207 (text (2:33-2:38) " world")
208 (softbreak (2:39-2:39))
209 (text (3:1-3:6) "hello ")
210 (link (3:7-3:11) "https://example.com" [
211 (text (3:8-3:10) "foo")
212 ])
213 (text (3:12-3:17) " world")
214 (softbreak (3:18-3:18))
215 (text (4:1-4:6) "hello ")
216 (link (4:7-4:16) "https://example.com" [
217 (text (4:8-4:10) "bar")
218 ])
219 (text (4:17-4:22) " world")
220 (softbreak (4:23-4:23))
221 (text (5:1-5:6) "hello ")
222 (link (5:7-5:29) "https://example.com/foo" [
223 (text (5:7-5:29) "https://example.com/foo")
224 ])
225 (text (5:30-5:35) " world")
226 (softbreak (5:36-5:36))
227 (text (6:1-6:6) "hello ")
228 (link (6:7-6:21) "http://www.example.com" [
229 (text (6:7-6:21) "www.example.com")
230 ])
231 (text (6:22-6:27) " world")
232 (softbreak (6:28-6:28))
233 (text (7:1-7:6) "hello ")
234 (link (7:7-7:21) "mailto:[email protected]" [
235 (text (7:7-7:21) "[email protected]")
236 ])
237 (text (7:22-7:27) " world")
238 ])
239 ])
240 );
241 }
242
243 #[test]
244 fn autolink_between_escaped_chars() {
245 assert_ast_match!(
246 [extension.autolink],
247 "a.b-c\\[email protected]\\_\n",
248 (document (1:1-1:14) [
249 (paragraph (1:1-1:14) [
250 (text (1:1-1:7) "a.b-c_")
251 (link (1:8-1:12) "mailto:[email protected]" [
252 (text (1:8-1:12) "[email protected]")
253 ])
254 (text (1:14-1:14) "_")
255 ])
256 ])
257 );
258 }
259
260 #[test]
261 fn sourcepos_newline_kinds() {
262 assert_ast_match!(
263 [],
264 "LF\n"
265 "CRLF\r\n"
266 "CR\r"
267 "end.",
268 (document (1:1-4:4) [
269 (paragraph (1:1-4:4) [
270 (text (1:1-1:2) "LF")
271 (softbreak (1:3-1:3))
272 (text (2:1-2:4) "CRLF")
273 (softbreak (2:5-2:6))
274 (text (3:1-3:2) "CR")
275 (softbreak (3:3-3:3))
276 (text (4:1-4:4) "end.")
277 ])
278 ])
279 );
280 }
281
282 #[test]
283 fn hex_entity_digit_limit() {
284 // 6 hex digits: valid
285 html("&#x000041;\n", "<p>A</p>\n");
286
287 // 7 hex digits: invalid, should be literal
288 html("&#x0000041;\n", "<p>&amp;#x0000041;</p>\n");
289
290 // 7 decimal digits: valid (decimal 100 = 'd')
291 html("&#0000100;\n", "<p>d</p>\n");
292 }