diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-09-07 15:53:06 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-09-07 15:53:06 +0200 |
commit | 1d92666865b35341e076efbefddf6e73b5e1542e (patch) | |
tree | 11c05985ec7679f73473e7ea2c769465698e2f08 /tests/gfm_autolink_literal.rs | |
parent | e6018e52ee6ad9a8f8a0672b75bf515faf74af1f (diff) | |
download | markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.tar.gz markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.tar.bz2 markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.zip |
Add support for recoverable syntax errors
Diffstat (limited to '')
-rw-r--r-- | tests/gfm_autolink_literal.rs | 122 |
1 files changed, 62 insertions, 60 deletions
diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs index 0c646b6..bcb0797 100644 --- a/tests/gfm_autolink_literal.rs +++ b/tests/gfm_autolink_literal.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn gfm_autolink_literal() { +fn gfm_autolink_literal() -> Result<(), String> { let gfm = Options { constructs: Constructs::gfm(), ..Options::default() @@ -26,165 +26,165 @@ fn gfm_autolink_literal() { ); assert_eq!( - micromark_with_options("https://example.com", &gfm), + micromark_with_options("https://example.com", &gfm)?, "<p><a href=\"https://example.com\">https://example.com</a></p>", "should support protocol urls if enabled" ); assert_eq!( - micromark_with_options("www.example.com", &gfm), + micromark_with_options("www.example.com", &gfm)?, "<p><a href=\"http://www.example.com\">www.example.com</a></p>", "should support www urls if enabled" ); assert_eq!( - micromark_with_options("user@example.com", &gfm), + micromark_with_options("user@example.com", &gfm)?, "<p><a href=\"mailto:user@example.com\">user@example.com</a></p>", "should support email urls if enabled" ); assert_eq!( - micromark_with_options("[https://example.com](xxx)", &gfm), + micromark_with_options("[https://example.com](xxx)", &gfm)?, "<p><a href=\"xxx\">https://example.com</a></p>", "should not link protocol urls in links" ); assert_eq!( - micromark_with_options("[www.example.com](xxx)", &gfm), + micromark_with_options("[www.example.com](xxx)", &gfm)?, "<p><a href=\"xxx\">www.example.com</a></p>", "should not link www urls in links" ); assert_eq!( - micromark_with_options("[user@example.com](xxx)", &gfm), + micromark_with_options("[user@example.com](xxx)", &gfm)?, "<p><a href=\"xxx\">user@example.com</a></p>", "should not link email urls in links" ); assert_eq!( - micromark_with_options("user@example.com", &gfm), + micromark_with_options("user@example.com", &gfm)?, "<p><a href=\"mailto:user@example.com\">user@example.com</a></p>", "should support a closing paren at TLD (email)" ); assert_eq!( - micromark_with_options("www.a.)", &gfm), + micromark_with_options("www.a.)", &gfm)?, "<p><a href=\"http://www.a\">www.a</a>.)</p>", "should support a closing paren at TLD (www)" ); assert_eq!( - micromark_with_options("www.a b", &gfm), + micromark_with_options("www.a b", &gfm)?, "<p><a href=\"http://www.a\">www.a</a> b</p>", "should support no TLD" ); assert_eq!( - micromark_with_options("www.a/b c", &gfm), + micromark_with_options("www.a/b c", &gfm)?, "<p><a href=\"http://www.a/b\">www.a/b</a> c</p>", "should support a path instead of TLD" ); assert_eq!( - micromark_with_options("www.�a", &gfm), + micromark_with_options("www.�a", &gfm)?, "<p><a href=\"http://www.%EF%BF%BDa\">www.�a</a></p>", "should support a replacement character in a domain" ); assert_eq!( - micromark_with_options("http://點看.com", &gfm), + micromark_with_options("http://點看.com", &gfm)?, "<p><a href=\"http://%E9%BB%9E%E7%9C%8B.com\">http://點看.com</a></p>", "should support non-ascii characters in a domain (http)" ); assert_eq!( - micromark_with_options("www.點看.com", &gfm), + micromark_with_options("www.點看.com", &gfm)?, "<p><a href=\"http://www.%E9%BB%9E%E7%9C%8B.com\">www.點看.com</a></p>", "should support non-ascii characters in a domain (www)" ); assert_eq!( - micromark_with_options("點看@example.com", &gfm), + micromark_with_options("點看@example.com", &gfm)?, "<p>點看@example.com</p>", "should *not* support non-ascii characters in atext (email)" ); assert_eq!( - micromark_with_options("example@點看.com", &gfm), + micromark_with_options("example@點看.com", &gfm)?, "<p>example@點看.com</p>", "should *not* support non-ascii characters in a domain (email)" ); assert_eq!( - micromark_with_options("www.a.com/點看", &gfm), + micromark_with_options("www.a.com/點看", &gfm)?, "<p><a href=\"http://www.a.com/%E9%BB%9E%E7%9C%8B\">www.a.com/點看</a></p>", "should support non-ascii characters in a path" ); assert_eq!( - micromark_with_options("www.-a.b", &gfm), + micromark_with_options("www.-a.b", &gfm)?, "<p><a href=\"http://www.-a.b\">www.-a.b</a></p>", "should support a dash to start a domain" ); assert_eq!( - micromark_with_options("www.$", &gfm), + micromark_with_options("www.$", &gfm)?, "<p><a href=\"http://www.$\">www.$</a></p>", "should support a dollar as a domain name" ); assert_eq!( - micromark_with_options("www.a..b.c", &gfm), + micromark_with_options("www.a..b.c", &gfm)?, "<p><a href=\"http://www.a..b.c\">www.a..b.c</a></p>", "should support adjacent dots in a domain name" ); assert_eq!( - micromark_with_options("www.a&a;", &gfm), + micromark_with_options("www.a&a;", &gfm)?, "<p><a href=\"http://www.a\">www.a</a>&a;</p>", "should support named character references in domains" ); assert_eq!( - micromark_with_options("https://a.bc/d/e/).", &gfm), + micromark_with_options("https://a.bc/d/e/).", &gfm)?, "<p><a href=\"https://a.bc/d/e/\">https://a.bc/d/e/</a>).</p>", "should support a closing paren and period after a path" ); assert_eq!( - micromark_with_options("https://a.bc/d/e/.)", &gfm), + micromark_with_options("https://a.bc/d/e/.)", &gfm)?, "<p><a href=\"https://a.bc/d/e/\">https://a.bc/d/e/</a>.)</p>", "should support a period and closing paren after a path" ); assert_eq!( - micromark_with_options("https://a.bc).", &gfm), + micromark_with_options("https://a.bc).", &gfm)?, "<p><a href=\"https://a.bc\">https://a.bc</a>).</p>", "should support a closing paren and period after a domain" ); assert_eq!( - micromark_with_options("https://a.bc.)", &gfm), + micromark_with_options("https://a.bc.)", &gfm)?, "<p><a href=\"https://a.bc\">https://a.bc</a>.)</p>", "should support a period and closing paren after a domain" ); assert_eq!( - micromark_with_options("https://a.bc).d", &gfm), + micromark_with_options("https://a.bc).d", &gfm)?, "<p><a href=\"https://a.bc).d\">https://a.bc).d</a></p>", "should support a closing paren and period in a path" ); assert_eq!( - micromark_with_options("https://a.bc.)d", &gfm), + micromark_with_options("https://a.bc.)d", &gfm)?, "<p><a href=\"https://a.bc.)d\">https://a.bc.)d</a></p>", "should support a period and closing paren in a path" ); assert_eq!( - micromark_with_options("https://a.bc/))d", &gfm), + micromark_with_options("https://a.bc/))d", &gfm)?, "<p><a href=\"https://a.bc/))d\">https://a.bc/))d</a></p>", "should support two closing parens in a path" ); assert_eq!( - micromark_with_options("ftp://a/b/c.txt", &gfm), + micromark_with_options("ftp://a/b/c.txt", &gfm)?, "<p>ftp://a/b/c.txt</p>", "should not support ftp links" ); @@ -193,19 +193,19 @@ fn gfm_autolink_literal() { // Fixing it would mean deviating from `cmark-gfm`: // Source: <https://github.com/github/cmark-gfm/blob/ef1cfcb/extensions/autolink.c#L156>. // assert_eq!( - // micromark_with_options(",www.example.com", &gfm), + // micromark_with_options(",www.example.com", &gfm)?, // "<p>,<a href=\"http://www.example.com\">www.example.com</a></p>", // "should support www links after Unicode punctuation", // ); assert_eq!( - micromark_with_options(",https://example.com", &gfm), + micromark_with_options(",https://example.com", &gfm)?, "<p>,<a href=\"https://example.com\">https://example.com</a></p>", "should support http links after Unicode punctuation" ); assert_eq!( - micromark_with_options(",example@example.com", &gfm), + micromark_with_options(",example@example.com", &gfm)?, "<p>,<a href=\"mailto:example@example.com\">example@example.com</a></p>", "should support email links after Unicode punctuation" ); @@ -214,13 +214,13 @@ fn gfm_autolink_literal() { micromark_with_options( "http://user:password@host:port/path?key=value#fragment", &gfm - ), + )?, "<p>http://user:password@host:port/path?key=value#fragment</p>", "should not link character reference for `:`" ); assert_eq!( - micromark_with_options("http://example.com/ab<cd", &gfm), + micromark_with_options("http://example.com/ab<cd", &gfm)?, "<p><a href=\"http://example.com/ab\">http://example.com/ab</a><cd</p>", "should stop domains/paths at `<`" ); @@ -252,7 +252,7 @@ xmpp:scyther@pokemon.com/message. Email me at:scyther@pokemon.com"###, &gfm - ), + )?, r###"<p><a href="mailto:scyther@pokemon.com">mailto:scyther@pokemon.com</a></p> <p>This is a <a href="mailto:scyther@pokemon.com">mailto:scyther@pokemon.com</a></p> <p><a href="mailto:scyther@pokemon.com">mailto:scyther@pokemon.com</a>.</p> @@ -298,7 +298,7 @@ a www.example.com&. b a www.example.com& b "###, &gfm - ), + )?, r###"<p>a <a href="http://www.example.com&xxx;b">www.example.com&xxx;b</a> c</p> <p>a <a href="http://www.example.com">www.example.com</a>&xxx;. b</p> <p>a <a href="http://www.example.com">www.example.com</a>&xxxxxxxxx;. b</p> @@ -345,7 +345,7 @@ a www.example.com& b ![ contact@example.com ](#) "###, &gfm - ), + )?, r###"<p>[ <a href="http://www.example.com">www.example.com</a></p> <p>[ <a href="https://example.com">https://example.com</a></p> <p>[ <a href="mailto:contact@example.com">contact@example.com</a></p> @@ -392,7 +392,7 @@ www.example.com/?q=a(business))) (www.example.com/?q=a(business)". "###, &gfm - ), + )?, r###"<p><a href="http://www.example.com/?=a(b)cccccc">www.example.com/?=a(b)cccccc</a></p> <p><a href="http://www.example.com/?=a(b(c)ccccc">www.example.com/?=a(b(c)ccccc</a></p> <p><a href="http://www.example.com/?=a(b(c)c)cccc">www.example.com/?=a(b(c)c)cccc</a></p> @@ -537,7 +537,7 @@ Can contain an underscore followed by a period: aaa@a.b_.c [link]() <http://autolink> should still be expanded. "###, &gfm - ), + )?, r###"<h1>Literal autolinks</h1> <h2>WWW autolinks</h2> <p>w.commonmark.org</p> @@ -641,7 +641,7 @@ H5. [[]]www.a.com©b "###, &gfm - ), + )?, r###"<p>H0.</p> <p>[<a href="https://a.com&copy;b">https://a.com&copy;b</a></p> <p>[<a href="http://www.a.com&copy;b">www.a.com&copy;b</a></p> @@ -716,7 +716,7 @@ Autolink literal after image. ![a]() www.a.com ![a]() a@b.c -"###, &gfm), +"###, &gfm)?, r###"<p>Image start.</p> <p>![<a href="https://a.com">https://a.com</a></p> <p>![<a href="http://a.com">http://a.com</a></p> @@ -858,7 +858,7 @@ Autolink literal after link. [a]() www.a.com [a]() a@b.c -"###, &gfm), +"###, &gfm)?, r###"<p>Link start.</p> <p>[<a href="https://a.com">https://a.com</a></p> <p>[<a href="http://a.com">http://a.com</a></p> @@ -991,7 +991,7 @@ www.a&b} www.a&b~ "###, &gfm - ), + )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a&b">www.a&b</a> (space)</p> <p><a href="http://www.a&b">www.a&b</a>!</p> @@ -1101,7 +1101,7 @@ www.a#| www.a#} www.a#~ -"###, &gfm), +"###, &gfm)?, r###"<h1>“character reference”</h1> <p><a href="http://www.a&#35">www.a&#35</a> (space)</p> <p><a href="http://www.a&#35">www.a&#35</a>!</p> @@ -1174,7 +1174,7 @@ react@0.0.0-experimental-aae83a4b9 [ react@0.0.0-experimental-aae83a4b9 "###, &gfm - ), + )?, r###"<p>a@0.0</p> <p><a href="mailto:a@0.b">a@0.b</a></p> <p>a@a.29</p> @@ -1267,7 +1267,7 @@ http://a} http://a~ "###, &gfm - ), + )?, r###"<h1>httpshhh? (2)</h1> <p><a href="http://a">http://a</a> (space)</p> <p><a href="http://a">http://a</a>!</p> @@ -1380,7 +1380,7 @@ http://} http://~ "###, &gfm - ), + )?, r###"<h1>httpshhh? (1)</h1> <p>http:// (space)</p> <p>http://!</p> @@ -1493,7 +1493,7 @@ http://a/b} http://a/b~ "###, &gfm - ), + )?, r###"<h1>httpshhh? (4)</h1> <p><a href="http://a/b">http://a/b</a> (space)</p> <p><a href="http://a/b">http://a/b</a>!</p> @@ -1606,7 +1606,7 @@ http://a/} http://a/~ "###, &gfm - ), + )?, r###"<h1>httpshhh? (3)</h1> <p><a href="http://a/">http://a/</a> (space)</p> <p><a href="http://a/">http://a/</a>!</p> @@ -1661,7 +1661,7 @@ www.example.com/a&bogus; www.example.com/a\. "###, &gfm - ), + )?, r###"<p><a href="#">www.example.com/a©</a></p> <p><a href="http://www.example.com/a">www.example.com/a</a>©</p> <p><a href="#">www.example.com/a&bogus;</a></p> @@ -1745,7 +1745,7 @@ www.a/b&c} www.a/b&c~ "###, &gfm - ), + )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a/b&c">www.a/b&c</a> (space)</p> <p><a href="http://www.a/b&c">www.a/b&c</a>!</p> @@ -1858,7 +1858,7 @@ www.a/b#} www.a/b#~ "###, &gfm - ), + )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a/b&#35">www.a/b&#35</a> (space)</p> <p><a href="http://www.a/b&#35">www.a/b&#35</a>!</p> @@ -1943,7 +1943,7 @@ http://a.com#d]() www.a.com#d]() "###, &gfm - ), + )?, r###"<p>In autolink literal path or link end?</p> <p><a href="">https://a.com/d</a></p> <p><a href="">http://a.com/d</a></p> @@ -2016,7 +2016,7 @@ Some non-ascii: 中noreply@example.com, 中http://example.com, 中https://exampl Some more non-ascii: 🤷noreply@example.com, 🤷http://example.com, 🤷https://example.com, 🤷www.example.com "###, &gfm - ), + )?, r###"<p>Last non-markdown ASCII whitespace (FF): <a href="mailto:noreply@example.com">noreply@example.com</a>, <a href="http://example.com">http://example.com</a>, <a href="https://example.com">https://example.com</a>, www.example.com</p> <p>Last non-whitespace ASCII control (US): <a href="mailto:noreply@example.com">noreply@example.com</a>, <a href="http://example.com">http://example.com</a>, <a href="https://example.com">https://example.com</a>, www.example.com</p> <p>First punctuation after controls: !<a href="mailto:noreply@example.com">noreply@example.com</a>, !<a href="http://example.com">http://example.com</a>, !<a href="https://example.com">https://example.com</a>, !www.example.com</p> @@ -2123,7 +2123,7 @@ See `https://github.com/remarkjs/remark/discussions/678`. [asd] ,https://github.com "###, &gfm - ), + )?, r###"<h1>HTTP</h1> <p><a href="https://a.b">https://a.b</a> can start after EOF</p> <p>Can start after EOL: @@ -2243,7 +2243,7 @@ www.a} www.a~ "###, &gfm - ), + )?, r###"<h1>wwwtf 2?</h1> <p><a href="http://www.a">www.a</a> (space)</p> <p><a href="http://www.a">www.a</a>!</p> @@ -2356,7 +2356,7 @@ www.a.} www.a.~ "###, &gfm - ), + )?, r###"<h1>wwwtf 5?</h1> <p><a href="http://www.a">www.a</a>. (space)</p> <p><a href="http://www.a">www.a</a>.!</p> @@ -2469,7 +2469,7 @@ www.} www.~ "###, &gfm - ), + )?, r###"<h1>wwwtf?</h1> <p><a href="http://www">www</a>. (space)</p> <p><a href="http://www">www</a>.!</p> @@ -2582,7 +2582,7 @@ www.a/b} www.a/b~ "###, &gfm - ), + )?, r###"<h1>wwwtf? (4)</h1> <p><a href="http://www.a/b">www.a/b</a> (space)</p> <p><a href="http://www.a/b">www.a/b</a>!</p> @@ -2695,7 +2695,7 @@ www.a/} www.a/~ "###, &gfm - ), + )?, r###"<h1>wwwtf? (3)</h1> <p><a href="http://www.a/">www.a/</a> (space)</p> <p><a href="http://www.a/">www.a/</a>!</p> @@ -2734,4 +2734,6 @@ www.a/~ "###, "should match www (path start) like GitHub does (except for the bracket bug)" ); + + Ok(()) } |