From 5403261e8213f68633a09fc3e9bc2e6e2cd777b2 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 18 Jul 2022 16:31:14 +0200 Subject: Add support for turning off constructs --- tests/attention.rs | 42 +- tests/autolink.rs | 40 +- tests/block_quote.rs | 24 +- tests/character_escape.rs | 36 +- tests/character_reference.rs | 38 +- tests/code_fenced.rs | 22 +- tests/code_indented.rs | 140 +- tests/code_text.rs | 36 +- tests/commonmark.rs | 4576 ++++++++++++++++++++++++++----------- tests/definition.rs | 40 +- tests/hard_break_escape.rs | 22 +- tests/hard_break_trailing.rs | 22 +- tests/heading_atx.rs | 22 +- tests/heading_setext.rs | 22 +- tests/html_flow.rs | 362 +-- tests/html_text.rs | 165 +- tests/image.rs | 25 +- tests/link_reference.rs | 56 +- tests/link_resource.rs | 22 +- tests/list.rs | 39 +- tests/misc_dangerous_html.rs | 14 +- tests/misc_default_line_ending.rs | 6 +- tests/misc_line_ending.rs | 30 +- tests/misc_tabs.rs | 13 +- tests/thematic_break.rs | 22 +- 25 files changed, 3981 insertions(+), 1855 deletions(-) (limited to 'tests') diff --git a/tests/attention.rs b/tests/attention.rs index 1d30dd4..9a3e2fe 100644 --- a/tests/attention.rs +++ b/tests/attention.rs @@ -1,14 +1,14 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, Options}; - -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - default_line_ending: None, -}; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn attention() { + let danger = Options { + allow_dangerous_html: true, + allow_dangerous_protocol: true, + ..Options::default() + }; + // Rule 1. assert_eq!( micromark("*foo bar*"), @@ -764,25 +764,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)" ); @@ -811,10 +811,18 @@ fn attention() { "should not end strong emphasis inside autolinks (2)" ); - // To do: turning things off. - // assert_eq!( - // micromark("*a*", {extensions: [{disable: {null: ["attention"]}}]}), - // "

*a*

", - // "should support turning off attention" - // ); + assert_eq!( + micromark_with_options( + "*a*", + &Options { + constructs: Constructs { + attention: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

*a*

", + "should support turning off attention" + ); } diff --git a/tests/autolink.rs b/tests/autolink.rs index 7396c7a..b6258e6 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -1,14 +1,14 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, Options}; - -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - default_line_ending: None, -}; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn autolink() { + let danger = Options { + allow_dangerous_html: true, + allow_dangerous_protocol: true, + ..Options::default() + }; + assert_eq!( micromark(""), "

http://foo.bar.baz

", @@ -40,7 +40,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)" ); @@ -52,7 +52,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)" ); @@ -64,7 +64,7 @@ fn autolink() { ); assert_eq!( - micromark_with_options("", DANGER), + micromark_with_options("", &danger), "

localhost:5001/foo

", "should support protocol autolinks w/ incorrect URIs (4)" ); @@ -246,10 +246,18 @@ fn autolink() { "should not support a dash before a dot in email autolinks" ); - // To do: turning things off. - // assert_eq!( - // micromark("", {extensions: [{disable: {null: ["autolink"]}}]}), - // "

<a@b.co>

", - // "should support turning off autolinks" - // ); + assert_eq!( + micromark_with_options( + "", + &Options { + constructs: Constructs { + autolink: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

<a@b.co>

", + "should support turning off autolinks" + ); } diff --git a/tests/block_quote.rs b/tests/block_quote.rs index 06bd49a..13af078 100644 --- a/tests/block_quote.rs +++ b/tests/block_quote.rs @@ -1,5 +1,5 @@ extern crate micromark; -use micromark::micromark; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn block_quote() { @@ -165,12 +165,18 @@ fn block_quote() { "should support 5 spaces for indented code, not 4" ); - // To do: turning things off. - // assert_eq!( - // micromark("> # a\n> b\n> c", { - // extensions: [{disable: {null: ["blockQuote"]}}] - // }), - // "

> # a\n> b\n> c

", - // "should support turning off block quotes" - // ); + assert_eq!( + micromark_with_options( + "> # a\n> b\n> c", + &Options { + constructs: Constructs { + block_quote: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

