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_table.rs | 126 ++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 64 deletions(-) (limited to 'tests/gfm_table.rs') diff --git a/tests/gfm_table.rs b/tests/gfm_table.rs index a265549..619bf2a 100644 --- a/tests/gfm_table.rs +++ b/tests/gfm_table.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn gfm_table() { +fn gfm_table() -> Result<(), String> { let gfm = Options { constructs: Constructs::gfm(), ..Options::default() @@ -16,181 +16,181 @@ fn gfm_table() { ); assert_eq!( - micromark_with_options("| a |\n| - |\n| b |", &gfm), + micromark_with_options("| a |\n| - |\n| b |", &gfm)?, "\n\n\n\n\n\n\n\n\n\n\n
a
b
", "should support tables" ); assert_eq!( - micromark_with_options("| a |", &gfm), + micromark_with_options("| a |", &gfm)?, "

| a |

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

| a

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

a |

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

| a |\n| - |

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

a\n| b |\n| - |

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

| a |

\n
\n

| - |

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

a\n| b |\n|-

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

| b |

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

a

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

| c |

", "should not support a lazy body row (2)" ); assert_eq!( - micromark_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &gfm), + micromark_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &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!( - micromark_with_options(" - d\n - e", &gfm), + micromark_with_options(" - d\n - e", &gfm)?, micromark(" - d\n - e"), "should not change how lists and lazyness work" ); assert_eq!( - micromark_with_options("| a |\n | - |", &gfm), + micromark_with_options("| a |\n | - |", &gfm)?, "\n\n\n\n\n\n
a
", "should form a table if the delimiter row is indented w/ 3 spaces" ); assert_eq!( - micromark_with_options("| a |\n | - |", &gfm), + micromark_with_options("| a |\n | - |", &gfm)?, "

| a |\n| - |

", "should not form a table if the delimiter row is indented w/ 4 spaces" ); @@ -202,31 +202,31 @@ fn gfm_table() { ..Constructs::gfm() }, ..Options::default() - }), + })?, "\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!( - micromark_with_options("| a |\n| - |\n> block quote?", &gfm), + micromark_with_options("| a |\n| - |\n> block quote?", &gfm)?, "\n\n\n\n\n\n
a
\n
\n

block quote?

\n
", "should be interrupted by a block quote" ); assert_eq!( - micromark_with_options("| a |\n| - |\n>", &gfm), + micromark_with_options("| a |\n| - |\n>", &gfm)?, "\n\n\n\n\n\n
a
\n
\n
", "should be interrupted by a block quote (empty)" ); assert_eq!( - micromark_with_options("| a |\n| - |\n- list?", &gfm), + micromark_with_options("| a |\n| - |\n- list?", &gfm)?, "\n\n\n\n\n\n
a
\n", "should be interrupted by a list" ); assert_eq!( - micromark_with_options("| a |\n| - |\n-", &gfm), + micromark_with_options("| a |\n| - |\n-", &gfm)?, "\n\n\n\n\n\n
a
\n", "should be interrupted by a list (empty)" ); @@ -239,7 +239,7 @@ fn gfm_table() { constructs: Constructs::gfm(), ..Options::default() } - ), + )?, "\n\n\n\n\n\n
a
\n", "should be interrupted by HTML (flow)" ); @@ -249,7 +249,7 @@ fn gfm_table() { allow_dangerous_html: true, constructs: Constructs::gfm(), ..Options::default() - }), + })?, "\n\n\n\n\n\n
a
\n
code?\n
", "should be interrupted by code (indented)" ); @@ -259,7 +259,7 @@ fn gfm_table() { allow_dangerous_html: true, constructs: Constructs::gfm(), ..Options::default() - }), + })?, "\n\n\n\n\n\n
a
\n
code?\n
\n", "should be interrupted by code (fenced)" ); @@ -272,75 +272,71 @@ fn gfm_table() { constructs: Constructs::gfm(), ..Options::default() } - ), + )?, "\n\n\n\n\n\n
a
\n
", "should be interrupted by a thematic break" ); assert_eq!( - micromark_with_options("| a |\n| - |\n# heading?", &gfm), + micromark_with_options("| a |\n| - |\n# heading?", &gfm)?, "\n\n\n\n\n\n
a
\n

heading?

", "should be interrupted by a heading (ATX)" ); assert_eq!( - micromark_with_options("| a |\n| - |\nheading\n=", &gfm), + micromark_with_options("| a |\n| - |\nheading\n=", &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!( - micromark_with_options("| a |\n| - |\nheading\n---", &gfm), + micromark_with_options("| a |\n| - |\nheading\n---", &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!( - micromark_with_options("| a |\n| - |\nheading\n-", &gfm), + micromark_with_options("| a |\n| - |\nheading\n-", &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!( - micromark_with_options("a\nb\n-:", &gfm), + micromark_with_options("a\nb\n-:", &gfm)?, "

a

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

| a |\n| - |

\n
", "should not support a lazy delimiter row if the head row is in a container" ); assert_eq!( - micromark_with_options("| a |\n> | - |", &gfm), + micromark_with_options("| a |\n> | - |", &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!( - micromark_with_options("> | a |\n> | - |\n| c |", &gfm), + micromark_with_options("> | a |\n> | - |\n| c |", &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!( - micromark_with_options("> | a |\n| - |\n> | c |", &gfm), + micromark_with_options("> | a |\n| - |\n> | c |", &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!(micromark_with_options("", &gfm), "", "should support"); - - assert_eq!(micromark_with_options("", &gfm), "", "should support"); - assert_eq!( micromark_with_options( r###"# Align @@ -422,7 +418,7 @@ a | f | "###, &gfm - ), + )?, r###"

Align

An empty initial cell

@@ -551,7 +547,7 @@ a | b | "###, &gfm - ), + )?, r###"

Tables

@@ -653,7 +649,7 @@ a |- "###, &gfm - ), + )?, r###"

Tables in things

In lists

@@ -876,7 +872,7 @@ bar | --- | --- | "###, &gfm - ), + )?, r###"

Examples from GFM

A

@@ -1037,7 +1033,7 @@ bar allow_dangerous_html: true, ..gfm.clone() } - ), + )?, r###"

Grave accents

Grave accent in cell

@@ -1148,7 +1144,7 @@ a | E | "###, &gfm - ), + )?, r###"

Code

Indented delimiter row

@@ -1345,7 +1341,7 @@ b allow_dangerous_html: true, ..gfm.clone() } - ), + )?, r###"

Blank line

@@ -1696,7 +1692,7 @@ a | - | "###, &gfm - ), + )?, r###"

Loose

Loose

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

Some more escapes

@@ -1779,4 +1775,6 @@ normal escape: https:// "###, "should match loose escapes like GitHub" ); + + Ok(()) } -- cgit