diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-13 12:37:25 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-13 12:37:25 +0200 |
commit | efdf90959f78d1582da312bffbefaabb79f264b7 (patch) | |
tree | a36c7dfa72ec5cadfdb296d94aed2d06a871b701 /tests | |
parent | 17f4eec55ad0a5f74aedbcff6c2f0119ad52e584 (diff) | |
download | markdown-rs-efdf90959f78d1582da312bffbefaabb79f264b7.tar.gz markdown-rs-efdf90959f78d1582da312bffbefaabb79f264b7.tar.bz2 markdown-rs-efdf90959f78d1582da312bffbefaabb79f264b7.zip |
Add autolinks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/autolink.rs | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/tests/autolink.rs b/tests/autolink.rs new file mode 100644 index 0000000..fc49dcb --- /dev/null +++ b/tests/autolink.rs @@ -0,0 +1,247 @@ +extern crate micromark; +use micromark::micromark; + +#[test] +fn autolink() { + assert_eq!( + micromark("```\n<\n >\n```"), + "<pre><code><\n >\n</code></pre>", + "should support fenced code w/ grave accents" + ); + + assert_eq!( + micromark("<http://foo.bar.baz>"), + "<p><a href=\"http://foo.bar.baz\">http://foo.bar.baz</a></p>", + "should support protocol autolinks (1)" + ); + + assert_eq!( + micromark("<http://foo.bar.baz/test?q=hello&id=22&boolean>"), + "<p><a href=\"http://foo.bar.baz/test?q=hello&id=22&boolean\">http://foo.bar.baz/test?q=hello&id=22&boolean</a></p>", + "should support protocol autolinks (2)" + ); + + assert_eq!( + micromark("<irc://foo.bar:2233/baz>"), + "<p><a href=\"irc://foo.bar:2233/baz\">irc://foo.bar:2233/baz</a></p>", + "should support protocol autolinks w/ non-HTTP schemes" + ); + + assert_eq!( + micromark("<MAILTO:FOO@BAR.BAZ>"), + "<p><a href=\"MAILTO:FOO@BAR.BAZ\">MAILTO:FOO@BAR.BAZ</a></p>", + "should support protocol autolinks in uppercase" + ); + + // To do: safety. + // assert_eq!( + // micromark("<a+b+c:d>", {allowDangerousProtocol: true}), + // "<p><a href=\"a+b+c:d\">a+b+c:d</a></p>", + // "should support protocol autolinks w/ incorrect URIs (1)" + // ); + + // To do: safety. + // assert_eq!( + // micromark("<made-up-scheme://foo,bar>", {allowDangerousProtocol: true}), + // "<p><a href=\"made-up-scheme://foo,bar\">made-up-scheme://foo,bar</a></p>", + // "should support protocol autolinks w/ incorrect URIs (2)" + // ); + + assert_eq!( + micromark("<http://../>"), + "<p><a href=\"http://../\">http://../</a></p>", + "should support protocol autolinks w/ incorrect URIs (3)" + ); + + // To do: safety. + // assert_eq!( + // micromark("<localhost:5001/foo>", {allowDangerousProtocol: true}), + // "<p><a href=\"localhost:5001/foo\">localhost:5001/foo</a></p>", + // "should support protocol autolinks w/ incorrect URIs (4)" + // ); + + assert_eq!( + micromark("<http://foo.bar/baz bim>"), + "<p><http://foo.bar/baz bim></p>", + "should not support protocol autolinks w/ spaces" + ); + + // To do: encode urls. + // assert_eq!( + // micromark("<http://example.com/\\[\\>"), + // "<p><a href=\"http://example.com/%5C%5B%5C\">http://example.com/\\[\\</a></p>", + // "should not support character escapes in protocol autolinks" + // ); + + assert_eq!( + micromark("<foo@bar.example.com>"), + "<p><a href=\"mailto:foo@bar.example.com\">foo@bar.example.com</a></p>", + "should support email autolinks (1)" + ); + + assert_eq!( + micromark("<foo+special@Bar.baz-bar0.com>"), + "<p><a href=\"mailto:foo+special@Bar.baz-bar0.com\">foo+special@Bar.baz-bar0.com</a></p>", + "should support email autolinks (2)" + ); + + assert_eq!( + micromark("<a@b.c>"), + "<p><a href=\"mailto:a@b.c\">a@b.c</a></p>", + "should support email autolinks (3)" + ); + + assert_eq!( + micromark("<foo\\+@bar.example.com>"), + "<p><foo+@bar.example.com></p>", + "should not support character escapes in email autolinks" + ); + + assert_eq!( + micromark("<>"), + "<p><></p>", + "should not support empty autolinks" + ); + + assert_eq!( + micromark("< http://foo.bar >"), + "<p>< http://foo.bar ></p>", + "should not support autolinks w/ space" + ); + + assert_eq!( + micromark("<m:abc>"), + "<p><m:abc></p>", + "should not support autolinks w/ a single character for a scheme" + ); + + assert_eq!( + micromark("<foo.bar.baz>"), + "<p><foo.bar.baz></p>", + "should not support autolinks w/o a colon or at sign" + ); + + assert_eq!( + micromark("http://example.com"), + "<p>http://example.com</p>", + "should not support protocol autolinks w/o angle brackets" + ); + + assert_eq!( + micromark("foo@bar.example.com"), + "<p>foo@bar.example.com</p>", + "should not support email autolinks w/o angle brackets" + ); + + // Extra: + assert_eq!( + micromark("<*@example.com>"), + "<p><a href=\"mailto:*@example.com\">*@example.com</a></p>", + "should support autolinks w/ atext (1)" + ); + assert_eq!( + micromark("<a*@example.com>"), + "<p><a href=\"mailto:a*@example.com\">a*@example.com</a></p>", + "should support autolinks w/ atext (2)" + ); + assert_eq!( + micromark("<aa*@example.com>"), + "<p><a href=\"mailto:aa*@example.com\">aa*@example.com</a></p>", + "should support autolinks w/ atext (3)" + ); + + assert_eq!( + micromark("<aaa©@example.com>"), + "<p><aaa©@example.com></p>", + "should support non-atext in email autolinks local part (1)" + ); + assert_eq!( + micromark("<a*a©@example.com>"), + "<p><a*a©@example.com></p>", + "should support non-atext in email autolinks local part (2)" + ); + + assert_eq!( + micromark("<asd@.example.com>"), + "<p><asd@.example.com></p>", + "should not support a dot after an at sign in email autolinks" + ); + assert_eq!( + micromark("<asd@e..xample.com>"), + "<p><asd@e..xample.com></p>", + "should not support a dot after another dot in email autolinks" + ); + + assert_eq!( + micromark( + "<asd@012345678901234567890123456789012345678901234567890123456789012>" + ), + "<p><a href=\"mailto:asd@012345678901234567890123456789012345678901234567890123456789012\">asd@012345678901234567890123456789012345678901234567890123456789012</a></p>", + "should support 63 character in email autolinks domains" + ); + + assert_eq!( + micromark("<asd@0123456789012345678901234567890123456789012345678901234567890123>"), + "<p><asd@0123456789012345678901234567890123456789012345678901234567890123></p>", + "should not support 64 character in email autolinks domains" + ); + + assert_eq!( + micromark( + "<asd@012345678901234567890123456789012345678901234567890123456789012.a>" + ), + "<p><a href=\"mailto:asd@012345678901234567890123456789012345678901234567890123456789012.a\">asd@012345678901234567890123456789012345678901234567890123456789012.a</a></p>", + "should support a TLD after a 63 character domain in email autolinks" + ); + + assert_eq!( + micromark("<asd@0123456789012345678901234567890123456789012345678901234567890123.a>"), + "<p><asd@0123456789012345678901234567890123456789012345678901234567890123.a></p>", + "should not support a TLD after a 64 character domain in email autolinks" + ); + + assert_eq!( + micromark( + "<asd@a.012345678901234567890123456789012345678901234567890123456789012>" + ), + "<p><a href=\"mailto:asd@a.012345678901234567890123456789012345678901234567890123456789012\">asd@a.012345678901234567890123456789012345678901234567890123456789012</a></p>", + "should support a 63 character TLD in email autolinks" + ); + + assert_eq!( + micromark("<asd@a.0123456789012345678901234567890123456789012345678901234567890123>"), + "<p><asd@a.0123456789012345678901234567890123456789012345678901234567890123></p>", + "should not support a 64 character TLD in email autolinks" + ); + + assert_eq!( + micromark("<asd@-example.com>"), + "<p><asd@-example.com></p>", + "should not support a dash after `@` in email autolinks" + ); + + assert_eq!( + micromark("<asd@e-xample.com>"), + "<p><a href=\"mailto:asd@e-xample.com\">asd@e-xample.com</a></p>", + "should support a dash after other domain characters in email autolinks" + ); + + assert_eq!( + micromark("<asd@e--xample.com>"), + "<p><a href=\"mailto:asd@e--xample.com\">asd@e--xample.com</a></p>", + "should support a dash after another dash in email autolinks" + ); + + assert_eq!( + micromark("<asd@example-.com>"), + "<p><asd@example-.com></p>", + "should not support a dash before a dot in email autolinks" + ); + + // To do: extensions. + // assert_eq!( + // micromark("<a@b.co>", {extensions: [{disable: {null: ["autolink"]}}]}), + // "<p><a@b.co></p>", + // "should support turning off autolinks" + // ); +} |