> # a\n> b\n> c

", + "should support turning off block quotes" + ); } diff --git a/tests/character_escape.rs b/tests/character_escape.rs index d27f20a..8cd170d 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -1,14 +1,14 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, Options}; - -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - default_line_ending: None, -}; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn character_escape() { + let danger = Options { + allow_dangerous_html: true, + allow_dangerous_protocol: true, + ..Options::default() + }; + assert_eq!( micromark( "\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~" @@ -56,7 +56,7 @@ fn character_escape() { ); assert_eq!( - micromark_with_options("", DANGER), + micromark_with_options("", &danger), "", "should not escape in flow html" ); @@ -79,10 +79,18 @@ fn character_escape() { "should escape in fenced code info" ); - // To do: turning things off - // assert_eq!( - // micromark("\\> a", {extensions: [{disable: {null: ["characterEscape"]}}]}), - // "

\\> a

", - // "should support turning off character escapes" - // ); + assert_eq!( + micromark_with_options( + "\\> a", + &Options { + constructs: Constructs { + character_escape: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

\\> a

", + "should support turning off character escapes" + ); } diff --git a/tests/character_reference.rs b/tests/character_reference.rs index ef2ba0d..c41f47d 100644 --- a/tests/character_reference.rs +++ b/tests/character_reference.rs @@ -1,11 +1,5 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, Options}; - -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - default_line_ending: None, -}; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn character_reference() { @@ -50,7 +44,13 @@ fn character_reference() { ); assert_eq!( - micromark_with_options("
", DANGER), + micromark_with_options( + "", + &Options { + allow_dangerous_html: true, + ..Options::default() + } + ), "", "should not care about character references in html" ); @@ -188,12 +188,18 @@ fn character_reference() { "should not support the other characters inside a hexademical" ); - // To do: turning things off. - // assert_eq!( - // micromark("&", { - // extensions: [{disable: {null: ["characterReferences"]}}] - // }), - // "

&

", - // "should support turning off character references" - // ); + assert_eq!( + micromark_with_options( + "&", + &Options { + constructs: Constructs { + character_reference: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

&amp;

", + "should support turning off character references" + ); } diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index fa9ed5f..f251952 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -1,5 +1,5 @@ extern crate micromark; -use micromark::micromark; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn code_fenced() { @@ -250,10 +250,18 @@ fn code_fenced() { "should not support lazyness (3)" ); - // To do: turning things off. - // assert_eq!( - // micromark("```", {extensions: [{disable: {null: ["codeFenced"]}}]}), - // "

```

", - // "should support turning off code (fenced)" - // ); + assert_eq!( + micromark_with_options( + "```", + &Options { + constructs: Constructs { + code_fenced: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

```

", + "should support turning off code (fenced)" + ); } diff --git a/tests/code_indented.rs b/tests/code_indented.rs index 6735954..cb316e7 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -1,5 +1,5 @@ extern crate micromark; -use micromark::micromark; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn code_indented() { @@ -117,75 +117,71 @@ fn code_indented() { "should not support lazyness (7)" ); - // To do: turning things off. - // assert_eq!( - // micromark(" a", {extensions: [{disable: {null: ["codeIndented"]}}]}), - // "

a

", - // "should support turning off code (indented, 1)" - // ); - - // assert_eq!( - // micromark("> a\n b", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
\n

a\nb

\n
", - // "should support turning off code (indented, 2)" - // ); - - // assert_eq!( - // micromark("- a\n b", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
    \n
  • a\nb
  • \n
", - // "should support turning off code (indented, 3)" - // ); - - // assert_eq!( - // micromark("- a\n - b", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
    \n
  • a\n
      \n
    • b
    • \n
    \n
  • \n
", - // "should support turning off code (indented, 4)" - // ); - - // assert_eq!( - // micromark("- a\n - b", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
    \n
  • a\n
      \n
    • b
    • \n
    \n
  • \n
", - // "should support turning off code (indented, 5)" - // ); - - // assert_eq!( - // micromark("```\na\n ```", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
a\n
", - // "should support turning off code (indented, 6)" - // ); - - // assert_eq!( - // micromark("a ", { - // allowDangerousHtml: true, - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "

a

