From e69071ccdda35e5b48b1623f9b2c01bcdde45a56 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 15 Jun 2022 13:36:02 +0200 Subject: Add tests for tabs --- tests/misc_tabs.rs | 305 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 tests/misc_tabs.rs (limited to 'tests') diff --git a/tests/misc_tabs.rs b/tests/misc_tabs.rs new file mode 100644 index 0000000..bdd88cf --- /dev/null +++ b/tests/misc_tabs.rs @@ -0,0 +1,305 @@ +extern crate micromark; +use micromark::{micromark, micromark_with_options, CompileOptions}; + +const DANGER: &CompileOptions = &CompileOptions { + allow_dangerous_html: true, + allow_dangerous_protocol: true, +}; + +#[test] +fn tabs_flow() { + assert_eq!( + micromark(" x"), + "
x\n
", + "should support a 4*SP to start code" + ); + + assert_eq!( + micromark("\tx"), + "
x\n
", + "should support a HT to start code" + ); + + assert_eq!( + micromark(" \tx"), + "
x\n
", + "should support a SP + HT to start code" + ); + + assert_eq!( + micromark(" \tx"), + "
x\n
", + "should support a 2*SP + HT to start code" + ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \tx"), + // "
x\n
", + // "should support a 3*SP + HT to start code" + // ); + + assert_eq!( + micromark(" \tx"), + "
\tx\n
", + "should support a 4*SP to start code, and leave the next HT as code data" + ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t# x"), + // "
# x\n
", + // "should not support a 3*SP + HT to start an ATX heading" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t> x"), + // "
> x\n
", + // "should not support a 3*SP + HT to start a block quote" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t- x"), + // "
- x\n
", + // "should not support a 3*SP + HT to start a list item" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t---"), + // "
---\n
", + // "should not support a 3*SP + HT to start a thematic break" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t---"), + // "
---\n
", + // "should not support a 3*SP + HT to start a thematic break" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t```"), + // "
```\n
", + // "should not support a 3*SP + HT to start a fenced code" + // ); + + // To do: bug with tabs/vs. + // assert_eq!( + // micromark(" \t
"), + // "
<div>\n
", + // "should not support a 3*SP + HT to start HTML" + // ); + + assert_eq!( + micromark("#\tx\t#\t"), + "

x

", + "should support tabs around ATX heading sequences" + ); + + assert_eq!( + micromark("#\t\tx\t\t#\t\t"), + "

x

", + "should support arbitrary tabs around ATX heading sequences" + ); + + assert_eq!( + micromark("```\tx\ty\t\n```\t"), + "
", + "should support tabs around fenced code fences, info, and meta" + ); + + assert_eq!( + micromark("```\t\tx\t\ty\t\t\n```\t\t"), + "
", + "should support arbitrary tabs around fenced code fences, info, and meta" + ); + + assert_eq!( + micromark("```x\n\t```"), + "
\t```\n
\n", + "should not support tabs before fenced code closing fences" + ); + + assert_eq!( + micromark_with_options("", DANGER), + "", + "should support tabs in HTML (if whitespace is allowed)" + ); + + assert_eq!( + micromark("*\t*\t*\t"), + "
", + "should support tabs in thematic breaks" + ); + + assert_eq!( + micromark("*\t\t*\t\t*\t\t"), + "
", + "should support arbitrary tabs in thematic breaks" + ); +} + +#[test] +fn tabs_text() { + assert_eq!( + micromark(""), + "

<http:\t>

", + "should not support a tab to start an autolink w/ protocol’s rest" + ); + + assert_eq!( + micromark(""), + "

<http:x\t>

", + "should not support a tab in an autolink w/ protocol’s rest" + ); + + assert_eq!( + micromark(""), + "

<example\t@x.com>

", + "should not support a tab in an email autolink’s local part" + ); + + assert_eq!( + micromark(""), + "

<example@x\ty.com>

", + "should not support a tab in an email autolink’s label" + ); + + assert_eq!( + micromark("\\\tx"), + "

\\\tx

", + "should not support character escaped tab" + ); + + assert_eq!( + micromark(" "), + "

\t

", + "should support character reference resolving to a tab" + ); + + // To do: code (text). + // assert_eq!( + // micromark("`\tx`"), + // "

\tx

", + // "should support a tab starting code" + // ); + + // To do: code (text). + // assert_eq!( + // micromark("`x\t`"), + // "

x\t

", + // "should support a tab ending code" + // ); + + // To do: code (text). + // assert_eq!( + // micromark("`\tx\t`"), + // "

\tx\t

", + // "should support tabs around code" + // ); + + // To do: code (text). + // assert_eq!( + // micromark("`\tx `"), + // "

\tx

", + // "should support a tab starting, and a space ending, code" + // ); + + // To do: code (text). + // assert_eq!( + // micromark("` x\t`"), + // "

x\t

", + // "should support a space starting, and a tab ending, code" + // ); + + // To do: trim trailing whitespace. + // // Note: CM does not strip it in this case. + // // However, that should be a bug there: makes more sense to remove it like + // // trailing spaces. + // assert_eq!( + // micromark("x\t\ny"), + // "

x\ny

", + // "should support a trailing tab at a line ending in a paragraph" + // ); + + // To do: trim trailing whitespace. + // assert_eq!( + // micromark("x\n\ty"), + // "

x\ny

", + // "should support an initial tab after a line ending in a paragraph" + // ); + + // To do: link (reference). + // assert_eq!( + // micromark("x[\ty](z)"), + // "

x\ty

", + // "should support an initial tab in a link label" + // ); + + // To do: link (reference). + // assert_eq!( + // micromark("x[y\t](z)"), + // "

xy\t

", + // "should support a final tab in a link label" + // ); + + // To do: link (reference). + // assert_eq!( + // micromark("[x\ty](z)"), + // "

x\ty

", + // "should support a tab in a link label" + // ); + + // To do: link (resource). + // Note: CM.js bug, see: + // assert_eq!( + // micromark("[x](\ty)"), + // "

x

", + // "should support a tab starting a link resource" + // ); + + // To do: link (resource). + // assert_eq!( + // micromark("[x](y\t)"), + // "

x

", + // "should support a tab ending a link resource" + // ); + + // To do: link (resource). + // assert_eq!( + // micromark("[x](y\t\"z\")"), + // "

x

", + // "should support a tab between a link destination and title" + // ); +} + +#[test] +fn tabs_virtual_spaces() { + assert_eq!( + micromark("```\n\tx"), + "
\tx\n
\n", + "should support a tab in fenced code" + ); + + assert_eq!( + micromark(" ```\n\tx"), + "
   x\n
\n", + "should strip 1 space from an initial tab in fenced code if the opening fence is indented as such" + ); + + assert_eq!( + micromark(" ```\n\tx"), + "
  x\n
\n", + "should strip 2 spaces from an initial tab in fenced code if the opening fence is indented as such" + ); + + assert_eq!( + micromark(" ```\n\tx"), + "
 x\n
\n", + "should strip 3 spaces from an initial tab in fenced code if the opening fence is indented as such" + ); +} -- cgit