diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-13 10:40:01 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-13 10:40:01 +0200 |
commit | ec2d1bfb4232178fb3a6cba36f138bc6efbbf34a (patch) | |
tree | 2da4be3be22c2324c48cb17133b3f4b26b9139d2 /tests/link_reference.rs | |
parent | 861af95c119721e814460fa7dc32bd3d74b38484 (diff) | |
download | markdown-rs-ec2d1bfb4232178fb3a6cba36f138bc6efbbf34a.tar.gz markdown-rs-ec2d1bfb4232178fb3a6cba36f138bc6efbbf34a.tar.bz2 markdown-rs-ec2d1bfb4232178fb3a6cba36f138bc6efbbf34a.zip |
Rename crate to `markdown`
Diffstat (limited to 'tests/link_reference.rs')
-rw-r--r-- | tests/link_reference.rs | 128 |
1 files changed, 63 insertions, 65 deletions
diff --git a/tests/link_reference.rs b/tests/link_reference.rs index 5e00dab..3769fbc 100644 --- a/tests/link_reference.rs +++ b/tests/link_reference.rs @@ -1,7 +1,7 @@ -extern crate micromark; -use micromark::{ +extern crate markdown; +use markdown::{ mdast::{Definition, LinkReference, Node, Paragraph, ReferenceKind, Root, Text}, - micromark, micromark_to_mdast, micromark_with_options, + to_html, to_html_with_options, to_mdast, unist::Position, CompileOptions, Constructs, Options, ParseOptions, }; @@ -19,277 +19,277 @@ fn link_reference() -> Result<(), String> { }; assert_eq!( - micromark("[bar]: /url \"title\"\n\n[foo][bar]"), + to_html("[bar]: /url \"title\"\n\n[foo][bar]"), "<p><a href=\"/url\" title=\"title\">foo</a></p>", "should support link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[link [foo [bar]]][ref]"), + to_html("[ref]: /uri\n\n[link [foo [bar]]][ref]"), "<p><a href=\"/uri\">link [foo [bar]]</a></p>", "should support balanced brackets in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[link \\[bar][ref]"), + to_html("[ref]: /uri\n\n[link \\[bar][ref]"), "<p><a href=\"/uri\">link [bar</a></p>", "should support escaped brackets in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[link *foo **bar** `#`*][ref]"), + to_html("[ref]: /uri\n\n[link *foo **bar** `#`*][ref]"), "<p><a href=\"/uri\">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>", "should support content in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[![moon](moon.jpg)][ref]"), + to_html("[ref]: /uri\n\n[![moon](moon.jpg)][ref]"), "<p><a href=\"/uri\"><img src=\"moon.jpg\" alt=\"moon\" /></a></p>", "should support images in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[foo [bar](/uri)][ref]"), + to_html("[ref]: /uri\n\n[foo [bar](/uri)][ref]"), "<p>[foo <a href=\"/uri\">bar</a>]<a href=\"/uri\">ref</a></p>", "should not support links in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[foo *bar [baz][ref]*][ref]"), + to_html("[ref]: /uri\n\n[foo *bar [baz][ref]*][ref]"), "<p>[foo <em>bar <a href=\"/uri\">baz</a></em>]<a href=\"/uri\">ref</a></p>", "should not support deep links in link references" ); assert_eq!( - micromark("[ref]: /uri\n\n*[foo*][ref]"), + to_html("[ref]: /uri\n\n*[foo*][ref]"), "<p>*<a href=\"/uri\">foo*</a></p>", "should prefer link references over emphasis (1)" ); assert_eq!( - micromark("[ref]: /uri\n\n[foo *bar][ref]"), + to_html("[ref]: /uri\n\n[foo *bar][ref]"), "<p><a href=\"/uri\">foo *bar</a></p>", "should prefer link references over emphasis (2)" ); assert_eq!( - micromark_with_options("[ref]: /uri\n\n[foo <bar attr=\"][ref]\">", &danger)?, + to_html_with_options("[ref]: /uri\n\n[foo <bar attr=\"][ref]\">", &danger)?, "<p>[foo <bar attr=\"][ref]\"></p>", "should prefer HTML over link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[foo`][ref]`"), + to_html("[ref]: /uri\n\n[foo`][ref]`"), "<p>[foo<code>][ref]</code></p>", "should prefer code over link references" ); assert_eq!( - micromark("[ref]: /uri\n\n[foo<http://example.com/?search=][ref]>"), + to_html("[ref]: /uri\n\n[foo<http://example.com/?search=][ref]>"), "<p>[foo<a href=\"http://example.com/?search=%5D%5Bref%5D\">http://example.com/?search=][ref]</a></p>", "should prefer autolinks over link references" ); assert_eq!( - micromark("[bar]: /url \"title\"\n\n[foo][BaR]"), + to_html("[bar]: /url \"title\"\n\n[foo][BaR]"), "<p><a href=\"/url\" title=\"title\">foo</a></p>", "should match references to definitions case-insensitively" ); assert_eq!( - micromark("[ТОЛПОЙ]: /url\n\n[Толпой][Толпой] is a Russian word."), + to_html("[ТОЛПОЙ]: /url\n\n[Толпой][Толпой] is a Russian word."), "<p><a href=\"/url\">Толпой</a> is a Russian word.</p>", "should match references to definitions w/ unicode case-folding" ); assert_eq!( - micromark("[Foo\n bar]: /url\n\n[Baz][Foo bar]"), + to_html("[Foo\n bar]: /url\n\n[Baz][Foo bar]"), "<p><a href=\"/url\">Baz</a></p>", "should match references to definitions w/ collapsing" ); assert_eq!( - micromark("[bar]: /url \"title\"\n\n[foo] [bar]"), + to_html("[bar]: /url \"title\"\n\n[foo] [bar]"), "<p>[foo] <a href=\"/url\" title=\"title\">bar</a></p>", "should not support whitespace between label and reference (1)" ); assert_eq!( - micromark("[bar]: /url \"title\"\n\n[foo]\n[bar]"), + to_html("[bar]: /url \"title\"\n\n[foo]\n[bar]"), "<p>[foo]\n<a href=\"/url\" title=\"title\">bar</a></p>", "should not support whitespace between label and reference (2)" ); assert_eq!( - micromark("[foo]: /url1\n\n[foo]: /url2\n\n[bar][foo]"), + to_html("[foo]: /url1\n\n[foo]: /url2\n\n[bar][foo]"), "<p><a href=\"/url1\">bar</a></p>", "should prefer earlier definitions" ); assert_eq!( - micromark("[foo!]: /url\n\n[bar][foo\\!]"), + to_html("[foo!]: /url\n\n[bar][foo\\!]"), "<p>[bar][foo!]</p>", "should not match references to definitions w/ escapes" ); assert_eq!( - micromark("[ref[]: /uri\n\n[foo][ref[]"), + to_html("[ref[]: /uri\n\n[foo][ref[]"), "<p>[ref[]: /uri</p>\n<p>[foo][ref[]</p>", "should not support references w/ brackets (1)" ); assert_eq!( - micromark("[ref[bar]]: /uri\n\n[foo][ref[bar]]"), + to_html("[ref[bar]]: /uri\n\n[foo][ref[bar]]"), "<p>[ref[bar]]: /uri</p>\n<p>[foo][ref[bar]]</p>", "should not support references w/ brackets (2)" ); assert_eq!( - micromark("[[[foo]]]: /url\n\n[[[foo]]]"), + to_html("[[[foo]]]: /url\n\n[[[foo]]]"), "<p>[[[foo]]]: /url</p>\n<p>[[[foo]]]</p>", "should not support references w/ brackets (3)" ); assert_eq!( - micromark("[ref\\[]: /uri\n\n[foo][ref\\[]"), + to_html("[ref\\[]: /uri\n\n[foo][ref\\[]"), "<p><a href=\"/uri\">foo</a></p>", "should match references to definitions w/ matching escapes" ); assert_eq!( - micromark("[bar\\\\]: /uri\n\n[bar\\\\]"), + to_html("[bar\\\\]: /uri\n\n[bar\\\\]"), "<p><a href=\"/uri\">bar\\</a></p>", "should support escapes" ); assert_eq!( - micromark("[]: /uri\n\n[]"), + to_html("[]: /uri\n\n[]"), "<p>[]: /uri</p>\n<p>[]</p>", "should not support empty references" ); assert_eq!( - micromark("[\n ]: /uri\n\n[\n ]"), + to_html("[\n ]: /uri\n\n[\n ]"), "<p>[\n]: /uri</p>\n<p>[\n]</p>", "should not support blank references" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[foo][]"), + to_html("[foo]: /url \"title\"\n\n[foo][]"), "<p><a href=\"/url\" title=\"title\">foo</a></p>", "should support collaped references" ); assert_eq!( - micromark("[*foo* bar]: /url \"title\"\n\n[*foo* bar][]"), + to_html("[*foo* bar]: /url \"title\"\n\n[*foo* bar][]"), "<p><a href=\"/url\" title=\"title\"><em>foo</em> bar</a></p>", "should support content in collaped references" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[Foo][]"), + to_html("[foo]: /url \"title\"\n\n[Foo][]"), "<p><a href=\"/url\" title=\"title\">Foo</a></p>", "should match references to definitions case-insensitively" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[foo] \n[]"), + to_html("[foo]: /url \"title\"\n\n[foo] \n[]"), "<p><a href=\"/url\" title=\"title\">foo</a>\n[]</p>", "should not support whitespace between label and collaped reference" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[foo]"), + to_html("[foo]: /url \"title\"\n\n[foo]"), "<p><a href=\"/url\" title=\"title\">foo</a></p>", "should support shortcut references" ); assert_eq!( - micromark("[*foo* bar]: /url \"title\"\n\n[*foo* bar]"), + to_html("[*foo* bar]: /url \"title\"\n\n[*foo* bar]"), "<p><a href=\"/url\" title=\"title\"><em>foo</em> bar</a></p>", "should support content in shortcut references (1)" ); assert_eq!( - micromark("[*foo* bar]: /url \"title\"\n\n[[*foo* bar]]"), + to_html("[*foo* bar]: /url \"title\"\n\n[[*foo* bar]]"), "<p>[<a href=\"/url\" title=\"title\"><em>foo</em> bar</a>]</p>", "should support content in shortcut references (2)" ); assert_eq!( - micromark("[foo]: /url\n\n[[bar [foo]"), + to_html("[foo]: /url\n\n[[bar [foo]"), "<p>[[bar <a href=\"/url\">foo</a></p>", "should support content in shortcut references (3)" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[Foo]"), + to_html("[foo]: /url \"title\"\n\n[Foo]"), "<p><a href=\"/url\" title=\"title\">Foo</a></p>", "should match shortcut references to definitions case-insensitively" ); assert_eq!( - micromark("[foo]: /url\n\n[foo] bar"), + to_html("[foo]: /url\n\n[foo] bar"), "<p><a href=\"/url\">foo</a> bar</p>", "should support whitespace after a shortcut reference" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n\\[foo]"), + to_html("[foo]: /url \"title\"\n\n\\[foo]"), "<p>[foo]</p>", "should “support” an escaped shortcut reference" ); assert_eq!( - micromark("[foo*]: /url\n\n*[foo*]"), + to_html("[foo*]: /url\n\n*[foo*]"), "<p>*<a href=\"/url\">foo*</a></p>", "should prefer shortcut references over emphasis" ); assert_eq!( - micromark("[foo]: /url1\n[bar]: /url2\n\n[foo][bar]"), + to_html("[foo]: /url1\n[bar]: /url2\n\n[foo][bar]"), "<p><a href=\"/url2\">foo</a></p>", "should prefer full references over shortcut references" ); assert_eq!( - micromark("[foo]: /url1\n\n[foo][]"), + to_html("[foo]: /url1\n\n[foo][]"), "<p><a href=\"/url1\">foo</a></p>", "should prefer collapsed references over shortcut references" ); assert_eq!( - micromark("[foo]: /url\n\n[foo]()"), + to_html("[foo]: /url\n\n[foo]()"), "<p><a href=\"\">foo</a></p>", "should prefer resources over shortcut references (1)" ); assert_eq!( - micromark("[foo]: /url \"title\"\n\n[foo]()"), + to_html("[foo]: /url \"title\"\n\n[foo]()"), "<p><a href=\"\">foo</a></p>", "should prefer resources over shortcut references (2)" ); assert_eq!( - micromark("[foo]: /url1\n\n[foo](not a link)"), + to_html("[foo]: /url1\n\n[foo](not a link)"), "<p><a href=\"/url1\">foo</a>(not a link)</p>", "should support shortcut references when followed by nonconforming resources" ); assert_eq!( - micromark("[baz]: /url\n\n[foo][bar][baz]"), + to_html("[baz]: /url\n\n[foo][bar][baz]"), "<p>[foo]<a href=\"/url\">bar</a></p>", "stable/unstable (1)" ); assert_eq!( - micromark("[baz]: /url1\n[bar]: /url2\n\n[foo][bar][baz]"), + to_html("[baz]: /url1\n[bar]: /url2\n\n[foo][bar][baz]"), "<p><a href=\"/url2\">foo</a><a href=\"/url1\">baz</a></p>", "stable/unstable (2)" ); assert_eq!( - micromark("[baz]: /url1\n[foo]: /url2\n\n[foo][bar][baz]"), + to_html("[baz]: /url1\n[foo]: /url2\n\n[foo][bar][baz]"), "<p>[foo]<a href=\"/url1\">bar</a></p>", "stable/unstable (3)" ); @@ -298,52 +298,50 @@ fn link_reference() -> Result<(), String> { // This matches most implimentations, but is not strictly according to spec. // See: <https://github.com/commonmark/commonmark-spec/issues/653> assert_eq!( - micromark("[x]: /url\n\n[x][ ], [x][\t], [x][\n], [x][]"), + to_html("[x]: /url\n\n[x][ ], [x][\t], [x][\n], [x][]"), "<p>[x][ ], [x][\t], [x][\n], <a href=\"/url\">x</a></p>", "should not support whitespace-only full references" ); // See also: <https://github.com/commonmark/commonmark-spec/issues/616> assert_eq!( - micromark("[+]: example.com\n[\\;]: example.com\n\nWill it link? [\\+], [;]"), + to_html("[+]: example.com\n[\\;]: example.com\n\nWill it link? [\\+], [;]"), "<p>Will it link? [+], [;]</p>", "should not support mismatched character escapes in shortcuts" ); assert_eq!( - micromark("[©]: example.com\n[&]: example.com\n\nWill it link? [©], [&]"), + to_html("[©]: example.com\n[&]: example.com\n\nWill it link? [©], [&]"), "<p>Will it link? [©], [&]</p>", "should not support mismatched character references in shortcuts" ); assert_eq!( - micromark("[+]: example.com\n[\\;]: example.com\n\nWill it link? [\\+][], [;][]"), + to_html("[+]: example.com\n[\\;]: example.com\n\nWill it link? [\\+][], [;][]"), "<p>Will it link? [+][], [;][]</p>", "should not support mismatched character escapes in collapsed" ); assert_eq!( - micromark("[©]: example.com\n[&]: example.com\n\nWill it link? [©][], [&][]"), + to_html("[©]: example.com\n[&]: example.com\n\nWill it link? [©][], [&][]"), "<p>Will it link? [©][], [&][]</p>", "should not support mismatched character references in collapsed" ); assert_eq!( - micromark("[+]: example.com\n[\\;]: example.com\n\nWill it link? [a][ \\+ ], [b][ ; ]"), + to_html("[+]: example.com\n[\\;]: example.com\n\nWill it link? [a][ \\+ ], [b][ ; ]"), "<p>Will it link? [a][ + ], [b][ ; ]</p>", "should not support mismatched character escapes in fulls" ); assert_eq!( - micromark( - "[©]: example.com\n[&]: example.com\n\nWill it link? [a][ © ], [b][ & ]" - ), + to_html("[©]: example.com\n[&]: example.com\n\nWill it link? [a][ © ], [b][ & ]"), "<p>Will it link? [a][ © ], [b][ & ]</p>", "should not support mismatched character references in fulls" ); assert_eq!( - micromark( + to_html( "[*f*][] [;][] [\\;][] @@ -375,25 +373,25 @@ fn link_reference() -> Result<(), String> { let max = "x".repeat(999); assert_eq!( - micromark(format!("[{}]: a\n[y][{}]", max, max).as_str()), + to_html(format!("[{}]: a\n[y][{}]", max, max).as_str()), "<p><a href=\"a\">y</a></p>", "should support 999 characters in a reference" ); assert_eq!( - micromark(format!("[{}x]: a\n[y][{}x]", max, max).as_str()), + to_html(format!("[{}x]: a\n[y][{}x]", max, max).as_str()), format!("<p>[{}x]: a\n[y][{}x]</p>", max, max), "should not support 1000 characters in a reference" ); assert_eq!( - micromark("[x] missing-colon\n\nWill it link? [x]"), + to_html("[x] missing-colon\n\nWill it link? [x]"), "<p>[x] missing-colon</p>\n<p>Will it link? [x]</p>", "should not fail on a missing colon in a definition" ); assert_eq!( - micromark_with_options( + to_html_with_options( "[x]()", &Options { parse: ParseOptions { @@ -411,7 +409,7 @@ fn link_reference() -> Result<(), String> { ); assert_eq!( - micromark_with_options( + to_html_with_options( "[x]()", &Options { parse: ParseOptions { @@ -429,7 +427,7 @@ fn link_reference() -> Result<(), String> { ); assert_eq!( - micromark_to_mdast( + to_mdast( "[x]: y\n\na [x] b [x][] c [d][x] e.", &ParseOptions::default() )?, |