| 1 |
use std::sync::Arc; |
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn pointy_brace_open() { |
| 7 |
html("<!-", "<p><!-</p>\n"); |
| 8 |
} |
| 9 |
|
| 10 |
#[test] |
| 11 |
fn tasklist() { |
| 12 |
html_opts!( |
| 13 |
[extension.tasklist, parse.relaxed_tasklist_matching], |
| 14 |
"* [*]", |
| 15 |
"<ul>\n<li><input type=\"checkbox\" checked=\"\" disabled=\"\" /> </li>\n</ul>\n", |
| 16 |
); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn tasklist_with_classes() { |
| 21 |
html_opts!( |
| 22 |
[ |
| 23 |
extension.tasklist, |
| 24 |
render.tasklist_classes, |
| 25 |
parse.relaxed_tasklist_matching |
| 26 |
], |
| 27 |
"* [*]", |
| 28 |
"<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" checked=\"\" disabled=\"\" /> </li>\n</ul>\n", |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn table_nul() { |
| 34 |
html_opts!( |
| 35 |
[extension.table], |
| 36 |
"\0|.\n-|-\nZ", |
| 37 |
r##"<table> |
| 38 |
<thead> |
| 39 |
<tr> |
| 40 |
<th>�</th> |
| 41 |
<th>.</th> |
| 42 |
</tr> |
| 43 |
</thead> |
| 44 |
<tbody> |
| 45 |
<tr> |
| 46 |
<td>Z</td> |
| 47 |
<td></td> |
| 48 |
</tr> |
| 49 |
</tbody> |
| 50 |
</table> |
| 51 |
"##, |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
#[test] |
| 56 |
fn footnote_def() { |
| 57 |
html_opts!( |
| 58 |
[ |
| 59 |
extension.autolink, |
| 60 |
extension.footnotes, |
| 61 |
render.sourcepos, |
| 62 |
render.hardbreaks |
| 63 |
], |
| 64 |
"\u{15}\u{b}\r[^ ]:", |
| 65 |
"<p data-sourcepos=\"1:1-2:5\">\u{15}\u{b}<br data-sourcepos=\"1:3-1:3\" />\n[^ ]:</p>\n", |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
fn line_end() { |
| 71 |
html("\u{2}\n\\\n\t-", "<p>\u{2}\n<br />\n-</p>\n"); |
| 72 |
} |
| 73 |
|
| 74 |
#[test] |
| 75 |
fn bracket_match() { |
| 76 |
html("[;\0V\n]::g\n[;\0V\n]", "<p><a href=\":g\">;�V\n</a></p>\n"); |
| 77 |
} |
| 78 |
|
| 79 |
#[test] |
| 80 |
fn trailing_hyphen() { |
| 81 |
assert_ast_match!( |
| 82 |
[extension.autolink, parse.smart], |
| 83 |
"[email protected]", |
| 84 |
(document (1:1-1:5) [ |
| 85 |
(paragraph (1:1-1:5) [ |
| 86 |
(text (1:1-1:5) "[email protected]") |
| 87 |
]) |
| 88 |
]) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
#[test] |
| 93 |
fn trailing_smart_endash_matches() { |
| 94 |
assert_ast_match!( |
| 95 |
[extension.autolink, parse.smart], |
| 96 |
"--\n" |
| 97 |
"--([email protected]\n", |
| 98 |
(document (1:1-2:9) [ |
| 99 |
(paragraph (1:1-2:9) [ |
| 100 |
(text (1:1-1:2) "–") // en-dash |
| 101 |
(softbreak (1:3-1:3)) |
| 102 |
(text (2:1-2:3) "–(") // en-dash |
| 103 |
(link (2:4-2:7) "mailto:[email protected]" [ |
| 104 |
(text (2:4-2:7) "[email protected]") |
| 105 |
]) |
| 106 |
(text (2:8-2:9) "–") // en-dash |
| 107 |
]) |
| 108 |
]) |
| 109 |
); |
| 110 |
} |
| 111 |
|
| 112 |
#[test] |
| 113 |
fn trailing_endash_matches() { |
| 114 |
assert_ast_match!( |
| 115 |
[extension.autolink], |
| 116 |
"–\n" |
| 117 |
"–([email protected]–\n", |
| 118 |
(document (1:1-2:11) [ |
| 119 |
(paragraph (1:1-2:11) [ |
| 120 |
(text (1:1-1:3) "–") // en-dash |
| 121 |
(softbreak (1:4-1:4)) |
| 122 |
(text (2:1-2:4) "–(") // en-dash |
| 123 |
(link (2:5-2:8) "mailto:[email protected]" [ |
| 124 |
(text (2:5-2:8) "[email protected]") |
| 125 |
]) |
| 126 |
(text (2:9-2:11) "–") // en-dash |
| 127 |
]) |
| 128 |
]) |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
#[test] |
| 133 |
fn no_empty_text_before_email() { |
| 134 |
assert_ast_match!( |
| 135 |
[extension.autolink], |
| 136 |
"[email protected]\n", |
| 137 |
(document (1:1-1:5) [ |
| 138 |
(paragraph (1:1-1:5) [ |
| 139 |
(link (1:1-1:5) "mailto:[email protected]" [ |
| 140 |
(text (1:1-1:5) "[email protected]") |
| 141 |
]) |
| 142 |
]) |
| 143 |
]) |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
#[test] |
| 148 |
fn smart_sourcepos() { |
| 149 |
assert_ast_match!( |
| 150 |
[parse.smart], |
| 151 |
": _--_ **---**\n\n" |
| 152 |
// As above, but entered directly. |
| 153 |
": _–_ **—**\n", |
| 154 |
(document (1:1-3:15) [ |
| 155 |
(paragraph (1:1-1:14) [ |
| 156 |
(text (1:1-1:2) ": ") |
| 157 |
(emph (1:3-1:6) [ |
| 158 |
(text (1:4-1:5) "–") // en-dash |
| 159 |
]) |
| 160 |
(text (1:7-1:7) " ") |
| 161 |
(strong (1:8-1:14) [ |
| 162 |
(text (1:10-1:12) "—") // em-dash |
| 163 |
]) |
| 164 |
]) |
| 165 |
(paragraph (3:1-3:15) [ |
| 166 |
(text (3:1-3:2) ": ") |
| 167 |
(emph (3:3-3:7) [ |
| 168 |
(text (3:4-3:6) "–") // en-dash; 3 bytes in input |
| 169 |
]) |
| 170 |
(text (3:8-3:8) " ") |
| 171 |
(strong (3:9-3:15) [ |
| 172 |
(text (3:11-3:13) "—") // em-dash; (still) 3 bytes |
| 173 |
]) |
| 174 |
]) |
| 175 |
]) |
| 176 |
); |
| 177 |
} |
| 178 |
|
| 179 |
#[test] |
| 180 |
fn linebreak_sourcepos() { |
| 181 |
assert_ast_match!( |
| 182 |
[], |
| 183 |
"a\\\n" |
| 184 |
"b\n", |
| 185 |
(document (1:1-2:1) [ |
| 186 |
(paragraph (1:1-2:1) [ |
| 187 |
(text (1:1-1:1) "a") |
| 188 |
(linebreak (1:2-1:3)) |
| 189 |
(text (2:1-2:1) "b") |
| 190 |
]) |
| 191 |
]) |
| 192 |
); |
| 193 |
} |
| 194 |
|
| 195 |
#[test] |
| 196 |
fn echaw() { |
| 197 |
assert_ast_match!( |
| 198 |
[extension.autolink], |
| 199 |
"<[email protected]<[email protected]", |
| 200 |
(document (1:1-1:11) [ |
| 201 |
(paragraph (1:1-1:11) [ |
| 202 |
(text (1:1-1:1) "<") |
| 203 |
(link (1:2-1:5) "mailto:[email protected]" [ |
| 204 |
(text (1:2-1:5) "[email protected]") |
| 205 |
]) |
| 206 |
(text (1:6-1:6) "<") |
| 207 |
(link (1:7-1:11) "mailto:[email protected]" [ |
| 208 |
(text (1:7-1:11) "[email protected]") |
| 209 |
]) |
| 210 |
]) |
| 211 |
]) |
| 212 |
); |
| 213 |
} |
| 214 |
|
| 215 |
#[test] |
| 216 |
fn echaw2() { |
| 217 |
assert_ast_match!( |
| 218 |
[extension.autolink, parse.smart], |
| 219 |
":[email protected]'[email protected]", |
| 220 |
(document (1:1-1:10) [ |
| 221 |
(paragraph (1:1-1:10) [ |
| 222 |
(text (1:1-1:1) ":") |
| 223 |
(link (1:2-1:5) "mailto:[email protected]" [ |
| 224 |
(text (1:2-1:5) "[email protected]") |
| 225 |
]) |
| 226 |
(text (1:6-1:6) "’") |
| 227 |
(link (1:7-1:10) "mailto:[email protected]" [ |
| 228 |
(text (1:7-1:10) "[email protected]") |
| 229 |
]) |
| 230 |
]) |
| 231 |
]) |
| 232 |
); |
| 233 |
} |
| 234 |
|
| 235 |
#[test] |
| 236 |
fn echaw3() { |
| 237 |
assert_ast_match!( |
| 238 |
[extension.autolink, parse.smart], |
| 239 |
"[email protected]\0\t\r" |
| 240 |
"z \n" |
| 241 |
" [email protected]", |
| 242 |
(document (1:1-3:5) [ |
| 243 |
(paragraph (1:1-3:5) [ |
| 244 |
(link (1:1-1:4) "mailto:[email protected]" [ |
| 245 |
(text (1:1-1:4) "[email protected]") |
| 246 |
]) |
| 247 |
(text (1:5-1:5) "\x00") |
| 248 |
// !! Spaces at EOL are trimmed. |
| 249 |
// See parser::inlines::Subject::parse_inline's final case. |
| 250 |
(softbreak (1:7-1:7)) |
| 251 |
(text (2:1-2:1) "z") |
| 252 |
(linebreak (2:2-2:4)) |
| 253 |
(link (3:2-3:5) "mailto:[email protected]" [ |
| 254 |
(text (3:2-3:5) "[email protected]") |
| 255 |
]) |
| 256 |
]) |
| 257 |
]) |
| 258 |
); |
| 259 |
} |
| 260 |
|
| 261 |
#[test] |
| 262 |
fn echaw4() { |
| 263 |
// _ resolves to a plain ASCII underscore "_". |
| 264 |
assert_ast_match!( |
| 265 |
[extension.autolink, parse.smart], |
| 266 |
"-@_.e--", |
| 267 |
(document (1:1-1:16) [ |
| 268 |
(paragraph (1:1-1:16) [ |
| 269 |
(link (1:1-1:14) "mailto:-@_.e" [ |
| 270 |
(text (1:1-1:14) "-@_.e") |
| 271 |
]) |
| 272 |
(text (1:15-1:16) "–") // en-dash |
| 273 |
]) |
| 274 |
]) |
| 275 |
); |
| 276 |
} |
| 277 |
|
| 278 |
#[test] |
| 279 |
fn echaw5() { |
| 280 |
assert_ast_match!( |
| 281 |
[], |
| 282 |
"_#[email protected]", |
| 283 |
(document (1:1-1:9) [ |
| 284 |
(paragraph (1:1-1:9) [ |
| 285 |
(emph (1:1-1:3) [ |
| 286 |
(text (1:2-1:2) "#") |
| 287 |
]) |
| 288 |
(text (1:4-1:9) "[email protected]") |
| 289 |
]) |
| 290 |
]) |
| 291 |
); |
| 292 |
} |
| 293 |
|
| 294 |
#[test] |
| 295 |
fn echaw6() { |
| 296 |
assert_ast_match!( |
| 297 |
[extension.autolink], |
| 298 |
"_#[email protected]", |
| 299 |
(document (1:1-1:9) [ |
| 300 |
(paragraph (1:1-1:9) [ |
| 301 |
(emph (1:1-1:3) [ |
| 302 |
(text (1:2-1:2) "#") |
| 303 |
]) |
| 304 |
(link (1:4-1:9) "mailto:[email protected]" [ |
| 305 |
(text (1:4-1:9) "[email protected]") |
| 306 |
]) |
| 307 |
]) |
| 308 |
]) |
| 309 |
); |
| 310 |
} |
| 311 |
|
| 312 |
#[test] |
| 313 |
fn echaw7() { |
| 314 |
assert_ast_match!( |
| 315 |
[extension.autolink], |
| 316 |
"A[email protected]", |
| 317 |
(document (1:1-1:10) [ |
| 318 |
(paragraph (1:1-1:10) [ |
| 319 |
(link (1:1-1:10) "mailto:[email protected]" [ |
| 320 |
(text (1:1-1:10) "[email protected]") |
| 321 |
]) |
| 322 |
]) |
| 323 |
]) |
| 324 |
); |
| 325 |
} |
| 326 |
|
| 327 |
#[test] |
| 328 |
fn echaw8() { |
| 329 |
// fuzz/artifacts/all_options/minimized-from-57c3eaf5e03b3fd7fa971b0db6143ee3c21a7452 |
| 330 |
assert_ast_match!( |
| 331 |
[extension.autolink, extension.tasklist], |
| 332 |
"- [x] 𝔛-<[email protected]", |
| 333 |
(document (1:1-1:17) [ |
| 334 |
(list (1:1-1:17) [ |
| 335 |
(taskitem (1:1-1:17) [ |
| 336 |
(paragraph (1:7-1:17) [ |
| 337 |
(text (1:7-1:13) "𝔛-<") |
| 338 |
(link (1:14-1:17) "mailto:[email protected]" [ |
| 339 |
(text (1:14-1:17) "[email protected]") |
| 340 |
]) |
| 341 |
]) |
| 342 |
]) |
| 343 |
]) |
| 344 |
]), |
| 345 |
); |
| 346 |
} |
| 347 |
|
| 348 |
#[test] |
| 349 |
fn echaw9() { |
| 350 |
// fuzz/artifacts/all_options/minimized-from-8a07a44ba1f971ec39d0c14d377c78c2535c6fd5 |
| 351 |
assert_ast_match!( |
| 352 |
[extension.tasklist], |
| 353 |
"-\t[ ]
", |
| 354 |
(document (1:1-1:14) [ |
| 355 |
(list (1:1-1:14) [ |
| 356 |
(taskitem (1:1-1:14)) |
| 357 |
]) |
| 358 |
]), |
| 359 |
); |
| 360 |
} |
| 361 |
|
| 362 |
#[test] |
| 363 |
fn relaxed_autolink_email_in_footnote() { |
| 364 |
assert_ast_match!( |
| 365 |
[ |
| 366 |
extension.autolink, |
| 367 |
extension.footnotes, |
| 368 |
parse.relaxed_autolinks |
| 369 |
], |
| 370 |
"[^[email protected]\nA]:\n", |
| 371 |
(document (1:1-2:3) [ |
| 372 |
(paragraph (1:1-2:3) [ |
| 373 |
(text (1:1-1:2) "[^") |
| 374 |
(link (1:3-1:7) "mailto:[email protected]" [ |
| 375 |
(text (1:3-1:7) "[email protected]") |
| 376 |
]) |
| 377 |
(softbreak (1:8-1:8)) |
| 378 |
(text (2:1-2:3) "A]:") |
| 379 |
]) |
| 380 |
]), |
| 381 |
); |
| 382 |
} |
| 383 |
|
| 384 |
#[test] |
| 385 |
fn nul_in_link() { |
| 386 |
html("", "<p><img src=\"#%EF%BF%BD\" alt=\"\" /></p>\n"); |
| 387 |
} |
| 388 |
|
| 389 |
#[test] |
| 390 |
fn truncate2() { |
| 391 |
html("~~~ ú", "<pre><code class=\"language-ú\"></code></pre>\n"); |
| 392 |
} |
| 393 |
|
| 394 |
#[test] |
| 395 |
fn commonmark_big_backtick_inline_code() { |
| 396 |
commonmark( |
| 397 |
"\0` ```````````````````````````````` <`", |
| 398 |
"�` ```````````````````````````````` < `\n", |
| 399 |
None, |
| 400 |
); |
| 401 |
} |
| 402 |
|
| 403 |
#[test] |
| 404 |
fn commonmark_table_of_fun() { |
| 405 |
let mut opts = Options::default(); |
| 406 |
opts.extension.table = true; |
| 407 |
opts.extension.spoiler = true; |
| 408 |
opts.render.experimental_minimize_commonmark = true; |
| 409 |
commonmark( |
| 410 |
"\0I|-|\r-|-|\r\u{c}||~|||", |
| 411 |
"| �I | - |\n| --- | --- |\n| \\||~\\|| | |\n", |
| 412 |
Some(&opts), |
| 413 |
); |
| 414 |
} |
| 415 |
|
| 416 |
#[test] |
| 417 |
fn tasklist_and_escapes_do_not_play() { |
| 418 |
assert_ast_match!( |
| 419 |
[], |
| 420 |
"\\!", |
| 421 |
(document (1:1-1:2) [ |
| 422 |
(paragraph (1:1-1:2) [ |
| 423 |
(text (1:2-1:2) "!") |
| 424 |
]) |
| 425 |
]) |
| 426 |
); |
| 427 |
|
| 428 |
assert_ast_match!( |
| 429 |
[parse.escaped_char_spans], |
| 430 |
"\\!", |
| 431 |
(document (1:1-1:2) [ |
| 432 |
(paragraph (1:1-1:2) [ |
| 433 |
(escaped (1:1-1:2) [ |
| 434 |
(text (1:2-1:2) "!") |
| 435 |
]) |
| 436 |
]) |
| 437 |
]) |
| 438 |
); |
| 439 |
|
| 440 |
assert_ast_match!( |
| 441 |
[], |
| 442 |
"+ \\[x]", |
| 443 |
(document (1:1-1:6) [ |
| 444 |
(list (1:1-1:6) [ |
| 445 |
(item (1:1-1:6) [ |
| 446 |
(paragraph (1:3-1:6) [ |
| 447 |
(text (1:4-1:6) "[x]") |
| 448 |
]) |
| 449 |
]) |
| 450 |
]) |
| 451 |
]) |
| 452 |
); |
| 453 |
|
| 454 |
assert_ast_match!( |
| 455 |
[parse.escaped_char_spans], |
| 456 |
"+ \\[x]", |
| 457 |
(document (1:1-1:6) [ |
| 458 |
(list (1:1-1:6) [ |
| 459 |
(item (1:1-1:6) [ |
| 460 |
(paragraph (1:3-1:6) [ |
| 461 |
(escaped (1:3-1:4) [ |
| 462 |
(text (1:4-1:4) "[") |
| 463 |
]) |
| 464 |
(text (1:5-1:6) "x]") |
| 465 |
]) |
| 466 |
]) |
| 467 |
]) |
| 468 |
]) |
| 469 |
); |
| 470 |
|
| 471 |
assert_ast_match!( |
| 472 |
[extension.tasklist, parse.relaxed_tasklist_matching], |
| 473 |
"+ \\[\\:]", |
| 474 |
(document (1:1-1:7) [ |
| 475 |
(list (1:1-1:7) [ |
| 476 |
(item (1:1-1:7) [ |
| 477 |
(paragraph (1:3-1:7) [ |
| 478 |
(text (1:4-1:7) "[:]") |
| 479 |
]) |
| 480 |
]) |
| 481 |
]) |
| 482 |
]) |
| 483 |
); |
| 484 |
|
| 485 |
assert_ast_match!( |
| 486 |
[extension.tasklist, parse.relaxed_tasklist_matching, parse.escaped_char_spans], |
| 487 |
"+ \\[\\:]", |
| 488 |
(document (1:1-1:7) [ |
| 489 |
(list (1:1-1:7) [ |
| 490 |
(item (1:1-1:7) [ |
| 491 |
(paragraph (1:3-1:7) [ |
| 492 |
(escaped (1:3-1:4) [ |
| 493 |
(text (1:4-1:4) "[") |
| 494 |
]) |
| 495 |
(escaped (1:5-1:6) [ |
| 496 |
(text (1:6-1:6) ":") |
| 497 |
]) |
| 498 |
(text (1:7-1:7) "]") |
| 499 |
]) |
| 500 |
]) |
| 501 |
]) |
| 502 |
]) |
| 503 |
); |
| 504 |
} |
| 505 |
|
| 506 |
#[test] |
| 507 |
fn dont_try_this_at_home() { |
| 508 |
assert_ast_match!( |
| 509 |
[extension.alerts, extension.table, parse.ignore_setext], |
| 510 |
"\u{3}\n--\nT", |
| 511 |
(document (1:1-3:1) [ |
| 512 |
(table (1:1-3:1) [ |
| 513 |
(table_row (1:1-1:1) [ |
| 514 |
(table_cell (1:1-1:1) [ |
| 515 |
(text (1:1-1:1) "\u{3}") |
| 516 |
]) |
| 517 |
]) |
| 518 |
(table_row (3:1-3:1) [ |
| 519 |
(table_cell (3:1-3:1) [ |
| 520 |
(text (3:1-3:1) "T") |
| 521 |
]) |
| 522 |
]) |
| 523 |
]) |
| 524 |
]) |
| 525 |
); |
| 526 |
} |
| 527 |
|
| 528 |
#[test] |
| 529 |
fn cargo_run_no_cargo_road() { |
| 530 |
assert_ast_match!( |
| 531 |
[], |
| 532 |
"\t", |
| 533 |
(document (1:1-1:1)) |
| 534 |
); |
| 535 |
} |
| 536 |
|
| 537 |
#[test] |
| 538 |
fn oye_siri_prende_las_luces() { |
| 539 |
assert_ast_match!( |
| 540 |
[], |
| 541 |
"* ", |
| 542 |
(document (1:1-1:2) [ |
| 543 |
(list (1:1-1:2) [ |
| 544 |
(item (1:1-1:2)) |
| 545 |
]) |
| 546 |
]) |
| 547 |
); |
| 548 |
} |
| 549 |
|
| 550 |
#[test] |
| 551 |
fn cursed_lands() { |
| 552 |
let mut opts = Options::default(); |
| 553 |
opts.extension.autolink = true; |
| 554 |
opts.extension.footnotes = true; |
| 555 |
opts.parse.smart = true; |
| 556 |
opts.parse.relaxed_autolinks = true; |
| 557 |
|
| 558 |
markdown_to_html("[^[email protected]]", &opts); |
| 559 |
} |
| 560 |
|
| 561 |
#[test] |
| 562 |
fn inquisitor() { |
| 563 |
let mut opts = Options::default(); |
| 564 |
opts.parse.broken_link_callback = Some(Arc::new(|link_ref: options::BrokenLinkReference| { |
| 565 |
Some(ResolvedReference { |
| 566 |
url: link_ref.normalized.to_string(), |
| 567 |
title: link_ref.original.to_string(), |
| 568 |
}) |
| 569 |
})); |
| 570 |
opts.render.width = 45; |
| 571 |
|
| 572 |
markdown_to_commonmark("\0\0\0\0\0\0[\\`\r\n;][ww=\\-", &opts); |
| 573 |
} |