From 1d92666865b35341e076efbefddf6e73b5e1542e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 7 Sep 2022 15:53:06 +0200 Subject: Add support for recoverable syntax errors --- tests/gfm_autolink_literal.rs | 122 +++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 60 deletions(-) (limited to 'tests/gfm_autolink_literal.rs') 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)?, "

https://example.com

", "should support protocol urls if enabled" ); assert_eq!( - micromark_with_options("www.example.com", &gfm), + 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), + micromark_with_options("user@example.com", &gfm)?, "

user@example.com

", "should support email urls if enabled" ); assert_eq!( - micromark_with_options("[https://example.com](xxx)", &gfm), + micromark_with_options("[https://example.com](xxx)", &gfm)?, "

https://example.com

", "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)?, "

www.example.com

", "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)?, "

user@example.com

", "should not link email urls in links" ); assert_eq!( - micromark_with_options("user@example.com", &gfm), + 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), + 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), + micromark_with_options("www.a b", &gfm)?, "

www.a b

", "should support no TLD" ); assert_eq!( - micromark_with_options("www.a/b c", &gfm), + 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), + micromark_with_options("www.�a", &gfm)?, "

www.�a

", "should support a replacement character in a domain" ); assert_eq!( - micromark_with_options("http://點看.com", &gfm), + 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), + 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), + 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), + 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), + 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), + 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), + micromark_with_options("www.$", &gfm)?, "

www.$

", "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)?, "

www.a..b.c

", "should support adjacent dots in a domain name" ); assert_eq!( - micromark_with_options("www.a&a;", &gfm), + 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), + 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), + 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), + 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), + 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), + 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), + 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), + 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), + micromark_with_options("ftp://a/b/c.txt", &gfm)?, "

ftp://a/b/c.txt

", "should not support ftp links" ); @@ -193,19 +193,19 @@ fn gfm_autolink_literal() { // Fixing it would mean deviating from `cmark-gfm`: // Source: . // assert_eq!( - // micromark_with_options(",www.example.com", &gfm), + // 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), + 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), + micromark_with_options(",example@example.com", &gfm)?, "

example@example.com

", "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 - ), + )?, "

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 `<`" ); @@ -252,7 +252,7 @@ xmpp:scyther@pokemon.com/message. Email me at:scyther@pokemon.com"###, &gfm - ), + )?, r###"

mailto:scyther@pokemon.com

This is a mailto:scyther@pokemon.com

mailto:scyther@pokemon.com.

@@ -298,7 +298,7 @@ a www.example.com&. b a www.example.com& b "###, &gfm - ), + )?, r###"

a www.example.com&xxx;b c

a www.example.com&xxx;. b

a www.example.com&xxxxxxxxx;. b

