From f99d131ec3ab60956344d001bcd40244343c241b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 21 Jun 2022 12:06:51 +0200 Subject: Add support for inferring line ending, configurable * Rename `CompileOptions` to `Options` * Add support for an optional default line ending style * Add support for inferring the used line ending style --- tests/autolink.rs | 5 +- tests/character_escape.rs | 5 +- tests/character_reference.rs | 5 +- tests/code_text.rs | 5 +- tests/definition.rs | 5 +- tests/html_flow.rs | 5 +- tests/html_text.rs | 5 +- tests/misc_dangerous_html.rs | 5 +- tests/misc_default_line_ending.rs | 56 +++++++++++++ tests/misc_line_ending.rs | 161 ++++++++++++++++++++++++++++++++++++++ tests/misc_tabs.rs | 5 +- 11 files changed, 244 insertions(+), 18 deletions(-) create mode 100644 tests/misc_default_line_ending.rs create mode 100644 tests/misc_line_ending.rs (limited to 'tests') diff --git a/tests/autolink.rs b/tests/autolink.rs index 51873ed..3882264 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] diff --git a/tests/character_escape.rs b/tests/character_escape.rs index ba94ab3..e4f23d2 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] diff --git a/tests/character_reference.rs b/tests/character_reference.rs index f2337ab..136ce17 100644 --- a/tests/character_reference.rs +++ b/tests/character_reference.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] diff --git a/tests/code_text.rs b/tests/code_text.rs index bab6dd6..054d8e2 100644 --- a/tests/code_text.rs +++ b/tests/code_text.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: false, + default_line_ending: None, }; #[test] diff --git a/tests/definition.rs b/tests/definition.rs index c15e44b..a8e8164 100644 --- a/tests/definition.rs +++ b/tests/definition.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] diff --git a/tests/html_flow.rs b/tests/html_flow.rs index 53105a6..d942642 100644 --- a/tests/html_flow.rs +++ b/tests/html_flow.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: false, + default_line_ending: None, }; #[test] diff --git a/tests/html_text.rs b/tests/html_text.rs index 1f85ac4..e70a4da 100644 --- a/tests/html_text.rs +++ b/tests/html_text.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: false, + default_line_ending: None, }; #[test] diff --git a/tests/misc_dangerous_html.rs b/tests/misc_dangerous_html.rs index 7a0b49a..76031c1 100644 --- a/tests/misc_dangerous_html.rs +++ b/tests/misc_dangerous_html.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] diff --git a/tests/misc_default_line_ending.rs b/tests/misc_default_line_ending.rs new file mode 100644 index 0000000..fb4e1df --- /dev/null +++ b/tests/misc_default_line_ending.rs @@ -0,0 +1,56 @@ +extern crate micromark; +// use micromark::{micromark, micromark_with_options, Options}; + +#[test] +fn default_line_ending() { + // To do: blockquote. + // assert_eq!( + // micromark("> a"), + // "
\n

a

\n
", + // "should use `\\n` default" + // ); + + // assert_eq!( + // micromark("> a\n"), + // "
\n

a

\n
\n", + // "should infer the first line ending (1)" + // ); + + // assert_eq!( + // micromark("> a\r"), + // "
\r

a

\r
\r", + // "should infer the first line ending (2)" + // ); + + // assert_eq!( + // micromark("> a\r\n"), + // "
\r\n

a

\r\n
\r\n", + // "should infer the first line ending (3)" + // ); + + // assert_eq!( + // micromark_with_options( + // "> a", + // &Options { + // // default_line_ending: "\r", + // allow_dangerous_html: false, + // allow_dangerous_protocol: false + // } + // ), + // "
\r

a

\r
", + // "should support the given line ending" + // ); + + // assert_eq!( + // micromark_with_options( + // "> a\n", + // &Options { + // // default_line_ending: "\r", + // allow_dangerous_html: false, + // allow_dangerous_protocol: false + // } + // ), + // "
\r

a

\r
\n", + // "should support the given line ending, even if line endings exist" + // ); +} diff --git a/tests/misc_line_ending.rs b/tests/misc_line_ending.rs new file mode 100644 index 0000000..195ddaa --- /dev/null +++ b/tests/misc_line_ending.rs @@ -0,0 +1,161 @@ +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, +}; + +#[test] +fn line_ending() { + assert_eq!( + micromark("a\nb"), + "

