From 25e267afbc0789ea36508d45c3ea3545b84223bb Mon Sep 17 00:00:00 2001
From: Titus Wormer
Date: Thu, 18 Aug 2022 18:33:10 +0200
Subject: Add support for GFM autolink literals
---
tests/gfm_autolink_literal.rs | 256 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 256 insertions(+)
create mode 100644 tests/gfm_autolink_literal.rs
(limited to 'tests/gfm_autolink_literal.rs')
diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs
new file mode 100644
index 0000000..9551751
--- /dev/null
+++ b/tests/gfm_autolink_literal.rs
@@ -0,0 +1,256 @@
+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),
+ "https://example.com
",
+ "should support protocol urls if enabled"
+ );
+ assert_eq!(
+ micromark_with_options("www.example.com", &gfm),
+ "www.example.com
",
+ "should support www urls if enabled"
+ );
+ assert_eq!(
+ micromark_with_options("user@example.com", &gfm),
+ "user@example.com
",
+ "should support email urls if enabled"
+ );
+
+ assert_eq!(
+ micromark_with_options("user@example.com", &gfm),
+ "user@example.com
",
+ "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),
+ "www.�a
",
+ "should support a replacement character in a domain"
+ );
+
+ assert_eq!(
+ micromark_with_options("http://點看.com", &gfm),
+ "http://點看.com
",
+ "should support non-ascii characters in a domain (http)"
+ );
+
+ assert_eq!(
+ micromark_with_options("www.點看.com", &gfm),
+ "www.點看.com
",
+ "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),
+ "www.a.com/點看
",
+ "should support non-ascii characters in a path"
+ );
+
+ assert_eq!(
+ micromark_with_options("www.-a.b", &gfm),
+ "www.-a.b
",
+ "should support a dash to start a domain"
+ );
+
+ assert_eq!(
+ micromark_with_options("www.$", &gfm),
+ "www.$
",
+ "should support a dollar as a domain name"
+ );
+
+ assert_eq!(
+ micromark_with_options("www.a..b.c", &gfm),
+ "www.a..b.c
",
+ "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),
+ "https://a.bc/d/e/).
",
+ "should support a closing paren and period after a path"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc/d/e/.)", &gfm),
+ "https://a.bc/d/e/.)
",
+ "should support a period and closing paren after a path"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc).", &gfm),
+ "https://a.bc).
",
+ "should support a closing paren and period after a domain"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc.)", &gfm),
+ "https://a.bc.)
",
+ "should support a period and closing paren after a domain"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc).d", &gfm),
+ "https://a.bc).d
",
+ "should support a closing paren and period in a path"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc.)d", &gfm),
+ "https://a.bc.)d
",
+ "should support a period and closing paren in a path"
+ );
+
+ assert_eq!(
+ micromark_with_options("https://a.bc/))d", &gfm),
+ "https://a.bc/))d
",
+ "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: .
+ // assert_eq!(
+ // micromark_with_options(",www.example.com", &gfm),
+ // ",www.example.com
",
+ // "should support www links after Unicode punctuation",
+ // );
+
+ assert_eq!(
+ micromark_with_options(",https://example.com", &gfm),
+ ",https://example.com
",
+ "should support http links after Unicode punctuation"
+ );
+
+ assert_eq!(
+ micromark_with_options(",example@example.com", &gfm),
+ ",example@example.com
",
+ "should support email links after Unicode punctuation"
+ );
+
+ assert_eq!(
+ micromark_with_options(
+ "http://user:password@host:port/path?key=value#fragment",
+ &gfm
+ ),
+ "http://user:password@host:port/path?key=value#fragment
",
+ "should not link character reference for `:`"
+ );
+
+ assert_eq!(
+ micromark_with_options("http://example.com/abhttp://example.com/ab<cd
",
+ "should stop domains/paths at `<`"
+ );
+
+ assert_eq!(
+ micromark_with_options(
+ r###"
+[ www.example.com
+
+[ https://example.com
+
+[ contact@example.com
+
+[ www.example.com ]
+
+[ https://example.com ]
+
+[ contact@example.com ]
+
+[ www.example.com ](#)
+
+[ https://example.com ](#)
+
+[ contact@example.com ](#)
+
+![ www.example.com ](#)
+
+![ https://example.com ](#)
+
+![ contact@example.com ](#)
+"###,
+ &gfm
+ ),
+ r###"[ www.example.com
+[ https://example.com
+[ contact@example.com
+[ www.example.com ]
+[ https://example.com ]
+[ contact@example.com ]
+ www.example.com
+ https://example.com
+ contact@example.com
+
+
+
+"###,
+ "should interplay with brackets, links, and images"
+ );
+}
--
cgit