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_table.rs | 184 ++++++++++++++++++++++------------------------------- 1 file changed, 77 insertions(+), 107 deletions(-) (limited to 'tests/gfm_table.rs') diff --git a/tests/gfm_table.rs b/tests/gfm_table.rs index 54e0ace..db1c364 100644 --- a/tests/gfm_table.rs +++ b/tests/gfm_table.rs @@ -9,14 +9,6 @@ use pretty_assertions::assert_eq; #[test] fn gfm_table() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("| a |\n| - |\n| b |"), "

| a |\n| - |\n| b |

", @@ -24,181 +16,181 @@ fn gfm_table() -> Result<(), String> { ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b |", &gfm)?, + to_html_with_options("| a |\n| - |\n| b |", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support tables" ); assert_eq!( - to_html_with_options("| a |", &gfm)?, + to_html_with_options("| a |", &Options::gfm())?, "

| a |

", "should not support a table w/ the head row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a", &gfm)?, + to_html_with_options("| a", &Options::gfm())?, "

| a

", "should not support a table w/ the head row ending in an eof (2)" ); assert_eq!( - to_html_with_options("a |", &gfm)?, + to_html_with_options("a |", &Options::gfm())?, "

a |

", "should not support a table w/ the head row ending in an eof (3)" ); assert_eq!( - to_html_with_options("| a |\n| - |", &gfm)?, + to_html_with_options("| a |\n| - |", &Options::gfm())?, "\n\n\n\n\n\n
a
", "should support a table w/ a delimiter row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a\n| -", &gfm)?, + to_html_with_options("| a\n| -", &Options::gfm())?, "\n\n\n\n\n\n
a
", "should support a table w/ a delimiter row ending in an eof (2)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b |", &gfm)?, + to_html_with_options("| a |\n| - |\n| b |", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support a table w/ a body row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a\n| -\n| b", &gfm)?, + to_html_with_options("| a\n| -\n| b", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support a table w/ a body row ending in an eof (2)" ); assert_eq!( - to_html_with_options("a|b\n-|-\nc|d", &gfm)?, + to_html_with_options("a|b\n-|-\nc|d", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n\n\n
ab
cd
", "should support a table w/ a body row ending in an eof (3)" ); assert_eq!( - to_html_with_options("| a \n| -\t\n| b | ", &gfm)?, + to_html_with_options("| a \n| -\t\n| b | ", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support rows w/ trailing whitespace (1)" ); assert_eq!( - to_html_with_options("| a | \n| - |", &gfm)?, + to_html_with_options("| a | \n| - |", &Options::gfm())?, "\n\n\n\n\n\n
a
", "should support rows w/ trailing whitespace (2)" ); assert_eq!( - to_html_with_options("| a |\n| - | ", &gfm)?, + to_html_with_options("| a |\n| - | ", &Options::gfm())?, "\n\n\n\n\n\n
a
", "should support rows w/ trailing whitespace (3)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b | ", &gfm)?, + to_html_with_options("| a |\n| - |\n| b | ", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support rows w/ trailing whitespace (4)" ); assert_eq!( - to_html_with_options("||a|\n|-|-|", &gfm)?, + to_html_with_options("||a|\n|-|-|", &Options::gfm())?, "\n\n\n\n\n\n\n
a
", "should support empty first header cells" ); assert_eq!( - to_html_with_options("|a||\n|-|-|", &gfm)?, + to_html_with_options("|a||\n|-|-|", &Options::gfm())?, "\n\n\n\n\n\n\n
a
", "should support empty last header cells" ); assert_eq!( - to_html_with_options("a||b\n-|-|-", &gfm)?, + to_html_with_options("a||b\n-|-|-", &Options::gfm())?, "\n\n\n\n\n\n\n\n
ab
", "should support empty header cells" ); assert_eq!( - to_html_with_options("|a|b|\n|-|-|\n||c|", &gfm)?, + to_html_with_options("|a|b|\n|-|-|\n||c|", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n\n\n
ab
c
", "should support empty first body cells" ); assert_eq!( - to_html_with_options("|a|b|\n|-|-|\n|c||", &gfm)?, + to_html_with_options("|a|b|\n|-|-|\n|c||", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n\n\n
ab
c
", "should support empty last body cells" ); assert_eq!( - to_html_with_options("a|b|c\n-|-|-\nd||e", &gfm)?, + to_html_with_options("a|b|c\n-|-|-\nd||e", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
abc
de
", "should support empty body cells" ); assert_eq!( - to_html_with_options("| a |\n| - |\n- b", &gfm)?, + to_html_with_options("| a |\n| - |\n- b", &Options::gfm())?, "\n\n\n\n\n\n
a
\n", "should support a list after a table" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "
\n

| a |\n| - |

\n
", "should not support a lazy delimiter row (1)" ); assert_eq!( - to_html_with_options("> a\n> | b |\n| - |", &gfm)?, + to_html_with_options("> a\n> | b |\n| - |", &Options::gfm())?, "
\n

a\n| b |\n| - |

\n
", "should not support a lazy delimiter row (2)" ); assert_eq!( - to_html_with_options("| a |\n> | - |", &gfm)?, + to_html_with_options("| a |\n> | - |", &Options::gfm())?, "

| a |

\n
\n

| - |

\n
", "should not support a piercing delimiter row" ); assert_eq!( - to_html_with_options("> a\n> | b |\n|-", &gfm)?, + to_html_with_options("> a\n> | b |\n|-", &Options::gfm())?, "
\n

a\n| b |\n|-

\n
", "should not support a lazy body row (2)" ); assert_eq!( - to_html_with_options("> | a |\n> | - |\n| b |", &gfm)?, + to_html_with_options("> | a |\n> | - |\n| b |", &Options::gfm())?, "
\n\n\n\n\n\n\n
a
\n
\n

| b |

", "should not support a lazy body row (1)" ); assert_eq!( - to_html_with_options("> a\n> | b |\n> | - |\n| c |", &gfm)?, + to_html_with_options("> a\n> | b |\n> | - |\n| c |", &Options::gfm())?, "
\n

a

\n\n\n\n\n\n\n
b
\n
\n

| c |

", "should not support a lazy body row (2)" ); assert_eq!( - to_html_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &gfm)?, + to_html_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &Options::gfm())?, "
\n\n\n\n\n\n\n\n\n\n\n\n
A
1
\n
\n

| 2 |

", "should not support a lazy body row (3)" ); assert_eq!( - to_html_with_options(" - d\n - e", &gfm)?, + to_html_with_options(" - d\n - e", &Options::gfm())?, to_html(" - d\n - e"), "should not change how lists and lazyness work" ); assert_eq!( - to_html_with_options("| a |\n | - |", &gfm)?, + to_html_with_options("| a |\n | - |", &Options::gfm())?, "\n\n\n\n\n\n
a
", "should form a table if the delimiter row is indented w/ 3 spaces" ); assert_eq!( - to_html_with_options("| a |\n | - |", &gfm)?, + to_html_with_options("| a |\n | - |", &Options::gfm())?, "

| a |\n| - |

", "should not form a table if the delimiter row is indented w/ 4 spaces" ); @@ -210,34 +202,34 @@ fn gfm_table() -> Result<(), String> { code_indented: false, ..Constructs::gfm() }, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - ..Options::default() + ..Options::gfm() })?, "\n\n\n\n\n\n
a
", "should form a table if the delimiter row is indented w/ 4 spaces and indented code is turned off" ); assert_eq!( - to_html_with_options("| a |\n| - |\n> block quote?", &gfm)?, + to_html_with_options("| a |\n| - |\n> block quote?", &Options::gfm())?, "\n\n\n\n\n\n
a
\n
\n

block quote?

\n
", "should be interrupted by a block quote" ); assert_eq!( - to_html_with_options("| a |\n| - |\n>", &gfm)?, + to_html_with_options("| a |\n| - |\n>", &Options::gfm())?, "\n\n\n\n\n\n
a
\n
\n
", "should be interrupted by a block quote (empty)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n- list?", &gfm)?, + to_html_with_options("| a |\n| - |\n- list?", &Options::gfm())?, "\n\n\n\n\n\n
a
\n", "should be interrupted by a list" ); assert_eq!( - to_html_with_options("| a |\n| - |\n-", &gfm)?, + to_html_with_options("| a |\n| - |\n-", &Options::gfm())?, "\n\n\n\n\n\n
a
\n", "should be interrupted by a list (empty)" ); @@ -246,15 +238,12 @@ fn gfm_table() -> Result<(), String> { to_html_with_options( "| a |\n| - |\n", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, "\n\n\n\n\n\n
a
\n", @@ -263,15 +252,12 @@ fn gfm_table() -> Result<(), String> { assert_eq!( to_html_with_options("| a |\n| - |\n\tcode?", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() })?, "\n\n\n\n\n\n
a
\n
code?\n
", "should be interrupted by code (indented)" @@ -279,15 +265,12 @@ fn gfm_table() -> Result<(), String> { assert_eq!( to_html_with_options("| a |\n| - |\n```js\ncode?", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() })?, "\n\n\n\n\n\n
a
\n
code?\n
\n", "should be interrupted by code (fenced)" @@ -297,15 +280,12 @@ fn gfm_table() -> Result<(), String> { to_html_with_options( "| a |\n| - |\n***", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, "\n\n\n\n\n\n
a
\n
", @@ -313,67 +293,67 @@ fn gfm_table() -> Result<(), String> { ); assert_eq!( - to_html_with_options("| a |\n| - |\n# heading?", &gfm)?, + to_html_with_options("| a |\n| - |\n# heading?", &Options::gfm())?, "\n\n\n\n\n\n
a
\n

heading?

", "should be interrupted by a heading (ATX)" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n=", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n=", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n
a
heading
=
", "should *not* be interrupted by a heading (setext)" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n---", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n---", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
heading
\n
", "should *not* be interrupted by a heading (setext), but interrupt if the underline is also a thematic break" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n-", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n-", &Options::gfm())?, "\n\n\n\n\n\n\n\n\n\n\n
a
heading
\n", "should *not* be interrupted by a heading (setext), but interrupt if the underline is also an empty list item bullet" ); assert_eq!( - to_html_with_options("a\nb\n-:", &gfm)?, + to_html_with_options("a\nb\n-:", &Options::gfm())?, "

a

\n\n\n\n\n\n\n
b
", "should support a single head row" ); assert_eq!( - to_html_with_options("> | a |\n> | - |", &gfm)?, + to_html_with_options("> | a |\n> | - |", &Options::gfm())?, "
\n\n\n\n\n\n\n
a
\n
", "should support a table in a container" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "
\n

| a |\n| - |

\n
", "should not support a lazy delimiter row if the head row is in a container" ); assert_eq!( - to_html_with_options("| a |\n> | - |", &gfm)?, + to_html_with_options("| a |\n> | - |", &Options::gfm())?, "

| a |

\n
\n

| - |

\n
", "should not support a “piercing” container for the delimiter row, if the head row was not in that container" ); assert_eq!( - to_html_with_options("> | a |\n> | - |\n| c |", &gfm)?, + to_html_with_options("> | a |\n> | - |\n| c |", &Options::gfm())?, "
\n\n\n\n\n\n\n
a
\n
\n

| c |

", "should not support a lazy body row if the head row and delimiter row are in a container" ); assert_eq!( - to_html_with_options("> | a |\n| - |\n> | c |", &gfm)?, + to_html_with_options("> | a |\n| - |\n> | c |", &Options::gfm())?, "
\n

| a |\n| - |\n| c |

\n
", "should not support a lazy delimiter row if the head row and a further body row are in a container" ); assert_eq!( - to_html_with_options("[\na\n:-\n]: b", &gfm)?, + to_html_with_options("[\na\n:-\n]: b", &Options::gfm())?, "

[

\n\n\n\n\n\n\n\n\n\n\n\n
a
]: b
", "should prefer GFM tables over definitions" ); @@ -385,13 +365,9 @@ fn gfm_table() -> Result<(), String> { code_indented: false, ..Constructs::gfm() }, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - compile: CompileOptions { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..Options::gfm() })?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support indented rows if code (indented) is off" @@ -477,7 +453,7 @@ a | - | - | :- | -: | :-: | | f | "###, - &gfm + &Options::gfm() )?, r###"

Align

An empty initial cell

@@ -606,7 +582,7 @@ a | - | | b | "###, - &gfm + &Options::gfm() )?, r###"

Tables

@@ -708,7 +684,7 @@ a a |- "###, - &gfm + &Options::gfm() )?, r###"

Tables in things

In lists

@@ -853,7 +829,7 @@ a | - | | 1 | "###, - &gfm + &Options::gfm() )?, r###"
@@ -931,7 +907,7 @@ bar | abc | def | | --- | --- | "###, - &gfm + &Options::gfm() )?, r###"

Examples from GFM

A

@@ -1090,15 +1066,12 @@ bar `\|\\` "###, &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, r###"

Grave accents

@@ -1210,7 +1183,7 @@ a | D | | E | "###, - &gfm + &Options::gfm() )?, r###"

Code

Indented delimiter row

@@ -1405,15 +1378,12 @@ b *** "###, &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, r###"

Blank line

@@ -1765,7 +1735,7 @@ b a | - | "###, - &gfm + &Options::gfm() )?, r###"

Loose

Loose

@@ -1817,7 +1787,7 @@ a Note: GH has a bug where in case C and E, the escaped escape is treated as a normal escape: . "###, - &gfm + &Options::gfm() )?, r###"

Some more escapes

@@ -1853,7 +1823,7 @@ normal escape: https:// assert_eq!( to_mdast( "| none | left | right | center |\n| - | :- | -: | :-: |\n| a |\n| b | c | d | e | f |", - &gfm.parse + &ParseOptions::gfm() )?, Node::Root(Root { children: vec![Node::Table(Table { @@ -1956,7 +1926,7 @@ normal escape: https:// ); assert_eq!( - to_mdast("| `a\\|b` |\n| - |", &gfm.parse)?, + to_mdast("| `a\\|b` |\n| - |", &ParseOptions::gfm())?, Node::Root(Root { children: vec![Node::Table(Table { align: vec![AlignKind::None,], -- cgit