extern crate micromark; use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] fn gfm_autolink_literal() { let gfm = Options { constructs: Constructs::gfm(), ..Options::default() }; assert_eq!( micromark("https://example.com"), "
https://example.com
", "should ignore protocol urls by default" ); assert_eq!( micromark("www.example.com"), "www.example.com
", "should ignore www urls by default" ); assert_eq!( micromark("user@example.com"), "user@example.com
", "should ignore email urls by default" ); assert_eq!( micromark_with_options("https://example.com", &gfm), "", "should support protocol urls if enabled" ); assert_eq!( micromark_with_options("www.example.com", &gfm), "", "should support www urls if enabled" ); assert_eq!( micromark_with_options("user@example.com", &gfm), "", "should support email urls if enabled" ); assert_eq!( micromark_with_options("user@example.com", &gfm), "", "should support a closing paren at TLD (email)" ); assert_eq!( micromark_with_options("www.a.)", &gfm), "www.a.)
", "should support a closing paren at TLD (www)" ); assert_eq!( micromark_with_options("www.a b", &gfm), "www.a b
", "should support no TLD" ); assert_eq!( micromark_with_options("www.a/b c", &gfm), "www.a/b c
", "should support a path instead of TLD" ); assert_eq!( micromark_with_options("www.�a", &gfm), "", "should support a replacement character in a domain" ); assert_eq!( micromark_with_options("http://點看.com", &gfm), "", "should support non-ascii characters in a domain (http)" ); assert_eq!( micromark_with_options("www.點看.com", &gfm), "", "should support non-ascii characters in a domain (www)" ); assert_eq!( micromark_with_options("點看@example.com", &gfm), "點看@example.com
", "should *not* support non-ascii characters in atext (email)" ); assert_eq!( micromark_with_options("example@點看.com", &gfm), "example@點看.com
", "should *not* support non-ascii characters in a domain (email)" ); assert_eq!( micromark_with_options("www.a.com/點看", &gfm), "", "should support non-ascii characters in a path" ); assert_eq!( micromark_with_options("www.-a.b", &gfm), "", "should support a dash to start a domain" ); assert_eq!( micromark_with_options("www.$", &gfm), "", "should support a dollar as a domain name" ); assert_eq!( micromark_with_options("www.a..b.c", &gfm), "", "should support adjacent dots in a domain name" ); assert_eq!( micromark_with_options("www.a&a;", &gfm), "www.a&a;
", "should support named character references in domains" ); assert_eq!( micromark_with_options("https://a.bc/d/e/).", &gfm), "", "should support a closing paren and period after a path" ); assert_eq!( micromark_with_options("https://a.bc/d/e/.)", &gfm), "", "should support a period and closing paren after a path" ); assert_eq!( micromark_with_options("https://a.bc).", &gfm), "", "should support a closing paren and period after a domain" ); assert_eq!( micromark_with_options("https://a.bc.)", &gfm), "", "should support a period and closing paren after a domain" ); assert_eq!( micromark_with_options("https://a.bc).d", &gfm), "", "should support a closing paren and period in a path" ); assert_eq!( micromark_with_options("https://a.bc.)d", &gfm), "", "should support a period and closing paren in a path" ); assert_eq!( micromark_with_options("https://a.bc/))d", &gfm), "", "should support two closing parens in a path" ); assert_eq!( micromark_with_options("ftp://a/b/c.txt", &gfm), "ftp://a/b/c.txt
", "should not support ftp links" ); // Note: GH comments/issues/PRs do not link this, but Gists/readmes do. // Fixing it would mean defiating from `cmark-gfm`: // Source:http://user:password@host:port/path?key=value#fragment
", "should not link character reference for `:`" ); assert_eq!( micromark_with_options("http://example.com/ab[ www.example.com ]
"###, "should interplay with brackets, links, and images" ); }