From 246063fb7cd21a83beae5934f95b2795fb85df51 Mon Sep 17 00:00:00 2001
From: Titus Wormer
Date: Fri, 14 Oct 2022 10:49:28 +0200
Subject: Refactor to use default trait in tests
---
tests/gfm_autolink_literal.rs | 130 ++++++++++++++++++++----------------------
1 file changed, 61 insertions(+), 69 deletions(-)
(limited to 'tests/gfm_autolink_literal.rs')
diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs
index cdeecd3..cb38f29 100644
--- a/tests/gfm_autolink_literal.rs
+++ b/tests/gfm_autolink_literal.rs
@@ -3,20 +3,12 @@ use markdown::{
mdast::{Link, Node, Paragraph, Root, Text},
to_html, to_html_with_options, to_mdast,
unist::Position,
- Constructs, Options, ParseOptions,
+ Options, ParseOptions,
};
use pretty_assertions::assert_eq;
#[test]
fn gfm_autolink_literal() -> Result<(), String> {
- let gfm = Options {
- parse: ParseOptions {
- constructs: Constructs::gfm(),
- ..ParseOptions::default()
- },
- ..Options::default()
- };
-
assert_eq!(
to_html("https://example.com"),
"https://example.com
",
@@ -34,165 +26,165 @@ fn gfm_autolink_literal() -> Result<(), String> {
);
assert_eq!(
- to_html_with_options("https://example.com", &gfm)?,
+ to_html_with_options("https://example.com", &Options::gfm())?,
"https://example.com
",
"should support protocol urls if enabled"
);
assert_eq!(
- to_html_with_options("www.example.com", &gfm)?,
+ to_html_with_options("www.example.com", &Options::gfm())?,
"www.example.com
",
"should support www urls if enabled"
);
assert_eq!(
- to_html_with_options("user@example.com", &gfm)?,
+ to_html_with_options("user@example.com", &Options::gfm())?,
"user@example.com
",
"should support email urls if enabled"
);
assert_eq!(
- to_html_with_options("[https://example.com](xxx)", &gfm)?,
+ to_html_with_options("[https://example.com](xxx)", &Options::gfm())?,
"https://example.com
",
"should not link protocol urls in links"
);
assert_eq!(
- to_html_with_options("[www.example.com](xxx)", &gfm)?,
+ to_html_with_options("[www.example.com](xxx)", &Options::gfm())?,
"www.example.com
",
"should not link www urls in links"
);
assert_eq!(
- to_html_with_options("[user@example.com](xxx)", &gfm)?,
+ to_html_with_options("[user@example.com](xxx)", &Options::gfm())?,
"user@example.com
",
"should not link email urls in links"
);
assert_eq!(
- to_html_with_options("user@example.com", &gfm)?,
+ to_html_with_options("user@example.com", &Options::gfm())?,
"user@example.com
",
"should support a closing paren at TLD (email)"
);
assert_eq!(
- to_html_with_options("www.a.)", &gfm)?,
+ to_html_with_options("www.a.)", &Options::gfm())?,
"www.a.)
",
"should support a closing paren at TLD (www)"
);
assert_eq!(
- to_html_with_options("www.a b", &gfm)?,
+ to_html_with_options("www.a b", &Options::gfm())?,
"www.a b
",
"should support no TLD"
);
assert_eq!(
- to_html_with_options("www.a/b c", &gfm)?,
+ to_html_with_options("www.a/b c", &Options::gfm())?,
"www.a/b c
",
"should support a path instead of TLD"
);
assert_eq!(
- to_html_with_options("www.�a", &gfm)?,
+ to_html_with_options("www.�a", &Options::gfm())?,
"www.�a
",
"should support a replacement character in a domain"
);
assert_eq!(
- to_html_with_options("http://點看.com", &gfm)?,
+ to_html_with_options("http://點看.com", &Options::gfm())?,
"http://點看.com
",
"should support non-ascii characters in a domain (http)"
);
assert_eq!(
- to_html_with_options("www.點看.com", &gfm)?,
+ to_html_with_options("www.點看.com", &Options::gfm())?,
"www.點看.com
",
"should support non-ascii characters in a domain (www)"
);
assert_eq!(
- to_html_with_options("點看@example.com", &gfm)?,
+ to_html_with_options("點看@example.com", &Options::gfm())?,
"點看@example.com
",
"should *not* support non-ascii characters in atext (email)"
);
assert_eq!(
- to_html_with_options("example@點看.com", &gfm)?,
+ to_html_with_options("example@點看.com", &Options::gfm())?,
"example@點看.com
",
"should *not* support non-ascii characters in a domain (email)"
);
assert_eq!(
- to_html_with_options("www.a.com/點看", &gfm)?,
+ to_html_with_options("www.a.com/點看", &Options::gfm())?,
"www.a.com/點看
",
"should support non-ascii characters in a path"
);
assert_eq!(
- to_html_with_options("www.-a.b", &gfm)?,
+ to_html_with_options("www.-a.b", &Options::gfm())?,
"www.-a.b
",
"should support a dash to start a domain"
);
assert_eq!(
- to_html_with_options("www.$", &gfm)?,
+ to_html_with_options("www.$", &Options::gfm())?,
"www.$
",
"should support a dollar as a domain name"
);
assert_eq!(
- to_html_with_options("www.a..b.c", &gfm)?,
+ to_html_with_options("www.a..b.c", &Options::gfm())?,
"www.a..b.c
",
"should support adjacent dots in a domain name"
);
assert_eq!(
- to_html_with_options("www.a&a;", &gfm)?,
+ to_html_with_options("www.a&a;", &Options::gfm())?,
"www.a&a;
",
"should support named character references in domains"
);
assert_eq!(
- to_html_with_options("https://a.bc/d/e/).", &gfm)?,
+ to_html_with_options("https://a.bc/d/e/).", &Options::gfm())?,
"https://a.bc/d/e/).
",
"should support a closing paren and period after a path"
);
assert_eq!(
- to_html_with_options("https://a.bc/d/e/.)", &gfm)?,
+ to_html_with_options("https://a.bc/d/e/.)", &Options::gfm())?,
"https://a.bc/d/e/.)
",
"should support a period and closing paren after a path"
);
assert_eq!(
- to_html_with_options("https://a.bc).", &gfm)?,
+ to_html_with_options("https://a.bc).", &Options::gfm())?,
"https://a.bc).
",
"should support a closing paren and period after a domain"
);
assert_eq!(
- to_html_with_options("https://a.bc.)", &gfm)?,
+ to_html_with_options("https://a.bc.)", &Options::gfm())?,
"https://a.bc.)
",
"should support a period and closing paren after a domain"
);
assert_eq!(
- to_html_with_options("https://a.bc).d", &gfm)?,
+ to_html_with_options("https://a.bc).d", &Options::gfm())?,
"https://a.bc).d
",
"should support a closing paren and period in a path"
);
assert_eq!(
- to_html_with_options("https://a.bc.)d", &gfm)?,
+ to_html_with_options("https://a.bc.)d", &Options::gfm())?,
"https://a.bc.)d
",
"should support a period and closing paren in a path"
);
assert_eq!(
- to_html_with_options("https://a.bc/))d", &gfm)?,
+ to_html_with_options("https://a.bc/))d", &Options::gfm())?,
"https://a.bc/))d
",
"should support two closing parens in a path"
);
assert_eq!(
- to_html_with_options("ftp://a/b/c.txt", &gfm)?,
+ to_html_with_options("ftp://a/b/c.txt", &Options::gfm())?,
"ftp://a/b/c.txt
",
"should not support ftp links"
);
@@ -201,19 +193,19 @@ fn gfm_autolink_literal() -> Result<(), String> {
// Fixing it would mean deviating from `cmark-gfm`:
// Source: .
// assert_eq!(
- // to_html_with_options(",www.example.com", &gfm)?,
+ // to_html_with_options(",www.example.com", &Options::gfm())?,
// ",www.example.com
",
// "should support www links after Unicode punctuation",
// );
assert_eq!(
- to_html_with_options(",https://example.com", &gfm)?,
+ to_html_with_options(",https://example.com", &Options::gfm())?,
",https://example.com
",
"should support http links after Unicode punctuation"
);
assert_eq!(
- to_html_with_options(",example@example.com", &gfm)?,
+ to_html_with_options(",example@example.com", &Options::gfm())?,
",example@example.com
",
"should support email links after Unicode punctuation"
);
@@ -221,14 +213,14 @@ fn gfm_autolink_literal() -> Result<(), String> {
assert_eq!(
to_html_with_options(
"http://user:password@host:port/path?key=value#fragment",
- &gfm
+ &Options::gfm()
)?,
"http://user:password@host:port/path?key=value#fragment
",
"should not link character reference for `:`"
);
assert_eq!(
- to_html_with_options("http://example.com/abhttp://example.com/ab<cd
",
"should stop domains/paths at `<`"
);
@@ -259,7 +251,7 @@ xmpp:scyther@pokemon.com/message
xmpp:scyther@pokemon.com/message.
Email me at:scyther@pokemon.com"###,
- &gfm
+ &Options::gfm()
)?,
r###"mailto:scyther@pokemon.com
This is a mailto:scyther@pokemon.com
@@ -305,7 +297,7 @@ a www.example.com&. b
a www.example.com& b
"###,
- &gfm
+ &Options::gfm()
)?,
r###"a www.example.com&xxx;b c
a www.example.com&xxx;. b
@@ -352,7 +344,7 @@ a www.example.com& b
![ contact@example.com ](#)
"###,
- &gfm
+ &Options::gfm()
)?,
r###"[ www.example.com
[ https://example.com
@@ -399,7 +391,7 @@ www.example.com/?q=a(business)))
(www.example.com/?q=a(business)".
"###,
- &gfm
+ &Options::gfm()
)?,
r###"www.example.com/?=a(b)cccccc
www.example.com/?=a(b(c)ccccc
@@ -544,7 +536,7 @@ Can contain an underscore followed by a period: aaa@a.b_.c
[link]() should still be expanded.
"###,
- &gfm
+ &Options::gfm()
)?,
r###"Literal autolinks
WWW autolinks
@@ -648,7 +640,7 @@ H5.
[[]]www.a.com©b
"###,
- &gfm
+ &Options::gfm()
)?,
r###"H0.
[https://a.com©b
@@ -724,7 +716,7 @@ Autolink literal after image.
![a]() www.a.com
![a]() a@b.c
-"###, &gfm)?,
+"###, &Options::gfm())?,
r###"Image start.
![https://a.com
![http://a.com
@@ -866,7 +858,7 @@ Autolink literal after link.
[a]() www.a.com
[a]() a@b.c
-"###, &gfm)?,
+"###, &Options::gfm())?,
r###"Link start.
[https://a.com
[http://a.com
@@ -998,7 +990,7 @@ www.a&b}
www.a&b~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"“character reference”
www.a&b (space)
@@ -1109,7 +1101,7 @@ www.a#|
www.a#}
www.a#~
-"###, &gfm)?,
+"###, &Options::gfm())?,
r###"“character reference”
www.a# (space)
www.a#!
@@ -1181,7 +1173,7 @@ react@0.0.0-experimental-aae83a4b9
[ react@0.0.0-experimental-aae83a4b9
"###,
- &gfm
+ &Options::gfm()
)?,
r###"a@0.0
a@0.b
@@ -1274,7 +1266,7 @@ http://a}
http://a~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"httpshhh? (2)
http://a (space)
@@ -1387,7 +1379,7 @@ http://}
http://~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"httpshhh? (1)
http:// (space)
@@ -1500,7 +1492,7 @@ http://a/b}
http://a/b~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"httpshhh? (4)
http://a/b (space)
@@ -1613,7 +1605,7 @@ http://a/}
http://a/~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"httpshhh? (3)
http://a/ (space)
@@ -1668,7 +1660,7 @@ www.example.com/a&bogus;
www.example.com/a\.
"###,
- &gfm
+ &Options::gfm()
)?,
r###"www.example.com/a©
www.example.com/a©
@@ -1752,7 +1744,7 @@ www.a/b&c}
www.a/b&c~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"“character reference”
www.a/b&c (space)
@@ -1865,7 +1857,7 @@ www.a/b#}
www.a/b#~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"“character reference”
www.a/b# (space)
@@ -1950,7 +1942,7 @@ http://a.com#d]()
www.a.com#d]()
"###,
- &gfm
+ &Options::gfm()
)?,
r###"In autolink literal path or link end?
https://a.com/d
@@ -2023,7 +2015,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
+ &Options::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
@@ -2130,7 +2122,7 @@ See `https://github.com/remarkjs/remark/discussions/678`.
[asd] ,https://github.com
"###,
- &gfm
+ &Options::gfm()
)?,
r###"HTTP
https://a.b can start after EOF
@@ -2250,7 +2242,7 @@ www.a}
www.a~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"wwwtf 2?
www.a (space)
@@ -2363,7 +2355,7 @@ www.a.}
www.a.~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"wwwtf 5?
www.a. (space)
@@ -2476,7 +2468,7 @@ www.}
www.~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"wwwtf?
www. (space)
@@ -2589,7 +2581,7 @@ www.a/b}
www.a/b~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"wwwtf? (4)
www.a/b (space)
@@ -2702,7 +2694,7 @@ www.a/}
www.a/~
"###,
- &gfm
+ &Options::gfm()
)?,
r###"wwwtf? (3)
www.a/ (space)
@@ -2746,7 +2738,7 @@ www.a/~
assert_eq!(
to_mdast(
"a https://alpha.com b bravo@charlie.com c www.delta.com d xmpp:echo@foxtrot.com e mailto:golf@hotel.com f.",
- &gfm.parse
+ &ParseOptions::gfm()
)?,
Node::Root(Root {
children: vec![Node::Paragraph(Paragraph {
--
cgit