@@ -345,7 +345,7 @@ a www.example.com& b ![ contact@example.com ](#) "###, &gfm - ), + )?, r###"

[ www.example.com

[ https://example.com

[ contact@example.com

@@ -392,7 +392,7 @@ www.example.com/?q=a(business))) (www.example.com/?q=a(business)". "###, &gfm - ), + )?, r###"

www.example.com/?=a(b)cccccc

www.example.com/?=a(b(c)ccccc

www.example.com/?=a(b(c)c)cccc

@@ -537,7 +537,7 @@ Can contain an underscore followed by a period: aaa@a.b_.c [link]() should still be expanded. "###, &gfm - ), + )?, r###"

Literal autolinks

WWW autolinks

w.commonmark.org

@@ -641,7 +641,7 @@ H5. [[]]www.a.com©b "###, &gfm - ), + )?, r###"

H0.

[https://a.com&copy;b

[www.a.com&copy;b

@@ -716,7 +716,7 @@ Autolink literal after image. ![a]() www.a.com ![a]() a@b.c -"###, &gfm), +"###, &gfm)?, r###"

Image start.

![https://a.com

![http://a.com

@@ -858,7 +858,7 @@ Autolink literal after link. [a]() www.a.com [a]() a@b.c -"###, &gfm), +"###, &gfm)?, r###"

Link start.

[https://a.com

[http://a.com

@@ -991,7 +991,7 @@ www.a&b} www.a&b~ "###, &gfm - ), + )?, r###"

“character reference”

www.a&b (space)

www.a&b!

@@ -1101,7 +1101,7 @@ www.a#| www.a#} www.a#~ -"###, &gfm), +"###, &gfm)?, r###"

“character reference”

www.a&#35 (space)

www.a&#35!

@@ -1174,7 +1174,7 @@ react@0.0.0-experimental-aae83a4b9 [ react@0.0.0-experimental-aae83a4b9 "###, &gfm - ), + )?, r###"

a@0.0

a@0.b

a@a.29

@@ -1267,7 +1267,7 @@ http://a} http://a~ "###, &gfm - ), + )?, r###"

httpshhh? (2)

http://a (space)

http://a!

@@ -1380,7 +1380,7 @@ http://} http://~ "###, &gfm - ), + )?, r###"

httpshhh? (1)

http:// (space)

http://!

@@ -1493,7 +1493,7 @@ http://a/b} http://a/b~ "###, &gfm - ), + )?, r###"

httpshhh? (4)

http://a/b (space)

http://a/b!

@@ -1606,7 +1606,7 @@ http://a/} http://a/~ "###, &gfm - ), + )?, r###"

httpshhh? (3)

http://a/ (space)

http://a/!

@@ -1661,7 +1661,7 @@ www.example.com/a&bogus; www.example.com/a\. "###, &gfm - ), + )?, r###"

www.example.com/a©

www.example.com/a©

www.example.com/a&bogus;

@@ -1745,7 +1745,7 @@ www.a/b&c} www.a/b&c~ "###, &gfm - ), + )?, r###"

“character reference”

www.a/b&c (space)

www.a/b&c!

@@ -1858,7 +1858,7 @@ www.a/b#} www.a/b#~ "###, &gfm - ), + )?, r###"

“character reference”

www.a/b&#35 (space)

www.a/b&#35!

@@ -1943,7 +1943,7 @@ http://a.com#d]() www.a.com#d]() "###, &gfm - ), + )?, r###"

In autolink literal path or link end?

https://a.com/d

http://a.com/d

@@ -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###"

Last non-markdown ASCII whitespace (FF): noreply@example.com, http://example.com, https://example.com, www.example.com

Last non-whitespace ASCII control (US): noreply@example.com, http://example.com, https://example.com, www.example.com

First punctuation after controls: !noreply@example.com, !http://example.com, !https://example.com, !www.example.com

@@ -2123,7 +2123,7 @@ See `https://github.com/remarkjs/remark/discussions/678`. [asd] ,https://github.com "###, &gfm - ), + )?, r###"

HTTP

https://a.b can start after EOF

Can start after EOL: @@ -2243,7 +2243,7 @@ www.a} www.a~ "###, &gfm - ), + )?, r###"

wwwtf 2?

www.a (space)

www.a!

@@ -2356,7 +2356,7 @@ www.a.} www.a.~ "###, &gfm - ), + )?, r###"

wwwtf 5?

www.a. (space)

www.a.!

@@ -2469,7 +2469,7 @@ www.} www.~ "###, &gfm - ), + )?, r###"

wwwtf?

www. (space)

www.!

@@ -2582,7 +2582,7 @@ www.a/b} www.a/b~ "###, &gfm - ), + )?, r###"

wwwtf? (4)

www.a/b (space)

www.a/b!

@@ -2695,7 +2695,7 @@ www.a/} www.a/~ "###, &gfm - ), + )?, r###"

wwwtf? (3)

www.a/ (space)

www.a/!

@@ -2734,4 +2734,6 @@ www.a/~ "###, "should match www (path start) like GitHub does (except for the bracket bug)" ); + + Ok(()) } -- cgit