extern crate micromark; use micromark::{micromark, micromark_with_options, Options}; use pretty_assertions::assert_eq; #[test] fn link_resource() { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, ..Options::default() }; assert_eq!( micromark("[link](/uri \"title\")"), "
", "should support links" ); assert_eq!( micromark("[link](/uri)"), "", "should support links w/o title" ); assert_eq!( micromark("[link]()"), "", "should support links w/o destination" ); assert_eq!( micromark("[link](<>)"), "", "should support links w/ empty enclosed destination" ); assert_eq!( micromark("[link](/my uri)"), "[link](/my uri)
", "should not support links w/ spaces in destination" ); assert_eq!( micromark("[link]()"), "", "should support links w/ spaces in enclosed destination" ); assert_eq!( micromark("[link](foo\nbar)"), "[link](foo\nbar)
", "should not support links w/ line endings in destination" ); assert_eq!( micromark_with_options("[link]([link](
[link](<foo>)
", "should not support links w/ enclosed destinations w/o end" ); assert_eq!( micromark_with_options("[a](\n[a](c)", &danger), "[a](<b)c\n[a](<b)c>\n[a](c)
", "should not support links w/ unmatched enclosed destinations" ); assert_eq!( micromark("[link](\\(foo\\))"), "", "should support links w/ destinations w/ escaped parens" ); assert_eq!( micromark("[link](foo(and(bar)))"), "", "should support links w/ destinations w/ balanced parens" ); assert_eq!( micromark("[link](foo\\(and\\(bar\\))"), "", "should support links w/ destinations w/ escaped parens" ); assert_eq!( micromark("[link]([link](/url "title "and" title")
", "should not support nested balanced quotes in title" ); assert_eq!( micromark("[link](/url 'title \"and\" title')"), "", "should support the other quotes in titles" ); assert_eq!( micromark("[link]( /uri\n \"title\" )"), "", "should support whitespace around destination and title (1)" ); assert_eq!( micromark("[link](\t\n/uri \"title\")"), "", "should support whitespace around destination and title (2)" ); assert_eq!( micromark("[link](/uri \"title\"\t\n)"), "", "should support whitespace around destination and title (3)" ); assert_eq!( micromark("[link] (/uri)"), "[link] (/uri)
", "should not support whitespace between label and resource" ); assert_eq!( micromark("[link [foo [bar]]](/uri)"), "", "should support balanced brackets" ); assert_eq!( micromark("[link] bar](/uri)"), "[link] bar](/uri)
", "should not support unbalanced brackets (1)" ); assert_eq!( micromark("[link [bar](/uri)"), "[link bar
", "should not support unbalanced brackets (2)" ); assert_eq!( micromark("[link \\[bar](/uri)"), "", "should support characer escapes" ); assert_eq!( micromark("[link *foo **bar** `#`*](/uri)"), "", "should support content" ); assert_eq!( micromark("[![moon](moon.jpg)](/uri)"), "", "should support an image as content" ); assert_eq!( micromark("[foo [bar](/uri)](/uri)"), "[foo bar](/uri)
", "should not support links in links (1)" ); assert_eq!( micromark("[foo *[bar [baz](/uri)](/uri)*](/uri)"), "[foo [bar baz](/uri)](/uri)
", "should not support links in links (2)" ); assert_eq!( micromark("![[[foo](uri1)](uri2)](uri3)"), "", "should not support links in links (3)" ); assert_eq!( micromark("*[foo*](/uri)"), "*foo*
", "should prefer links over emphasis (1)" ); assert_eq!( micromark("[foo *bar](baz*)"), "", "should prefer links over emphasis (2)" ); assert_eq!( micromark_with_options("[foo[foo
[foo](/uri)
[foohttp://example.com/?search=](uri)
", "should prefer autolinks over links" ); assert_eq!( micromark("[foo[foohttp://example.com/?search=](uri)
", "should prefer autolinks over links" ); // Extra assert_eq!( micromark("[]()"), "", "should support an empty link" ); // See:[a]("c")
", "should require whitespace between enclosed destination and title" ); assert_eq!( micromark("[](<"), "[](<
", "should not support an unclosed enclosed destination" ); assert_eq!( micromark("[]("), "[](
", "should not support an unclosed destination" ); assert_eq!( micromark("[](\\<)"), "", "should support unenclosed link destination starting w/ escapes" ); assert_eq!( micromark("[](<\\<>)"), "", "should support enclosed link destination starting w/ escapes" ); assert_eq!( micromark("[](\\"), "[](\\
", "should not support unenclosed link destination starting w/ an incorrect escape" ); assert_eq!( micromark("[](<\\"), "[](<\\
", "should not support enclosed link destination starting w/ an incorrect escape" ); assert_eq!( micromark("[](a \""), "[](a "
", "should not support an eof in a link title (1)" ); assert_eq!( micromark("[](a '"), "[](a '
", "should not support an eof in a link title (2)" ); assert_eq!( micromark("[](a ("), "[](a (
", "should not support an eof in a link title (3)" ); assert_eq!( micromark("[](a \"\\"), "[](a "\\
", "should not support an eof in a link title escape (1)" ); assert_eq!( micromark("[](a '\\"), "[](a '\\
", "should not support an eof in a link title escape (2)" ); assert_eq!( micromark("[](a (\\"), "[](a (\\
", "should not support an eof in a link title escape (3)" ); assert_eq!( micromark("[](a \"\\\"\")"), "", "should support a character escape to start a link title (1)" ); assert_eq!( micromark("[](a '\\'')"), "", "should support a character escape to start a link title (2)" ); assert_eq!( micromark("[](a (\\)))"), "", "should support a character escape to start a link title (3)" ); assert_eq!( micromark("[&©&](example.com/&©& \"&©&\")"), "", "should support character references in links" ); assert_eq!( micromark("[a](1())"), "", "should support 1 set of parens" ); assert_eq!( micromark("[a](1(2()))"), "", "should support 2 sets of parens" ); assert_eq!( micromark( "[a](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()))))))))))))))))))))))))))))))))" ), "", "should support 32 sets of parens" ); assert_eq!( micromark( "[a](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())))))))))))))))))))))))))))))))))" ), "[a](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())))))))))))))))))))))))))))))))))
", "should not support 33 or more sets of parens" ); assert_eq!( micromark("[a](b \"\n c\")"), "", "should support an eol at the start of a title" ); assert_eq!( micromark("[a](b( \"c\")"), "[a](b( "c")
", "should not support whitespace when unbalanced in a raw destination" ); assert_eq!( micromark("[a](\0)"), "", "should support a single NUL character as a link resource" ); }