diff options
Diffstat (limited to '')
-rw-r--r-- | tests/gfm_table.rs | 184 |
1 files changed, 77 insertions, 107 deletions
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 |"), "<p>| a |\n| - |\n| b |</p>", @@ -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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support tables" ); assert_eq!( - to_html_with_options("| a |", &gfm)?, + to_html_with_options("| a |", &Options::gfm())?, "<p>| a |</p>", "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())?, "<p>| a</p>", "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())?, "<p>a |</p>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support rows w/ trailing whitespace (1)" ); assert_eq!( - to_html_with_options("| a | \n| - |", &gfm)?, + to_html_with_options("| a | \n| - |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support rows w/ trailing whitespace (2)" ); assert_eq!( - to_html_with_options("| a |\n| - | ", &gfm)?, + to_html_with_options("| a |\n| - | ", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support rows w/ trailing whitespace (4)" ); assert_eq!( - to_html_with_options("||a|\n|-|-|", &gfm)?, + to_html_with_options("||a|\n|-|-|", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th></th>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support empty first header cells" ); assert_eq!( - to_html_with_options("|a||\n|-|-|", &gfm)?, + to_html_with_options("|a||\n|-|-|", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th></th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th></th>\n<th>b</th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td>c</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>c</td>\n<td></td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>d</td>\n<td></td>\n<td>e</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li>b</li>\n</ul>", "should support a list after a table" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "<blockquote>\n<p>| a |\n| - |</p>\n</blockquote>", "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())?, "<blockquote>\n<p>a\n| b |\n| - |</p>\n</blockquote>", "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())?, "<p>| a |</p>\n<blockquote>\n<p>| - |</p>\n</blockquote>", "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())?, "<blockquote>\n<p>a\n| b |\n|-</p>\n</blockquote>", "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())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| b |</p>", "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())?, "<blockquote>\n<p>a</p>\n<table>\n<thead>\n<tr>\n<th>b</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| c |</p>", "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())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>A</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n</blockquote>\n<p>| 2 |</p>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "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())?, "<p>| a |\n| - |</p>", "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() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<blockquote>\n<p>block quote?</p>\n</blockquote>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<blockquote>\n</blockquote>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li>list?</li>\n</ul>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li></li>\n</ul>", "should be interrupted by a list (empty)" ); @@ -246,15 +238,12 @@ fn gfm_table() -> Result<(), String> { to_html_with_options( "| a |\n| - |\n<!-- HTML? -->", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<!-- HTML? -->", @@ -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() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<pre><code>code?\n</code></pre>", "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() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<pre><code class=\"language-js\">code?\n</code></pre>\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() } )?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<hr />", @@ -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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<h1>heading?</h1>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n<tr>\n<td>=</td>\n</tr>\n</tbody>\n</table>", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n</tbody>\n</table>\n<hr />", "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())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li></li>\n</ul>", "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())?, "<p>a</p>\n<table>\n<thead>\n<tr>\n<th align=\"right\">b</th>\n</tr>\n</thead>\n</table>", "should support a single head row" ); assert_eq!( - to_html_with_options("> | a |\n> | - |", &gfm)?, + to_html_with_options("> | a |\n> | - |", &Options::gfm())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>", "should support a table in a container" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "<blockquote>\n<p>| a |\n| - |</p>\n</blockquote>", "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())?, "<p>| a |</p>\n<blockquote>\n<p>| - |</p>\n</blockquote>", "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())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| c |</p>", "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())?, "<blockquote>\n<p>| a |\n| - |\n| c |</p>\n</blockquote>", "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())?, "<p>[</p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">]: b</td>\n</tr>\n</tbody>\n</table>", "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() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support indented rows if code (indented) is off" @@ -477,7 +453,7 @@ a | - | - | :- | -: | :-: | | f | "###, - &gfm + &Options::gfm() )?, r###"<h1>Align</h1> <h2>An empty initial cell</h2> @@ -606,7 +582,7 @@ a | - | | b | "###, - &gfm + &Options::gfm() )?, r###"<h1>Tables</h1> <table> @@ -708,7 +684,7 @@ a a |- "###, - &gfm + &Options::gfm() )?, r###"<h1>Tables in things</h1> <h2>In lists</h2> @@ -853,7 +829,7 @@ a | - | | 1 | "###, - &gfm + &Options::gfm() )?, r###"<table> <thead> @@ -931,7 +907,7 @@ bar | abc | def | | --- | --- | "###, - &gfm + &Options::gfm() )?, r###"<h1>Examples from GFM</h1> <h2>A</h2> @@ -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###"<h1>Grave accents</h1> @@ -1210,7 +1183,7 @@ a | D | | E | "###, - &gfm + &Options::gfm() )?, r###"<h1>Code</h1> <h2>Indented delimiter row</h2> @@ -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###"<h2>Blank line</h2> @@ -1765,7 +1735,7 @@ b a | - | "###, - &gfm + &Options::gfm() )?, r###"<h1>Loose</h1> <h2>Loose</h2> @@ -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: <https://github.com/github/cmark-gfm/issues/277>. "###, - &gfm + &Options::gfm() )?, r###"<h1>Some more escapes</h1> <table> @@ -1853,7 +1823,7 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">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: <a href="https://github.com/github/cmark-gfm/issues/277">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,], |