a\nb

", + "should support a line feed for a line ending inside a paragraph" + ); + + assert_eq!( + micromark("a\rb"), + "

a\rb

", + "should support a carriage return for a line ending inside a paragraph" + ); + + assert_eq!( + micromark("a\r\nb"), + "

a\r\nb

", + "should support a carriage return + line feed for a line ending inside a paragraph" + ); + + assert_eq!( + micromark("\ta\n\tb"), + "
a\nb\n
", + "should support a line feed in indented code (and prefer it)" + ); + + assert_eq!( + micromark("\ta\r\tb"), + "
a\rb\r
", + "should support a carriage return in indented code (and prefer it)" + ); + + assert_eq!( + micromark("\ta\r\n\tb"), + "
a\r\nb\r\n
", + "should support a carriage return + line feed in indented code (and prefer it)" + ); + + assert_eq!( + micromark("***\n### Heading"), + "
\n

Heading

", + "should support a line feed between flow" + ); + + assert_eq!( + micromark("***\r### Heading"), + "
\r

Heading

", + "should support a carriage return between flow" + ); + + assert_eq!( + micromark("***\r\n### Heading"), + "
\r\n

Heading

", + "should support a carriage return + line feed between flow" + ); + + assert_eq!( + micromark("***\n\n\n### Heading\n"), + "
\n

Heading

\n", + "should support several line feeds between flow" + ); + + assert_eq!( + micromark("***\r\r\r### Heading\r"), + "
\r

Heading

\r", + "should support several carriage returns between flow" + ); + + assert_eq!( + micromark("***\r\n\r\n\r\n### Heading\r\n"), + "
\r\n

Heading

\r\n", + "should support several carriage return + line feeds between flow" + ); + + assert_eq!( + micromark("```x\n\n\ny\n\n\n```\n\n\n"), + "
\n\ny\n\n\n
\n", + "should support several line feeds in fenced code" + ); + + assert_eq!( + micromark("```x\r\r\ry\r\r\r```\r\r\r"), + "
\r\ry\r\r\r
\r", + "should support several carriage returns in fenced code" + ); + + assert_eq!( + micromark("```x\r\n\r\n\r\ny\r\n\r\n\r\n```\r\n\r\n\r\n"), + "
\r\n\r\ny\r\n\r\n\r\n
\r\n", + "should support several carriage return + line feeds in fenced code" + ); + + assert_eq!( + micromark("A\r\nB\r\n-\r\nC"), + "

A\r\nB

\r\n

C

", + "should support a carriage return + line feed in content" + ); + + assert_eq!( + micromark_with_options("\n\nx", DANGER), + "
\n

x

", + "should support a blank line w/ line feeds after html" + ); + + assert_eq!( + micromark_with_options("
\r\rx", DANGER), + "
\r

x

", + "should support a blank line w/ carriage returns after html" + ); + + assert_eq!( + micromark_with_options("
\r\n\r\nx", DANGER), + "
\r\n

x

", + "should support a blank line w/ carriage return + line feeds after html" + ); + + assert_eq!( + micromark_with_options("
\nx", DANGER), + "
\nx", + "should support a non-blank line w/ line feed in html" + ); + + assert_eq!( + micromark_with_options("
\rx", DANGER), + "
\rx", + "should support a non-blank line w/ carriage return in html" + ); + + assert_eq!( + micromark_with_options("
\r\nx", DANGER), + "
\r\nx", + "should support a non-blank line w/ carriage return + line feed in html" + ); +} diff --git a/tests/misc_tabs.rs b/tests/misc_tabs.rs index 46588e7..e9a0b72 100644 --- a/tests/misc_tabs.rs +++ b/tests/misc_tabs.rs @@ -1,9 +1,10 @@ extern crate micromark; -use micromark::{micromark, micromark_with_options, CompileOptions}; +use micromark::{micromark, micromark_with_options, Options}; -const DANGER: &CompileOptions = &CompileOptions { +const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, + default_line_ending: None, }; #[test] -- cgit