", - // "should support turning off code (indented, 7)" - // ); - - // assert_eq!( - // micromark("- Foo\n---", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
    \n
  • Foo
  • \n
\n
", - // "should support turning off code (indented, 8)" - // ); - - // assert_eq!( - // micromark("- Foo\n ---", { - // extensions: [{disable: {null: ["codeIndented"]}}] - // }), - // "
    \n
  • \n

    Foo

    \n
  • \n
", - // "should support turning off code (indented, 9)" - // ); + let off = Options { + constructs: Constructs { + code_indented: false, + ..Constructs::default() + }, + ..Options::default() + }; + + assert_eq!( + micromark_with_options(" a", &off), + "

a

", + "should support turning off code (indented, 1)" + ); + + assert_eq!( + 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), + "
    \n
  • a\nb
  • \n
", + "should support turning off code (indented, 3)" + ); + + assert_eq!( + 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), + "
    \n
  • a\n
      \n
    • b
    • \n
    \n
  • \n
", + "should support turning off code (indented, 5)" + ); + + assert_eq!( + micromark_with_options("```\na\n ```", &off), + "
a\n
", + "should support turning off code (indented, 6)" + ); + + assert_eq!( + micromark_with_options( + "a ", + &Options { + allow_dangerous_html: true, + ..off.clone() + } + ), + "

a

", + "should support turning off code (indented, 7)" + ); + + assert_eq!( + 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), + "
    \n
  • \n

    Foo

    \n
  • \n
", + "should support turning off code (indented, 9)" + ); } diff --git a/tests/code_text.rs b/tests/code_text.rs index 054d8e2..834b831 100644 --- a/tests/code_text.rs +++ b/tests/code_text.rs @@ -1,14 +1,14 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, Options}; - -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: false, - default_line_ending: None, -}; +use micromark::{micromark, micromark_with_options, Constructs, Options}; #[test] fn code_text() { + let danger = Options { + allow_dangerous_html: true, + allow_dangerous_protocol: true, + ..Options::default() + }; + assert_eq!( micromark("`foo`"), "

foo

", @@ -106,7 +106,7 @@ fn code_text() { ); assert_eq!( - micromark_with_options("
`", DANGER), + micromark_with_options("`", &danger), "

`

", "should have same precedence as HTML (2)" ); @@ -154,10 +154,18 @@ fn code_text() { "should support an escaped initial grave accent" ); - // To do: turning things off. - // assert_eq!( - // micromark("`a`", {extensions: [{disable: {null: ["codeText"]}}]}), - // "

`a`

", - // "should support turning off code (text)" - // ); + assert_eq!( + micromark_with_options( + "`a`", + &Options { + constructs: Constructs { + code_text: false, + ..Constructs::default() + }, + ..Options::default() + } + ), + "

`a`

", + "should support turning off code (text)" + ); } diff --git a/tests/commonmark.rs b/tests/commonmark.rs index 59908a2..95871a4 100644 --- a/tests/commonmark.rs +++ b/tests/commonmark.rs @@ -6,18 +6,21 @@ extern crate micromark; use micromark::{micromark_with_options, Options}; -const DANGER: &Options = &Options { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - default_line_ending: None, -}; - #[rustfmt::skip] #[test] fn commonmark() { + let danger = Options { + allow_dangerous_html: true, + allow_dangerous_protocol: true, + ..Options::default() + }; + assert_eq!( - micromark_with_options(r###" foo baz bim -"###, DANGER), + micromark_with_options( + r###" foo baz bim +"###, + &danger + ), r###"
foo	baz		bim
 
"###, @@ -25,8 +28,11 @@ fn commonmark() { ); assert_eq!( - micromark_with_options(r###" foo baz bim -"###, DANGER), + micromark_with_options( + r###" foo baz bim +"###, + &danger + ), r###"
foo	baz		bim
 
"###, @@ -34,9 +40,12 @@ fn commonmark() { ); assert_eq!( - micromark_with_options(r###" a a + micromark_with_options( + r###" a a ὐ a -"###, DANGER), +"###, + &danger + ), r###"
a	a
 ὐ	a
 
@@ -45,10 +54,13 @@ fn commonmark() { ); assert_eq!( - micromark_with_options(r###" - foo + micromark_with_options( + r###" - foo bar -"###, DANGER), +"###, + &danger + ), r###"