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/attention.rs | 14 +- tests/autolink.rs | 45 +- tests/block_quote.rs | 6 +- tests/character_escape.rs | 14 +- tests/character_reference.rs | 14 +- tests/code_fenced.rs | 6 +- tests/code_indented.rs | 22 +- tests/code_text.rs | 8 +- tests/commonmark.rs | 1308 +++++++++++++++++++------------------ tests/definition.rs | 13 +- tests/frontmatter.rs | 20 +- tests/gfm_autolink_literal.rs | 122 ++-- tests/gfm_footnote.rs | 103 +-- tests/gfm_strikethrough.rs | 30 +- tests/gfm_table.rs | 126 ++-- tests/gfm_tagfilter.rs | 12 +- tests/gfm_task_list_item.rs | 14 +- tests/hard_break_escape.rs | 6 +- tests/hard_break_trailing.rs | 6 +- tests/heading_atx.rs | 6 +- tests/heading_setext.rs | 6 +- tests/html_flow.rs | 328 +++++----- tests/html_text.rs | 138 ++-- tests/image.rs | 8 +- tests/link_reference.rs | 10 +- tests/link_resource.rs | 20 +- tests/list.rs | 33 +- tests/math_flow.rs | 80 +-- tests/math_text.rs | 54 +- tests/misc_bom.rs | 4 +- tests/misc_dangerous_html.rs | 6 +- tests/misc_dangerous_protocol.rs | 12 +- tests/misc_default_line_ending.rs | 8 +- tests/misc_line_ending.rs | 22 +- tests/misc_soft_break.rs | 4 +- tests/misc_tabs.rs | 14 +- tests/misc_url.rs | 4 +- tests/misc_zero.rs | 4 +- tests/text.rs | 4 +- tests/thematic_break.rs | 6 +- 40 files changed, 1371 insertions(+), 1289 deletions(-) (limited to 'tests') diff --git a/tests/attention.rs b/tests/attention.rs index c7d7454..93c3a50 100644 --- a/tests/attention.rs +++ b/tests/attention.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn attention() { +fn attention() -> Result<(), String> { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, @@ -765,25 +765,25 @@ fn attention() { ); assert_eq!( - micromark_with_options("*", &danger), + micromark_with_options("*", &danger)?, "

*

", "should not end inside HTML" ); assert_eq!( - micromark_with_options("*", &danger), + micromark_with_options("*", &danger)?, "

*

", "should not end emphasis inside HTML" ); assert_eq!( - micromark_with_options("**", &danger), + micromark_with_options("**", &danger)?, "

**

", "should not end strong inside HTML (1)" ); assert_eq!( - micromark_with_options("__", &danger), + micromark_with_options("__", &danger)?, "

__

", "should not end strong inside HTML (2)" ); @@ -822,8 +822,10 @@ fn attention() { }, ..Options::default() } - ), + )?, "

*a*

", "should support turning off attention" ); + + Ok(()) } diff --git a/tests/autolink.rs b/tests/autolink.rs index b851583..4cf357a 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn autolink() { +fn autolink() -> Result<(), String> { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, @@ -41,7 +41,7 @@ fn autolink() { ); assert_eq!( - micromark_with_options("", &danger), + micromark_with_options("", &danger)?, "

a+b+c:d

", "should support protocol autolinks w/ incorrect URIs (1, danger)" ); @@ -53,7 +53,7 @@ fn autolink() { ); assert_eq!( - micromark_with_options("", &danger), + micromark_with_options("", &danger)?, "

made-up-scheme://foo,bar

", "should support protocol autolinks w/ incorrect URIs (2, danger)" ); @@ -65,7 +65,7 @@ fn autolink() { ); assert_eq!( - micromark_with_options("", &danger), + micromark_with_options("", &danger)?, "

localhost:5001/foo

", "should support protocol autolinks w/ incorrect URIs (4)" ); @@ -182,12 +182,11 @@ fn autolink() { ); assert_eq!( - micromark( - "" - ), - "

asd@012345678901234567890123456789012345678901234567890123456789012

", - "should support 63 character in email autolinks domains" - ); + micromark( + ""), + "

asd@012345678901234567890123456789012345678901234567890123456789012

", + "should support 63 character in email autolinks domains" + ); assert_eq!( micromark(""), @@ -196,12 +195,11 @@ fn autolink() { ); assert_eq!( - micromark( - "" - ), - "

asd@012345678901234567890123456789012345678901234567890123456789012.a

", - "should support a TLD after a 63 character domain in email autolinks" - ); + micromark( + ""), + "

asd@012345678901234567890123456789012345678901234567890123456789012.a

", + "should support a TLD after a 63 character domain in email autolinks" + ); assert_eq!( micromark(""), @@ -210,12 +208,11 @@ fn autolink() { ); assert_eq!( - micromark( - "" - ), - "

asd@a.012345678901234567890123456789012345678901234567890123456789012

", - "should support a 63 character TLD in email autolinks" - ); + micromark( + ""), + "

asd@a.012345678901234567890123456789012345678901234567890123456789012

", + "should support a 63 character TLD in email autolinks" + ); assert_eq!( micromark(""), @@ -257,8 +254,10 @@ fn autolink() { }, ..Options::default() } - ), + )?, "

<a@b.co>

", "should support turning off autolinks" ); + + Ok(()) } diff --git a/tests/block_quote.rs b/tests/block_quote.rs index be9da40..6947ef3 100644 --- a/tests/block_quote.rs +++ b/tests/block_quote.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn block_quote() { +fn block_quote() -> Result<(), String> { assert_eq!( micromark("> # a\n> b\n> c"), "
\n

a

\n

b\nc

\n
", @@ -206,8 +206,10 @@ fn block_quote() { }, ..Options::default() } - ), + )?, "

> # a\n> b\n> c

", "should support turning off block quotes" ); + + Ok(()) } diff --git a/tests/character_escape.rs b/tests/character_escape.rs index 2ecaa5f..e76e3e9 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn character_escape() { +fn character_escape() -> Result<(), String> { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, @@ -12,8 +12,7 @@ fn character_escape() { assert_eq!( micromark( - "\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~" - ), + "\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~"), "

!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~

", "should support escaped ascii punctuation" ); @@ -26,8 +25,7 @@ fn character_escape() { assert_eq!( micromark( - "\\*not emphasized*\n\\
not a tag\n\\[not a link](/foo)\n\\`not code`\n1\\. not a list\n\\* not a list\n\\# not a heading\n\\[foo]: /url \"not a reference\"\n\\ö not a character entity" - ), + "\\*not emphasized*\n\\
not a tag\n\\[not a link](/foo)\n\\`not code`\n1\\. not a list\n\\* not a list\n\\# not a heading\n\\[foo]: /url \"not a reference\"\n\\ö not a character entity"), "

*not emphasized*\n<br/> not a tag\n[not a link](/foo)\n`not code`\n1. not a list\n* not a list\n# not a heading\n[foo]: /url "not a reference"\n&ouml; not a character entity

", "should escape other constructs" ); @@ -57,7 +55,7 @@ fn character_escape() { ); assert_eq!( - micromark_with_options("", &danger), + micromark_with_options("", &danger)?, "", "should not escape in flow html" ); @@ -90,8 +88,10 @@ fn character_escape() { }, ..Options::default() } - ), + )?, "

\\> a

", "should support turning off character escapes" ); + + Ok(()) } diff --git a/tests/character_reference.rs b/tests/character_reference.rs index c388514..a08c3f9 100644 --- a/tests/character_reference.rs +++ b/tests/character_reference.rs @@ -3,11 +3,10 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn character_reference() { +fn character_reference() -> Result<(), String> { assert_eq!( micromark( - "  & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸" - ), + "  & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸"), "

\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸

", "should support named character references" ); @@ -26,8 +25,7 @@ fn character_reference() { assert_eq!( micromark( - "  &x; &#; &#x;\n�\n&#abcdef0;\n&ThisIsNotDefined; &hi?;" - ), + "  &x; &#; &#x;\n�\n&#abcdef0;\n&ThisIsNotDefined; &hi?;"), "

&nbsp &x; &#; &#x;\n&#987654321;\n&#abcdef0;\n&ThisIsNotDefined; &hi?;

", "should not support other things that look like character references" ); @@ -51,7 +49,7 @@ fn character_reference() { allow_dangerous_html: true, ..Options::default() } - ), + )?, "
", "should not care about character references in html" ); @@ -199,8 +197,10 @@ fn character_reference() { }, ..Options::default() } - ), + )?, "

&amp;

", "should support turning off character references" ); + + Ok(()) } diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index fd35eb8..850bd1b 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn code_fenced() { +fn code_fenced() -> Result<(), String> { assert_eq!( micromark("```\n<\n >\n```"), "
<\n >\n
", @@ -267,8 +267,10 @@ fn code_fenced() { }, ..Options::default() } - ), + )?, "

```

", "should support turning off code (fenced)" ); + + Ok(()) } diff --git a/tests/code_indented.rs b/tests/code_indented.rs index cd27953..29d8909 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn code_indented() { +fn code_indented() -> Result<(), String> { assert_eq!( micromark(" a simple\n indented code block"), "
a simple\n  indented code block\n
", @@ -127,37 +127,37 @@ fn code_indented() { }; assert_eq!( - micromark_with_options(" a", &off), + micromark_with_options(" a", &off)?, "

a

", "should support turning off code (indented, 1)" ); assert_eq!( - micromark_with_options("> a\n b", &off), + micromark_with_options("> a\n b", &off)?, "
\n

a\nb

\n
", "should support turning off code (indented, 2)" ); assert_eq!( - micromark_with_options("- a\n b", &off), + micromark_with_options("- a\n b", &off)?, "
    \n
  • a\nb
  • \n
", "should support turning off code (indented, 3)" ); assert_eq!( - micromark_with_options("- a\n - b", &off), + micromark_with_options("- a\n - b", &off)?, "
    \n
  • a\n
      \n
    • b
    • \n
    \n
  • \n
", "should support turning off code (indented, 4)" ); assert_eq!( - micromark_with_options("- a\n - b", &off), + micromark_with_options("- a\n - b", &off)?, "
    \n
  • a\n
      \n
    • b
    • \n
    \n
  • \n
", "should support turning off code (indented, 5)" ); assert_eq!( - micromark_with_options("```\na\n ```", &off), + micromark_with_options("```\na\n ```", &off)?, "
a\n
", "should support turning off code (indented, 6)" ); @@ -169,20 +169,22 @@ fn code_indented() { allow_dangerous_html: true, ..off.clone() } - ), + )?, "

a

", "should support turning off code (indented, 7)" ); assert_eq!( - micromark_with_options("- Foo\n---", &off), + micromark_with_options("- Foo\n---", &off)?, "
    \n
  • Foo
  • \n
\n
", "should support turning off code (indented, 8)" ); assert_eq!( - micromark_with_options("- Foo\n ---", &off), + micromark_with_options("- Foo\n ---", &off)?, "
    \n
  • \n

    Foo

    \n
  • \n
", "should support turning off code (indented, 9)" ); + + Ok(()) } diff --git a/tests/code_text.rs b/tests/code_text.rs index 5199e7e..a0ed13e 100644 --- a/tests/code_text.rs +++ b/tests/code_text.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn code_text() { +fn code_text() -> Result<(), String> { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, @@ -107,7 +107,7 @@ fn code_text() { ); assert_eq!( - micromark_with_options("
`", &danger), + micromark_with_options("`", &danger)?, "

`

", "should have same precedence as HTML (2)" ); @@ -165,8 +165,10 @@ fn code_text() { }, ..Options::default() } - ), + )?, "

`a`

", "should support turning off code (text)" ); + + Ok(()) } diff --git a/tests/commonmark.rs b/tests/commonmark.rs index 889bbf3..b5bb40e 100644 --- a/tests/commonmark.rs +++ b/tests/commonmark.rs @@ -9,7 +9,7 @@ use pretty_assertions::assert_eq; #[rustfmt::skip] #[test] -fn commonmark() { +fn commonmark() -> Result<(), String> { let danger = Options { allow_dangerous_html: true, allow_dangerous_protocol: true, @@ -21,7 +21,7 @@ fn commonmark() { r###" foo baz bim "###, &danger - ), + )?, r###"
foo	baz		bim
 
"###, @@ -33,7 +33,7 @@ fn commonmark() { r###" foo baz bim "###, &danger - ), + )?, r###"
foo	baz		bim
 
"###, @@ -46,7 +46,7 @@ fn commonmark() { ὐ a "###, &danger - ), + )?, r###"
a	a
 ὐ	a
 
@@ -61,7 +61,7 @@ fn commonmark() { bar "###, &danger - ), + )?, r###"